Vcsn  2.0
Be Rational
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
vector.hh
Go to the documentation of this file.
1 #ifndef VCSN_MISC_VECTOR_HH
2 # define VCSN_MISC_VECTOR_HH
3 
4 # include <algorithm>
5 # include <vector>
6 
7 # include <vcsn/misc/attributes.hh>
8 # include <vcsn/misc/tuple.hh> // make_index_sequence.
9 
10 namespace vcsn
11 {
12 
13  namespace detail
14  {
15 
19  template <typename Fun>
20  inline void
21  cross(Fun f)
22  {
23  f();
24  }
25 
26  template<typename Fun, typename H, typename... Ts>
27  inline void
28  cross(Fun f,
29  std::vector<H> const& h,
30  std::vector<Ts> const&... ts)
31  {
32  for (H const& he: h)
33  cross([&](Ts const&... ts) { f(he, ts...); }, ts...);
34  }
35 
36  template<typename Fun, typename... Ts>
37  inline void
38  cross_tuple(Fun f,
39  const std::tuple<Ts...>& ts)
40  {
41  cross_tuple_(f, ts, make_index_sequence<sizeof...(Ts)>());
42  }
43 
44  template<typename Fun, typename... Ts, size_t... I>
45  inline void
46  cross_tuple_(Fun f,
47  const std::tuple<Ts...>& ts,
49  {
50  cross(f, std::get<I>(ts)...);
51  }
52 
54  template <typename Cont>
55  std::vector<typename Cont::value_type>
56  to_vector(const Cont& cont)
57  {
58  return {std::begin(cont), std::end(cont)};
59  }
60  }
61 
63  template <typename T, typename Alloc>
64  ATTRIBUTE_PURE
65  auto
66  find(const std::vector<T, Alloc>& s, const T& e)
67  -> typename std::vector<T, Alloc>::const_iterator
68  {
69  return std::find(std::begin(s), std::end(s), e);
70  }
71 
73  template <typename T, typename Alloc>
74  ATTRIBUTE_PURE
75  bool
76  has(const std::vector<T, Alloc>& s, const T& e)
77  {
78  return find(s, e) != std::end(s);
79  }
80 }
81 
82 #endif // !VCSN_MISC_VECTOR_HH
void cross_tuple_(Fun f, const std::tuple< Ts...> &ts, index_sequence< I...>)
Definition: vector.hh:46
void cross_tuple(Fun f, const std::tuple< Ts...> &ts)
Definition: vector.hh:38
std::vector< typename Cont::value_type > to_vector(const Cont &cont)
Return the content of cont as a vector.
Definition: vector.hh:56
void cross(Fun f)
Variadic Cartesian product of vectors.
Definition: vector.hh:21
bool has(const std::map< Key, Value, Compare, Alloc > &s, const Key &e)
Definition: map.hh:35
ATTRIBUTE_PURE auto find(const std::vector< T, Alloc > &s, const T &e) -> typename std::vector< T, Alloc >::const_iterator
Convenience wrapper around std::find.
Definition: vector.hh:66