Chris@16: /* Chris@16: Copyright (c) Marshall Clow 2008-2012. Chris@16: Chris@16: Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: */ Chris@16: Chris@16: /// \file iota.hpp Chris@16: /// \brief Generate an increasing series Chris@16: /// \author Marshall Clow Chris@16: Chris@16: #ifndef BOOST_ALGORITHM_IOTA_HPP Chris@16: #define BOOST_ALGORITHM_IOTA_HPP Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { namespace algorithm { Chris@16: Chris@16: /// \fn iota ( ForwardIterator first, ForwardIterator last, T value ) Chris@16: /// \brief Generates an increasing sequence of values, and stores them in [first, last) Chris@16: /// Chris@16: /// \param first The start of the input sequence Chris@16: /// \param last One past the end of the input sequence Chris@16: /// \param value The initial value of the sequence to be generated Chris@16: /// \note This function is part of the C++2011 standard library. Chris@16: /// We will use the standard one if it is available, Chris@16: /// otherwise we have our own implementation. Chris@16: template Chris@16: void iota ( ForwardIterator first, ForwardIterator last, T value ) Chris@16: { Chris@16: for ( ; first != last; ++first, ++value ) Chris@16: *first = value; Chris@16: } Chris@16: Chris@16: /// \fn iota ( Range &r, T value ) Chris@16: /// \brief Generates an increasing sequence of values, and stores them in the input Range. Chris@16: /// Chris@16: /// \param r The input range Chris@16: /// \param value The initial value of the sequence to be generated Chris@16: /// Chris@16: template Chris@16: void iota ( Range &r, T value ) Chris@16: { Chris@16: boost::algorithm::iota (boost::begin(r), boost::end(r), value); Chris@16: } Chris@16: Chris@16: Chris@16: /// \fn iota_n ( OutputIterator out, T value, std::size_t n ) Chris@16: /// \brief Generates an increasing sequence of values, and stores them in the input Range. Chris@16: /// Chris@16: /// \param out An output iterator to write the results into Chris@16: /// \param value The initial value of the sequence to be generated Chris@16: /// \param n The number of items to write Chris@16: /// Chris@16: template Chris@16: OutputIterator iota_n ( OutputIterator out, T value, std::size_t n ) Chris@16: { Chris@101: for ( ; n > 0; --n, ++value ) Chris@101: *out++ = value; Chris@16: Chris@16: return out; Chris@16: } Chris@16: Chris@16: }} Chris@16: Chris@16: #endif // BOOST_ALGORITHM_IOTA_HPP