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