用于头文件中的匿名命名空间
今天有人在 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.
相关文章