Awali
Another Weighted Automata library
is_iterable.hxx
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_IS_ITERABLE_HXX
18 #define AWALI_IS_ITERABLE_HXX
19 
20 #include<type_traits>
22 #include<iterator>
23 
24 namespace awali {
25 
26 
27 namespace internal {
28 
29  template <typename T, typename P>
31  -> decltype (
32  /* test begin and and := */
33  std::begin(std::declval<T&>()) != std::end(std::declval<T&>()),
34  void(), // Handle evil operator ,
35  ++std::declval<decltype(std::begin(std::declval<T&>()))&>(), // operator ++
36  void(*std::begin(std::declval<T&>())), // operator*
37  std::true_type{}
38  );
39 
40  template <typename T, typename P>
42 
43 }// end of namespace awali::internal
44 
46 template <typename T>
47 using is_iterable = decltype(internal::is_iterable_aux1<T>(priority::value));
48 
49 
50 namespace internal {
51  template <bool... T>
52  struct std_all {};
53 
54  template <>
55  struct std_all<> : std::true_type {};
56 
57  template <bool... Tail>
58  struct std_all<false, Tail...> : std::false_type {};
59 
60  template <bool... Tail>
61  struct std_all<true, Tail...> : std_all<Tail...> {};
62 
63 // template <typename T, typename X, typename P>
64 // auto is_iterable_aux2(priority::HIGH<P>)
65 // -> typename std::enable_if<
66 // std_all<is_iterable<T>::value,
67 // std::is_assignable<X&,
68 // decltype(*std::begin(std::declval<T&>()))
69 // >::value
70 // >::value,
71 // std::true_type
72 // >::type;
73 
74 template <typename T, typename X, typename P>
76 -> typename std::enable_if<
78  std::is_convertible<
79  decltype(*std::begin(std::declval<T&>())), X
80  >::value
81  >::value,
82  std::true_type
83  >::type;
84 
85 template <typename T, typename X, typename P>
87 
88 
89 }// end of namespace awali::internal
90 
91 
96 template <typename T, typename X>
97 using is_iterable_with = decltype(internal::is_iterable_aux2<T,X>(priority::value));
98 
99 
100 }// end of namespace awali
101 
102 #endif
auto is_iterable_aux1(priority::TOP< P >) -> decltype(std::begin(std::declval< T & >()) !=std::end(std::declval< T & >()), void(),++std::declval< decltype(std::begin(std::declval< T & >()))& >(), void(*std::begin(std::declval< T & >())), std::true_type{})
auto is_iterable_aux2(priority::TOP< P >) -> typename std::enable_if< std_all< is_iterable< T >::value, std::is_convertible< decltype(*std::begin(std::declval< T & >())), X >::value >::value, std::true_type >::type
Definition: is_iterable.hxx:52
static constexpr TOP< void > value
Definition: priority.hh:93
Definition: priority.hh:52
Main namespace of Awali.
Definition: ato.hh:22
decltype(internal::is_iterable_aux2< T, X >(priority::value)) is_iterable_with
Trait to test whether type T can be iterated over and assign its values to type X.
Definition: is_iterable.hxx:97
decltype(internal::is_iterable_aux1< T >(priority::value)) is_iterable
Trait to test whether type T can be iterated over.
Definition: is_iterable.hxx:47