c++ - 检查模板类实例化

标签 c++

程序:

#include <iostream>

#include <type_traits>

template <class C>
struct tmpl
{
};

int main(int, char*[])
{
  std::cout << std::is_class<tmpl<int> >::value << std::endl;
  std::cout << std::is_class<tmpl<char> >::value << std::endl;
  return 0;
}

输出:

1
1

但我希望编译器找出模板类 tmpl<int>tmpl<char>尚未实例化和输出0 .是否可以?我真的实例化了类模板吗 tmpl在我的例子中?

最佳答案

通过命名您实例化的类型。一引用tmpl<SomeTypeNamedFoo>编译器将代表您自动实例化。

关于c++ - 检查模板类实例化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15550677/

相关文章:

c++函数在之后立即调用析构函数

c++ - gcc 编译错误 "binding ‘const s’ 到类型 ‘s&’ 的引用丢弃限定符“在其他容器中使用 boost::container::static_vector 时

c++ - 将字符串转换为 GUID 的算法

c++ - 快速 64 位比较

c++ - 为什么 C++ 允许但忽略将 const 应用于函数类型?

c++ - 类相互依赖问题

c# - 从代码调用悬停预览

c++ - 关于 dllexport/dllimprt 的困惑

c++ - 如何使用指向指针的变量?

c++ - 以安全的方式了解 pthread 线程是否处于事件状态