Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of boost. Click here for the latest Boost documentation.
PrevUpHomeNext

TR1 By Subject

Reference Wrappers.
Smart Pointers.
Class template result_of.
Function template mem_fn.
Function Object Binders.
Polymorphic function wrappers.
Type Traits.
Random Number Generators and Distributions.
Tuples.
Tuple Interface to std::pair.
Fixed Size Array.
Hash Function Objects.
Regular Expressions.
Complex Number Algorithm Overloads.
Complex Number Additional Algorithms.

Reference Wrappers.

#include <boost/tr1/functional.hpp>

or

#include <functional>

The Ref library is a small library that is useful for passing references to function templates (algorithms) that would usually take copies of their arguments. It defines the class template reference_wrapper<T>, and the two functions ref and cref that return instances of reference_wrapper<T>. Refer to Boost.Bind for more information.

namespace std {
namespace tr1 {

template <class T> class reference_wrapper;

template <class T> reference_wrapper<T> ref(T&);
template <class T> reference_wrapper<const T> cref(const T&);
template <class T> reference_wrapper<T> ref(reference_wrapper<T>);
template <class T> reference_wrapper<const T> cref(reference_wrapper<T>);

} // namespace tr1
} // namespace std

Configuration: Boost.Config should (automatically) define the macro BOOST_HAS_TR1_REFERENCE_WRAPPER if your standard library implements this part of TR1.

Standard Conformity: The Boost version of this this component does not currently support function call invocation (2.1.2.4), or derivation from std::unary_function or std::binary_function (2.1.2 paragraphs 3 and 4).

The Boost version is not implicitly convertible to T& as the TR requires.

Smart Pointers.

#include <boost/tr1/memory.hpp>

or

#include <memory>

The shared_ptr class template stores a pointer to a dynamically allocated object, typically with a C++ new-expression. The object pointed to is guaranteed to be deleted when the last shared_ptr pointing to it is destroyed or reset. For more information refer to the shared_ptr and weak_ptr documentation.

namespace std {
namespace tr1 {

class bad_weak_ptr;

// [2.2.3] Class template shared_ptr
template<class T> class shared_ptr;

// [2.2.3.6] shared_ptr comparisons
template<class T, class U> bool operator==(shared_ptr<T> const& a, shared_ptr<U> const& b);
template<class T, class U> bool operator!=(shared_ptr<T> const& a, shared_ptr<U> const& b);
template<class T, class U> bool operator<(shared_ptr<T> const& a, shared_ptr<U> const& b);

// [2.2.3.8] shared_ptr specialized algorithms
template<class T> void swap(shared_ptr<T>& a, shared_ptr<T>& b);

// [2.2.3.9] shared_ptr casts
template<class T, class U> shared_ptr<T> static_pointer_cast(shared_ptr<U> const& r);
template<class T, class U> shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const& r);
template<class T, class U> shared_ptr<T> const_pointer_cast(shared_ptr<U> const& r);

// [2.2.3.7] shared_ptr I/O
template<class E, class T, class Y>
basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, shared_ptr<Y> const& p);

// [2.2.3.10] shared_ptr get_deleter
template<class D, class T> D * get_deleter(shared_ptr<T> const& p);

// [2.2.4] Class template weak_ptr
template<class T> class weak_ptr;

// [2.2.4.6] weak_ptr comparison
template<class T, class U> bool operator<(weak_ptr<T> const& a, weak_ptr<U> const& b);

// [2.2.4.7] weak_ptr specialized algorithms
template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b);

// [2.2.5] Class enable_shared_from_this
template<class T> class enable_shared_from_this;

} // namespace tr1
} // namespace std

Configuration: Boost.Config should (automatically) define the macro BOOST_HAS_TR1_SHARED_PTR if your standard library implements this part of TR1.

Standard Conformity: There are no known deviations from the standard when using the Boost version of this component.

Class template result_of.

#include <boost/tr1/functional.hpp>

or

#include <functional>

The class template result_of helps determine the type of a call expression. Given an lvalue f of type F and lvalues t1, t2, ..., tN of types T1, T2, ..., TN, respectively, the type result_of<F(T1, T2, ..., TN)>::type defines the result type of the expression f(t1, t2, ...,tN). The implementation permits the type F to be a function pointer, function reference, member function pointer, or class type. For more information refer to the Boost.Utility documentation.

namespace std {
namespace tr1 {

template <class T>
struct result_of
{
   typedef unspecified type;
};

} // namespace tr1
} // namespace std

Configuration: Boost.Config should (automatically) define the macro BOOST_HAS_TR1_RESULT_OF if your standard library implements this part of TR1.

Standard Conformity: No known problems.

Function template mem_fn.

#include <boost/tr1/functional.hpp>

or

#include <functional>

std::tr1::mem_fn is a generalization of the standard functions std::mem_fun and std::mem_fun_ref. It supports member function pointers with more than one argument, and the returned function object can take a pointer, a reference, or a smart pointer to an object instance as its first argument. mem_fn also supports pointers to data members by treating them as functions taking no arguments and returning a (const) reference to the member. For more information refer to the Boost.Mem_fn documentation.

namespace std {
namespace tr1 {

template <class R, class T> unspecified mem_fn(R T::* pm);

} // namespace tr1
} // namespace std

Configuration: Boost.Config should (automatically) define the macro BOOST_HAS_TR1_MEM_FN if your standard library implements this part of TR1.

Standard Conformity: The Boost implementation does not produce functors that inherit from std::unary_function or std::binary_function, nor does it function correctly with pointers to volatile member functions (these should be extremely rare in practice however).

Function Object Binders.

#include <boost/tr1/functional.hpp>

or

#include <functional>

std::tr1::bind is a generalization of the standard functions std::bind1st and std::bind2nd. It supports arbitrary function objects, functions, function pointers, and member function pointers, and is able to bind any argument to a specific value or route input arguments into arbitrary positions. bind does not place any requirements on the function object; in particular, it does not need the result_type, first_argument_type and second_argument_type standard typedefs. For more information refer to the Boost.Bind documentation.

namespace std {
namespace tr1 {

// [3.6] Function object binders
template<class T> struct is_bind_expression;
template<class T> struct is_placeholder;
template<class F, class T1, ..., class Tn > unspecified bind(F f, T1 t1, ..., Tn tn );
template<class R, class F, class T1, ..., class Tn > unspecified bind(F f, T1 t1, ..., Tn tn );

namespace placeholders {
   // M is the implementation-defined number of placeholders
   extern unspecified _1;
   extern unspecified _2;
   .
   .
   .
   extern unspecified _M;
}

} // namespace tr1
} // namespace std

Configuration: Boost.Config should (automatically) define the macro BOOST_HAS_TR1_BIND if your standard library implements this part of TR1.

Standard Conformity: The traits classes is_placeholder and is_bind_expression are not supported by the Boost implementation.

The named return value syntax isn't supported if the object being bound is a function pointer, for example:

std::tr1::bind(&my_proc, arg1, arg2 /* etc */); // works OK.
std::tr1::bind<double>(&my_proc, arg1, arg2 /* etc */); // causes compiler error.
std::tr1::bind<double>(my_function_object, arg1, arg2 /* etc */); // works OK.

On the other hand, the Boost implementation does work with pointers to overloaded functions, and optionally with function pointers with non-standard calling conventions.

Polymorphic function wrappers.

#include <boost/tr1/functional.hpp>

or

#include <functional>

The polymorphic function wrappers are a family of class templates that may be used as a generalized callback mechanism. A polymorphic function wrapper shares features with function pointers, in that both define a call interface (for example a function taking two integer arguments and returning a floating-point value) through which some arbitrary code may be called. However a polymorphic function wrapper can call any callable object with a compatible call signature, this could be a function pointer, or it could be a function object produced by std::tr1::bind, or some other mechanism. For more information see the Boost.Function documentation.

namespace std {
namespace tr1 {

// [3.7] polymorphic function wrappers
class bad_function_call;

template<class Function> 
class function;

template<class Function>
void swap(function<Function>&, function<Function>&);

template<class Function1, class Function2>
void operator==(const function<Function1>&, const function<Function2>&);
template<class Function1, class Function2>
void operator!=(const function<Function1>&, const function<Function2>&);
template <class Function>
bool operator==(const function<Function>&, unspecified-null-pointer-type );
template <class Function>
bool operator==(unspecified-null-pointer-type , const function<Function>&);
template <class Function>
bool operator!=(const function<Function>&, unspecified-null-pointer-type );
template <class Function>
bool operator!=(unspecified-null-pointer-type , const function<Function>&);

} // namespace tr1
} // namespace std

Configuration: Boost.Config should (automatically) define the macro BOOST_HAS_TR1_FUNCTION if your standard library implements this part of TR1.

Standard Conformity: The Boost version of std::tr1::function lacks the member function target_type() and does not inherit from std::unary_function or std::binary_function when applicable. The member function target() can only access pointer-to-member targets when they have been wrapped in mem_fn.

Type Traits.

#include <boost/tr1/type_traits.hpp>

or

#include <type_traits>

Type traits enable generic code to access the fundamental properties of a type, to determine the relationship between two types, or to transform one type into another related type. For more information refer to the Boost.Type_traits documentation.

namespace std {
namespace tr1 {

template <class T, T v> struct integral_constant;

typedef integral_constant<bool, true> true_type;
typedef integral_constant<bool, false> false_type;

// [4.5.1] primary type categories:
template <class T> struct is_void;
template <class T> struct is_integral;
template <class T> struct is_floating_point;
template <class T> struct is_array;
template <class T> struct is_pointer;
template <class T> struct is_reference;
template <class T> struct is_member_object_pointer;
template <class T> struct is_member_function_pointer;
template <class T> struct is_enum;
template <class T> struct is_union;
template <class T> struct is_class;
template <class T> struct is_function;

// [4.5.2] composite type categories:
template <class T> struct is_arithmetic;
template <class T> struct is_fundamental;
template <class T> struct is_object;
template <class T> struct is_scalar;
template <class T> struct is_compound;
template <class T> struct is_member_pointer;

// [4.5.3] type properties:
template <class T> struct is_const;
template <class T> struct is_volatile;
template <class T> struct is_pod;
template <class T> struct is_empty;
template <class T> struct is_polymorphic;
template <class T> struct is_abstract;
template <class T> struct has_trivial_constructor;
template <class T> struct has_trivial_copy;
template <class T> struct has_trivial_assign;
template <class T> struct has_trivial_destructor;
template <class T> struct has_nothrow_constructor;
template <class T> struct has_nothrow_copy;
template <class T> struct has_nothrow_assign;
template <class T> struct has_virtual_destructor;
template <class T> struct is_signed;
template <class T> struct is_unsigned;
template <class T> struct alignment_of;
template <class T> struct rank;
template <class T, unsigned I = 0> struct extent;

// [4.6] type relations:
template <class T, class U> struct is_same;
template <class Base, class Derived> struct is_base_of;
template <class From, class To> struct is_convertible;

// [4.7.1] const-volatile modifications:
template <class T> struct remove_const;
template <class T> struct remove_volatile;
template <class T> struct remove_cv;
template <class T> struct add_const;
template <class T> struct add_volatile;
template <class T> struct add_cv;

// [4.7.2] reference modifications:
template <class T> struct remove_reference;
template <class T> struct add_reference;

// [4.7.3] array modifications:
template <class T> struct remove_extent;
template <class T> struct remove_all_extents;

// [4.7.4] pointer modifications:
template <class T> struct remove_pointer;
template <class T> struct add_pointer;

// [4.8] other transformations:
template <std::size_t Len, std::size_t Align> struct aligned_storage;

} // namespace tr1
} // namespace std

Configuration: Boost.Config should (automatically) define the macro BOOST_HAS_TR1_TYPE_TRAITS if your standard library implements this part of TR1.

Standard Conformity: No known problems.

Random Number Generators and Distributions.

#include <boost/tr1/random.hpp>

or

#include <random>

The random number library is devided into three parts: generators, which are nullary functors producing uniform random number distributions. Distributions, which are unary functors that adapt a generator to some specific kind of distribution. And the class template variate_generator which combines a generator with a distribution, to create a new generator. For more information see the Boost.Random documentation.

namespace std {
namespace tr1 {

// [5.1.3] Class template variate_generator
template<class UniformRandomNumberGenerator, class Distribution>
class variate_generator;

// [5.1.4.1] Class template linear_congruential
template<class IntType, IntType a, IntType c, IntType m>
class linear_congruential;

// [5.1.4.2] Class template mersenne_twister
template<class UIntType, int w, int n, int m, int r,
UIntType a, int u, int s, UIntType b, int t, UIntType c, int l>
class mersenne_twister;

// [5.1.4.3] Class template substract_with_carry
template<class IntType, IntType m, int s, int r>
class subtract_with_carry;

// [5.1.4.4] Class template substract_with_carry_01
template<class RealType, int w, int s, int r>
class subtract_with_carry_01;

// [5.1.4.5] Class template discard_block
template<class UniformRandomNumberGenerator, int p, int r>
class discard_block;

// [5.1.4.6] Class template xor_combine
template<class UniformRandomNumberGenerator1, int s1,
class UniformRandomNumberGenerator2, int s2>
class xor_combine;

// [5.1.5] Predefined generators
typedef linear_congruential<
            implementation-defined , 
            16807, 
            0, 
            2147483647> minstd_rand0;
            
typedef linear_congruential<
            implementation-defined , 
            48271, 
            0, 
            2147483647> minstd_rand;
            
typedef mersenne_twister<
            implementation-defined ,
            32, 624, 397, 31, 
            0x9908b0df, 11, 7, 
            0x9d2c5680, 15, 
            0xefc60000, 18> mt19937;
            
typedef subtract_with_carry_01<
            float, 
            24, 
            10, 
            24> ranlux_base_01;
            
typedef subtract_with_carry_01<
            double, 
            48, 
            10, 
            24> ranlux64_base_01;
            
typedef discard_block<
            subtract_with_carry<
                  implementation-defined , 
                  (1<<24), 
                  10, 
                  24>, 
            223, 
            24> ranlux3;
            
typedef discard_block<
            subtract_with_carry<
                  implementation-defined, 
                  (1<<24), 
                  10, 
                  24>, 
            389, 
            24> ranlux4;
            
typedef discard_block<
            subtract_with_carry_01<
                  float, 
                  24, 
                  10, 
                  24>, 
            223, 
            24> ranlux3_01;
            
typedef discard_block<
            subtract_with_carry_01<
                  float, 
                  24, 
                  10, 
                  24>, 
            389, 
            24> ranlux4_01;

// [5.1.6] Class random_device
class random_device;

// [5.1.7.1] Class template uniform_int
template<class IntType = int>
class uniform_int;

// [5.1.7.2] Class bernoulli_distribution
class bernoulli_distribution;

// [5.1.7.3] Class template geometric_distribution
template<class IntType = int, class RealType = double>
class geometric_distribution;

// [5.1.7.4] Class template poisson_distribution
template<class IntType = int, class RealType = double>
class poisson_distribution;

// [5.1.7.5] Class template binomial_distribution
template<class IntType = int, class RealType = double>
class binomial_distribution;

// [5.1.7.6] Class template uniform_real
template<class RealType = double>
class uniform_real;

// [5.1.7.7] Class template exponential_distribution
template<class RealType = double>
class exponential_distribution;

// [5.1.7.8] Class template normal_distribution
template<class RealType = double>
class normal_distribution;

// [5.1.7.9] Class template gamma_distribution
template<class RealType = double>
class gamma_distribution;

} // namespace tr1
} // namespace std

Configuration: Boost.Config should (automatically) define the macro BOOST_HAS_TR1_RANDOM if your standard library implements this part of TR1.

Standard Conformity: The Boost implementation has the following limitations:

  • The linear_congruential generator is fully supported for signed integer types only (unsigned types probably only work when the modulus is zero).
  • The subtract_with_carry template does not support a modulus of zero.
  • Not all of the standard generator types have Boost documentation yet, they are none the less supported however.
  • Class template variate_generator does not have a template unary function call operator(), only the non-template nullary version.

Note also that most of the Random number generators have been re-implemented as thin wrappers around the Boost versions in order to provide a standard conforming interface (the Boost versions all take an additional, redundant, template parameter, and are initialized by iterators rather than functors).

Tuples.

#include <boost/tr1/tuple.hpp>

or

#include <tuple>

A tuple is a fixed size collection of elements. Pairs, triples, quadruples etc. are tuples. In a programming language, a tuple is a data object containing other objects as elements. These element objects may be of different types. Tuples are convenient in many circumstances. For instance, tuples make it easy to define functions that return more than one value. Some programming languages, such as ML, Python and Haskell, have built-in tuple constructs. Unfortunately C++ does not. To compensate for this "deficiency", the TR1 Tuple Library implements a tuple construct using templates. For more information see the Boost Tuple Library Documentation.

namespace std {
namespace tr1 {

// [6.1.3] Class template tuple
template <class T1 = unspecified ,
class T2 = unspecified ,
...,
class TM = unspecified > class tuple;

// [6.1.3.2] Tuple creation functions
const unspecified ignore;

template<class T1, class T2, ..., class TN>
tuple<V1, V2, ..., VN> make_tuple(const T1&, const T2& , ..., const TN&);

// [6.1] Tuple types Containers
template<class T1, class T2, ..., class TN>
tuple<T1&, T2&, ..., TN&> tie(T1&, T2& , ..., TN&);

// [6.1.3.3] Tuple helper classes
template <class T> class tuple_size;
template <int I, class T> class tuple_element;

// [6.1.3.4] Element access
template <int I, class T1, class T2, ..., class TN>
RI get(tuple<T1, T2, ..., TN>&);
template <int I, class T1, class T2, ..., class TN>
PI get(const tuple<T1, T2, ..., TN>&);

// [6.1.3.5] relational operators
template<class T1, class T2, ..., class TM, class U1, class U2, ..., class UM>
bool operator==(const tuple<T1, T2, ..., TM>&, const tuple<U1, U2, ..., UM>&);
template<class T1, class T2, ..., class TM, class U1, class U2, ..., class UM>
bool operator<(const tuple<T1, T2, ..., TM>&, const tuple<U1, U2, ..., UM>&);
template<class T1, class T2, ..., class TM, class U1, class U2, ..., class UM>
bool operator!=(const tuple<T1, T2, ..., TM>&, const tuple<U1, U2, ..., UM>&);
template<class T1, class T2, ..., class TM, class U1, class U2, ..., class UM>
bool operator>(const tuple<T1, T2, ..., TM>&, const tuple<U1, U2, ..., UM>&);
template<class T1, class T2, ..., class TM, class U1, class U2, ..., class UM>
bool operator<=(const tuple<T1, T2, ..., TM>&, const tuple<U1, U2, ..., UM>&);
template<class T1, class T2, ..., class TM, class U1, class U2, ..., class UM>
bool operator>=(const tuple<T1, T2, ..., TM>&, const tuple<U1, U2, ..., UM>&);

} // namespace tr1
} // namespace std

Configuration: Boost.Config should (automatically) define the macro BOOST_HAS_TR1_TUPLE if your standard library implements this part of TR1.

Standard Conformity: No known issues for conforming compilers.

Tuple Interface to std::pair.

#include <boost/tr1/utility.hpp>

or

#include <utility>

The existing class template std::pair, can also be accessed using the tuple interface.

namespace std {
namespace tr1 {

template <class T> class tuple_size; // forward declaration
template <int I, class T> class tuple_element; // forward declaration
template <class T1, class T2> struct tuple_size<std::pair<T1, T2> >;
template <class T1, class T2> struct tuple_element<0, std::pair<T2, T2> >;
template <class T1, class T2> struct tuple_element<1, std::pair<T2, T2> >;
// see below for definition of "P".
template<int I, class T1, class T2> P& get(std::pair<T1, T2>&);
template<int I, class T1, class T2> const P& get(const std::pair<T1, T2>&);

} // namespace tr1
} // namespace std

Configuration: Boost.Config should (automatically) define the macro BOOST_HAS_TR1_UTILITY if your standard library implements this part of TR1.

Standard Conformity: No known problems.

Fixed Size Array.

#include <boost/tr1/array.hpp>

or

#include <array>

Class template array is a fixed size array that is safer than and no less efficient than a C style array. Class array fulfils almost all of the requirements of a reversible-container (see Section 23.1, [lib.container.requirements] of the C++ Standard). For more information refer to the Boost.Array documentation.

namespace std {
namespace tr1 {

// [6.2.2] Class template array
template <class T, size_t N > struct array;

// Array comparisons
template <class T, size_t N> bool operator== (const array<T,N>& x, const array<T,N>& y);
template <class T, size_t N> bool operator< (const array<T,N>& x, const array<T,N>& y);
template <class T, size_t N> bool operator!= (const array<T,N>& x, const array<T,N>& y);
template <class T, size_t N> bool operator> (const array<T,N>& x, const array<T,N>& y);
template <class T, size_t N> bool operator>= (const array<T,N>& x, const array<T,N>& y);
template <class T, size_t N> bool operator<= (const array<T,N>& x, const array<T,N>& y);

// [6.2.2.2] Specialized algorithms
template <class T, size_t N > void swap(array<T,N>& x, array<T,N>& y);

// [6.2.2.5] Tuple interface to class template array
template <class T> class tuple_size; // forward declaration
template <int I, class T> class tuple_element; // forward declaration
template <class T, size_t N> struct tuple_size<array<T, N> >;
template <int I, class T, size_t N> struct tuple_element<I, array<T, N> >;
template <int I, class T, size_t N> T& get( array<T, N>&);
template <int I, class T, size_t N> const T& get(const array<T, N>&);

} // namespace tr1
} // namespace std

Configuration: Boost.Config should (automatically) define the macro BOOST_HAS_TR1_ARRAY if your standard library implements this part of TR1.

Standard Conformity: No known issues as of Boost-1.34 onwards.

Hash Function Objects.

#include <boost/tr1/functional.hpp>

or

#include <functional>

Class template std::hash is a unary-functor that converts some type T into a hash-value, specializations of std::hash are provided for integer, character, floating point, and pointer types, plus the two string types std::string and std::wstring. See the Boost.Hash documentation for more information.

namespace std {
namespace tr1 {

template <class T> 
struct hash : public unary_function<T, size_t>
{
   size_t operator()(T val)const;
};

// Hash function specializations
template <> struct hash<bool>;
template <> struct hash<char>;
template <> struct hash<signed char>;
template <> struct hash<unsigned char>;
template <> struct hash<wchar_t>;
template <> struct hash<short>;
template <> struct hash<int>;
template <> struct hash<long>;
template <> struct hash<unsigned short>;
template <> struct hash<unsigned int>;
template <> struct hash<unsigned long>;
template <> struct hash<float>;
template <> struct hash<double>;
template <> struct hash<long double>;
template<class T> struct hash<T*>;
template <> struct hash<std::string>;
template <> struct hash<std::wstring>;

} // namespace tr1
} // namespace std

Configuration: Boost.Config should (automatically) define the macro BOOST_HAS_TR1_HASH if your standard library implements this part of TR1.

Standard Conformity: Boost.Hash adds specialisations of std::hash for a wider range of types than those required by TR1: Boost.Hash acts as a testbed for issue 6.18 in the Library Extension Technical Report Issues List.

Regular Expressions.

#include <boost/tr1/regex.hpp>

or

#include <regex>

This library provides comprehensive support for regular expressions, including either iterator or string based matching, searching, search-and-replace, iteration, and tokenization. Both POSIX and ECMAScript (JavaScript) regular expressions are supported. For more information see the Boost.Regex documentation.

namespace std {
namespace tr1 {

// [7.5] Regex constants
namespace regex_constants {

typedef bitmask_type syntax_option_type;
typedef bitmask_type match_flag_type;
typedef implementation-defined error_type;

} // namespace regex_constants

// [7.6] Class regex_error
class regex_error;

// [7.7] Class template regex_traits
template <class charT> struct regex_traits;

// [7.8] Class template basic_regex
template <class charT, class traits = regex_traits<charT> > 
class basic_regex;

typedef basic_regex<char> regex;
typedef basic_regex<wchar_t> wregex;

// [7.8.6] basic_regex swap
template <class charT, class traits>
void swap(basic_regex<charT, traits>& e1,
         basic_regex<charT, traits>& e2);
          
// [7.9] Class template sub_match
template <class BidirectionalIterator>
class sub_match;

typedef sub_match<const char*> csub_match;
typedef sub_match<const wchar_t*> wcsub_match;
typedef sub_match<string::const_iterator> ssub_match;
typedef sub_match<wstring::const_iterator> wssub_match;

// [7.9.2] sub_match non-member operators

/* Comparison operators omitted for clarity.... */

template <class charT, class ST, class BiIter>
basic_ostream<charT, ST>&
   operator<<(basic_ostream<charT, ST>& os, 
            const sub_match<BiIter>& m);

// [7.10] Class template match_results
template <class BidirectionalIterator,
         class Allocator = allocator<sub_match<BidirectionalIterator> > >
class match_results;

typedef match_results<const char*> cmatch;
typedef match_results<const wchar_t*> wcmatch;
typedef match_results<string::const_iterator> smatch;
typedef match_results<wstring::const_iterator> wsmatch;

// match_results comparisons
template <class BidirectionalIterator, class Allocator>
bool operator== (const match_results<BidirectionalIterator, Allocator>& m1,
               const match_results<BidirectionalIterator, Allocator>& m2);
template <class BidirectionalIterator, class Allocator>
bool operator!= (const match_results<BidirectionalIterator, Allocator>& m1,
               const match_results<BidirectionalIterator, Allocator>& m2);

// [7.10.6] match_results swap
template <class BidirectionalIterator, class Allocator>
void swap(match_results<BidirectionalIterator, Allocator>& m1,
         match_results<BidirectionalIterator, Allocator>& m2);
          
// [7.11.2] Function template regex_match
template <class BidirectionalIterator, class Allocator, class charT, class traits>
bool regex_match(BidirectionalIterator first, 
               BidirectionalIterator last,
               match_results<BidirectionalIterator, Allocator>& m,
               const basic_regex<charT, traits>& e,
               regex_constants::match_flag_type flags = regex_constants::match_default);

template <class BidirectionalIterator, class charT, class traits>
bool regex_match(BidirectionalIterator first, 
               BidirectionalIterator last,
               const basic_regex<charT, traits>& e,
               regex_constants::match_flag_type flags = regex_constants::match_default);
                 
template <class charT, class Allocator, class traits>
bool regex_match(const charT* str, 
               match_results<const charT*, Allocator>& m,
               const basic_regex<charT, traits>& e,
               regex_constants::match_flag_type flags = regex_constants::match_default);
                 
template <class ST, class SA, class Allocator, class charT, class traits>
bool regex_match(const basic_string<charT, ST, SA>& s,
               match_results<typename basic_string<charT, ST, SA>::const_iterator,Allocator>& m,
               const basic_regex<charT, traits>& e,
               regex_constants::match_flag_type flags = regex_constants::match_default);
                 
template <class charT, class traits>
bool regex_match(const charT* str,
               const basic_regex<charT, traits>& e,
               regex_constants::match_flag_type flags = regex_constants::match_default);
                 
template <class ST, class SA, class charT, class traits>
bool regex_match(const basic_string<charT, ST, SA>& s,
               const basic_regex<charT, traits>& e,
               regex_constants::match_flag_type flags = regex_constants::match_default);
                 
// [7.11.3] Function template regex_search
template <class BidirectionalIterator, class Allocator, class charT, class traits>
bool regex_search(BidirectionalIterator first, 
                  BidirectionalIterator last,
                  match_results<BidirectionalIterator, Allocator>& m,
                  const basic_regex<charT, traits>& e,
                  regex_constants::match_flag_type flags = regex_constants::match_default);
                  
template <class BidirectionalIterator, class charT, class traits>
bool regex_search(BidirectionalIterator first, 
                  BidirectionalIterator last,
                  const basic_regex<charT, traits>& e,
                  regex_constants::match_flag_type flags = regex_constants::match_default);
                  
template <class charT, class Allocator, class traits>
bool regex_search(const charT* str,
                  match_results<const charT*, Allocator>& m,
                  const basic_regex<charT, traits>& e,
                  regex_constants::match_flag_type flags = regex_constants::match_default);
                  
template <class charT, class traits>
bool regex_search(const charT* str,
                  const basic_regex<charT, traits>& e,
                  regex_constants::match_flag_type flags = regex_constants::match_default);
                  
template <class ST, class SA, class charT, class traits>
bool regex_search(const basic_string<charT, ST, SA>& s,
                  const basic_regex<charT, traits>& e,
                  regex_constants::match_flag_type flags = regex_constants::match_default);
                  
template <class ST, class SA, class Allocator, class charT, class traits>
bool regex_search(const basic_string<charT, ST, SA>& s,
                  match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
                  const basic_regex<charT, traits>& e,
                  regex_constants::match_flag_type flags = regex_constants::match_default);
                  
// [7.11.4] Function template regex_replace
template <class OutputIterator, class BidirectionalIterator, class traits, class charT>
OutputIterator regex_replace(OutputIterator out,
                           BidirectionalIterator first, 
                           BidirectionalIterator last,
                           const basic_regex<charT, traits>& e,
                           const basic_string<charT>& fmt,
                           regex_constants::match_flag_type flags = regex_constants::match_default);
                             
template <class traits, class charT>
basic_string<charT> regex_replace(const basic_string<charT>& s,
                                       const basic_regex<charT, traits>& e,
                                       const basic_string<charT>& fmt,
                                       regex_constants::match_flag_type flags = regex_constants::match_default);
                                        
// [7.12.1] Class template regex_iterator
template <class BidirectionalIterator, 
         class charT = typename iterator_traits<BidirectionalIterator>::value_type,
         class traits = regex_traits<charT> >
class regex_iterator;

typedef regex_iterator<const char*> cregex_iterator;
typedef regex_iterator<const wchar_t*> wcregex_iterator;
typedef regex_iterator<string::const_iterator> sregex_iterator;
typedef regex_iterator<wstring::const_iterator> wsregex_iterator;

// [7.12.2] Class template regex_token_iterator
template <class BidirectionalIterator,
         class charT = typename iterator_traits<BidirectionalIterator>::value_type,
         class traits = regex_traits<charT> >
class regex_token_iterator;

typedef regex_token_iterator<const char*> cregex_token_iterator;
typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;

} // namespace tr1
} // namespace std

Configuration: Boost.Config should (automatically) define the macro BOOST_HAS_TR1_REGEX if your standard library implements this part of TR1.

Standard Conformity: No known problems.

Complex Number Algorithm Overloads.

#include <boost/tr1/complex.hpp>

or

#include <complex>

The following function templates have additional overloads: arg, norm, conj, polar, imag, and real.

The additional overloads are sufficient to ensure:

  • If the argument has type long double, then the overload behaves as if the argument had been cast to std::complex<long double>.
  • Otherwise, if the argument has type double or is an integer type, then the overload behaves as if the argument had been cast to std::complex<double>.
  • Otherwise, if the argument has type float, then the overload behaves as if the argument had been cast to std::complex<float>.

The function template pow has additional overloads sufficient to ensure, for a call with at least one argument of type std::complex<T>:

  • If either argument has type complex<long double> or type long double, then the overload behaves as if both arguments were cast to std::complex<long double>
  • Otherwise, if either argument has type complex<double>, double, or an integer type, then the overload behaves as if both arguments were cast to std::complex<double>
  • Otherwise, if either argument has type complex<float> or float, then the overload behaves as if both arguments were cast to std::complex<float>

In the following synopsis, Real is a floating point type, Arithmetic is an integer or floating point type, and PROMOTE(X1 ... XN) is the largest floating point type in the list X1 to XN, after any non-floating point types in the list have been replaced by the type double.

template <class Arithmetic>
PROMOTE(Arithmetic) arg(const Arithmetic& t);

template <class Arithmetic>
PROMOTE(Arithmetic) norm(const Arithmetic& t);

template <class Arithmetic>
complex<PROMOTE(Arithmetic)> conj(const Arithmetic& t);

template <class Arithmetic1, class Arithmetic2>
complex<PROMOTE(Arithmetic1,Arithmetic2)> polar(const Arithmetic1& rho, const Arithmetic2& theta = 0);

template <class Arithmetic>
PROMOTE(Arithmetic) imag(const Arithmetic& );

template <class Arithmetic>
PROMOTE(Arithmetic) real(const Arithmetic& t);

template<class Real1, class Real2>
complex<PROMOTE(Real1, Real2)> 
   pow(const complex<Real1>& x, const complex<Real2>& y);
   
template<class Real, class Arithmetic> 
complex<PROMOTE(Real, Arithmetic)> 
   pow (const complex<Real>& x, const Arithmetic& y);

template<class Arithmetic, class Real> 
complex<PROMOTE(Real, Arithmetic)> 
   pow (const Arithmetic& x, const complex<Real>& y);

Configuration: Boost.Config should (automatically) define the macro BOOST_HAS_TR1_COMPLEX_OVERLOADS if your standard library implements the additional overloads for the existing complex arithmetic functions.

Standard Conformity: No known problems.

Complex Number Additional Algorithms.

#include <boost/tr1/complex.hpp>

or

#include <complex>

The algorithms acos, asin, atan, acosh, asinh, atanh and fabs are overloaded for arguments of type std::complex<T>. These algorithms are entirely classical, and behave as specified in the C99 standard section 7.3.5. See the Boost.Math documentation for more information.

namespace std {
namespace tr1 {

template<class T> complex<T> acos(complex<T>& x);
template<class T> complex<T> asin(complex<T>& x);
template<class T> complex<T> atan(complex<T>& x);
template<class T> complex<T> acosh(complex<T>& x);
template<class T> complex<T> asinh(complex<T>& x);
template<class T> complex<T> atanh(complex<T>& x);
template<class T> complex<T> fabs(complex<T>& x);

} // namespace tr1
} // namespace std

Configuration: Boost.Config should (automatically) define the macro BOOST_HAS_TR1_COMPLEX_INVERSE_TRIG if your standard library implements the additional inverse trig functions.

Standard Conformity: No known problems.

Copyright © 2005 John Maddock

PrevUpHomeNext