Iros
 
Loading...
Searching...
No Matches
constexpr.h
Go to the documentation of this file.
1#pragma once
2
3#include "di/meta/core.h"
4#include "di/meta/language.h"
6
7namespace di::meta {
8namespace detail {
9 template<typename T>
10 concept ConstexprParam = requires { T::value; } && !concepts::MemberPointer<decltype(&T::value)> &&
11 requires { typename Constexpr<T::value>; };
12
13 template<typename T>
15
16 template<typename T, typename Self>
18}
19
35template<auto val, typename T>
36struct Constexpr {
37 using Value = T;
38 using Type = Constexpr;
39
40 constexpr static auto value = val;
41
42 constexpr operator Value() const { return value; }
43
44 template<detail::ConstexprParam U>
45 // NOLINTNEXTLINE(misc-unconventional-assign-operator)
46 constexpr auto operator=(U) const -> Constexpr<(val = U::value)> {
47 return {};
48 }
49
50 template<auto v = val>
51 constexpr auto operator+() const -> Constexpr<(+v)> {
52 return {};
53 }
54
55 template<auto v = val>
56 constexpr auto operator-() const -> Constexpr<(-v)> {
57 return {};
58 }
59
60 template<auto v = val>
61 constexpr auto operator~() const -> Constexpr<(~v)> {
62 return {};
63 }
64
65 template<auto v = val>
66 constexpr auto operator!() const -> Constexpr<(!v)> {
67 return {};
68 }
69
70 template<auto v = val>
71 constexpr auto operator&() const -> Constexpr<(&v)> {
72 return {};
73 }
74
75 template<auto v = val>
76 constexpr auto operator*() const -> Constexpr<(*v)> {
77 return {};
78 }
79
80 template<detail::ConstexprParam... Vs, auto v = val>
81 constexpr auto operator()(Vs...) const -> Constexpr<(v(Vs::value...))> {
82 return {};
83 }
84
85 template<detail::ConstexprParam... Vs, auto v = val>
86 constexpr auto operator[](Vs...) const -> Constexpr<(v[Vs::value...])> {
87 return {};
88 }
89
90 template<detail::LhsConstexprParam<Type> U, detail::ConstexprParam V>
91 constexpr friend auto operator+(U, V) -> Constexpr<(U::value + V::value)> {
92 return {};
93 }
94
95 template<detail::LhsConstexprParam<Type> U, detail::ConstexprParam V>
96 constexpr friend auto operator-(U, V) -> Constexpr<(U::value - V::value)> {
97 return {};
98 }
99
100 template<detail::LhsConstexprParam<Type> U, detail::ConstexprParam V>
101 constexpr friend auto operator*(U, V) -> Constexpr<(U::value * V::value)> {
102 return {};
103 }
104
105 template<detail::LhsConstexprParam<Type> U, detail::ConstexprParam V>
106 constexpr friend auto operator/(U, V) -> Constexpr<(U::value / V::value)> {
107 return {};
108 }
109
110 template<detail::LhsConstexprParam<Type> U, detail::ConstexprParam V>
111 constexpr friend auto operator%(U, V) -> Constexpr<U::value % V::value> {
112 return {};
113 }
114
115 template<detail::LhsConstexprParam<Type> U, detail::ConstexprParam V>
116 constexpr friend auto operator<<(U, V) -> Constexpr<(U::value << V::value)> {
117 return {};
118 }
119
120 template<detail::LhsConstexprParam<Type> U, detail::ConstexprParam V>
121 constexpr friend auto operator>>(U, V) -> Constexpr<(U::value >> V::value)> {
122 return {};
123 }
124
125 template<detail::LhsConstexprParam<Type> U, detail::ConstexprParam V>
126 constexpr friend auto operator&(U, V) -> Constexpr<(U::value & V::value)> {
127 return {};
128 }
129
130 template<detail::LhsConstexprParam<Type> U, detail::ConstexprParam V>
131 constexpr friend auto operator|(U, V) -> Constexpr<(U::value | V::value)> {
132 return {};
133 }
134
135 template<detail::LhsConstexprParam<Type> U, detail::ConstexprParam V>
136 constexpr friend auto operator^(U, V) -> Constexpr<(U::value ^ V::value)> {
137 return {};
138 }
139
140 template<detail::LhsConstexprParam<Type> U, detail::ConstexprParam V>
141 constexpr friend auto operator&&(U, V) -> Constexpr<(U::value && V::value)> {
142 return {};
143 }
144
145 template<detail::LhsConstexprParam<Type> U, detail::ConstexprParam V>
146 constexpr friend auto operator||(U, V) -> Constexpr<(U::value || V::value)> {
147 return {};
148 }
149
150 template<detail::LhsConstexprParam<Type> U, detail::ConstexprParam V>
151 constexpr friend auto operator==(U, V) -> Constexpr<(U::value == V::value)> {
152 return {};
153 }
154
155 template<detail::LhsConstexprParam<Type> U, detail::ConstexprParam V>
156 constexpr friend auto operator!=(U, V) -> Constexpr<(U::value != V::value)> {
157 return {};
158 }
159
160 template<detail::LhsConstexprParam<Type> U, detail::ConstexprParam V>
161 constexpr friend auto operator<(U, V) -> Constexpr<(U::value < V::value)> {
162 return {};
163 }
164
165 template<detail::LhsConstexprParam<Type> U, detail::ConstexprParam V>
166 constexpr friend auto operator>(U, V) -> Constexpr<(U::value > V::value)> {
167 return {};
168 }
169
170 template<detail::LhsConstexprParam<Type> U, detail::ConstexprParam V>
171 constexpr friend auto operator<=(U, V) -> Constexpr<(U::value <= V::value)> {
172 return {};
173 }
174
175 template<detail::LhsConstexprParam<Type> U, detail::ConstexprParam V>
176 constexpr friend auto operator>=(U, V) -> Constexpr<(U::value >= V::value)> {
177 return {};
178 }
179
180 template<detail::LhsConstexprParam<Type> U, detail::ConstexprParam V>
181 constexpr friend auto operator<=>(U, V) -> Constexpr<(U::value <=> V::value)> {
182 return {};
183 }
184
185 template<detail::LhsConstexprParam<Type> U, detail::ConstexprParam V>
186 constexpr friend auto operator,(U, V) -> Constexpr<(U::value, V::value)> {
187 return {};
188 }
189
190 template<detail::LhsConstexprParam<Type> U, detail::ConstexprParam V>
191 constexpr friend auto operator->*(U, V) -> Constexpr<(U::value->*V::value)> {
192 return {};
193 }
194
195 template<detail::LhsConstexprParam<Type> U, detail::ConstexprParam V>
196 constexpr friend auto operator+=(U, V) -> Constexpr<(U::value += V::value)> {
197 return {};
198 }
199
200 template<detail::LhsConstexprParam<Type> U, detail::ConstexprParam V>
201 constexpr friend auto operator-=(U, V) -> Constexpr<(U::value -= V::value)> {
202 return {};
203 }
204
205 template<detail::LhsConstexprParam<Type> U, detail::ConstexprParam V>
206 constexpr friend auto operator*=(U, V) -> Constexpr<(U::value *= V::value)> {
207 return {};
208 }
209
210 template<detail::LhsConstexprParam<Type> U, detail::ConstexprParam V>
211 constexpr friend auto operator/=(U, V) -> Constexpr<(U::value /= V::value)> {
212 return {};
213 }
214
215 template<detail::LhsConstexprParam<Type> U, detail::ConstexprParam V>
216 constexpr friend auto operator%=(U, V) -> Constexpr<(U::value %= V::value)> {
217 return {};
218 }
219
220 template<detail::LhsConstexprParam<Type> U, detail::ConstexprParam V>
221 friend auto operator&=(U, V) -> Constexpr<(U::value &= V::value)> {
222 return {};
223 }
224
225 template<detail::LhsConstexprParam<Type> U, detail::ConstexprParam V>
226 friend auto operator|=(U, V) -> Constexpr<(U::value |= V::value)> {
227 return {};
228 }
229
230 template<detail::LhsConstexprParam<Type> U, detail::ConstexprParam V>
231 friend auto operator^=(U, V) -> Constexpr<(U::value ^= V::value)> {
232 return {};
233 }
234
235 template<detail::LhsConstexprParam<Type> U, detail::ConstexprParam V>
236 friend auto operator<<=(U, V) -> Constexpr<(U::value <<= V::value)> {
237 return {};
238 }
239
240 template<detail::LhsConstexprParam<Type> U, detail::ConstexprParam V>
241 friend auto operator>>=(U, V) -> Constexpr<(U::value >>= V::value)> {
242 return {};
243 }
244};
245
251template<auto val>
252constexpr inline auto c_ = Constexpr<val> {};
253}
254
255namespace di::concepts {
256namespace detail {
257 template<typename T>
258 constexpr inline bool constexpr_helper = false;
259
260 template<auto val, typename T>
261 constexpr inline bool constexpr_helper<meta::Constexpr<val, T>> = true;
262}
263
269template<typename T>
271
278template<typename T, typename U>
280}
281
282namespace di {
283using meta::c_;
284using meta::Constexpr;
285}
Checks if T is a Constexpr instance with value U.
Definition constexpr.h:279
Checks if T is a Constexpr instance.
Definition constexpr.h:270
Definition operations.h:114
Definition language.h:171
Definition core.h:114
Definition constexpr.h:10
Definition constexpr.h:17
constexpr bool constexpr_helper
Definition constexpr.h:258
Definition any_storable.h:9
Definition const_sentinel.h:8
Definition merge_interfaces.h:6
constexpr auto c_
A value of type Constexpr<val>.
Definition constexpr.h:252
Definition zstring_parser.h:9
A wrapper for a constexpr value.
Definition core.h:77
constexpr auto operator=(U) const -> Constexpr<(val=U::value)>
Definition constexpr.h:46
constexpr friend auto operator%=(U, V) -> Constexpr<(U::value %=V::value)>
Definition constexpr.h:216
constexpr friend auto operator+(U, V) -> Constexpr<(U::value+V::value)>
Definition constexpr.h:91
constexpr friend auto operator->*(U, V) -> Constexpr<(U::value-> *V::value)>
Definition constexpr.h:191
constexpr friend auto operator>(U, V) -> Constexpr<(U::value > V::value)>
Definition constexpr.h:166
constexpr friend auto operator>>(U, V) -> Constexpr<(U::value > > V::value)>
Definition constexpr.h:121
constexpr friend auto operator<=(U, V) -> Constexpr<(U::value<=V::value)>
Definition constexpr.h:171
friend auto operator&=(U, V) -> Constexpr<(U::value &=V::value)>
Definition constexpr.h:221
friend auto operator|=(U, V) -> Constexpr<(U::value|=V::value)>
Definition constexpr.h:226
constexpr friend auto operator<(U, V) -> Constexpr<(U::value< V::value)>
Definition constexpr.h:161
constexpr auto operator*() const -> Constexpr<(*v)>
Definition constexpr.h:76
constexpr friend auto operator-=(U, V) -> Constexpr<(U::value -=V::value)>
Definition constexpr.h:201
constexpr friend auto operator^(U, V) -> Constexpr<(U::value ^ V::value)>
Definition constexpr.h:136
static constexpr auto value
Definition constexpr.h:40
constexpr friend auto operator>=(U, V) -> Constexpr<(U::value >=V::value)>
Definition constexpr.h:176
constexpr auto operator-() const -> Constexpr<(-v)>
Definition constexpr.h:56
constexpr auto operator+() const -> Constexpr<(+v)>
Definition constexpr.h:51
constexpr friend auto operator/=(U, V) -> Constexpr<(U::value/=V::value)>
Definition constexpr.h:211
constexpr friend auto operator!=(U, V) -> Constexpr<(U::value !=V::value)>
Definition constexpr.h:156
constexpr friend auto operator<<(U, V) -> Constexpr<(U::value<< V::value)>
Definition constexpr.h:116
constexpr friend auto operator%(U, V) -> Constexpr< U::value % V::value >
Definition constexpr.h:111
constexpr friend auto operator*=(U, V) -> Constexpr<(U::value *=V::value)>
Definition constexpr.h:206
constexpr friend auto operator,(U, V) -> Constexpr<(U::value, V::value)>
Definition constexpr.h:186
constexpr auto operator[](Vs...) const -> Constexpr<(v[Vs::value...])>
Definition constexpr.h:86
constexpr friend auto operator<=>(U, V) -> Constexpr<(U::value<=> V::value)>
Definition constexpr.h:181
constexpr friend auto operator-(U, V) -> Constexpr<(U::value - V::value)>
Definition constexpr.h:96
constexpr friend auto operator&&(U, V) -> Constexpr<(U::value &&V::value)>
Definition constexpr.h:141
constexpr auto operator!() const -> Constexpr<(!v)>
Definition constexpr.h:66
Constexpr Type
Definition constexpr.h:38
friend auto operator<<=(U, V) -> Constexpr<(U::value<<=V::value)>
Definition constexpr.h:236
constexpr auto operator~() const -> Constexpr<(~v)>
Definition constexpr.h:61
constexpr auto operator()(Vs...) const -> Constexpr<(v(Vs::value...))>
Definition constexpr.h:81
constexpr friend auto operator+=(U, V) -> Constexpr<(U::value+=V::value)>
Definition constexpr.h:196
constexpr friend auto operator*(U, V) -> Constexpr<(U::value *V::value)>
Definition constexpr.h:101
T Value
Definition constexpr.h:37
friend auto operator>>=(U, V) -> Constexpr<(U::value > >=V::value)>
Definition constexpr.h:241
constexpr friend auto operator&(U, V) -> Constexpr<(U::value &V::value)>
Definition constexpr.h:126
friend auto operator^=(U, V) -> Constexpr<(U::value ^=V::value)>
Definition constexpr.h:231
constexpr auto operator&() const -> Constexpr<(&v)>
Definition constexpr.h:71
constexpr friend auto operator==(U, V) -> Constexpr<(U::value==V::value)>
Definition constexpr.h:151
constexpr friend auto operator/(U, V) -> Constexpr<(U::value/V::value)>
Definition constexpr.h:106
constexpr friend auto operator|(U, V) -> Constexpr<(U::value|V::value)>
Definition constexpr.h:131
constexpr friend auto operator||(U, V) -> Constexpr<(U::value||V::value)>
Definition constexpr.h:146