Chris@16
|
1 /*
|
Chris@16
|
2 Copyright (c) Marshall Clow 2008-2012.
|
Chris@16
|
3
|
Chris@16
|
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6 */
|
Chris@16
|
7
|
Chris@16
|
8 /// \file iota.hpp
|
Chris@16
|
9 /// \brief Generate an increasing series
|
Chris@16
|
10 /// \author Marshall Clow
|
Chris@16
|
11
|
Chris@16
|
12 #ifndef BOOST_ALGORITHM_IOTA_HPP
|
Chris@16
|
13 #define BOOST_ALGORITHM_IOTA_HPP
|
Chris@16
|
14
|
Chris@16
|
15 #include <numeric>
|
Chris@16
|
16
|
Chris@16
|
17 #include <boost/range/begin.hpp>
|
Chris@16
|
18 #include <boost/range/end.hpp>
|
Chris@16
|
19
|
Chris@16
|
20 namespace boost { namespace algorithm {
|
Chris@16
|
21
|
Chris@16
|
22 /// \fn iota ( ForwardIterator first, ForwardIterator last, T value )
|
Chris@16
|
23 /// \brief Generates an increasing sequence of values, and stores them in [first, last)
|
Chris@16
|
24 ///
|
Chris@16
|
25 /// \param first The start of the input sequence
|
Chris@16
|
26 /// \param last One past the end of the input sequence
|
Chris@16
|
27 /// \param value The initial value of the sequence to be generated
|
Chris@16
|
28 /// \note This function is part of the C++2011 standard library.
|
Chris@16
|
29 /// We will use the standard one if it is available,
|
Chris@16
|
30 /// otherwise we have our own implementation.
|
Chris@16
|
31 template <typename ForwardIterator, typename T>
|
Chris@16
|
32 void iota ( ForwardIterator first, ForwardIterator last, T value )
|
Chris@16
|
33 {
|
Chris@16
|
34 for ( ; first != last; ++first, ++value )
|
Chris@16
|
35 *first = value;
|
Chris@16
|
36 }
|
Chris@16
|
37
|
Chris@16
|
38 /// \fn iota ( Range &r, T value )
|
Chris@16
|
39 /// \brief Generates an increasing sequence of values, and stores them in the input Range.
|
Chris@16
|
40 ///
|
Chris@16
|
41 /// \param r The input range
|
Chris@16
|
42 /// \param value The initial value of the sequence to be generated
|
Chris@16
|
43 ///
|
Chris@16
|
44 template <typename Range, typename T>
|
Chris@16
|
45 void iota ( Range &r, T value )
|
Chris@16
|
46 {
|
Chris@16
|
47 boost::algorithm::iota (boost::begin(r), boost::end(r), value);
|
Chris@16
|
48 }
|
Chris@16
|
49
|
Chris@16
|
50
|
Chris@16
|
51 /// \fn iota_n ( OutputIterator out, T value, std::size_t n )
|
Chris@16
|
52 /// \brief Generates an increasing sequence of values, and stores them in the input Range.
|
Chris@16
|
53 ///
|
Chris@16
|
54 /// \param out An output iterator to write the results into
|
Chris@16
|
55 /// \param value The initial value of the sequence to be generated
|
Chris@16
|
56 /// \param n The number of items to write
|
Chris@16
|
57 ///
|
Chris@16
|
58 template <typename OutputIterator, typename T>
|
Chris@16
|
59 OutputIterator iota_n ( OutputIterator out, T value, std::size_t n )
|
Chris@16
|
60 {
|
Chris@101
|
61 for ( ; n > 0; --n, ++value )
|
Chris@101
|
62 *out++ = value;
|
Chris@16
|
63
|
Chris@16
|
64 return out;
|
Chris@16
|
65 }
|
Chris@16
|
66
|
Chris@16
|
67 }}
|
Chris@16
|
68
|
Chris@16
|
69 #endif // BOOST_ALGORITHM_IOTA_HPP
|