值得在生产中使用 std::tr1 吗?
我正在使用 MS VC 2008,对于某些项目使用 Intel C++ 编译器 11.0。值得在生产中使用 tr1 功能吗?他们会保持新标准吗?
例如,现在我使用 stdext::hash_map
。 TR1 定义了 std::tr1::unordered_map
。但在 MS 实现中,unordered_map
只是他们的 stdext::hash_map
,以另一种方式模板化。
I'm using MS VC 2008 and for some projects Intel C++ compiler 11.0. Is it worth using tr1 features in production? Will they stay in new standard?
For example, now I use stdext::hash_map
. TR1 defines std::tr1::unordered_map
. But in MS implementation unordered_map
is just theirs stdext::hash_map
, templatized in another way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
请原谅我:不,他们不会。如此处所述:
但值得注意的是,现在愿意支持 tr1 的编译器供应商很可能不会把你的脚从地上拉下来,并为你提供某种过渡方法。
Forgive me: no, they will not. As described here:
But it's worth noting that compiler vendors willing to support tr1 now, will most probably not pull the earth from under your feet, and provide you with some sort of transition method.
我的建议是为包含您使用的 TR1 项目的命名空间使用别名。这样,当您的编译器支持它时,您将能够从使用 TR1 版本“移动”到标准版本。
对于 C++0x 编译器,第一行变为:
并且您可以保留其余部分。
My advice would be to use an alias for the namespace containing the TR1 items you use. This way, you'll be able to "move" from using the TR1 version to the standard version when your compiler supports it.
for a C++0x compiler, the first line becomes:
and you can leave the rest alone.
unordered_map
将出现在新标准中,hash_map
则不会。请注意,tr1
命名空间也不是标准的。unordered_map
will be in the new standard,hash_map
won't be. Note that thetr1
namespace is not standard either.将在 C++0x 中添加的绝大多数库代码已经在 Boost C++ 库中存在相当长一段时间了。我强烈建议使用Boost(即 boost::unordered_map ),因为它可以在大量 ISO C++ 1998 编译器上运行,并且将继续在 C++0x 编译器上运行(可能使用编译器的内置实现)。此外,您不需要更改命名空间 - 而 std::tr1 中批准的项目将移至 std - 因为它始终在 boost:: 中可用,您不必担心关于 tr1 的哪些元素已纳入标准。简而言之,Boost 是必经之路。
The vast majority of library code that will be added in C++0x has been around for quite a while in the Boost C++ Libraries. I would strongly recommend using Boost (i.e. boost::unordered_map), since it works on a very large number of ISO C++ 1998 compilers, and will continue to work (probably using the compiler's builtin implementation) on C++0x compilers. In addition, you won't need to change the namespace -- whereas items in std::tr1 that are approved will be moved into std -- since it will always be available in boost::, and you won't have to worry about which elements of tr1 have made it into the standard. In short, Boost is the way to go.
对于 tr1::unordered_map ,请注意,哈希映射有许多种可能的实现,并且标准选择的实现非常经典......但可能不是最适合您的特定任务的实现。
不幸的是,该标准并不要求实施多种策略(尽管我认为这需要相当多的工作)。
For the
tr1::unordered_map
be aware that there are many various implementations of Hash Maps possible and that the implementation elected by the standard is quite classic... but may not be the most performing for your particular task.Unfortunately the standard did not require that multiple strategies be implemented (though I suppose it would have required quite a lot of work).