rippled
Loading...
Searching...
No Matches
Zero.h
1// Copyright (c) 2014, Tom Ritchford <tom@swirly.com>
2
3#ifndef BEAST_UTILITY_ZERO_H_INCLUDED
4#define BEAST_UTILITY_ZERO_H_INCLUDED
5
6namespace beast {
7
25struct Zero
26{
27 explicit Zero() = default;
28};
29
30namespace {
31static constexpr Zero zero{};
32}
33
35template <typename T>
36auto
37signum(T const& t)
38{
39 return t.signum();
40}
41
42namespace detail {
43namespace zero_helper {
44
45// For argument dependent lookup to function properly, calls to signum must
46// be made from a namespace that does not include overloads of the function..
47template <class T>
48auto
49call_signum(T const& t)
50{
51 return signum(t);
52}
53
54} // namespace zero_helper
55} // namespace detail
56
57// Handle operators where T is on the left side using signum.
58
59template <typename T>
60bool
61operator==(T const& t, Zero)
62{
64}
65
66template <typename T>
67bool
68operator!=(T const& t, Zero)
69{
71}
72
73template <typename T>
74bool
75operator<(T const& t, Zero)
76{
78}
79
80template <typename T>
81bool
82operator>(T const& t, Zero)
83{
85}
86
87template <typename T>
88bool
89operator>=(T const& t, Zero)
90{
92}
93
94template <typename T>
95bool
96operator<=(T const& t, Zero)
97{
99}
100
101// Handle operators where T is on the right side by
102// reversing the operation, so that T is on the left side.
103
104template <typename T>
105bool
106operator==(Zero, T const& t)
107{
108 return t == zero;
109}
110
111template <typename T>
112bool
113operator!=(Zero, T const& t)
114{
115 return t != zero;
116}
117
118template <typename T>
119bool
120operator<(Zero, T const& t)
121{
122 return t > zero;
123}
124
125template <typename T>
126bool
127operator>(Zero, T const& t)
128{
129 return t < zero;
130}
131
132template <typename T>
133bool
134operator>=(Zero, T const& t)
135{
136 return t <= zero;
137}
138
139template <typename T>
140bool
141operator<=(Zero, T const& t)
142{
143 return t >= zero;
144}
145
146} // namespace beast
147
148#endif
auto call_signum(T const &t)
Definition Zero.h:49
bool operator<=(SemanticVersion const &lhs, SemanticVersion const &rhs)
bool operator>=(SemanticVersion const &lhs, SemanticVersion const &rhs)
bool operator>(SemanticVersion const &lhs, SemanticVersion const &rhs)
auto signum(T const &t)
Default implementation of signum calls the method on the class.
Definition Zero.h:37
bool operator<(SemanticVersion const &lhs, SemanticVersion const &rhs)
bool operator==(LockFreeStackIterator< Container, LhsIsConst > const &lhs, LockFreeStackIterator< Container, RhsIsConst > const &rhs)
bool operator!=(LockFreeStackIterator< Container, LhsIsConst > const &lhs, LockFreeStackIterator< Container, RhsIsConst > const &rhs)
Zero allows classes to offer efficient comparisons to zero.
Definition Zero.h:26
Zero()=default