| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#ifndef AAPT_UTIL_TYPETRAITS_H |
| 18 |
#define AAPT_UTIL_TYPETRAITS_H |
| 19 |
|
| 20 |
#include <type_traits> |
| 21 |
|
| 22 |
namespace aapt { |
| 23 |
|
| 24 |
#define DEFINE_HAS_BINARY_OP_TRAIT(name, op) \ |
| 25 |
template <typename T, typename U> \ |
| 26 |
struct name { \ |
| 27 |
template <typename V, typename W> \ |
| 28 |
static constexpr decltype(std::declval<V>() op std::declval<W>(), bool()) \ |
| 29 |
test(int) { \ |
| 30 |
return true; \ |
| 31 |
} \ |
| 32 |
template <typename V, typename W> \ |
| 33 |
static constexpr bool test(...) { \ |
| 34 |
return false; \ |
| 35 |
} \ |
| 36 |
static constexpr bool value = test<T, U>(int()); \ |
| 37 |
} |
| 38 |
|
| 39 |
DEFINE_HAS_BINARY_OP_TRAIT(has_eq_op, ==); |
| 40 |
DEFINE_HAS_BINARY_OP_TRAIT(has_lt_op, <); |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
template <typename T, typename U> |
| 46 |
struct is_comparable { |
| 47 |
static constexpr bool value = |
| 48 |
has_eq_op<T, U>::value && has_lt_op<T, U>::value; |
| 49 |
}; |
| 50 |
|
| 51 |
} |
| 52 |
|
| 53 |
#endif |