C++ Technical Report 1 (TR1) is the common name for ISO/IEC TR 19768, C++ Library Extensions, which is a document that proposed additions to the C++ standard library for the C++03 language standard. The additions include regular expressions, smart pointers, hash tables, and random number generators. TR1 was not a standard itself, but rather a draft document. However, most of its proposals became part of the later official standard, C++11. Before C++11 was standardized, vendors used this document as a guide to create extensions. The report's goal was "to build more widespread existing practice for an expanded C++ standard library".

The report was first circulated in draft form in 2005 as , then published in 2007 as an ISO/IEC standard as .

Overview

Compilers did not need to include the TR1 components in order to conform to the C++ standard, because TR1 proposals were not part of the standard itself, only a set of possible additions that were still to be ratified. However, most of TR1 was available from Boost, and several compiler/library distributors implemented all or some of the components. TR1 is not the complete list of additions to the library that appeared in C++11. For example, C++11 includes a thread support library that is not available in TR1.

The new components were defined in the std::tr1 namespace to distinguish them from the then-current standard library.

Components

TR1 includes the following components:

General utilities

Reference wrapper – enables passing references, rather than copies, into algorithms or function objects. The feature was based on Boost.Ref. A wrapper reference is obtained from an instance of the template class reference_wrapper. Wrapper references are similar to normal references (‘&’) of the C++ language. To obtain a wrapper reference from any object the template class ref is used (for a constant reference cref is used).

Wrapper references are useful above all for template functions, when argument deduction would not deduce a reference (e.g. when forwarding arguments):

Smart pointers – adds several classes that simplify object lifetime management in complex cases. Three main classes are added:

  • shared_ptr – a reference-counted smart pointer
  • weak_ptr – a variant of shared_ptr that doesn't increase the reference count

The proposal is based on Boost Smart Pointer library.

Function objects

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

Polymorphic function wrapper (function) – can store any callable function (function pointers, member function pointers, and function objects) that uses a specified function call signature. The type does not depend on the kind of the callable used. Based on Boost.Function

Function object binders (bind) – can bind any parameter parameters to function objects. Function composition is also allowed. This is a generalized version of the standard std::bind1st and std::bind2nd bind functions. The feature is based on Boost Bind library.

Function return types (result_of) – determines the type of a call expression.

Member functions (mem_fn) – enhancement to the standard std::mem_fun and std::mem_fun_ref. Allows pointers to member functions to be treated as function objects. Based on Boost Mem Fn library.

Metaprogramming and type traits

There is now <type_traits> header file that contains many useful trait meta-templates, such as is_pod, has_virtual_destructor, remove_extent, etc. It facilitates metaprogramming by enabling queries on and transformation between different types. The proposal is based on Boost Type Traits library.

Numerical facilities

Random number generation

Mathematical special functions

Some features of TR1, such as the mathematical special functions and certain C99 additions, are not included in the Visual C++ implementation of TR1. The Mathematical special functions library was not standardized in C++11.

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

These functions will likely be of principal interest to programmers in the engineering and scientific disciplines.

The following table shows all 23 special functions described in TR1.

Function nameFunction prototypeMathematical expression
Associated Laguerre polynomialsdouble assoc_laguerre(unsigned int n, unsigned int m, double x);L n m ( x ) = ( − 1 ) m d m d x m L n + m ( x ) , for x ≥ 0 {\displaystyle {L_{n}}^{m}(x)=(-1)^{m}{\frac {d^{m}}{dx^{m}}}L_{n+m}(x),{\text{ for }}x\geq 0}
Associated Legendre polynomialsdouble assoc_legendre(unsigned int l, unsigned int m, double x);P l m ( x ) = ( 1 − x 2 ) m / 2 d m d x m P l ( x ) , for x ≥ 0 {\displaystyle {P_{l}}^{m}(x)=(1-x^{2})^{m/2}{\frac {d^{m}}{dx^{m}}}P_{l}(x),{\text{ for }}x\geq 0}
Beta functiondouble beta(double x, double y);B ( x , y ) = Γ ( x ) Γ ( y ) Γ ( x + y ) {\displaystyle \mathrm {B} (x,y)={\frac {\Gamma (x)\Gamma (y)}{\Gamma (x+y)}}}
Complete elliptic integral of the first kinddouble comp_ellint_1(double k);K ( k ) = F ( k , π 2 ) = ∫ 0 π 2 d θ 1 − k 2 sin 2 ⁡ θ {\displaystyle K(k)=F\left(k,\textstyle {\frac {\pi }{2}}\right)=\int _{0}^{\frac {\pi }{2}}{\frac {d\theta }{\sqrt {1-k^{2}\sin ^{2}\theta }}}}
Complete elliptic integral of the second kinddouble comp_ellint_2(double k);E ( k , π 2 ) = ∫ 0 π 2 1 − k 2 sin 2 ⁡ θ d θ {\displaystyle E\left(k,\textstyle {\frac {\pi }{2}}\right)=\int _{0}^{\frac {\pi }{2}}{\sqrt {1-k^{2}\sin ^{2}\theta }}\;d\theta }
Complete elliptic integral of the third kinddouble comp_ellint_3(double k, double nu);Π ( ν , k , π 2 ) = ∫ 0 π 2 d θ ( 1 − ν sin 2 ⁡ θ ) 1 − k 2 sin 2 ⁡ θ {\displaystyle \Pi \left(\nu ,k,\textstyle {\frac {\pi }{2}}\right)=\int _{0}^{\frac {\pi }{2}}{\frac {d\theta }{(1-\nu \sin ^{2}\theta ){\sqrt {1-k^{2}\sin ^{2}\theta }}}}}
Confluent hypergeometric functionsdouble conf_hyperg(double a, double c, double x);F ( a , c , x ) = Γ ( c ) Γ ( a ) ∑ n = 0 ∞ Γ ( a + n ) x n Γ ( c + n ) n ! {\displaystyle F(a,c,x)={\frac {\Gamma (c)}{\Gamma (a)}}\sum _{n=0}^{\infty }{\frac {\Gamma (a+n)x^{n}}{\Gamma (c+n)n!}}}
Regular modified cylindrical Bessel functionsdouble cyl_bessel_i(double nu, double x);I ν ( x ) = i − ν J ν ( i x ) = ∑ k = 0 ∞ ( x / 2 ) ν + 2 k k ! Γ ( ν + k + 1 ) , for x ≥ 0 {\displaystyle I_{\nu }(x)=i^{-\nu }J_{\nu }(ix)=\sum _{k=0}^{\infty }{\frac {(x/2)^{\nu +2k}}{k!\;\Gamma (\nu +k+1)}},{\text{ for }}x\geq 0}
Cylindrical Bessel functions of the first kinddouble cyl_bessel_j(double nu, double x);J ν ( x ) = ∑ k = 0 ∞ ( − 1 ) k ( x / 2 ) ν + 2 k k ! Γ ( ν + k + 1 ) , for x ≥ 0 {\displaystyle J_{\nu }(x)=\sum _{k=0}^{\infty }{\frac {(-1)^{k}\;(x/2)^{\nu +2k}}{k!\;\Gamma (\nu +k+1)}},{\text{ for }}x\geq 0}
Irregular modified cylindrical Bessel functionsdouble cyl_bessel_k(double nu, double x);K ν ( x ) = π 2 i ν + 1 ( J ν ( i x ) + i N ν ( i x ) ) = { I − ν ( x ) − I ν ( x ) sin ⁡ ν π , for x ≥ 0 and ν ∉ Z π 2 lim μ → ν I − μ ( x ) − I μ ( x ) sin ⁡ μ π , for x < 0 and ν ∈ Z {\displaystyle {\begin{aligned}K_{\nu }(x)&=\textstyle {\frac {\pi }{2}}i^{\nu +1}{\big (}J_{\nu }(ix)+iN_{\nu }(ix){\big )}\\&={\begin{cases}\displaystyle {\frac {I_{-\nu }(x)-I_{\nu }(x)}{\sin \nu \pi }},&{\text{for }}x\geq 0{\text{ and }}\nu \notin \mathbb {Z} \\[10pt]\displaystyle {\frac {\pi }{2}}\lim _{\mu \to \nu }{\frac {I_{-\mu }(x)-I_{\mu }(x)}{\sin \mu \pi }},&{\text{for }}x<0{\text{ and }}\nu \in \mathbb {Z} \\\end{cases}}\end{aligned}}}
Cylindrical Neumann functions Cylindrical Bessel functions of the second kinddouble cyl_neumann(double nu, double x);N ν ( x ) = { J ν ( x ) cos ⁡ ν π − J − ν ( x ) sin ⁡ ν π , for x ≥ 0 and ν ∉ Z lim μ → ν J μ ( x ) cos ⁡ μ π − J − μ ( x ) sin ⁡ μ π , for x < 0 and ν ∈ Z {\displaystyle N_{\nu }(x)={\begin{cases}\displaystyle {\frac {J_{\nu }(x)\cos \nu \pi -J_{-\nu }(x)}{\sin \nu \pi }},&{\text{for }}x\geq 0{\text{ and }}\nu \notin \mathbb {Z} \\[10pt]\displaystyle \lim _{\mu \to \nu }{\frac {J_{\mu }(x)\cos \mu \pi -J_{-\mu }(x)}{\sin \mu \pi }},&{\text{for }}x<0{\text{ and }}\nu \in \mathbb {Z} \\\end{cases}}}
Incomplete elliptic integral of the first kinddouble ellint_1(double k, double phi);F ( k , ϕ ) = ∫ 0 ϕ d θ 1 − k 2 sin 2 ⁡ θ , for | k | ≤ 1 {\displaystyle F(k,\phi )=\int _{0}^{\phi }{\frac {d\theta }{\sqrt {1-k^{2}\sin ^{2}\theta }}},{\text{ for }}\left|k\right|\leq 1}
Incomplete elliptic integral of the second kinddouble ellint_2(double k, double phi);E ( k , ϕ ) = ∫ 0 ϕ 1 − k 2 sin 2 ⁡ θ d θ , for | k | ≤ 1 {\displaystyle \displaystyle E(k,\phi )=\int _{0}^{\phi }{\sqrt {1-k^{2}\sin ^{2}\theta }}d\theta ,{\text{ for }}\left|k\right|\leq 1}
Incomplete elliptic integral of the third kinddouble ellint_3(double k, double nu, double phi);Π ( k , ν , ϕ ) = ∫ 0 ϕ d θ ( 1 − ν sin 2 ⁡ θ ) 1 − k 2 sin 2 ⁡ θ , for | k | ≤ 1 {\displaystyle \Pi (k,\nu ,\phi )=\int _{0}^{\phi }{\frac {d\theta }{\left(1-\nu \sin ^{2}\theta \right){\sqrt {1-k^{2}\sin ^{2}\theta }}}},{\text{ for }}\left|k\right|\leq 1}
Exponential integraldouble expint(double x);E i ( x ) = − ∫ − x ∞ e − t t d t {\displaystyle {\mbox{E}}i(x)=-\int _{-x}^{\infty }{\frac {e^{-t}}{t}}\,dt}
Hermite polynomialsdouble hermite(unsigned int n, double x);H n ( x ) = ( − 1 ) n e x 2 d n d x n e − x 2 {\displaystyle H_{n}(x)=(-1)^{n}e^{x^{2}}{\frac {d^{n}}{dx^{n}}}e^{-x^{2}}\,\!}
Hypergeometric seriesdouble hyperg(double a, double b, double c, double x);F ( a , b , c , x ) = Γ ( c ) Γ ( a ) Γ ( b ) ∑ n = 0 ∞ Γ ( a + n ) Γ ( b + n ) Γ ( c + n ) x n n ! {\displaystyle F(a,b,c,x)={\frac {\Gamma (c)}{\Gamma (a)\Gamma (b)}}\sum _{n=0}^{\infty }{\frac {\Gamma (a+n)\Gamma (b+n)}{\Gamma (c+n)}}{\frac {x^{n}}{n!}}}
Laguerre polynomialsdouble laguerre(unsigned int n, double x);L n ( x ) = e x n ! d n d x n ( x n e − x ) , for x ≥ 0 {\displaystyle L_{n}(x)={\frac {e^{x}}{n!}}{\frac {d^{n}}{dx^{n}}}\left(x^{n}e^{-x}\right),{\text{ for }}x\geq 0}
Legendre polynomialsdouble legendre(unsigned int l, double x);P l ( x ) = 1 2 l l ! d l d x l ( x 2 − 1 ) l , for | x | ≤ 1 {\displaystyle P_{l}(x)={1 \over 2^{l}l!}{d^{l} \over dx^{l}}(x^{2}-1)^{l},{\text{ for }}\left|x\right|\leq 1}
Riemann zeta functiondouble riemann_zeta(double x);Z ( x ) = { ∑ k = 1 ∞ k − x , for x > 1 2 x π x − 1 sin ⁡ ( x π 2 ) Γ ( 1 − x ) ζ ( 1 − x ) , for x < 1 {\displaystyle \mathrm {Z} (x)={\begin{cases}\displaystyle \sum _{k=1}^{\infty }k^{-x},&{\text{for }}x>1\\[10pt]\displaystyle 2^{x}\pi ^{x-1}\sin \left({\frac {x\pi }{2}}\right)\Gamma (1-x)\zeta (1-x),&{\text{for }}x<1\\\end{cases}}}
Spherical Bessel functions of the first kinddouble sph_bessel(unsigned int n, double x);j n ( x ) = π 2 x J n + 1 / 2 ( x ) , for x ≥ 0 {\displaystyle j_{n}(x)={\sqrt {\frac {\pi }{2x}}}J_{n+1/2}(x),{\text{ for }}x\geq 0}
Spherical associated Legendre functionsdouble sph_legendre(unsigned int l, unsigned int m, double theta);Y l m ( θ , 0 ) where Y l m ( θ , ϕ ) = ( − 1 ) m [ ( 2 l + 1 ) 4 π ( l − m ) ! ( l + m ) ! ] 1 2 P l m ( cos ⁡ θ ) e i m ϕ , for | m | ≤ l {\displaystyle Y_{l}^{m}(\theta ,0){\text{ where }}Y_{l}^{m}(\theta ,\phi )=(-1)^{m}\left[{\frac {(2l+1)}{4\pi }}{\frac {(l-m)!}{(l+m)!}}\right]^{1 \over 2}P_{l}^{m}(\cos \theta )e^{\mathrm {i} m\phi },{\text{ for }}|m|\leq l}
Spherical Neumann functions Spherical Bessel functions of the second kinddouble sph_neumann(unsigned int n, double x);n n ( x ) = ( π 2 x ) 1 2 N n + 1 2 ( x ) , for x ≥ 0 {\displaystyle n_{n}(x)=\left({\frac {\pi }{2x}}\right)^{\frac {1}{2}}N_{n+{\frac {1}{2}}}(x),{\text{ for }}x\geq 0}

Each function has two additional variants. Appending the suffix ‘f’ or ‘l’ to a function name gives a function that operates on float or long double values respectively. For example:

Containers

Tuple types

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

Fixed size array

  • new <array> header file – array
  • taken from Boost Array library
  • as opposed to dynamic array types such as the standard std::vector

Hash tables

  • new <unordered_set>, <unordered_map> header files
  • they implement the unordered_set, unordered_multiset, unordered_map, and unordered_multimap classes, analogous to set, multiset, map, and multimap, respectively unfortunately, unordered_set and unordered_multiset cannot be used with the set_union, set_intersection, set_difference, set_symmetric_difference, and includes standard library functions, which work for set and multiset
  • 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

Regular expressions

  • new <regex> header file – regex, regex_match, regex_search, regex_replace, etc.
  • based on Boost RegEx library
  • pattern matching library

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

Technical Report 2

In 2005, a request for proposals for a TR2 was made with a special interest in Unicode, XML/HTML, Networking and usability for novice programmers..

Some of the proposals included:

  • Threads
  • The Asio C++ library (networking ).
  • Signals/Slots
  • Filesystem Library – Based on the Boost Filesystem Library, for query/manipulation of paths, files and directories.
  • Boost Any Library
  • Lexical Conversion Library
  • New String Algorithms
  • Toward a More Complete Taxonomy of Algebraic Properties for Numeric Libraries in TR2
  • Adding heterogeneous comparison lookup to associative containers for TR2

After the call was issued for proposals for TR2, ISO procedures were changed, so there will not be a TR2. Instead, enhancements to C++ will be published in a number of Technical Specifications. Some of the proposals listed above are already included in the C++ standard or in draft versions of the Technical Specifications.

See also

  • C++11, standard for the C++ programming language; the library improvements were based on TR1
  • C11 (C standard revision), a revision of the C standard which incorporated some features proposed in TR1
  • Boost library, a large collection of portable C++ libraries, several of which were included in TR1
  • Standard Template Library, part of the current C++ Standard Library

Sources

  • (PDF) (Report). 2005-06-24.
  • (Report). Nov 2007.
  • Becker, Peter (2006). The C++ Standard Library Extensions: A Tutorial and Reference. Addison-Wesley Professional. ISBN 0-321-41299-0.

External links

  • – contains links to the TR1 proposal documents which provide background and rationale for the TR1 libraries.