Front Page / Algorithms / Transformation Algorithms / copy_if |
template< typename Sequence , typename Pred , typename In = unspecified > struct copy_if { typedef unspecified type; };
Returns a filtered copy of the original sequence containing the elements that satisfy the predicate Pred.
[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]
#include <boost/mpl/copy_if.hpp>
Parameter | Requirement | Description |
---|---|---|
Sequence | Forward Sequence | A sequence to copy. |
Pred | Unary Lambda Expression | A copying condition. |
In | Inserter | An inserter. |
The semantics of an expression are defined only where they differ from, or are not defined in Reversible Algorithm.
For any Forward Sequence s, an unary Lambda Expression pred, and an Inserter in:
typedef copy_if<s,pred,in>::type r;
Return type: | A type. |
---|---|
Semantics: | Equivalent to typedef lambda<pred>::type p; typedef lambda<in::operation>::type op; typedef fold< s , in::state , eval_if< apply_wrap1<p,_2> , apply_wrap2<op,_1,_2> , identity<_1> > >::type r; |
Linear. Exactly size<s>::value applications of pred, and at most size<s>::value applications of in::operation.
typedef copy_if< range_c<int,0,10> , less< _1, int_<5> > , back_inserter< vector<> > >::type result; BOOST_MPL_ASSERT_RELATION( size<result>::value, ==, 5 ); BOOST_MPL_ASSERT(( equal<result,range_c<int,0,5> > ));