Vcsn  2.2a
Be Rational
crange.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <type_traits>
4 
5 #include <boost/iterator/filter_iterator.hpp>
6 
8 
9 namespace vcsn
10 {
12  template <typename C>
13  struct container_range
14  {
15  public:
17  using value_type = typename unref_C::value_type;
18 
19  using const_iterator = typename unref_C::const_iterator;
20  private:
21  const C cont_;
22  public:
23  container_range(const unref_C& cont)
24  : cont_(cont)
25  {}
26 
28 #define DEFINE(Name) \
29  auto Name() const -> decltype(this->cont_.Name()) \
30  { \
31  return cont_.Name(); \
32  }
43 #undef DEFINE
44  };
45 
46 
47  template <typename Cont, typename Pred>
49  {
50  public:
51  using container_t = Cont;
53  using value_type = typename unref_C::value_type;
54  using predicate_t = Pred;
55  using const_iterator
56  = boost::filter_iterator<predicate_t, typename unref_C::const_iterator>;
57  public:
58  container_filter_range(const unref_C& cont, predicate_t predicate)
59  : cont_(cont)
60  , predicate_(predicate)
61  {}
62 
64  {
65  return {predicate_, cont_.begin(), cont_.end()};
66  }
67 
69  {
70  return {predicate_, cont_.end(), cont_.end()};
71  }
72 
77  value_type front() const
78  {
79  assert(!empty());
80  return *begin();
81  }
82 
87  value_type back() const
88  {
89  assert(!empty());
90  return cont_.back();
91  }
92 
93  ATTRIBUTE_PURE
94  bool empty() const
95  {
96  return begin() == end();
97  }
98 
99  ATTRIBUTE_PURE
100  size_t size() const
101  {
102  return std::distance(begin(), end());
103  }
104 
105  private:
108  };
109 
110  template <typename Cont, typename Pred>
112  make_container_filter_range(const Cont& cont, Pred pred)
113  {
114  return {cont, pred};
115  }
116 }
auto front() const -> decltype(this->cont_.front())
The first element.
Definition: crange.hh:37
boost::filter_iterator< predicate_t, typename unref_C::const_iterator > const_iterator
Definition: crange.hh:56
value_type front() const
The first element.
Definition: crange.hh:77
auto size() const -> decltype(this->cont_.size())
Definition: crange.hh:42
auto end() const -> decltype(this->cont_.end())
Definition: crange.hh:34
auto begin() const -> decltype(this->cont_.begin())
Definition: crange.hh:33
const container_t cont_
Definition: crange.hh:106
typename std::remove_reference< C >::type unref_C
Definition: crange.hh:16
ATTRIBUTE_PURE size_t size() const
Definition: crange.hh:100
container_range(const unref_C &cont)
Definition: crange.hh:23
std::string type(const automaton &a)
The implementation type of a.
Definition: others.cc:206
value_type back() const
The last element.
Definition: crange.hh:87
typename unref_C::const_iterator const_iterator
Definition: crange.hh:19
#define DEFINE(Name)
Forward function Name to the container.
Definition: crange.hh:28
auto empty() const -> decltype(this->cont_.empty())
Definition: crange.hh:41
ATTRIBUTE_PURE bool empty() const
Definition: crange.hh:94
auto back() const -> decltype(this->cont_.back())
The last element.
Definition: crange.hh:40
typename std::remove_reference< container_t >::type unref_C
Definition: crange.hh:52
container_filter_range< Cont, Pred > make_container_filter_range(const Cont &cont, Pred pred)
Definition: crange.hh:112
container_filter_range(const unref_C &cont, predicate_t predicate)
Definition: crange.hh:58
typename unref_C::value_type value_type
Definition: crange.hh:17
const_iterator end() const
Definition: crange.hh:68
typename unref_C::value_type value_type
Definition: crange.hh:53
const_iterator begin() const
Definition: crange.hh:63
Definition: a-star.hh:8