Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:11

0001 //===----------------------------------------------------------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef _LIBCPP___ALGORITHM_RANGES_UNIQUE_COPY_H
0010 #define _LIBCPP___ALGORITHM_RANGES_UNIQUE_COPY_H
0011 
0012 #include <__algorithm/in_out_result.h>
0013 #include <__algorithm/iterator_operations.h>
0014 #include <__algorithm/make_projected.h>
0015 #include <__algorithm/unique_copy.h>
0016 #include <__concepts/same_as.h>
0017 #include <__config>
0018 #include <__functional/identity.h>
0019 #include <__functional/invoke.h>
0020 #include <__functional/ranges_operations.h>
0021 #include <__iterator/concepts.h>
0022 #include <__iterator/iterator_traits.h>
0023 #include <__iterator/projected.h>
0024 #include <__ranges/access.h>
0025 #include <__ranges/concepts.h>
0026 #include <__ranges/dangling.h>
0027 #include <__utility/forward.h>
0028 #include <__utility/move.h>
0029 #include <__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 <__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 template <class _InIter, class _OutIter>
0048 concept __can_reread_from_output = (input_iterator<_OutIter> && same_as<iter_value_t<_InIter>, iter_value_t<_OutIter>>);
0049 
0050 struct __unique_copy {
0051   template <class _InIter, class _OutIter>
0052   static consteval auto __get_algo_tag() {
0053     if constexpr (forward_iterator<_InIter>) {
0054       return __unique_copy_tags::__reread_from_input_tag{};
0055     } else if constexpr (__can_reread_from_output<_InIter, _OutIter>) {
0056       return __unique_copy_tags::__reread_from_output_tag{};
0057     } else if constexpr (indirectly_copyable_storable<_InIter, _OutIter>) {
0058       return __unique_copy_tags::__read_from_tmp_value_tag{};
0059     }
0060   }
0061 
0062   template <class _InIter, class _OutIter>
0063   using __algo_tag_t _LIBCPP_NODEBUG = decltype(__get_algo_tag<_InIter, _OutIter>());
0064 
0065   template <input_iterator _InIter,
0066             sentinel_for<_InIter> _Sent,
0067             weakly_incrementable _OutIter,
0068             class _Proj                                                    = identity,
0069             indirect_equivalence_relation<projected<_InIter, _Proj>> _Comp = ranges::equal_to>
0070     requires indirectly_copyable<_InIter, _OutIter> &&
0071              (forward_iterator<_InIter> ||
0072               (input_iterator<_OutIter> && same_as<iter_value_t<_InIter>, iter_value_t<_OutIter>>) ||
0073               indirectly_copyable_storable<_InIter, _OutIter>)
0074   _LIBCPP_HIDE_FROM_ABI constexpr unique_copy_result<_InIter, _OutIter>
0075   operator()(_InIter __first, _Sent __last, _OutIter __result, _Comp __comp = {}, _Proj __proj = {}) const {
0076     auto __ret = std::__unique_copy<_RangeAlgPolicy>(
0077         std::move(__first),
0078         std::move(__last),
0079         std::move(__result),
0080         std::__make_projected(__comp, __proj),
0081         __algo_tag_t<_InIter, _OutIter>());
0082     return {std::move(__ret.first), std::move(__ret.second)};
0083   }
0084 
0085   template <input_range _Range,
0086             weakly_incrementable _OutIter,
0087             class _Proj                                                               = identity,
0088             indirect_equivalence_relation<projected<iterator_t<_Range>, _Proj>> _Comp = ranges::equal_to>
0089     requires indirectly_copyable<iterator_t<_Range>, _OutIter> &&
0090              (forward_iterator<iterator_t<_Range>> ||
0091               (input_iterator<_OutIter> && same_as<range_value_t<_Range>, iter_value_t<_OutIter>>) ||
0092               indirectly_copyable_storable<iterator_t<_Range>, _OutIter>)
0093   _LIBCPP_HIDE_FROM_ABI constexpr unique_copy_result<borrowed_iterator_t<_Range>, _OutIter>
0094   operator()(_Range&& __range, _OutIter __result, _Comp __comp = {}, _Proj __proj = {}) const {
0095     auto __ret = std::__unique_copy<_RangeAlgPolicy>(
0096         ranges::begin(__range),
0097         ranges::end(__range),
0098         std::move(__result),
0099         std::__make_projected(__comp, __proj),
0100         __algo_tag_t<iterator_t<_Range>, _OutIter>());
0101     return {std::move(__ret.first), std::move(__ret.second)};
0102   }
0103 };
0104 
0105 inline namespace __cpo {
0106 inline constexpr auto unique_copy = __unique_copy{};
0107 } // namespace __cpo
0108 } // namespace ranges
0109 
0110 _LIBCPP_END_NAMESPACE_STD
0111 
0112 #endif // _LIBCPP_STD_VER >= 20
0113 
0114 _LIBCPP_POP_MACROS
0115 
0116 #endif // _LIBCPP___ALGORITHM_RANGES_UNIQUE_COPY_H