如何判断两个模板类是否相同 [英] How To Tell If Two Template Classes Are The Same Type
本文介绍了如何判断两个模板类是否相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一个具有两个模板类参数的函数,例如:
Say I have a function that has two template class parameters like:
template <template <typename...> C1, template <typename...> C2>
constexpr bool is_same_container() {
return std::is_same<C1, C2>::value;
}
is_same_container<std::vector, std::vector>();
当我编译时,编译器抱怨需要为 C1 和 C2 提供模板参数.
When I compile, the compiler complains that C1 and C2 needs to be supplied with template arguments.
我的问题是有没有办法直接比较两个未参数化的模板类?
std::vector 应该与 std::vector 相同.我怎么知道?
std::vector should be the same thing as std::vector. How can I find out?
推荐答案
当然,只需编写您自己的 trait.
Sure, just write your own trait.
template<template<class...> class C1, template<class...> class C2>
struct is_same_template : std::false_type {};
template<template<class...> class C>
struct is_same_template<C,C> : std::true_type {};
这篇关于如何判断两个模板类是否相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文