-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlambda_counter.cxx
51 lines (42 loc) · 1.18 KB
/
lambda_counter.cxx
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
template <size_t I>
struct flag {
// Note: Id isn't really neccessary, and this works even when we always supply
// the same type
template <typename Id>
friend constexpr auto adl(flag<I>, Id);
};
template <size_t I>
struct set {
static const constexpr size_t val = I;
template <typename Id>
friend constexpr auto adl(flag<I>, Id) {
return size_t(I);
}
};
template <typename X, size_t I, typename T = flag<I>>
constexpr auto get_current(float) {
return I;
}
template <typename X, size_t I, typename T = flag<I>,
typename = decltype(adl(T{}, X{}))>
constexpr auto get_current(int) {
return get_current<X, I + 1>(0);
}
template <auto X = []() {}>
constexpr auto lambda_counter() {
return set<get_current<decltype(X), 0>(0)>::val;
}
// template struct set<1>;
// template struct set<2>;
struct S;
int main() {
// decltype(adl(flag<1>{})) v2;
// std::cout << wrap<0>::get_current() << std::endl;
std::cout << lambda_counter() << std::endl;
std::cout << lambda_counter() << std::endl;
std::cout << lambda_counter() << std::endl;
std::cout << lambda_counter() << std::endl;
std::cout << lambda_counter() << std::endl;
return 0;
}