diff --git a/doc/index.html b/doc/index.html index e645f01..2b5aad8 100644 --- a/doc/index.html +++ b/doc/index.html @@ -1,495 +1,29 @@
- -Table of Contents
+The Boost MPL library documentation is currently undergoing a major overhaul +for the 1.32 release. Please come back in a few days.
-The MPL library is a C++ template metaprogramming framework of compile-time algorithms, sequences and metafunction classes. The two main documentation sources for the library is “the MPL paper”, and the library's reference documentation. If you haven't heard about the MPL before, we suggest you to start with the paper, and then move on to the reference documentation and the information in this document.
- -The latest library sources are available from the main trunk of the Boost CVS. Boost 1.30.0 distribution contains a stable version of the library as per March 12, 2003.
-The examples used through this tutorial use fully qualified names, e.g. std::vector instead of plain vector. Any unqualified name refers to a local entity defined in the example itself. The names from boost::mpl namespace are referred to using mpl namespace alias (e.g. mpl::apply instead of boost::mpl::apply), as if the following namespace alias definition were in effect:
- --namespace mpl = boost::mpl; -- -
Note that the library offers a special header, boost/mpl/alias.hpp, including which gives you a rough equivalent of the above. Alternatively, you can always spell the namespace alias definition manually in each translation unit as needed (if you choose to use the shorter namespace notation at all).
-In MPL, the metaprogramming equivalent of a function is a class template containing a nested typedef member aptly named “type”:
- --// on the face of it, not very useful -template< typename T > -struct identity -{ - typedef T type; -}; - -// perhaps more useful -template< typename T > -struct result_type -{ - typedef typename T::result_type type; -}; -- -
“Invoking” a metafunction is as simple as instantiating the class template with particular template parameters (metafunction “arguments”) and accessing the result through the nested type member:
- --typedef identity<int>::type t1; // t1 == int -typedef result_type< std::unary_function<int,bool> >::type t2; // t2 == bool --
The most interesting template metaprograms often contain a lot of decision-making code. Some of conditional decisions/behavior can be handled directly by (partial) class template specialization or function overloading [Vel95a], [Ale00], but in general there is a need for a standalone library primitive that would allow one to choose between two types basing on a compile-time expression. In boost::mpl such primitive is called if_:
- --template< typename T > -struct heap_holder -{ - // ... - private: - boost::scoped_ptr<T> m_object; -}; - -template< typename T > -struct stack_holder -{ - // ... - private: - T m_object; -}; - -template< typename T > -struct can_be_on_stack - : mpl::bool_c< (sizeof(T) <= sizeof(double)) > -{ -}; - -// use 'if_' to choose where to store 'T' member -template< typename T > -struct lightweight - : private mpl::if_< - can_be_on_stack<T> - , stack_holder<T> - , heap_holder<T> - >::type -{ - // ... -}; -- -
Note that the first template parameter of the if_ template is a type that should be a model of Integral Constant concept. The library also provides a less generic but sometimes more convenient form that accepts a condition in form of non-type bool template parameter:
- --template< typename T > -struct lightweight - : private mpl::if_c< - (sizeof(T) <= sizeof(double)) - , stack_holder<T> - , heap_holder<T> - >::type -{ - // ... -}; --
In run-time C++, it is guaranteed that when we reach an if statement, only one branch will be executed. Executing the branch for which the result is not required would be unnecessary and inefficient. More importantly, frequently the non-required branch is invalid, and executing it would cause an error. For instance, the following code would be badly broken if both branches of the statement were evaluated:
- --void fun(giraffe* g) -{ - if (g) - cout << g->name(); - else - cout << "no giraffe"; -} -- -
In compile-time world, things are different. Which parameters to if_ template are instantiated is determined by the form of each template parameter and the corresponding language rules ([ISO98], section 14.7.1), not by the value of the compile-time expression being switched on. That means that if, in attempt to process a particular if_ construct, the compiler determines that one of its “branch” template parameters is ill-formed, it will issue a diagnostics even if the value of compile-time expression would lead to “choosing” the other, valid parameter type.
- -To clarify what we just said, here is a broken first attempt at writing a pointed_type metafunction, that when instantiated for a T that is either a plain pointer or a smart pointer, “returns” the pointed type:
- --template< typename T > -struct pointed_type -{ - typedef typename mpl::if_< - boost::is_pointer<T> - , typename boost::remove_pointer<T>::type - , typename T::element_type // #1 - >::type type; -}; - -typedef pointed_type< std::auto_ptr<int> >::type int_ptr; // ok -typedef pointed_type<char*>::type char_ptr; // error in line #1! -- -
If we try to compile the above, we will get something like this:
- --Error: name followed by "::" must be a class or namespace name -- -
because the expression typename T::element_type is not valid in case of T == char*.
- -Here's what we need to do to make pointed_type work for plain pointers: 1 instead of instantiating our two potential results before passing them to if_, we need to write metafunctions that can be used to instantiate the results; then we can use if_ to choose a metafunction, and only then should we use that function to get the result.
- -boost::remove_pointer already is a metafunction. We just need to write an auxiliary function to return the element_type of a pointer type:
- --namespace aux { -template< typename T > -struct element_type -{ - typedef typename T::element_type type; -}; -} -- -
Now we can select the metafunction to call based on the result of boost::is_pointer, and then apply it to form the result:
- --template< typename T > -struct pointed_type -{ - private: - // pick a metafunction - typedef typename mpl::if_< - boost::is_pointer<T> - , boost::remove_pointer<T> - , aux::element_type<T> - >::type func_; // #1 - - public: - // apply the metafunction - typedef typename func_::type type; -}; -- -
The key knowledge that makes the above viable is that in line #1 the compiler is guaranteed not to instantiate boost::remove_pointer<T> and aux::element_type<T> templates, - even although they are passed as actual arguments to the if_.
- -The described technique is so common in template metaprograms, that it makes sense to facilitate the selection of the nested type member by introducing a high level equivalent to if_ that will do func_::type operation as a part of its invocation. The MPL provides such a template - it's called apply_if. Using it, we can re-write the above code as simply as:
- --[ -template< typename T > -struct pointed_type -{ - typedef typename mpl::apply_if< - boost::is_pointer<T> - , boost::remove_pointer<T> - , aux::element_type<T> - >::type type; -}; --
Besides solving the “making the code compile” problem, the apply_if technique we've just learned can be also used to improve metaprogram efficiency.
- -Suppose we want to define a high-level wrapper around boost::remove_pointer traits template, which will strip the pointer qualification conditionally. We will call it remove_pointer_if:
- --template< - typename Condition - , typename T - > -struct remove_pointer_if -{ - typedef typename mpl::if_< - Condition - , typename boost::remove_pointer<T>::type - , T - >::type type; -}; -- -
The above works the first time, but it's not the most optimal implementation. Similar to our previous examples, boost::remove_pointer<T> gets instantiated even if its result is never used. In the metaprogramming world compilation time is an important resource [Abr01], and it is wasted by unnecessary template instantiations.
- -Let's see what we need to substitute if_ by apply_if here. We already have one metafunction to pass to apply_if - boost::remove_pointer<T>, but we need a second one, - let's call it f, - such as f<T>::type == T. We could write this one ourselves, but fortunately MPL already provides us with a template that matches this exact definition - it's called identity. Applying this knowledge, we get:
- --template< - typename Condition - , typename T - > -struct remove_pointer_if -{ - typedef typename mpl::apply_if< - Condition - , boost::remove_pointer<T> - , mpl::identity<T> - >::type type; -}; --
The library provides you with a fine-grained header structure with one header per public component (class/function template), with the header named after the component; for example, boost::mpl::apply<> template is defined in the header boost/mpl/apply.hpp. This scheme both ensures that you don't pay for what you don't use in terms of compilation time/header dependencies, and frees you from memorizing/looking up header/component correspondence. Several composite headers for the entities that are likely to be used together (e.g. logical operations - logical_or, logical_and, etc.) are also provided. It allows one to avoid the burden of spelling many #include directives in programs that make an intensive use of the library facilities. 2
-Besides boost/config.hpp header, the MPL heavily depends on two other Boost libraries - the Boost Preprocessor library [PRE], and the Type Traits library [TTL]. These dependencies are essential and cannot be eliminated. In addition to those, the boost/mpl/assert.hpp header depends on Boost Static Assert library [SAL]. The library tests and examples may depend on some additional Boost libraries, e.g. Boost Bind [BBL]; you don't have to have those unless you are interested in actually compiling the tests/examples (probably you are, though).
-Below is the list of compilers the library has been tested with:
- -An incomplete matrix of recent test compilation results is available from here - http://www.mywikinet.com/mpl/log.html.
-Following is a list of people who in one or another way contributed to the library development. The list is work in progress!
- -David Abrahams, Emily Winch, Eric Friedman, Vesa Karvonen, Peter Dimov, Mat Marcus, Fernando Cacciola, Paul Mensonides, David B. Held, John Bandela, Arnaldur Gylfason, Hamish Mackenzie.
- -Copyright on this document. Copyright © 2002 Aleksey Gurtovoy, David Abrahams and Emily Winch.
-[Abr01] Effects of Metaprogramming Style on Compilation Time, 2001
-[Ale00] On Conversions between Types and Values, C/C++ Users Journal, October 2000
-[BBL] Boost Bind library, http://www.boost.org/libs/bind/bind.html
-[PRE] Boost Preprocessor Metaprogramming library, http://www.boost.org/libs/preprocessor/doc/
-[TTL] Boost Type Traits library, http://www.boost.org/libs/type_traits/
-[SAL] Boost Static Assert library, http://www.boost.org/libs/static_assert/static_assert.htm
-[Vel95a] Using C++ template metaprograms, C++ Report, SIGS Publications Inc., ISSN 1040-6042, No. 4, pp. 36-43, May 1995
-1 It would be easy to implement pointed_type using partial specialization to distinguish the case where T is a pointer. if_ is used here to avoid creating a complicated example.
-
-An Associative Sequence is a Sequence which allows efficient retrieval of elements based on keys. For some of associative sequences such as set
it is guaranteed that no two elements have the same key. Others, such as multiset
, allow multiple elements with the same key.
-
-
-Sequence -
-
-In addition to Sequence's expressions the following expressions are valid. -
-
Expression | Expression type |
---|---|
has_key<s,k>::type | A model of boolean Integral Constant |
count<s,k>::type | A model of Integral Constant |
order<s,k>::type | A model of Integral Constant or void_ |
at<s,k>::type | A type |
at<s,k,default>::type | A type |
-
-
Expression | Complexity | Precondition | Semantics | Postcondition |
---|---|---|---|---|
has_key<s,k>::type | Amortized constant time | |||
count<s,k>::type | Amortized constant time | |||
order<s,k>::type | Amortized constant time | |||
at<s,k>::type | Amortized constant time |
-
-
-For any associative sequence s
the following invariants always hold:
-
-
-
set
-map
-set_c
--
-
-Sequences, Forward Sequence, Extensible Associative Sequence, -
-A Bidirectional Iterator is a Forward Iterator that provides a way to obtain the previous element in a sequence. -
-
-
-
i
is decrementable if there is a "previous" iterator, that is, if i::prior
expression is well-defined; iterators pointing to the first element of the sequence are not decrementable.
--
-Bidirectional Iterator both defines a new expression and refines the one described in Forward Iterator. -
-
Expression | Expression type |
---|---|
typename i::next | A model of Bidirectional Iterator |
typename i::prior | A model of Bidirectional Iterator |
-
-Semantics of an expression is defined only where it is not defined in Forward Iterator. -
-
Expression | Complexity | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typename i::prior | Amortized constant time | i is decrementable | i::prior is an iterator pointing to the previous element of the sequence | i::prior is dereferencable and incrementable |
-
-For any bidirectional iterators i
and j
the following invariants always hold:
-
-
i
is incrementable, then i::next::prior
is a null operation; similarly, if i
is decrementable, i::prior::next
is a null operation.
--
-Bidirectional Sequence, Forward Iterator, Random Access Iterator -
-A Bidirectional Sequence is a Forward Sequence, which provides iterators that satisfy the Bidirectional Iterator requirements. -
-
-
-Bidirectional Sequence does not define any new expressions beyond those defined in Forward Sequence. However, it refines the expression requirements. -
-
Expression | Expression type |
---|---|
typename begin<s>::type | A model of Bidirectional Iterator |
typename end<s>::type | A model of Bidirectional Iterator |
-
-
--
-Forward Sequence, Random Access Sequence, Bidirectional Iterator -
-
-
-
-An Extensible Associative Sequence is an Associative Sequence that supports insertion and removal of elements. In contrast to Extensible Sequence, Extensible Associative Sequence does not provide a mechanism for inserting an element at a specific position. -
-Refinement of -
-
-
Expression | Expression type |
---|---|
typename clear<s>::type | A model of concept of s |
typename insert<s,t>::type | A model of concept of s |
typename remove<s,k>::type | A model of concept of s |
-
-TODO. -
-
-For any associative sequence s
the following invariants always hold:
-
-
-
set
-map
-set_c
--
-
-Sequences, Forward Sequence, Associative Sequence -
-An Extensible Sequence is either a Forward Sequence, a Bidirectional Sequence or a Random Access Sequence that supports insertion and removal operations. -
-
-Forward Sequence, Bidirectional Sequence or Random Access Sequence -
-
-
Expression | Expression type |
---|---|
typename clear<s>::type | A model of concept of s |
typename insert<s,pos,t>::type | A model of concept of s |
typename erase<s,pos>::type | A model of concept of s |
typename erase<s,first,last>::type | A model of concept of s |
-
-See the description of clear, insert, and erase algorithms. -
-
-
--
-Sequences, clear
, insert
, erase
-
-A Forward Iterator is an Input Iterator that guarantees a linear traversal over the sequence. -
-
-
-
-Forward Iterator does not define any new expressions beyond those defined in Input Iterator. However, some of the restrictions described in Input Iterator are relaxed. -
-
Expression | Expression type |
---|---|
typename i::next | A model of Forward Iterator |
-
-For any forward iterators i and j the following invariants always hold: -
i
and j
are dereferenceable and i
is identical to j
, then i::next
is identical to j::next
.
--
-Forward Sequence, Input Iterator, Bidirectional Iterator -
-A Forward Sequence is a Sequence which guarantees that its elements are arranged in a definite order, and that the ordering will not change spontaneously [1]. Iterators into a forward sequence satisfy the Forward Iterator requirements. -
-
-Sequence -
-
-Forward Sequence does not define any new expressions beyond those defined in Sequence. However, it refines the expression requirements. -
-
Expression | Expression type |
---|---|
typename begin<s>::type | A model of Forward Iterator |
typename end<s>::type | A model of Forward Iterator |
-
-For any forward sequence s
the following invariants always hold:
-
s
will access its elements in the same order.
--
-
--
-[1] Both between compilation sessions and from iteration to iteration.
-
-
-Sequence, Bidirectional Sequence, Forward Iterator -
-An Input Iterator is a Trivial Iterator that provides a way to obtain the next iterator in a sequence. -
-
-
-
i
is incrementable if there is a "next" iterator, that is, if i::next
expression is well-defined; past-the-end iterators are not incrementable;
-j
is reachable from an input iterator i
if, after recursive application of next
operation to i
a finite number of times, i
is identical to j
;
-[i,j)
refers to a range of iterators beginning with i
and up to but not including j
;
-[i,j)
is a valid range if both i
and j
are valid iterators, and j
is reachable from i
.
--
-In addition to the expressions defined in Trivial Iterator, the following expressions must be valid. -
-
Expression | Expression type |
---|---|
typename i::next | A model of Input Iterator |
-
-
Expression | Complexity | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typename i::next | Amortized constant time | i is incrementable | i::next is the next iterator in a sequence | i::next is dereferenceable or past-the-end |
-
-Sequence, Trivial Iterator, Forward Iterator -
-An Integral Constant is a class representing a value of a built-in integral type (bool
, int
, long
, etc.) in compile-time programs. An integral constant directly supports the increment/decrement operations within the range of the built-in integral type it wraps. Other arithmetic operations are supported through the external metafunctions.
-
-
-
Expression | Return type |
---|---|
typename n::value_type | An integral type |
typename n::type | A model of Integral Constant |
n::value | A compile-time integral constant of n::value_type |
typename n::next | A model of Integral Constant |
typename n::prior | A model of Integral Constant |
-
-
Expression | Complexity | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typename n::value_type | Amortized constant time | n::value_type is identical to typeof(n::value) | ||
typename n::type | Amortized constant time | Self-reference. | is_same<n::type,n>::value == true | |
n::value | Amortized constant time | Value of n . | ||
typename n::next | Amortized constant time | n::value_type supports an increment operation; n::value is incrementable | Increment operation | n::next::value == n::value + 1 |
typename n::prior | Amortized constant time | n::value_type supports an decrement operation; n::value is decrementable | Decrement operation | n::prior::value == n::value - 1 |
-
-
integral_c
-int_
-bool_
--
-next
, prior
-
-
-
-
-
-
-A metafunction is a class or a class template that represents a function invocable at compile-time. A non-nullary metafunction is invoked by instantiating the class template with particular template parameters
-(metafunction arguments); the result of the metafunction application is accessible through the instantiation's nested type
typedef. All metafunction's arguments must be types (i.e. only type template parameters are allowed). A metafunction can have a variable number of parameters. A nullary metafunction is represented as a class with a nested
-type
typename member.
-
-
-
Expression | Expression type |
---|---|
typename f::type | A type |
typename f<a1,..,an>::type | A type |
-
-
Expression | Complexity | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typename f::type | unspecified | f is a nullary metafunction; f::type is a type-name | f::type is the result of the metafunction invocation | |
typename f<a1,..,an>::type | unspecified | f is an n -ary metafunction; a1,..,an are types; f<a1,..,an>::type is a type-name | f<a1,..,an>::type is the result of the metafunction invocation with the actual arguments a1,..,an |
-
-
-
-// nullary metafunction -struct always_true { typedef true_ type; }; ---// unary metafunction -template< typename T > struct sizeof_ -{ - typedef int_< sizeof(T) > type; -}; -
-// binary metafunction -template< typename T1, typename T2 > -struct is_same -{ - typedef false_ type; -}; -
-template< typename T > -struct is_same<T,T> -{ - typedef true_ type; -}; -
-// invocations -typedef always_true::type t1; -typedef sizeof_<int>::type t2; -typedef is_same<int,char>::type t3; -
-// results checks -BOOST_STATIC_ASSERT(t1::value); -BOOST_STATIC_ASSERT(t2::value == sizeof(int)); -BOOST_STATIC_ASSERT(!t3::value); -
-
-
plus
-not_
-size
-max_element
--
-Metafunctions, Metafunction Class -
-A metafunction class is a certain form of metafunction representation that enables higher-order metaprogramming. In particular, a non-nullary metafunction class is a type with a nested class template member apply
. A nullary metafunction class has the form of a nullary metafunction. A metafunction class invocation is defined as invocation of its nested apply
metafunction.
-
-
-
Expression | Expression type |
---|---|
typename f::type | A type |
typename f::template apply<a1,..,an>::type | A type |
-
-
Expression | Complexity | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typename f::type | unspecified | f is a nullary metafunction class; f::type is a type-name | f::type is the result of the metafunction class invocation | |
typename f::template apply<a1,..,an>::type | unspecified | f is an n -ary metafunction class; apply is a metafunction | typename f::template apply<a1,..,an>::type is the result of the metafunction class invocation with the actual arguments a1,..,an |
-
-
-
-// nullary metafunction class -struct always_true { typedef true_ type; }; ---template< long N > struct le -{ - template< typename M > struct apply - { - typedef bool_< (M::value < N) > type; - }; -}; -
-// unary metafunction class -typedef le<5> less_than_5; -
-// binary metafunction class -struct less_than -{ - template< typename N1, typename N2 > struct apply - { - typedef bool_< (N1::value < N2::value) > type; - }; -}; -
-// invocations -typedef always_true::type t1; -typedef less_than_5::apply< int_<7> >::type t2; -typedef less_than::apply< int_<5>,int_<7> >::type t3; -
-// results checks -BOOST_STATIC_ASSERT(t1::value); -BOOST_STATIC_ASSERT(!t2::value); -BOOST_STATIC_ASSERT(t3::value); -
-
-Metafunctions, Metafunction -
-
-
-
-
-
-
-A Random Access Iterator is a Bidirectional Iterator that provides constant-time methods for moving forward and backward on a sequence in arbitrary-sized steps. -
-
-
-
-Random Access Iterator defines two new expressions and refines the ones described in Bidirectional Iterator. -
-
Expression | Expression type |
---|---|
typename i::next | A model of Random Access Iterator |
typename i::prior | A model of Random Access Iterator |
typename i::template advance<n>::type | A model of Random Access Iterator |
typename i::template distance<j>::type | A model of Integral Constant |
-
-Semantics of an expression is defined only where it is not defined in Bidirectional Iterator. -
-
Expression | Complexity | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typename i::template advance<n>::type | Amortized constant time | Including i itself, there must be n::value dereferenceable or past-the-end iterators following or preceding i , depending on whether n is positive or negative. | If n::value > 0 , equivalent to executing i::next n::value times; if n::value < 0 , equivalent to executing i::prior n::value times; if n::value == 0 , this is a null operation [1]. | The resulting iterator is dereferenceable or past-the-end. |
typename i::template distance<j>::type | Amortized constant time | Either i is reachable from j or j is reachable from i , or both. | Returns an integral constant n such that i::template advance<n>::type is identical to j . |
-
-For any random access iterators i
and j
the following invariants always hold:
-
-
i::advance<n>::type
is well-defined, then i::advance<n>::type::advance< negate<n>::type >::type
is a null operation.
--
-Random Access Sequence, Bidirectional Iterator -
-A Random Access Sequence is a Bidirectional Sequence which provides iterators that satisfy the Random Access Iterator requirements. A random access sequence provides amortized constant time access to arbitrary elements. -
-
-
-Random Access Sequence does not define any new expressions beyond those defined in Bidirectional Sequence. However, it refines the expression requirements. -
-
Expression | Expression type |
---|---|
typename begin<s>::type | A model of Random Access Iterator |
typename end<s>::type | A model of Random Access Iterator |
-
-
--
-Bidirectional Sequence, Random Access Iterator -
-A Rational Constant is a class representing the ration of two values of a built-in integral type (bool
, int
, long
, etc.) in compile-time programs. A rational constant directly supports access to the numerator
-and denominator. Other arithmetic operations are supported through the external metafunctions. A rational constant is always stored in simplified form.
-
-
-
Expression | Return type |
---|---|
typename n::integer_type | An integral type |
typename n::type | A model of Rational Constant |
typename n::numerator | A model of Integral Constant representing the numerator |
typename n::denominator | A model of Integral Constant representing the denominator |
n::value() | A run-time floating point approximation of n::type |
-
-
Expression | Complexity | Precondition | Semantics | Postcondition |
---|
-
-
rational_c
--
-Integral Constant, rational_c
-
-
-#define BOOST_MPL_AUX_LAMBDA_SUPPORT(arity, fun, params) \ - unspecified token sequence \ -/**/ --
-
-Broken compiler workaround macro, enables metafunction fun
for the use in lambda expressions on compilers that don't support partial template specialization or/and template template parameters. Expands to nothing on conforming compilers.
-
-
-
-#include "boost/mpl/aux_/lambda_support.hpp" --
-
Parameter | Description |
---|---|
arity | The metafunction's arity, i.e. the number of its template parameters, including the defaults. |
fun | The metafunction's name. |
params | PP-tuple of the metafunction's parameter names, in their original order. |
-
-
-template< typename T, typename U = int > struct f -{ - typedef T type[sizeof(U)]; --- BOOST_MPL_AUX_LAMBDA_SUPPORT(2,f,(T,U)) -}; -
-typedef lambda< f<char,_1> >::type f_; // use f in a lambda expression -typedef apply1<f_,long>::type res; -BOOST_MPL_ASSERT_IS_SAME(res, char[sizeof(long)]); -
-
-Macros -
-
-template< - typename Iterator - , typename N - > -struct advance -{ - typedef unspecified type; -}; --
-
-Returns an new iterator i
such as distance< Iterator,i >::type::value == N::value
.
-
-
-
-#include "boost/mpl/advance.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Iterator | A model of Input Iterator | |
N | A model of Integral Constant |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef advance<Iterator,N>::type i; | A model of Input Iterator | Iterator and every iterator between Iterator and i (inclusive) is nonsingular; N::value must be nonnegative if Iterator is a model of Input Iterator or Forward Iterator | Equivalent to typedef Iterator::next i1; typedef i1::next i2; .. typedef in-1::next i; if N::value > 0 , and typedef Iterator::prior i1; typedef i1::prior i2; .. typedef in-1::prior i; otherwise; if N::value == 0 , the algorithm has no effect. | distance< Iterator,i >::type::value == N::value |
-
-Amortized constant time if Iterator
is a model of Random Access Iterator, otherwise linear time.
-
-
-
-typedef vector_c<int,0,1,2,3,4,5,6,7,8,9> numbers; -typedef begin<numbers>::type first; -typedef end<numbers>::type last; -typedef advance_c<first,10>::type iter1; -typedef advance_c<last,-10>::type iter2; -BOOST_MPL_ASSERT_IS_SAME(iter1, last); -BOOST_MPL_ASSERT_IS_SAME(iter2, first); --
-
-Iterators, Sequence, distance
, begin
, end
-
-
-template< - typename F1 - , typename F2 - , typename F3 = true_ - ... - , typename Fn = true_ - > -struct and_ -{ - typedef unspecified type; -}; --
-
-Returns the result of short-circuit logical and (&&
) operation on its arguments.
-
-
-
-#include "boost/mpl/and.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
F1, F2, .., Fn | A model of nullary Metafunction |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
and_<f1,f2,..,fn> | A model of bool Integral Constant | false_ if either of f1::type::value, f2::type::value, .., fn::type::value expressions evaluates to false , and true_ otherwise; guarantees left-to-right evaluation; moreover, the operands subsequent to the first fi metafunction that evaluates to false are not evaluated. |
-
-
-// will generate compile-time error if invoked with T == any fundamental type -template< typename T > struct fail -{ - typedef typename T::nonexistent type; -}; ---BOOST_STATIC_ASSERT((and_< true_,false_ >::value == false)); -BOOST_STATIC_ASSERT((and_< false_,fail<int> >::value == false)); // OK, fail<int> is never invoked -BOOST_STATIC_ASSERT((and_< true_,false_,fail<int> >::value == false)); // OK too -
-
-Metafunctions, or_
, not_
-
-
-template< - typename Sequence - , typename N - > -struct at -{ - typedef unspecified type; -}; --
-
-Returns a type identical to the N
-th element from the beginning of the sequence.
-
-
-
-#include "boost/mpl/at.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Sequence | A model of Forward Sequence | A sequence to be examined. |
N | A model of Integral Constant | The offset from the beginning of the sequence that specifies the element to be retrieved. |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef at<Sequence,N>::type t; | A type | 0 <= N::value < size<Sequence>::type::value | Equivalent to typedef advance< begin<Sequence>::type,N >::type::type t; |
-
-Depends on the implementation of the particular sequence it is applied to. Linear in the worst case, or amortized constant time. -
-
-
-typedef range_c<long,10,50> range; -BOOST_STATIC_ASSERT(at< range, int_<0> >::type::value == 10); -BOOST_STATIC_ASSERT(at< range, int_<10> >::type::value == 20); -BOOST_STATIC_ASSERT(at< range, int_<40> >::type::value == 50); --
-
-Forward Sequence, at_c
, front
, back
-
-
-template< - typename Sequence - , long n - > -struct at_c -{ - typedef unspecified type; -}; --
-
-Returns a type identical to the n
-th element from the beginning of the sequence. at_c<Sequence,n>::type
is a shorcut notation for at< Sequence, integral_c<long,n> >::type
.
-
-
-
-#include "boost/mpl/at.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Sequence | A model of Forward Sequence | A sequence being examined. |
n | An compile-time integral constant | An offset from the beginning of the sequence that specifies the element to be retrieved. |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef at_c<Sequence,n>::type t; | A type | 0 <= n < size<Sequence>::type::value | Equivalent to typedef at< Sequence, integral_c<long,n> >::type t; |
-
-Depends on the implementation of the particular sequence it is applied to. Linear in the worst case, or amortized constant time. -
-
-
-typedef range_c<long,10,50> range; -BOOST_STATIC_ASSERT(at_c<range,0>::type::value == 10); -BOOST_STATIC_ASSERT(at_c<range,10>::type::value == 20); -BOOST_STATIC_ASSERT(at_c<range,40>::type::value == 50); --
-
-Forward Sequence, at
, front
, back
-
-
-template< - typename Sequence - > -struct back -{ - typedef unspecified type; -}; --
-
-Returns a type identical to the last element in the sequence, that is, the element in a position that preceeds the position of past-the-end iterator. -
-
-
-#include "boost/mpl/back.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Sequence | A model of Forward Sequence | A sequence to be examined. |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef back<Sequence>::type t; | A type | empty<Sequence>::type::value == false | Equivalent to typedef prior< end<Sequence>::type >::type::type t; |
-
-Amortized constant time [1]. -
-
-
-typedef range_c<int,0,1> range1; -typedef range_c<int,0,10> range2; -typedef range_c<int,-10,0> range3; ---BOOST_STATIC_ASSERT(back<range1>::type::value == 0); -BOOST_STATIC_ASSERT(back<range2>::type::value == 9); -BOOST_STATIC_ASSERT(back<range3>::type::value == -1); -
-
-[1] The algorithm is provided only if the sequence can meet the stated complexity requirements.
-
-
-Forward Sequence, front
, at
, end
, push_back
-
-
-template< - typename Sequence - > -struct begin -{ - typedef unspecified type; -}; --
-
-Returns an iterator that points to the first element of the sequence. -
-
-
-#include "boost/mpl/begin_end.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Sequence | A model of Sequence |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef begin<Sequence>::type first; | A model of Input Iterator | first is an iterator pointing to the first element of the Sequence ; equivalent to Sequence::begin unless the algorithm has been specialized for the particular type of sequence. | first is either dereferenceable or past-the-end; it is past-the-end if and only if size<Sequence>::type::value == 0 . |
-
-Amortized constant time. -
-
-
-typedef vector<unsigned char,unsigned short,unsigned int, unsigned long> unsigned_types; -typedef begin<unsigned_types>::type iter; -BOOST_STATIC_ASSERT((boost::is_same<iter::type,unsigned char>::value)); --
-
-Iterators, Sequence, end
, size
, empty
-
-
-template< - typename Sequence - > -struct clear -{ - typedef unspecified type; -}; --
-
-Returns an empty sequence that preserves all the functional and performance characteristics of the original Sequence
, except its size and identity.
-
-
-
-#include "boost/mpl/clear.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Sequence | A model of Extensible Sequence |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef clear<Sequence>::type s; | A model of Extensible Sequence | Equivalent to typedef erase<Sequence, begin<Sequence>::type, end<Sequence>::type>::type s; | empty<s>::type::value == true |
-
-Amortized constant time [1]. -
-
-
-typedef list_c<int,1,3,5,7,9,11> odds; -typedef clear<odds>::type nothing; -BOOST_STATIC_ASSERT(empty<nothing>::type::value); --
-
-[1] The algorithm is provided only if the sequence can meet the stated complexity requirements.
-
-
-Extensible Sequence, erase
, empty
, begin
, end
-
-
-template< - typename Sequence - , typename T - > -struct contains -{ - typedef unspecified type; -}; --
-
-Returns true_
if one or more elements in Sequence
are identical to T
, and false_
otherwise.
-
-
-
-#include "boost/mpl/contains.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Sequence | A model of Forward Sequence | A sequence to be examined. |
T | A type | The type to search for. |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef contains<Sequence,T>::type c; | A model of bool Integral Constant | Equivalent to typedef not_< is_same< find<Sequence,T>::type, end<Sequence>::type > >::type c ; |
-
-Linear. At most size<Sequence>::value
comparisons for identity.
-
-
-
-typedef vector<char,int,unsigned,long,unsigned long> types; -typedef contains<types,bool>::type result; -BOOST_STATIC_ASSERT(!result::value); --
-
-Algorithms, find
, find_if
, count
, count_if
-
-
-template< - typename Sequence - , typename State - , typename BinaryOp - > -struct copy -{ - typedef unspecified type; -}; --
-
-copy
is, in fact, just another name for fold
. It was introduced for symmetry with copy_if
[1], and because it's a nice name for one of the typical fold
applications, that is, copying the content of one sequence into another - see the example below.
-
-
-
-#include "boost/mpl/copy.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Sequence | A model of Sequence | A sequence to iterate. |
State | A type | The initial state for the first BinaryOp application. |
BinaryOp | A model of [Lambda Function] | The operation to be executed on forward traversal. |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef copy<Sequence,T,Op>::type s; | A type | Equivalent to typedef fold< Sequence,T,Op >::type s; . |
-
-Linear. Exactly size<Sequence>::type::value
applications of BinaryOp
.
-
-
-
-typedef vector_c<int,0,1,2,3,4,5,6,7,8,9> numbers; -typedef copy< - range_c<int,10,20> - , numbers - , push_back<_,_> - >::type result; ---BOOST_STATIC_ASSERT(size<result>::value == 20); -BOOST_STATIC_ASSERT((equal< result,range_c<int,0,20> >::type::value)); -
-
-[1] In case if you wonder why copy_if
, in its turn, wasn't just called fold_if
, - something that would allow to eliminate the family of copy
algorithms completely - these two have quite different semantics.
-
-
-Algorithms, copy_if
, copy_backward
, copy_backward_if
, fold
, fold_backward
-
-
-template< - typename Sequence - , typename State - , typename BinaryOp - > -struct copy_backward -{ - typedef unspecified type; -}; --
-
-copy_backward
is, in fact, just another name for fold_backward
. It was introduced for symmetry with copy_backward_if
[1], and because it's a nice name for one of the typical fold_backward
applications, that is, copying the content of one sequence into another - see the example below.
-
-
-
-#include "boost/mpl/copy_backward.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Sequence | A model of Sequence | A sequence to iterate. |
State | A type | The initial state for the first BinaryOp application. |
BinaryOp | A model of [Lambda Function] | The operation to be executed on backward traversal. |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef copy_backward<Sequence,T,Op>::type s; | A type | Equivalent to typedef fold_backward< Sequence,T,Op >::type s; . |
-
-Linear. Exactly size<Sequence>::type::value
applications of BinaryOp
.
-
-
-
-typedef list_c<int,10,11,12,13,14,15,16,17,18,19>::type numbers; -typedef copy_backward< - range_c<int,0,10> - , push_front<_,_> - , numbers - >::type result; ---BOOST_STATIC_ASSERT(size<result>::value == 20); -BOOST_STATIC_ASSERT((equal< result,range_c<int,0,20> >::type::value)); -
-
-[1] In case if you wonder why copy_backward_if
, in its turn, wasn't just called fold_backward_if
, - something that would allow to eliminate the family of copy_backward
algorithms completely - these two have quite different semantics.
-
-
-Algorithms, copy_backward_if
, copy
, copy_if
, fold
, fold_backward
-
-
-template< - typename Sequence - , typename State - , typename BinaryOp - , typename Pred - > -struct copy_backward_if -{ - typedef unspecified type; -}; --
-
-Returns the result of the successive application of BinaryOp
to the result of the previous BinaryOp
invocation (State
if it's the first call) and every element in the range [begin<Sequence>::type,end<Sequence>::type)
that satisfies the predicate Pred
, in the reverse order. A typical application for copy_backward_if
is to conditionally copy the content of one sequence into another - see the example below.
-
-
-
-#include "boost/mpl/copy_backward_if.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Sequence | A model of Sequence | A sequence to iterate. |
State | A type | The initial state for the first BinaryOp application. |
BinaryOp | A model of [Lambda Function] | The operation to be executed on backward traversal. |
Pred | An unary Predicate [Lambda Expression] | The copying condition. |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef copy_backward_if<Sequence,T,Op,Pred>::type s; | A type | Equivalent to typedef lambda<Op>::type op; typedef lambda<Pred>::type pred; typedef fold_backward< Sequence,T,if_< apply<pred,_2>, apply<op,_1,_2>, _1 > >::type s; . |
-
-Linear. Exactly size<Sequence>::type::value
applications of Pred
, and at most size<Sequence>::type::value
applications of BinaryOp
.
-
-
-
-typedef list_c<int,0,1,2,3,4,5,6,7,8,9>::type numbers; -typedef list_c<int,0,1,2,3,4>::type answer; -typedef copy_backward_if< - numbers - , list_c<int> - , push_front<_1,_2> - , less<_1,int_<5> > - >::type result; ---BOOST_STATIC_ASSERT(size<result>::value == 5); -BOOST_STATIC_ASSERT((equal<result,answer>::type::value)); -
-
-Algorithms, copy_backward
, copy_if
, copy
, fold
, fold_backward
-
-
-template< - typename Sequence - , typename State - , typename BinaryOp - , typename Pred - > -struct copy_if -{ - typedef unspecified type; -}; --
-
-Returns the result of the successive application of BinaryOp
to the result of the previous BinaryOp
invocation (State
if it's the first call) and every element in the range [begin<Sequence>::type,end<Sequence>::type)
that satisfies the predicate Pred
, in the linear order. A typical application for copy_if
is to conditionally copy the content of one sequence into another - see the example below.
-
-
-
-#include "boost/mpl/copy_if.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Sequence | A model of Sequence | A sequence to iterate. |
State | A type | The initial state for the first BinaryOp application. |
BinaryOp | A model of [Lambda Function] | The operation to be executed on forward traversal. |
Pred | An unary Predicate [Lambda Expression] | The copying condition. |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef copy_if<Sequence,T,Op,Pred>::type s; | A type | Equivalent to typedef lambda<Op>::type op; typedef lambda<Pred>::type pred; typedef fold< Sequence,T,if_< apply<pred,_2>, apply<op,_1,_2>, _1 > >::type s; . |
-
-Linear. Exactly size<Sequence>::type::value
applications of Pred
, and at most size<Sequence>::type::value
applications of BinaryOp
.
-
-
-
-typedef list_c<int,0,1,2,3,4,5,6,7,8,9>::type numbers; -typedef list_c<int,0,1,2,3,4>::type answer; -typedef copy_if< - numbers - , vector_c<int> - , push_back<_1,_2> - , less<_1,int_<5> > - >::type result; ---BOOST_STATIC_ASSERT(size<result>::value == 5); -BOOST_STATIC_ASSERT((equal<result,answer>::type::value)); -
-
-Algorithms, copy
, copy_backward_if
, copy_backward
, fold
, iter_fold
-
-
-template< - typename Sequence - , typename T - > -struct count -{ - typedef unspecified type; -}; --
-
-Returns the number of elements in a Sequence
that are identical to T
.
-
-
-
-#include "boost/mpl/count.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Sequence | A model of Forward Sequence | A sequence to be examined. |
T | A type | The type to be searched for. |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef count<Sequence,T>::type n; | A model of Integral Constant | Equivalent to typedef count_if< Sequence,is_same<_,T> >::type n; |
-
-
-Linear. Exactly size<Sequence>::value
comparisons for identity.
-
-
-
-typedef list<int,char,long,short,char,short,double,long> types; -typedef find<types, short>::type iter; -BOOST_STATIC_ASSERT((is_same<iter::type,short>::type::value)); -BOOST_STATIC_ASSERT((distance< begin<types>::type,iter >::type::value == 3)); --
-
-Algorithms, count_if
, find
, find_if
, contains
-
-
-template< - typename Sequence - , typename Pred - > -struct count_if -{ - typedef unspecified type; -}; --
-
-Returns the number of elements in a Sequence
that satisfy the predicate Pred
.
-
-
-
-#include "boost/mpl/count_if.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Sequence | A model of Forward Sequence | A sequence to be examined. |
Pred | A model of Predicate [Lambda Expression] | The count condition. |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef count_if<Sequence,Pred>::type n; | A model of Integral Constant | Equivalent to typedef lambda<Pred>::type pred; typedef fold< Sequence,integral_c<unsigned long,0>,if_<pred,next<_1>,_1> >::type n; |
-
-
-Linear. Exactly size<Sequence>::value
applications of Pred
.
-
-
-
-typedef list<int,char,long,short,char,long,double,long> types; ---BOOST_STATIC_ASSERT((count_if< types,boost::is_float<_> >::type::value == 1)); -BOOST_STATIC_ASSERT((count_if< types,boost::is_same<_,char> >::type::value == 2)); -BOOST_STATIC_ASSERT((count_if< types,boost::is_same<_,void> >::type::value == 0)); -
-
-Algorithms, count
, find_if
, find
, contains
-
-
-template< - typename Iterator - > -struct deref -{ - typedef typename Iterator::type type; -}; --
-
-Dereferences an iterator. -
-
-
-#include "boost/mpl/deref.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Iterator | A model of Trivial Iterator | An iterator to be dereferenced. |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef deref<Iterator>::type t; | A type | Equivalent to typedef Iterator::type t; . | Iterator is dereferenceable |
-
-Amortized constant time. -
-
-
-typedef list<char,short,int,long> types; -typedef begin<types>::type iter; -BOOST_STATIC_ASSERT(boost::is_same< deref<iter>::type,char >::value)); --
-
-
-template< - typename First - , typename Last - > -struct distance -{ - typedef unspecified type; -}; --
-
-Finds the distance between First
and Last
, that is, an Integral Constant D
such as advance< First,D >::type
is identical to Last
.
-
-
-
-#include "boost/mpl/distance.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
First , Last | A model of Input Iterator |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef distance<First,Last>::type d; | A model of Integral Constant | [First, Last) is a valid range | is_same< advance< First,d >::type, Last >::value |
-
-Amortized constant time if Iterator
is a model of Random Access Iterator, otherwise linear time.
-
-
-
-typedef range_c<int,0,10>::type range; -BOOST_STATIC_ASSERT((distance< begin<range>::type,end<range>::type >::type::value == 10)); --
-
-Iterators, Sequence, advance
, begin
, end
-
-
-template< - typename T1 - , typename T2 - , typename T3 = integral_c<int,1> - , ... - , typename Tn = integral_c<int,1> - > -struct divides -{ - typedef unspecified type; -}; --
-
-Returns the quotient of its arguments [1]. -
-
-
-#include "boost/mpl/divides.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
T1, T2, .., Tn | A model of Integral Constant |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef divides<t1,t2,..,tn>::type quot; | A model of Integral Constant | t2::value != 0, t3::value != 0, .., tn::value != 0 | Equivalent to typedef integral_c<typeof(t1::value / t2::value .. / tn::value), t1::value / t2::value .. / tn::value > quot; |
-
-Amortized constant time. -
-
-
-typedef divides< integral_c<short,-10>, integral_c<long,3> >::type quot; -BOOST_STATIC_ASSERT(quot::value == -3)); -BOOST_MPL_ASSERT_IS_SAME(quot::value_type, long); --
-
-[1] The divides
metafunction can be (and is expected to be) specialized by user to work on user-defined types that do not satisfy the Integral Constant requirements. The requirements listed here are the ones imposed by the default implementation.
-
-
-Metafunctions, multiplies
, modulus
, plus
, minus
, negate
-
-
-template< - typename Sequence - > -struct empty -{ - typedef unspecified type; -}; --
-
-Returns an Integral Constant c
such that c::value == true
if and only if the sequence is empty.
-
-
-
-#include "boost/mpl/empty.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Sequence | A model of Sequence |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef empty<Sequence>::type c; | A model of bool Integral Constant | Equivalent to typedef is_same< begin<Sequence>::type,end<Sequence>::type >::type c; |
-
-
-Amortized constant time. -
-
-
-typedef range_c<int,0,0> empty_range; -typedef list<long,float,double> types; ---BOOST_STATIC_ASSERT(empty<empty_range>::value) -BOOST_STATIC_ASSERT(!empty<types>::value) -
-
-
-template< - typename Sequence - > -struct end -{ - typedef unspecified type; -}; --
-
-Returns the past-the-end iterator to the sequence. -
-
-
-#include "boost/mpl/begin_end.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Sequence | A model of Sequence |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef end<Sequence>::type last; | A model of Input Iterator | last is an iterator pointing one past the last element in the Sequence ; equivalent to Sequence::end unless the algorithm has been specialized for the particular type of sequence. | last is past-the-end. |
-
-Amortized constant time. -
-
-
-typedef list<long> short_list; -typedef begin<short_list>::type first; -typedef end<short_list>::type last; -BOOST_STATIC_ASSERT((boost::is_same<first::next,last>::value)); --
-
-Iterators, Sequence, begin
, size
, empty
-
-
-template< - typename Sequence1 - , typename Sequence2 - , typename Pred = is_same<_1,_2> - > -struct equal -{ - typedef unspecified type; -}; --
-
-Returns true_
if the two sequences Sequence1
and Sequence2
are identical when compared element-by-element, and otherwise returns false_
.
-
-
-
-#include "boost/mpl/equal.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Sequence1 , Sequence2 | A model of Forward Sequence | Sequences to compare. |
Pred | A binary Predicate [Lambda Expression] | The comparison metafunction. |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef equal<Sequence1,Sequence2,Pred>::type c; | A model of Integral Constant | c::value == true is and only if size<Sequence1>::type::value == size<Sequence2>::type::value and for every iterator i in [begin<Sequence>::type,end<Sequence>::type) i::type is identical to advance< begin<Sequence2>::type, distance< begin<Sequence1>::type,i >::type >::type . |
-
-Linear. At most size<Sequence1>::value
comparisons.
-
-
-
-typedef vector<char,int,unsigned,long,unsigned long> s1; -typedef list<char,int,unsigned,long,unsigned long> s2; -BOOST_STATIC_ASSERT((equal<s1,s2>::type::value)); --
-
-Algorithms, count
, count_if
-
-
-template< - typename T1 - , typename T2 - > -struct equal_to -{ - typedef unspecified type; -}; --
-
-Returns true_
if T1::value == T2::value
and false_
otherwise [1].
-
-
-
-#include "boost/mpl/equal_to.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
T1, T2 | A model of Integral Constant |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef equal_to<t1,t2>::type c; | A model of bool Integral Constant | Equivalent to typedef bool_<(t1::value == t2::value)> c; |
-
-Amortized constant time. -
-
-
-typedef list_c<int,1,2,3,5,7,12,19,31> fibonacci; -typedef find_if< fibonacci, equal_to<_1,int_<12> > >::type iter; -BOOST_STATIC_ASSERT(equal_to< distance< begin<fibonacci>::type, iter >::type, int_<5> >::type::value)); --
-
-[1] The equal_to
metafunction can be (and is expected to be) specialized by user to work on user-defined types that do not satisfy the Integral Constant requirements. The requirements listed here are the ones imposed by the default implementation.
-
-
-Metafunctions, not_equal_to
, less
, less_equal
, greater
, greater_equal
-
-
-template< - typename Sequence - , typename First - , typename Last = typename First::next - > -struct erase -{ - typedef unspecified type; -}; --
-
-erase
performs a removal of one or several consequent elements in the sequence starting from an arbitrary position. The algorithm returns a new sequence which contains all the elements in the ranges [begin<Sequence>::type, First)
and [Last, end<Sequence>::type)
. The result sequence preserves all the functional and performance characteristics of the original Sequence
, except its size and identity.
-
-
-
-#include "boost/mpl/erase.hpp" --
-
Parameter | Requirement | Description | Default value |
---|---|---|---|
Sequence | A model of Extensible Sequence | A sequence to handle the erase operation. | |
First | A model of Forward Iterator | Iterator to the beginning of the range to be erased. | |
Last | A model of Forward Iterator | Past-the-end iterator of the range to be erased. | typename First::next |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef erase<Sequence,pos>::type s; | A model of Extensible Sequence | pos is a dereferenceable iterator in Sequence . | Returns a new sequence which contains all the elements in the ranges [begin<Sequence>::type, pos) and [next<pos>::type, end<Sequence>::type) . | size<s>::type::value == size<Sequence>::type::value - 1 ; the relative order of the elements in s is the same as in Sequence . |
typedef erase<Sequence,first,last>::type s; | A model of Extensible Sequence | [first,last) is a valid range in Sequence . | Returns a new sequence which contains all the elements in the ranges [begin<Sequence>::type, first) and [last, end<Sequence>::type) . | size<s>::type::value == size<Sequence>::type::value - distance<first,last>::type::value ; the relative order of the elements in s is the same as in Sequence . |
-
-The range form has linear complexity. The complexity of single-element erase is sequence dependent (linear in the worst case, or amortized constant time). -
-
-
-typedef list_c<int,1,0,5,1,7,5,0,5> values; -typedef find< values, integral_c<int,7> >::type pos; -typedef erase<values,pos>::type result_seq; -BOOST_STATIC_ASSERT(size<result_seq>::type::value == 7); ---typedef find<result, integral_c<int,7> >::type result_iter; -BOOST_MPL_ASSERT_IS_SAME(result_iter, end<result_seq>::type); -
-
-Extensible Sequence, pop_front
, pop_back
, insert
-
-
-template< - typename Sequence - , typename First - , typename Last - > -struct erase_range -{ - typedef implementation-defined type; -}; --
-
-[to do] -
-
-
-#include "boost/mpl/erase_range.hpp" --
-
Parameter | Requirement | Description | Default argument |
---|---|---|---|
Param | A model of Concept | [to do] | [to do] |
-
Member | Description |
---|---|
type | [to do] |
-
-[to do] -
-
-
-[to do] --
-
-Algorithms, erase
, erase_all
, erase_if
-
-
-template<
- typename Sequence
- , typename Pred
- >
-struct filter_view
-{
- // unspecified
-};
-
--
-filter_view
is a sequence wrapper that allows one to operate on the filtered sequence without actually creating one.
-
-
-
-#include "boost/mpl/filter_view.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Sequence | A model of Sequence | A sequence to wrap. |
Pred | A model of unary Predicate [Lambda Expression] | A filtering predicate. |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef filter_view<Sequence,Pred> s; | A model of Sequence | s prodives iterators to all the elements in the range [begin<Sequence>::type,end<Sequence>::type) that satisfy the predicate Pred . | size<s>::type::value == count_if< Sequence,Pred >::type::value . |
-
-Amortized constant time. -
-
-Finds the largest floating type in a sequence. -
-
-typedef list<int,float,long,float,char[50],long double,char> types; -typedef max_element< - transform_view< filter_view< types,boost::is_float<_> >, size_of<_> > - >::type iter; ---BOOST_STATIC_ASSERT((is_same<iter::base::type,long double>::value)); -
-
-Sequences, transform_view
, joint_view
, zip_view
, max_element
-
-
-template< - typename Sequence - , typename T - > -struct find -{ - typedef unspecified type; -}; --
-
-Finds the first occurrence of type T
in a Sequence
.
-
-
-
-#include "boost/mpl/find.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Sequence | A model of Forward Sequence | A sequence to search in. |
T | A type | The type to search for. |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef find<Sequence,T>::type i; | A model of Forward Iterator | Equivalent to typedef find_if<Sequence, is_same<_,T> >::type i ; |
-
-Linear. At most size<Sequence>::value
comparisons for identity.
-
-
-
-typedef vector<char,int,unsigned,long,unsigned long> types; -typedef find<types,unsigned>::type iter; -BOOST_STATIC_ASSERT(iter::pos::value == 2); --
-
-Algorithms, find_if
, contains
, count
, count_if
-
-
-template< - typename Sequence - , typename Pred - > -struct find_if -{ - typedef unspecified type; -}; --
-
-Finds the first element in a Sequence
that satisfies the predicate Pred
.
-
-
-
-#include "boost/mpl/find_if.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Sequence | A model of Forward Sequence | A sequence to search in. |
Pred | A model of Predicate [Lambda Expression] | A search condition. |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef find_if<Sequence,Pred>::type i; | A model of Forward Iterator | i is the first iterator in the range [begin<Sequence>::type, end<Sequence>::type) such that apply< lambda<Pred>::type,i::type >::type::value == true ; i is identical to end<Sequence>::type , if no such iterator exists. |
-
-Linear. At most size<Sequence>::value
applications of Pred
.
-
-
-
-typedef vector<char,int,unsigned,long,unsigned_long> types; -typedef find_if<types, is_same<_1,unsigned> >::type iter; -BOOST_STATIC_ASSERT(iter::pos::value == 2); --
-
-Algorithms, find
, contains
, count
, count_if
-
-
-template< - typename Sequence - , typename State - , typename ForwardOp - > -struct fold -{ - typedef unspecified type; -}; --
-
-Returns the result of the successive application of binary ForwardOp
to the result of the previous ForwardOp
invocation (State
if it's the first call) and every element of the sequence in the range [begin<Sequence>::type,end<Sequence>::type)
in the linear order.
-
-
-
-#include "boost/mpl/fold.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Sequence | A model of Sequence | A sequence to iterate. |
State | A type | The initial state for the first ForwardOp application. |
ForwardOp | A model of [Lambda Function] | The operation to be executed on forward traversal. |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef fold<Sequence,T,Op>::type t; | A type | Equivalent to typedef lambda<Op>::type op; typedef iter_fold< Sequence,T,apply<op,_1,deref<_2> > >::type t; . |
-
-Linear. Exactly size<Sequence>::type::value
applications of ForwardOp
.
-
-
-
-typedef vector<long,float,short,double,float,long,long double> types; -typedef typename fold< - types - , integral_c<long, 0> - , if_< is_float<_2>,next<_1>,_1 > - >::type number_of_floats; ---BOOST_STATIC_ASSERT(number_of_floats::value == 4); -
-
-Algorithms, fold_backward
, iter_fold
, iter_fold_backward
, copy
, copy_if
-
-
-template< - typename Sequence - , typename State - , typename BackwardOp - , typename ForwardOp = _1 - > -struct fold_backward -{ - typedef unspecified type; -}; --
-
-Returns the result of the successive application of binary BackwardOp
to the result of the previous BackwardOp
invocation (State
if it's the first call) and every element in the range [begin<Sequence>::type,end<Sequence>::type)
in the reverse order. If ForwardOp
is provided, then it's applied on forward traversal to form the result which is passed to the first BackwardOp
call.
-
-
-
-#include "boost/mpl/fold_backward.hpp" --
-
Parameter | Requirement | Description | Default value |
---|---|---|---|
Sequence | A model of Sequence | A sequence to iterate. | |
State | A type | The initial state for the first BackwardOp /ForwardOp application. | |
BackwardOp | A model of [Lambda Function] | The operation to be executed on backward traversal. | |
ForwardOp | A model of [Lambda Function] | The operation to be executed on forward traversal. | arg<1> |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef fold_backward< Sequence,T,BackwardOp >::type t; | A type | Equivalent to typedef lambda<BackwardOp>::type bk_op; typedef begin<Sequence>::type i1; typedef i1::next i2; ...; typedef in::next last; typedef apply<bk_op,T,in::type>::type tn; typedef apply<bk_op,tn,in-1::type>::type tn-1; ...; typedef apply<bk_op,t2,i1::type>::type t1; typedef t1 t , where n == size<Sequence>::type::value and last is identical to end<Sequence>::type ; Equivalent to typedef T t; if the sequence is empty. | ||
typedef fold_backward< Sequence,T,BackwardOp,ForwardOp >::type t; | A type | Equivalent to typedef fold_backward<Sequence, fold<Sequence,State,ForwardOp>::type, BackwardOp>::type t; . |
-
-Linear. Exactly size<Sequence>::type::value
applications of BackwardOp
and ForwardOp
.
-
-
-Removes negative elements from a sequence [1]. -
-
-typedef list_c<int,5,-1,0,-7,-2,0,-5,4> numbers; -typedef list_c<int,-1,-7,-2,-5> negatives; -typedef fold_backward< - numbers - , list_c<int> - , if_< less< _2,int_<0> >, push_front<_1,_2,>, _1 > - >::type result; ---BOOST_STATIC_ASSERT(equal< negatives,result >::type::value); -
-
-[1] See remove_if
for a more compact way to do this.
-
-
-Algorithms, fold
, iter_fold_backward
, iter_fold
, copy
, copy_backward
-
-
-template< - typename Sequence - > -struct front -{ - typedef unspecified type; -}; --
-
-Returns a type identical to the first element in the sequence. -
-
-
-#include "boost/mpl/front.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Sequence | A model of Forward Sequence | A sequence to be examined. |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef front<Sequence>::type t; | A type | empty<Sequence>::type::value == false | Equivalent to typedef begin<Sequence>::type::type t; |
-
-Amortized constant time. -
-
-
-typedef list<long>::type types1; -typedef list<int,long>::type types2; -typedef list<char,int,long>::type types3; ---BOOST_MPL_ASSERT_IS_SAME(front<types1>::type, long); -BOOST_MPL_ASSERT_IS_SAME(front<types2>::type, int); -BOOST_MPL_ASSERT_IS_SAME(front<types3>::type, char); -
-
-Forward Sequence, back
, at
, push_front
, begin
, empty
-
-
-template< - typename T1 - , typename T2 - > -struct greater -{ - typedef unspecified type; -}; --
-
-Returns true_
if T1::value > T2::value
and false_
otherwise [1].
-
-
-
-#include "boost/mpl/greater.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
T1, T2 | A model of Integral Constant |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef greater<t1,t2>::type c; | A model of bool Integral Constant | Equivalent to typedef bool_<(t1::value > t2::value)> c; |
-
-Amortized constant time. -
-
-
-typedef list_c<int,1,2,3,5,7,12,19,31> fibonacci; -typedef find_if< fibonacci, greater<_1,int_<10> > >::type iter; -BOOST_STATIC_ASSERT(iter::type::value == 12)); --
-
-[1] The greater
metafunction can be (and is expected to be) specialized by user to work on user-defined types that do not satisfy the Integral Constant requirements. The requirements listed here are the ones imposed by the default implementation.
-
-
-Metafunctions, greater_equal
, less
, less_equal
, equal_to
, not_equal_to
-
-
-template< - typename T1 - , typename T2 - > -struct greater_equal -{ - typedef unspecified type; -}; --
-
-Returns true_
if T1::value > T2::value
and false_
otherwise [1].
-
-
-
-#include "boost/mpl/greater_equal.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
T1, T2 | A model of Integral Constant |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef greater_equal<t1,t2>::type c; | A model of bool Integral Constant | Equivalent to typedef bool_<(t1::value >= t2::value)> c; |
-
-Amortized constant time. -
-
-
-typedef list_c<int,0,1,2,3,4,5,6,7,8,9> numbers; -typedef remove_if< numbers, greater_equal<_1,int_<5> > >::type result; -BOOST_STATIC_ASSERT(equal< result,range_c<int,0,5> >::type::value)); --
-
-[1] The greater_equal
metafunction can be (and is expected to be) specialized by user to work on user-defined types that do not satisfy the Integral Constant requirements. The requirements listed here are the ones imposed by the default implementation.
-
-
-Metafunctions, greater
, less
, less_equal
, equal_to
, not_equal_to
-
-
-template< - typename Sequence - , typename Pos - , typename T - > -struct insert -{ - typedef unspecified type; -}; --
-
-insert
performs an insertion of type T
at an arbitrary position in the sequence. The algorithm returns a new sequence which contains all the elements from Sequence
plus the type T
at the distance< begin<Sequence>::type,Pos >::type
position from the beginning. The result sequence preserves all the functional and performance characteristics of the original Sequence
, except its size and identity.
-
-
-
-#include "boost/mpl/insert.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Sequence | A model of Extensible Sequence | A sequence to handle the insert operation. |
Pos | A model of Forward Iterator | An insert position in the Sequence . |
T | A type | The element to be inserted. |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef insert<Sequence,pos,T>::type s; | A model of Extensible Sequence | pos is a valid iterator in Sequence . | s contains T at the distance< begin<Sequence>::type,pos >::type position. | size<s>::type::value == size<Sequence>::type::value + 1 ; at< distance< begin<Sequence>::type,pos >::type, s >::type is identical to T ; the relative order of the elements in s is the same as in Sequence . |
-
-Sequence dependent. Linear in the worst case, or amortized constant time. -
-
-
-typedef list_c<int,0,1,3,4,5,6,7,8,9> numbers; -typedef find< numbers,integral_c<int,3> >::type pos; -typedef insert< numbers,pos,integral_c<int,2> >::type range; -BOOST_STATIC_ASSERT(size<range>::type::value == 10); -BOOST_STATIC_ASSERT((equal< range,range_c<int,0,10> >::type::value)); --
-
-Extensible Sequence, insert_range
, push_front
, push_back
, erase
-
-
-template< - typename Sequence - , typename Pos - , typename Range - > -struct insert_range -{ - typedef unspecified type; -}; --
-
-insert_range
performs an insertion of a range of elements at an arbitrary position in the sequence. The algorithm returns a new sequence which contains all the elements of Sequence
plus all the elements of Range
starting at the distance< begin<Sequence>::type,Pos >::type
position from the beginning. The result sequence preserves all the functional and performance characteristics of the original Sequence
, except its size and identity.
-
-
-
-#include "boost/mpl/insert_range.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Sequence | A model of Extensible Sequence | A sequence to handle the insert operation. |
Pos | A model of Forward Iterator | An insert position in the Sequence . |
Range | A model of Sequence | The range of elements to be inserted. |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef insert<Sequence,pos,range>::type s; | A model of Extensible Sequence | pos is a valid iterator in Sequence . | s contains all the elements from range starting at the distance< begin<Sequence>::type,pos >::type position. | size<s>::type::value == size<Sequence>::type::value + size<range>::type::value ; the relative order of the elements in s is the same as in Sequence . |
-
-Linear time. -
-
-
-typedef list_c<int,0,1,7,8,9> numbers; -typedef find< numbers,integral_c<int,7> >::type pos; -typedef insert_range< numbers,pos,range_c<int,2,7> >::type range; -BOOST_STATIC_ASSERT(size<range>::type::value == 10); -BOOST_STATIC_ASSERT((equal< range,range_c<int,0,10> >::type::value)); --
-
-Extensible Sequence, insert
, push_front
, push_back
, erase
-
-
-template< - typename T - > -struct is_sequence -{ - typedef unspecified type; -}; --
-
-Returns an Integral Constant c
such that c::value == true
if and only if T
is a model of Sequence.
-
-
-
-#include "boost/mpl/is_sequence.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
T | A type |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef is_sequence<T>::type c; | A model of bool Integral Constant | Equivalent to typedef not_< is_same< begin<T>::type,void_ > >::type c; |
-
-
-Amortized constant time. -
-
-
-struct UDT {}; -BOOST_STATIC_ASSERT( !is_sequence<int>::value ); -BOOST_STATIC_ASSERT( !is_sequence<UDT>::value ); -BOOST_STATIC_ASSERT( is_sequence< list<> >::value ); -BOOST_STATIC_ASSERT( is_sequence< vector<> >::value ); --
-
-Sequence, begin
, end
, as_sequence
-
-
-template< - typename Sequence - , typename State - , typename ForwardOp - > -struct iter_fold -{ - typedef unspecified type; -}; --
-
-Returns the result of the successive application of binary ForwardOp
to the result of the previous ForwardOp
invocation (State
if it's the first call) and each iterator in the range [begin<Sequence>::type,end<Sequence>::type)
in the linear order.
-
-
-
-#include "boost/mpl/iter_fold.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Sequence | A model of Sequence | A sequence to iterate. |
State | A type | The initial state for the first ForwardOp application. |
ForwardOp | A model of [Lambda Function] | The operation to be executed on forward traversal. |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef iter_fold<Sequence,T,Op>::type t; | A type | Equivalent to typedef lambda<Op>::type op; typedef begin<Sequence>::type i1; typedef apply<op,T,i1>::type t1; typedef i1::next i2; typedef apply<op,t1,i2>::type t2; ...; typedef apply<op,T,in>::type tn; typedef in::next last; typedef tn t , where n == size<Sequence>::type::value and last is identical to end<Sequence>::type ; Equivalent to typedef T t; if the sequence is empty. |
-
-Linear. Exactly size<Sequence>::type::value
applications of ForwardOp
.
-
-
-
-typedef list_c<int,5,-1,0,7,2,0,-5,4> numbers; -typedef iter_fold< - numbers - , begin<numbers>::type - , if_< less< deref<_1>, deref<_2> >,_2,_1 > - >::type max_element_iter; ---BOOST_STATIC_ASSERT(max_element_iter::type::value == 7); -
-
-Algorithms, iter_fold_backward
, fold
, fold_backward
, copy
, copy_backward
-
-
-template< - typename Sequence - , typename State - , typename BackwardOp - , typename ForwardOp = _1 - > -struct iter_fold_backward -{ - typedef unspecified type; -}; --
-
-Returns the result of the successive application of binary BackwardOp
to the result of the previous BackwardOp
invocation (State
if it's the first call) and each iterator in the range [begin<Sequence>::type,end<Sequence>::type)
in the reverse order. If ForwardOp
is provided, then it's applied on forward traversal to form the result which is passed to the first BackwardOp
call.
-
-
-
-#include "boost/mpl/iter_fold_backward.hpp" --
-
Parameter | Requirement | Description | Default value |
---|---|---|---|
Sequence | A model of Sequence | A sequence to iterate. | |
State | A type | The initial state for the first BackwardOp /ForwardOp application. | |
BackwardOp | A model of [Lambda Function] | The operation to be executed on backward traversal. | |
ForwardOp | A model of [Lambda Function] | The operation to be executed on forward traversal. | arg<1> |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef iter_fold_backward< Sequence,T,BackwardOp >::type t; | A type | Equivalent to typedef lambda<BackwardOp>::type bk_op; typedef begin<Sequence>::type i1; typedef i1::next i2; ...; typedef in::next last; typedef apply<bk_op,T,in>::type tn; typedef apply<bk_op,tn,in-1>::type tn-1; ...; typedef apply<bk_op,t2,i1>::type t1; typedef t1 t , where n == size<Sequence>::type::value and last is identical to end<Sequence>::type ; Equivalent to typedef T t; if the sequence is empty. | ||
typedef iter_fold_backward< Sequence,T,BackwardOp,ForwardOp >::type t; | A type | Equivalent to typedef iter_fold_backward<Sequence, iter_fold<Sequence,State,ForwardOp>::type, BackwardOp>::type t; . |
-
-Linear. Exactly size<Sequence>::type::value
applications of BackwardOp
and ForwardOp
.
-
-
-Builds a list of iterators to the negative elements in a sequence. -
-
-typedef vector_c<int,5,-1,0,-7,-2,0,-5,4> numbers; -typedef list_c<int,-1,-7,-2,-5> negatives; -typedef iter_fold_backward< - numbers - , list<> - , if_< less< deref<_2>,int_<0> >, push_front<_1,_2>, _1 > - >::type iters; ---BOOST_STATIC_ASSERT(equal< negatives, transform_view< iters,deref<_1> > >::type::value); -
-
-Algorithms, iter_fold
, fold_backward
, fold
, copy
, copy_backward
-
-
-template< - typename Iterator - > -struct iterator_category -{ - typedef unspecified type; -}; --
-
-Returns one of the following iterator category tags: input_iterator_tag
, forward_iterator_tag
, bidirectional_iterator_tag
, or random_access_iterator_tag
.
-
-
-
-#include "boost/mpl/iterator_category.hpp" -#include "boost/mpl/iterator_tag.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Iterator | A model of Input Iterator |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef iterator_category<Iterator>::type tag; | An iterator category tag | tag is input_iterator_tag if Iterator is a model of Input Iterator, forward_iterator_tag if Iterator is a model of Forward Iterator, bidirectional_iterator_tag if Iterator is a model of Bidirectional Iterator, or random_access_iterator_tag if Iterator is a model of Random Access Iterator. |
-
-Amortized constant time. -
-
-
-template< typename Iterator > -struct my_algorithm - : my_algorithm_impl< - iterator_category<Iterator>::type - , Iterator - > -{ -}; --
-
-Iterators, Sequence, begin
, end
, advance
, distance
-
-
-template<
- typename Sequence1
- , typename Sequence2
- >
-struct joint_view
-{
- // unspecified
-};
-
--
-joint_view
is a two-sequence view that allows one to operate on a sequence of concatenated elements of sequences Sequence1
and Sequence2
without actually creating one.
-
-
-
-#include "boost/mpl/joint_view.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Sequence1 , Sequence2 | A model of Sequence | Sequences to concatenate. |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef joint_view<Sequence1,Sequence2> s; | A model of Sequence | s prodives iterators to all the elements in the ranges [begin<Sequence1>::type,end<Sequence1>::type) , [begin<Sequence2>::type,end<Sequence2>::type) . | size<s>::type::value == size< Sequence1 >::type::value + size< Sequence2 >::type::value . |
-
-Amortized constant time. -
-
-
-typedef joint_view< - range_c<int,0,10> - , range_c<int,10,15> - > numbers; ---typedef range_c<int,0,15> answer; -BOOST_STATIC_ASSERT((equal<numbers,answer>::type::value)); -
-
-Sequences, transform_view
, filter_view
, zip_view
-
-
-template< - typename T1 - , typename T2 - > -struct less -{ - typedef unspecified type; -}; --
-
-Returns true_
if T1::value < T2::value
and false_
otherwise [1].
-
-
-
-#include "boost/mpl/less.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
T1, T2 | A model of Integral Constant |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef less<t1,t2>::type c; | A model of bool Integral Constant | Equivalent to typedef bool_<(t1::value < t2::value)> c; |
-
-Amortized constant time. -
-
-
-typedef list_c<int,0,1,2,3,4,5,6,7,8,9> numbers; -typedef remove_if< numbers, less<_1,int_<5> > >::type result; -BOOST_STATIC_ASSERT(equal< result,range_c<int,5,10> >::type::value)); --
-
-[1] The less
metafunction can be (and is expected to be) specialized by user to work on user-defined types that do not satisfy the Integral Constant requirements. The requirements listed here are the ones imposed by the default implementation.
-
-
-Metafunctions, less_equal
, greater
, greater_equal
, equal
, not_equal_to
-
-
-template< - typename T1 - , typename T2 - > -struct less_equal -{ - typedef unspecified type; -}; --
-
-Returns true_
if T1::value <= T2::value
and false_
otherwise [1].
-
-
-
-#include "boost/mpl/less_equal.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
T1, T2 | A model of Integral Constant |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef less_equal<t1,t2>::type c; | A model of bool Integral Constant | Equivalent to typedef bool_<(t1::value <= t2::value)> c; |
-
-Amortized constant time. -
-
-
-typedef list_c<int,0,1,2,3,4,5,6,7,8,9> numbers; -typedef remove_if< numbers, less_equal<_1,int_<4> > >::type result; -BOOST_STATIC_ASSERT(equal< result,range_c<int,5,10> >::type::value)); --
-
-[1] The less_equal
metafunction can be (and is expected to be) specialized by user to work on user-defined types that do not satisfy the Integral Constant requirements. The requirements listed here are the ones imposed by the default implementation.
-
-
-Metafunctions, less
, greater
, greater_equal
, equal
, not_equal_to
-
-
-template< - typename T1 = implementation-defined - , typename T2 = implementation-defined - , ... - , typename Tn = implementation-defined - > -struct list -{ -}; --
-
-A list
is a Forward Sequence of types. It's also an Extensible Sequence that supports constant time insertion and removal of elements at the beginning (through push_front
), and linear time insertion and removal of elements at the end or in the middle (through insert
/erase
algorithms).
-
-
-
-typedef list<float,double,long double> floats; -typedef push_front<floating_types,my_float>::type ext_floats; -BOOST_STATIC_ASSERT((boost::is_same< front<ext_floats>::type, my_float >::value)); --
-
-
-#include "boost/mpl/list.hpp" -#include "boost/mpl/list/list0.hpp" -#include "boost/mpl/list/list10.hpp" -... -#include "boost/mpl/list/list50.hpp" --
-
-Forward Sequence, list_c
, vector
, vector_c
, range_c
-
-
-template< - typename T - , T C1 = implementation-defined - , T C2 = implementation-defined - , ... - , T CN = implementation-defined - > -struct list_c -{ -}; --
-
-Similary to vector_c
, list_c
is a shorcut interface whose whole purpose is to make the creation of a list
of Integral Constants less verbose:
-
-
-typedef list_c<unsigned long,-1,0,1,1,-1,0,0,1,-1> data; --
-If list_c
didn't exist, instead of the above line you would have to write this:
-
-
-typedef list< - integral_c<unsigned long,-1> - , integral_c<unsigned long,0> - , integral_c<unsigned long,1> - , integral_c<unsigned long,1> - , integral_c<unsigned long,-1> - , integral_c<unsigned long,0> - , integral_c<unsigned long,0> - , integral_c<unsigned long,1> - , integral_c<unsigned long,-1> - > data; --
-
-
-#include "boost/mpl/list_c.hpp" -#include "boost/mpl/list/list0_c.hpp" -#include "boost/mpl/list/list10_c.hpp" -... -#include "boost/mpl/list/list50_c.hpp" --
-
-Random Access Sequence, list
, vector
, vector_c
, range_c
-
-
-template< - typename Sequence - , typename T - , typename Pred = less<_,_> - > -struct lower_bound -{ - typedef unspecified type; -}; --
-
-Returns the first position in the sorted Sequence
where T
could be inserted without violating the ordering.
-
-
-
-#include "boost/mpl/lower_bound.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Sequence | A model of Forward Sequence | A sorted sequence. |
T | A type | A type to search the position for. |
Pred | A model of binary Predicate [Lambda Expression] | A sort criteria. |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef lower_bound< Sequence,T,Pred >::type i; | A model of Forward Iterator | i is the furthermost iterator in [begin<Sequence>::type, end<Sequence>::type) such that, for every iterator j in [begin<Sequence>::type, i) , apply< lambda<Pred>::type, j::type, T >::type::value == true . |
-
-The number of comparisons is logarithmic: at most log(size<Sequence>::type::value) + 1
. If Sequence
is a Random Access Sequence then the number of steps through the range is also logarithmic; otherwise, the number of steps is proportional to size<Sequence>::type::value
.
-
-
-
-typedef list_c<int,1,2,3,3,3,5,8> numbers; -typedef lower_bound< numbers, int_<3> >::type iter; -BOOST_STATIC_ASSERT((distance< begin<numbers>::type,iter >::type::value == 2)); -BOOST_STATIC_ASSERT(iter::type::value == 3); --
-
-Algorithms, sort
, upper_bound
-
-
-template< - typename Sequence - , typename Pred = less<_1,_2> - > -struct max_element -{ - typedef unspecified type; -}; --
-
-Finds the largest element in the Sequence
.
-
-
-
-#include "boost/mpl/max_element.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Sequence | A model of Forward Sequence | A sequence to be searched. |
Pred | A model of binary Predicate [Lambda Expression] | A comparison criteria. |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef max_element< Sequence,Pred >::type i; | A model of Forward Iterator | i is the first iterator in [begin<Sequence>::type, end<Sequence>::type) such that for every iterator j in [begin<Sequence>::type, end<Sequence>::type) , apply< lambda<Pred>::type, i::type, j::type >::type::value == false . |
-
-Linear. Zero comparisons if Sequence
is empty, otherwise exactly size<Sequence>::value - 1
comparisons.
-
-
-
-typedef vector<int,char[50],long,double> types; -typedef max_element< - transform_view< types,sizeof_<_1> > - >::type iter; ---BOOST_STATIC_ASSERT((distance< begin<types>::type,iter >::type::value == 1)); -BOOST_STATIC_ASSERT(sizeof(deref<iter>::type) == 50); -
-
-Algorithms, min_element
, upper_bound
, lower_bound
-
-
-template< - typename Sequence - , typename Pred = less<_1,_2> - > -struct min_element -{ - typedef unspecified type; -}; --
-
-Finds the smallest element in the Sequence
.
-
-
-
-#include "boost/mpl/min_element.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Sequence | A model of Forward Sequence | A sequence to be searched. |
Pred | A model of binary Predicate [Lambda Expression] | A comparison criteria. |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef min_element< Sequence,Pred >::type i; | A model of Forward Iterator | i is the first iterator in [begin<Sequence>::type, end<Sequence>::type) such that for every iterator j in [begin<Sequence>::type, end<Sequence>::type) , apply< lambda<Pred>::type, j::type, i::type >::type::value == false . |
-
-Linear. Zero comparisons if Sequence
is empty, otherwise exactly size<Sequence>::value - 1
comparisons.
-
-
-
-typedef vector<bool,char[50],long,double> types; -typedef min_element< - transform_view< types,sizeof_<_1> > - >::type iter; ---BOOST_STATIC_ASSERT((distance< begin<types>::type,iter >::type::value == 0)); -BOOST_STATIC_ASSERT(sizeof(deref<iter>::type) == sizeof(bool)); -
-
-Algorithms, max_element
, upper_bound
, lower_bound
-
-
-template< - typename T1 - , typename T2 - , typename T3 = integral_c<int,0> - , ... - , typename Tn = integral_c<int,0> - > -struct minus -{ - typedef unspecified type; -}; --
-
-Returns the difference of its arguments [1]. -
-
-
-#include "boost/mpl/minus.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
T1, T2, .., Tn | A model of Integral Constant |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef minus<t1,t2,..,tn>::type diff; | A model of Integral Constant | Equivalent to typedef integral_c<typeof(t1::value - t2::value .. - tn::value), t1::value - t2::value .. - tn::value > diff; |
-
-Amortized constant time. -
-
-
-typedef minus< integral_c<short,-1>, integral_c<long,10> >::type diff; -BOOST_STATIC_ASSERT(diff::value == -11)); -BOOST_MPL_ASSERT_IS_SAME(diff::value_type, long); --
-
-[1] The minus
metafunction can be (and is expected to be) specialized by user to work on user-defined types that do not satisfy the Integral Constant requirements. The requirements listed here are the ones imposed by the default implementation.
-
-
-Metafunctions, plus
, divides
, multiplies
, modulus
, negate
-
-
-template< - typename T1 - , typename T2 - > -struct modulus -{ - typedef unspecified type; -}; --
-
-Returns the modulus of its arguments [1]. -
-
-
-#include "boost/mpl/modulus.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
T1, T2 | A model of Integral Constant |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef modulus<t1,t2>::type mod; | A model of Integral Constant | t2::value != 0 | Equivalent to typedef integral_c<typeof(t1::value % t2::value), t1::value % t2::value> mod; |
-
-Amortized constant time. -
-
-
-typedef modulus< integral_c<short,10>, integral_c<long,3> >::type mod; -BOOST_STATIC_ASSERT(mod::value == 1)); -BOOST_MPL_ASSERT_IS_SAME(mod::value_type, long); --
-
-[1] The modulus
metafunction can be (and is expected to be) specialized by user to work on user-defined types that do not satisfy the Integral Constant requirements. The requirements listed here are the ones imposed by the default implementation.
-
-
-Metafunctions, divides
, multiplies
, plus
, minus
, negate
-
-
-template< - typename T1 - , typename T2 - , typename T3 = integral_c<int,1> - , ... - , typename Tn = integral_c<int,1> - > -struct multiplies -{ - typedef unspecified type; -}; --
-
-Returns the product of its arguments [1]. -
-
-
-#include "boost/mpl/multiplies.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
T1, T2, .., Tn | A model of Integral Constant |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef multiplies<t1,t2,..,tn>::type product; | A model of Integral Constant | Equivalent to typedef integral_c<typeof(t1::value * t2::value .. * tn::value), t1::value * t2::value .. * tn::value > product; |
-
-Amortized constant time. -
-
-
-typedef multiplies< integral_c<short,-1>, integral_c<long,10> >::type product; -BOOST_STATIC_ASSERT(product::value == -10)); -BOOST_MPL_ASSERT_IS_SAME(product::value_type, long); --
-
-[1] The multiplies
metafunction can be (and is expected to be) specialized by user to work on user-defined types that do not satisfy the Integral Constant requirements. The requirements listed here are the ones imposed by the default implementation.
-
-
-Metafunctions, divides
, modulus
, plus
, minus
, negate
-
-
-template< - typename T - > -struct negate -{ - typedef unspecified type; -}; --
-
-Returns the negative (additive inverse) of its argument [1]. -
-
-
-#include "boost/mpl/negate.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
T | A model of Integral Constant |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef negate<t>::type n; | A model of Integral Constant | Equivalent to typedef integral_c<t::value_type, -t::value> n; |
-
-Amortized constant time. -
-
-
-typedef negate< integral_c<short,-10> >::type n; -BOOST_STATIC_ASSERT(n::value == 10)); -BOOST_MPL_ASSERT_IS_SAME(n::value_type, short); --
-
-[1] The negate
metafunction can be (and is expected to be) specialized by user to work on user-defined types that do not satisfy the Integral Constant requirements. The requirements listed here are the ones imposed by the default implementation.
-
-
-Metafunctions, minus
, plus
, multiplies
, divides
, modulus
-
-
-template< - typename F - > -struct not_ -{ - typedef unspecified type; -}; --
-
-Returns the result of logical not (!
) operation on its argument.
-
-
-
-#include "boost/mpl/not.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
F | A model of nullary Metafunction |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
not_<f> | A model of bool Integral Constant | Equivalent to bool_<(!f::type::value)> |
-
-
-BOOST_STATIC_ASSERT(not_<true_>::value == false); -BOOST_STATIC_ASSERT(not_<false_>::value == true); --
-
-Metafunctions, and_
, or_
-
-
-template< - typename T1 - , typename T2 - > -struct not_equal_to -{ - typedef unspecified type; -}; --
-
-Returns true_
if T1::value != T2::value
and false_
otherwise [1].
-
-
-
-#include "boost/mpl/not_equal_to.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
T1, T2 | A model of Integral Constant |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef not_equal_to<t1,t2>::type c; | A model of bool Integral Constant | Equivalent to typedef bool_<(t1::value != t2::value)> c; |
-
-Amortized constant time. -
-
-
-typedef list_c<int,1,5,0,7,5,-1,2,4,5> numbers; -typedef remove_if< numbers, not_equal_to<_1,int_<5> > >::type fives; -BOOST_STATIC_ASSERT(equal_to< count_if< fives, equal_to<_1,int_<5> > >::type, size<fives>::type >::type::value)); --
-
-[1] The not_equal_to
metafunction can be (and is expected to be) specialized by user to work on user-defined types that do not satisfy the Integral Constant requirements. The requirements listed here are the ones imposed by the default implementation.
-
-
-Metafunctions, equal_to
, less
, less_equal
, greater
, greater_equal
-
-
-template< - typename F1 - , typename F2 - , typename F3 = false_ - ... - , typename Fn = false_ - > -struct or_ -{ - typedef unspecified type; -}; --
-
-Returns the result of short-circuit logical or (||
) operation on its arguments.
-
-
-
-#include "boost/mpl/or.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
F1, F2, .., Fn | A model of nullary Metafunction |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
or_<f1,f2,..,fn> | A model of bool Integral Constant | true_ if either of f1::type::value, f2::type::value, .., fn::type::value expressions evaluates to true, and false_ otherwise; guarantees left-to-right evaluation; moreover, the operands subsequent to the first fi metafunction that evaluates to true are not evaluated. |
-
-
-// will generate compile-time error if invoked with T == any fundamental type -template< typename T > struct fail -{ - typedef typename T::nonexistent type; -}; ---BOOST_STATIC_ASSERT((or_< false_,true_ >::value == true)); -BOOST_STATIC_ASSERT((or_< true_,fail<int> >::value == true)); // OK, fail<int> is never invoked -BOOST_STATIC_ASSERT((or_< false_,true_,fail<int> >::value == true)); // OK too -
-
-Metafunctions, and_
, not_
-
-
-template< - typename T1 - , typename T2 - , typename T3 = integral_c<int,0> - , ... - , typename Tn = integral_c<int,0> - > -struct plus -{ - typedef unspecified type; -}; --
-
-Returns the sum of its arguments [1]. -
-
-
-#include "boost/mpl/plus.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
T1, T2, .., Tn | A model of Integral Constant |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef plus<t1,t2,..,tn>::type sum; | A model of Integral Constant | Equivalent to typedef integral_c<typeof(t1::value + t2::value .. + tn::value), t1::value + t2::value .. + tn::value > sum; |
-
-Amortized constant time. -
-
-
-typedef plus< integral_c<short,-1>, integral_c<long,10> >::type sum; -BOOST_STATIC_ASSERT(sum::value == 9)); -BOOST_MPL_ASSERT_IS_SAME(sum::value_type, long); --
-
-[1] The plus
metafunction can be (and is expected to be) specialized by user to work on user-defined types that do not satisfy the Integral Constant requirements. The requirements listed here are the ones imposed by the default implementation.
-
-
-Metafunctions, minus
, multiplies
, divides
, modulus
, negate
-
-
-template< - typename Sequence - > -struct pop_back -{ - typedef unspecified type; -}; --
-
-pop_back
performs a removal at the end of the sequence. The algorithm returns a new sequence which contains all the elements in the range [begin<Sequence>::type, prior< end<Sequence>::type >::type)
. The result sequence preserves all the functional and performance characteristics of the original Sequence
, except its size and identity.
-
-
-
-#include "boost/mpl/pop_back.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Sequence | A model of Extensible Sequence | A sequence to handle the erase operation |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef pop_back<Sequence>::type s; | A model of Extensible Sequence | empty<Sequence>::type::value == false | Equivalent to typedef erase< Sequence, prior< end<Sequence>::type >::type >::type s; | size<s>::type::value == size<Sequence>::type::value - 1 |
-
-Amortized constant time [1]. -
-
-
-typedef list<long>::type types1; -typedef list<long,int>::type types2; -typedef list<long,int,char>::type types3; ---typedef pop_back<types1>::type result1; -typedef pop_back<types2>::type result2; -typedef pop_back<types3>::type result3; -
-BOOST_STATIC_ASSERT(size<result1>::type::value == 0); -BOOST_STATIC_ASSERT(size<result2>::type::value == 1); -BOOST_STATIC_ASSERT(size<result3>::type::value == 2); -
-BOOST_MPL_ASSERT_IS_SAME(back<result2>::type, long); -BOOST_MPL_ASSERT_IS_SAME(back<result3>::type, int); -
-
-[1] The algorithm is provided only if the sequence can meet the stated complexity requirements.
-
-
-Extensible Sequence, erase
, push_back
, back
, pop_front
-
-
-template< - typename Sequence - > -struct pop_front -{ - typedef unspecified type; -}; --
-
-pop_front
performs a removal at the beginning of the sequence. The algorithm returns a new sequence which contains all the elements in the range [next< begin<Sequence>::type >::type, end<Sequence>::type)
. The result sequence preserves all the functional and performance characteristics of the original Sequence
, except its size and identity.
-
-
-
-#include "boost/mpl/pop_front.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Sequence | A model of Extensible Sequence | A sequence to handle the erase operation |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef pop_front<Sequence>::type s; | A model of Extensible Sequence | empty<Sequence>::type::value == false | Equivalent to typedef erase< Sequence, begin<Sequence>::type >::type s; | size<s>::type::value == size<Sequence>::type::value - 1 |
-
-Amortized constant time [1]. -
-
-
-typedef list<long>::type types1; -typedef list<int,long>::type types2; -typedef list<char,int,long>::type types3; ---typedef pop_front<types1>::type result1; -typedef pop_front<types2>::type result2; -typedef pop_front<types3>::type result3; -
-BOOST_STATIC_ASSERT(size<result1>::type::value == 0); -BOOST_STATIC_ASSERT(size<result2>::type::value == 1); -BOOST_STATIC_ASSERT(size<result3>::type::value == 2); -
-BOOST_MPL_ASSERT_IS_SAME(front<result2>::type, long); -BOOST_MPL_ASSERT_IS_SAME(front<result3>::type, int); -
-
-[1] The algorithm is provided only if the sequence can meet the stated complexity requirements.
-
-
-Extensible Sequence, erase
, push_front
, front
, pop_back
-
-
-template< - typename Sequence - , typename T - > -struct push_back -{ - typedef unspecified type; -}; --
-
-push_back
performs an insertion at the end of the sequence. The algorithm returns a new sequence which contains type T
as its last element. The result sequence preserves all the functional and performance characteristics of the original Sequence
, except its size and identity.
-
-
-
-#include "boost/mpl/push_back.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Sequence | A model of Extensible Sequence | A sequence to handle the insert operation. |
T | A type | The element to be inserted. |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef push_back<Sequence,T>::type s; | A model of Extensible Sequence | Equivalent to typedef insert< Sequence,end<Sequence>::type,T >::type s; | size<s>::type::value == size<Sequence>::type::value + 1 ; back<s>::type is identical to T |
-
-Amortized constant time [1]. -
-
-
-typedef vector_c<bool,false,false,false,true,true,true,false,false> bools; -typedef push_back<bools,false_>::type message; -BOOST_STATIC_ASSERT(back<message>::type::value == false); -BOOST_STATIC_ASSERT((count_if<message, equal_to<_1,false_> >::type::value == 6)); --
-
-[1] The algorithm can be viewed as a notational shorcut to more verbose insert< Sequence,end<Sequence>::type,T >::type
, and is provided only if the sequence can meet the stated complexity requirements.
-
-
-Extensible Sequence, insert
, back
, pop_back
, push_front
-
-
-template< - typename Sequence - , typename T - > -struct push_front -{ - typedef unspecified type; -}; --
-
-push_front
performs an insertion at the beginning of the sequence. The algorithm returns a new sequence which contains type T
as its first element. The result sequence preserves all the functional and performance characteristics of the original Sequence
, except its size and identity.
-
-
-
-#include "boost/mpl/push_front.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Sequence | A model of Extensible Sequence | A sequence to handle the insert operation. |
T | A type | The element to be inserted. |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef push_front<Sequence,T>::type s; | A model of Extensible Sequence | Equivalent to typedef insert< Sequence,begin<Sequence>::type,T >::type s; | size<s>::type::value == size<Sequence>::type::value + 1 ; front<s>::type is identical to T |
-
-Amortized constant time [1]. -
-
-
-typedef list_c<int,1,2,3,5,8,13,21> something; -BOOST_STATIC_ASSERT(size<something>::type::value == 7); -typedef push_front< something,integral_c<int,1> >::type fibonacci; -BOOST_STATIC_ASSERT(size<fibonacci>::type::value == 8); -BOOST_STATIC_ASSERT((equal< fibonacci,list_c<int,1,1,2,3,5,8,13,21>,equal_to<_,_> >::type::value)); --
-
-[1] The algorithm can be viewed as a notational shorcut to more verbose insert< Sequence,begin<Sequence>::type,T >::type
, and is provided only if the sequence can meet the stated complexity requirements.
-
-
-Extensible Sequence, insert
, front
, pop_front
, push_back
-
-
-template< - typename T - , T Start - , T Finish - > -struct range_c -{ - typedef integral_c<T,Start> start; - typedef integral_c<T,Finish> finish; -}; --
-
-range_c
is a sorted Random Access Sequence of Integral Constants. It is not an Extensible Sequence, meaning that transformation algorithms, such as push_front
or replace
, are not applicable to it, at least directly - you need to copy the content of the range into a more suitable sequence, when needed [1].
-
-
-
-#include "boost/mpl/range_c.hpp" --
-
-
-typedef range_c<int,0,0> range0; -typedef range_c<int,0,1> range1; -typedef range_c<int,0,10> range10; ---BOOST_STATIC_ASSERT(size<range0>::type::value == 0); -BOOST_STATIC_ASSERT(size<range1>::type::value == 1); -BOOST_STATIC_ASSERT(size<range10>::type::value == 10); -
-BOOST_STATIC_ASSERT(empty<range0>::type::value); -BOOST_STATIC_ASSERT(!empty<range1>::type::value); -BOOST_STATIC_ASSERT(!empty<range10>::type::value); -
-BOOST_MPL_ASSERT_IS_SAME(begin<range0>::type, end<range0>::type); -BOOST_MPL_ASSERT_NOT_SAME(begin<range1>::type, end<range1>::type); -BOOST_MPL_ASSERT_NOT_SAME(begin<range10>::type, end<range10>::type); -
-BOOST_STATIC_ASSERT(front<range1>::type::value == 0); -BOOST_STATIC_ASSERT(back<range1>::type::value == 0); -BOOST_STATIC_ASSERT(front<range10>::type::value == 0); -BOOST_STATIC_ASSERT(back<range10>::type::value == 9); -
-
-[1] In fact, the most common application of range_c
class is to simplify the creation of sorted list
or vector
:
-
-
-typedef copy< - range_c<int,0,50> - , push_back<_,_> - , vector<> - >::type numbers; -
-
-Random Access Sequence, vector
, vector_c
, list
, list_c
-
-
-template< - typename IntegerType - , IntegerType N - , IntegerType D = 1 - > -struct rational_c -{ - typedef rational_c<IntegerType, N, D> type; - typedef IntegerType integer_type; - typedef integral_c<IntegerType,N> numerator; - typedef integral_c<IntegerType,D> denominator; --- static double value(); -}; -
-
-
-A model of Rational Constant. -
-
-
-#include "boost/mpl/math/rational_c.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
IntegerType | An integral type | Type used to represent numerator and denominator. |
N | A compile time integral constant of type IntegerType | Value of numerator. |
D | A compile time integral constant of type IntegerType | Value of denominator. |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
rational_c<T,n,d>::value() | double | static_cast<T>(d) != 0 | Returns static_cast<double>(static_cast<T>(n)) / static_cast<T>(d) . |
-
-All operations take amortized constant time. -
-
-
- typedef rational_c<int,1,2> half; - typedef rational_c<int,2,4> half_2; - typedef rational_c<long,9,15> three_fiths_3; - typedef rational_plus<three_fiths,half>::type eleven_tenth; - typedef rational_plus<half,half>::type one; - typedef rational_c<long,1,8> eighth; - typedef rational_minus<half,eighth>::type three_eighths; - typedef rational_multiplies<half,eighth>::type sixteenth; - typedef rational_divides<eighth,half>::type quarter; --
-
-Rational Constant, Integral Constant, integral_c
-
-
-template< - typename Sequence - , typename T - > -struct remove -{ - typedef unspecified type; -}; --
-
-Returns a new sequence which contains all the elements from [begin<Sequence>::type, end<Sequence>::type)
range except those that are identical to T
. The result sequence preserves all the functional and performance characteristics of the original Sequence
, except its size and identity.
-
-
-
-#include "boost/mpl/remove.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Sequence | A model of Extensible Sequence | The original sequence. |
T | A type | A type to be removed. |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef remove<Sequence,T>::type s; | A model of Extensible Sequence | Equivalent to typedef remove_if< Sequence,is_same<_,T> >::type t; . |
-
-Linear. Performs exactly size<Sequence>::type::value
comparisons for equality.
-
-
-
-typedef list<int,float,char,float,float,double>::type types; -typedef remove< types,float >::type result; -typedef list<int,char,double>::type answer; -BOOST_STATIC_ASSERT((equal< result,answer >::type::value)); --
-
-Algorithms, remove_if
, replace
, replace_if
, transform
-
-
-template< - typename Sequence - , typename Pred - > -struct remove_if -{ - typedef unspecified type; -}; --
-
-Returns a new sequence which contains all the elements from [begin<Sequence>::type, end<Sequence>::type)
range except those that satisfy the predicate Pred
. The result sequence preserves all the functional and performance characteristics of the original Sequence
, except its size and identity.
-
-
-
-#include "boost/mpl/remove_if.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Sequence | A model of Extensible Sequence | The original sequence. |
Pred | An unary Predicate [Lambda Expression] | A removal condition. |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef remove_if<Sequence,Pred>::type s; | A model of Extensible Sequence |
-
-Linear. Performs exactly size<Sequence>::type::value
applications of Pred
.
-
-
-
-typedef list_c<int,1,4,5,2,7,5,3,5>::type numbers; -typedef remove_if< numbers, greater<_,4> >::type result; -typedef list_c<int,1,4,2,3>::type answer; -BOOST_STATIC_ASSERT((equal< answer,result,equal_to<_,_> >::type::value)); --
-
-Algorithms, remove
, replace
, transform
-
-
-template< - typename Sequence - , typename OldType - , typename NewType - > -struct replace -{ - typedef unspecified type; -}; --
-
-Performs a replacement operation on the sequence. The algorithm returns a new sequence which contains all the elements from [begin<Sequence>::type, end<Sequence>::type)
range where every type identical to OldType
has been replaced with a NewType
. The result sequence preserves all the functional and performance characteristics of the original Sequence
, including its size, but not identity.
-
-
-
-#include "boost/mpl/replace.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Sequence | A model of Extensible Sequence | The original sequence. |
OldType | A type | A type to be replaced. |
NewType | A type | A type to replace with. |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef replace<Sequence,OldType,NewType>::type s; | A model of Extensible Sequence | Equivalent to typedef replace_if< Sequence,NewType,is_same<_,OldType> >::type t; . |
-
-Linear. Performs exactly size<Sequence>::type::value
comparisons for equality, and at most size<Sequence>::type::value
insertions.
-
-
-
-typedef list<int,float,char,float,float,double>::type types; -typedef replace< types,float,double >::type result; -typedef list<int,double,char,double,double,double>::type answer; -BOOST_STATIC_ASSERT((equal< result,answer >::type::value)); --
-
-Algorithms, replace_if
, transform
-
-
-template< - typename Sequence - , typename Pred - , typename NewType - > -struct replace_if -{ - typedef unspecified type; -}; --
-
-Performs a conditional replacement operation on the sequence. The algorithm returns a new sequence which contains all the elements from [begin<Sequence>::type, end<Sequence>::type)
range where every type that satisfies the predicate Pred
has been replaced with a NewType
. The result sequence preserves all the functional and performance characteristics of the original Sequence
, including its size, but not identity.
-
-
-
-#include "boost/mpl/replace_if.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Sequence | A model of Extensible Sequence | The original sequence. |
Pred | An unary Predicate [Lambda Expression] | The replacement condition. |
NewType | A type | A type to replace with. |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef replace_if<Sequence,Pred,NewType>::type s; | A model of Extensible Sequence | Equivalent to typedef lambda<Pred>::type pred; typedef transform< Sequence, if_< apply1<pred,_1>,NewType,_1> >::type t; . |
-
-Linear. Performs exactly size<Sequence>::type::value
applications of Pred
, and at most size<Sequence>::type::value
insertions.
-
-
-
-typedef list_c<int,1,4,5,2,7,5,3,5>::type numbers; -typedef replace_if< numbers, greater<_,4>, int_<0> >::type result; -typedef list_c<int,1,4,0,2,0,0,3,0>::type answer; -BOOST_STATIC_ASSERT((equal< answer,result >::type::value)); --
-
-Algorithms, replace
, transform
-
-
-template< - typename Sequence - > -struct reverse -{ - typedef implementation-defined type; -}; --
-
-Reverses a sequence. The result sequence preserves all the functional and performance characteristics of the original Sequence
, including its size, but not identity.
-
-
-
-#include "boost/mpl/reverse.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Sequence | A model of Extensible Sequence | The original sequence. |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef reverse<Sequence>::type s; | A model of Extensible Sequence | size<s>::type::value == size<Sequence>::type::value . |
-
-Linear. -
-
-
-typedef list_c<int,9,8,7,6,5,4,3,2,1,0>::type numbers; -typedef reverse< numbers >::type result; ---typedef range_c<int,0,10> answer; -BOOST_STATIC_ASSERT((equal<result,answer>::type::value)); -
-
-Algorithms, transform
, remove
, remove_if
-
-
-template<
- typename T
- >
-struct single_view
-{
- // unspecified
-};
-
--
-Allows one to represent an arbitrary type T
as a single-element sequence.
-
-
-
-#include "boost/mpl/single_view.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
T | A type | The type to be wrapped in a sequence. |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef single_view<T> s; | A model of Sequence | s is a random-access, single-element sequence such as front<s>::type is identical to T | size<s>::type::value == 1, boost::same_as<front<s>::type,T>::value == true . |
-
-Amortized constant time. -
-
-
-typedef single_view<int> view; -typedef begin<view>::type first; -typedef end<view>::type last; ---BOOST_MPL_ASSERT_IS_SAME(first::type,int); -BOOST_MPL_ASSERT_IS_SAME(first::next,last); -BOOST_MPL_ASSERT_IS_SAME(last::prior,first); -
-BOOST_STATIC_ASSERT(size<view>::type::value == 1); -
-
-Sequences, transform_view
, filter_view
, joint_view
, zip_view
-
-
-template< - typename Sequence - > -struct size -{ - typedef unspecified type; -}; --
-
-size
returns the number of elements in the sequence, that is, the number of elements in the range [begin<Sequence>::type,end<Sequence>::type)
.
-
-
-
-#include "boost/mpl/size.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Sequence | A model of Sequence |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef size<Sequence>::type s; | A model of Integral Constant | Equivalent to typedef distance< begin<Sequence>::type,end<Sequence>::type >::type s; | s::value >= 0 |
-
-The complexity of the size
algorithm directly depends on the implementation of the particular sequence it is applied to. In the worst case size
has a linear complexity. As a general rule, if the Sequence
is a Random Access Sequence, you can be certain that size<Sequence>::type
is an amortized constant time operation. The opposite is not necessary true - for example, a model of Forward Sequence still can guarantee you an amortized constant time size
complexity. Please refer the documentation page of the concrete sequence type for further information.
-
-
-
-typedef list0<> empty_list; -typedef vector_c<int,0,1,2,3,4,5> numbers; -typedef range_c<int,0,100> more_numbers; ---BOOST_STATIC_ASSERT(size<list>::type::value == 0); -BOOST_STATIC_ASSERT(size<numbers>::type::value == 5); -BOOST_STATIC_ASSERT(size<more_numbers>::type::value == 100); -
-
-Sequence, empty
, begin
, end
-
-
-template< - typename Sequence - , typename Op - > -struct transform -{ - typedef unspecified type; -}; --
-
-Performs a transformation on the sequence. The algorithm returns a new sequence produced by applying the unary metafunction Op
to every element in the [begin<Sequence>::type, end<Sequence>::type)
range. The result sequence preserves all the functional and performance characteristics of the original Sequence
, including its size, but not identity.
-
-
-
-#include "boost/mpl/transform.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Sequence | A model of Extensible Sequence | The original sequence. |
Op | An unary [Lambda Expression] | A transformation. |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef transform<Sequence,Op>::type s; | A model of Extensible Sequence | size<s>::type::value == size<Sequence>::type::value . |
-
-Linear. The operation Op
is applied exactly size<Sequence>::type::value
times.
-
-
-
-typedef list<char,short,int,long,float,double> types; -typedef list<char*,short*,int*,long*,float*,double*> pointers; -typedef transform< types,boost::add_pointer<_1> >::type result; -BOOST_STATIC_ASSERT((equal<result,pointers>::value)); --
-
-Algorithms, replace
, replace_if
, transform
-
-
-template<
- typename Sequence
- , typename F
- >
-struct transform_view
-{
- // unspecified
-};
-
--
-transform_view
is a sequence wrapper that allows one to operate on the transformed sequence without actually creating one.
-
-
-
-#include "boost/mpl/transform_view.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Sequence | A model of Sequence | A sequence to wrap. |
F | A model of unary [Lambda Expression] | A transformation metafunction. |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef transform_view<Sequence,F> s; | A model of Sequence | s is a sequence such that for each i in [begin<s>::type, end<s>::type) and for each j in [begin<Sequence>::type, end<Sequence>::type) i::type is identical to apply< lambda<F>::type, j::type >::type . | size<Sequence>::type::value == size<s>::type::value . |
-
-Amortized constant time. -
-
-Finds the largest type in a sequence. -
-
-typedef list<int,long,char,char[50],double> types; -typedef max_element< - transform_view< types, size_of<_> > - >::type iter; -BOOST_STATIC_ASSERT(iter::type::value == 50); --
-
-Sequences, filter_view
, joint_view
, zip_view
, max_element
-
-
-template< - typename Sequence - , typename T - , typename Pred = less<_1,_2> - > -struct upper_bound -{ - typedef unspecified type; -}; --
-
-Returns the last position in the sorted Sequence
where T
could be inserted without violating the ordering.
-
-
-
-#include "boost/mpl/upper_bound.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Sequence | A model of Forward Sequence | A sorted sequence. |
T | A type | A type to search the position for. |
Pred | A model of binary Predicate [Lambda Expression] | A sort criteria. |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef upper_bound< Sequence,T,Pred >::type i; | A model of Forward Iterator | i is the furthermost iterator in [begin<Sequence>::type, end<Sequence>::type) such that, for every iterator j in [begin<Sequence>::type, i) , apply< lambda<Pred>::type, T, j::type >::type::value == false . |
-
-The number of comparisons is logarithmic: at most log(size<Sequence>::type::value) + 1
. If Sequence
is a Random Access Sequence then the number of steps through the range is also logarithmic; otherwise, the number of steps is proportional to size<Sequence>::type::value
.
-
-
-
-typedef list_c<int,1,2,3,3,3,5,8> numbers; -typedef upper_bound< numbers, int_<3> >::type iter; -BOOST_STATIC_ASSERT((distance< begin<numbers>::type,iter >::type::value == 5)); -BOOST_STATIC_ASSERT(iter::type::value == 5); --
-
-Algorithms, sort
, lower_bound
-
-
-template< - typename T1 = implementation-defined - , typename T2 = implementation-defined - , ... - , typename Tn = implementation-defined - > -struct vector -{ -}; --
-
-An vector
is a Random Access Sequence of types. It's also an Extensible Sequence that supports constant time insertion and removal of elements at the end (through push_back
), and linear time insertion and removal of elements at the beginning or in the middle (through insert
/erase
algorithms). On compilers that support the typeof extension, vector is the simplest and in many cases the most efficient sequence [1].
-
-
-
-typedef vector<float,double,long double> floats; -typedef push_back<floating_types,my_float>::type ext_floats; -typedef at_c<3,ext_floats>::type my; -BOOST_STATIC_ASSERT((boost::is_same<my,my_float>::value)); --
-
-
-#include "boost/mpl/vector.hpp" -#include "boost/mpl/vector/vector0.hpp" -#include "boost/mpl/vector/vector10.hpp" -... -#include "boost/mpl/vector/vector50.hpp" --
-
-[1] The typeof
operator allows one to use overload resolution to implement a constant-time random access to elements of the sequence with minimum amount of code (in contrast to the usual brute-force approach the library has to resort to when the typeof
operator is not available):
-
-
-struct null_node -{ - static aux::type_wrapper<void_> item(...); -}; ---template< long N, typename T, typename Base > -struct node - : Base -{ - using Base::item; - static aux::type_wrapper<T> item(integral_c<long,N>); -}; -
-template< typename V, long N > -struct at -{ - typedef __typeof__(V::item(integral_c<long,N>())) wrapped_type_; - typedef typename wrapped_type_::type type; -}; -
-typedef node<1,char,node<0,int,null_node> > v; -typedef at<v,0>::type t; // constant-time random access! -BOOST_STATIC_ASSERT((is_same<t,int>::value)); -
-
-Random Access Sequence, vector_c
, list
, list_c
, range_c
-
-
-template< - typename T - , T C1 = implementation-defined - , T C2 = implementation-defined - , ... - , T CN = implementation-defined - > -struct vector_c -{ -}; --
-
-vector_c
is a shorcut interface whose whole purpose is to make the creation of a vector
of Integral Constants less verbose:
-
-
-typedef vector_c<unsigned long,-1,0,1,1,-1,0,0,1,-1> data; --
-If vector_c
didn't exist, instead of the above line you would have to write this:
-
-
-typedef vector< - integral_c<unsigned long,-1> - , integral_c<unsigned long,0> - , integral_c<unsigned long,1> - , integral_c<unsigned long,1> - , integral_c<unsigned long,-1> - , integral_c<unsigned long,0> - , integral_c<unsigned long,0> - , integral_c<unsigned long,1> - , integral_c<unsigned long,-1> - > data; --
-
-
-#include "boost/mpl/vector_c.hpp" -#include "boost/mpl/vector/vector0_c.hpp" -#include "boost/mpl/vector/vector10_c.hpp" -... -#include "boost/mpl/vector/vector50_c.hpp" --
-
-Random Access Sequence, vector
, list
, list_c
, range_c
-
-
-template<
- typename Sequences
- >
-struct zip_view
-{
- // unspecified
-};
-
--
-zip_view
provides a "zipped" view onto several sequences; that is, it allows to represent several sequences as a single sequence of elements each of those, in its turn, is a sequence of the corresponding Sequences
elements.
-
-
-
-#include "boost/mpl/zip_view.hpp" --
-
Parameter | Requirement | Description |
---|---|---|
Sequences | A Sequence of Sequences | Sequences to be "zipped". |
-
-
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef zip_view<Sequences> s; | A model of Sequence | s is a sequence such that for each i in [begin<s>::type, end<s>::type) and for each j in [begin<Sequences>::type, end<Sequences>::type) i::type is identical to transform<j::type, deref<_1> >::type . |
-
-Amortized constant time. -
-
-
-typedef range_c<int,0,10> s1; -typedef range_c<int,10,20> s2; ---typedef transform_view< - zip_view< list<s1,s2> > - , apply_seq< plus<_1,_2> > - > result; -
-BOOST_STATIC_ASSERT((equal< - result - , filter_view< range_c<int,10,30>, math::is_even<_1> > - , equal_to<_1,_2> - >::type::value)); -
-
-Sequences, transform_view
, filter_view
, joint_view
, equal
-
-A Sequence (or, more precisely, an Input Sequence) is a compile-time entity to which you can apply begin
/end
operations in order to get iterators for accessing the range of its elements. In general, a sequence does not guarantee that its content doesn't change from one iteration to another, or between different compilation sessions [1]. See Forward Sequence for the definition of the concept that imposes such additional requirements.
-
-
-
Expression | Expression type |
---|---|
typename begin<s>::type | A model of Input Iterator |
typename end<s>::type | A model of Input Iterator |
-
-See the description of begin/end operations. -
-
-For any sequence s
the following invariants always hold:
-
[begin<s>::type, end<s>::type)
is always a valid range;
-[begin<s>::type, end<s>::type)
will pass through every element of s
(once);
-begin<s>::type
is identical to end<s>::type
if and only if the sequence s
is empty.
--
-
--
-[1] For example, a sequence might implement an interface to a compile-time random-number generator; for such sequence the begin/end
invocation might return different iterators on every subsequent compilation of the code.
-
-
-Sequences, Forward Sequence, Input Iterator, begin
, end
-
-
--
-
-
-
-
-A Trivial Iterator i
is a type that represents a reference to an element of some Sequence, and allows to access the element through its nested type
member [1]. A trivial iterator does not define any traversal operations.
-
-
-
type
member is a well-defined operation.
--
-
Expression | Expression type |
---|---|
typename i::type | A type |
-
-
Expression | Complexity | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typename i::type | Amortized constant time | i is dereferenceable | i::type is identical to the type of the pointed element |
-
-For any trivial iterators i
and j
the following invariants always hold:
-
-
i
and j
are identical if and only if they are pointing to the same element;
-i
is dereferenceable, and j
is identical to i
, then j
is dereferenceable as well;
-i
and j
are identical and dereferenceable, then i::type
and j::type
are identical.
--
-