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