C++ Technical Report 1#General utilities
{{Short description|Document that proposed additions to the C++ standard library}}
{{Multiple issues|
{{Technical|date=October 2021}}
{{One source|date=October 2021}}
{{how-to|date=October 2021}}
}}
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 [http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf Draft Technical Report on C++ Library Extensions], then published in 2007 as an ISO/IEC standard as [http://www.iso.org/iso/iso_catalogue/catalogue_ics/catalogue_detail_ics.htm?ics1=35&ics2=60&ics3=&csnumber=43289 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.{{Cite web|url=https://www.boost.org/doc/libs/1_72_0/libs/core/doc/html/core/ref.html|title=ref - 1.72.0|website=www.boost.org}} 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
- include
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
std::cout << i << "\n"; // Output: 1
}
Smart pointers – adds several classes that simplify object lifetime management in complex cases. Three main classes are added:
shared_ptr
– a reference-counted smart pointerweak_ptr
– a variant ofshared_ptr
that doesn't increase the reference count
The proposal is based on Boost Smart Pointer library.{{Cite web|url=https://www.boost.org/doc/libs/1_72_0/libs/smart_ptr/doc/html/smart_ptr.html|title=Boost.SmartPtr: The Smart Pointer Library - 1.72.0|website=www.boost.org}}
=Function objects=
These four modules are added to the
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{{Cite web|url=https://www.boost.org/doc/libs/1_72_0/doc/html/function.html|title=Chapter 16. Boost.Function - 1.72.0|website=www.boost.org}}
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.{{Cite web|url=https://www.boost.org/doc/libs/1_72_0/libs/bind/doc/html/bind.html|title=Chapter 1. Boost.Bind - 1.72.0|website=www.boost.org}}
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.{{Cite web|url=https://www.boost.org/doc/libs/1_72_0/libs/bind/doc/html/mem_fn.html|title=Chapter 1. Boost.Member Function - 1.72.0|website=www.boost.org}}
=Metaprogramming and type traits=
There is now
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.{{Cite web|url=https://www.boost.org/doc/libs/1_37_0/libs/type_traits/doc/html/index.html|title=Chapter 1. Boost.TypeTraits - 1.37.0|website=www.boost.org}}
=Numerical facilities=
==Random number generation==
- new
header file –variate_generator
,mersenne_twister
,poisson_distribution
, etc. - utilities for generating random numbers using any of several Pseudorandom number generators, engines, and probability distributions
==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.
class="wikitable" | ||
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 ) ; || K_\nu(x) & = \textstyle\frac{\pi}{2} i^{\nu+1} \big(J_\nu(ix) + i N_\nu(ix)\big) \\ & = \begin{cases} \displaystyle \frac{I_{-\nu}(x) - I_\nu(x)}{\sin \nu\pi}, & \text{for } x \ge 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{align} | ||
Cylindrical Neumann functions
Cylindrical Bessel functions of the second kind | double cyl_neumann( double nu, double x ) ; || N_\nu(x) = \begin{cases} \displaystyle \frac{J_\nu(x)\cos \nu\pi - J_{-\nu}(x)}{\sin \nu\pi}, & \text{for } x \ge 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 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 ) ; || \Zeta(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 kind
| double sph_bessel( unsigned n, double x ) ; || | ||
Spherical associated Legendre functions
| double sph_legendre( unsigned l, unsigned m, double theta ) ; || | ||
Spherical Neumann functions
Spherical Bessel functions of the second kind | 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 ) ;
=Containers=
==Tuple types==
- new
header file –tuple
- based on Boost Tuple library{{Cite web |url=http://www.boost.org/libs/tuple/doc/tuple_users_guide.html |title=The Boost Tuple Library – Boost 1.48.0 |access-date=2006-05-27 |archive-url=https://web.archive.org/web/20060526205142/http://www.boost.org/libs/tuple/doc/tuple_users_guide.html |archive-date=2006-05-26 |url-status=dead }}
- vaguely an extension of the standard
std::pair
- fixed size collection of elements, which may be of different types
==Fixed size array==
- new
header file –array
- taken from Boost Array library{{Cite web|url=https://www.boost.org/doc/libs/1_72_0/doc/html/array.html|title=Chapter 5. Boost.Array - 1.72.0|website=www.boost.org}}
- as opposed to dynamic array types such as the standard
std::vector
==Hash tables==
- new
,<unordered_map>
header files - they implement the
unordered_set
,unordered_multiset
,unordered_map
, andunordered_multimap
classes, analogous toset
,multiset
,map
, andmultimap
, respectively - unfortunately,
unordered_set
andunordered_multiset
cannot be used with theset_union
,set_intersection
,set_difference
,set_symmetric_difference
, andincludes
standard library functions, which work forset
andmultiset
- 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
header file –regex
,regex_match
,regex_search
,regex_replace
, etc. - based on Boost RegEx library{{Cite web|url=https://www.boost.org/doc/libs/1_36_0/libs/regex/doc/html/index.html|title=Boost.Regex - 1.36.0|website=www.boost.org}}
- 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
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.[http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1810.html TR2 call for proposals].
Some of the proposals included:
- Threads [http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1883.pdf ]
- The Asio C++ library (networking [http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1925.pdf ][http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2175.pdf ]).
- Signals/Slots [http://www.mail-archive.com/libsigc-list@gnome.org/msg00115.html [sigc] Proposal for standardization in C++ Library TR2][http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2086.pdf ]
- Filesystem Library [http://www.open-std.org/JTC1/sc22/WG21/docs/papers/2011/n3239.html Filesystem Library for TR2] – Based on the Boost Filesystem Library, for query/manipulation of paths, files and directories.
- Boost Any Library [http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1939.html Any Library Proposal for TR2]
- Lexical Conversion Library [http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1973.html Conversion Library Proposal for TR2]
- New String Algorithms [http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2059.html#abstract Proposal for new string algorithms in TR2]
- Toward a More Complete Taxonomy of Algebraic Properties for Numeric Libraries in TR2 [http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/ ISO/IEC JTC1/SC22/WG21 - Papers 2008]
- Adding heterogeneous comparison lookup to associative containers for TR2 [http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2882.pdf ]
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
References
{{Reflist}}
=Sources=
- {{cite report|title=ISO/IEC JTC1/SC22/WG21 — Draft Technical Report on C++ Library Extensions |url=http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf|date=2005-06-24}}
- {{cite report|title=ISO/IEC TR 19768:2007 — Information technology — Programming languages — Technical Report on C++ Library Extensions|url=http://www.iso.org/iso/iso_catalogue/catalogue_ics/catalogue_detail_ics.htm?ics1=35&ics2=60&ics3=&csnumber=43289|date=Nov 2007}}
- {{cite book | first = Peter | last = Becker | title = The C++ Standard Library Extensions: A Tutorial and Reference | year = 2006 | publisher = Addison-Wesley Professional | isbn = 0-321-41299-0}}
External links
- [http://aristeia.com/EC3E/TR1_info_frames.html Scott Meyers' Effective C++: TR1 Information] – contains links to the TR1 proposal documents which provide background and rationale for the TR1 libraries.