Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:59:17

0001 //  Copyright Neil Groves 2009. Use, modification and
0002 //  distribution is subject to the Boost Software License, Version
0003 //  1.0. (See accompanying file LICENSE_1_0.txt or copy at
0004 //  http://www.boost.org/LICENSE_1_0.txt)
0005 //
0006 //
0007 // For more information, see http://www.boost.org/libs/range/
0008 //
0009 #ifndef BOOST_RANGE_ALGORITHM_TRANSFORM_HPP_INCLUDED
0010 #define BOOST_RANGE_ALGORITHM_TRANSFORM_HPP_INCLUDED
0011 
0012 #include <boost/assert.hpp>
0013 #include <boost/concept_check.hpp>
0014 #include <boost/range/begin.hpp>
0015 #include <boost/range/end.hpp>
0016 #include <boost/range/concepts.hpp>
0017 #include <algorithm>
0018 
0019 namespace boost
0020 {
0021     namespace range
0022     {
0023 
0024         /// \brief template function transform
0025         ///
0026         /// range-based version of the transform std algorithm
0027         ///
0028         /// \pre SinglePassRange1 is a model of the SinglePassRangeConcept
0029         /// \pre SinglePassRange2 is a model of the SinglePassRangeConcept
0030         /// \pre OutputIterator is a model of the OutputIteratorConcept
0031         /// \pre UnaryOperation is a model of the UnaryFunctionConcept
0032         /// \pre BinaryOperation is a model of the BinaryFunctionConcept
0033         template< class SinglePassRange1,
0034                   class OutputIterator,
0035                   class UnaryOperation >
0036         inline OutputIterator
0037         transform(const SinglePassRange1& rng,
0038                   OutputIterator          out,
0039                   UnaryOperation          fun)
0040         {
0041             BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange1> ));
0042             return std::transform(boost::begin(rng),boost::end(rng),out,fun);
0043         }
0044 
0045     } // namespace range
0046 
0047     namespace range_detail
0048     {
0049         template< class SinglePassTraversalReadableIterator1,
0050                   class SinglePassTraversalReadableIterator2,
0051                   class OutputIterator,
0052                   class BinaryFunction >
0053         inline OutputIterator
0054         transform_impl(SinglePassTraversalReadableIterator1 first1,
0055                        SinglePassTraversalReadableIterator1 last1,
0056                        SinglePassTraversalReadableIterator2 first2,
0057                        SinglePassTraversalReadableIterator2 last2,
0058                        OutputIterator                       out,
0059                        BinaryFunction                       fn)
0060         {
0061             for (; first1 != last1 && first2 != last2; ++first1, ++first2)
0062             {
0063                 *out = fn(*first1, *first2);
0064                 ++out;
0065             }
0066             return out;
0067         }
0068     }
0069 
0070     namespace range
0071     {
0072 
0073         /// \overload
0074         template< class SinglePassRange1,
0075                   class SinglePassRange2,
0076                   class OutputIterator,
0077                   class BinaryOperation >
0078         inline OutputIterator
0079         transform(const SinglePassRange1& rng1,
0080                   const SinglePassRange2& rng2,
0081                   OutputIterator          out,
0082                   BinaryOperation         fun)
0083         {
0084             BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange1> ));
0085             BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange2> ));
0086             return boost::range_detail::transform_impl(
0087                         boost::begin(rng1), boost::end(rng1),
0088                         boost::begin(rng2), boost::end(rng2),
0089                         out, fun);
0090         }
0091 
0092     } // namespace range
0093     using range::transform;
0094 } // namespace boost
0095 
0096 #endif // include guard