File tree Expand file tree Collapse file tree
include/boost/algorithm/cxx11 Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -63,8 +63,8 @@ void iota ( Range &r, T value )
6363template <typename OutputIterator, typename T>
6464OutputIterator iota_n ( OutputIterator out, T value, std::size_t n )
6565{
66- while ( n-- > 0 )
67- *out++ = value++ ;
66+ for ( ; n > 0 ; --n, ++value )
67+ *out++ = value;
6868
6969 return out;
7070}
Original file line number Diff line number Diff line change @@ -42,18 +42,22 @@ void test_ints () {
4242 std::vector<int > v;
4343 std::list<int > l;
4444
45- v.clear (); v.reserve ( 10 );
45+ v.clear (); v.resize ( 10 );
4646 boost::algorithm::iota ( v.begin (), v.end (), 23 );
4747 BOOST_CHECK ( test_iota_results ( v.begin (), v.end (), 23 ));
4848
49- v.clear (); v.reserve ( 19 );
49+ v.clear (); v.resize ( 19 );
5050 boost::algorithm::iota ( v, 18 );
5151 BOOST_CHECK ( test_iota_results ( v, 18 ));
5252
5353 v.clear ();
5454 boost::algorithm::iota_n ( std::back_inserter (v), 99 , 20 );
5555 BOOST_CHECK ( test_iota_results ( v, 99 ));
5656
57+ v.clear ();
58+ boost::algorithm::iota_n ( std::back_inserter (v), 99 , 0 );
59+ BOOST_CHECK ( v.size () == 0 );
60+
5761/*
5862 l.clear (); l.reserve ( 5 );
5963 boost::algorithm::iota ( l.begin (), l.end (), 123 );
You can’t perform that action at this time.
0 commit comments