Path: blob/main/contrib/llvm-project/libcxx/include/__algorithm/includes.h
35232 views
//===----------------------------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef _LIBCPP___ALGORITHM_INCLUDES_H9#define _LIBCPP___ALGORITHM_INCLUDES_H1011#include <__algorithm/comp.h>12#include <__algorithm/comp_ref_type.h>13#include <__config>14#include <__functional/identity.h>15#include <__functional/invoke.h>16#include <__iterator/iterator_traits.h>17#include <__type_traits/is_callable.h>18#include <__utility/move.h>1920#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)21# pragma GCC system_header22#endif2324_LIBCPP_PUSH_MACROS25#include <__undef_macros>2627_LIBCPP_BEGIN_NAMESPACE_STD2829template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Comp, class _Proj1, class _Proj2>30_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __includes(31_Iter1 __first1,32_Sent1 __last1,33_Iter2 __first2,34_Sent2 __last2,35_Comp&& __comp,36_Proj1&& __proj1,37_Proj2&& __proj2) {38for (; __first2 != __last2; ++__first1) {39if (__first1 == __last1 ||40std::__invoke(__comp, std::__invoke(__proj2, *__first2), std::__invoke(__proj1, *__first1)))41return false;42if (!std::__invoke(__comp, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2)))43++__first2;44}45return true;46}4748template <class _InputIterator1, class _InputIterator2, class _Compare>49_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool50includes(_InputIterator1 __first1,51_InputIterator1 __last1,52_InputIterator2 __first2,53_InputIterator2 __last2,54_Compare __comp) {55static_assert(56__is_callable<_Compare, decltype(*__first1), decltype(*__first2)>::value, "Comparator has to be callable");5758return std::__includes(59std::move(__first1),60std::move(__last1),61std::move(__first2),62std::move(__last2),63static_cast<__comp_ref_type<_Compare> >(__comp),64__identity(),65__identity());66}6768template <class _InputIterator1, class _InputIterator2>69_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool70includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) {71return std::includes(std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2), __less<>());72}7374_LIBCPP_END_NAMESPACE_STD7576_LIBCPP_POP_MACROS7778#endif // _LIBCPP___ALGORITHM_INCLUDES_H798081