I tried to implement an SFINAE using bool
(unlike popular void_
trick):
template<typename T, bool = true>
struct Resolve
{
static const bool value = false;
};
template<typename T>
struct Resolve<T, T::my_value>
{
static const bool value = true;
};
The goal is to specialize, the classes which have static const bool my_value = true;
defined inside it. If they are defined false
or not defined then don't specialize it. i.e.
struct B1 { // specialize Resolve for this case
static const bool my_value = true;
};
struct B2 { // don't specialize
static const bool my_value = false;
};
struct B3 {}; // don't specialize
When applying the above trick on B1
it gives the compilation error:
Resolve<B1>::value;
error: template argument ‘T::my_value’ involves template parameter(s)
I am aware that this can be achieved with alternate ways. However, I am interested in knowing, why it gives compiler error here and can it be solved in this code itself ?