【问题标题】:Can I use C++ TR1 in VS2010?我可以在 VS2010 中使用 C++ TR1 吗?
【发布时间】:2013-07-19 02:33:27
【问题描述】:

我们有一些用 TR1 编写的代码,例如:

#include <tr1/functional>
...
typedef std::tr1::function<void(int)> MyFunction;
..

使用 GCC 编译可以正常工作,但使用 VS2010 失败。

我们的代码有compatibility issue with C++11,所以恐怕我不能简单地切换到C++11。我也不想在我们的代码中引入 boost。

我应该为 VS2010 下载任何包或其他东西以使其支持 TR1 吗?

【问题讨论】:

    标签: c++ visual-studio-2010 tr1


    【解决方案1】:

    你可以在VS 2010中直接使用&lt;functional&gt;。这样就可以了

    #include <functional>
    ...
    typedef std::function<void(int)> MyFunction;
    ..
    

    VS 2010 将之前在 std::tr1 中的内容移动到通常的 std 命名空间中,但 VS 2008 仍然使用 std::tr1。也就是说,如果需要,您仍然应该能够显式使用 tr1 命名空间,即

    #include <functional>
    ...
    typedef std::tr1::function<void(int)> MyFunction;
    ..
    

    也是有效的(注意包含的头文件没有tr1/)。

    相关链接:

    What are differences between std, tr1 and boost (as namespaces and/or libraries)?

    Why does VS2010 maintain the std::tr1 namespace?

    【讨论】:

      【解决方案2】:

      VS 2010 支持 TR1 开箱即用。但是,当您包含它时,您不需要在文件名的开头使用tr1/

      #include <functional>
      
      typedef std::tr1::function<void(int)> MyFunction;
      

      请注意,TR1 没有为标题指定文件名,因此只要符合 TR1,任何一个都与另一个大致相同。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-12-17
        • 2012-08-21
        • 2012-07-09
        • 2012-07-02
        • 1970-01-01
        • 2011-05-12
        • 2011-06-02
        相关资源
        最近更新 更多