How can I force MinGW to use tr1 namespace?

不想你离开。 提交于 2019-12-13 14:30:44

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!