pRC
multi-purpose Tensor Train library for C++
Loading...
Searching...
No Matches
integer.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2
3#ifndef pRC_CORE_VALUE_INTEGER_H
4#define pRC_CORE_VALUE_INTEGER_H
5
15#include <prc/core/log/log.hpp>
17
18namespace pRC
19{
45 template<Bool S, Size W>
46 class Integer
47 {
48 public:
50 Conditional<IsSatisfied<(W == 8)>, std::int8_t,
51 Conditional<IsSatisfied<(W == 16)>, std::int16_t,
52 Conditional<IsSatisfied<(W == 32)>, std::int32_t,
53 Conditional<IsSatisfied<(W == 64)>, std::int64_t,
54 Undefined>>>>,
55 Conditional<IsSatisfied<(W == 8)>, std::uint8_t,
56 Conditional<IsSatisfied<(W == 16)>, std::uint16_t,
57 Conditional<IsSatisfied<(W == 32)>, std::uint32_t,
58 Conditional<IsSatisfied<(W == 64)>, std::uint64_t,
59 Undefined>>>>>;
60
61 static_assert(IsDefined<Fundamental>(),
62 "Integer<S, W>: W has to be a supported Width (8, 16, 32, 64).");
63
65 template<class V, If<IsValue<V>> = 0>
66 using ChangeValue = V;
67
69 template<Bool R>
71
73 template<Size Q>
75
79
80 public:
81 ~Integer() = default;
82 constexpr Integer(Integer const &) = default;
83 constexpr Integer(Integer &&) = default;
84 constexpr Integer &operator=(Integer const &) & = default;
85 constexpr Integer &operator=(Integer &&) & = default;
86 constexpr Integer() = default;
87
99 template<class U, If<IsConstructible<Fundamental, U>> = 0>
100 constexpr Integer(U const basic)
101 : mValue(basic)
102 {
103 }
104
112 template<class U, If<IsValue<U>> = 0>
113 constexpr Integer(U const &value)
114 : mValue(value())
115 {
116 }
117
128 template<class U, If<IsValue<U>> = 0>
129 constexpr Integer(Complex<U> const &value)
130 : Integer(value.real())
131 {
132 }
133
139 constexpr Integer(Zero<> const)
140 : Integer(zero<Integer>())
141 {
142 }
143
149 constexpr Integer(Unit<> const)
150 : Integer(unit<Integer>())
151 {
152 }
153
159 constexpr Integer(Identity<> const)
161 {
162 }
163
175 template<class U, If<IsAssignable<Fundamental, U>> = 0>
176 constexpr auto &operator=(U const basic) &
177 {
178 mValue = basic;
179 return *this;
180 }
181
190 template<class U, If<IsValue<U>> = 0>
191 constexpr auto &operator=(U const &value) &
192 {
193 mValue = value();
194 return *this;
195 }
196
206 template<class U, If<IsValue<U>> = 0>
207 constexpr auto &operator=(Complex<U> const &value) &
208 {
209 return *this = value.real();
210 }
211
217 constexpr auto &operator=(Zero<> const) &
218 {
219 return *this = zero<Integer>();
220 }
221
227 constexpr auto &operator=(Unit<> const) &
228 {
229 return *this = unit<Integer>();
230 }
231
237 constexpr auto &operator=(Identity<> const) &
238 {
239 return *this = identity<Integer>();
240 }
241
242 constexpr decltype(auto) operator()() &&
243 {
244 return move(mValue);
245 }
246
247 constexpr decltype(auto) operator()() const &&
248 {
249 return move(mValue);
250 }
251
252 constexpr auto &operator()() &
253 {
254 return mValue;
255 }
256
257 constexpr auto &operator()() const &
258 {
259 return mValue;
260 }
261
262 explicit constexpr operator Fundamental() const
263 {
264 return mValue;
265 }
266
274 template<class X, If<IsInvocable<Add, Integer &, X>> = 0>
275 constexpr auto &operator+=(X &&rhs) &
276 {
277 return *this = *this + forward<X>(rhs);
278 }
279
287 template<class X, If<IsInvocable<Sub, Integer &, X>> = 0>
288 constexpr auto &operator-=(X &&rhs) &
289 {
290 return *this = *this - forward<X>(rhs);
291 }
292
300 template<class X, If<IsInvocable<Mul, Integer &, X>> = 0>
301 constexpr auto &operator*=(X &&rhs) &
302 {
303 return *this = *this * forward<X>(rhs);
304 }
305
315 template<class X, If<IsInvocable<Div, Integer &, X>> = 0>
316 constexpr auto &operator/=(X &&rhs) &
317 {
318 return *this = *this / forward<X>(rhs);
319 }
320
328 template<class X, If<IsInvocable<Mod, Integer &, X>> = 0>
329 constexpr auto &operator%=(X &&rhs) &
330 {
331 return *this = *this % forward<X>(rhs);
332 }
333
334 private:
335 Fundamental mValue;
336 };
337
346}
347#endif // pRC_CORE_VALUE_INTEGER_H
Definition complex.hpp:26
Top-level class storing a floating point number.
Definition integer.hpp:47
constexpr auto & operator=(Unit<> const) &
Integer assignment from pRC::Unit.
Definition integer.hpp:227
constexpr Integer(U const basic)
Integer initializer from standard data types (like int, unsigned)
Definition integer.hpp:100
constexpr Integer & operator=(Integer const &) &=default
constexpr auto & operator=(U const &value) &
Integer asignment from pRC value data type (like Float, Integer)
Definition integer.hpp:191
constexpr Integer & operator=(Integer &&) &=default
constexpr auto & operator=(U const basic) &
Integer assignment from standard data types (like int, unsigned)
Definition integer.hpp:176
constexpr auto & operator/=(X &&rhs) &
/= operator for Integer
Definition integer.hpp:316
constexpr auto & operator=(Complex< U > const &value) &
Integer assignment from Complex object.
Definition integer.hpp:207
V ChangeValue
Definition integer.hpp:66
constexpr Integer(Integer const &)=default
constexpr Integer(Complex< U > const &value)
Integer initializer from pRC::Complex object.
Definition integer.hpp:129
constexpr Integer(U const &value)
Integer initializer from pRC value data type (like Float, Integer)
Definition integer.hpp:113
constexpr auto & operator-=(X &&rhs) &
-= operator for Integer
Definition integer.hpp:288
pRC::Constant< Bool, S > Signed
Definition integer.hpp:68
constexpr Integer(Zero<> const)
Integer initializer from pRC::Zero.
Definition integer.hpp:139
constexpr Integer(Integer &&)=default
Conditional< IsSatisfied<(S)>, Conditional< IsSatisfied<(W==8)>, std::int8_t, Conditional< IsSatisfied<(W==16)>, std::int16_t, Conditional< IsSatisfied<(W==32)>, std::int32_t, Conditional< IsSatisfied<(W==64)>, std::int64_t, Undefined > > > >, Conditional< IsSatisfied<(W==8)>, std::uint8_t, Conditional< IsSatisfied<(W==16)>, std::uint16_t, Conditional< IsSatisfied<(W==32)>, std::uint32_t, Conditional< IsSatisfied<(W==64)>, std::uint64_t, Undefined > > > > > Fundamental
Definition integer.hpp:59
constexpr auto & operator()() const &
Definition integer.hpp:257
constexpr auto & operator()() &
Definition integer.hpp:252
constexpr auto & operator%=(X &&rhs) &
%= operator for Integer
Definition integer.hpp:329
constexpr auto & operator=(Identity<> const) &
Integer assignment from pRC::Identity.
Definition integer.hpp:237
~Integer()=default
constexpr auto & operator=(Zero<> const) &
Integer assignment from pRC::Zero.
Definition integer.hpp:217
constexpr Integer(Identity<> const)
Integer initializer from pRC::Identity.
Definition integer.hpp:159
constexpr Integer()=default
pRC::Constant< Size, W > Width
Definition integer.hpp:72
constexpr auto & operator*=(X &&rhs) &
*= operator for Integer
Definition integer.hpp:301
constexpr auto & operator+=(X &&rhs) &
+= operator for Integer
Definition integer.hpp:275
constexpr Integer(Unit<> const)
Integer initializer from pRC::Unit.
Definition integer.hpp:149
Definition cholesky.hpp:18
static constexpr decltype(auto) real(X &&a)
Definition real.hpp:11
static constexpr auto zero()
Definition zero.hpp:12
std::integral_constant< T, V > Constant
Definition type_traits.hpp:34
Constant< Bool, B > IsSatisfied
Definition type_traits.hpp:71
static constexpr Conditional< IsSatisfied< C >, RemoveConstReference< X >, X > copy(X &&a)
Definition copy.hpp:13
static constexpr auto unit()
Definition unit.hpp:12
std::conditional_t< B{}, T, F > Conditional
Definition type_traits.hpp:131
static constexpr auto identity()
Definition identity.hpp:12
Definition type_traits.hpp:262
Definition type_traits.hpp:265
Definition type_traits.hpp:268