-
Notifications
You must be signed in to change notification settings - Fork 0
/
has_operator.h
82 lines (47 loc) · 3.3 KB
/
has_operator.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//
// Created by Eli Winkelman on 8/31/19.
//
#ifndef WEAK_TYPES_HAS_OPERATOR_H
#define WEAK_TYPES_HAS_OPERATOR_H
#include <type_traits>
template <class T, class U, class>
struct has_equal_impl : std::false_type {};
template <class T, class U> struct has_equal_impl<T, U, decltype(std::declval<T>() == std::declval<U>(), void())> : std::true_type {};
template <class T, class U> struct has_equal : has_equal_impl<T, U, void> {};
template <class T, class U, class>
struct has_not_equal_impl : std::false_type {};
template <class T, class U> struct has_not_equal_impl<T, U, decltype(std::declval<T>() != std::declval<U>(), void())> : std::true_type {};
template <class T, class U> struct has_not_equal : has_not_equal_impl<T, U, void> {};
template <class T, class U, class>
struct has_addition_impl : std::false_type {};
template <class T, class U> struct has_addition_impl<T, U, decltype(std::declval<T>() + std::declval<U>(), void())> : std::true_type {};
template <class T, class U> struct has_addition : has_addition_impl<T, U, void> {};
template <class T, class U, class>
struct has_subtraction_impl : std::false_type {};
template <class T, class U> struct has_subtraction_impl<T, U, decltype(std::declval<T>() - std::declval<U>(), void())> : std::true_type {};
template <class T, class U> struct has_subtraction : has_subtraction_impl<T, U, void> {};
template <class T, class U, class>
struct has_multiplication_impl : std::false_type {};
template <class T, class U> struct has_multiplication_impl<T, U, decltype(std::declval<T>() * std::declval<U>(), void())> : std::true_type {};
template <class T, class U> struct has_multiplication : has_multiplication_impl<T, U, void> {};
template <class T, class U, class>
struct has_division_impl : std::false_type {};
template <class T, class U> struct has_division_impl<T, U, decltype(std::declval<T>() / std::declval<U>(), void())> : std::true_type {};
template <class T, class U> struct has_division : has_division_impl<T, U, void> {};
template <class T, class U, class>
struct has_less_than_impl : std::false_type {};
template <class T, class U> struct has_less_than_impl<T, U, decltype(std::declval<T>() < std::declval<U>(), void())> : std::true_type {};
template <class T, class U> struct has_less_than : has_less_than_impl<T, U, void> {};
template <class T, class U, class>
struct has_greater_than_impl : std::false_type {};
template <class T, class U> struct has_greater_than_impl<T, U, decltype(std::declval<T>() > std::declval<U>(), void())> : std::true_type {};
template <class T, class U> struct has_greater_than : has_greater_than_impl<T, U, void> {};
template <class T, class U, class>
struct has_greater_than_equal_to_impl : std::false_type {};
template <class T, class U> struct has_greater_than_equal_to_impl<T, U, decltype(std::declval<T>() >= std::declval<U>(), void())> : std::true_type {};
template <class T, class U> struct has_greater_than_equal_to : has_greater_than_equal_to_impl<T, U, void> {};
template <class T, class U, class>
struct has_less_than_equal_to_impl : std::false_type {};
template <class T, class U> struct has_less_than_equal_to_impl<T, U, decltype(std::declval<T>() <= std::declval<U>(), void())> : std::true_type {};
template <class T, class U> struct has_less_than_equal_to : has_less_than_equal_to_impl<T, U, void> {};
#endif //WEAK_TYPES_HAS_OPERATOR_H