5 #ifndef LODESTAR_TEMPLATETRAITS_HPP
6 #define LODESTAR_TEMPLATETRAITS_HPP
10 #define RETURNS(...) \
11 noexcept(noexcept(__VA_ARGS__)) \
12 ->decltype(__VA_ARGS__) { \
13 return (__VA_ARGS__); \
21 template<
class,
template<
class...>
class>
23 static const bool value =
false;
26 template<
class... T,
template<
class...>
class U>
27 struct isInstance<U<T...>, U> :
public ::std::true_type {
28 static const bool value =
true;
40 template<
class R,
class... Ts>
41 using allConvertible = allTrue<::std::is_convertible<Ts, R>::value...>;
43 template<
class R,
class... Ts>
44 using allSame = allTrue<::std::is_same<Ts, R>::value...>;
46 template<
class R,
class... Ts>
47 using allBasedOf = allTrue<::std::is_base_of<R, Ts>::value...>;
50 using anyTrue = ::std::integral_constant<bool, !allFalse<bs...>::value>;
52 template<
class R,
class... Ts>
53 using anyConvertible = anyTrue<::std::is_convertible<Ts, R>::value...>;
61 template<
class T,
class U>
62 auto operator()(T t, U u) RETURNS(t + u)
66 template<
class T,
class U>
67 auto operator()(T t, U u) RETURNS(t - u)
71 template<
class T,
class U>
72 auto operator()(T t, U u) RETURNS(t * u)
76 template<
class T,
class U>
77 auto operator()(T t, U u) RETURNS(t / u)
87 using void_t =
typename voider<Ts...>::type;
89 template<
class T,
class U,
class BinaryOperation,
class Enable =
void>
91 using returnType = void;
94 template<
class T,
class U,
class BinOp>
96 decltype(::std::declval<BinOp>()(
97 ::std::declval<T>(), ::std::declval<U>()))>> :
99 using returnType = typename ::std::decay<decltype(::std::declval<BinOp>()(
100 ::std::declval<T>(), ::std::declval<U>()))>::type;
132 template<
template<
typename, int, int,
int...>
class TWrapper,
typename TScalar,
int TRows,
int TCols,
int... TOtherParams>
135 using scalar = TScalar;
141 template<
typename UScalar,
int URows,
int UCols,
int... UOtherParams>
142 using wrapper = TWrapper<UScalar, URows, UCols, UOtherParams...>;
151 template<
typename T,
class BinOp>
153 using returnType = T;
187 template<
class BinOp,
188 template<
typename,
typename,
int...>
class TWrapper,
190 template<
typename,
int...>
class TWrapperChild1,
191 template<
typename,
int...>
class TWrapperChild2,
197 TWrapperChild1<TScalar, TInts...>,
198 TWrapperChild2<UScalar, UInts...>,
199 TWrapperInts...>, BinOp>
202 using condition1 = typename ::std::conditional<
205 ::std::false_type>::type;
207 using condition2 = typename ::std::conditional<
214 using input = TWrapper<TWrapperChild1<TScalar, TInts...>, TWrapperChild2<UScalar, UInts...>>;
216 using sanitized = TWrapperChild1<typename ::std::decay<typename isBinopableImpl<TScalar, UScalar, BinOp>::returnType>::type,
parseMatrixLike<TWrapperChild1<TScalar, TInts...>>::rows,
parseMatrixLike<TWrapperChild2<UScalar, UInts...>>::cols>;
218 using returnType = typename ::std::conditional<
219 (allSame<::std::true_type, condition1, condition2>::value),
228 template<
class T,
class U,
class BinOp>
231 template<
class T,
class U = T>
234 template<
class T,
class U = T>
237 template<
class T,
class U = T>
240 template<
class T,
class U = T>
249 #endif //LODESTAR_TEMPLATETRAITS_HPP