| 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_UNIQUE_HPP |
| 15 |
#define RANGES_V3_ACTION_UNIQUE_HPP |
| 16 |
|
| 17 |
#include <range/v3/range_fwd.hpp> |
| 18 |
|
| 19 |
#include <range/v3/action/action.hpp> |
| 20 |
#include <range/v3/action/erase.hpp> |
| 21 |
#include <range/v3/algorithm/unique.hpp> |
| 22 |
#include <range/v3/functional/bind_back.hpp> |
| 23 |
#include <range/v3/functional/comparisons.hpp> |
| 24 |
#include <range/v3/functional/identity.hpp> |
| 25 |
#include <range/v3/iterator/concepts.hpp> |
| 26 |
#include <range/v3/range/traits.hpp> |
| 27 |
#include <range/v3/utility/static_const.hpp> |
| 28 |
|
| 29 |
#include <range/v3/detail/prologue.hpp> |
| 30 |
|
| 31 |
namespace ranges |
| 32 |
{ |
| 33 |
/// \addtogroup group-actions |
| 34 |
/// @{ |
| 35 |
namespace actions |
| 36 |
{ |
| 37 |
struct unique_fn |
| 38 |
{ |
| 39 |
template(typename C, typename P = identity)( |
| 40 |
requires (!range<C>)) |
| 41 |
constexpr auto operator()(C pred, P proj = P{}) const |
| 42 |
{ |
| 43 |
return make_action_closure( |
| 44 |
bind_back(unique_fn{}, std::move(pred), std::move(proj))); |
| 45 |
} |
| 46 |
|
| 47 |
template(typename Rng, typename C = equal_to, typename P = identity)( |
| 48 |
requires forward_range<Rng> AND |
| 49 |
erasable_range<Rng &, iterator_t<Rng>, sentinel_t<Rng>> AND |
| 50 |
sortable<iterator_t<Rng>, C, P>) |
| 51 |
Rng operator()(Rng && rng, C pred = C{}, P proj = P{}) const |
| 52 |
{ |
| 53 |
auto it = ranges::unique(rng, std::move(pred), std::move(proj)); |
| 54 |
ranges::erase(rng, it, end(rng)); |
| 55 |
return static_cast<Rng &&>(rng); |
| 56 |
} |
| 57 |
}; |
| 58 |
|
| 59 |
/// \relates detail::unique_fn |
| 60 |
/// \sa action_closure |
| 61 |
RANGES_INLINE_VARIABLE(action_closure<unique_fn>, unique) |
| 62 |
} // namespace actions |
| 63 |
/// @} |
| 64 |
} // namespace ranges |
| 65 |
|
| 66 |
#include <range/v3/detail/epilogue.hpp> |
| 67 |
|
| 68 |
#endif |