17 #ifndef TYPE_OPERATORS_HPP
18 #define TYPE_OPERATORS_HPP
25 template<
int bound,
int dim>
27 constexpr
static bool value = dim > 0 && dim <= bound;
33 template<
class T,
int dim>
35 static_assert(dim > 0,
"Dimension less than one passed to getter");
36 static_assert(std::is_floating_point<T>::value,
"Non floating-point type used with standard getter");
37 static inline T&
pull(T& inval){
42 template<
class T,
int dim>
44 static_assert(dim > 0,
"Dimension less than one passed to getter");
45 static_assert(std::is_floating_point<T>::value,
"Non floating-point type used with standard getter");
47 static inline T&
pull(T(& array)[N]){
48 static_assert(dim <= N,
"Dimension higher than array dimension used");
54 template<
class T,
int dim>
56 static_assert(dim > 0,
"Dimension less than one passed to getter");
57 static_assert(std::is_floating_point<T>::value,
"Non floating-point type used with standard getter");
59 static inline T&
pull(T* inval){
67 template<
class T,
size_t dim,
bool is_first>
70 T& cur = ((T*)&pullfrom)[0];
77 template<
class T,
size_t dim>
80 T& cur = ((T*)&pullfrom)[1];
96 template<
class T,
int dim>
97 struct get<std::complex<T>, dim>{
99 "Dimension used outside the range of complex values");
102 constexpr
static bool is_first = dim <= float_traits<T>::dim;
108 template<
class T,
int dim>
117 template<
class T,
int dim>
126 template<class T, size_t dim = float_traits<T>::dim>
135 static_assert(dim >= 1,
"A dimension less then one has been given to the apply structure");
169 template<
class Lambda>
171 std::forward<Lambda>(func)(
get(inval), dim);
198 template<
template<
size_t>
class Lambda>
200 Lambda<dim>::apply(inval);
201 apply<T, dim-1>::template transform<Lambda>(inval);
209 template<
class Lambda,
class Final>
210 static inline void transform(T& inval, Lambda&& func, Final&& finish){
212 std::forward<Final>(finish)(inval);
215 template<
class Lambda,
class Trans>
216 static inline void map_into(
const T& inval, Lambda&& func, Trans& outval){
218 "The dimension of the Trans type is not equal to the dimension of the T type");
223 template<
class Lambda,
class Trans>
224 static inline Trans
map(
const T& inval, Lambda&& func){
226 map_into(inval, std::forward<Lambda>(func), val);
230 template<
class Lambda,
class Trans,
class constr,
class postop>
231 static inline Trans
map(
const T& inval, Lambda&& func,
232 postop&& finish, constr&& build){
233 Trans val = std::forward<constr>(build)();
234 map_into(inval, std::forward<Lambda>(func), val);
235 std::forward<postop>(finish)(val);
242 static constexpr
size_t dim=1;
248 template<
class Lambda>
250 std::forward<Lambda>(func)(
get(inval), 1);
252 template<
template<
size_t>
class Lambda>
254 Lambda<1>::apply(inval);
256 template<
class Lambda,
class Final>
257 static inline void transform(T& inval, Lambda&& func, Final&& finish){
258 std::forward<Lambda>(func)(
get(inval), 1);
259 std::forward<Final>(finish)(inval);
261 template<
class Lambda,
class Trans>
262 static inline void map_into(
const T& inval, Lambda&& func, Trans& outval){
263 get(outval) = std::forward<Lambda>(func)(
get(inval), 1);