Skip to content
Surf Wiki
Save to docs
general/c-standard-library

From Surf Wiki (app.surf) — the open knowledge base

C++ Technical Report 1

Document that proposed additions to the C++ standard library


Summary

Document that proposed additions to the C++ standard library

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

CPP
#include <iostream>
#include <tr1/functional>

void f(int& r) { 
    ++r; 
}

template <class Func, class Arg>
void g(Func 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), std::tr1::reference_wrapper<int>>' is instanced
    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 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 `` 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 `` 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

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

  • additions to the / 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 expressionAssociated Laguerre polynomialsAssociated Legendre polynomialsBeta functionComplete elliptic integral of the first kindComplete elliptic integral of the second kindComplete elliptic integral of the third kindConfluent hypergeometric functionsRegular modified cylindrical Bessel functionsCylindrical Bessel functions of the first kindIrregular modified cylindrical Bessel functionsCylindrical Neumann functionsIncomplete elliptic integral of the first kindIncomplete elliptic integral of the second kindIncomplete elliptic integral of the third kindExponential integralHermite polynomialsHypergeometric seriesLaguerre polynomialsLegendre polynomialsRiemann zeta functionSpherical Bessel functions of the first kindSpherical associated Legendre functionsSpherical Neumann functions
{L_n}^m(x) = (-1)^m \frac{d^m}{dx^m} L_{n+m}(x), \text{ for } x \ge 0
{P_l}^m(x) = (1-x^2)^{m/2} \frac{d^m}{dx^m} P_l(x), \text{ for } x \ge 0
\Beta(x,y)=\frac{\Gamma(x) \Gamma(y)}{\Gamma(x+y)}
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}}
E\left(k, \textstyle \frac{\pi}{2}\right) = \int_0^{\frac{\pi}{2}} \sqrt{1 - k^2 \sin^2 \theta}\; d\theta
\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}}
F(a, c, x) = \frac{\Gamma(c)}{\Gamma(a)} \sum_{n = 0}^\infty \frac{\Gamma(a + n) x^n}{\Gamma(c + n) n!}
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 \ge 0
J_\nu(x) = \sum_{k = 0}^\infty \frac{(-1)^k \; (x/2)^{\nu + 2k}}{k! \; \Gamma(\nu + k + 1)}, \text{ for } x \ge 0
\begin{align}
k\right\le 1
k\right\le 1
k\right\le 1
\mbox{E}i(x)=-\int_{-x}^{\infty} \frac{e^{-t}}{t}\, dt
H_n(x)=(-1)^n e^{x^2}\frac{d^n}{dx^n}e^{-x^2}\,\!
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!}
L_n(x)=\frac{e^x}{n!}\frac{d^n}{dx^n}\left(x^n e^{-x}\right), \text{ for } x \ge 0
x\right\le 1
j_n(x) = \sqrt{\frac{\pi}{2x}} J_{n+1/2}(x), \text{ for } x \ge 0
m\leq l
n_n(x) = \left(\frac{\pi}{2x}\right)^{\frac{1}{2}}N_{n+\frac{1}{2}}(x), \text{ for } x \ge 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:

CPP
float sph_neumannf(unsigned int n, float x);
long double sph_neumannl(unsigned int n, long double x);

Containers

Tuple types

  • new `` 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 `` header file – array
  • taken from Boost Array library
  • as opposed to dynamic array types such as the standard std::vector

Hash tables

  • new , 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 `` 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 , , , 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.

References

Sources

References

  1. "ref - 1.72.0".
  2. "Boost.SmartPtr: The Smart Pointer Library - 1.72.0".
  3. "Chapter 16. Boost.Function - 1.72.0".
  4. "Chapter 1. Boost.Bind - 1.72.0".
  5. "Chapter 1. Boost.Member Function - 1.72.0".
  6. "Chapter 1. Boost.TypeTraits - 1.37.0".
  7. "The Boost Tuple Library – Boost 1.48.0".
  8. "Chapter 5. Boost.Array - 1.72.0".
  9. "Boost.Regex - 1.36.0".
Wikipedia Source

This article was imported from Wikipedia and is available under the Creative Commons Attribution-ShareAlike 4.0 License. Content has been adapted to SurfDoc format. Original contributors can be found on the article history page.

Want to explore this topic further?

Ask Mako anything about C++ Technical Report 1 — get instant answers, deeper analysis, and related topics.

Research with Mako

Free with your Surf account

Content sourced from Wikipedia, available under CC BY-SA 4.0.

This content may have been generated or modified by AI. CloudSurf Software LLC is not responsible for the accuracy, completeness, or reliability of AI-generated content. Always verify important information from primary sources.

Report