mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
update libcxx to LLVM 15
release/15.x commit 134fd359a5d884f16662a9edd22ab24feeb1498c
This commit is contained in:
parent
ac5c6b6061
commit
8278eb8837
840 changed files with 36287 additions and 20140 deletions
28
lib/libcxx/include/__algorithm/adjacent_find.h
vendored
28
lib/libcxx/include/__algorithm/adjacent_find.h
vendored
|
|
@ -11,34 +11,42 @@
|
|||
#define _LIBCPP___ALGORITHM_ADJACENT_FIND_H
|
||||
|
||||
#include <__algorithm/comp.h>
|
||||
#include <__algorithm/iterator_operations.h>
|
||||
#include <__config>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__utility/move.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _ForwardIterator, class _BinaryPredicate>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
|
||||
adjacent_find(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred) {
|
||||
if (__first != __last) {
|
||||
_ForwardIterator __i = __first;
|
||||
template <class _Iter, class _Sent, class _BinaryPredicate>
|
||||
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _Iter
|
||||
__adjacent_find(_Iter __first, _Sent __last, _BinaryPredicate&& __pred) {
|
||||
if (__first == __last)
|
||||
return __first;
|
||||
_Iter __i = __first;
|
||||
while (++__i != __last) {
|
||||
if (__pred(*__first, *__i))
|
||||
return __first;
|
||||
__first = __i;
|
||||
}
|
||||
}
|
||||
return __last;
|
||||
return __i;
|
||||
}
|
||||
|
||||
template <class _ForwardIterator, class _BinaryPredicate>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
|
||||
adjacent_find(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred) {
|
||||
return std::__adjacent_find(std::move(__first), std::move(__last), __pred);
|
||||
}
|
||||
|
||||
template <class _ForwardIterator>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
|
||||
adjacent_find(_ForwardIterator __first, _ForwardIterator __last) {
|
||||
typedef typename iterator_traits<_ForwardIterator>::value_type __v;
|
||||
return _VSTD::adjacent_find(__first, __last, __equal_to<__v>());
|
||||
return std::adjacent_find(std::move(__first), std::move(__last), __equal_to<__v>());
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
|
|
|||
52
lib/libcxx/include/__algorithm/algorithm_family.h
vendored
Normal file
52
lib/libcxx/include/__algorithm/algorithm_family.h
vendored
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_ALGORITHM_FAMILY_H
|
||||
#define _LIBCPP___ALGORITHM_ALGORITHM_FAMILY_H
|
||||
|
||||
#include <__algorithm/iterator_operations.h>
|
||||
#include <__algorithm/move.h>
|
||||
#include <__algorithm/ranges_move.h>
|
||||
#include <__config>
|
||||
#include <__utility/move.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _AlgPolicy>
|
||||
struct _AlgFamily;
|
||||
|
||||
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
template <>
|
||||
struct _AlgFamily<_RangeAlgPolicy> {
|
||||
static constexpr auto __move = ranges::move;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
template <>
|
||||
struct _AlgFamily<_ClassicAlgPolicy> {
|
||||
|
||||
// move
|
||||
template <class _InputIterator, class _OutputIterator>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 static _OutputIterator
|
||||
__move(_InputIterator __first, _InputIterator __last, _OutputIterator __result) {
|
||||
return std::move(
|
||||
std::move(__first),
|
||||
std::move(__last),
|
||||
std::move(__result));
|
||||
}
|
||||
};
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_ALGORITHM_FAMILY_H
|
||||
2
lib/libcxx/include/__algorithm/all_of.h
vendored
2
lib/libcxx/include/__algorithm/all_of.h
vendored
|
|
@ -13,7 +13,7 @@
|
|||
#include <__config>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
|
|
|||
2
lib/libcxx/include/__algorithm/any_of.h
vendored
2
lib/libcxx/include/__algorithm/any_of.h
vendored
|
|
@ -13,7 +13,7 @@
|
|||
#include <__config>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
|
|
|||
22
lib/libcxx/include/__algorithm/binary_search.h
vendored
22
lib/libcxx/include/__algorithm/binary_search.h
vendored
|
|
@ -16,37 +16,29 @@
|
|||
#include <__iterator/iterator_traits.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _Compare, class _ForwardIterator, class _Tp>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
bool
|
||||
__binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
|
||||
{
|
||||
__first = _VSTD::__lower_bound<_Compare>(__first, __last, __value_, __comp);
|
||||
return __first != __last && !__comp(__value_, *__first);
|
||||
}
|
||||
|
||||
template <class _ForwardIterator, class _Tp, class _Compare>
|
||||
_LIBCPP_NODISCARD_EXT inline
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
bool
|
||||
binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
|
||||
binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp)
|
||||
{
|
||||
typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
|
||||
return _VSTD::__binary_search<_Comp_ref>(__first, __last, __value_, __comp);
|
||||
using _Comp_ref = typename __comp_ref_type<_Compare>::type;
|
||||
__first = std::lower_bound<_ForwardIterator, _Tp, _Comp_ref>(__first, __last, __value, __comp);
|
||||
return __first != __last && !__comp(__value, *__first);
|
||||
}
|
||||
|
||||
template <class _ForwardIterator, class _Tp>
|
||||
_LIBCPP_NODISCARD_EXT inline
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
bool
|
||||
binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_)
|
||||
binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
|
||||
{
|
||||
return _VSTD::binary_search(__first, __last, __value_,
|
||||
return std::binary_search(__first, __last, __value,
|
||||
__less<typename iterator_traits<_ForwardIterator>::value_type, _Tp>());
|
||||
}
|
||||
|
||||
|
|
|
|||
4
lib/libcxx/include/__algorithm/clamp.h
vendored
4
lib/libcxx/include/__algorithm/clamp.h
vendored
|
|
@ -10,11 +10,11 @@
|
|||
#define _LIBCPP___ALGORITHM_CLAMP_H
|
||||
|
||||
#include <__algorithm/comp.h>
|
||||
#include <__assert>
|
||||
#include <__config>
|
||||
#include <__debug>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
|
|
|||
2
lib/libcxx/include/__algorithm/comp.h
vendored
2
lib/libcxx/include/__algorithm/comp.h
vendored
|
|
@ -12,7 +12,7 @@
|
|||
#include <__config>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
|
|
|||
23
lib/libcxx/include/__algorithm/comp_ref_type.h
vendored
23
lib/libcxx/include/__algorithm/comp_ref_type.h
vendored
|
|
@ -10,20 +10,15 @@
|
|||
#define _LIBCPP___ALGORITHM_COMP_REF_TYPE_H
|
||||
|
||||
#include <__config>
|
||||
|
||||
#ifdef _LIBCPP_DEBUG
|
||||
# include <__debug>
|
||||
# include <__utility/declval.h>
|
||||
#endif
|
||||
#include <__debug>
|
||||
#include <__utility/declval.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
#ifdef _LIBCPP_DEBUG
|
||||
|
||||
template <class _Compare>
|
||||
struct __debug_less
|
||||
{
|
||||
|
|
@ -57,8 +52,10 @@ struct __debug_less
|
|||
decltype((void)declval<_Compare&>()(
|
||||
declval<_LHS &>(), declval<_RHS &>()))
|
||||
__do_compare_assert(int, _LHS & __l, _RHS & __r) {
|
||||
_LIBCPP_ASSERT(!__comp_(__l, __r),
|
||||
_LIBCPP_DEBUG_ASSERT(!__comp_(__l, __r),
|
||||
"Comparator does not induce a strict weak ordering");
|
||||
(void)__l;
|
||||
(void)__r;
|
||||
}
|
||||
|
||||
template <class _LHS, class _RHS>
|
||||
|
|
@ -67,16 +64,14 @@ struct __debug_less
|
|||
void __do_compare_assert(long, _LHS &, _RHS &) {}
|
||||
};
|
||||
|
||||
#endif // _LIBCPP_DEBUG
|
||||
|
||||
template <class _Comp>
|
||||
struct __comp_ref_type {
|
||||
// Pass the comparator by lvalue reference. Or in debug mode, using a
|
||||
// debugging wrapper that stores a reference.
|
||||
#ifndef _LIBCPP_DEBUG
|
||||
typedef _Comp& type;
|
||||
#else
|
||||
#ifdef _LIBCPP_ENABLE_DEBUG_MODE
|
||||
typedef __debug_less<_Comp> type;
|
||||
#else
|
||||
typedef _Comp& type;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
|
|
|||
107
lib/libcxx/include/__algorithm/copy.h
vendored
107
lib/libcxx/include/__algorithm/copy.h
vendored
|
|
@ -10,66 +10,97 @@
|
|||
#define _LIBCPP___ALGORITHM_COPY_H
|
||||
|
||||
#include <__algorithm/unwrap_iter.h>
|
||||
#include <__algorithm/unwrap_range.h>
|
||||
#include <__config>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__iterator/reverse_iterator.h>
|
||||
#include <__utility/move.h>
|
||||
#include <__utility/pair.h>
|
||||
#include <cstring>
|
||||
#include <type_traits>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
// copy
|
||||
|
||||
template <class _InputIterator, class _OutputIterator>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
_OutputIterator
|
||||
__copy_constexpr(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
|
||||
{
|
||||
for (; __first != __last; ++__first, (void) ++__result)
|
||||
template <class _InIter, class _Sent, class _OutIter>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
|
||||
pair<_InIter, _OutIter> __copy_impl(_InIter __first, _Sent __last, _OutIter __result) {
|
||||
while (__first != __last) {
|
||||
*__result = *__first;
|
||||
return __result;
|
||||
++__first;
|
||||
++__result;
|
||||
}
|
||||
return pair<_InIter, _OutIter>(std::move(__first), std::move(__result));
|
||||
}
|
||||
|
||||
template <class _InputIterator, class _OutputIterator>
|
||||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
_OutputIterator
|
||||
__copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
|
||||
{
|
||||
return _VSTD::__copy_constexpr(__first, __last, __result);
|
||||
}
|
||||
|
||||
template <class _Tp, class _Up>
|
||||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
typename enable_if
|
||||
<
|
||||
is_same<typename remove_const<_Tp>::type, _Up>::value &&
|
||||
is_trivially_copy_assignable<_Up>::value,
|
||||
_Up*
|
||||
>::type
|
||||
__copy(_Tp* __first, _Tp* __last, _Up* __result)
|
||||
{
|
||||
template <class _InValueT,
|
||||
class _OutValueT,
|
||||
class = __enable_if_t<is_same<typename remove_const<_InValueT>::type, _OutValueT>::value
|
||||
&& is_trivially_copy_assignable<_OutValueT>::value> >
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
|
||||
pair<_InValueT*, _OutValueT*> __copy_impl(_InValueT* __first, _InValueT* __last, _OutValueT* __result) {
|
||||
if (__libcpp_is_constant_evaluated()
|
||||
// TODO: Remove this once GCC supports __builtin_memmove during constant evaluation
|
||||
#ifndef _LIBCPP_COMPILER_GCC
|
||||
&& !is_trivially_copyable<_InValueT>::value
|
||||
#endif
|
||||
)
|
||||
return std::__copy_impl<_InValueT*, _InValueT*, _OutValueT*>(__first, __last, __result);
|
||||
const size_t __n = static_cast<size_t>(__last - __first);
|
||||
if (__n > 0)
|
||||
_VSTD::memmove(__result, __first, __n * sizeof(_Up));
|
||||
return __result + __n;
|
||||
::__builtin_memmove(__result, __first, __n * sizeof(_OutValueT));
|
||||
return std::make_pair(__first + __n, __result + __n);
|
||||
}
|
||||
|
||||
template <class _InIter, class _OutIter,
|
||||
__enable_if_t<is_same<typename remove_const<__iter_value_type<_InIter> >::type, __iter_value_type<_OutIter> >::value
|
||||
&& __is_cpp17_contiguous_iterator<typename _InIter::iterator_type>::value
|
||||
&& __is_cpp17_contiguous_iterator<typename _OutIter::iterator_type>::value
|
||||
&& is_trivially_copy_assignable<__iter_value_type<_OutIter> >::value
|
||||
&& __is_reverse_iterator<_InIter>::value
|
||||
&& __is_reverse_iterator<_OutIter>::value, int> = 0>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
|
||||
pair<_InIter, _OutIter>
|
||||
__copy_impl(_InIter __first, _InIter __last, _OutIter __result) {
|
||||
auto __first_base = std::__unwrap_iter(__first.base());
|
||||
auto __last_base = std::__unwrap_iter(__last.base());
|
||||
auto __result_base = std::__unwrap_iter(__result.base());
|
||||
auto __result_first = __result_base - (__first_base - __last_base);
|
||||
std::__copy_impl(__last_base, __first_base, __result_first);
|
||||
return std::make_pair(__last, _OutIter(std::__rewrap_iter(__result.base(), __result_first)));
|
||||
}
|
||||
|
||||
template <class _InIter, class _Sent, class _OutIter,
|
||||
__enable_if_t<!(is_copy_constructible<_InIter>::value
|
||||
&& is_copy_constructible<_Sent>::value
|
||||
&& is_copy_constructible<_OutIter>::value), int> = 0 >
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
|
||||
pair<_InIter, _OutIter> __copy(_InIter __first, _Sent __last, _OutIter __result) {
|
||||
return std::__copy_impl(std::move(__first), std::move(__last), std::move(__result));
|
||||
}
|
||||
|
||||
template <class _InIter, class _Sent, class _OutIter,
|
||||
__enable_if_t<is_copy_constructible<_InIter>::value
|
||||
&& is_copy_constructible<_Sent>::value
|
||||
&& is_copy_constructible<_OutIter>::value, int> = 0>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
|
||||
pair<_InIter, _OutIter> __copy(_InIter __first, _Sent __last, _OutIter __result) {
|
||||
auto __range = std::__unwrap_range(__first, __last);
|
||||
auto __ret = std::__copy_impl(std::move(__range.first), std::move(__range.second), std::__unwrap_iter(__result));
|
||||
return std::make_pair(
|
||||
std::__rewrap_range<_Sent>(__first, __ret.first), std::__rewrap_iter(__result, __ret.second));
|
||||
}
|
||||
|
||||
template <class _InputIterator, class _OutputIterator>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
_OutputIterator
|
||||
copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
|
||||
{
|
||||
if (__libcpp_is_constant_evaluated()) {
|
||||
return _VSTD::__copy_constexpr(__first, __last, __result);
|
||||
} else {
|
||||
return _VSTD::__rewrap_iter(__result,
|
||||
_VSTD::__copy(_VSTD::__unwrap_iter(__first),
|
||||
_VSTD::__unwrap_iter(__last),
|
||||
_VSTD::__unwrap_iter(__result)));
|
||||
}
|
||||
copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result) {
|
||||
return std::__copy(__first, __last, __result).second;
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
|
|
|||
76
lib/libcxx/include/__algorithm/copy_backward.h
vendored
76
lib/libcxx/include/__algorithm/copy_backward.h
vendored
|
|
@ -9,69 +9,51 @@
|
|||
#ifndef _LIBCPP___ALGORITHM_COPY_BACKWARD_H
|
||||
#define _LIBCPP___ALGORITHM_COPY_BACKWARD_H
|
||||
|
||||
#include <__algorithm/copy.h>
|
||||
#include <__algorithm/iterator_operations.h>
|
||||
#include <__algorithm/ranges_copy.h>
|
||||
#include <__algorithm/unwrap_iter.h>
|
||||
#include <__concepts/same_as.h>
|
||||
#include <__config>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__iterator/reverse_iterator.h>
|
||||
#include <__ranges/subrange.h>
|
||||
#include <__utility/move.h>
|
||||
#include <__utility/pair.h>
|
||||
#include <cstring>
|
||||
#include <type_traits>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _BidirectionalIterator, class _OutputIterator>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
_OutputIterator
|
||||
__copy_backward_constexpr(_BidirectionalIterator __first, _BidirectionalIterator __last, _OutputIterator __result)
|
||||
{
|
||||
while (__first != __last)
|
||||
*--__result = *--__last;
|
||||
return __result;
|
||||
template <class _AlgPolicy, class _InputIterator, class _OutputIterator,
|
||||
__enable_if_t<is_same<_AlgPolicy, _ClassicAlgPolicy>::value, int> = 0>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 pair<_InputIterator, _OutputIterator>
|
||||
__copy_backward(_InputIterator __first, _InputIterator __last, _OutputIterator __result) {
|
||||
auto __ret = std::__copy(
|
||||
__unconstrained_reverse_iterator<_InputIterator>(__last),
|
||||
__unconstrained_reverse_iterator<_InputIterator>(__first),
|
||||
__unconstrained_reverse_iterator<_OutputIterator>(__result));
|
||||
return pair<_InputIterator, _OutputIterator>(__ret.first.base(), __ret.second.base());
|
||||
}
|
||||
|
||||
template <class _BidirectionalIterator, class _OutputIterator>
|
||||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
_OutputIterator
|
||||
__copy_backward(_BidirectionalIterator __first, _BidirectionalIterator __last, _OutputIterator __result)
|
||||
{
|
||||
return _VSTD::__copy_backward_constexpr(__first, __last, __result);
|
||||
}
|
||||
|
||||
template <class _Tp, class _Up>
|
||||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
typename enable_if
|
||||
<
|
||||
is_same<typename remove_const<_Tp>::type, _Up>::value &&
|
||||
is_trivially_copy_assignable<_Up>::value,
|
||||
_Up*
|
||||
>::type
|
||||
__copy_backward(_Tp* __first, _Tp* __last, _Up* __result)
|
||||
{
|
||||
const size_t __n = static_cast<size_t>(__last - __first);
|
||||
if (__n > 0)
|
||||
{
|
||||
__result -= __n;
|
||||
_VSTD::memmove(__result, __first, __n * sizeof(_Up));
|
||||
}
|
||||
return __result;
|
||||
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
template <class _AlgPolicy, class _Iter1, class _Sent1, class _Iter2,
|
||||
__enable_if_t<is_same<_AlgPolicy, _RangeAlgPolicy>::value, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr pair<_Iter1, _Iter2> __copy_backward(_Iter1 __first, _Sent1 __last, _Iter2 __result) {
|
||||
auto __reverse_range = std::__reverse_range(std::ranges::subrange(std::move(__first), std::move(__last)));
|
||||
auto __ret = ranges::copy(std::move(__reverse_range), std::make_reverse_iterator(__result));
|
||||
return std::make_pair(__ret.in.base(), __ret.out.base());
|
||||
}
|
||||
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
template <class _BidirectionalIterator1, class _BidirectionalIterator2>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
_BidirectionalIterator2
|
||||
copy_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last,
|
||||
_BidirectionalIterator2 __result)
|
||||
{
|
||||
if (__libcpp_is_constant_evaluated()) {
|
||||
return _VSTD::__copy_backward_constexpr(__first, __last, __result);
|
||||
} else {
|
||||
return _VSTD::__rewrap_iter(__result,
|
||||
_VSTD::__copy_backward(_VSTD::__unwrap_iter(__first),
|
||||
_VSTD::__unwrap_iter(__last),
|
||||
_VSTD::__unwrap_iter(__result)));
|
||||
}
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _BidirectionalIterator2
|
||||
copy_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last, _BidirectionalIterator2 __result) {
|
||||
return std::__copy_backward<_ClassicAlgPolicy>(__first, __last, __result).second;
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
|
|
|||
2
lib/libcxx/include/__algorithm/copy_if.h
vendored
2
lib/libcxx/include/__algorithm/copy_if.h
vendored
|
|
@ -12,7 +12,7 @@
|
|||
#include <__config>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
|
|
|||
2
lib/libcxx/include/__algorithm/copy_n.h
vendored
2
lib/libcxx/include/__algorithm/copy_n.h
vendored
|
|
@ -15,7 +15,7 @@
|
|||
#include <type_traits>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
|
|
|||
6
lib/libcxx/include/__algorithm/count.h
vendored
6
lib/libcxx/include/__algorithm/count.h
vendored
|
|
@ -14,7 +14,7 @@
|
|||
#include <__iterator/iterator_traits.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
|
@ -22,10 +22,10 @@ _LIBCPP_BEGIN_NAMESPACE_STD
|
|||
template <class _InputIterator, class _Tp>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
typename iterator_traits<_InputIterator>::difference_type
|
||||
count(_InputIterator __first, _InputIterator __last, const _Tp& __value_) {
|
||||
count(_InputIterator __first, _InputIterator __last, const _Tp& __value) {
|
||||
typename iterator_traits<_InputIterator>::difference_type __r(0);
|
||||
for (; __first != __last; ++__first)
|
||||
if (*__first == __value_)
|
||||
if (*__first == __value)
|
||||
++__r;
|
||||
return __r;
|
||||
}
|
||||
|
|
|
|||
2
lib/libcxx/include/__algorithm/count_if.h
vendored
2
lib/libcxx/include/__algorithm/count_if.h
vendored
|
|
@ -14,7 +14,7 @@
|
|||
#include <__iterator/iterator_traits.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
|
|
|||
2
lib/libcxx/include/__algorithm/equal.h
vendored
2
lib/libcxx/include/__algorithm/equal.h
vendored
|
|
@ -16,7 +16,7 @@
|
|||
#include <__iterator/iterator_traits.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
|
|
|||
90
lib/libcxx/include/__algorithm/equal_range.h
vendored
90
lib/libcxx/include/__algorithm/equal_range.h
vendored
|
|
@ -12,68 +12,70 @@
|
|||
#include <__algorithm/comp.h>
|
||||
#include <__algorithm/comp_ref_type.h>
|
||||
#include <__algorithm/half_positive.h>
|
||||
#include <__algorithm/iterator_operations.h>
|
||||
#include <__algorithm/lower_bound.h>
|
||||
#include <__algorithm/upper_bound.h>
|
||||
#include <__config>
|
||||
#include <iterator>
|
||||
#include <__functional/identity.h>
|
||||
#include <__functional/invoke.h>
|
||||
#include <__iterator/advance.h>
|
||||
#include <__iterator/distance.h>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__iterator/next.h>
|
||||
#include <__type_traits/is_callable.h>
|
||||
#include <__type_traits/is_copy_constructible.h>
|
||||
#include <__utility/move.h>
|
||||
#include <__utility/pair.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _Compare, class _ForwardIterator, class _Tp>
|
||||
_LIBCPP_CONSTEXPR_AFTER_CXX17 pair<_ForwardIterator, _ForwardIterator>
|
||||
__equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
|
||||
{
|
||||
typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type;
|
||||
difference_type __len = _VSTD::distance(__first, __last);
|
||||
while (__len != 0)
|
||||
{
|
||||
difference_type __l2 = _VSTD::__half_positive(__len);
|
||||
_ForwardIterator __m = __first;
|
||||
_VSTD::advance(__m, __l2);
|
||||
if (__comp(*__m, __value_))
|
||||
{
|
||||
__first = ++__m;
|
||||
__len -= __l2 + 1;
|
||||
}
|
||||
else if (__comp(__value_, *__m))
|
||||
{
|
||||
__last = __m;
|
||||
__len = __l2;
|
||||
}
|
||||
else
|
||||
{
|
||||
_ForwardIterator __mp1 = __m;
|
||||
return pair<_ForwardIterator, _ForwardIterator>
|
||||
(
|
||||
_VSTD::__lower_bound<_Compare>(__first, __m, __value_, __comp),
|
||||
_VSTD::__upper_bound<_Compare>(++__mp1, __last, __value_, __comp)
|
||||
);
|
||||
template <class _AlgPolicy, class _Compare, class _Iter, class _Sent, class _Tp, class _Proj>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 pair<_Iter, _Iter>
|
||||
__equal_range(_Iter __first, _Sent __last, const _Tp& __value, _Compare&& __comp, _Proj&& __proj) {
|
||||
auto __len = _IterOps<_AlgPolicy>::distance(__first, __last);
|
||||
_Iter __end = _IterOps<_AlgPolicy>::next(__first, __last);
|
||||
while (__len != 0) {
|
||||
auto __half_len = std::__half_positive(__len);
|
||||
_Iter __mid = _IterOps<_AlgPolicy>::next(__first, __half_len);
|
||||
if (std::__invoke(__comp, std::__invoke(__proj, *__mid), __value)) {
|
||||
__first = ++__mid;
|
||||
__len -= __half_len + 1;
|
||||
} else if (std::__invoke(__comp, __value, std::__invoke(__proj, *__mid))) {
|
||||
__end = __mid;
|
||||
__len = __half_len;
|
||||
} else {
|
||||
_Iter __mp1 = __mid;
|
||||
return pair<_Iter, _Iter>(
|
||||
std::__lower_bound_impl<_AlgPolicy>(__first, __mid, __value, __comp, __proj),
|
||||
std::__upper_bound<_AlgPolicy>(++__mp1, __end, __value, __comp, __proj));
|
||||
}
|
||||
}
|
||||
return pair<_ForwardIterator, _ForwardIterator>(__first, __first);
|
||||
return pair<_Iter, _Iter>(__first, __first);
|
||||
}
|
||||
|
||||
template <class _ForwardIterator, class _Tp, class _Compare>
|
||||
_LIBCPP_NODISCARD_EXT inline
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
pair<_ForwardIterator, _ForwardIterator>
|
||||
equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
|
||||
{
|
||||
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 pair<_ForwardIterator, _ForwardIterator>
|
||||
equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) {
|
||||
static_assert(__is_callable<_Compare, decltype(*__first), const _Tp&>::value,
|
||||
"The comparator has to be callable");
|
||||
static_assert(is_copy_constructible<_ForwardIterator>::value,
|
||||
"Iterator has to be copy constructible");
|
||||
typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
|
||||
return _VSTD::__equal_range<_Comp_ref>(__first, __last, __value_, __comp);
|
||||
return std::__equal_range<_ClassicAlgPolicy>(
|
||||
std::move(__first), std::move(__last), __value, static_cast<_Comp_ref>(__comp), std::__identity());
|
||||
}
|
||||
|
||||
template <class _ForwardIterator, class _Tp>
|
||||
_LIBCPP_NODISCARD_EXT inline
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
pair<_ForwardIterator, _ForwardIterator>
|
||||
equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_)
|
||||
{
|
||||
return _VSTD::equal_range(__first, __last, __value_,
|
||||
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 pair<_ForwardIterator, _ForwardIterator>
|
||||
equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
|
||||
return std::equal_range(
|
||||
std::move(__first),
|
||||
std::move(__last),
|
||||
__value,
|
||||
__less<typename iterator_traits<_ForwardIterator>::value_type, _Tp>());
|
||||
}
|
||||
|
||||
|
|
|
|||
16
lib/libcxx/include/__algorithm/fill.h
vendored
16
lib/libcxx/include/__algorithm/fill.h
vendored
|
|
@ -15,34 +15,36 @@
|
|||
#include <type_traits>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
// fill isn't specialized for std::memset, because the compiler already optimizes the loop to a call to std::memset.
|
||||
|
||||
template <class _ForwardIterator, class _Tp>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
void
|
||||
__fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, forward_iterator_tag)
|
||||
__fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, forward_iterator_tag)
|
||||
{
|
||||
for (; __first != __last; ++__first)
|
||||
*__first = __value_;
|
||||
*__first = __value;
|
||||
}
|
||||
|
||||
template <class _RandomAccessIterator, class _Tp>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
void
|
||||
__fill(_RandomAccessIterator __first, _RandomAccessIterator __last, const _Tp& __value_, random_access_iterator_tag)
|
||||
__fill(_RandomAccessIterator __first, _RandomAccessIterator __last, const _Tp& __value, random_access_iterator_tag)
|
||||
{
|
||||
_VSTD::fill_n(__first, __last - __first, __value_);
|
||||
_VSTD::fill_n(__first, __last - __first, __value);
|
||||
}
|
||||
|
||||
template <class _ForwardIterator, class _Tp>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
void
|
||||
fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_)
|
||||
fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
|
||||
{
|
||||
_VSTD::__fill(__first, __last, __value_, typename iterator_traits<_ForwardIterator>::iterator_category());
|
||||
_VSTD::__fill(__first, __last, __value, typename iterator_traits<_ForwardIterator>::iterator_category());
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
|
|
|||
12
lib/libcxx/include/__algorithm/fill_n.h
vendored
12
lib/libcxx/include/__algorithm/fill_n.h
vendored
|
|
@ -14,27 +14,29 @@
|
|||
#include <type_traits>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
// fill_n isn't specialized for std::memset, because the compiler already optimizes the loop to a call to std::memset.
|
||||
|
||||
template <class _OutputIterator, class _Size, class _Tp>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
_OutputIterator
|
||||
__fill_n(_OutputIterator __first, _Size __n, const _Tp& __value_)
|
||||
__fill_n(_OutputIterator __first, _Size __n, const _Tp& __value)
|
||||
{
|
||||
for (; __n > 0; ++__first, (void) --__n)
|
||||
*__first = __value_;
|
||||
*__first = __value;
|
||||
return __first;
|
||||
}
|
||||
|
||||
template <class _OutputIterator, class _Size, class _Tp>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
_OutputIterator
|
||||
fill_n(_OutputIterator __first, _Size __n, const _Tp& __value_)
|
||||
fill_n(_OutputIterator __first, _Size __n, const _Tp& __value)
|
||||
{
|
||||
return _VSTD::__fill_n(__first, _VSTD::__convert_to_integral(__n), __value_);
|
||||
return _VSTD::__fill_n(__first, _VSTD::__convert_to_integral(__n), __value);
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
|
|
|||
6
lib/libcxx/include/__algorithm/find.h
vendored
6
lib/libcxx/include/__algorithm/find.h
vendored
|
|
@ -13,16 +13,16 @@
|
|||
#include <__config>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _InputIterator, class _Tp>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _InputIterator
|
||||
find(_InputIterator __first, _InputIterator __last, const _Tp& __value_) {
|
||||
find(_InputIterator __first, _InputIterator __last, const _Tp& __value) {
|
||||
for (; __first != __last; ++__first)
|
||||
if (*__first == __value_)
|
||||
if (*__first == __value)
|
||||
break;
|
||||
return __first;
|
||||
}
|
||||
|
|
|
|||
179
lib/libcxx/include/__algorithm/find_end.h
vendored
179
lib/libcxx/include/__algorithm/find_end.h
vendored
|
|
@ -11,44 +11,69 @@
|
|||
#define _LIBCPP___ALGORITHM_FIND_END_OF_H
|
||||
|
||||
#include <__algorithm/comp.h>
|
||||
#include <__algorithm/iterator_operations.h>
|
||||
#include <__algorithm/search.h>
|
||||
#include <__config>
|
||||
#include <__functional/identity.h>
|
||||
#include <__iterator/advance.h>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__iterator/next.h>
|
||||
#include <__iterator/reverse_iterator.h>
|
||||
#include <__utility/pair.h>
|
||||
#include <type_traits>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _BinaryPredicate, class _ForwardIterator1, class _ForwardIterator2>
|
||||
_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator1 __find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
|
||||
_ForwardIterator2 __first2, _ForwardIterator2 __last2,
|
||||
_BinaryPredicate __pred, forward_iterator_tag,
|
||||
template <
|
||||
class _AlgPolicy,
|
||||
class _Iter1,
|
||||
class _Sent1,
|
||||
class _Iter2,
|
||||
class _Sent2,
|
||||
class _Pred,
|
||||
class _Proj1,
|
||||
class _Proj2>
|
||||
_LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR_AFTER_CXX11 pair<_Iter1, _Iter1> __find_end_impl(
|
||||
_Iter1 __first1,
|
||||
_Sent1 __last1,
|
||||
_Iter2 __first2,
|
||||
_Sent2 __last2,
|
||||
_Pred& __pred,
|
||||
_Proj1& __proj1,
|
||||
_Proj2& __proj2,
|
||||
forward_iterator_tag,
|
||||
forward_iterator_tag) {
|
||||
// modeled after search algorithm
|
||||
_ForwardIterator1 __r = __last1; // __last1 is the "default" answer
|
||||
_Iter1 __match_first = _IterOps<_AlgPolicy>::next(__first1, __last1); // __last1 is the "default" answer
|
||||
_Iter1 __match_last = __match_first;
|
||||
if (__first2 == __last2)
|
||||
return __r;
|
||||
return pair<_Iter1, _Iter1>(__match_last, __match_last);
|
||||
while (true) {
|
||||
while (true) {
|
||||
if (__first1 == __last1) // if source exhausted return last correct answer
|
||||
return __r; // (or __last1 if never found)
|
||||
if (__pred(*__first1, *__first2))
|
||||
if (__first1 == __last1) // if source exhausted return last correct answer (or __last1 if never found)
|
||||
return pair<_Iter1, _Iter1>(__match_first, __match_last);
|
||||
if (std::__invoke(__pred, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2)))
|
||||
break;
|
||||
++__first1;
|
||||
}
|
||||
// *__first1 matches *__first2, now match elements after here
|
||||
_ForwardIterator1 __m1 = __first1;
|
||||
_ForwardIterator2 __m2 = __first2;
|
||||
_Iter1 __m1 = __first1;
|
||||
_Iter2 __m2 = __first2;
|
||||
while (true) {
|
||||
if (++__m2 == __last2) { // Pattern exhaused, record answer and search for another one
|
||||
__r = __first1;
|
||||
__match_first = __first1;
|
||||
__match_last = ++__m1;
|
||||
++__first1;
|
||||
break;
|
||||
}
|
||||
if (++__m1 == __last1) // Source exhausted, return last answer
|
||||
return __r;
|
||||
if (!__pred(*__m1, *__m2)) // mismatch, restart with a new __first
|
||||
return pair<_Iter1, _Iter1>(__match_first, __match_last);
|
||||
// mismatch, restart with a new __first
|
||||
if (!std::__invoke(__pred, std::__invoke(__proj1, *__m1), std::__invoke(__proj2, *__m2)))
|
||||
{
|
||||
++__first1;
|
||||
break;
|
||||
|
|
@ -57,33 +82,52 @@ _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator1 __find_end(_ForwardIterator1 __f
|
|||
}
|
||||
}
|
||||
|
||||
template <class _BinaryPredicate, class _BidirectionalIterator1, class _BidirectionalIterator2>
|
||||
_LIBCPP_CONSTEXPR_AFTER_CXX17 _BidirectionalIterator1 __find_end(
|
||||
_BidirectionalIterator1 __first1, _BidirectionalIterator1 __last1, _BidirectionalIterator2 __first2,
|
||||
_BidirectionalIterator2 __last2, _BinaryPredicate __pred, bidirectional_iterator_tag, bidirectional_iterator_tag) {
|
||||
template <
|
||||
class _IterOps,
|
||||
class _Pred,
|
||||
class _Iter1,
|
||||
class _Sent1,
|
||||
class _Iter2,
|
||||
class _Sent2,
|
||||
class _Proj1,
|
||||
class _Proj2>
|
||||
_LIBCPP_CONSTEXPR_AFTER_CXX17 _Iter1 __find_end(
|
||||
_Iter1 __first1,
|
||||
_Sent1 __sent1,
|
||||
_Iter2 __first2,
|
||||
_Sent2 __sent2,
|
||||
_Pred& __pred,
|
||||
_Proj1& __proj1,
|
||||
_Proj2& __proj2,
|
||||
bidirectional_iterator_tag,
|
||||
bidirectional_iterator_tag) {
|
||||
auto __last1 = _IterOps::next(__first1, __sent1);
|
||||
auto __last2 = _IterOps::next(__first2, __sent2);
|
||||
// modeled after search algorithm (in reverse)
|
||||
if (__first2 == __last2)
|
||||
return __last1; // Everything matches an empty sequence
|
||||
_BidirectionalIterator1 __l1 = __last1;
|
||||
_BidirectionalIterator2 __l2 = __last2;
|
||||
_Iter1 __l1 = __last1;
|
||||
_Iter2 __l2 = __last2;
|
||||
--__l2;
|
||||
while (true) {
|
||||
// Find last element in sequence 1 that matchs *(__last2-1), with a mininum of loop checks
|
||||
while (true) {
|
||||
if (__first1 == __l1) // return __last1 if no element matches *__first2
|
||||
return __last1;
|
||||
if (__pred(*--__l1, *__l2))
|
||||
if (std::__invoke(__pred, std::__invoke(__proj1, *--__l1), std::__invoke(__proj2, *__l2)))
|
||||
break;
|
||||
}
|
||||
// *__l1 matches *__l2, now match elements before here
|
||||
_BidirectionalIterator1 __m1 = __l1;
|
||||
_BidirectionalIterator2 __m2 = __l2;
|
||||
_Iter1 __m1 = __l1;
|
||||
_Iter2 __m2 = __l2;
|
||||
while (true) {
|
||||
if (__m2 == __first2) // If pattern exhausted, __m1 is the answer (works for 1 element pattern)
|
||||
return __m1;
|
||||
if (__m1 == __first1) // Otherwise if source exhaused, pattern not found
|
||||
return __last1;
|
||||
if (!__pred(*--__m1, *--__m2)) // if there is a mismatch, restart with a new __l1
|
||||
|
||||
// if there is a mismatch, restart with a new __l1
|
||||
if (!std::__invoke(__pred, std::__invoke(__proj1, *--__m1), std::__invoke(__proj2, *--__m2)))
|
||||
{
|
||||
break;
|
||||
} // else there is a match, check next elements
|
||||
|
|
@ -91,37 +135,53 @@ _LIBCPP_CONSTEXPR_AFTER_CXX17 _BidirectionalIterator1 __find_end(
|
|||
}
|
||||
}
|
||||
|
||||
template <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2>
|
||||
_LIBCPP_CONSTEXPR_AFTER_CXX11 _RandomAccessIterator1 __find_end(
|
||||
_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2,
|
||||
_RandomAccessIterator2 __last2, _BinaryPredicate __pred, random_access_iterator_tag, random_access_iterator_tag) {
|
||||
typedef typename iterator_traits<_RandomAccessIterator1>::difference_type _D1;
|
||||
typedef typename iterator_traits<_RandomAccessIterator2>::difference_type _D2;
|
||||
template <
|
||||
class _AlgPolicy,
|
||||
class _Pred,
|
||||
class _Iter1,
|
||||
class _Sent1,
|
||||
class _Iter2,
|
||||
class _Sent2,
|
||||
class _Proj1,
|
||||
class _Proj2>
|
||||
_LIBCPP_CONSTEXPR_AFTER_CXX11 _Iter1 __find_end(
|
||||
_Iter1 __first1,
|
||||
_Sent1 __sent1,
|
||||
_Iter2 __first2,
|
||||
_Sent2 __sent2,
|
||||
_Pred& __pred,
|
||||
_Proj1& __proj1,
|
||||
_Proj2& __proj2,
|
||||
random_access_iterator_tag,
|
||||
random_access_iterator_tag) {
|
||||
typedef typename iterator_traits<_Iter1>::difference_type _D1;
|
||||
auto __last1 = _IterOps<_AlgPolicy>::next(__first1, __sent1);
|
||||
auto __last2 = _IterOps<_AlgPolicy>::next(__first2, __sent2);
|
||||
// Take advantage of knowing source and pattern lengths. Stop short when source is smaller than pattern
|
||||
_D2 __len2 = __last2 - __first2;
|
||||
auto __len2 = __last2 - __first2;
|
||||
if (__len2 == 0)
|
||||
return __last1;
|
||||
_D1 __len1 = __last1 - __first1;
|
||||
auto __len1 = __last1 - __first1;
|
||||
if (__len1 < __len2)
|
||||
return __last1;
|
||||
const _RandomAccessIterator1 __s = __first1 + _D1(__len2 - 1); // End of pattern match can't go before here
|
||||
_RandomAccessIterator1 __l1 = __last1;
|
||||
_RandomAccessIterator2 __l2 = __last2;
|
||||
const _Iter1 __s = __first1 + _D1(__len2 - 1); // End of pattern match can't go before here
|
||||
_Iter1 __l1 = __last1;
|
||||
_Iter2 __l2 = __last2;
|
||||
--__l2;
|
||||
while (true) {
|
||||
while (true) {
|
||||
if (__s == __l1)
|
||||
return __last1;
|
||||
if (__pred(*--__l1, *__l2))
|
||||
if (std::__invoke(__pred, std::__invoke(__proj1, *--__l1), std::__invoke(__proj2, *__l2)))
|
||||
break;
|
||||
}
|
||||
_RandomAccessIterator1 __m1 = __l1;
|
||||
_RandomAccessIterator2 __m2 = __l2;
|
||||
_Iter1 __m1 = __l1;
|
||||
_Iter2 __m2 = __l2;
|
||||
while (true) {
|
||||
if (__m2 == __first2)
|
||||
return __m1;
|
||||
// no need to check range on __m1 because __s guarantees we have enough source
|
||||
if (!__pred(*--__m1, *--__m2)) {
|
||||
if (!std::__invoke(__pred, std::__invoke(__proj1, *--__m1), std::__invoke(*--__m2))) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -129,20 +189,39 @@ _LIBCPP_CONSTEXPR_AFTER_CXX11 _RandomAccessIterator1 __find_end(
|
|||
}
|
||||
|
||||
template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator1
|
||||
find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2,
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
|
||||
_ForwardIterator1 __find_end_classic(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
|
||||
_ForwardIterator2 __first2, _ForwardIterator2 __last2,
|
||||
_BinaryPredicate& __pred) {
|
||||
auto __proj = __identity();
|
||||
return std::__find_end_impl<_ClassicAlgPolicy>(
|
||||
__first1,
|
||||
__last1,
|
||||
__first2,
|
||||
__last2,
|
||||
__pred,
|
||||
__proj,
|
||||
__proj,
|
||||
typename iterator_traits<_ForwardIterator1>::iterator_category(),
|
||||
typename iterator_traits<_ForwardIterator2>::iterator_category())
|
||||
.first;
|
||||
}
|
||||
|
||||
template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
_ForwardIterator1 find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
|
||||
_ForwardIterator2 __first2, _ForwardIterator2 __last2,
|
||||
_BinaryPredicate __pred) {
|
||||
return _VSTD::__find_end<_BinaryPredicate&>(
|
||||
__first1, __last1, __first2, __last2, __pred, typename iterator_traits<_ForwardIterator1>::iterator_category(),
|
||||
typename iterator_traits<_ForwardIterator2>::iterator_category());
|
||||
return std::__find_end_classic(__first1, __last1, __first2, __last2, __pred);
|
||||
}
|
||||
|
||||
template <class _ForwardIterator1, class _ForwardIterator2>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator1
|
||||
find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) {
|
||||
typedef typename iterator_traits<_ForwardIterator1>::value_type __v1;
|
||||
typedef typename iterator_traits<_ForwardIterator2>::value_type __v2;
|
||||
return _VSTD::find_end(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>());
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
_ForwardIterator1 find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
|
||||
_ForwardIterator2 __first2, _ForwardIterator2 __last2) {
|
||||
using __v1 = typename iterator_traits<_ForwardIterator1>::value_type;
|
||||
using __v2 = typename iterator_traits<_ForwardIterator2>::value_type;
|
||||
return std::find_end(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>());
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
#include <__iterator/iterator_traits.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
|
|
|||
2
lib/libcxx/include/__algorithm/find_if.h
vendored
2
lib/libcxx/include/__algorithm/find_if.h
vendored
|
|
@ -13,7 +13,7 @@
|
|||
#include <__config>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
|
|
|||
2
lib/libcxx/include/__algorithm/find_if_not.h
vendored
2
lib/libcxx/include/__algorithm/find_if_not.h
vendored
|
|
@ -13,7 +13,7 @@
|
|||
#include <__config>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
|
|
|||
2
lib/libcxx/include/__algorithm/for_each.h
vendored
2
lib/libcxx/include/__algorithm/for_each.h
vendored
|
|
@ -13,7 +13,7 @@
|
|||
#include <__config>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
|
|
|||
2
lib/libcxx/include/__algorithm/for_each_n.h
vendored
2
lib/libcxx/include/__algorithm/for_each_n.h
vendored
|
|
@ -14,7 +14,7 @@
|
|||
#include <type_traits>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
|
|
|||
2
lib/libcxx/include/__algorithm/generate.h
vendored
2
lib/libcxx/include/__algorithm/generate.h
vendored
|
|
@ -12,7 +12,7 @@
|
|||
#include <__config>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
|
|
|||
2
lib/libcxx/include/__algorithm/generate_n.h
vendored
2
lib/libcxx/include/__algorithm/generate_n.h
vendored
|
|
@ -13,7 +13,7 @@
|
|||
#include <type_traits>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
#include <type_traits>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
|
|
|||
49
lib/libcxx/include/__algorithm/in_found_result.h
vendored
Normal file
49
lib/libcxx/include/__algorithm/in_found_result.h
vendored
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
// -*- C++ -*-
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_IN_FOUND_RESULT_H
|
||||
#define _LIBCPP___ALGORITHM_IN_FOUND_RESULT_H
|
||||
|
||||
#include <__concepts/convertible_to.h>
|
||||
#include <__config>
|
||||
#include <__utility/move.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
namespace ranges {
|
||||
template <class _InIter1>
|
||||
struct in_found_result {
|
||||
_LIBCPP_NO_UNIQUE_ADDRESS _InIter1 in;
|
||||
bool found;
|
||||
|
||||
template <class _InIter2>
|
||||
requires convertible_to<const _InIter1&, _InIter2>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr operator in_found_result<_InIter2>() const & {
|
||||
return {in, found};
|
||||
}
|
||||
|
||||
template <class _InIter2>
|
||||
requires convertible_to<_InIter1, _InIter2>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr operator in_found_result<_InIter2>() && {
|
||||
return {std::move(in), found};
|
||||
}
|
||||
};
|
||||
} // namespace ranges
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_IN_FOUND_RESULT_H
|
||||
49
lib/libcxx/include/__algorithm/in_fun_result.h
vendored
Normal file
49
lib/libcxx/include/__algorithm/in_fun_result.h
vendored
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
// -*- C++ -*-
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_IN_FUN_RESULT_H
|
||||
#define _LIBCPP___ALGORITHM_IN_FUN_RESULT_H
|
||||
|
||||
#include <__concepts/convertible_to.h>
|
||||
#include <__config>
|
||||
#include <__utility/move.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
namespace ranges {
|
||||
template <class _InIter1, class _Func1>
|
||||
struct in_fun_result {
|
||||
_LIBCPP_NO_UNIQUE_ADDRESS _InIter1 in;
|
||||
_LIBCPP_NO_UNIQUE_ADDRESS _Func1 fun;
|
||||
|
||||
template <class _InIter2, class _Func2>
|
||||
requires convertible_to<const _InIter1&, _InIter2> && convertible_to<const _Func1&, _Func2>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr operator in_fun_result<_InIter2, _Func2>() const & {
|
||||
return {in, fun};
|
||||
}
|
||||
|
||||
template <class _InIter2, class _Func2>
|
||||
requires convertible_to<_InIter1, _InIter2> && convertible_to<_Func1, _Func2>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr operator in_fun_result<_InIter2, _Func2>() && {
|
||||
return {std::move(in), std::move(fun)};
|
||||
}
|
||||
};
|
||||
} // namespace ranges
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_IN_FUN_RESULT_H
|
||||
|
|
@ -15,39 +15,41 @@
|
|||
#include <__utility/move.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
namespace ranges {
|
||||
|
||||
template <class _I1, class _I2, class _O1>
|
||||
template <class _InIter1, class _InIter2, class _OutIter1>
|
||||
struct in_in_out_result {
|
||||
[[no_unique_address]] _I1 in1;
|
||||
[[no_unique_address]] _I2 in2;
|
||||
[[no_unique_address]] _O1 out;
|
||||
_LIBCPP_NO_UNIQUE_ADDRESS _InIter1 in1;
|
||||
_LIBCPP_NO_UNIQUE_ADDRESS _InIter2 in2;
|
||||
_LIBCPP_NO_UNIQUE_ADDRESS _OutIter1 out;
|
||||
|
||||
template <class _II1, class _II2, class _OO1>
|
||||
requires convertible_to<const _I1&, _II1> && convertible_to<const _I2&, _II2> && convertible_to<const _O1&, _OO1>
|
||||
template <class _InIter3, class _InIter4, class _OutIter2>
|
||||
requires convertible_to<const _InIter1&, _InIter3>
|
||||
&& convertible_to<const _InIter2&, _InIter4> && convertible_to<const _OutIter1&, _OutIter2>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
operator in_in_out_result<_II1, _II2, _OO1>() const& {
|
||||
operator in_in_out_result<_InIter3, _InIter4, _OutIter2>() const& {
|
||||
return {in1, in2, out};
|
||||
}
|
||||
|
||||
template <class _II1, class _II2, class _OO1>
|
||||
requires convertible_to<_I1, _II1> && convertible_to<_I2, _II2> && convertible_to<_O1, _OO1>
|
||||
template <class _InIter3, class _InIter4, class _OutIter2>
|
||||
requires convertible_to<_InIter1, _InIter3>
|
||||
&& convertible_to<_InIter2, _InIter4> && convertible_to<_OutIter1, _OutIter2>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
operator in_in_out_result<_II1, _II2, _OO1>() && {
|
||||
return {_VSTD::move(in1), _VSTD::move(in2), _VSTD::move(out)};
|
||||
operator in_in_out_result<_InIter3, _InIter4, _OutIter2>() && {
|
||||
return {std::move(in1), std::move(in2), std::move(out)};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace ranges
|
||||
|
||||
#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
|
|
|
|||
26
lib/libcxx/include/__algorithm/in_in_result.h
vendored
26
lib/libcxx/include/__algorithm/in_in_result.h
vendored
|
|
@ -15,36 +15,38 @@
|
|||
#include <__utility/move.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
|
||||
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
namespace ranges {
|
||||
|
||||
template <class _I1, class _I2>
|
||||
template <class _InIter1, class _InIter2>
|
||||
struct in_in_result {
|
||||
[[no_unique_address]] _I1 in1;
|
||||
[[no_unique_address]] _I2 in2;
|
||||
_LIBCPP_NO_UNIQUE_ADDRESS _InIter1 in1;
|
||||
_LIBCPP_NO_UNIQUE_ADDRESS _InIter2 in2;
|
||||
|
||||
template <class _II1, class _II2>
|
||||
requires convertible_to<const _I1&, _II1> && convertible_to<const _I2&, _II2>
|
||||
template <class _InIter3, class _InIter4>
|
||||
requires convertible_to<const _InIter1&, _InIter3> && convertible_to<const _InIter2&, _InIter4>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
operator in_in_result<_II1, _II2>() const & {
|
||||
operator in_in_result<_InIter3, _InIter4>() const & {
|
||||
return {in1, in2};
|
||||
}
|
||||
|
||||
template <class _II1, class _II2>
|
||||
requires convertible_to<_I1, _II1> && convertible_to<_I2, _II2>
|
||||
template <class _InIter3, class _InIter4>
|
||||
requires convertible_to<_InIter1, _InIter3> && convertible_to<_InIter2, _InIter4>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
operator in_in_result<_II1, _II2>() && { return {_VSTD::move(in1), _VSTD::move(in2)}; }
|
||||
operator in_in_result<_InIter3, _InIter4>() && {
|
||||
return {std::move(in1), std::move(in2)};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace ranges
|
||||
|
||||
#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
|
||||
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
|
|
|
|||
54
lib/libcxx/include/__algorithm/in_out_out_result.h
vendored
Normal file
54
lib/libcxx/include/__algorithm/in_out_out_result.h
vendored
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
// -*- C++ -*-
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_IN_OUT_OUT_RESULT_H
|
||||
#define _LIBCPP___ALGORITHM_IN_OUT_OUT_RESULT_H
|
||||
|
||||
#include <__concepts/convertible_to.h>
|
||||
#include <__config>
|
||||
#include <__utility/move.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
namespace ranges {
|
||||
template <class _InIter1, class _OutIter1, class _OutIter2>
|
||||
struct in_out_out_result {
|
||||
_LIBCPP_NO_UNIQUE_ADDRESS _InIter1 in;
|
||||
_LIBCPP_NO_UNIQUE_ADDRESS _OutIter1 out1;
|
||||
_LIBCPP_NO_UNIQUE_ADDRESS _OutIter2 out2;
|
||||
|
||||
template <class _InIter2, class _OutIter3, class _OutIter4>
|
||||
requires convertible_to<const _InIter1&, _InIter2>
|
||||
&& convertible_to<const _OutIter1&, _OutIter3> && convertible_to<const _OutIter2&, _OutIter4>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
operator in_out_out_result<_InIter2, _OutIter3, _OutIter4>() const& {
|
||||
return {in, out1, out2};
|
||||
}
|
||||
|
||||
template <class _InIter2, class _OutIter3, class _OutIter4>
|
||||
requires convertible_to<_InIter1, _InIter2>
|
||||
&& convertible_to<_OutIter1, _OutIter3> && convertible_to<_OutIter2, _OutIter4>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
operator in_out_out_result<_InIter2, _OutIter3, _OutIter4>() && {
|
||||
return {std::move(in), std::move(out1), std::move(out2)};
|
||||
}
|
||||
};
|
||||
} // namespace ranges
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_IN_OUT_OUT_RESULT_H
|
||||
27
lib/libcxx/include/__algorithm/in_out_result.h
vendored
27
lib/libcxx/include/__algorithm/in_out_result.h
vendored
|
|
@ -15,39 +15,38 @@
|
|||
#include <__utility/move.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
namespace ranges {
|
||||
|
||||
template<class _InputIterator, class _OutputIterator>
|
||||
template<class _InIter1, class _OutIter1>
|
||||
struct in_out_result {
|
||||
[[no_unique_address]] _InputIterator in;
|
||||
[[no_unique_address]] _OutputIterator out;
|
||||
_LIBCPP_NO_UNIQUE_ADDRESS _InIter1 in;
|
||||
_LIBCPP_NO_UNIQUE_ADDRESS _OutIter1 out;
|
||||
|
||||
template <class _InputIterator2, class _OutputIterator2>
|
||||
requires convertible_to<const _InputIterator&, _InputIterator2> && convertible_to<const _OutputIterator&,
|
||||
_OutputIterator2>
|
||||
template <class _InIter2, class _OutIter2>
|
||||
requires convertible_to<const _InIter1&, _InIter2> && convertible_to<const _OutIter1&, _OutIter2>
|
||||
_LIBCPP_HIDE_FROM_ABI
|
||||
constexpr operator in_out_result<_InputIterator2, _OutputIterator2>() const & {
|
||||
constexpr operator in_out_result<_InIter2, _OutIter2>() const & {
|
||||
return {in, out};
|
||||
}
|
||||
|
||||
template <class _InputIterator2, class _OutputIterator2>
|
||||
requires convertible_to<_InputIterator, _InputIterator2> && convertible_to<_OutputIterator, _OutputIterator2>
|
||||
template <class _InIter2, class _OutIter2>
|
||||
requires convertible_to<_InIter1, _InIter2> && convertible_to<_OutIter1, _OutIter2>
|
||||
_LIBCPP_HIDE_FROM_ABI
|
||||
constexpr operator in_out_result<_InputIterator2, _OutputIterator2>() && {
|
||||
return {_VSTD::move(in), _VSTD::move(out)};
|
||||
constexpr operator in_out_result<_InIter2, _OutIter2>() && {
|
||||
return {std::move(in), std::move(out)};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace ranges
|
||||
|
||||
#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
|
|
|
|||
55
lib/libcxx/include/__algorithm/includes.h
vendored
55
lib/libcxx/include/__algorithm/includes.h
vendored
|
|
@ -12,47 +12,56 @@
|
|||
#include <__algorithm/comp.h>
|
||||
#include <__algorithm/comp_ref_type.h>
|
||||
#include <__config>
|
||||
#include <__functional/identity.h>
|
||||
#include <__functional/invoke.h>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__type_traits/is_callable.h>
|
||||
#include <__utility/move.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _Compare, class _InputIterator1, class _InputIterator2>
|
||||
_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
|
||||
__includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2,
|
||||
_Compare __comp)
|
||||
{
|
||||
for (; __first2 != __last2; ++__first1)
|
||||
{
|
||||
if (__first1 == __last1 || __comp(*__first2, *__first1))
|
||||
template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Comp, class _Proj1, class _Proj2>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 bool
|
||||
__includes(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2,
|
||||
_Comp&& __comp, _Proj1&& __proj1, _Proj2&& __proj2) {
|
||||
for (; __first2 != __last2; ++__first1) {
|
||||
if (__first1 == __last1 || std::__invoke(
|
||||
__comp, std::__invoke(__proj2, *__first2), std::__invoke(__proj1, *__first1)))
|
||||
return false;
|
||||
if (!__comp(*__first1, *__first2))
|
||||
if (!std::__invoke(__comp, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2)))
|
||||
++__first2;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class _InputIterator1, class _InputIterator2, class _Compare>
|
||||
_LIBCPP_NODISCARD_EXT inline
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
bool
|
||||
includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2,
|
||||
_Compare __comp)
|
||||
{
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 bool includes(
|
||||
_InputIterator1 __first1,
|
||||
_InputIterator1 __last1,
|
||||
_InputIterator2 __first2,
|
||||
_InputIterator2 __last2,
|
||||
_Compare __comp) {
|
||||
static_assert(__is_callable<_Compare, decltype(*__first1), decltype(*__first2)>::value,
|
||||
"Comparator has to be callable");
|
||||
|
||||
typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
|
||||
return _VSTD::__includes<_Comp_ref>(__first1, __last1, __first2, __last2, __comp);
|
||||
return std::__includes(
|
||||
std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2),
|
||||
static_cast<_Comp_ref>(__comp), __identity(), __identity());
|
||||
}
|
||||
|
||||
template <class _InputIterator1, class _InputIterator2>
|
||||
_LIBCPP_NODISCARD_EXT inline
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
bool
|
||||
includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2)
|
||||
{
|
||||
return _VSTD::includes(__first1, __last1, __first2, __last2,
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 bool
|
||||
includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) {
|
||||
return std::includes(
|
||||
std::move(__first1),
|
||||
std::move(__last1),
|
||||
std::move(__first2),
|
||||
std::move(__last2),
|
||||
__less<typename iterator_traits<_InputIterator1>::value_type,
|
||||
typename iterator_traits<_InputIterator2>::value_type>());
|
||||
}
|
||||
|
|
|
|||
123
lib/libcxx/include/__algorithm/inplace_merge.h
vendored
123
lib/libcxx/include/__algorithm/inplace_merge.h
vendored
|
|
@ -9,20 +9,25 @@
|
|||
#ifndef _LIBCPP___ALGORITHM_INPLACE_MERGE_H
|
||||
#define _LIBCPP___ALGORITHM_INPLACE_MERGE_H
|
||||
|
||||
#include <__algorithm/algorithm_family.h>
|
||||
#include <__algorithm/comp.h>
|
||||
#include <__algorithm/comp_ref_type.h>
|
||||
#include <__algorithm/iterator_operations.h>
|
||||
#include <__algorithm/lower_bound.h>
|
||||
#include <__algorithm/min.h>
|
||||
#include <__algorithm/move.h>
|
||||
#include <__algorithm/rotate.h>
|
||||
#include <__algorithm/upper_bound.h>
|
||||
#include <__config>
|
||||
#include <__functional/identity.h>
|
||||
#include <__iterator/advance.h>
|
||||
#include <__iterator/distance.h>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__utility/swap.h>
|
||||
#include <__iterator/reverse_iterator.h>
|
||||
#include <memory>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_PUSH_MACROS
|
||||
|
|
@ -50,41 +55,43 @@ public:
|
|||
bool operator()(const _T1& __x, const _T2& __y) {return __p_(__y, __x);}
|
||||
};
|
||||
|
||||
template <class _Compare, class _InputIterator1, class _InputIterator2,
|
||||
class _OutputIterator>
|
||||
void __half_inplace_merge(_InputIterator1 __first1, _InputIterator1 __last1,
|
||||
_InputIterator2 __first2, _InputIterator2 __last2,
|
||||
_OutputIterator __result, _Compare __comp)
|
||||
template <class _AlgPolicy, class _Compare, class _InputIterator1, class _Sent1,
|
||||
class _InputIterator2, class _Sent2, class _OutputIterator>
|
||||
void __half_inplace_merge(_InputIterator1 __first1, _Sent1 __last1,
|
||||
_InputIterator2 __first2, _Sent2 __last2,
|
||||
_OutputIterator __result, _Compare&& __comp)
|
||||
{
|
||||
for (; __first1 != __last1; ++__result)
|
||||
{
|
||||
if (__first2 == __last2)
|
||||
{
|
||||
_VSTD::move(__first1, __last1, __result);
|
||||
_AlgFamily<_AlgPolicy>::__move(__first1, __last1, __result);
|
||||
return;
|
||||
}
|
||||
|
||||
if (__comp(*__first2, *__first1))
|
||||
{
|
||||
*__result = _VSTD::move(*__first2);
|
||||
*__result = _IterOps<_AlgPolicy>::__iter_move(__first2);
|
||||
++__first2;
|
||||
}
|
||||
else
|
||||
{
|
||||
*__result = _VSTD::move(*__first1);
|
||||
*__result = _IterOps<_AlgPolicy>::__iter_move(__first1);
|
||||
++__first1;
|
||||
}
|
||||
}
|
||||
// __first2 through __last2 are already in the right spot.
|
||||
}
|
||||
|
||||
template <class _Compare, class _BidirectionalIterator>
|
||||
void
|
||||
__buffered_inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last,
|
||||
_Compare __comp, typename iterator_traits<_BidirectionalIterator>::difference_type __len1,
|
||||
template <class _AlgPolicy, class _Compare, class _BidirectionalIterator>
|
||||
void __buffered_inplace_merge(
|
||||
_BidirectionalIterator __first,
|
||||
_BidirectionalIterator __middle,
|
||||
_BidirectionalIterator __last,
|
||||
_Compare&& __comp,
|
||||
typename iterator_traits<_BidirectionalIterator>::difference_type __len1,
|
||||
typename iterator_traits<_BidirectionalIterator>::difference_type __len2,
|
||||
typename iterator_traits<_BidirectionalIterator>::value_type* __buff)
|
||||
{
|
||||
typename iterator_traits<_BidirectionalIterator>::value_type* __buff) {
|
||||
typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
|
||||
__destruct_n __d(0);
|
||||
unique_ptr<value_type, __destruct_n&> __h2(__buff, __d);
|
||||
|
|
@ -92,30 +99,35 @@ __buffered_inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator
|
|||
{
|
||||
value_type* __p = __buff;
|
||||
for (_BidirectionalIterator __i = __first; __i != __middle; __d.template __incr<value_type>(), (void) ++__i, (void) ++__p)
|
||||
::new ((void*)__p) value_type(_VSTD::move(*__i));
|
||||
_VSTD::__half_inplace_merge<_Compare>(__buff, __p, __middle, __last, __first, __comp);
|
||||
::new ((void*)__p) value_type(_IterOps<_AlgPolicy>::__iter_move(__i));
|
||||
std::__half_inplace_merge<_AlgPolicy>(__buff, __p, __middle, __last, __first, __comp);
|
||||
}
|
||||
else
|
||||
{
|
||||
value_type* __p = __buff;
|
||||
for (_BidirectionalIterator __i = __middle; __i != __last; __d.template __incr<value_type>(), (void) ++__i, (void) ++__p)
|
||||
::new ((void*)__p) value_type(_VSTD::move(*__i));
|
||||
typedef reverse_iterator<_BidirectionalIterator> _RBi;
|
||||
typedef reverse_iterator<value_type*> _Rv;
|
||||
::new ((void*)__p) value_type(_IterOps<_AlgPolicy>::__iter_move(__i));
|
||||
typedef __unconstrained_reverse_iterator<_BidirectionalIterator> _RBi;
|
||||
typedef __unconstrained_reverse_iterator<value_type*> _Rv;
|
||||
typedef __invert<_Compare> _Inverted;
|
||||
_VSTD::__half_inplace_merge<_Inverted>(_Rv(__p), _Rv(__buff),
|
||||
std::__half_inplace_merge<_AlgPolicy>(_Rv(__p), _Rv(__buff),
|
||||
_RBi(__middle), _RBi(__first),
|
||||
_RBi(__last), _Inverted(__comp));
|
||||
}
|
||||
}
|
||||
|
||||
template <class _Compare, class _BidirectionalIterator>
|
||||
void
|
||||
__inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last,
|
||||
_Compare __comp, typename iterator_traits<_BidirectionalIterator>::difference_type __len1,
|
||||
template <class _AlgPolicy, class _Compare, class _BidirectionalIterator>
|
||||
void __inplace_merge(
|
||||
_BidirectionalIterator __first,
|
||||
_BidirectionalIterator __middle,
|
||||
_BidirectionalIterator __last,
|
||||
_Compare&& __comp,
|
||||
typename iterator_traits<_BidirectionalIterator>::difference_type __len1,
|
||||
typename iterator_traits<_BidirectionalIterator>::difference_type __len2,
|
||||
typename iterator_traits<_BidirectionalIterator>::value_type* __buff, ptrdiff_t __buff_size)
|
||||
{
|
||||
typename iterator_traits<_BidirectionalIterator>::value_type* __buff,
|
||||
ptrdiff_t __buff_size) {
|
||||
using _Ops = _IterOps<_AlgPolicy>;
|
||||
|
||||
typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
|
||||
while (true)
|
||||
{
|
||||
|
|
@ -123,7 +135,7 @@ __inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle,
|
|||
if (__len2 == 0)
|
||||
return;
|
||||
if (__len1 <= __buff_size || __len2 <= __buff_size)
|
||||
return _VSTD::__buffered_inplace_merge<_Compare>
|
||||
return std::__buffered_inplace_merge<_AlgPolicy>
|
||||
(__first, __middle, __last, __comp, __len1, __len2, __buff);
|
||||
// shrink [__first, __middle) as much as possible (with no moves), returning if it shrinks to 0
|
||||
for (; true; ++__first, (void) --__len1)
|
||||
|
|
@ -150,36 +162,37 @@ __inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle,
|
|||
{ // __len >= 1, __len2 >= 2
|
||||
__len21 = __len2 / 2;
|
||||
__m2 = __middle;
|
||||
_VSTD::advance(__m2, __len21);
|
||||
__m1 = _VSTD::__upper_bound<_Compare>(__first, __middle, *__m2, __comp);
|
||||
__len11 = _VSTD::distance(__first, __m1);
|
||||
_Ops::advance(__m2, __len21);
|
||||
__m1 = std::__upper_bound<_AlgPolicy>(__first, __middle, *__m2, __comp, std::__identity());
|
||||
__len11 = _Ops::distance(__first, __m1);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (__len1 == 1)
|
||||
{ // __len1 >= __len2 && __len2 > 0, therefore __len2 == 1
|
||||
// It is known *__first > *__middle
|
||||
swap(*__first, *__middle);
|
||||
_Ops::iter_swap(__first, __middle);
|
||||
return;
|
||||
}
|
||||
// __len1 >= 2, __len2 >= 1
|
||||
__len11 = __len1 / 2;
|
||||
__m1 = __first;
|
||||
_VSTD::advance(__m1, __len11);
|
||||
__m2 = _VSTD::__lower_bound<_Compare>(__middle, __last, *__m1, __comp);
|
||||
__len21 = _VSTD::distance(__middle, __m2);
|
||||
_Ops::advance(__m1, __len11);
|
||||
__m2 = std::lower_bound(__middle, __last, *__m1, __comp);
|
||||
__len21 = _Ops::distance(__middle, __m2);
|
||||
}
|
||||
difference_type __len12 = __len1 - __len11; // distance(__m1, __middle)
|
||||
difference_type __len22 = __len2 - __len21; // distance(__m2, __last)
|
||||
// [__first, __m1) [__m1, __middle) [__middle, __m2) [__m2, __last)
|
||||
// swap middle two partitions
|
||||
// TODO(alg-policy): pass `_AlgPolicy` once it's supported by `rotate`.
|
||||
__middle = _VSTD::rotate(__m1, __middle, __m2);
|
||||
// __len12 and __len21 now have swapped meanings
|
||||
// merge smaller range with recursive call and larger with tail recursion elimination
|
||||
if (__len11 + __len21 < __len12 + __len22)
|
||||
{
|
||||
_VSTD::__inplace_merge<_Compare>(__first, __m1, __middle, __comp, __len11, __len21, __buff, __buff_size);
|
||||
// _VSTD::__inplace_merge<_Compare>(__middle, __m2, __last, __comp, __len12, __len22, __buff, __buff_size);
|
||||
std::__inplace_merge<_AlgPolicy>(
|
||||
__first, __m1, __middle, __comp, __len11, __len21, __buff, __buff_size);
|
||||
__first = __middle;
|
||||
__middle = __m2;
|
||||
__len1 = __len12;
|
||||
|
|
@ -187,8 +200,8 @@ __inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle,
|
|||
}
|
||||
else
|
||||
{
|
||||
_VSTD::__inplace_merge<_Compare>(__middle, __m2, __last, __comp, __len12, __len22, __buff, __buff_size);
|
||||
// _VSTD::__inplace_merge<_Compare>(__first, __m1, __middle, __comp, __len11, __len21, __buff, __buff_size);
|
||||
std::__inplace_merge<_AlgPolicy>(
|
||||
__middle, __m2, __last, __comp, __len12, __len22, __buff, __buff_size);
|
||||
__last = __middle;
|
||||
__middle = __m1;
|
||||
__len1 = __len11;
|
||||
|
|
@ -197,30 +210,40 @@ __inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle,
|
|||
}
|
||||
}
|
||||
|
||||
template <class _BidirectionalIterator, class _Compare>
|
||||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
template <class _AlgPolicy, class _BidirectionalIterator, class _Compare>
|
||||
_LIBCPP_HIDE_FROM_ABI
|
||||
void
|
||||
inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last,
|
||||
_Compare __comp)
|
||||
__inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last,
|
||||
_Compare&& __comp)
|
||||
{
|
||||
typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
|
||||
typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
|
||||
difference_type __len1 = _VSTD::distance(__first, __middle);
|
||||
difference_type __len2 = _VSTD::distance(__middle, __last);
|
||||
difference_type __len1 = _IterOps<_AlgPolicy>::distance(__first, __middle);
|
||||
difference_type __len2 = _IterOps<_AlgPolicy>::distance(__middle, __last);
|
||||
difference_type __buf_size = _VSTD::min(__len1, __len2);
|
||||
// TODO: Remove the use of std::get_temporary_buffer
|
||||
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
|
||||
pair<value_type*, ptrdiff_t> __buf = _VSTD::get_temporary_buffer<value_type>(__buf_size);
|
||||
_LIBCPP_SUPPRESS_DEPRECATED_POP
|
||||
unique_ptr<value_type, __return_temporary_buffer> __h(__buf.first);
|
||||
return std::__inplace_merge<_AlgPolicy>(
|
||||
std::move(__first), std::move(__middle), std::move(__last), __comp, __len1, __len2, __buf.first, __buf.second);
|
||||
}
|
||||
|
||||
template <class _BidirectionalIterator, class _Compare>
|
||||
inline _LIBCPP_HIDE_FROM_ABI void inplace_merge(
|
||||
_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last, _Compare __comp) {
|
||||
typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
|
||||
return _VSTD::__inplace_merge<_Comp_ref>(__first, __middle, __last, __comp, __len1, __len2,
|
||||
__buf.first, __buf.second);
|
||||
std::__inplace_merge<_ClassicAlgPolicy>(
|
||||
std::move(__first), std::move(__middle), std::move(__last), static_cast<_Comp_ref>(__comp));
|
||||
}
|
||||
|
||||
template <class _BidirectionalIterator>
|
||||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
inline _LIBCPP_HIDE_FROM_ABI
|
||||
void
|
||||
inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last)
|
||||
{
|
||||
_VSTD::inplace_merge(__first, __middle, __last,
|
||||
std::inplace_merge(std::move(__first), std::move(__middle), std::move(__last),
|
||||
__less<typename iterator_traits<_BidirectionalIterator>::value_type>());
|
||||
}
|
||||
|
||||
|
|
|
|||
4
lib/libcxx/include/__algorithm/is_heap.h
vendored
4
lib/libcxx/include/__algorithm/is_heap.h
vendored
|
|
@ -16,7 +16,7 @@
|
|||
#include <__iterator/iterator_traits.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
|
@ -28,7 +28,7 @@ bool
|
|||
is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
|
||||
{
|
||||
typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
|
||||
return _VSTD::__is_heap_until<_Comp_ref>(__first, __last, __comp) == __last;
|
||||
return std::__is_heap_until(__first, __last, static_cast<_Comp_ref>(__comp)) == __last;
|
||||
}
|
||||
|
||||
template<class _RandomAccessIterator>
|
||||
|
|
|
|||
|
|
@ -15,14 +15,14 @@
|
|||
#include <__iterator/iterator_traits.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _Compare, class _RandomAccessIterator>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _RandomAccessIterator
|
||||
__is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
|
||||
__is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare&& __comp)
|
||||
{
|
||||
typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
|
||||
difference_type __len = __last - __first;
|
||||
|
|
@ -52,7 +52,7 @@ _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
|
|||
is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
|
||||
{
|
||||
typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
|
||||
return _VSTD::__is_heap_until<_Comp_ref>(__first, __last, __comp);
|
||||
return std::__is_heap_until(__first, __last, static_cast<_Comp_ref>(__comp));
|
||||
}
|
||||
|
||||
template<class _RandomAccessIterator>
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
#include <__config>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
#include <__iterator/next.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
|
|
|||
2
lib/libcxx/include/__algorithm/is_sorted.h
vendored
2
lib/libcxx/include/__algorithm/is_sorted.h
vendored
|
|
@ -16,7 +16,7 @@
|
|||
#include <__iterator/iterator_traits.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
#include <__iterator/iterator_traits.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
|
|
|||
2
lib/libcxx/include/__algorithm/iter_swap.h
vendored
2
lib/libcxx/include/__algorithm/iter_swap.h
vendored
|
|
@ -14,7 +14,7 @@
|
|||
#include <__utility/swap.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
|
|
|||
148
lib/libcxx/include/__algorithm/iterator_operations.h
vendored
Normal file
148
lib/libcxx/include/__algorithm/iterator_operations.h
vendored
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_ITERATOR_OPERATIONS_H
|
||||
#define _LIBCPP___ALGORITHM_ITERATOR_OPERATIONS_H
|
||||
|
||||
#include <__algorithm/iter_swap.h>
|
||||
#include <__config>
|
||||
#include <__iterator/advance.h>
|
||||
#include <__iterator/distance.h>
|
||||
#include <__iterator/iter_move.h>
|
||||
#include <__iterator/iter_swap.h>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__iterator/next.h>
|
||||
#include <__iterator/readable_traits.h>
|
||||
#include <__utility/declval.h>
|
||||
#include <__utility/forward.h>
|
||||
#include <__utility/move.h>
|
||||
#include <type_traits>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _AlgPolicy> struct _IterOps;
|
||||
|
||||
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
struct _RangeAlgPolicy {};
|
||||
|
||||
template <>
|
||||
struct _IterOps<_RangeAlgPolicy> {
|
||||
|
||||
template <class _Iter>
|
||||
using __value_type = iter_value_t<_Iter>;
|
||||
|
||||
static constexpr auto advance = ranges::advance;
|
||||
static constexpr auto distance = ranges::distance;
|
||||
static constexpr auto __iter_move = ranges::iter_move;
|
||||
static constexpr auto iter_swap = ranges::iter_swap;
|
||||
static constexpr auto next = ranges::next;
|
||||
static constexpr auto __advance_to = ranges::advance;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
struct _ClassicAlgPolicy {};
|
||||
|
||||
template <>
|
||||
struct _IterOps<_ClassicAlgPolicy> {
|
||||
|
||||
template <class _Iter>
|
||||
using __value_type = typename iterator_traits<_Iter>::value_type;
|
||||
|
||||
// advance
|
||||
template <class _Iter, class _Distance>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
|
||||
static void advance(_Iter& __iter, _Distance __count) {
|
||||
std::advance(__iter, __count);
|
||||
}
|
||||
|
||||
// distance
|
||||
template <class _Iter>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
|
||||
static typename iterator_traits<_Iter>::difference_type distance(_Iter __first, _Iter __last) {
|
||||
return std::distance(__first, __last);
|
||||
}
|
||||
|
||||
template <class _Iter>
|
||||
using __deref_t = decltype(*std::declval<_Iter&>());
|
||||
|
||||
template <class _Iter>
|
||||
using __move_t = decltype(std::move(*std::declval<_Iter&>()));
|
||||
|
||||
template <class _Iter>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
|
||||
static void __validate_iter_reference() {
|
||||
static_assert(is_same<__deref_t<_Iter>, typename iterator_traits<__uncvref_t<_Iter> >::reference>::value,
|
||||
"It looks like your iterator's `iterator_traits<It>::reference` does not match the return type of "
|
||||
"dereferencing the iterator, i.e., calling `*it`. This is undefined behavior according to [input.iterators] "
|
||||
"and can lead to dangling reference issues at runtime, so we are flagging this.");
|
||||
}
|
||||
|
||||
// iter_move
|
||||
template <class _Iter>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 static
|
||||
// If the result of dereferencing `_Iter` is a reference type, deduce the result of calling `std::move` on it. Note
|
||||
// that the C++03 mode doesn't support `decltype(auto)` as the return type.
|
||||
__enable_if_t<
|
||||
is_reference<__deref_t<_Iter> >::value,
|
||||
__move_t<_Iter> >
|
||||
__iter_move(_Iter&& __i) {
|
||||
__validate_iter_reference<_Iter>();
|
||||
|
||||
return std::move(*std::forward<_Iter>(__i));
|
||||
}
|
||||
|
||||
template <class _Iter>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 static
|
||||
// If the result of dereferencing `_Iter` is a value type, deduce the return value of this function to also be a
|
||||
// value -- otherwise, after `operator*` returns a temporary, this function would return a dangling reference to that
|
||||
// temporary. Note that the C++03 mode doesn't support `auto` as the return type.
|
||||
__enable_if_t<
|
||||
!is_reference<__deref_t<_Iter> >::value,
|
||||
__deref_t<_Iter> >
|
||||
__iter_move(_Iter&& __i) {
|
||||
__validate_iter_reference<_Iter>();
|
||||
|
||||
return *std::forward<_Iter>(__i);
|
||||
}
|
||||
|
||||
// iter_swap
|
||||
template <class _Iter1, class _Iter2>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
|
||||
static void iter_swap(_Iter1&& __a, _Iter2&& __b) {
|
||||
std::iter_swap(std::forward<_Iter1>(__a), std::forward<_Iter2>(__b));
|
||||
}
|
||||
|
||||
// next
|
||||
template <class _Iterator>
|
||||
_LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_AFTER_CXX11
|
||||
_Iterator next(_Iterator, _Iterator __last) {
|
||||
return __last;
|
||||
}
|
||||
|
||||
template <class _Iter>
|
||||
_LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_AFTER_CXX11
|
||||
__uncvref_t<_Iter> next(_Iter&& __it,
|
||||
typename iterator_traits<__uncvref_t<_Iter> >::difference_type __n = 1){
|
||||
return std::next(std::forward<_Iter>(__it), __n);
|
||||
}
|
||||
|
||||
template <class _Iter>
|
||||
_LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_AFTER_CXX11
|
||||
void __advance_to(_Iter& __first, _Iter __last) {
|
||||
__first = __last;
|
||||
}
|
||||
};
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_ITERATOR_OPERATIONS_H
|
||||
|
|
@ -15,7 +15,7 @@
|
|||
#include <__iterator/iterator_traits.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
|
|
|||
60
lib/libcxx/include/__algorithm/lower_bound.h
vendored
60
lib/libcxx/include/__algorithm/lower_bound.h
vendored
|
|
@ -11,53 +11,55 @@
|
|||
|
||||
#include <__algorithm/comp.h>
|
||||
#include <__algorithm/half_positive.h>
|
||||
#include <__algorithm/iterator_operations.h>
|
||||
#include <__config>
|
||||
#include <iterator>
|
||||
#include <__functional/identity.h>
|
||||
#include <__functional/invoke.h>
|
||||
#include <__iterator/advance.h>
|
||||
#include <__iterator/distance.h>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__type_traits/is_callable.h>
|
||||
#include <__type_traits/remove_reference.h>
|
||||
#include <type_traits>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _Compare, class _ForwardIterator, class _Tp>
|
||||
_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
|
||||
__lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
|
||||
{
|
||||
typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type;
|
||||
difference_type __len = _VSTD::distance(__first, __last);
|
||||
while (__len != 0)
|
||||
{
|
||||
difference_type __l2 = _VSTD::__half_positive(__len);
|
||||
_ForwardIterator __m = __first;
|
||||
_VSTD::advance(__m, __l2);
|
||||
if (__comp(*__m, __value_))
|
||||
{
|
||||
template <class _AlgPolicy, class _Iter, class _Sent, class _Type, class _Proj, class _Comp>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
_Iter __lower_bound_impl(_Iter __first, _Sent __last, const _Type& __value, _Comp& __comp, _Proj& __proj) {
|
||||
auto __len = _IterOps<_AlgPolicy>::distance(__first, __last);
|
||||
|
||||
while (__len != 0) {
|
||||
auto __l2 = std::__half_positive(__len);
|
||||
_Iter __m = __first;
|
||||
_IterOps<_AlgPolicy>::advance(__m, __l2);
|
||||
if (std::__invoke(__comp, std::__invoke(__proj, *__m), __value)) {
|
||||
__first = ++__m;
|
||||
__len -= __l2 + 1;
|
||||
}
|
||||
else
|
||||
} else {
|
||||
__len = __l2;
|
||||
}
|
||||
}
|
||||
return __first;
|
||||
}
|
||||
|
||||
template <class _ForwardIterator, class _Tp, class _Compare>
|
||||
_LIBCPP_NODISCARD_EXT inline
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
_ForwardIterator
|
||||
lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
|
||||
{
|
||||
return _VSTD::__lower_bound<_Compare&>(__first, __last, __value_, __comp);
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
_ForwardIterator lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) {
|
||||
static_assert(__is_callable<_Compare, decltype(*__first), const _Tp&>::value,
|
||||
"The comparator has to be callable");
|
||||
auto __proj = std::__identity();
|
||||
return std::__lower_bound_impl<_ClassicAlgPolicy>(__first, __last, __value, __comp, __proj);
|
||||
}
|
||||
|
||||
template <class _ForwardIterator, class _Tp>
|
||||
_LIBCPP_NODISCARD_EXT inline
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
_ForwardIterator
|
||||
lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_)
|
||||
{
|
||||
return _VSTD::lower_bound(__first, __last, __value_,
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
_ForwardIterator lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
|
||||
return std::lower_bound(__first, __last, __value,
|
||||
__less<typename iterator_traits<_ForwardIterator>::value_type, _Tp>());
|
||||
}
|
||||
|
||||
|
|
|
|||
42
lib/libcxx/include/__algorithm/make_heap.h
vendored
42
lib/libcxx/include/__algorithm/make_heap.h
vendored
|
|
@ -11,47 +11,45 @@
|
|||
|
||||
#include <__algorithm/comp.h>
|
||||
#include <__algorithm/comp_ref_type.h>
|
||||
#include <__algorithm/iterator_operations.h>
|
||||
#include <__algorithm/sift_down.h>
|
||||
#include <__config>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__utility/move.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _Compare, class _RandomAccessIterator>
|
||||
_LIBCPP_CONSTEXPR_AFTER_CXX11 void
|
||||
__make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
|
||||
{
|
||||
typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
|
||||
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
|
||||
void __make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare&& __comp) {
|
||||
using _CompRef = typename __comp_ref_type<_Compare>::type;
|
||||
_CompRef __comp_ref = __comp;
|
||||
|
||||
using difference_type = typename iterator_traits<_RandomAccessIterator>::difference_type;
|
||||
difference_type __n = __last - __first;
|
||||
if (__n > 1)
|
||||
{
|
||||
if (__n > 1) {
|
||||
// start from the first parent, there is no need to consider children
|
||||
for (difference_type __start = (__n - 2) / 2; __start >= 0; --__start)
|
||||
{
|
||||
_VSTD::__sift_down<_Compare>(__first, __comp, __n, __first + __start);
|
||||
for (difference_type __start = (__n - 2) / 2; __start >= 0; --__start) {
|
||||
std::__sift_down<_AlgPolicy>(__first, __comp_ref, __n, __first + __start);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class _RandomAccessIterator, class _Compare>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
void
|
||||
make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
|
||||
{
|
||||
typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
|
||||
_VSTD::__make_heap<_Comp_ref>(__first, __last, __comp);
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
void make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) {
|
||||
std::__make_heap<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __comp);
|
||||
}
|
||||
|
||||
template <class _RandomAccessIterator>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
void
|
||||
make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
|
||||
{
|
||||
_VSTD::make_heap(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
void make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) {
|
||||
std::make_heap(std::move(__first), std::move(__last),
|
||||
__less<typename iterator_traits<_RandomAccessIterator>::value_type>());
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
|
|
|||
126
lib/libcxx/include/__algorithm/make_projected.h
vendored
Normal file
126
lib/libcxx/include/__algorithm/make_projected.h
vendored
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_MAKE_PROJECTED_H
|
||||
#define _LIBCPP___ALGORITHM_MAKE_PROJECTED_H
|
||||
|
||||
#include <__concepts/same_as.h>
|
||||
#include <__config>
|
||||
#include <__functional/identity.h>
|
||||
#include <__functional/invoke.h>
|
||||
#include <__type_traits/decay.h>
|
||||
#include <__type_traits/enable_if.h>
|
||||
#include <__type_traits/integral_constant.h>
|
||||
#include <__type_traits/is_member_pointer.h>
|
||||
#include <__type_traits/is_same.h>
|
||||
#include <__utility/declval.h>
|
||||
#include <__utility/forward.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _Pred, class _Proj>
|
||||
struct _ProjectedPred {
|
||||
_Pred& __pred; // Can be a unary or a binary predicate.
|
||||
_Proj& __proj;
|
||||
|
||||
_LIBCPP_CONSTEXPR _ProjectedPred(_Pred& __pred_arg, _Proj& __proj_arg) : __pred(__pred_arg), __proj(__proj_arg) {}
|
||||
|
||||
template <class _Tp>
|
||||
typename __invoke_of<_Pred&,
|
||||
decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_Tp>()))
|
||||
>::type
|
||||
_LIBCPP_CONSTEXPR operator()(_Tp&& __v) const {
|
||||
return std::__invoke(__pred, std::__invoke(__proj, std::forward<_Tp>(__v)));
|
||||
}
|
||||
|
||||
template <class _T1, class _T2>
|
||||
typename __invoke_of<_Pred&,
|
||||
decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_T1>())),
|
||||
decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_T2>()))
|
||||
>::type
|
||||
_LIBCPP_CONSTEXPR operator()(_T1&& __lhs, _T2&& __rhs) const {
|
||||
return std::__invoke(__pred,
|
||||
std::__invoke(__proj, std::forward<_T1>(__lhs)),
|
||||
std::__invoke(__proj, std::forward<_T2>(__rhs)));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template <class _Pred, class _Proj, class = void>
|
||||
struct __can_use_pristine_comp : false_type {};
|
||||
|
||||
template <class _Pred, class _Proj>
|
||||
struct __can_use_pristine_comp<_Pred, _Proj, __enable_if_t<
|
||||
!is_member_pointer<typename decay<_Pred>::type>::value && (
|
||||
#if _LIBCPP_STD_VER > 17
|
||||
is_same<typename decay<_Proj>::type, identity>::value ||
|
||||
#endif
|
||||
is_same<typename decay<_Proj>::type, __identity>::value
|
||||
)
|
||||
> > : true_type {};
|
||||
|
||||
template <class _Pred, class _Proj>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR static
|
||||
__enable_if_t<
|
||||
!__can_use_pristine_comp<_Pred, _Proj>::value,
|
||||
_ProjectedPred<_Pred, _Proj>
|
||||
>
|
||||
__make_projected(_Pred& __pred, _Proj& __proj) {
|
||||
return _ProjectedPred<_Pred, _Proj>(__pred, __proj);
|
||||
}
|
||||
|
||||
// Avoid creating the functor and just use the pristine comparator -- for certain algorithms, this would enable
|
||||
// optimizations that rely on the type of the comparator. Additionally, this results in less layers of indirection in
|
||||
// the call stack when the comparator is invoked, even in an unoptimized build.
|
||||
template <class _Pred, class _Proj>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR static
|
||||
__enable_if_t<
|
||||
__can_use_pristine_comp<_Pred, _Proj>::value,
|
||||
_Pred&
|
||||
>
|
||||
__make_projected(_Pred& __pred, _Proj&) {
|
||||
return __pred;
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
namespace ranges {
|
||||
|
||||
template <class _Comp, class _Proj1, class _Proj2>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr static
|
||||
decltype(auto) __make_projected_comp(_Comp& __comp, _Proj1& __proj1, _Proj2& __proj2) {
|
||||
if constexpr (same_as<decay_t<_Proj1>, identity> && same_as<decay_t<_Proj2>, identity> &&
|
||||
!is_member_pointer_v<decay_t<_Comp>>) {
|
||||
// Avoid creating the lambda and just use the pristine comparator -- for certain algorithms, this would enable
|
||||
// optimizations that rely on the type of the comparator.
|
||||
return __comp;
|
||||
|
||||
} else {
|
||||
return [&](auto&& __lhs, auto&& __rhs) {
|
||||
return std::invoke(__comp,
|
||||
std::invoke(__proj1, std::forward<decltype(__lhs)>(__lhs)),
|
||||
std::invoke(__proj2, std::forward<decltype(__rhs)>(__rhs)));
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ranges
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_MAKE_PROJECTED_H
|
||||
2
lib/libcxx/include/__algorithm/max.h
vendored
2
lib/libcxx/include/__algorithm/max.h
vendored
|
|
@ -16,7 +16,7 @@
|
|||
#include <initializer_list>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_PUSH_MACROS
|
||||
|
|
|
|||
2
lib/libcxx/include/__algorithm/max_element.h
vendored
2
lib/libcxx/include/__algorithm/max_element.h
vendored
|
|
@ -15,7 +15,7 @@
|
|||
#include <__iterator/iterator_traits.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
|
|
|||
2
lib/libcxx/include/__algorithm/merge.h
vendored
2
lib/libcxx/include/__algorithm/merge.h
vendored
|
|
@ -16,7 +16,7 @@
|
|||
#include <__iterator/iterator_traits.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
|
|
|||
2
lib/libcxx/include/__algorithm/min.h
vendored
2
lib/libcxx/include/__algorithm/min.h
vendored
|
|
@ -16,7 +16,7 @@
|
|||
#include <initializer_list>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_PUSH_MACROS
|
||||
|
|
|
|||
44
lib/libcxx/include/__algorithm/min_element.h
vendored
44
lib/libcxx/include/__algorithm/min_element.h
vendored
|
|
@ -12,36 +12,50 @@
|
|||
#include <__algorithm/comp.h>
|
||||
#include <__algorithm/comp_ref_type.h>
|
||||
#include <__config>
|
||||
#include <__functional/identity.h>
|
||||
#include <__functional/invoke.h>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__type_traits/is_callable.h>
|
||||
#include <__utility/move.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _Compare, class _ForwardIterator>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator
|
||||
__min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
|
||||
{
|
||||
static_assert(__is_cpp17_forward_iterator<_ForwardIterator>::value,
|
||||
"std::min_element requires a ForwardIterator");
|
||||
if (__first != __last)
|
||||
{
|
||||
_ForwardIterator __i = __first;
|
||||
while (++__i != __last)
|
||||
if (__comp(*__i, *__first))
|
||||
__first = __i;
|
||||
}
|
||||
template <class _Comp, class _Iter, class _Sent, class _Proj>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
|
||||
_Iter __min_element(_Iter __first, _Sent __last, _Comp __comp, _Proj& __proj) {
|
||||
if (__first == __last)
|
||||
return __first;
|
||||
|
||||
_Iter __i = __first;
|
||||
while (++__i != __last)
|
||||
if (std::__invoke(__comp, std::__invoke(__proj, *__i), std::__invoke(__proj, *__first)))
|
||||
__first = __i;
|
||||
|
||||
return __first;
|
||||
}
|
||||
|
||||
template <class _Comp, class _Iter, class _Sent>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
|
||||
_Iter __min_element(_Iter __first, _Sent __last, _Comp __comp) {
|
||||
auto __proj = __identity();
|
||||
return std::__min_element<_Comp>(std::move(__first), std::move(__last), __comp, __proj);
|
||||
}
|
||||
|
||||
template <class _ForwardIterator, class _Compare>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator
|
||||
min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
|
||||
{
|
||||
static_assert(__is_cpp17_forward_iterator<_ForwardIterator>::value,
|
||||
"std::min_element requires a ForwardIterator");
|
||||
static_assert(__is_callable<_Compare, decltype(*__first), decltype(*__first)>::value,
|
||||
"The comparator has to be callable");
|
||||
|
||||
typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
|
||||
return _VSTD::__min_element<_Comp_ref>(__first, __last, __comp);
|
||||
return std::__min_element<_Comp_ref>(std::move(__first), std::move(__last), __comp);
|
||||
}
|
||||
|
||||
template <class _ForwardIterator>
|
||||
|
|
|
|||
56
lib/libcxx/include/__algorithm/min_max_result.h
vendored
Normal file
56
lib/libcxx/include/__algorithm/min_max_result.h
vendored
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
// -*- C++ -*-
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_MIN_MAX_RESULT_H
|
||||
#define _LIBCPP___ALGORITHM_MIN_MAX_RESULT_H
|
||||
|
||||
#include <__concepts/convertible_to.h>
|
||||
#include <__config>
|
||||
#include <__utility/move.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_PUSH_MACROS
|
||||
#include <__undef_macros>
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
namespace ranges {
|
||||
|
||||
template <class _T1>
|
||||
struct min_max_result {
|
||||
_LIBCPP_NO_UNIQUE_ADDRESS _T1 min;
|
||||
_LIBCPP_NO_UNIQUE_ADDRESS _T1 max;
|
||||
|
||||
template <class _T2>
|
||||
requires convertible_to<const _T1&, _T2>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr operator min_max_result<_T2>() const & {
|
||||
return {min, max};
|
||||
}
|
||||
|
||||
template <class _T2>
|
||||
requires convertible_to<_T1, _T2>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr operator min_max_result<_T2>() && {
|
||||
return {std::move(min), std::move(max)};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace ranges
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_MIN_MAX_RESULT_H
|
||||
52
lib/libcxx/include/__algorithm/minmax.h
vendored
52
lib/libcxx/include/__algorithm/minmax.h
vendored
|
|
@ -10,12 +10,15 @@
|
|||
#define _LIBCPP___ALGORITHM_MINMAX_H
|
||||
|
||||
#include <__algorithm/comp.h>
|
||||
#include <__algorithm/minmax_element.h>
|
||||
#include <__config>
|
||||
#include <__functional/identity.h>
|
||||
#include <__type_traits/is_callable.h>
|
||||
#include <__utility/pair.h>
|
||||
#include <initializer_list>
|
||||
#include <utility>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
|
@ -36,47 +39,18 @@ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
|||
pair<const _Tp&, const _Tp&>
|
||||
minmax(const _Tp& __a, const _Tp& __b)
|
||||
{
|
||||
return _VSTD::minmax(__a, __b, __less<_Tp>());
|
||||
return std::minmax(__a, __b, __less<_Tp>());
|
||||
}
|
||||
|
||||
#ifndef _LIBCPP_CXX03_LANG
|
||||
|
||||
template<class _Tp, class _Compare>
|
||||
_LIBCPP_NODISCARD_EXT inline
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
||||
pair<_Tp, _Tp>
|
||||
minmax(initializer_list<_Tp> __t, _Compare __comp)
|
||||
{
|
||||
typedef typename initializer_list<_Tp>::const_iterator _Iter;
|
||||
_Iter __first = __t.begin();
|
||||
_Iter __last = __t.end();
|
||||
pair<_Tp, _Tp> __result(*__first, *__first);
|
||||
|
||||
++__first;
|
||||
if (__t.size() % 2 == 0)
|
||||
{
|
||||
if (__comp(*__first, __result.first))
|
||||
__result.first = *__first;
|
||||
else
|
||||
__result.second = *__first;
|
||||
++__first;
|
||||
}
|
||||
|
||||
while (__first != __last)
|
||||
{
|
||||
_Tp __prev = *__first++;
|
||||
if (__comp(*__first, __prev)) {
|
||||
if ( __comp(*__first, __result.first)) __result.first = *__first;
|
||||
if (!__comp(__prev, __result.second)) __result.second = __prev;
|
||||
}
|
||||
else {
|
||||
if ( __comp(__prev, __result.first)) __result.first = __prev;
|
||||
if (!__comp(*__first, __result.second)) __result.second = *__first;
|
||||
}
|
||||
|
||||
__first++;
|
||||
}
|
||||
return __result;
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
|
||||
pair<_Tp, _Tp> minmax(initializer_list<_Tp> __t, _Compare __comp) {
|
||||
static_assert(__is_callable<_Compare, _Tp, _Tp>::value, "The comparator has to be callable");
|
||||
__identity __proj;
|
||||
auto __ret = std::__minmax_element_impl(__t.begin(), __t.end(), __comp, __proj);
|
||||
return pair<_Tp, _Tp>(*__ret.first, *__ret.second);
|
||||
}
|
||||
|
||||
template<class _Tp>
|
||||
|
|
@ -85,7 +59,7 @@ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
|||
pair<_Tp, _Tp>
|
||||
minmax(initializer_list<_Tp> __t)
|
||||
{
|
||||
return _VSTD::minmax(__t, __less<_Tp>());
|
||||
return std::minmax(__t, __less<_Tp>());
|
||||
}
|
||||
|
||||
#endif // _LIBCPP_CXX03_LANG
|
||||
|
|
|
|||
104
lib/libcxx/include/__algorithm/minmax_element.h
vendored
104
lib/libcxx/include/__algorithm/minmax_element.h
vendored
|
|
@ -11,73 +11,89 @@
|
|||
|
||||
#include <__algorithm/comp.h>
|
||||
#include <__config>
|
||||
#include <__functional/identity.h>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <utility>
|
||||
#include <__utility/pair.h>
|
||||
#include <type_traits>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _ForwardIterator, class _Compare>
|
||||
_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX11
|
||||
pair<_ForwardIterator, _ForwardIterator>
|
||||
minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
|
||||
{
|
||||
static_assert(__is_cpp17_forward_iterator<_ForwardIterator>::value,
|
||||
"std::minmax_element requires a ForwardIterator");
|
||||
pair<_ForwardIterator, _ForwardIterator> __result(__first, __first);
|
||||
if (__first != __last)
|
||||
{
|
||||
if (++__first != __last)
|
||||
{
|
||||
if (__comp(*__first, *__result.first))
|
||||
template <class _Comp, class _Proj>
|
||||
class _MinmaxElementLessFunc {
|
||||
_Comp& __comp_;
|
||||
_Proj& __proj_;
|
||||
|
||||
public:
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
|
||||
_MinmaxElementLessFunc(_Comp& __comp, _Proj& __proj) : __comp_(__comp), __proj_(__proj) {}
|
||||
|
||||
template <class _Iter>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
|
||||
bool operator()(_Iter& __it1, _Iter& __it2) {
|
||||
return std::__invoke(__comp_, std::__invoke(__proj_, *__it1), std::__invoke(__proj_, *__it2));
|
||||
}
|
||||
};
|
||||
|
||||
template <class _Iter, class _Sent, class _Proj, class _Comp>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
|
||||
pair<_Iter, _Iter> __minmax_element_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) {
|
||||
auto __less = _MinmaxElementLessFunc<_Comp, _Proj>(__comp, __proj);
|
||||
|
||||
pair<_Iter, _Iter> __result(__first, __first);
|
||||
if (__first == __last || ++__first == __last)
|
||||
return __result;
|
||||
|
||||
if (__less(__first, __result.first))
|
||||
__result.first = __first;
|
||||
else
|
||||
__result.second = __first;
|
||||
while (++__first != __last)
|
||||
{
|
||||
_ForwardIterator __i = __first;
|
||||
if (++__first == __last)
|
||||
{
|
||||
if (__comp(*__i, *__result.first))
|
||||
|
||||
while (++__first != __last) {
|
||||
_Iter __i = __first;
|
||||
if (++__first == __last) {
|
||||
if (__less(__i, __result.first))
|
||||
__result.first = __i;
|
||||
else if (!__comp(*__i, *__result.second))
|
||||
else if (!__less(__i, __result.second))
|
||||
__result.second = __i;
|
||||
break;
|
||||
return __result;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (__comp(*__first, *__i))
|
||||
{
|
||||
if (__comp(*__first, *__result.first))
|
||||
|
||||
if (__less(__first, __i)) {
|
||||
if (__less(__first, __result.first))
|
||||
__result.first = __first;
|
||||
if (!__comp(*__i, *__result.second))
|
||||
if (!__less(__i, __result.second))
|
||||
__result.second = __i;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (__comp(*__i, *__result.first))
|
||||
} else {
|
||||
if (__less(__i, __result.first))
|
||||
__result.first = __i;
|
||||
if (!__comp(*__first, *__result.second))
|
||||
if (!__less(__first, __result.second))
|
||||
__result.second = __first;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return __result;
|
||||
}
|
||||
|
||||
template <class _ForwardIterator>
|
||||
_LIBCPP_NODISCARD_EXT inline
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
||||
template <class _ForwardIterator, class _Compare>
|
||||
_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX11
|
||||
pair<_ForwardIterator, _ForwardIterator>
|
||||
minmax_element(_ForwardIterator __first, _ForwardIterator __last)
|
||||
{
|
||||
return _VSTD::minmax_element(__first, __last,
|
||||
__less<typename iterator_traits<_ForwardIterator>::value_type>());
|
||||
minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) {
|
||||
static_assert(__is_cpp17_forward_iterator<_ForwardIterator>::value,
|
||||
"std::minmax_element requires a ForwardIterator");
|
||||
static_assert(__is_callable<_Compare, decltype(*__first), decltype(*__first)>::value,
|
||||
"The comparator has to be callable");
|
||||
auto __proj = __identity();
|
||||
return std::__minmax_element_impl(__first, __last, __comp, __proj);
|
||||
}
|
||||
|
||||
template <class _ForwardIterator>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
|
||||
pair<_ForwardIterator, _ForwardIterator> minmax_element(_ForwardIterator __first, _ForwardIterator __last) {
|
||||
return std::minmax_element(__first, __last, __less<typename iterator_traits<_ForwardIterator>::value_type>());
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
|
|
|||
4
lib/libcxx/include/__algorithm/mismatch.h
vendored
4
lib/libcxx/include/__algorithm/mismatch.h
vendored
|
|
@ -13,10 +13,10 @@
|
|||
#include <__algorithm/comp.h>
|
||||
#include <__config>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <utility>
|
||||
#include <__utility/pair.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
|
|
|||
131
lib/libcxx/include/__algorithm/move.h
vendored
131
lib/libcxx/include/__algorithm/move.h
vendored
|
|
@ -11,66 +11,103 @@
|
|||
|
||||
#include <__algorithm/unwrap_iter.h>
|
||||
#include <__config>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__iterator/reverse_iterator.h>
|
||||
#include <__utility/move.h>
|
||||
#include <__utility/pair.h>
|
||||
#include <cstring>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
// move
|
||||
|
||||
template <class _InputIterator, class _OutputIterator>
|
||||
template <class _InIter, class _Sent, class _OutIter>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
|
||||
_OutputIterator
|
||||
__move_constexpr(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
|
||||
{
|
||||
for (; __first != __last; ++__first, (void) ++__result)
|
||||
*__result = _VSTD::move(*__first);
|
||||
return __result;
|
||||
}
|
||||
|
||||
template <class _InputIterator, class _OutputIterator>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
|
||||
_OutputIterator
|
||||
__move(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
|
||||
{
|
||||
return _VSTD::__move_constexpr(__first, __last, __result);
|
||||
}
|
||||
|
||||
template <class _Tp, class _Up>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
|
||||
typename enable_if
|
||||
<
|
||||
is_same<typename remove_const<_Tp>::type, _Up>::value &&
|
||||
is_trivially_move_assignable<_Up>::value,
|
||||
_Up*
|
||||
>::type
|
||||
__move(_Tp* __first, _Tp* __last, _Up* __result)
|
||||
{
|
||||
const size_t __n = static_cast<size_t>(__last - __first);
|
||||
if (__n > 0)
|
||||
_VSTD::memmove(__result, __first, __n * sizeof(_Up));
|
||||
return __result + __n;
|
||||
}
|
||||
|
||||
template <class _InputIterator, class _OutputIterator>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
_OutputIterator
|
||||
move(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
|
||||
{
|
||||
if (__libcpp_is_constant_evaluated()) {
|
||||
return _VSTD::__move_constexpr(__first, __last, __result);
|
||||
} else {
|
||||
return _VSTD::__rewrap_iter(__result,
|
||||
_VSTD::__move(_VSTD::__unwrap_iter(__first),
|
||||
_VSTD::__unwrap_iter(__last),
|
||||
_VSTD::__unwrap_iter(__result)));
|
||||
pair<_InIter, _OutIter> __move_impl(_InIter __first, _Sent __last, _OutIter __result) {
|
||||
while (__first != __last) {
|
||||
*__result = std::move(*__first);
|
||||
++__first;
|
||||
++__result;
|
||||
}
|
||||
return std::make_pair(std::move(__first), std::move(__result));
|
||||
}
|
||||
|
||||
template <class _InType,
|
||||
class _OutType,
|
||||
class = __enable_if_t<is_same<typename remove_const<_InType>::type, _OutType>::value
|
||||
&& is_trivially_move_assignable<_OutType>::value> >
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
|
||||
pair<_InType*, _OutType*> __move_impl(_InType* __first, _InType* __last, _OutType* __result) {
|
||||
if (__libcpp_is_constant_evaluated()
|
||||
// TODO: Remove this once GCC supports __builtin_memmove during constant evaluation
|
||||
#ifndef _LIBCPP_COMPILER_GCC
|
||||
&& !is_trivially_copyable<_InType>::value
|
||||
#endif
|
||||
)
|
||||
return std::__move_impl<_InType*, _InType*, _OutType*>(__first, __last, __result);
|
||||
const size_t __n = static_cast<size_t>(__last - __first);
|
||||
::__builtin_memmove(__result, __first, __n * sizeof(_OutType));
|
||||
return std::make_pair(__first + __n, __result + __n);
|
||||
}
|
||||
|
||||
template <class>
|
||||
struct __is_trivially_move_assignable_unwrapped_impl : false_type {};
|
||||
|
||||
template <class _Type>
|
||||
struct __is_trivially_move_assignable_unwrapped_impl<_Type*> : is_trivially_move_assignable<_Type> {};
|
||||
|
||||
template <class _Iter>
|
||||
struct __is_trivially_move_assignable_unwrapped
|
||||
: __is_trivially_move_assignable_unwrapped_impl<decltype(std::__unwrap_iter<_Iter>(std::declval<_Iter>()))> {};
|
||||
|
||||
template <class _InIter,
|
||||
class _OutIter,
|
||||
__enable_if_t<is_same<typename remove_const<typename iterator_traits<_InIter>::value_type>::type,
|
||||
typename iterator_traits<_OutIter>::value_type>::value
|
||||
&& __is_cpp17_contiguous_iterator<_InIter>::value
|
||||
&& __is_cpp17_contiguous_iterator<_OutIter>::value
|
||||
&& is_trivially_move_assignable<__iter_value_type<_OutIter> >::value, int> = 0>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
|
||||
pair<reverse_iterator<_InIter>, reverse_iterator<_OutIter> >
|
||||
__move_impl(reverse_iterator<_InIter> __first,
|
||||
reverse_iterator<_InIter> __last,
|
||||
reverse_iterator<_OutIter> __result) {
|
||||
auto __first_base = std::__unwrap_iter(__first.base());
|
||||
auto __last_base = std::__unwrap_iter(__last.base());
|
||||
auto __result_base = std::__unwrap_iter(__result.base());
|
||||
auto __result_first = __result_base - (__first_base - __last_base);
|
||||
std::__move_impl(__last_base, __first_base, __result_first);
|
||||
return std::make_pair(__last, reverse_iterator<_OutIter>(std::__rewrap_iter(__result.base(), __result_first)));
|
||||
}
|
||||
|
||||
template <class _InIter, class _Sent, class _OutIter>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
|
||||
__enable_if_t<is_copy_constructible<_InIter>::value
|
||||
&& is_copy_constructible<_Sent>::value
|
||||
&& is_copy_constructible<_OutIter>::value, pair<_InIter, _OutIter> >
|
||||
__move(_InIter __first, _Sent __last, _OutIter __result) {
|
||||
auto __ret = std::__move_impl(std::__unwrap_iter(__first), std::__unwrap_iter(__last), std::__unwrap_iter(__result));
|
||||
return std::make_pair(std::__rewrap_iter(__first, __ret.first), std::__rewrap_iter(__result, __ret.second));
|
||||
}
|
||||
|
||||
template <class _InIter, class _Sent, class _OutIter>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
|
||||
__enable_if_t<!is_copy_constructible<_InIter>::value
|
||||
|| !is_copy_constructible<_Sent>::value
|
||||
|| !is_copy_constructible<_OutIter>::value, pair<_InIter, _OutIter> >
|
||||
__move(_InIter __first, _Sent __last, _OutIter __result) {
|
||||
return std::__move_impl(std::move(__first), std::move(__last), std::move(__result));
|
||||
}
|
||||
|
||||
template <class _InputIterator, class _OutputIterator>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
_OutputIterator move(_InputIterator __first, _InputIterator __last, _OutputIterator __result) {
|
||||
return std::__move(__first, __last, __result).second;
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
|
|
|||
|
|
@ -11,12 +11,12 @@
|
|||
|
||||
#include <__algorithm/unwrap_iter.h>
|
||||
#include <__config>
|
||||
#include <__utility/move.h>
|
||||
#include <cstring>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
#include <__utility/swap.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
|
|
|||
2
lib/libcxx/include/__algorithm/none_of.h
vendored
2
lib/libcxx/include/__algorithm/none_of.h
vendored
|
|
@ -13,7 +13,7 @@
|
|||
#include <__config>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
|
|
|||
73
lib/libcxx/include/__algorithm/nth_element.h
vendored
73
lib/libcxx/include/__algorithm/nth_element.h
vendored
|
|
@ -11,17 +11,16 @@
|
|||
|
||||
#include <__algorithm/comp.h>
|
||||
#include <__algorithm/comp_ref_type.h>
|
||||
#include <__algorithm/iterator_operations.h>
|
||||
#include <__algorithm/sort.h>
|
||||
#include <__config>
|
||||
#include <__debug>
|
||||
#include <__debug_utils/randomize_range.h>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__utility/swap.h>
|
||||
|
||||
#if defined(_LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY)
|
||||
# include <__algorithm/shuffle.h>
|
||||
#endif
|
||||
#include <__utility/move.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
|
@ -42,10 +41,12 @@ __nth_element_find_guard(_RandomAccessIterator& __i, _RandomAccessIterator& __j,
|
|||
}
|
||||
}
|
||||
|
||||
template <class _Compare, class _RandomAccessIterator>
|
||||
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
|
||||
_LIBCPP_CONSTEXPR_AFTER_CXX11 void
|
||||
__nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare __comp)
|
||||
{
|
||||
using _Ops = _IterOps<_AlgPolicy>;
|
||||
|
||||
// _Compare is known to be a reference type
|
||||
typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
|
||||
const difference_type __limit = 7;
|
||||
|
|
@ -61,24 +62,24 @@ __nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _Rando
|
|||
return;
|
||||
case 2:
|
||||
if (__comp(*--__last, *__first))
|
||||
swap(*__first, *__last);
|
||||
_Ops::iter_swap(__first, __last);
|
||||
return;
|
||||
case 3:
|
||||
{
|
||||
_RandomAccessIterator __m = __first;
|
||||
_VSTD::__sort3<_Compare>(__first, ++__m, --__last, __comp);
|
||||
std::__sort3<_AlgPolicy, _Compare>(__first, ++__m, --__last, __comp);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (__len <= __limit)
|
||||
{
|
||||
_VSTD::__selection_sort<_Compare>(__first, __last, __comp);
|
||||
std::__selection_sort<_AlgPolicy, _Compare>(__first, __last, __comp);
|
||||
return;
|
||||
}
|
||||
// __len > __limit >= 3
|
||||
_RandomAccessIterator __m = __first + __len/2;
|
||||
_RandomAccessIterator __lm1 = __last;
|
||||
unsigned __n_swaps = _VSTD::__sort3<_Compare>(__first, __m, --__lm1, __comp);
|
||||
unsigned __n_swaps = std::__sort3<_AlgPolicy, _Compare>(__first, __m, --__lm1, __comp);
|
||||
// *__m is median
|
||||
// partition [__first, __m) < *__m and *__m <= [__m, __last)
|
||||
// (this inhibits tossing elements equivalent to __m around unnecessarily)
|
||||
|
|
@ -91,7 +92,7 @@ __nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _Rando
|
|||
{
|
||||
// *__first == *__m, *__first doesn't go in first part
|
||||
if (_VSTD::__nth_element_find_guard<_Compare>(__i, __j, __m, __comp)) {
|
||||
swap(*__i, *__j);
|
||||
_Ops::iter_swap(__i, __j);
|
||||
++__n_swaps;
|
||||
} else {
|
||||
// *__first == *__m, *__m <= all other elements
|
||||
|
|
@ -103,7 +104,7 @@ __nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _Rando
|
|||
if (__i == __j) {
|
||||
return; // [__first, __last) all equivalent elements
|
||||
} else if (__comp(*__first, *__i)) {
|
||||
swap(*__i, *__j);
|
||||
_Ops::iter_swap(__i, __j);
|
||||
++__n_swaps;
|
||||
++__i;
|
||||
break;
|
||||
|
|
@ -122,7 +123,7 @@ __nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _Rando
|
|||
;
|
||||
if (__i >= __j)
|
||||
break;
|
||||
swap(*__i, *__j);
|
||||
_Ops::iter_swap(__i, __j);
|
||||
++__n_swaps;
|
||||
++__i;
|
||||
}
|
||||
|
|
@ -153,7 +154,7 @@ __nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _Rando
|
|||
;
|
||||
if (__i >= __j)
|
||||
break;
|
||||
swap(*__i, *__j);
|
||||
_Ops::iter_swap(__i, __j);
|
||||
++__n_swaps;
|
||||
// It is known that __m != __j
|
||||
// If __m just moved, follow it
|
||||
|
|
@ -165,7 +166,7 @@ __nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _Rando
|
|||
// [__first, __i) < *__m and *__m <= [__i, __last)
|
||||
if (__i != __m && __comp(*__m, *__i))
|
||||
{
|
||||
swap(*__i, *__m);
|
||||
_Ops::iter_swap(__i, __m);
|
||||
++__n_swaps;
|
||||
}
|
||||
// [__first, __i) < *__i and *__i <= [__i+1, __last)
|
||||
|
|
@ -221,26 +222,36 @@ __nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _Rando
|
|||
}
|
||||
}
|
||||
|
||||
template <class _RandomAccessIterator, class _Compare>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
void
|
||||
nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare __comp)
|
||||
{
|
||||
_LIBCPP_DEBUG_RANDOMIZE_RANGE(__first, __last);
|
||||
typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
|
||||
_VSTD::__nth_element<_Comp_ref>(__first, __nth, __last, __comp);
|
||||
_LIBCPP_DEBUG_RANDOMIZE_RANGE(__first, __nth);
|
||||
template <class _AlgPolicy, class _RandomAccessIterator, class _Compare>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
void __nth_element_impl(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last,
|
||||
_Compare& __comp) {
|
||||
if (__nth == __last)
|
||||
return;
|
||||
|
||||
std::__debug_randomize_range<_AlgPolicy>(__first, __last);
|
||||
|
||||
using _Comp_ref = typename __comp_ref_type<_Compare>::type;
|
||||
std::__nth_element<_AlgPolicy, _Comp_ref>(__first, __nth, __last, __comp);
|
||||
|
||||
std::__debug_randomize_range<_AlgPolicy>(__first, __nth);
|
||||
if (__nth != __last) {
|
||||
_LIBCPP_DEBUG_RANDOMIZE_RANGE(++__nth, __last);
|
||||
std::__debug_randomize_range<_AlgPolicy>(++__nth, __last);
|
||||
}
|
||||
}
|
||||
|
||||
template <class _RandomAccessIterator, class _Compare>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
void nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last,
|
||||
_Compare __comp) {
|
||||
std::__nth_element_impl<_ClassicAlgPolicy>(std::move(__first), std::move(__nth), std::move(__last), __comp);
|
||||
}
|
||||
|
||||
template <class _RandomAccessIterator>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
void
|
||||
nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last)
|
||||
{
|
||||
_VSTD::nth_element(__first, __nth, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
void nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last) {
|
||||
std::nth_element(std::move(__first), std::move(__nth), std::move(__last), __less<typename
|
||||
iterator_traits<_RandomAccessIterator>::value_type>());
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
|
|
|||
67
lib/libcxx/include/__algorithm/partial_sort.h
vendored
67
lib/libcxx/include/__algorithm/partial_sort.h
vendored
|
|
@ -11,41 +11,64 @@
|
|||
|
||||
#include <__algorithm/comp.h>
|
||||
#include <__algorithm/comp_ref_type.h>
|
||||
#include <__algorithm/iterator_operations.h>
|
||||
#include <__algorithm/make_heap.h>
|
||||
#include <__algorithm/sift_down.h>
|
||||
#include <__algorithm/sort_heap.h>
|
||||
#include <__config>
|
||||
#include <__debug>
|
||||
#include <__debug_utils/randomize_range.h>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__utility/swap.h>
|
||||
|
||||
#if defined(_LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY)
|
||||
# include <__algorithm/shuffle.h>
|
||||
#endif
|
||||
#include <__utility/move.h>
|
||||
#include <type_traits>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _Compare, class _RandomAccessIterator>
|
||||
_LIBCPP_CONSTEXPR_AFTER_CXX17 void
|
||||
__partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last,
|
||||
_Compare __comp)
|
||||
{
|
||||
if (__first == __middle)
|
||||
return;
|
||||
_VSTD::__make_heap<_Compare>(__first, __middle, __comp);
|
||||
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator, class _Sentinel>
|
||||
_LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
_RandomAccessIterator __partial_sort_impl(
|
||||
_RandomAccessIterator __first, _RandomAccessIterator __middle, _Sentinel __last, _Compare&& __comp) {
|
||||
if (__first == __middle) {
|
||||
return _IterOps<_AlgPolicy>::next(__middle, __last);
|
||||
}
|
||||
|
||||
std::__make_heap<_AlgPolicy>(__first, __middle, __comp);
|
||||
|
||||
typename iterator_traits<_RandomAccessIterator>::difference_type __len = __middle - __first;
|
||||
for (_RandomAccessIterator __i = __middle; __i != __last; ++__i)
|
||||
_RandomAccessIterator __i = __middle;
|
||||
for (; __i != __last; ++__i)
|
||||
{
|
||||
if (__comp(*__i, *__first))
|
||||
{
|
||||
swap(*__i, *__first);
|
||||
_VSTD::__sift_down<_Compare>(__first, __comp, __len, __first);
|
||||
_IterOps<_AlgPolicy>::iter_swap(__i, __first);
|
||||
std::__sift_down<_AlgPolicy>(__first, __comp, __len, __first);
|
||||
}
|
||||
|
||||
}
|
||||
_VSTD::__sort_heap<_Compare>(__first, __middle, __comp);
|
||||
std::__sort_heap<_AlgPolicy>(std::move(__first), std::move(__middle), __comp);
|
||||
|
||||
return __i;
|
||||
}
|
||||
|
||||
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator, class _Sentinel>
|
||||
_LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
_RandomAccessIterator __partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _Sentinel __last,
|
||||
_Compare& __comp) {
|
||||
if (__first == __middle)
|
||||
return _IterOps<_AlgPolicy>::next(__middle, __last);
|
||||
|
||||
std::__debug_randomize_range<_AlgPolicy>(__first, __last);
|
||||
|
||||
using _Comp_ref = typename __comp_ref_type<_Compare>::type;
|
||||
auto __last_iter = std::__partial_sort_impl<_AlgPolicy>(__first, __middle, __last, static_cast<_Comp_ref>(__comp));
|
||||
|
||||
std::__debug_randomize_range<_AlgPolicy>(__middle, __last);
|
||||
|
||||
return __last_iter;
|
||||
}
|
||||
|
||||
template <class _RandomAccessIterator, class _Compare>
|
||||
|
|
@ -54,10 +77,10 @@ void
|
|||
partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last,
|
||||
_Compare __comp)
|
||||
{
|
||||
_LIBCPP_DEBUG_RANDOMIZE_RANGE(__first, __last);
|
||||
typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
|
||||
_VSTD::__partial_sort<_Comp_ref>(__first, __middle, __last, __comp);
|
||||
_LIBCPP_DEBUG_RANDOMIZE_RANGE(__middle, __last);
|
||||
static_assert(std::is_copy_constructible<_RandomAccessIterator>::value, "Iterators must be copy constructible.");
|
||||
static_assert(std::is_copy_assignable<_RandomAccessIterator>::value, "Iterators must be copy assignable.");
|
||||
|
||||
(void)std::__partial_sort<_ClassicAlgPolicy>(std::move(__first), std::move(__middle), std::move(__last), __comp);
|
||||
}
|
||||
|
||||
template <class _RandomAccessIterator>
|
||||
|
|
|
|||
|
|
@ -11,39 +11,52 @@
|
|||
|
||||
#include <__algorithm/comp.h>
|
||||
#include <__algorithm/comp_ref_type.h>
|
||||
#include <__algorithm/iterator_operations.h>
|
||||
#include <__algorithm/make_heap.h>
|
||||
#include <__algorithm/make_projected.h>
|
||||
#include <__algorithm/sift_down.h>
|
||||
#include <__algorithm/sort_heap.h>
|
||||
#include <__config>
|
||||
#include <__functional/identity.h>
|
||||
#include <__functional/invoke.h>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__type_traits/is_callable.h>
|
||||
#include <__utility/move.h>
|
||||
#include <__utility/pair.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _Compare, class _InputIterator, class _RandomAccessIterator>
|
||||
_LIBCPP_CONSTEXPR_AFTER_CXX17 _RandomAccessIterator
|
||||
__partial_sort_copy(_InputIterator __first, _InputIterator __last,
|
||||
_RandomAccessIterator __result_first, _RandomAccessIterator __result_last, _Compare __comp)
|
||||
template <class _AlgPolicy, class _Compare,
|
||||
class _InputIterator, class _Sentinel1, class _RandomAccessIterator, class _Sentinel2,
|
||||
class _Proj1, class _Proj2>
|
||||
_LIBCPP_CONSTEXPR_AFTER_CXX17 pair<_InputIterator, _RandomAccessIterator>
|
||||
__partial_sort_copy(_InputIterator __first, _Sentinel1 __last,
|
||||
_RandomAccessIterator __result_first, _Sentinel2 __result_last,
|
||||
_Compare&& __comp, _Proj1&& __proj1, _Proj2&& __proj2)
|
||||
{
|
||||
_RandomAccessIterator __r = __result_first;
|
||||
auto&& __projected_comp = std::__make_projected(__comp, __proj2);
|
||||
|
||||
if (__r != __result_last)
|
||||
{
|
||||
for (; __first != __last && __r != __result_last; ++__first, (void) ++__r)
|
||||
*__r = *__first;
|
||||
_VSTD::__make_heap<_Compare>(__result_first, __r, __comp);
|
||||
std::__make_heap<_AlgPolicy>(__result_first, __r, __projected_comp);
|
||||
typename iterator_traits<_RandomAccessIterator>::difference_type __len = __r - __result_first;
|
||||
for (; __first != __last; ++__first)
|
||||
if (__comp(*__first, *__result_first))
|
||||
{
|
||||
if (std::__invoke(__comp, std::__invoke(__proj1, *__first), std::__invoke(__proj2, *__result_first))) {
|
||||
*__result_first = *__first;
|
||||
_VSTD::__sift_down<_Compare>(__result_first, __comp, __len, __result_first);
|
||||
std::__sift_down<_AlgPolicy>(__result_first, __projected_comp, __len, __result_first);
|
||||
}
|
||||
_VSTD::__sort_heap<_Compare>(__result_first, __r, __comp);
|
||||
std::__sort_heap<_AlgPolicy>(__result_first, __r, __projected_comp);
|
||||
}
|
||||
return __r;
|
||||
|
||||
return pair<_InputIterator, _RandomAccessIterator>(
|
||||
_IterOps<_AlgPolicy>::next(std::move(__first), std::move(__last)), std::move(__r));
|
||||
}
|
||||
|
||||
template <class _InputIterator, class _RandomAccessIterator, class _Compare>
|
||||
|
|
@ -52,8 +65,13 @@ _RandomAccessIterator
|
|||
partial_sort_copy(_InputIterator __first, _InputIterator __last,
|
||||
_RandomAccessIterator __result_first, _RandomAccessIterator __result_last, _Compare __comp)
|
||||
{
|
||||
typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
|
||||
return _VSTD::__partial_sort_copy<_Comp_ref>(__first, __last, __result_first, __result_last, __comp);
|
||||
static_assert(__is_callable<_Compare, decltype(*__first), decltype(*__result_first)>::value,
|
||||
"Comparator has to be callable");
|
||||
|
||||
using _Comp_ref = typename __comp_ref_type<_Compare>::type;
|
||||
auto __result = std::__partial_sort_copy<_ClassicAlgPolicy>(__first, __last, __result_first, __result_last,
|
||||
static_cast<_Comp_ref>(__comp), __identity(), __identity());
|
||||
return __result.second;
|
||||
}
|
||||
|
||||
template <class _InputIterator, class _RandomAccessIterator>
|
||||
|
|
|
|||
51
lib/libcxx/include/__algorithm/partition.h
vendored
51
lib/libcxx/include/__algorithm/partition.h
vendored
|
|
@ -9,50 +9,58 @@
|
|||
#ifndef _LIBCPP___ALGORITHM_PARTITION_H
|
||||
#define _LIBCPP___ALGORITHM_PARTITION_H
|
||||
|
||||
#include <__algorithm/iterator_operations.h>
|
||||
#include <__config>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__utility/swap.h>
|
||||
#include <__utility/move.h>
|
||||
#include <__utility/pair.h>
|
||||
#include <type_traits>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _Predicate, class _ForwardIterator>
|
||||
_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
|
||||
__partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, forward_iterator_tag)
|
||||
template <class _Predicate, class _AlgPolicy, class _ForwardIterator, class _Sentinel>
|
||||
_LIBCPP_CONSTEXPR_AFTER_CXX17 pair<_ForwardIterator, _ForwardIterator>
|
||||
__partition_impl(_ForwardIterator __first, _Sentinel __last, _Predicate __pred, forward_iterator_tag)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (__first == __last)
|
||||
return __first;
|
||||
return std::make_pair(std::move(__first), std::move(__first));
|
||||
if (!__pred(*__first))
|
||||
break;
|
||||
++__first;
|
||||
}
|
||||
for (_ForwardIterator __p = __first; ++__p != __last;)
|
||||
|
||||
_ForwardIterator __p = __first;
|
||||
while (++__p != __last)
|
||||
{
|
||||
if (__pred(*__p))
|
||||
{
|
||||
swap(*__first, *__p);
|
||||
_IterOps<_AlgPolicy>::iter_swap(__first, __p);
|
||||
++__first;
|
||||
}
|
||||
}
|
||||
return __first;
|
||||
return std::make_pair(std::move(__first), std::move(__p));
|
||||
}
|
||||
|
||||
template <class _Predicate, class _BidirectionalIterator>
|
||||
_LIBCPP_CONSTEXPR_AFTER_CXX17 _BidirectionalIterator
|
||||
__partition(_BidirectionalIterator __first, _BidirectionalIterator __last, _Predicate __pred,
|
||||
template <class _Predicate, class _AlgPolicy, class _BidirectionalIterator, class _Sentinel>
|
||||
_LIBCPP_CONSTEXPR_AFTER_CXX17 pair<_BidirectionalIterator, _BidirectionalIterator>
|
||||
__partition_impl(_BidirectionalIterator __first, _Sentinel __sentinel, _Predicate __pred,
|
||||
bidirectional_iterator_tag)
|
||||
{
|
||||
_BidirectionalIterator __original_last = _IterOps<_AlgPolicy>::next(__first, __sentinel);
|
||||
_BidirectionalIterator __last = __original_last;
|
||||
|
||||
while (true)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (__first == __last)
|
||||
return __first;
|
||||
return std::make_pair(std::move(__first), std::move(__original_last));
|
||||
if (!__pred(*__first))
|
||||
break;
|
||||
++__first;
|
||||
|
|
@ -60,20 +68,29 @@ __partition(_BidirectionalIterator __first, _BidirectionalIterator __last, _Pred
|
|||
do
|
||||
{
|
||||
if (__first == --__last)
|
||||
return __first;
|
||||
return std::make_pair(std::move(__first), std::move(__original_last));
|
||||
} while (!__pred(*__last));
|
||||
swap(*__first, *__last);
|
||||
_IterOps<_AlgPolicy>::iter_swap(__first, __last);
|
||||
++__first;
|
||||
}
|
||||
}
|
||||
|
||||
template <class _AlgPolicy, class _ForwardIterator, class _Sentinel, class _Predicate, class _IterCategory>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
pair<_ForwardIterator, _ForwardIterator> __partition(
|
||||
_ForwardIterator __first, _Sentinel __last, _Predicate&& __pred, _IterCategory __iter_category) {
|
||||
return std::__partition_impl<__uncvref_t<_Predicate>&, _AlgPolicy>(
|
||||
std::move(__first), std::move(__last), __pred, __iter_category);
|
||||
}
|
||||
|
||||
template <class _ForwardIterator, class _Predicate>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
_ForwardIterator
|
||||
partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
|
||||
{
|
||||
return _VSTD::__partition<_Predicate&>(
|
||||
__first, __last, __pred, typename iterator_traits<_ForwardIterator>::iterator_category());
|
||||
using _IterCategory = typename iterator_traits<_ForwardIterator>::iterator_category;
|
||||
auto __result = std::__partition<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __pred, _IterCategory());
|
||||
return __result.first;
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
|
|
|||
|
|
@ -11,10 +11,10 @@
|
|||
|
||||
#include <__config>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <utility> // pair
|
||||
#include <__utility/pair.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
|
|
|||
|
|
@ -11,10 +11,12 @@
|
|||
|
||||
#include <__algorithm/half_positive.h>
|
||||
#include <__config>
|
||||
#include <iterator>
|
||||
#include <__iterator/advance.h>
|
||||
#include <__iterator/distance.h>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
|
|
|||
63
lib/libcxx/include/__algorithm/pop_heap.h
vendored
63
lib/libcxx/include/__algorithm/pop_heap.h
vendored
|
|
@ -11,45 +11,62 @@
|
|||
|
||||
#include <__algorithm/comp.h>
|
||||
#include <__algorithm/comp_ref_type.h>
|
||||
#include <__algorithm/iterator_operations.h>
|
||||
#include <__algorithm/push_heap.h>
|
||||
#include <__algorithm/sift_down.h>
|
||||
#include <__assert>
|
||||
#include <__config>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__utility/swap.h>
|
||||
#include <__utility/move.h>
|
||||
#include <type_traits>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _Compare, class _RandomAccessIterator>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
void
|
||||
__pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp,
|
||||
typename iterator_traits<_RandomAccessIterator>::difference_type __len)
|
||||
{
|
||||
if (__len > 1)
|
||||
{
|
||||
swap(*__first, *--__last);
|
||||
_VSTD::__sift_down<_Compare>(__first, __comp, __len - 1, __first);
|
||||
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
|
||||
void __pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare& __comp,
|
||||
typename iterator_traits<_RandomAccessIterator>::difference_type __len) {
|
||||
_LIBCPP_ASSERT(__len > 0, "The heap given to pop_heap must be non-empty");
|
||||
|
||||
using _CompRef = typename __comp_ref_type<_Compare>::type;
|
||||
_CompRef __comp_ref = __comp;
|
||||
|
||||
using value_type = typename iterator_traits<_RandomAccessIterator>::value_type;
|
||||
if (__len > 1) {
|
||||
value_type __top = _IterOps<_AlgPolicy>::__iter_move(__first); // create a hole at __first
|
||||
_RandomAccessIterator __hole = std::__floyd_sift_down<_AlgPolicy>(__first, __comp_ref, __len);
|
||||
--__last;
|
||||
|
||||
if (__hole == __last) {
|
||||
*__hole = std::move(__top);
|
||||
} else {
|
||||
*__hole = _IterOps<_AlgPolicy>::__iter_move(__last);
|
||||
++__hole;
|
||||
*__last = std::move(__top);
|
||||
std::__sift_up<_AlgPolicy>(__first, __hole, __comp_ref, __hole - __first);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class _RandomAccessIterator, class _Compare>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
void
|
||||
pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
|
||||
{
|
||||
typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
|
||||
_VSTD::__pop_heap<_Comp_ref>(__first, __last, __comp, __last - __first);
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
void pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) {
|
||||
static_assert(std::is_copy_constructible<_RandomAccessIterator>::value, "Iterators must be copy constructible.");
|
||||
static_assert(std::is_copy_assignable<_RandomAccessIterator>::value, "Iterators must be copy assignable.");
|
||||
|
||||
typename iterator_traits<_RandomAccessIterator>::difference_type __len = __last - __first;
|
||||
std::__pop_heap<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __comp, __len);
|
||||
}
|
||||
|
||||
template <class _RandomAccessIterator>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
void
|
||||
pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
|
||||
{
|
||||
_VSTD::pop_heap(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
void pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) {
|
||||
std::pop_heap(std::move(__first), std::move(__last),
|
||||
__less<typename iterator_traits<_RandomAccessIterator>::value_type>());
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
#include <__utility/swap.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
|
|
|||
62
lib/libcxx/include/__algorithm/push_heap.h
vendored
62
lib/libcxx/include/__algorithm/push_heap.h
vendored
|
|
@ -11,58 +11,66 @@
|
|||
|
||||
#include <__algorithm/comp.h>
|
||||
#include <__algorithm/comp_ref_type.h>
|
||||
#include <__algorithm/iterator_operations.h>
|
||||
#include <__config>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__utility/move.h>
|
||||
#include <type_traits>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _Compare, class _RandomAccessIterator>
|
||||
_LIBCPP_CONSTEXPR_AFTER_CXX11 void
|
||||
__sift_up(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp,
|
||||
typename iterator_traits<_RandomAccessIterator>::difference_type __len)
|
||||
{
|
||||
typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
|
||||
if (__len > 1)
|
||||
{
|
||||
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
|
||||
void __sift_up(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare&& __comp,
|
||||
typename iterator_traits<_RandomAccessIterator>::difference_type __len) {
|
||||
using value_type = typename iterator_traits<_RandomAccessIterator>::value_type;
|
||||
|
||||
if (__len > 1) {
|
||||
__len = (__len - 2) / 2;
|
||||
_RandomAccessIterator __ptr = __first + __len;
|
||||
if (__comp(*__ptr, *--__last))
|
||||
{
|
||||
value_type __t(_VSTD::move(*__last));
|
||||
do
|
||||
{
|
||||
*__last = _VSTD::move(*__ptr);
|
||||
|
||||
if (__comp(*__ptr, *--__last)) {
|
||||
value_type __t(_IterOps<_AlgPolicy>::__iter_move(__last));
|
||||
do {
|
||||
*__last = _IterOps<_AlgPolicy>::__iter_move(__ptr);
|
||||
__last = __ptr;
|
||||
if (__len == 0)
|
||||
break;
|
||||
__len = (__len - 1) / 2;
|
||||
__ptr = __first + __len;
|
||||
} while (__comp(*__ptr, __t));
|
||||
*__last = _VSTD::move(__t);
|
||||
|
||||
*__last = std::move(__t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class _AlgPolicy, class _RandomAccessIterator, class _Compare>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
|
||||
void __push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare& __comp) {
|
||||
using _CompRef = typename __comp_ref_type<_Compare>::type;
|
||||
typename iterator_traits<_RandomAccessIterator>::difference_type __len = __last - __first;
|
||||
std::__sift_up<_AlgPolicy, _CompRef>(std::move(__first), std::move(__last), __comp, __len);
|
||||
}
|
||||
|
||||
template <class _RandomAccessIterator, class _Compare>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
void
|
||||
push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
|
||||
{
|
||||
typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
|
||||
_VSTD::__sift_up<_Comp_ref>(__first, __last, __comp, __last - __first);
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
void push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) {
|
||||
static_assert(std::is_copy_constructible<_RandomAccessIterator>::value, "Iterators must be copy constructible.");
|
||||
static_assert(std::is_copy_assignable<_RandomAccessIterator>::value, "Iterators must be copy assignable.");
|
||||
|
||||
std::__push_heap<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __comp);
|
||||
}
|
||||
|
||||
template <class _RandomAccessIterator>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
void
|
||||
push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
|
||||
{
|
||||
_VSTD::push_heap(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
void push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) {
|
||||
std::push_heap(std::move(__first), std::move(__last),
|
||||
__less<typename iterator_traits<_RandomAccessIterator>::value_type>());
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
|
|
|||
78
lib/libcxx/include/__algorithm/ranges_adjacent_find.h
vendored
Normal file
78
lib/libcxx/include/__algorithm/ranges_adjacent_find.h
vendored
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_RANGES_ADJACENT_FIND_H
|
||||
#define _LIBCPP___ALGORITHM_RANGES_ADJACENT_FIND_H
|
||||
|
||||
#include <__config>
|
||||
#include <__functional/identity.h>
|
||||
#include <__functional/invoke.h>
|
||||
#include <__functional/ranges_operations.h>
|
||||
#include <__iterator/concepts.h>
|
||||
#include <__iterator/projected.h>
|
||||
#include <__ranges/access.h>
|
||||
#include <__ranges/concepts.h>
|
||||
#include <__ranges/dangling.h>
|
||||
#include <__utility/move.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
namespace ranges {
|
||||
namespace __adjacent_find {
|
||||
struct __fn {
|
||||
|
||||
template <class _Iter, class _Sent, class _Proj, class _Pred>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr static
|
||||
_Iter __adjacent_find_impl(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
|
||||
if (__first == __last)
|
||||
return __first;
|
||||
|
||||
auto __i = __first;
|
||||
while (++__i != __last) {
|
||||
if (std::invoke(__pred, std::invoke(__proj, *__first), std::invoke(__proj, *__i)))
|
||||
return __first;
|
||||
__first = __i;
|
||||
}
|
||||
return __i;
|
||||
}
|
||||
|
||||
template <forward_iterator _Iter, sentinel_for<_Iter> _Sent,
|
||||
class _Proj = identity,
|
||||
indirect_binary_predicate<projected<_Iter, _Proj>, projected<_Iter, _Proj>> _Pred = ranges::equal_to>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
_Iter operator()(_Iter __first, _Sent __last, _Pred __pred = {}, _Proj __proj = {}) const {
|
||||
return __adjacent_find_impl(std::move(__first), std::move(__last), __pred, __proj);
|
||||
}
|
||||
|
||||
template <forward_range _Range,
|
||||
class _Proj = identity,
|
||||
indirect_binary_predicate<projected<iterator_t<_Range>, _Proj>,
|
||||
projected<iterator_t<_Range>, _Proj>> _Pred = ranges::equal_to>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
borrowed_iterator_t<_Range> operator()(_Range&& __range, _Pred __pred = {}, _Proj __proj = {}) const {
|
||||
return __adjacent_find_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj);
|
||||
}
|
||||
};
|
||||
} // namespace __adjacent_find
|
||||
|
||||
inline namespace __cpo {
|
||||
inline constexpr auto adjacent_find = __adjacent_find::__fn{};
|
||||
} // namespace __cpo
|
||||
} // namespace ranges
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_RANGES_ADJACENT_FIND_H
|
||||
68
lib/libcxx/include/__algorithm/ranges_all_of.h
vendored
Normal file
68
lib/libcxx/include/__algorithm/ranges_all_of.h
vendored
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_RANGES_ALL_OF_H
|
||||
#define _LIBCPP___ALGORITHM_RANGES_ALL_OF_H
|
||||
|
||||
#include <__config>
|
||||
#include <__functional/identity.h>
|
||||
#include <__functional/invoke.h>
|
||||
#include <__iterator/concepts.h>
|
||||
#include <__iterator/projected.h>
|
||||
#include <__ranges/access.h>
|
||||
#include <__ranges/concepts.h>
|
||||
#include <__utility/move.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
namespace ranges {
|
||||
namespace __all_of {
|
||||
struct __fn {
|
||||
|
||||
template <class _Iter, class _Sent, class _Proj, class _Pred>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr static
|
||||
bool __all_of_impl(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
|
||||
for (; __first != __last; ++__first) {
|
||||
if (!std::invoke(__pred, std::invoke(__proj, *__first)))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template <input_iterator _Iter, sentinel_for<_Iter> _Sent, class _Proj = identity,
|
||||
indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
bool operator()(_Iter __first, _Sent __last, _Pred __pred, _Proj __proj = {}) const {
|
||||
return __all_of_impl(std::move(__first), std::move(__last), __pred, __proj);
|
||||
}
|
||||
|
||||
template <input_range _Range, class _Proj = identity,
|
||||
indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>> _Pred>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
bool operator()(_Range&& __range, _Pred __pred, _Proj __proj = {}) const {
|
||||
return __all_of_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj);
|
||||
}
|
||||
};
|
||||
} // namespace __all_of
|
||||
|
||||
inline namespace __cpo {
|
||||
inline constexpr auto all_of = __all_of::__fn{};
|
||||
} // namespace __cpo
|
||||
} // namespace ranges
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_RANGES_ALL_OF_H
|
||||
68
lib/libcxx/include/__algorithm/ranges_any_of.h
vendored
Normal file
68
lib/libcxx/include/__algorithm/ranges_any_of.h
vendored
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_RANGES_ANY_OF_H
|
||||
#define _LIBCPP___ALGORITHM_RANGES_ANY_OF_H
|
||||
|
||||
#include <__config>
|
||||
#include <__functional/identity.h>
|
||||
#include <__functional/invoke.h>
|
||||
#include <__iterator/concepts.h>
|
||||
#include <__iterator/projected.h>
|
||||
#include <__ranges/access.h>
|
||||
#include <__ranges/concepts.h>
|
||||
#include <__utility/move.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
namespace ranges {
|
||||
namespace __any_of {
|
||||
struct __fn {
|
||||
|
||||
template <class _Iter, class _Sent, class _Proj, class _Pred>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr static
|
||||
bool __any_of_impl(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
|
||||
for (; __first != __last; ++__first) {
|
||||
if (std::invoke(__pred, std::invoke(__proj, *__first)))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template <input_iterator _Iter, sentinel_for<_Iter> _Sent, class _Proj = identity,
|
||||
indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
bool operator()(_Iter __first, _Sent __last, _Pred __pred = {}, _Proj __proj = {}) const {
|
||||
return __any_of_impl(std::move(__first), std::move(__last), __pred, __proj);
|
||||
}
|
||||
|
||||
template <input_range _Range, class _Proj = identity,
|
||||
indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>> _Pred>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
bool operator()(_Range&& __range, _Pred __pred, _Proj __proj = {}) const {
|
||||
return __any_of_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj);
|
||||
}
|
||||
};
|
||||
} // namespace __any_of
|
||||
|
||||
inline namespace __cpo {
|
||||
inline constexpr auto any_of = __any_of::__fn{};
|
||||
} // namespace __cpo
|
||||
} // namespace ranges
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_RANGES_ANY_OF_H
|
||||
63
lib/libcxx/include/__algorithm/ranges_binary_search.h
vendored
Normal file
63
lib/libcxx/include/__algorithm/ranges_binary_search.h
vendored
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_RANGES_BINARY_SEARCH_H
|
||||
#define _LIBCPP___ALGORITHM_RANGES_BINARY_SEARCH_H
|
||||
|
||||
#include <__algorithm/iterator_operations.h>
|
||||
#include <__algorithm/lower_bound.h>
|
||||
#include <__config>
|
||||
#include <__functional/identity.h>
|
||||
#include <__functional/invoke.h>
|
||||
#include <__functional/ranges_operations.h>
|
||||
#include <__iterator/concepts.h>
|
||||
#include <__iterator/projected.h>
|
||||
#include <__ranges/access.h>
|
||||
#include <__ranges/concepts.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
namespace ranges {
|
||||
namespace __binary_search {
|
||||
struct __fn {
|
||||
template <forward_iterator _Iter, sentinel_for<_Iter> _Sent, class _Type, class _Proj = identity,
|
||||
indirect_strict_weak_order<const _Type*, projected<_Iter, _Proj>> _Comp = ranges::less>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
bool operator()(_Iter __first, _Sent __last, const _Type& __value, _Comp __comp = {}, _Proj __proj = {}) const {
|
||||
auto __ret = std::__lower_bound_impl<_RangeAlgPolicy>(__first, __last, __value, __comp, __proj);
|
||||
return __ret != __last && !std::invoke(__comp, __value, std::invoke(__proj, *__first));
|
||||
}
|
||||
|
||||
template <forward_range _Range, class _Type, class _Proj = identity,
|
||||
indirect_strict_weak_order<const _Type*, projected<iterator_t<_Range>, _Proj>> _Comp = ranges::less>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
bool operator()(_Range&& __r, const _Type& __value, _Comp __comp = {}, _Proj __proj = {}) const {
|
||||
auto __first = ranges::begin(__r);
|
||||
auto __last = ranges::end(__r);
|
||||
auto __ret = std::__lower_bound_impl<_RangeAlgPolicy>(__first, __last, __value, __comp, __proj);
|
||||
return __ret != __last && !std::invoke(__comp, __value, std::invoke(__proj, *__first));
|
||||
}
|
||||
};
|
||||
} // namespace __binary_search
|
||||
|
||||
inline namespace __cpo {
|
||||
inline constexpr auto binary_search = __binary_search::__fn{};
|
||||
} // namespace __cpo
|
||||
} // namespace ranges
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_RANGES_BINARY_SEARCH_H
|
||||
65
lib/libcxx/include/__algorithm/ranges_copy.h
vendored
Normal file
65
lib/libcxx/include/__algorithm/ranges_copy.h
vendored
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_RANGES_COPY_H
|
||||
#define _LIBCPP___ALGORITHM_RANGES_COPY_H
|
||||
|
||||
#include <__algorithm/copy.h>
|
||||
#include <__algorithm/in_out_result.h>
|
||||
#include <__config>
|
||||
#include <__functional/identity.h>
|
||||
#include <__iterator/concepts.h>
|
||||
#include <__ranges/access.h>
|
||||
#include <__ranges/concepts.h>
|
||||
#include <__ranges/dangling.h>
|
||||
#include <__utility/move.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
namespace ranges {
|
||||
|
||||
template <class _InIter, class _OutIter>
|
||||
using copy_result = in_out_result<_InIter, _OutIter>;
|
||||
|
||||
namespace __copy {
|
||||
struct __fn {
|
||||
|
||||
template <input_iterator _InIter, sentinel_for<_InIter> _Sent, weakly_incrementable _OutIter>
|
||||
requires indirectly_copyable<_InIter, _OutIter>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
copy_result<_InIter, _OutIter> operator()(_InIter __first, _Sent __last, _OutIter __result) const {
|
||||
auto __ret = std::__copy(std::move(__first), std::move(__last), std::move(__result));
|
||||
return {std::move(__ret.first), std::move(__ret.second)};
|
||||
}
|
||||
|
||||
template <input_range _Range, weakly_incrementable _OutIter>
|
||||
requires indirectly_copyable<iterator_t<_Range>, _OutIter>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
copy_result<borrowed_iterator_t<_Range>, _OutIter> operator()(_Range&& __r, _OutIter __result) const {
|
||||
auto __ret = std::__copy(ranges::begin(__r), ranges::end(__r), std::move(__result));
|
||||
return {std::move(__ret.first), std::move(__ret.second)};
|
||||
}
|
||||
};
|
||||
} // namespace __copy
|
||||
|
||||
inline namespace __cpo {
|
||||
inline constexpr auto copy = __copy::__fn{};
|
||||
} // namespace __cpo
|
||||
} // namespace ranges
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_RANGES_COPY_H
|
||||
66
lib/libcxx/include/__algorithm/ranges_copy_backward.h
vendored
Normal file
66
lib/libcxx/include/__algorithm/ranges_copy_backward.h
vendored
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_RANGES_COPY_BACKWARD_H
|
||||
#define _LIBCPP___ALGORITHM_RANGES_COPY_BACKWARD_H
|
||||
|
||||
#include <__algorithm/copy_backward.h>
|
||||
#include <__algorithm/in_out_result.h>
|
||||
#include <__algorithm/iterator_operations.h>
|
||||
#include <__config>
|
||||
#include <__iterator/concepts.h>
|
||||
#include <__iterator/reverse_iterator.h>
|
||||
#include <__ranges/access.h>
|
||||
#include <__ranges/concepts.h>
|
||||
#include <__ranges/dangling.h>
|
||||
#include <__utility/move.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
namespace ranges {
|
||||
|
||||
template<class _Ip, class _Op>
|
||||
using copy_backward_result = in_out_result<_Ip, _Op>;
|
||||
|
||||
namespace __copy_backward {
|
||||
struct __fn {
|
||||
|
||||
template <bidirectional_iterator _InIter1, sentinel_for<_InIter1> _Sent1, bidirectional_iterator _InIter2>
|
||||
requires indirectly_copyable<_InIter1, _InIter2>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
copy_backward_result<_InIter1, _InIter2> operator()(_InIter1 __first, _Sent1 __last, _InIter2 __result) const {
|
||||
auto __ret = std::__copy_backward<_RangeAlgPolicy>(std::move(__first), std::move(__last), std::move(__result));
|
||||
return {std::move(__ret.first), std::move(__ret.second)};
|
||||
}
|
||||
|
||||
template <bidirectional_range _Range, bidirectional_iterator _Iter>
|
||||
requires indirectly_copyable<iterator_t<_Range>, _Iter>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
copy_backward_result<borrowed_iterator_t<_Range>, _Iter> operator()(_Range&& __r, _Iter __result) const {
|
||||
auto __ret = std::__copy_backward<_RangeAlgPolicy>(ranges::begin(__r), ranges::end(__r), std::move(__result));
|
||||
return {std::move(__ret.first), std::move(__ret.second)};
|
||||
}
|
||||
};
|
||||
} // namespace __copy_backward
|
||||
|
||||
inline namespace __cpo {
|
||||
inline constexpr auto copy_backward = __copy_backward::__fn{};
|
||||
} // namespace __cpo
|
||||
} // namespace ranges
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_RANGES_COPY_BACKWARD_H
|
||||
81
lib/libcxx/include/__algorithm/ranges_copy_if.h
vendored
Normal file
81
lib/libcxx/include/__algorithm/ranges_copy_if.h
vendored
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_RANGES_COPY_IF_H
|
||||
#define _LIBCPP___ALGORITHM_RANGES_COPY_IF_H
|
||||
|
||||
#include <__algorithm/in_out_result.h>
|
||||
#include <__config>
|
||||
#include <__functional/identity.h>
|
||||
#include <__functional/invoke.h>
|
||||
#include <__iterator/concepts.h>
|
||||
#include <__iterator/projected.h>
|
||||
#include <__ranges/access.h>
|
||||
#include <__ranges/concepts.h>
|
||||
#include <__ranges/dangling.h>
|
||||
#include <__utility/move.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
namespace ranges {
|
||||
|
||||
template<class _Ip, class _Op>
|
||||
using copy_if_result = in_out_result<_Ip, _Op>;
|
||||
|
||||
namespace __copy_if {
|
||||
struct __fn {
|
||||
|
||||
template <class _InIter, class _Sent, class _OutIter, class _Proj, class _Pred>
|
||||
_LIBCPP_HIDE_FROM_ABI static constexpr
|
||||
copy_if_result <_InIter, _OutIter>
|
||||
__copy_if_impl(_InIter __first, _Sent __last, _OutIter __result, _Pred& __pred, _Proj& __proj) {
|
||||
for (; __first != __last; ++__first) {
|
||||
if (std::invoke(__pred, std::invoke(__proj, *__first))) {
|
||||
*__result = *__first;
|
||||
++__result;
|
||||
}
|
||||
}
|
||||
return {std::move(__first), std::move(__result)};
|
||||
}
|
||||
|
||||
template <input_iterator _Iter, sentinel_for<_Iter> _Sent, weakly_incrementable _OutIter, class _Proj = identity,
|
||||
indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
|
||||
requires indirectly_copyable<_Iter, _OutIter>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
copy_if_result<_Iter, _OutIter>
|
||||
operator()(_Iter __first, _Sent __last, _OutIter __result, _Pred __pred, _Proj __proj = {}) const {
|
||||
return __copy_if_impl(std::move(__first), std::move(__last), std::move(__result), __pred, __proj);
|
||||
}
|
||||
|
||||
template <input_range _Range, weakly_incrementable _OutIter, class _Proj = identity,
|
||||
indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>> _Pred>
|
||||
requires indirectly_copyable<iterator_t<_Range>, _OutIter>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
copy_if_result<borrowed_iterator_t<_Range>, _OutIter>
|
||||
operator()(_Range&& __r, _OutIter __result, _Pred __pred, _Proj __proj = {}) const {
|
||||
return __copy_if_impl(ranges::begin(__r), ranges::end(__r), std::move(__result), __pred, __proj);
|
||||
}
|
||||
};
|
||||
} // namespace __copy_if
|
||||
|
||||
inline namespace __cpo {
|
||||
inline constexpr auto copy_if = __copy_if::__fn{};
|
||||
} // namespace __cpo
|
||||
} // namespace ranges
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_RANGES_COPY_IF_H
|
||||
76
lib/libcxx/include/__algorithm/ranges_copy_n.h
vendored
Normal file
76
lib/libcxx/include/__algorithm/ranges_copy_n.h
vendored
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_RANGES_COPY_N_H
|
||||
#define _LIBCPP___ALGORITHM_RANGES_COPY_N_H
|
||||
|
||||
#include <__algorithm/copy.h>
|
||||
#include <__algorithm/in_out_result.h>
|
||||
#include <__algorithm/ranges_copy.h>
|
||||
#include <__config>
|
||||
#include <__functional/identity.h>
|
||||
#include <__iterator/concepts.h>
|
||||
#include <__iterator/incrementable_traits.h>
|
||||
#include <__iterator/unreachable_sentinel.h>
|
||||
#include <__iterator/wrap_iter.h>
|
||||
#include <__utility/move.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
namespace ranges {
|
||||
|
||||
template <class _Ip, class _Op>
|
||||
using copy_n_result = in_out_result<_Ip, _Op>;
|
||||
|
||||
namespace __copy_n {
|
||||
struct __fn {
|
||||
|
||||
template <class _InIter, class _DiffType, class _OutIter>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr static
|
||||
copy_n_result<_InIter, _OutIter> __go(_InIter __first, _DiffType __n, _OutIter __result) {
|
||||
while (__n != 0) {
|
||||
*__result = *__first;
|
||||
++__first;
|
||||
++__result;
|
||||
--__n;
|
||||
}
|
||||
return {std::move(__first), std::move(__result)};
|
||||
}
|
||||
|
||||
template <random_access_iterator _InIter, class _DiffType, random_access_iterator _OutIter>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr static
|
||||
copy_n_result<_InIter, _OutIter> __go(_InIter __first, _DiffType __n, _OutIter __result) {
|
||||
auto __ret = std::__copy(__first, __first + __n, __result);
|
||||
return {__ret.first, __ret.second};
|
||||
}
|
||||
|
||||
template <input_iterator _Ip, weakly_incrementable _Op>
|
||||
requires indirectly_copyable<_Ip, _Op>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
copy_n_result<_Ip, _Op> operator()(_Ip __first, iter_difference_t<_Ip> __n, _Op __result) const {
|
||||
return __go(std::move(__first), __n, std::move(__result));
|
||||
}
|
||||
};
|
||||
} // namespace __copy_n
|
||||
|
||||
inline namespace __cpo {
|
||||
inline constexpr auto copy_n = __copy_n::__fn{};
|
||||
} // namespace __cpo
|
||||
} // namespace ranges
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_RANGES_COPY_N_H
|
||||
62
lib/libcxx/include/__algorithm/ranges_count.h
vendored
Normal file
62
lib/libcxx/include/__algorithm/ranges_count.h
vendored
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_RANGES_COUNT_H
|
||||
#define _LIBCPP___ALGORITHM_RANGES_COUNT_H
|
||||
|
||||
#include <__algorithm/ranges_count_if.h>
|
||||
#include <__config>
|
||||
#include <__functional/identity.h>
|
||||
#include <__functional/ranges_operations.h>
|
||||
#include <__iterator/concepts.h>
|
||||
#include <__iterator/incrementable_traits.h>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__iterator/projected.h>
|
||||
#include <__ranges/access.h>
|
||||
#include <__ranges/concepts.h>
|
||||
#include <__utility/move.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
namespace ranges {
|
||||
namespace __count {
|
||||
struct __fn {
|
||||
template <input_iterator _Iter, sentinel_for<_Iter> _Sent, class _Type, class _Proj = identity>
|
||||
requires indirect_binary_predicate<ranges::equal_to, projected<_Iter, _Proj>, const _Type*>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
iter_difference_t<_Iter> operator()(_Iter __first, _Sent __last, const _Type& __value, _Proj __proj = {}) const {
|
||||
auto __pred = [&](auto&& __e) { return __e == __value; };
|
||||
return ranges::__count_if_impl(std::move(__first), std::move(__last), __pred, __proj);
|
||||
}
|
||||
|
||||
template <input_range _Range, class _Type, class _Proj = identity>
|
||||
requires indirect_binary_predicate<ranges::equal_to, projected<iterator_t<_Range>, _Proj>, const _Type*>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
range_difference_t<_Range> operator()(_Range&& __r, const _Type& __value, _Proj __proj = {}) const {
|
||||
auto __pred = [&](auto&& __e) { return __e == __value; };
|
||||
return ranges::__count_if_impl(ranges::begin(__r), ranges::end(__r), __pred, __proj);
|
||||
}
|
||||
};
|
||||
} // namespace __count
|
||||
|
||||
inline namespace __cpo {
|
||||
inline constexpr auto count = __count::__fn{};
|
||||
} // namespace __cpo
|
||||
} // namespace ranges
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_RANGES_COUNT_H
|
||||
72
lib/libcxx/include/__algorithm/ranges_count_if.h
vendored
Normal file
72
lib/libcxx/include/__algorithm/ranges_count_if.h
vendored
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_RANGES_COUNT_IF_H
|
||||
#define _LIBCPP___ALGORITHM_RANGES_COUNT_IF_H
|
||||
|
||||
#include <__config>
|
||||
#include <__functional/identity.h>
|
||||
#include <__functional/invoke.h>
|
||||
#include <__functional/ranges_operations.h>
|
||||
#include <__iterator/concepts.h>
|
||||
#include <__iterator/incrementable_traits.h>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__iterator/projected.h>
|
||||
#include <__ranges/access.h>
|
||||
#include <__ranges/concepts.h>
|
||||
#include <__utility/move.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
namespace ranges {
|
||||
template <class _Iter, class _Sent, class _Proj, class _Pred>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
iter_difference_t<_Iter> __count_if_impl(_Iter __first, _Sent __last,
|
||||
_Pred& __pred, _Proj& __proj) {
|
||||
iter_difference_t<_Iter> __counter(0);
|
||||
for (; __first != __last; ++__first) {
|
||||
if (std::invoke(__pred, std::invoke(__proj, *__first)))
|
||||
++__counter;
|
||||
}
|
||||
return __counter;
|
||||
}
|
||||
|
||||
namespace __count_if {
|
||||
struct __fn {
|
||||
template <input_iterator _Iter, sentinel_for<_Iter> _Sent, class _Proj = identity,
|
||||
indirect_unary_predicate<projected<_Iter, _Proj>> _Predicate>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
iter_difference_t<_Iter> operator()(_Iter __first, _Sent __last, _Predicate __pred, _Proj __proj = {}) const {
|
||||
return ranges::__count_if_impl(std::move(__first), std::move(__last), __pred, __proj);
|
||||
}
|
||||
|
||||
template <input_range _Range, class _Proj = identity,
|
||||
indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>> _Predicate>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
range_difference_t<_Range> operator()(_Range&& __r, _Predicate __pred, _Proj __proj = {}) const {
|
||||
return ranges::__count_if_impl(ranges::begin(__r), ranges::end(__r), __pred, __proj);
|
||||
}
|
||||
};
|
||||
} // namespace __count_if
|
||||
|
||||
inline namespace __cpo {
|
||||
inline constexpr auto count_if = __count_if::__fn{};
|
||||
} // namespace __cpo
|
||||
} // namespace ranges
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_RANGES_COUNT_IF_H
|
||||
115
lib/libcxx/include/__algorithm/ranges_equal.h
vendored
Normal file
115
lib/libcxx/include/__algorithm/ranges_equal.h
vendored
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_RANGES_EQUAL_H
|
||||
#define _LIBCPP___ALGORITHM_RANGES_EQUAL_H
|
||||
|
||||
#include <__config>
|
||||
#include <__functional/identity.h>
|
||||
#include <__functional/invoke.h>
|
||||
#include <__functional/ranges_operations.h>
|
||||
#include <__iterator/concepts.h>
|
||||
#include <__iterator/distance.h>
|
||||
#include <__iterator/indirectly_comparable.h>
|
||||
#include <__ranges/access.h>
|
||||
#include <__ranges/concepts.h>
|
||||
#include <__utility/move.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
namespace ranges {
|
||||
namespace __equal {
|
||||
struct __fn {
|
||||
private:
|
||||
template <class _Iter1, class _Sent1,
|
||||
class _Iter2, class _Sent2,
|
||||
class _Pred,
|
||||
class _Proj1,
|
||||
class _Proj2>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr static
|
||||
bool __equal_impl(_Iter1 __first1, _Sent1 __last1,
|
||||
_Iter2 __first2, _Sent2 __last2,
|
||||
_Pred& __pred,
|
||||
_Proj1& __proj1,
|
||||
_Proj2& __proj2) {
|
||||
while (__first1 != __last1 && __first2 != __last2) {
|
||||
if (!std::invoke(__pred, std::invoke(__proj1, *__first1), std::invoke(__proj2, *__first2)))
|
||||
return false;
|
||||
++__first1;
|
||||
++__first2;
|
||||
}
|
||||
return __first1 == __last1 && __first2 == __last2;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
template <input_iterator _Iter1, sentinel_for<_Iter1> _Sent1,
|
||||
input_iterator _Iter2, sentinel_for<_Iter2> _Sent2,
|
||||
class _Pred = ranges::equal_to,
|
||||
class _Proj1 = identity,
|
||||
class _Proj2 = identity>
|
||||
requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
bool operator()(_Iter1 __first1, _Sent1 __last1,
|
||||
_Iter2 __first2, _Sent2 __last2,
|
||||
_Pred __pred = {},
|
||||
_Proj1 __proj1 = {},
|
||||
_Proj2 __proj2 = {}) const {
|
||||
if constexpr (sized_sentinel_for<_Sent1, _Iter1> && sized_sentinel_for<_Sent2, _Iter2>) {
|
||||
if (__last1 - __first1 != __last2 - __first2)
|
||||
return false;
|
||||
}
|
||||
return __equal_impl(std::move(__first1), std::move(__last1),
|
||||
std::move(__first2), std::move(__last2),
|
||||
__pred,
|
||||
__proj1,
|
||||
__proj2);
|
||||
}
|
||||
|
||||
template <input_range _Range1,
|
||||
input_range _Range2,
|
||||
class _Pred = ranges::equal_to,
|
||||
class _Proj1 = identity,
|
||||
class _Proj2 = identity>
|
||||
requires indirectly_comparable<iterator_t<_Range1>, iterator_t<_Range2>, _Pred, _Proj1, _Proj2>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
bool operator()(_Range1&& __range1,
|
||||
_Range2&& __range2,
|
||||
_Pred __pred = {},
|
||||
_Proj1 __proj1 = {},
|
||||
_Proj2 __proj2 = {}) const {
|
||||
if constexpr (sized_range<_Range1> && sized_range<_Range2>) {
|
||||
if (ranges::distance(__range1) != ranges::distance(__range2))
|
||||
return false;
|
||||
}
|
||||
return __equal_impl(ranges::begin(__range1), ranges::end(__range1),
|
||||
ranges::begin(__range2), ranges::end(__range2),
|
||||
__pred,
|
||||
__proj1,
|
||||
__proj2);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
} // namespace __equal
|
||||
|
||||
inline namespace __cpo {
|
||||
inline constexpr auto equal = __equal::__fn{};
|
||||
} // namespace __cpo
|
||||
} // namespace ranges
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_RANGES_EQUAL_H
|
||||
77
lib/libcxx/include/__algorithm/ranges_equal_range.h
vendored
Normal file
77
lib/libcxx/include/__algorithm/ranges_equal_range.h
vendored
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM __project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_RANGES_EQUAL_RANGE_H
|
||||
#define _LIBCPP___ALGORITHM_RANGES_EQUAL_RANGE_H
|
||||
|
||||
#include <__algorithm/equal_range.h>
|
||||
#include <__algorithm/iterator_operations.h>
|
||||
#include <__config>
|
||||
#include <__functional/identity.h>
|
||||
#include <__functional/invoke.h>
|
||||
#include <__functional/ranges_operations.h>
|
||||
#include <__iterator/concepts.h>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__iterator/projected.h>
|
||||
#include <__ranges/access.h>
|
||||
#include <__ranges/concepts.h>
|
||||
#include <__ranges/dangling.h>
|
||||
#include <__ranges/subrange.h>
|
||||
#include <__utility/forward.h>
|
||||
#include <__utility/move.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
namespace ranges {
|
||||
namespace __equal_range {
|
||||
|
||||
struct __fn {
|
||||
template <
|
||||
forward_iterator _Iter,
|
||||
sentinel_for<_Iter> _Sent,
|
||||
class _Tp,
|
||||
class _Proj = identity,
|
||||
indirect_strict_weak_order<const _Tp*, projected<_Iter, _Proj>> _Comp = ranges::less>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr subrange<_Iter>
|
||||
operator()(_Iter __first, _Sent __last, const _Tp& __value, _Comp __comp = {}, _Proj __proj = {}) const {
|
||||
auto __ret = std::__equal_range<_RangeAlgPolicy>(
|
||||
std::move(__first), std::move(__last), __value, __comp, __proj);
|
||||
return {std::move(__ret.first), std::move(__ret.second)};
|
||||
}
|
||||
|
||||
template <
|
||||
forward_range _Range,
|
||||
class _Tp,
|
||||
class _Proj = identity,
|
||||
indirect_strict_weak_order<const _Tp*, projected<iterator_t<_Range>, _Proj>> _Comp = ranges::less>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr borrowed_subrange_t<_Range>
|
||||
operator()(_Range&& __range, const _Tp& __value, _Comp __comp = {}, _Proj __proj = {}) const {
|
||||
auto __ret = std::__equal_range<_RangeAlgPolicy>(
|
||||
ranges::begin(__range), ranges::end(__range), __value, __comp, __proj);
|
||||
return {std::move(__ret.first), std::move(__ret.second)};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace __equal_range
|
||||
|
||||
inline namespace __cpo {
|
||||
inline constexpr auto equal_range = __equal_range::__fn{};
|
||||
} // namespace __cpo
|
||||
} // namespace ranges
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_RANGES_EQUAL_RANGE_H
|
||||
59
lib/libcxx/include/__algorithm/ranges_fill.h
vendored
Normal file
59
lib/libcxx/include/__algorithm/ranges_fill.h
vendored
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_RANGES_FILL_H
|
||||
#define _LIBCPP___ALGORITHM_RANGES_FILL_H
|
||||
|
||||
#include <__algorithm/ranges_fill_n.h>
|
||||
#include <__config>
|
||||
#include <__iterator/concepts.h>
|
||||
#include <__ranges/access.h>
|
||||
#include <__ranges/concepts.h>
|
||||
#include <__ranges/dangling.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
namespace ranges {
|
||||
namespace __fill {
|
||||
struct __fn {
|
||||
template <class _Type, output_iterator<const _Type&> _Iter, sentinel_for<_Iter> _Sent>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
_Iter operator()(_Iter __first, _Sent __last, const _Type& __value) const {
|
||||
if constexpr(random_access_iterator<_Iter> && sized_sentinel_for<_Sent, _Iter>) {
|
||||
return ranges::fill_n(__first, __last - __first, __value);
|
||||
} else {
|
||||
for (; __first != __last; ++__first)
|
||||
*__first = __value;
|
||||
return __first;
|
||||
}
|
||||
}
|
||||
|
||||
template <class _Type, output_range<const _Type&> _Range>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
borrowed_iterator_t<_Range> operator()(_Range&& __range, const _Type& __value) const {
|
||||
return (*this)(ranges::begin(__range), ranges::end(__range), __value);
|
||||
}
|
||||
};
|
||||
} // namespace __fill
|
||||
|
||||
inline namespace __cpo {
|
||||
inline constexpr auto fill = __fill::__fn{};
|
||||
} // namespace __cpo
|
||||
} // namespace ranges
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_RANGES_FILL_H
|
||||
48
lib/libcxx/include/__algorithm/ranges_fill_n.h
vendored
Normal file
48
lib/libcxx/include/__algorithm/ranges_fill_n.h
vendored
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_RANGES_FILL_N_H
|
||||
#define _LIBCPP___ALGORITHM_RANGES_FILL_N_H
|
||||
|
||||
#include <__config>
|
||||
#include <__iterator/concepts.h>
|
||||
#include <__iterator/incrementable_traits.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
namespace ranges {
|
||||
namespace __fill_n {
|
||||
struct __fn {
|
||||
template <class _Type, output_iterator<const _Type&> _Iter>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
_Iter operator()(_Iter __first, iter_difference_t<_Iter> __n, const _Type& __value) const {
|
||||
for (; __n != 0; --__n) {
|
||||
*__first = __value;
|
||||
++__first;
|
||||
}
|
||||
return __first;
|
||||
}
|
||||
};
|
||||
} // namespace __fill_n
|
||||
|
||||
inline namespace __cpo {
|
||||
inline constexpr auto fill_n = __fill_n::__fn{};
|
||||
} // namespace __cpo
|
||||
} // namespace ranges
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_RANGES_FILL_N_H
|
||||
63
lib/libcxx/include/__algorithm/ranges_find.h
vendored
Normal file
63
lib/libcxx/include/__algorithm/ranges_find.h
vendored
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_RANGES_FIND_H
|
||||
#define _LIBCPP___ALGORITHM_RANGES_FIND_H
|
||||
|
||||
#include <__algorithm/ranges_find_if.h>
|
||||
#include <__config>
|
||||
#include <__functional/identity.h>
|
||||
#include <__functional/invoke.h>
|
||||
#include <__functional/ranges_operations.h>
|
||||
#include <__iterator/concepts.h>
|
||||
#include <__iterator/projected.h>
|
||||
#include <__ranges/access.h>
|
||||
#include <__ranges/concepts.h>
|
||||
#include <__ranges/dangling.h>
|
||||
#include <__utility/forward.h>
|
||||
#include <__utility/move.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
namespace ranges {
|
||||
namespace __find {
|
||||
struct __fn {
|
||||
template <input_iterator _Ip, sentinel_for<_Ip> _Sp, class _Tp, class _Proj = identity>
|
||||
requires indirect_binary_predicate<ranges::equal_to, projected<_Ip, _Proj>, const _Tp*>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
_Ip operator()(_Ip __first, _Sp __last, const _Tp& __value, _Proj __proj = {}) const {
|
||||
auto __pred = [&](auto&& __e) { return std::forward<decltype(__e)>(__e) == __value; };
|
||||
return ranges::__find_if_impl(std::move(__first), std::move(__last), __pred, __proj);
|
||||
}
|
||||
|
||||
template <input_range _Rp, class _Tp, class _Proj = identity>
|
||||
requires indirect_binary_predicate<ranges::equal_to, projected<iterator_t<_Rp>, _Proj>, const _Tp*>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
borrowed_iterator_t<_Rp> operator()(_Rp&& __r, const _Tp& __value, _Proj __proj = {}) const {
|
||||
auto __pred = [&](auto&& __e) { return std::forward<decltype(__e)>(__e) == __value; };
|
||||
return ranges::__find_if_impl(ranges::begin(__r), ranges::end(__r), __pred, __proj);
|
||||
}
|
||||
};
|
||||
} // namespace __find
|
||||
|
||||
inline namespace __cpo {
|
||||
inline constexpr auto find = __find::__fn{};
|
||||
} // namespace __cpo
|
||||
} // namespace ranges
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_RANGES_FIND_H
|
||||
97
lib/libcxx/include/__algorithm/ranges_find_end.h
vendored
Normal file
97
lib/libcxx/include/__algorithm/ranges_find_end.h
vendored
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_RANGES_FIND_END_H
|
||||
#define _LIBCPP___ALGORITHM_RANGES_FIND_END_H
|
||||
|
||||
#include <__algorithm/find_end.h>
|
||||
#include <__algorithm/iterator_operations.h>
|
||||
#include <__algorithm/ranges_iterator_concept.h>
|
||||
#include <__config>
|
||||
#include <__functional/identity.h>
|
||||
#include <__functional/ranges_operations.h>
|
||||
#include <__iterator/concepts.h>
|
||||
#include <__iterator/indirectly_comparable.h>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__ranges/access.h>
|
||||
#include <__ranges/concepts.h>
|
||||
#include <__ranges/subrange.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
namespace ranges {
|
||||
namespace __find_end {
|
||||
struct __fn {
|
||||
template <forward_iterator _Iter1, sentinel_for<_Iter1> _Sent1,
|
||||
forward_iterator _Iter2, sentinel_for<_Iter2> _Sent2,
|
||||
class _Pred = ranges::equal_to,
|
||||
class _Proj1 = identity,
|
||||
class _Proj2 = identity>
|
||||
requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
subrange<_Iter1> operator()(_Iter1 __first1, _Sent1 __last1,
|
||||
_Iter2 __first2, _Sent2 __last2,
|
||||
_Pred __pred = {},
|
||||
_Proj1 __proj1 = {},
|
||||
_Proj2 __proj2 = {}) const {
|
||||
auto __ret = std::__find_end_impl<_RangeAlgPolicy>(
|
||||
__first1,
|
||||
__last1,
|
||||
__first2,
|
||||
__last2,
|
||||
__pred,
|
||||
__proj1,
|
||||
__proj2,
|
||||
__iterator_concept<_Iter1>(),
|
||||
__iterator_concept<_Iter2>());
|
||||
return {__ret.first, __ret.second};
|
||||
}
|
||||
|
||||
template <forward_range _Range1,
|
||||
forward_range _Range2,
|
||||
class _Pred = ranges::equal_to,
|
||||
class _Proj1 = identity,
|
||||
class _Proj2 = identity>
|
||||
requires indirectly_comparable<iterator_t<_Range1>, iterator_t<_Range2>, _Pred, _Proj1, _Proj2>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
borrowed_subrange_t<_Range1> operator()(_Range1&& __range1,
|
||||
_Range2&& __range2,
|
||||
_Pred __pred = {},
|
||||
_Proj1 __proj1 = {},
|
||||
_Proj2 __proj2 = {}) const {
|
||||
auto __ret = std::__find_end_impl<_RangeAlgPolicy>(
|
||||
ranges::begin(__range1),
|
||||
ranges::end(__range1),
|
||||
ranges::begin(__range2),
|
||||
ranges::end(__range2),
|
||||
__pred,
|
||||
__proj1,
|
||||
__proj2,
|
||||
__iterator_concept<iterator_t<_Range1>>(),
|
||||
__iterator_concept<iterator_t<_Range2>>());
|
||||
return {__ret.first, __ret.second};
|
||||
}
|
||||
};
|
||||
} // namespace __find_end
|
||||
|
||||
inline namespace __cpo {
|
||||
inline constexpr auto find_end = __find_end::__fn{};
|
||||
} // namespace __cpo
|
||||
} // namespace ranges
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_RANGES_FIND_END_H
|
||||
101
lib/libcxx/include/__algorithm/ranges_find_first_of.h
vendored
Normal file
101
lib/libcxx/include/__algorithm/ranges_find_first_of.h
vendored
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_RANGES_FIND_FIRST_OF_H
|
||||
#define _LIBCPP___ALGORITHM_RANGES_FIND_FIRST_OF_H
|
||||
|
||||
#include <__config>
|
||||
#include <__functional/identity.h>
|
||||
#include <__functional/invoke.h>
|
||||
#include <__functional/ranges_operations.h>
|
||||
#include <__iterator/concepts.h>
|
||||
#include <__iterator/indirectly_comparable.h>
|
||||
#include <__ranges/access.h>
|
||||
#include <__ranges/concepts.h>
|
||||
#include <__ranges/dangling.h>
|
||||
#include <__utility/move.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
namespace ranges {
|
||||
namespace __find_first_of {
|
||||
struct __fn {
|
||||
|
||||
template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Pred, class _Proj1, class _Proj2>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr static
|
||||
_Iter1 __find_first_of_impl(_Iter1 __first1, _Sent1 __last1,
|
||||
_Iter2 __first2, _Sent2 __last2,
|
||||
_Pred& __pred,
|
||||
_Proj1& __proj1,
|
||||
_Proj2& __proj2) {
|
||||
for (; __first1 != __last1; ++__first1) {
|
||||
for (auto __j = __first2; __j != __last2; ++__j) {
|
||||
if (std::invoke(__pred, std::invoke(__proj1, *__first1), std::invoke(__proj2, *__j)))
|
||||
return __first1;
|
||||
}
|
||||
}
|
||||
return __first1;
|
||||
}
|
||||
|
||||
template <input_iterator _Iter1, sentinel_for<_Iter1> _Sent1,
|
||||
forward_iterator _Iter2, sentinel_for<_Iter2> _Sent2,
|
||||
class _Pred = ranges::equal_to,
|
||||
class _Proj1 = identity,
|
||||
class _Proj2 = identity>
|
||||
requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
_Iter1 operator()(_Iter1 __first1, _Sent1 __last1,
|
||||
_Iter2 __first2, _Sent2 __last2,
|
||||
_Pred __pred = {},
|
||||
_Proj1 __proj1 = {},
|
||||
_Proj2 __proj2 = {}) const {
|
||||
return __find_first_of_impl(std::move(__first1), std::move(__last1),
|
||||
std::move(__first2), std::move(__last2),
|
||||
__pred,
|
||||
__proj1,
|
||||
__proj2);
|
||||
}
|
||||
|
||||
template <input_range _Range1,
|
||||
forward_range _Range2,
|
||||
class _Pred = ranges::equal_to,
|
||||
class _Proj1 = identity,
|
||||
class _Proj2 = identity>
|
||||
requires indirectly_comparable<iterator_t<_Range1>, iterator_t<_Range2>, _Pred, _Proj1, _Proj2>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
borrowed_iterator_t<_Range1> operator()(_Range1&& __range1,
|
||||
_Range2&& __range2,
|
||||
_Pred __pred = {},
|
||||
_Proj1 __proj1 = {},
|
||||
_Proj2 __proj2 = {}) const {
|
||||
return __find_first_of_impl(ranges::begin(__range1), ranges::end(__range1),
|
||||
ranges::begin(__range2), ranges::end(__range2),
|
||||
__pred,
|
||||
__proj1,
|
||||
__proj2);
|
||||
}
|
||||
|
||||
};
|
||||
} // namespace __find_first_of
|
||||
|
||||
inline namespace __cpo {
|
||||
inline constexpr auto find_first_of = __find_first_of::__fn{};
|
||||
} // namespace __cpo
|
||||
} // namespace ranges
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_RANGES_FIND_FIRST_OF_H
|
||||
71
lib/libcxx/include/__algorithm/ranges_find_if.h
vendored
Normal file
71
lib/libcxx/include/__algorithm/ranges_find_if.h
vendored
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_RANGES_FIND_IF_H
|
||||
#define _LIBCPP___ALGORITHM_RANGES_FIND_IF_H
|
||||
|
||||
#include <__config>
|
||||
#include <__functional/identity.h>
|
||||
#include <__functional/invoke.h>
|
||||
#include <__functional/ranges_operations.h>
|
||||
#include <__iterator/concepts.h>
|
||||
#include <__iterator/projected.h>
|
||||
#include <__ranges/access.h>
|
||||
#include <__ranges/concepts.h>
|
||||
#include <__ranges/dangling.h>
|
||||
#include <__utility/move.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
namespace ranges {
|
||||
|
||||
template <class _Ip, class _Sp, class _Pred, class _Proj>
|
||||
_LIBCPP_HIDE_FROM_ABI static constexpr
|
||||
_Ip __find_if_impl(_Ip __first, _Sp __last, _Pred& __pred, _Proj& __proj) {
|
||||
for (; __first != __last; ++__first) {
|
||||
if (std::invoke(__pred, std::invoke(__proj, *__first)))
|
||||
break;
|
||||
}
|
||||
return __first;
|
||||
}
|
||||
|
||||
namespace __find_if {
|
||||
struct __fn {
|
||||
|
||||
template <input_iterator _Ip, sentinel_for<_Ip> _Sp, class _Proj = identity,
|
||||
indirect_unary_predicate<projected<_Ip, _Proj>> _Pred>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
_Ip operator()(_Ip __first, _Sp __last, _Pred __pred, _Proj __proj = {}) const {
|
||||
return ranges::__find_if_impl(std::move(__first), std::move(__last), __pred, __proj);
|
||||
}
|
||||
|
||||
template <input_range _Rp, class _Proj = identity,
|
||||
indirect_unary_predicate<projected<iterator_t<_Rp>, _Proj>> _Pred>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
borrowed_iterator_t<_Rp> operator()(_Rp&& __r, _Pred __pred, _Proj __proj = {}) const {
|
||||
return ranges::__find_if_impl(ranges::begin(__r), ranges::end(__r), __pred, __proj);
|
||||
}
|
||||
};
|
||||
} // namespace __find_if
|
||||
|
||||
inline namespace __cpo {
|
||||
inline constexpr auto find_if = __find_if::__fn{};
|
||||
} // namespace __cpo
|
||||
} // namespace ranges
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_RANGES_FIND_IF_H
|
||||
63
lib/libcxx/include/__algorithm/ranges_find_if_not.h
vendored
Normal file
63
lib/libcxx/include/__algorithm/ranges_find_if_not.h
vendored
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_RANGES_FIND_IF_NOT_H
|
||||
#define _LIBCPP___ALGORITHM_RANGES_FIND_IF_NOT_H
|
||||
|
||||
#include <__algorithm/ranges_find_if.h>
|
||||
#include <__config>
|
||||
#include <__functional/identity.h>
|
||||
#include <__functional/invoke.h>
|
||||
#include <__functional/ranges_operations.h>
|
||||
#include <__iterator/concepts.h>
|
||||
#include <__iterator/projected.h>
|
||||
#include <__ranges/access.h>
|
||||
#include <__ranges/concepts.h>
|
||||
#include <__ranges/dangling.h>
|
||||
#include <__utility/forward.h>
|
||||
#include <__utility/move.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
namespace ranges {
|
||||
namespace __find_if_not {
|
||||
struct __fn {
|
||||
template <input_iterator _Ip, sentinel_for<_Ip> _Sp, class _Proj = identity,
|
||||
indirect_unary_predicate<projected<_Ip, _Proj>> _Pred>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
_Ip operator()(_Ip __first, _Sp __last, _Pred __pred, _Proj __proj = {}) const {
|
||||
auto __pred2 = [&](auto&& __e) { return !std::invoke(__pred, std::forward<decltype(__e)>(__e)); };
|
||||
return ranges::__find_if_impl(std::move(__first), std::move(__last), __pred2, __proj);
|
||||
}
|
||||
|
||||
template <input_range _Rp, class _Proj = identity,
|
||||
indirect_unary_predicate<projected<iterator_t<_Rp>, _Proj>> _Pred>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
borrowed_iterator_t<_Rp> operator()(_Rp&& __r, _Pred __pred, _Proj __proj = {}) const {
|
||||
auto __pred2 = [&](auto&& __e) { return !std::invoke(__pred, std::forward<decltype(__e)>(__e)); };
|
||||
return ranges::__find_if_impl(ranges::begin(__r), ranges::end(__r), __pred2, __proj);
|
||||
}
|
||||
};
|
||||
} // namespace __find_if_not
|
||||
|
||||
inline namespace __cpo {
|
||||
inline constexpr auto find_if_not = __find_if_not::__fn{};
|
||||
} // namespace __cpo
|
||||
} // namespace ranges
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_RANGES_FIND_IF_NOT_H
|
||||
78
lib/libcxx/include/__algorithm/ranges_for_each.h
vendored
Normal file
78
lib/libcxx/include/__algorithm/ranges_for_each.h
vendored
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_RANGES_FOR_EACH_H
|
||||
#define _LIBCPP___ALGORITHM_RANGES_FOR_EACH_H
|
||||
|
||||
#include <__algorithm/in_fun_result.h>
|
||||
#include <__config>
|
||||
#include <__functional/identity.h>
|
||||
#include <__functional/invoke.h>
|
||||
#include <__iterator/concepts.h>
|
||||
#include <__iterator/projected.h>
|
||||
#include <__ranges/access.h>
|
||||
#include <__ranges/concepts.h>
|
||||
#include <__ranges/dangling.h>
|
||||
#include <__utility/move.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
namespace ranges {
|
||||
|
||||
template <class _Iter, class _Func>
|
||||
using for_each_result = in_fun_result<_Iter, _Func>;
|
||||
|
||||
namespace __for_each {
|
||||
struct __fn {
|
||||
private:
|
||||
template <class _Iter, class _Sent, class _Proj, class _Func>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr static
|
||||
for_each_result<_Iter, _Func> __for_each_impl(_Iter __first, _Sent __last, _Func& __func, _Proj& __proj) {
|
||||
for (; __first != __last; ++__first)
|
||||
std::invoke(__func, std::invoke(__proj, *__first));
|
||||
return {std::move(__first), std::move(__func)};
|
||||
}
|
||||
|
||||
public:
|
||||
template <input_iterator _Iter, sentinel_for<_Iter> _Sent,
|
||||
class _Proj = identity,
|
||||
indirectly_unary_invocable<projected<_Iter, _Proj>> _Func>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
for_each_result<_Iter, _Func> operator()(_Iter __first, _Sent __last, _Func __func, _Proj __proj = {}) const {
|
||||
return __for_each_impl(std::move(__first), std::move(__last), __func, __proj);
|
||||
}
|
||||
|
||||
template <input_range _Range,
|
||||
class _Proj = identity,
|
||||
indirectly_unary_invocable<projected<iterator_t<_Range>, _Proj>> _Func>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
for_each_result<borrowed_iterator_t<_Range>, _Func> operator()(_Range&& __range,
|
||||
_Func __func,
|
||||
_Proj __proj = {}) const {
|
||||
return __for_each_impl(ranges::begin(__range), ranges::end(__range), __func, __proj);
|
||||
}
|
||||
|
||||
};
|
||||
} // namespace __for_each
|
||||
|
||||
inline namespace __cpo {
|
||||
inline constexpr auto for_each = __for_each::__fn{};
|
||||
} // namespace __cpo
|
||||
} // namespace ranges
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_RANGES_FOR_EACH_H
|
||||
66
lib/libcxx/include/__algorithm/ranges_for_each_n.h
vendored
Normal file
66
lib/libcxx/include/__algorithm/ranges_for_each_n.h
vendored
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_RANGES_FOR_EACH_N_H
|
||||
#define _LIBCPP___ALGORITHM_RANGES_FOR_EACH_N_H
|
||||
|
||||
#include <__algorithm/in_fun_result.h>
|
||||
#include <__config>
|
||||
#include <__functional/identity.h>
|
||||
#include <__functional/invoke.h>
|
||||
#include <__iterator/concepts.h>
|
||||
#include <__iterator/incrementable_traits.h>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__iterator/projected.h>
|
||||
#include <__ranges/concepts.h>
|
||||
#include <__utility/move.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
namespace ranges {
|
||||
|
||||
template <class _Iter, class _Func>
|
||||
using for_each_n_result = in_fun_result<_Iter, _Func>;
|
||||
|
||||
namespace __for_each_n {
|
||||
struct __fn {
|
||||
|
||||
template <input_iterator _Iter,
|
||||
class _Proj = identity,
|
||||
indirectly_unary_invocable<projected<_Iter, _Proj>> _Func>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
for_each_n_result<_Iter, _Func> operator()(_Iter __first,
|
||||
iter_difference_t<_Iter> __count,
|
||||
_Func __func,
|
||||
_Proj __proj = {}) const {
|
||||
while (__count-- > 0) {
|
||||
std::invoke(__func, std::invoke(__proj, *__first));
|
||||
++__first;
|
||||
}
|
||||
return {std::move(__first), std::move(__func)};
|
||||
}
|
||||
|
||||
};
|
||||
} // namespace __for_each_n
|
||||
|
||||
inline namespace __cpo {
|
||||
inline constexpr auto for_each_n = __for_each_n::__fn{};
|
||||
} // namespace __cpo
|
||||
} // namespace ranges
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_RANGES_FOR_EACH_N_H
|
||||
73
lib/libcxx/include/__algorithm/ranges_generate.h
vendored
Normal file
73
lib/libcxx/include/__algorithm/ranges_generate.h
vendored
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_RANGES_GENERATE_H
|
||||
#define _LIBCPP___ALGORITHM_RANGES_GENERATE_H
|
||||
|
||||
#include <__concepts/constructible.h>
|
||||
#include <__concepts/invocable.h>
|
||||
#include <__config>
|
||||
#include <__functional/invoke.h>
|
||||
#include <__iterator/concepts.h>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__ranges/access.h>
|
||||
#include <__ranges/concepts.h>
|
||||
#include <__ranges/dangling.h>
|
||||
#include <__utility/move.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
namespace ranges {
|
||||
namespace __generate {
|
||||
|
||||
struct __fn {
|
||||
|
||||
template <class _OutIter, class _Sent, class _Func>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
static _OutIter __generate_fn_impl(_OutIter __first, _Sent __last, _Func& __gen) {
|
||||
for (; __first != __last; ++__first) {
|
||||
*__first = __gen();
|
||||
}
|
||||
|
||||
return __first;
|
||||
}
|
||||
|
||||
template <input_or_output_iterator _OutIter, sentinel_for<_OutIter> _Sent, copy_constructible _Func>
|
||||
requires invocable<_Func&> && indirectly_writable<_OutIter, invoke_result_t<_Func&>>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
_OutIter operator()(_OutIter __first, _Sent __last, _Func __gen) const {
|
||||
return __generate_fn_impl(std::move(__first), std::move(__last), __gen);
|
||||
}
|
||||
|
||||
template <class _Range, copy_constructible _Func>
|
||||
requires invocable<_Func&> && output_range<_Range, invoke_result_t<_Func&>>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
borrowed_iterator_t<_Range> operator()(_Range&& __range, _Func __gen) const {
|
||||
return __generate_fn_impl(ranges::begin(__range), ranges::end(__range), __gen);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} // namespace __generate
|
||||
|
||||
inline namespace __cpo {
|
||||
inline constexpr auto generate = __generate::__fn{};
|
||||
} // namespace __cpo
|
||||
} // namespace ranges
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_RANGES_GENERATE_H
|
||||
62
lib/libcxx/include/__algorithm/ranges_generate_n.h
vendored
Normal file
62
lib/libcxx/include/__algorithm/ranges_generate_n.h
vendored
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_RANGES_GENERATE_N_H
|
||||
#define _LIBCPP___ALGORITHM_RANGES_GENERATE_N_H
|
||||
|
||||
#include <__concepts/constructible.h>
|
||||
#include <__concepts/invocable.h>
|
||||
#include <__config>
|
||||
#include <__functional/identity.h>
|
||||
#include <__functional/invoke.h>
|
||||
#include <__iterator/concepts.h>
|
||||
#include <__iterator/incrementable_traits.h>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__ranges/access.h>
|
||||
#include <__ranges/concepts.h>
|
||||
#include <__utility/move.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
namespace ranges {
|
||||
namespace __generate_n {
|
||||
|
||||
struct __fn {
|
||||
|
||||
template <input_or_output_iterator _OutIter, copy_constructible _Func>
|
||||
requires invocable<_Func&> && indirectly_writable<_OutIter, invoke_result_t<_Func&>>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
_OutIter operator()(_OutIter __first, iter_difference_t<_OutIter> __n, _Func __gen) const {
|
||||
for (; __n > 0; --__n) {
|
||||
*__first = __gen();
|
||||
++__first;
|
||||
}
|
||||
|
||||
return __first;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} // namespace __generate_n
|
||||
|
||||
inline namespace __cpo {
|
||||
inline constexpr auto generate_n = __generate_n::__fn{};
|
||||
} // namespace __cpo
|
||||
} // namespace ranges
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_RANGES_GENERATE_N_H
|
||||
95
lib/libcxx/include/__algorithm/ranges_includes.h
vendored
Normal file
95
lib/libcxx/include/__algorithm/ranges_includes.h
vendored
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_RANGES_INCLUDES_H
|
||||
#define _LIBCPP___ALGORITHM_RANGES_INCLUDES_H
|
||||
|
||||
#include <__algorithm/includes.h>
|
||||
#include <__algorithm/make_projected.h>
|
||||
#include <__config>
|
||||
#include <__functional/identity.h>
|
||||
#include <__functional/invoke.h>
|
||||
#include <__functional/ranges_operations.h>
|
||||
#include <__iterator/concepts.h>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__iterator/projected.h>
|
||||
#include <__ranges/access.h>
|
||||
#include <__ranges/concepts.h>
|
||||
#include <__utility/forward.h>
|
||||
#include <__utility/move.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
namespace ranges {
|
||||
namespace __includes {
|
||||
|
||||
struct __fn {
|
||||
template <
|
||||
input_iterator _Iter1,
|
||||
sentinel_for<_Iter1> _Sent1,
|
||||
input_iterator _Iter2,
|
||||
sentinel_for<_Iter2> _Sent2,
|
||||
class _Proj1 = identity,
|
||||
class _Proj2 = identity,
|
||||
indirect_strict_weak_order<projected<_Iter1, _Proj1>, projected<_Iter2, _Proj2>> _Comp = ranges::less>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr bool operator()(
|
||||
_Iter1 __first1,
|
||||
_Sent1 __last1,
|
||||
_Iter2 __first2,
|
||||
_Sent2 __last2,
|
||||
_Comp __comp = {},
|
||||
_Proj1 __proj1 = {},
|
||||
_Proj2 __proj2 = {}) const {
|
||||
return std::__includes(
|
||||
std::move(__first1),
|
||||
std::move(__last1),
|
||||
std::move(__first2),
|
||||
std::move(__last2),
|
||||
std::move(__comp),
|
||||
std::move(__proj1),
|
||||
std::move(__proj2));
|
||||
}
|
||||
|
||||
template <
|
||||
input_range _Range1,
|
||||
input_range _Range2,
|
||||
class _Proj1 = identity,
|
||||
class _Proj2 = identity,
|
||||
indirect_strict_weak_order<projected<iterator_t<_Range1>, _Proj1>, projected<iterator_t<_Range2>, _Proj2>>
|
||||
_Comp = ranges::less>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr bool operator()(
|
||||
_Range1&& __range1, _Range2&& __range2, _Comp __comp = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const {
|
||||
return std::__includes(
|
||||
ranges::begin(__range1),
|
||||
ranges::end(__range1),
|
||||
ranges::begin(__range2),
|
||||
ranges::end(__range2),
|
||||
std::move(__comp),
|
||||
std::move(__proj1),
|
||||
std::move(__proj2));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace __includes
|
||||
|
||||
inline namespace __cpo {
|
||||
inline constexpr auto includes = __includes::__fn{};
|
||||
} // namespace __cpo
|
||||
} // namespace ranges
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_RANGES_INCLUDES_H
|
||||
85
lib/libcxx/include/__algorithm/ranges_inplace_merge.h
vendored
Normal file
85
lib/libcxx/include/__algorithm/ranges_inplace_merge.h
vendored
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_RANGES_INPLACE_MERGE_H
|
||||
#define _LIBCPP___ALGORITHM_RANGES_INPLACE_MERGE_H
|
||||
|
||||
#include <__algorithm/inplace_merge.h>
|
||||
#include <__algorithm/iterator_operations.h>
|
||||
#include <__algorithm/make_projected.h>
|
||||
#include <__config>
|
||||
#include <__functional/identity.h>
|
||||
#include <__functional/invoke.h>
|
||||
#include <__functional/ranges_operations.h>
|
||||
#include <__iterator/concepts.h>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__iterator/next.h>
|
||||
#include <__iterator/projected.h>
|
||||
#include <__iterator/sortable.h>
|
||||
#include <__ranges/access.h>
|
||||
#include <__ranges/concepts.h>
|
||||
#include <__ranges/dangling.h>
|
||||
#include <__utility/forward.h>
|
||||
#include <__utility/move.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
namespace ranges {
|
||||
namespace __inplace_merge {
|
||||
|
||||
struct __fn {
|
||||
template <class _Iter, class _Sent, class _Comp, class _Proj>
|
||||
_LIBCPP_HIDE_FROM_ABI static constexpr auto
|
||||
__inplace_merge_impl(_Iter __first, _Iter __middle, _Sent __last, _Comp&& __comp, _Proj&& __proj) {
|
||||
auto __last_iter = ranges::next(__middle, __last);
|
||||
std::__inplace_merge<_RangeAlgPolicy>(
|
||||
std::move(__first), std::move(__middle), __last_iter, std::__make_projected(__comp, __proj));
|
||||
return __last_iter;
|
||||
}
|
||||
|
||||
template <
|
||||
bidirectional_iterator _Iter,
|
||||
sentinel_for<_Iter> _Sent,
|
||||
class _Comp = ranges::less,
|
||||
class _Proj = identity>
|
||||
requires sortable<_Iter, _Comp, _Proj>
|
||||
_LIBCPP_HIDE_FROM_ABI _Iter
|
||||
operator()(_Iter __first, _Iter __middle, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const {
|
||||
return __inplace_merge_impl(
|
||||
std::move(__first), std::move(__middle), std::move(__last), std::move(__comp), std::move(__proj));
|
||||
}
|
||||
|
||||
template <bidirectional_range _Range, class _Comp = ranges::less, class _Proj = identity>
|
||||
requires sortable<
|
||||
iterator_t<_Range>,
|
||||
_Comp,
|
||||
_Proj> _LIBCPP_HIDE_FROM_ABI borrowed_iterator_t<_Range>
|
||||
operator()(_Range&& __range, iterator_t<_Range> __middle, _Comp __comp = {}, _Proj __proj = {}) const {
|
||||
return __inplace_merge_impl(
|
||||
ranges::begin(__range), std::move(__middle), ranges::end(__range), std::move(__comp), std::move(__proj));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace __inplace_merge
|
||||
|
||||
inline namespace __cpo {
|
||||
inline constexpr auto inplace_merge = __inplace_merge::__fn{};
|
||||
} // namespace __cpo
|
||||
} // namespace ranges
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_RANGES_INPLACE_MERGE_H
|
||||
74
lib/libcxx/include/__algorithm/ranges_is_heap.h
vendored
Normal file
74
lib/libcxx/include/__algorithm/ranges_is_heap.h
vendored
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_RANGES_IS_HEAP_H
|
||||
#define _LIBCPP___ALGORITHM_RANGES_IS_HEAP_H
|
||||
|
||||
#include <__algorithm/is_heap_until.h>
|
||||
#include <__algorithm/make_projected.h>
|
||||
#include <__config>
|
||||
#include <__functional/identity.h>
|
||||
#include <__functional/ranges_operations.h>
|
||||
#include <__iterator/concepts.h>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__iterator/next.h>
|
||||
#include <__iterator/projected.h>
|
||||
#include <__ranges/access.h>
|
||||
#include <__ranges/concepts.h>
|
||||
#include <__utility/move.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
namespace ranges {
|
||||
namespace __is_heap {
|
||||
|
||||
struct __fn {
|
||||
|
||||
template <class _Iter, class _Sent, class _Proj, class _Comp>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
static bool __is_heap_fn_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) {
|
||||
auto __last_iter = ranges::next(__first, __last);
|
||||
auto&& __projected_comp = std::__make_projected(__comp, __proj);
|
||||
|
||||
auto __result = std::__is_heap_until(std::move(__first), std::move(__last_iter), __projected_comp);
|
||||
return __result == __last;
|
||||
}
|
||||
|
||||
template <random_access_iterator _Iter, sentinel_for<_Iter> _Sent, class _Proj = identity,
|
||||
indirect_strict_weak_order<projected<_Iter, _Proj>> _Comp = ranges::less>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
bool operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const {
|
||||
return __is_heap_fn_impl(std::move(__first), std::move(__last), __comp, __proj);
|
||||
}
|
||||
|
||||
template <random_access_range _Range, class _Proj = identity,
|
||||
indirect_strict_weak_order<projected<iterator_t<_Range>, _Proj>> _Comp = ranges::less>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
bool operator()(_Range&& __range, _Comp __comp = {}, _Proj __proj = {}) const {
|
||||
return __is_heap_fn_impl(ranges::begin(__range), ranges::end(__range), __comp, __proj);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace __is_heap
|
||||
|
||||
inline namespace __cpo {
|
||||
inline constexpr auto is_heap = __is_heap::__fn{};
|
||||
} // namespace __cpo
|
||||
} // namespace ranges
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_RANGES_IS_HEAP_H
|
||||
75
lib/libcxx/include/__algorithm/ranges_is_heap_until.h
vendored
Normal file
75
lib/libcxx/include/__algorithm/ranges_is_heap_until.h
vendored
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_RANGES_IS_HEAP_UNTIL_H
|
||||
#define _LIBCPP___ALGORITHM_RANGES_IS_HEAP_UNTIL_H
|
||||
|
||||
#include <__algorithm/is_heap_until.h>
|
||||
#include <__algorithm/make_projected.h>
|
||||
#include <__config>
|
||||
#include <__functional/identity.h>
|
||||
#include <__functional/ranges_operations.h>
|
||||
#include <__iterator/concepts.h>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__iterator/next.h>
|
||||
#include <__iterator/projected.h>
|
||||
#include <__ranges/access.h>
|
||||
#include <__ranges/concepts.h>
|
||||
#include <__ranges/dangling.h>
|
||||
#include <__utility/move.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
namespace ranges {
|
||||
namespace __is_heap_until {
|
||||
|
||||
struct __fn {
|
||||
|
||||
template <class _Iter, class _Sent, class _Proj, class _Comp>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
static _Iter __is_heap_until_fn_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) {
|
||||
auto __last_iter = ranges::next(__first, __last);
|
||||
auto&& __projected_comp = std::__make_projected(__comp, __proj);
|
||||
|
||||
return std::__is_heap_until(std::move(__first), std::move(__last_iter), __projected_comp);
|
||||
}
|
||||
|
||||
template <random_access_iterator _Iter, sentinel_for<_Iter> _Sent, class _Proj = identity,
|
||||
indirect_strict_weak_order<projected<_Iter, _Proj>> _Comp = ranges::less>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
_Iter operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const {
|
||||
return __is_heap_until_fn_impl(std::move(__first), std::move(__last), __comp, __proj);
|
||||
}
|
||||
|
||||
template <random_access_range _Range, class _Proj = identity,
|
||||
indirect_strict_weak_order<projected<iterator_t<_Range>, _Proj>> _Comp = ranges::less>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
borrowed_iterator_t<_Range> operator()(_Range&& __range, _Comp __comp = {}, _Proj __proj = {}) const {
|
||||
return __is_heap_until_fn_impl(ranges::begin(__range), ranges::end(__range), __comp, __proj);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} // namespace __is_heap_until
|
||||
|
||||
inline namespace __cpo {
|
||||
inline constexpr auto is_heap_until = __is_heap_until::__fn{};
|
||||
} // namespace __cpo
|
||||
} // namespace ranges
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_RANGES_IS_HEAP_UNTIL_H
|
||||
81
lib/libcxx/include/__algorithm/ranges_is_partitioned.h
vendored
Normal file
81
lib/libcxx/include/__algorithm/ranges_is_partitioned.h
vendored
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_RANGES_IS_PARTITIONED_H
|
||||
#define _LIBCPP___ALGORITHM_RANGES_IS_PARTITIONED_H
|
||||
|
||||
#include <__config>
|
||||
#include <__functional/identity.h>
|
||||
#include <__functional/invoke.h>
|
||||
#include <__iterator/concepts.h>
|
||||
#include <__iterator/indirectly_comparable.h>
|
||||
#include <__iterator/projected.h>
|
||||
#include <__ranges/access.h>
|
||||
#include <__ranges/concepts.h>
|
||||
#include <__utility/move.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
namespace ranges {
|
||||
namespace __is_partitioned {
|
||||
struct __fn {
|
||||
|
||||
template <class _Iter, class _Sent, class _Proj, class _Pred>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr static
|
||||
bool __is_parititioned_impl(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
|
||||
for (; __first != __last; ++__first) {
|
||||
if (!std::invoke(__pred, std::invoke(__proj, *__first)))
|
||||
break;
|
||||
}
|
||||
|
||||
if (__first == __last)
|
||||
return true;
|
||||
++__first;
|
||||
|
||||
for (; __first != __last; ++__first) {
|
||||
if (std::invoke(__pred, std::invoke(__proj, *__first)))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template <input_iterator _Iter, sentinel_for<_Iter> _Sent,
|
||||
class _Proj = identity,
|
||||
indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
bool operator()(_Iter __first, _Sent __last, _Pred __pred, _Proj __proj = {}) const {
|
||||
return __is_parititioned_impl(std::move(__first), std::move(__last), __pred, __proj);
|
||||
}
|
||||
|
||||
template <input_range _Range,
|
||||
class _Proj = identity,
|
||||
indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>> _Pred>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
bool operator()(_Range&& __range, _Pred __pred, _Proj __proj = {}) const {
|
||||
return __is_parititioned_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj);
|
||||
}
|
||||
};
|
||||
} // namespace __is_partitioned
|
||||
|
||||
inline namespace __cpo {
|
||||
inline constexpr auto is_partitioned = __is_partitioned::__fn{};
|
||||
} // namespace __cpo
|
||||
} // namespace ranges
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_RANGES_IS_PARTITIONED_H
|
||||
61
lib/libcxx/include/__algorithm/ranges_is_sorted.h
vendored
Normal file
61
lib/libcxx/include/__algorithm/ranges_is_sorted.h
vendored
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP__ALGORITHM_RANGES_IS_SORTED_H
|
||||
#define _LIBCPP__ALGORITHM_RANGES_IS_SORTED_H
|
||||
|
||||
#include <__algorithm/ranges_is_sorted_until.h>
|
||||
#include <__config>
|
||||
#include <__functional/identity.h>
|
||||
#include <__functional/ranges_operations.h>
|
||||
#include <__iterator/concepts.h>
|
||||
#include <__iterator/projected.h>
|
||||
#include <__ranges/access.h>
|
||||
#include <__ranges/concepts.h>
|
||||
#include <__utility/move.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
namespace ranges {
|
||||
namespace __is_sorted {
|
||||
struct __fn {
|
||||
template <forward_iterator _Iter, sentinel_for<_Iter> _Sent,
|
||||
class _Proj = identity,
|
||||
indirect_strict_weak_order<projected<_Iter, _Proj>> _Comp = ranges::less>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
bool operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const {
|
||||
return ranges::__is_sorted_until_impl(std::move(__first), __last, __comp, __proj) == __last;
|
||||
}
|
||||
|
||||
template <forward_range _Range,
|
||||
class _Proj = identity,
|
||||
indirect_strict_weak_order<projected<iterator_t<_Range>, _Proj>> _Comp = ranges::less>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
bool operator()(_Range&& __range, _Comp __comp = {}, _Proj __proj = {}) const {
|
||||
auto __last = ranges::end(__range);
|
||||
return ranges::__is_sorted_until_impl(ranges::begin(__range), __last, __comp, __proj) == __last;
|
||||
}
|
||||
};
|
||||
} // namespace __is_sorted
|
||||
|
||||
inline namespace __cpo {
|
||||
inline constexpr auto is_sorted = __is_sorted::__fn{};
|
||||
} // namespace __cpo
|
||||
} // namespace ranges
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
#endif // _LIBCPP__ALGORITHM_RANGES_IS_SORTED_H
|
||||
76
lib/libcxx/include/__algorithm/ranges_is_sorted_until.h
vendored
Normal file
76
lib/libcxx/include/__algorithm/ranges_is_sorted_until.h
vendored
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP__ALGORITHM_RANGES_IS_SORTED_UNTIL_H
|
||||
#define _LIBCPP__ALGORITHM_RANGES_IS_SORTED_UNTIL_H
|
||||
|
||||
#include <__config>
|
||||
#include <__functional/identity.h>
|
||||
#include <__functional/invoke.h>
|
||||
#include <__functional/ranges_operations.h>
|
||||
#include <__iterator/concepts.h>
|
||||
#include <__iterator/projected.h>
|
||||
#include <__ranges/access.h>
|
||||
#include <__ranges/concepts.h>
|
||||
#include <__ranges/dangling.h>
|
||||
#include <__utility/move.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
namespace ranges {
|
||||
|
||||
template <class _Iter, class _Sent, class _Proj, class _Comp>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
_Iter __is_sorted_until_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) {
|
||||
if (__first == __last)
|
||||
return __first;
|
||||
auto __i = __first;
|
||||
while (++__i != __last) {
|
||||
if (std::invoke(__comp, std::invoke(__proj, *__i), std::invoke(__proj, *__first)))
|
||||
return __i;
|
||||
__first = __i;
|
||||
}
|
||||
return __i;
|
||||
}
|
||||
|
||||
namespace __is_sorted_until {
|
||||
struct __fn {
|
||||
template <forward_iterator _Iter, sentinel_for<_Iter> _Sent,
|
||||
class _Proj = identity,
|
||||
indirect_strict_weak_order<projected<_Iter, _Proj>> _Comp = ranges::less>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
_Iter operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const {
|
||||
return ranges::__is_sorted_until_impl(std::move(__first), std::move(__last), __comp, __proj);
|
||||
}
|
||||
|
||||
template <forward_range _Range,
|
||||
class _Proj = identity,
|
||||
indirect_strict_weak_order<projected<iterator_t<_Range>, _Proj>> _Comp = ranges::less>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
borrowed_iterator_t<_Range> operator()(_Range&& __range, _Comp __comp = {}, _Proj __proj = {}) const {
|
||||
return ranges::__is_sorted_until_impl(ranges::begin(__range), ranges::end(__range), __comp, __proj);
|
||||
}
|
||||
};
|
||||
} // namespace __is_sorted_until
|
||||
|
||||
inline namespace __cpo {
|
||||
inline constexpr auto is_sorted_until = __is_sorted_until::__fn{};
|
||||
} // namespace __cpo
|
||||
} // namespace ranges
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
||||
|
||||
#endif // _LIBCPP__ALGORITHM_RANGES_IS_SORTED_UNTIL_H
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue