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_CONTAINS_SUBRANGE_H
0010 #define _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H
0011 
0012 #include <__algorithm/ranges_search.h>
0013 #include <__config>
0014 #include <__functional/identity.h>
0015 #include <__functional/ranges_operations.h>
0016 #include <__functional/reference_wrapper.h>
0017 #include <__iterator/concepts.h>
0018 #include <__iterator/indirectly_comparable.h>
0019 #include <__iterator/projected.h>
0020 #include <__ranges/access.h>
0021 #include <__ranges/concepts.h>
0022 #include <__ranges/size.h>
0023 #include <__ranges/subrange.h>
0024 #include <__utility/move.h>
0025 
0026 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0027 #  pragma GCC system_header
0028 #endif
0029 
0030 _LIBCPP_PUSH_MACROS
0031 #include <__undef_macros>
0032 
0033 #if _LIBCPP_STD_VER >= 23
0034 
0035 _LIBCPP_BEGIN_NAMESPACE_STD
0036 
0037 namespace ranges {
0038 struct __contains_subrange {
0039   template <forward_iterator _Iter1,
0040             sentinel_for<_Iter1> _Sent1,
0041             forward_iterator _Iter2,
0042             sentinel_for<_Iter2> _Sent2,
0043             class _Pred  = ranges::equal_to,
0044             class _Proj1 = identity,
0045             class _Proj2 = identity>
0046     requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2>
0047   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool static operator()(
0048       _Iter1 __first1,
0049       _Sent1 __last1,
0050       _Iter2 __first2,
0051       _Sent2 __last2,
0052       _Pred __pred   = {},
0053       _Proj1 __proj1 = {},
0054       _Proj2 __proj2 = {}) {
0055     if (__first2 == __last2)
0056       return true;
0057 
0058     auto __ret = ranges::search(
0059         std::move(__first1), __last1, std::move(__first2), __last2, __pred, std::ref(__proj1), std::ref(__proj2));
0060     return __ret.empty() == false;
0061   }
0062 
0063   template <forward_range _Range1,
0064             forward_range _Range2,
0065             class _Pred  = ranges::equal_to,
0066             class _Proj1 = identity,
0067             class _Proj2 = identity>
0068     requires indirectly_comparable<iterator_t<_Range1>, iterator_t<_Range2>, _Pred, _Proj1, _Proj2>
0069   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool static
0070   operator()(_Range1&& __range1, _Range2&& __range2, _Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) {
0071     if constexpr (sized_range<_Range2>) {
0072       if (ranges::size(__range2) == 0)
0073         return true;
0074     } else {
0075       if (ranges::begin(__range2) == ranges::end(__range2))
0076         return true;
0077     }
0078 
0079     auto __ret = ranges::search(__range1, __range2, __pred, std::ref(__proj1), std::ref(__proj2));
0080     return __ret.empty() == false;
0081   }
0082 };
0083 
0084 inline namespace __cpo {
0085 inline constexpr auto contains_subrange = __contains_subrange{};
0086 } // namespace __cpo
0087 } // namespace ranges
0088 
0089 _LIBCPP_END_NAMESPACE_STD
0090 
0091 #endif // _LIBCPP_STD_VER >= 23
0092 
0093 _LIBCPP_POP_MACROS
0094 
0095 #endif // _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H