cMHN 1.1
C++ library for learning MHNs with pRC
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{
20 template<Bool S, Size W>
21 class Integer
22 {
23 public:
25 Conditional<IsSatisfied<(W == 8)>, std::int8_t,
26 Conditional<IsSatisfied<(W == 16)>, std::int16_t,
27 Conditional<IsSatisfied<(W == 32)>, std::int32_t,
28 Conditional<IsSatisfied<(W == 64)>, std::int64_t,
29 Undefined>>>>,
30 Conditional<IsSatisfied<(W == 8)>, std::uint8_t,
31 Conditional<IsSatisfied<(W == 16)>, std::uint16_t,
32 Conditional<IsSatisfied<(W == 32)>, std::uint32_t,
33 Conditional<IsSatisfied<(W == 64)>, std::uint64_t,
34 Undefined>>>>>;
35
36 static_assert(IsDefined<Fundamental>(),
37 "Integer<S, W>: W has to be a supported Width (8, 16, 32, 64).");
38
40 template<class V, If<IsValue<V>> = 0>
41 using ChangeValue = V;
42
44 template<Bool R>
46
48 template<Size Q>
50
54
55 public:
56 ~Integer() = default;
57 constexpr Integer(Integer const &) = default;
58 constexpr Integer(Integer &&) = default;
59 constexpr Integer &operator=(Integer const &) & = default;
60 constexpr Integer &operator=(Integer &&) & = default;
61 constexpr Integer() = default;
62
63 template<class U, If<IsConstructible<Fundamental, U>> = 0>
64 constexpr Integer(U const basic)
65 : mValue(basic)
66 {
67 }
68
69 template<class U, If<IsValue<U>> = 0>
70 constexpr Integer(U const &value)
71 : mValue(value())
72 {
73 }
74
75 template<class U, If<IsValue<U>> = 0>
76 constexpr Integer(Complex<U> const &value)
77 : Integer(value.real())
78 {
79 }
80
81 constexpr Integer(Zero<> const)
82 : Integer(zero<Integer>())
83 {
84 }
85
86 constexpr Integer(Unit<> const)
87 : Integer(unit<Integer>())
88 {
89 }
90
91 constexpr Integer(Identity<> const)
93 {
94 }
95
96 template<class U, If<IsAssignable<Fundamental, U>> = 0>
97 constexpr auto &operator=(U const basic) &
98 {
99 mValue = basic;
100 return *this;
101 }
102
103 template<class U, If<IsValue<U>> = 0>
104 constexpr auto &operator=(U const &value) &
105 {
106 mValue = value();
107 return *this;
108 }
109
110 template<class U, If<IsValue<U>> = 0>
111 constexpr auto &operator=(Complex<U> const &value) &
112 {
113 return *this = value.real();
114 }
115
116 constexpr auto &operator=(Zero<> const) &
117 {
118 return *this = zero<Integer>();
119 }
120
121 constexpr auto &operator=(Unit<> const) &
122 {
123 return *this = unit<Integer>();
124 }
125
126 constexpr auto &operator=(Identity<> const) &
127 {
128 return *this = identity<Integer>();
129 }
130
131 constexpr decltype(auto) operator()() &&
132 {
133 return move(mValue);
134 }
135
136 constexpr decltype(auto) operator()() const &&
137 {
138 return move(mValue);
139 }
140
141 constexpr auto &operator()() &
142 {
143 return mValue;
144 }
145
146 constexpr auto &operator()() const &
147 {
148 return mValue;
149 }
150
151 explicit constexpr operator Fundamental() const
152 {
153 return mValue;
154 }
155
156 template<class X, If<IsInvocable<Add, Integer &, X>> = 0>
157 constexpr auto &operator+=(X &&rhs) &
158 {
159 return *this = *this + forward<X>(rhs);
160 }
161
162 template<class X, If<IsInvocable<Sub, Integer &, X>> = 0>
163 constexpr auto &operator-=(X &&rhs) &
164 {
165 return *this = *this - forward<X>(rhs);
166 }
167
168 template<class X, If<IsInvocable<Mul, Integer &, X>> = 0>
169 constexpr auto &operator*=(X &&rhs) &
170 {
171 return *this = *this * forward<X>(rhs);
172 }
173
174 template<class X, If<IsInvocable<Div, Integer &, X>> = 0>
175 constexpr auto &operator/=(X &&rhs) &
176 {
177 return *this = *this / forward<X>(rhs);
178 }
179
180 template<class X, If<IsInvocable<Mod, Integer &, X>> = 0>
181 constexpr auto &operator%=(X &&rhs) &
182 {
183 return *this = *this % forward<X>(rhs);
184 }
185
186 private:
187 Fundamental mValue;
188 };
189
198}
199#endif // pRC_CORE_VALUE_INTEGER_H
Definition complex.hpp:26
Definition integer.hpp:22
constexpr auto & operator=(Unit<> const) &
Definition integer.hpp:121
constexpr Integer(U const basic)
Definition integer.hpp:64
constexpr Integer & operator=(Integer const &) &=default
constexpr auto & operator=(U const &value) &
Definition integer.hpp:104
constexpr Integer & operator=(Integer &&) &=default
constexpr auto & operator=(U const basic) &
Definition integer.hpp:97
constexpr auto & operator/=(X &&rhs) &
Definition integer.hpp:175
constexpr auto & operator=(Complex< U > const &value) &
Definition integer.hpp:111
V ChangeValue
Definition integer.hpp:41
constexpr Integer(Integer const &)=default
constexpr Integer(Complex< U > const &value)
Definition integer.hpp:76
constexpr Integer(U const &value)
Definition integer.hpp:70
constexpr auto & operator-=(X &&rhs) &
Definition integer.hpp:163
pRC::Constant< Bool, S > Signed
Definition integer.hpp:43
constexpr Integer(Zero<> const)
Definition integer.hpp:81
constexpr Integer(Integer &&)=default
constexpr auto & operator()() const &
Definition integer.hpp:146
constexpr auto & operator()() &
Definition integer.hpp:141
constexpr auto & operator%=(X &&rhs) &
Definition integer.hpp:181
constexpr auto & operator=(Identity<> const) &
Definition integer.hpp:126
~Integer()=default
constexpr auto & operator=(Zero<> const) &
Definition integer.hpp:116
constexpr Integer(Identity<> const)
Definition integer.hpp:91
constexpr 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:24
pRC::Constant< Size, W > Width
Definition integer.hpp:47
constexpr auto & operator*=(X &&rhs) &
Definition integer.hpp:169
constexpr auto & operator+=(X &&rhs) &
Definition integer.hpp:157
constexpr Integer(Unit<> const)
Definition integer.hpp:86
TN::Subscripts S
Definition externs_nonTT.hpp:9
Definition cholesky.hpp:18
static constexpr auto makeConstantSequence()
Definition sequence.hpp:402
static constexpr decltype(auto) real(X &&a)
Definition real.hpp:11
static constexpr auto zero()
Definition zero.hpp:12
Constant< Bool, B > IsSatisfied
Definition type_traits.hpp:71
static constexpr auto unit()
Definition unit.hpp:12
std::integral_constant< T, V > Constant
Definition type_traits.hpp:34
std::conditional_t< B{}, T, F > Conditional
Definition type_traits.hpp:131
Integer(Integer< true, 8 >::Fundamental const) -> Integer< true, 8 >
static constexpr auto identity()
Definition identity.hpp:12
Definition type_traits.hpp:262
Definition type_traits.hpp:265
Definition type_traits.hpp:268