Question

We have some code written with TR1, e.g.:

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

It works fine by compiling with GCC, but failed with VS2010.

Our code has compatibility issue with C++11 so I'm afraid I can't simply switch to C++11. I don't want to introduce boost into our code either.

Is there any pack or something I should download for VS2010 to make it support TR1?

Was it helpful?

Solution 2

VS 2010 supports TR1 out of the box. You don't need a tr1/ at the beginning of the file name when you include it though.

#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.

OTHER TIPS

You can directly use <functional> in VS 2010. So it'd be

#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. That said, you should still be able to use tr1 namespace explicitly, if you need it I.e.

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

is valid too (note the header file included doesn't have tr1/).

Relevant Links:

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

Why does VS2010 maintain the std::tr1 namespace?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top