PageRenderTime 56ms CodeModel.GetById 49ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 1ms

/Src/Dependencies/Boost/boost/range/algorithm/transform.hpp

http://hadesmem.googlecode.com/
C++ Header | 97 lines | 70 code | 9 blank | 18 comment | 3 complexity | a4355253ba5bdd97d971158013221ca4 MD5 | raw file
 1//  Copyright Neil Groves 2009. Use, modification and
 2//  distribution is subject to the Boost Software License, Version
 3//  1.0. (See accompanying file LICENSE_1_0.txt or copy at
 4//  http://www.boost.org/LICENSE_1_0.txt)
 5//
 6//
 7// For more information, see http://www.boost.org/libs/range/
 8//
 9#ifndef BOOST_RANGE_ALGORITHM_TRANSFORM_HPP_INCLUDED
10#define BOOST_RANGE_ALGORITHM_TRANSFORM_HPP_INCLUDED
11
12#include <boost/assert.hpp>
13#include <boost/concept_check.hpp>
14#include <boost/range/begin.hpp>
15#include <boost/range/end.hpp>
16#include <boost/range/concepts.hpp>
17#include <algorithm>
18
19namespace boost
20{
21    namespace range
22    {
23
24        /// \brief template function transform
25        ///
26        /// range-based version of the transform std algorithm
27        ///
28        /// \pre SinglePassRange1 is a model of the SinglePassRangeConcept
29        /// \pre SinglePassRange2 is a model of the SinglePassRangeConcept
30        /// \pre OutputIterator is a model of the OutputIteratorConcept
31        /// \pre UnaryOperation is a model of the UnaryFunctionConcept
32        /// \pre BinaryOperation is a model of the BinaryFunctionConcept
33        template< class SinglePassRange1,
34                  class OutputIterator,
35                  class UnaryOperation >
36        inline OutputIterator
37        transform(const SinglePassRange1& rng,
38                  OutputIterator          out,
39                  UnaryOperation          fun)
40        {
41            BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange1> ));
42            return std::transform(boost::begin(rng),boost::end(rng),out,fun);
43        }
44
45    } // namespace range
46
47    namespace range_detail
48    {
49        template< class SinglePassTraversalReadableIterator1,
50                  class SinglePassTraversalReadableIterator2,
51                  class OutputIterator,
52                  class BinaryFunction >
53        inline OutputIterator
54        transform_impl(SinglePassTraversalReadableIterator1 first1,
55                       SinglePassTraversalReadableIterator1 last1,
56                       SinglePassTraversalReadableIterator2 first2,
57                       SinglePassTraversalReadableIterator2 last2,
58                       OutputIterator                       out,
59                       BinaryFunction                       fn)
60        {
61            for (; first1 != last1; ++first1, ++first2)
62            {
63                BOOST_ASSERT( first2 != last2 );
64                *out = fn(*first1, *first2);
65                ++out;
66            }
67            return out;
68        }
69    }
70
71    namespace range
72    {
73
74        /// \overload
75        template< class SinglePassRange1,
76                  class SinglePassRange2,
77                  class OutputIterator,
78                  class BinaryOperation >
79        inline OutputIterator
80        transform(const SinglePassRange1& rng1,
81                  const SinglePassRange2& rng2,
82                  OutputIterator          out,
83                  BinaryOperation         fun)
84        {
85            BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange1> ));
86            BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange2> ));
87            return boost::range_detail::transform_impl(
88                        boost::begin(rng1), boost::end(rng1),
89                        boost::begin(rng2), boost::end(rng2),
90                        out, fun);
91        }
92
93    } // namespace range
94    using range::transform;
95} // namespace boost
96
97#endif // include guard