8 #ifndef TRSL_RANDOM_PERMUTATION_ITERATOR_HPP
9 #define TRSL_RANDOM_PERMUTATION_ITERATOR_HPP
38 template<
class ElementIterator>
39 reorder_iterator<ElementIterator>
42 unsigned permutationSize)
44 ptrdiff_t size = std::distance(first, last);
47 "random_permutation_iterator: "
49 if (permutationSize >
unsigned(size))
51 "random_permutation_iterator: "
52 "parameter permutationSize out of range.");
55 typename reorder_iterator<ElementIterator>::index_container
58 typename reorder_iterator<ElementIterator>::index_container_ptr
61 typename reorder_iterator<ElementIterator>::index_t
64 index_container_ptr index_collection(
new index_container);
66 index_collection->resize(size);
67 for (index_t i = 0; i < index_t(size); ++i)
68 (*index_collection)[i] = i;
69 if (permutationSize ==
unsigned(size))
70 std::random_shuffle(index_collection->begin(),
71 index_collection->end(),
75 detail::partial_random_shuffle(index_collection->begin(),
76 index_collection->begin()+permutationSize,
77 index_collection->end(),
79 index_collection->resize(permutationSize);
101 template<
class ElementIterator>
102 reorder_iterator<ElementIterator>
104 ElementIterator last)
108 std::distance(first, last));
113 #endif // include guard