diff --git a/doc/src/refmanual/ASSERT.rst b/doc/src/refmanual/ASSERT.rst new file mode 100644 index 0000000..5af88a7 --- /dev/null +++ b/doc/src/refmanual/ASSERT.rst @@ -0,0 +1,91 @@ +.. Macros/Asserts//BOOST_MPL_ASSERT + +BOOST_MPL_ASSERT +================ + +Synopsis +-------- + +.. parsed-literal:: + + #define BOOST_MPL_ASSERT( pred ) \\ + |unspecified-token-seq| \\ + /\*\*/ + + +Description +----------- + +Generates a compilation error when the predicate ``pred`` holds false. + + +Header +------ + +.. parsed-literal:: + + #include + + +Parameters +---------- + ++---------------+-----------------------------------+-------------------------------+ +| Parameter | Requirement | Description | ++===============+===================================+===============================+ +| ``pred`` | Boolean nullary |Metafunction| | A predicate to be asserted. | ++---------------+-----------------------------------+-------------------------------+ + + +Expression semantics +-------------------- + +For any boolean nullary |Metafunction| ``pred``: + + +.. parsed-literal:: + + BOOST_MPL_ASSERT(( pred )); + +:Return type: + None. + +:Semantics: + Generates a compilation error if ``pred::type::value != true``, otherwise + has no effect. Note that double parentheses are required even if no commas + appear in the condition. + + When possible within the compiler's diagnostic capabilities, + the error message will include the predicate's full type name, and have a + general form of: + + .. parsed-literal:: + + |...| \*\*\*\*\*\*\*\*\*\*\*\* pred::\*\*\*\*\*\*\*\*\*\*\*\* |...| + + +Example +------- + +:: + + template< typename T, typename U > struct my + { + // ... + BOOST_MPL_ASSERT(( is_same< T,U > )); + }; + + my test; + + // In instantiation of `my': + // instantiated from here + // conversion from ` + // mpl_::failed************boost::is_same::************' to + // non-scalar type `mpl_::assert' requested + + +See also +-------- + +|Asserts|, |BOOST_MPL_ASSERT_NOT|, |BOOST_MPL_ASSERT_MSG|, |BOOST_MPL_ASSERT_RELATION| + diff --git a/doc/src/refmanual/ASSERT_MSG.rst b/doc/src/refmanual/ASSERT_MSG.rst new file mode 100644 index 0000000..2728ad0 --- /dev/null +++ b/doc/src/refmanual/ASSERT_MSG.rst @@ -0,0 +1,129 @@ +.. Macros/Asserts//BOOST_MPL_ASSERT_MSG + +BOOST_MPL_ASSERT_MSG +==================== + +Synopsis +-------- + +.. parsed-literal:: + + #define BOOST_MPL_ASSERT_MSG( condition, message, types ) \\ + |unspecified-token-seq| \\ + /\*\*/ + + +Description +----------- + +Generates a compilation error with an embedded custom message when the condition +doesn't hold. + + +Header +------ + +.. parsed-literal:: + + #include + + +Parameters +---------- + ++---------------+-----------------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===================================+===============================================+ +| ``condition`` | An integral constant expression | A condition to be asserted. | ++---------------+-----------------------------------+-----------------------------------------------+ +| ``message`` | A legal identifier token | A custom message in a form of a legal C++ | +| | | identifier token. | ++---------------+-----------------------------------+-----------------------------------------------+ +| ``types`` | A legal function parameter list | A parenthized list of types to be displayed | +| | | in the error message. | ++---------------+-----------------------------------+-----------------------------------------------+ + + +Expression semantics +-------------------- + +For any integral constant expression ``expr``, legal C++ identifier ``message``, and +arbitrary types ``t1``, ``t2``,... ``tn``: + + +.. parsed-literal:: + + BOOST_MPL_ASSERT_MSG( expr, message, (t1, t2,... tn) ); + +:Return type: + None. + +:Precondition: + ``t1``, ``t2``,... ``tn`` are non-``void``. + +:Semantics: + Generates a compilation error if ``expr::value != true``, otherwise + has no effect. + + When possible within the compiler's diagnostic capabilities, + the error message will include the ``message`` identifier and the parenthized + list of ``t1``, ``t2``,... ``tn`` types, and have a general form of: + + .. parsed-literal:: + + |...| \*\*\*\*\*\*\*\*\*\*\*\*( |...|::message )\*\*\*\*\*\*\*\*\*\*\*\*)(t1, t2,... tn) |...| + + +.. parsed-literal:: + + BOOST_MPL_ASSERT_MSG( expr, message, (types) ); + +:Return type: + None. + +:Precondition: + None. + +:Semantics: + Generates a compilation error if ``expr::value != true``, otherwise + has no effect. + + When possible within the compiler's diagnostics capabilities, + the error message will include the ``message`` identifier and the list of + ``t1``, ``t2``,... ``tn`` types, and have a general form of: + + .. parsed-literal:: + + |...| \*\*\*\*\*\*\*\*\*\*\*\*( |...|::message )\*\*\*\*\*\*\*\*\*\*\*\*)(types) |...| + + +Example +------- + +:: + + template< typename T > struct my + { + // ... + BOOST_MPL_ASSERT_MSG( + is_integral::value + , NON_INTEGRAL_TYPES_ARE_NOT_ALLOWED + , (T) + ); + }; + + my test; + + // In instantiation of `my': + // instantiated from here + // conversion from ` + // mpl_::failed************(my:: + // NON_INTEGRAL_TYPES_ARE_NOT_ALLOWED::************)(void*) + // ' to non-scalar type `mpl_::assert' requested + + +See also +-------- + +|Asserts|, |BOOST_MPL_ASSERT|, |BOOST_MPL_ASSERT_NOT|, |BOOST_MPL_ASSERT_RELATION| + diff --git a/doc/src/refmanual/ASSERT_NOT.rst b/doc/src/refmanual/ASSERT_NOT.rst new file mode 100644 index 0000000..8b4f673 --- /dev/null +++ b/doc/src/refmanual/ASSERT_NOT.rst @@ -0,0 +1,91 @@ +.. Macros/Asserts//BOOST_MPL_ASSERT_NOT + +BOOST_MPL_ASSERT_NOT +==================== + +Synopsis +-------- + +.. parsed-literal:: + + #define BOOST_MPL_ASSERT_NOT( pred ) \\ + |unspecified-token-seq| \\ + /\*\*/ + + +Description +----------- + +Generates a compilation error when predicate holds true. + + +Header +------ + +.. parsed-literal:: + + #include + + +Parameters +---------- + ++---------------+-----------------------------------+-------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===================================+===========================================+ +| ``pred`` | Boolean nullary |Metafunction| | A predicate to be asserted to be false. | ++---------------+-----------------------------------+-------------------------------------------+ + + +Expression semantics +-------------------- + +For any boolean nullary |Metafunction| ``pred``: + + +.. parsed-literal:: + + BOOST_MPL_ASSERT_NOT(( pred )); + +:Return type: + None. + +:Semantics: + Generates a compilation error if ``pred::type::value != false``, otherwise + has no effect. Note that double parentheses are required even if no commas + appear in the condition. + + When possible within the compiler's diagnostic capabilities, + the error message will include the predicate's full type name, and have a + general form of: + + .. parsed-literal:: + + |...| \*\*\*\*\*\*\*\*\*\*\*\*boost::mpl::not_< pred >::\*\*\*\*\*\*\*\*\*\*\*\* |...| + + +Example +------- + +:: + + template< typename T, typename U > struct my + { + // ... + BOOST_MPL_ASSERT_NOT(( is_same< T,U > )); + }; + + my test; + + // In instantiation of `my': + // instantiated from here + // conversion from ` + // mpl_::failed************boost::mpl::not_ + // >::************' to non-scalar type `mpl_::assert' requested + + +See also +-------- + +|Asserts|, |BOOST_MPL_ASSERT|, |BOOST_MPL_ASSERT_MSG|, |BOOST_MPL_ASSERT_RELATION| + diff --git a/doc/src/refmanual/ASSERT_RELATION.rst b/doc/src/refmanual/ASSERT_RELATION.rst new file mode 100644 index 0000000..9828b81 --- /dev/null +++ b/doc/src/refmanual/ASSERT_RELATION.rst @@ -0,0 +1,98 @@ +.. Macros/Asserts//BOOST_MPL_ASSERT_RELATION + +BOOST_MPL_ASSERT_RELATION +========================= + +Synopsis +-------- + +.. parsed-literal:: + + #define BOOST_MPL_ASSERT_RELATION( x, relation, y ) \\ + |unspecified-token-seq| \\ + /\*\*/ + + + +Description +----------- + +A specialized assertion macro for checking numerical conditions. Generates +a compilation error when the condition ``( x relation y )`` +doesn't hold. + + +Header +------ + +.. parsed-literal:: + + #include + + +Parameters +---------- + ++---------------+-----------------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===================================+===============================================+ +| ``x`` | An integral constant | Left operand of the checked relation. | ++---------------+-----------------------------------+-----------------------------------------------+ +| ``y`` | An integral constant | Right operand of the checked relation. | ++---------------+-----------------------------------+-----------------------------------------------+ +| ``relation`` | A C++ operator token | An operator token for the relation being | +| | | checked. | ++---------------+-----------------------------------+-----------------------------------------------+ + + +Expression semantics +-------------------- + +For any integral constants ``x``, ``y`` and a legal C++ operator token ``op``: + + +.. parsed-literal:: + + BOOST_MPL_ASSERT_RELATION( x, op, y ); + +:Return type: + None. + +:Semantics: + Generates a compilation error if ``( x op y ) != true``, otherwise + has no effect. + + When possible within the compiler's diagnostic capabilities, + the error message will include a name of the relation being checked, + the actual values of both operands, and have a general form of: + + .. parsed-literal:: + + |...| \*\*\*\*\*\*\*\*\*\*\*\*\ |...|\ assert_relation::\*\*\*\*\*\*\*\*\*\*\*\*) |...| + + +Example +------- + +:: + + template< typename T, typename U > struct my + { + // ... + BOOST_MPL_ASSERT_RELATION( sizeof(T), <, sizeof(U) ); + }; + + my test; + + // In instantiation of `my': + // instantiated from here + // conversion from ` + // mpl_::failed************mpl_::assert_relation::************' + // to non-scalar type `mpl_::assert' requested + + +See also +-------- + +|Asserts|, |BOOST_MPL_ASSERT|, |BOOST_MPL_ASSERT_NOT|, |BOOST_MPL_ASSERT_MSG| + diff --git a/doc/src/refmanual/AUX_LAMBDA_SUPPORT.rst b/doc/src/refmanual/AUX_LAMBDA_SUPPORT.rst new file mode 100644 index 0000000..b45b36d --- /dev/null +++ b/doc/src/refmanual/AUX_LAMBDA_SUPPORT.rst @@ -0,0 +1,101 @@ +.. Macros/Broken Compiler Workarounds//BOOST_MPL_AUX_LAMBDA_SUPPORT + +BOOST_MPL_AUX_LAMBDA_SUPPORT +============================ + +Synopsis +-------- + +.. parsed-literal:: + + #define BOOST_MPL_AUX_LAMBDA_SUPPORT(arity, fun, params) \\ + |unspecified-token-seq| \\ + /\*\*/ + + + +Description +----------- + +Enables metafunction ``fun`` for the use in |Lambda Expression|\ s on +compilers that don't support partial template specialization or/and +template template parameters. Expands to nothing on conforming compilers. + + +Header +------ + +.. parsed-literal:: + + #include + + +Parameters +---------- + ++---------------+-------------------------------+---------------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===============================+===================================================+ +| ``arity`` | An integral constant | The metafunction's arity, i.e. the number of its | +| | | template parameters, including the defaults. | ++---------------+-------------------------------+---------------------------------------------------+ +| ``fun`` | A legal identifier token | The metafunction's name. | ++---------------+-------------------------------+---------------------------------------------------+ +| ``params`` | A |PP-tuple| | A tuple of the metafunction's parameter names, in | +| | | their original order, including the defaults. | ++---------------+-------------------------------+---------------------------------------------------+ + + +Expression semantics +-------------------- + +For any integral constant ``n``, a |Metafunction| ``fun``, and arbitrary types |A1...An|: + + +.. parsed-literal:: + + template< typename A1,\ |...| typename A\ *n* > struct fun + { + // |...| + + BOOST_MPL_AUX_LAMBDA_SUPPORT(n, fun, (A1,\ |...|\ A\ *n*\ )) + }; + +:Precondition: + Appears in ``fun``\ 's scope, immediately followed by the scope-closing + bracket (``}``). + +:Return type: + None. + +:Semantics: + Expands to nothing and has no effect on conforming compilers. On compilers that + don't support partial template specialization or/and template template parameters + expands to an unspecified token sequence enabling ``fun`` to participate in + |Lambda Expression|\ s with the semantics described in this manual. + + +Example +------- + +.. parsed-literal:: + + template< typename T, typename U = int > struct f + { + typedef T type[sizeof(U)]; + + BOOST_MPL_AUX_LAMBDA_SUPPORT(2, f, (T,U)) + }; + + typedef apply\ ``1``\< f,long >::type r; + BOOST_MPL_ASSERT(( is_same< r, char[sizeof(long)] > )); + + +See also +-------- + +|Macros|, |Metafunctions|, |Lambda Expression| + + +.. |PP-tuple| replace:: `PP-tuple`__ +__ http://www.boost.org/libs/preprocessor/doc/data/tuples.html diff --git a/doc/src/refmanual/Acknowledgements.rst b/doc/src/refmanual/Acknowledgements.rst new file mode 100644 index 0000000..d4f3b75 --- /dev/null +++ b/doc/src/refmanual/Acknowledgements.rst @@ -0,0 +1,6 @@ + +The format and language of this reference documentation has been greatly influenced by +the SGI's `Standard Template Library Programmer's Guide`__. + +__ http://www.sgi.com/tech/stl/ + \ No newline at end of file diff --git a/doc/src/refmanual/Algorithms-Iteration.rst b/doc/src/refmanual/Algorithms-Iteration.rst new file mode 100644 index 0000000..a3b7a93 --- /dev/null +++ b/doc/src/refmanual/Algorithms-Iteration.rst @@ -0,0 +1,19 @@ + +Iteration algorithms are the basic building blocks behind many of the +MPL's algorithms, and are usually the first place to look at when +starting to build a new one. Abstracting away the details of sequence +iteration and employing various optimizations such as recursion +unrolling, they provide significant advantages over a hand-coded +approach. + +.. Of all of iteration algorithms, ``iter_fold_if`` is the + most complex and at the same time the most fundamental. The rest of + the algorithms from the category |--| ``iter_fold``, ``reverse_iter_fold``, + ``fold``, and ``reverse_fold`` |--| simply provide a more high-level + (and more restricted) interface to the core ``iter_fold_if`` + functionality [#performace]_. + + .. [#performace] That's not to say that they are *implemented* + through ``iter_fold_if`` |--| they are often not, in particular + because the restricted functionality allows for more + optimizations. diff --git a/doc/src/refmanual/Algorithms-Querying.rst b/doc/src/refmanual/Algorithms-Querying.rst new file mode 100644 index 0000000..d1cf8e8 --- /dev/null +++ b/doc/src/refmanual/Algorithms-Querying.rst @@ -0,0 +1,2 @@ + +.. |Querying Algorithms| replace:: `Querying Algorithms`_ diff --git a/doc/src/refmanual/Algorithms-Transformation.rst b/doc/src/refmanual/Algorithms-Transformation.rst new file mode 100644 index 0000000..1c41029 --- /dev/null +++ b/doc/src/refmanual/Algorithms-Transformation.rst @@ -0,0 +1,24 @@ + +According to their name, MPL's *transformation*, or *sequence-building +algorithms* provide the tools for building new sequences from the existing +ones by performing some kind of transformation. A typical transformation +alogrithm takes one or more input sequences and a transformation +metafunction/predicate, and returns a new sequence built according to the +algorithm's semantics through the means of its |Inserter| argument, which +plays a role similar to the role of run-time |Output Iterator|. + +.. Say something about optionality of Inserters/their default behavior + +Every transformation algorithm is a |Reversible Algorithm|, providing +an accordingly named ``reverse_`` counterpart carrying the transformation +in the reverse order. Thus, all sequence-building algorithms come in pairs, +for instance ``replace`` / ``reverse_replace``. In presence of variability of +the output sequence's properties such as front or backward extensibility, +the existence of the bidirectional algorithms allows for the most efficient +way to perform the required transformation. + +.. |Transformation Algorithms| replace:: `Transformation Algorithms`_ + +.. |transformation algorithm| replace:: `transformation algorithm`_ +.. _transformation algorithm: `Transformation Algorithms`_ +.. |transformation algorithms| replace:: `transformation algorithms`_ diff --git a/doc/src/refmanual/Algorithms.rst b/doc/src/refmanual/Algorithms.rst new file mode 100644 index 0000000..30dcec7 --- /dev/null +++ b/doc/src/refmanual/Algorithms.rst @@ -0,0 +1,40 @@ + +The MPL provides a broad range of fundamental algorithms aimed to +satisfy the majority of sequential compile-time data processing +needs. The algorithms include compile-time counterparts +of many of the STL algorithms, iteration algorithms borrowed from +functional programming languages, and more. + +Unlike the algorithms in the C++ Standard Library, which operate on +implict *iterator ranges*, the majority of MPL counterparts take +and return *sequences*. This derivation is not dictated by the +functional nature of C++ compile-time computations per se, but +rather by a desire to improve general usability of the library, +making programming with compile-time data structures as enjoyable +as possible. + +.. This can be seen as a further generalization and extension of + the STL's conceptual framework. + +In the spirit of the STL, MPL algorithms are *generic*, meaning +that they are not tied to particular sequence class +implementations, and can operate on a wide range of arguments as +long as they satisfy the documented requirements. The requirements +are formulated in terms of concepts. Under the hood, +algorithms are decoupled from concrete sequence +implementations by operating on |iterators|. + +All MPL algorithms can be sorted into three +major categories: iteration algorithms, querying algorithms, and +transformation algorithms. The transformation algorithms introduce +an associated |Inserter| concept, a rough equivalent for the notion of +|Output Iterator| in the Standard Library. Moreover, every +transformation algorithm provides a ``reverse_`` counterpart, +allowing for a wider range of efficient transformations |--| a +common functionality documented by the |Reversible Algorithm| +concept. + + +.. |Output Iterator| replace:: `Output Iterator `_ +.. |sequence algorithms| replace:: `sequence algorithms`__ +__ `Algorithms`_ diff --git a/doc/src/refmanual/AssociativeSequence.rst b/doc/src/refmanual/AssociativeSequence.rst new file mode 100644 index 0000000..ddd99a0 --- /dev/null +++ b/doc/src/refmanual/AssociativeSequence.rst @@ -0,0 +1,116 @@ +.. Sequences/Concepts//Associative Sequence |70 + +Associative Sequence +==================== + +Description +----------- + +An |Associative Sequence| is a |Forward Sequence| that allows efficient retrieval of +elements based on keys. Unlike associative containers in the C++ Standard Library, +MPL associative sequences have no associated ordering relation. Instead, +*type identity* is used to impose an equivalence relation on keys, and the +order in which sequence elements are traversed during iteration is left +unspecified. + + +Definitions +----------- + +.. _`key-part`: + +.. _`value-part`: + +* A *key* is a part of the element type used to identify and retrieve + the element within the sequence. + +* A *value* is a part of the element type retrievied from the sequence + by its key. + + +Expression requirements +----------------------- + +|In the following table...| ``s`` is an |Associative Sequence|, +``x`` is a sequence element, and ``k`` and ``def`` are arbitrary types. + +In addition to the requirements defined in |Forward Sequence|, +the following must be met: + ++-------------------------------+-----------------------------------+---------------------------+ +| Expression | Type | Complexity | ++===============================+===================================+===========================+ +| ``has_key::type`` | Boolean |Integral Constant| | Amortized constant time | ++-------------------------------+-----------------------------------+---------------------------+ +| ``count::type`` | |Integral Constant| | Amortized constant time | ++-------------------------------+-----------------------------------+---------------------------+ +| ``order::type`` | |Integral Constant| or ``void_`` | Amortized constant time | ++-------------------------------+-----------------------------------+---------------------------+ +| ``at::type`` | Any type | Amortized constant time | ++-------------------------------+-----------------------------------+---------------------------+ +| ``at::type`` | Any type | Amortized constant time | ++-------------------------------+-----------------------------------+---------------------------+ +| ``key_type::type`` | Any type | Amortized constant time | ++-------------------------------+-----------------------------------+---------------------------+ +| ``value_type::type`` | Any type | Amortized constant time | ++-------------------------------+-----------------------------------+---------------------------+ + + +Expression semantics +-------------------- + +|Semantics disclaimer...| |Forward Sequence|. + ++-------------------------------+---------------------------------------------------------------+ +| Expression | Semantics | ++===============================+===============================================================+ +| ``has_key::type`` | |true if and only if| there is one or more | +| | elements with the key ``k`` in ``s``; see |has_key|. | ++-------------------------------+---------------------------------------------------------------+ +| ``count::type`` | The number of elements with the key ``k`` in ``s``; | +| | see |count|. | ++-------------------------------+---------------------------------------------------------------+ +| ``order::type`` | A unique unsigned |Integral Constant| associated | +| | with the key ``k`` in the sequence ``s``; see |order|. | ++-------------------------------+---------------------------------------------------------------+ +| .. parsed-literal:: | The first element associated with the key ``k`` | +| | in the sequence ``s``; see |at|. | +| at::type | | +| at::type | | ++-------------------------------+---------------------------------------------------------------+ +| ``key_type::type`` | The key part of the element ``x`` that would be | +| | used to identify ``x`` in ``s``; see |key_type|. | ++-------------------------------+---------------------------------------------------------------+ +| ``value_type::type`` | The value part of the element ``x`` that would be | +| | used for ``x`` in ``s``; see |value_type|. | ++-------------------------------+---------------------------------------------------------------+ + + +.. Invariants + ---------- + + For any associative sequence ``s`` the following invariants always hold: + + * ??? + + +Models +------ + +* |set| +* |map| + +.. * |multiset| + + +See also +-------- + +|Sequences|, |Extensible Associative Sequence|, |has_key|, |count|, |order|, |at|, |key_type|, |value_type| + + +.. |key| replace:: `key`__ +__ `key-part`_ + +.. |value| replace:: `value`__ +__ `value-part`_ diff --git a/doc/src/refmanual/BackExtensibleSequence.rst b/doc/src/refmanual/BackExtensibleSequence.rst new file mode 100644 index 0000000..b598d9b --- /dev/null +++ b/doc/src/refmanual/BackExtensibleSequence.rst @@ -0,0 +1,64 @@ +.. Sequences/Concepts//Back Extensible Sequence |60 + +Back Extensible Sequence +======================== + +Description +----------- + +A |Back Extensible Sequence| is an |Extensible Sequence| that supports amortized constant +time insertion and removal operations at the end. + +Refinement of +------------- + +|Extensible Sequence| + + +Expression requirements +----------------------- + +In addition to the requirements defined in |Extensible Sequence|, +for any |Back Extensible Sequence| ``s`` the following must be met: + ++-------------------------------+-------------------------------+---------------------------+ +| Expression | Type | Complexity | ++===============================+===============================+===========================+ +| ``push_back::type`` | |Back Extensible Sequence| | Amortized constant time | ++-------------------------------+-------------------------------+---------------------------+ +| ``pop_back::type`` | |Back Extensible Sequence| | Amortized constant time | ++-------------------------------+-------------------------------+---------------------------+ +| ``back::type`` | Any type | Amortized constant time | ++-------------------------------+-------------------------------+---------------------------+ + + +Expression semantics +-------------------- + +|Semantics disclaimer...| |Extensible Sequence|. + ++-------------------------------+-----------------------------------------------------------+ +| Expression | Semantics | ++===============================+===========================================================+ +| ``push_back::type`` | Equivalent to ``insert::type,x>::type``; | +| | see |push_back|. | ++-------------------------------+-----------------------------------------------------------+ +| ``pop_back::type`` | Equivalent to ``erase::type>::type``; | +| | see |pop_back|. | ++-------------------------------+-----------------------------------------------------------+ +| ``back::type`` | The last element in the sequence; see |back|. | ++-------------------------------+-----------------------------------------------------------+ + + +Models +------ + +* |vector| +* |deque| + + +See also +-------- + +|Sequences|, |Extensible Sequence|, |Front Extensible Sequence|, |push_back|, |pop_back|, |back| + diff --git a/doc/src/refmanual/BidirectionalIterator.rst b/doc/src/refmanual/BidirectionalIterator.rst new file mode 100644 index 0000000..9ae6ee7 --- /dev/null +++ b/doc/src/refmanual/BidirectionalIterator.rst @@ -0,0 +1,77 @@ +.. Iterators/Concepts//Bidirectional Iterator |20 + +Bidirectional Iterator +====================== + +Description +----------- + +A |Bidirectional Iterator| is a |Forward Iterator| that provides a way to +obtain an iterator to the previous element in a sequence. + +Refinement of +------------- + +|Forward Iterator| + +Definitions +----------- + +* a bidirectional iterator ``i`` is `decrementable` if there is a "previous" + iterator, that is, if ``prior::type`` expression is well-defined; + iterators pointing to the first element of the sequence are not + decrementable. + + +Expression requirements +----------------------- + +In addition to the requirements defined in |Forward Iterator|, +the following requirements must be met. + ++-----------------------+-------------------------------------------+---------------------------+ +| Expression | Type | Complexity | ++=======================+===========================================+===========================+ +| ``next::type`` | |Bidirectional Iterator| | Amortized constant time | ++-----------------------+-------------------------------------------+---------------------------+ +| ``prior::type`` | |Bidirectional Iterator| | Amortized constant time | ++-----------------------+-------------------------------------------+---------------------------+ +| ``i::category`` | |Integral Constant|, convertible | Constant time | +| | to ``bidirectional_iterator_tag`` | | ++-----------------------+-------------------------------------------+---------------------------+ + + +Expression semantics +-------------------- + +.. parsed-literal:: + + typedef prior::type j; + +:Precondition: + ``i`` is decrementable + +:Semantics: + ``j`` is an iterator pointing to the previous element of the + sequence + +:Postcondition: + ``j`` is dereferenceable and incrementable + + +Invariants +---------- + +For any bidirectional iterators ``i`` and ``j`` the following invariants +always hold: + +* If ``i`` is incrementable, then ``prior< next::type >::type`` is a null + operation; similarly, if ``i`` is decrementable, ``next< prior::type >::type`` + is a null operation. + + +See also +-------- + +|Iterators|, |Forward Iterator|, |Random Access Iterator|, |Bidirectional Sequence|, |prior| + diff --git a/doc/src/refmanual/BidirectionalSequence.rst b/doc/src/refmanual/BidirectionalSequence.rst new file mode 100644 index 0000000..e48886d --- /dev/null +++ b/doc/src/refmanual/BidirectionalSequence.rst @@ -0,0 +1,58 @@ +.. Sequences/Concepts//Bidirectional Sequence |20 + +Bidirectional Sequence +====================== + +Description +----------- + +A |Bidirectional Sequence| is a |Forward Sequence| whose iterators model +|Bidirectional Iterator|. + +Refinement of +------------- + +|Forward Sequence| + + +Expression requirements +----------------------- + +In addition to the requirements defined in |Forward Sequence|, +for any |Bidirectional Sequence| ``s`` the following must be met: + ++---------------------------+-----------------------------------+---------------------------+ +| Expression | Type | Complexity | ++===========================+===================================+===========================+ +| ``begin::type`` | |Bidirectional Iterator| | Amortized constant time | ++---------------------------+-----------------------------------+---------------------------+ +| ``end::type`` | |Bidirectional Iterator| | Amortized constant time | ++---------------------------+-----------------------------------+---------------------------+ +| ``back::type`` | Any type | Amortized constant time | ++---------------------------+-----------------------------------+---------------------------+ + + +Expression semantics +-------------------- + +|Semantics disclaimer...| |Forward Sequence|. + ++---------------------------+-----------------------------------------------------------------------+ +| Expression | Semantics | ++===========================+=======================================================================+ +| ``back::type`` | The last element in the sequence; see |back|. | ++---------------------------+-----------------------------------------------------------------------+ + + +Models +------ + +* |vector| +* |range_c| + + +See also +-------- + +|Sequences|, |Forward Sequence|, |Random Access Sequence|, |Bidirectional Iterator|, |begin| / |end|, |back| + diff --git a/doc/src/refmanual/CFG_NO_HAS_XXX.rst b/doc/src/refmanual/CFG_NO_HAS_XXX.rst new file mode 100644 index 0000000..ffb2cff --- /dev/null +++ b/doc/src/refmanual/CFG_NO_HAS_XXX.rst @@ -0,0 +1,27 @@ +.. Macros/Configuration//BOOST_MPL_CFG_NO_HAS_XXX |20 + +BOOST_MPL_CFG_NO_HAS_XXX +======================== + +Synopsis +-------- + +.. parsed-literal:: + + // #define BOOST_MPL_CFG_NO_HAS_XXX + + +Description +----------- + +``BOOST_MPL_CFG_NO_HAS_XXX`` is an boolean configuration macro +signaling availability of the |BOOST_MPL_HAS_XXX_TRAIT_DEF| / +|BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF| introspection macros' functionality +on a particular compiler. + + +See also +-------- + +|Macros|, |Configuration|, |BOOST_MPL_HAS_XXX_TRAIT_DEF|, |BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF| + diff --git a/doc/src/refmanual/CFG_NO_PREPROCESSED.rst b/doc/src/refmanual/CFG_NO_PREPROCESSED.rst new file mode 100644 index 0000000..5f3be39 --- /dev/null +++ b/doc/src/refmanual/CFG_NO_PREPROCESSED.rst @@ -0,0 +1,39 @@ +.. Macros/Configuration//BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS |10 + +BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS +===================================== +.. _`BOOST_MPL_CFG_NO_PREPROCESSED`: + +Synopsis +-------- + +.. parsed-literal:: + + // #define BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS + + +Description +----------- + +``BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS`` is an boolean configuration macro +regulating library's internal use of preprocessed headers. When defined, it +instructs the MPL to discard the pre-generated headers found in +``boost/mpl/aux_/preprocessed`` directory and use `preprocessor +metaprogramming`__ techniques to generate the necessary versions of the +library components on the fly. + +In this implementation of the library, the macro is not defined by default. +To change the default configuration, define +``BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS`` before including any library +header. + +__ http://boost-consulting.com/tmpbook/preprocessor.html + + +See also +-------- + +|Macros|, |Configuration| + +.. |preprocessed headers| replace:: `preprocessed headers`__ +__ `BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS`_ diff --git a/doc/src/refmanual/Categorized.rst b/doc/src/refmanual/Categorized.rst new file mode 100644 index 0000000..8ea4f76 --- /dev/null +++ b/doc/src/refmanual/Categorized.rst @@ -0,0 +1,12 @@ + +.. _`Categorized`: + +Concepts +//////// + +.. include:: concepts.gen + +Components +////////// + +.. include:: index.gen diff --git a/doc/src/refmanual/Data.Integral.rst b/doc/src/refmanual/Data.Integral.rst new file mode 100644 index 0000000..09e07e0 --- /dev/null +++ b/doc/src/refmanual/Data.Integral.rst @@ -0,0 +1,5 @@ + +.. |Integral Constants| replace:: `Integral Constants`_ + +.. |integral constants| replace:: `integral constants`__ +__ `Integral Constants`_ diff --git a/doc/src/refmanual/Data.rst b/doc/src/refmanual/Data.rst new file mode 100644 index 0000000..fb0775c --- /dev/null +++ b/doc/src/refmanual/Data.rst @@ -0,0 +1,4 @@ + +.. _`Data`: + +.. |Data Types| replace:: `Data Types`_ diff --git a/doc/src/refmanual/ExtensibleAssociativeSequence.rst b/doc/src/refmanual/ExtensibleAssociativeSequence.rst new file mode 100644 index 0000000..d0c26cd --- /dev/null +++ b/doc/src/refmanual/ExtensibleAssociativeSequence.rst @@ -0,0 +1,87 @@ +.. Sequences/Concepts//Extensible Associative Sequence |80 + +Extensible Associative Sequence +=============================== + +Description +----------- + +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. + + +Expression requirements +----------------------- + +|In the following table...| ``s`` is an |Associative Sequence|, +``pos`` is an iterator into ``s``, and ``x`` and ``k`` are arbitrary types. + +In addition to the |Associative Sequence| requirements, the following must be met: + ++-------------------------------+---------------------------------------+---------------------------+ +| Expression | Type | Complexity | ++===============================+=======================================+===========================+ +| ``insert::type`` | |Extensible Associative Sequence| | Amortized constant time | ++-------------------------------+---------------------------------------+---------------------------+ +| ``insert::type`` | |Extensible Associative Sequence| | Amortized constant time | ++-------------------------------+---------------------------------------+---------------------------+ +| ``erase_key::type`` | |Extensible Associative Sequence| | Amortized constant time | ++-------------------------------+---------------------------------------+---------------------------+ +| ``erase::type`` | |Extensible Associative Sequence| | Amortized constant time | ++-------------------------------+---------------------------------------+---------------------------+ +| ``clear::type`` | |Extensible Associative Sequence| | Amortized constant time | ++-------------------------------+---------------------------------------+---------------------------+ + + +Expression semantics +-------------------- + +|Semantics disclaimer...| |Associative Sequence|. + ++-------------------------------+-------------------------------------------------------------------+ +| Expression | Semantics | ++===============================+===================================================================+ +| ``insert::type`` | Inserts ``x`` into ``s``; the resulting sequence ``r`` is | +| | equivalent to ``s`` except that | +| | :: | +| | | +| | at< r, key_type::type >::type | +| | | +| | is identical to ``value_type::type``; see |insert|. | ++-------------------------------+-------------------------------------------------------------------+ +| ``insert::type`` | Equivalent to ``insert::type``; ``pos`` is ignored; | +| | see |insert|. | ++-------------------------------+-------------------------------------------------------------------+ +| ``erase_key::type`` | Erases elements in ``s`` associated with the key ``k``; | +| | the resulting sequence ``r`` is equivalent to ``s`` except | +| | that ``has_key::value == false``; see |erase_key|. | ++-------------------------------+-------------------------------------------------------------------+ +| ``erase::type`` | Erases the element at a specific position; equivalent to | +| | ``erase_key::type >::type``; see |erase|. | ++-------------------------------+-------------------------------------------------------------------+ +| ``clear::type`` | An empty sequence concept-identical to ``s``; see | +| | |clear|. | ++-------------------------------+-------------------------------------------------------------------+ + +.. Invariants + ---------- + + For any extensible associative sequence ``s`` the following invariants always hold: + + +Models +------ + +* |set| +* |map| + +.. * |multiset| + + +See also +-------- + +|Sequences|, |Associative Sequence|, |insert|, |erase|, |clear| + diff --git a/doc/src/refmanual/ExtensibleSequence.rst b/doc/src/refmanual/ExtensibleSequence.rst new file mode 100644 index 0000000..d2cc1d1 --- /dev/null +++ b/doc/src/refmanual/ExtensibleSequence.rst @@ -0,0 +1,77 @@ +.. Sequences/Concepts//Extensible Sequence |40 + +Extensible Sequence +=================== + +Description +----------- + +An |Extensible Sequence| is a sequence that supports insertion and removal of +elements. Extensibility is orthogonal to sequence traversal characteristics. + + +Expression requirements +----------------------- + +For any |Extensible Sequence| ``s``, its iterators ``pos`` and ``last``, +|Forward Sequence| ``r``, and any type ``x``, the following expressions must +be valid: + ++-----------------------------------+---------------------------+---------------------------+ +| Expression | Type | Complexity | ++===================================+===========================+===========================+ +| ``insert::type`` | |Extensible Sequence| | Unspecified | ++-----------------------------------+---------------------------+---------------------------+ +| ``insert_range::type`` | |Extensible Sequence| | Unspecified | ++-----------------------------------+---------------------------+---------------------------+ +| ``erase::type`` | |Extensible Sequence| | Unspecified | ++-----------------------------------+---------------------------+---------------------------+ +| ``erase::type`` | |Extensible Sequence| | Unspecified | ++-----------------------------------+---------------------------+---------------------------+ +| ``clear::type`` | |Extensible Sequence| | Constant time | ++-----------------------------------+---------------------------+---------------------------+ + +Expression semantics +-------------------- + ++-----------------------------------+---------------------------------------------------------------+ +| Expression | Semantics | ++===================================+===============================================================+ +| ``insert::type`` | A new sequence, concept-identical to ``s``, of | +| | the following elements: | +| | [``begin::type``, ``pos``), ``x``, | +| | [``pos``, ``end::type``); see |insert|. | ++-----------------------------------+---------------------------------------------------------------+ +| ``insert_range::type`` | A new sequence, concept-identical to ``s``, of | +| | the following elements: | +| | [``begin::type``, ``pos``), | +| | [``begin::type``, ``end::type``), | +| | [``pos``, ``end::type``); see |insert_range|. | ++-----------------------------------+---------------------------------------------------------------+ +| ``erase::type`` | A new sequence, concept-identical to ``s``, of | +| | the following elements: | +| | [``begin::type``, ``pos``), | +| | [``next::type``, ``end::type``); see |erase|. | ++-----------------------------------+---------------------------------------------------------------+ +| ``erase::type`` | A new sequence, concept-identical to ``s``, of | +| | the following elements: | +| | [``begin::type``, ``pos``), | +| | [``last``, ``end::type``); see |erase|. | ++-----------------------------------+---------------------------------------------------------------+ +| ``clear::type`` | An empty sequence concept-identical to ``s``; see | +| | |clear|. | ++-----------------------------------+---------------------------------------------------------------+ + + +Models +------ + +* |vector| +* |list| + + +See also +-------- + +|Sequences|, |Back Extensible Sequence|, |insert|, |insert_range|, |erase|, |clear| + diff --git a/doc/src/refmanual/ForwardIterator.rst b/doc/src/refmanual/ForwardIterator.rst new file mode 100644 index 0000000..fd30f24 --- /dev/null +++ b/doc/src/refmanual/ForwardIterator.rst @@ -0,0 +1,125 @@ +.. Iterators/Concepts//Forward Iterator |10 + +Forward Iterator +================ + +Description +----------- + +A |Forward Iterator| ``i`` is a type that represents a positional reference +to an element of a |Forward Sequence|. It allows to access the element through +a dereference operation, and provides a way to obtain an iterator to +the next element in a sequence. + +.. A [Forward Iterator] guarantees a linear traversal over + the sequence. + + +Definitions +----------- + +* An iterator can be `dereferenceable`, meaning that ``deref::type`` + is a well-defined expression. + +* An iterator is `past-the-end` if it points beyond the last element of a + sequence; past-the-end iterators are non-dereferenceable. + +* An iterator ``i`` is `incrementable` if there is a "next" iterator, that + is, if ``next::type`` expression is well-defined; past-the-end iterators are + not incrementable. + +* Two iterators into the same sequence are `equivalent` if they have the same + type. + +* An iterator ``j`` is `reachable` from an iterator ``i`` if , after recursive + application of ``next`` metafunction to ``i`` a finite number of times, ``i`` + is equivalent to ``j``. + +* The notation [``i``,\ ``j``) refers to a `range` of iterators beginning with + ``i`` and up to but not including ``j``. + +* The range [``i``,\ ``j``) is a `valid range` if ``j`` is reachable from ``i``. + + +Expression requirements +----------------------- + ++-----------------------+-------------------------------------------+---------------------------+ +| Expression | Type | Complexity | ++=======================+===========================================+===========================+ +| ``deref::type`` | Any type | Amortized constant time | ++-----------------------+-------------------------------------------+---------------------------+ +| ``next::type`` | |Forward Iterator| | Amortized constant time | ++-----------------------+-------------------------------------------+---------------------------+ +| ``i::category`` | |Integral Constant|, convertible | Constant time | +| | to ``forward_iterator_tag`` | | ++-----------------------+-------------------------------------------+---------------------------+ + + +Expression semantics +-------------------- + + +.. parsed-literal:: + + typedef deref::type j; + +:Precondition: + ``i`` is dereferenceable + +:Semantics: + ``j`` is identical to the type of the pointed element + + +.. .......................................................................... + +.. parsed-literal:: + + typedef next::type j; + +:Precondition: + ``i`` is incrementable + +:Semantics: + ``j`` is the next iterator in a sequence + +:Postcondition: + ``j`` is dereferenceable or past-the-end + + +.. .......................................................................... + +.. parsed-literal:: + + typedef i::category c; + +:Semantics: + ``c`` is identical to the iterator's category tag + + +Invariants +---------- + +For any forward iterators ``i`` and ``j`` the following invariants always hold: + +* ``i`` and ``j`` are equivalent if and only if they are pointing to the same + element. + +* If ``i`` is dereferenceable, and ``j`` is equivalent to ``i``, then ``j`` is + dereferenceable as well. + +* If ``i`` and ``j`` are equivalent and dereferenceable, then ``deref::type`` + and ``deref::type`` are identical. + +* If ``i`` is incrementable, and ``j`` is equivalent to ``i``, then ``j`` is + incrementable as well. + +* If ``i`` and ``j`` are equivalent and incrementable, then ``next::type`` + and ``next::type`` are equivalent. + + +See also +-------- + +|Iterators|, |Bidirectional Iterator|, |Forward Sequence|, |deref|, |next| + diff --git a/doc/src/refmanual/ForwardSequence.rst b/doc/src/refmanual/ForwardSequence.rst new file mode 100644 index 0000000..c4b1ce6 --- /dev/null +++ b/doc/src/refmanual/ForwardSequence.rst @@ -0,0 +1,91 @@ +.. Sequences/Concepts//Forward Sequence |10 + +Forward Sequence +================ + +Description +----------- + +A |Forward Sequence| is an MPL concept representing a compile-time sequence of +elements. Sequence elements are +types, and are accessible through |iterators|. The |begin| and |end| metafunctions +provide iterators delimiting the range of the sequence +elements. A sequence guarantees that its elements are arranged in a definite, +but possibly unspecified, order. Every MPL sequence is a |Forward Sequence|. + +Definitions +----------- + +* The *size* of a sequence is the number of elements it contains. The size is a + nonnegative number. + +* A sequence is *empty* if its size is zero. + + +Expression requirements +----------------------- + +For any |Forward Sequence| ``s`` the following expressions must be valid: + ++---------------------------+-----------------------------------+---------------------------+ +| Expression | Type | Complexity | ++===========================+===================================+===========================+ +| ``begin::type`` | |Forward Iterator| | Amortized constant time | ++---------------------------+-----------------------------------+---------------------------+ +| ``end::type`` | |Forward Iterator| | Amortized constant time | ++---------------------------+-----------------------------------+---------------------------+ +| ``size::type`` | |Integral Constant| | Unspecified | ++---------------------------+-----------------------------------+---------------------------+ +| ``empty::type`` | Boolean |Integral Constant| | Constant time | ++---------------------------+-----------------------------------+---------------------------+ +| ``front::type`` | Any type | Amortized constant time | ++---------------------------+-----------------------------------+---------------------------+ + + +Expression semantics +-------------------- + ++---------------------------+-----------------------------------------------------------------------+ +| Expression | Semantics | ++===========================+=======================================================================+ +| ``begin::type`` | An iterator to the first element of the sequence; see |begin|. | ++---------------------------+-----------------------------------------------------------------------+ +| ``end::type`` | A past-the-end iterator to the sequence; see |end|. | ++---------------------------+-----------------------------------------------------------------------+ +| ``size::type`` | The size of the sequence; see |size|. | ++---------------------------+-----------------------------------------------------------------------+ +| ``empty::type`` | |true if and only if| the sequence is empty; see |empty|. | ++---------------------------+-----------------------------------------------------------------------+ +| ``front::type`` | The first element in the sequence; see |front|. | ++---------------------------+-----------------------------------------------------------------------+ + + +Invariants +---------- + +For any |Forward Sequence| ``s`` the following invariants always hold: + +* [``begin::type``, ``end::type``) is always a valid range. + +* An algorithm that iterates through the range [``begin::type``, ``end::type``) + will pass through every element of ``s`` exactly once. + +* ``begin::type`` is identical to ``end::type`` if and only if ``s`` is empty. + +* Two different iterations through ``s`` will access its elements in the same order. + + +Models +------ + +* |vector| +* |map| +* |range_c| +* |iterator_range| +* |filter_view| + +See also +-------- + +|Sequences|, |Bidirectional Sequence|, |Forward Iterator|, |begin| / |end|, |size|, |empty|, |front| + diff --git a/doc/src/refmanual/FrontExtensibleSequence.rst b/doc/src/refmanual/FrontExtensibleSequence.rst new file mode 100644 index 0000000..4204639 --- /dev/null +++ b/doc/src/refmanual/FrontExtensibleSequence.rst @@ -0,0 +1,64 @@ +.. Sequences/Concepts//Front Extensible Sequence |50 + +Front Extensible Sequence +========================= + +Description +----------- + +A |Front Extensible Sequence| is an |Extensible Sequence| that supports amortized constant +time insertion and removal operations at the beginning. + +Refinement of +------------- + +|Extensible Sequence| + + +Expression requirements +----------------------- + +In addition to the requirements defined in |Extensible Sequence|, +for any |Back Extensible Sequence| ``s`` the following must be met: + ++-------------------------------+-------------------------------+---------------------------+ +| Expression | Type | Complexity | ++===============================+===============================+===========================+ +| ``push_front::type`` | |Front Extensible Sequence| | Amortized constant time | ++-------------------------------+-------------------------------+---------------------------+ +| ``pop_front::type`` | |Front Extensible Sequence| | Amortized constant time | ++-------------------------------+-------------------------------+---------------------------+ +| ``front::type`` | Any type | Amortized constant time | ++-------------------------------+-------------------------------+---------------------------+ + + +Expression semantics +-------------------- + +|Semantics disclaimer...| |Extensible Sequence|. + ++-------------------------------+-----------------------------------------------------------+ +| Expression | Semantics | ++===============================+===========================================================+ +| ``push_front::type`` | Equivalent to ``insert::type,x>::type``; | +| | see |push_front|. | ++-------------------------------+-----------------------------------------------------------+ +| ``pop_front::type`` | Equivalent to ``erase::type>::type``; | +| | see |pop_front|. | ++-------------------------------+-----------------------------------------------------------+ +| ``front::type`` | The first element in the sequence; see |front|. | ++-------------------------------+-----------------------------------------------------------+ + + +Models +------ + +* |vector| +* |list| + + +See also +-------- + +|Sequences|, |Extensible Sequence|, |Back Extensible Sequence|, |push_front|, |pop_front|, |front| + diff --git a/doc/src/refmanual/HAS_XXX_TRAIT_DEF.rst b/doc/src/refmanual/HAS_XXX_TRAIT_DEF.rst new file mode 100644 index 0000000..767d333 --- /dev/null +++ b/doc/src/refmanual/HAS_XXX_TRAIT_DEF.rst @@ -0,0 +1,116 @@ +.. Macros/Introspection//BOOST_MPL_HAS_XXX_TRAIT_DEF + +BOOST_MPL_HAS_XXX_TRAIT_DEF +=========================== + +Synopsis +-------- + +.. parsed-literal:: + + #define BOOST_MPL_HAS_XXX_TRAIT_DEF(name) \\ + |unspecified-token-seq| \\ + /\*\*/ + + +Description +----------- + +Expands into a definition of a boolean unary |Metafunction| ``has_name`` +such that for any type ``x`` ``has_name::value == true`` if and only +if ``x`` is a class type and has a nested type memeber ``x::name``. + +On the deficient compilers not capabale of performing the detection, +``has_name::value`` always returns ``false``. A boolean configuraion +macro, |BOOST_MPL_CFG_NO_HAS_XXX|, is provided to signal or override +the "deficient" status of a particular compiler. + +|Note:| |BOOST_MPL_HAS_XXX_TRAIT_DEF| is a simplified front end to +the |BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF| introspection macro |-- end note| + + +Header +------ + +.. parsed-literal:: + + #include + + +Parameters +---------- + + ++---------------+-------------------------------+---------------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===============================+===================================================+ +| ``name`` | A legal identifier token | A name of the member being detected. | ++---------------+-------------------------------+---------------------------------------------------+ + + +Expression semantics +-------------------- + +For any legal C++ identifier ``name``: + +.. parsed-literal:: + + BOOST_MPL_HAS_XXX_TRAIT_DEF(name) + +:Precondition: + Appears at namespace scope. + +:Return type: + None. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF( + BOOST_PP_CAT(has\_,name), name, false + ) + + +Example +------- + +.. parsed-literal:: + + BOOST_MPL_HAS_XXX_TRAIT_DEF(has_xxx) + + struct test1 {}; + struct test2 { void xxx(); }; + struct test3 { int xxx; }; + struct test4 { static int xxx(); }; + struct test5 { template< typename T > struct xxx {}; }; + struct test6 { typedef int xxx; }; + struct test7 { struct xxx; }; + struct test8 { typedef void (\*xxx)(); }; + struct test9 { typedef void (xxx)(); }; + + BOOST_MPL_ASSERT_NOT(( has_xxx )); + BOOST_MPL_ASSERT_NOT(( has_xxx )); + BOOST_MPL_ASSERT_NOT(( has_xxx )); + BOOST_MPL_ASSERT_NOT(( has_xxx )); + BOOST_MPL_ASSERT_NOT(( has_xxx )); + + #if !defined(BOOST_MPL_CFG_NO_HAS_XXX) + BOOST_MPL_ASSERT(( has_xxx )); + BOOST_MPL_ASSERT(( has_xxx )); + BOOST_MPL_ASSERT(( has_xxx )); + BOOST_MPL_ASSERT(( has_xxx )); + #endif + + BOOST_MPL_ASSERT(( has_xxx )); + BOOST_MPL_ASSERT(( has_xxx )); + BOOST_MPL_ASSERT(( has_xxx )); + BOOST_MPL_ASSERT(( has_xxx )); + + +See also +-------- + +|Macros|, |BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF|, |BOOST_MPL_CFG_NO_HAS_XXX| + diff --git a/doc/src/refmanual/HAS_XXX_TRAIT_NAMED_DEF.rst b/doc/src/refmanual/HAS_XXX_TRAIT_NAMED_DEF.rst new file mode 100644 index 0000000..a86fe87 --- /dev/null +++ b/doc/src/refmanual/HAS_XXX_TRAIT_NAMED_DEF.rst @@ -0,0 +1,153 @@ +.. Macros/Introspection//BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF + +BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF +================================= + +Synopsis +-------- + +.. parsed-literal:: + + #define BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(trait, name, default\_) \\ + |unspecified-token-seq| \\ + /\*\*/ + + +Description +----------- + +Expands into a definition of a boolean unary |Metafunction| ``trait`` +such that for any type ``x`` ``trait::value == true`` if and only +if ``x`` is a class type and has a nested type memeber ``x::name``. + +On the deficient compilers not capabale of performing the detection, +``trait::value`` always returns a fallback value ``default_``. +A boolean configuraion macro, |BOOST_MPL_CFG_NO_HAS_XXX|, is provided +to signal or override the "deficient" status of a particular compiler. +|Note:| The fallback value call also be provided at the point of the +metafunction invocation; see the `Expression semantics` section for +details |-- end note| + + +Header +------ + +.. parsed-literal:: + + #include + + +Parameters +---------- + ++---------------+-------------------------------+---------------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===============================+===================================================+ +| ``trait`` | A legal identifier token | A name of the metafunction to be generated. | ++---------------+-------------------------------+---------------------------------------------------+ +| ``name`` | A legal identifier token | A name of the member being detected. | ++---------------+-------------------------------+---------------------------------------------------+ +| ``default_`` | An boolean constant | A fallback value for the deficient compilers. | ++---------------+-------------------------------+---------------------------------------------------+ + + +Expression semantics +-------------------- + +For any legal C++ identifiers ``trait`` and ``name``, boolean constant expression ``c1``, +boolean |Integral Constant| ``c2``, and arbitrary type ``x``: + +.. parsed-literal:: + + BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(trait, name, c1) + +:Precondition: + Appears at namespace scope. + +:Return type: + None. + +:Semantics: + Expands into an equivalent of the following class template definition + + .. parsed-literal:: + + template< typename X, typename fallback = boost::mpl::bool_ > + struct trait + { + // |unspecified| + // ... + }; + + where ``trait`` is a boolean |Metafunction| with the following semantics: + + .. parsed-literal:: + + typedef trait::type r; + + :Return type: + |Integral Constant|. + + :Semantics: + If |BOOST_MPL_CFG_NO_HAS_XXX| is defined, ``r::value == c1``; + otherwise, ``r::value == true`` if and only if ``x`` is a class type + that has a nested type memeber ``x::name``. + + + .. parsed-literal:: + + typedef trait< x,c2 >::type r; + + :Return type: + |Integral Constant|. + + :Semantics: + If |BOOST_MPL_CFG_NO_HAS_XXX| is defined, ``r::value == c2::value``; + otherwise, equivalent to + + .. parsed-literal:: + + typedef trait::type r; + + +Example +------- + +.. parsed-literal:: + + BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_xxx, xxx, false) + + struct test1 {}; + struct test2 { void xxx(); }; + struct test3 { int xxx; }; + struct test4 { static int xxx(); }; + struct test5 { template< typename T > struct xxx {}; }; + struct test6 { typedef int xxx; }; + struct test7 { struct xxx; }; + struct test8 { typedef void (\*xxx)(); }; + struct test9 { typedef void (xxx)(); }; + + BOOST_MPL_ASSERT_NOT(( has_xxx )); + BOOST_MPL_ASSERT_NOT(( has_xxx )); + BOOST_MPL_ASSERT_NOT(( has_xxx )); + BOOST_MPL_ASSERT_NOT(( has_xxx )); + BOOST_MPL_ASSERT_NOT(( has_xxx )); + + #if !defined(BOOST_MPL_CFG_NO_HAS_XXX) + BOOST_MPL_ASSERT(( has_xxx )); + BOOST_MPL_ASSERT(( has_xxx )); + BOOST_MPL_ASSERT(( has_xxx )); + BOOST_MPL_ASSERT(( has_xxx )); + #endif + + BOOST_MPL_ASSERT(( has_xxx )); + BOOST_MPL_ASSERT(( has_xxx )); + BOOST_MPL_ASSERT(( has_xxx )); + BOOST_MPL_ASSERT(( has_xxx )); + + +See also +-------- + +|Macros|, |BOOST_MPL_HAS_XXX_TRAIT_DEF|, |BOOST_MPL_CFG_NO_HAS_XXX| + diff --git a/doc/src/refmanual/Inserter.rst b/doc/src/refmanual/Inserter.rst new file mode 100644 index 0000000..73857aa --- /dev/null +++ b/doc/src/refmanual/Inserter.rst @@ -0,0 +1,75 @@ +.. Algorithms/Concepts//Inserter + +Inserter +======== + +Description +----------- + +An |Inserter| is a compile-time substitute for STL |Output Iterator|. +Under the hood, it's simply a type holding +two entities: a *state* and an *operation*. When passed to a +|transformation algorithm|, the inserter's binary operation is +invoked for every element that would normally be written into the +output iterator, with the element itself (as the second +argument) and the result of the previous operation's invocation |--| or, +for the very first element, the inserter's initial state. + +Technically, instead of taking a single inserter parameter, +|transformation algorithms| could accept the state and the "output" +operation separately. Grouping these in a single parameter entity, +however, brings the algorithms semantically and syntactically closer to +their STL counterparts, significantly simplifying many of the common +use cases. + + +Valid expressions +----------------- + +|In the following table...| ``in`` is a model of |Inserter|. + ++-----------------------+-------------------------------+ +| Expression | Type | ++=======================+===============================+ +| ``in::state`` | Any type | ++-----------------------+-------------------------------+ +| ``in::operation`` | Binary |Lambda Expression| | ++-----------------------+-------------------------------+ + + +Expression semantics +-------------------- + ++-----------------------+-------------------------------------------+ +| Expression | Semantics | ++=======================+===========================================+ +| ``in::state`` | The inserter's initial state. | ++-----------------------+-------------------------------------------+ +| ``in::operation`` | The inserter's "output" operation. | ++-----------------------+-------------------------------------------+ + + +Example +------- + +.. parsed-literal:: + + typedef transform< + range_c + , plus<_1,_1> + , back_inserter< vector0<> > + >::type result; + + +Models +------ + +* |inserter| +* |front_inserter| +* |back_inserter| + +See also +-------- + +|Algorithms|, |Transformation Algorithms|, |inserter|, |front_inserter|, |back_inserter| + diff --git a/doc/src/refmanual/IntegralConstant.rst b/doc/src/refmanual/IntegralConstant.rst new file mode 100644 index 0000000..cc25661 --- /dev/null +++ b/doc/src/refmanual/IntegralConstant.rst @@ -0,0 +1,71 @@ +.. Data Types/Concepts//Integral Constant + +Integral Constant +================= + +Description +----------- + +An |Integral Constant| is a holder class for a compile-time value of an +integral type. Every |Integral Constant| is also a nullary |Metafunction|, +returning itself. An integral constant *object* is implicitly convertible to the +corresponding run-time value of the wrapped integral type. + +Expression requirements +----------------------- + +|In the following table...| ``n`` is a model of |Integral Constant|. + ++-----------------------------------+---------------------------------------+---------------------------+ +| Expression | Type | Complexity | ++===================================+=======================================+===========================+ +| ``n::value_type`` | An integral type | Constant time. | ++-----------------------------------+---------------------------------------+---------------------------+ +| ``n::value`` | An integral constant expression | Constant time. | ++-----------------------------------+---------------------------------------+---------------------------+ +| ``n::type`` | |Integral Constant| | Constant time. | ++-----------------------------------+---------------------------------------+---------------------------+ +| ``next::type`` | |Integral Constant| | Constant time. | ++-----------------------------------+---------------------------------------+---------------------------+ +| ``prior::type`` | |Integral Constant| | Constant time. | ++-----------------------------------+---------------------------------------+---------------------------+ +| ``n::value_type const c = n()`` | | Constant time. | ++-----------------------------------+---------------------------------------+---------------------------+ + + +Expression semantics +-------------------- + ++---------------------------------------+-----------------------------------------------------------+ +| Expression | Semantics | ++=======================================+===========================================================+ +| ``n::value_type`` | A cv-unqualified type of ``n::value``. | ++---------------------------------------+-----------------------------------------------------------+ +| ``n::value`` | The value of the wrapped integral constant. | ++---------------------------------------+-----------------------------------------------------------+ +| ``n::type`` | ``is_same::value == true``. | ++---------------------------------------+-----------------------------------------------------------+ +| ``next::type`` | An |Integral Constant| ``c`` of type ``n::value_type`` | +| | such that ``c::value == n::value + 1``. | ++---------------------------------------+-----------------------------------------------------------+ +| ``prior::type`` | An |Integral Constant| ``c`` of type ``n::value_type`` | +| | such that ``c::value == n::value - 1``. | ++---------------------------------------+-----------------------------------------------------------+ +| ``n::value_type const c = n()`` | ``c == n::value``. | ++---------------------------------------+-----------------------------------------------------------+ + + +Models +------ + +* |bool_| +* |int_| +* |long_| +* |integral_c| + + +See also +-------- + +|Data Types|, |Integral Sequence Wrapper|, |integral_c| + diff --git a/doc/src/refmanual/IntegralSequenceWrapper.rst b/doc/src/refmanual/IntegralSequenceWrapper.rst new file mode 100644 index 0000000..2aca36a --- /dev/null +++ b/doc/src/refmanual/IntegralSequenceWrapper.rst @@ -0,0 +1,116 @@ +.. Sequences/Concepts//Integral Sequence Wrapper |90 + +Integral Sequence Wrapper +========================= + +Description +----------- + +An |Integral Sequence Wrapper| is a class template that provides a concise +interface for creating a corresponding sequence of |Integral Constant|\ s. In +particular, assuming that ``seq`` is a name of the wrapper's underlying +sequence and |c1...cn| are integral constants of an integral type ``T`` to +be stored in the sequence, the wrapper provides us with the following +notation: + + .. line-block:: + + ``seq_c`` + +If ``seq`` is a |Variadic Sequence|, *numbered* wrapper forms are +also avaialable: + + .. line-block:: + + ``seq``\ *n*\ ``_c`` + + + +Expression requirements +----------------------- + +|In the following table...| ``seq`` is a placeholder token for the +|Integral Sequence Wrapper|'s underlying sequence's name. + + +.. |seq_c| replace:: ``seq_c`` | |Forward Sequence| | Amortized constant time. | ++-------------------------------+-----------------------+---------------------------+ +| |seq_c|\ ``>::type`` | |Forward Sequence| | Amortized constant time. | ++-------------------------------+-----------------------+---------------------------+ +| |seq_c|\ ``>::value_type`` | An integral type | Amortized constant time. | ++-------------------------------+-----------------------+---------------------------+ +| |seqn_c|\ ``>`` | |Forward Sequence| | Amortized constant time. | ++-------------------------------+-----------------------+---------------------------+ +| |seqn_c|\ ``>::type`` | |Forward Sequence| | Amortized constant time. | ++-------------------------------+-----------------------+---------------------------+ +| |seqn_c|\ ``>::value_type`` | An integral type | Amortized constant time. | ++-------------------------------+-----------------------+---------------------------+ + + +Expression semantics +-------------------- + + +.. parsed-literal:: + + typedef seq_c s; + typedef seq\ *n*\ _c s; + +:Semantics: + ``s`` is a sequence ``seq`` of integral constant wrappers ``integral_c``, + ``integral_c``, ... ``integral_c``. + +:Postcondition: + ``size::value == n``. + + .. .. parsed-literal:: + + BOOST_MPL_ASSERT_RELATION(( at_c::type::value,==,\ |c1| )); + BOOST_MPL_ASSERT_RELATION(( at_c::type::value,==,\ |c2| )); + ... + BOOST_MPL_ASSERT_RELATION(( at_c::type::value,==,\ |cn| )); + + +.. .......................................................................... + +.. parsed-literal:: + + typedef seq_c::type s; + typedef seq\ *n*\ _c::type s; + +:Semantics: + ``s`` is identical to + ``seq``\ *n*\ ``<``\ ``integral_c``,\ ``integral_c``, + ... ``integral_c`` ``>``. + + +.. .......................................................................... + +.. parsed-literal:: + + typedef seq_c::value_type t; + typedef seq\ *n*\ _c::value_type t; + +:Semantics: + ``is_same::value == true``. + + +Models +------ + +* |vector_c| +* |list_c| +* |set_c| + +See also +-------- + +|Sequences|, |Variadic Sequence|, |Integral Constant| + diff --git a/doc/src/refmanual/Iterators-Concepts.rst b/doc/src/refmanual/Iterators-Concepts.rst new file mode 100644 index 0000000..27cc124 --- /dev/null +++ b/doc/src/refmanual/Iterators-Concepts.rst @@ -0,0 +1,15 @@ + + +All iterators in MPL are classified into three iterator concepts, or +`categories`, named according to the type of traversal provided. The +categories are: |Forward Iterator|, |Bidirectional Iterator|, and +|Random Access Iterator|. The concepts are hierarchical: +|Random Access Iterator| is a refinement of |Bidirectional Iterator|, +which, in its turn, is a refinement of |Forward Iterator|. + +Because of the inherently immutable nature of the value access, MPL +iterators escape the problems of the traversal-only categorization +discussed at length in [n1550]_. + + +.. [n1550] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1550.htm diff --git a/doc/src/refmanual/Iterators-Metafunctions.rst b/doc/src/refmanual/Iterators-Metafunctions.rst new file mode 100644 index 0000000..1c9a3e1 --- /dev/null +++ b/doc/src/refmanual/Iterators-Metafunctions.rst @@ -0,0 +1,7 @@ + +From the implementation standpoint, iterators are almost-opaque types which +guarantee to provide us with the only memeber that we can access directly: +their category. Incrementing, dereferencing and the rest of iterator +functionality is available to us through the accosiated iterator +metafunctions. + diff --git a/doc/src/refmanual/Iterators.rst b/doc/src/refmanual/Iterators.rst new file mode 100644 index 0000000..5cbc572 --- /dev/null +++ b/doc/src/refmanual/Iterators.rst @@ -0,0 +1,14 @@ + +Iterators are generic means of addressing a particular element or a range +of sequential elements in a sequence. They are also a mechanism that makes +it possible to decouple `algorithms`__ from concrete compile-time `sequence +implementations`__. Under the hood, all MPL sequence algorithms are +implemented in terms of iterators. In particular, that means that they +will work on any custom compile-time sequence, given that the appropriate +iterator inteface is provided. + +__ `Algorithms`_ +__ `label-Sequences-Classes`_ + +.. Analogy with STL iterators? +.. More? diff --git a/doc/src/refmanual/LIMIT_LIST_SIZE.rst b/doc/src/refmanual/LIMIT_LIST_SIZE.rst new file mode 100644 index 0000000..583448a --- /dev/null +++ b/doc/src/refmanual/LIMIT_LIST_SIZE.rst @@ -0,0 +1,49 @@ +.. Macros/Configuration//BOOST_MPL_LIMIT_LIST_SIZE |40 + +BOOST_MPL_LIMIT_LIST_SIZE +========================= + +Synopsis +-------- + +.. parsed-literal:: + + #if !defined(BOOST_MPL_LIMIT_LIST_SIZE) + # define BOOST_MPL_LIMIT_LIST_SIZE \\ + |idic| \\ + /\*\*/ + #endif + + +Description +----------- + +``BOOST_MPL_LIMIT_LIST_SIZE`` is an overridable configuration macro regulating +the maximum arity of the ``list``\ 's and ``list_c``\ 's |variadic forms|. In this +implementation of the library, ``BOOST_MPL_LIMIT_LIST_SIZE`` has a default value +of 20. To override the default limit, define ``BOOST_MPL_LIMIT_LIST_SIZE`` to +the desired maximum arity rounded up to the nearest multiple of ten before +including any library header. |preprocessed headers disclaimer| + + +Example +------- + +.. parsed-literal:: + + #define BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS + #define BOOST_MPL_LIMIT_LIST_SIZE 10 + ``#``\ include + + using namespace boost::mpl; + + typedef list_c l_1; + typedef list_c l_10; + // typedef list_c l_11; // error! + + +See also +-------- + +|Configuration|, |BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS|, |BOOST_MPL_LIMIT_VECTOR_SIZE| + diff --git a/doc/src/refmanual/LIMIT_MAP_SIZE.rst b/doc/src/refmanual/LIMIT_MAP_SIZE.rst new file mode 100644 index 0000000..4ab7001 --- /dev/null +++ b/doc/src/refmanual/LIMIT_MAP_SIZE.rst @@ -0,0 +1,58 @@ +.. Macros/Configuration//BOOST_MPL_LIMIT_MAP_SIZE |60 + +BOOST_MPL_LIMIT_MAP_SIZE +======================== + +Synopsis +-------- + +.. parsed-literal:: + + #if !defined(BOOST_MPL_LIMIT_MAP_SIZE) + # define BOOST_MPL_LIMIT_MAP_SIZE \\ + |idic| \\ + /\*\*/ + #endif + + +Description +----------- + +``BOOST_MPL_LIMIT_MAP_SIZE`` is an overridable configuration macro regulating +the maximum arity of the ``map``\ 's `variadic form`__. In this +implementation of the library, ``BOOST_MPL_LIMIT_MAP_SIZE`` has a default value +of 20. To override the default limit, define ``BOOST_MPL_LIMIT_MAP_SIZE`` to +the desired maximum arity rounded up to the nearest multiple of ten before +including any library header. |preprocessed headers disclaimer| + +__ `Variadic Sequence`_ + + +Example +------- + +.. parsed-literal:: + + #define BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS + #define BOOST_MPL_LIMIT_MAP_SIZE 10 + ``#``\ include + ``#``\ include + ``#``\ include + + using namespace boost::mpl; + + template< int i > struct ints : pair< int_,int_ > {}; + + typedef map< ints<1> > m_1; + typedef map< ints<1>, ints<2>, ints<3>, ints<4>, ints<5> + ints<6>, ints<7>, ints<8>, ints<9>, ints<10> > m_10; + + // typedef map< ints<1>, ints<2>, ints<3>, ints<4>, ints<5> + // ints<6>, ints<7>, ints<8>, ints<9>, ints<10>, ints<11> > m_11; // error! + + +See also +-------- + +|Configuration|, |BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS|, |BOOST_MPL_LIMIT_SET_SIZE| + diff --git a/doc/src/refmanual/LIMIT_METAFUNCTION_ARITY.rst b/doc/src/refmanual/LIMIT_METAFUNCTION_ARITY.rst new file mode 100644 index 0000000..f1ec020 --- /dev/null +++ b/doc/src/refmanual/LIMIT_METAFUNCTION_ARITY.rst @@ -0,0 +1,62 @@ +.. Macros/Configuration//BOOST_MPL_LIMIT_METAFUNCTION_ARITY |20 + +BOOST_MPL_LIMIT_METAFUNCTION_ARITY +================================== + +Synopsis +-------- + +.. parsed-literal:: + + #if !defined(BOOST_MPL_LIMIT_METAFUNCTION_ARITY) + # define BOOST_MPL_LIMIT_METAFUNCTION_ARITY \\ + |idic| \\ + /\*\*/ + #endif + + +Description +----------- + +``BOOST_MPL_LIMIT_METAFUNCTION_ARITY`` is an overridable configuration macro +regulating the maximum supported arity of `metafunctions`__ and +`metafunction classes`__. In this implementation of the +library, ``BOOST_MPL_LIMIT_METAFUNCTION_ARITY`` has a default value of 5. To +override the default limit, define ``BOOST_MPL_LIMIT_METAFUNCTION_ARITY`` to +the desired maximum arity before including any library header. +|preprocessed headers disclaimer| + +__ `Metafunction`_ +__ `Metafunction Class`_ + + +Example +------- + +.. parsed-literal:: + + #define BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS + #define BOOST_MPL_LIMIT_METAFUNCTION_ARITY 2 + ``#``\ include + + using namespace boost::mpl; + + template< typename T1, typename T2 > struct second + { + typedef T2 type; + }; + + template< typename T1, typename T2, typename T3 > struct third + { + typedef T3 type; + }; + + typedef apply< second<_1,_2_>,int,long >::type r1; + // typedef apply< third<_1,_2_,_3>,int,long,float >::type r2; // error! + + +See also +-------- + +|Macros|, |Configuration|, |BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS| + diff --git a/doc/src/refmanual/LIMIT_SET_SIZE.rst b/doc/src/refmanual/LIMIT_SET_SIZE.rst new file mode 100644 index 0000000..04967f9 --- /dev/null +++ b/doc/src/refmanual/LIMIT_SET_SIZE.rst @@ -0,0 +1,48 @@ +.. Macros/Configuration//BOOST_MPL_LIMIT_SET_SIZE |50 + +BOOST_MPL_LIMIT_SET_SIZE +======================== + +Synopsis +-------- + +.. parsed-literal:: + + #if !defined(BOOST_MPL_LIMIT_SET_SIZE) + # define BOOST_MPL_LIMIT_SET_SIZE \\ + |idic| \\ + /\*\*/ + #endif + + +Description +----------- + +``BOOST_MPL_LIMIT_SET_SIZE`` is an overridable configuration macro regulating +the maximum arity of the ``set``\ 's and ``set_c``\ 's |variadic forms|. In this +implementation of the library, ``BOOST_MPL_LIMIT_SET_SIZE`` has a default value +of 20. To override the default limit, define ``BOOST_MPL_LIMIT_SET_SIZE`` to +the desired maximum arity rounded up to the nearest multiple of ten before +including any library header. |preprocessed headers disclaimer| + + +Example +------- + +.. parsed-literal:: + + #define BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS + #define BOOST_MPL_LIMIT_SET_SIZE 10 + ``#``\ include + + using namespace boost::mpl; + + typedef set_c s_1; + typedef set_c s_10; + // typedef set_c s_11; // error! + + +See also +-------- + +|Configuration|, |BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS|, |BOOST_MPL_LIMIT_MAP_SIZE| diff --git a/doc/src/refmanual/LIMIT_UNROLLING.rst b/doc/src/refmanual/LIMIT_UNROLLING.rst new file mode 100644 index 0000000..94fbc8c --- /dev/null +++ b/doc/src/refmanual/LIMIT_UNROLLING.rst @@ -0,0 +1,38 @@ +.. Macros/Configuration//BOOST_MPL_LIMIT_UNROLLING |70 + +BOOST_MPL_LIMIT_UNROLLING +========================= + +Synopsis +-------- + +.. parsed-literal:: + + #if !defined(BOOST_MPL_LIMIT_UNROLLING) + # define BOOST_MPL_LIMIT_UNROLLING \\ + |idic| \\ + /\*\*/ + #endif + + +Description +----------- + +``BOOST_MPL_LIMIT_UNROLLING`` is an overridable configuration macro regulating +the unrolling depth of the library's iteration algorithms. In this implementation +of the library, ``BOOST_MPL_LIMIT_UNROLLING`` has a default value of 4. To +override the default, define ``BOOST_MPL_LIMIT_UNROLLING`` to the desired +value before including any library header. +|preprocessed headers disclaimer| + + +Example +------- + +Except for overall library performace, overriding the +``BOOST_MPL_LIMIT_UNROLLING``\ 's default value has no user-observable effects. + +See also +-------- + +|Configuration|, |BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS| diff --git a/doc/src/refmanual/LIMIT_VECTOR_SIZE.rst b/doc/src/refmanual/LIMIT_VECTOR_SIZE.rst new file mode 100644 index 0000000..d0d728e --- /dev/null +++ b/doc/src/refmanual/LIMIT_VECTOR_SIZE.rst @@ -0,0 +1,49 @@ +.. Macros/Configuration//BOOST_MPL_LIMIT_VECTOR_SIZE |30 + +BOOST_MPL_LIMIT_VECTOR_SIZE +=========================== + +Synopsis +-------- + +.. parsed-literal:: + + #if !defined(BOOST_MPL_LIMIT_VECTOR_SIZE) + # define BOOST_MPL_LIMIT_VECTOR_SIZE \\ + |idic| \\ + /\*\*/ + #endif + + +Description +----------- + +``BOOST_MPL_LIMIT_VECTOR_SIZE`` is an overridable configuration macro regulating +the maximum arity of the ``vector``\ 's and ``vector_c``\ 's |variadic forms|. In this +implementation of the library, ``BOOST_MPL_LIMIT_VECTOR_SIZE`` has a default value +of 20. To override the default limit, define ``BOOST_MPL_LIMIT_VECTOR_SIZE`` to +the desired maximum arity rounded up to the nearest multiple of ten before +including any library header. |preprocessed headers disclaimer| + + +Example +------- + +.. parsed-literal:: + + #define BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS + #define BOOST_MPL_LIMIT_VECTOR_SIZE 10 + ``#``\ include + + using namespace boost::mpl; + + typedef vector_c v_1; + typedef vector_c v_10; + // typedef vector_c v_11; // error! + + +See also +-------- + +|Configuration|, |BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS|, |BOOST_MPL_LIMIT_LIST_SIZE| + diff --git a/doc/src/refmanual/LambdaExpression.rst b/doc/src/refmanual/LambdaExpression.rst new file mode 100644 index 0000000..28cd468 --- /dev/null +++ b/doc/src/refmanual/LambdaExpression.rst @@ -0,0 +1,37 @@ +.. Metafunctions/Concepts//Lambda Expression |30 + +Lambda Expression +================= + +Description +----------- + +A |Lambda Expression| is a compile-time invocable entity in either of the following two +forms: + +* |Metafunction Class| +* |Placeholder Expression| + +Most of the MPL components accept either of those, and the concept +gives us a consice way to describe these requirements. + + +Expression requirements +----------------------- + +See corresponding |Metafunction Class| and |Placeholder Expression| specifications. + + +Models +------ + +* |always| +* |unpack_args| +* ``plus<_, int_<2> >`` +* ``if_< less<_1, int_<7> >, plus<_1,_2>, _1 >`` + + +See also +-------- + +|Metafunctions|, |Placeholders|, |apply|, |lambda| diff --git a/doc/src/refmanual/Macros-Asserts.rst b/doc/src/refmanual/Macros-Asserts.rst new file mode 100644 index 0000000..cb36e89 --- /dev/null +++ b/doc/src/refmanual/Macros-Asserts.rst @@ -0,0 +1,10 @@ + + +The MPL supplies a suite of static assertion macros that are specifically +designed to generate maximally useful and informative error messages +within the diagnostic capabilities of each compiler. + +All assert macros can be used at class, function, or namespace scope. + + +.. |Asserts| replace:: `Asserts`_ diff --git a/doc/src/refmanual/Macros-Configuration.rst b/doc/src/refmanual/Macros-Configuration.rst new file mode 100644 index 0000000..cf7af68 --- /dev/null +++ b/doc/src/refmanual/Macros-Configuration.rst @@ -0,0 +1,2 @@ + +.. |Configuration| replace:: `Configuration`_ diff --git a/doc/src/refmanual/Macros.rst b/doc/src/refmanual/Macros.rst new file mode 100644 index 0000000..a8add17 --- /dev/null +++ b/doc/src/refmanual/Macros.rst @@ -0,0 +1,18 @@ + +Being a *template* metaprogramming framework, the MPL concentrates on +getting one thing done well and leaves most of the clearly +preprocessor-related tasks to the corresponding specialized +libraries [PRE]_, [Ve03]_. But whether we like it or not, macros play +an important role on today's C++ metaprogramming, and some of +the useful MPL-level functionality cannot be implemented +without leaking its preprocessor-dependent implementation +nature into the library's public interface. + + +.. [PRE] Vesa Karvonen, Paul Mensonides, + `The Boost Preprocessor Metaprogramming library`__ + +__ http://www.boost.org/libs/preprocessor/doc/index.html + +.. [Ve03] Vesa Karvonen, `The Order Programming Language`, 2003. + diff --git a/doc/src/refmanual/Metafunction.rst b/doc/src/refmanual/Metafunction.rst new file mode 100644 index 0000000..2ad7f75 --- /dev/null +++ b/doc/src/refmanual/Metafunction.rst @@ -0,0 +1,97 @@ +.. Metafunctions/Concepts//Metafunction |10 + +Metafunction +============ + +Description +----------- + +.. _`nullary-metafunction`: + +A *metafunction* is a class or a class template that represents a +function invocable at compile-time. An 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 (template) class with a nested ``type`` typename +member. + +.. |nullary metafunction| replace:: `nullary-metafunction`_ + + +Expression requirements +----------------------- + +|In the following table...| ``f`` is a |Metafunction|. + ++-------------------------------+-----------------------+---------------------------+ +| Expression | Type | Complexity | ++===============================+=======================+===========================+ +| ``f::type`` | Any type | Unspecified. | ++-------------------------------+-----------------------+---------------------------+ +| ``f<>::type`` | Any type | Unspecified. | ++-------------------------------+-----------------------+---------------------------+ +| ``f::type`` | Any type | Unspecified. | ++-------------------------------+-----------------------+---------------------------+ + + +Expression semantics +-------------------- + +.. parsed-literal:: + + typedef f::type x; + +:Precondition: + ``f`` is a nullary |Metafunction|; ``f::type`` is a *type-name*. + +:Semantics: + ``x`` is the result of the metafunction invocation. + + +.. ................................................................................... + +.. parsed-literal:: + + typedef f<>::type x; + +:Precondition: + ``f`` is a nullary |Metafunction|; ``f<>::type`` is a *type-name*. + +:Semantics: + ``x`` is the result of the metafunction invocation. + + +.. ................................................................................... + +.. parsed-literal:: + + typedef f::type x; + +:Precondition: + ``f`` is an *n*-ary |Metafunction|; |a1...an| are types; + ``f::type`` is a *type-name*. + +:Semantics: + ``x`` is the result of the metafunction invocation + with the actual arguments |a1...an|. + + +Models +------ + +* |identity| +* |plus| +* |begin| +* |insert| +* |fold| + + +See also +-------- + +|Metafunctions|, |Metafunction Class|, |Lambda Expression|, |Invocation|, |apply|, |lambda|, |bind| + diff --git a/doc/src/refmanual/MetafunctionClass.rst b/doc/src/refmanual/MetafunctionClass.rst new file mode 100644 index 0000000..fff1c47 --- /dev/null +++ b/doc/src/refmanual/MetafunctionClass.rst @@ -0,0 +1,86 @@ +.. Metafunctions/Concepts//Metafunction Class |20 + +Metafunction Class +================== + +Summary +------- + +A *metafunction class* is a certain form of metafunction representation +that enables higher-order metaprogramming. More precisely, it's a class +with a publicly-accessible nested |metafunction| called ``apply``. +Correspondingly, a metafunction class invocation is defined as invocation +of its nested ``apply`` metafunction. + + +Expression requirements +----------------------- + +|In the following table...| ``f`` is a |Metafunction Class|. + ++-------------------------------+---------------------------+---------------------------+ +| Expression | Type | Complexity | ++===============================+===========================+===========================+ +| ``f::apply::type`` | Any type | Unspecified. | ++-------------------------------+---------------------------+---------------------------+ +| ``f::apply<>::type`` | Any type | Unspecified. | ++-------------------------------+---------------------------+---------------------------+ +| ``f::apply::type`` | Any type | Unspecified. | ++-------------------------------+---------------------------+---------------------------+ + + +Expression semantics +-------------------- + +.. parsed-literal:: + + typedef f::apply::type x; + +:Precondition: + ``f`` is a nullary |Metafunction Class|; ``f::apply::type`` is a *type-name*. + +:Semantics: + ``x`` is the result of the metafunction class invocation. + + +.. ................................................................................... + +.. parsed-literal:: + + typedef f::apply<>::type x; + +:Precondition: + ``f`` is a nullary |Metafunction Class|; ``f::apply<>::type`` is a *type-name*. + +:Semantics: + ``x`` is the result of the metafunction class invocation. + + +.. ................................................................................... + +.. parsed-literal:: + + typedef f::apply::type x; + +:Precondition: + ``f`` is an *n*-ary metafunction class; ``apply`` is a |Metafunction|. + +:Semantics: + ``x`` is the result of the metafunction class + invocation with the actual arguments |a1...an|. + + +Models +------ + +* |always| +* |arg| +* |quote| +* |numeric_cast| +* |unpack_args| + + +See also +-------- + +|Metafunctions|, |Metafunction|, |Lambda Expression|, |Invocation|, |apply_wrap|, |bind|, |quote| diff --git a/doc/src/refmanual/Metafunctions-Arithmetic.rst b/doc/src/refmanual/Metafunctions-Arithmetic.rst new file mode 100644 index 0000000..dd5df7f --- /dev/null +++ b/doc/src/refmanual/Metafunctions-Arithmetic.rst @@ -0,0 +1,5 @@ + +.. |Arithmetic Operations| replace:: `Arithmetic Operations`_ + +.. |arithmetic| replace:: `arithmetic`__ +__ `Arithmetic Operations`_ diff --git a/doc/src/refmanual/Metafunctions-Bitwise.rst b/doc/src/refmanual/Metafunctions-Bitwise.rst new file mode 100644 index 0000000..a91b88e --- /dev/null +++ b/doc/src/refmanual/Metafunctions-Bitwise.rst @@ -0,0 +1,5 @@ + +.. |Bitwise Operations| replace:: `Bitwise Operations`_ + +.. |bitwise| replace:: `bitwise`__ +__ `Bitwise Operations`_ diff --git a/doc/src/refmanual/Metafunctions-Comparisons.rst b/doc/src/refmanual/Metafunctions-Comparisons.rst new file mode 100644 index 0000000..76b667e --- /dev/null +++ b/doc/src/refmanual/Metafunctions-Comparisons.rst @@ -0,0 +1,5 @@ + +.. |Comparisons| replace:: `Comparisons`_ + +.. |comparison| replace:: `comparison`__ +__ `Comparisons`_ diff --git a/doc/src/refmanual/Metafunctions-Composition.rst b/doc/src/refmanual/Metafunctions-Composition.rst new file mode 100644 index 0000000..4ebec6d --- /dev/null +++ b/doc/src/refmanual/Metafunctions-Composition.rst @@ -0,0 +1,7 @@ + +.. |Composition and Argument Binding| replace:: `Composition and Argument Binding`_ + +.. |composition| replace:: `composition`__ +.. |argument binding| replace:: `argument binding`__ +__ `Composition and Argument Binding`_ +__ `Composition and Argument Binding`_ diff --git a/doc/src/refmanual/Metafunctions-Conditional.rst b/doc/src/refmanual/Metafunctions-Conditional.rst new file mode 100644 index 0000000..d6ee00d --- /dev/null +++ b/doc/src/refmanual/Metafunctions-Conditional.rst @@ -0,0 +1,3 @@ + +.. |control flow| replace:: `control flow`__ +__ `Control Flow`_ diff --git a/doc/src/refmanual/Metafunctions-Invocation.rst b/doc/src/refmanual/Metafunctions-Invocation.rst new file mode 100644 index 0000000..c1be9b8 --- /dev/null +++ b/doc/src/refmanual/Metafunctions-Invocation.rst @@ -0,0 +1,3 @@ + +.. |invocation| replace:: `invocation`__ +__ `Invocation`_ diff --git a/doc/src/refmanual/Metafunctions-Logical.rst b/doc/src/refmanual/Metafunctions-Logical.rst new file mode 100644 index 0000000..826d8c5 --- /dev/null +++ b/doc/src/refmanual/Metafunctions-Logical.rst @@ -0,0 +1,6 @@ + +.. |logical| replace:: `logical`__ +__ `Logical Operations`_ + +.. |Logical Operations| replace:: `Logical Operations`_ +.. |logical operations| replace:: `logical operations`_ diff --git a/doc/src/refmanual/Metafunctions-Trivial.rst b/doc/src/refmanual/Metafunctions-Trivial.rst new file mode 100644 index 0000000..896cbc5 --- /dev/null +++ b/doc/src/refmanual/Metafunctions-Trivial.rst @@ -0,0 +1,61 @@ + +The MPL provides a number of |Trivial Metafunction|\ s that a nothing more than +thin wrappers for a differently-named class nested type members. While important +in the context of `in-place metafunction composition`__, these metafunctions have +so little to them that presenting them in the same format as the rest of the +compoments in this manual would result in more boilerplate syntactic baggage than +the actual content. To avoid this problem, we instead factor out the common +metafunctions' requirements into the `corresponding concept`__ and gather all of +them in a single place |--| this subsection |--| in a compact table form that is +presented below. + +__ `Composition and Argument Binding`_ +__ `Trivial Metafunction`_ + + +Trivial Metafunctions Summary +============================= + +In the following table, ``x`` is an arbitrary class type. + +.. |first| replace:: |``first``|__ +.. |``first``| replace:: :refentry:`first` + +__ `trivial-first`_ + +.. |second| replace:: |``second``|__ +.. |``second``| replace:: :refentry:`second` + +__ `trivial-second`_ + + +.. |base| replace:: |``base``|__ +.. |``base``| replace:: :refentry:`base` + +__ `trivial-base`_ + + + +.. _`trivial-first`: +.. _`trivial-second`: +.. _`trivial-base`: + + ++---------------------------+-------------------------------------------+ +| Metafunction | Header | ++===========================+===========================================+ +| ``first::type`` | ``#include `` | ++---------------------------+-------------------------------------------+ +| ``second::type`` | ``#include `` | ++---------------------------+-------------------------------------------+ +| ``base::type`` | ``#include `` | ++---------------------------+-------------------------------------------+ + + +See Also +-------- + +|Metafunctions|, |Trivial Metafunction| + +.. |Trivial Metafunctions| replace:: `Trivial Metafunctions`__ +__ `Trivial`_ diff --git a/doc/src/refmanual/Metafunctions-Type.rst b/doc/src/refmanual/Metafunctions-Type.rst new file mode 100644 index 0000000..ca7b7cf --- /dev/null +++ b/doc/src/refmanual/Metafunctions-Type.rst @@ -0,0 +1,3 @@ + +.. |type selection| replace:: `type selection`__ +__ `Type Selection`_ diff --git a/doc/src/refmanual/Metafunctions.rst b/doc/src/refmanual/Metafunctions.rst new file mode 100644 index 0000000..b983e41 --- /dev/null +++ b/doc/src/refmanual/Metafunctions.rst @@ -0,0 +1,51 @@ + +The MPL includes a number of predefined metafunctions that can be roughly +classified in two categories: `general purpose metafunctions`, dealing with +conditional |type selection| and higher-order metafunction |invocation|, +|composition|, and |argument binding|, and `numeric metafunctions`, +incapsulating built-in and user-defined |arithmetic|, |comparison|, +|logical|, and |bitwise| operations. + +Given that it is possible to perform integer numeric computations at +compile time using the conventional operators notation, the need for the +second category might be not obvious, but it in fact plays a cental role in +making programming with MPL seemingly effortless. In +particular, there are at least two contexts where built-in language +facilities fall short [#portability]_\ : + +1) Passing a computation to an algorithm. +2) Performing a computation on non-integer data. + +The second use case deserves special attention. In contrast to the built-in, +strictly integer compile-time arithmetics, the MPL numeric metafunctions are +*polymorphic*, with support for *mixed-type arithmetics*. This means that they +can operate on a variety of numeric types |--| for instance, rational, +fixed-point or complex numbers, |--| and that, in general, you are allowed to +freely intermix these types within a single expression. See |Numeric +Metafunction| concept for more details on the MPL numeric infrastructure. + +.. The provided `infrastructure`__ allows easy plugging of user-defined numeric + types + Naturally, they also , meaning that you can perform a computation on the + arguments of different types, and the result will yeild the largest/most general + of them. For user-defined numeric types, they provide an `infrastructure`__ that + allows easy plugging and seemless integration with predefined library + types. details. + + __ `Numeric Metafunction`_ + + +To reduce a negative syntactical impact of the metafunctions notation +over the infix operator notation, all numeric metafunctions +allow to pass up to N arguments, where N is defined by the value of +|BOOST_MPL_LIMIT_METAFUNCTION_ARITY| configuration macro. + + +.. [#portability] All other considerations aside, as of the time of this writing + (early 2004), using built-in operators on integral constants still often + present a portability problem |--| many compilers cannot handle particular + forms of expressions, forcing us to use conditional compilation. Because MPL + numeric metafunctions work on types and encapsulate these kind of workarounds + internally, they elude these problems, so if you aim for portability, it is + generally adviced to use them in the place of the conventional operators, even + at the price of slightly decreased readability. diff --git a/doc/src/refmanual/NumericMetafunction.rst b/doc/src/refmanual/NumericMetafunction.rst new file mode 100644 index 0000000..62ebcf0 --- /dev/null +++ b/doc/src/refmanual/NumericMetafunction.rst @@ -0,0 +1,139 @@ +.. Metafunctions/Concepts//Numeric Metafunction |60 + +Numeric Metafunction +==================== + +Description +----------- + +A |Numeric Metafunction| is a |tag dispatched metafunction| that provides +a built-in infrastructure for easy implementation of mixed-type operations. + + +Expression requirements +----------------------- + +|In the following table...| ``op`` is a placeholder token for the actual +|Numeric Metafunction|'s name, and ``x``, ``y`` and |x1...xn| are +arbitrary numeric types. + ++-------------------------------------------+-----------------------+---------------------------+ +| Expression | Type | Complexity | ++===========================================+=======================+===========================+ +|``op_tag::type`` | |Integral Constant| | Amortized constant time. | ++-------------------------------------------+-----------------------+---------------------------+ +| .. parsed-literal:: | Any type | Unspecified. | +| | | | +| op_impl< | | | +| op_tag::type | | | +| , op_tag::type | | | +| >::apply::type | | | ++-------------------------------------------+-----------------------+---------------------------+ +|``op<``\ |x1...xn|\ ``>::type`` | Any type | Unspecified. | ++-------------------------------------------+-----------------------+---------------------------+ + + +Expression semantics +-------------------- + +.. parsed-literal:: + + typedef op_tag::type tag; + +:Semantics: + ``tag`` is a tag type for ``x`` for ``op``. + ``tag::value`` is ``x``\ 's *conversion rank*. + + +.. .......................................................................... + +.. parsed-literal:: + + typedef op_impl< + op_tag::type + , op_tag::type + >::apply::type r; + +:Semantics: + ``r`` is the result of ``op`` application on arguments ``x`` + and ``y``. + + +.. .......................................................................... + +.. parsed-literal:: + + typedef op<\ |x1...xn|\ >::type r; + +:Semantics: + ``r`` is the result of ``op`` application on arguments |x1...xn|. + + + + +Example +------- + +.. parsed-literal:: + + + struct complex_tag : int_<10> {}; + + template< typename Re, typename Im > struct complex + { + typedef complex_tag tag; + typedef complex type; + typedef Re real; + typedef Im imag; + }; + + template< typename C > struct real : C::real {}; + template< typename C > struct imag : C::imag {}; + + namespace boost { namespace mpl { + + template<> + struct plus_impl< complex_tag,complex_tag > + { + template< typename N1, typename N2 > struct apply + : complex< + plus< typename N1::real, typename N2::real > + , plus< typename N1::imag, typename N2::imag > + > + { + }; + }; + + }} + + typedef complex< int_<5>, int_<-1> > c1; + typedef complex< int_<-5>, int_<1> > c2; + + typedef plus r1; + BOOST_MPL_ASSERT_RELATION( real::value, ==, 0 ); + BOOST_MPL_ASSERT_RELATION( imag::value, ==, 0 ); + + typedef plus r2; + BOOST_MPL_ASSERT_RELATION( real::value, ==, 10 ); + BOOST_MPL_ASSERT_RELATION( imag::value, ==, -2 ); + + typedef plus r3; + BOOST_MPL_ASSERT_RELATION( real::value, ==, -10 ); + BOOST_MPL_ASSERT_RELATION( imag::value, ==, 2 ); + + + +Models +------ + +* |plus| +* |minus| +* |times| +* |divides| + + +See also +-------- + +|Tag Dispatched Metafunction|, |Metafunctions|, |numeric_cast| + diff --git a/doc/src/refmanual/PlaceholderExpression.rst b/doc/src/refmanual/PlaceholderExpression.rst new file mode 100644 index 0000000..7f7df34 --- /dev/null +++ b/doc/src/refmanual/PlaceholderExpression.rst @@ -0,0 +1,44 @@ +.. Metafunctions/Concepts//Placeholder Expression |40 + +Placeholder Expression +====================== + +Description +----------- + +A |Placeholder Expression| is a type that is either a |placeholder| or a class +template specialization with at least one argument that itself is a +|Placeholder Expression|. + + +Expression requirements +----------------------- + +If ``X`` is a class template, and ``a1``,... ``an`` are arbitrary types, then +``X`` is a |Placeholder Expression| if and only if all of the following +conditions hold: + +* At least one of the template arguments ``a1``,... ``an`` is a |placeholder| + or a |Placeholder Expression|. + +* All of ``X``\ 's template parameters, including the default ones, are types. + +* The number of ``X``\ 's template parameters, including the default ones, is + less or equal to the value of ``BOOST_MPL_LIMIT_METAFUNCTION_ARITY`` + `configuration macro`__. + +__ `Configuration`_ + + +Models +------ + +* |_1| +* ``plus<_, int_<2> >`` +* ``if_< less<_1, int_<7> >, plus<_1,_2>, _1 >`` + + +See also +-------- + +|Lambda Expression|, |Placeholders|, |Metafunctions|, |apply|, |lambda| diff --git a/doc/src/refmanual/Placeholders.rst b/doc/src/refmanual/Placeholders.rst new file mode 100644 index 0000000..547b0a1 --- /dev/null +++ b/doc/src/refmanual/Placeholders.rst @@ -0,0 +1,95 @@ +.. Metafunctions/Composition and Argument Binding//_1,_2,..._n |10 + +Placeholders +============ + +Synopsis +-------- + +.. parsed-literal:: + + namespace placeholders { + typedef |unspecified| _; + typedef arg<1> _1; + typedef arg<2> _2; + |...| + typedef arg<\ *n*\ > _\ *n*\ ; + } + + using placeholders::_; + using placeholders::_1; + using placeholders::_2; + |...| + using placeholders::_\ *n*\ ; + + +Description +----------- + +A placeholder in a form ``_``\ *n* is simply a synonym for the corresponding +``arg`` specialization. The unnamed placeholder ``_`` (underscore) carries +`special meaning`__ in bind and lambda expressions, and does not have +defined semantics outside of these contexts. + +Placeholder names can be made available in the user namespace through +``using namespace mpl::placeholders;`` directive. + +__ `bind semantics`_ + +Header +------ + +.. parsed-literal:: + + #include + +|Note:| The include might be omitted when using placeholders to construct a |Lambda +Expression| for passing it to MPL's own algorithm or metafunction: any library +component that is documented to accept a lambda expression makes the placeholders +implicitly available for the user code |-- end note| + + +Parameters +---------- + +None. + + +Expression semantics +-------------------- + +For any integral constant ``n`` in the range [1, |BOOST_MPL_LIMIT_METAFUNCTION_ARITY|\] and +arbitrary types |a1...an|: + + +.. parsed-literal:: + + typedef apply_wrap\ *n*\<_\ *n*\,a1,\ |...|\a\ *n*\ >::type x; + +:Return type: + A type. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef apply_wrap\ *n*\< arg<\ *n*\ >,a1,\ |...|\a\ *n* >::type x; + + +Example +------- + +.. parsed-literal:: + + typedef apply_wrap\ ``5``\< _1,bool,char,short,int,long >::type t1; + typedef apply_wrap\ ``5``\< _3,bool,char,short,int,long >::type t3; + + BOOST_MPL_ASSERT(( is_same< t1, bool > )); + BOOST_MPL_ASSERT(( is_same< t3, short > )); + + +See also +-------- + +|Composition and Argument Binding|, |arg|, |lambda|, |bind|, |apply|, |apply_wrap| diff --git a/doc/src/refmanual/RandomAccessIterator.rst b/doc/src/refmanual/RandomAccessIterator.rst new file mode 100644 index 0000000..d3e2ea1 --- /dev/null +++ b/doc/src/refmanual/RandomAccessIterator.rst @@ -0,0 +1,77 @@ +.. Iterators/Concepts//Random Access Iterator |30 + +Random Access Iterator +====================== + +Description +----------- + +A |Random Access Iterator| is a |Bidirectional Iterator| that provides +constant-time guarantees on moving the iterator an arbitrary number of positions +forward or backward and for measuring the distance to another iterator in the +same sequence. + +Refinement of +------------- + +|Bidirectional Iterator| + + +Expression requirements +----------------------- + +In addition to the requirements defined in |Bidirectional Iterator|, +the following requirements must be met. + ++---------------------------+-------------------------------------------+---------------------------+ +| Expression | Type | Complexity | ++===========================+===========================================+===========================+ +| ``next::type`` | |Random Access Iterator| | Amortized constant time | ++---------------------------+-------------------------------------------+---------------------------+ +| ``prior::type`` | |Random Access Iterator| | Amortized constant time | ++---------------------------+-------------------------------------------+---------------------------+ +| ``i::category`` | |Integral Constant|, convertible | Constant time | +| | to ``random_access_iterator_tag`` | | ++---------------------------+-------------------------------------------+---------------------------+ +| ``advance::type`` | |Random Access Iterator| | Amortized constant time | ++---------------------------+-------------------------------------------+---------------------------+ +| ``distance::type`` | |Integral Constant| | Amortized constant time | ++---------------------------+-------------------------------------------+---------------------------+ + + +Expression semantics +-------------------- + +.. parsed-literal:: + + typedef advance::type j; + +:Semantics: + See ``advance`` specification + + +.. .......................................................................... + +.. parsed-literal:: + + typedef distance::type n; + +:Semantics: + See ``distance`` specification + + +Invariants +---------- + +For any random access iterators ``i`` and ``j`` the following invariants always +hold: + +* If ``advance::type`` is well-defined, then + ``advance< advance::type, negate::type >::type`` is a null operation. + + +See also +-------- + +|Iterators|, |Bidirectional Iterator|, |Random Access Sequence|, |advance|, |distance| + diff --git a/doc/src/refmanual/RandomAccessSequence.rst b/doc/src/refmanual/RandomAccessSequence.rst new file mode 100644 index 0000000..1b5c59b --- /dev/null +++ b/doc/src/refmanual/RandomAccessSequence.rst @@ -0,0 +1,61 @@ +.. Sequences/Concepts//Random Access Sequence |30 + +Random Access Sequence +====================== + +Description +----------- + +A |Random Access Sequence| is a |Bidirectional Sequence| whose iterators model +|Random Access Iterator|. A random access sequence guarantees amortized constant +time access to an arbitrary sequence element. + +Refinement of +------------- + +|Bidirectional Sequence| + + +Expression requirements +----------------------- + +In addition to the requirements defined in |Bidirectional Sequence|, +for any |Random Access Sequence| ``s`` the following must be met: + ++---------------------------+-----------------------------------+---------------------------+ +| Expression | Type | Complexity | ++===========================+===================================+===========================+ +| ``begin::type`` | |Random Access Iterator| | Amortized constant time | ++---------------------------+-----------------------------------+---------------------------+ +| ``end::type`` | |Random Access Iterator| | Amortized constant time | ++---------------------------+-----------------------------------+---------------------------+ +| ``at::type`` | Any type | Amortized constant time | ++---------------------------+-----------------------------------+---------------------------+ + + +Expression semantics +-------------------- + +Semantics of an expression is defined only where it differs from, or is not +defined in |Bidirectional Sequence|. + ++---------------------------+-----------------------------------------------------------------------+ +| Expression | Semantics | ++===========================+=======================================================================+ +| ``at::type`` | The ``n``\ th element from the beginning of the sequence; see |at|. | ++---------------------------+-----------------------------------------------------------------------+ + + +Models +------ + +* |vector| +* |range_c| + + +See also +-------- + +|Sequences|, |Bidirectional Sequence|, |Extensible Sequence|, |Random Access Iterator|, +|begin| / |end|, |at| + diff --git a/doc/src/refmanual/ReversibleAlgorithm.rst b/doc/src/refmanual/ReversibleAlgorithm.rst new file mode 100644 index 0000000..806564d --- /dev/null +++ b/doc/src/refmanual/ReversibleAlgorithm.rst @@ -0,0 +1,163 @@ +.. Algorithms/Concepts//Reversible Algorithm + +Reversible Algorithm +==================== + +Description +----------- + +A |Reversible Algorithm| is a member of a pair of +transformation algorithms that iterate over their input sequence(s) +in opposite directions. For each reversible +algorithm ``x`` there exists a *counterpart* algorithm ``reverse_x``, +that exhibits the exact semantics of ``x`` except that the elements +of its input sequence argument(s) are processed in the reverse +order. + + +Expression requirements +----------------------- + +.. |s1...sn| replace:: *s*\ :sub:`1`,\ *s*\ :sub:`2`,...\ *s*\ :sub:`n` + +.. |s1...sn>::type| replace:: |s1...sn|, ...\ ``>::type`` +.. |s1...sn,in>::type| replace:: |s1...sn|, ... ``in>::type`` + +|In the following table...| ``x`` is a placeholder token for the actual +|Reversible Algorithm|'s name, |s1...sn| are +|Forward Sequence|\ s, and ``in`` is an |Inserter|. + ++---------------------------------------+-----------------------+-------------------+ +| Expression | Type | Complexity | ++=======================================+=======================+===================+ +|``x<``\ |s1...sn>::type| | |Forward Sequence| | Unspecified. | ++---------------------------------------+-----------------------+-------------------+ +|``x<``\ |s1...sn,in>::type| | Any type | Unspecified. | ++---------------------------------------+-----------------------+-------------------+ +|``reverse_x<``\ |s1...sn>::type| | |Forward Sequence| | Unspecified. | ++---------------------------------------+-----------------------+-------------------+ +|``reverse_x<``\ |s1...sn,in>::type| | Any type | Unspecified. | ++---------------------------------------+-----------------------+-------------------+ + + +Expression semantics +-------------------- + +.. parsed-literal:: + + typedef x<\ *s*\ :sub:`1`,\ *s*\ :sub:`2`,...\ *s*\ :sub:`n`,...>::type t; + +:Precondition: + *s*\ :sub:`1` is an |Extensible Sequence|. + +:Semantics: + ``t`` is equivalent to + + .. parsed-literal:: + + x< + *s*\ :sub:`1`,\ *s*\ :sub:`2`,...\ *s*\ :sub:`n`,... + , back_inserter< clear<\ *s*\ :sub:`1`>::type > + >::type + + if ``has_push_back<``\ *s*\ :sub:`1`\ ``>::value == true`` and + + .. parsed-literal:: + + reverse_x< + *s*\ :sub:`1`,\ *s*\ :sub:`2`,...\ *s*\ :sub:`n`,... + , front_inserter< clear<\ *s*\ :sub:`1`>::type > + >::type + + otherwise. + +.. .......................................................................... + + +.. parsed-literal:: + + typedef x<\ *s*\ :sub:`1`,\ *s*\ :sub:`2`,...\ *s*\ :sub:`n`,...\ in>::type t; + +:Semantics: + ``t`` is the result of an ``x`` invocation with arguments + *s*\ :sub:`1`,\ *s*\ :sub:`2`,... \ *s*\ :sub:`n`,...\ ``in``. + + +.. .......................................................................... + + +.. parsed-literal:: + + typedef reverse_x<\ *s*\ :sub:`1`,\ *s*\ :sub:`2`,... \ *s*\ :sub:`n`,... >::type t; + +:Precondition: + *s*\ :sub:`1` is an |Extensible Sequence|. + +:Semantics: + ``t`` is equivalent to + + .. parsed-literal:: + + x< + *s*\ :sub:`1`,\ *s*\ :sub:`2`,...\ *s*\ :sub:`n`,... + , front_inserter< clear<\ *s*\ :sub:`1`>::type > + >::type + + if ``has_push_front<``\ *s*\ :sub:`1`\ ``>::value == true`` and + + .. parsed-literal:: + + reverse_x< + *s*\ :sub:`1`,\ *s*\ :sub:`2`,...\ *s*\ :sub:`n`,... + , back_inserter< clear<\ *s*\ :sub:`1`>::type > + >::type + + otherwise. + + +.. .......................................................................... + +.. parsed-literal:: + + typedef reverse_x<\ *s*\ :sub:`1`,\ *s*\ :sub:`2`,...\ *s*\ :sub:`n`,... in>::type t; + +:Semantics: + ``t`` is the result of a ``reverse_x`` invocation with arguments + *s*\ :sub:`1`,\ *s*\ :sub:`2`,...\ *s*\ :sub:`n`,...\ ``in``. + + +Example +------- + +.. parsed-literal:: + + typedef transform< + range_c + , plus<_1,int_<7> > + , back_inserter< vector0<> > + >::type r1; + + typedef transform< r1, minus<_1,int_<2> > >::type r2; + typedef reverse_transform< + r2 + , minus<_1,5> + , front_inserter< vector0<> > + >::type r3; + + BOOST_MPL_ASSERT(( equal > )); + BOOST_MPL_ASSERT(( equal > )); + BOOST_MPL_ASSERT(( equal > )); + + +Models +------ + +* |transform| +* |remove| +* |replace| + +See also +-------- + +|Transformation Algorithms|, |Inserter| + diff --git a/doc/src/refmanual/Sequences-Classes.rst b/doc/src/refmanual/Sequences-Classes.rst new file mode 100644 index 0000000..6af9d89 --- /dev/null +++ b/doc/src/refmanual/Sequences-Classes.rst @@ -0,0 +1,6 @@ + +The MPL provides a large number of predefined general-purpose sequence +classes covering most of the typical metaprogramming needs out-of-box. + +.. For all library-supplied sequences a publicly-derived class with no additional + members is equivalent except for type identity. diff --git a/doc/src/refmanual/Sequences-Concepts.rst b/doc/src/refmanual/Sequences-Concepts.rst new file mode 100644 index 0000000..0cf016c --- /dev/null +++ b/doc/src/refmanual/Sequences-Concepts.rst @@ -0,0 +1,28 @@ + +The taxonomy of sequence concepts in MPL parallels the taxonomy of the MPL +|iterators|, with two additional classification dimensions: +`extensibility` and `associativeness`. + +.. The latter two are orthogonal to + sequence traversal characteristics, but not to each other, meaning that + a sequence can be characterized as both `Bidirectional`__ + and `Back Extensible`__, or `Bidirectional`__ and + `Extensible Associative`__, but not as `Bidirectional`__, + `Back Extensible`__ *and* `Extensible Associative`__. + + __ `Bidirectional Sequence`_ + __ `Back Extensible Sequence`_ + __ `Bidirectional Sequence`_ + __ `Extensible Associative Sequence`_ + __ `Bidirectional Sequence`_ + __ `Back Extensible Sequence`_ + __ `Extensible Associative Sequence`_ + + + Two utility concepts, |Variadic Sequence| and |Integral Sequence Wrapper|, + are not applicable in generic contexts, but are used to group together + the common parts of different sequence classes' specifications. + + +.. |sequence concepts| replace:: `sequence concepts`__ +__ `label-Sequences-Concepts`_ diff --git a/doc/src/refmanual/Sequences-Intrinsic.rst b/doc/src/refmanual/Sequences-Intrinsic.rst new file mode 100644 index 0000000..faef490 --- /dev/null +++ b/doc/src/refmanual/Sequences-Intrinsic.rst @@ -0,0 +1,17 @@ + +The metafunctions that form the essential interface of sequence `classes`__ +documented in the corresponding |sequence concepts| are known as +*intrinsic sequence operations*. They differ from generic +|sequence algorithms| in that, in general, they need to be implemented +from scratch for each new sequence class [#intrinsic]_. + +__ `label-Sequences-Classes`_ + +It's worth noting that STL counterparts of these metafunctions are +usually implemented as member functions. + +.. [#intrinsic] In practice, many of intrinsic metafunctions offer a + default implementation that will work in majority of cases, given + that you've implemented the core functionality they rely on (such + as |begin| / |end|). + diff --git a/doc/src/refmanual/Sequences-Views.rst b/doc/src/refmanual/Sequences-Views.rst new file mode 100644 index 0000000..2dc694e --- /dev/null +++ b/doc/src/refmanual/Sequences-Views.rst @@ -0,0 +1,11 @@ + +A *view* is a sequence adaptor delivering an altered presentation of +one or more underlying sequences. Views are lazy, meaning that their +elements are only computed on demand. Similarly to the short-circuit +|logical operations| and |eval_if|, views make it possible to avoid +premature errors and inefficiencies from computations whose results +will never be used. When approached with views in mind, many +algorithmic problems can be solved in a simpler, more conceptually +precise, more expressive way. + +.. |Views| replace:: `Views`_ diff --git a/doc/src/refmanual/Sequences.rst b/doc/src/refmanual/Sequences.rst new file mode 100644 index 0000000..84c371f --- /dev/null +++ b/doc/src/refmanual/Sequences.rst @@ -0,0 +1,18 @@ + +Compile-time sequences of types are one of the basic concepts of C++ +template metaprogramming. Differences in types of objects being +manipulated is the most common point of variability of similar, but +not identical designs, and these are a direct target for +metaprogramming. Templates were originally designed to address this +exact problem. However, without predefined mechanisms for +representing and manipulating *sequences* of types as opposed to +standalone template parameters, high-level template metaprogramming +is severely limited in its capabitilies. + +The MPL recognizes the importance of type sequences as a fundamental +building block of many higher-level metaprogramming designs by +providing us with a conceptual framework for formal reasoning +and understanding of sequence properties, guarantees and +characteristics, as well as a first-class implementation of that +framework |--| a wealth of tools for concise, convenient, +conceptually precise and efficient sequence manipulation. diff --git a/doc/src/refmanual/TagDispatchedMetafunction.rst b/doc/src/refmanual/TagDispatchedMetafunction.rst new file mode 100644 index 0000000..e6b6380 --- /dev/null +++ b/doc/src/refmanual/TagDispatchedMetafunction.rst @@ -0,0 +1,163 @@ +.. Metafunctions/Concepts//Tag Dispatched Metafunction |50 + +Tag Dispatched Metafunction +=========================== + +Summary +------- + +A |Tag Dispatched Metafunction| is a |Metafunction| that employs a +*tag dispatching* technique in its implementation to build an +infrastructure for easy overriding/extenstion of the metafunction's +behavior. + + +Notation +-------- + +.. _`tag-metafunction`: + ++---------------------------+-----------------------------------------------------------+ +| Symbol | Legend | ++===========================+===========================================================+ +| |``name``| | A placeholder token for the specific metafunction's name. | ++---------------------------+-----------------------------------------------------------+ +| |``tag-metafunction``| | A placeholder token for the tag metafunction's name. | ++---------------------------+-----------------------------------------------------------+ +| |``tag``| | A placeholder token for one of possible tag types | +| | returned by the tag metafunction. | ++---------------------------+-----------------------------------------------------------+ + +.. |``name``| replace:: *name* +.. |``tag-metafunction``| replace:: *tag-metafunction* +.. |``tag``| replace:: *tag* + + +Synopsis +-------- + +.. parsed-literal:: + + template< typename Tag > struct *name*\_impl; + + template< + typename X + *[, ...]* + > + struct *name* + : *name*\_impl< typename *tag-metafunction*\::type > + ::template apply + { + }; + + template< typename Tag > struct *name*\_impl + { + template< typename X *[, ...]* > struct apply + { + // *default implementation* + }; + }; + + template<> struct *name*\_impl<*tag*> + { + template< typename X *[, ...]* > struct apply + { + // *tag-specific implementation* + }; + }; + + +Description +----------- + +The usual mechanism for overriding a metafunction's behavior is class +template specialization |--| given a library-defined metafunction ``f``, +it's possible to write a specialization of ``f`` for a specific type +``user_type`` that would have the required semantics [#spec]_. + +While this mechanism is always available, it's not always the most +convenient one, especially if it is desirable to specialize a +metafunction's behavior for a *family* of related types. A typical +example of it is numbered forms of sequence classes in MPL itself +(``list0``, ..., ``list50``, et al.), and sequence classes in general. + +A |Tag Dispatched Metafunction| is a concept name for an instance of +the metafunction implementation infrastructure being employed by the +library to make it easier for users and implementors to override the +behavior of library's metafunctions operating on families of specific +types. + +The infrastructure is built on a variation of the technique commonly +known as *tag dispatching* (hence the concept name), +and involves three entities: a metafunction itself, an associated +tag-producing |tag-metafunction|, and the metafunction's +implementation, in the form of a |Metafunction Class| template +parametrized by a ``Tag`` type parameter. The metafunction redirects +to its implementation class template by invoking its specialization +on a tag type produced by the tag metafunction with the original +metafunction's parameters. + + +.. [#spec] Usually such user-defined specialization is still required + to preserve the ``f``'s original invariants and complexity requirements. + + +Example +------- + +.. parsed-literal:: + + #include + + namespace user { + + struct bitset_tag; + + struct bitset0 + { + typedef bitset_tag tag; + // ... + }; + + template< typename B0 > struct bitset1 + { + typedef bitset_tag tag; + // ... + }; + + template< typename B0, *...,* typename B\ *n* > struct bitset\ *n* + { + typedef bitset_tag tag; + // ... + }; + + } // namespace user + + namespace boost { namespace mpl { + template<> struct size_impl + { + template< typename Bitset > struct apply + { + typedef typename Bitset::size type; + }; + }; + }} + + +Models +------- + +* |sequence_tag| + + +See also +-------- + +|Metafunction|, |Metafunction Class|, |Numeric Metafunction| + + +.. |tag-metafunction| replace:: `tag metafunction`__ +__ `tag-metafunction`_ + +.. |tag dispatched| replace:: `tag dispatched`__ +__ `Tag Dispatched Metafunction`_ diff --git a/doc/src/refmanual/TrivialMetafunction.rst b/doc/src/refmanual/TrivialMetafunction.rst new file mode 100644 index 0000000..9739417 --- /dev/null +++ b/doc/src/refmanual/TrivialMetafunction.rst @@ -0,0 +1,60 @@ +.. Metafunctions/Concepts//Trivial Metafunction |70 + +Trivial Metafunction +==================== + +Description +----------- + +A |Trivial Metafunction| accepts a single argument of a class type ``x`` and +returns the ``x``\ 's nested type member ``x::name``, where ``name`` is +a placeholder token for the actual member's name accessed by a specific +metafunction's instance. By convention, all `trivial metafunctions`__ in MPL +are named after the members they provide assess to. For instance, a |Trivial +Metafunction| named ``first`` reaches for the ``x``\ 's nested member +``::first``. + +__ `Trivial Metafunctions Summary`_ + + +Expression requirements +----------------------- + +|In the following table...| ``name`` is placeholder token for the names of +the |Trivial Metafunction| itself and the accessed member, and ``x`` is +a class type such that ``x::name`` is a valid *type-name*. + ++---------------------------+-------------------+---------------------------+ +| Expression | Type | Complexity | ++===========================+===================+===========================+ +| ``name::type`` | Any type | Constant time. | ++---------------------------+-------------------+---------------------------+ + + +Expression semantics +-------------------- + +.. parsed-literal:: + + typedef name::type r; + +:Precondition: + ``x::name`` is a valid *type-name*. + +:Semantics: + ``is_same::value == true``. + + +Models +------ + +* |first| +* |second| +* |base| + + +See also +-------- + +|Metafunctions|, |Trivial Metafunctions|, |identity| + diff --git a/doc/src/refmanual/VariadicSequence.rst b/doc/src/refmanual/VariadicSequence.rst new file mode 100644 index 0000000..02acc5c --- /dev/null +++ b/doc/src/refmanual/VariadicSequence.rst @@ -0,0 +1,118 @@ +.. Sequences/Concepts//Variadic Sequence |100 + +Variadic Sequence +================= + +Description +----------- + +A |Variadic Sequence| is a member of a family of sequence classes with both +*variadic* and *numbered* forms. If ``seq`` is a generic name for some +|Variadic Sequence|, its *variadic form* allows us to specify a sequence of +*n* elements |t1...tn|, for any *n* from 0 up to a +`preprocessor-configurable limit`__ ``BOOST_MPL_LIMIT_``\ *seq*\ ``_SIZE``, +using the following notation: + +__ `Configuration`_ + + .. line-block:: + + ``seq<``\ |t1...tn|\ ``>`` + +By contrast, each *numbered* sequence form accepts the exact number of elements +that is encoded in the name of the corresponding class template: + + .. line-block:: + + ``seq``\ *n*\ ``<``\ |t1...tn|\ ``>`` + +For numbered forms, there is no predefined top limit for *n*, aside from compiler +limitations on the number of template parameters. + +.. The variadic form of sequence ``seq`` is defined in + ```` header. + The numbered forms are defined in batches of 10. + + +Expression requirements +----------------------- + +|In the following table...| ``seq`` is a placeholder token for the actual +|Variadic Sequence| name. + +.. |seq| replace:: ``seq<``\ |t1...tn|\ ``>`` +.. |seq::type| replace:: ``seq<``\ |t1...tn|\ ``>::type`` + +.. |seqn| replace:: ``seq``\ *n*\ ``<``\ |t1...tn|\ ``>`` +.. |seqn::type| replace:: ``seq``\ *n*\ ``<``\ |t1...tn|\ ``>::type`` + + ++---------------------------+-----------------------+---------------------------+ +| Expression | Type | Complexity | ++===========================+=======================+===========================+ +| |seq| | |Forward Sequence| | Amortized constant time | ++---------------------------+-----------------------+---------------------------+ +| |seq::type| | |Forward Sequence| | Amortized constant time | ++---------------------------+-----------------------+---------------------------+ +| |seqn| | |Forward Sequence| | Amortized constant time | ++---------------------------+-----------------------+---------------------------+ +| |seqn::type| | |Forward Sequence| | Amortized constant time | ++---------------------------+-----------------------+---------------------------+ + + +Expression semantics +-------------------- + + +.. parsed-literal:: + + typedef seq<|t1...tn|> s; + typedef seq\ *n*\ <|t1...tn|> s; + +:Semantics: + ``s`` is a sequence of elements |t1...tn|. + +:Postcondition: + ``size::value == n``. + + .. FIXME .. parsed-literal:: + + BOOST_MPL_ASSERT((|is_same|\< at_c::type,\ |t1| >)); + BOOST_MPL_ASSERT((|is_same|\< at_c::type,\ |t2| >)); + ... + BOOST_MPL_ASSERT((|is_same|\< at_c::type,\ |tn| >)); + +.. .......................................................................... + +.. parsed-literal:: + + typedef seq<|t1...tn|>::type s; + typedef seq\ *n*\ <|t1...tn|>::type s; + +:Semantics: + ``s`` is identical to ``seq``\ *n*\ ``<``\ |t1...tn| ``>``. + +:Postcondition: + ``size::value == n``. + + +Models +------ + +* |vector| +* |list| +* |map| + +See also +-------- + +|Sequences|, |Configuration|, |Integral Sequence Wrapper| + +.. |variadic| replace:: `variadic`__ +__ `Variadic Sequence`_ + +.. |variadic forms| replace:: `variadic forms`__ +__ `Variadic Sequence`_ + +.. |numbered forms| replace:: `numbered forms`__ +__ `Variadic Sequence`_ diff --git a/doc/src/refmanual/accumulate.rst b/doc/src/refmanual/accumulate.rst new file mode 100644 index 0000000..7a772e1 --- /dev/null +++ b/doc/src/refmanual/accumulate.rst @@ -0,0 +1,102 @@ +.. Algorithms/Iteration Algorithms//accumulate |10 + +accumulate +========== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + , typename State + , typename ForwardOp + > + struct accumulate + { + typedef |unspecified| type; + }; + + + +Description +----------- + +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/end| in order. +|Note:| ``accumulate`` is a synonym for |fold| |-- end note| + + +Header +------ + +.. parsed-literal:: + + #include + + +Parameters +---------- + ++---------------+-------------------------------+---------------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===============================+===================================================+ +| ``Sequence`` | |Forward Sequence| | A sequence to iterate. | ++---------------+-------------------------------+---------------------------------------------------+ +| ``State`` | Any type | The initial state for the first ``ForwardOp`` | +| | | application. | ++---------------+-------------------------------+---------------------------------------------------+ +| ``ForwardOp`` | Binary |Lambda Expression| | The operation to be executed on forward | +| | | traversal. | ++---------------+-------------------------------+---------------------------------------------------+ + + +Expression semantics +-------------------- + +For any |Forward Sequence| ``s``, binary |Lambda Expression| ``op``, and arbitrary type ``state``: + + +.. parsed-literal:: + + typedef accumulate::type t; + +:Return type: + A type. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef fold::type t; + + + +Complexity +---------- + +Linear. Exactly ``size::value`` applications of ``op``. + + +Example +------- + +.. parsed-literal:: + + typedef vector types; + typedef accumulate< + types + , int_<0> + , if_< is_float<_2>,next<_1>,_1 > + >::type number_of_floats; + + BOOST_MPL_ASSERT_RELATION( number_of_floats::value, ==, 4 ); + + +See also +-------- + +|Algorithms|, |fold|, |reverse_fold|, |iter_fold|, |reverse_iter_fold|, |copy|, |copy_if| diff --git a/doc/src/refmanual/advance.rst b/doc/src/refmanual/advance.rst new file mode 100644 index 0000000..c86c5c6 --- /dev/null +++ b/doc/src/refmanual/advance.rst @@ -0,0 +1,129 @@ +.. Iterators/Iterator Metafunctions//advance |10 + +advance +======= + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Iterator + , typename N + > + struct advance + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Moves ``Iterator`` by the distance ``N``. For |bidirectional| and +|random access| iterators, the distance may be negative. + + +Header +------ + +.. parsed-literal:: + + #include + + +Parameters +---------- + ++---------------+---------------------------+-----------------------------------+ +| Parameter | Requirement | Description | ++===============+===========================+===================================+ +| ``Iterator`` | |Forward Iterator| | An iterator to advance. | ++---------------+---------------------------+-----------------------------------+ +| ``N`` | |Integral Constant| | A distance. | ++---------------+---------------------------+-----------------------------------+ + + +Model Of +-------- + +|Tag Dispatched Metafunction| + + +Expression semantics +-------------------- + +For a |Forward Iterator| ``iter`` and arbitrary |Integral Constant| ``n``: + +.. parsed-literal:: + + typedef advance::type j; + +:Return type: + |Forward Iterator|. + +:Precondition: + If ``Iterator`` is a |Forward Iterator|, ``n::value`` must be nonnegative. + +:Semantics: + Equivalent to: + + .. parsed-literal:: + + typedef iter i0; + typedef next::type i1; + |...| + typedef next::type j; + + if ``n::value > 0``, and + + .. parsed-literal:: + + typedef iter i0; + typedef prior::type i1; + |...| + typedef prior::type j; + + otherwise. + + +:Postcondition: + ``j`` is dereferenceable or past-the-end; + ``distance::value == n::value`` if ``n::value > 0``, and + ``distance::value == n::value`` otherwise. + + +Complexity +---------- + +Amortized constant time if ``iter`` is a model of +|Random Access Iterator|, otherwise linear time. + + +Example +------- + +.. parsed-literal:: + + typedef range_c numbers; + typedef begin::type first; + typedef end::type last; + + typedef advance >::type i1; + typedef advance >::type i2; + + BOOST_MPL_ASSERT(( boost::is_same )); + BOOST_MPL_ASSERT(( boost::is_same )); + + +See also +-------- + +|Iterators|, |Tag Dispatched Metafunction|, |distance|, |next| + +.. |bidirectional| replace:: `bidirectional`_ +.. _bidirectional: `Bidirectional Iterator`_ +.. |random access| replace:: `random access`_ +.. _random access: `Random Access Iterator`_ diff --git a/doc/src/refmanual/always.rst b/doc/src/refmanual/always.rst new file mode 100644 index 0000000..ecd3e1a --- /dev/null +++ b/doc/src/refmanual/always.rst @@ -0,0 +1,87 @@ +.. Metafunctions/Miscellaneous//always |20 + +always +====== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename X + > + struct always + { + // |unspecified| + // |...| + }; + + +Description +----------- + +``always`` specialization is a variadic |Metafunction Class| always returning the +same type, ``X``, regardless of the number and types of passed arguments. + + +Header +------ + +.. parsed-literal:: + + #include + +Model of +-------- + +|Metafunction Class| + + +Parameters +---------- + ++---------------+-------------------+-----------------------------------+ +| Parameter | Requirement | Description | ++===============+===================+===================================+ +| ``X`` | Any type | A type to be returned. | ++---------------+-------------------+-----------------------------------+ + + +Expression semantics +-------------------- + +For an arbitrary type ``x``: + + +.. parsed-literal:: + + typedef always f; + +:Return type: + |Metafunction Class|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + struct f : bind< identity<_1>, x > {}; + + +Example +------- + +.. parsed-literal:: + + typedef always always_true; + + BOOST_MPL_ASSERT(( apply< always_true,false\_> )); + BOOST_MPL_ASSERT(( apply< always_true,false\_,false\_ > )); + BOOST_MPL_ASSERT(( apply< always_true,false\_,false\_,false\_ > )); + + +See also +-------- + +|Metafunctions|, |Metafunction Class|, |identity|, |bind|, |apply| diff --git a/doc/src/refmanual/and_.rst b/doc/src/refmanual/and_.rst new file mode 100644 index 0000000..9d95ca3 --- /dev/null +++ b/doc/src/refmanual/and_.rst @@ -0,0 +1,104 @@ +.. Metafunctions/Logical Operations//and_ |10 + +and\_ +===== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename F1 + , typename F2 + |...| + , typename F\ *n* = |unspecified| + > + struct and\_ + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns the result of short-circuit *logical and* (``&&``) operation on its arguments. + + +Header +------ + +.. parsed-literal:: + + #include + #include + + +Parameters +---------- + ++---------------+---------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===========================+===============================================+ +| |F1...Fn| | Nullary |Metafunction| | Operation's arguments. | ++---------------+---------------------------+-----------------------------------------------+ + + +Expression semantics +-------------------- + +For arbitrary nullary |Metafunction|\ s |f1...fn|: + +.. parsed-literal:: + + typedef and_::type r; + +:Return type: + |Integral Constant|. + +:Semantics: + ``r`` is ``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; the operands subsequent to the first + ``f``\ *i* metafunction that evaluates to ``false`` are not evaluated. + + +.. .......................................................................... + +.. parsed-literal:: + + typedef and_ r; + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + struct r : and_::type {}; + + +Example +------- + +.. parsed-literal:: + + struct unknown; + + BOOST_MPL_ASSERT(( and_< true\_,true\_ > )); + BOOST_MPL_ASSERT_NOT(( and_< false\_,true\_ > )); + BOOST_MPL_ASSERT_NOT(( and_< true\_,false\_ > )); + BOOST_MPL_ASSERT_NOT(( and_< false\_,false\_ > )); + BOOST_MPL_ASSERT_NOT(( and_< false\_,unknown > )); // OK + BOOST_MPL_ASSERT_NOT(( and_< false\_,unknown,unknown > )); // OK too + + +See also +-------- + +|Metafunctions|, |Logical Operations|, |or_|, |not_| + diff --git a/doc/src/refmanual/apply.rst b/doc/src/refmanual/apply.rst new file mode 100644 index 0000000..28ace90 --- /dev/null +++ b/doc/src/refmanual/apply.rst @@ -0,0 +1,114 @@ +.. Metafunctions/Invocation//apply |10 + +apply +===== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename F + > + struct apply0 + { + typedef |unspecified| type; + }; + + template< + typename F, typename A1 + > + struct apply1 + { + typedef |unspecified| type; + }; + + |...| + + template< + typename F, typename A1,\ |...| typename An + > + struct apply\ *n* + { + typedef |unspecified| type; + }; + + template< + typename F + , typename A1 = |unspecified| + |...| + , typename An = |unspecified| + > + struct apply + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Invokes a |Metafunction Class| or a |Lambda Expression| ``F`` with arguments ``A1``,... ``An``. + + +Header +------ + +.. parsed-literal:: + + #include + + +Parameters +---------- + ++---------------+-----------------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===================================+===============================================+ +| ``F`` | |Lambda Expression| | An expression to invoke. | ++---------------+-----------------------------------+-----------------------------------------------+ +| |A1...An| | Any type | Invocation arguments. | ++---------------+-----------------------------------+-----------------------------------------------+ + + +Expression semantics +-------------------- + +For any |Lambda Expression| ``f`` and arbitrary types ``a1``,... ``an``: + + +.. parsed-literal:: + + typedef apply\ *n*\::type t; + typedef apply::type t; + +:Return type: + Any type. + +:Semantics: + Equivalent to ``typedef apply_wrap``\ *n*\ ``< lambda::type,a1,... an>::type t;``. + + +Example +------- + +.. parsed-literal:: + + template< typename N1, typename N2 > struct int_plus + : int_<( N1::value + N2::value )> + { + }; + + typedef apply< int_plus<_1,_2>, int_<2>, int_<3> >::type r1; + typedef apply< quote\ ``2``\ , int_<2>, int_<3> >::type r2; + + BOOST_MPL_ASSERT_RELATION( r1::value, ==, 5 ); + BOOST_MPL_ASSERT_RELATION( r2::value, ==, 5 ); + + +See also +-------- + +|Metafunctions|, |apply_wrap|, |lambda|, |quote|, |bind| diff --git a/doc/src/refmanual/apply_wrap.rst b/doc/src/refmanual/apply_wrap.rst new file mode 100644 index 0000000..02c3b14 --- /dev/null +++ b/doc/src/refmanual/apply_wrap.rst @@ -0,0 +1,129 @@ +.. Metafunctions/Invocation//apply_wrap |20 + +apply_wrap +========== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename F + > + struct apply_wrap0 + { + typedef |unspecified| type; + }; + + template< + typename F, typename A1 + > + struct apply_wrap1 + { + typedef |unspecified| type; + }; + + |...| + + template< + typename F, typename A1,\ |...| typename An + > + struct apply_wrap\ *n* + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Invokes a |Metafunction Class| ``F`` with arguments ``A1``,... ``An``. + +In essence, ``apply_wrap`` forms are nothing more than syntactic wrappers around +``F::apply::type`` / ``F::apply::type`` expressions (hence the name). +They provide a more concise notation and higher portability than their +underlaying constructs at the cost of an extra template instantiation. + + +Header +------ + +.. parsed-literal:: + + #include + + +Parameters +---------- + ++---------------+-----------------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===================================+===============================================+ +| ``F`` | |Metafunction Class| | A metafunction class to invoke. | ++---------------+-----------------------------------+-----------------------------------------------+ +| |A1...An| | Any type | Invocation arguments. | ++---------------+-----------------------------------+-----------------------------------------------+ + + +Expression semantics +-------------------- + +For any |Metafunction Class| ``f`` and arbitrary types |a1...an|: + + +.. parsed-literal:: + + typedef apply_wrap\ *n*\ ::type t; + +:Return type: + Any type. + +:Semantics: + If ``n > 0``, equivalent to ``typedef f::apply::type t;``, + otherwise equivalent to either ``typedef f::apply::type t;`` or + ``typedef f::apply<>::type t;`` depending on whether ``f::apply`` is + a class or a class template. + + +Example +------- + +.. parsed-literal:: + + struct f0 + { + template< typename T = int > struct apply + { + typedef char type; + }; + }; + + struct g0 + { + struct apply { typedef char type; }; + }; + + struct f2 + { + template< typename T1, typename T2 > struct apply + { + typedef T2 type; + }; + }; + + + typedef apply_wrap\ ``0``\ < f0 >::type r1; + typedef apply_wrap\ ``0``\ < g0 >::type r2; + typedef apply_wrap\ ``2``\ < f2,int,char >::type r3; + + BOOST_MPL_ASSERT(( is_same )); + BOOST_MPL_ASSERT(( is_same )); + BOOST_MPL_ASSERT(( is_same )); + + +See also +-------- + +|Metafunctions|, |Invocation|, |apply|, |lambda|, |quote|, |bind|, |protect| diff --git a/doc/src/refmanual/arg.rst b/doc/src/refmanual/arg.rst new file mode 100644 index 0000000..ef489e5 --- /dev/null +++ b/doc/src/refmanual/arg.rst @@ -0,0 +1,90 @@ +.. Metafunctions/Composition and Argument Binding//arg |50 + +arg +=== + +Synopsis +-------- + +.. parsed-literal:: + + template< int n > struct arg; + + template<> struct arg<1> + { + template< typename A1,\ |...| typename A\ *n* = |unspecified| > + struct apply + { + typedef A1 type; + }; + }; + + |...| + + template<> struct arg<\ *n*\> + { + template< typename A1,\ |...| typename A\ *n* > + struct apply + { + typedef A\ *n* type; + }; + }; + + +Description +----------- + +``arg`` specialization is a |Metafunction Class| that return the ``n``\ th of its arguments. + + +Header +------ + +.. parsed-literal:: + + #include + + +Parameters +---------- + ++---------------+-----------------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===================================+===============================================+ +| ``n`` | An integral constant | A number of argument to return. | ++---------------+-----------------------------------+-----------------------------------------------+ + + +Expression semantics +-------------------- + +For any integral constant ``n`` in the range [1, |BOOST_MPL_LIMIT_METAFUNCTION_ARITY|\] and +arbitrary types |a1...an|: + +.. parsed-literal:: + + typedef apply_wrap\ *n*\< arg<\ *n*\ >,a1,\ |...|\a\ *n* >::type x; + +:Return type: + A type. + +:Semantics: + ``x`` is identical to ``an``. + + +Example +------- + +.. parsed-literal:: + + typedef apply_wrap\ ``5``\< arg<1>,bool,char,short,int,long >::type t1; + typedef apply_wrap\ ``5``\< arg<3>,bool,char,short,int,long >::type t3; + + BOOST_MPL_ASSERT(( is_same< t1, bool > )); + BOOST_MPL_ASSERT(( is_same< t3, short > )); + + +See also +-------- + +|Composition and Argument Binding|, |Placeholders|, |lambda|, |bind|, |apply|, |apply_wrap| diff --git a/doc/src/refmanual/at.rst b/doc/src/refmanual/at.rst new file mode 100644 index 0000000..69f7994 --- /dev/null +++ b/doc/src/refmanual/at.rst @@ -0,0 +1,173 @@ +.. Sequences/Intrinsic Metafunctions//at + +at +== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + , typename N + > + struct at + { + typedef |unspecified| type; + }; + + template< + typename AssocSeq + , typename Key + , typename Default = |unspecified| + > + struct at + { + typedef |unspecified| type; + }; + + +Description +----------- + +``at`` is an |overloaded name|: + +* ``at`` returns the ``N``-th element from the beginning of the + |Forward Sequence| ``Sequence``. + +* ``at`` returns the first element associated with ``Key`` + in the |Associative Sequence| ``AssocSeq``, or ``Default`` if no such element + exists. + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Tag Dispatched Metafunction| + + +Parameters +---------- + ++---------------+---------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===========================+===============================================+ +| ``Sequence`` | |Forward Sequence| | A sequence to be examined. | ++---------------+---------------------------+-----------------------------------------------+ +| ``AssocSeq`` | |Associative Sequence| | A sequence to be examined. | ++---------------+---------------------------+-----------------------------------------------+ +| ``N`` | |Integral Constant| | An offset from the beginning of the sequence | +| | | specifying the element to be retrieved. | ++---------------+---------------------------+-----------------------------------------------+ +| ``Key`` | Any type | A key for the element to be retrieved. | ++---------------+---------------------------+-----------------------------------------------+ +| ``Default`` | Any type | A default value to return if the element is | +| | | not found. | ++---------------+---------------------------+-----------------------------------------------+ + + +Expression semantics +-------------------- + +.. compound:: + :class: expression-semantics + + For any |Forward Sequence| ``s``, and |Integral Constant| ``n``: + + .. parsed-literal:: + + typedef at::type t; + + :Return type: + A type. + + :Precondition: + ``0 <= n::value < size::value``. + + :Semantics: + Equivalent to + + .. parsed-literal:: + + typedef deref< advance< begin::type,n >::type >::type t; + + +.. compound:: + :class: expression-semantics + + For any |Associative Sequence| ``s``, and arbitrary types ``key`` and ``x``: + + .. parsed-literal:: + + typedef at::type t; + + :Return type: + A type. + + :Semantics: + If ``has_key::value == true``, ``t`` is the value type associated with ``key``; + otherwise ``t`` is identical to ``x``. + + + .. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + .. parsed-literal:: + + typedef at::type t; + + :Return type: + A type. + + :Semantics: + Equivalent to + + .. parsed-literal:: + + typedef at::type t; + + +Complexity +---------- + ++-------------------------------+-----------------------------------+ +| Sequence archetype | Complexity | ++===============================+===================================+ +| |Forward Sequence| | Linear. | ++-------------------------------+-----------------------------------+ +| |Random Access Sequence| | Amortized constant time. | ++-------------------------------+-----------------------------------+ +| |Associative Sequence| | Amortized constant time. | ++-------------------------------+-----------------------------------+ + +Example +------- + +.. parsed-literal:: + + typedef range_c range; + BOOST_MPL_ASSERT_RELATION( (at< range, int_<0> >::value), ==, 10 ); + BOOST_MPL_ASSERT_RELATION( (at< range, int_<10> >::value), ==, 20 ); + BOOST_MPL_ASSERT_RELATION( (at< range, int_<40> >::value), ==, 50 ); + + +.. parsed-literal:: + + typedef set< int const,long*,double > s; + + BOOST_MPL_ASSERT(( is_same< at::type, void\_ > )); + BOOST_MPL_ASSERT(( is_same< at::type, int > )); + + +See also +-------- + +|Forward Sequence|, |Random Access Sequence|, |Associative Sequence|, |at_c|, |front|, |back| diff --git a/doc/src/refmanual/at_c.rst b/doc/src/refmanual/at_c.rst new file mode 100644 index 0000000..84e78af --- /dev/null +++ b/doc/src/refmanual/at_c.rst @@ -0,0 +1,100 @@ +.. Sequences/Intrinsic Metafunctions//at_c + +at_c +==== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + , long n + > + struct at_c + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns a type identical to the ``n``\ th element from the beginning of +the sequence. ``at_c::type`` is a shorcut notation for +``at< Sequence, long_ >::type``. + + +Header +------ + +.. parsed-literal:: + + #include + + + +Parameters +---------- + ++---------------+-----------------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===================================+===============================================+ +| ``Sequence`` | |Forward Sequence| | A sequence to be examined. | ++---------------+-----------------------------------+-----------------------------------------------+ +| ``n`` | A compile-time integral constant | An offset from the beginning of the sequence | +| | | specifying the element to be retrieved. | ++---------------+-----------------------------------+-----------------------------------------------+ + + +Expression semantics +-------------------- + + +.. parsed-literal:: + + typedef at_c::type t; + +:Return type: + A type + +:Precondition: + ``0 <= n < size::value`` + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef at< Sequence, long_ >::type t; + + +Complexity +---------- + ++-------------------------------+-----------------------------------+ +| Sequence archetype | Complexity | ++===============================+===================================+ +| |Forward Sequence| | Linear. | ++-------------------------------+-----------------------------------+ +| |Random Access Sequence| | Amortized constant time. | ++-------------------------------+-----------------------------------+ + + +Example +------- + +.. parsed-literal:: + + typedef range_c range; + BOOST_MPL_ASSERT_RELATION( (at_c< range,0 >::value), ==, 10 ); + BOOST_MPL_ASSERT_RELATION( (at_c< range,10 >::value), ==, 20 ); + BOOST_MPL_ASSERT_RELATION( (at_c< range,40 >::value), ==, 50 ); + + +See also +-------- + +|Forward Sequence|, |Random Access Sequence|, |at|, |front|, |back| diff --git a/doc/src/refmanual/back.rst b/doc/src/refmanual/back.rst new file mode 100644 index 0000000..b868a3a --- /dev/null +++ b/doc/src/refmanual/back.rst @@ -0,0 +1,99 @@ +.. Sequences/Intrinsic Metafunctions//back + +back +==== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + > + struct back + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns the last element in the sequence. + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Tag Dispatched Metafunction| + + +Parameters +---------- + ++---------------+---------------------------+-----------------------------------+ +| Parameter | Requirement | Description | ++===============+===========================+===================================+ +| ``Sequence`` | |Bidirectional Sequence| | A sequence to be examined. | ++---------------+---------------------------+-----------------------------------+ + + +Expression semantics +-------------------- + +For any |Bidirectional Sequence| ``s``: + +.. parsed-literal:: + + typedef back::type t; + +:Return type: + A type. + +:Precondition: + ``empty::value == false``. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef deref< prior< end::type >::type >::type t; + + + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + typedef range_c range1; + typedef range_c range2; + typedef range_c range3; + + BOOST_MPL_ASSERT_RELATION( back::value, ==, 0 ); + BOOST_MPL_ASSERT_RELATION( back::value, ==, 9 ); + BOOST_MPL_ASSERT_RELATION( back::value, ==, -1 ); + + +See also +-------- + +|Bidirectional Sequence|, |front|, |push_back|, |end|, |deref|, |at| + diff --git a/doc/src/refmanual/back_inserter.rst b/doc/src/refmanual/back_inserter.rst new file mode 100644 index 0000000..1dcbb58 --- /dev/null +++ b/doc/src/refmanual/back_inserter.rst @@ -0,0 +1,89 @@ +.. Algorithms/Inserters//back_inserter + +back_inserter +============= + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Seq + > + struct back_inserter + { + // |unspecified| + // |...| + }; + + +Description +----------- + +Inserts elements at the end of the sequence. + +Header +------ + +.. parsed-literal:: + + #include + +Model of +-------- + +|Inserter| + + +Parameters +---------- + ++---------------+-------------------------------+---------------------------------------+ +| Parameter | Requirement | Description | ++===============+===============================+=======================================+ +| ``Seq`` | |Back Extensible Sequence| | A sequence to bind the inserter to. | ++---------------+-------------------------------+---------------------------------------+ + + +Expression semantics +-------------------- + +|Semantics disclaimer...| |Inserter|. + +For any |Back Extensible Sequence| ``s``: + ++---------------------------+-------------------------------------------------------+ +| Expression | Semantics | ++===========================+=======================================================+ +| ``back_inserter`` | An |Inserter| ``in``, equivalent to | +| | | +| | .. parsed-literal:: | +| | | +| | struct in : inserter > {}; | ++---------------------------+-------------------------------------------------------+ + + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + typedef copy< + range_c + , back_inserter< vector_c > + >::type range; + + BOOST_MPL_ASSERT(( equal< range, range_c > )); + + +See also +-------- + +|Algorithms|, |Inserter|, |Reversible Algorithm|, |inserter|, |front_inserter|, |push_back| diff --git a/doc/src/refmanual/begin.rst b/doc/src/refmanual/begin.rst new file mode 100644 index 0000000..6c1f440 --- /dev/null +++ b/doc/src/refmanual/begin.rst @@ -0,0 +1,98 @@ +.. Sequences/Intrinsic Metafunctions//begin + +begin +===== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename X + > + struct begin + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns an iterator that points to the first element of the sequence. If +the argument is not a |Forward Sequence|, returns |void_|. + + +Header +------ + +.. parsed-literal:: + + #include + + + +Model of +-------- + +|Tag Dispatched Metafunction| + + +Parameters +---------- + ++---------------+-------------------+---------------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===================+===================================================+ +| ``X`` | Any type | A type whose begin iterator, if any, will be | +| | | returned. | ++---------------+-------------------+---------------------------------------------------+ + + +Expression semantics +-------------------- + +For any arbitrary type ``x``: + +.. parsed-literal:: + + typedef begin::type first; + +:Return type: + |Forward Iterator| or |void_|. + +:Semantics: + If ``x`` is a |Forward Sequence|, ``first`` is an iterator pointing to the + first element of ``s``; otherwise ``first`` is |void_|. + +:Postcondition: + If ``first`` is an iterator, it is either dereferenceable or past-the-end; it + is past-the-end if and only if ``size::value == 0``. + + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + typedef vector< unsigned char,unsigned short, + unsigned int,unsigned long > unsigned_types; + + typedef begin::type iter; + BOOST_MPL_ASSERT(( is_same< deref::type, unsigned char > )); + + BOOST_MPL_ASSERT(( is_same< begin::type, void\_ > )); + + +See also +-------- + +|Iterators|, |Forward Sequence|, |end|, |size|, |empty| diff --git a/doc/src/refmanual/bind.rst b/doc/src/refmanual/bind.rst new file mode 100644 index 0000000..f33f336 --- /dev/null +++ b/doc/src/refmanual/bind.rst @@ -0,0 +1,204 @@ +.. Metafunctions/Composition and Argument Binding//bind |30 + +bind +==== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename F + > + struct bind0 + { + // |unspecified| + // |...| + }; + + template< + typename F, typename A1 + > + struct bind1 + { + // |unspecified| + // |...| + }; + + |...| + + template< + typename F, typename A1,\ |...| typename An + > + struct bind\ *n* + { + // |unspecified| + // |...| + }; + + template< + typename F + , typename A1 = |unspecified| + |...| + , typename An = |unspecified| + > + struct bind + { + // |unspecified| + // |...| + }; + + +Description +----------- + +``bind`` is a higher-order primitive for |Metafunction Class| composition +and argument binding. In essence, it's a compile-time counterpart of +the similar run-time functionality provided by |Boost.Bind| and |Boost.Lambda| +libraries. + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Metafunction Class| + + +Parameters +---------- + ++---------------+-----------------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===================================+===============================================+ +| ``F`` | |Metafunction Class| | An metafunction class to perform binding on. | ++---------------+-----------------------------------+-----------------------------------------------+ +| |A1...An| | Any type | Arguments to bind. | ++---------------+-----------------------------------+-----------------------------------------------+ + + +Expression semantics +-------------------- + +For any |Metafunction Class| ``f`` and arbitrary types |a1...an|: + +.. parsed-literal:: + + typedef bind g; + typedef bind\ *n*\ g; + +:Return type: + |Metafunction Class| + +.. _`bind semantics`: + +:Semantics: + Equivalent to + + .. parsed-literal:: + + struct g + { + template< + typename U1 = |unspecified| + |...| + , typename U\ *n* = |unspecified| + > + struct apply + : apply_wrap\ *n*\ < + typename h0::type + , typename h1::type + |...| + , typename h\ *n*\ ::type + > + { + }; + }; + + where ``h``\ *k* is equivalent to + + .. parsed-literal:: + + template< typename X, typename U1,\ |...| typename U\ *n* > struct h\ *k* + : apply_wrap\ *n*\ + { + }; + + if ``f`` or ``a``\ *k* is a |bind expression| or a |placeholder|, and + + .. parsed-literal:: + + template< typename X, typename U1,\ |...| typename U\ *n* > struct h\ *k* + { + typedef X type; + }; + + otherwise. |Note:| Every ``n``\th appearance of the `unnamed placeholder`__ + in the ``bind`` specialization is replaced with the corresponding + numbered placeholder ``_``\ *n* |-- end note| + +__ `Placeholders`_ + + +Example +------- + +.. parsed-literal:: + + struct f1 + { + template< typename T1 > struct apply + { + typedef T1 type; + }; + }; + + struct f5 + { + template< typename T1, typename T2, typename T3, typename T4, typename T5 > + struct apply + { + typedef T5 type; + }; + }; + + typedef apply_wrap\ ``1``\< + bind\ ``1``\ + , int + >::type r11; + + typedef apply_wrap\ ``5``\< + bind\ ``1``\ + , void,void,void,void,int + >::type r12; + + BOOST_MPL_ASSERT(( is_same )); + BOOST_MPL_ASSERT(( is_same )); + + typedef apply_wrap\ ``5``\< + bind\ ``5``\ + , void,void,void,void,int + >::type r51; + + typedef apply_wrap\ ``5``\< + bind\ ``5``\ + , int,void,void,void,void + >::type r52; + + BOOST_MPL_ASSERT(( is_same )); + BOOST_MPL_ASSERT(( is_same )); + + +See also +-------- + +|Composition and Argument Binding|, |Invocation|, |Placeholders|, |lambda|, |quote|, +|protect|, |apply|, |apply_wrap| diff --git a/doc/src/refmanual/bitand_.rst b/doc/src/refmanual/bitand_.rst new file mode 100644 index 0000000..9368705 --- /dev/null +++ b/doc/src/refmanual/bitand_.rst @@ -0,0 +1,128 @@ +.. Metafunctions/Bitwise Operations//bitand_ + +bitand\_ +======== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename T1 + , typename T2 + , typename T3 = |unspecified| + |...| + , typename T\ *n* = |unspecified| + > + struct bitand\_ + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns the result of *bitwise and* (``&``) operation of its arguments. + + +Header +------ + +.. parsed-literal:: + + #include + #include + + +Model of +-------- + +|Numeric Metafunction| + + +Parameters +---------- + ++---------------+---------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===========================+===============================================+ +| |T1...Tn| | |Integral Constant| | Operation's arguments. | ++---------------+---------------------------+-----------------------------------------------+ + +|Note:| |numeric metafunction note| |-- end note| + + +Expression semantics +-------------------- + +For any |Integral Constant|\ s |c1...cn|: + + +.. parsed-literal:: + + typedef bitand_::type r; + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef integral_c< + typeof(c1::value & c2::value) + , ( c1::value & c2::value ) + > c; + + typedef bitand_::type r; + +.. .......................................................................... + +.. parsed-literal:: + + typedef bitand_ r; + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + struct r : bitand_::type {}; + + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + typedef integral_c u0; + typedef integral_c u1; + typedef integral_c u2; + typedef integral_c u8; + typedef integral_c uffffffff; + + BOOST_MPL_ASSERT_RELATION( (bitand_::value), ==, 0 ); + BOOST_MPL_ASSERT_RELATION( (bitand_::value), ==, 0 ); + BOOST_MPL_ASSERT_RELATION( (bitand_::value), ==, 0 ); + BOOST_MPL_ASSERT_RELATION( (bitand_::value), ==, 0 ); + BOOST_MPL_ASSERT_RELATION( (bitand_::value), ==, 1 ); + BOOST_MPL_ASSERT_RELATION( (bitand_::value), ==, 8 ); + + +See also +-------- + +|Bitwise Operations|, |Numeric Metafunction|, |numeric_cast|, |bitor_|, |bitxor_|, |shift_left| diff --git a/doc/src/refmanual/bitor_.rst b/doc/src/refmanual/bitor_.rst new file mode 100644 index 0000000..6dd1836 --- /dev/null +++ b/doc/src/refmanual/bitor_.rst @@ -0,0 +1,128 @@ +.. Metafunctions/Bitwise Operations//bitor_ + +bitor\_ +======= + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename T1 + , typename T2 + , typename T3 = |unspecified| + |...| + , typename T\ *n* = |unspecified| + > + struct bitor\_ + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns the result of *bitwise or* (``|``) operation of its arguments. + + +Header +------ + +.. parsed-literal:: + + #include + #include + + +Model of +-------- + +|Numeric Metafunction| + + +Parameters +---------- + ++---------------+---------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===========================+===============================================+ +| |T1...Tn| | |Integral Constant| | Operation's arguments. | ++---------------+---------------------------+-----------------------------------------------+ + +|Note:| |numeric metafunction note| |-- end note| + + +Expression semantics +-------------------- + +For any |Integral Constant|\ s |c1...cn|: + + +.. parsed-literal:: + + typedef bitor_::type r; + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef integral_c< + typeof(c1::value | c2::value) + , ( c1::value | c2::value ) + > c; + + typedef bitor_::type r; + +.. .......................................................................... + +.. parsed-literal:: + + typedef bitor_ r; + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + struct r : bitor_::type {}; + + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + typedef integral_c u0; + typedef integral_c u1; + typedef integral_c u2; + typedef integral_c u8; + typedef integral_c uffffffff; + + BOOST_MPL_ASSERT_RELATION( (bitor_::value), ==, 0 ); + BOOST_MPL_ASSERT_RELATION( (bitor_::value), ==, 1 ); + BOOST_MPL_ASSERT_RELATION( (bitor_::value), ==, 1 ); + BOOST_MPL_ASSERT_RELATION( (bitor_::value), ==, 0xffffffff ); + BOOST_MPL_ASSERT_RELATION( (bitor_::value), ==, 0xffffffff ); + BOOST_MPL_ASSERT_RELATION( (bitor_::value), ==, 0xffffffff ); + + +See also +-------- + +|Bitwise Operations|, |Numeric Metafunction|, |numeric_cast|, |bitand_|, |bitxor_|, |shift_left| diff --git a/doc/src/refmanual/bitxor_.rst b/doc/src/refmanual/bitxor_.rst new file mode 100644 index 0000000..d0ebceb --- /dev/null +++ b/doc/src/refmanual/bitxor_.rst @@ -0,0 +1,129 @@ +.. Metafunctions/Bitwise Operations//bitxor_ + +bitxor\_ +======== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename T1 + , typename T2 + , typename T3 = |unspecified| + |...| + , typename T\ *n* = |unspecified| + > + struct bitxor\_ + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns the result of *bitwise xor* (``^``) operation of its arguments. + + +Header +------ + +.. parsed-literal:: + + #include + #include + + +Model of +-------- + +|Numeric Metafunction| + + +Parameters +---------- + ++---------------+---------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===========================+===============================================+ +| |T1...Tn| | |Integral Constant| | Operation's arguments. | ++---------------+---------------------------+-----------------------------------------------+ + +|Note:| |numeric metafunction note| |-- end note| + + +Expression semantics +-------------------- + +For any |Integral Constant|\ s |c1...cn|: + + +.. parsed-literal:: + + typedef bitxor_::type r; + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef integral_c< + typeof(c1::value ^ c2::value) + , ( c1::value ^ c2::value ) + > c; + + typedef bitxor_::type r; + +.. .......................................................................... + +.. parsed-literal:: + + typedef bitxor_ r; + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + struct r : bitxor_::type {}; + + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + typedef integral_c u0; + typedef integral_c u1; + typedef integral_c u2; + typedef integral_c u8; + typedef integral_c uffffffff; + + BOOST_MPL_ASSERT_RELATION( (bitxor_::value), ==, 0 ); + BOOST_MPL_ASSERT_RELATION( (bitxor_::value), ==, 1 ); + BOOST_MPL_ASSERT_RELATION( (bitxor_::value), ==, 1 ); + + BOOST_MPL_ASSERT_RELATION( (bitxor_::value), ==, 0xffffffff ^ 0 ); + BOOST_MPL_ASSERT_RELATION( (bitxor_::value), ==, 0xffffffff ^ 1 ); + BOOST_MPL_ASSERT_RELATION( (bitxor_::value), ==, 0xffffffff ^ 8 ); + + +See also +-------- + +|Bitwise Operations|, |Numeric Metafunction|, |numeric_cast|, |bitand_|, |bitor_|, |shift_left| diff --git a/doc/src/refmanual/bool_.rst b/doc/src/refmanual/bool_.rst new file mode 100644 index 0000000..39cc2c5 --- /dev/null +++ b/doc/src/refmanual/bool_.rst @@ -0,0 +1,92 @@ +.. Data Types/Numeric//bool_ |10 + +bool\_ +====== + +Synopsis +-------- + +.. parsed-literal:: + + template< + bool C + > + struct bool\_ + { + // |unspecified| + // ... + }; + + typedef bool_ true\_; + typedef bool_ false\_; + + +Description +----------- + +A boolean |Integral Constant| wrapper. + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Integral Constant| + + +Parameters +---------- + ++---------------+-------------------------------+---------------------------+ +| Parameter | Requirement | Description | ++===============+===============================+===========================+ +| ``C`` | A boolean integral constant | A value to wrap. | ++---------------+-------------------------------+---------------------------+ + +Expression semantics +-------------------- + +|Semantics disclaimer...| |Integral Constant|. + +For arbitrary integral constant ``c``: + ++-------------------+-----------------------------------------------------------+ +| Expression | Semantics | ++===================+===========================================================+ +| ``bool_`` | An |Integral Constant| ``x`` such that ``x::value == c`` | +| | and ``x::value_type`` is identical to ``bool``. | ++-------------------+-----------------------------------------------------------+ + + +Example +------- + +.. parsed-literal:: + + BOOST_MPL_ASSERT(( is_same< bool_::value_type, bool > )); + BOOST_MPL_ASSERT(( is_same< bool_, |true_| > )); } + BOOST_MPL_ASSERT(( is_same< bool_::type, bool_ > )); + BOOST_MPL_ASSERT_RELATION( bool_::value, ==, true ); + assert( bool_() == true ); + + +See also +-------- + +|Data Types|, |Integral Constant|, |int_|, |long_|, |integral_c| + + +.. |true_| replace:: |``true_``|__ +.. |``true_``| replace:: ``true_`` +__ `bool\_`_ + +.. |false_| replace:: |``false_``|__ +.. |``false_``| replace:: ``false_`` +__ `bool\_`_ diff --git a/doc/src/refmanual/clear.rst b/doc/src/refmanual/clear.rst new file mode 100644 index 0000000..65ee734 --- /dev/null +++ b/doc/src/refmanual/clear.rst @@ -0,0 +1,98 @@ +.. Sequences/Intrinsic Metafunctions//clear + +clear +===== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + > + struct clear + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns an empty sequence |concept-identical| to ``Sequence``. + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Tag Dispatched Metafunction| + + +Parameters +---------- + ++---------------+-----------------------------------+---------------------------------------+ +| Parameter | Requirement | Description | ++===============+===================================+=======================================+ +| ``Sequence`` | |Extensible Sequence| or | A sequence to get an empty "copy" of. | +| | |Extensible Associative Sequence| | | ++---------------+-----------------------------------+---------------------------------------+ + + +Expression semantics +-------------------- + +For any |Extensible Sequence| or |Extensible Associative Sequence| ``s``: + + +.. parsed-literal:: + + typedef clear::type t; + +:Return type: + |Extensible Sequence| or |Extensible Associative Sequence|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef erase< s, begin::type, end::type >::type t; + + +:Postcondition: + ``empty::value == true``. + + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + typedef vector_c odds; + typedef clear::type nothing; + + BOOST_MPL_ASSERT(( empty )); + + +See also +-------- + +|Extensible Sequence|, |Extensible Associative Sequence|, |erase|, |empty|, |begin|, |end| + diff --git a/doc/src/refmanual/contains.rst b/doc/src/refmanual/contains.rst new file mode 100644 index 0000000..01e2d0c --- /dev/null +++ b/doc/src/refmanual/contains.rst @@ -0,0 +1,92 @@ +.. Algorithms/Querying Algorithms//contains |30 + +contains +======== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + , typename T + > + struct contains + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns a true-valued |Integral Constant| if one or more elements in ``Sequence`` +are identical to ``T``. + + +Header +------ + +.. parsed-literal:: + + #include + + +Parameters +---------- + ++---------------+---------------------------+-----------------------------------+ +| Parameter | Requirement | Description | ++===============+===========================+===================================+ +| ``Sequence`` | |Forward Sequence| | A sequence to be examined. | ++---------------+---------------------------+-----------------------------------+ +| ``T`` | Any type | A type to search for. | ++---------------+---------------------------+-----------------------------------+ + + +Expression semantics +-------------------- + +For any |Forward Sequence| ``s`` and arbitrary type ``t``: + + +.. parsed-literal:: + + typedef contains::type r; + + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef not_< is_same< + find::type + , end::type + > >::type r; + + +Complexity +---------- + +Linear. At most ``size::value`` comparisons for identity. + + +Example +------- + +.. parsed-literal:: + + typedef vector types; + BOOST_MPL_ASSERT_NOT(( contains )); + + +See also +-------- + +|Querying Algorithms|, |find|, |find_if|, |count|, |lower_bound| diff --git a/doc/src/refmanual/copy.rst b/doc/src/refmanual/copy.rst new file mode 100644 index 0000000..12fde6b --- /dev/null +++ b/doc/src/refmanual/copy.rst @@ -0,0 +1,103 @@ +.. Algorithms/Transformation Algorithms//copy |10 + +copy +==== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + , typename In = |unspecified| + > + struct copy + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns a copy of the original sequence. + +|transformation algorithm disclaimer| + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Reversible Algorithm| + + +Parameters +---------- + ++---------------+---------------------------+-------------------------------+ +| Parameter | Requirement | Description | ++===============+===========================+===============================+ +| ``Sequence`` | |Forward Sequence| | A sequence to copy. | ++---------------+---------------------------+-------------------------------+ +| ``In`` | |Inserter| | An inserter. | ++---------------+---------------------------+-------------------------------+ + + +Expression semantics +-------------------- + +|Semantics disclaimer...| |Reversible Algorithm|. + +For any |Forward Sequence| ``s``, and an |Inserter| ``in``: + +.. parsed-literal:: + + typedef copy::type r; + +:Return type: + A type. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef fold< s,in::state,in::operation >::type r; + + + +Complexity +---------- + +Linear. Exactly ``size::value`` applications of ``in::operation``. + + +Example +------- + +.. parsed-literal:: + + typedef vector_c numbers; + typedef copy< + range_c + , back_inserter< numbers > + >::type result; + + BOOST_MPL_ASSERT_RELATION( size::value, ==, 20 ); + BOOST_MPL_ASSERT(( equal< result,range_c > )); + + +See also +-------- + +|Transformation Algorithms|, |Reversible Algorithm|, |reverse_copy|, |copy_if|, |transform| diff --git a/doc/src/refmanual/copy_if.rst b/doc/src/refmanual/copy_if.rst new file mode 100644 index 0000000..12b92df --- /dev/null +++ b/doc/src/refmanual/copy_if.rst @@ -0,0 +1,120 @@ +.. Algorithms/Transformation Algorithms//copy_if |20 + +copy_if +======= + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + , typename Pred + , typename In = |unspecified| + > + struct copy_if + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns a filtered copy of the original sequence containing the elements that satisfy +the predicate ``Pred``. + +|transformation algorithm disclaimer| + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Reversible Algorithm| + + +Parameters +---------- + ++---------------+-------------------------------+-------------------------------+ +| Parameter | Requirement | Description | ++===============+===============================+===============================+ +| ``Sequence`` | |Forward Sequence| | A sequence to copy. | ++---------------+-------------------------------+-------------------------------+ +| ``Pred`` | Unary |Lambda Expression| | A copying condition. | ++---------------+-------------------------------+-------------------------------+ +| ``In`` | |Inserter| | An inserter. | ++---------------+-------------------------------+-------------------------------+ + + +Expression semantics +-------------------- + +|Semantics disclaimer...| |Reversible Algorithm|. + +For any |Forward Sequence| ``s``, an unary |Lambda Expression| ``pred``, and +an |Inserter| ``in``: + + +.. parsed-literal:: + + typedef copy_if::type r; + + +:Return type: + A type. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef lambda::type p; + typedef lambda::type op; + + typedef fold< + s + , in::state + , eval_if< + apply_wrap\ ``1``\ + , apply_wrap\ ``2``\ + , identity<_1> + > + >::type r; + + +Complexity +---------- + +Linear. Exactly ``size::value`` applications of ``pred``, and at +most ``size::value`` applications of ``in::operation``. + + +Example +------- + +.. parsed-literal:: + + typedef copy_if< + range_c + , less< _1, int_<5> > + , back_inserter< vector<> > + >::type result; + + BOOST_MPL_ASSERT_RELATION( size::value, ==, 5 ); + BOOST_MPL_ASSERT(( equal > )); + + +See also +-------- + +|Transformation Algorithms|, |Reversible Algorithm|, |reverse_copy_if|, |copy|, |remove_if|, |replace_if| diff --git a/doc/src/refmanual/count.rst b/doc/src/refmanual/count.rst new file mode 100644 index 0000000..b5b0dfa --- /dev/null +++ b/doc/src/refmanual/count.rst @@ -0,0 +1,90 @@ +.. Algorithms/Querying Algorithms//count |40 + +count +===== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + , typename T + > + struct count + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns the number of elements in a ``Sequence`` that are identical to ``T``. + + +Header +------ + +.. parsed-literal:: + + #include + + +Parameters +---------- + ++---------------+---------------------------+-----------------------------------+ +| Parameter | Requirement | Description | ++===============+===========================+===================================+ +| ``Sequence`` | |Forward Sequence| | A sequence to be examined. | ++---------------+---------------------------+-----------------------------------+ +| ``T`` | Any type | A type to search for. | ++---------------+---------------------------+-----------------------------------+ + + +Expression semantics +-------------------- + + +For any |Forward Sequence| ``s`` and arbitrary type ``t``: + + +.. parsed-literal:: + + typedef count::type n; + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef count_if< s,is_same<_,T> >::type n; + + +Complexity +---------- + +Linear. Exactly ``size::value`` comparisons for identity. + + +Example +------- + +.. parsed-literal:: + + typedef vector types; + typedef count::type n; + + BOOST_MPL_ASSERT_RELATION( n::value, ==, 2 ); + + +See also +-------- + +|Querying Algorithms|, |count_if|, |find|, |find_if|, |contains|, |lower_bound| diff --git a/doc/src/refmanual/count_if.rst b/doc/src/refmanual/count_if.rst new file mode 100644 index 0000000..880146b --- /dev/null +++ b/doc/src/refmanual/count_if.rst @@ -0,0 +1,96 @@ +.. Algorithms/Querying Algorithms//count_if |50 + +count_if +======== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + , typename Pred + > + struct count_if + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns the number of elements in ``Sequence`` that satisfy the predicate ``Pred``. + + +Header +------ + +.. parsed-literal:: + + #include + + + +Parameters +---------- + ++---------------+-------------------------------+-----------------------------------+ +| Parameter | Requirement | Description | ++===============+===============================+===================================+ +| ``Sequence`` | |Forward Sequence| | A sequence to be examined. | ++---------------+-------------------------------+-----------------------------------+ +| ``Pred`` | Unary |Lambda Expression| | A count condition. | ++---------------+-------------------------------+-----------------------------------+ + + +Expression semantics +-------------------- + + +For any |Forward Sequence| ``s`` and unary |Lambda Expression| ``pred``: + +.. parsed-literal:: + + typedef count_if::type n; + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef lambda::type p; + typedef fold< + s + , long_<0> + , if_< apply_wrap\ ``1``\, next<_1>, _1 > + >::type n; + + +Complexity +---------- + +Linear. Exactly ``size::value`` applications of ``pred``. + + +Example +------- + +.. parsed-literal:: + + typedef vector types; + + BOOST_MPL_ASSERT_RELATION( (count_if< types, is_float<_> >::value), ==, 1 ); + BOOST_MPL_ASSERT_RELATION( (count_if< types, is_same<_,char> >::value), ==, 2 ); + BOOST_MPL_ASSERT_RELATION( (count_if< types, is_same<_,void> >::value), ==, 0 ); + + +See also +-------- + +|Querying Algorithms|, |count|, |find|, |find_if|, |contains| diff --git a/doc/src/refmanual/deque.rst b/doc/src/refmanual/deque.rst new file mode 100644 index 0000000..4a49c4b --- /dev/null +++ b/doc/src/refmanual/deque.rst @@ -0,0 +1,55 @@ +.. Sequences/Classes//deque |30 + +deque +===== + +Description +----------- + +``deque`` is a |variadic|, `random access`__, `extensible`__ sequence of types that +supports constant-time insertion and removal of elements at both ends, and +linear-time insertion and removal of elements in the middle. In this implementation +of the library, ``deque`` is a synonym for |vector|. + +__ `Random Access Sequence`_ +__ `Extensible Sequence`_ + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +* |Variadic Sequence| +* |Random Access Sequence| +* |Extensible Sequence| +* |Back Extensible Sequence| +* |Front Extensible Sequence| + + +Expression semantics +-------------------- + +See |vector| specification. + + +Example +------- + +.. parsed-literal:: + + typedef deque floats; + typedef push_back::type types; + + BOOST_MPL_ASSERT(( |is_same|\< at_c::type, int > )); + + +See also +-------- + +|Sequences|, |vector|, |list|, |set| diff --git a/doc/src/refmanual/deref.rst b/doc/src/refmanual/deref.rst new file mode 100644 index 0000000..8203411 --- /dev/null +++ b/doc/src/refmanual/deref.rst @@ -0,0 +1,94 @@ +.. Iterators/Iterator Metafunctions//deref |50 + +deref +===== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Iterator + > + struct deref + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Dereferences an iterator. + + +Header +------ + +.. parsed-literal:: + + #include + + + +Parameters +---------- + ++---------------+---------------------------+-----------------------------------+ +| Parameter | Requirement | Description | ++===============+===========================+===================================+ +| ``Iterator`` | |Forward Iterator| | The iterator to dereference. | ++---------------+---------------------------+-----------------------------------+ + + +Expression semantics +-------------------- + +For any |Forward Iterator|\ s ``iter``: + + +.. parsed-literal:: + + typedef deref::type t; + +:Return type: + A type. + +:Precondition: + ``iter`` is dereferenceable. + +:Semantics: + ``t`` is identical to the element referenced by ``iter``. If ``iter`` is + a user-defined iterator, the library-provided default implementation is + equivalent to + + .. parsed-literal:: + + typedef iter::type t; + + + + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + typedef vector types; + typedef begin::type iter; + + BOOST_MPL_ASSERT(( is_same< deref::type, char > )); + + +See also +-------- + +|Iterators|, |begin| / |end|, |next| diff --git a/doc/src/refmanual/distance.rst b/doc/src/refmanual/distance.rst new file mode 100644 index 0000000..18961d2 --- /dev/null +++ b/doc/src/refmanual/distance.rst @@ -0,0 +1,107 @@ +.. Iterators/Iterator Metafunctions//distance |20 + +distance +======== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename First + , typename Last + > + struct distance + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns the distance between ``First`` and ``Last`` iterators, that is, an +|Integral Constant| ``n`` such that ``advance::type`` is +identical to ``Last``. + + +Header +------ + +.. parsed-literal:: + + #include + + +Parameters +---------- + ++---------------+---------------------------+-----------------------------------+ +| Parameter | Requirement | Description | ++===============+===========================+===================================+ +| ``First``, | |Forward Iterator| | Iterators to compute a | +| ``Last`` | | distance between. | ++---------------+---------------------------+-----------------------------------+ + +Model Of +-------- + +|Tag Dispatched Metafunction| + + +Expression semantics +-------------------- + +For any |Forward Iterator|\ s ``first`` and ``last``: + +.. parsed-literal:: + + typedef distance::type n; + +:Return type: + |Integral Constant|. + +:Precondition: + [``first``, ``last``) is a valid range. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef iter_fold< + iterator_range + , long_<0> + , next<_1> + >::type n; + + +:Postcondition: + ``is_same< advance::type, last >::value == true``. + + +Complexity +---------- + +Amortized constant time if ``first`` and ``last`` are |Random Access Iterator|\ s, +otherwise linear time. + + +Example +------- + +.. parsed-literal:: + + typedef range_c::type range; + typedef begin::type first; + typedef end::type last; + + BOOST_MPL_ASSERT_RELATION( (distance::value), ==, 10); + + +See also +-------- + +|Iterators|, |Tag Dispatched Metafunction|, |advance|, |next|, |prior| diff --git a/doc/src/refmanual/divides.rst b/doc/src/refmanual/divides.rst new file mode 100644 index 0000000..c6d1736 --- /dev/null +++ b/doc/src/refmanual/divides.rst @@ -0,0 +1,125 @@ +.. Metafunctions/Arithmetic Operations//divides |40 + +divides +======= + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename T1 + , typename T2 + , typename T3 = |unspecified| + |...| + , typename T\ *n* = |unspecified| + > + struct divides + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns the quotient of its arguments. + + +Header +------ + +.. parsed-literal:: + + #include + #include + + +Model of +-------- + +|Numeric Metafunction| + + +Parameters +---------- + ++---------------+---------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===========================+===============================================+ +| |T1...Tn| | |Integral Constant| | Operation's arguments. | ++---------------+---------------------------+-----------------------------------------------+ + +|Note:| |numeric metafunction note| |-- end note| + + +Expression semantics +-------------------- + +For any |Integral Constant|\ s |c1...cn|: + + +.. parsed-literal:: + + typedef divides::type r; + +:Return type: + |Integral Constant|. + +:Precondition: + ``c2::value != 0``, |...| ``cn::value != 0``. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef integral_c< + typeof(c1::value / c2::value) + , ( c1::value / c2::value ) + > c; + + typedef divides::type r; + +.. .......................................................................... + +.. parsed-literal:: + + typedef divides r; + +:Return type: + |Integral Constant|. + +:Precondition: + ``c2::value != 0``, |...| ``cn::value != 0``. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + struct r : divides::type {}; + + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + typedef divides< int_<-10>, int_<3>, long_<1> >::type r; + BOOST_MPL_ASSERT_RELATION( r::value, ==, -3 ); + BOOST_MPL_ASSERT(( is_same< r::value_type, long > )); + + +See also +-------- + +|Arithmetic Operations|, |Numeric Metafunction|, |numeric_cast|, |times|, |modulus|, |plus| diff --git a/doc/src/refmanual/empty.rst b/doc/src/refmanual/empty.rst new file mode 100644 index 0000000..c9b65a7 --- /dev/null +++ b/doc/src/refmanual/empty.rst @@ -0,0 +1,94 @@ +.. Sequences/Intrinsic Metafunctions//empty + +empty +===== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + > + struct empty + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns an |Integral Constant| ``c`` such that ``c::value == true`` if +and only if the sequence is empty. + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Tag Dispatched Metafunction| + + +Parameters +---------- + ++---------------+-----------------------+-----------------------------------+ +| Parameter | Requirement | Description | ++===============+=======================+===================================+ +| ``Sequence`` | |Forward Sequence| | A sequence to test. | ++---------------+-----------------------+-----------------------------------+ + + +Expression semantics +-------------------- + +For any |Forward Sequence| ``s``: + + +.. parsed-literal:: + + typedef empty::type c; + +:Return type: + Boolean |Integral Constant|. + +:Semantics: + Equivalent to ``typedef is_same< begin::type,end::type >::type c;``. + +:Postcondition: + ``empty::value == ( size::value == 0 )``. + + + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + typedef range_c empty_range; + typedef vector types; + + BOOST_MPL_ASSERT( empty ); + BOOST_MPL_ASSERT_NOT( empty ); + + +See also +-------- + +|Forward Sequence|, |Integral Constant|, |size|, |begin| / |end| diff --git a/doc/src/refmanual/empty_base.rst b/doc/src/refmanual/empty_base.rst new file mode 100644 index 0000000..cdb2e40 --- /dev/null +++ b/doc/src/refmanual/empty_base.rst @@ -0,0 +1,32 @@ +.. Data Types/Miscellaneous//empty_base |20 + +empty_base +========== + +Synopsis +-------- + +.. parsed-literal:: + + struct empty_base {}; + + +Description +----------- + +An empty base class. Inheritance from |empty_base| through the |inherit| +metafunction is a no-op. + + +Header +------ + +.. parsed-literal:: + + #include + + +See also +-------- + +|Data Types|, |inherit|, |inherit_linearly|, |void_| diff --git a/doc/src/refmanual/empty_sequence.rst b/doc/src/refmanual/empty_sequence.rst new file mode 100644 index 0000000..24d6b5d --- /dev/null +++ b/doc/src/refmanual/empty_sequence.rst @@ -0,0 +1,70 @@ +.. Sequences/Views//empty_sequence + +empty_sequence +============== + +Synopsis +-------- + +.. parsed-literal:: + + struct empty_sequence + { + // |unspecified| + // |...| + }; + + +Description +----------- + +Represents a sequence containing no elements. + + +Header +------ + +.. parsed-literal:: + + #include + + +Expression semantics +-------------------- + +|Semantics disclaimer...| |Random Access Sequence|. + +In the following table, ``s`` is an instance of ``empty_sequence``. + ++-------------------------------+-----------------------------------------------------------+ +| Expression | Semantics | ++===============================+===========================================================+ +| ``empty_sequence`` | An empty |Random Access Sequence|. | ++-------------------------------+-----------------------------------------------------------+ +| ``size::type`` | ``size::value == 0``; see |Random Access Sequence|. | ++-------------------------------+-----------------------------------------------------------+ + + +Example +------- + +.. parsed-literal:: + + typedef begin::type first; + typedef end::type last; + + BOOST_MPL_ASSERT(( is_same )); + BOOST_MPL_ASSERT_RELATION( size::value, ==, 0 ); + + typedef transform_view< + empty_sequence + , add_pointer<_> + > empty_view; + + BOOST_MPL_ASSERT_RELATION( size::value, ==, 0 ); + + +See also +-------- + +|Sequences|, |Views|, |vector|, |list|, |single_view| diff --git a/doc/src/refmanual/end.rst b/doc/src/refmanual/end.rst new file mode 100644 index 0000000..5d184e0 --- /dev/null +++ b/doc/src/refmanual/end.rst @@ -0,0 +1,94 @@ +.. Sequences/Intrinsic Metafunctions//end + +end +=== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename X + > + struct end + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns the sequence's past-the-end iterator. If the argument is not a +|Forward Sequence|, returns |void_|. + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Tag Dispatched Metafunction| + + +Parameters +---------- + ++---------------+-------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===================+===============================================+ +| ``X`` | Any type | A type whose end iterator, if any, will be | +| | | returned. | ++---------------+-------------------+-----------------------------------------------+ + + +Expression semantics +-------------------- + +For any arbitrary type ``x``: + +.. parsed-literal:: + + typedef end::type last; + +:Return type: + |Forward Iterator| or |void_|. + +:Semantics: + If ``x`` is |Forward Sequence|, ``last`` is an iterator pointing one past the + last element in ``s``; otherwise ``last`` is |void_|. + +:Postcondition: + If ``last`` is an iterator, it is past-the-end. + + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + typedef vector v; + typedef begin::type first; + typedef end::type last; + + BOOST_MPL_ASSERT(( is_same< next::type, last > )); + + +See also +-------- + +|Iterators|, |Forward Sequence|, |begin|, |end|, |next| diff --git a/doc/src/refmanual/equal.rst b/doc/src/refmanual/equal.rst new file mode 100644 index 0000000..2a46203 --- /dev/null +++ b/doc/src/refmanual/equal.rst @@ -0,0 +1,93 @@ +.. Algorithms/Querying Algorithms//equal |100 + +equal +===== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Seq1 + , typename Seq2 + , typename Pred = is_same<_1,_2> + > + struct equal + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns a true-valued |Integral Constant| if the two sequences ``Seq1`` +and ``Seq2`` are identical when compared element-by-element. + + +Header +------ + +.. parsed-literal:: + + #include + + + +Parameters +---------- + ++-------------------+-------------------------------+-----------------------------------+ +| Parameter | Requirement | Description | ++===================+===============================+===================================+ +| ``Seq1``, ``Seq2``| |Forward Sequence| | Sequences to compare. | ++-------------------+-------------------------------+-----------------------------------+ +| ``Pred`` | Binary |Lambda Expression| | A comparison criterion. | ++-------------------+-------------------------------+-----------------------------------+ + + +Expression semantics +-------------------- + +For any |Forward Sequence|\ s ``s1`` and ``s2`` and a binary |Lambda Expression| ``pred``: + + +.. parsed-literal:: + + typedef equal::type c; + +:Return type: + |Integral Constant| + +:Semantics: + ``c::value == true`` is and only if ``size::value == size::value`` + and for every iterator ``i`` in |begin/end| ``deref::type`` is identical to + + .. parsed-literal:: + + advance< begin::type, distance< begin::type,i >::type >::type + + +Complexity +---------- + +Linear. At most ``size::value`` comparisons. + + +Example +------- + +.. parsed-literal:: + + typedef vector s1; + typedef list s2; + + BOOST_MPL_ASSERT(( equal )); + + +See also +-------- + +|Querying Algorithms|, |find|, |find_if| diff --git a/doc/src/refmanual/equal_to.rst b/doc/src/refmanual/equal_to.rst new file mode 100644 index 0000000..49fad65 --- /dev/null +++ b/doc/src/refmanual/equal_to.rst @@ -0,0 +1,114 @@ +.. Metafunctions/Comparisons//equal_to |50 + +equal_to +======== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename T1 + , typename T2 + > + struct equal_to + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns a true-valued |Integral Constant| if ``T1`` and ``T2`` are equal. + + +Header +------ + +.. parsed-literal:: + + #include + #include + + +Model of +-------- + +|Numeric Metafunction| + + +Parameters +---------- + ++---------------+---------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===========================+===============================================+ +| ``T1``, ``T2``| |Integral Constant| | Operation's arguments. | ++---------------+---------------------------+-----------------------------------------------+ + +|Note:| |numeric metafunction note| |-- end note| + + +Expression semantics +-------------------- + + +For any |Integral Constant|\ s ``c1`` and ``c2``: + +.. parsed-literal:: + + typedef equal_to::type r; + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef bool_< (c1::value == c2::value) > r; + + +.. .......................................................................... + +.. parsed-literal:: + + typedef equal_to r; + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + struct r : equal_to::type {}; + + + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + BOOST_MPL_ASSERT_NOT(( equal_to< int_<0>, int_<10> > )); + BOOST_MPL_ASSERT_NOT(( equal_to< long_<10>, int_<0> > )); + BOOST_MPL_ASSERT(( equal_to< long_<10>, int_<10> > )); + + +See also +-------- + +|Comparisons|, |Numeric Metafunction|, |numeric_cast|, |not_equal_to|, |less| + diff --git a/doc/src/refmanual/erase.rst b/doc/src/refmanual/erase.rst new file mode 100644 index 0000000..78047a4 --- /dev/null +++ b/doc/src/refmanual/erase.rst @@ -0,0 +1,165 @@ +.. Sequences/Intrinsic Metafunctions//erase + +erase +===== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + , typename First + , typename Last = |unspecified| + > + struct erase + { + typedef |unspecified| type; + }; + + + +Description +----------- + +``erase`` performs a removal of one or more adjacent elements in the sequence +starting from an arbitrary position. + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Tag Dispatched Metafunction| + + +Parameters +---------- + ++---------------+-----------------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===================================+===============================================+ +| ``Sequence`` | |Extensible Sequence| or | A sequence to erase from. | +| | |Extensible Associative Sequence| | | ++---------------+-----------------------------------+-----------------------------------------------+ +| ``First`` | |Forward Iterator| | An iterator to the beginning of the range to | +| | | be erased. | ++---------------+-----------------------------------+-----------------------------------------------+ +| ``Last`` | |Forward Iterator| | An iterator past-the-end of the range to be | +| | | erased. | ++---------------+-----------------------------------+-----------------------------------------------+ + + +Expression semantics +-------------------- + +.. compound:: + :class: expression-semantics + + For any |Extensible Sequence| ``s``, and iterators ``pos``, ``first`` and ``last`` into ``s``: + + + .. parsed-literal:: + + typedef erase::type r; + + :Return type: + |Extensible Sequence|. + + :Precondition: + ``[first,last)`` is a valid range in ``s``. + + :Semantics: + ``r`` is a new sequence, |concept-identical| to ``s``, of the following elements: + [``begin::type``, ``pos``), [``last``, ``end::type``). + + :Postcondition: + The relative order of the elements in ``r`` is the same as in ``s``; + + .. parsed-literal:: + + size::value == size::value - distance::value + + + .. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + .. parsed-literal:: + + typedef erase::type r; + + :Return type: + |Extensible Sequence|. + + :Precondition: + ``pos`` is a dereferenceable iterator in ``s``. + + :Semantics: + Equivalent to + + .. parsed-literal:: + + typedef erase< s,pos,next::type >::type r; + + + +.. compound:: + :class: expression-semantics + + For any |Extensible Associative Sequence| ``s``, and iterator ``pos`` into ``s``: + + .. parsed-literal:: + + typedef erase::type r; + + :Return type: + |Extensible Sequence|. + + :Precondition: + ``pos`` is a dereferenceable iterator to ``s``. + + :Semantics: + Erases the element at a specific position ``pos``; equivalent to + ``erase_key::type >::type``. + + :Postcondition: + ``size::value == size::value - 1``. + + +Complexity +---------- + ++---------------------------------------+-----------------------------------------------+ +| Sequence archetype | Complexity (the range form) | ++=======================================+===============================================+ +| |Extensible Associative Sequence| | Amortized constant time. | ++---------------------------------------+-----------------------------------------------+ +| |Extensible Sequence| | Quadratic in the worst case, linear at best. | ++---------------------------------------+-----------------------------------------------+ + + +Example +------- + +.. parsed-literal:: + + typedef vector_c values; + typedef find< values, integral_c >::type pos; + typedef erase::type result; + + BOOST_MPL_ASSERT_RELATION( size::value, ==, 7 ); + + typedef find >::type iter; + BOOST_MPL_ASSERT(( is_same< iter, end::type > )); + + +See also +-------- + +|Extensible Sequence|, |Extensible Associative Sequence|, |erase_key|, |pop_front|, |pop_back|, |insert| diff --git a/doc/src/refmanual/erase_key.rst b/doc/src/refmanual/erase_key.rst new file mode 100644 index 0000000..67d1e66 --- /dev/null +++ b/doc/src/refmanual/erase_key.rst @@ -0,0 +1,98 @@ +.. Sequences/Intrinsic Metafunctions//erase_key + +erase_key +========= + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename AssocSeq + , typename Key + > + struct erase_key + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Erases elements associated with the key ``Key`` in the |Extensible Associative Sequence| +``AssocSeq`` . + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Tag Dispatched Metafunction| + + +Parameters +---------- + ++---------------+-----------------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===================================+===============================================+ +| ``AssocSeq`` | |Extensible Associative Sequence| | A sequence to erase elements from. | ++---------------+-----------------------------------+-----------------------------------------------+ +| ``Key`` | Any type | A key for the elements to be removed. | ++---------------+-----------------------------------+-----------------------------------------------+ + + +Expression semantics +-------------------- + +For any |Extensible Associative Sequence| ``s``, and arbitrary type ``key``: + + +.. parsed-literal:: + + typedef erase_key::type r; + +:Return type: + |Extensible Associative Sequence|. + +:Semantics: + ``r`` is |concept-identical| and equivalent to ``s`` except that + ``has_key::value == false``. + +:Postcondition: + ``size::value == size::value - 1``. + + + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + typedef map< pair, pair > m; + typedef erase_key::type m1; + + BOOST_MPL_ASSERT_RELATION( size::type::value, ==, 1 ); + BOOST_MPL_ASSERT(( is_same< at::type,void\_ > )); + BOOST_MPL_ASSERT(( is_same< at::type,unsigned > )); + + +See also +-------- + +|Extensible Associative Sequence|, |erase|, |has_key|, |insert| diff --git a/doc/src/refmanual/eval_if.rst b/doc/src/refmanual/eval_if.rst new file mode 100644 index 0000000..d4bf51d --- /dev/null +++ b/doc/src/refmanual/eval_if.rst @@ -0,0 +1,83 @@ +.. Metafunctions/Type Selection//eval_if |30 + +eval_if +======= + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename C + , typename F1 + , typename F2 + > + struct eval_if + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Evaluates one of its two |nullary metafunction| arguments, ``F1`` or ``F2``, depending +on the value ``C``. + + +Header +------ + +.. parsed-literal:: + + #include + + +Parameters +---------- + ++---------------+-----------------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===================================+===============================================+ +| ``C`` | |Integral Constant| | An evaluation condition. | ++---------------+-----------------------------------+-----------------------------------------------+ +| ``F1``, ``F2``| Nullary |Metafunction| | Metafunctions to select for evaluation from. | ++---------------+-----------------------------------+-----------------------------------------------+ + + +Expression semantics +-------------------- + +For any |Integral Constant| ``c`` and nullary |Metafunction|\ s ``f1``, ``f2``: + + +.. parsed-literal:: + + typedef eval_if::type t; + +:Return type: + Any type. + +:Semantics: + If ``c::value == true``, ``t`` is identical to ``f1::type``; otherwise ``t`` is + identical to ``f2::type``. + + +Example +------- + +.. parsed-literal:: + + typedef eval_if< true\_, identity, identity >::type t1; + typedef eval_if< false\_, identity, identity >::type t2; + + BOOST_MPL_ASSERT(( is_same )); + BOOST_MPL_ASSERT(( is_same )); + + +See also +-------- + +|Metafunctions|, |Integral Constant|, |eval_if_c|, |if_| diff --git a/doc/src/refmanual/eval_if_c.rst b/doc/src/refmanual/eval_if_c.rst new file mode 100644 index 0000000..a7b2564 --- /dev/null +++ b/doc/src/refmanual/eval_if_c.rst @@ -0,0 +1,83 @@ +.. Metafunctions/Type Selection//eval_if_c |40 + +eval_if_c +========= + +Synopsis +-------- + +.. parsed-literal:: + + template< + bool c + , typename F1 + , typename F2 + > + struct eval_if_c + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Evaluates one of its two |nullary metafunction| arguments, ``F1`` or ``F2``, depending +on the value of integral constant ``c``. ``eval_if_c::type`` is a shorcut +notation for ``eval_if< bool_,f1,f2 >::type``. + + +Header +------ + +.. parsed-literal:: + + #include + + +Parameters +---------- + ++---------------+-----------------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===================================+===============================================+ +| ``c`` | An integral constant | An evaluation condition. | ++---------------+-----------------------------------+-----------------------------------------------+ +| ``F1``, ``F2``| Nullary |Metafunction| | Metafunctions to select for evaluation from. | ++---------------+-----------------------------------+-----------------------------------------------+ + + +Expression semantics +-------------------- + +For any integral constant ``c`` and nullary |Metafunction|\ s ``f1``, ``f2``: + + +.. parsed-literal:: + + typedef eval_if_c::type t; + +:Return type: + Any type. + +:Semantics: + Equivalent to ``typedef eval_if< bool_,f1,f2 >::type t;`` + + +Example +------- + +.. parsed-literal:: + + typedef eval_if_c< true, identity, identity >::type t1; + typedef eval_if_c< false, identity, identity >::type t2; + + BOOST_MPL_ASSERT(( is_same )); + BOOST_MPL_ASSERT(( is_same )); + + +See also +-------- + +|Metafunctions|, |Integral Constant|, |eval_if|, |if_|, |bool_| diff --git a/doc/src/refmanual/filter_view.rst b/doc/src/refmanual/filter_view.rst new file mode 100644 index 0000000..948551b --- /dev/null +++ b/doc/src/refmanual/filter_view.rst @@ -0,0 +1,96 @@ +.. Sequences/Views//filter_view + +filter_view +=========== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + , typename Pred + > + struct filter_view + { + // |unspecified| + // |...| + }; + + + +Description +----------- + +A view into a subset of ``Sequence``\ 's elements satisfying the predicate ``Pred``. + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +* |Forward Sequence| + + +Parameters +---------- + ++---------------+-----------------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===================================+===============================================+ +| ``Sequence`` | |Forward Sequence| | A sequence to wrap. | ++---------------+-----------------------------------+-----------------------------------------------+ +| ``Pred`` | Unary |Lambda Expression| | A filtering predicate. | ++---------------+-----------------------------------+-----------------------------------------------+ + + +Expression semantics +-------------------- + +Semantics of an expression is defined only where it differs from, or is not +defined in |Forward Sequence|. + +In the following table, ``v`` is an instance of ``filter_view``, ``s`` is an arbitrary +|Forward Sequence|, ``pred`` is an unary |Lambda Expression|. + ++---------------------------------------+-----------------------------------------------------------+ +| Expression | Semantics | ++=======================================+===========================================================+ +| .. parsed-literal:: | A lazy |Forward Sequence| sequence of all the elements in | +| | the range |begin/end| that satisfy the predicate | +| filter_view | ``pred``. | +| filter_view::type | | ++---------------------------------------+-----------------------------------------------------------+ +| ``size::type`` | The size of ``v``; | +| | ``size::value == count_if::value``; | +| | linear complexity; see |Forward Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ + + +Example +------- + +Find the largest floating type in a sequence. + +.. parsed-literal:: + + typedef vector types; + typedef max_element< + transform_view< filter_view< types,boost::is_float<_> >, size_of<_> > + >::type iter; + + BOOST_MPL_ASSERT(( is_same< deref::type, long double > )); + + +See also +-------- + +|Sequences|, |Views|, |transform_view|, |joint_view|, |zip_view|, |iterator_range| diff --git a/doc/src/refmanual/find.rst b/doc/src/refmanual/find.rst new file mode 100644 index 0000000..c5c6f09 --- /dev/null +++ b/doc/src/refmanual/find.rst @@ -0,0 +1,92 @@ +.. Algorithms/Querying Algorithms//find |10 + +find +==== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + , typename T + > + struct find + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns an iterator to the first occurrence of type ``T`` in a ``Sequence``. + + +Header +------ + +.. parsed-literal:: + + #include + + + +Parameters +---------- + ++---------------+-----------------------+-----------------------------------+ +| Parameter | Requirement | Description | ++===============+=======================+===================================+ +| ``Sequence`` | |Forward Sequence| | A sequence to search in. | ++---------------+-----------------------+-----------------------------------+ +| ``T`` | Any type | A type to search for. | ++---------------+-----------------------+-----------------------------------+ + + +Expression semantics +-------------------- + +For any |Forward Sequence| ``s`` and arbitrary type ``t``: + + +.. parsed-literal:: + + typedef find::type i; + + +:Return type: + |Forward Iterator|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef find_if >::type i; + + +Complexity +---------- + +Linear. At most ``size::value`` comparisons for identity. + + +Example +------- + +.. parsed-literal:: + + typedef vector types; + typedef find::type iter; + + BOOST_MPL_ASSERT(( is_same< deref::type, unsigned > )); + BOOST_MPL_ASSERT_RELATION( iter::pos::value, ==, 2 ); + + +See also +-------- + +|Querying Algorithms|, |contains|, |find_if|, |count|, |lower_bound| diff --git a/doc/src/refmanual/find_if.rst b/doc/src/refmanual/find_if.rst new file mode 100644 index 0000000..ffbe23b --- /dev/null +++ b/doc/src/refmanual/find_if.rst @@ -0,0 +1,94 @@ +.. Algorithms/Querying Algorithms//find_if |20 + +find_if +======= + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + , typename Pred + > + struct find_if + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns an iterator to the first element in ``Sequence`` that satisfies +the predicate ``Pred``. + + +Header +------ + +.. parsed-literal:: + + #include + + + +Parameters +---------- + ++---------------+-------------------------------+-----------------------------------+ +| Parameter | Requirement | Description | ++===============+===============================+===================================+ +| ``Sequence`` | |Forward Sequence| | A sequence to search in. | ++---------------+-------------------------------+-----------------------------------+ +| ``Pred`` | Unary |Lambda Expression| | A search condition. | ++---------------+-------------------------------+-----------------------------------+ + + +Expression semantics +-------------------- + +For any |Forward Sequence| ``s`` and unary |Lambda Expression| ``pred``: + + +.. parsed-literal:: + + typedef find_if::type i; + +:Return type: + |Forward Iterator|. + +:Semantics: + ``i`` is the first iterator in the range |begin/end| such that + + .. parsed-literal:: + + apply< pred,deref::type >::type::value == true + + If no such iterator exists, ``i`` is identical to ``end::type``. + + +Complexity +---------- + +Linear. At most ``size::value`` applications of ``pred``. + + +Example +------- + +.. parsed-literal:: + + typedef vector types; + typedef find_if >::type iter; + + BOOST_MPL_ASSERT(( is_same< deref::type, unsigned > )); + BOOST_MPL_ASSERT_RELATION( iter::pos::value, ==, 2 ); + + +See also +-------- + +|Querying Algorithms|, |find|, |count_if|, |lower_bound| diff --git a/doc/src/refmanual/fold.rst b/doc/src/refmanual/fold.rst new file mode 100644 index 0000000..188ad36 --- /dev/null +++ b/doc/src/refmanual/fold.rst @@ -0,0 +1,101 @@ +.. Algorithms/Iteration Algorithms//fold + +fold +==== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + , typename State + , typename ForwardOp + > + struct fold + { + typedef |unspecified| type; + }; + + + +Description +----------- + +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/end| in order. + + +Header +------ + +.. parsed-literal:: + + #include + + +Parameters +---------- + ++---------------+-------------------------------+---------------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===============================+===================================================+ +| ``Sequence`` | |Forward Sequence| | A sequence to iterate. | ++---------------+-------------------------------+---------------------------------------------------+ +| ``State`` | Any type | The initial state for the first ``ForwardOp`` | +| | | application. | ++---------------+-------------------------------+---------------------------------------------------+ +| ``ForwardOp`` | Binary |Lambda Expression| | The operation to be executed on forward | +| | | traversal. | ++---------------+-------------------------------+---------------------------------------------------+ + + +Expression semantics +-------------------- + +For any |Forward Sequence| ``s``, binary |Lambda Expression| ``op``, and arbitrary type ``state``: + + +.. parsed-literal:: + + typedef fold::type t; + +:Return type: + A type. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef iter_fold< s,state,apply > >::type t; + + + +Complexity +---------- + +Linear. Exactly ``size::value`` applications of ``op``. + + +Example +------- + +.. parsed-literal:: + + typedef vector types; + typedef fold< + types + , int_<0> + , if_< is_float<_2>,next<_1>,_1 > + >::type number_of_floats; + + BOOST_MPL_ASSERT_RELATION( number_of_floats::value, ==, 4 ); + + +See also +-------- + +|Algorithms|, |accumulate|, |reverse_fold|, |iter_fold|, |reverse_iter_fold|, |copy|, |copy_if| diff --git a/doc/src/refmanual/front.rst b/doc/src/refmanual/front.rst new file mode 100644 index 0000000..fd7da0e --- /dev/null +++ b/doc/src/refmanual/front.rst @@ -0,0 +1,100 @@ +.. Sequences/Intrinsic Metafunctions//front + +front +===== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + > + struct front + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns the first element in the sequence. + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Tag Dispatched Metafunction| + + +Parameters +---------- + ++---------------+-----------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+=======================+===============================================+ +| ``Sequence`` | |Forward Sequence| | A sequence to be examined. | ++---------------+-----------------------+-----------------------------------------------+ + + +Expression semantics +-------------------- + +For any |Forward Sequence| ``s``: + + +.. parsed-literal:: + + typedef front::type t; + +:Return type: + A type. + +:Precondition: + ``empty::value == false``. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef deref< begin::type >::type t; + + + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + typedef list::type types1; + typedef list::type types2; + typedef list::type types3; + + BOOST_MPL_ASSERT(( is_same< front::type, long > )); + BOOST_MPL_ASSERT(( is_same< front::type, int> )); + BOOST_MPL_ASSERT(( is_same< front::type, char> )); + + + +See also +-------- + +|Forward Sequence|, |back|, |push_front|, |begin|, |deref|, |at| diff --git a/doc/src/refmanual/front_inserter.rst b/doc/src/refmanual/front_inserter.rst new file mode 100644 index 0000000..faecc4b --- /dev/null +++ b/doc/src/refmanual/front_inserter.rst @@ -0,0 +1,89 @@ +.. Algorithms/Inserters//front_inserter + +front_inserter +============== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Seq + > + struct front_inserter + { + // |unspecified| + // |...| + }; + + +Description +----------- + +Inserts elements at the beginning of the sequence. + +Header +------ + +.. parsed-literal:: + + #include + +Model of +-------- + +|Inserter| + + +Parameters +---------- + ++---------------+-------------------------------+---------------------------------------+ +| Parameter | Requirement | Description | ++===============+===============================+=======================================+ +| ``Seq`` | |Front Extensible Sequence| | A sequence to bind the inserter to. | ++---------------+-------------------------------+---------------------------------------+ + + +Expression semantics +-------------------- + +|Semantics disclaimer...| |Inserter|. + +For any |Front Extensible Sequence| ``s``: + ++---------------------------+-------------------------------------------------------+ +| Expression | Semantics | ++===========================+=======================================================+ +| ``front_inserter`` | An |Inserter| ``in``, equivalent to | +| | | +| | .. parsed-literal:: | +| | | +| | struct in : inserter > {}; | ++---------------------------+-------------------------------------------------------+ + + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + typedef reverse_copy< + range_c + , front_inserter< vector_c > + >::type range; + + BOOST_MPL_ASSERT(( equal< range, range_c > )); + + +See also +-------- + +|Algorithms|, |Inserter|, |Reversible Algorithm|, |inserter|, |back_inserter|, |push_front| diff --git a/doc/src/refmanual/greater.rst b/doc/src/refmanual/greater.rst new file mode 100644 index 0000000..cf068a0 --- /dev/null +++ b/doc/src/refmanual/greater.rst @@ -0,0 +1,114 @@ +.. Metafunctions/Comparisons//greater |30 + +greater +======= + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename T1 + , typename T2 + > + struct greater + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns a true-valued |Integral Constant| if ``T1`` is greater than ``T2``. + + +Header +------ + +.. parsed-literal:: + + #include + #include + + +Model of +-------- + +|Numeric Metafunction| + + +Parameters +---------- + ++---------------+---------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===========================+===============================================+ +| ``T1``, ``T2``| |Integral Constant| | Operation's arguments. | ++---------------+---------------------------+-----------------------------------------------+ + +|Note:| |numeric metafunction note| |-- end note| + + +Expression semantics +-------------------- + + +For any |Integral Constant|\ s ``c1`` and ``c2``: + +.. parsed-literal:: + + typedef greater::type r; + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef bool_< (c1::value < c2::value) > r; + + +.. .......................................................................... + +.. parsed-literal:: + + typedef greater r; + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + struct r : greater::type {}; + + + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + BOOST_MPL_ASSERT(( greater< int_<10>, int_<0> > )); + BOOST_MPL_ASSERT_NOT(( greater< long_<0>, int_<10> > )); + BOOST_MPL_ASSERT_NOT(( greater< long_<10>, int_<10> > )); + + +See also +-------- + +|Comparisons|, |Numeric Metafunction|, |numeric_cast|, |greater_equal|, |less|, |equal_to| + diff --git a/doc/src/refmanual/greater_equal.rst b/doc/src/refmanual/greater_equal.rst new file mode 100644 index 0000000..3115b78 --- /dev/null +++ b/doc/src/refmanual/greater_equal.rst @@ -0,0 +1,114 @@ +.. Metafunctions/Comparisons//greater_equal |40 + +greater_equal +============= + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename T1 + , typename T2 + > + struct greater_equal + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns a true-valued |Integral Constant| if ``T1`` is greater than or equal to ``T2``. + + +Header +------ + +.. parsed-literal:: + + #include + #include + + +Model of +-------- + +|Numeric Metafunction| + + +Parameters +---------- + ++---------------+---------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===========================+===============================================+ +| ``T1``, ``T2``| |Integral Constant| | Operation's arguments. | ++---------------+---------------------------+-----------------------------------------------+ + +|Note:| |numeric metafunction note| |-- end note| + + +Expression semantics +-------------------- + + +For any |Integral Constant|\ s ``c1`` and ``c2``: + +.. parsed-literal:: + + typedef greater_equal::type r; + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef bool_< (c1::value < c2::value) > r; + + +.. .......................................................................... + +.. parsed-literal:: + + typedef greater_equal r; + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + struct r : greater_equal::type {}; + + + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + BOOST_MPL_ASSERT(( greater_equal< int_<10>, int_<0> > )); + BOOST_MPL_ASSERT_NOT(( greater_equal< long_<0>, int_<10> > )); + BOOST_MPL_ASSERT(( greater_equal< long_<10>, int_<10> > )); + + +See also +-------- + +|Comparisons|, |Numeric Metafunction|, |numeric_cast|, |greater|, |less|, |equal_to| + diff --git a/doc/src/refmanual/has_key.rst b/doc/src/refmanual/has_key.rst new file mode 100644 index 0000000..dcbde82 --- /dev/null +++ b/doc/src/refmanual/has_key.rst @@ -0,0 +1,93 @@ +.. Sequences/Intrinsic Metafunctions//has_key + +has_key +======= + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + , typename Key + > + struct has_key + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns a true-valued |Integral Constant| if ``Sequence`` contains an element +with key ``Key``. + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Tag Dispatched Metafunction| + + +Parameters +---------- + ++---------------+---------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===========================+===============================================+ +| ``Sequence`` | |Associative Sequence| | A sequence to query. | ++---------------+---------------------------+-----------------------------------------------+ +| ``Key`` | Any type | The queried key. | ++---------------+---------------------------+-----------------------------------------------+ + + +Expression semantics +-------------------- + +For any |Associative Sequence| ``s``, and arbitrary type ``key``: + +.. parsed-literal:: + + typedef has_key::type c; + +:Return type: + Boolean |Integral Constant|. + +:Semantics: + ``c::value == true`` if ``key`` is in ``s``'s set of keys; otherwise + ``c::value == false``. + + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + typedef map< pair, pair > m; + BOOST_MPL_ASSERT_NOT(( has_key )); + + typedef insert< m, pair > m1; + BOOST_MPL_ASSERT(( has_key )); + + +See also +-------- + +|Associative Sequence|, |count|, |insert|, |erase_key| diff --git a/doc/src/refmanual/identity.rst b/doc/src/refmanual/identity.rst new file mode 100644 index 0000000..b56718b --- /dev/null +++ b/doc/src/refmanual/identity.rst @@ -0,0 +1,93 @@ +.. Metafunctions/Miscellaneous//identity |10 + +identity +======== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename X + > + struct identity + { + typedef X type; + }; + + +Description +----------- + +The `identity`__ metafunction. Returns ``X`` unchanged. + +__ http://mathworld.wolfram.com/IdentityFunction.html + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Metafunction| + + +Parameters +---------- + ++---------------+-------------------+-----------------------------------+ +| Parameter | Requirement | Description | ++===============+===================+===================================+ +| ``X`` | Any type | An argument to be returned. | ++---------------+-------------------+-----------------------------------+ + + +Expression semantics +-------------------- + +For an arbitrary type ``x``: + + +.. parsed-literal:: + + typedef identity::type r; + +:Return type: + A type. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef x r; + + +:Postcondition: + ``is_same::value == true``. + + + +Example +------- + +.. parsed-literal:: + + typedef apply< identity<_1>, char >::type t1; + typedef apply< identity<_2>, char,int >::type t2; + + BOOST_MPL_ASSERT(( is_same< t1, char > )); + BOOST_MPL_ASSERT(( is_same< t2, int > )); + + +See also +-------- + +|Metafunctions|, |Placeholders|, |Trivial Metafunctions|, |always|, |apply| diff --git a/doc/src/refmanual/if_.rst b/doc/src/refmanual/if_.rst new file mode 100644 index 0000000..85330b8 --- /dev/null +++ b/doc/src/refmanual/if_.rst @@ -0,0 +1,82 @@ +.. Metafunctions/Type Selection//if_ |10 + +if\_ +==== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename C + , typename T1 + , typename T2 + > + struct if\_ + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns one of its two arguments, ``T1`` or ``T2``, depending on the value ``C``. + + +Header +------ + +.. parsed-literal:: + + #include + + +Parameters +---------- + ++---------------+-----------------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===================================+===============================================+ +| ``C`` | |Integral Constant| | A selection condition. | ++---------------+-----------------------------------+-----------------------------------------------+ +| ``T1``, ``T2``| Any type | Types to select from. | ++---------------+-----------------------------------+-----------------------------------------------+ + + +Expression semantics +-------------------- + +For any |Integral Constant| ``c`` and arbitrary types ``t1``, ``t2``: + + +.. parsed-literal:: + + typedef if_::type t; + +:Return type: + Any type. + +:Semantics: + If ``c::value == true``, ``t`` is identical to ``t1``; otherwise ``t`` is + identical to ``t2``. + + +Example +------- + +.. parsed-literal:: + + typedef if\_::type t1; + typedef if\_::type t2; + + BOOST_MPL_ASSERT(( is_same )); + BOOST_MPL_ASSERT(( is_same )); + + +See also +-------- + +|Metafunctions|, |Integral Constant|, |if_c|, |eval_if| diff --git a/doc/src/refmanual/if_c.rst b/doc/src/refmanual/if_c.rst new file mode 100644 index 0000000..bdacdd9 --- /dev/null +++ b/doc/src/refmanual/if_c.rst @@ -0,0 +1,83 @@ +.. Metafunctions/Type Selection//if_c |20 + +if_c +==== + +Synopsis +-------- + +.. parsed-literal:: + + template< + bool c + , typename T1 + , typename T2 + > + struct if_c + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns one of its two arguments, ``T1`` or ``T2``, depending on the value of +integral constant ``c``. ``if_c::type`` is a shorcut notation for +``if_< bool_,t1,t2 >::type``. + + +Header +------ + +.. parsed-literal:: + + #include + + +Parameters +---------- + ++---------------+-----------------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===================================+===============================================+ +| ``c`` | An integral constant | A selection condition. | ++---------------+-----------------------------------+-----------------------------------------------+ +| ``T1``, ``T2``| Any type | Types to select from. | ++---------------+-----------------------------------+-----------------------------------------------+ + + +Expression semantics +-------------------- + +For any integral constant ``c`` and arbitrary types ``t1``, ``t2``: + + +.. parsed-literal:: + + typedef if_c::type t; + +:Return type: + Any type. + +:Semantics: + Equivalent to ``typedef if_< bool_,t1,t2 >::type t;`` + + +Example +------- + +.. parsed-literal:: + + typedef if_c::type t1; + typedef if_c::type t2; + + BOOST_MPL_ASSERT(( is_same )); + BOOST_MPL_ASSERT(( is_same )); + + +See also +-------- + +|Metafunctions|, |Integral Constant|, |if_|, |eval_if|, |bool_| diff --git a/doc/src/refmanual/inherit.rst b/doc/src/refmanual/inherit.rst new file mode 100644 index 0000000..f8efa44 --- /dev/null +++ b/doc/src/refmanual/inherit.rst @@ -0,0 +1,197 @@ +.. Metafunctions/Miscellaneous//inherit |30 + +inherit +======= + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename T1, typename T2 + > + struct inherit\ ``2`` + { + typedef |unspecified| type; + }; + + |...| + + template< + typename T1, typename T2,\ |...| typename T\ *n* + > + struct inherit\ *n* + { + typedef |unspecified| type; + }; + + template< + typename T1 + , typename T2 + |...| + , typename T\ *n* = |unspecified| + > + struct inherit + { + typedef |unspecified| type; + }; + + +Description +----------- + +Returns an unspecified class type publically derived from |T1...Tn|. +Guarantees that derivation from |empty_base| is always a no-op, +regardless of the position and number of |empty_base| classes in +|T1...Tn|. + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Metafunction| + + +Parameters +---------- + ++---------------+-------------------+-----------------------------------+ +| Parameter | Requirement | Description | ++===============+===================+===================================+ +| |T1...Tn| | A class type | Classes to derived from. | ++---------------+-------------------+-----------------------------------+ + + +Expression semantics +-------------------- + +For artibrary class types |t1...tn|: + +.. parsed-literal:: + + typedef inherit2::type r; + +:Return type: + A class type. + +:Precondition: + ``t1`` and ``t2`` are complete types. + +:Semantics: + If both ``t1`` and ``t2`` are identical to ``empty_base``, equivalent to + + .. parsed-literal:: + + typedef empty_base r; + + + otherwise, if ``t1`` is identical to ``empty_base``, equivalent to + + .. parsed-literal:: + + typedef t2 r; + + + otherwise, if ``t2`` is identical to ``empty_base``, equivalent to + + .. parsed-literal:: + + typedef t1 r; + + + otherwise equivalent to + + .. parsed-literal:: + + struct r : t1, t2 {}; + +.. ........................................................................... + +.. parsed-literal:: + + typedef inherit\ *n*\::type r; + +:Return type: + A class type. + +:Precondition: + |t1...tn| are complete types. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + struct r + : inherit\ ``2``\< + inherit\ *n-1*\::type + , t\ *n* + > + { + }; + + +.. ........................................................................... + + +.. parsed-literal:: + + typedef inherit::type r; + +:Precondition: + |t1...tn| are complete types. + +:Return type: + A class type. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef inherit\ *n*\::type r; + + + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + struct udt1 { int n; }; + struct udt2 {}; + + typedef inherit::type r1; + typedef inherit::type r2; + typedef inherit::type r3; + typedef inherit::type r4; + typedef inherit::type r5; + + BOOST_MPL_ASSERT(( is_base_and_derived< udt1, r1> )); + BOOST_MPL_ASSERT(( is_base_and_derived< udt2, r1> )); + BOOST_MPL_ASSERT(( is_same< r2, udt1> )); + BOOST_MPL_ASSERT(( is_same< r3, udt1 > )); + BOOST_MPL_ASSERT(( is_base_and_derived< udt1, r4 > )); + BOOST_MPL_ASSERT(( is_base_and_derived< udt2, r4 > )); + BOOST_MPL_ASSERT(( is_same< r5, empty_base > )); + + +See also +-------- + +|Metafunctions|, |empty_base|, |inherit_linearly|, |identity| diff --git a/doc/src/refmanual/inherit_linearly.rst b/doc/src/refmanual/inherit_linearly.rst new file mode 100644 index 0000000..453b286 --- /dev/null +++ b/doc/src/refmanual/inherit_linearly.rst @@ -0,0 +1,131 @@ +.. Metafunctions/Miscellaneous//inherit_linearly |40 + +inherit_linearly +================ + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Types + , typename Node + , typename Root = empty_base + > + struct inherit_linearly + : fold + { + }; + + +Description +----------- + +A convenience wrapper for ``fold`` to use in the context of sequence-driven +class composition. Returns the result the successive application of binary +``Node`` to the result of the previous ``Node`` invocation (``Root`` if it's +the first call) and every type in the |Forward Sequence| ``Types`` in order. + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Metafunction| + + +Parameters +---------- + ++---------------+-------------------------------+---------------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===============================+===================================================+ +| ``Types`` | |Forward Sequence| | Types to inherit from. | ++---------------+-------------------------------+---------------------------------------------------+ +| ``Node`` | Binary |Lambda Expression| | A derivation metafunction. | ++---------------+-------------------------------+---------------------------------------------------+ +| ``Root`` | A class type | A type to be placed at the root of the class | +| | | hierarchy. | ++---------------+-------------------------------+---------------------------------------------------+ + + +Expression semantics +-------------------- + +For any |Forward Sequence| ``types``, binary |Lambda Expression| ``node``, and arbitrary +class type ``root``: + + +.. parsed-literal:: + + typedef inherit_linearly::type r; + +:Return type: + A class type. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef fold::type r; + + + +Complexity +---------- + +Linear. Exactly ``size::value`` applications of ``node``. + + +Example +------- + +.. parsed-literal:: + + template< typename T > struct tuple_field + { + T field; + }; + + template< typename T > + inline + T& field(tuple_field& t) + { + return t.field; + } + + typedef inherit_linearly< + vector + , inherit< _1, tuple_field<_2> > + >::type tuple; + + + int main() + { + tuple t; + + field(t) = -1; + field(t) = "text"; + field(t) = false; + + std::cout + << field(t) << '\n' + << field(t) << '\n' + << field(t) << '\n' + ; + } + + +See also +-------- + +|Metafunctions|, |Algorithms|, |inherit|, |empty_base|, |fold|, |reverse_fold| diff --git a/doc/src/refmanual/insert.rst b/doc/src/refmanual/insert.rst new file mode 100644 index 0000000..3330aae --- /dev/null +++ b/doc/src/refmanual/insert.rst @@ -0,0 +1,191 @@ +.. Sequences/Intrinsic Metafunctions//insert + +insert +====== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + , typename Pos + , typename T + > + struct insert + { + typedef |unspecified| type; + }; + + + template< + typename Sequence + , typename T + > + struct insert + { + typedef |unspecified| type; + }; + + +Description +----------- + +``insert`` is an |overloaded name|: + +* ``insert`` performs an insertion of + type ``T`` at an arbitrary position ``Pos`` in ``Sequence``. ``Pos`` is ignored is + ``Sequence`` is a model of |Extensible Associative Sequence|. + +* ``insert`` is a shortcut notation for ``insert`` for the + case when ``Sequence`` is a model of |Extensible Associative Sequence|. + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Tag Dispatched Metafunction| + + +Parameters +---------- + ++---------------+-----------------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===================================+===============================================+ +| ``Sequence`` | |Extensible Sequence| or | A sequence to insert into. | +| | |Extensible Associative Sequence| | | ++---------------+-----------------------------------+-----------------------------------------------+ +| ``Pos`` | |Forward Iterator| | An iterator in ``Sequence`` specifying the | +| | | insertion position. | ++---------------+-----------------------------------+-----------------------------------------------+ +| ``T`` | Any type | The element to be inserted. | ++---------------+-----------------------------------+-----------------------------------------------+ + + +Expression semantics +-------------------- + +.. compound:: + :class: expression-semantics + + For any |Extensible Sequence| ``s``, iterator ``pos`` in ``s``, and arbitrary type ``x``: + + .. parsed-literal:: + + typedef insert::type r; + + :Return type: + |Extensible Sequence| + + :Precondition: + ``pos`` is an iterator in ``s``. + + :Semantics: + ``r`` is a sequence, |concept-identical| to ``s``, of the following elements: + [``begin::type``, ``pos``), ``x``, [``pos``, ``end::type``). + + :Postcondition: + The relative order of the elements in ``r`` is the same as in ``s``. + + .. parsed-literal:: + + at< r, distance< begin::type,pos >::type >::type + + is identical to ``x``; + + .. parsed-literal:: + + size::value == size::value + 1; + + + +.. compound:: + :class: expression-semantics + + + For any |Extensible Associative Sequence| ``s``, iterator ``pos`` in ``s``, + and arbitrary type ``x``: + + + .. parsed-literal:: + + typedef insert::type r; + + :Return type: + |Extensible Associative Sequence| + + :Semantics: + ``r`` is |concept-identical| and equivalent to ``s``, except that + ``at< r, key_type::type >::type`` is identical to ``value_type::type``. + + :Postcondition: + ``size::value == size::value + 1``. + + + .. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + .. parsed-literal:: + + typedef insert::type r; + + :Return type: + |Extensible Associative Sequence| + + :Precondition: + ``pos`` is an iterator in ``s``. + + :Semantics: + Equivalent to ``typedef insert::type r``; ``pos`` is ignored. + + + +Complexity +---------- + ++---------------------------------------+-----------------------------------------------+ +| Sequence archetype | Complexity | ++=======================================+===============================================+ +| |Extensible Associative Sequence| | Amortized constant time. | ++---------------------------------------+-----------------------------------------------+ +| |Extensible Sequence| | Linear in the worst case, or amortized | +| | constant time. | ++---------------------------------------+-----------------------------------------------+ + + +Example +------- + +.. parsed-literal:: + + typedef vector_c numbers; + typedef find< numbers,integral_c >::type pos; + typedef insert< numbers,pos,integral_c >::type range; + + BOOST_MPL_ASSERT_RELATION( size::value, ==, 10 ); + BOOST_MPL_ASSERT(( equal< range,range_c > )); + + +.. parsed-literal:: + + typedef map< mpl::pair > m; + typedef insert >::type m1; + + BOOST_MPL_ASSERT_RELATION( size::value, ==, 2 ); + BOOST_MPL_ASSERT(( is_same< at::type,unsigned > )); + BOOST_MPL_ASSERT(( is_same< at::type,long > )); + + +See also +-------- + +|Extensible Sequence|, |Extensible Associative Sequence|, |insert_range|, |push_front|, |push_back|, |erase| diff --git a/doc/src/refmanual/insert_range.rst b/doc/src/refmanual/insert_range.rst new file mode 100644 index 0000000..8e93cef --- /dev/null +++ b/doc/src/refmanual/insert_range.rst @@ -0,0 +1,119 @@ +.. Sequences/Intrinsic Metafunctions//insert_range + +insert_range +============ + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + , typename Pos + , typename Range + > + struct insert_range + { + typedef |unspecified| type; + }; + + + +Description +----------- + +``insert_range`` performs an insertion of a range of elements at an arbitrary position in +the sequence. + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Tag Dispatched Metafunction| + + +Parameters +---------- + ++---------------+-----------------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===================================+===============================================+ +| ``Sequence`` | |Extensible Sequence| or | A sequence to insert into. | +| | |Extensible Associative Sequence| | | ++---------------+-----------------------------------+-----------------------------------------------+ +| ``Pos`` | |Forward Iterator| | An iterator in ``Sequence`` specifying the | +| | | insertion position. | ++---------------+-----------------------------------+-----------------------------------------------+ +| ``Range`` | |Forward Sequence| | The range of elements to be inserted. | ++---------------+-----------------------------------+-----------------------------------------------+ + + +Expression semantics +-------------------- + +For any |Extensible Sequence| ``s``, iterator ``pos`` in ``s``, and |Forward Sequence| ``range``: + +.. parsed-literal:: + + typedef insert::type r; + +:Return type: + |Extensible Sequence|. + +:Precondition: + ``pos`` is an iterator into ``s``. + +:Semantics: + ``r`` is a sequence, |concept-identical| to ``s``, of the following elements: + [``begin::type``, ``pos``), [``begin::type``, ``end::type``), + [``pos``, ``end::type``). + +:Postcondition: + The relative order of the elements in ``r`` is the same as in ``s``; + + .. parsed-literal:: + + size::value == size::value + size::value + + +Complexity +---------- + +Sequence dependent. Quadratic in the worst case, linear at best; see the particular +sequence class' specification for details. + + +Example +------- + +.. parsed-literal:: + + typedef vector_c numbers; + typedef find< numbers,integral_c >::type pos; + typedef insert_range< numbers,pos,range_c >::type range; + + BOOST_MPL_ASSERT_RELATION( size::value, ==, 10 ); + BOOST_MPL_ASSERT(( equal< range,range_c > )); + + typedef insert_range< + list\ ``0``\ <> + , end< list\ ``0``\ <> >::type + , list + >::type result2; + + BOOST_MPL_ASSERT_RELATION( size::value, ==, 1 ); + + +See also +-------- + +|Extensible Sequence|, |insert|, |push_front|, |push_back|, |erase| + diff --git a/doc/src/refmanual/inserter_.rst b/doc/src/refmanual/inserter_.rst new file mode 100644 index 0000000..11216fe --- /dev/null +++ b/doc/src/refmanual/inserter_.rst @@ -0,0 +1,101 @@ +.. Algorithms/Inserters//inserter + +|+inserter+| +================ + +.. _`inserter_`: + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename State + , typename Operation + > + struct inserter + { + typedef State state; + typedef Operation operation; + }; + + +Description +----------- + +A general-purpose model of the |Inserter| concept. + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Inserter| + + +Parameters +---------- + ++---------------+-------------------------------+-----------------------------------+ +| Parameter | Requirement | Description | ++===============+===============================+===================================+ +| ``State`` | Any type | A initial state. | ++---------------+-------------------------------+-----------------------------------+ +| ``Operation`` | Binary |Lambda Expression| | An output operation. | ++---------------+-------------------------------+-----------------------------------+ + +Expression semantics +-------------------- + +|Semantics disclaimer...| |Inserter|. + +For any binary |Lambda Expression| ``op`` and arbitrary type ``state``: + ++---------------------------+-------------------------------------------+ +| Expression | Semantics | ++===========================+===========================================+ +| ``inserter`` | An |Inserter|. | ++---------------------------+-------------------------------------------+ + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + template< typename N > struct is_odd : bool_< ( N::value % 2 ) > {}; + + typedef copy< + range_c + , inserter< // a filtering 'push_back' inserter + vector<> + , if_< is_odd<_2>, push_back<_1,_2>, _1 > + > + >::type odds; + + BOOST_MPL_ASSERT(( equal< odds, vector_c, equal_to<_,_> > )); + + +See also +-------- + +|Algorithms|, |Inserter|, |Reversible Algorithm|, |front_inserter|, |back_inserter| + + +.. |+inserter+| replace:: inserter +.. |inserter| replace:: |``inserter``|__ +.. |``inserter``| replace:: :refentry:`inserter` +__ `inserter_`_ diff --git a/doc/src/refmanual/int_.rst b/doc/src/refmanual/int_.rst new file mode 100644 index 0000000..96d4c25 --- /dev/null +++ b/doc/src/refmanual/int_.rst @@ -0,0 +1,84 @@ +.. Data Types/Numeric//int_ |20 + +int\_ +===== + +Synopsis +-------- + +.. parsed-literal:: + + template< + int N + > + struct int\_ + { + // |unspecified| + // ... + }; + + +Description +----------- + +An |Integral Constant| wrapper for ``int``. + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Integral Constant| + + +Parameters +---------- + ++---------------+-------------------------------+---------------------------+ +| Parameter | Requirement | Description | ++===============+===============================+===========================+ +| ``N`` | An integral constant | A value to wrap. | ++---------------+-------------------------------+---------------------------+ + +Expression semantics +-------------------- + +|Semantics disclaimer...| |Integral Constant|. + +For arbitrary integral constant ``n``: + ++-------------------+-----------------------------------------------------------+ +| Expression | Semantics | ++===================+===========================================================+ +| ``int_`` | An |Integral Constant| ``x`` such that ``x::value == c`` | +| | and ``x::value_type`` is identical to ``int``. | ++-------------------+-----------------------------------------------------------+ + + +Example +------- + +.. parsed-literal:: + + typedef int_<8> eight; + + BOOST_MPL_ASSERT(( is_same< eight::value_type, int > )); + BOOST_MPL_ASSERT(( is_same< eight::type, eight > )); + BOOST_MPL_ASSERT(( is_same< next< eight >::type, int_<9> > )); + BOOST_MPL_ASSERT(( is_same< prior< eight >::type, int_<7> > )); + BOOST_MPL_ASSERT_RELATION( (eight::value), ==, 8 ); + assert( eight() == 8 ); + + +See also +-------- + +|Data Types|, |Integral Constant|, |long_|, |size_t|, |integral_c| + diff --git a/doc/src/refmanual/integral_c.rst b/doc/src/refmanual/integral_c.rst new file mode 100644 index 0000000..34470e9 --- /dev/null +++ b/doc/src/refmanual/integral_c.rst @@ -0,0 +1,87 @@ +.. Data Types/Numeric//integral_c |50 + +integral_c +========== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename T, T N + > + struct integral_c + { + // |unspecified| + // ... + }; + + +Description +----------- + +A generic |Integral Constant| wrapper. + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Integral Constant| + + +Parameters +---------- + ++---------------+-------------------------------+---------------------------+ +| Parameter | Requirement | Description | ++===============+===============================+===========================+ +| ``T`` | An integral type | Wrapper's value type. | ++---------------+-------------------------------+---------------------------+ +| ``N`` | An integral constant | A value to wrap. | ++---------------+-------------------------------+---------------------------+ + + +Expression semantics +-------------------- + +|Semantics disclaimer...| |Integral Constant|. + +For arbitrary integral type ``t`` and integral constant ``n``: + ++-----------------------+-----------------------------------------------------------+ +| Expression | Semantics | ++=======================+===========================================================+ +| ``integral_c`` | An |Integral Constant| ``x`` such that ``x::value == c`` | +| | and ``x::value_type`` is identical to ``t``. | ++-----------------------+-----------------------------------------------------------+ + + +Example +------- + +.. parsed-literal:: + + typedef integral_c eight; + + BOOST_MPL_ASSERT(( is_same< eight::value_type, short > )); + BOOST_MPL_ASSERT(( is_same< eight::type, eight > )); + BOOST_MPL_ASSERT(( is_same< next< eight >::type, integral_c > )); + BOOST_MPL_ASSERT(( is_same< prior< eight >::type, integral_c > )); + BOOST_MPL_ASSERT_RELATION( (eight::value), ==, 8 ); + assert( eight() == 8 ); + + +See also +-------- + +|Data Types|, |Integral Constant|, |bool_|, |int_|, |long_|, |size_t| + diff --git a/doc/src/refmanual/is_sequence.rst b/doc/src/refmanual/is_sequence.rst new file mode 100644 index 0000000..b044636 --- /dev/null +++ b/doc/src/refmanual/is_sequence.rst @@ -0,0 +1,94 @@ +.. Sequences/Intrinsic Metafunctions//is_sequence + +is_sequence +=========== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename X + > + struct is_sequence + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns a boolean |Integral Constant| ``c`` such that ``c::value == true`` if and +only if ``X`` is a model of |Forward Sequence|. + + +Header +------ + +.. parsed-literal:: + + #include + + +Parameters +---------- + ++---------------+-------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===================+===============================================+ +| ``X`` | Any type | The type to query. | ++---------------+-------------------+-----------------------------------------------+ + + +Expression semantics +-------------------- + + +.. parsed-literal:: + + typedef is_sequence::type c; + +:Return type: + Boolean |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef not_< is_same< begin::type,void_ > >::type c; + + + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + struct UDT {}; + + BOOST_MPL_ASSERT_NOT(( is_sequence< std::vector > )); + BOOST_MPL_ASSERT_NOT(( is_sequence< int > )); + BOOST_MPL_ASSERT_NOT(( is_sequence< int& > )); + BOOST_MPL_ASSERT_NOT(( is_sequence< UDT > )); + BOOST_MPL_ASSERT_NOT(( is_sequence< UDT* > )); + BOOST_MPL_ASSERT(( is_sequence< range_c > )); + BOOST_MPL_ASSERT(( is_sequence< list<> > )); + BOOST_MPL_ASSERT(( is_sequence< list > )); + BOOST_MPL_ASSERT(( is_sequence< vector<> > )); + BOOST_MPL_ASSERT(( is_sequence< vector > )); + + +See also +-------- + +|Forward Sequence|, |begin|, |end|, |vector|, |list|, |range_c| diff --git a/doc/src/refmanual/iter_fold.rst b/doc/src/refmanual/iter_fold.rst new file mode 100644 index 0000000..871c51d --- /dev/null +++ b/doc/src/refmanual/iter_fold.rst @@ -0,0 +1,114 @@ +.. Algorithms/Iteration Algorithms//iter_fold + +iter_fold +========= + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + , typename State + , typename ForwardOp + > + struct iter_fold + { + typedef |unspecified| type; + }; + + + +Description +----------- + +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::type``, ``end::type``) in order. + + +Header +------ + +.. parsed-literal:: + + #include + + + +Parameters +---------- + ++---------------+-------------------------------+---------------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===============================+===================================================+ +| ``Sequence`` | |Forward Sequence| | A sequence to iterate. | ++---------------+-------------------------------+---------------------------------------------------+ +| ``State`` | Any type | The initial state for the first ``ForwardOp`` | +| | | application. | ++---------------+-------------------------------+---------------------------------------------------+ +| ``ForwardOp`` | Binary |Lambda Expression| | The operation to be executed on forward | +| | | traversal. | ++---------------+-------------------------------+---------------------------------------------------+ + + +Expression semantics +-------------------- + +For any |Forward Sequence| ``s``, binary |Lambda Expression| ``op``, and an +arbitrary type ``state``: + + +.. parsed-literal:: + + typedef iter_fold::type t; + +:Return type: + A type. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef begin::type i\ :sub:`1`; + typedef apply::type state\ :sub:`1`; + typedef next::type i\ :sub:`2`; + typedef apply::type state\ :sub:`2`; + |...| + typedef apply::type state\ :sub:`n`; + typedef next::type last; + typedef state\ :sub:`n` t; + + where ``n == size::value`` and ``last`` is identical to ``end::type``; equivalent + to ``typedef state t;`` if ``empty::value == true``. + + + +Complexity +---------- + +Linear. Exactly ``size::value`` applications of ``op``. + + +Example +------- + +.. parsed-literal:: + + typedef vector_c numbers; + typedef iter_fold< + numbers + , begin::type + , if_< less< deref<_1>, deref<_2> >,_2,_1 > + >::type max_element_iter; + + BOOST_MPL_ASSERT_RELATION( deref::type::value, ==, 7 ); + + + +See also +-------- + +|Algorithms|, |reverse_iter_fold|, |fold|, |reverse_fold|, |copy| diff --git a/doc/src/refmanual/iter_fold_if.rst b/doc/src/refmanual/iter_fold_if.rst new file mode 100644 index 0000000..2d01084 --- /dev/null +++ b/doc/src/refmanual/iter_fold_if.rst @@ -0,0 +1,125 @@ +.. .. Algorithms/Iteration Algorithms + +iter_fold_if +============ + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + , typename State + , typename ForwardOp + , typename ForwardPred + , typename BackwardOp = |unspecified| + , typename BackwardPred = |unspecified| + > + struct iter_fold_if + { + typedef |unspecified| type; + }; + + +Description +----------- + +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 sequence range determined by ``ForwardPred`` predicate. If ``BackwardOp`` +is provided, it's similarly applied on backward traversal to the result of the +previous ``BackwardOp`` invocation (the last result returned by ``ForwardOp` if it's +the first call) and each iterator in the sequence range determined by +``BackwardPred`` predicate. + + +Header +------ + +.. parsed-literal:: + + #include + + +Parameters +---------- + ++-------------------+-------------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===================================+===============================================+ +| ``Sequence`` | |Forward Sequence| | A sequence to iterate. | ++-------------------+-------------------------------+-----------------------------------------------+ +| ``State`` | Any type | The initial state for the first ``BackwardOp``| +| | | / ``ForwardOp`` application. | ++-------------------+-------------------------------+-----------------------------------------------+ +| ``ForwardOp`` | Binary |Lambda Expression| | The operation to be executed on forward | +| | | traversal. | ++-------------------+-------------------------------+-----------------------------------------------+ +| ``ForwardPred`` | Binary |Lambda Expression| | The forward traversal predicate. | ++-------------------+-------------------------------+-----------------------------------------------+ +| ``BackwardOp`` | Binary |Lambda Expression| | The operation to be executed on backward | +| | | traversal. | ++-------------------+-------------------------------+-----------------------------------------------+ +| ``BackwardPred`` | Binary |Lambda Expression| | The backward traversal predicate. | ++-------------------+-------------------------------+-----------------------------------------------+ + + +Expression semantics +-------------------- + + +.. parsed-literal:: + + typedef iter_fold::type t; + +:Return type: + A type + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef lambda::type op; + typedef begin::type i1; + typedef apply::type t1; + typedef i1::next i2; + typedef apply::type t2; + ... + typedef apply::type tn; + typedef in::next last; + typedef tn t + + where ``n == size::value`` and ``last`` is identical to ``end::type``; + + Equivalent to ``typedef T t;`` if the sequence is empty. + + + +Complexity +---------- + +Linear. Exactly ``size::value`` applications of ``ForwardOp``. + + +Example +------- + +.. parsed-literal:: + + typedef list_c numbers; + typedef iter_fold< + numbers + , begin::type + , if_< less< deref<_1>, deref<_2> >,_2,_1 > + >::type max_element_iter; + + BOOST_STATIC_ASSERT(max_element_iter::type::value == 7); + + + +See also +-------- + +Algorithms, ``iter_fold_backward``, ``fold``, ``fold_backward``, ``copy``, ``copy_backward`` diff --git a/doc/src/refmanual/iterator_category.rst b/doc/src/refmanual/iterator_category.rst new file mode 100644 index 0000000..5b10d0d --- /dev/null +++ b/doc/src/refmanual/iterator_category.rst @@ -0,0 +1,110 @@ +.. Iterators/Iterator Metafunctions//iterator_category |60 + +iterator_category +================= + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Iterator + > + struct iterator_category + { + typedef typename Iterator::category type; + }; + + + +Description +----------- + +Returns one of the following iterator category tags: + +* ``forward_iterator_tag`` +* ``bidirectional_iterator_tag`` +* ``random_access_iterator_tag`` + + +Header +------ + +.. parsed-literal:: + + #include + #include + + +Parameters +---------- + ++---------------+-----------------------+-------------------------------------------+ +| Parameter | Requirement | Description | ++===============+=======================+===========================================+ +| ``Iterator`` | |Forward Iterator| | The iterator to obtain a category for. | ++---------------+-----------------------+-------------------------------------------+ + + +Expression semantics +-------------------- + +For any |Forward Iterator|\ s ``iter``: + + +.. parsed-literal:: + + typedef iterator_category::type tag; + +:Return type: + |Integral Constant|. + +:Semantics: + ``tag`` is ``forward_iterator_tag`` if ``iter`` is a model of |Forward Iterator|, + ``bidirectional_iterator_tag`` if ``iter`` is a model of |Bidirectional Iterator|, + or ``random_access_iterator_tag`` if ``iter`` is a model of |Random Access Iterator|; + +:Postcondition: + ``forward_iterator_tag::value < bidirectional_iterator_tag::value``, + ``bidirectional_iterator_tag::value < random_access_iterator_tag::value``. + + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + template< typename Tag, typename Iterator > + struct algorithm_impl + { + // *O(n)* implementation + }; + + template< typename Iterator > + struct algorithm_impl + { + // *O(1)* implementation + }; + + template< typename Iterator > + struct algorithm + : algorithm_impl< + iterator_category::type + , Iterator + > + { + }; + + + +See also +-------- + +|Iterators|, |begin| / |end|, |advance|, |distance|, |next| diff --git a/doc/src/refmanual/iterator_range.rst b/doc/src/refmanual/iterator_range.rst new file mode 100644 index 0000000..9799764 --- /dev/null +++ b/doc/src/refmanual/iterator_range.rst @@ -0,0 +1,93 @@ +.. Sequences/Views//iterator_range + +iterator_range +============== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename First + , typename Last + > + struct iterator_range + { + // |unspecified| + // |...| + }; + + +Description +----------- + +A view into subset of sequence elements identified by a pair of iterators. + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +* `Forward`__, `Bidirectional`__, or |Random Access Sequence|, depending on the category + of the underlaying iterators. + +__ `Forward Sequence`_ +__ `Bidirectional Sequence`_ + + + +Parameters +---------- + ++---------------+-----------------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===================================+===============================================+ +| ``First``, | |Forward Iterator| | Iterators identifying the view's boundaries. | +| ``Last`` | | | ++---------------+-----------------------------------+-----------------------------------------------+ + + +Expression semantics +-------------------- + +|Semantics disclaimer...| |Forward Sequence|. + +In the following table, ``v`` is an instance of ``iterator_range``, ``first`` and ``last`` are +iterators into a |Forward Sequence|, and [``first``, ``last``) form a valid range. + ++-------------------------------------------+-------------------------------------------------------+ +| Expression | Semantics | ++===========================================+=======================================================+ +| .. parsed-literal:: | A lazy sequence all the elements in the range | +| | [``first``, ``last``). | +| iterator_range | | +| iterator_range::type | | ++-------------------------------------------+-------------------------------------------------------+ + +Example +------- + +.. parsed-literal:: + + typedef range_c r; + typedef advance_c< begin::type,10 >::type first; + typedef advance_c< end::type,-10 >::type last; + + BOOST_MPL_ASSERT(( equal< + iterator_range + , range_c + > )); + + +See also +-------- + +|Sequences|, |Views|, |filter_view|, |transform_view|, |joint_view|, |zip_view|, |max_element| diff --git a/doc/src/refmanual/joint_view.rst b/doc/src/refmanual/joint_view.rst new file mode 100644 index 0000000..c69b1bb --- /dev/null +++ b/doc/src/refmanual/joint_view.rst @@ -0,0 +1,91 @@ +.. Sequences/Views//joint_view + +joint_view +========== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence1 + , typename Sequence2 + > + struct joint_view + { + // |unspecified| + // |...| + }; + + + +Description +----------- + +A view into the sequence of elements formed by concatenating ``Sequence1`` +and ``Sequence2`` elements. + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +* |Forward Sequence| + + +Parameters +---------- + ++-----------------------+---------------------------+-----------------------------------+ +| Parameter | Requirement | Description | ++=======================+===========================+===================================+ +| ``Sequence1``, | |Forward Sequence| | Sequences to create a view on. | +| ``Sequence2`` | | | ++-----------------------+---------------------------+-----------------------------------+ + +Expression semantics +-------------------- + +|Semantics disclaimer...| |Forward Sequence|. + +In the following table, ``v`` is an instance of ``joint_view``, ``s1`` and ``s2`` are arbitrary +|Forward Sequence|\ s. + ++-------------------------------+-----------------------------------------------------------+ +| Expression | Semantics | ++===============================+===========================================================+ +| .. parsed-literal:: | A lazy |Forward Sequence| of all the elements in the | +| | ranges |begin/end|, |begin/end|. | +| joint_view | | +| joint_view::type | | ++-------------------------------+-----------------------------------------------------------+ +| ``size::type`` | The size of ``v``; | +| | ``size::value == size::value + size::value``; | +| | linear complexity; see |Forward Sequence|. | ++-------------------------------+-----------------------------------------------------------+ + +Example +------- + +.. parsed-literal:: + + typedef joint_view< + range_c + , range_c + > numbers; + + BOOST_MPL_ASSERT(( equal< numbers, range_c > )); + + +See also +-------- + +|Sequences|, |Views|, |filter_view|, |transform_view|, |zip_view|, |iterator_range| diff --git a/doc/src/refmanual/key_type.rst b/doc/src/refmanual/key_type.rst new file mode 100644 index 0000000..265b443 --- /dev/null +++ b/doc/src/refmanual/key_type.rst @@ -0,0 +1,100 @@ +.. Sequences/Intrinsic Metafunctions//key_type + +key_type +======== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + , typename X + > + struct key_type + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns the |key| that would be used to identify ``X`` in ``Sequence``. + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Tag Dispatched Metafunction| + + +Parameters +---------- + ++---------------+---------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===========================+===============================================+ +| ``Sequence`` | |Associative Sequence| | A sequence to query. | ++---------------+---------------------------+-----------------------------------------------+ +| ``X`` | Any type | The type to get the |key| for. | ++---------------+---------------------------+-----------------------------------------------+ + + +Expression semantics +-------------------- + +For any |Associative Sequence| ``s``, iterators ``pos1`` and ``pos2`` in ``s``, and an +artibrary type ``x``: + +.. parsed-literal:: + + typedef key_type::type k; + +:Return type: + A type. + +:Precondition: + ``x`` can be put in ``s``. + +:Semantics: + ``k`` is the |key| that would be used to identify ``x`` in ``s``. + +:Postcondition: + If ``key_type< s,deref::type >::type`` is identical to + ``key_type< s,deref::type >::type`` then ``pos1`` is identical to ``pos2``. + + + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + typedef key_type< map<>,pair >::type k1; + typedef key_type< set<>,pair >::type k2; + + BOOST_MPL_ASSERT(( is_same< k1,int > )); + BOOST_MPL_ASSERT(( is_same< k2,pair > )); + + +See also +-------- + +|Associative Sequence|, |value_type|, |has_key|, |set|, |map| diff --git a/doc/src/refmanual/lambda.rst b/doc/src/refmanual/lambda.rst new file mode 100644 index 0000000..762b85b --- /dev/null +++ b/doc/src/refmanual/lambda.rst @@ -0,0 +1,122 @@ +.. Metafunctions/Composition and Argument Binding//lambda |20 + +lambda +====== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename X + , typename Tag = |unspecified| + > + struct lambda + { + typedef |unspecified| type; + }; + + + +Description +----------- + +If ``X`` is a |placeholder expression|, transforms ``X`` into a corresponding +|Metafunction Class|, otherwise ``X`` is returned unchanged. + + +Header +------ + +.. parsed-literal:: + + #include + + +Parameters +---------- + ++---------------+-----------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+=======================+===============================================+ +| ``X`` | Any type | An expression to transform. | ++---------------+-----------------------+-----------------------------------------------+ +| ``Tag`` | Any type | A tag determining transform semantics. | ++---------------+-----------------------+-----------------------------------------------+ + +Expression semantics +-------------------- + +For arbitrary types ``x`` and ``tag``: + + +.. parsed-literal:: + + typedef lambda::type f; + +:Return type: + |Metafunction Class|. + +:Semantics: + If ``x`` is a |placeholder expression| in a general form ``X``, where + ``X`` is a class template and ``a1``,... ``an`` are arbitrary types, equivalent + to + + .. parsed-literal:: + + typedef protect< bind< + quote\ *n*\ + , lambda::type,\ |...| lambda::type + > > f; + + otherwise, ``f`` is identical to ``x``. + +.. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. parsed-literal:: + + typedef lambda::type f; + +:Return type: + |Metafunction Class|. + +:Semantics: + If ``x`` is a |placeholder expression| in a general form ``X``, where + ``X`` is a class template and ``a1``,... ``an`` are arbitrary types, equivalent + to + + .. parsed-literal:: + + typedef protect< bind< + quote\ *n*\ + , lambda::type,\ |...| lambda::type + > > f; + + otherwise, ``f`` is identical to ``x``. + + +Example +------- + +.. parsed-literal:: + + template< typename N1, typename N2 > struct int_plus + : int_<( N1::value + N2::value )> + { + }; + + typedef lambda< int_plus<_1, int_<42> > >::type f1; + typedef bind< quote\ ``2``\ , _1, int_<42> > f2; + + typedef f1::apply<42>::type r1; + typedef f2::apply<42>::type r2; + + BOOST_MPL_ASSERT_RELATION( r1::value, ==, 84 ); + BOOST_MPL_ASSERT_RELATION( r2::value, ==, 84 ); + + +See also +-------- + +|Composition and Argument Binding|, |Invocation|, |Placeholders|, |bind|, |quote|, |protect|, |apply| diff --git a/doc/src/refmanual/less.rst b/doc/src/refmanual/less.rst new file mode 100644 index 0000000..9e6d8f5 --- /dev/null +++ b/doc/src/refmanual/less.rst @@ -0,0 +1,114 @@ +.. Metafunctions/Comparisons//less |10 + +less +==== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename T1 + , typename T2 + > + struct less + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns a true-valued |Integral Constant| if ``T1`` is less than ``T2``. + + +Header +------ + +.. parsed-literal:: + + #include + #include + + +Model of +-------- + +|Numeric Metafunction| + + +Parameters +---------- + ++---------------+---------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===========================+===============================================+ +| ``T1``, ``T2``| |Integral Constant| | Operation's arguments. | ++---------------+---------------------------+-----------------------------------------------+ + +|Note:| |numeric metafunction note| |-- end note| + + +Expression semantics +-------------------- + + +For any |Integral Constant|\ s ``c1`` and ``c2``: + +.. parsed-literal:: + + typedef less::type r; + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef bool_< (c1::value < c2::value) > r; + + +.. .......................................................................... + +.. parsed-literal:: + + typedef less r; + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + struct r : less::type {}; + + + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + BOOST_MPL_ASSERT(( less< int_<0>, int_<10> > )); + BOOST_MPL_ASSERT_NOT(( less< long_<10>, int_<0> > )); + BOOST_MPL_ASSERT_NOT(( less< long_<10>, int_<10> > )); + + +See also +-------- + +|Comparisons|, |Numeric Metafunction|, |numeric_cast|, |less_equal|, |greater|, |equal| + diff --git a/doc/src/refmanual/less_equal.rst b/doc/src/refmanual/less_equal.rst new file mode 100644 index 0000000..834a9cb --- /dev/null +++ b/doc/src/refmanual/less_equal.rst @@ -0,0 +1,114 @@ +.. Metafunctions/Comparisons//less_equal |20 + +less_equal +========== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename T1 + , typename T2 + > + struct less_equal + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns a true-valued |Integral Constant| if ``T1`` is less than or equal to ``T2``. + + +Header +------ + +.. parsed-literal:: + + #include + #include + + +Model of +-------- + +|Numeric Metafunction| + + +Parameters +---------- + ++---------------+---------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===========================+===============================================+ +| ``T1``, ``T2``| |Integral Constant| | Operation's arguments. | ++---------------+---------------------------+-----------------------------------------------+ + +|Note:| |numeric metafunction note| |-- end note| + + +Expression semantics +-------------------- + + +For any |Integral Constant|\ s ``c1`` and ``c2``: + +.. parsed-literal:: + + typedef less_equal::type r; + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef bool_< (c1::value <= c2::value) > r; + + +.. .......................................................................... + +.. parsed-literal:: + + typedef less_equal r; + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + struct r : less_equal::type {}; + + + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + BOOST_MPL_ASSERT(( less_equal< int_<0>, int_<10> > )); + BOOST_MPL_ASSERT_NOT(( less_equal< long_<10>, int_<0> > )); + BOOST_MPL_ASSERT(( less_equal< long_<10>, int_<10> > )); + + +See also +-------- + +|Comparisons|, |Numeric Metafunction|, |numeric_cast|, |less|, |greater|, |equal| + diff --git a/doc/src/refmanual/list.rst b/doc/src/refmanual/list.rst new file mode 100644 index 0000000..5428838 --- /dev/null +++ b/doc/src/refmanual/list.rst @@ -0,0 +1,113 @@ +.. Sequences/Classes//list |20 + +list +==== + +Description +----------- + +A ``list`` is a |variadic|, `forward`__, `extensible`__ sequence of types that +supports constant-time insertion and removal of elements at the beginning, and +linear-time insertion and removal of elements at the end and in the middle. + +__ `Forward Sequence`_ +__ `Extensible Sequence`_ + +Header +------ + ++-------------------+-------------------------------------------------------+ +| Sequence form | Header | ++===================+=======================================================+ +| Variadic | ``#include `` | ++-------------------+-------------------------------------------------------+ +| Numbered | ``#include `` | ++-------------------+-------------------------------------------------------+ + + +Model of +-------- + +* |Variadic Sequence| +* |Forward Sequence| +* |Extensible Sequence| +* |Front Extensible Sequence| + + +Expression semantics +-------------------- + +In the following table, ``l`` is a ``list``, ``pos`` and ``last`` are iterators into ``l``, +``r`` is a |Forward Sequence|, and |t1...tn| and ``x`` are arbitrary types. + ++---------------------------------------+-----------------------------------------------------------+ +| Expression | Semantics | ++=======================================+===========================================================+ +| .. parsed-literal:: | ``list`` of elements |t1...tn|; see | +| | |Variadic Sequence|. | +| list<|t1...tn|> | | +| list\ *n*\ <|t1...tn|> | | ++---------------------------------------+-----------------------------------------------------------+ +| .. parsed-literal:: | Identical to ``list``\ *n*\ ``<``\ |t1...tn|\ ``>``; | +| | see |Variadic Sequence|. | +| list<|t1...tn|>::type | | +| list\ *n*\ <|t1...tn|>::type | | ++---------------------------------------+-----------------------------------------------------------+ +| ``begin::type`` | An iterator to the beginning of ``l``; | +| | see |Forward Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``end::type`` | An iterator to the end of ``l``; | +| | see |Forward Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``size::type`` | The size of ``l``; see |Forward Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``empty::type`` | |true if and only if| ``l`` is empty; see | +| | |Forward Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``front::type`` | The first element in ``l``; see | +| | |Forward Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``insert::type`` | A new ``list`` of following elements: | +| | [``begin::type``, ``pos``), ``x``, | +| | [``pos``, ``end::type``); see |Extensible Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``insert_range::type`` | A new ``list`` of following elements: | +| | [``begin::type``, ``pos``), | +| | [``begin::type``, ``end::type``) | +| | [``pos``, ``end::type``); see |Extensible Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``erase::type`` | A new ``list`` of following elements: | +| | [``begin::type``, ``pos``), | +| | [``next::type``, ``end::type``); see | +| | |Extensible Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``erase::type`` | A new ``list`` of following elements: | +| | [``begin::type``, ``pos``), | +| | [``last``, ``end::type``); see |Extensible Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``clear::type`` | An empty ``list``; see |Extensible Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``push_front::type`` | A new ``list`` containing ``x`` as its first | +| | element; see |Front Extensible Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``pop_front::type`` | A new ``list`` containing all but the first elements | +| | of ``l`` in the same order; see | +| | |Front Extensible Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ + + +Example +------- + +.. parsed-literal:: + + typedef list floats; + typedef push_front::type types; + + BOOST_MPL_ASSERT(( is_same< front::type, int > )); + + +See also +-------- + +|Sequences|, |Variadic Sequence|, |Forward Sequence|, |Extensible Sequence|, |vector|, |list_c| diff --git a/doc/src/refmanual/list_c.rst b/doc/src/refmanual/list_c.rst new file mode 100644 index 0000000..df7ff48 --- /dev/null +++ b/doc/src/refmanual/list_c.rst @@ -0,0 +1,79 @@ +.. Sequences/Classes//list_c |80 + +list_c +====== + +Description +----------- + +``list_c`` is an |Integral Sequence Wrapper| for |list|. As such, it shares +all |list| characteristics and requirements, and differs only in the way the +original sequence content is specified. + +Header +------ + ++-------------------+-------------------------------------------------------+ +| Sequence form | Header | ++===================+=======================================================+ +| Variadic | ``#include `` | ++-------------------+-------------------------------------------------------+ +| Numbered | ``#include `` | ++-------------------+-------------------------------------------------------+ + + +Model of +-------- + +* |Integral Sequence Wrapper| +* |Variadic Sequence| +* |Forward Sequence| +* |Extensible Sequence| +* |Front Extensible Sequence| + + +Expression semantics +-------------------- + +|Semantics disclaimer...| |list|. + +.. workaround substitution bug (should be replace:: list\ *n*\ _c) +.. |listn_c| replace:: list\ *n*\ _c + ++---------------------------------------+-----------------------------------------------+ +| Expression | Semantics | ++=======================================+===============================================+ +| .. parsed-literal:: | A |list| of integral constant wrappers | +| | ``integral_c``, | +| list_c | ``integral_c``, ... | +| |listn_c| | ``integral_c``; | +| | see |Integral Sequence Wrapper|. | ++---------------------------------------+-----------------------------------------------+ +| .. parsed-literal:: | Identical to ``list``\ *n*\ ``<`` | +| | ``integral_c``, | +| list_c::type | ``integral_c``, ... | +| |listn_c|::type | ``integral_c`` ``>``; | +| | see |Integral Sequence Wrapper|. | ++---------------------------------------+-----------------------------------------------+ +| .. parsed-literal:: | Identical to ``T``; see | +| | |Integral Sequence Wrapper|. | +| list_c::value_type | | +| |listn_c|::value_type | | ++---------------------------------------+-----------------------------------------------+ + + +Example +------- + +.. parsed-literal:: + + typedef list_c fibonacci; + typedef push_front >::type fibonacci2; + + BOOST_MPL_ASSERT_RELATION( front::type::value, ==, 1 ); + + +See also +-------- + +|Sequences|, |Integral Sequence Wrapper|, |list|, |integral_c|, |vector_c|, |set_c|, |range_c| diff --git a/doc/src/refmanual/long_.rst b/doc/src/refmanual/long_.rst new file mode 100644 index 0000000..cf3567d --- /dev/null +++ b/doc/src/refmanual/long_.rst @@ -0,0 +1,84 @@ +.. Data Types/Numeric//long_ |30 + +long\_ +====== + +Synopsis +-------- + +.. parsed-literal:: + + template< + long N + > + struct long\_ + { + // |unspecified| + // ... + }; + + +Description +----------- + +An |Integral Constant| wrapper for ``long``. + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Integral Constant| + + +Parameters +---------- + ++---------------+-------------------------------+---------------------------+ +| Parameter | Requirement | Description | ++===============+===============================+===========================+ +| ``N`` | An integral constant | A value to wrap. | ++---------------+-------------------------------+---------------------------+ + +Expression semantics +-------------------- + +|Semantics disclaimer...| |Integral Constant|. + +For arbitrary integral constant ``n``: + ++-------------------+-----------------------------------------------------------+ +| Expression | Semantics | ++===================+===========================================================+ +| ``long_`` | An |Integral Constant| ``x`` such that ``x::value == c`` | +| | and ``x::value_type`` is identical to ``long``. | ++-------------------+-----------------------------------------------------------+ + + +Example +------- + +.. parsed-literal:: + + typedef long_<8> eight; + + BOOST_MPL_ASSERT(( is_same< eight::value_type, long > )); + BOOST_MPL_ASSERT(( is_same< eight::type, eight > )); + BOOST_MPL_ASSERT(( is_same< next< eight >::type, long_<9> > )); + BOOST_MPL_ASSERT(( is_same< prior< eight >::type, long_<7> > )); + BOOST_MPL_ASSERT_RELATION( (eight::value), ==, 8 ); + assert( eight() == 8 ); + + +See also +-------- + +|Data Types|, |Integral Constant|, |int_|, |size_t|, |integral_c| + diff --git a/doc/src/refmanual/lower_bound.rst b/doc/src/refmanual/lower_bound.rst new file mode 100644 index 0000000..d3f417f --- /dev/null +++ b/doc/src/refmanual/lower_bound.rst @@ -0,0 +1,103 @@ +.. Algorithms/Querying Algorithms//lower_bound |60 + +lower_bound +=========== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + , typename T + , typename Pred = less<_1,_2> + > + struct lower_bound + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns the first position in the sorted ``Sequence`` where ``T`` could be inserted without +violating the ordering. + + +Header +------ + +.. parsed-literal:: + + #include + + +Parameters +---------- + ++---------------+-------------------------------+-----------------------------------+ +| Parameter | Requirement | Description | ++===============+===============================+===================================+ +|``Sequence`` | |Forward Sequence| | A sorted sequence to search in. | ++---------------+-------------------------------+-----------------------------------+ +|``T`` | Any type | A type to search a position for. | ++---------------+-------------------------------+-----------------------------------+ +|``Pred`` | Binary |Lambda Expression| | A search criteria. | ++---------------+-------------------------------+-----------------------------------+ + + +Expression semantics +-------------------- + +For any sorted |Forward Sequence| ``s``, binary |Lambda Expression| ``pred``, and +arbitrary type ``x``: + + +.. parsed-literal:: + + typedef lower_bound< s,x,pred >::type i; + +:Return type: + |Forward Iterator|. + +:Semantics: + ``i`` is the furthermost iterator in |begin/end| such that, for every iterator + ``j`` in [``begin::type``, ``i``), + + .. parsed-literal:: + + apply< pred, deref::type, x >::type::value == true + + + +Complexity +---------- + +The number of comparisons is logarithmic: at most log\ :sub:`2`\ ( ``size::value`` ) + 1. +If ``s`` 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::value``. + + +Example +------- + +.. parsed-literal:: + + typedef vector_c numbers; + typedef lower_bound< numbers, int_<3> >::type iter; + + BOOST_MPL_ASSERT_RELATION( + (distance< begin::type,iter >::value), ==, 2 + ); + + BOOST_MPL_ASSERT_RELATION( deref::type::value, ==, 3 ); + + +See also +-------- + +|Querying Algorithms|, |upper_bound|, |find|, |find_if|, |min_element| diff --git a/doc/src/refmanual/map.rst b/doc/src/refmanual/map.rst new file mode 100644 index 0000000..40add41 --- /dev/null +++ b/doc/src/refmanual/map.rst @@ -0,0 +1,130 @@ +.. Sequences/Classes//map |50 + +map +=== + +Description +----------- + +``map`` is a |variadic|, `associative`__, `extensible`__ sequence of type pairs that +supports constant-time insertion and removal of elements, and testing for membership. +A ``map`` may contain at most one element for each key. + +__ `Associative Sequence`_ +__ `Extensible Associative Sequence`_ + +Header +------ + ++-------------------+-------------------------------------------------------+ +| Sequence form | Header | ++===================+=======================================================+ +| Variadic | ``#include `` | ++-------------------+-------------------------------------------------------+ +| Numbered | ``#include `` | ++-------------------+-------------------------------------------------------+ + + +Model of +-------- + +* |Variadic Sequence| +* |Associative Sequence| +* |Extensible Associative Sequence| + + +Expression semantics +-------------------- + +|In the following table...| ``m`` is an instance of ``map``, +``pos`` is an iterator into ``m``, ``x`` and |p1...pn| are ``pair``\ s, and ``k`` is an arbitrary type. + ++---------------------------------------+-----------------------------------------------------------+ +| Expression | Semantics | ++=======================================+===========================================================+ +| .. parsed-literal:: | ``map`` of elements |p1...pn|; see | +| | |Variadic Sequence|. | +| map<|p1...pn|> | | +| map\ *n*\ <|p1...pn|> | | ++---------------------------------------+-----------------------------------------------------------+ +| .. parsed-literal:: | Identical to ``map``\ *n*\ ``<``\ |p1...pn|\ ``>``; | +| | see |Variadic Sequence|. | +| map<|p1...pn|>::type | | +| map\ *n*\ <|p1...pn|>::type | | ++---------------------------------------+-----------------------------------------------------------+ +| ``begin::type`` | An iterator pointing to the beginning of ``m``; | +| | see |Associative Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``end::type`` | An iterator pointing to the end of ``m``; | +| | see |Associative Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``size::type`` | The size of ``m``; see |Associative Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``empty::type`` | |true if and only if| ``m`` is empty; see | +| | |Associative Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``front::type`` | The first element in ``m``; see | +| | |Associative Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``has_key::type`` | Queries the presence of elements with the key ``k`` in | +| | ``m``; see |Associative Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``count::type`` | The number of elements with the key ``k`` in ``m``; | +| | see |Associative Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``order::type`` | A unique unsigned |Integral Constant| associated with | +| | the key ``k`` in ``m``; see |Associative Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| .. parsed-literal:: | The element associated with the key ``k`` in | +| | ``m``; see |Associative Sequence|. | +| at::type | | +| at::type | | ++---------------------------------------+-----------------------------------------------------------+ +| ``key_type::type`` | Identical to ``x::first``; see |Associative Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``value_type::type`` | Identical to ``x::second``; see |Associative Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``insert::type`` | A new ``map`` equivalent to ``m`` except that | +| | :: | +| | | +| | at< t, key_type::type >::type | +| | | +| | is identical to ``value_type::type``. | ++---------------------------------------+-----------------------------------------------------------+ +| ``insert::type`` | Equivalent to ``insert::type``; ``pos`` is ignored. | ++---------------------------------------+-----------------------------------------------------------+ +| ``erase_key::type`` | A new ``map`` equivalent to ``m`` except that | +| | ``has_key::value == false``. | ++---------------------------------------+-----------------------------------------------------------+ +| ``erase::type`` | Equivalent to ``erase::type >::type``. | ++---------------------------------------+-----------------------------------------------------------+ +| ``clear::type`` | An empty ``map``; see |clear|. | ++---------------------------------------+-----------------------------------------------------------+ + + +Example +------- + +.. parsed-literal:: + + typedef map< + pair + , pair + , pair,char[17]> + , pair + > m; + + BOOST_MPL_ASSERT_RELATION( size::value, ==, 4 ); + BOOST_MPL_ASSERT_NOT(( empty )); + + BOOST_MPL_ASSERT(( is_same< at::type, unsigned > )); + BOOST_MPL_ASSERT(( is_same< at >::type, char[17] > )); + BOOST_MPL_ASSERT(( is_same< at::type, bool > )); + BOOST_MPL_ASSERT(( is_same< at::type, void\_ > )); + + +See also +-------- + +|Sequences|, |Variadic Sequence|, |Associative Sequence|, |Extensible Associative Sequence|, |set|, |vector| + diff --git a/doc/src/refmanual/max.rst b/doc/src/refmanual/max.rst new file mode 100644 index 0000000..d65692b --- /dev/null +++ b/doc/src/refmanual/max.rst @@ -0,0 +1,101 @@ +.. Metafunctions/Miscellaneous//max |90 + +max +=== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename N1 + , typename N2 + > + struct max + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns the larger of its two arguments. + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Metafunction| + + +Parameters +---------- + ++---------------+-------------------+-------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===================+===========================================+ +| ``N1``, ``N2``| Any type | Types to compare. | ++---------------+-------------------+-------------------------------------------+ + + +Expression semantics +-------------------- + +For arbitrary types ``x`` and ``y``: + + +.. parsed-literal:: + + typedef max::type r; + + +:Return type: + A type. + +:Precondition: + ``less::value`` is a well-formed integral constant expression. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef if_< less,y,x >::type r; + + + +Complexity +---------- + +Constant time. + + +Example +------- + +.. parsed-literal:: + + typedef fold< + vector_c + , int_<10> + , max<_1,_2> + >::type r; + + BOOST_MPL_ASSERT(( is_same< r, int_<10> > )); + + +See also +-------- + +|Metafunctions|, |Comparison|, |min|, |less|, |max_element| diff --git a/doc/src/refmanual/max_element.rst b/doc/src/refmanual/max_element.rst new file mode 100644 index 0000000..7497065 --- /dev/null +++ b/doc/src/refmanual/max_element.rst @@ -0,0 +1,94 @@ +.. Algorithms/Querying Algorithms//max_element |90 + +max_element +=========== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + , typename Pred = less<_1,_2> + > + struct max_element + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns an iterator to the largest element in ``Sequence``. + + +Header +------ + +.. parsed-literal:: + + #include + + +Parameters +---------- + ++---------------+-------------------------------+-----------------------------------+ +| Parameter | Requirement | Description | ++===============+===============================+===================================+ +|``Sequence`` | |Forward Sequence| | A sequence to be searched. | ++---------------+-------------------------------+-----------------------------------+ +| ``Pred`` | Binary |Lambda Expression| | A comparison criteria. | ++---------------+-------------------------------+-----------------------------------+ + + +Expression semantics +-------------------- + + +For any |Forward Sequence| ``s`` and binary |Lambda Expression| ``pred``: + + +.. parsed-literal:: + + typedef max_element::type i; + +:Return type: + |Forward Iterator|. + +:Semantics: + ``i`` is the first iterator in |begin/end| such that for every iterator ``j`` + in |begin/end|, + + .. parsed-literal:: + + apply< pred, deref::type, deref::type >::type::value == false + + +Complexity +---------- + +Linear. Zero comparisons if ``s`` is empty, otherwise exactly ``size::value - 1`` +comparisons. + + +Example +------- + +.. parsed-literal:: + + typedef vector types; + typedef max_element< + transform_view< types,sizeof_<_1> > + >::type iter; + + BOOST_MPL_ASSERT(( is_same< deref::type, char[50]> )); + + +See also +-------- + +|Querying Algorithms|, |min_element|, |find_if|, |upper_bound|, |find| diff --git a/doc/src/refmanual/min.rst b/doc/src/refmanual/min.rst new file mode 100644 index 0000000..38e5559 --- /dev/null +++ b/doc/src/refmanual/min.rst @@ -0,0 +1,101 @@ +.. Metafunctions/Miscellaneous//min |80 + +min +=== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename N1 + , typename N2 + > + struct min + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns the smaller of its two arguments. + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Metafunction| + + +Parameters +---------- + ++---------------+-------------------+-------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===================+===========================================+ +| ``N1``, ``N2``| Any type | Types to compare. | ++---------------+-------------------+-------------------------------------------+ + + +Expression semantics +-------------------- + +For arbitrary types ``x`` and ``y``: + + +.. parsed-literal:: + + typedef min::type r; + + +:Return type: + A type. + +:Precondition: + ``less::value`` is a well-formed integral constant expression. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef if_< less,x,y >::type r; + + + +Complexity +---------- + +Constant time. + + +Example +------- + +.. parsed-literal:: + + typedef fold< + vector_c + , int_<-10> + , min<_1,_2> + >::type r; + + BOOST_MPL_ASSERT(( is_same< r, int_<-10> > )); + + +See also +-------- + +|Metafunctions|, |Comparison|, |max|, |less|, |min_element| diff --git a/doc/src/refmanual/min_element.rst b/doc/src/refmanual/min_element.rst new file mode 100644 index 0000000..38be095 --- /dev/null +++ b/doc/src/refmanual/min_element.rst @@ -0,0 +1,93 @@ +.. Algorithms/Querying Algorithms//min_element |80 + +min_element +=========== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + , typename Pred = less<_1,_2> + > + struct min_element + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns an iterator to the smallest element in ``Sequence``. + + +Header +------ + +.. parsed-literal:: + + #include + + +Parameters +---------- + ++---------------+-------------------------------+-----------------------------------+ +| Parameter | Requirement | Description | ++===============+===============================+===================================+ +|``Sequence`` | |Forward Sequence| | A sequence to be searched. | ++---------------+-------------------------------+-----------------------------------+ +| ``Pred`` | Binary |Lambda Expression| | A comparison criteria. | ++---------------+-------------------------------+-----------------------------------+ + + +Expression semantics +-------------------- + +For any |Forward Sequence| ``s`` and binary |Lambda Expression| ``pred``: + +.. parsed-literal:: + + typedef min_element::type i; + +:Return type: + |Forward Iterator|. + +:Semantics: + ``i`` is the first iterator in |begin/end| such that for every iterator ``j`` + in |begin/end|, + + .. parsed-literal:: + + apply< pred, deref::type, deref::type >::type::value == false + + + +Complexity +---------- + +Linear. Zero comparisons if ``s`` is empty, otherwise exactly ``size::value - 1`` +comparisons. + + +Example +------- + +.. parsed-literal:: + + typedef vector types; + typedef min_element< + transform_view< types,sizeof_<_1> > + >::type iter; + + BOOST_MPL_ASSERT(( is_same< deref::type, bool> )); + + +See also +-------- + +|Querying Algorithms|, |max_element|, |find_if|, |upper_bound|, |find| diff --git a/doc/src/refmanual/minus.rst b/doc/src/refmanual/minus.rst new file mode 100644 index 0000000..7a1a9d3 --- /dev/null +++ b/doc/src/refmanual/minus.rst @@ -0,0 +1,119 @@ +.. Metafunctions/Arithmetic Operations//minus |20 + +minus +===== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename T1 + , typename T2 + , typename T3 = |unspecified| + |...| + , typename T\ *n* = |unspecified| + > + struct minus + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns the difference of its arguments. + + +Header +------ + +.. parsed-literal:: + + #include + #include + + +Model of +-------- + +|Numeric Metafunction| + + +Parameters +---------- + ++---------------+---------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===========================+===============================================+ +| |T1...Tn| | |Integral Constant| | Operation's arguments. | ++---------------+---------------------------+-----------------------------------------------+ + +|Note:| |numeric metafunction note| |-- end note| + + +Expression semantics +-------------------- + +For any |Integral Constant|\ s |c1...cn|: + + +.. parsed-literal:: + + typedef minus::type r; + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef integral_c< + typeof(c1::value - c2::value) + , ( c1::value - c2::value ) + > c; + + typedef minus::type r; + +.. .......................................................................... + +.. parsed-literal:: + + typedef minus r; + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + struct r : minus::type {}; + + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + typedef minus< int_<-10>, int_<3>, long_<1> >::type r; + BOOST_MPL_ASSERT_RELATION( r::value, ==, -14 ); + BOOST_MPL_ASSERT(( is_same< r::value_type, long > )); + + +See also +-------- + +|Arithmetic Operations|, |Numeric Metafunction|, |numeric_cast|, |plus|, |negate|, |times| diff --git a/doc/src/refmanual/modulus.rst b/doc/src/refmanual/modulus.rst new file mode 100644 index 0000000..3662c99 --- /dev/null +++ b/doc/src/refmanual/modulus.rst @@ -0,0 +1,123 @@ +.. Metafunctions/Arithmetic Operations//modulus |50 + +modulus +======= + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename T1 + , typename T2 + > + struct modulus + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns the modulus of its arguments. + + +Header +------ + +.. parsed-literal:: + + #include + #include + + +Model of +-------- + +|Numeric Metafunction| + + +Parameters +---------- + ++---------------+---------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===========================+===============================================+ +| ``T1``, ``T2``| |Integral Constant| | Operation's arguments. | ++---------------+---------------------------+-----------------------------------------------+ + +|Note:| |numeric metafunction note| |-- end note| + + +Expression semantics +-------------------- + +For any |Integral Constant|\ s ``c1`` and ``c2``: + + +.. parsed-literal:: + + typedef modulus::type r; + +:Return type: + |Integral Constant|. + +:Precondition: + ``c2::value != 0`` + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef integral_c< + typeof(c1::value % c2::value) + , ( c1::value % c2::value ) + > r; + + +.. .......................................................................... + +.. parsed-literal:: + + typedef modulus r; + +:Return type: + |Integral Constant|. + +:Precondition: + ``c2::value != 0`` + +:Semantics: + Equivalent to + + .. parsed-literal:: + + struct r : modulus::type {}; + + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + typedef modulus< int_<10>, long_<3> >::type r; + BOOST_MPL_ASSERT_RELATION( r::value, ==, 1 ); + BOOST_MPL_ASSERT(( is_same< r::value_type, long > )); + + + +See also +-------- + +|Metafunctions|, |Numeric Metafunction|, |numeric_cast|, |divides|, |times|, |plus| + diff --git a/doc/src/refmanual/multiplies.rst b/doc/src/refmanual/multiplies.rst new file mode 100644 index 0000000..0521fac --- /dev/null +++ b/doc/src/refmanual/multiplies.rst @@ -0,0 +1,9 @@ +.. Metafunctions/Arithmetic Operations/multiplies |70 + +multiplies +========== + + +``multiplies`` is a synonym for |times|. It is Provided for backward compatibility with +earlier versions of the library. See |times| for the detailed specification. + diff --git a/doc/src/refmanual/negate.rst b/doc/src/refmanual/negate.rst new file mode 100644 index 0000000..c80bd04 --- /dev/null +++ b/doc/src/refmanual/negate.rst @@ -0,0 +1,110 @@ +.. Metafunctions/Arithmetic Operations//negate |60 + +negate +====== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename T + > + struct negate + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns the negative (additive inverse) of its argument. + + +Header +------ + +.. parsed-literal:: + + #include + #include + + +Model of +-------- + +|Numeric Metafunction| + + +Parameters +---------- + ++---------------+---------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===========================+===============================================+ +| ``T`` | |Integral Constant| | Operation's argument. | ++---------------+---------------------------+-----------------------------------------------+ + +|Note:| |numeric metafunction note| |-- end note| + + +Expression semantics +-------------------- + +For any |Integral Constant| ``c``: + +.. parsed-literal:: + + typedef negate::type r; + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef integral_c< c::value_type, ( -c::value ) > r; + +.. .......................................................................... + +.. parsed-literal:: + + typedef negate r; + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + struct r : negate::type {}; + + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + typedef negate< int_<-10> >::type r; + BOOST_MPL_ASSERT_RELATION( r::value, ==, 10 ); + BOOST_MPL_ASSERT(( is_same< r::value_type, int > )); + + +See also +-------- + +|Arithmetic Operations|, |Numeric Metafunction|, |numeric_cast|, |plus|, |minus|, |times| + diff --git a/doc/src/refmanual/next.rst b/doc/src/refmanual/next.rst new file mode 100644 index 0000000..5eaa7de --- /dev/null +++ b/doc/src/refmanual/next.rst @@ -0,0 +1,97 @@ +.. Iterators/Iterator Metafunctions//next |30 + +next +==== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Iterator + > + struct next + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns the next iterator in the sequence. |Note:| ``next`` has a number of +overloaded meanings, depending on the type of its argument. For instance, +if ``X`` is an |Integral Constant|, ``next`` returns an incremented +|Integral Constant| of the same type. The following specification is +iterator-specific. Please refer to the corresponding concept's +documentation for the details of the alternative semantics |-- end note|. + + +Header +------ + +.. parsed-literal:: + + #include + + +Parameters +---------- + ++---------------+---------------------------+-----------------------------------+ +| Parameter | Requirement | Description | ++===============+===========================+===================================+ +| ``Iterator`` | |Forward Iterator|. | An iterator to increment. | ++---------------+---------------------------+-----------------------------------+ + + +Expression semantics +-------------------- + +For any |Forward Iterator|\ s ``iter``: + + +.. parsed-literal:: + + typedef next::type j; + +:Return type: + |Forward Iterator|. + +:Precondition: + ``iter`` is incrementable. + +:Semantics: + ``j`` is an iterator pointing to the next element in the sequence, or + is past-the-end. If ``iter`` is a user-defined iterator, the + library-provided default implementation is equivalent to + + .. parsed-literal:: + + typedef iter::next j; + + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + typedef vector_c v; + typedef begin::type first; + typedef end::type last; + + BOOST_MPL_ASSERT(( is_same< next::type, last > )); + + +See also +-------- + +|Iterators|, |begin| / |end|, |prior|, |deref| diff --git a/doc/src/refmanual/not_.rst b/doc/src/refmanual/not_.rst new file mode 100644 index 0000000..e19aa2e --- /dev/null +++ b/doc/src/refmanual/not_.rst @@ -0,0 +1,95 @@ +.. Metafunctions/Logical Operations//not_ |30 + +not\_ +===== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename F + > + struct not\_ + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns the result of *logical not* (``!``) operation on its argument. + + +Header +------ + +.. parsed-literal:: + + #include + #include + + +Parameters +---------- + ++---------------+---------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===========================+===============================================+ +| ``F`` | Nullary |Metafunction| | Operation's argument. | ++---------------+---------------------------+-----------------------------------------------+ + + +Expression semantics +-------------------- + +For arbitrary nullary |Metafunction| ``f``: + +.. parsed-literal:: + + typedef not_::type r; + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef bool_< (!f::type::value) > r; + +.. .......................................................................... + +.. parsed-literal:: + + typedef not_ r; + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + struct r : not_::type {}; + + +Example +------- + +.. parsed-literal:: + + BOOST_MPL_ASSERT_NOT(( not_< true\_ > )); + BOOST_MPL_ASSERT(( not_< false\_ > )); + + +See also +-------- + +|Metafunctions|, |Logical Operations|, |and_|, |or_| + diff --git a/doc/src/refmanual/not_equal_to.rst b/doc/src/refmanual/not_equal_to.rst new file mode 100644 index 0000000..e536d21 --- /dev/null +++ b/doc/src/refmanual/not_equal_to.rst @@ -0,0 +1,114 @@ +.. Metafunctions/Comparisons//not_equal_to |60 + +not_equal_to +============ + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename T1 + , typename T2 + > + struct not_equal_to + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns a true-valued |Integral Constant| if ``T1`` and ``T2`` are not equal. + + +Header +------ + +.. parsed-literal:: + + #include + #include + + +Model of +-------- + +|Numeric Metafunction| + + +Parameters +---------- + ++---------------+---------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===========================+===============================================+ +| ``T1``, ``T2``| |Integral Constant| | Operation's arguments. | ++---------------+---------------------------+-----------------------------------------------+ + +|Note:| |numeric metafunction note| |-- end note| + + +Expression semantics +-------------------- + + +For any |Integral Constant|\ s ``c1`` and ``c2``: + +.. parsed-literal:: + + typedef not_equal_to::type r; + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef bool_< (c1::value != c2::value) > r; + + +.. .......................................................................... + +.. parsed-literal:: + + typedef not_equal_to r; + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + struct r : not_equal_to::type {}; + + + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + BOOST_MPL_ASSERT(( not_equal_to< int_<0>, int_<10> > )); + BOOST_MPL_ASSERT(( not_equal_to< long_<10>, int_<0> > )); + BOOST_MPL_ASSERT_NOT(( not_equal_to< long_<10>, int_<10> > )); + + +See also +-------- + +|Comparisons|, |Numeric Metafunction|, |numeric_cast|, |equal_to|, |less| + diff --git a/doc/src/refmanual/numeric_cast.rst b/doc/src/refmanual/numeric_cast.rst new file mode 100644 index 0000000..13d76ad --- /dev/null +++ b/doc/src/refmanual/numeric_cast.rst @@ -0,0 +1,128 @@ +.. Metafunctions/Miscellaneous//numeric_cast |50 + +numeric_cast +============ + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename SourceTag + , typename TargetTag + > + struct numeric_cast; + + +Description +----------- + +Each ``numeric_cast`` specialization is a user-specialized unary |Metafunction Class| +providing a conversion between two numeric types. + + +Header +------ + +.. parsed-literal:: + + #include + + +Parameters +---------- + ++---------------+---------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===========================+===============================================+ +| ``SourceTag`` | |Integral Constant| | A tag for the conversion's source type. | ++---------------+---------------------------+-----------------------------------------------+ +| ``TargetTag`` | |Integral Constant| | A tag for the conversion's destination type. | ++---------------+---------------------------+-----------------------------------------------+ + + +Expression semantics +-------------------- + +If ``x`` and ``y`` are two numeric types, ``x`` is convertible to ``y``, and +``x_tag`` and ``y_tag`` are the types' corresponding |Integral Constant| tags: + + +.. parsed-literal:: + + typedef apply_wrap\ ``2``\< numeric_cast,x >::type r; + +:Return type: + A type. + +:Semantics: + ``r`` is a value of ``x`` converted to the type of ``y``. + + +Complexity +---------- + +Unspecified. + + +Example +------- + +.. parsed-literal:: + + struct complex_tag : int_<10> {}; + + template< typename Re, typename Im > struct complex + { + typedef complex_tag tag; + typedef complex type; + typedef Re real; + typedef Im imag; + }; + + template< typename C > struct real : C::real {}; + template< typename C > struct imag : C::imag {}; + + namespace boost { namespace mpl { + + template<> struct numeric_cast< integral_c_tag,complex_tag > + { + template< typename N > struct apply + : complex< N, integral_c< typename N::value_type, 0 > > + { + }; + }; + + template<> + struct plus_impl< complex_tag,complex_tag > + { + template< typename N1, typename N2 > struct apply + : complex< + plus< typename N1::real, typename N2::real > + , plus< typename N1::imag, typename N2::imag > + > + { + }; + }; + + }} + + typedef int_<2> i; + typedef complex< int_<5>, int_<-1> > c1; + typedef complex< int_<-5>, int_<1> > c2; + + typedef plus r4; + BOOST_MPL_ASSERT_RELATION( real::value, ==, 7 ); + BOOST_MPL_ASSERT_RELATION( imag::value, ==, -1 ); + + typedef plus r5; + BOOST_MPL_ASSERT_RELATION( real::value, ==, -3 ); + BOOST_MPL_ASSERT_RELATION( imag::value, ==, 1 ); + + +See also +-------- + +|Metafunctions|, |Numeric Metafunction|, |plus|, |minus|, |times| + diff --git a/doc/src/refmanual/or_.rst b/doc/src/refmanual/or_.rst new file mode 100644 index 0000000..52db961 --- /dev/null +++ b/doc/src/refmanual/or_.rst @@ -0,0 +1,102 @@ +.. Metafunctions/Logical Operations//or_ |20 + +or\_ +==== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename F1 + , typename F2 + |...| + , typename F\ *n* = |unspecified| + > + struct or\_ + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns the result of short-circuit *logical or* (``||``) operation on its arguments. + + +Header +------ + +.. parsed-literal:: + + #include + #include + + +Parameters +---------- + ++---------------+---------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===========================+===============================================+ +| |F1...Fn| | Nullary |Metafunction| | Operation's arguments. | ++---------------+---------------------------+-----------------------------------------------+ + + +Expression semantics +-------------------- + +For arbitrary nullary |Metafunction|\ s |f1...fn|: + +.. parsed-literal:: + + typedef or_::type r; + +:Return type: + |Integral Constant|. + +:Semantics: + ``r`` is ``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; the operands subsequent to the first + ``f``\ *i* metafunction that evaluates to ``true`` are not evaluated. + +.. .......................................................................... + +.. parsed-literal:: + + typedef or_ r; + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + struct r : or_::type {}; + + +Example +------- + +.. parsed-literal:: + + struct unknown; + + BOOST_MPL_ASSERT(( or_< true\_,true\_ > )); + BOOST_MPL_ASSERT(( or_< false\_,true\_ > )); + BOOST_MPL_ASSERT(( or_< true\_,false\_ > )); + BOOST_MPL_ASSERT_NOT(( or_< false\_,false\_ > )); + BOOST_MPL_ASSERT(( or_< true\_,unknown > )); // OK + BOOST_MPL_ASSERT(( or_< true\_,unknown,unknown > )); // OK too + + +See also +-------- + +|Metafunctions|, |Logical Operations|, |and_|, |not_| diff --git a/doc/src/refmanual/order.rst b/doc/src/refmanual/order.rst new file mode 100644 index 0000000..1bb4da6 --- /dev/null +++ b/doc/src/refmanual/order.rst @@ -0,0 +1,94 @@ +.. Sequences/Intrinsic Metafunctions//order + +order +===== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + , typename Key + > + struct order + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns a unique unsigned |Integral Constant| associated with the key ``Key`` in +``Sequence``. + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Tag Dispatched Metafunction| + + +Parameters +---------- + ++---------------+---------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===========================+===============================================+ +| ``Sequence`` | |Associative Sequence| | A sequence to query. | ++---------------+---------------------------+-----------------------------------------------+ +| ``Key`` | Any type | The queried key. | ++---------------+---------------------------+-----------------------------------------------+ + + +Expression semantics +-------------------- + +For any |Associative Sequence| ``s``, and arbitrary type ``key``: + +.. parsed-literal:: + + typedef order::type n; + +:Return type: + Unsigned |Integral Constant|. + +:Semantics: + If ``has_key::value == true``, ``n`` is a unique unsigned + |Integral Constant| associated with ``key`` in ``s``; otherwise, + ``n`` is identical to ``void_``. + + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + typedef map< pair, pair > m; + + BOOST_MPL_ASSERT_NOT(( is_same< order::type, void\_ > )); + BOOST_MPL_ASSERT(( is_same< order::type,void\_ > )); + + + +See also +-------- + +|Associative Sequence|, |has_key|, |count|, |map| diff --git a/doc/src/refmanual/pair.rst b/doc/src/refmanual/pair.rst new file mode 100644 index 0000000..d22b3d8 --- /dev/null +++ b/doc/src/refmanual/pair.rst @@ -0,0 +1,66 @@ +.. Data Types/Miscellaneous//pair |10 + +pair +==== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename T1 + , typename T2 + > + struct pair + { + typedef pair type; + typedef T1 first; + typedef T2 second; + }; + + +Description +----------- + +A transparent holder for two arbitrary types. + + +Header +------ + +.. parsed-literal:: + + #include + + +Example +------- + +Count a number of elements in the sequence together with a number of negative +elements among these. + +.. parsed-literal:: + + typedef fold< + vector_c + , pair< int_<0>, int_<0> > + , pair< + next< first<_1> > + , if_< + less< _2, int_<0> > + , next< second<_1> > + , second<_1> + > + > + >::type p; + + BOOST_MPL_ASSERT_RELATION( p::first::value, ==, 8 ); + BOOST_MPL_ASSERT_RELATION( p::second::value, ==, 3 ); + + +See also +-------- + +|Data Types|, |Sequences|, |first|, |second| + diff --git a/doc/src/refmanual/partition.rst b/doc/src/refmanual/partition.rst new file mode 100644 index 0000000..ee53648 --- /dev/null +++ b/doc/src/refmanual/partition.rst @@ -0,0 +1,113 @@ +.. Algorithms/Transformation Algorithms//partition |85 + +partition +========= + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Seq + , typename Pred + , typename In1 = |unspecified| + , typename In2 = |unspecified| + > + struct partition + { + typedef |unspecified| type; + }; + + +Description +----------- + +Returns a pair of sequences together containing all elements in the range +|begin/end| split into two groups based on the predicate ``Pred``. +``partition`` is a synonym for |stable_partition|. + +|transformation algorithm disclaimer| + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Reversible Algorithm| + + +Parameters +---------- + ++-------------------+-----------------------------------+-------------------------------+ +| Parameter | Requirement | Description | ++===================+===================================+===============================+ +| ``Seq`` | |Forward Sequence| | An original sequence. | ++-------------------+-----------------------------------+-------------------------------+ +| ``Pred`` | Unary |Lambda Expression| | A partitioning predicate. | ++-------------------+-----------------------------------+-------------------------------+ +| ``In1``, ``In2`` | |Inserter| | Output inserters. | ++-------------------+-----------------------------------+-------------------------------+ + + +Expression semantics +-------------------- + +|Semantics disclaimer...| |Reversible Algorithm|. + +For any |Forward Sequence| ``s``, an unary |Lambda Expression| ``pred``, and |Inserter|\ s +``in1`` and ``in2``: + + +.. parsed-literal:: + + typedef partition::type r; + +:Return type: + A |pair|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef stable_partition::type r; + + +Complexity +---------- + +Linear. Exactly ``size::value`` applications of ``pred``, and ``size::value`` +of summarized ``in1::operation`` / ``in2::operation`` applications. + + +Example +------- + +.. parsed-literal:: + + template< typename N > struct is_odd : bool_<(N::value % 2)> {}; + + typedef partition< + range_c + , is_odd<_1> + , back_inserter< vector<> > + , back_inserter< vector<> > + >::type r; + + BOOST_MPL_ASSERT(( equal< r::first, vector_c > )); + BOOST_MPL_ASSERT(( equal< r::second, vector_c > )); + + +See also +-------- + +|Transformation Algorithms|, |Reversible Algorithm|, |reverse_partition|, |stable_partition|, |sort| diff --git a/doc/src/refmanual/plus.rst b/doc/src/refmanual/plus.rst new file mode 100644 index 0000000..a58e71b --- /dev/null +++ b/doc/src/refmanual/plus.rst @@ -0,0 +1,122 @@ +.. Metafunctions/Arithmetic Operations//plus |10 + +plus +==== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename T1 + , typename T2 + , typename T3 = |unspecified| + |...| + , typename T\ *n* = |unspecified| + > + struct plus + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns the sum of its arguments. + + +Header +------ + +.. parsed-literal:: + + #include + #include + + +Model of +-------- + +|Numeric Metafunction| + + + +Parameters +---------- + ++---------------+---------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===========================+===============================================+ +| |T1...Tn| | |Integral Constant| | Operation's arguments. | ++---------------+---------------------------+-----------------------------------------------+ + +|Note:| |numeric metafunction note| |-- end note| + + +Expression semantics +-------------------- + +For any |Integral Constant|\ s |c1...cn|: + + +.. parsed-literal:: + + typedef plus::type r; + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef integral_c< + typeof(c1::value + c2::value) + , ( c1::value + c2::value ) + > c; + + typedef plus::type r; + +.. .......................................................................... + +.. parsed-literal:: + + typedef plus r; + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + struct r : plus::type {}; + + + + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + typedef plus< int_<-10>, int_<3>, long_<1> >::type r; + BOOST_MPL_ASSERT_RELATION( r::value, ==, -6 ); + BOOST_MPL_ASSERT(( is_same< r::value_type, long > )); + + +See also +-------- + +|Arithmetic Operations|, |Numeric Metafunction|, |numeric_cast|, |minus|, |negate|, |times| diff --git a/doc/src/refmanual/pop_back.rst b/doc/src/refmanual/pop_back.rst new file mode 100644 index 0000000..0e5253c --- /dev/null +++ b/doc/src/refmanual/pop_back.rst @@ -0,0 +1,104 @@ +.. Sequences/Intrinsic Metafunctions//pop_back + +pop_back +======== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + > + struct pop_back + { + typedef |unspecified| type; + }; + + +Description +----------- + +``pop_back`` performs a removal at the end of the sequence with guaranteed |O(1)| +complexity. + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Tag Dispatched Metafunction| + + +Parameters +---------- + ++---------------+-------------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===============================+===============================================+ +| ``Sequence`` | |Back Extensible Sequence| | A sequence to erase the last element from. | ++---------------+-------------------------------+-----------------------------------------------+ + + +Expression semantics +-------------------- + +For any |Back Extensible Sequence| ``s``: + +.. parsed-literal:: + + typedef pop_back::type r; + +:Return type: + |Back Extensible Sequence|. + +:Precondition: + ``empty::value == false``. + +:Semantics: + Equivalent to ``erase::type>::type;``. + +:Postcondition: + ``size::value == size::value - 1``. + + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + typedef vector::type types1; + typedef vector::type types2; + typedef vector::type types3; + + typedef pop_back::type result1; + typedef pop_back::type result2; + typedef pop_back::type result3; + + BOOST_MPL_ASSERT_RELATION( size::value, ==, 0 ); + BOOST_MPL_ASSERT_RELATION( size::value, ==, 1 ); + BOOST_MPL_ASSERT_RELATION( size::value, ==, 2 ); + + BOOST_MPL_ASSERT(( is_same< back::type, long> )); + BOOST_MPL_ASSERT(( is_same< back::type, int > )); + + +See also +-------- + +|Back Extensible Sequence|, |erase|, |push_back|, |back|, |pop_front| + diff --git a/doc/src/refmanual/pop_front.rst b/doc/src/refmanual/pop_front.rst new file mode 100644 index 0000000..a7d294c --- /dev/null +++ b/doc/src/refmanual/pop_front.rst @@ -0,0 +1,106 @@ +.. Sequences/Intrinsic Metafunctions//pop_front + +pop_front +========= + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + > + struct pop_front + { + typedef |unspecified| type; + }; + + + +Description +----------- + +``pop_front`` performs a removal at the beginning of the sequence with guaranteed |O(1)| +complexity. + + +Header +------ + +.. parsed-literal:: + + #include + + + +Model of +-------- + +|Tag Dispatched Metafunction| + + +Parameters +---------- + ++---------------+-----------------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===================================+===============================================+ +| ``Sequence`` | |Front Extensible Sequence| | A sequence to erase the first element from. | ++---------------+-----------------------------------+-----------------------------------------------+ + + +Expression semantics +-------------------- + +For any |Front Extensible Sequence| ``s``: + +.. parsed-literal:: + + typedef pop_front::type r; + +:Return type: + |Front Extensible Sequence|. + +:Precondition: + ``empty::value == false``. + +:Semantics: + Equivalent to ``erase::type>::type;``. + +:Postcondition: + ``size::value == size::value - 1``. + + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + typedef vector::type types1; + typedef vector::type types2; + typedef vector::type types3; + + typedef pop_front::type result1; + typedef pop_front::type result2; + typedef pop_front::type result3; + + BOOST_MPL_ASSERT_RELATION( size::value, ==, 0 ); + BOOST_MPL_ASSERT_RELATION( size::value, ==, 1 ); + BOOST_MPL_ASSERT_RELATION( size::value, ==, 2 ); + + BOOST_MPL_ASSERT(( is_same< front::type, long > )); + BOOST_MPL_ASSERT(( is_same< front::type, int > )); + + +See also +-------- + +|Front Extensible Sequence|, |erase|, |push_front|, |front|, |pop_back| + diff --git a/doc/src/refmanual/preface.rst b/doc/src/refmanual/preface.rst new file mode 100644 index 0000000..b3b23b0 --- /dev/null +++ b/doc/src/refmanual/preface.rst @@ -0,0 +1,14 @@ + +* use of "returns" +* [Metafunction Class] form ('f<>') +* nested 'algo' namespace??? it becomes a problem as soon as users would + want to specialize 'advance'/'distance' + +* 'outer' scope construct for lambda +* 'scope/fun/func' +* iterators not requiring nested members; what about '::type', though? +* We don't dispatch _every_ metafunction through the tag mechanism, + only algorithms. I am ambivalent whether we should, and if so, + how it should be done. + +* 'drop_front'? \ No newline at end of file diff --git a/doc/src/refmanual/prior.rst b/doc/src/refmanual/prior.rst new file mode 100644 index 0000000..27efb97 --- /dev/null +++ b/doc/src/refmanual/prior.rst @@ -0,0 +1,97 @@ +.. Iterators/Iterator Metafunctions//prior |40 + +prior +===== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Iterator + > + struct prior + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns the previous iterator in the sequence. |Note:| ``prior`` has a number of +overloaded meanings, depending on the type of its argument. For instance, +if ``X`` is an |Integral Constant|, ``prior`` returns an decremented +|Integral Constant| of the same type. The following specification is +iterator-specific. Please refer to the corresponding concept's +documentation for the details of the alternative semantics |-- end note|. + + +Header +------ + +.. parsed-literal:: + + #include + + +Parameters +---------- + ++---------------+---------------------------+-----------------------------------+ +| Parameter | Requirement | Description | ++===============+===========================+===================================+ +| ``Iterator`` | |Forward Iterator|. | An iterator to decrement. | ++---------------+---------------------------+-----------------------------------+ + + +Expression semantics +-------------------- + +For any |Forward Iterator|\ s ``iter``: + + +.. parsed-literal:: + + typedef prior::type j; + +:Return type: + |Forward Iterator|. + +:Precondition: + ``iter`` is decrementable. + +:Semantics: + ``j`` is an iterator pointing to the previous element in the sequence. + If ``iter`` is a user-defined iterator, the library-provided default + implementation is equivalent to + + .. parsed-literal:: + + typedef iter::prior j; + + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + typedef vector_c v; + typedef begin::type first; + typedef end::type last; + + BOOST_MPL_ASSERT(( is_same< prior::type, first > )); + + +See also +-------- + +|Iterators|, |begin| / |end|, |next|, |deref| diff --git a/doc/src/refmanual/protect.rst b/doc/src/refmanual/protect.rst new file mode 100644 index 0000000..3a28ff5 --- /dev/null +++ b/doc/src/refmanual/protect.rst @@ -0,0 +1,108 @@ +.. Metafunctions/Composition and Argument Binding//protect |60 + +protect +======= + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename F + > + struct protect + { + // |unspecified| + // |...| + }; + + + +Description +----------- + +``protect`` is an identity wrapper for a |Metafunction Class| that prevents +its argument from being recognized as a |bind expression|. + + +Header +------ + +.. parsed-literal:: + + #include + + +Parameters +---------- + ++---------------+---------------------------+---------------------------------------+ +| Parameter | Requirement | Description | ++===============+===========================+=======================================+ +| ``F`` | |Metafunction Class| | A metafunction class to wrap. | ++---------------+---------------------------+---------------------------------------+ + + +Expression semantics +-------------------- + +For any |Metafunction Class| ``f``: + + +.. parsed-literal:: + + typedef protect g; + +:Return type: + |Metafunction Class|. + +:Semantics: + If ``f`` is a |bind expression|, equivalent to + + .. parsed-literal:: + + struct g + { + template< + typename U1 = |unspecified|\,\ |...| typename U\ *n* = |unspecified| + > + struct apply + : apply_wrap\ *n*\ + { + }; + }; + + otherwise equivalent to ``typedef f g;``. + + +Example +------- + +.. parsed-literal:: + + FIXME + + struct f + { + template< typename T1, typename T2 > struct apply + { + // |...| + }; + }; + + typedef bind<_1, protect< bind > > + + typedef apply_wrap0< f0 >::type r1; + typedef apply_wrap0< g0 >::type r2; + typedef apply_wrap2< f2,int,char >::type r3; + + BOOST_MPL_ASSERT(( is_same )); + BOOST_MPL_ASSERT(( is_same )); + BOOST_MPL_ASSERT(( is_same )); + + +See also +-------- + +|Composition and Argument Binding|, |Invocation|, |bind|, |quote|, |apply_wrap| diff --git a/doc/src/refmanual/push_back.rst b/doc/src/refmanual/push_back.rst new file mode 100644 index 0000000..1d5af39 --- /dev/null +++ b/doc/src/refmanual/push_back.rst @@ -0,0 +1,110 @@ +.. Sequences/Intrinsic Metafunctions//push_back + +push_back +========= + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + , typename T + > + struct push_back + { + typedef |unspecified| type; + }; + + + +Description +----------- + +``push_back`` performs an insertion at the end of the sequence with guaranteed |O(1)| +complexity. + +Header +------ + +.. parsed-literal:: + + #include + + + +Model of +-------- + +|Tag Dispatched Metafunction| + + +Parameters +---------- + ++---------------+-------------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===============================+===============================================+ +| ``Sequence`` | |Back Extensible Sequence| | A sequence to insert into. | ++---------------+-------------------------------+-----------------------------------------------+ +| ``T`` | Any type | The element to be inserted. | ++---------------+-------------------------------+-----------------------------------------------+ + + +Expression semantics +-------------------- + +For any |Back Extensible Sequence| ``s`` and arbitrary type ``x``: + + +.. parsed-literal:: + + typedef push_back::type r; + +:Return type: + |Back Extensible Sequence|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef insert< s,end::type,x >::type r; + + +:Postcondition: + ``back::type`` is identical to ``x``; + + .. parsed-literal:: + + size::value == size::value + 1 + + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + typedef vector_c bools; + + typedef push_back::type message; + + BOOST_MPL_ASSERT_RELATION( back::type::value, ==, false ); + BOOST_MPL_ASSERT_RELATION( + ( count_if >::value ), ==, 6 + ); + + +See also +-------- + +|Back Extensible Sequence|, |insert|, |pop_back|, |back|, |push_front| + diff --git a/doc/src/refmanual/push_front.rst b/doc/src/refmanual/push_front.rst new file mode 100644 index 0000000..aa55130 --- /dev/null +++ b/doc/src/refmanual/push_front.rst @@ -0,0 +1,110 @@ +.. Sequences/Intrinsic Metafunctions//push_front + +push_front +========== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + , typename T + > + struct push_front + { + typedef |unspecified| type; + }; + + + +Description +----------- + +``push_front`` performs an insertion at the beginning of the sequence with guaranteed |O(1)| +complexity. + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Tag Dispatched Metafunction| + + +Parameters +---------- + ++---------------+-------------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===============================+===============================================+ +| ``Sequence`` | |Front Extensible Sequence| | A sequence to insert into. | ++---------------+-------------------------------+-----------------------------------------------+ +| ``T`` | Any type | The element to be inserted. | ++---------------+-------------------------------+-----------------------------------------------+ + + + +Expression semantics +-------------------- + + +For any |Front Extensible Sequence| ``s`` and arbitrary type ``x``: + + +.. parsed-literal:: + + typedef push_front::type r; + +:Return type: + |Front Extensible Sequence|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef insert< s,begin::type,x >::type r; + + +:Postcondition: + ``size::value == size::value + 1``; + ``front::type`` is identical to ``x``. + + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + typedef vector_c v; + BOOST_MPL_ASSERT_RELATION( size::value, ==, 7 ); + + typedef push_front< v,integral_c >::type fibonacci; + BOOST_MPL_ASSERT_RELATION( size::value, ==, 8 ); + + BOOST_MPL_ASSERT(( equal< + fibonacci + , vector_c + , equal_to<_,_> + > )); + + +See also +-------- + +|Front Extensible Sequence|, |insert|, |pop_front|, |front|, |push_back| diff --git a/doc/src/refmanual/quote.rst b/doc/src/refmanual/quote.rst new file mode 100644 index 0000000..a62af77 --- /dev/null +++ b/doc/src/refmanual/quote.rst @@ -0,0 +1,137 @@ +.. Metafunctions/Composition and Argument Binding//quote |40 + +quote +===== + +Synopsis +-------- + +.. parsed-literal:: + + template< + template< typename P1 > class F + , typename Tag = |unspecified| + > + struct quote1 + { + // |unspecified| + // |...| + }; + + |...| + + template< + template< typename P1,\ |...| typename P\ *n* > class F + , typename Tag = |unspecified| + > + struct quote\ *n* + { + // |unspecified| + // |...| + }; + + +Description +----------- + +``quoten`` is a higher-order primitive that wraps an *n*-ary |Metafunction| to create +a corresponding |Metafunction Class|. + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Metafunction Class| + + +Parameters +---------- + ++---------------+-----------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+=======================+===============================================+ +| ``F`` | |Metafunction| | A metafunction to wrap. | ++---------------+-----------------------+-----------------------------------------------+ +| ``Tag`` | Any type | A tag determining wrap semantics. | ++---------------+-----------------------+-----------------------------------------------+ + + +Expression semantics +-------------------- + +For any *n*-ary |Metafunction| ``f`` and arbitrary type ``tag``: + + +.. parsed-literal:: + + typedef quote\ *n*\ g; + typedef quote\ *n*\ g; + +:Return type: + |Metafunction Class| + +:Semantics: + Equivalent to + + .. parsed-literal:: + + struct g + { + template< typename A1,\ |...| typename A\ *n* > struct apply + : f + { + }; + }; + + if ``f`` has a nested type member ``::type``, and to + + .. parsed-literal:: + + struct g + { + template< typename A1,\ |...| typename A\ *n* > struct apply + { + typedef f type; + }; + }; + + otherwise. + + +Example +------- + +.. parsed-literal:: + + template< typename T > struct f1 + { + typedef T type; + }; + + template< + typename T1, typename T2, typename T3, typename T4, typename T5 + > + struct f5 + { + // no 'type' member! + }; + + typedef quote\ ``1``\::apply::type t1; + typedef quote\ ``5``\::apply::type t5; + + BOOST_MPL_ASSERT(( is_same< t1, int > )); + BOOST_MPL_ASSERT(( is_same< t5, f5 > )); + + +See also +-------- + +|Composition and Argument Binding|, |Invocation|, |bind|, |lambda|, |protect|, |apply| diff --git a/doc/src/refmanual/range_c.rst b/doc/src/refmanual/range_c.rst new file mode 100644 index 0000000..6636bf4 --- /dev/null +++ b/doc/src/refmanual/range_c.rst @@ -0,0 +1,117 @@ +.. Sequences/Classes//range_c |60 + +range_c +======= + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename T + , T Start + , T Finish + > + struct range_c + { + typedef integral_c start; + typedef integral_c finish; + // |unspecified| + // |...| + }; + + +Description +----------- + +``range_c`` is a sorted |Random Access Sequence| of |Integral Constant|\ s. Note +that because it is not an |Extensible Sequence|, sequence-building +intrinsic metafunctions such as ``push_front`` and transformation algorithms +such as ``replace`` are not directly applicable |--| to be able to use +them, you'd first need to copy the content of the range into a more suitable +sequence. + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Random Access Sequence| + + +Expression semantics +-------------------- + +In the following table, ``r`` is an instance of ``range_c``, ``n`` is an |Integral Constant|, +``T`` is an arbitrary integral type, and ``n`` and ``m`` are integral constant values of type ``T``. + ++-------------------------------+-----------------------------------------------------------+ +| Expression | Semantics | ++===============================+===========================================================+ +| .. parsed-literal:: | A sorted |Random Access Sequence| of integral constant | +| | wrappers for the half-open range of values [\ ``n``, | +| ``range_c`` | ``m``): ``integral_c``, ``integral_c``,... | +| ``range_c::type`` | ``integral_c``. | +| | | ++-------------------------------+-----------------------------------------------------------+ +| ``begin::type`` | An iterator pointing to the beginning of ``r``; | +| | see |Random Access Sequence|. | ++-------------------------------+-----------------------------------------------------------+ +| ``end::type`` | An iterator pointing to the end of ``r``; | +| | see |Random Access Sequence|. | ++-------------------------------+-----------------------------------------------------------+ +| ``size::type`` | The size of ``r``; see |Random Access Sequence|. | ++-------------------------------+-----------------------------------------------------------+ +| ``empty::type`` | |true if and only if| ``r`` is empty; see | +| | |Random Access Sequence|. | ++-------------------------------+-----------------------------------------------------------+ +| ``front::type`` | The first element in ``r``; see | +| | |Random Access Sequence|. | ++-------------------------------+-----------------------------------------------------------+ +| ``back::type`` | The last element in ``r``; see | +| | |Random Access Sequence|. | ++-------------------------------+-----------------------------------------------------------+ +| ``at::type`` | The ``n``\ th element from the beginning of ``r``; see | +| | |Random Access Sequence|. | ++-------------------------------+-----------------------------------------------------------+ + + +Example +------- + +.. parsed-literal:: + + typedef range_c range0; + typedef range_c range1; + typedef range_c range10; + + BOOST_MPL_ASSERT_RELATION( size::value, ==, 0 ); + BOOST_MPL_ASSERT_RELATION( size::value, ==, 1 ); + BOOST_MPL_ASSERT_RELATION( size::value, ==, 10 ); + + BOOST_MPL_ASSERT(( empty )); + BOOST_MPL_ASSERT_NOT(( empty )); + BOOST_MPL_ASSERT_NOT(( empty )); + + BOOST_MPL_ASSERT(( is_same< begin::type, end::type > )); + BOOST_MPL_ASSERT_NOT(( is_same< begin::type, end::type > )); + BOOST_MPL_ASSERT_NOT(( is_same< begin::type, end::type > )); + + BOOST_MPL_ASSERT_RELATION( front::type::value, ==, 0 ); + BOOST_MPL_ASSERT_RELATION( back::type::value, ==, 0 ); + BOOST_MPL_ASSERT_RELATION( front::type::value, ==, 0 ); + BOOST_MPL_ASSERT_RELATION( back::type::value, ==, 9 ); + + +See also +-------- + +|Sequences|, |Random Access Sequence|, |vector_c|, |set_c|, |list_c| diff --git a/doc/src/refmanual/refmanual.py b/doc/src/refmanual/refmanual.py new file mode 100644 index 0000000..10bb88f --- /dev/null +++ b/doc/src/refmanual/refmanual.py @@ -0,0 +1,127 @@ +import time +import fnmatch +import os.path +import os +import re +import string + +underlines = ['+', '/'] + +def __section_header(section): + parts = section.split('/') + underline = underlines[len(parts) - 1] * len(parts[-1]) + if len(parts) > 0: + hidden_target = '.. _`label-%s`:' % '-'.join( parts ) + return '\n%s\n%s\n%s\n\n' % (parts[-1], underline, hidden_target ) + else: + return '\n%s\n%s\n\n' % (parts[-1], underline ) + + +def __section_intro(section): + parts = section.split('/') + return '%s.rst' % '-'.join( [x.split(' ')[0] for x in parts] ) + + +def __include_page( output, page ): + output.write( '.. include:: %s\n' % page ) + # output.write( '.. raw:: LaTeX\n\n' ) + # output.write( ' \\newpage\n\n') + + ref = '/'.join( page.split('.')[0].split('-') ) + if ref.upper() == ref: # macros + ref = 'BOOST_MPL_%s' % ref + output.write( + ( '.. |%(ref)s| replace:: |``%(ref)s``|__\n' + + '.. |``%(ref)s``| replace:: :refentry:`%(ref)s`\n' + + '__ `%(ref)s`_\n' ) + % { 'ref': ref } + ) + elif ref.lower() == ref: + output.write( + ( '.. |%(ref)s| replace:: |``%(ref)s``|__\n' + + '.. |``%(ref)s``| replace:: :refentry:`%(ref)s`\n' + + '__ `%(ref)s`_\n' ) + % { 'ref': ref } + ) + else: + if ref.find( '/' ) == -1: + ref = ' '.join( filter( lambda x: len(x) > 0, re.split( '([A-Z][a-z]+)', ref ) ) ) + output.write( '.. |%(ref)s| replace:: `%(ref)s`_\n' % { 'ref': ref } ) + + modtime = time.gmtime( os.stat( page ).st_mtime ) + output.write( '.. modtime: %s\n' % time.strftime( '%B %d, %Y %H:%M:%S +0000', modtime ) ) + output.write( '\n' ) + + +def __write_index( filename, index ): + index_file = open( filename, 'w' ) + index.sort() + for x in index: + index_file.write( '* |%s|\n' % x ) + + index_file.close() + + +def main( filename, dir ): + sources = filter( + lambda x: fnmatch.fnmatch(x,"*.rst") and x != filename + , os.listdir(dir) + ) + + toc = [t.strip() for t in open('%s.toc' % filename).readlines()] + topics = {} + for t in toc: topics[t] = [] + + concept_index = [] + index = [] + + output = open('%s.gen' % filename, 'w') + output.writelines( open( '%s.rst' % filename, 'r' ).readlines() ) + re_topic = re.compile(r'^..\s+(.+?)//(.+?)(\s*\|\s*(\d+))?\s*$') + for src in sources: + placement_spec = open(src, 'r').readline() + + topic = 'Unclassified' + name = None + order = -1 + + match = re_topic.match(placement_spec) + if match: + topic = match.group(1) + name = match.group(2) + if match.group(3): + order = int(match.group(4)) + + if not topics.has_key(topic): + topics[topic] = [] + + topics[topic].append((src, order)) + + if name: + if topic.find( '/Concepts' ) == -1: + index.append( name ) + else: + concept_index.append( name ) + + + for t in toc: + content = topics[t] + content.sort( lambda x,y: x[1] - y[1] ) + + output.write( __section_header(t) ) + + intro = __section_intro(t) + if os.path.exists(intro): + __include_page( output, intro ) + + for src in content: + __include_page( output, src[0] ) + + output.close() + + __write_index( 'concepts.gen', concept_index ) + __write_index( 'index.gen', index ) + + + +main( 'refmanual', os.getcwd() ) diff --git a/doc/src/refmanual/refmanual.rst b/doc/src/refmanual/refmanual.rst new file mode 100644 index 0000000..fa2487e --- /dev/null +++ b/doc/src/refmanual/refmanual.rst @@ -0,0 +1,145 @@ + +The MPL Reference Manual +************************ + +:Copyright: Copyright © Aleksey Gurtovoy and David Abrahams, 2001-2005. + +:License: Distributed under the Boost Software License, Version 1.0. (See + accompanying file ``LICENSE_1_0.txt`` or copy at + `http://www.boost.org/LICENSE_1_0.txt`__) + + +__ http://www.boost.org/LICENSE_1_0.txt + + + +.. no .. section-numbering:: + + +.. raw:: latex + + \setcounter{secnumdepth}{2} + \setcounter{tocdepth}{2} + +.. contents:: Table of Contents + :depth: 3 + +.. |Boost.Bind| replace:: `Boost.Bind`__ +__ http://www.boost.org/libs/bind/bind.html + +.. |Boost.Lambda| replace:: `Boost.Lambda`__ +__ http://www.boost.org/libs/lambda/doc/index.html + +.. role:: refentry(literal) + +.. |t1| replace:: \ *t*\ :sub:`1` +.. |t2| replace:: \ *t*\ :sub:`2` +.. |tn| replace:: \ *t*\ :sub:`n` +.. workaround weird substitution bug (used to work!): +.. |t1...tn| replace:: \ *t*\ :sub:`1`,\ *t*\ :sub:`2`,... |tn| + +.. |p1...pn| replace:: \ *p*\ :sub:`1`,\ *p*\ :sub:`2`,... \ *p*\ :sub:`n` + + +.. |c1| replace:: \ *c*\ :sub:`1` +.. |c2| replace:: \ *c*\ :sub:`2` +.. |cn| replace:: \ *c*\ :sub:`n` +.. workaround weird substitution bug (works with t's!): +.. |c1...cn| replace:: \ *c*\ :sub:`1`,\ *c*\ :sub:`2`,... \ *c*\ :sub:`n` + +.. |x1...xn| replace:: *x*\ :sub:`1`,\ *x*\ :sub:`2`,... \ *x*\ :sub:`n` + +.. |...| replace:: *...* +.. |T1...Tn| replace:: ``T1``, ``T2``,... ``Tn`` + +.. |F1...Fn| replace:: ``F1``, ``F2``,... ``Fn`` +.. |f1...fn| replace:: ``f1``, ``f2``,... ``fn`` + +.. |A1...An| replace:: ``A1``,... ``An`` +.. |a1...an| replace:: ``a1``,... ``an`` + + + +.. |begin/end| replace:: [``begin::type``, ``end::type``) +.. |begin/end| replace:: [``begin::type``, ``end::type``) +.. |begin/end| replace:: [``begin::type``, ``end::type``) +.. |begin/end| replace:: [``begin::type``, ``end::type``) + +.. |begin/end| replace:: [``begin::type``, ``end::type``) +.. |begin/end| replace:: [``begin::type``, ``end::type``) +.. |begin/end| replace:: [``begin::type``, ``end::type``) +.. |begin/end| replace:: [``begin::type``, ``end::type``) + +.. |is_same| replace:: is_same +.. |unspecified| replace:: *unspecified* +.. |unspecified-token-seq| replace:: *unspecified token sequence* + +.. |idic| replace:: *implementation-defined integral constant* + +.. |true if and only if| replace:: A boolean `Integral Constant`_ ``c`` such that + ``c::value == true`` if and only if + + +.. |O(1)| replace:: *O(1)* + +.. |_1| replace:: |``_1``|__ +.. |_2| replace:: |``_2``|__ +.. |_3| replace:: |``_3``|__ +.. |_4| replace:: |``_4``|__ +.. |_5| replace:: |``_5``|__ +.. |``_1``| replace:: :refentry:`_1` +.. |``_2``| replace:: :refentry:`_2` +.. |``_3``| replace:: :refentry:`_3` +.. |``_4``| replace:: :refentry:`_4` +.. |``_5``| replace:: :refentry:`_5` +__ `Placeholders`_ +__ `Placeholders`_ +__ `Placeholders`_ +__ `Placeholders`_ +__ `Placeholders`_ + +.. |placeholder| replace:: `placeholder`__ +__ `Placeholders`_ + +.. |_1,_2,..._n| replace:: |_1|, |_2|, |_3|,\ |...| + + +.. |--| unicode:: U+02014 .. EM DASH + + +.. |Note:| replace:: [*Note:* +.. |-- end note| replace:: |--| *end note*\] + + +.. |Semantics disclaimer...| replace:: The semantics of an expression are defined only + where they differ from, or are not defined in + + +.. |numeric metafunction note| replace:: The requirements listed in this specification + are the ones imposed by the default implementation. See |Numeric Metafunction| concept + for the details on how to provide an implementation for a user-defined numeric type + that does not satisfy the `Integral Constant`_ requirements. + + +.. "[*Note:*" instead of "|Note:|" to workaround another subst. bug + + +.. |preprocessed headers disclaimer| replace:: [*Note:* Overriding will take effect + *only* if the library is configured not to use `preprocessed headers`__. See + |+BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS+|__ for more information. |--| *end note*\] + +.. |+BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS+| replace:: :refentry:`BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS` +__ `BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS`_ +__ `BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS`_ + +.. |BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS| replace:: |``BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS``|__ +.. |``BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS``| replace:: :refentry:`BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS` +__ `BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS`_ + + +.. |transformation algorithm disclaimer| replace:: + [*Note:* This wording applies to a no-inserter version(s) of the algorithm. See the + `Expression semantics` subsection for a precise specification of the algorithm's + details in all cases |--| *end note*\] + +.. |In the following table...| replace:: In the following table and subsequent specifications, diff --git a/doc/src/refmanual/refmanual.toc b/doc/src/refmanual/refmanual.toc new file mode 100644 index 0000000..176408b --- /dev/null +++ b/doc/src/refmanual/refmanual.toc @@ -0,0 +1,37 @@ +Sequences +Sequences/Concepts +Sequences/Classes +Sequences/Views +Sequences/Intrinsic Metafunctions +Iterators +Iterators/Concepts +Iterators/Iterator Metafunctions +Algorithms +Algorithms/Concepts +Algorithms/Inserters +Algorithms/Iteration Algorithms +Algorithms/Querying Algorithms +Algorithms/Transformation Algorithms +Metafunctions +Metafunctions/Concepts +Metafunctions/Type Selection +Metafunctions/Invocation +Metafunctions/Composition and Argument Binding +Metafunctions/Arithmetic Operations +Metafunctions/Comparisons +Metafunctions/Logical Operations +Metafunctions/Bitwise Operations +Metafunctions/Trivial +Metafunctions/Miscellaneous +Data Types +Data Types/Concepts +Data Types/Numeric +Data Types/Miscellaneous +Macros +Macros/Asserts +Macros/Introspection +Macros/Configuration +Macros/Broken Compiler Workarounds +Terminology +Categorized Index +Acknowledgements diff --git a/doc/src/refmanual/remove.rst b/doc/src/refmanual/remove.rst new file mode 100644 index 0000000..22a714b --- /dev/null +++ b/doc/src/refmanual/remove.rst @@ -0,0 +1,106 @@ +.. Algorithms/Transformation Algorithms//remove |60 + +remove +====== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + , typename T + , typename In = |unspecified| + > + struct remove + { + typedef |unspecified| type; + }; + + +Description +----------- + +Returns a new sequence that contains all elements from |begin/end| +range except those that are identical to ``T``. + +.. Returns a copy of the original sequence with all elements identical to ``T`` + removed. + +|transformation algorithm disclaimer| + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Reversible Algorithm| + + +Parameters +---------- + ++---------------+-----------------------------------+-------------------------------+ +| Parameter | Requirement | Description | ++===============+===================================+===============================+ +| ``Sequence`` | |Forward Sequence| | An original sequence. | ++---------------+-----------------------------------+-------------------------------+ +| ``T`` | Any type | A type to be removed. | ++---------------+-----------------------------------+-------------------------------+ +| ``In`` | |Inserter| | An inserter. | ++---------------+-----------------------------------+-------------------------------+ + + +Expression semantics +-------------------- + +|Semantics disclaimer...| |Reversible Algorithm|. + +For any |Forward Sequence| ``s``, an |Inserter| ``in``, and arbitrary type ``x``: + + +.. parsed-literal:: + + typedef remove::type r; + +:Return type: + A type. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef remove_if< s,is_same<_,x>,in >::type r; + + +Complexity +---------- + +Linear. Performs exactly ``size::value`` comparisons for equality, and at +most ``size::value`` insertions. + + +Example +------- + +.. parsed-literal:: + + typedef vector::type types; + typedef remove< types,float >::type result; + + BOOST_MPL_ASSERT(( equal< result, vector > )); + + +See also +-------- + +|Transformation Algorithms|, |Reversible Algorithm|, |reverse_remove|, |remove_if|, |copy|, |replace| diff --git a/doc/src/refmanual/remove_if.rst b/doc/src/refmanual/remove_if.rst new file mode 100644 index 0000000..452b0ef --- /dev/null +++ b/doc/src/refmanual/remove_if.rst @@ -0,0 +1,117 @@ +.. Algorithms/Transformation Algorithms//remove_if |70 + +remove_if +========= + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + , typename Pred + , typename In = |unspecified| + > + struct remove_if + { + typedef |unspecified| type; + }; + + +Description +----------- + +Returns a new sequence that contains all the elements from |begin/end| range +except those that satisfy the predicate ``Pred``. + +.. Returns a copy of the original sequence with all elements satisfying the predicate + ``Pred`` removed. + +|transformation algorithm disclaimer| + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Reversible Algorithm| + + +Parameters +---------- + ++---------------+-----------------------------------+-------------------------------+ +| Parameter | Requirement | Description | ++===============+===================================+===============================+ +| ``Sequence`` | |Forward Sequence| | An original sequence. | ++---------------+-----------------------------------+-------------------------------+ +| ``Pred`` | Unary |Lambda Expression| | A removal condition. | ++---------------+-----------------------------------+-------------------------------+ +| ``In`` | |Inserter| | An inserter. | ++---------------+-----------------------------------+-------------------------------+ + + +Expression semantics +-------------------- + +|Semantics disclaimer...| |Reversible Algorithm|. + +For any |Forward Sequence| ``s``, and an |Inserter| ``in``, and an unary +|Lambda Expression| ``pred``: + + +.. parsed-literal:: + + typedef remove_if::type r; + +:Return type: + A type. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef lambda::type p; + typedef lambda::type op; + + typedef fold< + s + , in::state + , eval_if< + apply_wrap\ ``1``\ + , identity<_1> + , apply_wrap\ ``2``\ + > + >::type r; + + +Complexity +---------- + +Linear. Performs exactly ``size::value`` applications of ``pred``, and at +most ``size::value`` insertions. + + +Example +------- + +.. parsed-literal:: + + typedef vector_c::type numbers; + typedef remove_if< numbers, greater<_,int_<4> > >::type result; + + BOOST_MPL_ASSERT(( equal< result,vector_c,equal_to<_,_> > )); + + +See also +-------- + +|Transformation Algorithms|, |Reversible Algorithm|, |reverse_remove_if|, |remove|, |copy_if|, |replace_if| diff --git a/doc/src/refmanual/replace.rst b/doc/src/refmanual/replace.rst new file mode 100644 index 0000000..f14df35 --- /dev/null +++ b/doc/src/refmanual/replace.rst @@ -0,0 +1,107 @@ +.. Algorithms/Transformation Algorithms//replace |40 + +replace +======= + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + , typename OldType + , typename NewType + , typename In = |unspecified| + > + struct replace + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns a copy of the original sequence where every type identical to ``OldType`` +has been replaced with ``NewType``. + +|transformation algorithm disclaimer| + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Reversible Algorithm| + + +Parameters +---------- + ++---------------+-----------------------------------+-------------------------------+ +| Parameter | Requirement | Description | ++===============+===================================+===============================+ +| ``Sequence`` | |Forward Sequence| | A original sequence. | ++---------------+-----------------------------------+-------------------------------+ +| ``OldType`` | Any type | A type to be replaced. | ++---------------+-----------------------------------+-------------------------------+ +| ``NewType`` | Any type | A type to replace with. | ++---------------+-----------------------------------+-------------------------------+ +| ``In`` | |Inserter| | An inserter. | ++---------------+-----------------------------------+-------------------------------+ + + +Expression semantics +-------------------- + +|Semantics disclaimer...| |Reversible Algorithm|. + +For any |Forward Sequence| ``s``, an |Inserter| ``in``, and arbitrary types ``x`` and ``y``: + + +.. parsed-literal:: + + typedef replace::type r; + +:Return type: + A type. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef replace_if< s,y,is_same<_,x>,in >::type r; + + +Complexity +---------- + +Linear. Performs exactly ``size::value`` comparisons for +identity / insertions. + + +Example +------- + +.. parsed-literal:: + + typedef vector types; + typedef vector expected; + typedef replace< types,float,double >::type result; + + BOOST_MPL_ASSERT(( equal< result,expected > )); + + +See also +-------- + +|Transformation Algorithms|, |Reversible Algorithm|, |reverse_replace|, |replace_if|, |remove|, |transform| diff --git a/doc/src/refmanual/replace_if.rst b/doc/src/refmanual/replace_if.rst new file mode 100644 index 0000000..7b0e6b9 --- /dev/null +++ b/doc/src/refmanual/replace_if.rst @@ -0,0 +1,109 @@ +.. Algorithms/Transformation Algorithms//replace_if |50 + +replace_if +========== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + , typename Pred + , typename In = |unspecified| + > + struct replace_if + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns a copy of the original sequence where every type that satisfies +the predicate ``Pred`` has been replaced with ``NewType``. + +|transformation algorithm disclaimer| + +Header +------ + +.. parsed-literal:: + + #include + + + +Model of +-------- + +|Reversible Algorithm| + + +Parameters +---------- + ++---------------+-----------------------------------+-------------------------------+ +| Parameter | Requirement | Description | ++===============+===================================+===============================+ +| ``Sequence`` | |Forward Sequence| | An original sequence. | ++---------------+-----------------------------------+-------------------------------+ +| ``Pred`` | Unary |Lambda Expression| | A replacement condition. | ++---------------+-----------------------------------+-------------------------------+ +| ``NewType`` | Any type | A type to replace with. | ++---------------+-----------------------------------+-------------------------------+ +| ``In`` | |Inserter| | An inserter. | ++---------------+-----------------------------------+-------------------------------+ + + +Expression semantics +-------------------- + +|Semantics disclaimer...| |Reversible Algorithm|. + +For any |Forward Sequence| ``s``, an unary |Lambda Expression| ``pred``, +an |Inserter| ``in``, and arbitrary type ``x``: + + +.. parsed-literal:: + + typedef replace_if::type r; + +:Return type: + A type. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef lambda::type p; + typedef transform< s, if_< apply_wrap1,x,_1>, in >::type r; + + +Complexity +---------- + +Linear. Performs exactly ``size::value`` applications of ``pred``, and at most +``size::value`` insertions. + + +Example +------- + +.. parsed-literal:: + + typedef vector_c numbers; + typedef vector_c expected; + typedef replace_if< numbers, greater<_,int_<4> >, int_<0> >::type result; + + BOOST_MPL_ASSERT(( equal< result,expected, equal_to<_,_> > )); + + +See also +-------- + +|Transformation Algorithms|, |Reversible Algorithm|, |reverse_replace_if|, |replace|, |remove_if|, |transform| diff --git a/doc/src/refmanual/reverse.rst b/doc/src/refmanual/reverse.rst new file mode 100644 index 0000000..e7ab4d5 --- /dev/null +++ b/doc/src/refmanual/reverse.rst @@ -0,0 +1,90 @@ +.. Algorithms/Transformation Algorithms//reverse |100 + +reverse +======= + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + , typename In = |unspecified| + > + struct reverse + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns a reversed copy of the original sequence. ``reverse`` is a synonym for +|reverse_copy|. + +|transformation algorithm disclaimer| + +Header +------ + +.. parsed-literal:: + + #include + + +Parameters +---------- + ++---------------+-----------------------------------+-------------------------------+ +| Parameter | Requirement | Description | ++===============+===================================+===============================+ +| ``Sequence`` | |Forward Sequence| | A sequence to reverse. | ++---------------+-----------------------------------+-------------------------------+ +| ``In`` | |Inserter| | An inserter. | ++---------------+-----------------------------------+-------------------------------+ + + +Expression semantics +-------------------- + +For any |Forward Sequence| ``s``, and an |Inserter| ``in``: + +.. parsed-literal:: + + typedef reverse::type r; + +:Return type: + A type. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef reverse_copy::type r; + + +Complexity +---------- + +Linear. + + +Example +------- + +.. parsed-literal:: + + typedef vector_c numbers; + typedef reverse< numbers >::type result; + + BOOST_MPL_ASSERT(( equal< result, range_c > )); + + +See also +-------- + +|Transformation Algorithms|, |Reversible Algorithm|, |reverse_copy|, |copy|, |copy_if| diff --git a/doc/src/refmanual/reverse_copy.rst b/doc/src/refmanual/reverse_copy.rst new file mode 100644 index 0000000..78fbdd7 --- /dev/null +++ b/doc/src/refmanual/reverse_copy.rst @@ -0,0 +1,102 @@ +.. Algorithms/Transformation Algorithms//reverse_copy |110 + +reverse_copy +============ + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + , typename In = |unspecified| + > + struct reverse_copy + { + typedef |unspecified| type; + }; + + +Description +----------- + +Returns a reversed copy of the original sequence. + +|transformation algorithm disclaimer| + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Reversible Algorithm| + + +Parameters +---------- + ++---------------+-----------------------------------+-------------------------------+ +| Parameter | Requirement | Description | ++===============+===================================+===============================+ +| ``Sequence`` | |Forward Sequence| | A sequence to copy. | ++---------------+-----------------------------------+-------------------------------+ +| ``In`` | |Inserter| | An inserter. | ++---------------+-----------------------------------+-------------------------------+ + + +Expression semantics +-------------------- + +|Semantics disclaimer...| |Reversible Algorithm|. + +For any |Forward Sequence| ``s``, and an |Inserter| ``in``: + +.. parsed-literal:: + + typedef reverse_copy::type r; + +:Return type: + A type. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef reverse_fold< s,in::state,in::operation >::type r; + + + +Complexity +---------- + +Linear. Exactly ``size::value`` applications of ``in::operation``. + + +Example +------- + +.. parsed-literal:: + + typedef list_c::type numbers; + typedef reverse_copy< + range_c + , front_inserter< numbers > + >::type result; + + BOOST_MPL_ASSERT_RELATION( size::value, ==, 20 ); + BOOST_MPL_ASSERT(( equal< result,range_c > )); + + +See also +-------- + +|Transformation Algorithms|, |Reversible Algorithm|, |copy|, |reverse_copy_if|, |reverse_transform| diff --git a/doc/src/refmanual/reverse_copy_if.rst b/doc/src/refmanual/reverse_copy_if.rst new file mode 100644 index 0000000..3d35282 --- /dev/null +++ b/doc/src/refmanual/reverse_copy_if.rst @@ -0,0 +1,120 @@ +.. Algorithms/Transformation Algorithms//reverse_copy_if |120 + +reverse_copy_if +=============== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + , typename Pred + , typename In = |unspecified| + > + struct reverse_copy_if + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns a reversed, filtered copy of the original sequence containing the +elements that satisfy the predicate ``Pred``. + +|transformation algorithm disclaimer| + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Reversible Algorithm| + + +Parameters +---------- + ++---------------+-----------------------------------+-------------------------------+ +| Parameter | Requirement | Description | ++===============+===================================+===============================+ +| ``Sequence`` | |Forward Sequence| | A sequence to copy. | ++---------------+-----------------------------------+-------------------------------+ +| ``Pred`` | Unary |Lambda Expression| | A copying condition. | ++---------------+-----------------------------------+-------------------------------+ +| ``In`` | |Inserter| | An inserter. | ++---------------+-----------------------------------+-------------------------------+ + + +Expression semantics +-------------------- + +|Semantics disclaimer...| |Reversible Algorithm|. + +For any |Forward Sequence| ``s``, an unary |Lambda Expression| ``pred``, and +an |Inserter| ``in``: + + +.. parsed-literal:: + + typedef reverse_copy_if::type r; + + +:Return type: + A type + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef lambda::type p; + typedef lambda::type op; + + typedef reverse_fold< + s + , in::state + , eval_if< + apply_wrap\ ``1``\ + , apply_wrap\ ``2``\ + , identity<_1> + > + >::type r; + + +Complexity +---------- + +Linear. Exactly ``size::value`` applications of ``pred``, and at +most ``size::value`` applications of ``in::operation``. + + +Example +------- + +.. parsed-literal:: + + typedef reverse_copy_if< + range_c + , less< _1, int_<5> > + , front_inserter< vector<> > + >::type result; + + BOOST_MPL_ASSERT_RELATION( size::value, ==, 5 ); + BOOST_MPL_ASSERT(( equal > )); + + +See also +-------- + +|Transformation Algorithms|, |Reversible Algorithm|, |copy_if|, |reverse_copy|, |remove_if|, |replace_if| diff --git a/doc/src/refmanual/reverse_fold.rst b/doc/src/refmanual/reverse_fold.rst new file mode 100644 index 0000000..b2c3867 --- /dev/null +++ b/doc/src/refmanual/reverse_fold.rst @@ -0,0 +1,144 @@ +.. Algorithms/Iteration Algorithms//reverse_fold + +reverse_fold +============ + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + , typename State + , typename BackwardOp + , typename ForwardOp = _1 + > + struct reverse_fold + { + typedef |unspecified| type; + }; + + + +Description +----------- + +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::type``, ``end::type``) in +reverse order. If ``ForwardOp`` is provided, then it is applied on forward +traversal to form the result that is passed to the first ``BackwardOp`` call. + + +Header +------ + +.. parsed-literal:: + + #include + + + +Parameters +---------- + +Parameters +---------- + ++---------------+-------------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===============================+===============================================+ +| ``Sequence`` | |Forward Sequence| | A sequence to iterate. | ++---------------+-------------------------------+-----------------------------------------------+ +| ``State`` | Any type | The initial state for the first ``BackwardOp``| +| | | / ``ForwardOp`` application. | ++---------------+-------------------------------+-----------------------------------------------+ +| ``BackwardOp``| Binary |Lambda Expression| | The operation to be executed on backward | +| | | traversal. | ++---------------+-------------------------------+-----------------------------------------------+ +| ``ForwardOp`` | Binary |Lambda Expression| | The operation to be executed on forward | +| | | traversal. | ++---------------+-------------------------------+-----------------------------------------------+ + + +Expression semantics +-------------------- + +For any |Forward Sequence| ``s``, binary |Lambda Expression| ``backward_op`` and ``forward_op``, +and arbitrary type ``state``: + +.. parsed-literal:: + + typedef reverse_fold< s,state,backward_op >::type t; + +:Return type: + A type + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef reverse_iter_fold< + s + , state + , apply > + >::type t; + + +.. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + +.. parsed-literal:: + + typedef reverse_fold< s,state,backward_op,forward_op >::type t; + + +:Return type: + A type. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef reverse_fold< + Sequence + , fold::type + , backward_op + >::type t; + + +Complexity +---------- + +Linear. Exactly ``size::value`` applications of ``backward_op`` and ``forward_op``. + + +Example +------- + +Remove negative elements from a sequence [#reverse_fold_note]_. + +.. parsed-literal:: + + typedef list_c numbers; + typedef list_c negatives; + typedef reverse_fold< + numbers + , list_c + , if_< less< _2,int_<0> >, push_front<_1,_2,>, _1 > + >::type result; + + BOOST_MPL_ASSERT(( equal< negatives,result > )); + + +.. [#reverse_fold_note] See ``remove_if`` for a more compact way to do this. + + +See also +-------- + +|Algorithms|, |fold|, |reverse_iter_fold|, |iter_fold| + diff --git a/doc/src/refmanual/reverse_iter_fold.rst b/doc/src/refmanual/reverse_iter_fold.rst new file mode 100644 index 0000000..5b467cd --- /dev/null +++ b/doc/src/refmanual/reverse_iter_fold.rst @@ -0,0 +1,147 @@ +.. Algorithms/Iteration Algorithms//reverse_iter_fold + +reverse_iter_fold +================= + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + , typename State + , typename BackwardOp + , typename ForwardOp = _1 + > + struct reverse_iter_fold + { + typedef |unspecified| type; + }; + + + +Description +----------- + +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::type``, ``end::type``) +in 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. + + +Header +------ + +.. parsed-literal:: + + #include + + + +Parameters +---------- + ++---------------+-------------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===============================+===============================================+ +| ``Sequence`` | |Forward Sequence| | A sequence to iterate. | ++---------------+-------------------------------+-----------------------------------------------+ +| ``State`` | Any type | The initial state for the first ``BackwardOp``| +| | | / ``ForwardOp`` application. | ++---------------+-------------------------------+-----------------------------------------------+ +| ``BackwardOp``| Binary |Lambda Expression| | The operation to be executed on backward | +| | | traversal. | ++---------------+-------------------------------+-----------------------------------------------+ +| ``ForwardOp`` | Binary |Lambda Expression| | The operation to be executed on forward | +| | | traversal. | ++---------------+-------------------------------+-----------------------------------------------+ + + +Expression semantics +-------------------- + +For any |Forward Sequence| ``s``, binary |Lambda Expression| ``backward_op`` and ``forward_op``, +and arbitrary type ``state``: + + +.. parsed-literal:: + + typedef reverse_iter_fold< s,state,backward_op >::type t; + +:Return type: + A type. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef begin::type i\ :sub:`1`; + typedef next::type i\ :sub:`2`; + |...| + typedef next::type last; + typedef apply::type state\ :sub:`n`; + typedef apply::type state\ :sub:`n-1`; + |...| + typedef apply::type state\ :sub:`1`; + typedef state\ :sub:`1` t; + + where ``n == size::value`` and ``last`` is identical to ``end::type``; equivalent + to ``typedef state t;`` if ``empty::value == true``. + + +.. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + +.. parsed-literal:: + + typedef reverse_iter_fold< s,state,backward_op,forward_op >::type t; + +:Return type: + A type. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef reverse_iter_fold< + Sequence + , iter_fold::type + , backward_op + >::type t; + + +Complexity +---------- + +Linear. Exactly ``size::value`` applications of ``backward_op`` and ``forward_op``. + + +Example +------- + +Build a list of iterators to the negative elements in a sequence. + +.. parsed-literal:: + + typedef vector_c numbers; + typedef list_c negatives; + typedef reverse_iter_fold< + numbers + , list<> + , if_< less< deref<_2>,int_<0> >, push_front<_1,_2>, _1 > + >::type iters; + + BOOST_MPL_ASSERT(( equal< + negatives + , transform_view< iters,deref<_1> > + > )); + + +See also +-------- + +|Algorithms|, |iter_fold|, |reverse_fold|, |fold| diff --git a/doc/src/refmanual/reverse_partition.rst b/doc/src/refmanual/reverse_partition.rst new file mode 100644 index 0000000..913432e --- /dev/null +++ b/doc/src/refmanual/reverse_partition.rst @@ -0,0 +1,113 @@ +.. Algorithms/Transformation Algorithms//reverse_partition |185 + +reverse_partition +================= + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Seq + , typename Pred + , typename In1 = |unspecified| + , typename In2 = |unspecified| + > + struct reverse_partition + { + typedef |unspecified| type; + }; + + +Description +----------- + +Returns a pair of sequences together containing all elements in the range +|begin/end| split into two groups based on the predicate ``Pred``. +``reverse_partition`` is a synonym for |reverse_stable_partition|. + +|transformation algorithm disclaimer| + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Reversible Algorithm| + + +Parameters +---------- + ++-------------------+-----------------------------------+-------------------------------+ +| Parameter | Requirement | Description | ++===================+===================================+===============================+ +| ``Seq`` | |Forward Sequence| | An original sequence. | ++-------------------+-----------------------------------+-------------------------------+ +| ``Pred`` | Unary |Lambda Expression| | A partitioning predicate. | ++-------------------+-----------------------------------+-------------------------------+ +| ``In1``, ``In2`` | |Inserter| | Output inserters. | ++-------------------+-----------------------------------+-------------------------------+ + + +Expression semantics +-------------------- + +|Semantics disclaimer...| |Reversible Algorithm|. + +For any |Forward Sequence| ``s``, an unary |Lambda Expression| ``pred``, and |Inserter|\ s +``in1`` and ``in2``: + + +.. parsed-literal:: + + typedef reverse_partition::type r; + +:Return type: + A |pair|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef reverse_stable_partition::type r; + + +Complexity +---------- + +Linear. Exactly ``size::value`` applications of ``pred``, and ``size::value`` +of summarized ``in1::operation`` / ``in2::operation`` applications. + + +Example +------- + +.. parsed-literal:: + + template< typename N > struct is_odd : bool_<(N::value % 2)> {}; + + typedef partition< + range_c + , is_odd<_1> + , back_inserter< vector<> > + , back_inserter< vector<> > + >::type r; + + BOOST_MPL_ASSERT(( equal< r::first, vector_c > )); + BOOST_MPL_ASSERT(( equal< r::second, vector_c > )); + + +See also +-------- + +|Transformation Algorithms|, |Reversible Algorithm|, |partition|, |reverse_stable_partition|, |sort| diff --git a/doc/src/refmanual/reverse_remove.rst b/doc/src/refmanual/reverse_remove.rst new file mode 100644 index 0000000..3ce2d5f --- /dev/null +++ b/doc/src/refmanual/reverse_remove.rst @@ -0,0 +1,105 @@ +.. Algorithms/Transformation Algorithms//reverse_remove |160 + +reverse_remove +============== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + , typename T + , typename In = |unspecified| + > + struct reverse_remove + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns a new sequence that contains all elements from |begin/end| +range in reverse order except those that are identical to ``T``. + +|transformation algorithm disclaimer| + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Reversible Algorithm| + + +Parameters +---------- + ++---------------+-----------------------------------+-------------------------------+ +| Parameter | Requirement | Description | ++===============+===================================+===============================+ +| ``Sequence`` | |Forward Sequence| | An original sequence. | ++---------------+-----------------------------------+-------------------------------+ +| ``T`` | Any type | A type to be removed. | ++---------------+-----------------------------------+-------------------------------+ +| ``In`` | |Inserter| | An inserter. | ++---------------+-----------------------------------+-------------------------------+ + + +Expression semantics +-------------------- + +|Semantics disclaimer...| |Reversible Algorithm|. + +For any |Forward Sequence| ``s``, an |Inserter| ``in``, and arbitrary type ``x``: + + +.. parsed-literal:: + + typedef reverse_remove::type r; + +:Return type: + A type. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef reverse_remove_if< s,is_same<_,x>,in >::type r; + + +Complexity +---------- + +Linear. Performs exactly ``size::value`` comparisons for equality, and at +most ``size::value`` insertions. + + +Example +------- + +.. parsed-literal:: + + typedef vector::type types; + typedef reverse_remove< types,float >::type result; + + BOOST_MPL_ASSERT(( equal< result, vector > )); + + +See also +-------- + +|Transformation Algorithms|, |Reversible Algorithm|, |remove|, |reverse_remove_if|, +|reverse_copy|, |transform|, |replace| diff --git a/doc/src/refmanual/reverse_remove_if.rst b/doc/src/refmanual/reverse_remove_if.rst new file mode 100644 index 0000000..4e87fd9 --- /dev/null +++ b/doc/src/refmanual/reverse_remove_if.rst @@ -0,0 +1,115 @@ +.. Algorithms/Transformation Algorithms//reverse_remove_if |170 + +reverse_remove_if +================= + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + , typename Pred + , typename In = |unspecified| + > + struct reverse_remove_if + { + typedef |unspecified| type; + }; + + +Description +----------- + +Returns a new sequence that contains all the elements from |begin/end| range +in reverse order except those that satisfy the predicate ``Pred``. + +|transformation algorithm disclaimer| + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Reversible Algorithm| + + +Parameters +---------- + ++---------------+-----------------------------------+-------------------------------+ +| Parameter | Requirement | Description | ++===============+===================================+===============================+ +| ``Sequence`` | |Forward Sequence| | An original sequence. | ++---------------+-----------------------------------+-------------------------------+ +| ``Pred`` | Unary |Lambda Expression| | A removal condition. | ++---------------+-----------------------------------+-------------------------------+ +| ``In`` | |Inserter| | An inserter. | ++---------------+-----------------------------------+-------------------------------+ + + +Expression semantics +-------------------- + +|Semantics disclaimer...| |Reversible Algorithm|. + +For any |Forward Sequence| ``s``, and an |Inserter| ``in``, and an unary +|Lambda Expression| ``pred``: + + +.. parsed-literal:: + + typedef reverse_remove_if::type r; + +:Return type: + A type. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef lambda::type p; + typedef lambda::type op; + + typedef reverse_fold< + s + , in::state + , eval_if< + apply_wrap\ ``1``\ + , identity<_1> + , apply_wrap\ ``2``\ + > + >::type r; + + +Complexity +---------- + +Linear. Performs exactly ``size::value`` applications of ``pred``, and at +most ``size::value`` insertions. + + +Example +------- + +.. parsed-literal:: + + typedef vector_c::type numbers; + typedef reverse_remove_if< numbers, greater<_,int_<4> > >::type result; + + BOOST_MPL_ASSERT(( equal< result,vector_c,equal_to<_,_> > )); + + +See also +-------- + +|Transformation Algorithms|, |Reversible Algorithm|, |remove_if|, |reverse_remove|, +|reverse_copy_if|, |replace_if| diff --git a/doc/src/refmanual/reverse_replace.rst b/doc/src/refmanual/reverse_replace.rst new file mode 100644 index 0000000..8977765 --- /dev/null +++ b/doc/src/refmanual/reverse_replace.rst @@ -0,0 +1,107 @@ +.. Algorithms/Transformation Algorithms//reverse_replace |140 + +reverse_replace +=============== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + , typename OldType + , typename NewType + , typename In = |unspecified| + > + struct reverse_replace + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns a reversed copy of the original sequence where every type identical to ``OldType`` +has been replaced with ``NewType``. + +|transformation algorithm disclaimer| + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Reversible Algorithm| + + +Parameters +---------- + ++---------------+-----------------------------------+-------------------------------+ +| Parameter | Requirement | Description | ++===============+===================================+===============================+ +| ``Sequence`` | |Forward Sequence| | A original sequence. | ++---------------+-----------------------------------+-------------------------------+ +| ``OldType`` | Any type | A type to be replaced. | ++---------------+-----------------------------------+-------------------------------+ +| ``NewType`` | Any type | A type to replace with. | ++---------------+-----------------------------------+-------------------------------+ +| ``In`` | |Inserter| | An inserter. | ++---------------+-----------------------------------+-------------------------------+ + + +Expression semantics +-------------------- + +|Semantics disclaimer...| |Reversible Algorithm|. + +For any |Forward Sequence| ``s``, an |Inserter| ``in``, and arbitrary types ``x`` and ``y``: + + +.. parsed-literal:: + + typedef reverse_replace::type r; + +:Return type: + A type. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef reverse_replace_if< s,y,is_same<_,x>,in >::type r; + + +Complexity +---------- + +Linear. Performs exactly ``size::value`` comparisons for +identity / insertions. + + +Example +------- + +.. parsed-literal:: + + typedef vector types; + typedef vector expected; + typedef reverse_replace< types,float,double >::type result; + + BOOST_MPL_ASSERT(( equal< result,expected > )); + + +See also +-------- + +|Transformation Algorithms|, |Reversible Algorithm|, |replace|, |reverse_replace_if|, |remove|, |reverse_transform| diff --git a/doc/src/refmanual/reverse_replace_if.rst b/doc/src/refmanual/reverse_replace_if.rst new file mode 100644 index 0000000..601137e --- /dev/null +++ b/doc/src/refmanual/reverse_replace_if.rst @@ -0,0 +1,115 @@ +.. Algorithms/Transformation Algorithms//reverse_replace_if |150 + +reverse_replace_if +================== + + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + , typename Pred + , typename In = |unspecified| + > + struct reverse_replace_if + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns a reversed copy of the original sequence where every type that satisfies +the predicate ``Pred`` has been replaced with ``NewType``. + +|transformation algorithm disclaimer| + +Header +------ + +.. parsed-literal:: + + #include + + + +Model of +-------- + +|Reversible Algorithm| + + +Parameters +---------- + ++---------------+-----------------------------------+-------------------------------+ +| Parameter | Requirement | Description | ++===============+===================================+===============================+ +| ``Sequence`` | |Forward Sequence| | An original sequence. | ++---------------+-----------------------------------+-------------------------------+ +| ``Pred`` | Unary |Lambda Expression| | A replacement condition. | ++---------------+-----------------------------------+-------------------------------+ +| ``NewType`` | Any type | A type to replace with. | ++---------------+-----------------------------------+-------------------------------+ +| ``In`` | |Inserter| | An inserter. | ++---------------+-----------------------------------+-------------------------------+ + + +Expression semantics +-------------------- + +|Semantics disclaimer...| |Reversible Algorithm|. + +For any |Forward Sequence| ``s``, an unary |Lambda Expression| ``pred``, +an |Inserter| ``in``, and arbitrary type ``x``: + + +.. parsed-literal:: + + typedef reverse_replace_if::type r; + +:Return type: + A type. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef lambda::type p; + typedef reverse_transform< s, if_< apply_wrap1,x,_1>, in >::type r; + + +Complexity +---------- + +Linear. Performs exactly ``size::value`` applications of ``pred``, and at most +``size::value`` insertions. + + +Example +------- + +.. parsed-literal:: + + typedef vector_c numbers; + typedef vector_c expected; + typedef reverse_replace_if< + numbers + , greater< _, int_<4> > + , int_<0> + , front_inserter< vector<> > + >::type result; + + BOOST_MPL_ASSERT(( equal< result,expected, equal_to<_,_> > )); + + +See also +-------- + +|Transformation Algorithms|, |Reversible Algorithm|, |replace_if|, |reverse_replace|, |remove_if|, |transform| diff --git a/doc/src/refmanual/reverse_stable_partition.rst b/doc/src/refmanual/reverse_stable_partition.rst new file mode 100644 index 0000000..c388651 --- /dev/null +++ b/doc/src/refmanual/reverse_stable_partition.rst @@ -0,0 +1,127 @@ +.. Algorithms/Transformation Algorithms//reverse_stable_partition |190 + +reverse_stable_partition +======================== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Seq + , typename Pred + , typename In1 = |unspecified| + , typename In2 = |unspecified| + > + struct reverse_stable_partition + { + typedef |unspecified| type; + }; + + +Description +----------- + +Returns a pair of sequences together containing all elements in the range +|begin/end| split into two groups based on the predicate ``Pred``. +``reverse_stable_partition`` is guaranteed to preserve the reversed +relative order of the elements in the resulting sequences. + + +|transformation algorithm disclaimer| + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Reversible Algorithm| + + +Parameters +---------- + ++-------------------+-----------------------------------+-------------------------------+ +| Parameter | Requirement | Description | ++===================+===================================+===============================+ +| ``Seq`` | |Forward Sequence| | An original sequence. | ++-------------------+-----------------------------------+-------------------------------+ +| ``Pred`` | Unary |Lambda Expression| | A partitioning predicate. | ++-------------------+-----------------------------------+-------------------------------+ +| ``In1``, ``In2`` | |Inserter| | Output inserters. | ++-------------------+-----------------------------------+-------------------------------+ + + +Expression semantics +-------------------- + +|Semantics disclaimer...| |Reversible Algorithm|. + +For any |Forward Sequence| ``s``, an unary |Lambda Expression| ``pred``, and |Inserter|\ s +``in1`` and ``in2``: + + +.. parsed-literal:: + + typedef reverse_stable_partition::type r; + +:Return type: + A |pair|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef lambda::type p; + typedef lambda::type in1_op; + typedef lambda::type in2_op; + + typedef reverse_fold< + s + , pair< in1::state, in2::state > + , if_< + apply_wrap\ ``1``\ + , pair< apply_wrap\ ``2``\,_2>, second<_1> > + , pair< first<_1>, apply_wrap\ ``2``\,_2> > + > + >::type r; + + +Complexity +---------- + +Linear. Exactly ``size::value`` applications of ``pred``, and ``size::value`` +of summarized ``in1::operation`` / ``in2::operation`` applications. + + +Example +------- + +.. parsed-literal:: + + template< typename N > struct is_odd : bool_<(N::value % 2)> {}; + + typedef reverse_stable_partition< + range_c + , is_odd<_1> + , back_inserter< vector<> > + , back_inserter< vector<> > + >::type r; + + BOOST_MPL_ASSERT(( equal< r::first, vector_c > )); + BOOST_MPL_ASSERT(( equal< r::second, vector_c > )); + + +See also +-------- + +|Transformation Algorithms|, |Reversible Algorithm|, |stable_partition|, |reverse_partition|, |sort|, |transform| diff --git a/doc/src/refmanual/reverse_transform.rst b/doc/src/refmanual/reverse_transform.rst new file mode 100644 index 0000000..aff7149 --- /dev/null +++ b/doc/src/refmanual/reverse_transform.rst @@ -0,0 +1,158 @@ +.. Algorithms/Transformation Algorithms//reverse_transform |130 + +reverse_transform +================= + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Seq + , typename Op + , typename In = |unspecified| + > + struct reverse_transform + { + typedef |unspecified| type; + }; + + template< + typename Seq1 + , typename Seq2 + , typename BinaryOp + , typename In = |unspecified| + > + struct reverse_transform + { + typedef |unspecified| type; + }; + + +Description +----------- + +``reverse_transform`` is an |overloaded name|: + +* ``reverse_transform`` returns a reversed, transformed copy of the + original sequence produced by applying an unary transformation ``Op`` to + every element in the |begin/end| range. + +* ``reverse_transform`` returns a new sequence produced by applying a + binary transformation ``BinaryOp`` to a pair of elements (e\ :sub:`1`, e2\ :sub:`1`) + from the corresponding |begin/end| and |begin/end| ranges in reverse + order. + +|transformation algorithm disclaimer| + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Reversible Algorithm| + + +Parameters +---------- + ++-------------------+-----------------------------------+-----------------------------------+ +| Parameter | Requirement | Description | ++===================+===================================+===================================+ +| ``Sequence``, | |Forward Sequence| | Sequences to transform. | +| ``Seq1``, ``Seq2``| | | ++-------------------+-----------------------------------+-----------------------------------+ +| ``Op``, | |Lambda Expression| | A transformation. | +| ``BinaryOp`` | | | ++-------------------+-----------------------------------+-----------------------------------+ +| ``In`` | |Inserter| | An inserter. | ++-------------------+-----------------------------------+-----------------------------------+ + + +Expression semantics +-------------------- + +|Semantics disclaimer...| |Reversible Algorithm|. + +For any |Forward Sequence|\ s ``s``, ``s1`` and ``s2``, |Lambda Expression|\ s ``op`` and ``op2``, +and an |Inserter| ``in``: + +.. parsed-literal:: + + typedef reverse_transform::type r; + +:Return type: + A type. + +:Postcondition: + Equivalent to + + .. parsed-literal:: + + typedef lambda::type f; + typedef lambda::type in_op; + + typedef reverse_fold< + s + , in::state + , bind< in_op, _1, bind > + >::type r; + + +.. parsed-literal:: + + typedef transform::type r; + +:Return type: + A type. + +:Postcondition: + Equivalent to + + .. parsed-literal:: + + typedef lambda::type f; + typedef lambda::type in_op; + + typedef reverse_fold< + pair_view + , in::state + , bind< + in_op + , _1 + , bind,_2>, bind,_2> > + > + >::type r; + + +Complexity +---------- + +Linear. Exactly ``size::value`` / ``size::value`` applications of +``op`` / ``op2`` and ``in::operation``. + + +Example +------- + +.. parsed-literal:: + + typedef vector types; + typedef vector pointers; + typedef reverse_transform< types,boost::add_pointer<_1> >::type result; + + BOOST_MPL_ASSERT(( equal )); + + +See also +-------- + +|Transformation Algorithms|, |Reversible Algorithm|, |transform|, |reverse_copy|, |replace_if| diff --git a/doc/src/refmanual/reverse_unique.rst b/doc/src/refmanual/reverse_unique.rst new file mode 100644 index 0000000..cdfb0e1 --- /dev/null +++ b/doc/src/refmanual/reverse_unique.rst @@ -0,0 +1,127 @@ +.. Algorithms/Transformation Algorithms//reverse_unique |180 + +reverse_unique +============== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Seq + , typename Pred + , typename In = |unspecified| + > + struct reverse_unique + { + typedef |unspecified| type; + }; + + +Description +----------- + +Returns a sequence of the initial elements of every subrange of the +reversed original sequence ``Seq`` whose elements are all the same. + +|transformation algorithm disclaimer| + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Reversible Algorithm| + + +Parameters +---------- + ++---------------+-----------------------------------+-------------------------------+ +| Parameter | Requirement | Description | ++===============+===================================+===============================+ +| ``Sequence`` | |Forward Sequence| | An original sequence. | ++---------------+-----------------------------------+-------------------------------+ +| ``Pred`` | Binary |Lambda Expression| | An equivalence relation. | ++---------------+-----------------------------------+-------------------------------+ +| ``In`` | |Inserter| | An inserter. | ++---------------+-----------------------------------+-------------------------------+ + + +Expression semantics +-------------------- + +|Semantics disclaimer...| |Reversible Algorithm|. + +For any |Forward Sequence| ``s``, a binary |Lambda Expression| ``pred``, +and an |Inserter| ``in``: + + +.. parsed-literal:: + + typedef reverse_unique::type r; + +:Return type: + A type. + +:Semantics: + If ``size::value <= 1``, then equivalent to + + .. parsed-literal:: + + typedef reverse_copy::type r; + + otherwise equivalent to + + .. parsed-literal:: + + typedef lambda::type p; + typedef lambda::type in_op; + typedef apply_wrap\ ``2``\< + in_op + , in::state + , front::type + >::type in_state; + + typedef reverse_fold< + s + , pair< in_state, front::type > + , eval_if< + apply_wrap\ ``2``\, _2> + , identity< first<_1> > + , apply_wrap\ ``2``\, _2> + > + >::type::first r; + + +Complexity +---------- + +Linear. Performs exactly ``size::value - 1`` applications of ``pred``, and at +most ``size::value`` insertions. + + +Example +------- + +.. parsed-literal:: + + typedef vector types; + typedef vector expected; + typedef reverse_unique< types, is_same<_1,_2> >::type result; + + BOOST_MPL_ASSERT(( equal< result,expected > )); + + +See also +-------- + +|Transformation Algorithms|, |Reversible Algorithm|, |unique|, |reverse_remove|, +|reverse_copy_if|, |replace_if| diff --git a/doc/src/refmanual/sequence_tag.rst b/doc/src/refmanual/sequence_tag.rst new file mode 100644 index 0000000..e7f06a4 --- /dev/null +++ b/doc/src/refmanual/sequence_tag.rst @@ -0,0 +1,74 @@ +.. Sequences/Intrinsic Metafunctions//sequence_tag + +sequence_tag +============ + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename X + > + struct sequence_tag + { + typedef |unspecified| type; + }; + + + +Description +----------- + +``sequence_tag`` is a |tag-metafunction| for all |tag dispatched| +`intrinsic sequence operations`__. + +__ `Intrinsic Metafunctions`_ + + +Header +------ + +.. parsed-literal:: + + #include + + +Parameters +---------- + ++---------------+-------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===================+===============================================+ +| ``X`` | Any type | A type to obtain a sequence tag for. | ++---------------+-------------------+-----------------------------------------------+ + + +Expression semantics +-------------------- + +For any arbitrary type ``x``: + + +.. parsed-literal:: + + typedef sequence_tag::type tag; + +:Return type: + A type. + +:Semantics: + ``tag`` is an unspecified tag type for ``x``. + + +Complexity +---------- + +Amortized constant time. + + +See also +-------- + +`Intrinsic Metafunctions`_, |Tag Dispatched Metafunction| diff --git a/doc/src/refmanual/set.rst b/doc/src/refmanual/set.rst new file mode 100644 index 0000000..0238ba0 --- /dev/null +++ b/doc/src/refmanual/set.rst @@ -0,0 +1,125 @@ +.. Sequences/Classes//set |40 + +set +=== + +Description +----------- + +``set`` is a |variadic|, `associative`__, `extensible`__ sequence of types that +supports constant-time insertion and removal of elements, and testing for membership. +A ``set`` may contain at most one element for each key. + +__ `Associative Sequence`_ +__ `Extensible Associative Sequence`_ + +Header +------ + ++-------------------+-------------------------------------------------------+ +| Sequence form | Header | ++===================+=======================================================+ +| Variadic | ``#include `` | ++-------------------+-------------------------------------------------------+ +| Numbered | ``#include `` | ++-------------------+-------------------------------------------------------+ + + +Model of +-------- + +* |Variadic Sequence| +* |Associative Sequence| +* |Extensible Associative Sequence| + + +Expression semantics +-------------------- + +In the following table, ``s`` is an instance of ``set``, ``pos`` is an iterator into ``s``, +and ``x``, ``k``, and |t1...tn| are arbitrary types. + ++---------------------------------------+-----------------------------------------------------------+ +| Expression | Semantics | ++=======================================+===========================================================+ +| .. parsed-literal:: | ``set`` of elements |t1...tn|; see | +| | |Variadic Sequence|. | +| set<|t1...tn|> | | +| set\ *n*\ <|t1...tn|> | | ++---------------------------------------+-----------------------------------------------------------+ +| .. parsed-literal:: | Identical to ``set``\ *n*\ ``<``\ |t1...tn|\ ``>``; | +| | see |Variadic Sequence|. | +| set<|t1...tn|>::type | | +| set\ *n*\ <|t1...tn|>::type | | ++---------------------------------------+-----------------------------------------------------------+ +| ``begin::type`` | An iterator pointing to the beginning of ``s``; | +| | see |Associative Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``end::type`` | An iterator pointing to the end of ``s``; | +| | see |Associative Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``size::type`` | The size of ``s``; see |Associative Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``empty::type`` | |true if and only if| ``s`` is empty; see | +| | |Associative Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``front::type`` | The first element in ``s``; see | +| | |Associative Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``has_key::type`` | |true if and only if| there is one or more elements | +| | with the key ``k`` in ``s``; see |Associative Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``count::type`` | The number of elements with the key ``k`` in ``s``; | +| | see |Associative Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``order::type`` | A unique unsigned |Integral Constant| associated with | +| | the key ``k`` in ``s``; see |Associative Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| .. parsed-literal:: | The element associated with the key ``k`` in | +| | ``s``; see |Associative Sequence|. | +| at::type | | +| at::type | | ++---------------------------------------+-----------------------------------------------------------+ +| ``key_type::type`` | Identical to ``x``; see |Associative Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``value_type::type`` | Identical to ``x``; see |Associative Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``insert::type`` | A new ``set`` equivalent to ``s`` except that | +| | :: | +| | | +| | at< t, key_type::type >::type | +| | | +| | is identical to ``value_type::type``. | ++---------------------------------------+-----------------------------------------------------------+ +| ``insert::type`` | Equivalent to ``insert::type``; ``pos`` is ignored. | ++---------------------------------------+-----------------------------------------------------------+ +| ``erase_key::type`` | A new ``set`` equivalent to ``s`` except that | +| | ``has_key::value == false``. | ++---------------------------------------+-----------------------------------------------------------+ +| ``erase::type`` | Equivalent to ``erase::type >::type``. | ++---------------------------------------+-----------------------------------------------------------+ +| ``clear::type`` | An empty ``set``; see |clear|. | ++---------------------------------------+-----------------------------------------------------------+ + + +Example +------- + +.. parsed-literal:: + + typedef set< int,long,double,int_<5> > s; + + BOOST_MPL_ASSERT_RELATION( size::value, ==, 4 ); + BOOST_MPL_ASSERT_NOT(( empty )); + + BOOST_MPL_ASSERT(( is_same< at::type, int > )); + BOOST_MPL_ASSERT(( is_same< at::type, long > )); + BOOST_MPL_ASSERT(( is_same< at >::type, int_<5> > )); + BOOST_MPL_ASSERT(( is_same< at::type, void\_ > )); + + +See also +-------- + +|Sequences|, |Variadic Sequence|, |Associative Sequence|, |Extensible Associative Sequence|, |set_c|, |map|, |vector| + diff --git a/doc/src/refmanual/set_c.rst b/doc/src/refmanual/set_c.rst new file mode 100644 index 0000000..53cd704 --- /dev/null +++ b/doc/src/refmanual/set_c.rst @@ -0,0 +1,82 @@ +.. Sequences/Classes//set_c |90 + +set_c +===== + +Description +----------- + +``set_c`` is an |Integral Sequence Wrapper| for |set|. As such, it shares +all |set| characteristics and requirements, and differs only in the way the +original sequence content is specified. + +Header +------ + ++-------------------+-------------------------------------------------------+ +| Sequence form | Header | ++===================+=======================================================+ +| Variadic | ``#include `` | ++-------------------+-------------------------------------------------------+ +| Numbered | ``#include `` | ++-------------------+-------------------------------------------------------+ + + +Model of +-------- + +* |Variadic Sequence| +* |Associative Sequence| +* |Extensible Associative Sequence| + + +Expression semantics +-------------------- + +|Semantics disclaimer...| |set|. + +.. workaround substitution bug (should be replace:: set\ *n*\ _c) +.. |setn_c| replace:: set\ *n*\ _c + ++---------------------------------------+-----------------------------------------------+ +| Expression | Semantics | ++=======================================+===============================================+ +| .. parsed-literal:: | A |set| of integral constant wrappers | +| | ``integral_c``, | +| set_c | ``integral_c``, ... | +| |setn_c| | ``integral_c``; | +| | see |Integral Sequence Wrapper|. | ++---------------------------------------+-----------------------------------------------+ +| .. parsed-literal:: | Identical to ``set``\ *n*\ ``<`` | +| | ``integral_c``, | +| set_c::type | ``integral_c``, ... | +| |setn_c|::type | ``integral_c`` ``>``; | +| | see |Integral Sequence Wrapper|. | ++---------------------------------------+-----------------------------------------------+ +| .. parsed-literal:: | Identical to ``T``; see | +| | |Integral Sequence Wrapper|. | +| set_c::value_type | | +| |setn_c|::value_type | | ++---------------------------------------+-----------------------------------------------+ + + +Example +------- + +.. parsed-literal:: + + typedef set_c< int,1,3,5,7,9 > odds; + + BOOST_MPL_ASSERT_RELATION( size::value, ==, 5 ); + BOOST_MPL_ASSERT_NOT(( empty )); + + BOOST_MPL_ASSERT(( has_key< odds, integral_c > )); + BOOST_MPL_ASSERT_NOT(( has_key< odds, integral_c > )); + BOOST_MPL_ASSERT_NOT(( has_key< odds, integral_c > )); + + +See also +-------- + +|Sequences|, |Integral Sequence Wrapper|, |set|, |integral_c|, |vector_c|, |list_c|, |range_c| + diff --git a/doc/src/refmanual/shift_left.rst b/doc/src/refmanual/shift_left.rst new file mode 100644 index 0000000..af967db --- /dev/null +++ b/doc/src/refmanual/shift_left.rst @@ -0,0 +1,123 @@ +.. Metafunctions/Bitwise Operations//shift_left + +shift_left +========== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename T + , typename Shift + > + struct shift_left + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns the result of bitwise *shift left* (``<<``) operation on ``T``. + + +Header +------ + +.. parsed-literal:: + + #include + #include + + +Model of +-------- + +|Numeric Metafunction| + + +Parameters +---------- + ++---------------+-------------------------------+---------------------------+ +| Parameter | Requirement | Description | ++===============+===============================+===========================+ +| ``T`` | |Integral Constant| | A value to shift. | ++---------------+-------------------------------+---------------------------+ +| ``Shift`` | Unsigned |Integral Constant| | A shift distance. | ++---------------+-------------------------------+---------------------------+ + +|Note:| |numeric metafunction note| |-- end note| + + +Expression semantics +-------------------- + +For arbitrary |Integral Constant| ``c`` and unsigned |Integral Constant| ``shift``: + + +.. parsed-literal:: + + typedef shift_left::type r; + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef integral_c< + c::value_type + , ( c::value << shift::value ) + > r; + +.. .......................................................................... + +.. parsed-literal:: + + typedef shift_left r; + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + struct r : shift_left::type {}; + + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + typedef integral_c u0; + typedef integral_c u1; + typedef integral_c u2; + typedef integral_c u8; + + BOOST_MPL_ASSERT_RELATION( (shift_left::value), ==, 0 ); + BOOST_MPL_ASSERT_RELATION( (shift_left::value), ==, 1 ); + BOOST_MPL_ASSERT_RELATION( (shift_left::value), ==, 2 ); + BOOST_MPL_ASSERT_RELATION( (shift_left::value), ==, 4 ); + BOOST_MPL_ASSERT_RELATION( (shift_left::value), ==, 16 ); + + +See also +-------- + +|Bitwise Operations|, |Numeric Metafunction|, |numeric_cast|, |shift_right|, |bitand_| diff --git a/doc/src/refmanual/shift_right.rst b/doc/src/refmanual/shift_right.rst new file mode 100644 index 0000000..49abdec --- /dev/null +++ b/doc/src/refmanual/shift_right.rst @@ -0,0 +1,123 @@ +.. Metafunctions/Bitwise Operations//shift_right + +shift_right +=========== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename T + , typename Shift + > + struct shift_right + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns the result of bitwise *shift right* (``>>``) operation on ``T``. + + +Header +------ + +.. parsed-literal:: + + #include + #include + + +Model of +-------- + +|Numeric Metafunction| + + +Parameters +---------- + ++---------------+-------------------------------+---------------------------+ +| Parameter | Requirement | Description | ++===============+===============================+===========================+ +| ``T`` | |Integral Constant| | A value to shift. | ++---------------+-------------------------------+---------------------------+ +| ``Shift`` | Unsigned |Integral Constant| | A shift distance. | ++---------------+-------------------------------+---------------------------+ + +|Note:| |numeric metafunction note| |-- end note| + + +Expression semantics +-------------------- + +For arbitrary |Integral Constant| ``c`` and unsigned |Integral Constant| ``shift``: + + +.. parsed-literal:: + + typedef shift_right::type r; + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef integral_c< + c::value_type + , ( c::value >> shift::value ) + > r; + +.. .......................................................................... + +.. parsed-literal:: + + typedef shift_right r; + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + struct r : shift_right::type {}; + + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + typedef integral_c u0; + typedef integral_c u1; + typedef integral_c u2; + typedef integral_c u8; + + BOOST_MPL_ASSERT_RELATION( (shift_right::value), ==, 0 ); + BOOST_MPL_ASSERT_RELATION( (shift_right::value), ==, 1 ); + BOOST_MPL_ASSERT_RELATION( (shift_right::value), ==, 0 ); + BOOST_MPL_ASSERT_RELATION( (shift_right::value), ==, 1 ); + BOOST_MPL_ASSERT_RELATION( (shift_right::value), ==, 4 ); + + +See also +-------- + +|Bitwise Operations|, |Numeric Metafunction|, |numeric_cast|, |shift_left|, |bitand_| diff --git a/doc/src/refmanual/single_view.rst b/doc/src/refmanual/single_view.rst new file mode 100644 index 0000000..28c3450 --- /dev/null +++ b/doc/src/refmanual/single_view.rst @@ -0,0 +1,90 @@ +.. Sequences/Views//single_view + +single_view +=========== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename T + > + struct single_view + { + // |unspecified| + // |...| + }; + + + +Description +----------- + +A view onto an arbitrary type ``T`` as on a single-element sequence. + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +* |Random Access Sequence| + + +Parameters +---------- + ++---------------+-------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===================+===============================================+ +| ``T`` | Any type | The type to be wrapped in a sequence. | ++---------------+-------------------+-----------------------------------------------+ + + +Expression semantics +-------------------- + +|Semantics disclaimer...| |Random Access Sequence|. + +In the following table, ``v`` is an instance of ``single_view``, ``x`` is an arbitrary type. + ++-------------------------------+-----------------------------------------------------------+ +| Expression | Semantics | ++===============================+===========================================================+ +| .. parsed-literal:: | A single-element |Random Access Sequence| ``v`` such that | +| | ``front::type`` is identical to ``x``. | +| single_view | | +| single_view::type | | ++-------------------------------+-----------------------------------------------------------+ +| ``size::type`` | The size of ``v``; ``size::value == 1``; | +| | see |Random Access Sequence|. | ++-------------------------------+-----------------------------------------------------------+ + +Example +------- + +.. parsed-literal:: + + typedef single_view view; + typedef begin::type first; + typedef end::type last; + + BOOST_MPL_ASSERT(( is_same< deref::type,int > )); + BOOST_MPL_ASSERT(( is_same< next::type,last > )); + BOOST_MPL_ASSERT(( is_same< prior::type,first > )); + + BOOST_MPL_ASSERT_RELATION( size::value, ==, 1 ); + + +See also +-------- + +|Sequences|, |Views|, |iterator_range|, |filter_view|, |transform_view|, |joint_view|, |zip_view| diff --git a/doc/src/refmanual/size.rst b/doc/src/refmanual/size.rst new file mode 100644 index 0000000..6f88fa9 --- /dev/null +++ b/doc/src/refmanual/size.rst @@ -0,0 +1,109 @@ +.. Sequences/Intrinsic Metafunctions//size + +size +==== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + > + struct size + { + typedef |unspecified| type; + }; + + + +Description +----------- + +``size`` returns the number of elements in the sequence, that is, the number of elements +in the range [``begin::type``, ``end::type``). + + +Header +------ + +.. parsed-literal:: + + #include + + + +Model of +-------- + +|Tag Dispatched Metafunction| + + +Parameters +---------- + ++---------------+-----------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+=======================+===============================================+ +| ``Sequence`` | |Forward Sequence| | A sequence to query. | ++---------------+-----------------------+-----------------------------------------------+ + + +Expression semantics +-------------------- + + +For any |Forward Sequence| ``s``: + + +.. parsed-literal:: + + typedef size::type n; + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef distance< begin::type,end::type >::type n; + + +:Postcondition: + ``n::value >= 0``. + + + +Complexity +---------- + +The complexity of the ``size`` metafunction directly depends on the implementation of +the particular sequence it is applied to. In the worst case, ``size`` guarantees a +linear complexity. + +If the ``s`` is a |Random Access Sequence|, ``size::type`` is an |O(1)| operation. +The opposite is not necessarily true |--| for example, a sequence class that models +|Forward Sequence| might still give us an |O(1)| ``size`` implementation. + + +Example +------- + +.. parsed-literal:: + + typedef list0<> empty_list; + typedef vector_c numbers; + typedef range_c more_numbers; + + BOOST_MPL_ASSERT_RELATION( size::value, ==, 0 ); + BOOST_MPL_ASSERT_RELATION( size::value, ==, 5 ); + BOOST_MPL_ASSERT_RELATION( size::value, ==, 100 ); + + +See also +-------- + +|Forward Sequence|, |Random Access Sequence|, |empty|, |begin|, |end|, |distance| diff --git a/doc/src/refmanual/size_t.rst b/doc/src/refmanual/size_t.rst new file mode 100644 index 0000000..d6dfd2d --- /dev/null +++ b/doc/src/refmanual/size_t.rst @@ -0,0 +1,84 @@ +.. Data Types/Numeric//size_t |40 + +size_t +====== + +Synopsis +-------- + +.. parsed-literal:: + + template< + std::size_t N + > + struct size_t + { + // |unspecified| + // ... + }; + + +Description +----------- + +An |Integral Constant| wrapper for ``std::size_t``. + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Integral Constant| + + +Parameters +---------- + ++---------------+-------------------------------+---------------------------+ +| Parameter | Requirement | Description | ++===============+===============================+===========================+ +| ``N`` | An integral constant | A value to wrap. | ++---------------+-------------------------------+---------------------------+ + +Expression semantics +-------------------- + +|Semantics disclaimer...| |Integral Constant|. + +For arbitrary integral constant ``n``: + ++-------------------+-----------------------------------------------------------+ +| Expression | Semantics | ++===================+===========================================================+ +| ``size_t`` | An |Integral Constant| ``x`` such that ``x::value == c`` | +| | and ``x::value_type`` is identical to ``std::size_t``. | ++-------------------+-----------------------------------------------------------+ + + +Example +------- + +.. parsed-literal:: + + typedef size_t<8> eight; + + BOOST_MPL_ASSERT(( is_same< eight::value_type, std::size_t > )); + BOOST_MPL_ASSERT(( is_same< eight::type, eight > )); + BOOST_MPL_ASSERT(( is_same< next< eight >::type, size_t<9> > )); + BOOST_MPL_ASSERT(( is_same< prior< eight >::type, size_t<7> > )); + BOOST_MPL_ASSERT_RELATION( (eight::value), ==, 8 ); + assert( eight() == 8 ); + + +See also +-------- + +|Data Types|, |Integral Constant|, |int_|, |long_|, |integral_c| + diff --git a/doc/src/refmanual/sizeof_.rst b/doc/src/refmanual/sizeof_.rst new file mode 100644 index 0000000..4c6fda8 --- /dev/null +++ b/doc/src/refmanual/sizeof_.rst @@ -0,0 +1,100 @@ +.. Metafunctions/Miscellaneous//sizeof_ |100 + +sizeof\_ +======== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename X + > + struct sizeof\_ + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns the result of a ``sizeof(X)`` expression wrapped into an +|Integral Constant| of the corresponding type, ``std::size_t``. + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Metafunction| + + +Parameters +---------- + ++---------------+-------------------+-------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===================+===========================================+ +| ``X`` | Any type | A type to compute the ``sizeof`` for. | ++---------------+-------------------+-------------------------------------------+ + + +Expression semantics +-------------------- + +For an arbitrary type ``x``: + + +.. parsed-literal:: + + typedef sizeof_::type n; + + +:Return type: + |Integral Constant|. + +:Precondition: + ``x`` is a complete type. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef size_t< sizeof(x) > n; + + + +Complexity +---------- + +Constant time. + + +Example +------- + +.. parsed-literal:: + + struct udt { char a[100]; }; + + BOOST_MPL_ASSERT_RELATION( sizeof_::value, ==, sizeof(char) ); + BOOST_MPL_ASSERT_RELATION( sizeof_::value, ==, sizeof(int) ); + BOOST_MPL_ASSERT_RELATION( sizeof_::value, ==, sizeof(double) ); + BOOST_MPL_ASSERT_RELATION( sizeof_::value, ==, sizeof(my) ); + + +See also +-------- + +|Metafunctions|, |Integral Constant|, |size_t| diff --git a/doc/src/refmanual/sort.rst b/doc/src/refmanual/sort.rst new file mode 100644 index 0000000..9b9c68a --- /dev/null +++ b/doc/src/refmanual/sort.rst @@ -0,0 +1,130 @@ +.. Algorithms/Transformation Algorithms//sort |95 + +sort +==== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Seq + , typename Pred = less<_1,_2> + , typename In = |unspecified| + > + struct sort + { + typedef |unspecified| type; + }; + + +Description +----------- + +Returns a new sequence of all elements in the range |begin/end| sorted according +to the ordering relation ``Pred``. + +|transformation algorithm disclaimer| + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Reversible Algorithm| + + +Parameters +---------- + ++-------------------+-----------------------------------+-------------------------------+ +| Parameter | Requirement | Description | ++===================+===================================+===============================+ +| ``Seq`` | |Forward Sequence| | An original sequence. | ++-------------------+-----------------------------------+-------------------------------+ +| ``Pred`` | Binary |Lambda Expression| | An ordering relation. | ++-------------------+-----------------------------------+-------------------------------+ +| ``In`` | |Inserter| | An inserter. | ++-------------------+-----------------------------------+-------------------------------+ + + +Expression semantics +-------------------- + +|Semantics disclaimer...| |Reversible Algorithm|. + +For any |Forward Sequence| ``s``, a binary |Lambda Expression| ``pred``, and an +|Inserter| ``in``: + + +.. parsed-literal:: + + typedef sort::type r; + +:Return type: + A type. + +:Semantics: + If ``size::value <= 1``, equivalent to + + .. parsed-literal:: + + typedef copy::type r; + + + otherwise equivalent to + + .. parsed-literal:: + + typedef back_inserter< vector<> > aux_in; + typedef lambda::type p; + + typedef begin::type pivot; + typedef partition< + iterator_range< next::type, end::type > + , apply_wrap2::type> + , aux_in + , aux_in + >::type partitioned; + + typedef sort::type part1; + typedef sort::type part2; + + typedef copy< + joint_view< + joint_view::type > > + , part2 + > + , in + >::type r; + + +Complexity +---------- + +Average *O(n log(n))* where *n* == ``size::value``, quadratic at worst. + +Example +------- + +.. parsed-literal:: + + typedef vector_c numbers; + typedef vector_c expected; + typedef sort::type result; + + BOOST_MPL_ASSERT(( equal< result, expected, equal_to<_,_> > )); + + +See also +-------- + +|Transformation Algorithms|, |Reversible Algorithm|, |partition| diff --git a/doc/src/refmanual/stable_partition.rst b/doc/src/refmanual/stable_partition.rst new file mode 100644 index 0000000..61d85bc --- /dev/null +++ b/doc/src/refmanual/stable_partition.rst @@ -0,0 +1,127 @@ +.. Algorithms/Transformation Algorithms//stable_partition |90 + +stable_partition +================ + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Seq + , typename Pred + , typename In1 = |unspecified| + , typename In2 = |unspecified| + > + struct stable_partition + { + typedef |unspecified| type; + }; + + +Description +----------- + +Returns a pair of sequences together containing all elements in the range +|begin/end| split into two groups based on the predicate ``Pred``. +``stable_partition`` is guaranteed to preserve the relative order of the +elements in the resulting sequences. + + +|transformation algorithm disclaimer| + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Reversible Algorithm| + + +Parameters +---------- + ++-------------------+-----------------------------------+-------------------------------+ +| Parameter | Requirement | Description | ++===================+===================================+===============================+ +| ``Seq`` | |Forward Sequence| | An original sequence. | ++-------------------+-----------------------------------+-------------------------------+ +| ``Pred`` | Unary |Lambda Expression| | A partitioning predicate. | ++-------------------+-----------------------------------+-------------------------------+ +| ``In1``, ``In2`` | |Inserter| | Output inserters. | ++-------------------+-----------------------------------+-------------------------------+ + + +Expression semantics +-------------------- + +|Semantics disclaimer...| |Reversible Algorithm|. + +For any |Forward Sequence| ``s``, an unary |Lambda Expression| ``pred``, and |Inserter|\ s +``in1`` and ``in2``: + + +.. parsed-literal:: + + typedef stable_partition::type r; + +:Return type: + A |pair|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef lambda::type p; + typedef lambda::type in1_op; + typedef lambda::type in2_op; + + typedef fold< + s + , pair< in1::state, in2::state > + , if_< + apply_wrap\ ``1``\ + , pair< apply_wrap\ ``2``\,_2>, second<_1> > + , pair< first<_1>, apply_wrap\ ``2``\,_2> > + > + >::type r; + + +Complexity +---------- + +Linear. Exactly ``size::value`` applications of ``pred``, and ``size::value`` +of summarized ``in1::operation`` / ``in2::operation`` applications. + + +Example +------- + +.. parsed-literal:: + + template< typename N > struct is_odd : bool_<(N::value % 2)> {}; + + typedef stable_partition< + range_c + , is_odd<_1> + , back_inserter< vector<> > + , back_inserter< vector<> > + >::type r; + + BOOST_MPL_ASSERT(( equal< r::first, vector_c > )); + BOOST_MPL_ASSERT(( equal< r::second, vector_c > )); + + +See also +-------- + +|Transformation Algorithms|, |Reversible Algorithm|, |reverse_stable_partition|, |partition|, |sort|, |transform| diff --git a/doc/src/refmanual/terminology.rst b/doc/src/refmanual/terminology.rst new file mode 100644 index 0000000..c8dd027 --- /dev/null +++ b/doc/src/refmanual/terminology.rst @@ -0,0 +1,48 @@ + +.. _`Overloaded name`: + +Overloaded name + Overloaded name is a term used in this reference documentation to designate + a metafunction providing more than one public interface. In reality, + class template overloading is nonexistent and the referenced functionality + is implemented by other, unspecified, means. + + +.. |overloaded name| replace:: `overloaded name`__ +__ `Overloaded name`_ + + + +.. _`Concept-identical`: + +Concept-identical + A sequence ``s1`` is said to be concept-identical to a sequence ``s2`` if + ``s1`` and ``s2`` model the exact same set of concepts. + + +.. _`Bind expression`: + +Bind expression + A bind expression is simply that |--| an instantiation of one of the |bind| + class templates. For instance, these are all bind expressions:: + + bind< quote3, _1,int,long > + bind< _1, bind< plus<>, int_<5>, _2> > + bind< times<>, int_<2>, int_<2> > + + and these are not:: + + if_< _1, bind< plus<>, int_<5>, _2>, _2 > + protect< bind< quote3, _1,int,long > > + _2 + + +.. |bind expression| replace:: `bind expression`__ +__ `Bind expression`_ + + + +.. |concept-identical| replace:: `concept-identical`__ +__ `Concept-identical`_ + + diff --git a/doc/src/refmanual/times.rst b/doc/src/refmanual/times.rst new file mode 100644 index 0000000..6e4ed88 --- /dev/null +++ b/doc/src/refmanual/times.rst @@ -0,0 +1,120 @@ +.. Metafunctions/Arithmetic Operations//times |30 + +times +===== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename T1 + , typename T2 + , typename T3 = |unspecified| + |...| + , typename T\ *n* = |unspecified| + > + struct times + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns the product of its arguments. + + +Header +------ + +.. parsed-literal:: + + #include + #include + + +Model of +-------- + +|Numeric Metafunction| + + +Parameters +---------- + ++---------------+---------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===========================+===============================================+ +| |T1...Tn| | |Integral Constant| | Operation's arguments. | ++---------------+---------------------------+-----------------------------------------------+ + +|Note:| |numeric metafunction note| |-- end note| + + +Expression semantics +-------------------- + +For any |Integral Constant|\ s |c1...cn|: + + +.. parsed-literal:: + + typedef times::type r; + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef integral_c< + typeof(c1::value * c2::value) + , ( c1::value * c2::value ) + > c; + + typedef times::type r; + +.. .......................................................................... + + +.. parsed-literal:: + + typedef times r; + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + struct r : times::type {}; + + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + typedef times< int_<-10>, int_<3>, long_<1> >::type r; + BOOST_MPL_ASSERT_RELATION( r::value, ==, -30 ); + BOOST_MPL_ASSERT(( is_same< r::value_type, long > )); + + +See also +-------- + +|Metafunctions|, |Numeric Metafunction|, |numeric_cast|, |divides|, |modulus|, |plus| diff --git a/doc/src/refmanual/transform.rst b/doc/src/refmanual/transform.rst new file mode 100644 index 0000000..0912114 --- /dev/null +++ b/doc/src/refmanual/transform.rst @@ -0,0 +1,157 @@ +.. Algorithms/Transformation Algorithms//transform |30 + +transform +========= + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Seq + , typename Op + , typename In = |unspecified| + > + struct transform + { + typedef |unspecified| type; + }; + + template< + typename Seq1 + , typename Seq2 + , typename BinaryOp + , typename In = |unspecified| + > + struct transform + { + typedef |unspecified| type; + }; + + +Description +----------- + +``transform`` is an |overloaded name|: + +* ``transform`` returns a transformed copy of the original sequence + produced by applying an unary transformation ``Op`` to every element + in the |begin/end| range. + +* ``transform`` returns a new sequence produced by applying a + binary transformation ``BinaryOp`` to a pair of elements (e\ :sub:`1`, e2\ :sub:`1`) + from the corresponding |begin/end| and |begin/end| ranges. + +|transformation algorithm disclaimer| + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Reversible Algorithm| + + +Parameters +---------- + ++-------------------+-----------------------------------+-----------------------------------+ +| Parameter | Requirement | Description | ++===================+===================================+===================================+ +| ``Sequence``, | |Forward Sequence| | Sequences to transform. | +| ``Seq1``, ``Seq2``| | | ++-------------------+-----------------------------------+-----------------------------------+ +| ``Op``, | |Lambda Expression| | A transformation. | +| ``BinaryOp`` | | | ++-------------------+-----------------------------------+-----------------------------------+ +| ``In`` | |Inserter| | An inserter. | ++-------------------+-----------------------------------+-----------------------------------+ + + +Expression semantics +-------------------- + +|Semantics disclaimer...| |Reversible Algorithm|. + +For any |Forward Sequence|\ s ``s``, ``s1`` and ``s2``, |Lambda Expression|\ s ``op`` and ``op2``, +and an |Inserter| ``in``: + +.. parsed-literal:: + + typedef transform::type r; + +:Return type: + A type. + +:Postcondition: + Equivalent to + + .. parsed-literal:: + + typedef lambda::type f; + typedef lambda::type in_op; + + typedef fold< + s + , in::state + , bind< in_op, _1, bind > + >::type r; + + +.. parsed-literal:: + + typedef transform::type r; + +:Return type: + A type. + +:Postcondition: + Equivalent to + + .. parsed-literal:: + + typedef lambda::type f; + typedef lambda::type in_op; + + typedef fold< + pair_view + , in::state + , bind< + in_op + , _1 + , bind,_2>, bind,_2> > + > + >::type r; + + +Complexity +---------- + +Linear. Exactly ``size::value`` / ``size::value`` applications of +``op`` / ``op2`` and ``in::operation``. + + +Example +------- + +.. parsed-literal:: + + typedef vector types; + typedef vector pointers; + typedef transform< types,boost::add_pointer<_1> >::type result; + + BOOST_MPL_ASSERT(( equal )); + + +See also +-------- + +|Transformation Algorithms|, |Reversible Algorithm|, |reverse_transform|, |copy|, |replace_if| diff --git a/doc/src/refmanual/transform_view.rst b/doc/src/refmanual/transform_view.rst new file mode 100644 index 0000000..0d735f5 --- /dev/null +++ b/doc/src/refmanual/transform_view.rst @@ -0,0 +1,95 @@ +.. Sequences/Views//transform_view + +transform_view +============== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + , typename F + > + struct transform_view + { + // |unspecified| + // |...| + }; + + +Description +----------- + +A view the full range of ``Sequence``\ 's transformed elements. + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +* |Forward Sequence| + + +Parameters +---------- + ++---------------+-------------------------------+-------------------------------+ +| Parameter | Requirement | Description | ++===============+===============================+===============================+ +| ``Sequence`` | |Forward Sequence| | A sequence to wrap. | ++---------------+-------------------------------+-------------------------------+ +| ``F`` | Unary |Lambda Expression| | A transformation. | ++---------------+-------------------------------+-------------------------------+ + + +Expression semantics +-------------------- + +|Semantics disclaimer...| |Forward Sequence|. + +In the following table, ``v`` is an instance of ``transform_view``, ``s`` is an arbitrary +|Forward Sequence|, and ``f`` is an unary |Lambda Expression|. + ++-----------------------------------+-----------------------------------------------------------+ +| Expression | Semantics | ++===================================+===========================================================+ +| .. parsed-literal:: | A lazy |Forward Sequence| such that for each ``i`` in the | +| | range |begin/end| and each ``j`` in for in the range | +| transform_view | |begin/end| ``deref::type`` is identical to | +| transform_view::type | ``apply< f, deref::type >::type``. | ++-----------------------------------+-----------------------------------------------------------+ +| ``size::type`` | The size of ``v``; | +| | ``size::value == size::value``; | +| | linear complexity; see |Forward Sequence|. | ++-----------------------------------+-----------------------------------------------------------+ + + +Example +------- + +Find the largest type in a sequence. + +.. parsed-literal:: + + typedef vector types; + typedef max_element< + transform_view< types, size_of<_> > + >::type iter; + + BOOST_MPL_ASSERT_RELATION( deref::type::value, ==, 50 ); + + +See also +-------- + +|Sequences|, |Views|, |filter_view|, |joint_view|, |zip_view|, |iterator_range| + diff --git a/doc/src/refmanual/unique.rst b/doc/src/refmanual/unique.rst new file mode 100644 index 0000000..80bc551 --- /dev/null +++ b/doc/src/refmanual/unique.rst @@ -0,0 +1,126 @@ +.. Algorithms/Transformation Algorithms//unique |80 + +unique +====== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Seq + , typename Pred + , typename In = |unspecified| + > + struct unique + { + typedef |unspecified| type; + }; + + +Description +----------- + +Returns a sequence of the initial elements of every subrange of the +original sequence ``Seq`` whose elements are all the same. + +|transformation algorithm disclaimer| + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Reversible Algorithm| + + +Parameters +---------- + ++---------------+-----------------------------------+-------------------------------+ +| Parameter | Requirement | Description | ++===============+===================================+===============================+ +| ``Sequence`` | |Forward Sequence| | An original sequence. | ++---------------+-----------------------------------+-------------------------------+ +| ``Pred`` | Binary |Lambda Expression| | An equivalence relation. | ++---------------+-----------------------------------+-------------------------------+ +| ``In`` | |Inserter| | An inserter. | ++---------------+-----------------------------------+-------------------------------+ + + +Expression semantics +-------------------- + +|Semantics disclaimer...| |Reversible Algorithm|. + +For any |Forward Sequence| ``s``, a binary |Lambda Expression| ``pred``, +and an |Inserter| ``in``: + + +.. parsed-literal:: + + typedef unique::type r; + +:Return type: + A type. + +:Semantics: + If ``size::value <= 1``, then equivalent to + + .. parsed-literal:: + + typedef copy::type r; + + otherwise equivalent to + + .. parsed-literal:: + + typedef lambda::type p; + typedef lambda::type in_op; + typedef apply_wrap\ ``2``\< + in_op + , in::state + , front::type + >::type in_state; + + typedef fold< + s + , pair< in_state, front::type > + , eval_if< + apply_wrap\ ``2``\, _2> + , identity< first<_1> > + , apply_wrap\ ``2``\, _2> + > + >::type::first r; + + +Complexity +---------- + +Linear. Performs exactly ``size::value - 1`` applications of ``pred``, and at +most ``size::value`` insertions. + + +Example +------- + +.. parsed-literal:: + + typedef vector types; + typedef vector expected; + typedef unique< types, is_same<_1,_2> >::type result; + + BOOST_MPL_ASSERT(( equal< result,expected > )); + + +See also +-------- + +|Transformation Algorithms|, |Reversible Algorithm|, |reverse_unique|, |remove|, |copy_if|, |replace_if| diff --git a/doc/src/refmanual/unpack_args.rst b/doc/src/refmanual/unpack_args.rst new file mode 100644 index 0000000..6984593 --- /dev/null +++ b/doc/src/refmanual/unpack_args.rst @@ -0,0 +1,93 @@ +.. Metafunctions/Invocation//unpack_args |30 + +unpack_args +=========== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename F + > + struct unpack_args + { + // |unspecified| + // |...| + }; + + +Description +----------- + +A higher-order primitive transforming an *n*-ary |Lambda Expression| ``F`` into +an unary |Metafunction Class| ``g`` accepting a single sequence of *n* arguments. + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Metafunction Class| + + +Parameters +---------- + ++---------------+-----------------------+-------------------------------------------+ +| Parameter | Requirement | Description | ++===============+=======================+===========================================+ +| ``F`` | |Lambda Expression| | A lambda expression to adopt. | ++---------------+-----------------------+-------------------------------------------+ + + +Expression semantics +-------------------- + +For an arbitrary |Lambda Expression| ``f``, and arbitrary types |a1...an|: + + +.. parsed-literal:: + + typedef unpack_args g; + +:Return type: + |Metafunction Class|. + +:Semantics: + ``g`` is a unary |Metafunction Class| such that + + .. parsed-literal:: + + apply_wrap\ *n*\ < g, vector >::type + + is identical to + + .. parsed-literal:: + + apply::type + + +Example +------- + +.. parsed-literal:: + + BOOST_MPL_ASSERT(( apply< + unpack_args< is_same<_1,_2> > + , vector + > )); + + +See also +-------- + +|Metafunctions|, |Lambda Expression|, |Metafunction Class|, |apply|, |apply_wrap|, |bind| diff --git a/doc/src/refmanual/upper_bound.rst b/doc/src/refmanual/upper_bound.rst new file mode 100644 index 0000000..df17666 --- /dev/null +++ b/doc/src/refmanual/upper_bound.rst @@ -0,0 +1,103 @@ +.. Algorithms/Querying Algorithms//upper_bound |70 + +upper_bound +=========== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + , typename T + , typename Pred = less<_1,_2> + > + struct upper_bound + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns the last position in the sorted ``Sequence`` where ``T`` could be inserted without +violating the ordering. + + +Header +------ + +.. parsed-literal:: + + #include + + + +Parameters +---------- + ++---------------+-------------------------------+-----------------------------------+ +| Parameter | Requirement | Description | ++===============+===============================+===================================+ +|``Sequence`` | |Forward Sequence| | A sorted sequence to search in. | ++---------------+-------------------------------+-----------------------------------+ +|``T`` | Any type | A type to search a position for. | ++---------------+-------------------------------+-----------------------------------+ +|``Pred`` | Binary |Lambda Expression| | A search criteria. | ++---------------+-------------------------------+-----------------------------------+ + + +Expression semantics +-------------------- + +For any sorted |Forward Sequence| ``s``, binary |Lambda Expression| ``pred``, and +arbitrary type ``x``: + + +.. parsed-literal:: + + typedef upper_bound< s,x,pred >::type i; + +:Return type: + |Forward Iterator| + +:Semantics: + ``i`` is the furthermost iterator in |begin/end| such that, for every iterator + ``j`` in ``[begin::type, i)``, + + .. parsed-literal:: + + apply< pred, x, deref::type >::type::value == false + + +Complexity +---------- + +The number of comparisons is logarithmic: at most log\ :sub:`2`\ ( ``size::value`` ) + 1. +If ``s`` 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::value``. + + +Example +------- + +.. parsed-literal:: + + typedef vector_c numbers; + typedef upper_bound< numbers, int_<3> >::type iter; + + BOOST_MPL_ASSERT_RELATION( + (distance< begin::type,iter >::value), ==, 5 + ); + + BOOST_MPL_ASSERT_RELATION( deref::type::value, ==, 5 ); + + +See also +-------- + +|Querying Algorithms|, |lower_bound|, |find|, |find_if|, |min_element| diff --git a/doc/src/refmanual/value_type.rst b/doc/src/refmanual/value_type.rst new file mode 100644 index 0000000..7e81658 --- /dev/null +++ b/doc/src/refmanual/value_type.rst @@ -0,0 +1,109 @@ +.. Sequences/Intrinsic Metafunctions//value_type + +value_type +========== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequence + , typename X + > + struct value_type + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns the |value| that would be used for element ``X`` in ``Sequence``. + + +Header +------ + +.. parsed-literal:: + + #include + + +Model of +-------- + +|Tag Dispatched Metafunction| + + +Parameters +---------- + ++---------------+---------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===========================+===============================================+ +| ``Sequence`` | |Associative Sequence| | A sequence to query. | ++---------------+---------------------------+-----------------------------------------------+ +| ``X`` | Any type | The type to get the |value| for. | ++---------------+---------------------------+-----------------------------------------------+ + + +Expression semantics +-------------------- + +For any |Associative Sequence| ``s``, and an artibrary type ``x``: + + +.. parsed-literal:: + + typedef value_type::type v; + +:Return type: + A type. + +:Precondition: + ``x`` can be put in ``s``. + +:Semantics: + ``v`` is the |value| that would be used for ``x`` in ``s``. + +:Postcondition: + If + .. parsed-literal:: + + has_key< s,key_type::type >::type + + then + .. parsed-literal:: + + at< s,key_type::type >::type + + is identical to ``value_type::type``. + + + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + typedef value_type< map<>,pair >::type v1; + typedef value_type< set<>,pair >::type v2; + + BOOST_MPL_ASSERT(( is_same< v1,unsigned > )); + BOOST_MPL_ASSERT(( is_same< v2,pair > )); + + +See also +-------- + +|Associative Sequence|, |key_type|, |at|, |set|, |map| diff --git a/doc/src/refmanual/vector.rst b/doc/src/refmanual/vector.rst new file mode 100644 index 0000000..74a1748 --- /dev/null +++ b/doc/src/refmanual/vector.rst @@ -0,0 +1,131 @@ +.. Sequences/Classes//vector |10 + +vector +====== + +Description +----------- + +``vector`` is a |variadic|, `random access`__, `extensible`__ sequence of types that +supports constant-time insertion and removal of elements at both ends, and +linear-time insertion and removal of elements in the middle. On compilers that +support the ``typeof`` extension, ``vector`` is the simplest and in many cases the +most efficient sequence. + +__ `Random Access Sequence`_ +__ `Extensible Sequence`_ + +Header +------ + ++-------------------+-------------------------------------------------------+ +| Sequence form | Header | ++===================+=======================================================+ +| Variadic | ``#include `` | ++-------------------+-------------------------------------------------------+ +| Numbered | ``#include `` | ++-------------------+-------------------------------------------------------+ + +Model of +-------- + +* |Variadic Sequence| +* |Random Access Sequence| +* |Extensible Sequence| +* |Back Extensible Sequence| +* |Front Extensible Sequence| + + +Expression semantics +-------------------- + +In the following table, ``v`` is an instance of ``vector``, ``pos`` and ``last`` are iterators +into ``v``, ``r`` is a |Forward Sequence|, ``n`` is an |Integral Constant|, and ``x`` and +|t1...tn| are arbitrary types. + ++---------------------------------------+-----------------------------------------------------------+ +| Expression | Semantics | ++=======================================+===========================================================+ +| .. parsed-literal:: | ``vector`` of elements |t1...tn|; see | +| | |Variadic Sequence|. | +| vector<|t1...tn|> | | +| vector\ *n*\ <|t1...tn|> | | ++---------------------------------------+-----------------------------------------------------------+ +| .. parsed-literal:: | Identical to ``vector``\ *n*\ ``<``\ |t1...tn|\ ``>``; | +| | see |Variadic Sequence|. | +| vector<|t1...tn|>::type | | +| vector\ *n*\ <|t1...tn|>::type | | ++---------------------------------------+-----------------------------------------------------------+ +| ``begin::type`` | An iterator pointing to the beginning of ``v``; | +| | see |Random Access Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``end::type`` | An iterator pointing to the end of ``v``; | +| | see |Random Access Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``size::type`` | The size of ``v``; see |Random Access Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``empty::type`` | |true if and only if| the sequence is empty; | +| | see |Random Access Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``front::type`` | The first element in ``v``; see | +| | |Random Access Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``back::type`` | The last element in ``v``; see | +| | |Random Access Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``at::type`` | The ``n``\ th element from the beginning of ``v``; see | +| | |Random Access Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``insert::type`` | A new ``vector`` of following elements: | +| | [``begin::type``, ``pos``), ``x``, | +| | [``pos``, ``end::type``); see |Extensible Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``insert_range::type`` | A new ``vector`` of following elements: | +| | [``begin::type``, ``pos``), | +| | [``begin::type``, ``end::type``) | +| | [``pos``, ``end::type``); see |Extensible Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``erase::type`` | A new ``vector`` of following elements: | +| | [``begin::type``, ``pos``), | +| | [``next::type``, ``end::type``); see | +| | |Extensible Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``erase::type`` | A new ``vector`` of following elements: | +| | [``begin::type``, ``pos``), | +| | [``last``, ``end::type``); see |Extensible Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``clear::type`` | An empty ``vector``; see |Extensible Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``push_back::type`` | A new ``vector`` of following elements: | +| | |begin/end|, ``x``; | +| | see |Back Extensible Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``pop_back::type`` | A new ``vector`` of following elements: | +| | [``begin::type``, ``prior< end::type >::type``); | +| | see |Back Extensible Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``push_front::type`` | A new ``vector`` of following elements: | +| | |begin/end|, ``x``; see |Front Extensible Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ +| ``pop_front::type`` | A new ``vector`` of following elements: | +| | [``next< begin::type >::type``, ``end::type``); | +| | see |Front Extensible Sequence|. | ++---------------------------------------+-----------------------------------------------------------+ + + +Example +------- + +.. parsed-literal:: + + typedef vector floats; + typedef push_back::type types; + + BOOST_MPL_ASSERT(( |is_same|\< at_c::type, int > )); + + +See also +-------- + +|Sequences|, |Variadic Sequence|, |Random Access Sequence|, |Extensible Sequence|, |vector_c|, |list| + diff --git a/doc/src/refmanual/vector_c.rst b/doc/src/refmanual/vector_c.rst new file mode 100644 index 0000000..097d6d1 --- /dev/null +++ b/doc/src/refmanual/vector_c.rst @@ -0,0 +1,82 @@ +.. Sequences/Classes//vector_c |70 + +vector_c +======== + +Description +----------- + +``vector_c`` is an |Integral Sequence Wrapper| for |vector|. As such, it shares +all |vector| characteristics and requirements, and differs only in the way the +original sequence content is specified. + +Header +------ + ++-------------------+-----------------------------------------------------------+ +| Sequence form | Header | ++===================+===========================================================+ +| Variadic | ``#include `` | ++-------------------+-----------------------------------------------------------+ +| Numbered | ``#include `` | ++-------------------+-----------------------------------------------------------+ + + +Model of +-------- + +* |Integral Sequence Wrapper| +* |Variadic Sequence| +* |Random Access Sequence| +* |Extensible Sequence| +* |Back Extensible Sequence| +* |Front Extensible Sequence| + + +Expression semantics +-------------------- + +|Semantics disclaimer...| |vector|. + +.. workaround substitution bug (should be replace:: vector\ *n*\ _c) +.. |vectorn_c| replace:: vector\ *n*\ _c + ++-------------------------------------------+-----------------------------------------------+ +| Expression | Semantics | ++===========================================+===============================================+ +| .. parsed-literal:: | A |vector| of integral constant wrappers | +| | ``integral_c``, | +| vector_c | ``integral_c``, ... | +| |vectorn_c| | ``integral_c``; | +| | see |Integral Sequence Wrapper|. | ++-------------------------------------------+-----------------------------------------------+ +| .. parsed-literal:: | Identical to ``vector``\ *n*\ ``<`` | +| | ``integral_c``, | +| vector_c::type | ``integral_c``, ... | +| |vectorn_c|::type | ``integral_c`` ``>``; | +| | see |Integral Sequence Wrapper|. | ++-------------------------------------------+-----------------------------------------------+ +| .. parsed-literal:: | Identical to ``T``; see | +| | |Integral Sequence Wrapper|. | +| vector_c::value_type | | +| |vectorn_c|::value_type | | ++-------------------------------------------+-----------------------------------------------+ + + +Example +------- + +.. parsed-literal:: + + typedef vector_c fibonacci; + typedef push_back >::type fibonacci2; + + BOOST_MPL_ASSERT_RELATION( front::type::value, ==, 1 ); + BOOST_MPL_ASSERT_RELATION( back::type::value, ==, 50 ); + + +See also +-------- + +|Sequences|, |Integral Sequence Wrapper|, |vector|, |integral_c|, |set_c|, |list_c|, |range_c| + diff --git a/doc/src/refmanual/void_.rst b/doc/src/refmanual/void_.rst new file mode 100644 index 0000000..b4eacd8 --- /dev/null +++ b/doc/src/refmanual/void_.rst @@ -0,0 +1,40 @@ +.. Data Types/Miscellaneous//void_ |100 + +void\_ +====== + +Synopsis +-------- + +.. parsed-literal:: + + struct void\_ + { + typedef void\_ type; + }; + + template< typename T > struct is_void; + + +Description +----------- + +``void_`` is a generic type placeholder representing "nothing". + +.. In many cases, returning ``void_`` from a metafunction to signal + an absence of the requested data leads to a simpler user code than + having a separate metafunction specifically for the purpose of + performing the corresponding check. + +Header +------ + +.. parsed-literal:: + + #include + + +See also +-------- + +|Data Types|, |pair|, |empty_base|, |bool_|, |int_|, |integral_c| diff --git a/doc/src/refmanual/zip_view.rst b/doc/src/refmanual/zip_view.rst new file mode 100644 index 0000000..5831c41 --- /dev/null +++ b/doc/src/refmanual/zip_view.rst @@ -0,0 +1,105 @@ +.. Sequences/Views//zip_view + +zip_view +======== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename Sequences + > + struct zip_view + { + // |unspecified| + // |...| + }; + + + +Description +----------- + +Provides a "zipped" view onto several sequences; that is, represents several +sequences as a single sequence of elements each of which, in turn, +is a sequence of the corresponding ``Sequences``\ ' elements. + + +Header +------ + +.. parsed-literal:: + + #include + + + +Model of +-------- + +* |Forward Sequence| + + +Parameters +---------- + ++---------------+-----------------------------------+-------------------------------+ +| Parameter | Requirement | Description | ++===============+===================================+===============================+ +| ``Sequences`` | A |Forward Sequence| of | Sequences to be "zipped". | +| | |Forward Sequence|\ s | | ++---------------+-----------------------------------+-------------------------------+ + +Expression semantics +-------------------- + +|Semantics disclaimer...| |Forward Sequence|. + +In the following table, ``v`` is an instance of ``zip_view``, ``seq`` a |Forward Sequence| of ``n`` +|Forward Sequence|\ s. + ++-------------------------------+-----------------------------------------------------------+ +| Expression | Semantics | ++===============================+===========================================================+ +| .. parsed-literal:: | A lazy |Forward Sequence| ``v`` such that for each ``i`` | +| | in |begin/end| and for each ``j`` in | +| zip_view | [``begin::type``, ``end::type``) | +| zip_view::type | ``deref::type`` is identical to | +| | ``transform< deref::type, deref<_1> >::type``. | ++-------------------------------+-----------------------------------------------------------+ +| ``size::type`` | The size of ``v``; ``size::value`` is equal to | +| | :: | +| | | +| | deref< min_element< | +| | transform_view< seq, size<_1> > | +| | >::type >::type::value; | +| | | +| | linear complexity; see |Forward Sequence|. | ++-------------------------------+-----------------------------------------------------------+ + + +Example +------- + +Element-wise sum of three vectors. + +.. parsed-literal:: + + typedef vector_c v1; + typedef vector_c v2; + typedef vector_c v3; + + typedef transform_view< + zip_view< vector > + , unpack_args< plus<_1,_2,_3> > + > sum; + + BOOST_MPL_ASSERT(( equal< sum, vector_c > )); + + +See also +-------- + +|Sequences|, |Views|, |filter_view|, |transform_view|, |joint_view|, |single_view|, |iterator_range|