[libc++] Format the code base (#74334)

This patch runs clang-format on all of libcxx/include and libcxx/src, in
accordance with the RFC discussed at [1]. Follow-up patches will format
the benchmarks, the test suite and remaining parts of the code. I'm
splitting this one into its own patch so the diff is a bit easier to
review.

This patch was generated with:

   find libcxx/include libcxx/src -type f \
      | grep -v 'module.modulemap.in' \
      | grep -v 'CMakeLists.txt' \
      | grep -v 'README.txt' \
      | grep -v 'libcxx.imp' \
      | grep -v '__config_site.in' \
      | xargs clang-format -i

A Git merge driver is available in libcxx/utils/clang-format-merge-driver.sh
to help resolve merge and rebase issues across these formatting changes.

[1]: https://discourse.llvm.org/t/rfc-clang-formatting-all-of-libc-once-and-for-all
This commit is contained in:
Louis Dionne 2023-12-18 14:01:33 -05:00 committed by GitHub
parent e5c523e861
commit 9783f28cbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
542 changed files with 66602 additions and 83948 deletions

142
.gitattributes vendored Normal file
View File

@ -0,0 +1,142 @@
libcxx/src/**/*.cpp merge=libcxx-reformat
libcxx/include/**/*.h merge=libcxx-reformat
# Explicitly handle files with no extension
libcxx/include/__availability merge=libcxx-reformat
libcxx/include/__bit_reference merge=libcxx-reformat
libcxx/include/__config merge=libcxx-reformat
libcxx/include/__hash_table merge=libcxx-reformat
libcxx/include/__locale merge=libcxx-reformat
libcxx/include/__node_handle merge=libcxx-reformat
libcxx/include/__split_buffer merge=libcxx-reformat
libcxx/include/__std_clang_module merge=libcxx-reformat
libcxx/include/__threading_support merge=libcxx-reformat
libcxx/include/__tree merge=libcxx-reformat
libcxx/include/__verbose_abort merge=libcxx-reformat
libcxx/include/algorithm merge=libcxx-reformat
libcxx/include/any merge=libcxx-reformat
libcxx/include/array merge=libcxx-reformat
libcxx/include/atomic merge=libcxx-reformat
libcxx/include/barrier merge=libcxx-reformat
libcxx/include/bit merge=libcxx-reformat
libcxx/include/bitset merge=libcxx-reformat
libcxx/include/cassert merge=libcxx-reformat
libcxx/include/ccomplex merge=libcxx-reformat
libcxx/include/cctype merge=libcxx-reformat
libcxx/include/cerrno merge=libcxx-reformat
libcxx/include/cfenv merge=libcxx-reformat
libcxx/include/cfloat merge=libcxx-reformat
libcxx/include/charconv merge=libcxx-reformat
libcxx/include/chrono merge=libcxx-reformat
libcxx/include/cinttypes merge=libcxx-reformat
libcxx/include/ciso646 merge=libcxx-reformat
libcxx/include/climits merge=libcxx-reformat
libcxx/include/clocale merge=libcxx-reformat
libcxx/include/cmath merge=libcxx-reformat
libcxx/include/codecvt merge=libcxx-reformat
libcxx/include/compare merge=libcxx-reformat
libcxx/include/complex merge=libcxx-reformat
libcxx/include/concepts merge=libcxx-reformat
libcxx/include/condition_variable merge=libcxx-reformat
libcxx/include/coroutine merge=libcxx-reformat
libcxx/include/csetjmp merge=libcxx-reformat
libcxx/include/csignal merge=libcxx-reformat
libcxx/include/cstdarg merge=libcxx-reformat
libcxx/include/cstdbool merge=libcxx-reformat
libcxx/include/cstddef merge=libcxx-reformat
libcxx/include/cstdint merge=libcxx-reformat
libcxx/include/cstdio merge=libcxx-reformat
libcxx/include/cstdlib merge=libcxx-reformat
libcxx/include/cstring merge=libcxx-reformat
libcxx/include/ctgmath merge=libcxx-reformat
libcxx/include/ctime merge=libcxx-reformat
libcxx/include/cuchar merge=libcxx-reformat
libcxx/include/cwchar merge=libcxx-reformat
libcxx/include/cwctype merge=libcxx-reformat
libcxx/include/deque merge=libcxx-reformat
libcxx/include/exception merge=libcxx-reformat
libcxx/include/execution merge=libcxx-reformat
libcxx/include/expected merge=libcxx-reformat
libcxx/include/experimental/__config merge=libcxx-reformat
libcxx/include/experimental/__memory merge=libcxx-reformat
libcxx/include/experimental/deque merge=libcxx-reformat
libcxx/include/experimental/forward_list merge=libcxx-reformat
libcxx/include/experimental/iterator merge=libcxx-reformat
libcxx/include/experimental/list merge=libcxx-reformat
libcxx/include/experimental/map merge=libcxx-reformat
libcxx/include/experimental/memory merge=libcxx-reformat
libcxx/include/experimental/memory_resource merge=libcxx-reformat
libcxx/include/experimental/propagate_const merge=libcxx-reformat
libcxx/include/experimental/regex merge=libcxx-reformat
libcxx/include/experimental/set merge=libcxx-reformat
libcxx/include/experimental/simd merge=libcxx-reformat
libcxx/include/experimental/string merge=libcxx-reformat
libcxx/include/experimental/type_traits merge=libcxx-reformat
libcxx/include/experimental/unordered_map merge=libcxx-reformat
libcxx/include/experimental/unordered_set merge=libcxx-reformat
libcxx/include/experimental/utility merge=libcxx-reformat
libcxx/include/experimental/vector merge=libcxx-reformat
libcxx/include/ext/__hash merge=libcxx-reformat
libcxx/include/ext/hash_map merge=libcxx-reformat
libcxx/include/ext/hash_set merge=libcxx-reformat
libcxx/include/filesystem merge=libcxx-reformat
libcxx/include/format merge=libcxx-reformat
libcxx/include/forward_list merge=libcxx-reformat
libcxx/include/fstream merge=libcxx-reformat
libcxx/include/functional merge=libcxx-reformat
libcxx/include/future merge=libcxx-reformat
libcxx/include/initializer_list merge=libcxx-reformat
libcxx/include/iomanip merge=libcxx-reformat
libcxx/include/ios merge=libcxx-reformat
libcxx/include/iosfwd merge=libcxx-reformat
libcxx/include/iostream merge=libcxx-reformat
libcxx/include/istream merge=libcxx-reformat
libcxx/include/iterator merge=libcxx-reformat
libcxx/include/latch merge=libcxx-reformat
libcxx/include/limits merge=libcxx-reformat
libcxx/include/list merge=libcxx-reformat
libcxx/include/locale merge=libcxx-reformat
libcxx/include/map merge=libcxx-reformat
libcxx/include/mdspan merge=libcxx-reformat
libcxx/include/memory merge=libcxx-reformat
libcxx/include/memory_resource merge=libcxx-reformat
libcxx/include/mutex merge=libcxx-reformat
libcxx/include/new merge=libcxx-reformat
libcxx/include/numbers merge=libcxx-reformat
libcxx/include/numeric merge=libcxx-reformat
libcxx/include/optional merge=libcxx-reformat
libcxx/include/ostream merge=libcxx-reformat
libcxx/include/print merge=libcxx-reformat
libcxx/include/queue merge=libcxx-reformat
libcxx/include/random merge=libcxx-reformat
libcxx/include/ranges merge=libcxx-reformat
libcxx/include/ratio merge=libcxx-reformat
libcxx/include/regex merge=libcxx-reformat
libcxx/include/scoped_allocator merge=libcxx-reformat
libcxx/include/semaphore merge=libcxx-reformat
libcxx/include/set merge=libcxx-reformat
libcxx/include/shared_mutex merge=libcxx-reformat
libcxx/include/source_location merge=libcxx-reformat
libcxx/include/span merge=libcxx-reformat
libcxx/include/sstream merge=libcxx-reformat
libcxx/include/stack merge=libcxx-reformat
libcxx/include/stdexcept merge=libcxx-reformat
libcxx/include/stop_token merge=libcxx-reformat
libcxx/include/streambuf merge=libcxx-reformat
libcxx/include/string merge=libcxx-reformat
libcxx/include/string_view merge=libcxx-reformat
libcxx/include/strstream merge=libcxx-reformat
libcxx/include/syncstream merge=libcxx-reformat
libcxx/include/system_error merge=libcxx-reformat
libcxx/include/thread merge=libcxx-reformat
libcxx/include/tuple merge=libcxx-reformat
libcxx/include/type_traits merge=libcxx-reformat
libcxx/include/typeindex merge=libcxx-reformat
libcxx/include/typeinfo merge=libcxx-reformat
libcxx/include/unordered_map merge=libcxx-reformat
libcxx/include/unordered_set merge=libcxx-reformat
libcxx/include/utility merge=libcxx-reformat
libcxx/include/valarray merge=libcxx-reformat
libcxx/include/variant merge=libcxx-reformat
libcxx/include/vector merge=libcxx-reformat
libcxx/include/version merge=libcxx-reformat

View File

@ -22,21 +22,15 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template <class _ForwardIterator, class _Tp, class _Compare> template <class _ForwardIterator, class _Tp, class _Compare>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) {
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); __first = std::lower_bound<_ForwardIterator, _Tp, __comp_ref_type<_Compare> >(__first, __last, __value, __comp);
return __first != __last && !__comp(__value, *__first); return __first != __last && !__comp(__value, *__first);
} }
template <class _ForwardIterator, class _Tp> template <class _ForwardIterator, class _Tp>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
bool
binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
{
return std::binary_search(__first, __last, __value, __less<>()); return std::binary_search(__first, __last, __value, __less<>());
} }

View File

@ -20,15 +20,12 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template <class _Compare> template <class _Compare>
struct __debug_less struct __debug_less {
{ _Compare& __comp_;
_Compare &__comp_;
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI __debug_less(_Compare& __c) : __comp_(__c) {} _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI __debug_less(_Compare& __c) : __comp_(__c) {}
template <class _Tp, class _Up> template <class _Tp, class _Up>
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Up& __y) {
bool operator()(const _Tp& __x, const _Up& __y)
{
bool __r = __comp_(__x, __y); bool __r = __comp_(__x, __y);
if (__r) if (__r)
__do_compare_assert(0, __y, __x); __do_compare_assert(0, __y, __x);
@ -36,9 +33,7 @@ struct __debug_less
} }
template <class _Tp, class _Up> template <class _Tp, class _Up>
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool operator()(_Tp& __x, _Up& __y) {
bool operator()(_Tp& __x, _Up& __y)
{
bool __r = __comp_(__x, __y); bool __r = __comp_(__x, __y);
if (__r) if (__r)
__do_compare_assert(0, __y, __x); __do_compare_assert(0, __y, __x);
@ -46,26 +41,21 @@ struct __debug_less
} }
template <class _LHS, class _RHS> template <class _LHS, class _RHS>
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_CONSTEXPR_SINCE_CXX14 inline _LIBCPP_HIDE_FROM_ABI decltype((void)std::declval<_Compare&>()(
inline _LIBCPP_HIDE_FROM_ABI std::declval<_LHS&>(), std::declval<_RHS&>()))
decltype((void)std::declval<_Compare&>()( __do_compare_assert(int, _LHS& __l, _RHS& __r) {
std::declval<_LHS &>(), std::declval<_RHS &>())) _LIBCPP_ASSERT_UNCATEGORIZED(!__comp_(__l, __r), "Comparator does not induce a strict weak ordering");
__do_compare_assert(int, _LHS & __l, _RHS & __r) {
_LIBCPP_ASSERT_UNCATEGORIZED(!__comp_(__l, __r),
"Comparator does not induce a strict weak ordering");
(void)__l; (void)__l;
(void)__r; (void)__r;
} }
template <class _LHS, class _RHS> template <class _LHS, class _RHS>
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_CONSTEXPR_SINCE_CXX14 inline _LIBCPP_HIDE_FROM_ABI void __do_compare_assert(long, _LHS&, _RHS&) {}
inline _LIBCPP_HIDE_FROM_ABI
void __do_compare_assert(long, _LHS &, _RHS &) {}
}; };
// Pass the comparator by lvalue reference. Or in debug mode, using a // Pass the comparator by lvalue reference. Or in debug mode, using a
// debugging wrapper that stores a reference. // debugging wrapper that stores a reference.
# if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG #if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG
template <class _Comp> template <class _Comp>
using __comp_ref_type = __debug_less<_Comp>; using __comp_ref_type = __debug_less<_Comp>;
#else #else

View File

@ -108,8 +108,7 @@ struct __copy_backward_loop {
struct __copy_backward_trivial { struct __copy_backward_trivial {
// At this point, the iterators have been unwrapped so any `contiguous_iterator` has been unwrapped to a pointer. // At this point, the iterators have been unwrapped so any `contiguous_iterator` has been unwrapped to a pointer.
template <class _In, class _Out, template <class _In, class _Out, __enable_if_t<__can_lower_copy_assignment_to_memmove<_In, _Out>::value, int> = 0>
__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*> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_In*, _Out*>
operator()(_In* __first, _In* __last, _Out* __result) const { operator()(_In* __first, _In* __last, _Out* __result) const {
return std::__copy_backward_trivial_impl(__first, __last, __result); return std::__copy_backward_trivial_impl(__first, __last, __result);
@ -124,16 +123,13 @@ __copy_backward(_BidirectionalIterator1 __first, _Sentinel __last, _Bidirectiona
} }
template <class _BidirectionalIterator1, class _BidirectionalIterator2> template <class _BidirectionalIterator1, class _BidirectionalIterator2>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _BidirectionalIterator2
_BidirectionalIterator2 copy_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last, _BidirectionalIterator2 __result) {
copy_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last,
_BidirectionalIterator2 __result)
{
static_assert(std::is_copy_constructible<_BidirectionalIterator1>::value && 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>( return std::__copy_backward<_ClassicAlgPolicy>(std::move(__first), std::move(__last), std::move(__result)).second;
std::move(__first), std::move(__last), std::move(__result)).second;
} }
_LIBCPP_END_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD

View File

@ -17,16 +17,11 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template<class _InputIterator, class _OutputIterator, class _Predicate> template <class _InputIterator, class _OutputIterator, class _Predicate>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
_OutputIterator copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Predicate __pred) {
copy_if(_InputIterator __first, _InputIterator __last, for (; __first != __last; ++__first) {
_OutputIterator __result, _Predicate __pred) if (__pred(*__first)) {
{
for (; __first != __last; ++__first)
{
if (__pred(*__first))
{
*__result = *__first; *__result = *__first;
++__result; ++__result;
} }

View File

@ -43,17 +43,14 @@ struct __can_lower_copy_assignment_to_memmove {
// Reject conversions that wouldn't be performed by the regular built-in assignment (e.g. between arrays). // Reject conversions that wouldn't be performed by the regular built-in assignment (e.g. between arrays).
is_trivially_assignable<_To&, const _From&>::value && is_trivially_assignable<_To&, const _From&>::value &&
// `memmove` doesn't accept `volatile` pointers, make sure the optimization SFINAEs away in that case. // `memmove` doesn't accept `volatile` pointers, make sure the optimization SFINAEs away in that case.
!is_volatile<_From>::value && !is_volatile<_From>::value && !is_volatile<_To>::value;
!is_volatile<_To>::value;
}; };
template <class _From, class _To> template <class _From, class _To>
struct __can_lower_move_assignment_to_memmove { struct __can_lower_move_assignment_to_memmove {
static const bool value = static const bool value =
__is_always_bitcastable<_From, _To>::value && __is_always_bitcastable<_From, _To>::value && is_trivially_assignable<_To&, _From&&>::value &&
is_trivially_assignable<_To&, _From&&>::value && !is_volatile<_From>::value && !is_volatile<_To>::value;
!is_volatile<_From>::value &&
!is_volatile<_To>::value;
}; };
// `memmove` algorithms implementation. // `memmove` algorithms implementation.
@ -95,8 +92,8 @@ struct __can_rewrap<_InIter,
_Sent, _Sent,
_OutIter, _OutIter,
// Note that sentinels are always copy-constructible. // Note that sentinels are always copy-constructible.
__enable_if_t< is_copy_constructible<_InIter>::value && __enable_if_t< is_copy_constructible<_InIter>::value && is_copy_constructible<_OutIter>::value > >
is_copy_constructible<_OutIter>::value > > : true_type {}; : true_type {};
template <class _Algorithm, template <class _Algorithm,
class _InIter, class _InIter,

View File

@ -21,21 +21,20 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template<class _InputIterator, class _Size, class _OutputIterator, template <class _InputIterator,
class _Size,
class _OutputIterator,
__enable_if_t<__has_input_iterator_category<_InputIterator>::value && __enable_if_t<__has_input_iterator_category<_InputIterator>::value &&
!__has_random_access_iterator_category<_InputIterator>::value, int> = 0> !__has_random_access_iterator_category<_InputIterator>::value,
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 int> = 0>
_OutputIterator inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result) copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result) {
{
typedef decltype(std::__convert_to_integral(__orig_n)) _IntegralSize; typedef decltype(std::__convert_to_integral(__orig_n)) _IntegralSize;
_IntegralSize __n = __orig_n; _IntegralSize __n = __orig_n;
if (__n > 0) if (__n > 0) {
{
*__result = *__first; *__result = *__first;
++__result; ++__result;
for (--__n; __n > 0; --__n) for (--__n; __n > 0; --__n) {
{
++__first; ++__first;
*__result = *__first; *__result = *__first;
++__result; ++__result;
@ -44,12 +43,12 @@ copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result)
return __result; return __result;
} }
template<class _InputIterator, class _Size, class _OutputIterator, template <class _InputIterator,
class _Size,
class _OutputIterator,
__enable_if_t<__has_random_access_iterator_category<_InputIterator>::value, int> = 0> __enable_if_t<__has_random_access_iterator_category<_InputIterator>::value, int> = 0>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
_OutputIterator copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result) {
copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result)
{
typedef typename iterator_traits<_InputIterator>::difference_type difference_type; typedef typename iterator_traits<_InputIterator>::difference_type difference_type;
typedef decltype(std::__convert_to_integral(__orig_n)) _IntegralSize; typedef decltype(std::__convert_to_integral(__orig_n)) _IntegralSize;
_IntegralSize __n = __orig_n; _IntegralSize __n = __orig_n;

View File

@ -68,8 +68,13 @@ equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first
#if _LIBCPP_STD_VER >= 14 #if _LIBCPP_STD_VER >= 14
template <class _BinaryPredicate, class _InputIterator1, class _InputIterator2> template <class _BinaryPredicate, class _InputIterator1, class _InputIterator2>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
__equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, __equal(_InputIterator1 __first1,
_BinaryPredicate __pred, input_iterator_tag, input_iterator_tag) { _InputIterator1 __last1,
_InputIterator2 __first2,
_InputIterator2 __last2,
_BinaryPredicate __pred,
input_iterator_tag,
input_iterator_tag) {
for (; __first1 != __last1 && __first2 != __last2; ++__first1, (void)++__first2) for (; __first1 != __last1 && __first2 != __last2; ++__first1, (void)++__first2)
if (!__pred(*__first1, *__first2)) if (!__pred(*__first1, *__first2))
return false; return false;
@ -104,8 +109,12 @@ __equal_impl(_Tp* __first1, _Tp* __last1, _Up* __first2, _Up*, _Pred&, _Proj1&,
template <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2> template <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
__equal(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2, __equal(_RandomAccessIterator1 __first1,
_RandomAccessIterator2 __last2, _BinaryPredicate __pred, random_access_iterator_tag, _RandomAccessIterator1 __last1,
_RandomAccessIterator2 __first2,
_RandomAccessIterator2 __last2,
_BinaryPredicate __pred,
random_access_iterator_tag,
random_access_iterator_tag) { random_access_iterator_tag) {
if (std::distance(__first1, __last1) != std::distance(__first2, __last2)) if (std::distance(__first1, __last1) != std::distance(__first2, __last2))
return false; return false;
@ -122,10 +131,18 @@ __equal(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _Random
template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate> template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, equal(_InputIterator1 __first1,
_InputIterator1 __last1,
_InputIterator2 __first2,
_InputIterator2 __last2,
_BinaryPredicate __pred) { _BinaryPredicate __pred) {
return std::__equal<_BinaryPredicate&>( return std::__equal<_BinaryPredicate&>(
__first1, __last1, __first2, __last2, __pred, typename iterator_traits<_InputIterator1>::iterator_category(), __first1,
__last1,
__first2,
__last2,
__pred,
typename iterator_traits<_InputIterator1>::iterator_category(),
typename iterator_traits<_InputIterator2>::iterator_category()); typename iterator_traits<_InputIterator2>::iterator_category());
} }

View File

@ -49,8 +49,7 @@ __equal_range(_Iter __first, _Sent __last, const _Tp& __value, _Compare&& __comp
__len = __half_len; __len = __half_len;
} else { } else {
_Iter __mp1 = __mid; _Iter __mp1 = __mid;
return pair<_Iter, _Iter>( return pair<_Iter, _Iter>(std::__lower_bound<_AlgPolicy>(__first, __mid, __value, __comp, __proj),
std::__lower_bound<_AlgPolicy>(__first, __mid, __value, __comp, __proj),
std::__upper_bound<_AlgPolicy>(++__mp1, __end, __value, __comp, __proj)); std::__upper_bound<_AlgPolicy>(++__mp1, __end, __value, __comp, __proj));
} }
} }
@ -60,10 +59,8 @@ __equal_range(_Iter __first, _Sent __last, const _Tp& __value, _Compare&& __comp
template <class _ForwardIterator, class _Tp, class _Compare> template <class _ForwardIterator, class _Tp, class _Compare>
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator, _ForwardIterator> _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator, _ForwardIterator>
equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) { equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) {
static_assert(__is_callable<_Compare, decltype(*__first), const _Tp&>::value, static_assert(__is_callable<_Compare, decltype(*__first), const _Tp&>::value, "The comparator has to be callable");
"The comparator has to be callable"); static_assert(is_copy_constructible<_ForwardIterator>::value, "Iterator has to be copy constructible");
static_assert(is_copy_constructible<_ForwardIterator>::value,
"Iterator has to be copy constructible");
return std::__equal_range<_ClassicAlgPolicy>( return std::__equal_range<_ClassicAlgPolicy>(
std::move(__first), std::move(__first),
std::move(__last), std::move(__last),

View File

@ -22,27 +22,21 @@ _LIBCPP_BEGIN_NAMESPACE_STD
// fill isn't specialized for std::memset, because the compiler already optimizes the loop to a call to std::memset. // 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> template <class _ForwardIterator, class _Tp>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
void __fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, forward_iterator_tag) {
__fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, forward_iterator_tag)
{
for (; __first != __last; ++__first) for (; __first != __last; ++__first)
*__first = __value; *__first = __value;
} }
template <class _RandomAccessIterator, class _Tp> template <class _RandomAccessIterator, class _Tp>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
void __fill(_RandomAccessIterator __first, _RandomAccessIterator __last, const _Tp& __value, random_access_iterator_tag) {
__fill(_RandomAccessIterator __first, _RandomAccessIterator __last, const _Tp& __value, random_access_iterator_tag)
{
std::fill_n(__first, __last - __first, __value); std::fill_n(__first, __last - __first, __value);
} }
template <class _ForwardIterator, class _Tp> template <class _ForwardIterator, class _Tp>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
void fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
{
std::__fill(__first, __last, __value, typename iterator_traits<_ForwardIterator>::iterator_category()); std::__fill(__first, __last, __value, typename iterator_traits<_ForwardIterator>::iterator_category());
} }

View File

@ -22,20 +22,16 @@ _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. // 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> template <class _OutputIterator, class _Size, class _Tp>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
_OutputIterator __fill_n(_OutputIterator __first, _Size __n, const _Tp& __value) {
__fill_n(_OutputIterator __first, _Size __n, const _Tp& __value) for (; __n > 0; ++__first, (void)--__n)
{
for (; __n > 0; ++__first, (void) --__n)
*__first = __value; *__first = __value;
return __first; return __first;
} }
template <class _OutputIterator, class _Size, class _Tp> template <class _OutputIterator, class _Size, class _Tp>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
_OutputIterator fill_n(_OutputIterator __first, _Size __n, const _Tp& __value) {
fill_n(_OutputIterator __first, _Size __n, const _Tp& __value)
{
return std::__fill_n(__first, std::__convert_to_integral(__n), __value); return std::__fill_n(__first, std::__convert_to_integral(__n), __value);
} }

View File

@ -28,8 +28,7 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template < template < class _AlgPolicy,
class _AlgPolicy,
class _Iter1, class _Iter1,
class _Sent1, class _Sent1,
class _Iter2, class _Iter2,
@ -73,8 +72,7 @@ _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1>
if (++__m1 == __last1) // Source exhausted, return last answer if (++__m1 == __last1) // Source exhausted, return last answer
return pair<_Iter1, _Iter1>(__match_first, __match_last); return pair<_Iter1, _Iter1>(__match_first, __match_last);
// mismatch, restart with a new __first // mismatch, restart with a new __first
if (!std::__invoke(__pred, std::__invoke(__proj1, *__m1), std::__invoke(__proj2, *__m2))) if (!std::__invoke(__pred, std::__invoke(__proj1, *__m1), std::__invoke(__proj2, *__m2))) {
{
++__first1; ++__first1;
break; break;
} // else there is a match, check next elements } // else there is a match, check next elements
@ -82,8 +80,7 @@ _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1>
} }
} }
template < template < class _IterOps,
class _IterOps,
class _Pred, class _Pred,
class _Iter1, class _Iter1,
class _Sent1, class _Sent1,
@ -127,16 +124,14 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter1 __find_end(
return __last1; return __last1;
// if there is a mismatch, restart with a new __l1 // if there is a mismatch, restart with a new __l1
if (!std::__invoke(__pred, std::__invoke(__proj1, *--__m1), std::__invoke(__proj2, *--__m2))) if (!std::__invoke(__pred, std::__invoke(__proj1, *--__m1), std::__invoke(__proj2, *--__m2))) {
{
break; break;
} // else there is a match, check next elements } // else there is a match, check next elements
} }
} }
} }
template < template < class _AlgPolicy,
class _AlgPolicy,
class _Pred, class _Pred,
class _Iter1, class _Iter1,
class _Sent1, class _Sent1,
@ -189,9 +184,11 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iter1 __find_end(
} }
template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate> template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator1 __find_end_classic(
_ForwardIterator1 __find_end_classic(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator1 __first1,
_ForwardIterator2 __first2, _ForwardIterator2 __last2, _ForwardIterator1 __last1,
_ForwardIterator2 __first2,
_ForwardIterator2 __last2,
_BinaryPredicate& __pred) { _BinaryPredicate& __pred) {
auto __proj = __identity(); auto __proj = __identity();
return std::__find_end_impl<_ClassicAlgPolicy>( return std::__find_end_impl<_ClassicAlgPolicy>(
@ -208,17 +205,18 @@ _ForwardIterator1 __find_end_classic(_ForwardIterator1 __first1, _ForwardIterato
} }
template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate> template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 find_end(
_ForwardIterator1 find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator1 __first1,
_ForwardIterator2 __first2, _ForwardIterator2 __last2, _ForwardIterator1 __last1,
_ForwardIterator2 __first2,
_ForwardIterator2 __last2,
_BinaryPredicate __pred) { _BinaryPredicate __pred) {
return std::__find_end_classic(__first1, __last1, __first2, __last2, __pred); return std::__find_end_classic(__first1, __last1, __first2, __last2, __pred);
} }
template <class _ForwardIterator1, class _ForwardIterator2> template <class _ForwardIterator1, class _ForwardIterator2>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1
_ForwardIterator1 find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) {
_ForwardIterator2 __first2, _ForwardIterator2 __last2) {
return std::find_end(__first1, __last1, __first2, __last2, __equal_to()); return std::find_end(__first1, __last1, __first2, __last2, __equal_to());
} }

View File

@ -21,8 +21,8 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate> template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator1 __find_first_of_ce(
_LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator1 __find_first_of_ce(_ForwardIterator1 __first1, _ForwardIterator1 __first1,
_ForwardIterator1 __last1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _ForwardIterator2 __first2,
_ForwardIterator2 __last2, _ForwardIterator2 __last2,
@ -35,9 +35,12 @@ _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator1 __find_first_of_ce(_ForwardItera
} }
template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate> template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 find_first_of(
find_first_of(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator1 __first1,
_ForwardIterator2 __last2, _BinaryPredicate __pred) { _ForwardIterator1 __last1,
_ForwardIterator2 __first2,
_ForwardIterator2 __last2,
_BinaryPredicate __pred) {
return std::__find_first_of_ce(__first1, __last1, __first2, __last2, __pred); return std::__find_first_of_ce(__first1, __last1, __first2, __last2, __pred);
} }

View File

@ -22,9 +22,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD
#if _LIBCPP_STD_VER >= 17 #if _LIBCPP_STD_VER >= 17
template <class _InputIterator, class _Size, class _Function> template <class _InputIterator, class _Size, class _Function>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator for_each_n(_InputIterator __first, inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator
_Size __orig_n, for_each_n(_InputIterator __first, _Size __orig_n, _Function __f) {
_Function __f) {
typedef decltype(std::__convert_to_integral(__orig_n)) _IntegralSize; typedef decltype(std::__convert_to_integral(__orig_n)) _IntegralSize;
_IntegralSize __n = __orig_n; _IntegralSize __n = __orig_n;
while (__n > 0) { while (__n > 0) {

View File

@ -18,10 +18,8 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template <class _ForwardIterator, class _Generator> template <class _ForwardIterator, class _Generator>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
void generate(_ForwardIterator __first, _ForwardIterator __last, _Generator __gen) {
generate(_ForwardIterator __first, _ForwardIterator __last, _Generator __gen)
{
for (; __first != __last; ++__first) for (; __first != __last; ++__first)
*__first = __gen(); *__first = __gen();
} }

View File

@ -19,13 +19,11 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template <class _OutputIterator, class _Size, class _Generator> template <class _OutputIterator, class _Size, class _Generator>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
_OutputIterator generate_n(_OutputIterator __first, _Size __orig_n, _Generator __gen) {
generate_n(_OutputIterator __first, _Size __orig_n, _Generator __gen)
{
typedef decltype(std::__convert_to_integral(__orig_n)) _IntegralSize; typedef decltype(std::__convert_to_integral(__orig_n)) _IntegralSize;
_IntegralSize __n = __orig_n; _IntegralSize __n = __orig_n;
for (; __n > 0; ++__first, (void) --__n) for (; __n > 0; ++__first, (void)--__n)
*__first = __gen(); *__first = __gen();
return __first; return __first;
} }

View File

@ -23,18 +23,12 @@ _LIBCPP_BEGIN_NAMESPACE_STD
// Perform division by two quickly for positive integers (llvm.org/PR39129) // Perform division by two quickly for positive integers (llvm.org/PR39129)
template <typename _Integral, __enable_if_t<is_integral<_Integral>::value, int> = 0> template <typename _Integral, __enable_if_t<is_integral<_Integral>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Integral __half_positive(_Integral __value) {
_Integral
__half_positive(_Integral __value)
{
return static_cast<_Integral>(static_cast<__make_unsigned_t<_Integral> >(__value) / 2); return static_cast<_Integral>(static_cast<__make_unsigned_t<_Integral> >(__value) / 2);
} }
template <typename _Tp, __enable_if_t<!is_integral<_Tp>::value, int> = 0> template <typename _Tp, __enable_if_t<!is_integral<_Tp>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp __half_positive(_Tp __value) {
_Tp
__half_positive(_Tp __value)
{
return __value / 2; return __value / 2;
} }

View File

@ -30,7 +30,7 @@ struct in_found_result {
template <class _InIter2> template <class _InIter2>
requires convertible_to<const _InIter1&, _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}; return {in, found};
} }

View File

@ -30,7 +30,7 @@ struct in_fun_result {
template <class _InIter2, class _Func2> template <class _InIter2, class _Func2>
requires convertible_to<const _InIter1&, _InIter2> && convertible_to<const _Func1&, _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}; return {in, fun};
} }

View File

@ -31,18 +31,16 @@ struct in_in_out_result {
_LIBCPP_NO_UNIQUE_ADDRESS _OutIter1 out; _LIBCPP_NO_UNIQUE_ADDRESS _OutIter1 out;
template <class _InIter3, class _InIter4, class _OutIter2> template <class _InIter3, class _InIter4, class _OutIter2>
requires convertible_to<const _InIter1&, _InIter3> requires convertible_to<const _InIter1&, _InIter3> && convertible_to<const _InIter2&, _InIter4> &&
&& convertible_to<const _InIter2&, _InIter4> && convertible_to<const _OutIter1&, _OutIter2> convertible_to<const _OutIter1&, _OutIter2>
_LIBCPP_HIDE_FROM_ABI constexpr _LIBCPP_HIDE_FROM_ABI constexpr operator in_in_out_result<_InIter3, _InIter4, _OutIter2>() const& {
operator in_in_out_result<_InIter3, _InIter4, _OutIter2>() const& {
return {in1, in2, out}; return {in1, in2, out};
} }
template <class _InIter3, class _InIter4, class _OutIter2> template <class _InIter3, class _InIter4, class _OutIter2>
requires convertible_to<_InIter1, _InIter3> requires convertible_to<_InIter1, _InIter3> && convertible_to<_InIter2, _InIter4> &&
&& convertible_to<_InIter2, _InIter4> && convertible_to<_OutIter1, _OutIter2> convertible_to<_OutIter1, _OutIter2>
_LIBCPP_HIDE_FROM_ABI constexpr _LIBCPP_HIDE_FROM_ABI constexpr operator in_in_out_result<_InIter3, _InIter4, _OutIter2>() && {
operator in_in_out_result<_InIter3, _InIter4, _OutIter2>() && {
return {std::move(in1), std::move(in2), std::move(out)}; return {std::move(in1), std::move(in2), std::move(out)};
} }
}; };

View File

@ -31,15 +31,13 @@ struct in_in_result {
template <class _InIter3, class _InIter4> template <class _InIter3, class _InIter4>
requires convertible_to<const _InIter1&, _InIter3> && convertible_to<const _InIter2&, _InIter4> requires convertible_to<const _InIter1&, _InIter3> && convertible_to<const _InIter2&, _InIter4>
_LIBCPP_HIDE_FROM_ABI constexpr _LIBCPP_HIDE_FROM_ABI constexpr operator in_in_result<_InIter3, _InIter4>() const& {
operator in_in_result<_InIter3, _InIter4>() const & {
return {in1, in2}; return {in1, in2};
} }
template <class _InIter3, class _InIter4> template <class _InIter3, class _InIter4>
requires convertible_to<_InIter1, _InIter3> && convertible_to<_InIter2, _InIter4> requires convertible_to<_InIter1, _InIter3> && convertible_to<_InIter2, _InIter4>
_LIBCPP_HIDE_FROM_ABI constexpr _LIBCPP_HIDE_FROM_ABI constexpr operator in_in_result<_InIter3, _InIter4>() && {
operator in_in_result<_InIter3, _InIter4>() && {
return {std::move(in1), std::move(in2)}; return {std::move(in1), std::move(in2)};
} }
}; };

View File

@ -30,18 +30,16 @@ struct in_out_out_result {
_LIBCPP_NO_UNIQUE_ADDRESS _OutIter2 out2; _LIBCPP_NO_UNIQUE_ADDRESS _OutIter2 out2;
template <class _InIter2, class _OutIter3, class _OutIter4> template <class _InIter2, class _OutIter3, class _OutIter4>
requires convertible_to<const _InIter1&, _InIter2> requires convertible_to<const _InIter1&, _InIter2> && convertible_to<const _OutIter1&, _OutIter3> &&
&& convertible_to<const _OutIter1&, _OutIter3> && convertible_to<const _OutIter2&, _OutIter4> convertible_to<const _OutIter2&, _OutIter4>
_LIBCPP_HIDE_FROM_ABI constexpr _LIBCPP_HIDE_FROM_ABI constexpr operator in_out_out_result<_InIter2, _OutIter3, _OutIter4>() const& {
operator in_out_out_result<_InIter2, _OutIter3, _OutIter4>() const& {
return {in, out1, out2}; return {in, out1, out2};
} }
template <class _InIter2, class _OutIter3, class _OutIter4> template <class _InIter2, class _OutIter3, class _OutIter4>
requires convertible_to<_InIter1, _InIter2> requires convertible_to<_InIter1, _InIter2> && convertible_to<_OutIter1, _OutIter3> &&
&& convertible_to<_OutIter1, _OutIter3> && convertible_to<_OutIter2, _OutIter4> convertible_to<_OutIter2, _OutIter4>
_LIBCPP_HIDE_FROM_ABI constexpr _LIBCPP_HIDE_FROM_ABI constexpr operator in_out_out_result<_InIter2, _OutIter3, _OutIter4>() && {
operator in_out_out_result<_InIter2, _OutIter3, _OutIter4>() && {
return {std::move(in), std::move(out1), std::move(out2)}; return {std::move(in), std::move(out1), std::move(out2)};
} }
}; };

View File

@ -27,22 +27,20 @@ _LIBCPP_BEGIN_NAMESPACE_STD
namespace ranges { namespace ranges {
template<class _InIter1, class _OutIter1> template <class _InIter1, class _OutIter1>
struct in_out_result { struct in_out_result {
_LIBCPP_NO_UNIQUE_ADDRESS _InIter1 in; _LIBCPP_NO_UNIQUE_ADDRESS _InIter1 in;
_LIBCPP_NO_UNIQUE_ADDRESS _OutIter1 out; _LIBCPP_NO_UNIQUE_ADDRESS _OutIter1 out;
template <class _InIter2, class _OutIter2> template <class _InIter2, class _OutIter2>
requires convertible_to<const _InIter1&, _InIter2> && convertible_to<const _OutIter1&, _OutIter2> requires convertible_to<const _InIter1&, _InIter2> && convertible_to<const _OutIter1&, _OutIter2>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI constexpr operator in_out_result<_InIter2, _OutIter2>() const& {
constexpr operator in_out_result<_InIter2, _OutIter2>() const & {
return {in, out}; return {in, out};
} }
template <class _InIter2, class _OutIter2> template <class _InIter2, class _OutIter2>
requires convertible_to<_InIter1, _InIter2> && convertible_to<_OutIter1, _OutIter2> requires convertible_to<_InIter1, _InIter2> && convertible_to<_OutIter1, _OutIter2>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI constexpr operator in_out_result<_InIter2, _OutIter2>() && {
constexpr operator in_out_result<_InIter2, _OutIter2>() && {
return {std::move(in), std::move(out)}; return {std::move(in), std::move(out)};
} }
}; };

View File

@ -25,12 +25,17 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Comp, class _Proj1, class _Proj2> template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Comp, class _Proj1, class _Proj2>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __includes(
__includes(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, _Iter1 __first1,
_Comp&& __comp, _Proj1&& __proj1, _Proj2&& __proj2) { _Sent1 __last1,
_Iter2 __first2,
_Sent2 __last2,
_Comp&& __comp,
_Proj1&& __proj1,
_Proj2&& __proj2) {
for (; __first2 != __last2; ++__first1) { for (; __first2 != __last2; ++__first1) {
if (__first1 == __last1 || std::__invoke( if (__first1 == __last1 ||
__comp, std::__invoke(__proj2, *__first2), std::__invoke(__proj1, *__first1))) std::__invoke(__comp, std::__invoke(__proj2, *__first2), std::__invoke(__proj1, *__first1)))
return false; return false;
if (!std::__invoke(__comp, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2))) if (!std::__invoke(__comp, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2)))
++__first2; ++__first2;
@ -39,14 +44,14 @@ __includes(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2,
} }
template <class _InputIterator1, class _InputIterator2, class _Compare> template <class _InputIterator1, class _InputIterator2, class _Compare>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool includes( _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
_InputIterator1 __first1, includes(_InputIterator1 __first1,
_InputIterator1 __last1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __first2,
_InputIterator2 __last2, _InputIterator2 __last2,
_Compare __comp) { _Compare __comp) {
static_assert(__is_callable<_Compare, decltype(*__first1), decltype(*__first2)>::value, static_assert(
"Comparator has to be callable"); __is_callable<_Compare, decltype(*__first1), decltype(*__first2)>::value, "Comparator has to be callable");
return std::__includes( return std::__includes(
std::move(__first1), std::move(__first1),

View File

@ -43,43 +43,47 @@ class __invert // invert the sense of a comparison
{ {
private: private:
_Predicate __p_; _Predicate __p_;
public: public:
_LIBCPP_HIDE_FROM_ABI __invert() {} _LIBCPP_HIDE_FROM_ABI __invert() {}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI explicit __invert(_Predicate __p) : __p_(__p) {}
explicit __invert(_Predicate __p) : __p_(__p) {}
template <class _T1> template <class _T1>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI bool operator()(const _T1& __x) {
bool operator()(const _T1& __x) {return !__p_(__x);} return !__p_(__x);
}
template <class _T1, class _T2> template <class _T1, class _T2>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI bool operator()(const _T1& __x, const _T2& __y) {
bool operator()(const _T1& __x, const _T2& __y) {return __p_(__y, __x);} return __p_(__y, __x);
}
}; };
template <class _AlgPolicy, class _Compare, class _InputIterator1, class _Sent1, template <class _AlgPolicy,
class _InputIterator2, class _Sent2, class _OutputIterator> class _Compare,
_LIBCPP_HIDE_FROM_ABI class _InputIterator1,
void __half_inplace_merge(_InputIterator1 __first1, _Sent1 __last1, class _Sent1,
_InputIterator2 __first2, _Sent2 __last2, class _InputIterator2,
_OutputIterator __result, _Compare&& __comp) class _Sent2,
{ class _OutputIterator>
for (; __first1 != __last1; ++__result) _LIBCPP_HIDE_FROM_ABI void __half_inplace_merge(
{ _InputIterator1 __first1,
if (__first2 == __last2) _Sent1 __last1,
{ _InputIterator2 __first2,
_Sent2 __last2,
_OutputIterator __result,
_Compare&& __comp) {
for (; __first1 != __last1; ++__result) {
if (__first2 == __last2) {
std::__move<_AlgPolicy>(__first1, __last1, __result); std::__move<_AlgPolicy>(__first1, __last1, __result);
return; return;
} }
if (__comp(*__first2, *__first1)) if (__comp(*__first2, *__first1)) {
{
*__result = _IterOps<_AlgPolicy>::__iter_move(__first2); *__result = _IterOps<_AlgPolicy>::__iter_move(__first2);
++__first2; ++__first2;
} } else {
else
{
*__result = _IterOps<_AlgPolicy>::__iter_move(__first1); *__result = _IterOps<_AlgPolicy>::__iter_move(__first1);
++__first1; ++__first1;
} }
@ -88,8 +92,7 @@ void __half_inplace_merge(_InputIterator1 __first1, _Sent1 __last1,
} }
template <class _AlgPolicy, class _Compare, class _BidirectionalIterator> template <class _AlgPolicy, class _Compare, class _BidirectionalIterator>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI void __buffered_inplace_merge(
void __buffered_inplace_merge(
_BidirectionalIterator __first, _BidirectionalIterator __first,
_BidirectionalIterator __middle, _BidirectionalIterator __middle,
_BidirectionalIterator __last, _BidirectionalIterator __last,
@ -100,24 +103,22 @@ void __buffered_inplace_merge(
typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
__destruct_n __d(0); __destruct_n __d(0);
unique_ptr<value_type, __destruct_n&> __h2(__buff, __d); unique_ptr<value_type, __destruct_n&> __h2(__buff, __d);
if (__len1 <= __len2) if (__len1 <= __len2) {
{
value_type* __p = __buff; value_type* __p = __buff;
for (_BidirectionalIterator __i = __first; __i != __middle; __d.template __incr<value_type>(), (void) ++__i, (void) ++__p) 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)); ::new ((void*)__p) value_type(_IterOps<_AlgPolicy>::__iter_move(__i));
std::__half_inplace_merge<_AlgPolicy>(__buff, __p, __middle, __last, __first, __comp); std::__half_inplace_merge<_AlgPolicy>(__buff, __p, __middle, __last, __first, __comp);
} } else {
else
{
value_type* __p = __buff; value_type* __p = __buff;
for (_BidirectionalIterator __i = __middle; __i != __last; __d.template __incr<value_type>(), (void) ++__i, (void) ++__p) 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)); ::new ((void*)__p) value_type(_IterOps<_AlgPolicy>::__iter_move(__i));
typedef __unconstrained_reverse_iterator<_BidirectionalIterator> _RBi; typedef __unconstrained_reverse_iterator<_BidirectionalIterator> _RBi;
typedef __unconstrained_reverse_iterator<value_type*> _Rv; typedef __unconstrained_reverse_iterator<value_type*> _Rv;
typedef __invert<_Compare> _Inverted; typedef __invert<_Compare> _Inverted;
std::__half_inplace_merge<_AlgPolicy>(_Rv(__p), _Rv(__buff), std::__half_inplace_merge<_AlgPolicy>(
_RBi(__middle), _RBi(__first), _Rv(__p), _Rv(__buff), _RBi(__middle), _RBi(__first), _RBi(__last), _Inverted(__comp));
_RBi(__last), _Inverted(__comp));
} }
} }
@ -134,17 +135,14 @@ void __inplace_merge(
using _Ops = _IterOps<_AlgPolicy>; using _Ops = _IterOps<_AlgPolicy>;
typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
while (true) while (true) {
{
// if __middle == __last, we're done // if __middle == __last, we're done
if (__len2 == 0) if (__len2 == 0)
return; return;
if (__len1 <= __buff_size || __len2 <= __buff_size) if (__len1 <= __buff_size || __len2 <= __buff_size)
return std::__buffered_inplace_merge<_AlgPolicy> return std::__buffered_inplace_merge<_AlgPolicy>(__first, __middle, __last, __comp, __len1, __len2, __buff);
(__first, __middle, __last, __comp, __len1, __len2, __buff);
// shrink [__first, __middle) as much as possible (with no moves), returning if it shrinks to 0 // shrink [__first, __middle) as much as possible (with no moves), returning if it shrinks to 0
for (; true; ++__first, (void) --__len1) for (; true; ++__first, (void)--__len1) {
{
if (__len1 == 0) if (__len1 == 0)
return; return;
if (__comp(*__middle, *__first)) if (__comp(*__middle, *__first))
@ -163,18 +161,14 @@ void __inplace_merge(
difference_type __len11; // distance(__first, __m1) difference_type __len11; // distance(__first, __m1)
difference_type __len21; // distance(__middle, __m2) difference_type __len21; // distance(__middle, __m2)
// binary search smaller range // binary search smaller range
if (__len1 < __len2) if (__len1 < __len2) { // __len >= 1, __len2 >= 2
{ // __len >= 1, __len2 >= 2
__len21 = __len2 / 2; __len21 = __len2 / 2;
__m2 = __middle; __m2 = __middle;
_Ops::advance(__m2, __len21); _Ops::advance(__m2, __len21);
__m1 = std::__upper_bound<_AlgPolicy>(__first, __middle, *__m2, __comp, std::__identity()); __m1 = std::__upper_bound<_AlgPolicy>(__first, __middle, *__m2, __comp, std::__identity());
__len11 = _Ops::distance(__first, __m1); __len11 = _Ops::distance(__first, __m1);
} } else {
else if (__len1 == 1) { // __len1 >= __len2 && __len2 > 0, therefore __len2 == 1
{
if (__len1 == 1)
{ // __len1 >= __len2 && __len2 > 0, therefore __len2 == 1
// It is known *__first > *__middle // It is known *__first > *__middle
_Ops::iter_swap(__first, __middle); _Ops::iter_swap(__first, __middle);
return; return;
@ -193,19 +187,14 @@ void __inplace_merge(
__middle = std::__rotate<_AlgPolicy>(__m1, __middle, __m2).first; __middle = std::__rotate<_AlgPolicy>(__m1, __middle, __m2).first;
// __len12 and __len21 now have swapped meanings // __len12 and __len21 now have swapped meanings
// merge smaller range with recursive call and larger with tail recursion elimination // merge smaller range with recursive call and larger with tail recursion elimination
if (__len11 + __len21 < __len12 + __len22) if (__len11 + __len21 < __len12 + __len22) {
{ std::__inplace_merge<_AlgPolicy>(__first, __m1, __middle, __comp, __len11, __len21, __buff, __buff_size);
std::__inplace_merge<_AlgPolicy>(
__first, __m1, __middle, __comp, __len11, __len21, __buff, __buff_size);
__first = __middle; __first = __middle;
__middle = __m2; __middle = __m2;
__len1 = __len12; __len1 = __len12;
__len2 = __len22; __len2 = __len22;
} } else {
else std::__inplace_merge<_AlgPolicy>(__middle, __m2, __last, __comp, __len12, __len22, __buff, __buff_size);
{
std::__inplace_merge<_AlgPolicy>(
__middle, __m2, __last, __comp, __len12, __len22, __buff, __buff_size);
__last = __middle; __last = __middle;
__middle = __m1; __middle = __m1;
__len1 = __len11; __len1 = __len11;
@ -215,20 +204,17 @@ void __inplace_merge(
} }
template <class _AlgPolicy, class _BidirectionalIterator, class _Compare> template <class _AlgPolicy, class _BidirectionalIterator, class _Compare>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI void __inplace_merge(
void _BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last, _Compare&& __comp) {
__inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last,
_Compare&& __comp)
{
typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
difference_type __len1 = _IterOps<_AlgPolicy>::distance(__first, __middle); difference_type __len1 = _IterOps<_AlgPolicy>::distance(__first, __middle);
difference_type __len2 = _IterOps<_AlgPolicy>::distance(__middle, __last); difference_type __len2 = _IterOps<_AlgPolicy>::distance(__middle, __last);
difference_type __buf_size = std::min(__len1, __len2); difference_type __buf_size = std::min(__len1, __len2);
// TODO: Remove the use of std::get_temporary_buffer // TODO: Remove the use of std::get_temporary_buffer
_LIBCPP_SUPPRESS_DEPRECATED_PUSH _LIBCPP_SUPPRESS_DEPRECATED_PUSH
pair<value_type*, ptrdiff_t> __buf = std::get_temporary_buffer<value_type>(__buf_size); pair<value_type*, ptrdiff_t> __buf = std::get_temporary_buffer<value_type>(__buf_size);
_LIBCPP_SUPPRESS_DEPRECATED_POP _LIBCPP_SUPPRESS_DEPRECATED_POP
unique_ptr<value_type, __return_temporary_buffer> __h(__buf.first); unique_ptr<value_type, __return_temporary_buffer> __h(__buf.first);
return std::__inplace_merge<_AlgPolicy>( return std::__inplace_merge<_AlgPolicy>(
std::move(__first), std::move(__middle), std::move(__last), __comp, __len1, __len2, __buf.first, __buf.second); std::move(__first), std::move(__middle), std::move(__last), __comp, __len1, __len2, __buf.first, __buf.second);
@ -242,10 +228,8 @@ inline _LIBCPP_HIDE_FROM_ABI void inplace_merge(
} }
template <class _BidirectionalIterator> template <class _BidirectionalIterator>
inline _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_HIDE_FROM_ABI void
void inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last) {
inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last)
{
std::inplace_merge(std::move(__first), std::move(__middle), std::move(__last), __less<>()); std::inplace_merge(std::move(__first), std::move(__middle), std::move(__last), __less<>());
} }

View File

@ -22,20 +22,14 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template <class _RandomAccessIterator, class _Compare> template <class _RandomAccessIterator, class _Compare>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) {
bool
is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
{
return std::__is_heap_until(__first, __last, static_cast<__comp_ref_type<_Compare> >(__comp)) == __last; return std::__is_heap_until(__first, __last, static_cast<__comp_ref_type<_Compare> >(__comp)) == __last;
} }
template<class _RandomAccessIterator> template <class _RandomAccessIterator>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) {
bool
is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
{
return std::is_heap(__first, __last, __less<>()); return std::is_heap(__first, __last, __less<>());
} }

View File

@ -22,15 +22,13 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <class _Compare, class _RandomAccessIterator> template <class _Compare, class _RandomAccessIterator>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator
__is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare&& __comp) __is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare&& __comp) {
{
typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
difference_type __len = __last - __first; difference_type __len = __last - __first;
difference_type __p = 0; difference_type __p = 0;
difference_type __c = 1; difference_type __c = 1;
_RandomAccessIterator __pp = __first; _RandomAccessIterator __pp = __first;
while (__c < __len) while (__c < __len) {
{
_RandomAccessIterator __cp = __first + __c; _RandomAccessIterator __cp = __first + __c;
if (__comp(*__pp, *__cp)) if (__comp(*__pp, *__cp))
return __cp; return __cp;
@ -49,15 +47,13 @@ __is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Co
template <class _RandomAccessIterator, class _Compare> template <class _RandomAccessIterator, class _Compare>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator
is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) {
{
return std::__is_heap_until(__first, __last, static_cast<__comp_ref_type<_Compare> >(__comp)); return std::__is_heap_until(__first, __last, static_cast<__comp_ref_type<_Compare> >(__comp));
} }
template<class _RandomAccessIterator> template <class _RandomAccessIterator>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator
is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last) is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last) {
{
return std::__is_heap_until(__first, __last, __less<>()); return std::__is_heap_until(__first, __last, __less<>());
} }

View File

@ -19,12 +19,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <class _InputIterator, class _Predicate> template <class _InputIterator, class _Predicate>
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
is_partitioned(_InputIterator __first, _InputIterator __last, _Predicate __pred) is_partitioned(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
{
for (; __first != __last; ++__first) for (; __first != __last; ++__first)
if (!__pred(*__first)) if (!__pred(*__first))
break; break;
if ( __first == __last ) if (__first == __last)
return true; return true;
++__first; ++__first;
for (; __first != __last; ++__first) for (; __first != __last; ++__first)

View File

@ -37,18 +37,24 @@ struct _ConstTimeDistance : false_type {};
#if _LIBCPP_STD_VER >= 20 #if _LIBCPP_STD_VER >= 20
template <class _Iter1, class _Sent1, class _Iter2, class _Sent2> template <class _Iter1, class _Sent1, class _Iter2, class _Sent2>
struct _ConstTimeDistance<_Iter1, _Sent1, _Iter2, _Sent2, __enable_if_t< struct _ConstTimeDistance<_Iter1,
sized_sentinel_for<_Sent1, _Iter1> && _Sent1,
sized_sentinel_for<_Sent2, _Iter2> _Iter2,
>> : true_type {}; _Sent2,
__enable_if_t< sized_sentinel_for<_Sent1, _Iter1> && sized_sentinel_for<_Sent2, _Iter2> >>
: true_type {};
#else #else
template <class _Iter1, class _Iter2> template <class _Iter1, class _Iter2>
struct _ConstTimeDistance<_Iter1, _Iter1, _Iter2, _Iter2, __enable_if_t< struct _ConstTimeDistance<
is_same<typename iterator_traits<_Iter1>::iterator_category, random_access_iterator_tag>::value && _Iter1,
is_same<typename iterator_traits<_Iter2>::iterator_category, random_access_iterator_tag>::value _Iter1,
> > : true_type {}; _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 #endif // _LIBCPP_STD_VER >= 20
@ -56,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) // For each element in [f1, l1) see if there are the same number of equal elements in [f2, l2)
template <class _AlgPolicy, template <class _AlgPolicy,
class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Iter1,
class _Proj1, class _Proj2, class _Pred> class _Sent1,
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool class _Iter2,
__is_permutation_impl(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, class _Sent2,
_Pred&& __pred, _Proj1&& __proj1, _Proj2&& __proj2) { 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>; using _D1 = __iter_diff_t<_Iter1>;
for (auto __i = __first1; __i != __last1; ++__i) { for (auto __i = __first1; __i != __last1; ++__i) {
@ -97,9 +113,8 @@ __is_permutation_impl(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 _
// 2+1 iterators, predicate. Not used by range algorithms. // 2+1 iterators, predicate. Not used by range algorithms.
template <class _AlgPolicy, class _ForwardIterator1, class _Sentinel1, class _ForwardIterator2, class _BinaryPredicate> template <class _AlgPolicy, class _ForwardIterator1, class _Sentinel1, class _ForwardIterator2, class _BinaryPredicate>
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __is_permutation(
__is_permutation(_ForwardIterator1 __first1, _Sentinel1 __last1, _ForwardIterator2 __first2, _ForwardIterator1 __first1, _Sentinel1 __last1, _ForwardIterator2 __first2, _BinaryPredicate&& __pred) {
_BinaryPredicate&& __pred) {
// Shorten sequences as much as possible by lopping of any equal prefix. // Shorten sequences as much as possible by lopping of any equal prefix.
for (; __first1 != __last1; ++__first1, (void)++__first2) { for (; __first1 != __last1; ++__first1, (void)++__first2) {
if (!__pred(*__first1, *__first2)) if (!__pred(*__first1, *__first2))
@ -117,17 +132,32 @@ __is_permutation(_ForwardIterator1 __first1, _Sentinel1 __last1, _ForwardIterato
auto __last2 = _IterOps<_AlgPolicy>::next(__first2, __l1); auto __last2 = _IterOps<_AlgPolicy>::next(__first2, __l1);
return std::__is_permutation_impl<_AlgPolicy>( return std::__is_permutation_impl<_AlgPolicy>(
std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2), std::move(__first1),
__pred, __identity(), __identity()); std::move(__last1),
std::move(__first2),
std::move(__last2),
__pred,
__identity(),
__identity());
} }
// 2+2 iterators, predicate, non-constant time `distance`. // 2+2 iterators, predicate, non-constant time `distance`.
template <class _AlgPolicy, template <class _AlgPolicy,
class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Iter1,
class _Proj1, class _Proj2, class _Pred> class _Sent1,
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool class _Iter2,
__is_permutation(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, class _Sent2,
_Pred&& __pred, _Proj1&& __proj1, _Proj2&& __proj2, 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) { /*_ConstTimeDistance=*/false_type) {
// Shorten sequences as much as possible by lopping of any equal prefix. // Shorten sequences as much as possible by lopping of any equal prefix.
while (__first1 != __last1 && __first2 != __last2) { while (__first1 != __last1 && __first2 != __last2) {
@ -151,36 +181,65 @@ __is_permutation(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last
return false; return false;
return std::__is_permutation_impl<_AlgPolicy>( return std::__is_permutation_impl<_AlgPolicy>(
std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2), std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2), __pred, __proj1, __proj2);
__pred, __proj1, __proj2);
} }
// 2+2 iterators, predicate, specialization for constant-time `distance` call. // 2+2 iterators, predicate, specialization for constant-time `distance` call.
template <class _AlgPolicy, template <class _AlgPolicy,
class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Iter1,
class _Proj1, class _Proj2, class _Pred> class _Sent1,
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool class _Iter2,
__is_permutation(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, class _Sent2,
_Pred&& __pred, _Proj1&& __proj1, _Proj2&& __proj2, 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) { /*_ConstTimeDistance=*/true_type) {
if (std::distance(__first1, __last1) != std::distance(__first2, __last2)) if (std::distance(__first1, __last1) != std::distance(__first2, __last2))
return false; return false;
return std::__is_permutation<_AlgPolicy>( return std::__is_permutation<_AlgPolicy>(
std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2), std::move(__first1),
__pred, __proj1, __proj2, std::move(__last1),
std::move(__first2),
std::move(__last2),
__pred,
__proj1,
__proj2,
/*_ConstTimeDistance=*/false_type()); /*_ConstTimeDistance=*/false_type());
} }
// 2+2 iterators, predicate // 2+2 iterators, predicate
template <class _AlgPolicy, template <class _AlgPolicy,
class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Iter1,
class _Proj1, class _Proj2, class _Pred> class _Sent1,
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool class _Iter2,
__is_permutation(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, class _Sent2,
_Pred&& __pred, _Proj1&& __proj1, _Proj2&& __proj2) { 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>( return std::__is_permutation<_AlgPolicy>(
std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2), std::move(__first1),
__pred, __proj1, __proj2, std::move(__last1),
std::move(__first2),
std::move(__last2),
__pred,
__proj1,
__proj2,
_ConstTimeDistance<_Iter1, _Sent1, _Iter2, _Sent2>()); _ConstTimeDistance<_Iter1, _Sent1, _Iter2, _Sent2>());
} }
@ -188,14 +247,12 @@ __is_permutation(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last
// 2+1 iterators, predicate // 2+1 iterators, predicate
template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate> template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool is_permutation(
is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _BinaryPredicate __pred) {
_BinaryPredicate __pred) {
static_assert(__is_callable<_BinaryPredicate, decltype(*__first1), decltype(*__first2)>::value, 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>( return std::__is_permutation<_ClassicAlgPolicy>(std::move(__first1), std::move(__last1), std::move(__first2), __pred);
std::move(__first1), std::move(__last1), std::move(__first2), __pred);
} }
// 2+1 iterators // 2+1 iterators
@ -223,15 +280,23 @@ _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
// 2+2 iterators, predicate // 2+2 iterators, predicate
template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate> template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool is_permutation(
is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator1 __first1,
_ForwardIterator2 __last2, _BinaryPredicate __pred) { _ForwardIterator1 __last1,
_ForwardIterator2 __first2,
_ForwardIterator2 __last2,
_BinaryPredicate __pred) {
static_assert(__is_callable<_BinaryPredicate, decltype(*__first1), decltype(*__first2)>::value, 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>( return std::__is_permutation<_ClassicAlgPolicy>(
std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2), std::move(__first1),
__pred, __identity(), __identity()); std::move(__last1),
std::move(__first2),
std::move(__last2),
__pred,
__identity(),
__identity());
} }
#endif // _LIBCPP_STD_VER >= 14 #endif // _LIBCPP_STD_VER >= 14

View File

@ -22,20 +22,14 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template <class _ForwardIterator, class _Compare> template <class _ForwardIterator, class _Compare>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 is_sorted(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) {
bool
is_sorted(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
{
return std::__is_sorted_until<__comp_ref_type<_Compare> >(__first, __last, __comp) == __last; return std::__is_sorted_until<__comp_ref_type<_Compare> >(__first, __last, __comp) == __last;
} }
template<class _ForwardIterator> template <class _ForwardIterator>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 is_sorted(_ForwardIterator __first, _ForwardIterator __last) {
bool
is_sorted(_ForwardIterator __first, _ForwardIterator __last)
{
return std::is_sorted(__first, __last, __less<>()); return std::is_sorted(__first, __last, __less<>());
} }

View File

@ -22,13 +22,10 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <class _Compare, class _ForwardIterator> template <class _Compare, class _ForwardIterator>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
__is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) __is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) {
{ if (__first != __last) {
if (__first != __last)
{
_ForwardIterator __i = __first; _ForwardIterator __i = __first;
while (++__i != __last) while (++__i != __last) {
{
if (__comp(*__i, *__first)) if (__comp(*__i, *__first))
return __i; return __i;
__first = __i; __first = __i;
@ -39,15 +36,13 @@ __is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __
template <class _ForwardIterator, class _Compare> template <class _ForwardIterator, class _Compare>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) {
{
return std::__is_sorted_until<__comp_ref_type<_Compare> >(__first, __last, __comp); return std::__is_sorted_until<__comp_ref_type<_Compare> >(__first, __last, __comp);
} }
template<class _ForwardIterator> template <class _ForwardIterator>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
is_sorted_until(_ForwardIterator __first, _ForwardIterator __last) is_sorted_until(_ForwardIterator __first, _ForwardIterator __last) {
{
return std::is_sorted_until(__first, __last, __less<>()); return std::is_sorted_until(__first, __last, __less<>());
} }

View File

@ -20,8 +20,7 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template <class _ForwardIterator1, class _ForwardIterator2> template <class _ForwardIterator1, class _ForwardIterator2>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void iter_swap(_ForwardIterator1 __a, inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
_ForwardIterator2 __b)
// _NOEXCEPT_(_NOEXCEPT_(swap(*__a, *__b))) // _NOEXCEPT_(_NOEXCEPT_(swap(*__a, *__b)))
_NOEXCEPT_(_NOEXCEPT_(swap(*std::declval<_ForwardIterator1>(), *std::declval<_ForwardIterator2>()))) { _NOEXCEPT_(_NOEXCEPT_(swap(*std::declval<_ForwardIterator1>(), *std::declval<_ForwardIterator2>()))) {
swap(*__a, *__b); swap(*__a, *__b);

View File

@ -38,14 +38,14 @@ _LIBCPP_PUSH_MACROS
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template <class _AlgPolicy> struct _IterOps; template <class _AlgPolicy>
struct _IterOps;
#if _LIBCPP_STD_VER >= 20 #if _LIBCPP_STD_VER >= 20
struct _RangeAlgPolicy {}; struct _RangeAlgPolicy {};
template <> template <>
struct _IterOps<_RangeAlgPolicy> { struct _IterOps<_RangeAlgPolicy> {
template <class _Iter> template <class _Iter>
using __value_type = iter_value_t<_Iter>; using __value_type = iter_value_t<_Iter>;
@ -70,7 +70,6 @@ struct _ClassicAlgPolicy {};
template <> template <>
struct _IterOps<_ClassicAlgPolicy> { struct _IterOps<_ClassicAlgPolicy> {
template <class _Iter> template <class _Iter>
using __value_type = typename iterator_traits<_Iter>::value_type; using __value_type = typename iterator_traits<_Iter>::value_type;
@ -82,15 +81,14 @@ struct _IterOps<_ClassicAlgPolicy> {
// advance // advance
template <class _Iter, class _Distance> template <class _Iter, class _Distance>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static void advance(_Iter& __iter, _Distance __count) {
static void advance(_Iter& __iter, _Distance __count) {
std::advance(__iter, __count); std::advance(__iter, __count);
} }
// distance // distance
template <class _Iter> template <class _Iter>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static typename iterator_traits<_Iter>::difference_type
static typename iterator_traits<_Iter>::difference_type distance(_Iter __first, _Iter __last) { distance(_Iter __first, _Iter __last) {
return std::distance(__first, __last); return std::distance(__first, __last);
} }
@ -101,9 +99,9 @@ struct _IterOps<_ClassicAlgPolicy> {
using __move_t = decltype(std::move(*std::declval<_Iter&>())); using __move_t = decltype(std::move(*std::declval<_Iter&>()));
template <class _Iter> template <class _Iter>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static void __validate_iter_reference() {
static void __validate_iter_reference() { static_assert(
static_assert(is_same<__deref_t<_Iter>, typename iterator_traits<__remove_cvref_t<_Iter> >::reference>::value, 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 " "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] " "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."); "and can lead to dangling reference issues at runtime, so we are flagging this.");
@ -112,8 +110,8 @@ struct _IterOps<_ClassicAlgPolicy> {
// iter_move // iter_move
template <class _Iter, __enable_if_t<is_reference<__deref_t<_Iter> >::value, int> = 0> template <class _Iter, __enable_if_t<is_reference<__deref_t<_Iter> >::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static _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 // If the result of dereferencing `_Iter` is a reference type, deduce the result of calling `std::move` on it.
// that the C++03 mode doesn't support `decltype(auto)` as the return type. // Note that the C++03 mode doesn't support `decltype(auto)` as the return type.
__move_t<_Iter> __move_t<_Iter>
__iter_move(_Iter&& __i) { __iter_move(_Iter&& __i) {
__validate_iter_reference<_Iter>(); __validate_iter_reference<_Iter>();
@ -124,8 +122,8 @@ struct _IterOps<_ClassicAlgPolicy> {
template <class _Iter, __enable_if_t<!is_reference<__deref_t<_Iter> >::value, int> = 0> template <class _Iter, __enable_if_t<!is_reference<__deref_t<_Iter> >::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static _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 // 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 // value -- otherwise, after `operator*` returns a temporary, this function would return a dangling reference to
// temporary. Note that the C++03 mode doesn't support `auto` as the return type. // that temporary. Note that the C++03 mode doesn't support `auto` as the return type.
__deref_t<_Iter> __deref_t<_Iter>
__iter_move(_Iter&& __i) { __iter_move(_Iter&& __i) {
__validate_iter_reference<_Iter>(); __validate_iter_reference<_Iter>();
@ -135,36 +133,31 @@ struct _IterOps<_ClassicAlgPolicy> {
// iter_swap // iter_swap
template <class _Iter1, class _Iter2> template <class _Iter1, class _Iter2>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static void iter_swap(_Iter1&& __a, _Iter2&& __b) {
static void iter_swap(_Iter1&& __a, _Iter2&& __b) {
std::iter_swap(std::forward<_Iter1>(__a), std::forward<_Iter2>(__b)); std::iter_swap(std::forward<_Iter1>(__a), std::forward<_Iter2>(__b));
} }
// next // next
template <class _Iterator> template <class _Iterator>
_LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iterator next(_Iterator, _Iterator __last) {
_Iterator next(_Iterator, _Iterator __last) {
return __last; return __last;
} }
template <class _Iter> template <class _Iter>
_LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX14 __remove_cvref_t<_Iter>
__remove_cvref_t<_Iter> next(_Iter&& __it, next(_Iter&& __it, typename iterator_traits<__remove_cvref_t<_Iter> >::difference_type __n = 1) {
typename iterator_traits<__remove_cvref_t<_Iter> >::difference_type __n = 1) {
return std::next(std::forward<_Iter>(__it), __n); return std::next(std::forward<_Iter>(__it), __n);
} }
// prev // prev
template <class _Iter> template <class _Iter>
_LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX14 __remove_cvref_t<_Iter>
__remove_cvref_t<_Iter> prev(_Iter&& __iter, prev(_Iter&& __iter, typename iterator_traits<__remove_cvref_t<_Iter> >::difference_type __n = 1) {
typename iterator_traits<__remove_cvref_t<_Iter> >::difference_type __n = 1) {
return std::prev(std::forward<_Iter>(__iter), __n); return std::prev(std::forward<_Iter>(__iter), __n);
} }
template <class _Iter> template <class _Iter>
_LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX14 void __advance_to(_Iter& __first, _Iter __last) {
void __advance_to(_Iter& __first, _Iter __last) {
__first = __last; __first = __last;
} }
}; };

View File

@ -21,12 +21,13 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template <class _Compare, class _InputIterator1, class _InputIterator2> template <class _Compare, class _InputIterator1, class _InputIterator2>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __lexicographical_compare(
__lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator1 __first1,
_InputIterator2 __first2, _InputIterator2 __last2, _Compare __comp) _InputIterator1 __last1,
{ _InputIterator2 __first2,
for (; __first2 != __last2; ++__first1, (void) ++__first2) _InputIterator2 __last2,
{ _Compare __comp) {
for (; __first2 != __last2; ++__first1, (void)++__first2) {
if (__first1 == __last1 || __comp(*__first1, *__first2)) if (__first1 == __last1 || __comp(*__first1, *__first2))
return true; return true;
if (__comp(*__first2, *__first1)) if (__comp(*__first2, *__first1))
@ -36,22 +37,18 @@ __lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1,
} }
template <class _InputIterator1, class _InputIterator2, class _Compare> template <class _InputIterator1, class _InputIterator2, class _Compare>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool lexicographical_compare(
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator1 __first1,
bool _InputIterator1 __last1,
lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2,
_InputIterator2 __first2, _InputIterator2 __last2, _Compare __comp) _InputIterator2 __last2,
{ _Compare __comp) {
return std::__lexicographical_compare<__comp_ref_type<_Compare> >(__first1, __last1, __first2, __last2, __comp); return std::__lexicographical_compare<__comp_ref_type<_Compare> >(__first1, __last1, __first2, __last2, __comp);
} }
template <class _InputIterator1, class _InputIterator2> template <class _InputIterator1, class _InputIterator2>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool lexicographical_compare(
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) {
bool
lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2)
{
return std::lexicographical_compare(__first1, __last1, __first2, __last2, __less<>()); return std::lexicographical_compare(__first1, __last1, __first2, __last2, __less<>());
} }

View File

@ -28,8 +28,8 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template <class _AlgPolicy, class _Iter, class _Sent, class _Type, class _Proj, class _Comp> template <class _AlgPolicy, class _Iter, class _Sent, class _Type, class _Proj, class _Comp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter
_Iter __lower_bound(_Iter __first, _Sent __last, const _Type& __value, _Comp& __comp, _Proj& __proj) { __lower_bound(_Iter __first, _Sent __last, const _Type& __value, _Comp& __comp, _Proj& __proj) {
auto __len = _IterOps<_AlgPolicy>::distance(__first, __last); auto __len = _IterOps<_AlgPolicy>::distance(__first, __last);
while (__len != 0) { while (__len != 0) {
@ -47,17 +47,16 @@ _Iter __lower_bound(_Iter __first, _Sent __last, const _Type& __value, _Comp& __
} }
template <class _ForwardIterator, class _Tp, class _Compare> template <class _ForwardIterator, class _Tp, class _Compare>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
_ForwardIterator lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) { lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) {
static_assert(__is_callable<_Compare, decltype(*__first), const _Tp&>::value, static_assert(__is_callable<_Compare, decltype(*__first), const _Tp&>::value, "The comparator has to be callable");
"The comparator has to be callable");
auto __proj = std::__identity(); auto __proj = std::__identity();
return std::__lower_bound<_ClassicAlgPolicy>(__first, __last, __value, __comp, __proj); return std::__lower_bound<_ClassicAlgPolicy>(__first, __last, __value, __comp, __proj);
} }
template <class _ForwardIterator, class _Tp> template <class _ForwardIterator, class _Tp>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
_ForwardIterator lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
return std::lower_bound(__first, __last, __value, __less<>()); return std::lower_bound(__first, __last, __value, __less<>());
} }

View File

@ -27,8 +27,8 @@ _LIBCPP_PUSH_MACROS
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator> template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
void __make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare&& __comp) { __make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare&& __comp) {
__comp_ref_type<_Compare> __comp_ref = __comp; __comp_ref_type<_Compare> __comp_ref = __comp;
using difference_type = typename iterator_traits<_RandomAccessIterator>::difference_type; using difference_type = typename iterator_traits<_RandomAccessIterator>::difference_type;
@ -42,14 +42,14 @@ void __make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _C
} }
template <class _RandomAccessIterator, class _Compare> template <class _RandomAccessIterator, class _Compare>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
void make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) {
std::__make_heap<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __comp); std::__make_heap<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __comp);
} }
template <class _RandomAccessIterator> template <class _RandomAccessIterator>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
void make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) { make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) {
std::make_heap(std::move(__first), std::move(__last), __less<>()); std::make_heap(std::move(__first), std::move(__last), __less<>());
} }

View File

@ -36,44 +36,38 @@ struct _ProjectedPred {
: __pred(__pred_arg), __proj(__proj_arg) {} : __pred(__pred_arg), __proj(__proj_arg) {}
template <class _Tp> template <class _Tp>
typename __invoke_of<_Pred&, typename __invoke_of<_Pred&, decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_Tp>())) >::
decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_Tp>())) type _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
>::type operator()(_Tp&& __v) const {
_LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI operator()(_Tp&& __v) const {
return std::__invoke(__pred, std::__invoke(__proj, std::forward<_Tp>(__v))); return std::__invoke(__pred, std::__invoke(__proj, std::forward<_Tp>(__v)));
} }
template <class _T1, class _T2> template <class _T1, class _T2>
typename __invoke_of<_Pred&, typename __invoke_of<_Pred&,
decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_T1>())), decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_T1>())),
decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_T2>())) decltype(std::__invoke(std::declval<_Proj&>(),
>::type std::declval<_T2>())) >::type _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
_LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI operator()(_T1&& __lhs, _T2&& __rhs) const { operator()(_T1&& __lhs, _T2&& __rhs) const {
return std::__invoke(__pred, return std::__invoke(
std::__invoke(__proj, std::forward<_T1>(__lhs)), __pred, std::__invoke(__proj, std::forward<_T1>(__lhs)), std::__invoke(__proj, std::forward<_T2>(__rhs)));
std::__invoke(__proj, std::forward<_T2>(__rhs)));
} }
}; };
template <class _Pred, template <
class _Pred,
class _Proj, class _Proj,
__enable_if_t<!(!is_member_pointer<__decay_t<_Pred> >::value && __enable_if_t<!(!is_member_pointer<__decay_t<_Pred> >::value && __is_identity<__decay_t<_Proj> >::value), int> = 0>
__is_identity<__decay_t<_Proj> >::value), _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ProjectedPred<_Pred, _Proj> __make_projected(_Pred& __pred, _Proj& __proj) {
int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ProjectedPred<_Pred, _Proj>
__make_projected(_Pred& __pred, _Proj& __proj) {
return _ProjectedPred<_Pred, _Proj>(__pred, __proj); return _ProjectedPred<_Pred, _Proj>(__pred, __proj);
} }
// Avoid creating the functor and just use the pristine comparator -- for certain algorithms, this would enable // 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 // 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. // the call stack when the comparator is invoked, even in an unoptimized build.
template <class _Pred, template <
class _Pred,
class _Proj, class _Proj,
__enable_if_t<!is_member_pointer<__decay_t<_Pred> >::value && __enable_if_t<!is_member_pointer<__decay_t<_Pred> >::value && __is_identity<__decay_t<_Proj> >::value, int> = 0>
__is_identity<__decay_t<_Proj> >::value,
int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Pred& __make_projected(_Pred& __pred, _Proj&) { _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Pred& __make_projected(_Pred& __pred, _Proj&) {
return __pred; return __pred;
} }
@ -87,8 +81,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
namespace ranges { namespace ranges {
template <class _Comp, class _Proj1, class _Proj2> template <class _Comp, class _Proj1, class _Proj2>
_LIBCPP_HIDE_FROM_ABI constexpr _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) __make_projected_comp(_Comp& __comp, _Proj1& __proj1, _Proj2& __proj2) {
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 && if constexpr (__is_identity<decay_t<_Proj1>>::value && __is_identity<decay_t<_Proj2>>::value &&
!is_member_pointer_v<decay_t<_Comp>>) { !is_member_pointer_v<decay_t<_Comp>>) {
// Avoid creating the lambda and just use the pristine comparator -- for certain algorithms, this would enable // Avoid creating the lambda and just use the pristine comparator -- for certain algorithms, this would enable

View File

@ -25,40 +25,27 @@ _LIBCPP_PUSH_MACROS
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template <class _Tp, class _Compare> template <class _Tp, class _Compare>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp&
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 max(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b, _Compare __comp) {
const _Tp&
max(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b, _Compare __comp)
{
return __comp(__a, __b) ? __b : __a; return __comp(__a, __b) ? __b : __a;
} }
template <class _Tp> template <class _Tp>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp&
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 max(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b) {
const _Tp&
max(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b)
{
return std::max(__a, __b, __less<>()); return std::max(__a, __b, __less<>());
} }
#ifndef _LIBCPP_CXX03_LANG #ifndef _LIBCPP_CXX03_LANG
template<class _Tp, class _Compare> template <class _Tp, class _Compare>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 max(initializer_list<_Tp> __t, _Compare __comp) {
_Tp
max(initializer_list<_Tp> __t, _Compare __comp)
{
return *std::__max_element<__comp_ref_type<_Compare> >(__t.begin(), __t.end(), __comp); return *std::__max_element<__comp_ref_type<_Compare> >(__t.begin(), __t.end(), __comp);
} }
template<class _Tp> template <class _Tp>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp max(initializer_list<_Tp> __t) {
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
_Tp
max(initializer_list<_Tp> __t)
{
return *std::max_element(__t.begin(), __t.end(), __less<>()); return *std::max_element(__t.begin(), __t.end(), __less<>());
} }

View File

@ -22,12 +22,10 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <class _Compare, class _ForwardIterator> template <class _Compare, class _ForwardIterator>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator
__max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) __max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) {
{ static_assert(
static_assert(__has_forward_iterator_category<_ForwardIterator>::value, __has_forward_iterator_category<_ForwardIterator>::value, "std::max_element requires a ForwardIterator");
"std::max_element requires a ForwardIterator"); if (__first != __last) {
if (__first != __last)
{
_ForwardIterator __i = __first; _ForwardIterator __i = __first;
while (++__i != __last) while (++__i != __last)
if (__comp(*__first, *__i)) if (__comp(*__first, *__i))
@ -38,16 +36,13 @@ __max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp
template <class _ForwardIterator, class _Compare> template <class _ForwardIterator, class _Compare>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator
max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) {
{
return std::__max_element<__comp_ref_type<_Compare> >(__first, __last, __comp); return std::__max_element<__comp_ref_type<_Compare> >(__first, __last, __comp);
} }
template <class _ForwardIterator> template <class _ForwardIterator>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator
max_element(_ForwardIterator __first, _ForwardIterator __last) max_element(_ForwardIterator __first, _ForwardIterator __last) {
{
return std::max_element(__first, __last, __less<>()); return std::max_element(__first, __last, __less<>());
} }

View File

@ -22,22 +22,20 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template <class _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator> template <class _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator __merge(
_OutputIterator _InputIterator1 __first1,
__merge(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) _InputIterator2 __first2,
{ _InputIterator2 __last2,
for (; __first1 != __last1; ++__result) _OutputIterator __result,
{ _Compare __comp) {
for (; __first1 != __last1; ++__result) {
if (__first2 == __last2) if (__first2 == __last2)
return std::copy(__first1, __last1, __result); return std::copy(__first1, __last1, __result);
if (__comp(*__first2, *__first1)) if (__comp(*__first2, *__first1)) {
{
*__result = *__first2; *__result = *__first2;
++__first2; ++__first2;
} } else {
else
{
*__result = *__first1; *__result = *__first1;
++__first1; ++__first1;
} }
@ -46,20 +44,23 @@ __merge(_InputIterator1 __first1, _InputIterator1 __last1,
} }
template <class _InputIterator1, class _InputIterator2, class _OutputIterator, class _Compare> template <class _InputIterator1, class _InputIterator2, class _OutputIterator, class _Compare>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
_OutputIterator merge(_InputIterator1 __first1,
merge(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) _InputIterator2 __first2,
{ _InputIterator2 __last2,
_OutputIterator __result,
_Compare __comp) {
return std::__merge<__comp_ref_type<_Compare> >(__first1, __last1, __first2, __last2, __result, __comp); return std::__merge<__comp_ref_type<_Compare> >(__first1, __last1, __first2, __last2, __result, __comp);
} }
template <class _InputIterator1, class _InputIterator2, class _OutputIterator> template <class _InputIterator1, class _InputIterator2, class _OutputIterator>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
_OutputIterator merge(_InputIterator1 __first1,
merge(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result) _InputIterator2 __first2,
{ _InputIterator2 __last2,
_OutputIterator __result) {
return std::merge(__first1, __last1, __first2, __last2, __result, __less<>()); return std::merge(__first1, __last1, __first2, __last2, __result, __less<>());
} }

View File

@ -25,40 +25,27 @@ _LIBCPP_PUSH_MACROS
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template <class _Tp, class _Compare> template <class _Tp, class _Compare>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp&
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 min(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b, _Compare __comp) {
const _Tp&
min(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b, _Compare __comp)
{
return __comp(__b, __a) ? __b : __a; return __comp(__b, __a) ? __b : __a;
} }
template <class _Tp> template <class _Tp>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp&
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 min(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b) {
const _Tp&
min(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b)
{
return std::min(__a, __b, __less<>()); return std::min(__a, __b, __less<>());
} }
#ifndef _LIBCPP_CXX03_LANG #ifndef _LIBCPP_CXX03_LANG
template<class _Tp, class _Compare> template <class _Tp, class _Compare>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 min(initializer_list<_Tp> __t, _Compare __comp) {
_Tp
min(initializer_list<_Tp> __t, _Compare __comp)
{
return *std::__min_element<__comp_ref_type<_Compare> >(__t.begin(), __t.end(), __comp); return *std::__min_element<__comp_ref_type<_Compare> >(__t.begin(), __t.end(), __comp);
} }
template<class _Tp> template <class _Tp>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp min(initializer_list<_Tp> __t) {
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
_Tp
min(initializer_list<_Tp> __t)
{
return *std::min_element(__t.begin(), __t.end(), __less<>()); return *std::min_element(__t.begin(), __t.end(), __less<>());
} }

View File

@ -28,8 +28,8 @@ _LIBCPP_PUSH_MACROS
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template <class _Comp, class _Iter, class _Sent, class _Proj> template <class _Comp, class _Iter, class _Sent, class _Proj>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iter
_Iter __min_element(_Iter __first, _Sent __last, _Comp __comp, _Proj& __proj) { __min_element(_Iter __first, _Sent __last, _Comp __comp, _Proj& __proj) {
if (__first == __last) if (__first == __last)
return __first; return __first;
@ -42,28 +42,25 @@ _Iter __min_element(_Iter __first, _Sent __last, _Comp __comp, _Proj& __proj) {
} }
template <class _Comp, class _Iter, class _Sent> template <class _Comp, class _Iter, class _Sent>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iter __min_element(_Iter __first, _Sent __last, _Comp __comp) {
_Iter __min_element(_Iter __first, _Sent __last, _Comp __comp) {
auto __proj = __identity(); auto __proj = __identity();
return std::__min_element<_Comp>(std::move(__first), std::move(__last), __comp, __proj); return std::__min_element<_Comp>(std::move(__first), std::move(__last), __comp, __proj);
} }
template <class _ForwardIterator, class _Compare> template <class _ForwardIterator, class _Compare>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator
min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) {
{ static_assert(
static_assert(__has_forward_iterator_category<_ForwardIterator>::value, __has_forward_iterator_category<_ForwardIterator>::value, "std::min_element requires a ForwardIterator");
"std::min_element requires a ForwardIterator"); static_assert(
static_assert(__is_callable<_Compare, decltype(*__first), decltype(*__first)>::value, __is_callable<_Compare, decltype(*__first), decltype(*__first)>::value, "The comparator has to be callable");
"The comparator has to be callable");
return std::__min_element<__comp_ref_type<_Compare> >(std::move(__first), std::move(__last), __comp); return std::__min_element<__comp_ref_type<_Compare> >(std::move(__first), std::move(__last), __comp);
} }
template <class _ForwardIterator> template <class _ForwardIterator>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator
min_element(_ForwardIterator __first, _ForwardIterator __last) min_element(_ForwardIterator __first, _ForwardIterator __last) {
{
return std::min_element(__first, __last, __less<>()); return std::min_element(__first, __last, __less<>());
} }

View File

@ -34,7 +34,7 @@ struct min_max_result {
template <class _T2> template <class _T2>
requires convertible_to<const _T1&, _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}; return {min, max};
} }

View File

@ -23,42 +23,32 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template<class _Tp, class _Compare> template <class _Tp, class _Compare>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<const _Tp&, const _Tp&>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 minmax(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b, _Compare __comp) {
pair<const _Tp&, const _Tp&> return __comp(__b, __a) ? pair<const _Tp&, const _Tp&>(__b, __a) : pair<const _Tp&, const _Tp&>(__a, __b);
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> template <class _Tp>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<const _Tp&, const _Tp&>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 minmax(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b) {
pair<const _Tp&, const _Tp&>
minmax(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b)
{
return std::minmax(__a, __b, __less<>()); return std::minmax(__a, __b, __less<>());
} }
#ifndef _LIBCPP_CXX03_LANG #ifndef _LIBCPP_CXX03_LANG
template<class _Tp, class _Compare> template <class _Tp, class _Compare>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Tp, _Tp>
pair<_Tp, _Tp> minmax(initializer_list<_Tp> __t, _Compare __comp) { minmax(initializer_list<_Tp> __t, _Compare __comp) {
static_assert(__is_callable<_Compare, _Tp, _Tp>::value, "The comparator has to be callable"); static_assert(__is_callable<_Compare, _Tp, _Tp>::value, "The comparator has to be callable");
__identity __proj; __identity __proj;
auto __ret = std::__minmax_element_impl(__t.begin(), __t.end(), __comp, __proj); auto __ret = std::__minmax_element_impl(__t.begin(), __t.end(), __comp, __proj);
return pair<_Tp, _Tp>(*__ret.first, *__ret.second); return pair<_Tp, _Tp>(*__ret.first, *__ret.second);
} }
template<class _Tp> template <class _Tp>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Tp, _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 minmax(initializer_list<_Tp> __t) {
pair<_Tp, _Tp>
minmax(initializer_list<_Tp> __t)
{
return std::minmax(__t, __less<>()); return std::minmax(__t, __less<>());
} }

View File

@ -29,19 +29,18 @@ class _MinmaxElementLessFunc {
_Proj& __proj_; _Proj& __proj_;
public: public:
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _MinmaxElementLessFunc(_Comp& __comp, _Proj& __proj)
_MinmaxElementLessFunc(_Comp& __comp, _Proj& __proj) : __comp_(__comp), __proj_(__proj) {} : __comp_(__comp), __proj_(__proj) {}
template <class _Iter> template <class _Iter>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator()(_Iter& __it1, _Iter& __it2) {
bool operator()(_Iter& __it1, _Iter& __it2) {
return std::__invoke(__comp_, std::__invoke(__proj_, *__it1), std::__invoke(__proj_, *__it2)); return std::__invoke(__comp_, std::__invoke(__proj_, *__it1), std::__invoke(__proj_, *__it2));
} }
}; };
template <class _Iter, class _Sent, class _Proj, class _Comp> template <class _Iter, class _Sent, class _Proj, class _Comp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter, _Iter>
pair<_Iter, _Iter> __minmax_element_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) { __minmax_element_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) {
auto __less = _MinmaxElementLessFunc<_Comp, _Proj>(__comp, __proj); auto __less = _MinmaxElementLessFunc<_Comp, _Proj>(__comp, __proj);
pair<_Iter, _Iter> __result(__first, __first); pair<_Iter, _Iter> __result(__first, __first);
@ -80,20 +79,20 @@ pair<_Iter, _Iter> __minmax_element_impl(_Iter __first, _Sent __last, _Comp& __c
} }
template <class _ForwardIterator, class _Compare> template <class _ForwardIterator, class _Compare>
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_ForwardIterator, _ForwardIterator>
pair<_ForwardIterator, _ForwardIterator>
minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) { minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) {
static_assert(__has_forward_iterator_category<_ForwardIterator>::value, static_assert(
"std::minmax_element requires a ForwardIterator"); __has_forward_iterator_category<_ForwardIterator>::value, "std::minmax_element requires a ForwardIterator");
static_assert(__is_callable<_Compare, decltype(*__first), decltype(*__first)>::value, static_assert(
"The comparator has to be callable"); __is_callable<_Compare, decltype(*__first), decltype(*__first)>::value, "The comparator has to be callable");
auto __proj = __identity(); auto __proj = __identity();
return std::__minmax_element_impl(__first, __last, __comp, __proj); return std::__minmax_element_impl(__first, __last, __comp, __proj);
} }
template <class _ForwardIterator> template <class _ForwardIterator>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
pair<_ForwardIterator, _ForwardIterator> minmax_element(_ForwardIterator __first, _ForwardIterator __last) { pair<_ForwardIterator, _ForwardIterator>
minmax_element(_ForwardIterator __first, _ForwardIterator __last) {
return std::minmax_element(__first, __last, __less<>()); return std::minmax_element(__first, __last, __less<>());
} }

View File

@ -22,9 +22,8 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate> template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2>
_LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2> mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _BinaryPredicate __pred) {
mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _BinaryPredicate __pred) {
for (; __first1 != __last1; ++__first1, (void)++__first2) for (; __first1 != __last1; ++__first1, (void)++__first2)
if (!__pred(*__first1, *__first2)) if (!__pred(*__first1, *__first2))
break; break;
@ -32,17 +31,18 @@ _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI
} }
template <class _InputIterator1, class _InputIterator2> template <class _InputIterator1, class _InputIterator2>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2>
_LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2> mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2) {
mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2) {
return std::mismatch(__first1, __last1, __first2, __equal_to()); return std::mismatch(__first1, __last1, __first2, __equal_to());
} }
#if _LIBCPP_STD_VER >= 14 #if _LIBCPP_STD_VER >= 14
template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate> template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2>
_LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2> mismatch(_InputIterator1 __first1,
mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _InputIterator1 __last1,
_InputIterator2 __first2,
_InputIterator2 __last2,
_BinaryPredicate __pred) { _BinaryPredicate __pred) {
for (; __first1 != __last1 && __first2 != __last2; ++__first1, (void)++__first2) for (; __first1 != __last1 && __first2 != __last2; ++__first1, (void)++__first2)
if (!__pred(*__first1, *__first2)) if (!__pred(*__first1, *__first2))
@ -51,9 +51,8 @@ _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI
} }
template <class _InputIterator1, class _InputIterator2> template <class _InputIterator1, class _InputIterator2>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2>
_LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2> mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) {
mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) {
return std::mismatch(__first1, __last1, __first2, __last2, __equal_to()); return std::mismatch(__first1, __last1, __first2, __last2, __equal_to());
} }
#endif #endif

View File

@ -99,8 +99,7 @@ struct __move_loop {
struct __move_trivial { struct __move_trivial {
// At this point, the iterators have been unwrapped so any `contiguous_iterator` has been unwrapped to a pointer. // At this point, the iterators have been unwrapped so any `contiguous_iterator` has been unwrapped to a pointer.
template <class _In, class _Out, template <class _In, class _Out, __enable_if_t<__can_lower_move_assignment_to_memmove<_In, _Out>::value, int> = 0>
__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*> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_In*, _Out*>
operator()(_In* __first, _In* __last, _Out* __result) const { operator()(_In* __first, _In* __last, _Out* __result) const {
return std::__copy_trivial_impl(__first, __last, __result); return std::__copy_trivial_impl(__first, __last, __result);

View File

@ -108,8 +108,7 @@ struct __move_backward_loop {
struct __move_backward_trivial { struct __move_backward_trivial {
// At this point, the iterators have been unwrapped so any `contiguous_iterator` has been unwrapped to a pointer. // At this point, the iterators have been unwrapped so any `contiguous_iterator` has been unwrapped to a pointer.
template <class _In, class _Out, template <class _In, class _Out, __enable_if_t<__can_lower_move_assignment_to_memmove<_In, _Out>::value, int> = 0>
__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*> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_In*, _Out*>
operator()(_In* __first, _In* __last, _Out* __result) const { operator()(_In* __first, _In* __last, _Out* __result) const {
return std::__copy_backward_trivial_impl(__first, __last, __result); return std::__copy_backward_trivial_impl(__first, __last, __result);
@ -120,7 +119,8 @@ template <class _AlgPolicy, class _BidirectionalIterator1, class _Sentinel, clas
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_BidirectionalIterator1, _BidirectionalIterator2> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_BidirectionalIterator1, _BidirectionalIterator2>
__move_backward(_BidirectionalIterator1 __first, _Sentinel __last, _BidirectionalIterator2 __result) { __move_backward(_BidirectionalIterator1 __first, _Sentinel __last, _BidirectionalIterator2 __result) {
static_assert(std::is_copy_constructible<_BidirectionalIterator1>::value && 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::__dispatch_copy_or_move<_AlgPolicy, __move_backward_loop<_AlgPolicy>, __move_backward_trivial>(
std::move(__first), std::move(__last), std::move(__result)); std::move(__first), std::move(__last), std::move(__result));

View File

@ -26,8 +26,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <class _AlgPolicy, class _Compare, class _BidirectionalIterator, class _Sentinel> template <class _AlgPolicy, class _Compare, class _BidirectionalIterator, class _Sentinel>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_BidirectionalIterator, bool> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_BidirectionalIterator, bool>
__next_permutation(_BidirectionalIterator __first, _Sentinel __last, _Compare&& __comp) __next_permutation(_BidirectionalIterator __first, _Sentinel __last, _Compare&& __comp) {
{
using _Result = pair<_BidirectionalIterator, bool>; using _Result = pair<_BidirectionalIterator, bool>;
_BidirectionalIterator __last_iter = _IterOps<_AlgPolicy>::next(__first, __last); _BidirectionalIterator __last_iter = _IterOps<_AlgPolicy>::next(__first, __last);
@ -35,11 +34,9 @@ __next_permutation(_BidirectionalIterator __first, _Sentinel __last, _Compare&&
if (__first == __last || __first == --__i) if (__first == __last || __first == --__i)
return _Result(std::move(__last_iter), false); return _Result(std::move(__last_iter), false);
while (true) while (true) {
{
_BidirectionalIterator __ip1 = __i; _BidirectionalIterator __ip1 = __i;
if (__comp(*--__i, *__ip1)) if (__comp(*--__i, *__ip1)) {
{
_BidirectionalIterator __j = __last_iter; _BidirectionalIterator __j = __last_iter;
while (!__comp(*__i, *--__j)) while (!__comp(*__i, *--__j))
; ;
@ -47,8 +44,7 @@ __next_permutation(_BidirectionalIterator __first, _Sentinel __last, _Compare&&
std::__reverse<_AlgPolicy>(__ip1, __last_iter); std::__reverse<_AlgPolicy>(__ip1, __last_iter);
return _Result(std::move(__last_iter), true); return _Result(std::move(__last_iter), true);
} }
if (__i == __first) if (__i == __first) {
{
std::__reverse<_AlgPolicy>(__first, __last_iter); std::__reverse<_AlgPolicy>(__first, __last_iter);
return _Result(std::move(__last_iter), false); return _Result(std::move(__last_iter), false);
} }
@ -56,19 +52,16 @@ __next_permutation(_BidirectionalIterator __first, _Sentinel __last, _Compare&&
} }
template <class _BidirectionalIterator, class _Compare> template <class _BidirectionalIterator, class _Compare>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
bool next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) {
next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp)
{
return std::__next_permutation<_ClassicAlgPolicy>( 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> template <class _BidirectionalIterator>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
bool next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last) {
next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last)
{
return std::next_permutation(__first, __last, __less<>()); return std::next_permutation(__first, __last, __less<>());
} }

View File

@ -25,11 +25,9 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template<class _Compare, class _RandomAccessIterator> template <class _Compare, class _RandomAccessIterator>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool __nth_element_find_guard(
__nth_element_find_guard(_RandomAccessIterator& __i, _RandomAccessIterator& __j, _RandomAccessIterator& __i, _RandomAccessIterator& __j, _RandomAccessIterator __m, _Compare __comp) {
_RandomAccessIterator __m, _Compare __comp)
{
// manually guard downward moving __j against __i // manually guard downward moving __j against __i
while (true) { while (true) {
if (__i == --__j) { if (__i == --__j) {
@ -44,20 +42,18 @@ __nth_element_find_guard(_RandomAccessIterator& __i, _RandomAccessIterator& __j,
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator> template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
// NOLINTNEXTLINE(readability-function-cognitive-complexity) // NOLINTNEXTLINE(readability-function-cognitive-complexity)
__nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare __comp) __nth_element(
{ _RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare __comp) {
using _Ops = _IterOps<_AlgPolicy>; using _Ops = _IterOps<_AlgPolicy>;
// _Compare is known to be a reference type // _Compare is known to be a reference type
typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
const difference_type __limit = 7; const difference_type __limit = 7;
while (true) while (true) {
{
if (__nth == __last) if (__nth == __last)
return; return;
difference_type __len = __last - __first; difference_type __len = __last - __first;
switch (__len) switch (__len) {
{
case 0: case 0:
case 1: case 1:
return; return;
@ -65,20 +61,18 @@ __nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _Rando
if (__comp(*--__last, *__first)) if (__comp(*--__last, *__first))
_Ops::iter_swap(__first, __last); _Ops::iter_swap(__first, __last);
return; return;
case 3: case 3: {
{
_RandomAccessIterator __m = __first; _RandomAccessIterator __m = __first;
std::__sort3<_AlgPolicy, _Compare>(__first, ++__m, --__last, __comp); std::__sort3<_AlgPolicy, _Compare>(__first, ++__m, --__last, __comp);
return; return;
} }
} }
if (__len <= __limit) if (__len <= __limit) {
{
std::__selection_sort<_AlgPolicy, _Compare>(__first, __last, __comp); std::__selection_sort<_AlgPolicy, _Compare>(__first, __last, __comp);
return; return;
} }
// __len > __limit >= 3 // __len > __limit >= 3
_RandomAccessIterator __m = __first + __len/2; _RandomAccessIterator __m = __first + __len / 2;
_RandomAccessIterator __lm1 = __last; _RandomAccessIterator __lm1 = __last;
unsigned __n_swaps = std::__sort3<_AlgPolicy, _Compare>(__first, __m, --__lm1, __comp); unsigned __n_swaps = std::__sort3<_AlgPolicy, _Compare>(__first, __m, --__lm1, __comp);
// *__m is median // *__m is median
@ -150,11 +144,9 @@ __nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _Rando
++__i; ++__i;
// j points beyond range to be tested, *__lm1 is known to be <= *__m // j points beyond range to be tested, *__lm1 is known to be <= *__m
// if not yet partitioned... // if not yet partitioned...
if (__i < __j) if (__i < __j) {
{
// known that *(__i - 1) < *__m // known that *(__i - 1) < *__m
while (true) while (true) {
{
// __m still guards upward moving __i // __m still guards upward moving __i
while (__comp(*__i, *__m)) { while (__comp(*__i, *__m)) {
++__i; ++__i;
@ -181,19 +173,16 @@ __nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _Rando
} }
} }
// [__first, __i) < *__m and *__m <= [__i, __last) // [__first, __i) < *__m and *__m <= [__i, __last)
if (__i != __m && __comp(*__m, *__i)) if (__i != __m && __comp(*__m, *__i)) {
{
_Ops::iter_swap(__i, __m); _Ops::iter_swap(__i, __m);
++__n_swaps; ++__n_swaps;
} }
// [__first, __i) < *__i and *__i <= [__i+1, __last) // [__first, __i) < *__i and *__i <= [__i+1, __last)
if (__nth == __i) if (__nth == __i)
return; return;
if (__n_swaps == 0) if (__n_swaps == 0) {
{
// We were given a perfectly partitioned sequence. Coincidence? // We were given a perfectly partitioned sequence. Coincidence?
if (__nth < __i) if (__nth < __i) {
{
// Check for [__first, __i) already sorted // Check for [__first, __i) already sorted
__j = __m = __first; __j = __m = __first;
while (true) { while (true) {
@ -207,9 +196,7 @@ __nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _Rando
} }
__m = __j; __m = __j;
} }
} } else {
else
{
// Check for [__i, __last) already sorted // Check for [__i, __last) already sorted
__j = __m = __i; __j = __m = __i;
while (true) { while (true) {
@ -226,13 +213,10 @@ __nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _Rando
} }
} }
// __nth_element on range containing __nth // __nth_element on range containing __nth
if (__nth < __i) if (__nth < __i) {
{
// std::__nth_element<_Compare>(__first, __nth, __i, __comp); // std::__nth_element<_Compare>(__first, __nth, __i, __comp);
__last = __i; __last = __i;
} } else {
else
{
// std::__nth_element<_Compare>(__i+1, __nth, __last, __comp); // std::__nth_element<_Compare>(__i+1, __nth, __last, __comp);
__first = ++__i; __first = ++__i;
} }
@ -240,9 +224,8 @@ __nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _Rando
} }
template <class _AlgPolicy, class _RandomAccessIterator, class _Compare> template <class _AlgPolicy, class _RandomAccessIterator, class _Compare>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __nth_element_impl(
void __nth_element_impl(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare& __comp) {
_Compare& __comp) {
if (__nth == __last) if (__nth == __last)
return; return;
@ -257,15 +240,14 @@ void __nth_element_impl(_RandomAccessIterator __first, _RandomAccessIterator __n
} }
template <class _RandomAccessIterator, class _Compare> template <class _RandomAccessIterator, class _Compare>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
void nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare __comp) {
_Compare __comp) {
std::__nth_element_impl<_ClassicAlgPolicy>(std::move(__first), std::move(__nth), std::move(__last), __comp); std::__nth_element_impl<_ClassicAlgPolicy>(std::move(__first), std::move(__nth), std::move(__last), __comp);
} }
template <class _RandomAccessIterator> template <class _RandomAccessIterator>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
void nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last) { nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last) {
std::nth_element(std::move(__first), std::move(__nth), std::move(__last), __less<>()); std::nth_element(std::move(__first), std::move(__nth), std::move(__last), __less<>());
} }

View File

@ -29,8 +29,7 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator, class _Sentinel> template <class _AlgPolicy, class _Compare, class _RandomAccessIterator, class _Sentinel>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator __partial_sort_impl(
_RandomAccessIterator __partial_sort_impl(
_RandomAccessIterator __first, _RandomAccessIterator __middle, _Sentinel __last, _Compare&& __comp) { _RandomAccessIterator __first, _RandomAccessIterator __middle, _Sentinel __last, _Compare&& __comp) {
if (__first == __middle) { if (__first == __middle) {
return _IterOps<_AlgPolicy>::next(__middle, __last); return _IterOps<_AlgPolicy>::next(__middle, __last);
@ -40,10 +39,8 @@ _RandomAccessIterator __partial_sort_impl(
typename iterator_traits<_RandomAccessIterator>::difference_type __len = __middle - __first; typename iterator_traits<_RandomAccessIterator>::difference_type __len = __middle - __first;
_RandomAccessIterator __i = __middle; _RandomAccessIterator __i = __middle;
for (; __i != __last; ++__i) for (; __i != __last; ++__i) {
{ if (__comp(*__i, *__first)) {
if (__comp(*__i, *__first))
{
_IterOps<_AlgPolicy>::iter_swap(__i, __first); _IterOps<_AlgPolicy>::iter_swap(__i, __first);
std::__sift_down<_AlgPolicy>(__first, __comp, __len, __first); std::__sift_down<_AlgPolicy>(__first, __comp, __len, __first);
} }
@ -54,9 +51,8 @@ _RandomAccessIterator __partial_sort_impl(
} }
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator, class _Sentinel> template <class _AlgPolicy, class _Compare, class _RandomAccessIterator, class _Sentinel>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator
_RandomAccessIterator __partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _Sentinel __last, __partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _Sentinel __last, _Compare& __comp) {
_Compare& __comp) {
if (__first == __middle) if (__first == __middle)
return _IterOps<_AlgPolicy>::next(__middle, __last); return _IterOps<_AlgPolicy>::next(__middle, __last);
@ -71,11 +67,8 @@ _RandomAccessIterator __partial_sort(_RandomAccessIterator __first, _RandomAcces
} }
template <class _RandomAccessIterator, class _Compare> template <class _RandomAccessIterator, class _Compare>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void partial_sort(
void _RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last, _Compare __comp) {
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_constructible<_RandomAccessIterator>::value, "Iterators must be copy constructible.");
static_assert(std::is_copy_assignable<_RandomAccessIterator>::value, "Iterators must be copy assignable."); static_assert(std::is_copy_assignable<_RandomAccessIterator>::value, "Iterators must be copy assignable.");
@ -83,10 +76,8 @@ partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _Ran
} }
template <class _RandomAccessIterator> template <class _RandomAccessIterator>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
void partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last) {
partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last)
{
std::partial_sort(__first, __middle, __last, __less<>()); std::partial_sort(__first, __middle, __last, __less<>());
} }

View File

@ -30,20 +30,27 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template <class _AlgPolicy, class _Compare, template <class _AlgPolicy,
class _InputIterator, class _Sentinel1, class _RandomAccessIterator, class _Sentinel2, class _Compare,
class _Proj1, class _Proj2> class _InputIterator,
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator, _RandomAccessIterator> class _Sentinel1,
__partial_sort_copy(_InputIterator __first, _Sentinel1 __last, class _RandomAccessIterator,
_RandomAccessIterator __result_first, _Sentinel2 __result_last, class _Sentinel2,
_Compare&& __comp, _Proj1&& __proj1, _Proj2&& __proj2) 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; _RandomAccessIterator __r = __result_first;
auto&& __projected_comp = std::__make_projected(__comp, __proj2); auto&& __projected_comp = std::__make_projected(__comp, __proj2);
if (__r != __result_last) if (__r != __result_last) {
{ for (; __first != __last && __r != __result_last; ++__first, (void)++__r)
for (; __first != __last && __r != __result_last; ++__first, (void) ++__r)
*__r = *__first; *__r = *__first;
std::__make_heap<_AlgPolicy>(__result_first, __r, __projected_comp); std::__make_heap<_AlgPolicy>(__result_first, __r, __projected_comp);
typename iterator_traits<_RandomAccessIterator>::difference_type __len = __r - __result_first; typename iterator_traits<_RandomAccessIterator>::difference_type __len = __r - __result_first;
@ -60,25 +67,32 @@ __partial_sort_copy(_InputIterator __first, _Sentinel1 __last,
} }
template <class _InputIterator, class _RandomAccessIterator, class _Compare> template <class _InputIterator, class _RandomAccessIterator, class _Compare>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator partial_sort_copy(
_RandomAccessIterator _InputIterator __first,
partial_sort_copy(_InputIterator __first, _InputIterator __last, _InputIterator __last,
_RandomAccessIterator __result_first, _RandomAccessIterator __result_last, _Compare __comp) _RandomAccessIterator __result_first,
{ _RandomAccessIterator __result_last,
static_assert(__is_callable<_Compare, decltype(*__first), decltype(*__result_first)>::value, _Compare __comp) {
"Comparator has to be callable"); 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, auto __result = std::__partial_sort_copy<_ClassicAlgPolicy>(
static_cast<__comp_ref_type<_Compare> >(__comp), __identity(), __identity()); __first,
__last,
__result_first,
__result_last,
static_cast<__comp_ref_type<_Compare> >(__comp),
__identity(),
__identity());
return __result.second; return __result.second;
} }
template <class _InputIterator, class _RandomAccessIterator> template <class _InputIterator, class _RandomAccessIterator>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator partial_sort_copy(
_RandomAccessIterator _InputIterator __first,
partial_sort_copy(_InputIterator __first, _InputIterator __last, _InputIterator __last,
_RandomAccessIterator __result_first, _RandomAccessIterator __result_last) _RandomAccessIterator __result_first,
{ _RandomAccessIterator __result_last) {
return std::partial_sort_copy(__first, __last, __result_first, __result_last, __less<>()); return std::partial_sort_copy(__first, __last, __result_first, __result_last, __less<>());
} }

View File

@ -23,10 +23,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <class _Predicate, class _AlgPolicy, class _ForwardIterator, class _Sentinel> template <class _Predicate, class _AlgPolicy, class _ForwardIterator, class _Sentinel>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator, _ForwardIterator> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator, _ForwardIterator>
__partition_impl(_ForwardIterator __first, _Sentinel __last, _Predicate __pred, forward_iterator_tag) __partition_impl(_ForwardIterator __first, _Sentinel __last, _Predicate __pred, forward_iterator_tag) {
{ while (true) {
while (true)
{
if (__first == __last) if (__first == __last)
return std::make_pair(std::move(__first), std::move(__first)); return std::make_pair(std::move(__first), std::move(__first));
if (!__pred(*__first)) if (!__pred(*__first))
@ -35,10 +33,8 @@ __partition_impl(_ForwardIterator __first, _Sentinel __last, _Predicate __pred,
} }
_ForwardIterator __p = __first; _ForwardIterator __p = __first;
while (++__p != __last) while (++__p != __last) {
{ if (__pred(*__p)) {
if (__pred(*__p))
{
_IterOps<_AlgPolicy>::iter_swap(__first, __p); _IterOps<_AlgPolicy>::iter_swap(__first, __p);
++__first; ++__first;
} }
@ -48,24 +44,19 @@ __partition_impl(_ForwardIterator __first, _Sentinel __last, _Predicate __pred,
template <class _Predicate, class _AlgPolicy, class _BidirectionalIterator, class _Sentinel> template <class _Predicate, class _AlgPolicy, class _BidirectionalIterator, class _Sentinel>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_BidirectionalIterator, _BidirectionalIterator> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_BidirectionalIterator, _BidirectionalIterator>
__partition_impl(_BidirectionalIterator __first, _Sentinel __sentinel, _Predicate __pred, __partition_impl(_BidirectionalIterator __first, _Sentinel __sentinel, _Predicate __pred, bidirectional_iterator_tag) {
bidirectional_iterator_tag)
{
_BidirectionalIterator __original_last = _IterOps<_AlgPolicy>::next(__first, __sentinel); _BidirectionalIterator __original_last = _IterOps<_AlgPolicy>::next(__first, __sentinel);
_BidirectionalIterator __last = __original_last; _BidirectionalIterator __last = __original_last;
while (true) while (true) {
{ while (true) {
while (true)
{
if (__first == __last) if (__first == __last)
return std::make_pair(std::move(__first), std::move(__original_last)); return std::make_pair(std::move(__first), std::move(__original_last));
if (!__pred(*__first)) if (!__pred(*__first))
break; break;
++__first; ++__first;
} }
do do {
{
if (__first == --__last) if (__first == --__last)
return std::make_pair(std::move(__first), std::move(__original_last)); return std::make_pair(std::move(__first), std::move(__original_last));
} while (!__pred(*__last)); } while (!__pred(*__last));
@ -75,18 +66,15 @@ __partition_impl(_BidirectionalIterator __first, _Sentinel __sentinel, _Predicat
} }
template <class _AlgPolicy, class _ForwardIterator, class _Sentinel, class _Predicate, class _IterCategory> template <class _AlgPolicy, class _ForwardIterator, class _Sentinel, class _Predicate, class _IterCategory>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator, _ForwardIterator>
pair<_ForwardIterator, _ForwardIterator> __partition( __partition(_ForwardIterator __first, _Sentinel __last, _Predicate&& __pred, _IterCategory __iter_category) {
_ForwardIterator __first, _Sentinel __last, _Predicate&& __pred, _IterCategory __iter_category) {
return std::__partition_impl<__remove_cvref_t<_Predicate>&, _AlgPolicy>( return std::__partition_impl<__remove_cvref_t<_Predicate>&, _AlgPolicy>(
std::move(__first), std::move(__last), __pred, __iter_category); std::move(__first), std::move(__last), __pred, __iter_category);
} }
template <class _ForwardIterator, class _Predicate> template <class _ForwardIterator, class _Predicate>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
_ForwardIterator partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
{
using _IterCategory = typename iterator_traits<_ForwardIterator>::iterator_category; using _IterCategory = typename iterator_traits<_ForwardIterator>::iterator_category;
auto __result = std::__partition<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __pred, _IterCategory()); auto __result = std::__partition<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __pred, _IterCategory());
return __result.first; return __result.first;

View File

@ -19,22 +19,18 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template <class _InputIterator, class _OutputIterator1, template <class _InputIterator, class _OutputIterator1, class _OutputIterator2, class _Predicate>
class _OutputIterator2, class _Predicate> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_OutputIterator1, _OutputIterator2> partition_copy(
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_OutputIterator1, _OutputIterator2> _InputIterator __first,
partition_copy(_InputIterator __first, _InputIterator __last, _InputIterator __last,
_OutputIterator1 __out_true, _OutputIterator2 __out_false, _OutputIterator1 __out_true,
_Predicate __pred) _OutputIterator2 __out_false,
{ _Predicate __pred) {
for (; __first != __last; ++__first) for (; __first != __last; ++__first) {
{ if (__pred(*__first)) {
if (__pred(*__first))
{
*__out_true = *__first; *__out_true = *__first;
++__out_true; ++__out_true;
} } else {
else
{
*__out_false = *__first; *__out_false = *__first;
++__out_false; ++__out_false;
} }

View File

@ -21,23 +21,19 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template<class _ForwardIterator, class _Predicate> template <class _ForwardIterator, class _Predicate>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
partition_point(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) partition_point(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
{
typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type; typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type;
difference_type __len = std::distance(__first, __last); difference_type __len = std::distance(__first, __last);
while (__len != 0) while (__len != 0) {
{
difference_type __l2 = std::__half_positive(__len); difference_type __l2 = std::__half_positive(__len);
_ForwardIterator __m = __first; _ForwardIterator __m = __first;
std::advance(__m, __l2); std::advance(__m, __l2);
if (__pred(*__m)) if (__pred(*__m)) {
{
__first = ++__m; __first = ++__m;
__len -= __l2 + 1; __len -= __l2 + 1;
} } else
else
__len = __l2; __len = __l2;
} }
return __first; return __first;

View File

@ -31,8 +31,10 @@ _LIBCPP_PUSH_MACROS
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator> template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
void __pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare& __comp, __pop_heap(_RandomAccessIterator __first,
_RandomAccessIterator __last,
_Compare& __comp,
typename iterator_traits<_RandomAccessIterator>::difference_type __len) { typename iterator_traits<_RandomAccessIterator>::difference_type __len) {
_LIBCPP_ASSERT_UNCATEGORIZED(__len > 0, "The heap given to pop_heap must be non-empty"); _LIBCPP_ASSERT_UNCATEGORIZED(__len > 0, "The heap given to pop_heap must be non-empty");
@ -56,8 +58,8 @@ void __pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Co
} }
template <class _RandomAccessIterator, class _Compare> template <class _RandomAccessIterator, class _Compare>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
void pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { 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_constructible<_RandomAccessIterator>::value, "Iterators must be copy constructible.");
static_assert(std::is_copy_assignable<_RandomAccessIterator>::value, "Iterators must be copy assignable."); static_assert(std::is_copy_assignable<_RandomAccessIterator>::value, "Iterators must be copy assignable.");
@ -66,8 +68,8 @@ void pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp
} }
template <class _RandomAccessIterator> template <class _RandomAccessIterator>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
void pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) { pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) {
std::pop_heap(std::move(__first), std::move(__last), __less<>()); std::pop_heap(std::move(__first), std::move(__last), __less<>());
} }

View File

@ -25,10 +25,8 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template <class _AlgPolicy, class _Compare, class _BidirectionalIterator, class _Sentinel> template <class _AlgPolicy, class _Compare, class _BidirectionalIterator, class _Sentinel>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_BidirectionalIterator, bool>
pair<_BidirectionalIterator, bool> __prev_permutation(_BidirectionalIterator __first, _Sentinel __last, _Compare&& __comp) {
__prev_permutation(_BidirectionalIterator __first, _Sentinel __last, _Compare&& __comp)
{
using _Result = pair<_BidirectionalIterator, bool>; using _Result = pair<_BidirectionalIterator, bool>;
_BidirectionalIterator __last_iter = _IterOps<_AlgPolicy>::next(__first, __last); _BidirectionalIterator __last_iter = _IterOps<_AlgPolicy>::next(__first, __last);
@ -36,11 +34,9 @@ __prev_permutation(_BidirectionalIterator __first, _Sentinel __last, _Compare&&
if (__first == __last || __first == --__i) if (__first == __last || __first == --__i)
return _Result(std::move(__last_iter), false); return _Result(std::move(__last_iter), false);
while (true) while (true) {
{
_BidirectionalIterator __ip1 = __i; _BidirectionalIterator __ip1 = __i;
if (__comp(*__ip1, *--__i)) if (__comp(*__ip1, *--__i)) {
{
_BidirectionalIterator __j = __last_iter; _BidirectionalIterator __j = __last_iter;
while (!__comp(*--__j, *__i)) while (!__comp(*--__j, *__i))
; ;
@ -48,8 +44,7 @@ __prev_permutation(_BidirectionalIterator __first, _Sentinel __last, _Compare&&
std::__reverse<_AlgPolicy>(__ip1, __last_iter); std::__reverse<_AlgPolicy>(__ip1, __last_iter);
return _Result(std::move(__last_iter), true); return _Result(std::move(__last_iter), true);
} }
if (__i == __first) if (__i == __first) {
{
std::__reverse<_AlgPolicy>(__first, __last_iter); std::__reverse<_AlgPolicy>(__first, __last_iter);
return _Result(std::move(__last_iter), false); return _Result(std::move(__last_iter), false);
} }
@ -57,19 +52,16 @@ __prev_permutation(_BidirectionalIterator __first, _Sentinel __last, _Compare&&
} }
template <class _BidirectionalIterator, class _Compare> template <class _BidirectionalIterator, class _Compare>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
bool prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) {
prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp)
{
return std::__prev_permutation<_ClassicAlgPolicy>( 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> template <class _BidirectionalIterator>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
bool prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last) {
prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last)
{
return std::prev_permutation(__first, __last, __less<>()); return std::prev_permutation(__first, __last, __less<>());
} }

View File

@ -28,8 +28,10 @@ _LIBCPP_PUSH_MACROS
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator> template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
void __sift_up(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare&& __comp, __sift_up(_RandomAccessIterator __first,
_RandomAccessIterator __last,
_Compare&& __comp,
typename iterator_traits<_RandomAccessIterator>::difference_type __len) { typename iterator_traits<_RandomAccessIterator>::difference_type __len) {
using value_type = typename iterator_traits<_RandomAccessIterator>::value_type; using value_type = typename iterator_traits<_RandomAccessIterator>::value_type;
@ -54,15 +56,15 @@ void __sift_up(_RandomAccessIterator __first, _RandomAccessIterator __last, _Com
} }
template <class _AlgPolicy, class _RandomAccessIterator, class _Compare> template <class _AlgPolicy, class _RandomAccessIterator, class _Compare>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
void __push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare& __comp) { __push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare& __comp) {
typename iterator_traits<_RandomAccessIterator>::difference_type __len = __last - __first; 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); std::__sift_up<_AlgPolicy, __comp_ref_type<_Compare> >(std::move(__first), std::move(__last), __comp, __len);
} }
template <class _RandomAccessIterator, class _Compare> template <class _RandomAccessIterator, class _Compare>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
void push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { 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_constructible<_RandomAccessIterator>::value, "Iterators must be copy constructible.");
static_assert(std::is_copy_assignable<_RandomAccessIterator>::value, "Iterators must be copy assignable."); static_assert(std::is_copy_assignable<_RandomAccessIterator>::value, "Iterators must be copy assignable.");
@ -70,8 +72,8 @@ void push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Com
} }
template <class _RandomAccessIterator> template <class _RandomAccessIterator>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
void push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) { push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) {
std::push_heap(std::move(__first), std::move(__last), __less<>()); std::push_heap(std::move(__first), std::move(__last), __less<>());
} }

View File

@ -22,16 +22,12 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <class _ForwardIterator, class _Tp> template <class _ForwardIterator, class _Tp>
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
remove(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) remove(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
{
__first = std::find(__first, __last, __value); __first = std::find(__first, __last, __value);
if (__first != __last) if (__first != __last) {
{
_ForwardIterator __i = __first; _ForwardIterator __i = __first;
while (++__i != __last) while (++__i != __last) {
{ if (!(*__i == __value)) {
if (!(*__i == __value))
{
*__first = std::move(*__i); *__first = std::move(*__i);
++__first; ++__first;
} }

View File

@ -18,14 +18,10 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template <class _InputIterator, class _OutputIterator, class _Tp> template <class _InputIterator, class _OutputIterator, class _Tp>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
_OutputIterator remove_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, const _Tp& __value) {
remove_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, const _Tp& __value) for (; __first != __last; ++__first) {
{ if (!(*__first == __value)) {
for (; __first != __last; ++__first)
{
if (!(*__first == __value))
{
*__result = *__first; *__result = *__first;
++__result; ++__result;
} }

View File

@ -18,14 +18,10 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template <class _InputIterator, class _OutputIterator, class _Predicate> template <class _InputIterator, class _OutputIterator, class _Predicate>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
_OutputIterator remove_copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Predicate __pred) {
remove_copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Predicate __pred) for (; __first != __last; ++__first) {
{ if (!__pred(*__first)) {
for (; __first != __last; ++__first)
{
if (!__pred(*__first))
{
*__result = *__first; *__result = *__first;
++__result; ++__result;
} }

View File

@ -21,16 +21,12 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <class _ForwardIterator, class _Predicate> template <class _ForwardIterator, class _Predicate>
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
remove_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) remove_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
{
__first = std::find_if<_ForwardIterator, _Predicate&>(__first, __last, __pred); __first = std::find_if<_ForwardIterator, _Predicate&>(__first, __last, __pred);
if (__first != __last) if (__first != __last) {
{
_ForwardIterator __i = __first; _ForwardIterator __i = __first;
while (++__i != __last) while (++__i != __last) {
{ if (!__pred(*__i)) {
if (!__pred(*__i))
{
*__first = std::move(*__i); *__first = std::move(*__i);
++__first; ++__first;
} }

View File

@ -18,10 +18,8 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template <class _ForwardIterator, class _Tp> template <class _ForwardIterator, class _Tp>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
void replace(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __old_value, const _Tp& __new_value) {
replace(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __old_value, const _Tp& __new_value)
{
for (; __first != __last; ++__first) for (; __first != __last; ++__first)
if (*__first == __old_value) if (*__first == __old_value)
*__first = __new_value; *__first = __new_value;

View File

@ -18,12 +18,13 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template <class _InputIterator, class _OutputIterator, class _Tp> template <class _InputIterator, class _OutputIterator, class _Tp>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator replace_copy(
_OutputIterator _InputIterator __first,
replace_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _InputIterator __last,
const _Tp& __old_value, const _Tp& __new_value) _OutputIterator __result,
{ const _Tp& __old_value,
for (; __first != __last; ++__first, (void) ++__result) const _Tp& __new_value) {
for (; __first != __last; ++__first, (void)++__result)
if (*__first == __old_value) if (*__first == __old_value)
*__result = __new_value; *__result = __new_value;
else else

View File

@ -18,12 +18,13 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template <class _InputIterator, class _OutputIterator, class _Predicate, class _Tp> template <class _InputIterator, class _OutputIterator, class _Predicate, class _Tp>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator replace_copy_if(
_OutputIterator _InputIterator __first,
replace_copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _InputIterator __last,
_Predicate __pred, const _Tp& __new_value) _OutputIterator __result,
{ _Predicate __pred,
for (; __first != __last; ++__first, (void) ++__result) const _Tp& __new_value) {
for (; __first != __last; ++__first, (void)++__result)
if (__pred(*__first)) if (__pred(*__first))
*__result = __new_value; *__result = __new_value;
else else

View File

@ -18,10 +18,8 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template <class _ForwardIterator, class _Predicate, class _Tp> template <class _ForwardIterator, class _Predicate, class _Tp>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
void replace_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, const _Tp& __new_value) {
replace_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, const _Tp& __new_value)
{
for (; __first != __last; ++__first) for (; __first != __last; ++__first)
if (__pred(*__first)) if (__pred(*__first))
*__first = __new_value; *__first = __new_value;

View File

@ -22,12 +22,9 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template <class _AlgPolicy, class _BidirectionalIterator> template <class _AlgPolicy, class _BidirectionalIterator>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
void __reverse_impl(_BidirectionalIterator __first, _BidirectionalIterator __last, bidirectional_iterator_tag) {
__reverse_impl(_BidirectionalIterator __first, _BidirectionalIterator __last, bidirectional_iterator_tag) while (__first != __last) {
{
while (__first != __last)
{
if (__first == --__last) if (__first == --__last)
break; break;
_IterOps<_AlgPolicy>::iter_swap(__first, __last); _IterOps<_AlgPolicy>::iter_swap(__first, __last);
@ -36,27 +33,22 @@ __reverse_impl(_BidirectionalIterator __first, _BidirectionalIterator __last, bi
} }
template <class _AlgPolicy, class _RandomAccessIterator> template <class _AlgPolicy, class _RandomAccessIterator>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
void __reverse_impl(_RandomAccessIterator __first, _RandomAccessIterator __last, random_access_iterator_tag) {
__reverse_impl(_RandomAccessIterator __first, _RandomAccessIterator __last, random_access_iterator_tag)
{
if (__first != __last) if (__first != __last)
for (; __first < --__last; ++__first) for (; __first < --__last; ++__first)
_IterOps<_AlgPolicy>::iter_swap(__first, __last); _IterOps<_AlgPolicy>::iter_swap(__first, __last);
} }
template <class _AlgPolicy, class _BidirectionalIterator, class _Sentinel> template <class _AlgPolicy, class _BidirectionalIterator, class _Sentinel>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __reverse(_BidirectionalIterator __first, _Sentinel __last) {
void __reverse(_BidirectionalIterator __first, _Sentinel __last) {
using _IterCategory = typename _IterOps<_AlgPolicy>::template __iterator_category<_BidirectionalIterator>; using _IterCategory = typename _IterOps<_AlgPolicy>::template __iterator_category<_BidirectionalIterator>;
std::__reverse_impl<_AlgPolicy>(std::move(__first), std::move(__last), _IterCategory()); std::__reverse_impl<_AlgPolicy>(std::move(__first), std::move(__last), _IterCategory());
} }
template <class _BidirectionalIterator> template <class _BidirectionalIterator>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
void reverse(_BidirectionalIterator __first, _BidirectionalIterator __last) {
reverse(_BidirectionalIterator __first, _BidirectionalIterator __last)
{
std::__reverse<_ClassicAlgPolicy>(std::move(__first), std::move(__last)); std::__reverse<_ClassicAlgPolicy>(std::move(__first), std::move(__last));
} }

View File

@ -18,10 +18,8 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template <class _BidirectionalIterator, class _OutputIterator> template <class _BidirectionalIterator, class _OutputIterator>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
_OutputIterator reverse_copy(_BidirectionalIterator __first, _BidirectionalIterator __last, _OutputIterator __result) {
reverse_copy(_BidirectionalIterator __first, _BidirectionalIterator __last, _OutputIterator __result)
{
for (; __first != __last; ++__result) for (; __first != __last; ++__result)
*__result = *--__last; *__result = *--__last;
return __result; return __result;

View File

@ -27,22 +27,19 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <class _AlgPolicy, class _ForwardIterator> template <class _AlgPolicy, class _ForwardIterator>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator
__rotate_left(_ForwardIterator __first, _ForwardIterator __last) __rotate_left(_ForwardIterator __first, _ForwardIterator __last) {
{
typedef typename iterator_traits<_ForwardIterator>::value_type value_type; typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
using _Ops = _IterOps<_AlgPolicy>; using _Ops = _IterOps<_AlgPolicy>;
value_type __tmp = _Ops::__iter_move(__first); value_type __tmp = _Ops::__iter_move(__first);
_ForwardIterator __lm1 = std::__move<_AlgPolicy>( _ForwardIterator __lm1 = std::__move<_AlgPolicy>(_Ops::next(__first), __last, __first).second;
_Ops::next(__first), __last, __first).second;
*__lm1 = std::move(__tmp); *__lm1 = std::move(__tmp);
return __lm1; return __lm1;
} }
template <class _AlgPolicy, class _BidirectionalIterator> template <class _AlgPolicy, class _BidirectionalIterator>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _BidirectionalIterator _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _BidirectionalIterator
__rotate_right(_BidirectionalIterator __first, _BidirectionalIterator __last) __rotate_right(_BidirectionalIterator __first, _BidirectionalIterator __last) {
{
typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
using _Ops = _IterOps<_AlgPolicy>; using _Ops = _IterOps<_AlgPolicy>;
@ -55,11 +52,9 @@ __rotate_right(_BidirectionalIterator __first, _BidirectionalIterator __last)
template <class _AlgPolicy, class _ForwardIterator> template <class _AlgPolicy, class _ForwardIterator>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 _ForwardIterator _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 _ForwardIterator
__rotate_forward(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last) __rotate_forward(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last) {
{
_ForwardIterator __i = __middle; _ForwardIterator __i = __middle;
while (true) while (true) {
{
_IterOps<_AlgPolicy>::iter_swap(__first, __i); _IterOps<_AlgPolicy>::iter_swap(__first, __i);
++__first; ++__first;
if (++__i == __last) if (++__i == __last)
@ -68,33 +63,25 @@ __rotate_forward(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIt
__middle = __i; __middle = __i;
} }
_ForwardIterator __r = __first; _ForwardIterator __r = __first;
if (__first != __middle) if (__first != __middle) {
{
__i = __middle; __i = __middle;
while (true) while (true) {
{
_IterOps<_AlgPolicy>::iter_swap(__first, __i); _IterOps<_AlgPolicy>::iter_swap(__first, __i);
++__first; ++__first;
if (++__i == __last) if (++__i == __last) {
{
if (__first == __middle) if (__first == __middle)
break; break;
__i = __middle; __i = __middle;
} } else if (__first == __middle)
else if (__first == __middle)
__middle = __i; __middle = __i;
} }
} }
return __r; return __r;
} }
template<typename _Integral> template <typename _Integral>
inline _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 _Integral __algo_gcd(_Integral __x, _Integral __y) {
_LIBCPP_CONSTEXPR_SINCE_CXX17 _Integral do {
__algo_gcd(_Integral __x, _Integral __y)
{
do
{
_Integral __t = __x % __y; _Integral __t = __x % __y;
__x = __y; __x = __y;
__y = __t; __y = __t;
@ -104,27 +91,23 @@ __algo_gcd(_Integral __x, _Integral __y)
template <class _AlgPolicy, typename _RandomAccessIterator> template <class _AlgPolicy, typename _RandomAccessIterator>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 _RandomAccessIterator _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 _RandomAccessIterator
__rotate_gcd(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last) __rotate_gcd(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last) {
{
typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
using _Ops = _IterOps<_AlgPolicy>; using _Ops = _IterOps<_AlgPolicy>;
const difference_type __m1 = __middle - __first; const difference_type __m1 = __middle - __first;
const difference_type __m2 = _Ops::distance(__middle, __last); const difference_type __m2 = _Ops::distance(__middle, __last);
if (__m1 == __m2) if (__m1 == __m2) {
{
std::__swap_ranges<_AlgPolicy>(__first, __middle, __middle, __last); std::__swap_ranges<_AlgPolicy>(__first, __middle, __middle, __last);
return __middle; return __middle;
} }
const difference_type __g = std::__algo_gcd(__m1, __m2); const difference_type __g = std::__algo_gcd(__m1, __m2);
for (_RandomAccessIterator __p = __first + __g; __p != __first;) for (_RandomAccessIterator __p = __first + __g; __p != __first;) {
{
value_type __t(_Ops::__iter_move(--__p)); value_type __t(_Ops::__iter_move(--__p));
_RandomAccessIterator __p1 = __p; _RandomAccessIterator __p1 = __p;
_RandomAccessIterator __p2 = __p1 + __m1; _RandomAccessIterator __p2 = __p1 + __m1;
do do {
{
*__p1 = _Ops::__iter_move(__p2); *__p1 = _Ops::__iter_move(__p2);
__p1 = __p2; __p1 = __p2;
const difference_type __d = _Ops::distance(__p2, __last); const difference_type __d = _Ops::distance(__p2, __last);
@ -139,14 +122,10 @@ __rotate_gcd(_RandomAccessIterator __first, _RandomAccessIterator __middle, _Ran
} }
template <class _AlgPolicy, class _ForwardIterator> template <class _AlgPolicy, class _ForwardIterator>
inline _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator
_LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator __rotate_impl(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last, std::forward_iterator_tag) {
__rotate_impl(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last,
std::forward_iterator_tag)
{
typedef typename iterator_traits<_ForwardIterator>::value_type value_type; typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
if (is_trivially_move_assignable<value_type>::value) if (is_trivially_move_assignable<value_type>::value) {
{
if (_IterOps<_AlgPolicy>::next(__first) == __middle) if (_IterOps<_AlgPolicy>::next(__first) == __middle)
return std::__rotate_left<_AlgPolicy>(__first, __last); return std::__rotate_left<_AlgPolicy>(__first, __last);
} }
@ -154,14 +133,13 @@ __rotate_impl(_ForwardIterator __first, _ForwardIterator __middle, _ForwardItera
} }
template <class _AlgPolicy, class _BidirectionalIterator> template <class _AlgPolicy, class _BidirectionalIterator>
inline _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _BidirectionalIterator __rotate_impl(
_LIBCPP_CONSTEXPR_SINCE_CXX14 _BidirectionalIterator _BidirectionalIterator __first,
__rotate_impl(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last, _BidirectionalIterator __middle,
bidirectional_iterator_tag) _BidirectionalIterator __last,
{ bidirectional_iterator_tag) {
typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
if (is_trivially_move_assignable<value_type>::value) if (is_trivially_move_assignable<value_type>::value) {
{
if (_IterOps<_AlgPolicy>::next(__first) == __middle) if (_IterOps<_AlgPolicy>::next(__first) == __middle)
return std::__rotate_left<_AlgPolicy>(__first, __last); return std::__rotate_left<_AlgPolicy>(__first, __last);
if (_IterOps<_AlgPolicy>::next(__middle) == __last) if (_IterOps<_AlgPolicy>::next(__middle) == __last)
@ -171,14 +149,13 @@ __rotate_impl(_BidirectionalIterator __first, _BidirectionalIterator __middle, _
} }
template <class _AlgPolicy, class _RandomAccessIterator> template <class _AlgPolicy, class _RandomAccessIterator>
inline _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _RandomAccessIterator __rotate_impl(
_LIBCPP_CONSTEXPR_SINCE_CXX14 _RandomAccessIterator _RandomAccessIterator __first,
__rotate_impl(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last, _RandomAccessIterator __middle,
random_access_iterator_tag) _RandomAccessIterator __last,
{ random_access_iterator_tag) {
typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
if (is_trivially_move_assignable<value_type>::value) if (is_trivially_move_assignable<value_type>::value) {
{
if (_IterOps<_AlgPolicy>::next(__first) == __middle) if (_IterOps<_AlgPolicy>::next(__first) == __middle)
return std::__rotate_left<_AlgPolicy>(__first, __last); return std::__rotate_left<_AlgPolicy>(__first, __last);
if (_IterOps<_AlgPolicy>::next(__middle) == __last) if (_IterOps<_AlgPolicy>::next(__middle) == __last)
@ -189,8 +166,7 @@ __rotate_impl(_RandomAccessIterator __first, _RandomAccessIterator __middle, _Ra
} }
template <class _AlgPolicy, class _Iterator, class _Sentinel> template <class _AlgPolicy, class _Iterator, class _Sentinel>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iterator, _Iterator>
pair<_Iterator, _Iterator>
__rotate(_Iterator __first, _Iterator __middle, _Sentinel __last) { __rotate(_Iterator __first, _Iterator __middle, _Sentinel __last) {
using _Ret = pair<_Iterator, _Iterator>; using _Ret = pair<_Iterator, _Iterator>;
_Iterator __last_iter = _IterOps<_AlgPolicy>::next(__middle, __last); _Iterator __last_iter = _IterOps<_AlgPolicy>::next(__middle, __last);
@ -201,19 +177,15 @@ __rotate(_Iterator __first, _Iterator __middle, _Sentinel __last) {
return _Ret(std::move(__first), std::move(__last_iter)); return _Ret(std::move(__first), std::move(__last_iter));
using _IterCategory = typename _IterOps<_AlgPolicy>::template __iterator_category<_Iterator>; using _IterCategory = typename _IterOps<_AlgPolicy>::template __iterator_category<_Iterator>;
auto __result = std::__rotate_impl<_AlgPolicy>( auto __result = std::__rotate_impl<_AlgPolicy>(std::move(__first), std::move(__middle), __last_iter, _IterCategory());
std::move(__first), std::move(__middle), __last_iter, _IterCategory());
return _Ret(std::move(__result), std::move(__last_iter)); return _Ret(std::move(__result), std::move(__last_iter));
} }
template <class _ForwardIterator> template <class _ForwardIterator>
inline _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
_LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator rotate(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last) {
rotate(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last) return std::__rotate<_ClassicAlgPolicy>(std::move(__first), std::move(__middle), std::move(__last)).first;
{
return std::__rotate<_ClassicAlgPolicy>(
std::move(__first), std::move(__middle), std::move(__last)).first;
} }
_LIBCPP_END_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD

View File

@ -19,10 +19,8 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template <class _ForwardIterator, class _OutputIterator> template <class _ForwardIterator, class _OutputIterator>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
_OutputIterator rotate_copy(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last, _OutputIterator __result) {
rotate_copy(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last, _OutputIterator __result)
{
return std::copy(__first, __middle, std::copy(__middle, __last, __result)); return std::copy(__first, __middle, std::copy(__middle, __last, __result));
} }

View File

@ -29,20 +29,23 @@ _LIBCPP_PUSH_MACROS
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template <class _AlgPolicy, template <class _AlgPolicy,
class _PopulationIterator, class _PopulationSentinel, class _SampleIterator, class _Distance, class _PopulationIterator,
class _PopulationSentinel,
class _SampleIterator,
class _Distance,
class _UniformRandomNumberGenerator> class _UniformRandomNumberGenerator>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _SampleIterator __sample(
_SampleIterator __sample(_PopulationIterator __first, _PopulationIterator __first,
_PopulationSentinel __last, _SampleIterator __output_iter, _PopulationSentinel __last,
_SampleIterator __output_iter,
_Distance __n, _Distance __n,
_UniformRandomNumberGenerator& __g, _UniformRandomNumberGenerator& __g,
input_iterator_tag) { input_iterator_tag) {
_Distance __k = 0; _Distance __k = 0;
for (; __first != __last && __k < __n; ++__first, (void) ++__k) for (; __first != __last && __k < __n; ++__first, (void)++__k)
__output_iter[__k] = *__first; __output_iter[__k] = *__first;
_Distance __sz = __k; _Distance __sz = __k;
for (; __first != __last; ++__first, (void) ++__k) { for (; __first != __last; ++__first, (void)++__k) {
_Distance __r = uniform_int_distribution<_Distance>(0, __k)(__g); _Distance __r = uniform_int_distribution<_Distance>(0, __k)(__g);
if (__r < __sz) if (__r < __sz)
__output_iter[__r] = *__first; __output_iter[__r] = *__first;
@ -51,11 +54,15 @@ _SampleIterator __sample(_PopulationIterator __first,
} }
template <class _AlgPolicy, template <class _AlgPolicy,
class _PopulationIterator, class _PopulationSentinel, class _SampleIterator, class _Distance, class _PopulationIterator,
class _PopulationSentinel,
class _SampleIterator,
class _Distance,
class _UniformRandomNumberGenerator> class _UniformRandomNumberGenerator>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _SampleIterator __sample(
_SampleIterator __sample(_PopulationIterator __first, _PopulationIterator __first,
_PopulationSentinel __last, _SampleIterator __output_iter, _PopulationSentinel __last,
_SampleIterator __output_iter,
_Distance __n, _Distance __n,
_UniformRandomNumberGenerator& __g, _UniformRandomNumberGenerator& __g,
forward_iterator_tag) { forward_iterator_tag) {
@ -71,12 +78,17 @@ _SampleIterator __sample(_PopulationIterator __first,
} }
template <class _AlgPolicy, template <class _AlgPolicy,
class _PopulationIterator, class _PopulationSentinel, class _SampleIterator, class _Distance, class _PopulationIterator,
class _PopulationSentinel,
class _SampleIterator,
class _Distance,
class _UniformRandomNumberGenerator> class _UniformRandomNumberGenerator>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _SampleIterator __sample(
_SampleIterator __sample(_PopulationIterator __first, _PopulationIterator __first,
_PopulationSentinel __last, _SampleIterator __output_iter, _PopulationSentinel __last,
_Distance __n, _UniformRandomNumberGenerator& __g) { _SampleIterator __output_iter,
_Distance __n,
_UniformRandomNumberGenerator& __g) {
_LIBCPP_ASSERT_UNCATEGORIZED(__n >= 0, "N must be a positive number."); _LIBCPP_ASSERT_UNCATEGORIZED(__n >= 0, "N must be a positive number.");
using _PopIterCategory = typename _IterOps<_AlgPolicy>::template __iterator_category<_PopulationIterator>; using _PopIterCategory = typename _IterOps<_AlgPolicy>::template __iterator_category<_PopulationIterator>;
@ -84,23 +96,22 @@ _SampleIterator __sample(_PopulationIterator __first,
using _CommonType = typename common_type<_Distance, _Difference>::type; using _CommonType = typename common_type<_Distance, _Difference>::type;
return std::__sample<_AlgPolicy>( return std::__sample<_AlgPolicy>(
std::move(__first), std::move(__last), std::move(__output_iter), _CommonType(__n), std::move(__first), std::move(__last), std::move(__output_iter), _CommonType(__n), __g, _PopIterCategory());
__g, _PopIterCategory());
} }
#if _LIBCPP_STD_VER >= 17 #if _LIBCPP_STD_VER >= 17
template <class _PopulationIterator, class _SampleIterator, class _Distance, template <class _PopulationIterator, class _SampleIterator, class _Distance, class _UniformRandomNumberGenerator>
class _UniformRandomNumberGenerator> inline _LIBCPP_HIDE_FROM_ABI _SampleIterator
inline _LIBCPP_HIDE_FROM_ABI sample(_PopulationIterator __first,
_SampleIterator sample(_PopulationIterator __first, _PopulationIterator __last,
_PopulationIterator __last, _SampleIterator __output_iter, _SampleIterator __output_iter,
_Distance __n, _UniformRandomNumberGenerator&& __g) { _Distance __n,
_UniformRandomNumberGenerator&& __g) {
static_assert(__has_forward_iterator_category<_PopulationIterator>::value || static_assert(__has_forward_iterator_category<_PopulationIterator>::value ||
__has_random_access_iterator_category<_SampleIterator>::value, __has_random_access_iterator_category<_SampleIterator>::value,
"SampleIterator must meet the requirements of RandomAccessIterator"); "SampleIterator must meet the requirements of RandomAccessIterator");
return std::__sample<_ClassicAlgPolicy>( return std::__sample<_ClassicAlgPolicy>(std::move(__first), std::move(__last), std::move(__output_iter), __n, __g);
std::move(__first), std::move(__last), std::move(__output_iter), __n, __g);
} }
#endif // _LIBCPP_STD_VER >= 17 #endif // _LIBCPP_STD_VER >= 17

View File

@ -29,17 +29,15 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template <class _AlgPolicy, template <class _AlgPolicy,
class _Iter1, class _Sent1, class _Iter1,
class _Iter2, class _Sent2, class _Sent1,
class _Iter2,
class _Sent2,
class _Pred, class _Pred,
class _Proj1, class _Proj1,
class _Proj2> class _Proj2>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1> __search_forward_impl(
pair<_Iter1, _Iter1> __search_forward_impl(_Iter1 __first1, _Sent1 __last1, _Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, _Pred& __pred, _Proj1& __proj1, _Proj2& __proj2) {
_Iter2 __first2, _Sent2 __last2,
_Pred& __pred,
_Proj1& __proj1,
_Proj2& __proj2) {
if (__first2 == __last2) if (__first2 == __last2)
return std::make_pair(__first1, __first1); // Everything matches an empty sequence return std::make_pair(__first1, __first1); // Everything matches an empty sequence
while (true) { while (true) {
@ -64,8 +62,7 @@ pair<_Iter1, _Iter1> __search_forward_impl(_Iter1 __first1, _Sent1 __last1,
} }
// if there is a mismatch, restart with a new __first1 // if there is a mismatch, restart with a new __first1
if (!std::__invoke(__pred, std::__invoke(__proj1, *__m1), std::__invoke(__proj2, *__m2))) if (!std::__invoke(__pred, std::__invoke(__proj1, *__m1), std::__invoke(__proj2, *__m2))) {
{
++__first1; ++__first1;
break; break;
} // else there is a match, check next elements } // else there is a match, check next elements
@ -74,16 +71,20 @@ pair<_Iter1, _Iter1> __search_forward_impl(_Iter1 __first1, _Sent1 __last1,
} }
template <class _AlgPolicy, template <class _AlgPolicy,
class _Iter1, class _Sent1, class _Iter1,
class _Iter2, class _Sent2, class _Sent1,
class _Iter2,
class _Sent2,
class _Pred, class _Pred,
class _Proj1, class _Proj1,
class _Proj2, class _Proj2,
class _DiffT1, class _DiffT1,
class _DiffT2> class _DiffT2>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1> __search_random_access_impl(
pair<_Iter1, _Iter1> __search_random_access_impl(_Iter1 __first1, _Sent1 __last1, _Iter1 __first1,
_Iter2 __first2, _Sent2 __last2, _Sent1 __last1,
_Iter2 __first2,
_Sent2 __last2,
_Pred& __pred, _Pred& __pred,
_Proj1& __proj1, _Proj1& __proj1,
_Proj2& __proj2, _Proj2& __proj2,
@ -116,20 +117,17 @@ pair<_Iter1, _Iter1> __search_random_access_impl(_Iter1 __first1, _Sent1 __last1
} }
} }
template <class _Iter1, class _Sent1, template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Pred, class _Proj1, class _Proj2>
class _Iter2, class _Sent2, _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1> __search_impl(
class _Pred, _Iter1 __first1,
class _Proj1, _Sent1 __last1,
class _Proj2> _Iter2 __first2,
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Sent2 __last2,
pair<_Iter1, _Iter1> __search_impl(_Iter1 __first1, _Sent1 __last1,
_Iter2 __first2, _Sent2 __last2,
_Pred& __pred, _Pred& __pred,
_Proj1& __proj1, _Proj1& __proj1,
_Proj2& __proj2, _Proj2& __proj2,
__enable_if_t<__has_random_access_iterator_category<_Iter1>::value __enable_if_t<__has_random_access_iterator_category<_Iter1>::value &&
&& __has_random_access_iterator_category<_Iter2>::value>* = nullptr) { __has_random_access_iterator_category<_Iter2>::value>* = nullptr) {
auto __size2 = __last2 - __first2; auto __size2 = __last2 - __first2;
if (__size2 == 0) if (__size2 == 0)
return std::make_pair(__first1, __first1); return std::make_pair(__first1, __first1);
@ -139,41 +137,31 @@ pair<_Iter1, _Iter1> __search_impl(_Iter1 __first1, _Sent1 __last1,
return std::make_pair(__last1, __last1); return std::make_pair(__last1, __last1);
} }
return std::__search_random_access_impl<_ClassicAlgPolicy>(__first1, __last1, return std::__search_random_access_impl<_ClassicAlgPolicy>(
__first2, __last2, __first1, __last1, __first2, __last2, __pred, __proj1, __proj2, __size1, __size2);
__pred,
__proj1,
__proj2,
__size1,
__size2);
} }
template <class _Iter1, class _Sent1, template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Pred, class _Proj1, class _Proj2>
class _Iter2, class _Sent2, _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1> __search_impl(
class _Pred, _Iter1 __first1,
class _Proj1, _Sent1 __last1,
class _Proj2> _Iter2 __first2,
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Sent2 __last2,
pair<_Iter1, _Iter1> __search_impl(_Iter1 __first1, _Sent1 __last1,
_Iter2 __first2, _Sent2 __last2,
_Pred& __pred, _Pred& __pred,
_Proj1& __proj1, _Proj1& __proj1,
_Proj2& __proj2, _Proj2& __proj2,
__enable_if_t<__has_forward_iterator_category<_Iter1>::value __enable_if_t<__has_forward_iterator_category<_Iter1>::value && __has_forward_iterator_category<_Iter2>::value &&
&& __has_forward_iterator_category<_Iter2>::value !(__has_random_access_iterator_category<_Iter1>::value &&
&& !(__has_random_access_iterator_category<_Iter1>::value __has_random_access_iterator_category<_Iter2>::value)>* = nullptr) {
&& __has_random_access_iterator_category<_Iter2>::value)>* = nullptr) { return std::__search_forward_impl<_ClassicAlgPolicy>(__first1, __last1, __first2, __last2, __pred, __proj1, __proj2);
return std::__search_forward_impl<_ClassicAlgPolicy>(__first1, __last1,
__first2, __last2,
__pred,
__proj1,
__proj2);
} }
template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate> template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1
_ForwardIterator1 search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, search(_ForwardIterator1 __first1,
_ForwardIterator2 __first2, _ForwardIterator2 __last2, _ForwardIterator1 __last1,
_ForwardIterator2 __first2,
_ForwardIterator2 __last2,
_BinaryPredicate __pred) { _BinaryPredicate __pred) {
static_assert(__is_callable<_BinaryPredicate, decltype(*__first1), decltype(*__first2)>::value, static_assert(__is_callable<_BinaryPredicate, decltype(*__first1), decltype(*__first2)>::value,
"BinaryPredicate has to be callable"); "BinaryPredicate has to be callable");
@ -182,9 +170,8 @@ _ForwardIterator1 search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
} }
template <class _ForwardIterator1, class _ForwardIterator2> template <class _ForwardIterator1, class _ForwardIterator2>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1
_ForwardIterator1 search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) {
_ForwardIterator2 __first2, _ForwardIterator2 __last2) {
return std::search(__first1, __last1, __first2, __last2, __equal_to()); return std::search(__first1, __last1, __first2, __last2, __equal_to());
} }

View File

@ -31,12 +31,8 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template <class _AlgPolicy, class _Pred, class _Iter, class _Sent, class _SizeT, class _Type, class _Proj> template <class _AlgPolicy, class _Pred, class _Iter, class _Sent, class _SizeT, class _Type, class _Proj>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter, _Iter> __search_n_forward_impl(
pair<_Iter, _Iter> __search_n_forward_impl(_Iter __first, _Sent __last, _Iter __first, _Sent __last, _SizeT __count, const _Type& __value, _Pred& __pred, _Proj& __proj) {
_SizeT __count,
const _Type& __value,
_Pred& __pred,
_Proj& __proj) {
if (__count <= 0) if (__count <= 0)
return std::make_pair(__first, __first); return std::make_pair(__first, __first);
while (true) { while (true) {
@ -62,8 +58,7 @@ pair<_Iter, _Iter> __search_n_forward_impl(_Iter __first, _Sent __last,
} }
// if there is a mismatch, restart with a new __first // if there is a mismatch, restart with a new __first
if (!std::__invoke(__pred, std::__invoke(__proj, *__m), __value)) if (!std::__invoke(__pred, std::__invoke(__proj, *__m), __value)) {
{
__first = __m; __first = __m;
++__first; ++__first;
break; break;
@ -73,13 +68,8 @@ pair<_Iter, _Iter> __search_n_forward_impl(_Iter __first, _Sent __last,
} }
template <class _AlgPolicy, class _Pred, class _Iter, class _Sent, class _SizeT, class _Type, class _Proj, class _DiffT> template <class _AlgPolicy, class _Pred, class _Iter, class _Sent, class _SizeT, class _Type, class _Proj, class _DiffT>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 std::pair<_Iter, _Iter> __search_n_random_access_impl(
std::pair<_Iter, _Iter> __search_n_random_access_impl(_Iter __first, _Sent __last, _Iter __first, _Sent __last, _SizeT __count, const _Type& __value, _Pred& __pred, _Proj& __proj, _DiffT __size1) {
_SizeT __count,
const _Type& __value,
_Pred& __pred,
_Proj& __proj,
_DiffT __size1) {
using difference_type = typename iterator_traits<_Iter>::difference_type; using difference_type = typename iterator_traits<_Iter>::difference_type;
if (__count == 0) if (__count == 0)
return std::make_pair(__first, __first); return std::make_pair(__first, __first);
@ -109,8 +99,7 @@ std::pair<_Iter, _Iter> __search_n_random_access_impl(_Iter __first, _Sent __las
++__m; // no need to check range on __m because __s guarantees we have enough source ++__m; // no need to check range on __m because __s guarantees we have enough source
// if there is a mismatch, restart with a new __first // if there is a mismatch, restart with a new __first
if (!std::__invoke(__pred, std::__invoke(__proj, *__m), __value)) if (!std::__invoke(__pred, std::__invoke(__proj, *__m), __value)) {
{
__first = __m; __first = __m;
++__first; ++__first;
break; break;
@ -119,61 +108,44 @@ std::pair<_Iter, _Iter> __search_n_random_access_impl(_Iter __first, _Sent __las
} }
} }
template <class _Iter, class _Sent, template <class _Iter, class _Sent, class _DiffT, class _Type, class _Pred, class _Proj>
class _DiffT, _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter, _Iter> __search_n_impl(
class _Type, _Iter __first,
class _Pred, _Sent __last,
class _Proj>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
pair<_Iter, _Iter> __search_n_impl(_Iter __first, _Sent __last,
_DiffT __count, _DiffT __count,
const _Type& __value, const _Type& __value,
_Pred& __pred, _Pred& __pred,
_Proj& __proj, _Proj& __proj,
__enable_if_t<__has_random_access_iterator_category<_Iter>::value>* = nullptr) { __enable_if_t<__has_random_access_iterator_category<_Iter>::value>* = nullptr) {
return std::__search_n_random_access_impl<_ClassicAlgPolicy>(__first, __last, return std::__search_n_random_access_impl<_ClassicAlgPolicy>(
__count, __first, __last, __count, __value, __pred, __proj, __last - __first);
__value,
__pred,
__proj,
__last - __first);
} }
template <class _Iter1, class _Sent1, template <class _Iter1, class _Sent1, class _DiffT, class _Type, class _Pred, class _Proj>
class _DiffT, _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1> __search_n_impl(
class _Type, _Iter1 __first,
class _Pred, _Sent1 __last,
class _Proj>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
pair<_Iter1, _Iter1> __search_n_impl(_Iter1 __first, _Sent1 __last,
_DiffT __count, _DiffT __count,
const _Type& __value, const _Type& __value,
_Pred& __pred, _Pred& __pred,
_Proj& __proj, _Proj& __proj,
__enable_if_t<__has_forward_iterator_category<_Iter1>::value __enable_if_t<__has_forward_iterator_category<_Iter1>::value &&
&& !__has_random_access_iterator_category<_Iter1>::value>* = nullptr) { !__has_random_access_iterator_category<_Iter1>::value>* = nullptr) {
return std::__search_n_forward_impl<_ClassicAlgPolicy>(__first, __last, return std::__search_n_forward_impl<_ClassicAlgPolicy>(__first, __last, __count, __value, __pred, __proj);
__count,
__value,
__pred,
__proj);
} }
template <class _ForwardIterator, class _Size, class _Tp, class _BinaryPredicate> template <class _ForwardIterator, class _Size, class _Tp, class _BinaryPredicate>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator search_n(
_ForwardIterator search_n(_ForwardIterator __first, _ForwardIterator __last, _ForwardIterator __first, _ForwardIterator __last, _Size __count, const _Tp& __value, _BinaryPredicate __pred) {
_Size __count, static_assert(
const _Tp& __value, __is_callable<_BinaryPredicate, decltype(*__first), const _Tp&>::value, "BinaryPredicate has to be callable");
_BinaryPredicate __pred) {
static_assert(__is_callable<_BinaryPredicate, decltype(*__first), const _Tp&>::value,
"BinaryPredicate has to be callable");
auto __proj = __identity(); auto __proj = __identity();
return std::__search_n_impl(__first, __last, std::__convert_to_integral(__count), __value, __pred, __proj).first; return std::__search_n_impl(__first, __last, std::__convert_to_integral(__count), __value, __pred, __proj).first;
} }
template <class _ForwardIterator, class _Size, class _Tp> template <class _ForwardIterator, class _Size, class _Tp>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
_ForwardIterator search_n(_ForwardIterator __first, _ForwardIterator __last, _Size __count, const _Tp& __value) { search_n(_ForwardIterator __first, _ForwardIterator __last, _Size __count, const _Tp& __value) {
return std::search_n(__first, __last, std::__convert_to_integral(__count), __value, __equal_to()); return std::search_n(__first, __last, std::__convert_to_integral(__count), __value, __equal_to());
} }

View File

@ -22,11 +22,10 @@ _LIBCPP_BEGIN_NAMESPACE_STD
#if _LIBCPP_STD_VER >= 20 #if _LIBCPP_STD_VER >= 20
template <class _ForwardIterator> template <class _ForwardIterator>
inline _LIBCPP_HIDE_FROM_ABI constexpr inline _LIBCPP_HIDE_FROM_ABI constexpr _ForwardIterator
_ForwardIterator shift_left(_ForwardIterator __first,
shift_left(_ForwardIterator __first, _ForwardIterator __last, _ForwardIterator __last,
typename iterator_traits<_ForwardIterator>::difference_type __n) typename iterator_traits<_ForwardIterator>::difference_type __n) {
{
if (__n == 0) { if (__n == 0) {
return __last; return __last;
} }

View File

@ -25,11 +25,10 @@ _LIBCPP_BEGIN_NAMESPACE_STD
#if _LIBCPP_STD_VER >= 20 #if _LIBCPP_STD_VER >= 20
template <class _ForwardIterator> template <class _ForwardIterator>
inline _LIBCPP_HIDE_FROM_ABI constexpr inline _LIBCPP_HIDE_FROM_ABI constexpr _ForwardIterator
_ForwardIterator shift_right(_ForwardIterator __first,
shift_right(_ForwardIterator __first, _ForwardIterator __last, _ForwardIterator __last,
typename iterator_traits<_ForwardIterator>::difference_type __n) typename iterator_traits<_ForwardIterator>::difference_type __n) {
{
if (__n == 0) { if (__n == 0) {
return __first; return __first;
} }

View File

@ -62,17 +62,16 @@ private:
} }
}; };
#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE) \ #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE) || defined(_LIBCPP_BUILDING_LIBRARY)
|| defined(_LIBCPP_BUILDING_LIBRARY)
class _LIBCPP_EXPORTED_FROM_ABI __rs_default; class _LIBCPP_EXPORTED_FROM_ABI __rs_default;
_LIBCPP_EXPORTED_FROM_ABI __rs_default __rs_get(); _LIBCPP_EXPORTED_FROM_ABI __rs_default __rs_get();
class _LIBCPP_EXPORTED_FROM_ABI __rs_default class _LIBCPP_EXPORTED_FROM_ABI __rs_default {
{
static unsigned __c_; static unsigned __c_;
__rs_default(); __rs_default();
public: public:
typedef uint_fast32_t result_type; typedef uint_fast32_t result_type;
@ -84,8 +83,8 @@ public:
result_type operator()(); result_type operator()();
static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR result_type min() {return _Min;} static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR result_type min() { return _Min; }
static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR result_type max() {return _Max;} static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR result_type max() { return _Max; }
friend _LIBCPP_EXPORTED_FROM_ABI __rs_default __rs_get(); friend _LIBCPP_EXPORTED_FROM_ABI __rs_default __rs_get();
}; };
@ -94,18 +93,15 @@ _LIBCPP_EXPORTED_FROM_ABI __rs_default __rs_get();
template <class _RandomAccessIterator> template <class _RandomAccessIterator>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_IN_CXX14 void _LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_IN_CXX14 void
random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last) random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last) {
{
typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
typedef uniform_int_distribution<ptrdiff_t> _Dp; typedef uniform_int_distribution<ptrdiff_t> _Dp;
typedef typename _Dp::param_type _Pp; typedef typename _Dp::param_type _Pp;
difference_type __d = __last - __first; difference_type __d = __last - __first;
if (__d > 1) if (__d > 1) {
{
_Dp __uid; _Dp __uid;
__rs_default __g = __rs_get(); __rs_default __g = __rs_get();
for (--__last, (void) --__d; __first < __last; ++__first, (void) --__d) for (--__last, (void)--__d; __first < __last; ++__first, (void)--__d) {
{
difference_type __i = __uid(__g, _Pp(0, __d)); difference_type __i = __uid(__g, _Pp(0, __d));
if (__i != difference_type(0)) if (__i != difference_type(0))
swap(*__first, *(__first + __i)); swap(*__first, *(__first + __i));
@ -115,19 +111,18 @@ random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last)
template <class _RandomAccessIterator, class _RandomNumberGenerator> template <class _RandomAccessIterator, class _RandomNumberGenerator>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_IN_CXX14 void _LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_IN_CXX14 void
random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last, random_shuffle(_RandomAccessIterator __first,
#ifndef _LIBCPP_CXX03_LANG _RandomAccessIterator __last,
# ifndef _LIBCPP_CXX03_LANG
_RandomNumberGenerator&& __rand) _RandomNumberGenerator&& __rand)
#else # else
_RandomNumberGenerator& __rand) _RandomNumberGenerator& __rand)
#endif # endif
{ {
typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
difference_type __d = __last - __first; difference_type __d = __last - __first;
if (__d > 1) if (__d > 1) {
{ for (--__last; __first < __last; ++__first, (void)--__d) {
for (--__last; __first < __last; ++__first, (void) --__d)
{
difference_type __i = __rand(__d); difference_type __i = __rand(__d);
if (__i != difference_type(0)) if (__i != difference_type(0))
swap(*__first, *(__first + __i)); swap(*__first, *(__first + __i));
@ -137,8 +132,8 @@ random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last,
#endif #endif
template <class _AlgPolicy, class _RandomAccessIterator, class _Sentinel, class _UniformRandomNumberGenerator> template <class _AlgPolicy, class _RandomAccessIterator, class _Sentinel, class _UniformRandomNumberGenerator>
_LIBCPP_HIDE_FROM_ABI _RandomAccessIterator __shuffle( _LIBCPP_HIDE_FROM_ABI _RandomAccessIterator
_RandomAccessIterator __first, _Sentinel __last_sentinel, _UniformRandomNumberGenerator&& __g) { __shuffle(_RandomAccessIterator __first, _Sentinel __last_sentinel, _UniformRandomNumberGenerator&& __g) {
typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
typedef uniform_int_distribution<ptrdiff_t> _Dp; typedef uniform_int_distribution<ptrdiff_t> _Dp;
typedef typename _Dp::param_type _Pp; typedef typename _Dp::param_type _Pp;
@ -146,11 +141,9 @@ _LIBCPP_HIDE_FROM_ABI _RandomAccessIterator __shuffle(
auto __original_last = _IterOps<_AlgPolicy>::next(__first, __last_sentinel); auto __original_last = _IterOps<_AlgPolicy>::next(__first, __last_sentinel);
auto __last = __original_last; auto __last = __original_last;
difference_type __d = __last - __first; difference_type __d = __last - __first;
if (__d > 1) if (__d > 1) {
{
_Dp __uid; _Dp __uid;
for (--__last, (void) --__d; __first < __last; ++__first, (void) --__d) for (--__last, (void)--__d; __first < __last; ++__first, (void)--__d) {
{
difference_type __i = __uid(__g, _Pp(0, __d)); difference_type __i = __uid(__g, _Pp(0, __d));
if (__i != difference_type(0)) if (__i != difference_type(0))
_IterOps<_AlgPolicy>::iter_swap(__first, __first + __i); _IterOps<_AlgPolicy>::iter_swap(__first, __first + __i);

View File

@ -26,10 +26,10 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator> template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
__sift_down(_RandomAccessIterator __first, _Compare&& __comp, __sift_down(_RandomAccessIterator __first,
_Compare&& __comp,
typename iterator_traits<_RandomAccessIterator>::difference_type __len, typename iterator_traits<_RandomAccessIterator>::difference_type __len,
_RandomAccessIterator __start) _RandomAccessIterator __start) {
{
using _Ops = _IterOps<_AlgPolicy>; using _Ops = _IterOps<_AlgPolicy>;
typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
@ -56,8 +56,7 @@ __sift_down(_RandomAccessIterator __first, _Compare&& __comp,
return; return;
value_type __top(_Ops::__iter_move(__start)); value_type __top(_Ops::__iter_move(__start));
do do {
{
// we are not in heap-order, swap the parent with its largest child // we are not in heap-order, swap the parent with its largest child
*__start = _Ops::__iter_move(__child_i); *__start = _Ops::__iter_move(__child_i);
__start = __child_i; __start = __child_i;
@ -81,10 +80,10 @@ __sift_down(_RandomAccessIterator __first, _Compare&& __comp,
} }
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator> template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _RandomAccessIterator _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _RandomAccessIterator __floyd_sift_down(
__floyd_sift_down(_RandomAccessIterator __first, _Compare&& __comp, _RandomAccessIterator __first,
typename iterator_traits<_RandomAccessIterator>::difference_type __len) _Compare&& __comp,
{ typename iterator_traits<_RandomAccessIterator>::difference_type __len) {
using difference_type = typename iterator_traits<_RandomAccessIterator>::difference_type; using difference_type = typename iterator_traits<_RandomAccessIterator>::difference_type;
_LIBCPP_ASSERT_UNCATEGORIZED(__len >= 2, "shouldn't be called unless __len >= 2"); _LIBCPP_ASSERT_UNCATEGORIZED(__len >= 2, "shouldn't be called unless __len >= 2");

View File

@ -44,9 +44,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD
// stable, 2-3 compares, 0-2 swaps // stable, 2-3 compares, 0-2 swaps
template <class _AlgPolicy, class _Compare, class _ForwardIterator> template <class _AlgPolicy, class _Compare, class _ForwardIterator>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 unsigned
_LIBCPP_CONSTEXPR_SINCE_CXX14 unsigned __sort3(_ForwardIterator __x, _ForwardIterator __y, _ForwardIterator __z, __sort3(_ForwardIterator __x, _ForwardIterator __y, _ForwardIterator __z, _Compare __c) {
_Compare __c) {
using _Ops = _IterOps<_AlgPolicy>; using _Ops = _IterOps<_AlgPolicy>;
unsigned __r = 0; unsigned __r = 0;
@ -83,9 +82,8 @@ _LIBCPP_CONSTEXPR_SINCE_CXX14 unsigned __sort3(_ForwardIterator __x, _ForwardIte
// stable, 3-6 compares, 0-5 swaps // stable, 3-6 compares, 0-5 swaps
template <class _AlgPolicy, class _Compare, class _ForwardIterator> template <class _AlgPolicy, class _Compare, class _ForwardIterator>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI void
void __sort4(_ForwardIterator __x1, _ForwardIterator __x2, _ForwardIterator __x3, _ForwardIterator __x4, __sort4(_ForwardIterator __x1, _ForwardIterator __x2, _ForwardIterator __x3, _ForwardIterator __x4, _Compare __c) {
_Compare __c) {
using _Ops = _IterOps<_AlgPolicy>; using _Ops = _IterOps<_AlgPolicy>;
std::__sort3<_AlgPolicy, _Compare>(__x1, __x2, __x3, __c); std::__sort3<_AlgPolicy, _Compare>(__x1, __x2, __x3, __c);
if (__c(*__x4, *__x3)) { if (__c(*__x4, *__x3)) {
@ -102,8 +100,13 @@ void __sort4(_ForwardIterator __x1, _ForwardIterator __x2, _ForwardIterator __x3
// stable, 4-10 compares, 0-9 swaps // stable, 4-10 compares, 0-9 swaps
template <class _AlgPolicy, class _Comp, class _ForwardIterator> template <class _AlgPolicy, class _Comp, class _ForwardIterator>
_LIBCPP_HIDE_FROM_ABI void __sort5(_ForwardIterator __x1, _ForwardIterator __x2, _ForwardIterator __x3, _LIBCPP_HIDE_FROM_ABI void
_ForwardIterator __x4, _ForwardIterator __x5, _Comp __comp) { __sort5(_ForwardIterator __x1,
_ForwardIterator __x2,
_ForwardIterator __x3,
_ForwardIterator __x4,
_ForwardIterator __x5,
_Comp __comp) {
using _Ops = _IterOps<_AlgPolicy>; using _Ops = _IterOps<_AlgPolicy>;
std::__sort4<_AlgPolicy, _Comp>(__x1, __x2, __x3, __x4, __comp); std::__sort4<_AlgPolicy, _Comp>(__x1, __x2, __x3, __x4, __comp);
@ -139,7 +142,8 @@ struct __is_simple_comparator<ranges::greater&> : true_type {};
template <class _Compare, class _Iter, class _Tp = typename iterator_traits<_Iter>::value_type> template <class _Compare, class _Iter, class _Tp = typename iterator_traits<_Iter>::value_type>
using __use_branchless_sort = using __use_branchless_sort =
integral_constant<bool, __libcpp_is_contiguous_iterator<_Iter>::value && sizeof(_Tp) <= sizeof(void*) && integral_constant<bool,
__libcpp_is_contiguous_iterator<_Iter>::value && sizeof(_Tp) <= sizeof(void*) &&
is_arithmetic<_Tp>::value && __is_simple_comparator<_Compare>::value>; is_arithmetic<_Tp>::value && __is_simple_comparator<_Compare>::value>;
namespace __detail { namespace __detail {
@ -163,8 +167,8 @@ inline _LIBCPP_HIDE_FROM_ABI void __cond_swap(_RandomAccessIterator __x, _Random
// Ensures that *__x, *__y and *__z are ordered according to the comparator __c, // Ensures that *__x, *__y and *__z are ordered according to the comparator __c,
// under the assumption that *__y and *__z are already ordered. // under the assumption that *__y and *__z are already ordered.
template <class _Compare, class _RandomAccessIterator> template <class _Compare, class _RandomAccessIterator>
inline _LIBCPP_HIDE_FROM_ABI void __partially_sorted_swap(_RandomAccessIterator __x, _RandomAccessIterator __y, inline _LIBCPP_HIDE_FROM_ABI void
_RandomAccessIterator __z, _Compare __c) { __partially_sorted_swap(_RandomAccessIterator __x, _RandomAccessIterator __y, _RandomAccessIterator __z, _Compare __c) {
// Note: this function behaves correctly even with proxy iterators (because it relies on `value_type`). // Note: this function behaves correctly even with proxy iterators (because it relies on `value_type`).
using value_type = typename iterator_traits<_RandomAccessIterator>::value_type; using value_type = typename iterator_traits<_RandomAccessIterator>::value_type;
bool __r = __c(*__z, *__x); bool __r = __c(*__z, *__x);
@ -175,28 +179,35 @@ inline _LIBCPP_HIDE_FROM_ABI void __partially_sorted_swap(_RandomAccessIterator
*__y = __r ? *__y : __tmp; *__y = __r ? *__y : __tmp;
} }
template <class, class _Compare, class _RandomAccessIterator, template <class,
class _Compare,
class _RandomAccessIterator,
__enable_if_t<__use_branchless_sort<_Compare, _RandomAccessIterator>::value, int> = 0> __enable_if_t<__use_branchless_sort<_Compare, _RandomAccessIterator>::value, int> = 0>
inline _LIBCPP_HIDE_FROM_ABI void inline _LIBCPP_HIDE_FROM_ABI void __sort3_maybe_branchless(
__sort3_maybe_branchless(_RandomAccessIterator __x1, _RandomAccessIterator __x2, _RandomAccessIterator __x3, _RandomAccessIterator __x1, _RandomAccessIterator __x2, _RandomAccessIterator __x3, _Compare __c) {
_Compare __c) {
std::__cond_swap<_Compare>(__x2, __x3, __c); std::__cond_swap<_Compare>(__x2, __x3, __c);
std::__partially_sorted_swap<_Compare>(__x1, __x2, __x3, __c); std::__partially_sorted_swap<_Compare>(__x1, __x2, __x3, __c);
} }
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator, template <class _AlgPolicy,
class _Compare,
class _RandomAccessIterator,
__enable_if_t<!__use_branchless_sort<_Compare, _RandomAccessIterator>::value, int> = 0> __enable_if_t<!__use_branchless_sort<_Compare, _RandomAccessIterator>::value, int> = 0>
inline _LIBCPP_HIDE_FROM_ABI void inline _LIBCPP_HIDE_FROM_ABI void __sort3_maybe_branchless(
__sort3_maybe_branchless(_RandomAccessIterator __x1, _RandomAccessIterator __x2, _RandomAccessIterator __x3, _RandomAccessIterator __x1, _RandomAccessIterator __x2, _RandomAccessIterator __x3, _Compare __c) {
_Compare __c) {
std::__sort3<_AlgPolicy, _Compare>(__x1, __x2, __x3, __c); std::__sort3<_AlgPolicy, _Compare>(__x1, __x2, __x3, __c);
} }
template <class, class _Compare, class _RandomAccessIterator, template <class,
class _Compare,
class _RandomAccessIterator,
__enable_if_t<__use_branchless_sort<_Compare, _RandomAccessIterator>::value, int> = 0> __enable_if_t<__use_branchless_sort<_Compare, _RandomAccessIterator>::value, int> = 0>
inline _LIBCPP_HIDE_FROM_ABI void inline _LIBCPP_HIDE_FROM_ABI void __sort4_maybe_branchless(
__sort4_maybe_branchless(_RandomAccessIterator __x1, _RandomAccessIterator __x2, _RandomAccessIterator __x3, _RandomAccessIterator __x1,
_RandomAccessIterator __x4, _Compare __c) { _RandomAccessIterator __x2,
_RandomAccessIterator __x3,
_RandomAccessIterator __x4,
_Compare __c) {
std::__cond_swap<_Compare>(__x1, __x3, __c); std::__cond_swap<_Compare>(__x1, __x3, __c);
std::__cond_swap<_Compare>(__x2, __x4, __c); std::__cond_swap<_Compare>(__x2, __x4, __c);
std::__cond_swap<_Compare>(__x1, __x2, __c); std::__cond_swap<_Compare>(__x1, __x2, __c);
@ -204,18 +215,24 @@ __sort4_maybe_branchless(_RandomAccessIterator __x1, _RandomAccessIterator __x2,
std::__cond_swap<_Compare>(__x2, __x3, __c); std::__cond_swap<_Compare>(__x2, __x3, __c);
} }
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator, template <class _AlgPolicy,
class _Compare,
class _RandomAccessIterator,
__enable_if_t<!__use_branchless_sort<_Compare, _RandomAccessIterator>::value, int> = 0> __enable_if_t<!__use_branchless_sort<_Compare, _RandomAccessIterator>::value, int> = 0>
inline _LIBCPP_HIDE_FROM_ABI void inline _LIBCPP_HIDE_FROM_ABI void __sort4_maybe_branchless(
__sort4_maybe_branchless(_RandomAccessIterator __x1, _RandomAccessIterator __x2, _RandomAccessIterator __x3, _RandomAccessIterator __x1,
_RandomAccessIterator __x4, _Compare __c) { _RandomAccessIterator __x2,
_RandomAccessIterator __x3,
_RandomAccessIterator __x4,
_Compare __c) {
std::__sort4<_AlgPolicy, _Compare>(__x1, __x2, __x3, __x4, __c); std::__sort4<_AlgPolicy, _Compare>(__x1, __x2, __x3, __x4, __c);
} }
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator, template <class _AlgPolicy,
class _Compare,
class _RandomAccessIterator,
__enable_if_t<__use_branchless_sort<_Compare, _RandomAccessIterator>::value, int> = 0> __enable_if_t<__use_branchless_sort<_Compare, _RandomAccessIterator>::value, int> = 0>
inline _LIBCPP_HIDE_FROM_ABI void inline _LIBCPP_HIDE_FROM_ABI void __sort5_maybe_branchless(
__sort5_maybe_branchless(
_RandomAccessIterator __x1, _RandomAccessIterator __x1,
_RandomAccessIterator __x2, _RandomAccessIterator __x2,
_RandomAccessIterator __x3, _RandomAccessIterator __x3,
@ -230,20 +247,25 @@ __sort5_maybe_branchless(
std::__partially_sorted_swap<_Compare>(__x2, __x3, __x4, __c); std::__partially_sorted_swap<_Compare>(__x2, __x3, __x4, __c);
} }
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator, template <class _AlgPolicy,
class _Compare,
class _RandomAccessIterator,
__enable_if_t<!__use_branchless_sort<_Compare, _RandomAccessIterator>::value, int> = 0> __enable_if_t<!__use_branchless_sort<_Compare, _RandomAccessIterator>::value, int> = 0>
inline _LIBCPP_HIDE_FROM_ABI void inline _LIBCPP_HIDE_FROM_ABI void __sort5_maybe_branchless(
__sort5_maybe_branchless(_RandomAccessIterator __x1, _RandomAccessIterator __x2, _RandomAccessIterator __x3, _RandomAccessIterator __x1,
_RandomAccessIterator __x4, _RandomAccessIterator __x5, _Compare __c) { _RandomAccessIterator __x2,
_RandomAccessIterator __x3,
_RandomAccessIterator __x4,
_RandomAccessIterator __x5,
_Compare __c) {
std::__sort5<_AlgPolicy, _Compare, _RandomAccessIterator>( std::__sort5<_AlgPolicy, _Compare, _RandomAccessIterator>(
std::move(__x1), std::move(__x2), std::move(__x3), std::move(__x4), std::move(__x5), __c); std::move(__x1), std::move(__x2), std::move(__x3), std::move(__x4), std::move(__x5), __c);
} }
// Assumes size > 0 // Assumes size > 0
template <class _AlgPolicy, class _Compare, class _BidirectionalIterator> template <class _AlgPolicy, class _Compare, class _BidirectionalIterator>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
_LIBCPP_CONSTEXPR_SINCE_CXX14 void __selection_sort(_BidirectionalIterator __first, _BidirectionalIterator __last, __selection_sort(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) {
_Compare __comp) {
_BidirectionalIterator __lm1 = __last; _BidirectionalIterator __lm1 = __last;
for (--__lm1; __first != __lm1; ++__first) { for (--__lm1; __first != __lm1; ++__first) {
_BidirectionalIterator __i = std::__min_element<_Compare>(__first, __last, __comp); _BidirectionalIterator __i = std::__min_element<_Compare>(__first, __last, __comp);
@ -255,8 +277,8 @@ _LIBCPP_CONSTEXPR_SINCE_CXX14 void __selection_sort(_BidirectionalIterator __fir
// Sort the iterator range [__first, __last) using the comparator __comp using // Sort the iterator range [__first, __last) using the comparator __comp using
// the insertion sort algorithm. // the insertion sort algorithm.
template <class _AlgPolicy, class _Compare, class _BidirectionalIterator> template <class _AlgPolicy, class _Compare, class _BidirectionalIterator>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI void
void __insertion_sort(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) { __insertion_sort(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) {
using _Ops = _IterOps<_AlgPolicy>; using _Ops = _IterOps<_AlgPolicy>;
typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
@ -292,7 +314,8 @@ __insertion_sort_unguarded(_RandomAccessIterator const __first, _RandomAccessIte
typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
if (__first == __last) if (__first == __last)
return; return;
const _RandomAccessIterator __leftmost = __first - difference_type(1); (void)__leftmost; // can be unused when assertions are disabled const _RandomAccessIterator __leftmost = __first - difference_type(1);
(void)__leftmost; // can be unused when assertions are disabled
for (_RandomAccessIterator __i = __first + difference_type(1); __i != __last; ++__i) { for (_RandomAccessIterator __i = __first + difference_type(1); __i != __last; ++__i) {
_RandomAccessIterator __j = __i - difference_type(1); _RandomAccessIterator __j = __i - difference_type(1);
if (__comp(*__i, *__j)) { if (__comp(*__i, *__j)) {
@ -312,8 +335,8 @@ __insertion_sort_unguarded(_RandomAccessIterator const __first, _RandomAccessIte
} }
template <class _AlgPolicy, class _Comp, class _RandomAccessIterator> template <class _AlgPolicy, class _Comp, class _RandomAccessIterator>
_LIBCPP_HIDE_FROM_ABI bool __insertion_sort_incomplete( _LIBCPP_HIDE_FROM_ABI bool
_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp __comp) { __insertion_sort_incomplete(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp __comp) {
using _Ops = _IterOps<_AlgPolicy>; using _Ops = _IterOps<_AlgPolicy>;
typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
@ -334,8 +357,12 @@ _LIBCPP_HIDE_FROM_ABI bool __insertion_sort_incomplete(
return true; return true;
case 5: case 5:
std::__sort5_maybe_branchless<_AlgPolicy, _Comp>( std::__sort5_maybe_branchless<_AlgPolicy, _Comp>(
__first, __first + difference_type(1), __first + difference_type(2), __first + difference_type(3), __first,
--__last, __comp); __first + difference_type(1),
__first + difference_type(2),
__first + difference_type(3),
--__last,
__comp);
return true; return true;
} }
typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
@ -508,7 +535,8 @@ __bitset_partition(_RandomAccessIterator __first, _RandomAccessIterator __last,
typedef typename std::iterator_traits<_RandomAccessIterator>::difference_type difference_type; typedef typename std::iterator_traits<_RandomAccessIterator>::difference_type difference_type;
_LIBCPP_ASSERT_UNCATEGORIZED(__last - __first >= difference_type(3), ""); _LIBCPP_ASSERT_UNCATEGORIZED(__last - __first >= difference_type(3), "");
const _RandomAccessIterator __begin = __first; // used for bounds checking, those are not moved around const _RandomAccessIterator __begin = __first; // used for bounds checking, those are not moved around
const _RandomAccessIterator __end = __last; (void)__end; // const _RandomAccessIterator __end = __last;
(void)__end; //
value_type __pivot(_Ops::__iter_move(__first)); value_type __pivot(_Ops::__iter_move(__first));
// Find the first element greater than the pivot. // Find the first element greater than the pivot.
@ -599,7 +627,8 @@ __partition_with_equals_on_right(_RandomAccessIterator __first, _RandomAccessIte
typedef typename std::iterator_traits<_RandomAccessIterator>::value_type value_type; typedef typename std::iterator_traits<_RandomAccessIterator>::value_type value_type;
_LIBCPP_ASSERT_UNCATEGORIZED(__last - __first >= difference_type(3), ""); _LIBCPP_ASSERT_UNCATEGORIZED(__last - __first >= difference_type(3), "");
const _RandomAccessIterator __begin = __first; // used for bounds checking, those are not moved around const _RandomAccessIterator __begin = __first; // used for bounds checking, those are not moved around
const _RandomAccessIterator __end = __last; (void)__end; // const _RandomAccessIterator __end = __last;
(void)__end; //
value_type __pivot(_Ops::__iter_move(__first)); value_type __pivot(_Ops::__iter_move(__first));
// Find the first element greater or equal to the pivot. It will be always // Find the first element greater or equal to the pivot. It will be always
// guarded because __introsort will do the median-of-three before calling // guarded because __introsort will do the median-of-three before calling
@ -666,7 +695,8 @@ __partition_with_equals_on_left(_RandomAccessIterator __first, _RandomAccessIter
typedef typename std::iterator_traits<_RandomAccessIterator>::value_type value_type; typedef typename std::iterator_traits<_RandomAccessIterator>::value_type value_type;
// TODO(LLVM18): Make __begin const, see https://reviews.llvm.org/D147089#4349748 // TODO(LLVM18): Make __begin const, see https://reviews.llvm.org/D147089#4349748
_RandomAccessIterator __begin = __first; // used for bounds checking, those are not moved around _RandomAccessIterator __begin = __first; // used for bounds checking, those are not moved around
const _RandomAccessIterator __end = __last; (void)__end; // const _RandomAccessIterator __end = __last;
(void)__end; //
value_type __pivot(_Ops::__iter_move(__first)); value_type __pivot(_Ops::__iter_move(__first));
if (__comp(__pivot, *(__last - difference_type(1)))) { if (__comp(__pivot, *(__last - difference_type(1)))) {
// Guarded. // Guarded.
@ -753,8 +783,12 @@ void __introsort(_RandomAccessIterator __first,
return; return;
case 5: case 5:
std::__sort5_maybe_branchless<_AlgPolicy, _Compare>( std::__sort5_maybe_branchless<_AlgPolicy, _Compare>(
__first, __first + difference_type(1), __first + difference_type(2), __first + difference_type(3), __first,
--__last, __comp); __first + difference_type(1),
__first + difference_type(2),
__first + difference_type(3),
--__last,
__comp);
return; return;
} }
// Use insertion sort if the length of the range is below the specified limit. // Use insertion sort if the length of the range is below the specified limit.
@ -803,10 +837,10 @@ void __introsort(_RandomAccessIterator __first,
continue; continue;
} }
// Use bitset partition only if asked for. // Use bitset partition only if asked for.
auto __ret = auto __ret = _UseBitSetPartition
_UseBitSetPartition
? std::__bitset_partition<_AlgPolicy, _RandomAccessIterator, _Compare>(__first, __last, __comp) ? std::__bitset_partition<_AlgPolicy, _RandomAccessIterator, _Compare>(__first, __last, __comp)
: std::__partition_with_equals_on_right<_AlgPolicy, _RandomAccessIterator, _Compare>(__first, __last, __comp); : std::__partition_with_equals_on_right<_AlgPolicy, _RandomAccessIterator, _Compare>(
__first, __last, __comp);
_RandomAccessIterator __i = __ret.first; _RandomAccessIterator __i = __ret.first;
// [__first, __i) < *__i and *__i <= [__i+1, __last) // [__first, __i) < *__i and *__i <= [__i+1, __last)
// If we were given a perfect partition, see if insertion sort is quick... // If we were given a perfect partition, see if insertion sort is quick...
@ -858,19 +892,27 @@ extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less<char>&, char*>(char
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&); extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&);
#endif #endif
extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&); extern template _LIBCPP_EXPORTED_FROM_ABI void
extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less<unsigned char>&, unsigned char*>(unsigned char*, unsigned char*, __less<unsigned char>&); __sort<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&);
extern template _LIBCPP_EXPORTED_FROM_ABI void
__sort<__less<unsigned char>&, unsigned char*>(unsigned char*, unsigned char*, __less<unsigned char>&);
extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less<short>&, short*>(short*, short*, __less<short>&); extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less<short>&, short*>(short*, short*, __less<short>&);
extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less<unsigned short>&, unsigned short*>(unsigned short*, unsigned short*, __less<unsigned short>&); extern template _LIBCPP_EXPORTED_FROM_ABI void
__sort<__less<unsigned short>&, unsigned short*>(unsigned short*, unsigned short*, __less<unsigned short>&);
extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less<int>&, int*>(int*, int*, __less<int>&); extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less<int>&, int*>(int*, int*, __less<int>&);
extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less<unsigned>&, unsigned*>(unsigned*, unsigned*, __less<unsigned>&); extern template _LIBCPP_EXPORTED_FROM_ABI void
__sort<__less<unsigned>&, unsigned*>(unsigned*, unsigned*, __less<unsigned>&);
extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less<long>&, long*>(long*, long*, __less<long>&); extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less<long>&, long*>(long*, long*, __less<long>&);
extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less<unsigned long>&, unsigned long*>(unsigned long*, unsigned long*, __less<unsigned long>&); extern template _LIBCPP_EXPORTED_FROM_ABI void
extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less<long long>&, long long*>(long long*, long long*, __less<long long>&); __sort<__less<unsigned long>&, unsigned long*>(unsigned long*, unsigned long*, __less<unsigned long>&);
extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less<unsigned long long>&, unsigned long long*>(unsigned long long*, unsigned long long*, __less<unsigned long long>&); extern template _LIBCPP_EXPORTED_FROM_ABI void
__sort<__less<long long>&, long long*>(long long*, long long*, __less<long long>&);
extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less<unsigned long long>&, unsigned long long*>(
unsigned long long*, unsigned long long*, __less<unsigned long long>&);
extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less<float>&, float*>(float*, float*, __less<float>&); extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less<float>&, float*>(float*, float*, __less<float>&);
extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less<double>&, double*>(double*, double*, __less<double>&); extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less<double>&, double*>(double*, double*, __less<double>&);
extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less<long double>&, long double*>(long double*, long double*, __less<long double>&); extern template _LIBCPP_EXPORTED_FROM_ABI void
__sort<__less<long double>&, long double*>(long double*, long double*, __less<long double>&);
template <class _AlgPolicy, class _RandomAccessIterator, class _Comp> template <class _AlgPolicy, class _RandomAccessIterator, class _Comp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
@ -884,8 +926,7 @@ __sort_dispatch(_RandomAccessIterator __first, _RandomAccessIterator __last, _Co
std::__introsort<_AlgPolicy, std::__introsort<_AlgPolicy,
_Comp&, _Comp&,
_RandomAccessIterator, _RandomAccessIterator,
__use_branchless_sort<_Comp, _RandomAccessIterator>::value>( __use_branchless_sort<_Comp, _RandomAccessIterator>::value>(__first, __last, __comp, __depth_limit);
__first, __last, __comp, __depth_limit);
} }
template <class _Type, class... _Options> template <class _Type, class... _Options>
@ -941,8 +982,8 @@ _LIBCPP_HIDE_FROM_ABI void __sort_dispatch(_Type* __first, _Type* __last, ranges
#endif #endif
template <class _AlgPolicy, class _RandomAccessIterator, class _Comp> template <class _AlgPolicy, class _RandomAccessIterator, class _Comp>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
void __sort_impl(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp& __comp) { __sort_impl(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp& __comp) {
std::__debug_randomize_range<_AlgPolicy>(__first, __last); std::__debug_randomize_range<_AlgPolicy>(__first, __last);
if (__libcpp_is_constant_evaluated()) { if (__libcpp_is_constant_evaluated()) {
@ -955,14 +996,14 @@ void __sort_impl(_RandomAccessIterator __first, _RandomAccessIterator __last, _C
} }
template <class _RandomAccessIterator, class _Comp> template <class _RandomAccessIterator, class _Comp>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
void sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp __comp) { sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp __comp) {
std::__sort_impl<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __comp); std::__sort_impl<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __comp);
} }
template <class _RandomAccessIterator> template <class _RandomAccessIterator>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
void sort(_RandomAccessIterator __first, _RandomAccessIterator __last) { sort(_RandomAccessIterator __first, _RandomAccessIterator __last) {
std::sort(__first, __last, __less<>()); std::sort(__first, __last, __less<>());
} }

View File

@ -27,20 +27,20 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator> template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
void __sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare&& __comp) { __sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare&& __comp) {
_RandomAccessIterator __saved_last = __last; _RandomAccessIterator __saved_last = __last;
__comp_ref_type<_Compare> __comp_ref = __comp; __comp_ref_type<_Compare> __comp_ref = __comp;
using difference_type = typename iterator_traits<_RandomAccessIterator>::difference_type; using difference_type = typename iterator_traits<_RandomAccessIterator>::difference_type;
for (difference_type __n = __last - __first; __n > 1; --__last, (void) --__n) for (difference_type __n = __last - __first; __n > 1; --__last, (void)--__n)
std::__pop_heap<_AlgPolicy>(__first, __last, __comp_ref, __n); std::__pop_heap<_AlgPolicy>(__first, __last, __comp_ref, __n);
std::__check_strict_weak_ordering_sorted(__first, __saved_last, __comp_ref); std::__check_strict_weak_ordering_sorted(__first, __saved_last, __comp_ref);
} }
template <class _RandomAccessIterator, class _Compare> template <class _RandomAccessIterator, class _Compare>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
void sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { sort_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_constructible<_RandomAccessIterator>::value, "Iterators must be copy constructible.");
static_assert(std::is_copy_assignable<_RandomAccessIterator>::value, "Iterators must be copy assignable."); static_assert(std::is_copy_assignable<_RandomAccessIterator>::value, "Iterators must be copy assignable.");
@ -48,8 +48,8 @@ void sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Com
} }
template <class _RandomAccessIterator> template <class _RandomAccessIterator>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
void sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) { sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) {
std::sort_heap(std::move(__first), std::move(__last), __less<>()); std::sort_heap(std::move(__first), std::move(__last), __less<>());
} }

View File

@ -29,28 +29,28 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template <class _AlgPolicy, class _Predicate, class _ForwardIterator, class _Distance, class _Pair> template <class _AlgPolicy, class _Predicate, class _ForwardIterator, class _Distance, class _Pair>
_LIBCPP_HIDE_FROM_ABI _ForwardIterator _LIBCPP_HIDE_FROM_ABI _ForwardIterator __stable_partition_impl(
__stable_partition_impl(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, _ForwardIterator __first,
_Distance __len, _Pair __p, forward_iterator_tag __fit) _ForwardIterator __last,
{ _Predicate __pred,
_Distance __len,
_Pair __p,
forward_iterator_tag __fit) {
using _Ops = _IterOps<_AlgPolicy>; using _Ops = _IterOps<_AlgPolicy>;
// *__first is known to be false // *__first is known to be false
// __len >= 1 // __len >= 1
if (__len == 1) if (__len == 1)
return __first; return __first;
if (__len == 2) if (__len == 2) {
{
_ForwardIterator __m = __first; _ForwardIterator __m = __first;
if (__pred(*++__m)) if (__pred(*++__m)) {
{
_Ops::iter_swap(__first, __m); _Ops::iter_swap(__first, __m);
return __m; return __m;
} }
return __first; return __first;
} }
if (__len <= __p.second) if (__len <= __p.second) { // The buffer is big enough to use
{ // The buffer is big enough to use
typedef typename iterator_traits<_ForwardIterator>::value_type value_type; typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
__destruct_n __d(0); __destruct_n __d(0);
unique_ptr<value_type, __destruct_n&> __h(__p.first, __d); unique_ptr<value_type, __destruct_n&> __h(__p.first, __d);
@ -61,15 +61,11 @@ __stable_partition_impl(_ForwardIterator __first, _ForwardIterator __last, _Pred
__d.template __incr<value_type>(); __d.template __incr<value_type>();
++__t; ++__t;
_ForwardIterator __i = __first; _ForwardIterator __i = __first;
while (++__i != __last) while (++__i != __last) {
{ if (__pred(*__i)) {
if (__pred(*__i))
{
*__first = _Ops::__iter_move(__i); *__first = _Ops::__iter_move(__i);
++__first; ++__first;
} } else {
else
{
::new ((void*)__t) value_type(_Ops::__iter_move(__i)); ::new ((void*)__t) value_type(_Ops::__iter_move(__i));
__d.template __incr<value_type>(); __d.template __incr<value_type>();
++__t; ++__t;
@ -78,7 +74,7 @@ __stable_partition_impl(_ForwardIterator __first, _ForwardIterator __last, _Pred
// All trues now at start of range, all falses in buffer // All trues now at start of range, all falses in buffer
// Move falses back into range, but don't mess up __first which points to first false // Move falses back into range, but don't mess up __first which points to first false
__i = __first; __i = __first;
for (value_type* __t2 = __p.first; __t2 < __t; ++__t2, (void) ++__i) for (value_type* __t2 = __p.first; __t2 < __t; ++__t2, (void)++__i)
*__i = _Ops::__iter_move(__t2); *__i = _Ops::__iter_move(__t2);
// __h destructs moved-from values out of the temp buffer, but doesn't deallocate buffer // __h destructs moved-from values out of the temp buffer, but doesn't deallocate buffer
return __first; return __first;
@ -91,24 +87,22 @@ __stable_partition_impl(_ForwardIterator __first, _ForwardIterator __last, _Pred
// recurse on [__first, __m), *__first know to be false // recurse on [__first, __m), *__first know to be false
// F????????????????? // F?????????????????
// f m l // f m l
_ForwardIterator __first_false = std::__stable_partition_impl<_AlgPolicy, _Predicate&>( _ForwardIterator __first_false =
__first, __m, __pred, __len2, __p, __fit); std::__stable_partition_impl<_AlgPolicy, _Predicate&>(__first, __m, __pred, __len2, __p, __fit);
// TTTFFFFF?????????? // TTTFFFFF??????????
// f ff m l // f ff m l
// recurse on [__m, __last], except increase __m until *(__m) is false, *__last know to be true // recurse on [__m, __last], except increase __m until *(__m) is false, *__last know to be true
_ForwardIterator __m1 = __m; _ForwardIterator __m1 = __m;
_ForwardIterator __second_false = __last; _ForwardIterator __second_false = __last;
_Distance __len_half = __len - __len2; _Distance __len_half = __len - __len2;
while (__pred(*__m1)) while (__pred(*__m1)) {
{
if (++__m1 == __last) if (++__m1 == __last)
goto __second_half_done; goto __second_half_done;
--__len_half; --__len_half;
} }
// TTTFFFFFTTTF?????? // TTTFFFFFTTTF??????
// f ff m m1 l // f ff m m1 l
__second_false = std::__stable_partition_impl<_AlgPolicy, _Predicate&>( __second_false = std::__stable_partition_impl<_AlgPolicy, _Predicate&>(__m1, __last, __pred, __len_half, __p, __fit);
__m1, __last, __pred, __len_half, __p, __fit);
__second_half_done: __second_half_done:
// TTTFFFFFTTTTTFFFFF // TTTFFFFFTTTTTFFFFF
// f ff m sf l // f ff m sf l
@ -119,16 +113,13 @@ __second_half_done:
template <class _AlgPolicy, class _Predicate, class _ForwardIterator> template <class _AlgPolicy, class _Predicate, class _ForwardIterator>
_LIBCPP_HIDE_FROM_ABI _ForwardIterator _LIBCPP_HIDE_FROM_ABI _ForwardIterator
__stable_partition_impl(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, __stable_partition_impl(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, forward_iterator_tag) {
forward_iterator_tag)
{
typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type; typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type;
typedef typename iterator_traits<_ForwardIterator>::value_type value_type; typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
const difference_type __alloc_limit = 3; // might want to make this a function of trivial assignment const difference_type __alloc_limit = 3; // might want to make this a function of trivial assignment
// Either prove all true and return __first or point to first false // Either prove all true and return __first or point to first false
while (true) while (true) {
{
if (__first == __last) if (__first == __last)
return __first; return __first;
if (!__pred(*__first)) if (!__pred(*__first))
@ -140,12 +131,11 @@ __stable_partition_impl(_ForwardIterator __first, _ForwardIterator __last, _Pred
difference_type __len = _IterOps<_AlgPolicy>::distance(__first, __last); difference_type __len = _IterOps<_AlgPolicy>::distance(__first, __last);
pair<value_type*, ptrdiff_t> __p(0, 0); pair<value_type*, ptrdiff_t> __p(0, 0);
unique_ptr<value_type, __return_temporary_buffer> __h; unique_ptr<value_type, __return_temporary_buffer> __h;
if (__len >= __alloc_limit) if (__len >= __alloc_limit) {
{ // TODO: Remove the use of std::get_temporary_buffer
// TODO: Remove the use of std::get_temporary_buffer _LIBCPP_SUPPRESS_DEPRECATED_PUSH
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
__p = std::get_temporary_buffer<value_type>(__len); __p = std::get_temporary_buffer<value_type>(__len);
_LIBCPP_SUPPRESS_DEPRECATED_POP _LIBCPP_SUPPRESS_DEPRECATED_POP
__h.reset(__p.first); __h.reset(__p.first);
} }
return std::__stable_partition_impl<_AlgPolicy, _Predicate&>( return std::__stable_partition_impl<_AlgPolicy, _Predicate&>(
@ -153,25 +143,25 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
} }
template <class _AlgPolicy, class _Predicate, class _BidirectionalIterator, class _Distance, class _Pair> template <class _AlgPolicy, class _Predicate, class _BidirectionalIterator, class _Distance, class _Pair>
_BidirectionalIterator _BidirectionalIterator __stable_partition_impl(
__stable_partition_impl(_BidirectionalIterator __first, _BidirectionalIterator __last, _Predicate __pred, _BidirectionalIterator __first,
_Distance __len, _Pair __p, bidirectional_iterator_tag __bit) _BidirectionalIterator __last,
{ _Predicate __pred,
_Distance __len,
_Pair __p,
bidirectional_iterator_tag __bit) {
using _Ops = _IterOps<_AlgPolicy>; using _Ops = _IterOps<_AlgPolicy>;
// *__first is known to be false // *__first is known to be false
// *__last is known to be true // *__last is known to be true
// __len >= 2 // __len >= 2
if (__len == 2) if (__len == 2) {
{
_Ops::iter_swap(__first, __last); _Ops::iter_swap(__first, __last);
return __last; return __last;
} }
if (__len == 3) if (__len == 3) {
{
_BidirectionalIterator __m = __first; _BidirectionalIterator __m = __first;
if (__pred(*++__m)) if (__pred(*++__m)) {
{
_Ops::iter_swap(__first, __m); _Ops::iter_swap(__first, __m);
_Ops::iter_swap(__m, __last); _Ops::iter_swap(__m, __last);
return __last; return __last;
@ -180,8 +170,7 @@ __stable_partition_impl(_BidirectionalIterator __first, _BidirectionalIterator _
_Ops::iter_swap(__first, __m); _Ops::iter_swap(__first, __m);
return __m; return __m;
} }
if (__len <= __p.second) if (__len <= __p.second) { // The buffer is big enough to use
{ // The buffer is big enough to use
typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
__destruct_n __d(0); __destruct_n __d(0);
unique_ptr<value_type, __destruct_n&> __h(__p.first, __d); unique_ptr<value_type, __destruct_n&> __h(__p.first, __d);
@ -192,15 +181,11 @@ __stable_partition_impl(_BidirectionalIterator __first, _BidirectionalIterator _
__d.template __incr<value_type>(); __d.template __incr<value_type>();
++__t; ++__t;
_BidirectionalIterator __i = __first; _BidirectionalIterator __i = __first;
while (++__i != __last) while (++__i != __last) {
{ if (__pred(*__i)) {
if (__pred(*__i))
{
*__first = _Ops::__iter_move(__i); *__first = _Ops::__iter_move(__i);
++__first; ++__first;
} } else {
else
{
::new ((void*)__t) value_type(_Ops::__iter_move(__i)); ::new ((void*)__t) value_type(_Ops::__iter_move(__i));
__d.template __incr<value_type>(); __d.template __incr<value_type>();
++__t; ++__t;
@ -211,7 +196,7 @@ __stable_partition_impl(_BidirectionalIterator __first, _BidirectionalIterator _
__i = ++__first; __i = ++__first;
// All trues now at start of range, all falses in buffer // All trues now at start of range, all falses in buffer
// Move falses back into range, but don't mess up __first which points to first false // Move falses back into range, but don't mess up __first which points to first false
for (value_type* __t2 = __p.first; __t2 < __t; ++__t2, (void) ++__i) for (value_type* __t2 = __p.first; __t2 < __t; ++__t2, (void)++__i)
*__i = _Ops::__iter_move(__t2); *__i = _Ops::__iter_move(__t2);
// __h destructs moved-from values out of the temp buffer, but doesn't deallocate buffer // __h destructs moved-from values out of the temp buffer, but doesn't deallocate buffer
return __first; return __first;
@ -227,16 +212,14 @@ __stable_partition_impl(_BidirectionalIterator __first, _BidirectionalIterator _
_BidirectionalIterator __m1 = __m; _BidirectionalIterator __m1 = __m;
_BidirectionalIterator __first_false = __first; _BidirectionalIterator __first_false = __first;
_Distance __len_half = __len2; _Distance __len_half = __len2;
while (!__pred(*--__m1)) while (!__pred(*--__m1)) {
{
if (__m1 == __first) if (__m1 == __first)
goto __first_half_done; goto __first_half_done;
--__len_half; --__len_half;
} }
// F???TFFF?????????T // F???TFFF?????????T
// f m1 m l // f m1 m l
__first_false = std::__stable_partition_impl<_AlgPolicy, _Predicate&>( __first_false = std::__stable_partition_impl<_AlgPolicy, _Predicate&>(__first, __m1, __pred, __len_half, __p, __bit);
__first, __m1, __pred, __len_half, __p, __bit);
__first_half_done: __first_half_done:
// TTTFFFFF?????????T // TTTFFFFF?????????T
// f ff m l // f ff m l
@ -245,16 +228,14 @@ __first_half_done:
_BidirectionalIterator __second_false = __last; _BidirectionalIterator __second_false = __last;
++__second_false; ++__second_false;
__len_half = __len - __len2; __len_half = __len - __len2;
while (__pred(*__m1)) while (__pred(*__m1)) {
{
if (++__m1 == __last) if (++__m1 == __last)
goto __second_half_done; goto __second_half_done;
--__len_half; --__len_half;
} }
// TTTFFFFFTTTF?????T // TTTFFFFFTTTF?????T
// f ff m m1 l // f ff m m1 l
__second_false = std::__stable_partition_impl<_AlgPolicy, _Predicate&>( __second_false = std::__stable_partition_impl<_AlgPolicy, _Predicate&>(__m1, __last, __pred, __len_half, __p, __bit);
__m1, __last, __pred, __len_half, __p, __bit);
__second_half_done: __second_half_done:
// TTTFFFFFTTTTTFFFFF // TTTFFFFFTTTTTFFFFF
// f ff m sf l // f ff m sf l
@ -264,16 +245,13 @@ __second_half_done:
} }
template <class _AlgPolicy, class _Predicate, class _BidirectionalIterator> template <class _AlgPolicy, class _Predicate, class _BidirectionalIterator>
_LIBCPP_HIDE_FROM_ABI _BidirectionalIterator _LIBCPP_HIDE_FROM_ABI _BidirectionalIterator __stable_partition_impl(
__stable_partition_impl(_BidirectionalIterator __first, _BidirectionalIterator __last, _Predicate __pred, _BidirectionalIterator __first, _BidirectionalIterator __last, _Predicate __pred, bidirectional_iterator_tag) {
bidirectional_iterator_tag)
{
typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
const difference_type __alloc_limit = 4; // might want to make this a function of trivial assignment const difference_type __alloc_limit = 4; // might want to make this a function of trivial assignment
// Either prove all true and return __first or point to first false // Either prove all true and return __first or point to first false
while (true) while (true) {
{
if (__first == __last) if (__first == __last)
return __first; return __first;
if (!__pred(*__first)) if (!__pred(*__first))
@ -282,8 +260,7 @@ __stable_partition_impl(_BidirectionalIterator __first, _BidirectionalIterator _
} }
// __first points to first false, everything prior to __first is already set. // __first points to first false, everything prior to __first is already set.
// Either prove [__first, __last) is all false and return __first, or point __last to last true // Either prove [__first, __last) is all false and return __first, or point __last to last true
do do {
{
if (__first == --__last) if (__first == --__last)
return __first; return __first;
} while (!__pred(*__last)); } while (!__pred(*__last));
@ -294,12 +271,11 @@ __stable_partition_impl(_BidirectionalIterator __first, _BidirectionalIterator _
difference_type __len = _IterOps<_AlgPolicy>::distance(__first, __last) + 1; difference_type __len = _IterOps<_AlgPolicy>::distance(__first, __last) + 1;
pair<value_type*, ptrdiff_t> __p(0, 0); pair<value_type*, ptrdiff_t> __p(0, 0);
unique_ptr<value_type, __return_temporary_buffer> __h; unique_ptr<value_type, __return_temporary_buffer> __h;
if (__len >= __alloc_limit) if (__len >= __alloc_limit) {
{ // TODO: Remove the use of std::get_temporary_buffer
// TODO: Remove the use of std::get_temporary_buffer _LIBCPP_SUPPRESS_DEPRECATED_PUSH
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
__p = std::get_temporary_buffer<value_type>(__len); __p = std::get_temporary_buffer<value_type>(__len);
_LIBCPP_SUPPRESS_DEPRECATED_POP _LIBCPP_SUPPRESS_DEPRECATED_POP
__h.reset(__p.first); __h.reset(__p.first);
} }
return std::__stable_partition_impl<_AlgPolicy, _Predicate&>( return std::__stable_partition_impl<_AlgPolicy, _Predicate&>(
@ -307,18 +283,15 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
} }
template <class _AlgPolicy, class _Predicate, class _ForwardIterator, class _IterCategory> template <class _AlgPolicy, class _Predicate, class _ForwardIterator, class _IterCategory>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _ForwardIterator __stable_partition(
_ForwardIterator __stable_partition(
_ForwardIterator __first, _ForwardIterator __last, _Predicate&& __pred, _IterCategory __iter_category) { _ForwardIterator __first, _ForwardIterator __last, _Predicate&& __pred, _IterCategory __iter_category) {
return std::__stable_partition_impl<_AlgPolicy, __remove_cvref_t<_Predicate>&>( return std::__stable_partition_impl<_AlgPolicy, __remove_cvref_t<_Predicate>&>(
std::move(__first), std::move(__last), __pred, __iter_category); std::move(__first), std::move(__last), __pred, __iter_category);
} }
template <class _ForwardIterator, class _Predicate> template <class _ForwardIterator, class _Predicate>
inline _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator
_ForwardIterator stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
{
using _IterCategory = typename iterator_traits<_ForwardIterator>::iterator_category; using _IterCategory = typename iterator_traits<_ForwardIterator>::iterator_category;
return std::__stable_partition<_ClassicAlgPolicy, _Predicate&>( return std::__stable_partition<_ClassicAlgPolicy, _Predicate&>(
std::move(__first), std::move(__last), __pred, _IterCategory()); std::move(__first), std::move(__last), __pred, _IterCategory());

View File

@ -32,9 +32,11 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template <class _AlgPolicy, class _Compare, class _BidirectionalIterator> template <class _AlgPolicy, class _Compare, class _BidirectionalIterator>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI void __insertion_sort_move(
void __insertion_sort_move(_BidirectionalIterator __first1, _BidirectionalIterator __last1, _BidirectionalIterator __first1,
typename iterator_traits<_BidirectionalIterator>::value_type* __first2, _Compare __comp) { _BidirectionalIterator __last1,
typename iterator_traits<_BidirectionalIterator>::value_type* __first2,
_Compare __comp) {
using _Ops = _IterOps<_AlgPolicy>; using _Ops = _IterOps<_AlgPolicy>;
typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
@ -63,40 +65,36 @@ void __insertion_sort_move(_BidirectionalIterator __first1, _BidirectionalIterat
} }
template <class _AlgPolicy, class _Compare, class _InputIterator1, class _InputIterator2> template <class _AlgPolicy, class _Compare, class _InputIterator1, class _InputIterator2>
_LIBCPP_HIDE_FROM_ABI void _LIBCPP_HIDE_FROM_ABI void __merge_move_construct(
__merge_move_construct(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator1 __first1,
_InputIterator2 __first2, _InputIterator2 __last2, _InputIterator1 __last1,
typename iterator_traits<_InputIterator1>::value_type* __result, _Compare __comp) _InputIterator2 __first2,
{ _InputIterator2 __last2,
typename iterator_traits<_InputIterator1>::value_type* __result,
_Compare __comp) {
using _Ops = _IterOps<_AlgPolicy>; using _Ops = _IterOps<_AlgPolicy>;
typedef typename iterator_traits<_InputIterator1>::value_type value_type; typedef typename iterator_traits<_InputIterator1>::value_type value_type;
__destruct_n __d(0); __destruct_n __d(0);
unique_ptr<value_type, __destruct_n&> __h(__result, __d); unique_ptr<value_type, __destruct_n&> __h(__result, __d);
for (; true; ++__result) for (; true; ++__result) {
{ if (__first1 == __last1) {
if (__first1 == __last1) for (; __first2 != __last2; ++__first2, (void)++__result, __d.template __incr<value_type>())
{
for (; __first2 != __last2; ++__first2, (void) ++__result, __d.template __incr<value_type>())
::new ((void*)__result) value_type(_Ops::__iter_move(__first2)); ::new ((void*)__result) value_type(_Ops::__iter_move(__first2));
__h.release(); __h.release();
return; return;
} }
if (__first2 == __last2) if (__first2 == __last2) {
{ for (; __first1 != __last1; ++__first1, (void)++__result, __d.template __incr<value_type>())
for (; __first1 != __last1; ++__first1, (void) ++__result, __d.template __incr<value_type>())
::new ((void*)__result) value_type(_Ops::__iter_move(__first1)); ::new ((void*)__result) value_type(_Ops::__iter_move(__first1));
__h.release(); __h.release();
return; return;
} }
if (__comp(*__first2, *__first1)) if (__comp(*__first2, *__first1)) {
{
::new ((void*)__result) value_type(_Ops::__iter_move(__first2)); ::new ((void*)__result) value_type(_Ops::__iter_move(__first2));
__d.template __incr<value_type>(); __d.template __incr<value_type>();
++__first2; ++__first2;
} } else {
else
{
::new ((void*)__result) value_type(_Ops::__iter_move(__first1)); ::new ((void*)__result) value_type(_Ops::__iter_move(__first1));
__d.template __incr<value_type>(); __d.template __incr<value_type>();
++__first1; ++__first1;
@ -105,53 +103,51 @@ __merge_move_construct(_InputIterator1 __first1, _InputIterator1 __last1,
} }
template <class _AlgPolicy, class _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator> template <class _AlgPolicy, class _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator>
_LIBCPP_HIDE_FROM_ABI void _LIBCPP_HIDE_FROM_ABI void __merge_move_assign(
__merge_move_assign(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator1 __first1,
_InputIterator2 __first2, _InputIterator2 __last2, _InputIterator1 __last1,
_OutputIterator __result, _Compare __comp) _InputIterator2 __first2,
{ _InputIterator2 __last2,
_OutputIterator __result,
_Compare __comp) {
using _Ops = _IterOps<_AlgPolicy>; using _Ops = _IterOps<_AlgPolicy>;
for (; __first1 != __last1; ++__result) for (; __first1 != __last1; ++__result) {
{ if (__first2 == __last2) {
if (__first2 == __last2) for (; __first1 != __last1; ++__first1, (void)++__result)
{
for (; __first1 != __last1; ++__first1, (void) ++__result)
*__result = _Ops::__iter_move(__first1); *__result = _Ops::__iter_move(__first1);
return; return;
} }
if (__comp(*__first2, *__first1)) if (__comp(*__first2, *__first1)) {
{
*__result = _Ops::__iter_move(__first2); *__result = _Ops::__iter_move(__first2);
++__first2; ++__first2;
} } else {
else
{
*__result = _Ops::__iter_move(__first1); *__result = _Ops::__iter_move(__first1);
++__first1; ++__first1;
} }
} }
for (; __first2 != __last2; ++__first2, (void) ++__result) for (; __first2 != __last2; ++__first2, (void)++__result)
*__result = _Ops::__iter_move(__first2); *__result = _Ops::__iter_move(__first2);
} }
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator> template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
void void __stable_sort(_RandomAccessIterator __first,
__stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp, _RandomAccessIterator __last,
_Compare __comp,
typename iterator_traits<_RandomAccessIterator>::difference_type __len, typename iterator_traits<_RandomAccessIterator>::difference_type __len,
typename iterator_traits<_RandomAccessIterator>::value_type* __buff, ptrdiff_t __buff_size); typename iterator_traits<_RandomAccessIterator>::value_type* __buff,
ptrdiff_t __buff_size);
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator> template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
void void __stable_sort_move(_RandomAccessIterator __first1,
__stable_sort_move(_RandomAccessIterator __first1, _RandomAccessIterator __last1, _Compare __comp, _RandomAccessIterator __last1,
_Compare __comp,
typename iterator_traits<_RandomAccessIterator>::difference_type __len, typename iterator_traits<_RandomAccessIterator>::difference_type __len,
typename iterator_traits<_RandomAccessIterator>::value_type* __first2) typename iterator_traits<_RandomAccessIterator>::value_type* __first2) {
{
using _Ops = _IterOps<_AlgPolicy>; using _Ops = _IterOps<_AlgPolicy>;
typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
switch (__len) switch (__len) {
{
case 0: case 0:
return; return;
case 1: case 1:
@ -160,15 +156,12 @@ __stable_sort_move(_RandomAccessIterator __first1, _RandomAccessIterator __last1
case 2: case 2:
__destruct_n __d(0); __destruct_n __d(0);
unique_ptr<value_type, __destruct_n&> __h2(__first2, __d); unique_ptr<value_type, __destruct_n&> __h2(__first2, __d);
if (__comp(*--__last1, *__first1)) if (__comp(*--__last1, *__first1)) {
{
::new ((void*)__first2) value_type(_Ops::__iter_move(__last1)); ::new ((void*)__first2) value_type(_Ops::__iter_move(__last1));
__d.template __incr<value_type>(); __d.template __incr<value_type>();
++__first2; ++__first2;
::new ((void*)__first2) value_type(_Ops::__iter_move(__first1)); ::new ((void*)__first2) value_type(_Ops::__iter_move(__first1));
} } else {
else
{
::new ((void*)__first2) value_type(_Ops::__iter_move(__first1)); ::new ((void*)__first2) value_type(_Ops::__iter_move(__first1));
__d.template __incr<value_type>(); __d.template __incr<value_type>();
++__first2; ++__first2;
@ -177,8 +170,7 @@ __stable_sort_move(_RandomAccessIterator __first1, _RandomAccessIterator __last1
__h2.release(); __h2.release();
return; return;
} }
if (__len <= 8) if (__len <= 8) {
{
std::__insertion_sort_move<_AlgPolicy, _Compare>(__first1, __last1, __first2, __comp); std::__insertion_sort_move<_AlgPolicy, _Compare>(__first1, __last1, __first2, __comp);
return; return;
} }
@ -190,21 +182,20 @@ __stable_sort_move(_RandomAccessIterator __first1, _RandomAccessIterator __last1
} }
template <class _Tp> template <class _Tp>
struct __stable_sort_switch struct __stable_sort_switch {
{ static const unsigned value = 128 * is_trivially_copy_assignable<_Tp>::value;
static const unsigned value = 128*is_trivially_copy_assignable<_Tp>::value;
}; };
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator> template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
void void __stable_sort(_RandomAccessIterator __first,
__stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp, _RandomAccessIterator __last,
_Compare __comp,
typename iterator_traits<_RandomAccessIterator>::difference_type __len, typename iterator_traits<_RandomAccessIterator>::difference_type __len,
typename iterator_traits<_RandomAccessIterator>::value_type* __buff, ptrdiff_t __buff_size) typename iterator_traits<_RandomAccessIterator>::value_type* __buff,
{ ptrdiff_t __buff_size) {
typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
switch (__len) switch (__len) {
{
case 0: case 0:
case 1: case 1:
return; return;
@ -213,15 +204,13 @@ __stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp
_IterOps<_AlgPolicy>::iter_swap(__first, __last); _IterOps<_AlgPolicy>::iter_swap(__first, __last);
return; return;
} }
if (__len <= static_cast<difference_type>(__stable_sort_switch<value_type>::value)) if (__len <= static_cast<difference_type>(__stable_sort_switch<value_type>::value)) {
{
std::__insertion_sort<_AlgPolicy, _Compare>(__first, __last, __comp); std::__insertion_sort<_AlgPolicy, _Compare>(__first, __last, __comp);
return; return;
} }
typename iterator_traits<_RandomAccessIterator>::difference_type __l2 = __len / 2; typename iterator_traits<_RandomAccessIterator>::difference_type __l2 = __len / 2;
_RandomAccessIterator __m = __first + __l2; _RandomAccessIterator __m = __first + __l2;
if (__len <= __buff_size) if (__len <= __buff_size) {
{
__destruct_n __d(0); __destruct_n __d(0);
unique_ptr<value_type, __destruct_n&> __h2(__buff, __d); unique_ptr<value_type, __destruct_n&> __h2(__buff, __d);
std::__stable_sort_move<_AlgPolicy, _Compare>(__first, __m, __comp, __l2, __buff); std::__stable_sort_move<_AlgPolicy, _Compare>(__first, __m, __comp, __l2, __buff);
@ -230,11 +219,11 @@ __stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp
__d.__set(__len, (value_type*)nullptr); __d.__set(__len, (value_type*)nullptr);
std::__merge_move_assign<_AlgPolicy, _Compare>( std::__merge_move_assign<_AlgPolicy, _Compare>(
__buff, __buff + __l2, __buff + __l2, __buff + __len, __first, __comp); __buff, __buff + __l2, __buff + __l2, __buff + __len, __first, __comp);
// std::__merge<_Compare>(move_iterator<value_type*>(__buff), // std::__merge<_Compare>(move_iterator<value_type*>(__buff),
// move_iterator<value_type*>(__buff + __l2), // move_iterator<value_type*>(__buff + __l2),
// move_iterator<_RandomAccessIterator>(__buff + __l2), // move_iterator<_RandomAccessIterator>(__buff + __l2),
// move_iterator<_RandomAccessIterator>(__buff + __len), // move_iterator<_RandomAccessIterator>(__buff + __len),
// __first, __comp); // __first, __comp);
return; return;
} }
std::__stable_sort<_AlgPolicy, _Compare>(__first, __m, __comp, __l2, __buff, __buff_size); std::__stable_sort<_AlgPolicy, _Compare>(__first, __m, __comp, __l2, __buff, __buff_size);
@ -243,8 +232,8 @@ __stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp
} }
template <class _AlgPolicy, class _RandomAccessIterator, class _Compare> template <class _AlgPolicy, class _RandomAccessIterator, class _Compare>
inline _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_HIDE_FROM_ABI void
void __stable_sort_impl(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare& __comp) { __stable_sort_impl(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare& __comp) {
using value_type = typename iterator_traits<_RandomAccessIterator>::value_type; using value_type = typename iterator_traits<_RandomAccessIterator>::value_type;
using difference_type = typename iterator_traits<_RandomAccessIterator>::difference_type; using difference_type = typename iterator_traits<_RandomAccessIterator>::difference_type;
@ -252,10 +241,10 @@ void __stable_sort_impl(_RandomAccessIterator __first, _RandomAccessIterator __l
pair<value_type*, ptrdiff_t> __buf(0, 0); pair<value_type*, ptrdiff_t> __buf(0, 0);
unique_ptr<value_type, __return_temporary_buffer> __h; unique_ptr<value_type, __return_temporary_buffer> __h;
if (__len > static_cast<difference_type>(__stable_sort_switch<value_type>::value)) { if (__len > static_cast<difference_type>(__stable_sort_switch<value_type>::value)) {
// TODO: Remove the use of std::get_temporary_buffer // TODO: Remove the use of std::get_temporary_buffer
_LIBCPP_SUPPRESS_DEPRECATED_PUSH _LIBCPP_SUPPRESS_DEPRECATED_PUSH
__buf = std::get_temporary_buffer<value_type>(__len); __buf = std::get_temporary_buffer<value_type>(__len);
_LIBCPP_SUPPRESS_DEPRECATED_POP _LIBCPP_SUPPRESS_DEPRECATED_POP
__h.reset(__buf.first); __h.reset(__buf.first);
} }
@ -264,14 +253,13 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
} }
template <class _RandomAccessIterator, class _Compare> template <class _RandomAccessIterator, class _Compare>
inline _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_HIDE_FROM_ABI void
void stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) {
std::__stable_sort_impl<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __comp); std::__stable_sort_impl<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __comp);
} }
template <class _RandomAccessIterator> template <class _RandomAccessIterator>
inline _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_HIDE_FROM_ABI void stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last) {
void stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last) {
std::stable_sort(__first, __last, __less<>()); std::stable_sort(__first, __last, __less<>());
} }

View File

@ -22,8 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
// 2+2 iterators: the shorter size will be used. // 2+2 iterators: the shorter size will be used.
template <class _AlgPolicy, class _ForwardIterator1, class _Sentinel1, class _ForwardIterator2, class _Sentinel2> template <class _AlgPolicy, class _ForwardIterator1, class _Sentinel1, class _ForwardIterator2, class _Sentinel2>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator1, _ForwardIterator2>
pair<_ForwardIterator1, _ForwardIterator2>
__swap_ranges(_ForwardIterator1 __first1, _Sentinel1 __last1, _ForwardIterator2 __first2, _Sentinel2 __last2) { __swap_ranges(_ForwardIterator1 __first1, _Sentinel1 __last1, _ForwardIterator2 __first2, _Sentinel2 __last2) {
while (__first1 != __last1 && __first2 != __last2) { while (__first1 != __last1 && __first2 != __last2) {
_IterOps<_AlgPolicy>::iter_swap(__first1, __first2); _IterOps<_AlgPolicy>::iter_swap(__first1, __first2);
@ -36,8 +35,7 @@ __swap_ranges(_ForwardIterator1 __first1, _Sentinel1 __last1, _ForwardIterator2
// 2+1 iterators: size2 >= size1. // 2+1 iterators: size2 >= size1.
template <class _AlgPolicy, class _ForwardIterator1, class _Sentinel1, class _ForwardIterator2> template <class _AlgPolicy, class _ForwardIterator1, class _Sentinel1, class _ForwardIterator2>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator1, _ForwardIterator2>
pair<_ForwardIterator1, _ForwardIterator2>
__swap_ranges(_ForwardIterator1 __first1, _Sentinel1 __last1, _ForwardIterator2 __first2) { __swap_ranges(_ForwardIterator1 __first1, _Sentinel1 __last1, _ForwardIterator2 __first2) {
while (__first1 != __last1) { while (__first1 != __last1) {
_IterOps<_AlgPolicy>::iter_swap(__first1, __first2); _IterOps<_AlgPolicy>::iter_swap(__first1, __first2);
@ -51,8 +49,7 @@ __swap_ranges(_ForwardIterator1 __first1, _Sentinel1 __last1, _ForwardIterator2
template <class _ForwardIterator1, class _ForwardIterator2> template <class _ForwardIterator1, class _ForwardIterator2>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator2 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator2
swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2) { swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2) {
return std::__swap_ranges<_ClassicAlgPolicy>( return std::__swap_ranges<_ClassicAlgPolicy>(std::move(__first1), std::move(__last1), std::move(__first2)).second;
std::move(__first1), std::move(__last1), std::move(__first2)).second;
} }
_LIBCPP_END_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD

View File

@ -18,22 +18,21 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template <class _InputIterator, class _OutputIterator, class _UnaryOperation> template <class _InputIterator, class _OutputIterator, class _UnaryOperation>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
_OutputIterator transform(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _UnaryOperation __op) {
transform(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _UnaryOperation __op) for (; __first != __last; ++__first, (void)++__result)
{
for (; __first != __last; ++__first, (void) ++__result)
*__result = __op(*__first); *__result = __op(*__first);
return __result; return __result;
} }
template <class _InputIterator1, class _InputIterator2, class _OutputIterator, class _BinaryOperation> template <class _InputIterator1, class _InputIterator2, class _OutputIterator, class _BinaryOperation>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator transform(
_OutputIterator _InputIterator1 __first1,
transform(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator1 __last1,
_OutputIterator __result, _BinaryOperation __binary_op) _InputIterator2 __first2,
{ _OutputIterator __result,
for (; __first1 != __last1; ++__first1, (void) ++__first2, ++__result) _BinaryOperation __binary_op) {
for (; __first1 != __last1; ++__first1, (void)++__first2, ++__result)
*__result = __binary_op(*__first1, *__first2); *__result = __binary_op(*__first1, *__first2);
return __result; return __result;
} }

View File

@ -20,7 +20,7 @@
#if _LIBCPP_STD_VER >= 20 #if _LIBCPP_STD_VER >= 20
_LIBCPP_PUSH_MACROS _LIBCPP_PUSH_MACROS
#include <__undef_macros> # include <__undef_macros>
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
@ -41,16 +41,12 @@ private:
public: public:
using result_type = invoke_result_t<_Gen&>; using result_type = invoke_result_t<_Gen&>;
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI static constexpr auto min() { return __remove_cvref_t<_Gen>::min(); }
static constexpr auto min() { return __remove_cvref_t<_Gen>::min(); } _LIBCPP_HIDE_FROM_ABI static constexpr auto max() { return __remove_cvref_t<_Gen>::max(); }
_LIBCPP_HIDE_FROM_ABI
static constexpr auto max() { return __remove_cvref_t<_Gen>::max(); }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI constexpr explicit _ClassicGenAdaptor(_Gen& __g) : __gen_(__g) {}
constexpr explicit _ClassicGenAdaptor(_Gen& __g) : __gen_(__g) {}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI constexpr auto operator()() const { return __gen_(); }
constexpr auto operator()() const { return __gen_(); }
}; };
_LIBCPP_END_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD

View File

@ -57,11 +57,11 @@ struct __unwrap_iter_impl<_Iter, true> {
} }
}; };
template<class _Iter, template <class _Iter,
class _Impl = __unwrap_iter_impl<_Iter>, class _Impl = __unwrap_iter_impl<_Iter>,
__enable_if_t<is_copy_constructible<_Iter>::value, int> = 0> __enable_if_t<is_copy_constructible<_Iter>::value, int> = 0>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 decltype(_Impl::__unwrap(std::declval<_Iter>()))
decltype(_Impl::__unwrap(std::declval<_Iter>())) __unwrap_iter(_Iter __i) _NOEXCEPT { __unwrap_iter(_Iter __i) _NOEXCEPT {
return _Impl::__unwrap(__i); return _Impl::__unwrap(__i);
} }

View File

@ -33,30 +33,27 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template <class _Tp> template <class _Tp>
struct atomic struct atomic : public __atomic_base<_Tp> {
: public __atomic_base<_Tp>
{
using __base = __atomic_base<_Tp>; using __base = __atomic_base<_Tp>;
using value_type = _Tp; using value_type = _Tp;
using difference_type = value_type; using difference_type = value_type;
#if _LIBCPP_STD_VER >= 20 #if _LIBCPP_STD_VER >= 20
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI atomic() = default;
atomic() = default;
#else #else
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI atomic() _NOEXCEPT = default;
atomic() _NOEXCEPT = default;
#endif #endif
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR atomic(_Tp __d) _NOEXCEPT : __base(__d) {}
_LIBCPP_CONSTEXPR atomic(_Tp __d) _NOEXCEPT : __base(__d) {}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp operator=(_Tp __d) volatile _NOEXCEPT {
_Tp operator=(_Tp __d) volatile _NOEXCEPT __base::store(__d);
{__base::store(__d); return __d;} return __d;
_LIBCPP_HIDE_FROM_ABI }
_Tp operator=(_Tp __d) _NOEXCEPT _LIBCPP_HIDE_FROM_ABI _Tp operator=(_Tp __d) _NOEXCEPT {
{__base::store(__d); return __d;} __base::store(__d);
return __d;
}
atomic& operator=(const atomic&) = delete; atomic& operator=(const atomic&) = delete;
atomic& operator=(const atomic&) volatile = delete; atomic& operator=(const atomic&) volatile = delete;
@ -65,78 +62,60 @@ struct atomic
// atomic<T*> // atomic<T*>
template <class _Tp> template <class _Tp>
struct atomic<_Tp*> struct atomic<_Tp*> : public __atomic_base<_Tp*> {
: public __atomic_base<_Tp*>
{
using __base = __atomic_base<_Tp*>; using __base = __atomic_base<_Tp*>;
using value_type = _Tp*; using value_type = _Tp*;
using difference_type = ptrdiff_t; using difference_type = ptrdiff_t;
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI atomic() _NOEXCEPT = default;
atomic() _NOEXCEPT = default;
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR atomic(_Tp* __d) _NOEXCEPT : __base(__d) {}
_LIBCPP_CONSTEXPR atomic(_Tp* __d) _NOEXCEPT : __base(__d) {}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp* operator=(_Tp* __d) volatile _NOEXCEPT {
_Tp* operator=(_Tp* __d) volatile _NOEXCEPT __base::store(__d);
{__base::store(__d); return __d;} return __d;
_LIBCPP_HIDE_FROM_ABI }
_Tp* operator=(_Tp* __d) _NOEXCEPT _LIBCPP_HIDE_FROM_ABI _Tp* operator=(_Tp* __d) _NOEXCEPT {
{__base::store(__d); return __d;} __base::store(__d);
return __d;
}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT {
_Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT {
// __atomic_fetch_add accepts function pointers, guard against them. // __atomic_fetch_add accepts function pointers, guard against them.
static_assert(!is_function<__remove_pointer_t<_Tp> >::value, "Pointer to function isn't allowed"); static_assert(!is_function<__remove_pointer_t<_Tp> >::value, "Pointer to function isn't allowed");
return std::__cxx_atomic_fetch_add(std::addressof(this->__a_), __op, __m); return std::__cxx_atomic_fetch_add(std::addressof(this->__a_), __op, __m);
} }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT {
_Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT {
// __atomic_fetch_add accepts function pointers, guard against them. // __atomic_fetch_add accepts function pointers, guard against them.
static_assert(!is_function<__remove_pointer_t<_Tp> >::value, "Pointer to function isn't allowed"); static_assert(!is_function<__remove_pointer_t<_Tp> >::value, "Pointer to function isn't allowed");
return std::__cxx_atomic_fetch_add(std::addressof(this->__a_), __op, __m); return std::__cxx_atomic_fetch_add(std::addressof(this->__a_), __op, __m);
} }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT {
_Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT {
// __atomic_fetch_add accepts function pointers, guard against them. // __atomic_fetch_add accepts function pointers, guard against them.
static_assert(!is_function<__remove_pointer_t<_Tp> >::value, "Pointer to function isn't allowed"); static_assert(!is_function<__remove_pointer_t<_Tp> >::value, "Pointer to function isn't allowed");
return std::__cxx_atomic_fetch_sub(std::addressof(this->__a_), __op, __m); return std::__cxx_atomic_fetch_sub(std::addressof(this->__a_), __op, __m);
} }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT {
_Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT {
// __atomic_fetch_add accepts function pointers, guard against them. // __atomic_fetch_add accepts function pointers, guard against them.
static_assert(!is_function<__remove_pointer_t<_Tp> >::value, "Pointer to function isn't allowed"); static_assert(!is_function<__remove_pointer_t<_Tp> >::value, "Pointer to function isn't allowed");
return std::__cxx_atomic_fetch_sub(std::addressof(this->__a_), __op, __m); return std::__cxx_atomic_fetch_sub(std::addressof(this->__a_), __op, __m);
} }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp* operator++(int) volatile _NOEXCEPT { return fetch_add(1); }
_Tp* operator++(int) volatile _NOEXCEPT {return fetch_add(1);} _LIBCPP_HIDE_FROM_ABI _Tp* operator++(int) _NOEXCEPT { return fetch_add(1); }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp* operator--(int) volatile _NOEXCEPT { return fetch_sub(1); }
_Tp* operator++(int) _NOEXCEPT {return fetch_add(1);} _LIBCPP_HIDE_FROM_ABI _Tp* operator--(int) _NOEXCEPT { return fetch_sub(1); }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp* operator++() volatile _NOEXCEPT { return fetch_add(1) + 1; }
_Tp* operator--(int) volatile _NOEXCEPT {return fetch_sub(1);} _LIBCPP_HIDE_FROM_ABI _Tp* operator++() _NOEXCEPT { return fetch_add(1) + 1; }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp* operator--() volatile _NOEXCEPT { return fetch_sub(1) - 1; }
_Tp* operator--(int) _NOEXCEPT {return fetch_sub(1);} _LIBCPP_HIDE_FROM_ABI _Tp* operator--() _NOEXCEPT { return fetch_sub(1) - 1; }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp* operator+=(ptrdiff_t __op) volatile _NOEXCEPT { return fetch_add(__op) + __op; }
_Tp* operator++() volatile _NOEXCEPT {return fetch_add(1) + 1;} _LIBCPP_HIDE_FROM_ABI _Tp* operator+=(ptrdiff_t __op) _NOEXCEPT { return fetch_add(__op) + __op; }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp* operator-=(ptrdiff_t __op) volatile _NOEXCEPT { return fetch_sub(__op) - __op; }
_Tp* operator++() _NOEXCEPT {return fetch_add(1) + 1;} _LIBCPP_HIDE_FROM_ABI _Tp* operator-=(ptrdiff_t __op) _NOEXCEPT { return fetch_sub(__op) - __op; }
_LIBCPP_HIDE_FROM_ABI
_Tp* operator--() volatile _NOEXCEPT {return fetch_sub(1) - 1;}
_LIBCPP_HIDE_FROM_ABI
_Tp* operator--() _NOEXCEPT {return fetch_sub(1) - 1;}
_LIBCPP_HIDE_FROM_ABI
_Tp* operator+=(ptrdiff_t __op) volatile _NOEXCEPT {return fetch_add(__op) + __op;}
_LIBCPP_HIDE_FROM_ABI
_Tp* operator+=(ptrdiff_t __op) _NOEXCEPT {return fetch_add(__op) + __op;}
_LIBCPP_HIDE_FROM_ABI
_Tp* operator-=(ptrdiff_t __op) volatile _NOEXCEPT {return fetch_sub(__op) - __op;}
_LIBCPP_HIDE_FROM_ABI
_Tp* operator-=(ptrdiff_t __op) _NOEXCEPT {return fetch_sub(__op) - __op;}
atomic& operator=(const atomic&) = delete; atomic& operator=(const atomic&) = delete;
atomic& operator=(const atomic&) volatile = delete; atomic& operator=(const atomic&) volatile = delete;
@ -146,7 +125,7 @@ struct atomic<_Tp*>
template <class _Tp> template <class _Tp>
requires is_floating_point_v<_Tp> requires is_floating_point_v<_Tp>
struct atomic<_Tp> : __atomic_base<_Tp> { struct atomic<_Tp> : __atomic_base<_Tp> {
private: private:
_LIBCPP_HIDE_FROM_ABI static constexpr bool __is_fp80_long_double() { _LIBCPP_HIDE_FROM_ABI static constexpr bool __is_fp80_long_double() {
// Only x87-fp80 long double has 64-bit mantissa // Only x87-fp80 long double has 64-bit mantissa
return __LDBL_MANT_DIG__ == 64 && std::is_same_v<_Tp, long double>; return __LDBL_MANT_DIG__ == 64 && std::is_same_v<_Tp, long double>;
@ -210,7 +189,7 @@ struct atomic<_Tp> : __atomic_base<_Tp> {
return __rmw_op(std::forward<_This>(__self), __operand, __m, std::minus<>{}, __builtin_op); return __rmw_op(std::forward<_This>(__self), __operand, __m, std::minus<>{}, __builtin_op);
} }
public: public:
using __base = __atomic_base<_Tp>; using __base = __atomic_base<_Tp>;
using value_type = _Tp; using value_type = _Tp;
using difference_type = value_type; using difference_type = value_type;
@ -275,475 +254,362 @@ struct atomic<_Tp> : __atomic_base<_Tp> {
// atomic_is_lock_free // atomic_is_lock_free
template <class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI bool atomic_is_lock_free(const volatile atomic<_Tp>* __o) _NOEXCEPT {
bool
atomic_is_lock_free(const volatile atomic<_Tp>* __o) _NOEXCEPT
{
return __o->is_lock_free(); return __o->is_lock_free();
} }
template <class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI bool atomic_is_lock_free(const atomic<_Tp>* __o) _NOEXCEPT {
bool
atomic_is_lock_free(const atomic<_Tp>* __o) _NOEXCEPT
{
return __o->is_lock_free(); return __o->is_lock_free();
} }
// atomic_init // atomic_init
template <class _Tp> template <class _Tp>
_LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_HIDE_FROM_ABI void
void atomic_init(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT {
atomic_init(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT
{
std::__cxx_atomic_init(std::addressof(__o->__a_), __d); std::__cxx_atomic_init(std::addressof(__o->__a_), __d);
} }
template <class _Tp> template <class _Tp>
_LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_HIDE_FROM_ABI void
void atomic_init(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT {
atomic_init(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT
{
std::__cxx_atomic_init(std::addressof(__o->__a_), __d); std::__cxx_atomic_init(std::addressof(__o->__a_), __d);
} }
// atomic_store // atomic_store
template <class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI void atomic_store(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT {
void
atomic_store(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT
{
__o->store(__d); __o->store(__d);
} }
template <class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI void atomic_store(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT {
void
atomic_store(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT
{
__o->store(__d); __o->store(__d);
} }
// atomic_store_explicit // atomic_store_explicit
template <class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI void
void
atomic_store_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d, memory_order __m) _NOEXCEPT atomic_store_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d, memory_order __m) _NOEXCEPT
_LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) {
{
__o->store(__d, __m); __o->store(__d, __m);
} }
template <class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI void
void
atomic_store_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d, memory_order __m) _NOEXCEPT atomic_store_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d, memory_order __m) _NOEXCEPT
_LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) {
{
__o->store(__d, __m); __o->store(__d, __m);
} }
// atomic_load // atomic_load
template <class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp atomic_load(const volatile atomic<_Tp>* __o) _NOEXCEPT {
_Tp
atomic_load(const volatile atomic<_Tp>* __o) _NOEXCEPT
{
return __o->load(); return __o->load();
} }
template <class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp atomic_load(const atomic<_Tp>* __o) _NOEXCEPT {
_Tp
atomic_load(const atomic<_Tp>* __o) _NOEXCEPT
{
return __o->load(); return __o->load();
} }
// atomic_load_explicit // atomic_load_explicit
template <class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp atomic_load_explicit(const volatile atomic<_Tp>* __o, memory_order __m) _NOEXCEPT
_Tp _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) {
atomic_load_explicit(const volatile atomic<_Tp>* __o, memory_order __m) _NOEXCEPT
_LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m)
{
return __o->load(__m); return __o->load(__m);
} }
template <class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp atomic_load_explicit(const atomic<_Tp>* __o, memory_order __m) _NOEXCEPT
_Tp _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) {
atomic_load_explicit(const atomic<_Tp>* __o, memory_order __m) _NOEXCEPT
_LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m)
{
return __o->load(__m); return __o->load(__m);
} }
// atomic_exchange // atomic_exchange
template <class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp atomic_exchange(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT {
_Tp
atomic_exchange(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT
{
return __o->exchange(__d); return __o->exchange(__d);
} }
template <class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp atomic_exchange(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT {
_Tp
atomic_exchange(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT
{
return __o->exchange(__d); return __o->exchange(__d);
} }
// atomic_exchange_explicit // atomic_exchange_explicit
template <class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp
_Tp atomic_exchange_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d, memory_order __m) _NOEXCEPT {
atomic_exchange_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d, memory_order __m) _NOEXCEPT
{
return __o->exchange(__d, __m); return __o->exchange(__d, __m);
} }
template <class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp
_Tp atomic_exchange_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d, memory_order __m) _NOEXCEPT {
atomic_exchange_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d, memory_order __m) _NOEXCEPT
{
return __o->exchange(__d, __m); return __o->exchange(__d, __m);
} }
// atomic_compare_exchange_weak // atomic_compare_exchange_weak
template <class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI bool atomic_compare_exchange_weak(
bool volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type* __e, typename atomic<_Tp>::value_type __d) _NOEXCEPT {
atomic_compare_exchange_weak(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type* __e, typename atomic<_Tp>::value_type __d) _NOEXCEPT
{
return __o->compare_exchange_weak(*__e, __d); return __o->compare_exchange_weak(*__e, __d);
} }
template <class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI bool atomic_compare_exchange_weak(
bool atomic<_Tp>* __o, typename atomic<_Tp>::value_type* __e, typename atomic<_Tp>::value_type __d) _NOEXCEPT {
atomic_compare_exchange_weak(atomic<_Tp>* __o, typename atomic<_Tp>::value_type* __e, typename atomic<_Tp>::value_type __d) _NOEXCEPT
{
return __o->compare_exchange_weak(*__e, __d); return __o->compare_exchange_weak(*__e, __d);
} }
// atomic_compare_exchange_strong // atomic_compare_exchange_strong
template <class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI bool atomic_compare_exchange_strong(
bool volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type* __e, typename atomic<_Tp>::value_type __d) _NOEXCEPT {
atomic_compare_exchange_strong(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type* __e, typename atomic<_Tp>::value_type __d) _NOEXCEPT
{
return __o->compare_exchange_strong(*__e, __d); return __o->compare_exchange_strong(*__e, __d);
} }
template <class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI bool atomic_compare_exchange_strong(
bool atomic<_Tp>* __o, typename atomic<_Tp>::value_type* __e, typename atomic<_Tp>::value_type __d) _NOEXCEPT {
atomic_compare_exchange_strong(atomic<_Tp>* __o, typename atomic<_Tp>::value_type* __e, typename atomic<_Tp>::value_type __d) _NOEXCEPT
{
return __o->compare_exchange_strong(*__e, __d); return __o->compare_exchange_strong(*__e, __d);
} }
// atomic_compare_exchange_weak_explicit // atomic_compare_exchange_weak_explicit
template <class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI bool atomic_compare_exchange_weak_explicit(
bool volatile atomic<_Tp>* __o,
atomic_compare_exchange_weak_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type* __e, typename atomic<_Tp>::value_type* __e,
typename atomic<_Tp>::value_type __d, typename atomic<_Tp>::value_type __d,
memory_order __s, memory_order __f) _NOEXCEPT memory_order __s,
_LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) memory_order __f) _NOEXCEPT _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) {
{
return __o->compare_exchange_weak(*__e, __d, __s, __f); return __o->compare_exchange_weak(*__e, __d, __s, __f);
} }
template <class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI bool atomic_compare_exchange_weak_explicit(
bool atomic<_Tp>* __o,
atomic_compare_exchange_weak_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::value_type* __e, typename atomic<_Tp>::value_type __d, typename atomic<_Tp>::value_type* __e,
memory_order __s, memory_order __f) _NOEXCEPT typename atomic<_Tp>::value_type __d,
_LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) memory_order __s,
{ memory_order __f) _NOEXCEPT _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) {
return __o->compare_exchange_weak(*__e, __d, __s, __f); return __o->compare_exchange_weak(*__e, __d, __s, __f);
} }
// atomic_compare_exchange_strong_explicit // atomic_compare_exchange_strong_explicit
template <class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI bool atomic_compare_exchange_strong_explicit(
bool volatile atomic<_Tp>* __o,
atomic_compare_exchange_strong_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type* __e,
typename atomic<_Tp>::value_type* __e, typename atomic<_Tp>::value_type __d, typename atomic<_Tp>::value_type __d,
memory_order __s, memory_order __f) _NOEXCEPT memory_order __s,
_LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) memory_order __f) _NOEXCEPT _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) {
{
return __o->compare_exchange_strong(*__e, __d, __s, __f); return __o->compare_exchange_strong(*__e, __d, __s, __f);
} }
template <class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI bool atomic_compare_exchange_strong_explicit(
bool atomic<_Tp>* __o,
atomic_compare_exchange_strong_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::value_type* __e, typename atomic<_Tp>::value_type* __e,
typename atomic<_Tp>::value_type __d, typename atomic<_Tp>::value_type __d,
memory_order __s, memory_order __f) _NOEXCEPT memory_order __s,
_LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) memory_order __f) _NOEXCEPT _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) {
{
return __o->compare_exchange_strong(*__e, __d, __s, __f); return __o->compare_exchange_strong(*__e, __d, __s, __f);
} }
// atomic_wait // atomic_wait
template <class _Tp> template <class _Tp>
_LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void
void atomic_wait(const volatile atomic<_Tp>* __o, atomic_wait(const volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __v) _NOEXCEPT {
typename atomic<_Tp>::value_type __v) _NOEXCEPT
{
return __o->wait(__v); return __o->wait(__v);
} }
template <class _Tp> template <class _Tp>
_LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void
void atomic_wait(const atomic<_Tp>* __o, atomic_wait(const atomic<_Tp>* __o, typename atomic<_Tp>::value_type __v) _NOEXCEPT {
typename atomic<_Tp>::value_type __v) _NOEXCEPT
{
return __o->wait(__v); return __o->wait(__v);
} }
// atomic_wait_explicit // atomic_wait_explicit
template <class _Tp> template <class _Tp>
_LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void
void atomic_wait_explicit(const volatile atomic<_Tp>* __o, atomic_wait_explicit(const volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __v, memory_order __m) _NOEXCEPT
typename atomic<_Tp>::value_type __v, _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) {
memory_order __m) _NOEXCEPT
_LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m)
{
return __o->wait(__v, __m); return __o->wait(__v, __m);
} }
template <class _Tp> template <class _Tp>
_LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void
void atomic_wait_explicit(const atomic<_Tp>* __o, atomic_wait_explicit(const atomic<_Tp>* __o, typename atomic<_Tp>::value_type __v, memory_order __m) _NOEXCEPT
typename atomic<_Tp>::value_type __v, _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) {
memory_order __m) _NOEXCEPT
_LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m)
{
return __o->wait(__v, __m); return __o->wait(__v, __m);
} }
// atomic_notify_one // atomic_notify_one
template <class _Tp> template <class _Tp>
_LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void atomic_notify_one(volatile atomic<_Tp>* __o) _NOEXCEPT {
void atomic_notify_one(volatile atomic<_Tp>* __o) _NOEXCEPT
{
__o->notify_one(); __o->notify_one();
} }
template <class _Tp> template <class _Tp>
_LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void atomic_notify_one(atomic<_Tp>* __o) _NOEXCEPT {
void atomic_notify_one(atomic<_Tp>* __o) _NOEXCEPT
{
__o->notify_one(); __o->notify_one();
} }
// atomic_notify_all // atomic_notify_all
template <class _Tp> template <class _Tp>
_LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void atomic_notify_all(volatile atomic<_Tp>* __o) _NOEXCEPT {
void atomic_notify_all(volatile atomic<_Tp>* __o) _NOEXCEPT
{
__o->notify_all(); __o->notify_all();
} }
template <class _Tp> template <class _Tp>
_LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void atomic_notify_all(atomic<_Tp>* __o) _NOEXCEPT {
void atomic_notify_all(atomic<_Tp>* __o) _NOEXCEPT
{
__o->notify_all(); __o->notify_all();
} }
// atomic_fetch_add // atomic_fetch_add
template <class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp
_Tp atomic_fetch_add(volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op) _NOEXCEPT {
atomic_fetch_add(volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op) _NOEXCEPT
{
return __o->fetch_add(__op); return __o->fetch_add(__op);
} }
template <class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_add(atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op) _NOEXCEPT {
_Tp
atomic_fetch_add(atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op) _NOEXCEPT
{
return __o->fetch_add(__op); return __o->fetch_add(__op);
} }
// atomic_fetch_add_explicit // atomic_fetch_add_explicit
template <class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_add_explicit(
_Tp atomic_fetch_add_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT {
{
return __o->fetch_add(__op, __m); return __o->fetch_add(__op, __m);
} }
template <class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp
_Tp atomic_fetch_add_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT atomic_fetch_add_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT {
{
return __o->fetch_add(__op, __m); return __o->fetch_add(__op, __m);
} }
// atomic_fetch_sub // atomic_fetch_sub
template <class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp
_Tp atomic_fetch_sub(volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op) _NOEXCEPT atomic_fetch_sub(volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op) _NOEXCEPT {
{
return __o->fetch_sub(__op); return __o->fetch_sub(__op);
} }
template <class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_sub(atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op) _NOEXCEPT {
_Tp atomic_fetch_sub(atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op) _NOEXCEPT
{
return __o->fetch_sub(__op); return __o->fetch_sub(__op);
} }
// atomic_fetch_sub_explicit // atomic_fetch_sub_explicit
template <class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_sub_explicit(
_Tp atomic_fetch_sub_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT {
{
return __o->fetch_sub(__op, __m); return __o->fetch_sub(__op, __m);
} }
template <class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp
_Tp atomic_fetch_sub_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT atomic_fetch_sub_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT {
{
return __o->fetch_sub(__op, __m); return __o->fetch_sub(__op, __m);
} }
// atomic_fetch_and // atomic_fetch_and
template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0> template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_and(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) _NOEXCEPT {
_Tp
atomic_fetch_and(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) _NOEXCEPT
{
return __o->fetch_and(__op); return __o->fetch_and(__op);
} }
template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0> template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_and(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) _NOEXCEPT {
_Tp
atomic_fetch_and(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) _NOEXCEPT
{
return __o->fetch_and(__op); return __o->fetch_and(__op);
} }
// atomic_fetch_and_explicit // atomic_fetch_and_explicit
template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0> template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_and_explicit(
_Tp volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) _NOEXCEPT {
atomic_fetch_and_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) _NOEXCEPT
{
return __o->fetch_and(__op, __m); return __o->fetch_and(__op, __m);
} }
template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0> template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp
_Tp atomic_fetch_and_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) _NOEXCEPT {
atomic_fetch_and_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) _NOEXCEPT
{
return __o->fetch_and(__op, __m); return __o->fetch_and(__op, __m);
} }
// atomic_fetch_or // atomic_fetch_or
template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0> template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_or(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) _NOEXCEPT {
_Tp
atomic_fetch_or(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) _NOEXCEPT
{
return __o->fetch_or(__op); return __o->fetch_or(__op);
} }
template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0> template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_or(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) _NOEXCEPT {
_Tp
atomic_fetch_or(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) _NOEXCEPT
{
return __o->fetch_or(__op); return __o->fetch_or(__op);
} }
// atomic_fetch_or_explicit // atomic_fetch_or_explicit
template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0> template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp
_Tp atomic_fetch_or_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) _NOEXCEPT {
atomic_fetch_or_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) _NOEXCEPT
{
return __o->fetch_or(__op, __m); return __o->fetch_or(__op, __m);
} }
template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0> template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp
_Tp atomic_fetch_or_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) _NOEXCEPT {
atomic_fetch_or_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) _NOEXCEPT
{
return __o->fetch_or(__op, __m); return __o->fetch_or(__op, __m);
} }
// atomic_fetch_xor // atomic_fetch_xor
template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0> template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_xor(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) _NOEXCEPT {
_Tp
atomic_fetch_xor(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) _NOEXCEPT
{
return __o->fetch_xor(__op); return __o->fetch_xor(__op);
} }
template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0> template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_xor(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) _NOEXCEPT {
_Tp
atomic_fetch_xor(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) _NOEXCEPT
{
return __o->fetch_xor(__op); return __o->fetch_xor(__op);
} }
// atomic_fetch_xor_explicit // atomic_fetch_xor_explicit
template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0> template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_xor_explicit(
_Tp volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) _NOEXCEPT {
atomic_fetch_xor_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) _NOEXCEPT
{
return __o->fetch_xor(__op, __m); return __o->fetch_xor(__op, __m);
} }
template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0> template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp
_Tp atomic_fetch_xor_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) _NOEXCEPT {
atomic_fetch_xor_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) _NOEXCEPT
{
return __o->fetch_xor(__op, __m); return __o->fetch_xor(__op, __m);
} }

View File

@ -37,12 +37,12 @@ struct __atomic_base // false
static _LIBCPP_CONSTEXPR bool is_always_lock_free = __libcpp_is_always_lock_free<__cxx_atomic_impl<_Tp> >::__value; static _LIBCPP_CONSTEXPR bool is_always_lock_free = __libcpp_is_always_lock_free<__cxx_atomic_impl<_Tp> >::__value;
#endif #endif
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI bool is_lock_free() const volatile _NOEXCEPT {
bool is_lock_free() const volatile _NOEXCEPT return __cxx_atomic_is_lock_free(sizeof(__cxx_atomic_impl<_Tp>));
{return __cxx_atomic_is_lock_free(sizeof(__cxx_atomic_impl<_Tp>));} }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI bool is_lock_free() const _NOEXCEPT {
bool is_lock_free() const _NOEXCEPT return static_cast<__atomic_base const volatile*>(this)->is_lock_free();
{return static_cast<__atomic_base const volatile*>(this)->is_lock_free();} }
_LIBCPP_HIDE_FROM_ABI void store(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT _LIBCPP_HIDE_FROM_ABI void store(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
_LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) { _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) {
std::__cxx_atomic_store(std::addressof(__a_), __d, __m); std::__cxx_atomic_store(std::addressof(__a_), __d, __m);
@ -59,10 +59,8 @@ struct __atomic_base // false
_LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) { _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) {
return std::__cxx_atomic_load(std::addressof(__a_), __m); return std::__cxx_atomic_load(std::addressof(__a_), __m);
} }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI operator _Tp() const volatile _NOEXCEPT { return load(); }
operator _Tp() const volatile _NOEXCEPT {return load();} _LIBCPP_HIDE_FROM_ABI operator _Tp() const _NOEXCEPT { return load(); }
_LIBCPP_HIDE_FROM_ABI
operator _Tp() const _NOEXCEPT {return load();}
_LIBCPP_HIDE_FROM_ABI _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { _LIBCPP_HIDE_FROM_ABI _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT {
return std::__cxx_atomic_exchange(std::addressof(__a_), __d, __m); return std::__cxx_atomic_exchange(std::addressof(__a_), __d, __m);
} }
@ -126,15 +124,12 @@ struct __atomic_base // false
} }
#if _LIBCPP_STD_VER >= 20 #if _LIBCPP_STD_VER >= 20
_LIBCPP_HIDE_FROM_ABI constexpr _LIBCPP_HIDE_FROM_ABI constexpr __atomic_base() noexcept(is_nothrow_default_constructible_v<_Tp>) : __a_(_Tp()) {}
__atomic_base() noexcept(is_nothrow_default_constructible_v<_Tp>) : __a_(_Tp()) {}
#else #else
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI __atomic_base() _NOEXCEPT = default;
__atomic_base() _NOEXCEPT = default;
#endif #endif
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __a_(__d) {}
__atomic_base(_Tp __d) _NOEXCEPT : __a_(__d) {}
__atomic_base(const __atomic_base&) = delete; __atomic_base(const __atomic_base&) = delete;
}; };
@ -147,16 +142,12 @@ _LIBCPP_CONSTEXPR bool __atomic_base<_Tp, __b>::is_always_lock_free;
// atomic<Integral> // atomic<Integral>
template <class _Tp> template <class _Tp>
struct __atomic_base<_Tp, true> struct __atomic_base<_Tp, true> : public __atomic_base<_Tp, false> {
: public __atomic_base<_Tp, false>
{
using __base = __atomic_base<_Tp, false>; using __base = __atomic_base<_Tp, false>;
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __atomic_base() _NOEXCEPT = default;
__atomic_base() _NOEXCEPT = default;
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __base(__d) {}
_LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __base(__d) {}
_LIBCPP_HIDE_FROM_ABI _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { _LIBCPP_HIDE_FROM_ABI _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT {
return std::__cxx_atomic_fetch_add(std::addressof(this->__a_), __op, __m); return std::__cxx_atomic_fetch_add(std::addressof(this->__a_), __op, __m);
@ -189,42 +180,24 @@ struct __atomic_base<_Tp, true>
return std::__cxx_atomic_fetch_xor(std::addressof(this->__a_), __op, __m); return std::__cxx_atomic_fetch_xor(std::addressof(this->__a_), __op, __m);
} }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp operator++(int) volatile _NOEXCEPT { return fetch_add(_Tp(1)); }
_Tp operator++(int) volatile _NOEXCEPT {return fetch_add(_Tp(1));} _LIBCPP_HIDE_FROM_ABI _Tp operator++(int) _NOEXCEPT { return fetch_add(_Tp(1)); }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp operator--(int) volatile _NOEXCEPT { return fetch_sub(_Tp(1)); }
_Tp operator++(int) _NOEXCEPT {return fetch_add(_Tp(1));} _LIBCPP_HIDE_FROM_ABI _Tp operator--(int) _NOEXCEPT { return fetch_sub(_Tp(1)); }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp operator++() volatile _NOEXCEPT { return fetch_add(_Tp(1)) + _Tp(1); }
_Tp operator--(int) volatile _NOEXCEPT {return fetch_sub(_Tp(1));} _LIBCPP_HIDE_FROM_ABI _Tp operator++() _NOEXCEPT { return fetch_add(_Tp(1)) + _Tp(1); }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp operator--() volatile _NOEXCEPT { return fetch_sub(_Tp(1)) - _Tp(1); }
_Tp operator--(int) _NOEXCEPT {return fetch_sub(_Tp(1));} _LIBCPP_HIDE_FROM_ABI _Tp operator--() _NOEXCEPT { return fetch_sub(_Tp(1)) - _Tp(1); }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp operator+=(_Tp __op) volatile _NOEXCEPT { return fetch_add(__op) + __op; }
_Tp operator++() volatile _NOEXCEPT {return fetch_add(_Tp(1)) + _Tp(1);} _LIBCPP_HIDE_FROM_ABI _Tp operator+=(_Tp __op) _NOEXCEPT { return fetch_add(__op) + __op; }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp operator-=(_Tp __op) volatile _NOEXCEPT { return fetch_sub(__op) - __op; }
_Tp operator++() _NOEXCEPT {return fetch_add(_Tp(1)) + _Tp(1);} _LIBCPP_HIDE_FROM_ABI _Tp operator-=(_Tp __op) _NOEXCEPT { return fetch_sub(__op) - __op; }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp operator&=(_Tp __op) volatile _NOEXCEPT { return fetch_and(__op) & __op; }
_Tp operator--() volatile _NOEXCEPT {return fetch_sub(_Tp(1)) - _Tp(1);} _LIBCPP_HIDE_FROM_ABI _Tp operator&=(_Tp __op) _NOEXCEPT { return fetch_and(__op) & __op; }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp operator|=(_Tp __op) volatile _NOEXCEPT { return fetch_or(__op) | __op; }
_Tp operator--() _NOEXCEPT {return fetch_sub(_Tp(1)) - _Tp(1);} _LIBCPP_HIDE_FROM_ABI _Tp operator|=(_Tp __op) _NOEXCEPT { return fetch_or(__op) | __op; }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp operator^=(_Tp __op) volatile _NOEXCEPT { return fetch_xor(__op) ^ __op; }
_Tp operator+=(_Tp __op) volatile _NOEXCEPT {return fetch_add(__op) + __op;} _LIBCPP_HIDE_FROM_ABI _Tp operator^=(_Tp __op) _NOEXCEPT { return fetch_xor(__op) ^ __op; }
_LIBCPP_HIDE_FROM_ABI
_Tp operator+=(_Tp __op) _NOEXCEPT {return fetch_add(__op) + __op;}
_LIBCPP_HIDE_FROM_ABI
_Tp operator-=(_Tp __op) volatile _NOEXCEPT {return fetch_sub(__op) - __op;}
_LIBCPP_HIDE_FROM_ABI
_Tp operator-=(_Tp __op) _NOEXCEPT {return fetch_sub(__op) - __op;}
_LIBCPP_HIDE_FROM_ABI
_Tp operator&=(_Tp __op) volatile _NOEXCEPT {return fetch_and(__op) & __op;}
_LIBCPP_HIDE_FROM_ABI
_Tp operator&=(_Tp __op) _NOEXCEPT {return fetch_and(__op) & __op;}
_LIBCPP_HIDE_FROM_ABI
_Tp operator|=(_Tp __op) volatile _NOEXCEPT {return fetch_or(__op) | __op;}
_LIBCPP_HIDE_FROM_ABI
_Tp operator|=(_Tp __op) _NOEXCEPT {return fetch_or(__op) | __op;}
_LIBCPP_HIDE_FROM_ABI
_Tp operator^=(_Tp __op) volatile _NOEXCEPT {return fetch_xor(__op) ^ __op;}
_LIBCPP_HIDE_FROM_ABI
_Tp operator^=(_Tp __op) _NOEXCEPT {return fetch_xor(__op) ^ __op;}
}; };
_LIBCPP_END_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD

View File

@ -24,204 +24,134 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
struct atomic_flag struct atomic_flag {
{
__cxx_atomic_impl<_LIBCPP_ATOMIC_FLAG_TYPE> __a_; __cxx_atomic_impl<_LIBCPP_ATOMIC_FLAG_TYPE> __a_;
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI bool test(memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT {
bool test(memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT return _LIBCPP_ATOMIC_FLAG_TYPE(true) == __cxx_atomic_load(&__a_, __m);
{return _LIBCPP_ATOMIC_FLAG_TYPE(true) == __cxx_atomic_load(&__a_, __m);} }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI bool test(memory_order __m = memory_order_seq_cst) const _NOEXCEPT {
bool test(memory_order __m = memory_order_seq_cst) const _NOEXCEPT return _LIBCPP_ATOMIC_FLAG_TYPE(true) == __cxx_atomic_load(&__a_, __m);
{return _LIBCPP_ATOMIC_FLAG_TYPE(true) == __cxx_atomic_load(&__a_, __m);} }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI bool test_and_set(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT {
bool test_and_set(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT return __cxx_atomic_exchange(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(true), __m);
{return __cxx_atomic_exchange(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(true), __m);} }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI bool test_and_set(memory_order __m = memory_order_seq_cst) _NOEXCEPT {
bool test_and_set(memory_order __m = memory_order_seq_cst) _NOEXCEPT return __cxx_atomic_exchange(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(true), __m);
{return __cxx_atomic_exchange(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(true), __m);} }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI void clear(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT {
void clear(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT __cxx_atomic_store(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(false), __m);
{__cxx_atomic_store(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(false), __m);} }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI void clear(memory_order __m = memory_order_seq_cst) _NOEXCEPT {
void clear(memory_order __m = memory_order_seq_cst) _NOEXCEPT __cxx_atomic_store(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(false), __m);
{__cxx_atomic_store(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(false), __m);} }
_LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void wait(bool __v, memory_order __m = memory_order_seq_cst) const
void wait(bool __v, memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT volatile _NOEXCEPT {
{__cxx_atomic_wait(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(__v), __m);} __cxx_atomic_wait(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(__v), __m);
_LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI }
void wait(bool __v, memory_order __m = memory_order_seq_cst) const _NOEXCEPT _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void
{__cxx_atomic_wait(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(__v), __m);} wait(bool __v, memory_order __m = memory_order_seq_cst) const _NOEXCEPT {
_LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI __cxx_atomic_wait(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(__v), __m);
void notify_one() volatile _NOEXCEPT }
{__cxx_atomic_notify_one(&__a_);} _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_one() volatile _NOEXCEPT {
_LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI __cxx_atomic_notify_one(&__a_);
void notify_one() _NOEXCEPT }
{__cxx_atomic_notify_one(&__a_);} _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_one() _NOEXCEPT { __cxx_atomic_notify_one(&__a_); }
_LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_all() volatile _NOEXCEPT {
void notify_all() volatile _NOEXCEPT __cxx_atomic_notify_all(&__a_);
{__cxx_atomic_notify_all(&__a_);} }
_LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_all() _NOEXCEPT { __cxx_atomic_notify_all(&__a_); }
void notify_all() _NOEXCEPT
{__cxx_atomic_notify_all(&__a_);}
#if _LIBCPP_STD_VER >= 20 #if _LIBCPP_STD_VER >= 20
_LIBCPP_HIDE_FROM_ABI constexpr _LIBCPP_HIDE_FROM_ABI constexpr atomic_flag() _NOEXCEPT : __a_(false) {}
atomic_flag() _NOEXCEPT : __a_(false) {}
#else #else
atomic_flag() _NOEXCEPT = default; atomic_flag() _NOEXCEPT = default;
#endif #endif
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR atomic_flag(bool __b) _NOEXCEPT : __a_(__b) {} // EXTENSION
atomic_flag(bool __b) _NOEXCEPT : __a_(__b) {} // EXTENSION
atomic_flag(const atomic_flag&) = delete; atomic_flag(const atomic_flag&) = delete;
atomic_flag& operator=(const atomic_flag&) = delete; atomic_flag& operator=(const atomic_flag&) = delete;
atomic_flag& operator=(const atomic_flag&) volatile = delete; atomic_flag& operator=(const atomic_flag&) volatile = delete;
}; };
inline _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_HIDE_FROM_ABI bool atomic_flag_test(const volatile atomic_flag* __o) _NOEXCEPT { return __o->test(); }
bool
atomic_flag_test(const volatile atomic_flag* __o) _NOEXCEPT
{
return __o->test();
}
inline _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_HIDE_FROM_ABI bool atomic_flag_test(const atomic_flag* __o) _NOEXCEPT { return __o->test(); }
bool
atomic_flag_test(const atomic_flag* __o) _NOEXCEPT
{
return __o->test();
}
inline _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_HIDE_FROM_ABI bool
bool atomic_flag_test_explicit(const volatile atomic_flag* __o, memory_order __m) _NOEXCEPT {
atomic_flag_test_explicit(const volatile atomic_flag* __o, memory_order __m) _NOEXCEPT
{
return __o->test(__m); return __o->test(__m);
} }
inline _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_HIDE_FROM_ABI bool atomic_flag_test_explicit(const atomic_flag* __o, memory_order __m) _NOEXCEPT {
bool
atomic_flag_test_explicit(const atomic_flag* __o, memory_order __m) _NOEXCEPT
{
return __o->test(__m); return __o->test(__m);
} }
inline _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_HIDE_FROM_ABI bool atomic_flag_test_and_set(volatile atomic_flag* __o) _NOEXCEPT {
bool
atomic_flag_test_and_set(volatile atomic_flag* __o) _NOEXCEPT
{
return __o->test_and_set(); return __o->test_and_set();
} }
inline _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_HIDE_FROM_ABI bool atomic_flag_test_and_set(atomic_flag* __o) _NOEXCEPT { return __o->test_and_set(); }
bool
atomic_flag_test_and_set(atomic_flag* __o) _NOEXCEPT
{
return __o->test_and_set();
}
inline _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_HIDE_FROM_ABI bool
bool atomic_flag_test_and_set_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT {
atomic_flag_test_and_set_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT
{
return __o->test_and_set(__m); return __o->test_and_set(__m);
} }
inline _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_HIDE_FROM_ABI bool atomic_flag_test_and_set_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT {
bool
atomic_flag_test_and_set_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT
{
return __o->test_and_set(__m); return __o->test_and_set(__m);
} }
inline _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_HIDE_FROM_ABI void atomic_flag_clear(volatile atomic_flag* __o) _NOEXCEPT { __o->clear(); }
void
atomic_flag_clear(volatile atomic_flag* __o) _NOEXCEPT
{
__o->clear();
}
inline _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_HIDE_FROM_ABI void atomic_flag_clear(atomic_flag* __o) _NOEXCEPT { __o->clear(); }
void
atomic_flag_clear(atomic_flag* __o) _NOEXCEPT
{
__o->clear();
}
inline _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_HIDE_FROM_ABI void atomic_flag_clear_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT {
void
atomic_flag_clear_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT
{
__o->clear(__m); __o->clear(__m);
} }
inline _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_HIDE_FROM_ABI void atomic_flag_clear_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT {
void
atomic_flag_clear_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT
{
__o->clear(__m); __o->clear(__m);
} }
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void
void atomic_flag_wait(const volatile atomic_flag* __o, bool __v) _NOEXCEPT {
atomic_flag_wait(const volatile atomic_flag* __o, bool __v) _NOEXCEPT
{
__o->wait(__v); __o->wait(__v);
} }
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void
void atomic_flag_wait(const atomic_flag* __o, bool __v) _NOEXCEPT {
atomic_flag_wait(const atomic_flag* __o, bool __v) _NOEXCEPT
{
__o->wait(__v); __o->wait(__v);
} }
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void
void atomic_flag_wait_explicit(const volatile atomic_flag* __o, bool __v, memory_order __m) _NOEXCEPT {
atomic_flag_wait_explicit(const volatile atomic_flag* __o,
bool __v, memory_order __m) _NOEXCEPT
{
__o->wait(__v, __m); __o->wait(__v, __m);
} }
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void
void atomic_flag_wait_explicit(const atomic_flag* __o, bool __v, memory_order __m) _NOEXCEPT {
atomic_flag_wait_explicit(const atomic_flag* __o,
bool __v, memory_order __m) _NOEXCEPT
{
__o->wait(__v, __m); __o->wait(__v, __m);
} }
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void
void atomic_flag_notify_one(volatile atomic_flag* __o) _NOEXCEPT {
atomic_flag_notify_one(volatile atomic_flag* __o) _NOEXCEPT
{
__o->notify_one(); __o->notify_one();
} }
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void atomic_flag_notify_one(atomic_flag* __o) _NOEXCEPT {
void
atomic_flag_notify_one(atomic_flag* __o) _NOEXCEPT
{
__o->notify_one(); __o->notify_one();
} }
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void
void atomic_flag_notify_all(volatile atomic_flag* __o) _NOEXCEPT {
atomic_flag_notify_all(volatile atomic_flag* __o) _NOEXCEPT
{
__o->notify_all(); __o->notify_all();
} }
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void atomic_flag_notify_all(atomic_flag* __o) _NOEXCEPT {
void
atomic_flag_notify_all(atomic_flag* __o) _NOEXCEPT
{
__o->notify_all(); __o->notify_all();
} }

View File

@ -18,9 +18,9 @@
#if defined(__CLANG_ATOMIC_BOOL_LOCK_FREE) #if defined(__CLANG_ATOMIC_BOOL_LOCK_FREE)
# define ATOMIC_BOOL_LOCK_FREE __CLANG_ATOMIC_BOOL_LOCK_FREE # define ATOMIC_BOOL_LOCK_FREE __CLANG_ATOMIC_BOOL_LOCK_FREE
# define ATOMIC_CHAR_LOCK_FREE __CLANG_ATOMIC_CHAR_LOCK_FREE # define ATOMIC_CHAR_LOCK_FREE __CLANG_ATOMIC_CHAR_LOCK_FREE
#ifndef _LIBCPP_HAS_NO_CHAR8_T # ifndef _LIBCPP_HAS_NO_CHAR8_T
# define ATOMIC_CHAR8_T_LOCK_FREE __CLANG_ATOMIC_CHAR8_T_LOCK_FREE # define ATOMIC_CHAR8_T_LOCK_FREE __CLANG_ATOMIC_CHAR8_T_LOCK_FREE
#endif # endif
# define ATOMIC_CHAR16_T_LOCK_FREE __CLANG_ATOMIC_CHAR16_T_LOCK_FREE # define ATOMIC_CHAR16_T_LOCK_FREE __CLANG_ATOMIC_CHAR16_T_LOCK_FREE
# define ATOMIC_CHAR32_T_LOCK_FREE __CLANG_ATOMIC_CHAR32_T_LOCK_FREE # define ATOMIC_CHAR32_T_LOCK_FREE __CLANG_ATOMIC_CHAR32_T_LOCK_FREE
# define ATOMIC_WCHAR_T_LOCK_FREE __CLANG_ATOMIC_WCHAR_T_LOCK_FREE # define ATOMIC_WCHAR_T_LOCK_FREE __CLANG_ATOMIC_WCHAR_T_LOCK_FREE
@ -32,9 +32,9 @@
#elif defined(__GCC_ATOMIC_BOOL_LOCK_FREE) #elif defined(__GCC_ATOMIC_BOOL_LOCK_FREE)
# define ATOMIC_BOOL_LOCK_FREE __GCC_ATOMIC_BOOL_LOCK_FREE # define ATOMIC_BOOL_LOCK_FREE __GCC_ATOMIC_BOOL_LOCK_FREE
# define ATOMIC_CHAR_LOCK_FREE __GCC_ATOMIC_CHAR_LOCK_FREE # define ATOMIC_CHAR_LOCK_FREE __GCC_ATOMIC_CHAR_LOCK_FREE
#ifndef _LIBCPP_HAS_NO_CHAR8_T # ifndef _LIBCPP_HAS_NO_CHAR8_T
# define ATOMIC_CHAR8_T_LOCK_FREE __GCC_ATOMIC_CHAR8_T_LOCK_FREE # define ATOMIC_CHAR8_T_LOCK_FREE __GCC_ATOMIC_CHAR8_T_LOCK_FREE
#endif # endif
# define ATOMIC_CHAR16_T_LOCK_FREE __GCC_ATOMIC_CHAR16_T_LOCK_FREE # define ATOMIC_CHAR16_T_LOCK_FREE __GCC_ATOMIC_CHAR16_T_LOCK_FREE
# define ATOMIC_CHAR32_T_LOCK_FREE __GCC_ATOMIC_CHAR32_T_LOCK_FREE # define ATOMIC_CHAR32_T_LOCK_FREE __GCC_ATOMIC_CHAR32_T_LOCK_FREE
# define ATOMIC_WCHAR_T_LOCK_FREE __GCC_ATOMIC_WCHAR_T_LOCK_FREE # define ATOMIC_WCHAR_T_LOCK_FREE __GCC_ATOMIC_WCHAR_T_LOCK_FREE

View File

@ -34,37 +34,36 @@ _LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI void __cxx_atomic_notify_all
_LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI __cxx_contention_t __libcpp_atomic_monitor(void const volatile*); _LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI __cxx_contention_t __libcpp_atomic_monitor(void const volatile*);
_LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI void __libcpp_atomic_wait(void const volatile*, __cxx_contention_t); _LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI void __libcpp_atomic_wait(void const volatile*, __cxx_contention_t);
_LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI void __cxx_atomic_notify_one(__cxx_atomic_contention_t const volatile*); _LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI void
_LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI void __cxx_atomic_notify_all(__cxx_atomic_contention_t const volatile*); __cxx_atomic_notify_one(__cxx_atomic_contention_t const volatile*);
_LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI __cxx_contention_t __libcpp_atomic_monitor(__cxx_atomic_contention_t const volatile*); _LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI void
_LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI void __libcpp_atomic_wait(__cxx_atomic_contention_t const volatile*, __cxx_contention_t); __cxx_atomic_notify_all(__cxx_atomic_contention_t const volatile*);
_LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI __cxx_contention_t
__libcpp_atomic_monitor(__cxx_atomic_contention_t const volatile*);
_LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI void
__libcpp_atomic_wait(__cxx_atomic_contention_t const volatile*, __cxx_contention_t);
template <class _Atp, class _Fn> template <class _Atp, class _Fn>
struct __libcpp_atomic_wait_backoff_impl { struct __libcpp_atomic_wait_backoff_impl {
_Atp* __a; _Atp* __a;
_Fn __test_fn; _Fn __test_fn;
_LIBCPP_AVAILABILITY_SYNC _LIBCPP_AVAILABILITY_SYNC
_LIBCPP_HIDE_FROM_ABI bool operator()(chrono::nanoseconds __elapsed) const _LIBCPP_HIDE_FROM_ABI bool operator()(chrono::nanoseconds __elapsed) const {
{ if (__elapsed > chrono::microseconds(64)) {
if(__elapsed > chrono::microseconds(64))
{
auto const __monitor = std::__libcpp_atomic_monitor(__a); auto const __monitor = std::__libcpp_atomic_monitor(__a);
if(__test_fn()) if (__test_fn())
return true; return true;
std::__libcpp_atomic_wait(__a, __monitor); std::__libcpp_atomic_wait(__a, __monitor);
} } else if (__elapsed > chrono::microseconds(4))
else if(__elapsed > chrono::microseconds(4))
__libcpp_thread_yield(); __libcpp_thread_yield();
else else {
{} // poll } // poll
return false; return false;
} }
}; };
template <class _Atp, class _Fn> template <class _Atp, class _Fn>
_LIBCPP_AVAILABILITY_SYNC _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_wait(_Atp* __a, _Fn&& __test_fn) {
_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_wait(_Atp* __a, _Fn && __test_fn)
{
__libcpp_atomic_wait_backoff_impl<_Atp, __decay_t<_Fn> > __backoff_fn = {__a, __test_fn}; __libcpp_atomic_wait_backoff_impl<_Atp, __decay_t<_Fn> > __backoff_fn = {__a, __test_fn};
return std::__libcpp_thread_poll_with_backoff(__test_fn, __backoff_fn); return std::__libcpp_thread_poll_with_backoff(__test_fn, __backoff_fn);
} }
@ -72,19 +71,18 @@ _LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_wait(_Atp* __a, _Fn && __test_fn)
#else // _LIBCPP_HAS_NO_THREADS #else // _LIBCPP_HAS_NO_THREADS
template <class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI void __cxx_atomic_notify_all(__cxx_atomic_impl<_Tp> const volatile*) { } _LIBCPP_HIDE_FROM_ABI void __cxx_atomic_notify_all(__cxx_atomic_impl<_Tp> const volatile*) {}
template <class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI void __cxx_atomic_notify_one(__cxx_atomic_impl<_Tp> const volatile*) { } _LIBCPP_HIDE_FROM_ABI void __cxx_atomic_notify_one(__cxx_atomic_impl<_Tp> const volatile*) {}
template <class _Atp, class _Fn> template <class _Atp, class _Fn>
_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_wait(_Atp*, _Fn && __test_fn) _LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_wait(_Atp*, _Fn&& __test_fn) {
{
return std::__libcpp_thread_poll_with_backoff(__test_fn, __spinning_backoff_policy()); return std::__libcpp_thread_poll_with_backoff(__test_fn, __spinning_backoff_policy());
} }
#endif // _LIBCPP_HAS_NO_THREADS #endif // _LIBCPP_HAS_NO_THREADS
template <typename _Tp> _LIBCPP_HIDE_FROM_ABI template <typename _Tp>
bool __cxx_nonatomic_compare_equal(_Tp const& __lhs, _Tp const& __rhs) { _LIBCPP_HIDE_FROM_ABI bool __cxx_nonatomic_compare_equal(_Tp const& __lhs, _Tp const& __rhs) {
return std::memcmp(std::addressof(__lhs), std::addressof(__rhs), sizeof(_Tp)) == 0; return std::memcmp(std::addressof(__lhs), std::addressof(__rhs), sizeof(_Tp)) == 0;
} }
@ -93,16 +91,14 @@ struct __cxx_atomic_wait_test_fn_impl {
_Atp* __a; _Atp* __a;
_Tp __val; _Tp __val;
memory_order __order; memory_order __order;
_LIBCPP_HIDE_FROM_ABI bool operator()() const _LIBCPP_HIDE_FROM_ABI bool operator()() const {
{
return !std::__cxx_nonatomic_compare_equal(std::__cxx_atomic_load(__a, __order), __val); return !std::__cxx_nonatomic_compare_equal(std::__cxx_atomic_load(__a, __order), __val);
} }
}; };
template <class _Atp, class _Tp> template <class _Atp, class _Tp>
_LIBCPP_AVAILABILITY_SYNC _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI bool
_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_wait(_Atp* __a, _Tp const __val, memory_order __order) __cxx_atomic_wait(_Atp* __a, _Tp const __val, memory_order __order) {
{
__cxx_atomic_wait_test_fn_impl<_Atp, _Tp> __test_fn = {__a, __val, __order}; __cxx_atomic_wait_test_fn_impl<_Atp, _Tp> __test_fn = {__a, __val, __order};
return std::__cxx_atomic_wait(__a, __test_fn); return std::__cxx_atomic_wait(__a, __test_fn);
} }

View File

@ -16,19 +16,15 @@
#endif #endif
#define _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) \ #define _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) \
_LIBCPP_DIAGNOSE_WARNING(__m == memory_order_consume || \ _LIBCPP_DIAGNOSE_WARNING(__m == memory_order_consume || __m == memory_order_acquire || __m == memory_order_acq_rel, \
__m == memory_order_acquire || \
__m == memory_order_acq_rel, \
"memory order argument to atomic operation is invalid") "memory order argument to atomic operation is invalid")
#define _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) \ #define _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) \
_LIBCPP_DIAGNOSE_WARNING(__m == memory_order_release || \ _LIBCPP_DIAGNOSE_WARNING(__m == memory_order_release || __m == memory_order_acq_rel, \
__m == memory_order_acq_rel, \
"memory order argument to atomic operation is invalid") "memory order argument to atomic operation is invalid")
#define _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__m, __f) \ #define _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__m, __f) \
_LIBCPP_DIAGNOSE_WARNING(__f == memory_order_release || \ _LIBCPP_DIAGNOSE_WARNING(__f == memory_order_release || __f == memory_order_acq_rel, \
__f == memory_order_acq_rel, \
"memory order argument to atomic operation is invalid") "memory order argument to atomic operation is invalid")
#endif // _LIBCPP___ATOMIC_CHECK_MEMORY_ORDER_H #endif // _LIBCPP___ATOMIC_CHECK_MEMORY_ORDER_H

View File

@ -20,9 +20,9 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
#if defined(__linux__) || (defined(_AIX) && !defined(__64BIT__)) #if defined(__linux__) || (defined(_AIX) && !defined(__64BIT__))
using __cxx_contention_t = int32_t; using __cxx_contention_t = int32_t;
#else #else
using __cxx_contention_t = int64_t; using __cxx_contention_t = int64_t;
#endif // __linux__ || (_AIX && !__64BIT__) #endif // __linux__ || (_AIX && !__64BIT__)
using __cxx_atomic_contention_t = __cxx_atomic_impl<__cxx_contention_t>; using __cxx_atomic_contention_t = __cxx_atomic_impl<__cxx_contention_t>;

View File

@ -26,18 +26,17 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
#if defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) || \ #if defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) || defined(_LIBCPP_ATOMIC_ONLY_USE_BUILTINS)
defined(_LIBCPP_ATOMIC_ONLY_USE_BUILTINS)
// [atomics.types.generic]p1 guarantees _Tp is trivially copyable. Because // [atomics.types.generic]p1 guarantees _Tp is trivially copyable. Because
// the default operator= in an object is not volatile, a byte-by-byte copy // the default operator= in an object is not volatile, a byte-by-byte copy
// is required. // is required.
template <typename _Tp, typename _Tv, __enable_if_t<is_assignable<_Tp&, _Tv>::value, int> = 0> _LIBCPP_HIDE_FROM_ABI template <typename _Tp, typename _Tv, __enable_if_t<is_assignable<_Tp&, _Tv>::value, int> = 0>
void __cxx_atomic_assign_volatile(_Tp& __a_value, _Tv const& __val) { _LIBCPP_HIDE_FROM_ABI void __cxx_atomic_assign_volatile(_Tp& __a_value, _Tv const& __val) {
__a_value = __val; __a_value = __val;
} }
template <typename _Tp, typename _Tv, __enable_if_t<is_assignable<_Tp&, _Tv>::value, int> = 0> _LIBCPP_HIDE_FROM_ABI template <typename _Tp, typename _Tv, __enable_if_t<is_assignable<_Tp&, _Tv>::value, int> = 0>
void __cxx_atomic_assign_volatile(_Tp volatile& __a_value, _Tv volatile const& __val) { _LIBCPP_HIDE_FROM_ABI void __cxx_atomic_assign_volatile(_Tp volatile& __a_value, _Tv volatile const& __val) {
volatile char* __to = reinterpret_cast<volatile char*>(std::addressof(__a_value)); volatile char* __to = reinterpret_cast<volatile char*>(std::addressof(__a_value));
volatile char* __end = __to + sizeof(_Tp); volatile char* __end = __to + sizeof(_Tp);
volatile const char* __from = reinterpret_cast<volatile const char*>(std::addressof(__val)); volatile const char* __from = reinterpret_cast<volatile const char*>(std::addressof(__val));
@ -51,78 +50,74 @@ void __cxx_atomic_assign_volatile(_Tp volatile& __a_value, _Tv volatile const& _
template <typename _Tp> template <typename _Tp>
struct __cxx_atomic_base_impl { struct __cxx_atomic_base_impl {
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI
#ifndef _LIBCPP_CXX03_LANG # ifndef _LIBCPP_CXX03_LANG
__cxx_atomic_base_impl() _NOEXCEPT = default; __cxx_atomic_base_impl() _NOEXCEPT = default;
#else # else
__cxx_atomic_base_impl() _NOEXCEPT : __a_value() {} __cxx_atomic_base_impl() _NOEXCEPT : __a_value() {
#endif // _LIBCPP_CXX03_LANG }
_LIBCPP_CONSTEXPR explicit __cxx_atomic_base_impl(_Tp value) _NOEXCEPT # endif // _LIBCPP_CXX03_LANG
: __a_value(value) {} _LIBCPP_CONSTEXPR explicit __cxx_atomic_base_impl(_Tp value) _NOEXCEPT : __a_value(value) {}
_Tp __a_value; _Tp __a_value;
}; };
_LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR int __to_gcc_order(memory_order __order) { _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR int __to_gcc_order(memory_order __order) {
// Avoid switch statement to make this a constexpr. // Avoid switch statement to make this a constexpr.
return __order == memory_order_relaxed ? __ATOMIC_RELAXED: return __order == memory_order_relaxed
(__order == memory_order_acquire ? __ATOMIC_ACQUIRE: ? __ATOMIC_RELAXED
(__order == memory_order_release ? __ATOMIC_RELEASE: : (__order == memory_order_acquire
(__order == memory_order_seq_cst ? __ATOMIC_SEQ_CST: ? __ATOMIC_ACQUIRE
(__order == memory_order_acq_rel ? __ATOMIC_ACQ_REL: : (__order == memory_order_release
__ATOMIC_CONSUME)))); ? __ATOMIC_RELEASE
: (__order == memory_order_seq_cst
? __ATOMIC_SEQ_CST
: (__order == memory_order_acq_rel ? __ATOMIC_ACQ_REL : __ATOMIC_CONSUME))));
} }
_LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR int __to_gcc_failure_order(memory_order __order) { _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR int __to_gcc_failure_order(memory_order __order) {
// Avoid switch statement to make this a constexpr. // Avoid switch statement to make this a constexpr.
return __order == memory_order_relaxed ? __ATOMIC_RELAXED: return __order == memory_order_relaxed
(__order == memory_order_acquire ? __ATOMIC_ACQUIRE: ? __ATOMIC_RELAXED
(__order == memory_order_release ? __ATOMIC_RELAXED: : (__order == memory_order_acquire
(__order == memory_order_seq_cst ? __ATOMIC_SEQ_CST: ? __ATOMIC_ACQUIRE
(__order == memory_order_acq_rel ? __ATOMIC_ACQUIRE: : (__order == memory_order_release
__ATOMIC_CONSUME)))); ? __ATOMIC_RELAXED
: (__order == memory_order_seq_cst
? __ATOMIC_SEQ_CST
: (__order == memory_order_acq_rel ? __ATOMIC_ACQUIRE : __ATOMIC_CONSUME))));
} }
template <typename _Tp> template <typename _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI void __cxx_atomic_init(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __val) {
void __cxx_atomic_init(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __val) {
__cxx_atomic_assign_volatile(__a->__a_value, __val); __cxx_atomic_assign_volatile(__a->__a_value, __val);
} }
template <typename _Tp> template <typename _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI void __cxx_atomic_init(__cxx_atomic_base_impl<_Tp>* __a, _Tp __val) {
void __cxx_atomic_init(__cxx_atomic_base_impl<_Tp>* __a, _Tp __val) {
__a->__a_value = __val; __a->__a_value = __val;
} }
_LIBCPP_HIDE_FROM_ABI inline _LIBCPP_HIDE_FROM_ABI inline void __cxx_atomic_thread_fence(memory_order __order) {
void __cxx_atomic_thread_fence(memory_order __order) {
__atomic_thread_fence(__to_gcc_order(__order)); __atomic_thread_fence(__to_gcc_order(__order));
} }
_LIBCPP_HIDE_FROM_ABI inline _LIBCPP_HIDE_FROM_ABI inline void __cxx_atomic_signal_fence(memory_order __order) {
void __cxx_atomic_signal_fence(memory_order __order) {
__atomic_signal_fence(__to_gcc_order(__order)); __atomic_signal_fence(__to_gcc_order(__order));
} }
template <typename _Tp> template <typename _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI void
void __cxx_atomic_store(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __val, __cxx_atomic_store(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __val, memory_order __order) {
memory_order __order) {
__atomic_store(std::addressof(__a->__a_value), std::addressof(__val), __to_gcc_order(__order)); __atomic_store(std::addressof(__a->__a_value), std::addressof(__val), __to_gcc_order(__order));
} }
template <typename _Tp> template <typename _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI void __cxx_atomic_store(__cxx_atomic_base_impl<_Tp>* __a, _Tp __val, memory_order __order) {
void __cxx_atomic_store(__cxx_atomic_base_impl<_Tp>* __a, _Tp __val,
memory_order __order) {
__atomic_store(std::addressof(__a->__a_value), std::addressof(__val), __to_gcc_order(__order)); __atomic_store(std::addressof(__a->__a_value), std::addressof(__val), __to_gcc_order(__order));
} }
template <typename _Tp> template <typename _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_load(const volatile __cxx_atomic_base_impl<_Tp>* __a, memory_order __order) {
_Tp __cxx_atomic_load(const volatile __cxx_atomic_base_impl<_Tp>* __a,
memory_order __order) {
_Tp __ret; _Tp __ret;
__atomic_load(std::addressof(__a->__a_value), std::addressof(__ret), __to_gcc_order(__order)); __atomic_load(std::addressof(__a->__a_value), std::addressof(__ret), __to_gcc_order(__order));
return __ret; return __ret;
@ -141,17 +136,15 @@ __cxx_atomic_load_inplace(const __cxx_atomic_base_impl<_Tp>* __a, _Tp* __dst, me
} }
template <typename _Tp> template <typename _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_load(const __cxx_atomic_base_impl<_Tp>* __a, memory_order __order) {
_Tp __cxx_atomic_load(const __cxx_atomic_base_impl<_Tp>* __a, memory_order __order) {
_Tp __ret; _Tp __ret;
__atomic_load(std::addressof(__a->__a_value), std::addressof(__ret), __to_gcc_order(__order)); __atomic_load(std::addressof(__a->__a_value), std::addressof(__ret), __to_gcc_order(__order));
return __ret; return __ret;
} }
template <typename _Tp> template <typename _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp
_Tp __cxx_atomic_exchange(volatile __cxx_atomic_base_impl<_Tp>* __a, __cxx_atomic_exchange(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __value, memory_order __order) {
_Tp __value, memory_order __order) {
_Tp __ret; _Tp __ret;
__atomic_exchange( __atomic_exchange(
std::addressof(__a->__a_value), std::addressof(__value), std::addressof(__ret), __to_gcc_order(__order)); std::addressof(__a->__a_value), std::addressof(__value), std::addressof(__ret), __to_gcc_order(__order));
@ -159,9 +152,7 @@ _Tp __cxx_atomic_exchange(volatile __cxx_atomic_base_impl<_Tp>* __a,
} }
template <typename _Tp> template <typename _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_exchange(__cxx_atomic_base_impl<_Tp>* __a, _Tp __value, memory_order __order) {
_Tp __cxx_atomic_exchange(__cxx_atomic_base_impl<_Tp>* __a, _Tp __value,
memory_order __order) {
_Tp __ret; _Tp __ret;
__atomic_exchange( __atomic_exchange(
std::addressof(__a->__a_value), std::addressof(__value), std::addressof(__ret), __to_gcc_order(__order)); std::addressof(__a->__a_value), std::addressof(__value), std::addressof(__ret), __to_gcc_order(__order));
@ -169,23 +160,11 @@ _Tp __cxx_atomic_exchange(__cxx_atomic_base_impl<_Tp>* __a, _Tp __value,
} }
template <typename _Tp> template <typename _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_strong(
bool __cxx_atomic_compare_exchange_strong( volatile __cxx_atomic_base_impl<_Tp>* __a,
volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, _Tp* __expected,
memory_order __success, memory_order __failure) { _Tp __value,
return __atomic_compare_exchange( memory_order __success,
std::addressof(__a->__a_value),
__expected,
std::addressof(__value),
false,
__to_gcc_order(__success),
__to_gcc_failure_order(__failure));
}
template <typename _Tp>
_LIBCPP_HIDE_FROM_ABI
bool __cxx_atomic_compare_exchange_strong(
__cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success,
memory_order __failure) { memory_order __failure) {
return __atomic_compare_exchange( return __atomic_compare_exchange(
std::addressof(__a->__a_value), std::addressof(__a->__a_value),
@ -197,23 +176,23 @@ bool __cxx_atomic_compare_exchange_strong(
} }
template <typename _Tp> template <typename _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_strong(
bool __cxx_atomic_compare_exchange_weak( __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) {
volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value,
memory_order __success, memory_order __failure) {
return __atomic_compare_exchange( return __atomic_compare_exchange(
std::addressof(__a->__a_value), std::addressof(__a->__a_value),
__expected, __expected,
std::addressof(__value), std::addressof(__value),
true, false,
__to_gcc_order(__success), __to_gcc_order(__success),
__to_gcc_failure_order(__failure)); __to_gcc_failure_order(__failure));
} }
template <typename _Tp> template <typename _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_weak(
bool __cxx_atomic_compare_exchange_weak( volatile __cxx_atomic_base_impl<_Tp>* __a,
__cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success, _Tp* __expected,
_Tp __value,
memory_order __success,
memory_order __failure) { memory_order __failure) {
return __atomic_compare_exchange( return __atomic_compare_exchange(
std::addressof(__a->__a_value), std::addressof(__a->__a_value),
@ -225,150 +204,147 @@ bool __cxx_atomic_compare_exchange_weak(
} }
template <typename _Tp> template <typename _Tp>
struct __skip_amt { enum {value = 1}; }; _LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_weak(
__cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) {
return __atomic_compare_exchange(
std::addressof(__a->__a_value),
__expected,
std::addressof(__value),
true,
__to_gcc_order(__success),
__to_gcc_failure_order(__failure));
}
template <typename _Tp> template <typename _Tp>
struct __skip_amt<_Tp*> { enum {value = sizeof(_Tp)}; }; struct __skip_amt {
enum { value = 1 };
};
template <typename _Tp>
struct __skip_amt<_Tp*> {
enum { value = sizeof(_Tp) };
};
// FIXME: Haven't figured out what the spec says about using arrays with // FIXME: Haven't figured out what the spec says about using arrays with
// atomic_fetch_add. Force a failure rather than creating bad behavior. // atomic_fetch_add. Force a failure rather than creating bad behavior.
template <typename _Tp> template <typename _Tp>
struct __skip_amt<_Tp[]> { }; struct __skip_amt<_Tp[]> {};
template <typename _Tp, int n> template <typename _Tp, int n>
struct __skip_amt<_Tp[n]> { }; struct __skip_amt<_Tp[n]> {};
template <typename _Tp, typename _Td> template <typename _Tp, typename _Td>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp
_Tp __cxx_atomic_fetch_add(volatile __cxx_atomic_base_impl<_Tp>* __a, __cxx_atomic_fetch_add(volatile __cxx_atomic_base_impl<_Tp>* __a, _Td __delta, memory_order __order) {
_Td __delta, memory_order __order) {
return __atomic_fetch_add(std::addressof(__a->__a_value), __delta * __skip_amt<_Tp>::value, __to_gcc_order(__order)); return __atomic_fetch_add(std::addressof(__a->__a_value), __delta * __skip_amt<_Tp>::value, __to_gcc_order(__order));
} }
template <typename _Tp, typename _Td> template <typename _Tp, typename _Td>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp>* __a, _Td __delta, memory_order __order) {
_Tp __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp>* __a, _Td __delta,
memory_order __order) {
return __atomic_fetch_add(std::addressof(__a->__a_value), __delta * __skip_amt<_Tp>::value, __to_gcc_order(__order)); return __atomic_fetch_add(std::addressof(__a->__a_value), __delta * __skip_amt<_Tp>::value, __to_gcc_order(__order));
} }
template <typename _Tp, typename _Td> template <typename _Tp, typename _Td>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp
_Tp __cxx_atomic_fetch_sub(volatile __cxx_atomic_base_impl<_Tp>* __a, __cxx_atomic_fetch_sub(volatile __cxx_atomic_base_impl<_Tp>* __a, _Td __delta, memory_order __order) {
_Td __delta, memory_order __order) {
return __atomic_fetch_sub(std::addressof(__a->__a_value), __delta * __skip_amt<_Tp>::value, __to_gcc_order(__order)); return __atomic_fetch_sub(std::addressof(__a->__a_value), __delta * __skip_amt<_Tp>::value, __to_gcc_order(__order));
} }
template <typename _Tp, typename _Td> template <typename _Tp, typename _Td>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp>* __a, _Td __delta, memory_order __order) {
_Tp __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp>* __a, _Td __delta,
memory_order __order) {
return __atomic_fetch_sub(std::addressof(__a->__a_value), __delta * __skip_amt<_Tp>::value, __to_gcc_order(__order)); return __atomic_fetch_sub(std::addressof(__a->__a_value), __delta * __skip_amt<_Tp>::value, __to_gcc_order(__order));
} }
template <typename _Tp> template <typename _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp
_Tp __cxx_atomic_fetch_and(volatile __cxx_atomic_base_impl<_Tp>* __a, __cxx_atomic_fetch_and(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) {
_Tp __pattern, memory_order __order) {
return __atomic_fetch_and(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order)); return __atomic_fetch_and(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order));
} }
template <typename _Tp> template <typename _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp
_Tp __cxx_atomic_fetch_and(__cxx_atomic_base_impl<_Tp>* __a, __cxx_atomic_fetch_and(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) {
_Tp __pattern, memory_order __order) {
return __atomic_fetch_and(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order)); return __atomic_fetch_and(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order));
} }
template <typename _Tp> template <typename _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp
_Tp __cxx_atomic_fetch_or(volatile __cxx_atomic_base_impl<_Tp>* __a, __cxx_atomic_fetch_or(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) {
_Tp __pattern, memory_order __order) {
return __atomic_fetch_or(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order)); return __atomic_fetch_or(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order));
} }
template <typename _Tp> template <typename _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_fetch_or(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) {
_Tp __cxx_atomic_fetch_or(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern,
memory_order __order) {
return __atomic_fetch_or(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order)); return __atomic_fetch_or(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order));
} }
template <typename _Tp> template <typename _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp
_Tp __cxx_atomic_fetch_xor(volatile __cxx_atomic_base_impl<_Tp>* __a, __cxx_atomic_fetch_xor(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) {
_Tp __pattern, memory_order __order) {
return __atomic_fetch_xor(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order)); return __atomic_fetch_xor(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order));
} }
template <typename _Tp> template <typename _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp
_Tp __cxx_atomic_fetch_xor(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, __cxx_atomic_fetch_xor(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) {
memory_order __order) {
return __atomic_fetch_xor(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order)); return __atomic_fetch_xor(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order));
} }
#define __cxx_atomic_is_lock_free(__s) __atomic_is_lock_free(__s, 0) # define __cxx_atomic_is_lock_free(__s) __atomic_is_lock_free(__s, 0)
#elif defined(_LIBCPP_HAS_C_ATOMIC_IMP) #elif defined(_LIBCPP_HAS_C_ATOMIC_IMP)
template <typename _Tp> template <typename _Tp>
struct __cxx_atomic_base_impl { struct __cxx_atomic_base_impl {
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI
#ifndef _LIBCPP_CXX03_LANG # ifndef _LIBCPP_CXX03_LANG
__cxx_atomic_base_impl() _NOEXCEPT = default; __cxx_atomic_base_impl() _NOEXCEPT = default;
#else # else
__cxx_atomic_base_impl() _NOEXCEPT : __a_value() {} __cxx_atomic_base_impl() _NOEXCEPT : __a_value() {
#endif // _LIBCPP_CXX03_LANG }
_LIBCPP_CONSTEXPR explicit __cxx_atomic_base_impl(_Tp __value) _NOEXCEPT # endif // _LIBCPP_CXX03_LANG
: __a_value(__value) {} _LIBCPP_CONSTEXPR explicit __cxx_atomic_base_impl(_Tp __value) _NOEXCEPT : __a_value(__value) {}
_LIBCPP_DISABLE_EXTENSION_WARNING _Atomic(_Tp) __a_value; _LIBCPP_DISABLE_EXTENSION_WARNING _Atomic(_Tp) __a_value;
}; };
#define __cxx_atomic_is_lock_free(__s) __c11_atomic_is_lock_free(__s) # define __cxx_atomic_is_lock_free(__s) __c11_atomic_is_lock_free(__s)
_LIBCPP_HIDE_FROM_ABI inline _LIBCPP_HIDE_FROM_ABI inline void __cxx_atomic_thread_fence(memory_order __order) _NOEXCEPT {
void __cxx_atomic_thread_fence(memory_order __order) _NOEXCEPT {
__c11_atomic_thread_fence(static_cast<__memory_order_underlying_t>(__order)); __c11_atomic_thread_fence(static_cast<__memory_order_underlying_t>(__order));
} }
_LIBCPP_HIDE_FROM_ABI inline _LIBCPP_HIDE_FROM_ABI inline void __cxx_atomic_signal_fence(memory_order __order) _NOEXCEPT {
void __cxx_atomic_signal_fence(memory_order __order) _NOEXCEPT {
__c11_atomic_signal_fence(static_cast<__memory_order_underlying_t>(__order)); __c11_atomic_signal_fence(static_cast<__memory_order_underlying_t>(__order));
} }
template<class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI void __cxx_atomic_init(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __val) _NOEXCEPT {
void __cxx_atomic_init(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __val) _NOEXCEPT {
__c11_atomic_init(std::addressof(__a->__a_value), __val); __c11_atomic_init(std::addressof(__a->__a_value), __val);
} }
template<class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI void __cxx_atomic_init(__cxx_atomic_base_impl<_Tp>* __a, _Tp __val) _NOEXCEPT {
void __cxx_atomic_init(__cxx_atomic_base_impl<_Tp> * __a, _Tp __val) _NOEXCEPT {
__c11_atomic_init(std::addressof(__a->__a_value), __val); __c11_atomic_init(std::addressof(__a->__a_value), __val);
} }
template<class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI void
void __cxx_atomic_store(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __val, memory_order __order) _NOEXCEPT { __cxx_atomic_store(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __val, memory_order __order) _NOEXCEPT {
__c11_atomic_store(std::addressof(__a->__a_value), __val, static_cast<__memory_order_underlying_t>(__order)); __c11_atomic_store(std::addressof(__a->__a_value), __val, static_cast<__memory_order_underlying_t>(__order));
} }
template<class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI void
void __cxx_atomic_store(__cxx_atomic_base_impl<_Tp> * __a, _Tp __val, memory_order __order) _NOEXCEPT { __cxx_atomic_store(__cxx_atomic_base_impl<_Tp>* __a, _Tp __val, memory_order __order) _NOEXCEPT {
__c11_atomic_store(std::addressof(__a->__a_value), __val, static_cast<__memory_order_underlying_t>(__order)); __c11_atomic_store(std::addressof(__a->__a_value), __val, static_cast<__memory_order_underlying_t>(__order));
} }
template<class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp
_Tp __cxx_atomic_load(__cxx_atomic_base_impl<_Tp> const volatile* __a, memory_order __order) _NOEXCEPT { __cxx_atomic_load(__cxx_atomic_base_impl<_Tp> const volatile* __a, memory_order __order) _NOEXCEPT {
using __ptr_type = __remove_const_t<decltype(__a->__a_value)>*; using __ptr_type = __remove_const_t<decltype(__a->__a_value)>*;
return __c11_atomic_load( return __c11_atomic_load(
const_cast<__ptr_type>(std::addressof(__a->__a_value)), static_cast<__memory_order_underlying_t>(__order)); const_cast<__ptr_type>(std::addressof(__a->__a_value)), static_cast<__memory_order_underlying_t>(__order));
} }
template<class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_load(__cxx_atomic_base_impl<_Tp> const* __a, memory_order __order) _NOEXCEPT {
_Tp __cxx_atomic_load(__cxx_atomic_base_impl<_Tp> const* __a, memory_order __order) _NOEXCEPT {
using __ptr_type = __remove_const_t<decltype(__a->__a_value)>*; using __ptr_type = __remove_const_t<decltype(__a->__a_value)>*;
return __c11_atomic_load( return __c11_atomic_load(
const_cast<__ptr_type>(std::addressof(__a->__a_value)), static_cast<__memory_order_underlying_t>(__order)); const_cast<__ptr_type>(std::addressof(__a->__a_value)), static_cast<__memory_order_underlying_t>(__order));
@ -389,29 +365,33 @@ __cxx_atomic_load_inplace(__cxx_atomic_base_impl<_Tp> const* __a, _Tp* __dst, me
const_cast<__ptr_type>(std::addressof(__a->__a_value)), static_cast<__memory_order_underlying_t>(__order)); const_cast<__ptr_type>(std::addressof(__a->__a_value)), static_cast<__memory_order_underlying_t>(__order));
} }
template<class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp
_Tp __cxx_atomic_exchange(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __value, memory_order __order) _NOEXCEPT { __cxx_atomic_exchange(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __value, memory_order __order) _NOEXCEPT {
return __c11_atomic_exchange( return __c11_atomic_exchange(
std::addressof(__a->__a_value), __value, static_cast<__memory_order_underlying_t>(__order)); std::addressof(__a->__a_value), __value, static_cast<__memory_order_underlying_t>(__order));
} }
template<class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp
_Tp __cxx_atomic_exchange(__cxx_atomic_base_impl<_Tp> * __a, _Tp __value, memory_order __order) _NOEXCEPT { __cxx_atomic_exchange(__cxx_atomic_base_impl<_Tp>* __a, _Tp __value, memory_order __order) _NOEXCEPT {
return __c11_atomic_exchange( return __c11_atomic_exchange(
std::addressof(__a->__a_value), __value, static_cast<__memory_order_underlying_t>(__order)); std::addressof(__a->__a_value), __value, static_cast<__memory_order_underlying_t>(__order));
} }
_LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR memory_order __to_failure_order(memory_order __order) { _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR memory_order __to_failure_order(memory_order __order) {
// Avoid switch statement to make this a constexpr. // Avoid switch statement to make this a constexpr.
return __order == memory_order_release ? memory_order_relaxed: return __order == memory_order_release
(__order == memory_order_acq_rel ? memory_order_acquire: ? memory_order_relaxed
__order); : (__order == memory_order_acq_rel ? memory_order_acquire : __order);
} }
template<class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_strong(
bool __cxx_atomic_compare_exchange_strong(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) _NOEXCEPT { __cxx_atomic_base_impl<_Tp> volatile* __a,
_Tp* __expected,
_Tp __value,
memory_order __success,
memory_order __failure) _NOEXCEPT {
return __c11_atomic_compare_exchange_strong( return __c11_atomic_compare_exchange_strong(
std::addressof(__a->__a_value), std::addressof(__a->__a_value),
__expected, __expected,
@ -419,9 +399,10 @@ bool __cxx_atomic_compare_exchange_strong(__cxx_atomic_base_impl<_Tp> volatile*
static_cast<__memory_order_underlying_t>(__success), static_cast<__memory_order_underlying_t>(__success),
static_cast<__memory_order_underlying_t>(__to_failure_order(__failure))); static_cast<__memory_order_underlying_t>(__to_failure_order(__failure)));
} }
template<class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_strong(
bool __cxx_atomic_compare_exchange_strong(__cxx_atomic_base_impl<_Tp> * __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) _NOEXCEPT { __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure)
_NOEXCEPT {
return __c11_atomic_compare_exchange_strong( return __c11_atomic_compare_exchange_strong(
std::addressof(__a->__a_value), std::addressof(__a->__a_value),
__expected, __expected,
@ -430,9 +411,13 @@ bool __cxx_atomic_compare_exchange_strong(__cxx_atomic_base_impl<_Tp> * __a, _Tp
static_cast<__memory_order_underlying_t>(__to_failure_order(__failure))); static_cast<__memory_order_underlying_t>(__to_failure_order(__failure)));
} }
template<class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_weak(
bool __cxx_atomic_compare_exchange_weak(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) _NOEXCEPT { __cxx_atomic_base_impl<_Tp> volatile* __a,
_Tp* __expected,
_Tp __value,
memory_order __success,
memory_order __failure) _NOEXCEPT {
return __c11_atomic_compare_exchange_weak( return __c11_atomic_compare_exchange_weak(
std::addressof(__a->__a_value), std::addressof(__a->__a_value),
__expected, __expected,
@ -440,9 +425,10 @@ bool __cxx_atomic_compare_exchange_weak(__cxx_atomic_base_impl<_Tp> volatile* __
static_cast<__memory_order_underlying_t>(__success), static_cast<__memory_order_underlying_t>(__success),
static_cast<__memory_order_underlying_t>(__to_failure_order(__failure))); static_cast<__memory_order_underlying_t>(__to_failure_order(__failure)));
} }
template<class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_weak(
bool __cxx_atomic_compare_exchange_weak(__cxx_atomic_base_impl<_Tp> * __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) _NOEXCEPT { __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure)
_NOEXCEPT {
return __c11_atomic_compare_exchange_weak( return __c11_atomic_compare_exchange_weak(
std::addressof(__a->__a_value), std::addressof(__a->__a_value),
__expected, __expected,
@ -451,92 +437,92 @@ bool __cxx_atomic_compare_exchange_weak(__cxx_atomic_base_impl<_Tp> * __a, _Tp*
static_cast<__memory_order_underlying_t>(__to_failure_order(__failure))); static_cast<__memory_order_underlying_t>(__to_failure_order(__failure)));
} }
template<class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp
_Tp __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __delta, memory_order __order) _NOEXCEPT { __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __delta, memory_order __order) _NOEXCEPT {
return __c11_atomic_fetch_add( return __c11_atomic_fetch_add(
std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order)); std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order));
} }
template<class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp
_Tp __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp> * __a, _Tp __delta, memory_order __order) _NOEXCEPT { __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp>* __a, _Tp __delta, memory_order __order) _NOEXCEPT {
return __c11_atomic_fetch_add( return __c11_atomic_fetch_add(
std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order)); std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order));
} }
template<class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp*
_Tp* __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp*> volatile* __a, ptrdiff_t __delta, memory_order __order) _NOEXCEPT { __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp*> volatile* __a, ptrdiff_t __delta, memory_order __order) _NOEXCEPT {
return __c11_atomic_fetch_add( return __c11_atomic_fetch_add(
std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order)); std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order));
} }
template<class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp*
_Tp* __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp*> * __a, ptrdiff_t __delta, memory_order __order) _NOEXCEPT { __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp*>* __a, ptrdiff_t __delta, memory_order __order) _NOEXCEPT {
return __c11_atomic_fetch_add( return __c11_atomic_fetch_add(
std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order)); std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order));
} }
template<class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp
_Tp __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __delta, memory_order __order) _NOEXCEPT { __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __delta, memory_order __order) _NOEXCEPT {
return __c11_atomic_fetch_sub( return __c11_atomic_fetch_sub(
std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order)); std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order));
} }
template<class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp
_Tp __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp> * __a, _Tp __delta, memory_order __order) _NOEXCEPT { __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp>* __a, _Tp __delta, memory_order __order) _NOEXCEPT {
return __c11_atomic_fetch_sub( return __c11_atomic_fetch_sub(
std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order)); std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order));
} }
template<class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp*
_Tp* __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp*> volatile* __a, ptrdiff_t __delta, memory_order __order) _NOEXCEPT { __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp*> volatile* __a, ptrdiff_t __delta, memory_order __order) _NOEXCEPT {
return __c11_atomic_fetch_sub( return __c11_atomic_fetch_sub(
std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order)); std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order));
} }
template<class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp*
_Tp* __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp*> * __a, ptrdiff_t __delta, memory_order __order) _NOEXCEPT { __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp*>* __a, ptrdiff_t __delta, memory_order __order) _NOEXCEPT {
return __c11_atomic_fetch_sub( return __c11_atomic_fetch_sub(
std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order)); std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order));
} }
template<class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp
_Tp __cxx_atomic_fetch_and(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __pattern, memory_order __order) _NOEXCEPT { __cxx_atomic_fetch_and(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __pattern, memory_order __order) _NOEXCEPT {
return __c11_atomic_fetch_and( return __c11_atomic_fetch_and(
std::addressof(__a->__a_value), __pattern, static_cast<__memory_order_underlying_t>(__order)); std::addressof(__a->__a_value), __pattern, static_cast<__memory_order_underlying_t>(__order));
} }
template<class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp
_Tp __cxx_atomic_fetch_and(__cxx_atomic_base_impl<_Tp> * __a, _Tp __pattern, memory_order __order) _NOEXCEPT { __cxx_atomic_fetch_and(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) _NOEXCEPT {
return __c11_atomic_fetch_and( return __c11_atomic_fetch_and(
std::addressof(__a->__a_value), __pattern, static_cast<__memory_order_underlying_t>(__order)); std::addressof(__a->__a_value), __pattern, static_cast<__memory_order_underlying_t>(__order));
} }
template<class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp
_Tp __cxx_atomic_fetch_or(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __pattern, memory_order __order) _NOEXCEPT { __cxx_atomic_fetch_or(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __pattern, memory_order __order) _NOEXCEPT {
return __c11_atomic_fetch_or( return __c11_atomic_fetch_or(
std::addressof(__a->__a_value), __pattern, static_cast<__memory_order_underlying_t>(__order)); std::addressof(__a->__a_value), __pattern, static_cast<__memory_order_underlying_t>(__order));
} }
template<class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp
_Tp __cxx_atomic_fetch_or(__cxx_atomic_base_impl<_Tp> * __a, _Tp __pattern, memory_order __order) _NOEXCEPT { __cxx_atomic_fetch_or(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) _NOEXCEPT {
return __c11_atomic_fetch_or( return __c11_atomic_fetch_or(
std::addressof(__a->__a_value), __pattern, static_cast<__memory_order_underlying_t>(__order)); std::addressof(__a->__a_value), __pattern, static_cast<__memory_order_underlying_t>(__order));
} }
template<class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp
_Tp __cxx_atomic_fetch_xor(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __pattern, memory_order __order) _NOEXCEPT { __cxx_atomic_fetch_xor(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __pattern, memory_order __order) _NOEXCEPT {
return __c11_atomic_fetch_xor( return __c11_atomic_fetch_xor(
std::addressof(__a->__a_value), __pattern, static_cast<__memory_order_underlying_t>(__order)); std::addressof(__a->__a_value), __pattern, static_cast<__memory_order_underlying_t>(__order));
} }
template<class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp
_Tp __cxx_atomic_fetch_xor(__cxx_atomic_base_impl<_Tp> * __a, _Tp __pattern, memory_order __order) _NOEXCEPT { __cxx_atomic_fetch_xor(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) _NOEXCEPT {
return __c11_atomic_fetch_xor( return __c11_atomic_fetch_xor(
std::addressof(__a->__a_value), __pattern, static_cast<__memory_order_underlying_t>(__order)); std::addressof(__a->__a_value), __pattern, static_cast<__memory_order_underlying_t>(__order));
} }
@ -545,25 +531,22 @@ _Tp __cxx_atomic_fetch_xor(__cxx_atomic_base_impl<_Tp> * __a, _Tp __pattern, mem
#ifdef _LIBCPP_ATOMIC_ONLY_USE_BUILTINS #ifdef _LIBCPP_ATOMIC_ONLY_USE_BUILTINS
template<typename _Tp> template <typename _Tp>
struct __cxx_atomic_lock_impl { struct __cxx_atomic_lock_impl {
_LIBCPP_HIDE_FROM_ABI __cxx_atomic_lock_impl() _NOEXCEPT : __a_value(), __a_lock(0) {}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __cxx_atomic_lock_impl(_Tp value) _NOEXCEPT
__cxx_atomic_lock_impl() _NOEXCEPT : __a_value(value),
: __a_value(), __a_lock(0) {} __a_lock(0) {}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit
__cxx_atomic_lock_impl(_Tp value) _NOEXCEPT
: __a_value(value), __a_lock(0) {}
_Tp __a_value; _Tp __a_value;
mutable __cxx_atomic_base_impl<_LIBCPP_ATOMIC_FLAG_TYPE> __a_lock; mutable __cxx_atomic_base_impl<_LIBCPP_ATOMIC_FLAG_TYPE> __a_lock;
_LIBCPP_HIDE_FROM_ABI void __lock() const volatile { _LIBCPP_HIDE_FROM_ABI void __lock() const volatile {
while(1 == __cxx_atomic_exchange(&__a_lock, _LIBCPP_ATOMIC_FLAG_TYPE(true), memory_order_acquire)) while (1 == __cxx_atomic_exchange(&__a_lock, _LIBCPP_ATOMIC_FLAG_TYPE(true), memory_order_acquire))
/*spin*/; /*spin*/;
} }
_LIBCPP_HIDE_FROM_ABI void __lock() const { _LIBCPP_HIDE_FROM_ABI void __lock() const {
while(1 == __cxx_atomic_exchange(&__a_lock, _LIBCPP_ATOMIC_FLAG_TYPE(true), memory_order_acquire)) while (1 == __cxx_atomic_exchange(&__a_lock, _LIBCPP_ATOMIC_FLAG_TYPE(true), memory_order_acquire))
/*spin*/; /*spin*/;
} }
_LIBCPP_HIDE_FROM_ABI void __unlock() const volatile { _LIBCPP_HIDE_FROM_ABI void __unlock() const volatile {
@ -598,39 +581,33 @@ struct __cxx_atomic_lock_impl {
}; };
template <typename _Tp> template <typename _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI void __cxx_atomic_init(volatile __cxx_atomic_lock_impl<_Tp>* __a, _Tp __val) {
void __cxx_atomic_init(volatile __cxx_atomic_lock_impl<_Tp>* __a, _Tp __val) {
__cxx_atomic_assign_volatile(__a->__a_value, __val); __cxx_atomic_assign_volatile(__a->__a_value, __val);
} }
template <typename _Tp> template <typename _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI void __cxx_atomic_init(__cxx_atomic_lock_impl<_Tp>* __a, _Tp __val) {
void __cxx_atomic_init(__cxx_atomic_lock_impl<_Tp>* __a, _Tp __val) {
__a->__a_value = __val; __a->__a_value = __val;
} }
template <typename _Tp> template <typename _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI void __cxx_atomic_store(volatile __cxx_atomic_lock_impl<_Tp>* __a, _Tp __val, memory_order) {
void __cxx_atomic_store(volatile __cxx_atomic_lock_impl<_Tp>* __a, _Tp __val, memory_order) {
__a->__lock(); __a->__lock();
__cxx_atomic_assign_volatile(__a->__a_value, __val); __cxx_atomic_assign_volatile(__a->__a_value, __val);
__a->__unlock(); __a->__unlock();
} }
template <typename _Tp> template <typename _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI void __cxx_atomic_store(__cxx_atomic_lock_impl<_Tp>* __a, _Tp __val, memory_order) {
void __cxx_atomic_store(__cxx_atomic_lock_impl<_Tp>* __a, _Tp __val, memory_order) {
__a->__lock(); __a->__lock();
__a->__a_value = __val; __a->__a_value = __val;
__a->__unlock(); __a->__unlock();
} }
template <typename _Tp> template <typename _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_load(const volatile __cxx_atomic_lock_impl<_Tp>* __a, memory_order) {
_Tp __cxx_atomic_load(const volatile __cxx_atomic_lock_impl<_Tp>* __a, memory_order) {
return __a->__read(); return __a->__read();
} }
template <typename _Tp> template <typename _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_load(const __cxx_atomic_lock_impl<_Tp>* __a, memory_order) {
_Tp __cxx_atomic_load(const __cxx_atomic_lock_impl<_Tp>* __a, memory_order) {
return __a->__read(); return __a->__read();
} }
@ -645,8 +622,7 @@ _LIBCPP_HIDE_FROM_ABI void __cxx_atomic_load(const __cxx_atomic_lock_impl<_Tp>*
} }
template <typename _Tp> template <typename _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_exchange(volatile __cxx_atomic_lock_impl<_Tp>* __a, _Tp __value, memory_order) {
_Tp __cxx_atomic_exchange(volatile __cxx_atomic_lock_impl<_Tp>* __a, _Tp __value, memory_order) {
__a->__lock(); __a->__lock();
_Tp __old; _Tp __old;
__cxx_atomic_assign_volatile(__old, __a->__a_value); __cxx_atomic_assign_volatile(__old, __a->__a_value);
@ -655,8 +631,7 @@ _Tp __cxx_atomic_exchange(volatile __cxx_atomic_lock_impl<_Tp>* __a, _Tp __value
return __old; return __old;
} }
template <typename _Tp> template <typename _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_exchange(__cxx_atomic_lock_impl<_Tp>* __a, _Tp __value, memory_order) {
_Tp __cxx_atomic_exchange(__cxx_atomic_lock_impl<_Tp>* __a, _Tp __value, memory_order) {
__a->__lock(); __a->__lock();
_Tp __old = __a->__a_value; _Tp __old = __a->__a_value;
__a->__a_value = __value; __a->__a_value = __value;
@ -665,14 +640,13 @@ _Tp __cxx_atomic_exchange(__cxx_atomic_lock_impl<_Tp>* __a, _Tp __value, memory_
} }
template <typename _Tp> template <typename _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_strong(
bool __cxx_atomic_compare_exchange_strong(volatile __cxx_atomic_lock_impl<_Tp>* __a, volatile __cxx_atomic_lock_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order, memory_order) {
_Tp* __expected, _Tp __value, memory_order, memory_order) {
_Tp __temp; _Tp __temp;
__a->__lock(); __a->__lock();
__cxx_atomic_assign_volatile(__temp, __a->__a_value); __cxx_atomic_assign_volatile(__temp, __a->__a_value);
bool __ret = (std::memcmp(&__temp, __expected, sizeof(_Tp)) == 0); bool __ret = (std::memcmp(&__temp, __expected, sizeof(_Tp)) == 0);
if(__ret) if (__ret)
__cxx_atomic_assign_volatile(__a->__a_value, __value); __cxx_atomic_assign_volatile(__a->__a_value, __value);
else else
__cxx_atomic_assign_volatile(*__expected, __a->__a_value); __cxx_atomic_assign_volatile(*__expected, __a->__a_value);
@ -680,12 +654,11 @@ bool __cxx_atomic_compare_exchange_strong(volatile __cxx_atomic_lock_impl<_Tp>*
return __ret; return __ret;
} }
template <typename _Tp> template <typename _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_strong(
bool __cxx_atomic_compare_exchange_strong(__cxx_atomic_lock_impl<_Tp>* __a, __cxx_atomic_lock_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order, memory_order) {
_Tp* __expected, _Tp __value, memory_order, memory_order) {
__a->__lock(); __a->__lock();
bool __ret = (std::memcmp(&__a->__a_value, __expected, sizeof(_Tp)) == 0); bool __ret = (std::memcmp(&__a->__a_value, __expected, sizeof(_Tp)) == 0);
if(__ret) if (__ret)
std::memcpy(&__a->__a_value, &__value, sizeof(_Tp)); std::memcpy(&__a->__a_value, &__value, sizeof(_Tp));
else else
std::memcpy(__expected, &__a->__a_value, sizeof(_Tp)); std::memcpy(__expected, &__a->__a_value, sizeof(_Tp));
@ -694,14 +667,13 @@ bool __cxx_atomic_compare_exchange_strong(__cxx_atomic_lock_impl<_Tp>* __a,
} }
template <typename _Tp> template <typename _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_weak(
bool __cxx_atomic_compare_exchange_weak(volatile __cxx_atomic_lock_impl<_Tp>* __a, volatile __cxx_atomic_lock_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order, memory_order) {
_Tp* __expected, _Tp __value, memory_order, memory_order) {
_Tp __temp; _Tp __temp;
__a->__lock(); __a->__lock();
__cxx_atomic_assign_volatile(__temp, __a->__a_value); __cxx_atomic_assign_volatile(__temp, __a->__a_value);
bool __ret = (std::memcmp(&__temp, __expected, sizeof(_Tp)) == 0); bool __ret = (std::memcmp(&__temp, __expected, sizeof(_Tp)) == 0);
if(__ret) if (__ret)
__cxx_atomic_assign_volatile(__a->__a_value, __value); __cxx_atomic_assign_volatile(__a->__a_value, __value);
else else
__cxx_atomic_assign_volatile(*__expected, __a->__a_value); __cxx_atomic_assign_volatile(*__expected, __a->__a_value);
@ -709,12 +681,11 @@ bool __cxx_atomic_compare_exchange_weak(volatile __cxx_atomic_lock_impl<_Tp>* __
return __ret; return __ret;
} }
template <typename _Tp> template <typename _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_weak(
bool __cxx_atomic_compare_exchange_weak(__cxx_atomic_lock_impl<_Tp>* __a, __cxx_atomic_lock_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order, memory_order) {
_Tp* __expected, _Tp __value, memory_order, memory_order) {
__a->__lock(); __a->__lock();
bool __ret = (std::memcmp(&__a->__a_value, __expected, sizeof(_Tp)) == 0); bool __ret = (std::memcmp(&__a->__a_value, __expected, sizeof(_Tp)) == 0);
if(__ret) if (__ret)
std::memcpy(&__a->__a_value, &__value, sizeof(_Tp)); std::memcpy(&__a->__a_value, &__value, sizeof(_Tp));
else else
std::memcpy(__expected, &__a->__a_value, sizeof(_Tp)); std::memcpy(__expected, &__a->__a_value, sizeof(_Tp));
@ -723,9 +694,7 @@ bool __cxx_atomic_compare_exchange_weak(__cxx_atomic_lock_impl<_Tp>* __a,
} }
template <typename _Tp, typename _Td> template <typename _Tp, typename _Td>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_fetch_add(volatile __cxx_atomic_lock_impl<_Tp>* __a, _Td __delta, memory_order) {
_Tp __cxx_atomic_fetch_add(volatile __cxx_atomic_lock_impl<_Tp>* __a,
_Td __delta, memory_order) {
__a->__lock(); __a->__lock();
_Tp __old; _Tp __old;
__cxx_atomic_assign_volatile(__old, __a->__a_value); __cxx_atomic_assign_volatile(__old, __a->__a_value);
@ -734,9 +703,7 @@ _Tp __cxx_atomic_fetch_add(volatile __cxx_atomic_lock_impl<_Tp>* __a,
return __old; return __old;
} }
template <typename _Tp, typename _Td> template <typename _Tp, typename _Td>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_fetch_add(__cxx_atomic_lock_impl<_Tp>* __a, _Td __delta, memory_order) {
_Tp __cxx_atomic_fetch_add(__cxx_atomic_lock_impl<_Tp>* __a,
_Td __delta, memory_order) {
__a->__lock(); __a->__lock();
_Tp __old = __a->__a_value; _Tp __old = __a->__a_value;
__a->__a_value += __delta; __a->__a_value += __delta;
@ -745,9 +712,8 @@ _Tp __cxx_atomic_fetch_add(__cxx_atomic_lock_impl<_Tp>* __a,
} }
template <typename _Tp, typename _Td> template <typename _Tp, typename _Td>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp*
_Tp* __cxx_atomic_fetch_add(volatile __cxx_atomic_lock_impl<_Tp*>* __a, __cxx_atomic_fetch_add(volatile __cxx_atomic_lock_impl<_Tp*>* __a, ptrdiff_t __delta, memory_order) {
ptrdiff_t __delta, memory_order) {
__a->__lock(); __a->__lock();
_Tp* __old; _Tp* __old;
__cxx_atomic_assign_volatile(__old, __a->__a_value); __cxx_atomic_assign_volatile(__old, __a->__a_value);
@ -756,9 +722,7 @@ _Tp* __cxx_atomic_fetch_add(volatile __cxx_atomic_lock_impl<_Tp*>* __a,
return __old; return __old;
} }
template <typename _Tp, typename _Td> template <typename _Tp, typename _Td>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp* __cxx_atomic_fetch_add(__cxx_atomic_lock_impl<_Tp*>* __a, ptrdiff_t __delta, memory_order) {
_Tp* __cxx_atomic_fetch_add(__cxx_atomic_lock_impl<_Tp*>* __a,
ptrdiff_t __delta, memory_order) {
__a->__lock(); __a->__lock();
_Tp* __old = __a->__a_value; _Tp* __old = __a->__a_value;
__a->__a_value += __delta; __a->__a_value += __delta;
@ -767,9 +731,7 @@ _Tp* __cxx_atomic_fetch_add(__cxx_atomic_lock_impl<_Tp*>* __a,
} }
template <typename _Tp, typename _Td> template <typename _Tp, typename _Td>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_fetch_sub(volatile __cxx_atomic_lock_impl<_Tp>* __a, _Td __delta, memory_order) {
_Tp __cxx_atomic_fetch_sub(volatile __cxx_atomic_lock_impl<_Tp>* __a,
_Td __delta, memory_order) {
__a->__lock(); __a->__lock();
_Tp __old; _Tp __old;
__cxx_atomic_assign_volatile(__old, __a->__a_value); __cxx_atomic_assign_volatile(__old, __a->__a_value);
@ -778,9 +740,7 @@ _Tp __cxx_atomic_fetch_sub(volatile __cxx_atomic_lock_impl<_Tp>* __a,
return __old; return __old;
} }
template <typename _Tp, typename _Td> template <typename _Tp, typename _Td>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_fetch_sub(__cxx_atomic_lock_impl<_Tp>* __a, _Td __delta, memory_order) {
_Tp __cxx_atomic_fetch_sub(__cxx_atomic_lock_impl<_Tp>* __a,
_Td __delta, memory_order) {
__a->__lock(); __a->__lock();
_Tp __old = __a->__a_value; _Tp __old = __a->__a_value;
__a->__a_value -= __delta; __a->__a_value -= __delta;
@ -789,9 +749,8 @@ _Tp __cxx_atomic_fetch_sub(__cxx_atomic_lock_impl<_Tp>* __a,
} }
template <typename _Tp> template <typename _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp
_Tp __cxx_atomic_fetch_and(volatile __cxx_atomic_lock_impl<_Tp>* __a, __cxx_atomic_fetch_and(volatile __cxx_atomic_lock_impl<_Tp>* __a, _Tp __pattern, memory_order) {
_Tp __pattern, memory_order) {
__a->__lock(); __a->__lock();
_Tp __old; _Tp __old;
__cxx_atomic_assign_volatile(__old, __a->__a_value); __cxx_atomic_assign_volatile(__old, __a->__a_value);
@ -800,9 +759,7 @@ _Tp __cxx_atomic_fetch_and(volatile __cxx_atomic_lock_impl<_Tp>* __a,
return __old; return __old;
} }
template <typename _Tp> template <typename _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_fetch_and(__cxx_atomic_lock_impl<_Tp>* __a, _Tp __pattern, memory_order) {
_Tp __cxx_atomic_fetch_and(__cxx_atomic_lock_impl<_Tp>* __a,
_Tp __pattern, memory_order) {
__a->__lock(); __a->__lock();
_Tp __old = __a->__a_value; _Tp __old = __a->__a_value;
__a->__a_value &= __pattern; __a->__a_value &= __pattern;
@ -811,9 +768,8 @@ _Tp __cxx_atomic_fetch_and(__cxx_atomic_lock_impl<_Tp>* __a,
} }
template <typename _Tp> template <typename _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp
_Tp __cxx_atomic_fetch_or(volatile __cxx_atomic_lock_impl<_Tp>* __a, __cxx_atomic_fetch_or(volatile __cxx_atomic_lock_impl<_Tp>* __a, _Tp __pattern, memory_order) {
_Tp __pattern, memory_order) {
__a->__lock(); __a->__lock();
_Tp __old; _Tp __old;
__cxx_atomic_assign_volatile(__old, __a->__a_value); __cxx_atomic_assign_volatile(__old, __a->__a_value);
@ -822,9 +778,7 @@ _Tp __cxx_atomic_fetch_or(volatile __cxx_atomic_lock_impl<_Tp>* __a,
return __old; return __old;
} }
template <typename _Tp> template <typename _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_fetch_or(__cxx_atomic_lock_impl<_Tp>* __a, _Tp __pattern, memory_order) {
_Tp __cxx_atomic_fetch_or(__cxx_atomic_lock_impl<_Tp>* __a,
_Tp __pattern, memory_order) {
__a->__lock(); __a->__lock();
_Tp __old = __a->__a_value; _Tp __old = __a->__a_value;
__a->__a_value |= __pattern; __a->__a_value |= __pattern;
@ -833,9 +787,8 @@ _Tp __cxx_atomic_fetch_or(__cxx_atomic_lock_impl<_Tp>* __a,
} }
template <typename _Tp> template <typename _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp
_Tp __cxx_atomic_fetch_xor(volatile __cxx_atomic_lock_impl<_Tp>* __a, __cxx_atomic_fetch_xor(volatile __cxx_atomic_lock_impl<_Tp>* __a, _Tp __pattern, memory_order) {
_Tp __pattern, memory_order) {
__a->__lock(); __a->__lock();
_Tp __old; _Tp __old;
__cxx_atomic_assign_volatile(__old, __a->__a_value); __cxx_atomic_assign_volatile(__old, __a->__a_value);
@ -844,9 +797,7 @@ _Tp __cxx_atomic_fetch_xor(volatile __cxx_atomic_lock_impl<_Tp>* __a,
return __old; return __old;
} }
template <typename _Tp> template <typename _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_fetch_xor(__cxx_atomic_lock_impl<_Tp>* __a, _Tp __pattern, memory_order) {
_Tp __cxx_atomic_fetch_xor(__cxx_atomic_lock_impl<_Tp>* __a,
_Tp __pattern, memory_order) {
__a->__lock(); __a->__lock();
_Tp __old = __a->__a_value; _Tp __old = __a->__a_value;
__a->__a_value ^= __pattern; __a->__a_value ^= __pattern;
@ -859,16 +810,13 @@ template <typename _Tp,
__cxx_atomic_base_impl<_Tp>, __cxx_atomic_base_impl<_Tp>,
__cxx_atomic_lock_impl<_Tp> >::type> __cxx_atomic_lock_impl<_Tp> >::type>
#else #else
template <typename _Tp, template <typename _Tp, typename _Base = __cxx_atomic_base_impl<_Tp> >
typename _Base = __cxx_atomic_base_impl<_Tp> >
#endif //_LIBCPP_ATOMIC_ONLY_USE_BUILTINS #endif //_LIBCPP_ATOMIC_ONLY_USE_BUILTINS
struct __cxx_atomic_impl : public _Base { struct __cxx_atomic_impl : public _Base {
static_assert(is_trivially_copyable<_Tp>::value, static_assert(is_trivially_copyable<_Tp>::value, "std::atomic<T> requires that 'T' be a trivially copyable type");
"std::atomic<T> requires that 'T' be a trivially copyable type");
_LIBCPP_HIDE_FROM_ABI __cxx_atomic_impl() _NOEXCEPT = default; _LIBCPP_HIDE_FROM_ABI __cxx_atomic_impl() _NOEXCEPT = default;
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __cxx_atomic_impl(_Tp __value) _NOEXCEPT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __cxx_atomic_impl(_Tp __value) _NOEXCEPT : _Base(__value) {}
: _Base(__value) {}
}; };
_LIBCPP_END_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD

View File

@ -19,19 +19,9 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
inline _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_HIDE_FROM_ABI void atomic_thread_fence(memory_order __m) _NOEXCEPT { __cxx_atomic_thread_fence(__m); }
void
atomic_thread_fence(memory_order __m) _NOEXCEPT
{
__cxx_atomic_thread_fence(__m);
}
inline _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_HIDE_FROM_ABI void atomic_signal_fence(memory_order __m) _NOEXCEPT { __cxx_atomic_signal_fence(__m); }
void
atomic_signal_fence(memory_order __m) _NOEXCEPT
{
__cxx_atomic_signal_fence(__m);
}
_LIBCPP_END_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD

View File

@ -18,9 +18,7 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template <class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Tp kill_dependency(_Tp __y) _NOEXCEPT {
_Tp kill_dependency(_Tp __y) _NOEXCEPT
{
return __y; return __y;
} }

View File

@ -22,14 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
// Figure out what the underlying type for `memory_order` would be if it were // Figure out what the underlying type for `memory_order` would be if it were
// declared as an unscoped enum (accounting for -fshort-enums). Use this result // declared as an unscoped enum (accounting for -fshort-enums). Use this result
// to pin the underlying type in C++20. // to pin the underlying type in C++20.
enum __legacy_memory_order { enum __legacy_memory_order { __mo_relaxed, __mo_consume, __mo_acquire, __mo_release, __mo_acq_rel, __mo_seq_cst };
__mo_relaxed,
__mo_consume,
__mo_acquire,
__mo_release,
__mo_acq_rel,
__mo_seq_cst
};
using __memory_order_underlying_t = underlying_type<__legacy_memory_order>::type; using __memory_order_underlying_t = underlying_type<__legacy_memory_order>::type;

View File

@ -64,7 +64,6 @@
// //
// [1]: https://clang.llvm.org/docs/AttributeReference.html#availability // [1]: https://clang.llvm.org/docs/AttributeReference.html#availability
// For backwards compatibility, allow users to define _LIBCPP_DISABLE_AVAILABILITY // For backwards compatibility, allow users to define _LIBCPP_DISABLE_AVAILABILITY
// for a while. // for a while.
#if defined(_LIBCPP_DISABLE_AVAILABILITY) #if defined(_LIBCPP_DISABLE_AVAILABILITY)
@ -75,10 +74,8 @@
// Availability markup is disabled when building the library, or when the compiler // Availability markup is disabled when building the library, or when the compiler
// doesn't support the proper attributes. // doesn't support the proper attributes.
#if defined(_LIBCPP_BUILDING_LIBRARY) || \ #if defined(_LIBCPP_BUILDING_LIBRARY) || defined(_LIBCXXABI_BUILDING_LIBRARY) || \
defined(_LIBCXXABI_BUILDING_LIBRARY) || \ !__has_feature(attribute_availability_with_strict) || !__has_feature(attribute_availability_in_templates) || \
!__has_feature(attribute_availability_with_strict) || \
!__has_feature(attribute_availability_in_templates) || \
!__has_extension(pragma_clang_attribute_external_declaration) !__has_extension(pragma_clang_attribute_external_declaration)
# if !defined(_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS) # if !defined(_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS)
# define _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS # define _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS
@ -160,7 +157,7 @@
# define _LIBCPP_AVAILABILITY_HAS_BAD_VARIANT_ACCESS _LIBCPP_AVAILABILITY_HAS_BAD_OPTIONAL_ACCESS # define _LIBCPP_AVAILABILITY_HAS_BAD_VARIANT_ACCESS _LIBCPP_AVAILABILITY_HAS_BAD_OPTIONAL_ACCESS
# define _LIBCPP_AVAILABILITY_HAS_BAD_ANY_CAST _LIBCPP_AVAILABILITY_HAS_BAD_OPTIONAL_ACCESS # define _LIBCPP_AVAILABILITY_HAS_BAD_ANY_CAST _LIBCPP_AVAILABILITY_HAS_BAD_OPTIONAL_ACCESS
# define _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS __attribute__((availability(watchos,strict,introduced=5.0))) # define _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS __attribute__((availability(watchos, strict, introduced = 5.0)))
# define _LIBCPP_AVAILABILITY_BAD_VARIANT_ACCESS _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS # define _LIBCPP_AVAILABILITY_BAD_VARIANT_ACCESS _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS
# define _LIBCPP_AVAILABILITY_BAD_ANY_CAST _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS # define _LIBCPP_AVAILABILITY_BAD_ANY_CAST _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS
@ -176,10 +173,10 @@
# define _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY 1 # define _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY 1
# endif # endif
# define _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY \ # define _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY \
__attribute__((availability(macos,strict,introduced=10.15))) \ __attribute__((availability(macos, strict, introduced = 10.15))) \
__attribute__((availability(ios,strict,introduced=13.0))) \ __attribute__((availability(ios, strict, introduced = 13.0))) \
__attribute__((availability(tvos,strict,introduced=13.0))) \ __attribute__((availability(tvos, strict, introduced = 13.0))) \
__attribute__((availability(watchos,strict,introduced=6.0))) __attribute__((availability(watchos, strict, introduced = 6.0)))
// clang-format off // clang-format off
# define _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_PUSH \ # define _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_PUSH \
_Pragma("clang attribute push(__attribute__((availability(macos,strict,introduced=10.15))), apply_to=any(function,record))") \ _Pragma("clang attribute push(__attribute__((availability(macos,strict,introduced=10.15))), apply_to=any(function,record))") \
@ -205,12 +202,12 @@
# define _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT 1 # define _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT 1
# endif # endif
# define _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT \ # define _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT \
__attribute__((availability(macos,strict,introduced=13.3))) \ __attribute__((availability(macos, strict, introduced = 13.3))) \
__attribute__((availability(ios,strict,introduced=16.3))) \ __attribute__((availability(ios, strict, introduced = 16.3))) \
__attribute__((availability(tvos,strict,introduced=16.3))) \ __attribute__((availability(tvos, strict, introduced = 16.3))) \
__attribute__((availability(watchos,strict,introduced=9.3))) __attribute__((availability(watchos, strict, introduced = 9.3)))
// c++20 synchronization library // c++20 synchronization library
// clang-format off // clang-format off
# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 110000) || \ # if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 110000) || \
(defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 140000) || \ (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 140000) || \
@ -222,17 +219,16 @@
# define _LIBCPP_AVAILABILITY_HAS_SYNC 1 # define _LIBCPP_AVAILABILITY_HAS_SYNC 1
# endif # endif
# define _LIBCPP_AVAILABILITY_SYNC \ # define _LIBCPP_AVAILABILITY_SYNC \
__attribute__((availability(macos,strict,introduced=11.0))) \ __attribute__((availability(macos, strict, introduced = 11.0))) \
__attribute__((availability(ios,strict,introduced=14.0))) \ __attribute__((availability(ios, strict, introduced = 14.0))) \
__attribute__((availability(tvos,strict,introduced=14.0))) \ __attribute__((availability(tvos, strict, introduced = 14.0))) \
__attribute__((availability(watchos,strict,introduced=7.0))) __attribute__((availability(watchos, strict, introduced = 7.0)))
// __libcpp_verbose_abort // __libcpp_verbose_abort
// TODO: Update once this is released // TODO: Update once this is released
# define _LIBCPP_AVAILABILITY_HAS_VERBOSE_ABORT 0 # define _LIBCPP_AVAILABILITY_HAS_VERBOSE_ABORT 0
# define _LIBCPP_AVAILABILITY_VERBOSE_ABORT \ # define _LIBCPP_AVAILABILITY_VERBOSE_ABORT __attribute__((unavailable))
__attribute__((unavailable))
// std::pmr // std::pmr
// clang-format off // clang-format off
@ -276,7 +272,8 @@
// ...New vendors can add availability markup here... // ...New vendors can add availability markup here...
# error "It looks like you're trying to enable vendor availability markup, but you haven't defined the corresponding macros yet!" # error \
"It looks like you're trying to enable vendor availability markup, but you haven't defined the corresponding macros yet!"
#endif #endif

View File

@ -22,8 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
#if _LIBCPP_STD_VER >= 20 #if _LIBCPP_STD_VER >= 20
template <class _ToType, class _FromType> template <class _ToType, class _FromType>
requires(sizeof(_ToType) == sizeof(_FromType) && requires(sizeof(_ToType) == sizeof(_FromType) && is_trivially_copyable_v<_ToType> &&
is_trivially_copyable_v<_ToType> &&
is_trivially_copyable_v<_FromType>) is_trivially_copyable_v<_FromType>)
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr _ToType bit_cast(const _FromType& __from) noexcept { _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr _ToType bit_cast(const _FromType& __from) noexcept {
return __builtin_bit_cast(_ToType, __from); return __builtin_bit_cast(_ToType, __from);

View File

@ -24,7 +24,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <integral _Tp> template <integral _Tp>
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr _Tp byteswap(_Tp __val) noexcept { _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr _Tp byteswap(_Tp __val) noexcept {
if constexpr (sizeof(_Tp) == 1) { if constexpr (sizeof(_Tp) == 1) {
return __val; return __val;
} else if constexpr (sizeof(_Tp) == 2) { } else if constexpr (sizeof(_Tp) == 2) {
@ -33,15 +32,15 @@ _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr _Tp byteswap(_Tp __val) no
return __builtin_bswap32(__val); return __builtin_bswap32(__val);
} else if constexpr (sizeof(_Tp) == 8) { } else if constexpr (sizeof(_Tp) == 8) {
return __builtin_bswap64(__val); return __builtin_bswap64(__val);
#ifndef _LIBCPP_HAS_NO_INT128 # ifndef _LIBCPP_HAS_NO_INT128
} else if constexpr (sizeof(_Tp) == 16) { } else if constexpr (sizeof(_Tp) == 16) {
#if __has_builtin(__builtin_bswap128) # if __has_builtin(__builtin_bswap128)
return __builtin_bswap128(__val); return __builtin_bswap128(__val);
#else # else
return static_cast<_Tp>(byteswap(static_cast<uint64_t>(__val))) << 64 | return static_cast<_Tp>(byteswap(static_cast<uint64_t>(__val))) << 64 |
static_cast<_Tp>(byteswap(static_cast<uint64_t>(__val >> 64))); static_cast<_Tp>(byteswap(static_cast<uint64_t>(__val >> 64)));
#endif // __has_builtin(__builtin_bswap128) # endif // __has_builtin(__builtin_bswap128)
#endif // _LIBCPP_HAS_NO_INT128 # endif // _LIBCPP_HAS_NO_INT128
} else { } else {
static_assert(sizeof(_Tp) == 0, "byteswap is unimplemented for integral types of this size"); static_assert(sizeof(_Tp) == 0, "byteswap is unimplemented for integral types of this size");
} }

View File

@ -24,18 +24,20 @@ _LIBCPP_PUSH_MACROS
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_clz(unsigned __x) _NOEXCEPT {
int __libcpp_clz(unsigned __x) _NOEXCEPT { return __builtin_clz(__x); } return __builtin_clz(__x);
}
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_clz(unsigned long __x) _NOEXCEPT {
int __libcpp_clz(unsigned long __x) _NOEXCEPT { return __builtin_clzl(__x); } return __builtin_clzl(__x);
}
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_clz(unsigned long long __x) _NOEXCEPT {
int __libcpp_clz(unsigned long long __x) _NOEXCEPT { return __builtin_clzll(__x); } return __builtin_clzll(__x);
}
# ifndef _LIBCPP_HAS_NO_INT128 #ifndef _LIBCPP_HAS_NO_INT128
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_clz(__uint128_t __x) _NOEXCEPT {
int __libcpp_clz(__uint128_t __x) _NOEXCEPT {
// The function is written in this form due to C++ constexpr limitations. // The function is written in this form due to C++ constexpr limitations.
// The algorithm: // The algorithm:
// - Test whether any bit in the high 64-bits is set // - Test whether any bit in the high 64-bits is set
@ -45,31 +47,27 @@ int __libcpp_clz(__uint128_t __x) _NOEXCEPT {
// - Any bits set: // - Any bits set:
// - The number of leading zeros of the input is the number of leading // - The number of leading zeros of the input is the number of leading
// zeros in the high 64-bits. // zeros in the high 64-bits.
return ((__x >> 64) == 0) return ((__x >> 64) == 0) ? (64 + __builtin_clzll(static_cast<unsigned long long>(__x)))
? (64 + __builtin_clzll(static_cast<unsigned long long>(__x)))
: __builtin_clzll(static_cast<unsigned long long>(__x >> 64)); : __builtin_clzll(static_cast<unsigned long long>(__x >> 64));
} }
# endif // _LIBCPP_HAS_NO_INT128 #endif // _LIBCPP_HAS_NO_INT128
template<class _Tp> template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int __countl_zero(_Tp __t) _NOEXCEPT {
int __countl_zero(_Tp __t) _NOEXCEPT
{
static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__countl_zero requires an unsigned integer type"); static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__countl_zero requires an unsigned integer type");
if (__t == 0) if (__t == 0)
return numeric_limits<_Tp>::digits; return numeric_limits<_Tp>::digits;
if (sizeof(_Tp) <= sizeof(unsigned int)) if (sizeof(_Tp) <= sizeof(unsigned int))
return std::__libcpp_clz(static_cast<unsigned int>(__t)) return std::__libcpp_clz(static_cast<unsigned int>(__t)) -
- (numeric_limits<unsigned int>::digits - numeric_limits<_Tp>::digits); (numeric_limits<unsigned int>::digits - numeric_limits<_Tp>::digits);
else if (sizeof(_Tp) <= sizeof(unsigned long)) else if (sizeof(_Tp) <= sizeof(unsigned long))
return std::__libcpp_clz(static_cast<unsigned long>(__t)) return std::__libcpp_clz(static_cast<unsigned long>(__t)) -
- (numeric_limits<unsigned long>::digits - numeric_limits<_Tp>::digits); (numeric_limits<unsigned long>::digits - numeric_limits<_Tp>::digits);
else if (sizeof(_Tp) <= sizeof(unsigned long long)) else if (sizeof(_Tp) <= sizeof(unsigned long long))
return std::__libcpp_clz(static_cast<unsigned long long>(__t)) return std::__libcpp_clz(static_cast<unsigned long long>(__t)) -
- (numeric_limits<unsigned long long>::digits - numeric_limits<_Tp>::digits); (numeric_limits<unsigned long long>::digits - numeric_limits<_Tp>::digits);
else else {
{
int __ret = 0; int __ret = 0;
int __iter = 0; int __iter = 0;
const unsigned int __ulldigits = numeric_limits<unsigned long long>::digits; const unsigned int __ulldigits = numeric_limits<unsigned long long>::digits;

Some files were not shown because too many files have changed in this diff Show More