Skip to content

Commit fe51eb6

Browse files
committed
Rewrote iota_n to use pre-increment instead of post - now the same as iota. Added a test for 0 as well.
[SVN r85465]
1 parent fc0fe6a commit fe51eb6

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

include/boost/algorithm/cxx11/iota.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ void iota ( Range &r, T value )
6363
template <typename OutputIterator, typename T>
6464
OutputIterator 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
}

test/iota_test1.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff 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 );

0 commit comments

Comments
 (0)