diff --git a/doc/ref/Integral_constant_classes.html b/doc/ref/Integral_constant_classes.html new file mode 100644 index 0000000..fdc082b --- /dev/null +++ b/doc/ref/Integral_constant_classes.html @@ -0,0 +1,19 @@ + +
+
+A metafunction class is a certain form of metafunction representation that enables higher-order metaprogramming. In particular, a non-nullary metafunction class is a type with a nested class template member apply
. A nullary metafunction class has the form of a nullary metafunction. A metafunction class invocation is defined as invocation of its nested apply
metafunction.
+
+
+
Expression | Expression type |
---|---|
typename f::type | A type |
typename f::template apply<a1,..,an>::type | A type |
+
+
Expression | Complexity | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typename f::type | unspecified | f is a nullary metafunction class; f::type is a type-name | f::type is the result of the metafunction class invocation | |
typename f::template apply<a1,..,an>::type | unspecified | f is an n -ary metafunction class; apply is a metafunction | typename f::template apply<a1,..,an>::type is the result of the metafunction class invocation with the actual arguments a1,..,an |
+
+
+
+// nullary metafunction class +struct always_true { typedef true_ type; }; +++template< long N > struct le +{ + template< typename M > struct apply + { + typedef bool_< (M::value < N) > type; + }; +}; +
+// unary metafunction class +typedef le<5> less_than_5; +
+// binary metafunction class +struct less_than +{ + template< typename N1, typename N2 > struct apply + { + typedef bool_< (N1::value < N2::value) > type; + }; +}; +
+// invocations +typedef always_true::type t1; +typedef less_than_5::apply< int_<7> >::type t2; +typedef less_than::apply< int_<5>,int_<7> >::type t3; +
+// results checks +BOOST_STATIC_ASSERT(t1::value); +BOOST_STATIC_ASSERT(!t2::value); +BOOST_STATIC_ASSERT(t3::value); +
+
+Metafunctions, Metafunction +
+
+template< + typename F1 + , typename F2 + , typename F3 = true_ + ... + , typename Fn = true_ + > +struct and_ +{ + typedef unspecified type; +}; ++
+
+Returns the result of short-circuit logical and (&&
) operation on its arguments.
+
+
+
+#include "boost/mpl/and.hpp" ++
+
Parameter | Requirement | Description |
---|---|---|
F1, F2, .., Fn | A model of nullary Metafunction |
+
+
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef and_<f1,f2,..,fn>::type c; | A model of bool Integral Constant | Returns false_ if either of f1::type::value, f2::type::value, .., fn::type::value expressions evaluates to false , and true_ otherwise; guarantees left-to-right evaluation; moreover, the operands subsequent to the first fi metafunction that evaluates to false are not evaluated. |
+
+
+// will generate compile-time error if invoked with T == any fundamental type +template< typename T > struct fail +{ + typedef typename T::nonexistent type; +}; +++BOOST_STATIC_ASSERT((and_< true_,false_ >::type::value == false)); +BOOST_STATIC_ASSERT((and_< false_,fail<int> >::type::value == false)); // OK, fail<int> is never invoked +BOOST_STATIC_ASSERT((and_< true_,false_,fail<int> >::type::value == false)); // OK too +
+
+Metafunctions, or_
, not_
+
+
+template< + typename Iterator + > +struct deref +{ + typedef typename Iterator::type type; +}; ++
+
+Dereferences an iterator. +
+
+
+#include "boost/mpl/deref.hpp" ++
+
Parameter | Requirement | Description |
---|---|---|
Iterator | A model of Trivial Iterator | An iterator to be dereferenced. |
+
+
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef deref<Iterator>::type t; | A type | Equivalent to typedef Iterator::type t; . | Iterator is dereferenceable |
+
+Amortized constant time. +
+
+
+typedef list<char,short,int,long> types; +typedef begin<types>::type iter; +BOOST_STATIC_ASSERT(boost::is_same< deref<iter>::type,char >::value)); ++
+
+
+template<
+ typename Sequence1
+ , typename Sequence2
+ >
+struct joint_view
+{
+ // unspecified
+};
+
++
+joint_view
is a two-sequence view that allows one to operate on a sequence of concatenated elements of sequences Sequence1
and Sequence2
without actually creating one.
+
+
+
+#include "boost/mpl/joint_view.hpp" ++
+
Parameter | Requirement | Description |
---|---|---|
Sequence1 , Sequence2 | A model of Sequence | Sequences to concatenate. |
+
+
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef joint_view<Sequence1,Sequence2> s; | A model of Sequence | s prodives iterators to all the elements in the ranges [begin<Sequence1>::type,end<Sequence1>::type) , [begin<Sequence2>::type,end<Sequence2>::type) . | size<s>::type::value == size< Sequence1 >::type::value + size< Sequence2 >::type::value . |
+
+Amortized constant time. +
+
+
+typedef joint_view< + range_c<int,0,10> + , range_c<int,10,15> + > numbers; +++typedef range_c<int,0,15> answer; +BOOST_STATIC_ASSERT((equal<numbers,answer>::type::value)); +
+
+Sequences, transform_view
, filter_view
, zip_view
+
+
+template< + typename Sequence + , typename Pred = less<_1,_2> + > +struct max_element +{ + typedef unspecified type; +}; ++
+
+Finds the largest element in the Sequence
.
+
+
+
+#include "boost/mpl/max_element.hpp" ++
+
Parameter | Requirement | Description |
---|---|---|
Sequence | A model of Forward Sequence | A sequence to be searched. |
Pred | A model of binary Predicate [Lambda Expression] | A comparison criteria. |
+
+
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef max_element< Sequence,Pred >::type i; | A model of Forward Iterator | i is the first iterator in [begin<Sequence>::type, end<Sequence>::type) such that for every iterator j in [begin<Sequence>::type, end<Sequence>::type) , apply< lambda<Pred>::type, i::type, j::type >::type::value == false . |
+
+Linear. Zero comparisons if Sequence
is empty, otherwise exactly size<Sequence>::value - 1
comparisons.
+
+
+
+typedef vector<int,char[50],long,double> types; +typedef max_element< + transform_view< types,sizeof_<_1> > + >::type iter; +++BOOST_STATIC_ASSERT((distance< begin<types>::type,iter >::type::value == 1)); +BOOST_STATIC_ASSERT(sizeof(deref<iter>::type) == 50); +
+
+Algorithms, min_element
, upper_bound
, lower_bound
+
+
+template< + typename Sequence + , typename Pred = less<_1,_2> + > +struct min_element +{ + typedef unspecified type; +}; ++
+
+Finds the smallest element in the Sequence
.
+
+
+
+#include "boost/mpl/min_element.hpp" ++
+
Parameter | Requirement | Description |
---|---|---|
Sequence | A model of Forward Sequence | A sequence to be searched. |
Pred | A model of binary Predicate [Lambda Expression] | A comparison criteria. |
+
+
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef min_element< Sequence,Pred >::type i; | A model of Forward Iterator | i is the first iterator in [begin<Sequence>::type, end<Sequence>::type) such that for every iterator j in [begin<Sequence>::type, end<Sequence>::type) , apply< lambda<Pred>::type, j::type, i::type >::type::value == false . |
+
+Linear. Zero comparisons if Sequence
is empty, otherwise exactly size<Sequence>::value - 1
comparisons.
+
+
+
+typedef vector<bool,char[50],long,double> types; +typedef min_element< + transform_view< types,sizeof_<_1> > + >::type iter; +++BOOST_STATIC_ASSERT((distance< begin<types>::type,iter >::type::value == 0)); +BOOST_STATIC_ASSERT(sizeof(deref<iter>::type) == sizeof(bool)); +
+
+Algorithms, max_element
, upper_bound
, lower_bound
+
+
+template< + typename F + > +struct not_ +{ + typedef unspecified type; +}; ++
+
+Returns the result of logical not (!
) operation on its argument.
+
+
+
+#include "boost/mpl/not.hpp" ++
+
Parameter | Requirement | Description |
---|---|---|
F | A model of nullary Metafunction |
+
+
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef not_<f>::type c; | A model of bool Integral Constant | Equivalent to typedef bool_<(!f::type::value)> c; |
+
+
+BOOST_STATIC_ASSERT(not_<true_>::type::value == false); +BOOST_STATIC_ASSERT(not_<false_>::type::value == true); ++
+
+Metafunctions, and_
, or_
+
+
+template< + typename F1 + , typename F2 + , typename F3 = false_ + ... + , typename Fn = false_ + > +struct or_ +{ + typedef unspecified type; +}; ++
+
+Returns the result of short-circuit logical or (||
) operation on its arguments.
+
+
+
+#include "boost/mpl/or.hpp" ++
+
Parameter | Requirement | Description |
---|---|---|
F1, F2, .., Fn | A model of nullary Metafunction |
+
+
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef or_<f1,f2,..,fn>::type c; | A model of bool Integral Constant | Returns true_ if either of f1::type::value, f2::type::value, .., fn::type::value expressions evaluates to true, and false_ otherwise; guarantees left-to-right evaluation; moreover, the operands subsequent to the first fi metafunction that evaluates to true are not evaluated. |
+
+
+// will generate compile-time error if invoked with T == any fundamental type +template< typename T > struct fail +{ + typedef typename T::nonexistent type; +}; +++BOOST_STATIC_ASSERT((or_< false_,true_ >::type::value == true)); +BOOST_STATIC_ASSERT((or_< true_,fail<int> >::type::value == true)); // OK, fail<int> is never invoked +BOOST_STATIC_ASSERT((or_< false_,true_,fail<int> >::type::value == true)); // OK too +
+
+Metafunctions, and_
, not_
+
+
+template<
+ typename T
+ >
+struct single_view
+{
+ // unspecified
+};
+
++
+Allows one to represent an arbitrary type T
as a single-element sequence.
+
+
+
+#include "boost/mpl/single_view.hpp" ++
+
Parameter | Requirement | Description |
---|---|---|
T | A type | The type to be wrapped in a sequence. |
+
+
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef single_view<T> s; | A model of Sequence | s is a random-access, single-element sequence such as front<s>::type is identical to T | size<s>::type::value == 1, boost::same_as<front<s>::type,T>::value == true . |
+
+Amortized constant time. +
+
+
+typedef single_view<int> view; +typedef begin<view>::type first; +typedef end<view>::type last; +++BOOST_MPL_ASSERT_IS_SAME(first::type,int); +BOOST_MPL_ASSERT_IS_SAME(first::next,last); +BOOST_MPL_ASSERT_IS_SAME(last::prior,first); +
+BOOST_STATIC_ASSERT(size<view>::type::value == 1); +
+
+Sequences, transform_view
, filter_view
, joint_view
, zip_view
+
+
+template<
+ typename Sequences
+ >
+struct zip_view
+{
+ // unspecified
+};
+
++
+zip_view
provides a "zipped" view onto several sequences; that is, it allows to represent several sequences as a single sequence of elements each of those, in its turn, is a sequence of the corresponding Sequences
elements.
+
+
+
+#include "boost/mpl/zip_view.hpp" ++
+
Parameter | Requirement | Description |
---|---|---|
Sequences | A Sequence of Sequences | Sequences to be "zipped". |
+
+
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef zip_view<Sequences> s; | A model of Sequence | s is a sequence such that for each i in [begin<s>::type, end<s>::type) and for each j in [begin<Sequences>::type, end<Sequences>::type) i::type is identical to transform<j::type, deref<_1> >::type . |
+
+Amortized constant time. +
+
+
+typedef range_c<int,0,10> s1; +typedef range_c<int,10,20> s2; +++typedef transform_view< + zip_view< list<s1,s2> > + , apply_seq< plus<_1,_2> > + > result; +
+BOOST_STATIC_ASSERT((equal< + result + , filter_view< range_c<int,10,30>, math::is_even<_1> > + , equal_to<_1,_2> + >::type::value)); +
+
+Sequences, transform_view
, filter_view
, joint_view
, equal
+