I have a SFINAE template version of is_same
for comparing template template arguments.
It generally works as expected on both templates with fixed and variadic number of template parameters:
namespace eld::util::traits
{
template<template<typename...> class ATT, template<typename...> class BTT>
struct is_same_tt : std::false_type
{
};
template<template<typename...> class TT>
struct is_same_tt<TT, TT> : std::true_type
{
};
}
template<typename AT, typename BT, typename CT>
struct fixed_args_number
{
};
template<typename...>
struct variadic_args
{
};
static_assert(eld::util::traits::is_same_tt<fixed_args_number, fixed_args_number>(), "");
static_assert(eld::util::traits::is_same_tt<variadic_args, variadic_args>(), "");
But when I compare a template template with a fixed number of template parameters to a member template template, I get false
, though true
, when parameters are variadic.
template<template<typename...> class TT>
struct designated
{
template<typename... T>
using tt_type = TT<T...>;
};
// Does not compile
//static_assert(
// eld::util::traits::is_same_tt<fixed_args_number, designated<fixed_args_number>::tt_type>(),
// "");
static_assert(eld::util::traits::is_same_tt<variadic_args, designated<variadic_args>::tt_type>(),
"");
What is the reason? (I only checked it with MinGW64)
The initial problem is to find in a type list a designated class that satisfies the condition for the equality of template template types.
CodePudding user response:
Neither should work: GCC has a bug of helpfulness that it considers an alias template to be the same as the underlying template if they’re sufficiently similar. The fixed/variadic mismatch, while still usable in practice, is enough for it to revert to conforming behavior.