c++ - 什么样的C++模板编程可以调用 "meta programming"?

标签 c++ templates stl traits

<分区>

  1. 使用什么样的模板技术,才能称为“元编程”?
  2. 是否有关于什么是元编程和什么不是元编程的明确定义?
  3. 我们的 C++11 STL 是否包含大量元编程?
  4. “type_traits”是“元编程”吗?

非常感谢。

最佳答案

Q1.使用什么样的模板技术,才能称为“元编程”?

模板元编程是指使用模板和编译器来执行编程的一些关键元素:循环、if-else 分支、C/C++ 切换(如分支、递归等)。

第一个这样的元程序用于生成前几个素数作为编译器错误消息。参见 http://www.erwin-unruh.de/primorig.html

Q2.是否有关于什么是元编程和什么不是元编程的明确定义?

可以在 Wikipedia 找到一个很好的定义。 .

Template metaprogramming (TMP) is a metaprogramming technique in which templates are used by a compiler to generate temporary source code, which is merged by the compiler with the rest of the source code and then compiled. The output of these templates include compile-time constants, data structures, and complete functions. The use of templates can be thought of as compile-time execution. The technique is used by a number of languages, the best-known being C++, but also Curl, D, and XL.

Q3.我们的 C++11 STL 是否包含大量元编程?

很有可能,但这是一个猜测。我没有深入研究标准库的任何实现。

Q4.“type_traits”是“元编程”吗?

再说一次,我没有深入研究它,但我想“type_traits”的大部分功能都是使用元编程技术实现的。

关于c++ - 什么样的C++模板编程可以调用 "meta programming"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37770194/

相关文章:

c++ - 如何防止一个程序/进程的分页?

c++ - 如何禁用/覆盖 OpenSceneGraph 中的 Wireframe 和 Stats 键?

c++ - VS 链接器失败,std::string 方法出现 "object already exists"错误

c++ - SFINAE 未检测到 T::reference

c++ - 没有用于调用 'std::basic_string<char>::basic_string c++ 的匹配函数

c++ - 这个简单的模板类我做错了什么?

c++ - GCC 3.4 中奇怪的递归模板模式(确切地说是 MoSync)

c++ - 具有推导类模板特化类型的变量声明符中的冗余括号

c++ - 是否有防止 STL 容器被交换的 C++ 分配器?

C++ : handle resources if constructors may throw exceptions (Reference to FAQ 17. 4]