IceShard 1
A personal game engine project, with development focused on 2D/2.5D games.
Loading...
Searching...
No Matches
strong_type_integral.hxx
Go to the documentation of this file.
1
3
4#pragma once
6
7namespace ice
8{
9
11 struct StrongNumeric { };
12
13 template<typename T>
14 using StrongNumericBase = typename ice::detail::ExtractMemberType<decltype(&T::value)>::Type;
15
17 template<typename T>
18 concept StrongNumericType = std::is_pod_v<T>
21 && std::is_arithmetic_v<ice::StrongNumericBase<T>>;
22
23
25 {
26
28 {
31 };
32
33 //template<typename T, Operator Op> requires ice::StrongNumericType<T>
34 //constexpr static bool IsOperatorEnabled = true;
35
36 //template<typename T>
37 //constexpr static bool IsAddEnabled = IsOperatorEnabled<T, Operator::Add>;
38
39 //template<typename T>
40 //constexpr static bool IsSubEnabled = IsOperatorEnabled<T, Operator::Sub>;
41
42 //template<typename T>
43 //constexpr static bool IsNegateEnabled = IsOperatorEnabled<T, Operator::Neg>;
44
45 //template<typename T>
46 //constexpr static bool IsMulEnabled = IsOperatorEnabled<T, Operator::Mul>;
47
48 //template<typename T>
49 //constexpr static bool IsDivEnabled = IsOperatorEnabled<T, Operator::Div>;
50
51 //template<typename T>
52 //constexpr static bool IsAddEqEnabled = IsOperatorEnabled<T, Operator::AddEq>;
53
54 //template<typename T>
55 //constexpr static bool IsSubEqEnabled = IsOperatorEnabled<T, Operator::SubEq>;
56
57 //template<typename T>
58 //constexpr static bool IsMulEqEnabled = IsOperatorEnabled<T, Operator::MulEq>;
59
60 //template<typename T>
61 //constexpr static bool IsDivEqEnabled = IsOperatorEnabled<T, Operator::DivEq>;
62
63 } // namespace detail
64
65 template<typename T> requires ice::StrongNumericType<T>
66 constexpr auto operator==(T left, T right) noexcept -> bool
67 {
68 return left.value == right.value;
69 }
70
71 template<typename T> requires ice::StrongNumericType<T>
72 constexpr auto operator<=>(T left, T right) noexcept
73 {
74 return left.value <=> right.value;
75 }
76
77 template<typename T> requires StrongNumericType<T>// && ice::detail::numeric::IsAddEnabled<T>
78 constexpr auto operator+(T left, T right) noexcept -> T
79 {
80 return T{ left.value + right.value };
81 }
82
83 template<typename T> requires StrongNumericType<T>// && ice::detail::numeric::IsSubEnabled<T>
84 constexpr auto operator-(T left, T right) noexcept -> T
85 {
86 return T{ left.value - right.value };
87 }
88
89 template<typename T> requires StrongNumericType<T>// && ice::detail::numeric::IsNegateEnabled<T>
90 constexpr auto operator-(T left) noexcept -> T
91 {
92 return T{ -left.value };
93 }
94
95 template<typename T> requires StrongNumericType<T>// && ice::detail::numeric::IsMulEnabled<T>
96 constexpr auto operator*(T left, T right) noexcept -> T
97 {
98 return T{ left.value * right.value };
99 }
100
101 template<typename T> requires StrongNumericType<T>// && ice::detail::numeric::IsMulEnabled<T>
102 constexpr auto operator*(T left, ice::StrongNumericBase<T> right) noexcept -> T
103 {
104 return T{ left.value * right };
105 }
106
107 template<typename T> requires StrongNumericType<T>// && ice::detail::numeric::IsDivEnabled<T>
108 constexpr auto operator/(T left, T right) noexcept -> T
109 {
110 return T{ left.value / right.value };
111 }
112
113 template<typename T> requires StrongNumericType<T>// && ice::detail::numeric::IsDivEnabled<T>
114 constexpr auto operator/(T left, ice::StrongNumericBase<T> right) noexcept -> T
115 {
116 return T{ left.value / right };
117 }
118
119 template<typename T> requires StrongNumericType<T>// && ice::detail::numeric::IsAddEqEnabled<T>
120 constexpr auto operator+=(T& left, T right) noexcept -> T&
121 {
122 left.value += right.value;
123 return left;
124 }
125
126 template<typename T> requires StrongNumericType<T>// && ice::detail::numeric::IsSubEqEnabled<T>
127 constexpr auto operator-=(T& left, T right) noexcept -> T&
128 {
129 left.value -= right.value;
130 return left;
131 }
132
133 template<typename T> requires StrongNumericType<T>// && ice::detail::numeric::IsMulEqEnabled<T>
134 constexpr auto operator*=(T& left, T right) noexcept -> T&
135 {
136 left.value *= right.value;
137 return left;
138 }
139
140 template<typename T> requires StrongNumericType<T>// && ice::detail::numeric::IsMulEqEnabled<T>
141 constexpr auto operator*=(T& left, ice::StrongNumericBase<T> right) noexcept -> T&
142 {
143 left.value *= right;
144 return left;
145 }
146
147 template<typename T> requires StrongNumericType<T>// && ice::detail::numeric::IsDivEqEnabled<T>
148 constexpr auto operator/=(T& left, T right) noexcept -> T&
149 {
150 left.value /= right.value;
151 return left;
152 }
153
154 template<typename T> requires StrongNumericType<T>// && ice::detail::numeric::IsDivEqEnabled<T>
155 constexpr auto operator/=(T& left, ice::StrongNumericBase<T> right) noexcept -> T&
156 {
157 left.value /= right;
158 return left;
159 }
160
161} // namespace ice
Concept used to determine if a struct is considerd a strong number wrapper.
Definition strong_type_integral.hxx:18
Definition strong_type_base.hxx:23
Definition strong_type_base.hxx:20
Definition strong_type_integral.hxx:25
Operator
Definition strong_type_integral.hxx:28
@ AddEq
Definition strong_type_integral.hxx:30
@ Add
Definition strong_type_integral.hxx:29
@ Mul
Definition strong_type_integral.hxx:29
@ Neg
Definition strong_type_integral.hxx:29
@ MulEq
Definition strong_type_integral.hxx:30
@ DivEq
Definition strong_type_integral.hxx:30
@ Div
Definition strong_type_integral.hxx:29
@ SubEq
Definition strong_type_integral.hxx:30
@ Sub
Definition strong_type_integral.hxx:29
SPDX-License-Identifier: MIT.
Definition array.hxx:12
constexpr auto operator<=>(ice::TimeType auto left, TimeType auto right) noexcept
Definition clock_types.hxx:135
constexpr auto operator-(ice::TimeType auto left, TimeType auto right) noexcept
Definition clock_types.hxx:151
constexpr auto operator==(ice::TimeType auto left, TimeType auto right) noexcept
Definition clock_types.hxx:159
constexpr auto operator*(T left, T right) noexcept -> T
Definition strong_type_integral.hxx:96
constexpr auto operator/(T left, T right) noexcept -> T
Definition strong_type_integral.hxx:108
constexpr auto operator-=(T &left, T right) noexcept -> T &
Definition strong_type_integral.hxx:127
constexpr auto operator+=(T &left, T right) noexcept -> T &
Definition strong_type_integral.hxx:120
typename ice::detail::ExtractMemberType< decltype(&T::value)>::Type StrongNumericBase
Definition strong_type_integral.hxx:14
constexpr auto operator/=(T &left, T right) noexcept -> T &
Definition strong_type_integral.hxx:148
constexpr auto operator*=(T &left, T right) noexcept -> T &
Definition strong_type_integral.hxx:134
constexpr auto operator+(ice::TimeType auto left, TimeType auto right) noexcept
Definition clock_types.hxx:143
Type tag to enable utility functions for strongly typed numeric values.
Definition strong_type_integral.hxx:11
Definition strong_type_base.hxx:26