mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
Support empty ranges in selection_sort
This commit is contained in:
parent
570a431cfd
commit
19a1d7733b
@ -3109,6 +3109,11 @@ namespace etl
|
||||
ETL_CONSTEXPR20
|
||||
void selection_sort(TIterator first, TIterator last, TCompare compare)
|
||||
{
|
||||
if (first == last)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
TIterator min;
|
||||
const TIterator ilast = private_algorithm::get_before_last(first, last);
|
||||
const TIterator jlast = last;
|
||||
|
||||
@ -2163,6 +2163,30 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(selection_sort_empty_range)
|
||||
{
|
||||
// Forward iterators
|
||||
std::forward_list<int> fwd_data;
|
||||
etl::selection_sort(fwd_data.begin(), fwd_data.end());
|
||||
CHECK(fwd_data.empty());
|
||||
|
||||
// Bidirectional iterators
|
||||
std::list<int> bidir_data;
|
||||
etl::selection_sort(bidir_data.begin(), bidir_data.end());
|
||||
CHECK(bidir_data.empty());
|
||||
|
||||
// Random access iterators
|
||||
std::vector<int> ra_data;
|
||||
etl::selection_sort(ra_data.begin(), ra_data.end());
|
||||
CHECK(ra_data.empty());
|
||||
|
||||
// With comparator
|
||||
std::forward_list<int> fwd_data2;
|
||||
etl::selection_sort(fwd_data2.begin(), fwd_data2.end(), std::greater<int>());
|
||||
CHECK(fwd_data2.empty());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(heap_sort_default)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user