1 #ifndef TURI_TYPE_TRAITS_H_ 2 #define TURI_TYPE_TRAITS_H_ 6 #include <unordered_map> 9 #include <core/generics/gl_vector.hpp> 10 #include <core/generics/gl_string.hpp> 15 template <
typename T>
class gl_vector;
17 struct invalid_type {};
18 struct _invalid_type_base {
typedef invalid_type type; };
23 template<
class... T>
struct is_std_vector :
public std::false_type {};
24 template<
typename... A>
struct is_std_vector<
std::vector<A...> > :
public std::true_type {};
29 template<
class... T>
struct is_gl_vector :
public std::false_type {};
30 template<
typename... A>
struct is_gl_vector<gl_vector<A...> > :
public std::true_type {};
35 template<
typename... A>
struct is_vector {
36 static constexpr
bool value = (is_std_vector<A...>::value || is_gl_vector<A...>::value);
42 template<
typename... T>
struct is_deque :
public std::false_type {};
43 template<
typename... A>
struct is_deque<std::deque<A...> > :
public std::true_type {};
48 template<
typename... T>
struct is_list :
public std::false_type {};
49 template<
typename... A>
struct is_list<std::list<A...> > :
public std::true_type {};
54 template<
typename... A>
struct is_sequence_container {
55 static constexpr
bool value =
56 (is_vector<A...>::value || is_deque<A...>::value || is_list<A...>::value);
62 template<
class T>
struct is_std_map :
public std::false_type {};
63 template<
typename... A>
struct is_std_map<std::map<A...> > :
public std::true_type {};
68 template<
class T>
struct is_std_unordered_map :
public std::false_type {};
69 template<
typename... A>
struct is_std_unordered_map<std::unordered_map<A...> > :
public std::true_type {};
74 template<
class T>
struct is_boost_unordered_map :
public std::false_type {};
75 template<
typename... A>
struct is_boost_unordered_map<
boost::unordered_map<A...> > :
public std::true_type {};
80 template<
typename... A>
struct is_map {
81 static constexpr
bool value = (is_std_map<A...>::value
82 || is_std_unordered_map<A...>::value
83 || is_boost_unordered_map<A...>::value);
89 template<
class T>
struct is_std_pair :
public std::false_type {};
90 template<
typename... A>
struct is_std_pair<std::pair<A...> > :
public std::true_type {};
96 template<
class... T>
struct is_std_string :
public std::false_type {};
97 template <>
struct is_std_string<std::string> :
public std::true_type {};
102 template<
class... T>
struct is_gl_string :
public std::false_type {};
103 template <>
struct is_gl_string<gl_string> :
public std::true_type {};
108 template<
typename... A>
struct is_string {
109 static constexpr
bool value = (is_std_string<A...>::value || is_gl_string<A...>::value);
115 template<
class T>
struct is_tuple :
public std::false_type {};
116 template<
typename... A>
struct is_tuple<std::tuple<A...> > :
public std::true_type {};
128 typedef invalid_type type;
131 template<
class T,
typename... A,
template <
typename...>
class C>
136 template<
class T,
template <
typename>
class C>
150 typedef invalid_type type;
153 template<
class T,
class U,
typename... A,
template <
typename...>
class C>
158 template<
class T,
class U,
template <
typename...>
class C>
169 template <
template <
typename>
class P,
typename...>
170 struct all_true :
public std::false_type {};
172 template <
template <
typename>
class P,
class T>
173 struct all_true<P, T> {
174 static constexpr
bool value = P<T>::value;
177 template<
template <
typename>
class P,
class T,
typename ... Args>
178 struct all_true<P, T, Args...> {
179 static constexpr
bool value = (P<T>::value && all_true<P, Args...>::value);
189 template <
template <
typename>
class P,
typename...>
struct all_nested_true :
public std::false_type {};
191 template<
template <
typename>
class P,
template <
typename...>
class C,
typename... Args>
192 struct all_nested_true<P, C<Args...> > {
193 static constexpr
bool value = all_true<P, Args...>::value;
206 template <bool,
template <
typename...>
class Cond,
typename... Args>
struct conditional_test 207 :
public std::false_type {};
209 template <
template <
typename...>
class Cond,
typename... Args>
212 template <
template <
typename...>
class _Cond,
typename... _Args>
213 static constexpr
bool _value(
typename std::enable_if<_Cond<_Args...>::value,
int>::type = 0) {
217 template <
template <
typename...>
class _Cond,
typename... _Args>
218 static constexpr
bool _value(
typename std::enable_if<!_Cond<_Args...>::value,
int>::type = 0) {
222 static constexpr
bool value = _value<Cond, Args...>();
228 template <
typename T>
struct fits_in_4bytes {
229 static constexpr
bool value = (
sizeof(T) <= 4);
232 template <
typename T>
struct is_integer_in_4bytes {
239 template<
typename T>
struct swallow_to_false : std::false_type {};
244 template <
typename T>
struct base_type {
typedef T type; };
245 template <
typename T>
struct base_type<T&> {
typedef T type; };
246 template <
typename T>
struct base_type<const T&> {
typedef T type; };
247 template <
typename T>
struct base_type<T&&> {
typedef T type; };