Допустим, мы используем std::variant
using var_type = std::variant<int, bool, char>;
Или свой шаблон со списком параметров шаблона
template <class Ty1, class Ty2>
struct my_template{};
using my_template_type = my_template<int, char>;
Теперь я хочу определить, входит ли какой-то тип в список параметров шаблона:
using search_type = bool;
Для этого я пишу вот такую вещь:
// Определяет, является ли Ty одним из типов T1, T2... шаблона TemplateType<T1, T2, ...>
template<class Ty, class TemplateType>
struct is_template_parameter; // (1)
template<class Ty, template<class> class TemplateType, class... TemplateParameterTypes>
struct is_template_parameter<Ty, TemplateType<TemplateParameterTypes...>>
: std::disjunction<std::is_same<Ty, TemplateParameterTypes>...> {}; // (2)
template<class Ty, class TemplateType>
constexpr bool is_template_parameter_v = is_template_parameter<Ty, TemplateType>::value;
И использую это так:
void foo(){
bool in_variant_type = is_template_parameter_v<search_type, var_type>;
bool in_my_template_type = is_template_parameter_v<search_type, var_type>;
}
Это работает в MSVC и GCC, но не работает в clang:
<source>:16:46: error: implicit instantiation of undefined template 'is_template_parameter<bool, std::variant<int, bool, char>>'
constexpr bool is_template_parameter_v = is_template_parameter<Ty, TemplateType>::value;
^
<source>:23:28: note: in instantiation of variable template specialization 'is_template_parameter_v<bool, std::variant<int, bool, char>>' requested here
bool in_variant_type = is_template_parameter_v<search_type, var_type>;
^
<source>:9:12: note: template is declared here
struct is_template_parameter;
Я понимаю, что из двух специализация шаблона is_template_parameter
он выбирает (1)
, но не понимаю, почему так происходит?