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
| #ifndef ODFAEG_COMPILETIME_COUNTER
#define ODFAEG_COMPILETIME_COUNTER
namespace odfaeg {
namespace core {
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 = []{}>
constexpr 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, auto x = 0, auto = []{}>
constexpr auto ExtractCurrentState()->decltype(x) {
return x;
}
template<auto InstanceIdentifier, auto x = 0, auto = []{}>
constexpr auto ResetCurrentState()->decltype(x) {
return 0;
}
template <auto InstanceIdentifier = []{}>
struct Compteur {
template <auto x = ExtractThenUpdateCurrentState<InstanceIdentifier>()>
consteval auto next() const { return x; }
template <auto x = ExtractCurrentState<InstanceIdentifier>()>
consteval auto value() const { return x; }
template <auto x = ResetCurrentState<InstanceIdentifier>()>
void reset() const {
}
};
}
}
#endif |
Partager