Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

c++11

boost

tr1

I initially thought they're all the same, but it turned out to be wrong. So can anyone briefly explain the differences between these three? For example:

  1. std::bind ( newest one, next generation of C++ )
  2. std::tr1::bind ( old, extension of C++ std )
  3. boost::bind ( completely separate library )

or std::shared_ptr, std::tr1::shared_ptr, and boost::shared_ptr, ...etc

Update

bind, shared_ptr are examples that help to clarify my question. My intention was to understand the general differences between those three namespaces. There are several libraries that exist in all three namespaces, and apparently bind is one example, as well as shared_ptr.

What namespaces should I stick with? I personally prefer library from std:: since it will be the next standard of C++ ( C++0x ).

like image 710
Chan Avatar asked Jan 13 '11 17:01

Chan


People also ask

What is STD tr1?

The std::tr1 namespace was used to differentiate the libraries in their work-in-progress state, as opposed to everything standardized in the std namespace. 3 - boost::bind is for bind in the boost namespace, if you are using the Boost library.

What is standard namespace library?

Features of the C++ Standard Library are declared within the std namespace. The C++ Standard Library is based upon conventions introduced by the Standard Template Library (STL), and has been influenced by research in generic programming and developers of the STL such as Alexander Stepanov and Meng Lee.


1 Answers

1 - std::bind is the the standard name for it. This will be the name you use for C++11 compliant libraries. List of all libraries in standardized C++.

2 - std::tr1::bind is C++ Technical Report 1 namespace. Between C++03 and C++11 there was the C++ Technical Report 1, which proposed additional libraries and enhancements. Most of these already existed in Boost at the time, and some of these library changes were adopted in the C++11 standard, like <regex> and <functional> (which contains std::bind). The std::tr1 namespace was used to differentiate the libraries in their work-in-progress state, as opposed to everything standardized in the std namespace.

3 - boost::bind is for bind in the boost namespace, if you are using the Boost library. Boost encompasses much more than what is in TR1 and what i in C++11's std library. List of all libraries in Boost as of 1.52.0

Most of what was in TR1 has been standardized and is in the C++11 std namespace, and C++11 contains more libraries than mentioned in TR1 that were adapted from Boost constructs, like threading support defined in <thread>.

Part of what defines what you can use and which namespace you can use now depends on your compiler. I don't recall, but I think the more recent GCC-g++ implementations have started using std namespaces for the new C++11 libraries, but might require a different compiler flag to activate that. They will still support the std::tr1 namespace though. Visual C++ 2010 moved what was previously in std::tr1 into the normal std namespace, but Visual C++ 2008 still used std::tr1.

like image 69
逆さま Avatar answered Sep 19 '22 11:09

逆さま