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