Support Class Library
A set of tools providing classes and utility
type_check.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <type_traits>
4 #ifndef SCL_CPP17
6  #include <scl/tools/meta/exists.h>
7 #endif
8 
9 #define SCL_TYPECHECK(fn) \
10 template <class T>\
11 inline constexpr bool fn(){\
12  return std::fn<T>::value;\
13 }
14 
15 #define SCL_TYPECHECK_COMPOUND(fn) \
16 template <class T, class U>\
17 inline constexpr bool fn(){\
18  return std::fn<T, U>::value;\
19 }
20 
21 #define SCL_TYPECHECK_WITH_VARGS(fn)\
22 template <class T, class... Args>\
23 inline constexpr bool fn(){\
24  return std::fn<T, Args...>::value;\
25 }
26 
27 #define SCL_TYPECHECK_FN(fn)\
28 template <class F, class... Args>\
29 inline constexpr bool fn(){\
30  return std::fn<F, Args...>::value;\
31 }
32 
33 #define SCL_TYPECHECK_FN_R(fn)\
34 template <class R, class F, class... Args>\
35 inline constexpr bool fn(){\
36  return std::fn<R, F, Args...>::value;\
37 }
38 
39 namespace scl{
40  namespace tools{
41  namespace meta{
56 
64 
75 #ifdef SCL_ENABLE_DEPRECATED_TYPECHECKS
76  SCL_TYPECHECK(is_pod)
77  SCL_TYPECHECK(is_literal_type)
78 #endif
79 
80 #ifdef SCL_CPP14
81  SCL_TYPECHECK(is_final)
82 #endif
83 
84 #ifdef SCL_CPP17
85  SCL_TYPECHECK(is_aggregate)
86  SCL_TYPECHECK(has_unique_object_representations)
87 #endif
88 
92 
96 
100 
104 
108 
112 
117 
123  template <class T>
124  inline constexpr bool is_copyable(){
125  return is_copy_assignable<T>() && is_copy_constructible<T>();
126  }
127 
133  template <class T>
134  inline constexpr bool is_movable(){
135  return is_move_assignable<T>() && is_move_constructible<T>();
136  }
137 
143  template <class T>
144  inline constexpr bool is_trivially_movable(){
145  return is_trivially_move_assignable<T>() && is_trivially_move_constructible<T>();
146  }
147 
148 #ifdef SCL_CPP17
150  SCL_TYPECHECK(is_nothrow_swappable)
152  SCL_TYPECHECK_COMPOUND(is_nothrow_swappable_with)
153 
155  SCL_TYPECHECK_FN(is_nothrow_invocable)
156  SCL_TYPECHECK_FN(is_invocable_r)
157  SCL_TYPECHECK_FN_R(is_nothrow_invocable_r)
158 #else
159  template <class F, class... Args>
160  inline constexpr bool is_invocable(){
161 // return can_call<F, Args...>(std::declval<F>());
162  return exists<decltype(std::declval<F>()(std::declval<Args>()...))>();
163  }
164 #endif
165  }
166  }
167 }
168 
169 #ifndef SCL_CPP17
170  #include <scl/tools/meta/swap.h>
171 #endif
172 
173 #undef SCL_TYPECHECK
174 #undef SCL_TYPECHECK_COMPOUND
175 #undef SCL_TYPECHECK_WITH_VARGS
176 #undef SCL_TYPECHECK_FN
177 #undef SCL_TYPECHECK_FN_R
constexpr bool is_array()
Definition: type_check.h:46
constexpr bool is_movable()
Determines whether or not a type defines move semantics.
Definition: type_check.h:134
constexpr bool is_void()
Definition: type_check.h:42
constexpr bool is_copy_assignable()
Definition: type_check.h:105
#define SCL_TYPECHECK_COMPOUND(fn)
Definition: type_check.h:15
constexpr bool is_default_constructible()
Definition: type_check.h:93
constexpr bool is_object()
Definition: type_check.h:60
constexpr bool is_member_object_pointer()
Definition: type_check.h:54
constexpr bool is_unsigned()
Definition: type_check.h:74
#define SCL_TYPECHECK(fn)
Definition: type_check.h:9
constexpr bool is_trivially_copy_constructible()
Definition: type_check.h:98
constexpr bool is_empty()
Definition: type_check.h:70
constexpr bool is_nothrow_constructible()
Definition: type_check.h:91
Global namespace of the SCL.
Definition: alias.hpp:3
constexpr bool is_nothrow_default_constructible()
Definition: type_check.h:95
constexpr bool is_signed()
Definition: type_check.h:73
constexpr bool is_integral()
Definition: type_check.h:44
constexpr bool is_reference()
Definition: type_check.h:62
constexpr bool is_trivially_copy_assignable()
Definition: type_check.h:106
#define SCL_TYPECHECK_FN_R(fn)
Definition: type_check.h:33
constexpr bool is_move_assignable()
Definition: type_check.h:109
constexpr bool is_scalar()
Definition: type_check.h:59
constexpr bool is_union()
Definition: type_check.h:48
constexpr bool is_trivially_destructible()
Definition: type_check.h:114
constexpr bool is_class()
Definition: type_check.h:49
constexpr bool is_nothrow_copy_constructible()
Definition: type_check.h:99
constexpr bool is_null_pointer()
Definition: type_check.h:43
constexpr bool is_move_constructible()
Definition: type_check.h:101
constexpr bool is_enum()
Definition: type_check.h:47
constexpr bool is_swappable()
Definition: swap.h:43
constexpr bool is_rvalue_reference()
Definition: type_check.h:53
constexpr bool is_trivially_constructible()
Definition: type_check.h:90
constexpr bool is_swappable_with()
Definition: swap.h:28
constexpr bool is_function()
Definition: type_check.h:50
constexpr bool is_trivially_move_constructible()
Definition: type_check.h:102
constexpr bool is_nothrow_copy_assignable()
Definition: type_check.h:107
constexpr bool is_trivially_movable()
Determines whether or not a type defines trivial move semantics.
Definition: type_check.h:144
constexpr bool is_trivially_copyable()
Definition: type_check.h:68
constexpr bool is_member_pointer()
Definition: type_check.h:63
constexpr bool is_invocable()
Definition: type_check.h:160
constexpr bool is_fundamental()
Definition: type_check.h:57
constexpr bool is_const()
Definition: type_check.h:65
constexpr bool is_polymorphic()
Definition: type_check.h:71
constexpr bool is_member_function_pointer()
Definition: type_check.h:55
constexpr bool is_trivially_move_assignable()
Definition: type_check.h:110
constexpr bool is_compound()
Definition: type_check.h:61
constexpr bool is_nothrow_move_constructible()
Definition: type_check.h:103
constexpr bool is_constructible()
Definition: type_check.h:89
#define SCL_TYPECHECK_FN(fn)
Definition: type_check.h:27
constexpr bool is_standard_layout()
Definition: type_check.h:69
constexpr bool is_arithmetic()
Definition: type_check.h:58
constexpr bool is_abstract()
Definition: type_check.h:72
constexpr bool is_floating_point()
Definition: type_check.h:45
constexpr bool has_virtual_destructor()
Definition: type_check.h:116
constexpr bool is_lvalue_reference()
Definition: type_check.h:52
constexpr bool is_nothrow_move_assignable()
Definition: type_check.h:111
constexpr bool is_copyable()
Determines whether or not a type defines copy semantics.
Definition: type_check.h:124
constexpr bool is_nothrow_destructible()
Definition: type_check.h:115
constexpr bool is_copy_constructible()
Definition: type_check.h:97
constexpr bool is_trivially_default_constructible()
Definition: type_check.h:94
constexpr bool is_destructible()
Definition: type_check.h:113
constexpr bool is_volatile()
Definition: type_check.h:66
#define SCL_TYPECHECK_WITH_VARGS(fn)
Definition: type_check.h:21
constexpr bool is_trivial()
Definition: type_check.h:67
constexpr bool is_pointer()
Definition: type_check.h:51