annotate DEPENDENCIES/generic/include/boost/algorithm/cxx11/iota.hpp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children c530137014c0
rev   line source
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 #if __cplusplus >= 201103L
Chris@16 23 // Use the C++11 versions of iota if it is available
Chris@16 24 using std::iota; // Section 26.7.6
Chris@16 25 #else
Chris@16 26 /// \fn iota ( ForwardIterator first, ForwardIterator last, T value )
Chris@16 27 /// \brief Generates an increasing sequence of values, and stores them in [first, last)
Chris@16 28 ///
Chris@16 29 /// \param first The start of the input sequence
Chris@16 30 /// \param last One past the end of the input sequence
Chris@16 31 /// \param value The initial value of the sequence to be generated
Chris@16 32 /// \note This function is part of the C++2011 standard library.
Chris@16 33 /// We will use the standard one if it is available,
Chris@16 34 /// otherwise we have our own implementation.
Chris@16 35 template <typename ForwardIterator, typename T>
Chris@16 36 void iota ( ForwardIterator first, ForwardIterator last, T value )
Chris@16 37 {
Chris@16 38 for ( ; first != last; ++first, ++value )
Chris@16 39 *first = value;
Chris@16 40 }
Chris@16 41 #endif
Chris@16 42
Chris@16 43 /// \fn iota ( Range &r, T value )
Chris@16 44 /// \brief Generates an increasing sequence of values, and stores them in the input Range.
Chris@16 45 ///
Chris@16 46 /// \param r The input range
Chris@16 47 /// \param value The initial value of the sequence to be generated
Chris@16 48 ///
Chris@16 49 template <typename Range, typename T>
Chris@16 50 void iota ( Range &r, T value )
Chris@16 51 {
Chris@16 52 boost::algorithm::iota (boost::begin(r), boost::end(r), value);
Chris@16 53 }
Chris@16 54
Chris@16 55
Chris@16 56 /// \fn iota_n ( OutputIterator out, T value, std::size_t n )
Chris@16 57 /// \brief Generates an increasing sequence of values, and stores them in the input Range.
Chris@16 58 ///
Chris@16 59 /// \param out An output iterator to write the results into
Chris@16 60 /// \param value The initial value of the sequence to be generated
Chris@16 61 /// \param n The number of items to write
Chris@16 62 ///
Chris@16 63 template <typename OutputIterator, typename T>
Chris@16 64 OutputIterator iota_n ( OutputIterator out, T value, std::size_t n )
Chris@16 65 {
Chris@16 66 while ( n-- > 0 )
Chris@16 67 *out++ = value++;
Chris@16 68
Chris@16 69 return out;
Chris@16 70 }
Chris@16 71
Chris@16 72 }}
Chris@16 73
Chris@16 74 #endif // BOOST_ALGORITHM_IOTA_HPP