Vcsn  2.4
Be Rational
filter.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <boost/range/adaptor/filtered.hpp>
4 #include <boost/range/distance.hpp>
5 
6 namespace vcsn
7 {
8  namespace detail
9  {
10  template <typename Range, typename Filter>
12  {
13  safe_filtered(Range r, Filter f)
14  : range_(std::move(r))
15  , filtered_(f, range_)
16  {}
17 
18  using value_type = typename Range::value_type;
19  using difference_type = std::ptrdiff_t;
20  using filtered_t = boost::filtered_range<Filter, Range>;
21 
22  using iterator = typename filtered_t::iterator;
23  using const_iterator = typename filtered_t::const_iterator;
24 
25  const_iterator begin() const { return std::begin(filtered_); }
26  const_iterator end() const { return std::end(filtered_); }
27 
29  bool empty() const
30  {
31  return filtered_.empty();
32  }
33 
35  size_t size() const
36  {
37  return boost::distance(filtered_);
38  }
39 
40  Range range_;
42  };
43  }
44 
47  template <typename Range, typename Filter>
48  auto filter(Range&& r, Filter f,
49  // SFINAE against vcsn::filter for automata.
50  decltype(f(*std::begin(r)), void())* = nullptr)
51  {
52  return detail::safe_filtered<Range, Filter>{std::forward<Range>(r), f};
53  }
54 }
55 
56 namespace boost
57 {
58  template <typename Range, typename Filter>
59  struct range_difference<vcsn::detail::safe_filtered<Range, Filter>>
60  {
61  using type
63  };
64 }
STL namespace.
const_iterator end() const
Definition: filter.hh:26
const_iterator begin() const
Definition: filter.hh:25
Definition: filter.hh:56
weightset_mixin< detail::r_impl > r
Definition: fwd.hh:54
Provide a variadic mul on top of a binary mul(), and one().
Definition: fwd.hh:46
typename Range::value_type value_type
Definition: filter.hh:18
bool empty() const
Whether filters to nothing.
Definition: filter.hh:29
size_t size() const
Number of elements in the filtered range.
Definition: filter.hh:35
Definition: a-star.hh:8
boost::filtered_range< Filter, Range > filtered_t
Definition: filter.hh:20
safe_filtered(Range r, Filter f)
Definition: filter.hh:13
typename vcsn::detail::safe_filtered< Range, Filter >::difference_type type
Definition: filter.hh:62
std::ptrdiff_t difference_type
Definition: filter.hh:19
typename filtered_t::const_iterator const_iterator
Definition: filter.hh:23
typename filtered_t::iterator iterator
Definition: filter.hh:22
filter_automaton< Aut, Trans > filter(const Aut &aut, boost::optional< dynamic_bitset > ss={}, boost::optional< dynamic_bitset > ts={})
Get an automaton who is a part state set ss of aut.
Definition: filter.hh:301