xref: /llvm-project/libcxx/include/__algorithm/includes.h (revision 7ed7d4ccb8991e2b5b95334b508f8cec2faee737)
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_INCLUDES_H
10 #define _LIBCPP___ALGORITHM_INCLUDES_H
11 
12 #include <__config>
13 #include <__algorithm/comp_ref_type.h>
14 #include <__iterator/iterator_traits.h>
15 
16 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17 #pragma GCC system_header
18 #endif
19 
20 _LIBCPP_PUSH_MACROS
21 #include <__undef_macros>
22 
23 _LIBCPP_BEGIN_NAMESPACE_STD
24 
25 template <class _Compare, class _InputIterator1, class _InputIterator2>
26 _LIBCPP_CONSTEXPR_AFTER_CXX17 bool
27 __includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2,
28            _Compare __comp)
29 {
30     for (; __first2 != __last2; ++__first1)
31     {
32         if (__first1 == __last1 || __comp(*__first2, *__first1))
33             return false;
34         if (!__comp(*__first1, *__first2))
35             ++__first2;
36     }
37     return true;
38 }
39 
40 template <class _InputIterator1, class _InputIterator2, class _Compare>
41 _LIBCPP_NODISCARD_EXT inline
42 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
43 bool
44 includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2,
45          _Compare __comp)
46 {
47     typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
48     return _VSTD::__includes<_Comp_ref>(__first1, __last1, __first2, __last2, __comp);
49 }
50 
51 template <class _InputIterator1, class _InputIterator2>
52 _LIBCPP_NODISCARD_EXT inline
53 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
54 bool
55 includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2)
56 {
57     return _VSTD::includes(__first1, __last1, __first2, __last2,
58                           __less<typename iterator_traits<_InputIterator1>::value_type,
59                                  typename iterator_traits<_InputIterator2>::value_type>());
60 }
61 
62 _LIBCPP_END_NAMESPACE_STD
63 
64 _LIBCPP_POP_MACROS
65 
66 #endif // _LIBCPP___ALGORITHM_INCLUDES_H
67