在GCC和MSVC中使用TR1库 [英] Using TR1 libraries in GCC and MSVC

查看:109
本文介绍了在GCC和MSVC中使用TR1库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  #include< tr1 / memory> 
std :: tr1 :: shared_ptr< int> X;在MSVC中,我必须说



<$>




p $ p> #include< memory>
std :: shared_ptr< int> X;

我有两个问题:1)MSVC是否自动在C ++ 0x模式GCC的std = c ++ 0x),还是它也工作在C ++ 98/03模式默认? 2)如何统一包含和命名空间?我正在考虑一个类似INCLUDE_TR1(memory)或类似的预处理器宏。



为了说明,我想使用传统的标准C ++ 98/03;

我非常感谢任何建议。

解决方案

确定,在Boost.TR1遇到了几个不一致和不可克服的问题,特别是当试图使用GCC的原生TR1库时, Boost完全和使用一个小的#define解决方法。这是我的tr1.h:

  #ifndef _TR1_INCLUDE_H 
#define _TR1_INCLUDE_H
$ b b / **用法:#include TR1INCLUDE(unordered_map)
**
**配置:如果需要,定义HAVE_TR1_SUBDIR #include< tr1 / unordered_map>否则我们取#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

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

  #includetr1.h
#include TR1INCLUDE(unordered_map)


I would like to use the TR1 libraries that ship with modern versions of GCC and MSVC, but there are subtle differences: in GCC, I have to say

#include <tr1/memory>
std::tr1::shared_ptr<int> X;

while in MSVC I have to say

#include <memory>
std::shared_ptr<int> X;

I have two questions: 1) Does MSVC automatically operate in C++0x-mode (equivalent to GCC's std=c++0x), or does it also work in C++98/03 mode by default? 2) How can I unify the includes and namespaces? I was thinking about a preprocessor macro of the sort "INCLUDE_TR1(memory)" or something like that.

To clarify, I want to use the traditional, standard C++98/03; not C++0x (otherwise there'd be no problem).

I'd be most grateful for any suggestions!

解决方案

OK, after having several inconsistent and unsurmountable problems with Boost.TR1, especially when trying to use GCC's native TR1 libraries, I decided to ditch Boost entirely and use a small #define workaround. Here is my "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

Now I can just write my programs like this:

#include "tr1.h"
#include TR1INCLUDE(unordered_map)

这篇关于在GCC和MSVC中使用TR1库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆