NexusForce 1.0.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
inumeric.hpp
浏览该文件的文档.
1#ifndef NEFORCE_CORE_INTERFACE_INUMERIC_HPP__
2#define NEFORCE_CORE_INTERFACE_INUMERIC_HPP__
3
11
13NEFORCE_BEGIN_NAMESPACE__
14
20
29template <typename T>
31private:
36 constexpr const T& derived() const noexcept { return static_cast<const T&>(*this); }
37
42 constexpr T& derived() noexcept { return static_cast<T&>(*this); }
43
44public:
50 NEFORCE_NODISCARD NEFORCE_CONSTEXPR14 T operator+(const T& other) const
51 noexcept(noexcept(const_cast<T&>(derived()).operator+=(other))) {
52 T tmp(derived());
53 tmp += other;
54 return tmp;
55 }
56
62 NEFORCE_NODISCARD NEFORCE_CONSTEXPR14 T operator-(const T& other) const
63 noexcept(noexcept(const_cast<T&>(derived()).operator-=(other))) {
64 T tmp(derived());
65 tmp -= other;
66 return tmp;
67 }
68
74 NEFORCE_NODISCARD NEFORCE_CONSTEXPR14 T operator*(const T& other) const
75 noexcept(noexcept(const_cast<T&>(derived()).operator*=(other))) {
76 T tmp(derived());
77 tmp *= other;
78 return tmp;
79 }
80
86 NEFORCE_NODISCARD NEFORCE_CONSTEXPR14 T operator/(const T& other) const
87 noexcept(noexcept(const_cast<T&>(derived()).operator/=(other))) {
88 T tmp(derived());
89 tmp /= other;
90 return tmp;
91 }
92
98 NEFORCE_NODISCARD NEFORCE_CONSTEXPR14 T operator%(const T& other) const
99 noexcept(noexcept(const_cast<T&>(derived()).operator%=(other))) {
100 T tmp(derived());
101 tmp %= other;
102 return tmp;
103 }
104
109 NEFORCE_NODISCARD NEFORCE_CONSTEXPR14 T operator-() const noexcept(noexcept(derived().operator-())) {
110 return derived().operator-();
111 }
112
118 NEFORCE_CONSTEXPR14 T& operator+=(const T& other) noexcept(noexcept(derived().operator+=(other))) {
119 return derived().operator+=(other);
120 }
121
127 NEFORCE_CONSTEXPR14 T& operator-=(const T& other) noexcept(noexcept(derived().operator-=(other))) {
128 return derived().operator-=(other);
129 }
130
136 NEFORCE_CONSTEXPR14 T& operator*=(const T& other) noexcept(noexcept(derived().operator*=(other))) {
137 return derived().operator*=(other);
138 }
139
145 NEFORCE_CONSTEXPR14 T& operator/=(const T& other) { return derived().operator/=(other); }
146
152 NEFORCE_CONSTEXPR14 T& operator%=(const T& other) { return derived().operator%=(other); }
153
158 NEFORCE_CONSTEXPR14 T& operator++() noexcept(noexcept(derived().operator++())) { return derived().operator++(); }
159
164 NEFORCE_CONSTEXPR14 T operator++(int) noexcept(noexcept(derived().operator++())) {
165 T tmp(derived());
166 ++derived();
167 return tmp;
168 }
169
174 NEFORCE_CONSTEXPR14 T& operator--() noexcept(noexcept(derived().operator--())) { return derived().operator--(); }
175
180 NEFORCE_CONSTEXPR14 T operator--(int) noexcept(noexcept(derived().operator--())) {
181 T tmp(derived());
182 --derived();
183 return tmp;
184 }
185};
186
187
196template <typename T>
197struct ibinary {
198private:
203 constexpr const T& derived() const noexcept { return static_cast<const T&>(*this); }
204
209 constexpr T& derived() noexcept { return static_cast<T&>(*this); }
210
211public:
217 NEFORCE_NODISCARD NEFORCE_CONSTEXPR14 T operator&(const T& other) const
218 noexcept(noexcept(const_cast<T&>(derived()).operator&=(other))) {
219 T tmp(derived());
220 tmp &= other;
221 return tmp;
222 }
223
229 NEFORCE_NODISCARD NEFORCE_CONSTEXPR14 T operator|(const T& other) const
230 noexcept(noexcept(const_cast<T&>(derived()).operator|=(other))) {
231 T tmp(derived());
232 tmp |= other;
233 return tmp;
234 }
235
241 NEFORCE_NODISCARD NEFORCE_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
252 NEFORCE_NODISCARD NEFORCE_CONSTEXPR14 T operator~() const noexcept(noexcept(derived().operator~())) {
253 return derived().operator~();
254 }
255
260 NEFORCE_NODISCARD NEFORCE_CONSTEXPR14 T operator<<(const uint32_t shift) const {
261 T tmp(derived());
262 tmp <<= shift;
263 return tmp;
264 }
265
271 NEFORCE_NODISCARD NEFORCE_CONSTEXPR14 T operator>>(const uint32_t shift) const {
272 T tmp(derived());
273 tmp >>= shift;
274 return tmp;
275 }
276
282 NEFORCE_CONSTEXPR14 T& operator&=(const T& other) noexcept(noexcept(derived().operator&=(other))) {
283 return derived().operator&=(other);
284 }
285
291 NEFORCE_CONSTEXPR14 T& operator|=(const T& other) noexcept(noexcept(derived().operator|=(other))) {
292 return derived().operator|=(other);
293 }
294
300 NEFORCE_CONSTEXPR14 T& operator^=(const T& other) noexcept(noexcept(derived().operator^=(other))) {
301 return derived().operator^=(other);
302 }
303
309 NEFORCE_CONSTEXPR14 T& operator<<=(const uint32_t shift) { return derived().operator<<=(shift); }
310
316 NEFORCE_CONSTEXPR14 T& operator>>=(const uint32_t shift) { return derived().operator>>=(shift); }
317};
318 // CRTPInterfaces
320
321NEFORCE_END_NAMESPACE__
322#endif // NEFORCE_CORE_INTERFACE_INUMERIC_HPP__
unsigned int uint32_t
32位无符号整数类型
算术运算接口基类
NEFORCE_CONSTEXPR14 T & operator%=(const T &other)
取模赋值运算符
NEFORCE_CONSTEXPR14 T & operator--() noexcept(noexcept(derived().operator--()))
前置自减运算符
NEFORCE_NODISCARD NEFORCE_CONSTEXPR14 T operator%(const T &other) const noexcept(noexcept(const_cast< T & >(derived()).operator%=(other)))
取模运算符
NEFORCE_CONSTEXPR14 T & operator*=(const T &other) noexcept(noexcept(derived().operator*=(other)))
乘法赋值运算符
NEFORCE_CONSTEXPR14 T & operator++() noexcept(noexcept(derived().operator++()))
前置自增运算符
NEFORCE_CONSTEXPR14 T & operator-=(const T &other) noexcept(noexcept(derived().operator-=(other)))
减法赋值运算符
NEFORCE_CONSTEXPR14 T operator--(int) noexcept(noexcept(derived().operator--()))
后置自减运算符
NEFORCE_NODISCARD NEFORCE_CONSTEXPR14 T operator/(const T &other) const noexcept(noexcept(const_cast< T & >(derived()).operator/=(other)))
除法运算符
NEFORCE_NODISCARD NEFORCE_CONSTEXPR14 T operator-(const T &other) const noexcept(noexcept(const_cast< T & >(derived()).operator-=(other)))
减法运算符
NEFORCE_CONSTEXPR14 T & operator/=(const T &other)
除法赋值运算符
NEFORCE_CONSTEXPR14 T & operator+=(const T &other) noexcept(noexcept(derived().operator+=(other)))
加法赋值运算符
NEFORCE_CONSTEXPR14 T operator++(int) noexcept(noexcept(derived().operator++()))
后置自增运算符
NEFORCE_NODISCARD NEFORCE_CONSTEXPR14 T operator-() const noexcept(noexcept(derived().operator-()))
一元负号运算符
NEFORCE_NODISCARD NEFORCE_CONSTEXPR14 T operator+(const T &other) const noexcept(noexcept(const_cast< T & >(derived()).operator+=(other)))
加法运算符
NEFORCE_NODISCARD NEFORCE_CONSTEXPR14 T operator*(const T &other) const noexcept(noexcept(const_cast< T & >(derived()).operator*=(other)))
乘法运算符
位运算接口基类
NEFORCE_CONSTEXPR14 T & operator|=(const T &other) noexcept(noexcept(derived().operator|=(other)))
按位或赋值运算符
NEFORCE_NODISCARD NEFORCE_CONSTEXPR14 T operator~() const noexcept(noexcept(derived().operator~()))
按位取反运算符
NEFORCE_NODISCARD NEFORCE_CONSTEXPR14 T operator>>(const uint32_t shift) const
右移运算符
NEFORCE_NODISCARD NEFORCE_CONSTEXPR14 T operator|(const T &other) const noexcept(noexcept(const_cast< T & >(derived()).operator|=(other)))
按位或运算符
NEFORCE_CONSTEXPR14 T & operator>>=(const uint32_t shift)
右移赋值运算符
NEFORCE_NODISCARD NEFORCE_CONSTEXPR14 T operator<<(const uint32_t shift) const
左移运算符
NEFORCE_CONSTEXPR14 T & operator^=(const T &other) noexcept(noexcept(derived().operator^=(other)))
按位异或赋值运算符
NEFORCE_NODISCARD NEFORCE_CONSTEXPR14 T operator^(const T &other) const noexcept(noexcept(const_cast< T & >(derived()).operator^=(other)))
按位异或运算符
NEFORCE_CONSTEXPR14 T & operator<<=(const uint32_t shift)
左移赋值运算符
NEFORCE_CONSTEXPR14 T & operator&=(const T &other) noexcept(noexcept(derived().operator&=(other)))
按位与赋值运算符
NEFORCE_NODISCARD NEFORCE_CONSTEXPR14 T operator&(const T &other) const noexcept(noexcept(const_cast< T & >(derived()).operator&=(other)))
按位与运算符
基本类型别名