28 #ifndef __RTTR_MISC_TYPE_TRAITS_H__
29 #define __RTTR_MISC_TYPE_TRAITS_H__
35 #include <type_traits>
47 struct raw_type {
typedef T type; };
49 template<
class T>
struct raw_type<const T> {
typedef typename raw_type<T>::type type; };
51 template<
class T>
struct raw_type<T*> {
typedef typename raw_type<T>::type type; };
52 template<
class T>
struct raw_type<T*
const> {
typedef typename raw_type<T>::type type; };
53 template<
class T>
struct raw_type<T*
volatile> {
typedef typename raw_type<T>::type type; };
55 template<
class T>
struct raw_type<T&> {
typedef typename raw_type<T>::type type; };
56 template<
class T, std::
size_t N>
57 struct raw_type<const T[N]> {
typedef typename raw_type<T[N]>::type type; };
62 template <
bool... b>
struct static_all_of;
64 template <
bool... tail>
65 struct static_all_of<true, tail...> : static_all_of<tail...> {};
67 template <
bool... tail>
68 struct static_all_of<false, tail...> : std::false_type {};
71 template <>
struct static_all_of<> : std::true_type {};
78 template <
bool... b>
struct static_any_of;
80 template <
bool... tail>
81 struct static_any_of<true, tail...> : std::true_type {};
83 template <
bool... tail>
84 struct static_any_of<false, tail...> : static_any_of<tail...> {};
87 template <>
struct static_any_of<> : std::false_type {};
95 class has_get_type_func_impl
97 typedef char YesType[1];
98 typedef char NoType[2];
100 template <
typename U, rttr::type (U::*)() const>
103 template <
typename C>
104 static YesType& f(check<C, &C::get_type>*);
106 template <
typename C>
107 static NoType& f(...);
110 static const bool value = (
sizeof(f<typename raw_type<T>::type>(0)) ==
sizeof(YesType));
116 template<
class T,
typename Enable =
void>
117 struct has_get_type_func : std::false_type
121 struct has_get_type_func<T, typename std::enable_if<has_get_type_func_impl<T>::value>::type > : std::true_type
130 template <
typename T>
131 class has_get_ptr_func_impl
133 typedef char YesType[1];
134 typedef char NoType[2];
136 template <
typename U,
void* (U::*)()>
139 template <
typename C>
140 static YesType& f(check<C, &C::get_ptr>*);
142 template <
typename C>
143 static NoType& f(...);
146 static const bool value = (
sizeof(f<typename raw_type<T>::type>(0)) ==
sizeof(YesType));
152 template<
class T,
typename Enable =
void>
153 struct has_get_ptr_func : std::false_type
157 struct has_get_ptr_func<T, typename std::enable_if<has_get_ptr_func_impl<T>::value>::type > : std::true_type
166 template <
typename T>
167 class has_get_derived_info_func_impl
169 typedef char YesType[1];
170 typedef char NoType[2];
172 template <
typename U, derived_info (U::*)()>
175 template <
typename C>
176 static YesType& f(check<C, &C::get_derived_info>*);
178 template <
typename C>
179 static NoType& f(...);
182 static const bool value = (
sizeof(f<typename raw_type<T>::type>(0)) ==
sizeof(YesType));
188 template<
class T,
typename Enable =
void>
189 struct has_get_derived_info_func : std::false_type
193 struct has_get_derived_info_func<T, typename std::enable_if<has_get_derived_info_func_impl<T>::value>::type > : std::true_type
203 return const_cast<void*
>(
reinterpret_cast<const void*
>(&data));
208 struct get_ptr_impl<T*>
212 return get_ptr_impl<T>::get(*data);
217 struct get_ptr_impl<void*>
226 struct get_ptr_impl<const void*>
230 return const_cast<void*
>(data);
237 return get_ptr_impl<T*>::get(data);
243 return get_ptr_impl<T>::get(data);
248 template<
typename T,
typename... Types>
249 struct contains : static_any_of<std::is_same<T, Types>::value...>
253 template<
typename T,
typename... Types,
template<
class...>
class TContainer>
254 struct contains<T, TContainer<Types...>> : contains<T, Types...>
260 template <
typename T>
263 typedef char YesType[1];
264 typedef char NoType[2];
266 template <
typename U>
static NoType& check(
typename U::no_array_type*);
267 template <
typename U>
static YesType& check(...);
270 static const bool value = (
sizeof(check<array_mapper<T> >(0)) ==
sizeof(YesType));
274 struct is_array : std::conditional<is_array_impl<T>::value,
276 std::false_type>::type
287 template <
typename... T>
288 struct concat_array_types;
291 template <
template <
typename ...>
class List,
typename ...Types,
typename T>
292 struct concat_array_types<List<Types...>, T, std::true_type>
294 using type = List<Types...>;
297 template <
template <
typename... >
class List, typename... Types, typename T>
298 struct concat_array_types<List<Types...>, T, std::false_type>
300 using sub_type =
typename array_mapper<T>::sub_type;
301 using type =
typename concat_array_types< List<Types..., T>, sub_type,
typename std::is_same<T, sub_type>::type>::type;
305 struct array_rank_type_list
307 using sub_type =
typename array_mapper<T>::sub_type;
308 using types =
typename concat_array_types< std::tuple<>, T,
typename std::is_same<T, sub_type>::type>::type;
311 template<
typename T,
size_t N>
314 using type =
typename std::tuple_element<N, typename array_rank_type_list<T>::types>::type;
322 template <
typename... T>
325 using type =
typename std::integral_constant<std::size_t, 0>::type;
328 template <
template <
typename... >
class List, typename... Types>
329 struct rank_impl<List<Types...>>
331 using type =
typename std::integral_constant<std::size_t,
sizeof...(Types) - 1>::type;
335 using rank =
typename rank_impl< typename detail::array_rank_type_list<T>::types >::type;
343 struct pointer_count_impl
345 static const std::size_t size = 0;
350 struct pointer_count_impl<T*>
352 static const std::size_t size = pointer_count_impl<T>::size + 1;
358 struct pointer_count : std::integral_constant<std::size_t, pointer_count_impl<T>::size>
367 struct char_array_impl : std::false_type
372 template<std::
size_t N>
373 struct char_array_impl<char[N]> : std::true_type
378 using is_char_array = char_array_impl<T>;
381 struct is_one_dim_char_array : std::integral_constant<bool, is_char_array<T>::value && (std::rank<T>::value == 1)>
385 struct is_array_and_not_one_dim_char_array : std::integral_constant<bool, std::is_array<T>::value && !is_one_dim_char_array<T>::value>
396 #endif // __RTTR_MISC_TYPE_TRAITS_H__
#define RTTR_INLINE
Definition: core_prerequisites.h:90