File indexing completed on 2026-05-03 08:13:21
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LIBCPP___CXX03___ALGORITHM_RANGES_UNIQUE_COPY_H
0010 #define _LIBCPP___CXX03___ALGORITHM_RANGES_UNIQUE_COPY_H
0011
0012 #include <__cxx03/__algorithm/in_out_result.h>
0013 #include <__cxx03/__algorithm/iterator_operations.h>
0014 #include <__cxx03/__algorithm/make_projected.h>
0015 #include <__cxx03/__algorithm/unique_copy.h>
0016 #include <__cxx03/__concepts/same_as.h>
0017 #include <__cxx03/__config>
0018 #include <__cxx03/__functional/identity.h>
0019 #include <__cxx03/__functional/invoke.h>
0020 #include <__cxx03/__functional/ranges_operations.h>
0021 #include <__cxx03/__iterator/concepts.h>
0022 #include <__cxx03/__iterator/iterator_traits.h>
0023 #include <__cxx03/__iterator/projected.h>
0024 #include <__cxx03/__ranges/access.h>
0025 #include <__cxx03/__ranges/concepts.h>
0026 #include <__cxx03/__ranges/dangling.h>
0027 #include <__cxx03/__utility/forward.h>
0028 #include <__cxx03/__utility/move.h>
0029 #include <__cxx03/__utility/pair.h>
0030
0031 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0032 # pragma GCC system_header
0033 #endif
0034
0035 _LIBCPP_PUSH_MACROS
0036 #include <__cxx03/__undef_macros>
0037
0038 #if _LIBCPP_STD_VER >= 20
0039
0040 _LIBCPP_BEGIN_NAMESPACE_STD
0041
0042 namespace ranges {
0043
0044 template <class _InIter, class _OutIter>
0045 using unique_copy_result = in_out_result<_InIter, _OutIter>;
0046
0047 namespace __unique_copy {
0048
0049 template <class _InIter, class _OutIter>
0050 concept __can_reread_from_output = (input_iterator<_OutIter> && same_as<iter_value_t<_InIter>, iter_value_t<_OutIter>>);
0051
0052 struct __fn {
0053 template <class _InIter, class _OutIter>
0054 static consteval auto __get_algo_tag() {
0055 if constexpr (forward_iterator<_InIter>) {
0056 return __unique_copy_tags::__reread_from_input_tag{};
0057 } else if constexpr (__can_reread_from_output<_InIter, _OutIter>) {
0058 return __unique_copy_tags::__reread_from_output_tag{};
0059 } else if constexpr (indirectly_copyable_storable<_InIter, _OutIter>) {
0060 return __unique_copy_tags::__read_from_tmp_value_tag{};
0061 }
0062 }
0063
0064 template <class _InIter, class _OutIter>
0065 using __algo_tag_t = decltype(__get_algo_tag<_InIter, _OutIter>());
0066
0067 template <input_iterator _InIter,
0068 sentinel_for<_InIter> _Sent,
0069 weakly_incrementable _OutIter,
0070 class _Proj = identity,
0071 indirect_equivalence_relation<projected<_InIter, _Proj>> _Comp = ranges::equal_to>
0072 requires indirectly_copyable<_InIter, _OutIter> &&
0073 (forward_iterator<_InIter> ||
0074 (input_iterator<_OutIter> && same_as<iter_value_t<_InIter>, iter_value_t<_OutIter>>) ||
0075 indirectly_copyable_storable<_InIter, _OutIter>)
0076 _LIBCPP_HIDE_FROM_ABI constexpr unique_copy_result<_InIter, _OutIter>
0077 operator()(_InIter __first, _Sent __last, _OutIter __result, _Comp __comp = {}, _Proj __proj = {}) const {
0078 auto __ret = std::__unique_copy<_RangeAlgPolicy>(
0079 std::move(__first),
0080 std::move(__last),
0081 std::move(__result),
0082 std::__make_projected(__comp, __proj),
0083 __algo_tag_t<_InIter, _OutIter>());
0084 return {std::move(__ret.first), std::move(__ret.second)};
0085 }
0086
0087 template <input_range _Range,
0088 weakly_incrementable _OutIter,
0089 class _Proj = identity,
0090 indirect_equivalence_relation<projected<iterator_t<_Range>, _Proj>> _Comp = ranges::equal_to>
0091 requires indirectly_copyable<iterator_t<_Range>, _OutIter> &&
0092 (forward_iterator<iterator_t<_Range>> ||
0093 (input_iterator<_OutIter> && same_as<range_value_t<_Range>, iter_value_t<_OutIter>>) ||
0094 indirectly_copyable_storable<iterator_t<_Range>, _OutIter>)
0095 _LIBCPP_HIDE_FROM_ABI constexpr unique_copy_result<borrowed_iterator_t<_Range>, _OutIter>
0096 operator()(_Range&& __range, _OutIter __result, _Comp __comp = {}, _Proj __proj = {}) const {
0097 auto __ret = std::__unique_copy<_RangeAlgPolicy>(
0098 ranges::begin(__range),
0099 ranges::end(__range),
0100 std::move(__result),
0101 std::__make_projected(__comp, __proj),
0102 __algo_tag_t<iterator_t<_Range>, _OutIter>());
0103 return {std::move(__ret.first), std::move(__ret.second)};
0104 }
0105 };
0106
0107 }
0108
0109 inline namespace __cpo {
0110 inline constexpr auto unique_copy = __unique_copy::__fn{};
0111 }
0112 }
0113
0114 _LIBCPP_END_NAMESPACE_STD
0115
0116 #endif
0117
0118 _LIBCPP_POP_MACROS
0119
0120 #endif