| 1 |
/// \file |
| 2 |
// Range v3 library |
| 3 |
// |
| 4 |
// Copyright Eric Niebler 2013-present |
| 5 |
// |
| 6 |
// Use, modification and distribution is subject to the |
| 7 |
// Boost Software License, Version 1.0. (See accompanying |
| 8 |
// file LICENSE_1_0.txt or copy at |
| 9 |
// http://www.boost.org/LICENSE_1_0.txt) |
| 10 |
// |
| 11 |
// Project home: https://github.com/ericniebler/range-v3 |
| 12 |
// |
| 13 |
|
| 14 |
#ifndef RANGES_V3_ACTION_STABLE_SORT_HPP |
| 15 |
#define RANGES_V3_ACTION_STABLE_SORT_HPP |
| 16 |
|
| 17 |
#include <range/v3/range_fwd.hpp> |
| 18 |
|
| 19 |
#include <range/v3/action/action.hpp> |
| 20 |
#include <range/v3/algorithm/stable_sort.hpp> |
| 21 |
#include <range/v3/functional/bind_back.hpp> |
| 22 |
#include <range/v3/functional/comparisons.hpp> |
| 23 |
#include <range/v3/functional/identity.hpp> |
| 24 |
#include <range/v3/iterator/concepts.hpp> |
| 25 |
#include <range/v3/iterator/traits.hpp> |
| 26 |
#include <range/v3/utility/static_const.hpp> |
| 27 |
|
| 28 |
#include <range/v3/detail/prologue.hpp> |
| 29 |
|
| 30 |
namespace ranges |
| 31 |
{ |
| 32 |
/// \addtogroup group-actions |
| 33 |
/// @{ |
| 34 |
namespace actions |
| 35 |
{ |
| 36 |
struct stable_sort_fn |
| 37 |
{ |
| 38 |
template(typename C, typename P = identity)( |
| 39 |
requires (!range<C>)) |
| 40 |
constexpr auto operator()(C pred, P proj = P{}) const |
| 41 |
{ |
| 42 |
return make_action_closure( |
| 43 |
bind_back(stable_sort_fn{}, std::move(pred), std::move(proj))); |
| 44 |
} |
| 45 |
|
| 46 |
template(typename Rng, typename C = less, typename P = identity)( |
| 47 |
requires forward_range<Rng> AND sortable<iterator_t<Rng>, C, P>) |
| 48 |
Rng operator()(Rng && rng, C pred = C{}, P proj = P{}) const |
| 49 |
{ |
| 50 |
ranges::stable_sort(rng, std::move(pred), std::move(proj)); |
| 51 |
return static_cast<Rng &&>(rng); |
| 52 |
} |
| 53 |
}; |
| 54 |
|
| 55 |
/// \relates actions::stable_sort_fn |
| 56 |
/// \sa action_closure |
| 57 |
RANGES_INLINE_VARIABLE(action_closure<stable_sort_fn>, stable_sort) |
| 58 |
} // namespace actions |
| 59 |
/// @} |
| 60 |
} // namespace ranges |
| 61 |
|
| 62 |
#include <range/v3/detail/epilogue.hpp> |
| 63 |
|
| 64 |
#endif |