Skip to content

Commit

Permalink
constexpr poplar_sorter (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
Morwenn committed Jan 7, 2024
1 parent f26cf20 commit a0312e0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
20 changes: 10 additions & 10 deletions include/cpp-sort/detail/poplar_sort.h
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2023 Morwenn
* Copyright (c) 2016-2024 Morwenn
* SPDX-License-Identifier: MIT
*/
#ifndef CPPSORT_DETAIL_POPLAR_SORT_H_
Expand All @@ -26,7 +26,7 @@ namespace cppsort::detail
RandomAccessIterator begin, end;
mstd::make_unsigned_t<mstd::iter_difference_t<RandomAccessIterator>> size;

auto root() const
constexpr auto root() const
-> RandomAccessIterator
{
auto res = end;
Expand All @@ -36,8 +36,8 @@ namespace cppsort::detail

template<typename RandomAccessIterator, typename Size,
typename Compare, typename Projection>
auto sift(RandomAccessIterator first, Size size,
Compare compare, Projection projection)
constexpr auto sift(RandomAccessIterator first, Size size,
Compare compare, Projection projection)
-> void
{
if (size < 2) return;
Expand Down Expand Up @@ -84,8 +84,8 @@ namespace cppsort::detail
}

template<typename RandomAccessIterator, typename Compare, typename Projection>
auto relocate(const std::vector<poplar<RandomAccessIterator>>& poplars,
Compare compare, Projection projection)
constexpr auto relocate(const std::vector<poplar<RandomAccessIterator>>& poplars,
Compare compare, Projection projection)
-> void
{
auto&& comp = utility::as_function(compare);
Expand All @@ -109,8 +109,8 @@ namespace cppsort::detail
}

template<typename RandomAccessIterator, typename Compare, typename Projection>
auto make_poplar(RandomAccessIterator first, RandomAccessIterator last,
Compare compare, Projection projection)
constexpr auto make_poplar(RandomAccessIterator first, RandomAccessIterator last,
Compare compare, Projection projection)
-> void
{
auto size = as_unsigned(last - first);
Expand All @@ -130,8 +130,8 @@ namespace cppsort::detail
}

template<typename RandomAccessIterator, typename Compare, typename Projection>
auto poplar_sort(RandomAccessIterator first, RandomAccessIterator last,
Compare compare, Projection projection)
constexpr auto poplar_sort(RandomAccessIterator first, RandomAccessIterator last,
Compare compare, Projection projection)
-> void
{
using poplar_size_t = mstd::make_unsigned_t<mstd::iter_difference_t<RandomAccessIterator>>;
Expand Down
6 changes: 3 additions & 3 deletions include/cpp-sort/sorters/poplar_sorter.h
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2022 Morwenn
* Copyright (c) 2016-2024 Morwenn
* SPDX-License-Identifier: MIT
*/
#ifndef CPPSORT_SORTERS_POPLAR_SORTER_H_
Expand Down Expand Up @@ -33,8 +33,8 @@ namespace cppsort
typename Projection = std::identity
>
requires is_projection_iterator_v<Projection, Iterator, Compare>
auto operator()(Iterator first, Sentinel last,
Compare compare={}, Projection projection={}) const
constexpr auto operator()(Iterator first, Sentinel last,
Compare compare={}, Projection projection={}) const
-> Iterator
{
auto last_it = mstd::next(first, std::move(last));
Expand Down
3 changes: 2 additions & 1 deletion tests/sorters/every_sorter_constexpr.cpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Morwenn
* Copyright (c) 2022-2024 Morwenn
* SPDX-License-Identifier: MIT
*/
#include <cstddef>
Expand Down Expand Up @@ -31,6 +31,7 @@ TEMPLATE_TEST_CASE( "test every constexpr sorter", "[sorters][constexpr]",
cppsort::d_ary_heap_sorter<7>,
cppsort::heap_sorter,
cppsort::insertion_sorter,
cppsort::poplar_sorter,
cppsort::pdq_sorter,
cppsort::quick_merge_sorter,
cppsort::quick_sorter,
Expand Down

0 comments on commit a0312e0

Please sign in to comment.