NexusForce 1.0.0
A rigorously engineered full-stack C++ backend library.
载入中...
搜索中...
未找到
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
110 NEFORCE_CONSTEXPR14 T& operator+=(const T& other) noexcept(noexcept(derived().operator+=(other))) {
111 return derived().operator+=(other);
112 }
113
119 NEFORCE_CONSTEXPR14 T& operator-=(const T& other) noexcept(noexcept(derived().operator-=(other))) {
120 return derived().operator-=(other);
121 }
122
128 NEFORCE_CONSTEXPR14 T& operator*=(const T& other) noexcept(noexcept(derived().operator*=(other))) {
129 return derived().operator*=(other);
130 }
131
137 NEFORCE_CONSTEXPR14 T& operator/=(const T& other) { return derived().operator/=(other); }
138
144 NEFORCE_CONSTEXPR14 T& operator%=(const T& other) { return derived().operator%=(other); }
145
150 NEFORCE_CONSTEXPR14 T& operator++() noexcept(noexcept(derived().operator++())) { return derived().operator++(); }
151
156 NEFORCE_CONSTEXPR14 T operator++(int) noexcept(noexcept(derived().operator++())) {
157 T tmp(derived());
158 ++derived();
159 return tmp;
160 }
161
166 NEFORCE_CONSTEXPR14 T& operator--() noexcept(noexcept(derived().operator--())) { return derived().operator--(); }
167
172 NEFORCE_CONSTEXPR14 T operator--(int) noexcept(noexcept(derived().operator--())) {
173 T tmp(derived());
174 --derived();
175 return tmp;
176 }
177};
178
179
188template <typename T>
189struct ibinary {
190private:
195 constexpr const T& derived() const noexcept { return static_cast<const T&>(*this); }
196
201 constexpr T& derived() noexcept { return static_cast<T&>(*this); }
202
203public:
209 NEFORCE_NODISCARD NEFORCE_CONSTEXPR14 T operator&(const T& other) const
210 noexcept(noexcept(const_cast<T&>(derived()).operator&=(other))) {
211 T tmp(derived());
212 tmp &= other;
213 return tmp;
214 }
215
221 NEFORCE_NODISCARD NEFORCE_CONSTEXPR14 T operator|(const T& other) const
222 noexcept(noexcept(const_cast<T&>(derived()).operator|=(other))) {
223 T tmp(derived());
224 tmp |= other;
225 return tmp;
226 }
227
233 NEFORCE_NODISCARD NEFORCE_CONSTEXPR14 T operator^(const T& other) const
234 noexcept(noexcept(const_cast<T&>(derived()).operator^=(other))) {
235 T tmp(derived());
236 tmp ^= other;
237 return tmp;
238 }
239
244 NEFORCE_NODISCARD NEFORCE_CONSTEXPR14 T operator~() const noexcept(noexcept(derived().operator~())) {
245 return derived().operator~();
246 }
247
252 NEFORCE_NODISCARD NEFORCE_CONSTEXPR14 T operator<<(const uint32_t shift) const {
253 T tmp(derived());
254 tmp <<= shift;
255 return tmp;
256 }
257
263 NEFORCE_NODISCARD NEFORCE_CONSTEXPR14 T operator>>(const uint32_t shift) const {
264 T tmp(derived());
265 tmp >>= shift;
266 return tmp;
267 }
268
274 NEFORCE_CONSTEXPR14 T& operator&=(const T& other) noexcept(noexcept(derived().operator&=(other))) {
275 return derived().operator&=(other);
276 }
277
283 NEFORCE_CONSTEXPR14 T& operator|=(const T& other) noexcept(noexcept(derived().operator|=(other))) {
284 return derived().operator|=(other);
285 }
286
292 NEFORCE_CONSTEXPR14 T& operator^=(const T& other) noexcept(noexcept(derived().operator^=(other))) {
293 return derived().operator^=(other);
294 }
295
301 NEFORCE_CONSTEXPR14 T& operator<<=(const uint32_t shift) { return derived().operator<<=(shift); }
302
308 NEFORCE_CONSTEXPR14 T& operator>>=(const uint32_t shift) { return derived().operator>>=(shift); }
309};
310 // CRTPInterfaces
312
313NEFORCE_END_NAMESPACE__
314#endif // NEFORCE_CORE_INTERFACE_INUMERIC_HPP__
unsigned int uint32_t
32位无符号整数类型
算术运算接口基类
constexpr T & operator/=(const T &other)
除法赋值运算符
constexpr T operator--(int) noexcept(noexcept(derived().operator--()))
后置自减运算符
constexpr T & operator-=(const T &other) noexcept(noexcept(derived().operator-=(other)))
减法赋值运算符
constexpr T operator/(const T &other) const noexcept(noexcept(const_cast< T & >(derived()).operator/=(other)))
除法运算符
constexpr T & operator++() noexcept(noexcept(derived().operator++()))
前置自增运算符
constexpr T operator+(const T &other) const noexcept(noexcept(const_cast< T & >(derived()).operator+=(other)))
加法运算符
constexpr T & operator+=(const T &other) noexcept(noexcept(derived().operator+=(other)))
加法赋值运算符
constexpr T operator%(const T &other) const noexcept(noexcept(const_cast< T & >(derived()).operator%=(other)))
取模运算符
constexpr T operator++(int) noexcept(noexcept(derived().operator++()))
后置自增运算符
constexpr T & operator--() noexcept(noexcept(derived().operator--()))
前置自减运算符
constexpr T operator-(const T &other) const noexcept(noexcept(const_cast< T & >(derived()).operator-=(other)))
减法运算符
constexpr T & operator*=(const T &other) noexcept(noexcept(derived().operator*=(other)))
乘法赋值运算符
constexpr T operator*(const T &other) const noexcept(noexcept(const_cast< T & >(derived()).operator*=(other)))
乘法运算符
constexpr T & operator%=(const T &other)
取模赋值运算符
位运算接口基类
constexpr T operator|(const T &other) const noexcept(noexcept(const_cast< T & >(derived()).operator|=(other)))
按位或运算符
constexpr T operator~() const noexcept(noexcept(derived().operator~()))
按位取反运算符
constexpr T & operator&=(const T &other) noexcept(noexcept(derived().operator&=(other)))
按位与赋值运算符
constexpr T & operator|=(const T &other) noexcept(noexcept(derived().operator|=(other)))
按位或赋值运算符
constexpr T & operator>>=(const uint32_t shift)
右移赋值运算符
constexpr T operator<<(const uint32_t shift) const
左移运算符
constexpr T & operator<<=(const uint32_t shift)
左移赋值运算符
constexpr T operator>>(const uint32_t shift) const
右移运算符
constexpr T operator&(const T &other) const noexcept(noexcept(const_cast< T & >(derived()).operator&=(other)))
按位与运算符
constexpr T & operator^=(const T &other) noexcept(noexcept(derived().operator^=(other)))
按位异或赋值运算符
constexpr T operator^(const T &other) const noexcept(noexcept(const_cast< T & >(derived()).operator^=(other)))
按位异或运算符
基本类型别名