rippled
Loading...
Searching...
No Matches
Zero.h
1// Copyright (c) 2014, Tom Ritchford <tom@swirly.com>
2
3#pragma once
4
5namespace beast {
6
24struct Zero
25{
26 explicit Zero() = default;
27};
28
29namespace {
30static constexpr Zero zero{};
31}
32
34template <typename T>
35auto
36signum(T const& t)
37{
38 return t.signum();
39}
40
41namespace detail {
42namespace zero_helper {
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
48call_signum(T const& t)
49{
50 return signum(t);
51}
52
53} // namespace zero_helper
54} // namespace detail
55
56// Handle operators where T is on the left side using signum.
57
58template <typename T>
59bool
60operator==(T const& t, Zero)
61{
63}
64
65template <typename T>
66bool
67operator!=(T const& t, Zero)
68{
70}
71
72template <typename T>
73bool
74operator<(T const& t, Zero)
75{
77}
78
79template <typename T>
80bool
81operator>(T const& t, Zero)
82{
84}
85
86template <typename T>
87bool
88operator>=(T const& t, Zero)
89{
91}
92
93template <typename T>
94bool
95operator<=(T const& t, Zero)
96{
98}
99
100// Handle operators where T is on the right side by
101// reversing the operation, so that T is on the left side.
102
103template <typename T>
104bool
105operator==(Zero, T const& t)
106{
107 return t == zero;
108}
109
110template <typename T>
111bool
112operator!=(Zero, T const& t)
113{
114 return t != zero;
115}
116
117template <typename T>
118bool
119operator<(Zero, T const& t)
120{
121 return t > zero;
122}
123
124template <typename T>
125bool
126operator>(Zero, T const& t)
127{
128 return t < zero;
129}
130
131template <typename T>
132bool
133operator>=(Zero, T const& t)
134{
135 return t <= zero;
136}
137
138template <typename T>
139bool
140operator<=(Zero, T const& t)
141{
142 return t >= zero;
143}
144
145} // namespace beast
auto call_signum(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: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