| 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_VIEW_UNIQUE_HPP |
| 15 |
#define RANGES_V3_VIEW_UNIQUE_HPP |
| 16 |
|
| 17 |
#include <utility> |
| 18 |
|
| 19 |
#include <meta/meta.hpp> |
| 20 |
|
| 21 |
#include <range/v3/range_fwd.hpp> |
| 22 |
|
| 23 |
#include <range/v3/functional/bind_back.hpp> |
| 24 |
#include <range/v3/functional/not_fn.hpp> |
| 25 |
#include <range/v3/utility/static_const.hpp> |
| 26 |
#include <range/v3/view/adjacent_filter.hpp> |
| 27 |
#include <range/v3/view/all.hpp> |
| 28 |
#include <range/v3/view/view.hpp> |
| 29 |
|
| 30 |
#include <range/v3/detail/prologue.hpp> |
| 31 |
|
| 32 |
namespace ranges |
| 33 |
{ |
| 34 |
/// \addtogroup group-views |
| 35 |
/// @{ |
| 36 |
namespace views |
| 37 |
{ |
| 38 |
struct unique_base_fn |
| 39 |
{ |
| 40 |
template(typename Rng, typename C = equal_to)( |
| 41 |
requires viewable_range<Rng> AND forward_range<Rng> AND |
| 42 |
indirect_relation<C, iterator_t<Rng>>) |
| 43 |
constexpr adjacent_filter_view<all_t<Rng>, logical_negate<C>> // |
| 44 |
operator()(Rng && rng, C pred = {}) const |
| 45 |
{ |
| 46 |
return {all(static_cast<Rng &&>(rng)), not_fn(pred)}; |
| 47 |
} |
| 48 |
}; |
| 49 |
|
| 50 |
struct unique_fn : unique_base_fn |
| 51 |
{ |
| 52 |
using unique_base_fn::operator(); |
| 53 |
|
| 54 |
template(typename C)( |
| 55 |
requires (!range<C>)) |
| 56 |
constexpr auto operator()(C && pred) const |
| 57 |
{ |
| 58 |
return make_view_closure( |
| 59 |
bind_back(unique_base_fn{}, static_cast<C &&>(pred))); |
| 60 |
} |
| 61 |
}; |
| 62 |
|
| 63 |
/// \relates unique_fn |
| 64 |
/// \ingroup group-views |
| 65 |
RANGES_INLINE_VARIABLE(view_closure<unique_fn>, unique) |
| 66 |
} // namespace views |
| 67 |
/// @} |
| 68 |
} // namespace ranges |
| 69 |
|
| 70 |
#include <range/v3/detail/epilogue.hpp> |
| 71 |
|
| 72 |
#endif |