Chris@16: // Copyright Neil Groves 2009. Use, modification and Chris@16: // distribution is subject to the Boost Software License, Version Chris@16: // 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: // Chris@16: // For more information, see http://www.boost.org/libs/range/ Chris@16: // Chris@16: #ifndef BOOST_RANGE_ALGORITHM_TRANSFORM_HPP_INCLUDED Chris@16: #define BOOST_RANGE_ALGORITHM_TRANSFORM_HPP_INCLUDED Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost Chris@16: { Chris@16: namespace range Chris@16: { Chris@16: Chris@16: /// \brief template function transform Chris@16: /// Chris@16: /// range-based version of the transform std algorithm Chris@16: /// Chris@16: /// \pre SinglePassRange1 is a model of the SinglePassRangeConcept Chris@16: /// \pre SinglePassRange2 is a model of the SinglePassRangeConcept Chris@16: /// \pre OutputIterator is a model of the OutputIteratorConcept Chris@16: /// \pre UnaryOperation is a model of the UnaryFunctionConcept Chris@16: /// \pre BinaryOperation is a model of the BinaryFunctionConcept Chris@16: template< class SinglePassRange1, Chris@16: class OutputIterator, Chris@16: class UnaryOperation > Chris@16: inline OutputIterator Chris@16: transform(const SinglePassRange1& rng, Chris@16: OutputIterator out, Chris@16: UnaryOperation fun) Chris@16: { Chris@16: BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); Chris@16: return std::transform(boost::begin(rng),boost::end(rng),out,fun); Chris@16: } Chris@16: Chris@16: } // namespace range Chris@16: Chris@16: namespace range_detail Chris@16: { Chris@16: template< class SinglePassTraversalReadableIterator1, Chris@16: class SinglePassTraversalReadableIterator2, Chris@16: class OutputIterator, Chris@16: class BinaryFunction > Chris@16: inline OutputIterator Chris@16: transform_impl(SinglePassTraversalReadableIterator1 first1, Chris@16: SinglePassTraversalReadableIterator1 last1, Chris@16: SinglePassTraversalReadableIterator2 first2, Chris@16: SinglePassTraversalReadableIterator2 last2, Chris@16: OutputIterator out, Chris@16: BinaryFunction fn) Chris@16: { Chris@101: for (; first1 != last1 && first2 != last2; ++first1, ++first2) Chris@16: { Chris@16: *out = fn(*first1, *first2); Chris@16: ++out; Chris@16: } Chris@16: return out; Chris@16: } Chris@16: } Chris@16: Chris@16: namespace range Chris@16: { Chris@16: Chris@16: /// \overload Chris@16: template< class SinglePassRange1, Chris@16: class SinglePassRange2, Chris@16: class OutputIterator, Chris@16: class BinaryOperation > Chris@16: inline OutputIterator Chris@16: transform(const SinglePassRange1& rng1, Chris@16: const SinglePassRange2& rng2, Chris@16: OutputIterator out, Chris@16: BinaryOperation fun) Chris@16: { Chris@16: BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); Chris@16: BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); Chris@16: return boost::range_detail::transform_impl( Chris@16: boost::begin(rng1), boost::end(rng1), Chris@16: boost::begin(rng2), boost::end(rng2), Chris@16: out, fun); Chris@16: } Chris@16: Chris@16: } // namespace range Chris@16: using range::transform; Chris@16: } // namespace boost Chris@16: Chris@16: #endif // include guard