mirror of
https://github.com/boostorg/algorithm.git
synced 2025-07-06 09:16:33 +02:00
Rewrote iota_n to use pre-increment instead of post - now the same as iota. Added a test for 0 as well.
[SVN r85465]
This commit is contained in:
@ -63,8 +63,8 @@ void iota ( Range &r, T value )
|
|||||||
template <typename OutputIterator, typename T>
|
template <typename OutputIterator, typename T>
|
||||||
OutputIterator iota_n ( OutputIterator out, T value, std::size_t n )
|
OutputIterator iota_n ( OutputIterator out, T value, std::size_t n )
|
||||||
{
|
{
|
||||||
while ( n-- > 0 )
|
for ( ; n > 0; --n, ++value )
|
||||||
*out++ = value++;
|
*out++ = value;
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
@ -42,11 +42,11 @@ void test_ints () {
|
|||||||
std::vector<int> v;
|
std::vector<int> v;
|
||||||
std::list<int> l;
|
std::list<int> l;
|
||||||
|
|
||||||
v.clear (); v.reserve ( 10 );
|
v.clear (); v.resize ( 10 );
|
||||||
boost::algorithm::iota ( v.begin (), v.end (), 23 );
|
boost::algorithm::iota ( v.begin (), v.end (), 23 );
|
||||||
BOOST_CHECK ( test_iota_results ( v.begin (), v.end (), 23 ));
|
BOOST_CHECK ( test_iota_results ( v.begin (), v.end (), 23 ));
|
||||||
|
|
||||||
v.clear (); v.reserve ( 19 );
|
v.clear (); v.resize ( 19 );
|
||||||
boost::algorithm::iota ( v, 18 );
|
boost::algorithm::iota ( v, 18 );
|
||||||
BOOST_CHECK ( test_iota_results ( v, 18 ));
|
BOOST_CHECK ( test_iota_results ( v, 18 ));
|
||||||
|
|
||||||
@ -54,6 +54,10 @@ void test_ints () {
|
|||||||
boost::algorithm::iota_n ( std::back_inserter(v), 99, 20 );
|
boost::algorithm::iota_n ( std::back_inserter(v), 99, 20 );
|
||||||
BOOST_CHECK ( test_iota_results ( v, 99 ));
|
BOOST_CHECK ( test_iota_results ( v, 99 ));
|
||||||
|
|
||||||
|
v.clear ();
|
||||||
|
boost::algorithm::iota_n ( std::back_inserter(v), 99, 0 );
|
||||||
|
BOOST_CHECK ( v.size() == 0 );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
l.clear (); l.reserve ( 5 );
|
l.clear (); l.reserve ( 5 );
|
||||||
boost::algorithm::iota ( l.begin (), l.end (), 123 );
|
boost::algorithm::iota ( l.begin (), l.end (), 123 );
|
||||||
|
Reference in New Issue
Block a user