brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.6 KiB · 194f508 Raw
80 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___CXX03___ALGORITHM_INCLUDES_H10#define _LIBCPP___CXX03___ALGORITHM_INCLUDES_H11 12#include <__cxx03/__algorithm/comp.h>13#include <__cxx03/__algorithm/comp_ref_type.h>14#include <__cxx03/__config>15#include <__cxx03/__functional/identity.h>16#include <__cxx03/__iterator/iterator_traits.h>17#include <__cxx03/__type_traits/invoke.h>18#include <__cxx03/__type_traits/is_callable.h>19#include <__cxx03/__utility/move.h>20 21#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)22#  pragma GCC system_header23#endif24 25_LIBCPP_PUSH_MACROS26#include <__cxx03/__undef_macros>27 28_LIBCPP_BEGIN_NAMESPACE_STD29 30template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Comp, class _Proj1, class _Proj2>31_LIBCPP_HIDE_FROM_ABI bool __includes(32    _Iter1 __first1,33    _Sent1 __last1,34    _Iter2 __first2,35    _Sent2 __last2,36    _Comp&& __comp,37    _Proj1&& __proj1,38    _Proj2&& __proj2) {39  for (; __first2 != __last2; ++__first1) {40    if (__first1 == __last1 ||41        std::__invoke(__comp, std::__invoke(__proj2, *__first2), std::__invoke(__proj1, *__first1)))42      return false;43    if (!std::__invoke(__comp, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2)))44      ++__first2;45  }46  return true;47}48 49template <class _InputIterator1, class _InputIterator2, class _Compare>50_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool51includes(_InputIterator1 __first1,52         _InputIterator1 __last1,53         _InputIterator2 __first2,54         _InputIterator2 __last2,55         _Compare __comp) {56  static_assert(57      __is_callable<_Compare, decltype(*__first1), decltype(*__first2)>::value, "Comparator has to be callable");58 59  return std::__includes(60      std::move(__first1),61      std::move(__last1),62      std::move(__first2),63      std::move(__last2),64      static_cast<__comp_ref_type<_Compare> >(__comp),65      __identity(),66      __identity());67}68 69template <class _InputIterator1, class _InputIterator2>70_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool71includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) {72  return std::includes(std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2), __less<>());73}74 75_LIBCPP_END_NAMESPACE_STD76 77_LIBCPP_POP_MACROS78 79#endif // _LIBCPP___CXX03___ALGORITHM_INCLUDES_H80