Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

69 lines
2.1KB

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