值得在生产中使用 std::tr1 吗?

发布于 2024-08-24 10:57:52 字数 256 浏览 6 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

橙幽之幻 2024-08-31 10:57:52

是的,tr1 中的所有内容都会
呆在那里。有些事情将会
std:: 接受,但它们将保留
也在 tr1 中。所以你的代码都没有
一旦新标准出台就会打破
完成了。

请原谅我:不,他们不会。如此处所述:

提案中添加了两条注释,以便向用户明确,在从 TR 到未来标准的过渡中,TR 组件将不会保留在命名空间 std::tr1 中,并且配置宏将消失。

但值得注意的是,现在愿意支持 tr1 的编译器供应商很可能不会把你的脚从地上拉下来,并为你提供某种过渡方法。

Yes, everything that's in tr1 will
stay there. Some things will be
accepted in std::, but they will stay
in tr1 also. So none of your code
will break once the new standard is
finished.

Forgive me: no, they will not. As described here:

Two notes have been added to the proposal to make it clear to users that in the transition from the TR to future standards, the TR components will not remain in namespace std::tr1 and the configuration macros will disappear.

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.

上课铃就是安魂曲 2024-08-31 10:57:52

我的建议是为包含您使用的 TR1 项目的命名空间使用别名。这样,当您的编译器支持它时,您将能够从使用 TR1 版本“移动”到标准版本。

namespace cpp0x = std::tr1;

cpp0x::unordered_map<std::string, int> mymap;

对于 C++0x 编译器,第一行变为:

namespace cpp0x = std;

并且您可以保留其余部分。

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.

namespace cpp0x = std::tr1;

cpp0x::unordered_map<std::string, int> mymap;

for a C++0x compiler, the first line becomes:

namespace cpp0x = std;

and you can leave the rest alone.

北方的韩爷 2024-08-31 10:57:52

unordered_map 将出现在新标准中,hash_map 则不会。请注意,tr1 命名空间也不是标准的。

unordered_map will be in the new standard, hash_map won't be. Note that the tr1 namespace is not standard either.

我的鱼塘能养鲲 2024-08-31 10:57:52

将在 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.

七度光 2024-08-31 10:57:52

对于 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文