ranges_unique.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef _LIBCPP___ALGORITHM_RANGES_UNIQUE_H
  9. #define _LIBCPP___ALGORITHM_RANGES_UNIQUE_H
  10. #include <__algorithm/iterator_operations.h>
  11. #include <__algorithm/make_projected.h>
  12. #include <__algorithm/unique.h>
  13. #include <__config>
  14. #include <__functional/identity.h>
  15. #include <__functional/invoke.h>
  16. #include <__functional/ranges_operations.h>
  17. #include <__iterator/concepts.h>
  18. #include <__iterator/iterator_traits.h>
  19. #include <__iterator/permutable.h>
  20. #include <__iterator/projected.h>
  21. #include <__ranges/access.h>
  22. #include <__ranges/concepts.h>
  23. #include <__ranges/dangling.h>
  24. #include <__ranges/subrange.h>
  25. #include <__utility/forward.h>
  26. #include <__utility/move.h>
  27. #include <__utility/pair.h>
  28. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  29. # pragma GCC system_header
  30. #endif
  31. #if _LIBCPP_STD_VER >= 20
  32. _LIBCPP_BEGIN_NAMESPACE_STD
  33. namespace ranges {
  34. namespace __unique {
  35. struct __fn {
  36. template <permutable _Iter,
  37. sentinel_for<_Iter> _Sent,
  38. class _Proj = identity,
  39. indirect_equivalence_relation<projected<_Iter, _Proj>> _Comp = ranges::equal_to>
  40. _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr subrange<_Iter>
  41. operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const {
  42. auto __ret =
  43. std::__unique<_RangeAlgPolicy>(std::move(__first), std::move(__last), std::__make_projected(__comp, __proj));
  44. return {std::move(__ret.first), std::move(__ret.second)};
  45. }
  46. template <forward_range _Range,
  47. class _Proj = identity,
  48. indirect_equivalence_relation<projected<iterator_t<_Range>, _Proj>> _Comp = ranges::equal_to>
  49. requires permutable<iterator_t<_Range>>
  50. _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr borrowed_subrange_t<_Range>
  51. operator()(_Range&& __range, _Comp __comp = {}, _Proj __proj = {}) const {
  52. auto __ret = std::__unique<_RangeAlgPolicy>(
  53. ranges::begin(__range), ranges::end(__range), std::__make_projected(__comp, __proj));
  54. return {std::move(__ret.first), std::move(__ret.second)};
  55. }
  56. };
  57. } // namespace __unique
  58. inline namespace __cpo {
  59. inline constexpr auto unique = __unique::__fn{};
  60. } // namespace __cpo
  61. } // namespace ranges
  62. _LIBCPP_END_NAMESPACE_STD
  63. #endif // _LIBCPP_STD_VER >= 20
  64. #endif // _LIBCPP___ALGORITHM_RANGES_UNIQUE_H