NumCpp  2.4.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
TypeTraits.hpp
Go to the documentation of this file.
1 #pragma once
29 
30 #include <complex>
31 #include <type_traits>
32 
33 namespace nc
34 {
35  //============================================================================
36  // Class Description:
39  template<bool B, class T = void>
40  using enable_if_t = typename std::enable_if<B, T>::type;
41 
42  //============================================================================
43  // Class Description:
46  template<class A, class B>
47  constexpr bool is_same_v = std::is_same<A, B>::value;
48 
49  //============================================================================
50  // Class Description:
53  template<typename T>
54  constexpr bool is_arithmetic_v = std::is_arithmetic<T>::value;
55 
56  //============================================================================
57  // Class Description:
60  template<typename T>
61  constexpr bool is_integral_v = std::is_integral<T>::value;
62 
63  //============================================================================
64  // Class Description:
67  template<typename T>
68  constexpr bool is_floating_point_v = std::is_floating_point<T>::value;
69 
70  //============================================================================
71  // Class Description:
74  template <typename... Ts>
76 
77  //============================================================================
78  // Class Description:
81  template <typename Head, typename... Tail>
82  struct all_arithmetic<Head, Tail...>
83  {
84  static constexpr bool value = std::is_arithmetic<Head>::value && all_arithmetic<Tail...>::value;
85  };
86 
87  //============================================================================
88  // Class Description:
91  template <typename T>
92  struct all_arithmetic<T>
93  {
94  static constexpr bool value = std::is_arithmetic<T>::value;
95  };
96 
97  //============================================================================
98  // Class Description:
101  template<typename... Ts>
102  constexpr bool all_arithmetic_v = all_arithmetic<Ts...>::value;
103 
104  //============================================================================
105  // Class Description:
108  template <typename T1, typename... Ts>
109  struct all_same;
110 
111  //============================================================================
112  // Class Description:
115  template <typename T1, typename Head, typename... Tail>
116  struct all_same<T1, Head, Tail...>
117  {
118  static constexpr bool value = std::is_same<T1, Head>::value && all_same<T1, Tail...>::value;
119  };
120 
121  //============================================================================
122  // Class Description:
125  template <typename T1, typename T2>
126  struct all_same<T1, T2>
127  {
128  static constexpr bool value = std::is_same<T1, T2>::value;
129  };
130 
131  //============================================================================
132  // Class Description:
135  template<typename... Ts>
136  constexpr bool all_same_v = all_same<Ts...>::value;
137 
138  //============================================================================
139  // Class Description:
142  template<typename dtype>
144  {
145  static constexpr bool value = std::is_default_constructible<dtype>::value &&
146  std::is_nothrow_copy_constructible<dtype>::value &&
147  std::is_nothrow_move_constructible<dtype>::value &&
148  std::is_nothrow_copy_assignable<dtype>::value &&
149  std::is_nothrow_move_assignable<dtype>::value &&
150  std::is_nothrow_destructible<dtype>::value &&
151  !std::is_void<dtype>::value &&
152  !std::is_pointer<dtype>::value &&
153  !std::is_array<dtype>::value &&
154  !std::is_union<dtype>::value &&
155  !std::is_function<dtype>::value &&
156  !std::is_abstract<dtype>::value;
157  };
158 
159  //============================================================================
160  // Class Description:
163  template<class dtype>
165 
166  //============================================================================
167  // Class Description:
170  template<class T>
171  struct is_complex
172  {
173  static constexpr bool value = false;
174  };
175 
176  //============================================================================
177  // Class Description:
180  template<class T>
181  struct is_complex<std::complex<T>>
182  {
183  static constexpr bool value = true;
184  };
185 
186  //============================================================================
187  // Class Description:
190  template<class T>
192 } // namespace nc
nc::enable_if_t
typename std::enable_if< B, T >::type enable_if_t
Definition: TypeTraits.hpp:40
nc::all_arithmetic
Definition: TypeTraits.hpp:75
nc::complex
auto complex(dtype inReal)
Definition: complex.hpp:48
nc::is_arithmetic_v
constexpr bool is_arithmetic_v
Definition: TypeTraits.hpp:54
nc::is_valid_dtype::value
static constexpr bool value
Definition: TypeTraits.hpp:145
nc::is_integral_v
constexpr bool is_integral_v
Definition: TypeTraits.hpp:61
nc::is_complex_v
constexpr bool is_complex_v
Definition: TypeTraits.hpp:191
nc::all_arithmetic_v
constexpr bool all_arithmetic_v
Definition: TypeTraits.hpp:102
nc::is_floating_point_v
constexpr bool is_floating_point_v
Definition: TypeTraits.hpp:68
nc::is_same_v
constexpr bool is_same_v
Definition: TypeTraits.hpp:47
nc::all_same
Definition: TypeTraits.hpp:109
nc
Definition: Coordinate.hpp:44
nc::is_valid_dtype_v
constexpr bool is_valid_dtype_v
Definition: TypeTraits.hpp:164
nc::all_same_v
constexpr bool all_same_v
Definition: TypeTraits.hpp:136
nc::is_complex::value
static constexpr bool value
Definition: TypeTraits.hpp:173
nc::is_complex
Definition: TypeTraits.hpp:171
nc::is_valid_dtype
Definition: TypeTraits.hpp:143