C++ Technical Report 1 Explained

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 Draft Technical Report on C++ Library Extensions, then published in 2007 as an ISO/IEC standard as ISO/IEC TR 19768:2007.

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.[1] 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):

  1. include
  2. include

void f(int &r)

template< class Funct, class Arg >void g(Funct f, Arg t)

int main

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

The proposal is based on Boost Smart Pointer library.[2]

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[3]

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.[4]

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.[5]

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.[6]

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.

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 polynomialsdouble assoc_laguerre(unsigned n, unsigned m, double x) ;
m(x)
{L
n}

=(-1)m

dm
dxm

Ln+m(x),forx\ge0

Associated Legendre polynomialsdouble assoc_legendre(unsigned l, unsigned m, double x) ;
m(x)
{P
l}

=(1-x2)m/2

dm
dxm

Pl(x),forx\ge0

Beta functiondouble beta(double x, double y) ;
\Beta(x,y)=\Gamma(x)\Gamma(y)
\Gamma(x+y)
Complete elliptic integral of the first kinddouble comp_ellint_1(double k) ;

K(k)=F\left(k,style

\pi
2

\right)=

\pi
2
\int
0
d\theta
\sqrt{1-k2\sin2\theta
}
Complete elliptic integral of the second kinddouble comp_ellint_2(double k) ;

E\left(k,style

\pi
2

\right)=

\pi
2
\int
0

\sqrt{1-k2\sin2\theta}d\theta

Complete elliptic integral of the third kinddouble comp_ellint_3(double k, double nu) ;

\Pi\left(\nu,k,style

\pi
2

\right)=

\pi
2
\int
0
d\theta
(1-\nu\sin2\theta)\sqrt{1-k2\sin2\theta
}
Confluent hypergeometric functionsdouble conf_hyperg(double a, double c, double x) ;

F(a,c,x)=

\Gamma(c)
\Gamma(a)
infty
\sum
n=0
\Gamma(a+n)xn
\Gamma(c+n)n!
Regular modified cylindrical Bessel functionsdouble cyl_bessel_i(double nu, double x) ;

I\nu(x)=i-\nuJ\nu(ix)=

infty
\sum
k=0
(x/2)\nu
k!\Gamma(\nu+k+1)

,forx\ge0

Cylindrical Bessel functions of the first kinddouble cyl_bessel_j(double nu, double x) ;

J\nu(x)=

infty
\sum
k=0
(-1)k(x/2)\nu
k!\Gamma(\nu+k+1)

,forx\ge0

Irregular modified cylindrical Bessel functionsdouble cyl_bessel_k(double nu, double x) ;

\begin{align} K\nu(x)&=

style\pi
2

i\nu+1(J\nu(ix)+iN\nu(ix))\\ &=\begin{cases} \displaystyle

I-\nu(x)-I\nu(x)
\sin\nu\pi

,&forx\ge0and\nu\notinZ\\[10pt] \displaystyle

\pi
2

\lim\mu

I-\mu(x)-I\mu(x)
\sin\mu\pi

,&forx<0and\nu\inZ\\ \end{cases} \end{align}

Cylindrical Neumann functionsCylindrical Bessel functions of the second kinddouble cyl_neumann(double nu, double x) ;

N\nu(x)=\begin{cases} \displaystyle

J\nu(x)\cos\nu\pi-J-\nu(x)
\sin\nu\pi

,&forx\ge0and\nu\notinZ\\[10pt] \displaystyle\lim\mu

J\mu(x)\cos\mu\pi-J-\mu(x)
\sin\mu\pi

,&forx<0and\nu\inZ\\ \end{cases}

Incomplete elliptic integral of the first kinddouble ellint_1(double k, double phi) ;
\phid\theta
\sqrt{1-k2\sin2\theta
F(k,\phi)=\int
0
}, \text \left
k\right\le 1
Incomplete elliptic integral of the second kinddouble ellint_2(double k, double phi) ;

\displaystyle

\phi\sqrt{1-k
E(k,\phi)=\int
0

2\sin2\theta}d\theta,for\left

k\right\le 1
Incomplete elliptic integral of the third kinddouble ellint_3(double k, double nu, double phi) ;
\phid\theta
\left(1-\nu\sin2\theta\right)\sqrt{1-k2\sin2\theta
\Pi(k,\nu,\phi)=\int
0
}, \text \left
k\right\le 1
Exponential integraldouble expint(double x) ;
infty
Ei(x)=-\int
-x
e-t
t

dt

Hermite polynomialsdouble hermite(unsigned n, double x) ;
n
H
n(x)=(-1)
x2
e
dn
dxn
-x2
e

Hypergeometric seriesdouble hyperg(double a, double b, double c, double x) ;
F(a,b,c,x)=\Gamma(c)
\Gamma(a)\Gamma(b)
infty\Gamma(a+n)\Gamma(b+n)
\Gamma(c+n)
\sum
n=0
xn
n!
Laguerre polynomialsdouble laguerre(unsigned n, double x) ;
L
n(x)=ex
n!
dn
dxn

\left(xne-x\right),forx\ge0

Legendre polynomialsdouble legendre(unsigned l, double x) ;

Pl(x)={1\over2ll!}{dl\overdxl}(x2-1)l,for\left

x\right\le 1
Riemann zeta functiondouble riemann_zeta(double x) ;

\Zeta(x)= \begin{cases} \displaystyle

infty
\sum
k=1

k-x,&forx>1\\[10pt] \displaystyle2x\pix-1\sin\left(

x\pi
2

\right)\Gamma(1-x)\zeta(1-x),&forx<1\\ \end{cases}

Spherical Bessel functions of the first kinddouble sph_bessel(unsigned n, double x) ;

jn(x)=\sqrt{

\pi
2x
} J_(x), \text x \ge 0
Spherical associated Legendre functionsdouble sph_legendre(unsigned l, unsigned m, double theta) ;
m
Y
l

(\theta,0)where

m
Y
l

(\theta,\phi)=(-1)m\left[

(2l+1)
4\pi
(l-m)!
(l+m)!

\right]1

m
P
l

(\cos\theta)eim\phi,for

m\leq l
Spherical Neumann functionsSpherical Bessel functions of the second kinddouble sph_neumann(unsigned n, double x) ;

nn(x)=\left(

\pi
2x
1
2
\right)
N
n+1
2

(x),forx\ge0

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

Containers

Tuple types

Fixed size array

Hash tables

Regular expressions

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 , , , 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.TR2 call for proposals.

Some of the proposals included:

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

References

Sources

External links

Notes and References

  1. Web site: ref - 1.72.0. www.boost.org.
  2. Web site: Boost.SmartPtr: The Smart Pointer Library - 1.72.0. www.boost.org.
  3. Web site: Chapter 16. Boost.Function - 1.72.0. www.boost.org.
  4. Web site: Chapter 1. Boost.Bind - 1.72.0. www.boost.org.
  5. Web site: Chapter 1. Boost.Member Function - 1.72.0. www.boost.org.
  6. Web site: Chapter 1. Boost.TypeTraits - 1.37.0. www.boost.org.
  7. Web site: The Boost Tuple Library – Boost 1.48.0 . 2006-05-27 . https://web.archive.org/web/20060526205142/http://www.boost.org/libs/tuple/doc/tuple_users_guide.html . 2006-05-26 . dead .
  8. Web site: Chapter 5. Boost.Array - 1.72.0. www.boost.org.
  9. Web site: Boost.Regex - 1.36.0. www.boost.org.