CPP Homework 04
Exercise from OTUS C++ developer course.
traits.h
Go to the documentation of this file.
1 #ifndef TRAITS_H
2 #define TRAITS_H
3 
4 #include <type_traits>
5 
7 
14 template <typename T, typename = void>
15 struct is_iterable: std::false_type { };
16 
24 template <typename T>
25 struct is_iterable<
26  T,
27  std::void_t<
28  typename T::iterator,
29  decltype(std::declval<T>().begin()),
30  decltype(std::declval<T>().end())
31  >>: public std::true_type {};
32 
33 /* @brief Alias for is_iterable<T>::value.
34  *
35  * @param T Type to test.
36  */
37 template <typename T>
39 
40 // Attribution to https://stackoverflow.com/a/11251408/7486328.
49 template <template <typename ...> class T, typename = void>
50 struct is_specialisation_of: std::false_type { };
51 
63 template <template <typename ...> class T, typename ... Args>
64 struct is_specialisation_of<T, T<Args...>>: std::true_type { };
65 
66 /* @brief Alias for is_specialisation_of<T>::value.
67  *
68  * @param T Type to compare with.
69  * @param U Type to compare for.
70  */
71 template <template <typename ...> class T, typename U>
73 
75 
76 #endif
constexpr bool is_iterable_v
Definition: traits.h:38
Compile-time function to check can be instance iterated.
Definition: traits.h:15
constexpr bool is_specialisation_of_v
Definition: traits.h:72
Compile-time function to check whether one type is a specialisation of another.
Definition: traits.h:50