forked from boostorg/algorithm
Fixed compatibility with old compilers
This commit is contained in:
@ -19,7 +19,7 @@
|
||||
#define BOOST_ALGORITHM_APPLY_PERMUTATION_HPP
|
||||
|
||||
#include <algorithm>
|
||||
#include <type_traits>
|
||||
#include <iterator>
|
||||
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
@ -41,14 +41,14 @@ void
|
||||
apply_permutation(RandomAccessIterator1 item_begin, RandomAccessIterator1 item_end,
|
||||
RandomAccessIterator2 ind_begin)
|
||||
{
|
||||
using Diff = typename std::iterator_traits<RandomAccessIterator1>::difference_type;
|
||||
typedef typename std::iterator_traits<RandomAccessIterator1>::difference_type Diff;
|
||||
Diff size = std::distance(item_begin, item_end);
|
||||
for (Diff i = 0; i < size; i++)
|
||||
for (Diff i = 0; i < size; ++i)
|
||||
{
|
||||
auto current = i;
|
||||
Diff current = i;
|
||||
while (i != ind_begin[current])
|
||||
{
|
||||
auto next = ind_begin[current];
|
||||
Diff next = static_cast<Diff>(ind_begin[current]);
|
||||
std::swap(item_begin[current], item_begin[next]);
|
||||
ind_begin[current] = current;
|
||||
current = next;
|
||||
@ -68,14 +68,12 @@ apply_permutation(RandomAccessIterator1 item_begin, RandomAccessIterator1 item_e
|
||||
/// Complexity: O(N).
|
||||
template<typename RandomAccessIterator1, typename RandomAccessIterator2>
|
||||
void
|
||||
apply_reverse_permutation(
|
||||
RandomAccessIterator1 item_begin,
|
||||
RandomAccessIterator1 item_end,
|
||||
apply_reverse_permutation(RandomAccessIterator1 item_begin, RandomAccessIterator1 item_end,
|
||||
RandomAccessIterator2 ind_begin)
|
||||
{
|
||||
using Diff = typename std::iterator_traits<RandomAccessIterator2>::difference_type;
|
||||
typedef typename std::iterator_traits<RandomAccessIterator1>::difference_type Diff;
|
||||
Diff length = std::distance(item_begin, item_end);
|
||||
for (Diff i = 0; i < length; i++)
|
||||
for (Diff i = 0; i < length; ++i)
|
||||
{
|
||||
while (i != ind_begin[i])
|
||||
{
|
||||
|
Reference in New Issue
Block a user