1a6b846aeSZijunZhaoCCK //===----------------------------------------------------------------------===// 2a6b846aeSZijunZhaoCCK // 3a6b846aeSZijunZhaoCCK // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4a6b846aeSZijunZhaoCCK // See https://llvm.org/LICENSE.txt for license information. 5a6b846aeSZijunZhaoCCK // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6a6b846aeSZijunZhaoCCK // 7a6b846aeSZijunZhaoCCK //===----------------------------------------------------------------------===// 8a6b846aeSZijunZhaoCCK 9a6b846aeSZijunZhaoCCK #ifndef _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H 10a6b846aeSZijunZhaoCCK #define _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H 11a6b846aeSZijunZhaoCCK 12a6b846aeSZijunZhaoCCK #include <__algorithm/ranges_search.h> 13a6b846aeSZijunZhaoCCK #include <__config> 14a6b846aeSZijunZhaoCCK #include <__functional/identity.h> 15a6b846aeSZijunZhaoCCK #include <__functional/ranges_operations.h> 16a6b846aeSZijunZhaoCCK #include <__functional/reference_wrapper.h> 17a6b846aeSZijunZhaoCCK #include <__iterator/concepts.h> 18a6b846aeSZijunZhaoCCK #include <__iterator/indirectly_comparable.h> 19a6b846aeSZijunZhaoCCK #include <__iterator/projected.h> 20a6b846aeSZijunZhaoCCK #include <__ranges/access.h> 21a6b846aeSZijunZhaoCCK #include <__ranges/concepts.h> 2204dbf7adSA. Jiang #include <__ranges/size.h> 23a6b846aeSZijunZhaoCCK #include <__ranges/subrange.h> 24a6b846aeSZijunZhaoCCK #include <__utility/move.h> 25a6b846aeSZijunZhaoCCK 26a6b846aeSZijunZhaoCCK #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 27a6b846aeSZijunZhaoCCK # pragma GCC system_header 28a6b846aeSZijunZhaoCCK #endif 29a6b846aeSZijunZhaoCCK 30a6b846aeSZijunZhaoCCK _LIBCPP_PUSH_MACROS 31a6b846aeSZijunZhaoCCK #include <__undef_macros> 32a6b846aeSZijunZhaoCCK 33a6b846aeSZijunZhaoCCK #if _LIBCPP_STD_VER >= 23 34a6b846aeSZijunZhaoCCK 35a6b846aeSZijunZhaoCCK _LIBCPP_BEGIN_NAMESPACE_STD 36a6b846aeSZijunZhaoCCK 37a6b846aeSZijunZhaoCCK namespace ranges { 38*d10dc5a0SChristopher Di Bella struct __contains_subrange { 39a6b846aeSZijunZhaoCCK template <forward_iterator _Iter1, 40a6b846aeSZijunZhaoCCK sentinel_for<_Iter1> _Sent1, 41a6b846aeSZijunZhaoCCK forward_iterator _Iter2, 42a6b846aeSZijunZhaoCCK sentinel_for<_Iter2> _Sent2, 43a6b846aeSZijunZhaoCCK class _Pred = ranges::equal_to, 44a6b846aeSZijunZhaoCCK class _Proj1 = identity, 45a6b846aeSZijunZhaoCCK class _Proj2 = identity> 46a6b846aeSZijunZhaoCCK requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2> 4783bc7b57SNikolas Klauser [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool static operator()( 48a6b846aeSZijunZhaoCCK _Iter1 __first1, 49a6b846aeSZijunZhaoCCK _Sent1 __last1, 50a6b846aeSZijunZhaoCCK _Iter2 __first2, 51a6b846aeSZijunZhaoCCK _Sent2 __last2, 52a6b846aeSZijunZhaoCCK _Pred __pred = {}, 53a6b846aeSZijunZhaoCCK _Proj1 __proj1 = {}, 54a6b846aeSZijunZhaoCCK _Proj2 __proj2 = {}) { 5504dbf7adSA. Jiang if (__first2 == __last2) 56a6b846aeSZijunZhaoCCK return true; 57a6b846aeSZijunZhaoCCK 58a6b846aeSZijunZhaoCCK auto __ret = ranges::search( 59a6b846aeSZijunZhaoCCK std::move(__first1), __last1, std::move(__first2), __last2, __pred, std::ref(__proj1), std::ref(__proj2)); 60a6b846aeSZijunZhaoCCK return __ret.empty() == false; 61a6b846aeSZijunZhaoCCK } 62a6b846aeSZijunZhaoCCK 63a6b846aeSZijunZhaoCCK template <forward_range _Range1, 64a6b846aeSZijunZhaoCCK forward_range _Range2, 65a6b846aeSZijunZhaoCCK class _Pred = ranges::equal_to, 66a6b846aeSZijunZhaoCCK class _Proj1 = identity, 67a6b846aeSZijunZhaoCCK class _Proj2 = identity> 68a6b846aeSZijunZhaoCCK requires indirectly_comparable<iterator_t<_Range1>, iterator_t<_Range2>, _Pred, _Proj1, _Proj2> 6983bc7b57SNikolas Klauser [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool static 70a6b846aeSZijunZhaoCCK operator()(_Range1&& __range1, _Range2&& __range2, _Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) { 71a6b846aeSZijunZhaoCCK if constexpr (sized_range<_Range2>) { 7204dbf7adSA. Jiang if (ranges::size(__range2) == 0) 73a6b846aeSZijunZhaoCCK return true; 7404dbf7adSA. Jiang } else { 7504dbf7adSA. Jiang if (ranges::begin(__range2) == ranges::end(__range2)) 7604dbf7adSA. Jiang return true; 7704dbf7adSA. Jiang } 78a6b846aeSZijunZhaoCCK 79a6b846aeSZijunZhaoCCK auto __ret = ranges::search(__range1, __range2, __pred, std::ref(__proj1), std::ref(__proj2)); 80a6b846aeSZijunZhaoCCK return __ret.empty() == false; 81a6b846aeSZijunZhaoCCK } 82a6b846aeSZijunZhaoCCK }; 83a6b846aeSZijunZhaoCCK 84a6b846aeSZijunZhaoCCK inline namespace __cpo { 85*d10dc5a0SChristopher Di Bella inline constexpr auto contains_subrange = __contains_subrange{}; 86a6b846aeSZijunZhaoCCK } // namespace __cpo 87a6b846aeSZijunZhaoCCK } // namespace ranges 88a6b846aeSZijunZhaoCCK 89a6b846aeSZijunZhaoCCK _LIBCPP_END_NAMESPACE_STD 90a6b846aeSZijunZhaoCCK 91a6b846aeSZijunZhaoCCK #endif // _LIBCPP_STD_VER >= 23 92a6b846aeSZijunZhaoCCK 93a6b846aeSZijunZhaoCCK _LIBCPP_POP_MACROS 94a6b846aeSZijunZhaoCCK 95a6b846aeSZijunZhaoCCK #endif // _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H 96