Technical Report 1

From Wikipedia, the free encyclopedia

Technical Report 1 (TR1) is a draft document specifying additions to the C++ Standard Library such as regular expressions, smart pointers, hash tables, and random number generators. TR1 is not yet standardized, but likely will be part of the next official standard mostly as it stands now. In the meantime, vendors can use this document as a guide to create extensions. The report's goal is "to build more widespread existing practice for an expanded C++ standard library."[1]

Contents

[edit] Overview

Compilers need not include the TR1 components to be conforming, as TR1 is not yet officially part of the standard. Much of it is available from Boost, and several compiler/library distributors currently implement all or part of the components.

TR1 is not a complete list of additions to the library that will appear in the next standard; for example, the next standard, C++0x, may include support for threading. There is also a second technical report, TR2, planned for publishing after C++0x [2].

The new components are in the std::tr1 namespace to distinguish them from the current standard library.

[edit] Components

TR1 includes the following components:

[edit] General Utilities

[edit] Reference Wrapper

  • lifted from Boost.Ref [3]
  • additions to the <functional> header file - cref, ref, reference_wrapper
  • enables passing references, rather than copies, into algorithms or function objects

[edit] Smart Pointers

  • based on Boost Smart Pointer library [4]
  • additions to the <memory> header file - shared_ptr, weak_ptr, etc
  • utility for memory management and exception safety using the Resource Acquisition Is Initialization (RAII) idiom

[edit] Function Objects

These four modules are added to the <functional> header file:

[edit] Polymorphic Function Wrapper

  • function
  • based on Boost.Function [5]
  • allows for higher order programming and function object manipulation

[edit] Function Object Binders

  • bind
  • taken from Boost Bind library [6]
  • generalized version of the standard std::bind1st and std::bind2nd
  • binds parameters to function objects

[edit] Function Return Types

  • result_of
  • taken from Boost
  • determines the type of a call expression

[edit] mem_fn

  • mem_fn
  • based on Boost Mem Fn library [7]
  • enhancement to the standard std::mem_fun and std::mem_fun_ref
  • allows pointers to member functions to be treated as objects

[edit] Metaprogramming and Type Traits

  • new <type_traits> header file - is_pod, has_virtual_destructor, remove_extent, etc
  • based on Boost Type Traits library [8]
  • facilitates metaprogramming by enabling queries on and transformation between different types

[edit] Numerical Facilities

[edit] Random Number Generation

[edit] Mathematical Functions

  • additions to the <cmath>/<math.h> header files - beta, legendre, etc
  • mathematical functions

[edit] Containers

[edit] Tuple Types

  • new <tuple> header file - tuple
  • based on Boost Tuple library [9]
  • vaguely an extension of the standard std::pair
  • fixed size collection of elements, which may be of different types

[edit] Fixed Size Array

  • new <array> header file - array
  • lifted from Boost Array library [10]
  • as opposed to dynamic array types such as the standard std::vector

[edit] Hash Tables

  • new <unordered_set>, <unordered_map> header files
  • new implementation, not derived from an existing library, not fully API compatible with existing libraries
  • like all hash tables, often provide constant time lookup of elements but the worst case can be linear in the size of the container

[edit] Regular Expressions

  • new <regex> header file - regex, regex_match, regex_search, regex_replace, etc
  • based on Boost RegEx library [11]
  • pattern matching library

[edit] C Compatibility

C++ is designed to be compatible with the C programming language, but is not a strict superset of C due to diverging standards. TR1 attempts to reconcile some of these differences through additions to various headers in the C++ library, such as <complex>, <locale>, <cmath>, etc. These changes help to bring C++ more in line with the C99 version of the C standard (not all parts of C99 are included in TR1).

[edit] See also

[edit] Literature

  • Peter Becker: "The C++ Standard Library Extensions: A Tutorial and Reference", 2006, ISBN 0-321-41299-0. Covers also the TR1 extensions.

[edit] External links

In other languages