brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.6 KiB · bc6c657 Raw
79 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef _LIBCPP___ALGORITHM_INCLUDES_H10#define _LIBCPP___ALGORITHM_INCLUDES_H11 12#include <__algorithm/comp.h>13#include <__algorithm/comp_ref_type.h>14#include <__config>15#include <__functional/identity.h>16#include <__type_traits/invoke.h>17#include <__type_traits/is_callable.h>18#include <__utility/move.h>19 20#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)21#  pragma GCC system_header22#endif23 24_LIBCPP_PUSH_MACROS25#include <__undef_macros>26 27_LIBCPP_BEGIN_NAMESPACE_STD28 29template <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) {38  for (; __first2 != __last2; ++__first1) {39    if (__first1 == __last1 ||40        std::__invoke(__comp, std::__invoke(__proj2, *__first2), std::__invoke(__proj1, *__first1)))41      return false;42    if (!std::__invoke(__comp, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2)))43      ++__first2;44  }45  return true;46}47 48template <class _InputIterator1, class _InputIterator2, class _Compare>49[[__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) {55  static_assert(56      __is_callable<_Compare&, decltype(*__first1), decltype(*__first2)>::value, "The comparator has to be callable");57 58  return std::__includes(59      std::move(__first1),60      std::move(__last1),61      std::move(__first2),62      std::move(__last2),63      static_cast<__comp_ref_type<_Compare> >(__comp),64      __identity(),65      __identity());66}67 68template <class _InputIterator1, class _InputIterator2>69[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool70includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) {71  return std::includes(std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2), __less<>());72}73 74_LIBCPP_END_NAMESPACE_STD75 76_LIBCPP_POP_MACROS77 78#endif // _LIBCPP___ALGORITHM_INCLUDES_H79