I saw a blog post which used non-type variadic templates (currently not supported by gcc, only by clang).
template
stru
Here are two ways of defining a variadic function template only accepting int
parameters. The first one generates a hard-error when instantiated, the second uses SFINAE:
template
struct and_: std::true_type {};
template
struct and_
: std::integral_constant<
bool
, First::value && and_::value
> {};
template
void
foo(T... t)
{
static_assert(
and_...>::value
, "Invalid parameter was passed" );
// ...
}
template<
typename... T
, typename = typename std::enable_if<
and_...>::value
>::type
>
void
foo(T... t)
{
// ...
}
As you can see, non-type template parameters aren't used here.