mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-31 17:52:27 +00:00
Release Cosmopolitan v3.6.0
This release is an atomic upgrade to GCC 14.1.0 with C23 and C++23
This commit is contained in:
parent
62ace3623a
commit
5660ec4741
1585 changed files with 117353 additions and 271644 deletions
11
third_party/libcxx/__algorithm/adjacent_find.h
vendored
11
third_party/libcxx/__algorithm/adjacent_find.h
vendored
|
@ -20,10 +20,13 @@
|
|||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_PUSH_MACROS
|
||||
#include <__undef_macros>
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _Iter, class _Sent, class _BinaryPredicate>
|
||||
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter
|
||||
_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter
|
||||
__adjacent_find(_Iter __first, _Sent __last, _BinaryPredicate&& __pred) {
|
||||
if (__first == __last)
|
||||
return __first;
|
||||
|
@ -37,17 +40,19 @@ __adjacent_find(_Iter __first, _Sent __last, _BinaryPredicate&& __pred) {
|
|||
}
|
||||
|
||||
template <class _ForwardIterator, class _BinaryPredicate>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _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_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
|
||||
adjacent_find(_ForwardIterator __first, _ForwardIterator __last) {
|
||||
return std::adjacent_find(std::move(__first), std::move(__last), __equal_to());
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_ADJACENT_FIND_H
|
||||
|
|
2
third_party/libcxx/__algorithm/all_of.h
vendored
2
third_party/libcxx/__algorithm/all_of.h
vendored
|
@ -19,7 +19,7 @@
|
|||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _InputIterator, class _Predicate>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
|
||||
all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
|
||||
for (; __first != __last; ++__first)
|
||||
if (!__pred(*__first))
|
||||
|
|
2
third_party/libcxx/__algorithm/any_of.h
vendored
2
third_party/libcxx/__algorithm/any_of.h
vendored
|
@ -19,7 +19,7 @@
|
|||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _InputIterator, class _Predicate>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
|
||||
any_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
|
||||
for (; __first != __last; ++__first)
|
||||
if (__pred(*__first))
|
||||
|
|
21
third_party/libcxx/__algorithm/binary_search.h
vendored
21
third_party/libcxx/__algorithm/binary_search.h
vendored
|
@ -22,23 +22,16 @@
|
|||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _ForwardIterator, class _Tp, class _Compare>
|
||||
_LIBCPP_NODISCARD_EXT inline
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
bool
|
||||
binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp)
|
||||
{
|
||||
__first = std::lower_bound<_ForwardIterator, _Tp, __comp_ref_type<_Compare> >(__first, __last, __value, __comp);
|
||||
return __first != __last && !__comp(__value, *__first);
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
|
||||
binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) {
|
||||
__first = std::lower_bound<_ForwardIterator, _Tp, __comp_ref_type<_Compare> >(__first, __last, __value, __comp);
|
||||
return __first != __last && !__comp(__value, *__first);
|
||||
}
|
||||
|
||||
template <class _ForwardIterator, class _Tp>
|
||||
_LIBCPP_NODISCARD_EXT inline
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
bool
|
||||
binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
|
||||
{
|
||||
return std::binary_search(__first, __last, __value,
|
||||
__less<typename iterator_traits<_ForwardIterator>::value_type, _Tp>());
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
|
||||
binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
|
||||
return std::binary_search(__first, __last, __value, __less<>());
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
|
30
third_party/libcxx/__algorithm/clamp.h
vendored
30
third_party/libcxx/__algorithm/clamp.h
vendored
|
@ -20,24 +20,22 @@
|
|||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
#if _LIBCPP_STD_VER >= 17
|
||||
template<class _Tp, class _Compare>
|
||||
_LIBCPP_NODISCARD_EXT inline
|
||||
_LIBCPP_INLINE_VISIBILITY constexpr
|
||||
const _Tp&
|
||||
clamp(const _Tp& __v, const _Tp& __lo, const _Tp& __hi, _Compare __comp)
|
||||
{
|
||||
_LIBCPP_ASSERT(!__comp(__hi, __lo), "Bad bounds passed to std::clamp");
|
||||
return __comp(__v, __lo) ? __lo : __comp(__hi, __v) ? __hi : __v;
|
||||
|
||||
template <class _Tp, class _Compare>
|
||||
[[nodiscard]] inline _LIBCPP_HIDE_FROM_ABI constexpr const _Tp&
|
||||
clamp(_LIBCPP_LIFETIMEBOUND const _Tp& __v,
|
||||
_LIBCPP_LIFETIMEBOUND const _Tp& __lo,
|
||||
_LIBCPP_LIFETIMEBOUND const _Tp& __hi,
|
||||
_Compare __comp) {
|
||||
_LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(!__comp(__hi, __lo), "Bad bounds passed to std::clamp");
|
||||
return __comp(__v, __lo) ? __lo : __comp(__hi, __v) ? __hi : __v;
|
||||
}
|
||||
|
||||
template<class _Tp>
|
||||
_LIBCPP_NODISCARD_EXT inline
|
||||
_LIBCPP_INLINE_VISIBILITY constexpr
|
||||
const _Tp&
|
||||
clamp(const _Tp& __v, const _Tp& __lo, const _Tp& __hi)
|
||||
{
|
||||
return _VSTD::clamp(__v, __lo, __hi, __less<_Tp>());
|
||||
template <class _Tp>
|
||||
[[nodiscard]] inline _LIBCPP_HIDE_FROM_ABI constexpr const _Tp&
|
||||
clamp(_LIBCPP_LIFETIMEBOUND const _Tp& __v,
|
||||
_LIBCPP_LIFETIMEBOUND const _Tp& __lo,
|
||||
_LIBCPP_LIFETIMEBOUND const _Tp& __hi) {
|
||||
return std::clamp(__v, __lo, __hi, __less<>());
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
52
third_party/libcxx/__algorithm/comp.h
vendored
52
third_party/libcxx/__algorithm/comp.h
vendored
|
@ -10,8 +10,7 @@
|
|||
#define _LIBCPP___ALGORITHM_COMP_H
|
||||
|
||||
#include <__config>
|
||||
#include <__type_traits/integral_constant.h>
|
||||
#include <__type_traits/predicate_traits.h>
|
||||
#include <__type_traits/desugars_to.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
|
@ -26,45 +25,24 @@ struct __equal_to {
|
|||
}
|
||||
};
|
||||
|
||||
template <class _Lhs, class _Rhs>
|
||||
struct __is_trivial_equality_predicate<__equal_to, _Lhs, _Rhs> : true_type {};
|
||||
template <class _Tp, class _Up>
|
||||
inline const bool __desugars_to_v<__equal_tag, __equal_to, _Tp, _Up> = true;
|
||||
|
||||
template <class _T1, class _T2 = _T1>
|
||||
struct __less
|
||||
{
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
|
||||
bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;}
|
||||
// The definition is required because __less is part of the ABI, but it's empty
|
||||
// because all comparisons should be transparent.
|
||||
template <class _T1 = void, class _T2 = _T1>
|
||||
struct __less {};
|
||||
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
|
||||
bool operator()(const _T1& __x, const _T2& __y) const {return __x < __y;}
|
||||
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
|
||||
bool operator()(const _T2& __x, const _T1& __y) const {return __x < __y;}
|
||||
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
|
||||
bool operator()(const _T2& __x, const _T2& __y) const {return __x < __y;}
|
||||
template <>
|
||||
struct __less<void, void> {
|
||||
template <class _Tp, class _Up>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator()(const _Tp& __lhs, const _Up& __rhs) const {
|
||||
return __lhs < __rhs;
|
||||
}
|
||||
};
|
||||
|
||||
template <class _T1>
|
||||
struct __less<_T1, _T1>
|
||||
{
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
|
||||
bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;}
|
||||
};
|
||||
|
||||
template <class _T1>
|
||||
struct __less<const _T1, _T1>
|
||||
{
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
|
||||
bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;}
|
||||
};
|
||||
|
||||
template <class _T1>
|
||||
struct __less<_T1, const _T1>
|
||||
{
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
|
||||
bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;}
|
||||
};
|
||||
template <class _Tp>
|
||||
inline const bool __desugars_to_v<__less_tag, __less<>, _Tp, _Tp> = true;
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
|
|
71
third_party/libcxx/__algorithm/comp_ref_type.h
vendored
71
third_party/libcxx/__algorithm/comp_ref_type.h
vendored
|
@ -9,8 +9,8 @@
|
|||
#ifndef _LIBCPP___ALGORITHM_COMP_REF_TYPE_H
|
||||
#define _LIBCPP___ALGORITHM_COMP_REF_TYPE_H
|
||||
|
||||
#include <__assert>
|
||||
#include <__config>
|
||||
#include <__debug>
|
||||
#include <__utility/declval.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
|
@ -20,52 +20,41 @@
|
|||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _Compare>
|
||||
struct __debug_less
|
||||
{
|
||||
_Compare &__comp_;
|
||||
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI __debug_less(_Compare& __c) : __comp_(__c) {}
|
||||
struct __debug_less {
|
||||
_Compare& __comp_;
|
||||
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI __debug_less(_Compare& __c) : __comp_(__c) {}
|
||||
|
||||
template <class _Tp, class _Up>
|
||||
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
|
||||
bool operator()(const _Tp& __x, const _Up& __y)
|
||||
{
|
||||
bool __r = __comp_(__x, __y);
|
||||
if (__r)
|
||||
__do_compare_assert(0, __y, __x);
|
||||
return __r;
|
||||
}
|
||||
template <class _Tp, class _Up>
|
||||
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Up& __y) {
|
||||
bool __r = __comp_(__x, __y);
|
||||
if (__r)
|
||||
__do_compare_assert(0, __y, __x);
|
||||
return __r;
|
||||
}
|
||||
|
||||
template <class _Tp, class _Up>
|
||||
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
|
||||
bool operator()(_Tp& __x, _Up& __y)
|
||||
{
|
||||
bool __r = __comp_(__x, __y);
|
||||
if (__r)
|
||||
__do_compare_assert(0, __y, __x);
|
||||
return __r;
|
||||
}
|
||||
template <class _Tp, class _Up>
|
||||
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool operator()(_Tp& __x, _Up& __y) {
|
||||
bool __r = __comp_(__x, __y);
|
||||
if (__r)
|
||||
__do_compare_assert(0, __y, __x);
|
||||
return __r;
|
||||
}
|
||||
|
||||
template <class _LHS, class _RHS>
|
||||
_LIBCPP_CONSTEXPR_SINCE_CXX14
|
||||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
decltype((void)std::declval<_Compare&>()(
|
||||
std::declval<_LHS &>(), std::declval<_RHS &>()))
|
||||
__do_compare_assert(int, _LHS & __l, _RHS & __r) {
|
||||
_LIBCPP_DEBUG_ASSERT(!__comp_(__l, __r),
|
||||
"Comparator does not induce a strict weak ordering");
|
||||
(void)__l;
|
||||
(void)__r;
|
||||
}
|
||||
template <class _LHS, class _RHS>
|
||||
_LIBCPP_CONSTEXPR_SINCE_CXX14 inline
|
||||
_LIBCPP_HIDE_FROM_ABI decltype((void)std::declval<_Compare&>()(std::declval<_LHS&>(), std::declval<_RHS&>()))
|
||||
__do_compare_assert(int, _LHS& __l, _RHS& __r) {
|
||||
_LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(!__comp_(__l, __r), "Comparator does not induce a strict weak ordering");
|
||||
(void)__l;
|
||||
(void)__r;
|
||||
}
|
||||
|
||||
template <class _LHS, class _RHS>
|
||||
_LIBCPP_CONSTEXPR_SINCE_CXX14
|
||||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
void __do_compare_assert(long, _LHS &, _RHS &) {}
|
||||
template <class _LHS, class _RHS>
|
||||
_LIBCPP_CONSTEXPR_SINCE_CXX14 inline _LIBCPP_HIDE_FROM_ABI void __do_compare_assert(long, _LHS&, _RHS&) {}
|
||||
};
|
||||
|
||||
// Pass the comparator by lvalue reference. Or in debug mode, using a
|
||||
// debugging wrapper that stores a reference.
|
||||
#ifdef _LIBCPP_ENABLE_DEBUG_MODE
|
||||
// Pass the comparator by lvalue reference. Or in the debug mode, using a debugging wrapper that stores a reference.
|
||||
#if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG
|
||||
template <class _Comp>
|
||||
using __comp_ref_type = __debug_less<_Comp>;
|
||||
#else
|
||||
|
|
15
third_party/libcxx/__algorithm/copy.h
vendored
15
third_party/libcxx/__algorithm/copy.h
vendored
|
@ -32,7 +32,7 @@ template <class, class _InIter, class _Sent, class _OutIter>
|
|||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> __copy(_InIter, _Sent, _OutIter);
|
||||
|
||||
template <class _AlgPolicy>
|
||||
struct __copy_loop {
|
||||
struct __copy_impl {
|
||||
template <class _InIter, class _Sent, class _OutIter>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter>
|
||||
operator()(_InIter __first, _Sent __last, _OutIter __result) const {
|
||||
|
@ -51,9 +51,10 @@ struct __copy_loop {
|
|||
|
||||
_OutIter& __result_;
|
||||
|
||||
_LIBCPP_HIDE_FROM_ABI _CopySegment(_OutIter& __result) : __result_(__result) {}
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit _CopySegment(_OutIter& __result)
|
||||
: __result_(__result) {}
|
||||
|
||||
_LIBCPP_HIDE_FROM_ABI void
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
|
||||
operator()(typename _Traits::__local_iterator __lfirst, typename _Traits::__local_iterator __llast) {
|
||||
__result_ = std::__copy<_AlgPolicy>(__lfirst, __llast, std::move(__result_)).second;
|
||||
}
|
||||
|
@ -72,7 +73,7 @@ struct __copy_loop {
|
|||
!__is_segmented_iterator<_InIter>::value && __is_segmented_iterator<_OutIter>::value,
|
||||
int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter>
|
||||
operator()(_InIter __first, _InIter __last, _OutIter __result) {
|
||||
operator()(_InIter __first, _InIter __last, _OutIter __result) const {
|
||||
using _Traits = __segmented_iterator_traits<_OutIter>;
|
||||
using _DiffT = typename common_type<__iter_diff_t<_InIter>, __iter_diff_t<_OutIter> >::type;
|
||||
|
||||
|
@ -93,9 +94,7 @@ struct __copy_loop {
|
|||
__local_first = _Traits::__begin(++__segment_iterator);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct __copy_trivial {
|
||||
// At this point, the iterators have been unwrapped so any `contiguous_iterator` has been unwrapped to a pointer.
|
||||
template <class _In, class _Out, __enable_if_t<__can_lower_copy_assignment_to_memmove<_In, _Out>::value, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_In*, _Out*>
|
||||
|
@ -107,12 +106,12 @@ struct __copy_trivial {
|
|||
template <class _AlgPolicy, class _InIter, class _Sent, class _OutIter>
|
||||
pair<_InIter, _OutIter> inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
|
||||
__copy(_InIter __first, _Sent __last, _OutIter __result) {
|
||||
return std::__dispatch_copy_or_move<_AlgPolicy, __copy_loop<_AlgPolicy>, __copy_trivial>(
|
||||
return std::__copy_move_unwrap_iters<__copy_impl<_AlgPolicy> >(
|
||||
std::move(__first), std::move(__last), std::move(__result));
|
||||
}
|
||||
|
||||
template <class _InputIterator, class _OutputIterator>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
|
||||
copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result) {
|
||||
return std::__copy<_ClassicAlgPolicy>(__first, __last, __result).second;
|
||||
}
|
||||
|
|
26
third_party/libcxx/__algorithm/copy_backward.h
vendored
26
third_party/libcxx/__algorithm/copy_backward.h
vendored
|
@ -15,7 +15,7 @@
|
|||
#include <__config>
|
||||
#include <__iterator/segmented_iterator.h>
|
||||
#include <__type_traits/common_type.h>
|
||||
#include <__type_traits/is_copy_constructible.h>
|
||||
#include <__type_traits/is_constructible.h>
|
||||
#include <__utility/move.h>
|
||||
#include <__utility/pair.h>
|
||||
|
||||
|
@ -33,7 +33,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InIter, _OutIter>
|
|||
__copy_backward(_InIter __first, _Sent __last, _OutIter __result);
|
||||
|
||||
template <class _AlgPolicy>
|
||||
struct __copy_backward_loop {
|
||||
struct __copy_backward_impl {
|
||||
template <class _InIter, class _Sent, class _OutIter>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter>
|
||||
operator()(_InIter __first, _Sent __last, _OutIter __result) const {
|
||||
|
@ -80,7 +80,7 @@ struct __copy_backward_loop {
|
|||
!__is_segmented_iterator<_InIter>::value && __is_segmented_iterator<_OutIter>::value,
|
||||
int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter>
|
||||
operator()(_InIter __first, _InIter __last, _OutIter __result) {
|
||||
operator()(_InIter __first, _InIter __last, _OutIter __result) const {
|
||||
using _Traits = __segmented_iterator_traits<_OutIter>;
|
||||
auto __orig_last = __last;
|
||||
auto __segment_iterator = _Traits::__segment(__result);
|
||||
|
@ -104,12 +104,9 @@ struct __copy_backward_loop {
|
|||
__local_last = _Traits::__end(__segment_iterator);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct __copy_backward_trivial {
|
||||
// At this point, the iterators have been unwrapped so any `contiguous_iterator` has been unwrapped to a pointer.
|
||||
template <class _In, class _Out,
|
||||
__enable_if_t<__can_lower_copy_assignment_to_memmove<_In, _Out>::value, int> = 0>
|
||||
template <class _In, class _Out, __enable_if_t<__can_lower_copy_assignment_to_memmove<_In, _Out>::value, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_In*, _Out*>
|
||||
operator()(_In* __first, _In* __last, _Out* __result) const {
|
||||
return std::__copy_backward_trivial_impl(__first, __last, __result);
|
||||
|
@ -119,21 +116,18 @@ struct __copy_backward_trivial {
|
|||
template <class _AlgPolicy, class _BidirectionalIterator1, class _Sentinel, class _BidirectionalIterator2>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_BidirectionalIterator1, _BidirectionalIterator2>
|
||||
__copy_backward(_BidirectionalIterator1 __first, _Sentinel __last, _BidirectionalIterator2 __result) {
|
||||
return std::__dispatch_copy_or_move<_AlgPolicy, __copy_backward_loop<_AlgPolicy>, __copy_backward_trivial>(
|
||||
return std::__copy_move_unwrap_iters<__copy_backward_impl<_AlgPolicy> >(
|
||||
std::move(__first), std::move(__last), std::move(__result));
|
||||
}
|
||||
|
||||
template <class _BidirectionalIterator1, class _BidirectionalIterator2>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
_BidirectionalIterator2
|
||||
copy_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last,
|
||||
_BidirectionalIterator2 __result)
|
||||
{
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _BidirectionalIterator2
|
||||
copy_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last, _BidirectionalIterator2 __result) {
|
||||
static_assert(std::is_copy_constructible<_BidirectionalIterator1>::value &&
|
||||
std::is_copy_constructible<_BidirectionalIterator1>::value, "Iterators must be copy constructible.");
|
||||
std::is_copy_constructible<_BidirectionalIterator1>::value,
|
||||
"Iterators must be copy constructible.");
|
||||
|
||||
return std::__copy_backward<_ClassicAlgPolicy>(
|
||||
std::move(__first), std::move(__last), std::move(__result)).second;
|
||||
return std::__copy_backward<_ClassicAlgPolicy>(std::move(__first), std::move(__last), std::move(__result)).second;
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
|
23
third_party/libcxx/__algorithm/copy_if.h
vendored
23
third_party/libcxx/__algorithm/copy_if.h
vendored
|
@ -17,21 +17,16 @@
|
|||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template<class _InputIterator, class _OutputIterator, class _Predicate>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
_OutputIterator
|
||||
copy_if(_InputIterator __first, _InputIterator __last,
|
||||
_OutputIterator __result, _Predicate __pred)
|
||||
{
|
||||
for (; __first != __last; ++__first)
|
||||
{
|
||||
if (__pred(*__first))
|
||||
{
|
||||
*__result = *__first;
|
||||
++__result;
|
||||
}
|
||||
template <class _InputIterator, class _OutputIterator, class _Predicate>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
|
||||
copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Predicate __pred) {
|
||||
for (; __first != __last; ++__first) {
|
||||
if (__pred(*__first)) {
|
||||
*__result = *__first;
|
||||
++__result;
|
||||
}
|
||||
return __result;
|
||||
}
|
||||
return __result;
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
|
101
third_party/libcxx/__algorithm/copy_move_common.h
vendored
101
third_party/libcxx/__algorithm/copy_move_common.h
vendored
|
@ -15,12 +15,12 @@
|
|||
#include <__config>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__memory/pointer_traits.h>
|
||||
#include <__string/constexpr_c_functions.h>
|
||||
#include <__type_traits/enable_if.h>
|
||||
#include <__type_traits/is_always_bitcastable.h>
|
||||
#include <__type_traits/is_constant_evaluated.h>
|
||||
#include <__type_traits/is_copy_constructible.h>
|
||||
#include <__type_traits/is_constructible.h>
|
||||
#include <__type_traits/is_trivially_assignable.h>
|
||||
#include <__type_traits/is_trivially_copyable.h>
|
||||
#include <__type_traits/is_volatile.h>
|
||||
#include <__utility/move.h>
|
||||
#include <__utility/pair.h>
|
||||
|
@ -30,6 +30,9 @@
|
|||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_PUSH_MACROS
|
||||
#include <__undef_macros>
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
// Type traits.
|
||||
|
@ -37,22 +40,19 @@ _LIBCPP_BEGIN_NAMESPACE_STD
|
|||
template <class _From, class _To>
|
||||
struct __can_lower_copy_assignment_to_memmove {
|
||||
static const bool value =
|
||||
// If the types are always bitcastable, it's valid to do a bitwise copy between them.
|
||||
__is_always_bitcastable<_From, _To>::value &&
|
||||
// Reject conversions that wouldn't be performed by the regular built-in assignment (e.g. between arrays).
|
||||
is_trivially_assignable<_To&, const _From&>::value &&
|
||||
// `memmove` doesn't accept `volatile` pointers, make sure the optimization SFINAEs away in that case.
|
||||
!is_volatile<_From>::value &&
|
||||
!is_volatile<_To>::value;
|
||||
// If the types are always bitcastable, it's valid to do a bitwise copy between them.
|
||||
__is_always_bitcastable<_From, _To>::value &&
|
||||
// Reject conversions that wouldn't be performed by the regular built-in assignment (e.g. between arrays).
|
||||
is_trivially_assignable<_To&, const _From&>::value &&
|
||||
// `memmove` doesn't accept `volatile` pointers, make sure the optimization SFINAEs away in that case.
|
||||
!is_volatile<_From>::value && !is_volatile<_To>::value;
|
||||
};
|
||||
|
||||
template <class _From, class _To>
|
||||
struct __can_lower_move_assignment_to_memmove {
|
||||
static const bool value =
|
||||
__is_always_bitcastable<_From, _To>::value &&
|
||||
is_trivially_assignable<_To&, _From&&>::value &&
|
||||
!is_volatile<_From>::value &&
|
||||
!is_volatile<_To>::value;
|
||||
__is_always_bitcastable<_From, _To>::value && is_trivially_assignable<_To&, _From&&>::value &&
|
||||
!is_volatile<_From>::value && !is_volatile<_To>::value;
|
||||
};
|
||||
|
||||
// `memmove` algorithms implementation.
|
||||
|
@ -61,7 +61,8 @@ template <class _In, class _Out>
|
|||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_In*, _Out*>
|
||||
__copy_trivial_impl(_In* __first, _In* __last, _Out* __result) {
|
||||
const size_t __n = static_cast<size_t>(__last - __first);
|
||||
::__builtin_memmove(__result, __first, __n * sizeof(_Out));
|
||||
|
||||
std::__constexpr_memmove(__result, __first, __element_count(__n));
|
||||
|
||||
return std::make_pair(__last, __result + __n);
|
||||
}
|
||||
|
@ -72,92 +73,42 @@ __copy_backward_trivial_impl(_In* __first, _In* __last, _Out* __result) {
|
|||
const size_t __n = static_cast<size_t>(__last - __first);
|
||||
__result -= __n;
|
||||
|
||||
::__builtin_memmove(__result, __first, __n * sizeof(_Out));
|
||||
std::__constexpr_memmove(__result, __first, __element_count(__n));
|
||||
|
||||
return std::make_pair(__last, __result);
|
||||
}
|
||||
|
||||
// Iterator unwrapping and dispatching to the correct overload.
|
||||
|
||||
template <class _F1, class _F2>
|
||||
struct __overload : _F1, _F2 {
|
||||
using _F1::operator();
|
||||
using _F2::operator();
|
||||
};
|
||||
|
||||
template <class _InIter, class _Sent, class _OutIter, class = void>
|
||||
struct __can_rewrap : false_type {};
|
||||
|
||||
template <class _InIter, class _Sent, class _OutIter>
|
||||
struct __can_rewrap<_InIter,
|
||||
_Sent,
|
||||
_OutIter,
|
||||
// Note that sentinels are always copy-constructible.
|
||||
__enable_if_t< is_copy_constructible<_InIter>::value &&
|
||||
is_copy_constructible<_OutIter>::value > > : true_type {};
|
||||
template <class _InIter, class _OutIter>
|
||||
struct __can_rewrap
|
||||
: integral_constant<bool, is_copy_constructible<_InIter>::value && is_copy_constructible<_OutIter>::value> {};
|
||||
|
||||
template <class _Algorithm,
|
||||
class _InIter,
|
||||
class _Sent,
|
||||
class _OutIter,
|
||||
__enable_if_t<__can_rewrap<_InIter, _Sent, _OutIter>::value, int> = 0>
|
||||
__enable_if_t<__can_rewrap<_InIter, _OutIter>::value, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 pair<_InIter, _OutIter>
|
||||
__unwrap_and_dispatch(_InIter __first, _Sent __last, _OutIter __out_first) {
|
||||
__copy_move_unwrap_iters(_InIter __first, _Sent __last, _OutIter __out_first) {
|
||||
auto __range = std::__unwrap_range(__first, std::move(__last));
|
||||
auto __result = _Algorithm()(std::move(__range.first), std::move(__range.second), std::__unwrap_iter(__out_first));
|
||||
return std::make_pair(std::__rewrap_range<_Sent>(std::move(__first), std::move(__result.first)),
|
||||
std::__rewrap_iter(std::move(__out_first), std::move(__result.second)));
|
||||
std::__rewrap_iter(std::move(__out_first), std::move(__result.second)));
|
||||
}
|
||||
|
||||
template <class _Algorithm,
|
||||
class _InIter,
|
||||
class _Sent,
|
||||
class _OutIter,
|
||||
__enable_if_t<!__can_rewrap<_InIter, _Sent, _OutIter>::value, int> = 0>
|
||||
__enable_if_t<!__can_rewrap<_InIter, _OutIter>::value, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 pair<_InIter, _OutIter>
|
||||
__unwrap_and_dispatch(_InIter __first, _Sent __last, _OutIter __out_first) {
|
||||
__copy_move_unwrap_iters(_InIter __first, _Sent __last, _OutIter __out_first) {
|
||||
return _Algorithm()(std::move(__first), std::move(__last), std::move(__out_first));
|
||||
}
|
||||
|
||||
template <class _IterOps, class _InValue, class _OutIter, class = void>
|
||||
struct __can_copy_without_conversion : false_type {};
|
||||
|
||||
template <class _IterOps, class _InValue, class _OutIter>
|
||||
struct __can_copy_without_conversion<
|
||||
_IterOps,
|
||||
_InValue,
|
||||
_OutIter,
|
||||
__enable_if_t<is_same<_InValue, typename _IterOps::template __value_type<_OutIter> >::value> > : true_type {};
|
||||
|
||||
template <class _AlgPolicy,
|
||||
class _NaiveAlgorithm,
|
||||
class _OptimizedAlgorithm,
|
||||
class _InIter,
|
||||
class _Sent,
|
||||
class _OutIter>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 pair<_InIter, _OutIter>
|
||||
__dispatch_copy_or_move(_InIter __first, _Sent __last, _OutIter __out_first) {
|
||||
#ifdef _LIBCPP_COMPILER_GCC
|
||||
// GCC doesn't support `__builtin_memmove` during constant evaluation.
|
||||
if (__libcpp_is_constant_evaluated()) {
|
||||
return std::__unwrap_and_dispatch<_NaiveAlgorithm>(std::move(__first), std::move(__last), std::move(__out_first));
|
||||
}
|
||||
#else
|
||||
// In Clang, `__builtin_memmove` only supports fully trivially copyable types (just having trivial copy assignment is
|
||||
// insufficient). Also, conversions are not supported.
|
||||
if (__libcpp_is_constant_evaluated()) {
|
||||
using _InValue = typename _IterOps<_AlgPolicy>::template __value_type<_InIter>;
|
||||
if (!is_trivially_copyable<_InValue>::value ||
|
||||
!__can_copy_without_conversion<_IterOps<_AlgPolicy>, _InValue, _OutIter>::value) {
|
||||
return std::__unwrap_and_dispatch<_NaiveAlgorithm>(std::move(__first), std::move(__last), std::move(__out_first));
|
||||
}
|
||||
}
|
||||
#endif // _LIBCPP_COMPILER_GCC
|
||||
|
||||
using _Algorithm = __overload<_NaiveAlgorithm, _OptimizedAlgorithm>;
|
||||
return std::__unwrap_and_dispatch<_Algorithm>(std::move(__first), std::move(__last), std::move(__out_first));
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_COPY_MOVE_COMMON_H
|
||||
|
|
65
third_party/libcxx/__algorithm/copy_n.h
vendored
65
third_party/libcxx/__algorithm/copy_n.h
vendored
|
@ -21,45 +21,38 @@
|
|||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template<class _InputIterator, class _Size, class _OutputIterator>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
typename enable_if
|
||||
<
|
||||
__has_input_iterator_category<_InputIterator>::value &&
|
||||
!__has_random_access_iterator_category<_InputIterator>::value,
|
||||
_OutputIterator
|
||||
>::type
|
||||
copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result)
|
||||
{
|
||||
typedef decltype(_VSTD::__convert_to_integral(__orig_n)) _IntegralSize;
|
||||
_IntegralSize __n = __orig_n;
|
||||
if (__n > 0)
|
||||
{
|
||||
*__result = *__first;
|
||||
++__result;
|
||||
for (--__n; __n > 0; --__n)
|
||||
{
|
||||
++__first;
|
||||
*__result = *__first;
|
||||
++__result;
|
||||
}
|
||||
template <class _InputIterator,
|
||||
class _Size,
|
||||
class _OutputIterator,
|
||||
__enable_if_t<__has_input_iterator_category<_InputIterator>::value &&
|
||||
!__has_random_access_iterator_category<_InputIterator>::value,
|
||||
int> = 0>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
|
||||
copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result) {
|
||||
typedef decltype(std::__convert_to_integral(__orig_n)) _IntegralSize;
|
||||
_IntegralSize __n = __orig_n;
|
||||
if (__n > 0) {
|
||||
*__result = *__first;
|
||||
++__result;
|
||||
for (--__n; __n > 0; --__n) {
|
||||
++__first;
|
||||
*__result = *__first;
|
||||
++__result;
|
||||
}
|
||||
return __result;
|
||||
}
|
||||
return __result;
|
||||
}
|
||||
|
||||
template<class _InputIterator, class _Size, class _OutputIterator>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
typename enable_if
|
||||
<
|
||||
__has_random_access_iterator_category<_InputIterator>::value,
|
||||
_OutputIterator
|
||||
>::type
|
||||
copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result)
|
||||
{
|
||||
typedef typename iterator_traits<_InputIterator>::difference_type difference_type;
|
||||
typedef decltype(_VSTD::__convert_to_integral(__orig_n)) _IntegralSize;
|
||||
_IntegralSize __n = __orig_n;
|
||||
return _VSTD::copy(__first, __first + difference_type(__n), __result);
|
||||
template <class _InputIterator,
|
||||
class _Size,
|
||||
class _OutputIterator,
|
||||
__enable_if_t<__has_random_access_iterator_category<_InputIterator>::value, int> = 0>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
|
||||
copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result) {
|
||||
typedef typename iterator_traits<_InputIterator>::difference_type difference_type;
|
||||
typedef decltype(std::__convert_to_integral(__orig_n)) _IntegralSize;
|
||||
_IntegralSize __n = __orig_n;
|
||||
return std::copy(__first, __first + difference_type(__n), __result);
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
|
69
third_party/libcxx/__algorithm/count.h
vendored
69
third_party/libcxx/__algorithm/count.h
vendored
|
@ -10,26 +10,83 @@
|
|||
#ifndef _LIBCPP___ALGORITHM_COUNT_H
|
||||
#define _LIBCPP___ALGORITHM_COUNT_H
|
||||
|
||||
#include <__algorithm/iterator_operations.h>
|
||||
#include <__algorithm/min.h>
|
||||
#include <__bit/invert_if.h>
|
||||
#include <__bit/popcount.h>
|
||||
#include <__config>
|
||||
#include <__functional/identity.h>
|
||||
#include <__functional/invoke.h>
|
||||
#include <__fwd/bit_reference.h>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_PUSH_MACROS
|
||||
#include <__undef_macros>
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _InputIterator, class _Tp>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
typename iterator_traits<_InputIterator>::difference_type
|
||||
count(_InputIterator __first, _InputIterator __last, const _Tp& __value) {
|
||||
typename iterator_traits<_InputIterator>::difference_type __r(0);
|
||||
// generic implementation
|
||||
template <class _AlgPolicy, class _Iter, class _Sent, class _Tp, class _Proj>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename _IterOps<_AlgPolicy>::template __difference_type<_Iter>
|
||||
__count(_Iter __first, _Sent __last, const _Tp& __value, _Proj& __proj) {
|
||||
typename _IterOps<_AlgPolicy>::template __difference_type<_Iter> __r(0);
|
||||
for (; __first != __last; ++__first)
|
||||
if (*__first == __value)
|
||||
if (std::__invoke(__proj, *__first) == __value)
|
||||
++__r;
|
||||
return __r;
|
||||
}
|
||||
|
||||
// __bit_iterator implementation
|
||||
template <bool _ToCount, class _Cp, bool _IsConst>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename __bit_iterator<_Cp, _IsConst>::difference_type
|
||||
__count_bool(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n) {
|
||||
using _It = __bit_iterator<_Cp, _IsConst>;
|
||||
using __storage_type = typename _It::__storage_type;
|
||||
using difference_type = typename _It::difference_type;
|
||||
|
||||
const int __bits_per_word = _It::__bits_per_word;
|
||||
difference_type __r = 0;
|
||||
// do first partial word
|
||||
if (__first.__ctz_ != 0) {
|
||||
__storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_);
|
||||
__storage_type __dn = std::min(__clz_f, __n);
|
||||
__storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
|
||||
__r = std::__libcpp_popcount(std::__invert_if<!_ToCount>(*__first.__seg_) & __m);
|
||||
__n -= __dn;
|
||||
++__first.__seg_;
|
||||
}
|
||||
// do middle whole words
|
||||
for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word)
|
||||
__r += std::__libcpp_popcount(std::__invert_if<!_ToCount>(*__first.__seg_));
|
||||
// do last partial word
|
||||
if (__n > 0) {
|
||||
__storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
|
||||
__r += std::__libcpp_popcount(std::__invert_if<!_ToCount>(*__first.__seg_) & __m);
|
||||
}
|
||||
return __r;
|
||||
}
|
||||
|
||||
template <class, class _Cp, bool _IsConst, class _Tp, class _Proj, __enable_if_t<__is_identity<_Proj>::value, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __iter_diff_t<__bit_iterator<_Cp, _IsConst> >
|
||||
__count(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value, _Proj&) {
|
||||
if (__value)
|
||||
return std::__count_bool<true>(__first, static_cast<typename _Cp::size_type>(__last - __first));
|
||||
return std::__count_bool<false>(__first, static_cast<typename _Cp::size_type>(__last - __first));
|
||||
}
|
||||
|
||||
template <class _InputIterator, class _Tp>
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __iter_diff_t<_InputIterator>
|
||||
count(_InputIterator __first, _InputIterator __last, const _Tp& __value) {
|
||||
__identity __proj;
|
||||
return std::__count<_ClassicAlgPolicy>(__first, __last, __value, __proj);
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_COUNT_H
|
||||
|
|
6
third_party/libcxx/__algorithm/count_if.h
vendored
6
third_party/libcxx/__algorithm/count_if.h
vendored
|
@ -20,9 +20,9 @@
|
|||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _InputIterator, class _Predicate>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
typename iterator_traits<_InputIterator>::difference_type
|
||||
count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
typename iterator_traits<_InputIterator>::difference_type
|
||||
count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
|
||||
typename iterator_traits<_InputIterator>::difference_type __r(0);
|
||||
for (; __first != __last; ++__first)
|
||||
if (__pred(*__first))
|
||||
|
|
88
third_party/libcxx/__algorithm/equal.h
vendored
88
third_party/libcxx/__algorithm/equal.h
vendored
|
@ -18,18 +18,20 @@
|
|||
#include <__iterator/distance.h>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__string/constexpr_c_functions.h>
|
||||
#include <__type_traits/desugars_to.h>
|
||||
#include <__type_traits/enable_if.h>
|
||||
#include <__type_traits/integral_constant.h>
|
||||
#include <__type_traits/is_constant_evaluated.h>
|
||||
#include <__type_traits/is_equality_comparable.h>
|
||||
#include <__type_traits/is_volatile.h>
|
||||
#include <__type_traits/predicate_traits.h>
|
||||
#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
|
||||
|
||||
template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
|
||||
|
@ -41,41 +43,31 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 boo
|
|||
return true;
|
||||
}
|
||||
|
||||
template <
|
||||
class _Tp,
|
||||
class _Up,
|
||||
class _BinaryPredicate,
|
||||
__enable_if_t<__is_trivial_equality_predicate<_BinaryPredicate, _Tp, _Up>::value && !is_volatile<_Tp>::value &&
|
||||
!is_volatile<_Up>::value && __libcpp_is_trivially_equality_comparable<_Tp, _Up>::value,
|
||||
int> = 0>
|
||||
template <class _Tp,
|
||||
class _Up,
|
||||
class _BinaryPredicate,
|
||||
__enable_if_t<__desugars_to_v<__equal_tag, _BinaryPredicate, _Tp, _Up> && !is_volatile<_Tp>::value &&
|
||||
!is_volatile<_Up>::value && __libcpp_is_trivially_equality_comparable<_Tp, _Up>::value,
|
||||
int> = 0>
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
|
||||
__equal_iter_impl(_Tp* __first1, _Tp* __last1, _Up* __first2, _BinaryPredicate&) {
|
||||
return std::__constexpr_memcmp_equal(__first1, __first2, (__last1 - __first1) * sizeof(_Tp));
|
||||
return std::__constexpr_memcmp_equal(__first1, __first2, __element_count(__last1 - __first1));
|
||||
}
|
||||
|
||||
template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
|
||||
equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _BinaryPredicate __pred) {
|
||||
return std::__equal_iter_impl(
|
||||
std::__unwrap_iter(__first1), std::__unwrap_iter(__last1), std::__unwrap_iter(__first2), __pred);
|
||||
}
|
||||
|
||||
template <class _InputIterator1, class _InputIterator2>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
|
||||
equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2) {
|
||||
return std::equal(__first1, __last1, __first2, __equal_to());
|
||||
}
|
||||
|
||||
#if _LIBCPP_STD_VER >= 14
|
||||
template <class _BinaryPredicate, class _InputIterator1, class _InputIterator2>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
|
||||
__equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2,
|
||||
_BinaryPredicate __pred, input_iterator_tag, input_iterator_tag) {
|
||||
for (; __first1 != __last1 && __first2 != __last2; ++__first1, (void)++__first2)
|
||||
if (!__pred(*__first1, *__first2))
|
||||
return false;
|
||||
return __first1 == __last1 && __first2 == __last2;
|
||||
}
|
||||
|
||||
template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Pred, class _Proj1, class _Proj2>
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __equal_impl(
|
||||
|
@ -94,22 +86,27 @@ template <class _Tp,
|
|||
class _Pred,
|
||||
class _Proj1,
|
||||
class _Proj2,
|
||||
__enable_if_t<__is_trivial_equality_predicate<_Pred, _Tp, _Up>::value && __is_identity<_Proj1>::value &&
|
||||
__enable_if_t<__desugars_to_v<__equal_tag, _Pred, _Tp, _Up> && __is_identity<_Proj1>::value &&
|
||||
__is_identity<_Proj2>::value && !is_volatile<_Tp>::value && !is_volatile<_Up>::value &&
|
||||
__libcpp_is_trivially_equality_comparable<_Tp, _Up>::value,
|
||||
int> = 0>
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __equal_impl(
|
||||
_Tp* __first1, _Tp* __last1, _Up* __first2, _Up*, _Pred&, _Proj1&, _Proj2&) {
|
||||
return std::__constexpr_memcmp_equal(__first1, __first2, (__last1 - __first1) * sizeof(_Tp));
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
|
||||
__equal_impl(_Tp* __first1, _Tp* __last1, _Up* __first2, _Up*, _Pred&, _Proj1&, _Proj2&) {
|
||||
return std::__constexpr_memcmp_equal(__first1, __first2, __element_count(__last1 - __first1));
|
||||
}
|
||||
|
||||
template <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
|
||||
__equal(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2,
|
||||
_RandomAccessIterator2 __last2, _BinaryPredicate __pred, random_access_iterator_tag,
|
||||
random_access_iterator_tag) {
|
||||
if (_VSTD::distance(__first1, __last1) != _VSTD::distance(__first2, __last2))
|
||||
return false;
|
||||
template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
|
||||
equal(_InputIterator1 __first1,
|
||||
_InputIterator1 __last1,
|
||||
_InputIterator2 __first2,
|
||||
_InputIterator2 __last2,
|
||||
_BinaryPredicate __pred) {
|
||||
if constexpr (__has_random_access_iterator_category<_InputIterator1>::value &&
|
||||
__has_random_access_iterator_category<_InputIterator2>::value) {
|
||||
if (std::distance(__first1, __last1) != std::distance(__first2, __last2))
|
||||
return false;
|
||||
}
|
||||
__identity __proj;
|
||||
return std::__equal_impl(
|
||||
std::__unwrap_iter(__first1),
|
||||
|
@ -121,29 +118,16 @@ __equal(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _Random
|
|||
__proj);
|
||||
}
|
||||
|
||||
template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
|
||||
equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2,
|
||||
_BinaryPredicate __pred) {
|
||||
return _VSTD::__equal<_BinaryPredicate&>(
|
||||
__first1, __last1, __first2, __last2, __pred, typename iterator_traits<_InputIterator1>::iterator_category(),
|
||||
typename iterator_traits<_InputIterator2>::iterator_category());
|
||||
template <class _InputIterator1, class _InputIterator2>
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
|
||||
equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) {
|
||||
return std::equal(__first1, __last1, __first2, __last2, __equal_to());
|
||||
}
|
||||
|
||||
template <class _InputIterator1, class _InputIterator2>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
|
||||
equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) {
|
||||
return std::__equal(
|
||||
__first1,
|
||||
__last1,
|
||||
__first2,
|
||||
__last2,
|
||||
__equal_to(),
|
||||
typename iterator_traits<_InputIterator1>::iterator_category(),
|
||||
typename iterator_traits<_InputIterator2>::iterator_category());
|
||||
}
|
||||
#endif
|
||||
#endif // _LIBCPP_STD_VER >= 14
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_EQUAL_H
|
||||
|
|
28
third_party/libcxx/__algorithm/equal_range.h
vendored
28
third_party/libcxx/__algorithm/equal_range.h
vendored
|
@ -23,7 +23,7 @@
|
|||
#include <__iterator/iterator_traits.h>
|
||||
#include <__iterator/next.h>
|
||||
#include <__type_traits/is_callable.h>
|
||||
#include <__type_traits/is_copy_constructible.h>
|
||||
#include <__type_traits/is_constructible.h>
|
||||
#include <__utility/move.h>
|
||||
#include <__utility/pair.h>
|
||||
|
||||
|
@ -31,6 +31,9 @@
|
|||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_PUSH_MACROS
|
||||
#include <__undef_macros>
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _AlgPolicy, class _Compare, class _Iter, class _Sent, class _Tp, class _Proj>
|
||||
|
@ -49,21 +52,18 @@ __equal_range(_Iter __first, _Sent __last, const _Tp& __value, _Compare&& __comp
|
|||
__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<_Iter, _Iter>(std::__lower_bound<_AlgPolicy>(__first, __mid, __value, __comp, __proj),
|
||||
std::__upper_bound<_AlgPolicy>(++__mp1, __end, __value, __comp, __proj));
|
||||
}
|
||||
}
|
||||
return pair<_Iter, _Iter>(__first, __first);
|
||||
}
|
||||
|
||||
template <class _ForwardIterator, class _Tp, class _Compare>
|
||||
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator, _ForwardIterator>
|
||||
_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 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");
|
||||
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");
|
||||
return std::__equal_range<_ClassicAlgPolicy>(
|
||||
std::move(__first),
|
||||
std::move(__last),
|
||||
|
@ -73,15 +73,13 @@ equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __valu
|
|||
}
|
||||
|
||||
template <class _ForwardIterator, class _Tp>
|
||||
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator, _ForwardIterator>
|
||||
_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 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>());
|
||||
return std::equal_range(std::move(__first), std::move(__last), __value, __less<>());
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_EQUAL_RANGE_H
|
||||
|
|
26
third_party/libcxx/__algorithm/fill.h
vendored
26
third_party/libcxx/__algorithm/fill.h
vendored
|
@ -22,28 +22,22 @@ _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_SINCE_CXX20
|
||||
void
|
||||
__fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, forward_iterator_tag)
|
||||
{
|
||||
for (; __first != __last; ++__first)
|
||||
*__first = __value;
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
|
||||
__fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, forward_iterator_tag) {
|
||||
for (; __first != __last; ++__first)
|
||||
*__first = __value;
|
||||
}
|
||||
|
||||
template <class _RandomAccessIterator, class _Tp>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
void
|
||||
__fill(_RandomAccessIterator __first, _RandomAccessIterator __last, const _Tp& __value, random_access_iterator_tag)
|
||||
{
|
||||
_VSTD::fill_n(__first, __last - __first, __value);
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
|
||||
__fill(_RandomAccessIterator __first, _RandomAccessIterator __last, const _Tp& __value, random_access_iterator_tag) {
|
||||
std::fill_n(__first, __last - __first, __value);
|
||||
}
|
||||
|
||||
template <class _ForwardIterator, class _Tp>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
void
|
||||
fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
|
||||
{
|
||||
_VSTD::__fill(__first, __last, __value, typename iterator_traits<_ForwardIterator>::iterator_category());
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
|
||||
fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
|
||||
std::__fill(__first, __last, __value, typename iterator_traits<_ForwardIterator>::iterator_category());
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
|
78
third_party/libcxx/__algorithm/fill_n.h
vendored
78
third_party/libcxx/__algorithm/fill_n.h
vendored
|
@ -9,36 +9,90 @@
|
|||
#ifndef _LIBCPP___ALGORITHM_FILL_N_H
|
||||
#define _LIBCPP___ALGORITHM_FILL_N_H
|
||||
|
||||
#include <__algorithm/min.h>
|
||||
#include <__config>
|
||||
#include <__fwd/bit_reference.h>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__memory/pointer_traits.h>
|
||||
#include <__utility/convert_to_integral.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_PUSH_MACROS
|
||||
#include <__undef_macros>
|
||||
|
||||
_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_SINCE_CXX20
|
||||
_OutputIterator
|
||||
__fill_n(_OutputIterator __first, _Size __n, const _Tp& __value)
|
||||
{
|
||||
for (; __n > 0; ++__first, (void) --__n)
|
||||
*__first = __value;
|
||||
return __first;
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
|
||||
__fill_n(_OutputIterator __first, _Size __n, const _Tp& __value);
|
||||
|
||||
template <bool _FillVal, class _Cp>
|
||||
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
|
||||
__fill_n_bool(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n) {
|
||||
using _It = __bit_iterator<_Cp, false>;
|
||||
using __storage_type = typename _It::__storage_type;
|
||||
|
||||
const int __bits_per_word = _It::__bits_per_word;
|
||||
// do first partial word
|
||||
if (__first.__ctz_ != 0) {
|
||||
__storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_);
|
||||
__storage_type __dn = std::min(__clz_f, __n);
|
||||
__storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
|
||||
if (_FillVal)
|
||||
*__first.__seg_ |= __m;
|
||||
else
|
||||
*__first.__seg_ &= ~__m;
|
||||
__n -= __dn;
|
||||
++__first.__seg_;
|
||||
}
|
||||
// do middle whole words
|
||||
__storage_type __nw = __n / __bits_per_word;
|
||||
std::__fill_n(std::__to_address(__first.__seg_), __nw, _FillVal ? static_cast<__storage_type>(-1) : 0);
|
||||
__n -= __nw * __bits_per_word;
|
||||
// do last partial word
|
||||
if (__n > 0) {
|
||||
__first.__seg_ += __nw;
|
||||
__storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
|
||||
if (_FillVal)
|
||||
*__first.__seg_ |= __m;
|
||||
else
|
||||
*__first.__seg_ &= ~__m;
|
||||
}
|
||||
}
|
||||
|
||||
template <class _Cp, class _Size>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator<_Cp, false>
|
||||
__fill_n(__bit_iterator<_Cp, false> __first, _Size __n, const bool& __value) {
|
||||
if (__n > 0) {
|
||||
if (__value)
|
||||
std::__fill_n_bool<true>(__first, __n);
|
||||
else
|
||||
std::__fill_n_bool<false>(__first, __n);
|
||||
}
|
||||
return __first + __n;
|
||||
}
|
||||
|
||||
template <class _OutputIterator, class _Size, class _Tp>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
_OutputIterator
|
||||
fill_n(_OutputIterator __first, _Size __n, const _Tp& __value)
|
||||
{
|
||||
return _VSTD::__fill_n(__first, _VSTD::__convert_to_integral(__n), __value);
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
|
||||
__fill_n(_OutputIterator __first, _Size __n, const _Tp& __value) {
|
||||
for (; __n > 0; ++__first, (void)--__n)
|
||||
*__first = __value;
|
||||
return __first;
|
||||
}
|
||||
|
||||
template <class _OutputIterator, class _Size, class _Tp>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
|
||||
fill_n(_OutputIterator __first, _Size __n, const _Tp& __value) {
|
||||
return std::__fill_n(__first, std::__convert_to_integral(__n), __value);
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_FILL_N_H
|
||||
|
|
118
third_party/libcxx/__algorithm/find.h
vendored
118
third_party/libcxx/__algorithm/find.h
vendored
|
@ -10,12 +10,22 @@
|
|||
#ifndef _LIBCPP___ALGORITHM_FIND_H
|
||||
#define _LIBCPP___ALGORITHM_FIND_H
|
||||
|
||||
#include <__algorithm/find_segment_if.h>
|
||||
#include <__algorithm/min.h>
|
||||
#include <__algorithm/unwrap_iter.h>
|
||||
#include <__bit/countr.h>
|
||||
#include <__bit/invert_if.h>
|
||||
#include <__config>
|
||||
#include <__functional/identity.h>
|
||||
#include <__functional/invoke.h>
|
||||
#include <__fwd/bit_reference.h>
|
||||
#include <__iterator/segmented_iterator.h>
|
||||
#include <__string/constexpr_c_functions.h>
|
||||
#include <__type_traits/is_integral.h>
|
||||
#include <__type_traits/is_same.h>
|
||||
#include <__type_traits/is_signed.h>
|
||||
#include <__utility/move.h>
|
||||
#include <limits>
|
||||
|
||||
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
|
||||
# include <cwchar>
|
||||
|
@ -25,25 +35,29 @@
|
|||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_PUSH_MACROS
|
||||
#include <__undef_macros>
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
// generic implementation
|
||||
template <class _Iter, class _Sent, class _Tp, class _Proj>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iter
|
||||
__find_impl(_Iter __first, _Sent __last, const _Tp& __value, _Proj& __proj) {
|
||||
__find(_Iter __first, _Sent __last, const _Tp& __value, _Proj& __proj) {
|
||||
for (; __first != __last; ++__first)
|
||||
if (std::__invoke(__proj, *__first) == __value)
|
||||
break;
|
||||
return __first;
|
||||
}
|
||||
|
||||
// trivially equality comparable implementations
|
||||
template <class _Tp,
|
||||
class _Up,
|
||||
class _Proj,
|
||||
__enable_if_t<__is_identity<_Proj>::value && __libcpp_is_trivially_equality_comparable<_Tp, _Up>::value &&
|
||||
sizeof(_Tp) == 1,
|
||||
int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp*
|
||||
__find_impl(_Tp* __first, _Tp* __last, const _Up& __value, _Proj&) {
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp* __find(_Tp* __first, _Tp* __last, const _Up& __value, _Proj&) {
|
||||
if (auto __ret = std::__constexpr_memchr(__first, __value, __last - __first))
|
||||
return __ret;
|
||||
return __last;
|
||||
|
@ -56,22 +70,112 @@ template <class _Tp,
|
|||
__enable_if_t<__is_identity<_Proj>::value && __libcpp_is_trivially_equality_comparable<_Tp, _Up>::value &&
|
||||
sizeof(_Tp) == sizeof(wchar_t) && _LIBCPP_ALIGNOF(_Tp) >= _LIBCPP_ALIGNOF(wchar_t),
|
||||
int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp*
|
||||
__find_impl(_Tp* __first, _Tp* __last, const _Up& __value, _Proj&) {
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp* __find(_Tp* __first, _Tp* __last, const _Up& __value, _Proj&) {
|
||||
if (auto __ret = std::__constexpr_wmemchr(__first, __value, __last - __first))
|
||||
return __ret;
|
||||
return __last;
|
||||
}
|
||||
#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
|
||||
|
||||
// TODO: This should also be possible to get right with different signedness
|
||||
// cast integral types to allow vectorization
|
||||
template <class _Tp,
|
||||
class _Up,
|
||||
class _Proj,
|
||||
__enable_if_t<__is_identity<_Proj>::value && !__libcpp_is_trivially_equality_comparable<_Tp, _Up>::value &&
|
||||
is_integral<_Tp>::value && is_integral<_Up>::value &&
|
||||
is_signed<_Tp>::value == is_signed<_Up>::value,
|
||||
int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp*
|
||||
__find(_Tp* __first, _Tp* __last, const _Up& __value, _Proj& __proj) {
|
||||
if (__value < numeric_limits<_Tp>::min() || __value > numeric_limits<_Tp>::max())
|
||||
return __last;
|
||||
return std::__find(__first, __last, _Tp(__value), __proj);
|
||||
}
|
||||
|
||||
// __bit_iterator implementation
|
||||
template <bool _ToFind, class _Cp, bool _IsConst>
|
||||
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, _IsConst>
|
||||
__find_bool(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n) {
|
||||
using _It = __bit_iterator<_Cp, _IsConst>;
|
||||
using __storage_type = typename _It::__storage_type;
|
||||
|
||||
const int __bits_per_word = _It::__bits_per_word;
|
||||
// do first partial word
|
||||
if (__first.__ctz_ != 0) {
|
||||
__storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_);
|
||||
__storage_type __dn = std::min(__clz_f, __n);
|
||||
__storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
|
||||
__storage_type __b = std::__invert_if<!_ToFind>(*__first.__seg_) & __m;
|
||||
if (__b)
|
||||
return _It(__first.__seg_, static_cast<unsigned>(std::__libcpp_ctz(__b)));
|
||||
if (__n == __dn)
|
||||
return __first + __n;
|
||||
__n -= __dn;
|
||||
++__first.__seg_;
|
||||
}
|
||||
// do middle whole words
|
||||
for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word) {
|
||||
__storage_type __b = std::__invert_if<!_ToFind>(*__first.__seg_);
|
||||
if (__b)
|
||||
return _It(__first.__seg_, static_cast<unsigned>(std::__libcpp_ctz(__b)));
|
||||
}
|
||||
// do last partial word
|
||||
if (__n > 0) {
|
||||
__storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
|
||||
__storage_type __b = std::__invert_if<!_ToFind>(*__first.__seg_) & __m;
|
||||
if (__b)
|
||||
return _It(__first.__seg_, static_cast<unsigned>(std::__libcpp_ctz(__b)));
|
||||
}
|
||||
return _It(__first.__seg_, static_cast<unsigned>(__n));
|
||||
}
|
||||
|
||||
template <class _Cp, bool _IsConst, class _Tp, class _Proj, __enable_if_t<__is_identity<_Proj>::value, int> = 0>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator<_Cp, _IsConst>
|
||||
__find(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value, _Proj&) {
|
||||
if (static_cast<bool>(__value))
|
||||
return std::__find_bool<true>(__first, static_cast<typename _Cp::size_type>(__last - __first));
|
||||
return std::__find_bool<false>(__first, static_cast<typename _Cp::size_type>(__last - __first));
|
||||
}
|
||||
|
||||
// segmented iterator implementation
|
||||
|
||||
template <class>
|
||||
struct __find_segment;
|
||||
|
||||
template <class _SegmentedIterator,
|
||||
class _Tp,
|
||||
class _Proj,
|
||||
__enable_if_t<__is_segmented_iterator<_SegmentedIterator>::value, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _SegmentedIterator
|
||||
__find(_SegmentedIterator __first, _SegmentedIterator __last, const _Tp& __value, _Proj& __proj) {
|
||||
return std::__find_segment_if(std::move(__first), std::move(__last), __find_segment<_Tp>(__value), __proj);
|
||||
}
|
||||
|
||||
template <class _Tp>
|
||||
struct __find_segment {
|
||||
const _Tp& __value_;
|
||||
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __find_segment(const _Tp& __value) : __value_(__value) {}
|
||||
|
||||
template <class _InputIterator, class _Proj>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _InputIterator
|
||||
operator()(_InputIterator __first, _InputIterator __last, _Proj& __proj) const {
|
||||
return std::__find(__first, __last, __value_, __proj);
|
||||
}
|
||||
};
|
||||
|
||||
// public API
|
||||
template <class _InputIterator, class _Tp>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator
|
||||
find(_InputIterator __first, _InputIterator __last, const _Tp& __value) {
|
||||
__identity __proj;
|
||||
return std::__rewrap_iter(
|
||||
__first, std::__find_impl(std::__unwrap_iter(__first), std::__unwrap_iter(__last), __value, __proj));
|
||||
__first, std::__find(std::__unwrap_iter(__first), std::__unwrap_iter(__last), __value, __proj));
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_FIND_H
|
||||
|
|
92
third_party/libcxx/__algorithm/find_end.h
vendored
92
third_party/libcxx/__algorithm/find_end.h
vendored
|
@ -28,15 +28,14 @@
|
|||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <
|
||||
class _AlgPolicy,
|
||||
class _Iter1,
|
||||
class _Sent1,
|
||||
class _Iter2,
|
||||
class _Sent2,
|
||||
class _Pred,
|
||||
class _Proj1,
|
||||
class _Proj2>
|
||||
template < class _AlgPolicy,
|
||||
class _Iter1,
|
||||
class _Sent1,
|
||||
class _Iter2,
|
||||
class _Sent2,
|
||||
class _Pred,
|
||||
class _Proj1,
|
||||
class _Proj2>
|
||||
_LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1> __find_end_impl(
|
||||
_Iter1 __first1,
|
||||
_Sent1 __last1,
|
||||
|
@ -49,7 +48,7 @@ _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1>
|
|||
forward_iterator_tag) {
|
||||
// modeled after search algorithm
|
||||
_Iter1 __match_first = _IterOps<_AlgPolicy>::next(__first1, __last1); // __last1 is the "default" answer
|
||||
_Iter1 __match_last = __match_first;
|
||||
_Iter1 __match_last = __match_first;
|
||||
if (__first2 == __last2)
|
||||
return pair<_Iter1, _Iter1>(__match_last, __match_last);
|
||||
while (true) {
|
||||
|
@ -66,15 +65,14 @@ _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1>
|
|||
while (true) {
|
||||
if (++__m2 == __last2) { // Pattern exhaused, record answer and search for another one
|
||||
__match_first = __first1;
|
||||
__match_last = ++__m1;
|
||||
__match_last = ++__m1;
|
||||
++__first1;
|
||||
break;
|
||||
}
|
||||
if (++__m1 == __last1) // Source exhausted, return last answer
|
||||
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)))
|
||||
{
|
||||
// mismatch, restart with a new __first
|
||||
if (!std::__invoke(__pred, std::__invoke(__proj1, *__m1), std::__invoke(__proj2, *__m2))) {
|
||||
++__first1;
|
||||
break;
|
||||
} // else there is a match, check next elements
|
||||
|
@ -82,15 +80,14 @@ _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1>
|
|||
}
|
||||
}
|
||||
|
||||
template <
|
||||
class _IterOps,
|
||||
class _Pred,
|
||||
class _Iter1,
|
||||
class _Sent1,
|
||||
class _Iter2,
|
||||
class _Sent2,
|
||||
class _Proj1,
|
||||
class _Proj2>
|
||||
template < class _IterOps,
|
||||
class _Pred,
|
||||
class _Iter1,
|
||||
class _Sent1,
|
||||
class _Iter2,
|
||||
class _Sent2,
|
||||
class _Proj1,
|
||||
class _Proj2>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter1 __find_end(
|
||||
_Iter1 __first1,
|
||||
_Sent1 __sent1,
|
||||
|
@ -127,23 +124,21 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter1 __find_end(
|
|||
return __last1;
|
||||
|
||||
// if there is a mismatch, restart with a new __l1
|
||||
if (!std::__invoke(__pred, std::__invoke(__proj1, *--__m1), std::__invoke(__proj2, *--__m2)))
|
||||
{
|
||||
if (!std::__invoke(__pred, std::__invoke(__proj1, *--__m1), std::__invoke(__proj2, *--__m2))) {
|
||||
break;
|
||||
} // else there is a match, check next elements
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <
|
||||
class _AlgPolicy,
|
||||
class _Pred,
|
||||
class _Iter1,
|
||||
class _Sent1,
|
||||
class _Iter2,
|
||||
class _Sent2,
|
||||
class _Proj1,
|
||||
class _Proj2>
|
||||
template < class _AlgPolicy,
|
||||
class _Pred,
|
||||
class _Iter1,
|
||||
class _Sent1,
|
||||
class _Iter2,
|
||||
class _Sent2,
|
||||
class _Proj1,
|
||||
class _Proj2>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iter1 __find_end(
|
||||
_Iter1 __first1,
|
||||
_Sent1 __sent1,
|
||||
|
@ -165,8 +160,8 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iter1 __find_end(
|
|||
if (__len1 < __len2)
|
||||
return __last1;
|
||||
const _Iter1 __s = __first1 + _D1(__len2 - 1); // End of pattern match can't go before here
|
||||
_Iter1 __l1 = __last1;
|
||||
_Iter2 __l2 = __last2;
|
||||
_Iter1 __l1 = __last1;
|
||||
_Iter2 __l2 = __last2;
|
||||
--__l2;
|
||||
while (true) {
|
||||
while (true) {
|
||||
|
@ -189,10 +184,12 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iter1 __find_end(
|
|||
}
|
||||
|
||||
template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
|
||||
_ForwardIterator1 __find_end_classic(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
|
||||
_ForwardIterator2 __first2, _ForwardIterator2 __last2,
|
||||
_BinaryPredicate& __pred) {
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator1 __find_end_classic(
|
||||
_ForwardIterator1 __first1,
|
||||
_ForwardIterator1 __last1,
|
||||
_ForwardIterator2 __first2,
|
||||
_ForwardIterator2 __last2,
|
||||
_BinaryPredicate& __pred) {
|
||||
auto __proj = __identity();
|
||||
return std::__find_end_impl<_ClassicAlgPolicy>(
|
||||
__first1,
|
||||
|
@ -208,17 +205,18 @@ _ForwardIterator1 __find_end_classic(_ForwardIterator1 __first1, _ForwardIterato
|
|||
}
|
||||
|
||||
template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
_ForwardIterator1 find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
|
||||
_ForwardIterator2 __first2, _ForwardIterator2 __last2,
|
||||
_BinaryPredicate __pred) {
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 find_end(
|
||||
_ForwardIterator1 __first1,
|
||||
_ForwardIterator1 __last1,
|
||||
_ForwardIterator2 __first2,
|
||||
_ForwardIterator2 __last2,
|
||||
_BinaryPredicate __pred) {
|
||||
return std::__find_end_classic(__first1, __last1, __first2, __last2, __pred);
|
||||
}
|
||||
|
||||
template <class _ForwardIterator1, class _ForwardIterator2>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
_ForwardIterator1 find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
|
||||
_ForwardIterator2 __first2, _ForwardIterator2 __last2) {
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1
|
||||
find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) {
|
||||
return std::find_end(__first1, __last1, __first2, __last2, __equal_to());
|
||||
}
|
||||
|
||||
|
|
25
third_party/libcxx/__algorithm/find_first_of.h
vendored
25
third_party/libcxx/__algorithm/find_first_of.h
vendored
|
@ -21,12 +21,12 @@
|
|||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
|
||||
_LIBCPP_HIDE_FROM_ABI
|
||||
_LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator1 __find_first_of_ce(_ForwardIterator1 __first1,
|
||||
_ForwardIterator1 __last1,
|
||||
_ForwardIterator2 __first2,
|
||||
_ForwardIterator2 __last2,
|
||||
_BinaryPredicate&& __pred) {
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator1 __find_first_of_ce(
|
||||
_ForwardIterator1 __first1,
|
||||
_ForwardIterator1 __last1,
|
||||
_ForwardIterator2 __first2,
|
||||
_ForwardIterator2 __last2,
|
||||
_BinaryPredicate&& __pred) {
|
||||
for (; __first1 != __last1; ++__first1)
|
||||
for (_ForwardIterator2 __j = __first2; __j != __last2; ++__j)
|
||||
if (__pred(*__first1, *__j))
|
||||
|
@ -35,14 +35,17 @@ _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator1 __find_first_of_ce(_ForwardItera
|
|||
}
|
||||
|
||||
template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1
|
||||
find_first_of(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
|
||||
_ForwardIterator2 __last2, _BinaryPredicate __pred) {
|
||||
return _VSTD::__find_first_of_ce(__first1, __last1, __first2, __last2, __pred);
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 find_first_of(
|
||||
_ForwardIterator1 __first1,
|
||||
_ForwardIterator1 __last1,
|
||||
_ForwardIterator2 __first2,
|
||||
_ForwardIterator2 __last2,
|
||||
_BinaryPredicate __pred) {
|
||||
return std::__find_first_of_ce(__first1, __last1, __first2, __last2, __pred);
|
||||
}
|
||||
|
||||
template <class _ForwardIterator1, class _ForwardIterator2>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 find_first_of(
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 find_first_of(
|
||||
_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) {
|
||||
return std::__find_first_of_ce(__first1, __last1, __first2, __last2, __equal_to());
|
||||
}
|
||||
|
|
2
third_party/libcxx/__algorithm/find_if.h
vendored
2
third_party/libcxx/__algorithm/find_if.h
vendored
|
@ -19,7 +19,7 @@
|
|||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _InputIterator, class _Predicate>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator
|
||||
find_if(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
|
||||
for (; __first != __last; ++__first)
|
||||
if (__pred(*__first))
|
||||
|
|
2
third_party/libcxx/__algorithm/find_if_not.h
vendored
2
third_party/libcxx/__algorithm/find_if_not.h
vendored
|
@ -19,7 +19,7 @@
|
|||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _InputIterator, class _Predicate>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator
|
||||
find_if_not(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
|
||||
for (; __first != __last; ++__first)
|
||||
if (!__pred(*__first))
|
||||
|
|
62
third_party/libcxx/__algorithm/find_segment_if.h
vendored
Normal file
62
third_party/libcxx/__algorithm/find_segment_if.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_FIND_SEGMENT_IF_H
|
||||
#define _LIBCPP___ALGORITHM_FIND_SEGMENT_IF_H
|
||||
|
||||
#include <__config>
|
||||
#include <__iterator/segmented_iterator.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
// __find_segment_if is a utility function for optimizing iteration over segmented iterators linearly.
|
||||
// [__first, __last) has to be a segmented range. __pred is expected to take a range of local iterators and the __proj.
|
||||
// It returns an iterator to the first element that satisfies the predicate, or a one-past-the-end iterator if there was
|
||||
// no match. __proj may be anything that should be passed to __pred, but is expected to be a projection to support
|
||||
// ranges algorithms, or __identity for classic algorithms.
|
||||
|
||||
template <class _SegmentedIterator, class _Pred, class _Proj>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _SegmentedIterator
|
||||
__find_segment_if(_SegmentedIterator __first, _SegmentedIterator __last, _Pred __pred, _Proj& __proj) {
|
||||
using _Traits = __segmented_iterator_traits<_SegmentedIterator>;
|
||||
|
||||
auto __sfirst = _Traits::__segment(__first);
|
||||
auto __slast = _Traits::__segment(__last);
|
||||
|
||||
// We are in a single segment, so we might not be at the beginning or end
|
||||
if (__sfirst == __slast)
|
||||
return _Traits::__compose(__sfirst, __pred(_Traits::__local(__first), _Traits::__local(__last), __proj));
|
||||
|
||||
{ // We have more than one segment. Iterate over the first segment, since we might not start at the beginning
|
||||
auto __llast = _Traits::__end(__sfirst);
|
||||
auto __liter = __pred(_Traits::__local(__first), __llast, __proj);
|
||||
if (__liter != __llast)
|
||||
return _Traits::__compose(__sfirst, __liter);
|
||||
}
|
||||
++__sfirst;
|
||||
|
||||
// Iterate over the segments which are guaranteed to be completely in the range
|
||||
while (__sfirst != __slast) {
|
||||
auto __llast = _Traits::__end(__sfirst);
|
||||
auto __liter = __pred(_Traits::__begin(__sfirst), _Traits::__end(__sfirst), __proj);
|
||||
if (__liter != __llast)
|
||||
return _Traits::__compose(__sfirst, __liter);
|
||||
++__sfirst;
|
||||
}
|
||||
|
||||
// Iterate over the last segment
|
||||
return _Traits::__compose(__sfirst, __pred(_Traits::__begin(__sfirst), _Traits::__local(__last), __proj));
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_FIND_SEGMENT_IF_H
|
128
third_party/libcxx/__algorithm/fold.h
vendored
Normal file
128
third_party/libcxx/__algorithm/fold.h
vendored
Normal file
|
@ -0,0 +1,128 @@
|
|||
// -*- 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_FOLD_H
|
||||
#define _LIBCPP___ALGORITHM_FOLD_H
|
||||
|
||||
#include <__concepts/assignable.h>
|
||||
#include <__concepts/convertible_to.h>
|
||||
#include <__concepts/invocable.h>
|
||||
#include <__concepts/movable.h>
|
||||
#include <__config>
|
||||
#include <__functional/invoke.h>
|
||||
#include <__functional/reference_wrapper.h>
|
||||
#include <__iterator/concepts.h>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__iterator/next.h>
|
||||
#include <__ranges/access.h>
|
||||
#include <__ranges/concepts.h>
|
||||
#include <__ranges/dangling.h>
|
||||
#include <__type_traits/decay.h>
|
||||
#include <__type_traits/invoke.h>
|
||||
#include <__utility/forward.h>
|
||||
#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 >= 23
|
||||
|
||||
namespace ranges {
|
||||
template <class _Ip, class _Tp>
|
||||
struct in_value_result {
|
||||
_LIBCPP_NO_UNIQUE_ADDRESS _Ip in;
|
||||
_LIBCPP_NO_UNIQUE_ADDRESS _Tp value;
|
||||
|
||||
template <class _I2, class _T2>
|
||||
requires convertible_to<const _Ip&, _I2> && convertible_to<const _Tp&, _T2>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr operator in_value_result<_I2, _T2>() const& {
|
||||
return {in, value};
|
||||
}
|
||||
|
||||
template <class _I2, class _T2>
|
||||
requires convertible_to<_Ip, _I2> && convertible_to<_Tp, _T2>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr operator in_value_result<_I2, _T2>() && {
|
||||
return {std::move(in), std::move(value)};
|
||||
}
|
||||
};
|
||||
|
||||
template <class _Ip, class _Tp>
|
||||
using fold_left_with_iter_result = in_value_result<_Ip, _Tp>;
|
||||
|
||||
template <class _Fp, class _Tp, class _Ip, class _Rp, class _Up = decay_t<_Rp>>
|
||||
concept __indirectly_binary_left_foldable_impl =
|
||||
convertible_to<_Rp, _Up> && //
|
||||
movable<_Tp> && //
|
||||
movable<_Up> && //
|
||||
convertible_to<_Tp, _Up> && //
|
||||
invocable<_Fp&, _Up, iter_reference_t<_Ip>> && //
|
||||
assignable_from<_Up&, invoke_result_t<_Fp&, _Up, iter_reference_t<_Ip>>>;
|
||||
|
||||
template <class _Fp, class _Tp, class _Ip>
|
||||
concept __indirectly_binary_left_foldable =
|
||||
copy_constructible<_Fp> && //
|
||||
invocable<_Fp&, _Tp, iter_reference_t<_Ip>> && //
|
||||
__indirectly_binary_left_foldable_impl<_Fp, _Tp, _Ip, invoke_result_t<_Fp&, _Tp, iter_reference_t<_Ip>>>;
|
||||
|
||||
struct __fold_left_with_iter {
|
||||
template <input_iterator _Ip, sentinel_for<_Ip> _Sp, class _Tp, __indirectly_binary_left_foldable<_Tp, _Ip> _Fp>
|
||||
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr auto operator()(_Ip __first, _Sp __last, _Tp __init, _Fp __f) {
|
||||
using _Up = decay_t<invoke_result_t<_Fp&, _Tp, iter_reference_t<_Ip>>>;
|
||||
|
||||
if (__first == __last) {
|
||||
return fold_left_with_iter_result<_Ip, _Up>{std::move(__first), _Up(std::move(__init))};
|
||||
}
|
||||
|
||||
_Up __result = std::invoke(__f, std::move(__init), *__first);
|
||||
for (++__first; __first != __last; ++__first) {
|
||||
__result = std::invoke(__f, std::move(__result), *__first);
|
||||
}
|
||||
|
||||
return fold_left_with_iter_result<_Ip, _Up>{std::move(__first), std::move(__result)};
|
||||
}
|
||||
|
||||
template <input_range _Rp, class _Tp, __indirectly_binary_left_foldable<_Tp, iterator_t<_Rp>> _Fp>
|
||||
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr auto operator()(_Rp&& __r, _Tp __init, _Fp __f) {
|
||||
auto __result = operator()(ranges::begin(__r), ranges::end(__r), std::move(__init), std::ref(__f));
|
||||
|
||||
using _Up = decay_t<invoke_result_t<_Fp&, _Tp, range_reference_t<_Rp>>>;
|
||||
return fold_left_with_iter_result<borrowed_iterator_t<_Rp>, _Up>{std::move(__result.in), std::move(__result.value)};
|
||||
}
|
||||
};
|
||||
|
||||
inline constexpr auto fold_left_with_iter = __fold_left_with_iter();
|
||||
|
||||
struct __fold_left {
|
||||
template <input_iterator _Ip, sentinel_for<_Ip> _Sp, class _Tp, __indirectly_binary_left_foldable<_Tp, _Ip> _Fp>
|
||||
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr auto operator()(_Ip __first, _Sp __last, _Tp __init, _Fp __f) {
|
||||
return fold_left_with_iter(std::move(__first), std::move(__last), std::move(__init), std::ref(__f)).value;
|
||||
}
|
||||
|
||||
template <input_range _Rp, class _Tp, __indirectly_binary_left_foldable<_Tp, iterator_t<_Rp>> _Fp>
|
||||
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr auto operator()(_Rp&& __r, _Tp __init, _Fp __f) {
|
||||
return fold_left_with_iter(ranges::begin(__r), ranges::end(__r), std::move(__init), std::ref(__f)).value;
|
||||
}
|
||||
};
|
||||
|
||||
inline constexpr auto fold_left = __fold_left();
|
||||
} // namespace ranges
|
||||
|
||||
#endif // _LIBCPP_STD_VER >= 23
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_FOLD_H
|
20
third_party/libcxx/__algorithm/for_each.h
vendored
20
third_party/libcxx/__algorithm/for_each.h
vendored
|
@ -13,13 +13,18 @@
|
|||
#include <__algorithm/for_each_segment.h>
|
||||
#include <__config>
|
||||
#include <__iterator/segmented_iterator.h>
|
||||
#include <__ranges/movable_box.h>
|
||||
#include <__type_traits/enable_if.h>
|
||||
#include <__utility/in_place.h>
|
||||
#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
|
||||
|
||||
template <class _InputIterator, class _Function>
|
||||
|
@ -30,18 +35,23 @@ for_each(_InputIterator __first, _InputIterator __last, _Function __f) {
|
|||
return __f;
|
||||
}
|
||||
|
||||
#if _LIBCPP_STD_VER >= 20
|
||||
// __movable_box is available in C++20, but is actually a copyable-box, so optimization is only correct in C++23
|
||||
#if _LIBCPP_STD_VER >= 23
|
||||
template <class _SegmentedIterator, class _Function>
|
||||
requires __is_segmented_iterator<_SegmentedIterator>::value
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Function
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr _Function
|
||||
for_each(_SegmentedIterator __first, _SegmentedIterator __last, _Function __func) {
|
||||
ranges::__movable_box<_Function> __wrapped_func(in_place, std::move(__func));
|
||||
std::__for_each_segment(__first, __last, [&](auto __lfirst, auto __llast) {
|
||||
__func = std::for_each(__lfirst, __llast, std::move(__func));
|
||||
__wrapped_func =
|
||||
ranges::__movable_box<_Function>(in_place, std::for_each(__lfirst, __llast, std::move(*__wrapped_func)));
|
||||
});
|
||||
return __func;
|
||||
return std::move(*__wrapped_func);
|
||||
}
|
||||
#endif // _LIBCPP_STD_VER >= 20
|
||||
#endif // _LIBCPP_STD_VER >= 23
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_FOR_EACH_H
|
||||
|
|
7
third_party/libcxx/__algorithm/for_each_n.h
vendored
7
third_party/libcxx/__algorithm/for_each_n.h
vendored
|
@ -22,10 +22,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD
|
|||
#if _LIBCPP_STD_VER >= 17
|
||||
|
||||
template <class _InputIterator, class _Size, class _Function>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator for_each_n(_InputIterator __first,
|
||||
_Size __orig_n,
|
||||
_Function __f) {
|
||||
typedef decltype(_VSTD::__convert_to_integral(__orig_n)) _IntegralSize;
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator
|
||||
for_each_n(_InputIterator __first, _Size __orig_n, _Function __f) {
|
||||
typedef decltype(std::__convert_to_integral(__orig_n)) _IntegralSize;
|
||||
_IntegralSize __n = __orig_n;
|
||||
while (__n > 0) {
|
||||
__f(*__first);
|
||||
|
|
10
third_party/libcxx/__algorithm/generate.h
vendored
10
third_party/libcxx/__algorithm/generate.h
vendored
|
@ -18,12 +18,10 @@
|
|||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _ForwardIterator, class _Generator>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
void
|
||||
generate(_ForwardIterator __first, _ForwardIterator __last, _Generator __gen)
|
||||
{
|
||||
for (; __first != __last; ++__first)
|
||||
*__first = __gen();
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
|
||||
generate(_ForwardIterator __first, _ForwardIterator __last, _Generator __gen) {
|
||||
for (; __first != __last; ++__first)
|
||||
*__first = __gen();
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
|
16
third_party/libcxx/__algorithm/generate_n.h
vendored
16
third_party/libcxx/__algorithm/generate_n.h
vendored
|
@ -19,15 +19,13 @@
|
|||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _OutputIterator, class _Size, class _Generator>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
_OutputIterator
|
||||
generate_n(_OutputIterator __first, _Size __orig_n, _Generator __gen)
|
||||
{
|
||||
typedef decltype(_VSTD::__convert_to_integral(__orig_n)) _IntegralSize;
|
||||
_IntegralSize __n = __orig_n;
|
||||
for (; __n > 0; ++__first, (void) --__n)
|
||||
*__first = __gen();
|
||||
return __first;
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
|
||||
generate_n(_OutputIterator __first, _Size __orig_n, _Generator __gen) {
|
||||
typedef decltype(std::__convert_to_integral(__orig_n)) _IntegralSize;
|
||||
_IntegralSize __n = __orig_n;
|
||||
for (; __n > 0; ++__first, (void)--__n)
|
||||
*__first = __gen();
|
||||
return __first;
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
|
26
third_party/libcxx/__algorithm/half_positive.h
vendored
26
third_party/libcxx/__algorithm/half_positive.h
vendored
|
@ -22,28 +22,14 @@ _LIBCPP_BEGIN_NAMESPACE_STD
|
|||
|
||||
// Perform division by two quickly for positive integers (llvm.org/PR39129)
|
||||
|
||||
template <typename _Integral>
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
|
||||
typename enable_if
|
||||
<
|
||||
is_integral<_Integral>::value,
|
||||
_Integral
|
||||
>::type
|
||||
__half_positive(_Integral __value)
|
||||
{
|
||||
return static_cast<_Integral>(static_cast<__make_unsigned_t<_Integral> >(__value) / 2);
|
||||
template <typename _Integral, __enable_if_t<is_integral<_Integral>::value, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Integral __half_positive(_Integral __value) {
|
||||
return static_cast<_Integral>(static_cast<__make_unsigned_t<_Integral> >(__value) / 2);
|
||||
}
|
||||
|
||||
template <typename _Tp>
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
|
||||
typename enable_if
|
||||
<
|
||||
!is_integral<_Tp>::value,
|
||||
_Tp
|
||||
>::type
|
||||
__half_positive(_Tp __value)
|
||||
{
|
||||
return __value / 2;
|
||||
template <typename _Tp, __enable_if_t<!is_integral<_Tp>::value, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp __half_positive(_Tp __value) {
|
||||
return __value / 2;
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
|
|
@ -18,6 +18,9 @@
|
|||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_PUSH_MACROS
|
||||
#include <__undef_macros>
|
||||
|
||||
#if _LIBCPP_STD_VER >= 20
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
@ -30,7 +33,7 @@ struct in_found_result {
|
|||
|
||||
template <class _InIter2>
|
||||
requires convertible_to<const _InIter1&, _InIter2>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr operator in_found_result<_InIter2>() const & {
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr operator in_found_result<_InIter2>() const& {
|
||||
return {in, found};
|
||||
}
|
||||
|
||||
|
@ -46,4 +49,6 @@ _LIBCPP_END_NAMESPACE_STD
|
|||
|
||||
#endif // _LIBCPP_STD_VER >= 20
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_IN_FOUND_RESULT_H
|
||||
|
|
|
@ -18,6 +18,9 @@
|
|||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_PUSH_MACROS
|
||||
#include <__undef_macros>
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
#if _LIBCPP_STD_VER >= 20
|
||||
|
@ -30,7 +33,7 @@ struct in_fun_result {
|
|||
|
||||
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 & {
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr operator in_fun_result<_InIter2, _Func2>() const& {
|
||||
return {in, fun};
|
||||
}
|
||||
|
||||
|
@ -46,4 +49,6 @@ struct in_fun_result {
|
|||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_IN_FUN_RESULT_H
|
||||
|
|
|
@ -18,6 +18,9 @@
|
|||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_PUSH_MACROS
|
||||
#include <__undef_macros>
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
#if _LIBCPP_STD_VER >= 20
|
||||
|
@ -31,18 +34,16 @@ struct in_in_out_result {
|
|||
_LIBCPP_NO_UNIQUE_ADDRESS _OutIter1 out;
|
||||
|
||||
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<_InIter3, _InIter4, _OutIter2>() const& {
|
||||
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<_InIter3, _InIter4, _OutIter2>() const& {
|
||||
return {in1, in2, out};
|
||||
}
|
||||
|
||||
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<_InIter3, _InIter4, _OutIter2>() && {
|
||||
requires convertible_to<_InIter1, _InIter3> && convertible_to<_InIter2, _InIter4> &&
|
||||
convertible_to<_OutIter1, _OutIter2>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr operator in_in_out_result<_InIter3, _InIter4, _OutIter2>() && {
|
||||
return {std::move(in1), std::move(in2), std::move(out)};
|
||||
}
|
||||
};
|
||||
|
@ -53,4 +54,6 @@ struct in_in_out_result {
|
|||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_IN_IN_OUT_RESULT_H
|
||||
|
|
11
third_party/libcxx/__algorithm/in_in_result.h
vendored
11
third_party/libcxx/__algorithm/in_in_result.h
vendored
|
@ -18,6 +18,9 @@
|
|||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_PUSH_MACROS
|
||||
#include <__undef_macros>
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
#if _LIBCPP_STD_VER >= 20
|
||||
|
@ -31,15 +34,13 @@ struct in_in_result {
|
|||
|
||||
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<_InIter3, _InIter4>() const & {
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr operator in_in_result<_InIter3, _InIter4>() const& {
|
||||
return {in1, in2};
|
||||
}
|
||||
|
||||
template <class _InIter3, class _InIter4>
|
||||
requires convertible_to<_InIter1, _InIter3> && convertible_to<_InIter2, _InIter4>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
operator in_in_result<_InIter3, _InIter4>() && {
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr operator in_in_result<_InIter3, _InIter4>() && {
|
||||
return {std::move(in1), std::move(in2)};
|
||||
}
|
||||
};
|
||||
|
@ -50,4 +51,6 @@ struct in_in_result {
|
|||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_IN_IN_RESULT_H
|
||||
|
|
|
@ -18,6 +18,9 @@
|
|||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_PUSH_MACROS
|
||||
#include <__undef_macros>
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
#if _LIBCPP_STD_VER >= 20
|
||||
|
@ -30,18 +33,16 @@ struct in_out_out_result {
|
|||
_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& {
|
||||
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>() && {
|
||||
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)};
|
||||
}
|
||||
};
|
||||
|
@ -51,4 +52,6 @@ struct in_out_out_result {
|
|||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_IN_OUT_OUT_RESULT_H
|
||||
|
|
13
third_party/libcxx/__algorithm/in_out_result.h
vendored
13
third_party/libcxx/__algorithm/in_out_result.h
vendored
|
@ -18,28 +18,29 @@
|
|||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_PUSH_MACROS
|
||||
#include <__undef_macros>
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
#if _LIBCPP_STD_VER >= 20
|
||||
|
||||
namespace ranges {
|
||||
|
||||
template<class _InIter1, class _OutIter1>
|
||||
template <class _InIter1, class _OutIter1>
|
||||
struct in_out_result {
|
||||
_LIBCPP_NO_UNIQUE_ADDRESS _InIter1 in;
|
||||
_LIBCPP_NO_UNIQUE_ADDRESS _OutIter1 out;
|
||||
|
||||
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<_InIter2, _OutIter2>() const & {
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr operator in_out_result<_InIter2, _OutIter2>() const& {
|
||||
return {in, out};
|
||||
}
|
||||
|
||||
template <class _InIter2, class _OutIter2>
|
||||
requires convertible_to<_InIter1, _InIter2> && convertible_to<_OutIter1, _OutIter2>
|
||||
_LIBCPP_HIDE_FROM_ABI
|
||||
constexpr operator in_out_result<_InIter2, _OutIter2>() && {
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr operator in_out_result<_InIter2, _OutIter2>() && {
|
||||
return {std::move(in), std::move(out)};
|
||||
}
|
||||
};
|
||||
|
@ -50,4 +51,6 @@ struct in_out_result {
|
|||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_IN_OUT_RESULT_H
|
||||
|
|
46
third_party/libcxx/__algorithm/includes.h
vendored
46
third_party/libcxx/__algorithm/includes.h
vendored
|
@ -22,15 +22,23 @@
|
|||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_PUSH_MACROS
|
||||
#include <__undef_macros>
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Comp, class _Proj1, class _Proj2>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
|
||||
__includes(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2,
|
||||
_Comp&& __comp, _Proj1&& __proj1, _Proj2&& __proj2) {
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 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)))
|
||||
if (__first1 == __last1 ||
|
||||
std::__invoke(__comp, std::__invoke(__proj2, *__first2), std::__invoke(__proj1, *__first1)))
|
||||
return false;
|
||||
if (!std::__invoke(__comp, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2)))
|
||||
++__first2;
|
||||
|
@ -39,14 +47,14 @@ __includes(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2,
|
|||
}
|
||||
|
||||
template <class _InputIterator1, class _InputIterator2, class _Compare>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 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");
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 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");
|
||||
|
||||
return std::__includes(
|
||||
std::move(__first1),
|
||||
|
@ -59,17 +67,13 @@ _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
|
|||
}
|
||||
|
||||
template <class _InputIterator1, class _InputIterator2>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 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>());
|
||||
return std::includes(std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2), __less<>());
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_INCLUDES_H
|
||||
|
|
305
third_party/libcxx/__algorithm/inplace_merge.h
vendored
305
third_party/libcxx/__algorithm/inplace_merge.h
vendored
|
@ -42,54 +42,57 @@ template <class _Predicate>
|
|||
class __invert // invert the sense of a comparison
|
||||
{
|
||||
private:
|
||||
_Predicate __p_;
|
||||
_Predicate __p_;
|
||||
|
||||
public:
|
||||
_LIBCPP_INLINE_VISIBILITY __invert() {}
|
||||
_LIBCPP_HIDE_FROM_ABI __invert() {}
|
||||
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
explicit __invert(_Predicate __p) : __p_(__p) {}
|
||||
_LIBCPP_HIDE_FROM_ABI explicit __invert(_Predicate __p) : __p_(__p) {}
|
||||
|
||||
template <class _T1>
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
bool operator()(const _T1& __x) {return !__p_(__x);}
|
||||
template <class _T1>
|
||||
_LIBCPP_HIDE_FROM_ABI bool operator()(const _T1& __x) {
|
||||
return !__p_(__x);
|
||||
}
|
||||
|
||||
template <class _T1, class _T2>
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
bool operator()(const _T1& __x, const _T2& __y) {return __p_(__y, __x);}
|
||||
template <class _T1, class _T2>
|
||||
_LIBCPP_HIDE_FROM_ABI bool operator()(const _T1& __x, const _T2& __y) {
|
||||
return __p_(__y, __x);
|
||||
}
|
||||
};
|
||||
|
||||
template <class _AlgPolicy, class _Compare, class _InputIterator1, class _Sent1,
|
||||
class _InputIterator2, class _Sent2, class _OutputIterator>
|
||||
_LIBCPP_HIDE_FROM_ABI
|
||||
void __half_inplace_merge(_InputIterator1 __first1, _Sent1 __last1,
|
||||
_InputIterator2 __first2, _Sent2 __last2,
|
||||
_OutputIterator __result, _Compare&& __comp)
|
||||
{
|
||||
for (; __first1 != __last1; ++__result)
|
||||
{
|
||||
if (__first2 == __last2)
|
||||
{
|
||||
std::__move<_AlgPolicy>(__first1, __last1, __result);
|
||||
return;
|
||||
}
|
||||
|
||||
if (__comp(*__first2, *__first1))
|
||||
{
|
||||
*__result = _IterOps<_AlgPolicy>::__iter_move(__first2);
|
||||
++__first2;
|
||||
}
|
||||
else
|
||||
{
|
||||
*__result = _IterOps<_AlgPolicy>::__iter_move(__first1);
|
||||
++__first1;
|
||||
}
|
||||
template <class _AlgPolicy,
|
||||
class _Compare,
|
||||
class _InputIterator1,
|
||||
class _Sent1,
|
||||
class _InputIterator2,
|
||||
class _Sent2,
|
||||
class _OutputIterator>
|
||||
_LIBCPP_HIDE_FROM_ABI void __half_inplace_merge(
|
||||
_InputIterator1 __first1,
|
||||
_Sent1 __last1,
|
||||
_InputIterator2 __first2,
|
||||
_Sent2 __last2,
|
||||
_OutputIterator __result,
|
||||
_Compare&& __comp) {
|
||||
for (; __first1 != __last1; ++__result) {
|
||||
if (__first2 == __last2) {
|
||||
std::__move<_AlgPolicy>(__first1, __last1, __result);
|
||||
return;
|
||||
}
|
||||
// __first2 through __last2 are already in the right spot.
|
||||
|
||||
if (__comp(*__first2, *__first1)) {
|
||||
*__result = _IterOps<_AlgPolicy>::__iter_move(__first2);
|
||||
++__first2;
|
||||
} else {
|
||||
*__result = _IterOps<_AlgPolicy>::__iter_move(__first1);
|
||||
++__first1;
|
||||
}
|
||||
}
|
||||
// __first2 through __last2 are already in the right spot.
|
||||
}
|
||||
|
||||
template <class _AlgPolicy, class _Compare, class _BidirectionalIterator>
|
||||
_LIBCPP_HIDE_FROM_ABI
|
||||
void __buffered_inplace_merge(
|
||||
_LIBCPP_HIDE_FROM_ABI void __buffered_inplace_merge(
|
||||
_BidirectionalIterator __first,
|
||||
_BidirectionalIterator __middle,
|
||||
_BidirectionalIterator __last,
|
||||
|
@ -98,27 +101,25 @@ void __buffered_inplace_merge(
|
|||
typename iterator_traits<_BidirectionalIterator>::difference_type __len2,
|
||||
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);
|
||||
if (__len1 <= __len2)
|
||||
{
|
||||
value_type* __p = __buff;
|
||||
for (_BidirectionalIterator __i = __first; __i != __middle; __d.template __incr<value_type>(), (void) ++__i, (void) ++__p)
|
||||
::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(_IterOps<_AlgPolicy>::__iter_move(__i));
|
||||
typedef __unconstrained_reverse_iterator<_BidirectionalIterator> _RBi;
|
||||
typedef __unconstrained_reverse_iterator<value_type*> _Rv;
|
||||
typedef __invert<_Compare> _Inverted;
|
||||
std::__half_inplace_merge<_AlgPolicy>(_Rv(__p), _Rv(__buff),
|
||||
_RBi(__middle), _RBi(__first),
|
||||
_RBi(__last), _Inverted(__comp));
|
||||
}
|
||||
__destruct_n __d(0);
|
||||
unique_ptr<value_type, __destruct_n&> __h2(__buff, __d);
|
||||
if (__len1 <= __len2) {
|
||||
value_type* __p = __buff;
|
||||
for (_BidirectionalIterator __i = __first; __i != __middle;
|
||||
__d.template __incr<value_type>(), (void)++__i, (void)++__p)
|
||||
::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(_IterOps<_AlgPolicy>::__iter_move(__i));
|
||||
typedef reverse_iterator<_BidirectionalIterator> _RBi;
|
||||
typedef reverse_iterator<value_type*> _Rv;
|
||||
typedef __invert<_Compare> _Inverted;
|
||||
std::__half_inplace_merge<_AlgPolicy>(
|
||||
_Rv(__p), _Rv(__buff), _RBi(__middle), _RBi(__first), _RBi(__last), _Inverted(__comp));
|
||||
}
|
||||
}
|
||||
|
||||
template <class _AlgPolicy, class _Compare, class _BidirectionalIterator>
|
||||
|
@ -131,107 +132,92 @@ void __inplace_merge(
|
|||
typename iterator_traits<_BidirectionalIterator>::difference_type __len2,
|
||||
typename iterator_traits<_BidirectionalIterator>::value_type* __buff,
|
||||
ptrdiff_t __buff_size) {
|
||||
using _Ops = _IterOps<_AlgPolicy>;
|
||||
using _Ops = _IterOps<_AlgPolicy>;
|
||||
|
||||
typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
|
||||
while (true)
|
||||
{
|
||||
// if __middle == __last, we're done
|
||||
if (__len2 == 0)
|
||||
return;
|
||||
if (__len1 <= __buff_size || __len2 <= __buff_size)
|
||||
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)
|
||||
{
|
||||
if (__len1 == 0)
|
||||
return;
|
||||
if (__comp(*__middle, *__first))
|
||||
break;
|
||||
}
|
||||
// __first < __middle < __last
|
||||
// *__first > *__middle
|
||||
// partition [__first, __m1) [__m1, __middle) [__middle, __m2) [__m2, __last) such that
|
||||
// all elements in:
|
||||
// [__first, __m1) <= [__middle, __m2)
|
||||
// [__middle, __m2) < [__m1, __middle)
|
||||
// [__m1, __middle) <= [__m2, __last)
|
||||
// and __m1 or __m2 is in the middle of its range
|
||||
_BidirectionalIterator __m1; // "median" of [__first, __middle)
|
||||
_BidirectionalIterator __m2; // "median" of [__middle, __last)
|
||||
difference_type __len11; // distance(__first, __m1)
|
||||
difference_type __len21; // distance(__middle, __m2)
|
||||
// binary search smaller range
|
||||
if (__len1 < __len2)
|
||||
{ // __len >= 1, __len2 >= 2
|
||||
__len21 = __len2 / 2;
|
||||
__m2 = __middle;
|
||||
_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
|
||||
_Ops::iter_swap(__first, __middle);
|
||||
return;
|
||||
}
|
||||
// __len1 >= 2, __len2 >= 1
|
||||
__len11 = __len1 / 2;
|
||||
__m1 = __first;
|
||||
_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
|
||||
__middle = std::__rotate<_AlgPolicy>(__m1, __middle, __m2).first;
|
||||
// __len12 and __len21 now have swapped meanings
|
||||
// merge smaller range with recursive call and larger with tail recursion elimination
|
||||
if (__len11 + __len21 < __len12 + __len22)
|
||||
{
|
||||
std::__inplace_merge<_AlgPolicy>(
|
||||
__first, __m1, __middle, __comp, __len11, __len21, __buff, __buff_size);
|
||||
__first = __middle;
|
||||
__middle = __m2;
|
||||
__len1 = __len12;
|
||||
__len2 = __len22;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::__inplace_merge<_AlgPolicy>(
|
||||
__middle, __m2, __last, __comp, __len12, __len22, __buff, __buff_size);
|
||||
__last = __middle;
|
||||
__middle = __m1;
|
||||
__len1 = __len11;
|
||||
__len2 = __len21;
|
||||
}
|
||||
typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
|
||||
while (true) {
|
||||
// if __middle == __last, we're done
|
||||
if (__len2 == 0)
|
||||
return;
|
||||
if (__len1 <= __buff_size || __len2 <= __buff_size)
|
||||
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) {
|
||||
if (__len1 == 0)
|
||||
return;
|
||||
if (__comp(*__middle, *__first))
|
||||
break;
|
||||
}
|
||||
// __first < __middle < __last
|
||||
// *__first > *__middle
|
||||
// partition [__first, __m1) [__m1, __middle) [__middle, __m2) [__m2, __last) such that
|
||||
// all elements in:
|
||||
// [__first, __m1) <= [__middle, __m2)
|
||||
// [__middle, __m2) < [__m1, __middle)
|
||||
// [__m1, __middle) <= [__m2, __last)
|
||||
// and __m1 or __m2 is in the middle of its range
|
||||
_BidirectionalIterator __m1; // "median" of [__first, __middle)
|
||||
_BidirectionalIterator __m2; // "median" of [__middle, __last)
|
||||
difference_type __len11; // distance(__first, __m1)
|
||||
difference_type __len21; // distance(__middle, __m2)
|
||||
// binary search smaller range
|
||||
if (__len1 < __len2) { // __len >= 1, __len2 >= 2
|
||||
__len21 = __len2 / 2;
|
||||
__m2 = __middle;
|
||||
_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
|
||||
_Ops::iter_swap(__first, __middle);
|
||||
return;
|
||||
}
|
||||
// __len1 >= 2, __len2 >= 1
|
||||
__len11 = __len1 / 2;
|
||||
__m1 = __first;
|
||||
_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
|
||||
__middle = std::__rotate<_AlgPolicy>(__m1, __middle, __m2).first;
|
||||
// __len12 and __len21 now have swapped meanings
|
||||
// merge smaller range with recursive call and larger with tail recursion elimination
|
||||
if (__len11 + __len21 < __len12 + __len22) {
|
||||
std::__inplace_merge<_AlgPolicy>(__first, __m1, __middle, __comp, __len11, __len21, __buff, __buff_size);
|
||||
__first = __middle;
|
||||
__middle = __m2;
|
||||
__len1 = __len12;
|
||||
__len2 = __len22;
|
||||
} else {
|
||||
std::__inplace_merge<_AlgPolicy>(__middle, __m2, __last, __comp, __len12, __len22, __buff, __buff_size);
|
||||
__last = __middle;
|
||||
__middle = __m1;
|
||||
__len1 = __len11;
|
||||
__len2 = __len21;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class _AlgPolicy, class _BidirectionalIterator, class _Compare>
|
||||
_LIBCPP_HIDE_FROM_ABI
|
||||
void
|
||||
__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 = _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);
|
||||
_LIBCPP_HIDE_FROM_ABI void __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 = _IterOps<_AlgPolicy>::distance(__first, __middle);
|
||||
difference_type __len2 = _IterOps<_AlgPolicy>::distance(__middle, __last);
|
||||
difference_type __buf_size = std::min(__len1, __len2);
|
||||
// TODO: Remove the use of std::get_temporary_buffer
|
||||
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
|
||||
pair<value_type*, ptrdiff_t> __buf = std::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>
|
||||
|
@ -242,12 +228,9 @@ inline _LIBCPP_HIDE_FROM_ABI void inplace_merge(
|
|||
}
|
||||
|
||||
template <class _BidirectionalIterator>
|
||||
inline _LIBCPP_HIDE_FROM_ABI
|
||||
void
|
||||
inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last)
|
||||
{
|
||||
std::inplace_merge(std::move(__first), std::move(__middle), std::move(__last),
|
||||
__less<typename iterator_traits<_BidirectionalIterator>::value_type>());
|
||||
inline _LIBCPP_HIDE_FROM_ABI void
|
||||
inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last) {
|
||||
std::inplace_merge(std::move(__first), std::move(__middle), std::move(__last), __less<>());
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
|
20
third_party/libcxx/__algorithm/is_heap.h
vendored
20
third_party/libcxx/__algorithm/is_heap.h
vendored
|
@ -22,21 +22,15 @@
|
|||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _RandomAccessIterator, class _Compare>
|
||||
_LIBCPP_NODISCARD_EXT inline
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
bool
|
||||
is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
|
||||
{
|
||||
return std::__is_heap_until(__first, __last, static_cast<__comp_ref_type<_Compare> >(__comp)) == __last;
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
|
||||
is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) {
|
||||
return std::__is_heap_until(__first, __last, static_cast<__comp_ref_type<_Compare> >(__comp)) == __last;
|
||||
}
|
||||
|
||||
template<class _RandomAccessIterator>
|
||||
_LIBCPP_NODISCARD_EXT inline
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
bool
|
||||
is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
|
||||
{
|
||||
return _VSTD::is_heap(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
|
||||
template <class _RandomAccessIterator>
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
|
||||
is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) {
|
||||
return std::is_heap(__first, __last, __less<>());
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
|
60
third_party/libcxx/__algorithm/is_heap_until.h
vendored
60
third_party/libcxx/__algorithm/is_heap_until.h
vendored
|
@ -22,43 +22,39 @@ _LIBCPP_BEGIN_NAMESPACE_STD
|
|||
|
||||
template <class _Compare, class _RandomAccessIterator>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator
|
||||
__is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare&& __comp)
|
||||
{
|
||||
typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
|
||||
difference_type __len = __last - __first;
|
||||
difference_type __p = 0;
|
||||
difference_type __c = 1;
|
||||
_RandomAccessIterator __pp = __first;
|
||||
while (__c < __len)
|
||||
{
|
||||
_RandomAccessIterator __cp = __first + __c;
|
||||
if (__comp(*__pp, *__cp))
|
||||
return __cp;
|
||||
++__c;
|
||||
++__cp;
|
||||
if (__c == __len)
|
||||
return __last;
|
||||
if (__comp(*__pp, *__cp))
|
||||
return __cp;
|
||||
++__p;
|
||||
++__pp;
|
||||
__c = 2 * __p + 1;
|
||||
}
|
||||
return __last;
|
||||
__is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare&& __comp) {
|
||||
typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
|
||||
difference_type __len = __last - __first;
|
||||
difference_type __p = 0;
|
||||
difference_type __c = 1;
|
||||
_RandomAccessIterator __pp = __first;
|
||||
while (__c < __len) {
|
||||
_RandomAccessIterator __cp = __first + __c;
|
||||
if (__comp(*__pp, *__cp))
|
||||
return __cp;
|
||||
++__c;
|
||||
++__cp;
|
||||
if (__c == __len)
|
||||
return __last;
|
||||
if (__comp(*__pp, *__cp))
|
||||
return __cp;
|
||||
++__p;
|
||||
++__pp;
|
||||
__c = 2 * __p + 1;
|
||||
}
|
||||
return __last;
|
||||
}
|
||||
|
||||
template <class _RandomAccessIterator, class _Compare>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator
|
||||
is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
|
||||
{
|
||||
return std::__is_heap_until(__first, __last, static_cast<__comp_ref_type<_Compare> >(__comp));
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator
|
||||
is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) {
|
||||
return std::__is_heap_until(__first, __last, static_cast<__comp_ref_type<_Compare> >(__comp));
|
||||
}
|
||||
|
||||
template<class _RandomAccessIterator>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator
|
||||
is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last)
|
||||
{
|
||||
return _VSTD::__is_heap_until(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
|
||||
template <class _RandomAccessIterator>
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator
|
||||
is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last) {
|
||||
return std::__is_heap_until(__first, __last, __less<>());
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
|
23
third_party/libcxx/__algorithm/is_partitioned.h
vendored
23
third_party/libcxx/__algorithm/is_partitioned.h
vendored
|
@ -18,19 +18,18 @@
|
|||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _InputIterator, class _Predicate>
|
||||
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
|
||||
is_partitioned(_InputIterator __first, _InputIterator __last, _Predicate __pred)
|
||||
{
|
||||
for (; __first != __last; ++__first)
|
||||
if (!__pred(*__first))
|
||||
break;
|
||||
if ( __first == __last )
|
||||
return true;
|
||||
++__first;
|
||||
for (; __first != __last; ++__first)
|
||||
if (__pred(*__first))
|
||||
return false;
|
||||
_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
|
||||
is_partitioned(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
|
||||
for (; __first != __last; ++__first)
|
||||
if (!__pred(*__first))
|
||||
break;
|
||||
if (__first == __last)
|
||||
return true;
|
||||
++__first;
|
||||
for (; __first != __last; ++__first)
|
||||
if (__pred(*__first))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
|
186
third_party/libcxx/__algorithm/is_permutation.h
vendored
186
third_party/libcxx/__algorithm/is_permutation.h
vendored
|
@ -26,6 +26,9 @@
|
|||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_PUSH_MACROS
|
||||
#include <__undef_macros>
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class = void>
|
||||
|
@ -34,18 +37,24 @@ struct _ConstTimeDistance : false_type {};
|
|||
#if _LIBCPP_STD_VER >= 20
|
||||
|
||||
template <class _Iter1, class _Sent1, class _Iter2, class _Sent2>
|
||||
struct _ConstTimeDistance<_Iter1, _Sent1, _Iter2, _Sent2, __enable_if_t<
|
||||
sized_sentinel_for<_Sent1, _Iter1> &&
|
||||
sized_sentinel_for<_Sent2, _Iter2>
|
||||
>> : true_type {};
|
||||
struct _ConstTimeDistance<_Iter1,
|
||||
_Sent1,
|
||||
_Iter2,
|
||||
_Sent2,
|
||||
__enable_if_t< sized_sentinel_for<_Sent1, _Iter1> && sized_sentinel_for<_Sent2, _Iter2> >>
|
||||
: true_type {};
|
||||
|
||||
#else
|
||||
|
||||
template <class _Iter1, class _Iter2>
|
||||
struct _ConstTimeDistance<_Iter1, _Iter1, _Iter2, _Iter2, __enable_if_t<
|
||||
is_same<typename iterator_traits<_Iter1>::iterator_category, random_access_iterator_tag>::value &&
|
||||
is_same<typename iterator_traits<_Iter2>::iterator_category, random_access_iterator_tag>::value
|
||||
> > : true_type {};
|
||||
struct _ConstTimeDistance<
|
||||
_Iter1,
|
||||
_Iter1,
|
||||
_Iter2,
|
||||
_Iter2,
|
||||
__enable_if_t< is_same<typename iterator_traits<_Iter1>::iterator_category, random_access_iterator_tag>::value &&
|
||||
is_same<typename iterator_traits<_Iter2>::iterator_category, random_access_iterator_tag>::value > >
|
||||
: true_type {};
|
||||
|
||||
#endif // _LIBCPP_STD_VER >= 20
|
||||
|
||||
|
@ -53,11 +62,21 @@ struct _ConstTimeDistance<_Iter1, _Iter1, _Iter2, _Iter2, __enable_if_t<
|
|||
|
||||
// For each element in [f1, l1) see if there are the same number of equal elements in [f2, l2)
|
||||
template <class _AlgPolicy,
|
||||
class _Iter1, class _Sent1, class _Iter2, class _Sent2,
|
||||
class _Proj1, class _Proj2, class _Pred>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
|
||||
__is_permutation_impl(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2,
|
||||
_Pred&& __pred, _Proj1&& __proj1, _Proj2&& __proj2) {
|
||||
class _Iter1,
|
||||
class _Sent1,
|
||||
class _Iter2,
|
||||
class _Sent2,
|
||||
class _Proj1,
|
||||
class _Proj2,
|
||||
class _Pred>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __is_permutation_impl(
|
||||
_Iter1 __first1,
|
||||
_Sent1 __last1,
|
||||
_Iter2 __first2,
|
||||
_Sent2 __last2,
|
||||
_Pred&& __pred,
|
||||
_Proj1&& __proj1,
|
||||
_Proj2&& __proj2) {
|
||||
using _D1 = __iter_diff_t<_Iter1>;
|
||||
|
||||
for (auto __i = __first1; __i != __last1; ++__i) {
|
||||
|
@ -94,9 +113,8 @@ __is_permutation_impl(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 _
|
|||
|
||||
// 2+1 iterators, predicate. Not used by range algorithms.
|
||||
template <class _AlgPolicy, class _ForwardIterator1, class _Sentinel1, class _ForwardIterator2, class _BinaryPredicate>
|
||||
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
|
||||
__is_permutation(_ForwardIterator1 __first1, _Sentinel1 __last1, _ForwardIterator2 __first2,
|
||||
_BinaryPredicate&& __pred) {
|
||||
_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __is_permutation(
|
||||
_ForwardIterator1 __first1, _Sentinel1 __last1, _ForwardIterator2 __first2, _BinaryPredicate&& __pred) {
|
||||
// Shorten sequences as much as possible by lopping of any equal prefix.
|
||||
for (; __first1 != __last1; ++__first1, (void)++__first2) {
|
||||
if (!__pred(*__first1, *__first2))
|
||||
|
@ -108,24 +126,39 @@ __is_permutation(_ForwardIterator1 __first1, _Sentinel1 __last1, _ForwardIterato
|
|||
|
||||
// __first1 != __last1 && *__first1 != *__first2
|
||||
using _D1 = __iter_diff_t<_ForwardIterator1>;
|
||||
_D1 __l1 = _IterOps<_AlgPolicy>::distance(__first1, __last1);
|
||||
_D1 __l1 = _IterOps<_AlgPolicy>::distance(__first1, __last1);
|
||||
if (__l1 == _D1(1))
|
||||
return false;
|
||||
auto __last2 = _IterOps<_AlgPolicy>::next(__first2, __l1);
|
||||
|
||||
return std::__is_permutation_impl<_AlgPolicy>(
|
||||
std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2),
|
||||
__pred, __identity(), __identity());
|
||||
std::move(__first1),
|
||||
std::move(__last1),
|
||||
std::move(__first2),
|
||||
std::move(__last2),
|
||||
__pred,
|
||||
__identity(),
|
||||
__identity());
|
||||
}
|
||||
|
||||
// 2+2 iterators, predicate, non-constant time `distance`.
|
||||
template <class _AlgPolicy,
|
||||
class _Iter1, class _Sent1, class _Iter2, class _Sent2,
|
||||
class _Proj1, class _Proj2, class _Pred>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
|
||||
__is_permutation(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2,
|
||||
_Pred&& __pred, _Proj1&& __proj1, _Proj2&& __proj2,
|
||||
/*_ConstTimeDistance=*/false_type) {
|
||||
class _Iter1,
|
||||
class _Sent1,
|
||||
class _Iter2,
|
||||
class _Sent2,
|
||||
class _Proj1,
|
||||
class _Proj2,
|
||||
class _Pred>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __is_permutation(
|
||||
_Iter1 __first1,
|
||||
_Sent1 __last1,
|
||||
_Iter2 __first2,
|
||||
_Sent2 __last2,
|
||||
_Pred&& __pred,
|
||||
_Proj1&& __proj1,
|
||||
_Proj2&& __proj2,
|
||||
/*_ConstTimeDistance=*/false_type) {
|
||||
// Shorten sequences as much as possible by lopping of any equal prefix.
|
||||
while (__first1 != __last1 && __first2 != __last2) {
|
||||
if (!std::__invoke(__pred, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2)))
|
||||
|
@ -140,44 +173,73 @@ __is_permutation(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last
|
|||
return false;
|
||||
|
||||
using _D1 = __iter_diff_t<_Iter1>;
|
||||
_D1 __l1 = _IterOps<_AlgPolicy>::distance(__first1, __last1);
|
||||
_D1 __l1 = _IterOps<_AlgPolicy>::distance(__first1, __last1);
|
||||
|
||||
using _D2 = __iter_diff_t<_Iter2>;
|
||||
_D2 __l2 = _IterOps<_AlgPolicy>::distance(__first2, __last2);
|
||||
_D2 __l2 = _IterOps<_AlgPolicy>::distance(__first2, __last2);
|
||||
if (__l1 != __l2)
|
||||
return false;
|
||||
|
||||
return std::__is_permutation_impl<_AlgPolicy>(
|
||||
std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2),
|
||||
__pred, __proj1, __proj2);
|
||||
std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2), __pred, __proj1, __proj2);
|
||||
}
|
||||
|
||||
// 2+2 iterators, predicate, specialization for constant-time `distance` call.
|
||||
template <class _AlgPolicy,
|
||||
class _Iter1, class _Sent1, class _Iter2, class _Sent2,
|
||||
class _Proj1, class _Proj2, class _Pred>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
|
||||
__is_permutation(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2,
|
||||
_Pred&& __pred, _Proj1&& __proj1, _Proj2&& __proj2,
|
||||
/*_ConstTimeDistance=*/true_type) {
|
||||
class _Iter1,
|
||||
class _Sent1,
|
||||
class _Iter2,
|
||||
class _Sent2,
|
||||
class _Proj1,
|
||||
class _Proj2,
|
||||
class _Pred>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __is_permutation(
|
||||
_Iter1 __first1,
|
||||
_Sent1 __last1,
|
||||
_Iter2 __first2,
|
||||
_Sent2 __last2,
|
||||
_Pred&& __pred,
|
||||
_Proj1&& __proj1,
|
||||
_Proj2&& __proj2,
|
||||
/*_ConstTimeDistance=*/true_type) {
|
||||
if (std::distance(__first1, __last1) != std::distance(__first2, __last2))
|
||||
return false;
|
||||
return std::__is_permutation<_AlgPolicy>(
|
||||
std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2),
|
||||
__pred, __proj1, __proj2,
|
||||
std::move(__first1),
|
||||
std::move(__last1),
|
||||
std::move(__first2),
|
||||
std::move(__last2),
|
||||
__pred,
|
||||
__proj1,
|
||||
__proj2,
|
||||
/*_ConstTimeDistance=*/false_type());
|
||||
}
|
||||
|
||||
// 2+2 iterators, predicate
|
||||
template <class _AlgPolicy,
|
||||
class _Iter1, class _Sent1, class _Iter2, class _Sent2,
|
||||
class _Proj1, class _Proj2, class _Pred>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
|
||||
__is_permutation(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2,
|
||||
_Pred&& __pred, _Proj1&& __proj1, _Proj2&& __proj2) {
|
||||
class _Iter1,
|
||||
class _Sent1,
|
||||
class _Iter2,
|
||||
class _Sent2,
|
||||
class _Proj1,
|
||||
class _Proj2,
|
||||
class _Pred>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __is_permutation(
|
||||
_Iter1 __first1,
|
||||
_Sent1 __last1,
|
||||
_Iter2 __first2,
|
||||
_Sent2 __last2,
|
||||
_Pred&& __pred,
|
||||
_Proj1&& __proj1,
|
||||
_Proj2&& __proj2) {
|
||||
return std::__is_permutation<_AlgPolicy>(
|
||||
std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2),
|
||||
__pred, __proj1, __proj2,
|
||||
std::move(__first1),
|
||||
std::move(__last1),
|
||||
std::move(__first2),
|
||||
std::move(__last2),
|
||||
__pred,
|
||||
__proj1,
|
||||
__proj2,
|
||||
_ConstTimeDistance<_Iter1, _Sent1, _Iter2, _Sent2>());
|
||||
}
|
||||
|
||||
|
@ -185,19 +247,17 @@ __is_permutation(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last
|
|||
|
||||
// 2+1 iterators, predicate
|
||||
template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
|
||||
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
|
||||
is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
|
||||
_BinaryPredicate __pred) {
|
||||
_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool is_permutation(
|
||||
_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _BinaryPredicate __pred) {
|
||||
static_assert(__is_callable<_BinaryPredicate, decltype(*__first1), decltype(*__first2)>::value,
|
||||
"The predicate has to be callable");
|
||||
"The predicate has to be callable");
|
||||
|
||||
return std::__is_permutation<_ClassicAlgPolicy>(
|
||||
std::move(__first1), std::move(__last1), std::move(__first2), __pred);
|
||||
return std::__is_permutation<_ClassicAlgPolicy>(std::move(__first1), std::move(__last1), std::move(__first2), __pred);
|
||||
}
|
||||
|
||||
// 2+1 iterators
|
||||
template <class _ForwardIterator1, class _ForwardIterator2>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
|
||||
is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2) {
|
||||
return std::is_permutation(__first1, __last1, __first2, __equal_to());
|
||||
}
|
||||
|
@ -206,7 +266,7 @@ is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIt
|
|||
|
||||
// 2+2 iterators
|
||||
template <class _ForwardIterator1, class _ForwardIterator2>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool is_permutation(
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool is_permutation(
|
||||
_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) {
|
||||
return std::__is_permutation<_ClassicAlgPolicy>(
|
||||
std::move(__first1),
|
||||
|
@ -220,19 +280,29 @@ _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
|
|||
|
||||
// 2+2 iterators, predicate
|
||||
template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
|
||||
is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
|
||||
_ForwardIterator2 __last2, _BinaryPredicate __pred) {
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool is_permutation(
|
||||
_ForwardIterator1 __first1,
|
||||
_ForwardIterator1 __last1,
|
||||
_ForwardIterator2 __first2,
|
||||
_ForwardIterator2 __last2,
|
||||
_BinaryPredicate __pred) {
|
||||
static_assert(__is_callable<_BinaryPredicate, decltype(*__first1), decltype(*__first2)>::value,
|
||||
"The predicate has to be callable");
|
||||
"The predicate has to be callable");
|
||||
|
||||
return std::__is_permutation<_ClassicAlgPolicy>(
|
||||
std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2),
|
||||
__pred, __identity(), __identity());
|
||||
std::move(__first1),
|
||||
std::move(__last1),
|
||||
std::move(__first2),
|
||||
std::move(__last2),
|
||||
__pred,
|
||||
__identity(),
|
||||
__identity());
|
||||
}
|
||||
|
||||
#endif // _LIBCPP_STD_VER >= 14
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_IS_PERMUTATION_H
|
||||
|
|
20
third_party/libcxx/__algorithm/is_sorted.h
vendored
20
third_party/libcxx/__algorithm/is_sorted.h
vendored
|
@ -22,21 +22,15 @@
|
|||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _ForwardIterator, class _Compare>
|
||||
_LIBCPP_NODISCARD_EXT inline
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
bool
|
||||
is_sorted(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
|
||||
{
|
||||
return _VSTD::__is_sorted_until<__comp_ref_type<_Compare> >(__first, __last, __comp) == __last;
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
|
||||
is_sorted(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) {
|
||||
return std::__is_sorted_until<__comp_ref_type<_Compare> >(__first, __last, __comp) == __last;
|
||||
}
|
||||
|
||||
template<class _ForwardIterator>
|
||||
_LIBCPP_NODISCARD_EXT inline
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
bool
|
||||
is_sorted(_ForwardIterator __first, _ForwardIterator __last)
|
||||
{
|
||||
return _VSTD::is_sorted(__first, __last, __less<typename iterator_traits<_ForwardIterator>::value_type>());
|
||||
template <class _ForwardIterator>
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
|
||||
is_sorted(_ForwardIterator __first, _ForwardIterator __last) {
|
||||
return std::is_sorted(__first, __last, __less<>());
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
|
37
third_party/libcxx/__algorithm/is_sorted_until.h
vendored
37
third_party/libcxx/__algorithm/is_sorted_until.h
vendored
|
@ -22,33 +22,28 @@ _LIBCPP_BEGIN_NAMESPACE_STD
|
|||
|
||||
template <class _Compare, class _ForwardIterator>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
|
||||
__is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
|
||||
{
|
||||
if (__first != __last)
|
||||
{
|
||||
_ForwardIterator __i = __first;
|
||||
while (++__i != __last)
|
||||
{
|
||||
if (__comp(*__i, *__first))
|
||||
return __i;
|
||||
__first = __i;
|
||||
}
|
||||
__is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) {
|
||||
if (__first != __last) {
|
||||
_ForwardIterator __i = __first;
|
||||
while (++__i != __last) {
|
||||
if (__comp(*__i, *__first))
|
||||
return __i;
|
||||
__first = __i;
|
||||
}
|
||||
return __last;
|
||||
}
|
||||
return __last;
|
||||
}
|
||||
|
||||
template <class _ForwardIterator, class _Compare>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
|
||||
is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
|
||||
{
|
||||
return _VSTD::__is_sorted_until<__comp_ref_type<_Compare> >(__first, __last, __comp);
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
|
||||
is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) {
|
||||
return std::__is_sorted_until<__comp_ref_type<_Compare> >(__first, __last, __comp);
|
||||
}
|
||||
|
||||
template<class _ForwardIterator>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
|
||||
is_sorted_until(_ForwardIterator __first, _ForwardIterator __last)
|
||||
{
|
||||
return _VSTD::is_sorted_until(__first, __last, __less<typename iterator_traits<_ForwardIterator>::value_type>());
|
||||
template <class _ForwardIterator>
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
|
||||
is_sorted_until(_ForwardIterator __first, _ForwardIterator __last) {
|
||||
return std::is_sorted_until(__first, __last, __less<>());
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
|
3
third_party/libcxx/__algorithm/iter_swap.h
vendored
3
third_party/libcxx/__algorithm/iter_swap.h
vendored
|
@ -20,8 +20,7 @@
|
|||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _ForwardIterator1, class _ForwardIterator2>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 void iter_swap(_ForwardIterator1 __a,
|
||||
_ForwardIterator2 __b)
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
|
||||
// _NOEXCEPT_(_NOEXCEPT_(swap(*__a, *__b)))
|
||||
_NOEXCEPT_(_NOEXCEPT_(swap(*std::declval<_ForwardIterator1>(), *std::declval<_ForwardIterator2>()))) {
|
||||
swap(*__a, *__b);
|
||||
|
|
134
third_party/libcxx/__algorithm/iterator_operations.h
vendored
134
third_party/libcxx/__algorithm/iterator_operations.h
vendored
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include <__algorithm/iter_swap.h>
|
||||
#include <__algorithm/ranges_iterator_concept.h>
|
||||
#include <__assert>
|
||||
#include <__config>
|
||||
#include <__iterator/advance.h>
|
||||
#include <__iterator/distance.h>
|
||||
|
@ -33,16 +34,19 @@
|
|||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_PUSH_MACROS
|
||||
#include <__undef_macros>
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _AlgPolicy> struct _IterOps;
|
||||
template <class _AlgPolicy>
|
||||
struct _IterOps;
|
||||
|
||||
#if _LIBCPP_STD_VER >= 20
|
||||
struct _RangeAlgPolicy {};
|
||||
|
||||
template <>
|
||||
struct _IterOps<_RangeAlgPolicy> {
|
||||
|
||||
template <class _Iter>
|
||||
using __value_type = iter_value_t<_Iter>;
|
||||
|
||||
|
@ -52,12 +56,12 @@ struct _IterOps<_RangeAlgPolicy> {
|
|||
template <class _Iter>
|
||||
using __difference_type = iter_difference_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 prev = ranges::prev;
|
||||
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 prev = ranges::prev;
|
||||
static constexpr auto __advance_to = ranges::advance;
|
||||
};
|
||||
|
||||
|
@ -67,7 +71,6 @@ struct _ClassicAlgPolicy {};
|
|||
|
||||
template <>
|
||||
struct _IterOps<_ClassicAlgPolicy> {
|
||||
|
||||
template <class _Iter>
|
||||
using __value_type = typename iterator_traits<_Iter>::value_type;
|
||||
|
||||
|
@ -79,15 +82,14 @@ struct _IterOps<_ClassicAlgPolicy> {
|
|||
|
||||
// advance
|
||||
template <class _Iter, class _Distance>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
|
||||
static void advance(_Iter& __iter, _Distance __count) {
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static void advance(_Iter& __iter, _Distance __count) {
|
||||
std::advance(__iter, __count);
|
||||
}
|
||||
|
||||
// distance
|
||||
template <class _Iter>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
|
||||
static typename iterator_traits<_Iter>::difference_type distance(_Iter __first, _Iter __last) {
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static typename iterator_traits<_Iter>::difference_type
|
||||
distance(_Iter __first, _Iter __last) {
|
||||
return std::distance(__first, __last);
|
||||
}
|
||||
|
||||
|
@ -98,37 +100,33 @@ struct _IterOps<_ClassicAlgPolicy> {
|
|||
using __move_t = decltype(std::move(*std::declval<_Iter&>()));
|
||||
|
||||
template <class _Iter>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
|
||||
static void __validate_iter_reference() {
|
||||
static_assert(is_same<__deref_t<_Iter>, typename iterator_traits<__remove_cvref_t<_Iter> >::reference>::value,
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static void __validate_iter_reference() {
|
||||
static_assert(
|
||||
is_same<__deref_t<_Iter>, typename iterator_traits<__remove_cvref_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>
|
||||
template <class _Iter, __enable_if_t<is_reference<__deref_t<_Iter> >::value, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 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) {
|
||||
// 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.
|
||||
__move_t<_Iter>
|
||||
__iter_move(_Iter&& __i) {
|
||||
__validate_iter_reference<_Iter>();
|
||||
|
||||
return std::move(*std::forward<_Iter>(__i));
|
||||
}
|
||||
|
||||
template <class _Iter>
|
||||
template <class _Iter, __enable_if_t<!is_reference<__deref_t<_Iter> >::value, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 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) {
|
||||
// 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.
|
||||
__deref_t<_Iter>
|
||||
__iter_move(_Iter&& __i) {
|
||||
__validate_iter_reference<_Iter>();
|
||||
|
||||
return *std::forward<_Iter>(__i);
|
||||
|
@ -136,40 +134,90 @@ struct _IterOps<_ClassicAlgPolicy> {
|
|||
|
||||
// iter_swap
|
||||
template <class _Iter1, class _Iter2>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
|
||||
static void iter_swap(_Iter1&& __a, _Iter2&& __b) {
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 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_SINCE_CXX14
|
||||
_Iterator next(_Iterator, _Iterator __last) {
|
||||
_LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iterator next(_Iterator, _Iterator __last) {
|
||||
return __last;
|
||||
}
|
||||
|
||||
template <class _Iter>
|
||||
_LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX14
|
||||
__remove_cvref_t<_Iter> next(_Iter&& __it,
|
||||
typename iterator_traits<__remove_cvref_t<_Iter> >::difference_type __n = 1) {
|
||||
_LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX14 __remove_cvref_t<_Iter>
|
||||
next(_Iter&& __it, typename iterator_traits<__remove_cvref_t<_Iter> >::difference_type __n = 1) {
|
||||
return std::next(std::forward<_Iter>(__it), __n);
|
||||
}
|
||||
|
||||
// prev
|
||||
template <class _Iter>
|
||||
_LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX14
|
||||
__remove_cvref_t<_Iter> prev(_Iter&& __iter,
|
||||
typename iterator_traits<__remove_cvref_t<_Iter> >::difference_type __n = 1) {
|
||||
_LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX14 __remove_cvref_t<_Iter>
|
||||
prev(_Iter&& __iter, typename iterator_traits<__remove_cvref_t<_Iter> >::difference_type __n = 1) {
|
||||
return std::prev(std::forward<_Iter>(__iter), __n);
|
||||
}
|
||||
|
||||
template <class _Iter>
|
||||
_LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX14
|
||||
void __advance_to(_Iter& __first, _Iter __last) {
|
||||
_LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX14 void __advance_to(_Iter& __first, _Iter __last) {
|
||||
__first = __last;
|
||||
}
|
||||
|
||||
// advance with sentinel, a la std::ranges::advance
|
||||
template <class _Iter>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static __difference_type<_Iter>
|
||||
__advance_to(_Iter& __iter, __difference_type<_Iter> __count, const _Iter& __sentinel) {
|
||||
return _IterOps::__advance_to(__iter, __count, __sentinel, typename iterator_traits<_Iter>::iterator_category());
|
||||
}
|
||||
|
||||
private:
|
||||
// advance with sentinel, a la std::ranges::advance -- InputIterator specialization
|
||||
template <class _InputIter>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static __difference_type<_InputIter> __advance_to(
|
||||
_InputIter& __iter, __difference_type<_InputIter> __count, const _InputIter& __sentinel, input_iterator_tag) {
|
||||
__difference_type<_InputIter> __dist = 0;
|
||||
for (; __dist < __count && __iter != __sentinel; ++__dist)
|
||||
++__iter;
|
||||
return __count - __dist;
|
||||
}
|
||||
|
||||
// advance with sentinel, a la std::ranges::advance -- BidirectionalIterator specialization
|
||||
template <class _BiDirIter>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static __difference_type<_BiDirIter>
|
||||
__advance_to(_BiDirIter& __iter,
|
||||
__difference_type<_BiDirIter> __count,
|
||||
const _BiDirIter& __sentinel,
|
||||
bidirectional_iterator_tag) {
|
||||
__difference_type<_BiDirIter> __dist = 0;
|
||||
if (__count >= 0)
|
||||
for (; __dist < __count && __iter != __sentinel; ++__dist)
|
||||
++__iter;
|
||||
else
|
||||
for (__count = -__count; __dist < __count && __iter != __sentinel; ++__dist)
|
||||
--__iter;
|
||||
return __count - __dist;
|
||||
}
|
||||
|
||||
// advance with sentinel, a la std::ranges::advance -- RandomIterator specialization
|
||||
template <class _RandIter>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static __difference_type<_RandIter>
|
||||
__advance_to(_RandIter& __iter,
|
||||
__difference_type<_RandIter> __count,
|
||||
const _RandIter& __sentinel,
|
||||
random_access_iterator_tag) {
|
||||
auto __dist = _IterOps::distance(__iter, __sentinel);
|
||||
_LIBCPP_ASSERT_VALID_INPUT_RANGE(
|
||||
__count == 0 || (__dist < 0) == (__count < 0), "__sentinel must precede __iter when __count < 0");
|
||||
if (__count < 0)
|
||||
__dist = __dist > __count ? __dist : __count;
|
||||
else
|
||||
__dist = __dist < __count ? __dist : __count;
|
||||
__iter += __dist;
|
||||
return __count - __dist;
|
||||
}
|
||||
};
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_ITERATOR_OPERATIONS_H
|
||||
|
|
|
@ -21,40 +21,35 @@
|
|||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _Compare, class _InputIterator1, class _InputIterator2>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
|
||||
__lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1,
|
||||
_InputIterator2 __first2, _InputIterator2 __last2, _Compare __comp)
|
||||
{
|
||||
for (; __first2 != __last2; ++__first1, (void) ++__first2)
|
||||
{
|
||||
if (__first1 == __last1 || __comp(*__first1, *__first2))
|
||||
return true;
|
||||
if (__comp(*__first2, *__first1))
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __lexicographical_compare(
|
||||
_InputIterator1 __first1,
|
||||
_InputIterator1 __last1,
|
||||
_InputIterator2 __first2,
|
||||
_InputIterator2 __last2,
|
||||
_Compare __comp) {
|
||||
for (; __first2 != __last2; ++__first1, (void)++__first2) {
|
||||
if (__first1 == __last1 || __comp(*__first1, *__first2))
|
||||
return true;
|
||||
if (__comp(*__first2, *__first1))
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template <class _InputIterator1, class _InputIterator2, class _Compare>
|
||||
_LIBCPP_NODISCARD_EXT inline
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
bool
|
||||
lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1,
|
||||
_InputIterator2 __first2, _InputIterator2 __last2, _Compare __comp)
|
||||
{
|
||||
return _VSTD::__lexicographical_compare<__comp_ref_type<_Compare> >(__first1, __last1, __first2, __last2, __comp);
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool lexicographical_compare(
|
||||
_InputIterator1 __first1,
|
||||
_InputIterator1 __last1,
|
||||
_InputIterator2 __first2,
|
||||
_InputIterator2 __last2,
|
||||
_Compare __comp) {
|
||||
return std::__lexicographical_compare<__comp_ref_type<_Compare> >(__first1, __last1, __first2, __last2, __comp);
|
||||
}
|
||||
|
||||
template <class _InputIterator1, class _InputIterator2>
|
||||
_LIBCPP_NODISCARD_EXT inline
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
bool
|
||||
lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1,
|
||||
_InputIterator2 __first2, _InputIterator2 __last2)
|
||||
{
|
||||
return _VSTD::lexicographical_compare(__first1, __last1, __first2, __last2,
|
||||
__less<typename iterator_traits<_InputIterator1>::value_type,
|
||||
typename iterator_traits<_InputIterator2>::value_type>());
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool lexicographical_compare(
|
||||
_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) {
|
||||
return std::lexicographical_compare(__first1, __last1, __first2, __last2, __less<>());
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include <__config>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__type_traits/common_type.h>
|
||||
#include <__type_traits/is_copy_constructible.h>
|
||||
#include <__type_traits/is_constructible.h>
|
||||
#include <__utility/move.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
|
@ -90,7 +90,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr auto __lexicographical_compare_three_way_slow_pa
|
|||
}
|
||||
|
||||
template <class _InputIterator1, class _InputIterator2, class _Cmp>
|
||||
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr auto lexicographical_compare_three_way(
|
||||
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto lexicographical_compare_three_way(
|
||||
_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _Cmp __comp)
|
||||
-> decltype(__comp(*__first1, *__first2)) {
|
||||
static_assert(__comparison_category<decltype(__comp(*__first1, *__first2))>,
|
||||
|
@ -110,7 +110,7 @@ _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr auto lexicographical_compa
|
|||
}
|
||||
|
||||
template <class _InputIterator1, class _InputIterator2>
|
||||
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr auto lexicographical_compare_three_way(
|
||||
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto lexicographical_compare_three_way(
|
||||
_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) {
|
||||
return std::lexicographical_compare_three_way(
|
||||
std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2), std::compare_three_way());
|
||||
|
|
70
third_party/libcxx/__algorithm/lower_bound.h
vendored
70
third_party/libcxx/__algorithm/lower_bound.h
vendored
|
@ -27,11 +27,13 @@
|
|||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _AlgPolicy, class _Iter, class _Sent, class _Type, class _Proj, class _Comp>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
_Iter __lower_bound_impl(_Iter __first, _Sent __last, const _Type& __value, _Comp& __comp, _Proj& __proj) {
|
||||
auto __len = _IterOps<_AlgPolicy>::distance(__first, __last);
|
||||
|
||||
template <class _AlgPolicy, class _Iter, class _Type, class _Proj, class _Comp>
|
||||
_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter __lower_bound_bisecting(
|
||||
_Iter __first,
|
||||
const _Type& __value,
|
||||
typename iterator_traits<_Iter>::difference_type __len,
|
||||
_Comp& __comp,
|
||||
_Proj& __proj) {
|
||||
while (__len != 0) {
|
||||
auto __l2 = std::__half_positive(__len);
|
||||
_Iter __m = __first;
|
||||
|
@ -46,20 +48,60 @@ _Iter __lower_bound_impl(_Iter __first, _Sent __last, const _Type& __value, _Com
|
|||
return __first;
|
||||
}
|
||||
|
||||
// One-sided binary search, aka meta binary search, has been in the public domain for decades, and has the general
|
||||
// advantage of being \Omega(1) rather than the classic algorithm's \Omega(log(n)), with the downside of executing at
|
||||
// most 2*log(n) comparisons vs the classic algorithm's exact log(n). There are two scenarios in which it really shines:
|
||||
// the first one is when operating over non-random-access iterators, because the classic algorithm requires knowing the
|
||||
// container's size upfront, which adds \Omega(n) iterator increments to the complexity. The second one is when you're
|
||||
// traversing the container in order, trying to fast-forward to the next value: in that case, the classic algorithm
|
||||
// would yield \Omega(n*log(n)) comparisons and, for non-random-access iterators, \Omega(n^2) iterator increments,
|
||||
// whereas the one-sided version will yield O(n) operations on both counts, with a \Omega(log(n)) bound on the number of
|
||||
// comparisons.
|
||||
template <class _AlgPolicy, class _ForwardIterator, class _Sent, class _Type, class _Proj, class _Comp>
|
||||
_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
|
||||
__lower_bound_onesided(_ForwardIterator __first, _Sent __last, const _Type& __value, _Comp& __comp, _Proj& __proj) {
|
||||
// step = 0, ensuring we can always short-circuit when distance is 1 later on
|
||||
if (__first == __last || !std::__invoke(__comp, std::__invoke(__proj, *__first), __value))
|
||||
return __first;
|
||||
|
||||
using _Distance = typename iterator_traits<_ForwardIterator>::difference_type;
|
||||
for (_Distance __step = 1; __first != __last; __step <<= 1) {
|
||||
auto __it = __first;
|
||||
auto __dist = __step - _IterOps<_AlgPolicy>::__advance_to(__it, __step, __last);
|
||||
// once we reach the last range where needle can be we must start
|
||||
// looking inwards, bisecting that range
|
||||
if (__it == __last || !std::__invoke(__comp, std::__invoke(__proj, *__it), __value)) {
|
||||
// we've already checked the previous value and it was less, we can save
|
||||
// one comparison by skipping bisection
|
||||
if (__dist == 1)
|
||||
return __it;
|
||||
return std::__lower_bound_bisecting<_AlgPolicy>(__first, __value, __dist, __comp, __proj);
|
||||
}
|
||||
// range not found, move forward!
|
||||
__first = __it;
|
||||
}
|
||||
return __first;
|
||||
}
|
||||
|
||||
template <class _AlgPolicy, class _ForwardIterator, class _Sent, class _Type, class _Proj, class _Comp>
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
|
||||
__lower_bound(_ForwardIterator __first, _Sent __last, const _Type& __value, _Comp& __comp, _Proj& __proj) {
|
||||
const auto __dist = _IterOps<_AlgPolicy>::distance(__first, __last);
|
||||
return std::__lower_bound_bisecting<_AlgPolicy>(__first, __value, __dist, __comp, __proj);
|
||||
}
|
||||
|
||||
template <class _ForwardIterator, class _Tp, class _Compare>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
_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");
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _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);
|
||||
return std::__lower_bound<_ClassicAlgPolicy>(__first, __last, __value, __comp, __proj);
|
||||
}
|
||||
|
||||
template <class _ForwardIterator, class _Tp>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
_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>());
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
|
||||
lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
|
||||
return std::lower_bound(__first, __last, __value, __less<>());
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
|
24
third_party/libcxx/__algorithm/make_heap.h
vendored
24
third_party/libcxx/__algorithm/make_heap.h
vendored
|
@ -21,36 +21,40 @@
|
|||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_PUSH_MACROS
|
||||
#include <__undef_macros>
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
|
||||
void __make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare&& __comp) {
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
|
||||
__make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare&& __comp) {
|
||||
__comp_ref_type<_Compare> __comp_ref = __comp;
|
||||
|
||||
using difference_type = typename iterator_traits<_RandomAccessIterator>::difference_type;
|
||||
difference_type __n = __last - __first;
|
||||
difference_type __n = __last - __first;
|
||||
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) {
|
||||
std::__sift_down<_AlgPolicy>(__first, __comp_ref, __n, __first + __start);
|
||||
std::__sift_down<_AlgPolicy>(__first, __comp_ref, __n, __first + __start);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class _RandomAccessIterator, class _Compare>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
void make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) {
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 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_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
void make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) {
|
||||
std::make_heap(std::move(__first), std::move(__last),
|
||||
__less<typename iterator_traits<_RandomAccessIterator>::value_type>());
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
|
||||
make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) {
|
||||
std::make_heap(std::move(__first), std::move(__last), __less<>());
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_MAKE_HEAP_H
|
||||
|
|
49
third_party/libcxx/__algorithm/make_projected.h
vendored
49
third_party/libcxx/__algorithm/make_projected.h
vendored
|
@ -36,44 +36,38 @@ struct _ProjectedPred {
|
|||
: __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 _LIBCPP_HIDE_FROM_ABI operator()(_Tp&& __v) const {
|
||||
typename __invoke_of<_Pred&, decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_Tp>()))>::type
|
||||
_LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
|
||||
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 _LIBCPP_HIDE_FROM_ABI operator()(_T1&& __lhs, _T2&& __rhs) const {
|
||||
return std::__invoke(__pred,
|
||||
std::__invoke(__proj, std::forward<_T1>(__lhs)),
|
||||
std::__invoke(__proj, std::forward<_T2>(__rhs)));
|
||||
decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_T2>()))>::type _LIBCPP_CONSTEXPR
|
||||
_LIBCPP_HIDE_FROM_ABI
|
||||
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,
|
||||
__enable_if_t<!(!is_member_pointer<__decay_t<_Pred> >::value &&
|
||||
__is_identity<__decay_t<_Proj> >::value),
|
||||
int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ProjectedPred<_Pred, _Proj>
|
||||
__make_projected(_Pred& __pred, _Proj& __proj) {
|
||||
template <
|
||||
class _Pred,
|
||||
class _Proj,
|
||||
__enable_if_t<!(!is_member_pointer<__decay_t<_Pred> >::value && __is_identity<__decay_t<_Proj> >::value), int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _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,
|
||||
__enable_if_t<!is_member_pointer<__decay_t<_Pred> >::value &&
|
||||
__is_identity<__decay_t<_Proj> >::value,
|
||||
int> = 0>
|
||||
template <
|
||||
class _Pred,
|
||||
class _Proj,
|
||||
__enable_if_t<!is_member_pointer<__decay_t<_Pred> >::value && __is_identity<__decay_t<_Proj> >::value, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Pred& __make_projected(_Pred& __pred, _Proj&) {
|
||||
return __pred;
|
||||
}
|
||||
|
@ -87,8 +81,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
|
|||
namespace ranges {
|
||||
|
||||
template <class _Comp, class _Proj1, class _Proj2>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr
|
||||
decltype(auto) __make_projected_comp(_Comp& __comp, _Proj1& __proj1, _Proj2& __proj2) {
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) __make_projected_comp(_Comp& __comp, _Proj1& __proj1, _Proj2& __proj2) {
|
||||
if constexpr (__is_identity<decay_t<_Proj1>>::value && __is_identity<decay_t<_Proj2>>::value &&
|
||||
!is_member_pointer_v<decay_t<_Comp>>) {
|
||||
// Avoid creating the lambda and just use the pristine comparator -- for certain algorithms, this would enable
|
||||
|
@ -96,10 +89,10 @@ decltype(auto) __make_projected_comp(_Comp& __comp, _Proj1& __proj1, _Proj2& __p
|
|||
return __comp;
|
||||
|
||||
} else {
|
||||
return [&](auto&& __lhs, auto&& __rhs) {
|
||||
return [&](auto&& __lhs, auto&& __rhs) -> bool {
|
||||
return std::invoke(__comp,
|
||||
std::invoke(__proj1, std::forward<decltype(__lhs)>(__lhs)),
|
||||
std::invoke(__proj2, std::forward<decltype(__rhs)>(__rhs)));
|
||||
std::invoke(__proj1, std::forward<decltype(__lhs)>(__lhs)),
|
||||
std::invoke(__proj2, std::forward<decltype(__rhs)>(__rhs)));
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
39
third_party/libcxx/__algorithm/max.h
vendored
39
third_party/libcxx/__algorithm/max.h
vendored
|
@ -25,41 +25,28 @@ _LIBCPP_PUSH_MACROS
|
|||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _Tp, class _Compare>
|
||||
_LIBCPP_NODISCARD_EXT inline
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
|
||||
const _Tp&
|
||||
max(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b, _Compare __comp)
|
||||
{
|
||||
return __comp(__a, __b) ? __b : __a;
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp&
|
||||
max(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b, _Compare __comp) {
|
||||
return __comp(__a, __b) ? __b : __a;
|
||||
}
|
||||
|
||||
template <class _Tp>
|
||||
_LIBCPP_NODISCARD_EXT inline
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
|
||||
const _Tp&
|
||||
max(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b)
|
||||
{
|
||||
return _VSTD::max(__a, __b, __less<_Tp>());
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp&
|
||||
max(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b) {
|
||||
return std::max(__a, __b, __less<>());
|
||||
}
|
||||
|
||||
#ifndef _LIBCPP_CXX03_LANG
|
||||
|
||||
template<class _Tp, class _Compare>
|
||||
_LIBCPP_NODISCARD_EXT inline
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
|
||||
_Tp
|
||||
max(initializer_list<_Tp> __t, _Compare __comp)
|
||||
{
|
||||
return *_VSTD::__max_element<__comp_ref_type<_Compare> >(__t.begin(), __t.end(), __comp);
|
||||
template <class _Tp, class _Compare>
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp
|
||||
max(initializer_list<_Tp> __t, _Compare __comp) {
|
||||
return *std::__max_element<__comp_ref_type<_Compare> >(__t.begin(), __t.end(), __comp);
|
||||
}
|
||||
|
||||
template<class _Tp>
|
||||
_LIBCPP_NODISCARD_EXT inline
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
|
||||
_Tp
|
||||
max(initializer_list<_Tp> __t)
|
||||
{
|
||||
return *_VSTD::max_element(__t.begin(), __t.end(), __less<_Tp>());
|
||||
template <class _Tp>
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp max(initializer_list<_Tp> __t) {
|
||||
return *std::max_element(__t.begin(), __t.end(), __less<>());
|
||||
}
|
||||
|
||||
#endif // _LIBCPP_CXX03_LANG
|
||||
|
|
38
third_party/libcxx/__algorithm/max_element.h
vendored
38
third_party/libcxx/__algorithm/max_element.h
vendored
|
@ -22,34 +22,28 @@ _LIBCPP_BEGIN_NAMESPACE_STD
|
|||
|
||||
template <class _Compare, class _ForwardIterator>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator
|
||||
__max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
|
||||
{
|
||||
static_assert(__has_forward_iterator_category<_ForwardIterator>::value,
|
||||
"std::max_element requires a ForwardIterator");
|
||||
if (__first != __last)
|
||||
{
|
||||
_ForwardIterator __i = __first;
|
||||
while (++__i != __last)
|
||||
if (__comp(*__first, *__i))
|
||||
__first = __i;
|
||||
}
|
||||
return __first;
|
||||
__max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) {
|
||||
static_assert(
|
||||
__has_forward_iterator_category<_ForwardIterator>::value, "std::max_element requires a ForwardIterator");
|
||||
if (__first != __last) {
|
||||
_ForwardIterator __i = __first;
|
||||
while (++__i != __last)
|
||||
if (__comp(*__first, *__i))
|
||||
__first = __i;
|
||||
}
|
||||
return __first;
|
||||
}
|
||||
|
||||
template <class _ForwardIterator, class _Compare>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator
|
||||
max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
|
||||
{
|
||||
return _VSTD::__max_element<__comp_ref_type<_Compare> >(__first, __last, __comp);
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator
|
||||
max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) {
|
||||
return std::__max_element<__comp_ref_type<_Compare> >(__first, __last, __comp);
|
||||
}
|
||||
|
||||
|
||||
template <class _ForwardIterator>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator
|
||||
max_element(_ForwardIterator __first, _ForwardIterator __last)
|
||||
{
|
||||
return _VSTD::max_element(__first, __last,
|
||||
__less<typename iterator_traits<_ForwardIterator>::value_type>());
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator
|
||||
max_element(_ForwardIterator __first, _ForwardIterator __last) {
|
||||
return std::max_element(__first, __last, __less<>());
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
|
67
third_party/libcxx/__algorithm/merge.h
vendored
67
third_party/libcxx/__algorithm/merge.h
vendored
|
@ -22,47 +22,46 @@
|
|||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
_OutputIterator
|
||||
__merge(_InputIterator1 __first1, _InputIterator1 __last1,
|
||||
_InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp)
|
||||
{
|
||||
for (; __first1 != __last1; ++__result)
|
||||
{
|
||||
if (__first2 == __last2)
|
||||
return _VSTD::copy(__first1, __last1, __result);
|
||||
if (__comp(*__first2, *__first1))
|
||||
{
|
||||
*__result = *__first2;
|
||||
++__first2;
|
||||
}
|
||||
else
|
||||
{
|
||||
*__result = *__first1;
|
||||
++__first1;
|
||||
}
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator __merge(
|
||||
_InputIterator1 __first1,
|
||||
_InputIterator1 __last1,
|
||||
_InputIterator2 __first2,
|
||||
_InputIterator2 __last2,
|
||||
_OutputIterator __result,
|
||||
_Compare __comp) {
|
||||
for (; __first1 != __last1; ++__result) {
|
||||
if (__first2 == __last2)
|
||||
return std::copy(__first1, __last1, __result);
|
||||
if (__comp(*__first2, *__first1)) {
|
||||
*__result = *__first2;
|
||||
++__first2;
|
||||
} else {
|
||||
*__result = *__first1;
|
||||
++__first1;
|
||||
}
|
||||
return _VSTD::copy(__first2, __last2, __result);
|
||||
}
|
||||
return std::copy(__first2, __last2, __result);
|
||||
}
|
||||
|
||||
template <class _InputIterator1, class _InputIterator2, class _OutputIterator, class _Compare>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
_OutputIterator
|
||||
merge(_InputIterator1 __first1, _InputIterator1 __last1,
|
||||
_InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp)
|
||||
{
|
||||
return _VSTD::__merge<__comp_ref_type<_Compare> >(__first1, __last1, __first2, __last2, __result, __comp);
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
|
||||
merge(_InputIterator1 __first1,
|
||||
_InputIterator1 __last1,
|
||||
_InputIterator2 __first2,
|
||||
_InputIterator2 __last2,
|
||||
_OutputIterator __result,
|
||||
_Compare __comp) {
|
||||
return std::__merge<__comp_ref_type<_Compare> >(__first1, __last1, __first2, __last2, __result, __comp);
|
||||
}
|
||||
|
||||
template <class _InputIterator1, class _InputIterator2, class _OutputIterator>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
_OutputIterator
|
||||
merge(_InputIterator1 __first1, _InputIterator1 __last1,
|
||||
_InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result)
|
||||
{
|
||||
typedef typename iterator_traits<_InputIterator1>::value_type __v1;
|
||||
typedef typename iterator_traits<_InputIterator2>::value_type __v2;
|
||||
return _VSTD::merge(__first1, __last1, __first2, __last2, __result, __less<__v1, __v2>());
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
|
||||
merge(_InputIterator1 __first1,
|
||||
_InputIterator1 __last1,
|
||||
_InputIterator2 __first2,
|
||||
_InputIterator2 __last2,
|
||||
_OutputIterator __result) {
|
||||
return std::merge(__first1, __last1, __first2, __last2, __result, __less<>());
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
|
39
third_party/libcxx/__algorithm/min.h
vendored
39
third_party/libcxx/__algorithm/min.h
vendored
|
@ -25,41 +25,28 @@ _LIBCPP_PUSH_MACROS
|
|||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _Tp, class _Compare>
|
||||
_LIBCPP_NODISCARD_EXT inline
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
|
||||
const _Tp&
|
||||
min(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b, _Compare __comp)
|
||||
{
|
||||
return __comp(__b, __a) ? __b : __a;
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp&
|
||||
min(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b, _Compare __comp) {
|
||||
return __comp(__b, __a) ? __b : __a;
|
||||
}
|
||||
|
||||
template <class _Tp>
|
||||
_LIBCPP_NODISCARD_EXT inline
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
|
||||
const _Tp&
|
||||
min(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b)
|
||||
{
|
||||
return _VSTD::min(__a, __b, __less<_Tp>());
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp&
|
||||
min(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b) {
|
||||
return std::min(__a, __b, __less<>());
|
||||
}
|
||||
|
||||
#ifndef _LIBCPP_CXX03_LANG
|
||||
|
||||
template<class _Tp, class _Compare>
|
||||
_LIBCPP_NODISCARD_EXT inline
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
|
||||
_Tp
|
||||
min(initializer_list<_Tp> __t, _Compare __comp)
|
||||
{
|
||||
return *_VSTD::__min_element<__comp_ref_type<_Compare> >(__t.begin(), __t.end(), __comp);
|
||||
template <class _Tp, class _Compare>
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp
|
||||
min(initializer_list<_Tp> __t, _Compare __comp) {
|
||||
return *std::__min_element<__comp_ref_type<_Compare> >(__t.begin(), __t.end(), __comp);
|
||||
}
|
||||
|
||||
template<class _Tp>
|
||||
_LIBCPP_NODISCARD_EXT inline
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
|
||||
_Tp
|
||||
min(initializer_list<_Tp> __t)
|
||||
{
|
||||
return *_VSTD::min_element(__t.begin(), __t.end(), __less<_Tp>());
|
||||
template <class _Tp>
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp min(initializer_list<_Tp> __t) {
|
||||
return *std::min_element(__t.begin(), __t.end(), __less<>());
|
||||
}
|
||||
|
||||
#endif // _LIBCPP_CXX03_LANG
|
||||
|
|
33
third_party/libcxx/__algorithm/min_element.h
vendored
33
third_party/libcxx/__algorithm/min_element.h
vendored
|
@ -22,11 +22,14 @@
|
|||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_PUSH_MACROS
|
||||
#include <__undef_macros>
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _Comp, class _Iter, class _Sent, class _Proj>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
|
||||
_Iter __min_element(_Iter __first, _Sent __last, _Comp __comp, _Proj& __proj) {
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iter
|
||||
__min_element(_Iter __first, _Sent __last, _Comp __comp, _Proj& __proj) {
|
||||
if (__first == __last)
|
||||
return __first;
|
||||
|
||||
|
@ -39,32 +42,30 @@ _Iter __min_element(_Iter __first, _Sent __last, _Comp __comp, _Proj& __proj) {
|
|||
}
|
||||
|
||||
template <class _Comp, class _Iter, class _Sent>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
|
||||
_Iter __min_element(_Iter __first, _Sent __last, _Comp __comp) {
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _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_SINCE_CXX14 _ForwardIterator
|
||||
min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
|
||||
{
|
||||
static_assert(__has_forward_iterator_category<_ForwardIterator>::value,
|
||||
"std::min_element requires a ForwardIterator");
|
||||
static_assert(__is_callable<_Compare, decltype(*__first), decltype(*__first)>::value,
|
||||
"The comparator has to be callable");
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator
|
||||
min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) {
|
||||
static_assert(
|
||||
__has_forward_iterator_category<_ForwardIterator>::value, "std::min_element requires a ForwardIterator");
|
||||
static_assert(
|
||||
__is_callable<_Compare, decltype(*__first), decltype(*__first)>::value, "The comparator has to be callable");
|
||||
|
||||
return std::__min_element<__comp_ref_type<_Compare> >(std::move(__first), std::move(__last), __comp);
|
||||
}
|
||||
|
||||
template <class _ForwardIterator>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator
|
||||
min_element(_ForwardIterator __first, _ForwardIterator __last)
|
||||
{
|
||||
return _VSTD::min_element(__first, __last,
|
||||
__less<typename iterator_traits<_ForwardIterator>::value_type>());
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator
|
||||
min_element(_ForwardIterator __first, _ForwardIterator __last) {
|
||||
return std::min_element(__first, __last, __less<>());
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_MIN_ELEMENT_H
|
||||
|
|
|
@ -34,7 +34,7 @@ struct min_max_result {
|
|||
|
||||
template <class _T2>
|
||||
requires convertible_to<const _T1&, _T2>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr operator min_max_result<_T2>() const & {
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr operator min_max_result<_T2>() const& {
|
||||
return {min, max};
|
||||
}
|
||||
|
||||
|
|
48
third_party/libcxx/__algorithm/minmax.h
vendored
48
third_party/libcxx/__algorithm/minmax.h
vendored
|
@ -23,43 +23,33 @@
|
|||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template<class _Tp, class _Compare>
|
||||
_LIBCPP_NODISCARD_EXT inline
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
|
||||
pair<const _Tp&, const _Tp&>
|
||||
minmax(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b, _Compare __comp)
|
||||
{
|
||||
return __comp(__b, __a) ? pair<const _Tp&, const _Tp&>(__b, __a) :
|
||||
pair<const _Tp&, const _Tp&>(__a, __b);
|
||||
template <class _Tp, class _Compare>
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<const _Tp&, const _Tp&>
|
||||
minmax(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b, _Compare __comp) {
|
||||
return __comp(__b, __a) ? pair<const _Tp&, const _Tp&>(__b, __a) : pair<const _Tp&, const _Tp&>(__a, __b);
|
||||
}
|
||||
|
||||
template<class _Tp>
|
||||
_LIBCPP_NODISCARD_EXT inline
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
|
||||
pair<const _Tp&, const _Tp&>
|
||||
minmax(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b)
|
||||
{
|
||||
return std::minmax(__a, __b, __less<_Tp>());
|
||||
template <class _Tp>
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<const _Tp&, const _Tp&>
|
||||
minmax(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b) {
|
||||
return std::minmax(__a, __b, __less<>());
|
||||
}
|
||||
|
||||
#ifndef _LIBCPP_CXX03_LANG
|
||||
|
||||
template<class _Tp, class _Compare>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
|
||||
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, class _Compare>
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 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>
|
||||
_LIBCPP_NODISCARD_EXT inline
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
|
||||
pair<_Tp, _Tp>
|
||||
minmax(initializer_list<_Tp> __t)
|
||||
{
|
||||
return std::minmax(__t, __less<_Tp>());
|
||||
template <class _Tp>
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Tp, _Tp>
|
||||
minmax(initializer_list<_Tp> __t) {
|
||||
return std::minmax(__t, __less<>());
|
||||
}
|
||||
|
||||
#endif // _LIBCPP_CXX03_LANG
|
||||
|
|
32
third_party/libcxx/__algorithm/minmax_element.h
vendored
32
third_party/libcxx/__algorithm/minmax_element.h
vendored
|
@ -29,19 +29,18 @@ class _MinmaxElementLessFunc {
|
|||
_Proj& __proj_;
|
||||
|
||||
public:
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
|
||||
_MinmaxElementLessFunc(_Comp& __comp, _Proj& __proj) : __comp_(__comp), __proj_(__proj) {}
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _MinmaxElementLessFunc(_Comp& __comp, _Proj& __proj)
|
||||
: __comp_(__comp), __proj_(__proj) {}
|
||||
|
||||
template <class _Iter>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
|
||||
bool operator()(_Iter& __it1, _Iter& __it2) {
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 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_SINCE_CXX14
|
||||
pair<_Iter, _Iter> __minmax_element_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) {
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 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);
|
||||
|
@ -66,8 +65,8 @@ pair<_Iter, _Iter> __minmax_element_impl(_Iter __first, _Sent __last, _Comp& __c
|
|||
if (__less(__first, __i)) {
|
||||
if (__less(__first, __result.first))
|
||||
__result.first = __first;
|
||||
if (!__less(__i, __result.second))
|
||||
__result.second = __i;
|
||||
if (!__less(__i, __result.second))
|
||||
__result.second = __i;
|
||||
} else {
|
||||
if (__less(__i, __result.first))
|
||||
__result.first = __i;
|
||||
|
@ -80,21 +79,20 @@ pair<_Iter, _Iter> __minmax_element_impl(_Iter __first, _Sent __last, _Comp& __c
|
|||
}
|
||||
|
||||
template <class _ForwardIterator, class _Compare>
|
||||
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
|
||||
pair<_ForwardIterator, _ForwardIterator>
|
||||
_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_ForwardIterator, _ForwardIterator>
|
||||
minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) {
|
||||
static_assert(__has_forward_iterator_category<_ForwardIterator>::value,
|
||||
"std::minmax_element requires a ForwardIterator");
|
||||
static_assert(__is_callable<_Compare, decltype(*__first), decltype(*__first)>::value,
|
||||
"The comparator has to be callable");
|
||||
static_assert(
|
||||
__has_forward_iterator_category<_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_SINCE_CXX14
|
||||
pair<_ForwardIterator, _ForwardIterator> minmax_element(_ForwardIterator __first, _ForwardIterator __last) {
|
||||
return std::minmax_element(__first, __last, __less<typename iterator_traits<_ForwardIterator>::value_type>());
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_ForwardIterator, _ForwardIterator>
|
||||
minmax_element(_ForwardIterator __first, _ForwardIterator __last) {
|
||||
return std::minmax_element(__first, __last, __less<>());
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
|
198
third_party/libcxx/__algorithm/mismatch.h
vendored
198
third_party/libcxx/__algorithm/mismatch.h
vendored
|
@ -11,53 +11,207 @@
|
|||
#define _LIBCPP___ALGORITHM_MISMATCH_H
|
||||
|
||||
#include <__algorithm/comp.h>
|
||||
#include <__algorithm/min.h>
|
||||
#include <__algorithm/simd_utils.h>
|
||||
#include <__algorithm/unwrap_iter.h>
|
||||
#include <__config>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__functional/identity.h>
|
||||
#include <__iterator/aliasing_iterator.h>
|
||||
#include <__type_traits/desugars_to.h>
|
||||
#include <__type_traits/invoke.h>
|
||||
#include <__type_traits/is_constant_evaluated.h>
|
||||
#include <__type_traits/is_equality_comparable.h>
|
||||
#include <__type_traits/is_integral.h>
|
||||
#include <__utility/move.h>
|
||||
#include <__utility/pair.h>
|
||||
#include <__utility/unreachable.h>
|
||||
#include <cstddef>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_PUSH_MACROS
|
||||
#include <__undef_macros>
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY
|
||||
_LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2>
|
||||
mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _BinaryPredicate __pred) {
|
||||
for (; __first1 != __last1; ++__first1, (void)++__first2)
|
||||
if (!__pred(*__first1, *__first2))
|
||||
template <class _Iter1, class _Sent1, class _Iter2, class _Pred, class _Proj1, class _Proj2>
|
||||
_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Iter1, _Iter2>
|
||||
__mismatch_loop(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Pred& __pred, _Proj1& __proj1, _Proj2& __proj2) {
|
||||
while (__first1 != __last1) {
|
||||
if (!std::__invoke(__pred, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2)))
|
||||
break;
|
||||
return pair<_InputIterator1, _InputIterator2>(__first1, __first2);
|
||||
++__first1;
|
||||
++__first2;
|
||||
}
|
||||
return std::make_pair(std::move(__first1), std::move(__first2));
|
||||
}
|
||||
|
||||
template <class _Iter1, class _Sent1, class _Iter2, class _Pred, class _Proj1, class _Proj2>
|
||||
_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Iter1, _Iter2>
|
||||
__mismatch(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Pred& __pred, _Proj1& __proj1, _Proj2& __proj2) {
|
||||
return std::__mismatch_loop(__first1, __last1, __first2, __pred, __proj1, __proj2);
|
||||
}
|
||||
|
||||
#if _LIBCPP_VECTORIZE_ALGORITHMS
|
||||
|
||||
template <class _Iter>
|
||||
_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Iter, _Iter>
|
||||
__mismatch_vectorized(_Iter __first1, _Iter __last1, _Iter __first2) {
|
||||
using __value_type = __iter_value_type<_Iter>;
|
||||
constexpr size_t __unroll_count = 4;
|
||||
constexpr size_t __vec_size = __native_vector_size<__value_type>;
|
||||
using __vec = __simd_vector<__value_type, __vec_size>;
|
||||
|
||||
if (!__libcpp_is_constant_evaluated()) {
|
||||
auto __orig_first1 = __first1;
|
||||
auto __last2 = __first2 + (__last1 - __first1);
|
||||
while (static_cast<size_t>(__last1 - __first1) >= __unroll_count * __vec_size) [[__unlikely__]] {
|
||||
__vec __lhs[__unroll_count];
|
||||
__vec __rhs[__unroll_count];
|
||||
|
||||
for (size_t __i = 0; __i != __unroll_count; ++__i) {
|
||||
__lhs[__i] = std::__load_vector<__vec>(__first1 + __i * __vec_size);
|
||||
__rhs[__i] = std::__load_vector<__vec>(__first2 + __i * __vec_size);
|
||||
}
|
||||
|
||||
for (size_t __i = 0; __i != __unroll_count; ++__i) {
|
||||
if (auto __cmp_res = __lhs[__i] == __rhs[__i]; !std::__all_of(__cmp_res)) {
|
||||
auto __offset = __i * __vec_size + std::__find_first_not_set(__cmp_res);
|
||||
return {__first1 + __offset, __first2 + __offset};
|
||||
}
|
||||
}
|
||||
|
||||
__first1 += __unroll_count * __vec_size;
|
||||
__first2 += __unroll_count * __vec_size;
|
||||
}
|
||||
|
||||
// check the remaining 0-3 vectors
|
||||
while (static_cast<size_t>(__last1 - __first1) >= __vec_size) {
|
||||
if (auto __cmp_res = std::__load_vector<__vec>(__first1) == std::__load_vector<__vec>(__first2);
|
||||
!std::__all_of(__cmp_res)) {
|
||||
auto __offset = std::__find_first_not_set(__cmp_res);
|
||||
return {__first1 + __offset, __first2 + __offset};
|
||||
}
|
||||
__first1 += __vec_size;
|
||||
__first2 += __vec_size;
|
||||
}
|
||||
|
||||
if (__last1 - __first1 == 0)
|
||||
return {__first1, __first2};
|
||||
|
||||
// Check if we can load elements in front of the current pointer. If that's the case load a vector at
|
||||
// (last - vector_size) to check the remaining elements
|
||||
if (static_cast<size_t>(__first1 - __orig_first1) >= __vec_size) {
|
||||
__first1 = __last1 - __vec_size;
|
||||
__first2 = __last2 - __vec_size;
|
||||
auto __offset =
|
||||
std::__find_first_not_set(std::__load_vector<__vec>(__first1) == std::__load_vector<__vec>(__first2));
|
||||
return {__first1 + __offset, __first2 + __offset};
|
||||
} // else loop over the elements individually
|
||||
}
|
||||
|
||||
__equal_to __pred;
|
||||
__identity __proj;
|
||||
return std::__mismatch_loop(__first1, __last1, __first2, __pred, __proj, __proj);
|
||||
}
|
||||
|
||||
template <class _Tp,
|
||||
class _Pred,
|
||||
class _Proj1,
|
||||
class _Proj2,
|
||||
__enable_if_t<is_integral<_Tp>::value && __desugars_to_v<__equal_tag, _Pred, _Tp, _Tp> &&
|
||||
__is_identity<_Proj1>::value && __is_identity<_Proj2>::value,
|
||||
int> = 0>
|
||||
_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Tp*, _Tp*>
|
||||
__mismatch(_Tp* __first1, _Tp* __last1, _Tp* __first2, _Pred&, _Proj1&, _Proj2&) {
|
||||
return std::__mismatch_vectorized(__first1, __last1, __first2);
|
||||
}
|
||||
|
||||
template <class _Tp,
|
||||
class _Pred,
|
||||
class _Proj1,
|
||||
class _Proj2,
|
||||
__enable_if_t<!is_integral<_Tp>::value && __desugars_to_v<__equal_tag, _Pred, _Tp, _Tp> &&
|
||||
__is_identity<_Proj1>::value && __is_identity<_Proj2>::value &&
|
||||
__can_map_to_integer_v<_Tp> && __libcpp_is_trivially_equality_comparable<_Tp, _Tp>::value,
|
||||
int> = 0>
|
||||
_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Tp*, _Tp*>
|
||||
__mismatch(_Tp* __first1, _Tp* __last1, _Tp* __first2, _Pred& __pred, _Proj1& __proj1, _Proj2& __proj2) {
|
||||
if (__libcpp_is_constant_evaluated()) {
|
||||
return std::__mismatch_loop(__first1, __last1, __first2, __pred, __proj1, __proj2);
|
||||
} else {
|
||||
using _Iter = __aliasing_iterator<_Tp*, __get_as_integer_type_t<_Tp>>;
|
||||
auto __ret = std::__mismatch_vectorized(_Iter(__first1), _Iter(__last1), _Iter(__first2));
|
||||
return {__ret.first.__base(), __ret.second.__base()};
|
||||
}
|
||||
}
|
||||
#endif // _LIBCPP_VECTORIZE_ALGORITHMS
|
||||
|
||||
template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2>
|
||||
mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _BinaryPredicate __pred) {
|
||||
__identity __proj;
|
||||
auto __res = std::__mismatch(
|
||||
std::__unwrap_iter(__first1), std::__unwrap_iter(__last1), std::__unwrap_iter(__first2), __pred, __proj, __proj);
|
||||
return std::make_pair(std::__rewrap_iter(__first1, __res.first), std::__rewrap_iter(__first2, __res.second));
|
||||
}
|
||||
|
||||
template <class _InputIterator1, class _InputIterator2>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY
|
||||
_LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2>
|
||||
mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2) {
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2>
|
||||
mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2) {
|
||||
return std::mismatch(__first1, __last1, __first2, __equal_to());
|
||||
}
|
||||
|
||||
#if _LIBCPP_STD_VER >= 14
|
||||
template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY
|
||||
_LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2>
|
||||
mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2,
|
||||
_BinaryPredicate __pred) {
|
||||
for (; __first1 != __last1 && __first2 != __last2; ++__first1, (void)++__first2)
|
||||
if (!__pred(*__first1, *__first2))
|
||||
template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Pred, class _Proj1, class _Proj2>
|
||||
_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Iter1, _Iter2> __mismatch(
|
||||
_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)))
|
||||
break;
|
||||
return pair<_InputIterator1, _InputIterator2>(__first1, __first2);
|
||||
++__first1;
|
||||
++__first2;
|
||||
}
|
||||
return {std::move(__first1), std::move(__first2)};
|
||||
}
|
||||
|
||||
template <class _Tp, class _Pred, class _Proj1, class _Proj2>
|
||||
_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Tp*, _Tp*>
|
||||
__mismatch(_Tp* __first1, _Tp* __last1, _Tp* __first2, _Tp* __last2, _Pred& __pred, _Proj1& __proj1, _Proj2& __proj2) {
|
||||
auto __len = std::min(__last1 - __first1, __last2 - __first2);
|
||||
return std::__mismatch(__first1, __first1 + __len, __first2, __pred, __proj1, __proj2);
|
||||
}
|
||||
|
||||
template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2>
|
||||
mismatch(_InputIterator1 __first1,
|
||||
_InputIterator1 __last1,
|
||||
_InputIterator2 __first2,
|
||||
_InputIterator2 __last2,
|
||||
_BinaryPredicate __pred) {
|
||||
__identity __proj;
|
||||
auto __res = std::__mismatch(
|
||||
std::__unwrap_iter(__first1),
|
||||
std::__unwrap_iter(__last1),
|
||||
std::__unwrap_iter(__first2),
|
||||
std::__unwrap_iter(__last2),
|
||||
__pred,
|
||||
__proj,
|
||||
__proj);
|
||||
return {std::__rewrap_iter(__first1, __res.first), std::__rewrap_iter(__first2, __res.second)};
|
||||
}
|
||||
|
||||
template <class _InputIterator1, class _InputIterator2>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY
|
||||
_LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2>
|
||||
mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) {
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2>
|
||||
mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) {
|
||||
return std::mismatch(__first1, __last1, __first2, __last2, __equal_to());
|
||||
}
|
||||
#endif
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_MISMATCH_H
|
||||
|
|
18
third_party/libcxx/__algorithm/move.h
vendored
18
third_party/libcxx/__algorithm/move.h
vendored
|
@ -16,7 +16,7 @@
|
|||
#include <__config>
|
||||
#include <__iterator/segmented_iterator.h>
|
||||
#include <__type_traits/common_type.h>
|
||||
#include <__type_traits/is_copy_constructible.h>
|
||||
#include <__type_traits/is_constructible.h>
|
||||
#include <__utility/move.h>
|
||||
#include <__utility/pair.h>
|
||||
|
||||
|
@ -34,7 +34,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIte
|
|||
__move(_InIter __first, _Sent __last, _OutIter __result);
|
||||
|
||||
template <class _AlgPolicy>
|
||||
struct __move_loop {
|
||||
struct __move_impl {
|
||||
template <class _InIter, class _Sent, class _OutIter>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter>
|
||||
operator()(_InIter __first, _Sent __last, _OutIter __result) const {
|
||||
|
@ -52,9 +52,10 @@ struct __move_loop {
|
|||
|
||||
_OutIter& __result_;
|
||||
|
||||
_LIBCPP_HIDE_FROM_ABI _MoveSegment(_OutIter& __result) : __result_(__result) {}
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit _MoveSegment(_OutIter& __result)
|
||||
: __result_(__result) {}
|
||||
|
||||
_LIBCPP_HIDE_FROM_ABI void
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
|
||||
operator()(typename _Traits::__local_iterator __lfirst, typename _Traits::__local_iterator __llast) {
|
||||
__result_ = std::__move<_AlgPolicy>(__lfirst, __llast, std::move(__result_)).second;
|
||||
}
|
||||
|
@ -73,7 +74,7 @@ struct __move_loop {
|
|||
!__is_segmented_iterator<_InIter>::value && __is_segmented_iterator<_OutIter>::value,
|
||||
int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter>
|
||||
operator()(_InIter __first, _InIter __last, _OutIter __result) {
|
||||
operator()(_InIter __first, _InIter __last, _OutIter __result) const {
|
||||
using _Traits = __segmented_iterator_traits<_OutIter>;
|
||||
using _DiffT = typename common_type<__iter_diff_t<_InIter>, __iter_diff_t<_OutIter> >::type;
|
||||
|
||||
|
@ -94,12 +95,9 @@ struct __move_loop {
|
|||
__local_first = _Traits::__begin(++__segment_iterator);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct __move_trivial {
|
||||
// At this point, the iterators have been unwrapped so any `contiguous_iterator` has been unwrapped to a pointer.
|
||||
template <class _In, class _Out,
|
||||
__enable_if_t<__can_lower_move_assignment_to_memmove<_In, _Out>::value, int> = 0>
|
||||
template <class _In, class _Out, __enable_if_t<__can_lower_move_assignment_to_memmove<_In, _Out>::value, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_In*, _Out*>
|
||||
operator()(_In* __first, _In* __last, _Out* __result) const {
|
||||
return std::__copy_trivial_impl(__first, __last, __result);
|
||||
|
@ -109,7 +107,7 @@ struct __move_trivial {
|
|||
template <class _AlgPolicy, class _InIter, class _Sent, class _OutIter>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter>
|
||||
__move(_InIter __first, _Sent __last, _OutIter __result) {
|
||||
return std::__dispatch_copy_or_move<_AlgPolicy, __move_loop<_AlgPolicy>, __move_trivial>(
|
||||
return std::__copy_move_unwrap_iters<__move_impl<_AlgPolicy> >(
|
||||
std::move(__first), std::move(__last), std::move(__result));
|
||||
}
|
||||
|
||||
|
|
18
third_party/libcxx/__algorithm/move_backward.h
vendored
18
third_party/libcxx/__algorithm/move_backward.h
vendored
|
@ -15,7 +15,7 @@
|
|||
#include <__config>
|
||||
#include <__iterator/segmented_iterator.h>
|
||||
#include <__type_traits/common_type.h>
|
||||
#include <__type_traits/is_copy_constructible.h>
|
||||
#include <__type_traits/is_constructible.h>
|
||||
#include <__utility/move.h>
|
||||
#include <__utility/pair.h>
|
||||
|
||||
|
@ -33,7 +33,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_BidirectionalIterator1
|
|||
__move_backward(_BidirectionalIterator1 __first, _Sentinel __last, _BidirectionalIterator2 __result);
|
||||
|
||||
template <class _AlgPolicy>
|
||||
struct __move_backward_loop {
|
||||
struct __move_backward_impl {
|
||||
template <class _InIter, class _Sent, class _OutIter>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter>
|
||||
operator()(_InIter __first, _Sent __last, _OutIter __result) const {
|
||||
|
@ -80,7 +80,7 @@ struct __move_backward_loop {
|
|||
!__is_segmented_iterator<_InIter>::value && __is_segmented_iterator<_OutIter>::value,
|
||||
int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter>
|
||||
operator()(_InIter __first, _InIter __last, _OutIter __result) {
|
||||
operator()(_InIter __first, _InIter __last, _OutIter __result) const {
|
||||
using _Traits = __segmented_iterator_traits<_OutIter>;
|
||||
using _DiffT = typename common_type<__iter_diff_t<_InIter>, __iter_diff_t<_OutIter> >::type;
|
||||
|
||||
|
@ -104,12 +104,9 @@ struct __move_backward_loop {
|
|||
__local_last = _Traits::__end(--__segment_iterator);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct __move_backward_trivial {
|
||||
// At this point, the iterators have been unwrapped so any `contiguous_iterator` has been unwrapped to a pointer.
|
||||
template <class _In, class _Out,
|
||||
__enable_if_t<__can_lower_move_assignment_to_memmove<_In, _Out>::value, int> = 0>
|
||||
template <class _In, class _Out, __enable_if_t<__can_lower_move_assignment_to_memmove<_In, _Out>::value, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_In*, _Out*>
|
||||
operator()(_In* __first, _In* __last, _Out* __result) const {
|
||||
return std::__copy_backward_trivial_impl(__first, __last, __result);
|
||||
|
@ -120,14 +117,15 @@ template <class _AlgPolicy, class _BidirectionalIterator1, class _Sentinel, clas
|
|||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_BidirectionalIterator1, _BidirectionalIterator2>
|
||||
__move_backward(_BidirectionalIterator1 __first, _Sentinel __last, _BidirectionalIterator2 __result) {
|
||||
static_assert(std::is_copy_constructible<_BidirectionalIterator1>::value &&
|
||||
std::is_copy_constructible<_BidirectionalIterator1>::value, "Iterators must be copy constructible.");
|
||||
std::is_copy_constructible<_BidirectionalIterator1>::value,
|
||||
"Iterators must be copy constructible.");
|
||||
|
||||
return std::__dispatch_copy_or_move<_AlgPolicy, __move_backward_loop<_AlgPolicy>, __move_backward_trivial>(
|
||||
return std::__copy_move_unwrap_iters<__move_backward_impl<_AlgPolicy> >(
|
||||
std::move(__first), std::move(__last), std::move(__result));
|
||||
}
|
||||
|
||||
template <class _BidirectionalIterator1, class _BidirectionalIterator2>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _BidirectionalIterator2
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _BidirectionalIterator2
|
||||
move_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last, _BidirectionalIterator2 __result) {
|
||||
return std::__move_backward<_ClassicAlgPolicy>(std::move(__first), std::move(__last), std::move(__result)).second;
|
||||
}
|
||||
|
|
|
@ -22,57 +22,54 @@
|
|||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_PUSH_MACROS
|
||||
#include <__undef_macros>
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _AlgPolicy, class _Compare, class _BidirectionalIterator, class _Sentinel>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_BidirectionalIterator, bool>
|
||||
__next_permutation(_BidirectionalIterator __first, _Sentinel __last, _Compare&& __comp)
|
||||
{
|
||||
using _Result = pair<_BidirectionalIterator, bool>;
|
||||
__next_permutation(_BidirectionalIterator __first, _Sentinel __last, _Compare&& __comp) {
|
||||
using _Result = pair<_BidirectionalIterator, bool>;
|
||||
|
||||
_BidirectionalIterator __last_iter = _IterOps<_AlgPolicy>::next(__first, __last);
|
||||
_BidirectionalIterator __i = __last_iter;
|
||||
if (__first == __last || __first == --__i)
|
||||
return _Result(std::move(__last_iter), false);
|
||||
_BidirectionalIterator __last_iter = _IterOps<_AlgPolicy>::next(__first, __last);
|
||||
_BidirectionalIterator __i = __last_iter;
|
||||
if (__first == __last || __first == --__i)
|
||||
return _Result(std::move(__last_iter), false);
|
||||
|
||||
while (true)
|
||||
{
|
||||
_BidirectionalIterator __ip1 = __i;
|
||||
if (__comp(*--__i, *__ip1))
|
||||
{
|
||||
_BidirectionalIterator __j = __last_iter;
|
||||
while (!__comp(*__i, *--__j))
|
||||
;
|
||||
_IterOps<_AlgPolicy>::iter_swap(__i, __j);
|
||||
std::__reverse<_AlgPolicy>(__ip1, __last_iter);
|
||||
return _Result(std::move(__last_iter), true);
|
||||
}
|
||||
if (__i == __first)
|
||||
{
|
||||
std::__reverse<_AlgPolicy>(__first, __last_iter);
|
||||
return _Result(std::move(__last_iter), false);
|
||||
}
|
||||
while (true) {
|
||||
_BidirectionalIterator __ip1 = __i;
|
||||
if (__comp(*--__i, *__ip1)) {
|
||||
_BidirectionalIterator __j = __last_iter;
|
||||
while (!__comp(*__i, *--__j))
|
||||
;
|
||||
_IterOps<_AlgPolicy>::iter_swap(__i, __j);
|
||||
std::__reverse<_AlgPolicy>(__ip1, __last_iter);
|
||||
return _Result(std::move(__last_iter), true);
|
||||
}
|
||||
if (__i == __first) {
|
||||
std::__reverse<_AlgPolicy>(__first, __last_iter);
|
||||
return _Result(std::move(__last_iter), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class _BidirectionalIterator, class _Compare>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
bool
|
||||
next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp)
|
||||
{
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
|
||||
next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) {
|
||||
return std::__next_permutation<_ClassicAlgPolicy>(
|
||||
std::move(__first), std::move(__last), static_cast<__comp_ref_type<_Compare> >(__comp)).second;
|
||||
std::move(__first), std::move(__last), static_cast<__comp_ref_type<_Compare> >(__comp))
|
||||
.second;
|
||||
}
|
||||
|
||||
template <class _BidirectionalIterator>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
bool
|
||||
next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last)
|
||||
{
|
||||
return _VSTD::next_permutation(__first, __last,
|
||||
__less<typename iterator_traits<_BidirectionalIterator>::value_type>());
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
|
||||
next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last) {
|
||||
return std::next_permutation(__first, __last, __less<>());
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_NEXT_PERMUTATION_H
|
||||
|
|
2
third_party/libcxx/__algorithm/none_of.h
vendored
2
third_party/libcxx/__algorithm/none_of.h
vendored
|
@ -19,7 +19,7 @@
|
|||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _InputIterator, class _Predicate>
|
||||
_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
|
||||
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
|
||||
none_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
|
||||
for (; __first != __last; ++__first)
|
||||
if (__pred(*__first))
|
||||
|
|
401
third_party/libcxx/__algorithm/nth_element.h
vendored
401
third_party/libcxx/__algorithm/nth_element.h
vendored
|
@ -13,8 +13,8 @@
|
|||
#include <__algorithm/comp_ref_type.h>
|
||||
#include <__algorithm/iterator_operations.h>
|
||||
#include <__algorithm/sort.h>
|
||||
#include <__assert>
|
||||
#include <__config>
|
||||
#include <__debug>
|
||||
#include <__debug_utils/randomize_range.h>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__utility/move.h>
|
||||
|
@ -23,209 +23,212 @@
|
|||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_PUSH_MACROS
|
||||
#include <__undef_macros>
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template<class _Compare, class _RandomAccessIterator>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
|
||||
__nth_element_find_guard(_RandomAccessIterator& __i, _RandomAccessIterator& __j,
|
||||
_RandomAccessIterator __m, _Compare __comp)
|
||||
{
|
||||
// manually guard downward moving __j against __i
|
||||
while (true) {
|
||||
if (__i == --__j) {
|
||||
return false;
|
||||
}
|
||||
if (__comp(*__j, *__m)) {
|
||||
return true; // found guard for downward moving __j, now use unguarded partition
|
||||
}
|
||||
template <class _Compare, class _RandomAccessIterator>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool __nth_element_find_guard(
|
||||
_RandomAccessIterator& __i, _RandomAccessIterator& __j, _RandomAccessIterator __m, _Compare __comp) {
|
||||
// manually guard downward moving __j against __i
|
||||
while (true) {
|
||||
if (__i == --__j) {
|
||||
return false;
|
||||
}
|
||||
if (__comp(*__j, *__m)) {
|
||||
return true; // found guard for downward moving __j, now use unguarded partition
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
|
||||
__nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare __comp)
|
||||
{
|
||||
using _Ops = _IterOps<_AlgPolicy>;
|
||||
// NOLINTNEXTLINE(readability-function-cognitive-complexity)
|
||||
__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;
|
||||
while (true)
|
||||
{
|
||||
if (__nth == __last)
|
||||
return;
|
||||
difference_type __len = __last - __first;
|
||||
switch (__len)
|
||||
{
|
||||
case 0:
|
||||
case 1:
|
||||
return;
|
||||
case 2:
|
||||
if (__comp(*--__last, *__first))
|
||||
_Ops::iter_swap(__first, __last);
|
||||
return;
|
||||
case 3:
|
||||
{
|
||||
_RandomAccessIterator __m = __first;
|
||||
std::__sort3<_AlgPolicy, _Compare>(__first, ++__m, --__last, __comp);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (__len <= __limit)
|
||||
{
|
||||
std::__selection_sort<_AlgPolicy, _Compare>(__first, __last, __comp);
|
||||
return;
|
||||
}
|
||||
// __len > __limit >= 3
|
||||
_RandomAccessIterator __m = __first + __len/2;
|
||||
_RandomAccessIterator __lm1 = __last;
|
||||
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)
|
||||
_RandomAccessIterator __i = __first;
|
||||
_RandomAccessIterator __j = __lm1;
|
||||
// j points beyond range to be tested, *__lm1 is known to be <= *__m
|
||||
// The search going up is known to be guarded but the search coming down isn't.
|
||||
// Prime the downward search with a guard.
|
||||
if (!__comp(*__i, *__m)) // if *__first == *__m
|
||||
{
|
||||
// *__first == *__m, *__first doesn't go in first part
|
||||
if (_VSTD::__nth_element_find_guard<_Compare>(__i, __j, __m, __comp)) {
|
||||
_Ops::iter_swap(__i, __j);
|
||||
++__n_swaps;
|
||||
} else {
|
||||
// *__first == *__m, *__m <= all other elements
|
||||
// Partition instead into [__first, __i) == *__first and *__first < [__i, __last)
|
||||
++__i; // __first + 1
|
||||
__j = __last;
|
||||
if (!__comp(*__first, *--__j)) { // we need a guard if *__first == *(__last-1)
|
||||
while (true) {
|
||||
if (__i == __j) {
|
||||
return; // [__first, __last) all equivalent elements
|
||||
} else if (__comp(*__first, *__i)) {
|
||||
_Ops::iter_swap(__i, __j);
|
||||
++__n_swaps;
|
||||
++__i;
|
||||
break;
|
||||
}
|
||||
++__i;
|
||||
}
|
||||
}
|
||||
// [__first, __i) == *__first and *__first < [__j, __last) and __j == __last - 1
|
||||
if (__i == __j) {
|
||||
return;
|
||||
}
|
||||
while (true) {
|
||||
while (!__comp(*__first, *__i))
|
||||
++__i;
|
||||
while (__comp(*__first, *--__j))
|
||||
;
|
||||
if (__i >= __j)
|
||||
break;
|
||||
_Ops::iter_swap(__i, __j);
|
||||
++__n_swaps;
|
||||
++__i;
|
||||
}
|
||||
// [__first, __i) == *__first and *__first < [__i, __last)
|
||||
// The first part is sorted,
|
||||
if (__nth < __i) {
|
||||
return;
|
||||
}
|
||||
// __nth_element the second part
|
||||
// _VSTD::__nth_element<_Compare>(__i, __nth, __last, __comp);
|
||||
__first = __i;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
++__i;
|
||||
// j points beyond range to be tested, *__lm1 is known to be <= *__m
|
||||
// if not yet partitioned...
|
||||
if (__i < __j)
|
||||
{
|
||||
// known that *(__i - 1) < *__m
|
||||
while (true)
|
||||
{
|
||||
// __m still guards upward moving __i
|
||||
while (__comp(*__i, *__m))
|
||||
++__i;
|
||||
// It is now known that a guard exists for downward moving __j
|
||||
while (!__comp(*--__j, *__m))
|
||||
;
|
||||
if (__i >= __j)
|
||||
break;
|
||||
_Ops::iter_swap(__i, __j);
|
||||
++__n_swaps;
|
||||
// It is known that __m != __j
|
||||
// If __m just moved, follow it
|
||||
if (__m == __i)
|
||||
__m = __j;
|
||||
++__i;
|
||||
}
|
||||
}
|
||||
// [__first, __i) < *__m and *__m <= [__i, __last)
|
||||
if (__i != __m && __comp(*__m, *__i))
|
||||
{
|
||||
_Ops::iter_swap(__i, __m);
|
||||
++__n_swaps;
|
||||
}
|
||||
// [__first, __i) < *__i and *__i <= [__i+1, __last)
|
||||
if (__nth == __i)
|
||||
return;
|
||||
if (__n_swaps == 0)
|
||||
{
|
||||
// We were given a perfectly partitioned sequence. Coincidence?
|
||||
if (__nth < __i)
|
||||
{
|
||||
// Check for [__first, __i) already sorted
|
||||
__j = __m = __first;
|
||||
while (true) {
|
||||
if (++__j == __i) {
|
||||
// [__first, __i) sorted
|
||||
return;
|
||||
}
|
||||
if (__comp(*__j, *__m)) {
|
||||
// not yet sorted, so sort
|
||||
break;
|
||||
}
|
||||
__m = __j;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Check for [__i, __last) already sorted
|
||||
__j = __m = __i;
|
||||
while (true) {
|
||||
if (++__j == __last) {
|
||||
// [__i, __last) sorted
|
||||
return;
|
||||
}
|
||||
if (__comp(*__j, *__m)) {
|
||||
// not yet sorted, so sort
|
||||
break;
|
||||
}
|
||||
__m = __j;
|
||||
}
|
||||
}
|
||||
}
|
||||
// __nth_element on range containing __nth
|
||||
if (__nth < __i)
|
||||
{
|
||||
// _VSTD::__nth_element<_Compare>(__first, __nth, __i, __comp);
|
||||
__last = __i;
|
||||
}
|
||||
else
|
||||
{
|
||||
// _VSTD::__nth_element<_Compare>(__i+1, __nth, __last, __comp);
|
||||
__first = ++__i;
|
||||
}
|
||||
// _Compare is known to be a reference type
|
||||
typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
|
||||
const difference_type __limit = 7;
|
||||
while (true) {
|
||||
if (__nth == __last)
|
||||
return;
|
||||
difference_type __len = __last - __first;
|
||||
switch (__len) {
|
||||
case 0:
|
||||
case 1:
|
||||
return;
|
||||
case 2:
|
||||
if (__comp(*--__last, *__first))
|
||||
_Ops::iter_swap(__first, __last);
|
||||
return;
|
||||
case 3: {
|
||||
_RandomAccessIterator __m = __first;
|
||||
std::__sort3<_AlgPolicy, _Compare>(__first, ++__m, --__last, __comp);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (__len <= __limit) {
|
||||
std::__selection_sort<_AlgPolicy, _Compare>(__first, __last, __comp);
|
||||
return;
|
||||
}
|
||||
// __len > __limit >= 3
|
||||
_RandomAccessIterator __m = __first + __len / 2;
|
||||
_RandomAccessIterator __lm1 = __last;
|
||||
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)
|
||||
_RandomAccessIterator __i = __first;
|
||||
_RandomAccessIterator __j = __lm1;
|
||||
// j points beyond range to be tested, *__lm1 is known to be <= *__m
|
||||
// The search going up is known to be guarded but the search coming down isn't.
|
||||
// Prime the downward search with a guard.
|
||||
if (!__comp(*__i, *__m)) // if *__first == *__m
|
||||
{
|
||||
// *__first == *__m, *__first doesn't go in first part
|
||||
if (std::__nth_element_find_guard<_Compare>(__i, __j, __m, __comp)) {
|
||||
_Ops::iter_swap(__i, __j);
|
||||
++__n_swaps;
|
||||
} else {
|
||||
// *__first == *__m, *__m <= all other elements
|
||||
// Partition instead into [__first, __i) == *__first and *__first < [__i, __last)
|
||||
++__i; // __first + 1
|
||||
__j = __last;
|
||||
if (!__comp(*__first, *--__j)) { // we need a guard if *__first == *(__last-1)
|
||||
while (true) {
|
||||
if (__i == __j) {
|
||||
return; // [__first, __last) all equivalent elements
|
||||
} else if (__comp(*__first, *__i)) {
|
||||
_Ops::iter_swap(__i, __j);
|
||||
++__n_swaps;
|
||||
++__i;
|
||||
break;
|
||||
}
|
||||
++__i;
|
||||
}
|
||||
}
|
||||
// [__first, __i) == *__first and *__first < [__j, __last) and __j == __last - 1
|
||||
if (__i == __j) {
|
||||
return;
|
||||
}
|
||||
while (true) {
|
||||
while (!__comp(*__first, *__i)) {
|
||||
++__i;
|
||||
_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
|
||||
__i != __last,
|
||||
"Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?");
|
||||
}
|
||||
do {
|
||||
_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
|
||||
__j != __first,
|
||||
"Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?");
|
||||
--__j;
|
||||
} while (__comp(*__first, *__j));
|
||||
if (__i >= __j)
|
||||
break;
|
||||
_Ops::iter_swap(__i, __j);
|
||||
++__n_swaps;
|
||||
++__i;
|
||||
}
|
||||
// [__first, __i) == *__first and *__first < [__i, __last)
|
||||
// The first part is sorted,
|
||||
if (__nth < __i) {
|
||||
return;
|
||||
}
|
||||
// __nth_element the second part
|
||||
// std::__nth_element<_Compare>(__i, __nth, __last, __comp);
|
||||
__first = __i;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
++__i;
|
||||
// j points beyond range to be tested, *__lm1 is known to be <= *__m
|
||||
// if not yet partitioned...
|
||||
if (__i < __j) {
|
||||
// known that *(__i - 1) < *__m
|
||||
while (true) {
|
||||
// __m still guards upward moving __i
|
||||
while (__comp(*__i, *__m)) {
|
||||
++__i;
|
||||
_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
|
||||
__i != __last,
|
||||
"Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?");
|
||||
}
|
||||
// It is now known that a guard exists for downward moving __j
|
||||
do {
|
||||
_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
|
||||
__j != __first,
|
||||
"Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?");
|
||||
--__j;
|
||||
} while (!__comp(*__j, *__m));
|
||||
if (__i >= __j)
|
||||
break;
|
||||
_Ops::iter_swap(__i, __j);
|
||||
++__n_swaps;
|
||||
// It is known that __m != __j
|
||||
// If __m just moved, follow it
|
||||
if (__m == __i)
|
||||
__m = __j;
|
||||
++__i;
|
||||
}
|
||||
}
|
||||
// [__first, __i) < *__m and *__m <= [__i, __last)
|
||||
if (__i != __m && __comp(*__m, *__i)) {
|
||||
_Ops::iter_swap(__i, __m);
|
||||
++__n_swaps;
|
||||
}
|
||||
// [__first, __i) < *__i and *__i <= [__i+1, __last)
|
||||
if (__nth == __i)
|
||||
return;
|
||||
if (__n_swaps == 0) {
|
||||
// We were given a perfectly partitioned sequence. Coincidence?
|
||||
if (__nth < __i) {
|
||||
// Check for [__first, __i) already sorted
|
||||
__j = __m = __first;
|
||||
while (true) {
|
||||
if (++__j == __i) {
|
||||
// [__first, __i) sorted
|
||||
return;
|
||||
}
|
||||
if (__comp(*__j, *__m)) {
|
||||
// not yet sorted, so sort
|
||||
break;
|
||||
}
|
||||
__m = __j;
|
||||
}
|
||||
} else {
|
||||
// Check for [__i, __last) already sorted
|
||||
__j = __m = __i;
|
||||
while (true) {
|
||||
if (++__j == __last) {
|
||||
// [__i, __last) sorted
|
||||
return;
|
||||
}
|
||||
if (__comp(*__j, *__m)) {
|
||||
// not yet sorted, so sort
|
||||
break;
|
||||
}
|
||||
__m = __j;
|
||||
}
|
||||
}
|
||||
}
|
||||
// __nth_element on range containing __nth
|
||||
if (__nth < __i) {
|
||||
// std::__nth_element<_Compare>(__first, __nth, __i, __comp);
|
||||
__last = __i;
|
||||
} else {
|
||||
// std::__nth_element<_Compare>(__i+1, __nth, __last, __comp);
|
||||
__first = ++__i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class _AlgPolicy, class _RandomAccessIterator, class _Compare>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
void __nth_element_impl(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last,
|
||||
_Compare& __comp) {
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __nth_element_impl(
|
||||
_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare& __comp) {
|
||||
if (__nth == __last)
|
||||
return;
|
||||
|
||||
|
@ -240,19 +243,19 @@ void __nth_element_impl(_RandomAccessIterator __first, _RandomAccessIterator __n
|
|||
}
|
||||
|
||||
template <class _RandomAccessIterator, class _Compare>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
void nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last,
|
||||
_Compare __comp) {
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 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_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
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>());
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
|
||||
nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last) {
|
||||
std::nth_element(std::move(__first), std::move(__nth), std::move(__last), __less<>());
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_NTH_ELEMENT_H
|
||||
|
|
50
third_party/libcxx/__algorithm/partial_sort.h
vendored
50
third_party/libcxx/__algorithm/partial_sort.h
vendored
|
@ -16,22 +16,23 @@
|
|||
#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 <__type_traits/is_copy_assignable.h>
|
||||
#include <__type_traits/is_copy_constructible.h>
|
||||
#include <__type_traits/is_assignable.h>
|
||||
#include <__type_traits/is_constructible.h>
|
||||
#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
|
||||
|
||||
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator, class _Sentinel>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
_RandomAccessIterator __partial_sort_impl(
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator __partial_sort_impl(
|
||||
_RandomAccessIterator __first, _RandomAccessIterator __middle, _Sentinel __last, _Compare&& __comp) {
|
||||
if (__first == __middle) {
|
||||
return _IterOps<_AlgPolicy>::next(__middle, __last);
|
||||
|
@ -40,14 +41,12 @@ _RandomAccessIterator __partial_sort_impl(
|
|||
std::__make_heap<_AlgPolicy>(__first, __middle, __comp);
|
||||
|
||||
typename iterator_traits<_RandomAccessIterator>::difference_type __len = __middle - __first;
|
||||
_RandomAccessIterator __i = __middle;
|
||||
for (; __i != __last; ++__i)
|
||||
{
|
||||
if (__comp(*__i, *__first))
|
||||
{
|
||||
_IterOps<_AlgPolicy>::iter_swap(__i, __first);
|
||||
std::__sift_down<_AlgPolicy>(__first, __comp, __len, __first);
|
||||
}
|
||||
_RandomAccessIterator __i = __middle;
|
||||
for (; __i != __last; ++__i) {
|
||||
if (__comp(*__i, *__first)) {
|
||||
_IterOps<_AlgPolicy>::iter_swap(__i, __first);
|
||||
std::__sift_down<_AlgPolicy>(__first, __comp, __len, __first);
|
||||
}
|
||||
}
|
||||
std::__sort_heap<_AlgPolicy>(std::move(__first), std::move(__middle), __comp);
|
||||
|
||||
|
@ -55,11 +54,10 @@ _RandomAccessIterator __partial_sort_impl(
|
|||
}
|
||||
|
||||
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator, class _Sentinel>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
_RandomAccessIterator __partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _Sentinel __last,
|
||||
_Compare& __comp) {
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator
|
||||
__partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _Sentinel __last, _Compare& __comp) {
|
||||
if (__first == __middle)
|
||||
return _IterOps<_AlgPolicy>::next(__middle, __last);
|
||||
return _IterOps<_AlgPolicy>::next(__middle, __last);
|
||||
|
||||
std::__debug_randomize_range<_AlgPolicy>(__first, __last);
|
||||
|
||||
|
@ -72,11 +70,8 @@ _RandomAccessIterator __partial_sort(_RandomAccessIterator __first, _RandomAcces
|
|||
}
|
||||
|
||||
template <class _RandomAccessIterator, class _Compare>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
void
|
||||
partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last,
|
||||
_Compare __comp)
|
||||
{
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void partial_sort(
|
||||
_RandomAccessIterator __first, _RandomAccessIterator __middle, _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.");
|
||||
|
||||
|
@ -84,14 +79,13 @@ partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _Ran
|
|||
}
|
||||
|
||||
template <class _RandomAccessIterator>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
void
|
||||
partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last)
|
||||
{
|
||||
_VSTD::partial_sort(__first, __middle, __last,
|
||||
__less<typename iterator_traits<_RandomAccessIterator>::value_type>());
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
|
||||
partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last) {
|
||||
std::partial_sort(__first, __middle, __last, __less<>());
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_PARTIAL_SORT_H
|
||||
|
|
100
third_party/libcxx/__algorithm/partial_sort_copy.h
vendored
100
third_party/libcxx/__algorithm/partial_sort_copy.h
vendored
|
@ -28,61 +28,79 @@
|
|||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_PUSH_MACROS
|
||||
#include <__undef_macros>
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _AlgPolicy, class _Compare,
|
||||
class _InputIterator, class _Sentinel1, class _RandomAccessIterator, class _Sentinel2,
|
||||
class _Proj1, class _Proj2>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 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);
|
||||
template <class _AlgPolicy,
|
||||
class _Compare,
|
||||
class _InputIterator,
|
||||
class _Sentinel1,
|
||||
class _RandomAccessIterator,
|
||||
class _Sentinel2,
|
||||
class _Proj1,
|
||||
class _Proj2>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 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;
|
||||
std::__make_heap<_AlgPolicy>(__result_first, __r, __projected_comp);
|
||||
typename iterator_traits<_RandomAccessIterator>::difference_type __len = __r - __result_first;
|
||||
for (; __first != __last; ++__first)
|
||||
if (std::__invoke(__comp, std::__invoke(__proj1, *__first), std::__invoke(__proj2, *__result_first))) {
|
||||
*__result_first = *__first;
|
||||
std::__sift_down<_AlgPolicy>(__result_first, __projected_comp, __len, __result_first);
|
||||
}
|
||||
std::__sort_heap<_AlgPolicy>(__result_first, __r, __projected_comp);
|
||||
}
|
||||
if (__r != __result_last) {
|
||||
for (; __first != __last && __r != __result_last; ++__first, (void)++__r)
|
||||
*__r = *__first;
|
||||
std::__make_heap<_AlgPolicy>(__result_first, __r, __projected_comp);
|
||||
typename iterator_traits<_RandomAccessIterator>::difference_type __len = __r - __result_first;
|
||||
for (; __first != __last; ++__first)
|
||||
if (std::__invoke(__comp, std::__invoke(__proj1, *__first), std::__invoke(__proj2, *__result_first))) {
|
||||
*__result_first = *__first;
|
||||
std::__sift_down<_AlgPolicy>(__result_first, __projected_comp, __len, __result_first);
|
||||
}
|
||||
std::__sort_heap<_AlgPolicy>(__result_first, __r, __projected_comp);
|
||||
}
|
||||
|
||||
return pair<_InputIterator, _RandomAccessIterator>(
|
||||
_IterOps<_AlgPolicy>::next(std::move(__first), std::move(__last)), std::move(__r));
|
||||
return pair<_InputIterator, _RandomAccessIterator>(
|
||||
_IterOps<_AlgPolicy>::next(std::move(__first), std::move(__last)), std::move(__r));
|
||||
}
|
||||
|
||||
template <class _InputIterator, class _RandomAccessIterator, class _Compare>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
_RandomAccessIterator
|
||||
partial_sort_copy(_InputIterator __first, _InputIterator __last,
|
||||
_RandomAccessIterator __result_first, _RandomAccessIterator __result_last, _Compare __comp)
|
||||
{
|
||||
static_assert(__is_callable<_Compare, decltype(*__first), decltype(*__result_first)>::value,
|
||||
"Comparator has to be callable");
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator partial_sort_copy(
|
||||
_InputIterator __first,
|
||||
_InputIterator __last,
|
||||
_RandomAccessIterator __result_first,
|
||||
_RandomAccessIterator __result_last,
|
||||
_Compare __comp) {
|
||||
static_assert(
|
||||
__is_callable<_Compare, decltype(*__first), decltype(*__result_first)>::value, "Comparator has to be callable");
|
||||
|
||||
auto __result = std::__partial_sort_copy<_ClassicAlgPolicy>(__first, __last, __result_first, __result_last,
|
||||
static_cast<__comp_ref_type<_Compare> >(__comp), __identity(), __identity());
|
||||
auto __result = std::__partial_sort_copy<_ClassicAlgPolicy>(
|
||||
__first,
|
||||
__last,
|
||||
__result_first,
|
||||
__result_last,
|
||||
static_cast<__comp_ref_type<_Compare> >(__comp),
|
||||
__identity(),
|
||||
__identity());
|
||||
return __result.second;
|
||||
}
|
||||
|
||||
template <class _InputIterator, class _RandomAccessIterator>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
_RandomAccessIterator
|
||||
partial_sort_copy(_InputIterator __first, _InputIterator __last,
|
||||
_RandomAccessIterator __result_first, _RandomAccessIterator __result_last)
|
||||
{
|
||||
return _VSTD::partial_sort_copy(__first, __last, __result_first, __result_last,
|
||||
__less<typename iterator_traits<_RandomAccessIterator>::value_type>());
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator partial_sort_copy(
|
||||
_InputIterator __first,
|
||||
_InputIterator __last,
|
||||
_RandomAccessIterator __result_first,
|
||||
_RandomAccessIterator __result_last) {
|
||||
return std::partial_sort_copy(__first, __last, __result_first, __result_last, __less<>());
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_PARTIAL_SORT_COPY_H
|
||||
|
|
89
third_party/libcxx/__algorithm/partition.h
vendored
89
third_party/libcxx/__algorithm/partition.h
vendored
|
@ -19,74 +19,65 @@
|
|||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_PUSH_MACROS
|
||||
#include <__undef_macros>
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _Predicate, class _AlgPolicy, class _ForwardIterator, class _Sentinel>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator, _ForwardIterator>
|
||||
__partition_impl(_ForwardIterator __first, _Sentinel __last, _Predicate __pred, forward_iterator_tag)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (__first == __last)
|
||||
return std::make_pair(std::move(__first), std::move(__first));
|
||||
if (!__pred(*__first))
|
||||
break;
|
||||
++__first;
|
||||
}
|
||||
__partition_impl(_ForwardIterator __first, _Sentinel __last, _Predicate __pred, forward_iterator_tag) {
|
||||
while (true) {
|
||||
if (__first == __last)
|
||||
return std::make_pair(std::move(__first), std::move(__first));
|
||||
if (!__pred(*__first))
|
||||
break;
|
||||
++__first;
|
||||
}
|
||||
|
||||
_ForwardIterator __p = __first;
|
||||
while (++__p != __last)
|
||||
{
|
||||
if (__pred(*__p))
|
||||
{
|
||||
_IterOps<_AlgPolicy>::iter_swap(__first, __p);
|
||||
++__first;
|
||||
}
|
||||
_ForwardIterator __p = __first;
|
||||
while (++__p != __last) {
|
||||
if (__pred(*__p)) {
|
||||
_IterOps<_AlgPolicy>::iter_swap(__first, __p);
|
||||
++__first;
|
||||
}
|
||||
return std::make_pair(std::move(__first), std::move(__p));
|
||||
}
|
||||
return std::make_pair(std::move(__first), std::move(__p));
|
||||
}
|
||||
|
||||
template <class _Predicate, class _AlgPolicy, class _BidirectionalIterator, class _Sentinel>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 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;
|
||||
__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 std::make_pair(std::move(__first), std::move(__original_last));
|
||||
if (!__pred(*__first))
|
||||
break;
|
||||
++__first;
|
||||
}
|
||||
do
|
||||
{
|
||||
if (__first == --__last)
|
||||
return std::make_pair(std::move(__first), std::move(__original_last));
|
||||
} while (!__pred(*__last));
|
||||
_IterOps<_AlgPolicy>::iter_swap(__first, __last);
|
||||
++__first;
|
||||
while (true) {
|
||||
while (true) {
|
||||
if (__first == __last)
|
||||
return std::make_pair(std::move(__first), std::move(__original_last));
|
||||
if (!__pred(*__first))
|
||||
break;
|
||||
++__first;
|
||||
}
|
||||
do {
|
||||
if (__first == --__last)
|
||||
return std::make_pair(std::move(__first), std::move(__original_last));
|
||||
} while (!__pred(*__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_SINCE_CXX20
|
||||
pair<_ForwardIterator, _ForwardIterator> __partition(
|
||||
_ForwardIterator __first, _Sentinel __last, _Predicate&& __pred, _IterCategory __iter_category) {
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator, _ForwardIterator>
|
||||
__partition(_ForwardIterator __first, _Sentinel __last, _Predicate&& __pred, _IterCategory __iter_category) {
|
||||
return std::__partition_impl<__remove_cvref_t<_Predicate>&, _AlgPolicy>(
|
||||
std::move(__first), std::move(__last), __pred, __iter_category);
|
||||
}
|
||||
|
||||
template <class _ForwardIterator, class _Predicate>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
_ForwardIterator
|
||||
partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
|
||||
{
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
|
||||
partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
|
||||
using _IterCategory = typename iterator_traits<_ForwardIterator>::iterator_category;
|
||||
auto __result = std::__partition<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __pred, _IterCategory());
|
||||
return __result.first;
|
||||
|
@ -94,4 +85,6 @@ partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
|
|||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_PARTITION_H
|
||||
|
|
36
third_party/libcxx/__algorithm/partition_copy.h
vendored
36
third_party/libcxx/__algorithm/partition_copy.h
vendored
|
@ -19,27 +19,23 @@
|
|||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _InputIterator, class _OutputIterator1,
|
||||
class _OutputIterator2, class _Predicate>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_OutputIterator1, _OutputIterator2>
|
||||
partition_copy(_InputIterator __first, _InputIterator __last,
|
||||
_OutputIterator1 __out_true, _OutputIterator2 __out_false,
|
||||
_Predicate __pred)
|
||||
{
|
||||
for (; __first != __last; ++__first)
|
||||
{
|
||||
if (__pred(*__first))
|
||||
{
|
||||
*__out_true = *__first;
|
||||
++__out_true;
|
||||
}
|
||||
else
|
||||
{
|
||||
*__out_false = *__first;
|
||||
++__out_false;
|
||||
}
|
||||
template <class _InputIterator, class _OutputIterator1, class _OutputIterator2, class _Predicate>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_OutputIterator1, _OutputIterator2> partition_copy(
|
||||
_InputIterator __first,
|
||||
_InputIterator __last,
|
||||
_OutputIterator1 __out_true,
|
||||
_OutputIterator2 __out_false,
|
||||
_Predicate __pred) {
|
||||
for (; __first != __last; ++__first) {
|
||||
if (__pred(*__first)) {
|
||||
*__out_true = *__first;
|
||||
++__out_true;
|
||||
} else {
|
||||
*__out_false = *__first;
|
||||
++__out_false;
|
||||
}
|
||||
return pair<_OutputIterator1, _OutputIterator2>(__out_true, __out_false);
|
||||
}
|
||||
return pair<_OutputIterator1, _OutputIterator2>(__out_true, __out_false);
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
|
34
third_party/libcxx/__algorithm/partition_point.h
vendored
34
third_party/libcxx/__algorithm/partition_point.h
vendored
|
@ -21,26 +21,22 @@
|
|||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template<class _ForwardIterator, class _Predicate>
|
||||
template <class _ForwardIterator, class _Predicate>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
|
||||
partition_point(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
|
||||
{
|
||||
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 (__pred(*__m))
|
||||
{
|
||||
__first = ++__m;
|
||||
__len -= __l2 + 1;
|
||||
}
|
||||
else
|
||||
__len = __l2;
|
||||
}
|
||||
return __first;
|
||||
partition_point(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
|
||||
typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type;
|
||||
difference_type __len = std::distance(__first, __last);
|
||||
while (__len != 0) {
|
||||
difference_type __l2 = std::__half_positive(__len);
|
||||
_ForwardIterator __m = __first;
|
||||
std::advance(__m, __l2);
|
||||
if (__pred(*__m)) {
|
||||
__first = ++__m;
|
||||
__len -= __l2 + 1;
|
||||
} else
|
||||
__len = __l2;
|
||||
}
|
||||
return __first;
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
|
33
third_party/libcxx/__algorithm/pop_heap.h
vendored
33
third_party/libcxx/__algorithm/pop_heap.h
vendored
|
@ -17,27 +17,33 @@
|
|||
#include <__assert>
|
||||
#include <__config>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__type_traits/is_copy_assignable.h>
|
||||
#include <__type_traits/is_copy_constructible.h>
|
||||
#include <__type_traits/is_assignable.h>
|
||||
#include <__type_traits/is_constructible.h>
|
||||
#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
|
||||
|
||||
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
|
||||
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");
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
|
||||
__pop_heap(_RandomAccessIterator __first,
|
||||
_RandomAccessIterator __last,
|
||||
_Compare& __comp,
|
||||
typename iterator_traits<_RandomAccessIterator>::difference_type __len) {
|
||||
// Calling `pop_heap` on an empty range is undefined behavior, but in practice it will be a no-op.
|
||||
_LIBCPP_ASSERT_PEDANTIC(__len > 0, "The heap given to pop_heap must be non-empty");
|
||||
|
||||
__comp_ref_type<_Compare> __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
|
||||
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;
|
||||
|
||||
|
@ -53,8 +59,8 @@ void __pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Co
|
|||
}
|
||||
|
||||
template <class _RandomAccessIterator, class _Compare>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
void pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) {
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 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.");
|
||||
|
||||
|
@ -63,12 +69,13 @@ void pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp
|
|||
}
|
||||
|
||||
template <class _RandomAccessIterator>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
void pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) {
|
||||
std::pop_heap(std::move(__first), std::move(__last),
|
||||
__less<typename iterator_traits<_RandomAccessIterator>::value_type>());
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
|
||||
pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) {
|
||||
std::pop_heap(std::move(__first), std::move(__last), __less<>());
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_POP_HEAP_H
|
||||
|
|
|
@ -22,58 +22,54 @@
|
|||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_PUSH_MACROS
|
||||
#include <__undef_macros>
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _AlgPolicy, class _Compare, class _BidirectionalIterator, class _Sentinel>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
pair<_BidirectionalIterator, bool>
|
||||
__prev_permutation(_BidirectionalIterator __first, _Sentinel __last, _Compare&& __comp)
|
||||
{
|
||||
using _Result = pair<_BidirectionalIterator, bool>;
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_BidirectionalIterator, bool>
|
||||
__prev_permutation(_BidirectionalIterator __first, _Sentinel __last, _Compare&& __comp) {
|
||||
using _Result = pair<_BidirectionalIterator, bool>;
|
||||
|
||||
_BidirectionalIterator __last_iter = _IterOps<_AlgPolicy>::next(__first, __last);
|
||||
_BidirectionalIterator __i = __last_iter;
|
||||
if (__first == __last || __first == --__i)
|
||||
return _Result(std::move(__last_iter), false);
|
||||
_BidirectionalIterator __last_iter = _IterOps<_AlgPolicy>::next(__first, __last);
|
||||
_BidirectionalIterator __i = __last_iter;
|
||||
if (__first == __last || __first == --__i)
|
||||
return _Result(std::move(__last_iter), false);
|
||||
|
||||
while (true)
|
||||
{
|
||||
_BidirectionalIterator __ip1 = __i;
|
||||
if (__comp(*__ip1, *--__i))
|
||||
{
|
||||
_BidirectionalIterator __j = __last_iter;
|
||||
while (!__comp(*--__j, *__i))
|
||||
;
|
||||
_IterOps<_AlgPolicy>::iter_swap(__i, __j);
|
||||
std::__reverse<_AlgPolicy>(__ip1, __last_iter);
|
||||
return _Result(std::move(__last_iter), true);
|
||||
}
|
||||
if (__i == __first)
|
||||
{
|
||||
std::__reverse<_AlgPolicy>(__first, __last_iter);
|
||||
return _Result(std::move(__last_iter), false);
|
||||
}
|
||||
while (true) {
|
||||
_BidirectionalIterator __ip1 = __i;
|
||||
if (__comp(*__ip1, *--__i)) {
|
||||
_BidirectionalIterator __j = __last_iter;
|
||||
while (!__comp(*--__j, *__i))
|
||||
;
|
||||
_IterOps<_AlgPolicy>::iter_swap(__i, __j);
|
||||
std::__reverse<_AlgPolicy>(__ip1, __last_iter);
|
||||
return _Result(std::move(__last_iter), true);
|
||||
}
|
||||
if (__i == __first) {
|
||||
std::__reverse<_AlgPolicy>(__first, __last_iter);
|
||||
return _Result(std::move(__last_iter), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class _BidirectionalIterator, class _Compare>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
bool
|
||||
prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp)
|
||||
{
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
|
||||
prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) {
|
||||
return std::__prev_permutation<_ClassicAlgPolicy>(
|
||||
std::move(__first), std::move(__last), static_cast<__comp_ref_type<_Compare> >(__comp)).second;
|
||||
std::move(__first), std::move(__last), static_cast<__comp_ref_type<_Compare> >(__comp))
|
||||
.second;
|
||||
}
|
||||
|
||||
template <class _BidirectionalIterator>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
bool
|
||||
prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last)
|
||||
{
|
||||
return _VSTD::prev_permutation(__first, __last,
|
||||
__less<typename iterator_traits<_BidirectionalIterator>::value_type>());
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
|
||||
prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last) {
|
||||
return std::prev_permutation(__first, __last, __less<>());
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_PREV_PERMUTATION_H
|
||||
|
|
663
third_party/libcxx/__algorithm/pstl.h
vendored
Normal file
663
third_party/libcxx/__algorithm/pstl.h
vendored
Normal file
|
@ -0,0 +1,663 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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_PSTL_H
|
||||
#define _LIBCPP___ALGORITHM_PSTL_H
|
||||
|
||||
#include <__config>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_PUSH_MACROS
|
||||
#include <__undef_macros>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
# include <__functional/operations.h>
|
||||
# include <__iterator/cpp17_iterator_concepts.h>
|
||||
# include <__iterator/iterator_traits.h>
|
||||
# include <__pstl/backend.h>
|
||||
# include <__pstl/dispatch.h>
|
||||
# include <__pstl/handle_exception.h>
|
||||
# include <__type_traits/enable_if.h>
|
||||
# include <__type_traits/is_execution_policy.h>
|
||||
# include <__type_traits/remove_cvref.h>
|
||||
# include <__utility/forward.h>
|
||||
# include <__utility/move.h>
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator,
|
||||
class _Predicate,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI bool
|
||||
any_of(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "any_of requires a ForwardIterator");
|
||||
using _Implementation = __pstl::__dispatch<__pstl::__any_of, __pstl::__current_configuration, _RawPolicy>;
|
||||
return __pstl::__handle_exception<_Implementation>(
|
||||
std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), std::move(__pred));
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator,
|
||||
class _Pred,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI bool
|
||||
all_of(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Pred __pred) {
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "all_of requires a ForwardIterator");
|
||||
using _Implementation = __pstl::__dispatch<__pstl::__all_of, __pstl::__current_configuration, _RawPolicy>;
|
||||
return __pstl::__handle_exception<_Implementation>(
|
||||
std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), std::move(__pred));
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator,
|
||||
class _Pred,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI bool
|
||||
none_of(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Pred __pred) {
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "none_of requires a ForwardIterator");
|
||||
using _Implementation = __pstl::__dispatch<__pstl::__none_of, __pstl::__current_configuration, _RawPolicy>;
|
||||
return __pstl::__handle_exception<_Implementation>(
|
||||
std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), std::move(__pred));
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator,
|
||||
class _ForwardOutIterator,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator
|
||||
copy(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _ForwardOutIterator __result) {
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(
|
||||
_ForwardIterator, "copy(first, last, result) requires [first, last) to be ForwardIterators");
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(
|
||||
_ForwardOutIterator, "copy(first, last, result) requires result to be a ForwardIterator");
|
||||
_LIBCPP_REQUIRE_CPP17_OUTPUT_ITERATOR(
|
||||
_ForwardOutIterator, decltype(*__first), "copy(first, last, result) requires result to be an OutputIterator");
|
||||
using _Implementation = __pstl::__dispatch<__pstl::__copy, __pstl::__current_configuration, _RawPolicy>;
|
||||
return __pstl::__handle_exception<_Implementation>(
|
||||
std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), std::move(__result));
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator,
|
||||
class _ForwardOutIterator,
|
||||
class _Size,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator
|
||||
copy_n(_ExecutionPolicy&& __policy, _ForwardIterator __first, _Size __n, _ForwardOutIterator __result) {
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(
|
||||
_ForwardIterator, "copy_n(first, n, result) requires first to be a ForwardIterator");
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(
|
||||
_ForwardOutIterator, "copy_n(first, n, result) requires result to be a ForwardIterator");
|
||||
_LIBCPP_REQUIRE_CPP17_OUTPUT_ITERATOR(
|
||||
_ForwardOutIterator, decltype(*__first), "copy_n(first, n, result) requires result to be an OutputIterator");
|
||||
using _Implementation = __pstl::__dispatch<__pstl::__copy_n, __pstl::__current_configuration, _RawPolicy>;
|
||||
return __pstl::__handle_exception<_Implementation>(
|
||||
std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__n), std::move(__result));
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator,
|
||||
class _Predicate,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI __iter_diff_t<_ForwardIterator>
|
||||
count_if(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(
|
||||
_ForwardIterator, "count_if(first, last, pred) requires [first, last) to be ForwardIterators");
|
||||
using _Implementation = __pstl::__dispatch<__pstl::__count_if, __pstl::__current_configuration, _RawPolicy>;
|
||||
return __pstl::__handle_exception<_Implementation>(
|
||||
std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), std::move(__pred));
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator,
|
||||
class _Tp,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI __iter_diff_t<_ForwardIterator>
|
||||
count(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(
|
||||
_ForwardIterator, "count(first, last, val) requires [first, last) to be ForwardIterators");
|
||||
using _Implementation = __pstl::__dispatch<__pstl::__count, __pstl::__current_configuration, _RawPolicy>;
|
||||
return __pstl::__handle_exception<_Implementation>(
|
||||
std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), __value);
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator1,
|
||||
class _ForwardIterator2,
|
||||
class _Pred,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI bool
|
||||
equal(_ExecutionPolicy&& __policy,
|
||||
_ForwardIterator1 __first1,
|
||||
_ForwardIterator1 __last1,
|
||||
_ForwardIterator2 __first2,
|
||||
_Pred __pred) {
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator1, "equal requires ForwardIterators");
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator2, "equal requires ForwardIterators");
|
||||
using _Implementation = __pstl::__dispatch<__pstl::__equal_3leg, __pstl::__current_configuration, _RawPolicy>;
|
||||
return __pstl::__handle_exception<_Implementation>(
|
||||
std::forward<_ExecutionPolicy>(__policy),
|
||||
std::move(__first1),
|
||||
std::move(__last1),
|
||||
std::move(__first2),
|
||||
std::move(__pred));
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator1,
|
||||
class _ForwardIterator2,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI bool
|
||||
equal(_ExecutionPolicy&& __policy, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2) {
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator1, "equal requires ForwardIterators");
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator2, "equal requires ForwardIterators");
|
||||
using _Implementation = __pstl::__dispatch<__pstl::__equal_3leg, __pstl::__current_configuration, _RawPolicy>;
|
||||
return __pstl::__handle_exception<_Implementation>(
|
||||
std::forward<_ExecutionPolicy>(__policy),
|
||||
std::move(__first1),
|
||||
std::move(__last1),
|
||||
std::move(__first2),
|
||||
equal_to{});
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator1,
|
||||
class _ForwardIterator2,
|
||||
class _Pred,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI bool
|
||||
equal(_ExecutionPolicy&& __policy,
|
||||
_ForwardIterator1 __first1,
|
||||
_ForwardIterator1 __last1,
|
||||
_ForwardIterator2 __first2,
|
||||
_ForwardIterator2 __last2,
|
||||
_Pred __pred) {
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator1, "equal requires ForwardIterators");
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator2, "equal requires ForwardIterators");
|
||||
using _Implementation = __pstl::__dispatch<__pstl::__equal, __pstl::__current_configuration, _RawPolicy>;
|
||||
return __pstl::__handle_exception<_Implementation>(
|
||||
std::forward<_ExecutionPolicy>(__policy),
|
||||
std::move(__first1),
|
||||
std::move(__last1),
|
||||
std::move(__first2),
|
||||
std::move(__last2),
|
||||
std::move(__pred));
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator1,
|
||||
class _ForwardIterator2,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI bool
|
||||
equal(_ExecutionPolicy&& __policy,
|
||||
_ForwardIterator1 __first1,
|
||||
_ForwardIterator1 __last1,
|
||||
_ForwardIterator2 __first2,
|
||||
_ForwardIterator2 __last2) {
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator1, "equal requires ForwardIterators");
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator2, "equal requires ForwardIterators");
|
||||
using _Implementation = __pstl::__dispatch<__pstl::__equal, __pstl::__current_configuration, _RawPolicy>;
|
||||
return __pstl::__handle_exception<_Implementation>(
|
||||
std::forward<_ExecutionPolicy>(__policy),
|
||||
std::move(__first1),
|
||||
std::move(__last1),
|
||||
std::move(__first2),
|
||||
std::move(__last2),
|
||||
equal_to{});
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator,
|
||||
class _Tp,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI void
|
||||
fill(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "fill requires ForwardIterators");
|
||||
using _Implementation = __pstl::__dispatch<__pstl::__fill, __pstl::__current_configuration, _RawPolicy>;
|
||||
__pstl::__handle_exception<_Implementation>(
|
||||
std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), __value);
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator,
|
||||
class _Size,
|
||||
class _Tp,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI void
|
||||
fill_n(_ExecutionPolicy&& __policy, _ForwardIterator __first, _Size __n, const _Tp& __value) {
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "fill_n requires a ForwardIterator");
|
||||
using _Implementation = __pstl::__dispatch<__pstl::__fill_n, __pstl::__current_configuration, _RawPolicy>;
|
||||
__pstl::__handle_exception<_Implementation>(
|
||||
std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__n), __value);
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator,
|
||||
class _Predicate,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI _ForwardIterator
|
||||
find_if(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "find_if requires ForwardIterators");
|
||||
using _Implementation = __pstl::__dispatch<__pstl::__find_if, __pstl::__current_configuration, _RawPolicy>;
|
||||
return __pstl::__handle_exception<_Implementation>(
|
||||
std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), std::move(__pred));
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator,
|
||||
class _Predicate,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI _ForwardIterator
|
||||
find_if_not(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "find_if_not requires ForwardIterators");
|
||||
using _Implementation = __pstl::__dispatch<__pstl::__find_if_not, __pstl::__current_configuration, _RawPolicy>;
|
||||
return __pstl::__handle_exception<_Implementation>(
|
||||
std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), std::move(__pred));
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator,
|
||||
class _Tp,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI _ForwardIterator
|
||||
find(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "find requires ForwardIterators");
|
||||
using _Implementation = __pstl::__dispatch<__pstl::__find, __pstl::__current_configuration, _RawPolicy>;
|
||||
return __pstl::__handle_exception<_Implementation>(
|
||||
std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), __value);
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator,
|
||||
class _Function,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI void
|
||||
for_each(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Function __func) {
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "for_each requires ForwardIterators");
|
||||
using _Implementation = __pstl::__dispatch<__pstl::__for_each, __pstl::__current_configuration, _RawPolicy>;
|
||||
__pstl::__handle_exception<_Implementation>(
|
||||
std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), std::move(__func));
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator,
|
||||
class _Size,
|
||||
class _Function,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI void
|
||||
for_each_n(_ExecutionPolicy&& __policy, _ForwardIterator __first, _Size __size, _Function __func) {
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "for_each_n requires a ForwardIterator");
|
||||
using _Implementation = __pstl::__dispatch<__pstl::__for_each_n, __pstl::__current_configuration, _RawPolicy>;
|
||||
__pstl::__handle_exception<_Implementation>(
|
||||
std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__size), std::move(__func));
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator,
|
||||
class _Generator,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI void
|
||||
generate(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Generator __gen) {
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "generate requires ForwardIterators");
|
||||
using _Implementation = __pstl::__dispatch<__pstl::__generate, __pstl::__current_configuration, _RawPolicy>;
|
||||
__pstl::__handle_exception<_Implementation>(
|
||||
std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), std::move(__gen));
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator,
|
||||
class _Size,
|
||||
class _Generator,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI void
|
||||
generate_n(_ExecutionPolicy&& __policy, _ForwardIterator __first, _Size __n, _Generator __gen) {
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "generate_n requires a ForwardIterator");
|
||||
using _Implementation = __pstl::__dispatch<__pstl::__generate_n, __pstl::__current_configuration, _RawPolicy>;
|
||||
__pstl::__handle_exception<_Implementation>(
|
||||
std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__n), std::move(__gen));
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator,
|
||||
class _Predicate,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool
|
||||
is_partitioned(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "is_partitioned requires ForwardIterators");
|
||||
using _Implementation = __pstl::__dispatch<__pstl::__is_partitioned, __pstl::__current_configuration, _RawPolicy>;
|
||||
return __pstl::__handle_exception<_Implementation>(
|
||||
std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), std::move(__pred));
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator1,
|
||||
class _ForwardIterator2,
|
||||
class _ForwardOutIterator,
|
||||
class _Comp,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator
|
||||
merge(_ExecutionPolicy&& __policy,
|
||||
_ForwardIterator1 __first1,
|
||||
_ForwardIterator1 __last1,
|
||||
_ForwardIterator2 __first2,
|
||||
_ForwardIterator2 __last2,
|
||||
_ForwardOutIterator __result,
|
||||
_Comp __comp) {
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator1, "merge requires ForwardIterators");
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator2, "merge requires ForwardIterators");
|
||||
_LIBCPP_REQUIRE_CPP17_OUTPUT_ITERATOR(_ForwardOutIterator, decltype(*__first1), "merge requires an OutputIterator");
|
||||
_LIBCPP_REQUIRE_CPP17_OUTPUT_ITERATOR(_ForwardOutIterator, decltype(*__first2), "merge requires an OutputIterator");
|
||||
using _Implementation = __pstl::__dispatch<__pstl::__merge, __pstl::__current_configuration, _RawPolicy>;
|
||||
return __pstl::__handle_exception<_Implementation>(
|
||||
std::forward<_ExecutionPolicy>(__policy),
|
||||
std::move(__first1),
|
||||
std::move(__last1),
|
||||
std::move(__first2),
|
||||
std::move(__last2),
|
||||
std::move(__result),
|
||||
std::move(__comp));
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator1,
|
||||
class _ForwardIterator2,
|
||||
class _ForwardOutIterator,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator
|
||||
merge(_ExecutionPolicy&& __policy,
|
||||
_ForwardIterator1 __first1,
|
||||
_ForwardIterator1 __last1,
|
||||
_ForwardIterator2 __first2,
|
||||
_ForwardIterator2 __last2,
|
||||
_ForwardOutIterator __result) {
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator1, "merge requires ForwardIterators");
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator2, "merge requires ForwardIterators");
|
||||
_LIBCPP_REQUIRE_CPP17_OUTPUT_ITERATOR(_ForwardOutIterator, decltype(*__first1), "merge requires an OutputIterator");
|
||||
_LIBCPP_REQUIRE_CPP17_OUTPUT_ITERATOR(_ForwardOutIterator, decltype(*__first2), "merge requires an OutputIterator");
|
||||
using _Implementation = __pstl::__dispatch<__pstl::__merge, __pstl::__current_configuration, _RawPolicy>;
|
||||
return __pstl::__handle_exception<_Implementation>(
|
||||
std::forward<_ExecutionPolicy>(__policy),
|
||||
std::move(__first1),
|
||||
std::move(__last1),
|
||||
std::move(__first2),
|
||||
std::move(__last2),
|
||||
std::move(__result),
|
||||
less{});
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator,
|
||||
class _ForwardOutIterator,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator
|
||||
move(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _ForwardOutIterator __result) {
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "move requires ForwardIterators");
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardOutIterator, "move requires an OutputIterator");
|
||||
_LIBCPP_REQUIRE_CPP17_OUTPUT_ITERATOR(
|
||||
_ForwardOutIterator, decltype(std::move(*__first)), "move requires an OutputIterator");
|
||||
using _Implementation = __pstl::__dispatch<__pstl::__move, __pstl::__current_configuration, _RawPolicy>;
|
||||
return __pstl::__handle_exception<_Implementation>(
|
||||
std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), std::move(__result));
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator,
|
||||
class _Pred,
|
||||
class _Tp,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI void
|
||||
replace_if(_ExecutionPolicy&& __policy,
|
||||
_ForwardIterator __first,
|
||||
_ForwardIterator __last,
|
||||
_Pred __pred,
|
||||
const _Tp& __new_value) {
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "replace_if requires ForwardIterators");
|
||||
using _Implementation = __pstl::__dispatch<__pstl::__replace_if, __pstl::__current_configuration, _RawPolicy>;
|
||||
__pstl::__handle_exception<_Implementation>(
|
||||
std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), std::move(__pred), __new_value);
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator,
|
||||
class _Tp,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI void
|
||||
replace(_ExecutionPolicy&& __policy,
|
||||
_ForwardIterator __first,
|
||||
_ForwardIterator __last,
|
||||
const _Tp& __old_value,
|
||||
const _Tp& __new_value) {
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "replace requires ForwardIterators");
|
||||
using _Implementation = __pstl::__dispatch<__pstl::__replace, __pstl::__current_configuration, _RawPolicy>;
|
||||
__pstl::__handle_exception<_Implementation>(
|
||||
std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), __old_value, __new_value);
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator,
|
||||
class _ForwardOutIterator,
|
||||
class _Pred,
|
||||
class _Tp,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI void replace_copy_if(
|
||||
_ExecutionPolicy&& __policy,
|
||||
_ForwardIterator __first,
|
||||
_ForwardIterator __last,
|
||||
_ForwardOutIterator __result,
|
||||
_Pred __pred,
|
||||
const _Tp& __new_value) {
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "replace_copy_if requires ForwardIterators");
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardOutIterator, "replace_copy_if requires ForwardIterators");
|
||||
_LIBCPP_REQUIRE_CPP17_OUTPUT_ITERATOR(
|
||||
_ForwardOutIterator, decltype(*__first), "replace_copy_if requires an OutputIterator");
|
||||
_LIBCPP_REQUIRE_CPP17_OUTPUT_ITERATOR(_ForwardOutIterator, const _Tp&, "replace_copy requires an OutputIterator");
|
||||
using _Implementation = __pstl::__dispatch<__pstl::__replace_copy_if, __pstl::__current_configuration, _RawPolicy>;
|
||||
__pstl::__handle_exception<_Implementation>(
|
||||
std::forward<_ExecutionPolicy>(__policy),
|
||||
std::move(__first),
|
||||
std::move(__last),
|
||||
std::move(__result),
|
||||
std::move(__pred),
|
||||
__new_value);
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator,
|
||||
class _ForwardOutIterator,
|
||||
class _Tp,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI void replace_copy(
|
||||
_ExecutionPolicy&& __policy,
|
||||
_ForwardIterator __first,
|
||||
_ForwardIterator __last,
|
||||
_ForwardOutIterator __result,
|
||||
const _Tp& __old_value,
|
||||
const _Tp& __new_value) {
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "replace_copy requires ForwardIterators");
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardOutIterator, "replace_copy requires ForwardIterators");
|
||||
_LIBCPP_REQUIRE_CPP17_OUTPUT_ITERATOR(
|
||||
_ForwardOutIterator, decltype(*__first), "replace_copy requires an OutputIterator");
|
||||
_LIBCPP_REQUIRE_CPP17_OUTPUT_ITERATOR(_ForwardOutIterator, const _Tp&, "replace_copy requires an OutputIterator");
|
||||
using _Implementation = __pstl::__dispatch<__pstl::__replace_copy, __pstl::__current_configuration, _RawPolicy>;
|
||||
__pstl::__handle_exception<_Implementation>(
|
||||
std::forward<_ExecutionPolicy>(__policy),
|
||||
std::move(__first),
|
||||
std::move(__last),
|
||||
std::move(__result),
|
||||
__old_value,
|
||||
__new_value);
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator,
|
||||
class _ForwardOutIterator,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator rotate_copy(
|
||||
_ExecutionPolicy&& __policy,
|
||||
_ForwardIterator __first,
|
||||
_ForwardIterator __middle,
|
||||
_ForwardIterator __last,
|
||||
_ForwardOutIterator __result) {
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "rotate_copy requires ForwardIterators");
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardOutIterator, "rotate_copy requires ForwardIterators");
|
||||
_LIBCPP_REQUIRE_CPP17_OUTPUT_ITERATOR(
|
||||
_ForwardOutIterator, decltype(*__first), "rotate_copy requires an OutputIterator");
|
||||
using _Implementation = __pstl::__dispatch<__pstl::__rotate_copy, __pstl::__current_configuration, _RawPolicy>;
|
||||
return __pstl::__handle_exception<_Implementation>(
|
||||
std::forward<_ExecutionPolicy>(__policy),
|
||||
std::move(__first),
|
||||
std::move(__middle),
|
||||
std::move(__last),
|
||||
std::move(__result));
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _RandomAccessIterator,
|
||||
class _Comp,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI void
|
||||
sort(_ExecutionPolicy&& __policy, _RandomAccessIterator __first, _RandomAccessIterator __last, _Comp __comp) {
|
||||
_LIBCPP_REQUIRE_CPP17_RANDOM_ACCESS_ITERATOR(_RandomAccessIterator, "sort requires RandomAccessIterators");
|
||||
using _Implementation = __pstl::__dispatch<__pstl::__sort, __pstl::__current_configuration, _RawPolicy>;
|
||||
__pstl::__handle_exception<_Implementation>(
|
||||
std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), std::move(__comp));
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _RandomAccessIterator,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI void
|
||||
sort(_ExecutionPolicy&& __policy, _RandomAccessIterator __first, _RandomAccessIterator __last) {
|
||||
_LIBCPP_REQUIRE_CPP17_RANDOM_ACCESS_ITERATOR(_RandomAccessIterator, "sort requires RandomAccessIterators");
|
||||
using _Implementation = __pstl::__dispatch<__pstl::__sort, __pstl::__current_configuration, _RawPolicy>;
|
||||
__pstl::__handle_exception<_Implementation>(
|
||||
std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), less{});
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _RandomAccessIterator,
|
||||
class _Comp,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI void
|
||||
stable_sort(_ExecutionPolicy&& __policy, _RandomAccessIterator __first, _RandomAccessIterator __last, _Comp __comp) {
|
||||
_LIBCPP_REQUIRE_CPP17_RANDOM_ACCESS_ITERATOR(_RandomAccessIterator, "stable_sort requires RandomAccessIterators");
|
||||
using _Implementation = __pstl::__dispatch<__pstl::__stable_sort, __pstl::__current_configuration, _RawPolicy>;
|
||||
__pstl::__handle_exception<_Implementation>(
|
||||
std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), std::move(__comp));
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _RandomAccessIterator,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI void
|
||||
stable_sort(_ExecutionPolicy&& __policy, _RandomAccessIterator __first, _RandomAccessIterator __last) {
|
||||
_LIBCPP_REQUIRE_CPP17_RANDOM_ACCESS_ITERATOR(_RandomAccessIterator, "stable_sort requires RandomAccessIterators");
|
||||
using _Implementation = __pstl::__dispatch<__pstl::__stable_sort, __pstl::__current_configuration, _RawPolicy>;
|
||||
__pstl::__handle_exception<_Implementation>(
|
||||
std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), less{});
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator,
|
||||
class _ForwardOutIterator,
|
||||
class _UnaryOperation,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator transform(
|
||||
_ExecutionPolicy&& __policy,
|
||||
_ForwardIterator __first,
|
||||
_ForwardIterator __last,
|
||||
_ForwardOutIterator __result,
|
||||
_UnaryOperation __op) {
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "transform requires ForwardIterators");
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardOutIterator, "transform requires an OutputIterator");
|
||||
_LIBCPP_REQUIRE_CPP17_OUTPUT_ITERATOR(
|
||||
_ForwardOutIterator, decltype(__op(*__first)), "transform requires an OutputIterator");
|
||||
using _Implementation = __pstl::__dispatch<__pstl::__transform, __pstl::__current_configuration, _RawPolicy>;
|
||||
return __pstl::__handle_exception<_Implementation>(
|
||||
std::forward<_ExecutionPolicy>(__policy),
|
||||
std::move(__first),
|
||||
std::move(__last),
|
||||
std::move(__result),
|
||||
std::move(__op));
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator1,
|
||||
class _ForwardIterator2,
|
||||
class _ForwardOutIterator,
|
||||
class _BinaryOperation,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator transform(
|
||||
_ExecutionPolicy&& __policy,
|
||||
_ForwardIterator1 __first1,
|
||||
_ForwardIterator1 __last1,
|
||||
_ForwardIterator2 __first2,
|
||||
_ForwardOutIterator __result,
|
||||
_BinaryOperation __op) {
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator1, "transform requires ForwardIterators");
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator2, "transform requires ForwardIterators");
|
||||
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardOutIterator, "transform requires an OutputIterator");
|
||||
_LIBCPP_REQUIRE_CPP17_OUTPUT_ITERATOR(
|
||||
_ForwardOutIterator, decltype(__op(*__first1, *__first2)), "transform requires an OutputIterator");
|
||||
using _Implementation = __pstl::__dispatch<__pstl::__transform_binary, __pstl::__current_configuration, _RawPolicy>;
|
||||
return __pstl::__handle_exception<_Implementation>(
|
||||
std::forward<_ExecutionPolicy>(__policy),
|
||||
std::move(__first1),
|
||||
std::move(__last1),
|
||||
std::move(__first2),
|
||||
std::move(__result),
|
||||
std::move(__op));
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_PSTL_H
|
|
@ -1,95 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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_PSTL_ANY_ALL_NONE_OF_H
|
||||
#define _LIBCPP___ALGORITHM_PSTL_ANY_ALL_NONE_OF_H
|
||||
|
||||
#include <__algorithm/pstl_find.h>
|
||||
#include <__algorithm/pstl_frontend_dispatch.h>
|
||||
#include <__config>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__type_traits/enable_if.h>
|
||||
#include <__type_traits/is_execution_policy.h>
|
||||
#include <__type_traits/remove_cvref.h>
|
||||
#include <__utility/terminate_on_exception.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class>
|
||||
void __pstl_any_of(); // declaration needed for the frontend dispatch below
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator,
|
||||
class _Predicate,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI bool
|
||||
any_of(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
|
||||
return std::__pstl_frontend_dispatch(
|
||||
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_any_of),
|
||||
[&](_ForwardIterator __g_first, _ForwardIterator __g_last, _Predicate __g_pred) {
|
||||
return std::find_if(__policy, __g_first, __g_last, __g_pred) != __g_last;
|
||||
},
|
||||
std::move(__first),
|
||||
std::move(__last),
|
||||
std::move(__pred));
|
||||
}
|
||||
|
||||
template <class>
|
||||
void __pstl_all_of(); // declaration needed for the frontend dispatch below
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator,
|
||||
class _Pred,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI bool
|
||||
all_of(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Pred __pred) {
|
||||
return std::__pstl_frontend_dispatch(
|
||||
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_all_of),
|
||||
[&](_ForwardIterator __g_first, _ForwardIterator __g_last, _Pred __g_pred) {
|
||||
return !std::any_of(__policy, __g_first, __g_last, [&](__iter_reference<_ForwardIterator> __value) {
|
||||
return !__g_pred(__value);
|
||||
});
|
||||
},
|
||||
std::move(__first),
|
||||
std::move(__last),
|
||||
std::move(__pred));
|
||||
}
|
||||
|
||||
template <class>
|
||||
void __pstl_none_of(); // declaration needed for the frontend dispatch below
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator,
|
||||
class _Pred,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI bool
|
||||
none_of(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Pred __pred) {
|
||||
return std::__pstl_frontend_dispatch(
|
||||
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_none_of),
|
||||
[&](_ForwardIterator __g_first, _ForwardIterator __g_last, _Pred __g_pred) {
|
||||
return !std::any_of(__policy, __g_first, __g_last, __g_pred);
|
||||
},
|
||||
std::move(__first),
|
||||
std::move(__last),
|
||||
std::move(__pred));
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_PSTL_ANY_ALL_NONE_OF_H
|
125
third_party/libcxx/__algorithm/pstl_backend.h
vendored
125
third_party/libcxx/__algorithm/pstl_backend.h
vendored
|
@ -1,125 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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_PSTL_BACKEND_H
|
||||
#define _LIBCPP___ALGORITHM_PSTL_BACKEND_H
|
||||
|
||||
#include <__algorithm/pstl_backends/cpu_backend.h>
|
||||
#include <__config>
|
||||
#include <execution>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
/*
|
||||
TODO: Documentation of how backends work
|
||||
|
||||
A PSTL parallel backend is a tag type to which the following functions are associated, at minimum:
|
||||
|
||||
template <class _ExecutionPolicy, class _Iterator, class _Func>
|
||||
void __pstl_for_each(_Backend, _ExecutionPolicy&&, _Iterator __first, _Iterator __last, _Func __f);
|
||||
|
||||
template <class _ExecutionPolicy, class _Iterator, class _Predicate>
|
||||
_Iterator __pstl_find_if(_Backend, _Iterator __first, _Iterator __last, _Predicate __pred);
|
||||
|
||||
template <class _ExecutionPolicy, class _InIterator, class _OutIterator, class _UnaryOperation>
|
||||
_OutIterator __pstl_transform(_InIterator __first, _InIterator __last, _OutIterator __result, _UnaryOperation __op);
|
||||
|
||||
template <class _ExecutionPolicy, class _InIterator1, class _InIterator2, class _OutIterator, class _BinaryOperation>
|
||||
_OutIterator __pstl_transform(_InIterator1 __first1,
|
||||
_InIterator1 __last1,
|
||||
_InIterator2 __first2,
|
||||
_OutIterator __result,
|
||||
_BinaryOperation __op);
|
||||
|
||||
// TODO: Complete this list
|
||||
|
||||
The following functions are optional but can be provided. If provided, they are used by the corresponding
|
||||
algorithms, otherwise they are implemented in terms of other algorithms. If none of the optional algorithms are
|
||||
implemented, all the algorithms will eventually forward to the basis algorithms listed above:
|
||||
|
||||
template <class _ExecutionPolicy, class _Iterator, class _Size, class _Func>
|
||||
void __pstl_for_each_n(_Backend, _Iterator __first, _Size __n, _Func __f);
|
||||
|
||||
template <class _ExecutionPolicy, class _Iterator, class _Predicate>
|
||||
bool __pstl_any_of(_Backend, _Iterator __first, _iterator __last, _Predicate __pred);
|
||||
|
||||
template <class _ExecutionPolicy, class _Iterator, class _Predicate>
|
||||
bool __pstl_all_of(_Backend, _Iterator __first, _iterator __last, _Predicate __pred);
|
||||
|
||||
template <class _ExecutionPolicy, class _Iterator, class _Predicate>
|
||||
bool __pstl_none_of(_Backend, _Iterator __first, _iterator __last, _Predicate __pred);
|
||||
|
||||
template <class _ExecutionPolicy, class _Iterator, class _Tp>
|
||||
_Iterator __pstl_find(_Backend, _Iterator __first, _Iterator __last, const _Tp& __value);
|
||||
|
||||
template <class _ExecutionPolicy, class _Iterator, class _Predicate>
|
||||
_Iterator __pstl_find_if_not(_Backend, _Iterator __first, _Iterator __last, _Predicate __pred);
|
||||
|
||||
template <class _ExecutionPolicy, class _Iterator, class _Tp>
|
||||
void __pstl_fill(_Backend, _Iterator __first, _Iterator __last, const _Tp& __value);
|
||||
|
||||
template <class _ExecutionPolicy, class _Iterator, class _SizeT, class _Tp>
|
||||
void __pstl_fill_n(_Backend, _Iterator __first, _SizeT __n, const _Tp& __value);
|
||||
|
||||
template <class _ExecutionPolicy, class _terator1, class _Iterator2, class _OutIterator, class _Comp>
|
||||
_OutIterator __pstl_merge(_Backend,
|
||||
_Iterator1 __first1,
|
||||
_Iterator1 __last1,
|
||||
_Iterator2 __first2,
|
||||
_Iterator2 __last2,
|
||||
_OutIterator __result,
|
||||
_Comp __comp);
|
||||
|
||||
// TODO: Complete this list
|
||||
|
||||
*/
|
||||
|
||||
template <class _ExecutionPolicy>
|
||||
struct __select_backend;
|
||||
|
||||
template <>
|
||||
struct __select_backend<std::execution::sequenced_policy> {
|
||||
using type = __cpu_backend_tag;
|
||||
};
|
||||
|
||||
# if _LIBCPP_STD_VER >= 20
|
||||
template <>
|
||||
struct __select_backend<std::execution::unsequenced_policy> {
|
||||
using type = __cpu_backend_tag;
|
||||
};
|
||||
# endif
|
||||
|
||||
# if defined(_LIBCPP_PSTL_CPU_BACKEND_SERIAL) || defined(_LIBCPP_PSTL_CPU_BACKEND_THREAD)
|
||||
template <>
|
||||
struct __select_backend<std::execution::parallel_policy> {
|
||||
using type = __cpu_backend_tag;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct __select_backend<std::execution::parallel_unsequenced_policy> {
|
||||
using type = __cpu_backend_tag;
|
||||
};
|
||||
|
||||
# else
|
||||
|
||||
// ...New vendors can add parallel backends here...
|
||||
|
||||
# error "Invalid choice of a PSTL parallel backend"
|
||||
# endif
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_PSTL_BACKEND_H
|
|
@ -1,47 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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_PSTL_BACKENDS_CPU_BACKEND_H
|
||||
#define _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKEND_H
|
||||
|
||||
#include <__config>
|
||||
|
||||
/*
|
||||
|
||||
// _Functor takes a subrange for [__first, __last) that should be executed in serial
|
||||
template <class _RandomAccessIterator, class _Functor>
|
||||
void __parallel_for(_RandomAccessIterator __first, _RandomAccessIterator __last, _Functor __func);
|
||||
|
||||
// Cancel the execution of other jobs - they aren't needed anymore
|
||||
void __cancel_execution();
|
||||
|
||||
template <class _RandomAccessIterator1,
|
||||
class _RandomAccessIterator2,
|
||||
class _RandomAccessIterator3,
|
||||
class _Compare,
|
||||
class _LeafMerge>
|
||||
void __parallel_merge(
|
||||
_RandomAccessIterator1 __first1,
|
||||
_RandomAccessIterator1 __last1,
|
||||
_RandomAccessIterator2 __first2,
|
||||
_RandomAccessIterator2 __last2,
|
||||
_RandomAccessIterator3 __outit,
|
||||
_Compare __comp,
|
||||
_LeafMerge __leaf_merge);
|
||||
|
||||
TODO: Document the parallel backend
|
||||
*/
|
||||
|
||||
#include <__algorithm/pstl_backends/cpu_backends/any_of.h>
|
||||
#include <__algorithm/pstl_backends/cpu_backends/fill.h>
|
||||
#include <__algorithm/pstl_backends/cpu_backends/find_if.h>
|
||||
#include <__algorithm/pstl_backends/cpu_backends/for_each.h>
|
||||
#include <__algorithm/pstl_backends/cpu_backends/merge.h>
|
||||
#include <__algorithm/pstl_backends/cpu_backends/transform.h>
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKEND_H
|
|
@ -1,90 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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_PSTL_BACKENDS_CPU_BACKEND_ANY_OF_H
|
||||
#define _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKEND_ANY_OF_H
|
||||
|
||||
#include <__algorithm/any_of.h>
|
||||
#include <__algorithm/find_if.h>
|
||||
#include <__algorithm/pstl_backends/cpu_backends/backend.h>
|
||||
#include <__atomic/atomic.h>
|
||||
#include <__atomic/memory_order.h>
|
||||
#include <__config>
|
||||
#include <__functional/operations.h>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__type_traits/is_execution_policy.h>
|
||||
#include <__utility/pair.h>
|
||||
#include <__utility/terminate_on_exception.h>
|
||||
#include <cstdint>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _Index, class _Brick>
|
||||
_LIBCPP_HIDE_FROM_ABI bool __parallel_or(_Index __first, _Index __last, _Brick __f) {
|
||||
std::atomic<bool> __found(false);
|
||||
__par_backend::__parallel_for(__first, __last, [__f, &__found](_Index __i, _Index __j) {
|
||||
if (!__found.load(std::memory_order_relaxed) && __f(__i, __j)) {
|
||||
__found.store(true, std::memory_order_relaxed);
|
||||
__par_backend::__cancel_execution();
|
||||
}
|
||||
});
|
||||
return __found;
|
||||
}
|
||||
|
||||
// TODO: check whether __simd_first() can be used here
|
||||
template <class _Index, class _DifferenceType, class _Pred>
|
||||
_LIBCPP_HIDE_FROM_ABI bool __simd_or(_Index __first, _DifferenceType __n, _Pred __pred) noexcept {
|
||||
_DifferenceType __block_size = 4 < __n ? 4 : __n;
|
||||
const _Index __last = __first + __n;
|
||||
while (__last != __first) {
|
||||
int32_t __flag = 1;
|
||||
_PSTL_PRAGMA_SIMD_REDUCTION(& : __flag)
|
||||
for (_DifferenceType __i = 0; __i < __block_size; ++__i)
|
||||
if (__pred(*(__first + __i)))
|
||||
__flag = 0;
|
||||
if (!__flag)
|
||||
return true;
|
||||
|
||||
__first += __block_size;
|
||||
if (__last - __first >= __block_size << 1) {
|
||||
// Double the block _Size. Any unnecessary iterations can be amortized against work done so far.
|
||||
__block_size <<= 1;
|
||||
} else {
|
||||
__block_size = __last - __first;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy, class _ForwardIterator, class _Predicate>
|
||||
_LIBCPP_HIDE_FROM_ABI bool
|
||||
__pstl_any_of(__cpu_backend_tag, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
|
||||
if constexpr (__is_parallel_execution_policy_v<_ExecutionPolicy> &&
|
||||
__has_random_access_iterator_category<_ForwardIterator>::value) {
|
||||
return std::__terminate_on_exception([&] {
|
||||
return std::__parallel_or(
|
||||
__first, __last, [&__pred](_ForwardIterator __brick_first, _ForwardIterator __brick_last) {
|
||||
return std::__pstl_any_of<__remove_parallel_policy_t<_ExecutionPolicy>>(
|
||||
__cpu_backend_tag{}, __brick_first, __brick_last, __pred);
|
||||
});
|
||||
});
|
||||
} else if constexpr (__is_unsequenced_execution_policy_v<_ExecutionPolicy> &&
|
||||
__has_random_access_iterator_category<_ForwardIterator>::value) {
|
||||
return std::__simd_or(__first, __last - __first, __pred);
|
||||
} else {
|
||||
return std::any_of(__first, __last, __pred);
|
||||
}
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKEND_ANY_OF_H
|
|
@ -1,32 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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_PSTL_BACKENDS_CPU_BACKEND_BACKEND_H
|
||||
#define _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKEND_BACKEND_H
|
||||
|
||||
#include <__config>
|
||||
|
||||
#if defined(_LIBCPP_PSTL_CPU_BACKEND_SERIAL)
|
||||
# include <__algorithm/pstl_backends/cpu_backends/serial.h>
|
||||
#elif defined(_LIBCPP_PSTL_CPU_BACKEND_THREAD)
|
||||
# include <__algorithm/pstl_backends/cpu_backends/thread.h>
|
||||
#else
|
||||
# error "Invalid CPU backend choice"
|
||||
#endif
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
struct __cpu_backend_tag {};
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKEND_BACKEND_H
|
|
@ -1,60 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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_PSTL_BACKENDS_CPU_BACKENDS_FILL_H
|
||||
#define _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKENDS_FILL_H
|
||||
|
||||
#include <__algorithm/fill.h>
|
||||
#include <__algorithm/pstl_backends/cpu_backends/backend.h>
|
||||
#include <__config>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__type_traits/is_execution_policy.h>
|
||||
#include <__utility/terminate_on_exception.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _Index, class _DifferenceType, class _Tp>
|
||||
_LIBCPP_HIDE_FROM_ABI _Index __simd_fill_n(_Index __first, _DifferenceType __n, const _Tp& __value) noexcept {
|
||||
_PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED
|
||||
_PSTL_PRAGMA_SIMD
|
||||
for (_DifferenceType __i = 0; __i < __n; ++__i)
|
||||
__first[__i] = __value;
|
||||
return __first + __n;
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy, class _ForwardIterator, class _Tp>
|
||||
_LIBCPP_HIDE_FROM_ABI void
|
||||
__pstl_fill(__cpu_backend_tag, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
|
||||
if constexpr (__is_parallel_execution_policy_v<_ExecutionPolicy> &&
|
||||
__has_random_access_iterator_category<_ForwardIterator>::value) {
|
||||
std::__terminate_on_exception([&] {
|
||||
__par_backend::__parallel_for(
|
||||
__first, __last, [&__value](_ForwardIterator __brick_first, _ForwardIterator __brick_last) {
|
||||
std::__pstl_fill<__remove_parallel_policy_t<_ExecutionPolicy>>(
|
||||
__cpu_backend_tag{}, __brick_first, __brick_last, __value);
|
||||
});
|
||||
});
|
||||
} else if constexpr (__is_unsequenced_execution_policy_v<_ExecutionPolicy> &&
|
||||
__has_random_access_iterator_category<_ForwardIterator>::value) {
|
||||
std::__simd_fill_n(__first, __last - __first, __value);
|
||||
} else {
|
||||
std::fill(__first, __last, __value);
|
||||
}
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKENDS_FILL_H
|
|
@ -1,125 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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_PSTL_BACKENDS_CPU_BACKENDS_FIND_IF_H
|
||||
#define _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKENDS_FIND_IF_H
|
||||
|
||||
#include <__algorithm/find_if.h>
|
||||
#include <__algorithm/pstl_backends/cpu_backends/backend.h>
|
||||
#include <__atomic/atomic.h>
|
||||
#include <__config>
|
||||
#include <__functional/operations.h>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__type_traits/is_execution_policy.h>
|
||||
#include <__utility/pair.h>
|
||||
#include <__utility/terminate_on_exception.h>
|
||||
#include <cstddef>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _Index, class _Brick, class _Compare>
|
||||
_LIBCPP_HIDE_FROM_ABI _Index
|
||||
__parallel_find(_Index __first, _Index __last, _Brick __f, _Compare __comp, bool __b_first) {
|
||||
typedef typename std::iterator_traits<_Index>::difference_type _DifferenceType;
|
||||
const _DifferenceType __n = __last - __first;
|
||||
_DifferenceType __initial_dist = __b_first ? __n : -1;
|
||||
std::atomic<_DifferenceType> __extremum(__initial_dist);
|
||||
// TODO: find out what is better here: parallel_for or parallel_reduce
|
||||
__par_backend::__parallel_for(__first, __last, [__comp, __f, __first, &__extremum](_Index __i, _Index __j) {
|
||||
// See "Reducing Contention Through Priority Updates", PPoPP '13, for discussion of
|
||||
// why using a shared variable scales fairly well in this situation.
|
||||
if (__comp(__i - __first, __extremum)) {
|
||||
_Index __res = __f(__i, __j);
|
||||
// If not '__last' returned then we found what we want so put this to extremum
|
||||
if (__res != __j) {
|
||||
const _DifferenceType __k = __res - __first;
|
||||
for (_DifferenceType __old = __extremum; __comp(__k, __old); __old = __extremum) {
|
||||
__extremum.compare_exchange_weak(__old, __k);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return __extremum != __initial_dist ? __first + __extremum : __last;
|
||||
}
|
||||
|
||||
const std::size_t __lane_size = 64;
|
||||
|
||||
template <class _Index, class _DifferenceType, class _Compare>
|
||||
_LIBCPP_HIDE_FROM_ABI _Index
|
||||
__simd_first(_Index __first, _DifferenceType __begin, _DifferenceType __end, _Compare __comp) noexcept {
|
||||
// Experiments show good block sizes like this
|
||||
const _DifferenceType __block_size = 8;
|
||||
alignas(__lane_size) _DifferenceType __lane[__block_size] = {0};
|
||||
while (__end - __begin >= __block_size) {
|
||||
_DifferenceType __found = 0;
|
||||
_PSTL_PRAGMA_SIMD_REDUCTION(| : __found) for (_DifferenceType __i = __begin; __i < __begin + __block_size; ++__i) {
|
||||
const _DifferenceType __t = __comp(__first, __i);
|
||||
__lane[__i - __begin] = __t;
|
||||
__found |= __t;
|
||||
}
|
||||
if (__found) {
|
||||
_DifferenceType __i;
|
||||
// This will vectorize
|
||||
for (__i = 0; __i < __block_size; ++__i) {
|
||||
if (__lane[__i]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return __first + __begin + __i;
|
||||
}
|
||||
__begin += __block_size;
|
||||
}
|
||||
|
||||
// Keep remainder scalar
|
||||
while (__begin != __end) {
|
||||
if (__comp(__first, __begin)) {
|
||||
return __first + __begin;
|
||||
}
|
||||
++__begin;
|
||||
}
|
||||
return __first + __end;
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy, class _ForwardIterator, class _Predicate>
|
||||
_LIBCPP_HIDE_FROM_ABI _ForwardIterator
|
||||
__pstl_find_if(__cpu_backend_tag, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
|
||||
if constexpr (__is_parallel_execution_policy_v<_ExecutionPolicy> &&
|
||||
__has_random_access_iterator_category<_ForwardIterator>::value) {
|
||||
return std::__terminate_on_exception([&] {
|
||||
return std::__parallel_find(
|
||||
__first,
|
||||
__last,
|
||||
[&__pred](_ForwardIterator __brick_first, _ForwardIterator __brick_last) {
|
||||
return std::__pstl_find_if<__remove_parallel_policy_t<_ExecutionPolicy>>(
|
||||
__cpu_backend_tag{}, __brick_first, __brick_last, __pred);
|
||||
},
|
||||
less<>{},
|
||||
true);
|
||||
});
|
||||
} else if constexpr (__is_unsequenced_execution_policy_v<_ExecutionPolicy> &&
|
||||
__has_random_access_iterator_category<_ForwardIterator>::value) {
|
||||
using __diff_t = __iter_diff_t<_ForwardIterator>;
|
||||
return std::__simd_first(__first, __diff_t(0), __last - __first, [&__pred](_ForwardIterator __iter, __diff_t __i) {
|
||||
return __pred(__iter[__i]);
|
||||
});
|
||||
} else {
|
||||
return std::find_if(__first, __last, __pred);
|
||||
}
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKENDS_FIND_IF_H
|
|
@ -1,60 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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_PSTL_BACKENDS_CPU_BACKNEDS_FOR_EACH_H
|
||||
#define _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKNEDS_FOR_EACH_H
|
||||
|
||||
#include <__algorithm/for_each.h>
|
||||
#include <__algorithm/pstl_backends/cpu_backends/backend.h>
|
||||
#include <__config>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__type_traits/is_execution_policy.h>
|
||||
#include <__utility/terminate_on_exception.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _Iterator, class _DifferenceType, class _Function>
|
||||
_LIBCPP_HIDE_FROM_ABI _Iterator __simd_walk_1(_Iterator __first, _DifferenceType __n, _Function __f) noexcept {
|
||||
_PSTL_PRAGMA_SIMD
|
||||
for (_DifferenceType __i = 0; __i < __n; ++__i)
|
||||
__f(__first[__i]);
|
||||
|
||||
return __first + __n;
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy, class _ForwardIterator, class _Functor>
|
||||
_LIBCPP_HIDE_FROM_ABI void
|
||||
__pstl_for_each(__cpu_backend_tag, _ForwardIterator __first, _ForwardIterator __last, _Functor __func) {
|
||||
if constexpr (__is_parallel_execution_policy_v<_ExecutionPolicy> &&
|
||||
__has_random_access_iterator_category<_ForwardIterator>::value) {
|
||||
std::__terminate_on_exception([&] {
|
||||
std::__par_backend::__parallel_for(
|
||||
__first, __last, [__func](_ForwardIterator __brick_first, _ForwardIterator __brick_last) {
|
||||
std::__pstl_for_each<__remove_parallel_policy_t<_ExecutionPolicy>>(
|
||||
__cpu_backend_tag{}, __brick_first, __brick_last, __func);
|
||||
});
|
||||
});
|
||||
} else if constexpr (__is_unsequenced_execution_policy_v<_ExecutionPolicy> &&
|
||||
__has_random_access_iterator_category<_ForwardIterator>::value) {
|
||||
std::__simd_walk_1(__first, __last - __first, __func);
|
||||
} else {
|
||||
std::for_each(__first, __last, __func);
|
||||
}
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKNEDS_FOR_EACH_H
|
|
@ -1,79 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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_PSTL_BACKENDS_CPU_BACKENDS_MERGE_H
|
||||
#define _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKENDS_MERGE_H
|
||||
|
||||
#include <__algorithm/merge.h>
|
||||
#include <__algorithm/pstl_backends/cpu_backends/backend.h>
|
||||
#include <__config>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__type_traits/is_execution_policy.h>
|
||||
#include <__utility/move.h>
|
||||
#include <__utility/terminate_on_exception.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator1,
|
||||
class _ForwardIterator2,
|
||||
class _ForwardOutIterator,
|
||||
class _Comp>
|
||||
_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator __pstl_merge(
|
||||
__cpu_backend_tag,
|
||||
_ForwardIterator1 __first1,
|
||||
_ForwardIterator1 __last1,
|
||||
_ForwardIterator2 __first2,
|
||||
_ForwardIterator2 __last2,
|
||||
_ForwardOutIterator __result,
|
||||
_Comp __comp) {
|
||||
if constexpr (__is_parallel_execution_policy_v<_ExecutionPolicy> &&
|
||||
__has_random_access_iterator_category<_ForwardIterator1>::value &&
|
||||
__has_random_access_iterator_category<_ForwardIterator2>::value &&
|
||||
__has_random_access_iterator_category<_ForwardOutIterator>::value) {
|
||||
return std::__terminate_on_exception([&] {
|
||||
__par_backend::__parallel_merge(
|
||||
__first1,
|
||||
__last1,
|
||||
__first2,
|
||||
__last2,
|
||||
__result,
|
||||
__comp,
|
||||
[](_ForwardIterator1 __g_first1,
|
||||
_ForwardIterator1 __g_last1,
|
||||
_ForwardIterator2 __g_first2,
|
||||
_ForwardIterator2 __g_last2,
|
||||
_ForwardOutIterator __g_result,
|
||||
_Comp __g_comp) {
|
||||
return std::__pstl_merge<__remove_parallel_policy_t<_ExecutionPolicy>>(
|
||||
__cpu_backend_tag{},
|
||||
std::move(__g_first1),
|
||||
std::move(__g_last1),
|
||||
std::move(__g_first2),
|
||||
std::move(__g_last2),
|
||||
std::move(__g_result),
|
||||
std::move(__g_comp));
|
||||
});
|
||||
return __result + (__last1 - __first1) + (__last2 - __first2);
|
||||
});
|
||||
} else {
|
||||
return std::merge(__first1, __last1, __first2, __last2, __result, __comp);
|
||||
}
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKENDS_MERGE_H
|
|
@ -1,58 +0,0 @@
|
|||
// -*- 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_PSTL_BACKENDS_CPU_BACKENDS_SERIAL_H
|
||||
#define _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKENDS_SERIAL_H
|
||||
|
||||
#include <__config>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
namespace __par_backend {
|
||||
inline namespace __serial_cpu_backend {
|
||||
|
||||
template <class _RandomAccessIterator, class _Fp>
|
||||
_LIBCPP_HIDE_FROM_ABI void __parallel_for(_RandomAccessIterator __first, _RandomAccessIterator __last, _Fp __f) {
|
||||
__f(__first, __last);
|
||||
}
|
||||
|
||||
_LIBCPP_HIDE_FROM_ABI inline void __cancel_execution() {}
|
||||
|
||||
template <class _RandomAccessIterator1,
|
||||
class _RandomAccessIterator2,
|
||||
class _RandomAccessIterator3,
|
||||
class _Compare,
|
||||
class _LeafMerge>
|
||||
_LIBCPP_HIDE_FROM_ABI void __parallel_merge(
|
||||
_RandomAccessIterator1 __first1,
|
||||
_RandomAccessIterator1 __last1,
|
||||
_RandomAccessIterator2 __first2,
|
||||
_RandomAccessIterator2 __last2,
|
||||
_RandomAccessIterator3 __outit,
|
||||
_Compare __comp,
|
||||
_LeafMerge __leaf_merge) {
|
||||
__leaf_merge(__first1, __last1, __first2, __last2, __outit, __comp);
|
||||
}
|
||||
|
||||
// TODO: Complete this list
|
||||
|
||||
} // namespace __serial_cpu_backend
|
||||
} // namespace __par_backend
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && && _LIBCPP_STD_VER >= 17
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKENDS_SERIAL_H
|
|
@ -1,59 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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_PSTL_BACKENDS_CPU_BACKENDS_THREAD_H
|
||||
#define _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKENDS_THREAD_H
|
||||
|
||||
#include <__assert>
|
||||
#include <__config>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
// This backend implementation is for testing purposes only and not meant for production use. This will be replaced
|
||||
// by a proper implementation once the PSTL implementation is somewhat stable.
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
namespace __par_backend {
|
||||
inline namespace __thread_cpu_backend {
|
||||
|
||||
template <class _RandomAccessIterator, class _Fp>
|
||||
_LIBCPP_HIDE_FROM_ABI void __parallel_for(_RandomAccessIterator __first, _RandomAccessIterator __last, _Fp __f) {
|
||||
__f(__first, __last);
|
||||
}
|
||||
|
||||
_LIBCPP_HIDE_FROM_ABI inline void __cancel_execution() {}
|
||||
|
||||
template <class _RandomAccessIterator1,
|
||||
class _RandomAccessIterator2,
|
||||
class _RandomAccessIterator3,
|
||||
class _Compare,
|
||||
class _LeafMerge>
|
||||
_LIBCPP_HIDE_FROM_ABI void __parallel_merge(
|
||||
_RandomAccessIterator1 __first1,
|
||||
_RandomAccessIterator1 __last1,
|
||||
_RandomAccessIterator2 __first2,
|
||||
_RandomAccessIterator2 __last2,
|
||||
_RandomAccessIterator3 __outit,
|
||||
_Compare __comp,
|
||||
_LeafMerge __leaf_merge) {
|
||||
__leaf_merge(__first1, __last1, __first2, __last2, __outit, __comp);
|
||||
}
|
||||
|
||||
} // namespace __thread_cpu_backend
|
||||
} // namespace __par_backend
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && && _LIBCPP_STD_VER >= 17
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKENDS_THREAD_H
|
|
@ -1,132 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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_PSTL_BACKENDS_CPU_BACKENDS_TRANSFORM_H
|
||||
#define _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKENDS_TRANSFORM_H
|
||||
|
||||
#include <__algorithm/pstl_backends/cpu_backends/backend.h>
|
||||
#include <__algorithm/transform.h>
|
||||
#include <__config>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__type_traits/enable_if.h>
|
||||
#include <__type_traits/is_execution_policy.h>
|
||||
#include <__type_traits/remove_cvref.h>
|
||||
#include <__utility/terminate_on_exception.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _Iterator1, class _DifferenceType, class _Iterator2, class _Function>
|
||||
_LIBCPP_HIDE_FROM_ABI _Iterator2
|
||||
__simd_walk_2(_Iterator1 __first1, _DifferenceType __n, _Iterator2 __first2, _Function __f) noexcept {
|
||||
_PSTL_PRAGMA_SIMD
|
||||
for (_DifferenceType __i = 0; __i < __n; ++__i)
|
||||
__f(__first1[__i], __first2[__i]);
|
||||
return __first2 + __n;
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy, class _ForwardIterator, class _ForwardOutIterator, class _UnaryOperation>
|
||||
_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator __pstl_transform(
|
||||
__cpu_backend_tag,
|
||||
_ForwardIterator __first,
|
||||
_ForwardIterator __last,
|
||||
_ForwardOutIterator __result,
|
||||
_UnaryOperation __op) {
|
||||
if constexpr (__is_parallel_execution_policy_v<_ExecutionPolicy> &&
|
||||
__has_random_access_iterator_category<_ForwardIterator>::value &&
|
||||
__has_random_access_iterator_category<_ForwardOutIterator>::value) {
|
||||
std::__terminate_on_exception([&] {
|
||||
std::__par_backend::__parallel_for(
|
||||
__first, __last, [__op, __first, __result](_ForwardIterator __brick_first, _ForwardIterator __brick_last) {
|
||||
return std::__pstl_transform<__remove_parallel_policy_t<_ExecutionPolicy>>(
|
||||
__cpu_backend_tag{}, __brick_first, __brick_last, __result + (__brick_first - __first), __op);
|
||||
});
|
||||
});
|
||||
return __result + (__last - __first);
|
||||
} else if constexpr (__is_unsequenced_execution_policy_v<_ExecutionPolicy> &&
|
||||
__has_random_access_iterator_category<_ForwardIterator>::value &&
|
||||
__has_random_access_iterator_category<_ForwardOutIterator>::value) {
|
||||
return std::__simd_walk_2(
|
||||
__first,
|
||||
__last - __first,
|
||||
__result,
|
||||
[&](__iter_reference<_ForwardIterator> __in_value, __iter_reference<_ForwardOutIterator> __out_value) {
|
||||
__out_value = __op(__in_value);
|
||||
});
|
||||
} else {
|
||||
return std::transform(__first, __last, __result, __op);
|
||||
}
|
||||
}
|
||||
|
||||
template <class _Iterator1, class _DifferenceType, class _Iterator2, class _Iterator3, class _Function>
|
||||
_LIBCPP_HIDE_FROM_ABI _Iterator3 __simd_walk_3(
|
||||
_Iterator1 __first1, _DifferenceType __n, _Iterator2 __first2, _Iterator3 __first3, _Function __f) noexcept {
|
||||
_PSTL_PRAGMA_SIMD
|
||||
for (_DifferenceType __i = 0; __i < __n; ++__i)
|
||||
__f(__first1[__i], __first2[__i], __first3[__i]);
|
||||
return __first3 + __n;
|
||||
}
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator1,
|
||||
class _ForwardIterator2,
|
||||
class _ForwardOutIterator,
|
||||
class _BinaryOperation,
|
||||
enable_if_t<is_execution_policy_v<__remove_cvref_t<_ExecutionPolicy>>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator __pstl_transform(
|
||||
__cpu_backend_tag,
|
||||
_ForwardIterator1 __first1,
|
||||
_ForwardIterator1 __last1,
|
||||
_ForwardIterator2 __first2,
|
||||
_ForwardOutIterator __result,
|
||||
_BinaryOperation __op) {
|
||||
if constexpr (__is_parallel_execution_policy_v<_ExecutionPolicy> &&
|
||||
__has_random_access_iterator_category<_ForwardIterator1>::value &&
|
||||
__has_random_access_iterator_category<_ForwardIterator2>::value &&
|
||||
__has_random_access_iterator_category<_ForwardOutIterator>::value) {
|
||||
std::__terminate_on_exception([&] {
|
||||
std::__par_backend::__parallel_for(
|
||||
__first1,
|
||||
__last1,
|
||||
[__op, __first1, __first2, __result](_ForwardIterator1 __brick_first, _ForwardIterator1 __brick_last) {
|
||||
return std::__pstl_transform<__remove_parallel_policy_t<_ExecutionPolicy>>(
|
||||
__cpu_backend_tag{},
|
||||
__brick_first,
|
||||
__brick_last,
|
||||
__first2 + (__brick_first - __first1),
|
||||
__result + (__brick_first - __first1),
|
||||
__op);
|
||||
});
|
||||
});
|
||||
return __result + (__last1 - __first1);
|
||||
} else if constexpr (__is_unsequenced_execution_policy_v<_ExecutionPolicy> &&
|
||||
__has_random_access_iterator_category<_ForwardIterator1>::value &&
|
||||
__has_random_access_iterator_category<_ForwardIterator2>::value &&
|
||||
__has_random_access_iterator_category<_ForwardOutIterator>::value) {
|
||||
return std::__simd_walk_3(
|
||||
__first1,
|
||||
__last1 - __first1,
|
||||
__first2,
|
||||
__result,
|
||||
[&](__iter_reference<_ForwardIterator1> __in1,
|
||||
__iter_reference<_ForwardIterator2> __in2,
|
||||
__iter_reference<_ForwardOutIterator> __out_value) { __out_value = __op(__in1, __in2); });
|
||||
} else {
|
||||
return std::transform(__first1, __last1, __first2, __result, __op);
|
||||
}
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKENDS_TRANSFORM_H
|
57
third_party/libcxx/__algorithm/pstl_copy.h
vendored
57
third_party/libcxx/__algorithm/pstl_copy.h
vendored
|
@ -1,57 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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_PSTL_COPY_H
|
||||
#define _LIBCPP___ALGORITHM_PSTL_COPY_H
|
||||
|
||||
#include <__algorithm/copy_n.h>
|
||||
#include <__algorithm/pstl_transform.h>
|
||||
#include <__config>
|
||||
#include <__functional/identity.h>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__type_traits/is_constant_evaluated.h>
|
||||
#include <__type_traits/is_execution_policy.h>
|
||||
#include <__type_traits/is_trivially_copyable.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
// TODO: Use the std::copy/move shenanigans to forward to std::memmove
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator,
|
||||
class _ForwardOutIterator,
|
||||
enable_if_t<is_execution_policy_v<__remove_cvref_t<_ExecutionPolicy>>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator
|
||||
copy(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _ForwardOutIterator __result) {
|
||||
return std::transform(__policy, __first, __last, __result, __identity());
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator,
|
||||
class _ForwardOutIterator,
|
||||
class _Size,
|
||||
enable_if_t<is_execution_policy_v<__remove_cvref_t<_ExecutionPolicy>>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator
|
||||
copy_n(_ExecutionPolicy&& __policy, _ForwardIterator __first, _Size __n, _ForwardOutIterator __result) {
|
||||
if constexpr (__has_random_access_iterator_category<_ForwardIterator>::value)
|
||||
return std::copy(__policy, __first, __first + __n, __result);
|
||||
else
|
||||
return std::copy_n(__first, __n, __result);
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_PSTL_COPY_H
|
79
third_party/libcxx/__algorithm/pstl_fill.h
vendored
79
third_party/libcxx/__algorithm/pstl_fill.h
vendored
|
@ -1,79 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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_PSTL_FILL_H
|
||||
#define _LIBCPP___ALGORITHM_PSTL_FILL_H
|
||||
|
||||
#include <__algorithm/fill_n.h>
|
||||
#include <__algorithm/pstl_for_each.h>
|
||||
#include <__algorithm/pstl_frontend_dispatch.h>
|
||||
#include <__config>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__type_traits/is_execution_policy.h>
|
||||
#include <__type_traits/remove_cvref.h>
|
||||
#include <__utility/terminate_on_exception.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class>
|
||||
void __pstl_fill(); // declaration needed for the frontend dispatch below
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator,
|
||||
class _Tp,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI void
|
||||
fill(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
|
||||
std::__pstl_frontend_dispatch(
|
||||
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_fill),
|
||||
[&](_ForwardIterator __g_first, _ForwardIterator __g_last, const _Tp& __g_value) {
|
||||
std::for_each(__policy, __g_first, __g_last, [&](__iter_reference<_ForwardIterator> __element) {
|
||||
__element = __g_value;
|
||||
});
|
||||
},
|
||||
std::move(__first),
|
||||
std::move(__last),
|
||||
__value);
|
||||
}
|
||||
|
||||
template <class>
|
||||
void __pstl_fill_n(); // declaration needed for the frontend dispatch below
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator,
|
||||
class _SizeT,
|
||||
class _Tp,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI void
|
||||
fill_n(_ExecutionPolicy&& __policy, _ForwardIterator __first, _SizeT __n, const _Tp& __value) {
|
||||
std::__pstl_frontend_dispatch(
|
||||
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_fill_n),
|
||||
[&](_ForwardIterator __g_first, _SizeT __g_n, const _Tp& __g_value) {
|
||||
if constexpr (__has_random_access_iterator_category<_ForwardIterator>::value)
|
||||
std::fill(__policy, __g_first, __g_first + __g_n, __g_value);
|
||||
else
|
||||
std::fill_n(__g_first, __g_n, __g_value);
|
||||
},
|
||||
std::move(__first),
|
||||
__n,
|
||||
__value);
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_PSTL_FILL_H
|
89
third_party/libcxx/__algorithm/pstl_find.h
vendored
89
third_party/libcxx/__algorithm/pstl_find.h
vendored
|
@ -1,89 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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_PSTL_FIND_H
|
||||
#define _LIBCPP___ALGORITHM_PSTL_FIND_H
|
||||
|
||||
#include <__algorithm/comp.h>
|
||||
#include <__algorithm/find.h>
|
||||
#include <__algorithm/pstl_backend.h>
|
||||
#include <__algorithm/pstl_frontend_dispatch.h>
|
||||
#include <__config>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__type_traits/is_execution_policy.h>
|
||||
#include <__type_traits/remove_cvref.h>
|
||||
#include <__utility/terminate_on_exception.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator,
|
||||
class _Predicate,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI _ForwardIterator
|
||||
find_if(_ExecutionPolicy&&, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
|
||||
using _Backend = typename __select_backend<_RawPolicy>::type;
|
||||
return std::__pstl_find_if<_RawPolicy>(_Backend{}, std::move(__first), std::move(__last), std::move(__pred));
|
||||
}
|
||||
|
||||
template <class>
|
||||
void __pstl_find_if_not();
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator,
|
||||
class _Predicate,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI _ForwardIterator
|
||||
find_if_not(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
|
||||
return std::__pstl_frontend_dispatch(
|
||||
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_find_if_not),
|
||||
[&](_ForwardIterator __g_first, _ForwardIterator __g_last, _Predicate __g_pred) {
|
||||
return std::find_if(__policy, __g_first, __g_last, [&](__iter_reference<_ForwardIterator> __value) {
|
||||
return !__g_pred(__value);
|
||||
});
|
||||
},
|
||||
std::move(__first),
|
||||
std::move(__last),
|
||||
std::move(__pred));
|
||||
}
|
||||
|
||||
template <class>
|
||||
void __pstl_find();
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator,
|
||||
class _Tp,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI _ForwardIterator
|
||||
find(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
|
||||
return std::__pstl_frontend_dispatch(
|
||||
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_find),
|
||||
[&](_ForwardIterator __g_first, _ForwardIterator __g_last, const _Tp& __g_value) {
|
||||
return std::find_if(__policy, __g_first, __g_last, [&](__iter_reference<_ForwardIterator> __element) {
|
||||
return __element == __g_value;
|
||||
});
|
||||
},
|
||||
std::move(__first),
|
||||
std::move(__last),
|
||||
__value);
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_PSTL_FIND_H
|
71
third_party/libcxx/__algorithm/pstl_for_each.h
vendored
71
third_party/libcxx/__algorithm/pstl_for_each.h
vendored
|
@ -1,71 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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_PSTL_FOR_EACH_H
|
||||
#define _LIBCPP___ALGORITHM_PSTL_FOR_EACH_H
|
||||
|
||||
#include <__algorithm/for_each.h>
|
||||
#include <__algorithm/for_each_n.h>
|
||||
#include <__algorithm/pstl_backend.h>
|
||||
#include <__algorithm/pstl_frontend_dispatch.h>
|
||||
#include <__config>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__type_traits/is_execution_policy.h>
|
||||
#include <__type_traits/remove_cvref.h>
|
||||
#include <__type_traits/void_t.h>
|
||||
#include <__utility/terminate_on_exception.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator,
|
||||
class _Function,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI void
|
||||
for_each(_ExecutionPolicy&&, _ForwardIterator __first, _ForwardIterator __last, _Function __func) {
|
||||
using _Backend = typename __select_backend<_RawPolicy>::type;
|
||||
std::__pstl_for_each<_RawPolicy>(_Backend{}, std::move(__first), std::move(__last), std::move(__func));
|
||||
}
|
||||
|
||||
template <class>
|
||||
void __pstl_for_each_n(); // declaration needed for the frontend dispatch below
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator,
|
||||
class _Size,
|
||||
class _Function,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI void
|
||||
for_each_n(_ExecutionPolicy&& __policy, _ForwardIterator __first, _Size __size, _Function __func) {
|
||||
return std::__pstl_frontend_dispatch(
|
||||
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_for_each_n),
|
||||
[&](_ForwardIterator __g_first, _Size __g_size, _Function __g_func) {
|
||||
if constexpr (__has_random_access_iterator_category<_ForwardIterator>::value) {
|
||||
std::for_each(__policy, std::move(__g_first), __g_first + __g_size, std::move(__g_func));
|
||||
} else {
|
||||
std::for_each_n(std::move(__g_first), __g_size, std::move(__g_func));
|
||||
}
|
||||
},
|
||||
__first,
|
||||
__size,
|
||||
std::move(__func));
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_PSTL_FOR_EACH_H
|
|
@ -1,45 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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_PSTL_FRONTEND_DISPATCH
|
||||
#define _LIBCPP___ALGORITHM_PSTL_FRONTEND_DISPATCH
|
||||
|
||||
#include <__config>
|
||||
#include <__type_traits/is_callable.h>
|
||||
#include <__utility/forward.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if _LIBCPP_STD_VER >= 17
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
# define _LIBCPP_PSTL_CUSTOMIZATION_POINT(name) \
|
||||
[](auto&&... __args) -> decltype(std::name<_RawPolicy>(typename __select_backend<_RawPolicy>::type{}, \
|
||||
std::forward<decltype(__args)>(__args)...)) { \
|
||||
return std::name<_RawPolicy>( \
|
||||
typename __select_backend<_RawPolicy>::type{}, std::forward<decltype(__args)>(__args)...); \
|
||||
}
|
||||
|
||||
template <class _SpecializedImpl, class _GenericImpl, class... _Args>
|
||||
_LIBCPP_HIDE_FROM_ABI decltype(auto)
|
||||
__pstl_frontend_dispatch(_SpecializedImpl __specialized_impl, _GenericImpl __generic_impl, _Args&&... __args) {
|
||||
if constexpr (__is_callable<_SpecializedImpl, _Args...>::value) {
|
||||
return __specialized_impl(std::forward<_Args>(__args)...);
|
||||
} else {
|
||||
return __generic_impl(std::forward<_Args>(__args)...);
|
||||
}
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_STD_VER >= 17
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_PSTL_FRONTEND_DISPATCH
|
56
third_party/libcxx/__algorithm/pstl_merge.h
vendored
56
third_party/libcxx/__algorithm/pstl_merge.h
vendored
|
@ -1,56 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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_PSTL_MERGE_H
|
||||
#define _LIBCPP___ALGORITHM_PSTL_MERGE_H
|
||||
|
||||
#include <__algorithm/pstl_backend.h>
|
||||
#include <__config>
|
||||
#include <__functional/operations.h>
|
||||
#include <__type_traits/is_execution_policy.h>
|
||||
#include <__type_traits/remove_cvref.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator1,
|
||||
class _ForwardIterator2,
|
||||
class _ForwardOutIterator,
|
||||
class _Comp = std::less<>,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator
|
||||
merge(_ExecutionPolicy&&,
|
||||
_ForwardIterator1 __first1,
|
||||
_ForwardIterator1 __last1,
|
||||
_ForwardIterator2 __first2,
|
||||
_ForwardIterator2 __last2,
|
||||
_ForwardOutIterator __result,
|
||||
_Comp __comp = {}) {
|
||||
using _Backend = typename __select_backend<_RawPolicy>::type;
|
||||
return std::__pstl_merge<_RawPolicy>(
|
||||
_Backend{},
|
||||
std::move(__first1),
|
||||
std::move(__last1),
|
||||
std::move(__first2),
|
||||
std::move(__last2),
|
||||
std::move(__result),
|
||||
std::move(__comp));
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_PSTL_MERGE_H
|
66
third_party/libcxx/__algorithm/pstl_transform.h
vendored
66
third_party/libcxx/__algorithm/pstl_transform.h
vendored
|
@ -1,66 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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_PSTL_TRANSFORM_H
|
||||
#define _LIBCPP___ALGORITHM_PSTL_TRANSFORM_H
|
||||
|
||||
#include <__algorithm/pstl_backend.h>
|
||||
#include <__config>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__type_traits/is_execution_policy.h>
|
||||
#include <__utility/terminate_on_exception.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator,
|
||||
class _ForwardOutIterator,
|
||||
class _UnaryOperation,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator transform(
|
||||
_ExecutionPolicy&&,
|
||||
_ForwardIterator __first,
|
||||
_ForwardIterator __last,
|
||||
_ForwardOutIterator __result,
|
||||
_UnaryOperation __op) {
|
||||
using _Backend = typename __select_backend<_RawPolicy>::type;
|
||||
return std::__pstl_transform<_RawPolicy>(
|
||||
_Backend{}, std::move(__first), std::move(__last), std::move(__result), std::move(__op));
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator1,
|
||||
class _ForwardIterator2,
|
||||
class _ForwardOutIterator,
|
||||
class _BinaryOperation,
|
||||
class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
|
||||
enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator transform(
|
||||
_ExecutionPolicy&&,
|
||||
_ForwardIterator1 __first1,
|
||||
_ForwardIterator1 __last1,
|
||||
_ForwardIterator2 __first2,
|
||||
_ForwardOutIterator __result,
|
||||
_BinaryOperation __op) {
|
||||
using _Backend = typename __select_backend<_RawPolicy>::type;
|
||||
return std::__pstl_transform<_RawPolicy>(
|
||||
_Backend{}, std::move(__first1), std::move(__last1), std::move(__first2), std::move(__result), std::move(__op));
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_PSTL_TRANSFORM_H
|
36
third_party/libcxx/__algorithm/push_heap.h
vendored
36
third_party/libcxx/__algorithm/push_heap.h
vendored
|
@ -14,31 +14,36 @@
|
|||
#include <__algorithm/iterator_operations.h>
|
||||
#include <__config>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__type_traits/is_copy_assignable.h>
|
||||
#include <__type_traits/is_copy_constructible.h>
|
||||
#include <__type_traits/is_assignable.h>
|
||||
#include <__type_traits/is_constructible.h>
|
||||
#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
|
||||
|
||||
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
|
||||
void __sift_up(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare&& __comp,
|
||||
typename iterator_traits<_RandomAccessIterator>::difference_type __len) {
|
||||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 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;
|
||||
__len = (__len - 2) / 2;
|
||||
_RandomAccessIterator __ptr = __first + __len;
|
||||
|
||||
if (__comp(*__ptr, *--__last)) {
|
||||
value_type __t(_IterOps<_AlgPolicy>::__iter_move(__last));
|
||||
do {
|
||||
*__last = _IterOps<_AlgPolicy>::__iter_move(__ptr);
|
||||
__last = __ptr;
|
||||
__last = __ptr;
|
||||
if (__len == 0)
|
||||
break;
|
||||
__len = (__len - 1) / 2;
|
||||
|
@ -51,15 +56,15 @@ void __sift_up(_RandomAccessIterator __first, _RandomAccessIterator __last, _Com
|
|||
}
|
||||
|
||||
template <class _AlgPolicy, class _RandomAccessIterator, class _Compare>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
|
||||
void __push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare& __comp) {
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
|
||||
__push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare& __comp) {
|
||||
typename iterator_traits<_RandomAccessIterator>::difference_type __len = __last - __first;
|
||||
std::__sift_up<_AlgPolicy, __comp_ref_type<_Compare> >(std::move(__first), std::move(__last), __comp, __len);
|
||||
}
|
||||
|
||||
template <class _RandomAccessIterator, class _Compare>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
void push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) {
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 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.");
|
||||
|
||||
|
@ -67,12 +72,13 @@ void push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Com
|
|||
}
|
||||
|
||||
template <class _RandomAccessIterator>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
|
||||
void push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) {
|
||||
std::push_heap(std::move(__first), std::move(__last),
|
||||
__less<typename iterator_traits<_RandomAccessIterator>::value_type>());
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
|
||||
push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) {
|
||||
std::push_heap(std::move(__first), std::move(__last), __less<>());
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_PUSH_HEAP_H
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_PUSH_MACROS
|
||||
#include <__undef_macros>
|
||||
|
||||
#if _LIBCPP_STD_VER >= 20
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
@ -31,10 +34,9 @@ _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) {
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr static _Iter
|
||||
__adjacent_find_impl(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
|
||||
if (__first == __last)
|
||||
return __first;
|
||||
|
||||
|
@ -47,27 +49,28 @@ struct __fn {
|
|||
return __i;
|
||||
}
|
||||
|
||||
template <forward_iterator _Iter, sentinel_for<_Iter> _Sent,
|
||||
class _Proj = identity,
|
||||
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_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr
|
||||
_Iter operator()(_Iter __first, _Sent __last, _Pred __pred = {}, _Proj __proj = {}) const {
|
||||
[[nodiscard]] _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_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr
|
||||
borrowed_iterator_t<_Range> operator()(_Range&& __range, _Pred __pred = {}, _Proj __proj = {}) const {
|
||||
indirect_binary_predicate<projected<iterator_t<_Range>, _Proj>, projected<iterator_t<_Range>, _Proj>>
|
||||
_Pred = ranges::equal_to>
|
||||
[[nodiscard]] _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{};
|
||||
inline constexpr auto adjacent_find = __adjacent_find::__fn{};
|
||||
} // namespace __cpo
|
||||
} // namespace ranges
|
||||
|
||||
|
@ -75,4 +78,6 @@ _LIBCPP_END_NAMESPACE_STD
|
|||
|
||||
#endif // _LIBCPP_STD_VER >= 20
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_RANGES_ADJACENT_FIND_H
|
||||
|
|
26
third_party/libcxx/__algorithm/ranges_all_of.h
vendored
26
third_party/libcxx/__algorithm/ranges_all_of.h
vendored
|
@ -22,6 +22,9 @@
|
|||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_PUSH_MACROS
|
||||
#include <__undef_macros>
|
||||
|
||||
#if _LIBCPP_STD_VER >= 20
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
@ -29,10 +32,8 @@ _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) {
|
||||
_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;
|
||||
|
@ -40,24 +41,27 @@ struct __fn {
|
|||
return true;
|
||||
}
|
||||
|
||||
template <input_iterator _Iter, sentinel_for<_Iter> _Sent, class _Proj = identity,
|
||||
template <input_iterator _Iter,
|
||||
sentinel_for<_Iter> _Sent,
|
||||
class _Proj = identity,
|
||||
indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
|
||||
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr
|
||||
bool operator()(_Iter __first, _Sent __last, _Pred __pred, _Proj __proj = {}) const {
|
||||
[[nodiscard]] _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,
|
||||
template <input_range _Range,
|
||||
class _Proj = identity,
|
||||
indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>> _Pred>
|
||||
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr
|
||||
bool operator()(_Range&& __range, _Pred __pred, _Proj __proj = {}) const {
|
||||
[[nodiscard]] _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{};
|
||||
inline constexpr auto all_of = __all_of::__fn{};
|
||||
} // namespace __cpo
|
||||
} // namespace ranges
|
||||
|
||||
|
@ -65,4 +69,6 @@ _LIBCPP_END_NAMESPACE_STD
|
|||
|
||||
#endif // _LIBCPP_STD_VER >= 20
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_RANGES_ALL_OF_H
|
||||
|
|
26
third_party/libcxx/__algorithm/ranges_any_of.h
vendored
26
third_party/libcxx/__algorithm/ranges_any_of.h
vendored
|
@ -22,6 +22,9 @@
|
|||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_PUSH_MACROS
|
||||
#include <__undef_macros>
|
||||
|
||||
#if _LIBCPP_STD_VER >= 20
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
@ -29,10 +32,8 @@ _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) {
|
||||
_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;
|
||||
|
@ -40,24 +41,27 @@ struct __fn {
|
|||
return false;
|
||||
}
|
||||
|
||||
template <input_iterator _Iter, sentinel_for<_Iter> _Sent, class _Proj = identity,
|
||||
template <input_iterator _Iter,
|
||||
sentinel_for<_Iter> _Sent,
|
||||
class _Proj = identity,
|
||||
indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
|
||||
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr
|
||||
bool operator()(_Iter __first, _Sent __last, _Pred __pred = {}, _Proj __proj = {}) const {
|
||||
[[nodiscard]] _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,
|
||||
template <input_range _Range,
|
||||
class _Proj = identity,
|
||||
indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>> _Pred>
|
||||
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr
|
||||
bool operator()(_Range&& __range, _Pred __pred, _Proj __proj = {}) const {
|
||||
[[nodiscard]] _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{};
|
||||
inline constexpr auto any_of = __any_of::__fn{};
|
||||
} // namespace __cpo
|
||||
} // namespace ranges
|
||||
|
||||
|
@ -65,4 +69,6 @@ _LIBCPP_END_NAMESPACE_STD
|
|||
|
||||
#endif // _LIBCPP_STD_VER >= 20
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_RANGES_ANY_OF_H
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_PUSH_MACROS
|
||||
#include <__undef_macros>
|
||||
|
||||
#if _LIBCPP_STD_VER >= 20
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
@ -31,28 +34,33 @@ _LIBCPP_BEGIN_NAMESPACE_STD
|
|||
namespace ranges {
|
||||
namespace __binary_search {
|
||||
struct __fn {
|
||||
template <forward_iterator _Iter, sentinel_for<_Iter> _Sent, class _Type, class _Proj = identity,
|
||||
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_NODISCARD_EXT _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);
|
||||
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool
|
||||
operator()(_Iter __first, _Sent __last, const _Type& __value, _Comp __comp = {}, _Proj __proj = {}) const {
|
||||
auto __ret = std::__lower_bound<_RangeAlgPolicy>(__first, __last, __value, __comp, __proj);
|
||||
return __ret != __last && !std::invoke(__comp, __value, std::invoke(__proj, *__ret));
|
||||
}
|
||||
|
||||
template <forward_range _Range, class _Type, class _Proj = identity,
|
||||
template <forward_range _Range,
|
||||
class _Type,
|
||||
class _Proj = identity,
|
||||
indirect_strict_weak_order<const _Type*, projected<iterator_t<_Range>, _Proj>> _Comp = ranges::less>
|
||||
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr
|
||||
bool operator()(_Range&& __r, const _Type& __value, _Comp __comp = {}, _Proj __proj = {}) const {
|
||||
[[nodiscard]] _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);
|
||||
auto __last = ranges::end(__r);
|
||||
auto __ret = std::__lower_bound<_RangeAlgPolicy>(__first, __last, __value, __comp, __proj);
|
||||
return __ret != __last && !std::invoke(__comp, __value, std::invoke(__proj, *__ret));
|
||||
}
|
||||
};
|
||||
} // namespace __binary_search
|
||||
|
||||
inline namespace __cpo {
|
||||
inline constexpr auto binary_search = __binary_search::__fn{};
|
||||
inline constexpr auto binary_search = __binary_search::__fn{};
|
||||
} // namespace __cpo
|
||||
} // namespace ranges
|
||||
|
||||
|
@ -60,4 +68,6 @@ _LIBCPP_END_NAMESPACE_STD
|
|||
|
||||
#endif // _LIBCPP_STD_VER >= 20
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_RANGES_BINARY_SEARCH_H
|
||||
|
|
29
third_party/libcxx/__algorithm/ranges_clamp.h
vendored
29
third_party/libcxx/__algorithm/ranges_clamp.h
vendored
|
@ -22,6 +22,9 @@
|
|||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_PUSH_MACROS
|
||||
#include <__undef_macros>
|
||||
|
||||
#if _LIBCPP_STD_VER >= 20
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
@ -29,32 +32,28 @@ _LIBCPP_BEGIN_NAMESPACE_STD
|
|||
namespace ranges {
|
||||
namespace __clamp {
|
||||
struct __fn {
|
||||
|
||||
template <class _Type,
|
||||
class _Proj = identity,
|
||||
class _Proj = identity,
|
||||
indirect_strict_weak_order<projected<const _Type*, _Proj>> _Comp = ranges::less>
|
||||
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr
|
||||
const _Type& operator()(const _Type& __value,
|
||||
const _Type& __low,
|
||||
const _Type& __high,
|
||||
_Comp __comp = {},
|
||||
_Proj __proj = {}) const {
|
||||
_LIBCPP_ASSERT(!bool(std::invoke(__comp, std::invoke(__proj, __high), std::invoke(__proj, __low))),
|
||||
"Bad bounds passed to std::ranges::clamp");
|
||||
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const _Type& operator()(
|
||||
const _Type& __value, const _Type& __low, const _Type& __high, _Comp __comp = {}, _Proj __proj = {}) const {
|
||||
_LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(
|
||||
!bool(std::invoke(__comp, std::invoke(__proj, __high), std::invoke(__proj, __low))),
|
||||
"Bad bounds passed to std::ranges::clamp");
|
||||
|
||||
if (std::invoke(__comp, std::invoke(__proj, __value), std::invoke(__proj, __low)))
|
||||
auto&& __projected = std::invoke(__proj, __value);
|
||||
if (std::invoke(__comp, std::forward<decltype(__projected)>(__projected), std::invoke(__proj, __low)))
|
||||
return __low;
|
||||
else if (std::invoke(__comp, std::invoke(__proj, __high), std::invoke(__proj, __value)))
|
||||
else if (std::invoke(__comp, std::invoke(__proj, __high), std::forward<decltype(__projected)>(__projected)))
|
||||
return __high;
|
||||
else
|
||||
return __value;
|
||||
}
|
||||
|
||||
};
|
||||
} // namespace __clamp
|
||||
|
||||
inline namespace __cpo {
|
||||
inline constexpr auto clamp = __clamp::__fn{};
|
||||
inline constexpr auto clamp = __clamp::__fn{};
|
||||
} // namespace __cpo
|
||||
} // namespace ranges
|
||||
|
||||
|
@ -62,4 +61,6 @@ _LIBCPP_END_NAMESPACE_STD
|
|||
|
||||
#endif // _LIBCPP_STD_VER >= 20
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_RANGES_CLAMP_H
|
||||
|
|
66
third_party/libcxx/__algorithm/ranges_contains.h
vendored
Normal file
66
third_party/libcxx/__algorithm/ranges_contains.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_CONTAINS_H
|
||||
#define _LIBCPP___ALGORITHM_RANGES_CONTAINS_H
|
||||
|
||||
#include <__algorithm/ranges_find.h>
|
||||
#include <__config>
|
||||
#include <__functional/identity.h>
|
||||
#include <__functional/ranges_operations.h>
|
||||
#include <__functional/reference_wrapper.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
|
||||
|
||||
_LIBCPP_PUSH_MACROS
|
||||
#include <__undef_macros>
|
||||
|
||||
#if _LIBCPP_STD_VER >= 23
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
namespace ranges {
|
||||
namespace __contains {
|
||||
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*>
|
||||
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool static
|
||||
operator()(_Iter __first, _Sent __last, const _Type& __value, _Proj __proj = {}) {
|
||||
return ranges::find(std::move(__first), __last, __value, std::ref(__proj)) != __last;
|
||||
}
|
||||
|
||||
template <input_range _Range, class _Type, class _Proj = identity>
|
||||
requires indirect_binary_predicate<ranges::equal_to, projected<iterator_t<_Range>, _Proj>, const _Type*>
|
||||
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool static
|
||||
operator()(_Range&& __range, const _Type& __value, _Proj __proj = {}) {
|
||||
return ranges::find(ranges::begin(__range), ranges::end(__range), __value, std::ref(__proj)) !=
|
||||
ranges::end(__range);
|
||||
}
|
||||
};
|
||||
} // namespace __contains
|
||||
|
||||
inline namespace __cpo {
|
||||
inline constexpr auto contains = __contains::__fn{};
|
||||
} // namespace __cpo
|
||||
} // namespace ranges
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_STD_VER >= 23
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_RANGES_CONTAINS_H
|
97
third_party/libcxx/__algorithm/ranges_contains_subrange.h
vendored
Normal file
97
third_party/libcxx/__algorithm/ranges_contains_subrange.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_CONTAINS_SUBRANGE_H
|
||||
#define _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H
|
||||
|
||||
#include <__algorithm/ranges_search.h>
|
||||
#include <__config>
|
||||
#include <__functional/identity.h>
|
||||
#include <__functional/ranges_operations.h>
|
||||
#include <__functional/reference_wrapper.h>
|
||||
#include <__iterator/concepts.h>
|
||||
#include <__iterator/indirectly_comparable.h>
|
||||
#include <__iterator/projected.h>
|
||||
#include <__ranges/access.h>
|
||||
#include <__ranges/concepts.h>
|
||||
#include <__ranges/size.h>
|
||||
#include <__ranges/subrange.h>
|
||||
#include <__utility/move.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_PUSH_MACROS
|
||||
#include <__undef_macros>
|
||||
|
||||
#if _LIBCPP_STD_VER >= 23
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
namespace ranges {
|
||||
namespace __contains_subrange {
|
||||
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>
|
||||
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool static operator()(
|
||||
_Iter1 __first1,
|
||||
_Sent1 __last1,
|
||||
_Iter2 __first2,
|
||||
_Sent2 __last2,
|
||||
_Pred __pred = {},
|
||||
_Proj1 __proj1 = {},
|
||||
_Proj2 __proj2 = {}) {
|
||||
if (__first2 == __last2)
|
||||
return true;
|
||||
|
||||
auto __ret = ranges::search(
|
||||
std::move(__first1), __last1, std::move(__first2), __last2, __pred, std::ref(__proj1), std::ref(__proj2));
|
||||
return __ret.empty() == false;
|
||||
}
|
||||
|
||||
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>
|
||||
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool static
|
||||
operator()(_Range1&& __range1, _Range2&& __range2, _Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) {
|
||||
if constexpr (sized_range<_Range2>) {
|
||||
if (ranges::size(__range2) == 0)
|
||||
return true;
|
||||
} else {
|
||||
if (ranges::begin(__range2) == ranges::end(__range2))
|
||||
return true;
|
||||
}
|
||||
|
||||
auto __ret = ranges::search(__range1, __range2, __pred, std::ref(__proj1), std::ref(__proj2));
|
||||
return __ret.empty() == false;
|
||||
}
|
||||
};
|
||||
} // namespace __contains_subrange
|
||||
|
||||
inline namespace __cpo {
|
||||
inline constexpr auto contains_subrange = __contains_subrange::__fn{};
|
||||
} // namespace __cpo
|
||||
} // namespace ranges
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_STD_VER >= 23
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue