-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathsubstructural type (affine type).cxx
More file actions
34 lines (27 loc) · 1016 Bytes
/
Copy pathsubstructural type (affine type).cxx
File metadata and controls
34 lines (27 loc) · 1016 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
template<auto, auto>
struct ADLType {
friend consteval auto ADLFunc(ADLType, auto...);
};
template<auto InstanceIdentifier, auto x>
struct InjectDefinitionForADLFunc {
friend consteval auto ADLFunc(ADLType<InstanceIdentifier, x>, auto...) {}
};
template<auto InstanceIdentifier, auto x = 0, auto = []{}>
consteval auto ExtractThenUpdateCurrentState()->decltype(x) {
if constexpr (requires { ADLFunc(ADLType<InstanceIdentifier, x>{}); })
return ExtractThenUpdateCurrentState<InstanceIdentifier, x + 1>();
else
InjectDefinitionForADLFunc<InstanceIdentifier, x>{};
return x;
}
template<auto InstanceIdentifier = []{}>
struct AffineType {};
template<auto InstanceIdentifier, auto x = ExtractThenUpdateCurrentState<InstanceIdentifier>()>
auto Use(AffineType<InstanceIdentifier>) requires (x == 0) {}
auto main()->int {
auto x = AffineType{};
auto y = AffineType{};
Use(x);
Use(y);
// Use(x); <- type level failure
}