cMHN 1.2
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
14#include <prc/core/log/log.hpp>
16
17namespace pRC
18{
19 template<Bool S, Size W>
20 class Integer
21 {
22 public:
24 Conditional<W == 8, std::int8_t,
25 Conditional<W == 16, std::int16_t,
26 Conditional<W == 32, std::int32_t,
28 Conditional<W == 8, std::uint8_t,
29 Conditional<W == 16, std::uint16_t,
30 Conditional<W == 32, std::uint32_t,
32
33 static constexpr Size Width = W;
34 template<Size C>
36
37 static constexpr Bool Signed = S;
38 template<Bool C>
40
41 public:
43 requires IsDefined<Fundamental>
44 = default;
45 constexpr Integer(Integer const &) = default;
46 constexpr Integer(Integer &&) = default;
47 constexpr Integer &operator=(Integer const &) & = default;
48 constexpr Integer &operator=(Integer &&) & = default;
49 constexpr Integer() = default;
50
51 template<class U>
52 requires IsConstructible<Fundamental, U>
53 constexpr Integer(U const basic)
54 : mValue(basic)
55 {
56 }
57
58 template<IsValue U>
59 constexpr Integer(U const &value)
60 : mValue(value())
61 {
62 }
63
64 constexpr Integer(Zero<> const)
65 : Integer(zero<Integer>())
66 {
67 }
68
69 constexpr Integer(Unit<> const)
70 : Integer(unit<Integer>())
71 {
72 }
73
74 constexpr Integer(Identity<> const)
76 {
77 }
78
79 template<class U>
81 constexpr auto &operator=(U const basic) &
82 {
83 mValue = basic;
84 return *this;
85 }
86
87 template<IsValue U>
88 constexpr auto &operator=(U const &value) &
89 {
90 mValue = value();
91 return *this;
92 }
93
94 constexpr auto &operator=(Zero<> const) &
95 {
96 return *this = zero<Integer>();
97 }
98
99 constexpr auto &operator=(Unit<> const) &
100 {
101 return *this = unit<Integer>();
102 }
103
104 constexpr auto &operator=(Identity<> const) &
105 {
106 return *this = identity<Integer>();
107 }
108
109 constexpr decltype(auto) operator()() &&
110 {
111 return move(mValue);
112 }
113
114 constexpr decltype(auto) operator()() const &&
115 {
116 return move(mValue);
117 }
118
119 constexpr auto &operator()() &
120 {
121 return mValue;
122 }
123
124 constexpr auto &operator()() const &
125 {
126 return mValue;
127 }
128
129 explicit constexpr operator Fundamental() const
130 {
131 return mValue;
132 }
133
134 template<class X>
136 constexpr auto &operator+=(X &&rhs) &
137 {
138 return *this = *this + forward<X>(rhs);
139 }
140
141 template<class X>
143 constexpr auto &operator-=(X &&rhs) &
144 {
145 return *this = *this - forward<X>(rhs);
146 }
147
148 template<class X>
150 constexpr auto &operator*=(X &&rhs) &
151 {
152 return *this = *this * forward<X>(rhs);
153 }
154
155 template<class X>
157 constexpr auto &operator/=(X &&rhs) &
158 {
159 return *this = *this / forward<X>(rhs);
160 }
161
162 template<class X>
164 constexpr auto &operator%=(X &&rhs) &
165 {
166 return *this = *this % forward<X>(rhs);
167 }
168
169 private:
170 Fundamental mValue;
171 };
172
181}
182#endif // pRC_CORE_VALUE_INTEGER_H
Definition value.hpp:12
Definition value.hpp:15
constexpr auto & operator=(Unit<> const) &
Definition integer.hpp:99
constexpr auto & operator-=(X &&rhs) &
Definition integer.hpp:143
constexpr auto & operator=(Zero<> const) &
Definition integer.hpp:94
constexpr Integer(Unit<> const)
Definition integer.hpp:69
static constexpr Bool Signed
Definition integer.hpp:37
constexpr auto & operator+=(X &&rhs) &
Definition integer.hpp:136
constexpr auto & operator()() const &
Definition integer.hpp:124
~Integer()=default
constexpr Integer(Zero<> const)
Definition integer.hpp:64
constexpr auto & operator=(U const basic) &
Definition integer.hpp:81
constexpr auto & operator/=(X &&rhs) &
Definition integer.hpp:157
constexpr Integer(Identity<> const)
Definition integer.hpp:74
constexpr Integer(U const &value)
Definition integer.hpp:59
constexpr auto & operator%=(X &&rhs) &
Definition integer.hpp:164
constexpr auto & operator*=(X &&rhs) &
Definition integer.hpp:150
Conditional< S, Conditional< W==8, std::int8_t, Conditional< W==16, std::int16_t, Conditional< W==32, std::int32_t, Conditional< W==64, std::int64_t, Undefined > > > >, Conditional< W==8, std::uint8_t, Conditional< W==16, std::uint16_t, Conditional< W==32, std::uint32_t, Conditional< W==64, std::uint64_t, Undefined > > > > > Fundamental
Definition integer.hpp:23
constexpr auto & operator()() &
Definition integer.hpp:119
constexpr auto & operator=(Identity<> const) &
Definition integer.hpp:104
constexpr auto & operator=(U const &value) &
Definition integer.hpp:88
static constexpr Size Width
Definition integer.hpp:33
Definition concepts.hpp:40
Definition concepts.hpp:37
Definition concepts.hpp:16
Definition concepts.hpp:31
TN::Subscripts S
Definition externs_nonTT.hpp:9
int value
Definition gmock-actions_test.cc:1714
Definition cholesky.hpp:10
static constexpr auto unit()
Definition unit.hpp:13
std::size_t Size
Definition basics.hpp:31
std::conditional_t< B, T, F > Conditional
Definition basics.hpp:56
static constexpr auto identity()
Definition identity.hpp:13
static constexpr auto zero()
Definition zero.hpp:12
Integer(Integer< true, 8 >::Fundamental const) -> Integer< true, 8 >
Definition gtest_pred_impl_unittest.cc:54
Definition identity.hpp:11
Definition unit.hpp:11
Definition zero.hpp:11