I\'m trying to learn some arcane stateful template metaprogramming tricks.
(Here\'s why I want to learn it. Unfortunately this library doesn\'t work on GCC
The body of a constexpr function template must yield the same answer for all instatiations with the same template parameters and same arguments. You need to add a level of indirection, so the calculation can happen in the default argument of a template parameter dependent on the first.
See https://gcc.godbolt.org/z/GHfKKf
namespace Meta
{
template struct Tag {};
template
struct Checker{
static constexpr int currentval() noexcept{
return N;
}
};
template
struct CheckerWrapper{
template>::Read(),int M=Checker::currentval()>
static constexpr int currentval(){
return M;
}
};
template
struct Checker{
template::currentval()>
static constexpr int currentval() noexcept{
return M;
}
};
template>::ReadSet()>
struct Next{
static constexpr int value() noexcept{
return N;
}
};
template class TaggedCounter
{
public:
template ::currentval()> static constexpr int Value(){
return Next::value();
}
};
}