I want to check whether a function can be evaluated during compilation. I found this, but I don't understand the concept completely. I have a few doubts:
What is the role of the following line in the code?
template<int Value = Trait::f()>
Every time when I need to check whether the function is compile-time evaluable, Do I need to make it a member function of some struct?
PS
I am copying the code in the link, just for convenience.
template<typename Trait>
struct test
{
template<int Value = Trait::f()>
static std::true_type do_call(int){ return std::true_type(); }
static std::false_type do_call(...){ return std::false_type(); }
static bool call(){ return do_call(0); }
};
struct trait
{
static int f(){ return 15; }
};
struct ctrait
{
static constexpr int f(){ return 20; }
};
int main()
{
std::cout << "regular: " << test<trait>::call() << std::endl;
std::cout << "constexpr: " << test<ctrait>::call() << std::endl;
}