Awali
Another Weighted Automata library
vector.hh
Go to the documentation of this file.
1 // This file is part of Awali.
2 // Copyright 2016-2022 Sylvain Lombardy, Victor Marsault, Jacques Sakarovitch
3 //
4 // Awali is a free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef AWALI_MISC_VECTOR_HH
18 # define AWALI_MISC_VECTOR_HH
19 
20 # include <algorithm>
21 # include <vector>
22 
24 #include <awali/common/tuple.hh> // make_index_sequence.
25 
26 namespace awali { namespace sttc {
27 
28 
29  namespace internal
30  {
31 
35  template <typename Fun>
36  inline void
37  cross(Fun f)
38  {
39  f();
40  }
41 
42  template<typename Fun, typename H, typename... Ts>
43  inline void
44  cross(Fun f,
45  std::vector<H> const& h,
46  std::vector<Ts> const&... ts)
47  {
48  for (H const& he: h)
49  cross([&](Ts const&... ts2) { f(he, ts2...); }, ts...);
50  }
51 
52  template<typename Fun, typename... Ts>
53  inline void
54  cross_tuple(Fun f,
55  const std::tuple<Ts...>& ts)
56  {
57  cross_tuple_(f, ts, awali::internal::make_index_sequence<sizeof...(Ts)>());
58  }
59 
60  template<typename Fun, typename... Ts, size_t... I>
61  inline void
62  cross_tuple_(Fun f,
63  const std::tuple<Ts...>& ts,
65  {
66  cross(f, std::get<I>(ts)...);
67  }
68 
70  template <typename Cont>
71  std::vector<typename Cont::value_type>
72  to_vector(const Cont& cont)
73  {
74  return {cont.begin(), cont.end()};
75  }
76 
78  template <typename T, typename Alloc>
79  ATTRIBUTE_PURE
80  auto
81  find(const std::vector<T, Alloc>& s, const T& e)
82  -> typename std::vector<T, Alloc>::const_iterator
83  {
84  return std::find(std::begin(s), std::end(s), e);
85  }
86 
88  template <typename T, typename Alloc>
89  ATTRIBUTE_PURE
90  bool
91  has(const std::vector<T, Alloc>& s, const T& e)
92  {
93  return find(s, e) != std::end(s);
94  }
95  }
96 }}//end of ns awali::stc
97 
98 #endif // !AWALI_MISC_VECTOR_HH
Definition: tuple.hh:43
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:81
cross_sequences< Sequences... > cross_tuple(const std::tuple< Sequences... > &seqs)
Definition: cross.hh:264
bool has(const std::map< Key, Value, Compare, Alloc > &s, const Key &e)
Definition: map.hh:53
void cross_tuple_(Fun f, const std::tuple< Ts... > &ts, awali::internal::index_sequence< I... >)
Definition: vector.hh:62
cross_sequences< Sequences... > cross(Sequences &&... seqs)
Definition: cross.hh:257
std::vector< typename Cont::value_type > to_vector(const Cont &cont)
Return the content of cont as a vector.
Definition: vector.hh:72
Main namespace of Awali.
Definition: ato.hh:22