Back to home page

EIC code displayed by LXR

 
 

    


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

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_FIND_FIRST_OF_H
0010 #define _LIBCPP___ALGORITHM_RANGES_FIND_FIRST_OF_H
0011 
0012 #include <__config>
0013 #include <__functional/identity.h>
0014 #include <__functional/invoke.h>
0015 #include <__functional/ranges_operations.h>
0016 #include <__iterator/concepts.h>
0017 #include <__iterator/indirectly_comparable.h>
0018 #include <__ranges/access.h>
0019 #include <__ranges/concepts.h>
0020 #include <__ranges/dangling.h>
0021 #include <__utility/move.h>
0022 
0023 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0024 #  pragma GCC system_header
0025 #endif
0026 
0027 _LIBCPP_PUSH_MACROS
0028 #include <__undef_macros>
0029 
0030 #if _LIBCPP_STD_VER >= 20
0031 
0032 _LIBCPP_BEGIN_NAMESPACE_STD
0033 
0034 namespace ranges {
0035 struct __find_first_of {
0036   template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Pred, class _Proj1, class _Proj2>
0037   _LIBCPP_HIDE_FROM_ABI constexpr static _Iter1 __find_first_of_impl(
0038       _Iter1 __first1,
0039       _Sent1 __last1,
0040       _Iter2 __first2,
0041       _Sent2 __last2,
0042       _Pred& __pred,
0043       _Proj1& __proj1,
0044       _Proj2& __proj2) {
0045     for (; __first1 != __last1; ++__first1) {
0046       for (auto __j = __first2; __j != __last2; ++__j) {
0047         if (std::invoke(__pred, std::invoke(__proj1, *__first1), std::invoke(__proj2, *__j)))
0048           return __first1;
0049       }
0050     }
0051     return __first1;
0052   }
0053 
0054   template <input_iterator _Iter1,
0055             sentinel_for<_Iter1> _Sent1,
0056             forward_iterator _Iter2,
0057             sentinel_for<_Iter2> _Sent2,
0058             class _Pred  = ranges::equal_to,
0059             class _Proj1 = identity,
0060             class _Proj2 = identity>
0061     requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2>
0062   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Iter1 operator()(
0063       _Iter1 __first1,
0064       _Sent1 __last1,
0065       _Iter2 __first2,
0066       _Sent2 __last2,
0067       _Pred __pred   = {},
0068       _Proj1 __proj1 = {},
0069       _Proj2 __proj2 = {}) const {
0070     return __find_first_of_impl(
0071         std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2), __pred, __proj1, __proj2);
0072   }
0073 
0074   template <input_range _Range1,
0075             forward_range _Range2,
0076             class _Pred  = ranges::equal_to,
0077             class _Proj1 = identity,
0078             class _Proj2 = identity>
0079     requires indirectly_comparable<iterator_t<_Range1>, iterator_t<_Range2>, _Pred, _Proj1, _Proj2>
0080   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Range1> operator()(
0081       _Range1&& __range1, _Range2&& __range2, _Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const {
0082     return __find_first_of_impl(
0083         ranges::begin(__range1),
0084         ranges::end(__range1),
0085         ranges::begin(__range2),
0086         ranges::end(__range2),
0087         __pred,
0088         __proj1,
0089         __proj2);
0090   }
0091 };
0092 
0093 inline namespace __cpo {
0094 inline constexpr auto find_first_of = __find_first_of{};
0095 } // namespace __cpo
0096 } // namespace ranges
0097 
0098 _LIBCPP_END_NAMESPACE_STD
0099 
0100 #endif // _LIBCPP_STD_VER >= 20
0101 
0102 _LIBCPP_POP_MACROS
0103 
0104 #endif // _LIBCPP___ALGORITHM_RANGES_FIND_FIRST_OF_H