1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef _LIBCPP___ALGORITHM_RANGES_STARTS_WITH_H 10 #define _LIBCPP___ALGORITHM_RANGES_STARTS_WITH_H 11 12 #include <__algorithm/in_in_result.h> 13 #include <__algorithm/ranges_mismatch.h> 14 #include <__config> 15 #include <__functional/identity.h> 16 #include <__functional/ranges_operations.h> 17 #include <__iterator/concepts.h> 18 #include <__iterator/indirectly_comparable.h> 19 #include <__ranges/access.h> 20 #include <__ranges/concepts.h> 21 #include <__utility/move.h> 22 23 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 24 # pragma GCC system_header 25 #endif 26 27 #if _LIBCPP_STD_VER >= 23 28 29 _LIBCPP_BEGIN_NAMESPACE_STD 30 31 namespace ranges { 32 namespace __starts_with { 33 struct __fn { 34 template <input_iterator _Iter1, 35 sentinel_for<_Iter1> _Sent1, 36 input_iterator _Iter2, 37 sentinel_for<_Iter2> _Sent2, 38 class _Pred = ranges::equal_to, 39 class _Proj1 = identity, 40 class _Proj2 = identity> 41 requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2> 42 _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()( 43 _Iter1 __first1, 44 _Sent1 __last1, 45 _Iter2 __first2, 46 _Sent2 __last2, 47 _Pred __pred = {}, 48 _Proj1 __proj1 = {}, 49 _Proj2 __proj2 = {}) const { 50 return __mismatch::__fn::__go( 51 std::move(__first1), 52 std::move(__last1), 53 std::move(__first2), 54 std::move(__last2), 55 __pred, 56 __proj1, 57 __proj2) 58 .in2 == __last2; 59 } 60 61 template <input_range _Range1, 62 input_range _Range2, 63 class _Pred = ranges::equal_to, 64 class _Proj1 = identity, 65 class _Proj2 = identity> 66 requires indirectly_comparable<iterator_t<_Range1>, iterator_t<_Range2>, _Pred, _Proj1, _Proj2> 67 _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()( 68 _Range1&& __range1, _Range2&& __range2, _Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const { 69 return __mismatch::__fn::__go( 70 ranges::begin(__range1), 71 ranges::end(__range1), 72 ranges::begin(__range2), 73 ranges::end(__range2), 74 __pred, 75 __proj1, 76 __proj2) 77 .in2 == ranges::end(__range2); 78 } 79 }; 80 } // namespace __starts_with 81 inline namespace __cpo { 82 inline constexpr auto starts_with = __starts_with::__fn{}; 83 } // namespace __cpo 84 } // namespace ranges 85 86 _LIBCPP_END_NAMESPACE_STD 87 88 #endif // _LIBCPP_STD_VER >= 23 89 90 #endif // _LIBCPP___ALGORITHM_RANGES_STARTS_WITH_H 91