10 template <
typename Any,
typename parameter,
template <
typename>
class... utils_>
11 class strong_type final :
public utils_<strong_type<Any, parameter, utils_...>>...
14 using value_type = Any;
18 noexcept(std::is_nothrow_default_constructible_v<value_type>)
19 requires std::default_initializable<value_type> =
default;
21 constexpr
explicit strong_type(
const value_type& value)
22 noexcept(std::is_nothrow_copy_constructible_v<value_type>)
23 requires std::copy_constructible<value_type>
28 noexcept(std::is_nothrow_move_assignable_v<value_type>)
29 requires std::move_constructible<value_type>
30 : m_value{std::move(value)}
33 constexpr
auto value() noexcept -> value_type&
37 constexpr
auto value()
const noexcept ->
const value_type&
57 constexpr
auto operator=(value_type&& value)
const ->
strong_type
59 return strong_type{std::forward<value_type>(value)};
62 constexpr
auto operator=(
auto&& value)
const ->
strong_type
64 return strong_type{std::forward<decltype(value)>(value)};
75 template <
typename Any,
template <
typename>
class crtp_type_>
78 constexpr
auto underlying() -> Any& {
return static_cast<Any&
>(*this); }
79 constexpr
auto underlying()
const -> Any
const& {
return static_cast<Any const&
>(*this); }
83 template <
typename Any>
86 constexpr
auto operator++() -> Any&
88 ++this->underlying().value();
89 return this->underlying();
93 template <
typename Any>
96 constexpr
auto operator++(
int) -> Any {
return this->underlying().value()++; }
99 template <
typename Any>
106 template <
typename Any>
109 constexpr
auto operator--() -> Any&
111 --this->underlying().value();
112 return this->underlying();
116 template <
typename Any>
119 constexpr
auto operator--(
int) -> Any {
return this->underlying().value()--; }
122 template <
typename Any>
129 template <
typename Any>
132 constexpr
auto operator+(
const Any& rhs)
const
134 return Any{this->underlying().value() + rhs.value()};
137 constexpr
auto operator+=(
const Any& rhs)
139 this->underlying().vale() += rhs.value();
140 return this->underlying();
144 template <
typename Any>
147 constexpr
auto operator+()
const {
return Any{+this->undelying().value()}; }
150 template <
typename Any>
157 template <
typename Any>
160 constexpr
auto operator-(
const Any& rhs)
const
162 return Any{this->underlying().value() - rhs.value()};
165 constexpr
auto operator-=(
const Any& rhs)
167 this->underlying().value() -= rhs.value();
168 return this->underlying();
172 template <
typename Any>
175 constexpr
auto operator-()
const {
return Any{-this->undelying().value()}; }
178 template <
typename Any>
185 template <
typename Any>
188 constexpr
auto operator*(
const Any& rhs)
const -> Any
190 return Any{this->underlying().value() * rhs.value()};
192 constexpr
auto operator*=(
const Any& rhs) -> Any&
194 this->underlying().value() *= rhs.value();
195 return this->underlying();
199 template <
typename Any>
202 constexpr
auto operator/(
const Any& other)
const -> Any
204 return Any{this->underlying().value() / other.value()};
206 constexpr
auto operator/=(
const Any& rhs) -> Any&
208 this->underlying().value() /= rhs.value();
209 return this->underlying();
213 template <
typename Any>
216 constexpr
auto operator%(
const Any& rhs)
const -> Any
218 return Any{this->underlying().value() % rhs.value()};
220 constexpr
auto operator%=(
const Any& other) -> Any&
222 this->underlying().value() %= other.value();
223 return this->underlying();
227 template <
typename Any>
230 constexpr
friend auto operator==(
const Any& lhs,
const Any& rhs) ->
bool
232 return lhs.value() == rhs.value();
236 template <
typename Any>
239 constexpr
friend auto operator<=>(
const Any& lhs,
const Any& rhs)
241 return std::compare_three_way{}(lhs, rhs);
245 template <
typename Any>
Definition: strong_type.hpp:12
Definition: strong_type.hpp:152
Definition: strong_type.hpp:255
Definition: strong_type.hpp:131
Definition: strong_type.hpp:159
Definition: strong_type.hpp:238
Definition: strong_type.hpp:124
Definition: strong_type.hpp:77
Definition: strong_type.hpp:201
Definition: strong_type.hpp:229
Definition: strong_type.hpp:101
Definition: strong_type.hpp:215
Definition: strong_type.hpp:187
Definition: strong_type.hpp:118
Definition: strong_type.hpp:95
Definition: strong_type.hpp:108
Definition: strong_type.hpp:85
Definition: strong_type.hpp:48
Definition: strong_type.hpp:180
Definition: strong_type.hpp:146
Definition: strong_type.hpp:174