C++ Technical Report 1 (TR1) is the common name for ISO/IEC TR 19768, C++ Library Extensions, which was a document proposing 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 is not a standard itself, but rather a draft document. However, most of its proposals became part of the current official standard, C++11. Before C++11 was standardized, vendors used 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."
Contents |
Compilers need not include the TR1 components to be conforming, as the TR1 proposals are 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 appear in the next standard; for example, the current standard, C++11, supports threading. There is also a second technical report, C++ Technical Report 2, planned for publishing after C++11 [1].
The new components are in the std::tr1
namespace to distinguish them from the current standard library.
TR1 includes the following components:
<functional>
header file - cref
, ref
, reference_wrapper
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):
#include <iostream> #include <tr1/functional> void f( int &r ) { ++r; } template< class Funct, class Arg > void g( Funct f, Arg t ) { f(t); } int main() { int i = 0; g( f, i ); // 'g< void(int &r), int >' is instantiated std::cout << i << "\n"; // Output: 0 g( f, std::tr1::ref(i) ); // 'g< void(int &r), reference_wrapper<int> >' is instanced std::cout << i << "\n"; // Output: 1 }
<memory>
header file - shared_ptr
, weak_ptr
, etc.These four modules are added to the <functional>
header file:
function
bind
std::bind1st
and std::bind2nd
result_of
mem_fn
std::mem_fun
and std::mem_fun_ref
<type_traits>
header file - is_pod
, has_virtual_destructor
, remove_extent
, etc.<random>
header file - variate_generator
, mersenne_twister
, poisson_distribution
, etc.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.
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 name | Function prototype | Mathematical expression |
---|---|---|
Associated Laguerre polynomials | double assoc_laguerre( unsigned n, unsigned m, double x ) ; | |
Associated Legendre polynomials | double assoc_legendre( unsigned l, unsigned m, double x ) ; | |
Beta function | double beta( double x, double y ) ; | |
Complete elliptic integral of the first kind | double comp_ellint_1( double k ) ; | |
Complete elliptic integral of the second kind | double comp_ellint_2( double k ) ; | |
Complete elliptic integral of the third kind | double comp_ellint_3( double k, double nu ) ; | |
Confluent hypergeometric functions | double conf_hyperg( double a, double c, double x ) ; | |
Regular modified cylindrical Bessel functions | double cyl_bessel_i( double nu, double x ) ; | |
Cylindrical Bessel functions of the first kind | double cyl_bessel_j( double nu, double x ) ; | |
Irregular modified cylindrical Bessel functions | double cyl_bessel_k( double nu, double x ) ; | |
Cylindrical Neumann functions | double cyl_neumann( double nu, double x ) ; | |
Incomplete elliptic integral of the first kind | double ellint_1( double k, double phi ) ; | |
Incomplete elliptic integral of the second kind | double ellint_2( double k, double phi ) ; | |
Incomplete elliptic integral of the third kind | double ellint_3( double k, double nu, double phi ) ; | |
Exponential integral | double expint( double x ) ; | |
Hermite polynomials | double hermite( unsigned n, double x ) ; | |
Hypergeometric series | double hyperg( double a, double b, double c, double x ) ; | |
Laguerre polynomials | double laguerre( unsigned n, double x ) ; | |
Legendre polynomials | double legendre( unsigned l, double x ) ; | |
Riemann zeta function | double riemann_zeta( double x ) ; | |
Spherical Bessel functions of the first kind | double sph_bessel( unsigned n, double x ) ; | |
Spherical associated Legendre functions | double sph_legendre( unsigned l, unsigned m, double theta ) ; | |
Spherical Neumann functions | double sph_neumann( unsigned n, double x ) ; |
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:
float sph_neumannf( unsigned n, float x ) ; long double sph_neumannl( unsigned n, long double x ) ;
<tuple>
header file - tuple
std::pair
<array>
header file - array
std::vector
<unordered_set>
, <unordered_map>
header filesunordered_set
, unordered_multiset
, unordered_map
, and unordered_multimap
classes, analogous to set
, multiset
, map
, and multimap
, respectively
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
<regex>
header file - regex
, regex_match
, regex_search
, regex_replace
, etc.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).
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.[3].
Some of the proposals include: