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