Uses for anonymous namespaces in header files(用于头文件中的匿名命名空间)
问题描述
今天有人在 SO 上断言,你永远不应该在头文件中使用匿名命名空间.通常这是正确的,但我似乎记得曾经有人告诉我其中一个标准库在头文件中使用匿名命名空间来执行某种初始化.
Someone asserted on SO today that you should never use anonymous namespaces in header files. Normally this is correct, but I seem to remember once someone told me that one of the standard libraries uses anonymous namespaces in header files to perform some sort of initialization.
我没记错吗?有人可以填写详细信息吗?
Am I remembering correctly? Can someone fill in the details?
推荐答案
header 中的无名命名空间唯一有用的情况是,当您只想将代码作为头文件分发时.例如,Boost 的一个大型独立子集纯粹是标头.
The only situation in which a nameless namespace in header can be useful is when you want to distribute code as header files only. For example, a large standalone subset of Boost is purely headers.
另一个答案中提到的元组标记 ignore 是一个例子,_1、_2 等绑定占位符是其他的.
The token ignore for tuples, mentioned in another answer is one example, the _1, _2 etc. bind placeholders are others.
这篇关于用于头文件中的匿名命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:用于头文件中的匿名命名空间
基础教程推荐
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- c++ STL设置差异 2022-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
- 提升 ASIO 流缓冲 2021-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
