简体   繁体   English

如何强制 MinGW 使用 tr1 命名空间?

[英]How can I force MinGW to use tr1 namespace?

I'm using MinGW 4.5.2 and I'd like to use unordered_map from the tr1 namespace, not the one from std namespace that is enabled by passing -std=c++0x.我正在使用 MinGW 4.5.2,我想使用 tr1 命名空间中的 unordered_map,而不是通过传递 -std=c++0x 启用的 std 命名空间中的 unordered_map。 I'm sure this can be done since there are two unordered_map files, and one is in the tr1 sub-directory.我确信这是可以做到的,因为有两个 unordered_map 文件,一个在 tr1 子目录中。

Clarification: I'm also compiling this code with msvc10 and it supports unordered_map in both namespaces but only in one location.澄清:我也在用 msvc10 编译这段代码,它在两个命名空间中都支持 unordered_map,但只在一个位置。 So I'd like to make it compile with both compilers with changing as least as possible.所以我想让它与两个编译器一起编译,尽可能少地改变。

Include <tr1/unordered_map> and use std::tr1::unordered_map<> .包括<tr1/unordered_map>并使用std::tr1::unordered_map<>

EDIT:编辑:

I'm also compiling this code with msvc10 and it supports it in both namespaces but only in one location.我也在用 msvc10 编译这段代码,它在两个命名空间中都支持它,但只在一个位置。 So I'd like to make it compile with both compilers with changing as least as possible.所以我想让它与两个编译器一起编译,尽可能少地改变。

To make it compile with both compilers you can use something like:要使其与两个编译器一起编译,您可以使用以下内容:

#if defined(_MSC_VER) && _MSC_VER >= 1600
# include <unordered_map>
#else
# include <tr1/unordered_map>
#endif

Isn't this as simple as这不是那么简单吗

#include <tr1/unordered_map>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM