Every Flavour Beans

“The time has come…to talk of many [technologies].” –Lewis Carroll(’The Walrus and the Carpenter’)
Development Tools. Web Frameworks. GNU/Linux. Nokia N800. Video Encoding.

December 10, 2006

Getting Started with C++ TR1 Libraries

Filed under: C++ Boost — tabrez @ 3:03 pm

What is C++ TR1?

What exactly is C++ TR1? It is the first Technical Report on C++ Library Extensions as accepted by C++ standards committee and these library extensions will be available in the next official C++ standard to be released - C++0x. All the libraries that are a part of C++ TR1 will be included (hopefully) by the compilers once the next C++ standard is finalised and released. Mathew Austern nicely introduces C++ TR1 on the Dr. Dobbs Journal website:

The C++ Standard Library is a large and successful project. The specification of the library is about 370 pages in length[..] If a C++ program was written within the last five years, it's standard fare for it to use std::string, STL containers and algorithms, or IOStreams.
But if we look at it a little differently, the Standard Library doesn't seem so large after all. The Perl, Python, and Java standard libraries include facilities for parsing XML, performing regular expression searches, manipulating image files, and sending data over the network. From that perspective, the C++ Standard Library looks like it's only the beginning.[...] The question isn't whether we need a more comprehensive library, but how we get one. Historically, members of the Standards committee came up with two answers: Boost Libraries and C++ TR1.

The draft version of the official document describing the extensions to the C++ standard library is available for download from open-std.org website.

Does My Compiler Support C++ TR1?

But if you would like to immediately start playing with these libraries in your C++ programs without having to wait for the next C++ standard to be finalised and released, you have two options to do so.

  1. If you are using one of the later versions of the ubiquitous GCC compiler collection(4.0 or later) on a *NIX flavour of operating system, then consider yourself lucky as the libstdc++ library that had shipped with GCC on your system might already contain a partial implementation of the C++ TR1. GCC website documents the currently supported C++ TR1 libraries. See below for some examples on compiling C++ TR1 code using the recent GCC versions.

    If you are a Windows user, then you can either search for a the binary package of GCC 4.0 or later(only DJGPP seems to support the GCC 4 version; MinGW and Cygwin use older versions) or you can try to build such a version manually from the latest GCC sources. Scott Meyers describes his experience at manually building GCC on his machine and an adapted version of the same is published by MinGW website:

    Testing C++ TR1 Support on Your GCC System

    Fire up your favourite programming editor and enter the following code in it:

    C++:
    1. #include<tr1/array>
    2. #include<iostream>
    3.  
    4. int main()
    5. {
    6.   std::tr1::array<int, 5> a = {{ 1,2,3,4,5 }};
    7.   std::cout <<a[3] <<'\n';
    8. }

    If the above program compiles on your system without any complains from the compiler, then you have got the right version of gcc and libstdc++ installed on your system. You can start scanning through the TR1 libraries and testing how many of them are supported on your system. Below is just another example to test:

    C++:
    1. #include<iostream>
    2. #include<tr1/tuple>
    3. int main()
    4. {
    5.   std::tr1::tuple<int, std::string, double> t(12,"Hello", 43.56);
    6.   std::cout<<std::tr1::get<1>(t)<<std::endl;
    7. }

    You can find more example TR1 code snippets in Austern's article or on the Boost website.

  2. The second way is to download and use the C++ Boost Libraries, which is a collection of high quality C++ libraries including, but not limited to, the C++ TR1 libraries. You can read more about the C++ Boost libraries on the Boost website. If interested, you can browse through the installation procedure of C++ Boost on various operating systems.

New Boost Subset Package For C++ TR1

Boost has announced a new package couple of weeks back containing the subset of Boost Libraries by including only those libraries that have been accepted in C++ TR1. It is in alpha stage right now and currently going through evaluation by the community members. Those who are interested in such a library package can download it from the sourceforge.net website and give it a try. The procedure to download, install, and use the library is summarised below.

  1. Download the alpha version of the package from the sourceforge.net website(use the latest version from the page; currently it is alpha).
  2. Extract it in your home directory, change to the extracted directory and build the package. Let us keep it in the home directory so as not to overwrite the actual Boost library installation(in case it is also installed). This way it helps in updating the package easily in the future by just deleting the contents of the directory and extracting the updated package over it when later versions of the package will be released.
  3. Set include and library paths according to the compiler that you are using.
  4. Create a sample program that uses the boost libraries(see above for some examples) and build it.

According to the (one month old) mailing list announcement, the subset includes:

  • Reference Wrappers
  • Shared_ptr
  • result_of
  • mem_fn
  • Function Object Binders
  • Polymorphic Function Wrappers
  • Type Traits
  • Random Numbers
  • Tuples
  • Array
  • Hash Functions
  • Regular Expressions
  • Complex Number Algorithms

For more documentation on these libraries, refer to the official TR1 document and Boost website. I will follow up with step-by-step procedure to download and install Boost C++ TR1 subset library.


If you want to receive future posts by email, enter your email address here:

Related Posts:

  • Is C++ really a bigger language than Java?
  • Setting the Stage for C++ Boost
  • Maemo SDK VMWare Appliance 0.4 Released With Lot of Goodies
  • Installing C++ Boost on Microsoft Windows for Visual Studio .NET 2003/2005/Orcas
  • Installing C++ Boost on Gentoo and Debian/Ubuntu
  • Wascana is Eclipse Based Standalone C++ IDE for MS Windows
  • Boost Filesystem Library: Writing Portable C++ Programs to Acess The Filesystem

  • Readers who viewed this page, also viewed:


    No Comments »

    No comments yet.

    RSS feed for comments on this post. TrackBack URI

    Leave a comment

    Subscribe without commenting


    Copyright (c) 2006, 2007 Tabrez Iqbal.
    Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. Verbatim copying and distribution of this entire article is permitted in any medium without royalty provided this notice is preserved. A copy of the license is included in the section entitled "GNU Free Documentation License".


    Powered by WordPress
    This website is hosted by Dreamhost