MSTL 1.4.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
inumeric.hpp
浏览该文件的文档.
1#ifndef MSTL_CORE_INTERFACE_INUMERIC_HPP__
2#define MSTL_CORE_INTERFACE_INUMERIC_HPP__
3
11
14
20
29template <typename T>
31private:
36 constexpr const T& derived() const noexcept {
37 return static_cast<const T&>(*this);
38 }
39
44 constexpr T& derived() noexcept {
45 return static_cast<T&>(*this);
46 }
47
48public:
54 MSTL_NODISCARD MSTL_CONSTEXPR14 T operator +(const T& other) const
55 noexcept(noexcept(const_cast<T&>(derived()).operator+=(other))) {
56 T tmp(derived());
57 tmp += other;
58 return tmp;
59 }
60
66 MSTL_NODISCARD MSTL_CONSTEXPR14 T operator -(const T& other) const
67 noexcept(noexcept(const_cast<T&>(derived()).operator-=(other))) {
68 T tmp(derived());
69 tmp -= other;
70 return tmp;
71 }
72
78 MSTL_NODISCARD MSTL_CONSTEXPR14 T operator *(const T& other) const
79 noexcept(noexcept(const_cast<T&>(derived()).operator*=(other))) {
80 T tmp(derived());
81 tmp *= other;
82 return tmp;
83 }
84
90 MSTL_NODISCARD MSTL_CONSTEXPR14 T operator /(const T& other) const
91 noexcept(noexcept(const_cast<T&>(derived()).operator/=(other))) {
92 T tmp(derived());
93 tmp /= other;
94 return tmp;
95 }
96
102 MSTL_NODISCARD MSTL_CONSTEXPR14 T operator %(const T& other) const
103 noexcept(noexcept(const_cast<T&>(derived()).operator%=(other))) {
104 T tmp(derived());
105 tmp %= other;
106 return tmp;
107 }
108
113 MSTL_NODISCARD MSTL_CONSTEXPR14 T operator -() const
114 noexcept(noexcept(derived().operator-())) {
115 return derived().operator-();
116 }
117
123 MSTL_CONSTEXPR14 T& operator +=(const T& other)
124 noexcept(noexcept(derived().operator+=(other))) {
125 return derived().operator+=(other);
126 }
127
133 MSTL_CONSTEXPR14 T& operator -=(const T& other)
134 noexcept(noexcept(derived().operator-=(other))) {
135 return derived().operator-=(other);
136 }
137
143 MSTL_CONSTEXPR14 T& operator *=(const T& other)
144 noexcept(noexcept(derived().operator*=(other))) {
145 return derived().operator*=(other);
146 }
147
153 MSTL_CONSTEXPR14 T& operator /=(const T& other) {
154 return derived().operator/=(other);
155 }
156
162 MSTL_CONSTEXPR14 T& operator %=(const T& other) {
163 return derived().operator%=(other);
164 }
165
170 MSTL_CONSTEXPR14 T& operator ++()
171 noexcept(noexcept(derived().operator++())) {
172 return derived().operator++();
173 }
174
179 MSTL_CONSTEXPR14 T operator ++(int)
180 noexcept(noexcept(derived().operator++())) {
181 T tmp(derived());
182 ++derived();
183 return tmp;
184 }
185
190 MSTL_CONSTEXPR14 T& operator --()
191 noexcept(noexcept(derived().operator--())) {
192 return derived().operator--();
193 }
194
199 MSTL_CONSTEXPR14 T operator --(int)
200 noexcept(noexcept(derived().operator--())) {
201 T tmp(derived());
202 --derived();
203 return tmp;
204 }
205};
206
207
216template <typename T>
217struct ibinary {
218private:
223 constexpr const T& derived() const noexcept {
224 return static_cast<const T&>(*this);
225 }
226
231 constexpr T& derived() noexcept {
232 return static_cast<T&>(*this);
233 }
234
235public:
241 MSTL_NODISCARD MSTL_CONSTEXPR14 T operator &(const T& other) const
242 noexcept(noexcept(const_cast<T&>(derived()).operator&=(other))) {
243 T tmp(derived());
244 tmp &= other;
245 return tmp;
246 }
247
253 MSTL_NODISCARD MSTL_CONSTEXPR14 T operator |(const T& other) const
254 noexcept(noexcept(const_cast<T&>(derived()).operator|=(other))) {
255 T tmp(derived());
256 tmp |= other;
257 return tmp;
258 }
259
265 MSTL_NODISCARD MSTL_CONSTEXPR14 T operator ^(const T& other) const
266 noexcept(noexcept(const_cast<T&>(derived()).operator^=(other))) {
267 T tmp(derived());
268 tmp ^= other;
269 return tmp;
270 }
271
276 MSTL_NODISCARD MSTL_CONSTEXPR14 T operator ~() const
277 noexcept(noexcept(derived().operator~())) {
278 return derived().operator~();
279 }
280
285 MSTL_NODISCARD MSTL_CONSTEXPR14 T operator <<(const uint32_t shift) const {
286 T tmp(derived());
287 tmp <<= shift;
288 return tmp;
289 }
290
296 MSTL_NODISCARD MSTL_CONSTEXPR14 T operator >>(const uint32_t shift) const {
297 T tmp(derived());
298 tmp >>= shift;
299 return tmp;
300 }
301
307 MSTL_CONSTEXPR14 T& operator &=(const T& other)
308 noexcept(noexcept(derived().operator&=(other))) {
309 return derived().operator&=(other);
310 }
311
317 MSTL_CONSTEXPR14 T& operator |=(const T& other)
318 noexcept(noexcept(derived().operator|=(other))) {
319 return derived().operator|=(other);
320 }
321
327 MSTL_CONSTEXPR14 T& operator ^=(const T& other)
328 noexcept(noexcept(derived().operator^=(other))) {
329 return derived().operator^=(other);
330 }
331
337 MSTL_CONSTEXPR14 T& operator <<=(const uint32_t shift) {
338 return derived().operator<<=(shift);
339 }
340
346 MSTL_CONSTEXPR14 T& operator >>=(const uint32_t shift) {
347 return derived().operator>>=(shift);
348 }
349};
350 // CRTPInterfaces
352
354#endif // MSTL_CORE_INTERFACE_INUMERIC_HPP__
unsigned int uint32_t
32位无符号整数类型
#define MSTL_END_NAMESPACE__
结束全局命名空间MSTL
#define MSTL_BEGIN_NAMESPACE__
开始全局命名空间MSTL
算术运算接口基类
MSTL_NODISCARD MSTL_CONSTEXPR14 T operator-() const noexcept(noexcept(derived().operator-()))
一元负号运算符
MSTL_CONSTEXPR14 T & operator%=(const T &other)
取模赋值运算符
MSTL_CONSTEXPR14 T & operator-=(const T &other) noexcept(noexcept(derived().operator-=(other)))
减法赋值运算符
MSTL_NODISCARD MSTL_CONSTEXPR14 T operator/(const T &other) const noexcept(noexcept(const_cast< T & >(derived()).operator/=(other)))
除法运算符
MSTL_CONSTEXPR14 T & operator+=(const T &other) noexcept(noexcept(derived().operator+=(other)))
加法赋值运算符
MSTL_CONSTEXPR14 T & operator--() noexcept(noexcept(derived().operator--()))
前置自减运算符
MSTL_NODISCARD MSTL_CONSTEXPR14 T operator+(const T &other) const noexcept(noexcept(const_cast< T & >(derived()).operator+=(other)))
加法运算符
MSTL_CONSTEXPR14 T & operator++() noexcept(noexcept(derived().operator++()))
前置自增运算符
MSTL_CONSTEXPR14 T & operator*=(const T &other) noexcept(noexcept(derived().operator*=(other)))
乘法赋值运算符
MSTL_NODISCARD MSTL_CONSTEXPR14 T operator%(const T &other) const noexcept(noexcept(const_cast< T & >(derived()).operator%=(other)))
取模运算符
MSTL_CONSTEXPR14 T & operator/=(const T &other)
除法赋值运算符
MSTL_NODISCARD MSTL_CONSTEXPR14 T operator*(const T &other) const noexcept(noexcept(const_cast< T & >(derived()).operator*=(other)))
乘法运算符
位运算接口基类
MSTL_NODISCARD MSTL_CONSTEXPR14 T operator^(const T &other) const noexcept(noexcept(const_cast< T & >(derived()).operator^=(other)))
按位异或运算符
MSTL_CONSTEXPR14 T & operator|=(const T &other) noexcept(noexcept(derived().operator|=(other)))
按位或赋值运算符
MSTL_CONSTEXPR14 T & operator^=(const T &other) noexcept(noexcept(derived().operator^=(other)))
按位异或赋值运算符
MSTL_NODISCARD MSTL_CONSTEXPR14 T operator|(const T &other) const noexcept(noexcept(const_cast< T & >(derived()).operator|=(other)))
按位或运算符
MSTL_CONSTEXPR14 T & operator<<=(const uint32_t shift)
左移赋值运算符
MSTL_CONSTEXPR14 T & operator&=(const T &other) noexcept(noexcept(derived().operator&=(other)))
按位与赋值运算符
MSTL_NODISCARD MSTL_CONSTEXPR14 T operator>>(const uint32_t shift) const
右移运算符
MSTL_CONSTEXPR14 T & operator>>=(const uint32_t shift)
右移赋值运算符
MSTL_NODISCARD MSTL_CONSTEXPR14 T operator&(const T &other) const noexcept(noexcept(const_cast< T & >(derived()).operator&=(other)))
按位与运算符
MSTL_NODISCARD MSTL_CONSTEXPR14 T operator~() const noexcept(noexcept(derived().operator~()))
按位取反运算符
MSTL_NODISCARD MSTL_CONSTEXPR14 T operator<<(const uint32_t shift) const
左移运算符
MSTL基本类型别名