I am trying to implement a basic template metaprogramming struct which determines if a list of types are all the same using std::is_same
. I tried to implement it as follows:
template <typename T, typename U, typename... Args>
struct check_same {
static const bool value = std::is_same<T, U>::value && check_same<U, Args...>::value;
};
template <typename T, typename U>
struct check_same {
static const bool value = std::is_same<T, U>::value;
};
However, if I try to instantiate check_same
I get the following compiler error:
'check_same' : too few template arguments
Why is this not a valid way to perform compile-time boolean algebra? Surely as all of the expressions involved are constexpr
(or const
here as MSVC doesn't yet implement constexpr
), it should compile?
The following will fail to compile:
int main()
{
static_assert( check_same<int, unsigned int, float>::value, "Types must be the same" );
return 0;
}