Lodestar
An integrated real-time control package in C++
BinOpCheck.hpp
1 //
2 // Created by Hamza El-Kebir on 6/12/21.
3 //
4 
5 #ifndef LODESTAR_BINOPCHECK_HPP
6 #define LODESTAR_BINOPCHECK_HPP
7 
8 #include <type_traits>
9 
10 // See https://stackoverflow.com/a/29014938
11 template<class...>
12 struct voider {
13  using type = void;
14 };
15 template<class...Ts>
16 using void_t = typename voider<Ts...>::type;
17 
18 template<class T, class U, class BinaryOperation, class Enable = void>
19 struct is_binop_able_ : std::false_type {
20 };
21 template<class T, class U, class BinOp>
22 struct is_binop_able_<T, U, BinOp, void_t<
23  decltype(std::declval<BinOp>()(
24  std::declval<T>(), std::declval<U>()))>> :
25  std::true_type {
26 };
27 
28 template<class T, class U, class BinOp>
29 using is_binop_able = typename is_binop_able_<T, U, BinOp>::type;
30 
31 #define RETURNS(...) \
32  noexcept(noexcept(__VA_ARGS__)) \
33  ->decltype(__VA_ARGS__) { \
34  return (__VA_ARGS__); \
35  }
36 
37 struct plus {
38  template<class T, class U>
39  auto operator()(T t, U u) RETURNS(t + u)
40 };
41 
42 template<class T, class U = T>
43 using is_addable = is_binop_able<T, U, plus>;
44 
45 struct multiplies {
46  template<class T, class U>
47  auto operator()(T t, U u) RETURNS(t * u)
48 };
49 
50 template<class T, class U = T>
51 using is_multiplicable = is_binop_able<T, U, multiplies>;
52 
53 #undef RETURNS
54 
55 #endif //LODESTAR_BINOPCHECK_HPP
is_binop_able_
Definition: BinOpCheck.hpp:19
multiplies
Definition: BinOpCheck.hpp:45
voider
Definition: BinOpCheck.hpp:12
plus
Definition: BinOpCheck.hpp:37