#include <functional> template < typename InputIterator, typename OutputIterator, typename UnaryOperation, typename UnaryPredicate > OutputIterator transform_if( InputIterator first, InputIterator last, OutputIterator result, UnaryPredicate pred, UnaryOperation op) { while (first != last) { if (pred(*first)) *result = op(*first); ++first; ++result; } return (result); } template<class _Ty> struct binary_and : public std::binary_function<_Ty, _Ty, bool> { result_type operator()(const first_argument_type& _Left, const second_argument_type& _Right) const { return (_Left & _Right) ? true : false; } }; int main() { const size_t N = 10; int A[N] = {0,1,2,3,4,5,6,7,8,9}; transform_if(A, A+N, A, std::bind2nd(binary_and<int>(), 1), std::bind2nd(std::plus<int>(), 1)); return (0); } |