这个模板创建的实际源代码是什么样子的?
What will the actual source code this template creates look like?
template <int N>
struct Factorial {
enum { value = N * Factorial<N - 1>::value };
};
template <>
struct Factorial<0> {
enum { value = 1 };
};
const int x = Factorial<4>::value; // == 24
const int y = Factorial<0>::value; // == 1
预编译后,如果我们能神奇地看到编译器生成的结果,我们真的会看到:
const int x = 24;
const int y = 1;
我们会看到struct Factorial
的实际定义,这些的倍数吗?如果是这样,它们看起来会是什么样子?
在此代码上使用g++ -fdump-tree-original
,我看到以下结果,对于这种情况似乎证实了您的怀疑:
;; Function int main() (null)
;; enabled by -tree-original
{
const int x = 24;
const int y = 1;
<<cleanup_point const int x = 24;>>;
<<cleanup_point const int y = 1;>>;
}
return <retval> = 0;
相关文章:
- 在Linux中哪里可以找到互斥、未来等的源代码
- 如果编译的源代码是特定于它编译的硬件的,我们如何分发它
- 使用cmake从源代码构建MySQL连接器/C++失败(与以前的声明冲突)
- 难以理解某些人解决IOI问题的源代码
- 使用g++编译hdf5源代码
- 返回的指向C++对象的链接是什么样的
- 这些是什么样的错误?即使我不在 Linux 上工作,我也遇到了 Linux 错误
- 如何使用C++读取另一个程序中的源代码输出
- Poco FindMySql.cmake 无法找到 MySQL 源代码
- 更改命令行 qt5 源代码构建配置的正确/快速方法
- C++出现控制台错误.我无法识别源代码的问题
- Qt Quick,如何更改 Ui 源代码?
- 使用 Git 处理 C++ Visual Studio 2019 解决方案的外部依赖项源代码管理的最佳方法是什么?
- 从macOS Catalina上的源代码编译LLVM(如何解决未找到"stdio.h")
- 如何使用QT创建器获取网页源代码?
- 从源代码构建 gRPC C++
- 如何使用我构建的库,而不会从源代码出错,但不为我自己的项目编译?
- 如何在使用 LLVM 编译时获取部分源代码的二进制代码
- 如何在源代码中包含外部库的头文件?
- 如何查找 torch.bmm 的 c++ 源代码 pytorch.