rippled
Loading...
Searching...
No Matches
Zero.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of Beast: https://github.com/vinniefalco/Beast
4 Copyright 2014, Tom Ritchford <tom@swirly.com>
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef BEAST_UTILITY_ZERO_H_INCLUDED
21#define BEAST_UTILITY_ZERO_H_INCLUDED
22
23namespace beast {
24
42struct Zero
43{
44 explicit Zero() = default;
45};
46
47namespace {
48static constexpr Zero zero{};
49}
50
52template <typename T>
53auto
54signum(T const& t)
55{
56 return t.signum();
57}
58
59namespace detail {
60namespace zero_helper {
61
62// For argument dependent lookup to function properly, calls to signum must
63// be made from a namespace that does not include overloads of the function..
64template <class T>
65auto
66call_signum(T const& t)
67{
68 return signum(t);
69}
70
71} // namespace zero_helper
72} // namespace detail
73
74// Handle operators where T is on the left side using signum.
75
76template <typename T>
77bool
78operator==(T const& t, Zero)
79{
81}
82
83template <typename T>
84bool
85operator!=(T const& t, Zero)
86{
88}
89
90template <typename T>
91bool
92operator<(T const& t, Zero)
93{
95}
96
97template <typename T>
98bool
99operator>(T const& t, Zero)
100{
102}
103
104template <typename T>
105bool
106operator>=(T const& t, Zero)
107{
109}
110
111template <typename T>
112bool
113operator<=(T const& t, Zero)
114{
116}
117
118// Handle operators where T is on the right side by
119// reversing the operation, so that T is on the left side.
120
121template <typename T>
122bool
123operator==(Zero, T const& t)
124{
125 return t == zero;
126}
127
128template <typename T>
129bool
130operator!=(Zero, T const& t)
131{
132 return t != zero;
133}
134
135template <typename T>
136bool
137operator<(Zero, T const& t)
138{
139 return t > zero;
140}
141
142template <typename T>
143bool
144operator>(Zero, T const& t)
145{
146 return t < zero;
147}
148
149template <typename T>
150bool
151operator>=(Zero, T const& t)
152{
153 return t <= zero;
154}
155
156template <typename T>
157bool
158operator<=(Zero, T const& t)
159{
160 return t >= zero;
161}
162
163} // namespace beast
164
165#endif
auto call_signum(T const &t)
Definition: Zero.h:66
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:54
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:43
Zero()=default