Chris@16
|
1 // Boost.Range library
|
Chris@16
|
2 //
|
Chris@16
|
3 // Copyright Neil Groves 2009. Use, modification and
|
Chris@16
|
4 // distribution is subject to the Boost Software License, Version
|
Chris@16
|
5 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
6 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
7 //
|
Chris@16
|
8 // For more information, see http://www.boost.org/libs/range/
|
Chris@16
|
9 //
|
Chris@16
|
10 #ifndef BOOST_RANGE_ALGORITHM_EXT_IOTA_HPP_INCLUDED
|
Chris@16
|
11 #define BOOST_RANGE_ALGORITHM_EXT_IOTA_HPP_INCLUDED
|
Chris@16
|
12
|
Chris@16
|
13 #include <boost/range/config.hpp>
|
Chris@16
|
14 #include <boost/range/concepts.hpp>
|
Chris@16
|
15 #include <boost/range/iterator.hpp>
|
Chris@16
|
16 #include <boost/range/begin.hpp>
|
Chris@16
|
17 #include <boost/range/end.hpp>
|
Chris@16
|
18
|
Chris@16
|
19 namespace boost
|
Chris@16
|
20 {
|
Chris@16
|
21 namespace range
|
Chris@16
|
22 {
|
Chris@16
|
23
|
Chris@16
|
24 template< class ForwardRange, class Value >
|
Chris@16
|
25 inline ForwardRange& iota( ForwardRange& rng, Value x )
|
Chris@16
|
26 {
|
Chris@16
|
27 BOOST_CONCEPT_ASSERT(( ForwardRangeConcept<ForwardRange> ));
|
Chris@16
|
28 typedef BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type iterator_t;
|
Chris@16
|
29
|
Chris@16
|
30 iterator_t last_target = ::boost::end(rng);
|
Chris@16
|
31 for (iterator_t target = ::boost::begin(rng); target != last_target; ++target, ++x)
|
Chris@16
|
32 *target = x;
|
Chris@16
|
33
|
Chris@16
|
34 return rng;
|
Chris@16
|
35 }
|
Chris@16
|
36
|
Chris@16
|
37 template< class ForwardRange, class Value >
|
Chris@16
|
38 inline const ForwardRange& iota( const ForwardRange& rng, Value x )
|
Chris@16
|
39 {
|
Chris@16
|
40 BOOST_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange> ));
|
Chris@16
|
41 typedef BOOST_DEDUCED_TYPENAME range_iterator<const ForwardRange>::type iterator_t;
|
Chris@16
|
42
|
Chris@16
|
43 iterator_t last_target = ::boost::end(rng);
|
Chris@16
|
44 for (iterator_t target = ::boost::begin(rng); target != last_target; ++target, ++x)
|
Chris@16
|
45 *target = x;
|
Chris@16
|
46
|
Chris@16
|
47 return rng;
|
Chris@16
|
48 }
|
Chris@16
|
49
|
Chris@16
|
50 } // namespace range
|
Chris@16
|
51 using range::iota;
|
Chris@16
|
52 } // namespace boost
|
Chris@16
|
53
|
Chris@16
|
54 #endif // include guard
|