在GCC和MSVC中使用TR1文库

Ker*_* SB 10 c++ gcc tr1 visual-c++

我想使用现代版本的GCC和MSVC附带的TR1库,但有一些细微的差别:在GCC中,我不得不说

#include <tr1/memory>
std::tr1::shared_ptr<int> X;
Run Code Online (Sandbox Code Playgroud)

而在MSVC我不得不说

#include <memory>
std::shared_ptr<int> X;
Run Code Online (Sandbox Code Playgroud)

我有两个问题:1)MSVC是否自动在C++ 0x模式下运行(相当于GCC的std = c ++ 0x),或者默认情况下它是否也在C++ 98/03模式下运行?2)如何统一包含和命名空间?我正在考虑"INCLUDE_TR1(内存)"之类的预处理器宏或类似的东西.

为了澄清,我想使用传统的标准C++ 98/03; 不是 C++ 0x(否则没有问题).

对于任何建议我都非常感激!

Ker*_* SB 2

好的,在 Boost.TR1 遇到几个不一致且无法克服的问题之后,特别是在尝试使用 GCC 的本机 TR1 库时,我决定完全放弃 Boost 并使用一个小的 #define 解决方法。这是我的“tr1.h”:

#ifndef _TR1_INCLUDE_H
#define _TR1_INCLUDE_H

/** Usage: #include TR1INCLUDE(unordered_map)
 **
 ** Configuration: Define HAVE_TR1_SUBDIR if you need #include <tr1/unordered_map>; otherwise we take #include <unordered_map>.
 **
 **/

#define QUOTE(arg) <arg>

#ifdef HAVE_TR1_SUBDIR
#  define TR1IFY(arg) tr1/arg
#else
#  define TR1IFY(arg) arg
#endif

#define TR1INCLUDE(arg) QUOTE(TR1IFY(arg))

#endif
Run Code Online (Sandbox Code Playgroud)

现在我可以像这样编写我的程序:

#include "tr1.h"
#include TR1INCLUDE(unordered_map)
Run Code Online (Sandbox Code Playgroud)