IsIterable.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <type_traits>
7 
8 #include "Utilities/TypeTraits.hpp"
9 
10 namespace tt {
11 // @{
12 /// \ingroup TypeTraitsGroup
13 /// \brief Check if type T has a begin() and end() function
14 ///
15 /// \details
16 /// Given a type `T` inherits from std::true_type if `T` has member functions
17 /// `begin()` and `end()`, otherwise inherits from std::false_type
18 ///
19 /// \usage
20 /// For any type `T`
21 /// \code
22 /// using result = tt::is_iterable<T>;
23 /// \endcode
24 ///
25 /// \metareturns
26 /// cpp17::bool_constant
27 ///
28 /// \semantics
29 /// If `T` has member function `begin()` and `end()` then
30 /// \code
31 /// typename result::type = std::true_type;
32 /// \endcode
33 /// otherwise
34 /// \code
35 /// typename result::type = std::false_type;
36 /// \endcode
37 ///
38 /// \example
39 /// \snippet Test_IsIterable.cpp is_iterable_example
40 /// \tparam T the type to check
41 template <typename T, typename = cpp17::void_t<>>
43 
44 /// \cond HIDDEN_SYMBOLS
45 template <typename T>
46 struct is_iterable<T, cpp17::void_t<decltype(std::declval<T>().begin(),
47  std::declval<T>().end())>>
48  : std::true_type {};
49 /// \endcond
50 
51 /// \see is_iterable
52 template <typename T>
54 
55 /// \see is_iterable
56 template <typename T>
58 // @}
59 } // namespace tt
constexpr bool is_iterable_v
Definition: IsIterable.hpp:53
typename is_iterable< T >::type is_iterable_t
Definition: IsIterable.hpp:57
void void_t
Given a set of types, returns void
Definition: TypeTraits.hpp:187
A collection of useful type traits.
Definition: TensorExpression.hpp:113
Check if type T has a begin() and end() function.
Definition: IsIterable.hpp:42