.. 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|