forked from boostorg/algorithm
Replace hand-rolled loop with 'iota_n' and back_insert_iterator
This commit is contained in:
@ -18,6 +18,8 @@
|
|||||||
#include <functional> // for std::less
|
#include <functional> // for std::less
|
||||||
#include <vector> // for std::vector
|
#include <vector> // for std::vector
|
||||||
|
|
||||||
|
#include <boost/algorithm/cxx11/iota.hpp>
|
||||||
|
|
||||||
namespace boost { namespace algorithm {
|
namespace boost { namespace algorithm {
|
||||||
|
|
||||||
typedef std::vector<size_t> Permutation;
|
typedef std::vector<size_t> Permutation;
|
||||||
@ -37,15 +39,15 @@ namespace detail {
|
|||||||
Iter iter_;
|
Iter iter_;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Initialize a permutation
|
// Initialize a permutation of size 'size'. [ 0, 1, 2, ... size-1 ]
|
||||||
// it would be nice to use 'iota' here, but that call writes over
|
// Note: it would be nice to use 'iota' here, but that call writes over
|
||||||
// existing elements - not append them. I don't want to initialize
|
// existing elements - not append them. I don't want to initialize
|
||||||
// the elements of the permutation to zero, and then immediately
|
// the elements of the permutation to zero, and then immediately
|
||||||
// overwrite them.
|
// overwrite them.
|
||||||
void init_permutation (Permutation &p, size_t size) {
|
void init_permutation (Permutation &p, size_t size) {
|
||||||
p.reserve(size);
|
p.reserve(size);
|
||||||
for (size_t i = 0; i < size; ++i)
|
boost::algorithm::iota_n(
|
||||||
p.push_back(i);
|
std::back_insert_iterator<Permutation>(p), size_t(0), size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user