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