#include <iostream>
#include <type_traits>
template <typename T>
struct is_template : std::false_type {};
template <template <typename...> class C, typename... Ts>
struct is_template<C<Ts...>> : std::true_type {};
template <typename T>
struct A {};
template <typename T>
void func(T a) {
if constexpr (is_template<T>::value) {
std::cout << "T is a template type" << std::endl;
}
else {
std::cout << "T is not a template type" << std::endl;
}
}
int main() {
func(A<int>{}); // 输出 "T is a template type"
func(int{}); // 输出 "T is not a template type"
return 0;
}
C++ 判断类型 <T> 是否为模板类型
最新推荐文章于 2024-06-22 19:46:59 发布