1753f127fSDimitry Andric //===----------------------------------------------------------------------===// 2753f127fSDimitry Andric // 3753f127fSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4753f127fSDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5753f127fSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6753f127fSDimitry Andric // 7753f127fSDimitry Andric //===----------------------------------------------------------------------===// 8753f127fSDimitry Andric 9753f127fSDimitry Andric #ifndef _LIBCPP___ALGORITHM_RANGES_UNIQUE_H 10753f127fSDimitry Andric #define _LIBCPP___ALGORITHM_RANGES_UNIQUE_H 11753f127fSDimitry Andric 1261cfbce3SDimitry Andric #include <__algorithm/iterator_operations.h> 13753f127fSDimitry Andric #include <__algorithm/make_projected.h> 14753f127fSDimitry Andric #include <__algorithm/unique.h> 15753f127fSDimitry Andric #include <__config> 16753f127fSDimitry Andric #include <__functional/identity.h> 17753f127fSDimitry Andric #include <__functional/invoke.h> 18753f127fSDimitry Andric #include <__functional/ranges_operations.h> 19753f127fSDimitry Andric #include <__iterator/concepts.h> 20753f127fSDimitry Andric #include <__iterator/iterator_traits.h> 21753f127fSDimitry Andric #include <__iterator/permutable.h> 22753f127fSDimitry Andric #include <__iterator/projected.h> 23753f127fSDimitry Andric #include <__ranges/access.h> 24753f127fSDimitry Andric #include <__ranges/concepts.h> 25753f127fSDimitry Andric #include <__ranges/dangling.h> 26753f127fSDimitry Andric #include <__ranges/subrange.h> 27753f127fSDimitry Andric #include <__utility/forward.h> 28753f127fSDimitry Andric #include <__utility/move.h> 29bdd1243dSDimitry Andric #include <__utility/pair.h> 30753f127fSDimitry Andric 31753f127fSDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 32753f127fSDimitry Andric # pragma GCC system_header 33753f127fSDimitry Andric #endif 34753f127fSDimitry Andric 35b3edf446SDimitry Andric _LIBCPP_PUSH_MACROS 36b3edf446SDimitry Andric #include <__undef_macros> 37b3edf446SDimitry Andric 3806c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 20 39753f127fSDimitry Andric 40753f127fSDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD 41753f127fSDimitry Andric 42753f127fSDimitry Andric namespace ranges { 43753f127fSDimitry Andric namespace __unique { 44753f127fSDimitry Andric 45753f127fSDimitry Andric struct __fn { 4606c3fb27SDimitry Andric template <permutable _Iter, 4761cfbce3SDimitry Andric sentinel_for<_Iter> _Sent, 4861cfbce3SDimitry Andric class _Proj = identity, 49753f127fSDimitry Andric indirect_equivalence_relation<projected<_Iter, _Proj>> _Comp = ranges::equal_to> 50*0fca6ea1SDimitry Andric [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr subrange<_Iter> operator__fn5161cfbce3SDimitry Andric operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const { 5206c3fb27SDimitry Andric auto __ret = 5306c3fb27SDimitry Andric std::__unique<_RangeAlgPolicy>(std::move(__first), std::move(__last), std::__make_projected(__comp, __proj)); 5461cfbce3SDimitry Andric return {std::move(__ret.first), std::move(__ret.second)}; 55753f127fSDimitry Andric } 56753f127fSDimitry Andric 5706c3fb27SDimitry Andric template <forward_range _Range, 5861cfbce3SDimitry Andric class _Proj = identity, 59753f127fSDimitry Andric indirect_equivalence_relation<projected<iterator_t<_Range>, _Proj>> _Comp = ranges::equal_to> 60753f127fSDimitry Andric requires permutable<iterator_t<_Range>> 61*0fca6ea1SDimitry Andric [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr borrowed_subrange_t<_Range> operator__fn6261cfbce3SDimitry Andric operator()(_Range&& __range, _Comp __comp = {}, _Proj __proj = {}) const { 6361cfbce3SDimitry Andric auto __ret = std::__unique<_RangeAlgPolicy>( 6461cfbce3SDimitry Andric ranges::begin(__range), ranges::end(__range), std::__make_projected(__comp, __proj)); 6561cfbce3SDimitry Andric return {std::move(__ret.first), std::move(__ret.second)}; 66753f127fSDimitry Andric } 67753f127fSDimitry Andric }; 68753f127fSDimitry Andric 69753f127fSDimitry Andric } // namespace __unique 70753f127fSDimitry Andric 71753f127fSDimitry Andric inline namespace __cpo { 72753f127fSDimitry Andric inline constexpr auto unique = __unique::__fn{}; 73753f127fSDimitry Andric } // namespace __cpo 74753f127fSDimitry Andric } // namespace ranges 75753f127fSDimitry Andric 76753f127fSDimitry Andric _LIBCPP_END_NAMESPACE_STD 77753f127fSDimitry Andric 7806c3fb27SDimitry Andric #endif // _LIBCPP_STD_VER >= 20 79753f127fSDimitry Andric 80b3edf446SDimitry Andric _LIBCPP_POP_MACROS 81b3edf446SDimitry Andric 82753f127fSDimitry Andric #endif // _LIBCPP___ALGORITHM_RANGES_UNIQUE_H 83