]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Copyright Neil Groves 2009. Use, modification and |
2 | // distribution is subject to the Boost Software License, Version | |
3 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at | |
4 | // http://www.boost.org/LICENSE_1_0.txt) | |
5 | // | |
6 | // | |
7 | // For more information, see http://www.boost.org/libs/range/ | |
8 | // | |
9 | #ifndef BOOST_RANGE_ALGORITHM_FILL_N_HPP_INCLUDED | |
10 | #define BOOST_RANGE_ALGORITHM_FILL_N_HPP_INCLUDED | |
11 | ||
12 | #include <boost/assert.hpp> | |
13 | #include <boost/concept_check.hpp> | |
14 | #include <boost/range/begin.hpp> | |
15 | #include <boost/range/end.hpp> | |
16 | #include <boost/range/concepts.hpp> | |
17 | #include <algorithm> | |
18 | ||
19 | namespace boost | |
20 | { | |
21 | namespace range | |
22 | { | |
23 | ||
24 | /// \brief template function fill_n | |
25 | /// | |
26 | /// range-based version of the fill_n std algorithm | |
27 | /// | |
28 | /// \pre ForwardRange is a model of the ForwardRangeConcept | |
29 | /// \pre n <= std::distance(boost::begin(rng), boost::end(rng)) | |
30 | template< class ForwardRange, class Size, class Value > | |
31 | inline ForwardRange& fill_n(ForwardRange& rng, Size n, const Value& val) | |
32 | { | |
33 | BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<ForwardRange> )); | |
34 | BOOST_ASSERT( static_cast<Size>(std::distance(boost::begin(rng), boost::end(rng))) >= n ); | |
35 | std::fill_n(boost::begin(rng), n, val); | |
36 | return rng; | |
37 | } | |
38 | ||
39 | /// \overload | |
40 | template< class ForwardRange, class Size, class Value > | |
41 | inline const ForwardRange& fill_n(const ForwardRange& rng, Size n, const Value& val) | |
42 | { | |
43 | BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange> )); | |
44 | BOOST_ASSERT( static_cast<Size>(std::distance(boost::begin(rng), boost::end(rng))) >= n ); | |
45 | std::fill_n(boost::begin(rng), n, val); | |
46 | return rng; | |
47 | } | |
48 | ||
49 | } // namespace range | |
50 | using range::fill_n; | |
51 | } // namespace boost | |
52 | ||
53 | #endif // include guard |