Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it worth using std::tr1 in production?

I'm using MS VC 2008 and for some projects Intel C++ compiler 11.0. Is it worth using tr1 features in production? Will they stay in new standard?

For example, now I use stdext::hash_map. TR1 defines std::tr1::unordered_map. But in MS implementation unordered_map is just theirs stdext::hash_map, templatized in another way.

like image 261
flashnik Avatar asked Mar 08 '10 12:03

flashnik


2 Answers

Yes, everything that's in tr1 will stay there. Some things will be accepted in std::, but they will stay in tr1 also. So none of your code will break once the new standard is finished.

Forgive me: no, they will not. As described here:

Two notes have been added to the proposal to make it clear to users that in the transition from the TR to future standards, the TR components will not remain in namespace std::tr1 and the configuration macros will disappear.

But it's worth noting that compiler vendors willing to support tr1 now, will most probably not pull the earth from under your feet, and provide you with some sort of transition method.

like image 185
Jan Avatar answered Oct 12 '22 23:10

Jan


My advice would be to use an alias for the namespace containing the TR1 items you use. This way, you'll be able to "move" from using the TR1 version to the standard version when your compiler supports it.

namespace cpp0x = std::tr1;

cpp0x::unordered_map<std::string, int> mymap;

for a C++0x compiler, the first line becomes:

namespace cpp0x = std;

and you can leave the rest alone.

like image 34
Jerry Coffin Avatar answered Oct 12 '22 23:10

Jerry Coffin