用于头文件中的匿名命名空间 [英] Uses for anonymous namespaces in header files

查看:11
本文介绍了用于头文件中的匿名命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天有人在 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.

这篇关于用于头文件中的匿名命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆