[英]Can I use C++ TR1 in VS2010?
We have some code written with TR1, eg: 我们有一些用TR1编写的代码,例如:
#include <tr1/functional>
...
typedef std::tr1::function<void(int)> MyFunction;
..
It works fine by compiling with GCC, but failed with VS2010. 通过与GCC进行编译,它可以正常工作,但与VS2010一起运行时则失败。
Our code has compatibility issue with C++11 so I'm afraid I can't simply switch to C++11. 我们的代码存在与C ++ 11的兼容性问题,所以我恐怕不能简单地切换到C ++ 11。 I don't want to introduce boost into our code either. 我也不想在我们的代码中引入boost。
Is there any pack or something I should download for VS2010 to make it support TR1? VS2010是否有任何软件包或我应该下载的软件包才能支持TR1?
You can directly use <functional>
in VS 2010. So it'd be 您可以在VS 2010中直接使用<functional>
。
#include <functional>
...
typedef std::function<void(int)> MyFunction;
..
VS 2010 moved what was previously in std::tr1
into the usual std
namespace, but VS 2008 still uses std::tr1
. VS 2010将以前std::tr1
移到了通常的std
名称空间中,但是VS 2008仍使用std::tr1
。 That said, you should still be able to use tr1
namespace explicitly, if you need it Ie 就是说,如果需要,您仍然应该仍然可以显式使用tr1
命名空间。
#include <functional>
...
typedef std::tr1::function<void(int)> MyFunction;
..
is valid too (note the header file included doesn't have tr1/
). 也有效(请注意,所包含的头文件没有tr1/
)。
Relevant Links: 相关链接:
What are differences between std, tr1 and boost (as namespaces and/or libraries)? std,tr1和boost(作为名称空间和/或库)之间有什么区别?
Why does VS2010 maintain the std::tr1 namespace? 为什么VS2010维护std :: tr1命名空间?
VS 2010 supports TR1 out of the box. VS 2010开箱即用地支持TR1。 You don't need a tr1/
at the beginning of the file name when you include it though. 但是,在包含文件名时,不需要在文件名的开头加上tr1/
。
#include <functional>
typedef std::tr1::function<void(int)> MyFunction;
Note that TR1 doesn't specify a file name for the headers, so as far as conforming with TR1 goes, either one is about the same as the other. 请注意,TR1并未为标头指定文件名,因此就符合TR1而言,其中一个与另一个大致相同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.