Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r85465 - in trunk: boost/algorithm/cxx11 libs/algorithm/test
From: marshall_at_[hidden]
Date: 2013-08-25 12:29:01


Author: marshall
Date: 2013-08-25 12:29:01 EDT (Sun, 25 Aug 2013)
New Revision: 85465
URL: http://svn.boost.org/trac/boost/changeset/85465

Log:
Rewrote iota_n to use pre-increment instead of post - now the same as iota. Added a test for 0 as well.

Text files modified:
   trunk/boost/algorithm/cxx11/iota.hpp | 4 ++--
   trunk/libs/algorithm/test/iota_test1.cpp | 8 ++++++--
   2 files changed, 8 insertions(+), 4 deletions(-)

Modified: trunk/boost/algorithm/cxx11/iota.hpp
==============================================================================
--- trunk/boost/algorithm/cxx11/iota.hpp Sun Aug 25 11:13:17 2013 (r85464)
+++ trunk/boost/algorithm/cxx11/iota.hpp 2013-08-25 12:29:01 EDT (Sun, 25 Aug 2013) (r85465)
@@ -63,8 +63,8 @@
 template <typename OutputIterator, typename T>
 OutputIterator iota_n ( OutputIterator out, T value, std::size_t n )
 {
- while ( n-- > 0 )
- *out++ = value++;
+ for ( ; n > 0; --n, ++value )
+ *out++ = value;
 
     return out;
 }

Modified: trunk/libs/algorithm/test/iota_test1.cpp
==============================================================================
--- trunk/libs/algorithm/test/iota_test1.cpp Sun Aug 25 11:13:17 2013 (r85464)
+++ trunk/libs/algorithm/test/iota_test1.cpp 2013-08-25 12:29:01 EDT (Sun, 25 Aug 2013) (r85465)
@@ -42,11 +42,11 @@
     std::vector<int> v;
     std::list<int> l;
 
- v.clear (); v.reserve ( 10 );
+ v.clear (); v.resize ( 10 );
     boost::algorithm::iota ( 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_CHECK ( test_iota_results ( v, 18 ));
     
@@ -54,6 +54,10 @@
     boost::algorithm::iota_n ( std::back_inserter(v), 99, 20 );
     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 );
     boost::algorithm::iota ( l.begin (), l.end (), 123 );


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk