algo/sort: assert we're operating on random iterators
This commit is contained in:
parent
92727ff351
commit
1200b1a038
@ -26,6 +26,8 @@
|
|||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <iterator>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
#include "../debug.hpp"
|
#include "../debug.hpp"
|
||||||
#include "../tuple.hpp"
|
#include "../tuple.hpp"
|
||||||
@ -37,6 +39,13 @@ namespace cruft::util::sort::detail {
|
|||||||
void
|
void
|
||||||
index_swap (IndexA a, IndexB b, RandomIt value)
|
index_swap (IndexA a, IndexB b, RandomIt value)
|
||||||
{
|
{
|
||||||
|
static_assert(
|
||||||
|
std::is_base_of<
|
||||||
|
std::random_access_iterator_tag,
|
||||||
|
typename std::iterator_traits<RandomIt>::iterator_category
|
||||||
|
>::value
|
||||||
|
);
|
||||||
|
|
||||||
std::swap (value[a], value[b]);
|
std::swap (value[a], value[b]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,6 +67,20 @@ cruft::util::sort::reorder (IndexIt idx_first,
|
|||||||
ValueIt value,
|
ValueIt value,
|
||||||
OtherIt ...tail)
|
OtherIt ...tail)
|
||||||
{
|
{
|
||||||
|
static_assert (
|
||||||
|
std::is_base_of<
|
||||||
|
std::random_access_iterator_tag,
|
||||||
|
typename std::iterator_traits<IndexIt>::iterator_category
|
||||||
|
>::value
|
||||||
|
);
|
||||||
|
|
||||||
|
static_assert (
|
||||||
|
std::is_base_of<
|
||||||
|
std::random_access_iterator_tag,
|
||||||
|
typename std::iterator_traits<ValueIt>::iterator_category
|
||||||
|
>::value
|
||||||
|
);
|
||||||
|
|
||||||
// Bail early on zero size arrays, partly so we can simplify some
|
// Bail early on zero size arrays, partly so we can simplify some
|
||||||
// debugging checks
|
// debugging checks
|
||||||
auto size = std::distance (idx_first, idx_last);
|
auto size = std::distance (idx_first, idx_last);
|
||||||
@ -84,6 +107,13 @@ cruft::util::sort::soa (RandomIt key_first,
|
|||||||
Comparator comp,
|
Comparator comp,
|
||||||
Args ...values)
|
Args ...values)
|
||||||
{
|
{
|
||||||
|
static_assert (
|
||||||
|
std::is_base_of<
|
||||||
|
std::random_access_iterator_tag,
|
||||||
|
typename std::iterator_traits<RandomIt>::iterator_category
|
||||||
|
>::value
|
||||||
|
);
|
||||||
|
|
||||||
// bail early on guaranteed sorted or degenerate cases. we can make some
|
// bail early on guaranteed sorted or degenerate cases. we can make some
|
||||||
// assumptions about minimum array sizes and non-wrapping indices later on
|
// assumptions about minimum array sizes and non-wrapping indices later on
|
||||||
// this way.
|
// this way.
|
||||||
|
Loading…
Reference in New Issue
Block a user