编译时如何检查TR1?
我们正在编写一个日志库,将其自身保存在 .hpp 文件中。 我们希望包含
(如果编译器支持 TR1)或标准 。 是否有一种标准方法可以在编译时检查 tr1 是否可用?
我在想,与“__cplusplus
”定义符号的存在方式相同,也可以定义“__cxx__tr1
”或类似的东西。 我在 TR1 的草稿中没有看到这一点,所以我认为它不存在,但我想先问一下以防万一。
请注意,如果这些定义不存在,将它们包含在提案本身中也不是一个坏主意。
We are programming a logging library that keeps itself in a .hpp file. We would like to include <tr1/unordered_map>
(if the compiler supports TR1,) or the standard <map>
otherwise. Is there a standard way of checking at compile time if tr1 is available or not?
I was thinking that the same way that the "__cplusplus
" define symbol is present, there could have been defined a "__cxx__tr1
" or something like that. I haven't seen that in the drafts for TR1, so I assume it is not present, but I wanted to ask first just in case.
As a note, if those defines don't exist, it wouldn't be a bad idea to include them in proposals themselves.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您正在使用任何配置工具(例如自动工具),您可以尝试编写如下测试:
然后在代码中使用这些定义。
一般来说 __cplusplus 宏应该给你标准版本号,但没有编译器给你 100% 标准实现......因此编写配置宏。
不幸的是,这只是检查此类事情的相当可靠的方法,除非您想为每个编译器编写 1001 #ifdef (boost 的作用)
然后:
If you are using any configuration tools like autotools you may try to write a test like:
And then use these defines in your code.
Generally speaking
__cplusplus
macro should give you standard version number, but there is no compiler that gives you 100% standard implementation... Thus write configure macros.Unfortunately this is only quite reliable way to check such things unless you want to write 1001
#ifdef
for each compiler (what boost does)And then:
GCC-4.3有:
但是,这显然不是标准的。
GCC-4.3 has:
But, this is obviously not standard.
请参阅 ISO C++ (WG21) 论文 N1575 。 这篇论文已从 TR1 中删除,没有替代品。 所以没有官方的方法来检测TR1。
See ISO C++ (WG21) paper N1575. This paper has been dropped from TR1, with no replacement. So there is no official way to detect TR1.
我处理的一个库需要使用一些从 Boost 添加到 TR1 的类,如果可用的话更喜欢 TR1。 解决方案(作为基于 Unix 的库)是将检查推入配置脚本中。
换句话说,据我所知,没有什么可移植的。 也就是说,如果您使用的是 Unix,则配置脚本检查工作得足够好。
One library I deal with needs to use some classes that got added to TR1 from Boost, preferring TR1 if available. The solution (being a Unix-based library) is to shove the checks into the configure script.
So in other words, no, nothing portable that I know of. That said, if you're on Unix, the configure script checks work well enough.
假设您正在使用 VS2010 或任何具有 TR1 可用的套件,如果您执行
uMap
的类型是什么,会发生什么情况?Assuming one is using VS2010, or any suite that has TR1 available, what would happen if one were to do
What would be the type of
uMap
be?