问题
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.
回答1:
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
回答2:
Isn't this as simple as
#include <tr1/unordered_map>
来源:https://stackoverflow.com/questions/6263262/how-can-i-force-mingw-to-use-tr1-namespace