简体   繁体   中英

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. I'm sure this can be done since there are two unordered_map files, and one is in the tr1 sub-directory.

Clarification: I'm also compiling this code with msvc10 and it supports unordered_map in both namespaces but only in one location. 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<> .

EDIT:

I'm also compiling this code with msvc10 and it supports it in both namespaces but only in one location. 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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