authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-08-04 17:53:05-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-08-04 17:53:05-07:00
log8278eb88376341420817f15791fe7c1715e04a4f
tree4195bafa4e21a5787cb3ada46bc0816d67d487dd
parentac5c6b6061c6454a891c22a8258069370b57c05b

update libcxx to LLVM 15

release/15.x commit 134fd359a5d884f16662a9edd22ab24feeb1498c

841 files changed, 37007 insertions(+), 20860 deletions(-)

lib/libcxx/include/__algorithm/adjacent_find.h+21-13
......@@ -11,34 +11,42 @@
1111#define _LIBCPP___ALGORITHM_ADJACENT_FIND_H
1212
1313#include <__algorithm/comp.h>
14#include <__algorithm/iterator_operations.h>
1415#include <__config>
1516#include <__iterator/iterator_traits.h>
17#include <__utility/move.h>
1618
1719#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
20# pragma GCC system_header
1921#endif
2022
2123_LIBCPP_BEGIN_NAMESPACE_STD
2224
25template <class _Iter, class _Sent, class _BinaryPredicate>
26_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _Iter
27__adjacent_find(_Iter __first, _Sent __last, _BinaryPredicate&& __pred) {
28 if (__first == __last)
29 return __first;
30 _Iter __i = __first;
31 while (++__i != __last) {
32 if (__pred(*__first, *__i))
33 return __first;
34 __first = __i;
35 }
36 return __i;
37}
38
2339template <class _ForwardIterator, class _BinaryPredicate>
24_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
40_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
2541adjacent_find(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred) {
26 if (__first != __last) {
27 _ForwardIterator __i = __first;
28 while (++__i != __last) {
29 if (__pred(*__first, *__i))
30 return __first;
31 __first = __i;
32 }
33 }
34 return __last;
42 return std::__adjacent_find(std::move(__first), std::move(__last), __pred);
3543}
3644
3745template <class _ForwardIterator>
38_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
46_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
3947adjacent_find(_ForwardIterator __first, _ForwardIterator __last) {
4048 typedef typename iterator_traits<_ForwardIterator>::value_type __v;
41 return _VSTD::adjacent_find(__first, __last, __equal_to<__v>());
49 return std::adjacent_find(std::move(__first), std::move(__last), __equal_to<__v>());
4250}
4351
4452_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__algorithm/algorithm_family.h created+52
......@@ -0,0 +1,52 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_ALGORITHM_FAMILY_H
10#define _LIBCPP___ALGORITHM_ALGORITHM_FAMILY_H
11
12#include <__algorithm/iterator_operations.h>
13#include <__algorithm/move.h>
14#include <__algorithm/ranges_move.h>
15#include <__config>
16#include <__utility/move.h>
17
18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19# pragma GCC system_header
20#endif
21
22_LIBCPP_BEGIN_NAMESPACE_STD
23
24template <class _AlgPolicy>
25struct _AlgFamily;
26
27#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
28
29template <>
30struct _AlgFamily<_RangeAlgPolicy> {
31 static constexpr auto __move = ranges::move;
32};
33
34#endif
35
36template <>
37struct _AlgFamily<_ClassicAlgPolicy> {
38
39 // move
40 template <class _InputIterator, class _OutputIterator>
41 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 static _OutputIterator
42 __move(_InputIterator __first, _InputIterator __last, _OutputIterator __result) {
43 return std::move(
44 std::move(__first),
45 std::move(__last),
46 std::move(__result));
47 }
48};
49
50_LIBCPP_END_NAMESPACE_STD
51
52#endif // _LIBCPP___ALGORITHM_ALGORITHM_FAMILY_H
lib/libcxx/include/__algorithm/all_of.h+1-1
......@@ -13,7 +13,7 @@
1313#include <__config>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16#pragma GCC system_header
16# pragma GCC system_header
1717#endif
1818
1919_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/any_of.h+1-1
......@@ -13,7 +13,7 @@
1313#include <__config>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16#pragma GCC system_header
16# pragma GCC system_header
1717#endif
1818
1919_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/binary_search.h+8-16
......@@ -16,38 +16,30 @@
1616#include <__iterator/iterator_traits.h>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
19# pragma GCC system_header
2020#endif
2121
2222_LIBCPP_BEGIN_NAMESPACE_STD
2323
24template <class _Compare, class _ForwardIterator, class _Tp>
25inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
26bool
27__binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
28{
29 __first = _VSTD::__lower_bound<_Compare>(__first, __last, __value_, __comp);
30 return __first != __last && !__comp(__value_, *__first);
31}
32
3324template <class _ForwardIterator, class _Tp, class _Compare>
3425_LIBCPP_NODISCARD_EXT inline
3526_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
3627bool
37binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
28binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp)
3829{
39 typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
40 return _VSTD::__binary_search<_Comp_ref>(__first, __last, __value_, __comp);
30 using _Comp_ref = typename __comp_ref_type<_Compare>::type;
31 __first = std::lower_bound<_ForwardIterator, _Tp, _Comp_ref>(__first, __last, __value, __comp);
32 return __first != __last && !__comp(__value, *__first);
4133}
4234
4335template <class _ForwardIterator, class _Tp>
4436_LIBCPP_NODISCARD_EXT inline
4537_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
4638bool
47binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_)
39binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
4840{
49 return _VSTD::binary_search(__first, __last, __value_,
50 __less<typename iterator_traits<_ForwardIterator>::value_type, _Tp>());
41 return std::binary_search(__first, __last, __value,
42 __less<typename iterator_traits<_ForwardIterator>::value_type, _Tp>());
5143}
5244
5345_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__algorithm/clamp.h+2-2
......@@ -10,11 +10,11 @@
1010#define _LIBCPP___ALGORITHM_CLAMP_H
1111
1212#include <__algorithm/comp.h>
13#include <__assert>
1314#include <__config>
14#include <__debug>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
17# pragma GCC system_header
1818#endif
1919
2020_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/comp.h+1-1
......@@ -12,7 +12,7 @@
1212#include <__config>
1313
1414#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15#pragma GCC system_header
15# pragma GCC system_header
1616#endif
1717
1818_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/comp_ref_type.h+9-14
......@@ -10,20 +10,15 @@
1010#define _LIBCPP___ALGORITHM_COMP_REF_TYPE_H
1111
1212#include <__config>
13
14#ifdef _LIBCPP_DEBUG
15# include <__debug>
16# include <__utility/declval.h>
17#endif
13#include <__debug>
14#include <__utility/declval.h>
1815
1916#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20#pragma GCC system_header
17# pragma GCC system_header
2118#endif
2219
2320_LIBCPP_BEGIN_NAMESPACE_STD
2421
25#ifdef _LIBCPP_DEBUG
26
2722template <class _Compare>
2823struct __debug_less
2924{
......@@ -57,8 +52,10 @@ struct __debug_less
5752 decltype((void)declval<_Compare&>()(
5853 declval<_LHS &>(), declval<_RHS &>()))
5954 __do_compare_assert(int, _LHS & __l, _RHS & __r) {
60 _LIBCPP_ASSERT(!__comp_(__l, __r),
55 _LIBCPP_DEBUG_ASSERT(!__comp_(__l, __r),
6156 "Comparator does not induce a strict weak ordering");
57 (void)__l;
58 (void)__r;
6259 }
6360
6461 template <class _LHS, class _RHS>
......@@ -67,16 +64,14 @@ struct __debug_less
6764 void __do_compare_assert(long, _LHS &, _RHS &) {}
6865};
6966
70#endif // _LIBCPP_DEBUG
71
7267template <class _Comp>
7368struct __comp_ref_type {
7469 // Pass the comparator by lvalue reference. Or in debug mode, using a
7570 // debugging wrapper that stores a reference.
76#ifndef _LIBCPP_DEBUG
77 typedef _Comp& type;
78#else
71#ifdef _LIBCPP_ENABLE_DEBUG_MODE
7972 typedef __debug_less<_Comp> type;
73#else
74 typedef _Comp& type;
8075#endif
8176};
8277
lib/libcxx/include/__algorithm/copy.h+70-39
......@@ -10,66 +10,97 @@
1010#define _LIBCPP___ALGORITHM_COPY_H
1111
1212#include <__algorithm/unwrap_iter.h>
13#include <__algorithm/unwrap_range.h>
1314#include <__config>
1415#include <__iterator/iterator_traits.h>
16#include <__iterator/reverse_iterator.h>
17#include <__utility/move.h>
18#include <__utility/pair.h>
1519#include <cstring>
1620#include <type_traits>
1721
1822#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
23# pragma GCC system_header
2024#endif
2125
2226_LIBCPP_BEGIN_NAMESPACE_STD
2327
2428// copy
2529
26template <class _InputIterator, class _OutputIterator>
27inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
28_OutputIterator
29__copy_constexpr(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
30{
31 for (; __first != __last; ++__first, (void) ++__result)
32 *__result = *__first;
33 return __result;
30template <class _InIter, class _Sent, class _OutIter>
31inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
32pair<_InIter, _OutIter> __copy_impl(_InIter __first, _Sent __last, _OutIter __result) {
33 while (__first != __last) {
34 *__result = *__first;
35 ++__first;
36 ++__result;
37 }
38 return pair<_InIter, _OutIter>(std::move(__first), std::move(__result));
3439}
3540
36template <class _InputIterator, class _OutputIterator>
37inline _LIBCPP_INLINE_VISIBILITY
38_OutputIterator
39__copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
40{
41 return _VSTD::__copy_constexpr(__first, __last, __result);
41template <class _InValueT,
42 class _OutValueT,
43 class = __enable_if_t<is_same<typename remove_const<_InValueT>::type, _OutValueT>::value
44 && is_trivially_copy_assignable<_OutValueT>::value> >
45inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
46pair<_InValueT*, _OutValueT*> __copy_impl(_InValueT* __first, _InValueT* __last, _OutValueT* __result) {
47 if (__libcpp_is_constant_evaluated()
48// TODO: Remove this once GCC supports __builtin_memmove during constant evaluation
49#ifndef _LIBCPP_COMPILER_GCC
50 && !is_trivially_copyable<_InValueT>::value
51#endif
52 )
53 return std::__copy_impl<_InValueT*, _InValueT*, _OutValueT*>(__first, __last, __result);
54 const size_t __n = static_cast<size_t>(__last - __first);
55 if (__n > 0)
56 ::__builtin_memmove(__result, __first, __n * sizeof(_OutValueT));
57 return std::make_pair(__first + __n, __result + __n);
58}
59
60template <class _InIter, class _OutIter,
61 __enable_if_t<is_same<typename remove_const<__iter_value_type<_InIter> >::type, __iter_value_type<_OutIter> >::value
62 && __is_cpp17_contiguous_iterator<typename _InIter::iterator_type>::value
63 && __is_cpp17_contiguous_iterator<typename _OutIter::iterator_type>::value
64 && is_trivially_copy_assignable<__iter_value_type<_OutIter> >::value
65 && __is_reverse_iterator<_InIter>::value
66 && __is_reverse_iterator<_OutIter>::value, int> = 0>
67inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
68pair<_InIter, _OutIter>
69__copy_impl(_InIter __first, _InIter __last, _OutIter __result) {
70 auto __first_base = std::__unwrap_iter(__first.base());
71 auto __last_base = std::__unwrap_iter(__last.base());
72 auto __result_base = std::__unwrap_iter(__result.base());
73 auto __result_first = __result_base - (__first_base - __last_base);
74 std::__copy_impl(__last_base, __first_base, __result_first);
75 return std::make_pair(__last, _OutIter(std::__rewrap_iter(__result.base(), __result_first)));
76}
77
78template <class _InIter, class _Sent, class _OutIter,
79 __enable_if_t<!(is_copy_constructible<_InIter>::value
80 && is_copy_constructible<_Sent>::value
81 && is_copy_constructible<_OutIter>::value), int> = 0 >
82inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
83pair<_InIter, _OutIter> __copy(_InIter __first, _Sent __last, _OutIter __result) {
84 return std::__copy_impl(std::move(__first), std::move(__last), std::move(__result));
4285}
4386
44template <class _Tp, class _Up>
45inline _LIBCPP_INLINE_VISIBILITY
46typename enable_if
47<
48 is_same<typename remove_const<_Tp>::type, _Up>::value &&
49 is_trivially_copy_assignable<_Up>::value,
50 _Up*
51>::type
52__copy(_Tp* __first, _Tp* __last, _Up* __result)
53{
54 const size_t __n = static_cast<size_t>(__last - __first);
55 if (__n > 0)
56 _VSTD::memmove(__result, __first, __n * sizeof(_Up));
57 return __result + __n;
87template <class _InIter, class _Sent, class _OutIter,
88 __enable_if_t<is_copy_constructible<_InIter>::value
89 && is_copy_constructible<_Sent>::value
90 && is_copy_constructible<_OutIter>::value, int> = 0>
91inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
92pair<_InIter, _OutIter> __copy(_InIter __first, _Sent __last, _OutIter __result) {
93 auto __range = std::__unwrap_range(__first, __last);
94 auto __ret = std::__copy_impl(std::move(__range.first), std::move(__range.second), std::__unwrap_iter(__result));
95 return std::make_pair(
96 std::__rewrap_range<_Sent>(__first, __ret.first), std::__rewrap_iter(__result, __ret.second));
5897}
5998
6099template <class _InputIterator, class _OutputIterator>
61100inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
62101_OutputIterator
63copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
64{
65 if (__libcpp_is_constant_evaluated()) {
66 return _VSTD::__copy_constexpr(__first, __last, __result);
67 } else {
68 return _VSTD::__rewrap_iter(__result,
69 _VSTD::__copy(_VSTD::__unwrap_iter(__first),
70 _VSTD::__unwrap_iter(__last),
71 _VSTD::__unwrap_iter(__result)));
72 }
102copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result) {
103 return std::__copy(__first, __last, __result).second;
73104}
74105
75106_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__algorithm/copy_backward.h+29-47
......@@ -9,69 +9,51 @@
99#ifndef _LIBCPP___ALGORITHM_COPY_BACKWARD_H
1010#define _LIBCPP___ALGORITHM_COPY_BACKWARD_H
1111
12#include <__algorithm/copy.h>
13#include <__algorithm/iterator_operations.h>
14#include <__algorithm/ranges_copy.h>
1215#include <__algorithm/unwrap_iter.h>
16#include <__concepts/same_as.h>
1317#include <__config>
1418#include <__iterator/iterator_traits.h>
19#include <__iterator/reverse_iterator.h>
20#include <__ranges/subrange.h>
21#include <__utility/move.h>
22#include <__utility/pair.h>
1523#include <cstring>
1624#include <type_traits>
1725
1826#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
27# pragma GCC system_header
2028#endif
2129
2230_LIBCPP_BEGIN_NAMESPACE_STD
2331
24template <class _BidirectionalIterator, class _OutputIterator>
25inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
26_OutputIterator
27__copy_backward_constexpr(_BidirectionalIterator __first, _BidirectionalIterator __last, _OutputIterator __result)
28{
29 while (__first != __last)
30 *--__result = *--__last;
31 return __result;
32template <class _AlgPolicy, class _InputIterator, class _OutputIterator,
33 __enable_if_t<is_same<_AlgPolicy, _ClassicAlgPolicy>::value, int> = 0>
34inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 pair<_InputIterator, _OutputIterator>
35__copy_backward(_InputIterator __first, _InputIterator __last, _OutputIterator __result) {
36 auto __ret = std::__copy(
37 __unconstrained_reverse_iterator<_InputIterator>(__last),
38 __unconstrained_reverse_iterator<_InputIterator>(__first),
39 __unconstrained_reverse_iterator<_OutputIterator>(__result));
40 return pair<_InputIterator, _OutputIterator>(__ret.first.base(), __ret.second.base());
3241}
3342
34template <class _BidirectionalIterator, class _OutputIterator>
35inline _LIBCPP_INLINE_VISIBILITY
36_OutputIterator
37__copy_backward(_BidirectionalIterator __first, _BidirectionalIterator __last, _OutputIterator __result)
38{
39 return _VSTD::__copy_backward_constexpr(__first, __last, __result);
40}
41
42template <class _Tp, class _Up>
43inline _LIBCPP_INLINE_VISIBILITY
44typename enable_if
45<
46 is_same<typename remove_const<_Tp>::type, _Up>::value &&
47 is_trivially_copy_assignable<_Up>::value,
48 _Up*
49>::type
50__copy_backward(_Tp* __first, _Tp* __last, _Up* __result)
51{
52 const size_t __n = static_cast<size_t>(__last - __first);
53 if (__n > 0)
54 {
55 __result -= __n;
56 _VSTD::memmove(__result, __first, __n * sizeof(_Up));
57 }
58 return __result;
43#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
44template <class _AlgPolicy, class _Iter1, class _Sent1, class _Iter2,
45 __enable_if_t<is_same<_AlgPolicy, _RangeAlgPolicy>::value, int> = 0>
46_LIBCPP_HIDE_FROM_ABI constexpr pair<_Iter1, _Iter2> __copy_backward(_Iter1 __first, _Sent1 __last, _Iter2 __result) {
47 auto __reverse_range = std::__reverse_range(std::ranges::subrange(std::move(__first), std::move(__last)));
48 auto __ret = ranges::copy(std::move(__reverse_range), std::make_reverse_iterator(__result));
49 return std::make_pair(__ret.in.base(), __ret.out.base());
5950}
51#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
6052
6153template <class _BidirectionalIterator1, class _BidirectionalIterator2>
62inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
63_BidirectionalIterator2
64copy_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last,
65 _BidirectionalIterator2 __result)
66{
67 if (__libcpp_is_constant_evaluated()) {
68 return _VSTD::__copy_backward_constexpr(__first, __last, __result);
69 } else {
70 return _VSTD::__rewrap_iter(__result,
71 _VSTD::__copy_backward(_VSTD::__unwrap_iter(__first),
72 _VSTD::__unwrap_iter(__last),
73 _VSTD::__unwrap_iter(__result)));
74 }
54inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _BidirectionalIterator2
55copy_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last, _BidirectionalIterator2 __result) {
56 return std::__copy_backward<_ClassicAlgPolicy>(__first, __last, __result).second;
7557}
7658
7759_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__algorithm/copy_if.h+1-1
......@@ -12,7 +12,7 @@
1212#include <__config>
1313
1414#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15#pragma GCC system_header
15# pragma GCC system_header
1616#endif
1717
1818_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/copy_n.h+1-1
......@@ -15,7 +15,7 @@
1515#include <type_traits>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/count.h+3-3
......@@ -14,7 +14,7 @@
1414#include <__iterator/iterator_traits.h>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
17# pragma GCC system_header
1818#endif
1919
2020_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -22,10 +22,10 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2222template <class _InputIterator, class _Tp>
2323_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
2424 typename iterator_traits<_InputIterator>::difference_type
25 count(_InputIterator __first, _InputIterator __last, const _Tp& __value_) {
25 count(_InputIterator __first, _InputIterator __last, const _Tp& __value) {
2626 typename iterator_traits<_InputIterator>::difference_type __r(0);
2727 for (; __first != __last; ++__first)
28 if (*__first == __value_)
28 if (*__first == __value)
2929 ++__r;
3030 return __r;
3131}
lib/libcxx/include/__algorithm/count_if.h+1-1
......@@ -14,7 +14,7 @@
1414#include <__iterator/iterator_traits.h>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
17# pragma GCC system_header
1818#endif
1919
2020_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/equal.h+1-1
......@@ -16,7 +16,7 @@
1616#include <__iterator/iterator_traits.h>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
19# pragma GCC system_header
2020#endif
2121
2222_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/equal_range.h+49-47
......@@ -12,69 +12,71 @@
1212#include <__algorithm/comp.h>
1313#include <__algorithm/comp_ref_type.h>
1414#include <__algorithm/half_positive.h>
15#include <__algorithm/iterator_operations.h>
1516#include <__algorithm/lower_bound.h>
1617#include <__algorithm/upper_bound.h>
1718#include <__config>
18#include <iterator>
19#include <__functional/identity.h>
20#include <__functional/invoke.h>
21#include <__iterator/advance.h>
22#include <__iterator/distance.h>
23#include <__iterator/iterator_traits.h>
24#include <__iterator/next.h>
25#include <__type_traits/is_callable.h>
26#include <__type_traits/is_copy_constructible.h>
27#include <__utility/move.h>
28#include <__utility/pair.h>
1929
2030#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21#pragma GCC system_header
31# pragma GCC system_header
2232#endif
2333
2434_LIBCPP_BEGIN_NAMESPACE_STD
2535
26template <class _Compare, class _ForwardIterator, class _Tp>
27_LIBCPP_CONSTEXPR_AFTER_CXX17 pair<_ForwardIterator, _ForwardIterator>
28__equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
29{
30 typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type;
31 difference_type __len = _VSTD::distance(__first, __last);
32 while (__len != 0)
33 {
34 difference_type __l2 = _VSTD::__half_positive(__len);
35 _ForwardIterator __m = __first;
36 _VSTD::advance(__m, __l2);
37 if (__comp(*__m, __value_))
38 {
39 __first = ++__m;
40 __len -= __l2 + 1;
41 }
42 else if (__comp(__value_, *__m))
43 {
44 __last = __m;
45 __len = __l2;
46 }
47 else
48 {
49 _ForwardIterator __mp1 = __m;
50 return pair<_ForwardIterator, _ForwardIterator>
51 (
52 _VSTD::__lower_bound<_Compare>(__first, __m, __value_, __comp),
53 _VSTD::__upper_bound<_Compare>(++__mp1, __last, __value_, __comp)
54 );
55 }
36template <class _AlgPolicy, class _Compare, class _Iter, class _Sent, class _Tp, class _Proj>
37_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 pair<_Iter, _Iter>
38__equal_range(_Iter __first, _Sent __last, const _Tp& __value, _Compare&& __comp, _Proj&& __proj) {
39 auto __len = _IterOps<_AlgPolicy>::distance(__first, __last);
40 _Iter __end = _IterOps<_AlgPolicy>::next(__first, __last);
41 while (__len != 0) {
42 auto __half_len = std::__half_positive(__len);
43 _Iter __mid = _IterOps<_AlgPolicy>::next(__first, __half_len);
44 if (std::__invoke(__comp, std::__invoke(__proj, *__mid), __value)) {
45 __first = ++__mid;
46 __len -= __half_len + 1;
47 } else if (std::__invoke(__comp, __value, std::__invoke(__proj, *__mid))) {
48 __end = __mid;
49 __len = __half_len;
50 } else {
51 _Iter __mp1 = __mid;
52 return pair<_Iter, _Iter>(
53 std::__lower_bound_impl<_AlgPolicy>(__first, __mid, __value, __comp, __proj),
54 std::__upper_bound<_AlgPolicy>(++__mp1, __end, __value, __comp, __proj));
5655 }
57 return pair<_ForwardIterator, _ForwardIterator>(__first, __first);
56 }
57 return pair<_Iter, _Iter>(__first, __first);
5858}
5959
6060template <class _ForwardIterator, class _Tp, class _Compare>
61_LIBCPP_NODISCARD_EXT inline
62_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
63pair<_ForwardIterator, _ForwardIterator>
64equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
65{
66 typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
67 return _VSTD::__equal_range<_Comp_ref>(__first, __last, __value_, __comp);
61_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 pair<_ForwardIterator, _ForwardIterator>
62equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) {
63 static_assert(__is_callable<_Compare, decltype(*__first), const _Tp&>::value,
64 "The comparator has to be callable");
65 static_assert(is_copy_constructible<_ForwardIterator>::value,
66 "Iterator has to be copy constructible");
67 typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
68 return std::__equal_range<_ClassicAlgPolicy>(
69 std::move(__first), std::move(__last), __value, static_cast<_Comp_ref>(__comp), std::__identity());
6870}
6971
7072template <class _ForwardIterator, class _Tp>
71_LIBCPP_NODISCARD_EXT inline
72_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
73pair<_ForwardIterator, _ForwardIterator>
74equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_)
75{
76 return _VSTD::equal_range(__first, __last, __value_,
77 __less<typename iterator_traits<_ForwardIterator>::value_type, _Tp>());
73_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 pair<_ForwardIterator, _ForwardIterator>
74equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
75 return std::equal_range(
76 std::move(__first),
77 std::move(__last),
78 __value,
79 __less<typename iterator_traits<_ForwardIterator>::value_type, _Tp>());
7880}
7981
8082_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__algorithm/fill.h+9-7
......@@ -15,34 +15,36 @@
1515#include <type_traits>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
2222
23// fill isn't specialized for std::memset, because the compiler already optimizes the loop to a call to std::memset.
24
2325template <class _ForwardIterator, class _Tp>
2426inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
2527void
26__fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, forward_iterator_tag)
28__fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, forward_iterator_tag)
2729{
2830 for (; __first != __last; ++__first)
29 *__first = __value_;
31 *__first = __value;
3032}
3133
3234template <class _RandomAccessIterator, class _Tp>
3335inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
3436void
35__fill(_RandomAccessIterator __first, _RandomAccessIterator __last, const _Tp& __value_, random_access_iterator_tag)
37__fill(_RandomAccessIterator __first, _RandomAccessIterator __last, const _Tp& __value, random_access_iterator_tag)
3638{
37 _VSTD::fill_n(__first, __last - __first, __value_);
39 _VSTD::fill_n(__first, __last - __first, __value);
3840}
3941
4042template <class _ForwardIterator, class _Tp>
4143inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
4244void
43fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_)
45fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
4446{
45 _VSTD::__fill(__first, __last, __value_, typename iterator_traits<_ForwardIterator>::iterator_category());
47 _VSTD::__fill(__first, __last, __value, typename iterator_traits<_ForwardIterator>::iterator_category());
4648}
4749
4850_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__algorithm/fill_n.h+7-5
......@@ -14,27 +14,29 @@
1414#include <type_traits>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
17# pragma GCC system_header
1818#endif
1919
2020_LIBCPP_BEGIN_NAMESPACE_STD
2121
22// fill_n isn't specialized for std::memset, because the compiler already optimizes the loop to a call to std::memset.
23
2224template <class _OutputIterator, class _Size, class _Tp>
2325inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
2426_OutputIterator
25__fill_n(_OutputIterator __first, _Size __n, const _Tp& __value_)
27__fill_n(_OutputIterator __first, _Size __n, const _Tp& __value)
2628{
2729 for (; __n > 0; ++__first, (void) --__n)
28 *__first = __value_;
30 *__first = __value;
2931 return __first;
3032}
3133
3234template <class _OutputIterator, class _Size, class _Tp>
3335inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
3436_OutputIterator
35fill_n(_OutputIterator __first, _Size __n, const _Tp& __value_)
37fill_n(_OutputIterator __first, _Size __n, const _Tp& __value)
3638{
37 return _VSTD::__fill_n(__first, _VSTD::__convert_to_integral(__n), __value_);
39 return _VSTD::__fill_n(__first, _VSTD::__convert_to_integral(__n), __value);
3840}
3941
4042_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__algorithm/find.h+3-3
......@@ -13,16 +13,16 @@
1313#include <__config>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16#pragma GCC system_header
16# pragma GCC system_header
1717#endif
1818
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _InputIterator, class _Tp>
2222_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _InputIterator
23find(_InputIterator __first, _InputIterator __last, const _Tp& __value_) {
23find(_InputIterator __first, _InputIterator __last, const _Tp& __value) {
2424 for (; __first != __last; ++__first)
25 if (*__first == __value_)
25 if (*__first == __value)
2626 break;
2727 return __first;
2828}
lib/libcxx/include/__algorithm/find_end.h+131-52
......@@ -11,44 +11,69 @@
1111#define _LIBCPP___ALGORITHM_FIND_END_OF_H
1212
1313#include <__algorithm/comp.h>
14#include <__algorithm/iterator_operations.h>
15#include <__algorithm/search.h>
1416#include <__config>
17#include <__functional/identity.h>
18#include <__iterator/advance.h>
1519#include <__iterator/iterator_traits.h>
20#include <__iterator/next.h>
21#include <__iterator/reverse_iterator.h>
22#include <__utility/pair.h>
23#include <type_traits>
1624
1725#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
26# pragma GCC system_header
1927#endif
2028
2129_LIBCPP_BEGIN_NAMESPACE_STD
2230
23template <class _BinaryPredicate, class _ForwardIterator1, class _ForwardIterator2>
24_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator1 __find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
25 _ForwardIterator2 __first2, _ForwardIterator2 __last2,
26 _BinaryPredicate __pred, forward_iterator_tag,
27 forward_iterator_tag) {
31template <
32 class _AlgPolicy,
33 class _Iter1,
34 class _Sent1,
35 class _Iter2,
36 class _Sent2,
37 class _Pred,
38 class _Proj1,
39 class _Proj2>
40_LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR_AFTER_CXX11 pair<_Iter1, _Iter1> __find_end_impl(
41 _Iter1 __first1,
42 _Sent1 __last1,
43 _Iter2 __first2,
44 _Sent2 __last2,
45 _Pred& __pred,
46 _Proj1& __proj1,
47 _Proj2& __proj2,
48 forward_iterator_tag,
49 forward_iterator_tag) {
2850 // modeled after search algorithm
29 _ForwardIterator1 __r = __last1; // __last1 is the "default" answer
51 _Iter1 __match_first = _IterOps<_AlgPolicy>::next(__first1, __last1); // __last1 is the "default" answer
52 _Iter1 __match_last = __match_first;
3053 if (__first2 == __last2)
31 return __r;
54 return pair<_Iter1, _Iter1>(__match_last, __match_last);
3255 while (true) {
3356 while (true) {
34 if (__first1 == __last1) // if source exhausted return last correct answer
35 return __r; // (or __last1 if never found)
36 if (__pred(*__first1, *__first2))
57 if (__first1 == __last1) // if source exhausted return last correct answer (or __last1 if never found)
58 return pair<_Iter1, _Iter1>(__match_first, __match_last);
59 if (std::__invoke(__pred, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2)))
3760 break;
3861 ++__first1;
3962 }
4063 // *__first1 matches *__first2, now match elements after here
41 _ForwardIterator1 __m1 = __first1;
42 _ForwardIterator2 __m2 = __first2;
64 _Iter1 __m1 = __first1;
65 _Iter2 __m2 = __first2;
4366 while (true) {
4467 if (++__m2 == __last2) { // Pattern exhaused, record answer and search for another one
45 __r = __first1;
68 __match_first = __first1;
69 __match_last = ++__m1;
4670 ++__first1;
4771 break;
4872 }
4973 if (++__m1 == __last1) // Source exhausted, return last answer
50 return __r;
51 if (!__pred(*__m1, *__m2)) // mismatch, restart with a new __first
74 return pair<_Iter1, _Iter1>(__match_first, __match_last);
75 // mismatch, restart with a new __first
76 if (!std::__invoke(__pred, std::__invoke(__proj1, *__m1), std::__invoke(__proj2, *__m2)))
5277 {
5378 ++__first1;
5479 break;
......@@ -57,33 +82,52 @@ _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator1 __find_end(_ForwardIterator1 __f
5782 }
5883}
5984
60template <class _BinaryPredicate, class _BidirectionalIterator1, class _BidirectionalIterator2>
61_LIBCPP_CONSTEXPR_AFTER_CXX17 _BidirectionalIterator1 __find_end(
62 _BidirectionalIterator1 __first1, _BidirectionalIterator1 __last1, _BidirectionalIterator2 __first2,
63 _BidirectionalIterator2 __last2, _BinaryPredicate __pred, bidirectional_iterator_tag, bidirectional_iterator_tag) {
85template <
86 class _IterOps,
87 class _Pred,
88 class _Iter1,
89 class _Sent1,
90 class _Iter2,
91 class _Sent2,
92 class _Proj1,
93 class _Proj2>
94_LIBCPP_CONSTEXPR_AFTER_CXX17 _Iter1 __find_end(
95 _Iter1 __first1,
96 _Sent1 __sent1,
97 _Iter2 __first2,
98 _Sent2 __sent2,
99 _Pred& __pred,
100 _Proj1& __proj1,
101 _Proj2& __proj2,
102 bidirectional_iterator_tag,
103 bidirectional_iterator_tag) {
104 auto __last1 = _IterOps::next(__first1, __sent1);
105 auto __last2 = _IterOps::next(__first2, __sent2);
64106 // modeled after search algorithm (in reverse)
65107 if (__first2 == __last2)
66108 return __last1; // Everything matches an empty sequence
67 _BidirectionalIterator1 __l1 = __last1;
68 _BidirectionalIterator2 __l2 = __last2;
109 _Iter1 __l1 = __last1;
110 _Iter2 __l2 = __last2;
69111 --__l2;
70112 while (true) {
71113 // Find last element in sequence 1 that matchs *(__last2-1), with a mininum of loop checks
72114 while (true) {
73115 if (__first1 == __l1) // return __last1 if no element matches *__first2
74116 return __last1;
75 if (__pred(*--__l1, *__l2))
117 if (std::__invoke(__pred, std::__invoke(__proj1, *--__l1), std::__invoke(__proj2, *__l2)))
76118 break;
77119 }
78120 // *__l1 matches *__l2, now match elements before here
79 _BidirectionalIterator1 __m1 = __l1;
80 _BidirectionalIterator2 __m2 = __l2;
121 _Iter1 __m1 = __l1;
122 _Iter2 __m2 = __l2;
81123 while (true) {
82124 if (__m2 == __first2) // If pattern exhausted, __m1 is the answer (works for 1 element pattern)
83125 return __m1;
84126 if (__m1 == __first1) // Otherwise if source exhaused, pattern not found
85127 return __last1;
86 if (!__pred(*--__m1, *--__m2)) // if there is a mismatch, restart with a new __l1
128
129 // if there is a mismatch, restart with a new __l1
130 if (!std::__invoke(__pred, std::__invoke(__proj1, *--__m1), std::__invoke(__proj2, *--__m2)))
87131 {
88132 break;
89133 } // else there is a match, check next elements
......@@ -91,37 +135,53 @@ _LIBCPP_CONSTEXPR_AFTER_CXX17 _BidirectionalIterator1 __find_end(
91135 }
92136}
93137
94template <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2>
95_LIBCPP_CONSTEXPR_AFTER_CXX11 _RandomAccessIterator1 __find_end(
96 _RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2,
97 _RandomAccessIterator2 __last2, _BinaryPredicate __pred, random_access_iterator_tag, random_access_iterator_tag) {
98 typedef typename iterator_traits<_RandomAccessIterator1>::difference_type _D1;
99 typedef typename iterator_traits<_RandomAccessIterator2>::difference_type _D2;
138template <
139 class _AlgPolicy,
140 class _Pred,
141 class _Iter1,
142 class _Sent1,
143 class _Iter2,
144 class _Sent2,
145 class _Proj1,
146 class _Proj2>
147_LIBCPP_CONSTEXPR_AFTER_CXX11 _Iter1 __find_end(
148 _Iter1 __first1,
149 _Sent1 __sent1,
150 _Iter2 __first2,
151 _Sent2 __sent2,
152 _Pred& __pred,
153 _Proj1& __proj1,
154 _Proj2& __proj2,
155 random_access_iterator_tag,
156 random_access_iterator_tag) {
157 typedef typename iterator_traits<_Iter1>::difference_type _D1;
158 auto __last1 = _IterOps<_AlgPolicy>::next(__first1, __sent1);
159 auto __last2 = _IterOps<_AlgPolicy>::next(__first2, __sent2);
100160 // Take advantage of knowing source and pattern lengths. Stop short when source is smaller than pattern
101 _D2 __len2 = __last2 - __first2;
161 auto __len2 = __last2 - __first2;
102162 if (__len2 == 0)
103163 return __last1;
104 _D1 __len1 = __last1 - __first1;
164 auto __len1 = __last1 - __first1;
105165 if (__len1 < __len2)
106166 return __last1;
107 const _RandomAccessIterator1 __s = __first1 + _D1(__len2 - 1); // End of pattern match can't go before here
108 _RandomAccessIterator1 __l1 = __last1;
109 _RandomAccessIterator2 __l2 = __last2;
167 const _Iter1 __s = __first1 + _D1(__len2 - 1); // End of pattern match can't go before here
168 _Iter1 __l1 = __last1;
169 _Iter2 __l2 = __last2;
110170 --__l2;
111171 while (true) {
112172 while (true) {
113173 if (__s == __l1)
114174 return __last1;
115 if (__pred(*--__l1, *__l2))
175 if (std::__invoke(__pred, std::__invoke(__proj1, *--__l1), std::__invoke(__proj2, *__l2)))
116176 break;
117177 }
118 _RandomAccessIterator1 __m1 = __l1;
119 _RandomAccessIterator2 __m2 = __l2;
178 _Iter1 __m1 = __l1;
179 _Iter2 __m2 = __l2;
120180 while (true) {
121181 if (__m2 == __first2)
122182 return __m1;
123183 // no need to check range on __m1 because __s guarantees we have enough source
124 if (!__pred(*--__m1, *--__m2)) {
184 if (!std::__invoke(__pred, std::__invoke(__proj1, *--__m1), std::__invoke(*--__m2))) {
125185 break;
126186 }
127187 }
......@@ -129,20 +189,39 @@ _LIBCPP_CONSTEXPR_AFTER_CXX11 _RandomAccessIterator1 __find_end(
129189}
130190
131191template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
132_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator1
133find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2,
134 _BinaryPredicate __pred) {
135 return _VSTD::__find_end<_BinaryPredicate&>(
136 __first1, __last1, __first2, __last2, __pred, typename iterator_traits<_ForwardIterator1>::iterator_category(),
137 typename iterator_traits<_ForwardIterator2>::iterator_category());
192_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
193_ForwardIterator1 __find_end_classic(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
194 _ForwardIterator2 __first2, _ForwardIterator2 __last2,
195 _BinaryPredicate& __pred) {
196 auto __proj = __identity();
197 return std::__find_end_impl<_ClassicAlgPolicy>(
198 __first1,
199 __last1,
200 __first2,
201 __last2,
202 __pred,
203 __proj,
204 __proj,
205 typename iterator_traits<_ForwardIterator1>::iterator_category(),
206 typename iterator_traits<_ForwardIterator2>::iterator_category())
207 .first;
208}
209
210template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
211_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
212_ForwardIterator1 find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
213 _ForwardIterator2 __first2, _ForwardIterator2 __last2,
214 _BinaryPredicate __pred) {
215 return std::__find_end_classic(__first1, __last1, __first2, __last2, __pred);
138216}
139217
140218template <class _ForwardIterator1, class _ForwardIterator2>
141_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator1
142find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) {
143 typedef typename iterator_traits<_ForwardIterator1>::value_type __v1;
144 typedef typename iterator_traits<_ForwardIterator2>::value_type __v2;
145 return _VSTD::find_end(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>());
219_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
220_ForwardIterator1 find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
221 _ForwardIterator2 __first2, _ForwardIterator2 __last2) {
222 using __v1 = typename iterator_traits<_ForwardIterator1>::value_type;
223 using __v2 = typename iterator_traits<_ForwardIterator2>::value_type;
224 return std::find_end(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>());
146225}
147226
148227_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__algorithm/find_first_of.h+1-1
......@@ -15,7 +15,7 @@
1515#include <__iterator/iterator_traits.h>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/find_if.h+1-1
......@@ -13,7 +13,7 @@
1313#include <__config>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16#pragma GCC system_header
16# pragma GCC system_header
1717#endif
1818
1919_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/find_if_not.h+1-1
......@@ -13,7 +13,7 @@
1313#include <__config>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16#pragma GCC system_header
16# pragma GCC system_header
1717#endif
1818
1919_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/for_each.h+1-1
......@@ -13,7 +13,7 @@
1313#include <__config>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16#pragma GCC system_header
16# pragma GCC system_header
1717#endif
1818
1919_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/for_each_n.h+1-1
......@@ -14,7 +14,7 @@
1414#include <type_traits>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
17# pragma GCC system_header
1818#endif
1919
2020_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/generate.h+1-1
......@@ -12,7 +12,7 @@
1212#include <__config>
1313
1414#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15#pragma GCC system_header
15# pragma GCC system_header
1616#endif
1717
1818_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/generate_n.h+1-1
......@@ -13,7 +13,7 @@
1313#include <type_traits>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16#pragma GCC system_header
16# pragma GCC system_header
1717#endif
1818
1919_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/half_positive.h+1-1
......@@ -13,7 +13,7 @@
1313#include <type_traits>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16#pragma GCC system_header
16# pragma GCC system_header
1717#endif
1818
1919_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/in_found_result.h created+49
......@@ -0,0 +1,49 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___ALGORITHM_IN_FOUND_RESULT_H
11#define _LIBCPP___ALGORITHM_IN_FOUND_RESULT_H
12
13#include <__concepts/convertible_to.h>
14#include <__config>
15#include <__utility/move.h>
16
17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18# pragma GCC system_header
19#endif
20
21#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
22
23_LIBCPP_BEGIN_NAMESPACE_STD
24
25namespace ranges {
26template <class _InIter1>
27struct in_found_result {
28 _LIBCPP_NO_UNIQUE_ADDRESS _InIter1 in;
29 bool found;
30
31 template <class _InIter2>
32 requires convertible_to<const _InIter1&, _InIter2>
33 _LIBCPP_HIDE_FROM_ABI constexpr operator in_found_result<_InIter2>() const & {
34 return {in, found};
35 }
36
37 template <class _InIter2>
38 requires convertible_to<_InIter1, _InIter2>
39 _LIBCPP_HIDE_FROM_ABI constexpr operator in_found_result<_InIter2>() && {
40 return {std::move(in), found};
41 }
42};
43} // namespace ranges
44
45_LIBCPP_END_NAMESPACE_STD
46
47#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
48
49#endif // _LIBCPP___ALGORITHM_IN_FOUND_RESULT_H
lib/libcxx/include/__algorithm/in_fun_result.h created+49
......@@ -0,0 +1,49 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___ALGORITHM_IN_FUN_RESULT_H
11#define _LIBCPP___ALGORITHM_IN_FUN_RESULT_H
12
13#include <__concepts/convertible_to.h>
14#include <__config>
15#include <__utility/move.h>
16
17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18# pragma GCC system_header
19#endif
20
21_LIBCPP_BEGIN_NAMESPACE_STD
22
23#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
24
25namespace ranges {
26template <class _InIter1, class _Func1>
27struct in_fun_result {
28 _LIBCPP_NO_UNIQUE_ADDRESS _InIter1 in;
29 _LIBCPP_NO_UNIQUE_ADDRESS _Func1 fun;
30
31 template <class _InIter2, class _Func2>
32 requires convertible_to<const _InIter1&, _InIter2> && convertible_to<const _Func1&, _Func2>
33 _LIBCPP_HIDE_FROM_ABI constexpr operator in_fun_result<_InIter2, _Func2>() const & {
34 return {in, fun};
35 }
36
37 template <class _InIter2, class _Func2>
38 requires convertible_to<_InIter1, _InIter2> && convertible_to<_Func1, _Func2>
39 _LIBCPP_HIDE_FROM_ABI constexpr operator in_fun_result<_InIter2, _Func2>() && {
40 return {std::move(in), std::move(fun)};
41 }
42};
43} // namespace ranges
44
45#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
46
47_LIBCPP_END_NAMESPACE_STD
48
49#endif // _LIBCPP___ALGORITHM_IN_FUN_RESULT_H
lib/libcxx/include/__algorithm/in_in_out_result.h+16-14
......@@ -15,39 +15,41 @@
1515#include <__utility/move.h>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
2222
23#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
23#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
2424
2525namespace ranges {
2626
27template <class _I1, class _I2, class _O1>
27template <class _InIter1, class _InIter2, class _OutIter1>
2828struct in_in_out_result {
29 [[no_unique_address]] _I1 in1;
30 [[no_unique_address]] _I2 in2;
31 [[no_unique_address]] _O1 out;
29 _LIBCPP_NO_UNIQUE_ADDRESS _InIter1 in1;
30 _LIBCPP_NO_UNIQUE_ADDRESS _InIter2 in2;
31 _LIBCPP_NO_UNIQUE_ADDRESS _OutIter1 out;
3232
33 template <class _II1, class _II2, class _OO1>
34 requires convertible_to<const _I1&, _II1> && convertible_to<const _I2&, _II2> && convertible_to<const _O1&, _OO1>
33 template <class _InIter3, class _InIter4, class _OutIter2>
34 requires convertible_to<const _InIter1&, _InIter3>
35 && convertible_to<const _InIter2&, _InIter4> && convertible_to<const _OutIter1&, _OutIter2>
3536 _LIBCPP_HIDE_FROM_ABI constexpr
36 operator in_in_out_result<_II1, _II2, _OO1>() const& {
37 operator in_in_out_result<_InIter3, _InIter4, _OutIter2>() const& {
3738 return {in1, in2, out};
3839 }
3940
40 template <class _II1, class _II2, class _OO1>
41 requires convertible_to<_I1, _II1> && convertible_to<_I2, _II2> && convertible_to<_O1, _OO1>
41 template <class _InIter3, class _InIter4, class _OutIter2>
42 requires convertible_to<_InIter1, _InIter3>
43 && convertible_to<_InIter2, _InIter4> && convertible_to<_OutIter1, _OutIter2>
4244 _LIBCPP_HIDE_FROM_ABI constexpr
43 operator in_in_out_result<_II1, _II2, _OO1>() && {
44 return {_VSTD::move(in1), _VSTD::move(in2), _VSTD::move(out)};
45 operator in_in_out_result<_InIter3, _InIter4, _OutIter2>() && {
46 return {std::move(in1), std::move(in2), std::move(out)};
4547 }
4648};
4749
4850} // namespace ranges
4951
50#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
52#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
5153
5254_LIBCPP_END_NAMESPACE_STD
5355
lib/libcxx/include/__algorithm/in_in_result.h+14-12
......@@ -15,36 +15,38 @@
1515#include <__utility/move.h>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
2222
23#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
23#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
2424
2525namespace ranges {
2626
27template <class _I1, class _I2>
27template <class _InIter1, class _InIter2>
2828struct in_in_result {
29 [[no_unique_address]] _I1 in1;
30 [[no_unique_address]] _I2 in2;
29 _LIBCPP_NO_UNIQUE_ADDRESS _InIter1 in1;
30 _LIBCPP_NO_UNIQUE_ADDRESS _InIter2 in2;
3131
32 template <class _II1, class _II2>
33 requires convertible_to<const _I1&, _II1> && convertible_to<const _I2&, _II2>
32 template <class _InIter3, class _InIter4>
33 requires convertible_to<const _InIter1&, _InIter3> && convertible_to<const _InIter2&, _InIter4>
3434 _LIBCPP_HIDE_FROM_ABI constexpr
35 operator in_in_result<_II1, _II2>() const & {
35 operator in_in_result<_InIter3, _InIter4>() const & {
3636 return {in1, in2};
3737 }
3838
39 template <class _II1, class _II2>
40 requires convertible_to<_I1, _II1> && convertible_to<_I2, _II2>
39 template <class _InIter3, class _InIter4>
40 requires convertible_to<_InIter1, _InIter3> && convertible_to<_InIter2, _InIter4>
4141 _LIBCPP_HIDE_FROM_ABI constexpr
42 operator in_in_result<_II1, _II2>() && { return {_VSTD::move(in1), _VSTD::move(in2)}; }
42 operator in_in_result<_InIter3, _InIter4>() && {
43 return {std::move(in1), std::move(in2)};
44 }
4345};
4446
4547} // namespace ranges
4648
47#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
49#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
4850
4951_LIBCPP_END_NAMESPACE_STD
5052
lib/libcxx/include/__algorithm/in_out_out_result.h created+54
......@@ -0,0 +1,54 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___ALGORITHM_IN_OUT_OUT_RESULT_H
11#define _LIBCPP___ALGORITHM_IN_OUT_OUT_RESULT_H
12
13#include <__concepts/convertible_to.h>
14#include <__config>
15#include <__utility/move.h>
16
17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18# pragma GCC system_header
19#endif
20
21_LIBCPP_BEGIN_NAMESPACE_STD
22
23#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
24
25namespace ranges {
26template <class _InIter1, class _OutIter1, class _OutIter2>
27struct in_out_out_result {
28 _LIBCPP_NO_UNIQUE_ADDRESS _InIter1 in;
29 _LIBCPP_NO_UNIQUE_ADDRESS _OutIter1 out1;
30 _LIBCPP_NO_UNIQUE_ADDRESS _OutIter2 out2;
31
32 template <class _InIter2, class _OutIter3, class _OutIter4>
33 requires convertible_to<const _InIter1&, _InIter2>
34 && convertible_to<const _OutIter1&, _OutIter3> && convertible_to<const _OutIter2&, _OutIter4>
35 _LIBCPP_HIDE_FROM_ABI constexpr
36 operator in_out_out_result<_InIter2, _OutIter3, _OutIter4>() const& {
37 return {in, out1, out2};
38 }
39
40 template <class _InIter2, class _OutIter3, class _OutIter4>
41 requires convertible_to<_InIter1, _InIter2>
42 && convertible_to<_OutIter1, _OutIter3> && convertible_to<_OutIter2, _OutIter4>
43 _LIBCPP_HIDE_FROM_ABI constexpr
44 operator in_out_out_result<_InIter2, _OutIter3, _OutIter4>() && {
45 return {std::move(in), std::move(out1), std::move(out2)};
46 }
47};
48} // namespace ranges
49
50#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
51
52_LIBCPP_END_NAMESPACE_STD
53
54#endif // _LIBCPP___ALGORITHM_IN_OUT_OUT_RESULT_H
lib/libcxx/include/__algorithm/in_out_result.h+13-14
......@@ -15,39 +15,38 @@
1515#include <__utility/move.h>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
2222
23#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
23#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
2424
2525namespace ranges {
2626
27template<class _InputIterator, class _OutputIterator>
27template<class _InIter1, class _OutIter1>
2828struct in_out_result {
29 [[no_unique_address]] _InputIterator in;
30 [[no_unique_address]] _OutputIterator out;
29 _LIBCPP_NO_UNIQUE_ADDRESS _InIter1 in;
30 _LIBCPP_NO_UNIQUE_ADDRESS _OutIter1 out;
3131
32 template <class _InputIterator2, class _OutputIterator2>
33 requires convertible_to<const _InputIterator&, _InputIterator2> && convertible_to<const _OutputIterator&,
34 _OutputIterator2>
32 template <class _InIter2, class _OutIter2>
33 requires convertible_to<const _InIter1&, _InIter2> && convertible_to<const _OutIter1&, _OutIter2>
3534 _LIBCPP_HIDE_FROM_ABI
36 constexpr operator in_out_result<_InputIterator2, _OutputIterator2>() const & {
35 constexpr operator in_out_result<_InIter2, _OutIter2>() const & {
3736 return {in, out};
3837 }
3938
40 template <class _InputIterator2, class _OutputIterator2>
41 requires convertible_to<_InputIterator, _InputIterator2> && convertible_to<_OutputIterator, _OutputIterator2>
39 template <class _InIter2, class _OutIter2>
40 requires convertible_to<_InIter1, _InIter2> && convertible_to<_OutIter1, _OutIter2>
4241 _LIBCPP_HIDE_FROM_ABI
43 constexpr operator in_out_result<_InputIterator2, _OutputIterator2>() && {
44 return {_VSTD::move(in), _VSTD::move(out)};
42 constexpr operator in_out_result<_InIter2, _OutIter2>() && {
43 return {std::move(in), std::move(out)};
4544 }
4645};
4746
4847} // namespace ranges
4948
50#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
49#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
5150
5251_LIBCPP_END_NAMESPACE_STD
5352
lib/libcxx/include/__algorithm/includes.h+39-30
......@@ -12,49 +12,58 @@
1212#include <__algorithm/comp.h>
1313#include <__algorithm/comp_ref_type.h>
1414#include <__config>
15#include <__functional/identity.h>
16#include <__functional/invoke.h>
1517#include <__iterator/iterator_traits.h>
18#include <__type_traits/is_callable.h>
19#include <__utility/move.h>
1620
1721#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
22# pragma GCC system_header
1923#endif
2024
2125_LIBCPP_BEGIN_NAMESPACE_STD
2226
23template <class _Compare, class _InputIterator1, class _InputIterator2>
24_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
25__includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2,
26 _Compare __comp)
27{
28 for (; __first2 != __last2; ++__first1)
29 {
30 if (__first1 == __last1 || __comp(*__first2, *__first1))
31 return false;
32 if (!__comp(*__first1, *__first2))
33 ++__first2;
34 }
35 return true;
27template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Comp, class _Proj1, class _Proj2>
28_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 bool
29__includes(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2,
30 _Comp&& __comp, _Proj1&& __proj1, _Proj2&& __proj2) {
31 for (; __first2 != __last2; ++__first1) {
32 if (__first1 == __last1 || std::__invoke(
33 __comp, std::__invoke(__proj2, *__first2), std::__invoke(__proj1, *__first1)))
34 return false;
35 if (!std::__invoke(__comp, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2)))
36 ++__first2;
37 }
38 return true;
3639}
3740
3841template <class _InputIterator1, class _InputIterator2, class _Compare>
39_LIBCPP_NODISCARD_EXT inline
40_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
41bool
42includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2,
43 _Compare __comp)
44{
45 typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
46 return _VSTD::__includes<_Comp_ref>(__first1, __last1, __first2, __last2, __comp);
42_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 bool includes(
43 _InputIterator1 __first1,
44 _InputIterator1 __last1,
45 _InputIterator2 __first2,
46 _InputIterator2 __last2,
47 _Compare __comp) {
48 static_assert(__is_callable<_Compare, decltype(*__first1), decltype(*__first2)>::value,
49 "Comparator has to be callable");
50
51 typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
52 return std::__includes(
53 std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2),
54 static_cast<_Comp_ref>(__comp), __identity(), __identity());
4755}
4856
4957template <class _InputIterator1, class _InputIterator2>
50_LIBCPP_NODISCARD_EXT inline
51_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
52bool
53includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2)
54{
55 return _VSTD::includes(__first1, __last1, __first2, __last2,
56 __less<typename iterator_traits<_InputIterator1>::value_type,
57 typename iterator_traits<_InputIterator2>::value_type>());
58_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 bool
59includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) {
60 return std::includes(
61 std::move(__first1),
62 std::move(__last1),
63 std::move(__first2),
64 std::move(__last2),
65 __less<typename iterator_traits<_InputIterator1>::value_type,
66 typename iterator_traits<_InputIterator2>::value_type>());
5867}
5968
6069_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__algorithm/inplace_merge.h+77-54
......@@ -9,20 +9,25 @@
99#ifndef _LIBCPP___ALGORITHM_INPLACE_MERGE_H
1010#define _LIBCPP___ALGORITHM_INPLACE_MERGE_H
1111
12#include <__algorithm/algorithm_family.h>
1213#include <__algorithm/comp.h>
1314#include <__algorithm/comp_ref_type.h>
15#include <__algorithm/iterator_operations.h>
1416#include <__algorithm/lower_bound.h>
1517#include <__algorithm/min.h>
1618#include <__algorithm/move.h>
1719#include <__algorithm/rotate.h>
1820#include <__algorithm/upper_bound.h>
1921#include <__config>
22#include <__functional/identity.h>
23#include <__iterator/advance.h>
24#include <__iterator/distance.h>
2025#include <__iterator/iterator_traits.h>
21#include <__utility/swap.h>
26#include <__iterator/reverse_iterator.h>
2227#include <memory>
2328
2429#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
25#pragma GCC system_header
30# pragma GCC system_header
2631#endif
2732
2833_LIBCPP_PUSH_MACROS
......@@ -50,72 +55,79 @@ public:
5055 bool operator()(const _T1& __x, const _T2& __y) {return __p_(__y, __x);}
5156};
5257
53template <class _Compare, class _InputIterator1, class _InputIterator2,
54 class _OutputIterator>
55void __half_inplace_merge(_InputIterator1 __first1, _InputIterator1 __last1,
56 _InputIterator2 __first2, _InputIterator2 __last2,
57 _OutputIterator __result, _Compare __comp)
58template <class _AlgPolicy, class _Compare, class _InputIterator1, class _Sent1,
59 class _InputIterator2, class _Sent2, class _OutputIterator>
60void __half_inplace_merge(_InputIterator1 __first1, _Sent1 __last1,
61 _InputIterator2 __first2, _Sent2 __last2,
62 _OutputIterator __result, _Compare&& __comp)
5863{
5964 for (; __first1 != __last1; ++__result)
6065 {
6166 if (__first2 == __last2)
6267 {
63 _VSTD::move(__first1, __last1, __result);
68 _AlgFamily<_AlgPolicy>::__move(__first1, __last1, __result);
6469 return;
6570 }
6671
6772 if (__comp(*__first2, *__first1))
6873 {
69 *__result = _VSTD::move(*__first2);
74 *__result = _IterOps<_AlgPolicy>::__iter_move(__first2);
7075 ++__first2;
7176 }
7277 else
7378 {
74 *__result = _VSTD::move(*__first1);
79 *__result = _IterOps<_AlgPolicy>::__iter_move(__first1);
7580 ++__first1;
7681 }
7782 }
7883 // __first2 through __last2 are already in the right spot.
7984}
8085
81template <class _Compare, class _BidirectionalIterator>
82void
83__buffered_inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last,
84 _Compare __comp, typename iterator_traits<_BidirectionalIterator>::difference_type __len1,
85 typename iterator_traits<_BidirectionalIterator>::difference_type __len2,
86 typename iterator_traits<_BidirectionalIterator>::value_type* __buff)
87{
88 typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
86template <class _AlgPolicy, class _Compare, class _BidirectionalIterator>
87void __buffered_inplace_merge(
88 _BidirectionalIterator __first,
89 _BidirectionalIterator __middle,
90 _BidirectionalIterator __last,
91 _Compare&& __comp,
92 typename iterator_traits<_BidirectionalIterator>::difference_type __len1,
93 typename iterator_traits<_BidirectionalIterator>::difference_type __len2,
94 typename iterator_traits<_BidirectionalIterator>::value_type* __buff) {
95 typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
8996 __destruct_n __d(0);
9097 unique_ptr<value_type, __destruct_n&> __h2(__buff, __d);
9198 if (__len1 <= __len2)
9299 {
93100 value_type* __p = __buff;
94101 for (_BidirectionalIterator __i = __first; __i != __middle; __d.template __incr<value_type>(), (void) ++__i, (void) ++__p)
95 ::new ((void*)__p) value_type(_VSTD::move(*__i));
96 _VSTD::__half_inplace_merge<_Compare>(__buff, __p, __middle, __last, __first, __comp);
102 ::new ((void*)__p) value_type(_IterOps<_AlgPolicy>::__iter_move(__i));
103 std::__half_inplace_merge<_AlgPolicy>(__buff, __p, __middle, __last, __first, __comp);
97104 }
98105 else
99106 {
100107 value_type* __p = __buff;
101108 for (_BidirectionalIterator __i = __middle; __i != __last; __d.template __incr<value_type>(), (void) ++__i, (void) ++__p)
102 ::new ((void*)__p) value_type(_VSTD::move(*__i));
103 typedef reverse_iterator<_BidirectionalIterator> _RBi;
104 typedef reverse_iterator<value_type*> _Rv;
109 ::new ((void*)__p) value_type(_IterOps<_AlgPolicy>::__iter_move(__i));
110 typedef __unconstrained_reverse_iterator<_BidirectionalIterator> _RBi;
111 typedef __unconstrained_reverse_iterator<value_type*> _Rv;
105112 typedef __invert<_Compare> _Inverted;
106 _VSTD::__half_inplace_merge<_Inverted>(_Rv(__p), _Rv(__buff),
113 std::__half_inplace_merge<_AlgPolicy>(_Rv(__p), _Rv(__buff),
107114 _RBi(__middle), _RBi(__first),
108115 _RBi(__last), _Inverted(__comp));
109116 }
110117}
111118
112template <class _Compare, class _BidirectionalIterator>
113void
114__inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last,
115 _Compare __comp, typename iterator_traits<_BidirectionalIterator>::difference_type __len1,
116 typename iterator_traits<_BidirectionalIterator>::difference_type __len2,
117 typename iterator_traits<_BidirectionalIterator>::value_type* __buff, ptrdiff_t __buff_size)
118{
119template <class _AlgPolicy, class _Compare, class _BidirectionalIterator>
120void __inplace_merge(
121 _BidirectionalIterator __first,
122 _BidirectionalIterator __middle,
123 _BidirectionalIterator __last,
124 _Compare&& __comp,
125 typename iterator_traits<_BidirectionalIterator>::difference_type __len1,
126 typename iterator_traits<_BidirectionalIterator>::difference_type __len2,
127 typename iterator_traits<_BidirectionalIterator>::value_type* __buff,
128 ptrdiff_t __buff_size) {
129 using _Ops = _IterOps<_AlgPolicy>;
130
119131 typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
120132 while (true)
121133 {
......@@ -123,7 +135,7 @@ __inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle,
123135 if (__len2 == 0)
124136 return;
125137 if (__len1 <= __buff_size || __len2 <= __buff_size)
126 return _VSTD::__buffered_inplace_merge<_Compare>
138 return std::__buffered_inplace_merge<_AlgPolicy>
127139 (__first, __middle, __last, __comp, __len1, __len2, __buff);
128140 // shrink [__first, __middle) as much as possible (with no moves), returning if it shrinks to 0
129141 for (; true; ++__first, (void) --__len1)
......@@ -150,36 +162,37 @@ __inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle,
150162 { // __len >= 1, __len2 >= 2
151163 __len21 = __len2 / 2;
152164 __m2 = __middle;
153 _VSTD::advance(__m2, __len21);
154 __m1 = _VSTD::__upper_bound<_Compare>(__first, __middle, *__m2, __comp);
155 __len11 = _VSTD::distance(__first, __m1);
165 _Ops::advance(__m2, __len21);
166 __m1 = std::__upper_bound<_AlgPolicy>(__first, __middle, *__m2, __comp, std::__identity());
167 __len11 = _Ops::distance(__first, __m1);
156168 }
157169 else
158170 {
159171 if (__len1 == 1)
160172 { // __len1 >= __len2 && __len2 > 0, therefore __len2 == 1
161173 // It is known *__first > *__middle
162 swap(*__first, *__middle);
174 _Ops::iter_swap(__first, __middle);
163175 return;
164176 }
165177 // __len1 >= 2, __len2 >= 1
166178 __len11 = __len1 / 2;
167179 __m1 = __first;
168 _VSTD::advance(__m1, __len11);
169 __m2 = _VSTD::__lower_bound<_Compare>(__middle, __last, *__m1, __comp);
170 __len21 = _VSTD::distance(__middle, __m2);
180 _Ops::advance(__m1, __len11);
181 __m2 = std::lower_bound(__middle, __last, *__m1, __comp);
182 __len21 = _Ops::distance(__middle, __m2);
171183 }
172184 difference_type __len12 = __len1 - __len11; // distance(__m1, __middle)
173185 difference_type __len22 = __len2 - __len21; // distance(__m2, __last)
174186 // [__first, __m1) [__m1, __middle) [__middle, __m2) [__m2, __last)
175187 // swap middle two partitions
188 // TODO(alg-policy): pass `_AlgPolicy` once it's supported by `rotate`.
176189 __middle = _VSTD::rotate(__m1, __middle, __m2);
177190 // __len12 and __len21 now have swapped meanings
178191 // merge smaller range with recursive call and larger with tail recursion elimination
179192 if (__len11 + __len21 < __len12 + __len22)
180193 {
181 _VSTD::__inplace_merge<_Compare>(__first, __m1, __middle, __comp, __len11, __len21, __buff, __buff_size);
182// _VSTD::__inplace_merge<_Compare>(__middle, __m2, __last, __comp, __len12, __len22, __buff, __buff_size);
194 std::__inplace_merge<_AlgPolicy>(
195 __first, __m1, __middle, __comp, __len11, __len21, __buff, __buff_size);
183196 __first = __middle;
184197 __middle = __m2;
185198 __len1 = __len12;
......@@ -187,8 +200,8 @@ __inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle,
187200 }
188201 else
189202 {
190 _VSTD::__inplace_merge<_Compare>(__middle, __m2, __last, __comp, __len12, __len22, __buff, __buff_size);
191// _VSTD::__inplace_merge<_Compare>(__first, __m1, __middle, __comp, __len11, __len21, __buff, __buff_size);
203 std::__inplace_merge<_AlgPolicy>(
204 __middle, __m2, __last, __comp, __len12, __len22, __buff, __buff_size);
192205 __last = __middle;
193206 __middle = __m1;
194207 __len1 = __len11;
......@@ -197,30 +210,40 @@ __inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle,
197210 }
198211}
199212
200template <class _BidirectionalIterator, class _Compare>
201inline _LIBCPP_INLINE_VISIBILITY
213template <class _AlgPolicy, class _BidirectionalIterator, class _Compare>
214_LIBCPP_HIDE_FROM_ABI
202215void
203inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last,
204 _Compare __comp)
216__inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last,
217 _Compare&& __comp)
205218{
206219 typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
207220 typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
208 difference_type __len1 = _VSTD::distance(__first, __middle);
209 difference_type __len2 = _VSTD::distance(__middle, __last);
221 difference_type __len1 = _IterOps<_AlgPolicy>::distance(__first, __middle);
222 difference_type __len2 = _IterOps<_AlgPolicy>::distance(__middle, __last);
210223 difference_type __buf_size = _VSTD::min(__len1, __len2);
224// TODO: Remove the use of std::get_temporary_buffer
225_LIBCPP_SUPPRESS_DEPRECATED_PUSH
211226 pair<value_type*, ptrdiff_t> __buf = _VSTD::get_temporary_buffer<value_type>(__buf_size);
227_LIBCPP_SUPPRESS_DEPRECATED_POP
212228 unique_ptr<value_type, __return_temporary_buffer> __h(__buf.first);
213 typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
214 return _VSTD::__inplace_merge<_Comp_ref>(__first, __middle, __last, __comp, __len1, __len2,
215 __buf.first, __buf.second);
229 return std::__inplace_merge<_AlgPolicy>(
230 std::move(__first), std::move(__middle), std::move(__last), __comp, __len1, __len2, __buf.first, __buf.second);
231}
232
233template <class _BidirectionalIterator, class _Compare>
234inline _LIBCPP_HIDE_FROM_ABI void inplace_merge(
235 _BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last, _Compare __comp) {
236 typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
237 std::__inplace_merge<_ClassicAlgPolicy>(
238 std::move(__first), std::move(__middle), std::move(__last), static_cast<_Comp_ref>(__comp));
216239}
217240
218241template <class _BidirectionalIterator>
219inline _LIBCPP_INLINE_VISIBILITY
242inline _LIBCPP_HIDE_FROM_ABI
220243void
221244inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last)
222245{
223 _VSTD::inplace_merge(__first, __middle, __last,
246 std::inplace_merge(std::move(__first), std::move(__middle), std::move(__last),
224247 __less<typename iterator_traits<_BidirectionalIterator>::value_type>());
225248}
226249
lib/libcxx/include/__algorithm/is_heap.h+2-2
......@@ -16,7 +16,7 @@
1616#include <__iterator/iterator_traits.h>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
19# pragma GCC system_header
2020#endif
2121
2222_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -28,7 +28,7 @@ bool
2828is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
2929{
3030 typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
31 return _VSTD::__is_heap_until<_Comp_ref>(__first, __last, __comp) == __last;
31 return std::__is_heap_until(__first, __last, static_cast<_Comp_ref>(__comp)) == __last;
3232}
3333
3434template<class _RandomAccessIterator>
lib/libcxx/include/__algorithm/is_heap_until.h+3-3
......@@ -15,14 +15,14 @@
1515#include <__iterator/iterator_traits.h>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
2222
2323template <class _Compare, class _RandomAccessIterator>
2424_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _RandomAccessIterator
25__is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
25__is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare&& __comp)
2626{
2727 typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
2828 difference_type __len = __last - __first;
......@@ -52,7 +52,7 @@ _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
5252is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
5353{
5454 typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
55 return _VSTD::__is_heap_until<_Comp_ref>(__first, __last, __comp);
55 return std::__is_heap_until(__first, __last, static_cast<_Comp_ref>(__comp));
5656}
5757
5858template<class _RandomAccessIterator>
lib/libcxx/include/__algorithm/is_partitioned.h+1-1
......@@ -12,7 +12,7 @@
1212#include <__config>
1313
1414#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15#pragma GCC system_header
15# pragma GCC system_header
1616#endif
1717
1818_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/is_permutation.h+1-1
......@@ -17,7 +17,7 @@
1717#include <__iterator/next.h>
1818
1919#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20#pragma GCC system_header
20# pragma GCC system_header
2121#endif
2222
2323_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/is_sorted.h+1-1
......@@ -16,7 +16,7 @@
1616#include <__iterator/iterator_traits.h>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
19# pragma GCC system_header
2020#endif
2121
2222_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/is_sorted_until.h+1-1
......@@ -15,7 +15,7 @@
1515#include <__iterator/iterator_traits.h>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/iter_swap.h+1-1
......@@ -14,7 +14,7 @@
1414#include <__utility/swap.h>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
17# pragma GCC system_header
1818#endif
1919
2020_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/iterator_operations.h created+148
......@@ -0,0 +1,148 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_ITERATOR_OPERATIONS_H
10#define _LIBCPP___ALGORITHM_ITERATOR_OPERATIONS_H
11
12#include <__algorithm/iter_swap.h>
13#include <__config>
14#include <__iterator/advance.h>
15#include <__iterator/distance.h>
16#include <__iterator/iter_move.h>
17#include <__iterator/iter_swap.h>
18#include <__iterator/iterator_traits.h>
19#include <__iterator/next.h>
20#include <__iterator/readable_traits.h>
21#include <__utility/declval.h>
22#include <__utility/forward.h>
23#include <__utility/move.h>
24#include <type_traits>
25
26#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
27# pragma GCC system_header
28#endif
29
30_LIBCPP_BEGIN_NAMESPACE_STD
31
32template <class _AlgPolicy> struct _IterOps;
33
34#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
35struct _RangeAlgPolicy {};
36
37template <>
38struct _IterOps<_RangeAlgPolicy> {
39
40 template <class _Iter>
41 using __value_type = iter_value_t<_Iter>;
42
43 static constexpr auto advance = ranges::advance;
44 static constexpr auto distance = ranges::distance;
45 static constexpr auto __iter_move = ranges::iter_move;
46 static constexpr auto iter_swap = ranges::iter_swap;
47 static constexpr auto next = ranges::next;
48 static constexpr auto __advance_to = ranges::advance;
49};
50
51#endif
52
53struct _ClassicAlgPolicy {};
54
55template <>
56struct _IterOps<_ClassicAlgPolicy> {
57
58 template <class _Iter>
59 using __value_type = typename iterator_traits<_Iter>::value_type;
60
61 // advance
62 template <class _Iter, class _Distance>
63 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
64 static void advance(_Iter& __iter, _Distance __count) {
65 std::advance(__iter, __count);
66 }
67
68 // distance
69 template <class _Iter>
70 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
71 static typename iterator_traits<_Iter>::difference_type distance(_Iter __first, _Iter __last) {
72 return std::distance(__first, __last);
73 }
74
75 template <class _Iter>
76 using __deref_t = decltype(*std::declval<_Iter&>());
77
78 template <class _Iter>
79 using __move_t = decltype(std::move(*std::declval<_Iter&>()));
80
81 template <class _Iter>
82 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
83 static void __validate_iter_reference() {
84 static_assert(is_same<__deref_t<_Iter>, typename iterator_traits<__uncvref_t<_Iter> >::reference>::value,
85 "It looks like your iterator's `iterator_traits<It>::reference` does not match the return type of "
86 "dereferencing the iterator, i.e., calling `*it`. This is undefined behavior according to [input.iterators] "
87 "and can lead to dangling reference issues at runtime, so we are flagging this.");
88 }
89
90 // iter_move
91 template <class _Iter>
92 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 static
93 // If the result of dereferencing `_Iter` is a reference type, deduce the result of calling `std::move` on it. Note
94 // that the C++03 mode doesn't support `decltype(auto)` as the return type.
95 __enable_if_t<
96 is_reference<__deref_t<_Iter> >::value,
97 __move_t<_Iter> >
98 __iter_move(_Iter&& __i) {
99 __validate_iter_reference<_Iter>();
100
101 return std::move(*std::forward<_Iter>(__i));
102 }
103
104 template <class _Iter>
105 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 static
106 // If the result of dereferencing `_Iter` is a value type, deduce the return value of this function to also be a
107 // value -- otherwise, after `operator*` returns a temporary, this function would return a dangling reference to that
108 // temporary. Note that the C++03 mode doesn't support `auto` as the return type.
109 __enable_if_t<
110 !is_reference<__deref_t<_Iter> >::value,
111 __deref_t<_Iter> >
112 __iter_move(_Iter&& __i) {
113 __validate_iter_reference<_Iter>();
114
115 return *std::forward<_Iter>(__i);
116 }
117
118 // iter_swap
119 template <class _Iter1, class _Iter2>
120 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
121 static void iter_swap(_Iter1&& __a, _Iter2&& __b) {
122 std::iter_swap(std::forward<_Iter1>(__a), std::forward<_Iter2>(__b));
123 }
124
125 // next
126 template <class _Iterator>
127 _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_AFTER_CXX11
128 _Iterator next(_Iterator, _Iterator __last) {
129 return __last;
130 }
131
132 template <class _Iter>
133 _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_AFTER_CXX11
134 __uncvref_t<_Iter> next(_Iter&& __it,
135 typename iterator_traits<__uncvref_t<_Iter> >::difference_type __n = 1){
136 return std::next(std::forward<_Iter>(__it), __n);
137 }
138
139 template <class _Iter>
140 _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_AFTER_CXX11
141 void __advance_to(_Iter& __first, _Iter __last) {
142 __first = __last;
143 }
144};
145
146_LIBCPP_END_NAMESPACE_STD
147
148#endif // _LIBCPP___ALGORITHM_ITERATOR_OPERATIONS_H
lib/libcxx/include/__algorithm/lexicographical_compare.h+1-1
......@@ -15,7 +15,7 @@
1515#include <__iterator/iterator_traits.h>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/lower_bound.h+36-34
......@@ -11,54 +11,56 @@
1111
1212#include <__algorithm/comp.h>
1313#include <__algorithm/half_positive.h>
14#include <__algorithm/iterator_operations.h>
1415#include <__config>
15#include <iterator>
16#include <__functional/identity.h>
17#include <__functional/invoke.h>
18#include <__iterator/advance.h>
19#include <__iterator/distance.h>
20#include <__iterator/iterator_traits.h>
21#include <__type_traits/is_callable.h>
22#include <__type_traits/remove_reference.h>
23#include <type_traits>
1624
1725#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
26# pragma GCC system_header
1927#endif
2028
2129_LIBCPP_BEGIN_NAMESPACE_STD
2230
23template <class _Compare, class _ForwardIterator, class _Tp>
24_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
25__lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
26{
27 typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type;
28 difference_type __len = _VSTD::distance(__first, __last);
29 while (__len != 0)
30 {
31 difference_type __l2 = _VSTD::__half_positive(__len);
32 _ForwardIterator __m = __first;
33 _VSTD::advance(__m, __l2);
34 if (__comp(*__m, __value_))
35 {
36 __first = ++__m;
37 __len -= __l2 + 1;
38 }
39 else
40 __len = __l2;
31template <class _AlgPolicy, class _Iter, class _Sent, class _Type, class _Proj, class _Comp>
32_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
33_Iter __lower_bound_impl(_Iter __first, _Sent __last, const _Type& __value, _Comp& __comp, _Proj& __proj) {
34 auto __len = _IterOps<_AlgPolicy>::distance(__first, __last);
35
36 while (__len != 0) {
37 auto __l2 = std::__half_positive(__len);
38 _Iter __m = __first;
39 _IterOps<_AlgPolicy>::advance(__m, __l2);
40 if (std::__invoke(__comp, std::__invoke(__proj, *__m), __value)) {
41 __first = ++__m;
42 __len -= __l2 + 1;
43 } else {
44 __len = __l2;
4145 }
42 return __first;
46 }
47 return __first;
4348}
4449
4550template <class _ForwardIterator, class _Tp, class _Compare>
46_LIBCPP_NODISCARD_EXT inline
47_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
48_ForwardIterator
49lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
50{
51 return _VSTD::__lower_bound<_Compare&>(__first, __last, __value_, __comp);
51_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
52_ForwardIterator lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) {
53 static_assert(__is_callable<_Compare, decltype(*__first), const _Tp&>::value,
54 "The comparator has to be callable");
55 auto __proj = std::__identity();
56 return std::__lower_bound_impl<_ClassicAlgPolicy>(__first, __last, __value, __comp, __proj);
5257}
5358
5459template <class _ForwardIterator, class _Tp>
55_LIBCPP_NODISCARD_EXT inline
56_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
57_ForwardIterator
58lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_)
59{
60 return _VSTD::lower_bound(__first, __last, __value_,
61 __less<typename iterator_traits<_ForwardIterator>::value_type, _Tp>());
60_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
61_ForwardIterator lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
62 return std::lower_bound(__first, __last, __value,
63 __less<typename iterator_traits<_ForwardIterator>::value_type, _Tp>());
6264}
6365
6466_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__algorithm/make_heap.h+23-25
......@@ -11,47 +11,45 @@
1111
1212#include <__algorithm/comp.h>
1313#include <__algorithm/comp_ref_type.h>
14#include <__algorithm/iterator_operations.h>
1415#include <__algorithm/sift_down.h>
1516#include <__config>
1617#include <__iterator/iterator_traits.h>
18#include <__utility/move.h>
1719
1820#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
21# pragma GCC system_header
2022#endif
2123
2224_LIBCPP_BEGIN_NAMESPACE_STD
2325
24template <class _Compare, class _RandomAccessIterator>
25_LIBCPP_CONSTEXPR_AFTER_CXX11 void
26__make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
27{
28 typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
29 difference_type __n = __last - __first;
30 if (__n > 1)
31 {
32 // start from the first parent, there is no need to consider children
33 for (difference_type __start = (__n - 2) / 2; __start >= 0; --__start)
34 {
35 _VSTD::__sift_down<_Compare>(__first, __comp, __n, __first + __start);
36 }
26template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
27inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
28void __make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare&& __comp) {
29 using _CompRef = typename __comp_ref_type<_Compare>::type;
30 _CompRef __comp_ref = __comp;
31
32 using difference_type = typename iterator_traits<_RandomAccessIterator>::difference_type;
33 difference_type __n = __last - __first;
34 if (__n > 1) {
35 // start from the first parent, there is no need to consider children
36 for (difference_type __start = (__n - 2) / 2; __start >= 0; --__start) {
37 std::__sift_down<_AlgPolicy>(__first, __comp_ref, __n, __first + __start);
3738 }
39 }
3840}
3941
4042template <class _RandomAccessIterator, class _Compare>
41inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
42void
43make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
44{
45 typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
46 _VSTD::__make_heap<_Comp_ref>(__first, __last, __comp);
43inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
44void make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) {
45 std::__make_heap<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __comp);
4746}
4847
4948template <class _RandomAccessIterator>
50inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
51void
52make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
53{
54 _VSTD::make_heap(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
49inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
50void make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) {
51 std::make_heap(std::move(__first), std::move(__last),
52 __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
5553}
5654
5755_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__algorithm/make_projected.h created+126
......@@ -0,0 +1,126 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_MAKE_PROJECTED_H
10#define _LIBCPP___ALGORITHM_MAKE_PROJECTED_H
11
12#include <__concepts/same_as.h>
13#include <__config>
14#include <__functional/identity.h>
15#include <__functional/invoke.h>
16#include <__type_traits/decay.h>
17#include <__type_traits/enable_if.h>
18#include <__type_traits/integral_constant.h>
19#include <__type_traits/is_member_pointer.h>
20#include <__type_traits/is_same.h>
21#include <__utility/declval.h>
22#include <__utility/forward.h>
23
24#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
25# pragma GCC system_header
26#endif
27
28_LIBCPP_BEGIN_NAMESPACE_STD
29
30template <class _Pred, class _Proj>
31struct _ProjectedPred {
32 _Pred& __pred; // Can be a unary or a binary predicate.
33 _Proj& __proj;
34
35 _LIBCPP_CONSTEXPR _ProjectedPred(_Pred& __pred_arg, _Proj& __proj_arg) : __pred(__pred_arg), __proj(__proj_arg) {}
36
37 template <class _Tp>
38 typename __invoke_of<_Pred&,
39 decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_Tp>()))
40 >::type
41 _LIBCPP_CONSTEXPR operator()(_Tp&& __v) const {
42 return std::__invoke(__pred, std::__invoke(__proj, std::forward<_Tp>(__v)));
43 }
44
45 template <class _T1, class _T2>
46 typename __invoke_of<_Pred&,
47 decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_T1>())),
48 decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_T2>()))
49 >::type
50 _LIBCPP_CONSTEXPR operator()(_T1&& __lhs, _T2&& __rhs) const {
51 return std::__invoke(__pred,
52 std::__invoke(__proj, std::forward<_T1>(__lhs)),
53 std::__invoke(__proj, std::forward<_T2>(__rhs)));
54 }
55
56};
57
58template <class _Pred, class _Proj, class = void>
59struct __can_use_pristine_comp : false_type {};
60
61template <class _Pred, class _Proj>
62struct __can_use_pristine_comp<_Pred, _Proj, __enable_if_t<
63 !is_member_pointer<typename decay<_Pred>::type>::value && (
64#if _LIBCPP_STD_VER > 17
65 is_same<typename decay<_Proj>::type, identity>::value ||
66#endif
67 is_same<typename decay<_Proj>::type, __identity>::value
68 )
69> > : true_type {};
70
71template <class _Pred, class _Proj>
72_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR static
73__enable_if_t<
74 !__can_use_pristine_comp<_Pred, _Proj>::value,
75 _ProjectedPred<_Pred, _Proj>
76>
77__make_projected(_Pred& __pred, _Proj& __proj) {
78 return _ProjectedPred<_Pred, _Proj>(__pred, __proj);
79}
80
81// Avoid creating the functor and just use the pristine comparator -- for certain algorithms, this would enable
82// optimizations that rely on the type of the comparator. Additionally, this results in less layers of indirection in
83// the call stack when the comparator is invoked, even in an unoptimized build.
84template <class _Pred, class _Proj>
85_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR static
86__enable_if_t<
87 __can_use_pristine_comp<_Pred, _Proj>::value,
88 _Pred&
89>
90__make_projected(_Pred& __pred, _Proj&) {
91 return __pred;
92}
93
94_LIBCPP_END_NAMESPACE_STD
95
96#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
97
98_LIBCPP_BEGIN_NAMESPACE_STD
99
100namespace ranges {
101
102template <class _Comp, class _Proj1, class _Proj2>
103_LIBCPP_HIDE_FROM_ABI constexpr static
104decltype(auto) __make_projected_comp(_Comp& __comp, _Proj1& __proj1, _Proj2& __proj2) {
105 if constexpr (same_as<decay_t<_Proj1>, identity> && same_as<decay_t<_Proj2>, identity> &&
106 !is_member_pointer_v<decay_t<_Comp>>) {
107 // Avoid creating the lambda and just use the pristine comparator -- for certain algorithms, this would enable
108 // optimizations that rely on the type of the comparator.
109 return __comp;
110
111 } else {
112 return [&](auto&& __lhs, auto&& __rhs) {
113 return std::invoke(__comp,
114 std::invoke(__proj1, std::forward<decltype(__lhs)>(__lhs)),
115 std::invoke(__proj2, std::forward<decltype(__rhs)>(__rhs)));
116 };
117 }
118}
119
120} // namespace ranges
121
122_LIBCPP_END_NAMESPACE_STD
123
124#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
125
126#endif // _LIBCPP___ALGORITHM_MAKE_PROJECTED_H
lib/libcxx/include/__algorithm/max.h+1-1
......@@ -16,7 +16,7 @@
1616#include <initializer_list>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
19# pragma GCC system_header
2020#endif
2121
2222_LIBCPP_PUSH_MACROS
lib/libcxx/include/__algorithm/max_element.h+1-1
......@@ -15,7 +15,7 @@
1515#include <__iterator/iterator_traits.h>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/merge.h+1-1
......@@ -16,7 +16,7 @@
1616#include <__iterator/iterator_traits.h>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
19# pragma GCC system_header
2020#endif
2121
2222_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/min.h+1-1
......@@ -16,7 +16,7 @@
1616#include <initializer_list>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
19# pragma GCC system_header
2020#endif
2121
2222_LIBCPP_PUSH_MACROS
lib/libcxx/include/__algorithm/min_element.h+30-16
......@@ -12,36 +12,50 @@
1212#include <__algorithm/comp.h>
1313#include <__algorithm/comp_ref_type.h>
1414#include <__config>
15#include <__functional/identity.h>
16#include <__functional/invoke.h>
1517#include <__iterator/iterator_traits.h>
18#include <__type_traits/is_callable.h>
19#include <__utility/move.h>
1620
1721#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
22# pragma GCC system_header
1923#endif
2024
2125_LIBCPP_BEGIN_NAMESPACE_STD
2226
23template <class _Compare, class _ForwardIterator>
24inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator
25__min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
26{
27 static_assert(__is_cpp17_forward_iterator<_ForwardIterator>::value,
28 "std::min_element requires a ForwardIterator");
29 if (__first != __last)
30 {
31 _ForwardIterator __i = __first;
32 while (++__i != __last)
33 if (__comp(*__i, *__first))
34 __first = __i;
35 }
27template <class _Comp, class _Iter, class _Sent, class _Proj>
28inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
29_Iter __min_element(_Iter __first, _Sent __last, _Comp __comp, _Proj& __proj) {
30 if (__first == __last)
3631 return __first;
32
33 _Iter __i = __first;
34 while (++__i != __last)
35 if (std::__invoke(__comp, std::__invoke(__proj, *__i), std::__invoke(__proj, *__first)))
36 __first = __i;
37
38 return __first;
39}
40
41template <class _Comp, class _Iter, class _Sent>
42_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
43_Iter __min_element(_Iter __first, _Sent __last, _Comp __comp) {
44 auto __proj = __identity();
45 return std::__min_element<_Comp>(std::move(__first), std::move(__last), __comp, __proj);
3746}
3847
3948template <class _ForwardIterator, class _Compare>
4049_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator
4150min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
4251{
43 typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
44 return _VSTD::__min_element<_Comp_ref>(__first, __last, __comp);
52 static_assert(__is_cpp17_forward_iterator<_ForwardIterator>::value,
53 "std::min_element requires a ForwardIterator");
54 static_assert(__is_callable<_Compare, decltype(*__first), decltype(*__first)>::value,
55 "The comparator has to be callable");
56
57 typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
58 return std::__min_element<_Comp_ref>(std::move(__first), std::move(__last), __comp);
4559}
4660
4761template <class _ForwardIterator>
lib/libcxx/include/__algorithm/min_max_result.h created+56
......@@ -0,0 +1,56 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___ALGORITHM_MIN_MAX_RESULT_H
11#define _LIBCPP___ALGORITHM_MIN_MAX_RESULT_H
12
13#include <__concepts/convertible_to.h>
14#include <__config>
15#include <__utility/move.h>
16
17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18# pragma GCC system_header
19#endif
20
21_LIBCPP_PUSH_MACROS
22#include <__undef_macros>
23
24_LIBCPP_BEGIN_NAMESPACE_STD
25
26#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
27
28namespace ranges {
29
30template <class _T1>
31struct min_max_result {
32 _LIBCPP_NO_UNIQUE_ADDRESS _T1 min;
33 _LIBCPP_NO_UNIQUE_ADDRESS _T1 max;
34
35 template <class _T2>
36 requires convertible_to<const _T1&, _T2>
37 _LIBCPP_HIDE_FROM_ABI constexpr operator min_max_result<_T2>() const & {
38 return {min, max};
39 }
40
41 template <class _T2>
42 requires convertible_to<_T1, _T2>
43 _LIBCPP_HIDE_FROM_ABI constexpr operator min_max_result<_T2>() && {
44 return {std::move(min), std::move(max)};
45 }
46};
47
48} // namespace ranges
49
50#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
51
52_LIBCPP_END_NAMESPACE_STD
53
54_LIBCPP_POP_MACROS
55
56#endif // _LIBCPP___ALGORITHM_MIN_MAX_RESULT_H
lib/libcxx/include/__algorithm/minmax.h+13-39
......@@ -10,12 +10,15 @@
1010#define _LIBCPP___ALGORITHM_MINMAX_H
1111
1212#include <__algorithm/comp.h>
13#include <__algorithm/minmax_element.h>
1314#include <__config>
15#include <__functional/identity.h>
16#include <__type_traits/is_callable.h>
17#include <__utility/pair.h>
1418#include <initializer_list>
15#include <utility>
1619
1720#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
21# pragma GCC system_header
1922#endif
2023
2124_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -36,47 +39,18 @@ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
3639pair<const _Tp&, const _Tp&>
3740minmax(const _Tp& __a, const _Tp& __b)
3841{
39 return _VSTD::minmax(__a, __b, __less<_Tp>());
42 return std::minmax(__a, __b, __less<_Tp>());
4043}
4144
4245#ifndef _LIBCPP_CXX03_LANG
4346
4447template<class _Tp, class _Compare>
45_LIBCPP_NODISCARD_EXT inline
46_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
47pair<_Tp, _Tp>
48minmax(initializer_list<_Tp> __t, _Compare __comp)
49{
50 typedef typename initializer_list<_Tp>::const_iterator _Iter;
51 _Iter __first = __t.begin();
52 _Iter __last = __t.end();
53 pair<_Tp, _Tp> __result(*__first, *__first);
54
55 ++__first;
56 if (__t.size() % 2 == 0)
57 {
58 if (__comp(*__first, __result.first))
59 __result.first = *__first;
60 else
61 __result.second = *__first;
62 ++__first;
63 }
64
65 while (__first != __last)
66 {
67 _Tp __prev = *__first++;
68 if (__comp(*__first, __prev)) {
69 if ( __comp(*__first, __result.first)) __result.first = *__first;
70 if (!__comp(__prev, __result.second)) __result.second = __prev;
71 }
72 else {
73 if ( __comp(__prev, __result.first)) __result.first = __prev;
74 if (!__comp(*__first, __result.second)) __result.second = *__first;
75 }
76
77 __first++;
78 }
79 return __result;
48_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
49pair<_Tp, _Tp> minmax(initializer_list<_Tp> __t, _Compare __comp) {
50 static_assert(__is_callable<_Compare, _Tp, _Tp>::value, "The comparator has to be callable");
51 __identity __proj;
52 auto __ret = std::__minmax_element_impl(__t.begin(), __t.end(), __comp, __proj);
53 return pair<_Tp, _Tp>(*__ret.first, *__ret.second);
8054}
8155
8256template<class _Tp>
......@@ -85,7 +59,7 @@ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
8559pair<_Tp, _Tp>
8660minmax(initializer_list<_Tp> __t)
8761{
88 return _VSTD::minmax(__t, __less<_Tp>());
62 return std::minmax(__t, __less<_Tp>());
8963}
9064
9165#endif // _LIBCPP_CXX03_LANG
lib/libcxx/include/__algorithm/minmax_element.h+69-53
......@@ -11,73 +11,89 @@
1111
1212#include <__algorithm/comp.h>
1313#include <__config>
14#include <__functional/identity.h>
1415#include <__iterator/iterator_traits.h>
15#include <utility>
16#include <__utility/pair.h>
17#include <type_traits>
1618
1719#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
20# pragma GCC system_header
1921#endif
2022
2123_LIBCPP_BEGIN_NAMESPACE_STD
2224
25template <class _Comp, class _Proj>
26class _MinmaxElementLessFunc {
27 _Comp& __comp_;
28 _Proj& __proj_;
29
30public:
31 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
32 _MinmaxElementLessFunc(_Comp& __comp, _Proj& __proj) : __comp_(__comp), __proj_(__proj) {}
33
34 template <class _Iter>
35 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
36 bool operator()(_Iter& __it1, _Iter& __it2) {
37 return std::__invoke(__comp_, std::__invoke(__proj_, *__it1), std::__invoke(__proj_, *__it2));
38 }
39};
40
41template <class _Iter, class _Sent, class _Proj, class _Comp>
42_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
43pair<_Iter, _Iter> __minmax_element_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) {
44 auto __less = _MinmaxElementLessFunc<_Comp, _Proj>(__comp, __proj);
45
46 pair<_Iter, _Iter> __result(__first, __first);
47 if (__first == __last || ++__first == __last)
48 return __result;
49
50 if (__less(__first, __result.first))
51 __result.first = __first;
52 else
53 __result.second = __first;
54
55 while (++__first != __last) {
56 _Iter __i = __first;
57 if (++__first == __last) {
58 if (__less(__i, __result.first))
59 __result.first = __i;
60 else if (!__less(__i, __result.second))
61 __result.second = __i;
62 return __result;
63 }
64
65 if (__less(__first, __i)) {
66 if (__less(__first, __result.first))
67 __result.first = __first;
68 if (!__less(__i, __result.second))
69 __result.second = __i;
70 } else {
71 if (__less(__i, __result.first))
72 __result.first = __i;
73 if (!__less(__first, __result.second))
74 __result.second = __first;
75 }
76 }
77
78 return __result;
79}
80
2381template <class _ForwardIterator, class _Compare>
2482_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX11
2583pair<_ForwardIterator, _ForwardIterator>
26minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
27{
84minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) {
2885 static_assert(__is_cpp17_forward_iterator<_ForwardIterator>::value,
29 "std::minmax_element requires a ForwardIterator");
30 pair<_ForwardIterator, _ForwardIterator> __result(__first, __first);
31 if (__first != __last)
32 {
33 if (++__first != __last)
34 {
35 if (__comp(*__first, *__result.first))
36 __result.first = __first;
37 else
38 __result.second = __first;
39 while (++__first != __last)
40 {
41 _ForwardIterator __i = __first;
42 if (++__first == __last)
43 {
44 if (__comp(*__i, *__result.first))
45 __result.first = __i;
46 else if (!__comp(*__i, *__result.second))
47 __result.second = __i;
48 break;
49 }
50 else
51 {
52 if (__comp(*__first, *__i))
53 {
54 if (__comp(*__first, *__result.first))
55 __result.first = __first;
56 if (!__comp(*__i, *__result.second))
57 __result.second = __i;
58 }
59 else
60 {
61 if (__comp(*__i, *__result.first))
62 __result.first = __i;
63 if (!__comp(*__first, *__result.second))
64 __result.second = __first;
65 }
66 }
67 }
68 }
69 }
70 return __result;
86 "std::minmax_element requires a ForwardIterator");
87 static_assert(__is_callable<_Compare, decltype(*__first), decltype(*__first)>::value,
88 "The comparator has to be callable");
89 auto __proj = __identity();
90 return std::__minmax_element_impl(__first, __last, __comp, __proj);
7191}
7292
7393template <class _ForwardIterator>
74_LIBCPP_NODISCARD_EXT inline
75_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
76pair<_ForwardIterator, _ForwardIterator>
77minmax_element(_ForwardIterator __first, _ForwardIterator __last)
78{
79 return _VSTD::minmax_element(__first, __last,
80 __less<typename iterator_traits<_ForwardIterator>::value_type>());
94_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
95pair<_ForwardIterator, _ForwardIterator> minmax_element(_ForwardIterator __first, _ForwardIterator __last) {
96 return std::minmax_element(__first, __last, __less<typename iterator_traits<_ForwardIterator>::value_type>());
8197}
8298
8399_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__algorithm/mismatch.h+2-2
......@@ -13,10 +13,10 @@
1313#include <__algorithm/comp.h>
1414#include <__config>
1515#include <__iterator/iterator_traits.h>
16#include <utility>
16#include <__utility/pair.h>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
19# pragma GCC system_header
2020#endif
2121
2222_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/move.h+78-41
......@@ -11,66 +11,103 @@
1111
1212#include <__algorithm/unwrap_iter.h>
1313#include <__config>
14#include <__iterator/iterator_traits.h>
15#include <__iterator/reverse_iterator.h>
1416#include <__utility/move.h>
17#include <__utility/pair.h>
1518#include <cstring>
1619#include <type_traits>
17#include <utility>
1820
1921#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20#pragma GCC system_header
22# pragma GCC system_header
2123#endif
2224
2325_LIBCPP_BEGIN_NAMESPACE_STD
2426
2527// move
2628
27template <class _InputIterator, class _OutputIterator>
29template <class _InIter, class _Sent, class _OutIter>
2830inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
29_OutputIterator
30__move_constexpr(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
31{
32 for (; __first != __last; ++__first, (void) ++__result)
33 *__result = _VSTD::move(*__first);
34 return __result;
31pair<_InIter, _OutIter> __move_impl(_InIter __first, _Sent __last, _OutIter __result) {
32 while (__first != __last) {
33 *__result = std::move(*__first);
34 ++__first;
35 ++__result;
36 }
37 return std::make_pair(std::move(__first), std::move(__result));
3538}
3639
37template <class _InputIterator, class _OutputIterator>
38inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
39_OutputIterator
40__move(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
41{
42 return _VSTD::__move_constexpr(__first, __last, __result);
40template <class _InType,
41 class _OutType,
42 class = __enable_if_t<is_same<typename remove_const<_InType>::type, _OutType>::value
43 && is_trivially_move_assignable<_OutType>::value> >
44inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
45pair<_InType*, _OutType*> __move_impl(_InType* __first, _InType* __last, _OutType* __result) {
46 if (__libcpp_is_constant_evaluated()
47// TODO: Remove this once GCC supports __builtin_memmove during constant evaluation
48#ifndef _LIBCPP_COMPILER_GCC
49 && !is_trivially_copyable<_InType>::value
50#endif
51 )
52 return std::__move_impl<_InType*, _InType*, _OutType*>(__first, __last, __result);
53 const size_t __n = static_cast<size_t>(__last - __first);
54 ::__builtin_memmove(__result, __first, __n * sizeof(_OutType));
55 return std::make_pair(__first + __n, __result + __n);
4356}
4457
45template <class _Tp, class _Up>
46inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
47typename enable_if
48<
49 is_same<typename remove_const<_Tp>::type, _Up>::value &&
50 is_trivially_move_assignable<_Up>::value,
51 _Up*
52>::type
53__move(_Tp* __first, _Tp* __last, _Up* __result)
54{
55 const size_t __n = static_cast<size_t>(__last - __first);
56 if (__n > 0)
57 _VSTD::memmove(__result, __first, __n * sizeof(_Up));
58 return __result + __n;
58template <class>
59struct __is_trivially_move_assignable_unwrapped_impl : false_type {};
60
61template <class _Type>
62struct __is_trivially_move_assignable_unwrapped_impl<_Type*> : is_trivially_move_assignable<_Type> {};
63
64template <class _Iter>
65struct __is_trivially_move_assignable_unwrapped
66 : __is_trivially_move_assignable_unwrapped_impl<decltype(std::__unwrap_iter<_Iter>(std::declval<_Iter>()))> {};
67
68template <class _InIter,
69 class _OutIter,
70 __enable_if_t<is_same<typename remove_const<typename iterator_traits<_InIter>::value_type>::type,
71 typename iterator_traits<_OutIter>::value_type>::value
72 && __is_cpp17_contiguous_iterator<_InIter>::value
73 && __is_cpp17_contiguous_iterator<_OutIter>::value
74 && is_trivially_move_assignable<__iter_value_type<_OutIter> >::value, int> = 0>
75inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
76pair<reverse_iterator<_InIter>, reverse_iterator<_OutIter> >
77__move_impl(reverse_iterator<_InIter> __first,
78 reverse_iterator<_InIter> __last,
79 reverse_iterator<_OutIter> __result) {
80 auto __first_base = std::__unwrap_iter(__first.base());
81 auto __last_base = std::__unwrap_iter(__last.base());
82 auto __result_base = std::__unwrap_iter(__result.base());
83 auto __result_first = __result_base - (__first_base - __last_base);
84 std::__move_impl(__last_base, __first_base, __result_first);
85 return std::make_pair(__last, reverse_iterator<_OutIter>(std::__rewrap_iter(__result.base(), __result_first)));
86}
87
88template <class _InIter, class _Sent, class _OutIter>
89inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
90__enable_if_t<is_copy_constructible<_InIter>::value
91 && is_copy_constructible<_Sent>::value
92 && is_copy_constructible<_OutIter>::value, pair<_InIter, _OutIter> >
93__move(_InIter __first, _Sent __last, _OutIter __result) {
94 auto __ret = std::__move_impl(std::__unwrap_iter(__first), std::__unwrap_iter(__last), std::__unwrap_iter(__result));
95 return std::make_pair(std::__rewrap_iter(__first, __ret.first), std::__rewrap_iter(__result, __ret.second));
96}
97
98template <class _InIter, class _Sent, class _OutIter>
99inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
100__enable_if_t<!is_copy_constructible<_InIter>::value
101 || !is_copy_constructible<_Sent>::value
102 || !is_copy_constructible<_OutIter>::value, pair<_InIter, _OutIter> >
103__move(_InIter __first, _Sent __last, _OutIter __result) {
104 return std::__move_impl(std::move(__first), std::move(__last), std::move(__result));
59105}
60106
61107template <class _InputIterator, class _OutputIterator>
62inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
63_OutputIterator
64move(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
65{
66 if (__libcpp_is_constant_evaluated()) {
67 return _VSTD::__move_constexpr(__first, __last, __result);
68 } else {
69 return _VSTD::__rewrap_iter(__result,
70 _VSTD::__move(_VSTD::__unwrap_iter(__first),
71 _VSTD::__unwrap_iter(__last),
72 _VSTD::__unwrap_iter(__result)));
73 }
108inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
109_OutputIterator move(_InputIterator __first, _InputIterator __last, _OutputIterator __result) {
110 return std::__move(__first, __last, __result).second;
74111}
75112
76113_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__algorithm/move_backward.h+2-2
......@@ -11,12 +11,12 @@
1111
1212#include <__algorithm/unwrap_iter.h>
1313#include <__config>
14#include <__utility/move.h>
1415#include <cstring>
1516#include <type_traits>
16#include <utility>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
19# pragma GCC system_header
2020#endif
2121
2222_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/next_permutation.h+1-1
......@@ -17,7 +17,7 @@
1717#include <__utility/swap.h>
1818
1919#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20#pragma GCC system_header
20# pragma GCC system_header
2121#endif
2222
2323_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/none_of.h+1-1
......@@ -13,7 +13,7 @@
1313#include <__config>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16#pragma GCC system_header
16# pragma GCC system_header
1717#endif
1818
1919_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/nth_element.h+42-31
......@@ -11,17 +11,16 @@
1111
1212#include <__algorithm/comp.h>
1313#include <__algorithm/comp_ref_type.h>
14#include <__algorithm/iterator_operations.h>
1415#include <__algorithm/sort.h>
1516#include <__config>
17#include <__debug>
18#include <__debug_utils/randomize_range.h>
1619#include <__iterator/iterator_traits.h>
17#include <__utility/swap.h>
18
19#if defined(_LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY)
20# include <__algorithm/shuffle.h>
21#endif
20#include <__utility/move.h>
2221
2322#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
24#pragma GCC system_header
23# pragma GCC system_header
2524#endif
2625
2726_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -42,10 +41,12 @@ __nth_element_find_guard(_RandomAccessIterator& __i, _RandomAccessIterator& __j,
4241 }
4342}
4443
45template <class _Compare, class _RandomAccessIterator>
44template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
4645_LIBCPP_CONSTEXPR_AFTER_CXX11 void
4746__nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare __comp)
4847{
48 using _Ops = _IterOps<_AlgPolicy>;
49
4950 // _Compare is known to be a reference type
5051 typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
5152 const difference_type __limit = 7;
......@@ -61,24 +62,24 @@ __nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _Rando
6162 return;
6263 case 2:
6364 if (__comp(*--__last, *__first))
64 swap(*__first, *__last);
65 _Ops::iter_swap(__first, __last);
6566 return;
6667 case 3:
6768 {
6869 _RandomAccessIterator __m = __first;
69 _VSTD::__sort3<_Compare>(__first, ++__m, --__last, __comp);
70 std::__sort3<_AlgPolicy, _Compare>(__first, ++__m, --__last, __comp);
7071 return;
7172 }
7273 }
7374 if (__len <= __limit)
7475 {
75 _VSTD::__selection_sort<_Compare>(__first, __last, __comp);
76 std::__selection_sort<_AlgPolicy, _Compare>(__first, __last, __comp);
7677 return;
7778 }
7879 // __len > __limit >= 3
7980 _RandomAccessIterator __m = __first + __len/2;
8081 _RandomAccessIterator __lm1 = __last;
81 unsigned __n_swaps = _VSTD::__sort3<_Compare>(__first, __m, --__lm1, __comp);
82 unsigned __n_swaps = std::__sort3<_AlgPolicy, _Compare>(__first, __m, --__lm1, __comp);
8283 // *__m is median
8384 // partition [__first, __m) < *__m and *__m <= [__m, __last)
8485 // (this inhibits tossing elements equivalent to __m around unnecessarily)
......@@ -91,7 +92,7 @@ __nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _Rando
9192 {
9293 // *__first == *__m, *__first doesn't go in first part
9394 if (_VSTD::__nth_element_find_guard<_Compare>(__i, __j, __m, __comp)) {
94 swap(*__i, *__j);
95 _Ops::iter_swap(__i, __j);
9596 ++__n_swaps;
9697 } else {
9798 // *__first == *__m, *__m <= all other elements
......@@ -103,7 +104,7 @@ __nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _Rando
103104 if (__i == __j) {
104105 return; // [__first, __last) all equivalent elements
105106 } else if (__comp(*__first, *__i)) {
106 swap(*__i, *__j);
107 _Ops::iter_swap(__i, __j);
107108 ++__n_swaps;
108109 ++__i;
109110 break;
......@@ -122,7 +123,7 @@ __nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _Rando
122123 ;
123124 if (__i >= __j)
124125 break;
125 swap(*__i, *__j);
126 _Ops::iter_swap(__i, __j);
126127 ++__n_swaps;
127128 ++__i;
128129 }
......@@ -153,7 +154,7 @@ __nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _Rando
153154 ;
154155 if (__i >= __j)
155156 break;
156 swap(*__i, *__j);
157 _Ops::iter_swap(__i, __j);
157158 ++__n_swaps;
158159 // It is known that __m != __j
159160 // If __m just moved, follow it
......@@ -165,7 +166,7 @@ __nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _Rando
165166 // [__first, __i) < *__m and *__m <= [__i, __last)
166167 if (__i != __m && __comp(*__m, *__i))
167168 {
168 swap(*__i, *__m);
169 _Ops::iter_swap(__i, __m);
169170 ++__n_swaps;
170171 }
171172 // [__first, __i) < *__i and *__i <= [__i+1, __last)
......@@ -221,26 +222,36 @@ __nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _Rando
221222 }
222223}
223224
224template <class _RandomAccessIterator, class _Compare>
225inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
226void
227nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare __comp)
228{
229 _LIBCPP_DEBUG_RANDOMIZE_RANGE(__first, __last);
230 typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
231 _VSTD::__nth_element<_Comp_ref>(__first, __nth, __last, __comp);
232 _LIBCPP_DEBUG_RANDOMIZE_RANGE(__first, __nth);
225template <class _AlgPolicy, class _RandomAccessIterator, class _Compare>
226inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
227void __nth_element_impl(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last,
228 _Compare& __comp) {
229 if (__nth == __last)
230 return;
231
232 std::__debug_randomize_range<_AlgPolicy>(__first, __last);
233
234 using _Comp_ref = typename __comp_ref_type<_Compare>::type;
235 std::__nth_element<_AlgPolicy, _Comp_ref>(__first, __nth, __last, __comp);
236
237 std::__debug_randomize_range<_AlgPolicy>(__first, __nth);
233238 if (__nth != __last) {
234 _LIBCPP_DEBUG_RANDOMIZE_RANGE(++__nth, __last);
239 std::__debug_randomize_range<_AlgPolicy>(++__nth, __last);
235240 }
236241}
237242
243template <class _RandomAccessIterator, class _Compare>
244inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
245void nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last,
246 _Compare __comp) {
247 std::__nth_element_impl<_ClassicAlgPolicy>(std::move(__first), std::move(__nth), std::move(__last), __comp);
248}
249
238250template <class _RandomAccessIterator>
239inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
240void
241nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last)
242{
243 _VSTD::nth_element(__first, __nth, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
251inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
252void nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last) {
253 std::nth_element(std::move(__first), std::move(__nth), std::move(__last), __less<typename
254 iterator_traits<_RandomAccessIterator>::value_type>());
244255}
245256
246257_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__algorithm/partial_sort.h+51-28
......@@ -11,41 +11,64 @@
1111
1212#include <__algorithm/comp.h>
1313#include <__algorithm/comp_ref_type.h>
14#include <__algorithm/iterator_operations.h>
1415#include <__algorithm/make_heap.h>
1516#include <__algorithm/sift_down.h>
1617#include <__algorithm/sort_heap.h>
1718#include <__config>
19#include <__debug>
20#include <__debug_utils/randomize_range.h>
1821#include <__iterator/iterator_traits.h>
19#include <__utility/swap.h>
20
21#if defined(_LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY)
22# include <__algorithm/shuffle.h>
23#endif
22#include <__utility/move.h>
23#include <type_traits>
2424
2525#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
26#pragma GCC system_header
26# pragma GCC system_header
2727#endif
2828
2929_LIBCPP_BEGIN_NAMESPACE_STD
3030
31template <class _Compare, class _RandomAccessIterator>
32_LIBCPP_CONSTEXPR_AFTER_CXX17 void
33__partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last,
34 _Compare __comp)
35{
36 if (__first == __middle)
37 return;
38 _VSTD::__make_heap<_Compare>(__first, __middle, __comp);
39 typename iterator_traits<_RandomAccessIterator>::difference_type __len = __middle - __first;
40 for (_RandomAccessIterator __i = __middle; __i != __last; ++__i)
41 {
42 if (__comp(*__i, *__first))
43 {
44 swap(*__i, *__first);
45 _VSTD::__sift_down<_Compare>(__first, __comp, __len, __first);
46 }
47 }
48 _VSTD::__sort_heap<_Compare>(__first, __middle, __comp);
31template <class _AlgPolicy, class _Compare, class _RandomAccessIterator, class _Sentinel>
32_LIBCPP_CONSTEXPR_AFTER_CXX17
33_RandomAccessIterator __partial_sort_impl(
34 _RandomAccessIterator __first, _RandomAccessIterator __middle, _Sentinel __last, _Compare&& __comp) {
35 if (__first == __middle) {
36 return _IterOps<_AlgPolicy>::next(__middle, __last);
37 }
38
39 std::__make_heap<_AlgPolicy>(__first, __middle, __comp);
40
41 typename iterator_traits<_RandomAccessIterator>::difference_type __len = __middle - __first;
42 _RandomAccessIterator __i = __middle;
43 for (; __i != __last; ++__i)
44 {
45 if (__comp(*__i, *__first))
46 {
47 _IterOps<_AlgPolicy>::iter_swap(__i, __first);
48 std::__sift_down<_AlgPolicy>(__first, __comp, __len, __first);
49 }
50
51 }
52 std::__sort_heap<_AlgPolicy>(std::move(__first), std::move(__middle), __comp);
53
54 return __i;
55}
56
57template <class _AlgPolicy, class _Compare, class _RandomAccessIterator, class _Sentinel>
58_LIBCPP_CONSTEXPR_AFTER_CXX17
59_RandomAccessIterator __partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _Sentinel __last,
60 _Compare& __comp) {
61 if (__first == __middle)
62 return _IterOps<_AlgPolicy>::next(__middle, __last);
63
64 std::__debug_randomize_range<_AlgPolicy>(__first, __last);
65
66 using _Comp_ref = typename __comp_ref_type<_Compare>::type;
67 auto __last_iter = std::__partial_sort_impl<_AlgPolicy>(__first, __middle, __last, static_cast<_Comp_ref>(__comp));
68
69 std::__debug_randomize_range<_AlgPolicy>(__middle, __last);
70
71 return __last_iter;
4972}
5073
5174template <class _RandomAccessIterator, class _Compare>
......@@ -54,10 +77,10 @@ void
5477partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last,
5578 _Compare __comp)
5679{
57 _LIBCPP_DEBUG_RANDOMIZE_RANGE(__first, __last);
58 typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
59 _VSTD::__partial_sort<_Comp_ref>(__first, __middle, __last, __comp);
60 _LIBCPP_DEBUG_RANDOMIZE_RANGE(__middle, __last);
80 static_assert(std::is_copy_constructible<_RandomAccessIterator>::value, "Iterators must be copy constructible.");
81 static_assert(std::is_copy_assignable<_RandomAccessIterator>::value, "Iterators must be copy assignable.");
82
83 (void)std::__partial_sort<_ClassicAlgPolicy>(std::move(__first), std::move(__middle), std::move(__last), __comp);
6184}
6285
6386template <class _RandomAccessIterator>
lib/libcxx/include/__algorithm/partial_sort_copy.h+31-13
......@@ -11,39 +11,52 @@
1111
1212#include <__algorithm/comp.h>
1313#include <__algorithm/comp_ref_type.h>
14#include <__algorithm/iterator_operations.h>
1415#include <__algorithm/make_heap.h>
16#include <__algorithm/make_projected.h>
1517#include <__algorithm/sift_down.h>
1618#include <__algorithm/sort_heap.h>
1719#include <__config>
20#include <__functional/identity.h>
21#include <__functional/invoke.h>
1822#include <__iterator/iterator_traits.h>
23#include <__type_traits/is_callable.h>
24#include <__utility/move.h>
25#include <__utility/pair.h>
1926
2027#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21#pragma GCC system_header
28# pragma GCC system_header
2229#endif
2330
2431_LIBCPP_BEGIN_NAMESPACE_STD
2532
26template <class _Compare, class _InputIterator, class _RandomAccessIterator>
27_LIBCPP_CONSTEXPR_AFTER_CXX17 _RandomAccessIterator
28__partial_sort_copy(_InputIterator __first, _InputIterator __last,
29 _RandomAccessIterator __result_first, _RandomAccessIterator __result_last, _Compare __comp)
33template <class _AlgPolicy, class _Compare,
34 class _InputIterator, class _Sentinel1, class _RandomAccessIterator, class _Sentinel2,
35 class _Proj1, class _Proj2>
36_LIBCPP_CONSTEXPR_AFTER_CXX17 pair<_InputIterator, _RandomAccessIterator>
37__partial_sort_copy(_InputIterator __first, _Sentinel1 __last,
38 _RandomAccessIterator __result_first, _Sentinel2 __result_last,
39 _Compare&& __comp, _Proj1&& __proj1, _Proj2&& __proj2)
3040{
3141 _RandomAccessIterator __r = __result_first;
42 auto&& __projected_comp = std::__make_projected(__comp, __proj2);
43
3244 if (__r != __result_last)
3345 {
3446 for (; __first != __last && __r != __result_last; ++__first, (void) ++__r)
3547 *__r = *__first;
36 _VSTD::__make_heap<_Compare>(__result_first, __r, __comp);
48 std::__make_heap<_AlgPolicy>(__result_first, __r, __projected_comp);
3749 typename iterator_traits<_RandomAccessIterator>::difference_type __len = __r - __result_first;
3850 for (; __first != __last; ++__first)
39 if (__comp(*__first, *__result_first))
40 {
51 if (std::__invoke(__comp, std::__invoke(__proj1, *__first), std::__invoke(__proj2, *__result_first))) {
4152 *__result_first = *__first;
42 _VSTD::__sift_down<_Compare>(__result_first, __comp, __len, __result_first);
53 std::__sift_down<_AlgPolicy>(__result_first, __projected_comp, __len, __result_first);
4354 }
44 _VSTD::__sort_heap<_Compare>(__result_first, __r, __comp);
55 std::__sort_heap<_AlgPolicy>(__result_first, __r, __projected_comp);
4556 }
46 return __r;
57
58 return pair<_InputIterator, _RandomAccessIterator>(
59 _IterOps<_AlgPolicy>::next(std::move(__first), std::move(__last)), std::move(__r));
4760}
4861
4962template <class _InputIterator, class _RandomAccessIterator, class _Compare>
......@@ -52,8 +65,13 @@ _RandomAccessIterator
5265partial_sort_copy(_InputIterator __first, _InputIterator __last,
5366 _RandomAccessIterator __result_first, _RandomAccessIterator __result_last, _Compare __comp)
5467{
55 typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
56 return _VSTD::__partial_sort_copy<_Comp_ref>(__first, __last, __result_first, __result_last, __comp);
68 static_assert(__is_callable<_Compare, decltype(*__first), decltype(*__result_first)>::value,
69 "Comparator has to be callable");
70
71 using _Comp_ref = typename __comp_ref_type<_Compare>::type;
72 auto __result = std::__partial_sort_copy<_ClassicAlgPolicy>(__first, __last, __result_first, __result_last,
73 static_cast<_Comp_ref>(__comp), __identity(), __identity());
74 return __result.second;
5775}
5876
5977template <class _InputIterator, class _RandomAccessIterator>
lib/libcxx/include/__algorithm/partition.h+34-17
......@@ -9,50 +9,58 @@
99#ifndef _LIBCPP___ALGORITHM_PARTITION_H
1010#define _LIBCPP___ALGORITHM_PARTITION_H
1111
12#include <__algorithm/iterator_operations.h>
1213#include <__config>
1314#include <__iterator/iterator_traits.h>
14#include <__utility/swap.h>
15#include <__utility/move.h>
16#include <__utility/pair.h>
17#include <type_traits>
1518
1619#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
20# pragma GCC system_header
1821#endif
1922
2023_LIBCPP_BEGIN_NAMESPACE_STD
2124
22template <class _Predicate, class _ForwardIterator>
23_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
24__partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, forward_iterator_tag)
25template <class _Predicate, class _AlgPolicy, class _ForwardIterator, class _Sentinel>
26_LIBCPP_CONSTEXPR_AFTER_CXX17 pair<_ForwardIterator, _ForwardIterator>
27__partition_impl(_ForwardIterator __first, _Sentinel __last, _Predicate __pred, forward_iterator_tag)
2528{
2629 while (true)
2730 {
2831 if (__first == __last)
29 return __first;
32 return std::make_pair(std::move(__first), std::move(__first));
3033 if (!__pred(*__first))
3134 break;
3235 ++__first;
3336 }
34 for (_ForwardIterator __p = __first; ++__p != __last;)
37
38 _ForwardIterator __p = __first;
39 while (++__p != __last)
3540 {
3641 if (__pred(*__p))
3742 {
38 swap(*__first, *__p);
43 _IterOps<_AlgPolicy>::iter_swap(__first, __p);
3944 ++__first;
4045 }
4146 }
42 return __first;
47 return std::make_pair(std::move(__first), std::move(__p));
4348}
4449
45template <class _Predicate, class _BidirectionalIterator>
46_LIBCPP_CONSTEXPR_AFTER_CXX17 _BidirectionalIterator
47__partition(_BidirectionalIterator __first, _BidirectionalIterator __last, _Predicate __pred,
50template <class _Predicate, class _AlgPolicy, class _BidirectionalIterator, class _Sentinel>
51_LIBCPP_CONSTEXPR_AFTER_CXX17 pair<_BidirectionalIterator, _BidirectionalIterator>
52__partition_impl(_BidirectionalIterator __first, _Sentinel __sentinel, _Predicate __pred,
4853 bidirectional_iterator_tag)
4954{
55 _BidirectionalIterator __original_last = _IterOps<_AlgPolicy>::next(__first, __sentinel);
56 _BidirectionalIterator __last = __original_last;
57
5058 while (true)
5159 {
5260 while (true)
5361 {
5462 if (__first == __last)
55 return __first;
63 return std::make_pair(std::move(__first), std::move(__original_last));
5664 if (!__pred(*__first))
5765 break;
5866 ++__first;
......@@ -60,20 +68,29 @@ __partition(_BidirectionalIterator __first, _BidirectionalIterator __last, _Pred
6068 do
6169 {
6270 if (__first == --__last)
63 return __first;
71 return std::make_pair(std::move(__first), std::move(__original_last));
6472 } while (!__pred(*__last));
65 swap(*__first, *__last);
73 _IterOps<_AlgPolicy>::iter_swap(__first, __last);
6674 ++__first;
6775 }
6876}
6977
78template <class _AlgPolicy, class _ForwardIterator, class _Sentinel, class _Predicate, class _IterCategory>
79inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
80pair<_ForwardIterator, _ForwardIterator> __partition(
81 _ForwardIterator __first, _Sentinel __last, _Predicate&& __pred, _IterCategory __iter_category) {
82 return std::__partition_impl<__uncvref_t<_Predicate>&, _AlgPolicy>(
83 std::move(__first), std::move(__last), __pred, __iter_category);
84}
85
7086template <class _ForwardIterator, class _Predicate>
7187inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
7288_ForwardIterator
7389partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
7490{
75 return _VSTD::__partition<_Predicate&>(
76 __first, __last, __pred, typename iterator_traits<_ForwardIterator>::iterator_category());
91 using _IterCategory = typename iterator_traits<_ForwardIterator>::iterator_category;
92 auto __result = std::__partition<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __pred, _IterCategory());
93 return __result.first;
7794}
7895
7996_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__algorithm/partition_copy.h+2-2
......@@ -11,10 +11,10 @@
1111
1212#include <__config>
1313#include <__iterator/iterator_traits.h>
14#include <utility> // pair
14#include <__utility/pair.h>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
17# pragma GCC system_header
1818#endif
1919
2020_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/partition_point.h+4-2
......@@ -11,10 +11,12 @@
1111
1212#include <__algorithm/half_positive.h>
1313#include <__config>
14#include <iterator>
14#include <__iterator/advance.h>
15#include <__iterator/distance.h>
16#include <__iterator/iterator_traits.h>
1517
1618#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
19# pragma GCC system_header
1820#endif
1921
2022_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/pop_heap.h+40-23
......@@ -11,45 +11,62 @@
1111
1212#include <__algorithm/comp.h>
1313#include <__algorithm/comp_ref_type.h>
14#include <__algorithm/iterator_operations.h>
15#include <__algorithm/push_heap.h>
1416#include <__algorithm/sift_down.h>
17#include <__assert>
1518#include <__config>
1619#include <__iterator/iterator_traits.h>
17#include <__utility/swap.h>
20#include <__utility/move.h>
21#include <type_traits>
1822
1923#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20#pragma GCC system_header
24# pragma GCC system_header
2125#endif
2226
2327_LIBCPP_BEGIN_NAMESPACE_STD
2428
25template <class _Compare, class _RandomAccessIterator>
26inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
27void
28__pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp,
29 typename iterator_traits<_RandomAccessIterator>::difference_type __len)
30{
31 if (__len > 1)
32 {
33 swap(*__first, *--__last);
34 _VSTD::__sift_down<_Compare>(__first, __comp, __len - 1, __first);
29template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
30inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
31void __pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare& __comp,
32 typename iterator_traits<_RandomAccessIterator>::difference_type __len) {
33 _LIBCPP_ASSERT(__len > 0, "The heap given to pop_heap must be non-empty");
34
35 using _CompRef = typename __comp_ref_type<_Compare>::type;
36 _CompRef __comp_ref = __comp;
37
38 using value_type = typename iterator_traits<_RandomAccessIterator>::value_type;
39 if (__len > 1) {
40 value_type __top = _IterOps<_AlgPolicy>::__iter_move(__first); // create a hole at __first
41 _RandomAccessIterator __hole = std::__floyd_sift_down<_AlgPolicy>(__first, __comp_ref, __len);
42 --__last;
43
44 if (__hole == __last) {
45 *__hole = std::move(__top);
46 } else {
47 *__hole = _IterOps<_AlgPolicy>::__iter_move(__last);
48 ++__hole;
49 *__last = std::move(__top);
50 std::__sift_up<_AlgPolicy>(__first, __hole, __comp_ref, __hole - __first);
3551 }
52 }
3653}
3754
3855template <class _RandomAccessIterator, class _Compare>
39inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
40void
41pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
42{
43 typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
44 _VSTD::__pop_heap<_Comp_ref>(__first, __last, __comp, __last - __first);
56inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
57void pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) {
58 static_assert(std::is_copy_constructible<_RandomAccessIterator>::value, "Iterators must be copy constructible.");
59 static_assert(std::is_copy_assignable<_RandomAccessIterator>::value, "Iterators must be copy assignable.");
60
61 typename iterator_traits<_RandomAccessIterator>::difference_type __len = __last - __first;
62 std::__pop_heap<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __comp, __len);
4563}
4664
4765template <class _RandomAccessIterator>
48inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
49void
50pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
51{
52 _VSTD::pop_heap(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
66inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
67void pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) {
68 std::pop_heap(std::move(__first), std::move(__last),
69 __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
5370}
5471
5572_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__algorithm/prev_permutation.h+1-1
......@@ -17,7 +17,7 @@
1717#include <__utility/swap.h>
1818
1919#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20#pragma GCC system_header
20# pragma GCC system_header
2121#endif
2222
2323_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/push_heap.h+44-36
......@@ -11,58 +11,66 @@
1111
1212#include <__algorithm/comp.h>
1313#include <__algorithm/comp_ref_type.h>
14#include <__algorithm/iterator_operations.h>
1415#include <__config>
1516#include <__iterator/iterator_traits.h>
1617#include <__utility/move.h>
18#include <type_traits>
1719
1820#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
21# pragma GCC system_header
2022#endif
2123
2224_LIBCPP_BEGIN_NAMESPACE_STD
2325
24template <class _Compare, class _RandomAccessIterator>
25_LIBCPP_CONSTEXPR_AFTER_CXX11 void
26__sift_up(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp,
27 typename iterator_traits<_RandomAccessIterator>::difference_type __len)
28{
29 typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
30 if (__len > 1)
31 {
32 __len = (__len - 2) / 2;
33 _RandomAccessIterator __ptr = __first + __len;
34 if (__comp(*__ptr, *--__last))
35 {
36 value_type __t(_VSTD::move(*__last));
37 do
38 {
39 *__last = _VSTD::move(*__ptr);
40 __last = __ptr;
41 if (__len == 0)
42 break;
43 __len = (__len - 1) / 2;
44 __ptr = __first + __len;
45 } while (__comp(*__ptr, __t));
46 *__last = _VSTD::move(__t);
47 }
26template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
27_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
28void __sift_up(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare&& __comp,
29 typename iterator_traits<_RandomAccessIterator>::difference_type __len) {
30 using value_type = typename iterator_traits<_RandomAccessIterator>::value_type;
31
32 if (__len > 1) {
33 __len = (__len - 2) / 2;
34 _RandomAccessIterator __ptr = __first + __len;
35
36 if (__comp(*__ptr, *--__last)) {
37 value_type __t(_IterOps<_AlgPolicy>::__iter_move(__last));
38 do {
39 *__last = _IterOps<_AlgPolicy>::__iter_move(__ptr);
40 __last = __ptr;
41 if (__len == 0)
42 break;
43 __len = (__len - 1) / 2;
44 __ptr = __first + __len;
45 } while (__comp(*__ptr, __t));
46
47 *__last = std::move(__t);
4848 }
49 }
50}
51
52template <class _AlgPolicy, class _RandomAccessIterator, class _Compare>
53inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
54void __push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare& __comp) {
55 using _CompRef = typename __comp_ref_type<_Compare>::type;
56 typename iterator_traits<_RandomAccessIterator>::difference_type __len = __last - __first;
57 std::__sift_up<_AlgPolicy, _CompRef>(std::move(__first), std::move(__last), __comp, __len);
4958}
5059
5160template <class _RandomAccessIterator, class _Compare>
52inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
53void
54push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
55{
56 typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
57 _VSTD::__sift_up<_Comp_ref>(__first, __last, __comp, __last - __first);
61inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
62void push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) {
63 static_assert(std::is_copy_constructible<_RandomAccessIterator>::value, "Iterators must be copy constructible.");
64 static_assert(std::is_copy_assignable<_RandomAccessIterator>::value, "Iterators must be copy assignable.");
65
66 std::__push_heap<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __comp);
5867}
5968
6069template <class _RandomAccessIterator>
61inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
62void
63push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
64{
65 _VSTD::push_heap(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
70inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
71void push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) {
72 std::push_heap(std::move(__first), std::move(__last),
73 __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
6674}
6775
6876_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__algorithm/ranges_adjacent_find.h created+78
......@@ -0,0 +1,78 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_ADJACENT_FIND_H
10#define _LIBCPP___ALGORITHM_RANGES_ADJACENT_FIND_H
11
12#include <__config>
13#include <__functional/identity.h>
14#include <__functional/invoke.h>
15#include <__functional/ranges_operations.h>
16#include <__iterator/concepts.h>
17#include <__iterator/projected.h>
18#include <__ranges/access.h>
19#include <__ranges/concepts.h>
20#include <__ranges/dangling.h>
21#include <__utility/move.h>
22
23#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
24# pragma GCC system_header
25#endif
26
27#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
28
29_LIBCPP_BEGIN_NAMESPACE_STD
30
31namespace ranges {
32namespace __adjacent_find {
33struct __fn {
34
35 template <class _Iter, class _Sent, class _Proj, class _Pred>
36 _LIBCPP_HIDE_FROM_ABI constexpr static
37 _Iter __adjacent_find_impl(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
38 if (__first == __last)
39 return __first;
40
41 auto __i = __first;
42 while (++__i != __last) {
43 if (std::invoke(__pred, std::invoke(__proj, *__first), std::invoke(__proj, *__i)))
44 return __first;
45 __first = __i;
46 }
47 return __i;
48 }
49
50 template <forward_iterator _Iter, sentinel_for<_Iter> _Sent,
51 class _Proj = identity,
52 indirect_binary_predicate<projected<_Iter, _Proj>, projected<_Iter, _Proj>> _Pred = ranges::equal_to>
53 _LIBCPP_HIDE_FROM_ABI constexpr
54 _Iter operator()(_Iter __first, _Sent __last, _Pred __pred = {}, _Proj __proj = {}) const {
55 return __adjacent_find_impl(std::move(__first), std::move(__last), __pred, __proj);
56 }
57
58 template <forward_range _Range,
59 class _Proj = identity,
60 indirect_binary_predicate<projected<iterator_t<_Range>, _Proj>,
61 projected<iterator_t<_Range>, _Proj>> _Pred = ranges::equal_to>
62 _LIBCPP_HIDE_FROM_ABI constexpr
63 borrowed_iterator_t<_Range> operator()(_Range&& __range, _Pred __pred = {}, _Proj __proj = {}) const {
64 return __adjacent_find_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj);
65 }
66};
67} // namespace __adjacent_find
68
69inline namespace __cpo {
70 inline constexpr auto adjacent_find = __adjacent_find::__fn{};
71} // namespace __cpo
72} // namespace ranges
73
74_LIBCPP_END_NAMESPACE_STD
75
76#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
77
78#endif // _LIBCPP___ALGORITHM_RANGES_ADJACENT_FIND_H
lib/libcxx/include/__algorithm/ranges_all_of.h created+68
......@@ -0,0 +1,68 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_ALL_OF_H
10#define _LIBCPP___ALGORITHM_RANGES_ALL_OF_H
11
12#include <__config>
13#include <__functional/identity.h>
14#include <__functional/invoke.h>
15#include <__iterator/concepts.h>
16#include <__iterator/projected.h>
17#include <__ranges/access.h>
18#include <__ranges/concepts.h>
19#include <__utility/move.h>
20
21#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22# pragma GCC system_header
23#endif
24
25#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
26
27_LIBCPP_BEGIN_NAMESPACE_STD
28
29namespace ranges {
30namespace __all_of {
31struct __fn {
32
33 template <class _Iter, class _Sent, class _Proj, class _Pred>
34 _LIBCPP_HIDE_FROM_ABI constexpr static
35 bool __all_of_impl(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
36 for (; __first != __last; ++__first) {
37 if (!std::invoke(__pred, std::invoke(__proj, *__first)))
38 return false;
39 }
40 return true;
41 }
42
43 template <input_iterator _Iter, sentinel_for<_Iter> _Sent, class _Proj = identity,
44 indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
45 _LIBCPP_HIDE_FROM_ABI constexpr
46 bool operator()(_Iter __first, _Sent __last, _Pred __pred, _Proj __proj = {}) const {
47 return __all_of_impl(std::move(__first), std::move(__last), __pred, __proj);
48 }
49
50 template <input_range _Range, class _Proj = identity,
51 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>> _Pred>
52 _LIBCPP_HIDE_FROM_ABI constexpr
53 bool operator()(_Range&& __range, _Pred __pred, _Proj __proj = {}) const {
54 return __all_of_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj);
55 }
56};
57} // namespace __all_of
58
59inline namespace __cpo {
60 inline constexpr auto all_of = __all_of::__fn{};
61} // namespace __cpo
62} // namespace ranges
63
64_LIBCPP_END_NAMESPACE_STD
65
66#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
67
68#endif // _LIBCPP___ALGORITHM_RANGES_ALL_OF_H
lib/libcxx/include/__algorithm/ranges_any_of.h created+68
......@@ -0,0 +1,68 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_ANY_OF_H
10#define _LIBCPP___ALGORITHM_RANGES_ANY_OF_H
11
12#include <__config>
13#include <__functional/identity.h>
14#include <__functional/invoke.h>
15#include <__iterator/concepts.h>
16#include <__iterator/projected.h>
17#include <__ranges/access.h>
18#include <__ranges/concepts.h>
19#include <__utility/move.h>
20
21#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22# pragma GCC system_header
23#endif
24
25#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
26
27_LIBCPP_BEGIN_NAMESPACE_STD
28
29namespace ranges {
30namespace __any_of {
31struct __fn {
32
33 template <class _Iter, class _Sent, class _Proj, class _Pred>
34 _LIBCPP_HIDE_FROM_ABI constexpr static
35 bool __any_of_impl(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
36 for (; __first != __last; ++__first) {
37 if (std::invoke(__pred, std::invoke(__proj, *__first)))
38 return true;
39 }
40 return false;
41 }
42
43 template <input_iterator _Iter, sentinel_for<_Iter> _Sent, class _Proj = identity,
44 indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
45 _LIBCPP_HIDE_FROM_ABI constexpr
46 bool operator()(_Iter __first, _Sent __last, _Pred __pred = {}, _Proj __proj = {}) const {
47 return __any_of_impl(std::move(__first), std::move(__last), __pred, __proj);
48 }
49
50 template <input_range _Range, class _Proj = identity,
51 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>> _Pred>
52 _LIBCPP_HIDE_FROM_ABI constexpr
53 bool operator()(_Range&& __range, _Pred __pred, _Proj __proj = {}) const {
54 return __any_of_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj);
55 }
56};
57} // namespace __any_of
58
59inline namespace __cpo {
60 inline constexpr auto any_of = __any_of::__fn{};
61} // namespace __cpo
62} // namespace ranges
63
64_LIBCPP_END_NAMESPACE_STD
65
66#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
67
68#endif // _LIBCPP___ALGORITHM_RANGES_ANY_OF_H
lib/libcxx/include/__algorithm/ranges_binary_search.h created+63
......@@ -0,0 +1,63 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_BINARY_SEARCH_H
10#define _LIBCPP___ALGORITHM_RANGES_BINARY_SEARCH_H
11
12#include <__algorithm/iterator_operations.h>
13#include <__algorithm/lower_bound.h>
14#include <__config>
15#include <__functional/identity.h>
16#include <__functional/invoke.h>
17#include <__functional/ranges_operations.h>
18#include <__iterator/concepts.h>
19#include <__iterator/projected.h>
20#include <__ranges/access.h>
21#include <__ranges/concepts.h>
22
23#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
24# pragma GCC system_header
25#endif
26
27#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
28
29_LIBCPP_BEGIN_NAMESPACE_STD
30
31namespace ranges {
32namespace __binary_search {
33struct __fn {
34 template <forward_iterator _Iter, sentinel_for<_Iter> _Sent, class _Type, class _Proj = identity,
35 indirect_strict_weak_order<const _Type*, projected<_Iter, _Proj>> _Comp = ranges::less>
36 _LIBCPP_HIDE_FROM_ABI constexpr
37 bool operator()(_Iter __first, _Sent __last, const _Type& __value, _Comp __comp = {}, _Proj __proj = {}) const {
38 auto __ret = std::__lower_bound_impl<_RangeAlgPolicy>(__first, __last, __value, __comp, __proj);
39 return __ret != __last && !std::invoke(__comp, __value, std::invoke(__proj, *__first));
40 }
41
42 template <forward_range _Range, class _Type, class _Proj = identity,
43 indirect_strict_weak_order<const _Type*, projected<iterator_t<_Range>, _Proj>> _Comp = ranges::less>
44 _LIBCPP_HIDE_FROM_ABI constexpr
45 bool operator()(_Range&& __r, const _Type& __value, _Comp __comp = {}, _Proj __proj = {}) const {
46 auto __first = ranges::begin(__r);
47 auto __last = ranges::end(__r);
48 auto __ret = std::__lower_bound_impl<_RangeAlgPolicy>(__first, __last, __value, __comp, __proj);
49 return __ret != __last && !std::invoke(__comp, __value, std::invoke(__proj, *__first));
50 }
51};
52} // namespace __binary_search
53
54inline namespace __cpo {
55 inline constexpr auto binary_search = __binary_search::__fn{};
56} // namespace __cpo
57} // namespace ranges
58
59_LIBCPP_END_NAMESPACE_STD
60
61#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
62
63#endif // _LIBCPP___ALGORITHM_RANGES_BINARY_SEARCH_H
lib/libcxx/include/__algorithm/ranges_copy.h created+65
......@@ -0,0 +1,65 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_COPY_H
10#define _LIBCPP___ALGORITHM_RANGES_COPY_H
11
12#include <__algorithm/copy.h>
13#include <__algorithm/in_out_result.h>
14#include <__config>
15#include <__functional/identity.h>
16#include <__iterator/concepts.h>
17#include <__ranges/access.h>
18#include <__ranges/concepts.h>
19#include <__ranges/dangling.h>
20#include <__utility/move.h>
21
22#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23# pragma GCC system_header
24#endif
25
26#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
27
28_LIBCPP_BEGIN_NAMESPACE_STD
29
30namespace ranges {
31
32template <class _InIter, class _OutIter>
33using copy_result = in_out_result<_InIter, _OutIter>;
34
35namespace __copy {
36struct __fn {
37
38 template <input_iterator _InIter, sentinel_for<_InIter> _Sent, weakly_incrementable _OutIter>
39 requires indirectly_copyable<_InIter, _OutIter>
40 _LIBCPP_HIDE_FROM_ABI constexpr
41 copy_result<_InIter, _OutIter> operator()(_InIter __first, _Sent __last, _OutIter __result) const {
42 auto __ret = std::__copy(std::move(__first), std::move(__last), std::move(__result));
43 return {std::move(__ret.first), std::move(__ret.second)};
44 }
45
46 template <input_range _Range, weakly_incrementable _OutIter>
47 requires indirectly_copyable<iterator_t<_Range>, _OutIter>
48 _LIBCPP_HIDE_FROM_ABI constexpr
49 copy_result<borrowed_iterator_t<_Range>, _OutIter> operator()(_Range&& __r, _OutIter __result) const {
50 auto __ret = std::__copy(ranges::begin(__r), ranges::end(__r), std::move(__result));
51 return {std::move(__ret.first), std::move(__ret.second)};
52 }
53};
54} // namespace __copy
55
56inline namespace __cpo {
57 inline constexpr auto copy = __copy::__fn{};
58} // namespace __cpo
59} // namespace ranges
60
61_LIBCPP_END_NAMESPACE_STD
62
63#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
64
65#endif // _LIBCPP___ALGORITHM_RANGES_COPY_H
lib/libcxx/include/__algorithm/ranges_copy_backward.h created+66
......@@ -0,0 +1,66 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_COPY_BACKWARD_H
10#define _LIBCPP___ALGORITHM_RANGES_COPY_BACKWARD_H
11
12#include <__algorithm/copy_backward.h>
13#include <__algorithm/in_out_result.h>
14#include <__algorithm/iterator_operations.h>
15#include <__config>
16#include <__iterator/concepts.h>
17#include <__iterator/reverse_iterator.h>
18#include <__ranges/access.h>
19#include <__ranges/concepts.h>
20#include <__ranges/dangling.h>
21#include <__utility/move.h>
22
23#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
24# pragma GCC system_header
25#endif
26
27#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
28
29_LIBCPP_BEGIN_NAMESPACE_STD
30
31namespace ranges {
32
33template<class _Ip, class _Op>
34using copy_backward_result = in_out_result<_Ip, _Op>;
35
36namespace __copy_backward {
37struct __fn {
38
39 template <bidirectional_iterator _InIter1, sentinel_for<_InIter1> _Sent1, bidirectional_iterator _InIter2>
40 requires indirectly_copyable<_InIter1, _InIter2>
41 _LIBCPP_HIDE_FROM_ABI constexpr
42 copy_backward_result<_InIter1, _InIter2> operator()(_InIter1 __first, _Sent1 __last, _InIter2 __result) const {
43 auto __ret = std::__copy_backward<_RangeAlgPolicy>(std::move(__first), std::move(__last), std::move(__result));
44 return {std::move(__ret.first), std::move(__ret.second)};
45 }
46
47 template <bidirectional_range _Range, bidirectional_iterator _Iter>
48 requires indirectly_copyable<iterator_t<_Range>, _Iter>
49 _LIBCPP_HIDE_FROM_ABI constexpr
50 copy_backward_result<borrowed_iterator_t<_Range>, _Iter> operator()(_Range&& __r, _Iter __result) const {
51 auto __ret = std::__copy_backward<_RangeAlgPolicy>(ranges::begin(__r), ranges::end(__r), std::move(__result));
52 return {std::move(__ret.first), std::move(__ret.second)};
53 }
54};
55} // namespace __copy_backward
56
57inline namespace __cpo {
58 inline constexpr auto copy_backward = __copy_backward::__fn{};
59} // namespace __cpo
60} // namespace ranges
61
62_LIBCPP_END_NAMESPACE_STD
63
64#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
65
66#endif // _LIBCPP___ALGORITHM_RANGES_COPY_BACKWARD_H
lib/libcxx/include/__algorithm/ranges_copy_if.h created+81
......@@ -0,0 +1,81 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_COPY_IF_H
10#define _LIBCPP___ALGORITHM_RANGES_COPY_IF_H
11
12#include <__algorithm/in_out_result.h>
13#include <__config>
14#include <__functional/identity.h>
15#include <__functional/invoke.h>
16#include <__iterator/concepts.h>
17#include <__iterator/projected.h>
18#include <__ranges/access.h>
19#include <__ranges/concepts.h>
20#include <__ranges/dangling.h>
21#include <__utility/move.h>
22
23#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
24# pragma GCC system_header
25#endif
26
27#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
28
29_LIBCPP_BEGIN_NAMESPACE_STD
30
31namespace ranges {
32
33template<class _Ip, class _Op>
34using copy_if_result = in_out_result<_Ip, _Op>;
35
36namespace __copy_if {
37struct __fn {
38
39 template <class _InIter, class _Sent, class _OutIter, class _Proj, class _Pred>
40 _LIBCPP_HIDE_FROM_ABI static constexpr
41 copy_if_result <_InIter, _OutIter>
42 __copy_if_impl(_InIter __first, _Sent __last, _OutIter __result, _Pred& __pred, _Proj& __proj) {
43 for (; __first != __last; ++__first) {
44 if (std::invoke(__pred, std::invoke(__proj, *__first))) {
45 *__result = *__first;
46 ++__result;
47 }
48 }
49 return {std::move(__first), std::move(__result)};
50 }
51
52 template <input_iterator _Iter, sentinel_for<_Iter> _Sent, weakly_incrementable _OutIter, class _Proj = identity,
53 indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
54 requires indirectly_copyable<_Iter, _OutIter>
55 _LIBCPP_HIDE_FROM_ABI constexpr
56 copy_if_result<_Iter, _OutIter>
57 operator()(_Iter __first, _Sent __last, _OutIter __result, _Pred __pred, _Proj __proj = {}) const {
58 return __copy_if_impl(std::move(__first), std::move(__last), std::move(__result), __pred, __proj);
59 }
60
61 template <input_range _Range, weakly_incrementable _OutIter, class _Proj = identity,
62 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>> _Pred>
63 requires indirectly_copyable<iterator_t<_Range>, _OutIter>
64 _LIBCPP_HIDE_FROM_ABI constexpr
65 copy_if_result<borrowed_iterator_t<_Range>, _OutIter>
66 operator()(_Range&& __r, _OutIter __result, _Pred __pred, _Proj __proj = {}) const {
67 return __copy_if_impl(ranges::begin(__r), ranges::end(__r), std::move(__result), __pred, __proj);
68 }
69};
70} // namespace __copy_if
71
72inline namespace __cpo {
73 inline constexpr auto copy_if = __copy_if::__fn{};
74} // namespace __cpo
75} // namespace ranges
76
77_LIBCPP_END_NAMESPACE_STD
78
79#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
80
81#endif // _LIBCPP___ALGORITHM_RANGES_COPY_IF_H
lib/libcxx/include/__algorithm/ranges_copy_n.h created+76
......@@ -0,0 +1,76 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_COPY_N_H
10#define _LIBCPP___ALGORITHM_RANGES_COPY_N_H
11
12#include <__algorithm/copy.h>
13#include <__algorithm/in_out_result.h>
14#include <__algorithm/ranges_copy.h>
15#include <__config>
16#include <__functional/identity.h>
17#include <__iterator/concepts.h>
18#include <__iterator/incrementable_traits.h>
19#include <__iterator/unreachable_sentinel.h>
20#include <__iterator/wrap_iter.h>
21#include <__utility/move.h>
22
23#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
24# pragma GCC system_header
25#endif
26
27_LIBCPP_BEGIN_NAMESPACE_STD
28
29#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
30
31namespace ranges {
32
33template <class _Ip, class _Op>
34using copy_n_result = in_out_result<_Ip, _Op>;
35
36namespace __copy_n {
37struct __fn {
38
39 template <class _InIter, class _DiffType, class _OutIter>
40 _LIBCPP_HIDE_FROM_ABI constexpr static
41 copy_n_result<_InIter, _OutIter> __go(_InIter __first, _DiffType __n, _OutIter __result) {
42 while (__n != 0) {
43 *__result = *__first;
44 ++__first;
45 ++__result;
46 --__n;
47 }
48 return {std::move(__first), std::move(__result)};
49 }
50
51 template <random_access_iterator _InIter, class _DiffType, random_access_iterator _OutIter>
52 _LIBCPP_HIDE_FROM_ABI constexpr static
53 copy_n_result<_InIter, _OutIter> __go(_InIter __first, _DiffType __n, _OutIter __result) {
54 auto __ret = std::__copy(__first, __first + __n, __result);
55 return {__ret.first, __ret.second};
56 }
57
58 template <input_iterator _Ip, weakly_incrementable _Op>
59 requires indirectly_copyable<_Ip, _Op>
60 _LIBCPP_HIDE_FROM_ABI constexpr
61 copy_n_result<_Ip, _Op> operator()(_Ip __first, iter_difference_t<_Ip> __n, _Op __result) const {
62 return __go(std::move(__first), __n, std::move(__result));
63 }
64};
65} // namespace __copy_n
66
67inline namespace __cpo {
68 inline constexpr auto copy_n = __copy_n::__fn{};
69} // namespace __cpo
70} // namespace ranges
71
72#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
73
74_LIBCPP_END_NAMESPACE_STD
75
76#endif // _LIBCPP___ALGORITHM_RANGES_COPY_N_H
lib/libcxx/include/__algorithm/ranges_count.h created+62
......@@ -0,0 +1,62 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_COUNT_H
10#define _LIBCPP___ALGORITHM_RANGES_COUNT_H
11
12#include <__algorithm/ranges_count_if.h>
13#include <__config>
14#include <__functional/identity.h>
15#include <__functional/ranges_operations.h>
16#include <__iterator/concepts.h>
17#include <__iterator/incrementable_traits.h>
18#include <__iterator/iterator_traits.h>
19#include <__iterator/projected.h>
20#include <__ranges/access.h>
21#include <__ranges/concepts.h>
22#include <__utility/move.h>
23
24#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
25# pragma GCC system_header
26#endif
27
28#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
29
30_LIBCPP_BEGIN_NAMESPACE_STD
31
32namespace ranges {
33namespace __count {
34struct __fn {
35 template <input_iterator _Iter, sentinel_for<_Iter> _Sent, class _Type, class _Proj = identity>
36 requires indirect_binary_predicate<ranges::equal_to, projected<_Iter, _Proj>, const _Type*>
37 _LIBCPP_HIDE_FROM_ABI constexpr
38 iter_difference_t<_Iter> operator()(_Iter __first, _Sent __last, const _Type& __value, _Proj __proj = {}) const {
39 auto __pred = [&](auto&& __e) { return __e == __value; };
40 return ranges::__count_if_impl(std::move(__first), std::move(__last), __pred, __proj);
41 }
42
43 template <input_range _Range, class _Type, class _Proj = identity>
44 requires indirect_binary_predicate<ranges::equal_to, projected<iterator_t<_Range>, _Proj>, const _Type*>
45 _LIBCPP_HIDE_FROM_ABI constexpr
46 range_difference_t<_Range> operator()(_Range&& __r, const _Type& __value, _Proj __proj = {}) const {
47 auto __pred = [&](auto&& __e) { return __e == __value; };
48 return ranges::__count_if_impl(ranges::begin(__r), ranges::end(__r), __pred, __proj);
49 }
50};
51} // namespace __count
52
53inline namespace __cpo {
54 inline constexpr auto count = __count::__fn{};
55} // namespace __cpo
56} // namespace ranges
57
58_LIBCPP_END_NAMESPACE_STD
59
60#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
61
62#endif // _LIBCPP___ALGORITHM_RANGES_COUNT_H
lib/libcxx/include/__algorithm/ranges_count_if.h created+72
......@@ -0,0 +1,72 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_COUNT_IF_H
10#define _LIBCPP___ALGORITHM_RANGES_COUNT_IF_H
11
12#include <__config>
13#include <__functional/identity.h>
14#include <__functional/invoke.h>
15#include <__functional/ranges_operations.h>
16#include <__iterator/concepts.h>
17#include <__iterator/incrementable_traits.h>
18#include <__iterator/iterator_traits.h>
19#include <__iterator/projected.h>
20#include <__ranges/access.h>
21#include <__ranges/concepts.h>
22#include <__utility/move.h>
23
24#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
25# pragma GCC system_header
26#endif
27
28#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
29
30_LIBCPP_BEGIN_NAMESPACE_STD
31
32namespace ranges {
33template <class _Iter, class _Sent, class _Proj, class _Pred>
34_LIBCPP_HIDE_FROM_ABI constexpr
35iter_difference_t<_Iter> __count_if_impl(_Iter __first, _Sent __last,
36 _Pred& __pred, _Proj& __proj) {
37 iter_difference_t<_Iter> __counter(0);
38 for (; __first != __last; ++__first) {
39 if (std::invoke(__pred, std::invoke(__proj, *__first)))
40 ++__counter;
41 }
42 return __counter;
43}
44
45namespace __count_if {
46struct __fn {
47 template <input_iterator _Iter, sentinel_for<_Iter> _Sent, class _Proj = identity,
48 indirect_unary_predicate<projected<_Iter, _Proj>> _Predicate>
49 _LIBCPP_HIDE_FROM_ABI constexpr
50 iter_difference_t<_Iter> operator()(_Iter __first, _Sent __last, _Predicate __pred, _Proj __proj = {}) const {
51 return ranges::__count_if_impl(std::move(__first), std::move(__last), __pred, __proj);
52 }
53
54 template <input_range _Range, class _Proj = identity,
55 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>> _Predicate>
56 _LIBCPP_HIDE_FROM_ABI constexpr
57 range_difference_t<_Range> operator()(_Range&& __r, _Predicate __pred, _Proj __proj = {}) const {
58 return ranges::__count_if_impl(ranges::begin(__r), ranges::end(__r), __pred, __proj);
59 }
60};
61} // namespace __count_if
62
63inline namespace __cpo {
64 inline constexpr auto count_if = __count_if::__fn{};
65} // namespace __cpo
66} // namespace ranges
67
68_LIBCPP_END_NAMESPACE_STD
69
70#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
71
72#endif // _LIBCPP___ALGORITHM_RANGES_COUNT_IF_H
lib/libcxx/include/__algorithm/ranges_equal.h created+115
......@@ -0,0 +1,115 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_EQUAL_H
10#define _LIBCPP___ALGORITHM_RANGES_EQUAL_H
11
12#include <__config>
13#include <__functional/identity.h>
14#include <__functional/invoke.h>
15#include <__functional/ranges_operations.h>
16#include <__iterator/concepts.h>
17#include <__iterator/distance.h>
18#include <__iterator/indirectly_comparable.h>
19#include <__ranges/access.h>
20#include <__ranges/concepts.h>
21#include <__utility/move.h>
22
23#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
24# pragma GCC system_header
25#endif
26
27#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
28
29_LIBCPP_BEGIN_NAMESPACE_STD
30
31namespace ranges {
32namespace __equal {
33struct __fn {
34private:
35 template <class _Iter1, class _Sent1,
36 class _Iter2, class _Sent2,
37 class _Pred,
38 class _Proj1,
39 class _Proj2>
40 _LIBCPP_HIDE_FROM_ABI constexpr static
41 bool __equal_impl(_Iter1 __first1, _Sent1 __last1,
42 _Iter2 __first2, _Sent2 __last2,
43 _Pred& __pred,
44 _Proj1& __proj1,
45 _Proj2& __proj2) {
46 while (__first1 != __last1 && __first2 != __last2) {
47 if (!std::invoke(__pred, std::invoke(__proj1, *__first1), std::invoke(__proj2, *__first2)))
48 return false;
49 ++__first1;
50 ++__first2;
51 }
52 return __first1 == __last1 && __first2 == __last2;
53 }
54
55public:
56
57 template <input_iterator _Iter1, sentinel_for<_Iter1> _Sent1,
58 input_iterator _Iter2, sentinel_for<_Iter2> _Sent2,
59 class _Pred = ranges::equal_to,
60 class _Proj1 = identity,
61 class _Proj2 = identity>
62 requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2>
63 _LIBCPP_HIDE_FROM_ABI constexpr
64 bool operator()(_Iter1 __first1, _Sent1 __last1,
65 _Iter2 __first2, _Sent2 __last2,
66 _Pred __pred = {},
67 _Proj1 __proj1 = {},
68 _Proj2 __proj2 = {}) const {
69 if constexpr (sized_sentinel_for<_Sent1, _Iter1> && sized_sentinel_for<_Sent2, _Iter2>) {
70 if (__last1 - __first1 != __last2 - __first2)
71 return false;
72 }
73 return __equal_impl(std::move(__first1), std::move(__last1),
74 std::move(__first2), std::move(__last2),
75 __pred,
76 __proj1,
77 __proj2);
78 }
79
80 template <input_range _Range1,
81 input_range _Range2,
82 class _Pred = ranges::equal_to,
83 class _Proj1 = identity,
84 class _Proj2 = identity>
85 requires indirectly_comparable<iterator_t<_Range1>, iterator_t<_Range2>, _Pred, _Proj1, _Proj2>
86 _LIBCPP_HIDE_FROM_ABI constexpr
87 bool operator()(_Range1&& __range1,
88 _Range2&& __range2,
89 _Pred __pred = {},
90 _Proj1 __proj1 = {},
91 _Proj2 __proj2 = {}) const {
92 if constexpr (sized_range<_Range1> && sized_range<_Range2>) {
93 if (ranges::distance(__range1) != ranges::distance(__range2))
94 return false;
95 }
96 return __equal_impl(ranges::begin(__range1), ranges::end(__range1),
97 ranges::begin(__range2), ranges::end(__range2),
98 __pred,
99 __proj1,
100 __proj2);
101 return false;
102 }
103};
104} // namespace __equal
105
106inline namespace __cpo {
107 inline constexpr auto equal = __equal::__fn{};
108} // namespace __cpo
109} // namespace ranges
110
111_LIBCPP_END_NAMESPACE_STD
112
113#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
114
115#endif // _LIBCPP___ALGORITHM_RANGES_EQUAL_H
lib/libcxx/include/__algorithm/ranges_equal_range.h created+77
......@@ -0,0 +1,77 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM __project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_EQUAL_RANGE_H
10#define _LIBCPP___ALGORITHM_RANGES_EQUAL_RANGE_H
11
12#include <__algorithm/equal_range.h>
13#include <__algorithm/iterator_operations.h>
14#include <__config>
15#include <__functional/identity.h>
16#include <__functional/invoke.h>
17#include <__functional/ranges_operations.h>
18#include <__iterator/concepts.h>
19#include <__iterator/iterator_traits.h>
20#include <__iterator/projected.h>
21#include <__ranges/access.h>
22#include <__ranges/concepts.h>
23#include <__ranges/dangling.h>
24#include <__ranges/subrange.h>
25#include <__utility/forward.h>
26#include <__utility/move.h>
27
28#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
29# pragma GCC system_header
30#endif
31
32#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
33
34_LIBCPP_BEGIN_NAMESPACE_STD
35
36namespace ranges {
37namespace __equal_range {
38
39struct __fn {
40 template <
41 forward_iterator _Iter,
42 sentinel_for<_Iter> _Sent,
43 class _Tp,
44 class _Proj = identity,
45 indirect_strict_weak_order<const _Tp*, projected<_Iter, _Proj>> _Comp = ranges::less>
46 _LIBCPP_HIDE_FROM_ABI constexpr subrange<_Iter>
47 operator()(_Iter __first, _Sent __last, const _Tp& __value, _Comp __comp = {}, _Proj __proj = {}) const {
48 auto __ret = std::__equal_range<_RangeAlgPolicy>(
49 std::move(__first), std::move(__last), __value, __comp, __proj);
50 return {std::move(__ret.first), std::move(__ret.second)};
51 }
52
53 template <
54 forward_range _Range,
55 class _Tp,
56 class _Proj = identity,
57 indirect_strict_weak_order<const _Tp*, projected<iterator_t<_Range>, _Proj>> _Comp = ranges::less>
58 _LIBCPP_HIDE_FROM_ABI constexpr borrowed_subrange_t<_Range>
59 operator()(_Range&& __range, const _Tp& __value, _Comp __comp = {}, _Proj __proj = {}) const {
60 auto __ret = std::__equal_range<_RangeAlgPolicy>(
61 ranges::begin(__range), ranges::end(__range), __value, __comp, __proj);
62 return {std::move(__ret.first), std::move(__ret.second)};
63 }
64};
65
66} // namespace __equal_range
67
68inline namespace __cpo {
69 inline constexpr auto equal_range = __equal_range::__fn{};
70} // namespace __cpo
71} // namespace ranges
72
73_LIBCPP_END_NAMESPACE_STD
74
75#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
76
77#endif // _LIBCPP___ALGORITHM_RANGES_EQUAL_RANGE_H
lib/libcxx/include/__algorithm/ranges_fill.h created+59
......@@ -0,0 +1,59 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_FILL_H
10#define _LIBCPP___ALGORITHM_RANGES_FILL_H
11
12#include <__algorithm/ranges_fill_n.h>
13#include <__config>
14#include <__iterator/concepts.h>
15#include <__ranges/access.h>
16#include <__ranges/concepts.h>
17#include <__ranges/dangling.h>
18
19#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20# pragma GCC system_header
21#endif
22
23#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
24
25_LIBCPP_BEGIN_NAMESPACE_STD
26
27namespace ranges {
28namespace __fill {
29struct __fn {
30 template <class _Type, output_iterator<const _Type&> _Iter, sentinel_for<_Iter> _Sent>
31 _LIBCPP_HIDE_FROM_ABI constexpr
32 _Iter operator()(_Iter __first, _Sent __last, const _Type& __value) const {
33 if constexpr(random_access_iterator<_Iter> && sized_sentinel_for<_Sent, _Iter>) {
34 return ranges::fill_n(__first, __last - __first, __value);
35 } else {
36 for (; __first != __last; ++__first)
37 *__first = __value;
38 return __first;
39 }
40 }
41
42 template <class _Type, output_range<const _Type&> _Range>
43 _LIBCPP_HIDE_FROM_ABI constexpr
44 borrowed_iterator_t<_Range> operator()(_Range&& __range, const _Type& __value) const {
45 return (*this)(ranges::begin(__range), ranges::end(__range), __value);
46 }
47};
48} // namespace __fill
49
50inline namespace __cpo {
51 inline constexpr auto fill = __fill::__fn{};
52} // namespace __cpo
53} // namespace ranges
54
55_LIBCPP_END_NAMESPACE_STD
56
57#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
58
59#endif // _LIBCPP___ALGORITHM_RANGES_FILL_H
lib/libcxx/include/__algorithm/ranges_fill_n.h created+48
......@@ -0,0 +1,48 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_FILL_N_H
10#define _LIBCPP___ALGORITHM_RANGES_FILL_N_H
11
12#include <__config>
13#include <__iterator/concepts.h>
14#include <__iterator/incrementable_traits.h>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
20#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
21
22_LIBCPP_BEGIN_NAMESPACE_STD
23
24namespace ranges {
25namespace __fill_n {
26struct __fn {
27 template <class _Type, output_iterator<const _Type&> _Iter>
28 _LIBCPP_HIDE_FROM_ABI constexpr
29 _Iter operator()(_Iter __first, iter_difference_t<_Iter> __n, const _Type& __value) const {
30 for (; __n != 0; --__n) {
31 *__first = __value;
32 ++__first;
33 }
34 return __first;
35 }
36};
37} // namespace __fill_n
38
39inline namespace __cpo {
40 inline constexpr auto fill_n = __fill_n::__fn{};
41} // namespace __cpo
42} // namespace ranges
43
44_LIBCPP_END_NAMESPACE_STD
45
46#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
47
48#endif // _LIBCPP___ALGORITHM_RANGES_FILL_N_H
lib/libcxx/include/__algorithm/ranges_find.h created+63
......@@ -0,0 +1,63 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_FIND_H
10#define _LIBCPP___ALGORITHM_RANGES_FIND_H
11
12#include <__algorithm/ranges_find_if.h>
13#include <__config>
14#include <__functional/identity.h>
15#include <__functional/invoke.h>
16#include <__functional/ranges_operations.h>
17#include <__iterator/concepts.h>
18#include <__iterator/projected.h>
19#include <__ranges/access.h>
20#include <__ranges/concepts.h>
21#include <__ranges/dangling.h>
22#include <__utility/forward.h>
23#include <__utility/move.h>
24
25#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
26# pragma GCC system_header
27#endif
28
29#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
30
31_LIBCPP_BEGIN_NAMESPACE_STD
32
33namespace ranges {
34namespace __find {
35struct __fn {
36 template <input_iterator _Ip, sentinel_for<_Ip> _Sp, class _Tp, class _Proj = identity>
37 requires indirect_binary_predicate<ranges::equal_to, projected<_Ip, _Proj>, const _Tp*>
38 _LIBCPP_HIDE_FROM_ABI constexpr
39 _Ip operator()(_Ip __first, _Sp __last, const _Tp& __value, _Proj __proj = {}) const {
40 auto __pred = [&](auto&& __e) { return std::forward<decltype(__e)>(__e) == __value; };
41 return ranges::__find_if_impl(std::move(__first), std::move(__last), __pred, __proj);
42 }
43
44 template <input_range _Rp, class _Tp, class _Proj = identity>
45 requires indirect_binary_predicate<ranges::equal_to, projected<iterator_t<_Rp>, _Proj>, const _Tp*>
46 _LIBCPP_HIDE_FROM_ABI constexpr
47 borrowed_iterator_t<_Rp> operator()(_Rp&& __r, const _Tp& __value, _Proj __proj = {}) const {
48 auto __pred = [&](auto&& __e) { return std::forward<decltype(__e)>(__e) == __value; };
49 return ranges::__find_if_impl(ranges::begin(__r), ranges::end(__r), __pred, __proj);
50 }
51};
52} // namespace __find
53
54inline namespace __cpo {
55 inline constexpr auto find = __find::__fn{};
56} // namespace __cpo
57} // namespace ranges
58
59_LIBCPP_END_NAMESPACE_STD
60
61#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
62
63#endif // _LIBCPP___ALGORITHM_RANGES_FIND_H
lib/libcxx/include/__algorithm/ranges_find_end.h created+97
......@@ -0,0 +1,97 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_FIND_END_H
10#define _LIBCPP___ALGORITHM_RANGES_FIND_END_H
11
12#include <__algorithm/find_end.h>
13#include <__algorithm/iterator_operations.h>
14#include <__algorithm/ranges_iterator_concept.h>
15#include <__config>
16#include <__functional/identity.h>
17#include <__functional/ranges_operations.h>
18#include <__iterator/concepts.h>
19#include <__iterator/indirectly_comparable.h>
20#include <__iterator/iterator_traits.h>
21#include <__ranges/access.h>
22#include <__ranges/concepts.h>
23#include <__ranges/subrange.h>
24
25#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
26# pragma GCC system_header
27#endif
28
29#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
30
31_LIBCPP_BEGIN_NAMESPACE_STD
32
33namespace ranges {
34namespace __find_end {
35struct __fn {
36 template <forward_iterator _Iter1, sentinel_for<_Iter1> _Sent1,
37 forward_iterator _Iter2, sentinel_for<_Iter2> _Sent2,
38 class _Pred = ranges::equal_to,
39 class _Proj1 = identity,
40 class _Proj2 = identity>
41 requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2>
42 _LIBCPP_HIDE_FROM_ABI constexpr
43 subrange<_Iter1> operator()(_Iter1 __first1, _Sent1 __last1,
44 _Iter2 __first2, _Sent2 __last2,
45 _Pred __pred = {},
46 _Proj1 __proj1 = {},
47 _Proj2 __proj2 = {}) const {
48 auto __ret = std::__find_end_impl<_RangeAlgPolicy>(
49 __first1,
50 __last1,
51 __first2,
52 __last2,
53 __pred,
54 __proj1,
55 __proj2,
56 __iterator_concept<_Iter1>(),
57 __iterator_concept<_Iter2>());
58 return {__ret.first, __ret.second};
59 }
60
61 template <forward_range _Range1,
62 forward_range _Range2,
63 class _Pred = ranges::equal_to,
64 class _Proj1 = identity,
65 class _Proj2 = identity>
66 requires indirectly_comparable<iterator_t<_Range1>, iterator_t<_Range2>, _Pred, _Proj1, _Proj2>
67 _LIBCPP_HIDE_FROM_ABI constexpr
68 borrowed_subrange_t<_Range1> operator()(_Range1&& __range1,
69 _Range2&& __range2,
70 _Pred __pred = {},
71 _Proj1 __proj1 = {},
72 _Proj2 __proj2 = {}) const {
73 auto __ret = std::__find_end_impl<_RangeAlgPolicy>(
74 ranges::begin(__range1),
75 ranges::end(__range1),
76 ranges::begin(__range2),
77 ranges::end(__range2),
78 __pred,
79 __proj1,
80 __proj2,
81 __iterator_concept<iterator_t<_Range1>>(),
82 __iterator_concept<iterator_t<_Range2>>());
83 return {__ret.first, __ret.second};
84 }
85};
86} // namespace __find_end
87
88inline namespace __cpo {
89 inline constexpr auto find_end = __find_end::__fn{};
90} // namespace __cpo
91} // namespace ranges
92
93_LIBCPP_END_NAMESPACE_STD
94
95#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
96
97#endif // _LIBCPP___ALGORITHM_RANGES_FIND_END_H
lib/libcxx/include/__algorithm/ranges_find_first_of.h created+101
......@@ -0,0 +1,101 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_FIND_FIRST_OF_H
10#define _LIBCPP___ALGORITHM_RANGES_FIND_FIRST_OF_H
11
12#include <__config>
13#include <__functional/identity.h>
14#include <__functional/invoke.h>
15#include <__functional/ranges_operations.h>
16#include <__iterator/concepts.h>
17#include <__iterator/indirectly_comparable.h>
18#include <__ranges/access.h>
19#include <__ranges/concepts.h>
20#include <__ranges/dangling.h>
21#include <__utility/move.h>
22
23#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
24# pragma GCC system_header
25#endif
26
27#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
28
29_LIBCPP_BEGIN_NAMESPACE_STD
30
31namespace ranges {
32namespace __find_first_of {
33struct __fn {
34
35 template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Pred, class _Proj1, class _Proj2>
36 _LIBCPP_HIDE_FROM_ABI constexpr static
37 _Iter1 __find_first_of_impl(_Iter1 __first1, _Sent1 __last1,
38 _Iter2 __first2, _Sent2 __last2,
39 _Pred& __pred,
40 _Proj1& __proj1,
41 _Proj2& __proj2) {
42 for (; __first1 != __last1; ++__first1) {
43 for (auto __j = __first2; __j != __last2; ++__j) {
44 if (std::invoke(__pred, std::invoke(__proj1, *__first1), std::invoke(__proj2, *__j)))
45 return __first1;
46 }
47 }
48 return __first1;
49 }
50
51 template <input_iterator _Iter1, sentinel_for<_Iter1> _Sent1,
52 forward_iterator _Iter2, sentinel_for<_Iter2> _Sent2,
53 class _Pred = ranges::equal_to,
54 class _Proj1 = identity,
55 class _Proj2 = identity>
56 requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2>
57 _LIBCPP_HIDE_FROM_ABI constexpr
58 _Iter1 operator()(_Iter1 __first1, _Sent1 __last1,
59 _Iter2 __first2, _Sent2 __last2,
60 _Pred __pred = {},
61 _Proj1 __proj1 = {},
62 _Proj2 __proj2 = {}) const {
63 return __find_first_of_impl(std::move(__first1), std::move(__last1),
64 std::move(__first2), std::move(__last2),
65 __pred,
66 __proj1,
67 __proj2);
68 }
69
70 template <input_range _Range1,
71 forward_range _Range2,
72 class _Pred = ranges::equal_to,
73 class _Proj1 = identity,
74 class _Proj2 = identity>
75 requires indirectly_comparable<iterator_t<_Range1>, iterator_t<_Range2>, _Pred, _Proj1, _Proj2>
76 _LIBCPP_HIDE_FROM_ABI constexpr
77 borrowed_iterator_t<_Range1> operator()(_Range1&& __range1,
78 _Range2&& __range2,
79 _Pred __pred = {},
80 _Proj1 __proj1 = {},
81 _Proj2 __proj2 = {}) const {
82 return __find_first_of_impl(ranges::begin(__range1), ranges::end(__range1),
83 ranges::begin(__range2), ranges::end(__range2),
84 __pred,
85 __proj1,
86 __proj2);
87 }
88
89};
90} // namespace __find_first_of
91
92inline namespace __cpo {
93 inline constexpr auto find_first_of = __find_first_of::__fn{};
94} // namespace __cpo
95} // namespace ranges
96
97_LIBCPP_END_NAMESPACE_STD
98
99#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
100
101#endif // _LIBCPP___ALGORITHM_RANGES_FIND_FIRST_OF_H
lib/libcxx/include/__algorithm/ranges_find_if.h created+71
......@@ -0,0 +1,71 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_FIND_IF_H
10#define _LIBCPP___ALGORITHM_RANGES_FIND_IF_H
11
12#include <__config>
13#include <__functional/identity.h>
14#include <__functional/invoke.h>
15#include <__functional/ranges_operations.h>
16#include <__iterator/concepts.h>
17#include <__iterator/projected.h>
18#include <__ranges/access.h>
19#include <__ranges/concepts.h>
20#include <__ranges/dangling.h>
21#include <__utility/move.h>
22
23#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
24# pragma GCC system_header
25#endif
26
27#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
28
29_LIBCPP_BEGIN_NAMESPACE_STD
30
31namespace ranges {
32
33template <class _Ip, class _Sp, class _Pred, class _Proj>
34_LIBCPP_HIDE_FROM_ABI static constexpr
35_Ip __find_if_impl(_Ip __first, _Sp __last, _Pred& __pred, _Proj& __proj) {
36 for (; __first != __last; ++__first) {
37 if (std::invoke(__pred, std::invoke(__proj, *__first)))
38 break;
39 }
40 return __first;
41}
42
43namespace __find_if {
44struct __fn {
45
46 template <input_iterator _Ip, sentinel_for<_Ip> _Sp, class _Proj = identity,
47 indirect_unary_predicate<projected<_Ip, _Proj>> _Pred>
48 _LIBCPP_HIDE_FROM_ABI constexpr
49 _Ip operator()(_Ip __first, _Sp __last, _Pred __pred, _Proj __proj = {}) const {
50 return ranges::__find_if_impl(std::move(__first), std::move(__last), __pred, __proj);
51 }
52
53 template <input_range _Rp, class _Proj = identity,
54 indirect_unary_predicate<projected<iterator_t<_Rp>, _Proj>> _Pred>
55 _LIBCPP_HIDE_FROM_ABI constexpr
56 borrowed_iterator_t<_Rp> operator()(_Rp&& __r, _Pred __pred, _Proj __proj = {}) const {
57 return ranges::__find_if_impl(ranges::begin(__r), ranges::end(__r), __pred, __proj);
58 }
59};
60} // namespace __find_if
61
62inline namespace __cpo {
63 inline constexpr auto find_if = __find_if::__fn{};
64} // namespace __cpo
65} // namespace ranges
66
67_LIBCPP_END_NAMESPACE_STD
68
69#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
70
71#endif // _LIBCPP___ALGORITHM_RANGES_FIND_IF_H
lib/libcxx/include/__algorithm/ranges_find_if_not.h created+63
......@@ -0,0 +1,63 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_FIND_IF_NOT_H
10#define _LIBCPP___ALGORITHM_RANGES_FIND_IF_NOT_H
11
12#include <__algorithm/ranges_find_if.h>
13#include <__config>
14#include <__functional/identity.h>
15#include <__functional/invoke.h>
16#include <__functional/ranges_operations.h>
17#include <__iterator/concepts.h>
18#include <__iterator/projected.h>
19#include <__ranges/access.h>
20#include <__ranges/concepts.h>
21#include <__ranges/dangling.h>
22#include <__utility/forward.h>
23#include <__utility/move.h>
24
25#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
26# pragma GCC system_header
27#endif
28
29#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
30
31_LIBCPP_BEGIN_NAMESPACE_STD
32
33namespace ranges {
34namespace __find_if_not {
35struct __fn {
36 template <input_iterator _Ip, sentinel_for<_Ip> _Sp, class _Proj = identity,
37 indirect_unary_predicate<projected<_Ip, _Proj>> _Pred>
38 _LIBCPP_HIDE_FROM_ABI constexpr
39 _Ip operator()(_Ip __first, _Sp __last, _Pred __pred, _Proj __proj = {}) const {
40 auto __pred2 = [&](auto&& __e) { return !std::invoke(__pred, std::forward<decltype(__e)>(__e)); };
41 return ranges::__find_if_impl(std::move(__first), std::move(__last), __pred2, __proj);
42 }
43
44 template <input_range _Rp, class _Proj = identity,
45 indirect_unary_predicate<projected<iterator_t<_Rp>, _Proj>> _Pred>
46 _LIBCPP_HIDE_FROM_ABI constexpr
47 borrowed_iterator_t<_Rp> operator()(_Rp&& __r, _Pred __pred, _Proj __proj = {}) const {
48 auto __pred2 = [&](auto&& __e) { return !std::invoke(__pred, std::forward<decltype(__e)>(__e)); };
49 return ranges::__find_if_impl(ranges::begin(__r), ranges::end(__r), __pred2, __proj);
50 }
51};
52} // namespace __find_if_not
53
54inline namespace __cpo {
55 inline constexpr auto find_if_not = __find_if_not::__fn{};
56} // namespace __cpo
57} // namespace ranges
58
59_LIBCPP_END_NAMESPACE_STD
60
61#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
62
63#endif // _LIBCPP___ALGORITHM_RANGES_FIND_IF_NOT_H
lib/libcxx/include/__algorithm/ranges_for_each.h created+78
......@@ -0,0 +1,78 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_FOR_EACH_H
10#define _LIBCPP___ALGORITHM_RANGES_FOR_EACH_H
11
12#include <__algorithm/in_fun_result.h>
13#include <__config>
14#include <__functional/identity.h>
15#include <__functional/invoke.h>
16#include <__iterator/concepts.h>
17#include <__iterator/projected.h>
18#include <__ranges/access.h>
19#include <__ranges/concepts.h>
20#include <__ranges/dangling.h>
21#include <__utility/move.h>
22
23#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
24# pragma GCC system_header
25#endif
26
27#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
28
29_LIBCPP_BEGIN_NAMESPACE_STD
30
31namespace ranges {
32
33template <class _Iter, class _Func>
34using for_each_result = in_fun_result<_Iter, _Func>;
35
36namespace __for_each {
37struct __fn {
38private:
39 template <class _Iter, class _Sent, class _Proj, class _Func>
40 _LIBCPP_HIDE_FROM_ABI constexpr static
41 for_each_result<_Iter, _Func> __for_each_impl(_Iter __first, _Sent __last, _Func& __func, _Proj& __proj) {
42 for (; __first != __last; ++__first)
43 std::invoke(__func, std::invoke(__proj, *__first));
44 return {std::move(__first), std::move(__func)};
45 }
46
47public:
48 template <input_iterator _Iter, sentinel_for<_Iter> _Sent,
49 class _Proj = identity,
50 indirectly_unary_invocable<projected<_Iter, _Proj>> _Func>
51 _LIBCPP_HIDE_FROM_ABI constexpr
52 for_each_result<_Iter, _Func> operator()(_Iter __first, _Sent __last, _Func __func, _Proj __proj = {}) const {
53 return __for_each_impl(std::move(__first), std::move(__last), __func, __proj);
54 }
55
56 template <input_range _Range,
57 class _Proj = identity,
58 indirectly_unary_invocable<projected<iterator_t<_Range>, _Proj>> _Func>
59 _LIBCPP_HIDE_FROM_ABI constexpr
60 for_each_result<borrowed_iterator_t<_Range>, _Func> operator()(_Range&& __range,
61 _Func __func,
62 _Proj __proj = {}) const {
63 return __for_each_impl(ranges::begin(__range), ranges::end(__range), __func, __proj);
64 }
65
66};
67} // namespace __for_each
68
69inline namespace __cpo {
70 inline constexpr auto for_each = __for_each::__fn{};
71} // namespace __cpo
72} // namespace ranges
73
74_LIBCPP_END_NAMESPACE_STD
75
76#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
77
78#endif // _LIBCPP___ALGORITHM_RANGES_FOR_EACH_H
lib/libcxx/include/__algorithm/ranges_for_each_n.h created+66
......@@ -0,0 +1,66 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_FOR_EACH_N_H
10#define _LIBCPP___ALGORITHM_RANGES_FOR_EACH_N_H
11
12#include <__algorithm/in_fun_result.h>
13#include <__config>
14#include <__functional/identity.h>
15#include <__functional/invoke.h>
16#include <__iterator/concepts.h>
17#include <__iterator/incrementable_traits.h>
18#include <__iterator/iterator_traits.h>
19#include <__iterator/projected.h>
20#include <__ranges/concepts.h>
21#include <__utility/move.h>
22
23#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
24# pragma GCC system_header
25#endif
26
27#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
28
29_LIBCPP_BEGIN_NAMESPACE_STD
30
31namespace ranges {
32
33template <class _Iter, class _Func>
34using for_each_n_result = in_fun_result<_Iter, _Func>;
35
36namespace __for_each_n {
37struct __fn {
38
39 template <input_iterator _Iter,
40 class _Proj = identity,
41 indirectly_unary_invocable<projected<_Iter, _Proj>> _Func>
42 _LIBCPP_HIDE_FROM_ABI constexpr
43 for_each_n_result<_Iter, _Func> operator()(_Iter __first,
44 iter_difference_t<_Iter> __count,
45 _Func __func,
46 _Proj __proj = {}) const {
47 while (__count-- > 0) {
48 std::invoke(__func, std::invoke(__proj, *__first));
49 ++__first;
50 }
51 return {std::move(__first), std::move(__func)};
52 }
53
54};
55} // namespace __for_each_n
56
57inline namespace __cpo {
58 inline constexpr auto for_each_n = __for_each_n::__fn{};
59} // namespace __cpo
60} // namespace ranges
61
62_LIBCPP_END_NAMESPACE_STD
63
64#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
65
66#endif // _LIBCPP___ALGORITHM_RANGES_FOR_EACH_N_H
lib/libcxx/include/__algorithm/ranges_generate.h created+73
......@@ -0,0 +1,73 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_GENERATE_H
10#define _LIBCPP___ALGORITHM_RANGES_GENERATE_H
11
12#include <__concepts/constructible.h>
13#include <__concepts/invocable.h>
14#include <__config>
15#include <__functional/invoke.h>
16#include <__iterator/concepts.h>
17#include <__iterator/iterator_traits.h>
18#include <__ranges/access.h>
19#include <__ranges/concepts.h>
20#include <__ranges/dangling.h>
21#include <__utility/move.h>
22
23#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
24# pragma GCC system_header
25#endif
26
27#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
28
29_LIBCPP_BEGIN_NAMESPACE_STD
30
31namespace ranges {
32namespace __generate {
33
34struct __fn {
35
36 template <class _OutIter, class _Sent, class _Func>
37 _LIBCPP_HIDE_FROM_ABI constexpr
38 static _OutIter __generate_fn_impl(_OutIter __first, _Sent __last, _Func& __gen) {
39 for (; __first != __last; ++__first) {
40 *__first = __gen();
41 }
42
43 return __first;
44 }
45
46 template <input_or_output_iterator _OutIter, sentinel_for<_OutIter> _Sent, copy_constructible _Func>
47 requires invocable<_Func&> && indirectly_writable<_OutIter, invoke_result_t<_Func&>>
48 _LIBCPP_HIDE_FROM_ABI constexpr
49 _OutIter operator()(_OutIter __first, _Sent __last, _Func __gen) const {
50 return __generate_fn_impl(std::move(__first), std::move(__last), __gen);
51 }
52
53 template <class _Range, copy_constructible _Func>
54 requires invocable<_Func&> && output_range<_Range, invoke_result_t<_Func&>>
55 _LIBCPP_HIDE_FROM_ABI constexpr
56 borrowed_iterator_t<_Range> operator()(_Range&& __range, _Func __gen) const {
57 return __generate_fn_impl(ranges::begin(__range), ranges::end(__range), __gen);
58 }
59
60};
61
62} // namespace __generate
63
64inline namespace __cpo {
65 inline constexpr auto generate = __generate::__fn{};
66} // namespace __cpo
67} // namespace ranges
68
69_LIBCPP_END_NAMESPACE_STD
70
71#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
72
73#endif // _LIBCPP___ALGORITHM_RANGES_GENERATE_H
lib/libcxx/include/__algorithm/ranges_generate_n.h created+62
......@@ -0,0 +1,62 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_GENERATE_N_H
10#define _LIBCPP___ALGORITHM_RANGES_GENERATE_N_H
11
12#include <__concepts/constructible.h>
13#include <__concepts/invocable.h>
14#include <__config>
15#include <__functional/identity.h>
16#include <__functional/invoke.h>
17#include <__iterator/concepts.h>
18#include <__iterator/incrementable_traits.h>
19#include <__iterator/iterator_traits.h>
20#include <__ranges/access.h>
21#include <__ranges/concepts.h>
22#include <__utility/move.h>
23
24#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
25# pragma GCC system_header
26#endif
27
28#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
29
30_LIBCPP_BEGIN_NAMESPACE_STD
31
32namespace ranges {
33namespace __generate_n {
34
35struct __fn {
36
37 template <input_or_output_iterator _OutIter, copy_constructible _Func>
38 requires invocable<_Func&> && indirectly_writable<_OutIter, invoke_result_t<_Func&>>
39 _LIBCPP_HIDE_FROM_ABI constexpr
40 _OutIter operator()(_OutIter __first, iter_difference_t<_OutIter> __n, _Func __gen) const {
41 for (; __n > 0; --__n) {
42 *__first = __gen();
43 ++__first;
44 }
45
46 return __first;
47 }
48
49};
50
51} // namespace __generate_n
52
53inline namespace __cpo {
54 inline constexpr auto generate_n = __generate_n::__fn{};
55} // namespace __cpo
56} // namespace ranges
57
58_LIBCPP_END_NAMESPACE_STD
59
60#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
61
62#endif // _LIBCPP___ALGORITHM_RANGES_GENERATE_N_H
lib/libcxx/include/__algorithm/ranges_includes.h created+95
......@@ -0,0 +1,95 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_INCLUDES_H
10#define _LIBCPP___ALGORITHM_RANGES_INCLUDES_H
11
12#include <__algorithm/includes.h>
13#include <__algorithm/make_projected.h>
14#include <__config>
15#include <__functional/identity.h>
16#include <__functional/invoke.h>
17#include <__functional/ranges_operations.h>
18#include <__iterator/concepts.h>
19#include <__iterator/iterator_traits.h>
20#include <__iterator/projected.h>
21#include <__ranges/access.h>
22#include <__ranges/concepts.h>
23#include <__utility/forward.h>
24#include <__utility/move.h>
25
26#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
27# pragma GCC system_header
28#endif
29
30#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
31
32_LIBCPP_BEGIN_NAMESPACE_STD
33
34namespace ranges {
35namespace __includes {
36
37struct __fn {
38 template <
39 input_iterator _Iter1,
40 sentinel_for<_Iter1> _Sent1,
41 input_iterator _Iter2,
42 sentinel_for<_Iter2> _Sent2,
43 class _Proj1 = identity,
44 class _Proj2 = identity,
45 indirect_strict_weak_order<projected<_Iter1, _Proj1>, projected<_Iter2, _Proj2>> _Comp = ranges::less>
46 _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(
47 _Iter1 __first1,
48 _Sent1 __last1,
49 _Iter2 __first2,
50 _Sent2 __last2,
51 _Comp __comp = {},
52 _Proj1 __proj1 = {},
53 _Proj2 __proj2 = {}) const {
54 return std::__includes(
55 std::move(__first1),
56 std::move(__last1),
57 std::move(__first2),
58 std::move(__last2),
59 std::move(__comp),
60 std::move(__proj1),
61 std::move(__proj2));
62 }
63
64 template <
65 input_range _Range1,
66 input_range _Range2,
67 class _Proj1 = identity,
68 class _Proj2 = identity,
69 indirect_strict_weak_order<projected<iterator_t<_Range1>, _Proj1>, projected<iterator_t<_Range2>, _Proj2>>
70 _Comp = ranges::less>
71 _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(
72 _Range1&& __range1, _Range2&& __range2, _Comp __comp = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const {
73 return std::__includes(
74 ranges::begin(__range1),
75 ranges::end(__range1),
76 ranges::begin(__range2),
77 ranges::end(__range2),
78 std::move(__comp),
79 std::move(__proj1),
80 std::move(__proj2));
81 }
82};
83
84} // namespace __includes
85
86inline namespace __cpo {
87 inline constexpr auto includes = __includes::__fn{};
88} // namespace __cpo
89} // namespace ranges
90
91_LIBCPP_END_NAMESPACE_STD
92
93#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
94
95#endif // _LIBCPP___ALGORITHM_RANGES_INCLUDES_H
lib/libcxx/include/__algorithm/ranges_inplace_merge.h created+85
......@@ -0,0 +1,85 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_INPLACE_MERGE_H
10#define _LIBCPP___ALGORITHM_RANGES_INPLACE_MERGE_H
11
12#include <__algorithm/inplace_merge.h>
13#include <__algorithm/iterator_operations.h>
14#include <__algorithm/make_projected.h>
15#include <__config>
16#include <__functional/identity.h>
17#include <__functional/invoke.h>
18#include <__functional/ranges_operations.h>
19#include <__iterator/concepts.h>
20#include <__iterator/iterator_traits.h>
21#include <__iterator/next.h>
22#include <__iterator/projected.h>
23#include <__iterator/sortable.h>
24#include <__ranges/access.h>
25#include <__ranges/concepts.h>
26#include <__ranges/dangling.h>
27#include <__utility/forward.h>
28#include <__utility/move.h>
29
30#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
31# pragma GCC system_header
32#endif
33
34#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
35
36_LIBCPP_BEGIN_NAMESPACE_STD
37
38namespace ranges {
39namespace __inplace_merge {
40
41 struct __fn {
42 template <class _Iter, class _Sent, class _Comp, class _Proj>
43 _LIBCPP_HIDE_FROM_ABI static constexpr auto
44 __inplace_merge_impl(_Iter __first, _Iter __middle, _Sent __last, _Comp&& __comp, _Proj&& __proj) {
45 auto __last_iter = ranges::next(__middle, __last);
46 std::__inplace_merge<_RangeAlgPolicy>(
47 std::move(__first), std::move(__middle), __last_iter, std::__make_projected(__comp, __proj));
48 return __last_iter;
49 }
50
51 template <
52 bidirectional_iterator _Iter,
53 sentinel_for<_Iter> _Sent,
54 class _Comp = ranges::less,
55 class _Proj = identity>
56 requires sortable<_Iter, _Comp, _Proj>
57 _LIBCPP_HIDE_FROM_ABI _Iter
58 operator()(_Iter __first, _Iter __middle, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const {
59 return __inplace_merge_impl(
60 std::move(__first), std::move(__middle), std::move(__last), std::move(__comp), std::move(__proj));
61 }
62
63 template <bidirectional_range _Range, class _Comp = ranges::less, class _Proj = identity>
64 requires sortable<
65 iterator_t<_Range>,
66 _Comp,
67 _Proj> _LIBCPP_HIDE_FROM_ABI borrowed_iterator_t<_Range>
68 operator()(_Range&& __range, iterator_t<_Range> __middle, _Comp __comp = {}, _Proj __proj = {}) const {
69 return __inplace_merge_impl(
70 ranges::begin(__range), std::move(__middle), ranges::end(__range), std::move(__comp), std::move(__proj));
71 }
72 };
73
74} // namespace __inplace_merge
75
76inline namespace __cpo {
77 inline constexpr auto inplace_merge = __inplace_merge::__fn{};
78} // namespace __cpo
79} // namespace ranges
80
81_LIBCPP_END_NAMESPACE_STD
82
83#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
84
85#endif // _LIBCPP___ALGORITHM_RANGES_INPLACE_MERGE_H
lib/libcxx/include/__algorithm/ranges_is_heap.h created+74
......@@ -0,0 +1,74 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_IS_HEAP_H
10#define _LIBCPP___ALGORITHM_RANGES_IS_HEAP_H
11
12#include <__algorithm/is_heap_until.h>
13#include <__algorithm/make_projected.h>
14#include <__config>
15#include <__functional/identity.h>
16#include <__functional/ranges_operations.h>
17#include <__iterator/concepts.h>
18#include <__iterator/iterator_traits.h>
19#include <__iterator/next.h>
20#include <__iterator/projected.h>
21#include <__ranges/access.h>
22#include <__ranges/concepts.h>
23#include <__utility/move.h>
24
25#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
26# pragma GCC system_header
27#endif
28
29#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
30
31_LIBCPP_BEGIN_NAMESPACE_STD
32
33namespace ranges {
34namespace __is_heap {
35
36struct __fn {
37
38 template <class _Iter, class _Sent, class _Proj, class _Comp>
39 _LIBCPP_HIDE_FROM_ABI constexpr
40 static bool __is_heap_fn_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) {
41 auto __last_iter = ranges::next(__first, __last);
42 auto&& __projected_comp = std::__make_projected(__comp, __proj);
43
44 auto __result = std::__is_heap_until(std::move(__first), std::move(__last_iter), __projected_comp);
45 return __result == __last;
46 }
47
48 template <random_access_iterator _Iter, sentinel_for<_Iter> _Sent, class _Proj = identity,
49 indirect_strict_weak_order<projected<_Iter, _Proj>> _Comp = ranges::less>
50 _LIBCPP_HIDE_FROM_ABI constexpr
51 bool operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const {
52 return __is_heap_fn_impl(std::move(__first), std::move(__last), __comp, __proj);
53 }
54
55 template <random_access_range _Range, class _Proj = identity,
56 indirect_strict_weak_order<projected<iterator_t<_Range>, _Proj>> _Comp = ranges::less>
57 _LIBCPP_HIDE_FROM_ABI constexpr
58 bool operator()(_Range&& __range, _Comp __comp = {}, _Proj __proj = {}) const {
59 return __is_heap_fn_impl(ranges::begin(__range), ranges::end(__range), __comp, __proj);
60 }
61};
62
63} // namespace __is_heap
64
65inline namespace __cpo {
66 inline constexpr auto is_heap = __is_heap::__fn{};
67} // namespace __cpo
68} // namespace ranges
69
70_LIBCPP_END_NAMESPACE_STD
71
72#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
73
74#endif // _LIBCPP___ALGORITHM_RANGES_IS_HEAP_H
lib/libcxx/include/__algorithm/ranges_is_heap_until.h created+75
......@@ -0,0 +1,75 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_IS_HEAP_UNTIL_H
10#define _LIBCPP___ALGORITHM_RANGES_IS_HEAP_UNTIL_H
11
12#include <__algorithm/is_heap_until.h>
13#include <__algorithm/make_projected.h>
14#include <__config>
15#include <__functional/identity.h>
16#include <__functional/ranges_operations.h>
17#include <__iterator/concepts.h>
18#include <__iterator/iterator_traits.h>
19#include <__iterator/next.h>
20#include <__iterator/projected.h>
21#include <__ranges/access.h>
22#include <__ranges/concepts.h>
23#include <__ranges/dangling.h>
24#include <__utility/move.h>
25
26#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
27# pragma GCC system_header
28#endif
29
30#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
31
32_LIBCPP_BEGIN_NAMESPACE_STD
33
34namespace ranges {
35namespace __is_heap_until {
36
37struct __fn {
38
39 template <class _Iter, class _Sent, class _Proj, class _Comp>
40 _LIBCPP_HIDE_FROM_ABI constexpr
41 static _Iter __is_heap_until_fn_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) {
42 auto __last_iter = ranges::next(__first, __last);
43 auto&& __projected_comp = std::__make_projected(__comp, __proj);
44
45 return std::__is_heap_until(std::move(__first), std::move(__last_iter), __projected_comp);
46 }
47
48 template <random_access_iterator _Iter, sentinel_for<_Iter> _Sent, class _Proj = identity,
49 indirect_strict_weak_order<projected<_Iter, _Proj>> _Comp = ranges::less>
50 _LIBCPP_HIDE_FROM_ABI constexpr
51 _Iter operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const {
52 return __is_heap_until_fn_impl(std::move(__first), std::move(__last), __comp, __proj);
53 }
54
55 template <random_access_range _Range, class _Proj = identity,
56 indirect_strict_weak_order<projected<iterator_t<_Range>, _Proj>> _Comp = ranges::less>
57 _LIBCPP_HIDE_FROM_ABI constexpr
58 borrowed_iterator_t<_Range> operator()(_Range&& __range, _Comp __comp = {}, _Proj __proj = {}) const {
59 return __is_heap_until_fn_impl(ranges::begin(__range), ranges::end(__range), __comp, __proj);
60 }
61
62};
63
64} // namespace __is_heap_until
65
66inline namespace __cpo {
67 inline constexpr auto is_heap_until = __is_heap_until::__fn{};
68} // namespace __cpo
69} // namespace ranges
70
71_LIBCPP_END_NAMESPACE_STD
72
73#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
74
75#endif // _LIBCPP___ALGORITHM_RANGES_IS_HEAP_UNTIL_H
lib/libcxx/include/__algorithm/ranges_is_partitioned.h created+81
......@@ -0,0 +1,81 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_IS_PARTITIONED_H
10#define _LIBCPP___ALGORITHM_RANGES_IS_PARTITIONED_H
11
12#include <__config>
13#include <__functional/identity.h>
14#include <__functional/invoke.h>
15#include <__iterator/concepts.h>
16#include <__iterator/indirectly_comparable.h>
17#include <__iterator/projected.h>
18#include <__ranges/access.h>
19#include <__ranges/concepts.h>
20#include <__utility/move.h>
21
22#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23# pragma GCC system_header
24#endif
25
26#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
27
28_LIBCPP_BEGIN_NAMESPACE_STD
29
30namespace ranges {
31namespace __is_partitioned {
32struct __fn {
33
34 template <class _Iter, class _Sent, class _Proj, class _Pred>
35 _LIBCPP_HIDE_FROM_ABI constexpr static
36 bool __is_parititioned_impl(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
37 for (; __first != __last; ++__first) {
38 if (!std::invoke(__pred, std::invoke(__proj, *__first)))
39 break;
40 }
41
42 if (__first == __last)
43 return true;
44 ++__first;
45
46 for (; __first != __last; ++__first) {
47 if (std::invoke(__pred, std::invoke(__proj, *__first)))
48 return false;
49 }
50
51 return true;
52 }
53
54 template <input_iterator _Iter, sentinel_for<_Iter> _Sent,
55 class _Proj = identity,
56 indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
57 _LIBCPP_HIDE_FROM_ABI constexpr
58 bool operator()(_Iter __first, _Sent __last, _Pred __pred, _Proj __proj = {}) const {
59 return __is_parititioned_impl(std::move(__first), std::move(__last), __pred, __proj);
60 }
61
62 template <input_range _Range,
63 class _Proj = identity,
64 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>> _Pred>
65 _LIBCPP_HIDE_FROM_ABI constexpr
66 bool operator()(_Range&& __range, _Pred __pred, _Proj __proj = {}) const {
67 return __is_parititioned_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj);
68 }
69};
70} // namespace __is_partitioned
71
72inline namespace __cpo {
73 inline constexpr auto is_partitioned = __is_partitioned::__fn{};
74} // namespace __cpo
75} // namespace ranges
76
77_LIBCPP_END_NAMESPACE_STD
78
79#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
80
81#endif // _LIBCPP___ALGORITHM_RANGES_IS_PARTITIONED_H
lib/libcxx/include/__algorithm/ranges_is_sorted.h created+61
......@@ -0,0 +1,61 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP__ALGORITHM_RANGES_IS_SORTED_H
10#define _LIBCPP__ALGORITHM_RANGES_IS_SORTED_H
11
12#include <__algorithm/ranges_is_sorted_until.h>
13#include <__config>
14#include <__functional/identity.h>
15#include <__functional/ranges_operations.h>
16#include <__iterator/concepts.h>
17#include <__iterator/projected.h>
18#include <__ranges/access.h>
19#include <__ranges/concepts.h>
20#include <__utility/move.h>
21
22#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23# pragma GCC system_header
24#endif
25
26#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
27
28_LIBCPP_BEGIN_NAMESPACE_STD
29
30namespace ranges {
31namespace __is_sorted {
32struct __fn {
33 template <forward_iterator _Iter, sentinel_for<_Iter> _Sent,
34 class _Proj = identity,
35 indirect_strict_weak_order<projected<_Iter, _Proj>> _Comp = ranges::less>
36 _LIBCPP_HIDE_FROM_ABI constexpr
37 bool operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const {
38 return ranges::__is_sorted_until_impl(std::move(__first), __last, __comp, __proj) == __last;
39 }
40
41 template <forward_range _Range,
42 class _Proj = identity,
43 indirect_strict_weak_order<projected<iterator_t<_Range>, _Proj>> _Comp = ranges::less>
44 _LIBCPP_HIDE_FROM_ABI constexpr
45 bool operator()(_Range&& __range, _Comp __comp = {}, _Proj __proj = {}) const {
46 auto __last = ranges::end(__range);
47 return ranges::__is_sorted_until_impl(ranges::begin(__range), __last, __comp, __proj) == __last;
48 }
49};
50} // namespace __is_sorted
51
52inline namespace __cpo {
53 inline constexpr auto is_sorted = __is_sorted::__fn{};
54} // namespace __cpo
55} // namespace ranges
56
57_LIBCPP_END_NAMESPACE_STD
58
59#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
60
61#endif // _LIBCPP__ALGORITHM_RANGES_IS_SORTED_H
lib/libcxx/include/__algorithm/ranges_is_sorted_until.h created+76
......@@ -0,0 +1,76 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP__ALGORITHM_RANGES_IS_SORTED_UNTIL_H
10#define _LIBCPP__ALGORITHM_RANGES_IS_SORTED_UNTIL_H
11
12#include <__config>
13#include <__functional/identity.h>
14#include <__functional/invoke.h>
15#include <__functional/ranges_operations.h>
16#include <__iterator/concepts.h>
17#include <__iterator/projected.h>
18#include <__ranges/access.h>
19#include <__ranges/concepts.h>
20#include <__ranges/dangling.h>
21#include <__utility/move.h>
22
23#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
24# pragma GCC system_header
25#endif
26
27#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
28
29_LIBCPP_BEGIN_NAMESPACE_STD
30
31namespace ranges {
32
33template <class _Iter, class _Sent, class _Proj, class _Comp>
34_LIBCPP_HIDE_FROM_ABI constexpr
35_Iter __is_sorted_until_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) {
36 if (__first == __last)
37 return __first;
38 auto __i = __first;
39 while (++__i != __last) {
40 if (std::invoke(__comp, std::invoke(__proj, *__i), std::invoke(__proj, *__first)))
41 return __i;
42 __first = __i;
43 }
44 return __i;
45}
46
47namespace __is_sorted_until {
48struct __fn {
49 template <forward_iterator _Iter, sentinel_for<_Iter> _Sent,
50 class _Proj = identity,
51 indirect_strict_weak_order<projected<_Iter, _Proj>> _Comp = ranges::less>
52 _LIBCPP_HIDE_FROM_ABI constexpr
53 _Iter operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const {
54 return ranges::__is_sorted_until_impl(std::move(__first), std::move(__last), __comp, __proj);
55 }
56
57 template <forward_range _Range,
58 class _Proj = identity,
59 indirect_strict_weak_order<projected<iterator_t<_Range>, _Proj>> _Comp = ranges::less>
60 _LIBCPP_HIDE_FROM_ABI constexpr
61 borrowed_iterator_t<_Range> operator()(_Range&& __range, _Comp __comp = {}, _Proj __proj = {}) const {
62 return ranges::__is_sorted_until_impl(ranges::begin(__range), ranges::end(__range), __comp, __proj);
63 }
64};
65} // namespace __is_sorted_until
66
67inline namespace __cpo {
68 inline constexpr auto is_sorted_until = __is_sorted_until::__fn{};
69} // namespace __cpo
70} // namespace ranges
71
72_LIBCPP_END_NAMESPACE_STD
73
74#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
75
76#endif // _LIBCPP__ALGORITHM_RANGES_IS_SORTED_UNTIL_H
lib/libcxx/include/__algorithm/ranges_iterator_concept.h created+51
......@@ -0,0 +1,51 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_ITERATOR_CONCEPT_H
10#define _LIBCPP___ALGORITHM_RANGES_ITERATOR_CONCEPT_H
11
12#include <__config>
13#include <__iterator/concepts.h>
14#include <__iterator/iterator_traits.h>
15#include <type_traits>
16
17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18# pragma GCC system_header
19#endif
20
21#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
22
23_LIBCPP_BEGIN_NAMESPACE_STD
24
25namespace ranges {
26
27template <class _IterMaybeQualified>
28consteval auto __get_iterator_concept() {
29 using _Iter = __uncvref_t<_IterMaybeQualified>;
30
31 if constexpr (contiguous_iterator<_Iter>)
32 return contiguous_iterator_tag();
33 else if constexpr (random_access_iterator<_Iter>)
34 return random_access_iterator_tag();
35 else if constexpr (bidirectional_iterator<_Iter>)
36 return bidirectional_iterator_tag();
37 else if constexpr (forward_iterator<_Iter>)
38 return forward_iterator_tag();
39 else if constexpr (input_iterator<_Iter>)
40 return input_iterator_tag();
41}
42
43template <class _Iter>
44using __iterator_concept = decltype(__get_iterator_concept<_Iter>());
45
46} // namespace ranges
47_LIBCPP_END_NAMESPACE_STD
48
49#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
50
51#endif // _LIBCPP___ALGORITHM_RANGES_ITERATOR_CONCEPT_H
lib/libcxx/include/__algorithm/ranges_lexicographical_compare.h created+98
......@@ -0,0 +1,98 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_LEXICOGRAPHICAL_COMPARE_H
10#define _LIBCPP___ALGORITHM_RANGES_LEXICOGRAPHICAL_COMPARE_H
11
12#include <__config>
13#include <__functional/identity.h>
14#include <__functional/invoke.h>
15#include <__functional/ranges_operations.h>
16#include <__iterator/concepts.h>
17#include <__iterator/projected.h>
18#include <__ranges/access.h>
19#include <__ranges/concepts.h>
20#include <__utility/move.h>
21
22#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23# pragma GCC system_header
24#endif
25
26#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
27
28_LIBCPP_BEGIN_NAMESPACE_STD
29
30namespace ranges {
31namespace __lexicographical_compare {
32struct __fn {
33
34 template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Proj1, class _Proj2, class _Comp>
35 _LIBCPP_HIDE_FROM_ABI constexpr static
36 bool __lexicographical_compare_impl(_Iter1 __first1, _Sent1 __last1,
37 _Iter2 __first2, _Sent2 __last2,
38 _Comp& __comp,
39 _Proj1& __proj1,
40 _Proj2& __proj2) {
41 while (__first2 != __last2) {
42 if (__first1 == __last1
43 || std::invoke(__comp, std::invoke(__proj1, *__first1), std::invoke(__proj2, *__first2)))
44 return true;
45 if (std::invoke(__comp, std::invoke(__proj2, *__first2), std::invoke(__proj1, *__first1)))
46 return false;
47 ++__first1;
48 ++__first2;
49 }
50 return false;
51 }
52
53 template <input_iterator _Iter1, sentinel_for<_Iter1> _Sent1,
54 input_iterator _Iter2, sentinel_for<_Iter2> _Sent2,
55 class _Proj1 = identity,
56 class _Proj2 = identity,
57 indirect_strict_weak_order<projected<_Iter1, _Proj1>, projected<_Iter2, _Proj2>> _Comp = ranges::less>
58 _LIBCPP_HIDE_FROM_ABI constexpr
59 bool operator()(_Iter1 __first1, _Sent1 __last1,
60 _Iter2 __first2, _Sent2 __last2,
61 _Comp __comp = {},
62 _Proj1 __proj1 = {},
63 _Proj2 __proj2 = {}) const {
64 return __lexicographical_compare_impl(std::move(__first1), std::move(__last1),
65 std::move(__first2), std::move(__last2),
66 __comp,
67 __proj1,
68 __proj2);
69 }
70
71 template <input_range _Range1,
72 input_range _Range2,
73 class _Proj1 = identity,
74 class _Proj2 = identity,
75 indirect_strict_weak_order<projected<iterator_t<_Range1>, _Proj1>,
76 projected<iterator_t<_Range2>, _Proj2>> _Comp = ranges::less>
77 _LIBCPP_HIDE_FROM_ABI constexpr
78 bool operator()(_Range1&& __range1, _Range2&& __range2, _Comp __comp = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const {
79 return __lexicographical_compare_impl(ranges::begin(__range1), ranges::end(__range1),
80 ranges::begin(__range2), ranges::end(__range2),
81 __comp,
82 __proj1,
83 __proj2);
84 }
85
86};
87} // namespace __lexicographical_compare
88
89inline namespace __cpo {
90 inline constexpr auto lexicographical_compare = __lexicographical_compare::__fn{};
91} // namespace __cpo
92} // namespace ranges
93
94_LIBCPP_END_NAMESPACE_STD
95
96#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
97
98#endif // _LIBCPP___ALGORITHM_RANGES_LEXICOGRAPHICAL_COMPARE_H
lib/libcxx/include/__algorithm/ranges_lower_bound.h created+66
......@@ -0,0 +1,66 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_LOWER_BOUND_H
10#define _LIBCPP___ALGORITHM_RANGES_LOWER_BOUND_H
11
12#include <__algorithm/iterator_operations.h>
13#include <__algorithm/lower_bound.h>
14#include <__config>
15#include <__functional/identity.h>
16#include <__functional/invoke.h>
17#include <__functional/ranges_operations.h>
18#include <__iterator/advance.h>
19#include <__iterator/concepts.h>
20#include <__iterator/iterator_traits.h>
21#include <__iterator/projected.h>
22#include <__ranges/access.h>
23#include <__ranges/concepts.h>
24#include <__ranges/dangling.h>
25
26#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
27# pragma GCC system_header
28#endif
29
30#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
31
32_LIBCPP_BEGIN_NAMESPACE_STD
33
34namespace ranges {
35
36namespace __lower_bound {
37struct __fn {
38 template <forward_iterator _Iter, sentinel_for<_Iter> _Sent, class _Type, class _Proj = identity,
39 indirect_strict_weak_order<const _Type*, projected<_Iter, _Proj>> _Comp = ranges::less>
40 _LIBCPP_HIDE_FROM_ABI constexpr
41 _Iter operator()(_Iter __first, _Sent __last, const _Type& __value, _Comp __comp = {}, _Proj __proj = {}) const {
42 return std::__lower_bound_impl<_RangeAlgPolicy>(__first, __last, __value, __comp, __proj);
43 }
44
45 template <forward_range _Range, class _Type, class _Proj = identity,
46 indirect_strict_weak_order<const _Type*, projected<iterator_t<_Range>, _Proj>> _Comp = ranges::less>
47 _LIBCPP_HIDE_FROM_ABI constexpr
48 borrowed_iterator_t<_Range> operator()(_Range&& __r,
49 const _Type& __value,
50 _Comp __comp = {},
51 _Proj __proj = {}) const {
52 return std::__lower_bound_impl<_RangeAlgPolicy>(ranges::begin(__r), ranges::end(__r), __value, __comp, __proj);
53 }
54};
55} // namespace __lower_bound
56
57inline namespace __cpo {
58 inline constexpr auto lower_bound = __lower_bound::__fn{};
59} // namespace __cpo
60} // namespace ranges
61
62_LIBCPP_END_NAMESPACE_STD
63
64#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
65
66#endif // _LIBCPP___ALGORITHM_RANGES_LOWER_BOUND_H
lib/libcxx/include/__algorithm/ranges_make_heap.h created+80
......@@ -0,0 +1,80 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_MAKE_HEAP_H
10#define _LIBCPP___ALGORITHM_RANGES_MAKE_HEAP_H
11
12#include <__algorithm/iterator_operations.h>
13#include <__algorithm/make_heap.h>
14#include <__algorithm/make_projected.h>
15#include <__concepts/same_as.h>
16#include <__config>
17#include <__functional/identity.h>
18#include <__functional/invoke.h>
19#include <__functional/ranges_operations.h>
20#include <__iterator/concepts.h>
21#include <__iterator/iterator_traits.h>
22#include <__iterator/next.h>
23#include <__iterator/projected.h>
24#include <__iterator/sortable.h>
25#include <__ranges/access.h>
26#include <__ranges/concepts.h>
27#include <__ranges/dangling.h>
28#include <__utility/forward.h>
29#include <__utility/move.h>
30
31#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
32# pragma GCC system_header
33#endif
34
35#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
36
37_LIBCPP_BEGIN_NAMESPACE_STD
38
39namespace ranges {
40namespace __make_heap {
41
42struct __fn {
43 template <class _Iter, class _Sent, class _Comp, class _Proj>
44 _LIBCPP_HIDE_FROM_ABI constexpr static
45 _Iter __make_heap_fn_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) {
46 auto __last_iter = ranges::next(__first, __last);
47
48 auto&& __projected_comp = std::__make_projected(__comp, __proj);
49 std::__make_heap<_RangeAlgPolicy>(std::move(__first), __last_iter, __projected_comp);
50
51 return __last_iter;
52 }
53
54 template <random_access_iterator _Iter, sentinel_for<_Iter> _Sent, class _Comp = ranges::less, class _Proj = identity>
55 requires sortable<_Iter, _Comp, _Proj>
56 _LIBCPP_HIDE_FROM_ABI constexpr
57 _Iter operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const {
58 return __make_heap_fn_impl(std::move(__first), std::move(__last), __comp, __proj);
59 }
60
61 template <random_access_range _Range, class _Comp = ranges::less, class _Proj = identity>
62 requires sortable<iterator_t<_Range>, _Comp, _Proj>
63 _LIBCPP_HIDE_FROM_ABI constexpr
64 borrowed_iterator_t<_Range> operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {}) const {
65 return __make_heap_fn_impl(ranges::begin(__r), ranges::end(__r), __comp, __proj);
66 }
67};
68
69} // namespace __make_heap
70
71inline namespace __cpo {
72 inline constexpr auto make_heap = __make_heap::__fn{};
73} // namespace __cpo
74} // namespace ranges
75
76_LIBCPP_END_NAMESPACE_STD
77
78#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
79
80#endif // _LIBCPP___ALGORITHM_RANGES_MAKE_HEAP_H
lib/libcxx/include/__algorithm/ranges_max.h created+93
......@@ -0,0 +1,93 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_MAX_H
10#define _LIBCPP___ALGORITHM_RANGES_MAX_H
11
12#include <__algorithm/ranges_min_element.h>
13#include <__assert>
14#include <__concepts/copyable.h>
15#include <__config>
16#include <__functional/identity.h>
17#include <__functional/invoke.h>
18#include <__functional/ranges_operations.h>
19#include <__iterator/concepts.h>
20#include <__iterator/projected.h>
21#include <__ranges/access.h>
22#include <__ranges/concepts.h>
23#include <__utility/move.h>
24#include <initializer_list>
25
26#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
27# pragma GCC system_header
28#endif
29
30#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
31
32_LIBCPP_PUSH_MACROS
33#include <__undef_macros>
34
35_LIBCPP_BEGIN_NAMESPACE_STD
36
37namespace ranges {
38namespace __max {
39struct __fn {
40 template <class _Tp, class _Proj = identity,
41 indirect_strict_weak_order<projected<const _Tp*, _Proj>> _Comp = ranges::less>
42 _LIBCPP_HIDE_FROM_ABI constexpr
43 const _Tp& operator()(const _Tp& __a, const _Tp& __b, _Comp __comp = {}, _Proj __proj = {}) const {
44 return std::invoke(__comp, std::invoke(__proj, __a), std::invoke(__proj, __b)) ? __b : __a;
45 }
46
47 template <copyable _Tp, class _Proj = identity,
48 indirect_strict_weak_order<projected<const _Tp*, _Proj>> _Comp = ranges::less>
49 _LIBCPP_HIDE_FROM_ABI constexpr
50 _Tp operator()(initializer_list<_Tp> __il, _Comp __comp = {}, _Proj __proj = {}) const {
51 _LIBCPP_ASSERT(__il.begin() != __il.end(), "initializer_list must contain at least one element");
52
53 auto __comp_lhs_rhs_swapped = [&](auto&& __lhs, auto&& __rhs) { return std::invoke(__comp, __rhs, __lhs); };
54 return *ranges::__min_element_impl(__il.begin(), __il.end(), __comp_lhs_rhs_swapped, __proj);
55 }
56
57 template <input_range _Rp, class _Proj = identity,
58 indirect_strict_weak_order<projected<iterator_t<_Rp>, _Proj>> _Comp = ranges::less>
59 requires indirectly_copyable_storable<iterator_t<_Rp>, range_value_t<_Rp>*>
60 _LIBCPP_HIDE_FROM_ABI constexpr
61 range_value_t<_Rp> operator()(_Rp&& __r, _Comp __comp = {}, _Proj __proj = {}) const {
62 auto __first = ranges::begin(__r);
63 auto __last = ranges::end(__r);
64
65 _LIBCPP_ASSERT(__first != __last, "range must contain at least one element");
66
67 if constexpr (forward_range<_Rp>) {
68 auto __comp_lhs_rhs_swapped = [&](auto&& __lhs, auto&& __rhs) { return std::invoke(__comp, __rhs, __lhs); };
69 return *ranges::__min_element_impl(std::move(__first), std::move(__last), __comp_lhs_rhs_swapped, __proj);
70 } else {
71 range_value_t<_Rp> __result = *__first;
72 while (++__first != __last) {
73 if (std::invoke(__comp, std::invoke(__proj, __result), std::invoke(__proj, *__first)))
74 __result = *__first;
75 }
76 return __result;
77 }
78 }
79};
80} // namespace __max
81
82inline namespace __cpo {
83 inline constexpr auto max = __max::__fn{};
84} // namespace __cpo
85} // namespace ranges
86
87_LIBCPP_END_NAMESPACE_STD
88
89_LIBCPP_POP_MACROS
90
91#endif // _LIBCPP_STD_VER > 17 && && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
92
93#endif // _LIBCPP___ALGORITHM_RANGES_MAX_H
lib/libcxx/include/__algorithm/ranges_max_element.h created+61
......@@ -0,0 +1,61 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_MAX_ELEMENT_H
10#define _LIBCPP___ALGORITHM_RANGES_MAX_ELEMENT_H
11
12#include <__algorithm/ranges_min_element.h>
13#include <__config>
14#include <__functional/identity.h>
15#include <__functional/invoke.h>
16#include <__functional/ranges_operations.h>
17#include <__iterator/concepts.h>
18#include <__iterator/projected.h>
19#include <__ranges/access.h>
20#include <__ranges/concepts.h>
21#include <__ranges/dangling.h>
22
23#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
24# pragma GCC system_header
25#endif
26
27#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
28
29_LIBCPP_BEGIN_NAMESPACE_STD
30
31namespace ranges {
32namespace __max_element {
33struct __fn {
34 template <forward_iterator _Ip, sentinel_for<_Ip> _Sp, class _Proj = identity,
35 indirect_strict_weak_order<projected<_Ip, _Proj>> _Comp = ranges::less>
36 _LIBCPP_HIDE_FROM_ABI constexpr
37 _Ip operator()(_Ip __first, _Sp __last, _Comp __comp = {}, _Proj __proj = {}) const {
38 auto __comp_lhs_rhs_swapped = [&](auto&& __lhs, auto&& __rhs) { return std::invoke(__comp, __rhs, __lhs); };
39 return ranges::__min_element_impl(__first, __last, __comp_lhs_rhs_swapped, __proj);
40 }
41
42 template <forward_range _Rp, class _Proj = identity,
43 indirect_strict_weak_order<projected<iterator_t<_Rp>, _Proj>> _Comp = ranges::less>
44 _LIBCPP_HIDE_FROM_ABI constexpr
45 borrowed_iterator_t<_Rp> operator()(_Rp&& __r, _Comp __comp = {}, _Proj __proj = {}) const {
46 auto __comp_lhs_rhs_swapped = [&](auto&& __lhs, auto&& __rhs) { return std::invoke(__comp, __rhs, __lhs); };
47 return ranges::__min_element_impl(ranges::begin(__r), ranges::end(__r), __comp_lhs_rhs_swapped, __proj);
48 }
49};
50} // namespace __max_element
51
52inline namespace __cpo {
53 inline constexpr auto max_element = __max_element::__fn{};
54} // namespace __cpo
55} // namespace ranges
56
57_LIBCPP_END_NAMESPACE_STD
58
59#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
60
61#endif // _LIBCPP___ALGORITHM_RANGES_MAX_ELEMENT_H
lib/libcxx/include/__algorithm/ranges_merge.h created+142
......@@ -0,0 +1,142 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_MERGE_H
10#define _LIBCPP___ALGORITHM_RANGES_MERGE_H
11
12#include <__algorithm/in_in_out_result.h>
13#include <__algorithm/ranges_copy.h>
14#include <__config>
15#include <__functional/identity.h>
16#include <__functional/invoke.h>
17#include <__functional/ranges_operations.h>
18#include <__iterator/concepts.h>
19#include <__iterator/mergeable.h>
20#include <__ranges/access.h>
21#include <__ranges/concepts.h>
22#include <__ranges/dangling.h>
23#include <__utility/move.h>
24#include <type_traits>
25
26#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
27# pragma GCC system_header
28#endif
29
30#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
31
32_LIBCPP_BEGIN_NAMESPACE_STD
33
34namespace ranges {
35
36template <class _InIter1, class _InIter2, class _OutIter>
37using merge_result = in_in_out_result<_InIter1, _InIter2, _OutIter>;
38
39namespace __merge {
40
41template <
42 class _InIter1,
43 class _Sent1,
44 class _InIter2,
45 class _Sent2,
46 class _OutIter,
47 class _Comp,
48 class _Proj1,
49 class _Proj2>
50_LIBCPP_HIDE_FROM_ABI constexpr merge_result<__uncvref_t<_InIter1>, __uncvref_t<_InIter2>, __uncvref_t<_OutIter>>
51__merge_impl(
52 _InIter1&& __first1,
53 _Sent1&& __last1,
54 _InIter2&& __first2,
55 _Sent2&& __last2,
56 _OutIter&& __result,
57 _Comp&& __comp,
58 _Proj1&& __proj1,
59 _Proj2&& __proj2) {
60 for (; __first1 != __last1 && __first2 != __last2; ++__result) {
61 if (std::invoke(__comp, std::invoke(__proj2, *__first2), std::invoke(__proj1, *__first1))) {
62 *__result = *__first2;
63 ++__first2;
64 } else {
65 *__result = *__first1;
66 ++__first1;
67 }
68 }
69 auto __ret1 = ranges::copy(std::move(__first1), std::move(__last1), std::move(__result));
70 auto __ret2 = ranges::copy(std::move(__first2), std::move(__last2), std::move(__ret1.out));
71 return {std::move(__ret1.in), std::move(__ret2.in), std::move(__ret2.out)};
72}
73
74struct __fn {
75 template <
76 input_iterator _InIter1,
77 sentinel_for<_InIter1> _Sent1,
78 input_iterator _InIter2,
79 sentinel_for<_InIter2> _Sent2,
80 weakly_incrementable _OutIter,
81 class _Comp = less,
82 class _Proj1 = identity,
83 class _Proj2 = identity>
84 requires mergeable<_InIter1, _InIter2, _OutIter, _Comp, _Proj1, _Proj2>
85 _LIBCPP_HIDE_FROM_ABI constexpr merge_result<_InIter1, _InIter2, _OutIter> operator()(
86 _InIter1 __first1,
87 _Sent1 __last1,
88 _InIter2 __first2,
89 _Sent2 __last2,
90 _OutIter __result,
91 _Comp __comp = {},
92 _Proj1 __proj1 = {},
93 _Proj2 __proj2 = {}) const {
94 return __merge::__merge_impl(__first1, __last1, __first2, __last2, __result, __comp, __proj1, __proj2);
95 }
96
97 template <
98 input_range _Range1,
99 input_range _Range2,
100 weakly_incrementable _OutIter,
101 class _Comp = less,
102 class _Proj1 = identity,
103 class _Proj2 = identity>
104 requires mergeable<
105 iterator_t<_Range1>,
106 iterator_t<_Range2>,
107 _OutIter,
108 _Comp,
109 _Proj1,
110 _Proj2>
111 _LIBCPP_HIDE_FROM_ABI constexpr merge_result<borrowed_iterator_t<_Range1>, borrowed_iterator_t<_Range2>, _OutIter>
112 operator()(
113 _Range1&& __range1,
114 _Range2&& __range2,
115 _OutIter __result,
116 _Comp __comp = {},
117 _Proj1 __proj1 = {},
118 _Proj2 __proj2 = {}) const {
119 return __merge::__merge_impl(
120 ranges::begin(__range1),
121 ranges::end(__range1),
122 ranges::begin(__range2),
123 ranges::end(__range2),
124 __result,
125 __comp,
126 __proj1,
127 __proj2);
128 }
129};
130
131} // namespace __merge
132
133inline namespace __cpo {
134 inline constexpr auto merge = __merge::__fn{};
135} // namespace __cpo
136} // namespace ranges
137
138_LIBCPP_END_NAMESPACE_STD
139
140#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
141
142#endif // _LIBCPP___ALGORITHM_RANGES_MERGE_H
lib/libcxx/include/__algorithm/ranges_min.h created+89
......@@ -0,0 +1,89 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_MIN_H
10#define _LIBCPP___ALGORITHM_RANGES_MIN_H
11
12#include <__algorithm/ranges_min_element.h>
13#include <__assert>
14#include <__concepts/copyable.h>
15#include <__config>
16#include <__functional/identity.h>
17#include <__functional/invoke.h>
18#include <__functional/ranges_operations.h>
19#include <__iterator/concepts.h>
20#include <__iterator/projected.h>
21#include <__ranges/access.h>
22#include <__ranges/concepts.h>
23#include <initializer_list>
24
25#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
26# pragma GCC system_header
27#endif
28
29#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
30
31_LIBCPP_PUSH_MACROS
32#include <__undef_macros>
33
34_LIBCPP_BEGIN_NAMESPACE_STD
35
36namespace ranges {
37namespace __min {
38struct __fn {
39 template <class _Tp, class _Proj = identity,
40 indirect_strict_weak_order<projected<const _Tp*, _Proj>> _Comp = ranges::less>
41 _LIBCPP_HIDE_FROM_ABI constexpr
42 const _Tp& operator()(const _Tp& __a, const _Tp& __b, _Comp __comp = {}, _Proj __proj = {}) const {
43 return std::invoke(__comp, std::invoke(__proj, __b), std::invoke(__proj, __a)) ? __b : __a;
44 }
45
46 template <copyable _Tp, class _Proj = identity,
47 indirect_strict_weak_order<projected<const _Tp*, _Proj>> _Comp = ranges::less>
48 _LIBCPP_HIDE_FROM_ABI constexpr
49 _Tp operator()(initializer_list<_Tp> __il, _Comp __comp = {}, _Proj __proj = {}) const {
50 _LIBCPP_ASSERT(__il.begin() != __il.end(), "initializer_list must contain at least one element");
51 return *ranges::__min_element_impl(__il.begin(), __il.end(), __comp, __proj);
52 }
53
54 template <input_range _Rp, class _Proj = identity,
55 indirect_strict_weak_order<projected<iterator_t<_Rp>, _Proj>> _Comp = ranges::less>
56 requires indirectly_copyable_storable<iterator_t<_Rp>, range_value_t<_Rp>*>
57 _LIBCPP_HIDE_FROM_ABI constexpr
58 range_value_t<_Rp> operator()(_Rp&& __r, _Comp __comp = {}, _Proj __proj = {}) const {
59 auto __first = ranges::begin(__r);
60 auto __last = ranges::end(__r);
61
62 _LIBCPP_ASSERT(__first != __last, "range must contain at least one element");
63
64 if constexpr (forward_range<_Rp>) {
65 return *ranges::__min_element_impl(__first, __last, __comp, __proj);
66 } else {
67 range_value_t<_Rp> __result = *__first;
68 while (++__first != __last) {
69 if (std::invoke(__comp, std::invoke(__proj, *__first), std::invoke(__proj, __result)))
70 __result = *__first;
71 }
72 return __result;
73 }
74 }
75};
76} // namespace __min
77
78inline namespace __cpo {
79 inline constexpr auto min = __min::__fn{};
80} // namespace __cpo
81} // namespace ranges
82
83_LIBCPP_END_NAMESPACE_STD
84
85_LIBCPP_POP_MACROS
86
87#endif // _LIBCPP_STD_VER > 17 && && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
88
89#endif // _LIBCPP___ALGORITHM_RANGES_MIN_H
lib/libcxx/include/__algorithm/ranges_min_element.h created+74
......@@ -0,0 +1,74 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_MIN_ELEMENT_H
10#define _LIBCPP___ALGORITHM_RANGES_MIN_ELEMENT_H
11
12#include <__config>
13#include <__functional/identity.h>
14#include <__functional/invoke.h>
15#include <__functional/ranges_operations.h>
16#include <__iterator/concepts.h>
17#include <__iterator/projected.h>
18#include <__ranges/access.h>
19#include <__ranges/concepts.h>
20#include <__ranges/dangling.h>
21#include <__utility/forward.h>
22
23#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
24# pragma GCC system_header
25#endif
26
27#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
28
29_LIBCPP_BEGIN_NAMESPACE_STD
30
31namespace ranges {
32
33// TODO(ranges): `ranges::min_element` can now simply delegate to `std::__min_element`.
34template <class _Ip, class _Sp, class _Proj, class _Comp>
35_LIBCPP_HIDE_FROM_ABI static constexpr
36_Ip __min_element_impl(_Ip __first, _Sp __last, _Comp& __comp, _Proj& __proj) {
37 if (__first == __last)
38 return __first;
39
40 _Ip __i = __first;
41 while (++__i != __last)
42 if (std::invoke(__comp, std::invoke(__proj, *__i), std::invoke(__proj, *__first)))
43 __first = __i;
44 return __first;
45}
46
47namespace __min_element {
48struct __fn {
49 template <forward_iterator _Ip, sentinel_for<_Ip> _Sp, class _Proj = identity,
50 indirect_strict_weak_order<projected<_Ip, _Proj>> _Comp = ranges::less>
51 _LIBCPP_HIDE_FROM_ABI constexpr
52 _Ip operator()(_Ip __first, _Sp __last, _Comp __comp = {}, _Proj __proj = {}) const {
53 return ranges::__min_element_impl(__first, __last, __comp, __proj);
54 }
55
56 template <forward_range _Rp, class _Proj = identity,
57 indirect_strict_weak_order<projected<iterator_t<_Rp>, _Proj>> _Comp = ranges::less>
58 _LIBCPP_HIDE_FROM_ABI constexpr
59 borrowed_iterator_t<_Rp> operator()(_Rp&& __r, _Comp __comp = {}, _Proj __proj = {}) const {
60 return ranges::__min_element_impl(ranges::begin(__r), ranges::end(__r), __comp, __proj);
61 }
62};
63} // namespace __min_element
64
65inline namespace __cpo {
66 inline constexpr auto min_element = __min_element::__fn{};
67} // namespace __cpo
68} // namespace ranges
69
70_LIBCPP_END_NAMESPACE_STD
71
72#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
73
74#endif // _LIBCPP___ALGORITHM_RANGES_MIN_ELEMENT_H
lib/libcxx/include/__algorithm/ranges_minmax.h created+133
......@@ -0,0 +1,133 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_MINMAX_H
10#define _LIBCPP___ALGORITHM_RANGES_MINMAX_H
11
12#include <__algorithm/min_max_result.h>
13#include <__algorithm/minmax_element.h>
14#include <__assert>
15#include <__concepts/copyable.h>
16#include <__config>
17#include <__functional/identity.h>
18#include <__functional/invoke.h>
19#include <__functional/ranges_operations.h>
20#include <__iterator/concepts.h>
21#include <__iterator/projected.h>
22#include <__ranges/access.h>
23#include <__ranges/concepts.h>
24#include <__utility/forward.h>
25#include <__utility/move.h>
26#include <initializer_list>
27
28#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
29# pragma GCC system_header
30#endif
31
32#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
33
34_LIBCPP_PUSH_MACROS
35#include <__undef_macros>
36
37_LIBCPP_BEGIN_NAMESPACE_STD
38
39namespace ranges {
40template <class _T1>
41using minmax_result = min_max_result<_T1>;
42
43namespace __minmax {
44struct __fn {
45 template <class _Type, class _Proj = identity,
46 indirect_strict_weak_order<projected<const _Type*, _Proj>> _Comp = ranges::less>
47 _LIBCPP_HIDE_FROM_ABI constexpr ranges::minmax_result<const _Type&>
48 operator()(const _Type& __a, const _Type& __b, _Comp __comp = {}, _Proj __proj = {}) const {
49 if (std::invoke(__comp, std::invoke(__proj, __b), std::invoke(__proj, __a)))
50 return {__b, __a};
51 return {__a, __b};
52 }
53
54 template <copyable _Type, class _Proj = identity,
55 indirect_strict_weak_order<projected<const _Type*, _Proj>> _Comp = ranges::less>
56 _LIBCPP_HIDE_FROM_ABI constexpr
57 ranges::minmax_result<_Type> operator()(initializer_list<_Type> __il, _Comp __comp = {}, _Proj __proj = {}) const {
58 _LIBCPP_ASSERT(__il.begin() != __il.end(), "initializer_list has to contain at least one element");
59 auto __iters = std::__minmax_element_impl(__il.begin(), __il.end(), __comp, __proj);
60 return ranges::minmax_result<_Type> { *__iters.first, *__iters.second };
61 }
62
63 template <input_range _Range, class _Proj = identity,
64 indirect_strict_weak_order<projected<iterator_t<_Range>, _Proj>> _Comp = ranges::less>
65 requires indirectly_copyable_storable<iterator_t<_Range>, range_value_t<_Range>*>
66 _LIBCPP_HIDE_FROM_ABI constexpr
67 ranges::minmax_result<range_value_t<_Range>> operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {}) const {
68 auto __first = ranges::begin(__r);
69 auto __last = ranges::end(__r);
70 using _ValueT = range_value_t<_Range>;
71
72 _LIBCPP_ASSERT(__first != __last, "range has to contain at least one element");
73
74 if constexpr (forward_range<_Range>) {
75 auto __result = std::__minmax_element_impl(__first, __last, __comp, __proj);
76 return {*__result.first, *__result.second};
77 } else {
78 // input_iterators can't be copied, so the implementation for input_iterators has to store
79 // the values instead of a pointer to the correct values
80 auto __less = [&](auto&& __a, auto&& __b) -> bool {
81 return std::invoke(__comp, std::invoke(__proj, std::forward<decltype(__a)>(__a)),
82 std::invoke(__proj, std::forward<decltype(__b)>(__b)));
83 };
84
85 ranges::minmax_result<_ValueT> __result = {*__first, __result.min};
86 if (__first == __last || ++__first == __last)
87 return __result;
88
89 if (__less(*__first, __result.min))
90 __result.min = *__first;
91 else
92 __result.max = *__first;
93
94 while (++__first != __last) {
95 _ValueT __i = *__first;
96 if (++__first == __last) {
97 if (__less(__i, __result.min))
98 __result.min = __i;
99 else if (!__less(__i, __result.max))
100 __result.max = __i;
101 return __result;
102 }
103
104 if (__less(*__first, __i)) {
105 if (__less(*__first, __result.min))
106 __result.min = *__first;
107 if (!__less(__i, __result.max))
108 __result.max = std::move(__i);
109 } else {
110 if (__less(__i, __result.min))
111 __result.min = std::move(__i);
112 if (!__less(*__first, __result.max))
113 __result.max = *__first;
114 }
115 }
116 return __result;
117 }
118 }
119};
120} // namespace __minmax
121
122inline namespace __cpo {
123 inline constexpr auto minmax = __minmax::__fn{};
124} // namespace __cpo
125} // namespace ranges
126
127_LIBCPP_END_NAMESPACE_STD
128
129_LIBCPP_POP_MACROS
130
131#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
132
133#endif // _LIBCPP___ALGORITHM_RANGES_MINMAX_H
lib/libcxx/include/__algorithm/ranges_minmax_element.h created+72
......@@ -0,0 +1,72 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_MINMAX_ELEMENT_H
10#define _LIBCPP___ALGORITHM_RANGES_MINMAX_ELEMENT_H
11
12#include <__algorithm/min_max_result.h>
13#include <__algorithm/minmax_element.h>
14#include <__config>
15#include <__functional/identity.h>
16#include <__functional/invoke.h>
17#include <__functional/ranges_operations.h>
18#include <__iterator/concepts.h>
19#include <__iterator/projected.h>
20#include <__ranges/access.h>
21#include <__ranges/concepts.h>
22#include <__ranges/dangling.h>
23#include <__utility/forward.h>
24#include <__utility/move.h>
25#include <__utility/pair.h>
26#include <type_traits>
27
28#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
29# pragma GCC system_header
30#endif
31
32#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
33
34_LIBCPP_BEGIN_NAMESPACE_STD
35
36namespace ranges {
37
38template <class _T1>
39using minmax_element_result = min_max_result<_T1>;
40
41namespace __minmax_element {
42struct __fn {
43 template <forward_iterator _Ip, sentinel_for<_Ip> _Sp, class _Proj = identity,
44 indirect_strict_weak_order<projected<_Ip, _Proj>> _Comp = ranges::less>
45 _LIBCPP_HIDE_FROM_ABI constexpr
46 ranges::minmax_element_result<_Ip> operator()(_Ip __first, _Sp __last, _Comp __comp = {}, _Proj __proj = {}) const {
47 auto __ret = std::__minmax_element_impl(std::move(__first), std::move(__last), __comp, __proj);
48 return {__ret.first, __ret.second};
49 }
50
51 template <forward_range _Rp, class _Proj = identity,
52 indirect_strict_weak_order<projected<iterator_t<_Rp>, _Proj>> _Comp = ranges::less>
53 _LIBCPP_HIDE_FROM_ABI constexpr
54 ranges::minmax_element_result<borrowed_iterator_t<_Rp>>
55 operator()(_Rp&& __r, _Comp __comp = {}, _Proj __proj = {}) const {
56 auto __ret = std::__minmax_element_impl(ranges::begin(__r), ranges::end(__r), __comp, __proj);
57 return {__ret.first, __ret.second};
58 }
59};
60} // namespace __minmax_element
61
62inline namespace __cpo {
63 inline constexpr auto minmax_element = __minmax_element::__fn{};
64} // namespace __cpo
65
66} // namespace ranges
67
68_LIBCPP_END_NAMESPACE_STD
69
70#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
71
72#endif // _LIBCPP___ALGORITHM_RANGES_MINMAX_H
lib/libcxx/include/__algorithm/ranges_mismatch.h created+85
......@@ -0,0 +1,85 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_MISMATCH_H
10#define _LIBCPP___ALGORITHM_RANGES_MISMATCH_H
11
12#include <__algorithm/in_in_result.h>
13#include <__config>
14#include <__functional/identity.h>
15#include <__functional/invoke.h>
16#include <__functional/ranges_operations.h>
17#include <__iterator/concepts.h>
18#include <__iterator/indirectly_comparable.h>
19#include <__ranges/access.h>
20#include <__ranges/concepts.h>
21#include <__ranges/dangling.h>
22#include <__utility/move.h>
23
24#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
25# pragma GCC system_header
26#endif
27
28_LIBCPP_BEGIN_NAMESPACE_STD
29
30#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
31
32namespace ranges {
33
34template <class _I1, class _I2>
35using mismatch_result = in_in_result<_I1, _I2>;
36
37namespace __mismatch {
38struct __fn {
39 template <class _I1, class _S1, class _I2, class _S2,
40 class _Pred, class _Proj1, class _Proj2>
41 static _LIBCPP_HIDE_FROM_ABI constexpr
42 mismatch_result<_I1, _I2>
43 __go(_I1 __first1, _S1 __last1, _I2 __first2, _S2 __last2,
44 _Pred& __pred, _Proj1& __proj1, _Proj2& __proj2) {
45 while (__first1 != __last1 && __first2 != __last2) {
46 if (!std::invoke(__pred, std::invoke(__proj1, *__first1), std::invoke(__proj2, *__first2)))
47 break;
48 ++__first1;
49 ++__first2;
50 }
51 return {std::move(__first1), std::move(__first2)};
52 }
53
54 template <input_iterator _I1, sentinel_for<_I1> _S1,
55 input_iterator _I2, sentinel_for<_I2> _S2,
56 class _Pred = ranges::equal_to, class _Proj1 = identity, class _Proj2 = identity>
57 requires indirectly_comparable<_I1, _I2, _Pred, _Proj1, _Proj2>
58 _LIBCPP_HIDE_FROM_ABI constexpr
59 mismatch_result<_I1, _I2> operator()(_I1 __first1, _S1 __last1, _I2 __first2, _S2 __last2,
60 _Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const {
61 return __go(std::move(__first1), __last1, std::move(__first2), __last2, __pred, __proj1, __proj2);
62 }
63
64 template <input_range _R1, input_range _R2,
65 class _Pred = ranges::equal_to, class _Proj1 = identity, class _Proj2 = identity>
66 requires indirectly_comparable<iterator_t<_R1>, iterator_t<_R2>, _Pred, _Proj1, _Proj2>
67 _LIBCPP_HIDE_FROM_ABI constexpr
68 mismatch_result<borrowed_iterator_t<_R1>, borrowed_iterator_t<_R2>>
69 operator()(_R1&& __r1, _R2&& __r2, _Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const {
70 return __go(ranges::begin(__r1), ranges::end(__r1), ranges::begin(__r2), ranges::end(__r2),
71 __pred, __proj1, __proj2);
72 }
73};
74} // namespace __mismatch
75
76inline namespace __cpo {
77 constexpr inline auto mismatch = __mismatch::__fn{};
78} // namespace __cpo
79} // namespace ranges
80
81#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
82
83_LIBCPP_END_NAMESPACE_STD
84
85#endif // _LIBCPP___ALGORITHM_RANGES_MISMATCH_H
lib/libcxx/include/__algorithm/ranges_move.h created+83
......@@ -0,0 +1,83 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_MOVE_H
10#define _LIBCPP___ALGORITHM_RANGES_MOVE_H
11
12#include <__algorithm/in_out_result.h>
13#include <__algorithm/move.h>
14#include <__config>
15#include <__iterator/concepts.h>
16#include <__iterator/iter_move.h>
17#include <__ranges/access.h>
18#include <__ranges/concepts.h>
19#include <__ranges/dangling.h>
20#include <__utility/move.h>
21
22#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23# pragma GCC system_header
24#endif
25
26#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
27
28_LIBCPP_BEGIN_NAMESPACE_STD
29
30namespace ranges {
31
32template <class _InIter, class _OutIter>
33using move_result = in_out_result<_InIter, _OutIter>;
34
35namespace __move {
36struct __fn {
37
38 template <class _InIter, class _Sent, class _OutIter>
39 requires __iter_move::__move_deref<_InIter> // check that we are allowed to std::move() the value
40 _LIBCPP_HIDE_FROM_ABI constexpr static
41 move_result<_InIter, _OutIter> __move_impl(_InIter __first, _Sent __last, _OutIter __result) {
42 auto __ret = std::__move(std::move(__first), std::move(__last), std::move(__result));
43 return {std::move(__ret.first), std::move(__ret.second)};
44 }
45
46 template <class _InIter, class _Sent, class _OutIter>
47 _LIBCPP_HIDE_FROM_ABI constexpr static
48 move_result<_InIter, _OutIter> __move_impl(_InIter __first, _Sent __last, _OutIter __result) {
49 while (__first != __last) {
50 *__result = ranges::iter_move(__first);
51 ++__first;
52 ++__result;
53 }
54 return {std::move(__first), std::move(__result)};
55 }
56
57 template <input_iterator _InIter, sentinel_for<_InIter> _Sent, weakly_incrementable _OutIter>
58 requires indirectly_movable<_InIter, _OutIter>
59 _LIBCPP_HIDE_FROM_ABI constexpr
60 move_result<_InIter, _OutIter> operator()(_InIter __first, _Sent __last, _OutIter __result) const {
61 return __move_impl(std::move(__first), std::move(__last), std::move(__result));
62 }
63
64 template <input_range _Range, weakly_incrementable _OutIter>
65 requires indirectly_movable<iterator_t<_Range>, _OutIter>
66 _LIBCPP_HIDE_FROM_ABI constexpr
67 move_result<borrowed_iterator_t<_Range>, _OutIter> operator()(_Range&& __range, _OutIter __result) const {
68 return __move_impl(ranges::begin(__range), ranges::end(__range), std::move(__result));
69 }
70
71};
72} // namespace __move
73
74inline namespace __cpo {
75 inline constexpr auto move = __move::__fn{};
76} // namespace __cpo
77} // namespace ranges
78
79_LIBCPP_END_NAMESPACE_STD
80
81#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
82
83#endif // _LIBCPP___ALGORITHM_RANGES_MOVE_H
lib/libcxx/include/__algorithm/ranges_move_backward.h created+75
......@@ -0,0 +1,75 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_MOVE_BACKWARD_H
10#define _LIBCPP___ALGORITHM_RANGES_MOVE_BACKWARD_H
11
12#include <__algorithm/in_out_result.h>
13#include <__algorithm/ranges_move.h>
14#include <__config>
15#include <__iterator/concepts.h>
16#include <__iterator/iter_move.h>
17#include <__iterator/next.h>
18#include <__iterator/reverse_iterator.h>
19#include <__ranges/access.h>
20#include <__ranges/concepts.h>
21#include <__ranges/dangling.h>
22#include <__utility/move.h>
23
24#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
25# pragma GCC system_header
26#endif
27
28#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
29
30_LIBCPP_BEGIN_NAMESPACE_STD
31
32namespace ranges {
33
34template <class _InIter, class _OutIter>
35using move_backward_result = in_out_result<_InIter, _OutIter>;
36
37namespace __move_backward {
38struct __fn {
39
40 template <class _InIter, class _Sent, class _OutIter>
41 _LIBCPP_HIDE_FROM_ABI constexpr static
42 move_backward_result<_InIter, _OutIter> __move_backward_impl(_InIter __first, _Sent __last, _OutIter __result) {
43 auto __ret = ranges::move(std::make_reverse_iterator(ranges::next(__first, __last)),
44 std::make_reverse_iterator(__first),
45 std::make_reverse_iterator(__result));
46 return {std::move(__ret.in.base()), std::move(__ret.out.base())};
47 }
48
49 template <bidirectional_iterator _InIter, sentinel_for<_InIter> _Sent, bidirectional_iterator _OutIter>
50 requires indirectly_movable<_InIter, _OutIter>
51 _LIBCPP_HIDE_FROM_ABI constexpr
52 move_backward_result<_InIter, _OutIter> operator()(_InIter __first, _Sent __last, _OutIter __result) const {
53 return __move_backward_impl(std::move(__first), std::move(__last), std::move(__result));
54 }
55
56 template <bidirectional_range _Range, bidirectional_iterator _Iter>
57 requires indirectly_movable<iterator_t<_Range>, _Iter>
58 _LIBCPP_HIDE_FROM_ABI constexpr
59 move_backward_result<borrowed_iterator_t<_Range>, _Iter> operator()(_Range&& __range, _Iter __result) const {
60 return __move_backward_impl(ranges::begin(__range), ranges::end(__range), std::move(__result));
61 }
62
63};
64} // namespace __move_backward
65
66inline namespace __cpo {
67 inline constexpr auto move_backward = __move_backward::__fn{};
68} // namespace __cpo
69} // namespace ranges
70
71_LIBCPP_END_NAMESPACE_STD
72
73#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
74
75#endif // _LIBCPP___ALGORITHM_RANGES_MOVE_BACKWARD_H
lib/libcxx/include/__algorithm/ranges_none_of.h created+68
......@@ -0,0 +1,68 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_NONE_OF_H
10#define _LIBCPP___ALGORITHM_RANGES_NONE_OF_H
11
12#include <__config>
13#include <__functional/identity.h>
14#include <__functional/invoke.h>
15#include <__iterator/concepts.h>
16#include <__iterator/projected.h>
17#include <__ranges/access.h>
18#include <__ranges/concepts.h>
19#include <__utility/move.h>
20
21#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22# pragma GCC system_header
23#endif
24
25#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
26
27_LIBCPP_BEGIN_NAMESPACE_STD
28
29namespace ranges {
30namespace __none_of {
31struct __fn {
32
33 template <class _Iter, class _Sent, class _Proj, class _Pred>
34 _LIBCPP_HIDE_FROM_ABI constexpr static
35 bool __none_of_impl(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
36 for (; __first != __last; ++__first) {
37 if (std::invoke(__pred, std::invoke(__proj, *__first)))
38 return false;
39 }
40 return true;
41 }
42
43 template <input_iterator _Iter, sentinel_for<_Iter> _Sent, class _Proj = identity,
44 indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
45 _LIBCPP_HIDE_FROM_ABI constexpr
46 bool operator()(_Iter __first, _Sent __last, _Pred __pred = {}, _Proj __proj = {}) const {
47 return __none_of_impl(std::move(__first), std::move(__last), __pred, __proj);
48 }
49
50 template <input_range _Range, class _Proj = identity,
51 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>> _Pred>
52 _LIBCPP_HIDE_FROM_ABI constexpr
53 bool operator()(_Range&& __range, _Pred __pred, _Proj __proj = {}) const {
54 return __none_of_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj);
55 }
56};
57} // namespace __none_of
58
59inline namespace __cpo {
60 inline constexpr auto none_of = __none_of::__fn{};
61} // namespace __cpo
62} // namespace ranges
63
64_LIBCPP_END_NAMESPACE_STD
65
66#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
67
68#endif // _LIBCPP___ALGORITHM_RANGES_NONE_OF_H
lib/libcxx/include/__algorithm/ranges_nth_element.h created+80
......@@ -0,0 +1,80 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_NTH_ELEMENT_H
10#define _LIBCPP___ALGORITHM_RANGES_NTH_ELEMENT_H
11
12#include <__algorithm/iterator_operations.h>
13#include <__algorithm/make_projected.h>
14#include <__algorithm/nth_element.h>
15#include <__config>
16#include <__functional/identity.h>
17#include <__functional/invoke.h>
18#include <__functional/ranges_operations.h>
19#include <__iterator/concepts.h>
20#include <__iterator/iterator_traits.h>
21#include <__iterator/next.h>
22#include <__iterator/projected.h>
23#include <__iterator/sortable.h>
24#include <__ranges/access.h>
25#include <__ranges/concepts.h>
26#include <__ranges/dangling.h>
27#include <__utility/forward.h>
28#include <__utility/move.h>
29
30#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
31# pragma GCC system_header
32#endif
33
34#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
35
36_LIBCPP_BEGIN_NAMESPACE_STD
37
38namespace ranges {
39namespace __nth_element {
40
41struct __fn {
42 template <class _Iter, class _Sent, class _Comp, class _Proj>
43 _LIBCPP_HIDE_FROM_ABI constexpr static
44 _Iter __nth_element_fn_impl(_Iter __first, _Iter __nth, _Sent __last, _Comp& __comp, _Proj& __proj) {
45 auto __last_iter = ranges::next(__first, __last);
46
47 auto&& __projected_comp = std::__make_projected(__comp, __proj);
48 std::__nth_element_impl<_RangeAlgPolicy>(std::move(__first), std::move(__nth), __last_iter, __projected_comp);
49
50 return __last_iter;
51 }
52
53 template <random_access_iterator _Iter, sentinel_for<_Iter> _Sent, class _Comp = ranges::less, class _Proj = identity>
54 requires sortable<_Iter, _Comp, _Proj>
55 _LIBCPP_HIDE_FROM_ABI constexpr
56 _Iter operator()(_Iter __first, _Iter __nth, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const {
57 return __nth_element_fn_impl(std::move(__first), std::move(__nth), std::move(__last), __comp, __proj);
58 }
59
60 template <random_access_range _Range, class _Comp = ranges::less, class _Proj = identity>
61 requires sortable<iterator_t<_Range>, _Comp, _Proj>
62 _LIBCPP_HIDE_FROM_ABI constexpr
63 borrowed_iterator_t<_Range> operator()(_Range&& __r, iterator_t<_Range> __nth, _Comp __comp = {},
64 _Proj __proj = {}) const {
65 return __nth_element_fn_impl(ranges::begin(__r), std::move(__nth), ranges::end(__r), __comp, __proj);
66 }
67};
68
69} // namespace __nth_element
70
71inline namespace __cpo {
72 inline constexpr auto nth_element = __nth_element::__fn{};
73} // namespace __cpo
74} // namespace ranges
75
76_LIBCPP_END_NAMESPACE_STD
77
78#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
79
80#endif // _LIBCPP___ALGORITHM_RANGES_NTH_ELEMENT_H
lib/libcxx/include/__algorithm/ranges_partial_sort.h created+77
......@@ -0,0 +1,77 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_PARTIAL_SORT_H
10#define _LIBCPP___ALGORITHM_RANGES_PARTIAL_SORT_H
11
12#include <__algorithm/iterator_operations.h>
13#include <__algorithm/make_projected.h>
14#include <__algorithm/partial_sort.h>
15#include <__concepts/same_as.h>
16#include <__config>
17#include <__functional/identity.h>
18#include <__functional/invoke.h>
19#include <__functional/ranges_operations.h>
20#include <__iterator/concepts.h>
21#include <__iterator/iterator_traits.h>
22#include <__iterator/next.h>
23#include <__iterator/projected.h>
24#include <__iterator/sortable.h>
25#include <__ranges/access.h>
26#include <__ranges/concepts.h>
27#include <__ranges/dangling.h>
28#include <__utility/forward.h>
29#include <__utility/move.h>
30
31#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
32# pragma GCC system_header
33#endif
34
35#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
36
37_LIBCPP_BEGIN_NAMESPACE_STD
38
39namespace ranges {
40namespace __partial_sort {
41
42struct __fn {
43 template <class _Iter, class _Sent, class _Comp, class _Proj>
44 _LIBCPP_HIDE_FROM_ABI constexpr static
45 _Iter __partial_sort_fn_impl(_Iter __first, _Iter __middle, _Sent __last, _Comp& __comp, _Proj& __proj) {
46 auto&& __projected_comp = std::__make_projected(__comp, __proj);
47 return std::__partial_sort<_RangeAlgPolicy>(std::move(__first), std::move(__middle), __last, __projected_comp);
48 }
49
50 template <random_access_iterator _Iter, sentinel_for<_Iter> _Sent, class _Comp = ranges::less, class _Proj = identity>
51 requires sortable<_Iter, _Comp, _Proj>
52 _LIBCPP_HIDE_FROM_ABI constexpr
53 _Iter operator()(_Iter __first, _Iter __middle, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const {
54 return __partial_sort_fn_impl(std::move(__first), std::move(__middle), std::move(__last), __comp, __proj);
55 }
56
57 template <random_access_range _Range, class _Comp = ranges::less, class _Proj = identity>
58 requires sortable<iterator_t<_Range>, _Comp, _Proj>
59 _LIBCPP_HIDE_FROM_ABI constexpr
60 borrowed_iterator_t<_Range> operator()(_Range&& __r, iterator_t<_Range> __middle, _Comp __comp = {},
61 _Proj __proj = {}) const {
62 return __partial_sort_fn_impl(ranges::begin(__r), std::move(__middle), ranges::end(__r), __comp, __proj);
63 }
64};
65
66} // namespace __partial_sort
67
68inline namespace __cpo {
69 inline constexpr auto partial_sort = __partial_sort::__fn{};
70} // namespace __cpo
71} // namespace ranges
72
73_LIBCPP_END_NAMESPACE_STD
74
75#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
76
77#endif // _LIBCPP___ALGORITHM_RANGES_PARTIAL_SORT_H
lib/libcxx/include/__algorithm/ranges_partial_sort_copy.h created+91
......@@ -0,0 +1,91 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_PARTIAL_SORT_COPY_H
10#define _LIBCPP___ALGORITHM_RANGES_PARTIAL_SORT_COPY_H
11
12#include <__algorithm/in_out_result.h>
13#include <__algorithm/iterator_operations.h>
14#include <__algorithm/make_projected.h>
15#include <__algorithm/partial_sort_copy.h>
16#include <__config>
17#include <__functional/identity.h>
18#include <__functional/ranges_operations.h>
19#include <__iterator/concepts.h>
20#include <__iterator/iterator_traits.h>
21#include <__iterator/projected.h>
22#include <__iterator/sortable.h>
23#include <__ranges/access.h>
24#include <__ranges/concepts.h>
25#include <__ranges/dangling.h>
26#include <__utility/move.h>
27
28#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
29# pragma GCC system_header
30#endif
31
32#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
33
34_LIBCPP_BEGIN_NAMESPACE_STD
35
36namespace ranges {
37
38template <class _InIter, class _OutIter>
39using partial_sort_copy_result = in_out_result<_InIter, _OutIter>;
40
41namespace __partial_sort_copy {
42
43struct __fn {
44
45 template <input_iterator _Iter1, sentinel_for<_Iter1> _Sent1,
46 random_access_iterator _Iter2, sentinel_for<_Iter2> _Sent2,
47 class _Comp = ranges::less, class _Proj1 = identity, class _Proj2 = identity>
48 requires indirectly_copyable<_Iter1, _Iter2> && sortable<_Iter2, _Comp, _Proj2> &&
49 indirect_strict_weak_order<_Comp, projected<_Iter1, _Proj1>, projected<_Iter2, _Proj2>>
50 _LIBCPP_HIDE_FROM_ABI constexpr
51 partial_sort_copy_result<_Iter1, _Iter2>
52 operator()(_Iter1 __first, _Sent1 __last, _Iter2 __result_first, _Sent2 __result_last,
53 _Comp __comp = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const {
54 auto __result = std::__partial_sort_copy<_RangeAlgPolicy>(
55 std::move(__first), std::move(__last), std::move(__result_first), std::move(__result_last),
56 __comp, __proj1, __proj2
57 );
58 return {std::move(__result.first), std::move(__result.second)};
59 }
60
61 template <input_range _Range1, random_access_range _Range2, class _Comp = ranges::less,
62 class _Proj1 = identity, class _Proj2 = identity>
63 requires indirectly_copyable<iterator_t<_Range1>, iterator_t<_Range2>> &&
64 sortable<iterator_t<_Range2>, _Comp, _Proj2> &&
65 indirect_strict_weak_order<_Comp, projected<iterator_t<_Range1>, _Proj1>,
66 projected<iterator_t<_Range2>, _Proj2>>
67 _LIBCPP_HIDE_FROM_ABI constexpr
68 partial_sort_copy_result<borrowed_iterator_t<_Range1>, borrowed_iterator_t<_Range2>>
69 operator()(_Range1&& __range, _Range2&& __result_range, _Comp __comp = {},
70 _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const {
71 auto __result = std::__partial_sort_copy<_RangeAlgPolicy>(
72 ranges::begin(__range), ranges::end(__range), ranges::begin(__result_range), ranges::end(__result_range),
73 __comp, __proj1, __proj2
74 );
75 return {std::move(__result.first), std::move(__result.second)};
76 }
77
78};
79
80} // namespace __partial_sort_copy
81
82inline namespace __cpo {
83 inline constexpr auto partial_sort_copy = __partial_sort_copy::__fn{};
84} // namespace __cpo
85} // namespace ranges
86
87_LIBCPP_END_NAMESPACE_STD
88
89#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
90
91#endif // _LIBCPP___ALGORITHM_RANGES_PARTIAL_SORT_COPY_H
lib/libcxx/include/__algorithm/ranges_partition.h created+82
......@@ -0,0 +1,82 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_PARTITION_H
10#define _LIBCPP___ALGORITHM_RANGES_PARTITION_H
11
12#include <__algorithm/iterator_operations.h>
13#include <__algorithm/make_projected.h>
14#include <__algorithm/partition.h>
15#include <__algorithm/ranges_iterator_concept.h>
16#include <__config>
17#include <__functional/identity.h>
18#include <__functional/invoke.h>
19#include <__functional/ranges_operations.h>
20#include <__iterator/concepts.h>
21#include <__iterator/iterator_traits.h>
22#include <__iterator/permutable.h>
23#include <__iterator/projected.h>
24#include <__ranges/access.h>
25#include <__ranges/concepts.h>
26#include <__ranges/subrange.h>
27#include <__utility/forward.h>
28#include <__utility/move.h>
29#include <type_traits>
30
31#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
32# pragma GCC system_header
33#endif
34
35#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
36
37_LIBCPP_BEGIN_NAMESPACE_STD
38
39namespace ranges {
40namespace __partition {
41
42struct __fn {
43
44 template <class _Iter, class _Sent, class _Proj, class _Pred>
45 _LIBCPP_HIDE_FROM_ABI static constexpr
46 subrange<__uncvref_t<_Iter>> __partition_fn_impl(_Iter&& __first, _Sent&& __last, _Pred&& __pred, _Proj&& __proj) {
47 auto&& __projected_pred = std::__make_projected(__pred, __proj);
48 auto __result = std::__partition<_RangeAlgPolicy>(
49 std::move(__first), std::move(__last), __projected_pred, __iterator_concept<_Iter>());
50
51 return {std::move(__result.first), std::move(__result.second)};
52 }
53
54 template <permutable _Iter, sentinel_for<_Iter> _Sent, class _Proj = identity,
55 indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
56 _LIBCPP_HIDE_FROM_ABI constexpr
57 subrange<_Iter> operator()(_Iter __first, _Sent __last, _Pred __pred, _Proj __proj = {}) const {
58 return __partition_fn_impl(__first, __last, __pred, __proj);
59 }
60
61 template <forward_range _Range, class _Proj = identity,
62 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>> _Pred>
63 requires permutable<iterator_t<_Range>>
64 _LIBCPP_HIDE_FROM_ABI constexpr
65 borrowed_subrange_t<_Range> operator()(_Range&& __range, _Pred __pred, _Proj __proj = {}) const {
66 return __partition_fn_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj);
67 }
68
69};
70
71} // namespace __partition
72
73inline namespace __cpo {
74 inline constexpr auto partition = __partition::__fn{};
75} // namespace __cpo
76} // namespace ranges
77
78_LIBCPP_END_NAMESPACE_STD
79
80#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
81
82#endif // _LIBCPP___ALGORITHM_RANGES_PARTITION_H
lib/libcxx/include/__algorithm/ranges_partition_copy.h created+98
......@@ -0,0 +1,98 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_PARTITION_COPY_H
10#define _LIBCPP___ALGORITHM_RANGES_PARTITION_COPY_H
11
12#include <__algorithm/in_out_out_result.h>
13#include <__config>
14#include <__functional/identity.h>
15#include <__functional/invoke.h>
16#include <__iterator/concepts.h>
17#include <__iterator/iterator_traits.h>
18#include <__iterator/projected.h>
19#include <__ranges/access.h>
20#include <__ranges/concepts.h>
21#include <__ranges/dangling.h>
22#include <__utility/move.h>
23#include <type_traits>
24
25#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
26# pragma GCC system_header
27#endif
28
29#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
30
31_LIBCPP_BEGIN_NAMESPACE_STD
32
33namespace ranges {
34
35template <class _InIter, class _OutIter1, class _OutIter2>
36using partition_copy_result = in_out_out_result<_InIter, _OutIter1, _OutIter2>;
37
38namespace __partition_copy {
39
40struct __fn {
41
42 // TODO(ranges): delegate to the classic algorithm.
43 template <class _InIter, class _Sent, class _OutIter1, class _OutIter2, class _Proj, class _Pred>
44 _LIBCPP_HIDE_FROM_ABI constexpr
45 static partition_copy_result<
46 __uncvref_t<_InIter>, __uncvref_t<_OutIter1>, __uncvref_t<_OutIter2>
47 > __partition_copy_fn_impl( _InIter&& __first, _Sent&& __last, _OutIter1&& __out_true, _OutIter2&& __out_false,
48 _Pred& __pred, _Proj& __proj) {
49 for (; __first != __last; ++__first) {
50 if (std::invoke(__pred, std::invoke(__proj, *__first))) {
51 *__out_true = *__first;
52 ++__out_true;
53
54 } else {
55 *__out_false = *__first;
56 ++__out_false;
57 }
58 }
59
60 return {std::move(__first), std::move(__out_true), std::move(__out_false)};
61 }
62
63 template <input_iterator _InIter, sentinel_for<_InIter> _Sent,
64 weakly_incrementable _OutIter1, weakly_incrementable _OutIter2,
65 class _Proj = identity, indirect_unary_predicate<projected<_InIter, _Proj>> _Pred>
66 requires indirectly_copyable<_InIter, _OutIter1> && indirectly_copyable<_InIter, _OutIter2>
67 _LIBCPP_HIDE_FROM_ABI constexpr
68 partition_copy_result<_InIter, _OutIter1, _OutIter2>
69 operator()(_InIter __first, _Sent __last, _OutIter1 __out_true, _OutIter2 __out_false,
70 _Pred __pred, _Proj __proj = {}) const {
71 return __partition_copy_fn_impl(
72 std::move(__first), std::move(__last), std::move(__out_true), std::move(__out_false), __pred, __proj);
73 }
74
75 template <input_range _Range, weakly_incrementable _OutIter1, weakly_incrementable _OutIter2,
76 class _Proj = identity, indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>> _Pred>
77 requires indirectly_copyable<iterator_t<_Range>, _OutIter1> && indirectly_copyable<iterator_t<_Range>, _OutIter2>
78 _LIBCPP_HIDE_FROM_ABI constexpr
79 partition_copy_result<borrowed_iterator_t<_Range>, _OutIter1, _OutIter2>
80 operator()(_Range&& __range, _OutIter1 __out_true, _OutIter2 __out_false, _Pred __pred, _Proj __proj = {}) const {
81 return __partition_copy_fn_impl(
82 ranges::begin(__range), ranges::end(__range), std::move(__out_true), std::move(__out_false), __pred, __proj);
83 }
84
85};
86
87} // namespace __partition_copy
88
89inline namespace __cpo {
90 inline constexpr auto partition_copy = __partition_copy::__fn{};
91} // namespace __cpo
92} // namespace ranges
93
94_LIBCPP_END_NAMESPACE_STD
95
96#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
97
98#endif // _LIBCPP___ALGORITHM_RANGES_PARTITION_COPY_H
lib/libcxx/include/__algorithm/ranges_partition_point.h created+88
......@@ -0,0 +1,88 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_PARTITION_POINT_H
10#define _LIBCPP___ALGORITHM_RANGES_PARTITION_POINT_H
11
12#include <__algorithm/half_positive.h>
13#include <__config>
14#include <__functional/identity.h>
15#include <__functional/invoke.h>
16#include <__iterator/concepts.h>
17#include <__iterator/distance.h>
18#include <__iterator/iterator_traits.h>
19#include <__iterator/next.h>
20#include <__iterator/projected.h>
21#include <__ranges/access.h>
22#include <__ranges/concepts.h>
23#include <__ranges/dangling.h>
24#include <__utility/move.h>
25
26#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
27# pragma GCC system_header
28#endif
29
30#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
31
32_LIBCPP_BEGIN_NAMESPACE_STD
33
34namespace ranges {
35namespace __partition_point {
36
37struct __fn {
38
39 // TODO(ranges): delegate to the classic algorithm.
40 template <class _Iter, class _Sent, class _Proj, class _Pred>
41 _LIBCPP_HIDE_FROM_ABI constexpr
42 static _Iter __partition_point_fn_impl(_Iter&& __first, _Sent&& __last, _Pred& __pred, _Proj& __proj) {
43 auto __len = ranges::distance(__first, __last);
44
45 while (__len != 0) {
46 auto __half_len = std::__half_positive(__len);
47 auto __mid = ranges::next(__first, __half_len);
48
49 if (std::invoke(__pred, std::invoke(__proj, *__mid))) {
50 __first = ++__mid;
51 __len -= __half_len + 1;
52
53 } else {
54 __len = __half_len;
55 }
56 }
57
58 return __first;
59 }
60
61 template <forward_iterator _Iter, sentinel_for<_Iter> _Sent, class _Proj = identity,
62 indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
63 _LIBCPP_HIDE_FROM_ABI constexpr
64 _Iter operator()(_Iter __first, _Sent __last, _Pred __pred, _Proj __proj = {}) const {
65 return __partition_point_fn_impl(std::move(__first), std::move(__last), __pred, __proj);
66 }
67
68 template <forward_range _Range, class _Proj = identity,
69 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>> _Pred>
70 _LIBCPP_HIDE_FROM_ABI constexpr
71 borrowed_iterator_t<_Range> operator()(_Range&& __range, _Pred __pred, _Proj __proj = {}) const {
72 return __partition_point_fn_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj);
73 }
74
75};
76
77} // namespace __partition_point
78
79inline namespace __cpo {
80 inline constexpr auto partition_point = __partition_point::__fn{};
81} // namespace __cpo
82} // namespace ranges
83
84_LIBCPP_END_NAMESPACE_STD
85
86#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
87
88#endif // _LIBCPP___ALGORITHM_RANGES_PARTITION_POINT_H
lib/libcxx/include/__algorithm/ranges_pop_heap.h created+81
......@@ -0,0 +1,81 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_POP_HEAP_H
10#define _LIBCPP___ALGORITHM_RANGES_POP_HEAP_H
11
12#include <__algorithm/iterator_operations.h>
13#include <__algorithm/make_projected.h>
14#include <__algorithm/pop_heap.h>
15#include <__concepts/same_as.h>
16#include <__config>
17#include <__functional/identity.h>
18#include <__functional/invoke.h>
19#include <__functional/ranges_operations.h>
20#include <__iterator/concepts.h>
21#include <__iterator/iterator_traits.h>
22#include <__iterator/next.h>
23#include <__iterator/projected.h>
24#include <__iterator/sortable.h>
25#include <__ranges/access.h>
26#include <__ranges/concepts.h>
27#include <__ranges/dangling.h>
28#include <__utility/forward.h>
29#include <__utility/move.h>
30
31#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
32# pragma GCC system_header
33#endif
34
35#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
36
37_LIBCPP_BEGIN_NAMESPACE_STD
38
39namespace ranges {
40namespace __pop_heap {
41
42struct __fn {
43 template <class _Iter, class _Sent, class _Comp, class _Proj>
44 _LIBCPP_HIDE_FROM_ABI constexpr static
45 _Iter __pop_heap_fn_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) {
46 auto __last_iter = ranges::next(__first, __last);
47 auto __len = __last_iter - __first;
48
49 auto&& __projected_comp = std::__make_projected(__comp, __proj);
50 std::__pop_heap<_RangeAlgPolicy>(std::move(__first), __last_iter, __projected_comp, __len);
51
52 return __last_iter;
53 }
54
55 template <random_access_iterator _Iter, sentinel_for<_Iter> _Sent, class _Comp = ranges::less, class _Proj = identity>
56 requires sortable<_Iter, _Comp, _Proj>
57 _LIBCPP_HIDE_FROM_ABI constexpr
58 _Iter operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const {
59 return __pop_heap_fn_impl(std::move(__first), std::move(__last), __comp, __proj);
60 }
61
62 template <random_access_range _Range, class _Comp = ranges::less, class _Proj = identity>
63 requires sortable<iterator_t<_Range>, _Comp, _Proj>
64 _LIBCPP_HIDE_FROM_ABI constexpr
65 borrowed_iterator_t<_Range> operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {}) const {
66 return __pop_heap_fn_impl(ranges::begin(__r), ranges::end(__r), __comp, __proj);
67 }
68};
69
70} // namespace __pop_heap
71
72inline namespace __cpo {
73 inline constexpr auto pop_heap = __pop_heap::__fn{};
74} // namespace __cpo
75} // namespace ranges
76
77_LIBCPP_END_NAMESPACE_STD
78
79#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
80
81#endif // _LIBCPP___ALGORITHM_RANGES_POP_HEAP_H
lib/libcxx/include/__algorithm/ranges_push_heap.h created+80
......@@ -0,0 +1,80 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_PUSH_HEAP_H
10#define _LIBCPP___ALGORITHM_RANGES_PUSH_HEAP_H
11
12#include <__algorithm/iterator_operations.h>
13#include <__algorithm/make_projected.h>
14#include <__algorithm/push_heap.h>
15#include <__concepts/same_as.h>
16#include <__config>
17#include <__functional/identity.h>
18#include <__functional/invoke.h>
19#include <__functional/ranges_operations.h>
20#include <__iterator/concepts.h>
21#include <__iterator/iterator_traits.h>
22#include <__iterator/next.h>
23#include <__iterator/projected.h>
24#include <__iterator/sortable.h>
25#include <__ranges/access.h>
26#include <__ranges/concepts.h>
27#include <__ranges/dangling.h>
28#include <__utility/forward.h>
29#include <__utility/move.h>
30
31#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
32# pragma GCC system_header
33#endif
34
35#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
36
37_LIBCPP_BEGIN_NAMESPACE_STD
38
39namespace ranges {
40namespace __push_heap {
41
42struct __fn {
43 template <class _Iter, class _Sent, class _Comp, class _Proj>
44 _LIBCPP_HIDE_FROM_ABI constexpr static
45 _Iter __push_heap_fn_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) {
46 auto __last_iter = ranges::next(__first, __last);
47
48 auto&& __projected_comp = std::__make_projected(__comp, __proj);
49 std::__push_heap<_RangeAlgPolicy>(std::move(__first), __last_iter, __projected_comp);
50
51 return __last_iter;
52 }
53
54 template <random_access_iterator _Iter, sentinel_for<_Iter> _Sent, class _Comp = ranges::less, class _Proj = identity>
55 requires sortable<_Iter, _Comp, _Proj>
56 _LIBCPP_HIDE_FROM_ABI constexpr
57 _Iter operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const {
58 return __push_heap_fn_impl(std::move(__first), std::move(__last), __comp, __proj);
59 }
60
61 template <random_access_range _Range, class _Comp = ranges::less, class _Proj = identity>
62 requires sortable<iterator_t<_Range>, _Comp, _Proj>
63 _LIBCPP_HIDE_FROM_ABI constexpr
64 borrowed_iterator_t<_Range> operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {}) const {
65 return __push_heap_fn_impl(ranges::begin(__r), ranges::end(__r), __comp, __proj);
66 }
67};
68
69} // namespace __push_heap
70
71inline namespace __cpo {
72 inline constexpr auto push_heap = __push_heap::__fn{};
73} // namespace __cpo
74} // namespace ranges
75
76_LIBCPP_END_NAMESPACE_STD
77
78#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
79
80#endif // _LIBCPP___ALGORITHM_RANGES_PUSH_HEAP_H
lib/libcxx/include/__algorithm/ranges_remove.h created+64
......@@ -0,0 +1,64 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_REMOVE_H
10#define _LIBCPP___ALGORITHM_RANGES_REMOVE_H
11#include <__config>
12
13#include <__algorithm/ranges_remove_if.h>
14#include <__functional/identity.h>
15#include <__functional/ranges_operations.h>
16#include <__iterator/concepts.h>
17#include <__iterator/permutable.h>
18#include <__iterator/projected.h>
19#include <__ranges/access.h>
20#include <__ranges/concepts.h>
21#include <__ranges/subrange.h>
22#include <__utility/move.h>
23
24#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
25# pragma GCC system_header
26#endif
27
28#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
29
30_LIBCPP_BEGIN_NAMESPACE_STD
31
32namespace ranges {
33namespace __remove {
34struct __fn {
35
36 template <permutable _Iter, sentinel_for<_Iter> _Sent, class _Type, class _Proj = identity>
37 requires indirect_binary_predicate<ranges::equal_to, projected<_Iter, _Proj>, const _Type*>
38 _LIBCPP_HIDE_FROM_ABI constexpr
39 subrange<_Iter> operator()(_Iter __first, _Sent __last, const _Type& __value, _Proj __proj = {}) const {
40 auto __pred = [&](auto&& __other) { return __value == __other; };
41 return ranges::__remove_if_impl(std::move(__first), std::move(__last), __pred, __proj);
42 }
43
44 template <forward_range _Range, class _Type, class _Proj = identity>
45 requires permutable<iterator_t<_Range>>
46 && indirect_binary_predicate<ranges::equal_to, projected<iterator_t<_Range>, _Proj>, const _Type*>
47 _LIBCPP_HIDE_FROM_ABI constexpr
48 borrowed_subrange_t<_Range> operator()(_Range&& __range, const _Type& __value, _Proj __proj = {}) const {
49 auto __pred = [&](auto&& __other) { return __value == __other; };
50 return ranges::__remove_if_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj);
51 }
52};
53} // namespace __remove
54
55inline namespace __cpo {
56 inline constexpr auto remove = __remove::__fn{};
57} // namespace __cpo
58} // namespace ranges
59
60_LIBCPP_END_NAMESPACE_STD
61
62#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
63
64#endif // _LIBCPP___ALGORITHM_RANGES_REMOVE_H
lib/libcxx/include/__algorithm/ranges_remove_copy.h created+81
......@@ -0,0 +1,81 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_REMOVE_COPY_H
10#define _LIBCPP___ALGORITHM_RANGES_REMOVE_COPY_H
11
12#include <__algorithm/in_out_result.h>
13#include <__algorithm/make_projected.h>
14#include <__algorithm/remove_copy.h>
15#include <__config>
16#include <__functional/identity.h>
17#include <__functional/invoke.h>
18#include <__functional/ranges_operations.h>
19#include <__iterator/concepts.h>
20#include <__iterator/iterator_traits.h>
21#include <__iterator/projected.h>
22#include <__ranges/access.h>
23#include <__ranges/concepts.h>
24#include <__ranges/dangling.h>
25#include <__utility/forward.h>
26#include <__utility/move.h>
27
28#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
29# pragma GCC system_header
30#endif
31
32#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
33
34_LIBCPP_BEGIN_NAMESPACE_STD
35
36namespace ranges {
37
38template <class _InIter, class _OutIter>
39using remove_copy_result = in_out_result<_InIter, _OutIter>;
40
41namespace __remove_copy {
42
43struct __fn {
44
45 template <input_iterator _InIter, sentinel_for<_InIter> _Sent, weakly_incrementable _OutIter, class _Type,
46 class _Proj = identity>
47 requires indirectly_copyable<_InIter, _OutIter> &&
48 indirect_binary_predicate<ranges::equal_to, projected<_InIter, _Proj>, const _Type*>
49 _LIBCPP_HIDE_FROM_ABI constexpr
50 remove_copy_result<_InIter, _OutIter>
51 operator()(_InIter __first, _Sent __last, _OutIter __result, const _Type& __value, _Proj __proj = {}) const {
52 // TODO: implement
53 (void)__first; (void)__last; (void)__result; (void)__value; (void)__proj;
54 return {};
55 }
56
57 template <input_range _Range, weakly_incrementable _OutIter, class _Type, class _Proj = identity>
58 requires indirectly_copyable<iterator_t<_Range>, _OutIter> &&
59 indirect_binary_predicate<ranges::equal_to, projected<iterator_t<_Range>, _Proj>, const _Type*>
60 _LIBCPP_HIDE_FROM_ABI constexpr
61 remove_copy_result<borrowed_iterator_t<_Range>, _OutIter>
62 operator()(_Range&& __range, _OutIter __result, const _Type& __value, _Proj __proj = {}) const {
63 // TODO: implement
64 (void)__range; (void)__result; (void)__value; (void)__proj;
65 return {};
66 }
67
68};
69
70} // namespace __remove_copy
71
72inline namespace __cpo {
73 inline constexpr auto remove_copy = __remove_copy::__fn{};
74} // namespace __cpo
75} // namespace ranges
76
77_LIBCPP_END_NAMESPACE_STD
78
79#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
80
81#endif // _LIBCPP___ALGORITHM_RANGES_REMOVE_COPY_H
lib/libcxx/include/__algorithm/ranges_remove_copy_if.h created+80
......@@ -0,0 +1,80 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_REMOVE_COPY_IF_H
10#define _LIBCPP___ALGORITHM_RANGES_REMOVE_COPY_IF_H
11
12#include <__algorithm/in_out_result.h>
13#include <__algorithm/make_projected.h>
14#include <__algorithm/remove_copy_if.h>
15#include <__config>
16#include <__functional/identity.h>
17#include <__functional/invoke.h>
18#include <__functional/ranges_operations.h>
19#include <__iterator/concepts.h>
20#include <__iterator/iterator_traits.h>
21#include <__iterator/projected.h>
22#include <__ranges/access.h>
23#include <__ranges/concepts.h>
24#include <__ranges/dangling.h>
25#include <__utility/forward.h>
26#include <__utility/move.h>
27
28#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
29# pragma GCC system_header
30#endif
31
32#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
33
34_LIBCPP_BEGIN_NAMESPACE_STD
35
36namespace ranges {
37
38template <class _InIter, class _OutIter>
39using remove_copy_if_result = in_out_result<_InIter, _OutIter>;
40
41namespace __remove_copy_if {
42
43struct __fn {
44
45 template <input_iterator _InIter, sentinel_for<_InIter> _Sent, weakly_incrementable _OutIter,
46 class _Proj = identity, indirect_unary_predicate<projected<_InIter, _Proj>> _Pred>
47 requires indirectly_copyable<_InIter, _OutIter>
48 _LIBCPP_HIDE_FROM_ABI constexpr
49 remove_copy_if_result<_InIter, _OutIter>
50 operator()(_InIter __first, _Sent __last, _OutIter __result, _Pred __pred, _Proj __proj = {}) const {
51 // TODO: implement
52 (void)__first; (void)__last; (void)__result; (void)__pred; (void)__proj;
53 return {};
54 }
55
56 template <input_range _Range, weakly_incrementable _OutIter, class _Proj = identity,
57 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>> _Pred>
58 requires indirectly_copyable<iterator_t<_Range>, _OutIter>
59 _LIBCPP_HIDE_FROM_ABI constexpr
60 remove_copy_if_result<borrowed_iterator_t<_Range>, _OutIter>
61 operator()(_Range&& __range, _OutIter __result, _Pred __pred, _Proj __proj = {}) const {
62 // TODO: implement
63 (void)__range; (void)__result; (void)__pred; (void)__proj;
64 return {};
65 }
66
67};
68
69} // namespace __remove_copy_if
70
71inline namespace __cpo {
72 inline constexpr auto remove_copy_if = __remove_copy_if::__fn{};
73} // namespace __cpo
74} // namespace ranges
75
76_LIBCPP_END_NAMESPACE_STD
77
78#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
79
80#endif // _LIBCPP___ALGORITHM_RANGES_REMOVE_COPY_IF_H
lib/libcxx/include/__algorithm/ranges_remove_if.h created+85
......@@ -0,0 +1,85 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_REMOVE_IF_H
10#define _LIBCPP___ALGORITHM_RANGES_REMOVE_IF_H
11#include <__config>
12
13#include <__algorithm/ranges_find_if.h>
14#include <__functional/identity.h>
15#include <__functional/invoke.h>
16#include <__functional/ranges_operations.h>
17#include <__iterator/concepts.h>
18#include <__iterator/iter_move.h>
19#include <__iterator/permutable.h>
20#include <__iterator/projected.h>
21#include <__ranges/access.h>
22#include <__ranges/concepts.h>
23#include <__ranges/subrange.h>
24#include <__utility/move.h>
25
26#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
27# pragma GCC system_header
28#endif
29
30#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
31
32_LIBCPP_BEGIN_NAMESPACE_STD
33
34namespace ranges {
35
36template <class _Iter, class _Sent, class _Proj, class _Pred>
37_LIBCPP_HIDE_FROM_ABI constexpr
38subrange<_Iter> __remove_if_impl(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
39 auto __new_end = ranges::__find_if_impl(__first, __last, __pred, __proj);
40 if (__new_end == __last)
41 return {__new_end, __new_end};
42
43 _Iter __i = __new_end;
44 while (++__i != __last) {
45 if (!std::invoke(__pred, std::invoke(__proj, *__i))) {
46 *__new_end = ranges::iter_move(__i);
47 ++__new_end;
48 }
49 }
50 return {__new_end, __i};
51}
52
53namespace __remove_if {
54struct __fn {
55
56 template <permutable _Iter, sentinel_for<_Iter> _Sent,
57 class _Proj = identity,
58 indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
59 _LIBCPP_HIDE_FROM_ABI constexpr
60 subrange<_Iter> operator()(_Iter __first, _Sent __last, _Pred __pred, _Proj __proj = {}) const {
61 return ranges::__remove_if_impl(std::move(__first), std::move(__last), __pred, __proj);
62 }
63
64 template <forward_range _Range,
65 class _Proj = identity,
66 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>> _Pred>
67 requires permutable<iterator_t<_Range>>
68 _LIBCPP_HIDE_FROM_ABI constexpr
69 borrowed_subrange_t<_Range> operator()(_Range&& __range, _Pred __pred, _Proj __proj = {}) const {
70 return ranges::__remove_if_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj);
71 }
72
73};
74} // namespace __remove_if
75
76inline namespace __cpo {
77 inline constexpr auto remove_if = __remove_if::__fn{};
78} // namespace __cpo
79} // namespace ranges
80
81_LIBCPP_END_NAMESPACE_STD
82
83#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
84
85#endif // _LIBCPP___ALGORITHM_RANGES_REMOVE_IF_H
lib/libcxx/include/__algorithm/ranges_replace.h created+74
......@@ -0,0 +1,74 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_REPLACE_H
10#define _LIBCPP___ALGORITHM_RANGES_REPLACE_H
11
12#include <__algorithm/ranges_replace_if.h>
13#include <__config>
14#include <__functional/identity.h>
15#include <__functional/ranges_operations.h>
16#include <__iterator/concepts.h>
17#include <__iterator/projected.h>
18#include <__ranges/access.h>
19#include <__ranges/concepts.h>
20#include <__ranges/dangling.h>
21#include <__utility/move.h>
22
23#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
24# pragma GCC system_header
25#endif
26
27#if _LIBCPP_STD_VER > 17 && !defined (_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
28
29_LIBCPP_BEGIN_NAMESPACE_STD
30
31namespace ranges {
32namespace __replace {
33struct __fn {
34
35 template <input_iterator _Iter, sentinel_for<_Iter> _Sent,
36 class _Type1,
37 class _Type2,
38 class _Proj = identity>
39 requires indirectly_writable<_Iter, const _Type2&>
40 && indirect_binary_predicate<ranges::equal_to, projected<_Iter, _Proj>, const _Type1*>
41 _LIBCPP_HIDE_FROM_ABI constexpr
42 _Iter operator()(_Iter __first, _Sent __last,
43 const _Type1& __old_value,
44 const _Type2& __new_value,
45 _Proj __proj = {}) const {
46 auto __pred = [&](const auto& __val) { return __val == __old_value; };
47 return ranges::__replace_if_impl(std::move(__first), std::move(__last), __pred, __new_value, __proj);
48 }
49
50 template <input_range _Range,
51 class _Type1,
52 class _Type2,
53 class _Proj = identity>
54 requires indirectly_writable<iterator_t<_Range>, const _Type2&>
55 && indirect_binary_predicate<ranges::equal_to, projected<iterator_t<_Range>, _Proj>, const _Type1*>
56 _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Range>
57 operator()(_Range&& __range, const _Type1& __old_value, const _Type2& __new_value, _Proj __proj = {}) const {
58 auto __pred = [&](auto&& __val) { return __val == __old_value; };
59 return ranges::__replace_if_impl(ranges::begin(__range), ranges::end(__range), __pred, __new_value, __proj);
60 }
61
62};
63} // namespace __replace
64
65inline namespace __cpo {
66 inline constexpr auto replace = __replace::__fn{};
67} // namespace __cpo
68} // namespace ranges
69
70_LIBCPP_END_NAMESPACE_STD
71
72#endif // _LIBCPP_STD_VER > 17 && !defined (_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
73
74#endif // _LIBCPP___ALGORITHM_RANGES_REPLACE_H
lib/libcxx/include/__algorithm/ranges_replace_copy.h created+84
......@@ -0,0 +1,84 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_REPLACE_COPY_H
10#define _LIBCPP___ALGORITHM_RANGES_REPLACE_COPY_H
11
12#include <__algorithm/in_out_result.h>
13#include <__algorithm/make_projected.h>
14#include <__algorithm/replace_copy.h>
15#include <__config>
16#include <__functional/identity.h>
17#include <__functional/invoke.h>
18#include <__functional/ranges_operations.h>
19#include <__iterator/concepts.h>
20#include <__iterator/iterator_traits.h>
21#include <__iterator/projected.h>
22#include <__ranges/access.h>
23#include <__ranges/concepts.h>
24#include <__ranges/dangling.h>
25#include <__utility/forward.h>
26#include <__utility/move.h>
27
28#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
29# pragma GCC system_header
30#endif
31
32#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
33
34_LIBCPP_BEGIN_NAMESPACE_STD
35
36namespace ranges {
37
38template <class _InIter, class _OutIter>
39using replace_copy_result = in_out_result<_InIter, _OutIter>;
40
41namespace __replace_copy {
42
43struct __fn {
44
45 template <input_iterator _InIter, sentinel_for<_InIter> _Sent, class _Type1, class _Type2,
46 output_iterator<const _Type2&> _OutIter, class _Proj = identity>
47 requires indirectly_copyable<_InIter, _OutIter> &&
48 indirect_binary_predicate<ranges::equal_to, projected<_InIter, _Proj>, const _Type1*>
49 _LIBCPP_HIDE_FROM_ABI constexpr
50 replace_copy_result<_InIter, _OutIter>
51 operator()(_InIter __first, _Sent __last, _OutIter __result, const _Type1& __old_value, const _Type2& __new_value,
52 _Proj __proj = {}) const {
53 // TODO: implement
54 (void)__first; (void)__last; (void)__result; (void)__old_value; (void)__new_value; (void)__proj;
55 return {};
56 }
57
58 template <input_range _Range, class _Type1, class _Type2, output_iterator<const _Type2&> _OutIter,
59 class _Proj = identity>
60 requires indirectly_copyable<iterator_t<_Range>, _OutIter> &&
61 indirect_binary_predicate<ranges::equal_to, projected<iterator_t<_Range>, _Proj>, const _Type1*>
62 _LIBCPP_HIDE_FROM_ABI constexpr
63 replace_copy_result<borrowed_iterator_t<_Range>, _OutIter>
64 operator()(_Range&& __range, _OutIter __result, const _Type1& __old_value, const _Type2& __new_value,
65 _Proj __proj = {}) const {
66 // TODO: implement
67 (void)__range; (void)__result; (void)__old_value; (void)__new_value; (void)__proj;
68 return {};
69 }
70
71};
72
73} // namespace __replace_copy
74
75inline namespace __cpo {
76 inline constexpr auto replace_copy = __replace_copy::__fn{};
77} // namespace __cpo
78} // namespace ranges
79
80_LIBCPP_END_NAMESPACE_STD
81
82#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
83
84#endif // _LIBCPP___ALGORITHM_RANGES_REPLACE_COPY_H
lib/libcxx/include/__algorithm/ranges_replace_copy_if.h created+81
......@@ -0,0 +1,81 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_REPLACE_COPY_IF_H
10#define _LIBCPP___ALGORITHM_RANGES_REPLACE_COPY_IF_H
11
12#include <__algorithm/in_out_result.h>
13#include <__algorithm/make_projected.h>
14#include <__algorithm/replace_copy_if.h>
15#include <__config>
16#include <__functional/identity.h>
17#include <__functional/invoke.h>
18#include <__functional/ranges_operations.h>
19#include <__iterator/concepts.h>
20#include <__iterator/iterator_traits.h>
21#include <__iterator/projected.h>
22#include <__ranges/access.h>
23#include <__ranges/concepts.h>
24#include <__ranges/dangling.h>
25#include <__utility/forward.h>
26#include <__utility/move.h>
27
28#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
29# pragma GCC system_header
30#endif
31
32#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
33
34_LIBCPP_BEGIN_NAMESPACE_STD
35
36namespace ranges {
37
38template <class _InIter, class _OutIter>
39using replace_copy_if_result = in_out_result<_InIter, _OutIter>;
40
41namespace __replace_copy_if {
42
43struct __fn {
44
45 template <input_iterator _InIter, sentinel_for<_InIter> _Sent, class _Type, output_iterator<const _Type&> _OutIter,
46 class _Proj = identity, indirect_unary_predicate<projected<_InIter, _Proj>> _Pred>
47 requires indirectly_copyable<_InIter, _OutIter>
48 _LIBCPP_HIDE_FROM_ABI constexpr
49 replace_copy_if_result<_InIter, _OutIter>
50 operator()(_InIter __first, _Sent __last, _OutIter __result, _Pred __pred, const _Type& __new_value,
51 _Proj __proj = {}) const {
52 // TODO: implement
53 (void)__first; (void)__last; (void)__result; (void)__pred; (void)__new_value; (void)__proj;
54 return {};
55 }
56
57 template <input_range _Range, class _Type, output_iterator<const _Type&> _OutIter, class _Proj = identity,
58 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>> _Pred>
59 requires indirectly_copyable<iterator_t<_Range>, _OutIter>
60 _LIBCPP_HIDE_FROM_ABI constexpr
61 replace_copy_if_result<borrowed_iterator_t<_Range>, _OutIter>
62 operator()(_Range&& __range, _OutIter __result, _Pred __pred, const _Type& __new_value, _Proj __proj = {}) const {
63 // TODO: implement
64 (void)__range; (void)__result; (void)__pred; (void)__new_value; (void)__proj;
65 return {};
66 }
67
68};
69
70} // namespace __replace_copy_if
71
72inline namespace __cpo {
73 inline constexpr auto replace_copy_if = __replace_copy_if::__fn{};
74} // namespace __cpo
75} // namespace ranges
76
77_LIBCPP_END_NAMESPACE_STD
78
79#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
80
81#endif // _LIBCPP___ALGORITHM_RANGES_REPLACE_COPY_IF_H
lib/libcxx/include/__algorithm/ranges_replace_if.h created+77
......@@ -0,0 +1,77 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_REPLACE_IF_H
10#define _LIBCPP___ALGORITHM_RANGES_REPLACE_IF_H
11
12#include <__config>
13#include <__functional/identity.h>
14#include <__functional/invoke.h>
15#include <__iterator/concepts.h>
16#include <__iterator/projected.h>
17#include <__ranges/access.h>
18#include <__ranges/concepts.h>
19#include <__ranges/dangling.h>
20#include <__utility/move.h>
21
22#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23# pragma GCC system_header
24#endif
25
26#if _LIBCPP_STD_VER > 17 && !defined (_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
27
28_LIBCPP_BEGIN_NAMESPACE_STD
29
30namespace ranges {
31
32template <class _Iter, class _Sent, class _Type, class _Proj, class _Pred>
33_LIBCPP_HIDE_FROM_ABI constexpr
34_Iter __replace_if_impl(_Iter __first, _Sent __last, _Pred& __pred, const _Type& __new_value, _Proj& __proj) {
35 for (; __first != __last; ++__first) {
36 if (std::invoke(__pred, std::invoke(__proj, *__first)))
37 *__first = __new_value;
38 }
39 return __first;
40}
41
42namespace __replace_if {
43struct __fn {
44
45 template <input_iterator _Iter, sentinel_for<_Iter> _Sent,
46 class _Type,
47 class _Proj = identity,
48 indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
49 requires indirectly_writable<_Iter, const _Type&>
50 _LIBCPP_HIDE_FROM_ABI constexpr
51 _Iter operator()(_Iter __first, _Sent __last, _Pred __pred, const _Type& __new_value, _Proj __proj = {}) const {
52 return ranges::__replace_if_impl(std::move(__first), std::move(__last), __pred, __new_value, __proj);
53 }
54
55 template <input_range _Range,
56 class _Type,
57 class _Proj = identity,
58 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>> _Pred>
59 requires indirectly_writable<iterator_t<_Range>, const _Type&>
60 _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Range>
61 operator()(_Range&& __range, _Pred __pred, const _Type& __new_value, _Proj __proj = {}) const {
62 return ranges::__replace_if_impl(ranges::begin(__range), ranges::end(__range), __pred, __new_value, __proj);
63 }
64
65};
66} // namespace __replace_if
67
68inline namespace __cpo {
69 inline constexpr auto replace_if = __replace_if::__fn{};
70} // namespace __cpo
71} // namespace ranges
72
73_LIBCPP_END_NAMESPACE_STD
74
75#endif // _LIBCPP_STD_VER > 17 && !defined (_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
76
77#endif // _LIBCPP___ALGORITHM_RANGES_REPLACE_IF_H
lib/libcxx/include/__algorithm/ranges_reverse.h created+83
......@@ -0,0 +1,83 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_REVERSE_H
10#define _LIBCPP___ALGORITHM_RANGES_REVERSE_H
11
12#include <__config>
13#include <__iterator/concepts.h>
14#include <__iterator/iter_swap.h>
15#include <__iterator/next.h>
16#include <__iterator/permutable.h>
17#include <__ranges/access.h>
18#include <__ranges/concepts.h>
19#include <__ranges/dangling.h>
20
21#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22# pragma GCC system_header
23#endif
24
25#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
26
27_LIBCPP_BEGIN_NAMESPACE_STD
28
29namespace ranges {
30namespace __reverse {
31struct __fn {
32
33 template <bidirectional_iterator _Iter, sentinel_for<_Iter> _Sent>
34 requires permutable<_Iter>
35 _LIBCPP_HIDE_FROM_ABI constexpr
36 _Iter operator()(_Iter __first, _Sent __last) const {
37 if constexpr (random_access_iterator<_Iter>) {
38 if (__first == __last)
39 return __first;
40
41 auto __end = ranges::next(__first, __last);
42 auto __ret = __end;
43
44 while (__first < --__end) {
45 ranges::iter_swap(__first, __end);
46 ++__first;
47 }
48 return __ret;
49 } else {
50 auto __end = ranges::next(__first, __last);
51 auto __ret = __end;
52
53 while (__first != __end) {
54 if (__first == --__end)
55 break;
56
57 ranges::iter_swap(__first, __end);
58 ++__first;
59 }
60 return __ret;
61 }
62 }
63
64 template <bidirectional_range _Range>
65 requires permutable<iterator_t<_Range>>
66 _LIBCPP_HIDE_FROM_ABI constexpr
67 borrowed_iterator_t<_Range> operator()(_Range&& __range) const {
68 return (*this)(ranges::begin(__range), ranges::end(__range));
69 }
70
71};
72} // namespace __reverse
73
74inline namespace __cpo {
75 inline constexpr auto reverse = __reverse::__fn{};
76} // namespace __cpo
77} // namespace ranges
78
79_LIBCPP_END_NAMESPACE_STD
80
81#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
82
83#endif // _LIBCPP___ALGORITHM_RANGES_REVERSE_H
lib/libcxx/include/__algorithm/ranges_reverse_copy.h created+67
......@@ -0,0 +1,67 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_REVERSE_COPY_H
10#define _LIBCPP___ALGORITHM_RANGES_REVERSE_COPY_H
11
12#include <__algorithm/in_out_result.h>
13#include <__algorithm/ranges_copy.h>
14#include <__config>
15#include <__iterator/concepts.h>
16#include <__iterator/next.h>
17#include <__iterator/reverse_iterator.h>
18#include <__ranges/access.h>
19#include <__ranges/concepts.h>
20#include <__ranges/dangling.h>
21#include <__ranges/subrange.h>
22#include <__utility/move.h>
23
24#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
25# pragma GCC system_header
26#endif
27
28#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
29
30_LIBCPP_BEGIN_NAMESPACE_STD
31
32namespace ranges {
33
34template <class _InIter, class _OutIter>
35using reverse_copy_result = in_out_result<_InIter, _OutIter>;
36
37namespace __reverse_copy {
38struct __fn {
39
40 template <bidirectional_iterator _InIter, sentinel_for<_InIter> _Sent, weakly_incrementable _OutIter>
41 requires indirectly_copyable<_InIter, _OutIter>
42 _LIBCPP_HIDE_FROM_ABI constexpr
43 reverse_copy_result<_InIter, _OutIter> operator()(_InIter __first, _Sent __last, _OutIter __result) const {
44 return (*this)(subrange(std::move(__first), std::move(__last)), std::move(__result));
45 }
46
47 template <bidirectional_range _Range, weakly_incrementable _OutIter>
48 requires indirectly_copyable<iterator_t<_Range>, _OutIter>
49 _LIBCPP_HIDE_FROM_ABI constexpr
50 reverse_copy_result<borrowed_iterator_t<_Range>, _OutIter> operator()(_Range&& __range, _OutIter __result) const {
51 auto __ret = ranges::copy(std::__reverse_range(__range), std::move(__result));
52 return {ranges::next(ranges::begin(__range), ranges::end(__range)), std::move(__ret.out)};
53 }
54
55};
56} // namespace __reverse_copy
57
58inline namespace __cpo {
59 inline constexpr auto reverse_copy = __reverse_copy::__fn{};
60} // namespace __cpo
61} // namespace ranges
62
63_LIBCPP_END_NAMESPACE_STD
64
65#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
66
67#endif // _LIBCPP___ALGORITHM_RANGES_REVERSE_COPY_H
lib/libcxx/include/__algorithm/ranges_rotate_copy.h created+68
......@@ -0,0 +1,68 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_ROTATE_COPY_H
10#define _LIBCPP___ALGORITHM_RANGES_ROTATE_COPY_H
11
12#include <__algorithm/in_out_result.h>
13#include <__algorithm/ranges_copy.h>
14#include <__config>
15#include <__iterator/concepts.h>
16#include <__iterator/reverse_iterator.h>
17#include <__ranges/access.h>
18#include <__ranges/concepts.h>
19#include <__ranges/dangling.h>
20#include <__utility/move.h>
21
22#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23# pragma GCC system_header
24#endif
25
26#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
27
28_LIBCPP_BEGIN_NAMESPACE_STD
29
30namespace ranges {
31
32template <class _InIter, class _OutIter>
33using rotate_copy_result = in_out_result<_InIter, _OutIter>;
34
35namespace __rotate_copy {
36struct __fn {
37
38 template <bidirectional_iterator _InIter, sentinel_for<_InIter> _Sent, weakly_incrementable _OutIter>
39 requires indirectly_copyable<_InIter, _OutIter>
40 _LIBCPP_HIDE_FROM_ABI constexpr
41 rotate_copy_result<_InIter, _OutIter>
42 operator()(_InIter __first, _InIter __middle, _Sent __last, _OutIter __result) const {
43 auto __res1 = ranges::copy(__middle, __last, std::move(__result));
44 auto __res2 = ranges::copy(__first, __middle, std::move(__res1.out));
45 return {std::move(__res1.in), std::move(__res2.out)};
46 }
47
48 template <bidirectional_range _Range, weakly_incrementable _OutIter>
49 requires indirectly_copyable<iterator_t<_Range>, _OutIter>
50 _LIBCPP_HIDE_FROM_ABI constexpr
51 rotate_copy_result<borrowed_iterator_t<_Range>, _OutIter>
52 operator()(_Range&& __range, iterator_t<_Range> __middle, _OutIter __result) const {
53 return (*this)(ranges::begin(__range), std::move(__middle), ranges::end(__range), std::move(__result));
54 }
55
56};
57} // namespace __rotate_copy
58
59inline namespace __cpo {
60 inline constexpr auto rotate_copy = __rotate_copy::__fn{};
61} // namespace __cpo
62} // namespace ranges
63
64_LIBCPP_END_NAMESPACE_STD
65
66#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
67
68#endif // _LIBCPP___ALGORITHM_RANGES_ROTATE_COPY_H
lib/libcxx/include/__algorithm/ranges_search.h created+134
......@@ -0,0 +1,134 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_SEARCH_H
10#define _LIBCPP___ALGORITHM_RANGES_SEARCH_H
11
12#include <__algorithm/iterator_operations.h>
13#include <__algorithm/search.h>
14#include <__config>
15#include <__functional/identity.h>
16#include <__functional/ranges_operations.h>
17#include <__iterator/advance.h>
18#include <__iterator/concepts.h>
19#include <__iterator/distance.h>
20#include <__iterator/indirectly_comparable.h>
21#include <__ranges/access.h>
22#include <__ranges/concepts.h>
23#include <__ranges/size.h>
24#include <__ranges/subrange.h>
25
26#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
27# pragma GCC system_header
28#endif
29
30#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
31
32_LIBCPP_BEGIN_NAMESPACE_STD
33
34namespace ranges {
35namespace __search {
36struct __fn {
37 template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Pred, class _Proj1, class _Proj2>
38 _LIBCPP_HIDE_FROM_ABI static constexpr subrange<_Iter1> __ranges_search_impl(
39 _Iter1 __first1,
40 _Sent1 __last1,
41 _Iter2 __first2,
42 _Sent2 __last2,
43 _Pred& __pred,
44 _Proj1& __proj1,
45 _Proj2& __proj2) {
46 if constexpr (sized_sentinel_for<_Sent2, _Iter2>) {
47 auto __size2 = ranges::distance(__first2, __last2);
48 if (__size2 == 0)
49 return {__first1, __first1};
50
51 if constexpr (sized_sentinel_for<_Sent1, _Iter1>) {
52 auto __size1 = ranges::distance(__first1, __last1);
53 if (__size1 < __size2) {
54 ranges::advance(__first1, __last1);
55 return {__first1, __first1};
56 }
57
58 if constexpr (random_access_iterator<_Iter1> && random_access_iterator<_Iter2>) {
59 auto __ret = std::__search_random_access_impl<_RangeAlgPolicy>(
60 __first1, __last1, __first2, __last2, __pred, __proj1, __proj2, __size1, __size2);
61 return {__ret.first, __ret.second};
62 }
63 }
64 }
65
66 auto __ret =
67 std::__search_forward_impl<_RangeAlgPolicy>(__first1, __last1, __first2, __last2, __pred, __proj1, __proj2);
68 return {__ret.first, __ret.second};
69 }
70
71 template <forward_iterator _Iter1, sentinel_for<_Iter1> _Sent1,
72 forward_iterator _Iter2, sentinel_for<_Iter2> _Sent2,
73 class _Pred = ranges::equal_to,
74 class _Proj1 = identity,
75 class _Proj2 = identity>
76 requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2>
77 _LIBCPP_HIDE_FROM_ABI constexpr
78 subrange<_Iter1> operator()(_Iter1 __first1, _Sent1 __last1,
79 _Iter2 __first2, _Sent2 __last2,
80 _Pred __pred = {},
81 _Proj1 __proj1 = {},
82 _Proj2 __proj2 = {}) const {
83 return __ranges_search_impl(__first1, __last1, __first2, __last2, __pred, __proj1, __proj2);
84 }
85
86 template <forward_range _Range1,
87 forward_range _Range2,
88 class _Pred = ranges::equal_to,
89 class _Proj1 = identity,
90 class _Proj2 = identity>
91 requires indirectly_comparable<iterator_t<_Range1>, iterator_t<_Range2>, _Pred, _Proj1, _Proj2>
92 _LIBCPP_HIDE_FROM_ABI constexpr
93 borrowed_subrange_t<_Range1> operator()(_Range1&& __range1,
94 _Range2&& __range2,
95 _Pred __pred = {},
96 _Proj1 __proj1 = {},
97 _Proj2 __proj2 = {}) const {
98 auto __first1 = ranges::begin(__range1);
99 if constexpr (sized_range<_Range2>) {
100 auto __size2 = ranges::size(__range2);
101 if (__size2 == 0)
102 return {__first1, __first1};
103 if constexpr (sized_range<_Range1>) {
104 auto __size1 = ranges::size(__range1);
105 if (__size1 < __size2) {
106 ranges::advance(__first1, ranges::end(__range1));
107 return {__first1, __first1};
108 }
109 }
110 }
111
112 return __ranges_search_impl(
113 ranges::begin(__range1),
114 ranges::end(__range1),
115 ranges::begin(__range2),
116 ranges::end(__range2),
117 __pred,
118 __proj1,
119 __proj2);
120 }
121
122};
123} // namespace __search
124
125inline namespace __cpo {
126 inline constexpr auto search = __search::__fn{};
127} // namespace __cpo
128} // namespace ranges
129
130_LIBCPP_END_NAMESPACE_STD
131
132#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
133
134#endif // _LIBCPP___ALGORITHM_RANGES_SEARCH_H
lib/libcxx/include/__algorithm/ranges_search_n.h created+120
......@@ -0,0 +1,120 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_SEARCH_N_H
10#define _LIBCPP___ALGORITHM_RANGES_SEARCH_N_H
11
12#include <__algorithm/iterator_operations.h>
13#include <__algorithm/search_n.h>
14#include <__config>
15#include <__functional/identity.h>
16#include <__functional/ranges_operations.h>
17#include <__iterator/advance.h>
18#include <__iterator/concepts.h>
19#include <__iterator/distance.h>
20#include <__iterator/incrementable_traits.h>
21#include <__iterator/indirectly_comparable.h>
22#include <__iterator/iterator_traits.h>
23#include <__ranges/access.h>
24#include <__ranges/concepts.h>
25#include <__ranges/size.h>
26#include <__ranges/subrange.h>
27#include <__utility/move.h>
28
29#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
30# pragma GCC system_header
31#endif
32
33#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
34
35_LIBCPP_BEGIN_NAMESPACE_STD
36
37namespace ranges {
38namespace __search_n {
39struct __fn {
40
41 template <class _Iter1, class _Sent1, class _SizeT, class _Type, class _Pred, class _Proj>
42 _LIBCPP_HIDE_FROM_ABI static constexpr subrange<_Iter1> __ranges_search_n_impl(
43 _Iter1 __first, _Sent1 __last, _SizeT __count, const _Type& __value, _Pred& __pred, _Proj& __proj) {
44 if (__count == 0)
45 return {__first, __first};
46
47 if constexpr (sized_sentinel_for<_Sent1, _Iter1>) {
48 auto __size = ranges::distance(__first, __last);
49 if (__size < __count) {
50 ranges::advance(__first, __last);
51 return {__first, __first};
52 }
53
54 if constexpr (random_access_iterator<_Iter1>) {
55 auto __ret = __search_n_random_access_impl<_RangeAlgPolicy>(__first, __last,
56 __count,
57 __value,
58 __pred,
59 __proj,
60 __size);
61 return {std::move(__ret.first), std::move(__ret.second)};
62 }
63 }
64
65 auto __ret = std::__search_n_forward_impl<_RangeAlgPolicy>(__first, __last,
66 __count,
67 __value,
68 __pred,
69 __proj);
70 return {std::move(__ret.first), std::move(__ret.second)};
71 }
72
73 template <forward_iterator _Iter, sentinel_for<_Iter> _Sent,
74 class _Type,
75 class _Pred = ranges::equal_to,
76 class _Proj = identity>
77 requires indirectly_comparable<_Iter, const _Type*, _Pred, _Proj>
78 _LIBCPP_HIDE_FROM_ABI constexpr
79 subrange<_Iter> operator()(_Iter __first, _Sent __last,
80 iter_difference_t<_Iter> __count,
81 const _Type& __value,
82 _Pred __pred = {},
83 _Proj __proj = _Proj{}) const {
84 return __ranges_search_n_impl(__first, __last, __count, __value, __pred, __proj);
85 }
86
87 template <forward_range _Range, class _Type, class _Pred = ranges::equal_to, class _Proj = identity>
88 requires indirectly_comparable<iterator_t<_Range>, const _Type*, _Pred, _Proj>
89 _LIBCPP_HIDE_FROM_ABI constexpr
90 borrowed_subrange_t<_Range> operator()(_Range&& __range,
91 range_difference_t<_Range> __count,
92 const _Type& __value,
93 _Pred __pred = {},
94 _Proj __proj = {}) const {
95 auto __first = ranges::begin(__range);
96 if (__count <= 0)
97 return {__first, __first};
98 if constexpr (sized_range<_Range>) {
99 auto __size1 = ranges::size(__range);
100 if (__size1 < static_cast<range_size_t<_Range>>(__count)) {
101 ranges::advance(__first, ranges::end(__range));
102 return {__first, __first};
103 }
104 }
105
106 return __ranges_search_n_impl(ranges::begin(__range), ranges::end(__range), __count, __value, __pred, __proj);
107 }
108};
109} // namespace __search_n
110
111inline namespace __cpo {
112 inline constexpr auto search_n = __search_n::__fn{};
113} // namespace __cpo
114} // namespace ranges
115
116_LIBCPP_END_NAMESPACE_STD
117
118#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
119
120#endif // _LIBCPP___ALGORITHM_RANGES_SEARCH_N_H
lib/libcxx/include/__algorithm/ranges_set_difference.h created+104
......@@ -0,0 +1,104 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_SET_DIFFERENCE_H
10#define _LIBCPP___ALGORITHM_RANGES_SET_DIFFERENCE_H
11
12#include <__algorithm/in_out_result.h>
13#include <__algorithm/make_projected.h>
14#include <__algorithm/set_difference.h>
15#include <__config>
16#include <__functional/identity.h>
17#include <__functional/invoke.h>
18#include <__functional/ranges_operations.h>
19#include <__iterator/concepts.h>
20#include <__iterator/mergeable.h>
21#include <__ranges/access.h>
22#include <__ranges/concepts.h>
23#include <__ranges/dangling.h>
24#include <__type_traits/decay.h>
25#include <__utility/move.h>
26
27#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
28# pragma GCC system_header
29#endif
30
31#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
32
33_LIBCPP_BEGIN_NAMESPACE_STD
34
35namespace ranges {
36
37template <class _InIter, class _OutIter>
38using set_difference_result = in_out_result<_InIter, _OutIter>;
39
40namespace __set_difference {
41
42struct __fn {
43 template <
44 input_iterator _InIter1,
45 sentinel_for<_InIter1> _Sent1,
46 input_iterator _InIter2,
47 sentinel_for<_InIter2> _Sent2,
48 weakly_incrementable _OutIter,
49 class _Comp = less,
50 class _Proj1 = identity,
51 class _Proj2 = identity>
52 requires mergeable<_InIter1, _InIter2, _OutIter, _Comp, _Proj1, _Proj2>
53 _LIBCPP_HIDE_FROM_ABI constexpr set_difference_result<_InIter1, _OutIter> operator()(
54 _InIter1 __first1,
55 _Sent1 __last1,
56 _InIter2 __first2,
57 _Sent2 __last2,
58 _OutIter __result,
59 _Comp __comp = {},
60 _Proj1 __proj1 = {},
61 _Proj2 __proj2 = {}) const {
62 auto __ret = std::__set_difference(
63 __first1, __last1, __first2, __last2, __result, ranges::__make_projected_comp(__comp, __proj1, __proj2));
64 return {std::move(__ret.first), std::move(__ret.second)};
65 }
66
67 template <
68 input_range _Range1,
69 input_range _Range2,
70 weakly_incrementable _OutIter,
71 class _Comp = less,
72 class _Proj1 = identity,
73 class _Proj2 = identity>
74 requires mergeable<iterator_t<_Range1>, iterator_t<_Range2>, _OutIter, _Comp, _Proj1, _Proj2>
75 _LIBCPP_HIDE_FROM_ABI constexpr set_difference_result<borrowed_iterator_t<_Range1>, _OutIter>
76 operator()(
77 _Range1&& __range1,
78 _Range2&& __range2,
79 _OutIter __result,
80 _Comp __comp = {},
81 _Proj1 __proj1 = {},
82 _Proj2 __proj2 = {}) const {
83 auto __ret = std::__set_difference(
84 ranges::begin(__range1),
85 ranges::end(__range1),
86 ranges::begin(__range2),
87 ranges::end(__range2),
88 __result,
89 ranges::__make_projected_comp(__comp, __proj1, __proj2));
90 return {std::move(__ret.first), std::move(__ret.second)};
91 }
92};
93
94} // namespace __set_difference
95
96inline namespace __cpo {
97 inline constexpr auto set_difference = __set_difference::__fn{};
98} // namespace __cpo
99} // namespace ranges
100
101_LIBCPP_END_NAMESPACE_STD
102
103#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
104#endif // _LIBCPP___ALGORITHM_RANGES_SET_DIFFERENCE_H
lib/libcxx/include/__algorithm/ranges_set_intersection.h created+117
......@@ -0,0 +1,117 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_SET_INTERSECTION_H
10#define _LIBCPP___ALGORITHM_RANGES_SET_INTERSECTION_H
11
12#include <__algorithm/in_in_out_result.h>
13#include <__algorithm/iterator_operations.h>
14#include <__algorithm/make_projected.h>
15#include <__algorithm/set_intersection.h>
16#include <__config>
17#include <__functional/identity.h>
18#include <__functional/invoke.h>
19#include <__functional/ranges_operations.h>
20#include <__iterator/concepts.h>
21#include <__iterator/mergeable.h>
22#include <__ranges/access.h>
23#include <__ranges/concepts.h>
24#include <__ranges/dangling.h>
25#include <__utility/move.h>
26
27#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
28# pragma GCC system_header
29#endif
30
31#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
32
33_LIBCPP_BEGIN_NAMESPACE_STD
34
35namespace ranges {
36
37template <class _InIter1, class _InIter2, class _OutIter>
38using set_intersection_result = in_in_out_result<_InIter1, _InIter2, _OutIter>;
39
40namespace __set_intersection {
41
42struct __fn {
43 template <
44 input_iterator _InIter1,
45 sentinel_for<_InIter1> _Sent1,
46 input_iterator _InIter2,
47 sentinel_for<_InIter2> _Sent2,
48 weakly_incrementable _OutIter,
49 class _Comp = less,
50 class _Proj1 = identity,
51 class _Proj2 = identity>
52 requires mergeable<_InIter1, _InIter2, _OutIter, _Comp, _Proj1, _Proj2>
53 _LIBCPP_HIDE_FROM_ABI constexpr set_intersection_result<_InIter1, _InIter2, _OutIter> operator()(
54 _InIter1 __first1,
55 _Sent1 __last1,
56 _InIter2 __first2,
57 _Sent2 __last2,
58 _OutIter __result,
59 _Comp __comp = {},
60 _Proj1 __proj1 = {},
61 _Proj2 __proj2 = {}) const {
62 auto __ret = std::__set_intersection<_RangeAlgPolicy>(
63 std::move(__first1),
64 std::move(__last1),
65 std::move(__first2),
66 std::move(__last2),
67 std::move(__result),
68 ranges::__make_projected_comp(__comp, __proj1, __proj2));
69 return {std::move(__ret.__in1_), std::move(__ret.__in2_), std::move(__ret.__out_)};
70 }
71
72 template <
73 input_range _Range1,
74 input_range _Range2,
75 weakly_incrementable _OutIter,
76 class _Comp = less,
77 class _Proj1 = identity,
78 class _Proj2 = identity>
79 requires mergeable<
80 iterator_t<_Range1>,
81 iterator_t<_Range2>,
82 _OutIter,
83 _Comp,
84 _Proj1,
85 _Proj2>
86 _LIBCPP_HIDE_FROM_ABI constexpr set_intersection_result<borrowed_iterator_t<_Range1>,
87 borrowed_iterator_t<_Range2>,
88 _OutIter>
89 operator()(
90 _Range1&& __range1,
91 _Range2&& __range2,
92 _OutIter __result,
93 _Comp __comp = {},
94 _Proj1 __proj1 = {},
95 _Proj2 __proj2 = {}) const {
96 auto __ret = std::__set_intersection<_RangeAlgPolicy>(
97 ranges::begin(__range1),
98 ranges::end(__range1),
99 ranges::begin(__range2),
100 ranges::end(__range2),
101 std::move(__result),
102 ranges::__make_projected_comp(__comp, __proj1, __proj2));
103 return {std::move(__ret.__in1_), std::move(__ret.__in2_), std::move(__ret.__out_)};
104 }
105};
106
107} // namespace __set_intersection
108
109inline namespace __cpo {
110 inline constexpr auto set_intersection = __set_intersection::__fn{};
111} // namespace __cpo
112} // namespace ranges
113
114_LIBCPP_END_NAMESPACE_STD
115
116#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
117#endif // _LIBCPP___ALGORITHM_RANGES_SET_INTERSECTION_H
lib/libcxx/include/__algorithm/ranges_set_symmetric_difference.h created+116
......@@ -0,0 +1,116 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_SET_SYMMETRIC_DIFFERENCE_H
10#define _LIBCPP___ALGORITHM_RANGES_SET_SYMMETRIC_DIFFERENCE_H
11
12#include <__algorithm/in_in_out_result.h>
13#include <__algorithm/make_projected.h>
14#include <__algorithm/set_symmetric_difference.h>
15#include <__config>
16#include <__functional/identity.h>
17#include <__functional/invoke.h>
18#include <__functional/ranges_operations.h>
19#include <__iterator/concepts.h>
20#include <__iterator/mergeable.h>
21#include <__ranges/access.h>
22#include <__ranges/concepts.h>
23#include <__ranges/dangling.h>
24#include <__utility/move.h>
25
26#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
27# pragma GCC system_header
28#endif
29
30#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
31
32_LIBCPP_BEGIN_NAMESPACE_STD
33
34namespace ranges {
35
36template <class _InIter1, class _InIter2, class _OutIter>
37using set_symmetric_difference_result = in_in_out_result<_InIter1, _InIter2, _OutIter>;
38
39namespace __set_symmetric_difference {
40
41struct __fn {
42 template <
43 input_iterator _InIter1,
44 sentinel_for<_InIter1> _Sent1,
45 input_iterator _InIter2,
46 sentinel_for<_InIter2> _Sent2,
47 weakly_incrementable _OutIter,
48 class _Comp = ranges::less,
49 class _Proj1 = identity,
50 class _Proj2 = identity>
51 requires mergeable<_InIter1, _InIter2, _OutIter, _Comp, _Proj1, _Proj2>
52 _LIBCPP_HIDE_FROM_ABI constexpr set_symmetric_difference_result<_InIter1, _InIter2, _OutIter> operator()(
53 _InIter1 __first1,
54 _Sent1 __last1,
55 _InIter2 __first2,
56 _Sent2 __last2,
57 _OutIter __result,
58 _Comp __comp = {},
59 _Proj1 __proj1 = {},
60 _Proj2 __proj2 = {}) const {
61 auto __ret = std::__set_symmetric_difference(
62 std::move(__first1),
63 std::move(__last1),
64 std::move(__first2),
65 std::move(__last2),
66 std::move(__result),
67 ranges::__make_projected_comp(__comp, __proj1, __proj2));
68 return {std::move(__ret.__in1_), std::move(__ret.__in2_), std::move(__ret.__out_)};
69 }
70
71 template <
72 input_range _Range1,
73 input_range _Range2,
74 weakly_incrementable _OutIter,
75 class _Comp = ranges::less,
76 class _Proj1 = identity,
77 class _Proj2 = identity>
78 requires mergeable<
79 iterator_t<_Range1>,
80 iterator_t<_Range2>,
81 _OutIter,
82 _Comp,
83 _Proj1,
84 _Proj2>
85 _LIBCPP_HIDE_FROM_ABI constexpr set_symmetric_difference_result<borrowed_iterator_t<_Range1>,
86 borrowed_iterator_t<_Range2>,
87 _OutIter>
88 operator()(
89 _Range1&& __range1,
90 _Range2&& __range2,
91 _OutIter __result,
92 _Comp __comp = {},
93 _Proj1 __proj1 = {},
94 _Proj2 __proj2 = {}) const {
95 auto __ret = std::__set_symmetric_difference(
96 ranges::begin(__range1),
97 ranges::end(__range1),
98 ranges::begin(__range2),
99 ranges::end(__range2),
100 std::move(__result),
101 ranges::__make_projected_comp(__comp, __proj1, __proj2));
102 return {std::move(__ret.__in1_), std::move(__ret.__in2_), std::move(__ret.__out_)};
103 }
104};
105
106} // namespace __set_symmetric_difference
107
108inline namespace __cpo {
109 inline constexpr auto set_symmetric_difference = __set_symmetric_difference::__fn{};
110} // namespace __cpo
111} // namespace ranges
112
113_LIBCPP_END_NAMESPACE_STD
114
115#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
116#endif // _LIBCPP___ALGORITHM_RANGES_SET_SYMMETRIC_DIFFERENCE_H
lib/libcxx/include/__algorithm/ranges_set_union.h created+120
......@@ -0,0 +1,120 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_SET_UNION_H
10#define _LIBCPP___ALGORITHM_RANGES_SET_UNION_H
11
12#include <__algorithm/in_in_out_result.h>
13#include <__algorithm/make_projected.h>
14#include <__algorithm/set_union.h>
15#include <__config>
16#include <__functional/identity.h>
17#include <__functional/invoke.h>
18#include <__functional/ranges_operations.h>
19#include <__iterator/concepts.h>
20#include <__iterator/iterator_traits.h>
21#include <__iterator/mergeable.h>
22#include <__iterator/projected.h>
23#include <__ranges/access.h>
24#include <__ranges/concepts.h>
25#include <__ranges/dangling.h>
26#include <__utility/forward.h>
27#include <__utility/move.h>
28
29#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
30# pragma GCC system_header
31#endif
32
33#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
34
35_LIBCPP_BEGIN_NAMESPACE_STD
36
37namespace ranges {
38
39template <class _InIter1, class _InIter2, class _OutIter>
40using set_union_result = in_in_out_result<_InIter1, _InIter2, _OutIter>;
41
42namespace __set_union {
43
44struct __fn {
45 template <
46 input_iterator _InIter1,
47 sentinel_for<_InIter1> _Sent1,
48 input_iterator _InIter2,
49 sentinel_for<_InIter2> _Sent2,
50 weakly_incrementable _OutIter,
51 class _Comp = ranges::less,
52 class _Proj1 = identity,
53 class _Proj2 = identity>
54 requires mergeable<_InIter1, _InIter2, _OutIter, _Comp, _Proj1, _Proj2>
55 _LIBCPP_HIDE_FROM_ABI constexpr set_union_result<_InIter1, _InIter2, _OutIter> operator()(
56 _InIter1 __first1,
57 _Sent1 __last1,
58 _InIter2 __first2,
59 _Sent2 __last2,
60 _OutIter __result,
61 _Comp __comp = {},
62 _Proj1 __proj1 = {},
63 _Proj2 __proj2 = {}) const {
64 auto __ret = std::__set_union(
65 std::move(__first1),
66 std::move(__last1),
67 std::move(__first2),
68 std::move(__last2),
69 std::move(__result),
70 ranges::__make_projected_comp(__comp, __proj1, __proj2));
71 return {std::move(__ret.__in1_), std::move(__ret.__in2_), std::move(__ret.__out_)};
72 }
73
74 template <
75 input_range _Range1,
76 input_range _Range2,
77 weakly_incrementable _OutIter,
78 class _Comp = ranges::less,
79 class _Proj1 = identity,
80 class _Proj2 = identity>
81 requires mergeable<
82 iterator_t<_Range1>,
83 iterator_t<_Range2>,
84 _OutIter,
85 _Comp,
86 _Proj1,
87 _Proj2>
88 _LIBCPP_HIDE_FROM_ABI constexpr set_union_result<borrowed_iterator_t<_Range1>,
89 borrowed_iterator_t<_Range2>,
90 _OutIter>
91 operator()(
92 _Range1&& __range1,
93 _Range2&& __range2,
94 _OutIter __result,
95 _Comp __comp = {},
96 _Proj1 __proj1 = {},
97 _Proj2 __proj2 = {}) const {
98 auto __ret = std::__set_union(
99 ranges::begin(__range1),
100 ranges::end(__range1),
101 ranges::begin(__range2),
102 ranges::end(__range2),
103 std::move(__result),
104 ranges::__make_projected_comp(__comp, __proj1, __proj2));
105 return {std::move(__ret.__in1_), std::move(__ret.__in2_), std::move(__ret.__out_)};
106 }
107};
108
109} // namespace __set_union
110
111inline namespace __cpo {
112 inline constexpr auto set_union = __set_union::__fn{};
113} // namespace __cpo
114} // namespace ranges
115
116_LIBCPP_END_NAMESPACE_STD
117
118#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
119
120#endif // _LIBCPP___ALGORITHM_RANGES_SET_UNION_H
lib/libcxx/include/__algorithm/ranges_shuffle.h created+103
......@@ -0,0 +1,103 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_SHUFFLE_H
10#define _LIBCPP___ALGORITHM_RANGES_SHUFFLE_H
11
12#include <__algorithm/iterator_operations.h>
13#include <__algorithm/shuffle.h>
14#include <__config>
15#include <__functional/invoke.h>
16#include <__functional/ranges_operations.h>
17#include <__iterator/concepts.h>
18#include <__iterator/iterator_traits.h>
19#include <__iterator/next.h>
20#include <__iterator/permutable.h>
21#include <__random/uniform_random_bit_generator.h>
22#include <__ranges/access.h>
23#include <__ranges/concepts.h>
24#include <__ranges/dangling.h>
25#include <__utility/forward.h>
26#include <__utility/move.h>
27#include <type_traits>
28
29#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
30# pragma GCC system_header
31#endif
32
33#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
34
35_LIBCPP_PUSH_MACROS
36#include <__undef_macros>
37
38_LIBCPP_BEGIN_NAMESPACE_STD
39
40namespace ranges {
41namespace __shuffle {
42
43struct __fn {
44 // `std::shuffle` is more constrained than `std::ranges::shuffle`. `std::ranges::shuffle` only requires the given
45 // generator to satisfy the `std::uniform_random_bit_generator` concept. `std::shuffle` requires the given
46 // generator to meet the uniform random bit generator requirements; these requirements include satisfying
47 // `std::uniform_random_bit_generator` and add a requirement for the generator to provide a nested `result_type`
48 // typedef (see `[rand.req.urng]`).
49 //
50 // To reuse the implementation from `std::shuffle`, make the given generator meet the classic requirements by wrapping
51 // it into an adaptor type that forwards all of its interface and adds the required typedef.
52 template <class _Gen>
53 class _ClassicGenAdaptor {
54 private:
55 // The generator is not required to be copyable or movable, so it has to be stored as a reference.
56 _Gen& __gen;
57
58 public:
59 using result_type = invoke_result_t<_Gen&>;
60
61 _LIBCPP_HIDE_FROM_ABI
62 static constexpr auto min() { return __uncvref_t<_Gen>::min(); }
63 _LIBCPP_HIDE_FROM_ABI
64 static constexpr auto max() { return __uncvref_t<_Gen>::max(); }
65
66 _LIBCPP_HIDE_FROM_ABI
67 constexpr explicit _ClassicGenAdaptor(_Gen& __g) : __gen(__g) {}
68
69 _LIBCPP_HIDE_FROM_ABI
70 constexpr auto operator()() const { return __gen(); }
71 };
72
73 template <random_access_iterator _Iter, sentinel_for<_Iter> _Sent, class _Gen>
74 requires permutable<_Iter> && uniform_random_bit_generator<remove_reference_t<_Gen>>
75 _LIBCPP_HIDE_FROM_ABI
76 _Iter operator()(_Iter __first, _Sent __last, _Gen&& __gen) const {
77 _ClassicGenAdaptor<_Gen> __adapted_gen(__gen);
78 return std::__shuffle<_RangeAlgPolicy>(std::move(__first), std::move(__last), __adapted_gen);
79 }
80
81 template<random_access_range _Range, class _Gen>
82 requires permutable<iterator_t<_Range>> && uniform_random_bit_generator<remove_reference_t<_Gen>>
83 _LIBCPP_HIDE_FROM_ABI
84 borrowed_iterator_t<_Range> operator()(_Range&& __range, _Gen&& __gen) const {
85 return (*this)(ranges::begin(__range), ranges::end(__range), std::forward<_Gen>(__gen));
86 }
87
88};
89
90} // namespace __shuffle
91
92inline namespace __cpo {
93 inline constexpr auto shuffle = __shuffle::__fn{};
94} // namespace __cpo
95} // namespace ranges
96
97_LIBCPP_END_NAMESPACE_STD
98
99_LIBCPP_POP_MACROS
100
101#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
102
103#endif // _LIBCPP___ALGORITHM_RANGES_SHUFFLE_H
lib/libcxx/include/__algorithm/ranges_sort.h created+79
......@@ -0,0 +1,79 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_SORT_H
10#define _LIBCPP___ALGORITHM_RANGES_SORT_H
11
12#include <__algorithm/iterator_operations.h>
13#include <__algorithm/make_projected.h>
14#include <__algorithm/sort.h>
15#include <__config>
16#include <__functional/identity.h>
17#include <__functional/invoke.h>
18#include <__functional/ranges_operations.h>
19#include <__iterator/concepts.h>
20#include <__iterator/iterator_traits.h>
21#include <__iterator/next.h>
22#include <__iterator/projected.h>
23#include <__iterator/sortable.h>
24#include <__ranges/access.h>
25#include <__ranges/concepts.h>
26#include <__ranges/dangling.h>
27#include <__utility/forward.h>
28#include <__utility/move.h>
29
30#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
31# pragma GCC system_header
32#endif
33
34#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
35
36_LIBCPP_BEGIN_NAMESPACE_STD
37
38namespace ranges {
39namespace __sort {
40
41struct __fn {
42 template <class _Iter, class _Sent, class _Comp, class _Proj>
43 _LIBCPP_HIDE_FROM_ABI constexpr static
44 _Iter __sort_fn_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) {
45 auto __last_iter = ranges::next(__first, __last);
46
47 auto&& __projected_comp = std::__make_projected(__comp, __proj);
48 std::__sort_impl<_RangeAlgPolicy>(std::move(__first), __last_iter, __projected_comp);
49
50 return __last_iter;
51 }
52
53 template <random_access_iterator _Iter, sentinel_for<_Iter> _Sent, class _Comp = ranges::less, class _Proj = identity>
54 requires sortable<_Iter, _Comp, _Proj>
55 _LIBCPP_HIDE_FROM_ABI constexpr
56 _Iter operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const {
57 return __sort_fn_impl(std::move(__first), std::move(__last), __comp, __proj);
58 }
59
60 template <random_access_range _Range, class _Comp = ranges::less, class _Proj = identity>
61 requires sortable<iterator_t<_Range>, _Comp, _Proj>
62 _LIBCPP_HIDE_FROM_ABI constexpr
63 borrowed_iterator_t<_Range> operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {}) const {
64 return __sort_fn_impl(ranges::begin(__r), ranges::end(__r), __comp, __proj);
65 }
66};
67
68} // namespace __sort
69
70inline namespace __cpo {
71 inline constexpr auto sort = __sort::__fn{};
72} // namespace __cpo
73} // namespace ranges
74
75_LIBCPP_END_NAMESPACE_STD
76
77#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
78
79#endif // _LIBCPP___ALGORITHM_RANGES_SORT_H
lib/libcxx/include/__algorithm/ranges_sort_heap.h created+80
......@@ -0,0 +1,80 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_SORT_HEAP_H
10#define _LIBCPP___ALGORITHM_RANGES_SORT_HEAP_H
11
12#include <__algorithm/iterator_operations.h>
13#include <__algorithm/make_projected.h>
14#include <__algorithm/sort_heap.h>
15#include <__concepts/same_as.h>
16#include <__config>
17#include <__functional/identity.h>
18#include <__functional/invoke.h>
19#include <__functional/ranges_operations.h>
20#include <__iterator/concepts.h>
21#include <__iterator/iterator_traits.h>
22#include <__iterator/next.h>
23#include <__iterator/projected.h>
24#include <__iterator/sortable.h>
25#include <__ranges/access.h>
26#include <__ranges/concepts.h>
27#include <__ranges/dangling.h>
28#include <__utility/forward.h>
29#include <__utility/move.h>
30
31#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
32# pragma GCC system_header
33#endif
34
35#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
36
37_LIBCPP_BEGIN_NAMESPACE_STD
38
39namespace ranges {
40namespace __sort_heap {
41
42struct __fn {
43 template <class _Iter, class _Sent, class _Comp, class _Proj>
44 _LIBCPP_HIDE_FROM_ABI constexpr static
45 _Iter __sort_heap_fn_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) {
46 auto __last_iter = ranges::next(__first, __last);
47
48 auto&& __projected_comp = std::__make_projected(__comp, __proj);
49 std::__sort_heap<_RangeAlgPolicy>(std::move(__first), __last_iter, __projected_comp);
50
51 return __last_iter;
52 }
53
54 template <random_access_iterator _Iter, sentinel_for<_Iter> _Sent, class _Comp = ranges::less, class _Proj = identity>
55 requires sortable<_Iter, _Comp, _Proj>
56 _LIBCPP_HIDE_FROM_ABI constexpr
57 _Iter operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const {
58 return __sort_heap_fn_impl(std::move(__first), std::move(__last), __comp, __proj);
59 }
60
61 template <random_access_range _Range, class _Comp = ranges::less, class _Proj = identity>
62 requires sortable<iterator_t<_Range>, _Comp, _Proj>
63 _LIBCPP_HIDE_FROM_ABI constexpr
64 borrowed_iterator_t<_Range> operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {}) const {
65 return __sort_heap_fn_impl(ranges::begin(__r), ranges::end(__r), __comp, __proj);
66 }
67};
68
69} // namespace __sort_heap
70
71inline namespace __cpo {
72 inline constexpr auto sort_heap = __sort_heap::__fn{};
73} // namespace __cpo
74} // namespace ranges
75
76_LIBCPP_END_NAMESPACE_STD
77
78#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
79
80#endif // _LIBCPP___ALGORITHM_RANGES_SORT_HEAP_H
lib/libcxx/include/__algorithm/ranges_stable_partition.h created+88
......@@ -0,0 +1,88 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_STABLE_PARTITION_H
10#define _LIBCPP___ALGORITHM_RANGES_STABLE_PARTITION_H
11
12#include <__algorithm/iterator_operations.h>
13#include <__algorithm/make_projected.h>
14#include <__algorithm/ranges_iterator_concept.h>
15#include <__algorithm/stable_partition.h>
16#include <__config>
17#include <__functional/identity.h>
18#include <__functional/invoke.h>
19#include <__functional/ranges_operations.h>
20#include <__iterator/concepts.h>
21#include <__iterator/iterator_traits.h>
22#include <__iterator/next.h>
23#include <__iterator/permutable.h>
24#include <__iterator/projected.h>
25#include <__ranges/access.h>
26#include <__ranges/concepts.h>
27#include <__ranges/dangling.h>
28#include <__ranges/subrange.h>
29#include <__utility/forward.h>
30#include <__utility/move.h>
31#include <type_traits>
32
33#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
34# pragma GCC system_header
35#endif
36
37#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
38
39_LIBCPP_BEGIN_NAMESPACE_STD
40
41namespace ranges {
42namespace __stable_partition {
43
44struct __fn {
45
46 template <class _Iter, class _Sent, class _Proj, class _Pred>
47 _LIBCPP_HIDE_FROM_ABI static
48 subrange<__uncvref_t<_Iter>> __stable_partition_fn_impl(
49 _Iter&& __first, _Sent&& __last, _Pred&& __pred, _Proj&& __proj) {
50 auto __last_iter = ranges::next(__first, __last);
51
52 auto&& __projected_pred = std::__make_projected(__pred, __proj);
53 auto __result = std::__stable_partition<_RangeAlgPolicy>(
54 std::move(__first), __last_iter, __projected_pred, __iterator_concept<_Iter>());
55
56 return {std::move(__result), std::move(__last_iter)};
57 }
58
59 template <bidirectional_iterator _Iter, sentinel_for<_Iter> _Sent, class _Proj = identity,
60 indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
61 requires permutable<_Iter>
62 _LIBCPP_HIDE_FROM_ABI
63 subrange<_Iter> operator()(_Iter __first, _Sent __last, _Pred __pred, _Proj __proj = {}) const {
64 return __stable_partition_fn_impl(__first, __last, __pred, __proj);
65 }
66
67 template <bidirectional_range _Range, class _Proj = identity,
68 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>> _Pred>
69 requires permutable<iterator_t<_Range>>
70 _LIBCPP_HIDE_FROM_ABI
71 borrowed_subrange_t<_Range> operator()(_Range&& __range, _Pred __pred, _Proj __proj = {}) const {
72 return __stable_partition_fn_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj);
73 }
74
75};
76
77} // namespace __stable_partition
78
79inline namespace __cpo {
80 inline constexpr auto stable_partition = __stable_partition::__fn{};
81} // namespace __cpo
82} // namespace ranges
83
84_LIBCPP_END_NAMESPACE_STD
85
86#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
87
88#endif // _LIBCPP___ALGORITHM_RANGES_STABLE_PARTITION_H
lib/libcxx/include/__algorithm/ranges_stable_sort.h created+79
......@@ -0,0 +1,79 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_STABLE_SORT_H
10#define _LIBCPP___ALGORITHM_RANGES_STABLE_SORT_H
11
12#include <__algorithm/iterator_operations.h>
13#include <__algorithm/make_projected.h>
14#include <__algorithm/stable_sort.h>
15#include <__config>
16#include <__functional/identity.h>
17#include <__functional/invoke.h>
18#include <__functional/ranges_operations.h>
19#include <__iterator/concepts.h>
20#include <__iterator/iterator_traits.h>
21#include <__iterator/next.h>
22#include <__iterator/projected.h>
23#include <__iterator/sortable.h>
24#include <__ranges/access.h>
25#include <__ranges/concepts.h>
26#include <__ranges/dangling.h>
27#include <__utility/forward.h>
28#include <__utility/move.h>
29
30#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
31# pragma GCC system_header
32#endif
33
34#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
35
36_LIBCPP_BEGIN_NAMESPACE_STD
37
38namespace ranges {
39namespace __stable_sort {
40
41struct __fn {
42 template <class _Iter, class _Sent, class _Comp, class _Proj>
43 _LIBCPP_HIDE_FROM_ABI
44 static _Iter __stable_sort_fn_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) {
45 auto __last_iter = ranges::next(__first, __last);
46
47 auto&& __projected_comp = std::__make_projected(__comp, __proj);
48 std::__stable_sort_impl<_RangeAlgPolicy>(std::move(__first), __last_iter, __projected_comp);
49
50 return __last_iter;
51 }
52
53 template <random_access_iterator _Iter, sentinel_for<_Iter> _Sent, class _Comp = ranges::less, class _Proj = identity>
54 requires sortable<_Iter, _Comp, _Proj>
55 _LIBCPP_HIDE_FROM_ABI
56 _Iter operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const {
57 return __stable_sort_fn_impl(std::move(__first), std::move(__last), __comp, __proj);
58 }
59
60 template <random_access_range _Range, class _Comp = ranges::less, class _Proj = identity>
61 requires sortable<iterator_t<_Range>, _Comp, _Proj>
62 _LIBCPP_HIDE_FROM_ABI
63 borrowed_iterator_t<_Range> operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {}) const {
64 return __stable_sort_fn_impl(ranges::begin(__r), ranges::end(__r), __comp, __proj);
65 }
66};
67
68} // namespace __stable_sort
69
70inline namespace __cpo {
71 inline constexpr auto stable_sort = __stable_sort::__fn{};
72} // namespace __cpo
73} // namespace ranges
74
75_LIBCPP_END_NAMESPACE_STD
76
77#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
78
79#endif // _LIBCPP___ALGORITHM_RANGES_STABLE_SORT_H
lib/libcxx/include/__algorithm/ranges_swap_ranges.h created+69
......@@ -0,0 +1,69 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_SWAP_RANGES_H
10#define _LIBCPP___ALGORITHM_RANGES_SWAP_RANGES_H
11
12#include <__algorithm/in_in_result.h>
13#include <__config>
14#include <__iterator/concepts.h>
15#include <__iterator/iter_swap.h>
16#include <__ranges/access.h>
17#include <__ranges/concepts.h>
18#include <__ranges/dangling.h>
19#include <__utility/move.h>
20
21#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22# pragma GCC system_header
23#endif
24
25#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
26
27_LIBCPP_BEGIN_NAMESPACE_STD
28
29namespace ranges {
30
31template <class _I1, class _I2>
32using swap_ranges_result = in_in_result<_I1, _I2>;
33
34namespace __swap_ranges {
35struct __fn {
36 template <input_iterator _I1, sentinel_for<_I1> _S1,
37 input_iterator _I2, sentinel_for<_I2> _S2>
38 requires indirectly_swappable<_I1, _I2>
39 _LIBCPP_HIDE_FROM_ABI constexpr swap_ranges_result<_I1, _I2>
40 operator()(_I1 __first1, _S1 __last1, _I2 __first2, _S2 __last2) const {
41 while (__first1 != __last1 && __first2 != __last2) {
42 ranges::iter_swap(__first1, __first2);
43 ++__first1;
44 ++__first2;
45 }
46 return {_VSTD::move(__first1), _VSTD::move(__first2)};
47 }
48
49 template <input_range _R1, input_range _R2>
50 requires indirectly_swappable<iterator_t<_R1>, iterator_t<_R2>>
51 _LIBCPP_HIDE_FROM_ABI constexpr
52 swap_ranges_result<borrowed_iterator_t<_R1>, borrowed_iterator_t<_R2>>
53 operator()(_R1&& __r1, _R2&& __r2) const {
54 return operator()(ranges::begin(__r1), ranges::end(__r1),
55 ranges::begin(__r2), ranges::end(__r2));
56 }
57};
58} // namespace __swap_ranges
59
60inline namespace __cpo {
61 inline constexpr auto swap_ranges = __swap_ranges::__fn{};
62} // namespace __cpo
63} // namespace ranges
64
65_LIBCPP_END_NAMESPACE_STD
66
67#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
68
69#endif // _LIBCPP___ALGORITHM_RANGES_SWAP_RANGES_H
lib/libcxx/include/__algorithm/ranges_transform.h created+170
......@@ -0,0 +1,170 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_TRANSFORM_H
10#define _LIBCPP___ALGORITHM_RANGES_TRANSFORM_H
11
12#include <__algorithm/in_in_out_result.h>
13#include <__algorithm/in_out_result.h>
14#include <__concepts/constructible.h>
15#include <__config>
16#include <__functional/identity.h>
17#include <__functional/invoke.h>
18#include <__iterator/concepts.h>
19#include <__iterator/projected.h>
20#include <__ranges/access.h>
21#include <__ranges/concepts.h>
22#include <__ranges/dangling.h>
23#include <__utility/move.h>
24
25#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
26# pragma GCC system_header
27#endif
28
29#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
30
31_LIBCPP_BEGIN_NAMESPACE_STD
32
33namespace ranges {
34
35template <class _Ip, class _Op>
36using unary_transform_result = in_out_result<_Ip, _Op>;
37
38template <class _I1, class _I2, class _O1>
39using binary_transform_result = in_in_out_result<_I1, _I2, _O1>;
40
41namespace __transform {
42struct __fn {
43private:
44 template <class _InIter, class _Sent,
45 class _OutIter,
46 class _Func,
47 class _Proj>
48 _LIBCPP_HIDE_FROM_ABI static constexpr
49 unary_transform_result<_InIter, _OutIter> __unary(_InIter __first, _Sent __last,
50 _OutIter __result,
51 _Func& __operation,
52 _Proj& __projection) {
53 while (__first != __last) {
54 *__result = std::invoke(__operation, std::invoke(__projection, *__first));
55 ++__first;
56 ++__result;
57 }
58
59 return {std::move(__first), std::move(__result)};
60 }
61
62 template <class _InIter1, class _Sent1,
63 class _InIter2, class _Sent2,
64 class _OutIter,
65 class _Func,
66 class _Proj1,
67 class _Proj2>
68 _LIBCPP_HIDE_FROM_ABI static constexpr binary_transform_result<_InIter1, _InIter2, _OutIter>
69 __binary(_InIter1 __first1, _Sent1 __last1,
70 _InIter2 __first2, _Sent2 __last2,
71 _OutIter __result,
72 _Func& __binary_operation,
73 _Proj1& __projection1,
74 _Proj2& __projection2) {
75 while (__first1 != __last1 && __first2 != __last2) {
76 *__result = std::invoke(__binary_operation, std::invoke(__projection1, *__first1),
77 std::invoke(__projection2, *__first2));
78 ++__first1;
79 ++__first2;
80 ++__result;
81 }
82 return {std::move(__first1), std::move(__first2), std::move(__result)};
83 }
84public:
85 template <input_iterator _InIter, sentinel_for<_InIter> _Sent,
86 weakly_incrementable _OutIter,
87 copy_constructible _Func,
88 class _Proj = identity>
89 requires indirectly_writable<_OutIter, indirect_result_t<_Func&, projected<_InIter, _Proj>>>
90 _LIBCPP_HIDE_FROM_ABI constexpr
91 unary_transform_result<_InIter, _OutIter> operator()(_InIter __first, _Sent __last,
92 _OutIter __result,
93 _Func __operation,
94 _Proj __proj = {}) const {
95 return __unary(std::move(__first), std::move(__last), std::move(__result), __operation, __proj);
96 }
97
98 template <input_range _Range,
99 weakly_incrementable _OutIter,
100 copy_constructible _Func,
101 class _Proj = identity>
102 requires indirectly_writable<_OutIter, indirect_result_t<_Func, projected<iterator_t<_Range>, _Proj>>>
103 _LIBCPP_HIDE_FROM_ABI constexpr
104 unary_transform_result<borrowed_iterator_t<_Range>, _OutIter> operator()(_Range&& __range,
105 _OutIter __result,
106 _Func __operation,
107 _Proj __projection = {}) const {
108 return __unary(ranges::begin(__range), ranges::end(__range), std::move(__result), __operation, __projection);
109 }
110
111 template <input_iterator _InIter1, sentinel_for<_InIter1> _Sent1,
112 input_iterator _InIter2, sentinel_for<_InIter2> _Sent2,
113 weakly_incrementable _OutIter,
114 copy_constructible _Func,
115 class _Proj1 = identity,
116 class _Proj2 = identity>
117 requires indirectly_writable<_OutIter, indirect_result_t<_Func&, projected<_InIter1, _Proj1>,
118 projected<_InIter2, _Proj2>>>
119 _LIBCPP_HIDE_FROM_ABI constexpr
120 binary_transform_result<_InIter1, _InIter2, _OutIter> operator()(_InIter1 __first1, _Sent1 __last1,
121 _InIter2 __first2, _Sent2 __last2,
122 _OutIter __result,
123 _Func __binary_operation,
124 _Proj1 __projection1 = {},
125 _Proj2 __projection2 = {}) const {
126 return __binary(std::move(__first1), std::move(__last1),
127 std::move(__first2), std::move(__last2),
128 std::move(__result),
129 __binary_operation,
130 __projection1,
131 __projection2);
132 }
133
134 template <input_range _Range1,
135 input_range _Range2,
136 weakly_incrementable _OutIter,
137 copy_constructible _Func,
138 class _Proj1 = identity,
139 class _Proj2 = identity>
140 requires indirectly_writable<_OutIter, indirect_result_t<_Func&, projected<iterator_t<_Range1>, _Proj1>,
141 projected<iterator_t<_Range2>, _Proj2>>>
142 _LIBCPP_HIDE_FROM_ABI constexpr
143 binary_transform_result<borrowed_iterator_t<_Range1>, borrowed_iterator_t<_Range2>, _OutIter>
144 operator()(_Range1&& __range1,
145 _Range2&& __range2,
146 _OutIter __result,
147 _Func __binary_operation,
148 _Proj1 __projection1 = {},
149 _Proj2 __projection2 = {}) const {
150 return __binary(ranges::begin(__range1), ranges::end(__range1),
151 ranges::begin(__range2), ranges::end(__range2),
152 std::move(__result),
153 __binary_operation,
154 __projection1,
155 __projection2);
156 }
157
158};
159} // namespace __transform
160
161inline namespace __cpo {
162 inline constexpr auto transform = __transform::__fn{};
163} // namespace __cpo
164} // namespace ranges
165
166_LIBCPP_END_NAMESPACE_STD
167
168#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
169
170#endif // _LIBCPP___ALGORITHM_RANGES_TRANSFORM_H
lib/libcxx/include/__algorithm/ranges_unique.h created+78
......@@ -0,0 +1,78 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_UNIQUE_H
10#define _LIBCPP___ALGORITHM_RANGES_UNIQUE_H
11
12#include <__algorithm/iterator_operations.h>
13#include <__algorithm/make_projected.h>
14#include <__algorithm/unique.h>
15#include <__config>
16#include <__functional/identity.h>
17#include <__functional/invoke.h>
18#include <__functional/ranges_operations.h>
19#include <__iterator/concepts.h>
20#include <__iterator/iterator_traits.h>
21#include <__iterator/permutable.h>
22#include <__iterator/projected.h>
23#include <__ranges/access.h>
24#include <__ranges/concepts.h>
25#include <__ranges/dangling.h>
26#include <__ranges/subrange.h>
27#include <__utility/forward.h>
28#include <__utility/move.h>
29
30#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
31# pragma GCC system_header
32#endif
33
34#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
35
36_LIBCPP_BEGIN_NAMESPACE_STD
37
38namespace ranges {
39namespace __unique {
40
41 struct __fn {
42 template <
43 permutable _Iter,
44 sentinel_for<_Iter> _Sent,
45 class _Proj = identity,
46 indirect_equivalence_relation<projected<_Iter, _Proj>> _Comp = ranges::equal_to>
47 _LIBCPP_HIDE_FROM_ABI constexpr subrange<_Iter>
48 operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const {
49 auto __ret = std::__unique<_RangeAlgPolicy>(
50 std::move(__first), std::move(__last), std::__make_projected(__comp, __proj));
51 return {std::move(__ret.first), std::move(__ret.second)};
52 }
53
54 template <
55 forward_range _Range,
56 class _Proj = identity,
57 indirect_equivalence_relation<projected<iterator_t<_Range>, _Proj>> _Comp = ranges::equal_to>
58 requires permutable<iterator_t<_Range>>
59 _LIBCPP_HIDE_FROM_ABI constexpr borrowed_subrange_t<_Range>
60 operator()(_Range&& __range, _Comp __comp = {}, _Proj __proj = {}) const {
61 auto __ret = std::__unique<_RangeAlgPolicy>(
62 ranges::begin(__range), ranges::end(__range), std::__make_projected(__comp, __proj));
63 return {std::move(__ret.first), std::move(__ret.second)};
64 }
65 };
66
67} // namespace __unique
68
69inline namespace __cpo {
70 inline constexpr auto unique = __unique::__fn{};
71} // namespace __cpo
72} // namespace ranges
73
74_LIBCPP_END_NAMESPACE_STD
75
76#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
77
78#endif // _LIBCPP___ALGORITHM_RANGES_UNIQUE_H
lib/libcxx/include/__algorithm/ranges_unique_copy.h created+115
......@@ -0,0 +1,115 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_UNIQUE_COPY_H
10#define _LIBCPP___ALGORITHM_RANGES_UNIQUE_COPY_H
11
12#include <__algorithm/in_out_result.h>
13#include <__algorithm/iterator_operations.h>
14#include <__algorithm/make_projected.h>
15#include <__algorithm/unique_copy.h>
16#include <__concepts/same_as.h>
17#include <__config>
18#include <__functional/identity.h>
19#include <__functional/invoke.h>
20#include <__functional/ranges_operations.h>
21#include <__iterator/concepts.h>
22#include <__iterator/iterator_traits.h>
23#include <__iterator/projected.h>
24#include <__iterator/readable_traits.h>
25#include <__ranges/access.h>
26#include <__ranges/concepts.h>
27#include <__ranges/dangling.h>
28#include <__utility/forward.h>
29#include <__utility/move.h>
30
31#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
32# pragma GCC system_header
33#endif
34
35#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
36
37_LIBCPP_BEGIN_NAMESPACE_STD
38
39namespace ranges {
40
41template <class _InIter, class _OutIter>
42using unique_copy_result = in_out_result<_InIter, _OutIter>;
43
44namespace __unique_copy {
45
46template <class _InIter, class _OutIter>
47concept __can_reread_from_output = (input_iterator<_OutIter> && same_as<iter_value_t<_InIter>, iter_value_t<_OutIter>>);
48
49struct __fn {
50 template <class _InIter, class _OutIter>
51 static consteval auto __get_algo_tag() {
52 if constexpr (forward_iterator<_InIter>) {
53 return __unique_copy_tags::__reread_from_input_tag{};
54 } else if constexpr (__can_reread_from_output<_InIter, _OutIter>) {
55 return __unique_copy_tags::__reread_from_output_tag{};
56 } else if constexpr (indirectly_copyable_storable<_InIter, _OutIter>) {
57 return __unique_copy_tags::__read_from_tmp_value_tag{};
58 }
59 }
60
61 template <class _InIter, class _OutIter>
62 using __algo_tag_t = decltype(__get_algo_tag<_InIter, _OutIter>());
63
64 template <input_iterator _InIter,
65 sentinel_for<_InIter> _Sent,
66 weakly_incrementable _OutIter,
67 class _Proj = identity,
68 indirect_equivalence_relation<projected<_InIter, _Proj>> _Comp = ranges::equal_to>
69 requires indirectly_copyable<_InIter, _OutIter> &&
70 (forward_iterator<_InIter> ||
71 (input_iterator<_OutIter> && same_as<iter_value_t<_InIter>, iter_value_t<_OutIter>>) ||
72 indirectly_copyable_storable<_InIter, _OutIter>)
73 _LIBCPP_HIDE_FROM_ABI constexpr unique_copy_result<_InIter, _OutIter>
74 operator()(_InIter __first, _Sent __last, _OutIter __result, _Comp __comp = {}, _Proj __proj = {}) const {
75 auto __ret = std::__unique_copy<_RangeAlgPolicy>(
76 std::move(__first),
77 std::move(__last),
78 std::move(__result),
79 std::__make_projected(__comp, __proj),
80 __algo_tag_t<_InIter, _OutIter>());
81 return {std::move(__ret.first), std::move(__ret.second)};
82 }
83
84 template <input_range _Range,
85 weakly_incrementable _OutIter,
86 class _Proj = identity,
87 indirect_equivalence_relation<projected<iterator_t<_Range>, _Proj>> _Comp = ranges::equal_to>
88 requires indirectly_copyable<iterator_t<_Range>, _OutIter> &&
89 (forward_iterator<iterator_t<_Range>> ||
90 (input_iterator<_OutIter> && same_as<range_value_t<_Range>, iter_value_t<_OutIter>>) ||
91 indirectly_copyable_storable<iterator_t<_Range>, _OutIter>)
92 _LIBCPP_HIDE_FROM_ABI constexpr unique_copy_result<borrowed_iterator_t<_Range>, _OutIter>
93 operator()(_Range&& __range, _OutIter __result, _Comp __comp = {}, _Proj __proj = {}) const {
94 auto __ret = std::__unique_copy<_RangeAlgPolicy>(
95 ranges::begin(__range),
96 ranges::end(__range),
97 std::move(__result),
98 std::__make_projected(__comp, __proj),
99 __algo_tag_t<iterator_t<_Range>, _OutIter>());
100 return {std::move(__ret.first), std::move(__ret.second)};
101 }
102};
103
104} // namespace __unique_copy
105
106inline namespace __cpo {
107inline constexpr auto unique_copy = __unique_copy::__fn{};
108} // namespace __cpo
109} // namespace ranges
110
111_LIBCPP_END_NAMESPACE_STD
112
113#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
114
115#endif // _LIBCPP___ALGORITHM_RANGES_UNIQUE_COPY_H
lib/libcxx/include/__algorithm/ranges_upper_bound.h created+75
......@@ -0,0 +1,75 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_UPPER_BOUND_H
10#define _LIBCPP___ALGORITHM_RANGES_UPPER_BOUND_H
11
12#include <__algorithm/iterator_operations.h>
13#include <__algorithm/lower_bound.h>
14#include <__config>
15#include <__functional/identity.h>
16#include <__functional/invoke.h>
17#include <__functional/ranges_operations.h>
18#include <__iterator/concepts.h>
19#include <__iterator/projected.h>
20#include <__ranges/access.h>
21#include <__ranges/concepts.h>
22#include <__ranges/dangling.h>
23
24#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
25# pragma GCC system_header
26#endif
27
28#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
29
30_LIBCPP_BEGIN_NAMESPACE_STD
31
32namespace ranges {
33namespace __upper_bound {
34struct __fn {
35 template <forward_iterator _Iter, sentinel_for<_Iter> _Sent, class _Type, class _Proj = identity,
36 indirect_strict_weak_order<const _Type*, projected<_Iter, _Proj>> _Comp = ranges::less>
37 _LIBCPP_HIDE_FROM_ABI constexpr
38 _Iter operator()(_Iter __first, _Sent __last, const _Type& __value, _Comp __comp = {}, _Proj __proj = {}) const {
39 auto __comp_lhs_rhs_swapped = [&](const auto& __lhs, const auto& __rhs) {
40 return !std::invoke(__comp, __rhs, __lhs);
41 };
42
43 return std::__lower_bound_impl<_RangeAlgPolicy>(__first, __last, __value, __comp_lhs_rhs_swapped, __proj);
44 }
45
46 template <forward_range _Range, class _Type, class _Proj = identity,
47 indirect_strict_weak_order<const _Type*, projected<iterator_t<_Range>, _Proj>> _Comp = ranges::less>
48 _LIBCPP_HIDE_FROM_ABI constexpr
49 borrowed_iterator_t<_Range> operator()(_Range&& __r,
50 const _Type& __value,
51 _Comp __comp = {},
52 _Proj __proj = {}) const {
53 auto __comp_lhs_rhs_swapped = [&](const auto& __lhs, const auto& __rhs) {
54 return !std::invoke(__comp, __rhs, __lhs);
55 };
56
57 return std::__lower_bound_impl<_RangeAlgPolicy>(ranges::begin(__r),
58 ranges::end(__r),
59 __value,
60 __comp_lhs_rhs_swapped,
61 __proj);
62 }
63};
64} // namespace __upper_bound
65
66inline namespace __cpo {
67 inline constexpr auto upper_bound = __upper_bound::__fn{};
68} // namespace __cpo
69} // namespace ranges
70
71_LIBCPP_END_NAMESPACE_STD
72
73#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
74
75#endif // _LIBCPP___ALGORITHM_RANGES_UPPER_BOUND_H
lib/libcxx/include/__algorithm/remove.h+4-4
......@@ -15,22 +15,22 @@
1515#include <__utility/move.h>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
2222
2323template <class _ForwardIterator, class _Tp>
2424_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
25remove(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_)
25remove(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
2626{
27 __first = _VSTD::find(__first, __last, __value_);
27 __first = _VSTD::find(__first, __last, __value);
2828 if (__first != __last)
2929 {
3030 _ForwardIterator __i = __first;
3131 while (++__i != __last)
3232 {
33 if (!(*__i == __value_))
33 if (!(*__i == __value))
3434 {
3535 *__first = _VSTD::move(*__i);
3636 ++__first;
lib/libcxx/include/__algorithm/remove_copy.h+3-3
......@@ -12,7 +12,7 @@
1212#include <__config>
1313
1414#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15#pragma GCC system_header
15# pragma GCC system_header
1616#endif
1717
1818_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -20,11 +20,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2020template <class _InputIterator, class _OutputIterator, class _Tp>
2121inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
2222_OutputIterator
23remove_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, const _Tp& __value_)
23remove_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, const _Tp& __value)
2424{
2525 for (; __first != __last; ++__first)
2626 {
27 if (!(*__first == __value_))
27 if (!(*__first == __value))
2828 {
2929 *__result = *__first;
3030 ++__result;
lib/libcxx/include/__algorithm/remove_copy_if.h+1-1
......@@ -12,7 +12,7 @@
1212#include <__config>
1313
1414#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15#pragma GCC system_header
15# pragma GCC system_header
1616#endif
1717
1818_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/remove_if.h+2-2
......@@ -11,10 +11,10 @@
1111
1212#include <__algorithm/find_if.h>
1313#include <__config>
14#include <utility>
14#include <__utility/move.h>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
17# pragma GCC system_header
1818#endif
1919
2020_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/replace.h+1-1
......@@ -12,7 +12,7 @@
1212#include <__config>
1313
1414#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15#pragma GCC system_header
15# pragma GCC system_header
1616#endif
1717
1818_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/replace_copy.h+1-1
......@@ -12,7 +12,7 @@
1212#include <__config>
1313
1414#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15#pragma GCC system_header
15# pragma GCC system_header
1616#endif
1717
1818_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/replace_copy_if.h+1-1
......@@ -12,7 +12,7 @@
1212#include <__config>
1313
1414#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15#pragma GCC system_header
15# pragma GCC system_header
1616#endif
1717
1818_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/replace_if.h+1-1
......@@ -12,7 +12,7 @@
1212#include <__config>
1313
1414#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15#pragma GCC system_header
15# pragma GCC system_header
1616#endif
1717
1818_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/reverse.h+1-1
......@@ -14,7 +14,7 @@
1414#include <__iterator/iterator_traits.h>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
17# pragma GCC system_header
1818#endif
1919
2020_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/reverse_copy.h+1-1
......@@ -12,7 +12,7 @@
1212#include <__config>
1313
1414#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15#pragma GCC system_header
15# pragma GCC system_header
1616#endif
1717
1818_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/rotate.h+52-38
......@@ -9,6 +9,7 @@
99#ifndef _LIBCPP___ALGORITHM_ROTATE_H
1010#define _LIBCPP___ALGORITHM_ROTATE_H
1111
12#include <__algorithm/iterator_operations.h>
1213#include <__algorithm/move.h>
1314#include <__algorithm/move_backward.h>
1415#include <__algorithm/swap_ranges.h>
......@@ -16,46 +17,50 @@
1617#include <__iterator/iterator_traits.h>
1718#include <__iterator/next.h>
1819#include <__iterator/prev.h>
20#include <__utility/move.h>
1921#include <__utility/swap.h>
20#include <iterator>
22#include <type_traits>
2123
2224#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23#pragma GCC system_header
25# pragma GCC system_header
2426#endif
2527
2628_LIBCPP_BEGIN_NAMESPACE_STD
2729
28template <class _ForwardIterator>
30template <class _AlgPolicy, class _ForwardIterator>
2931_LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator
3032__rotate_left(_ForwardIterator __first, _ForwardIterator __last)
3133{
3234 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
33 value_type __tmp = _VSTD::move(*__first);
35 value_type __tmp = _IterOps<_AlgPolicy>::__iter_move(__first);
36 // TODO(ranges): pass `_AlgPolicy` to `move`.
3437 _ForwardIterator __lm1 = _VSTD::move(_VSTD::next(__first), __last, __first);
3538 *__lm1 = _VSTD::move(__tmp);
3639 return __lm1;
3740}
3841
39template <class _BidirectionalIterator>
42template <class _AlgPolicy, class _BidirectionalIterator>
4043_LIBCPP_CONSTEXPR_AFTER_CXX11 _BidirectionalIterator
4144__rotate_right(_BidirectionalIterator __first, _BidirectionalIterator __last)
4245{
4346 typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
47 // TODO(ranges): pass `_AlgPolicy` to `prev`.
4448 _BidirectionalIterator __lm1 = _VSTD::prev(__last);
45 value_type __tmp = _VSTD::move(*__lm1);
49 value_type __tmp = _IterOps<_AlgPolicy>::__iter_move(__lm1);
50 // TODO(ranges): pass `_AlgPolicy` to `move_backward`.
4651 _BidirectionalIterator __fp1 = _VSTD::move_backward(__first, __lm1, __last);
4752 *__first = _VSTD::move(__tmp);
4853 return __fp1;
4954}
5055
51template <class _ForwardIterator>
56template <class _AlgPolicy, class _ForwardIterator>
5257_LIBCPP_CONSTEXPR_AFTER_CXX14 _ForwardIterator
5358__rotate_forward(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last)
5459{
5560 _ForwardIterator __i = __middle;
5661 while (true)
5762 {
58 swap(*__first, *__i);
63 _IterOps<_AlgPolicy>::iter_swap(__first, __i);
5964 ++__first;
6065 if (++__i == __last)
6166 break;
......@@ -68,7 +73,7 @@ __rotate_forward(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIt
6873 __i = __middle;
6974 while (true)
7075 {
71 swap(*__first, *__i);
76 _IterOps<_AlgPolicy>::iter_swap(__first, __i);
7277 ++__first;
7378 if (++__i == __last)
7479 {
......@@ -97,7 +102,7 @@ __algo_gcd(_Integral __x, _Integral __y)
97102 return __x;
98103}
99104
100template<typename _RandomAccessIterator>
105template <class _AlgPolicy, typename _RandomAccessIterator>
101106_LIBCPP_CONSTEXPR_AFTER_CXX14 _RandomAccessIterator
102107__rotate_gcd(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last)
103108{
......@@ -108,18 +113,19 @@ __rotate_gcd(_RandomAccessIterator __first, _RandomAccessIterator __middle, _Ran
108113 const difference_type __m2 = __last - __middle;
109114 if (__m1 == __m2)
110115 {
116 // TODO(ranges): pass `_AlgPolicy` to `swap_ranges`.
111117 _VSTD::swap_ranges(__first, __middle, __middle);
112118 return __middle;
113119 }
114120 const difference_type __g = _VSTD::__algo_gcd(__m1, __m2);
115121 for (_RandomAccessIterator __p = __first + __g; __p != __first;)
116122 {
117 value_type __t(_VSTD::move(*--__p));
123 value_type __t(_IterOps<_AlgPolicy>::__iter_move(--__p));
118124 _RandomAccessIterator __p1 = __p;
119125 _RandomAccessIterator __p2 = __p1 + __m1;
120126 do
121127 {
122 *__p1 = _VSTD::move(*__p2);
128 *__p1 = _IterOps<_AlgPolicy>::__iter_move(__p2);
123129 __p1 = __p2;
124130 const difference_type __d = __last - __p2;
125131 if (__m1 < __d)
......@@ -132,54 +138,66 @@ __rotate_gcd(_RandomAccessIterator __first, _RandomAccessIterator __middle, _Ran
132138 return __first + __m2;
133139}
134140
135template <class _ForwardIterator>
141template <class _AlgPolicy, class _ForwardIterator>
136142inline _LIBCPP_INLINE_VISIBILITY
137143_LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator
138__rotate(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last,
144__rotate_impl(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last,
139145 _VSTD::forward_iterator_tag)
140146{
141147 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
142148 if (is_trivially_move_assignable<value_type>::value)
143149 {
144 if (_VSTD::next(__first) == __middle)
145 return _VSTD::__rotate_left(__first, __last);
150 if (_IterOps<_AlgPolicy>::next(__first) == __middle)
151 return std::__rotate_left<_AlgPolicy>(__first, __last);
146152 }
147 return _VSTD::__rotate_forward(__first, __middle, __last);
153 return std::__rotate_forward<_AlgPolicy>(__first, __middle, __last);
148154}
149155
150template <class _BidirectionalIterator>
156template <class _AlgPolicy, class _BidirectionalIterator>
151157inline _LIBCPP_INLINE_VISIBILITY
152158_LIBCPP_CONSTEXPR_AFTER_CXX11 _BidirectionalIterator
153__rotate(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last,
159__rotate_impl(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last,
154160 bidirectional_iterator_tag)
155161{
156162 typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
157163 if (is_trivially_move_assignable<value_type>::value)
158164 {
159 if (_VSTD::next(__first) == __middle)
160 return _VSTD::__rotate_left(__first, __last);
161 if (_VSTD::next(__middle) == __last)
162 return _VSTD::__rotate_right(__first, __last);
165 if (_IterOps<_AlgPolicy>::next(__first) == __middle)
166 return std::__rotate_left<_AlgPolicy>(__first, __last);
167 if (_IterOps<_AlgPolicy>::next(__middle) == __last)
168 return std::__rotate_right<_AlgPolicy>(__first, __last);
163169 }
164 return _VSTD::__rotate_forward(__first, __middle, __last);
170 return std::__rotate_forward<_AlgPolicy>(__first, __middle, __last);
165171}
166172
167template <class _RandomAccessIterator>
173template <class _AlgPolicy, class _RandomAccessIterator>
168174inline _LIBCPP_INLINE_VISIBILITY
169175_LIBCPP_CONSTEXPR_AFTER_CXX11 _RandomAccessIterator
170__rotate(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last,
176__rotate_impl(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last,
171177 random_access_iterator_tag)
172178{
173179 typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
174180 if (is_trivially_move_assignable<value_type>::value)
175181 {
176 if (_VSTD::next(__first) == __middle)
177 return _VSTD::__rotate_left(__first, __last);
178 if (_VSTD::next(__middle) == __last)
179 return _VSTD::__rotate_right(__first, __last);
180 return _VSTD::__rotate_gcd(__first, __middle, __last);
182 if (_IterOps<_AlgPolicy>::next(__first) == __middle)
183 return std::__rotate_left<_AlgPolicy>(__first, __last);
184 if (_IterOps<_AlgPolicy>::next(__middle) == __last)
185 return std::__rotate_right<_AlgPolicy>(__first, __last);
186 return std::__rotate_gcd<_AlgPolicy>(__first, __middle, __last);
181187 }
182 return _VSTD::__rotate_forward(__first, __middle, __last);
188 return std::__rotate_forward<_AlgPolicy>(__first, __middle, __last);
189}
190
191template <class _AlgPolicy, class _RandomAccessIterator, class _IterCategory>
192_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
193_RandomAccessIterator __rotate(_RandomAccessIterator __first, _RandomAccessIterator __middle,
194 _RandomAccessIterator __last, _IterCategory __iter_category) {
195 if (__first == __middle)
196 return __last;
197 if (__middle == __last)
198 return __first;
199
200 return std::__rotate_impl<_AlgPolicy>(std::move(__first), std::move(__middle), std::move(__last), __iter_category);
183201}
184202
185203template <class _ForwardIterator>
......@@ -187,12 +205,8 @@ inline _LIBCPP_INLINE_VISIBILITY
187205_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
188206rotate(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last)
189207{
190 if (__first == __middle)
191 return __last;
192 if (__middle == __last)
193 return __first;
194 return _VSTD::__rotate(__first, __middle, __last,
195 typename iterator_traits<_ForwardIterator>::iterator_category());
208 return std::__rotate<_ClassicAlgPolicy>(__first, __middle, __last,
209 typename iterator_traits<_ForwardIterator>::iterator_category());
196210}
197211
198212_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__algorithm/rotate_copy.h+1-1
......@@ -13,7 +13,7 @@
1313#include <__config>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16#pragma GCC system_header
16# pragma GCC system_header
1717#endif
1818
1919_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/sample.h+5-3
......@@ -10,13 +10,15 @@
1010#define _LIBCPP___ALGORITHM_SAMPLE_H
1111
1212#include <__algorithm/min.h>
13#include <__assert>
1314#include <__config>
14#include <__debug>
15#include <__iterator/distance.h>
16#include <__iterator/iterator_traits.h>
1517#include <__random/uniform_int_distribution.h>
16#include <iterator>
18#include <type_traits>
1719
1820#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
21# pragma GCC system_header
2022#endif
2123
2224_LIBCPP_PUSH_MACROS
lib/libcxx/include/__algorithm/search.h+129-51
......@@ -11,41 +11,59 @@
1111#define _LIBCPP___ALGORITHM_SEARCH_H
1212
1313#include <__algorithm/comp.h>
14#include <__algorithm/iterator_operations.h>
1415#include <__config>
16#include <__functional/identity.h>
17#include <__iterator/advance.h>
18#include <__iterator/concepts.h>
1519#include <__iterator/iterator_traits.h>
16#include <utility>
20#include <__type_traits/is_callable.h>
21#include <__utility/pair.h>
22#include <type_traits>
1723
1824#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
25# pragma GCC system_header
2026#endif
2127
2228_LIBCPP_BEGIN_NAMESPACE_STD
2329
24template <class _BinaryPredicate, class _ForwardIterator1, class _ForwardIterator2>
25pair<_ForwardIterator1, _ForwardIterator1>
26 _LIBCPP_CONSTEXPR_AFTER_CXX11 __search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
27 _ForwardIterator2 __first2, _ForwardIterator2 __last2,
28 _BinaryPredicate __pred, forward_iterator_tag, forward_iterator_tag) {
30template <class _AlgPolicy,
31 class _Iter1, class _Sent1,
32 class _Iter2, class _Sent2,
33 class _Pred,
34 class _Proj1,
35 class _Proj2>
36_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
37pair<_Iter1, _Iter1> __search_forward_impl(_Iter1 __first1, _Sent1 __last1,
38 _Iter2 __first2, _Sent2 __last2,
39 _Pred& __pred,
40 _Proj1& __proj1,
41 _Proj2& __proj2) {
2942 if (__first2 == __last2)
30 return _VSTD::make_pair(__first1, __first1); // Everything matches an empty sequence
43 return std::make_pair(__first1, __first1); // Everything matches an empty sequence
3144 while (true) {
3245 // Find first element in sequence 1 that matchs *__first2, with a mininum of loop checks
3346 while (true) {
34 if (__first1 == __last1) // return __last1 if no element matches *__first2
35 return _VSTD::make_pair(__last1, __last1);
36 if (__pred(*__first1, *__first2))
47 if (__first1 == __last1) { // return __last1 if no element matches *__first2
48 _IterOps<_AlgPolicy>::__advance_to(__first1, __last1);
49 return std::make_pair(__first1, __first1);
50 }
51 if (std::__invoke(__pred, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2)))
3752 break;
3853 ++__first1;
3954 }
4055 // *__first1 matches *__first2, now match elements after here
41 _ForwardIterator1 __m1 = __first1;
42 _ForwardIterator2 __m2 = __first2;
56 _Iter1 __m1 = __first1;
57 _Iter2 __m2 = __first2;
4358 while (true) {
4459 if (++__m2 == __last2) // If pattern exhausted, __first1 is the answer (works for 1 element pattern)
45 return _VSTD::make_pair(__first1, __m1);
46 if (++__m1 == __last1) // Otherwise if source exhaused, pattern not found
47 return _VSTD::make_pair(__last1, __last1);
48 if (!__pred(*__m1, *__m2)) // if there is a mismatch, restart with a new __first1
60 return std::make_pair(__first1, ++__m1);
61 if (++__m1 == __last1) { // Otherwise if source exhaused, pattern not found
62 return std::make_pair(__m1, __m1);
63 }
64
65 // if there is a mismatch, restart with a new __first1
66 if (!std::__invoke(__pred, std::__invoke(__proj1, *__m1), std::__invoke(__proj2, *__m2)))
4967 {
5068 ++__first1;
5169 break;
......@@ -54,38 +72,42 @@ pair<_ForwardIterator1, _ForwardIterator1>
5472 }
5573}
5674
57template <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2>
58_LIBCPP_CONSTEXPR_AFTER_CXX11 pair<_RandomAccessIterator1, _RandomAccessIterator1>
59__search(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2,
60 _RandomAccessIterator2 __last2, _BinaryPredicate __pred, random_access_iterator_tag,
61 random_access_iterator_tag) {
62 typedef typename iterator_traits<_RandomAccessIterator1>::difference_type _D1;
63 typedef typename iterator_traits<_RandomAccessIterator2>::difference_type _D2;
64 // Take advantage of knowing source and pattern lengths. Stop short when source is smaller than pattern
65 const _D2 __len2 = __last2 - __first2;
66 if (__len2 == 0)
67 return _VSTD::make_pair(__first1, __first1);
68 const _D1 __len1 = __last1 - __first1;
69 if (__len1 < __len2)
70 return _VSTD::make_pair(__last1, __last1);
71 const _RandomAccessIterator1 __s = __last1 - _D1(__len2 - 1); // Start of pattern match can't go beyond here
75template <class _AlgPolicy,
76 class _Iter1, class _Sent1,
77 class _Iter2, class _Sent2,
78 class _Pred,
79 class _Proj1,
80 class _Proj2,
81 class _DiffT1,
82 class _DiffT2>
83_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
84pair<_Iter1, _Iter1> __search_random_access_impl(_Iter1 __first1, _Sent1 __last1,
85 _Iter2 __first2, _Sent2 __last2,
86 _Pred& __pred,
87 _Proj1& __proj1,
88 _Proj2& __proj2,
89 _DiffT1 __size1,
90 _DiffT2 __size2) {
91 const _Iter1 __s = __first1 + __size1 - _DiffT1(__size2 - 1); // Start of pattern match can't go beyond here
7292
7393 while (true) {
7494 while (true) {
75 if (__first1 == __s)
76 return _VSTD::make_pair(__last1, __last1);
77 if (__pred(*__first1, *__first2))
95 if (__first1 == __s) {
96 _IterOps<_AlgPolicy>::__advance_to(__first1, __last1);
97 return std::make_pair(__first1, __first1);
98 }
99 if (std::__invoke(__pred, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2)))
78100 break;
79101 ++__first1;
80102 }
81103
82 _RandomAccessIterator1 __m1 = __first1;
83 _RandomAccessIterator2 __m2 = __first2;
104 _Iter1 __m1 = __first1;
105 _Iter2 __m2 = __first2;
84106 while (true) {
85107 if (++__m2 == __last2)
86 return _VSTD::make_pair(__first1, __first1 + _D1(__len2));
108 return std::make_pair(__first1, __first1 + _DiffT1(__size2));
87109 ++__m1; // no need to check range on __m1 because __s guarantees we have enough source
88 if (!__pred(*__m1, *__m2)) {
110 if (!std::__invoke(__pred, std::__invoke(__proj1, *__m1), std::__invoke(__proj2, *__m2))) {
89111 ++__first1;
90112 break;
91113 }
......@@ -93,22 +115,78 @@ __search(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _Rando
93115 }
94116}
95117
118template <class _Iter1, class _Sent1,
119 class _Iter2, class _Sent2,
120 class _Pred,
121 class _Proj1,
122 class _Proj2>
123_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
124pair<_Iter1, _Iter1> __search_impl(_Iter1 __first1, _Sent1 __last1,
125 _Iter2 __first2, _Sent2 __last2,
126 _Pred& __pred,
127 _Proj1& __proj1,
128 _Proj2& __proj2,
129 __enable_if_t<__is_cpp17_random_access_iterator<_Iter1>::value
130 && __is_cpp17_random_access_iterator<_Iter2>::value>* = nullptr) {
131
132 auto __size2 = __last2 - __first2;
133 if (__size2 == 0)
134 return std::make_pair(__first1, __first1);
135
136 auto __size1 = __last1 - __first1;
137 if (__size1 < __size2) {
138 return std::make_pair(__last1, __last1);
139 }
140
141 return std::__search_random_access_impl<_ClassicAlgPolicy>(__first1, __last1,
142 __first2, __last2,
143 __pred,
144 __proj1,
145 __proj2,
146 __size1,
147 __size2);
148}
149
150template <class _Iter1, class _Sent1,
151 class _Iter2, class _Sent2,
152 class _Pred,
153 class _Proj1,
154 class _Proj2>
155_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
156pair<_Iter1, _Iter1> __search_impl(_Iter1 __first1, _Sent1 __last1,
157 _Iter2 __first2, _Sent2 __last2,
158 _Pred& __pred,
159 _Proj1& __proj1,
160 _Proj2& __proj2,
161 __enable_if_t<__is_cpp17_forward_iterator<_Iter1>::value
162 && __is_cpp17_forward_iterator<_Iter2>::value
163 && !(__is_cpp17_random_access_iterator<_Iter1>::value
164 && __is_cpp17_random_access_iterator<_Iter2>::value)>* = nullptr) {
165 return std::__search_forward_impl<_ClassicAlgPolicy>(__first1, __last1,
166 __first2, __last2,
167 __pred,
168 __proj1,
169 __proj2);
170}
171
96172template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
97_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator1
98search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2,
99 _BinaryPredicate __pred) {
100 return _VSTD::__search<_BinaryPredicate&>(
101 __first1, __last1, __first2, __last2, __pred,
102 typename iterator_traits<_ForwardIterator1>::iterator_category(),
103 typename iterator_traits<_ForwardIterator2>::iterator_category()).first;
173_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
174_ForwardIterator1 search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
175 _ForwardIterator2 __first2, _ForwardIterator2 __last2,
176 _BinaryPredicate __pred) {
177 static_assert(__is_callable<_BinaryPredicate, decltype(*__first1), decltype(*__first2)>::value,
178 "BinaryPredicate has to be callable");
179 auto __proj = __identity();
180 return std::__search_impl(__first1, __last1, __first2, __last2, __pred, __proj, __proj).first;
104181}
105182
106183template <class _ForwardIterator1, class _ForwardIterator2>
107_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator1
108search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) {
109 typedef typename iterator_traits<_ForwardIterator1>::value_type __v1;
110 typedef typename iterator_traits<_ForwardIterator2>::value_type __v2;
111 return _VSTD::search(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>());
184_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
185_ForwardIterator1 search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
186 _ForwardIterator2 __first2, _ForwardIterator2 __last2) {
187 using __v1 = typename iterator_traits<_ForwardIterator1>::value_type;
188 using __v2 = typename iterator_traits<_ForwardIterator2>::value_type;
189 return std::search(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>());
112190}
113191
114192#if _LIBCPP_STD_VER > 14
lib/libcxx/include/__algorithm/search_n.h+115-46
......@@ -11,40 +11,56 @@
1111#define _LIBCPP___ALGORITHM_SEARCH_N_H
1212
1313#include <__algorithm/comp.h>
14#include <__algorithm/iterator_operations.h>
1415#include <__config>
16#include <__functional/identity.h>
17#include <__iterator/advance.h>
18#include <__iterator/concepts.h>
19#include <__iterator/distance.h>
1520#include <__iterator/iterator_traits.h>
21#include <__ranges/concepts.h>
22#include <__utility/pair.h>
1623#include <type_traits> // __convert_to_integral
1724
1825#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
26# pragma GCC system_header
2027#endif
2128
2229_LIBCPP_BEGIN_NAMESPACE_STD
2330
24template <class _BinaryPredicate, class _ForwardIterator, class _Size, class _Tp>
25_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator __search_n(_ForwardIterator __first, _ForwardIterator __last,
26 _Size __count, const _Tp& __value_, _BinaryPredicate __pred,
27 forward_iterator_tag) {
31template <class _AlgPolicy, class _Pred, class _Iter, class _Sent, class _SizeT, class _Type, class _Proj>
32_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
33pair<_Iter, _Iter> __search_n_forward_impl(_Iter __first, _Sent __last,
34 _SizeT __count,
35 const _Type& __value,
36 _Pred& __pred,
37 _Proj& __proj) {
2838 if (__count <= 0)
29 return __first;
39 return std::make_pair(__first, __first);
3040 while (true) {
31 // Find first element in sequence that matchs __value_, with a mininum of loop checks
41 // Find first element in sequence that matchs __value, with a mininum of loop checks
3242 while (true) {
33 if (__first == __last) // return __last if no element matches __value_
34 return __last;
35 if (__pred(*__first, __value_))
43 if (__first == __last) { // return __last if no element matches __value
44 _IterOps<_AlgPolicy>::__advance_to(__first, __last);
45 return std::make_pair(__first, __first);
46 }
47 if (std::__invoke(__pred, std::__invoke(__proj, *__first), __value))
3648 break;
3749 ++__first;
3850 }
39 // *__first matches __value_, now match elements after here
40 _ForwardIterator __m = __first;
41 _Size __c(0);
51 // *__first matches __value, now match elements after here
52 _Iter __m = __first;
53 _SizeT __c(0);
4254 while (true) {
4355 if (++__c == __count) // If pattern exhausted, __first is the answer (works for 1 element pattern)
44 return __first;
45 if (++__m == __last) // Otherwise if source exhaused, pattern not found
46 return __last;
47 if (!__pred(*__m, __value_)) // if there is a mismatch, restart with a new __first
56 return std::make_pair(__first, ++__m);
57 if (++__m == __last) { // Otherwise if source exhaused, pattern not found
58 _IterOps<_AlgPolicy>::__advance_to(__first, __last);
59 return std::make_pair(__first, __first);
60 }
61
62 // if there is a mismatch, restart with a new __first
63 if (!std::__invoke(__pred, std::__invoke(__proj, *__m), __value))
4864 {
4965 __first = __m;
5066 ++__first;
......@@ -54,35 +70,44 @@ _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator __search_n(_ForwardIterator __fir
5470 }
5571}
5672
57template <class _BinaryPredicate, class _RandomAccessIterator, class _Size, class _Tp>
58_LIBCPP_CONSTEXPR_AFTER_CXX17 _RandomAccessIterator __search_n(_RandomAccessIterator __first,
59 _RandomAccessIterator __last, _Size __count,
60 const _Tp& __value_, _BinaryPredicate __pred,
61 random_access_iterator_tag) {
62 typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
63 if (__count <= 0)
64 return __first;
65 _Size __len = static_cast<_Size>(__last - __first);
66 if (__len < __count)
67 return __last;
68 const _RandomAccessIterator __s = __last - difference_type(__count - 1); // Start of pattern match can't go beyond here
73template <class _AlgPolicy, class _Pred, class _Iter, class _Sent, class _SizeT, class _Type, class _Proj, class _DiffT>
74_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
75std::pair<_Iter, _Iter> __search_n_random_access_impl(_Iter __first, _Sent __last,
76 _SizeT __count,
77 const _Type& __value,
78 _Pred& __pred,
79 _Proj& __proj,
80 _DiffT __size1) {
81 using difference_type = typename iterator_traits<_Iter>::difference_type;
82 if (__count == 0)
83 return std::make_pair(__first, __first);
84 if (__size1 < static_cast<_DiffT>(__count)) {
85 _IterOps<_AlgPolicy>::__advance_to(__first, __last);
86 return std::make_pair(__first, __first);
87 }
88
89 const auto __s = __first + __size1 - difference_type(__count - 1); // Start of pattern match can't go beyond here
6990 while (true) {
70 // Find first element in sequence that matchs __value_, with a mininum of loop checks
91 // Find first element in sequence that matchs __value, with a mininum of loop checks
7192 while (true) {
72 if (__first >= __s) // return __last if no element matches __value_
73 return __last;
74 if (__pred(*__first, __value_))
93 if (__first >= __s) { // return __last if no element matches __value
94 _IterOps<_AlgPolicy>::__advance_to(__first, __last);
95 return std::make_pair(__first, __first);
96 }
97 if (std::__invoke(__pred, std::__invoke(__proj, *__first), __value))
7598 break;
7699 ++__first;
77100 }
78101 // *__first matches __value_, now match elements after here
79 _RandomAccessIterator __m = __first;
80 _Size __c(0);
102 auto __m = __first;
103 _SizeT __c(0);
81104 while (true) {
82105 if (++__c == __count) // If pattern exhausted, __first is the answer (works for 1 element pattern)
83 return __first;
84 ++__m; // no need to check range on __m because __s guarantees we have enough source
85 if (!__pred(*__m, __value_)) // if there is a mismatch, restart with a new __first
106 return std::make_pair(__first, __first + _DiffT(__count));
107 ++__m; // no need to check range on __m because __s guarantees we have enough source
108
109 // if there is a mismatch, restart with a new __first
110 if (!std::__invoke(__pred, std::__invoke(__proj, *__m), __value))
86111 {
87112 __first = __m;
88113 ++__first;
......@@ -92,19 +117,63 @@ _LIBCPP_CONSTEXPR_AFTER_CXX17 _RandomAccessIterator __search_n(_RandomAccessIter
92117 }
93118}
94119
120template <class _Iter, class _Sent,
121 class _DiffT,
122 class _Type,
123 class _Pred,
124 class _Proj>
125_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
126pair<_Iter, _Iter> __search_n_impl(_Iter __first, _Sent __last,
127 _DiffT __count,
128 const _Type& __value,
129 _Pred& __pred,
130 _Proj& __proj,
131 __enable_if_t<__is_cpp17_random_access_iterator<_Iter>::value>* = nullptr) {
132 return std::__search_n_random_access_impl<_ClassicAlgPolicy>(__first, __last,
133 __count,
134 __value,
135 __pred,
136 __proj,
137 __last - __first);
138}
139
140template <class _Iter1, class _Sent1,
141 class _DiffT,
142 class _Type,
143 class _Pred,
144 class _Proj>
145_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
146pair<_Iter1, _Iter1> __search_n_impl(_Iter1 __first, _Sent1 __last,
147 _DiffT __count,
148 const _Type& __value,
149 _Pred& __pred,
150 _Proj& __proj,
151 __enable_if_t<__is_cpp17_forward_iterator<_Iter1>::value
152 && !__is_cpp17_random_access_iterator<_Iter1>::value>* = nullptr) {
153 return std::__search_n_forward_impl<_ClassicAlgPolicy>(__first, __last,
154 __count,
155 __value,
156 __pred,
157 __proj);
158}
159
95160template <class _ForwardIterator, class _Size, class _Tp, class _BinaryPredicate>
96_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator search_n(
97 _ForwardIterator __first, _ForwardIterator __last, _Size __count, const _Tp& __value_, _BinaryPredicate __pred) {
98 return _VSTD::__search_n<_BinaryPredicate&>(
99 __first, __last, _VSTD::__convert_to_integral(__count), __value_, __pred,
100 typename iterator_traits<_ForwardIterator>::iterator_category());
161_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
162_ForwardIterator search_n(_ForwardIterator __first, _ForwardIterator __last,
163 _Size __count,
164 const _Tp& __value,
165 _BinaryPredicate __pred) {
166 static_assert(__is_callable<_BinaryPredicate, decltype(*__first), const _Tp&>::value,
167 "BinaryPredicate has to be callable");
168 auto __proj = __identity();
169 return std::__search_n_impl(__first, __last, std::__convert_to_integral(__count), __value, __pred, __proj).first;
101170}
102171
103172template <class _ForwardIterator, class _Size, class _Tp>
104_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
105search_n(_ForwardIterator __first, _ForwardIterator __last, _Size __count, const _Tp& __value_) {
173_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
174_ForwardIterator search_n(_ForwardIterator __first, _ForwardIterator __last, _Size __count, const _Tp& __value) {
106175 typedef typename iterator_traits<_ForwardIterator>::value_type __v;
107 return _VSTD::search_n(__first, __last, _VSTD::__convert_to_integral(__count), __value_, __equal_to<__v, _Tp>());
176 return std::search_n(__first, __last, std::__convert_to_integral(__count), __value, __equal_to<__v, _Tp>());
108177}
109178
110179_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__algorithm/set_difference.h+45-38
......@@ -13,58 +13,65 @@
1313#include <__algorithm/comp_ref_type.h>
1414#include <__algorithm/copy.h>
1515#include <__config>
16#include <__functional/identity.h>
17#include <__functional/invoke.h>
1618#include <__iterator/iterator_traits.h>
19#include <__utility/move.h>
20#include <__utility/pair.h>
21#include <type_traits>
1722
1823#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
24# pragma GCC system_header
2025#endif
2126
2227_LIBCPP_BEGIN_NAMESPACE_STD
2328
24template <class _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator>
25_LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator
26__set_difference(_InputIterator1 __first1, _InputIterator1 __last1,
27 _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp)
28{
29 while (__first1 != __last1)
30 {
31 if (__first2 == __last2)
32 return _VSTD::copy(__first1, __last1, __result);
33 if (__comp(*__first1, *__first2))
34 {
35 *__result = *__first1;
36 ++__result;
37 ++__first1;
38 }
39 else
40 {
41 if (!__comp(*__first2, *__first1))
42 ++__first1;
43 ++__first2;
44 }
29template < class _Comp, class _InIter1, class _Sent1, class _InIter2, class _Sent2, class _OutIter>
30_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 pair<__uncvref_t<_InIter1>, __uncvref_t<_OutIter> >
31__set_difference(
32 _InIter1&& __first1, _Sent1&& __last1, _InIter2&& __first2, _Sent2&& __last2, _OutIter&& __result, _Comp&& __comp) {
33 while (__first1 != __last1 && __first2 != __last2) {
34 if (__comp(*__first1, *__first2)) {
35 *__result = *__first1;
36 ++__first1;
37 ++__result;
38 } else if (__comp(*__first2, *__first1)) {
39 ++__first2;
40 } else {
41 ++__first1;
42 ++__first2;
4543 }
46 return __result;
44 }
45 return std::__copy(std::move(__first1), std::move(__last1), std::move(__result));
4746}
4847
4948template <class _InputIterator1, class _InputIterator2, class _OutputIterator, class _Compare>
50inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
51_OutputIterator
52set_difference(_InputIterator1 __first1, _InputIterator1 __last1,
53 _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp)
54{
55 typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
56 return _VSTD::__set_difference<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __comp);
49inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator set_difference(
50 _InputIterator1 __first1,
51 _InputIterator1 __last1,
52 _InputIterator2 __first2,
53 _InputIterator2 __last2,
54 _OutputIterator __result,
55 _Compare __comp) {
56 typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
57 return std::__set_difference<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __comp).second;
5758}
5859
5960template <class _InputIterator1, class _InputIterator2, class _OutputIterator>
60inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
61_OutputIterator
62set_difference(_InputIterator1 __first1, _InputIterator1 __last1,
63 _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result)
64{
65 return _VSTD::set_difference(__first1, __last1, __first2, __last2, __result,
66 __less<typename iterator_traits<_InputIterator1>::value_type,
67 typename iterator_traits<_InputIterator2>::value_type>());
61inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator set_difference(
62 _InputIterator1 __first1,
63 _InputIterator1 __last1,
64 _InputIterator2 __first2,
65 _InputIterator2 __last2,
66 _OutputIterator __result) {
67 return std::__set_difference(
68 __first1,
69 __last1,
70 __first2,
71 __last2,
72 __result,
73 __less<typename iterator_traits<_InputIterator1>::value_type,
74 typename iterator_traits<_InputIterator2>::value_type>()).second;
6875}
6976
7077_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__algorithm/set_intersection.h+67-36
......@@ -11,57 +11,88 @@
1111
1212#include <__algorithm/comp.h>
1313#include <__algorithm/comp_ref_type.h>
14#include <__algorithm/iterator_operations.h>
1415#include <__config>
1516#include <__iterator/iterator_traits.h>
17#include <__iterator/next.h>
18#include <__utility/move.h>
1619
1720#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
21# pragma GCC system_header
1922#endif
2023
2124_LIBCPP_BEGIN_NAMESPACE_STD
2225
23template <class _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator>
24_LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator
25__set_intersection(_InputIterator1 __first1, _InputIterator1 __last1,
26 _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp)
27{
28 while (__first1 != __last1 && __first2 != __last2)
29 {
30 if (__comp(*__first1, *__first2))
31 ++__first1;
32 else
33 {
34 if (!__comp(*__first2, *__first1))
35 {
36 *__result = *__first1;
37 ++__result;
38 ++__first1;
39 }
40 ++__first2;
41 }
26template <class _InIter1, class _InIter2, class _OutIter>
27struct __set_intersection_result {
28 _InIter1 __in1_;
29 _InIter2 __in2_;
30 _OutIter __out_;
31
32 // need a constructor as C++03 aggregate init is hard
33 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
34 __set_intersection_result(_InIter1&& __in_iter1, _InIter2&& __in_iter2, _OutIter&& __out_iter)
35 : __in1_(std::move(__in_iter1)), __in2_(std::move(__in_iter2)), __out_(std::move(__out_iter)) {}
36};
37
38template <class _AlgPolicy, class _Compare, class _InIter1, class _Sent1, class _InIter2, class _Sent2, class _OutIter>
39_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 __set_intersection_result<_InIter1, _InIter2, _OutIter>
40__set_intersection(
41 _InIter1 __first1, _Sent1 __last1, _InIter2 __first2, _Sent2 __last2, _OutIter __result, _Compare&& __comp) {
42 while (__first1 != __last1 && __first2 != __last2) {
43 if (__comp(*__first1, *__first2))
44 ++__first1;
45 else {
46 if (!__comp(*__first2, *__first1)) {
47 *__result = *__first1;
48 ++__result;
49 ++__first1;
50 }
51 ++__first2;
4252 }
43 return __result;
53 }
54
55 return __set_intersection_result<_InIter1, _InIter2, _OutIter>(
56 _IterOps<_AlgPolicy>::next(std::move(__first1), std::move(__last1)),
57 _IterOps<_AlgPolicy>::next(std::move(__first2), std::move(__last2)),
58 std::move(__result));
4459}
4560
4661template <class _InputIterator1, class _InputIterator2, class _OutputIterator, class _Compare>
47inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
48_OutputIterator
49set_intersection(_InputIterator1 __first1, _InputIterator1 __last1,
50 _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp)
51{
52 typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
53 return _VSTD::__set_intersection<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __comp);
62inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator set_intersection(
63 _InputIterator1 __first1,
64 _InputIterator1 __last1,
65 _InputIterator2 __first2,
66 _InputIterator2 __last2,
67 _OutputIterator __result,
68 _Compare __comp) {
69 typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
70 return std::__set_intersection<_ClassicAlgPolicy, _Comp_ref>(
71 std::move(__first1),
72 std::move(__last1),
73 std::move(__first2),
74 std::move(__last2),
75 std::move(__result),
76 __comp)
77 .__out_;
5478}
5579
5680template <class _InputIterator1, class _InputIterator2, class _OutputIterator>
57inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
58_OutputIterator
59set_intersection(_InputIterator1 __first1, _InputIterator1 __last1,
60 _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result)
61{
62 return _VSTD::set_intersection(__first1, __last1, __first2, __last2, __result,
63 __less<typename iterator_traits<_InputIterator1>::value_type,
64 typename iterator_traits<_InputIterator2>::value_type>());
81inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator set_intersection(
82 _InputIterator1 __first1,
83 _InputIterator1 __last1,
84 _InputIterator2 __first2,
85 _InputIterator2 __last2,
86 _OutputIterator __result) {
87 return std::__set_intersection<_ClassicAlgPolicy>(
88 std::move(__first1),
89 std::move(__last1),
90 std::move(__first2),
91 std::move(__last2),
92 std::move(__result),
93 __less<typename iterator_traits<_InputIterator1>::value_type,
94 typename iterator_traits<_InputIterator2>::value_type>())
95 .__out_;
6596}
6697
6798_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__algorithm/set_symmetric_difference.h+70-43
......@@ -14,62 +14,89 @@
1414#include <__algorithm/copy.h>
1515#include <__config>
1616#include <__iterator/iterator_traits.h>
17#include <__utility/move.h>
1718
1819#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
20# pragma GCC system_header
2021#endif
2122
2223_LIBCPP_BEGIN_NAMESPACE_STD
2324
24template <class _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator>
25_LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator
26__set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 __last1,
27 _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp)
28{
29 while (__first1 != __last1)
30 {
31 if (__first2 == __last2)
32 return _VSTD::copy(__first1, __last1, __result);
33 if (__comp(*__first1, *__first2))
34 {
35 *__result = *__first1;
36 ++__result;
37 ++__first1;
38 }
39 else
40 {
41 if (__comp(*__first2, *__first1))
42 {
43 *__result = *__first2;
44 ++__result;
45 }
46 else
47 ++__first1;
48 ++__first2;
49 }
25template <class _InIter1, class _InIter2, class _OutIter>
26struct __set_symmetric_difference_result {
27 _InIter1 __in1_;
28 _InIter2 __in2_;
29 _OutIter __out_;
30
31 // need a constructor as C++03 aggregate init is hard
32 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
33 __set_symmetric_difference_result(_InIter1&& __in_iter1, _InIter2&& __in_iter2, _OutIter&& __out_iter)
34 : __in1_(std::move(__in_iter1)), __in2_(std::move(__in_iter2)), __out_(std::move(__out_iter)) {}
35};
36
37template <class _Compare, class _InIter1, class _Sent1, class _InIter2, class _Sent2, class _OutIter>
38_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 __set_symmetric_difference_result<_InIter1, _InIter2, _OutIter>
39__set_symmetric_difference(
40 _InIter1 __first1, _Sent1 __last1, _InIter2 __first2, _Sent2 __last2, _OutIter __result, _Compare&& __comp) {
41 while (__first1 != __last1) {
42 if (__first2 == __last2) {
43 auto __ret1 = std::__copy_impl(std::move(__first1), std::move(__last1), std::move(__result));
44 return __set_symmetric_difference_result<_InIter1, _InIter2, _OutIter>(
45 std::move(__ret1.first), std::move(__first2), std::move((__ret1.second)));
46 }
47 if (__comp(*__first1, *__first2)) {
48 *__result = *__first1;
49 ++__result;
50 ++__first1;
51 } else {
52 if (__comp(*__first2, *__first1)) {
53 *__result = *__first2;
54 ++__result;
55 } else {
56 ++__first1;
57 }
58 ++__first2;
5059 }
51 return _VSTD::copy(__first2, __last2, __result);
60 }
61 auto __ret2 = std::__copy_impl(std::move(__first2), std::move(__last2), std::move(__result));
62 return __set_symmetric_difference_result<_InIter1, _InIter2, _OutIter>(
63 std::move(__first1), std::move(__ret2.first), std::move((__ret2.second)));
5264}
5365
5466template <class _InputIterator1, class _InputIterator2, class _OutputIterator, class _Compare>
55inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
56_OutputIterator
57set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 __last1,
58 _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp)
59{
60 typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
61 return _VSTD::__set_symmetric_difference<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __comp);
67_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator set_symmetric_difference(
68 _InputIterator1 __first1,
69 _InputIterator1 __last1,
70 _InputIterator2 __first2,
71 _InputIterator2 __last2,
72 _OutputIterator __result,
73 _Compare __comp) {
74 typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
75 return std::__set_symmetric_difference<_Comp_ref>(
76 std::move(__first1),
77 std::move(__last1),
78 std::move(__first2),
79 std::move(__last2),
80 std::move(__result),
81 __comp)
82 .__out_;
6283}
6384
6485template <class _InputIterator1, class _InputIterator2, class _OutputIterator>
65inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
66_OutputIterator
67set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 __last1,
68 _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result)
69{
70 return _VSTD::set_symmetric_difference(__first1, __last1, __first2, __last2, __result,
71 __less<typename iterator_traits<_InputIterator1>::value_type,
72 typename iterator_traits<_InputIterator2>::value_type>());
86_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator set_symmetric_difference(
87 _InputIterator1 __first1,
88 _InputIterator1 __last1,
89 _InputIterator2 __first2,
90 _InputIterator2 __last2,
91 _OutputIterator __result) {
92 return std::set_symmetric_difference(
93 std::move(__first1),
94 std::move(__last1),
95 std::move(__first2),
96 std::move(__last2),
97 std::move(__result),
98 __less<typename iterator_traits<_InputIterator1>::value_type,
99 typename iterator_traits<_InputIterator2>::value_type>());
73100}
74101
75102_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__algorithm/set_union.h+66-38
......@@ -14,57 +14,85 @@
1414#include <__algorithm/copy.h>
1515#include <__config>
1616#include <__iterator/iterator_traits.h>
17#include <__utility/move.h>
1718
1819#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
20# pragma GCC system_header
2021#endif
2122
2223_LIBCPP_BEGIN_NAMESPACE_STD
2324
24template <class _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator>
25_LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator
26__set_union(_InputIterator1 __first1, _InputIterator1 __last1,
27 _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp)
28{
29 for (; __first1 != __last1; ++__result)
30 {
31 if (__first2 == __last2)
32 return _VSTD::copy(__first1, __last1, __result);
33 if (__comp(*__first2, *__first1))
34 {
35 *__result = *__first2;
36 ++__first2;
37 }
38 else
39 {
40 if (!__comp(*__first1, *__first2))
41 ++__first2;
42 *__result = *__first1;
43 ++__first1;
44 }
25template <class _InIter1, class _InIter2, class _OutIter>
26struct __set_union_result {
27 _InIter1 __in1_;
28 _InIter2 __in2_;
29 _OutIter __out_;
30
31 // need a constructor as C++03 aggregate init is hard
32 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
33 __set_union_result(_InIter1&& __in_iter1, _InIter2&& __in_iter2, _OutIter&& __out_iter)
34 : __in1_(std::move(__in_iter1)), __in2_(std::move(__in_iter2)), __out_(std::move(__out_iter)) {}
35};
36
37template <class _Compare, class _InIter1, class _Sent1, class _InIter2, class _Sent2, class _OutIter>
38_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 __set_union_result<_InIter1, _InIter2, _OutIter> __set_union(
39 _InIter1 __first1, _Sent1 __last1, _InIter2 __first2, _Sent2 __last2, _OutIter __result, _Compare&& __comp) {
40 for (; __first1 != __last1; ++__result) {
41 if (__first2 == __last2) {
42 auto __ret1 = std::__copy_impl(std::move(__first1), std::move(__last1), std::move(__result));
43 return __set_union_result<_InIter1, _InIter2, _OutIter>(
44 std::move(__ret1.first), std::move(__first2), std::move((__ret1.second)));
45 }
46 if (__comp(*__first2, *__first1)) {
47 *__result = *__first2;
48 ++__first2;
49 } else {
50 if (!__comp(*__first1, *__first2)) {
51 ++__first2;
52 }
53 *__result = *__first1;
54 ++__first1;
4555 }
46 return _VSTD::copy(__first2, __last2, __result);
56 }
57 auto __ret2 = std::__copy_impl(std::move(__first2), std::move(__last2), std::move(__result));
58 return __set_union_result<_InIter1, _InIter2, _OutIter>(
59 std::move(__first1), std::move(__ret2.first), std::move((__ret2.second)));
4760}
4861
4962template <class _InputIterator1, class _InputIterator2, class _OutputIterator, class _Compare>
50inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
51_OutputIterator
52set_union(_InputIterator1 __first1, _InputIterator1 __last1,
53 _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp)
54{
55 typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
56 return _VSTD::__set_union<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __comp);
63_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator set_union(
64 _InputIterator1 __first1,
65 _InputIterator1 __last1,
66 _InputIterator2 __first2,
67 _InputIterator2 __last2,
68 _OutputIterator __result,
69 _Compare __comp) {
70 typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
71 return std::__set_union<_Comp_ref>(
72 std::move(__first1),
73 std::move(__last1),
74 std::move(__first2),
75 std::move(__last2),
76 std::move(__result),
77 __comp)
78 .__out_;
5779}
5880
5981template <class _InputIterator1, class _InputIterator2, class _OutputIterator>
60inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
61_OutputIterator
62set_union(_InputIterator1 __first1, _InputIterator1 __last1,
63 _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result)
64{
65 return _VSTD::set_union(__first1, __last1, __first2, __last2, __result,
66 __less<typename iterator_traits<_InputIterator1>::value_type,
67 typename iterator_traits<_InputIterator2>::value_type>());
82_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator set_union(
83 _InputIterator1 __first1,
84 _InputIterator1 __last1,
85 _InputIterator2 __first2,
86 _InputIterator2 __last2,
87 _OutputIterator __result) {
88 return std::set_union(
89 std::move(__first1),
90 std::move(__last1),
91 std::move(__first2),
92 std::move(__last2),
93 std::move(__result),
94 __less<typename iterator_traits<_InputIterator1>::value_type,
95 typename iterator_traits<_InputIterator2>::value_type>());
6896}
6997
7098_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__algorithm/shift_left.h+1-1
......@@ -15,7 +15,7 @@
1515#include <type_traits>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/shift_right.h+1-1
......@@ -18,7 +18,7 @@
1818#include <type_traits>
1919
2020#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21#pragma GCC system_header
21# pragma GCC system_header
2222#endif
2323
2424_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/shuffle.h+21-7
......@@ -9,15 +9,18 @@
99#ifndef _LIBCPP___ALGORITHM_SHUFFLE_H
1010#define _LIBCPP___ALGORITHM_SHUFFLE_H
1111
12#include <__algorithm/iterator_operations.h>
1213#include <__config>
14#include <__debug>
1315#include <__iterator/iterator_traits.h>
1416#include <__random/uniform_int_distribution.h>
15#include <__utility/swap.h>
17#include <__utility/forward.h>
18#include <__utility/move.h>
1619#include <cstddef>
1720#include <cstdint>
1821
1922#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20#pragma GCC system_header
23# pragma GCC system_header
2124#endif
2225
2326_LIBCPP_PUSH_MACROS
......@@ -133,13 +136,15 @@ random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last,
133136}
134137#endif
135138
136template<class _RandomAccessIterator, class _UniformRandomNumberGenerator>
137 void shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last,
138 _UniformRandomNumberGenerator&& __g)
139{
139template <class _AlgPolicy, class _RandomAccessIterator, class _Sentinel, class _UniformRandomNumberGenerator>
140_RandomAccessIterator __shuffle(
141 _RandomAccessIterator __first, _Sentinel __last_sentinel, _UniformRandomNumberGenerator&& __g) {
140142 typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
141143 typedef uniform_int_distribution<ptrdiff_t> _Dp;
142144 typedef typename _Dp::param_type _Pp;
145
146 auto __original_last = _IterOps<_AlgPolicy>::next(__first, __last_sentinel);
147 auto __last = __original_last;
143148 difference_type __d = __last - __first;
144149 if (__d > 1)
145150 {
......@@ -148,9 +153,18 @@ template<class _RandomAccessIterator, class _UniformRandomNumberGenerator>
148153 {
149154 difference_type __i = __uid(__g, _Pp(0, __d));
150155 if (__i != difference_type(0))
151 swap(*__first, *(__first + __i));
156 _IterOps<_AlgPolicy>::iter_swap(__first, __first + __i);
152157 }
153158 }
159
160 return __original_last;
161}
162
163template <class _RandomAccessIterator, class _UniformRandomNumberGenerator>
164void shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last,
165 _UniformRandomNumberGenerator&& __g) {
166 (void)std::__shuffle<_ClassicAlgPolicy>(
167 std::move(__first), std::move(__last), std::forward<_UniformRandomNumberGenerator>(__g));
154168}
155169
156170_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__algorithm/sift_down.h+41-5
......@@ -9,22 +9,26 @@
99#ifndef _LIBCPP___ALGORITHM_SIFT_DOWN_H
1010#define _LIBCPP___ALGORITHM_SIFT_DOWN_H
1111
12#include <__algorithm/iterator_operations.h>
13#include <__assert>
1214#include <__config>
1315#include <__iterator/iterator_traits.h>
1416#include <__utility/move.h>
1517
1618#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
19# pragma GCC system_header
1820#endif
1921
2022_LIBCPP_BEGIN_NAMESPACE_STD
2123
22template <class _Compare, class _RandomAccessIterator>
24template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
2325_LIBCPP_CONSTEXPR_AFTER_CXX11 void
24__sift_down(_RandomAccessIterator __first, _Compare __comp,
26__sift_down(_RandomAccessIterator __first, _Compare&& __comp,
2527 typename iterator_traits<_RandomAccessIterator>::difference_type __len,
2628 _RandomAccessIterator __start)
2729{
30 using _Ops = _IterOps<_AlgPolicy>;
31
2832 typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
2933 typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
3034 // left-child of __start is at 2 * __start + 1
......@@ -48,11 +52,11 @@ __sift_down(_RandomAccessIterator __first, _Compare __comp,
4852 // we are, __start is larger than its largest child
4953 return;
5054
51 value_type __top(_VSTD::move(*__start));
55 value_type __top(_Ops::__iter_move(__start));
5256 do
5357 {
5458 // we are not in heap-order, swap the parent with its largest child
55 *__start = _VSTD::move(*__child_i);
59 *__start = _Ops::__iter_move(__child_i);
5660 __start = __child_i;
5761
5862 if ((__len - 2) / 2 < __child)
......@@ -73,6 +77,38 @@ __sift_down(_RandomAccessIterator __first, _Compare __comp,
7377 *__start = _VSTD::move(__top);
7478}
7579
80template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
81_LIBCPP_CONSTEXPR_AFTER_CXX11 _RandomAccessIterator
82__floyd_sift_down(_RandomAccessIterator __first, _Compare&& __comp,
83 typename iterator_traits<_RandomAccessIterator>::difference_type __len)
84{
85 using difference_type = typename iterator_traits<_RandomAccessIterator>::difference_type;
86 _LIBCPP_ASSERT(__len >= 2, "shouldn't be called unless __len >= 2");
87
88 _RandomAccessIterator __hole = __first;
89 _RandomAccessIterator __child_i = __first;
90 difference_type __child = 0;
91
92 while (true) {
93 __child_i += difference_type(__child + 1);
94 __child = 2 * __child + 1;
95
96 if ((__child + 1) < __len && __comp(*__child_i, *(__child_i + difference_type(1)))) {
97 // right-child exists and is greater than left-child
98 ++__child_i;
99 ++__child;
100 }
101
102 // swap __hole with its largest child
103 *__hole = _IterOps<_AlgPolicy>::__iter_move(__child_i);
104 __hole = __child_i;
105
106 // if __hole is now a leaf, we're done
107 if (__child > (__len - 2) / 2)
108 return __hole;
109 }
110}
111
76112_LIBCPP_END_NAMESPACE_STD
77113
78114#endif // _LIBCPP___ALGORITHM_SIFT_DOWN_H
lib/libcxx/include/__algorithm/sort.h+598-449
......@@ -11,462 +11,602 @@
1111
1212#include <__algorithm/comp.h>
1313#include <__algorithm/comp_ref_type.h>
14#include <__algorithm/iterator_operations.h>
1415#include <__algorithm/min_element.h>
1516#include <__algorithm/partial_sort.h>
1617#include <__algorithm/unwrap_iter.h>
18#include <__bits>
1719#include <__config>
18#include <__utility/swap.h>
20#include <__debug>
21#include <__debug_utils/randomize_range.h>
22#include <__functional/operations.h>
23#include <__functional/ranges_operations.h>
24#include <__iterator/iterator_traits.h>
25#include <climits>
1926#include <memory>
2027
21#if defined(_LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY)
22# include <__algorithm/shuffle.h>
23#endif
24
2528#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
26#pragma GCC system_header
29# pragma GCC system_header
2730#endif
2831
2932_LIBCPP_BEGIN_NAMESPACE_STD
3033
34// Wraps an algorithm policy tag and a comparator in a single struct, used to pass the policy tag around without
35// changing the number of template arguments (to keep the ABI stable). This is only used for the "range" policy tag.
36//
37// To create an object of this type, use `_WrapAlgPolicy<T, C>::type` -- see the specialization below for the rationale.
38template <class _PolicyT, class _CompT, class = void>
39struct _WrapAlgPolicy {
40 using type = _WrapAlgPolicy;
41
42 using _AlgPolicy = _PolicyT;
43 using _Comp = _CompT;
44 _Comp& __comp;
45
46 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
47 _WrapAlgPolicy(_Comp& __c) : __comp(__c) {}
48};
49
50// Specialization for the "classic" policy tag that avoids creating a struct and simply defines an alias for the
51// comparator. When unwrapping, a pristine comparator is always considered to have the "classic" tag attached. Passing
52// the pristine comparator where possible allows using template instantiations from the dylib.
53template <class _PolicyT, class _CompT>
54struct _WrapAlgPolicy<_PolicyT, _CompT, __enable_if_t<std::is_same<_PolicyT, _ClassicAlgPolicy>::value> > {
55 using type = _CompT;
56};
57
58// Unwraps a pristine functor (e.g. `std::less`) as if it were wrapped using `_WrapAlgPolicy`. The policy tag is always
59// set to "classic".
60template <class _CompT>
61struct _UnwrapAlgPolicy {
62 using _AlgPolicy = _ClassicAlgPolicy;
63 using _Comp = _CompT;
64
65 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 static
66 _Comp __get_comp(_Comp __comp) { return __comp; }
67};
68
69// Unwraps a `_WrapAlgPolicy` struct.
70template <class... _Ts>
71struct _UnwrapAlgPolicy<_WrapAlgPolicy<_Ts...> > {
72 using _Wrapped = _WrapAlgPolicy<_Ts...>;
73 using _AlgPolicy = typename _Wrapped::_AlgPolicy;
74 using _Comp = typename _Wrapped::_Comp;
75
76 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 static
77 _Comp __get_comp(_Wrapped& __w) { return __w.__comp; }
78};
79
3180// stable, 2-3 compares, 0-2 swaps
3281
33template <class _Compare, class _ForwardIterator>
34_LIBCPP_CONSTEXPR_AFTER_CXX11 unsigned
35__sort3(_ForwardIterator __x, _ForwardIterator __y, _ForwardIterator __z, _Compare __c)
36{
37 unsigned __r = 0;
38 if (!__c(*__y, *__x)) // if x <= y
39 {
40 if (!__c(*__z, *__y)) // if y <= z
41 return __r; // x <= y && y <= z
42 // x <= y && y > z
43 swap(*__y, *__z); // x <= z && y < z
44 __r = 1;
45 if (__c(*__y, *__x)) // if x > y
46 {
47 swap(*__x, *__y); // x < y && y <= z
48 __r = 2;
49 }
50 return __r; // x <= y && y < z
51 }
52 if (__c(*__z, *__y)) // x > y, if y > z
53 {
54 swap(*__x, *__z); // x < y && y < z
55 __r = 1;
56 return __r;
57 }
58 swap(*__x, *__y); // x > y && y <= z
59 __r = 1; // x < y && x <= z
60 if (__c(*__z, *__y)) // if y > z
82template <class _AlgPolicy, class _Compare, class _ForwardIterator>
83_LIBCPP_CONSTEXPR_AFTER_CXX11 unsigned __sort3(_ForwardIterator __x, _ForwardIterator __y, _ForwardIterator __z,
84 _Compare __c) {
85 using _Ops = _IterOps<_AlgPolicy>;
86
87 unsigned __r = 0;
88 if (!__c(*__y, *__x)) // if x <= y
89 {
90 if (!__c(*__z, *__y)) // if y <= z
91 return __r; // x <= y && y <= z
92 // x <= y && y > z
93 _Ops::iter_swap(__y, __z); // x <= z && y < z
94 __r = 1;
95 if (__c(*__y, *__x)) // if x > y
6196 {
62 swap(*__y, *__z); // x <= y && y < z
63 __r = 2;
97 _Ops::iter_swap(__x, __y); // x < y && y <= z
98 __r = 2;
6499 }
100 return __r; // x <= y && y < z
101 }
102 if (__c(*__z, *__y)) // x > y, if y > z
103 {
104 _Ops::iter_swap(__x, __z); // x < y && y < z
105 __r = 1;
65106 return __r;
66} // x <= y && y <= z
107 }
108 _Ops::iter_swap(__x, __y); // x > y && y <= z
109 __r = 1; // x < y && x <= z
110 if (__c(*__z, *__y)) // if y > z
111 {
112 _Ops::iter_swap(__y, __z); // x <= y && y < z
113 __r = 2;
114 }
115 return __r;
116} // x <= y && y <= z
67117
68118// stable, 3-6 compares, 0-5 swaps
69119
70template <class _Compare, class _ForwardIterator>
71unsigned
72__sort4(_ForwardIterator __x1, _ForwardIterator __x2, _ForwardIterator __x3,
73 _ForwardIterator __x4, _Compare __c)
74{
75 unsigned __r = _VSTD::__sort3<_Compare>(__x1, __x2, __x3, __c);
76 if (__c(*__x4, *__x3))
77 {
78 swap(*__x3, *__x4);
120template <class _AlgPolicy, class _Compare, class _ForwardIterator>
121unsigned __sort4(_ForwardIterator __x1, _ForwardIterator __x2, _ForwardIterator __x3, _ForwardIterator __x4,
122 _Compare __c) {
123 using _Ops = _IterOps<_AlgPolicy>;
124
125 unsigned __r = std::__sort3<_AlgPolicy, _Compare>(__x1, __x2, __x3, __c);
126 if (__c(*__x4, *__x3)) {
127 _Ops::iter_swap(__x3, __x4);
128 ++__r;
129 if (__c(*__x3, *__x2)) {
130 _Ops::iter_swap(__x2, __x3);
131 ++__r;
132 if (__c(*__x2, *__x1)) {
133 _Ops::iter_swap(__x1, __x2);
79134 ++__r;
80 if (__c(*__x3, *__x2))
81 {
82 swap(*__x2, *__x3);
83 ++__r;
84 if (__c(*__x2, *__x1))
85 {
86 swap(*__x1, *__x2);
87 ++__r;
88 }
89 }
135 }
90136 }
91 return __r;
137 }
138 return __r;
92139}
93140
94141// stable, 4-10 compares, 0-9 swaps
95142
96template <class _Compare, class _ForwardIterator>
97_LIBCPP_HIDDEN
98unsigned
99__sort5(_ForwardIterator __x1, _ForwardIterator __x2, _ForwardIterator __x3,
100 _ForwardIterator __x4, _ForwardIterator __x5, _Compare __c)
101{
102 unsigned __r = _VSTD::__sort4<_Compare>(__x1, __x2, __x3, __x4, __c);
103 if (__c(*__x5, *__x4))
104 {
105 swap(*__x4, *__x5);
143template <class _WrappedComp, class _ForwardIterator>
144_LIBCPP_HIDDEN unsigned __sort5(_ForwardIterator __x1, _ForwardIterator __x2, _ForwardIterator __x3,
145 _ForwardIterator __x4, _ForwardIterator __x5, _WrappedComp __wrapped_comp) {
146 using _Unwrap = _UnwrapAlgPolicy<_WrappedComp>;
147 using _AlgPolicy = typename _Unwrap::_AlgPolicy;
148 using _Ops = _IterOps<_AlgPolicy>;
149
150 using _Compare = typename _Unwrap::_Comp;
151 _Compare __c = _Unwrap::__get_comp(__wrapped_comp);
152
153 unsigned __r = std::__sort4<_AlgPolicy, _Compare>(__x1, __x2, __x3, __x4, __c);
154 if (__c(*__x5, *__x4)) {
155 _Ops::iter_swap(__x4, __x5);
156 ++__r;
157 if (__c(*__x4, *__x3)) {
158 _Ops::iter_swap(__x3, __x4);
159 ++__r;
160 if (__c(*__x3, *__x2)) {
161 _Ops::iter_swap(__x2, __x3);
106162 ++__r;
107 if (__c(*__x4, *__x3))
108 {
109 swap(*__x3, *__x4);
110 ++__r;
111 if (__c(*__x3, *__x2))
112 {
113 swap(*__x2, *__x3);
114 ++__r;
115 if (__c(*__x2, *__x1))
116 {
117 swap(*__x1, *__x2);
118 ++__r;
119 }
120 }
163 if (__c(*__x2, *__x1)) {
164 _Ops::iter_swap(__x1, __x2);
165 ++__r;
121166 }
167 }
122168 }
123 return __r;
169 }
170 return __r;
171}
172
173template <class _AlgPolicy, class _Compare, class _ForwardIterator>
174_LIBCPP_HIDDEN unsigned __sort5_wrap_policy(
175 _ForwardIterator __x1, _ForwardIterator __x2, _ForwardIterator __x3, _ForwardIterator __x4, _ForwardIterator __x5,
176 _Compare __c) {
177 using _WrappedComp = typename _WrapAlgPolicy<_AlgPolicy, _Compare>::type;
178 _WrappedComp __wrapped_comp(__c);
179 return std::__sort5<_WrappedComp>(
180 std::move(__x1), std::move(__x2), std::move(__x3), std::move(__x4), std::move(__x5), __wrapped_comp);
181}
182
183// The comparator being simple is a prerequisite for using the branchless optimization.
184template <class _Tp>
185struct __is_simple_comparator : false_type {};
186template <class _Tp>
187struct __is_simple_comparator<__less<_Tp>&> : true_type {};
188template <class _Tp>
189struct __is_simple_comparator<less<_Tp>&> : true_type {};
190template <class _Tp>
191struct __is_simple_comparator<greater<_Tp>&> : true_type {};
192#if _LIBCPP_STD_VER > 17
193template <>
194struct __is_simple_comparator<ranges::less&> : true_type {};
195template <>
196struct __is_simple_comparator<ranges::greater&> : true_type {};
197#endif
198
199template <class _Compare, class _Iter, class _Tp = typename iterator_traits<_Iter>::value_type>
200using __use_branchless_sort =
201 integral_constant<bool, __is_cpp17_contiguous_iterator<_Iter>::value && sizeof(_Tp) <= sizeof(void*) &&
202 is_arithmetic<_Tp>::value && __is_simple_comparator<_Compare>::value>;
203
204// Ensures that __c(*__x, *__y) is true by swapping *__x and *__y if necessary.
205template <class _Compare, class _RandomAccessIterator>
206inline _LIBCPP_HIDE_FROM_ABI void __cond_swap(_RandomAccessIterator __x, _RandomAccessIterator __y, _Compare __c) {
207 // Note: this function behaves correctly even with proxy iterators (because it relies on `value_type`).
208 using value_type = typename iterator_traits<_RandomAccessIterator>::value_type;
209 bool __r = __c(*__x, *__y);
210 value_type __tmp = __r ? *__x : *__y;
211 *__y = __r ? *__y : *__x;
212 *__x = __tmp;
213}
214
215// Ensures that *__x, *__y and *__z are ordered according to the comparator __c,
216// under the assumption that *__y and *__z are already ordered.
217template <class _Compare, class _RandomAccessIterator>
218inline _LIBCPP_HIDE_FROM_ABI void __partially_sorted_swap(_RandomAccessIterator __x, _RandomAccessIterator __y,
219 _RandomAccessIterator __z, _Compare __c) {
220 // Note: this function behaves correctly even with proxy iterators (because it relies on `value_type`).
221 using value_type = typename iterator_traits<_RandomAccessIterator>::value_type;
222 bool __r = __c(*__z, *__x);
223 value_type __tmp = __r ? *__z : *__x;
224 *__z = __r ? *__x : *__z;
225 __r = __c(__tmp, *__y);
226 *__x = __r ? *__x : *__y;
227 *__y = __r ? *__y : __tmp;
228}
229
230template <class, class _Compare, class _RandomAccessIterator>
231inline _LIBCPP_HIDE_FROM_ABI __enable_if_t<__use_branchless_sort<_Compare, _RandomAccessIterator>::value, void>
232__sort3_maybe_branchless(_RandomAccessIterator __x1, _RandomAccessIterator __x2, _RandomAccessIterator __x3,
233 _Compare __c) {
234 _VSTD::__cond_swap<_Compare>(__x2, __x3, __c);
235 _VSTD::__partially_sorted_swap<_Compare>(__x1, __x2, __x3, __c);
236}
237
238template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
239inline _LIBCPP_HIDE_FROM_ABI __enable_if_t<!__use_branchless_sort<_Compare, _RandomAccessIterator>::value, void>
240__sort3_maybe_branchless(_RandomAccessIterator __x1, _RandomAccessIterator __x2, _RandomAccessIterator __x3,
241 _Compare __c) {
242 std::__sort3<_AlgPolicy, _Compare>(__x1, __x2, __x3, __c);
243}
244
245template <class, class _Compare, class _RandomAccessIterator>
246inline _LIBCPP_HIDE_FROM_ABI __enable_if_t<__use_branchless_sort<_Compare, _RandomAccessIterator>::value, void>
247__sort4_maybe_branchless(_RandomAccessIterator __x1, _RandomAccessIterator __x2, _RandomAccessIterator __x3,
248 _RandomAccessIterator __x4, _Compare __c) {
249 _VSTD::__cond_swap<_Compare>(__x1, __x3, __c);
250 _VSTD::__cond_swap<_Compare>(__x2, __x4, __c);
251 _VSTD::__cond_swap<_Compare>(__x1, __x2, __c);
252 _VSTD::__cond_swap<_Compare>(__x3, __x4, __c);
253 _VSTD::__cond_swap<_Compare>(__x2, __x3, __c);
254}
255
256template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
257inline _LIBCPP_HIDE_FROM_ABI __enable_if_t<!__use_branchless_sort<_Compare, _RandomAccessIterator>::value, void>
258__sort4_maybe_branchless(_RandomAccessIterator __x1, _RandomAccessIterator __x2, _RandomAccessIterator __x3,
259 _RandomAccessIterator __x4, _Compare __c) {
260 std::__sort4<_AlgPolicy, _Compare>(__x1, __x2, __x3, __x4, __c);
261}
262
263template <class, class _Compare, class _RandomAccessIterator>
264inline _LIBCPP_HIDE_FROM_ABI __enable_if_t<__use_branchless_sort<_Compare, _RandomAccessIterator>::value, void>
265__sort5_maybe_branchless(_RandomAccessIterator __x1, _RandomAccessIterator __x2, _RandomAccessIterator __x3,
266 _RandomAccessIterator __x4, _RandomAccessIterator __x5, _Compare __c) {
267 _VSTD::__cond_swap<_Compare>(__x1, __x2, __c);
268 _VSTD::__cond_swap<_Compare>(__x4, __x5, __c);
269 _VSTD::__partially_sorted_swap<_Compare>(__x3, __x4, __x5, __c);
270 _VSTD::__cond_swap<_Compare>(__x2, __x5, __c);
271 _VSTD::__partially_sorted_swap<_Compare>(__x1, __x3, __x4, __c);
272 _VSTD::__partially_sorted_swap<_Compare>(__x2, __x3, __x4, __c);
273}
274
275template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
276inline _LIBCPP_HIDE_FROM_ABI __enable_if_t<!__use_branchless_sort<_Compare, _RandomAccessIterator>::value, void>
277__sort5_maybe_branchless(_RandomAccessIterator __x1, _RandomAccessIterator __x2, _RandomAccessIterator __x3,
278 _RandomAccessIterator __x4, _RandomAccessIterator __x5, _Compare __c) {
279 std::__sort5_wrap_policy<_AlgPolicy, _Compare>(__x1, __x2, __x3, __x4, __x5, __c);
124280}
125281
126282// Assumes size > 0
127template <class _Compare, class _BidirectionalIterator>
128_LIBCPP_CONSTEXPR_AFTER_CXX11 void
129__selection_sort(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp)
130{
131 _BidirectionalIterator __lm1 = __last;
132 for (--__lm1; __first != __lm1; ++__first)
133 {
134 _BidirectionalIterator __i = _VSTD::min_element(__first, __last, __comp);
135 if (__i != __first)
136 swap(*__first, *__i);
283template <class _AlgPolicy, class _Compare, class _BidirectionalIterator>
284_LIBCPP_CONSTEXPR_AFTER_CXX11 void __selection_sort(_BidirectionalIterator __first, _BidirectionalIterator __last,
285 _Compare __comp) {
286 _BidirectionalIterator __lm1 = __last;
287 for (--__lm1; __first != __lm1; ++__first) {
288 _BidirectionalIterator __i = std::__min_element<_Compare>(__first, __last, __comp);
289 if (__i != __first)
290 _IterOps<_AlgPolicy>::iter_swap(__first, __i);
291 }
292}
293
294template <class _AlgPolicy, class _Compare, class _BidirectionalIterator>
295void __insertion_sort(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) {
296 using _Ops = _IterOps<_AlgPolicy>;
297
298 typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
299 if (__first != __last) {
300 _BidirectionalIterator __i = __first;
301 for (++__i; __i != __last; ++__i) {
302 _BidirectionalIterator __j = __i;
303 value_type __t(_Ops::__iter_move(__j));
304 for (_BidirectionalIterator __k = __i; __k != __first && __comp(__t, *--__k); --__j)
305 *__j = _Ops::__iter_move(__k);
306 *__j = _VSTD::move(__t);
137307 }
308 }
138309}
139310
140template <class _Compare, class _BidirectionalIterator>
141void
142__insertion_sort(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp)
143{
144 typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
145 if (__first != __last)
146 {
147 _BidirectionalIterator __i = __first;
148 for (++__i; __i != __last; ++__i)
149 {
150 _BidirectionalIterator __j = __i;
151 value_type __t(_VSTD::move(*__j));
152 for (_BidirectionalIterator __k = __i; __k != __first && __comp(__t, *--__k); --__j)
153 *__j = _VSTD::move(*__k);
154 *__j = _VSTD::move(__t);
155 }
311template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
312void __insertion_sort_3(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) {
313 using _Ops = _IterOps<_AlgPolicy>;
314
315 typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
316 typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
317 _RandomAccessIterator __j = __first + difference_type(2);
318 std::__sort3_maybe_branchless<_AlgPolicy, _Compare>(__first, __first + difference_type(1), __j, __comp);
319 for (_RandomAccessIterator __i = __j + difference_type(1); __i != __last; ++__i) {
320 if (__comp(*__i, *__j)) {
321 value_type __t(_Ops::__iter_move(__i));
322 _RandomAccessIterator __k = __j;
323 __j = __i;
324 do {
325 *__j = _Ops::__iter_move(__k);
326 __j = __k;
327 } while (__j != __first && __comp(__t, *--__k));
328 *__j = _VSTD::move(__t);
156329 }
330 __j = __i;
331 }
157332}
158333
159template <class _Compare, class _RandomAccessIterator>
160void
161__insertion_sort_3(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
162{
163 typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
164 typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
165 _RandomAccessIterator __j = __first+difference_type(2);
166 _VSTD::__sort3<_Compare>(__first, __first+difference_type(1), __j, __comp);
167 for (_RandomAccessIterator __i = __j+difference_type(1); __i != __last; ++__i)
168 {
169 if (__comp(*__i, *__j))
170 {
171 value_type __t(_VSTD::move(*__i));
172 _RandomAccessIterator __k = __j;
173 __j = __i;
174 do
175 {
176 *__j = _VSTD::move(*__k);
177 __j = __k;
178 } while (__j != __first && __comp(__t, *--__k));
179 *__j = _VSTD::move(__t);
180 }
181 __j = __i;
334template <class _WrappedComp, class _RandomAccessIterator>
335bool __insertion_sort_incomplete(
336 _RandomAccessIterator __first, _RandomAccessIterator __last, _WrappedComp __wrapped_comp) {
337 using _Unwrap = _UnwrapAlgPolicy<_WrappedComp>;
338 using _AlgPolicy = typename _Unwrap::_AlgPolicy;
339 using _Ops = _IterOps<_AlgPolicy>;
340
341 using _Compare = typename _Unwrap::_Comp;
342 _Compare __comp = _Unwrap::__get_comp(__wrapped_comp);
343
344 typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
345 switch (__last - __first) {
346 case 0:
347 case 1:
348 return true;
349 case 2:
350 if (__comp(*--__last, *__first))
351 _IterOps<_AlgPolicy>::iter_swap(__first, __last);
352 return true;
353 case 3:
354 std::__sort3_maybe_branchless<_AlgPolicy, _Compare>(__first, __first + difference_type(1), --__last, __comp);
355 return true;
356 case 4:
357 std::__sort4_maybe_branchless<_AlgPolicy, _Compare>(
358 __first, __first + difference_type(1), __first + difference_type(2), --__last, __comp);
359 return true;
360 case 5:
361 std::__sort5_maybe_branchless<_AlgPolicy, _Compare>(
362 __first, __first + difference_type(1), __first + difference_type(2), __first + difference_type(3),
363 --__last, __comp);
364 return true;
365 }
366 typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
367 _RandomAccessIterator __j = __first + difference_type(2);
368 std::__sort3_maybe_branchless<_AlgPolicy, _Compare>(__first, __first + difference_type(1), __j, __comp);
369 const unsigned __limit = 8;
370 unsigned __count = 0;
371 for (_RandomAccessIterator __i = __j + difference_type(1); __i != __last; ++__i) {
372 if (__comp(*__i, *__j)) {
373 value_type __t(_Ops::__iter_move(__i));
374 _RandomAccessIterator __k = __j;
375 __j = __i;
376 do {
377 *__j = _Ops::__iter_move(__k);
378 __j = __k;
379 } while (__j != __first && __comp(__t, *--__k));
380 *__j = _VSTD::move(__t);
381 if (++__count == __limit)
382 return ++__i == __last;
182383 }
384 __j = __i;
385 }
386 return true;
183387}
184388
185template <class _Compare, class _RandomAccessIterator>
186bool
187__insertion_sort_incomplete(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
188{
189 typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
190 switch (__last - __first)
191 {
389template <class _AlgPolicy, class _Compare, class _BidirectionalIterator>
390void __insertion_sort_move(_BidirectionalIterator __first1, _BidirectionalIterator __last1,
391 typename iterator_traits<_BidirectionalIterator>::value_type* __first2, _Compare __comp) {
392 using _Ops = _IterOps<_AlgPolicy>;
393
394 typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
395 if (__first1 != __last1) {
396 __destruct_n __d(0);
397 unique_ptr<value_type, __destruct_n&> __h(__first2, __d);
398 value_type* __last2 = __first2;
399 ::new ((void*)__last2) value_type(_Ops::__iter_move(__first1));
400 __d.template __incr<value_type>();
401 for (++__last2; ++__first1 != __last1; ++__last2) {
402 value_type* __j2 = __last2;
403 value_type* __i2 = __j2;
404 if (__comp(*__first1, *--__i2)) {
405 ::new ((void*)__j2) value_type(std::move(*__i2));
406 __d.template __incr<value_type>();
407 for (--__j2; __i2 != __first2 && __comp(*__first1, *--__i2); --__j2)
408 *__j2 = std::move(*__i2);
409 *__j2 = _Ops::__iter_move(__first1);
410 } else {
411 ::new ((void*)__j2) value_type(_Ops::__iter_move(__first1));
412 __d.template __incr<value_type>();
413 }
414 }
415 __h.release();
416 }
417}
418
419template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
420void __introsort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp,
421 typename iterator_traits<_RandomAccessIterator>::difference_type __depth) {
422 using _Ops = _IterOps<_AlgPolicy>;
423
424 typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
425 typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
426 const difference_type __limit =
427 is_trivially_copy_constructible<value_type>::value && is_trivially_copy_assignable<value_type>::value ? 30 : 6;
428 while (true) {
429 __restart:
430 difference_type __len = __last - __first;
431 switch (__len) {
192432 case 0:
193433 case 1:
194 return true;
434 return;
195435 case 2:
196 if (__comp(*--__last, *__first))
197 swap(*__first, *__last);
198 return true;
436 if (__comp(*--__last, *__first))
437 _IterOps<_AlgPolicy>::iter_swap(__first, __last);
438 return;
199439 case 3:
200 _VSTD::__sort3<_Compare>(__first, __first+difference_type(1), --__last, __comp);
201 return true;
440 std::__sort3_maybe_branchless<_AlgPolicy, _Compare>(__first, __first + difference_type(1), --__last, __comp);
441 return;
202442 case 4:
203 _VSTD::__sort4<_Compare>(__first, __first+difference_type(1), __first+difference_type(2), --__last, __comp);
204 return true;
443 std::__sort4_maybe_branchless<_AlgPolicy, _Compare>(
444 __first, __first + difference_type(1), __first + difference_type(2), --__last, __comp);
445 return;
205446 case 5:
206 _VSTD::__sort5<_Compare>(__first, __first+difference_type(1), __first+difference_type(2), __first+difference_type(3), --__last, __comp);
207 return true;
447 std::__sort5_maybe_branchless<_AlgPolicy, _Compare>(
448 __first, __first + difference_type(1), __first + difference_type(2), __first + difference_type(3),
449 --__last, __comp);
450 return;
208451 }
209 typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
210 _RandomAccessIterator __j = __first+difference_type(2);
211 _VSTD::__sort3<_Compare>(__first, __first+difference_type(1), __j, __comp);
212 const unsigned __limit = 8;
213 unsigned __count = 0;
214 for (_RandomAccessIterator __i = __j+difference_type(1); __i != __last; ++__i)
215 {
216 if (__comp(*__i, *__j))
217 {
218 value_type __t(_VSTD::move(*__i));
219 _RandomAccessIterator __k = __j;
220 __j = __i;
221 do
222 {
223 *__j = _VSTD::move(*__k);
224 __j = __k;
225 } while (__j != __first && __comp(__t, *--__k));
226 *__j = _VSTD::move(__t);
227 if (++__count == __limit)
228 return ++__i == __last;
229 }
230 __j = __i;
452 if (__len <= __limit) {
453 std::__insertion_sort_3<_AlgPolicy, _Compare>(__first, __last, __comp);
454 return;
231455 }
232 return true;
233}
234
235template <class _Compare, class _BidirectionalIterator>
236void
237__insertion_sort_move(_BidirectionalIterator __first1, _BidirectionalIterator __last1,
238 typename iterator_traits<_BidirectionalIterator>::value_type* __first2, _Compare __comp)
239{
240 typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
241 if (__first1 != __last1)
456 // __len > 5
457 if (__depth == 0) {
458 // Fallback to heap sort as Introsort suggests.
459 std::__partial_sort<_AlgPolicy, _Compare>(__first, __last, __last, __comp);
460 return;
461 }
462 --__depth;
463 _RandomAccessIterator __m = __first;
464 _RandomAccessIterator __lm1 = __last;
465 --__lm1;
466 unsigned __n_swaps;
242467 {
243 __destruct_n __d(0);
244 unique_ptr<value_type, __destruct_n&> __h(__first2, __d);
245 value_type* __last2 = __first2;
246 ::new ((void*)__last2) value_type(_VSTD::move(*__first1));
247 __d.template __incr<value_type>();
248 for (++__last2; ++__first1 != __last1; ++__last2)
249 {
250 value_type* __j2 = __last2;
251 value_type* __i2 = __j2;
252 if (__comp(*__first1, *--__i2))
253 {
254 ::new ((void*)__j2) value_type(_VSTD::move(*__i2));
255 __d.template __incr<value_type>();
256 for (--__j2; __i2 != __first2 && __comp(*__first1, *--__i2); --__j2)
257 *__j2 = _VSTD::move(*__i2);
258 *__j2 = _VSTD::move(*__first1);
259 }
260 else
261 {
262 ::new ((void*)__j2) value_type(_VSTD::move(*__first1));
263 __d.template __incr<value_type>();
264 }
265 }
266 __h.release();
468 difference_type __delta;
469 if (__len >= 1000) {
470 __delta = __len / 2;
471 __m += __delta;
472 __delta /= 2;
473 __n_swaps = std::__sort5_wrap_policy<_AlgPolicy, _Compare>(
474 __first, __first + __delta, __m, __m + __delta, __lm1, __comp);
475 } else {
476 __delta = __len / 2;
477 __m += __delta;
478 __n_swaps = std::__sort3<_AlgPolicy, _Compare>(__first, __m, __lm1, __comp);
479 }
267480 }
268}
269
270template <class _Compare, class _RandomAccessIterator>
271void
272__introsort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp,
273 typename iterator_traits<_RandomAccessIterator>::difference_type __depth)
274{
275 typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
276 typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
277 const difference_type __limit = is_trivially_copy_constructible<value_type>::value &&
278 is_trivially_copy_assignable<value_type>::value ? 30 : 6;
279 while (true)
481 // *__m is median
482 // partition [__first, __m) < *__m and *__m <= [__m, __last)
483 // (this inhibits tossing elements equivalent to __m around unnecessarily)
484 _RandomAccessIterator __i = __first;
485 _RandomAccessIterator __j = __lm1;
486 // j points beyond range to be tested, *__m is known to be <= *__lm1
487 // The search going up is known to be guarded but the search coming down isn't.
488 // Prime the downward search with a guard.
489 if (!__comp(*__i, *__m)) // if *__first == *__m
280490 {
281 __restart:
282 difference_type __len = __last - __first;
283 switch (__len)
284 {
285 case 0:
286 case 1:
287 return;
288 case 2:
289 if (__comp(*--__last, *__first))
290 swap(*__first, *__last);
291 return;
292 case 3:
293 _VSTD::__sort3<_Compare>(__first, __first+difference_type(1), --__last, __comp);
294 return;
295 case 4:
296 _VSTD::__sort4<_Compare>(__first, __first+difference_type(1), __first+difference_type(2), --__last, __comp);
297 return;
298 case 5:
299 _VSTD::__sort5<_Compare>(__first, __first+difference_type(1), __first+difference_type(2), __first+difference_type(3), --__last, __comp);
300 return;
301 }
302 if (__len <= __limit)
303 {
304 _VSTD::__insertion_sort_3<_Compare>(__first, __last, __comp);
305 return;
306 }
307 // __len > 5
308 if (__depth == 0)
309 {
310 // Fallback to heap sort as Introsort suggests.
311 _VSTD::__partial_sort<_Compare>(__first, __last, __last, __comp);
312 return;
313 }
314 --__depth;
315 _RandomAccessIterator __m = __first;
316 _RandomAccessIterator __lm1 = __last;
317 --__lm1;
318 unsigned __n_swaps;
319 {
320 difference_type __delta;
321 if (__len >= 1000)
322 {
323 __delta = __len/2;
324 __m += __delta;
325 __delta /= 2;
326 __n_swaps = _VSTD::__sort5<_Compare>(__first, __first + __delta, __m, __m+__delta, __lm1, __comp);
327 }
328 else
329 {
330 __delta = __len/2;
331 __m += __delta;
332 __n_swaps = _VSTD::__sort3<_Compare>(__first, __m, __lm1, __comp);
333 }
334 }
335 // *__m is median
336 // partition [__first, __m) < *__m and *__m <= [__m, __last)
337 // (this inhibits tossing elements equivalent to __m around unnecessarily)
338 _RandomAccessIterator __i = __first;
339 _RandomAccessIterator __j = __lm1;
340 // j points beyond range to be tested, *__m is known to be <= *__lm1
341 // The search going up is known to be guarded but the search coming down isn't.
342 // Prime the downward search with a guard.
343 if (!__comp(*__i, *__m)) // if *__first == *__m
344 {
345 // *__first == *__m, *__first doesn't go in first part
346 // manually guard downward moving __j against __i
347 while (true)
348 {
349 if (__i == --__j)
350 {
351 // *__first == *__m, *__m <= all other elements
352 // Parition instead into [__first, __i) == *__first and *__first < [__i, __last)
353 ++__i; // __first + 1
354 __j = __last;
355 if (!__comp(*__first, *--__j)) // we need a guard if *__first == *(__last-1)
356 {
357 while (true)
358 {
359 if (__i == __j)
360 return; // [__first, __last) all equivalent elements
361 if (__comp(*__first, *__i))
362 {
363 swap(*__i, *__j);
364 ++__n_swaps;
365 ++__i;
366 break;
367 }
368 ++__i;
369 }
370 }
371 // [__first, __i) == *__first and *__first < [__j, __last) and __j == __last - 1
372 if (__i == __j)
373 return;
374 while (true)
375 {
376 while (!__comp(*__first, *__i))
377 ++__i;
378 while (__comp(*__first, *--__j))
379 ;
380 if (__i >= __j)
381 break;
382 swap(*__i, *__j);
383 ++__n_swaps;
384 ++__i;
385 }
386 // [__first, __i) == *__first and *__first < [__i, __last)
387 // The first part is sorted, sort the second part
388 // _VSTD::__sort<_Compare>(__i, __last, __comp);
389 __first = __i;
390 goto __restart;
391 }
392 if (__comp(*__j, *__m))
393 {
394 swap(*__i, *__j);
395 ++__n_swaps;
396 break; // found guard for downward moving __j, now use unguarded partition
397 }
398 }
399 }
400 // It is known that *__i < *__m
401 ++__i;
402 // j points beyond range to be tested, *__m is known to be <= *__lm1
403 // if not yet partitioned...
404 if (__i < __j)
405 {
406 // known that *(__i - 1) < *__m
407 // known that __i <= __m
408 while (true)
409 {
410 // __m still guards upward moving __i
411 while (__comp(*__i, *__m))
412 ++__i;
413 // It is now known that a guard exists for downward moving __j
414 while (!__comp(*--__j, *__m))
415 ;
416 if (__i > __j)
417 break;
418 swap(*__i, *__j);
491 // *__first == *__m, *__first doesn't go in first part
492 // manually guard downward moving __j against __i
493 while (true) {
494 if (__i == --__j) {
495 // *__first == *__m, *__m <= all other elements
496 // Parition instead into [__first, __i) == *__first and *__first < [__i, __last)
497 ++__i; // __first + 1
498 __j = __last;
499 if (!__comp(*__first, *--__j)) // we need a guard if *__first == *(__last-1)
500 {
501 while (true) {
502 if (__i == __j)
503 return; // [__first, __last) all equivalent elements
504 if (__comp(*__first, *__i)) {
505 _Ops::iter_swap(__i, __j);
419506 ++__n_swaps;
420 // It is known that __m != __j
421 // If __m just moved, follow it
422 if (__m == __i)
423 __m = __j;
424507 ++__i;
508 break;
509 }
510 ++__i;
425511 }
426 }
427 // [__first, __i) < *__m and *__m <= [__i, __last)
428 if (__i != __m && __comp(*__m, *__i))
429 {
430 swap(*__i, *__m);
512 }
513 // [__first, __i) == *__first and *__first < [__j, __last) and __j == __last - 1
514 if (__i == __j)
515 return;
516 while (true) {
517 while (!__comp(*__first, *__i))
518 ++__i;
519 while (__comp(*__first, *--__j))
520 ;
521 if (__i >= __j)
522 break;
523 _Ops::iter_swap(__i, __j);
431524 ++__n_swaps;
525 ++__i;
526 }
527 // [__first, __i) == *__first and *__first < [__i, __last)
528 // The first part is sorted, sort the second part
529 // _VSTD::__sort<_Compare>(__i, __last, __comp);
530 __first = __i;
531 goto __restart;
432532 }
433 // [__first, __i) < *__i and *__i <= [__i+1, __last)
434 // If we were given a perfect partition, see if insertion sort is quick...
435 if (__n_swaps == 0)
436 {
437 bool __fs = _VSTD::__insertion_sort_incomplete<_Compare>(__first, __i, __comp);
438 if (_VSTD::__insertion_sort_incomplete<_Compare>(__i+difference_type(1), __last, __comp))
439 {
440 if (__fs)
441 return;
442 __last = __i;
443 continue;
444 }
445 else
446 {
447 if (__fs)
448 {
449 __first = ++__i;
450 continue;
451 }
452 }
533 if (__comp(*__j, *__m)) {
534 _Ops::iter_swap(__i, __j);
535 ++__n_swaps;
536 break; // found guard for downward moving __j, now use unguarded partition
453537 }
454 // sort smaller range with recursive call and larger with tail recursion elimination
455 if (__i - __first < __last - __i)
456 {
457 _VSTD::__introsort<_Compare>(__first, __i, __comp, __depth);
538 }
539 }
540 // It is known that *__i < *__m
541 ++__i;
542 // j points beyond range to be tested, *__m is known to be <= *__lm1
543 // if not yet partitioned...
544 if (__i < __j) {
545 // known that *(__i - 1) < *__m
546 // known that __i <= __m
547 while (true) {
548 // __m still guards upward moving __i
549 while (__comp(*__i, *__m))
550 ++__i;
551 // It is now known that a guard exists for downward moving __j
552 while (!__comp(*--__j, *__m))
553 ;
554 if (__i > __j)
555 break;
556 _Ops::iter_swap(__i, __j);
557 ++__n_swaps;
558 // It is known that __m != __j
559 // If __m just moved, follow it
560 if (__m == __i)
561 __m = __j;
562 ++__i;
563 }
564 }
565 // [__first, __i) < *__m and *__m <= [__i, __last)
566 if (__i != __m && __comp(*__m, *__i)) {
567 _Ops::iter_swap(__i, __m);
568 ++__n_swaps;
569 }
570 // [__first, __i) < *__i and *__i <= [__i+1, __last)
571 // If we were given a perfect partition, see if insertion sort is quick...
572 if (__n_swaps == 0) {
573 using _WrappedComp = typename _WrapAlgPolicy<_AlgPolicy, _Compare>::type;
574 _WrappedComp __wrapped_comp(__comp);
575 bool __fs = std::__insertion_sort_incomplete<_WrappedComp>(__first, __i, __wrapped_comp);
576 if (std::__insertion_sort_incomplete<_WrappedComp>(__i + difference_type(1), __last, __wrapped_comp)) {
577 if (__fs)
578 return;
579 __last = __i;
580 continue;
581 } else {
582 if (__fs) {
458583 __first = ++__i;
584 continue;
459585 }
460 else
461 {
462 _VSTD::__introsort<_Compare>(__i + difference_type(1), __last, __comp, __depth);
463 __last = __i;
464 }
586 }
465587 }
588 // sort smaller range with recursive call and larger with tail recursion elimination
589 if (__i - __first < __last - __i) {
590 std::__introsort<_AlgPolicy, _Compare>(__first, __i, __comp, __depth);
591 __first = ++__i;
592 } else {
593 std::__introsort<_AlgPolicy, _Compare>(__i + difference_type(1), __last, __comp, __depth);
594 __last = __i;
595 }
596 }
466597}
467598
468599template <typename _Number>
469600inline _LIBCPP_HIDE_FROM_ABI _Number __log2i(_Number __n) {
601 if (__n == 0)
602 return 0;
603 if (sizeof(__n) <= sizeof(unsigned))
604 return sizeof(unsigned) * CHAR_BIT - 1 - __libcpp_clz(static_cast<unsigned>(__n));
605 if (sizeof(__n) <= sizeof(unsigned long))
606 return sizeof(unsigned long) * CHAR_BIT - 1 - __libcpp_clz(static_cast<unsigned long>(__n));
607 if (sizeof(__n) <= sizeof(unsigned long long))
608 return sizeof(unsigned long long) * CHAR_BIT - 1 - __libcpp_clz(static_cast<unsigned long long>(__n));
609
470610 _Number __log2 = 0;
471611 while (__n > 1) {
472612 __log2++;
......@@ -475,80 +615,89 @@ inline _LIBCPP_HIDE_FROM_ABI _Number __log2i(_Number __n) {
475615 return __log2;
476616}
477617
478template <class _Compare, class _RandomAccessIterator>
479void __sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) {
618template <class _WrappedComp, class _RandomAccessIterator>
619void __sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _WrappedComp __wrapped_comp) {
480620 typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
481621 difference_type __depth_limit = 2 * __log2i(__last - __first);
482 _VSTD::__introsort<_Compare>(__first, __last, __comp, __depth_limit);
622
623 using _Unwrap = _UnwrapAlgPolicy<_WrappedComp>;
624 using _AlgPolicy = typename _Unwrap::_AlgPolicy;
625 using _Compare = typename _Unwrap::_Comp;
626 _Compare __comp = _Unwrap::__get_comp(__wrapped_comp);
627 std::__introsort<_AlgPolicy, _Compare>(__first, __last, __comp, __depth_limit);
483628}
484629
485630template <class _Compare, class _Tp>
486inline _LIBCPP_INLINE_VISIBILITY
487void
488__sort(_Tp** __first, _Tp** __last, __less<_Tp*>&)
489{
490 __less<uintptr_t> __comp;
491 _VSTD::__sort<__less<uintptr_t>&, uintptr_t*>((uintptr_t*)__first, (uintptr_t*)__last, __comp);
631inline _LIBCPP_INLINE_VISIBILITY void __sort(_Tp** __first, _Tp** __last, __less<_Tp*>&) {
632 __less<uintptr_t> __comp;
633 std::__sort<__less<uintptr_t>&, uintptr_t*>((uintptr_t*)__first, (uintptr_t*)__last, __comp);
492634}
493635
494_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<char>&, char*>(char*, char*, __less<char>&))
636extern template _LIBCPP_FUNC_VIS void __sort<__less<char>&, char*>(char*, char*, __less<char>&);
495637#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
496_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&))
638extern template _LIBCPP_FUNC_VIS void __sort<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&);
497639#endif
498_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&))
499_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<unsigned char>&, unsigned char*>(unsigned char*, unsigned char*, __less<unsigned char>&))
500_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<short>&, short*>(short*, short*, __less<short>&))
501_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<unsigned short>&, unsigned short*>(unsigned short*, unsigned short*, __less<unsigned short>&))
502_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<int>&, int*>(int*, int*, __less<int>&))
503_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<unsigned>&, unsigned*>(unsigned*, unsigned*, __less<unsigned>&))
504_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<long>&, long*>(long*, long*, __less<long>&))
505_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<unsigned long>&, unsigned long*>(unsigned long*, unsigned long*, __less<unsigned long>&))
506_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<long long>&, long long*>(long long*, long long*, __less<long long>&))
507_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<unsigned long long>&, unsigned long long*>(unsigned long long*, unsigned long long*, __less<unsigned long long>&))
508_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<float>&, float*>(float*, float*, __less<float>&))
509_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<double>&, double*>(double*, double*, __less<double>&))
510_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<long double>&, long double*>(long double*, long double*, __less<long double>&))
511
512_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<char>&, char*>(char*, char*, __less<char>&))
640extern template _LIBCPP_FUNC_VIS void __sort<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&);
641extern template _LIBCPP_FUNC_VIS void __sort<__less<unsigned char>&, unsigned char*>(unsigned char*, unsigned char*, __less<unsigned char>&);
642extern template _LIBCPP_FUNC_VIS void __sort<__less<short>&, short*>(short*, short*, __less<short>&);
643extern template _LIBCPP_FUNC_VIS void __sort<__less<unsigned short>&, unsigned short*>(unsigned short*, unsigned short*, __less<unsigned short>&);
644extern template _LIBCPP_FUNC_VIS void __sort<__less<int>&, int*>(int*, int*, __less<int>&);
645extern template _LIBCPP_FUNC_VIS void __sort<__less<unsigned>&, unsigned*>(unsigned*, unsigned*, __less<unsigned>&);
646extern template _LIBCPP_FUNC_VIS void __sort<__less<long>&, long*>(long*, long*, __less<long>&);
647extern template _LIBCPP_FUNC_VIS void __sort<__less<unsigned long>&, unsigned long*>(unsigned long*, unsigned long*, __less<unsigned long>&);
648extern template _LIBCPP_FUNC_VIS void __sort<__less<long long>&, long long*>(long long*, long long*, __less<long long>&);
649extern template _LIBCPP_FUNC_VIS void __sort<__less<unsigned long long>&, unsigned long long*>(unsigned long long*, unsigned long long*, __less<unsigned long long>&);
650extern template _LIBCPP_FUNC_VIS void __sort<__less<float>&, float*>(float*, float*, __less<float>&);
651extern template _LIBCPP_FUNC_VIS void __sort<__less<double>&, double*>(double*, double*, __less<double>&);
652extern template _LIBCPP_FUNC_VIS void __sort<__less<long double>&, long double*>(long double*, long double*, __less<long double>&);
653
654extern template _LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<char>&, char*>(char*, char*, __less<char>&);
513655#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
514_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&))
656extern template _LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&);
515657#endif
516_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&))
517_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<unsigned char>&, unsigned char*>(unsigned char*, unsigned char*, __less<unsigned char>&))
518_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<short>&, short*>(short*, short*, __less<short>&))
519_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<unsigned short>&, unsigned short*>(unsigned short*, unsigned short*, __less<unsigned short>&))
520_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<int>&, int*>(int*, int*, __less<int>&))
521_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<unsigned>&, unsigned*>(unsigned*, unsigned*, __less<unsigned>&))
522_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<long>&, long*>(long*, long*, __less<long>&))
523_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<unsigned long>&, unsigned long*>(unsigned long*, unsigned long*, __less<unsigned long>&))
524_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<long long>&, long long*>(long long*, long long*, __less<long long>&))
525_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<unsigned long long>&, unsigned long long*>(unsigned long long*, unsigned long long*, __less<unsigned long long>&))
526_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<float>&, float*>(float*, float*, __less<float>&))
527_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<double>&, double*>(double*, double*, __less<double>&))
528_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<long double>&, long double*>(long double*, long double*, __less<long double>&))
529
530_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS unsigned __sort5<__less<long double>&, long double*>(long double*, long double*, long double*, long double*, long double*, __less<long double>&))
531
532template <class _RandomAccessIterator, class _Compare>
533inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
534void
535sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
536{
537 _LIBCPP_DEBUG_RANDOMIZE_RANGE(__first, __last);
538 typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
658extern template _LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&);
659extern template _LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<unsigned char>&, unsigned char*>(unsigned char*, unsigned char*, __less<unsigned char>&);
660extern template _LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<short>&, short*>(short*, short*, __less<short>&);
661extern template _LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<unsigned short>&, unsigned short*>(unsigned short*, unsigned short*, __less<unsigned short>&);
662extern template _LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<int>&, int*>(int*, int*, __less<int>&);
663extern template _LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<unsigned>&, unsigned*>(unsigned*, unsigned*, __less<unsigned>&);
664extern template _LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<long>&, long*>(long*, long*, __less<long>&);
665extern template _LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<unsigned long>&, unsigned long*>(unsigned long*, unsigned long*, __less<unsigned long>&);
666extern template _LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<long long>&, long long*>(long long*, long long*, __less<long long>&);
667extern template _LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<unsigned long long>&, unsigned long long*>(unsigned long long*, unsigned long long*, __less<unsigned long long>&);
668extern template _LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<float>&, float*>(float*, float*, __less<float>&);
669extern template _LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<double>&, double*>(double*, double*, __less<double>&);
670extern template _LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<long double>&, long double*>(long double*, long double*, __less<long double>&);
671
672extern template _LIBCPP_FUNC_VIS unsigned __sort5<__less<long double>&, long double*>(long double*, long double*, long double*, long double*, long double*, __less<long double>&);
673
674template <class _AlgPolicy, class _RandomAccessIterator, class _Comp>
675inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
676void __sort_impl(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp& __comp) {
677 std::__debug_randomize_range<_AlgPolicy>(__first, __last);
678
679 using _Comp_ref = typename __comp_ref_type<_Comp>::type;
539680 if (__libcpp_is_constant_evaluated()) {
540 _VSTD::__partial_sort<_Comp_ref>(__first, __last, __last, _Comp_ref(__comp));
681 std::__partial_sort<_AlgPolicy>(__first, __last, __last, __comp);
682
541683 } else {
542 _VSTD::__sort<_Comp_ref>(_VSTD::__unwrap_iter(__first), _VSTD::__unwrap_iter(__last), _Comp_ref(__comp));
684 using _WrappedComp = typename _WrapAlgPolicy<_AlgPolicy, _Comp_ref>::type;
685 _Comp_ref __comp_ref(__comp);
686 _WrappedComp __wrapped_comp(__comp_ref);
687 std::__sort<_WrappedComp>(std::__unwrap_iter(__first), std::__unwrap_iter(__last), __wrapped_comp);
543688 }
544689}
545690
691template <class _RandomAccessIterator, class _Comp>
692inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
693void sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp __comp) {
694 std::__sort_impl<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __comp);
695}
696
546697template <class _RandomAccessIterator>
547inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
548void
549sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
550{
551 _VSTD::sort(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
698inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
699void sort(_RandomAccessIterator __first, _RandomAccessIterator __last) {
700 std::sort(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
552701}
553702
554703_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__algorithm/sort_heap.h+23-20
......@@ -11,41 +11,44 @@
1111
1212#include <__algorithm/comp.h>
1313#include <__algorithm/comp_ref_type.h>
14#include <__algorithm/iterator_operations.h>
1415#include <__algorithm/pop_heap.h>
1516#include <__config>
1617#include <__iterator/iterator_traits.h>
17#include <type_traits> // swap
18#include <__utility/move.h>
19#include <type_traits>
1820
1921#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20#pragma GCC system_header
22# pragma GCC system_header
2123#endif
2224
2325_LIBCPP_BEGIN_NAMESPACE_STD
2426
25template <class _Compare, class _RandomAccessIterator>
26_LIBCPP_CONSTEXPR_AFTER_CXX17 void
27__sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
28{
29 typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
30 for (difference_type __n = __last - __first; __n > 1; --__last, (void) --__n)
31 _VSTD::__pop_heap<_Compare>(__first, __last, __comp, __n);
27template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
28inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
29void __sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare&& __comp) {
30 using _CompRef = typename __comp_ref_type<_Compare>::type;
31 _CompRef __comp_ref = __comp;
32
33 using difference_type = typename iterator_traits<_RandomAccessIterator>::difference_type;
34 for (difference_type __n = __last - __first; __n > 1; --__last, (void) --__n)
35 std::__pop_heap<_AlgPolicy>(__first, __last, __comp_ref, __n);
3236}
3337
3438template <class _RandomAccessIterator, class _Compare>
35inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
36void
37sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
38{
39 typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
40 _VSTD::__sort_heap<_Comp_ref>(__first, __last, __comp);
39inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
40void sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) {
41 static_assert(std::is_copy_constructible<_RandomAccessIterator>::value, "Iterators must be copy constructible.");
42 static_assert(std::is_copy_assignable<_RandomAccessIterator>::value, "Iterators must be copy assignable.");
43
44 std::__sort_heap<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __comp);
4145}
4246
4347template <class _RandomAccessIterator>
44inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
45void
46sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
47{
48 _VSTD::sort_heap(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
48inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
49void sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) {
50 std::sort_heap(std::move(__first), std::move(__last),
51 __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
4952}
5053
5154_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__algorithm/stable_partition.h+67-38
......@@ -9,23 +9,28 @@
99#ifndef _LIBCPP___ALGORITHM_STABLE_PARTITION_H
1010#define _LIBCPP___ALGORITHM_STABLE_PARTITION_H
1111
12#include <__algorithm/iterator_operations.h>
1213#include <__algorithm/rotate.h>
1314#include <__config>
15#include <__iterator/advance.h>
16#include <__iterator/distance.h>
1417#include <__iterator/iterator_traits.h>
15#include <__utility/swap.h>
1618#include <memory>
19#include <type_traits>
1720
1821#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
22# pragma GCC system_header
2023#endif
2124
2225_LIBCPP_BEGIN_NAMESPACE_STD
2326
24template <class _Predicate, class _ForwardIterator, class _Distance, class _Pair>
27template <class _AlgPolicy, class _Predicate, class _ForwardIterator, class _Distance, class _Pair>
2528_ForwardIterator
26__stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred,
29__stable_partition_impl(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred,
2730 _Distance __len, _Pair __p, forward_iterator_tag __fit)
2831{
32 using _Ops = _IterOps<_AlgPolicy>;
33
2934 // *__first is known to be false
3035 // __len >= 1
3136 if (__len == 1)
......@@ -35,7 +40,7 @@ __stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate
3540 _ForwardIterator __m = __first;
3641 if (__pred(*++__m))
3742 {
38 swap(*__first, *__m);
43 _Ops::iter_swap(__first, __m);
3944 return __m;
4045 }
4146 return __first;
......@@ -48,7 +53,7 @@ __stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate
4853 // Move the falses into the temporary buffer, and the trues to the front of the line
4954 // Update __first to always point to the end of the trues
5055 value_type* __t = __p.first;
51 ::new ((void*)__t) value_type(_VSTD::move(*__first));
56 ::new ((void*)__t) value_type(_Ops::__iter_move(__first));
5257 __d.template __incr<value_type>();
5358 ++__t;
5459 _ForwardIterator __i = __first;
......@@ -56,12 +61,12 @@ __stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate
5661 {
5762 if (__pred(*__i))
5863 {
59 *__first = _VSTD::move(*__i);
64 *__first = _Ops::__iter_move(__i);
6065 ++__first;
6166 }
6267 else
6368 {
64 ::new ((void*)__t) value_type(_VSTD::move(*__i));
69 ::new ((void*)__t) value_type(_Ops::__iter_move(__i));
6570 __d.template __incr<value_type>();
6671 ++__t;
6772 }
......@@ -70,7 +75,7 @@ __stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate
7075 // Move falses back into range, but don't mess up __first which points to first false
7176 __i = __first;
7277 for (value_type* __t2 = __p.first; __t2 < __t; ++__t2, (void) ++__i)
73 *__i = _VSTD::move(*__t2);
78 *__i = _Ops::__iter_move(__t2);
7479 // __h destructs moved-from values out of the temp buffer, but doesn't deallocate buffer
7580 return __first;
7681 }
......@@ -78,11 +83,12 @@ __stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate
7883 // __len >= 3
7984 _ForwardIterator __m = __first;
8085 _Distance __len2 = __len / 2; // __len2 >= 2
81 _VSTD::advance(__m, __len2);
86 _Ops::advance(__m, __len2);
8287 // recurse on [__first, __m), *__first know to be false
8388 // F?????????????????
8489 // f m l
85 _ForwardIterator __first_false = _VSTD::__stable_partition<_Predicate&>(__first, __m, __pred, __len2, __p, __fit);
90 _ForwardIterator __first_false = std::__stable_partition_impl<_AlgPolicy, _Predicate&>(
91 __first, __m, __pred, __len2, __p, __fit);
8692 // TTTFFFFF??????????
8793 // f ff m l
8894 // recurse on [__m, __last], except increase __m until *(__m) is false, *__last know to be true
......@@ -97,18 +103,19 @@ __stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate
97103 }
98104 // TTTFFFFFTTTF??????
99105 // f ff m m1 l
100 __second_false = _VSTD::__stable_partition<_Predicate&>(__m1, __last, __pred, __len_half, __p, __fit);
106 __second_false = std::__stable_partition_impl<_AlgPolicy, _Predicate&>(
107 __m1, __last, __pred, __len_half, __p, __fit);
101108__second_half_done:
102109 // TTTFFFFFTTTTTFFFFF
103110 // f ff m sf l
104 return _VSTD::rotate(__first_false, __m, __second_false);
111 return std::__rotate<_AlgPolicy>(__first_false, __m, __second_false, __fit);
105112 // TTTTTTTTFFFFFFFFFF
106113 // |
107114}
108115
109template <class _Predicate, class _ForwardIterator>
116template <class _AlgPolicy, class _Predicate, class _ForwardIterator>
110117_ForwardIterator
111__stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred,
118__stable_partition_impl(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred,
112119 forward_iterator_tag)
113120{
114121 const unsigned __alloc_limit = 3; // might want to make this a function of trivial assignment
......@@ -125,28 +132,34 @@ __stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate
125132 // *__first is known to be false
126133 typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type;
127134 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
128 difference_type __len = _VSTD::distance(__first, __last);
135 difference_type __len = _IterOps<_AlgPolicy>::distance(__first, __last);
129136 pair<value_type*, ptrdiff_t> __p(0, 0);
130137 unique_ptr<value_type, __return_temporary_buffer> __h;
131138 if (__len >= __alloc_limit)
132139 {
140// TODO: Remove the use of std::get_temporary_buffer
141_LIBCPP_SUPPRESS_DEPRECATED_PUSH
133142 __p = _VSTD::get_temporary_buffer<value_type>(__len);
143_LIBCPP_SUPPRESS_DEPRECATED_POP
134144 __h.reset(__p.first);
135145 }
136 return _VSTD::__stable_partition<_Predicate&>(__first, __last, __pred, __len, __p, forward_iterator_tag());
146 return std::__stable_partition_impl<_AlgPolicy, _Predicate&>(
147 std::move(__first), std::move(__last), __pred, __len, __p, forward_iterator_tag());
137148}
138149
139template <class _Predicate, class _BidirectionalIterator, class _Distance, class _Pair>
150template <class _AlgPolicy, class _Predicate, class _BidirectionalIterator, class _Distance, class _Pair>
140151_BidirectionalIterator
141__stable_partition(_BidirectionalIterator __first, _BidirectionalIterator __last, _Predicate __pred,
152__stable_partition_impl(_BidirectionalIterator __first, _BidirectionalIterator __last, _Predicate __pred,
142153 _Distance __len, _Pair __p, bidirectional_iterator_tag __bit)
143154{
155 using _Ops = _IterOps<_AlgPolicy>;
156
144157 // *__first is known to be false
145158 // *__last is known to be true
146159 // __len >= 2
147160 if (__len == 2)
148161 {
149 swap(*__first, *__last);
162 _Ops::iter_swap(__first, __last);
150163 return __last;
151164 }
152165 if (__len == 3)
......@@ -154,12 +167,12 @@ __stable_partition(_BidirectionalIterator __first, _BidirectionalIterator __last
154167 _BidirectionalIterator __m = __first;
155168 if (__pred(*++__m))
156169 {
157 swap(*__first, *__m);
158 swap(*__m, *__last);
170 _Ops::iter_swap(__first, __m);
171 _Ops::iter_swap(__m, __last);
159172 return __last;
160173 }
161 swap(*__m, *__last);
162 swap(*__first, *__m);
174 _Ops::iter_swap(__m, __last);
175 _Ops::iter_swap(__first, __m);
163176 return __m;
164177 }
165178 if (__len <= __p.second)
......@@ -170,7 +183,7 @@ __stable_partition(_BidirectionalIterator __first, _BidirectionalIterator __last
170183 // Move the falses into the temporary buffer, and the trues to the front of the line
171184 // Update __first to always point to the end of the trues
172185 value_type* __t = __p.first;
173 ::new ((void*)__t) value_type(_VSTD::move(*__first));
186 ::new ((void*)__t) value_type(_Ops::__iter_move(__first));
174187 __d.template __incr<value_type>();
175188 ++__t;
176189 _BidirectionalIterator __i = __first;
......@@ -178,23 +191,23 @@ __stable_partition(_BidirectionalIterator __first, _BidirectionalIterator __last
178191 {
179192 if (__pred(*__i))
180193 {
181 *__first = _VSTD::move(*__i);
194 *__first = _Ops::__iter_move(__i);
182195 ++__first;
183196 }
184197 else
185198 {
186 ::new ((void*)__t) value_type(_VSTD::move(*__i));
199 ::new ((void*)__t) value_type(_Ops::__iter_move(__i));
187200 __d.template __incr<value_type>();
188201 ++__t;
189202 }
190203 }
191204 // move *__last, known to be true
192 *__first = _VSTD::move(*__i);
205 *__first = _Ops::__iter_move(__i);
193206 __i = ++__first;
194207 // All trues now at start of range, all falses in buffer
195208 // Move falses back into range, but don't mess up __first which points to first false
196209 for (value_type* __t2 = __p.first; __t2 < __t; ++__t2, (void) ++__i)
197 *__i = _VSTD::move(*__t2);
210 *__i = _Ops::__iter_move(__t2);
198211 // __h destructs moved-from values out of the temp buffer, but doesn't deallocate buffer
199212 return __first;
200213 }
......@@ -202,7 +215,7 @@ __stable_partition(_BidirectionalIterator __first, _BidirectionalIterator __last
202215 // __len >= 4
203216 _BidirectionalIterator __m = __first;
204217 _Distance __len2 = __len / 2; // __len2 >= 2
205 _VSTD::advance(__m, __len2);
218 _Ops::advance(__m, __len2);
206219 // recurse on [__first, __m-1], except reduce __m-1 until *(__m-1) is true, *__first know to be false
207220 // F????????????????T
208221 // f m l
......@@ -217,7 +230,8 @@ __stable_partition(_BidirectionalIterator __first, _BidirectionalIterator __last
217230 }
218231 // F???TFFF?????????T
219232 // f m1 m l
220 __first_false = _VSTD::__stable_partition<_Predicate&>(__first, __m1, __pred, __len_half, __p, __bit);
233 __first_false = std::__stable_partition_impl<_AlgPolicy, _Predicate&>(
234 __first, __m1, __pred, __len_half, __p, __bit);
221235__first_half_done:
222236 // TTTFFFFF?????????T
223237 // f ff m l
......@@ -234,18 +248,19 @@ __first_half_done:
234248 }
235249 // TTTFFFFFTTTF?????T
236250 // f ff m m1 l
237 __second_false = _VSTD::__stable_partition<_Predicate&>(__m1, __last, __pred, __len_half, __p, __bit);
251 __second_false = std::__stable_partition_impl<_AlgPolicy, _Predicate&>(
252 __m1, __last, __pred, __len_half, __p, __bit);
238253__second_half_done:
239254 // TTTFFFFFTTTTTFFFFF
240255 // f ff m sf l
241 return _VSTD::rotate(__first_false, __m, __second_false);
256 return std::__rotate<_AlgPolicy>(__first_false, __m, __second_false, __bit);
242257 // TTTTTTTTFFFFFFFFFF
243258 // |
244259}
245260
246template <class _Predicate, class _BidirectionalIterator>
261template <class _AlgPolicy, class _Predicate, class _BidirectionalIterator>
247262_BidirectionalIterator
248__stable_partition(_BidirectionalIterator __first, _BidirectionalIterator __last, _Predicate __pred,
263__stable_partition_impl(_BidirectionalIterator __first, _BidirectionalIterator __last, _Predicate __pred,
249264 bidirectional_iterator_tag)
250265{
251266 typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
......@@ -271,15 +286,27 @@ __stable_partition(_BidirectionalIterator __first, _BidirectionalIterator __last
271286 // *__first is known to be false
272287 // *__last is known to be true
273288 // __len >= 2
274 difference_type __len = _VSTD::distance(__first, __last) + 1;
289 difference_type __len = _IterOps<_AlgPolicy>::distance(__first, __last) + 1;
275290 pair<value_type*, ptrdiff_t> __p(0, 0);
276291 unique_ptr<value_type, __return_temporary_buffer> __h;
277292 if (__len >= __alloc_limit)
278293 {
294// TODO: Remove the use of std::get_temporary_buffer
295_LIBCPP_SUPPRESS_DEPRECATED_PUSH
279296 __p = _VSTD::get_temporary_buffer<value_type>(__len);
297_LIBCPP_SUPPRESS_DEPRECATED_POP
280298 __h.reset(__p.first);
281299 }
282 return _VSTD::__stable_partition<_Predicate&>(__first, __last, __pred, __len, __p, bidirectional_iterator_tag());
300 return std::__stable_partition_impl<_AlgPolicy, _Predicate&>(
301 std::move(__first), std::move(__last), __pred, __len, __p, bidirectional_iterator_tag());
302}
303
304template <class _AlgPolicy, class _Predicate, class _ForwardIterator, class _IterCategory>
305_LIBCPP_HIDE_FROM_ABI
306_ForwardIterator __stable_partition(
307 _ForwardIterator __first, _ForwardIterator __last, _Predicate&& __pred, _IterCategory __iter_category) {
308 return std::__stable_partition_impl<_AlgPolicy, __uncvref_t<_Predicate>&>(
309 std::move(__first), std::move(__last), __pred, __iter_category);
283310}
284311
285312template <class _ForwardIterator, class _Predicate>
......@@ -287,7 +314,9 @@ inline _LIBCPP_INLINE_VISIBILITY
287314_ForwardIterator
288315stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
289316{
290 return _VSTD::__stable_partition<_Predicate&>(__first, __last, __pred, typename iterator_traits<_ForwardIterator>::iterator_category());
317 using _IterCategory = typename iterator_traits<_ForwardIterator>::iterator_category;
318 return std::__stable_partition<_ClassicAlgPolicy, _Predicate&>(
319 std::move(__first), std::move(__last), __pred, _IterCategory());
291320}
292321
293322_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__algorithm/stable_sort.h+67-53
......@@ -12,25 +12,28 @@
1212#include <__algorithm/comp.h>
1313#include <__algorithm/comp_ref_type.h>
1414#include <__algorithm/inplace_merge.h>
15#include <__algorithm/iterator_operations.h>
1516#include <__algorithm/sort.h>
1617#include <__config>
1718#include <__iterator/iterator_traits.h>
18#include <__utility/swap.h>
19#include <__utility/move.h>
1920#include <memory>
2021#include <type_traits>
2122
2223#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23#pragma GCC system_header
24# pragma GCC system_header
2425#endif
2526
2627_LIBCPP_BEGIN_NAMESPACE_STD
2728
28template <class _Compare, class _InputIterator1, class _InputIterator2>
29template <class _AlgPolicy, class _Compare, class _InputIterator1, class _InputIterator2>
2930void
3031__merge_move_construct(_InputIterator1 __first1, _InputIterator1 __last1,
3132 _InputIterator2 __first2, _InputIterator2 __last2,
3233 typename iterator_traits<_InputIterator1>::value_type* __result, _Compare __comp)
3334{
35 using _Ops = _IterOps<_AlgPolicy>;
36
3437 typedef typename iterator_traits<_InputIterator1>::value_type value_type;
3538 __destruct_n __d(0);
3639 unique_ptr<value_type, __destruct_n&> __h(__result, __d);
......@@ -39,111 +42,115 @@ __merge_move_construct(_InputIterator1 __first1, _InputIterator1 __last1,
3942 if (__first1 == __last1)
4043 {
4144 for (; __first2 != __last2; ++__first2, (void) ++__result, __d.template __incr<value_type>())
42 ::new ((void*)__result) value_type(_VSTD::move(*__first2));
45 ::new ((void*)__result) value_type(_Ops::__iter_move(__first2));
4346 __h.release();
4447 return;
4548 }
4649 if (__first2 == __last2)
4750 {
4851 for (; __first1 != __last1; ++__first1, (void) ++__result, __d.template __incr<value_type>())
49 ::new ((void*)__result) value_type(_VSTD::move(*__first1));
52 ::new ((void*)__result) value_type(_Ops::__iter_move(__first1));
5053 __h.release();
5154 return;
5255 }
5356 if (__comp(*__first2, *__first1))
5457 {
55 ::new ((void*)__result) value_type(_VSTD::move(*__first2));
58 ::new ((void*)__result) value_type(_Ops::__iter_move(__first2));
5659 __d.template __incr<value_type>();
5760 ++__first2;
5861 }
5962 else
6063 {
61 ::new ((void*)__result) value_type(_VSTD::move(*__first1));
64 ::new ((void*)__result) value_type(_Ops::__iter_move(__first1));
6265 __d.template __incr<value_type>();
6366 ++__first1;
6467 }
6568 }
6669}
6770
68template <class _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator>
71template <class _AlgPolicy, class _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator>
6972void
7073__merge_move_assign(_InputIterator1 __first1, _InputIterator1 __last1,
7174 _InputIterator2 __first2, _InputIterator2 __last2,
7275 _OutputIterator __result, _Compare __comp)
7376{
77 using _Ops = _IterOps<_AlgPolicy>;
78
7479 for (; __first1 != __last1; ++__result)
7580 {
7681 if (__first2 == __last2)
7782 {
7883 for (; __first1 != __last1; ++__first1, (void) ++__result)
79 *__result = _VSTD::move(*__first1);
84 *__result = _Ops::__iter_move(__first1);
8085 return;
8186 }
8287 if (__comp(*__first2, *__first1))
8388 {
84 *__result = _VSTD::move(*__first2);
89 *__result = _Ops::__iter_move(__first2);
8590 ++__first2;
8691 }
8792 else
8893 {
89 *__result = _VSTD::move(*__first1);
94 *__result = _Ops::__iter_move(__first1);
9095 ++__first1;
9196 }
9297 }
9398 for (; __first2 != __last2; ++__first2, (void) ++__result)
94 *__result = _VSTD::move(*__first2);
99 *__result = _Ops::__iter_move(__first2);
95100}
96101
97template <class _Compare, class _RandomAccessIterator>
102template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
98103void
99104__stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp,
100105 typename iterator_traits<_RandomAccessIterator>::difference_type __len,
101106 typename iterator_traits<_RandomAccessIterator>::value_type* __buff, ptrdiff_t __buff_size);
102107
103template <class _Compare, class _RandomAccessIterator>
108template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
104109void
105110__stable_sort_move(_RandomAccessIterator __first1, _RandomAccessIterator __last1, _Compare __comp,
106111 typename iterator_traits<_RandomAccessIterator>::difference_type __len,
107112 typename iterator_traits<_RandomAccessIterator>::value_type* __first2)
108113{
114 using _Ops = _IterOps<_AlgPolicy>;
115
109116 typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
110117 switch (__len)
111118 {
112119 case 0:
113120 return;
114121 case 1:
115 ::new ((void*)__first2) value_type(_VSTD::move(*__first1));
122 ::new ((void*)__first2) value_type(_Ops::__iter_move(__first1));
116123 return;
117124 case 2:
118125 __destruct_n __d(0);
119126 unique_ptr<value_type, __destruct_n&> __h2(__first2, __d);
120127 if (__comp(*--__last1, *__first1))
121128 {
122 ::new ((void*)__first2) value_type(_VSTD::move(*__last1));
129 ::new ((void*)__first2) value_type(_Ops::__iter_move(__last1));
123130 __d.template __incr<value_type>();
124131 ++__first2;
125 ::new ((void*)__first2) value_type(_VSTD::move(*__first1));
132 ::new ((void*)__first2) value_type(_Ops::__iter_move(__first1));
126133 }
127134 else
128135 {
129 ::new ((void*)__first2) value_type(_VSTD::move(*__first1));
136 ::new ((void*)__first2) value_type(_Ops::__iter_move(__first1));
130137 __d.template __incr<value_type>();
131138 ++__first2;
132 ::new ((void*)__first2) value_type(_VSTD::move(*__last1));
139 ::new ((void*)__first2) value_type(_Ops::__iter_move(__last1));
133140 }
134141 __h2.release();
135142 return;
136143 }
137144 if (__len <= 8)
138145 {
139 _VSTD::__insertion_sort_move<_Compare>(__first1, __last1, __first2, __comp);
146 std::__insertion_sort_move<_AlgPolicy, _Compare>(__first1, __last1, __first2, __comp);
140147 return;
141148 }
142149 typename iterator_traits<_RandomAccessIterator>::difference_type __l2 = __len / 2;
143150 _RandomAccessIterator __m = __first1 + __l2;
144 _VSTD::__stable_sort<_Compare>(__first1, __m, __comp, __l2, __first2, __l2);
145 _VSTD::__stable_sort<_Compare>(__m, __last1, __comp, __len - __l2, __first2 + __l2, __len - __l2);
146 _VSTD::__merge_move_construct<_Compare>(__first1, __m, __m, __last1, __first2, __comp);
151 std::__stable_sort<_AlgPolicy, _Compare>(__first1, __m, __comp, __l2, __first2, __l2);
152 std::__stable_sort<_AlgPolicy, _Compare>(__m, __last1, __comp, __len - __l2, __first2 + __l2, __len - __l2);
153 std::__merge_move_construct<_AlgPolicy, _Compare>(__first1, __m, __m, __last1, __first2, __comp);
147154}
148155
149156template <class _Tp>
......@@ -152,7 +159,7 @@ struct __stable_sort_switch
152159 static const unsigned value = 128*is_trivially_copy_assignable<_Tp>::value;
153160};
154161
155template <class _Compare, class _RandomAccessIterator>
162template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
156163void
157164__stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp,
158165 typename iterator_traits<_RandomAccessIterator>::difference_type __len,
......@@ -167,12 +174,12 @@ __stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp
167174 return;
168175 case 2:
169176 if (__comp(*--__last, *__first))
170 swap(*__first, *__last);
177 _IterOps<_AlgPolicy>::iter_swap(__first, __last);
171178 return;
172179 }
173180 if (__len <= static_cast<difference_type>(__stable_sort_switch<value_type>::value))
174181 {
175 _VSTD::__insertion_sort<_Compare>(__first, __last, __comp);
182 std::__insertion_sort<_AlgPolicy, _Compare>(__first, __last, __comp);
176183 return;
177184 }
178185 typename iterator_traits<_RandomAccessIterator>::difference_type __l2 = __len / 2;
......@@ -181,11 +188,12 @@ __stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp
181188 {
182189 __destruct_n __d(0);
183190 unique_ptr<value_type, __destruct_n&> __h2(__buff, __d);
184 _VSTD::__stable_sort_move<_Compare>(__first, __m, __comp, __l2, __buff);
191 std::__stable_sort_move<_AlgPolicy, _Compare>(__first, __m, __comp, __l2, __buff);
185192 __d.__set(__l2, (value_type*)nullptr);
186 _VSTD::__stable_sort_move<_Compare>(__m, __last, __comp, __len - __l2, __buff + __l2);
193 std::__stable_sort_move<_AlgPolicy, _Compare>(__m, __last, __comp, __len - __l2, __buff + __l2);
187194 __d.__set(__len, (value_type*)nullptr);
188 _VSTD::__merge_move_assign<_Compare>(__buff, __buff + __l2, __buff + __l2, __buff + __len, __first, __comp);
195 std::__merge_move_assign<_AlgPolicy, _Compare>(
196 __buff, __buff + __l2, __buff + __l2, __buff + __len, __first, __comp);
189197// _VSTD::__merge<_Compare>(move_iterator<value_type*>(__buff),
190198// move_iterator<value_type*>(__buff + __l2),
191199// move_iterator<_RandomAccessIterator>(__buff + __l2),
......@@ -193,36 +201,42 @@ __stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp
193201// __first, __comp);
194202 return;
195203 }
196 _VSTD::__stable_sort<_Compare>(__first, __m, __comp, __l2, __buff, __buff_size);
197 _VSTD::__stable_sort<_Compare>(__m, __last, __comp, __len - __l2, __buff, __buff_size);
198 _VSTD::__inplace_merge<_Compare>(__first, __m, __last, __comp, __l2, __len - __l2, __buff, __buff_size);
204 std::__stable_sort<_AlgPolicy, _Compare>(__first, __m, __comp, __l2, __buff, __buff_size);
205 std::__stable_sort<_AlgPolicy, _Compare>(__m, __last, __comp, __len - __l2, __buff, __buff_size);
206 std::__inplace_merge<_AlgPolicy>(__first, __m, __last, __comp, __l2, __len - __l2, __buff, __buff_size);
207}
208
209template <class _AlgPolicy, class _RandomAccessIterator, class _Compare>
210inline _LIBCPP_HIDE_FROM_ABI
211void __stable_sort_impl(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare& __comp) {
212 using value_type = typename iterator_traits<_RandomAccessIterator>::value_type;
213 using difference_type = typename iterator_traits<_RandomAccessIterator>::difference_type;
214
215 difference_type __len = __last - __first;
216 pair<value_type*, ptrdiff_t> __buf(0, 0);
217 unique_ptr<value_type, __return_temporary_buffer> __h;
218 if (__len > static_cast<difference_type>(__stable_sort_switch<value_type>::value)) {
219// TODO: Remove the use of std::get_temporary_buffer
220_LIBCPP_SUPPRESS_DEPRECATED_PUSH
221 __buf = std::get_temporary_buffer<value_type>(__len);
222_LIBCPP_SUPPRESS_DEPRECATED_POP
223 __h.reset(__buf.first);
224 }
225
226 using _Comp_ref = typename __comp_ref_type<_Compare>::type;
227 std::__stable_sort<_AlgPolicy, _Comp_ref>(__first, __last, __comp, __len, __buf.first, __buf.second);
199228}
200229
201230template <class _RandomAccessIterator, class _Compare>
202inline _LIBCPP_INLINE_VISIBILITY
203void
204stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
205{
206 typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
207 typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
208 difference_type __len = __last - __first;
209 pair<value_type*, ptrdiff_t> __buf(0, 0);
210 unique_ptr<value_type, __return_temporary_buffer> __h;
211 if (__len > static_cast<difference_type>(__stable_sort_switch<value_type>::value))
212 {
213 __buf = _VSTD::get_temporary_buffer<value_type>(__len);
214 __h.reset(__buf.first);
215 }
216 typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
217 _VSTD::__stable_sort<_Comp_ref>(__first, __last, __comp, __len, __buf.first, __buf.second);
231inline _LIBCPP_HIDE_FROM_ABI
232void stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) {
233 std::__stable_sort_impl<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __comp);
218234}
219235
220236template <class _RandomAccessIterator>
221inline _LIBCPP_INLINE_VISIBILITY
222void
223stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
224{
225 _VSTD::stable_sort(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
237inline _LIBCPP_HIDE_FROM_ABI
238void stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last) {
239 std::stable_sort(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
226240}
227241
228242_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__algorithm/swap_ranges.h+1-2
......@@ -11,10 +11,9 @@
1111
1212#include <__config>
1313#include <__utility/swap.h>
14#include <type_traits>
1514
1615#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
16# pragma GCC system_header
1817#endif
1918
2019_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/transform.h+1-1
......@@ -12,7 +12,7 @@
1212#include <__config>
1313
1414#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15#pragma GCC system_header
15# pragma GCC system_header
1616#endif
1717
1818_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__algorithm/unique.h+27-23
......@@ -11,44 +11,48 @@
1111
1212#include <__algorithm/adjacent_find.h>
1313#include <__algorithm/comp.h>
14#include <__algorithm/iterator_operations.h>
1415#include <__config>
1516#include <__iterator/iterator_traits.h>
1617#include <__utility/move.h>
18#include <__utility/pair.h>
1719
1820#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
21# pragma GCC system_header
2022#endif
2123
2224_LIBCPP_BEGIN_NAMESPACE_STD
2325
2426// unique
2527
28template <class _AlgPolicy, class _Iter, class _Sent, class _BinaryPredicate>
29_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 std::pair<_Iter, _Iter>
30__unique(_Iter __first, _Sent __last, _BinaryPredicate&& __pred) {
31 __first = std::__adjacent_find(__first, __last, __pred);
32 if (__first != __last) {
33 // ... a a ? ...
34 // f i
35 _Iter __i = __first;
36 for (++__i; ++__i != __last;)
37 if (!__pred(*__first, *__i))
38 *++__first = _IterOps<_AlgPolicy>::__iter_move(__i);
39 ++__first;
40 return std::pair<_Iter, _Iter>(std::move(__first), std::move(__i));
41 }
42 return std::pair<_Iter, _Iter>(__first, __first);
43}
44
2645template <class _ForwardIterator, class _BinaryPredicate>
27_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
28unique(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred)
29{
30 __first = _VSTD::adjacent_find<_ForwardIterator, _BinaryPredicate&>(__first, __last, __pred);
31 if (__first != __last)
32 {
33 // ... a a ? ...
34 // f i
35 _ForwardIterator __i = __first;
36 for (++__i; ++__i != __last;)
37 if (!__pred(*__first, *__i))
38 *++__first = _VSTD::move(*__i);
39 ++__first;
40 }
41 return __first;
46_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
47unique(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred) {
48 return std::__unique<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __pred).first;
4249}
4350
4451template <class _ForwardIterator>
45_LIBCPP_NODISCARD_EXT inline
46_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
47_ForwardIterator
48unique(_ForwardIterator __first, _ForwardIterator __last)
49{
50 typedef typename iterator_traits<_ForwardIterator>::value_type __v;
51 return _VSTD::unique(__first, __last, __equal_to<__v>());
52_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
53unique(_ForwardIterator __first, _ForwardIterator __last) {
54 typedef typename iterator_traits<_ForwardIterator>::value_type __v;
55 return std::unique(__first, __last, __equal_to<__v>());
5256}
5357
5458_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__algorithm/unique_copy.h+83-67
......@@ -10,98 +10,114 @@
1010#define _LIBCPP___ALGORITHM_UNIQUE_COPY_H
1111
1212#include <__algorithm/comp.h>
13#include <__algorithm/iterator_operations.h>
1314#include <__config>
1415#include <__iterator/iterator_traits.h>
15#include <utility>
16#include <__type_traits/conditional.h>
17#include <__type_traits/is_base_of.h>
18#include <__type_traits/is_same.h>
19#include <__utility/move.h>
20#include <__utility/pair.h>
1621
1722#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
23# pragma GCC system_header
1924#endif
2025
2126_LIBCPP_BEGIN_NAMESPACE_STD
2227
23template <class _BinaryPredicate, class _InputIterator, class _OutputIterator>
24_LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator
25__unique_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryPredicate __pred,
26 input_iterator_tag, output_iterator_tag)
27{
28 if (__first != __last)
29 {
30 typename iterator_traits<_InputIterator>::value_type __t(*__first);
28namespace __unique_copy_tags {
29
30struct __reread_from_input_tag {};
31struct __reread_from_output_tag {};
32struct __read_from_tmp_value_tag {};
33
34} // namespace __unique_copy_tags
35
36template <class _AlgPolicy, class _BinaryPredicate, class _InputIterator, class _Sent, class _OutputIterator>
37_LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _OutputIterator>
38__unique_copy(_InputIterator __first,
39 _Sent __last,
40 _OutputIterator __result,
41 _BinaryPredicate&& __pred,
42 __unique_copy_tags::__read_from_tmp_value_tag) {
43 if (__first != __last) {
44 typename _IterOps<_AlgPolicy>::template __value_type<_InputIterator> __t(*__first);
45 *__result = __t;
46 ++__result;
47 while (++__first != __last) {
48 if (!__pred(__t, *__first)) {
49 __t = *__first;
3150 *__result = __t;
3251 ++__result;
33 while (++__first != __last)
34 {
35 if (!__pred(__t, *__first))
36 {
37 __t = *__first;
38 *__result = __t;
39 ++__result;
40 }
41 }
52 }
4253 }
43 return __result;
54 }
55 return pair<_InputIterator, _OutputIterator>(std::move(__first), std::move(__result));
4456}
4557
46template <class _BinaryPredicate, class _ForwardIterator, class _OutputIterator>
47_LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator
48__unique_copy(_ForwardIterator __first, _ForwardIterator __last, _OutputIterator __result, _BinaryPredicate __pred,
49 forward_iterator_tag, output_iterator_tag)
50{
51 if (__first != __last)
52 {
53 _ForwardIterator __i = __first;
54 *__result = *__i;
58template <class _AlgPolicy, class _BinaryPredicate, class _ForwardIterator, class _Sent, class _OutputIterator>
59_LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI pair<_ForwardIterator, _OutputIterator>
60__unique_copy(_ForwardIterator __first,
61 _Sent __last,
62 _OutputIterator __result,
63 _BinaryPredicate&& __pred,
64 __unique_copy_tags::__reread_from_input_tag) {
65 if (__first != __last) {
66 _ForwardIterator __i = __first;
67 *__result = *__i;
68 ++__result;
69 while (++__first != __last) {
70 if (!__pred(*__i, *__first)) {
71 *__result = *__first;
5572 ++__result;
56 while (++__first != __last)
57 {
58 if (!__pred(*__i, *__first))
59 {
60 *__result = *__first;
61 ++__result;
62 __i = __first;
63 }
64 }
73 __i = __first;
74 }
6575 }
66 return __result;
76 }
77 return pair<_ForwardIterator, _OutputIterator>(std::move(__first), std::move(__result));
6778}
6879
69template <class _BinaryPredicate, class _InputIterator, class _ForwardIterator>
70_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
71__unique_copy(_InputIterator __first, _InputIterator __last, _ForwardIterator __result, _BinaryPredicate __pred,
72 input_iterator_tag, forward_iterator_tag)
73{
74 if (__first != __last)
75 {
76 *__result = *__first;
77 while (++__first != __last)
78 if (!__pred(*__result, *__first))
79 *++__result = *__first;
80 ++__result;
81 }
82 return __result;
80template <class _AlgPolicy, class _BinaryPredicate, class _InputIterator, class _Sent, class _InputAndOutputIterator>
81_LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _InputAndOutputIterator>
82__unique_copy(_InputIterator __first,
83 _Sent __last,
84 _InputAndOutputIterator __result,
85 _BinaryPredicate&& __pred,
86 __unique_copy_tags::__reread_from_output_tag) {
87 if (__first != __last) {
88 *__result = *__first;
89 while (++__first != __last)
90 if (!__pred(*__result, *__first))
91 *++__result = *__first;
92 ++__result;
93 }
94 return pair<_InputIterator, _InputAndOutputIterator>(std::move(__first), std::move(__result));
8395}
8496
8597template <class _InputIterator, class _OutputIterator, class _BinaryPredicate>
86inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
87_OutputIterator
88unique_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryPredicate __pred)
89{
90 return _VSTD::__unique_copy<_BinaryPredicate&>(__first, __last, __result, __pred,
91 typename iterator_traits<_InputIterator>::iterator_category(),
92 typename iterator_traits<_OutputIterator>::iterator_category());
98inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator
99unique_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryPredicate __pred) {
100 using __algo_tag = typename conditional<
101 is_base_of<forward_iterator_tag, typename iterator_traits<_InputIterator>::iterator_category>::value,
102 __unique_copy_tags::__reread_from_input_tag,
103 typename conditional<
104 is_base_of<forward_iterator_tag, typename iterator_traits<_OutputIterator>::iterator_category>::value &&
105 is_same< typename iterator_traits<_InputIterator>::value_type,
106 typename iterator_traits<_OutputIterator>::value_type>::value,
107 __unique_copy_tags::__reread_from_output_tag,
108 __unique_copy_tags::__read_from_tmp_value_tag>::type >::type;
109 return std::__unique_copy<_ClassicAlgPolicy>(
110 std::move(__first), std::move(__last), std::move(__result), __pred, __algo_tag())
111 .second;
93112}
94113
95114template <class _InputIterator, class _OutputIterator>
96inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
97_OutputIterator
98unique_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
99{
100 typedef typename iterator_traits<_InputIterator>::value_type __v;
101 return _VSTD::unique_copy(__first, __last, __result, __equal_to<__v>());
115inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator
116unique_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result) {
117 typedef typename iterator_traits<_InputIterator>::value_type __v;
118 return std::unique_copy(std::move(__first), std::move(__last), std::move(__result), __equal_to<__v>());
102119}
103120
104
105121_LIBCPP_END_NAMESPACE_STD
106122
107123#endif // _LIBCPP___ALGORITHM_UNIQUE_COPY_H
lib/libcxx/include/__algorithm/unwrap_iter.h+31-43
......@@ -10,73 +10,61 @@
1010#define _LIBCPP___ALGORITHM_UNWRAP_ITER_H
1111
1212#include <__config>
13#include <__iterator/iterator_traits.h>
1314#include <__memory/pointer_traits.h>
14#include <iterator>
15#include <__utility/move.h>
1516#include <type_traits>
1617
1718#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
19# pragma GCC system_header
1920#endif
2021
2122_LIBCPP_BEGIN_NAMESPACE_STD
2223
23// The job of __unwrap_iter is to lower contiguous iterators (such as
24// vector<T>::iterator) into pointers, to reduce the number of template
25// instantiations and to enable pointer-based optimizations e.g. in std::copy.
26// For iterators that are not contiguous, it must be a no-op.
24// TODO: Change the name of __unwrap_iter_impl to something more appropriate
25// The job of __unwrap_iter is to remove iterator wrappers (like reverse_iterator or __wrap_iter),
26// to reduce the number of template instantiations and to enable pointer-based optimizations e.g. in std::copy.
2727// In debug mode, we don't do this.
2828//
29// __unwrap_iter is non-constexpr for user-defined iterators whose
30// `to_address` and/or `operator->` is non-constexpr. This is okay; but we
31// try to avoid doing __unwrap_iter in constant-evaluated contexts anyway.
32//
3329// Some algorithms (e.g. std::copy, but not std::sort) need to convert an
34// "unwrapped" result back into a contiguous iterator. Since contiguous iterators
35// are random-access, we can do this portably using iterator arithmetic; this
36// is the job of __rewrap_iter.
30// "unwrapped" result back into the original iterator type. Doing that is the job of __rewrap_iter.
3731
32// Default case - we can't unwrap anything
3833template <class _Iter, bool = __is_cpp17_contiguous_iterator<_Iter>::value>
3934struct __unwrap_iter_impl {
40 static _LIBCPP_CONSTEXPR _Iter
41 __apply(_Iter __i) _NOEXCEPT {
42 return __i;
43 }
35 static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Iter __rewrap(_Iter, _Iter __iter) { return __iter; }
36 static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Iter __unwrap(_Iter __i) _NOEXCEPT { return __i; }
4437};
4538
46#if _LIBCPP_DEBUG_LEVEL < 2
39#ifndef _LIBCPP_ENABLE_DEBUG_MODE
4740
41// It's a contiguous iterator, so we can use a raw pointer instead
4842template <class _Iter>
4943struct __unwrap_iter_impl<_Iter, true> {
50 static _LIBCPP_CONSTEXPR decltype(_VSTD::__to_address(declval<_Iter>()))
51 __apply(_Iter __i) _NOEXCEPT {
52 return _VSTD::__to_address(__i);
53 }
54};
44 using _ToAddressT = decltype(std::__to_address(std::declval<_Iter>()));
5545
56#endif // _LIBCPP_DEBUG_LEVEL < 2
46 static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Iter __rewrap(_Iter __orig_iter, _ToAddressT __unwrapped_iter) {
47 return __orig_iter + (__unwrapped_iter - std::__to_address(__orig_iter));
48 }
5749
58template<class _Iter, class _Impl = __unwrap_iter_impl<_Iter> >
59inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
60decltype(_Impl::__apply(declval<_Iter>()))
61__unwrap_iter(_Iter __i) _NOEXCEPT
62{
63 return _Impl::__apply(__i);
64}
50 static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToAddressT __unwrap(_Iter __i) _NOEXCEPT {
51 return std::__to_address(__i);
52 }
53};
54
55#endif // !_LIBCPP_ENABLE_DEBUG_MODE
6556
66template<class _OrigIter>
67_LIBCPP_HIDE_FROM_ABI
68_OrigIter __rewrap_iter(_OrigIter, _OrigIter __result)
69{
70 return __result;
57template<class _Iter,
58 class _Impl = __unwrap_iter_impl<_Iter>,
59 __enable_if_t<is_copy_constructible<_Iter>::value, int> = 0>
60inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
61decltype(_Impl::__unwrap(std::declval<_Iter>())) __unwrap_iter(_Iter __i) _NOEXCEPT {
62 return _Impl::__unwrap(__i);
7163}
7264
73template<class _OrigIter, class _UnwrappedIter>
74_LIBCPP_HIDE_FROM_ABI
75_OrigIter __rewrap_iter(_OrigIter __first, _UnwrappedIter __result)
76{
77 // Precondition: __result is reachable from __first
78 // Precondition: _OrigIter is a contiguous iterator
79 return __first + (__result - _VSTD::__unwrap_iter(__first));
65template <class _OrigIter, class _Iter, class _Impl = __unwrap_iter_impl<_OrigIter> >
66_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _OrigIter __rewrap_iter(_OrigIter __orig_iter, _Iter __iter) _NOEXCEPT {
67 return _Impl::__rewrap(std::move(__orig_iter), std::move(__iter));
8068}
8169
8270_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__algorithm/unwrap_range.h created+97
......@@ -0,0 +1,97 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_UNWRAP_RANGE_H
10#define _LIBCPP___ALGORITHM_UNWRAP_RANGE_H
11
12#include <__algorithm/unwrap_iter.h>
13#include <__concepts/constructible.h>
14#include <__config>
15#include <__iterator/concepts.h>
16#include <__iterator/next.h>
17#include <__utility/declval.h>
18#include <__utility/move.h>
19#include <__utility/pair.h>
20
21#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22# pragma GCC system_header
23#endif
24
25_LIBCPP_BEGIN_NAMESPACE_STD
26
27// __unwrap_range and __rewrap_range are used to unwrap ranges which may have different iterator and sentinel types.
28// __unwrap_iter and __rewrap_iter don't work for this, because they assume that the iterator and sentinel have
29// the same type. __unwrap_range tries to get two iterators and then forward to __unwrap_iter.
30
31#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
32template <class _Iter, class _Sent>
33struct __unwrap_range_impl {
34 _LIBCPP_HIDE_FROM_ABI static constexpr auto __unwrap(_Iter __first, _Sent __sent)
35 requires random_access_iterator<_Iter> && sized_sentinel_for<_Sent, _Iter>
36 {
37 auto __last = ranges::next(__first, __sent);
38 return pair{std::__unwrap_iter(std::move(__first)), std::__unwrap_iter(std::move(__last))};
39 }
40
41 _LIBCPP_HIDE_FROM_ABI static constexpr auto __unwrap(_Iter __first, _Sent __last) {
42 return pair{std::move(__first), std::move(__last)};
43 }
44
45 _LIBCPP_HIDE_FROM_ABI static constexpr auto
46 __rewrap(_Iter __orig_iter, decltype(std::__unwrap_iter(__orig_iter)) __iter)
47 requires random_access_iterator<_Iter> && sized_sentinel_for<_Sent, _Iter>
48 {
49 return std::__rewrap_iter(std::move(__orig_iter), std::move(__iter));
50 }
51
52 _LIBCPP_HIDE_FROM_ABI static constexpr auto __rewrap(const _Iter&, _Iter __iter)
53 requires (!(random_access_iterator<_Iter> && sized_sentinel_for<_Sent, _Iter>))
54 {
55 return __iter;
56 }
57};
58
59template <class _Iter>
60struct __unwrap_range_impl<_Iter, _Iter> {
61 _LIBCPP_HIDE_FROM_ABI static constexpr auto __unwrap(_Iter __first, _Iter __last) {
62 return pair{std::__unwrap_iter(std::move(__first)), std::__unwrap_iter(std::move(__last))};
63 }
64
65 _LIBCPP_HIDE_FROM_ABI static constexpr auto
66 __rewrap(_Iter __orig_iter, decltype(std::__unwrap_iter(__orig_iter)) __iter) {
67 return std::__rewrap_iter(std::move(__orig_iter), std::move(__iter));
68 }
69};
70
71template <class _Iter, class _Sent>
72_LIBCPP_HIDE_FROM_ABI constexpr auto __unwrap_range(_Iter __first, _Sent __last) {
73 return __unwrap_range_impl<_Iter, _Sent>::__unwrap(std::move(__first), std::move(__last));
74}
75
76template <
77 class _Sent,
78 class _Iter,
79 class _Unwrapped = decltype(std::__unwrap_range(std::declval<_Iter>(), std::declval<_Sent>()))>
80_LIBCPP_HIDE_FROM_ABI constexpr _Iter __rewrap_range(_Iter __orig_iter, _Unwrapped __iter) {
81 return __unwrap_range_impl<_Iter, _Sent>::__rewrap(std::move(__orig_iter), std::move(__iter));
82}
83#else // _LIBCPP_STD_VER > 17
84template <class _Iter, class _Unwrapped = decltype(std::__unwrap_iter(std::declval<_Iter>()))>
85_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR pair<_Unwrapped, _Unwrapped> __unwrap_range(_Iter __first, _Iter __last) {
86 return std::make_pair(std::__unwrap_iter(std::move(__first)), std::__unwrap_iter(std::move(__last)));
87}
88
89template <class _Iter, class _Unwrapped = decltype(std::__unwrap_iter(std::declval<_Iter>()))>
90_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Iter __rewrap_range(_Iter __orig_iter, _Unwrapped __iter) {
91 return std::__rewrap_iter(std::move(__orig_iter), std::move(__iter));
92}
93#endif // _LIBCPP_STD_VER > 17
94
95_LIBCPP_END_NAMESPACE_STD
96
97#endif // _LIBCPP___ALGORITHM_UNWRAP_RANGE_H
lib/libcxx/include/__algorithm/upper_bound.h+36-34
......@@ -11,54 +11,56 @@
1111
1212#include <__algorithm/comp.h>
1313#include <__algorithm/half_positive.h>
14#include <__algorithm/iterator_operations.h>
1415#include <__config>
15#include <iterator>
16#include <__functional/identity.h>
17#include <__functional/invoke.h>
18#include <__iterator/advance.h>
19#include <__iterator/distance.h>
20#include <__iterator/iterator_traits.h>
21#include <__type_traits/is_copy_constructible.h>
22#include <__utility/move.h>
1623
1724#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
25# pragma GCC system_header
1926#endif
2027
2128_LIBCPP_BEGIN_NAMESPACE_STD
2229
23template <class _Compare, class _ForwardIterator, class _Tp>
24_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
25__upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
26{
27 typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type;
28 difference_type __len = _VSTD::distance(__first, __last);
29 while (__len != 0)
30 {
31 difference_type __l2 = _VSTD::__half_positive(__len);
32 _ForwardIterator __m = __first;
33 _VSTD::advance(__m, __l2);
34 if (__comp(__value_, *__m))
35 __len = __l2;
36 else
37 {
38 __first = ++__m;
39 __len -= __l2 + 1;
40 }
30template <class _AlgPolicy, class _Compare, class _Iter, class _Sent, class _Tp, class _Proj>
31_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _Iter
32__upper_bound(_Iter __first, _Sent __last, const _Tp& __value, _Compare&& __comp, _Proj&& __proj) {
33 auto __len = _IterOps<_AlgPolicy>::distance(__first, __last);
34 while (__len != 0) {
35 auto __half_len = std::__half_positive(__len);
36 auto __mid = _IterOps<_AlgPolicy>::next(__first, __half_len);
37 if (std::__invoke(__comp, __value, std::__invoke(__proj, *__mid)))
38 __len = __half_len;
39 else {
40 __first = ++__mid;
41 __len -= __half_len + 1;
4142 }
42 return __first;
43 }
44 return __first;
4345}
4446
4547template <class _ForwardIterator, class _Tp, class _Compare>
46_LIBCPP_NODISCARD_EXT inline
47_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
48_ForwardIterator
49upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
50{
51 return _VSTD::__upper_bound<_Compare&>(__first, __last, __value_, __comp);
48_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
49upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) {
50 static_assert(is_copy_constructible<_ForwardIterator>::value,
51 "Iterator has to be copy constructible");
52 return std::__upper_bound<_ClassicAlgPolicy>(
53 std::move(__first), std::move(__last), __value, std::move(__comp), std::__identity());
5254}
5355
5456template <class _ForwardIterator, class _Tp>
55_LIBCPP_NODISCARD_EXT inline
56_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
57_ForwardIterator
58upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_)
59{
60 return _VSTD::upper_bound(__first, __last, __value_,
61 __less<_Tp, typename iterator_traits<_ForwardIterator>::value_type>());
57_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
58upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
59 return std::upper_bound(
60 std::move(__first),
61 std::move(__last),
62 __value,
63 __less<_Tp, typename iterator_traits<_ForwardIterator>::value_type>());
6264}
6365
6466_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__assert created+59
......@@ -0,0 +1,59 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___ASSERT
11#define _LIBCPP___ASSERT
12
13#include <__config>
14#include <__verbose_abort>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
20// This is for backwards compatibility with code that might have been enabling
21// assertions through the Debug mode previously.
22// TODO: In LLVM 16, make it an error to define _LIBCPP_DEBUG
23#if defined(_LIBCPP_DEBUG)
24# ifndef _LIBCPP_ENABLE_ASSERTIONS
25# define _LIBCPP_ENABLE_ASSERTIONS 1
26# endif
27#endif
28
29// Automatically enable assertions when the debug mode is enabled.
30#if defined(_LIBCPP_ENABLE_DEBUG_MODE)
31# ifndef _LIBCPP_ENABLE_ASSERTIONS
32# define _LIBCPP_ENABLE_ASSERTIONS 1
33# endif
34#endif
35
36#ifndef _LIBCPP_ENABLE_ASSERTIONS
37# define _LIBCPP_ENABLE_ASSERTIONS _LIBCPP_ENABLE_ASSERTIONS_DEFAULT
38#endif
39
40#if _LIBCPP_ENABLE_ASSERTIONS != 0 && _LIBCPP_ENABLE_ASSERTIONS != 1
41# error "_LIBCPP_ENABLE_ASSERTIONS must be set to 0 or 1"
42#endif
43
44#if _LIBCPP_ENABLE_ASSERTIONS
45# define _LIBCPP_ASSERT(expression, message) \
46 (__builtin_expect(static_cast<bool>(expression), 1) ? \
47 (void)0 : \
48 ::std::__libcpp_verbose_abort("%s:%d: assertion %s failed: %s", __FILE__, __LINE__, #expression, message))
49#elif !defined(_LIBCPP_ASSERTIONS_DISABLE_ASSUME) && __has_builtin(__builtin_assume)
50# define _LIBCPP_ASSERT(expression, message) \
51 (_LIBCPP_DIAGNOSTIC_PUSH \
52 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wassume") \
53 __builtin_assume(static_cast<bool>(expression)) \
54 _LIBCPP_DIAGNOSTIC_POP)
55#else
56# define _LIBCPP_ASSERT(expression, message) ((void)0)
57#endif
58
59#endif // _LIBCPP___ASSERT
lib/libcxx/include/__availability+60-28
......@@ -13,7 +13,7 @@
1313#include <__config>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
16# pragma GCC system_header
1717#endif
1818
1919// Libc++ is shipped by various vendors. In particular, it is used as a system
......@@ -91,6 +91,10 @@
9191 // other exception types. These were put in the shared library to prevent
9292 // code bloat from every user program defining the vtable for these exception
9393 // types.
94 //
95 // Note that when exceptions are disabled, the methods that normally throw
96 // these exceptions can be used even on older deployment targets, but those
97 // methods will abort instead of throwing.
9498# define _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS
9599# define _LIBCPP_AVAILABILITY_BAD_VARIANT_ACCESS
96100# define _LIBCPP_AVAILABILITY_BAD_ANY_CAST
......@@ -99,10 +103,15 @@
99103# define _LIBCPP_AVAILABILITY_UNCAUGHT_EXCEPTIONS
100104
101105 // This controls the availability of the sized version of ::operator delete,
102 // which was added to the dylib later.
106 // ::operator delete[], and their align_val_t variants, which were all added
107 // in C++17, and hence not present in early dylibs.
103108# define _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE
104109
105110 // This controls the availability of the std::future_error exception.
111 //
112 // Note that when exceptions are disabled, the methods that normally throw
113 // std::future_error can be used even on older deployment targets, but those
114 // methods will abort instead of throwing.
106115# define _LIBCPP_AVAILABILITY_FUTURE_ERROR
107116
108117 // This controls the availability of std::type_info's vtable.
......@@ -126,16 +135,14 @@
126135# define _LIBCPP_AVAILABILITY_FILESYSTEM_POP
127136// # define _LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_filesystem
128137
129 // This controls the availability of std::to_chars.
130# define _LIBCPP_AVAILABILITY_TO_CHARS
131
132138 // This controls the availability of floating-point std::to_chars functions.
133139 // These overloads were added later than the integer overloads.
134140# define _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT
135141
136142 // This controls the availability of the C++20 synchronization library,
137143 // which requires shared library support for various operations
138 // (see libcxx/src/atomic.cpp).
144 // (see libcxx/src/atomic.cpp). This includes <barier>, <latch>,
145 // <semaphore>, and notification functions on std::atomic.
139146# define _LIBCPP_AVAILABILITY_SYNC
140147// # define _LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_atomic_wait
141148// # define _LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_barrier
......@@ -149,10 +156,26 @@
149156# define _LIBCPP_AVAILABILITY_FORMAT
150157// # define _LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_format
151158
159 // This controls whether the default verbose termination function is
160 // provided by the library.
161 //
162 // Note that when users provide their own custom function, it doesn't
163 // matter whether the dylib provides a default function, and the
164 // availability markup can actually give a false positive diagnostic
165 // (it will think that no function is provided, when in reality the
166 // user has provided their own).
167 //
168 // Users can pass -D_LIBCPP_AVAILABILITY_CUSTOM_VERBOSE_ABORT_PROVIDED
169 // to the compiler to tell the library to ignore the fact that the
170 // default function isn't available on their deployment target. Note that
171 // defining this macro but failing to define a custom function will lead to
172 // a load-time error on back-deployment targets, so it should be avoided.
173# define _LIBCPP_AVAILABILITY_DEFAULT_VERBOSE_ABORT
174
152175#elif defined(__APPLE__)
153176
154177# define _LIBCPP_AVAILABILITY_SHARED_MUTEX \
155 __attribute__((availability(macosx,strict,introduced=10.12))) \
178 __attribute__((availability(macos,strict,introduced=10.12))) \
156179 __attribute__((availability(ios,strict,introduced=10.0))) \
157180 __attribute__((availability(tvos,strict,introduced=10.0))) \
158181 __attribute__((availability(watchos,strict,introduced=3.0)))
......@@ -164,24 +187,27 @@
164187# define _LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_shared_timed_mutex
165188# endif
166189
190 // Note: bad_optional_access & friends were not introduced in the matching
191 // macOS and iOS versions, so the version mismatch between macOS and others
192 // is intended.
167193# define _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS \
168 __attribute__((availability(macosx,strict,introduced=10.13))) \
169 __attribute__((availability(ios,strict,introduced=11.0))) \
170 __attribute__((availability(tvos,strict,introduced=11.0))) \
171 __attribute__((availability(watchos,strict,introduced=4.0)))
194 __attribute__((availability(macos,strict,introduced=10.13))) \
195 __attribute__((availability(ios,strict,introduced=12.0))) \
196 __attribute__((availability(tvos,strict,introduced=12.0))) \
197 __attribute__((availability(watchos,strict,introduced=5.0)))
172198# define _LIBCPP_AVAILABILITY_BAD_VARIANT_ACCESS \
173199 _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS
174200# define _LIBCPP_AVAILABILITY_BAD_ANY_CAST \
175201 _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS
176202
177203# define _LIBCPP_AVAILABILITY_UNCAUGHT_EXCEPTIONS \
178 __attribute__((availability(macosx,strict,introduced=10.12))) \
204 __attribute__((availability(macos,strict,introduced=10.12))) \
179205 __attribute__((availability(ios,strict,introduced=10.0))) \
180206 __attribute__((availability(tvos,strict,introduced=10.0))) \
181207 __attribute__((availability(watchos,strict,introduced=3.0)))
182208
183209# define _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE \
184 __attribute__((availability(macosx,strict,introduced=10.12))) \
210 __attribute__((availability(macos,strict,introduced=10.12))) \
185211 __attribute__((availability(ios,strict,introduced=10.0))) \
186212 __attribute__((availability(tvos,strict,introduced=10.0))) \
187213 __attribute__((availability(watchos,strict,introduced=3.0)))
......@@ -190,26 +216,26 @@
190216 __attribute__((availability(ios,strict,introduced=6.0)))
191217
192218# define _LIBCPP_AVAILABILITY_TYPEINFO_VTABLE \
193 __attribute__((availability(macosx,strict,introduced=10.9))) \
219 __attribute__((availability(macos,strict,introduced=10.9))) \
194220 __attribute__((availability(ios,strict,introduced=7.0)))
195221
196222# define _LIBCPP_AVAILABILITY_LOCALE_CATEGORY \
197 __attribute__((availability(macosx,strict,introduced=10.9))) \
223 __attribute__((availability(macos,strict,introduced=10.9))) \
198224 __attribute__((availability(ios,strict,introduced=7.0)))
199225
200226# define _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR \
201 __attribute__((availability(macosx,strict,introduced=10.9))) \
227 __attribute__((availability(macos,strict,introduced=10.9))) \
202228 __attribute__((availability(ios,strict,introduced=7.0)))
203229
204230# define _LIBCPP_AVAILABILITY_FILESYSTEM \
205 __attribute__((availability(macosx,strict,introduced=10.15))) \
231 __attribute__((availability(macos,strict,introduced=10.15))) \
206232 __attribute__((availability(ios,strict,introduced=13.0))) \
207233 __attribute__((availability(tvos,strict,introduced=13.0))) \
208234 __attribute__((availability(watchos,strict,introduced=6.0)))
209235# define _LIBCPP_AVAILABILITY_FILESYSTEM_PUSH \
210 _Pragma("clang attribute push(__attribute__((availability(macosx,strict,introduced=10.15))), apply_to=any(function,record))") \
211 _Pragma("clang attribute push(__attribute__((availability(ios,strict,introduced=13.0))), apply_to=any(function,record))") \
212 _Pragma("clang attribute push(__attribute__((availability(tvos,strict,introduced=13.0))), apply_to=any(function,record))") \
236 _Pragma("clang attribute push(__attribute__((availability(macos,strict,introduced=10.15))), apply_to=any(function,record))") \
237 _Pragma("clang attribute push(__attribute__((availability(ios,strict,introduced=13.0))), apply_to=any(function,record))") \
238 _Pragma("clang attribute push(__attribute__((availability(tvos,strict,introduced=13.0))), apply_to=any(function,record))") \
213239 _Pragma("clang attribute push(__attribute__((availability(watchos,strict,introduced=6.0))), apply_to=any(function,record))")
214240# define _LIBCPP_AVAILABILITY_FILESYSTEM_POP \
215241 _Pragma("clang attribute pop") \
......@@ -223,14 +249,11 @@
223249# define _LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_filesystem
224250# endif
225251
226# define _LIBCPP_AVAILABILITY_TO_CHARS \
227 _LIBCPP_AVAILABILITY_FILESYSTEM
228
229252# define _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT \
230253 __attribute__((unavailable))
231254
232255# define _LIBCPP_AVAILABILITY_SYNC \
233 __attribute__((availability(macosx,strict,introduced=11.0))) \
256 __attribute__((availability(macos,strict,introduced=11.0))) \
234257 __attribute__((availability(ios,strict,introduced=14.0))) \
235258 __attribute__((availability(tvos,strict,introduced=14.0))) \
236259 __attribute__((availability(watchos,strict,introduced=7.0)))
......@@ -244,13 +267,12 @@
244267# define _LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_semaphore
245268# endif
246269
247 // This controls the availability of the C++20 format library.
248 // The library is in development and not ABI stable yet. P2216 is
249 // retroactively accepted in C++20. This paper contains ABI breaking
250 // changes.
251270# define _LIBCPP_AVAILABILITY_FORMAT \
252271 __attribute__((unavailable))
253272# define _LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_format
273
274# define _LIBCPP_AVAILABILITY_DEFAULT_VERBOSE_ABORT \
275 __attribute__((unavailable))
254276#else
255277
256278// ...New vendors can add availability markup here...
......@@ -274,4 +296,14 @@
274296# define _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS _LIBCPP_AVAILABILITY_BAD_VARIANT_ACCESS
275297#endif
276298
299// Define the special verbose termination function availability attribute, which can be silenced by
300// users if they provide their own custom function. The rest of the code should not use the
301// *_DEFAULT_* macro directly, since that would make it ignore the fact that the user provided
302// a custom function.
303#if defined(_LIBCPP_AVAILABILITY_CUSTOM_VERBOSE_ABORT_PROVIDED)
304# define _LIBCPP_AVAILABILITY_VERBOSE_ABORT /* nothing */
305#else
306# define _LIBCPP_AVAILABILITY_VERBOSE_ABORT _LIBCPP_AVAILABILITY_DEFAULT_VERBOSE_ABORT
307#endif
308
277309#endif // _LIBCPP___AVAILABILITY
lib/libcxx/include/__bit/bit_cast.h+7-9
......@@ -14,21 +14,19 @@
1414#include <type_traits>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
17# pragma GCC system_header
1818#endif
1919
2020_LIBCPP_BEGIN_NAMESPACE_STD
2121
2222#if _LIBCPP_STD_VER > 17
2323
24template<class _ToType, class _FromType, class = enable_if_t<
25 sizeof(_ToType) == sizeof(_FromType) &&
26 is_trivially_copyable_v<_ToType> &&
27 is_trivially_copyable_v<_FromType>
28>>
29_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI
30constexpr _ToType bit_cast(_FromType const& __from) noexcept {
31 return __builtin_bit_cast(_ToType, __from);
24template <class _ToType, class _FromType>
25 requires(sizeof(_ToType) == sizeof(_FromType) &&
26 is_trivially_copyable_v<_ToType> &&
27 is_trivially_copyable_v<_FromType>)
28_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr _ToType bit_cast(const _FromType& __from) noexcept {
29 return __builtin_bit_cast(_ToType, __from);
3230}
3331
3432#endif // _LIBCPP_STD_VER > 17
lib/libcxx/include/__bit/byteswap.h+2-2
......@@ -21,7 +21,7 @@
2121
2222_LIBCPP_BEGIN_NAMESPACE_STD
2323
24#if _LIBCPP_STD_VER > 20 && !defined(_LIBCPP_HAS_NO_CONCEPTS)
24#if _LIBCPP_STD_VER > 20
2525
2626template <integral _Tp>
2727_LIBCPP_HIDE_FROM_ABI constexpr _Tp byteswap(_Tp __val) noexcept {
......@@ -48,7 +48,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Tp byteswap(_Tp __val) noexcept {
4848 }
4949}
5050
51#endif // _LIBCPP_STD_VER > 20 && !defined(_LIBCPP_HAS_NO_CONCEPTS)
51#endif // _LIBCPP_STD_VER > 20
5252
5353_LIBCPP_END_NAMESPACE_STD
5454
lib/libcxx/include/__bit_reference+172-117
......@@ -10,12 +10,19 @@
1010#ifndef _LIBCPP___BIT_REFERENCE
1111#define _LIBCPP___BIT_REFERENCE
1212
13#include <__algorithm/copy_n.h>
14#include <__algorithm/fill_n.h>
15#include <__algorithm/min.h>
1316#include <__bits>
1417#include <__config>
15#include <algorithm>
18#include <__iterator/iterator_traits.h>
19#include <__memory/construct_at.h>
20#include <__memory/pointer_traits.h>
21#include <cstring>
22#include <type_traits>
1623
1724#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
25# pragma GCC system_header
1926#endif
2027
2128_LIBCPP_PUSH_MACROS
......@@ -47,15 +54,15 @@ class __bit_reference
4754 friend class __bit_const_reference<_Cp>;
4855 friend class __bit_iterator<_Cp, false>;
4956public:
50 _LIBCPP_INLINE_VISIBILITY
57 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
5158 __bit_reference(const __bit_reference&) = default;
5259
53 _LIBCPP_INLINE_VISIBILITY operator bool() const _NOEXCEPT
60 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 operator bool() const _NOEXCEPT
5461 {return static_cast<bool>(*__seg_ & __mask_);}
55 _LIBCPP_INLINE_VISIBILITY bool operator ~() const _NOEXCEPT
62 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 bool operator ~() const _NOEXCEPT
5663 {return !static_cast<bool>(*this);}
5764
58 _LIBCPP_INLINE_VISIBILITY
65 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
5966 __bit_reference& operator=(bool __x) _NOEXCEPT
6067 {
6168 if (__x)
......@@ -65,16 +72,26 @@ public:
6572 return *this;
6673 }
6774
68 _LIBCPP_INLINE_VISIBILITY
75#if _LIBCPP_STD_VER > 20
76 _LIBCPP_HIDE_FROM_ABI constexpr const __bit_reference& operator=(bool __x) const noexcept {
77 if (__x)
78 *__seg_ |= __mask_;
79 else
80 *__seg_ &= ~__mask_;
81 return *this;
82 }
83#endif
84
85 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
6986 __bit_reference& operator=(const __bit_reference& __x) _NOEXCEPT
7087 {return operator=(static_cast<bool>(__x));}
7188
72 _LIBCPP_INLINE_VISIBILITY void flip() _NOEXCEPT {*__seg_ ^= __mask_;}
73 _LIBCPP_INLINE_VISIBILITY __bit_iterator<_Cp, false> operator&() const _NOEXCEPT
89 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 void flip() _NOEXCEPT {*__seg_ ^= __mask_;}
90 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 __bit_iterator<_Cp, false> operator&() const _NOEXCEPT
7491 {return __bit_iterator<_Cp, false>(__seg_, static_cast<unsigned>(__libcpp_ctz(__mask_)));}
7592private:
76 _LIBCPP_INLINE_VISIBILITY
77 __bit_reference(__storage_pointer __s, __storage_type __m) _NOEXCEPT
93 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
94 explicit __bit_reference(__storage_pointer __s, __storage_type __m) _NOEXCEPT
7895 : __seg_(__s), __mask_(__m) {}
7996};
8097
......@@ -84,7 +101,7 @@ class __bit_reference<_Cp, false>
84101};
85102
86103template <class _Cp>
87inline _LIBCPP_INLINE_VISIBILITY
104inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
88105void
89106swap(__bit_reference<_Cp> __x, __bit_reference<_Cp> __y) _NOEXCEPT
90107{
......@@ -94,7 +111,7 @@ swap(__bit_reference<_Cp> __x, __bit_reference<_Cp> __y) _NOEXCEPT
94111}
95112
96113template <class _Cp, class _Dp>
97inline _LIBCPP_INLINE_VISIBILITY
114inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
98115void
99116swap(__bit_reference<_Cp> __x, __bit_reference<_Dp> __y) _NOEXCEPT
100117{
......@@ -104,7 +121,7 @@ swap(__bit_reference<_Cp> __x, __bit_reference<_Dp> __y) _NOEXCEPT
104121}
105122
106123template <class _Cp>
107inline _LIBCPP_INLINE_VISIBILITY
124inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
108125void
109126swap(__bit_reference<_Cp> __x, bool& __y) _NOEXCEPT
110127{
......@@ -114,7 +131,7 @@ swap(__bit_reference<_Cp> __x, bool& __y) _NOEXCEPT
114131}
115132
116133template <class _Cp>
117inline _LIBCPP_INLINE_VISIBILITY
134inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
118135void
119136swap(bool& __x, __bit_reference<_Cp> __y) _NOEXCEPT
120137{
......@@ -138,19 +155,19 @@ public:
138155 _LIBCPP_INLINE_VISIBILITY
139156 __bit_const_reference(const __bit_const_reference&) = default;
140157
141 _LIBCPP_INLINE_VISIBILITY
158 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
142159 __bit_const_reference(const __bit_reference<_Cp>& __x) _NOEXCEPT
143160 : __seg_(__x.__seg_), __mask_(__x.__mask_) {}
144161
145162 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR operator bool() const _NOEXCEPT
146163 {return static_cast<bool>(*__seg_ & __mask_);}
147164
148 _LIBCPP_INLINE_VISIBILITY __bit_iterator<_Cp, true> operator&() const _NOEXCEPT
165 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 __bit_iterator<_Cp, true> operator&() const _NOEXCEPT
149166 {return __bit_iterator<_Cp, true>(__seg_, static_cast<unsigned>(__libcpp_ctz(__mask_)));}
150167private:
151168 _LIBCPP_INLINE_VISIBILITY
152169 _LIBCPP_CONSTEXPR
153 __bit_const_reference(__storage_pointer __s, __storage_type __m) _NOEXCEPT
170 explicit __bit_const_reference(__storage_pointer __s, __storage_type __m) _NOEXCEPT
154171 : __seg_(__s), __mask_(__m) {}
155172
156173 __bit_const_reference& operator=(const __bit_const_reference&) = delete;
......@@ -159,12 +176,12 @@ private:
159176// find
160177
161178template <class _Cp, bool _IsConst>
162__bit_iterator<_Cp, _IsConst>
179_LIBCPP_CONSTEXPR_AFTER_CXX17 __bit_iterator<_Cp, _IsConst>
163180__find_bool_true(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n)
164181{
165182 typedef __bit_iterator<_Cp, _IsConst> _It;
166183 typedef typename _It::__storage_type __storage_type;
167 static const int __bits_per_word = _It::__bits_per_word;
184 const int __bits_per_word = _It::__bits_per_word;
168185 // do first partial word
169186 if (__first.__ctz_ != 0)
170187 {
......@@ -195,7 +212,7 @@ __find_bool_true(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type
195212}
196213
197214template <class _Cp, bool _IsConst>
198__bit_iterator<_Cp, _IsConst>
215_LIBCPP_CONSTEXPR_AFTER_CXX17 __bit_iterator<_Cp, _IsConst>
199216__find_bool_false(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n)
200217{
201218 typedef __bit_iterator<_Cp, _IsConst> _It;
......@@ -234,11 +251,11 @@ __find_bool_false(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type
234251}
235252
236253template <class _Cp, bool _IsConst, class _Tp>
237inline _LIBCPP_INLINE_VISIBILITY
254inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
238255__bit_iterator<_Cp, _IsConst>
239find(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value_)
256find(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value)
240257{
241 if (static_cast<bool>(__value_))
258 if (static_cast<bool>(__value))
242259 return _VSTD::__find_bool_true(__first, static_cast<typename _Cp::size_type>(__last - __first));
243260 return _VSTD::__find_bool_false(__first, static_cast<typename _Cp::size_type>(__last - __first));
244261}
......@@ -310,9 +327,9 @@ __count_bool_false(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_typ
310327template <class _Cp, bool _IsConst, class _Tp>
311328inline _LIBCPP_INLINE_VISIBILITY
312329typename __bit_iterator<_Cp, _IsConst>::difference_type
313count(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value_)
330count(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value)
314331{
315 if (static_cast<bool>(__value_))
332 if (static_cast<bool>(__value))
316333 return _VSTD::__count_bool_true(__first, static_cast<typename _Cp::size_type>(__last - __first));
317334 return _VSTD::__count_bool_false(__first, static_cast<typename _Cp::size_type>(__last - __first));
318335}
......@@ -320,7 +337,7 @@ count(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __las
320337// fill_n
321338
322339template <class _Cp>
323void
340_LIBCPP_CONSTEXPR_AFTER_CXX17 void
324341__fill_n_false(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n)
325342{
326343 typedef __bit_iterator<_Cp, false> _It;
......@@ -338,7 +355,7 @@ __fill_n_false(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n)
338355 }
339356 // do middle whole words
340357 __storage_type __nw = __n / __bits_per_word;
341 _VSTD::memset(_VSTD::__to_address(__first.__seg_), 0, __nw * sizeof(__storage_type));
358 std::fill_n(std::__to_address(__first.__seg_), __nw, 0);
342359 __n -= __nw * __bits_per_word;
343360 // do last partial word
344361 if (__n > 0)
......@@ -350,7 +367,7 @@ __fill_n_false(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n)
350367}
351368
352369template <class _Cp>
353void
370_LIBCPP_CONSTEXPR_AFTER_CXX17 void
354371__fill_n_true(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n)
355372{
356373 typedef __bit_iterator<_Cp, false> _It;
......@@ -368,7 +385,8 @@ __fill_n_true(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n)
368385 }
369386 // do middle whole words
370387 __storage_type __nw = __n / __bits_per_word;
371 _VSTD::memset(_VSTD::__to_address(__first.__seg_), -1, __nw * sizeof(__storage_type));
388 // __storage_type is always an unsigned type, so -1 sets all bits
389 std::fill_n(std::__to_address(__first.__seg_), __nw, static_cast<__storage_type>(-1));
372390 __n -= __nw * __bits_per_word;
373391 // do last partial word
374392 if (__n > 0)
......@@ -380,13 +398,13 @@ __fill_n_true(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n)
380398}
381399
382400template <class _Cp>
383inline _LIBCPP_INLINE_VISIBILITY
401inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
384402void
385fill_n(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n, bool __value_)
403fill_n(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n, bool __value)
386404{
387405 if (__n > 0)
388406 {
389 if (__value_)
407 if (__value)
390408 _VSTD::__fill_n_true(__first, __n);
391409 else
392410 _VSTD::__fill_n_false(__first, __n);
......@@ -396,16 +414,17 @@ fill_n(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n, bool __v
396414// fill
397415
398416template <class _Cp>
399inline _LIBCPP_INLINE_VISIBILITY
417inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
400418void
401fill(__bit_iterator<_Cp, false> __first, __bit_iterator<_Cp, false> __last, bool __value_)
419fill(__bit_iterator<_Cp, false> __first, __bit_iterator<_Cp, false> __last, bool __value)
402420{
403 _VSTD::fill_n(__first, static_cast<typename _Cp::size_type>(__last - __first), __value_);
421 _VSTD::fill_n(__first, static_cast<typename _Cp::size_type>(__last - __first), __value);
404422}
405423
406424// copy
407425
408426template <class _Cp, bool _IsConst>
427_LIBCPP_CONSTEXPR_AFTER_CXX17
409428__bit_iterator<_Cp, false>
410429__copy_aligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last,
411430 __bit_iterator<_Cp, false> __result)
......@@ -435,9 +454,7 @@ __copy_aligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsCon
435454 // __first.__ctz_ == 0;
436455 // do middle words
437456 __storage_type __nw = __n / __bits_per_word;
438 _VSTD::memmove(_VSTD::__to_address(__result.__seg_),
439 _VSTD::__to_address(__first.__seg_),
440 __nw * sizeof(__storage_type));
457 std::copy_n(std::__to_address(__first.__seg_), __nw, std::__to_address(__result.__seg_));
441458 __n -= __nw * __bits_per_word;
442459 __result.__seg_ += __nw;
443460 // do last word
......@@ -455,6 +472,7 @@ __copy_aligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsCon
455472}
456473
457474template <class _Cp, bool _IsConst>
475_LIBCPP_CONSTEXPR_AFTER_CXX17
458476__bit_iterator<_Cp, false>
459477__copy_unaligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last,
460478 __bit_iterator<_Cp, false> __result)
......@@ -462,7 +480,7 @@ __copy_unaligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsC
462480 typedef __bit_iterator<_Cp, _IsConst> _In;
463481 typedef typename _In::difference_type difference_type;
464482 typedef typename _In::__storage_type __storage_type;
465 static const int __bits_per_word = _In::__bits_per_word;
483 const int __bits_per_word = _In::__bits_per_word;
466484 difference_type __n = __last - __first;
467485 if (__n > 0)
468486 {
......@@ -533,7 +551,7 @@ __copy_unaligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsC
533551}
534552
535553template <class _Cp, bool _IsConst>
536inline _LIBCPP_INLINE_VISIBILITY
554inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
537555__bit_iterator<_Cp, false>
538556copy(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result)
539557{
......@@ -545,7 +563,7 @@ copy(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last
545563// copy_backward
546564
547565template <class _Cp, bool _IsConst>
548__bit_iterator<_Cp, false>
566_LIBCPP_CONSTEXPR_AFTER_CXX17 __bit_iterator<_Cp, false>
549567__copy_backward_aligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last,
550568 __bit_iterator<_Cp, false> __result)
551569{
......@@ -576,9 +594,7 @@ __copy_backward_aligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_C
576594 __storage_type __nw = __n / __bits_per_word;
577595 __result.__seg_ -= __nw;
578596 __last.__seg_ -= __nw;
579 _VSTD::memmove(_VSTD::__to_address(__result.__seg_),
580 _VSTD::__to_address(__last.__seg_),
581 __nw * sizeof(__storage_type));
597 std::copy_n(std::__to_address(__last.__seg_), __nw, std::__to_address(__result.__seg_));
582598 __n -= __nw * __bits_per_word;
583599 // do last word
584600 if (__n > 0)
......@@ -594,7 +610,7 @@ __copy_backward_aligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_C
594610}
595611
596612template <class _Cp, bool _IsConst>
597__bit_iterator<_Cp, false>
613_LIBCPP_CONSTEXPR_AFTER_CXX17 __bit_iterator<_Cp, false>
598614__copy_backward_unaligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last,
599615 __bit_iterator<_Cp, false> __result)
600616{
......@@ -680,7 +696,7 @@ __copy_backward_unaligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<
680696}
681697
682698template <class _Cp, bool _IsConst>
683inline _LIBCPP_INLINE_VISIBILITY
699inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
684700__bit_iterator<_Cp, false>
685701copy_backward(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result)
686702{
......@@ -887,14 +903,19 @@ struct __bit_array
887903 difference_type __size_;
888904 __storage_type __word_[_Np];
889905
890 _LIBCPP_INLINE_VISIBILITY static difference_type capacity()
906 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 static difference_type capacity()
891907 {return static_cast<difference_type>(_Np * __bits_per_word);}
892 _LIBCPP_INLINE_VISIBILITY explicit __bit_array(difference_type __s) : __size_(__s) {}
893 _LIBCPP_INLINE_VISIBILITY iterator begin()
908 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit __bit_array(difference_type __s) : __size_(__s) {
909 if (__libcpp_is_constant_evaluated()) {
910 for (size_t __i = 0; __i != __bit_array<_Cp>::_Np; ++__i)
911 std::__construct_at(__word_ + __i, 0);
912 }
913 }
914 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 iterator begin()
894915 {
895916 return iterator(pointer_traits<__storage_pointer>::pointer_to(__word_[0]), 0);
896917 }
897 _LIBCPP_INLINE_VISIBILITY iterator end()
918 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 iterator end()
898919 {
899920 return iterator(pointer_traits<__storage_pointer>::pointer_to(__word_[0]) + __size_ / __bits_per_word,
900921 static_cast<unsigned>(__size_ % __bits_per_word));
......@@ -902,7 +923,7 @@ struct __bit_array
902923};
903924
904925template <class _Cp>
905__bit_iterator<_Cp, false>
926_LIBCPP_CONSTEXPR_AFTER_CXX17 __bit_iterator<_Cp, false>
906927rotate(__bit_iterator<_Cp, false> __first, __bit_iterator<_Cp, false> __middle, __bit_iterator<_Cp, false> __last)
907928{
908929 typedef __bit_iterator<_Cp, false> _I1;
......@@ -953,14 +974,14 @@ rotate(__bit_iterator<_Cp, false> __first, __bit_iterator<_Cp, false> __middle,
953974// equal
954975
955976template <class _Cp, bool _IC1, bool _IC2>
956bool
977_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
957978__equal_unaligned(__bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> __last1,
958979 __bit_iterator<_Cp, _IC2> __first2)
959980{
960981 typedef __bit_iterator<_Cp, _IC1> _It;
961982 typedef typename _It::difference_type difference_type;
962983 typedef typename _It::__storage_type __storage_type;
963 static const int __bits_per_word = _It::__bits_per_word;
984 const int __bits_per_word = _It::__bits_per_word;
964985 difference_type __n = __last1 - __first1;
965986 if (__n > 0)
966987 {
......@@ -1035,14 +1056,14 @@ __equal_unaligned(__bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1>
10351056}
10361057
10371058template <class _Cp, bool _IC1, bool _IC2>
1038bool
1059_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
10391060__equal_aligned(__bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> __last1,
10401061 __bit_iterator<_Cp, _IC2> __first2)
10411062{
10421063 typedef __bit_iterator<_Cp, _IC1> _It;
10431064 typedef typename _It::difference_type difference_type;
10441065 typedef typename _It::__storage_type __storage_type;
1045 static const int __bits_per_word = _It::__bits_per_word;
1066 const int __bits_per_word = _It::__bits_per_word;
10461067 difference_type __n = __last1 - __first1;
10471068 if (__n > 0)
10481069 {
......@@ -1078,7 +1099,7 @@ __equal_aligned(__bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> __
10781099}
10791100
10801101template <class _Cp, bool _IC1, bool _IC2>
1081inline _LIBCPP_INLINE_VISIBILITY
1102inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
10821103bool
10831104equal(__bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> __last1, __bit_iterator<_Cp, _IC2> __first2)
10841105{
......@@ -1095,7 +1116,11 @@ public:
10951116 typedef typename _Cp::difference_type difference_type;
10961117 typedef bool value_type;
10971118 typedef __bit_iterator pointer;
1119#ifndef _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL
10981120 typedef typename conditional<_IsConst, __bit_const_reference<_Cp>, __bit_reference<_Cp> >::type reference;
1121#else
1122 using reference = typename conditional<_IsConst, bool, __bit_reference<_Cp> >::type;
1123#endif
10991124 typedef random_access_iterator_tag iterator_category;
11001125
11011126private:
......@@ -1108,7 +1133,7 @@ private:
11081133 unsigned __ctz_;
11091134
11101135public:
1111 _LIBCPP_INLINE_VISIBILITY __bit_iterator() _NOEXCEPT
1136 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 __bit_iterator() _NOEXCEPT
11121137#if _LIBCPP_STD_VER > 11
11131138 : __seg_(nullptr), __ctz_(0)
11141139#endif
......@@ -1119,7 +1144,7 @@ public:
11191144 // When _IsConst=true, this is a converting constructor;
11201145 // the copy and move constructors are implicitly generated
11211146 // and trivial.
1122 _LIBCPP_INLINE_VISIBILITY
1147 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
11231148 __bit_iterator(const __bit_iterator<_Cp, false>& __it) _NOEXCEPT
11241149 : __seg_(__it.__seg_), __ctz_(__it.__ctz_) {}
11251150
......@@ -1128,17 +1153,19 @@ public:
11281153 // the implicit generation of a defaulted one is deprecated.
11291154 // When _IsConst=true, the assignment operators are
11301155 // implicitly generated and trivial.
1131 _LIBCPP_INLINE_VISIBILITY
1156 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
11321157 __bit_iterator& operator=(const _If<_IsConst, struct __private_nat, __bit_iterator>& __it) {
11331158 __seg_ = __it.__seg_;
11341159 __ctz_ = __it.__ctz_;
11351160 return *this;
11361161 }
11371162
1138 _LIBCPP_INLINE_VISIBILITY reference operator*() const _NOEXCEPT
1139 {return reference(__seg_, __storage_type(1) << __ctz_);}
1163 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 reference operator*() const _NOEXCEPT {
1164 return typename conditional<_IsConst, __bit_const_reference<_Cp>, __bit_reference<_Cp> >
1165 ::type(__seg_, __storage_type(1) << __ctz_);
1166 }
11401167
1141 _LIBCPP_INLINE_VISIBILITY __bit_iterator& operator++()
1168 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 __bit_iterator& operator++()
11421169 {
11431170 if (__ctz_ != __bits_per_word-1)
11441171 ++__ctz_;
......@@ -1150,14 +1177,14 @@ public:
11501177 return *this;
11511178 }
11521179
1153 _LIBCPP_INLINE_VISIBILITY __bit_iterator operator++(int)
1180 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 __bit_iterator operator++(int)
11541181 {
11551182 __bit_iterator __tmp = *this;
11561183 ++(*this);
11571184 return __tmp;
11581185 }
11591186
1160 _LIBCPP_INLINE_VISIBILITY __bit_iterator& operator--()
1187 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 __bit_iterator& operator--()
11611188 {
11621189 if (__ctz_ != 0)
11631190 --__ctz_;
......@@ -1169,14 +1196,14 @@ public:
11691196 return *this;
11701197 }
11711198
1172 _LIBCPP_INLINE_VISIBILITY __bit_iterator operator--(int)
1199 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 __bit_iterator operator--(int)
11731200 {
11741201 __bit_iterator __tmp = *this;
11751202 --(*this);
11761203 return __tmp;
11771204 }
11781205
1179 _LIBCPP_INLINE_VISIBILITY __bit_iterator& operator+=(difference_type __n)
1206 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 __bit_iterator& operator+=(difference_type __n)
11801207 {
11811208 if (__n >= 0)
11821209 __seg_ += (__n + __ctz_) / __bits_per_word;
......@@ -1188,55 +1215,55 @@ public:
11881215 return *this;
11891216 }
11901217
1191 _LIBCPP_INLINE_VISIBILITY __bit_iterator& operator-=(difference_type __n)
1218 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 __bit_iterator& operator-=(difference_type __n)
11921219 {
11931220 return *this += -__n;
11941221 }
11951222
1196 _LIBCPP_INLINE_VISIBILITY __bit_iterator operator+(difference_type __n) const
1223 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 __bit_iterator operator+(difference_type __n) const
11971224 {
11981225 __bit_iterator __t(*this);
11991226 __t += __n;
12001227 return __t;
12011228 }
12021229
1203 _LIBCPP_INLINE_VISIBILITY __bit_iterator operator-(difference_type __n) const
1230 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 __bit_iterator operator-(difference_type __n) const
12041231 {
12051232 __bit_iterator __t(*this);
12061233 __t -= __n;
12071234 return __t;
12081235 }
12091236
1210 _LIBCPP_INLINE_VISIBILITY
1237 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
12111238 friend __bit_iterator operator+(difference_type __n, const __bit_iterator& __it) {return __it + __n;}
12121239
1213 _LIBCPP_INLINE_VISIBILITY
1240 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
12141241 friend difference_type operator-(const __bit_iterator& __x, const __bit_iterator& __y)
12151242 {return (__x.__seg_ - __y.__seg_) * __bits_per_word + __x.__ctz_ - __y.__ctz_;}
12161243
1217 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const {return *(*this + __n);}
1244 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 reference operator[](difference_type __n) const {return *(*this + __n);}
12181245
1219 _LIBCPP_INLINE_VISIBILITY friend bool operator==(const __bit_iterator& __x, const __bit_iterator& __y)
1246 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 friend bool operator==(const __bit_iterator& __x, const __bit_iterator& __y)
12201247 {return __x.__seg_ == __y.__seg_ && __x.__ctz_ == __y.__ctz_;}
12211248
1222 _LIBCPP_INLINE_VISIBILITY friend bool operator!=(const __bit_iterator& __x, const __bit_iterator& __y)
1249 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 friend bool operator!=(const __bit_iterator& __x, const __bit_iterator& __y)
12231250 {return !(__x == __y);}
12241251
1225 _LIBCPP_INLINE_VISIBILITY friend bool operator<(const __bit_iterator& __x, const __bit_iterator& __y)
1252 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 friend bool operator<(const __bit_iterator& __x, const __bit_iterator& __y)
12261253 {return __x.__seg_ < __y.__seg_ || (__x.__seg_ == __y.__seg_ && __x.__ctz_ < __y.__ctz_);}
12271254
1228 _LIBCPP_INLINE_VISIBILITY friend bool operator>(const __bit_iterator& __x, const __bit_iterator& __y)
1255 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 friend bool operator>(const __bit_iterator& __x, const __bit_iterator& __y)
12291256 {return __y < __x;}
12301257
1231 _LIBCPP_INLINE_VISIBILITY friend bool operator<=(const __bit_iterator& __x, const __bit_iterator& __y)
1258 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 friend bool operator<=(const __bit_iterator& __x, const __bit_iterator& __y)
12321259 {return !(__y < __x);}
12331260
1234 _LIBCPP_INLINE_VISIBILITY friend bool operator>=(const __bit_iterator& __x, const __bit_iterator& __y)
1261 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 friend bool operator>=(const __bit_iterator& __x, const __bit_iterator& __y)
12351262 {return !(__x < __y);}
12361263
12371264private:
1238 _LIBCPP_INLINE_VISIBILITY
1239 __bit_iterator(__storage_pointer __s, unsigned __ctz) _NOEXCEPT
1265 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1266 explicit __bit_iterator(__storage_pointer __s, unsigned __ctz) _NOEXCEPT
12401267 : __seg_(__s), __ctz_(__ctz) {}
12411268
12421269 friend typename _Cp::__self;
......@@ -1245,26 +1272,44 @@ private:
12451272 friend class __bit_const_reference<_Cp>;
12461273 friend class __bit_iterator<_Cp, true>;
12471274 template <class _Dp> friend struct __bit_array;
1248 template <class _Dp> friend void __fill_n_false(__bit_iterator<_Dp, false> __first, typename _Dp::size_type __n);
1249 template <class _Dp> friend void __fill_n_true(__bit_iterator<_Dp, false> __first, typename _Dp::size_type __n);
1250 template <class _Dp, bool _IC> friend __bit_iterator<_Dp, false> __copy_aligned(__bit_iterator<_Dp, _IC> __first,
1251 __bit_iterator<_Dp, _IC> __last,
1252 __bit_iterator<_Dp, false> __result);
1253 template <class _Dp, bool _IC> friend __bit_iterator<_Dp, false> __copy_unaligned(__bit_iterator<_Dp, _IC> __first,
1254 __bit_iterator<_Dp, _IC> __last,
1255 __bit_iterator<_Dp, false> __result);
1256 template <class _Dp, bool _IC> friend __bit_iterator<_Dp, false> copy(__bit_iterator<_Dp, _IC> __first,
1257 __bit_iterator<_Dp, _IC> __last,
1258 __bit_iterator<_Dp, false> __result);
1259 template <class _Dp, bool _IC> friend __bit_iterator<_Dp, false> __copy_backward_aligned(__bit_iterator<_Dp, _IC> __first,
1260 __bit_iterator<_Dp, _IC> __last,
1261 __bit_iterator<_Dp, false> __result);
1262 template <class _Dp, bool _IC> friend __bit_iterator<_Dp, false> __copy_backward_unaligned(__bit_iterator<_Dp, _IC> __first,
1263 __bit_iterator<_Dp, _IC> __last,
1264 __bit_iterator<_Dp, false> __result);
1265 template <class _Dp, bool _IC> friend __bit_iterator<_Dp, false> copy_backward(__bit_iterator<_Dp, _IC> __first,
1266 __bit_iterator<_Dp, _IC> __last,
1267 __bit_iterator<_Dp, false> __result);
1275 template <class _Dp>
1276 _LIBCPP_CONSTEXPR_AFTER_CXX17
1277 friend void __fill_n_false(__bit_iterator<_Dp, false> __first, typename _Dp::size_type __n);
1278
1279 template <class _Dp>
1280 _LIBCPP_CONSTEXPR_AFTER_CXX17
1281 friend void __fill_n_true(__bit_iterator<_Dp, false> __first, typename _Dp::size_type __n);
1282
1283 template <class _Dp, bool _IC>
1284 _LIBCPP_CONSTEXPR_AFTER_CXX17
1285 friend __bit_iterator<_Dp, false> __copy_aligned(__bit_iterator<_Dp, _IC> __first,
1286 __bit_iterator<_Dp, _IC> __last,
1287 __bit_iterator<_Dp, false> __result);
1288 template <class _Dp, bool _IC>
1289 _LIBCPP_CONSTEXPR_AFTER_CXX17
1290 friend __bit_iterator<_Dp, false> __copy_unaligned(__bit_iterator<_Dp, _IC> __first,
1291 __bit_iterator<_Dp, _IC> __last,
1292 __bit_iterator<_Dp, false> __result);
1293 template <class _Dp, bool _IC>
1294 _LIBCPP_CONSTEXPR_AFTER_CXX17
1295 friend __bit_iterator<_Dp, false> copy(__bit_iterator<_Dp, _IC> __first,
1296 __bit_iterator<_Dp, _IC> __last,
1297 __bit_iterator<_Dp, false> __result);
1298 template <class _Dp, bool _IC>
1299 _LIBCPP_CONSTEXPR_AFTER_CXX17
1300 friend __bit_iterator<_Dp, false> __copy_backward_aligned(__bit_iterator<_Dp, _IC> __first,
1301 __bit_iterator<_Dp, _IC> __last,
1302 __bit_iterator<_Dp, false> __result);
1303 template <class _Dp, bool _IC>
1304 _LIBCPP_CONSTEXPR_AFTER_CXX17
1305 friend __bit_iterator<_Dp, false> __copy_backward_unaligned(__bit_iterator<_Dp, _IC> __first,
1306 __bit_iterator<_Dp, _IC> __last,
1307 __bit_iterator<_Dp, false> __result);
1308 template <class _Dp, bool _IC>
1309 _LIBCPP_CONSTEXPR_AFTER_CXX17
1310 friend __bit_iterator<_Dp, false> copy_backward(__bit_iterator<_Dp, _IC> __first,
1311 __bit_iterator<_Dp, _IC> __last,
1312 __bit_iterator<_Dp, false> __result);
12681313 template <class __C1, class __C2>friend __bit_iterator<__C2, false> __swap_ranges_aligned(__bit_iterator<__C1, false>,
12691314 __bit_iterator<__C1, false>,
12701315 __bit_iterator<__C2, false>);
......@@ -1274,22 +1319,32 @@ private:
12741319 template <class __C1, class __C2>friend __bit_iterator<__C2, false> swap_ranges(__bit_iterator<__C1, false>,
12751320 __bit_iterator<__C1, false>,
12761321 __bit_iterator<__C2, false>);
1277 template <class _Dp> friend __bit_iterator<_Dp, false> rotate(__bit_iterator<_Dp, false>,
1278 __bit_iterator<_Dp, false>,
1279 __bit_iterator<_Dp, false>);
1280 template <class _Dp, bool _IC1, bool _IC2> friend bool __equal_aligned(__bit_iterator<_Dp, _IC1>,
1281 __bit_iterator<_Dp, _IC1>,
1282 __bit_iterator<_Dp, _IC2>);
1283 template <class _Dp, bool _IC1, bool _IC2> friend bool __equal_unaligned(__bit_iterator<_Dp, _IC1>,
1284 __bit_iterator<_Dp, _IC1>,
1285 __bit_iterator<_Dp, _IC2>);
1286 template <class _Dp, bool _IC1, bool _IC2> friend bool equal(__bit_iterator<_Dp, _IC1>,
1287 __bit_iterator<_Dp, _IC1>,
1288 __bit_iterator<_Dp, _IC2>);
1289 template <class _Dp, bool _IC> friend __bit_iterator<_Dp, _IC> __find_bool_true(__bit_iterator<_Dp, _IC>,
1290 typename _Dp::size_type);
1291 template <class _Dp, bool _IC> friend __bit_iterator<_Dp, _IC> __find_bool_false(__bit_iterator<_Dp, _IC>,
1292 typename _Dp::size_type);
1322 template <class _Dp>
1323 _LIBCPP_CONSTEXPR_AFTER_CXX17
1324 friend __bit_iterator<_Dp, false> rotate(__bit_iterator<_Dp, false>,
1325 __bit_iterator<_Dp, false>,
1326 __bit_iterator<_Dp, false>);
1327 template <class _Dp, bool _IC1, bool _IC2>
1328 _LIBCPP_CONSTEXPR_AFTER_CXX17
1329 friend bool __equal_aligned(__bit_iterator<_Dp, _IC1>,
1330 __bit_iterator<_Dp, _IC1>,
1331 __bit_iterator<_Dp, _IC2>);
1332 template <class _Dp, bool _IC1, bool _IC2>
1333 _LIBCPP_CONSTEXPR_AFTER_CXX17
1334 friend bool __equal_unaligned(__bit_iterator<_Dp, _IC1>,
1335 __bit_iterator<_Dp, _IC1>,
1336 __bit_iterator<_Dp, _IC2>);
1337 template <class _Dp, bool _IC1, bool _IC2>
1338 _LIBCPP_CONSTEXPR_AFTER_CXX17
1339 friend bool equal(__bit_iterator<_Dp, _IC1>,
1340 __bit_iterator<_Dp, _IC1>,
1341 __bit_iterator<_Dp, _IC2>);
1342 template <class _Dp, bool _IC>
1343 _LIBCPP_CONSTEXPR_AFTER_CXX17
1344 friend __bit_iterator<_Dp, _IC> __find_bool_true(__bit_iterator<_Dp, _IC>, typename _Dp::size_type);
1345 template <class _Dp, bool _IC>
1346 _LIBCPP_CONSTEXPR_AFTER_CXX17
1347 friend __bit_iterator<_Dp, _IC> __find_bool_false(__bit_iterator<_Dp, _IC>, typename _Dp::size_type);
12931348 template <class _Dp, bool _IC> friend typename __bit_iterator<_Dp, _IC>::difference_type
12941349 __count_bool_true(__bit_iterator<_Dp, _IC>, typename _Dp::size_type);
12951350 template <class _Dp, bool _IC> friend typename __bit_iterator<_Dp, _IC>::difference_type
lib/libcxx/include/__bits+18-1
......@@ -13,7 +13,7 @@
1313#include <__config>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16#pragma GCC system_header
16# pragma GCC system_header
1717#endif
1818
1919_LIBCPP_PUSH_MACROS
......@@ -43,6 +43,23 @@ int __libcpp_clz(unsigned long __x) _NOEXCEPT { return __builtin_clzl(__x);
4343inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
4444int __libcpp_clz(unsigned long long __x) _NOEXCEPT { return __builtin_clzll(__x); }
4545
46# ifndef _LIBCPP_HAS_NO_INT128
47inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
48int __libcpp_clz(__uint128_t __x) _NOEXCEPT {
49 // The function is written in this form due to C++ constexpr limitations.
50 // The algorithm:
51 // - Test whether any bit in the high 64-bits is set
52 // - No bits set:
53 // - The high 64-bits contain 64 leading zeros,
54 // - Add the result of the low 64-bits.
55 // - Any bits set:
56 // - The number of leading zeros of the input is the number of leading
57 // zeros in the high 64-bits.
58 return ((__x >> 64) == 0)
59 ? (64 + __builtin_clzll(static_cast<unsigned long long>(__x)))
60 : __builtin_clzll(static_cast<unsigned long long>(__x >> 64));
61}
62# endif
4663
4764inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
4865int __libcpp_popcount(unsigned __x) _NOEXCEPT { return __builtin_popcount(__x); }
lib/libcxx/include/__bsd_locale_defaults.h+4-4
......@@ -11,11 +11,11 @@
1111// we will define the mapping from an internal macro to the real BSD symbol.
1212//===----------------------------------------------------------------------===//
1313
14#ifndef _LIBCPP_BSD_LOCALE_DEFAULTS_H
15#define _LIBCPP_BSD_LOCALE_DEFAULTS_H
14#ifndef _LIBCPP___BSD_LOCALE_DEFAULTS_H
15#define _LIBCPP___BSD_LOCALE_DEFAULTS_H
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121#define __libcpp_mb_cur_max_l(loc) MB_CUR_MAX_L(loc)
......@@ -33,4 +33,4 @@
3333#define __libcpp_asprintf_l(...) asprintf_l(__VA_ARGS__)
3434#define __libcpp_sscanf_l(...) sscanf_l(__VA_ARGS__)
3535
36#endif // _LIBCPP_BSD_LOCALE_DEFAULTS_H
36#endif // _LIBCPP___BSD_LOCALE_DEFAULTS_H
lib/libcxx/include/__bsd_locale_fallbacks.h+4-4
......@@ -10,15 +10,15 @@
1010// of those functions for non-BSD platforms.
1111//===----------------------------------------------------------------------===//
1212
13#ifndef _LIBCPP_BSD_LOCALE_FALLBACKS_DEFAULTS_H
14#define _LIBCPP_BSD_LOCALE_FALLBACKS_DEFAULTS_H
13#ifndef _LIBCPP___BSD_LOCALE_FALLBACKS_H
14#define _LIBCPP___BSD_LOCALE_FALLBACKS_H
1515
1616#include <memory>
1717#include <stdarg.h>
1818#include <stdlib.h>
1919
2020#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21#pragma GCC system_header
21# pragma GCC system_header
2222#endif
2323
2424_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -140,4 +140,4 @@ int __libcpp_sscanf_l(const char *__s, locale_t __l, const char *__format, ...)
140140
141141_LIBCPP_END_NAMESPACE_STD
142142
143#endif // _LIBCPP_BSD_LOCALE_FALLBACKS_DEFAULTS_H
143#endif // _LIBCPP___BSD_LOCALE_FALLBACKS_H
lib/libcxx/include/__charconv/chars_format.h+1-1
......@@ -14,7 +14,7 @@
1414#include <__utility/to_underlying.h>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
17# pragma GCC system_header
1818#endif
1919
2020_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__charconv/from_chars_result.h+1-1
......@@ -14,7 +14,7 @@
1414#include <__errc>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
17# pragma GCC system_header
1818#endif
1919
2020_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__charconv/tables.h created+180
......@@ -0,0 +1,180 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___CHARCONV_TABLES
11#define _LIBCPP___CHARCONV_TABLES
12
13#include <__config>
14#include <cstdint>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
20_LIBCPP_BEGIN_NAMESPACE_STD
21
22#ifndef _LIBCPP_CXX03_LANG
23
24namespace __itoa {
25
26/// Contains the charconv helper tables.
27///
28/// In C++17 these could be inline constexpr variable, but libc++ supports
29/// charconv for integrals in C++11 mode.
30template <class = void>
31struct __table {
32 static const char __base_2_lut[64];
33 static const char __base_8_lut[128];
34 static const char __base_16_lut[512];
35
36 static const uint32_t __pow10_32[10];
37 static const uint64_t __pow10_64[20];
38# ifndef _LIBCPP_HAS_NO_INT128
39 // TODO FMT Reduce the number of entries in this table.
40 static const __uint128_t __pow10_128[40];
41 static const int __pow10_128_offset = 0;
42# endif
43 static const char __digits_base_10[200];
44};
45
46template <class _Tp>
47const char __table<_Tp>::__base_2_lut[64] = {
48 '0', '0', '0', '0', '0', '0', '0', '1', '0', '0', '1', '0', '0', '0', '1', '1', '0', '1', '0', '0', '0', '1',
49 '0', '1', '0', '1', '1', '0', '0', '1', '1', '1', '1', '0', '0', '0', '1', '0', '0', '1', '1', '0', '1', '0',
50 '1', '0', '1', '1', '1', '1', '0', '0', '1', '1', '0', '1', '1', '1', '1', '0', '1', '1', '1', '1'};
51
52template <class _Tp>
53const char __table<_Tp>::__base_8_lut[128] = {
54 '0', '0', '0', '1', '0', '2', '0', '3', '0', '4', '0', '5', '0', '6', '0', '7', '1', '0', '1', '1', '1', '2',
55 '1', '3', '1', '4', '1', '5', '1', '6', '1', '7', '2', '0', '2', '1', '2', '2', '2', '3', '2', '4', '2', '5',
56 '2', '6', '2', '7', '3', '0', '3', '1', '3', '2', '3', '3', '3', '4', '3', '5', '3', '6', '3', '7', '4', '0',
57 '4', '1', '4', '2', '4', '3', '4', '4', '4', '5', '4', '6', '4', '7', '5', '0', '5', '1', '5', '2', '5', '3',
58 '5', '4', '5', '5', '5', '6', '5', '7', '6', '0', '6', '1', '6', '2', '6', '3', '6', '4', '6', '5', '6', '6',
59 '6', '7', '7', '0', '7', '1', '7', '2', '7', '3', '7', '4', '7', '5', '7', '6', '7', '7'};
60
61template <class _Tp>
62const char __table<_Tp>::__base_16_lut[512] = {
63 '0', '0', '0', '1', '0', '2', '0', '3', '0', '4', '0', '5', '0', '6', '0', '7', '0', '8', '0', '9', '0', 'a', '0',
64 'b', '0', 'c', '0', 'd', '0', 'e', '0', 'f', '1', '0', '1', '1', '1', '2', '1', '3', '1', '4', '1', '5', '1', '6',
65 '1', '7', '1', '8', '1', '9', '1', 'a', '1', 'b', '1', 'c', '1', 'd', '1', 'e', '1', 'f', '2', '0', '2', '1', '2',
66 '2', '2', '3', '2', '4', '2', '5', '2', '6', '2', '7', '2', '8', '2', '9', '2', 'a', '2', 'b', '2', 'c', '2', 'd',
67 '2', 'e', '2', 'f', '3', '0', '3', '1', '3', '2', '3', '3', '3', '4', '3', '5', '3', '6', '3', '7', '3', '8', '3',
68 '9', '3', 'a', '3', 'b', '3', 'c', '3', 'd', '3', 'e', '3', 'f', '4', '0', '4', '1', '4', '2', '4', '3', '4', '4',
69 '4', '5', '4', '6', '4', '7', '4', '8', '4', '9', '4', 'a', '4', 'b', '4', 'c', '4', 'd', '4', 'e', '4', 'f', '5',
70 '0', '5', '1', '5', '2', '5', '3', '5', '4', '5', '5', '5', '6', '5', '7', '5', '8', '5', '9', '5', 'a', '5', 'b',
71 '5', 'c', '5', 'd', '5', 'e', '5', 'f', '6', '0', '6', '1', '6', '2', '6', '3', '6', '4', '6', '5', '6', '6', '6',
72 '7', '6', '8', '6', '9', '6', 'a', '6', 'b', '6', 'c', '6', 'd', '6', 'e', '6', 'f', '7', '0', '7', '1', '7', '2',
73 '7', '3', '7', '4', '7', '5', '7', '6', '7', '7', '7', '8', '7', '9', '7', 'a', '7', 'b', '7', 'c', '7', 'd', '7',
74 'e', '7', 'f', '8', '0', '8', '1', '8', '2', '8', '3', '8', '4', '8', '5', '8', '6', '8', '7', '8', '8', '8', '9',
75 '8', 'a', '8', 'b', '8', 'c', '8', 'd', '8', 'e', '8', 'f', '9', '0', '9', '1', '9', '2', '9', '3', '9', '4', '9',
76 '5', '9', '6', '9', '7', '9', '8', '9', '9', '9', 'a', '9', 'b', '9', 'c', '9', 'd', '9', 'e', '9', 'f', 'a', '0',
77 'a', '1', 'a', '2', 'a', '3', 'a', '4', 'a', '5', 'a', '6', 'a', '7', 'a', '8', 'a', '9', 'a', 'a', 'a', 'b', 'a',
78 'c', 'a', 'd', 'a', 'e', 'a', 'f', 'b', '0', 'b', '1', 'b', '2', 'b', '3', 'b', '4', 'b', '5', 'b', '6', 'b', '7',
79 'b', '8', 'b', '9', 'b', 'a', 'b', 'b', 'b', 'c', 'b', 'd', 'b', 'e', 'b', 'f', 'c', '0', 'c', '1', 'c', '2', 'c',
80 '3', 'c', '4', 'c', '5', 'c', '6', 'c', '7', 'c', '8', 'c', '9', 'c', 'a', 'c', 'b', 'c', 'c', 'c', 'd', 'c', 'e',
81 'c', 'f', 'd', '0', 'd', '1', 'd', '2', 'd', '3', 'd', '4', 'd', '5', 'd', '6', 'd', '7', 'd', '8', 'd', '9', 'd',
82 'a', 'd', 'b', 'd', 'c', 'd', 'd', 'd', 'e', 'd', 'f', 'e', '0', 'e', '1', 'e', '2', 'e', '3', 'e', '4', 'e', '5',
83 'e', '6', 'e', '7', 'e', '8', 'e', '9', 'e', 'a', 'e', 'b', 'e', 'c', 'e', 'd', 'e', 'e', 'e', 'f', 'f', '0', 'f',
84 '1', 'f', '2', 'f', '3', 'f', '4', 'f', '5', 'f', '6', 'f', '7', 'f', '8', 'f', '9', 'f', 'a', 'f', 'b', 'f', 'c',
85 'f', 'd', 'f', 'e', 'f', 'f'};
86
87template <class _Tp>
88const uint32_t __table<_Tp>::__pow10_32[10] = {
89 UINT32_C(0), UINT32_C(10), UINT32_C(100), UINT32_C(1000), UINT32_C(10000),
90 UINT32_C(100000), UINT32_C(1000000), UINT32_C(10000000), UINT32_C(100000000), UINT32_C(1000000000)};
91
92template <class _Tp>
93const uint64_t __table<_Tp>::__pow10_64[20] = {UINT64_C(0),
94 UINT64_C(10),
95 UINT64_C(100),
96 UINT64_C(1000),
97 UINT64_C(10000),
98 UINT64_C(100000),
99 UINT64_C(1000000),
100 UINT64_C(10000000),
101 UINT64_C(100000000),
102 UINT64_C(1000000000),
103 UINT64_C(10000000000),
104 UINT64_C(100000000000),
105 UINT64_C(1000000000000),
106 UINT64_C(10000000000000),
107 UINT64_C(100000000000000),
108 UINT64_C(1000000000000000),
109 UINT64_C(10000000000000000),
110 UINT64_C(100000000000000000),
111 UINT64_C(1000000000000000000),
112 UINT64_C(10000000000000000000)};
113
114# ifndef _LIBCPP_HAS_NO_INT128
115template <class _Tp>
116const __uint128_t __table<_Tp>::__pow10_128[40] = {
117 UINT64_C(0),
118 UINT64_C(10),
119 UINT64_C(100),
120 UINT64_C(1000),
121 UINT64_C(10000),
122 UINT64_C(100000),
123 UINT64_C(1000000),
124 UINT64_C(10000000),
125 UINT64_C(100000000),
126 UINT64_C(1000000000),
127 UINT64_C(10000000000),
128 UINT64_C(100000000000),
129 UINT64_C(1000000000000),
130 UINT64_C(10000000000000),
131 UINT64_C(100000000000000),
132 UINT64_C(1000000000000000),
133 UINT64_C(10000000000000000),
134 UINT64_C(100000000000000000),
135 UINT64_C(1000000000000000000),
136 UINT64_C(10000000000000000000),
137 __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(10),
138 __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(100),
139 __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(1000),
140 __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(10000),
141 __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(100000),
142 __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(1000000),
143 __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(10000000),
144 __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(100000000),
145 __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(1000000000),
146 __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(10000000000),
147 __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(100000000000),
148 __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(1000000000000),
149 __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(10000000000000),
150 __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(100000000000000),
151 __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(1000000000000000),
152 __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(10000000000000000),
153 __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(100000000000000000),
154 __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(1000000000000000000),
155 __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(10000000000000000000),
156 (__uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(10000000000000000000)) * 10};
157# endif
158
159template <class _Tp>
160const char __table<_Tp>::__digits_base_10[200] = {
161 // clang-format off
162 '0', '0', '0', '1', '0', '2', '0', '3', '0', '4', '0', '5', '0', '6', '0', '7', '0', '8', '0', '9',
163 '1', '0', '1', '1', '1', '2', '1', '3', '1', '4', '1', '5', '1', '6', '1', '7', '1', '8', '1', '9',
164 '2', '0', '2', '1', '2', '2', '2', '3', '2', '4', '2', '5', '2', '6', '2', '7', '2', '8', '2', '9',
165 '3', '0', '3', '1', '3', '2', '3', '3', '3', '4', '3', '5', '3', '6', '3', '7', '3', '8', '3', '9',
166 '4', '0', '4', '1', '4', '2', '4', '3', '4', '4', '4', '5', '4', '6', '4', '7', '4', '8', '4', '9',
167 '5', '0', '5', '1', '5', '2', '5', '3', '5', '4', '5', '5', '5', '6', '5', '7', '5', '8', '5', '9',
168 '6', '0', '6', '1', '6', '2', '6', '3', '6', '4', '6', '5', '6', '6', '6', '7', '6', '8', '6', '9',
169 '7', '0', '7', '1', '7', '2', '7', '3', '7', '4', '7', '5', '7', '6', '7', '7', '7', '8', '7', '9',
170 '8', '0', '8', '1', '8', '2', '8', '3', '8', '4', '8', '5', '8', '6', '8', '7', '8', '8', '8', '9',
171 '9', '0', '9', '1', '9', '2', '9', '3', '9', '4', '9', '5', '9', '6', '9', '7', '9', '8', '9', '9'};
172// clang-format on
173
174} // namespace __itoa
175
176#endif // _LIBCPP_CXX03_LANG
177
178_LIBCPP_END_NAMESPACE_STD
179
180#endif // _LIBCPP___CHARCONV_TABLES
lib/libcxx/include/__charconv/to_chars_base_10.h created+185
......@@ -0,0 +1,185 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___CHARCONV_TO_CHARS_BASE_10_H
11#define _LIBCPP___CHARCONV_TO_CHARS_BASE_10_H
12
13#include <__algorithm/copy_n.h>
14#include <__charconv/tables.h>
15#include <__config>
16#include <cstdint>
17#include <limits>
18
19#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20# pragma GCC system_header
21#endif
22
23_LIBCPP_PUSH_MACROS
24#include <__undef_macros>
25
26_LIBCPP_BEGIN_NAMESPACE_STD
27
28#ifndef _LIBCPP_CXX03_LANG
29
30namespace __itoa {
31
32_LIBCPP_HIDE_FROM_ABI inline char* __append1(char* __first, uint32_t __value) noexcept {
33 *__first = '0' + static_cast<char>(__value);
34 return __first + 1;
35}
36
37_LIBCPP_HIDE_FROM_ABI inline char* __append2(char* __first, uint32_t __value) noexcept {
38 return std::copy_n(&__table<>::__digits_base_10[__value * 2], 2, __first);
39}
40
41_LIBCPP_HIDE_FROM_ABI inline char* __append3(char* __first, uint32_t __value) noexcept {
42 return __itoa::__append2(__itoa::__append1(__first, __value / 100), __value % 100);
43}
44
45_LIBCPP_HIDE_FROM_ABI inline char* __append4(char* __first, uint32_t __value) noexcept {
46 return __itoa::__append2(__itoa::__append2(__first, __value / 100), __value % 100);
47}
48
49_LIBCPP_HIDE_FROM_ABI inline char* __append5(char* __first, uint32_t __value) noexcept {
50 return __itoa::__append4(__itoa::__append1(__first, __value / 10000), __value % 10000);
51}
52
53_LIBCPP_HIDE_FROM_ABI inline char* __append6(char* __first, uint32_t __value) noexcept {
54 return __itoa::__append4(__itoa::__append2(__first, __value / 10000), __value % 10000);
55}
56
57_LIBCPP_HIDE_FROM_ABI inline char* __append7(char* __first, uint32_t __value) noexcept {
58 return __itoa::__append6(__itoa::__append1(__first, __value / 1000000), __value % 1000000);
59}
60
61_LIBCPP_HIDE_FROM_ABI inline char* __append8(char* __first, uint32_t __value) noexcept {
62 return __itoa::__append6(__itoa::__append2(__first, __value / 1000000), __value % 1000000);
63}
64
65_LIBCPP_HIDE_FROM_ABI inline char* __append9(char* __first, uint32_t __value) noexcept {
66 return __itoa::__append8(__itoa::__append1(__first, __value / 100000000), __value % 100000000);
67}
68
69template <class _Tp>
70_LIBCPP_HIDE_FROM_ABI char* __append10(char* __first, _Tp __value) noexcept {
71 return __itoa::__append8(__itoa::__append2(__first, static_cast<uint32_t>(__value / 100000000)),
72 static_cast<uint32_t>(__value % 100000000));
73}
74
75_LIBCPP_HIDE_FROM_ABI inline char* __base_10_u32(char* __first, uint32_t __value) noexcept {
76 if (__value < 1000000) {
77 if (__value < 10000) {
78 if (__value < 100) {
79 // 0 <= __value < 100
80 if (__value < 10)
81 return __itoa::__append1(__first, __value);
82 return __itoa::__append2(__first, __value);
83 }
84 // 100 <= __value < 10'000
85 if (__value < 1000)
86 return __itoa::__append3(__first, __value);
87 return __itoa::__append4(__first, __value);
88 }
89
90 // 10'000 <= __value < 1'000'000
91 if (__value < 100000)
92 return __itoa::__append5(__first, __value);
93 return __itoa::__append6(__first, __value);
94 }
95
96 // __value => 1'000'000
97 if (__value < 100000000) {
98 // 1'000'000 <= __value < 100'000'000
99 if (__value < 10000000)
100 return __itoa::__append7(__first, __value);
101 return __itoa::__append8(__first, __value);
102 }
103
104 // 100'000'000 <= __value < max
105 if (__value < 1000000000)
106 return __itoa::__append9(__first, __value);
107 return __itoa::__append10(__first, __value);
108}
109
110_LIBCPP_HIDE_FROM_ABI inline char* __base_10_u64(char* __buffer, uint64_t __value) noexcept {
111 if (__value <= UINT32_MAX)
112 return __itoa::__base_10_u32(__buffer, static_cast<uint32_t>(__value));
113
114 // Numbers in the range UINT32_MAX <= val < 10'000'000'000 always contain 10
115 // digits and are outputted after this if statement.
116 if (__value >= 10000000000) {
117 // This function properly deterimines the first non-zero leading digit.
118 __buffer = __itoa::__base_10_u32(__buffer, static_cast<uint32_t>(__value / 10000000000));
119 __value %= 10000000000;
120 }
121 return __itoa::__append10(__buffer, __value);
122}
123
124# ifndef _LIBCPP_HAS_NO_INT128
125/// \returns 10^\a exp
126///
127/// \pre \a exp [19, 39]
128///
129/// \note The lookup table contains a partial set of exponents limiting the
130/// range that can be used. However the range is sufficient for
131/// \ref __base_10_u128.
132_LIBCPP_HIDE_FROM_ABI inline __uint128_t __pow_10(int __exp) noexcept {
133 _LIBCPP_ASSERT(__exp >= __table<>::__pow10_128_offset, "Index out of bounds");
134 return __table<>::__pow10_128[__exp - __table<>::__pow10_128_offset];
135}
136
137_LIBCPP_HIDE_FROM_ABI inline char* __base_10_u128(char* __buffer, __uint128_t __value) noexcept {
138 _LIBCPP_ASSERT(
139 __value > numeric_limits<uint64_t>::max(), "The optimizations for this algorithm fail when this isn't true.");
140
141 // Unlike the 64 to 32 bit case the 128 bit case the "upper half" can't be
142 // stored in the "lower half". Instead we first need to handle the top most
143 // digits separately.
144 //
145 // Maximum unsigned values
146 // 64 bit 18'446'744'073'709'551'615 (20 digits)
147 // 128 bit 340'282'366'920'938'463'463'374'607'431'768'211'455 (39 digits)
148 // step 1 ^ ([0-1] digits)
149 // step 2 ^^^^^^^^^^^^^^^^^^^^^^^^^ ([0-19] digits)
150 // step 3 ^^^^^^^^^^^^^^^^^^^^^^^^^ (19 digits)
151 if (__value >= __itoa::__pow_10(38)) {
152 // step 1
153 __buffer = __itoa::__append1(__buffer, static_cast<uint32_t>(__value / __itoa::__pow_10(38)));
154 __value %= __itoa::__pow_10(38);
155
156 // step 2 always 19 digits.
157 // They are handled here since leading zeros need to be appended to the buffer,
158 __buffer = __itoa::__append9(__buffer, static_cast<uint32_t>(__value / __itoa::__pow_10(29)));
159 __value %= __itoa::__pow_10(29);
160 __buffer = __itoa::__append10(__buffer, static_cast<uint64_t>(__value / __itoa::__pow_10(19)));
161 __value %= __itoa::__pow_10(19);
162 }
163 else {
164 // step 2
165 // This version needs to determine the position of the leading non-zero digit.
166 __buffer = __base_10_u64(__buffer, static_cast<uint64_t>(__value / __itoa::__pow_10(19)));
167 __value %= __itoa::__pow_10(19);
168 }
169
170 // Step 3
171 __buffer = __itoa::__append9(__buffer, static_cast<uint32_t>(__value / 10000000000));
172 __buffer = __itoa::__append10(__buffer, static_cast<uint64_t>(__value % 10000000000));
173
174 return __buffer;
175}
176# endif
177} // namespace __itoa
178
179#endif // _LIBCPP_CXX03_LANG
180
181_LIBCPP_END_NAMESPACE_STD
182
183_LIBCPP_POP_MACROS
184
185#endif // _LIBCPP___CHARCONV_TO_CHARS_BASE_10_H
lib/libcxx/include/__charconv/to_chars_result.h+1-1
......@@ -14,7 +14,7 @@
1414#include <__errc>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
17# pragma GCC system_header
1818#endif
1919
2020_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__chrono/calendar.h+2-1234
......@@ -11,20 +11,13 @@
1111#define _LIBCPP___CHRONO_CALENDAR_H
1212
1313#include <__chrono/duration.h>
14#include <__chrono/system_clock.h>
1514#include <__chrono/time_point.h>
1615#include <__config>
17#include <limits>
18#include <ratio>
19#include <type_traits>
2016
2117#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22#pragma GCC system_header
18# pragma GCC system_header
2319#endif
2420
25_LIBCPP_PUSH_MACROS
26#include <__undef_macros>
27
2821#if _LIBCPP_STD_VER > 17
2922
3023_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -38,1239 +31,14 @@ using local_time = time_point<local_t, Duration>;
3831using local_seconds = local_time<seconds>;
3932using local_days = local_time<days>;
4033
41struct last_spec { explicit last_spec() = default; };
42
43class day {
44private:
45 unsigned char __d;
46public:
47 day() = default;
48 explicit inline constexpr day(unsigned __val) noexcept : __d(static_cast<unsigned char>(__val)) {}
49 inline constexpr day& operator++() noexcept { ++__d; return *this; }
50 inline constexpr day operator++(int) noexcept { day __tmp = *this; ++(*this); return __tmp; }
51 inline constexpr day& operator--() noexcept { --__d; return *this; }
52 inline constexpr day operator--(int) noexcept { day __tmp = *this; --(*this); return __tmp; }
53 constexpr day& operator+=(const days& __dd) noexcept;
54 constexpr day& operator-=(const days& __dd) noexcept;
55 explicit inline constexpr operator unsigned() const noexcept { return __d; }
56 inline constexpr bool ok() const noexcept { return __d >= 1 && __d <= 31; }
57 };
58
59
60inline constexpr
61bool operator==(const day& __lhs, const day& __rhs) noexcept
62{ return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); }
63
64inline constexpr
65bool operator!=(const day& __lhs, const day& __rhs) noexcept
66{ return !(__lhs == __rhs); }
67
68inline constexpr
69bool operator< (const day& __lhs, const day& __rhs) noexcept
70{ return static_cast<unsigned>(__lhs) < static_cast<unsigned>(__rhs); }
71
72inline constexpr
73bool operator> (const day& __lhs, const day& __rhs) noexcept
74{ return __rhs < __lhs; }
75
76inline constexpr
77bool operator<=(const day& __lhs, const day& __rhs) noexcept
78{ return !(__rhs < __lhs);}
79
80inline constexpr
81bool operator>=(const day& __lhs, const day& __rhs) noexcept
82{ return !(__lhs < __rhs); }
83
84inline constexpr
85day operator+ (const day& __lhs, const days& __rhs) noexcept
86{ return day(static_cast<unsigned>(__lhs) + __rhs.count()); }
87
88inline constexpr
89day operator+ (const days& __lhs, const day& __rhs) noexcept
90{ return __rhs + __lhs; }
91
92inline constexpr
93day operator- (const day& __lhs, const days& __rhs) noexcept
94{ return __lhs + -__rhs; }
95
96inline constexpr
97days operator-(const day& __lhs, const day& __rhs) noexcept
98{ return days(static_cast<int>(static_cast<unsigned>(__lhs)) -
99 static_cast<int>(static_cast<unsigned>(__rhs))); }
100
101inline constexpr day& day::operator+=(const days& __dd) noexcept
102{ *this = *this + __dd; return *this; }
103
104inline constexpr day& day::operator-=(const days& __dd) noexcept
105{ *this = *this - __dd; return *this; }
106
107
108class month {
109private:
110 unsigned char __m;
111public:
112 month() = default;
113 explicit inline constexpr month(unsigned __val) noexcept : __m(static_cast<unsigned char>(__val)) {}
114 inline constexpr month& operator++() noexcept { ++__m; return *this; }
115 inline constexpr month operator++(int) noexcept { month __tmp = *this; ++(*this); return __tmp; }
116 inline constexpr month& operator--() noexcept { --__m; return *this; }
117 inline constexpr month operator--(int) noexcept { month __tmp = *this; --(*this); return __tmp; }
118 constexpr month& operator+=(const months& __m1) noexcept;
119 constexpr month& operator-=(const months& __m1) noexcept;
120 explicit inline constexpr operator unsigned() const noexcept { return __m; }
121 inline constexpr bool ok() const noexcept { return __m >= 1 && __m <= 12; }
122};
123
124
125inline constexpr
126bool operator==(const month& __lhs, const month& __rhs) noexcept
127{ return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); }
128
129inline constexpr
130bool operator!=(const month& __lhs, const month& __rhs) noexcept
131{ return !(__lhs == __rhs); }
132
133inline constexpr
134bool operator< (const month& __lhs, const month& __rhs) noexcept
135{ return static_cast<unsigned>(__lhs) < static_cast<unsigned>(__rhs); }
136
137inline constexpr
138bool operator> (const month& __lhs, const month& __rhs) noexcept
139{ return __rhs < __lhs; }
140
141inline constexpr
142bool operator<=(const month& __lhs, const month& __rhs) noexcept
143{ return !(__rhs < __lhs); }
144
145inline constexpr
146bool operator>=(const month& __lhs, const month& __rhs) noexcept
147{ return !(__lhs < __rhs); }
148
149inline constexpr
150month operator+ (const month& __lhs, const months& __rhs) noexcept
151{
152 auto const __mu = static_cast<long long>(static_cast<unsigned>(__lhs)) + (__rhs.count() - 1);
153 auto const __yr = (__mu >= 0 ? __mu : __mu - 11) / 12;
154 return month{static_cast<unsigned>(__mu - __yr * 12 + 1)};
155}
156
157inline constexpr
158month operator+ (const months& __lhs, const month& __rhs) noexcept
159{ return __rhs + __lhs; }
160
161inline constexpr
162month operator- (const month& __lhs, const months& __rhs) noexcept
163{ return __lhs + -__rhs; }
164
165inline constexpr
166months operator-(const month& __lhs, const month& __rhs) noexcept
167{
168 auto const __dm = static_cast<unsigned>(__lhs) - static_cast<unsigned>(__rhs);
169 return months(__dm <= 11 ? __dm : __dm + 12);
170}
171
172inline constexpr month& month::operator+=(const months& __dm) noexcept
173{ *this = *this + __dm; return *this; }
174
175inline constexpr month& month::operator-=(const months& __dm) noexcept
176{ *this = *this - __dm; return *this; }
177
178
179class year {
180private:
181 short __y;
182public:
183 year() = default;
184 explicit inline constexpr year(int __val) noexcept : __y(static_cast<short>(__val)) {}
185
186 inline constexpr year& operator++() noexcept { ++__y; return *this; }
187 inline constexpr year operator++(int) noexcept { year __tmp = *this; ++(*this); return __tmp; }
188 inline constexpr year& operator--() noexcept { --__y; return *this; }
189 inline constexpr year operator--(int) noexcept { year __tmp = *this; --(*this); return __tmp; }
190 constexpr year& operator+=(const years& __dy) noexcept;
191 constexpr year& operator-=(const years& __dy) noexcept;
192 inline constexpr year operator+() const noexcept { return *this; }
193 inline constexpr year operator-() const noexcept { return year{-__y}; }
194
195 inline constexpr bool is_leap() const noexcept { return __y % 4 == 0 && (__y % 100 != 0 || __y % 400 == 0); }
196 explicit inline constexpr operator int() const noexcept { return __y; }
197 constexpr bool ok() const noexcept;
198 static inline constexpr year min() noexcept { return year{-32767}; }
199 static inline constexpr year max() noexcept { return year{ 32767}; }
200};
201
202
203inline constexpr
204bool operator==(const year& __lhs, const year& __rhs) noexcept
205{ return static_cast<int>(__lhs) == static_cast<int>(__rhs); }
206
207inline constexpr
208bool operator!=(const year& __lhs, const year& __rhs) noexcept
209{ return !(__lhs == __rhs); }
210
211inline constexpr
212bool operator< (const year& __lhs, const year& __rhs) noexcept
213{ return static_cast<int>(__lhs) < static_cast<int>(__rhs); }
214
215inline constexpr
216bool operator> (const year& __lhs, const year& __rhs) noexcept
217{ return __rhs < __lhs; }
218
219inline constexpr
220bool operator<=(const year& __lhs, const year& __rhs) noexcept
221{ return !(__rhs < __lhs); }
222
223inline constexpr
224bool operator>=(const year& __lhs, const year& __rhs) noexcept
225{ return !(__lhs < __rhs); }
226
227inline constexpr
228year operator+ (const year& __lhs, const years& __rhs) noexcept
229{ return year(static_cast<int>(__lhs) + __rhs.count()); }
230
231inline constexpr
232year operator+ (const years& __lhs, const year& __rhs) noexcept
233{ return __rhs + __lhs; }
234
235inline constexpr
236year operator- (const year& __lhs, const years& __rhs) noexcept
237{ return __lhs + -__rhs; }
238
239inline constexpr
240years operator-(const year& __lhs, const year& __rhs) noexcept
241{ return years{static_cast<int>(__lhs) - static_cast<int>(__rhs)}; }
242
243
244inline constexpr year& year::operator+=(const years& __dy) noexcept
245{ *this = *this + __dy; return *this; }
246
247inline constexpr year& year::operator-=(const years& __dy) noexcept
248{ *this = *this - __dy; return *this; }
249
250inline constexpr bool year::ok() const noexcept
251{ return static_cast<int>(min()) <= __y && __y <= static_cast<int>(max()); }
252
253class weekday_indexed;
254class weekday_last;
255
256class weekday {
257private:
258 unsigned char __wd;
259 static constexpr unsigned char __weekday_from_days(int __days) noexcept;
260public:
261 weekday() = default;
262 inline explicit constexpr weekday(unsigned __val) noexcept : __wd(static_cast<unsigned char>(__val == 7 ? 0 : __val)) {}
263 inline constexpr weekday(const sys_days& __sysd) noexcept
264 : __wd(__weekday_from_days(__sysd.time_since_epoch().count())) {}
265 inline explicit constexpr weekday(const local_days& __locd) noexcept
266 : __wd(__weekday_from_days(__locd.time_since_epoch().count())) {}
267
268 inline constexpr weekday& operator++() noexcept { __wd = (__wd == 6 ? 0 : __wd + 1); return *this; }
269 inline constexpr weekday operator++(int) noexcept { weekday __tmp = *this; ++(*this); return __tmp; }
270 inline constexpr weekday& operator--() noexcept { __wd = (__wd == 0 ? 6 : __wd - 1); return *this; }
271 inline constexpr weekday operator--(int) noexcept { weekday __tmp = *this; --(*this); return __tmp; }
272 constexpr weekday& operator+=(const days& __dd) noexcept;
273 constexpr weekday& operator-=(const days& __dd) noexcept;
274 inline constexpr unsigned c_encoding() const noexcept { return __wd; }
275 inline constexpr unsigned iso_encoding() const noexcept { return __wd == 0u ? 7 : __wd; }
276 inline constexpr bool ok() const noexcept { return __wd <= 6; }
277 constexpr weekday_indexed operator[](unsigned __index) const noexcept;
278 constexpr weekday_last operator[](last_spec) const noexcept;
279};
280
281
282// https://howardhinnant.github.io/date_algorithms.html#weekday_from_days
283inline constexpr
284unsigned char weekday::__weekday_from_days(int __days) noexcept
285{
286 return static_cast<unsigned char>(
287 static_cast<unsigned>(__days >= -4 ? (__days+4) % 7 : (__days+5) % 7 + 6)
288 );
289}
290
291inline constexpr
292bool operator==(const weekday& __lhs, const weekday& __rhs) noexcept
293{ return __lhs.c_encoding() == __rhs.c_encoding(); }
294
295inline constexpr
296bool operator!=(const weekday& __lhs, const weekday& __rhs) noexcept
297{ return !(__lhs == __rhs); }
298
299inline constexpr
300bool operator< (const weekday& __lhs, const weekday& __rhs) noexcept
301{ return __lhs.c_encoding() < __rhs.c_encoding(); }
302
303inline constexpr
304bool operator> (const weekday& __lhs, const weekday& __rhs) noexcept
305{ return __rhs < __lhs; }
306
307inline constexpr
308bool operator<=(const weekday& __lhs, const weekday& __rhs) noexcept
309{ return !(__rhs < __lhs);}
310
311inline constexpr
312bool operator>=(const weekday& __lhs, const weekday& __rhs) noexcept
313{ return !(__lhs < __rhs); }
314
315constexpr weekday operator+(const weekday& __lhs, const days& __rhs) noexcept
316{
317 auto const __mu = static_cast<long long>(__lhs.c_encoding()) + __rhs.count();
318 auto const __yr = (__mu >= 0 ? __mu : __mu - 6) / 7;
319 return weekday{static_cast<unsigned>(__mu - __yr * 7)};
320}
321
322constexpr weekday operator+(const days& __lhs, const weekday& __rhs) noexcept
323{ return __rhs + __lhs; }
324
325constexpr weekday operator-(const weekday& __lhs, const days& __rhs) noexcept
326{ return __lhs + -__rhs; }
327
328constexpr days operator-(const weekday& __lhs, const weekday& __rhs) noexcept
329{
330 const int __wdu = __lhs.c_encoding() - __rhs.c_encoding();
331 const int __wk = (__wdu >= 0 ? __wdu : __wdu-6) / 7;
332 return days{__wdu - __wk * 7};
333}
334
335inline constexpr weekday& weekday::operator+=(const days& __dd) noexcept
336{ *this = *this + __dd; return *this; }
337
338inline constexpr weekday& weekday::operator-=(const days& __dd) noexcept
339{ *this = *this - __dd; return *this; }
340
341
342class weekday_indexed {
343private:
344 chrono::weekday __wd;
345 unsigned char __idx;
346public:
347 weekday_indexed() = default;
348 inline constexpr weekday_indexed(const chrono::weekday& __wdval, unsigned __idxval) noexcept
349 : __wd{__wdval}, __idx(__idxval) {}
350 inline constexpr chrono::weekday weekday() const noexcept { return __wd; }
351 inline constexpr unsigned index() const noexcept { return __idx; }
352 inline constexpr bool ok() const noexcept { return __wd.ok() && __idx >= 1 && __idx <= 5; }
353};
354
355inline constexpr
356bool operator==(const weekday_indexed& __lhs, const weekday_indexed& __rhs) noexcept
357{ return __lhs.weekday() == __rhs.weekday() && __lhs.index() == __rhs.index(); }
358
359inline constexpr
360bool operator!=(const weekday_indexed& __lhs, const weekday_indexed& __rhs) noexcept
361{ return !(__lhs == __rhs); }
362
363
364class weekday_last {
365private:
366 chrono::weekday __wd;
367public:
368 explicit constexpr weekday_last(const chrono::weekday& __val) noexcept
369 : __wd{__val} {}
370 constexpr chrono::weekday weekday() const noexcept { return __wd; }
371 constexpr bool ok() const noexcept { return __wd.ok(); }
372};
373
374inline constexpr
375bool operator==(const weekday_last& __lhs, const weekday_last& __rhs) noexcept
376{ return __lhs.weekday() == __rhs.weekday(); }
377
378inline constexpr
379bool operator!=(const weekday_last& __lhs, const weekday_last& __rhs) noexcept
380{ return !(__lhs == __rhs); }
381
382inline constexpr
383weekday_indexed weekday::operator[](unsigned __index) const noexcept { return weekday_indexed{*this, __index}; }
384
385inline constexpr
386weekday_last weekday::operator[](last_spec) const noexcept { return weekday_last{*this}; }
387
388
34struct last_spec { _LIBCPP_HIDE_FROM_ABI explicit last_spec() = default; };
38935inline constexpr last_spec last{};
390inline constexpr weekday Sunday{0};
391inline constexpr weekday Monday{1};
392inline constexpr weekday Tuesday{2};
393inline constexpr weekday Wednesday{3};
394inline constexpr weekday Thursday{4};
395inline constexpr weekday Friday{5};
396inline constexpr weekday Saturday{6};
397
398inline constexpr month January{1};
399inline constexpr month February{2};
400inline constexpr month March{3};
401inline constexpr month April{4};
402inline constexpr month May{5};
403inline constexpr month June{6};
404inline constexpr month July{7};
405inline constexpr month August{8};
406inline constexpr month September{9};
407inline constexpr month October{10};
408inline constexpr month November{11};
409inline constexpr month December{12};
410
411
412class month_day {
413private:
414 chrono::month __m;
415 chrono::day __d;
416public:
417 month_day() = default;
418 constexpr month_day(const chrono::month& __mval, const chrono::day& __dval) noexcept
419 : __m{__mval}, __d{__dval} {}
420 inline constexpr chrono::month month() const noexcept { return __m; }
421 inline constexpr chrono::day day() const noexcept { return __d; }
422 constexpr bool ok() const noexcept;
423};
424
425inline constexpr
426bool month_day::ok() const noexcept
427{
428 if (!__m.ok()) return false;
429 const unsigned __dval = static_cast<unsigned>(__d);
430 if (__dval < 1 || __dval > 31) return false;
431 if (__dval <= 29) return true;
432// Now we've got either 30 or 31
433 const unsigned __mval = static_cast<unsigned>(__m);
434 if (__mval == 2) return false;
435 if (__mval == 4 || __mval == 6 || __mval == 9 || __mval == 11)
436 return __dval == 30;
437 return true;
438}
439
440inline constexpr
441bool operator==(const month_day& __lhs, const month_day& __rhs) noexcept
442{ return __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); }
443
444inline constexpr
445bool operator!=(const month_day& __lhs, const month_day& __rhs) noexcept
446{ return !(__lhs == __rhs); }
447
448inline constexpr
449month_day operator/(const month& __lhs, const day& __rhs) noexcept
450{ return month_day{__lhs, __rhs}; }
451
452constexpr
453month_day operator/(const day& __lhs, const month& __rhs) noexcept
454{ return __rhs / __lhs; }
455
456inline constexpr
457month_day operator/(const month& __lhs, int __rhs) noexcept
458{ return __lhs / day(__rhs); }
459
460constexpr
461month_day operator/(int __lhs, const day& __rhs) noexcept
462{ return month(__lhs) / __rhs; }
463
464constexpr
465month_day operator/(const day& __lhs, int __rhs) noexcept
466{ return month(__rhs) / __lhs; }
467
468
469inline constexpr
470bool operator< (const month_day& __lhs, const month_day& __rhs) noexcept
471{ return __lhs.month() != __rhs.month() ? __lhs.month() < __rhs.month() : __lhs.day() < __rhs.day(); }
472
473inline constexpr
474bool operator> (const month_day& __lhs, const month_day& __rhs) noexcept
475{ return __rhs < __lhs; }
476
477inline constexpr
478bool operator<=(const month_day& __lhs, const month_day& __rhs) noexcept
479{ return !(__rhs < __lhs);}
480
481inline constexpr
482bool operator>=(const month_day& __lhs, const month_day& __rhs) noexcept
483{ return !(__lhs < __rhs); }
484
485
486
487class month_day_last {
488private:
489 chrono::month __m;
490public:
491 explicit constexpr month_day_last(const chrono::month& __val) noexcept
492 : __m{__val} {}
493 inline constexpr chrono::month month() const noexcept { return __m; }
494 inline constexpr bool ok() const noexcept { return __m.ok(); }
495};
496
497inline constexpr
498bool operator==(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
499{ return __lhs.month() == __rhs.month(); }
500
501inline constexpr
502bool operator!=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
503{ return !(__lhs == __rhs); }
50436
505inline constexpr
506bool operator< (const month_day_last& __lhs, const month_day_last& __rhs) noexcept
507{ return __lhs.month() < __rhs.month(); }
50837
509inline constexpr
510bool operator> (const month_day_last& __lhs, const month_day_last& __rhs) noexcept
511{ return __rhs < __lhs; }
512
513inline constexpr
514bool operator<=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
515{ return !(__rhs < __lhs);}
516
517inline constexpr
518bool operator>=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
519{ return !(__lhs < __rhs); }
520
521inline constexpr
522month_day_last operator/(const month& __lhs, last_spec) noexcept
523{ return month_day_last{__lhs}; }
524
525inline constexpr
526month_day_last operator/(last_spec, const month& __rhs) noexcept
527{ return month_day_last{__rhs}; }
528
529inline constexpr
530month_day_last operator/(int __lhs, last_spec) noexcept
531{ return month_day_last{month(__lhs)}; }
532
533inline constexpr
534month_day_last operator/(last_spec, int __rhs) noexcept
535{ return month_day_last{month(__rhs)}; }
536
537
538class month_weekday {
539private:
540 chrono::month __m;
541 chrono::weekday_indexed __wdi;
542public:
543 constexpr month_weekday(const chrono::month& __mval, const chrono::weekday_indexed& __wdival) noexcept
544 : __m{__mval}, __wdi{__wdival} {}
545 inline constexpr chrono::month month() const noexcept { return __m; }
546 inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { return __wdi; }
547 inline constexpr bool ok() const noexcept { return __m.ok() && __wdi.ok(); }
548};
549
550inline constexpr
551bool operator==(const month_weekday& __lhs, const month_weekday& __rhs) noexcept
552{ return __lhs.month() == __rhs.month() && __lhs.weekday_indexed() == __rhs.weekday_indexed(); }
553
554inline constexpr
555bool operator!=(const month_weekday& __lhs, const month_weekday& __rhs) noexcept
556{ return !(__lhs == __rhs); }
557
558inline constexpr
559month_weekday operator/(const month& __lhs, const weekday_indexed& __rhs) noexcept
560{ return month_weekday{__lhs, __rhs}; }
561
562inline constexpr
563month_weekday operator/(int __lhs, const weekday_indexed& __rhs) noexcept
564{ return month_weekday{month(__lhs), __rhs}; }
565
566inline constexpr
567month_weekday operator/(const weekday_indexed& __lhs, const month& __rhs) noexcept
568{ return month_weekday{__rhs, __lhs}; }
569
570inline constexpr
571month_weekday operator/(const weekday_indexed& __lhs, int __rhs) noexcept
572{ return month_weekday{month(__rhs), __lhs}; }
573
574
575class month_weekday_last {
576 chrono::month __m;
577 chrono::weekday_last __wdl;
578 public:
579 constexpr month_weekday_last(const chrono::month& __mval, const chrono::weekday_last& __wdlval) noexcept
580 : __m{__mval}, __wdl{__wdlval} {}
581 inline constexpr chrono::month month() const noexcept { return __m; }
582 inline constexpr chrono::weekday_last weekday_last() const noexcept { return __wdl; }
583 inline constexpr bool ok() const noexcept { return __m.ok() && __wdl.ok(); }
584};
585
586inline constexpr
587bool operator==(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noexcept
588{ return __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last(); }
589
590inline constexpr
591bool operator!=(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noexcept
592{ return !(__lhs == __rhs); }
593
594
595inline constexpr
596month_weekday_last operator/(const month& __lhs, const weekday_last& __rhs) noexcept
597{ return month_weekday_last{__lhs, __rhs}; }
598
599inline constexpr
600month_weekday_last operator/(int __lhs, const weekday_last& __rhs) noexcept
601{ return month_weekday_last{month(__lhs), __rhs}; }
602
603inline constexpr
604month_weekday_last operator/(const weekday_last& __lhs, const month& __rhs) noexcept
605{ return month_weekday_last{__rhs, __lhs}; }
606
607inline constexpr
608month_weekday_last operator/(const weekday_last& __lhs, int __rhs) noexcept
609{ return month_weekday_last{month(__rhs), __lhs}; }
610
611
612class year_month {
613 chrono::year __y;
614 chrono::month __m;
615public:
616 year_month() = default;
617 constexpr year_month(const chrono::year& __yval, const chrono::month& __mval) noexcept
618 : __y{__yval}, __m{__mval} {}
619 inline constexpr chrono::year year() const noexcept { return __y; }
620 inline constexpr chrono::month month() const noexcept { return __m; }
621 inline constexpr year_month& operator+=(const months& __dm) noexcept { this->__m += __dm; return *this; }
622 inline constexpr year_month& operator-=(const months& __dm) noexcept { this->__m -= __dm; return *this; }
623 inline constexpr year_month& operator+=(const years& __dy) noexcept { this->__y += __dy; return *this; }
624 inline constexpr year_month& operator-=(const years& __dy) noexcept { this->__y -= __dy; return *this; }
625 inline constexpr bool ok() const noexcept { return __y.ok() && __m.ok(); }
626};
627
628inline constexpr
629year_month operator/(const year& __y, const month& __m) noexcept { return year_month{__y, __m}; }
630
631inline constexpr
632year_month operator/(const year& __y, int __m) noexcept { return year_month{__y, month(__m)}; }
633
634inline constexpr
635bool operator==(const year_month& __lhs, const year_month& __rhs) noexcept
636{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month(); }
637
638inline constexpr
639bool operator!=(const year_month& __lhs, const year_month& __rhs) noexcept
640{ return !(__lhs == __rhs); }
641
642inline constexpr
643bool operator< (const year_month& __lhs, const year_month& __rhs) noexcept
644{ return __lhs.year() != __rhs.year() ? __lhs.year() < __rhs.year() : __lhs.month() < __rhs.month(); }
645
646inline constexpr
647bool operator> (const year_month& __lhs, const year_month& __rhs) noexcept
648{ return __rhs < __lhs; }
649
650inline constexpr
651bool operator<=(const year_month& __lhs, const year_month& __rhs) noexcept
652{ return !(__rhs < __lhs);}
653
654inline constexpr
655bool operator>=(const year_month& __lhs, const year_month& __rhs) noexcept
656{ return !(__lhs < __rhs); }
657
658constexpr year_month operator+(const year_month& __lhs, const months& __rhs) noexcept
659{
660 int __dmi = static_cast<int>(static_cast<unsigned>(__lhs.month())) - 1 + __rhs.count();
661 const int __dy = (__dmi >= 0 ? __dmi : __dmi-11) / 12;
662 __dmi = __dmi - __dy * 12 + 1;
663 return (__lhs.year() + years(__dy)) / month(static_cast<unsigned>(__dmi));
664}
665
666constexpr year_month operator+(const months& __lhs, const year_month& __rhs) noexcept
667{ return __rhs + __lhs; }
668
669constexpr year_month operator+(const year_month& __lhs, const years& __rhs) noexcept
670{ return (__lhs.year() + __rhs) / __lhs.month(); }
671
672constexpr year_month operator+(const years& __lhs, const year_month& __rhs) noexcept
673{ return __rhs + __lhs; }
674
675constexpr months operator-(const year_month& __lhs, const year_month& __rhs) noexcept
676{ return (__lhs.year() - __rhs.year()) + months(static_cast<unsigned>(__lhs.month()) - static_cast<unsigned>(__rhs.month())); }
677
678constexpr year_month operator-(const year_month& __lhs, const months& __rhs) noexcept
679{ return __lhs + -__rhs; }
680
681constexpr year_month operator-(const year_month& __lhs, const years& __rhs) noexcept
682{ return __lhs + -__rhs; }
683
684class year_month_day_last;
685
686class year_month_day {
687private:
688 chrono::year __y;
689 chrono::month __m;
690 chrono::day __d;
691public:
692 year_month_day() = default;
693 inline constexpr year_month_day(
694 const chrono::year& __yval, const chrono::month& __mval, const chrono::day& __dval) noexcept
695 : __y{__yval}, __m{__mval}, __d{__dval} {}
696 constexpr year_month_day(const year_month_day_last& __ymdl) noexcept;
697 inline constexpr year_month_day(const sys_days& __sysd) noexcept
698 : year_month_day(__from_days(__sysd.time_since_epoch())) {}
699 inline explicit constexpr year_month_day(const local_days& __locd) noexcept
700 : year_month_day(__from_days(__locd.time_since_epoch())) {}
701
702 constexpr year_month_day& operator+=(const months& __dm) noexcept;
703 constexpr year_month_day& operator-=(const months& __dm) noexcept;
704 constexpr year_month_day& operator+=(const years& __dy) noexcept;
705 constexpr year_month_day& operator-=(const years& __dy) noexcept;
706
707 inline constexpr chrono::year year() const noexcept { return __y; }
708 inline constexpr chrono::month month() const noexcept { return __m; }
709 inline constexpr chrono::day day() const noexcept { return __d; }
710 inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; }
711 inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; }
712
713 constexpr bool ok() const noexcept;
714
715 static constexpr year_month_day __from_days(days __d) noexcept;
716 constexpr days __to_days() const noexcept;
717};
718
719
720// https://howardhinnant.github.io/date_algorithms.html#civil_from_days
721inline constexpr
722year_month_day
723year_month_day::__from_days(days __d) noexcept
724{
725 static_assert(numeric_limits<unsigned>::digits >= 18, "");
726 static_assert(numeric_limits<int>::digits >= 20 , "");
727 const int __z = __d.count() + 719468;
728 const int __era = (__z >= 0 ? __z : __z - 146096) / 146097;
729 const unsigned __doe = static_cast<unsigned>(__z - __era * 146097); // [0, 146096]
730 const unsigned __yoe = (__doe - __doe/1460 + __doe/36524 - __doe/146096) / 365; // [0, 399]
731 const int __yr = static_cast<int>(__yoe) + __era * 400;
732 const unsigned __doy = __doe - (365 * __yoe + __yoe/4 - __yoe/100); // [0, 365]
733 const unsigned __mp = (5 * __doy + 2)/153; // [0, 11]
734 const unsigned __dy = __doy - (153 * __mp + 2)/5 + 1; // [1, 31]
735 const unsigned __mth = __mp + (__mp < 10 ? 3 : -9); // [1, 12]
736 return year_month_day{chrono::year{__yr + (__mth <= 2)}, chrono::month{__mth}, chrono::day{__dy}};
737}
738
739// https://howardhinnant.github.io/date_algorithms.html#days_from_civil
740inline constexpr days year_month_day::__to_days() const noexcept
741{
742 static_assert(numeric_limits<unsigned>::digits >= 18, "");
743 static_assert(numeric_limits<int>::digits >= 20 , "");
744
745 const int __yr = static_cast<int>(__y) - (__m <= February);
746 const unsigned __mth = static_cast<unsigned>(__m);
747 const unsigned __dy = static_cast<unsigned>(__d);
748
749 const int __era = (__yr >= 0 ? __yr : __yr - 399) / 400;
750 const unsigned __yoe = static_cast<unsigned>(__yr - __era * 400); // [0, 399]
751 const unsigned __doy = (153 * (__mth + (__mth > 2 ? -3 : 9)) + 2) / 5 + __dy-1; // [0, 365]
752 const unsigned __doe = __yoe * 365 + __yoe/4 - __yoe/100 + __doy; // [0, 146096]
753 return days{__era * 146097 + static_cast<int>(__doe) - 719468};
754}
755
756inline constexpr
757bool operator==(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
758{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); }
759
760inline constexpr
761bool operator!=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
762{ return !(__lhs == __rhs); }
763
764inline constexpr
765bool operator< (const year_month_day& __lhs, const year_month_day& __rhs) noexcept
766{
767 if (__lhs.year() < __rhs.year()) return true;
768 if (__lhs.year() > __rhs.year()) return false;
769 if (__lhs.month() < __rhs.month()) return true;
770 if (__lhs.month() > __rhs.month()) return false;
771 return __lhs.day() < __rhs.day();
772}
773
774inline constexpr
775bool operator> (const year_month_day& __lhs, const year_month_day& __rhs) noexcept
776{ return __rhs < __lhs; }
777
778inline constexpr
779bool operator<=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
780{ return !(__rhs < __lhs);}
781
782inline constexpr
783bool operator>=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
784{ return !(__lhs < __rhs); }
785
786inline constexpr
787year_month_day operator/(const year_month& __lhs, const day& __rhs) noexcept
788{ return year_month_day{__lhs.year(), __lhs.month(), __rhs}; }
789
790inline constexpr
791year_month_day operator/(const year_month& __lhs, int __rhs) noexcept
792{ return __lhs / day(__rhs); }
793
794inline constexpr
795year_month_day operator/(const year& __lhs, const month_day& __rhs) noexcept
796{ return __lhs / __rhs.month() / __rhs.day(); }
797
798inline constexpr
799year_month_day operator/(int __lhs, const month_day& __rhs) noexcept
800{ return year(__lhs) / __rhs; }
801
802inline constexpr
803year_month_day operator/(const month_day& __lhs, const year& __rhs) noexcept
804{ return __rhs / __lhs; }
805
806inline constexpr
807year_month_day operator/(const month_day& __lhs, int __rhs) noexcept
808{ return year(__rhs) / __lhs; }
809
810
811inline constexpr
812year_month_day operator+(const year_month_day& __lhs, const months& __rhs) noexcept
813{ return (__lhs.year()/__lhs.month() + __rhs)/__lhs.day(); }
814
815inline constexpr
816year_month_day operator+(const months& __lhs, const year_month_day& __rhs) noexcept
817{ return __rhs + __lhs; }
818
819inline constexpr
820year_month_day operator-(const year_month_day& __lhs, const months& __rhs) noexcept
821{ return __lhs + -__rhs; }
822
823inline constexpr
824year_month_day operator+(const year_month_day& __lhs, const years& __rhs) noexcept
825{ return (__lhs.year() + __rhs) / __lhs.month() / __lhs.day(); }
826
827inline constexpr
828year_month_day operator+(const years& __lhs, const year_month_day& __rhs) noexcept
829{ return __rhs + __lhs; }
830
831inline constexpr
832year_month_day operator-(const year_month_day& __lhs, const years& __rhs) noexcept
833{ return __lhs + -__rhs; }
834
835inline constexpr year_month_day& year_month_day::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
836inline constexpr year_month_day& year_month_day::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
837inline constexpr year_month_day& year_month_day::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; }
838inline constexpr year_month_day& year_month_day::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; }
839
840class year_month_day_last {
841private:
842 chrono::year __y;
843 chrono::month_day_last __mdl;
844public:
845 constexpr year_month_day_last(const year& __yval, const month_day_last& __mdlval) noexcept
846 : __y{__yval}, __mdl{__mdlval} {}
847
848 constexpr year_month_day_last& operator+=(const months& __m) noexcept;
849 constexpr year_month_day_last& operator-=(const months& __m) noexcept;
850 constexpr year_month_day_last& operator+=(const years& __y) noexcept;
851 constexpr year_month_day_last& operator-=(const years& __y) noexcept;
852
853 inline constexpr chrono::year year() const noexcept { return __y; }
854 inline constexpr chrono::month month() const noexcept { return __mdl.month(); }
855 inline constexpr chrono::month_day_last month_day_last() const noexcept { return __mdl; }
856 constexpr chrono::day day() const noexcept;
857 inline constexpr operator sys_days() const noexcept { return sys_days{year()/month()/day()}; }
858 inline explicit constexpr operator local_days() const noexcept { return local_days{year()/month()/day()}; }
859 inline constexpr bool ok() const noexcept { return __y.ok() && __mdl.ok(); }
860};
861
862inline constexpr
863chrono::day year_month_day_last::day() const noexcept
864{
865 constexpr chrono::day __d[] =
866 {
867 chrono::day(31), chrono::day(28), chrono::day(31),
868 chrono::day(30), chrono::day(31), chrono::day(30),
869 chrono::day(31), chrono::day(31), chrono::day(30),
870 chrono::day(31), chrono::day(30), chrono::day(31)
871 };
872 return (month() != February || !__y.is_leap()) && month().ok() ?
873 __d[static_cast<unsigned>(month()) - 1] : chrono::day{29};
874}
875
876inline constexpr
877bool operator==(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
878{ return __lhs.year() == __rhs.year() && __lhs.month_day_last() == __rhs.month_day_last(); }
879
880inline constexpr
881bool operator!=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
882{ return !(__lhs == __rhs); }
883
884inline constexpr
885bool operator< (const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
886{
887 if (__lhs.year() < __rhs.year()) return true;
888 if (__lhs.year() > __rhs.year()) return false;
889 return __lhs.month_day_last() < __rhs.month_day_last();
890}
891
892inline constexpr
893bool operator> (const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
894{ return __rhs < __lhs; }
895
896inline constexpr
897bool operator<=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
898{ return !(__rhs < __lhs);}
899
900inline constexpr
901bool operator>=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
902{ return !(__lhs < __rhs); }
903
904inline constexpr year_month_day_last operator/(const year_month& __lhs, last_spec) noexcept
905{ return year_month_day_last{__lhs.year(), month_day_last{__lhs.month()}}; }
906
907inline constexpr year_month_day_last operator/(const year& __lhs, const month_day_last& __rhs) noexcept
908{ return year_month_day_last{__lhs, __rhs}; }
909
910inline constexpr year_month_day_last operator/(int __lhs, const month_day_last& __rhs) noexcept
911{ return year_month_day_last{year{__lhs}, __rhs}; }
912
913inline constexpr year_month_day_last operator/(const month_day_last& __lhs, const year& __rhs) noexcept
914{ return __rhs / __lhs; }
915
916inline constexpr year_month_day_last operator/(const month_day_last& __lhs, int __rhs) noexcept
917{ return year{__rhs} / __lhs; }
918
919
920inline constexpr
921year_month_day_last operator+(const year_month_day_last& __lhs, const months& __rhs) noexcept
922{ return (__lhs.year() / __lhs.month() + __rhs) / last; }
923
924inline constexpr
925year_month_day_last operator+(const months& __lhs, const year_month_day_last& __rhs) noexcept
926{ return __rhs + __lhs; }
927
928inline constexpr
929year_month_day_last operator-(const year_month_day_last& __lhs, const months& __rhs) noexcept
930{ return __lhs + (-__rhs); }
931
932inline constexpr
933year_month_day_last operator+(const year_month_day_last& __lhs, const years& __rhs) noexcept
934{ return year_month_day_last{__lhs.year() + __rhs, __lhs.month_day_last()}; }
935
936inline constexpr
937year_month_day_last operator+(const years& __lhs, const year_month_day_last& __rhs) noexcept
938{ return __rhs + __lhs; }
939
940inline constexpr
941year_month_day_last operator-(const year_month_day_last& __lhs, const years& __rhs) noexcept
942{ return __lhs + (-__rhs); }
943
944inline constexpr year_month_day_last& year_month_day_last::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
945inline constexpr year_month_day_last& year_month_day_last::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
946inline constexpr year_month_day_last& year_month_day_last::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; }
947inline constexpr year_month_day_last& year_month_day_last::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; }
948
949inline constexpr year_month_day::year_month_day(const year_month_day_last& __ymdl) noexcept
950 : __y{__ymdl.year()}, __m{__ymdl.month()}, __d{__ymdl.day()} {}
951
952inline constexpr bool year_month_day::ok() const noexcept
953{
954 if (!__y.ok() || !__m.ok()) return false;
955 return chrono::day{1} <= __d && __d <= (__y / __m / last).day();
956}
957
958class year_month_weekday {
959 chrono::year __y;
960 chrono::month __m;
961 chrono::weekday_indexed __wdi;
962public:
963 year_month_weekday() = default;
964 constexpr year_month_weekday(const chrono::year& __yval, const chrono::month& __mval,
965 const chrono::weekday_indexed& __wdival) noexcept
966 : __y{__yval}, __m{__mval}, __wdi{__wdival} {}
967 constexpr year_month_weekday(const sys_days& __sysd) noexcept
968 : year_month_weekday(__from_days(__sysd.time_since_epoch())) {}
969 inline explicit constexpr year_month_weekday(const local_days& __locd) noexcept
970 : year_month_weekday(__from_days(__locd.time_since_epoch())) {}
971 constexpr year_month_weekday& operator+=(const months& m) noexcept;
972 constexpr year_month_weekday& operator-=(const months& m) noexcept;
973 constexpr year_month_weekday& operator+=(const years& y) noexcept;
974 constexpr year_month_weekday& operator-=(const years& y) noexcept;
975
976 inline constexpr chrono::year year() const noexcept { return __y; }
977 inline constexpr chrono::month month() const noexcept { return __m; }
978 inline constexpr chrono::weekday weekday() const noexcept { return __wdi.weekday(); }
979 inline constexpr unsigned index() const noexcept { return __wdi.index(); }
980 inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { return __wdi; }
981
982 inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; }
983 inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; }
984 inline constexpr bool ok() const noexcept
985 {
986 if (!__y.ok() || !__m.ok() || !__wdi.ok()) return false;
987 if (__wdi.index() <= 4) return true;
988 auto __nth_weekday_day =
989 __wdi.weekday() -
990 chrono::weekday{static_cast<sys_days>(__y / __m / 1)} +
991 days{(__wdi.index() - 1) * 7 + 1};
992 return static_cast<unsigned>(__nth_weekday_day.count()) <=
993 static_cast<unsigned>((__y / __m / last).day());
994 }
995
996 static constexpr year_month_weekday __from_days(days __d) noexcept;
997 constexpr days __to_days() const noexcept;
998};
999
1000inline constexpr
1001year_month_weekday year_month_weekday::__from_days(days __d) noexcept
1002{
1003 const sys_days __sysd{__d};
1004 const chrono::weekday __wd = chrono::weekday(__sysd);
1005 const year_month_day __ymd = year_month_day(__sysd);
1006 return year_month_weekday{__ymd.year(), __ymd.month(),
1007 __wd[(static_cast<unsigned>(__ymd.day())-1)/7+1]};
1008}
1009
1010inline constexpr
1011days year_month_weekday::__to_days() const noexcept
1012{
1013 const sys_days __sysd = sys_days(__y/__m/1);
1014 return (__sysd + (__wdi.weekday() - chrono::weekday(__sysd) + days{(__wdi.index()-1)*7}))
1015 .time_since_epoch();
1016}
1017
1018inline constexpr
1019bool operator==(const year_month_weekday& __lhs, const year_month_weekday& __rhs) noexcept
1020{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.weekday_indexed() == __rhs.weekday_indexed(); }
1021
1022inline constexpr
1023bool operator!=(const year_month_weekday& __lhs, const year_month_weekday& __rhs) noexcept
1024{ return !(__lhs == __rhs); }
1025
1026inline constexpr
1027year_month_weekday operator/(const year_month& __lhs, const weekday_indexed& __rhs) noexcept
1028{ return year_month_weekday{__lhs.year(), __lhs.month(), __rhs}; }
1029
1030inline constexpr
1031year_month_weekday operator/(const year& __lhs, const month_weekday& __rhs) noexcept
1032{ return year_month_weekday{__lhs, __rhs.month(), __rhs.weekday_indexed()}; }
1033
1034inline constexpr
1035year_month_weekday operator/(int __lhs, const month_weekday& __rhs) noexcept
1036{ return year(__lhs) / __rhs; }
1037
1038inline constexpr
1039year_month_weekday operator/(const month_weekday& __lhs, const year& __rhs) noexcept
1040{ return __rhs / __lhs; }
1041
1042inline constexpr
1043year_month_weekday operator/(const month_weekday& __lhs, int __rhs) noexcept
1044{ return year(__rhs) / __lhs; }
1045
1046
1047inline constexpr
1048year_month_weekday operator+(const year_month_weekday& __lhs, const months& __rhs) noexcept
1049{ return (__lhs.year() / __lhs.month() + __rhs) / __lhs.weekday_indexed(); }
1050
1051inline constexpr
1052year_month_weekday operator+(const months& __lhs, const year_month_weekday& __rhs) noexcept
1053{ return __rhs + __lhs; }
1054
1055inline constexpr
1056year_month_weekday operator-(const year_month_weekday& __lhs, const months& __rhs) noexcept
1057{ return __lhs + (-__rhs); }
1058
1059inline constexpr
1060year_month_weekday operator+(const year_month_weekday& __lhs, const years& __rhs) noexcept
1061{ return year_month_weekday{__lhs.year() + __rhs, __lhs.month(), __lhs.weekday_indexed()}; }
1062
1063inline constexpr
1064year_month_weekday operator+(const years& __lhs, const year_month_weekday& __rhs) noexcept
1065{ return __rhs + __lhs; }
1066
1067inline constexpr
1068year_month_weekday operator-(const year_month_weekday& __lhs, const years& __rhs) noexcept
1069{ return __lhs + (-__rhs); }
1070
1071
1072inline constexpr year_month_weekday& year_month_weekday::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
1073inline constexpr year_month_weekday& year_month_weekday::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
1074inline constexpr year_month_weekday& year_month_weekday::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; }
1075inline constexpr year_month_weekday& year_month_weekday::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; }
1076
1077class year_month_weekday_last {
1078private:
1079 chrono::year __y;
1080 chrono::month __m;
1081 chrono::weekday_last __wdl;
1082public:
1083 constexpr year_month_weekday_last(const chrono::year& __yval, const chrono::month& __mval,
1084 const chrono::weekday_last& __wdlval) noexcept
1085 : __y{__yval}, __m{__mval}, __wdl{__wdlval} {}
1086 constexpr year_month_weekday_last& operator+=(const months& __dm) noexcept;
1087 constexpr year_month_weekday_last& operator-=(const months& __dm) noexcept;
1088 constexpr year_month_weekday_last& operator+=(const years& __dy) noexcept;
1089 constexpr year_month_weekday_last& operator-=(const years& __dy) noexcept;
1090
1091 inline constexpr chrono::year year() const noexcept { return __y; }
1092 inline constexpr chrono::month month() const noexcept { return __m; }
1093 inline constexpr chrono::weekday weekday() const noexcept { return __wdl.weekday(); }
1094 inline constexpr chrono::weekday_last weekday_last() const noexcept { return __wdl; }
1095 inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; }
1096 inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; }
1097 inline constexpr bool ok() const noexcept { return __y.ok() && __m.ok() && __wdl.ok(); }
1098
1099 constexpr days __to_days() const noexcept;
1100
1101};
1102
1103inline constexpr
1104days year_month_weekday_last::__to_days() const noexcept
1105{
1106 const sys_days __last = sys_days{__y/__m/last};
1107 return (__last - (chrono::weekday{__last} - __wdl.weekday())).time_since_epoch();
1108
1109}
1110
1111inline constexpr
1112bool operator==(const year_month_weekday_last& __lhs, const year_month_weekday_last& __rhs) noexcept
1113{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last(); }
1114
1115inline constexpr
1116bool operator!=(const year_month_weekday_last& __lhs, const year_month_weekday_last& __rhs) noexcept
1117{ return !(__lhs == __rhs); }
1118
1119
1120inline constexpr
1121year_month_weekday_last operator/(const year_month& __lhs, const weekday_last& __rhs) noexcept
1122{ return year_month_weekday_last{__lhs.year(), __lhs.month(), __rhs}; }
1123
1124inline constexpr
1125year_month_weekday_last operator/(const year& __lhs, const month_weekday_last& __rhs) noexcept
1126{ return year_month_weekday_last{__lhs, __rhs.month(), __rhs.weekday_last()}; }
1127
1128inline constexpr
1129year_month_weekday_last operator/(int __lhs, const month_weekday_last& __rhs) noexcept
1130{ return year(__lhs) / __rhs; }
1131
1132inline constexpr
1133year_month_weekday_last operator/(const month_weekday_last& __lhs, const year& __rhs) noexcept
1134{ return __rhs / __lhs; }
1135
1136inline constexpr
1137year_month_weekday_last operator/(const month_weekday_last& __lhs, int __rhs) noexcept
1138{ return year(__rhs) / __lhs; }
1139
1140
1141inline constexpr
1142year_month_weekday_last operator+(const year_month_weekday_last& __lhs, const months& __rhs) noexcept
1143{ return (__lhs.year() / __lhs.month() + __rhs) / __lhs.weekday_last(); }
1144
1145inline constexpr
1146year_month_weekday_last operator+(const months& __lhs, const year_month_weekday_last& __rhs) noexcept
1147{ return __rhs + __lhs; }
1148
1149inline constexpr
1150year_month_weekday_last operator-(const year_month_weekday_last& __lhs, const months& __rhs) noexcept
1151{ return __lhs + (-__rhs); }
1152
1153inline constexpr
1154year_month_weekday_last operator+(const year_month_weekday_last& __lhs, const years& __rhs) noexcept
1155{ return year_month_weekday_last{__lhs.year() + __rhs, __lhs.month(), __lhs.weekday_last()}; }
1156
1157inline constexpr
1158year_month_weekday_last operator+(const years& __lhs, const year_month_weekday_last& __rhs) noexcept
1159{ return __rhs + __lhs; }
1160
1161inline constexpr
1162year_month_weekday_last operator-(const year_month_weekday_last& __lhs, const years& __rhs) noexcept
1163{ return __lhs + (-__rhs); }
1164
1165inline constexpr year_month_weekday_last& year_month_weekday_last::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
1166inline constexpr year_month_weekday_last& year_month_weekday_last::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
1167inline constexpr year_month_weekday_last& year_month_weekday_last::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; }
1168inline constexpr year_month_weekday_last& year_month_weekday_last::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; }
1169
1170
1171template <class _Duration>
1172class hh_mm_ss
1173{
1174private:
1175 static_assert(__is_duration<_Duration>::value, "template parameter of hh_mm_ss must be a std::chrono::duration");
1176 using __CommonType = common_type_t<_Duration, chrono::seconds>;
1177
1178 static constexpr uint64_t __pow10(unsigned __exp)
1179 {
1180 uint64_t __ret = 1;
1181 for (unsigned __i = 0; __i < __exp; ++__i)
1182 __ret *= 10U;
1183 return __ret;
1184 }
1185
1186 static constexpr unsigned __width(uint64_t __n, uint64_t __d = 10, unsigned __w = 0)
1187 {
1188 if (__n >= 2 && __d != 0 && __w < 19)
1189 return 1 + __width(__n, __d % __n * 10, __w+1);
1190 return 0;
1191 }
1192
1193public:
1194 static unsigned constexpr fractional_width = __width(__CommonType::period::den) < 19 ?
1195 __width(__CommonType::period::den) : 6u;
1196 using precision = duration<typename __CommonType::rep, ratio<1, __pow10(fractional_width)>>;
1197
1198 constexpr hh_mm_ss() noexcept : hh_mm_ss{_Duration::zero()} {}
1199
1200 constexpr explicit hh_mm_ss(_Duration __d) noexcept :
1201 __is_neg(__d < _Duration(0)),
1202 __h(duration_cast<chrono::hours> (abs(__d))),
1203 __m(duration_cast<chrono::minutes>(abs(__d) - hours())),
1204 __s(duration_cast<chrono::seconds>(abs(__d) - hours() - minutes())),
1205 __f(duration_cast<precision> (abs(__d) - hours() - minutes() - seconds()))
1206 {}
1207
1208 constexpr bool is_negative() const noexcept { return __is_neg; }
1209 constexpr chrono::hours hours() const noexcept { return __h; }
1210 constexpr chrono::minutes minutes() const noexcept { return __m; }
1211 constexpr chrono::seconds seconds() const noexcept { return __s; }
1212 constexpr precision subseconds() const noexcept { return __f; }
1213
1214 constexpr precision to_duration() const noexcept
1215 {
1216 auto __dur = __h + __m + __s + __f;
1217 return __is_neg ? -__dur : __dur;
1218 }
1219
1220 constexpr explicit operator precision() const noexcept { return to_duration(); }
1221
1222private:
1223 bool __is_neg;
1224 chrono::hours __h;
1225 chrono::minutes __m;
1226 chrono::seconds __s;
1227 precision __f;
1228};
1229
1230constexpr bool is_am(const hours& __h) noexcept { return __h >= hours( 0) && __h < hours(12); }
1231constexpr bool is_pm(const hours& __h) noexcept { return __h >= hours(12) && __h < hours(24); }
1232
1233constexpr hours make12(const hours& __h) noexcept
1234{
1235 if (__h == hours( 0)) return hours(12);
1236 else if (__h <= hours(12)) return __h;
1237 else return __h - hours(12);
1238}
1239
1240constexpr hours make24(const hours& __h, bool __is_pm) noexcept
1241{
1242 if (__is_pm)
1243 return __h == hours(12) ? __h : __h + hours(12);
1244 else
1245 return __h == hours(12) ? hours(0) : __h;
1246}
1247
1248} // namespace chrono
1249
1250inline namespace literals
1251{
1252 inline namespace chrono_literals
1253 {
1254 constexpr chrono::day operator ""d(unsigned long long __d) noexcept
1255 {
1256 return chrono::day(static_cast<unsigned>(__d));
1257 }
1258
1259 constexpr chrono::year operator ""y(unsigned long long __y) noexcept
1260 {
1261 return chrono::year(static_cast<int>(__y));
1262 }
1263} // namespace chrono_literals
1264} // namespace literals
1265
1266namespace chrono { // hoist the literals into namespace std::chrono
1267 using namespace literals::chrono_literals;
126838} // namespace chrono
126939
127040_LIBCPP_END_NAMESPACE_STD
127141
127242#endif // _LIBCPP_STD_VER > 17
127343
1274_LIBCPP_POP_MACROS
1275
127644#endif // _LIBCPP___CHRONO_CALENDAR_H
lib/libcxx/include/__chrono/convert_to_timespec.h+1-1
......@@ -14,7 +14,7 @@
1414#include <limits>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
17# pragma GCC system_header
1818#endif
1919
2020_LIBCPP_PUSH_MACROS
lib/libcxx/include/__chrono/day.h created+84
......@@ -0,0 +1,84 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___CHRONO_DAY_H
11#define _LIBCPP___CHRONO_DAY_H
12
13#include <__chrono/duration.h>
14#include <__config>
15#include <compare>
16
17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18# pragma GCC system_header
19#endif
20
21#if _LIBCPP_STD_VER > 17
22
23_LIBCPP_BEGIN_NAMESPACE_STD
24
25namespace chrono
26{
27
28class day {
29private:
30 unsigned char __d;
31public:
32 _LIBCPP_HIDE_FROM_ABI day() = default;
33 _LIBCPP_HIDE_FROM_ABI explicit inline constexpr day(unsigned __val) noexcept : __d(static_cast<unsigned char>(__val)) {}
34 _LIBCPP_HIDE_FROM_ABI inline constexpr day& operator++() noexcept { ++__d; return *this; }
35 _LIBCPP_HIDE_FROM_ABI inline constexpr day operator++(int) noexcept { day __tmp = *this; ++(*this); return __tmp; }
36 _LIBCPP_HIDE_FROM_ABI inline constexpr day& operator--() noexcept { --__d; return *this; }
37 _LIBCPP_HIDE_FROM_ABI inline constexpr day operator--(int) noexcept { day __tmp = *this; --(*this); return __tmp; }
38 _LIBCPP_HIDE_FROM_ABI constexpr day& operator+=(const days& __dd) noexcept;
39 _LIBCPP_HIDE_FROM_ABI constexpr day& operator-=(const days& __dd) noexcept;
40 _LIBCPP_HIDE_FROM_ABI explicit inline constexpr operator unsigned() const noexcept { return __d; }
41 _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __d >= 1 && __d <= 31; }
42 };
43
44
45_LIBCPP_HIDE_FROM_ABI inline constexpr
46bool operator==(const day& __lhs, const day& __rhs) noexcept
47{ return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); }
48
49_LIBCPP_HIDE_FROM_ABI constexpr strong_ordering operator<=>(const day& __lhs, const day& __rhs) noexcept {
50 return static_cast<unsigned>(__lhs) <=> static_cast<unsigned>(__rhs);
51}
52
53_LIBCPP_HIDE_FROM_ABI inline constexpr
54day operator+ (const day& __lhs, const days& __rhs) noexcept
55{ return day(static_cast<unsigned>(__lhs) + __rhs.count()); }
56
57_LIBCPP_HIDE_FROM_ABI inline constexpr
58day operator+ (const days& __lhs, const day& __rhs) noexcept
59{ return __rhs + __lhs; }
60
61_LIBCPP_HIDE_FROM_ABI inline constexpr
62day operator- (const day& __lhs, const days& __rhs) noexcept
63{ return __lhs + -__rhs; }
64
65_LIBCPP_HIDE_FROM_ABI inline constexpr
66days operator-(const day& __lhs, const day& __rhs) noexcept
67{ return days(static_cast<int>(static_cast<unsigned>(__lhs)) -
68 static_cast<int>(static_cast<unsigned>(__rhs))); }
69
70_LIBCPP_HIDE_FROM_ABI inline constexpr
71day& day::operator+=(const days& __dd) noexcept
72{ *this = *this + __dd; return *this; }
73
74_LIBCPP_HIDE_FROM_ABI inline constexpr
75day& day::operator-=(const days& __dd) noexcept
76{ *this = *this - __dd; return *this; }
77
78} // namespace chrono
79
80_LIBCPP_END_NAMESPACE_STD
81
82#endif // _LIBCPP_STD_VER > 17
83
84#endif // _LIBCPP___CHRONO_DAY_H
lib/libcxx/include/__chrono/duration.h+5-5
......@@ -16,7 +16,7 @@
1616#include <type_traits>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
19# pragma GCC system_header
2020#endif
2121
2222_LIBCPP_PUSH_MACROS
......@@ -286,10 +286,10 @@ public:
286286 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator+=(const duration& __d) {__rep_ += __d.count(); return *this;}
287287 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator-=(const duration& __d) {__rep_ -= __d.count(); return *this;}
288288
289 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator*=(const rep& rhs) {__rep_ *= rhs; return *this;}
290 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator/=(const rep& rhs) {__rep_ /= rhs; return *this;}
291 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator%=(const rep& rhs) {__rep_ %= rhs; return *this;}
292 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator%=(const duration& rhs) {__rep_ %= rhs.count(); return *this;}
289 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator*=(const rep& __rhs) {__rep_ *= __rhs; return *this;}
290 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator/=(const rep& __rhs) {__rep_ /= __rhs; return *this;}
291 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator%=(const rep& __rhs) {__rep_ %= __rhs; return *this;}
292 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator%=(const duration& __rhs) {__rep_ %= __rhs.count(); return *this;}
293293
294294 // special values
295295
lib/libcxx/include/__chrono/file_clock.h+1-1
......@@ -18,7 +18,7 @@
1818#include <ratio>
1919
2020#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21#pragma GCC system_header
21# pragma GCC system_header
2222#endif
2323
2424#ifndef _LIBCPP_CXX03_LANG
lib/libcxx/include/__chrono/hh_mm_ss.h created+112
......@@ -0,0 +1,112 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___CHRONO_HH_MM_SS_H
11#define _LIBCPP___CHRONO_HH_MM_SS_H
12
13#include <__chrono/duration.h>
14#include <__chrono/time_point.h>
15#include <__config>
16#include <ratio>
17#include <type_traits>
18
19#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20# pragma GCC system_header
21#endif
22
23#if _LIBCPP_STD_VER > 17
24
25_LIBCPP_BEGIN_NAMESPACE_STD
26
27namespace chrono
28{
29
30template <class _Duration>
31class hh_mm_ss
32{
33private:
34 static_assert(__is_duration<_Duration>::value, "template parameter of hh_mm_ss must be a std::chrono::duration");
35 using __CommonType = common_type_t<_Duration, chrono::seconds>;
36
37 _LIBCPP_HIDE_FROM_ABI static constexpr uint64_t __pow10(unsigned __exp)
38 {
39 uint64_t __ret = 1;
40 for (unsigned __i = 0; __i < __exp; ++__i)
41 __ret *= 10U;
42 return __ret;
43 }
44
45 _LIBCPP_HIDE_FROM_ABI static constexpr unsigned __width(uint64_t __n, uint64_t __d = 10, unsigned __w = 0)
46 {
47 if (__n >= 2 && __d != 0 && __w < 19)
48 return 1 + __width(__n, __d % __n * 10, __w+1);
49 return 0;
50 }
51
52public:
53 _LIBCPP_HIDE_FROM_ABI static unsigned constexpr fractional_width = __width(__CommonType::period::den) < 19 ?
54 __width(__CommonType::period::den) : 6u;
55 using precision = duration<typename __CommonType::rep, ratio<1, __pow10(fractional_width)>>;
56
57 _LIBCPP_HIDE_FROM_ABI constexpr hh_mm_ss() noexcept : hh_mm_ss{_Duration::zero()} {}
58
59 _LIBCPP_HIDE_FROM_ABI constexpr explicit hh_mm_ss(_Duration __d) noexcept :
60 __is_neg(__d < _Duration(0)),
61 __h(duration_cast<chrono::hours> (abs(__d))),
62 __m(duration_cast<chrono::minutes>(abs(__d) - hours())),
63 __s(duration_cast<chrono::seconds>(abs(__d) - hours() - minutes())),
64 __f(duration_cast<precision> (abs(__d) - hours() - minutes() - seconds()))
65 {}
66
67 _LIBCPP_HIDE_FROM_ABI constexpr bool is_negative() const noexcept { return __is_neg; }
68 _LIBCPP_HIDE_FROM_ABI constexpr chrono::hours hours() const noexcept { return __h; }
69 _LIBCPP_HIDE_FROM_ABI constexpr chrono::minutes minutes() const noexcept { return __m; }
70 _LIBCPP_HIDE_FROM_ABI constexpr chrono::seconds seconds() const noexcept { return __s; }
71 _LIBCPP_HIDE_FROM_ABI constexpr precision subseconds() const noexcept { return __f; }
72
73 _LIBCPP_HIDE_FROM_ABI constexpr precision to_duration() const noexcept
74 {
75 auto __dur = __h + __m + __s + __f;
76 return __is_neg ? -__dur : __dur;
77 }
78
79 _LIBCPP_HIDE_FROM_ABI constexpr explicit operator precision() const noexcept { return to_duration(); }
80
81private:
82 bool __is_neg;
83 chrono::hours __h;
84 chrono::minutes __m;
85 chrono::seconds __s;
86 precision __f;
87};
88
89_LIBCPP_HIDE_FROM_ABI constexpr bool is_am(const hours& __h) noexcept { return __h >= hours( 0) && __h < hours(12); }
90_LIBCPP_HIDE_FROM_ABI constexpr bool is_pm(const hours& __h) noexcept { return __h >= hours(12) && __h < hours(24); }
91
92_LIBCPP_HIDE_FROM_ABI constexpr hours make12(const hours& __h) noexcept
93{
94 if (__h == hours( 0)) return hours(12);
95 else if (__h <= hours(12)) return __h;
96 else return __h - hours(12);
97}
98
99_LIBCPP_HIDE_FROM_ABI constexpr hours make24(const hours& __h, bool __is_pm) noexcept
100{
101 if (__is_pm)
102 return __h == hours(12) ? __h : __h + hours(12);
103 else
104 return __h == hours(12) ? hours(0) : __h;
105}
106} // namespace chrono
107
108_LIBCPP_END_NAMESPACE_STD
109
110#endif // _LIBCPP_STD_VER > 17
111
112#endif // _LIBCPP___CHRONO_HH_MM_SS_H
lib/libcxx/include/__chrono/high_resolution_clock.h+1-1
......@@ -15,7 +15,7 @@
1515#include <__config>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__chrono/literals.h created+49
......@@ -0,0 +1,49 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___CHRONO_LITERALS_H
11#define _LIBCPP___CHRONO_LITERALS_H
12
13#include <__chrono/day.h>
14#include <__chrono/year.h>
15#include <__config>
16
17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18# pragma GCC system_header
19#endif
20
21#if _LIBCPP_STD_VER > 17
22
23_LIBCPP_BEGIN_NAMESPACE_STD
24
25inline namespace literals
26{
27 inline namespace chrono_literals
28 {
29 _LIBCPP_HIDE_FROM_ABI constexpr chrono::day operator ""d(unsigned long long __d) noexcept
30 {
31 return chrono::day(static_cast<unsigned>(__d));
32 }
33
34 _LIBCPP_HIDE_FROM_ABI constexpr chrono::year operator ""y(unsigned long long __y) noexcept
35 {
36 return chrono::year(static_cast<int>(__y));
37 }
38} // namespace chrono_literals
39} // namespace literals
40
41namespace chrono { // hoist the literals into namespace std::chrono
42 using namespace literals::chrono_literals;
43} // namespace chrono
44
45_LIBCPP_END_NAMESPACE_STD
46
47#endif // _LIBCPP_STD_VER > 17
48
49#endif // _LIBCPP___CHRONO_LITERALS_H
lib/libcxx/include/__chrono/month.h created+118
......@@ -0,0 +1,118 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___CHRONO_MONTH_H
11#define _LIBCPP___CHRONO_MONTH_H
12
13#include <__chrono/duration.h>
14#include <__config>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
20#if _LIBCPP_STD_VER > 17
21
22_LIBCPP_BEGIN_NAMESPACE_STD
23
24namespace chrono
25{
26
27class month {
28private:
29 unsigned char __m;
30public:
31 _LIBCPP_HIDE_FROM_ABI month() = default;
32 _LIBCPP_HIDE_FROM_ABI explicit inline constexpr month(unsigned __val) noexcept : __m(static_cast<unsigned char>(__val)) {}
33 _LIBCPP_HIDE_FROM_ABI inline constexpr month& operator++() noexcept { ++__m; return *this; }
34 _LIBCPP_HIDE_FROM_ABI inline constexpr month operator++(int) noexcept { month __tmp = *this; ++(*this); return __tmp; }
35 _LIBCPP_HIDE_FROM_ABI inline constexpr month& operator--() noexcept { --__m; return *this; }
36 _LIBCPP_HIDE_FROM_ABI inline constexpr month operator--(int) noexcept { month __tmp = *this; --(*this); return __tmp; }
37 _LIBCPP_HIDE_FROM_ABI constexpr month& operator+=(const months& __m1) noexcept;
38 _LIBCPP_HIDE_FROM_ABI constexpr month& operator-=(const months& __m1) noexcept;
39 _LIBCPP_HIDE_FROM_ABI explicit inline constexpr operator unsigned() const noexcept { return __m; }
40 _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __m >= 1 && __m <= 12; }
41};
42
43
44_LIBCPP_HIDE_FROM_ABI inline constexpr
45bool operator==(const month& __lhs, const month& __rhs) noexcept
46{ return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); }
47
48_LIBCPP_HIDE_FROM_ABI inline constexpr
49bool operator!=(const month& __lhs, const month& __rhs) noexcept
50{ return !(__lhs == __rhs); }
51
52_LIBCPP_HIDE_FROM_ABI inline constexpr
53bool operator< (const month& __lhs, const month& __rhs) noexcept
54{ return static_cast<unsigned>(__lhs) < static_cast<unsigned>(__rhs); }
55
56_LIBCPP_HIDE_FROM_ABI inline constexpr
57bool operator> (const month& __lhs, const month& __rhs) noexcept
58{ return __rhs < __lhs; }
59
60_LIBCPP_HIDE_FROM_ABI inline constexpr
61bool operator<=(const month& __lhs, const month& __rhs) noexcept
62{ return !(__rhs < __lhs); }
63
64_LIBCPP_HIDE_FROM_ABI inline constexpr
65bool operator>=(const month& __lhs, const month& __rhs) noexcept
66{ return !(__lhs < __rhs); }
67
68_LIBCPP_HIDE_FROM_ABI inline constexpr
69month operator+ (const month& __lhs, const months& __rhs) noexcept
70{
71 auto const __mu = static_cast<long long>(static_cast<unsigned>(__lhs)) + (__rhs.count() - 1);
72 auto const __yr = (__mu >= 0 ? __mu : __mu - 11) / 12;
73 return month{static_cast<unsigned>(__mu - __yr * 12 + 1)};
74}
75
76_LIBCPP_HIDE_FROM_ABI inline constexpr
77month operator+ (const months& __lhs, const month& __rhs) noexcept
78{ return __rhs + __lhs; }
79
80_LIBCPP_HIDE_FROM_ABI inline constexpr
81month operator- (const month& __lhs, const months& __rhs) noexcept
82{ return __lhs + -__rhs; }
83
84_LIBCPP_HIDE_FROM_ABI inline constexpr
85months operator-(const month& __lhs, const month& __rhs) noexcept
86{
87 auto const __dm = static_cast<unsigned>(__lhs) - static_cast<unsigned>(__rhs);
88 return months(__dm <= 11 ? __dm : __dm + 12);
89}
90
91_LIBCPP_HIDE_FROM_ABI inline constexpr
92month& month::operator+=(const months& __dm) noexcept
93{ *this = *this + __dm; return *this; }
94
95_LIBCPP_HIDE_FROM_ABI inline constexpr
96month& month::operator-=(const months& __dm) noexcept
97{ *this = *this - __dm; return *this; }
98
99inline constexpr month January{1};
100inline constexpr month February{2};
101inline constexpr month March{3};
102inline constexpr month April{4};
103inline constexpr month May{5};
104inline constexpr month June{6};
105inline constexpr month July{7};
106inline constexpr month August{8};
107inline constexpr month September{9};
108inline constexpr month October{10};
109inline constexpr month November{11};
110inline constexpr month December{12};
111
112} // namespace chrono
113
114_LIBCPP_END_NAMESPACE_STD
115
116#endif // _LIBCPP_STD_VER > 17
117
118#endif // _LIBCPP___CHRONO_MONTH_H
lib/libcxx/include/__chrono/month_weekday.h created+106
......@@ -0,0 +1,106 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___CHRONO_MONTH_WEEKDAY_H
11#define _LIBCPP___CHRONO_MONTH_WEEKDAY_H
12
13#include <__chrono/month.h>
14#include <__chrono/weekday.h>
15#include <__config>
16
17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18# pragma GCC system_header
19#endif
20
21#if _LIBCPP_STD_VER > 17
22
23_LIBCPP_BEGIN_NAMESPACE_STD
24
25namespace chrono
26{
27
28class month_weekday {
29private:
30 chrono::month __m;
31 chrono::weekday_indexed __wdi;
32public:
33 _LIBCPP_HIDE_FROM_ABI constexpr month_weekday(const chrono::month& __mval, const chrono::weekday_indexed& __wdival) noexcept
34 : __m{__mval}, __wdi{__wdival} {}
35 _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m; }
36 _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { return __wdi; }
37 _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __m.ok() && __wdi.ok(); }
38};
39
40_LIBCPP_HIDE_FROM_ABI inline constexpr
41bool operator==(const month_weekday& __lhs, const month_weekday& __rhs) noexcept
42{ return __lhs.month() == __rhs.month() && __lhs.weekday_indexed() == __rhs.weekday_indexed(); }
43
44_LIBCPP_HIDE_FROM_ABI inline constexpr
45bool operator!=(const month_weekday& __lhs, const month_weekday& __rhs) noexcept
46{ return !(__lhs == __rhs); }
47
48_LIBCPP_HIDE_FROM_ABI inline constexpr
49month_weekday operator/(const month& __lhs, const weekday_indexed& __rhs) noexcept
50{ return month_weekday{__lhs, __rhs}; }
51
52_LIBCPP_HIDE_FROM_ABI inline constexpr
53month_weekday operator/(int __lhs, const weekday_indexed& __rhs) noexcept
54{ return month_weekday{month(__lhs), __rhs}; }
55
56_LIBCPP_HIDE_FROM_ABI inline constexpr
57month_weekday operator/(const weekday_indexed& __lhs, const month& __rhs) noexcept
58{ return month_weekday{__rhs, __lhs}; }
59
60_LIBCPP_HIDE_FROM_ABI inline constexpr
61month_weekday operator/(const weekday_indexed& __lhs, int __rhs) noexcept
62{ return month_weekday{month(__rhs), __lhs}; }
63
64
65class month_weekday_last {
66 chrono::month __m;
67 chrono::weekday_last __wdl;
68 public:
69 _LIBCPP_HIDE_FROM_ABI constexpr month_weekday_last(const chrono::month& __mval, const chrono::weekday_last& __wdlval) noexcept
70 : __m{__mval}, __wdl{__wdlval} {}
71 _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m; }
72 _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday_last weekday_last() const noexcept { return __wdl; }
73 _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __m.ok() && __wdl.ok(); }
74};
75
76_LIBCPP_HIDE_FROM_ABI inline constexpr
77bool operator==(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noexcept
78{ return __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last(); }
79
80_LIBCPP_HIDE_FROM_ABI inline constexpr
81bool operator!=(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noexcept
82{ return !(__lhs == __rhs); }
83
84
85_LIBCPP_HIDE_FROM_ABI inline constexpr
86month_weekday_last operator/(const month& __lhs, const weekday_last& __rhs) noexcept
87{ return month_weekday_last{__lhs, __rhs}; }
88
89_LIBCPP_HIDE_FROM_ABI inline constexpr
90month_weekday_last operator/(int __lhs, const weekday_last& __rhs) noexcept
91{ return month_weekday_last{month(__lhs), __rhs}; }
92
93_LIBCPP_HIDE_FROM_ABI inline constexpr
94month_weekday_last operator/(const weekday_last& __lhs, const month& __rhs) noexcept
95{ return month_weekday_last{__rhs, __lhs}; }
96
97_LIBCPP_HIDE_FROM_ABI inline constexpr
98month_weekday_last operator/(const weekday_last& __lhs, int __rhs) noexcept
99{ return month_weekday_last{month(__rhs), __lhs}; }
100} // namespace chrono
101
102_LIBCPP_END_NAMESPACE_STD
103
104#endif // _LIBCPP_STD_VER > 17
105
106#endif // _LIBCPP___CHRONO_MONTH_WEEKDAY_H
lib/libcxx/include/__chrono/monthday.h created+160
......@@ -0,0 +1,160 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___CHRONO_MONTHDAY_H
11#define _LIBCPP___CHRONO_MONTHDAY_H
12
13#include <__chrono/calendar.h>
14#include <__chrono/day.h>
15#include <__chrono/month.h>
16#include <__config>
17
18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19# pragma GCC system_header
20#endif
21
22#if _LIBCPP_STD_VER > 17
23
24_LIBCPP_BEGIN_NAMESPACE_STD
25
26namespace chrono
27{
28
29class month_day {
30private:
31 chrono::month __m;
32 chrono::day __d;
33public:
34 _LIBCPP_HIDE_FROM_ABI month_day() = default;
35 _LIBCPP_HIDE_FROM_ABI constexpr month_day(const chrono::month& __mval, const chrono::day& __dval) noexcept
36 : __m{__mval}, __d{__dval} {}
37 _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m; }
38 _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::day day() const noexcept { return __d; }
39 _LIBCPP_HIDE_FROM_ABI constexpr bool ok() const noexcept;
40};
41
42_LIBCPP_HIDE_FROM_ABI inline constexpr
43bool month_day::ok() const noexcept
44{
45 if (!__m.ok()) return false;
46 const unsigned __dval = static_cast<unsigned>(__d);
47 if (__dval < 1 || __dval > 31) return false;
48 if (__dval <= 29) return true;
49// Now we've got either 30 or 31
50 const unsigned __mval = static_cast<unsigned>(__m);
51 if (__mval == 2) return false;
52 if (__mval == 4 || __mval == 6 || __mval == 9 || __mval == 11)
53 return __dval == 30;
54 return true;
55}
56
57_LIBCPP_HIDE_FROM_ABI inline constexpr
58bool operator==(const month_day& __lhs, const month_day& __rhs) noexcept
59{ return __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); }
60
61_LIBCPP_HIDE_FROM_ABI inline constexpr
62bool operator!=(const month_day& __lhs, const month_day& __rhs) noexcept
63{ return !(__lhs == __rhs); }
64
65_LIBCPP_HIDE_FROM_ABI inline constexpr
66month_day operator/(const month& __lhs, const day& __rhs) noexcept
67{ return month_day{__lhs, __rhs}; }
68
69_LIBCPP_HIDE_FROM_ABI constexpr
70month_day operator/(const day& __lhs, const month& __rhs) noexcept
71{ return __rhs / __lhs; }
72
73_LIBCPP_HIDE_FROM_ABI inline constexpr
74month_day operator/(const month& __lhs, int __rhs) noexcept
75{ return __lhs / day(__rhs); }
76
77_LIBCPP_HIDE_FROM_ABI constexpr
78month_day operator/(int __lhs, const day& __rhs) noexcept
79{ return month(__lhs) / __rhs; }
80
81_LIBCPP_HIDE_FROM_ABI constexpr
82month_day operator/(const day& __lhs, int __rhs) noexcept
83{ return month(__rhs) / __lhs; }
84
85
86_LIBCPP_HIDE_FROM_ABI inline constexpr
87bool operator< (const month_day& __lhs, const month_day& __rhs) noexcept
88{ return __lhs.month() != __rhs.month() ? __lhs.month() < __rhs.month() : __lhs.day() < __rhs.day(); }
89
90_LIBCPP_HIDE_FROM_ABI inline constexpr
91bool operator> (const month_day& __lhs, const month_day& __rhs) noexcept
92{ return __rhs < __lhs; }
93
94_LIBCPP_HIDE_FROM_ABI inline constexpr
95bool operator<=(const month_day& __lhs, const month_day& __rhs) noexcept
96{ return !(__rhs < __lhs);}
97
98_LIBCPP_HIDE_FROM_ABI inline constexpr
99bool operator>=(const month_day& __lhs, const month_day& __rhs) noexcept
100{ return !(__lhs < __rhs); }
101
102
103
104class month_day_last {
105private:
106 chrono::month __m;
107public:
108 _LIBCPP_HIDE_FROM_ABI explicit constexpr month_day_last(const chrono::month& __val) noexcept
109 : __m{__val} {}
110 _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m; }
111 _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __m.ok(); }
112};
113
114_LIBCPP_HIDE_FROM_ABI inline constexpr
115bool operator==(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
116{ return __lhs.month() == __rhs.month(); }
117
118_LIBCPP_HIDE_FROM_ABI inline constexpr
119bool operator!=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
120{ return !(__lhs == __rhs); }
121
122_LIBCPP_HIDE_FROM_ABI inline constexpr
123bool operator< (const month_day_last& __lhs, const month_day_last& __rhs) noexcept
124{ return __lhs.month() < __rhs.month(); }
125
126_LIBCPP_HIDE_FROM_ABI inline constexpr
127bool operator> (const month_day_last& __lhs, const month_day_last& __rhs) noexcept
128{ return __rhs < __lhs; }
129
130_LIBCPP_HIDE_FROM_ABI inline constexpr
131bool operator<=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
132{ return !(__rhs < __lhs);}
133
134_LIBCPP_HIDE_FROM_ABI inline constexpr
135bool operator>=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
136{ return !(__lhs < __rhs); }
137
138_LIBCPP_HIDE_FROM_ABI inline constexpr
139month_day_last operator/(const month& __lhs, last_spec) noexcept
140{ return month_day_last{__lhs}; }
141
142_LIBCPP_HIDE_FROM_ABI inline constexpr
143month_day_last operator/(last_spec, const month& __rhs) noexcept
144{ return month_day_last{__rhs}; }
145
146_LIBCPP_HIDE_FROM_ABI inline constexpr
147month_day_last operator/(int __lhs, last_spec) noexcept
148{ return month_day_last{month(__lhs)}; }
149
150_LIBCPP_HIDE_FROM_ABI inline constexpr
151month_day_last operator/(last_spec, int __rhs) noexcept
152{ return month_day_last{month(__rhs)}; }
153
154} // namespace chrono
155
156_LIBCPP_END_NAMESPACE_STD
157
158#endif // _LIBCPP_STD_VER > 17
159
160#endif // _LIBCPP___CHRONO_MONTHDAY_H
lib/libcxx/include/__chrono/steady_clock.h+1-1
......@@ -15,7 +15,7 @@
1515#include <__config>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__chrono/system_clock.h+1-1
......@@ -16,7 +16,7 @@
1616#include <ctime>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
19# pragma GCC system_header
2020#endif
2121
2222_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__chrono/time_point.h+3-3
......@@ -16,7 +16,7 @@
1616#include <type_traits>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
19# pragma GCC system_header
2020#endif
2121
2222_LIBCPP_PUSH_MACROS
......@@ -47,12 +47,12 @@ public:
4747 // conversions
4848 template <class _Duration2>
4949 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
50 time_point(const time_point<clock, _Duration2>& t,
50 time_point(const time_point<clock, _Duration2>& __t,
5151 typename enable_if
5252 <
5353 is_convertible<_Duration2, duration>::value
5454 >::type* = nullptr)
55 : __d_(t.time_since_epoch()) {}
55 : __d_(__t.time_since_epoch()) {}
5656
5757 // observer
5858
lib/libcxx/include/__chrono/weekday.h created+185
......@@ -0,0 +1,185 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___CHRONO_WEEKDAY_H
11#define _LIBCPP___CHRONO_WEEKDAY_H
12
13#include <__chrono/calendar.h>
14#include <__chrono/duration.h>
15#include <__chrono/system_clock.h>
16#include <__chrono/time_point.h>
17#include <__config>
18
19#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20# pragma GCC system_header
21#endif
22
23#if _LIBCPP_STD_VER > 17
24
25_LIBCPP_BEGIN_NAMESPACE_STD
26
27namespace chrono
28{
29
30class weekday_indexed;
31class weekday_last;
32
33class weekday {
34private:
35 unsigned char __wd;
36 _LIBCPP_HIDE_FROM_ABI static constexpr unsigned char __weekday_from_days(int __days) noexcept;
37public:
38 _LIBCPP_HIDE_FROM_ABI weekday() = default;
39 _LIBCPP_HIDE_FROM_ABI inline explicit constexpr weekday(unsigned __val) noexcept : __wd(static_cast<unsigned char>(__val == 7 ? 0 : __val)) {}
40 _LIBCPP_HIDE_FROM_ABI inline constexpr weekday(const sys_days& __sysd) noexcept
41 : __wd(__weekday_from_days(__sysd.time_since_epoch().count())) {}
42 _LIBCPP_HIDE_FROM_ABI inline explicit constexpr weekday(const local_days& __locd) noexcept
43 : __wd(__weekday_from_days(__locd.time_since_epoch().count())) {}
44
45 _LIBCPP_HIDE_FROM_ABI inline constexpr weekday& operator++() noexcept { __wd = (__wd == 6 ? 0 : __wd + 1); return *this; }
46 _LIBCPP_HIDE_FROM_ABI inline constexpr weekday operator++(int) noexcept { weekday __tmp = *this; ++(*this); return __tmp; }
47 _LIBCPP_HIDE_FROM_ABI inline constexpr weekday& operator--() noexcept { __wd = (__wd == 0 ? 6 : __wd - 1); return *this; }
48 _LIBCPP_HIDE_FROM_ABI inline constexpr weekday operator--(int) noexcept { weekday __tmp = *this; --(*this); return __tmp; }
49 _LIBCPP_HIDE_FROM_ABI constexpr weekday& operator+=(const days& __dd) noexcept;
50 _LIBCPP_HIDE_FROM_ABI constexpr weekday& operator-=(const days& __dd) noexcept;
51 _LIBCPP_HIDE_FROM_ABI inline constexpr unsigned c_encoding() const noexcept { return __wd; }
52 _LIBCPP_HIDE_FROM_ABI inline constexpr unsigned iso_encoding() const noexcept { return __wd == 0u ? 7 : __wd; }
53 _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __wd <= 6; }
54 _LIBCPP_HIDE_FROM_ABI constexpr weekday_indexed operator[](unsigned __index) const noexcept;
55 _LIBCPP_HIDE_FROM_ABI constexpr weekday_last operator[](last_spec) const noexcept;
56};
57
58
59// https://howardhinnant.github.io/date_algorithms.html#weekday_from_days
60_LIBCPP_HIDE_FROM_ABI inline constexpr
61unsigned char weekday::__weekday_from_days(int __days) noexcept
62{
63 return static_cast<unsigned char>(
64 static_cast<unsigned>(__days >= -4 ? (__days+4) % 7 : (__days+5) % 7 + 6)
65 );
66}
67
68_LIBCPP_HIDE_FROM_ABI inline constexpr
69bool operator==(const weekday& __lhs, const weekday& __rhs) noexcept
70{ return __lhs.c_encoding() == __rhs.c_encoding(); }
71
72_LIBCPP_HIDE_FROM_ABI inline constexpr
73bool operator!=(const weekday& __lhs, const weekday& __rhs) noexcept
74{ return !(__lhs == __rhs); }
75
76_LIBCPP_HIDE_FROM_ABI inline constexpr
77bool operator< (const weekday& __lhs, const weekday& __rhs) noexcept
78{ return __lhs.c_encoding() < __rhs.c_encoding(); }
79
80_LIBCPP_HIDE_FROM_ABI inline constexpr
81bool operator> (const weekday& __lhs, const weekday& __rhs) noexcept
82{ return __rhs < __lhs; }
83
84_LIBCPP_HIDE_FROM_ABI inline constexpr
85bool operator<=(const weekday& __lhs, const weekday& __rhs) noexcept
86{ return !(__rhs < __lhs);}
87
88_LIBCPP_HIDE_FROM_ABI inline constexpr
89bool operator>=(const weekday& __lhs, const weekday& __rhs) noexcept
90{ return !(__lhs < __rhs); }
91
92_LIBCPP_HIDE_FROM_ABI constexpr
93weekday operator+(const weekday& __lhs, const days& __rhs) noexcept
94{
95 auto const __mu = static_cast<long long>(__lhs.c_encoding()) + __rhs.count();
96 auto const __yr = (__mu >= 0 ? __mu : __mu - 6) / 7;
97 return weekday{static_cast<unsigned>(__mu - __yr * 7)};
98}
99
100_LIBCPP_HIDE_FROM_ABI constexpr
101weekday operator+(const days& __lhs, const weekday& __rhs) noexcept
102{ return __rhs + __lhs; }
103
104_LIBCPP_HIDE_FROM_ABI constexpr
105weekday operator-(const weekday& __lhs, const days& __rhs) noexcept
106{ return __lhs + -__rhs; }
107
108_LIBCPP_HIDE_FROM_ABI constexpr
109days operator-(const weekday& __lhs, const weekday& __rhs) noexcept
110{
111 const int __wdu = __lhs.c_encoding() - __rhs.c_encoding();
112 const int __wk = (__wdu >= 0 ? __wdu : __wdu-6) / 7;
113 return days{__wdu - __wk * 7};
114}
115
116_LIBCPP_HIDE_FROM_ABI inline constexpr
117weekday& weekday::operator+=(const days& __dd) noexcept
118{ *this = *this + __dd; return *this; }
119
120_LIBCPP_HIDE_FROM_ABI inline constexpr
121weekday& weekday::operator-=(const days& __dd) noexcept
122{ *this = *this - __dd; return *this; }
123
124class weekday_indexed {
125private:
126 chrono::weekday __wd;
127 unsigned char __idx;
128public:
129 _LIBCPP_HIDE_FROM_ABI weekday_indexed() = default;
130 _LIBCPP_HIDE_FROM_ABI inline constexpr weekday_indexed(const chrono::weekday& __wdval, unsigned __idxval) noexcept
131 : __wd{__wdval}, __idx(__idxval) {}
132 _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday weekday() const noexcept { return __wd; }
133 _LIBCPP_HIDE_FROM_ABI inline constexpr unsigned index() const noexcept { return __idx; }
134 _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __wd.ok() && __idx >= 1 && __idx <= 5; }
135};
136
137_LIBCPP_HIDE_FROM_ABI inline constexpr
138bool operator==(const weekday_indexed& __lhs, const weekday_indexed& __rhs) noexcept
139{ return __lhs.weekday() == __rhs.weekday() && __lhs.index() == __rhs.index(); }
140
141_LIBCPP_HIDE_FROM_ABI inline constexpr
142bool operator!=(const weekday_indexed& __lhs, const weekday_indexed& __rhs) noexcept
143{ return !(__lhs == __rhs); }
144
145
146class weekday_last {
147private:
148 chrono::weekday __wd;
149public:
150 _LIBCPP_HIDE_FROM_ABI explicit constexpr weekday_last(const chrono::weekday& __val) noexcept
151 : __wd{__val} {}
152 _LIBCPP_HIDE_FROM_ABI constexpr chrono::weekday weekday() const noexcept { return __wd; }
153 _LIBCPP_HIDE_FROM_ABI constexpr bool ok() const noexcept { return __wd.ok(); }
154};
155
156_LIBCPP_HIDE_FROM_ABI inline constexpr
157bool operator==(const weekday_last& __lhs, const weekday_last& __rhs) noexcept
158{ return __lhs.weekday() == __rhs.weekday(); }
159
160_LIBCPP_HIDE_FROM_ABI inline constexpr
161bool operator!=(const weekday_last& __lhs, const weekday_last& __rhs) noexcept
162{ return !(__lhs == __rhs); }
163
164_LIBCPP_HIDE_FROM_ABI inline constexpr
165weekday_indexed weekday::operator[](unsigned __index) const noexcept { return weekday_indexed{*this, __index}; }
166
167_LIBCPP_HIDE_FROM_ABI inline constexpr
168weekday_last weekday::operator[](last_spec) const noexcept { return weekday_last{*this}; }
169
170
171inline constexpr weekday Sunday{0};
172inline constexpr weekday Monday{1};
173inline constexpr weekday Tuesday{2};
174inline constexpr weekday Wednesday{3};
175inline constexpr weekday Thursday{4};
176inline constexpr weekday Friday{5};
177inline constexpr weekday Saturday{6};
178
179} // namespace chrono
180
181_LIBCPP_END_NAMESPACE_STD
182
183#endif // _LIBCPP_STD_VER > 17
184
185#endif // _LIBCPP___CHRONO_WEEKDAY_H
lib/libcxx/include/__chrono/year.h created+117
......@@ -0,0 +1,117 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___CHRONO_YEAR_H
11#define _LIBCPP___CHRONO_YEAR_H
12
13#include <__chrono/duration.h>
14#include <__config>
15#include <limits>
16
17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18# pragma GCC system_header
19#endif
20
21_LIBCPP_PUSH_MACROS
22#include <__undef_macros>
23
24#if _LIBCPP_STD_VER > 17
25
26_LIBCPP_BEGIN_NAMESPACE_STD
27
28namespace chrono
29{
30
31class year {
32private:
33 short __y;
34public:
35 _LIBCPP_HIDE_FROM_ABI year() = default;
36 _LIBCPP_HIDE_FROM_ABI explicit inline constexpr year(int __val) noexcept : __y(static_cast<short>(__val)) {}
37
38 _LIBCPP_HIDE_FROM_ABI inline constexpr year& operator++() noexcept { ++__y; return *this; }
39 _LIBCPP_HIDE_FROM_ABI inline constexpr year operator++(int) noexcept { year __tmp = *this; ++(*this); return __tmp; }
40 _LIBCPP_HIDE_FROM_ABI inline constexpr year& operator--() noexcept { --__y; return *this; }
41 _LIBCPP_HIDE_FROM_ABI inline constexpr year operator--(int) noexcept { year __tmp = *this; --(*this); return __tmp; }
42 _LIBCPP_HIDE_FROM_ABI constexpr year& operator+=(const years& __dy) noexcept;
43 _LIBCPP_HIDE_FROM_ABI constexpr year& operator-=(const years& __dy) noexcept;
44 _LIBCPP_HIDE_FROM_ABI inline constexpr year operator+() const noexcept { return *this; }
45 _LIBCPP_HIDE_FROM_ABI inline constexpr year operator-() const noexcept { return year{-__y}; }
46
47 _LIBCPP_HIDE_FROM_ABI inline constexpr bool is_leap() const noexcept { return __y % 4 == 0 && (__y % 100 != 0 || __y % 400 == 0); }
48 _LIBCPP_HIDE_FROM_ABI explicit inline constexpr operator int() const noexcept { return __y; }
49 _LIBCPP_HIDE_FROM_ABI constexpr bool ok() const noexcept;
50 _LIBCPP_HIDE_FROM_ABI static inline constexpr year min() noexcept { return year{-32767}; }
51 _LIBCPP_HIDE_FROM_ABI static inline constexpr year max() noexcept { return year{ 32767}; }
52};
53
54
55_LIBCPP_HIDE_FROM_ABI inline constexpr
56bool operator==(const year& __lhs, const year& __rhs) noexcept
57{ return static_cast<int>(__lhs) == static_cast<int>(__rhs); }
58
59_LIBCPP_HIDE_FROM_ABI inline constexpr
60bool operator!=(const year& __lhs, const year& __rhs) noexcept
61{ return !(__lhs == __rhs); }
62
63_LIBCPP_HIDE_FROM_ABI inline constexpr
64bool operator< (const year& __lhs, const year& __rhs) noexcept
65{ return static_cast<int>(__lhs) < static_cast<int>(__rhs); }
66
67_LIBCPP_HIDE_FROM_ABI inline constexpr
68bool operator> (const year& __lhs, const year& __rhs) noexcept
69{ return __rhs < __lhs; }
70
71_LIBCPP_HIDE_FROM_ABI inline constexpr
72bool operator<=(const year& __lhs, const year& __rhs) noexcept
73{ return !(__rhs < __lhs); }
74
75_LIBCPP_HIDE_FROM_ABI inline constexpr
76bool operator>=(const year& __lhs, const year& __rhs) noexcept
77{ return !(__lhs < __rhs); }
78
79_LIBCPP_HIDE_FROM_ABI inline constexpr
80year operator+ (const year& __lhs, const years& __rhs) noexcept
81{ return year(static_cast<int>(__lhs) + __rhs.count()); }
82
83_LIBCPP_HIDE_FROM_ABI inline constexpr
84year operator+ (const years& __lhs, const year& __rhs) noexcept
85{ return __rhs + __lhs; }
86
87_LIBCPP_HIDE_FROM_ABI inline constexpr
88year operator- (const year& __lhs, const years& __rhs) noexcept
89{ return __lhs + -__rhs; }
90
91_LIBCPP_HIDE_FROM_ABI inline constexpr
92years operator-(const year& __lhs, const year& __rhs) noexcept
93{ return years{static_cast<int>(__lhs) - static_cast<int>(__rhs)}; }
94
95
96_LIBCPP_HIDE_FROM_ABI inline constexpr
97year& year::operator+=(const years& __dy) noexcept
98{ *this = *this + __dy; return *this; }
99
100_LIBCPP_HIDE_FROM_ABI inline constexpr
101year& year::operator-=(const years& __dy) noexcept
102{ *this = *this - __dy; return *this; }
103
104_LIBCPP_HIDE_FROM_ABI constexpr bool year::ok() const noexcept {
105 static_assert(static_cast<int>(std::numeric_limits<decltype(__y)>::max()) == static_cast<int>(max()));
106 return static_cast<int>(min()) <= __y;
107}
108
109} // namespace chrono
110
111_LIBCPP_END_NAMESPACE_STD
112
113#endif // _LIBCPP_STD_VER > 17
114
115_LIBCPP_POP_MACROS
116
117#endif // _LIBCPP___CHRONO_YEAR_H
lib/libcxx/include/__chrono/year_month.h created+114
......@@ -0,0 +1,114 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___CHRONO_YEAR_MONTH_H
11#define _LIBCPP___CHRONO_YEAR_MONTH_H
12
13#include <__chrono/duration.h>
14#include <__chrono/month.h>
15#include <__chrono/year.h>
16#include <__config>
17
18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19# pragma GCC system_header
20#endif
21
22#if _LIBCPP_STD_VER > 17
23
24_LIBCPP_BEGIN_NAMESPACE_STD
25
26namespace chrono
27{
28
29class year_month {
30 chrono::year __y;
31 chrono::month __m;
32public:
33 _LIBCPP_HIDE_FROM_ABI year_month() = default;
34 _LIBCPP_HIDE_FROM_ABI constexpr year_month(const chrono::year& __yval, const chrono::month& __mval) noexcept
35 : __y{__yval}, __m{__mval} {}
36 _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::year year() const noexcept { return __y; }
37 _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m; }
38 _LIBCPP_HIDE_FROM_ABI inline constexpr year_month& operator+=(const months& __dm) noexcept { this->__m += __dm; return *this; }
39 _LIBCPP_HIDE_FROM_ABI inline constexpr year_month& operator-=(const months& __dm) noexcept { this->__m -= __dm; return *this; }
40 _LIBCPP_HIDE_FROM_ABI inline constexpr year_month& operator+=(const years& __dy) noexcept { this->__y += __dy; return *this; }
41 _LIBCPP_HIDE_FROM_ABI inline constexpr year_month& operator-=(const years& __dy) noexcept { this->__y -= __dy; return *this; }
42 _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __y.ok() && __m.ok(); }
43};
44
45_LIBCPP_HIDE_FROM_ABI inline constexpr
46year_month operator/(const year& __y, const month& __m) noexcept { return year_month{__y, __m}; }
47
48_LIBCPP_HIDE_FROM_ABI inline constexpr
49year_month operator/(const year& __y, int __m) noexcept { return year_month{__y, month(__m)}; }
50
51_LIBCPP_HIDE_FROM_ABI inline constexpr
52bool operator==(const year_month& __lhs, const year_month& __rhs) noexcept
53{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month(); }
54
55_LIBCPP_HIDE_FROM_ABI inline constexpr
56bool operator!=(const year_month& __lhs, const year_month& __rhs) noexcept
57{ return !(__lhs == __rhs); }
58
59_LIBCPP_HIDE_FROM_ABI inline constexpr
60bool operator< (const year_month& __lhs, const year_month& __rhs) noexcept
61{ return __lhs.year() != __rhs.year() ? __lhs.year() < __rhs.year() : __lhs.month() < __rhs.month(); }
62
63_LIBCPP_HIDE_FROM_ABI inline constexpr
64bool operator> (const year_month& __lhs, const year_month& __rhs) noexcept
65{ return __rhs < __lhs; }
66
67_LIBCPP_HIDE_FROM_ABI inline constexpr
68bool operator<=(const year_month& __lhs, const year_month& __rhs) noexcept
69{ return !(__rhs < __lhs);}
70
71_LIBCPP_HIDE_FROM_ABI inline constexpr
72bool operator>=(const year_month& __lhs, const year_month& __rhs) noexcept
73{ return !(__lhs < __rhs); }
74
75_LIBCPP_HIDE_FROM_ABI constexpr
76year_month operator+(const year_month& __lhs, const months& __rhs) noexcept
77{
78 int __dmi = static_cast<int>(static_cast<unsigned>(__lhs.month())) - 1 + __rhs.count();
79 const int __dy = (__dmi >= 0 ? __dmi : __dmi-11) / 12;
80 __dmi = __dmi - __dy * 12 + 1;
81 return (__lhs.year() + years(__dy)) / month(static_cast<unsigned>(__dmi));
82}
83
84_LIBCPP_HIDE_FROM_ABI constexpr
85year_month operator+(const months& __lhs, const year_month& __rhs) noexcept
86{ return __rhs + __lhs; }
87
88_LIBCPP_HIDE_FROM_ABI constexpr
89year_month operator+(const year_month& __lhs, const years& __rhs) noexcept
90{ return (__lhs.year() + __rhs) / __lhs.month(); }
91
92_LIBCPP_HIDE_FROM_ABI constexpr
93year_month operator+(const years& __lhs, const year_month& __rhs) noexcept
94{ return __rhs + __lhs; }
95
96_LIBCPP_HIDE_FROM_ABI constexpr
97months operator-(const year_month& __lhs, const year_month& __rhs) noexcept
98{ return (__lhs.year() - __rhs.year()) + months(static_cast<unsigned>(__lhs.month()) - static_cast<unsigned>(__rhs.month())); }
99
100_LIBCPP_HIDE_FROM_ABI constexpr
101year_month operator-(const year_month& __lhs, const months& __rhs) noexcept
102{ return __lhs + -__rhs; }
103
104_LIBCPP_HIDE_FROM_ABI constexpr
105year_month operator-(const year_month& __lhs, const years& __rhs) noexcept
106{ return __lhs + -__rhs; }
107
108} // namespace chrono
109
110_LIBCPP_END_NAMESPACE_STD
111
112#endif // _LIBCPP_STD_VER > 17
113
114#endif // _LIBCPP___CHRONO_YEAR_MONTH_H
lib/libcxx/include/__chrono/year_month_day.h created+323
......@@ -0,0 +1,323 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___CHRONO_YEAR_MONTH_DAY_H
11#define _LIBCPP___CHRONO_YEAR_MONTH_DAY_H
12
13#include <__chrono/calendar.h>
14#include <__chrono/day.h>
15#include <__chrono/duration.h>
16#include <__chrono/month.h>
17#include <__chrono/monthday.h>
18#include <__chrono/system_clock.h>
19#include <__chrono/time_point.h>
20#include <__chrono/year.h>
21#include <__chrono/year_month.h>
22#include <__config>
23#include <limits>
24
25#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
26# pragma GCC system_header
27#endif
28
29#if _LIBCPP_STD_VER > 17
30
31_LIBCPP_BEGIN_NAMESPACE_STD
32
33namespace chrono
34{
35
36class year_month_day_last;
37
38class year_month_day {
39private:
40 chrono::year __y;
41 chrono::month __m;
42 chrono::day __d;
43public:
44 _LIBCPP_HIDE_FROM_ABI year_month_day() = default;
45 _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day(
46 const chrono::year& __yval, const chrono::month& __mval, const chrono::day& __dval) noexcept
47 : __y{__yval}, __m{__mval}, __d{__dval} {}
48 _LIBCPP_HIDE_FROM_ABI constexpr year_month_day(const year_month_day_last& __ymdl) noexcept;
49 _LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day(const sys_days& __sysd) noexcept
50 : year_month_day(__from_days(__sysd.time_since_epoch())) {}
51 _LIBCPP_HIDE_FROM_ABI inline explicit constexpr year_month_day(const local_days& __locd) noexcept
52 : year_month_day(__from_days(__locd.time_since_epoch())) {}
53
54 _LIBCPP_HIDE_FROM_ABI constexpr year_month_day& operator+=(const months& __dm) noexcept;
55 _LIBCPP_HIDE_FROM_ABI constexpr year_month_day& operator-=(const months& __dm) noexcept;
56 _LIBCPP_HIDE_FROM_ABI constexpr year_month_day& operator+=(const years& __dy) noexcept;
57 _LIBCPP_HIDE_FROM_ABI constexpr year_month_day& operator-=(const years& __dy) noexcept;
58
59 _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::year year() const noexcept { return __y; }
60 _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m; }
61 _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::day day() const noexcept { return __d; }
62 _LIBCPP_HIDE_FROM_ABI inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; }
63 _LIBCPP_HIDE_FROM_ABI inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; }
64
65 _LIBCPP_HIDE_FROM_ABI constexpr bool ok() const noexcept;
66
67 _LIBCPP_HIDE_FROM_ABI static constexpr year_month_day __from_days(days __d) noexcept;
68 _LIBCPP_HIDE_FROM_ABI constexpr days __to_days() const noexcept;
69};
70
71
72// https://howardhinnant.github.io/date_algorithms.html#civil_from_days
73_LIBCPP_HIDE_FROM_ABI inline constexpr
74year_month_day year_month_day::__from_days(days __d) noexcept
75{
76 static_assert(numeric_limits<unsigned>::digits >= 18, "");
77 static_assert(numeric_limits<int>::digits >= 20 , "");
78 const int __z = __d.count() + 719468;
79 const int __era = (__z >= 0 ? __z : __z - 146096) / 146097;
80 const unsigned __doe = static_cast<unsigned>(__z - __era * 146097); // [0, 146096]
81 const unsigned __yoe = (__doe - __doe/1460 + __doe/36524 - __doe/146096) / 365; // [0, 399]
82 const int __yr = static_cast<int>(__yoe) + __era * 400;
83 const unsigned __doy = __doe - (365 * __yoe + __yoe/4 - __yoe/100); // [0, 365]
84 const unsigned __mp = (5 * __doy + 2)/153; // [0, 11]
85 const unsigned __dy = __doy - (153 * __mp + 2)/5 + 1; // [1, 31]
86 const unsigned __mth = __mp + (__mp < 10 ? 3 : -9); // [1, 12]
87 return year_month_day{chrono::year{__yr + (__mth <= 2)}, chrono::month{__mth}, chrono::day{__dy}};
88}
89
90// https://howardhinnant.github.io/date_algorithms.html#days_from_civil
91_LIBCPP_HIDE_FROM_ABI inline constexpr
92days year_month_day::__to_days() const noexcept
93{
94 static_assert(numeric_limits<unsigned>::digits >= 18, "");
95 static_assert(numeric_limits<int>::digits >= 20 , "");
96
97 const int __yr = static_cast<int>(__y) - (__m <= February);
98 const unsigned __mth = static_cast<unsigned>(__m);
99 const unsigned __dy = static_cast<unsigned>(__d);
100
101 const int __era = (__yr >= 0 ? __yr : __yr - 399) / 400;
102 const unsigned __yoe = static_cast<unsigned>(__yr - __era * 400); // [0, 399]
103 const unsigned __doy = (153 * (__mth + (__mth > 2 ? -3 : 9)) + 2) / 5 + __dy-1; // [0, 365]
104 const unsigned __doe = __yoe * 365 + __yoe/4 - __yoe/100 + __doy; // [0, 146096]
105 return days{__era * 146097 + static_cast<int>(__doe) - 719468};
106}
107
108_LIBCPP_HIDE_FROM_ABI inline constexpr
109bool operator==(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
110{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); }
111
112_LIBCPP_HIDE_FROM_ABI inline constexpr
113bool operator!=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
114{ return !(__lhs == __rhs); }
115
116_LIBCPP_HIDE_FROM_ABI inline constexpr
117bool operator< (const year_month_day& __lhs, const year_month_day& __rhs) noexcept
118{
119 if (__lhs.year() < __rhs.year()) return true;
120 if (__lhs.year() > __rhs.year()) return false;
121 if (__lhs.month() < __rhs.month()) return true;
122 if (__lhs.month() > __rhs.month()) return false;
123 return __lhs.day() < __rhs.day();
124}
125
126_LIBCPP_HIDE_FROM_ABI inline constexpr
127bool operator> (const year_month_day& __lhs, const year_month_day& __rhs) noexcept
128{ return __rhs < __lhs; }
129
130_LIBCPP_HIDE_FROM_ABI inline constexpr
131bool operator<=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
132{ return !(__rhs < __lhs);}
133
134_LIBCPP_HIDE_FROM_ABI inline constexpr
135bool operator>=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
136{ return !(__lhs < __rhs); }
137
138_LIBCPP_HIDE_FROM_ABI inline constexpr
139year_month_day operator/(const year_month& __lhs, const day& __rhs) noexcept
140{ return year_month_day{__lhs.year(), __lhs.month(), __rhs}; }
141
142_LIBCPP_HIDE_FROM_ABI inline constexpr
143year_month_day operator/(const year_month& __lhs, int __rhs) noexcept
144{ return __lhs / day(__rhs); }
145
146_LIBCPP_HIDE_FROM_ABI inline constexpr
147year_month_day operator/(const year& __lhs, const month_day& __rhs) noexcept
148{ return __lhs / __rhs.month() / __rhs.day(); }
149
150_LIBCPP_HIDE_FROM_ABI inline constexpr
151year_month_day operator/(int __lhs, const month_day& __rhs) noexcept
152{ return year(__lhs) / __rhs; }
153
154_LIBCPP_HIDE_FROM_ABI inline constexpr
155year_month_day operator/(const month_day& __lhs, const year& __rhs) noexcept
156{ return __rhs / __lhs; }
157
158_LIBCPP_HIDE_FROM_ABI inline constexpr
159year_month_day operator/(const month_day& __lhs, int __rhs) noexcept
160{ return year(__rhs) / __lhs; }
161
162
163_LIBCPP_HIDE_FROM_ABI inline constexpr
164year_month_day operator+(const year_month_day& __lhs, const months& __rhs) noexcept
165{ return (__lhs.year()/__lhs.month() + __rhs)/__lhs.day(); }
166
167_LIBCPP_HIDE_FROM_ABI inline constexpr
168year_month_day operator+(const months& __lhs, const year_month_day& __rhs) noexcept
169{ return __rhs + __lhs; }
170
171_LIBCPP_HIDE_FROM_ABI inline constexpr
172year_month_day operator-(const year_month_day& __lhs, const months& __rhs) noexcept
173{ return __lhs + -__rhs; }
174
175_LIBCPP_HIDE_FROM_ABI inline constexpr
176year_month_day operator+(const year_month_day& __lhs, const years& __rhs) noexcept
177{ return (__lhs.year() + __rhs) / __lhs.month() / __lhs.day(); }
178
179_LIBCPP_HIDE_FROM_ABI inline constexpr
180year_month_day operator+(const years& __lhs, const year_month_day& __rhs) noexcept
181{ return __rhs + __lhs; }
182
183_LIBCPP_HIDE_FROM_ABI inline constexpr
184year_month_day operator-(const year_month_day& __lhs, const years& __rhs) noexcept
185{ return __lhs + -__rhs; }
186
187_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day& year_month_day::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
188_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day& year_month_day::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
189_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day& year_month_day::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; }
190_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day& year_month_day::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; }
191
192class year_month_day_last {
193private:
194 chrono::year __y;
195 chrono::month_day_last __mdl;
196public:
197 _LIBCPP_HIDE_FROM_ABI constexpr year_month_day_last(const year& __yval, const month_day_last& __mdlval) noexcept
198 : __y{__yval}, __mdl{__mdlval} {}
199
200 _LIBCPP_HIDE_FROM_ABI constexpr year_month_day_last& operator+=(const months& __m) noexcept;
201 _LIBCPP_HIDE_FROM_ABI constexpr year_month_day_last& operator-=(const months& __m) noexcept;
202 _LIBCPP_HIDE_FROM_ABI constexpr year_month_day_last& operator+=(const years& __y) noexcept;
203 _LIBCPP_HIDE_FROM_ABI constexpr year_month_day_last& operator-=(const years& __y) noexcept;
204
205 _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::year year() const noexcept { return __y; }
206 _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __mdl.month(); }
207 _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month_day_last month_day_last() const noexcept { return __mdl; }
208 _LIBCPP_HIDE_FROM_ABI constexpr chrono::day day() const noexcept;
209 _LIBCPP_HIDE_FROM_ABI inline constexpr operator sys_days() const noexcept { return sys_days{year()/month()/day()}; }
210 _LIBCPP_HIDE_FROM_ABI inline explicit constexpr operator local_days() const noexcept { return local_days{year()/month()/day()}; }
211 _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __y.ok() && __mdl.ok(); }
212};
213
214_LIBCPP_HIDE_FROM_ABI inline constexpr
215chrono::day year_month_day_last::day() const noexcept
216{
217 constexpr chrono::day __d[] =
218 {
219 chrono::day(31), chrono::day(28), chrono::day(31),
220 chrono::day(30), chrono::day(31), chrono::day(30),
221 chrono::day(31), chrono::day(31), chrono::day(30),
222 chrono::day(31), chrono::day(30), chrono::day(31)
223 };
224 return (month() != February || !__y.is_leap()) && month().ok() ?
225 __d[static_cast<unsigned>(month()) - 1] : chrono::day{29};
226}
227
228_LIBCPP_HIDE_FROM_ABI inline constexpr
229bool operator==(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
230{ return __lhs.year() == __rhs.year() && __lhs.month_day_last() == __rhs.month_day_last(); }
231
232_LIBCPP_HIDE_FROM_ABI inline constexpr
233bool operator!=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
234{ return !(__lhs == __rhs); }
235
236_LIBCPP_HIDE_FROM_ABI inline constexpr
237bool operator< (const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
238{
239 if (__lhs.year() < __rhs.year()) return true;
240 if (__lhs.year() > __rhs.year()) return false;
241 return __lhs.month_day_last() < __rhs.month_day_last();
242}
243
244_LIBCPP_HIDE_FROM_ABI inline constexpr
245bool operator> (const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
246{ return __rhs < __lhs; }
247
248_LIBCPP_HIDE_FROM_ABI inline constexpr
249bool operator<=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
250{ return !(__rhs < __lhs);}
251
252_LIBCPP_HIDE_FROM_ABI inline constexpr
253bool operator>=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
254{ return !(__lhs < __rhs); }
255
256_LIBCPP_HIDE_FROM_ABI inline constexpr
257year_month_day_last operator/(const year_month& __lhs, last_spec) noexcept
258{ return year_month_day_last{__lhs.year(), month_day_last{__lhs.month()}}; }
259
260_LIBCPP_HIDE_FROM_ABI inline constexpr
261year_month_day_last operator/(const year& __lhs, const month_day_last& __rhs) noexcept
262{ return year_month_day_last{__lhs, __rhs}; }
263
264_LIBCPP_HIDE_FROM_ABI inline constexpr
265year_month_day_last operator/(int __lhs, const month_day_last& __rhs) noexcept
266{ return year_month_day_last{year{__lhs}, __rhs}; }
267
268_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last
269operator/(const month_day_last& __lhs, const year& __rhs) noexcept
270{ return __rhs / __lhs; }
271
272_LIBCPP_HIDE_FROM_ABI inline constexpr
273year_month_day_last operator/(const month_day_last& __lhs, int __rhs) noexcept
274{ return year{__rhs} / __lhs; }
275
276
277_LIBCPP_HIDE_FROM_ABI inline constexpr
278year_month_day_last operator+(const year_month_day_last& __lhs, const months& __rhs) noexcept
279{ return (__lhs.year() / __lhs.month() + __rhs) / last; }
280
281_LIBCPP_HIDE_FROM_ABI inline constexpr
282year_month_day_last operator+(const months& __lhs, const year_month_day_last& __rhs) noexcept
283{ return __rhs + __lhs; }
284
285_LIBCPP_HIDE_FROM_ABI inline constexpr
286year_month_day_last operator-(const year_month_day_last& __lhs, const months& __rhs) noexcept
287{ return __lhs + (-__rhs); }
288
289_LIBCPP_HIDE_FROM_ABI inline constexpr
290year_month_day_last operator+(const year_month_day_last& __lhs, const years& __rhs) noexcept
291{ return year_month_day_last{__lhs.year() + __rhs, __lhs.month_day_last()}; }
292
293_LIBCPP_HIDE_FROM_ABI inline constexpr
294year_month_day_last operator+(const years& __lhs, const year_month_day_last& __rhs) noexcept
295{ return __rhs + __lhs; }
296
297_LIBCPP_HIDE_FROM_ABI inline constexpr
298year_month_day_last operator-(const year_month_day_last& __lhs, const years& __rhs) noexcept
299{ return __lhs + (-__rhs); }
300
301_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last& year_month_day_last::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
302_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last& year_month_day_last::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
303_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last& year_month_day_last::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; }
304_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last& year_month_day_last::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; }
305
306_LIBCPP_HIDE_FROM_ABI inline constexpr
307year_month_day::year_month_day(const year_month_day_last& __ymdl) noexcept
308 : __y{__ymdl.year()}, __m{__ymdl.month()}, __d{__ymdl.day()} {}
309
310_LIBCPP_HIDE_FROM_ABI inline constexpr
311bool year_month_day::ok() const noexcept
312{
313 if (!__y.ok() || !__m.ok()) return false;
314 return chrono::day{1} <= __d && __d <= (__y / __m / last).day();
315}
316
317} // namespace chrono
318
319_LIBCPP_END_NAMESPACE_STD
320
321#endif // _LIBCPP_STD_VER > 17
322
323#endif // _LIBCPP___CHRONO_YEAR_MONTH_DAY_H
lib/libcxx/include/__chrono/year_month_weekday.h created+255
......@@ -0,0 +1,255 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___CHRONO_YEAR_MONTH_WEEKDAY_H
11#define _LIBCPP___CHRONO_YEAR_MONTH_WEEKDAY_H
12
13#include <__chrono/calendar.h>
14#include <__chrono/day.h>
15#include <__chrono/duration.h>
16#include <__chrono/month.h>
17#include <__chrono/month_weekday.h>
18#include <__chrono/system_clock.h>
19#include <__chrono/time_point.h>
20#include <__chrono/weekday.h>
21#include <__chrono/year.h>
22#include <__chrono/year_month.h>
23#include <__chrono/year_month_day.h>
24#include <__config>
25
26#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
27# pragma GCC system_header
28#endif
29
30#if _LIBCPP_STD_VER > 17
31
32_LIBCPP_BEGIN_NAMESPACE_STD
33
34namespace chrono
35{
36
37class year_month_weekday {
38 chrono::year __y;
39 chrono::month __m;
40 chrono::weekday_indexed __wdi;
41public:
42 _LIBCPP_HIDE_FROM_ABI year_month_weekday() = default;
43 _LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday(const chrono::year& __yval, const chrono::month& __mval,
44 const chrono::weekday_indexed& __wdival) noexcept
45 : __y{__yval}, __m{__mval}, __wdi{__wdival} {}
46 _LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday(const sys_days& __sysd) noexcept
47 : year_month_weekday(__from_days(__sysd.time_since_epoch())) {}
48 _LIBCPP_HIDE_FROM_ABI inline explicit constexpr year_month_weekday(const local_days& __locd) noexcept
49 : year_month_weekday(__from_days(__locd.time_since_epoch())) {}
50 _LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday& operator+=(const months&) noexcept;
51 _LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday& operator-=(const months&) noexcept;
52 _LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday& operator+=(const years&) noexcept;
53 _LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday& operator-=(const years&) noexcept;
54
55 _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::year year() const noexcept { return __y; }
56 _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m; }
57 _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday weekday() const noexcept { return __wdi.weekday(); }
58 _LIBCPP_HIDE_FROM_ABI inline constexpr unsigned index() const noexcept { return __wdi.index(); }
59 _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { return __wdi; }
60
61 _LIBCPP_HIDE_FROM_ABI inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; }
62 _LIBCPP_HIDE_FROM_ABI inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; }
63 _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept
64 {
65 if (!__y.ok() || !__m.ok() || !__wdi.ok()) return false;
66 if (__wdi.index() <= 4) return true;
67 auto __nth_weekday_day =
68 __wdi.weekday() -
69 chrono::weekday{static_cast<sys_days>(__y / __m / 1)} +
70 days{(__wdi.index() - 1) * 7 + 1};
71 return static_cast<unsigned>(__nth_weekday_day.count()) <=
72 static_cast<unsigned>((__y / __m / last).day());
73 }
74
75 _LIBCPP_HIDE_FROM_ABI static constexpr year_month_weekday __from_days(days __d) noexcept;
76 _LIBCPP_HIDE_FROM_ABI constexpr days __to_days() const noexcept;
77};
78
79_LIBCPP_HIDE_FROM_ABI inline constexpr
80year_month_weekday year_month_weekday::__from_days(days __d) noexcept
81{
82 const sys_days __sysd{__d};
83 const chrono::weekday __wd = chrono::weekday(__sysd);
84 const year_month_day __ymd = year_month_day(__sysd);
85 return year_month_weekday{__ymd.year(), __ymd.month(),
86 __wd[(static_cast<unsigned>(__ymd.day())-1)/7+1]};
87}
88
89_LIBCPP_HIDE_FROM_ABI inline constexpr
90days year_month_weekday::__to_days() const noexcept
91{
92 const sys_days __sysd = sys_days(__y/__m/1);
93 return (__sysd + (__wdi.weekday() - chrono::weekday(__sysd) + days{(__wdi.index()-1)*7}))
94 .time_since_epoch();
95}
96
97_LIBCPP_HIDE_FROM_ABI inline constexpr
98bool operator==(const year_month_weekday& __lhs, const year_month_weekday& __rhs) noexcept
99{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.weekday_indexed() == __rhs.weekday_indexed(); }
100
101_LIBCPP_HIDE_FROM_ABI inline constexpr
102bool operator!=(const year_month_weekday& __lhs, const year_month_weekday& __rhs) noexcept
103{ return !(__lhs == __rhs); }
104
105_LIBCPP_HIDE_FROM_ABI inline constexpr
106year_month_weekday operator/(const year_month& __lhs, const weekday_indexed& __rhs) noexcept
107{ return year_month_weekday{__lhs.year(), __lhs.month(), __rhs}; }
108
109_LIBCPP_HIDE_FROM_ABI inline constexpr
110year_month_weekday operator/(const year& __lhs, const month_weekday& __rhs) noexcept
111{ return year_month_weekday{__lhs, __rhs.month(), __rhs.weekday_indexed()}; }
112
113_LIBCPP_HIDE_FROM_ABI inline constexpr
114year_month_weekday operator/(int __lhs, const month_weekday& __rhs) noexcept
115{ return year(__lhs) / __rhs; }
116
117_LIBCPP_HIDE_FROM_ABI inline constexpr
118year_month_weekday operator/(const month_weekday& __lhs, const year& __rhs) noexcept
119{ return __rhs / __lhs; }
120
121_LIBCPP_HIDE_FROM_ABI inline constexpr
122year_month_weekday operator/(const month_weekday& __lhs, int __rhs) noexcept
123{ return year(__rhs) / __lhs; }
124
125
126_LIBCPP_HIDE_FROM_ABI inline constexpr
127year_month_weekday operator+(const year_month_weekday& __lhs, const months& __rhs) noexcept
128{ return (__lhs.year() / __lhs.month() + __rhs) / __lhs.weekday_indexed(); }
129
130_LIBCPP_HIDE_FROM_ABI inline constexpr
131year_month_weekday operator+(const months& __lhs, const year_month_weekday& __rhs) noexcept
132{ return __rhs + __lhs; }
133
134_LIBCPP_HIDE_FROM_ABI inline constexpr
135year_month_weekday operator-(const year_month_weekday& __lhs, const months& __rhs) noexcept
136{ return __lhs + (-__rhs); }
137
138_LIBCPP_HIDE_FROM_ABI inline constexpr
139year_month_weekday operator+(const year_month_weekday& __lhs, const years& __rhs) noexcept
140{ return year_month_weekday{__lhs.year() + __rhs, __lhs.month(), __lhs.weekday_indexed()}; }
141
142_LIBCPP_HIDE_FROM_ABI inline constexpr
143year_month_weekday operator+(const years& __lhs, const year_month_weekday& __rhs) noexcept
144{ return __rhs + __lhs; }
145
146_LIBCPP_HIDE_FROM_ABI inline constexpr
147year_month_weekday operator-(const year_month_weekday& __lhs, const years& __rhs) noexcept
148{ return __lhs + (-__rhs); }
149
150
151_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday& year_month_weekday::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
152_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday& year_month_weekday::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
153_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday& year_month_weekday::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; }
154_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday& year_month_weekday::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; }
155
156class year_month_weekday_last {
157private:
158 chrono::year __y;
159 chrono::month __m;
160 chrono::weekday_last __wdl;
161public:
162 _LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday_last(const chrono::year& __yval, const chrono::month& __mval,
163 const chrono::weekday_last& __wdlval) noexcept
164 : __y{__yval}, __m{__mval}, __wdl{__wdlval} {}
165 _LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday_last& operator+=(const months& __dm) noexcept;
166 _LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday_last& operator-=(const months& __dm) noexcept;
167 _LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday_last& operator+=(const years& __dy) noexcept;
168 _LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday_last& operator-=(const years& __dy) noexcept;
169
170 _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::year year() const noexcept { return __y; }
171 _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m; }
172 _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday weekday() const noexcept { return __wdl.weekday(); }
173 _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday_last weekday_last() const noexcept { return __wdl; }
174 _LIBCPP_HIDE_FROM_ABI inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; }
175 _LIBCPP_HIDE_FROM_ABI inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; }
176 _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __y.ok() && __m.ok() && __wdl.ok(); }
177
178 _LIBCPP_HIDE_FROM_ABI constexpr days __to_days() const noexcept;
179
180};
181
182_LIBCPP_HIDE_FROM_ABI inline constexpr
183days year_month_weekday_last::__to_days() const noexcept
184{
185 const sys_days __last = sys_days{__y/__m/last};
186 return (__last - (chrono::weekday{__last} - __wdl.weekday())).time_since_epoch();
187
188}
189
190_LIBCPP_HIDE_FROM_ABI inline constexpr
191bool operator==(const year_month_weekday_last& __lhs, const year_month_weekday_last& __rhs) noexcept
192{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last(); }
193
194_LIBCPP_HIDE_FROM_ABI inline constexpr
195bool operator!=(const year_month_weekday_last& __lhs, const year_month_weekday_last& __rhs) noexcept
196{ return !(__lhs == __rhs); }
197
198
199_LIBCPP_HIDE_FROM_ABI inline constexpr
200year_month_weekday_last operator/(const year_month& __lhs, const weekday_last& __rhs) noexcept
201{ return year_month_weekday_last{__lhs.year(), __lhs.month(), __rhs}; }
202
203_LIBCPP_HIDE_FROM_ABI inline constexpr
204year_month_weekday_last operator/(const year& __lhs, const month_weekday_last& __rhs) noexcept
205{ return year_month_weekday_last{__lhs, __rhs.month(), __rhs.weekday_last()}; }
206
207_LIBCPP_HIDE_FROM_ABI inline constexpr
208year_month_weekday_last operator/(int __lhs, const month_weekday_last& __rhs) noexcept
209{ return year(__lhs) / __rhs; }
210
211_LIBCPP_HIDE_FROM_ABI inline constexpr
212year_month_weekday_last operator/(const month_weekday_last& __lhs, const year& __rhs) noexcept
213{ return __rhs / __lhs; }
214
215_LIBCPP_HIDE_FROM_ABI inline constexpr
216year_month_weekday_last operator/(const month_weekday_last& __lhs, int __rhs) noexcept
217{ return year(__rhs) / __lhs; }
218
219
220_LIBCPP_HIDE_FROM_ABI inline constexpr
221year_month_weekday_last operator+(const year_month_weekday_last& __lhs, const months& __rhs) noexcept
222{ return (__lhs.year() / __lhs.month() + __rhs) / __lhs.weekday_last(); }
223
224_LIBCPP_HIDE_FROM_ABI inline constexpr
225year_month_weekday_last operator+(const months& __lhs, const year_month_weekday_last& __rhs) noexcept
226{ return __rhs + __lhs; }
227
228_LIBCPP_HIDE_FROM_ABI inline constexpr
229year_month_weekday_last operator-(const year_month_weekday_last& __lhs, const months& __rhs) noexcept
230{ return __lhs + (-__rhs); }
231
232_LIBCPP_HIDE_FROM_ABI inline constexpr
233year_month_weekday_last operator+(const year_month_weekday_last& __lhs, const years& __rhs) noexcept
234{ return year_month_weekday_last{__lhs.year() + __rhs, __lhs.month(), __lhs.weekday_last()}; }
235
236_LIBCPP_HIDE_FROM_ABI inline constexpr
237year_month_weekday_last operator+(const years& __lhs, const year_month_weekday_last& __rhs) noexcept
238{ return __rhs + __lhs; }
239
240_LIBCPP_HIDE_FROM_ABI inline constexpr
241year_month_weekday_last operator-(const year_month_weekday_last& __lhs, const years& __rhs) noexcept
242{ return __lhs + (-__rhs); }
243
244_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last& year_month_weekday_last::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
245_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last& year_month_weekday_last::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
246_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last& year_month_weekday_last::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; }
247_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last& year_month_weekday_last::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; }
248
249} // namespace chrono
250
251_LIBCPP_END_NAMESPACE_STD
252
253#endif // _LIBCPP_STD_VER > 17
254
255#endif // _LIBCPP___CHRONO_YEAR_MONTH_WEEKDAY_H
lib/libcxx/include/__compare/common_comparison_category.h+1-1
......@@ -14,7 +14,7 @@
1414#include <type_traits>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
17# pragma GCC system_header
1818#endif
1919
2020_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__compare/compare_partial_order_fallback.h+3-3
......@@ -17,12 +17,12 @@
1717#include <type_traits>
1818
1919#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
20#pragma GCC system_header
20# pragma GCC system_header
2121#endif
2222
2323_LIBCPP_BEGIN_NAMESPACE_STD
2424
25#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
25#if _LIBCPP_STD_VER > 17
2626
2727// [cmp.alg]
2828namespace __compare_partial_order_fallback {
......@@ -66,7 +66,7 @@ inline namespace __cpo {
6666 inline constexpr auto compare_partial_order_fallback = __compare_partial_order_fallback::__fn{};
6767} // namespace __cpo
6868
69#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
69#endif // _LIBCPP_STD_VER > 17
7070
7171_LIBCPP_END_NAMESPACE_STD
7272
lib/libcxx/include/__compare/compare_strong_order_fallback.h+3-3
......@@ -17,12 +17,12 @@
1717#include <type_traits>
1818
1919#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
20#pragma GCC system_header
20# pragma GCC system_header
2121#endif
2222
2323_LIBCPP_BEGIN_NAMESPACE_STD
2424
25#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
25#if _LIBCPP_STD_VER > 17
2626
2727// [cmp.alg]
2828namespace __compare_strong_order_fallback {
......@@ -63,7 +63,7 @@ inline namespace __cpo {
6363 inline constexpr auto compare_strong_order_fallback = __compare_strong_order_fallback::__fn{};
6464} // namespace __cpo
6565
66#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
66#endif // _LIBCPP_STD_VER > 17
6767
6868_LIBCPP_END_NAMESPACE_STD
6969
lib/libcxx/include/__compare/compare_three_way.h+3-3
......@@ -15,12 +15,12 @@
1515#include <__utility/forward.h>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
2222
23#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
23#if _LIBCPP_STD_VER > 17
2424
2525struct _LIBCPP_TEMPLATE_VIS compare_three_way
2626{
......@@ -34,7 +34,7 @@ struct _LIBCPP_TEMPLATE_VIS compare_three_way
3434 using is_transparent = void;
3535};
3636
37#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
37#endif // _LIBCPP_STD_VER > 17
3838
3939_LIBCPP_END_NAMESPACE_STD
4040
lib/libcxx/include/__compare/compare_three_way_result.h+1-1
......@@ -13,7 +13,7 @@
1313#include <type_traits>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16#pragma GCC system_header
16# pragma GCC system_header
1717#endif
1818
1919_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__compare/compare_weak_order_fallback.h+3-3
......@@ -17,12 +17,12 @@
1717#include <type_traits>
1818
1919#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
20#pragma GCC system_header
20# pragma GCC system_header
2121#endif
2222
2323_LIBCPP_BEGIN_NAMESPACE_STD
2424
25#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
25#if _LIBCPP_STD_VER > 17
2626
2727// [cmp.alg]
2828namespace __compare_weak_order_fallback {
......@@ -63,7 +63,7 @@ inline namespace __cpo {
6363 inline constexpr auto compare_weak_order_fallback = __compare_weak_order_fallback::__fn{};
6464} // namespace __cpo
6565
66#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
66#endif // _LIBCPP_STD_VER > 17
6767
6868_LIBCPP_END_NAMESPACE_STD
6969
lib/libcxx/include/__compare/is_eq.h+1-1
......@@ -13,7 +13,7 @@
1313#include <__config>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16#pragma GCC system_header
16# pragma GCC system_header
1717#endif
1818
1919_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__compare/ordering.h+1-1
......@@ -13,7 +13,7 @@
1313#include <type_traits>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16#pragma GCC system_header
16# pragma GCC system_header
1717#endif
1818
1919_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__compare/partial_order.h+3-3
......@@ -18,12 +18,12 @@
1818#include <type_traits>
1919
2020#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
21#pragma GCC system_header
21# pragma GCC system_header
2222#endif
2323
2424_LIBCPP_BEGIN_NAMESPACE_STD
2525
26#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
26#if _LIBCPP_STD_VER > 17
2727
2828// [cmp.alg]
2929namespace __partial_order {
......@@ -64,7 +64,7 @@ inline namespace __cpo {
6464 inline constexpr auto partial_order = __partial_order::__fn{};
6565} // namespace __cpo
6666
67#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
67#endif // _LIBCPP_STD_VER > 17
6868
6969_LIBCPP_END_NAMESPACE_STD
7070
lib/libcxx/include/__compare/strong_order.h+3-3
......@@ -21,7 +21,7 @@
2121#include <type_traits>
2222
2323#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
24#pragma GCC system_header
24# pragma GCC system_header
2525#endif
2626
2727_LIBCPP_PUSH_MACROS
......@@ -29,7 +29,7 @@ _LIBCPP_PUSH_MACROS
2929
3030_LIBCPP_BEGIN_NAMESPACE_STD
3131
32#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
32#if _LIBCPP_STD_VER > 17
3333
3434// [cmp.alg]
3535namespace __strong_order {
......@@ -127,7 +127,7 @@ inline namespace __cpo {
127127 inline constexpr auto strong_order = __strong_order::__fn{};
128128} // namespace __cpo
129129
130#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
130#endif // _LIBCPP_STD_VER > 17
131131
132132_LIBCPP_END_NAMESPACE_STD
133133
lib/libcxx/include/__compare/synth_three_way.h+4-4
......@@ -16,12 +16,12 @@
1616#include <__utility/declval.h>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
19# pragma GCC system_header
2020#endif
2121
2222_LIBCPP_BEGIN_NAMESPACE_STD
2323
24#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
24#if _LIBCPP_STD_VER > 17
2525
2626// [expos.only.func]
2727
......@@ -42,9 +42,9 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr auto __synth_three_way =
4242 };
4343
4444template <class _Tp, class _Up = _Tp>
45using __synth_three_way_result = decltype(__synth_three_way(declval<_Tp&>(), declval<_Up&>()));
45using __synth_three_way_result = decltype(std::__synth_three_way(declval<_Tp&>(), declval<_Up&>()));
4646
47#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
47#endif // _LIBCPP_STD_VER > 17
4848
4949_LIBCPP_END_NAMESPACE_STD
5050
lib/libcxx/include/__compare/three_way_comparable.h+3-3
......@@ -19,12 +19,12 @@
1919#include <type_traits>
2020
2121#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22#pragma GCC system_header
22# pragma GCC system_header
2323#endif
2424
2525_LIBCPP_BEGIN_NAMESPACE_STD
2626
27#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
27#if _LIBCPP_STD_VER > 17
2828
2929template<class _Tp, class _Cat>
3030concept __compares_as =
......@@ -51,7 +51,7 @@ concept three_way_comparable_with =
5151 { __u <=> __t } -> __compares_as<_Cat>;
5252 };
5353
54#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
54#endif // _LIBCPP_STD_VER > 17
5555
5656_LIBCPP_END_NAMESPACE_STD
5757
lib/libcxx/include/__compare/weak_order.h+3-3
......@@ -19,12 +19,12 @@
1919#include <type_traits>
2020
2121#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
22#pragma GCC system_header
22# pragma GCC system_header
2323#endif
2424
2525_LIBCPP_BEGIN_NAMESPACE_STD
2626
27#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
27#if _LIBCPP_STD_VER > 17
2828
2929// [cmp.alg]
3030namespace __weak_order {
......@@ -93,7 +93,7 @@ inline namespace __cpo {
9393 inline constexpr auto weak_order = __weak_order::__fn{};
9494} // namespace __cpo
9595
96#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
96#endif // _LIBCPP_STD_VER > 17
9797
9898_LIBCPP_END_NAMESPACE_STD
9999
lib/libcxx/include/__concepts/arithmetic.h+5-3
......@@ -10,15 +10,17 @@
1010#define _LIBCPP___CONCEPTS_ARITHMETIC_H
1111
1212#include <__config>
13#include <__type_traits/is_signed_integer.h>
14#include <__type_traits/is_unsigned_integer.h>
1315#include <type_traits>
1416
1517#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16#pragma GCC system_header
18# pragma GCC system_header
1719#endif
1820
1921_LIBCPP_BEGIN_NAMESPACE_STD
2022
21#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
23#if _LIBCPP_STD_VER > 17
2224
2325// [concepts.arithmetic], arithmetic concepts
2426
......@@ -41,7 +43,7 @@ concept __libcpp_unsigned_integer = __libcpp_is_unsigned_integer<_Tp>::value;
4143template <class _Tp>
4244concept __libcpp_signed_integer = __libcpp_is_signed_integer<_Tp>::value;
4345
44#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
46#endif // _LIBCPP_STD_VER > 17
4547
4648_LIBCPP_END_NAMESPACE_STD
4749
lib/libcxx/include/__concepts/assignable.h+3-3
......@@ -16,12 +16,12 @@
1616#include <type_traits>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
19# pragma GCC system_header
2020#endif
2121
2222_LIBCPP_BEGIN_NAMESPACE_STD
2323
24#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
24#if _LIBCPP_STD_VER > 17
2525
2626// [concept.assignable]
2727
......@@ -33,7 +33,7 @@ concept assignable_from =
3333 { __lhs = _VSTD::forward<_Rhs>(__rhs) } -> same_as<_Lhs>;
3434 };
3535
36#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
36#endif // _LIBCPP_STD_VER > 17
3737
3838_LIBCPP_END_NAMESPACE_STD
3939
lib/libcxx/include/__concepts/boolean_testable.h+3-3
......@@ -14,12 +14,12 @@
1414#include <__utility/forward.h>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
17# pragma GCC system_header
1818#endif
1919
2020_LIBCPP_BEGIN_NAMESPACE_STD
2121
22#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
22#if _LIBCPP_STD_VER > 17
2323
2424// [concepts.booleantestable]
2525
......@@ -31,7 +31,7 @@ concept __boolean_testable = __boolean_testable_impl<_Tp> && requires(_Tp&& __t)
3131 { !_VSTD::forward<_Tp>(__t) } -> __boolean_testable_impl;
3232};
3333
34#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
34#endif // _LIBCPP_STD_VER > 17
3535
3636_LIBCPP_END_NAMESPACE_STD
3737
lib/libcxx/include/__concepts/class_or_enum.h+4-3
......@@ -13,12 +13,12 @@
1313#include <type_traits>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16#pragma GCC system_header
16# pragma GCC system_header
1717#endif
1818
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
21#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
21#if _LIBCPP_STD_VER > 17
2222
2323// Whether a type is a class type or enumeration type according to the Core wording.
2424
......@@ -26,10 +26,11 @@ template<class _Tp>
2626concept __class_or_enum = is_class_v<_Tp> || is_union_v<_Tp> || is_enum_v<_Tp>;
2727
2828// Work around Clang bug https://llvm.org/PR52970
29// TODO: remove this workaround once libc++ no longer has to support Clang 13 (it was fixed in Clang 14).
2930template<class _Tp>
3031concept __workaround_52970 = is_class_v<__uncvref_t<_Tp>> || is_union_v<__uncvref_t<_Tp>>;
3132
32#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
33#endif // _LIBCPP_STD_VER > 17
3334
3435_LIBCPP_END_NAMESPACE_STD
3536
lib/libcxx/include/__concepts/common_reference_with.h+3-3
......@@ -15,12 +15,12 @@
1515#include <type_traits>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
2222
23#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
23#if _LIBCPP_STD_VER > 17
2424
2525// [concept.commonref]
2626
......@@ -30,7 +30,7 @@ concept common_reference_with =
3030 convertible_to<_Tp, common_reference_t<_Tp, _Up>> &&
3131 convertible_to<_Up, common_reference_t<_Tp, _Up>>;
3232
33#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
33#endif // _LIBCPP_STD_VER > 17
3434
3535_LIBCPP_END_NAMESPACE_STD
3636
lib/libcxx/include/__concepts/common_with.h+3-3
......@@ -15,12 +15,12 @@
1515#include <type_traits>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
2222
23#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
23#if _LIBCPP_STD_VER > 17
2424
2525// [concept.common]
2626
......@@ -40,7 +40,7 @@ concept common_with =
4040 add_lvalue_reference_t<const _Tp>,
4141 add_lvalue_reference_t<const _Up>>>;
4242
43#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
43#endif // _LIBCPP_STD_VER > 17
4444
4545_LIBCPP_END_NAMESPACE_STD
4646
lib/libcxx/include/__concepts/constructible.h+3-3
......@@ -15,12 +15,12 @@
1515#include <type_traits>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
2222
23#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
23#if _LIBCPP_STD_VER > 17
2424
2525// [concept.constructible]
2626template<class _Tp, class... _Args>
......@@ -49,7 +49,7 @@ concept copy_constructible =
4949 constructible_from<_Tp, const _Tp&> && convertible_to<const _Tp&, _Tp> &&
5050 constructible_from<_Tp, const _Tp> && convertible_to<const _Tp, _Tp>;
5151
52#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
52#endif // _LIBCPP_STD_VER > 17
5353
5454_LIBCPP_END_NAMESPACE_STD
5555
lib/libcxx/include/__concepts/convertible_to.h+3-3
......@@ -14,12 +14,12 @@
1414#include <type_traits>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
17# pragma GCC system_header
1818#endif
1919
2020_LIBCPP_BEGIN_NAMESPACE_STD
2121
22#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
22#if _LIBCPP_STD_VER > 17
2323
2424// [concept.convertible]
2525
......@@ -30,7 +30,7 @@ concept convertible_to =
3030 static_cast<_To>(declval<_From>());
3131 };
3232
33#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
33#endif // _LIBCPP_STD_VER > 17
3434
3535_LIBCPP_END_NAMESPACE_STD
3636
lib/libcxx/include/__concepts/copyable.h+3-3
......@@ -15,12 +15,12 @@
1515#include <__config>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
2222
23#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
23#if _LIBCPP_STD_VER > 17
2424
2525// [concepts.object]
2626
......@@ -32,7 +32,7 @@ concept copyable =
3232 assignable_from<_Tp&, const _Tp&> &&
3333 assignable_from<_Tp&, const _Tp>;
3434
35#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
35#endif // _LIBCPP_STD_VER > 17
3636
3737_LIBCPP_END_NAMESPACE_STD
3838
lib/libcxx/include/__concepts/derived_from.h+3-3
......@@ -13,12 +13,12 @@
1313#include <type_traits>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16#pragma GCC system_header
16# pragma GCC system_header
1717#endif
1818
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
21#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
21#if _LIBCPP_STD_VER > 17
2222
2323// [concept.derived]
2424
......@@ -27,7 +27,7 @@ concept derived_from =
2727 is_base_of_v<_Bp, _Dp> &&
2828 is_convertible_v<const volatile _Dp*, const volatile _Bp*>;
2929
30#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
30#endif // _LIBCPP_STD_VER > 17
3131
3232_LIBCPP_END_NAMESPACE_STD
3333
lib/libcxx/include/__concepts/destructible.h+3-3
......@@ -13,19 +13,19 @@
1313#include <type_traits>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16#pragma GCC system_header
16# pragma GCC system_header
1717#endif
1818
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
21#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
21#if _LIBCPP_STD_VER > 17
2222
2323// [concept.destructible]
2424
2525template<class _Tp>
2626concept destructible = is_nothrow_destructible_v<_Tp>;
2727
28#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
28#endif // _LIBCPP_STD_VER > 17
2929
3030_LIBCPP_END_NAMESPACE_STD
3131
lib/libcxx/include/__concepts/different_from.h+3-3
......@@ -14,17 +14,17 @@
1414#include <type_traits>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
17# pragma GCC system_header
1818#endif
1919
2020_LIBCPP_BEGIN_NAMESPACE_STD
2121
22#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
22#if _LIBCPP_STD_VER > 17
2323
2424template<class _Tp, class _Up>
2525concept __different_from = !same_as<remove_cvref_t<_Tp>, remove_cvref_t<_Up>>;
2626
27#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
27#endif // _LIBCPP_STD_VER > 17
2828
2929_LIBCPP_END_NAMESPACE_STD
3030
lib/libcxx/include/__concepts/equality_comparable.h+3-3
......@@ -15,12 +15,12 @@
1515#include <type_traits>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
2222
23#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
23#if _LIBCPP_STD_VER > 17
2424
2525// [concept.equalitycomparable]
2626
......@@ -46,7 +46,7 @@ concept equality_comparable_with =
4646 __make_const_lvalue_ref<_Up>>> &&
4747 __weakly_equality_comparable_with<_Tp, _Up>;
4848
49#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
49#endif // _LIBCPP_STD_VER > 17
5050
5151_LIBCPP_END_NAMESPACE_STD
5252
lib/libcxx/include/__concepts/invocable.h+3-3
......@@ -15,12 +15,12 @@
1515#include <type_traits>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
2222
23#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
23#if _LIBCPP_STD_VER > 17
2424
2525// [concept.invocable]
2626
......@@ -34,7 +34,7 @@ concept invocable = requires(_Fn&& __fn, _Args&&... __args) {
3434template<class _Fn, class... _Args>
3535concept regular_invocable = invocable<_Fn, _Args...>;
3636
37#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
37#endif // _LIBCPP_STD_VER > 17
3838
3939_LIBCPP_END_NAMESPACE_STD
4040
lib/libcxx/include/__concepts/movable.h+3-3
......@@ -16,12 +16,12 @@
1616#include <type_traits>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
19# pragma GCC system_header
2020#endif
2121
2222_LIBCPP_BEGIN_NAMESPACE_STD
2323
24#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
24#if _LIBCPP_STD_VER > 17
2525
2626// [concepts.object]
2727
......@@ -32,7 +32,7 @@ concept movable =
3232 assignable_from<_Tp&, _Tp> &&
3333 swappable<_Tp>;
3434
35#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
35#endif // _LIBCPP_STD_VER > 17
3636
3737_LIBCPP_END_NAMESPACE_STD
3838
lib/libcxx/include/__concepts/predicate.h+3-3
......@@ -15,12 +15,12 @@
1515#include <type_traits>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
2222
23#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
23#if _LIBCPP_STD_VER > 17
2424
2525// [concept.predicate]
2626
......@@ -28,7 +28,7 @@ template<class _Fn, class... _Args>
2828concept predicate =
2929 regular_invocable<_Fn, _Args...> && __boolean_testable<invoke_result_t<_Fn, _Args...>>;
3030
31#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
31#endif // _LIBCPP_STD_VER > 17
3232
3333_LIBCPP_END_NAMESPACE_STD
3434
lib/libcxx/include/__concepts/regular.h+3-3
......@@ -14,19 +14,19 @@
1414#include <__config>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
17# pragma GCC system_header
1818#endif
1919
2020_LIBCPP_BEGIN_NAMESPACE_STD
2121
22#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
22#if _LIBCPP_STD_VER > 17
2323
2424// [concept.object]
2525
2626template<class _Tp>
2727concept regular = semiregular<_Tp> && equality_comparable<_Tp>;
2828
29#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
29#endif // _LIBCPP_STD_VER > 17
3030
3131_LIBCPP_END_NAMESPACE_STD
3232
lib/libcxx/include/__concepts/relation.h+3-3
......@@ -13,12 +13,12 @@
1313#include <__config>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16#pragma GCC system_header
16# pragma GCC system_header
1717#endif
1818
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
21#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
21#if _LIBCPP_STD_VER > 17
2222
2323// [concept.relation]
2424
......@@ -37,7 +37,7 @@ concept equivalence_relation = relation<_Rp, _Tp, _Up>;
3737template<class _Rp, class _Tp, class _Up>
3838concept strict_weak_order = relation<_Rp, _Tp, _Up>;
3939
40#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
40#endif // _LIBCPP_STD_VER > 17
4141
4242_LIBCPP_END_NAMESPACE_STD
4343
lib/libcxx/include/__concepts/same_as.h+3-3
......@@ -13,12 +13,12 @@
1313#include <type_traits>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16#pragma GCC system_header
16# pragma GCC system_header
1717#endif
1818
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
21#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
21#if _LIBCPP_STD_VER > 17
2222
2323// [concept.same]
2424
......@@ -28,7 +28,7 @@ concept __same_as_impl = _IsSame<_Tp, _Up>::value;
2828template<class _Tp, class _Up>
2929concept same_as = __same_as_impl<_Tp, _Up> && __same_as_impl<_Up, _Tp>;
3030
31#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
31#endif // _LIBCPP_STD_VER > 17
3232
3333_LIBCPP_END_NAMESPACE_STD
3434
lib/libcxx/include/__concepts/semiregular.h+3-3
......@@ -14,19 +14,19 @@
1414#include <__config>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
17# pragma GCC system_header
1818#endif
1919
2020_LIBCPP_BEGIN_NAMESPACE_STD
2121
22#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
22#if _LIBCPP_STD_VER > 17
2323
2424// [concept.object]
2525
2626template<class _Tp>
2727concept semiregular = copyable<_Tp> && default_initializable<_Tp>;
2828
29#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
29#endif // _LIBCPP_STD_VER > 17
3030
3131_LIBCPP_END_NAMESPACE_STD
3232
lib/libcxx/include/__concepts/swappable.h+3-3
......@@ -20,12 +20,12 @@
2020#include <type_traits>
2121
2222#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23#pragma GCC system_header
23# pragma GCC system_header
2424#endif
2525
2626_LIBCPP_BEGIN_NAMESPACE_STD
2727
28#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
28#if _LIBCPP_STD_VER > 17
2929
3030// [concept.swappable]
3131
......@@ -109,7 +109,7 @@ concept swappable_with =
109109 ranges::swap(_VSTD::forward<_Up>(__u), _VSTD::forward<_Tp>(__t));
110110 };
111111
112#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
112#endif // _LIBCPP_STD_VER > 17
113113
114114_LIBCPP_END_NAMESPACE_STD
115115
lib/libcxx/include/__concepts/totally_ordered.h+3-3
......@@ -15,12 +15,12 @@
1515#include <type_traits>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
2222
23#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
23#if _LIBCPP_STD_VER > 17
2424
2525// [concept.totallyordered]
2626
......@@ -50,7 +50,7 @@ concept totally_ordered_with =
5050 __make_const_lvalue_ref<_Up>>> &&
5151 __partially_ordered_with<_Tp, _Up>;
5252
53#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
53#endif // _LIBCPP_STD_VER > 17
5454
5555_LIBCPP_END_NAMESPACE_STD
5656
lib/libcxx/include/__config+872-1083
......@@ -7,8 +7,8 @@
77//
88//===----------------------------------------------------------------------===//
99
10#ifndef _LIBCPP_CONFIG
11#define _LIBCPP_CONFIG
10#ifndef _LIBCPP___CONFIG
11#define _LIBCPP___CONFIG
1212
1313#if defined(_MSC_VER) && !defined(__clang__)
1414# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -17,334 +17,326 @@
1717#endif
1818
1919#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
20#pragma GCC system_header
20# pragma GCC system_header
2121#endif
2222
2323#ifdef __cplusplus
2424
25#define _LIBCPP_VERSION 14000
25# define _LIBCPP_VERSION 15000
2626
27#ifndef _LIBCPP_ABI_VERSION
28# define _LIBCPP_ABI_VERSION 1
29#endif
27# define _LIBCPP_CONCAT_IMPL(_X, _Y) _X##_Y
28# define _LIBCPP_CONCAT(_X, _Y) _LIBCPP_CONCAT_IMPL(_X, _Y)
3029
31#if __STDC_HOSTED__ == 0
32# define _LIBCPP_FREESTANDING
33#endif
30// Valid C++ identifier that revs with every libc++ version. This can be used to
31// generate identifiers that must be unique for every released libc++ version.
32# define _LIBCPP_VERSIONED_IDENTIFIER _LIBCPP_CONCAT(v, _LIBCPP_VERSION)
33
34# if __STDC_HOSTED__ == 0
35# define _LIBCPP_FREESTANDING
36# endif
3437
35#ifndef _LIBCPP_STD_VER
36# if __cplusplus <= 201103L
37# define _LIBCPP_STD_VER 11
38# elif __cplusplus <= 201402L
39# define _LIBCPP_STD_VER 14
40# elif __cplusplus <= 201703L
41# define _LIBCPP_STD_VER 17
42# elif __cplusplus <= 202002L
43# define _LIBCPP_STD_VER 20
38# ifndef _LIBCPP_STD_VER
39# if __cplusplus <= 201103L
40# define _LIBCPP_STD_VER 11
41# elif __cplusplus <= 201402L
42# define _LIBCPP_STD_VER 14
43# elif __cplusplus <= 201703L
44# define _LIBCPP_STD_VER 17
45# elif __cplusplus <= 202002L
46# define _LIBCPP_STD_VER 20
47# else
48# define _LIBCPP_STD_VER 22 // current year, or date of c++2b ratification
49# endif
50# endif // _LIBCPP_STD_VER
51
52# if defined(__ELF__)
53# define _LIBCPP_OBJECT_FORMAT_ELF 1
54# elif defined(__MACH__)
55# define _LIBCPP_OBJECT_FORMAT_MACHO 1
56# elif defined(_WIN32)
57# define _LIBCPP_OBJECT_FORMAT_COFF 1
58# elif defined(__wasm__)
59# define _LIBCPP_OBJECT_FORMAT_WASM 1
60# elif defined(_AIX)
61# define _LIBCPP_OBJECT_FORMAT_XCOFF 1
4462# else
45# define _LIBCPP_STD_VER 21 // current year, or date of c++2b ratification
46# endif
47#endif // _LIBCPP_STD_VER
48
49#if defined(__ELF__)
50# define _LIBCPP_OBJECT_FORMAT_ELF 1
51#elif defined(__MACH__)
52# define _LIBCPP_OBJECT_FORMAT_MACHO 1
53#elif defined(_WIN32)
54# define _LIBCPP_OBJECT_FORMAT_COFF 1
55#elif defined(__wasm__)
56# define _LIBCPP_OBJECT_FORMAT_WASM 1
57#else
58 // ... add new file formats here ...
59#endif
63// ... add new file formats here ...
64# endif
6065
61#if defined(_LIBCPP_ABI_UNSTABLE) || _LIBCPP_ABI_VERSION >= 2
66# if _LIBCPP_ABI_VERSION >= 2
6267// Change short string representation so that string data starts at offset 0,
6368// improving its alignment in some cases.
64# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
69# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
6570// Fix deque iterator type in order to support incomplete types.
66# define _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE
71# define _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE
6772// Fix undefined behavior in how std::list stores its linked nodes.
68# define _LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB
73# define _LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB
6974// Fix undefined behavior in how __tree stores its end and parent nodes.
70# define _LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB
75# define _LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB
7176// Fix undefined behavior in how __hash_table stores its pointer types.
72# define _LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB
73# define _LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB
74# define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE
77# define _LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB
78# define _LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB
79# define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE
7580// Define a key function for `bad_function_call` in the library, to centralize
7681// its vtable and typeinfo to libc++ rather than having all other libraries
7782// using that class define their own copies.
78# define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
83# define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
7984// Override the default return value of exception::what() for
8085// bad_function_call::what() with a string that is specific to
8186// bad_function_call (see http://wg21.link/LWG2233). This is an ABI break
8287// because it changes the vtable layout of bad_function_call.
83# define _LIBCPP_ABI_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE
88# define _LIBCPP_ABI_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE
8489// Enable optimized version of __do_get_(un)signed which avoids redundant copies.
85# define _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
86// In C++20 and later, don't derive std::plus from std::binary_function,
87// nor std::negate from std::unary_function.
88# define _LIBCPP_ABI_NO_BINDER_BASES
90# define _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
8991// Give reverse_iterator<T> one data member of type T, not two.
9092// Also, in C++17 and later, don't derive iterator types from std::iterator.
91# define _LIBCPP_ABI_NO_ITERATOR_BASES
93# define _LIBCPP_ABI_NO_ITERATOR_BASES
9294// Use the smallest possible integer type to represent the index of the variant.
9395// Previously libc++ used "unsigned int" exclusively.
94# define _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION
96# define _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION
9597// Unstable attempt to provide a more optimized std::function
96# define _LIBCPP_ABI_OPTIMIZED_FUNCTION
98# define _LIBCPP_ABI_OPTIMIZED_FUNCTION
9799// All the regex constants must be distinct and nonzero.
98# define _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO
99// Use raw pointers, not wrapped ones, for std::span's iterator type.
100# define _LIBCPP_ABI_SPAN_POINTER_ITERATORS
100# define _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO
101101// Re-worked external template instantiations for std::string with a focus on
102102// performance and fast-path inlining.
103# define _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
103# define _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
104104// Enable clang::trivial_abi on std::unique_ptr.
105# define _LIBCPP_ABI_ENABLE_UNIQUE_PTR_TRIVIAL_ABI
105# define _LIBCPP_ABI_ENABLE_UNIQUE_PTR_TRIVIAL_ABI
106106// Enable clang::trivial_abi on std::shared_ptr and std::weak_ptr
107# define _LIBCPP_ABI_ENABLE_SHARED_PTR_TRIVIAL_ABI
107# define _LIBCPP_ABI_ENABLE_SHARED_PTR_TRIVIAL_ABI
108108// std::random_device holds some state when it uses an implementation that gets
109109// entropy from a file (see _LIBCPP_USING_DEV_RANDOM). When switching from this
110110// implementation to another one on a platform that has already shipped
111111// std::random_device, one needs to retain the same object layout to remain ABI
112112// compatible. This switch removes these workarounds for platforms that don't care
113113// about ABI compatibility.
114# define _LIBCPP_ABI_NO_RANDOM_DEVICE_COMPATIBILITY_LAYOUT
115// Remove basic_string common base
116# define _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON
117// Remove vector base class
118# define _LIBCPP_ABI_DO_NOT_EXPORT_VECTOR_BASE_COMMON
119#elif _LIBCPP_ABI_VERSION == 1
120# if !defined(_LIBCPP_OBJECT_FORMAT_COFF)
114# define _LIBCPP_ABI_NO_RANDOM_DEVICE_COMPATIBILITY_LAYOUT
115// Don't export the legacy __basic_string_common class and its methods from the built library.
116# define _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON
117// Don't export the legacy __vector_base_common class and its methods from the built library.
118# define _LIBCPP_ABI_DO_NOT_EXPORT_VECTOR_BASE_COMMON
119// According to the Standard, `bitset::operator[] const` returns bool
120# define _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL
121// Remove the base 10 implementation of std::to_chars from the dylib.
122// The implementation moved to the header, but we still export the symbols from
123// the dylib for backwards compatibility.
124# define _LIBCPP_ABI_DO_NOT_EXPORT_TO_CHARS_BASE_10
125# elif _LIBCPP_ABI_VERSION == 1
126# if !(defined(_LIBCPP_OBJECT_FORMAT_COFF) || defined(_LIBCPP_OBJECT_FORMAT_XCOFF))
121127// Enable compiling copies of now inline methods into the dylib to support
122128// applications compiled against older libraries. This is unnecessary with
123129// COFF dllexport semantics, since dllexport forces a non-inline definition
124130// of inline functions to be emitted anyway. Our own non-inline copy would
125// conflict with the dllexport-emitted copy, so we disable it.
126# define _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS
127# endif
131// conflict with the dllexport-emitted copy, so we disable it. For XCOFF,
132// the linker will take issue with the symbols in the shared object if the
133// weak inline methods get visibility (such as from -fvisibility-inlines-hidden),
134// so disable it.
135# define _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS
136# endif
128137// Feature macros for disabling pre ABI v1 features. All of these options
129138// are deprecated.
130# if defined(__FreeBSD__)
131# define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR
139# if defined(__FreeBSD__)
140# define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR
141# endif
132142# endif
133#endif
134
135// By default, don't use a nullptr_t emulation type in C++03.
136//
137// This is technically an ABI break from previous releases, however it is
138// very unlikely to impact anyone. If a user is impacted by this break,
139// they can return to using the C++03 nullptr emulation by defining
140// _LIBCPP_ABI_USE_CXX03_NULLPTR_EMULATION.
141//
142// This switch will be removed entirely in favour of never providing a
143// C++03 emulation after one release.
144//
145// IMPORTANT: IF YOU ARE READING THIS AND YOU TURN THIS MACRO ON, PLEASE LEAVE
146// A COMMENT ON https://reviews.llvm.org/D109459 OR YOU WILL BE BROKEN
147// IN THE FUTURE WHEN WE REMOVE THE ABILITY TO USE THE C++03 EMULATION.
148#ifndef _LIBCPP_ABI_USE_CXX03_NULLPTR_EMULATION
149# define _LIBCPP_ABI_ALWAYS_USE_CXX11_NULLPTR
150#endif
151143
152#if defined(_LIBCPP_BUILDING_LIBRARY) || defined(_LIBCPP_ABI_UNSTABLE) || _LIBCPP_ABI_VERSION >= 2
144# if defined(_LIBCPP_BUILDING_LIBRARY) || _LIBCPP_ABI_VERSION >= 2
153145// Enable additional explicit instantiations of iostreams components. This
154146// reduces the number of weak definitions generated in programs that use
155147// iostreams by providing a single strong definition in the shared library.
156# define _LIBCPP_ABI_ENABLE_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1
148# define _LIBCPP_ABI_ENABLE_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1
157149
158150// Define a key function for `bad_function_call` in the library, to centralize
159151// its vtable and typeinfo to libc++ rather than having all other libraries
160152// using that class define their own copies.
161# define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
162#endif
153# define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
154# endif
163155
164#define _LIBCPP_CONCAT1(_LIBCPP_X,_LIBCPP_Y) _LIBCPP_X##_LIBCPP_Y
165#define _LIBCPP_CONCAT(_LIBCPP_X,_LIBCPP_Y) _LIBCPP_CONCAT1(_LIBCPP_X,_LIBCPP_Y)
156# define _LIBCPP_TOSTRING2(x) # x
157# define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x)
166158
167#ifndef _LIBCPP_ABI_NAMESPACE
168# define _LIBCPP_ABI_NAMESPACE _LIBCPP_CONCAT(__,_LIBCPP_ABI_VERSION)
169#endif
170
171#if __cplusplus < 201103L
172#define _LIBCPP_CXX03_LANG
173#endif
159# if __cplusplus < 201103L
160# define _LIBCPP_CXX03_LANG
161# endif
174162
175#ifndef __has_attribute
176#define __has_attribute(__x) 0
177#endif
163# ifndef __has_attribute
164# define __has_attribute(__x) 0
165# endif
178166
179#ifndef __has_builtin
180#define __has_builtin(__x) 0
181#endif
167# ifndef __has_builtin
168# define __has_builtin(__x) 0
169# endif
182170
183#ifndef __has_extension
184#define __has_extension(__x) 0
185#endif
171# ifndef __has_extension
172# define __has_extension(__x) 0
173# endif
186174
187#ifndef __has_feature
188#define __has_feature(__x) 0
189#endif
175# ifndef __has_feature
176# define __has_feature(__x) 0
177# endif
190178
191#ifndef __has_cpp_attribute
192#define __has_cpp_attribute(__x) 0
193#endif
179# ifndef __has_cpp_attribute
180# define __has_cpp_attribute(__x) 0
181# endif
194182
195183// '__is_identifier' returns '0' if '__x' is a reserved identifier provided by
196184// the compiler and '1' otherwise.
197#ifndef __is_identifier
198#define __is_identifier(__x) 1
199#endif
185# ifndef __is_identifier
186# define __is_identifier(__x) 1
187# endif
200188
201#ifndef __has_declspec_attribute
202#define __has_declspec_attribute(__x) 0
203#endif
189# ifndef __has_declspec_attribute
190# define __has_declspec_attribute(__x) 0
191# endif
204192
205#define __has_keyword(__x) !(__is_identifier(__x))
193# define __has_keyword(__x) !(__is_identifier(__x))
206194
207#ifndef __has_include
208#define __has_include(...) 0
209#endif
195# ifndef __has_include
196# define __has_include(...) 0
197# endif
210198
211#if defined(__apple_build_version__)
212# define _LIBCPP_COMPILER_CLANG_BASED
213# define _LIBCPP_APPLE_CLANG_VER (__apple_build_version__ / 10000)
214#elif defined(__clang__)
215# define _LIBCPP_COMPILER_CLANG_BASED
216# define _LIBCPP_CLANG_VER (__clang_major__ * 100 + __clang_minor__)
217#elif defined(__GNUC__)
218# define _LIBCPP_COMPILER_GCC
219#elif defined(_MSC_VER)
220# define _LIBCPP_COMPILER_MSVC
221#elif defined(__IBMCPP__)
222# define _LIBCPP_COMPILER_IBM
223#endif
199# if defined(__apple_build_version__)
200# define _LIBCPP_COMPILER_CLANG_BASED
201# define _LIBCPP_APPLE_CLANG_VER (__apple_build_version__ / 10000)
202# elif defined(__clang__)
203# define _LIBCPP_COMPILER_CLANG_BASED
204# define _LIBCPP_CLANG_VER (__clang_major__ * 100 + __clang_minor__)
205# elif defined(__GNUC__)
206# define _LIBCPP_COMPILER_GCC
207# elif defined(_MSC_VER)
208# define _LIBCPP_COMPILER_MSVC
209# endif
224210
225#if defined(_LIBCPP_COMPILER_GCC) && __cplusplus < 201103L
226#error "libc++ does not support using GCC with C++03. Please enable C++11"
227#endif
211# if !defined(_LIBCPP_COMPILER_CLANG_BASED) && __cplusplus < 201103L
212# error "libc++ only supports C++03 with Clang-based compilers. Please enable C++11"
213# endif
214
215# ifdef _LIBCPP_COMPILER_MSVC
216# error If you successfully use libc++ with MSVC please tell the libc++ developers and consider upstreaming your \
217changes. We are not aware of anybody using this configuration and know that at least some code is currently broken. \
218If there are users of this configuration we are happy to provide support.
219# endif
228220
229221// FIXME: ABI detection should be done via compiler builtin macros. This
230222// is just a placeholder until Clang implements such macros. For now assume
231223// that Windows compilers pretending to be MSVC++ target the Microsoft ABI,
232224// and allow the user to explicitly specify the ABI to handle cases where this
233225// heuristic falls short.
234#if defined(_LIBCPP_ABI_FORCE_ITANIUM) && defined(_LIBCPP_ABI_FORCE_MICROSOFT)
235# error "Only one of _LIBCPP_ABI_FORCE_ITANIUM and _LIBCPP_ABI_FORCE_MICROSOFT can be defined"
236#elif defined(_LIBCPP_ABI_FORCE_ITANIUM)
237# define _LIBCPP_ABI_ITANIUM
238#elif defined(_LIBCPP_ABI_FORCE_MICROSOFT)
239# define _LIBCPP_ABI_MICROSOFT
240#else
241# if defined(_WIN32) && defined(_MSC_VER)
226# if defined(_LIBCPP_ABI_FORCE_ITANIUM) && defined(_LIBCPP_ABI_FORCE_MICROSOFT)
227# error "Only one of _LIBCPP_ABI_FORCE_ITANIUM and _LIBCPP_ABI_FORCE_MICROSOFT can be defined"
228# elif defined(_LIBCPP_ABI_FORCE_ITANIUM)
229# define _LIBCPP_ABI_ITANIUM
230# elif defined(_LIBCPP_ABI_FORCE_MICROSOFT)
242231# define _LIBCPP_ABI_MICROSOFT
243232# else
244# define _LIBCPP_ABI_ITANIUM
233# if defined(_WIN32) && defined(_MSC_VER)
234# define _LIBCPP_ABI_MICROSOFT
235# else
236# define _LIBCPP_ABI_ITANIUM
237# endif
245238# endif
246#endif
247239
248#if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME)
249# define _LIBCPP_ABI_VCRUNTIME
250#endif
240# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME)
241# define _LIBCPP_ABI_VCRUNTIME
242# endif
251243
252// Need to detect which libc we're using if we're on Linux.
253#if defined(__linux__)
254# include <features.h>
255# if defined(__GLIBC_PREREQ)
256# define _LIBCPP_GLIBC_PREREQ(a, b) __GLIBC_PREREQ(a, b)
257# else
258# define _LIBCPP_GLIBC_PREREQ(a, b) 0
259# endif // defined(__GLIBC_PREREQ)
260#endif // defined(__linux__)
244# if __has_feature(experimental_library)
245# ifndef _LIBCPP_ENABLE_EXPERIMENTAL
246# define _LIBCPP_ENABLE_EXPERIMENTAL
247# endif
248# endif
261249
262#if defined(__MVS__)
263# include <features.h> // for __NATIVE_ASCII_F
264#endif
250// Incomplete features get their own specific disabling flags. This makes it
251// easier to grep for target specific flags once the feature is complete.
252# if !defined(_LIBCPP_ENABLE_EXPERIMENTAL) && !defined(_LIBCPP_BUILDING_LIBRARY)
253# define _LIBCPP_HAS_NO_INCOMPLETE_FORMAT
254# define _LIBCPP_HAS_NO_INCOMPLETE_RANGES
255# endif
265256
266#ifdef __LITTLE_ENDIAN__
267# if __LITTLE_ENDIAN__
268# define _LIBCPP_LITTLE_ENDIAN
269# endif // __LITTLE_ENDIAN__
270#endif // __LITTLE_ENDIAN__
257// Need to detect which libc we're using if we're on Linux.
258# if defined(__linux__)
259# include <features.h>
260# if defined(__GLIBC_PREREQ)
261# define _LIBCPP_GLIBC_PREREQ(a, b) __GLIBC_PREREQ(a, b)
262# else
263# define _LIBCPP_GLIBC_PREREQ(a, b) 0
264# endif // defined(__GLIBC_PREREQ)
265# endif // defined(__linux__)
271266
272#ifdef __BIG_ENDIAN__
273# if __BIG_ENDIAN__
274# define _LIBCPP_BIG_ENDIAN
275# endif // __BIG_ENDIAN__
276#endif // __BIG_ENDIAN__
267# if defined(__MVS__)
268# include <features.h> // for __NATIVE_ASCII_F
269# endif
277270
278#ifdef __BYTE_ORDER__
279# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
271# ifdef __LITTLE_ENDIAN__
272# if __LITTLE_ENDIAN__
273# define _LIBCPP_LITTLE_ENDIAN
274# endif // __LITTLE_ENDIAN__
275# endif // __LITTLE_ENDIAN__
276
277# ifdef __BIG_ENDIAN__
278# if __BIG_ENDIAN__
279# define _LIBCPP_BIG_ENDIAN
280# endif // __BIG_ENDIAN__
281# endif // __BIG_ENDIAN__
282
283# ifdef __BYTE_ORDER__
284# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
285# define _LIBCPP_LITTLE_ENDIAN
286# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
287# define _LIBCPP_BIG_ENDIAN
288# endif // __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
289# endif // __BYTE_ORDER__
290
291# ifdef __FreeBSD__
292# include <sys/endian.h>
293# include <osreldate.h>
294# if _BYTE_ORDER == _LITTLE_ENDIAN
295# define _LIBCPP_LITTLE_ENDIAN
296# else // _BYTE_ORDER == _LITTLE_ENDIAN
297# define _LIBCPP_BIG_ENDIAN
298# endif // _BYTE_ORDER == _LITTLE_ENDIAN
299# endif // __FreeBSD__
300
301# if defined(__NetBSD__) || defined(__OpenBSD__)
302# include <sys/endian.h>
303# if _BYTE_ORDER == _LITTLE_ENDIAN
304# define _LIBCPP_LITTLE_ENDIAN
305# else // _BYTE_ORDER == _LITTLE_ENDIAN
306# define _LIBCPP_BIG_ENDIAN
307# endif // _BYTE_ORDER == _LITTLE_ENDIAN
308# endif // defined(__NetBSD__) || defined(__OpenBSD__)
309
310# if defined(_WIN32)
311# define _LIBCPP_WIN32API
280312# define _LIBCPP_LITTLE_ENDIAN
281# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
282# define _LIBCPP_BIG_ENDIAN
283# endif // __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
284#endif // __BYTE_ORDER__
285
286#ifdef __FreeBSD__
287# include <sys/endian.h>
288# include <osreldate.h>
289# if _BYTE_ORDER == _LITTLE_ENDIAN
290# define _LIBCPP_LITTLE_ENDIAN
291# else // _BYTE_ORDER == _LITTLE_ENDIAN
292# define _LIBCPP_BIG_ENDIAN
293# endif // _BYTE_ORDER == _LITTLE_ENDIAN
294#endif // __FreeBSD__
295
296#if defined(__NetBSD__) || defined(__OpenBSD__)
297# include <sys/endian.h>
298# if _BYTE_ORDER == _LITTLE_ENDIAN
299# define _LIBCPP_LITTLE_ENDIAN
300# else // _BYTE_ORDER == _LITTLE_ENDIAN
301# define _LIBCPP_BIG_ENDIAN
302# endif // _BYTE_ORDER == _LITTLE_ENDIAN
303#endif // defined(__NetBSD__) || defined(__OpenBSD__)
304
305#if defined(_WIN32)
306# define _LIBCPP_WIN32API
307# define _LIBCPP_LITTLE_ENDIAN
308# define _LIBCPP_SHORT_WCHAR 1
313# define _LIBCPP_SHORT_WCHAR 1
309314// Both MinGW and native MSVC provide a "MSVC"-like environment
310# define _LIBCPP_MSVCRT_LIKE
315# define _LIBCPP_MSVCRT_LIKE
311316// If mingw not explicitly detected, assume using MS C runtime only if
312317// a MS compatibility version is specified.
313# if defined(_MSC_VER) && !defined(__MINGW32__)
314# define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library
315# endif
316# if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__))
317# define _LIBCPP_HAS_BITSCAN64
318# endif
319# define _LIBCPP_HAS_OPEN_WITH_WCHAR
320# if defined(_LIBCPP_MSVCRT)
321# define _LIBCPP_HAS_QUICK_EXIT
322# endif
318# if defined(_MSC_VER) && !defined(__MINGW32__)
319# define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library
320# endif
321# if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__))
322# define _LIBCPP_HAS_BITSCAN64
323# endif
324# define _LIBCPP_HAS_OPEN_WITH_WCHAR
325# endif // defined(_WIN32)
323326
324// Some CRT APIs are unavailable to store apps
325# if defined(WINAPI_FAMILY)
326# include <winapifamily.h>
327# if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) && \
328 (!defined(WINAPI_PARTITION_SYSTEM) || \
329 !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_SYSTEM))
330# define _LIBCPP_WINDOWS_STORE_APP
327# ifdef __sun__
328# include <sys/isa_defs.h>
329# ifdef _LITTLE_ENDIAN
330# define _LIBCPP_LITTLE_ENDIAN
331# else
332# define _LIBCPP_BIG_ENDIAN
331333# endif
332# endif
333#endif // defined(_WIN32)
334# endif // __sun__
334335
335#ifdef __sun__
336# include <sys/isa_defs.h>
337# ifdef _LITTLE_ENDIAN
338# define _LIBCPP_LITTLE_ENDIAN
339# else
340# define _LIBCPP_BIG_ENDIAN
336# if defined(_AIX) && !defined(__64BIT__)
337// The size of wchar is 2 byte on 32-bit mode on AIX.
338# define _LIBCPP_SHORT_WCHAR 1
341339# endif
342#endif // __sun__
343
344#if defined(_AIX) && !defined(__64BIT__)
345 // The size of wchar is 2 byte on 32-bit mode on AIX.
346# define _LIBCPP_SHORT_WCHAR 1
347#endif
348340
349341// Libc++ supports various implementations of std::random_device.
350342//
......@@ -384,806 +376,581 @@
384376// Use rand_s(), for use on Windows.
385377// When this option is used, the token passed to `std::random_device`'s
386378// constructor *must* be "/dev/urandom" -- anything else is an error.
387#if defined(__OpenBSD__) || defined(__APPLE__)
388# define _LIBCPP_USING_ARC4_RANDOM
389#elif defined(__wasi__)
390# define _LIBCPP_USING_GETENTROPY
391#elif defined(__Fuchsia__)
392# define _LIBCPP_USING_FUCHSIA_CPRNG
393#elif defined(__native_client__)
394# define _LIBCPP_USING_NACL_RANDOM
395#elif defined(_LIBCPP_WIN32API)
396# define _LIBCPP_USING_WIN32_RANDOM
397#else
398# define _LIBCPP_USING_DEV_RANDOM
399#endif
400
401#if !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN)
402# include <endian.h>
403# if __BYTE_ORDER == __LITTLE_ENDIAN
404# define _LIBCPP_LITTLE_ENDIAN
405# elif __BYTE_ORDER == __BIG_ENDIAN
406# define _LIBCPP_BIG_ENDIAN
407# else // __BYTE_ORDER == __BIG_ENDIAN
408# error unable to determine endian
379# if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \
380 defined(__DragonFly__) || defined(__sun__)
381# define _LIBCPP_USING_ARC4_RANDOM
382# elif defined(__wasi__) || defined(__EMSCRIPTEN__)
383# define _LIBCPP_USING_GETENTROPY
384# elif defined(__Fuchsia__)
385# define _LIBCPP_USING_FUCHSIA_CPRNG
386# elif defined(__native_client__)
387# define _LIBCPP_USING_NACL_RANDOM
388# elif defined(_LIBCPP_WIN32API)
389# define _LIBCPP_USING_WIN32_RANDOM
390# else
391# define _LIBCPP_USING_DEV_RANDOM
409392# endif
410#endif // !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN)
411393
412#if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC)
413# define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi")))
414#else
415# define _LIBCPP_NO_CFI
416#endif
417
418// If the compiler supports using_if_exists, pretend we have those functions and they'll
419// be picked up if the C library provides them.
420//
421// TODO: Once we drop support for Clang 12, we can assume the compiler supports using_if_exists
422// for platforms that don't have a conforming C11 library, so we can drop this whole thing.
423#if __has_attribute(using_if_exists)
424# define _LIBCPP_HAS_TIMESPEC_GET
425# define _LIBCPP_HAS_QUICK_EXIT
426# define _LIBCPP_HAS_ALIGNED_ALLOC
427#else
428#if (defined(__ISO_C_VISIBLE) && (__ISO_C_VISIBLE >= 2011)) || __cplusplus >= 201103L
429# if defined(__FreeBSD__)
430# define _LIBCPP_HAS_ALIGNED_ALLOC
431# define _LIBCPP_HAS_QUICK_EXIT
432# if __FreeBSD_version >= 1300064 || \
433 (__FreeBSD_version >= 1201504 && __FreeBSD_version < 1300000)
434# define _LIBCPP_HAS_TIMESPEC_GET
435# endif
436# elif defined(__BIONIC__)
437# if __ANDROID_API__ >= 21
438# define _LIBCPP_HAS_QUICK_EXIT
439# endif
440# if __ANDROID_API__ >= 28
441# define _LIBCPP_HAS_ALIGNED_ALLOC
442# endif
443# if __ANDROID_API__ >= 29
444# define _LIBCPP_HAS_TIMESPEC_GET
445# endif
446# elif defined(__Fuchsia__) || defined(__wasi__) || defined(__NetBSD__)
447# define _LIBCPP_HAS_ALIGNED_ALLOC
448# define _LIBCPP_HAS_QUICK_EXIT
449# define _LIBCPP_HAS_TIMESPEC_GET
450# elif defined(__OpenBSD__)
451# define _LIBCPP_HAS_ALIGNED_ALLOC
452# define _LIBCPP_HAS_TIMESPEC_GET
453# elif defined(__linux__)
454# if !defined(_LIBCPP_HAS_MUSL_LIBC)
455# if _LIBCPP_GLIBC_PREREQ(2, 15) || defined(__BIONIC__)
456# define _LIBCPP_HAS_QUICK_EXIT
457# endif
458# if _LIBCPP_GLIBC_PREREQ(2, 17)
459# define _LIBCPP_HAS_ALIGNED_ALLOC
460# define _LIBCPP_HAS_TIMESPEC_GET
461# endif
462# else // defined(_LIBCPP_HAS_MUSL_LIBC)
463# define _LIBCPP_HAS_ALIGNED_ALLOC
464# define _LIBCPP_HAS_QUICK_EXIT
465# define _LIBCPP_HAS_TIMESPEC_GET
466# endif
467# elif defined(_LIBCPP_MSVCRT)
468 // Using Microsoft's C Runtime library, not MinGW
469# define _LIBCPP_HAS_TIMESPEC_GET
470# elif defined(__APPLE__)
471 // timespec_get and aligned_alloc were introduced in macOS 10.15 and
472 // aligned releases
473# if ((defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101500) || \
474 (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 130000) || \
475 (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ >= 130000) || \
476 (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ >= 60000))
477# define _LIBCPP_HAS_ALIGNED_ALLOC
478# define _LIBCPP_HAS_TIMESPEC_GET
394# if !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN)
395# include <endian.h>
396# if __BYTE_ORDER == __LITTLE_ENDIAN
397# define _LIBCPP_LITTLE_ENDIAN
398# elif __BYTE_ORDER == __BIG_ENDIAN
399# define _LIBCPP_BIG_ENDIAN
400# else // __BYTE_ORDER == __BIG_ENDIAN
401# error unable to determine endian
479402# endif
480# endif // __APPLE__
481#endif
482#endif // __has_attribute(using_if_exists)
483
484#ifndef _LIBCPP_CXX03_LANG
485# define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp)
486#elif defined(_LIBCPP_COMPILER_CLANG_BASED)
487# define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp)
488#else
489# error "We don't know a correct way to implement alignof(T) in C++03 outside of Clang"
490#endif
403# endif // !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN)
491404
492#define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp)
405# if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC)
406# define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi")))
407# else
408# define _LIBCPP_NO_CFI
409# endif
493410
494#if defined(_LIBCPP_COMPILER_CLANG_BASED)
411# ifndef _LIBCPP_CXX03_LANG
495412
496#if defined(_LIBCPP_ALTERNATE_STRING_LAYOUT)
497# error _LIBCPP_ALTERNATE_STRING_LAYOUT is deprecated, please use _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT instead
498#endif
499#if defined(__APPLE__) && !defined(__i386__) && !defined(__x86_64__) && \
500 (!defined(__arm__) || __ARM_ARCH_7K__ >= 2)
501# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
502#endif
413# define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp)
414# define _ALIGNAS_TYPE(x) alignas(x)
415# define _ALIGNAS(x) alignas(x)
416# define _LIBCPP_NORETURN [[noreturn]]
417# define _NOEXCEPT noexcept
418# define _NOEXCEPT_(x) noexcept(x)
503419
504#if __has_feature(cxx_alignas)
505# define _ALIGNAS_TYPE(x) alignas(x)
506# define _ALIGNAS(x) alignas(x)
507#else
508# define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x))))
509# define _ALIGNAS(x) __attribute__((__aligned__(x)))
510#endif
420# else
421
422# define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp)
423# define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x))))
424# define _ALIGNAS(x) __attribute__((__aligned__(x)))
425# define _LIBCPP_NORETURN __attribute__((noreturn))
426# define _LIBCPP_HAS_NO_NOEXCEPT
427# define nullptr __nullptr
428# define _NOEXCEPT throw()
429# define _NOEXCEPT_(x)
511430
512#if __cplusplus < 201103L
513431typedef __char16_t char16_t;
514432typedef __char32_t char32_t;
515#endif
516
517#if !__has_feature(cxx_exceptions)
518# define _LIBCPP_NO_EXCEPTIONS
519#endif
520433
521#if !(__has_feature(cxx_strong_enums))
522#define _LIBCPP_HAS_NO_STRONG_ENUMS
523#endif
524
525#if __has_feature(cxx_attributes)
526# define _LIBCPP_NORETURN [[noreturn]]
527#else
528# define _LIBCPP_NORETURN __attribute__ ((noreturn))
529#endif
530
531#if !(__has_feature(cxx_nullptr))
532# if (__has_extension(cxx_nullptr) || __has_keyword(__nullptr)) && defined(_LIBCPP_ABI_ALWAYS_USE_CXX11_NULLPTR)
533# define nullptr __nullptr
534# else
535# define _LIBCPP_HAS_NO_NULLPTR
536434# endif
537#endif
538
539// Objective-C++ features (opt-in)
540#if __has_feature(objc_arc)
541#define _LIBCPP_HAS_OBJC_ARC
542#endif
543
544#if __has_feature(objc_arc_weak)
545#define _LIBCPP_HAS_OBJC_ARC_WEAK
546#endif
547
548#if __has_extension(blocks)
549# define _LIBCPP_HAS_EXTENSION_BLOCKS
550#endif
551435
552#if defined(_LIBCPP_HAS_EXTENSION_BLOCKS) && defined(__APPLE__)
553# define _LIBCPP_HAS_BLOCKS_RUNTIME
554#endif
436# if !defined(__cpp_exceptions) || __cpp_exceptions < 199711L
437# define _LIBCPP_NO_EXCEPTIONS
438# endif
555439
556#if !(__has_feature(cxx_noexcept))
557#define _LIBCPP_HAS_NO_NOEXCEPT
558#endif
440# define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp)
559441
560#if !__has_feature(address_sanitizer)
561#define _LIBCPP_HAS_NO_ASAN
562#endif
442# if defined(_LIBCPP_COMPILER_CLANG_BASED)
563443
564// Allow for build-time disabling of unsigned integer sanitization
565#if __has_attribute(no_sanitize)
566#define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow")))
567#endif
568
569#define _LIBCPP_ALWAYS_INLINE __attribute__ ((__always_inline__))
444# if defined(__APPLE__) && !defined(__i386__) && !defined(__x86_64__) && (!defined(__arm__) || __ARM_ARCH_7K__ >= 2)
445# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
446# endif
570447
571#define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
448// Objective-C++ features (opt-in)
449# if __has_feature(objc_arc)
450# define _LIBCPP_HAS_OBJC_ARC
451# endif
572452
573#elif defined(_LIBCPP_COMPILER_GCC)
453# if __has_feature(objc_arc_weak)
454# define _LIBCPP_HAS_OBJC_ARC_WEAK
455# endif
574456
575#define _ALIGNAS(x) __attribute__((__aligned__(x)))
576#define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x))))
457# if __has_extension(blocks)
458# define _LIBCPP_HAS_EXTENSION_BLOCKS
459# endif
577460
578#define _LIBCPP_NORETURN __attribute__((noreturn))
461# if defined(_LIBCPP_HAS_EXTENSION_BLOCKS) && defined(__APPLE__)
462# define _LIBCPP_HAS_BLOCKS_RUNTIME
463# endif
579464
580#if !defined(__EXCEPTIONS)
581# define _LIBCPP_NO_EXCEPTIONS
582#endif
465# if !__has_feature(address_sanitizer)
466# define _LIBCPP_HAS_NO_ASAN
467# endif
583468
584#if !defined(__SANITIZE_ADDRESS__)
585#define _LIBCPP_HAS_NO_ASAN
586#endif
469// Allow for build-time disabling of unsigned integer sanitization
470# if __has_attribute(no_sanitize)
471# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow")))
472# endif
587473
588#define _LIBCPP_ALWAYS_INLINE __attribute__ ((__always_inline__))
474# define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__))
589475
590#define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
476# define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
591477
592#elif defined(_LIBCPP_COMPILER_MSVC)
478# elif defined(_LIBCPP_COMPILER_GCC)
593479
594#define _LIBCPP_TOSTRING2(x) #x
595#define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x)
596#define _LIBCPP_WARNING(x) __pragma(message(__FILE__ "(" _LIBCPP_TOSTRING(__LINE__) ") : warning note: " x))
480# if !defined(__SANITIZE_ADDRESS__)
481# define _LIBCPP_HAS_NO_ASAN
482# endif
597483
598#if _MSC_VER < 1900
599#error "MSVC versions prior to Visual Studio 2015 are not supported"
600#endif
484# define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__))
601485
602#define __alignof__ __alignof
603#define _LIBCPP_NORETURN __declspec(noreturn)
604#define _ALIGNAS(x) __declspec(align(x))
605#define _ALIGNAS_TYPE(x) alignas(x)
486# define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
606487
607#define _LIBCPP_WEAK
488# elif defined(_LIBCPP_COMPILER_MSVC)
608489
609#define _LIBCPP_HAS_NO_ASAN
490# define _LIBCPP_WARNING(x) __pragma(message(__FILE__ "(" _LIBCPP_TOSTRING(__LINE__) ") : warning note: " x))
610491
611#define _LIBCPP_ALWAYS_INLINE __forceinline
492# if _MSC_VER < 1900
493# error "MSVC versions prior to Visual Studio 2015 are not supported"
494# endif
612495
613#define _LIBCPP_HAS_NO_VECTOR_EXTENSION
496# define _LIBCPP_NORETURN __declspec(noreturn)
614497
615#define _LIBCPP_DISABLE_EXTENSION_WARNING
498# define _LIBCPP_WEAK
616499
617#elif defined(_LIBCPP_COMPILER_IBM)
500# define _LIBCPP_HAS_NO_ASAN
618501
619#define _ALIGNAS(x) __attribute__((__aligned__(x)))
620#define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x))))
621#define _ATTRIBUTE(x) __attribute__((x))
622#define _LIBCPP_NORETURN __attribute__((noreturn))
502# define _LIBCPP_ALWAYS_INLINE __forceinline
623503
624#define _LIBCPP_HAS_NO_UNICODE_CHARS
504# define _LIBCPP_HAS_NO_VECTOR_EXTENSION
625505
626#if defined(_AIX)
627#define __MULTILOCALE_API
628#endif
506# define _LIBCPP_DISABLE_EXTENSION_WARNING
629507
630#define _LIBCPP_HAS_NO_ASAN
508# endif // _LIBCPP_COMPILER_[CLANG|GCC|MSVC]
631509
632#define _LIBCPP_ALWAYS_INLINE __attribute__ ((__always_inline__))
510# if defined(_LIBCPP_OBJECT_FORMAT_COFF)
633511
634#define _LIBCPP_HAS_NO_VECTOR_EXTENSION
512# ifdef _DLL
513# define _LIBCPP_CRT_FUNC __declspec(dllimport)
514# else
515# define _LIBCPP_CRT_FUNC
516# endif
635517
636#define _LIBCPP_DISABLE_EXTENSION_WARNING
518# if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) || (defined(__MINGW32__) && !defined(_LIBCPP_BUILDING_LIBRARY))
519# define _LIBCPP_DLL_VIS
520# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
521# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
522# define _LIBCPP_OVERRIDABLE_FUNC_VIS
523# define _LIBCPP_EXPORTED_FROM_ABI
524# elif defined(_LIBCPP_BUILDING_LIBRARY)
525# define _LIBCPP_DLL_VIS __declspec(dllexport)
526# if defined(__MINGW32__)
527# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
528# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
529# else
530# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
531# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCPP_DLL_VIS
532# endif
533# define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_DLL_VIS
534# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport)
535# else
536# define _LIBCPP_DLL_VIS __declspec(dllimport)
537# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
538# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
539# define _LIBCPP_OVERRIDABLE_FUNC_VIS
540# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport)
541# endif
637542
638#endif // _LIBCPP_COMPILER_[CLANG|GCC|MSVC|IBM]
543# define _LIBCPP_TYPE_VIS _LIBCPP_DLL_VIS
544# define _LIBCPP_FUNC_VIS _LIBCPP_DLL_VIS
545# define _LIBCPP_EXCEPTION_ABI _LIBCPP_DLL_VIS
546# define _LIBCPP_HIDDEN
547# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
548# define _LIBCPP_TEMPLATE_VIS
549# define _LIBCPP_TEMPLATE_DATA_VIS
550# define _LIBCPP_ENUM_VIS
639551
640#if defined(_LIBCPP_OBJECT_FORMAT_COFF)
552# else
641553
642#ifdef _DLL
643# define _LIBCPP_CRT_FUNC __declspec(dllimport)
644#else
645# define _LIBCPP_CRT_FUNC
646#endif
554# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
555# define _LIBCPP_VISIBILITY(vis) __attribute__((__visibility__(vis)))
556# else
557# define _LIBCPP_VISIBILITY(vis)
558# endif
647559
648#if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
649# define _LIBCPP_DLL_VIS
650# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
651# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
652# define _LIBCPP_OVERRIDABLE_FUNC_VIS
653# define _LIBCPP_EXPORTED_FROM_ABI
654#elif defined(_LIBCPP_BUILDING_LIBRARY)
655# define _LIBCPP_DLL_VIS __declspec(dllexport)
656# if defined(__MINGW32__)
657# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
560# define _LIBCPP_HIDDEN _LIBCPP_VISIBILITY("hidden")
561# define _LIBCPP_FUNC_VIS _LIBCPP_VISIBILITY("default")
562# define _LIBCPP_TYPE_VIS _LIBCPP_VISIBILITY("default")
563# define _LIBCPP_TEMPLATE_DATA_VIS _LIBCPP_VISIBILITY("default")
564# define _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_VISIBILITY("default")
565# define _LIBCPP_EXCEPTION_ABI _LIBCPP_VISIBILITY("default")
566# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_VISIBILITY("default")
658567# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
659# else
660# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
661# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCPP_DLL_VIS
662# endif
663# define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_DLL_VIS
664# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport)
665#else
666# define _LIBCPP_DLL_VIS __declspec(dllimport)
667# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
668# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
669# define _LIBCPP_OVERRIDABLE_FUNC_VIS
670# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport)
671#endif
672568
673#define _LIBCPP_TYPE_VIS _LIBCPP_DLL_VIS
674#define _LIBCPP_FUNC_VIS _LIBCPP_DLL_VIS
675#define _LIBCPP_EXCEPTION_ABI _LIBCPP_DLL_VIS
676#define _LIBCPP_HIDDEN
677#define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
678#define _LIBCPP_TEMPLATE_VIS
679#define _LIBCPP_TEMPLATE_DATA_VIS
680#define _LIBCPP_ENUM_VIS
569// TODO: Make this a proper customization point or remove the option to override it.
570# ifndef _LIBCPP_OVERRIDABLE_FUNC_VIS
571# define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_VISIBILITY("default")
572# endif
681573
682#endif // defined(_LIBCPP_OBJECT_FORMAT_COFF)
574# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
575// The inline should be removed once PR32114 is resolved
576# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS inline _LIBCPP_HIDDEN
577# else
578# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
579# endif
683580
684#ifndef _LIBCPP_HIDDEN
685# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
686# define _LIBCPP_HIDDEN __attribute__ ((__visibility__("hidden")))
687# else
688# define _LIBCPP_HIDDEN
689# endif
690#endif
581# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
582# if __has_attribute(__type_visibility__)
583# define _LIBCPP_TEMPLATE_VIS __attribute__((__type_visibility__("default")))
584# else
585# define _LIBCPP_TEMPLATE_VIS __attribute__((__visibility__("default")))
586# endif
587# else
588# define _LIBCPP_TEMPLATE_VIS
589# endif
691590
692#ifndef _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
693# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
694// The inline should be removed once PR32114 is resolved
695# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS inline _LIBCPP_HIDDEN
696# else
697# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
698# endif
699#endif
591# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__)
592# define _LIBCPP_ENUM_VIS __attribute__((__type_visibility__("default")))
593# else
594# define _LIBCPP_ENUM_VIS
595# endif
596
597# endif // defined(_LIBCPP_OBJECT_FORMAT_COFF)
700598
701#ifndef _LIBCPP_FUNC_VIS
702# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
703# define _LIBCPP_FUNC_VIS __attribute__ ((__visibility__("default")))
599# if __has_attribute(exclude_from_explicit_instantiation)
600# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__((__exclude_from_explicit_instantiation__))
704601# else
705# define _LIBCPP_FUNC_VIS
602// Try to approximate the effect of exclude_from_explicit_instantiation
603// (which is that entities are not assumed to be provided by explicit
604// template instantiations in the dylib) by always inlining those entities.
605# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCPP_ALWAYS_INLINE
706606# endif
707#endif
708607
709#ifndef _LIBCPP_TYPE_VIS
710# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
711# define _LIBCPP_TYPE_VIS __attribute__ ((__visibility__("default")))
608// This macro marks a symbol as being hidden from libc++'s ABI. This is achieved
609// on two levels:
610// 1. The symbol is given hidden visibility, which ensures that users won't start exporting
611// symbols from their dynamic library by means of using the libc++ headers. This ensures
612// that those symbols stay private to the dynamic library in which it is defined.
613//
614// 2. The symbol is given an ABI tag that changes with each version of libc++. This ensures
615// that no ODR violation can arise from mixing two TUs compiled with different versions
616// of libc++ where we would have changed the definition of a symbol. If the symbols shared
617// the same name, the ODR would require that their definitions be token-by-token equivalent,
618// which basically prevents us from being able to make any change to any function in our
619// headers. Using this ABI tag ensures that the symbol name is "bumped" artificially at
620// each release, which lets us change the definition of these symbols at our leisure.
621// Note that historically, this has been achieved in various ways, including force-inlining
622// all functions or giving internal linkage to all functions. Both these (previous) solutions
623// suffer from drawbacks that lead notably to code bloat.
624//
625// Note that we use _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION to ensure that we don't depend
626// on _LIBCPP_HIDE_FROM_ABI methods of classes explicitly instantiated in the dynamic library.
627//
628// TODO: We provide a escape hatch with _LIBCPP_NO_ABI_TAG for folks who want to avoid increasing
629// the length of symbols with an ABI tag. In practice, we should remove the escape hatch and
630// use compression mangling instead, see https://github.com/itanium-cxx-abi/cxx-abi/issues/70.
631# ifndef _LIBCPP_NO_ABI_TAG
632# define _LIBCPP_HIDE_FROM_ABI \
633 _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION \
634 __attribute__((__abi_tag__(_LIBCPP_TOSTRING(_LIBCPP_VERSIONED_IDENTIFIER))))
712635# else
713# define _LIBCPP_TYPE_VIS
636# define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION
714637# endif
715#endif
716638
717#ifndef _LIBCPP_TEMPLATE_VIS
718# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
719# if __has_attribute(__type_visibility__)
720# define _LIBCPP_TEMPLATE_VIS __attribute__ ((__type_visibility__("default")))
639# ifdef _LIBCPP_BUILDING_LIBRARY
640# if _LIBCPP_ABI_VERSION > 1
641# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
721642# else
722# define _LIBCPP_TEMPLATE_VIS __attribute__ ((__visibility__("default")))
643# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1
723644# endif
724645# else
725# define _LIBCPP_TEMPLATE_VIS
646# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
726647# endif
727#endif
728648
729#ifndef _LIBCPP_TEMPLATE_DATA_VIS
730# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
731# define _LIBCPP_TEMPLATE_DATA_VIS __attribute__ ((__visibility__("default")))
732# else
733# define _LIBCPP_TEMPLATE_DATA_VIS
734# endif
735#endif
649// Just so we can migrate to the new macros gradually.
650# define _LIBCPP_INLINE_VISIBILITY _LIBCPP_HIDE_FROM_ABI
736651
737#ifndef _LIBCPP_EXPORTED_FROM_ABI
738# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
739# define _LIBCPP_EXPORTED_FROM_ABI __attribute__((__visibility__("default")))
740# else
741# define _LIBCPP_EXPORTED_FROM_ABI
742# endif
743#endif
652// Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect.
653// clang-format off
654# define _LIBCPP_BEGIN_NAMESPACE_STD namespace std { inline namespace _LIBCPP_ABI_NAMESPACE {
655# define _LIBCPP_END_NAMESPACE_STD }}
656# define _VSTD std
744657
745#ifndef _LIBCPP_OVERRIDABLE_FUNC_VIS
746#define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_FUNC_VIS
747#endif
658_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD
748659
749#ifndef _LIBCPP_EXCEPTION_ABI
750# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
751# define _LIBCPP_EXCEPTION_ABI __attribute__ ((__visibility__("default")))
660# if _LIBCPP_STD_VER > 14
661# define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM \
662 _LIBCPP_BEGIN_NAMESPACE_STD inline namespace __fs { namespace filesystem {
752663# else
753# define _LIBCPP_EXCEPTION_ABI
664# define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM \
665 _LIBCPP_BEGIN_NAMESPACE_STD namespace __fs { namespace filesystem {
754666# endif
755#endif
756667
757#ifndef _LIBCPP_ENUM_VIS
758# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__)
759# define _LIBCPP_ENUM_VIS __attribute__ ((__type_visibility__("default")))
760# else
761# define _LIBCPP_ENUM_VIS
762# endif
763#endif
668# define _LIBCPP_END_NAMESPACE_FILESYSTEM _LIBCPP_END_NAMESPACE_STD }}
669// clang-format on
764670
765#ifndef _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
766# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
767# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __attribute__ ((__visibility__("default")))
768# else
769# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
770# endif
771#endif
671# define _VSTD_FS std::__fs::filesystem
772672
773#ifndef _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
774#define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
775#endif
673# if __has_attribute(__enable_if__)
674# define _LIBCPP_PREFERRED_OVERLOAD __attribute__((__enable_if__(true, "")))
675# endif
776676
777#if __has_attribute(internal_linkage)
778# define _LIBCPP_INTERNAL_LINKAGE __attribute__ ((internal_linkage))
779#else
780# define _LIBCPP_INTERNAL_LINKAGE _LIBCPP_ALWAYS_INLINE
781#endif
677# ifndef __SIZEOF_INT128__
678# define _LIBCPP_HAS_NO_INT128
679# endif
782680
783#if __has_attribute(exclude_from_explicit_instantiation)
784# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__ ((__exclude_from_explicit_instantiation__))
785#else
786 // Try to approximate the effect of exclude_from_explicit_instantiation
787 // (which is that entities are not assumed to be provided by explicit
788 // template instantiations in the dylib) by always inlining those entities.
789# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCPP_ALWAYS_INLINE
790#endif
681# ifdef _LIBCPP_CXX03_LANG
682# define static_assert(...) _Static_assert(__VA_ARGS__)
683# define decltype(...) __decltype(__VA_ARGS__)
684# endif // _LIBCPP_CXX03_LANG
791685
792#ifndef _LIBCPP_HIDE_FROM_ABI_PER_TU
793# ifndef _LIBCPP_HIDE_FROM_ABI_PER_TU_BY_DEFAULT
794# define _LIBCPP_HIDE_FROM_ABI_PER_TU 0
686# ifdef _LIBCPP_CXX03_LANG
687# define _LIBCPP_CONSTEXPR
795688# else
796# define _LIBCPP_HIDE_FROM_ABI_PER_TU 1
689# define _LIBCPP_CONSTEXPR constexpr
797690# endif
798#endif
799691
800#ifndef _LIBCPP_HIDE_FROM_ABI
801# if _LIBCPP_HIDE_FROM_ABI_PER_TU
802# define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_INTERNAL_LINKAGE
692# ifndef __cpp_consteval
693# define _LIBCPP_CONSTEVAL _LIBCPP_CONSTEXPR
803694# else
804# define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION
695# define _LIBCPP_CONSTEVAL consteval
805696# endif
806#endif
807697
808#ifdef _LIBCPP_BUILDING_LIBRARY
809# if _LIBCPP_ABI_VERSION > 1
810# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
698# ifdef __GNUC__
699# define _LIBCPP_NOALIAS __attribute__((__malloc__))
811700# else
812# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1
701# define _LIBCPP_NOALIAS
813702# endif
814#else
815# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
816#endif
817
818// Just so we can migrate to the new macros gradually.
819#define _LIBCPP_INLINE_VISIBILITY _LIBCPP_HIDE_FROM_ABI
820
821// Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect.
822#define _LIBCPP_BEGIN_NAMESPACE_STD namespace std { inline namespace _LIBCPP_ABI_NAMESPACE {
823#define _LIBCPP_END_NAMESPACE_STD } }
824#define _VSTD std
825_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD
826
827#if _LIBCPP_STD_VER > 14
828#define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM \
829 _LIBCPP_BEGIN_NAMESPACE_STD inline namespace __fs { namespace filesystem {
830#else
831#define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM \
832 _LIBCPP_BEGIN_NAMESPACE_STD namespace __fs { namespace filesystem {
833#endif
834
835#define _LIBCPP_END_NAMESPACE_FILESYSTEM \
836 _LIBCPP_END_NAMESPACE_STD } }
837
838#define _VSTD_FS _VSTD::__fs::filesystem
839
840#if __has_attribute(__enable_if__)
841# define _LIBCPP_PREFERRED_OVERLOAD __attribute__ ((__enable_if__(true, "")))
842#endif
843
844#ifndef _LIBCPP_HAS_NO_NOEXCEPT
845# define _NOEXCEPT noexcept
846# define _NOEXCEPT_(x) noexcept(x)
847#else
848# define _NOEXCEPT throw()
849# define _NOEXCEPT_(x)
850#endif
851
852#ifdef _LIBCPP_HAS_NO_UNICODE_CHARS
853typedef unsigned short char16_t;
854typedef unsigned int char32_t;
855#endif
856
857#ifndef __SIZEOF_INT128__
858#define _LIBCPP_HAS_NO_INT128
859#endif
860703
861#ifdef _LIBCPP_CXX03_LANG
862# define static_assert(...) _Static_assert(__VA_ARGS__)
863# define decltype(...) __decltype(__VA_ARGS__)
864#endif // _LIBCPP_CXX03_LANG
865
866#ifdef _LIBCPP_CXX03_LANG
867# define _LIBCPP_CONSTEXPR
868#else
869# define _LIBCPP_CONSTEXPR constexpr
870#endif
871
872#ifndef __cpp_consteval
873# define _LIBCPP_CONSTEVAL _LIBCPP_CONSTEXPR
874#else
875# define _LIBCPP_CONSTEVAL consteval
876#endif
877
878#if _LIBCPP_STD_VER <= 17 || !defined(__cpp_concepts) || __cpp_concepts < 201907L
879#define _LIBCPP_HAS_NO_CONCEPTS
880#endif
881
882#ifdef __GNUC__
883# define _LIBCPP_NOALIAS __attribute__((__malloc__))
884#else
885# define _LIBCPP_NOALIAS
886#endif
887
888#if __has_attribute(using_if_exists)
889# define _LIBCPP_USING_IF_EXISTS __attribute__((using_if_exists))
890#else
891# define _LIBCPP_USING_IF_EXISTS
892#endif
893
894#ifdef _LIBCPP_HAS_NO_STRONG_ENUMS
895# define _LIBCPP_DECLARE_STRONG_ENUM(x) struct _LIBCPP_TYPE_VIS x { enum __lx
896# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) \
897 __lx __v_; \
898 _LIBCPP_INLINE_VISIBILITY x(__lx __v) : __v_(__v) {} \
899 _LIBCPP_INLINE_VISIBILITY explicit x(int __v) : __v_(static_cast<__lx>(__v)) {} \
900 _LIBCPP_INLINE_VISIBILITY operator int() const {return __v_;} \
901 };
902#else // _LIBCPP_HAS_NO_STRONG_ENUMS
903# define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class _LIBCPP_ENUM_VIS x
904# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x)
905#endif // _LIBCPP_HAS_NO_STRONG_ENUMS
906
907// _LIBCPP_DEBUG potential values:
908// - undefined: No assertions. This is the default.
909// - 0: Basic assertions
910// - 1: Basic assertions + iterator validity checks + unspecified behavior randomization.
911# if !defined(_LIBCPP_DEBUG)
912# define _LIBCPP_DEBUG_LEVEL 0
913# elif _LIBCPP_DEBUG == 0
914# define _LIBCPP_DEBUG_LEVEL 1
915# elif _LIBCPP_DEBUG == 1
916# define _LIBCPP_DEBUG_LEVEL 2
704# if __has_attribute(using_if_exists)
705# define _LIBCPP_USING_IF_EXISTS __attribute__((using_if_exists))
917706# else
918# error Supported values for _LIBCPP_DEBUG are 0 and 1
707# define _LIBCPP_USING_IF_EXISTS
919708# endif
920709
921# if _LIBCPP_DEBUG_LEVEL >= 2 && !defined(_LIBCPP_CXX03_LANG)
922# define _LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY
710# ifdef _LIBCPP_CXX03_LANG
711# define _LIBCPP_DECLARE_STRONG_ENUM(x) \
712 struct _LIBCPP_TYPE_VIS x { \
713 enum __lx
714// clang-format off
715# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) \
716 __lx __v_; \
717 _LIBCPP_INLINE_VISIBILITY x(__lx __v) : __v_(__v) {} \
718 _LIBCPP_INLINE_VISIBILITY explicit x(int __v) : __v_(static_cast<__lx>(__v)) {} \
719 _LIBCPP_INLINE_VISIBILITY operator int() const { return __v_; } \
720 };
721// clang-format on
722
723# else // _LIBCPP_CXX03_LANG
724# define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class _LIBCPP_ENUM_VIS x
725# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x)
726# endif // _LIBCPP_CXX03_LANG
727
728# if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || defined(__sun__) || \
729 defined(__NetBSD__)
730# define _LIBCPP_LOCALE__L_EXTENSIONS 1
923731# endif
924732
925# if defined(_LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY)
926# if defined(_LIBCPP_CXX03_LANG)
927# error Support for unspecified stability is only for C++11 and higher
928# endif
929# define _LIBCPP_DEBUG_RANDOMIZE_RANGE(__first, __last) \
930 do { \
931 if (!__builtin_is_constant_evaluated()) \
932 _VSTD::shuffle(__first, __last, __libcpp_debug_randomizer()); \
933 } while (false)
934# else
935# define _LIBCPP_DEBUG_RANDOMIZE_RANGE(__first, __last) \
936 do { \
937 } while (false)
733# ifdef __FreeBSD__
734# define _DECLARE_C99_LDBL_MATH 1
938735# endif
939736
940// Libc++ allows disabling extern template instantiation declarations by
941// means of users defining _LIBCPP_DISABLE_EXTERN_TEMPLATE.
942//
943// Furthermore, when the Debug mode is enabled, we disable extern declarations
944// when building user code because we don't want to use the functions compiled
945// in the library, which might not have had the debug mode enabled when built.
946// However, some extern declarations need to be used, because code correctness
947// depends on it (several instances in <locale>). Those special declarations
948// are declared with _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE, which is enabled
949// even when the debug mode is enabled.
950#if defined(_LIBCPP_DISABLE_EXTERN_TEMPLATE)
951# define _LIBCPP_EXTERN_TEMPLATE(...) /* nothing */
952# define _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(...) /* nothing */
953#elif _LIBCPP_DEBUG_LEVEL >= 1 && !defined(_LIBCPP_BUILDING_LIBRARY)
954# define _LIBCPP_EXTERN_TEMPLATE(...) /* nothing */
955# define _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(...) extern template __VA_ARGS__;
956#else
957# define _LIBCPP_EXTERN_TEMPLATE(...) extern template __VA_ARGS__;
958# define _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(...) extern template __VA_ARGS__;
959#endif
960
961#if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || \
962 defined(__sun__) || defined(__NetBSD__)
963#define _LIBCPP_LOCALE__L_EXTENSIONS 1
964#endif
965
966#ifdef __FreeBSD__
967#define _DECLARE_C99_LDBL_MATH 1
968#endif
969
970737// If we are getting operator new from the MSVC CRT, then allocation overloads
971738// for align_val_t were added in 19.12, aka VS 2017 version 15.3.
972#if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912
973# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
974#elif defined(_LIBCPP_ABI_VCRUNTIME) && !defined(__cpp_aligned_new)
975 // We're deferring to Microsoft's STL to provide aligned new et al. We don't
976 // have it unless the language feature test macro is defined.
977# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
978#elif defined(__MVS__)
979# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
980#endif
739# if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912
740# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
741# elif defined(_LIBCPP_ABI_VCRUNTIME) && !defined(__cpp_aligned_new)
742// We're deferring to Microsoft's STL to provide aligned new et al. We don't
743// have it unless the language feature test macro is defined.
744# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
745# elif defined(__MVS__)
746# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
747# endif
981748
982#if defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) || \
983 (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606)
984# define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
985#endif
749# if defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) || (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606)
750# define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
751# endif
986752
987#if defined(__APPLE__) || defined(__FreeBSD__)
988#define _LIBCPP_HAS_DEFAULTRUNELOCALE
989#endif
753# if defined(__APPLE__) || defined(__FreeBSD__)
754# define _LIBCPP_HAS_DEFAULTRUNELOCALE
755# endif
990756
991#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__sun__)
992#define _LIBCPP_WCTYPE_IS_MASK
993#endif
757# if defined(__APPLE__) || defined(__FreeBSD__) || defined(__sun__)
758# define _LIBCPP_WCTYPE_IS_MASK
759# endif
994760
995#if _LIBCPP_STD_VER <= 17 || !defined(__cpp_char8_t)
996#define _LIBCPP_HAS_NO_CHAR8_T
997#endif
761# if _LIBCPP_STD_VER <= 17 || !defined(__cpp_char8_t)
762# define _LIBCPP_HAS_NO_CHAR8_T
763# endif
998764
999765// Deprecation macros.
1000766//
1001767// Deprecations warnings are always enabled, except when users explicitly opt-out
1002768// by defining _LIBCPP_DISABLE_DEPRECATION_WARNINGS.
1003#if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS)
1004# if __has_attribute(deprecated)
1005# define _LIBCPP_DEPRECATED __attribute__ ((deprecated))
1006# elif _LIBCPP_STD_VER > 11
1007# define _LIBCPP_DEPRECATED [[deprecated]]
769# if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS)
770# if __has_attribute(deprecated)
771# define _LIBCPP_DEPRECATED __attribute__((deprecated))
772# define _LIBCPP_DEPRECATED_(m) __attribute__((deprected(m)))
773# elif _LIBCPP_STD_VER > 11
774# define _LIBCPP_DEPRECATED [[deprecated]]
775# define _LIBCPP_DEPRECATED_(m) [[deprecated(m)]]
776# else
777# define _LIBCPP_DEPRECATED
778# define _LIBCPP_DEPRECATED_(m)
779# endif
1008780# else
1009781# define _LIBCPP_DEPRECATED
782# define _LIBCPP_DEPRECATED_(m)
1010783# endif
1011#else
1012# define _LIBCPP_DEPRECATED
1013#endif
1014784
1015#if !defined(_LIBCPP_CXX03_LANG)
1016# define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED
1017#else
1018# define _LIBCPP_DEPRECATED_IN_CXX11
1019#endif
785# if !defined(_LIBCPP_CXX03_LANG)
786# define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED
787# else
788# define _LIBCPP_DEPRECATED_IN_CXX11
789# endif
1020790
1021#if _LIBCPP_STD_VER >= 14
1022# define _LIBCPP_DEPRECATED_IN_CXX14 _LIBCPP_DEPRECATED
1023#else
1024# define _LIBCPP_DEPRECATED_IN_CXX14
1025#endif
791# if _LIBCPP_STD_VER > 11
792# define _LIBCPP_DEPRECATED_IN_CXX14 _LIBCPP_DEPRECATED
793# else
794# define _LIBCPP_DEPRECATED_IN_CXX14
795# endif
1026796
1027#if _LIBCPP_STD_VER >= 17
1028# define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED
1029#else
1030# define _LIBCPP_DEPRECATED_IN_CXX17
1031#endif
797# if _LIBCPP_STD_VER > 14
798# define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED
799# else
800# define _LIBCPP_DEPRECATED_IN_CXX17
801# endif
1032802
1033#if _LIBCPP_STD_VER > 17
1034# define _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_DEPRECATED
1035#else
1036# define _LIBCPP_DEPRECATED_IN_CXX20
1037#endif
803# if _LIBCPP_STD_VER > 17
804# define _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_DEPRECATED
805# else
806# define _LIBCPP_DEPRECATED_IN_CXX20
807# endif
1038808
1039#if !defined(_LIBCPP_HAS_NO_CHAR8_T)
1040# define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED
1041#else
1042# define _LIBCPP_DEPRECATED_WITH_CHAR8_T
1043#endif
809# if !defined(_LIBCPP_HAS_NO_CHAR8_T)
810# define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED
811# else
812# define _LIBCPP_DEPRECATED_WITH_CHAR8_T
813# endif
1044814
1045815// Macros to enter and leave a state where deprecation warnings are suppressed.
1046#if defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_COMPILER_GCC)
1047# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \
1048 _Pragma("GCC diagnostic push") \
1049 _Pragma("GCC diagnostic ignored \"-Wdeprecated\"") \
1050 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
1051# define _LIBCPP_SUPPRESS_DEPRECATED_POP \
1052 _Pragma("GCC diagnostic pop")
1053#else
1054# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH
1055# define _LIBCPP_SUPPRESS_DEPRECATED_POP
1056#endif
816# if defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_COMPILER_GCC)
817# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \
818 _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdeprecated\"") \
819 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
820# define _LIBCPP_SUPPRESS_DEPRECATED_POP _Pragma("GCC diagnostic pop")
821# else
822# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH
823# define _LIBCPP_SUPPRESS_DEPRECATED_POP
824# endif
1057825
1058#if _LIBCPP_STD_VER <= 11
1059# define _LIBCPP_EXPLICIT_AFTER_CXX11
1060#else
1061# define _LIBCPP_EXPLICIT_AFTER_CXX11 explicit
1062#endif
826# if _LIBCPP_STD_VER <= 11
827# define _LIBCPP_EXPLICIT_AFTER_CXX11
828# else
829# define _LIBCPP_EXPLICIT_AFTER_CXX11 explicit
830# endif
1063831
1064#if _LIBCPP_STD_VER > 11
1065# define _LIBCPP_CONSTEXPR_AFTER_CXX11 constexpr
1066#else
1067# define _LIBCPP_CONSTEXPR_AFTER_CXX11
1068#endif
832# if _LIBCPP_STD_VER > 11
833# define _LIBCPP_CONSTEXPR_AFTER_CXX11 constexpr
834# else
835# define _LIBCPP_CONSTEXPR_AFTER_CXX11
836# endif
1069837
1070#if _LIBCPP_STD_VER > 14
1071# define _LIBCPP_CONSTEXPR_AFTER_CXX14 constexpr
1072#else
1073# define _LIBCPP_CONSTEXPR_AFTER_CXX14
1074#endif
838# if _LIBCPP_STD_VER > 14
839# define _LIBCPP_CONSTEXPR_AFTER_CXX14 constexpr
840# else
841# define _LIBCPP_CONSTEXPR_AFTER_CXX14
842# endif
1075843
1076#if _LIBCPP_STD_VER > 17
1077# define _LIBCPP_CONSTEXPR_AFTER_CXX17 constexpr
1078#else
1079# define _LIBCPP_CONSTEXPR_AFTER_CXX17
1080#endif
844# if _LIBCPP_STD_VER > 17
845# define _LIBCPP_CONSTEXPR_AFTER_CXX17 constexpr
846# else
847# define _LIBCPP_CONSTEXPR_AFTER_CXX17
848# endif
1081849
1082#if __has_cpp_attribute(nodiscard) || defined(_LIBCPP_COMPILER_MSVC)
1083# define _LIBCPP_NODISCARD [[nodiscard]]
1084#elif defined(_LIBCPP_COMPILER_CLANG_BASED) && !defined(_LIBCPP_CXX03_LANG)
1085# define _LIBCPP_NODISCARD [[clang::warn_unused_result]]
1086#else
850# if __has_cpp_attribute(nodiscard) || defined(_LIBCPP_COMPILER_MSVC)
851# define _LIBCPP_NODISCARD [[nodiscard]]
852# elif defined(_LIBCPP_COMPILER_CLANG_BASED) && !defined(_LIBCPP_CXX03_LANG)
853# define _LIBCPP_NODISCARD [[clang::warn_unused_result]]
854# else
1087855// We can't use GCC's [[gnu::warn_unused_result]] and
1088856// __attribute__((warn_unused_result)), because GCC does not silence them via
1089857// (void) cast.
1090# define _LIBCPP_NODISCARD
1091#endif
858# define _LIBCPP_NODISCARD
859# endif
1092860
1093861// _LIBCPP_NODISCARD_EXT may be used to apply [[nodiscard]] to entities not
1094862// specified as such as an extension.
1095#if defined(_LIBCPP_ENABLE_NODISCARD) && !defined(_LIBCPP_DISABLE_NODISCARD_EXT)
1096# define _LIBCPP_NODISCARD_EXT _LIBCPP_NODISCARD
1097#else
1098# define _LIBCPP_NODISCARD_EXT
1099#endif
863# if defined(_LIBCPP_ENABLE_NODISCARD) && !defined(_LIBCPP_DISABLE_NODISCARD_EXT)
864# define _LIBCPP_NODISCARD_EXT _LIBCPP_NODISCARD
865# else
866# define _LIBCPP_NODISCARD_EXT
867# endif
1100868
1101#if !defined(_LIBCPP_DISABLE_NODISCARD_AFTER_CXX17) && \
1102 (_LIBCPP_STD_VER > 17 || defined(_LIBCPP_ENABLE_NODISCARD))
1103# define _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_NODISCARD
1104#else
1105# define _LIBCPP_NODISCARD_AFTER_CXX17
1106#endif
869# if !defined(_LIBCPP_DISABLE_NODISCARD_AFTER_CXX17) && (_LIBCPP_STD_VER > 17 || defined(_LIBCPP_ENABLE_NODISCARD))
870# define _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_NODISCARD
871# else
872# define _LIBCPP_NODISCARD_AFTER_CXX17
873# endif
1107874
1108#if __has_attribute(no_destroy)
1109# define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__))
1110#else
1111# define _LIBCPP_NO_DESTROY
1112#endif
875# if __has_attribute(no_destroy)
876# define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__))
877# else
878# define _LIBCPP_NO_DESTROY
879# endif
1113880
1114#ifndef _LIBCPP_HAS_NO_ASAN
1115extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
1116 const void *, const void *, const void *, const void *);
1117#endif
881# ifndef _LIBCPP_HAS_NO_ASAN
882 extern "C" _LIBCPP_FUNC_VIS void
883 __sanitizer_annotate_contiguous_container(const void*, const void*, const void*, const void*);
884# endif
1118885
1119886// Try to find out if RTTI is disabled.
1120#if defined(_LIBCPP_COMPILER_CLANG_BASED) && !__has_feature(cxx_rtti)
1121# define _LIBCPP_NO_RTTI
1122#elif defined(__GNUC__) && !defined(__GXX_RTTI)
1123# define _LIBCPP_NO_RTTI
1124#elif defined(_LIBCPP_COMPILER_MSVC) && !defined(_CPPRTTI)
1125# define _LIBCPP_NO_RTTI
1126#endif
887# if !defined(__cpp_rtti) || __cpp_rtti < 199711L
888# define _LIBCPP_NO_RTTI
889# endif
1127890
1128#ifndef _LIBCPP_WEAK
1129#define _LIBCPP_WEAK __attribute__((__weak__))
1130#endif
891# ifndef _LIBCPP_WEAK
892# define _LIBCPP_WEAK __attribute__((__weak__))
893# endif
1131894
1132895// Thread API
1133#if !defined(_LIBCPP_HAS_NO_THREADS) && \
1134 !defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && \
1135 !defined(_LIBCPP_HAS_THREAD_API_WIN32) && \
1136 !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
1137# if defined(__FreeBSD__) || \
1138 defined(__wasi__) || \
1139 defined(__NetBSD__) || \
1140 defined(__OpenBSD__) || \
1141 defined(__NuttX__) || \
1142 defined(__linux__) || \
1143 defined(__GNU__) || \
1144 defined(__APPLE__) || \
1145 defined(__sun__) || \
1146 defined(__MVS__) || \
1147 defined(_AIX)
1148# define _LIBCPP_HAS_THREAD_API_PTHREAD
1149# elif defined(__Fuchsia__)
1150 // TODO(44575): Switch to C11 thread API when possible.
1151# define _LIBCPP_HAS_THREAD_API_PTHREAD
1152# elif defined(_LIBCPP_WIN32API)
1153# define _LIBCPP_HAS_THREAD_API_WIN32
1154# else
1155# error "No thread API"
1156# endif // _LIBCPP_HAS_THREAD_API
1157#endif // _LIBCPP_HAS_NO_THREADS
1158
1159#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
1160#if defined(__ANDROID__) && __ANDROID_API__ >= 30
1161#define _LIBCPP_HAS_COND_CLOCKWAIT
1162#elif defined(_LIBCPP_GLIBC_PREREQ)
1163#if _LIBCPP_GLIBC_PREREQ(2, 30)
1164#define _LIBCPP_HAS_COND_CLOCKWAIT
1165#endif
1166#endif
1167#endif
896// clang-format off
897# if !defined(_LIBCPP_HAS_NO_THREADS) && \
898 !defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && \
899 !defined(_LIBCPP_HAS_THREAD_API_WIN32) && \
900 !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
901
902# if defined(__FreeBSD__) || \
903 defined(__wasi__) || \
904 defined(__NetBSD__) || \
905 defined(__OpenBSD__) || \
906 defined(__NuttX__) || \
907 defined(__linux__) || \
908 defined(__GNU__) || \
909 defined(__APPLE__) || \
910 defined(__sun__) || \
911 defined(__MVS__) || \
912 defined(_AIX) || \
913 defined(__EMSCRIPTEN__)
914// clang-format on
915# define _LIBCPP_HAS_THREAD_API_PTHREAD
916# elif defined(__Fuchsia__)
917// TODO(44575): Switch to C11 thread API when possible.
918# define _LIBCPP_HAS_THREAD_API_PTHREAD
919# elif defined(_LIBCPP_WIN32API)
920# define _LIBCPP_HAS_THREAD_API_WIN32
921# else
922# error "No thread API"
923# endif // _LIBCPP_HAS_THREAD_API
924# endif // _LIBCPP_HAS_NO_THREADS
925
926# if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
927# if defined(__ANDROID__) && __ANDROID_API__ >= 30
928# define _LIBCPP_HAS_COND_CLOCKWAIT
929# elif defined(_LIBCPP_GLIBC_PREREQ)
930# if _LIBCPP_GLIBC_PREREQ(2, 30)
931# define _LIBCPP_HAS_COND_CLOCKWAIT
932# endif
933# endif
934# endif
1168935
1169#if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
1170#error _LIBCPP_HAS_THREAD_API_PTHREAD may only be defined when \
936# if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
937# error _LIBCPP_HAS_THREAD_API_PTHREAD may only be defined when \
1171938 _LIBCPP_HAS_NO_THREADS is not defined.
1172#endif
939# endif
1173940
1174#if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
1175#error _LIBCPP_HAS_THREAD_API_EXTERNAL may not be defined when \
941# if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
942# error _LIBCPP_HAS_THREAD_API_EXTERNAL may not be defined when \
1176943 _LIBCPP_HAS_NO_THREADS is defined.
1177#endif
944# endif
1178945
1179#if defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK) && !defined(_LIBCPP_HAS_NO_THREADS)
1180#error _LIBCPP_HAS_NO_MONOTONIC_CLOCK may only be defined when \
946# if defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK) && !defined(_LIBCPP_HAS_NO_THREADS)
947# error _LIBCPP_HAS_NO_MONOTONIC_CLOCK may only be defined when \
1181948 _LIBCPP_HAS_NO_THREADS is defined.
1182#endif
949# endif
1183950
1184#if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(__STDCPP_THREADS__)
1185#define __STDCPP_THREADS__ 1
1186#endif
951# if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(__STDCPP_THREADS__)
952# define __STDCPP_THREADS__ 1
953# endif
1187954
1188955// The glibc and Bionic implementation of pthreads implements
1189956// pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32
......@@ -1195,11 +962,13 @@ extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
1195962//
1196963// TODO(EricWF): Enable this optimization on Bionic after speaking to their
1197964// respective stakeholders.
1198#if (defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && defined(__GLIBC__)) \
1199 || (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) \
1200 || defined(_LIBCPP_HAS_THREAD_API_WIN32)
1201# define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION
1202#endif
965// clang-format off
966# if (defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && defined(__GLIBC__)) || \
967 (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || \
968 defined(_LIBCPP_HAS_THREAD_API_WIN32)
969// clang-format on
970# define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION
971# endif
1203972
1204973// Destroying a condvar is a nop on Windows.
1205974//
......@@ -1209,225 +978,245 @@ extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
1209978//
1210979// TODO(EricWF): This is potentially true for some pthread implementations
1211980// as well.
1212#if (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || \
1213 defined(_LIBCPP_HAS_THREAD_API_WIN32)
1214# define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION
1215#endif
981# if (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || defined(_LIBCPP_HAS_THREAD_API_WIN32)
982# define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION
983# endif
1216984
1217985// Some systems do not provide gets() in their C library, for security reasons.
1218#if defined(_LIBCPP_MSVCRT) || \
1219 (defined(__FreeBSD_version) && __FreeBSD_version >= 1300043) || \
1220 defined(__OpenBSD__)
1221# define _LIBCPP_C_HAS_NO_GETS
1222#endif
1223
1224#if defined(__BIONIC__) || defined(__NuttX__) || \
1225 defined(__Fuchsia__) || defined(__wasi__) || \
1226 defined(_LIBCPP_HAS_MUSL_LIBC) || defined(__OpenBSD__)
1227#define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
1228#endif
986# if defined(_LIBCPP_MSVCRT) || (defined(__FreeBSD_version) && __FreeBSD_version >= 1300043) || defined(__OpenBSD__)
987# define _LIBCPP_C_HAS_NO_GETS
988# endif
1229989
1230#if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic)
1231# define _LIBCPP_HAS_C_ATOMIC_IMP
1232#elif defined(_LIBCPP_COMPILER_GCC)
1233# define _LIBCPP_HAS_GCC_ATOMIC_IMP
1234#endif
990# if defined(__BIONIC__) || defined(__NuttX__) || defined(__Fuchsia__) || defined(__wasi__) || \
991 defined(_LIBCPP_HAS_MUSL_LIBC) || defined(__OpenBSD__)
992# define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
993# endif
1235994
1236#if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && \
1237 !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) && \
1238 !defined(_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP)
1239# define _LIBCPP_HAS_NO_ATOMIC_HEADER
1240#else
1241# ifndef _LIBCPP_ATOMIC_FLAG_TYPE
1242# define _LIBCPP_ATOMIC_FLAG_TYPE bool
995# if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic)
996# define _LIBCPP_HAS_C_ATOMIC_IMP
997# elif defined(_LIBCPP_COMPILER_GCC)
998# define _LIBCPP_HAS_GCC_ATOMIC_IMP
1243999# endif
1244# ifdef _LIBCPP_FREESTANDING
1245# define _LIBCPP_ATOMIC_ONLY_USE_BUILTINS
1000
1001# if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) && \
1002 !defined(_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP)
1003# define _LIBCPP_HAS_NO_ATOMIC_HEADER
1004# else
1005# ifndef _LIBCPP_ATOMIC_FLAG_TYPE
1006# define _LIBCPP_ATOMIC_FLAG_TYPE bool
1007# endif
1008# ifdef _LIBCPP_FREESTANDING
1009# define _LIBCPP_ATOMIC_ONLY_USE_BUILTINS
1010# endif
12461011# endif
1247#endif
12481012
1249#ifndef _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1250#define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1251#endif
1013# ifndef _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1014# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1015# endif
12521016
1253#if defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS)
1254# if defined(__clang__) && __has_attribute(acquire_capability)
1017# if defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS)
1018# if defined(__clang__) && __has_attribute(acquire_capability)
12551019// Work around the attribute handling in clang. When both __declspec and
12561020// __attribute__ are present, the processing goes awry preventing the definition
12571021// of the types. In MinGW mode, __declspec evaluates to __attribute__, and thus
12581022// combining the two does work.
1259# if !defined(_MSC_VER)
1260# define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
1023# if !defined(_MSC_VER)
1024# define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
1025# endif
12611026# endif
12621027# endif
1263#endif
12641028
1265#ifdef _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
1266# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) __attribute__((x))
1267#else
1268# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x)
1269#endif
1029# ifdef _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
1030# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) __attribute__((x))
1031# else
1032# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x)
1033# endif
12701034
1271#if __has_attribute(require_constant_initialization)
1272# define _LIBCPP_SAFE_STATIC __attribute__((__require_constant_initialization__))
1273#else
1274# define _LIBCPP_SAFE_STATIC
1275#endif
1035# if _LIBCPP_STD_VER > 17
1036# define _LIBCPP_CONSTINIT constinit
1037# elif __has_attribute(require_constant_initialization)
1038# define _LIBCPP_CONSTINIT __attribute__((__require_constant_initialization__))
1039# else
1040# define _LIBCPP_CONSTINIT
1041# endif
12761042
1277#if __has_attribute(diagnose_if) && !defined(_LIBCPP_DISABLE_ADDITIONAL_DIAGNOSTICS)
1278# define _LIBCPP_DIAGNOSE_WARNING(...) \
1279 __attribute__((diagnose_if(__VA_ARGS__, "warning")))
1280# define _LIBCPP_DIAGNOSE_ERROR(...) \
1281 __attribute__((diagnose_if(__VA_ARGS__, "error")))
1282#else
1283# define _LIBCPP_DIAGNOSE_WARNING(...)
1284# define _LIBCPP_DIAGNOSE_ERROR(...)
1285#endif
1043# if __has_attribute(diagnose_if) && !defined(_LIBCPP_DISABLE_ADDITIONAL_DIAGNOSTICS)
1044# define _LIBCPP_DIAGNOSE_WARNING(...) __attribute__((diagnose_if(__VA_ARGS__, "warning")))
1045# define _LIBCPP_DIAGNOSE_ERROR(...) __attribute__((diagnose_if(__VA_ARGS__, "error")))
1046# else
1047# define _LIBCPP_DIAGNOSE_WARNING(...)
1048# define _LIBCPP_DIAGNOSE_ERROR(...)
1049# endif
12861050
12871051// Use a function like macro to imply that it must be followed by a semicolon
1288#if __cplusplus > 201402L && __has_cpp_attribute(fallthrough)
1289# define _LIBCPP_FALLTHROUGH() [[fallthrough]]
1290#elif __has_cpp_attribute(clang::fallthrough)
1291# define _LIBCPP_FALLTHROUGH() [[clang::fallthrough]]
1292#elif __has_attribute(__fallthrough__)
1293# define _LIBCPP_FALLTHROUGH() __attribute__((__fallthrough__))
1294#else
1295# define _LIBCPP_FALLTHROUGH() ((void)0)
1296#endif
1052# if __has_cpp_attribute(fallthrough)
1053# define _LIBCPP_FALLTHROUGH() [[fallthrough]]
1054# elif __has_attribute(__fallthrough__)
1055# define _LIBCPP_FALLTHROUGH() __attribute__((__fallthrough__))
1056# else
1057# define _LIBCPP_FALLTHROUGH() ((void)0)
1058# endif
12971059
1298#if __has_attribute(__nodebug__)
1299#define _LIBCPP_NODEBUG __attribute__((__nodebug__))
1300#else
1301#define _LIBCPP_NODEBUG
1302#endif
1060# if __has_attribute(__nodebug__)
1061# define _LIBCPP_NODEBUG __attribute__((__nodebug__))
1062# else
1063# define _LIBCPP_NODEBUG
1064# endif
13031065
1304#if __has_attribute(__standalone_debug__)
1305#define _LIBCPP_STANDALONE_DEBUG __attribute__((__standalone_debug__))
1306#else
1307#define _LIBCPP_STANDALONE_DEBUG
1308#endif
1066# if __has_attribute(__standalone_debug__)
1067# define _LIBCPP_STANDALONE_DEBUG __attribute__((__standalone_debug__))
1068# else
1069# define _LIBCPP_STANDALONE_DEBUG
1070# endif
13091071
1310#if __has_attribute(__preferred_name__)
1311#define _LIBCPP_PREFERRED_NAME(x) __attribute__((__preferred_name__(x)))
1312#else
1313#define _LIBCPP_PREFERRED_NAME(x)
1314#endif
1072# if __has_attribute(__preferred_name__)
1073# define _LIBCPP_PREFERRED_NAME(x) __attribute__((__preferred_name__(x)))
1074# else
1075# define _LIBCPP_PREFERRED_NAME(x)
1076# endif
13151077
13161078// We often repeat things just for handling wide characters in the library.
13171079// When wide characters are disabled, it can be useful to have a quick way of
13181080// disabling it without having to resort to #if-#endif, which has a larger
13191081// impact on readability.
1320#if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
1321# define _LIBCPP_IF_WIDE_CHARACTERS(...)
1322#else
1323# define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__
1324#endif
1325
1326#if defined(_LIBCPP_ABI_MICROSOFT) && \
1327 (defined(_LIBCPP_COMPILER_MSVC) || __has_declspec_attribute(empty_bases))
1328# define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases)
1329#else
1330# define _LIBCPP_DECLSPEC_EMPTY_BASES
1331#endif
1332
1333#if defined(_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES)
1334#define _LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR
1335#define _LIBCPP_ENABLE_CXX17_REMOVED_BINDERS
1336#define _LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE
1337#define _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS
1338#endif // _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES
1339
1340#if defined(_LIBCPP_ENABLE_CXX20_REMOVED_FEATURES)
1341#define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS
1342#define _LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS
1343#define _LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS
1344#define _LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR
1345#define _LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS
1346#endif // _LIBCPP_ENABLE_CXX20_REMOVED_FEATURES
1347
1348#if !defined(__cpp_impl_coroutine) || __cpp_impl_coroutine < 201902L
1349#define _LIBCPP_HAS_NO_CXX20_COROUTINES
1350#endif
1351
1352#if defined(_LIBCPP_COMPILER_IBM)
1353#define _LIBCPP_HAS_NO_PRAGMA_PUSH_POP_MACRO
1354#endif
1082# if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
1083# define _LIBCPP_IF_WIDE_CHARACTERS(...)
1084# else
1085# define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__
1086# endif
13551087
1356#if defined(_LIBCPP_HAS_NO_PRAGMA_PUSH_POP_MACRO)
1357# define _LIBCPP_PUSH_MACROS
1358# define _LIBCPP_POP_MACROS
1359#else
1360 // Don't warn about macro conflicts when we can restore them at the
1361 // end of the header.
1362# ifndef _LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS
1363# define _LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS
1364# endif
1365# if defined(_LIBCPP_COMPILER_MSVC)
1366# define _LIBCPP_PUSH_MACROS \
1367 __pragma(push_macro("min")) \
1368 __pragma(push_macro("max"))
1369# define _LIBCPP_POP_MACROS \
1370 __pragma(pop_macro("min")) \
1371 __pragma(pop_macro("max"))
1088# if defined(_LIBCPP_ABI_MICROSOFT) && (defined(_LIBCPP_COMPILER_MSVC) || __has_declspec_attribute(empty_bases))
1089# define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases)
13721090# else
1373# define _LIBCPP_PUSH_MACROS \
1374 _Pragma("push_macro(\"min\")") \
1375 _Pragma("push_macro(\"max\")")
1376# define _LIBCPP_POP_MACROS \
1377 _Pragma("pop_macro(\"min\")") \
1378 _Pragma("pop_macro(\"max\")")
1091# define _LIBCPP_DECLSPEC_EMPTY_BASES
13791092# endif
1380#endif // defined(_LIBCPP_HAS_NO_PRAGMA_PUSH_POP_MACRO)
13811093
1382#ifndef _LIBCPP_NO_AUTO_LINK
1383# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
1384# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
1385# pragma comment(lib, "c++.lib")
1386# else
1387# pragma comment(lib, "libc++.lib")
1388# endif
1389# endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
1390#endif // _LIBCPP_NO_AUTO_LINK
1094# if defined(_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES)
1095# define _LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR
1096# define _LIBCPP_ENABLE_CXX17_REMOVED_BINDERS
1097# define _LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE
1098# define _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS
1099# define _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION
1100# endif // _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES
1101
1102# if defined(_LIBCPP_ENABLE_CXX20_REMOVED_FEATURES)
1103# define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS
1104# define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_VOID_SPECIALIZATION
1105# define _LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS
1106# define _LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS
1107# define _LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR
1108# define _LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS
1109# endif // _LIBCPP_ENABLE_CXX20_REMOVED_FEATURES
1110
1111# if !defined(__cpp_impl_coroutine) || __cpp_impl_coroutine < 201902L
1112# define _LIBCPP_HAS_NO_CXX20_COROUTINES
1113# endif
1114
1115# define _LIBCPP_PUSH_MACROS _Pragma("push_macro(\"min\")") _Pragma("push_macro(\"max\")")
1116# define _LIBCPP_POP_MACROS _Pragma("pop_macro(\"min\")") _Pragma("pop_macro(\"max\")")
1117
1118# ifndef _LIBCPP_NO_AUTO_LINK
1119# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
1120# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
1121# pragma comment(lib, "c++.lib")
1122# else
1123# pragma comment(lib, "libc++.lib")
1124# endif
1125# endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
1126# endif // _LIBCPP_NO_AUTO_LINK
13911127
13921128// Configures the fopen close-on-exec mode character, if any. This string will
13931129// be appended to any mode string used by fstream for fopen/fdopen.
13941130//
13951131// Not all platforms support this, but it helps avoid fd-leaks on platforms that
13961132// do.
1397#if defined(__BIONIC__)
1398# define _LIBCPP_FOPEN_CLOEXEC_MODE "e"
1399#else
1400# define _LIBCPP_FOPEN_CLOEXEC_MODE
1401#endif
1133# if defined(__BIONIC__)
1134# define _LIBCPP_FOPEN_CLOEXEC_MODE "e"
1135# else
1136# define _LIBCPP_FOPEN_CLOEXEC_MODE
1137# endif
14021138
14031139// Support for _FILE_OFFSET_BITS=64 landed gradually in Android, so the full set
14041140// of functions used in cstdio may not be available for low API levels when
14051141// using 64-bit file offsets on LP32.
1406#if defined(__BIONIC__) && defined(__USE_FILE_OFFSET64) && __ANDROID_API__ < 24
1407#define _LIBCPP_HAS_NO_FGETPOS_FSETPOS
1408#endif
1142# if defined(__BIONIC__) && defined(__USE_FILE_OFFSET64) && __ANDROID_API__ < 24
1143# define _LIBCPP_HAS_NO_FGETPOS_FSETPOS
1144# endif
14091145
1410#if __has_attribute(init_priority)
1411 // TODO: Remove this once we drop support for building libc++ with old Clangs
1412# if (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER < 1200) || \
1413 (defined(__apple_build_version__) && __apple_build_version__ < 13000000)
1414# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(101)))
1415# else
1416# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(100)))
1417# endif
1418#else
1419# define _LIBCPP_INIT_PRIORITY_MAX
1420#endif
1146# if __has_attribute(init_priority)
1147// TODO: Remove this once we drop support for building libc++ with old Clangs
1148# if (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER < 1200) || \
1149 (defined(__apple_build_version__) && __apple_build_version__ < 13000000)
1150# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(101)))
1151# else
1152# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(100)))
1153# endif
1154# else
1155# define _LIBCPP_INIT_PRIORITY_MAX
1156# endif
14211157
1422#if defined(__GNUC__) || defined(__clang__)
1423 // The attribute uses 1-based indices for ordinary and static member functions.
1424 // The attribute uses 2-based indices for non-static member functions.
1425# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) \
1426 __attribute__((__format__(archetype, format_string_index, first_format_arg_index)))
1427#else
1428# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */
1429#endif
1158# if defined(__GNUC__) || defined(__clang__)
1159// The attribute uses 1-based indices for ordinary and static member functions.
1160// The attribute uses 2-based indices for non-static member functions.
1161# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) \
1162 __attribute__((__format__(archetype, format_string_index, first_format_arg_index)))
1163# else
1164# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */
1165# endif
1166
1167# if __has_cpp_attribute(msvc::no_unique_address)
1168// MSVC implements [[no_unique_address]] as a silent no-op currently.
1169// (If/when MSVC breaks its C++ ABI, it will be changed to work as intended.)
1170// However, MSVC implements [[msvc::no_unique_address]] which does what
1171// [[no_unique_address]] is supposed to do, in general.
1172
1173// Clang-cl does not yet (14.0) implement either [[no_unique_address]] or
1174// [[msvc::no_unique_address]] though. If/when it does implement
1175// [[msvc::no_unique_address]], this should be preferred though.
1176# define _LIBCPP_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
1177# elif __has_cpp_attribute(no_unique_address)
1178# define _LIBCPP_NO_UNIQUE_ADDRESS [[no_unique_address]]
1179# else
1180# define _LIBCPP_NO_UNIQUE_ADDRESS /* nothing */
1181// Note that this can be replaced by #error as soon as clang-cl
1182// implements msvc::no_unique_address, since there should be no C++20
1183// compiler that doesn't support one of the two attributes at that point.
1184// We generally don't want to use this macro outside of C++20-only code,
1185// because using it conditionally in one language version only would make
1186// the ABI inconsistent.
1187# endif
1188
1189# ifdef _LIBCPP_COMPILER_CLANG_BASED
1190# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
1191# define _LIBCPP_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
1192# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(clang diagnostic ignored str))
1193# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str)
1194# elif defined(_LIBCPP_COMPILER_GCC)
1195# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
1196# define _LIBCPP_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
1197# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str)
1198# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(GCC diagnostic ignored str))
1199# else
1200# define _LIBCPP_DIAGNOSTIC_PUSH
1201# define _LIBCPP_DIAGNOSTIC_POP
1202# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str)
1203# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str)
1204# endif
1205
1206# if defined(_AIX) && !defined(_LIBCPP_COMPILER_GCC)
1207# define _LIBCPP_PACKED_BYTE_FOR_AIX _Pragma("pack(1)")
1208# define _LIBCPP_PACKED_BYTE_FOR_AIX_END _Pragma("pack(pop)")
1209# else
1210# define _LIBCPP_PACKED_BYTE_FOR_AIX /* empty */
1211# define _LIBCPP_PACKED_BYTE_FOR_AIX_END /* empty */
1212# endif
1213
1214# if __has_attribute(__packed__)
1215# define _LIBCPP_PACKED __attribute__((__packed__))
1216# else
1217# define _LIBCPP_PACKED
1218# endif
14301219
14311220#endif // __cplusplus
14321221
1433#endif // _LIBCPP_CONFIG
1222#endif // _LIBCPP___CONFIG
lib/libcxx/include/__coroutine/coroutine_handle.h+2-2
......@@ -9,15 +9,15 @@
99#ifndef _LIBCPP___COROUTINE_COROUTINE_HANDLE_H
1010#define _LIBCPP___COROUTINE_COROUTINE_HANDLE_H
1111
12#include <__assert>
1213#include <__config>
13#include <__debug>
1414#include <__functional/hash.h>
1515#include <__memory/addressof.h>
1616#include <compare>
1717#include <type_traits>
1818
1919#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20#pragma GCC system_header
20# pragma GCC system_header
2121#endif
2222
2323#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_COROUTINES)
lib/libcxx/include/__coroutine/coroutine_traits.h+1-1
......@@ -13,7 +13,7 @@
1313#include <type_traits>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16#pragma GCC system_header
16# pragma GCC system_header
1717#endif
1818
1919#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_COROUTINES)
lib/libcxx/include/__coroutine/noop_coroutine_handle.h+2-2
......@@ -13,7 +13,7 @@
1313#include <__coroutine/coroutine_handle.h>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16#pragma GCC system_header
16# pragma GCC system_header
1717#endif
1818
1919#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_COROUTINES)
......@@ -66,7 +66,7 @@ private:
6666 friend coroutine_handle<noop_coroutine_promise> noop_coroutine() noexcept;
6767
6868#if __has_builtin(__builtin_coro_noop)
69 _LIBCPP_HIDE_FROM_ABI coroutine_handle() noexcept {
69 _LIBCPP_HIDE_FROM_ABI coroutine_handle() noexcept {
7070 this->__handle_ = __builtin_coro_noop();
7171 }
7272
lib/libcxx/include/__coroutine/trivial_awaitables.h+1-1
......@@ -13,7 +13,7 @@
1313#include <__coroutine/coroutine_handle.h>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16#pragma GCC system_header
16# pragma GCC system_header
1717#endif
1818
1919#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_COROUTINES)
lib/libcxx/include/__debug+58-85
......@@ -7,80 +7,37 @@
77//
88//===----------------------------------------------------------------------===//
99
10#ifndef _LIBCPP_DEBUG_H
11#define _LIBCPP_DEBUG_H
10#ifndef _LIBCPP___DEBUG
11#define _LIBCPP___DEBUG
1212
13#include <__assert>
1314#include <__config>
14#include <iosfwd>
15#include <cstddef>
1516#include <type_traits>
1617
1718#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
19# pragma GCC system_header
1920#endif
2021
21#if defined(_LIBCPP_HAS_NO_NULLPTR)
22# include <cstddef>
22// Catch invalid uses of the legacy _LIBCPP_DEBUG toggle.
23#if defined(_LIBCPP_DEBUG) && _LIBCPP_DEBUG != 0 && !defined(_LIBCPP_ENABLE_DEBUG_MODE)
24# error "Enabling the debug mode now requires having configured the library with support for the debug mode"
2325#endif
2426
25#if _LIBCPP_DEBUG_LEVEL >= 1 || defined(_LIBCPP_BUILDING_LIBRARY)
26# include <cstddef>
27# include <cstdio>
28# include <cstdlib>
27#if defined(_LIBCPP_ENABLE_DEBUG_MODE) && !defined(_LIBCPP_CXX03_LANG) && !defined(_LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY)
28# define _LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY
2929#endif
3030
31#if _LIBCPP_DEBUG_LEVEL == 0
32# define _LIBCPP_DEBUG_ASSERT(x, m) ((void)0)
33# define _LIBCPP_ASSERT_IMPL(x, m) ((void)0)
34#elif _LIBCPP_DEBUG_LEVEL == 1
35# define _LIBCPP_DEBUG_ASSERT(x, m) ((void)0)
36# define _LIBCPP_ASSERT_IMPL(x, m) ((x) ? (void)0 : _VSTD::__libcpp_debug_function(_VSTD::__libcpp_debug_info(__FILE__, __LINE__, #x, m)))
37#elif _LIBCPP_DEBUG_LEVEL == 2
38# define _LIBCPP_DEBUG_ASSERT(x, m) _LIBCPP_ASSERT(__libcpp_is_constant_evaluated() || (x), m)
39# define _LIBCPP_ASSERT_IMPL(x, m) ((x) ? (void)0 : _VSTD::__libcpp_debug_function(_VSTD::__libcpp_debug_info(__FILE__, __LINE__, #x, m)))
31#ifdef _LIBCPP_ENABLE_DEBUG_MODE
32# define _LIBCPP_DEBUG_ASSERT(x, m) _LIBCPP_ASSERT(::std::__libcpp_is_constant_evaluated() || (x), m)
4033#else
41# error _LIBCPP_DEBUG_LEVEL must be one of 0, 1, 2
34# define _LIBCPP_DEBUG_ASSERT(x, m) ((void)0)
4235#endif
4336
44#if !defined(_LIBCPP_ASSERT)
45# define _LIBCPP_ASSERT(x, m) _LIBCPP_ASSERT_IMPL(x, m)
46#endif
37#if defined(_LIBCPP_ENABLE_DEBUG_MODE) || defined(_LIBCPP_BUILDING_LIBRARY)
4738
4839_LIBCPP_BEGIN_NAMESPACE_STD
4940
50struct _LIBCPP_TEMPLATE_VIS __libcpp_debug_info {
51 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
52 __libcpp_debug_info()
53 : __file_(nullptr), __line_(-1), __pred_(nullptr), __msg_(nullptr) {}
54 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
55 __libcpp_debug_info(const char* __f, int __l, const char* __p, const char* __m)
56 : __file_(__f), __line_(__l), __pred_(__p), __msg_(__m) {}
57
58 _LIBCPP_FUNC_VIS string what() const;
59
60 const char* __file_;
61 int __line_;
62 const char* __pred_;
63 const char* __msg_;
64};
65
66/// __libcpp_debug_function_type - The type of the assertion failure handler.
67typedef void(*__libcpp_debug_function_type)(__libcpp_debug_info const&);
68
69/// __libcpp_debug_function - The handler function called when a _LIBCPP_ASSERT
70/// fails.
71extern _LIBCPP_EXPORTED_FROM_ABI __libcpp_debug_function_type __libcpp_debug_function;
72
73/// __libcpp_abort_debug_function - A debug handler that aborts when called.
74_LIBCPP_NORETURN _LIBCPP_FUNC_VIS
75void __libcpp_abort_debug_function(__libcpp_debug_info const&);
76
77/// __libcpp_set_debug_function - Set the debug handler to the specified
78/// function.
79_LIBCPP_FUNC_VIS
80bool __libcpp_set_debug_function(__libcpp_debug_function_type __func);
81
82#if _LIBCPP_DEBUG_LEVEL == 2 || defined(_LIBCPP_BUILDING_LIBRARY)
83
8441struct _LIBCPP_TYPE_VIS __c_node;
8542
8643struct _LIBCPP_TYPE_VIS __i_node
......@@ -89,15 +46,9 @@ struct _LIBCPP_TYPE_VIS __i_node
8946 __i_node* __next_;
9047 __c_node* __c_;
9148
92#ifndef _LIBCPP_CXX03_LANG
9349 __i_node(const __i_node&) = delete;
9450 __i_node& operator=(const __i_node&) = delete;
95#else
96private:
97 __i_node(const __i_node&);
98 __i_node& operator=(const __i_node&);
99public:
100#endif
51
10152 _LIBCPP_INLINE_VISIBILITY
10253 __i_node(void* __i, __i_node* __next, __c_node* __c)
10354 : __i_(__i), __next_(__next), __c_(__c) {}
......@@ -112,17 +63,11 @@ struct _LIBCPP_TYPE_VIS __c_node
11263 __i_node** end_;
11364 __i_node** cap_;
11465
115#ifndef _LIBCPP_CXX03_LANG
11666 __c_node(const __c_node&) = delete;
11767 __c_node& operator=(const __c_node&) = delete;
118#else
119private:
120 __c_node(const __c_node&);
121 __c_node& operator=(const __c_node&);
122public:
123#endif
68
12469 _LIBCPP_INLINE_VISIBILITY
125 __c_node(void* __c, __c_node* __next)
70 explicit __c_node(void* __c, __c_node* __next)
12671 : __c_(__c), __next_(__next), beg_(nullptr), end_(nullptr), cap_(nullptr) {}
12772 virtual ~__c_node();
12873
......@@ -139,7 +84,7 @@ template <class _Cont>
13984struct _C_node
14085 : public __c_node
14186{
142 _C_node(void* __c, __c_node* __n)
87 explicit _C_node(void* __c, __c_node* __n)
14388 : __c_node(__c, __n) {}
14489
14590 virtual bool __dereferenceable(const void*) const;
......@@ -197,17 +142,11 @@ class _LIBCPP_TYPE_VIS __libcpp_db
197142 __i_node** __iend_;
198143 size_t __isz_;
199144
200 __libcpp_db();
145 explicit __libcpp_db();
201146public:
202#ifndef _LIBCPP_CXX03_LANG
203147 __libcpp_db(const __libcpp_db&) = delete;
204148 __libcpp_db& operator=(const __libcpp_db&) = delete;
205#else
206private:
207 __libcpp_db(const __libcpp_db&);
208 __libcpp_db& operator=(const __libcpp_db&);
209public:
210#endif
149
211150 ~__libcpp_db();
212151
213152 class __db_c_iterator;
......@@ -266,12 +205,15 @@ private:
266205_LIBCPP_FUNC_VIS __libcpp_db* __get_db();
267206_LIBCPP_FUNC_VIS const __libcpp_db* __get_const_db();
268207
208_LIBCPP_END_NAMESPACE_STD
269209
270#endif // _LIBCPP_DEBUG_LEVEL == 2 || defined(_LIBCPP_BUILDING_LIBRARY)
210#endif // defined(_LIBCPP_ENABLE_DEBUG_MODE) || defined(_LIBCPP_BUILDING_LIBRARY)
211
212_LIBCPP_BEGIN_NAMESPACE_STD
271213
272214template <class _Tp>
273215_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 inline void __debug_db_insert_c(_Tp* __c) {
274#if _LIBCPP_DEBUG_LEVEL == 2
216#ifdef _LIBCPP_ENABLE_DEBUG_MODE
275217 if (!__libcpp_is_constant_evaluated())
276218 __get_db()->__insert_c(__c);
277219#else
......@@ -281,7 +223,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 inline void __debug_db_inser
281223
282224template <class _Tp>
283225_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 inline void __debug_db_insert_i(_Tp* __i) {
284#if _LIBCPP_DEBUG_LEVEL == 2
226#ifdef _LIBCPP_ENABLE_DEBUG_MODE
285227 if (!__libcpp_is_constant_evaluated())
286228 __get_db()->__insert_i(__i);
287229#else
......@@ -289,6 +231,37 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 inline void __debug_db_inser
289231#endif
290232}
291233
234template <class _Tp>
235_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 inline void __debug_db_erase_c(_Tp* __c) {
236#ifdef _LIBCPP_ENABLE_DEBUG_MODE
237 if (!__libcpp_is_constant_evaluated())
238 __get_db()->__erase_c(__c);
239#else
240 (void)(__c);
241#endif
242}
243
244template <class _Tp>
245_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 inline void __debug_db_swap(_Tp* __lhs, _Tp* __rhs) {
246#ifdef _LIBCPP_ENABLE_DEBUG_MODE
247 if (!__libcpp_is_constant_evaluated())
248 __get_db()->swap(__lhs, __rhs);
249#else
250 (void)(__lhs);
251 (void)(__rhs);
252#endif
253}
254
255template <class _Tp>
256_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 inline void __debug_db_invalidate_all(_Tp* __c) {
257#ifdef _LIBCPP_ENABLE_DEBUG_MODE
258 if (!__libcpp_is_constant_evaluated())
259 __get_db()->__invalidate_all(__c);
260#else
261 (void)(__c);
262#endif
263}
264
292265_LIBCPP_END_NAMESPACE_STD
293266
294#endif // _LIBCPP_DEBUG_H
267#endif // _LIBCPP___DEBUG
lib/libcxx/include/__debug_utils/randomize_range.h created+43
......@@ -0,0 +1,43 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___LIBCXX_DEBUG_RANDOMIZE_RANGE_H
10#define _LIBCPP___LIBCXX_DEBUG_RANDOMIZE_RANGE_H
11
12#include <__config>
13
14#ifdef _LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY
15# include <__algorithm/shuffle.h>
16# include <__type_traits/is_constant_evaluated.h>
17#endif
18
19#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20# pragma GCC system_header
21#endif
22
23_LIBCPP_BEGIN_NAMESPACE_STD
24
25template <class _AlgPolicy, class _Iterator, class _Sentinel>
26_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
27void __debug_randomize_range(_Iterator __first, _Sentinel __last) {
28#ifdef _LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY
29# ifdef _LIBCPP_CXX03_LANG
30# error Support for unspecified stability is only for C++11 and higher
31# endif
32
33 if (!__libcpp_is_constant_evaluated())
34 std::__shuffle<_AlgPolicy>(__first, __last, __libcpp_debug_randomizer());
35#else
36 (void)__first;
37 (void)__last;
38#endif
39}
40
41_LIBCPP_END_NAMESPACE_STD
42
43#endif // _LIBCPP___LIBCXX_DEBUG_RANDOMIZE_RANGE_H
lib/libcxx/include/__errc+1-1
......@@ -104,7 +104,7 @@ enum class errc
104104#include <cerrno>
105105
106106#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
107#pragma GCC system_header
107# pragma GCC system_header
108108#endif
109109
110110_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__filesystem/copy_options.h+21-17
......@@ -13,6 +13,10 @@
1313#include <__availability>
1414#include <__config>
1515
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
1620#ifndef _LIBCPP_CXX03_LANG
1721
1822_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
......@@ -34,41 +38,41 @@ enum class _LIBCPP_ENUM_VIS copy_options : unsigned short {
3438};
3539
3640_LIBCPP_INLINE_VISIBILITY
37inline constexpr copy_options operator&(copy_options _LHS, copy_options _RHS) {
38 return static_cast<copy_options>(static_cast<unsigned short>(_LHS) &
39 static_cast<unsigned short>(_RHS));
41inline constexpr copy_options operator&(copy_options __lhs, copy_options __rhs) {
42 return static_cast<copy_options>(static_cast<unsigned short>(__lhs) &
43 static_cast<unsigned short>(__rhs));
4044}
4145
4246_LIBCPP_INLINE_VISIBILITY
43inline constexpr copy_options operator|(copy_options _LHS, copy_options _RHS) {
44 return static_cast<copy_options>(static_cast<unsigned short>(_LHS) |
45 static_cast<unsigned short>(_RHS));
47inline constexpr copy_options operator|(copy_options __lhs, copy_options __rhs) {
48 return static_cast<copy_options>(static_cast<unsigned short>(__lhs) |
49 static_cast<unsigned short>(__rhs));
4650}
4751
4852_LIBCPP_INLINE_VISIBILITY
49inline constexpr copy_options operator^(copy_options _LHS, copy_options _RHS) {
50 return static_cast<copy_options>(static_cast<unsigned short>(_LHS) ^
51 static_cast<unsigned short>(_RHS));
53inline constexpr copy_options operator^(copy_options __lhs, copy_options __rhs) {
54 return static_cast<copy_options>(static_cast<unsigned short>(__lhs) ^
55 static_cast<unsigned short>(__rhs));
5256}
5357
5458_LIBCPP_INLINE_VISIBILITY
55inline constexpr copy_options operator~(copy_options _LHS) {
56 return static_cast<copy_options>(~static_cast<unsigned short>(_LHS));
59inline constexpr copy_options operator~(copy_options __lhs) {
60 return static_cast<copy_options>(~static_cast<unsigned short>(__lhs));
5761}
5862
5963_LIBCPP_INLINE_VISIBILITY
60inline copy_options& operator&=(copy_options& _LHS, copy_options _RHS) {
61 return _LHS = _LHS & _RHS;
64inline copy_options& operator&=(copy_options& __lhs, copy_options __rhs) {
65 return __lhs = __lhs & __rhs;
6266}
6367
6468_LIBCPP_INLINE_VISIBILITY
65inline copy_options& operator|=(copy_options& _LHS, copy_options _RHS) {
66 return _LHS = _LHS | _RHS;
69inline copy_options& operator|=(copy_options& __lhs, copy_options __rhs) {
70 return __lhs = __lhs | __rhs;
6771}
6872
6973_LIBCPP_INLINE_VISIBILITY
70inline copy_options& operator^=(copy_options& _LHS, copy_options _RHS) {
71 return _LHS = _LHS ^ _RHS;
74inline copy_options& operator^=(copy_options& __lhs, copy_options __rhs) {
75 return __lhs = __lhs ^ __rhs;
7276}
7377
7478_LIBCPP_AVAILABILITY_FILESYSTEM_POP
lib/libcxx/include/__filesystem/directory_entry.h+13-8
......@@ -11,6 +11,7 @@
1111#define _LIBCPP___FILESYSTEM_DIRECTORY_ENTRY_H
1212
1313#include <__availability>
14#include <__chrono/time_point.h>
1415#include <__config>
1516#include <__errc>
1617#include <__filesystem/file_status.h>
......@@ -20,12 +21,16 @@
2021#include <__filesystem/operations.h>
2122#include <__filesystem/path.h>
2223#include <__filesystem/perms.h>
23#include <chrono>
24#include <__utility/unreachable.h>
2425#include <cstdint>
2526#include <cstdlib>
2627#include <iosfwd>
2728#include <system_error>
2829
30#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
31# pragma GCC system_header
32#endif
33
2934_LIBCPP_PUSH_MACROS
3035#include <__undef_macros>
3136
......@@ -358,7 +363,7 @@ private:
358363 __ec->clear();
359364 return __data_.__type_;
360365 }
361 _LIBCPP_UNREACHABLE();
366 __libcpp_unreachable();
362367 }
363368
364369 _LIBCPP_INLINE_VISIBILITY
......@@ -379,7 +384,7 @@ private:
379384 return __data_.__type_;
380385 }
381386 }
382 _LIBCPP_UNREACHABLE();
387 __libcpp_unreachable();
383388 }
384389
385390 _LIBCPP_INLINE_VISIBILITY
......@@ -394,7 +399,7 @@ private:
394399 case _RefreshSymlink:
395400 return file_status(__get_ft(__ec), __data_.__non_sym_perms_);
396401 }
397 _LIBCPP_UNREACHABLE();
402 __libcpp_unreachable();
398403 }
399404
400405 _LIBCPP_INLINE_VISIBILITY
......@@ -410,7 +415,7 @@ private:
410415 case _RefreshSymlinkUnresolved:
411416 return file_status(__get_sym_ft(__ec), __data_.__sym_perms_);
412417 }
413 _LIBCPP_UNREACHABLE();
418 __libcpp_unreachable();
414419 }
415420
416421 _LIBCPP_INLINE_VISIBILITY
......@@ -435,7 +440,7 @@ private:
435440 return __data_.__size_;
436441 }
437442 }
438 _LIBCPP_UNREACHABLE();
443 __libcpp_unreachable();
439444 }
440445
441446 _LIBCPP_INLINE_VISIBILITY
......@@ -454,7 +459,7 @@ private:
454459 return __data_.__nlink_;
455460 }
456461 }
457 _LIBCPP_UNREACHABLE();
462 __libcpp_unreachable();
458463 }
459464
460465 _LIBCPP_INLINE_VISIBILITY
......@@ -477,7 +482,7 @@ private:
477482 return __data_.__write_time_;
478483 }
479484 }
480 _LIBCPP_UNREACHABLE();
485 __libcpp_unreachable();
481486 }
482487
483488private:
lib/libcxx/include/__filesystem/directory_iterator.h+27-12
......@@ -10,9 +10,9 @@
1010#ifndef _LIBCPP___FILESYSTEM_DIRECTORY_ITERATOR_H
1111#define _LIBCPP___FILESYSTEM_DIRECTORY_ITERATOR_H
1212
13#include <__assert>
1314#include <__availability>
1415#include <__config>
15#include <__debug>
1616#include <__filesystem/directory_entry.h>
1717#include <__filesystem/directory_options.h>
1818#include <__filesystem/path.h>
......@@ -23,6 +23,10 @@
2323#include <cstddef>
2424#include <system_error>
2525
26#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
27# pragma GCC system_header
28#endif
29
2630#ifndef _LIBCPP_CXX03_LANG
2731
2832_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
......@@ -40,25 +44,31 @@ public:
4044
4145public:
4246 //ctor & dtor
47 _LIBCPP_HIDE_FROM_ABI
4348 directory_iterator() noexcept {}
4449
50 _LIBCPP_HIDE_FROM_ABI
4551 explicit directory_iterator(const path& __p)
4652 : directory_iterator(__p, nullptr) {}
4753
54 _LIBCPP_HIDE_FROM_ABI
4855 directory_iterator(const path& __p, directory_options __opts)
4956 : directory_iterator(__p, nullptr, __opts) {}
5057
58 _LIBCPP_HIDE_FROM_ABI
5159 directory_iterator(const path& __p, error_code& __ec)
5260 : directory_iterator(__p, &__ec) {}
5361
62 _LIBCPP_HIDE_FROM_ABI
5463 directory_iterator(const path& __p, directory_options __opts,
5564 error_code& __ec)
5665 : directory_iterator(__p, &__ec, __opts) {}
5766
58 directory_iterator(const directory_iterator&) = default;
59 directory_iterator(directory_iterator&&) = default;
60 directory_iterator& operator=(const directory_iterator&) = default;
67 _LIBCPP_HIDE_FROM_ABI directory_iterator(const directory_iterator&) = default;
68 _LIBCPP_HIDE_FROM_ABI directory_iterator(directory_iterator&&) = default;
69 _LIBCPP_HIDE_FROM_ABI directory_iterator& operator=(const directory_iterator&) = default;
6170
71 _LIBCPP_HIDE_FROM_ABI
6272 directory_iterator& operator=(directory_iterator&& __o) noexcept {
6373 // non-default implementation provided to support self-move assign.
6474 if (this != &__o) {
......@@ -67,27 +77,32 @@ public:
6777 return *this;
6878 }
6979
70 ~directory_iterator() = default;
80 _LIBCPP_HIDE_FROM_ABI ~directory_iterator() = default;
7181
82 _LIBCPP_HIDE_FROM_ABI
7283 const directory_entry& operator*() const {
7384 _LIBCPP_ASSERT(__imp_, "The end iterator cannot be dereferenced");
7485 return __dereference();
7586 }
7687
88 _LIBCPP_HIDE_FROM_ABI
7789 const directory_entry* operator->() const { return &**this; }
7890
91 _LIBCPP_HIDE_FROM_ABI
7992 directory_iterator& operator++() { return __increment(); }
8093
94 _LIBCPP_HIDE_FROM_ABI
8195 __dir_element_proxy operator++(int) {
8296 __dir_element_proxy __p(**this);
8397 __increment();
8498 return __p;
8599 }
86100
101 _LIBCPP_HIDE_FROM_ABI
87102 directory_iterator& increment(error_code& __ec) { return __increment(&__ec); }
88103
89104private:
90 inline _LIBCPP_INLINE_VISIBILITY friend bool
105 inline _LIBCPP_HIDE_FROM_ABI friend bool
91106 operator==(const directory_iterator& __lhs,
92107 const directory_iterator& __rhs) noexcept;
93108
......@@ -106,25 +121,25 @@ private:
106121 shared_ptr<__dir_stream> __imp_;
107122};
108123
109inline _LIBCPP_INLINE_VISIBILITY bool
124inline _LIBCPP_HIDE_FROM_ABI bool
110125operator==(const directory_iterator& __lhs,
111126 const directory_iterator& __rhs) noexcept {
112127 return __lhs.__imp_ == __rhs.__imp_;
113128}
114129
115inline _LIBCPP_INLINE_VISIBILITY bool
130inline _LIBCPP_HIDE_FROM_ABI bool
116131operator!=(const directory_iterator& __lhs,
117132 const directory_iterator& __rhs) noexcept {
118133 return !(__lhs == __rhs);
119134}
120135
121136// enable directory_iterator range-based for statements
122inline _LIBCPP_INLINE_VISIBILITY directory_iterator
137inline _LIBCPP_HIDE_FROM_ABI directory_iterator
123138begin(directory_iterator __iter) noexcept {
124139 return __iter;
125140}
126141
127inline _LIBCPP_INLINE_VISIBILITY directory_iterator
142inline _LIBCPP_HIDE_FROM_ABI directory_iterator
128143end(directory_iterator) noexcept {
129144 return directory_iterator();
130145}
......@@ -133,7 +148,7 @@ _LIBCPP_AVAILABILITY_FILESYSTEM_POP
133148
134149_LIBCPP_END_NAMESPACE_FILESYSTEM
135150
136#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
151#if _LIBCPP_STD_VER > 17
137152
138153template <>
139154_LIBCPP_AVAILABILITY_FILESYSTEM
......@@ -143,7 +158,7 @@ template <>
143158_LIBCPP_AVAILABILITY_FILESYSTEM
144159inline constexpr bool _VSTD::ranges::enable_view<_VSTD_FS::directory_iterator> = true;
145160
146#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
161#endif // _LIBCPP_STD_VER > 17
147162
148163#endif // _LIBCPP_CXX03_LANG
149164
lib/libcxx/include/__filesystem/directory_options.h+27-23
......@@ -13,6 +13,10 @@
1313#include <__availability>
1414#include <__config>
1515
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
1620#ifndef _LIBCPP_CXX03_LANG
1721
1822_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
......@@ -26,47 +30,47 @@ enum class _LIBCPP_ENUM_VIS directory_options : unsigned char {
2630};
2731
2832_LIBCPP_INLINE_VISIBILITY
29inline constexpr directory_options operator&(directory_options _LHS,
30 directory_options _RHS) {
31 return static_cast<directory_options>(static_cast<unsigned char>(_LHS) &
32 static_cast<unsigned char>(_RHS));
33inline constexpr directory_options operator&(directory_options __lhs,
34 directory_options __rhs) {
35 return static_cast<directory_options>(static_cast<unsigned char>(__lhs) &
36 static_cast<unsigned char>(__rhs));
3337}
3438
3539_LIBCPP_INLINE_VISIBILITY
36inline constexpr directory_options operator|(directory_options _LHS,
37 directory_options _RHS) {
38 return static_cast<directory_options>(static_cast<unsigned char>(_LHS) |
39 static_cast<unsigned char>(_RHS));
40inline constexpr directory_options operator|(directory_options __lhs,
41 directory_options __rhs) {
42 return static_cast<directory_options>(static_cast<unsigned char>(__lhs) |
43 static_cast<unsigned char>(__rhs));
4044}
4145
4246_LIBCPP_INLINE_VISIBILITY
43inline constexpr directory_options operator^(directory_options _LHS,
44 directory_options _RHS) {
45 return static_cast<directory_options>(static_cast<unsigned char>(_LHS) ^
46 static_cast<unsigned char>(_RHS));
47inline constexpr directory_options operator^(directory_options __lhs,
48 directory_options __rhs) {
49 return static_cast<directory_options>(static_cast<unsigned char>(__lhs) ^
50 static_cast<unsigned char>(__rhs));
4751}
4852
4953_LIBCPP_INLINE_VISIBILITY
50inline constexpr directory_options operator~(directory_options _LHS) {
51 return static_cast<directory_options>(~static_cast<unsigned char>(_LHS));
54inline constexpr directory_options operator~(directory_options __lhs) {
55 return static_cast<directory_options>(~static_cast<unsigned char>(__lhs));
5256}
5357
5458_LIBCPP_INLINE_VISIBILITY
55inline directory_options& operator&=(directory_options& _LHS,
56 directory_options _RHS) {
57 return _LHS = _LHS & _RHS;
59inline directory_options& operator&=(directory_options& __lhs,
60 directory_options __rhs) {
61 return __lhs = __lhs & __rhs;
5862}
5963
6064_LIBCPP_INLINE_VISIBILITY
61inline directory_options& operator|=(directory_options& _LHS,
62 directory_options _RHS) {
63 return _LHS = _LHS | _RHS;
65inline directory_options& operator|=(directory_options& __lhs,
66 directory_options __rhs) {
67 return __lhs = __lhs | __rhs;
6468}
6569
6670_LIBCPP_INLINE_VISIBILITY
67inline directory_options& operator^=(directory_options& _LHS,
68 directory_options _RHS) {
69 return _LHS = _LHS ^ _RHS;
71inline directory_options& operator^=(directory_options& __lhs,
72 directory_options __rhs) {
73 return __lhs = __lhs ^ __rhs;
7074}
7175
7276_LIBCPP_AVAILABILITY_FILESYSTEM_POP
lib/libcxx/include/__filesystem/file_status.h+4
......@@ -15,6 +15,10 @@
1515#include <__filesystem/file_type.h>
1616#include <__filesystem/perms.h>
1717
18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19# pragma GCC system_header
20#endif
21
1822#ifndef _LIBCPP_CXX03_LANG
1923
2024_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
lib/libcxx/include/__filesystem/file_time_type.h+6-1
......@@ -11,8 +11,13 @@
1111#define _LIBCPP___FILESYSTEM_FILE_TIME_TYPE_H
1212
1313#include <__availability>
14#include <__chrono/file_clock.h>
15#include <__chrono/time_point.h>
1416#include <__config>
15#include <chrono>
17
18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19# pragma GCC system_header
20#endif
1621
1722#ifndef _LIBCPP_CXX03_LANG
1823
lib/libcxx/include/__filesystem/file_type.h+4
......@@ -13,6 +13,10 @@
1313#include <__availability>
1414#include <__config>
1515
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
1620#ifndef _LIBCPP_CXX03_LANG
1721
1822_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
lib/libcxx/include/__filesystem/filesystem_error.h+4
......@@ -19,6 +19,10 @@
1919#include <system_error>
2020#include <type_traits>
2121
22#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23# pragma GCC system_header
24#endif
25
2226#ifndef _LIBCPP_CXX03_LANG
2327
2428_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
lib/libcxx/include/__filesystem/operations.h+112-108
......@@ -11,6 +11,7 @@
1111#define _LIBCPP___FILESYSTEM_OPERATIONS_H
1212
1313#include <__availability>
14#include <__chrono/time_point.h>
1415#include <__config>
1516#include <__filesystem/copy_options.h>
1617#include <__filesystem/file_status.h>
......@@ -20,10 +21,13 @@
2021#include <__filesystem/perm_options.h>
2122#include <__filesystem/perms.h>
2223#include <__filesystem/space_info.h>
23#include <chrono>
2424#include <cstdint>
2525#include <system_error>
2626
27#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
28# pragma GCC system_header
29#endif
30
2731#ifndef _LIBCPP_CXX03_LANG
2832
2933_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
......@@ -35,10 +39,10 @@ _LIBCPP_FUNC_VIS path __canonical(const path&, error_code* __ec = nullptr);
3539_LIBCPP_FUNC_VIS bool __copy_file(const path& __from, const path& __to, copy_options __opt, error_code* __ec = nullptr);
3640_LIBCPP_FUNC_VIS void __copy_symlink(const path& __existing_symlink, const path& __new_symlink, error_code* __ec = nullptr);
3741_LIBCPP_FUNC_VIS void __copy(const path& __from, const path& __to, copy_options __opt, error_code* __ec = nullptr);
38_LIBCPP_FUNC_VIS bool __create_directories(const path& p, error_code* ec = nullptr);
42_LIBCPP_FUNC_VIS bool __create_directories(const path&, error_code* = nullptr);
3943_LIBCPP_FUNC_VIS void __create_directory_symlink(const path& __to, const path& __new_symlink, error_code* __ec = nullptr);
40_LIBCPP_FUNC_VIS bool __create_directory(const path& p, error_code* ec = nullptr);
41_LIBCPP_FUNC_VIS bool __create_directory(const path& p, const path& attributes, error_code* ec = nullptr);
44_LIBCPP_FUNC_VIS bool __create_directory(const path&, error_code* = nullptr);
45_LIBCPP_FUNC_VIS bool __create_directory(const path&, const path& __attributes, error_code* = nullptr);
4246_LIBCPP_FUNC_VIS void __create_hard_link(const path& __to, const path& __new_hard_link, error_code* __ec = nullptr);
4347_LIBCPP_FUNC_VIS void __create_symlink(const path& __to, const path& __new_symlink, error_code* __ec = nullptr);
4448_LIBCPP_FUNC_VIS path __current_path(error_code* __ec = nullptr);
......@@ -48,51 +52,51 @@ _LIBCPP_FUNC_VIS file_status __status(const path&, error_code* __ec = nullptr);
4852_LIBCPP_FUNC_VIS uintmax_t __file_size(const path&, error_code* __ec = nullptr);
4953_LIBCPP_FUNC_VIS uintmax_t __hard_link_count(const path&, error_code* __ec = nullptr);
5054_LIBCPP_FUNC_VIS file_status __symlink_status(const path&, error_code* __ec = nullptr);
51_LIBCPP_FUNC_VIS file_time_type __last_write_time(const path& p, error_code* ec = nullptr);
52_LIBCPP_FUNC_VIS void __last_write_time(const path& p, file_time_type new_time, error_code* ec = nullptr);
55_LIBCPP_FUNC_VIS file_time_type __last_write_time(const path&, error_code* __ec = nullptr);
56_LIBCPP_FUNC_VIS void __last_write_time(const path&, file_time_type __new_time, error_code* __ec = nullptr);
5357_LIBCPP_FUNC_VIS path __weakly_canonical(path const& __p, error_code* __ec = nullptr);
54_LIBCPP_FUNC_VIS path __read_symlink(const path& p, error_code* ec = nullptr);
55_LIBCPP_FUNC_VIS uintmax_t __remove_all(const path& p, error_code* ec = nullptr);
56_LIBCPP_FUNC_VIS bool __remove(const path& p, error_code* ec = nullptr);
57_LIBCPP_FUNC_VIS void __rename(const path& from, const path& to, error_code* ec = nullptr);
58_LIBCPP_FUNC_VIS void __resize_file(const path& p, uintmax_t size, error_code* ec = nullptr);
58_LIBCPP_FUNC_VIS path __read_symlink(const path&, error_code* __ec = nullptr);
59_LIBCPP_FUNC_VIS uintmax_t __remove_all(const path&, error_code* __ec = nullptr);
60_LIBCPP_FUNC_VIS bool __remove(const path&, error_code* __ec = nullptr);
61_LIBCPP_FUNC_VIS void __rename(const path& __from, const path& __to, error_code* __ec = nullptr);
62_LIBCPP_FUNC_VIS void __resize_file(const path&, uintmax_t __size, error_code* = nullptr);
5963_LIBCPP_FUNC_VIS path __temp_directory_path(error_code* __ec = nullptr);
6064
61inline _LIBCPP_INLINE_VISIBILITY path absolute(const path& __p) { return __absolute(__p); }
62inline _LIBCPP_INLINE_VISIBILITY path absolute(const path& __p, error_code& __ec) { return __absolute(__p, &__ec); }
63inline _LIBCPP_INLINE_VISIBILITY path canonical(const path& __p) { return __canonical(__p); }
64inline _LIBCPP_INLINE_VISIBILITY path canonical(const path& __p, error_code& __ec) { return __canonical(__p, &__ec); }
65inline _LIBCPP_INLINE_VISIBILITY bool copy_file(const path& __from, const path& __to) { return __copy_file(__from, __to, copy_options::none); }
66inline _LIBCPP_INLINE_VISIBILITY bool copy_file(const path& __from, const path& __to, error_code& __ec) { return __copy_file(__from, __to, copy_options::none, &__ec); }
67inline _LIBCPP_INLINE_VISIBILITY bool copy_file(const path& __from, const path& __to, copy_options __opt) { return __copy_file(__from, __to, __opt); }
68inline _LIBCPP_INLINE_VISIBILITY bool copy_file(const path& __from, const path& __to, copy_options __opt, error_code& __ec) { return __copy_file(__from, __to, __opt, &__ec); }
69inline _LIBCPP_INLINE_VISIBILITY void copy_symlink(const path& __from, const path& __to) { __copy_symlink(__from, __to); }
70inline _LIBCPP_INLINE_VISIBILITY void copy_symlink(const path& __from, const path& __to, error_code& __ec) noexcept { __copy_symlink(__from, __to, &__ec); }
71inline _LIBCPP_INLINE_VISIBILITY void copy(const path& __from, const path& __to) { __copy(__from, __to, copy_options::none); }
72inline _LIBCPP_INLINE_VISIBILITY void copy(const path& __from, const path& __to, error_code& __ec) { __copy(__from, __to, copy_options::none, &__ec); }
73inline _LIBCPP_INLINE_VISIBILITY void copy(const path& __from, const path& __to, copy_options __opt) { __copy(__from, __to, __opt); }
74inline _LIBCPP_INLINE_VISIBILITY void copy(const path& __from, const path& __to, copy_options __opt, error_code& __ec) { __copy(__from, __to, __opt, &__ec); }
75inline _LIBCPP_INLINE_VISIBILITY bool create_directories(const path& __p) { return __create_directories(__p); }
76inline _LIBCPP_INLINE_VISIBILITY bool create_directories(const path& __p, error_code& __ec) { return __create_directories(__p, &__ec); }
77inline _LIBCPP_INLINE_VISIBILITY void create_directory_symlink(const path& __target, const path& __link) { __create_directory_symlink(__target, __link); }
78inline _LIBCPP_INLINE_VISIBILITY void create_directory_symlink(const path& __target, const path& __link, error_code& __ec) noexcept { __create_directory_symlink(__target, __link, &__ec); }
79inline _LIBCPP_INLINE_VISIBILITY bool create_directory(const path& __p) { return __create_directory(__p); }
80inline _LIBCPP_INLINE_VISIBILITY bool create_directory(const path& __p, error_code& __ec) noexcept { return __create_directory(__p, &__ec); }
81inline _LIBCPP_INLINE_VISIBILITY bool create_directory(const path& __p, const path& __attrs) { return __create_directory(__p, __attrs); }
82inline _LIBCPP_INLINE_VISIBILITY bool create_directory(const path& __p, const path& __attrs, error_code& __ec) noexcept { return __create_directory(__p, __attrs, &__ec); }
83inline _LIBCPP_INLINE_VISIBILITY void create_hard_link(const path& __target, const path& __link) { __create_hard_link(__target, __link); }
84inline _LIBCPP_INLINE_VISIBILITY void create_hard_link(const path& __target, const path& __link, error_code& __ec) noexcept { __create_hard_link(__target, __link, &__ec); }
85inline _LIBCPP_INLINE_VISIBILITY void create_symlink(const path& __target, const path& __link) { __create_symlink(__target, __link); }
86inline _LIBCPP_INLINE_VISIBILITY void create_symlink(const path& __target, const path& __link, error_code& __ec) noexcept { return __create_symlink(__target, __link, &__ec); }
87inline _LIBCPP_INLINE_VISIBILITY path current_path() { return __current_path(); }
88inline _LIBCPP_INLINE_VISIBILITY path current_path(error_code& __ec) { return __current_path(&__ec); }
89inline _LIBCPP_INLINE_VISIBILITY void current_path(const path& __p) { __current_path(__p); }
90inline _LIBCPP_INLINE_VISIBILITY void current_path(const path& __p, error_code& __ec) noexcept { __current_path(__p, &__ec); }
91inline _LIBCPP_INLINE_VISIBILITY bool equivalent(const path& __p1, const path& __p2) { return __equivalent(__p1, __p2); }
92inline _LIBCPP_INLINE_VISIBILITY bool equivalent(const path& __p1, const path& __p2, error_code& __ec) noexcept { return __equivalent(__p1, __p2, &__ec); }
93inline _LIBCPP_INLINE_VISIBILITY bool status_known(file_status __s) noexcept { return __s.type() != file_type::none; }
94inline _LIBCPP_INLINE_VISIBILITY bool exists(file_status __s) noexcept { return status_known(__s) && __s.type() != file_type::not_found; }
95inline _LIBCPP_INLINE_VISIBILITY bool exists(const path& __p) { return exists(__status(__p)); }
65inline _LIBCPP_HIDE_FROM_ABI path absolute(const path& __p) { return __absolute(__p); }
66inline _LIBCPP_HIDE_FROM_ABI path absolute(const path& __p, error_code& __ec) { return __absolute(__p, &__ec); }
67inline _LIBCPP_HIDE_FROM_ABI path canonical(const path& __p) { return __canonical(__p); }
68inline _LIBCPP_HIDE_FROM_ABI path canonical(const path& __p, error_code& __ec) { return __canonical(__p, &__ec); }
69inline _LIBCPP_HIDE_FROM_ABI bool copy_file(const path& __from, const path& __to) { return __copy_file(__from, __to, copy_options::none); }
70inline _LIBCPP_HIDE_FROM_ABI bool copy_file(const path& __from, const path& __to, error_code& __ec) { return __copy_file(__from, __to, copy_options::none, &__ec); }
71inline _LIBCPP_HIDE_FROM_ABI bool copy_file(const path& __from, const path& __to, copy_options __opt) { return __copy_file(__from, __to, __opt); }
72inline _LIBCPP_HIDE_FROM_ABI bool copy_file(const path& __from, const path& __to, copy_options __opt, error_code& __ec) { return __copy_file(__from, __to, __opt, &__ec); }
73inline _LIBCPP_HIDE_FROM_ABI void copy_symlink(const path& __from, const path& __to) { __copy_symlink(__from, __to); }
74inline _LIBCPP_HIDE_FROM_ABI void copy_symlink(const path& __from, const path& __to, error_code& __ec) noexcept { __copy_symlink(__from, __to, &__ec); }
75inline _LIBCPP_HIDE_FROM_ABI void copy(const path& __from, const path& __to) { __copy(__from, __to, copy_options::none); }
76inline _LIBCPP_HIDE_FROM_ABI void copy(const path& __from, const path& __to, error_code& __ec) { __copy(__from, __to, copy_options::none, &__ec); }
77inline _LIBCPP_HIDE_FROM_ABI void copy(const path& __from, const path& __to, copy_options __opt) { __copy(__from, __to, __opt); }
78inline _LIBCPP_HIDE_FROM_ABI void copy(const path& __from, const path& __to, copy_options __opt, error_code& __ec) { __copy(__from, __to, __opt, &__ec); }
79inline _LIBCPP_HIDE_FROM_ABI bool create_directories(const path& __p) { return __create_directories(__p); }
80inline _LIBCPP_HIDE_FROM_ABI bool create_directories(const path& __p, error_code& __ec) { return __create_directories(__p, &__ec); }
81inline _LIBCPP_HIDE_FROM_ABI void create_directory_symlink(const path& __target, const path& __link) { __create_directory_symlink(__target, __link); }
82inline _LIBCPP_HIDE_FROM_ABI void create_directory_symlink(const path& __target, const path& __link, error_code& __ec) noexcept { __create_directory_symlink(__target, __link, &__ec); }
83inline _LIBCPP_HIDE_FROM_ABI bool create_directory(const path& __p) { return __create_directory(__p); }
84inline _LIBCPP_HIDE_FROM_ABI bool create_directory(const path& __p, error_code& __ec) noexcept { return __create_directory(__p, &__ec); }
85inline _LIBCPP_HIDE_FROM_ABI bool create_directory(const path& __p, const path& __attrs) { return __create_directory(__p, __attrs); }
86inline _LIBCPP_HIDE_FROM_ABI bool create_directory(const path& __p, const path& __attrs, error_code& __ec) noexcept { return __create_directory(__p, __attrs, &__ec); }
87inline _LIBCPP_HIDE_FROM_ABI void create_hard_link(const path& __target, const path& __link) { __create_hard_link(__target, __link); }
88inline _LIBCPP_HIDE_FROM_ABI void create_hard_link(const path& __target, const path& __link, error_code& __ec) noexcept { __create_hard_link(__target, __link, &__ec); }
89inline _LIBCPP_HIDE_FROM_ABI void create_symlink(const path& __target, const path& __link) { __create_symlink(__target, __link); }
90inline _LIBCPP_HIDE_FROM_ABI void create_symlink(const path& __target, const path& __link, error_code& __ec) noexcept { return __create_symlink(__target, __link, &__ec); }
91inline _LIBCPP_HIDE_FROM_ABI path current_path() { return __current_path(); }
92inline _LIBCPP_HIDE_FROM_ABI path current_path(error_code& __ec) { return __current_path(&__ec); }
93inline _LIBCPP_HIDE_FROM_ABI void current_path(const path& __p) { __current_path(__p); }
94inline _LIBCPP_HIDE_FROM_ABI void current_path(const path& __p, error_code& __ec) noexcept { __current_path(__p, &__ec); }
95inline _LIBCPP_HIDE_FROM_ABI bool equivalent(const path& __p1, const path& __p2) { return __equivalent(__p1, __p2); }
96inline _LIBCPP_HIDE_FROM_ABI bool equivalent(const path& __p1, const path& __p2, error_code& __ec) noexcept { return __equivalent(__p1, __p2, &__ec); }
97inline _LIBCPP_HIDE_FROM_ABI bool status_known(file_status __s) noexcept { return __s.type() != file_type::none; }
98inline _LIBCPP_HIDE_FROM_ABI bool exists(file_status __s) noexcept { return status_known(__s) && __s.type() != file_type::not_found; }
99inline _LIBCPP_HIDE_FROM_ABI bool exists(const path& __p) { return exists(__status(__p)); }
96100
97101inline _LIBCPP_INLINE_VISIBILITY bool exists(const path& __p, error_code& __ec) noexcept {
98102 auto __s = __status(__p, &__ec);
......@@ -101,45 +105,45 @@ inline _LIBCPP_INLINE_VISIBILITY bool exists(const path& __p, error_code& __ec)
101105 return exists(__s);
102106}
103107
104inline _LIBCPP_INLINE_VISIBILITY uintmax_t file_size(const path& __p) { return __file_size(__p); }
105inline _LIBCPP_INLINE_VISIBILITY uintmax_t file_size(const path& __p, error_code& __ec) noexcept { return __file_size(__p, &__ec); }
106inline _LIBCPP_INLINE_VISIBILITY uintmax_t hard_link_count(const path& __p) { return __hard_link_count(__p); }
107inline _LIBCPP_INLINE_VISIBILITY uintmax_t hard_link_count(const path& __p, error_code& __ec) noexcept { return __hard_link_count(__p, &__ec); }
108inline _LIBCPP_INLINE_VISIBILITY bool is_block_file(file_status __s) noexcept { return __s.type() == file_type::block; }
109inline _LIBCPP_INLINE_VISIBILITY bool is_block_file(const path& __p) { return is_block_file(__status(__p)); }
110inline _LIBCPP_INLINE_VISIBILITY bool is_block_file(const path& __p, error_code& __ec) noexcept { return is_block_file(__status(__p, &__ec)); }
111inline _LIBCPP_INLINE_VISIBILITY bool is_character_file(file_status __s) noexcept { return __s.type() == file_type::character; }
112inline _LIBCPP_INLINE_VISIBILITY bool is_character_file(const path& __p) { return is_character_file(__status(__p)); }
113inline _LIBCPP_INLINE_VISIBILITY bool is_character_file(const path& __p, error_code& __ec) noexcept { return is_character_file(__status(__p, &__ec)); }
114inline _LIBCPP_INLINE_VISIBILITY bool is_directory(file_status __s) noexcept { return __s.type() == file_type::directory; }
115inline _LIBCPP_INLINE_VISIBILITY bool is_directory(const path& __p) { return is_directory(__status(__p)); }
116inline _LIBCPP_INLINE_VISIBILITY bool is_directory(const path& __p, error_code& __ec) noexcept { return is_directory(__status(__p, &__ec)); }
117_LIBCPP_FUNC_VIS bool __fs_is_empty(const path& p, error_code* ec = nullptr);
118inline _LIBCPP_INLINE_VISIBILITY bool is_empty(const path& __p) { return __fs_is_empty(__p); }
119inline _LIBCPP_INLINE_VISIBILITY bool is_empty(const path& __p, error_code& __ec) { return __fs_is_empty(__p, &__ec); }
120inline _LIBCPP_INLINE_VISIBILITY bool is_fifo(file_status __s) noexcept { return __s.type() == file_type::fifo; }
121inline _LIBCPP_INLINE_VISIBILITY bool is_fifo(const path& __p) { return is_fifo(__status(__p)); }
122inline _LIBCPP_INLINE_VISIBILITY bool is_fifo(const path& __p, error_code& __ec) noexcept { return is_fifo(__status(__p, &__ec)); }
123inline _LIBCPP_INLINE_VISIBILITY bool is_regular_file(file_status __s) noexcept { return __s.type() == file_type::regular; }
124inline _LIBCPP_INLINE_VISIBILITY bool is_regular_file(const path& __p) { return is_regular_file(__status(__p)); }
125inline _LIBCPP_INLINE_VISIBILITY bool is_regular_file(const path& __p, error_code& __ec) noexcept { return is_regular_file(__status(__p, &__ec)); }
126inline _LIBCPP_INLINE_VISIBILITY bool is_symlink(file_status __s) noexcept { return __s.type() == file_type::symlink; }
127inline _LIBCPP_INLINE_VISIBILITY bool is_symlink(const path& __p) { return is_symlink(__symlink_status(__p)); }
128inline _LIBCPP_INLINE_VISIBILITY bool is_symlink(const path& __p, error_code& __ec) noexcept { return is_symlink(__symlink_status(__p, &__ec)); }
129inline _LIBCPP_INLINE_VISIBILITY bool is_other(file_status __s) noexcept { return exists(__s) && !is_regular_file(__s) && !is_directory(__s) && !is_symlink(__s); }
130inline _LIBCPP_INLINE_VISIBILITY bool is_other(const path& __p) { return is_other(__status(__p)); }
131inline _LIBCPP_INLINE_VISIBILITY bool is_other(const path& __p, error_code& __ec) noexcept { return is_other(__status(__p, &__ec)); }
132inline _LIBCPP_INLINE_VISIBILITY bool is_socket(file_status __s) noexcept { return __s.type() == file_type::socket; }
133inline _LIBCPP_INLINE_VISIBILITY bool is_socket(const path& __p) { return is_socket(__status(__p)); }
134inline _LIBCPP_INLINE_VISIBILITY bool is_socket(const path& __p, error_code& __ec) noexcept { return is_socket(__status(__p, &__ec)); }
135inline _LIBCPP_INLINE_VISIBILITY file_time_type last_write_time(const path& __p) { return __last_write_time(__p); }
136inline _LIBCPP_INLINE_VISIBILITY file_time_type last_write_time(const path& __p, error_code& __ec) noexcept { return __last_write_time(__p, &__ec); }
137inline _LIBCPP_INLINE_VISIBILITY void last_write_time(const path& __p, file_time_type __t) { __last_write_time(__p, __t); }
138inline _LIBCPP_INLINE_VISIBILITY void last_write_time(const path& __p, file_time_type __t, error_code& __ec) noexcept { __last_write_time(__p, __t, &__ec); }
108inline _LIBCPP_HIDE_FROM_ABI uintmax_t file_size(const path& __p) { return __file_size(__p); }
109inline _LIBCPP_HIDE_FROM_ABI uintmax_t file_size(const path& __p, error_code& __ec) noexcept { return __file_size(__p, &__ec); }
110inline _LIBCPP_HIDE_FROM_ABI uintmax_t hard_link_count(const path& __p) { return __hard_link_count(__p); }
111inline _LIBCPP_HIDE_FROM_ABI uintmax_t hard_link_count(const path& __p, error_code& __ec) noexcept { return __hard_link_count(__p, &__ec); }
112inline _LIBCPP_HIDE_FROM_ABI bool is_block_file(file_status __s) noexcept { return __s.type() == file_type::block; }
113inline _LIBCPP_HIDE_FROM_ABI bool is_block_file(const path& __p) { return is_block_file(__status(__p)); }
114inline _LIBCPP_HIDE_FROM_ABI bool is_block_file(const path& __p, error_code& __ec) noexcept { return is_block_file(__status(__p, &__ec)); }
115inline _LIBCPP_HIDE_FROM_ABI bool is_character_file(file_status __s) noexcept { return __s.type() == file_type::character; }
116inline _LIBCPP_HIDE_FROM_ABI bool is_character_file(const path& __p) { return is_character_file(__status(__p)); }
117inline _LIBCPP_HIDE_FROM_ABI bool is_character_file(const path& __p, error_code& __ec) noexcept { return is_character_file(__status(__p, &__ec)); }
118inline _LIBCPP_HIDE_FROM_ABI bool is_directory(file_status __s) noexcept { return __s.type() == file_type::directory; }
119inline _LIBCPP_HIDE_FROM_ABI bool is_directory(const path& __p) { return is_directory(__status(__p)); }
120inline _LIBCPP_HIDE_FROM_ABI bool is_directory(const path& __p, error_code& __ec) noexcept { return is_directory(__status(__p, &__ec)); }
121_LIBCPP_FUNC_VIS bool __fs_is_empty(const path& __p, error_code* __ec = nullptr);
122inline _LIBCPP_HIDE_FROM_ABI bool is_empty(const path& __p) { return __fs_is_empty(__p); }
123inline _LIBCPP_HIDE_FROM_ABI bool is_empty(const path& __p, error_code& __ec) { return __fs_is_empty(__p, &__ec); }
124inline _LIBCPP_HIDE_FROM_ABI bool is_fifo(file_status __s) noexcept { return __s.type() == file_type::fifo; }
125inline _LIBCPP_HIDE_FROM_ABI bool is_fifo(const path& __p) { return is_fifo(__status(__p)); }
126inline _LIBCPP_HIDE_FROM_ABI bool is_fifo(const path& __p, error_code& __ec) noexcept { return is_fifo(__status(__p, &__ec)); }
127inline _LIBCPP_HIDE_FROM_ABI bool is_regular_file(file_status __s) noexcept { return __s.type() == file_type::regular; }
128inline _LIBCPP_HIDE_FROM_ABI bool is_regular_file(const path& __p) { return is_regular_file(__status(__p)); }
129inline _LIBCPP_HIDE_FROM_ABI bool is_regular_file(const path& __p, error_code& __ec) noexcept { return is_regular_file(__status(__p, &__ec)); }
130inline _LIBCPP_HIDE_FROM_ABI bool is_symlink(file_status __s) noexcept { return __s.type() == file_type::symlink; }
131inline _LIBCPP_HIDE_FROM_ABI bool is_symlink(const path& __p) { return is_symlink(__symlink_status(__p)); }
132inline _LIBCPP_HIDE_FROM_ABI bool is_symlink(const path& __p, error_code& __ec) noexcept { return is_symlink(__symlink_status(__p, &__ec)); }
133inline _LIBCPP_HIDE_FROM_ABI bool is_other(file_status __s) noexcept { return exists(__s) && !is_regular_file(__s) && !is_directory(__s) && !is_symlink(__s); }
134inline _LIBCPP_HIDE_FROM_ABI bool is_other(const path& __p) { return is_other(__status(__p)); }
135inline _LIBCPP_HIDE_FROM_ABI bool is_other(const path& __p, error_code& __ec) noexcept { return is_other(__status(__p, &__ec)); }
136inline _LIBCPP_HIDE_FROM_ABI bool is_socket(file_status __s) noexcept { return __s.type() == file_type::socket; }
137inline _LIBCPP_HIDE_FROM_ABI bool is_socket(const path& __p) { return is_socket(__status(__p)); }
138inline _LIBCPP_HIDE_FROM_ABI bool is_socket(const path& __p, error_code& __ec) noexcept { return is_socket(__status(__p, &__ec)); }
139inline _LIBCPP_HIDE_FROM_ABI file_time_type last_write_time(const path& __p) { return __last_write_time(__p); }
140inline _LIBCPP_HIDE_FROM_ABI file_time_type last_write_time(const path& __p, error_code& __ec) noexcept { return __last_write_time(__p, &__ec); }
141inline _LIBCPP_HIDE_FROM_ABI void last_write_time(const path& __p, file_time_type __t) { __last_write_time(__p, __t); }
142inline _LIBCPP_HIDE_FROM_ABI void last_write_time(const path& __p, file_time_type __t, error_code& __ec) noexcept { __last_write_time(__p, __t, &__ec); }
139143_LIBCPP_FUNC_VIS void __permissions(const path&, perms, perm_options, error_code* = nullptr);
140inline _LIBCPP_INLINE_VISIBILITY void permissions(const path& __p, perms __prms, perm_options __opts = perm_options::replace) { __permissions(__p, __prms, __opts); }
141inline _LIBCPP_INLINE_VISIBILITY void permissions(const path& __p, perms __prms, error_code& __ec) noexcept { __permissions(__p, __prms, perm_options::replace, &__ec); }
142inline _LIBCPP_INLINE_VISIBILITY void permissions(const path& __p, perms __prms, perm_options __opts, error_code& __ec) { __permissions(__p, __prms, __opts, &__ec); }
144inline _LIBCPP_HIDE_FROM_ABI void permissions(const path& __p, perms __prms, perm_options __opts = perm_options::replace) { __permissions(__p, __prms, __opts); }
145inline _LIBCPP_HIDE_FROM_ABI void permissions(const path& __p, perms __prms, error_code& __ec) noexcept { __permissions(__p, __prms, perm_options::replace, &__ec); }
146inline _LIBCPP_HIDE_FROM_ABI void permissions(const path& __p, perms __prms, perm_options __opts, error_code& __ec) { __permissions(__p, __prms, __opts, &__ec); }
143147
144148inline _LIBCPP_INLINE_VISIBILITY path proximate(const path& __p, const path& __base, error_code& __ec) {
145149 path __tmp = __weakly_canonical(__p, &__ec);
......@@ -151,10 +155,10 @@ inline _LIBCPP_INLINE_VISIBILITY path proximate(const path& __p, const path& __b
151155 return __tmp.lexically_proximate(__tmp_base);
152156}
153157
154inline _LIBCPP_INLINE_VISIBILITY path proximate(const path& __p, error_code& __ec) { return proximate(__p, current_path(), __ec); }
155inline _LIBCPP_INLINE_VISIBILITY path proximate(const path& __p, const path& __base = current_path()) { return __weakly_canonical(__p).lexically_proximate(__weakly_canonical(__base)); }
156inline _LIBCPP_INLINE_VISIBILITY path read_symlink(const path& __p) { return __read_symlink(__p); }
157inline _LIBCPP_INLINE_VISIBILITY path read_symlink(const path& __p, error_code& __ec) { return __read_symlink(__p, &__ec); }
158inline _LIBCPP_HIDE_FROM_ABI path proximate(const path& __p, error_code& __ec) { return proximate(__p, current_path(), __ec); }
159inline _LIBCPP_HIDE_FROM_ABI path proximate(const path& __p, const path& __base = current_path()) { return __weakly_canonical(__p).lexically_proximate(__weakly_canonical(__base)); }
160inline _LIBCPP_HIDE_FROM_ABI path read_symlink(const path& __p) { return __read_symlink(__p); }
161inline _LIBCPP_HIDE_FROM_ABI path read_symlink(const path& __p, error_code& __ec) { return __read_symlink(__p, &__ec); }
158162
159163inline _LIBCPP_INLINE_VISIBILITY path relative(const path& __p, const path& __base, error_code& __ec) {
160164 path __tmp = __weakly_canonical(__p, &__ec);
......@@ -166,27 +170,27 @@ inline _LIBCPP_INLINE_VISIBILITY path relative(const path& __p, const path& __ba
166170 return __tmp.lexically_relative(__tmpbase);
167171}
168172
169inline _LIBCPP_INLINE_VISIBILITY path relative(const path& __p, error_code& __ec) { return relative(__p, current_path(), __ec); }
170inline _LIBCPP_INLINE_VISIBILITY path relative(const path& __p, const path& __base = current_path()) { return __weakly_canonical(__p).lexically_relative(__weakly_canonical(__base)); }
171inline _LIBCPP_INLINE_VISIBILITY uintmax_t remove_all(const path& __p) { return __remove_all(__p); }
172inline _LIBCPP_INLINE_VISIBILITY uintmax_t remove_all(const path& __p, error_code& __ec) { return __remove_all(__p, &__ec); }
173inline _LIBCPP_INLINE_VISIBILITY bool remove(const path& __p) { return __remove(__p); }
174inline _LIBCPP_INLINE_VISIBILITY bool remove(const path& __p, error_code& __ec) noexcept { return __remove(__p, &__ec); }
175inline _LIBCPP_INLINE_VISIBILITY void rename(const path& __from, const path& __to) { return __rename(__from, __to); }
176inline _LIBCPP_INLINE_VISIBILITY void rename(const path& __from, const path& __to, error_code& __ec) noexcept { return __rename(__from, __to, &__ec); }
177inline _LIBCPP_INLINE_VISIBILITY void resize_file(const path& __p, uintmax_t __ns) { return __resize_file(__p, __ns); }
178inline _LIBCPP_INLINE_VISIBILITY void resize_file(const path& __p, uintmax_t __ns, error_code& __ec) noexcept { return __resize_file(__p, __ns, &__ec); }
173inline _LIBCPP_HIDE_FROM_ABI path relative(const path& __p, error_code& __ec) { return relative(__p, current_path(), __ec); }
174inline _LIBCPP_HIDE_FROM_ABI path relative(const path& __p, const path& __base = current_path()) { return __weakly_canonical(__p).lexically_relative(__weakly_canonical(__base)); }
175inline _LIBCPP_HIDE_FROM_ABI uintmax_t remove_all(const path& __p) { return __remove_all(__p); }
176inline _LIBCPP_HIDE_FROM_ABI uintmax_t remove_all(const path& __p, error_code& __ec) { return __remove_all(__p, &__ec); }
177inline _LIBCPP_HIDE_FROM_ABI bool remove(const path& __p) { return __remove(__p); }
178inline _LIBCPP_HIDE_FROM_ABI bool remove(const path& __p, error_code& __ec) noexcept { return __remove(__p, &__ec); }
179inline _LIBCPP_HIDE_FROM_ABI void rename(const path& __from, const path& __to) { return __rename(__from, __to); }
180inline _LIBCPP_HIDE_FROM_ABI void rename(const path& __from, const path& __to, error_code& __ec) noexcept { return __rename(__from, __to, &__ec); }
181inline _LIBCPP_HIDE_FROM_ABI void resize_file(const path& __p, uintmax_t __ns) { return __resize_file(__p, __ns); }
182inline _LIBCPP_HIDE_FROM_ABI void resize_file(const path& __p, uintmax_t __ns, error_code& __ec) noexcept { return __resize_file(__p, __ns, &__ec); }
179183_LIBCPP_FUNC_VIS space_info __space(const path&, error_code* __ec = nullptr);
180inline _LIBCPP_INLINE_VISIBILITY space_info space(const path& __p) { return __space(__p); }
181inline _LIBCPP_INLINE_VISIBILITY space_info space(const path& __p, error_code& __ec) noexcept { return __space(__p, &__ec); }
182inline _LIBCPP_INLINE_VISIBILITY file_status status(const path& __p) { return __status(__p); }
183inline _LIBCPP_INLINE_VISIBILITY file_status status(const path& __p, error_code& __ec) noexcept { return __status(__p, &__ec); }
184inline _LIBCPP_INLINE_VISIBILITY file_status symlink_status(const path& __p) { return __symlink_status(__p); }
185inline _LIBCPP_INLINE_VISIBILITY file_status symlink_status(const path& __p, error_code& __ec) noexcept { return __symlink_status(__p, &__ec); }
186inline _LIBCPP_INLINE_VISIBILITY path temp_directory_path() { return __temp_directory_path(); }
187inline _LIBCPP_INLINE_VISIBILITY path temp_directory_path(error_code& __ec) { return __temp_directory_path(&__ec); }
188inline _LIBCPP_INLINE_VISIBILITY path weakly_canonical(path const& __p) { return __weakly_canonical(__p); }
189inline _LIBCPP_INLINE_VISIBILITY path weakly_canonical(path const& __p, error_code& __ec) { return __weakly_canonical(__p, &__ec); }
184inline _LIBCPP_HIDE_FROM_ABI space_info space(const path& __p) { return __space(__p); }
185inline _LIBCPP_HIDE_FROM_ABI space_info space(const path& __p, error_code& __ec) noexcept { return __space(__p, &__ec); }
186inline _LIBCPP_HIDE_FROM_ABI file_status status(const path& __p) { return __status(__p); }
187inline _LIBCPP_HIDE_FROM_ABI file_status status(const path& __p, error_code& __ec) noexcept { return __status(__p, &__ec); }
188inline _LIBCPP_HIDE_FROM_ABI file_status symlink_status(const path& __p) { return __symlink_status(__p); }
189inline _LIBCPP_HIDE_FROM_ABI file_status symlink_status(const path& __p, error_code& __ec) noexcept { return __symlink_status(__p, &__ec); }
190inline _LIBCPP_HIDE_FROM_ABI path temp_directory_path() { return __temp_directory_path(); }
191inline _LIBCPP_HIDE_FROM_ABI path temp_directory_path(error_code& __ec) { return __temp_directory_path(&__ec); }
192inline _LIBCPP_HIDE_FROM_ABI path weakly_canonical(path const& __p) { return __weakly_canonical(__p); }
193inline _LIBCPP_HIDE_FROM_ABI path weakly_canonical(path const& __p, error_code& __ec) { return __weakly_canonical(__p, &__ec); }
190194
191195_LIBCPP_AVAILABILITY_FILESYSTEM_POP
192196
lib/libcxx/include/__filesystem/path.h+147-81
......@@ -10,6 +10,8 @@
1010#ifndef _LIBCPP___FILESYSTEM_PATH_H
1111#define _LIBCPP___FILESYSTEM_PATH_H
1212
13#include <__algorithm/replace.h>
14#include <__algorithm/replace_copy.h>
1315#include <__availability>
1416#include <__config>
1517#include <__iterator/back_insert_iterator.h>
......@@ -24,6 +26,10 @@
2426# include <locale>
2527#endif
2628
29#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
30# pragma GCC system_header
31#endif
32
2733#ifndef _LIBCPP_CXX03_LANG
2834
2935_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
......@@ -65,6 +71,7 @@ struct __can_convert_char<char32_t> {
6571};
6672
6773template <class _ECharT>
74_LIBCPP_HIDE_FROM_ABI
6875typename enable_if<__can_convert_char<_ECharT>::value, bool>::type
6976__is_separator(_ECharT __e) {
7077#if defined(_LIBCPP_WIN32API)
......@@ -95,10 +102,16 @@ struct __is_pathable_string<
95102 : public __can_convert_char<_ECharT> {
96103 using _Str = basic_string<_ECharT, _Traits, _Alloc>;
97104 using _Base = __can_convert_char<_ECharT>;
105
106 _LIBCPP_HIDE_FROM_ABI
98107 static _ECharT const* __range_begin(_Str const& __s) { return __s.data(); }
108
109 _LIBCPP_HIDE_FROM_ABI
99110 static _ECharT const* __range_end(_Str const& __s) {
100111 return __s.data() + __s.length();
101112 }
113
114 _LIBCPP_HIDE_FROM_ABI
102115 static _ECharT __first_or_null(_Str const& __s) {
103116 return __s.empty() ? _ECharT{} : __s[0];
104117 }
......@@ -111,10 +124,16 @@ struct __is_pathable_string<
111124 : public __can_convert_char<_ECharT> {
112125 using _Str = basic_string_view<_ECharT, _Traits>;
113126 using _Base = __can_convert_char<_ECharT>;
127
128 _LIBCPP_HIDE_FROM_ABI
114129 static _ECharT const* __range_begin(_Str const& __s) { return __s.data(); }
130
131 _LIBCPP_HIDE_FROM_ABI
115132 static _ECharT const* __range_end(_Str const& __s) {
116133 return __s.data() + __s.length();
117134 }
135
136 _LIBCPP_HIDE_FROM_ABI
118137 static _ECharT __first_or_null(_Str const& __s) {
119138 return __s.empty() ? _ECharT{} : __s[0];
120139 }
......@@ -132,7 +151,10 @@ struct __is_pathable_char_array<_Source, _ECharT*, _UPtr, true>
132151 : __can_convert_char<typename remove_const<_ECharT>::type> {
133152 using _Base = __can_convert_char<typename remove_const<_ECharT>::type>;
134153
154 _LIBCPP_HIDE_FROM_ABI
135155 static _ECharT const* __range_begin(const _ECharT* __b) { return __b; }
156
157 _LIBCPP_HIDE_FROM_ABI
136158 static _ECharT const* __range_end(const _ECharT* __b) {
137159 using _Iter = const _ECharT*;
138160 const _ECharT __sentinel = _ECharT{};
......@@ -142,6 +164,7 @@ struct __is_pathable_char_array<_Source, _ECharT*, _UPtr, true>
142164 return __e;
143165 }
144166
167 _LIBCPP_HIDE_FROM_ABI
145168 static _ECharT __first_or_null(const _ECharT* __b) { return *__b; }
146169};
147170
......@@ -158,9 +181,13 @@ struct __is_pathable_iter<
158181 using _ECharT = typename iterator_traits<_Iter>::value_type;
159182 using _Base = __can_convert_char<_ECharT>;
160183
184 _LIBCPP_HIDE_FROM_ABI
161185 static _Iter __range_begin(_Iter __b) { return __b; }
186
187 _LIBCPP_HIDE_FROM_ABI
162188 static _NullSentinel __range_end(_Iter) { return _NullSentinel{}; }
163189
190 _LIBCPP_HIDE_FROM_ABI
164191 static _ECharT __first_or_null(_Iter __b) { return *__b; }
165192};
166193
......@@ -210,6 +237,7 @@ struct _PathCVT {
210237 typedef __widen_from_utf8<sizeof(wchar_t) * __CHAR_BIT__> _Widener;
211238#endif
212239
240 _LIBCPP_HIDE_FROM_ABI
213241 static void __append_range(__path_string& __dest, _ECharT const* __b,
214242 _ECharT const* __e) {
215243#if defined(_LIBCPP_WIN32API)
......@@ -222,6 +250,7 @@ struct _PathCVT {
222250 }
223251
224252 template <class _Iter>
253 _LIBCPP_HIDE_FROM_ABI
225254 static void __append_range(__path_string& __dest, _Iter __b, _Iter __e) {
226255 static_assert(!is_same<_Iter, _ECharT*>::value, "Call const overload");
227256 if (__b == __e)
......@@ -239,6 +268,7 @@ struct _PathCVT {
239268 }
240269
241270 template <class _Iter>
271 _LIBCPP_HIDE_FROM_ABI
242272 static void __append_range(__path_string& __dest, _Iter __b, _NullSentinel) {
243273 static_assert(!is_same<_Iter, _ECharT*>::value, "Call const overload");
244274 const _ECharT __sentinel = _ECharT{};
......@@ -259,6 +289,7 @@ struct _PathCVT {
259289 }
260290
261291 template <class _Source>
292 _LIBCPP_HIDE_FROM_ABI
262293 static void __append_source(__path_string& __dest, _Source const& __s) {
263294 using _Traits = __is_pathable<_Source>;
264295 __append_range(__dest, _Traits::__range_begin(__s),
......@@ -271,6 +302,7 @@ template <>
271302struct _PathCVT<__path_value> {
272303
273304 template <class _Iter>
305 _LIBCPP_HIDE_FROM_ABI
274306 static typename enable_if<__is_exactly_cpp17_input_iterator<_Iter>::value>::type
275307 __append_range(__path_string& __dest, _Iter __b, _Iter __e) {
276308 for (; __b != __e; ++__b)
......@@ -278,12 +310,14 @@ struct _PathCVT<__path_value> {
278310 }
279311
280312 template <class _Iter>
313 _LIBCPP_HIDE_FROM_ABI
281314 static typename enable_if<__is_cpp17_forward_iterator<_Iter>::value>::type
282315 __append_range(__path_string& __dest, _Iter __b, _Iter __e) {
283316 __dest.append(__b, __e);
284317 }
285318
286319 template <class _Iter>
320 _LIBCPP_HIDE_FROM_ABI
287321 static void __append_range(__path_string& __dest, _Iter __b, _NullSentinel) {
288322 const char __sentinel = char{};
289323 for (; *__b != __sentinel; ++__b)
......@@ -291,6 +325,7 @@ struct _PathCVT<__path_value> {
291325 }
292326
293327 template <class _Source>
328 _LIBCPP_HIDE_FROM_ABI
294329 static void __append_source(__path_string& __dest, _Source const& __s) {
295330 using _Traits = __is_pathable<_Source>;
296331 __append_range(__dest, _Traits::__range_begin(__s),
......@@ -302,6 +337,7 @@ struct _PathCVT<__path_value> {
302337template <>
303338struct _PathCVT<char> {
304339
340 _LIBCPP_HIDE_FROM_ABI
305341 static void
306342 __append_string(__path_string& __dest, const basic_string<char> &__str) {
307343 size_t __size = __char_to_wide(__str, nullptr, 0);
......@@ -311,6 +347,7 @@ struct _PathCVT<char> {
311347 }
312348
313349 template <class _Iter>
350 _LIBCPP_HIDE_FROM_ABI
314351 static typename enable_if<__is_exactly_cpp17_input_iterator<_Iter>::value>::type
315352 __append_range(__path_string& __dest, _Iter __b, _Iter __e) {
316353 basic_string<char> __tmp(__b, __e);
......@@ -318,6 +355,7 @@ struct _PathCVT<char> {
318355 }
319356
320357 template <class _Iter>
358 _LIBCPP_HIDE_FROM_ABI
321359 static typename enable_if<__is_cpp17_forward_iterator<_Iter>::value>::type
322360 __append_range(__path_string& __dest, _Iter __b, _Iter __e) {
323361 basic_string<char> __tmp(__b, __e);
......@@ -325,6 +363,7 @@ struct _PathCVT<char> {
325363 }
326364
327365 template <class _Iter>
366 _LIBCPP_HIDE_FROM_ABI
328367 static void __append_range(__path_string& __dest, _Iter __b, _NullSentinel) {
329368 const char __sentinel = char{};
330369 basic_string<char> __tmp;
......@@ -334,6 +373,7 @@ struct _PathCVT<char> {
334373 }
335374
336375 template <class _Source>
376 _LIBCPP_HIDE_FROM_ABI
337377 static void __append_source(__path_string& __dest, _Source const& __s) {
338378 using _Traits = __is_pathable<_Source>;
339379 __append_range(__dest, _Traits::__range_begin(__s),
......@@ -347,6 +387,7 @@ struct _PathExport {
347387 typedef __widen_from_utf8<sizeof(_ECharT) * __CHAR_BIT__> _Widener;
348388
349389 template <class _Str>
390 _LIBCPP_HIDE_FROM_ABI
350391 static void __append(_Str& __dest, const __path_string& __src) {
351392 string __utf8;
352393 _Narrower()(back_inserter(__utf8), __src.data(), __src.data() + __src.size());
......@@ -357,6 +398,7 @@ struct _PathExport {
357398template <>
358399struct _PathExport<char> {
359400 template <class _Str>
401 _LIBCPP_HIDE_FROM_ABI
360402 static void __append(_Str& __dest, const __path_string& __src) {
361403 size_t __size = __wide_to_char(__src, nullptr, 0);
362404 size_t __pos = __dest.size();
......@@ -368,6 +410,7 @@ struct _PathExport<char> {
368410template <>
369411struct _PathExport<wchar_t> {
370412 template <class _Str>
413 _LIBCPP_HIDE_FROM_ABI
371414 static void __append(_Str& __dest, const __path_string& __src) {
372415 __dest.append(__src.begin(), __src.end());
373416 }
......@@ -376,6 +419,7 @@ struct _PathExport<wchar_t> {
376419template <>
377420struct _PathExport<char16_t> {
378421 template <class _Str>
422 _LIBCPP_HIDE_FROM_ABI
379423 static void __append(_Str& __dest, const __path_string& __src) {
380424 __dest.append(__src.begin(), __src.end());
381425 }
......@@ -387,6 +431,7 @@ struct _PathExport<char8_t> {
387431 typedef __narrow_to_utf8<sizeof(wchar_t) * __CHAR_BIT__> _Narrower;
388432
389433 template <class _Str>
434 _LIBCPP_HIDE_FROM_ABI
390435 static void __append(_Str& __dest, const __path_string& __src) {
391436 _Narrower()(back_inserter(__dest), __src.data(), __src.data() + __src.size());
392437 }
......@@ -423,21 +468,23 @@ public:
423468 };
424469
425470 // constructors and destructor
426 _LIBCPP_INLINE_VISIBILITY path() noexcept {}
427 _LIBCPP_INLINE_VISIBILITY path(const path& __p) : __pn_(__p.__pn_) {}
428 _LIBCPP_INLINE_VISIBILITY path(path&& __p) noexcept
471 _LIBCPP_HIDE_FROM_ABI path() noexcept {}
472 _LIBCPP_HIDE_FROM_ABI path(const path& __p) : __pn_(__p.__pn_) {}
473 _LIBCPP_HIDE_FROM_ABI path(path&& __p) noexcept
429474 : __pn_(_VSTD::move(__p.__pn_)) {}
430475
431 _LIBCPP_INLINE_VISIBILITY
476 _LIBCPP_HIDE_FROM_ABI
432477 path(string_type&& __s, format = format::auto_format) noexcept
433478 : __pn_(_VSTD::move(__s)) {}
434479
435480 template <class _Source, class = _EnableIfPathable<_Source, void> >
481 _LIBCPP_HIDE_FROM_ABI
436482 path(const _Source& __src, format = format::auto_format) {
437483 _SourceCVT<_Source>::__append_source(__pn_, __src);
438484 }
439485
440486 template <class _InputIt>
487 _LIBCPP_HIDE_FROM_ABI
441488 path(_InputIt __first, _InputIt __last, format = format::auto_format) {
442489 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
443490 _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
......@@ -454,41 +501,42 @@ public:
454501#endif
455502*/
456503
457 _LIBCPP_INLINE_VISIBILITY
504 _LIBCPP_HIDE_FROM_ABI
458505 ~path() = default;
459506
460507 // assignments
461 _LIBCPP_INLINE_VISIBILITY
508 _LIBCPP_HIDE_FROM_ABI
462509 path& operator=(const path& __p) {
463510 __pn_ = __p.__pn_;
464511 return *this;
465512 }
466513
467 _LIBCPP_INLINE_VISIBILITY
514 _LIBCPP_HIDE_FROM_ABI
468515 path& operator=(path&& __p) noexcept {
469516 __pn_ = _VSTD::move(__p.__pn_);
470517 return *this;
471518 }
472519
473 _LIBCPP_INLINE_VISIBILITY
520 _LIBCPP_HIDE_FROM_ABI
474521 path& operator=(string_type&& __s) noexcept {
475522 __pn_ = _VSTD::move(__s);
476523 return *this;
477524 }
478525
479 _LIBCPP_INLINE_VISIBILITY
526 _LIBCPP_HIDE_FROM_ABI
480527 path& assign(string_type&& __s) noexcept {
481528 __pn_ = _VSTD::move(__s);
482529 return *this;
483530 }
484531
485532 template <class _Source>
486 _LIBCPP_INLINE_VISIBILITY _EnableIfPathable<_Source>
533 _LIBCPP_HIDE_FROM_ABI _EnableIfPathable<_Source>
487534 operator=(const _Source& __src) {
488535 return this->assign(__src);
489536 }
490537
491538 template <class _Source>
539 _LIBCPP_HIDE_FROM_ABI
492540 _EnableIfPathable<_Source> assign(const _Source& __src) {
493541 __pn_.clear();
494542 _SourceCVT<_Source>::__append_source(__pn_, __src);
......@@ -496,6 +544,7 @@ public:
496544 }
497545
498546 template <class _InputIt>
547 _LIBCPP_HIDE_FROM_ABI
499548 path& assign(_InputIt __first, _InputIt __last) {
500549 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
501550 __pn_.clear();
......@@ -506,6 +555,7 @@ public:
506555public:
507556 // appends
508557#if defined(_LIBCPP_WIN32API)
558 _LIBCPP_HIDE_FROM_ABI
509559 path& operator/=(const path& __p) {
510560 auto __p_root_name = __p.__root_name();
511561 auto __p_root_name_size = __p_root_name.size();
......@@ -532,15 +582,18 @@ public:
532582 }
533583
534584 template <class _Source>
585 _LIBCPP_HIDE_FROM_ABI
535586 _EnableIfPathable<_Source> append(const _Source& __src) {
536587 return operator/=(path(__src));
537588 }
538589
539590 template <class _InputIt>
591 _LIBCPP_HIDE_FROM_ABI
540592 path& append(_InputIt __first, _InputIt __last) {
541593 return operator/=(path(__first, __last));
542594 }
543595#else
596 _LIBCPP_HIDE_FROM_ABI
544597 path& operator/=(const path& __p) {
545598 if (__p.is_absolute()) {
546599 __pn_ = __p.__pn_;
......@@ -556,12 +609,13 @@ public:
556609 // is known at compile time to be "/' since the user almost certainly intended
557610 // to append a separator instead of overwriting the path with "/"
558611 template <class _Source>
559 _LIBCPP_INLINE_VISIBILITY _EnableIfPathable<_Source>
612 _LIBCPP_HIDE_FROM_ABI _EnableIfPathable<_Source>
560613 operator/=(const _Source& __src) {
561614 return this->append(__src);
562615 }
563616
564617 template <class _Source>
618 _LIBCPP_HIDE_FROM_ABI
565619 _EnableIfPathable<_Source> append(const _Source& __src) {
566620 using _Traits = __is_pathable<_Source>;
567621 using _CVT = _PathCVT<_SourceChar<_Source> >;
......@@ -575,6 +629,7 @@ public:
575629 }
576630
577631 template <class _InputIt>
632 _LIBCPP_HIDE_FROM_ABI
578633 path& append(_InputIt __first, _InputIt __last) {
579634 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
580635 static_assert(__can_convert_char<_ItVal>::value, "Must convertible");
......@@ -589,37 +644,38 @@ public:
589644#endif
590645
591646 // concatenation
592 _LIBCPP_INLINE_VISIBILITY
647 _LIBCPP_HIDE_FROM_ABI
593648 path& operator+=(const path& __x) {
594649 __pn_ += __x.__pn_;
595650 return *this;
596651 }
597652
598 _LIBCPP_INLINE_VISIBILITY
653 _LIBCPP_HIDE_FROM_ABI
599654 path& operator+=(const string_type& __x) {
600655 __pn_ += __x;
601656 return *this;
602657 }
603658
604 _LIBCPP_INLINE_VISIBILITY
659 _LIBCPP_HIDE_FROM_ABI
605660 path& operator+=(__string_view __x) {
606661 __pn_ += __x;
607662 return *this;
608663 }
609664
610 _LIBCPP_INLINE_VISIBILITY
665 _LIBCPP_HIDE_FROM_ABI
611666 path& operator+=(const value_type* __x) {
612667 __pn_ += __x;
613668 return *this;
614669 }
615670
616 _LIBCPP_INLINE_VISIBILITY
671 _LIBCPP_HIDE_FROM_ABI
617672 path& operator+=(value_type __x) {
618673 __pn_ += __x;
619674 return *this;
620675 }
621676
622677 template <class _ECharT>
678 _LIBCPP_HIDE_FROM_ABI
623679 typename enable_if<__can_convert_char<_ECharT>::value, path&>::type
624680 operator+=(_ECharT __x) {
625681 _PathCVT<_ECharT>::__append_source(__pn_,
......@@ -628,17 +684,20 @@ public:
628684 }
629685
630686 template <class _Source>
687 _LIBCPP_HIDE_FROM_ABI
631688 _EnableIfPathable<_Source> operator+=(const _Source& __x) {
632689 return this->concat(__x);
633690 }
634691
635692 template <class _Source>
693 _LIBCPP_HIDE_FROM_ABI
636694 _EnableIfPathable<_Source> concat(const _Source& __x) {
637695 _SourceCVT<_Source>::__append_source(__pn_, __x);
638696 return *this;
639697 }
640698
641699 template <class _InputIt>
700 _LIBCPP_HIDE_FROM_ABI
642701 path& concat(_InputIt __first, _InputIt __last) {
643702 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
644703 _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
......@@ -646,9 +705,10 @@ public:
646705 }
647706
648707 // modifiers
649 _LIBCPP_INLINE_VISIBILITY
708 _LIBCPP_HIDE_FROM_ABI
650709 void clear() noexcept { __pn_.clear(); }
651710
711 _LIBCPP_HIDE_FROM_ABI
652712 path& make_preferred() {
653713#if defined(_LIBCPP_WIN32API)
654714 _VSTD::replace(__pn_.begin(), __pn_.end(), L'/', L'\\');
......@@ -656,7 +716,7 @@ public:
656716 return *this;
657717 }
658718
659 _LIBCPP_INLINE_VISIBILITY
719 _LIBCPP_HIDE_FROM_ABI
660720 path& remove_filename() {
661721 auto __fname = __filename();
662722 if (!__fname.empty())
......@@ -664,6 +724,7 @@ public:
664724 return *this;
665725 }
666726
727 _LIBCPP_HIDE_FROM_ABI
667728 path& replace_filename(const path& __replacement) {
668729 remove_filename();
669730 return (*this /= __replacement);
......@@ -671,25 +732,26 @@ public:
671732
672733 path& replace_extension(const path& __replacement = path());
673734
674 _LIBCPP_INLINE_VISIBILITY
735 _LIBCPP_HIDE_FROM_ABI
675736 void swap(path& __rhs) noexcept { __pn_.swap(__rhs.__pn_); }
676737
677738 // private helper to allow reserving memory in the path
678 _LIBCPP_INLINE_VISIBILITY
739 _LIBCPP_HIDE_FROM_ABI
679740 void __reserve(size_t __s) { __pn_.reserve(__s); }
680741
681742 // native format observers
682 _LIBCPP_INLINE_VISIBILITY
743 _LIBCPP_HIDE_FROM_ABI
683744 const string_type& native() const noexcept { return __pn_; }
684745
685 _LIBCPP_INLINE_VISIBILITY
746 _LIBCPP_HIDE_FROM_ABI
686747 const value_type* c_str() const noexcept { return __pn_.c_str(); }
687748
688 _LIBCPP_INLINE_VISIBILITY operator string_type() const { return __pn_; }
749 _LIBCPP_HIDE_FROM_ABI operator string_type() const { return __pn_; }
689750
690751#if defined(_LIBCPP_WIN32API)
691 _LIBCPP_INLINE_VISIBILITY _VSTD::wstring wstring() const { return __pn_; }
752 _LIBCPP_HIDE_FROM_ABI _VSTD::wstring wstring() const { return __pn_; }
692753
754 _LIBCPP_HIDE_FROM_ABI
693755 _VSTD::wstring generic_wstring() const {
694756 _VSTD::wstring __s;
695757 __s.resize(__pn_.size());
......@@ -700,6 +762,7 @@ public:
700762#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
701763 template <class _ECharT, class _Traits = char_traits<_ECharT>,
702764 class _Allocator = allocator<_ECharT> >
765 _LIBCPP_HIDE_FROM_ABI
703766 basic_string<_ECharT, _Traits, _Allocator>
704767 string(const _Allocator& __a = _Allocator()) const {
705768 using _Str = basic_string<_ECharT, _Traits, _Allocator>;
......@@ -709,10 +772,10 @@ public:
709772 return __s;
710773 }
711774
712 _LIBCPP_INLINE_VISIBILITY _VSTD::string string() const {
775 _LIBCPP_HIDE_FROM_ABI _VSTD::string string() const {
713776 return string<char>();
714777 }
715 _LIBCPP_INLINE_VISIBILITY __u8_string u8string() const {
778 _LIBCPP_HIDE_FROM_ABI __u8_string u8string() const {
716779 using _CVT = __narrow_to_utf8<sizeof(wchar_t) * __CHAR_BIT__>;
717780 __u8_string __s;
718781 __s.reserve(__pn_.size());
......@@ -720,16 +783,17 @@ public:
720783 return __s;
721784 }
722785
723 _LIBCPP_INLINE_VISIBILITY _VSTD::u16string u16string() const {
786 _LIBCPP_HIDE_FROM_ABI _VSTD::u16string u16string() const {
724787 return string<char16_t>();
725788 }
726 _LIBCPP_INLINE_VISIBILITY _VSTD::u32string u32string() const {
789 _LIBCPP_HIDE_FROM_ABI _VSTD::u32string u32string() const {
727790 return string<char32_t>();
728791 }
729792
730793 // generic format observers
731794 template <class _ECharT, class _Traits = char_traits<_ECharT>,
732795 class _Allocator = allocator<_ECharT> >
796 _LIBCPP_HIDE_FROM_ABI
733797 basic_string<_ECharT, _Traits, _Allocator>
734798 generic_string(const _Allocator& __a = _Allocator()) const {
735799 using _Str = basic_string<_ECharT, _Traits, _Allocator>;
......@@ -742,9 +806,10 @@ public:
742806 return __s;
743807 }
744808
745 _VSTD::string generic_string() const { return generic_string<char>(); }
746 _VSTD::u16string generic_u16string() const { return generic_string<char16_t>(); }
747 _VSTD::u32string generic_u32string() const { return generic_string<char32_t>(); }
809 _LIBCPP_HIDE_FROM_ABI _VSTD::string generic_string() const { return generic_string<char>(); }
810 _LIBCPP_HIDE_FROM_ABI _VSTD::u16string generic_u16string() const { return generic_string<char16_t>(); }
811 _LIBCPP_HIDE_FROM_ABI _VSTD::u32string generic_u32string() const { return generic_string<char32_t>(); }
812 _LIBCPP_HIDE_FROM_ABI
748813 __u8_string generic_u8string() const {
749814 __u8_string __s = u8string();
750815 _VSTD::replace(__s.begin(), __s.end(), '\\', '/');
......@@ -753,16 +818,17 @@ public:
753818#endif /* !_LIBCPP_HAS_NO_LOCALIZATION */
754819#else /* _LIBCPP_WIN32API */
755820
756 _LIBCPP_INLINE_VISIBILITY _VSTD::string string() const { return __pn_; }
821 _LIBCPP_HIDE_FROM_ABI _VSTD::string string() const { return __pn_; }
757822#ifndef _LIBCPP_HAS_NO_CHAR8_T
758 _LIBCPP_INLINE_VISIBILITY _VSTD::u8string u8string() const { return _VSTD::u8string(__pn_.begin(), __pn_.end()); }
823 _LIBCPP_HIDE_FROM_ABI _VSTD::u8string u8string() const { return _VSTD::u8string(__pn_.begin(), __pn_.end()); }
759824#else
760 _LIBCPP_INLINE_VISIBILITY _VSTD::string u8string() const { return __pn_; }
825 _LIBCPP_HIDE_FROM_ABI _VSTD::string u8string() const { return __pn_; }
761826#endif
762827
763828#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
764829 template <class _ECharT, class _Traits = char_traits<_ECharT>,
765830 class _Allocator = allocator<_ECharT> >
831 _LIBCPP_HIDE_FROM_ABI
766832 basic_string<_ECharT, _Traits, _Allocator>
767833 string(const _Allocator& __a = _Allocator()) const {
768834 using _CVT = __widen_from_utf8<sizeof(_ECharT) * __CHAR_BIT__>;
......@@ -774,39 +840,40 @@ public:
774840 }
775841
776842#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
777 _LIBCPP_INLINE_VISIBILITY _VSTD::wstring wstring() const {
843 _LIBCPP_HIDE_FROM_ABI _VSTD::wstring wstring() const {
778844 return string<wchar_t>();
779845 }
780846#endif
781 _LIBCPP_INLINE_VISIBILITY _VSTD::u16string u16string() const {
847 _LIBCPP_HIDE_FROM_ABI _VSTD::u16string u16string() const {
782848 return string<char16_t>();
783849 }
784 _LIBCPP_INLINE_VISIBILITY _VSTD::u32string u32string() const {
850 _LIBCPP_HIDE_FROM_ABI _VSTD::u32string u32string() const {
785851 return string<char32_t>();
786852 }
787853#endif /* !_LIBCPP_HAS_NO_LOCALIZATION */
788854
789855 // generic format observers
790 _VSTD::string generic_string() const { return __pn_; }
856 _LIBCPP_HIDE_FROM_ABI _VSTD::string generic_string() const { return __pn_; }
791857#ifndef _LIBCPP_HAS_NO_CHAR8_T
792 _VSTD::u8string generic_u8string() const { return _VSTD::u8string(__pn_.begin(), __pn_.end()); }
858 _LIBCPP_HIDE_FROM_ABI _VSTD::u8string generic_u8string() const { return _VSTD::u8string(__pn_.begin(), __pn_.end()); }
793859#else
794 _VSTD::string generic_u8string() const { return __pn_; }
860 _LIBCPP_HIDE_FROM_ABI _VSTD::string generic_u8string() const { return __pn_; }
795861#endif
796862
797863#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
798864 template <class _ECharT, class _Traits = char_traits<_ECharT>,
799865 class _Allocator = allocator<_ECharT> >
866 _LIBCPP_HIDE_FROM_ABI
800867 basic_string<_ECharT, _Traits, _Allocator>
801868 generic_string(const _Allocator& __a = _Allocator()) const {
802869 return string<_ECharT, _Traits, _Allocator>(__a);
803870 }
804871
805872#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
806 _VSTD::wstring generic_wstring() const { return string<wchar_t>(); }
873 _LIBCPP_HIDE_FROM_ABI _VSTD::wstring generic_wstring() const { return string<wchar_t>(); }
807874#endif
808 _VSTD::u16string generic_u16string() const { return string<char16_t>(); }
809 _VSTD::u32string generic_u32string() const { return string<char32_t>(); }
875 _LIBCPP_HIDE_FROM_ABI _VSTD::u16string generic_u16string() const { return string<char16_t>(); }
876 _LIBCPP_HIDE_FROM_ABI _VSTD::u32string generic_u32string() const { return string<char32_t>(); }
810877#endif /* !_LIBCPP_HAS_NO_LOCALIZATION */
811878#endif /* !_LIBCPP_WIN32API */
812879
......@@ -823,77 +890,77 @@ private:
823890
824891public:
825892 // compare
826 _LIBCPP_INLINE_VISIBILITY int compare(const path& __p) const noexcept {
893 _LIBCPP_HIDE_FROM_ABI int compare(const path& __p) const noexcept {
827894 return __compare(__p.__pn_);
828895 }
829 _LIBCPP_INLINE_VISIBILITY int compare(const string_type& __s) const {
896 _LIBCPP_HIDE_FROM_ABI int compare(const string_type& __s) const {
830897 return __compare(__s);
831898 }
832 _LIBCPP_INLINE_VISIBILITY int compare(__string_view __s) const {
899 _LIBCPP_HIDE_FROM_ABI int compare(__string_view __s) const {
833900 return __compare(__s);
834901 }
835 _LIBCPP_INLINE_VISIBILITY int compare(const value_type* __s) const {
902 _LIBCPP_HIDE_FROM_ABI int compare(const value_type* __s) const {
836903 return __compare(__s);
837904 }
838905
839906 // decomposition
840 _LIBCPP_INLINE_VISIBILITY path root_name() const {
907 _LIBCPP_HIDE_FROM_ABI path root_name() const {
841908 return string_type(__root_name());
842909 }
843 _LIBCPP_INLINE_VISIBILITY path root_directory() const {
910 _LIBCPP_HIDE_FROM_ABI path root_directory() const {
844911 return string_type(__root_directory());
845912 }
846 _LIBCPP_INLINE_VISIBILITY path root_path() const {
913 _LIBCPP_HIDE_FROM_ABI path root_path() const {
847914#if defined(_LIBCPP_WIN32API)
848915 return string_type(__root_path_raw());
849916#else
850917 return root_name().append(string_type(__root_directory()));
851918#endif
852919 }
853 _LIBCPP_INLINE_VISIBILITY path relative_path() const {
920 _LIBCPP_HIDE_FROM_ABI path relative_path() const {
854921 return string_type(__relative_path());
855922 }
856 _LIBCPP_INLINE_VISIBILITY path parent_path() const {
923 _LIBCPP_HIDE_FROM_ABI path parent_path() const {
857924 return string_type(__parent_path());
858925 }
859 _LIBCPP_INLINE_VISIBILITY path filename() const {
926 _LIBCPP_HIDE_FROM_ABI path filename() const {
860927 return string_type(__filename());
861928 }
862 _LIBCPP_INLINE_VISIBILITY path stem() const { return string_type(__stem()); }
863 _LIBCPP_INLINE_VISIBILITY path extension() const {
929 _LIBCPP_HIDE_FROM_ABI path stem() const { return string_type(__stem()); }
930 _LIBCPP_HIDE_FROM_ABI path extension() const {
864931 return string_type(__extension());
865932 }
866933
867934 // query
868 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool
935 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI bool
869936 empty() const noexcept {
870937 return __pn_.empty();
871938 }
872939
873 _LIBCPP_INLINE_VISIBILITY bool has_root_name() const {
940 _LIBCPP_HIDE_FROM_ABI bool has_root_name() const {
874941 return !__root_name().empty();
875942 }
876 _LIBCPP_INLINE_VISIBILITY bool has_root_directory() const {
943 _LIBCPP_HIDE_FROM_ABI bool has_root_directory() const {
877944 return !__root_directory().empty();
878945 }
879 _LIBCPP_INLINE_VISIBILITY bool has_root_path() const {
946 _LIBCPP_HIDE_FROM_ABI bool has_root_path() const {
880947 return !__root_path_raw().empty();
881948 }
882 _LIBCPP_INLINE_VISIBILITY bool has_relative_path() const {
949 _LIBCPP_HIDE_FROM_ABI bool has_relative_path() const {
883950 return !__relative_path().empty();
884951 }
885 _LIBCPP_INLINE_VISIBILITY bool has_parent_path() const {
952 _LIBCPP_HIDE_FROM_ABI bool has_parent_path() const {
886953 return !__parent_path().empty();
887954 }
888 _LIBCPP_INLINE_VISIBILITY bool has_filename() const {
955 _LIBCPP_HIDE_FROM_ABI bool has_filename() const {
889956 return !__filename().empty();
890957 }
891 _LIBCPP_INLINE_VISIBILITY bool has_stem() const { return !__stem().empty(); }
892 _LIBCPP_INLINE_VISIBILITY bool has_extension() const {
958 _LIBCPP_HIDE_FROM_ABI bool has_stem() const { return !__stem().empty(); }
959 _LIBCPP_HIDE_FROM_ABI bool has_extension() const {
893960 return !__extension().empty();
894961 }
895962
896 _LIBCPP_INLINE_VISIBILITY bool is_absolute() const {
963 _LIBCPP_HIDE_FROM_ABI bool is_absolute() const {
897964#if defined(_LIBCPP_WIN32API)
898965 __string_view __root_name_str = __root_name();
899966 __string_view __root_dir = __root_directory();
......@@ -917,13 +984,13 @@ public:
917984 return has_root_directory();
918985#endif
919986 }
920 _LIBCPP_INLINE_VISIBILITY bool is_relative() const { return !is_absolute(); }
987 _LIBCPP_HIDE_FROM_ABI bool is_relative() const { return !is_absolute(); }
921988
922989 // relative paths
923990 path lexically_normal() const;
924991 path lexically_relative(const path& __base) const;
925992
926 _LIBCPP_INLINE_VISIBILITY path lexically_proximate(const path& __base) const {
993 _LIBCPP_HIDE_FROM_ABI path lexically_proximate(const path& __base) const {
927994 path __result = this->lexically_relative(__base);
928995 if (__result.native().empty())
929996 return *this;
......@@ -939,7 +1006,7 @@ public:
9391006
9401007#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
9411008 template <class _CharT, class _Traits>
942 _LIBCPP_INLINE_VISIBILITY friend
1009 _LIBCPP_HIDE_FROM_ABI friend
9431010 typename enable_if<is_same<_CharT, value_type>::value &&
9441011 is_same<_Traits, char_traits<value_type> >::value,
9451012 basic_ostream<_CharT, _Traits>&>::type
......@@ -949,7 +1016,7 @@ public:
9491016 }
9501017
9511018 template <class _CharT, class _Traits>
952 _LIBCPP_INLINE_VISIBILITY friend
1019 _LIBCPP_HIDE_FROM_ABI friend
9531020 typename enable_if<!is_same<_CharT, value_type>::value ||
9541021 !is_same<_Traits, char_traits<value_type> >::value,
9551022 basic_ostream<_CharT, _Traits>&>::type
......@@ -959,42 +1026,41 @@ public:
9591026 }
9601027
9611028 template <class _CharT, class _Traits>
962 _LIBCPP_INLINE_VISIBILITY friend basic_istream<_CharT, _Traits>&
1029 _LIBCPP_HIDE_FROM_ABI friend basic_istream<_CharT, _Traits>&
9631030 operator>>(basic_istream<_CharT, _Traits>& __is, path& __p) {
9641031 basic_string<_CharT, _Traits> __tmp;
965 __is >> __quoted(__tmp);
1032 __is >> _VSTD::__quoted(__tmp);
9661033 __p = __tmp;
9671034 return __is;
9681035 }
9691036#endif // !_LIBCPP_HAS_NO_LOCALIZATION
9701037
971 friend _LIBCPP_INLINE_VISIBILITY bool operator==(const path& __lhs, const path& __rhs) noexcept {
1038 friend _LIBCPP_HIDE_FROM_ABI bool operator==(const path& __lhs, const path& __rhs) noexcept {
9721039 return __lhs.__compare(__rhs.__pn_) == 0;
9731040 }
974 friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const path& __lhs, const path& __rhs) noexcept {
1041 friend _LIBCPP_HIDE_FROM_ABI bool operator!=(const path& __lhs, const path& __rhs) noexcept {
9751042 return __lhs.__compare(__rhs.__pn_) != 0;
9761043 }
977 friend _LIBCPP_INLINE_VISIBILITY bool operator<(const path& __lhs, const path& __rhs) noexcept {
1044 friend _LIBCPP_HIDE_FROM_ABI bool operator<(const path& __lhs, const path& __rhs) noexcept {
9781045 return __lhs.__compare(__rhs.__pn_) < 0;
9791046 }
980 friend _LIBCPP_INLINE_VISIBILITY bool operator<=(const path& __lhs, const path& __rhs) noexcept {
1047 friend _LIBCPP_HIDE_FROM_ABI bool operator<=(const path& __lhs, const path& __rhs) noexcept {
9811048 return __lhs.__compare(__rhs.__pn_) <= 0;
9821049 }
983 friend _LIBCPP_INLINE_VISIBILITY bool operator>(const path& __lhs, const path& __rhs) noexcept {
1050 friend _LIBCPP_HIDE_FROM_ABI bool operator>(const path& __lhs, const path& __rhs) noexcept {
9841051 return __lhs.__compare(__rhs.__pn_) > 0;
9851052 }
986 friend _LIBCPP_INLINE_VISIBILITY bool operator>=(const path& __lhs, const path& __rhs) noexcept {
1053 friend _LIBCPP_HIDE_FROM_ABI bool operator>=(const path& __lhs, const path& __rhs) noexcept {
9871054 return __lhs.__compare(__rhs.__pn_) >= 0;
9881055 }
9891056
990 friend _LIBCPP_INLINE_VISIBILITY path operator/(const path& __lhs,
991 const path& __rhs) {
1057 friend _LIBCPP_HIDE_FROM_ABI path operator/(const path& __lhs, const path& __rhs) {
9921058 path __result(__lhs);
9931059 __result /= __rhs;
9941060 return __result;
9951061 }
9961062private:
997 inline _LIBCPP_INLINE_VISIBILITY path&
1063 inline _LIBCPP_HIDE_FROM_ABI path&
9981064 __assign_view(__string_view const& __s) noexcept {
9991065 __pn_ = string_type(__s);
10001066 return *this;
......@@ -1002,7 +1068,7 @@ private:
10021068 string_type __pn_;
10031069};
10041070
1005inline _LIBCPP_INLINE_VISIBILITY void swap(path& __lhs, path& __rhs) noexcept {
1071inline _LIBCPP_HIDE_FROM_ABI void swap(path& __lhs, path& __rhs) noexcept {
10061072 __lhs.swap(__rhs);
10071073}
10081074
lib/libcxx/include/__filesystem/path_iterator.h+5-1
......@@ -10,15 +10,19 @@
1010#ifndef _LIBCPP___FILESYSTEM_PATH_ITERATOR_H
1111#define _LIBCPP___FILESYSTEM_PATH_ITERATOR_H
1212
13#include <__assert>
1314#include <__availability>
1415#include <__config>
15#include <__debug>
1616#include <__filesystem/path.h>
1717#include <__iterator/iterator_traits.h>
1818#include <cstddef>
1919#include <string>
2020#include <string_view>
2121
22#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23# pragma GCC system_header
24#endif
25
2226#ifndef _LIBCPP_CXX03_LANG
2327
2428_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
lib/libcxx/include/__filesystem/perm_options.h+21-17
......@@ -13,6 +13,10 @@
1313#include <__availability>
1414#include <__config>
1515
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
1620#ifndef _LIBCPP_CXX03_LANG
1721
1822_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
......@@ -27,41 +31,41 @@ enum class _LIBCPP_ENUM_VIS perm_options : unsigned char {
2731};
2832
2933_LIBCPP_INLINE_VISIBILITY
30inline constexpr perm_options operator&(perm_options _LHS, perm_options _RHS) {
31 return static_cast<perm_options>(static_cast<unsigned>(_LHS) &
32 static_cast<unsigned>(_RHS));
34inline constexpr perm_options operator&(perm_options __lhs, perm_options __rhs) {
35 return static_cast<perm_options>(static_cast<unsigned>(__lhs) &
36 static_cast<unsigned>(__rhs));
3337}
3438
3539_LIBCPP_INLINE_VISIBILITY
36inline constexpr perm_options operator|(perm_options _LHS, perm_options _RHS) {
37 return static_cast<perm_options>(static_cast<unsigned>(_LHS) |
38 static_cast<unsigned>(_RHS));
40inline constexpr perm_options operator|(perm_options __lhs, perm_options __rhs) {
41 return static_cast<perm_options>(static_cast<unsigned>(__lhs) |
42 static_cast<unsigned>(__rhs));
3943}
4044
4145_LIBCPP_INLINE_VISIBILITY
42inline constexpr perm_options operator^(perm_options _LHS, perm_options _RHS) {
43 return static_cast<perm_options>(static_cast<unsigned>(_LHS) ^
44 static_cast<unsigned>(_RHS));
46inline constexpr perm_options operator^(perm_options __lhs, perm_options __rhs) {
47 return static_cast<perm_options>(static_cast<unsigned>(__lhs) ^
48 static_cast<unsigned>(__rhs));
4549}
4650
4751_LIBCPP_INLINE_VISIBILITY
48inline constexpr perm_options operator~(perm_options _LHS) {
49 return static_cast<perm_options>(~static_cast<unsigned>(_LHS));
52inline constexpr perm_options operator~(perm_options __lhs) {
53 return static_cast<perm_options>(~static_cast<unsigned>(__lhs));
5054}
5155
5256_LIBCPP_INLINE_VISIBILITY
53inline perm_options& operator&=(perm_options& _LHS, perm_options _RHS) {
54 return _LHS = _LHS & _RHS;
57inline perm_options& operator&=(perm_options& __lhs, perm_options __rhs) {
58 return __lhs = __lhs & __rhs;
5559}
5660
5761_LIBCPP_INLINE_VISIBILITY
58inline perm_options& operator|=(perm_options& _LHS, perm_options _RHS) {
59 return _LHS = _LHS | _RHS;
62inline perm_options& operator|=(perm_options& __lhs, perm_options __rhs) {
63 return __lhs = __lhs | __rhs;
6064}
6165
6266_LIBCPP_INLINE_VISIBILITY
63inline perm_options& operator^=(perm_options& _LHS, perm_options _RHS) {
64 return _LHS = _LHS ^ _RHS;
67inline perm_options& operator^=(perm_options& __lhs, perm_options __rhs) {
68 return __lhs = __lhs ^ __rhs;
6569}
6670
6771_LIBCPP_AVAILABILITY_FILESYSTEM_POP
lib/libcxx/include/__filesystem/perms.h+18-14
......@@ -13,6 +13,10 @@
1313#include <__availability>
1414#include <__config>
1515
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
1620#ifndef _LIBCPP_CXX03_LANG
1721
1822_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
......@@ -51,36 +55,36 @@ enum class _LIBCPP_ENUM_VIS perms : unsigned {
5155};
5256
5357_LIBCPP_INLINE_VISIBILITY
54inline constexpr perms operator&(perms _LHS, perms _RHS) {
55 return static_cast<perms>(static_cast<unsigned>(_LHS) &
56 static_cast<unsigned>(_RHS));
58inline constexpr perms operator&(perms __lhs, perms __rhs) {
59 return static_cast<perms>(static_cast<unsigned>(__lhs) &
60 static_cast<unsigned>(__rhs));
5761}
5862
5963_LIBCPP_INLINE_VISIBILITY
60inline constexpr perms operator|(perms _LHS, perms _RHS) {
61 return static_cast<perms>(static_cast<unsigned>(_LHS) |
62 static_cast<unsigned>(_RHS));
64inline constexpr perms operator|(perms __lhs, perms __rhs) {
65 return static_cast<perms>(static_cast<unsigned>(__lhs) |
66 static_cast<unsigned>(__rhs));
6367}
6468
6569_LIBCPP_INLINE_VISIBILITY
66inline constexpr perms operator^(perms _LHS, perms _RHS) {
67 return static_cast<perms>(static_cast<unsigned>(_LHS) ^
68 static_cast<unsigned>(_RHS));
70inline constexpr perms operator^(perms __lhs, perms __rhs) {
71 return static_cast<perms>(static_cast<unsigned>(__lhs) ^
72 static_cast<unsigned>(__rhs));
6973}
7074
7175_LIBCPP_INLINE_VISIBILITY
72inline constexpr perms operator~(perms _LHS) {
73 return static_cast<perms>(~static_cast<unsigned>(_LHS));
76inline constexpr perms operator~(perms __lhs) {
77 return static_cast<perms>(~static_cast<unsigned>(__lhs));
7478}
7579
7680_LIBCPP_INLINE_VISIBILITY
77inline perms& operator&=(perms& _LHS, perms _RHS) { return _LHS = _LHS & _RHS; }
81inline perms& operator&=(perms& __lhs, perms __rhs) { return __lhs = __lhs & __rhs; }
7882
7983_LIBCPP_INLINE_VISIBILITY
80inline perms& operator|=(perms& _LHS, perms _RHS) { return _LHS = _LHS | _RHS; }
84inline perms& operator|=(perms& __lhs, perms __rhs) { return __lhs = __lhs | __rhs; }
8185
8286_LIBCPP_INLINE_VISIBILITY
83inline perms& operator^=(perms& _LHS, perms _RHS) { return _LHS = _LHS ^ _RHS; }
87inline perms& operator^=(perms& __lhs, perms __rhs) { return __lhs = __lhs ^ __rhs; }
8488
8589_LIBCPP_AVAILABILITY_FILESYSTEM_POP
8690
lib/libcxx/include/__filesystem/recursive_directory_iterator.h+6-2
......@@ -22,6 +22,10 @@
2222#include <cstddef>
2323#include <system_error>
2424
25#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
26# pragma GCC system_header
27#endif
28
2529#ifndef _LIBCPP_CXX03_LANG
2630
2731_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
......@@ -164,7 +168,7 @@ _LIBCPP_AVAILABILITY_FILESYSTEM_POP
164168
165169_LIBCPP_END_NAMESPACE_FILESYSTEM
166170
167#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
171#if _LIBCPP_STD_VER > 17
168172
169173template <>
170174_LIBCPP_AVAILABILITY_FILESYSTEM
......@@ -174,7 +178,7 @@ template <>
174178_LIBCPP_AVAILABILITY_FILESYSTEM
175179inline constexpr bool _VSTD::ranges::enable_view<_VSTD_FS::recursive_directory_iterator> = true;
176180
177#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
181#endif // _LIBCPP_STD_VER > 17
178182
179183#endif // _LIBCPP_CXX03_LANG
180184
lib/libcxx/include/__filesystem/space_info.h+4
......@@ -14,6 +14,10 @@
1414#include <__config>
1515#include <cstdint>
1616
17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18# pragma GCC system_header
19#endif
20
1721#ifndef _LIBCPP_CXX03_LANG
1822
1923_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
lib/libcxx/include/__filesystem/u8path.h+12
......@@ -10,11 +10,23 @@
1010#ifndef _LIBCPP___FILESYSTEM_U8PATH_H
1111#define _LIBCPP___FILESYSTEM_U8PATH_H
1212
13#include <__algorithm/unwrap_iter.h>
1314#include <__availability>
1415#include <__config>
1516#include <__filesystem/path.h>
17#include <string>
1618#include <type_traits>
1719
20// Only required on Windows for __widen_from_utf8, and included conservatively
21// because it requires support for localization.
22#if defined(_LIBCPP_WIN32API)
23# include <locale>
24#endif
25
26#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
27# pragma GCC system_header
28#endif
29
1830#ifndef _LIBCPP_CXX03_LANG
1931
2032_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
lib/libcxx/include/__format/buffer.h created+369
......@@ -0,0 +1,369 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___FORMAT_BUFFER_H
11#define _LIBCPP___FORMAT_BUFFER_H
12
13#include <__algorithm/copy_n.h>
14#include <__algorithm/max.h>
15#include <__algorithm/min.h>
16#include <__algorithm/unwrap_iter.h>
17#include <__config>
18#include <__format/enable_insertable.h>
19#include <__format/format_to_n_result.h>
20#include <__format/formatter.h> // for __char_type TODO FMT Move the concept?
21#include <__iterator/back_insert_iterator.h>
22#include <__iterator/concepts.h>
23#include <__iterator/incrementable_traits.h>
24#include <__iterator/iterator_traits.h>
25#include <__iterator/wrap_iter.h>
26#include <__utility/move.h>
27#include <concepts>
28#include <cstddef>
29#include <type_traits>
30
31#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
32# pragma GCC system_header
33#endif
34
35_LIBCPP_PUSH_MACROS
36#include <__undef_macros>
37
38_LIBCPP_BEGIN_NAMESPACE_STD
39
40#if _LIBCPP_STD_VER > 17
41
42namespace __format {
43
44/// A "buffer" that handles writing to the proper iterator.
45///
46/// This helper is used together with the @ref back_insert_iterator to offer
47/// type-erasure for the formatting functions. This reduces the number to
48/// template instantiations.
49template <__formatter::__char_type _CharT>
50class _LIBCPP_TEMPLATE_VIS __output_buffer {
51public:
52 using value_type = _CharT;
53
54 template <class _Tp>
55 _LIBCPP_HIDE_FROM_ABI explicit __output_buffer(_CharT* __ptr,
56 size_t __capacity, _Tp* __obj)
57 : __ptr_(__ptr), __capacity_(__capacity),
58 __flush_([](_CharT* __p, size_t __size, void* __o) {
59 static_cast<_Tp*>(__o)->flush(__p, __size);
60 }),
61 __obj_(__obj) {}
62
63 _LIBCPP_HIDE_FROM_ABI void reset(_CharT* __ptr, size_t __capacity) {
64 __ptr_ = __ptr;
65 __capacity_ = __capacity;
66 }
67
68 _LIBCPP_HIDE_FROM_ABI auto make_output_iterator() {
69 return back_insert_iterator{*this};
70 }
71
72 // TODO FMT It would be nice to have an overload taking a
73 // basic_string_view<_CharT> and append it directly.
74 _LIBCPP_HIDE_FROM_ABI void push_back(_CharT __c) {
75 __ptr_[__size_++] = __c;
76
77 // Profiling showed flushing after adding is more efficient than flushing
78 // when entering the function.
79 if (__size_ == __capacity_)
80 flush();
81 }
82
83 _LIBCPP_HIDE_FROM_ABI void flush() {
84 __flush_(__ptr_, __size_, __obj_);
85 __size_ = 0;
86 }
87
88private:
89 _CharT* __ptr_;
90 size_t __capacity_;
91 size_t __size_{0};
92 void (*__flush_)(_CharT*, size_t, void*);
93 void* __obj_;
94};
95
96/// A storage using an internal buffer.
97///
98/// This storage is used when writing a single element to the output iterator
99/// is expensive.
100template <__formatter::__char_type _CharT>
101class _LIBCPP_TEMPLATE_VIS __internal_storage {
102public:
103 _LIBCPP_HIDE_FROM_ABI _CharT* begin() { return __buffer_; }
104
105 static constexpr size_t __buffer_size = 256 / sizeof(_CharT);
106
107private:
108 _CharT __buffer_[__buffer_size];
109};
110
111/// A storage writing directly to the storage.
112///
113/// This requires the storage to be a contiguous buffer of \a _CharT.
114/// Since the output is directly written to the underlying storage this class
115/// is just an empty class.
116template <__formatter::__char_type _CharT>
117class _LIBCPP_TEMPLATE_VIS __direct_storage {};
118
119template <class _OutIt, class _CharT>
120concept __enable_direct_output = __formatter::__char_type<_CharT> &&
121 (same_as<_OutIt, _CharT*>
122#ifndef _LIBCPP_ENABLE_DEBUG_MODE
123 || same_as<_OutIt, __wrap_iter<_CharT*>>
124#endif
125 );
126
127/// Write policy for directly writing to the underlying output.
128template <class _OutIt, __formatter::__char_type _CharT>
129class _LIBCPP_TEMPLATE_VIS __writer_direct {
130public:
131 _LIBCPP_HIDE_FROM_ABI explicit __writer_direct(_OutIt __out_it)
132 : __out_it_(__out_it) {}
133
134 _LIBCPP_HIDE_FROM_ABI auto out() { return __out_it_; }
135
136 _LIBCPP_HIDE_FROM_ABI void flush(_CharT*, size_t __size) {
137 // _OutIt can be a __wrap_iter<CharT*>. Therefore the original iterator
138 // is adjusted.
139 __out_it_ += __size;
140 }
141
142private:
143 _OutIt __out_it_;
144};
145
146/// Write policy for copying the buffer to the output.
147template <class _OutIt, __formatter::__char_type _CharT>
148class _LIBCPP_TEMPLATE_VIS __writer_iterator {
149public:
150 _LIBCPP_HIDE_FROM_ABI explicit __writer_iterator(_OutIt __out_it)
151 : __out_it_{_VSTD::move(__out_it)} {}
152
153 _LIBCPP_HIDE_FROM_ABI auto out() { return __out_it_; }
154
155 _LIBCPP_HIDE_FROM_ABI void flush(_CharT* __ptr, size_t __size) {
156 __out_it_ = _VSTD::copy_n(__ptr, __size, _VSTD::move(__out_it_));
157 }
158
159private:
160 _OutIt __out_it_;
161};
162
163/// Concept to see whether a \a _Container is insertable.
164///
165/// The concept is used to validate whether multiple calls to a
166/// \ref back_insert_iterator can be replace by a call to \c _Container::insert.
167///
168/// \note a \a _Container needs to opt-in to the concept by specializing
169/// \ref __enable_insertable.
170template <class _Container>
171concept __insertable =
172 __enable_insertable<_Container> && __formatter::__char_type<typename _Container::value_type> &&
173 requires(_Container& __t, add_pointer_t<typename _Container::value_type> __first,
174 add_pointer_t<typename _Container::value_type> __last) { __t.insert(__t.end(), __first, __last); };
175
176/// Extract the container type of a \ref back_insert_iterator.
177template <class _It>
178struct _LIBCPP_TEMPLATE_VIS __back_insert_iterator_container {
179 using type = void;
180};
181
182template <__insertable _Container>
183struct _LIBCPP_TEMPLATE_VIS __back_insert_iterator_container<back_insert_iterator<_Container>> {
184 using type = _Container;
185};
186
187/// Write policy for inserting the buffer in a container.
188template <class _Container>
189class _LIBCPP_TEMPLATE_VIS __writer_container {
190public:
191 using _CharT = typename _Container::value_type;
192
193 _LIBCPP_HIDE_FROM_ABI explicit __writer_container(back_insert_iterator<_Container> __out_it)
194 : __container_{__out_it.__get_container()} {}
195
196 _LIBCPP_HIDE_FROM_ABI auto out() { return back_inserter(*__container_); }
197
198 _LIBCPP_HIDE_FROM_ABI void flush(_CharT* __ptr, size_t __size) {
199 __container_->insert(__container_->end(), __ptr, __ptr + __size);
200 }
201
202private:
203 _Container* __container_;
204};
205
206/// Selects the type of the writer used for the output iterator.
207template <class _OutIt, class _CharT>
208class _LIBCPP_TEMPLATE_VIS __writer_selector {
209 using _Container = typename __back_insert_iterator_container<_OutIt>::type;
210
211public:
212 using type = conditional_t<!same_as<_Container, void>, __writer_container<_Container>,
213 conditional_t<__enable_direct_output<_OutIt, _CharT>, __writer_direct<_OutIt, _CharT>,
214 __writer_iterator<_OutIt, _CharT>>>;
215};
216
217/// The generic formatting buffer.
218template <class _OutIt, __formatter::__char_type _CharT>
219requires(output_iterator<_OutIt, const _CharT&>) class _LIBCPP_TEMPLATE_VIS
220 __format_buffer {
221 using _Storage =
222 conditional_t<__enable_direct_output<_OutIt, _CharT>,
223 __direct_storage<_CharT>, __internal_storage<_CharT>>;
224
225public:
226 _LIBCPP_HIDE_FROM_ABI explicit __format_buffer(_OutIt __out_it)
227 requires(same_as<_Storage, __internal_storage<_CharT>>)
228 : __output_(__storage_.begin(), __storage_.__buffer_size, this), __writer_(_VSTD::move(__out_it)) {}
229
230 _LIBCPP_HIDE_FROM_ABI explicit __format_buffer(_OutIt __out_it) requires(
231 same_as<_Storage, __direct_storage<_CharT>>)
232 : __output_(_VSTD::__unwrap_iter(__out_it), size_t(-1), this),
233 __writer_(_VSTD::move(__out_it)) {}
234
235 _LIBCPP_HIDE_FROM_ABI auto make_output_iterator() {
236 return __output_.make_output_iterator();
237 }
238
239 _LIBCPP_HIDE_FROM_ABI void flush(_CharT* __ptr, size_t __size) {
240 __writer_.flush(__ptr, __size);
241 }
242
243 _LIBCPP_HIDE_FROM_ABI _OutIt out() && {
244 __output_.flush();
245 return _VSTD::move(__writer_).out();
246 }
247
248private:
249 _LIBCPP_NO_UNIQUE_ADDRESS _Storage __storage_;
250 __output_buffer<_CharT> __output_;
251 typename __writer_selector<_OutIt, _CharT>::type __writer_;
252};
253
254/// A buffer that counts the number of insertions.
255///
256/// Since \ref formatted_size only needs to know the size, the output itself is
257/// discarded.
258template <__formatter::__char_type _CharT>
259class _LIBCPP_TEMPLATE_VIS __formatted_size_buffer {
260public:
261 _LIBCPP_HIDE_FROM_ABI auto make_output_iterator() { return __output_.make_output_iterator(); }
262
263 _LIBCPP_HIDE_FROM_ABI void flush(const _CharT*, size_t __size) { __size_ += __size; }
264
265 _LIBCPP_HIDE_FROM_ABI size_t result() && {
266 __output_.flush();
267 return __size_;
268 }
269
270private:
271 __internal_storage<_CharT> __storage_;
272 __output_buffer<_CharT> __output_{__storage_.begin(), __storage_.__buffer_size, this};
273 size_t __size_{0};
274};
275
276/// The base of a buffer that counts and limits the number of insertions.
277template <class _OutIt, __formatter::__char_type _CharT, bool>
278 requires(output_iterator<_OutIt, const _CharT&>)
279struct _LIBCPP_TEMPLATE_VIS __format_to_n_buffer_base {
280 using _Size = iter_difference_t<_OutIt>;
281
282public:
283 _LIBCPP_HIDE_FROM_ABI explicit __format_to_n_buffer_base(_OutIt __out_it, _Size __n)
284 : __writer_(_VSTD::move(__out_it)), __n_(_VSTD::max(_Size(0), __n)) {}
285
286 _LIBCPP_HIDE_FROM_ABI void flush(_CharT* __ptr, size_t __size) {
287 if (_Size(__size_) <= __n_)
288 __writer_.flush(__ptr, _VSTD::min(_Size(__size), __n_ - __size_));
289 __size_ += __size;
290 }
291
292protected:
293 __internal_storage<_CharT> __storage_;
294 __output_buffer<_CharT> __output_{__storage_.begin(), __storage_.__buffer_size, this};
295 typename __writer_selector<_OutIt, _CharT>::type __writer_;
296
297 _Size __n_;
298 _Size __size_{0};
299};
300
301/// The base of a buffer that counts and limits the number of insertions.
302///
303/// This version is used when \c __enable_direct_output<_OutIt, _CharT> == true.
304///
305/// This class limits the size available the the direct writer so it will not
306/// exceed the maximum number of code units.
307template <class _OutIt, __formatter::__char_type _CharT>
308 requires(output_iterator<_OutIt, const _CharT&>)
309class _LIBCPP_TEMPLATE_VIS __format_to_n_buffer_base<_OutIt, _CharT, true> {
310 using _Size = iter_difference_t<_OutIt>;
311
312public:
313 _LIBCPP_HIDE_FROM_ABI explicit __format_to_n_buffer_base(_OutIt __out_it, _Size __n)
314 : __output_(_VSTD::__unwrap_iter(__out_it), __n, this), __writer_(_VSTD::move(__out_it)) {
315 if (__n <= 0) [[unlikely]]
316 __output_.reset(__storage_.begin(), __storage_.__buffer_size);
317 }
318
319 _LIBCPP_HIDE_FROM_ABI void flush(_CharT* __ptr, size_t __size) {
320 // A flush to the direct writer happens in two occasions:
321 // - The format function has written the maximum number of allowed code
322 // units. At this point it's no longer valid to write to this writer. So
323 // switch to the internal storage. This internal storage doesn't need to
324 // be written anywhere so the flush for that storage writes no output.
325 // - The format_to_n function is finished. In this case there's no need to
326 // switch the buffer, but for simplicity the buffers are still switched.
327 // When the __n <= 0 the constructor already switched the buffers.
328 if (__size_ == 0 && __ptr != __storage_.begin()) {
329 __writer_.flush(__ptr, __size);
330 __output_.reset(__storage_.begin(), __storage_.__buffer_size);
331 }
332
333 __size_ += __size;
334 }
335
336protected:
337 __internal_storage<_CharT> __storage_;
338 __output_buffer<_CharT> __output_;
339 __writer_direct<_OutIt, _CharT> __writer_;
340
341 _Size __size_{0};
342};
343
344/// The buffer that counts and limits the number of insertions.
345template <class _OutIt, __formatter::__char_type _CharT>
346 requires(output_iterator<_OutIt, const _CharT&>)
347struct _LIBCPP_TEMPLATE_VIS __format_to_n_buffer final
348 : public __format_to_n_buffer_base< _OutIt, _CharT, __enable_direct_output<_OutIt, _CharT>> {
349 using _Base = __format_to_n_buffer_base<_OutIt, _CharT, __enable_direct_output<_OutIt, _CharT>>;
350 using _Size = iter_difference_t<_OutIt>;
351
352public:
353 _LIBCPP_HIDE_FROM_ABI explicit __format_to_n_buffer(_OutIt __out_it, _Size __n) : _Base(_VSTD::move(__out_it), __n) {}
354 _LIBCPP_HIDE_FROM_ABI auto make_output_iterator() { return this->__output_.make_output_iterator(); }
355
356 _LIBCPP_HIDE_FROM_ABI format_to_n_result<_OutIt> result() && {
357 this->__output_.flush();
358 return {_VSTD::move(this->__writer_).out(), this->__size_};
359 }
360};
361} // namespace __format
362
363#endif //_LIBCPP_STD_VER > 17
364
365_LIBCPP_END_NAMESPACE_STD
366
367_LIBCPP_POP_MACROS
368
369#endif // _LIBCPP___FORMAT_BUFFER_H
lib/libcxx/include/__format/concepts.h created+53
......@@ -0,0 +1,53 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___FORMAT_CONCEPTS_H
11#define _LIBCPP___FORMAT_CONCEPTS_H
12
13#include <__concepts/same_as.h>
14#include <__concepts/semiregular.h>
15#include <__config>
16#include <__format/format_fwd.h>
17#include <__format/format_parse_context.h>
18#include <type_traits>
19
20#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21# pragma GCC system_header
22#endif
23
24_LIBCPP_BEGIN_NAMESPACE_STD
25
26#if _LIBCPP_STD_VER > 17
27
28// The output iterator isn't specified. A formatter should accept any
29// output_iterator. This iterator is a minimal iterator to test the concept.
30// (Note testing for (w)format_context would be a valid choice, but requires
31// selecting the proper one depending on the type of _CharT.)
32template <class _CharT>
33using __fmt_iter_for = _CharT*;
34
35// The concept is based on P2286R6
36// It lacks the const of __cf as required by, the not yet accepted, LWG-3636.
37// The current formatters can't be easily adapted, but that is WIP.
38// TODO FMT properly implement this concepts once accepted.
39template <class _Tp, class _CharT>
40concept __formattable = (semiregular<formatter<remove_cvref_t<_Tp>, _CharT>>) &&
41 requires(formatter<remove_cvref_t<_Tp>, _CharT> __f,
42 formatter<remove_cvref_t<_Tp>, _CharT> __cf, _Tp __t,
43 basic_format_context<__fmt_iter_for<_CharT>, _CharT> __fc,
44 basic_format_parse_context<_CharT> __pc) {
45 { __f.parse(__pc) } -> same_as<typename basic_format_parse_context<_CharT>::iterator>;
46 { __cf.format(__t, __fc) } -> same_as<__fmt_iter_for<_CharT>>;
47 };
48
49#endif //_LIBCPP_STD_VER > 17
50
51_LIBCPP_END_NAMESPACE_STD
52
53#endif // _LIBCPP___FORMAT_CONCEPTS_H
lib/libcxx/include/__format/enable_insertable.h created+35
......@@ -0,0 +1,35 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___FORMAT_ENABLE_INSERTABLE_H
11#define _LIBCPP___FORMAT_ENABLE_INSERTABLE_H
12
13#include <__config>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21#if _LIBCPP_STD_VER > 17
22
23namespace __format {
24
25/// Opt-in to enable \ref __insertable for a \a _Container.
26template <class _Container>
27inline constexpr bool __enable_insertable = false;
28
29} // namespace __format
30
31#endif //_LIBCPP_STD_VER > 17
32
33_LIBCPP_END_NAMESPACE_STD
34
35#endif // _LIBCPP___FORMAT_ENABLE_INSERTABLE_H
lib/libcxx/include/__format/extended_grapheme_cluster_table.h created+332
......@@ -0,0 +1,332 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10// WARNING, this entire header is generated by
11// utiles/generate_extended_grapheme_cluster_table.py
12// DO NOT MODIFY!
13
14// UNICODE, INC. LICENSE AGREEMENT - DATA FILES AND SOFTWARE
15//
16// See Terms of Use <https://www.unicode.org/copyright.html>
17// for definitions of Unicode Inc.'s Data Files and Software.
18//
19// NOTICE TO USER: Carefully read the following legal agreement.
20// BY DOWNLOADING, INSTALLING, COPYING OR OTHERWISE USING UNICODE INC.'S
21// DATA FILES ("DATA FILES"), AND/OR SOFTWARE ("SOFTWARE"),
22// YOU UNEQUIVOCALLY ACCEPT, AND AGREE TO BE BOUND BY, ALL OF THE
23// TERMS AND CONDITIONS OF THIS AGREEMENT.
24// IF YOU DO NOT AGREE, DO NOT DOWNLOAD, INSTALL, COPY, DISTRIBUTE OR USE
25// THE DATA FILES OR SOFTWARE.
26//
27// COPYRIGHT AND PERMISSION NOTICE
28//
29// Copyright (c) 1991-2022 Unicode, Inc. All rights reserved.
30// Distributed under the Terms of Use in https://www.unicode.org/copyright.html.
31//
32// Permission is hereby granted, free of charge, to any person obtaining
33// a copy of the Unicode data files and any associated documentation
34// (the "Data Files") or Unicode software and any associated documentation
35// (the "Software") to deal in the Data Files or Software
36// without restriction, including without limitation the rights to use,
37// copy, modify, merge, publish, distribute, and/or sell copies of
38// the Data Files or Software, and to permit persons to whom the Data Files
39// or Software are furnished to do so, provided that either
40// (a) this copyright and permission notice appear with all copies
41// of the Data Files or Software, or
42// (b) this copyright and permission notice appear in associated
43// Documentation.
44//
45// THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF
46// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
47// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
48// NONINFRINGEMENT OF THIRD PARTY RIGHTS.
49// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS
50// NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL
51// DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
52// DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
53// TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
54// PERFORMANCE OF THE DATA FILES OR SOFTWARE.
55//
56// Except as contained in this notice, the name of a copyright holder
57// shall not be used in advertising or otherwise to promote the sale,
58// use or other dealings in these Data Files or Software without prior
59// written authorization of the copyright holder.
60
61#ifndef _LIBCPP___FORMAT_EXTENDED_GRAPHEME_CLUSTER_TABLE_H
62#define _LIBCPP___FORMAT_EXTENDED_GRAPHEME_CLUSTER_TABLE_H
63
64#include <__algorithm/upper_bound.h>
65#include <__config>
66#include <__iterator/access.h>
67#include <cstddef>
68#include <cstdint>
69
70#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
71# pragma GCC system_header
72#endif
73
74_LIBCPP_BEGIN_NAMESPACE_STD
75
76#if _LIBCPP_STD_VER > 17
77
78namespace __extended_grapheme_custer_property_boundary {
79
80enum class __property : uint8_t {
81 // Values generated from the data files.
82 __CR,
83 __Control,
84 __Extend,
85 __Extended_Pictographic,
86 __L,
87 __LF,
88 __LV,
89 __LVT,
90 __Prepend,
91 __Regional_Indicator,
92 __SpacingMark,
93 __T,
94 __V,
95 __ZWJ,
96
97 // The properies below aren't stored in the "database".
98
99 // Text position properties.
100 __sot,
101 __eot,
102
103 // The code unit has none of above properties.
104 __none
105};
106
107/// The entries of the extended grapheme cluster bondary property table.
108///
109/// The data is generated from
110/// - https://www.unicode.org/Public/UCD/latest/ucd/auxiliary/GraphemeBreakProperty.txt
111/// - https://www.unicode.org/Public/UCD/latest/ucd/emoji/emoji-data.txt
112///
113/// The data has 3 values
114/// - bits [0, 3] The property. One of the values generated form the datafiles
115/// of \ref __property
116/// - bits [4, 10] The size of the range.
117/// - bits [11, 31] The lower bound code point of the range. The upper bound of
118/// the range is lower bound + size.
119///
120/// The 7 bits for the size allow a maximum range of 128 elements. Some ranges
121/// in the Unicode tables are larger. They are stored in multiple consecutive
122/// ranges in the data table. An alternative would be to store the sizes in a
123/// separate 16-bit value. The original MSVC STL code had such an approach, but
124/// this approach uses less space for the data and is about 4% faster in the
125/// following benchmark.
126/// libcxx/benchmarks/std_format_spec_string_unicode.bench.cpp
127inline constexpr uint32_t __entries[1480] = {
128 0x00000091, 0x00005005, 0x00005811, 0x00006800, 0x00007111, 0x0003fa01, 0x00054803, 0x00056801, 0x00057003,
129 0x001806f2, 0x00241862, 0x002c8ac2, 0x002df802, 0x002e0812, 0x002e2012, 0x002e3802, 0x00300058, 0x003080a2,
130 0x0030e001, 0x00325942, 0x00338002, 0x0036b062, 0x0036e808, 0x0036f852, 0x00373812, 0x00375032, 0x00387808,
131 0x00388802, 0x003981a2, 0x003d30a2, 0x003f5882, 0x003fe802, 0x0040b032, 0x0040d882, 0x00412822, 0x00414842,
132 0x0042c822, 0x00448018, 0x0044c072, 0x00465172, 0x00471008, 0x004719f2, 0x0048180a, 0x0049d002, 0x0049d80a,
133 0x0049e002, 0x0049f02a, 0x004a0872, 0x004a483a, 0x004a6802, 0x004a701a, 0x004a8862, 0x004b1012, 0x004c0802,
134 0x004c101a, 0x004de002, 0x004df002, 0x004df81a, 0x004e0832, 0x004e381a, 0x004e581a, 0x004e6802, 0x004eb802,
135 0x004f1012, 0x004ff002, 0x00500812, 0x0050180a, 0x0051e002, 0x0051f02a, 0x00520812, 0x00523812, 0x00525822,
136 0x00528802, 0x00538012, 0x0053a802, 0x00540812, 0x0054180a, 0x0055e002, 0x0055f02a, 0x00560842, 0x00563812,
137 0x0056480a, 0x0056581a, 0x00566802, 0x00571012, 0x0057d052, 0x00580802, 0x0058101a, 0x0059e002, 0x0059f012,
138 0x005a000a, 0x005a0832, 0x005a381a, 0x005a581a, 0x005a6802, 0x005aa822, 0x005b1012, 0x005c1002, 0x005df002,
139 0x005df80a, 0x005e0002, 0x005e081a, 0x005e302a, 0x005e502a, 0x005e6802, 0x005eb802, 0x00600002, 0x0060082a,
140 0x00602002, 0x0061e002, 0x0061f022, 0x0062083a, 0x00623022, 0x00625032, 0x0062a812, 0x00631012, 0x00640802,
141 0x0064101a, 0x0065e002, 0x0065f00a, 0x0065f802, 0x0066001a, 0x00661002, 0x0066181a, 0x00663002, 0x0066381a,
142 0x0066501a, 0x00666012, 0x0066a812, 0x00671012, 0x00680012, 0x0068101a, 0x0069d812, 0x0069f002, 0x0069f81a,
143 0x006a0832, 0x006a302a, 0x006a502a, 0x006a6802, 0x006a7008, 0x006ab802, 0x006b1012, 0x006c0802, 0x006c101a,
144 0x006e5002, 0x006e7802, 0x006e801a, 0x006e9022, 0x006eb002, 0x006ec06a, 0x006ef802, 0x006f901a, 0x00718802,
145 0x0071980a, 0x0071a062, 0x00723872, 0x00758802, 0x0075980a, 0x0075a082, 0x00764052, 0x0078c012, 0x0079a802,
146 0x0079b802, 0x0079c802, 0x0079f01a, 0x007b88d2, 0x007bf80a, 0x007c0042, 0x007c3012, 0x007c68a2, 0x007cca32,
147 0x007e3002, 0x00816832, 0x0081880a, 0x00819052, 0x0081c812, 0x0081d81a, 0x0081e812, 0x0082b01a, 0x0082c012,
148 0x0082f022, 0x00838832, 0x00841002, 0x0084200a, 0x00842812, 0x00846802, 0x0084e802, 0x008805f4, 0x008b047c,
149 0x008d457b, 0x009ae822, 0x00b89022, 0x00b8a80a, 0x00b99012, 0x00b9a00a, 0x00ba9012, 0x00bb9012, 0x00bda012,
150 0x00bdb00a, 0x00bdb862, 0x00bdf07a, 0x00be3002, 0x00be381a, 0x00be48a2, 0x00bee802, 0x00c05822, 0x00c07001,
151 0x00c07802, 0x00c42812, 0x00c54802, 0x00c90022, 0x00c9183a, 0x00c93812, 0x00c9482a, 0x00c9801a, 0x00c99002,
152 0x00c9985a, 0x00c9c822, 0x00d0b812, 0x00d0c81a, 0x00d0d802, 0x00d2a80a, 0x00d2b002, 0x00d2b80a, 0x00d2c062,
153 0x00d30002, 0x00d31002, 0x00d32872, 0x00d3685a, 0x00d39892, 0x00d3f802, 0x00d581e2, 0x00d80032, 0x00d8200a,
154 0x00d9a062, 0x00d9d80a, 0x00d9e002, 0x00d9e84a, 0x00da1002, 0x00da181a, 0x00db5882, 0x00dc0012, 0x00dc100a,
155 0x00dd080a, 0x00dd1032, 0x00dd301a, 0x00dd4012, 0x00dd500a, 0x00dd5822, 0x00df3002, 0x00df380a, 0x00df4012,
156 0x00df502a, 0x00df6802, 0x00df700a, 0x00df7822, 0x00df901a, 0x00e1207a, 0x00e16072, 0x00e1a01a, 0x00e1b012,
157 0x00e68022, 0x00e6a0c2, 0x00e7080a, 0x00e71062, 0x00e76802, 0x00e7a002, 0x00e7b80a, 0x00e7c012, 0x00ee03f2,
158 0x01005801, 0x01006002, 0x0100680d, 0x01007011, 0x01014061, 0x0101e003, 0x01024803, 0x010300f1, 0x01068202,
159 0x01091003, 0x0109c803, 0x010ca053, 0x010d4813, 0x0118d013, 0x01194003, 0x011c4003, 0x011e7803, 0x011f48a3,
160 0x011fc023, 0x01261003, 0x012d5013, 0x012db003, 0x012e0003, 0x012fd833, 0x01300053, 0x013038b3, 0x0130a713,
161 0x01348753, 0x013840a3, 0x0138a003, 0x0138b003, 0x0138e803, 0x01390803, 0x01394003, 0x01399813, 0x013a2003,
162 0x013a3803, 0x013a6003, 0x013a7003, 0x013a9823, 0x013ab803, 0x013b1843, 0x013ca823, 0x013d0803, 0x013d8003,
163 0x013df803, 0x0149a013, 0x01582823, 0x0158d813, 0x015a8003, 0x015aa803, 0x01677822, 0x016bf802, 0x016f01f2,
164 0x01815052, 0x01818003, 0x0181e803, 0x0184c812, 0x0194b803, 0x0194c803, 0x05337832, 0x0533a092, 0x0534f012,
165 0x05378012, 0x05401002, 0x05403002, 0x05405802, 0x0541181a, 0x05412812, 0x0541380a, 0x05416002, 0x0544001a,
166 0x0545a0fa, 0x05462012, 0x05470112, 0x0547f802, 0x05493072, 0x054a38a2, 0x054a901a, 0x054b01c4, 0x054c0022,
167 0x054c180a, 0x054d9802, 0x054da01a, 0x054db032, 0x054dd01a, 0x054de012, 0x054df02a, 0x054f2802, 0x05514852,
168 0x0551781a, 0x05518812, 0x0551981a, 0x0551a812, 0x05521802, 0x05526002, 0x0552680a, 0x0553e002, 0x05558002,
169 0x05559022, 0x0555b812, 0x0555f012, 0x05560802, 0x0557580a, 0x05576012, 0x0557701a, 0x0557a80a, 0x0557b002,
170 0x055f181a, 0x055f2802, 0x055f301a, 0x055f4002, 0x055f481a, 0x055f600a, 0x055f6802, 0x05600006, 0x056009a7,
171 0x0560e006, 0x0560e9a7, 0x0561c006, 0x0561c9a7, 0x0562a006, 0x0562a9a7, 0x05638006, 0x056389a7, 0x05646006,
172 0x056469a7, 0x05654006, 0x056549a7, 0x05662006, 0x056629a7, 0x05670006, 0x056709a7, 0x0567e006, 0x0567e9a7,
173 0x0568c006, 0x0568c9a7, 0x0569a006, 0x0569a9a7, 0x056a8006, 0x056a89a7, 0x056b6006, 0x056b69a7, 0x056c4006,
174 0x056c49a7, 0x056d2006, 0x056d29a7, 0x056e0006, 0x056e09a7, 0x056ee006, 0x056ee9a7, 0x056fc006, 0x056fc9a7,
175 0x0570a006, 0x0570a9a7, 0x05718006, 0x057189a7, 0x05726006, 0x057269a7, 0x05734006, 0x057349a7, 0x05742006,
176 0x057429a7, 0x05750006, 0x057509a7, 0x0575e006, 0x0575e9a7, 0x0576c006, 0x0576c9a7, 0x0577a006, 0x0577a9a7,
177 0x05788006, 0x057889a7, 0x05796006, 0x057969a7, 0x057a4006, 0x057a49a7, 0x057b2006, 0x057b29a7, 0x057c0006,
178 0x057c09a7, 0x057ce006, 0x057ce9a7, 0x057dc006, 0x057dc9a7, 0x057ea006, 0x057ea9a7, 0x057f8006, 0x057f89a7,
179 0x05806006, 0x058069a7, 0x05814006, 0x058149a7, 0x05822006, 0x058229a7, 0x05830006, 0x058309a7, 0x0583e006,
180 0x0583e9a7, 0x0584c006, 0x0584c9a7, 0x0585a006, 0x0585a9a7, 0x05868006, 0x058689a7, 0x05876006, 0x058769a7,
181 0x05884006, 0x058849a7, 0x05892006, 0x058929a7, 0x058a0006, 0x058a09a7, 0x058ae006, 0x058ae9a7, 0x058bc006,
182 0x058bc9a7, 0x058ca006, 0x058ca9a7, 0x058d8006, 0x058d89a7, 0x058e6006, 0x058e69a7, 0x058f4006, 0x058f49a7,
183 0x05902006, 0x059029a7, 0x05910006, 0x059109a7, 0x0591e006, 0x0591e9a7, 0x0592c006, 0x0592c9a7, 0x0593a006,
184 0x0593a9a7, 0x05948006, 0x059489a7, 0x05956006, 0x059569a7, 0x05964006, 0x059649a7, 0x05972006, 0x059729a7,
185 0x05980006, 0x059809a7, 0x0598e006, 0x0598e9a7, 0x0599c006, 0x0599c9a7, 0x059aa006, 0x059aa9a7, 0x059b8006,
186 0x059b89a7, 0x059c6006, 0x059c69a7, 0x059d4006, 0x059d49a7, 0x059e2006, 0x059e29a7, 0x059f0006, 0x059f09a7,
187 0x059fe006, 0x059fe9a7, 0x05a0c006, 0x05a0c9a7, 0x05a1a006, 0x05a1a9a7, 0x05a28006, 0x05a289a7, 0x05a36006,
188 0x05a369a7, 0x05a44006, 0x05a449a7, 0x05a52006, 0x05a529a7, 0x05a60006, 0x05a609a7, 0x05a6e006, 0x05a6e9a7,
189 0x05a7c006, 0x05a7c9a7, 0x05a8a006, 0x05a8a9a7, 0x05a98006, 0x05a989a7, 0x05aa6006, 0x05aa69a7, 0x05ab4006,
190 0x05ab49a7, 0x05ac2006, 0x05ac29a7, 0x05ad0006, 0x05ad09a7, 0x05ade006, 0x05ade9a7, 0x05aec006, 0x05aec9a7,
191 0x05afa006, 0x05afa9a7, 0x05b08006, 0x05b089a7, 0x05b16006, 0x05b169a7, 0x05b24006, 0x05b249a7, 0x05b32006,
192 0x05b329a7, 0x05b40006, 0x05b409a7, 0x05b4e006, 0x05b4e9a7, 0x05b5c006, 0x05b5c9a7, 0x05b6a006, 0x05b6a9a7,
193 0x05b78006, 0x05b789a7, 0x05b86006, 0x05b869a7, 0x05b94006, 0x05b949a7, 0x05ba2006, 0x05ba29a7, 0x05bb0006,
194 0x05bb09a7, 0x05bbe006, 0x05bbe9a7, 0x05bcc006, 0x05bcc9a7, 0x05bda006, 0x05bda9a7, 0x05be8006, 0x05be89a7,
195 0x05bf6006, 0x05bf69a7, 0x05c04006, 0x05c049a7, 0x05c12006, 0x05c129a7, 0x05c20006, 0x05c209a7, 0x05c2e006,
196 0x05c2e9a7, 0x05c3c006, 0x05c3c9a7, 0x05c4a006, 0x05c4a9a7, 0x05c58006, 0x05c589a7, 0x05c66006, 0x05c669a7,
197 0x05c74006, 0x05c749a7, 0x05c82006, 0x05c829a7, 0x05c90006, 0x05c909a7, 0x05c9e006, 0x05c9e9a7, 0x05cac006,
198 0x05cac9a7, 0x05cba006, 0x05cba9a7, 0x05cc8006, 0x05cc89a7, 0x05cd6006, 0x05cd69a7, 0x05ce4006, 0x05ce49a7,
199 0x05cf2006, 0x05cf29a7, 0x05d00006, 0x05d009a7, 0x05d0e006, 0x05d0e9a7, 0x05d1c006, 0x05d1c9a7, 0x05d2a006,
200 0x05d2a9a7, 0x05d38006, 0x05d389a7, 0x05d46006, 0x05d469a7, 0x05d54006, 0x05d549a7, 0x05d62006, 0x05d629a7,
201 0x05d70006, 0x05d709a7, 0x05d7e006, 0x05d7e9a7, 0x05d8c006, 0x05d8c9a7, 0x05d9a006, 0x05d9a9a7, 0x05da8006,
202 0x05da89a7, 0x05db6006, 0x05db69a7, 0x05dc4006, 0x05dc49a7, 0x05dd2006, 0x05dd29a7, 0x05de0006, 0x05de09a7,
203 0x05dee006, 0x05dee9a7, 0x05dfc006, 0x05dfc9a7, 0x05e0a006, 0x05e0a9a7, 0x05e18006, 0x05e189a7, 0x05e26006,
204 0x05e269a7, 0x05e34006, 0x05e349a7, 0x05e42006, 0x05e429a7, 0x05e50006, 0x05e509a7, 0x05e5e006, 0x05e5e9a7,
205 0x05e6c006, 0x05e6c9a7, 0x05e7a006, 0x05e7a9a7, 0x05e88006, 0x05e889a7, 0x05e96006, 0x05e969a7, 0x05ea4006,
206 0x05ea49a7, 0x05eb2006, 0x05eb29a7, 0x05ec0006, 0x05ec09a7, 0x05ece006, 0x05ece9a7, 0x05edc006, 0x05edc9a7,
207 0x05eea006, 0x05eea9a7, 0x05ef8006, 0x05ef89a7, 0x05f06006, 0x05f069a7, 0x05f14006, 0x05f149a7, 0x05f22006,
208 0x05f229a7, 0x05f30006, 0x05f309a7, 0x05f3e006, 0x05f3e9a7, 0x05f4c006, 0x05f4c9a7, 0x05f5a006, 0x05f5a9a7,
209 0x05f68006, 0x05f689a7, 0x05f76006, 0x05f769a7, 0x05f84006, 0x05f849a7, 0x05f92006, 0x05f929a7, 0x05fa0006,
210 0x05fa09a7, 0x05fae006, 0x05fae9a7, 0x05fbc006, 0x05fbc9a7, 0x05fca006, 0x05fca9a7, 0x05fd8006, 0x05fd89a7,
211 0x05fe6006, 0x05fe69a7, 0x05ff4006, 0x05ff49a7, 0x06002006, 0x060029a7, 0x06010006, 0x060109a7, 0x0601e006,
212 0x0601e9a7, 0x0602c006, 0x0602c9a7, 0x0603a006, 0x0603a9a7, 0x06048006, 0x060489a7, 0x06056006, 0x060569a7,
213 0x06064006, 0x060649a7, 0x06072006, 0x060729a7, 0x06080006, 0x060809a7, 0x0608e006, 0x0608e9a7, 0x0609c006,
214 0x0609c9a7, 0x060aa006, 0x060aa9a7, 0x060b8006, 0x060b89a7, 0x060c6006, 0x060c69a7, 0x060d4006, 0x060d49a7,
215 0x060e2006, 0x060e29a7, 0x060f0006, 0x060f09a7, 0x060fe006, 0x060fe9a7, 0x0610c006, 0x0610c9a7, 0x0611a006,
216 0x0611a9a7, 0x06128006, 0x061289a7, 0x06136006, 0x061369a7, 0x06144006, 0x061449a7, 0x06152006, 0x061529a7,
217 0x06160006, 0x061609a7, 0x0616e006, 0x0616e9a7, 0x0617c006, 0x0617c9a7, 0x0618a006, 0x0618a9a7, 0x06198006,
218 0x061989a7, 0x061a6006, 0x061a69a7, 0x061b4006, 0x061b49a7, 0x061c2006, 0x061c29a7, 0x061d0006, 0x061d09a7,
219 0x061de006, 0x061de9a7, 0x061ec006, 0x061ec9a7, 0x061fa006, 0x061fa9a7, 0x06208006, 0x062089a7, 0x06216006,
220 0x062169a7, 0x06224006, 0x062249a7, 0x06232006, 0x062329a7, 0x06240006, 0x062409a7, 0x0624e006, 0x0624e9a7,
221 0x0625c006, 0x0625c9a7, 0x0626a006, 0x0626a9a7, 0x06278006, 0x062789a7, 0x06286006, 0x062869a7, 0x06294006,
222 0x062949a7, 0x062a2006, 0x062a29a7, 0x062b0006, 0x062b09a7, 0x062be006, 0x062be9a7, 0x062cc006, 0x062cc9a7,
223 0x062da006, 0x062da9a7, 0x062e8006, 0x062e89a7, 0x062f6006, 0x062f69a7, 0x06304006, 0x063049a7, 0x06312006,
224 0x063129a7, 0x06320006, 0x063209a7, 0x0632e006, 0x0632e9a7, 0x0633c006, 0x0633c9a7, 0x0634a006, 0x0634a9a7,
225 0x06358006, 0x063589a7, 0x06366006, 0x063669a7, 0x06374006, 0x063749a7, 0x06382006, 0x063829a7, 0x06390006,
226 0x063909a7, 0x0639e006, 0x0639e9a7, 0x063ac006, 0x063ac9a7, 0x063ba006, 0x063ba9a7, 0x063c8006, 0x063c89a7,
227 0x063d6006, 0x063d69a7, 0x063e4006, 0x063e49a7, 0x063f2006, 0x063f29a7, 0x06400006, 0x064009a7, 0x0640e006,
228 0x0640e9a7, 0x0641c006, 0x0641c9a7, 0x0642a006, 0x0642a9a7, 0x06438006, 0x064389a7, 0x06446006, 0x064469a7,
229 0x06454006, 0x064549a7, 0x06462006, 0x064629a7, 0x06470006, 0x064709a7, 0x0647e006, 0x0647e9a7, 0x0648c006,
230 0x0648c9a7, 0x0649a006, 0x0649a9a7, 0x064a8006, 0x064a89a7, 0x064b6006, 0x064b69a7, 0x064c4006, 0x064c49a7,
231 0x064d2006, 0x064d29a7, 0x064e0006, 0x064e09a7, 0x064ee006, 0x064ee9a7, 0x064fc006, 0x064fc9a7, 0x0650a006,
232 0x0650a9a7, 0x06518006, 0x065189a7, 0x06526006, 0x065269a7, 0x06534006, 0x065349a7, 0x06542006, 0x065429a7,
233 0x06550006, 0x065509a7, 0x0655e006, 0x0655e9a7, 0x0656c006, 0x0656c9a7, 0x0657a006, 0x0657a9a7, 0x06588006,
234 0x065889a7, 0x06596006, 0x065969a7, 0x065a4006, 0x065a49a7, 0x065b2006, 0x065b29a7, 0x065c0006, 0x065c09a7,
235 0x065ce006, 0x065ce9a7, 0x065dc006, 0x065dc9a7, 0x065ea006, 0x065ea9a7, 0x065f8006, 0x065f89a7, 0x06606006,
236 0x066069a7, 0x06614006, 0x066149a7, 0x06622006, 0x066229a7, 0x06630006, 0x066309a7, 0x0663e006, 0x0663e9a7,
237 0x0664c006, 0x0664c9a7, 0x0665a006, 0x0665a9a7, 0x06668006, 0x066689a7, 0x06676006, 0x066769a7, 0x06684006,
238 0x066849a7, 0x06692006, 0x066929a7, 0x066a0006, 0x066a09a7, 0x066ae006, 0x066ae9a7, 0x066bc006, 0x066bc9a7,
239 0x066ca006, 0x066ca9a7, 0x066d8006, 0x066d89a7, 0x066e6006, 0x066e69a7, 0x066f4006, 0x066f49a7, 0x06702006,
240 0x067029a7, 0x06710006, 0x067109a7, 0x0671e006, 0x0671e9a7, 0x0672c006, 0x0672c9a7, 0x0673a006, 0x0673a9a7,
241 0x06748006, 0x067489a7, 0x06756006, 0x067569a7, 0x06764006, 0x067649a7, 0x06772006, 0x067729a7, 0x06780006,
242 0x067809a7, 0x0678e006, 0x0678e9a7, 0x0679c006, 0x0679c9a7, 0x067aa006, 0x067aa9a7, 0x067b8006, 0x067b89a7,
243 0x067c6006, 0x067c69a7, 0x067d4006, 0x067d49a7, 0x067e2006, 0x067e29a7, 0x067f0006, 0x067f09a7, 0x067fe006,
244 0x067fe9a7, 0x0680c006, 0x0680c9a7, 0x0681a006, 0x0681a9a7, 0x06828006, 0x068289a7, 0x06836006, 0x068369a7,
245 0x06844006, 0x068449a7, 0x06852006, 0x068529a7, 0x06860006, 0x068609a7, 0x0686e006, 0x0686e9a7, 0x0687c006,
246 0x0687c9a7, 0x0688a006, 0x0688a9a7, 0x06898006, 0x068989a7, 0x068a6006, 0x068a69a7, 0x068b4006, 0x068b49a7,
247 0x068c2006, 0x068c29a7, 0x068d0006, 0x068d09a7, 0x068de006, 0x068de9a7, 0x068ec006, 0x068ec9a7, 0x068fa006,
248 0x068fa9a7, 0x06908006, 0x069089a7, 0x06916006, 0x069169a7, 0x06924006, 0x069249a7, 0x06932006, 0x069329a7,
249 0x06940006, 0x069409a7, 0x0694e006, 0x0694e9a7, 0x0695c006, 0x0695c9a7, 0x0696a006, 0x0696a9a7, 0x06978006,
250 0x069789a7, 0x06986006, 0x069869a7, 0x06994006, 0x069949a7, 0x069a2006, 0x069a29a7, 0x069b0006, 0x069b09a7,
251 0x069be006, 0x069be9a7, 0x069cc006, 0x069cc9a7, 0x069da006, 0x069da9a7, 0x069e8006, 0x069e89a7, 0x069f6006,
252 0x069f69a7, 0x06a04006, 0x06a049a7, 0x06a12006, 0x06a129a7, 0x06a20006, 0x06a209a7, 0x06a2e006, 0x06a2e9a7,
253 0x06a3c006, 0x06a3c9a7, 0x06a4a006, 0x06a4a9a7, 0x06a58006, 0x06a589a7, 0x06a66006, 0x06a669a7, 0x06a74006,
254 0x06a749a7, 0x06a82006, 0x06a829a7, 0x06a90006, 0x06a909a7, 0x06a9e006, 0x06a9e9a7, 0x06aac006, 0x06aac9a7,
255 0x06aba006, 0x06aba9a7, 0x06ac8006, 0x06ac89a7, 0x06ad6006, 0x06ad69a7, 0x06ae4006, 0x06ae49a7, 0x06af2006,
256 0x06af29a7, 0x06b00006, 0x06b009a7, 0x06b0e006, 0x06b0e9a7, 0x06b1c006, 0x06b1c9a7, 0x06b2a006, 0x06b2a9a7,
257 0x06b38006, 0x06b389a7, 0x06b46006, 0x06b469a7, 0x06b54006, 0x06b549a7, 0x06b62006, 0x06b629a7, 0x06b70006,
258 0x06b709a7, 0x06b7e006, 0x06b7e9a7, 0x06b8c006, 0x06b8c9a7, 0x06b9a006, 0x06b9a9a7, 0x06ba8006, 0x06ba89a7,
259 0x06bb6006, 0x06bb69a7, 0x06bc4006, 0x06bc49a7, 0x06bd816c, 0x06be5b0b, 0x07d8f002, 0x07f000f2, 0x07f100f2,
260 0x07f7f801, 0x07fcf012, 0x07ff80b1, 0x080fe802, 0x08170002, 0x081bb042, 0x08500822, 0x08502812, 0x08506032,
261 0x0851c022, 0x0851f802, 0x08572812, 0x08692032, 0x08755812, 0x087a30a2, 0x087c1032, 0x0880000a, 0x08800802,
262 0x0880100a, 0x0881c0e2, 0x08838002, 0x08839812, 0x0883f822, 0x0884100a, 0x0885802a, 0x08859832, 0x0885b81a,
263 0x0885c812, 0x0885e808, 0x08861002, 0x08866808, 0x08880022, 0x08893842, 0x0889600a, 0x08896872, 0x088a281a,
264 0x088b9802, 0x088c0012, 0x088c100a, 0x088d982a, 0x088db082, 0x088df81a, 0x088e1018, 0x088e4832, 0x088e700a,
265 0x088e7802, 0x0891602a, 0x08917822, 0x0891901a, 0x0891a002, 0x0891a80a, 0x0891b012, 0x0891f002, 0x0896f802,
266 0x0897002a, 0x08971872, 0x08980012, 0x0898101a, 0x0899d812, 0x0899f002, 0x0899f80a, 0x089a0002, 0x089a083a,
267 0x089a381a, 0x089a582a, 0x089ab802, 0x089b101a, 0x089b3062, 0x089b8042, 0x08a1a82a, 0x08a1c072, 0x08a2001a,
268 0x08a21022, 0x08a2280a, 0x08a23002, 0x08a2f002, 0x08a58002, 0x08a5881a, 0x08a59852, 0x08a5c80a, 0x08a5d002,
269 0x08a5d81a, 0x08a5e802, 0x08a5f00a, 0x08a5f812, 0x08a6080a, 0x08a61012, 0x08ad7802, 0x08ad801a, 0x08ad9032,
270 0x08adc03a, 0x08ade012, 0x08adf00a, 0x08adf812, 0x08aee012, 0x08b1802a, 0x08b19872, 0x08b1d81a, 0x08b1e802,
271 0x08b1f00a, 0x08b1f812, 0x08b55802, 0x08b5600a, 0x08b56802, 0x08b5701a, 0x08b58052, 0x08b5b00a, 0x08b5b802,
272 0x08b8e822, 0x08b91032, 0x08b9300a, 0x08b93842, 0x08c1602a, 0x08c17882, 0x08c1c00a, 0x08c1c812, 0x08c98002,
273 0x08c9884a, 0x08c9b81a, 0x08c9d812, 0x08c9e80a, 0x08c9f002, 0x08c9f808, 0x08ca000a, 0x08ca0808, 0x08ca100a,
274 0x08ca1802, 0x08ce882a, 0x08cea032, 0x08ced012, 0x08cee03a, 0x08cf0002, 0x08cf200a, 0x08d00892, 0x08d19852,
275 0x08d1c80a, 0x08d1d008, 0x08d1d832, 0x08d23802, 0x08d28852, 0x08d2b81a, 0x08d2c822, 0x08d42058, 0x08d450c2,
276 0x08d4b80a, 0x08d4c012, 0x08e1780a, 0x08e18062, 0x08e1c052, 0x08e1f00a, 0x08e1f802, 0x08e49152, 0x08e5480a,
277 0x08e55062, 0x08e5880a, 0x08e59012, 0x08e5a00a, 0x08e5a812, 0x08e98852, 0x08e9d002, 0x08e9e012, 0x08e9f862,
278 0x08ea3008, 0x08ea3802, 0x08ec504a, 0x08ec8012, 0x08ec981a, 0x08eca802, 0x08ecb00a, 0x08ecb802, 0x08f79812,
279 0x08f7a81a, 0x09a18081, 0x0b578042, 0x0b598062, 0x0b7a7802, 0x0b7a8b6a, 0x0b7c7832, 0x0b7f2002, 0x0b7f801a,
280 0x0de4e812, 0x0de50031, 0x0e7802d2, 0x0e798162, 0x0e8b2802, 0x0e8b300a, 0x0e8b3822, 0x0e8b680a, 0x0e8b7042,
281 0x0e8b9871, 0x0e8bd872, 0x0e8c2862, 0x0e8d5032, 0x0e921022, 0x0ed00362, 0x0ed1db12, 0x0ed3a802, 0x0ed42002,
282 0x0ed4d842, 0x0ed508e2, 0x0f000062, 0x0f004102, 0x0f00d862, 0x0f011812, 0x0f013042, 0x0f098062, 0x0f157002,
283 0x0f176032, 0x0f468062, 0x0f4a2062, 0x0f8007f3, 0x0f8407f3, 0x0f886823, 0x0f897803, 0x0f8b6053, 0x0f8bf013,
284 0x0f8c7003, 0x0f8c8893, 0x0f8d6b83, 0x0f8f3199, 0x0f9008e3, 0x0f90d003, 0x0f917803, 0x0f919083, 0x0f91e033,
285 0x0f924ff3, 0x0f964ff3, 0x0f9a4ff3, 0x0f9e4b13, 0x0f9fd842, 0x0fa007f3, 0x0fa407f3, 0x0fa803d3, 0x0faa37f3,
286 0x0fae37f3, 0x0fb23093, 0x0fb407f3, 0x0fbba0b3, 0x0fbeaaa3, 0x0fc06033, 0x0fc24073, 0x0fc2d053, 0x0fc44073,
287 0x0fc57513, 0x0fc862e3, 0x0fc9e093, 0x0fca3ff3, 0x0fce3ff3, 0x0fd23ff3, 0x0fd63b83, 0x0fe007f3, 0x0fe407f3,
288 0x0fe807f3, 0x0fec07f3, 0x0ff007f3, 0x0ff407f3, 0x0ff807f3, 0x0ffc07d3, 0x700001f1, 0x700105f2, 0x700407f1,
289 0x700807f2, 0x700c06f2, 0x700f87f1, 0x701387f1, 0x701787f1, 0x701b87f1, 0x701f87f1, 0x702387f1, 0x702787f1,
290 0x702b87f1, 0x702f87f1, 0x703387f1, 0x703787f1, 0x703b87f1, 0x703f87f1, 0x704387f1, 0x704787f1, 0x704b87f1,
291 0x704f87f1, 0x705387f1, 0x705787f1, 0x705b87f1, 0x705f87f1, 0x706387f1, 0x706787f1, 0x706b87f1, 0x706f87f1,
292 0x707387f1, 0x707787f1, 0x707b87f1, 0x707f80f1};
293
294/// Returns the extended grapheme cluster bondary property of a code point.
295[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr __property __get_property(const char32_t __code_point) noexcept {
296 // TODO FMT use std::ranges::upper_bound.
297
298 // The algorithm searches for the upper bound of the range and, when found,
299 // steps back one entry. This algorithm is used since the code point can be
300 // anywhere in the range. After a lower bound is found the next step is to
301 // compare whether the code unit is indeed in the range.
302 //
303 // Since the entry contains a code unit, size, and property the code point
304 // being sought needs to be adjusted. Just shifting the code point to the
305 // proper position doesn't work; suppose an entry has property 0, size 1,
306 // and lower bound 3. This results in the entry 0x1810.
307 // When searching for code point 3 it will search for 0x1800, find 0x1810
308 // and moves to the previous entry. Thus the lower bound value will never
309 // be found.
310 // The simple solution is to set the bits belonging to the property and
311 // size. Then the upper bound for code point 3 will return the entry after
312 // 0x1810. After moving to the previous entry the algorithm arrives at the
313 // correct entry.
314 ptrdiff_t __i = std::upper_bound(__entries, std::end(__entries), (__code_point << 11) | 0x7ffu) - __entries;
315 if (__i == 0)
316 return __property::__none;
317
318 --__i;
319 uint32_t __upper_bound = (__entries[__i] >> 11) + ((__entries[__i] >> 4) & 0x7f);
320 if (__code_point <= __upper_bound)
321 return static_cast<__property>(__entries[__i] & 0xf);
322
323 return __property::__none;
324}
325
326} // namespace __extended_grapheme_custer_property_boundary
327
328#endif //_LIBCPP_STD_VER > 17
329
330_LIBCPP_END_NAMESPACE_STD
331
332#endif // _LIBCPP___FORMAT_EXTENDED_GRAPHEME_CLUSTER_TABLE_H
lib/libcxx/include/__format/format_arg.h+152-172
......@@ -10,39 +10,41 @@
1010#ifndef _LIBCPP___FORMAT_FORMAT_ARG_H
1111#define _LIBCPP___FORMAT_FORMAT_ARG_H
1212
13#include <__assert>
1314#include <__concepts/arithmetic.h>
1415#include <__config>
1516#include <__format/format_error.h>
1617#include <__format/format_fwd.h>
1718#include <__format/format_parse_context.h>
18#include <__functional_base>
19#include <__functional/invoke.h>
1920#include <__memory/addressof.h>
21#include <__utility/forward.h>
22#include <__utility/unreachable.h>
2023#include <__variant/monostate.h>
2124#include <string>
2225#include <string_view>
2326
2427#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
25#pragma GCC system_header
28# pragma GCC system_header
2629#endif
2730
28_LIBCPP_PUSH_MACROS
29#include <__undef_macros>
30
3131_LIBCPP_BEGIN_NAMESPACE_STD
3232
3333#if _LIBCPP_STD_VER > 17
3434
35// TODO FMT Remove this once we require compilers with proper C++20 support.
36// If the compiler has no concepts support, the format header will be disabled.
37// Without concepts support enable_if needs to be used and that too much effort
38// to support compilers with partial C++20 support.
39#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
40
4135namespace __format {
4236/// The type stored in @ref basic_format_arg.
4337///
4438/// @note The 128-bit types are unconditionally in the list to avoid the values
4539/// of the enums to depend on the availability of 128-bit integers.
40///
41/// @note The value is stored as a 5-bit value in the __packed_arg_t_bits. This
42/// limits the maximum number of elements to 32.
43/// When modifying update the test
44/// test/libcxx/utilities/format/format.arguments/format.arg/arg_t.compile.pass.cpp
45/// It could be packed in 4-bits but that means a new type directly becomes an
46/// ABI break. The packed type is 64-bit so this reduces the maximum number of
47/// packed elements from 16 to 12.
4648enum class _LIBCPP_ENUM_VIS __arg_t : uint8_t {
4749 __none,
4850 __boolean,
......@@ -61,58 +63,158 @@ enum class _LIBCPP_ENUM_VIS __arg_t : uint8_t {
6163 __ptr,
6264 __handle
6365};
66
67inline constexpr unsigned __packed_arg_t_bits = 5;
68inline constexpr uint8_t __packed_arg_t_mask = 0x1f;
69
70inline constexpr unsigned __packed_types_storage_bits = 64;
71inline constexpr unsigned __packed_types_max = __packed_types_storage_bits / __packed_arg_t_bits;
72
73_LIBCPP_HIDE_FROM_ABI
74constexpr bool __use_packed_format_arg_store(size_t __size) { return __size <= __packed_types_max; }
75
76_LIBCPP_HIDE_FROM_ABI
77constexpr __arg_t __get_packed_type(uint64_t __types, size_t __id) {
78 _LIBCPP_ASSERT(__id <= __packed_types_max, "");
79
80 if (__id > 0)
81 __types >>= __id * __packed_arg_t_bits;
82
83 return static_cast<__format::__arg_t>(__types & __packed_arg_t_mask);
84}
85
6486} // namespace __format
6587
6688template <class _Visitor, class _Context>
67_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT decltype(auto)
68visit_format_arg(_Visitor&& __vis, basic_format_arg<_Context> __arg) {
89_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT decltype(auto) visit_format_arg(_Visitor&& __vis,
90 basic_format_arg<_Context> __arg) {
6991 switch (__arg.__type_) {
7092 case __format::__arg_t::__none:
71 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), monostate{});
93 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__value_.__monostate_);
7294 case __format::__arg_t::__boolean:
73 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__boolean);
95 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__value_.__boolean_);
7496 case __format::__arg_t::__char_type:
75 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__char_type);
97 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__value_.__char_type_);
7698 case __format::__arg_t::__int:
77 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__int);
99 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__value_.__int_);
78100 case __format::__arg_t::__long_long:
79 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__long_long);
101 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__value_.__long_long_);
80102 case __format::__arg_t::__i128:
81#ifndef _LIBCPP_HAS_NO_INT128
82 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__i128);
83#else
84 _LIBCPP_UNREACHABLE();
85#endif
103# ifndef _LIBCPP_HAS_NO_INT128
104 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__value_.__i128_);
105# else
106 __libcpp_unreachable();
107# endif
86108 case __format::__arg_t::__unsigned:
87 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__unsigned);
109 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__value_.__unsigned_);
88110 case __format::__arg_t::__unsigned_long_long:
89 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis),
90 __arg.__unsigned_long_long);
111 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__value_.__unsigned_long_long_);
91112 case __format::__arg_t::__u128:
92#ifndef _LIBCPP_HAS_NO_INT128
93 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__u128);
94#else
95 _LIBCPP_UNREACHABLE();
96#endif
113# ifndef _LIBCPP_HAS_NO_INT128
114 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__value_.__u128_);
115# else
116 __libcpp_unreachable();
117# endif
97118 case __format::__arg_t::__float:
98 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__float);
119 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__value_.__float_);
99120 case __format::__arg_t::__double:
100 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__double);
121 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__value_.__double_);
101122 case __format::__arg_t::__long_double:
102 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__long_double);
123 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__value_.__long_double_);
103124 case __format::__arg_t::__const_char_type_ptr:
104 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis),
105 __arg.__const_char_type_ptr);
125 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__value_.__const_char_type_ptr_);
106126 case __format::__arg_t::__string_view:
107 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__string_view);
127 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__value_.__string_view_);
108128 case __format::__arg_t::__ptr:
109 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__ptr);
129 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__value_.__ptr_);
110130 case __format::__arg_t::__handle:
111 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__handle);
131 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis),
132 typename basic_format_arg<_Context>::handle{__arg.__value_.__handle_});
112133 }
113 _LIBCPP_UNREACHABLE();
134
135 __libcpp_unreachable();
114136}
115137
138/// Contains the values used in basic_format_arg.
139///
140/// This is a separate type so it's possible to store the values and types in
141/// separate arrays.
142template <class _Context>
143class __basic_format_arg_value {
144 using _CharT = typename _Context::char_type;
145
146public:
147 /// Contains the implementation for basic_format_arg::handle.
148 struct __handle {
149 template <class _Tp>
150 _LIBCPP_HIDE_FROM_ABI explicit __handle(_Tp&& __v) noexcept
151 : __ptr_(_VSTD::addressof(__v)),
152 __format_([](basic_format_parse_context<_CharT>& __parse_ctx, _Context& __ctx, const void* __ptr) {
153 using _Dp = remove_cvref_t<_Tp>;
154 using _Formatter = typename _Context::template formatter_type<_Dp>;
155 constexpr bool __const_formattable =
156 requires { _Formatter().format(declval<const _Dp&>(), declval<_Context&>()); };
157 using _Qp = conditional_t<__const_formattable, const _Dp, _Dp>;
158
159 static_assert(__const_formattable || !is_const_v<remove_reference_t<_Tp>>, "Mandated by [format.arg]/18");
160
161 _Formatter __f;
162 __parse_ctx.advance_to(__f.parse(__parse_ctx));
163 __ctx.advance_to(__f.format(*const_cast<_Qp*>(static_cast<const _Dp*>(__ptr)), __ctx));
164 }) {}
165
166 const void* __ptr_;
167 void (*__format_)(basic_format_parse_context<_CharT>&, _Context&, const void*);
168 };
169
170 union {
171 monostate __monostate_;
172 bool __boolean_;
173 _CharT __char_type_;
174 int __int_;
175 unsigned __unsigned_;
176 long long __long_long_;
177 unsigned long long __unsigned_long_long_;
178# ifndef _LIBCPP_HAS_NO_INT128
179 __int128_t __i128_;
180 __uint128_t __u128_;
181# endif
182 float __float_;
183 double __double_;
184 long double __long_double_;
185 const _CharT* __const_char_type_ptr_;
186 basic_string_view<_CharT> __string_view_;
187 const void* __ptr_;
188 __handle __handle_;
189 };
190
191 // These constructors contain the exact storage type used. If adjustments are
192 // required, these will be done in __create_format_arg.
193
194 _LIBCPP_HIDE_FROM_ABI __basic_format_arg_value() noexcept : __monostate_() {}
195 _LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(bool __value) noexcept : __boolean_(__value) {}
196 _LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(_CharT __value) noexcept : __char_type_(__value) {}
197 _LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(int __value) noexcept : __int_(__value) {}
198 _LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(unsigned __value) noexcept : __unsigned_(__value) {}
199 _LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(long long __value) noexcept : __long_long_(__value) {}
200 _LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(unsigned long long __value) noexcept
201 : __unsigned_long_long_(__value) {}
202# ifndef _LIBCPP_HAS_NO_INT128
203 _LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(__int128_t __value) noexcept : __i128_(__value) {}
204 _LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(__uint128_t __value) noexcept : __u128_(__value) {}
205# endif
206 _LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(float __value) noexcept : __float_(__value) {}
207 _LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(double __value) noexcept : __double_(__value) {}
208 _LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(long double __value) noexcept : __long_double_(__value) {}
209 _LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(const _CharT* __value) noexcept : __const_char_type_ptr_(__value) {}
210 _LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(basic_string_view<_CharT> __value) noexcept
211 : __string_view_(__value) {}
212 _LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(const void* __value) noexcept : __ptr_(__value) {}
213 _LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(__handle __value) noexcept
214 // TODO FMT Investigate why it doesn't work without the forward.
215 : __handle_(std::forward<__handle>(__value)) {}
216};
217
116218template <class _Context>
117219class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT basic_format_arg {
118220public:
......@@ -139,154 +241,32 @@ private:
139241 // .format(declval<const T&>(), declval<Context&>())
140242 // shall be well-formed when treated as an unevaluated operand.
141243
142 template <class _Ctx, class... _Args>
143 _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT friend __format_arg_store<_Ctx, _Args...>
144 make_format_args(const _Args&...);
145
146 template <class _Visitor, class _Ctx>
147 _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT friend decltype(auto)
148 visit_format_arg(_Visitor&& __vis, basic_format_arg<_Ctx> __arg);
149
150 union {
151 bool __boolean;
152 char_type __char_type;
153 int __int;
154 unsigned __unsigned;
155 long long __long_long;
156 unsigned long long __unsigned_long_long;
157#ifndef _LIBCPP_HAS_NO_INT128
158 __int128_t __i128;
159 __uint128_t __u128;
160#endif
161 float __float;
162 double __double;
163 long double __long_double;
164 const char_type* __const_char_type_ptr;
165 basic_string_view<char_type> __string_view;
166 const void* __ptr;
167 handle __handle;
168 };
244public:
245 __basic_format_arg_value<_Context> __value_;
169246 __format::__arg_t __type_;
170247
171 _LIBCPP_HIDE_FROM_ABI explicit basic_format_arg(bool __v) noexcept
172 : __boolean(__v), __type_(__format::__arg_t::__boolean) {}
173
174 template <class _Tp>
175 _LIBCPP_HIDE_FROM_ABI explicit basic_format_arg(_Tp __v) noexcept
176 requires(same_as<_Tp, char_type> ||
177 (same_as<_Tp, char> && same_as<char_type, wchar_t>))
178 : __char_type(__v), __type_(__format::__arg_t::__char_type) {}
179
180 template <__libcpp_signed_integer _Tp>
181 _LIBCPP_HIDE_FROM_ABI explicit basic_format_arg(_Tp __v) noexcept {
182 if constexpr (sizeof(_Tp) <= sizeof(int)) {
183 __int = static_cast<int>(__v);
184 __type_ = __format::__arg_t::__int;
185 } else if constexpr (sizeof(_Tp) <= sizeof(long long)) {
186 __long_long = static_cast<long long>(__v);
187 __type_ = __format::__arg_t::__long_long;
188 }
189#ifndef _LIBCPP_HAS_NO_INT128
190 else if constexpr (sizeof(_Tp) == sizeof(__int128_t)) {
191 __i128 = __v;
192 __type_ = __format::__arg_t::__i128;
193 }
194#endif
195 else
196 static_assert(sizeof(_Tp) == 0, "An unsupported signed integer was used");
197 }
198
199 template <__libcpp_unsigned_integer _Tp>
200 _LIBCPP_HIDE_FROM_ABI explicit basic_format_arg(_Tp __v) noexcept {
201 if constexpr (sizeof(_Tp) <= sizeof(unsigned)) {
202 __unsigned = static_cast<unsigned>(__v);
203 __type_ = __format::__arg_t::__unsigned;
204 } else if constexpr (sizeof(_Tp) <= sizeof(unsigned long long)) {
205 __unsigned_long_long = static_cast<unsigned long long>(__v);
206 __type_ = __format::__arg_t::__unsigned_long_long;
207 }
208#ifndef _LIBCPP_HAS_NO_INT128
209 else if constexpr (sizeof(_Tp) == sizeof(__int128_t)) {
210 __u128 = __v;
211 __type_ = __format::__arg_t::__u128;
212 }
213#endif
214 else
215 static_assert(sizeof(_Tp) == 0,
216 "An unsupported unsigned integer was used");
217 }
218
219 _LIBCPP_HIDE_FROM_ABI explicit basic_format_arg(float __v) noexcept
220 : __float(__v), __type_(__format::__arg_t::__float) {}
221
222 _LIBCPP_HIDE_FROM_ABI explicit basic_format_arg(double __v) noexcept
223 : __double(__v), __type_(__format::__arg_t::__double) {}
224
225 _LIBCPP_HIDE_FROM_ABI explicit basic_format_arg(long double __v) noexcept
226 : __long_double(__v), __type_(__format::__arg_t::__long_double) {}
227
228 // Note not a 'noexcept' function.
229 _LIBCPP_HIDE_FROM_ABI explicit basic_format_arg(const char_type* __s)
230 : __const_char_type_ptr(__s),
231 __type_(__format::__arg_t::__const_char_type_ptr) {
232 _LIBCPP_ASSERT(__s, "Used a nullptr argument to initialize a C-string");
233 }
234
235 template <class _Traits>
236 _LIBCPP_HIDE_FROM_ABI explicit basic_format_arg(
237 basic_string_view<char_type, _Traits> __s) noexcept
238 : __string_view{__s.data(), __s.size()},
239 __type_(__format::__arg_t::__string_view) {}
240
241 template <class _Traits, class _Allocator>
242 _LIBCPP_HIDE_FROM_ABI explicit basic_format_arg(
243 const basic_string<char_type, _Traits, _Allocator>& __s) noexcept
244 : __string_view{__s.data(), __s.size()},
245 __type_(__format::__arg_t::__string_view) {}
246
247 _LIBCPP_HIDE_FROM_ABI
248 explicit basic_format_arg(nullptr_t) noexcept
249 : __ptr(nullptr), __type_(__format::__arg_t::__ptr) {}
250
251 template <class _Tp>
252 requires is_void_v<_Tp> _LIBCPP_HIDE_FROM_ABI explicit basic_format_arg(_Tp* __p) noexcept
253 : __ptr(__p), __type_(__format::__arg_t::__ptr) {}
254
255 template <class _Tp>
256 _LIBCPP_HIDE_FROM_ABI explicit basic_format_arg(const _Tp& __v) noexcept
257 : __handle(__v), __type_(__format::__arg_t::__handle) {}
248 _LIBCPP_HIDE_FROM_ABI explicit basic_format_arg(__format::__arg_t __type,
249 __basic_format_arg_value<_Context> __value) noexcept
250 : __value_(__value), __type_(__type) {}
258251};
259252
260253template <class _Context>
261254class _LIBCPP_TEMPLATE_VIS basic_format_arg<_Context>::handle {
262 friend class basic_format_arg<_Context>;
263
264255public:
265256 _LIBCPP_HIDE_FROM_ABI
266257 void format(basic_format_parse_context<char_type>& __parse_ctx, _Context& __ctx) const {
267 __format_(__parse_ctx, __ctx, __ptr_);
258 __handle_.__format_(__parse_ctx, __ctx, __handle_.__ptr_);
268259 }
269260
261 _LIBCPP_HIDE_FROM_ABI explicit handle(typename __basic_format_arg_value<_Context>::__handle& __handle) noexcept
262 : __handle_(__handle) {}
263
270264private:
271 const void* __ptr_;
272 void (*__format_)(basic_format_parse_context<char_type>&, _Context&, const void*);
273
274 template <class _Tp>
275 _LIBCPP_HIDE_FROM_ABI explicit handle(const _Tp& __v) noexcept
276 : __ptr_(_VSTD::addressof(__v)),
277 __format_([](basic_format_parse_context<char_type>& __parse_ctx, _Context& __ctx, const void* __ptr) {
278 typename _Context::template formatter_type<_Tp> __f;
279 __parse_ctx.advance_to(__f.parse(__parse_ctx));
280 __ctx.advance_to(__f.format(*static_cast<const _Tp*>(__ptr), __ctx));
281 }) {}
265 typename __basic_format_arg_value<_Context>::__handle& __handle_;
282266};
283267
284#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
285
286268#endif //_LIBCPP_STD_VER > 17
287269
288270_LIBCPP_END_NAMESPACE_STD
289271
290_LIBCPP_POP_MACROS
291
292272#endif // _LIBCPP___FORMAT_FORMAT_ARG_H
lib/libcxx/include/__format/format_arg_store.h created+253
......@@ -0,0 +1,253 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___FORMAT_FORMAT_ARG_STORE_H
11#define _LIBCPP___FORMAT_FORMAT_ARG_STORE_H
12
13#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
14# pragma GCC system_header
15#endif
16
17#include <__concepts/arithmetic.h>
18#include <__concepts/same_as.h>
19#include <__config>
20#include <__format/concepts.h>
21#include <__format/format_arg.h>
22#include <cstring>
23#include <string>
24#include <string_view>
25#include <type_traits>
26
27_LIBCPP_BEGIN_NAMESPACE_STD
28
29#if _LIBCPP_STD_VER > 17
30
31namespace __format {
32
33/// \returns The @c __arg_t based on the type of the formatting argument.
34///
35/// \pre \c __formattable<_Tp, typename _Context::char_type>
36template <class _Context, class _Tp>
37consteval __arg_t __determine_arg_t();
38
39// Boolean
40template <class, same_as<bool> _Tp>
41consteval __arg_t __determine_arg_t() {
42 return __arg_t::__boolean;
43}
44
45// Char
46template <class _Context, same_as<typename _Context::char_type> _Tp>
47consteval __arg_t __determine_arg_t() {
48 return __arg_t::__char_type;
49}
50# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
51template <class _Context, class _CharT>
52 requires(same_as<typename _Context::char_type, wchar_t> && same_as<_CharT, char>)
53consteval __arg_t __determine_arg_t() {
54 return __arg_t::__char_type;
55}
56# endif
57
58// Signed integers
59template <class, __libcpp_signed_integer _Tp>
60consteval __arg_t __determine_arg_t() {
61 if constexpr (sizeof(_Tp) <= sizeof(int))
62 return __arg_t::__int;
63 else if constexpr (sizeof(_Tp) <= sizeof(long long))
64 return __arg_t::__long_long;
65# ifndef _LIBCPP_HAS_NO_INT128
66 else if constexpr (sizeof(_Tp) == sizeof(__int128_t))
67 return __arg_t::__i128;
68# endif
69 else
70 static_assert(sizeof(_Tp) == 0, "an unsupported signed integer was used");
71}
72
73// Unsigned integers
74template <class, __libcpp_unsigned_integer _Tp>
75consteval __arg_t __determine_arg_t() {
76 if constexpr (sizeof(_Tp) <= sizeof(unsigned))
77 return __arg_t::__unsigned;
78 else if constexpr (sizeof(_Tp) <= sizeof(unsigned long long))
79 return __arg_t::__unsigned_long_long;
80# ifndef _LIBCPP_HAS_NO_INT128
81 else if constexpr (sizeof(_Tp) == sizeof(__uint128_t))
82 return __arg_t::__u128;
83# endif
84 else
85 static_assert(sizeof(_Tp) == 0, "an unsupported unsigned integer was used");
86}
87
88// Floating-point
89template <class, same_as<float> _Tp>
90consteval __arg_t __determine_arg_t() {
91 return __arg_t::__float;
92}
93template <class, same_as<double> _Tp>
94consteval __arg_t __determine_arg_t() {
95 return __arg_t::__double;
96}
97template <class, same_as<long double> _Tp>
98consteval __arg_t __determine_arg_t() {
99 return __arg_t::__long_double;
100}
101
102// Char pointer
103template <class _Context, class _Tp>
104 requires(same_as<typename _Context::char_type*, _Tp> || same_as<const typename _Context::char_type*, _Tp>)
105consteval __arg_t __determine_arg_t() {
106 return __arg_t::__const_char_type_ptr;
107}
108
109// Char array
110template <class _Context, class _Tp>
111 requires(is_array_v<_Tp> && same_as<_Tp, typename _Context::char_type[extent_v<_Tp>]>)
112consteval __arg_t __determine_arg_t() {
113 return __arg_t::__string_view;
114}
115
116// String view
117template <class _Context, class _Tp>
118 requires(same_as<typename _Context::char_type, typename _Tp::value_type> &&
119 same_as<_Tp, basic_string_view<typename _Tp::value_type, typename _Tp::traits_type>>)
120consteval __arg_t __determine_arg_t() {
121 return __arg_t::__string_view;
122}
123
124// String
125template <class _Context, class _Tp>
126 requires(
127 same_as<typename _Context::char_type, typename _Tp::value_type> &&
128 same_as<_Tp, basic_string<typename _Tp::value_type, typename _Tp::traits_type, typename _Tp::allocator_type>>)
129consteval __arg_t __determine_arg_t() {
130 return __arg_t::__string_view;
131}
132
133// Pointers
134template <class, class _Ptr>
135 requires(same_as<_Ptr, void*> || same_as<_Ptr, const void*> || same_as<_Ptr, nullptr_t>)
136consteval __arg_t __determine_arg_t() {
137 return __arg_t::__ptr;
138}
139
140// Handle
141//
142// Note this version can't be constrained avoiding ambiguous overloads.
143// That means it can be instantiated by disabled formatters. To solve this, a
144// constrained version for not formattable formatters is added. That overload
145// is marked as deleted to fail creating a storage type for disabled formatters.
146template <class _Context, class _Tp>
147consteval __arg_t __determine_arg_t() {
148 return __arg_t::__handle;
149}
150
151template <class _Context, class _Tp>
152 requires(!__formattable<_Tp, typename _Context::char_type>)
153consteval __arg_t __determine_arg_t() = delete;
154
155template <class _Context, class _Tp>
156_LIBCPP_HIDE_FROM_ABI basic_format_arg<_Context> __create_format_arg(_Tp&& __value) noexcept {
157 constexpr __arg_t __arg = __determine_arg_t<_Context, remove_cvref_t<_Tp>>();
158 static_assert(__arg != __arg_t::__none);
159
160 // Not all types can be used to directly initialize the
161 // __basic_format_arg_value. First handle all types needing adjustment, the
162 // final else requires no adjustment.
163 if constexpr (__arg == __arg_t::__char_type)
164 // On some platforms initializing a wchar_t from a char is a narrowing
165 // conversion.
166 return basic_format_arg<_Context>{__arg, static_cast<typename _Context::char_type>(__value)};
167 else if constexpr (__arg == __arg_t::__int)
168 return basic_format_arg<_Context>{__arg, static_cast<int>(__value)};
169 else if constexpr (__arg == __arg_t::__long_long)
170 return basic_format_arg<_Context>{__arg, static_cast<long long>(__value)};
171 else if constexpr (__arg == __arg_t::__unsigned)
172 return basic_format_arg<_Context>{__arg, static_cast<unsigned>(__value)};
173 else if constexpr (__arg == __arg_t::__unsigned_long_long)
174 return basic_format_arg<_Context>{__arg, static_cast<unsigned long long>(__value)};
175 else if constexpr (__arg == __arg_t::__string_view)
176 // Using std::size on a character array will add the NUL-terminator to the size.
177 if constexpr (is_array_v<remove_cvref_t<_Tp>>)
178 return basic_format_arg<_Context>{
179 __arg, basic_string_view<typename _Context::char_type>{__value, extent_v<remove_cvref_t<_Tp>> - 1}};
180 else
181 // When the _Traits or _Allocator are different an implicit conversion will
182 // fail.
183 return basic_format_arg<_Context>{
184 __arg, basic_string_view<typename _Context::char_type>{__value.data(), __value.size()}};
185 else if constexpr (__arg == __arg_t::__ptr)
186 return basic_format_arg<_Context>{__arg, static_cast<const void*>(__value)};
187 else if constexpr (__arg == __arg_t::__handle)
188 return basic_format_arg<_Context>{
189 __arg, typename __basic_format_arg_value<_Context>::__handle{_VSTD::forward<_Tp>(__value)}};
190 else
191 return basic_format_arg<_Context>{__arg, __value};
192}
193
194template <class _Context, class... _Args>
195_LIBCPP_HIDE_FROM_ABI void __create_packed_storage(uint64_t& __types, __basic_format_arg_value<_Context>* __values,
196 _Args&&... __args) noexcept {
197 int __shift = 0;
198 (
199 [&] {
200 basic_format_arg<_Context> __arg = __create_format_arg<_Context>(__args);
201 if (__shift != 0)
202 __types |= static_cast<uint64_t>(__arg.__type_) << __shift;
203 else
204 // Assigns the initial value.
205 __types = static_cast<uint64_t>(__arg.__type_);
206 __shift += __packed_arg_t_bits;
207 *__values++ = __arg.__value_;
208 }(),
209 ...);
210}
211
212template <class _Context, class... _Args>
213_LIBCPP_HIDE_FROM_ABI void __store_basic_format_arg(basic_format_arg<_Context>* __data, _Args&&... __args) noexcept {
214 ([&] { *__data++ = __create_format_arg<_Context>(__args); }(), ...);
215}
216
217template <class _Context, size_t N>
218struct __packed_format_arg_store {
219 __basic_format_arg_value<_Context> __values_[N];
220 uint64_t __types_;
221};
222
223template <class _Context, size_t N>
224struct __unpacked_format_arg_store {
225 basic_format_arg<_Context> __args_[N];
226};
227
228} // namespace __format
229
230template <class _Context, class... _Args>
231struct _LIBCPP_TEMPLATE_VIS __format_arg_store {
232 _LIBCPP_HIDE_FROM_ABI
233 __format_arg_store(_Args&... __args) noexcept {
234 if constexpr (sizeof...(_Args) != 0) {
235 if constexpr (__format::__use_packed_format_arg_store(sizeof...(_Args)))
236 __format::__create_packed_storage(__storage.__types_, __storage.__values_, __args...);
237 else
238 __format::__store_basic_format_arg<_Context>(__storage.__args_, __args...);
239 }
240 }
241
242 using _Storage = conditional_t<__format::__use_packed_format_arg_store(sizeof...(_Args)),
243 __format::__packed_format_arg_store<_Context, sizeof...(_Args)>,
244 __format::__unpacked_format_arg_store<_Context, sizeof...(_Args)>>;
245
246 _Storage __storage;
247};
248
249#endif //_LIBCPP_STD_VER > 17
250
251_LIBCPP_END_NAMESPACE_STD
252
253#endif // _LIBCPP___FORMAT_FORMAT_ARG_STORE_H
lib/libcxx/include/__format/format_args.h+33-25
......@@ -12,60 +12,68 @@
1212
1313#include <__availability>
1414#include <__config>
15#include <__format/format_arg.h>
16#include <__format/format_arg_store.h>
1517#include <__format/format_fwd.h>
1618#include <cstddef>
19#include <cstdint>
1720
1821#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
22# pragma GCC system_header
2023#endif
2124
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
2525_LIBCPP_BEGIN_NAMESPACE_STD
2626
2727#if _LIBCPP_STD_VER > 17
2828
29// TODO FMT Remove this once we require compilers with proper C++20 support.
30// If the compiler has no concepts support, the format header will be disabled.
31// Without concepts support enable_if needs to be used and that too much effort
32// to support compilers with partial C++20 support.
33#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
34
3529template <class _Context>
3630class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT basic_format_args {
3731public:
38 // TODO FMT Implement [format.args]/5
39 // [Note 1: Implementations are encouraged to optimize the representation of
40 // basic_format_args for small number of formatting arguments by storing
41 // indices of type alternatives separately from values and packing the
42 // former. - end note]
43 // Note: Change __format_arg_store to use a built-in array.
4432 _LIBCPP_HIDE_FROM_ABI basic_format_args() noexcept = default;
4533
4634 template <class... _Args>
47 _LIBCPP_HIDE_FROM_ABI basic_format_args(
48 const __format_arg_store<_Context, _Args...>& __store) noexcept
49 : __size_(sizeof...(_Args)), __data_(__store.__args.data()) {}
35 _LIBCPP_HIDE_FROM_ABI basic_format_args(const __format_arg_store<_Context, _Args...>& __store) noexcept
36 : __size_(sizeof...(_Args)) {
37 if constexpr (sizeof...(_Args) != 0) {
38 if constexpr (__format::__use_packed_format_arg_store(sizeof...(_Args))) {
39 __values_ = __store.__storage.__values_;
40 __types_ = __store.__storage.__types_;
41 } else
42 __args_ = __store.__storage.__args_;
43 }
44 }
5045
5146 _LIBCPP_HIDE_FROM_ABI
5247 basic_format_arg<_Context> get(size_t __id) const noexcept {
53 return __id < __size_ ? __data_[__id] : basic_format_arg<_Context>{};
48 if (__id >= __size_)
49 return basic_format_arg<_Context>{};
50
51 if (__format::__use_packed_format_arg_store(__size_))
52 return basic_format_arg<_Context>{__format::__get_packed_type(__types_, __id), __values_[__id]};
53
54 return __args_[__id];
5455 }
5556
5657 _LIBCPP_HIDE_FROM_ABI size_t __size() const noexcept { return __size_; }
5758
5859private:
5960 size_t __size_{0};
60 const basic_format_arg<_Context>* __data_{nullptr};
61 // [format.args]/5
62 // [Note 1: Implementations are encouraged to optimize the representation of
63 // basic_format_args for small number of formatting arguments by storing
64 // indices of type alternatives separately from values and packing the
65 // former. - end note]
66 union {
67 struct {
68 const __basic_format_arg_value<_Context>* __values_;
69 uint64_t __types_;
70 };
71 const basic_format_arg<_Context>* __args_;
72 };
6173};
6274
63#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
64
6575#endif //_LIBCPP_STD_VER > 17
6676
6777_LIBCPP_END_NAMESPACE_STD
6878
69_LIBCPP_POP_MACROS
70
7179#endif // _LIBCPP___FORMAT_FORMAT_ARGS_H
lib/libcxx/include/__format/format_context.h+10-24
......@@ -12,11 +12,14 @@
1212
1313#include <__availability>
1414#include <__config>
15#include <__format/buffer.h>
1516#include <__format/format_args.h>
1617#include <__format/format_fwd.h>
1718#include <__iterator/back_insert_iterator.h>
1819#include <__iterator/concepts.h>
20#include <__utility/move.h>
1921#include <concepts>
22#include <cstddef>
2023
2124#ifndef _LIBCPP_HAS_NO_LOCALIZATION
2225#include <locale>
......@@ -24,22 +27,13 @@
2427#endif
2528
2629#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
27#pragma GCC system_header
30# pragma GCC system_header
2831#endif
2932
30_LIBCPP_PUSH_MACROS
31#include <__undef_macros>
32
3333_LIBCPP_BEGIN_NAMESPACE_STD
3434
3535#if _LIBCPP_STD_VER > 17
3636
37// TODO FMT Remove this once we require compilers with proper C++20 support.
38// If the compiler has no concepts support, the format header will be disabled.
39// Without concepts support enable_if needs to be used and that too much effort
40// to support compilers with partial C++20 support.
41#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
42
4337template <class _OutIt, class _CharT>
4438requires output_iterator<_OutIt, const _CharT&>
4539class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT basic_format_context;
......@@ -69,16 +63,12 @@ __format_context_create(
6963}
7064#endif
7165
72// TODO FMT Implement [format.context]/4
73// [Note 1: For a given type charT, implementations are encouraged to provide a
74// single instantiation of basic_format_context for appending to
75// basic_string<charT>, vector<charT>, or any other container with contiguous
76// storage by wrapping those in temporary objects with a uniform interface
77// (such as a span<charT>) and polymorphic reallocation. - end note]
78
79using format_context = basic_format_context<back_insert_iterator<string>, char>;
66using format_context =
67 basic_format_context<back_insert_iterator<__format::__output_buffer<char>>,
68 char>;
8069#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
81using wformat_context = basic_format_context<back_insert_iterator<wstring>, wchar_t>;
70using wformat_context = basic_format_context<
71 back_insert_iterator<__format::__output_buffer<wchar_t>>, wchar_t>;
8272#endif
8373
8474template <class _OutIt, class _CharT>
......@@ -101,7 +91,7 @@ public:
10191 basic_format_context& operator=(const basic_format_context&) = delete;
10292
10393 _LIBCPP_HIDE_FROM_ABI basic_format_arg<basic_format_context>
104 arg(size_t __id) const {
94 arg(size_t __id) const noexcept {
10595 return __args_.get(__id);
10696 }
10797#ifndef _LIBCPP_HAS_NO_LOCALIZATION
......@@ -154,12 +144,8 @@ private:
154144#endif
155145};
156146
157#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
158
159147#endif //_LIBCPP_STD_VER > 17
160148
161149_LIBCPP_END_NAMESPACE_STD
162150
163_LIBCPP_POP_MACROS
164
165151#endif // _LIBCPP___FORMAT_FORMAT_CONTEXT_H
lib/libcxx/include/__format/format_error.h+1-1
......@@ -18,7 +18,7 @@
1818#endif
1919
2020#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21#pragma GCC system_header
21# pragma GCC system_header
2222#endif
2323
2424_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__format/format_fwd.h+4-21
......@@ -13,44 +13,27 @@
1313#include <__availability>
1414#include <__config>
1515#include <__iterator/concepts.h>
16#include <__utility/forward.h>
1716
1817#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
18# pragma GCC system_header
2019#endif
2120
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
2521_LIBCPP_BEGIN_NAMESPACE_STD
2622
2723#if _LIBCPP_STD_VER > 17
2824
29// TODO FMT Remove this once we require compilers with proper C++20 support.
30// If the compiler has no concepts support, the format header will be disabled.
31// Without concepts support enable_if needs to be used and that too much effort
32// to support compilers with partial C++20 support.
33#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
34
3525template <class _Context>
3626class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT basic_format_arg;
3727
38template <class _Context, class... _Args>
39struct _LIBCPP_TEMPLATE_VIS __format_arg_store;
40
41template <class _Ctx, class... _Args>
42_LIBCPP_HIDE_FROM_ABI __format_arg_store<_Ctx, _Args...>
43make_format_args(const _Args&...);
28template <class _OutIt, class _CharT>
29 requires output_iterator<_OutIt, const _CharT&>
30class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT basic_format_context;
4431
4532template <class _Tp, class _CharT = char>
4633struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter;
4734
48#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
49
5035#endif //_LIBCPP_STD_VER > 17
5136
5237_LIBCPP_END_NAMESPACE_STD
5338
54_LIBCPP_POP_MACROS
55
5639#endif // _LIBCPP___FORMAT_FORMAT_FWD_H
lib/libcxx/include/__format/format_parse_context.h+1-9
......@@ -15,19 +15,13 @@
1515#include <string_view>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
2222
2323#if _LIBCPP_STD_VER > 17
2424
25// TODO FMT Remove this once we require compilers with proper C++20 support.
26// If the compiler has no concepts support, the format header will be disabled.
27// Without concepts support enable_if needs to be used and that too much effort
28// to support compilers with partial C++20 support.
29#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
30
3125template <class _CharT>
3226class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT basic_format_parse_context {
3327public:
......@@ -100,8 +94,6 @@ using format_parse_context = basic_format_parse_context<char>;
10094using wformat_parse_context = basic_format_parse_context<wchar_t>;
10195#endif
10296
103#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
104
10597#endif //_LIBCPP_STD_VER > 17
10698
10799_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__format/format_string.h+2-10
......@@ -10,26 +10,20 @@
1010#ifndef _LIBCPP___FORMAT_FORMAT_STRING_H
1111#define _LIBCPP___FORMAT_FORMAT_STRING_H
1212
13#include <__assert>
1314#include <__config>
14#include <__debug>
1515#include <__format/format_error.h>
1616#include <cstddef>
1717#include <cstdint>
1818
1919#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20#pragma GCC system_header
20# pragma GCC system_header
2121#endif
2222
2323_LIBCPP_BEGIN_NAMESPACE_STD
2424
2525#if _LIBCPP_STD_VER > 17
2626
27// TODO FMT Remove this once we require compilers with proper C++20 support.
28// If the compiler has no concepts support, the format header will be disabled.
29// Without concepts support enable_if needs to be used and that too much effort
30// to support compilers with partial C++20 support.
31#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
32
3327namespace __format {
3428
3529template <class _CharT>
......@@ -160,8 +154,6 @@ __parse_arg_id(const _CharT* __begin, const _CharT* __end, auto& __parse_ctx) {
160154
161155} // namespace __format
162156
163#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
164
165157#endif //_LIBCPP_STD_VER > 17
166158
167159_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__format/format_to_n_result.h-7
......@@ -21,19 +21,12 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2121
2222#if _LIBCPP_STD_VER > 17
2323
24// TODO FMT Remove this once we require compilers with proper C++20 support.
25// If the compiler has no concepts support, the format header will be disabled.
26// Without concepts support enable_if needs to be used and that too much effort
27// to support compilers with partial C++20 support.
28#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
29
3024template <class _OutIt>
3125struct _LIBCPP_TEMPLATE_VIS format_to_n_result {
3226 _OutIt out;
3327 iter_difference_t<_OutIt> size;
3428};
3529
36#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
3730#endif //_LIBCPP_STD_VER > 17
3831
3932_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__format/formatter.h+2-238
......@@ -10,34 +10,19 @@
1010#ifndef _LIBCPP___FORMAT_FORMATTER_H
1111#define _LIBCPP___FORMAT_FORMATTER_H
1212
13#include <__algorithm/copy.h>
14#include <__algorithm/fill_n.h>
1513#include <__availability>
14#include <__concepts/same_as.h>
1615#include <__config>
17#include <__format/format_error.h>
1816#include <__format/format_fwd.h>
19#include <__format/format_string.h>
20#include <__format/parser_std_format_spec.h>
21#include <concepts>
22#include <string_view>
2317
2418#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
25#pragma GCC system_header
19# pragma GCC system_header
2620#endif
2721
28_LIBCPP_PUSH_MACROS
29#include <__undef_macros>
30
3122_LIBCPP_BEGIN_NAMESPACE_STD
3223
3324#if _LIBCPP_STD_VER > 17
3425
35// TODO FMT Remove this once we require compilers with proper C++20 support.
36// If the compiler has no concepts support, the format header will be disabled.
37// Without concepts support enable_if needs to be used and that too much effort
38// to support compilers with partial C++20 support.
39#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
40
4126/// The default formatter template.
4227///
4328/// [format.formatter.spec]/5
......@@ -54,237 +39,16 @@ struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter {
5439 formatter& operator=(const formatter&) = delete;
5540};
5641
57namespace __format_spec {
58
59_LIBCPP_HIDE_FROM_ABI inline char* __insert_sign(char* __buf, bool __negative,
60 _Flags::_Sign __sign) {
61 if (__negative)
62 *__buf++ = '-';
63 else
64 switch (__sign) {
65 case _Flags::_Sign::__default:
66 case _Flags::_Sign::__minus:
67 // No sign added.
68 break;
69 case _Flags::_Sign::__plus:
70 *__buf++ = '+';
71 break;
72 case _Flags::_Sign::__space:
73 *__buf++ = ' ';
74 break;
75 }
76
77 return __buf;
78}
79
80_LIBCPP_HIDE_FROM_ABI constexpr char __hex_to_upper(char c) {
81 switch (c) {
82 case 'a':
83 return 'A';
84 case 'b':
85 return 'B';
86 case 'c':
87 return 'C';
88 case 'd':
89 return 'D';
90 case 'e':
91 return 'E';
92 case 'f':
93 return 'F';
94 }
95 return c;
96}
97
98} // namespace __format_spec
99
10042namespace __formatter {
10143
10244/** The character types that formatters are specialized for. */
10345template <class _CharT>
10446concept __char_type = same_as<_CharT, char> || same_as<_CharT, wchar_t>;
10547
106struct _LIBCPP_TEMPLATE_VIS __padding_size_result {
107 size_t __before;
108 size_t __after;
109};
110
111_LIBCPP_HIDE_FROM_ABI constexpr __padding_size_result
112__padding_size(size_t __size, size_t __width,
113 __format_spec::_Flags::_Alignment __align) {
114 _LIBCPP_ASSERT(__width > __size,
115 "Don't call this function when no padding is required");
116 _LIBCPP_ASSERT(
117 __align != __format_spec::_Flags::_Alignment::__default,
118 "Caller should adjust the default to the value required by the type");
119
120 size_t __fill = __width - __size;
121 switch (__align) {
122 case __format_spec::_Flags::_Alignment::__default:
123 _LIBCPP_UNREACHABLE();
124
125 case __format_spec::_Flags::_Alignment::__left:
126 return {0, __fill};
127
128 case __format_spec::_Flags::_Alignment::__center: {
129 // The extra padding is divided per [format.string.std]/3
130 // __before = floor(__fill, 2);
131 // __after = ceil(__fill, 2);
132 size_t __before = __fill / 2;
133 size_t __after = __fill - __before;
134 return {__before, __after};
135 }
136 case __format_spec::_Flags::_Alignment::__right:
137 return {__fill, 0};
138 }
139 _LIBCPP_UNREACHABLE();
140}
141
142/**
143 * Writes the input to the output with the required padding.
144 *
145 * Since the output column width is specified the function can be used for
146 * ASCII and Unicode input.
147 *
148 * @pre [@a __first, @a __last) is a valid range.
149 * @pre @a __size <= @a __width. Using this function when this pre-condition
150 * doesn't hold incurs an unwanted overhead.
151 *
152 * @param __out_it The output iterator to write to.
153 * @param __first Pointer to the first element to write.
154 * @param __last Pointer beyond the last element to write.
155 * @param __size The (estimated) output column width. When the elements
156 * to be written are ASCII the following condition holds
157 * @a __size == @a __last - @a __first.
158 * @param __width The number of output columns to write.
159 * @param __fill The character used for the alignment of the output.
160 * TODO FMT Will probably change to support Unicode grapheme
161 * cluster.
162 * @param __alignment The requested alignment.
163 *
164 * @returns An iterator pointing beyond the last element written.
165 *
166 * @note The type of the elements in range [@a __first, @a __last) can differ
167 * from the type of @a __fill. Integer output uses @c std::to_chars for its
168 * conversion, which means the [@a __first, @a __last) always contains elements
169 * of the type @c char.
170 */
171template <class _CharT, class _Fill>
172_LIBCPP_HIDE_FROM_ABI auto
173__write(output_iterator<const _CharT&> auto __out_it, const _CharT* __first,
174 const _CharT* __last, size_t __size, size_t __width, _Fill __fill,
175 __format_spec::_Flags::_Alignment __alignment) -> decltype(__out_it) {
176
177 _LIBCPP_ASSERT(__first <= __last, "Not a valid range");
178 _LIBCPP_ASSERT(__size < __width, "Precondition failure");
179
180 __padding_size_result __padding =
181 __padding_size(__size, __width, __alignment);
182 __out_it = _VSTD::fill_n(_VSTD::move(__out_it), __padding.__before, __fill);
183 __out_it = _VSTD::copy(__first, __last, _VSTD::move(__out_it));
184 return _VSTD::fill_n(_VSTD::move(__out_it), __padding.__after, __fill);
185}
186
187/**
188 * @overload
189 *
190 * Writes additional zero's for the precision before the exponent.
191 * This is used when the precision requested in the format string is larger
192 * than the maximum precision of the floating-point type. These precision
193 * digits are always 0.
194 *
195 * @param __exponent The location of the exponent character.
196 * @param __num_trailing_zeros The number of 0's to write before the exponent
197 * character.
198 */
199template <class _CharT, class _Fill>
200_LIBCPP_HIDE_FROM_ABI auto __write(output_iterator<const _CharT&> auto __out_it, const _CharT* __first,
201 const _CharT* __last, size_t __size, size_t __width, _Fill __fill,
202 __format_spec::_Flags::_Alignment __alignment, const _CharT* __exponent,
203 size_t __num_trailing_zeros) -> decltype(__out_it) {
204 _LIBCPP_ASSERT(__first <= __last, "Not a valid range");
205 _LIBCPP_ASSERT(__num_trailing_zeros > 0, "The overload not writing trailing zeros should have been used");
206
207 __padding_size_result __padding = __padding_size(__size + __num_trailing_zeros, __width, __alignment);
208 __out_it = _VSTD::fill_n(_VSTD::move(__out_it), __padding.__before, __fill);
209 __out_it = _VSTD::copy(__first, __exponent, _VSTD::move(__out_it));
210 __out_it = _VSTD::fill_n(_VSTD::move(__out_it), __num_trailing_zeros, _CharT('0'));
211 __out_it = _VSTD::copy(__exponent, __last, _VSTD::move(__out_it));
212 return _VSTD::fill_n(_VSTD::move(__out_it), __padding.__after, __fill);
213}
214
215/**
216 * @overload
217 *
218 * Uses a transformation operation before writing an element.
219 *
220 * TODO FMT Fill will probably change to support Unicode grapheme cluster.
221 */
222template <class _CharT, class _UnaryOperation, class _Fill>
223_LIBCPP_HIDE_FROM_ABI auto
224__write(output_iterator<const _CharT&> auto __out_it, const _CharT* __first,
225 const _CharT* __last, size_t __size, _UnaryOperation __op,
226 size_t __width, _Fill __fill,
227 __format_spec::_Flags::_Alignment __alignment) -> decltype(__out_it) {
228
229 _LIBCPP_ASSERT(__first <= __last, "Not a valid range");
230 _LIBCPP_ASSERT(__size < __width, "Precondition failure");
231
232 __padding_size_result __padding =
233 __padding_size(__size, __width, __alignment);
234 __out_it = _VSTD::fill_n(_VSTD::move(__out_it), __padding.__before, __fill);
235 __out_it = _VSTD::transform(__first, __last, _VSTD::move(__out_it), __op);
236 return _VSTD::fill_n(_VSTD::move(__out_it), __padding.__after, __fill);
237}
238
239/**
240 * Writes Unicode input to the output with the required padding.
241 *
242 * This function does almost the same as the @ref __write function, but handles
243 * the width estimation of the Unicode input.
244 *
245 * @param __str The range [@a __first, @a __last).
246 * @param __precision The width to truncate the input string to, use @c -1 for
247 * no limit.
248 */
249template <class _CharT, class _Fill>
250_LIBCPP_HIDE_FROM_ABI auto
251__write_unicode(output_iterator<const _CharT&> auto __out_it,
252 basic_string_view<_CharT> __str, ptrdiff_t __width,
253 ptrdiff_t __precision, _Fill __fill,
254 __format_spec::_Flags::_Alignment __alignment)
255 -> decltype(__out_it) {
256
257 // This value changes when there Unicode column width limits the output
258 // size.
259 auto __last = __str.end();
260 if (__width != 0 || __precision != -1) {
261 __format_spec::__string_alignment<_CharT> __format_traits =
262 __format_spec::__get_string_alignment(__str.begin(), __str.end(),
263 __width, __precision);
264
265 if (__format_traits.__align)
266 return __write(_VSTD::move(__out_it), __str.begin(),
267 __format_traits.__last, __format_traits.__size, __width,
268 __fill, __alignment);
269
270 // No alignment required update the output based on the precision.
271 // This might be the same as __str.end().
272 __last = __format_traits.__last;
273 }
274
275 // Copy the input to the output. The output size might be limited by the
276 // precision.
277 return _VSTD::copy(__str.begin(), __last, _VSTD::move(__out_it));
278}
279
28048} // namespace __formatter
28149
282#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
283
28450#endif //_LIBCPP_STD_VER > 17
28551
28652_LIBCPP_END_NAMESPACE_STD
28753
288_LIBCPP_POP_MACROS
289
29054#endif // _LIBCPP___FORMAT_FORMATTER_H
lib/libcxx/include/__format/formatter_bool.h+33-102
......@@ -10,136 +10,67 @@
1010#ifndef _LIBCPP___FORMAT_FORMATTER_BOOL_H
1111#define _LIBCPP___FORMAT_FORMATTER_BOOL_H
1212
13#include <__algorithm/copy.h>
1314#include <__availability>
1415#include <__config>
16#include <__debug>
1517#include <__format/format_error.h>
1618#include <__format/format_fwd.h>
19#include <__format/format_parse_context.h>
1720#include <__format/formatter.h>
1821#include <__format/formatter_integral.h>
1922#include <__format/parser_std_format_spec.h>
23#include <__utility/unreachable.h>
2024#include <string_view>
2125
2226#ifndef _LIBCPP_HAS_NO_LOCALIZATION
23#include <locale>
27# include <locale>
2428#endif
2529
2630#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
27#pragma GCC system_header
31# pragma GCC system_header
2832#endif
2933
3034_LIBCPP_BEGIN_NAMESPACE_STD
3135
3236#if _LIBCPP_STD_VER > 17
3337
34// TODO FMT Remove this once we require compilers with proper C++20 support.
35// If the compiler has no concepts support, the format header will be disabled.
36// Without concepts support enable_if needs to be used and that too much effort
37// to support compilers with partial C++20 support.
38#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
39
40namespace __format_spec {
41
42template <class _CharT>
43class _LIBCPP_TEMPLATE_VIS __parser_bool : public __parser_integral<_CharT> {
38template <__formatter::__char_type _CharT>
39struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<bool, _CharT> {
4440public:
45 _LIBCPP_HIDE_FROM_ABI constexpr auto parse(auto& __parse_ctx)
46 -> decltype(__parse_ctx.begin()) {
47 auto __it = __parser_integral<_CharT>::__parse(__parse_ctx);
48
49 switch (this->__type) {
50 case _Flags::_Type::__default:
51 this->__type = _Flags::_Type::__string;
52 [[fallthrough]];
53 case _Flags::_Type::__string:
54 this->__handle_bool();
55 break;
56
57 case _Flags::_Type::__char:
58 this->__handle_char();
59 break;
41 _LIBCPP_HIDE_FROM_ABI constexpr auto
42 parse(basic_format_parse_context<_CharT>& __parse_ctx) -> decltype(__parse_ctx.begin()) {
43 auto __result = __parser_.__parse(__parse_ctx, __format_spec::__fields_integral);
44 __format_spec::__process_parsed_bool(__parser_);
45 return __result;
46 }
6047
61 case _Flags::_Type::__binary_lower_case:
62 case _Flags::_Type::__binary_upper_case:
63 case _Flags::_Type::__octal:
64 case _Flags::_Type::__decimal:
65 case _Flags::_Type::__hexadecimal_lower_case:
66 case _Flags::_Type::__hexadecimal_upper_case:
67 this->__handle_integer();
68 break;
48 _LIBCPP_HIDE_FROM_ABI auto format(bool __value, auto& __ctx) const -> decltype(__ctx.out()) {
49 switch (__parser_.__type_) {
50 case __format_spec::__type::__default:
51 case __format_spec::__type::__string:
52 return __formatter::__format_bool(__value, __ctx, __parser_.__get_parsed_std_specifications(__ctx));
53
54 case __format_spec::__type::__binary_lower_case:
55 case __format_spec::__type::__binary_upper_case:
56 case __format_spec::__type::__octal:
57 case __format_spec::__type::__decimal:
58 case __format_spec::__type::__hexadecimal_lower_case:
59 case __format_spec::__type::__hexadecimal_upper_case:
60 // Promotes bool to an integral type. This reduces the number of
61 // instantiations of __format_integer reducing code size.
62 return __formatter::__format_integer(
63 static_cast<unsigned>(__value), __ctx, __parser_.__get_parsed_std_specifications(__ctx));
6964
7065 default:
71 __throw_format_error(
72 "The format-spec type has a type not supported for a bool argument");
66 _LIBCPP_ASSERT(false, "The parse function should have validated the type");
67 __libcpp_unreachable();
7368 }
74
75 return __it;
7669 }
77};
78
79template <class _CharT>
80struct _LIBCPP_TEMPLATE_VIS __bool_strings;
81
82template <>
83struct _LIBCPP_TEMPLATE_VIS __bool_strings<char> {
84 static constexpr string_view __true{"true"};
85 static constexpr string_view __false{"false"};
86};
87
88#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
89template <>
90struct _LIBCPP_TEMPLATE_VIS __bool_strings<wchar_t> {
91 static constexpr wstring_view __true{L"true"};
92 static constexpr wstring_view __false{L"false"};
93};
94#endif
9570
96template <class _CharT>
97using __formatter_bool = __formatter_integral<__parser_bool<_CharT>>;
98
99} //namespace __format_spec
100
101// [format.formatter.spec]/2.3
102// For each charT, for each cv-unqualified arithmetic type ArithmeticT other
103// than char, wchar_t, char8_t, char16_t, or char32_t, a specialization
104
105template <__formatter::__char_type _CharT>
106struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<bool, _CharT>
107 : public __format_spec::__formatter_bool<_CharT> {
108 using _Base = __format_spec::__formatter_bool<_CharT>;
109
110 _LIBCPP_HIDE_FROM_ABI auto format(bool __value, auto& __ctx)
111 -> decltype(__ctx.out()) {
112 if (this->__type != __format_spec::_Flags::_Type::__string)
113 return _Base::format(static_cast<unsigned char>(__value), __ctx);
114
115 if (this->__width_needs_substitution())
116 this->__substitute_width_arg_id(__ctx.arg(this->__width));
117
118#ifndef _LIBCPP_HAS_NO_LOCALIZATION
119 if (this->__locale_specific_form) {
120 const auto& __np = use_facet<numpunct<_CharT>>(__ctx.locale());
121 basic_string<_CharT> __str = __value ? __np.truename() : __np.falsename();
122 return __formatter::__write_unicode(
123 __ctx.out(), basic_string_view<_CharT>{__str}, this->__width, -1,
124 this->__fill, this->__alignment);
125 }
126#endif
127 basic_string_view<_CharT> __str =
128 __value ? __format_spec::__bool_strings<_CharT>::__true
129 : __format_spec::__bool_strings<_CharT>::__false;
130
131 // The output only uses ASCII so every character is one column.
132 unsigned __size = __str.size();
133 if (__size >= this->__width)
134 return _VSTD::copy(__str.begin(), __str.end(), __ctx.out());
135
136 return __formatter::__write(__ctx.out(), __str.begin(), __str.end(), __size,
137 this->__width, this->__fill, this->__alignment);
138 }
71 __format_spec::__parser<_CharT> __parser_;
13972};
14073
141#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
142
14374#endif //_LIBCPP_STD_VER > 17
14475
14576_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__format/formatter_char.h+40-60
......@@ -11,91 +11,71 @@
1111#define _LIBCPP___FORMAT_FORMATTER_CHAR_H
1212
1313#include <__availability>
14#include <__concepts/same_as.h>
1415#include <__config>
15#include <__format/format_error.h>
1616#include <__format/format_fwd.h>
17#include <__format/format_parse_context.h>
1718#include <__format/formatter.h>
1819#include <__format/formatter_integral.h>
20#include <__format/formatter_output.h>
1921#include <__format/parser_std_format_spec.h>
22#include <__type_traits/conditional.h>
23#include <__type_traits/is_signed.h>
2024
2125#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22#pragma GCC system_header
26# pragma GCC system_header
2327#endif
2428
2529_LIBCPP_BEGIN_NAMESPACE_STD
2630
2731#if _LIBCPP_STD_VER > 17
2832
29// TODO FMT Remove this once we require compilers with proper C++20 support.
30// If the compiler has no concepts support, the format header will be disabled.
31// Without concepts support enable_if needs to be used and that too much effort
32// to support compilers with partial C++20 support.
33#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
34
35namespace __format_spec {
36
37template <class _CharT>
38class _LIBCPP_TEMPLATE_VIS __parser_char : public __parser_integral<_CharT> {
33template <__formatter::__char_type _CharT>
34struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT __formatter_char {
3935public:
40 _LIBCPP_HIDE_FROM_ABI constexpr auto parse(auto& __parse_ctx)
41 -> decltype(__parse_ctx.begin()) {
42 auto __it = __parser_integral<_CharT>::__parse(__parse_ctx);
43
44 switch (this->__type) {
45 case _Flags::_Type::__default:
46 this->__type = _Flags::_Type::__char;
47 [[fallthrough]];
48 case _Flags::_Type::__char:
49 this->__handle_char();
50 break;
51
52 case _Flags::_Type::__binary_lower_case:
53 case _Flags::_Type::__binary_upper_case:
54 case _Flags::_Type::__octal:
55 case _Flags::_Type::__decimal:
56 case _Flags::_Type::__hexadecimal_lower_case:
57 case _Flags::_Type::__hexadecimal_upper_case:
58 this->__handle_integer();
59 break;
60
61 default:
62 __throw_format_error(
63 "The format-spec type has a type not supported for a char argument");
64 }
65
66 return __it;
36 _LIBCPP_HIDE_FROM_ABI constexpr auto
37 parse(basic_format_parse_context<_CharT>& __parse_ctx) -> decltype(__parse_ctx.begin()) {
38 auto __result = __parser_.__parse(__parse_ctx, __format_spec::__fields_integral);
39 __format_spec::__process_parsed_char(__parser_);
40 return __result;
6741 }
68};
6942
70template <class _CharT>
71using __formatter_char = __formatter_integral<__parser_char<_CharT>>;
43 _LIBCPP_HIDE_FROM_ABI auto format(_CharT __value, auto& __ctx) const -> decltype(__ctx.out()) {
44 if (__parser_.__type_ == __format_spec::__type::__default || __parser_.__type_ == __format_spec::__type::__char)
45 return __formatter::__format_char(__value, __ctx.out(), __parser_.__get_parsed_std_specifications(__ctx));
46
47 if constexpr (sizeof(_CharT) <= sizeof(int))
48 // Promotes _CharT to an integral type. This reduces the number of
49 // instantiations of __format_integer reducing code size.
50 return __formatter::__format_integer(
51 static_cast<conditional_t<is_signed_v<_CharT>, int, unsigned>>(__value),
52 __ctx,
53 __parser_.__get_parsed_std_specifications(__ctx));
54 else
55 return __formatter::__format_integer(__value, __ctx, __parser_.__get_parsed_std_specifications(__ctx));
56 }
7257
73} // namespace __format_spec
58 _LIBCPP_HIDE_FROM_ABI auto format(char __value, auto& __ctx) const -> decltype(__ctx.out())
59 requires(same_as<_CharT, wchar_t>)
60 {
61 return format(static_cast<wchar_t>(__value), __ctx);
62 }
7463
75// [format.formatter.spec]/2.1 The specializations
64 __format_spec::__parser<_CharT> __parser_;
65};
7666
7767template <>
78struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<char, char>
79 : public __format_spec::__formatter_char<char> {};
68struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<char, char> : public __formatter_char<char> {};
8069
81#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
70# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
8271template <>
83struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<char, wchar_t>
84 : public __format_spec::__formatter_char<wchar_t> {
85 using _Base = __format_spec::__formatter_char<wchar_t>;
72struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<char, wchar_t> : public __formatter_char<wchar_t> {};
8673
87 _LIBCPP_HIDE_FROM_ABI auto format(char __value, auto& __ctx)
88 -> decltype(__ctx.out()) {
89 return _Base::format(static_cast<wchar_t>(__value), __ctx);
90 }
74template <>
75struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<wchar_t, wchar_t> : public __formatter_char<wchar_t> {
9176};
9277
93template <>
94struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT
95 formatter<wchar_t, wchar_t>
96 : public __format_spec::__formatter_char<wchar_t> {};
97#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
98#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
78# endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
9979
10080#endif //_LIBCPP_STD_VER > 17
10181
lib/libcxx/include/__format/formatter_floating_point.h+216-212
......@@ -18,17 +18,18 @@
1818#include <__algorithm/rotate.h>
1919#include <__algorithm/transform.h>
2020#include <__concepts/arithmetic.h>
21#include <__concepts/same_as.h>
2122#include <__config>
22#include <__debug>
23#include <__format/format_error.h>
2423#include <__format/format_fwd.h>
25#include <__format/format_string.h>
24#include <__format/format_parse_context.h>
2625#include <__format/formatter.h>
2726#include <__format/formatter_integral.h>
27#include <__format/formatter_output.h>
2828#include <__format/parser_std_format_spec.h>
29#include <__memory/allocator.h>
2930#include <__utility/move.h>
31#include <__utility/unreachable.h>
3032#include <charconv>
31#include <cmath>
3233
3334#ifndef _LIBCPP_HAS_NO_LOCALIZATION
3435# include <locale>
......@@ -45,13 +46,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
4546
4647#if _LIBCPP_STD_VER > 17
4748
48// TODO FMT Remove this once we require compilers with proper C++20 support.
49// If the compiler has no concepts support, the format header will be disabled.
50// Without concepts support enable_if needs to be used and that too much effort
51// to support compilers with partial C++20 support.
52# if !defined(_LIBCPP_HAS_NO_CONCEPTS)
53
54namespace __format_spec {
49namespace __formatter {
5550
5651template <floating_point _Tp>
5752_LIBCPP_HIDE_FROM_ABI char* __to_buffer(char* __first, char* __last, _Tp __value) {
......@@ -167,7 +162,7 @@ public:
167162 __precision_ = _Traits::__max_fractional;
168163 }
169164
170 __size_ = __format_spec::__float_buffer_size<_Fp>(__precision_);
165 __size_ = __formatter::__float_buffer_size<_Fp>(__precision_);
171166 if (__size_ > _Traits::__stack_buffer_size)
172167 // The allocated buffer's contents don't need initialization.
173168 __begin_ = allocator<char>{}.allocate(__size_);
......@@ -236,9 +231,9 @@ _LIBCPP_HIDE_FROM_ABI __float_result __format_buffer_default(const __float_buffe
236231 char* __integral) {
237232 __float_result __result;
238233 __result.__integral = __integral;
239 __result.__last = __format_spec::__to_buffer(__integral, __buffer.end(), __value);
234 __result.__last = __formatter::__to_buffer(__integral, __buffer.end(), __value);
240235
241 __result.__exponent = __format_spec::__find_exponent(__result.__integral, __result.__last);
236 __result.__exponent = __formatter::__find_exponent(__result.__integral, __result.__last);
242237
243238 // Constrains:
244239 // - There's at least one decimal digit before the radix point.
......@@ -267,9 +262,9 @@ _LIBCPP_HIDE_FROM_ABI __float_result __format_buffer_hexadecimal_lower_case(cons
267262 __float_result __result;
268263 __result.__integral = __integral;
269264 if (__precision == -1)
270 __result.__last = __format_spec::__to_buffer(__integral, __buffer.end(), __value, chars_format::hex);
265 __result.__last = __formatter::__to_buffer(__integral, __buffer.end(), __value, chars_format::hex);
271266 else
272 __result.__last = __format_spec::__to_buffer(__integral, __buffer.end(), __value, chars_format::hex, __precision);
267 __result.__last = __formatter::__to_buffer(__integral, __buffer.end(), __value, chars_format::hex, __precision);
273268
274269 // H = one or more hex-digits
275270 // S = sign
......@@ -318,7 +313,7 @@ _LIBCPP_HIDE_FROM_ABI __float_result __format_buffer_hexadecimal_upper_case(cons
318313 _Tp __value, int __precision,
319314 char* __integral) {
320315 __float_result __result =
321 __format_spec::__format_buffer_hexadecimal_lower_case(__buffer, __value, __precision, __integral);
316 __formatter::__format_buffer_hexadecimal_lower_case(__buffer, __value, __precision, __integral);
322317 _VSTD::transform(__result.__integral, __result.__exponent, __result.__integral, __hex_to_upper);
323318 *__result.__exponent = 'P';
324319 return __result;
......@@ -331,13 +326,13 @@ _LIBCPP_HIDE_FROM_ABI __float_result __format_buffer_scientific_lower_case(const
331326 __float_result __result;
332327 __result.__integral = __integral;
333328 __result.__last =
334 __format_spec::__to_buffer(__integral, __buffer.end(), __value, chars_format::scientific, __precision);
329 __formatter::__to_buffer(__integral, __buffer.end(), __value, chars_format::scientific, __precision);
335330
336331 char* __first = __integral + 1;
337332 _LIBCPP_ASSERT(__first != __result.__last, "No exponent present");
338333 if (*__first == '.') {
339334 __result.__radix_point = __first;
340 __result.__exponent = __format_spec::__find_exponent(__first + 1, __result.__last);
335 __result.__exponent = __formatter::__find_exponent(__first + 1, __result.__last);
341336 } else {
342337 __result.__radix_point = __result.__last;
343338 __result.__exponent = __first;
......@@ -357,7 +352,7 @@ _LIBCPP_HIDE_FROM_ABI __float_result __format_buffer_scientific_upper_case(const
357352 _Tp __value, int __precision,
358353 char* __integral) {
359354 __float_result __result =
360 __format_spec::__format_buffer_scientific_lower_case(__buffer, __value, __precision, __integral);
355 __formatter::__format_buffer_scientific_lower_case(__buffer, __value, __precision, __integral);
361356 *__result.__exponent = 'E';
362357 return __result;
363358}
......@@ -367,7 +362,7 @@ _LIBCPP_HIDE_FROM_ABI __float_result __format_buffer_fixed(const __float_buffer<
367362 int __precision, char* __integral) {
368363 __float_result __result;
369364 __result.__integral = __integral;
370 __result.__last = __format_spec::__to_buffer(__integral, __buffer.end(), __value, chars_format::fixed, __precision);
365 __result.__last = __formatter::__to_buffer(__integral, __buffer.end(), __value, chars_format::fixed, __precision);
371366
372367 // When there's no precision there's no radix point.
373368 // Else the radix point is placed at __precision + 1 from the end.
......@@ -393,14 +388,14 @@ _LIBCPP_HIDE_FROM_ABI __float_result __format_buffer_general_lower_case(__float_
393388
394389 __float_result __result;
395390 __result.__integral = __integral;
396 __result.__last = __format_spec::__to_buffer(__integral, __buffer.end(), __value, chars_format::general, __precision);
391 __result.__last = __formatter::__to_buffer(__integral, __buffer.end(), __value, chars_format::general, __precision);
397392
398393 char* __first = __integral + 1;
399394 if (__first == __result.__last) {
400395 __result.__radix_point = __result.__last;
401396 __result.__exponent = __result.__last;
402397 } else {
403 __result.__exponent = __format_spec::__find_exponent(__first, __result.__last);
398 __result.__exponent = __formatter::__find_exponent(__first, __result.__last);
404399 if (__result.__exponent != __result.__last)
405400 // In scientific mode if there's a radix point it will always be after
406401 // the first digit. (This is the position __first points at).
......@@ -426,19 +421,79 @@ _LIBCPP_HIDE_FROM_ABI __float_result __format_buffer_general_lower_case(__float_
426421template <class _Fp, class _Tp>
427422_LIBCPP_HIDE_FROM_ABI __float_result __format_buffer_general_upper_case(__float_buffer<_Fp>& __buffer, _Tp __value,
428423 int __precision, char* __integral) {
429 __float_result __result =
430 __format_spec::__format_buffer_general_lower_case(__buffer, __value, __precision, __integral);
424 __float_result __result = __formatter::__format_buffer_general_lower_case(__buffer, __value, __precision, __integral);
431425 if (__result.__exponent != __result.__last)
432426 *__result.__exponent = 'E';
433427 return __result;
434428}
435429
436# ifndef _LIBCPP_HAS_NO_LOCALIZATION
430/// Fills the buffer with the data based on the requested formatting.
431///
432/// This function, when needed, turns the characters to upper case and
433/// determines the "interesting" locations which are returned to the caller.
434///
435/// This means the caller never has to convert the contents of the buffer to
436/// upper case or search for radix points and the location of the exponent.
437/// This gives a bit of overhead. The original code didn't do that, but due
438/// to the number of possible additional work needed to turn this number to
439/// the proper output the code was littered with tests for upper cases and
440/// searches for radix points and exponents.
441/// - When a precision larger than the type's precision is selected
442/// additional zero characters need to be written before the exponent.
443/// - alternate form needs to add a radix point when not present.
444/// - localization needs to do grouping in the integral part.
445template <class _Fp, class _Tp>
446// TODO FMT _Fp should just be _Tp when to_chars has proper long double support.
447_LIBCPP_HIDE_FROM_ABI __float_result __format_buffer(
448 __float_buffer<_Fp>& __buffer,
449 _Tp __value,
450 bool __negative,
451 bool __has_precision,
452 __format_spec::__sign __sign,
453 __format_spec::__type __type) {
454 char* __first = __formatter::__insert_sign(__buffer.begin(), __negative, __sign);
455 switch (__type) {
456 case __format_spec::__type::__default:
457 return __formatter::__format_buffer_default(__buffer, __value, __first);
458
459 case __format_spec::__type::__hexfloat_lower_case:
460 return __formatter::__format_buffer_hexadecimal_lower_case(
461 __buffer, __value, __has_precision ? __buffer.__precision() : -1, __first);
462
463 case __format_spec::__type::__hexfloat_upper_case:
464 return __formatter::__format_buffer_hexadecimal_upper_case(
465 __buffer, __value, __has_precision ? __buffer.__precision() : -1, __first);
466
467 case __format_spec::__type::__scientific_lower_case:
468 return __formatter::__format_buffer_scientific_lower_case(__buffer, __value, __buffer.__precision(), __first);
469
470 case __format_spec::__type::__scientific_upper_case:
471 return __formatter::__format_buffer_scientific_upper_case(__buffer, __value, __buffer.__precision(), __first);
472
473 case __format_spec::__type::__fixed_lower_case:
474 case __format_spec::__type::__fixed_upper_case:
475 return __formatter::__format_buffer_fixed(__buffer, __value, __buffer.__precision(), __first);
476
477 case __format_spec::__type::__general_lower_case:
478 return __formatter::__format_buffer_general_lower_case(__buffer, __value, __buffer.__precision(), __first);
479
480 case __format_spec::__type::__general_upper_case:
481 return __formatter::__format_buffer_general_upper_case(__buffer, __value, __buffer.__precision(), __first);
482
483 default:
484 _LIBCPP_ASSERT(false, "The parser should have validated the type");
485 __libcpp_unreachable();
486 }
487}
488
489# ifndef _LIBCPP_HAS_NO_LOCALIZATION
437490template <class _OutIt, class _Fp, class _CharT>
438_LIBCPP_HIDE_FROM_ABI _OutIt __format_locale_specific_form(_OutIt __out_it, const __float_buffer<_Fp>& __buffer,
439 const __float_result& __result, _VSTD::locale __loc,
440 size_t __width, _Flags::_Alignment __alignment,
441 _CharT __fill) {
491_LIBCPP_HIDE_FROM_ABI _OutIt __format_locale_specific_form(
492 _OutIt __out_it,
493 const __float_buffer<_Fp>& __buffer,
494 const __float_result& __result,
495 _VSTD::locale __loc,
496 __format_spec::__parsed_specifications<_CharT> __specs) {
442497 const auto& __np = use_facet<numpunct<_CharT>>(__loc);
443498 string __grouping = __np.grouping();
444499 char* __first = __result.__integral;
......@@ -450,29 +505,30 @@ _LIBCPP_HIDE_FROM_ABI _OutIt __format_locale_specific_form(_OutIt __out_it, cons
450505 if (__digits <= __grouping[0])
451506 __grouping.clear();
452507 else
453 __grouping = __determine_grouping(__digits, __grouping);
508 __grouping = __formatter::__determine_grouping(__digits, __grouping);
454509 }
455510
456 size_t __size = __result.__last - __buffer.begin() + // Formatted string
457 __buffer.__num_trailing_zeros() + // Not yet rendered zeros
458 __grouping.size() - // Grouping contains one
459 !__grouping.empty(); // additional character
511 ptrdiff_t __size =
512 __result.__last - __buffer.begin() + // Formatted string
513 __buffer.__num_trailing_zeros() + // Not yet rendered zeros
514 __grouping.size() - // Grouping contains one
515 !__grouping.empty(); // additional character
460516
461 __formatter::__padding_size_result __padding = {0, 0};
462 bool __zero_padding = __alignment == _Flags::_Alignment::__default;
463 if (__size < __width) {
517 __formatter::__padding_size_result __padding = {0, 0};
518 bool __zero_padding = __specs.__alignment_ == __format_spec::__alignment::__zero_padding;
519 if (__size < __specs.__width_) {
464520 if (__zero_padding) {
465 __alignment = _Flags::_Alignment::__right;
466 __fill = _CharT('0');
521 __specs.__alignment_ = __format_spec::__alignment::__right;
522 __specs.__fill_ = _CharT('0');
467523 }
468524
469 __padding = __formatter::__padding_size(__size, __width, __alignment);
525 __padding = __formatter::__padding_size(__size, __specs.__width_, __specs.__alignment_);
470526 }
471527
472528 // sign and (zero padding or alignment)
473529 if (__zero_padding && __first != __buffer.begin())
474530 *__out_it++ = *__buffer.begin();
475 __out_it = _VSTD::fill_n(_VSTD::move(__out_it), __padding.__before, __fill);
531 __out_it = _VSTD::fill_n(_VSTD::move(__out_it), __padding.__before_, __specs.__fill_);
476532 if (!__zero_padding && __first != __buffer.begin())
477533 *__out_it++ = *__buffer.begin();
478534
......@@ -513,200 +569,148 @@ _LIBCPP_HIDE_FROM_ABI _OutIt __format_locale_specific_form(_OutIt __out_it, cons
513569 __out_it = _VSTD::copy(__result.__exponent, __result.__last, _VSTD::move(__out_it));
514570
515571 // alignment
516 return _VSTD::fill_n(_VSTD::move(__out_it), __padding.__after, __fill);
572 return _VSTD::fill_n(_VSTD::move(__out_it), __padding.__after_, __specs.__fill_);
573}
574# endif // _LIBCPP_HAS_NO_LOCALIZATION
575
576template <class _OutIt, class _CharT>
577_LIBCPP_HIDE_FROM_ABI _OutIt __format_floating_point_non_finite(
578 _OutIt __out_it, __format_spec::__parsed_specifications<_CharT> __specs, bool __negative, bool __isnan) {
579 char __buffer[4];
580 char* __last = __formatter::__insert_sign(__buffer, __negative, __specs.__std_.__sign_);
581
582 // to_chars can return inf, infinity, nan, and nan(n-char-sequence).
583 // The format library requires inf and nan.
584 // All in one expression to avoid dangling references.
585 bool __upper_case =
586 __specs.__std_.__type_ == __format_spec::__type::__hexfloat_upper_case ||
587 __specs.__std_.__type_ == __format_spec::__type::__scientific_upper_case ||
588 __specs.__std_.__type_ == __format_spec::__type::__fixed_upper_case ||
589 __specs.__std_.__type_ == __format_spec::__type::__general_upper_case;
590 __last = _VSTD::copy_n(&("infnanINFNAN"[6 * __upper_case + 3 * __isnan]), 3, __last);
591
592 // [format.string.std]/13
593 // A zero (0) character preceding the width field pads the field with
594 // leading zeros (following any indication of sign or base) to the field
595 // width, except when applied to an infinity or NaN.
596 if (__specs.__alignment_ == __format_spec::__alignment::__zero_padding)
597 __specs.__alignment_ = __format_spec::__alignment::__right;
598
599 return __formatter::__write(__buffer, __last, _VSTD::move(__out_it), __specs);
517600}
518601
519# endif // _LIBCPP_HAS_NO_LOCALIZATION
520
521template <__formatter::__char_type _CharT>
522class _LIBCPP_TEMPLATE_VIS __formatter_floating_point : public __parser_floating_point<_CharT> {
523public:
524 template <floating_point _Tp>
525 _LIBCPP_HIDE_FROM_ABI auto format(_Tp __value, auto& __ctx) -> decltype(__ctx.out()) {
526 if (this->__width_needs_substitution())
527 this->__substitute_width_arg_id(__ctx.arg(this->__width));
528
529 bool __negative = _VSTD::signbit(__value);
530
531 if (!_VSTD::isfinite(__value)) [[unlikely]]
532 return __format_non_finite(__ctx.out(), __negative, _VSTD::isnan(__value));
533
534 bool __has_precision = this->__has_precision_field();
535 if (this->__precision_needs_substitution())
536 this->__substitute_precision_arg_id(__ctx.arg(this->__precision));
537
538 // Depending on the std-format-spec string the sign and the value
539 // might not be outputted together:
540 // - zero-padding may insert additional '0' characters.
541 // Therefore the value is processed as a non negative value.
542 // The function @ref __insert_sign will insert a '-' when the value was
543 // negative.
544
545 if (__negative)
546 __value = _VSTD::copysign(__value, +1.0);
547
548 // TODO FMT _Fp should just be _Tp when to_chars has proper long double support.
549 using _Fp = conditional_t<same_as<_Tp, long double>, double, _Tp>;
550 // Force the type of the precision to avoid -1 to become an unsigned value.
551 __float_buffer<_Fp> __buffer(__has_precision ? int(this->__precision) : -1);
552 __float_result __result = __format_buffer(__buffer, __value, __negative, __has_precision);
553
554 if (this->__alternate_form && __result.__radix_point == __result.__last) {
555 *__result.__last++ = '.';
556
557 // When there is an exponent the point needs to be moved before the
558 // exponent. When there's no exponent the rotate does nothing. Since
559 // rotate tests whether the operation is a nop, call it unconditionally.
560 _VSTD::rotate(__result.__exponent, __result.__last - 1, __result.__last);
561 __result.__radix_point = __result.__exponent;
562
563 // The radix point is always placed before the exponent.
564 // - No exponent needs to point to the new last.
565 // - An exponent needs to move one position to the right.
566 // So it's safe to increment the value unconditionally.
567 ++__result.__exponent;
568 }
602template <floating_point _Tp, class _CharT>
603_LIBCPP_HIDE_FROM_ABI auto
604__format_floating_point(_Tp __value, auto& __ctx, __format_spec::__parsed_specifications<_CharT> __specs)
605 -> decltype(__ctx.out()) {
606 bool __negative = _VSTD::signbit(__value);
569607
570# ifndef _LIBCPP_HAS_NO_LOCALIZATION
571 if (this->__locale_specific_form)
572 return __format_spec::__format_locale_specific_form(__ctx.out(), __buffer, __result, __ctx.locale(),
573 this->__width, this->__alignment, this->__fill);
574# endif
575
576 ptrdiff_t __size = __result.__last - __buffer.begin();
577 int __num_trailing_zeros = __buffer.__num_trailing_zeros();
578 if (__size + __num_trailing_zeros >= this->__width) {
579 if (__num_trailing_zeros && __result.__exponent != __result.__last)
580 // Insert trailing zeros before exponent character.
581 return _VSTD::copy(__result.__exponent, __result.__last,
582 _VSTD::fill_n(_VSTD::copy(__buffer.begin(), __result.__exponent, __ctx.out()),
583 __num_trailing_zeros, _CharT('0')));
584
585 return _VSTD::fill_n(_VSTD::copy(__buffer.begin(), __result.__last, __ctx.out()), __num_trailing_zeros,
586 _CharT('0'));
587 }
608 if (!_VSTD::isfinite(__value)) [[unlikely]]
609 return __formatter::__format_floating_point_non_finite(__ctx.out(), __specs, __negative, _VSTD::isnan(__value));
588610
589 auto __out_it = __ctx.out();
590 char* __first = __buffer.begin();
591 if (this->__alignment == _Flags::_Alignment::__default) {
592 // When there is a sign output it before the padding. Note the __size
593 // doesn't need any adjustment, regardless whether the sign is written
594 // here or in __formatter::__write.
595 if (__first != __result.__integral)
596 *__out_it++ = *__first++;
597 // After the sign is written, zero padding is the same a right alignment
598 // with '0'.
599 this->__alignment = _Flags::_Alignment::__right;
600 this->__fill = _CharT('0');
601 }
611 // Depending on the std-format-spec string the sign and the value
612 // might not be outputted together:
613 // - zero-padding may insert additional '0' characters.
614 // Therefore the value is processed as a non negative value.
615 // The function @ref __insert_sign will insert a '-' when the value was
616 // negative.
602617
603 if (__num_trailing_zeros)
604 return __formatter::__write(_VSTD::move(__out_it), __first, __result.__last, __size, this->__width, this->__fill,
605 this->__alignment, __result.__exponent, __num_trailing_zeros);
618 if (__negative)
619 __value = -__value;
606620
607 return __formatter::__write(_VSTD::move(__out_it), __first, __result.__last, __size, this->__width, this->__fill,
608 this->__alignment);
621 // TODO FMT _Fp should just be _Tp when to_chars has proper long double support.
622 using _Fp = conditional_t<same_as<_Tp, long double>, double, _Tp>;
623 // Force the type of the precision to avoid -1 to become an unsigned value.
624 __float_buffer<_Fp> __buffer(__specs.__precision_);
625 __float_result __result = __formatter::__format_buffer(
626 __buffer, __value, __negative, (__specs.__has_precision()), __specs.__std_.__sign_, __specs.__std_.__type_);
627
628 if (__specs.__std_.__alternate_form_ && __result.__radix_point == __result.__last) {
629 *__result.__last++ = '.';
630
631 // When there is an exponent the point needs to be moved before the
632 // exponent. When there's no exponent the rotate does nothing. Since
633 // rotate tests whether the operation is a nop, call it unconditionally.
634 _VSTD::rotate(__result.__exponent, __result.__last - 1, __result.__last);
635 __result.__radix_point = __result.__exponent;
636
637 // The radix point is always placed before the exponent.
638 // - No exponent needs to point to the new last.
639 // - An exponent needs to move one position to the right.
640 // So it's safe to increment the value unconditionally.
641 ++__result.__exponent;
609642 }
610643
611private:
612 template <class _OutIt>
613 _LIBCPP_HIDE_FROM_ABI _OutIt __format_non_finite(_OutIt __out_it, bool __negative, bool __isnan) {
614 char __buffer[4];
615 char* __last = __insert_sign(__buffer, __negative, this->__sign);
616
617 // to_char can return inf, infinity, nan, and nan(n-char-sequence).
618 // The format library requires inf and nan.
619 // All in one expression to avoid dangling references.
620 __last = _VSTD::copy_n(&("infnanINFNAN"[6 * (this->__type == _Flags::_Type::__float_hexadecimal_upper_case ||
621 this->__type == _Flags::_Type::__scientific_upper_case ||
622 this->__type == _Flags::_Type::__fixed_upper_case ||
623 this->__type == _Flags::_Type::__general_upper_case) +
624 3 * __isnan]),
625 3, __last);
626
627 // [format.string.std]/13
628 // A zero (0) character preceding the width field pads the field with
629 // leading zeros (following any indication of sign or base) to the field
630 // width, except when applied to an infinity or NaN.
631 if (this->__alignment == _Flags::_Alignment::__default)
632 this->__alignment = _Flags::_Alignment::__right;
633
634 ptrdiff_t __size = __last - __buffer;
635 if (__size >= this->__width)
636 return _VSTD::copy_n(__buffer, __size, _VSTD::move(__out_it));
637
638 return __formatter::__write(_VSTD::move(__out_it), __buffer, __last, __size, this->__width, this->__fill,
639 this->__alignment);
644# ifndef _LIBCPP_HAS_NO_LOCALIZATION
645 if (__specs.__std_.__locale_specific_form_)
646 return __formatter::__format_locale_specific_form(__ctx.out(), __buffer, __result, __ctx.locale(), __specs);
647# endif
648
649 ptrdiff_t __size = __result.__last - __buffer.begin();
650 int __num_trailing_zeros = __buffer.__num_trailing_zeros();
651 if (__size + __num_trailing_zeros >= __specs.__width_) {
652 if (__num_trailing_zeros && __result.__exponent != __result.__last)
653 // Insert trailing zeros before exponent character.
654 return _VSTD::copy(
655 __result.__exponent,
656 __result.__last,
657 _VSTD::fill_n(
658 _VSTD::copy(__buffer.begin(), __result.__exponent, __ctx.out()), __num_trailing_zeros, _CharT('0')));
659
660 return _VSTD::fill_n(
661 _VSTD::copy(__buffer.begin(), __result.__last, __ctx.out()), __num_trailing_zeros, _CharT('0'));
640662 }
641663
642 /// Fills the buffer with the data based on the requested formatting.
643 ///
644 /// This function, when needed, turns the characters to upper case and
645 /// determines the "interesting" locations which are returned to the caller.
646 ///
647 /// This means the caller never has to convert the contents of the buffer to
648 /// upper case or search for radix points and the location of the exponent.
649 /// This gives a bit of overhead. The original code didn't do that, but due
650 /// to the number of possible additional work needed to turn this number to
651 /// the proper output the code was littered with tests for upper cases and
652 /// searches for radix points and exponents.
653 /// - When a precision larger than the type's precision is selected
654 /// additional zero characters need to be written before the exponent.
655 /// - alternate form needs to add a radix point when not present.
656 /// - localization needs to do grouping in the integral part.
657 template <class _Fp, class _Tp>
658 // TODO FMT _Fp should just be _Tp when to_chars has proper long double support.
659 _LIBCPP_HIDE_FROM_ABI __float_result __format_buffer(__float_buffer<_Fp>& __buffer, _Tp __value, bool __negative,
660 bool __has_precision) {
661 char* __first = __insert_sign(__buffer.begin(), __negative, this->__sign);
662 switch (this->__type) {
663 case _Flags::_Type::__default:
664 return __format_spec::__format_buffer_default(__buffer, __value, __first);
665
666 case _Flags::_Type::__float_hexadecimal_lower_case:
667 return __format_spec::__format_buffer_hexadecimal_lower_case(
668 __buffer, __value, __has_precision ? __buffer.__precision() : -1, __first);
669
670 case _Flags::_Type::__float_hexadecimal_upper_case:
671 return __format_spec::__format_buffer_hexadecimal_upper_case(
672 __buffer, __value, __has_precision ? __buffer.__precision() : -1, __first);
673
674 case _Flags::_Type::__scientific_lower_case:
675 return __format_spec::__format_buffer_scientific_lower_case(__buffer, __value, __buffer.__precision(), __first);
664 auto __out_it = __ctx.out();
665 char* __first = __buffer.begin();
666 if (__specs.__alignment_ == __format_spec::__alignment ::__zero_padding) {
667 // When there is a sign output it before the padding. Note the __size
668 // doesn't need any adjustment, regardless whether the sign is written
669 // here or in __formatter::__write.
670 if (__first != __result.__integral)
671 *__out_it++ = *__first++;
672 // After the sign is written, zero padding is the same a right alignment
673 // with '0'.
674 __specs.__alignment_ = __format_spec::__alignment::__right;
675 __specs.__fill_ = _CharT('0');
676 }
676677
677 case _Flags::_Type::__scientific_upper_case:
678 return __format_spec::__format_buffer_scientific_upper_case(__buffer, __value, __buffer.__precision(), __first);
678 if (__num_trailing_zeros)
679 return __formatter::__write_using_trailing_zeros(
680 __first, __result.__last, _VSTD::move(__out_it), __specs, __size, __result.__exponent, __num_trailing_zeros);
679681
680 case _Flags::_Type::__fixed_lower_case:
681 case _Flags::_Type::__fixed_upper_case:
682 return __format_spec::__format_buffer_fixed(__buffer, __value, __buffer.__precision(), __first);
682 return __formatter::__write(__first, __result.__last, _VSTD::move(__out_it), __specs, __size);
683}
683684
684 case _Flags::_Type::__general_lower_case:
685 return __format_spec::__format_buffer_general_lower_case(__buffer, __value, __buffer.__precision(), __first);
685} // namespace __formatter
686686
687 case _Flags::_Type::__general_upper_case:
688 return __format_spec::__format_buffer_general_upper_case(__buffer, __value, __buffer.__precision(), __first);
687template <__formatter::__char_type _CharT>
688struct _LIBCPP_TEMPLATE_VIS __formatter_floating_point {
689public:
690 _LIBCPP_HIDE_FROM_ABI constexpr auto
691 parse(basic_format_parse_context<_CharT>& __parse_ctx) -> decltype(__parse_ctx.begin()) {
692 auto __result = __parser_.__parse(__parse_ctx, __format_spec::__fields_floating_point);
693 __format_spec::__process_parsed_floating_point(__parser_);
694 return __result;
695 }
689696
690 default:
691 _LIBCPP_ASSERT(false, "The parser should have validated the type");
692 _LIBCPP_UNREACHABLE();
693 }
697 template <floating_point _Tp>
698 _LIBCPP_HIDE_FROM_ABI auto format(_Tp __value, auto& __ctx) const -> decltype(__ctx.out()) {
699 return __formatter::__format_floating_point(__value, __ctx, __parser_.__get_parsed_std_specifications(__ctx));
694700 }
695};
696701
697} //namespace __format_spec
702 __format_spec::__parser<_CharT> __parser_;
703};
698704
699705template <__formatter::__char_type _CharT>
700706struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<float, _CharT>
701 : public __format_spec::__formatter_floating_point<_CharT> {};
707 : public __formatter_floating_point<_CharT> {};
702708template <__formatter::__char_type _CharT>
703709struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<double, _CharT>
704 : public __format_spec::__formatter_floating_point<_CharT> {};
710 : public __formatter_floating_point<_CharT> {};
705711template <__formatter::__char_type _CharT>
706712struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<long double, _CharT>
707 : public __format_spec::__formatter_floating_point<_CharT> {};
708
709# endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
713 : public __formatter_floating_point<_CharT> {};
710714
711715#endif //_LIBCPP_STD_VER > 17
712716
lib/libcxx/include/__format/formatter_integer.h+54-117
......@@ -11,160 +11,97 @@
1111#define _LIBCPP___FORMAT_FORMATTER_INTEGER_H
1212
1313#include <__availability>
14#include <__concepts/arithmetic.h>
1415#include <__config>
15#include <__format/format_error.h>
1616#include <__format/format_fwd.h>
17#include <__format/format_parse_context.h>
1718#include <__format/formatter.h>
1819#include <__format/formatter_integral.h>
20#include <__format/formatter_output.h>
1921#include <__format/parser_std_format_spec.h>
20#include <limits>
22#include <__type_traits/make_32_64_or_128_bit.h>
23#include <type_traits>
2124
2225#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23#pragma GCC system_header
26# pragma GCC system_header
2427#endif
2528
26_LIBCPP_PUSH_MACROS
27#include <__undef_macros>
28
29_LIBCPP_BEGIN_NAMESPACE_STD
29 _LIBCPP_BEGIN_NAMESPACE_STD
3030
3131#if _LIBCPP_STD_VER > 17
3232
33// TODO FMT Remove this once we require compilers with proper C++20 support.
34// If the compiler has no concepts support, the format header will be disabled.
35// Without concepts support enable_if needs to be used and that too much effort
36// to support compilers with partial C++20 support.
37#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
38
39namespace __format_spec {
33 template <__formatter::__char_type _CharT>
34 struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT __formatter_integer {
4035
41template <class _CharT>
42class _LIBCPP_TEMPLATE_VIS __parser_integer : public __parser_integral<_CharT> {
4336public:
44 _LIBCPP_HIDE_FROM_ABI constexpr auto parse(auto& __parse_ctx)
45 -> decltype(__parse_ctx.begin()) {
46 auto __it = __parser_integral<_CharT>::__parse(__parse_ctx);
47
48 switch (this->__type) {
49 case _Flags::_Type::__default:
50 this->__type = _Flags::_Type::__decimal;
51 [[fallthrough]];
52
53 case _Flags::_Type::__binary_lower_case:
54 case _Flags::_Type::__binary_upper_case:
55 case _Flags::_Type::__octal:
56 case _Flags::_Type::__decimal:
57 case _Flags::_Type::__hexadecimal_lower_case:
58 case _Flags::_Type::__hexadecimal_upper_case:
59 this->__handle_integer();
60 break;
61
62 case _Flags::_Type::__char:
63 this->__handle_char();
64 break;
65
66 default:
67 __throw_format_error("The format-spec type has a type not supported for "
68 "an integer argument");
69 }
70 return __it;
37 _LIBCPP_HIDE_FROM_ABI constexpr auto
38 parse(basic_format_parse_context<_CharT>& __parse_ctx) -> decltype(__parse_ctx.begin()) {
39 auto __result = __parser_.__parse(__parse_ctx, __format_spec::__fields_integral);
40 __format_spec::__process_parsed_integer(__parser_);
41 return __result;
7142 }
72};
7343
74template <class _CharT>
75using __formatter_integer = __formatter_integral<__parser_integer<_CharT>>;
44 template <integral _Tp>
45 _LIBCPP_HIDE_FROM_ABI auto format(_Tp __value, auto& __ctx) const -> decltype(__ctx.out()) {
46 __format_spec::__parsed_specifications<_CharT> __specs = __parser_.__get_parsed_std_specifications(__ctx);
47
48 if (__specs.__std_.__type_ == __format_spec::__type::__char)
49 return __formatter::__format_char(__value, __ctx.out(), __specs);
7650
77} // namespace __format_spec
51 using _Type = __make_32_64_or_128_bit_t<_Tp>;
52 static_assert(!is_same<_Type, void>::value, "unsupported integral type used in __formatter_integer::__format");
7853
79// [format.formatter.spec]/2.3
80// For each charT, for each cv-unqualified arithmetic type ArithmeticT other
81// than char, wchar_t, char8_t, char16_t, or char32_t, a specialization
54 // Reduce the number of instantiation of the integer formatter
55 return __formatter::__format_integer(static_cast<_Type>(__value), __ctx, __specs);
56 }
57
58 __format_spec::__parser<_CharT> __parser_;
59};
8260
8361// Signed integral types.
8462template <__formatter::__char_type _CharT>
85struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT
86 formatter<signed char, _CharT>
87 : public __format_spec::__formatter_integer<_CharT> {};
63struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<signed char, _CharT>
64 : public __formatter_integer<_CharT> {};
8865template <__formatter::__char_type _CharT>
89struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<short, _CharT>
90 : public __format_spec::__formatter_integer<_CharT> {};
66struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<short, _CharT> : public __formatter_integer<_CharT> {
67};
9168template <__formatter::__char_type _CharT>
92struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<int, _CharT>
93 : public __format_spec::__formatter_integer<_CharT> {};
69struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<int, _CharT> : public __formatter_integer<_CharT> {};
9470template <__formatter::__char_type _CharT>
95struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<long, _CharT>
96 : public __format_spec::__formatter_integer<_CharT> {};
71struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<long, _CharT> : public __formatter_integer<_CharT> {};
9772template <__formatter::__char_type _CharT>
98struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT
99 formatter<long long, _CharT>
100 : public __format_spec::__formatter_integer<_CharT> {};
101#ifndef _LIBCPP_HAS_NO_INT128
73struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<long long, _CharT>
74 : public __formatter_integer<_CharT> {};
75# ifndef _LIBCPP_HAS_NO_INT128
10276template <__formatter::__char_type _CharT>
103struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT
104 formatter<__int128_t, _CharT>
105 : public __format_spec::__formatter_integer<_CharT> {
106 using _Base = __format_spec::__formatter_integer<_CharT>;
107
108 _LIBCPP_HIDE_FROM_ABI auto format(__int128_t __value, auto& __ctx)
109 -> decltype(__ctx.out()) {
110 // TODO FMT Implement full 128 bit support.
111 using _To = long long;
112 if (__value < numeric_limits<_To>::min() ||
113 __value > numeric_limits<_To>::max())
114 __throw_format_error("128-bit value is outside of implemented range");
115
116 return _Base::format(static_cast<_To>(__value), __ctx);
117 }
118};
119#endif
77struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<__int128_t, _CharT>
78 : public __formatter_integer<_CharT> {};
79# endif
12080
12181// Unsigned integral types.
12282template <__formatter::__char_type _CharT>
123struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT
124 formatter<unsigned char, _CharT>
125 : public __format_spec::__formatter_integer<_CharT> {};
83struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<unsigned char, _CharT>
84 : public __formatter_integer<_CharT> {};
12685template <__formatter::__char_type _CharT>
127struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT
128 formatter<unsigned short, _CharT>
129 : public __format_spec::__formatter_integer<_CharT> {};
86struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<unsigned short, _CharT>
87 : public __formatter_integer<_CharT> {};
13088template <__formatter::__char_type _CharT>
131struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT
132 formatter<unsigned, _CharT>
133 : public __format_spec::__formatter_integer<_CharT> {};
89struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<unsigned, _CharT>
90 : public __formatter_integer<_CharT> {};
13491template <__formatter::__char_type _CharT>
135struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT
136 formatter<unsigned long, _CharT>
137 : public __format_spec::__formatter_integer<_CharT> {};
92struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<unsigned long, _CharT>
93 : public __formatter_integer<_CharT> {};
13894template <__formatter::__char_type _CharT>
139struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT
140 formatter<unsigned long long, _CharT>
141 : public __format_spec::__formatter_integer<_CharT> {};
142#ifndef _LIBCPP_HAS_NO_INT128
95struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<unsigned long long, _CharT>
96 : public __formatter_integer<_CharT> {};
97# ifndef _LIBCPP_HAS_NO_INT128
14398template <__formatter::__char_type _CharT>
144struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT
145 formatter<__uint128_t, _CharT>
146 : public __format_spec::__formatter_integer<_CharT> {
147 using _Base = __format_spec::__formatter_integer<_CharT>;
148
149 _LIBCPP_HIDE_FROM_ABI auto format(__uint128_t __value, auto& __ctx)
150 -> decltype(__ctx.out()) {
151 // TODO FMT Implement full 128 bit support.
152 using _To = unsigned long long;
153 if (__value < numeric_limits<_To>::min() ||
154 __value > numeric_limits<_To>::max())
155 __throw_format_error("128-bit value is outside of implemented range");
156
157 return _Base::format(static_cast<_To>(__value), __ctx);
158 }
159};
160#endif
161
162#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
99struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<__uint128_t, _CharT>
100 : public __formatter_integer<_CharT> {};
101# endif
163102
164103#endif //_LIBCPP_STD_VER > 17
165104
166105_LIBCPP_END_NAMESPACE_STD
167106
168_LIBCPP_POP_MACROS
169
170107#endif // _LIBCPP___FORMAT_FORMATTER_INTEGER_H
lib/libcxx/include/__format/formatter_integral.h+254-355
......@@ -10,27 +10,24 @@
1010#ifndef _LIBCPP___FORMAT_FORMATTER_INTEGRAL_H
1111#define _LIBCPP___FORMAT_FORMATTER_INTEGRAL_H
1212
13#include <__algorithm/copy.h>
14#include <__algorithm/copy_n.h>
15#include <__algorithm/fill_n.h>
16#include <__algorithm/transform.h>
13#include <__concepts/arithmetic.h>
14#include <__concepts/same_as.h>
1715#include <__config>
1816#include <__format/format_error.h>
19#include <__format/format_fwd.h>
20#include <__format/formatter.h>
17#include <__format/formatter.h> // for __char_type TODO FMT Move the concept?
18#include <__format/formatter_output.h>
2119#include <__format/parser_std_format_spec.h>
22#include <array>
20#include <__utility/unreachable.h>
2321#include <charconv>
24#include <concepts>
2522#include <limits>
2623#include <string>
2724
2825#ifndef _LIBCPP_HAS_NO_LOCALIZATION
29#include <locale>
26# include <locale>
3027#endif
3128
3229#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
33#pragma GCC system_header
30# pragma GCC system_header
3431#endif
3532
3633_LIBCPP_PUSH_MACROS
......@@ -40,97 +37,30 @@ _LIBCPP_BEGIN_NAMESPACE_STD
4037
4138#if _LIBCPP_STD_VER > 17
4239
43// TODO FMT Remove this once we require compilers with proper C++20 support.
44// If the compiler has no concepts support, the format header will be disabled.
45// Without concepts support enable_if needs to be used and that too much effort
46// to support compilers with partial C++20 support.
47#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
40namespace __formatter {
4841
49/**
50 * Integral formatting classes.
51 *
52 * There are two types used here:
53 * * C++-type, the type as used in C++.
54 * * format-type, the output type specified in the std-format-spec.
55 *
56 * Design of the integral formatters consists of several layers.
57 * * @ref __parser_integral The basic std-format-spec parser for all integral
58 * classes. This parser does the basic sanity checks. It also contains some
59 * helper functions that are nice to have available for all parsers.
60 * * A C++-type specific parser. These parsers must derive from
61 * @ref __parser_integral. Their task is to validate whether the parsed
62 * std-format-spec is valid for the C++-type and selected format-type. After
63 * validation they need to make sure all members are properly set. For
64 * example, when the alignment hasn't changed it needs to set the proper
65 * default alignment for the format-type. The following parsers are available:
66 * - @ref __parser_integer
67 * - @ref __parser_char
68 * - @ref __parser_bool
69 * * A general formatter for all integral types @ref __formatter_integral. This
70 * formatter can handle all formatting of integers and characters. The class
71 * derives from the proper formatter.
72 * Note the boolean string format-type isn't supported in this class.
73 * * A typedef C++-type group combining the @ref __formatter_integral with a
74 * parser:
75 * * @ref __formatter_integer
76 * * @ref __formatter_char
77 * * @ref __formatter_bool
78 * * Then every C++-type has its own formatter specializations. They inherit
79 * from the C++-type group typedef. Most specializations need nothing else.
80 * Others need some additional specializations in this class.
81 */
82namespace __format_spec {
83
84/** Wrapper around @ref to_chars, returning the output pointer. */
85template <integral _Tp>
86_LIBCPP_HIDE_FROM_ABI char* __to_buffer(char* __first, char* __last,
87 _Tp __value, int __base) {
88 // TODO FMT Evaluate code overhead due to not calling the internal function
89 // directly. (Should be zero overhead.)
90 to_chars_result __r = _VSTD::to_chars(__first, __last, __value, __base);
91 _LIBCPP_ASSERT(__r.ec == errc(0), "Internal buffer too small");
92 return __r.ptr;
93}
94
95/**
96 * Helper to determine the buffer size to output a integer in Base @em x.
97 *
98 * There are several overloads for the supported bases. The function uses the
99 * base as template argument so it can be used in a constant expression.
100 */
101template <unsigned_integral _Tp, size_t _Base>
102_LIBCPP_HIDE_FROM_ABI constexpr size_t __buffer_size() noexcept
103 requires(_Base == 2) {
104 return numeric_limits<_Tp>::digits // The number of binary digits.
105 + 2 // Reserve space for the '0[Bb]' prefix.
106 + 1; // Reserve space for the sign.
107}
108
109template <unsigned_integral _Tp, size_t _Base>
110_LIBCPP_HIDE_FROM_ABI constexpr size_t __buffer_size() noexcept
111 requires(_Base == 8) {
112 return numeric_limits<_Tp>::digits // The number of binary digits.
113 / 3 // Adjust to octal.
114 + 1 // Turn floor to ceil.
115 + 1 // Reserve space for the '0' prefix.
116 + 1; // Reserve space for the sign.
117}
42//
43// Generic
44//
11845
119template <unsigned_integral _Tp, size_t _Base>
120_LIBCPP_HIDE_FROM_ABI constexpr size_t __buffer_size() noexcept
121 requires(_Base == 10) {
122 return numeric_limits<_Tp>::digits10 // The floored value.
123 + 1 // Turn floor to ceil.
124 + 1; // Reserve space for the sign.
125}
46_LIBCPP_HIDE_FROM_ABI inline char* __insert_sign(char* __buf, bool __negative, __format_spec::__sign __sign) {
47 if (__negative)
48 *__buf++ = '-';
49 else
50 switch (__sign) {
51 case __format_spec::__sign::__default:
52 case __format_spec::__sign::__minus:
53 // No sign added.
54 break;
55 case __format_spec::__sign::__plus:
56 *__buf++ = '+';
57 break;
58 case __format_spec::__sign::__space:
59 *__buf++ = ' ';
60 break;
61 }
12662
127template <unsigned_integral _Tp, size_t _Base>
128_LIBCPP_HIDE_FROM_ABI constexpr size_t __buffer_size() noexcept
129 requires(_Base == 16) {
130 return numeric_limits<_Tp>::digits // The number of binary digits.
131 / 4 // Adjust to hexadecimal.
132 + 2 // Reserve space for the '0[Xx]' prefix.
133 + 1; // Reserve space for the sign.
63 return __buf;
13464}
13565
13666/**
......@@ -148,8 +78,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr size_t __buffer_size() noexcept
14878 * @note The grouping field of the locale is always a @c std::string,
14979 * regardless whether the @c std::numpunct's type is @c char or @c wchar_t.
15080 */
151_LIBCPP_HIDE_FROM_ABI inline string
152__determine_grouping(ptrdiff_t __size, const string& __grouping) {
81_LIBCPP_HIDE_FROM_ABI inline string __determine_grouping(ptrdiff_t __size, const string& __grouping) {
15382 _LIBCPP_ASSERT(!__grouping.empty() && __size > __grouping[0],
15483 "The slow grouping formatting is used while there will be no "
15584 "separators written");
......@@ -176,283 +105,253 @@ __determine_grouping(ptrdiff_t __size, const string& __grouping) {
176105 }
177106 }
178107
179 _LIBCPP_UNREACHABLE();
108 __libcpp_unreachable();
180109}
181110
182template <class _Parser>
183requires __formatter::__char_type<typename _Parser::char_type>
184class _LIBCPP_TEMPLATE_VIS __formatter_integral : public _Parser {
185public:
186 using _CharT = typename _Parser::char_type;
187
188 template <integral _Tp>
189 _LIBCPP_HIDE_FROM_ABI auto format(_Tp __value, auto& __ctx)
190 -> decltype(__ctx.out()) {
191 if (this->__width_needs_substitution())
192 this->__substitute_width_arg_id(__ctx.arg(this->__width));
193
194 if (this->__type == _Flags::_Type::__char)
195 return __format_as_char(__value, __ctx);
111//
112// Char
113//
196114
197 if constexpr (unsigned_integral<_Tp>)
198 return __format_unsigned_integral(__value, false, __ctx);
199 else {
200 // Depending on the std-format-spec string the sign and the value
201 // might not be outputted together:
202 // - alternate form may insert a prefix string.
203 // - zero-padding may insert additional '0' characters.
204 // Therefore the value is processed as a positive unsigned value.
205 // The function @ref __insert_sign will a '-' when the value was negative.
206 auto __r = __to_unsigned_like(__value);
207 bool __negative = __value < 0;
208 if (__negative)
209 __r = __complement(__r);
210
211 return __format_unsigned_integral(__r, __negative, __ctx);
115template <__formatter::__char_type _CharT>
116_LIBCPP_HIDE_FROM_ABI auto __format_char(
117 integral auto __value,
118 output_iterator<const _CharT&> auto __out_it,
119 __format_spec::__parsed_specifications<_CharT> __specs) -> decltype(__out_it) {
120 using _Tp = decltype(__value);
121 if constexpr (!same_as<_CharT, _Tp>) {
122 // cmp_less and cmp_greater can't be used for character types.
123 if constexpr (signed_integral<_CharT> == signed_integral<_Tp>) {
124 if (__value < numeric_limits<_CharT>::min() || __value > numeric_limits<_CharT>::max())
125 std::__throw_format_error("Integral value outside the range of the char type");
126 } else if constexpr (signed_integral<_CharT>) {
127 // _CharT is signed _Tp is unsigned
128 if (__value > static_cast<make_unsigned_t<_CharT>>(numeric_limits<_CharT>::max()))
129 std::__throw_format_error("Integral value outside the range of the char type");
130 } else {
131 // _CharT is unsigned _Tp is signed
132 if (__value < 0 || static_cast<make_unsigned_t<_Tp>>(__value) > numeric_limits<_CharT>::max())
133 std::__throw_format_error("Integral value outside the range of the char type");
212134 }
213135 }
214136
215private:
216 /** Generic formatting for format-type c. */
217 _LIBCPP_HIDE_FROM_ABI auto __format_as_char(integral auto __value,
218 auto& __ctx)
219 -> decltype(__ctx.out()) {
220 if (this->__alignment == _Flags::_Alignment::__default)
221 this->__alignment = _Flags::_Alignment::__right;
222
223 using _Tp = decltype(__value);
224 if constexpr (!same_as<_CharT, _Tp>) {
225 // cmp_less and cmp_greater can't be used for character types.
226 if constexpr (signed_integral<_CharT> == signed_integral<_Tp>) {
227 if (__value < numeric_limits<_CharT>::min() ||
228 __value > numeric_limits<_CharT>::max())
229 __throw_format_error(
230 "Integral value outside the range of the char type");
231 } else if constexpr (signed_integral<_CharT>) {
232 // _CharT is signed _Tp is unsigned
233 if (__value >
234 static_cast<make_unsigned_t<_CharT>>(numeric_limits<_CharT>::max()))
235 __throw_format_error(
236 "Integral value outside the range of the char type");
237 } else {
238 // _CharT is unsigned _Tp is signed
239 if (__value < 0 || static_cast<make_unsigned_t<_Tp>>(__value) >
240 numeric_limits<_CharT>::max())
241 __throw_format_error(
242 "Integral value outside the range of the char type");
243 }
244 }
137 const auto __c = static_cast<_CharT>(__value);
138 return __formatter::__write(_VSTD::addressof(__c), _VSTD::addressof(__c) + 1, _VSTD::move(__out_it), __specs);
139}
245140
246 const auto __c = static_cast<_CharT>(__value);
247 return __write(_VSTD::addressof(__c), _VSTD::addressof(__c) + 1,
248 __ctx.out());
249 }
141//
142// Integer
143//
250144
251 /**
252 * Generic formatting for format-type bBdoxX.
253 *
254 * This small wrapper allocates a buffer with the required size. Then calls
255 * the real formatter with the buffer and the prefix for the base.
256 */
257 _LIBCPP_HIDE_FROM_ABI auto
258 __format_unsigned_integral(unsigned_integral auto __value, bool __negative,
259 auto& __ctx) -> decltype(__ctx.out()) {
260 switch (this->__type) {
261 case _Flags::_Type::__binary_lower_case: {
262 array<char, __buffer_size<decltype(__value), 2>()> __array;
263 return __format_unsigned_integral(__array.begin(), __array.end(), __value,
264 __negative, 2, __ctx, "0b");
265 }
266 case _Flags::_Type::__binary_upper_case: {
267 array<char, __buffer_size<decltype(__value), 2>()> __array;
268 return __format_unsigned_integral(__array.begin(), __array.end(), __value,
269 __negative, 2, __ctx, "0B");
270 }
271 case _Flags::_Type::__octal: {
272 // Octal is special; if __value == 0 there's no prefix.
273 array<char, __buffer_size<decltype(__value), 8>()> __array;
274 return __format_unsigned_integral(__array.begin(), __array.end(), __value,
275 __negative, 8, __ctx,
276 __value != 0 ? "0" : nullptr);
277 }
278 case _Flags::_Type::__decimal: {
279 array<char, __buffer_size<decltype(__value), 10>()> __array;
280 return __format_unsigned_integral(__array.begin(), __array.end(), __value,
281 __negative, 10, __ctx, nullptr);
282 }
283 case _Flags::_Type::__hexadecimal_lower_case: {
284 array<char, __buffer_size<decltype(__value), 16>()> __array;
285 return __format_unsigned_integral(__array.begin(), __array.end(), __value,
286 __negative, 16, __ctx, "0x");
287 }
288 case _Flags::_Type::__hexadecimal_upper_case: {
289 array<char, __buffer_size<decltype(__value), 16>()> __array;
290 return __format_unsigned_integral(__array.begin(), __array.end(), __value,
291 __negative, 16, __ctx, "0X");
292 }
293 default:
294 _LIBCPP_ASSERT(false, "The parser should have validated the type");
295 _LIBCPP_UNREACHABLE();
296 }
297 }
145/** Wrapper around @ref to_chars, returning the output pointer. */
146template <integral _Tp>
147_LIBCPP_HIDE_FROM_ABI char* __to_buffer(char* __first, char* __last, _Tp __value, int __base) {
148 // TODO FMT Evaluate code overhead due to not calling the internal function
149 // directly. (Should be zero overhead.)
150 to_chars_result __r = _VSTD::to_chars(__first, __last, __value, __base);
151 _LIBCPP_ASSERT(__r.ec == errc(0), "Internal buffer too small");
152 return __r.ptr;
153}
298154
299 template <class _Tp>
300 requires(same_as<char, _Tp> || same_as<wchar_t, _Tp>) _LIBCPP_HIDE_FROM_ABI
301 auto __write(const _Tp* __first, const _Tp* __last, auto __out_it)
302 -> decltype(__out_it) {
155/**
156 * Helper to determine the buffer size to output a integer in Base @em x.
157 *
158 * There are several overloads for the supported bases. The function uses the
159 * base as template argument so it can be used in a constant expression.
160 */
161template <unsigned_integral _Tp, size_t _Base>
162consteval size_t __buffer_size() noexcept
163 requires(_Base == 2)
164{
165 return numeric_limits<_Tp>::digits // The number of binary digits.
166 + 2 // Reserve space for the '0[Bb]' prefix.
167 + 1; // Reserve space for the sign.
168}
303169
304 unsigned __size = __last - __first;
305 if (this->__type != _Flags::_Type::__hexadecimal_upper_case) [[likely]] {
306 if (__size >= this->__width)
307 return _VSTD::copy(__first, __last, _VSTD::move(__out_it));
170template <unsigned_integral _Tp, size_t _Base>
171consteval size_t __buffer_size() noexcept
172 requires(_Base == 8)
173{
174 return numeric_limits<_Tp>::digits // The number of binary digits.
175 / 3 // Adjust to octal.
176 + 1 // Turn floor to ceil.
177 + 1 // Reserve space for the '0' prefix.
178 + 1; // Reserve space for the sign.
179}
308180
309 return __formatter::__write(_VSTD::move(__out_it), __first, __last,
310 __size, this->__width, this->__fill,
311 this->__alignment);
312 }
181template <unsigned_integral _Tp, size_t _Base>
182consteval size_t __buffer_size() noexcept
183 requires(_Base == 10)
184{
185 return numeric_limits<_Tp>::digits10 // The floored value.
186 + 1 // Turn floor to ceil.
187 + 1; // Reserve space for the sign.
188}
189
190template <unsigned_integral _Tp, size_t _Base>
191consteval size_t __buffer_size() noexcept
192 requires(_Base == 16)
193{
194 return numeric_limits<_Tp>::digits // The number of binary digits.
195 / 4 // Adjust to hexadecimal.
196 + 2 // Reserve space for the '0[Xx]' prefix.
197 + 1; // Reserve space for the sign.
198}
313199
314 // this->__type == _Flags::_Type::__hexadecimal_upper_case
315 // This means all characters in the range [a-f] need to be changed to their
316 // uppercase representation. The transformation is done as transformation
317 // in the output routine instead of before. This avoids another pass over
318 // the data.
319 // TODO FMT See whether it's possible to do this transformation during the
320 // conversion. (This probably requires changing std::to_chars' alphabet.)
321 if (__size >= this->__width)
322 return _VSTD::transform(__first, __last, _VSTD::move(__out_it),
323 __hex_to_upper);
324
325 return __formatter::__write(_VSTD::move(__out_it), __first, __last, __size,
326 __hex_to_upper, this->__width, this->__fill,
327 this->__alignment);
200template <unsigned_integral _Tp, class _CharT>
201_LIBCPP_HIDE_FROM_ABI auto __format_integer(
202 _Tp __value,
203 auto& __ctx,
204 __format_spec::__parsed_specifications<_CharT> __specs,
205 bool __negative,
206 char* __begin,
207 char* __end,
208 const char* __prefix,
209 int __base) -> decltype(__ctx.out()) {
210 char* __first = __formatter::__insert_sign(__begin, __negative, __specs.__std_.__sign_);
211 if (__specs.__std_.__alternate_form_ && __prefix)
212 while (*__prefix)
213 *__first++ = *__prefix++;
214
215 char* __last = __formatter::__to_buffer(__first, __end, __value, __base);
216
217# ifndef _LIBCPP_HAS_NO_LOCALIZATION
218 if (__specs.__std_.__locale_specific_form_) {
219 const auto& __np = use_facet<numpunct<_CharT>>(__ctx.locale());
220 string __grouping = __np.grouping();
221 ptrdiff_t __size = __last - __first;
222 // Writing the grouped form has more overhead than the normal output
223 // routines. If there will be no separators written the locale-specific
224 // form is identical to the normal routine. Test whether to grouped form
225 // is required.
226 if (!__grouping.empty() && __size > __grouping[0])
227 return __formatter::__write_using_decimal_separators(
228 __ctx.out(),
229 __begin,
230 __first,
231 __last,
232 __formatter::__determine_grouping(__size, __grouping),
233 __np.thousands_sep(),
234 __specs);
235 }
236# endif
237 auto __out_it = __ctx.out();
238 if (__specs.__alignment_ != __format_spec::__alignment::__zero_padding)
239 __first = __begin;
240 else {
241 // __buf contains [sign][prefix]data
242 // ^ location of __first
243 // The zero padding is done like:
244 // - Write [sign][prefix]
245 // - Write data right aligned with '0' as fill character.
246 __out_it = _VSTD::copy(__begin, __first, _VSTD::move(__out_it));
247 __specs.__alignment_ = __format_spec::__alignment::__right;
248 __specs.__fill_ = _CharT('0');
249 int32_t __size = __first - __begin;
250
251 __specs.__width_ -= _VSTD::min(__size, __specs.__width_);
328252 }
329253
330 _LIBCPP_HIDE_FROM_ABI auto
331 __format_unsigned_integral(char* __begin, char* __end,
332 unsigned_integral auto __value, bool __negative,
333 int __base, auto& __ctx, const char* __prefix)
334 -> decltype(__ctx.out()) {
335 char* __first = __insert_sign(__begin, __negative, this->__sign);
336 if (this->__alternate_form && __prefix)
337 while (*__prefix)
338 *__first++ = *__prefix++;
339
340 char* __last = __to_buffer(__first, __end, __value, __base);
341#ifndef _LIBCPP_HAS_NO_LOCALIZATION
342 if (this->__locale_specific_form) {
343 const auto& __np = use_facet<numpunct<_CharT>>(__ctx.locale());
344 string __grouping = __np.grouping();
345 ptrdiff_t __size = __last - __first;
346 // Writing the grouped form has more overhead than the normal output
347 // routines. If there will be no separators written the locale-specific
348 // form is identical to the normal routine. Test whether to grouped form
349 // is required.
350 if (!__grouping.empty() && __size > __grouping[0])
351 return __format_grouping(__ctx.out(), __begin, __first, __last,
352 __determine_grouping(__size, __grouping),
353 __np.thousands_sep());
354 }
355#endif
356 auto __out_it = __ctx.out();
357 if (this->__alignment != _Flags::_Alignment::__default)
358 __first = __begin;
359 else {
360 // __buf contains [sign][prefix]data
361 // ^ location of __first
362 // The zero padding is done like:
363 // - Write [sign][prefix]
364 // - Write data right aligned with '0' as fill character.
365 __out_it = _VSTD::copy(__begin, __first, _VSTD::move(__out_it));
366 this->__alignment = _Flags::_Alignment::__right;
367 this->__fill = _CharT('0');
368 uint32_t __size = __first - __begin;
369 this->__width -= _VSTD::min(__size, this->__width);
370 }
254 if (__specs.__std_.__type_ != __format_spec::__type::__hexadecimal_upper_case) [[likely]]
255 return __formatter::__write(__first, __last, __ctx.out(), __specs);
256
257 return __formatter::__write_transformed(__first, __last, __ctx.out(), __specs, __formatter::__hex_to_upper);
258}
371259
372 return __write(__first, __last, _VSTD::move(__out_it));
260template <unsigned_integral _Tp, class _CharT>
261_LIBCPP_HIDE_FROM_ABI auto __format_integer(
262 _Tp __value, auto& __ctx, __format_spec::__parsed_specifications<_CharT> __specs, bool __negative = false)
263 -> decltype(__ctx.out()) {
264 switch (__specs.__std_.__type_) {
265 case __format_spec::__type::__binary_lower_case: {
266 array<char, __formatter::__buffer_size<decltype(__value), 2>()> __array;
267 return __formatter::__format_integer(__value, __ctx, __specs, __negative, __array.begin(), __array.end(), "0b", 2);
268 }
269 case __format_spec::__type::__binary_upper_case: {
270 array<char, __formatter::__buffer_size<decltype(__value), 2>()> __array;
271 return __formatter::__format_integer(__value, __ctx, __specs, __negative, __array.begin(), __array.end(), "0B", 2);
272 }
273 case __format_spec::__type::__octal: {
274 // Octal is special; if __value == 0 there's no prefix.
275 array<char, __formatter::__buffer_size<decltype(__value), 8>()> __array;
276 return __formatter::__format_integer(
277 __value, __ctx, __specs, __negative, __array.begin(), __array.end(), __value != 0 ? "0" : nullptr, 8);
278 }
279 case __format_spec::__type::__default:
280 case __format_spec::__type::__decimal: {
281 array<char, __formatter::__buffer_size<decltype(__value), 10>()> __array;
282 return __formatter::__format_integer(
283 __value, __ctx, __specs, __negative, __array.begin(), __array.end(), nullptr, 10);
284 }
285 case __format_spec::__type::__hexadecimal_lower_case: {
286 array<char, __formatter::__buffer_size<decltype(__value), 16>()> __array;
287 return __formatter::__format_integer(__value, __ctx, __specs, __negative, __array.begin(), __array.end(), "0x", 16);
288 }
289 case __format_spec::__type::__hexadecimal_upper_case: {
290 array<char, __formatter::__buffer_size<decltype(__value), 16>()> __array;
291 return __formatter::__format_integer(__value, __ctx, __specs, __negative, __array.begin(), __array.end(), "0X", 16);
292 }
293 default:
294 _LIBCPP_ASSERT(false, "The parse function should have validated the type");
295 __libcpp_unreachable();
373296 }
297}
374298
375#ifndef _LIBCPP_HAS_NO_LOCALIZATION
376 /** Format's the locale-specific form's groupings. */
377 template <class _OutIt, class _CharT>
378 _LIBCPP_HIDE_FROM_ABI _OutIt
379 __format_grouping(_OutIt __out_it, const char* __begin, const char* __first,
380 const char* __last, string&& __grouping, _CharT __sep) {
381
382 // TODO FMT This function duplicates some functionality of the normal
383 // output routines. Evaluate whether these parts can be efficiently
384 // combined with the existing routines.
385
386 unsigned __size = (__first - __begin) + // [sign][prefix]
387 (__last - __first) + // data
388 (__grouping.size() - 1); // number of separator characters
389
390 __formatter::__padding_size_result __padding = {0, 0};
391 if (this->__alignment == _Flags::_Alignment::__default) {
392 // Write [sign][prefix].
393 __out_it = _VSTD::copy(__begin, __first, _VSTD::move(__out_it));
394
395 if (this->__width > __size) {
396 // Write zero padding.
397 __padding.__before = this->__width - __size;
398 __out_it = _VSTD::fill_n(_VSTD::move(__out_it), this->__width - __size,
399 _CharT('0'));
400 }
401 } else {
402 if (this->__width > __size) {
403 // Determine padding and write padding.
404 __padding = __formatter::__padding_size(__size, this->__width,
405 this->__alignment);
406
407 __out_it = _VSTD::fill_n(_VSTD::move(__out_it), __padding.__before,
408 this->__fill);
409 }
410 // Write [sign][prefix].
411 __out_it = _VSTD::copy(__begin, __first, _VSTD::move(__out_it));
412 }
299template <signed_integral _Tp, class _CharT>
300_LIBCPP_HIDE_FROM_ABI auto
301__format_integer(_Tp __value, auto& __ctx, __format_spec::__parsed_specifications<_CharT> __specs)
302 -> decltype(__ctx.out()) {
303 // Depending on the std-format-spec string the sign and the value
304 // might not be outputted together:
305 // - alternate form may insert a prefix string.
306 // - zero-padding may insert additional '0' characters.
307 // Therefore the value is processed as a positive unsigned value.
308 // The function @ref __insert_sign will a '-' when the value was negative.
309 auto __r = std::__to_unsigned_like(__value);
310 bool __negative = __value < 0;
311 if (__negative)
312 __r = __complement(__r);
313
314 return __formatter::__format_integer(__r, __ctx, __specs, __negative);
315}
413316
414 auto __r = __grouping.rbegin();
415 auto __e = __grouping.rend() - 1;
416 _LIBCPP_ASSERT(__r != __e, "The slow grouping formatting is used while "
417 "there will be no separators written.");
418 // The output is divided in small groups of numbers to write:
419 // - A group before the first separator.
420 // - A separator and a group, repeated for the number of separators.
421 // - A group after the last separator.
422 // This loop achieves that process by testing the termination condition
423 // midway in the loop.
424 //
425 // TODO FMT This loop evaluates the loop invariant `this->__type !=
426 // _Flags::_Type::__hexadecimal_upper_case` for every iteration. (This test
427 // happens in the __write call.) Benchmark whether making two loops and
428 // hoisting the invariant is worth the effort.
429 while (true) {
430 if (this->__type == _Flags::_Type::__hexadecimal_upper_case) {
431 __last = __first + *__r;
432 __out_it = _VSTD::transform(__first, __last, _VSTD::move(__out_it),
433 __hex_to_upper);
434 __first = __last;
435 } else {
436 __out_it = _VSTD::copy_n(__first, *__r, _VSTD::move(__out_it));
437 __first += *__r;
438 }
439
440 if (__r == __e)
441 break;
442
443 ++__r;
444 *__out_it++ = __sep;
445 }
317//
318// Formatter arithmetic (bool)
319//
446320
447 return _VSTD::fill_n(_VSTD::move(__out_it), __padding.__after,
448 this->__fill);
449 }
450#endif // _LIBCPP_HAS_NO_LOCALIZATION
321template <class _CharT>
322struct _LIBCPP_TEMPLATE_VIS __bool_strings;
323
324template <>
325struct _LIBCPP_TEMPLATE_VIS __bool_strings<char> {
326 static constexpr string_view __true{"true"};
327 static constexpr string_view __false{"false"};
451328};
452329
453} // namespace __format_spec
330# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
331template <>
332struct _LIBCPP_TEMPLATE_VIS __bool_strings<wchar_t> {
333 static constexpr wstring_view __true{L"true"};
334 static constexpr wstring_view __false{L"false"};
335};
336# endif
337
338template <class _CharT>
339_LIBCPP_HIDE_FROM_ABI auto
340__format_bool(bool __value, auto& __ctx, __format_spec::__parsed_specifications<_CharT> __specs)
341 -> decltype(__ctx.out()) {
342# ifndef _LIBCPP_HAS_NO_LOCALIZATION
343 if (__specs.__std_.__locale_specific_form_) {
344 const auto& __np = use_facet<numpunct<_CharT>>(__ctx.locale());
345 basic_string<_CharT> __str = __value ? __np.truename() : __np.falsename();
346 return __formatter::__write_string_no_precision(basic_string_view<_CharT>{__str}, __ctx.out(), __specs);
347 }
348# endif
349 basic_string_view<_CharT> __str =
350 __value ? __formatter::__bool_strings<_CharT>::__true : __formatter::__bool_strings<_CharT>::__false;
351 return __formatter::__write(__str.begin(), __str.end(), __ctx.out(), __specs);
352}
454353
455#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
354} // namespace __formatter
456355
457356#endif //_LIBCPP_STD_VER > 17
458357
lib/libcxx/include/__format/formatter_output.h created+308
......@@ -0,0 +1,308 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___FORMAT_FORMATTER_OUTPUT_H
11#define _LIBCPP___FORMAT_FORMATTER_OUTPUT_H
12
13#include <__algorithm/copy.h>
14#include <__algorithm/copy_n.h>
15#include <__algorithm/fill_n.h>
16#include <__algorithm/transform.h>
17#include <__config>
18#include <__format/formatter.h>
19#include <__format/parser_std_format_spec.h>
20#include <__format/unicode.h>
21#include <__utility/move.h>
22#include <__utility/unreachable.h>
23#include <cstddef>
24#include <string>
25#include <string_view>
26
27#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
28# pragma GCC system_header
29#endif
30
31_LIBCPP_BEGIN_NAMESPACE_STD
32
33#if _LIBCPP_STD_VER > 17
34
35namespace __formatter {
36
37_LIBCPP_HIDE_FROM_ABI constexpr char __hex_to_upper(char __c) {
38 switch (__c) {
39 case 'a':
40 return 'A';
41 case 'b':
42 return 'B';
43 case 'c':
44 return 'C';
45 case 'd':
46 return 'D';
47 case 'e':
48 return 'E';
49 case 'f':
50 return 'F';
51 }
52 return __c;
53}
54
55struct _LIBCPP_TYPE_VIS __padding_size_result {
56 size_t __before_;
57 size_t __after_;
58};
59
60_LIBCPP_HIDE_FROM_ABI constexpr __padding_size_result
61__padding_size(size_t __size, size_t __width, __format_spec::__alignment __align) {
62 _LIBCPP_ASSERT(__width > __size, "don't call this function when no padding is required");
63 _LIBCPP_ASSERT(
64 __align != __format_spec::__alignment::__zero_padding, "the caller should have handled the zero-padding");
65
66 size_t __fill = __width - __size;
67 switch (__align) {
68 case __format_spec::__alignment::__zero_padding:
69 __libcpp_unreachable();
70
71 case __format_spec::__alignment::__left:
72 return {0, __fill};
73
74 case __format_spec::__alignment::__center: {
75 // The extra padding is divided per [format.string.std]/3
76 // __before = floor(__fill, 2);
77 // __after = ceil(__fill, 2);
78 size_t __before = __fill / 2;
79 size_t __after = __fill - __before;
80 return {__before, __after};
81 }
82 case __format_spec::__alignment::__default:
83 case __format_spec::__alignment::__right:
84 return {__fill, 0};
85 }
86 __libcpp_unreachable();
87}
88
89template <class _OutIt, class _CharT>
90_LIBCPP_HIDE_FROM_ABI _OutIt __write_using_decimal_separators(_OutIt __out_it, const char* __begin, const char* __first,
91 const char* __last, string&& __grouping, _CharT __sep,
92 __format_spec::__parsed_specifications<_CharT> __specs) {
93 int __size = (__first - __begin) + // [sign][prefix]
94 (__last - __first) + // data
95 (__grouping.size() - 1); // number of separator characters
96
97 __padding_size_result __padding = {0, 0};
98 if (__specs.__alignment_ == __format_spec::__alignment::__zero_padding) {
99 // Write [sign][prefix].
100 __out_it = _VSTD::copy(__begin, __first, _VSTD::move(__out_it));
101
102 if (__specs.__width_ > __size) {
103 // Write zero padding.
104 __padding.__before_ = __specs.__width_ - __size;
105 __out_it = _VSTD::fill_n(_VSTD::move(__out_it), __specs.__width_ - __size, _CharT('0'));
106 }
107 } else {
108 if (__specs.__width_ > __size) {
109 // Determine padding and write padding.
110 __padding = __padding_size(__size, __specs.__width_, __specs.__alignment_);
111
112 __out_it = _VSTD::fill_n(_VSTD::move(__out_it), __padding.__before_, __specs.__fill_);
113 }
114 // Write [sign][prefix].
115 __out_it = _VSTD::copy(__begin, __first, _VSTD::move(__out_it));
116 }
117
118 auto __r = __grouping.rbegin();
119 auto __e = __grouping.rend() - 1;
120 _LIBCPP_ASSERT(__r != __e, "The slow grouping formatting is used while "
121 "there will be no separators written.");
122 // The output is divided in small groups of numbers to write:
123 // - A group before the first separator.
124 // - A separator and a group, repeated for the number of separators.
125 // - A group after the last separator.
126 // This loop achieves that process by testing the termination condition
127 // midway in the loop.
128 //
129 // TODO FMT This loop evaluates the loop invariant `__parser.__type !=
130 // _Flags::_Type::__hexadecimal_upper_case` for every iteration. (This test
131 // happens in the __write call.) Benchmark whether making two loops and
132 // hoisting the invariant is worth the effort.
133 while (true) {
134 if (__specs.__std_.__type_ == __format_spec::__type::__hexadecimal_upper_case) {
135 __last = __first + *__r;
136 __out_it = _VSTD::transform(__first, __last, _VSTD::move(__out_it), __hex_to_upper);
137 __first = __last;
138 } else {
139 __out_it = _VSTD::copy_n(__first, *__r, _VSTD::move(__out_it));
140 __first += *__r;
141 }
142
143 if (__r == __e)
144 break;
145
146 ++__r;
147 *__out_it++ = __sep;
148 }
149
150 return _VSTD::fill_n(_VSTD::move(__out_it), __padding.__after_, __specs.__fill_);
151}
152
153/// Writes the input to the output with the required padding.
154///
155/// Since the output column width is specified the function can be used for
156/// ASCII and Unicode output.
157///
158/// \pre [\a __first, \a __last) is a valid range.
159/// \pre \a __size <= \a __width. Using this function when this pre-condition
160/// doesn't hold incurs an unwanted overhead.
161///
162/// \param __first Pointer to the first element to write.
163/// \param __last Pointer beyond the last element to write.
164/// \param __out_it The output iterator to write to.
165/// \param __specs The parsed formatting specifications.
166/// \param __size The (estimated) output column width. When the elements
167/// to be written are ASCII the following condition holds
168/// \a __size == \a __last - \a __first.
169///
170/// \returns An iterator pointing beyond the last element written.
171///
172/// \note The type of the elements in range [\a __first, \a __last) can differ
173/// from the type of \a __specs. Integer output uses \c std::to_chars for its
174/// conversion, which means the [\a __first, \a __last) always contains elements
175/// of the type \c char.
176template <class _CharT, class _ParserCharT>
177_LIBCPP_HIDE_FROM_ABI auto __write(
178 const _CharT* __first,
179 const _CharT* __last,
180 output_iterator<const _CharT&> auto __out_it,
181 __format_spec::__parsed_specifications<_ParserCharT> __specs,
182 ptrdiff_t __size) -> decltype(__out_it) {
183 _LIBCPP_ASSERT(__first <= __last, "Not a valid range");
184
185 if (__size >= __specs.__width_)
186 return _VSTD::copy(__first, __last, _VSTD::move(__out_it));
187
188 __padding_size_result __padding = __formatter::__padding_size(__size, __specs.__width_, __specs.__std_.__alignment_);
189 __out_it = _VSTD::fill_n(_VSTD::move(__out_it), __padding.__before_, __specs.__fill_);
190 __out_it = _VSTD::copy(__first, __last, _VSTD::move(__out_it));
191 return _VSTD::fill_n(_VSTD::move(__out_it), __padding.__after_, __specs.__fill_);
192}
193
194/// \overload
195///
196/// Calls the function above where \a __size = \a __last - \a __first.
197template <class _CharT, class _ParserCharT>
198_LIBCPP_HIDE_FROM_ABI auto __write(const _CharT* __first, const _CharT* __last,
199 output_iterator<const _CharT&> auto __out_it,
200 __format_spec::__parsed_specifications<_ParserCharT> __specs) -> decltype(__out_it) {
201 return __write(__first, __last, _VSTD::move(__out_it), __specs, __last - __first);
202}
203
204template <class _CharT, class _ParserCharT, class _UnaryOperation>
205_LIBCPP_HIDE_FROM_ABI auto __write_transformed(const _CharT* __first, const _CharT* __last,
206 output_iterator<const _CharT&> auto __out_it,
207 __format_spec::__parsed_specifications<_ParserCharT> __specs,
208 _UnaryOperation __op) -> decltype(__out_it) {
209 _LIBCPP_ASSERT(__first <= __last, "Not a valid range");
210
211 ptrdiff_t __size = __last - __first;
212 if (__size >= __specs.__width_)
213 return _VSTD::transform(__first, __last, _VSTD::move(__out_it), __op);
214
215 __padding_size_result __padding = __padding_size(__size, __specs.__width_, __specs.__alignment_);
216 __out_it = _VSTD::fill_n(_VSTD::move(__out_it), __padding.__before_, __specs.__fill_);
217 __out_it = _VSTD::transform(__first, __last, _VSTD::move(__out_it), __op);
218 return _VSTD::fill_n(_VSTD::move(__out_it), __padding.__after_, __specs.__fill_);
219}
220
221/// Writes additional zero's for the precision before the exponent.
222/// This is used when the precision requested in the format string is larger
223/// than the maximum precision of the floating-point type. These precision
224/// digits are always 0.
225///
226/// \param __exponent The location of the exponent character.
227/// \param __num_trailing_zeros The number of 0's to write before the exponent
228/// character.
229template <class _CharT, class _ParserCharT>
230_LIBCPP_HIDE_FROM_ABI auto __write_using_trailing_zeros(
231 const _CharT* __first,
232 const _CharT* __last,
233 output_iterator<const _CharT&> auto __out_it,
234 __format_spec::__parsed_specifications<_ParserCharT> __specs,
235 size_t __size,
236 const _CharT* __exponent,
237 size_t __num_trailing_zeros) -> decltype(__out_it) {
238 _LIBCPP_ASSERT(__first <= __last, "Not a valid range");
239 _LIBCPP_ASSERT(__num_trailing_zeros > 0, "The overload not writing trailing zeros should have been used");
240
241 __padding_size_result __padding =
242 __padding_size(__size + __num_trailing_zeros, __specs.__width_, __specs.__alignment_);
243 __out_it = _VSTD::fill_n(_VSTD::move(__out_it), __padding.__before_, __specs.__fill_);
244 __out_it = _VSTD::copy(__first, __exponent, _VSTD::move(__out_it));
245 __out_it = _VSTD::fill_n(_VSTD::move(__out_it), __num_trailing_zeros, _CharT('0'));
246 __out_it = _VSTD::copy(__exponent, __last, _VSTD::move(__out_it));
247 return _VSTD::fill_n(_VSTD::move(__out_it), __padding.__after_, __specs.__fill_);
248}
249
250/// Writes a string using format's width estimation algorithm.
251///
252/// \pre !__specs.__has_precision()
253///
254/// \note When \c _LIBCPP_HAS_NO_UNICODE is defined the function assumes the
255/// input is ASCII.
256template <class _CharT>
257_LIBCPP_HIDE_FROM_ABI auto __write_string_no_precision(
258 basic_string_view<_CharT> __str,
259 output_iterator<const _CharT&> auto __out_it,
260 __format_spec::__parsed_specifications<_CharT> __specs) -> decltype(__out_it) {
261 _LIBCPP_ASSERT(!__specs.__has_precision(), "use __write_string");
262
263 // No padding -> copy the string
264 if (!__specs.__has_width())
265 return _VSTD::copy(__str.begin(), __str.end(), _VSTD::move(__out_it));
266
267 // Note when the estimated width is larger than size there's no padding. So
268 // there's no reason to get the real size when the estimate is larger than or
269 // equal to the minimum field width.
270 size_t __size =
271 __format_spec::__estimate_column_width(__str, __specs.__width_, __format_spec::__column_width_rounding::__up)
272 .__width_;
273
274 return __formatter::__write(__str.begin(), __str.end(), _VSTD::move(__out_it), __specs, __size);
275}
276
277template <class _CharT>
278_LIBCPP_HIDE_FROM_ABI int __truncate(basic_string_view<_CharT>& __str, int __precision) {
279 __format_spec::__column_width_result<_CharT> __result =
280 __format_spec::__estimate_column_width(__str, __precision, __format_spec::__column_width_rounding::__down);
281 __str = basic_string_view<_CharT>{__str.begin(), __result.__last_};
282 return __result.__width_;
283}
284
285/// Writes a string using format's width estimation algorithm.
286///
287/// \note When \c _LIBCPP_HAS_NO_UNICODE is defined the function assumes the
288/// input is ASCII.
289template <class _CharT>
290_LIBCPP_HIDE_FROM_ABI auto __write_string(
291 basic_string_view<_CharT> __str,
292 output_iterator<const _CharT&> auto __out_it,
293 __format_spec::__parsed_specifications<_CharT> __specs) -> decltype(__out_it) {
294 if (!__specs.__has_precision())
295 return __formatter::__write_string_no_precision(__str, _VSTD::move(__out_it), __specs);
296
297 int __size = __formatter::__truncate(__str, __specs.__precision_);
298
299 return __write(__str.begin(), __str.end(), _VSTD::move(__out_it), __specs, __size);
300}
301
302} // namespace __formatter
303
304#endif //_LIBCPP_STD_VER > 17
305
306_LIBCPP_END_NAMESPACE_STD
307
308#endif // _LIBCPP___FORMAT_FORMATTER_OUTPUT_H
lib/libcxx/include/__format/formatter_pointer.h+22-40
......@@ -10,17 +10,15 @@
1010#ifndef _LIBCPP___FORMAT_FORMATTER_POINTER_H
1111#define _LIBCPP___FORMAT_FORMATTER_POINTER_H
1212
13#include <__algorithm/copy.h>
1413#include <__availability>
1514#include <__config>
16#include <__debug>
17#include <__format/format_error.h>
1815#include <__format/format_fwd.h>
16#include <__format/format_parse_context.h>
1917#include <__format/formatter.h>
2018#include <__format/formatter_integral.h>
19#include <__format/formatter_output.h>
2120#include <__format/parser_std_format_spec.h>
22#include <__iterator/access.h>
23#include <__nullptr>
21#include <cstddef>
2422#include <cstdint>
2523
2624#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -31,41 +29,27 @@ _LIBCPP_BEGIN_NAMESPACE_STD
3129
3230#if _LIBCPP_STD_VER > 17
3331
34// TODO FMT Remove this once we require compilers with proper C++20 support.
35// If the compiler has no concepts support, the format header will be disabled.
36// Without concepts support enable_if needs to be used and that too much effort
37// to support compilers with partial C++20 support.
38# if !defined(_LIBCPP_HAS_NO_CONCEPTS)
39
40namespace __format_spec {
41
4232template <__formatter::__char_type _CharT>
43class _LIBCPP_TEMPLATE_VIS __formatter_pointer : public __parser_pointer<_CharT> {
33struct _LIBCPP_TEMPLATE_VIS __formatter_pointer {
4434public:
45 _LIBCPP_HIDE_FROM_ABI auto format(const void* __ptr, auto& __ctx) -> decltype(__ctx.out()) {
46 _LIBCPP_ASSERT(this->__alignment != _Flags::_Alignment::__default,
47 "The call to parse should have updated the alignment");
48 if (this->__width_needs_substitution())
49 this->__substitute_width_arg_id(__ctx.arg(this->__width));
35 constexpr __formatter_pointer() { __parser_.__alignment_ = __format_spec::__alignment::__right; }
5036
51 // This code looks a lot like the code to format a hexadecimal integral,
52 // but that code isn't public. Making that code public requires some
53 // refactoring.
54 // TODO FMT Remove code duplication.
55 char __buffer[2 + 2 * sizeof(uintptr_t)];
56 __buffer[0] = '0';
57 __buffer[1] = 'x';
58 char* __last = __to_buffer(__buffer + 2, _VSTD::end(__buffer), reinterpret_cast<uintptr_t>(__ptr), 16);
59
60 unsigned __size = __last - __buffer;
61 if (__size >= this->__width)
62 return _VSTD::copy(__buffer, __last, __ctx.out());
37 _LIBCPP_HIDE_FROM_ABI constexpr auto
38 parse(basic_format_parse_context<_CharT>& __parse_ctx) -> decltype(__parse_ctx.begin()) {
39 auto __result = __parser_.__parse(__parse_ctx, __format_spec::__fields_pointer);
40 __format_spec::__process_display_type_pointer(__parser_.__type_);
41 return __result;
42 }
6343
64 return __formatter::__write(__ctx.out(), __buffer, __last, __size, this->__width, this->__fill, this->__alignment);
44 _LIBCPP_HIDE_FROM_ABI auto format(const void* __ptr, auto& __ctx) const -> decltype(__ctx.out()) {
45 __format_spec::__parsed_specifications<_CharT> __specs = __parser_.__get_parsed_std_specifications(__ctx);
46 __specs.__std_.__alternate_form_ = true;
47 __specs.__std_.__type_ = __format_spec::__type::__hexadecimal_lower_case;
48 return __formatter::__format_integer(reinterpret_cast<uintptr_t>(__ptr), __ctx, __specs);
6549 }
66};
6750
68} // namespace __format_spec
51 __format_spec::__parser<_CharT> __parser_;
52};
6953
7054// [format.formatter.spec]/2.4
7155// For each charT, the pointer type specializations template<>
......@@ -74,15 +58,13 @@ public:
7458// - template<> struct formatter<const void*, charT>;
7559template <__formatter::__char_type _CharT>
7660struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<nullptr_t, _CharT>
77 : public __format_spec::__formatter_pointer<_CharT> {};
61 : public __formatter_pointer<_CharT> {};
7862template <__formatter::__char_type _CharT>
79struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<void*, _CharT>
80 : public __format_spec::__formatter_pointer<_CharT> {};
63struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<void*, _CharT> : public __formatter_pointer<_CharT> {
64};
8165template <__formatter::__char_type _CharT>
8266struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<const void*, _CharT>
83 : public __format_spec::__formatter_pointer<_CharT> {};
84
85# endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
67 : public __formatter_pointer<_CharT> {};
8668
8769#endif //_LIBCPP_STD_VER > 17
8870
lib/libcxx/include/__format/formatter_string.h+51-68
......@@ -10,68 +10,49 @@
1010#ifndef _LIBCPP___FORMAT_FORMATTER_STRING_H
1111#define _LIBCPP___FORMAT_FORMATTER_STRING_H
1212
13#include <__availability>
1314#include <__config>
14#include <__format/format_error.h>
1515#include <__format/format_fwd.h>
16#include <__format/format_string.h>
16#include <__format/format_parse_context.h>
1717#include <__format/formatter.h>
18#include <__format/formatter_output.h>
1819#include <__format/parser_std_format_spec.h>
20#include <__utility/move.h>
21#include <string>
1922#include <string_view>
2023
2124#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22#pragma GCC system_header
25# pragma GCC system_header
2326#endif
2427
25_LIBCPP_PUSH_MACROS
26#include <__undef_macros>
27
2828_LIBCPP_BEGIN_NAMESPACE_STD
2929
3030#if _LIBCPP_STD_VER > 17
3131
32// TODO FMT Remove this once we require compilers with proper C++20 support.
33// If the compiler has no concepts support, the format header will be disabled.
34// Without concepts support enable_if needs to be used and that too much effort
35// to support compilers with partial C++20 support.
36#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
37
38namespace __format_spec {
39
4032template <__formatter::__char_type _CharT>
41class _LIBCPP_TEMPLATE_VIS __formatter_string : public __parser_string<_CharT> {
33struct _LIBCPP_TEMPLATE_VIS __formatter_string {
4234public:
43 _LIBCPP_HIDE_FROM_ABI auto format(basic_string_view<_CharT> __str,
44 auto& __ctx) -> decltype(__ctx.out()) {
45
46 _LIBCPP_ASSERT(this->__alignment != _Flags::_Alignment::__default,
47 "The parser should not use these defaults");
48
49 if (this->__width_needs_substitution())
50 this->__substitute_width_arg_id(__ctx.arg(this->__width));
51
52 if (this->__precision_needs_substitution())
53 this->__substitute_precision_arg_id(__ctx.arg(this->__precision));
54
55 return __formatter::__write_unicode(
56 __ctx.out(), __str, this->__width,
57 this->__has_precision_field() ? this->__precision : -1, this->__fill,
58 this->__alignment);
35 _LIBCPP_HIDE_FROM_ABI constexpr auto parse(basic_format_parse_context<_CharT>& __parse_ctx)
36 -> decltype(__parse_ctx.begin()) {
37 auto __result = __parser_.__parse(__parse_ctx, __format_spec::__fields_string);
38 __format_spec::__process_display_type_string(__parser_.__type_);
39 return __result;
5940 }
60};
6141
62} //namespace __format_spec
42 _LIBCPP_HIDE_FROM_ABI auto format(basic_string_view<_CharT> __str, auto& __ctx) const -> decltype(__ctx.out()) {
43 return __formatter::__write_string(__str, __ctx.out(), __parser_.__get_parsed_std_specifications(__ctx));
44 }
6345
64// [format.formatter.spec]/2.2 For each charT, the string type specializations
46 __format_spec::__parser<_CharT> __parser_;
47};
6548
6649// Formatter const char*.
6750template <__formatter::__char_type _CharT>
68struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT
69 formatter<const _CharT*, _CharT>
70 : public __format_spec::__formatter_string<_CharT> {
71 using _Base = __format_spec::__formatter_string<_CharT>;
51struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<const _CharT*, _CharT>
52 : public __formatter_string<_CharT> {
53 using _Base = __formatter_string<_CharT>;
7254
73 _LIBCPP_HIDE_FROM_ABI auto format(const _CharT* __str, auto& __ctx)
74 -> decltype(__ctx.out()) {
55 _LIBCPP_HIDE_FROM_ABI auto format(const _CharT* __str, auto& __ctx) const -> decltype(__ctx.out()) {
7556 _LIBCPP_ASSERT(__str, "The basic_format_arg constructor should have "
7657 "prevented an invalid pointer.");
7758
......@@ -86,8 +67,9 @@ struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT
8667 // now these optimizations aren't implemented. Instead the base class
8768 // handles these options.
8869 // TODO FMT Implement these improvements.
89 if (this->__has_width_field() || this->__has_precision_field())
90 return _Base::format(__str, __ctx);
70 __format_spec::__parsed_specifications<_CharT> __specs = _Base::__parser_.__get_parsed_std_specifications(__ctx);
71 if (__specs.__has_width() || __specs.__has_precision())
72 return __formatter::__write_string(basic_string_view<_CharT>{__str}, __ctx.out(), __specs);
9173
9274 // No formatting required, copy the string to the output.
9375 auto __out_it = __ctx.out();
......@@ -99,40 +81,46 @@ struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT
9981
10082// Formatter char*.
10183template <__formatter::__char_type _CharT>
102struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT
103 formatter<_CharT*, _CharT> : public formatter<const _CharT*, _CharT> {
84struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<_CharT*, _CharT>
85 : public formatter<const _CharT*, _CharT> {
10486 using _Base = formatter<const _CharT*, _CharT>;
10587
106 _LIBCPP_HIDE_FROM_ABI auto format(_CharT* __str, auto& __ctx)
107 -> decltype(__ctx.out()) {
88 _LIBCPP_HIDE_FROM_ABI auto format(_CharT* __str, auto& __ctx) const -> decltype(__ctx.out()) {
10889 return _Base::format(__str, __ctx);
10990 }
11091};
11192
93// Formatter char[].
94template <__formatter::__char_type _CharT, size_t _Size>
95struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<_CharT[_Size], _CharT>
96 : public __formatter_string<_CharT> {
97 using _Base = __formatter_string<_CharT>;
98
99 _LIBCPP_HIDE_FROM_ABI auto format(_CharT __str[_Size], auto& __ctx) const -> decltype(__ctx.out()) {
100 return _Base::format(basic_string_view<_CharT>(__str, _Size), __ctx);
101 }
102};
103
112104// Formatter const char[].
113105template <__formatter::__char_type _CharT, size_t _Size>
114struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT
115 formatter<const _CharT[_Size], _CharT>
116 : public __format_spec::__formatter_string<_CharT> {
117 using _Base = __format_spec::__formatter_string<_CharT>;
106struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<const _CharT[_Size], _CharT>
107 : public __formatter_string<_CharT> {
108 using _Base = __formatter_string<_CharT>;
118109
119 _LIBCPP_HIDE_FROM_ABI auto format(const _CharT __str[_Size], auto& __ctx)
120 -> decltype(__ctx.out()) {
110 _LIBCPP_HIDE_FROM_ABI auto format(const _CharT __str[_Size], auto& __ctx) const -> decltype(__ctx.out()) {
121111 return _Base::format(basic_string_view<_CharT>(__str, _Size), __ctx);
122112 }
123113};
124114
125115// Formatter std::string.
126116template <__formatter::__char_type _CharT, class _Traits, class _Allocator>
127struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT
128 formatter<basic_string<_CharT, _Traits, _Allocator>, _CharT>
129 : public __format_spec::__formatter_string<_CharT> {
130 using _Base = __format_spec::__formatter_string<_CharT>;
117struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<basic_string<_CharT, _Traits, _Allocator>, _CharT>
118 : public __formatter_string<_CharT> {
119 using _Base = __formatter_string<_CharT>;
131120
132 _LIBCPP_HIDE_FROM_ABI auto
133 format(const basic_string<_CharT, _Traits, _Allocator>& __str, auto& __ctx)
121 _LIBCPP_HIDE_FROM_ABI auto format(const basic_string<_CharT, _Traits, _Allocator>& __str, auto& __ctx) const
134122 -> decltype(__ctx.out()) {
135 // drop _Traits and _Allocator
123 // Drop _Traits and _Allocator to have one std::basic_string formatter.
136124 return _Base::format(basic_string_view<_CharT>(__str.data(), __str.size()), __ctx);
137125 }
138126};
......@@ -140,23 +128,18 @@ struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT
140128// Formatter std::string_view.
141129template <__formatter::__char_type _CharT, class _Traits>
142130struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<basic_string_view<_CharT, _Traits>, _CharT>
143 : public __format_spec::__formatter_string<_CharT> {
144 using _Base = __format_spec::__formatter_string<_CharT>;
131 : public __formatter_string<_CharT> {
132 using _Base = __formatter_string<_CharT>;
145133
146 _LIBCPP_HIDE_FROM_ABI auto
147 format(basic_string_view<_CharT, _Traits> __str, auto& __ctx)
134 _LIBCPP_HIDE_FROM_ABI auto format(basic_string_view<_CharT, _Traits> __str, auto& __ctx) const
148135 -> decltype(__ctx.out()) {
149 // drop _Traits
136 // Drop _Traits to have one std::basic_string_view formatter.
150137 return _Base::format(basic_string_view<_CharT>(__str.data(), __str.size()), __ctx);
151138 }
152139};
153140
154#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
155
156141#endif //_LIBCPP_STD_VER > 17
157142
158143_LIBCPP_END_NAMESPACE_STD
159144
160_LIBCPP_POP_MACROS
161
162145#endif // _LIBCPP___FORMAT_FORMATTER_STRING_H
lib/libcxx/include/__format/parser_std_format_spec.h+677-1169
......@@ -10,21 +10,31 @@
1010#ifndef _LIBCPP___FORMAT_PARSER_STD_FORMAT_SPEC_H
1111#define _LIBCPP___FORMAT_PARSER_STD_FORMAT_SPEC_H
1212
13/// \file Contains the std-format-spec parser.
14///
15/// Most of the code can be reused in the chrono-format-spec.
16/// This header has some support for the chrono-format-spec since it doesn't
17/// affect the std-format-spec.
18
1319#include <__algorithm/find_if.h>
1420#include <__algorithm/min.h>
21#include <__assert>
1522#include <__config>
1623#include <__debug>
1724#include <__format/format_arg.h>
1825#include <__format/format_error.h>
26#include <__format/format_parse_context.h>
1927#include <__format/format_string.h>
28#include <__format/unicode.h>
2029#include <__variant/monostate.h>
2130#include <bit>
2231#include <concepts>
2332#include <cstdint>
33#include <string_view>
2434#include <type_traits>
2535
2636#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
27# pragma GCC system_header
37# pragma GCC system_header
2838#endif
2939
3040_LIBCPP_PUSH_MACROS
......@@ -34,174 +44,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD
3444
3545#if _LIBCPP_STD_VER > 17
3646
37// TODO FMT Remove this once we require compilers with proper C++20 support.
38// If the compiler has no concepts support, the format header will be disabled.
39// Without concepts support enable_if needs to be used and that too much effort
40// to support compilers with partial C++20 support.
41# if !defined(_LIBCPP_HAS_NO_CONCEPTS)
42
4347namespace __format_spec {
4448
45/**
46 * Contains the flags for the std-format-spec.
47 *
48 * Some format-options can only be used for specific C++types and may depend on
49 * the selected format-type.
50 * * The C++type filtering can be done using the proper policies for
51 * @ref __parser_std.
52 * * The format-type filtering needs to be done post parsing in the parser
53 * derived from @ref __parser_std.
54 */
55class _LIBCPP_TYPE_VIS _Flags {
56public:
57 enum class _LIBCPP_ENUM_VIS _Alignment : uint8_t {
58 /**
59 * No alignment is set in the format string.
60 *
61 * Zero-padding is ignored when an alignment is selected.
62 * The default alignment depends on the selected format-type.
63 */
64 __default,
65 __left,
66 __center,
67 __right
68 };
69 enum class _LIBCPP_ENUM_VIS _Sign : uint8_t {
70 /**
71 * No sign is set in the format string.
72 *
73 * The sign isn't allowed for certain format-types. By using this value
74 * it's possible to detect whether or not the user explicitly set the sign
75 * flag. For formatting purposes it behaves the same as @ref __minus.
76 */
77 __default,
78 __minus,
79 __plus,
80 __space
81 };
82
83 _Alignment __alignment : 2 {_Alignment::__default};
84 _Sign __sign : 2 {_Sign::__default};
85 uint8_t __alternate_form : 1 {false};
86 uint8_t __zero_padding : 1 {false};
87 uint8_t __locale_specific_form : 1 {false};
88
89 enum class _LIBCPP_ENUM_VIS _Type : uint8_t {
90 __default,
91 __string,
92 __binary_lower_case,
93 __binary_upper_case,
94 __octal,
95 __decimal,
96 __hexadecimal_lower_case,
97 __hexadecimal_upper_case,
98 __pointer,
99 __char,
100 __float_hexadecimal_lower_case,
101 __float_hexadecimal_upper_case,
102 __scientific_lower_case,
103 __scientific_upper_case,
104 __fixed_lower_case,
105 __fixed_upper_case,
106 __general_lower_case,
107 __general_upper_case
108 };
109
110 _Type __type{_Type::__default};
111};
112
113namespace __detail {
114template <class _CharT>
115_LIBCPP_HIDE_FROM_ABI constexpr bool
116__parse_alignment(_CharT __c, _Flags& __flags) noexcept {
117 switch (__c) {
118 case _CharT('<'):
119 __flags.__alignment = _Flags::_Alignment::__left;
120 return true;
121
122 case _CharT('^'):
123 __flags.__alignment = _Flags::_Alignment::__center;
124 return true;
125
126 case _CharT('>'):
127 __flags.__alignment = _Flags::_Alignment::__right;
128 return true;
129 }
130 return false;
131}
132} // namespace __detail
133
134template <class _CharT>
135class _LIBCPP_TEMPLATE_VIS __parser_fill_align {
136public:
137 // TODO FMT The standard doesn't specify this character is a Unicode
138 // character. Validate what fmt and MSVC have implemented.
139 _CharT __fill{_CharT(' ')};
140
141protected:
142 _LIBCPP_HIDE_FROM_ABI constexpr const _CharT*
143 __parse(const _CharT* __begin, const _CharT* __end, _Flags& __flags) {
144 _LIBCPP_ASSERT(__begin != __end,
145 "When called with an empty input the function will cause "
146 "undefined behavior by evaluating data not in the input");
147 if (__begin + 1 != __end) {
148 if (__detail::__parse_alignment(*(__begin + 1), __flags)) {
149 if (*__begin == _CharT('{') || *__begin == _CharT('}'))
150 __throw_format_error(
151 "The format-spec fill field contains an invalid character");
152 __fill = *__begin;
153 return __begin + 2;
154 }
155 }
156
157 if (__detail::__parse_alignment(*__begin, __flags))
158 return __begin + 1;
159
160 return __begin;
161 }
162};
163
164template <class _CharT>
165_LIBCPP_HIDE_FROM_ABI constexpr const _CharT*
166__parse_sign(const _CharT* __begin, _Flags& __flags) noexcept {
167 switch (*__begin) {
168 case _CharT('-'):
169 __flags.__sign = _Flags::_Sign::__minus;
170 break;
171 case _CharT('+'):
172 __flags.__sign = _Flags::_Sign::__plus;
173 break;
174 case _CharT(' '):
175 __flags.__sign = _Flags::_Sign::__space;
176 break;
177 default:
178 return __begin;
179 }
180 return __begin + 1;
181}
182
183template <class _CharT>
184_LIBCPP_HIDE_FROM_ABI constexpr const _CharT*
185__parse_alternate_form(const _CharT* __begin, _Flags& __flags) noexcept {
186 if (*__begin == _CharT('#')) {
187 __flags.__alternate_form = true;
188 ++__begin;
189 }
190
191 return __begin;
192}
193
194template <class _CharT>
195_LIBCPP_HIDE_FROM_ABI constexpr const _CharT*
196__parse_zero_padding(const _CharT* __begin, _Flags& __flags) noexcept {
197 if (*__begin == _CharT('0')) {
198 __flags.__zero_padding = true;
199 ++__begin;
200 }
201
202 return __begin;
203}
204
20549template <class _CharT>
20650_LIBCPP_HIDE_FROM_ABI constexpr __format::__parse_number_result< _CharT>
20751__parse_arg_id(const _CharT* __begin, const _CharT* __end, auto& __parse_ctx) {
......@@ -222,7 +66,7 @@ __parse_arg_id(const _CharT* __begin, const _CharT* __end, auto& __parse_ctx) {
22266
22367template <class _Context>
22468_LIBCPP_HIDE_FROM_ABI constexpr uint32_t
225__substitute_arg_id(basic_format_arg<_Context> __arg) {
69__substitute_arg_id(basic_format_arg<_Context> __format_arg) {
22670 return visit_format_arg(
22771 [](auto __arg) -> uint32_t {
22872 using _Type = decltype(__arg);
......@@ -246,803 +90,638 @@ __substitute_arg_id(basic_format_arg<_Context> __arg) {
24690 __throw_format_error("A format-spec arg-id replacement argument "
24791 "isn't an integral type");
24892 },
249 __arg);
93 __format_arg);
25094}
25195
252class _LIBCPP_TYPE_VIS __parser_width {
253public:
254 /** Contains a width or an arg-id. */
255 uint32_t __width : 31 {0};
256 /** Determines whether the value stored is a width or an arg-id. */
257 uint32_t __width_as_arg : 1 {0};
258
259protected:
260 /**
261 * Does the supplied std-format-spec contain a width field?
262 *
263 * When the field isn't present there's no padding required. This can be used
264 * to optimize the formatting.
265 */
266 constexpr bool __has_width_field() const noexcept {
267 return __width_as_arg || __width;
268 }
269
270 /**
271 * Does the supplied width field contain an arg-id?
272 *
273 * If @c true the formatter needs to call @ref __substitute_width_arg_id.
274 */
275 constexpr bool __width_needs_substitution() const noexcept {
276 return __width_as_arg;
277 }
278
279 template <class _CharT>
280 _LIBCPP_HIDE_FROM_ABI constexpr const _CharT*
281 __parse(const _CharT* __begin, const _CharT* __end, auto& __parse_ctx) {
282 if (*__begin == _CharT('0'))
283 __throw_format_error(
284 "A format-spec width field shouldn't have a leading zero");
285
286 if (*__begin == _CharT('{')) {
287 __format::__parse_number_result __r =
288 __parse_arg_id(++__begin, __end, __parse_ctx);
289 __width = __r.__value;
290 __width_as_arg = 1;
291 return __r.__ptr;
292 }
96/// These fields are a filter for which elements to parse.
97///
98/// They default to false so when a new field is added it needs to be opted in
99/// explicitly.
100struct __fields {
101 uint8_t __sign_ : 1 {false};
102 uint8_t __alternate_form_ : 1 {false};
103 uint8_t __zero_padding_ : 1 {false};
104 uint8_t __precision_ : 1 {false};
105 uint8_t __locale_specific_form_ : 1 {false};
106 uint8_t __type_ : 1 {false};
107};
293108
294 if (*__begin < _CharT('0') || *__begin > _CharT('9'))
295 return __begin;
109// By not placing this constant in the formatter class it's not duplicated for
110// char and wchar_t.
111inline constexpr __fields __fields_integral{
112 .__sign_ = true,
113 .__alternate_form_ = true,
114 .__zero_padding_ = true,
115 .__locale_specific_form_ = true,
116 .__type_ = true};
117inline constexpr __fields __fields_floating_point{
118 .__sign_ = true,
119 .__alternate_form_ = true,
120 .__zero_padding_ = true,
121 .__precision_ = true,
122 .__locale_specific_form_ = true,
123 .__type_ = true};
124inline constexpr __fields __fields_string{.__precision_ = true, .__type_ = true};
125inline constexpr __fields __fields_pointer{.__type_ = true};
126
127enum class _LIBCPP_ENUM_VIS __alignment : uint8_t {
128 /// No alignment is set in the format string.
129 __default,
130 __left,
131 __center,
132 __right,
133 __zero_padding
134};
296135
297 __format::__parse_number_result __r =
298 __format::__parse_number(__begin, __end);
299 __width = __r.__value;
300 _LIBCPP_ASSERT(__width != 0,
301 "A zero value isn't allowed and should be impossible, "
302 "due to validations in this function");
303 return __r.__ptr;
304 }
136enum class _LIBCPP_ENUM_VIS __sign : uint8_t {
137 /// No sign is set in the format string.
138 ///
139 /// The sign isn't allowed for certain format-types. By using this value
140 /// it's possible to detect whether or not the user explicitly set the sign
141 /// flag. For formatting purposes it behaves the same as \ref __minus.
142 __default,
143 __minus,
144 __plus,
145 __space
146};
305147
306 _LIBCPP_HIDE_FROM_ABI constexpr void __substitute_width_arg_id(auto __arg) {
307 _LIBCPP_ASSERT(__width_as_arg == 1,
308 "Substitute width called when no substitution is required");
309
310 // The clearing of the flag isn't required but looks better when debugging
311 // the code.
312 __width_as_arg = 0;
313 __width = __substitute_arg_id(__arg);
314 if (__width == 0)
315 __throw_format_error(
316 "A format-spec width field replacement should have a positive value");
317 }
148enum class _LIBCPP_ENUM_VIS __type : uint8_t {
149 __default,
150 __string,
151 __binary_lower_case,
152 __binary_upper_case,
153 __octal,
154 __decimal,
155 __hexadecimal_lower_case,
156 __hexadecimal_upper_case,
157 __pointer,
158 __char,
159 __hexfloat_lower_case,
160 __hexfloat_upper_case,
161 __scientific_lower_case,
162 __scientific_upper_case,
163 __fixed_lower_case,
164 __fixed_upper_case,
165 __general_lower_case,
166 __general_upper_case
318167};
319168
320class _LIBCPP_TYPE_VIS __parser_precision {
321public:
322 /** Contains a precision or an arg-id. */
323 uint32_t __precision : 31 {__format::__number_max};
324 /**
325 * Determines whether the value stored is a precision or an arg-id.
326 *
327 * @note Since @ref __precision == @ref __format::__number_max is a valid
328 * value, the default value contains an arg-id of INT32_MAX. (This number of
329 * arguments isn't supported by compilers.) This is used to detect whether
330 * the std-format-spec contains a precision field.
331 */
332 uint32_t __precision_as_arg : 1 {1};
333
334protected:
335 /**
336 * Does the supplied std-format-spec contain a precision field?
337 *
338 * When the field isn't present there's no truncating required. This can be
339 * used to optimize the formatting.
340 */
341 constexpr bool __has_precision_field() const noexcept {
342
343 return __precision_as_arg == 0 || // Contains a value?
344 __precision != __format::__number_max; // The arg-id is valid?
345 }
169struct __std {
170 __alignment __alignment_ : 3;
171 __sign __sign_ : 2;
172 bool __alternate_form_ : 1;
173 bool __locale_specific_form_ : 1;
174 __type __type_;
175};
346176
347 /**
348 * Does the supplied precision field contain an arg-id?
349 *
350 * If @c true the formatter needs to call @ref __substitute_precision_arg_id.
351 */
352 constexpr bool __precision_needs_substitution() const noexcept {
353 return __precision_as_arg && __precision != __format::__number_max;
354 }
177struct __chrono {
178 __alignment __alignment_ : 3;
179 bool __weekday_name_ : 1;
180 bool __month_name_ : 1;
181};
355182
356 template <class _CharT>
357 _LIBCPP_HIDE_FROM_ABI constexpr const _CharT*
358 __parse(const _CharT* __begin, const _CharT* __end, auto& __parse_ctx) {
359 if (*__begin != _CharT('.'))
360 return __begin;
183/// Contains the parsed formatting specifications.
184///
185/// This contains information for both the std-format-spec and the
186/// chrono-format-spec. This results in some unused members for both
187/// specifications. However these unused members don't increase the size
188/// of the structure.
189///
190/// This struct doesn't cross ABI boundaries so its layout doesn't need to be
191/// kept stable.
192template <class _CharT>
193struct __parsed_specifications {
194 union {
195 // The field __alignment_ is the first element in __std_ and __chrono_.
196 // This allows the code to always inspect this value regards which member
197 // of the union is the active member [class.union.general]/2.
198 //
199 // This is needed since the generic output routines handle the alignment of
200 // the output.
201 __alignment __alignment_ : 3;
202 __std __std_;
203 __chrono __chrono_;
204 };
361205
362 ++__begin;
363 if (__begin == __end)
364 __throw_format_error("End of input while parsing format-spec precision");
206 /// The requested width.
207 ///
208 /// When the format-spec used an arg-id for this field it has already been
209 /// replaced with the value of that arg-id.
210 int32_t __width_;
365211
366 if (*__begin == _CharT('{')) {
367 __format::__parse_number_result __arg_id =
368 __parse_arg_id(++__begin, __end, __parse_ctx);
369 _LIBCPP_ASSERT(__arg_id.__value != __format::__number_max,
370 "Unsupported number of arguments, since this number of "
371 "arguments is used a special value");
372 __precision = __arg_id.__value;
373 return __arg_id.__ptr;
374 }
212 /// The requested precision.
213 ///
214 /// When the format-spec used an arg-id for this field it has already been
215 /// replaced with the value of that arg-id.
216 int32_t __precision_;
375217
376 if (*__begin < _CharT('0') || *__begin > _CharT('9'))
377 __throw_format_error(
378 "The format-spec precision field doesn't contain a value or arg-id");
379
380 __format::__parse_number_result __r =
381 __format::__parse_number(__begin, __end);
382 __precision = __r.__value;
383 __precision_as_arg = 0;
384 return __r.__ptr;
385 }
218 _CharT __fill_;
386219
387 _LIBCPP_HIDE_FROM_ABI constexpr void __substitute_precision_arg_id(
388 auto __arg) {
389 _LIBCPP_ASSERT(
390 __precision_as_arg == 1 && __precision != __format::__number_max,
391 "Substitute precision called when no substitution is required");
220 _LIBCPP_HIDE_FROM_ABI constexpr bool __has_width() const { return __width_ > 0; }
392221
393 // The clearing of the flag isn't required but looks better when debugging
394 // the code.
395 __precision_as_arg = 0;
396 __precision = __substitute_arg_id(__arg);
397 }
222 _LIBCPP_HIDE_FROM_ABI constexpr bool __has_precision() const { return __precision_ >= 0; }
398223};
399224
225// Validate the struct is small and cheap to copy since the struct is passed by
226// value in formatting functions.
227static_assert(sizeof(__parsed_specifications<char>) == 16);
228static_assert(is_trivially_copyable_v<__parsed_specifications<char>>);
229# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
230static_assert(sizeof(__parsed_specifications<wchar_t>) == 16);
231static_assert(is_trivially_copyable_v<__parsed_specifications<wchar_t>>);
232# endif
233
234/// The parser for the std-format-spec.
235///
236/// Note this class is a member of std::formatter specializations. It's
237/// expected developers will create their own formatter specializations that
238/// inherit from the std::formatter specializations. This means this class
239/// must be ABI stable. To aid the stability the unused bits in the class are
240/// set to zero. That way they can be repurposed if a future revision of the
241/// Standards adds new fields to std-format-spec.
400242template <class _CharT>
401_LIBCPP_HIDE_FROM_ABI constexpr const _CharT*
402__parse_locale_specific_form(const _CharT* __begin, _Flags& __flags) noexcept {
403 if (*__begin == _CharT('L')) {
404 __flags.__locale_specific_form = true;
405 ++__begin;
406 }
407
408 return __begin;
409}
410
411template <class _CharT>
412_LIBCPP_HIDE_FROM_ABI constexpr const _CharT*
413__parse_type(const _CharT* __begin, _Flags& __flags) {
414
415 // Determines the type. It does not validate whether the selected type is
416 // valid. Most formatters have optional fields that are only allowed for
417 // certain types. These parsers need to do validation after the type has
418 // been parsed. So its easier to implement the validation for all types in
419 // the specific parse function.
420 switch (*__begin) {
421 case 'A':
422 __flags.__type = _Flags::_Type::__float_hexadecimal_upper_case;
423 break;
424 case 'B':
425 __flags.__type = _Flags::_Type::__binary_upper_case;
426 break;
427 case 'E':
428 __flags.__type = _Flags::_Type::__scientific_upper_case;
429 break;
430 case 'F':
431 __flags.__type = _Flags::_Type::__fixed_upper_case;
432 break;
433 case 'G':
434 __flags.__type = _Flags::_Type::__general_upper_case;
435 break;
436 case 'X':
437 __flags.__type = _Flags::_Type::__hexadecimal_upper_case;
438 break;
439 case 'a':
440 __flags.__type = _Flags::_Type::__float_hexadecimal_lower_case;
441 break;
442 case 'b':
443 __flags.__type = _Flags::_Type::__binary_lower_case;
444 break;
445 case 'c':
446 __flags.__type = _Flags::_Type::__char;
447 break;
448 case 'd':
449 __flags.__type = _Flags::_Type::__decimal;
450 break;
451 case 'e':
452 __flags.__type = _Flags::_Type::__scientific_lower_case;
453 break;
454 case 'f':
455 __flags.__type = _Flags::_Type::__fixed_lower_case;
456 break;
457 case 'g':
458 __flags.__type = _Flags::_Type::__general_lower_case;
459 break;
460 case 'o':
461 __flags.__type = _Flags::_Type::__octal;
462 break;
463 case 'p':
464 __flags.__type = _Flags::_Type::__pointer;
465 break;
466 case 's':
467 __flags.__type = _Flags::_Type::__string;
468 break;
469 case 'x':
470 __flags.__type = _Flags::_Type::__hexadecimal_lower_case;
471 break;
472 default:
473 return __begin;
474 }
475 return ++__begin;
476}
477
478/**
479 * Process the parsed alignment and zero-padding state of arithmetic types.
480 *
481 * [format.string.std]/13
482 * If the 0 character and an align option both appear, the 0 character is
483 * ignored.
484 *
485 * For the formatter a @ref __default alignment means zero-padding.
486 */
487_LIBCPP_HIDE_FROM_ABI constexpr void __process_arithmetic_alignment(_Flags& __flags) {
488 __flags.__zero_padding &= __flags.__alignment == _Flags::_Alignment::__default;
489 if (!__flags.__zero_padding && __flags.__alignment == _Flags::_Alignment::__default)
490 __flags.__alignment = _Flags::_Alignment::__right;
491}
492
493/**
494 * The parser for the std-format-spec.
495 *
496 * [format.string.std]/1 specifies the std-format-spec:
497 * fill-and-align sign # 0 width precision L type
498 *
499 * All these fields are optional. Whether these fields can be used depend on:
500 * - The type supplied to the format string.
501 * E.g. A string never uses the sign field so the field may not be set.
502 * This constrain is validated by the parsers in this file.
503 * - The supplied value for the optional type field.
504 * E.g. A int formatted as decimal uses the sign field.
505 * When formatted as a char the sign field may no longer be set.
506 * This constrain isn't validated by the parsers in this file.
507 *
508 * The base classes are ordered to minimize the amount of padding.
509 *
510 * This implements the parser for the string types.
511 */
512template <class _CharT>
513class _LIBCPP_TEMPLATE_VIS __parser_string
514 : public __parser_width, // provides __width(|as_arg)
515 public __parser_precision, // provides __precision(|as_arg)
516 public __parser_fill_align<_CharT>, // provides __fill and uses __flags
517 public _Flags // provides __flags
518{
243class _LIBCPP_TEMPLATE_VIS __parser {
519244public:
520 using char_type = _CharT;
245 _LIBCPP_HIDE_FROM_ABI constexpr auto __parse(basic_format_parse_context<_CharT>& __parse_ctx, __fields __fields)
246 -> decltype(__parse_ctx.begin()) {
521247
522 _LIBCPP_HIDE_FROM_ABI constexpr __parser_string() {
523 this->__alignment = _Flags::_Alignment::__left;
524 }
248 const _CharT* __begin = __parse_ctx.begin();
249 const _CharT* __end = __parse_ctx.end();
250 if (__begin == __end)
251 return __begin;
525252
526 /**
527 * The low-level std-format-spec parse function.
528 *
529 * @pre __begin points at the beginning of the std-format-spec. This means
530 * directly after the ':'.
531 * @pre The std-format-spec parses the entire input, or the first unmatched
532 * character is a '}'.
533 *
534 * @returns The iterator pointing at the last parsed character.
535 */
536 _LIBCPP_HIDE_FROM_ABI constexpr auto parse(auto& __parse_ctx)
537 -> decltype(__parse_ctx.begin()) {
538 auto __it = __parse(__parse_ctx);
539 __process_display_type();
540 return __it;
541 }
253 if (__parse_fill_align(__begin, __end) && __begin == __end)
254 return __begin;
542255
543private:
544 /**
545 * Parses the std-format-spec.
546 *
547 * @throws __throw_format_error When @a __parse_ctx contains an ill-formed
548 * std-format-spec.
549 *
550 * @returns An iterator to the end of input or point at the closing '}'.
551 */
552 _LIBCPP_HIDE_FROM_ABI constexpr auto __parse(auto& __parse_ctx)
553 -> decltype(__parse_ctx.begin()) {
256 if (__fields.__sign_ && __parse_sign(__begin) && __begin == __end)
257 return __begin;
554258
555 auto __begin = __parse_ctx.begin();
556 auto __end = __parse_ctx.end();
557 if (__begin == __end)
259 if (__fields.__alternate_form_ && __parse_alternate_form(__begin) && __begin == __end)
558260 return __begin;
559261
560 __begin = __parser_fill_align<_CharT>::__parse(__begin, __end,
561 static_cast<_Flags&>(*this));
562 if (__begin == __end)
262 if (__fields.__zero_padding_ && __parse_zero_padding(__begin) && __begin == __end)
563263 return __begin;
564264
565 __begin = __parser_width::__parse(__begin, __end, __parse_ctx);
566 if (__begin == __end)
265 if (__parse_width(__begin, __end, __parse_ctx) && __begin == __end)
567266 return __begin;
568267
569 __begin = __parser_precision::__parse(__begin, __end, __parse_ctx);
570 if (__begin == __end)
268 if (__fields.__precision_ && __parse_precision(__begin, __end, __parse_ctx) && __begin == __end)
269 return __begin;
270
271 if (__fields.__locale_specific_form_ && __parse_locale_specific_form(__begin) && __begin == __end)
571272 return __begin;
572273
573 __begin = __parse_type(__begin, static_cast<_Flags&>(*this));
274 if (__fields.__type_) {
275 __parse_type(__begin);
574276
575 if (__begin != __end && *__begin != _CharT('}'))
576 __throw_format_error(
577 "The format-spec should consume the input or end with a '}'");
277 // When __type_ is false the calling parser is expected to do additional
278 // parsing. In that case that parser should do the end of format string
279 // validation.
280 if (__begin != __end && *__begin != _CharT('}'))
281 __throw_format_error("The format-spec should consume the input or end with a '}'");
282 }
578283
579284 return __begin;
580285 }
581286
582 /** Processes the parsed std-format-spec based on the parsed display type. */
583 _LIBCPP_HIDE_FROM_ABI constexpr void __process_display_type() {
584 switch (this->__type) {
585 case _Flags::_Type::__default:
586 case _Flags::_Type::__string:
587 break;
287 /// \returns the `__parsed_specifications` with the resolved dynamic sizes..
288 _LIBCPP_HIDE_FROM_ABI
289 __parsed_specifications<_CharT> __get_parsed_std_specifications(auto& __ctx) const {
290 return __parsed_specifications<_CharT>{
291 .__std_ =
292 __std{.__alignment_ = __alignment_,
293 .__sign_ = __sign_,
294 .__alternate_form_ = __alternate_form_,
295 .__locale_specific_form_ = __locale_specific_form_,
296 .__type_ = __type_},
297 .__width_{__get_width(__ctx)},
298 .__precision_{__get_precision(__ctx)},
299 .__fill_{__fill_}};
300 }
301
302 __alignment __alignment_ : 3 {__alignment::__default};
303 __sign __sign_ : 2 {__sign::__default};
304 bool __alternate_form_ : 1 {false};
305 bool __locale_specific_form_ : 1 {false};
306 bool __reserved_0_ : 1 {false};
307 __type __type_{__type::__default};
308
309 // These two flags are used for formatting chrono. Since the struct has
310 // padding space left it's added to this structure.
311 bool __weekday_name_ : 1 {false};
312 bool __month_name_ : 1 {false};
313
314 uint8_t __reserved_1_ : 6 {0};
315 uint8_t __reserved_2_ : 6 {0};
316 // These two flags are only used internally and not part of the
317 // __parsed_specifications. Therefore put them at the end.
318 bool __width_as_arg_ : 1 {false};
319 bool __precision_as_arg_ : 1 {false};
320
321 /// The requested width, either the value or the arg-id.
322 int32_t __width_{0};
323
324 /// The requested precision, either the value or the arg-id.
325 int32_t __precision_{-1};
326
327 // LWG 3576 will probably change this to always accept a Unicode code point
328 // To avoid changing the size with that change align the field so when it
329 // becomes 32-bit its alignment will remain the same. That also means the
330 // size will remain the same. (D2572 addresses the solution for LWG 3576.)
331 _CharT __fill_{_CharT(' ')};
588332
589 default:
590 __throw_format_error("The format-spec type has a type not supported for "
591 "a string argument");
333private:
334 _LIBCPP_HIDE_FROM_ABI constexpr bool __parse_alignment(_CharT __c) {
335 switch (__c) {
336 case _CharT('<'):
337 __alignment_ = __alignment::__left;
338 return true;
339
340 case _CharT('^'):
341 __alignment_ = __alignment::__center;
342 return true;
343
344 case _CharT('>'):
345 __alignment_ = __alignment::__right;
346 return true;
592347 }
348 return false;
593349 }
594};
595
596/**
597 * The parser for the std-format-spec.
598 *
599 * This implements the parser for the integral types. This includes the
600 * character type and boolean type.
601 *
602 * See @ref __parser_string.
603 */
604template <class _CharT>
605class _LIBCPP_TEMPLATE_VIS __parser_integral
606 : public __parser_width, // provides __width(|as_arg)
607 public __parser_fill_align<_CharT>, // provides __fill and uses __flags
608 public _Flags // provides __flags
609{
610public:
611 using char_type = _CharT;
612
613protected:
614 /**
615 * The low-level std-format-spec parse function.
616 *
617 * @pre __begin points at the beginning of the std-format-spec. This means
618 * directly after the ':'.
619 * @pre The std-format-spec parses the entire input, or the first unmatched
620 * character is a '}'.
621 *
622 * @returns The iterator pointing at the last parsed character.
623 */
624 _LIBCPP_HIDE_FROM_ABI constexpr auto __parse(auto& __parse_ctx)
625 -> decltype(__parse_ctx.begin()) {
626 auto __begin = __parse_ctx.begin();
627 auto __end = __parse_ctx.end();
628 if (__begin == __end)
629 return __begin;
630350
631 __begin = __parser_fill_align<_CharT>::__parse(__begin, __end,
632 static_cast<_Flags&>(*this));
633 if (__begin == __end)
634 return __begin;
635
636 __begin = __parse_sign(__begin, static_cast<_Flags&>(*this));
637 if (__begin == __end)
638 return __begin;
639
640 __begin = __parse_alternate_form(__begin, static_cast<_Flags&>(*this));
641 if (__begin == __end)
642 return __begin;
351 _LIBCPP_HIDE_FROM_ABI constexpr bool __parse_fill_align(const _CharT*& __begin, const _CharT* __end) {
352 _LIBCPP_ASSERT(__begin != __end, "when called with an empty input the function will cause "
353 "undefined behavior by evaluating data not in the input");
354 if (__begin + 1 != __end) {
355 if (__parse_alignment(*(__begin + 1))) {
356 if (*__begin == _CharT('{') || *__begin == _CharT('}'))
357 __throw_format_error("The format-spec fill field contains an invalid character");
643358
644 __begin = __parse_zero_padding(__begin, static_cast<_Flags&>(*this));
645 if (__begin == __end)
646 return __begin;
359 __fill_ = *__begin;
360 __begin += 2;
361 return true;
362 }
363 }
647364
648 __begin = __parser_width::__parse(__begin, __end, __parse_ctx);
649 if (__begin == __end)
650 return __begin;
365 if (!__parse_alignment(*__begin))
366 return false;
651367
652 __begin =
653 __parse_locale_specific_form(__begin, static_cast<_Flags&>(*this));
654 if (__begin == __end)
655 return __begin;
368 ++__begin;
369 return true;
370 }
656371
657 __begin = __parse_type(__begin, static_cast<_Flags&>(*this));
372 _LIBCPP_HIDE_FROM_ABI constexpr bool __parse_sign(const _CharT*& __begin) {
373 switch (*__begin) {
374 case _CharT('-'):
375 __sign_ = __sign::__minus;
376 break;
377 case _CharT('+'):
378 __sign_ = __sign::__plus;
379 break;
380 case _CharT(' '):
381 __sign_ = __sign::__space;
382 break;
383 default:
384 return false;
385 }
386 ++__begin;
387 return true;
388 }
658389
659 if (__begin != __end && *__begin != _CharT('}'))
660 __throw_format_error(
661 "The format-spec should consume the input or end with a '}'");
390 _LIBCPP_HIDE_FROM_ABI constexpr bool __parse_alternate_form(const _CharT*& __begin) {
391 if (*__begin != _CharT('#'))
392 return false;
662393
663 return __begin;
394 __alternate_form_ = true;
395 ++__begin;
396 return true;
664397 }
665398
666 /** Handles the post-parsing updates for the integer types. */
667 _LIBCPP_HIDE_FROM_ABI constexpr void __handle_integer() noexcept {
668 __process_arithmetic_alignment(static_cast<_Flags&>(*this));
669 }
399 _LIBCPP_HIDE_FROM_ABI constexpr bool __parse_zero_padding(const _CharT*& __begin) {
400 if (*__begin != _CharT('0'))
401 return false;
670402
671 /**
672 * Handles the post-parsing updates for the character types.
673 *
674 * Sets the alignment and validates the format flags set for a character type.
675 *
676 * At the moment the validation for a character and a Boolean behave the
677 * same, but this may change in the future.
678 * Specifically at the moment the locale-specific form is allowed for the
679 * char output type, but it has no effect on the output.
680 */
681 _LIBCPP_HIDE_FROM_ABI constexpr void __handle_char() { __handle_bool(); }
682
683 /**
684 * Handles the post-parsing updates for the Boolean types.
685 *
686 * Sets the alignment and validates the format flags set for a Boolean type.
687 */
688 _LIBCPP_HIDE_FROM_ABI constexpr void __handle_bool() {
689 if (this->__sign != _Flags::_Sign::__default)
690 __throw_format_error("A sign field isn't allowed in this format-spec");
691
692 if (this->__alternate_form)
693 __throw_format_error(
694 "An alternate form field isn't allowed in this format-spec");
695
696 if (this->__zero_padding)
697 __throw_format_error(
698 "A zero-padding field isn't allowed in this format-spec");
699
700 if (this->__alignment == _Flags::_Alignment::__default)
701 this->__alignment = _Flags::_Alignment::__left;
403 if (__alignment_ == __alignment::__default)
404 __alignment_ = __alignment::__zero_padding;
405 ++__begin;
406 return true;
702407 }
703};
704408
705/**
706 * The parser for the std-format-spec.
707 *
708 * This implements the parser for the floating-point types.
709 *
710 * See @ref __parser_string.
711 */
712template <class _CharT>
713class _LIBCPP_TEMPLATE_VIS __parser_floating_point
714 : public __parser_width, // provides __width(|as_arg)
715 public __parser_precision, // provides __precision(|as_arg)
716 public __parser_fill_align<_CharT>, // provides __fill and uses __flags
717 public _Flags // provides __flags
718{
719public:
720 using char_type = _CharT;
721
722 /**
723 * The low-level std-format-spec parse function.
724 *
725 * @pre __begin points at the beginning of the std-format-spec. This means
726 * directly after the ':'.
727 * @pre The std-format-spec parses the entire input, or the first unmatched
728 * character is a '}'.
729 *
730 * @returns The iterator pointing at the last parsed character.
731 */
732 _LIBCPP_HIDE_FROM_ABI constexpr auto parse(auto& __parse_ctx)
733 -> decltype(__parse_ctx.begin()) {
734 auto __it = __parse(__parse_ctx);
735 __process_arithmetic_alignment(static_cast<_Flags&>(*this));
736 __process_display_type();
737 return __it;
738 }
739protected:
740 /**
741 * The low-level std-format-spec parse function.
742 *
743 * @pre __begin points at the beginning of the std-format-spec. This means
744 * directly after the ':'.
745 * @pre The std-format-spec parses the entire input, or the first unmatched
746 * character is a '}'.
747 *
748 * @returns The iterator pointing at the last parsed character.
749 */
750 _LIBCPP_HIDE_FROM_ABI constexpr auto __parse(auto& __parse_ctx)
751 -> decltype(__parse_ctx.begin()) {
752 auto __begin = __parse_ctx.begin();
753 auto __end = __parse_ctx.end();
754 if (__begin == __end)
755 return __begin;
409 _LIBCPP_HIDE_FROM_ABI constexpr bool __parse_width(const _CharT*& __begin, const _CharT* __end, auto& __parse_ctx) {
410 if (*__begin == _CharT('0'))
411 __throw_format_error("A format-spec width field shouldn't have a leading zero");
756412
757 __begin = __parser_fill_align<_CharT>::__parse(__begin, __end,
758 static_cast<_Flags&>(*this));
759 if (__begin == __end)
760 return __begin;
413 if (*__begin == _CharT('{')) {
414 __format::__parse_number_result __r = __format_spec::__parse_arg_id(++__begin, __end, __parse_ctx);
415 __width_as_arg_ = true;
416 __width_ = __r.__value;
417 __begin = __r.__ptr;
418 return true;
419 }
761420
762 __begin = __parse_sign(__begin, static_cast<_Flags&>(*this));
763 if (__begin == __end)
764 return __begin;
421 if (*__begin < _CharT('0') || *__begin > _CharT('9'))
422 return false;
765423
766 __begin = __parse_alternate_form(__begin, static_cast<_Flags&>(*this));
767 if (__begin == __end)
768 return __begin;
424 __format::__parse_number_result __r = __format::__parse_number(__begin, __end);
425 __width_ = __r.__value;
426 _LIBCPP_ASSERT(__width_ != 0, "A zero value isn't allowed and should be impossible, "
427 "due to validations in this function");
428 __begin = __r.__ptr;
429 return true;
430 }
769431
770 __begin = __parse_zero_padding(__begin, static_cast<_Flags&>(*this));
771 if (__begin == __end)
772 return __begin;
432 _LIBCPP_HIDE_FROM_ABI constexpr bool __parse_precision(const _CharT*& __begin, const _CharT* __end,
433 auto& __parse_ctx) {
434 if (*__begin != _CharT('.'))
435 return false;
773436
774 __begin = __parser_width::__parse(__begin, __end, __parse_ctx);
437 ++__begin;
775438 if (__begin == __end)
776 return __begin;
439 __throw_format_error("End of input while parsing format-spec precision");
777440
778 __begin = __parser_precision::__parse(__begin, __end, __parse_ctx);
779 if (__begin == __end)
780 return __begin;
441 if (*__begin == _CharT('{')) {
442 __format::__parse_number_result __arg_id = __format_spec::__parse_arg_id(++__begin, __end, __parse_ctx);
443 __precision_as_arg_ = true;
444 __precision_ = __arg_id.__value;
445 __begin = __arg_id.__ptr;
446 return true;
447 }
781448
782 __begin =
783 __parse_locale_specific_form(__begin, static_cast<_Flags&>(*this));
784 if (__begin == __end)
785 return __begin;
449 if (*__begin < _CharT('0') || *__begin > _CharT('9'))
450 __throw_format_error("The format-spec precision field doesn't contain a value or arg-id");
786451
787 __begin = __parse_type(__begin, static_cast<_Flags&>(*this));
452 __format::__parse_number_result __r = __format::__parse_number(__begin, __end);
453 __precision_ = __r.__value;
454 __precision_as_arg_ = false;
455 __begin = __r.__ptr;
456 return true;
457 }
788458
789 if (__begin != __end && *__begin != _CharT('}'))
790 __throw_format_error(
791 "The format-spec should consume the input or end with a '}'");
459 _LIBCPP_HIDE_FROM_ABI constexpr bool __parse_locale_specific_form(const _CharT*& __begin) {
460 if (*__begin != _CharT('L'))
461 return false;
792462
793 return __begin;
463 __locale_specific_form_ = true;
464 ++__begin;
465 return true;
794466 }
795467
796 /** Processes the parsed std-format-spec based on the parsed display type. */
797 _LIBCPP_HIDE_FROM_ABI constexpr void __process_display_type() {
798 switch (this->__type) {
799 case _Flags::_Type::__default:
800 // When no precision specified then it keeps default since that
801 // formatting differs from the other types.
802 if (this->__has_precision_field())
803 this->__type = _Flags::_Type::__general_lower_case;
468 _LIBCPP_HIDE_FROM_ABI constexpr void __parse_type(const _CharT*& __begin) {
469 // Determines the type. It does not validate whether the selected type is
470 // valid. Most formatters have optional fields that are only allowed for
471 // certain types. These parsers need to do validation after the type has
472 // been parsed. So its easier to implement the validation for all types in
473 // the specific parse function.
474 switch (*__begin) {
475 case 'A':
476 __type_ = __type::__hexfloat_upper_case;
804477 break;
805 case _Flags::_Type::__float_hexadecimal_lower_case:
806 case _Flags::_Type::__float_hexadecimal_upper_case:
807 // Precision specific behavior will be handled later.
478 case 'B':
479 __type_ = __type::__binary_upper_case;
808480 break;
809 case _Flags::_Type::__scientific_lower_case:
810 case _Flags::_Type::__scientific_upper_case:
811 case _Flags::_Type::__fixed_lower_case:
812 case _Flags::_Type::__fixed_upper_case:
813 case _Flags::_Type::__general_lower_case:
814 case _Flags::_Type::__general_upper_case:
815 if (!this->__has_precision_field()) {
816 // Set the default precision for the call to to_chars.
817 this->__precision = 6;
818 this->__precision_as_arg = false;
819 }
481 case 'E':
482 __type_ = __type::__scientific_upper_case;
483 break;
484 case 'F':
485 __type_ = __type::__fixed_upper_case;
486 break;
487 case 'G':
488 __type_ = __type::__general_upper_case;
489 break;
490 case 'X':
491 __type_ = __type::__hexadecimal_upper_case;
492 break;
493 case 'a':
494 __type_ = __type::__hexfloat_lower_case;
495 break;
496 case 'b':
497 __type_ = __type::__binary_lower_case;
498 break;
499 case 'c':
500 __type_ = __type::__char;
501 break;
502 case 'd':
503 __type_ = __type::__decimal;
504 break;
505 case 'e':
506 __type_ = __type::__scientific_lower_case;
507 break;
508 case 'f':
509 __type_ = __type::__fixed_lower_case;
510 break;
511 case 'g':
512 __type_ = __type::__general_lower_case;
513 break;
514 case 'o':
515 __type_ = __type::__octal;
516 break;
517 case 'p':
518 __type_ = __type::__pointer;
519 break;
520 case 's':
521 __type_ = __type::__string;
522 break;
523 case 'x':
524 __type_ = __type::__hexadecimal_lower_case;
820525 break;
821
822526 default:
823 __throw_format_error("The format-spec type has a type not supported for "
824 "a floating-point argument");
527 return;
825528 }
529 ++__begin;
826530 }
827};
828531
829/**
830 * The parser for the std-format-spec.
831 *
832 * This implements the parser for the pointer types.
833 *
834 * See @ref __parser_string.
835 */
836template <class _CharT>
837class _LIBCPP_TEMPLATE_VIS __parser_pointer : public __parser_width, // provides __width(|as_arg)
838 public __parser_fill_align<_CharT>, // provides __fill and uses __flags
839 public _Flags // provides __flags
840{
841public:
842 using char_type = _CharT;
532 _LIBCPP_HIDE_FROM_ABI
533 int32_t __get_width(auto& __ctx) const {
534 if (!__width_as_arg_)
535 return __width_;
843536
844 _LIBCPP_HIDE_FROM_ABI constexpr __parser_pointer() {
845 // Implements LWG3612 Inconsistent pointer alignment in std::format.
846 // The issue's current status is "Tentatively Ready" and libc++ status is
847 // still experimental.
848 //
849 // TODO FMT Validate this with the final resolution of LWG3612.
850 this->__alignment = _Flags::_Alignment::__right;
537 int32_t __result = __format_spec::__substitute_arg_id(__ctx.arg(__width_));
538 if (__result == 0)
539 __throw_format_error("A format-spec width field replacement should have a positive value");
540 return __result;
851541 }
852542
853 /**
854 * The low-level std-format-spec parse function.
855 *
856 * @pre __begin points at the beginning of the std-format-spec. This means
857 * directly after the ':'.
858 * @pre The std-format-spec parses the entire input, or the first unmatched
859 * character is a '}'.
860 *
861 * @returns The iterator pointing at the last parsed character.
862 */
863 _LIBCPP_HIDE_FROM_ABI constexpr auto parse(auto& __parse_ctx) -> decltype(__parse_ctx.begin()) {
864 auto __it = __parse(__parse_ctx);
865 __process_display_type();
866 return __it;
543 _LIBCPP_HIDE_FROM_ABI
544 int32_t __get_precision(auto& __ctx) const {
545 if (!__precision_as_arg_)
546 return __precision_;
547
548 return __format_spec::__substitute_arg_id(__ctx.arg(__precision_));
867549 }
550};
868551
869protected:
870 /**
871 * The low-level std-format-spec parse function.
872 *
873 * @pre __begin points at the beginning of the std-format-spec. This means
874 * directly after the ':'.
875 * @pre The std-format-spec parses the entire input, or the first unmatched
876 * character is a '}'.
877 *
878 * @returns The iterator pointing at the last parsed character.
879 */
880 _LIBCPP_HIDE_FROM_ABI constexpr auto __parse(auto& __parse_ctx) -> decltype(__parse_ctx.begin()) {
881 auto __begin = __parse_ctx.begin();
882 auto __end = __parse_ctx.end();
883 if (__begin == __end)
884 return __begin;
552// Validates whether the reserved bitfields don't change the size.
553static_assert(sizeof(__parser<char>) == 16);
554# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
555static_assert(sizeof(__parser<wchar_t>) == 16);
556# endif
885557
886 __begin = __parser_fill_align<_CharT>::__parse(__begin, __end, static_cast<_Flags&>(*this));
887 if (__begin == __end)
888 return __begin;
558_LIBCPP_HIDE_FROM_ABI constexpr void __process_display_type_string(__format_spec::__type __type) {
559 switch (__type) {
560 case __format_spec::__type::__default:
561 case __format_spec::__type::__string:
562 break;
889563
890 // An integer presentation type isn't defined in the Standard.
891 // Since a pointer is formatted as an integer it can be argued it's an
892 // integer presentation type. However there are two LWG-issues asserting it
893 // isn't an integer presentation type:
894 // - LWG3612 Inconsistent pointer alignment in std::format
895 // - LWG3644 std::format does not define "integer presentation type"
896 //
897 // There's a paper to make additional clarifications on the status of
898 // formatting pointers and proposes additional fields to be valid. That
899 // paper hasn't been reviewed by the Committee yet.
900 // - P2510 Formatting pointers
901 //
902 // The current implementation assumes formatting pointers isn't covered by
903 // "integer presentation type".
904 // TODO FMT Apply the LWG-issues/papers after approval/rejection by the Committee.
564 default:
565 std::__throw_format_error("The format-spec type has a type not supported for a string argument");
566 }
567}
905568
906 __begin = __parser_width::__parse(__begin, __end, __parse_ctx);
907 if (__begin == __end)
908 return __begin;
569template <class _CharT>
570_LIBCPP_HIDE_FROM_ABI constexpr void __process_display_type_bool_string(__parser<_CharT>& __parser) {
571 if (__parser.__sign_ != __sign::__default)
572 std::__throw_format_error("A sign field isn't allowed in this format-spec");
909573
910 __begin = __parse_type(__begin, static_cast<_Flags&>(*this));
574 if (__parser.__alternate_form_)
575 std::__throw_format_error("An alternate form field isn't allowed in this format-spec");
911576
912 if (__begin != __end && *__begin != _CharT('}'))
913 __throw_format_error("The format-spec should consume the input or end with a '}'");
577 if (__parser.__alignment_ == __alignment::__zero_padding)
578 std::__throw_format_error("A zero-padding field isn't allowed in this format-spec");
914579
915 return __begin;
916 }
580 if (__parser.__alignment_ == __alignment::__default)
581 __parser.__alignment_ = __alignment::__left;
582}
917583
918 /** Processes the parsed std-format-spec based on the parsed display type. */
919 _LIBCPP_HIDE_FROM_ABI constexpr void __process_display_type() {
920 switch (this->__type) {
921 case _Flags::_Type::__default:
922 this->__type = _Flags::_Type::__pointer;
923 break;
924 case _Flags::_Type::__pointer:
925 break;
926 default:
927 __throw_format_error("The format-spec type has a type not supported for a pointer argument");
928 }
929 }
930};
584template <class _CharT>
585_LIBCPP_HIDE_FROM_ABI constexpr void __process_display_type_char(__parser<_CharT>& __parser) {
586 __format_spec::__process_display_type_bool_string(__parser);
587}
931588
932/** Helper struct returned from @ref __get_string_alignment. */
933589template <class _CharT>
934struct _LIBCPP_TEMPLATE_VIS __string_alignment {
935 /** Points beyond the last character to write to the output. */
936 const _CharT* __last;
937 /**
938 * The estimated number of columns in the output or 0.
939 *
940 * Only when the output needs to be aligned it's required to know the exact
941 * number of columns in the output. So if the formatted output has only a
942 * minimum width the exact size isn't important. It's only important to know
943 * the minimum has been reached. The minimum width is the width specified in
944 * the format-spec.
945 *
946 * For example in this code @code std::format("{:10}", MyString); @endcode
947 * the width estimation can stop once the algorithm has determined the output
948 * width is 10 columns.
949 *
950 * So if:
951 * * @ref __align == @c true the @ref __size is the estimated number of
952 * columns required.
953 * * @ref __align == @c false the @ref __size is the estimated number of
954 * columns required or 0 when the estimation algorithm stopped prematurely.
955 */
956 ptrdiff_t __size;
957 /**
958 * Does the output need to be aligned.
959 *
960 * When alignment is needed the output algorithm needs to add the proper
961 * padding. Else the output algorithm just needs to copy the input up to
962 * @ref __last.
963 */
964 bool __align;
965};
590_LIBCPP_HIDE_FROM_ABI constexpr void __process_parsed_bool(__parser<_CharT>& __parser) {
591 switch (__parser.__type_) {
592 case __format_spec::__type::__default:
593 case __format_spec::__type::__string:
594 __format_spec::__process_display_type_bool_string(__parser);
595 break;
966596
967#ifndef _LIBCPP_HAS_NO_UNICODE
968namespace __detail {
597 case __format_spec::__type::__binary_lower_case:
598 case __format_spec::__type::__binary_upper_case:
599 case __format_spec::__type::__octal:
600 case __format_spec::__type::__decimal:
601 case __format_spec::__type::__hexadecimal_lower_case:
602 case __format_spec::__type::__hexadecimal_upper_case:
603 break;
604
605 default:
606 std::__throw_format_error("The format-spec type has a type not supported for a bool argument");
607 }
608}
969609
970/**
971 * Unicode column width estimates.
972 *
973 * Unicode can be stored in several formats: UTF-8, UTF-16, and UTF-32.
974 * Depending on format the relation between the number of code units stored and
975 * the number of output columns differs. The first relation is the number of
976 * code units forming a code point. (The text assumes the code units are
977 * unsigned.)
978 * - UTF-8 The number of code units is between one and four. The first 127
979 * Unicode code points match the ASCII character set. When the highest bit is
980 * set it means the code point has more than one code unit.
981 * - UTF-16: The number of code units is between 1 and 2. When the first
982 * code unit is in the range [0xd800,0xdfff) it means the code point uses two
983 * code units.
984 * - UTF-32: The number of code units is always one.
985 *
986 * The code point to the number of columns isn't well defined. The code uses the
987 * estimations defined in [format.string.std]/11. This list might change in the
988 * future.
989 *
990 * The algorithm of @ref __get_string_alignment uses two different scanners:
991 * - The simple scanner @ref __estimate_column_width_fast. This scanner assumes
992 * 1 code unit is 1 column. This scanner stops when it can't be sure the
993 * assumption is valid:
994 * - UTF-8 when the code point is encoded in more than 1 code unit.
995 * - UTF-16 and UTF-32 when the first multi-column code point is encountered.
996 * (The code unit's value is lower than 0xd800 so the 2 code unit encoding
997 * is irrelevant for this scanner.)
998 * Due to these assumptions the scanner is faster than the full scanner. It
999 * can process all text only containing ASCII. For UTF-16/32 it can process
1000 * most (all?) European languages. (Note the set it can process might be
1001 * reduced in the future, due to updates in the scanning rules.)
1002 * - The full scanner @ref __estimate_column_width. This scanner, if needed,
1003 * converts multiple code units into one code point then converts the code
1004 * point to a column width.
1005 *
1006 * See also:
1007 * - [format.string.general]/11
1008 * - https://en.wikipedia.org/wiki/UTF-8#Encoding
1009 * - https://en.wikipedia.org/wiki/UTF-16#U+D800_to_U+DFFF
1010 */
1011
1012/**
1013 * The first 2 column code point.
1014 *
1015 * This is the point where the fast UTF-16/32 scanner needs to stop processing.
1016 */
1017inline constexpr uint32_t __two_column_code_point = 0x1100;
1018
1019/** Helper concept for an UTF-8 character type. */
1020610template <class _CharT>
1021concept __utf8_character = same_as<_CharT, char> || same_as<_CharT, char8_t>;
611_LIBCPP_HIDE_FROM_ABI constexpr void __process_parsed_char(__parser<_CharT>& __parser) {
612 switch (__parser.__type_) {
613 case __format_spec::__type::__default:
614 case __format_spec::__type::__char:
615 __format_spec::__process_display_type_char(__parser);
616 break;
617
618 case __format_spec::__type::__binary_lower_case:
619 case __format_spec::__type::__binary_upper_case:
620 case __format_spec::__type::__octal:
621 case __format_spec::__type::__decimal:
622 case __format_spec::__type::__hexadecimal_lower_case:
623 case __format_spec::__type::__hexadecimal_upper_case:
624 break;
625
626 default:
627 std::__throw_format_error("The format-spec type has a type not supported for a char argument");
628 }
629}
1022630
1023/** Helper concept for an UTF-16 character type. */
1024631template <class _CharT>
1025concept __utf16_character = (same_as<_CharT, wchar_t> && sizeof(wchar_t) == 2) || same_as<_CharT, char16_t>;
632_LIBCPP_HIDE_FROM_ABI constexpr void __process_parsed_integer(__parser<_CharT>& __parser) {
633 switch (__parser.__type_) {
634 case __format_spec::__type::__default:
635 case __format_spec::__type::__binary_lower_case:
636 case __format_spec::__type::__binary_upper_case:
637 case __format_spec::__type::__octal:
638 case __format_spec::__type::__decimal:
639 case __format_spec::__type::__hexadecimal_lower_case:
640 case __format_spec::__type::__hexadecimal_upper_case:
641 break;
642
643 case __format_spec::__type::__char:
644 __format_spec::__process_display_type_char(__parser);
645 break;
646
647 default:
648 std::__throw_format_error("The format-spec type has a type not supported for an integer argument");
649 }
650}
1026651
1027/** Helper concept for an UTF-32 character type. */
1028652template <class _CharT>
1029concept __utf32_character = (same_as<_CharT, wchar_t> && sizeof(wchar_t) == 4) || same_as<_CharT, char32_t>;
653_LIBCPP_HIDE_FROM_ABI constexpr void __process_parsed_floating_point(__parser<_CharT>& __parser) {
654 switch (__parser.__type_) {
655 case __format_spec::__type::__default:
656 // When no precision specified then it keeps default since that
657 // formatting differs from the other types.
658 if (__parser.__precision_as_arg_ || __parser.__precision_ != -1)
659 __parser.__type_ = __format_spec::__type::__general_lower_case;
660 break;
661 case __format_spec::__type::__hexfloat_lower_case:
662 case __format_spec::__type::__hexfloat_upper_case:
663 // Precision specific behavior will be handled later.
664 break;
665 case __format_spec::__type::__scientific_lower_case:
666 case __format_spec::__type::__scientific_upper_case:
667 case __format_spec::__type::__fixed_lower_case:
668 case __format_spec::__type::__fixed_upper_case:
669 case __format_spec::__type::__general_lower_case:
670 case __format_spec::__type::__general_upper_case:
671 if (!__parser.__precision_as_arg_ && __parser.__precision_ == -1)
672 // Set the default precision for the call to to_chars.
673 __parser.__precision_ = 6;
674 break;
675
676 default:
677 std::__throw_format_error("The format-spec type has a type not supported for a floating-point argument");
678 }
679}
680
681_LIBCPP_HIDE_FROM_ABI constexpr void __process_display_type_pointer(__format_spec::__type __type) {
682 switch (__type) {
683 case __format_spec::__type::__default:
684 case __format_spec::__type::__pointer:
685 break;
686
687 default:
688 std::__throw_format_error("The format-spec type has a type not supported for a pointer argument");
689 }
690}
1030691
1031/** Helper concept for an UTF-16 or UTF-32 character type. */
1032692template <class _CharT>
1033concept __utf16_or_32_character = __utf16_character<_CharT> || __utf32_character<_CharT>;
1034
1035/**
1036 * Converts a code point to the column width.
1037 *
1038 * The estimations are conforming to [format.string.general]/11
1039 *
1040 * This version expects a value less than 0x1'0000, which is a 3-byte UTF-8
1041 * character.
1042 */
1043_LIBCPP_HIDE_FROM_ABI inline constexpr int __column_width_3(uint32_t __c) noexcept {
1044 _LIBCPP_ASSERT(__c < 0x1'0000,
1045 "Use __column_width_4 or __column_width for larger values");
693struct __column_width_result {
694 /// The number of output columns.
695 size_t __width_;
696 /// One beyond the last code unit used in the estimation.
697 ///
698 /// This limits the original output to fit in the wanted number of columns.
699 const _CharT* __last_;
700};
701
702/// Since a column width can be two it's possible that the requested column
703/// width can't be achieved. Depending on the intended usage the policy can be
704/// selected.
705/// - When used as precision the maximum width may not be exceeded and the
706/// result should be "rounded down" to the previous boundary.
707/// - When used as a width we're done once the minimum is reached, but
708/// exceeding is not an issue. Rounding down is an issue since that will
709/// result in writing fill characters. Therefore the result needs to be
710/// "rounded up".
711enum class __column_width_rounding { __down, __up };
712
713# ifndef _LIBCPP_HAS_NO_UNICODE
714
715namespace __detail {
716
717/// Converts a code point to the column width.
718///
719/// The estimations are conforming to [format.string.general]/11
720///
721/// This version expects a value less than 0x1'0000, which is a 3-byte UTF-8
722/// character.
723_LIBCPP_HIDE_FROM_ABI constexpr int __column_width_3(uint32_t __c) noexcept {
724 _LIBCPP_ASSERT(__c < 0x10000, "Use __column_width_4 or __column_width for larger values");
1046725
1047726 // clang-format off
1048727 return 1 + (__c >= 0x1100 && (__c <= 0x115f ||
......@@ -1059,15 +738,12 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr int __column_width_3(uint32_t __c) noexce
1059738 // clang-format on
1060739}
1061740
1062/**
1063 * @overload
1064 *
1065 * This version expects a value greater than or equal to 0x1'0000, which is a
1066 * 4-byte UTF-8 character.
1067 */
1068_LIBCPP_HIDE_FROM_ABI inline constexpr int __column_width_4(uint32_t __c) noexcept {
1069 _LIBCPP_ASSERT(__c >= 0x1'0000,
1070 "Use __column_width_3 or __column_width for smaller values");
741/// @overload
742///
743/// This version expects a value greater than or equal to 0x1'0000, which is a
744/// 4-byte UTF-8 character.
745_LIBCPP_HIDE_FROM_ABI constexpr int __column_width_4(uint32_t __c) noexcept {
746 _LIBCPP_ASSERT(__c >= 0x10000, "Use __column_width_3 or __column_width for smaller values");
1071747
1072748 // clang-format off
1073749 return 1 + (__c >= 0x1'f300 && (__c <= 0x1'f64f ||
......@@ -1078,316 +754,148 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr int __column_width_4(uint32_t __c) noexce
1078754 // clang-format on
1079755}
1080756
1081/**
1082 * @overload
1083 *
1084 * The general case, accepting all values.
1085 */
1086_LIBCPP_HIDE_FROM_ABI inline constexpr int __column_width(uint32_t __c) noexcept {
1087 if (__c < 0x1'0000)
1088 return __column_width_3(__c);
757/// @overload
758///
759/// The general case, accepting all values.
760_LIBCPP_HIDE_FROM_ABI constexpr int __column_width(uint32_t __c) noexcept {
761 if (__c < 0x10000)
762 return __detail::__column_width_3(__c);
1089763
1090 return __column_width_4(__c);
1091}
1092
1093/**
1094 * Estimate the column width for the UTF-8 sequence using the fast algorithm.
1095 */
1096template <__utf8_character _CharT>
1097_LIBCPP_HIDE_FROM_ABI constexpr const _CharT*
1098__estimate_column_width_fast(const _CharT* __first,
1099 const _CharT* __last) noexcept {
1100 return _VSTD::find_if(__first, __last,
1101 [](unsigned char __c) { return __c & 0x80; });
1102}
1103
1104/**
1105 * @overload
1106 *
1107 * The implementation for UTF-16/32.
1108 */
1109template <__utf16_or_32_character _CharT>
1110_LIBCPP_HIDE_FROM_ABI constexpr const _CharT*
1111__estimate_column_width_fast(const _CharT* __first,
1112 const _CharT* __last) noexcept {
1113 return _VSTD::find_if(__first, __last,
1114 [](uint32_t __c) { return __c >= 0x1100; });
764 return __detail::__column_width_4(__c);
1115765}
1116766
1117767template <class _CharT>
1118struct _LIBCPP_TEMPLATE_VIS __column_width_result {
1119 /** The number of output columns. */
1120 size_t __width;
1121 /**
1122 * The last parsed element.
1123 *
1124 * This limits the original output to fit in the wanted number of columns.
1125 */
1126 const _CharT* __ptr;
1127};
1128
1129/**
1130 * Small helper to determine the width of malformed Unicode.
1131 *
1132 * @note This function's only needed for UTF-8. During scanning UTF-8 there
1133 * are multiple place where it can be detected that the Unicode is malformed.
1134 * UTF-16 only requires 1 test and UTF-32 requires no testing.
1135 */
1136template <__utf8_character _CharT>
1137_LIBCPP_HIDE_FROM_ABI constexpr __column_width_result<_CharT>
1138__estimate_column_width_malformed(const _CharT* __first, const _CharT* __last,
1139 size_t __maximum, size_t __result) noexcept {
1140 size_t __size = __last - __first;
1141 size_t __n = _VSTD::min(__size, __maximum);
1142 return {__result + __n, __first + __n};
1143}
768_LIBCPP_HIDE_FROM_ABI constexpr __column_width_result<_CharT> __estimate_column_width_grapheme_clustering(
769 const _CharT* __first, const _CharT* __last, size_t __maximum, __column_width_rounding __rounding) noexcept {
770 __unicode::__extended_grapheme_cluster_view<_CharT> __view{__first, __last};
1144771
1145/**
1146 * Determines the number of output columns needed to render the input.
1147 *
1148 * @note When the scanner encounters malformed Unicode it acts as-if every code
1149 * unit at the end of the input is one output column. It's expected the output
1150 * terminal will replace these malformed code units with a one column
1151 * replacement characters.
1152 *
1153 * @param __first Points to the first element of the input range.
1154 * @param __last Points beyond the last element of the input range.
1155 * @param __maximum The maximum number of output columns. The returned number
1156 * of estimated output columns will not exceed this value.
1157 */
1158template <__utf8_character _CharT>
1159_LIBCPP_HIDE_FROM_ABI constexpr __column_width_result<_CharT>
1160__estimate_column_width(const _CharT* __first, const _CharT* __last,
1161 size_t __maximum) noexcept {
1162 size_t __result = 0;
1163
1164 while (__first != __last) {
1165 // Based on the number of leading 1 bits the number of code units in the
1166 // code point can be determined. See
1167 // https://en.wikipedia.org/wiki/UTF-8#Encoding
1168 switch (_VSTD::countl_one(static_cast<unsigned char>(*__first))) {
1169 case 0: // 1-code unit encoding: all 1 column
1170 ++__result;
1171 ++__first;
1172 break;
772 __column_width_result<_CharT> __result{0, __first};
773 while (__result.__last_ != __last && __result.__width_ <= __maximum) {
774 typename __unicode::__extended_grapheme_cluster_view<_CharT>::__cluster __cluster = __view.__consume();
775 int __width = __detail::__column_width(__cluster.__code_point_);
1173776
1174 case 2: // 2-code unit encoding: all 1 column
1175 // Malformed Unicode.
1176 if (__last - __first < 2) [[unlikely]]
1177 return __estimate_column_width_malformed(__first, __last, __maximum,
1178 __result);
1179 __first += 2;
1180 ++__result;
1181 break;
777 // When the next entry would exceed the maximum width the previous width
778 // might be returned. For example when a width of 100 is requested the
779 // returned width might be 99, since the next code point has an estimated
780 // column width of 2. This depends on the rounding flag.
781 // When the maximum is exceeded the loop will abort the next iteration.
782 if (__rounding == __column_width_rounding::__down && __result.__width_ + __width > __maximum)
783 return __result;
1182784
1183 case 3: // 3-code unit encoding: either 1 or 2 columns
1184 // Malformed Unicode.
1185 if (__last - __first < 3) [[unlikely]]
1186 return __estimate_column_width_malformed(__first, __last, __maximum,
1187 __result);
1188 {
1189 uint32_t __c = static_cast<unsigned char>(*__first++) & 0x0f;
1190 __c <<= 6;
1191 __c |= static_cast<unsigned char>(*__first++) & 0x3f;
1192 __c <<= 6;
1193 __c |= static_cast<unsigned char>(*__first++) & 0x3f;
1194 __result += __column_width_3(__c);
1195 if (__result > __maximum)
1196 return {__result - 2, __first - 3};
1197 }
1198 break;
1199 case 4: // 4-code unit encoding: either 1 or 2 columns
1200 // Malformed Unicode.
1201 if (__last - __first < 4) [[unlikely]]
1202 return __estimate_column_width_malformed(__first, __last, __maximum,
1203 __result);
1204 {
1205 uint32_t __c = static_cast<unsigned char>(*__first++) & 0x07;
1206 __c <<= 6;
1207 __c |= static_cast<unsigned char>(*__first++) & 0x3f;
1208 __c <<= 6;
1209 __c |= static_cast<unsigned char>(*__first++) & 0x3f;
1210 __c <<= 6;
1211 __c |= static_cast<unsigned char>(*__first++) & 0x3f;
1212 __result += __column_width_4(__c);
1213 if (__result > __maximum)
1214 return {__result - 2, __first - 4};
1215 }
1216 break;
1217 default:
1218 // Malformed Unicode.
1219 return __estimate_column_width_malformed(__first, __last, __maximum,
1220 __result);
1221 }
1222
1223 if (__result >= __maximum)
1224 return {__result, __first};
785 __result.__width_ += __width;
786 __result.__last_ = __cluster.__last_;
1225787 }
1226 return {__result, __first};
1227}
1228788
1229template <__utf16_character _CharT>
1230_LIBCPP_HIDE_FROM_ABI constexpr __column_width_result<_CharT>
1231__estimate_column_width(const _CharT* __first, const _CharT* __last,
1232 size_t __maximum) noexcept {
1233 size_t __result = 0;
1234
1235 while (__first != __last) {
1236 uint32_t __c = *__first;
1237 // Is the code unit part of a surrogate pair? See
1238 // https://en.wikipedia.org/wiki/UTF-16#U+D800_to_U+DFFF
1239 if (__c >= 0xd800 && __c <= 0xDfff) {
1240 // Malformed Unicode.
1241 if (__last - __first < 2) [[unlikely]]
1242 return {__result + 1, __first + 1};
1243
1244 __c -= 0xd800;
1245 __c <<= 10;
1246 __c += (*(__first + 1) - 0xdc00);
1247 __c += 0x10'000;
1248
1249 __result += __column_width_4(__c);
1250 if (__result > __maximum)
1251 return {__result - 2, __first};
1252 __first += 2;
1253 } else {
1254 __result += __column_width_3(__c);
1255 if (__result > __maximum)
1256 return {__result - 2, __first};
1257 ++__first;
1258 }
1259
1260 if (__result >= __maximum)
1261 return {__result, __first};
1262 }
1263
1264 return {__result, __first};
1265}
1266
1267template <__utf32_character _CharT>
1268_LIBCPP_HIDE_FROM_ABI constexpr __column_width_result<_CharT>
1269__estimate_column_width(const _CharT* __first, const _CharT* __last,
1270 size_t __maximum) noexcept {
1271 size_t __result = 0;
1272
1273 while (__first != __last) {
1274 wchar_t __c = *__first;
1275 __result += __column_width(__c);
1276
1277 if (__result > __maximum)
1278 return {__result - 2, __first};
1279
1280 ++__first;
1281 if (__result >= __maximum)
1282 return {__result, __first};
1283 }
1284
1285 return {__result, __first};
789 return __result;
1286790}
1287791
1288792} // namespace __detail
1289793
794// Unicode can be stored in several formats: UTF-8, UTF-16, and UTF-32.
795// Depending on format the relation between the number of code units stored and
796// the number of output columns differs. The first relation is the number of
797// code units forming a code point. (The text assumes the code units are
798// unsigned.)
799// - UTF-8 The number of code units is between one and four. The first 127
800// Unicode code points match the ASCII character set. When the highest bit is
801// set it means the code point has more than one code unit.
802// - UTF-16: The number of code units is between 1 and 2. When the first
803// code unit is in the range [0xd800,0xdfff) it means the code point uses two
804// code units.
805// - UTF-32: The number of code units is always one.
806//
807// The code point to the number of columns is specified in
808// [format.string.std]/11. This list might change in the future.
809//
810// Another thing to be taken into account is Grapheme clustering. This means
811// that in some cases multiple code points are combined one element in the
812// output. For example:
813// - an ASCII character with a combined diacritical mark
814// - an emoji with a skin tone modifier
815// - a group of combined people emoji to create a family
816// - a combination of flag emoji
817//
818// See also:
819// - [format.string.general]/11
820// - https://en.wikipedia.org/wiki/UTF-8#Encoding
821// - https://en.wikipedia.org/wiki/UTF-16#U+D800_to_U+DFFF
822
823_LIBCPP_HIDE_FROM_ABI constexpr bool __is_ascii(char32_t __c) { return __c < 0x80; }
824
825/// Determines the number of output columns needed to render the input.
826///
827/// \note When the scanner encounters malformed Unicode it acts as-if every
828/// code unit is a one column code point. Typically a terminal uses the same
829/// strategy and replaces every malformed code unit with a one column
830/// replacement character.
831///
832/// \param __first Points to the first element of the input range.
833/// \param __last Points beyond the last element of the input range.
834/// \param __maximum The maximum number of output columns. The returned number
835/// of estimated output columns will not exceed this value.
836/// \param __rounding Selects the rounding method.
837/// \c __down result.__width_ <= __maximum
838/// \c __up result.__width_ <= __maximum + 1
1290839template <class _CharT>
1291_LIBCPP_HIDE_FROM_ABI constexpr __string_alignment<_CharT>
1292__get_string_alignment(const _CharT* __first, const _CharT* __last,
1293 ptrdiff_t __width, ptrdiff_t __precision) noexcept {
1294 _LIBCPP_ASSERT(__width != 0 || __precision != -1,
1295 "The function has no effect and shouldn't be used");
1296
1297 // TODO FMT There might be more optimizations possible:
1298 // If __precision == __format::__number_max and the encoding is:
1299 // * UTF-8 : 4 * (__last - __first) >= __width
1300 // * UTF-16 : 2 * (__last - __first) >= __width
1301 // * UTF-32 : (__last - __first) >= __width
1302 // In these cases it's certain the output is at least the requested width.
1303 // It's unknown how often this happens in practice. For now the improvement
1304 // isn't implemented.
1305
1306 /*
1307 * First assume there are no special Unicode code units in the input.
1308 * - Apply the precision (this may reduce the size of the input). When
1309 * __precison == -1 this step is omitted.
1310 * - Scan for special code units in the input.
1311 * If our assumption was correct the __pos will be at the end of the input.
1312 */
1313 const ptrdiff_t __length = __last - __first;
1314 const _CharT* __limit =
1315 __first +
1316 (__precision == -1 ? __length : _VSTD::min(__length, __precision));
1317 ptrdiff_t __size = __limit - __first;
1318 const _CharT* __pos =
1319 __detail::__estimate_column_width_fast(__first, __limit);
1320
1321 if (__pos == __limit)
1322 return {__limit, __size, __size < __width};
1323
1324 /*
1325 * Our assumption was wrong, there are special Unicode code units.
1326 * The range [__first, __pos) contains a set of code units with the
1327 * following property:
1328 * Every _CharT in the range will be rendered in 1 column.
1329 *
1330 * If there's no maximum width and the parsed size already exceeds the
1331 * minimum required width. The real size isn't important. So bail out.
1332 */
1333 if (__precision == -1 && (__pos - __first) >= __width)
1334 return {__last, 0, false};
1335
1336 /* If there's a __precision, truncate the output to that width. */
1337 ptrdiff_t __prefix = __pos - __first;
1338 if (__precision != -1) {
1339 _LIBCPP_ASSERT(__precision > __prefix, "Logic error.");
1340 auto __lengh_info = __detail::__estimate_column_width(
1341 __pos, __last, __precision - __prefix);
1342 __size = __lengh_info.__width + __prefix;
1343 return {__lengh_info.__ptr, __size, __size < __width};
840_LIBCPP_HIDE_FROM_ABI constexpr __column_width_result<_CharT> __estimate_column_width(
841 basic_string_view<_CharT> __str, size_t __maximum, __column_width_rounding __rounding) noexcept {
842 // The width estimation is done in two steps:
843 // - Quickly process for the ASCII part. ASCII has the following properties
844 // - One code unit is one code point
845 // - Every code point has an estimated width of one
846 // - When needed it will a Unicode Grapheme clustering algorithm to find
847 // the proper place for truncation.
848
849 if (__str.empty() || __maximum == 0)
850 return {0, __str.begin()};
851
852 // ASCII has one caveat; when an ASCII character is followed by a non-ASCII
853 // character they might be part of an extended grapheme cluster. For example:
854 // an ASCII letter and a COMBINING ACUTE ACCENT
855 // The truncate should happen after the COMBINING ACUTE ACCENT. Therefore we
856 // need to scan one code unit beyond the requested precision. When this code
857 // unit is non-ASCII we omit the current code unit and let the Grapheme
858 // clustering algorithm do its work.
859 const _CharT* __it = __str.begin();
860 if (__is_ascii(*__it)) {
861 do {
862 --__maximum;
863 ++__it;
864 if (__it == __str.end())
865 return {__str.size(), __str.end()};
866
867 if (__maximum == 0) {
868 if (__is_ascii(*__it))
869 return {static_cast<size_t>(__it - __str.begin()), __it};
870
871 break;
872 }
873 } while (__is_ascii(*__it));
874 --__it;
875 ++__maximum;
1344876 }
1345877
1346 /* Else use __width to determine the number of required padding characters. */
1347 _LIBCPP_ASSERT(__width > __prefix, "Logic error.");
1348 /*
1349 * The column width is always one or two columns. For the precision the wanted
1350 * column width is the maximum, for the width it's the minimum. Using the
1351 * width estimation with its truncating behavior will result in the wrong
1352 * result in the following case:
1353 * - The last code unit processed requires two columns and exceeds the
1354 * maximum column width.
1355 * By increasing the __maximum by one avoids this issue. (It means it may
1356 * pass one code point more than required to determine the proper result;
1357 * that however isn't a problem for the algorithm.)
1358 */
1359 size_t __maximum = 1 + __width - __prefix;
1360 auto __lengh_info =
1361 __detail::__estimate_column_width(__pos, __last, __maximum);
1362 if (__lengh_info.__ptr != __last) {
1363 // Consumed the width number of code units. The exact size of the string
1364 // is unknown. We only know we don't need to align the output.
1365 _LIBCPP_ASSERT(static_cast<ptrdiff_t>(__lengh_info.__width + __prefix) >=
1366 __width,
1367 "Logic error");
1368 return {__last, 0, false};
1369 }
878 ptrdiff_t __ascii_size = __it - __str.begin();
879 __column_width_result __result =
880 __detail::__estimate_column_width_grapheme_clustering(__it, __str.end(), __maximum, __rounding);
1370881
1371 __size = __lengh_info.__width + __prefix;
1372 return {__last, __size, __size < __width};
882 __result.__width_ += __ascii_size;
883 return __result;
1373884}
1374#else // _LIBCPP_HAS_NO_UNICODE
885# else // !defined(_LIBCPP_HAS_NO_UNICODE)
1375886template <class _CharT>
1376_LIBCPP_HIDE_FROM_ABI constexpr __string_alignment<_CharT>
1377__get_string_alignment(const _CharT* __first, const _CharT* __last,
1378 ptrdiff_t __width, ptrdiff_t __precision) noexcept {
1379 const ptrdiff_t __length = __last - __first;
1380 const _CharT* __limit =
1381 __first +
1382 (__precision == -1 ? __length : _VSTD::min(__length, __precision));
1383 ptrdiff_t __size = __limit - __first;
1384 return {__limit, __size, __size < __width};
887_LIBCPP_HIDE_FROM_ABI constexpr __column_width_result<_CharT>
888__estimate_column_width(basic_string_view<_CharT> __str, size_t __maximum, __column_width_rounding) noexcept {
889 // When Unicode isn't supported assume ASCII and every code unit is one code
890 // point. In ASCII the estimated column width is always one. Thus there's no
891 // need for rounding.
892 size_t __width_ = _VSTD::min(__str.size(), __maximum);
893 return {__width_, __str.begin() + __width_};
1385894}
1386#endif // _LIBCPP_HAS_NO_UNICODE
1387895
1388} // namespace __format_spec
896# endif // !defined(_LIBCPP_HAS_NO_UNICODE)
1389897
1390# endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
898} // namespace __format_spec
1391899
1392900#endif //_LIBCPP_STD_VER > 17
1393901
lib/libcxx/include/__format/unicode.h created+339
......@@ -0,0 +1,339 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___FORMAT_UNICODE_H
11#define _LIBCPP___FORMAT_UNICODE_H
12
13#include <__assert>
14#include <__config>
15#include <__format/extended_grapheme_cluster_table.h>
16#include <__utility/unreachable.h>
17#include <bit>
18
19#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20# pragma GCC system_header
21#endif
22
23_LIBCPP_BEGIN_NAMESPACE_STD
24
25#if _LIBCPP_STD_VER > 17
26
27# ifndef _LIBCPP_HAS_NO_UNICODE
28
29/// Implements the grapheme cluster boundary rules
30///
31/// These rules are used to implement format's width estimation as stated in
32/// [format.string.std]/11
33///
34/// The Standard refers to UAX \#29 for Unicode 12.0.0
35/// https://www.unicode.org/reports/tr29/#Grapheme_Cluster_Boundary_Rules
36///
37/// The data tables used are
38/// https://www.unicode.org/Public/UCD/latest/ucd/auxiliary/GraphemeBreakProperty.txt
39/// https://www.unicode.org/Public/UCD/latest/ucd/emoji/emoji-data.txt
40/// https://www.unicode.org/Public/UCD/latest/ucd/auxiliary/GraphemeBreakTest.txt (for testing only)
41
42namespace __unicode {
43
44inline constexpr char32_t __replacement_character = U'\ufffd';
45
46_LIBCPP_HIDE_FROM_ABI constexpr bool __is_continuation(const char* __char, int __count) {
47 do {
48 if ((*__char & 0b1000'0000) != 0b1000'0000)
49 return false;
50 --__count;
51 ++__char;
52 } while (__count);
53 return true;
54}
55
56/// Helper class to extract a code unit from a Unicode character range.
57///
58/// The stored range is a view. There are multiple specialization for different
59/// character types.
60template <class _CharT>
61class __code_point_view;
62
63/// UTF-8 specialization.
64template <>
65class __code_point_view<char> {
66public:
67 _LIBCPP_HIDE_FROM_ABI constexpr explicit __code_point_view(const char* __first, const char* __last)
68 : __first_(__first), __last_(__last) {}
69
70 _LIBCPP_HIDE_FROM_ABI constexpr bool __at_end() const noexcept { return __first_ == __last_; }
71 _LIBCPP_HIDE_FROM_ABI constexpr const char* __position() const noexcept { return __first_; }
72
73 _LIBCPP_HIDE_FROM_ABI constexpr char32_t __consume() noexcept {
74 _LIBCPP_ASSERT(__first_ != __last_, "can't move beyond the end of input");
75
76 // Based on the number of leading 1 bits the number of code units in the
77 // code point can be determined. See
78 // https://en.wikipedia.org/wiki/UTF-8#Encoding
79 switch (_VSTD::countl_one(static_cast<unsigned char>(*__first_))) {
80 case 0:
81 return *__first_++;
82
83 case 2:
84 if (__last_ - __first_ < 2 || !__unicode::__is_continuation(__first_ + 1, 1)) [[unlikely]]
85 break;
86 else {
87 char32_t __value = static_cast<unsigned char>(*__first_++) & 0x1f;
88 __value <<= 6;
89 __value |= static_cast<unsigned char>(*__first_++) & 0x3f;
90 return __value;
91 }
92
93 case 3:
94 if (__last_ - __first_ < 3 || !__unicode::__is_continuation(__first_ + 1, 2)) [[unlikely]]
95 break;
96 else {
97 char32_t __value = static_cast<unsigned char>(*__first_++) & 0x0f;
98 __value <<= 6;
99 __value |= static_cast<unsigned char>(*__first_++) & 0x3f;
100 __value <<= 6;
101 __value |= static_cast<unsigned char>(*__first_++) & 0x3f;
102 return __value;
103 }
104
105 case 4:
106 if (__last_ - __first_ < 4 || !__unicode::__is_continuation(__first_ + 1, 3)) [[unlikely]]
107 break;
108 else {
109 char32_t __value = static_cast<unsigned char>(*__first_++) & 0x07;
110 __value <<= 6;
111 __value |= static_cast<unsigned char>(*__first_++) & 0x3f;
112 __value <<= 6;
113 __value |= static_cast<unsigned char>(*__first_++) & 0x3f;
114 __value <<= 6;
115 __value |= static_cast<unsigned char>(*__first_++) & 0x3f;
116 return __value;
117 }
118 }
119 // An invalid number of leading ones can be garbage or a code unit in the
120 // middle of a code point. By consuming one code unit the parser may get
121 // "in sync" after a few code units.
122 ++__first_;
123 return __replacement_character;
124 }
125
126private:
127 const char* __first_;
128 const char* __last_;
129};
130
131# ifndef TEST_HAS_NO_WIDE_CHARACTERS
132/// This specialization depends on the size of wchar_t
133/// - 2 UTF-16 (for example Windows and AIX)
134/// - 4 UTF-32 (for example Linux)
135template <>
136class __code_point_view<wchar_t> {
137public:
138 _LIBCPP_HIDE_FROM_ABI constexpr explicit __code_point_view(const wchar_t* __first, const wchar_t* __last)
139 : __first_(__first), __last_(__last) {}
140
141 _LIBCPP_HIDE_FROM_ABI constexpr const wchar_t* __position() const noexcept { return __first_; }
142 _LIBCPP_HIDE_FROM_ABI constexpr bool __at_end() const noexcept { return __first_ == __last_; }
143
144 _LIBCPP_HIDE_FROM_ABI constexpr char32_t __consume() noexcept {
145 _LIBCPP_ASSERT(__first_ != __last_, "can't move beyond the end of input");
146
147 if constexpr (sizeof(wchar_t) == 2) {
148 char32_t __result = *__first_++;
149 // Is the code unit part of a surrogate pair? See
150 // https://en.wikipedia.org/wiki/UTF-16#U+D800_to_U+DFFF
151 if (__result >= 0xd800 && __result <= 0xDfff) {
152 // Malformed Unicode.
153 if (__first_ == __last_) [[unlikely]]
154 return __replacement_character;
155
156 __result -= 0xd800;
157 __result <<= 10;
158 __result += *__first_++ - 0xdc00;
159 __result += 0x10000;
160 }
161 return __result;
162
163 } else if constexpr (sizeof(wchar_t) == 4) {
164 char32_t __result = *__first_++;
165 if (__result > 0x10FFFF) [[unlikely]]
166 return __replacement_character;
167 return __result;
168 } else {
169 // TODO FMT P2593R0 Use static_assert(false, "sizeof(wchar_t) has a not implemented value");
170 _LIBCPP_ASSERT(sizeof(wchar_t) == 0, "sizeof(wchar_t) has a not implemented value");
171 __libcpp_unreachable();
172 }
173 }
174
175private:
176 const wchar_t* __first_;
177 const wchar_t* __last_;
178};
179# endif
180
181_LIBCPP_HIDE_FROM_ABI constexpr bool __at_extended_grapheme_cluster_break(
182 bool& __ri_break_allowed,
183 bool __has_extened_pictographic,
184 __extended_grapheme_custer_property_boundary::__property __prev,
185 __extended_grapheme_custer_property_boundary::__property __next) {
186 using __extended_grapheme_custer_property_boundary::__property;
187
188 __has_extened_pictographic |= __prev == __property::__Extended_Pictographic;
189
190 // https://www.unicode.org/reports/tr29/tr29-39.html#Grapheme_Cluster_Boundary_Rules
191
192 // *** Break at the start and end of text, unless the text is empty. ***
193
194 _LIBCPP_ASSERT(__prev != __property::__sot, "should be handled in the constructor"); // GB1
195 _LIBCPP_ASSERT(__prev != __property::__eot, "should be handled by our caller"); // GB2
196
197 // *** Do not break between a CR and LF. Otherwise, break before and after controls. ***
198 if (__prev == __property::__CR && __next == __property::__LF) // GB3
199 return false;
200
201 if (__prev == __property::__Control || __prev == __property::__CR || __prev == __property::__LF) // GB4
202 return true;
203
204 if (__next == __property::__Control || __next == __property::__CR || __next == __property::__LF) // GB5
205 return true;
206
207 // *** Do not break Hangul syllable sequences. ***
208 if (__prev == __property::__L &&
209 (__next == __property::__L || __next == __property::__V || __next == __property::__LV ||
210 __next == __property::__LVT)) // GB6
211 return false;
212
213 if ((__prev == __property::__LV || __prev == __property::__V) &&
214 (__next == __property::__V || __next == __property::__T)) // GB7
215 return false;
216
217 if ((__prev == __property::__LVT || __prev == __property::__T) && __next == __property::__T) // GB8
218 return false;
219
220 // *** Do not break before extending characters or ZWJ. ***
221 if (__next == __property::__Extend || __next == __property::__ZWJ)
222 return false; // GB9
223
224 // *** Do not break before SpacingMarks, or after Prepend characters. ***
225 if (__next == __property::__SpacingMark) // GB9a
226 return false;
227
228 if (__prev == __property::__Prepend) // GB9b
229 return false;
230
231 // *** Do not break within emoji modifier sequences or emoji zwj sequences. ***
232
233 // GB11 \p{Extended_Pictographic} Extend* ZWJ x \p{Extended_Pictographic}
234 //
235 // Note that several parts of this rule are matched by GB9: Any x (Extend | ZWJ)
236 // - \p{Extended_Pictographic} x Extend
237 // - Extend x Extend
238 // - \p{Extended_Pictographic} x ZWJ
239 // - Extend x ZWJ
240 //
241 // So the only case left to test is
242 // - \p{Extended_Pictographic}' x ZWJ x \p{Extended_Pictographic}
243 // where \p{Extended_Pictographic}' is stored in __has_extened_pictographic
244 if (__has_extened_pictographic && __prev == __property::__ZWJ && __next == __property::__Extended_Pictographic)
245 return false;
246
247 // *** Do not break within emoji flag sequences ***
248
249 // That is, do not break between regional indicator (RI) symbols if there
250 // is an odd number of RI characters before the break point.
251
252 if (__prev == __property::__Regional_Indicator && __next == __property::__Regional_Indicator) { // GB12 + GB13
253 __ri_break_allowed = !__ri_break_allowed;
254 if (__ri_break_allowed)
255 return true;
256
257 return false;
258 }
259
260 // *** Otherwise, break everywhere. ***
261 return true; // GB999
262}
263
264/// Helper class to extract an extended grapheme cluster from a Unicode character range.
265///
266/// This function is used to determine the column width of an extended grapheme
267/// cluster. In order to do that only the first code point is evaluated.
268/// Therefore only this code point is extracted.
269template <class _CharT>
270class __extended_grapheme_cluster_view {
271public:
272 _LIBCPP_HIDE_FROM_ABI constexpr explicit __extended_grapheme_cluster_view(const _CharT* __first, const _CharT* __last)
273 : __code_point_view_(__first, __last),
274 __next_code_point_(__code_point_view_.__consume()),
275 __next_prop_(__extended_grapheme_custer_property_boundary::__get_property(__next_code_point_)) {}
276
277 struct __cluster {
278 /// The first code point of the extended grapheme cluster.
279 ///
280 /// The first code point is used to estimate the width of the extended
281 /// grapheme cluster.
282 char32_t __code_point_;
283
284 /// Points one beyond the last code unit in the extended grapheme cluster.
285 ///
286 /// It's expected the caller has the start position and thus can determine
287 /// the code unit range of the extended grapheme cluster.
288 const _CharT* __last_;
289 };
290
291 _LIBCPP_HIDE_FROM_ABI constexpr __cluster __consume() {
292 _LIBCPP_ASSERT(
293 __next_prop_ != __extended_grapheme_custer_property_boundary::__property::__eot,
294 "can't move beyond the end of input");
295 char32_t __code_point = __next_code_point_;
296 if (!__code_point_view_.__at_end())
297 return {__code_point, __get_break()};
298
299 __next_prop_ = __extended_grapheme_custer_property_boundary::__property::__eot;
300 return {__code_point, __code_point_view_.__position()};
301 }
302
303private:
304 __code_point_view<_CharT> __code_point_view_;
305
306 char32_t __next_code_point_;
307 __extended_grapheme_custer_property_boundary::__property __next_prop_;
308
309 _LIBCPP_HIDE_FROM_ABI constexpr const _CharT* __get_break() {
310 bool __ri_break_allowed = true;
311 bool __has_extened_pictographic = false;
312 while (true) {
313 const _CharT* __result = __code_point_view_.__position();
314 __extended_grapheme_custer_property_boundary::__property __prev = __next_prop_;
315 if (__code_point_view_.__at_end()) {
316 __next_prop_ = __extended_grapheme_custer_property_boundary::__property::__eot;
317 return __result;
318 }
319 __next_code_point_ = __code_point_view_.__consume();
320 __next_prop_ = __extended_grapheme_custer_property_boundary::__get_property(__next_code_point_);
321
322 __has_extened_pictographic |=
323 __prev == __extended_grapheme_custer_property_boundary::__property::__Extended_Pictographic;
324
325 if (__at_extended_grapheme_cluster_break(__ri_break_allowed, __has_extened_pictographic, __prev, __next_prop_))
326 return __result;
327 }
328 }
329};
330
331} // namespace __unicode
332
333# endif // _LIBCPP_HAS_NO_UNICODE
334
335#endif //_LIBCPP_STD_VER > 17
336
337_LIBCPP_END_NAMESPACE_STD
338
339#endif // _LIBCPP___FORMAT_UNICODE_H
lib/libcxx/include/__functional/binary_function.h+25-2
......@@ -13,19 +13,42 @@
1313#include <__config>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16#pragma GCC system_header
16# pragma GCC system_header
1717#endif
1818
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
21#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION)
22
2123template <class _Arg1, class _Arg2, class _Result>
22struct _LIBCPP_TEMPLATE_VIS binary_function
24struct _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binary_function
2325{
2426 typedef _Arg1 first_argument_type;
2527 typedef _Arg2 second_argument_type;
2628 typedef _Result result_type;
2729};
2830
31#endif // _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION)
32
33template <class _Arg1, class _Arg2, class _Result> struct __binary_function_keep_layout_base {
34#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
35 using first_argument_type _LIBCPP_DEPRECATED_IN_CXX17 = _Arg1;
36 using second_argument_type _LIBCPP_DEPRECATED_IN_CXX17 = _Arg2;
37 using result_type _LIBCPP_DEPRECATED_IN_CXX17 = _Result;
38#endif
39};
40
41#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION)
42_LIBCPP_DIAGNOSTIC_PUSH
43_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
44template <class _Arg1, class _Arg2, class _Result>
45using __binary_function = binary_function<_Arg1, _Arg2, _Result>;
46_LIBCPP_DIAGNOSTIC_POP
47#else
48template <class _Arg1, class _Arg2, class _Result>
49using __binary_function = __binary_function_keep_layout_base<_Arg1, _Arg2, _Result>;
50#endif
51
2952_LIBCPP_END_NAMESPACE_STD
3053
3154#endif // _LIBCPP___FUNCTIONAL_BINARY_FUNCTION_H
lib/libcxx/include/__functional/binary_negate.h+4-4
......@@ -14,7 +14,7 @@
1414#include <__functional/binary_function.h>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
17# pragma GCC system_header
1818#endif
1919
2020_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -23,9 +23,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2323
2424template <class _Predicate>
2525class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 binary_negate
26 : public binary_function<typename _Predicate::first_argument_type,
27 typename _Predicate::second_argument_type,
28 bool>
26 : public __binary_function<typename _Predicate::first_argument_type,
27 typename _Predicate::second_argument_type,
28 bool>
2929{
3030 _Predicate __pred_;
3131public:
lib/libcxx/include/__functional/bind.h+6-9
......@@ -18,16 +18,16 @@
1818#include <type_traits>
1919
2020#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21#pragma GCC system_header
21# pragma GCC system_header
2222#endif
2323
2424_LIBCPP_BEGIN_NAMESPACE_STD
2525
2626template<class _Tp>
2727struct is_bind_expression : _If<
28 _IsSame<_Tp, typename __uncvref<_Tp>::type>::value,
28 _IsSame<_Tp, __uncvref_t<_Tp> >::value,
2929 false_type,
30 is_bind_expression<typename __uncvref<_Tp>::type>
30 is_bind_expression<__uncvref_t<_Tp> >
3131> {};
3232
3333#if _LIBCPP_STD_VER > 14
......@@ -37,9 +37,9 @@ inline constexpr size_t is_bind_expression_v = is_bind_expression<_Tp>::value;
3737
3838template<class _Tp>
3939struct is_placeholder : _If<
40 _IsSame<_Tp, typename __uncvref<_Tp>::type>::value,
40 _IsSame<_Tp, __uncvref_t<_Tp> >::value,
4141 integral_constant<int, 0>,
42 is_placeholder<typename __uncvref<_Tp>::type>
42 is_placeholder<__uncvref_t<_Tp> >
4343> {};
4444
4545#if _LIBCPP_STD_VER > 14
......@@ -264,10 +264,7 @@ __apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
264264}
265265
266266template<class _Fp, class ..._BoundArgs>
267class __bind
268#if _LIBCPP_STD_VER <= 17 || !defined(_LIBCPP_ABI_NO_BINDER_BASES)
269 : public __weak_result_type<typename decay<_Fp>::type>
270#endif
267class __bind : public __weak_result_type<typename decay<_Fp>::type>
271268{
272269protected:
273270 typedef typename decay<_Fp>::type _Fd;
lib/libcxx/include/__functional/bind_back.h+6-7
......@@ -19,7 +19,7 @@
1919#include <type_traits>
2020
2121#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22#pragma GCC system_header
22# pragma GCC system_header
2323#endif
2424
2525_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -31,12 +31,11 @@ struct __bind_back_op;
3131
3232template <size_t _NBound, size_t ..._Ip>
3333struct __bind_back_op<_NBound, index_sequence<_Ip...>> {
34 template <class _Fn, class _Bound, class ..._Args>
35 _LIBCPP_HIDE_FROM_ABI
36 constexpr auto operator()(_Fn&& __f, _Bound&& __bound, _Args&& ...__args) const
37 noexcept(noexcept(_VSTD::invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)..., _VSTD::get<_Ip>(_VSTD::forward<_Bound>(__bound))...)))
38 -> decltype( _VSTD::invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)..., _VSTD::get<_Ip>(_VSTD::forward<_Bound>(__bound))...))
39 { return _VSTD::invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)..., _VSTD::get<_Ip>(_VSTD::forward<_Bound>(__bound))...); }
34 template <class _Fn, class _BoundArgs, class... _Args>
35 _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Fn&& __f, _BoundArgs&& __bound_args, _Args&&... __args) const
36 noexcept(noexcept(_VSTD::invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)..., _VSTD::get<_Ip>(_VSTD::forward<_BoundArgs>(__bound_args))...)))
37 -> decltype( _VSTD::invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)..., _VSTD::get<_Ip>(_VSTD::forward<_BoundArgs>(__bound_args))...))
38 { return _VSTD::invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)..., _VSTD::get<_Ip>(_VSTD::forward<_BoundArgs>(__bound_args))...); }
4039};
4140
4241template <class _Fn, class _BoundArgs>
lib/libcxx/include/__functional/bind_front.h+2-2
......@@ -13,11 +13,11 @@
1313#include <__config>
1414#include <__functional/invoke.h>
1515#include <__functional/perfect_forward.h>
16#include <__utility/forward.h>
1617#include <type_traits>
17#include <utility>
1818
1919#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20#pragma GCC system_header
20# pragma GCC system_header
2121#endif
2222
2323_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__functional/binder1st.h+2-3
......@@ -14,7 +14,7 @@
1414#include <__functional/unary_function.h>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
17# pragma GCC system_header
1818#endif
1919
2020_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -23,8 +23,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2323
2424template <class __Operation>
2525class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binder1st
26 : public unary_function<typename __Operation::second_argument_type,
27 typename __Operation::result_type>
26 : public __unary_function<typename __Operation::second_argument_type, typename __Operation::result_type>
2827{
2928protected:
3029 __Operation op;
lib/libcxx/include/__functional/binder2nd.h+2-3
......@@ -14,7 +14,7 @@
1414#include <__functional/unary_function.h>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
17# pragma GCC system_header
1818#endif
1919
2020_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -23,8 +23,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2323
2424template <class __Operation>
2525class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binder2nd
26 : public unary_function<typename __Operation::first_argument_type,
27 typename __Operation::result_type>
26 : public __unary_function<typename __Operation::first_argument_type, typename __Operation::result_type>
2827{
2928protected:
3029 __Operation op;
lib/libcxx/include/__functional/boyer_moore_searcher.h created+313
......@@ -0,0 +1,313 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___FUNCTIONAL_BOYER_MOORE_SEARCHER_H
10#define _LIBCPP___FUNCTIONAL_BOYER_MOORE_SEARCHER_H
11
12#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
13# pragma GCC system_header
14#endif
15
16#include <__algorithm/fill_n.h>
17#include <__config>
18#include <__functional/hash.h>
19#include <__functional/operations.h>
20#include <__iterator/distance.h>
21#include <__iterator/iterator_traits.h>
22#include <__memory/shared_ptr.h>
23#include <__utility/pair.h>
24#include <array>
25#include <unordered_map>
26#include <vector>
27
28#if _LIBCPP_STD_VER > 14
29
30_LIBCPP_PUSH_MACROS
31#include <__undef_macros>
32
33_LIBCPP_BEGIN_NAMESPACE_STD
34
35template <class _Key,
36 class _Value,
37 class _Hash,
38 class _BinaryPredicate,
39 bool /*useArray*/>
40class _BMSkipTable;
41
42// General case for BM data searching; use a map
43template <class _Key,
44 class _Value,
45 class _Hash,
46 class _BinaryPredicate>
47class _BMSkipTable<_Key, _Value, _Hash, _BinaryPredicate, false> {
48private:
49 using value_type = _Value;
50 using key_type = _Key;
51
52 const value_type __default_value_;
53 unordered_map<_Key, _Value, _Hash, _BinaryPredicate> __table_;
54
55public:
56 _LIBCPP_HIDE_FROM_ABI
57 explicit _BMSkipTable(size_t __sz, value_type __default_value, _Hash __hash, _BinaryPredicate __pred)
58 : __default_value_(__default_value),
59 __table_(__sz, __hash, __pred) {}
60
61 _LIBCPP_HIDE_FROM_ABI void insert(const key_type& __key, value_type __val) {
62 __table_[__key] = __val;
63 }
64
65 _LIBCPP_HIDE_FROM_ABI value_type operator[](const key_type& __key) const {
66 auto __it = __table_.find(__key);
67 return __it == __table_.end() ? __default_value_ : __it->second;
68 }
69};
70
71// Special case small numeric values; use an array
72template <class _Key,
73 class _Value,
74 class _Hash,
75 class _BinaryPredicate>
76class _BMSkipTable<_Key, _Value, _Hash, _BinaryPredicate, true> {
77private:
78 using value_type = _Value;
79 using key_type = _Key;
80
81 using unsigned_key_type = make_unsigned_t<key_type>;
82 std::array<value_type, 256> __table_;
83 static_assert(numeric_limits<unsigned_key_type>::max() < 256);
84
85public:
86 _LIBCPP_HIDE_FROM_ABI explicit _BMSkipTable(size_t, value_type __default_value, _Hash, _BinaryPredicate) {
87 std::fill_n(__table_.data(), __table_.size(), __default_value);
88 }
89
90 _LIBCPP_HIDE_FROM_ABI void insert(key_type __key, value_type __val) {
91 __table_[static_cast<unsigned_key_type>(__key)] = __val;
92 }
93
94 _LIBCPP_HIDE_FROM_ABI value_type operator[](key_type __key) const {
95 return __table_[static_cast<unsigned_key_type>(__key)];
96 }
97};
98
99template <class _RandomAccessIterator1,
100 class _Hash = hash<typename iterator_traits<_RandomAccessIterator1>::value_type>,
101 class _BinaryPredicate = equal_to<>>
102class _LIBCPP_TEMPLATE_VIS boyer_moore_searcher {
103private:
104 using difference_type = typename std::iterator_traits<_RandomAccessIterator1>::difference_type;
105 using value_type = typename std::iterator_traits<_RandomAccessIterator1>::value_type;
106 using __skip_table_type = _BMSkipTable<value_type,
107 difference_type,
108 _Hash,
109 _BinaryPredicate,
110 is_integral_v<value_type>
111 && sizeof(value_type) == 1
112 && is_same_v<_Hash, hash<value_type>>
113 && is_same_v<_BinaryPredicate, equal_to<>>>;
114
115public:
116 boyer_moore_searcher(_RandomAccessIterator1 __first,
117 _RandomAccessIterator1 __last,
118 _Hash __hash = _Hash(),
119 _BinaryPredicate __pred = _BinaryPredicate())
120 : __first_(__first),
121 __last_(__last),
122 __pred_(__pred),
123 __pattern_length_(__last - __first),
124 __skip_table_(std::make_shared<__skip_table_type>(__pattern_length_, -1, __hash, __pred_)),
125 __suffix_(std::__allocate_shared_unbounded_array<difference_type[]>(
126 allocator<difference_type>(), __pattern_length_ + 1)) {
127 difference_type __i = 0;
128 while (__first != __last) {
129 __skip_table_->insert(*__first, __i);
130 ++__first;
131 ++__i;
132 }
133 __build_suffix_table(__first_, __last_, __pred_);
134 }
135
136 template <class _RandomAccessIterator2>
137 pair<_RandomAccessIterator2, _RandomAccessIterator2>
138 operator()(_RandomAccessIterator2 __first, _RandomAccessIterator2 __last) const {
139 static_assert(__is_same_uncvref<typename iterator_traits<_RandomAccessIterator1>::value_type,
140 typename iterator_traits<_RandomAccessIterator2>::value_type>::value,
141 "Corpus and Pattern iterators must point to the same type");
142 if (__first == __last)
143 return std::make_pair(__last, __last);
144 if (__first_ == __last_)
145 return std::make_pair(__first, __first);
146
147 if (__pattern_length_ > (__last - __first))
148 return std::make_pair(__last, __last);
149 return __search(__first, __last);
150 }
151
152private:
153 _RandomAccessIterator1 __first_;
154 _RandomAccessIterator1 __last_;
155 _BinaryPredicate __pred_;
156 difference_type __pattern_length_;
157 shared_ptr<__skip_table_type> __skip_table_;
158 shared_ptr<difference_type[]> __suffix_;
159
160 template <class _RandomAccessIterator2>
161 pair<_RandomAccessIterator2, _RandomAccessIterator2>
162 __search(_RandomAccessIterator2 __f, _RandomAccessIterator2 __l) const {
163 _RandomAccessIterator2 __current = __f;
164 const _RandomAccessIterator2 __last = __l - __pattern_length_;
165 const __skip_table_type& __skip_table = *__skip_table_;
166
167 while (__current <= __last) {
168 difference_type __j = __pattern_length_;
169 while (__pred_(__first_[__j - 1], __current[__j - 1])) {
170 --__j;
171 if (__j == 0)
172 return std::make_pair(__current, __current + __pattern_length_);
173 }
174
175 difference_type __k = __skip_table[__current[__j - 1]];
176 difference_type __m = __j - __k - 1;
177 if (__k < __j && __m > __suffix_[__j])
178 __current += __m;
179 else
180 __current += __suffix_[__j];
181 }
182 return std::make_pair(__l, __l);
183 }
184
185 template <class _Iterator, class _Container>
186 void __compute_bm_prefix(_Iterator __first, _Iterator __last, _BinaryPredicate __pred, _Container& __prefix) {
187 const size_t __count = __last - __first;
188
189 __prefix[0] = 0;
190 size_t __k = 0;
191
192 for (size_t __i = 1; __i != __count; ++__i) {
193 while (__k > 0 && !__pred(__first[__k], __first[__i]))
194 __k = __prefix[__k - 1];
195
196 if (__pred(__first[__k], __first[__i]))
197 ++__k;
198 __prefix[__i] = __k;
199 }
200 }
201
202 void __build_suffix_table(_RandomAccessIterator1 __first, _RandomAccessIterator1 __last, _BinaryPredicate __pred) {
203 const size_t __count = __last - __first;
204
205 if (__count == 0)
206 return;
207
208 vector<difference_type> __scratch(__count);
209
210 __compute_bm_prefix(__first, __last, __pred, __scratch);
211 for (size_t __i = 0; __i <= __count; ++__i)
212 __suffix_[__i] = __count - __scratch[__count - 1];
213
214 using _ReverseIter = reverse_iterator<_RandomAccessIterator1>;
215 __compute_bm_prefix(_ReverseIter(__last), _ReverseIter(__first), __pred, __scratch);
216
217 for (size_t __i = 0; __i != __count; ++__i) {
218 const size_t __j = __count - __scratch[__i];
219 const difference_type __k = __i - __scratch[__i] + 1;
220
221 if (__suffix_[__j] > __k)
222 __suffix_[__j] = __k;
223 }
224 }
225};
226
227template <class _RandomAccessIterator1,
228 class _Hash = hash<typename iterator_traits<_RandomAccessIterator1>::value_type>,
229 class _BinaryPredicate = equal_to<>>
230class _LIBCPP_TEMPLATE_VIS boyer_moore_horspool_searcher {
231private:
232 using difference_type = typename iterator_traits<_RandomAccessIterator1>::difference_type;
233 using value_type = typename iterator_traits<_RandomAccessIterator1>::value_type;
234 using __skip_table_type = _BMSkipTable<value_type,
235 difference_type,
236 _Hash,
237 _BinaryPredicate,
238 is_integral_v<value_type>
239 && sizeof(value_type) == 1
240 && is_same_v<_Hash, hash<value_type>>
241 && is_same_v<_BinaryPredicate, equal_to<>>>;
242public:
243 boyer_moore_horspool_searcher(_RandomAccessIterator1 __first,
244 _RandomAccessIterator1 __last,
245 _Hash __hash = _Hash(),
246 _BinaryPredicate __pred = _BinaryPredicate())
247 : __first_(__first),
248 __last_(__last),
249 __pred_(__pred),
250 __pattern_length_(__last - __first),
251 __skip_table_(std::make_shared<__skip_table_type>(__pattern_length_, __pattern_length_, __hash, __pred_)) {
252 if (__first == __last)
253 return;
254 --__last;
255 difference_type __i = 0;
256 while (__first != __last) {
257 __skip_table_->insert(*__first, __pattern_length_ - 1 - __i);
258 ++__first;
259 ++__i;
260 }
261 }
262
263 template <class _RandomAccessIterator2>
264 pair<_RandomAccessIterator2, _RandomAccessIterator2>
265 operator()(_RandomAccessIterator2 __first, _RandomAccessIterator2 __last) const {
266 static_assert(__is_same_uncvref<typename std::iterator_traits<_RandomAccessIterator1>::value_type,
267 typename std::iterator_traits<_RandomAccessIterator2>::value_type>::value,
268 "Corpus and Pattern iterators must point to the same type");
269 if (__first == __last)
270 return std::make_pair(__last, __last);
271 if (__first_ == __last_)
272 return std::make_pair(__first, __first);
273
274 if (__pattern_length_ > __last - __first)
275 return std::make_pair(__last, __last);
276
277 return __search(__first, __last);
278 }
279
280private:
281 _RandomAccessIterator1 __first_;
282 _RandomAccessIterator1 __last_;
283 _BinaryPredicate __pred_;
284 difference_type __pattern_length_;
285 shared_ptr<__skip_table_type> __skip_table_;
286
287 template <class _RandomAccessIterator2>
288 pair<_RandomAccessIterator2, _RandomAccessIterator2>
289 __search(_RandomAccessIterator2 __f, _RandomAccessIterator2 __l) const {
290 _RandomAccessIterator2 __current = __f;
291 const _RandomAccessIterator2 __last = __l - __pattern_length_;
292 const __skip_table_type& __skip_table = *__skip_table_;
293
294 while (__current <= __last) {
295 difference_type __j = __pattern_length_;
296 while (__pred_(__first_[__j - 1], __current[__j - 1])) {
297 --__j;
298 if (__j == 0)
299 return std::make_pair(__current, __current + __pattern_length_);
300 }
301 __current += __skip_table[__current[__pattern_length_ - 1]];
302 }
303 return std::make_pair(__l, __l);
304 }
305};
306
307_LIBCPP_END_NAMESPACE_STD
308
309_LIBCPP_POP_MACROS
310
311#endif // _LIBCPP_STD_VER > 14
312
313#endif // _LIBCPP___FUNCTIONAL_BOYER_MOORE_SEARCHER_H
lib/libcxx/include/__functional/compose.h+1-1
......@@ -17,7 +17,7 @@
1717#include <type_traits>
1818
1919#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20#pragma GCC system_header
20# pragma GCC system_header
2121#endif
2222
2323_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__functional/default_searcher.h+6-6
......@@ -12,12 +12,13 @@
1212
1313#include <__algorithm/search.h>
1414#include <__config>
15#include <__functional/identity.h>
1516#include <__functional/operations.h>
1617#include <__iterator/iterator_traits.h>
17#include <utility>
18#include <__utility/pair.h>
1819
1920#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20#pragma GCC system_header
21# pragma GCC system_header
2122#endif
2223
2324_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -38,16 +39,15 @@ public:
3839 pair<_ForwardIterator2, _ForwardIterator2>
3940 operator () (_ForwardIterator2 __f, _ForwardIterator2 __l) const
4041 {
41 return _VSTD::__search(__f, __l, __first_, __last_, __pred_,
42 typename iterator_traits<_ForwardIterator>::iterator_category(),
43 typename iterator_traits<_ForwardIterator2>::iterator_category());
42 auto __proj = __identity();
43 return std::__search_impl(__f, __l, __first_, __last_, __pred_, __proj, __proj);
4444 }
4545
4646private:
4747 _ForwardIterator __first_;
4848 _ForwardIterator __last_;
4949 _BinaryPredicate __pred_;
50 };
50};
5151
5252#endif // _LIBCPP_STD_VER > 14
5353
lib/libcxx/include/__functional/function.h+14-11
......@@ -10,8 +10,8 @@
1010#ifndef _LIBCPP___FUNCTIONAL_FUNCTION_H
1111#define _LIBCPP___FUNCTIONAL_FUNCTION_H
1212
13#include <__assert>
1314#include <__config>
14#include <__debug>
1515#include <__functional/binary_function.h>
1616#include <__functional/invoke.h>
1717#include <__functional/unary_function.h>
......@@ -20,19 +20,23 @@
2020#include <__memory/allocator_traits.h>
2121#include <__memory/compressed_pair.h>
2222#include <__memory/shared_ptr.h>
23#include <__utility/forward.h>
24#include <__utility/move.h>
25#include <__utility/swap.h>
2326#include <exception>
2427#include <memory> // TODO: replace with <__memory/__builtin_new_allocator.h>
2528#include <type_traits>
26#include <utility>
2729
2830#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
29#pragma GCC system_header
31# pragma GCC system_header
3032#endif
3133
3234_LIBCPP_BEGIN_NAMESPACE_STD
3335
3436// bad_function_call
3537
38_LIBCPP_DIAGNOSTIC_PUSH
39_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wweak-vtables")
3640class _LIBCPP_EXCEPTION_ABI bad_function_call
3741 : public exception
3842{
......@@ -50,6 +54,7 @@ public:
5054 virtual const char* what() const _NOEXCEPT;
5155#endif
5256};
57_LIBCPP_DIAGNOSTIC_POP
5358
5459_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
5560void __throw_bad_function_call()
......@@ -80,7 +85,7 @@ struct __maybe_derive_from_unary_function
8085
8186template<class _Rp, class _A1>
8287struct __maybe_derive_from_unary_function<_Rp(_A1)>
83 : public unary_function<_A1, _Rp>
88 : public __unary_function<_A1, _Rp>
8489{
8590};
8691
......@@ -91,7 +96,7 @@ struct __maybe_derive_from_binary_function
9196
9297template<class _Rp, class _A1, class _A2>
9398struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)>
94 : public binary_function<_A1, _A2, _Rp>
99 : public __binary_function<_A1, _A2, _Rp>
95100{
96101};
97102
......@@ -385,9 +390,9 @@ template <class _Rp, class... _ArgTypes> class __value_func<_Rp(_ArgTypes...)>
385390 typedef __base<_Rp(_ArgTypes...)> __func;
386391 __func* __f_;
387392
388 _LIBCPP_NO_CFI static __func* __as_base(void* p)
393 _LIBCPP_NO_CFI static __func* __as_base(void* __p)
389394 {
390 return reinterpret_cast<__func*>(p);
395 return reinterpret_cast<__func*>(__p);
391396 }
392397
393398 public:
......@@ -951,10 +956,8 @@ public:
951956
952957template<class _Rp, class ..._ArgTypes>
953958class _LIBCPP_TEMPLATE_VIS function<_Rp(_ArgTypes...)>
954#if _LIBCPP_STD_VER <= 17 || !defined(_LIBCPP_ABI_NO_BINDER_BASES)
955959 : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>,
956960 public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)>
957#endif
958961{
959962#ifndef _LIBCPP_ABI_OPTIMIZED_FUNCTION
960963 typedef __function::__value_func<_Rp(_ArgTypes...)> __func;
......@@ -1237,7 +1240,7 @@ void
12371240swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT
12381241{return __x.swap(__y);}
12391242
1240#else // _LIBCPP_CXX03_LANG
1243#elif defined(_LIBCPP_ENABLE_CXX03_FUNCTION)
12411244
12421245namespace __function {
12431246
......@@ -2803,7 +2806,7 @@ void
28032806swap(function<_Fp>& __x, function<_Fp>& __y)
28042807{return __x.swap(__y);}
28052808
2806#endif
2809#endif // _LIBCPP_CXX03_LANG
28072810
28082811_LIBCPP_END_NAMESPACE_STD
28092812
lib/libcxx/include/__functional/hash.h+24-207
......@@ -23,7 +23,7 @@
2323#include <type_traits>
2424
2525#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
26#pragma GCC system_header
26# pragma GCC system_header
2727#endif
2828
2929_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -265,18 +265,10 @@ __murmur2_or_cityhash<_Size, 64>::operator()(const void* __key, _Size __len)
265265template <class _Tp, size_t = sizeof(_Tp) / sizeof(size_t)>
266266struct __scalar_hash;
267267
268_LIBCPP_SUPPRESS_DEPRECATED_PUSH
269268template <class _Tp>
270269struct __scalar_hash<_Tp, 0>
271#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
272 : public unary_function<_Tp, size_t>
273#endif
270 : public __unary_function<_Tp, size_t>
274271{
275_LIBCPP_SUPPRESS_DEPRECATED_POP
276#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
277 _LIBCPP_DEPRECATED_IN_CXX17 typedef size_t result_type;
278 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp argument_type;
279#endif
280272 _LIBCPP_INLINE_VISIBILITY
281273 size_t operator()(_Tp __v) const _NOEXCEPT
282274 {
......@@ -291,18 +283,10 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
291283 }
292284};
293285
294_LIBCPP_SUPPRESS_DEPRECATED_PUSH
295286template <class _Tp>
296287struct __scalar_hash<_Tp, 1>
297#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
298 : public unary_function<_Tp, size_t>
299#endif
288 : public __unary_function<_Tp, size_t>
300289{
301_LIBCPP_SUPPRESS_DEPRECATED_POP
302#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
303 _LIBCPP_DEPRECATED_IN_CXX17 typedef size_t result_type;
304 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp argument_type;
305#endif
306290 _LIBCPP_INLINE_VISIBILITY
307291 size_t operator()(_Tp __v) const _NOEXCEPT
308292 {
......@@ -316,18 +300,10 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
316300 }
317301};
318302
319_LIBCPP_SUPPRESS_DEPRECATED_PUSH
320303template <class _Tp>
321304struct __scalar_hash<_Tp, 2>
322#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
323 : public unary_function<_Tp, size_t>
324#endif
305 : public __unary_function<_Tp, size_t>
325306{
326_LIBCPP_SUPPRESS_DEPRECATED_POP
327#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
328 _LIBCPP_DEPRECATED_IN_CXX17 typedef size_t result_type;
329 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp argument_type;
330#endif
331307 _LIBCPP_INLINE_VISIBILITY
332308 size_t operator()(_Tp __v) const _NOEXCEPT
333309 {
......@@ -345,18 +321,10 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
345321 }
346322};
347323
348_LIBCPP_SUPPRESS_DEPRECATED_PUSH
349324template <class _Tp>
350325struct __scalar_hash<_Tp, 3>
351#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
352 : public unary_function<_Tp, size_t>
353#endif
326 : public __unary_function<_Tp, size_t>
354327{
355_LIBCPP_SUPPRESS_DEPRECATED_POP
356#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
357 _LIBCPP_DEPRECATED_IN_CXX17 typedef size_t result_type;
358 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp argument_type;
359#endif
360328 _LIBCPP_INLINE_VISIBILITY
361329 size_t operator()(_Tp __v) const _NOEXCEPT
362330 {
......@@ -375,18 +343,10 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
375343 }
376344};
377345
378_LIBCPP_SUPPRESS_DEPRECATED_PUSH
379346template <class _Tp>
380347struct __scalar_hash<_Tp, 4>
381#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
382 : public unary_function<_Tp, size_t>
383#endif
348 : public __unary_function<_Tp, size_t>
384349{
385_LIBCPP_SUPPRESS_DEPRECATED_POP
386#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
387 _LIBCPP_DEPRECATED_IN_CXX17 typedef size_t result_type;
388 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp argument_type;
389#endif
390350 _LIBCPP_INLINE_VISIBILITY
391351 size_t operator()(_Tp __v) const _NOEXCEPT
392352 {
......@@ -418,18 +378,10 @@ inline size_t __hash_combine(size_t __lhs, size_t __rhs) _NOEXCEPT {
418378 return _HashT()(__p);
419379}
420380
421_LIBCPP_SUPPRESS_DEPRECATED_PUSH
422381template<class _Tp>
423382struct _LIBCPP_TEMPLATE_VIS hash<_Tp*>
424#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
425 : public unary_function<_Tp*, size_t>
426#endif
383 : public __unary_function<_Tp*, size_t>
427384{
428_LIBCPP_SUPPRESS_DEPRECATED_POP
429#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
430 _LIBCPP_DEPRECATED_IN_CXX17 typedef size_t result_type;
431 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp* argument_type;
432#endif
433385 _LIBCPP_INLINE_VISIBILITY
434386 size_t operator()(_Tp* __v) const _NOEXCEPT
435387 {
......@@ -443,234 +395,118 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
443395 }
444396};
445397
446_LIBCPP_SUPPRESS_DEPRECATED_PUSH
447398template <>
448399struct _LIBCPP_TEMPLATE_VIS hash<bool>
449#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
450 : public unary_function<bool, size_t>
451#endif
400 : public __unary_function<bool, size_t>
452401{
453_LIBCPP_SUPPRESS_DEPRECATED_POP
454#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
455 _LIBCPP_DEPRECATED_IN_CXX17 typedef size_t result_type;
456 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool argument_type;
457#endif
458402 _LIBCPP_INLINE_VISIBILITY
459403 size_t operator()(bool __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
460404};
461405
462_LIBCPP_SUPPRESS_DEPRECATED_PUSH
463406template <>
464407struct _LIBCPP_TEMPLATE_VIS hash<char>
465#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
466 : public unary_function<char, size_t>
467#endif
408 : public __unary_function<char, size_t>
468409{
469_LIBCPP_SUPPRESS_DEPRECATED_POP
470#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
471 _LIBCPP_DEPRECATED_IN_CXX17 typedef size_t result_type;
472 _LIBCPP_DEPRECATED_IN_CXX17 typedef char argument_type;
473#endif
474410 _LIBCPP_INLINE_VISIBILITY
475411 size_t operator()(char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
476412};
477413
478_LIBCPP_SUPPRESS_DEPRECATED_PUSH
479414template <>
480415struct _LIBCPP_TEMPLATE_VIS hash<signed char>
481#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
482 : public unary_function<signed char, size_t>
483#endif
416 : public __unary_function<signed char, size_t>
484417{
485_LIBCPP_SUPPRESS_DEPRECATED_POP
486#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
487 _LIBCPP_DEPRECATED_IN_CXX17 typedef size_t result_type;
488 _LIBCPP_DEPRECATED_IN_CXX17 typedef signed char argument_type;
489#endif
490418 _LIBCPP_INLINE_VISIBILITY
491419 size_t operator()(signed char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
492420};
493421
494_LIBCPP_SUPPRESS_DEPRECATED_PUSH
495422template <>
496423struct _LIBCPP_TEMPLATE_VIS hash<unsigned char>
497#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
498 : public unary_function<unsigned char, size_t>
499#endif
424 : public __unary_function<unsigned char, size_t>
500425{
501_LIBCPP_SUPPRESS_DEPRECATED_POP
502#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
503 _LIBCPP_DEPRECATED_IN_CXX17 typedef size_t result_type;
504 _LIBCPP_DEPRECATED_IN_CXX17 typedef unsigned char argument_type;
505#endif
506426 _LIBCPP_INLINE_VISIBILITY
507427 size_t operator()(unsigned char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
508428};
509429
510430#ifndef _LIBCPP_HAS_NO_CHAR8_T
511_LIBCPP_SUPPRESS_DEPRECATED_PUSH
512431template <>
513432struct _LIBCPP_TEMPLATE_VIS hash<char8_t>
514#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
515 : public unary_function<char8_t, size_t>
516#endif
433 : public __unary_function<char8_t, size_t>
517434{
518_LIBCPP_SUPPRESS_DEPRECATED_POP
519#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
520 _LIBCPP_DEPRECATED_IN_CXX17 typedef size_t result_type;
521 _LIBCPP_DEPRECATED_IN_CXX17 typedef char8_t argument_type;
522#endif
523435 _LIBCPP_INLINE_VISIBILITY
524436 size_t operator()(char8_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
525437};
526438#endif // !_LIBCPP_HAS_NO_CHAR8_T
527439
528#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
529
530_LIBCPP_SUPPRESS_DEPRECATED_PUSH
531440template <>
532441struct _LIBCPP_TEMPLATE_VIS hash<char16_t>
533#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
534 : public unary_function<char16_t, size_t>
535#endif
442 : public __unary_function<char16_t, size_t>
536443{
537_LIBCPP_SUPPRESS_DEPRECATED_POP
538#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
539 _LIBCPP_DEPRECATED_IN_CXX17 typedef size_t result_type;
540 _LIBCPP_DEPRECATED_IN_CXX17 typedef char16_t argument_type;
541#endif
542444 _LIBCPP_INLINE_VISIBILITY
543445 size_t operator()(char16_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
544446};
545447
546_LIBCPP_SUPPRESS_DEPRECATED_PUSH
547448template <>
548449struct _LIBCPP_TEMPLATE_VIS hash<char32_t>
549#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
550 : public unary_function<char32_t, size_t>
551#endif
450 : public __unary_function<char32_t, size_t>
552451{
553_LIBCPP_SUPPRESS_DEPRECATED_POP
554#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
555 _LIBCPP_DEPRECATED_IN_CXX17 typedef size_t result_type;
556 _LIBCPP_DEPRECATED_IN_CXX17 typedef char32_t argument_type;
557#endif
558452 _LIBCPP_INLINE_VISIBILITY
559453 size_t operator()(char32_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
560454};
561455
562#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
563
564456#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
565_LIBCPP_SUPPRESS_DEPRECATED_PUSH
566457template <>
567458struct _LIBCPP_TEMPLATE_VIS hash<wchar_t>
568#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
569 : public unary_function<wchar_t, size_t>
570#endif
459 : public __unary_function<wchar_t, size_t>
571460{
572_LIBCPP_SUPPRESS_DEPRECATED_POP
573#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
574 _LIBCPP_DEPRECATED_IN_CXX17 typedef size_t result_type;
575 _LIBCPP_DEPRECATED_IN_CXX17 typedef wchar_t argument_type;
576#endif
577461 _LIBCPP_INLINE_VISIBILITY
578462 size_t operator()(wchar_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
579463};
580464#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
581465
582_LIBCPP_SUPPRESS_DEPRECATED_PUSH
583466template <>
584467struct _LIBCPP_TEMPLATE_VIS hash<short>
585#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
586 : public unary_function<short, size_t>
587#endif
468 : public __unary_function<short, size_t>
588469{
589_LIBCPP_SUPPRESS_DEPRECATED_POP
590#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
591 _LIBCPP_DEPRECATED_IN_CXX17 typedef size_t result_type;
592 _LIBCPP_DEPRECATED_IN_CXX17 typedef short argument_type;
593#endif
594470 _LIBCPP_INLINE_VISIBILITY
595471 size_t operator()(short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
596472};
597473
598_LIBCPP_SUPPRESS_DEPRECATED_PUSH
599474template <>
600475struct _LIBCPP_TEMPLATE_VIS hash<unsigned short>
601#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
602 : public unary_function<unsigned short, size_t>
603#endif
476 : public __unary_function<unsigned short, size_t>
604477{
605_LIBCPP_SUPPRESS_DEPRECATED_POP
606#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
607 _LIBCPP_DEPRECATED_IN_CXX17 typedef size_t result_type;
608 _LIBCPP_DEPRECATED_IN_CXX17 typedef unsigned short argument_type;
609#endif
610478 _LIBCPP_INLINE_VISIBILITY
611479 size_t operator()(unsigned short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
612480};
613481
614_LIBCPP_SUPPRESS_DEPRECATED_PUSH
615482template <>
616483struct _LIBCPP_TEMPLATE_VIS hash<int>
617#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
618 : public unary_function<int, size_t>
619#endif
484 : public __unary_function<int, size_t>
620485{
621_LIBCPP_SUPPRESS_DEPRECATED_POP
622#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
623 _LIBCPP_DEPRECATED_IN_CXX17 typedef size_t result_type;
624 _LIBCPP_DEPRECATED_IN_CXX17 typedef int argument_type;
625#endif
626486 _LIBCPP_INLINE_VISIBILITY
627487 size_t operator()(int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
628488};
629489
630_LIBCPP_SUPPRESS_DEPRECATED_PUSH
631490template <>
632491struct _LIBCPP_TEMPLATE_VIS hash<unsigned int>
633#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
634 : public unary_function<unsigned int, size_t>
635#endif
492 : public __unary_function<unsigned int, size_t>
636493{
637_LIBCPP_SUPPRESS_DEPRECATED_POP
638#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
639 _LIBCPP_DEPRECATED_IN_CXX17 typedef size_t result_type;
640 _LIBCPP_DEPRECATED_IN_CXX17 typedef unsigned int argument_type;
641#endif
642494 _LIBCPP_INLINE_VISIBILITY
643495 size_t operator()(unsigned int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
644496};
645497
646_LIBCPP_SUPPRESS_DEPRECATED_PUSH
647498template <>
648499struct _LIBCPP_TEMPLATE_VIS hash<long>
649#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
650 : public unary_function<long, size_t>
651#endif
500 : public __unary_function<long, size_t>
652501{
653_LIBCPP_SUPPRESS_DEPRECATED_POP
654#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
655 _LIBCPP_DEPRECATED_IN_CXX17 typedef size_t result_type;
656 _LIBCPP_DEPRECATED_IN_CXX17 typedef long argument_type;
657#endif
658502 _LIBCPP_INLINE_VISIBILITY
659503 size_t operator()(long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
660504};
661505
662_LIBCPP_SUPPRESS_DEPRECATED_PUSH
663506template <>
664507struct _LIBCPP_TEMPLATE_VIS hash<unsigned long>
665#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
666 : public unary_function<unsigned long, size_t>
667#endif
508 : public __unary_function<unsigned long, size_t>
668509{
669_LIBCPP_SUPPRESS_DEPRECATED_POP
670#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
671 _LIBCPP_DEPRECATED_IN_CXX17 typedef size_t result_type;
672 _LIBCPP_DEPRECATED_IN_CXX17 typedef unsigned long argument_type;
673#endif
674510 _LIBCPP_INLINE_VISIBILITY
675511 size_t operator()(unsigned long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
676512};
......@@ -781,25 +617,15 @@ struct _LIBCPP_TEMPLATE_VIS hash<long double>
781617 }
782618};
783619
784#if _LIBCPP_STD_VER > 11
785
786_LIBCPP_SUPPRESS_DEPRECATED_PUSH
787620template <class _Tp, bool = is_enum<_Tp>::value>
788621struct _LIBCPP_TEMPLATE_VIS __enum_hash
789#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
790 : public unary_function<_Tp, size_t>
791#endif
622 : public __unary_function<_Tp, size_t>
792623{
793_LIBCPP_SUPPRESS_DEPRECATED_POP
794#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
795 _LIBCPP_DEPRECATED_IN_CXX17 typedef size_t result_type;
796 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp argument_type;
797#endif
798624 _LIBCPP_INLINE_VISIBILITY
799625 size_t operator()(_Tp __v) const _NOEXCEPT
800626 {
801627 typedef typename underlying_type<_Tp>::type type;
802 return hash<type>{}(static_cast<type>(__v));
628 return hash<type>()(static_cast<type>(__v));
803629 }
804630};
805631template <class _Tp>
......@@ -813,22 +639,13 @@ template <class _Tp>
813639struct _LIBCPP_TEMPLATE_VIS hash : public __enum_hash<_Tp>
814640{
815641};
816#endif
817642
818643#if _LIBCPP_STD_VER > 14
819644
820_LIBCPP_SUPPRESS_DEPRECATED_PUSH
821645template <>
822646struct _LIBCPP_TEMPLATE_VIS hash<nullptr_t>
823#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
824 : public unary_function<nullptr_t, size_t>
825#endif
647 : public __unary_function<nullptr_t, size_t>
826648{
827_LIBCPP_SUPPRESS_DEPRECATED_POP
828#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
829 _LIBCPP_DEPRECATED_IN_CXX17 typedef size_t result_type;
830 _LIBCPP_DEPRECATED_IN_CXX17 typedef nullptr_t argument_type;
831#endif
832649 _LIBCPP_INLINE_VISIBILITY
833650 size_t operator()(nullptr_t) const _NOEXCEPT {
834651 return 662607004ull;
lib/libcxx/include/__functional/identity.h+11-2
......@@ -11,14 +11,23 @@
1111#define _LIBCPP___FUNCTIONAL_IDENTITY_H
1212
1313#include <__config>
14#include <utility>
14#include <__utility/forward.h>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
17# pragma GCC system_header
1818#endif
1919
2020_LIBCPP_BEGIN_NAMESPACE_STD
2121
22struct __identity {
23 template <class _Tp>
24 _LIBCPP_NODISCARD _LIBCPP_CONSTEXPR _Tp&& operator()(_Tp&& __t) const _NOEXCEPT {
25 return std::forward<_Tp>(__t);
26 }
27
28 using is_transparent = void;
29};
30
2231#if _LIBCPP_STD_VER > 17
2332
2433struct identity {
lib/libcxx/include/__functional/invoke.h+485-47
......@@ -11,79 +11,517 @@
1111#define _LIBCPP___FUNCTIONAL_INVOKE_H
1212
1313#include <__config>
14#include <__functional/weak_result_type.h>
14#include <__type_traits/add_lvalue_reference.h>
15#include <__type_traits/apply_cv.h>
16#include <__type_traits/conditional.h>
17#include <__type_traits/decay.h>
18#include <__type_traits/enable_if.h>
19#include <__type_traits/integral_constant.h>
20#include <__type_traits/is_base_of.h>
21#include <__type_traits/is_core_convertible.h>
22#include <__type_traits/is_member_function_pointer.h>
23#include <__type_traits/is_member_object_pointer.h>
24#include <__type_traits/is_reference_wrapper.h>
25#include <__type_traits/is_same.h>
26#include <__type_traits/is_void.h>
27#include <__type_traits/nat.h>
28#include <__type_traits/remove_cv.h>
29#include <__utility/declval.h>
1530#include <__utility/forward.h>
16#include <type_traits>
1731
1832#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
33# pragma GCC system_header
2034#endif
2135
36// TODO: Disentangle the type traits and std::invoke properly
37
2238_LIBCPP_BEGIN_NAMESPACE_STD
2339
40struct __any
41{
42 __any(...);
43};
44
45template <class _MP, bool _IsMemberFunctionPtr, bool _IsMemberObjectPtr>
46struct __member_pointer_traits_imp
47{
48};
49
50template <class _Rp, class _Class, class ..._Param>
51struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...), true, false>
52{
53 typedef _Class _ClassType;
54 typedef _Rp _ReturnType;
55 typedef _Rp (_FnType) (_Param...);
56};
57
58template <class _Rp, class _Class, class ..._Param>
59struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...), true, false>
60{
61 typedef _Class _ClassType;
62 typedef _Rp _ReturnType;
63 typedef _Rp (_FnType) (_Param..., ...);
64};
65
66template <class _Rp, class _Class, class ..._Param>
67struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const, true, false>
68{
69 typedef _Class const _ClassType;
70 typedef _Rp _ReturnType;
71 typedef _Rp (_FnType) (_Param...);
72};
73
74template <class _Rp, class _Class, class ..._Param>
75struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const, true, false>
76{
77 typedef _Class const _ClassType;
78 typedef _Rp _ReturnType;
79 typedef _Rp (_FnType) (_Param..., ...);
80};
81
82template <class _Rp, class _Class, class ..._Param>
83struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) volatile, true, false>
84{
85 typedef _Class volatile _ClassType;
86 typedef _Rp _ReturnType;
87 typedef _Rp (_FnType) (_Param...);
88};
89
90template <class _Rp, class _Class, class ..._Param>
91struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) volatile, true, false>
92{
93 typedef _Class volatile _ClassType;
94 typedef _Rp _ReturnType;
95 typedef _Rp (_FnType) (_Param..., ...);
96};
97
98template <class _Rp, class _Class, class ..._Param>
99struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const volatile, true, false>
100{
101 typedef _Class const volatile _ClassType;
102 typedef _Rp _ReturnType;
103 typedef _Rp (_FnType) (_Param...);
104};
105
106template <class _Rp, class _Class, class ..._Param>
107struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const volatile, true, false>
108{
109 typedef _Class const volatile _ClassType;
110 typedef _Rp _ReturnType;
111 typedef _Rp (_FnType) (_Param..., ...);
112};
113
114template <class _Rp, class _Class, class ..._Param>
115struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) &, true, false>
116{
117 typedef _Class& _ClassType;
118 typedef _Rp _ReturnType;
119 typedef _Rp (_FnType) (_Param...);
120};
121
122template <class _Rp, class _Class, class ..._Param>
123struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) &, true, false>
124{
125 typedef _Class& _ClassType;
126 typedef _Rp _ReturnType;
127 typedef _Rp (_FnType) (_Param..., ...);
128};
129
130template <class _Rp, class _Class, class ..._Param>
131struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const&, true, false>
132{
133 typedef _Class const& _ClassType;
134 typedef _Rp _ReturnType;
135 typedef _Rp (_FnType) (_Param...);
136};
137
138template <class _Rp, class _Class, class ..._Param>
139struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const&, true, false>
140{
141 typedef _Class const& _ClassType;
142 typedef _Rp _ReturnType;
143 typedef _Rp (_FnType) (_Param..., ...);
144};
145
146template <class _Rp, class _Class, class ..._Param>
147struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) volatile&, true, false>
148{
149 typedef _Class volatile& _ClassType;
150 typedef _Rp _ReturnType;
151 typedef _Rp (_FnType) (_Param...);
152};
153
154template <class _Rp, class _Class, class ..._Param>
155struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) volatile&, true, false>
156{
157 typedef _Class volatile& _ClassType;
158 typedef _Rp _ReturnType;
159 typedef _Rp (_FnType) (_Param..., ...);
160};
161
162template <class _Rp, class _Class, class ..._Param>
163struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const volatile&, true, false>
164{
165 typedef _Class const volatile& _ClassType;
166 typedef _Rp _ReturnType;
167 typedef _Rp (_FnType) (_Param...);
168};
169
170template <class _Rp, class _Class, class ..._Param>
171struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const volatile&, true, false>
172{
173 typedef _Class const volatile& _ClassType;
174 typedef _Rp _ReturnType;
175 typedef _Rp (_FnType) (_Param..., ...);
176};
177
178template <class _Rp, class _Class, class ..._Param>
179struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) &&, true, false>
180{
181 typedef _Class&& _ClassType;
182 typedef _Rp _ReturnType;
183 typedef _Rp (_FnType) (_Param...);
184};
185
186template <class _Rp, class _Class, class ..._Param>
187struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) &&, true, false>
188{
189 typedef _Class&& _ClassType;
190 typedef _Rp _ReturnType;
191 typedef _Rp (_FnType) (_Param..., ...);
192};
193
194template <class _Rp, class _Class, class ..._Param>
195struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const&&, true, false>
196{
197 typedef _Class const&& _ClassType;
198 typedef _Rp _ReturnType;
199 typedef _Rp (_FnType) (_Param...);
200};
201
202template <class _Rp, class _Class, class ..._Param>
203struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const&&, true, false>
204{
205 typedef _Class const&& _ClassType;
206 typedef _Rp _ReturnType;
207 typedef _Rp (_FnType) (_Param..., ...);
208};
209
210template <class _Rp, class _Class, class ..._Param>
211struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) volatile&&, true, false>
212{
213 typedef _Class volatile&& _ClassType;
214 typedef _Rp _ReturnType;
215 typedef _Rp (_FnType) (_Param...);
216};
217
218template <class _Rp, class _Class, class ..._Param>
219struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) volatile&&, true, false>
220{
221 typedef _Class volatile&& _ClassType;
222 typedef _Rp _ReturnType;
223 typedef _Rp (_FnType) (_Param..., ...);
224};
225
226template <class _Rp, class _Class, class ..._Param>
227struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const volatile&&, true, false>
228{
229 typedef _Class const volatile&& _ClassType;
230 typedef _Rp _ReturnType;
231 typedef _Rp (_FnType) (_Param...);
232};
233
234template <class _Rp, class _Class, class ..._Param>
235struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const volatile&&, true, false>
236{
237 typedef _Class const volatile&& _ClassType;
238 typedef _Rp _ReturnType;
239 typedef _Rp (_FnType) (_Param..., ...);
240};
241
242template <class _Rp, class _Class>
243struct __member_pointer_traits_imp<_Rp _Class::*, false, true>
244{
245 typedef _Class _ClassType;
246 typedef _Rp _ReturnType;
247};
248
249template <class _MP>
250struct __member_pointer_traits
251 : public __member_pointer_traits_imp<typename remove_cv<_MP>::type,
252 is_member_function_pointer<_MP>::value,
253 is_member_object_pointer<_MP>::value>
254{
255// typedef ... _ClassType;
256// typedef ... _ReturnType;
257// typedef ... _FnType;
258};
259
260template <class _DecayedFp>
261struct __member_pointer_class_type {};
262
263template <class _Ret, class _ClassType>
264struct __member_pointer_class_type<_Ret _ClassType::*> {
265 typedef _ClassType type;
266};
267
268template <class _Fp, class _A0,
269 class _DecayFp = typename decay<_Fp>::type,
270 class _DecayA0 = typename decay<_A0>::type,
271 class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
272using __enable_if_bullet1 = typename enable_if
273 <
274 is_member_function_pointer<_DecayFp>::value
275 && is_base_of<_ClassT, _DecayA0>::value
276 >::type;
277
278template <class _Fp, class _A0,
279 class _DecayFp = typename decay<_Fp>::type,
280 class _DecayA0 = typename decay<_A0>::type>
281using __enable_if_bullet2 = typename enable_if
282 <
283 is_member_function_pointer<_DecayFp>::value
284 && __is_reference_wrapper<_DecayA0>::value
285 >::type;
286
287template <class _Fp, class _A0,
288 class _DecayFp = typename decay<_Fp>::type,
289 class _DecayA0 = typename decay<_A0>::type,
290 class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
291using __enable_if_bullet3 = typename enable_if
292 <
293 is_member_function_pointer<_DecayFp>::value
294 && !is_base_of<_ClassT, _DecayA0>::value
295 && !__is_reference_wrapper<_DecayA0>::value
296 >::type;
297
298template <class _Fp, class _A0,
299 class _DecayFp = typename decay<_Fp>::type,
300 class _DecayA0 = typename decay<_A0>::type,
301 class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
302using __enable_if_bullet4 = typename enable_if
303 <
304 is_member_object_pointer<_DecayFp>::value
305 && is_base_of<_ClassT, _DecayA0>::value
306 >::type;
307
308template <class _Fp, class _A0,
309 class _DecayFp = typename decay<_Fp>::type,
310 class _DecayA0 = typename decay<_A0>::type>
311using __enable_if_bullet5 = typename enable_if
312 <
313 is_member_object_pointer<_DecayFp>::value
314 && __is_reference_wrapper<_DecayA0>::value
315 >::type;
316
317template <class _Fp, class _A0,
318 class _DecayFp = typename decay<_Fp>::type,
319 class _DecayA0 = typename decay<_A0>::type,
320 class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
321using __enable_if_bullet6 = typename enable_if
322 <
323 is_member_object_pointer<_DecayFp>::value
324 && !is_base_of<_ClassT, _DecayA0>::value
325 && !__is_reference_wrapper<_DecayA0>::value
326 >::type;
327
328// __invoke forward declarations
329
330// fall back - none of the bullets
331
332template <class ..._Args>
333__nat __invoke(__any, _Args&& ...__args);
334
335// bullets 1, 2 and 3
336
337template <class _Fp, class _A0, class ..._Args,
338 class = __enable_if_bullet1<_Fp, _A0> >
339inline _LIBCPP_INLINE_VISIBILITY
340_LIBCPP_CONSTEXPR decltype((std::declval<_A0>().*std::declval<_Fp>())(std::declval<_Args>()...))
341__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
342 _NOEXCEPT_(noexcept((static_cast<_A0&&>(__a0).*__f)(static_cast<_Args&&>(__args)...)))
343 { return (static_cast<_A0&&>(__a0).*__f)(static_cast<_Args&&>(__args)...); }
344
345template <class _Fp, class _A0, class ..._Args,
346 class = __enable_if_bullet2<_Fp, _A0> >
347inline _LIBCPP_INLINE_VISIBILITY
348_LIBCPP_CONSTEXPR decltype((std::declval<_A0>().get().*std::declval<_Fp>())(std::declval<_Args>()...))
349__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
350 _NOEXCEPT_(noexcept((__a0.get().*__f)(static_cast<_Args&&>(__args)...)))
351 { return (__a0.get().*__f)(static_cast<_Args&&>(__args)...); }
352
353template <class _Fp, class _A0, class ..._Args,
354 class = __enable_if_bullet3<_Fp, _A0> >
355inline _LIBCPP_INLINE_VISIBILITY
356_LIBCPP_CONSTEXPR decltype(((*std::declval<_A0>()).*std::declval<_Fp>())(std::declval<_Args>()...))
357__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
358 _NOEXCEPT_(noexcept(((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_Args&&>(__args)...)))
359 { return ((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_Args&&>(__args)...); }
360
361// bullets 4, 5 and 6
362
363template <class _Fp, class _A0,
364 class = __enable_if_bullet4<_Fp, _A0> >
365inline _LIBCPP_INLINE_VISIBILITY
366_LIBCPP_CONSTEXPR decltype(std::declval<_A0>().*std::declval<_Fp>())
367__invoke(_Fp&& __f, _A0&& __a0)
368 _NOEXCEPT_(noexcept(static_cast<_A0&&>(__a0).*__f))
369 { return static_cast<_A0&&>(__a0).*__f; }
370
371template <class _Fp, class _A0,
372 class = __enable_if_bullet5<_Fp, _A0> >
373inline _LIBCPP_INLINE_VISIBILITY
374_LIBCPP_CONSTEXPR decltype(std::declval<_A0>().get().*std::declval<_Fp>())
375__invoke(_Fp&& __f, _A0&& __a0)
376 _NOEXCEPT_(noexcept(__a0.get().*__f))
377 { return __a0.get().*__f; }
378
379template <class _Fp, class _A0,
380 class = __enable_if_bullet6<_Fp, _A0> >
381inline _LIBCPP_INLINE_VISIBILITY
382_LIBCPP_CONSTEXPR decltype((*std::declval<_A0>()).*std::declval<_Fp>())
383__invoke(_Fp&& __f, _A0&& __a0)
384 _NOEXCEPT_(noexcept((*static_cast<_A0&&>(__a0)).*__f))
385 { return (*static_cast<_A0&&>(__a0)).*__f; }
386
387// bullet 7
388
389template <class _Fp, class ..._Args>
390inline _LIBCPP_INLINE_VISIBILITY
391_LIBCPP_CONSTEXPR decltype(std::declval<_Fp>()(std::declval<_Args>()...))
392__invoke(_Fp&& __f, _Args&& ...__args)
393 _NOEXCEPT_(noexcept(static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...)))
394 { return static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...); }
395
396// __invokable
397template <class _Ret, class _Fp, class ..._Args>
398struct __invokable_r
399{
400 template <class _XFp, class ..._XArgs>
401 static decltype(std::__invoke(declval<_XFp>(), declval<_XArgs>()...)) __try_call(int);
402 template <class _XFp, class ..._XArgs>
403 static __nat __try_call(...);
404
405 // FIXME: Check that _Ret, _Fp, and _Args... are all complete types, cv void,
406 // or incomplete array types as required by the standard.
407 using _Result = decltype(__try_call<_Fp, _Args...>(0));
408
409 using type = typename conditional<
410 _IsNotSame<_Result, __nat>::value,
411 typename conditional< is_void<_Ret>::value, true_type, __is_core_convertible<_Result, _Ret> >::type,
412 false_type >::type;
413 static const bool value = type::value;
414};
415template <class _Fp, class ..._Args>
416using __invokable = __invokable_r<void, _Fp, _Args...>;
417
418template <bool _IsInvokable, bool _IsCVVoid, class _Ret, class _Fp, class ..._Args>
419struct __nothrow_invokable_r_imp {
420 static const bool value = false;
421};
422
423template <class _Ret, class _Fp, class ..._Args>
424struct __nothrow_invokable_r_imp<true, false, _Ret, _Fp, _Args...>
425{
426 typedef __nothrow_invokable_r_imp _ThisT;
427
428 template <class _Tp>
429 static void __test_noexcept(_Tp) _NOEXCEPT;
430
431 static const bool value = noexcept(_ThisT::__test_noexcept<_Ret>(
432 _VSTD::__invoke(declval<_Fp>(), declval<_Args>()...)));
433};
434
435template <class _Ret, class _Fp, class ..._Args>
436struct __nothrow_invokable_r_imp<true, true, _Ret, _Fp, _Args...>
437{
438 static const bool value = noexcept(
439 _VSTD::__invoke(declval<_Fp>(), declval<_Args>()...));
440};
441
442template <class _Ret, class _Fp, class ..._Args>
443using __nothrow_invokable_r =
444 __nothrow_invokable_r_imp<
445 __invokable_r<_Ret, _Fp, _Args...>::value,
446 is_void<_Ret>::value,
447 _Ret, _Fp, _Args...
448 >;
449
450template <class _Fp, class ..._Args>
451using __nothrow_invokable =
452 __nothrow_invokable_r_imp<
453 __invokable<_Fp, _Args...>::value,
454 true, void, _Fp, _Args...
455 >;
456
457template <class _Fp, class ..._Args>
458struct __invoke_of
459 : public enable_if<
460 __invokable<_Fp, _Args...>::value,
461 typename __invokable_r<void, _Fp, _Args...>::_Result>
462{
463};
464
24465template <class _Ret, bool = is_void<_Ret>::value>
25466struct __invoke_void_return_wrapper
26467{
27#ifndef _LIBCPP_CXX03_LANG
28468 template <class ..._Args>
29469 static _Ret __call(_Args&&... __args) {
30 return _VSTD::__invoke(_VSTD::forward<_Args>(__args)...);
31 }
32#else
33 template <class _Fn>
34 static _Ret __call(_Fn __f) {
35 return _VSTD::__invoke(__f);
470 return std::__invoke(std::forward<_Args>(__args)...);
36471 }
37
38 template <class _Fn, class _A0>
39 static _Ret __call(_Fn __f, _A0& __a0) {
40 return _VSTD::__invoke(__f, __a0);
41 }
42
43 template <class _Fn, class _A0, class _A1>
44 static _Ret __call(_Fn __f, _A0& __a0, _A1& __a1) {
45 return _VSTD::__invoke(__f, __a0, __a1);
46 }
47
48 template <class _Fn, class _A0, class _A1, class _A2>
49 static _Ret __call(_Fn __f, _A0& __a0, _A1& __a1, _A2& __a2){
50 return _VSTD::__invoke(__f, __a0, __a1, __a2);
51 }
52#endif
53472};
54473
55474template <class _Ret>
56475struct __invoke_void_return_wrapper<_Ret, true>
57476{
58#ifndef _LIBCPP_CXX03_LANG
59477 template <class ..._Args>
60478 static void __call(_Args&&... __args) {
61 _VSTD::__invoke(_VSTD::forward<_Args>(__args)...);
62 }
63#else
64 template <class _Fn>
65 static void __call(_Fn __f) {
66 _VSTD::__invoke(__f);
479 std::__invoke(std::forward<_Args>(__args)...);
67480 }
481};
68482
69 template <class _Fn, class _A0>
70 static void __call(_Fn __f, _A0& __a0) {
71 _VSTD::__invoke(__f, __a0);
72 }
483#if _LIBCPP_STD_VER > 14
73484
74 template <class _Fn, class _A0, class _A1>
75 static void __call(_Fn __f, _A0& __a0, _A1& __a1) {
76 _VSTD::__invoke(__f, __a0, __a1);
77 }
485// is_invocable
78486
79 template <class _Fn, class _A0, class _A1, class _A2>
80 static void __call(_Fn __f, _A0& __a0, _A1& __a1, _A2& __a2) {
81 _VSTD::__invoke(__f, __a0, __a1, __a2);
82 }
83#endif
487template <class _Fn, class ..._Args>
488struct _LIBCPP_TEMPLATE_VIS is_invocable
489 : integral_constant<bool, __invokable<_Fn, _Args...>::value> {};
490
491template <class _Ret, class _Fn, class ..._Args>
492struct _LIBCPP_TEMPLATE_VIS is_invocable_r
493 : integral_constant<bool, __invokable_r<_Ret, _Fn, _Args...>::value> {};
494
495template <class _Fn, class ..._Args>
496inline constexpr bool is_invocable_v = is_invocable<_Fn, _Args...>::value;
497
498template <class _Ret, class _Fn, class ..._Args>
499inline constexpr bool is_invocable_r_v = is_invocable_r<_Ret, _Fn, _Args...>::value;
500
501// is_nothrow_invocable
502
503template <class _Fn, class ..._Args>
504struct _LIBCPP_TEMPLATE_VIS is_nothrow_invocable
505 : integral_constant<bool, __nothrow_invokable<_Fn, _Args...>::value> {};
506
507template <class _Ret, class _Fn, class ..._Args>
508struct _LIBCPP_TEMPLATE_VIS is_nothrow_invocable_r
509 : integral_constant<bool, __nothrow_invokable_r<_Ret, _Fn, _Args...>::value> {};
510
511template <class _Fn, class ..._Args>
512inline constexpr bool is_nothrow_invocable_v = is_nothrow_invocable<_Fn, _Args...>::value;
513
514template <class _Ret, class _Fn, class ..._Args>
515inline constexpr bool is_nothrow_invocable_r_v = is_nothrow_invocable_r<_Ret, _Fn, _Args...>::value;
516
517template <class _Fn, class... _Args>
518struct _LIBCPP_TEMPLATE_VIS invoke_result
519 : __invoke_of<_Fn, _Args...>
520{
84521};
85522
86#if _LIBCPP_STD_VER > 14
523template <class _Fn, class... _Args>
524using invoke_result_t = typename invoke_result<_Fn, _Args...>::type;
87525
88526template <class _Fn, class ..._Args>
89527_LIBCPP_CONSTEXPR_AFTER_CXX17 invoke_result_t<_Fn, _Args...>
lib/libcxx/include/__functional/is_transparent.h+1-1
......@@ -14,7 +14,7 @@
1414#include <type_traits>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
17# pragma GCC system_header
1818#endif
1919
2020_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__functional/mem_fn.h+6-108
......@@ -14,19 +14,17 @@
1414#include <__functional/binary_function.h>
1515#include <__functional/invoke.h>
1616#include <__functional/weak_result_type.h>
17#include <utility>
17#include <__utility/forward.h>
18#include <type_traits>
1819
1920#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20#pragma GCC system_header
21# pragma GCC system_header
2122#endif
2223
2324_LIBCPP_BEGIN_NAMESPACE_STD
2425
2526template <class _Tp>
26class __mem_fn
27#if _LIBCPP_STD_VER <= 17 || !defined(_LIBCPP_ABI_NO_BINDER_BASES)
28 : public __weak_result_type<_Tp>
29#endif
27class __mem_fn : public __weak_result_type<_Tp>
3028{
3129public:
3230 // types
......@@ -38,114 +36,14 @@ public:
3836 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
3937 __mem_fn(type __f) _NOEXCEPT : __f_(__f) {}
4038
41#ifndef _LIBCPP_CXX03_LANG
4239 // invoke
4340 template <class... _ArgTypes>
4441 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
42
4543 typename __invoke_return<type, _ArgTypes...>::type
4644 operator() (_ArgTypes&&... __args) const {
47 return _VSTD::__invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...);
48 }
49#else
50
51 template <class _A0>
52 _LIBCPP_INLINE_VISIBILITY
53 typename __invoke_return0<type, _A0>::type
54 operator() (_A0& __a0) const {
55 return _VSTD::__invoke(__f_, __a0);
56 }
57
58 template <class _A0>
59 _LIBCPP_INLINE_VISIBILITY
60 typename __invoke_return0<type, _A0 const>::type
61 operator() (_A0 const& __a0) const {
62 return _VSTD::__invoke(__f_, __a0);
63 }
64
65 template <class _A0, class _A1>
66 _LIBCPP_INLINE_VISIBILITY
67 typename __invoke_return1<type, _A0, _A1>::type
68 operator() (_A0& __a0, _A1& __a1) const {
69 return _VSTD::__invoke(__f_, __a0, __a1);
70 }
71
72 template <class _A0, class _A1>
73 _LIBCPP_INLINE_VISIBILITY
74 typename __invoke_return1<type, _A0 const, _A1>::type
75 operator() (_A0 const& __a0, _A1& __a1) const {
76 return _VSTD::__invoke(__f_, __a0, __a1);
77 }
78
79 template <class _A0, class _A1>
80 _LIBCPP_INLINE_VISIBILITY
81 typename __invoke_return1<type, _A0, _A1 const>::type
82 operator() (_A0& __a0, _A1 const& __a1) const {
83 return _VSTD::__invoke(__f_, __a0, __a1);
84 }
85
86 template <class _A0, class _A1>
87 _LIBCPP_INLINE_VISIBILITY
88 typename __invoke_return1<type, _A0 const, _A1 const>::type
89 operator() (_A0 const& __a0, _A1 const& __a1) const {
90 return _VSTD::__invoke(__f_, __a0, __a1);
91 }
92
93 template <class _A0, class _A1, class _A2>
94 _LIBCPP_INLINE_VISIBILITY
95 typename __invoke_return2<type, _A0, _A1, _A2>::type
96 operator() (_A0& __a0, _A1& __a1, _A2& __a2) const {
97 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
45 return std::__invoke(__f_, std::forward<_ArgTypes>(__args)...);
9846 }
99
100 template <class _A0, class _A1, class _A2>
101 _LIBCPP_INLINE_VISIBILITY
102 typename __invoke_return2<type, _A0 const, _A1, _A2>::type
103 operator() (_A0 const& __a0, _A1& __a1, _A2& __a2) const {
104 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
105 }
106
107 template <class _A0, class _A1, class _A2>
108 _LIBCPP_INLINE_VISIBILITY
109 typename __invoke_return2<type, _A0, _A1 const, _A2>::type
110 operator() (_A0& __a0, _A1 const& __a1, _A2& __a2) const {
111 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
112 }
113
114 template <class _A0, class _A1, class _A2>
115 _LIBCPP_INLINE_VISIBILITY
116 typename __invoke_return2<type, _A0, _A1, _A2 const>::type
117 operator() (_A0& __a0, _A1& __a1, _A2 const& __a2) const {
118 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
119 }
120
121 template <class _A0, class _A1, class _A2>
122 _LIBCPP_INLINE_VISIBILITY
123 typename __invoke_return2<type, _A0 const, _A1 const, _A2>::type
124 operator() (_A0 const& __a0, _A1 const& __a1, _A2& __a2) const {
125 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
126 }
127
128 template <class _A0, class _A1, class _A2>
129 _LIBCPP_INLINE_VISIBILITY
130 typename __invoke_return2<type, _A0 const, _A1, _A2 const>::type
131 operator() (_A0 const& __a0, _A1& __a1, _A2 const& __a2) const {
132 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
133 }
134
135 template <class _A0, class _A1, class _A2>
136 _LIBCPP_INLINE_VISIBILITY
137 typename __invoke_return2<type, _A0, _A1 const, _A2 const>::type
138 operator() (_A0& __a0, _A1 const& __a1, _A2 const& __a2) const {
139 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
140 }
141
142 template <class _A0, class _A1, class _A2>
143 _LIBCPP_INLINE_VISIBILITY
144 typename __invoke_return2<type, _A0 const, _A1 const, _A2 const>::type
145 operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const {
146 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
147 }
148#endif
14947};
15048
15149template<class _Rp, class _Tp>
lib/libcxx/include/__functional/mem_fun_ref.h+9-9
......@@ -15,7 +15,7 @@
1515#include <__functional/unary_function.h>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -24,7 +24,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2424
2525template<class _Sp, class _Tp>
2626class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun_t
27 : public unary_function<_Tp*, _Sp>
27 : public __unary_function<_Tp*, _Sp>
2828{
2929 _Sp (_Tp::*__p_)();
3030public:
......@@ -36,7 +36,7 @@ public:
3636
3737template<class _Sp, class _Tp, class _Ap>
3838class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun1_t
39 : public binary_function<_Tp*, _Ap, _Sp>
39 : public __binary_function<_Tp*, _Ap, _Sp>
4040{
4141 _Sp (_Tp::*__p_)(_Ap);
4242public:
......@@ -60,7 +60,7 @@ mem_fun(_Sp (_Tp::*__f)(_Ap))
6060
6161template<class _Sp, class _Tp>
6262class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun_ref_t
63 : public unary_function<_Tp, _Sp>
63 : public __unary_function<_Tp, _Sp>
6464{
6565 _Sp (_Tp::*__p_)();
6666public:
......@@ -72,7 +72,7 @@ public:
7272
7373template<class _Sp, class _Tp, class _Ap>
7474class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun1_ref_t
75 : public binary_function<_Tp, _Ap, _Sp>
75 : public __binary_function<_Tp, _Ap, _Sp>
7676{
7777 _Sp (_Tp::*__p_)(_Ap);
7878public:
......@@ -96,7 +96,7 @@ mem_fun_ref(_Sp (_Tp::*__f)(_Ap))
9696
9797template <class _Sp, class _Tp>
9898class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun_t
99 : public unary_function<const _Tp*, _Sp>
99 : public __unary_function<const _Tp*, _Sp>
100100{
101101 _Sp (_Tp::*__p_)() const;
102102public:
......@@ -108,7 +108,7 @@ public:
108108
109109template <class _Sp, class _Tp, class _Ap>
110110class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun1_t
111 : public binary_function<const _Tp*, _Ap, _Sp>
111 : public __binary_function<const _Tp*, _Ap, _Sp>
112112{
113113 _Sp (_Tp::*__p_)(_Ap) const;
114114public:
......@@ -132,7 +132,7 @@ mem_fun(_Sp (_Tp::*__f)(_Ap) const)
132132
133133template <class _Sp, class _Tp>
134134class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun_ref_t
135 : public unary_function<_Tp, _Sp>
135 : public __unary_function<_Tp, _Sp>
136136{
137137 _Sp (_Tp::*__p_)() const;
138138public:
......@@ -144,7 +144,7 @@ public:
144144
145145template <class _Sp, class _Tp, class _Ap>
146146class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun1_ref_t
147 : public binary_function<_Tp, _Ap, _Sp>
147 : public __binary_function<_Tp, _Ap, _Sp>
148148{
149149 _Sp (_Tp::*__p_)(_Ap) const;
150150public:
lib/libcxx/include/__functional/not_fn.h+3-2
......@@ -13,10 +13,11 @@
1313#include <__config>
1414#include <__functional/invoke.h>
1515#include <__functional/perfect_forward.h>
16#include <utility>
16#include <__utility/forward.h>
17#include <type_traits>
1718
1819#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
20# pragma GCC system_header
2021#endif
2122
2223_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__functional/operations.h+20-188
......@@ -16,31 +16,22 @@
1616#include <__utility/forward.h>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
19# pragma GCC system_header
2020#endif
2121
2222_LIBCPP_BEGIN_NAMESPACE_STD
2323
2424// Arithmetic operations
2525
26_LIBCPP_SUPPRESS_DEPRECATED_PUSH
2726#if _LIBCPP_STD_VER > 11
2827template <class _Tp = void>
2928#else
3029template <class _Tp>
3130#endif
3231struct _LIBCPP_TEMPLATE_VIS plus
33#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
34 : binary_function<_Tp, _Tp, _Tp>
35#endif
32 : __binary_function<_Tp, _Tp, _Tp>
3633{
37_LIBCPP_SUPPRESS_DEPRECATED_POP
3834 typedef _Tp __result_type; // used by valarray
39#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
40 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
41 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
42 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
43#endif
4435 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
4536 _Tp operator()(const _Tp& __x, const _Tp& __y) const
4637 {return __x + __y;}
......@@ -60,24 +51,15 @@ struct _LIBCPP_TEMPLATE_VIS plus<void>
6051};
6152#endif
6253
63_LIBCPP_SUPPRESS_DEPRECATED_PUSH
6454#if _LIBCPP_STD_VER > 11
6555template <class _Tp = void>
6656#else
6757template <class _Tp>
6858#endif
6959struct _LIBCPP_TEMPLATE_VIS minus
70#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
71 : binary_function<_Tp, _Tp, _Tp>
72#endif
60 : __binary_function<_Tp, _Tp, _Tp>
7361{
74_LIBCPP_SUPPRESS_DEPRECATED_POP
7562 typedef _Tp __result_type; // used by valarray
76#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
77 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
78 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
79 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
80#endif
8163 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
8264 _Tp operator()(const _Tp& __x, const _Tp& __y) const
8365 {return __x - __y;}
......@@ -97,24 +79,15 @@ struct _LIBCPP_TEMPLATE_VIS minus<void>
9779};
9880#endif
9981
100_LIBCPP_SUPPRESS_DEPRECATED_PUSH
10182#if _LIBCPP_STD_VER > 11
10283template <class _Tp = void>
10384#else
10485template <class _Tp>
10586#endif
10687struct _LIBCPP_TEMPLATE_VIS multiplies
107#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
108 : binary_function<_Tp, _Tp, _Tp>
109#endif
88 : __binary_function<_Tp, _Tp, _Tp>
11089{
111_LIBCPP_SUPPRESS_DEPRECATED_POP
11290 typedef _Tp __result_type; // used by valarray
113#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
114 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
115 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
116 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
117#endif
11891 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
11992 _Tp operator()(const _Tp& __x, const _Tp& __y) const
12093 {return __x * __y;}
......@@ -134,24 +107,15 @@ struct _LIBCPP_TEMPLATE_VIS multiplies<void>
134107};
135108#endif
136109
137_LIBCPP_SUPPRESS_DEPRECATED_PUSH
138110#if _LIBCPP_STD_VER > 11
139111template <class _Tp = void>
140112#else
141113template <class _Tp>
142114#endif
143115struct _LIBCPP_TEMPLATE_VIS divides
144#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
145 : binary_function<_Tp, _Tp, _Tp>
146#endif
116 : __binary_function<_Tp, _Tp, _Tp>
147117{
148_LIBCPP_SUPPRESS_DEPRECATED_POP
149118 typedef _Tp __result_type; // used by valarray
150#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
151 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
152 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
153 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
154#endif
155119 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
156120 _Tp operator()(const _Tp& __x, const _Tp& __y) const
157121 {return __x / __y;}
......@@ -171,24 +135,15 @@ struct _LIBCPP_TEMPLATE_VIS divides<void>
171135};
172136#endif
173137
174_LIBCPP_SUPPRESS_DEPRECATED_PUSH
175138#if _LIBCPP_STD_VER > 11
176139template <class _Tp = void>
177140#else
178141template <class _Tp>
179142#endif
180143struct _LIBCPP_TEMPLATE_VIS modulus
181#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
182 : binary_function<_Tp, _Tp, _Tp>
183#endif
144 : __binary_function<_Tp, _Tp, _Tp>
184145{
185_LIBCPP_SUPPRESS_DEPRECATED_POP
186146 typedef _Tp __result_type; // used by valarray
187#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
188 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
189 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
190 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
191#endif
192147 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
193148 _Tp operator()(const _Tp& __x, const _Tp& __y) const
194149 {return __x % __y;}
......@@ -208,23 +163,15 @@ struct _LIBCPP_TEMPLATE_VIS modulus<void>
208163};
209164#endif
210165
211_LIBCPP_SUPPRESS_DEPRECATED_PUSH
212166#if _LIBCPP_STD_VER > 11
213167template <class _Tp = void>
214168#else
215169template <class _Tp>
216170#endif
217171struct _LIBCPP_TEMPLATE_VIS negate
218#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
219 : unary_function<_Tp, _Tp>
220#endif
172 : __unary_function<_Tp, _Tp>
221173{
222_LIBCPP_SUPPRESS_DEPRECATED_POP
223174 typedef _Tp __result_type; // used by valarray
224#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
225 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
226 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp argument_type;
227#endif
228175 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
229176 _Tp operator()(const _Tp& __x) const
230177 {return -__x;}
......@@ -246,24 +193,15 @@ struct _LIBCPP_TEMPLATE_VIS negate<void>
246193
247194// Bitwise operations
248195
249_LIBCPP_SUPPRESS_DEPRECATED_PUSH
250196#if _LIBCPP_STD_VER > 11
251197template <class _Tp = void>
252198#else
253199template <class _Tp>
254200#endif
255201struct _LIBCPP_TEMPLATE_VIS bit_and
256#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
257 : binary_function<_Tp, _Tp, _Tp>
258#endif
202 : __binary_function<_Tp, _Tp, _Tp>
259203{
260_LIBCPP_SUPPRESS_DEPRECATED_POP
261204 typedef _Tp __result_type; // used by valarray
262#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
263 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
264 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
265 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
266#endif
267205 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
268206 _Tp operator()(const _Tp& __x, const _Tp& __y) const
269207 {return __x & __y;}
......@@ -284,18 +222,10 @@ struct _LIBCPP_TEMPLATE_VIS bit_and<void>
284222#endif
285223
286224#if _LIBCPP_STD_VER > 11
287_LIBCPP_SUPPRESS_DEPRECATED_PUSH
288225template <class _Tp = void>
289226struct _LIBCPP_TEMPLATE_VIS bit_not
290#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
291 : unary_function<_Tp, _Tp>
292#endif
227 : __unary_function<_Tp, _Tp>
293228{
294_LIBCPP_SUPPRESS_DEPRECATED_POP
295#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
296 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
297 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp argument_type;
298#endif
299229 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
300230 _Tp operator()(const _Tp& __x) const
301231 {return ~__x;}
......@@ -314,24 +244,15 @@ struct _LIBCPP_TEMPLATE_VIS bit_not<void>
314244};
315245#endif
316246
317_LIBCPP_SUPPRESS_DEPRECATED_PUSH
318247#if _LIBCPP_STD_VER > 11
319248template <class _Tp = void>
320249#else
321250template <class _Tp>
322251#endif
323252struct _LIBCPP_TEMPLATE_VIS bit_or
324#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
325 : binary_function<_Tp, _Tp, _Tp>
326#endif
253 : __binary_function<_Tp, _Tp, _Tp>
327254{
328_LIBCPP_SUPPRESS_DEPRECATED_POP
329255 typedef _Tp __result_type; // used by valarray
330#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
331 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
332 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
333 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
334#endif
335256 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
336257 _Tp operator()(const _Tp& __x, const _Tp& __y) const
337258 {return __x | __y;}
......@@ -351,24 +272,15 @@ struct _LIBCPP_TEMPLATE_VIS bit_or<void>
351272};
352273#endif
353274
354_LIBCPP_SUPPRESS_DEPRECATED_PUSH
355275#if _LIBCPP_STD_VER > 11
356276template <class _Tp = void>
357277#else
358278template <class _Tp>
359279#endif
360280struct _LIBCPP_TEMPLATE_VIS bit_xor
361#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
362 : binary_function<_Tp, _Tp, _Tp>
363#endif
281 : __binary_function<_Tp, _Tp, _Tp>
364282{
365_LIBCPP_SUPPRESS_DEPRECATED_POP
366283 typedef _Tp __result_type; // used by valarray
367#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
368 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
369 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
370 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
371#endif
372284 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
373285 _Tp operator()(const _Tp& __x, const _Tp& __y) const
374286 {return __x ^ __y;}
......@@ -390,24 +302,15 @@ struct _LIBCPP_TEMPLATE_VIS bit_xor<void>
390302
391303// Comparison operations
392304
393_LIBCPP_SUPPRESS_DEPRECATED_PUSH
394305#if _LIBCPP_STD_VER > 11
395306template <class _Tp = void>
396307#else
397308template <class _Tp>
398309#endif
399310struct _LIBCPP_TEMPLATE_VIS equal_to
400#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
401 : binary_function<_Tp, _Tp, bool>
402#endif
311 : __binary_function<_Tp, _Tp, bool>
403312{
404_LIBCPP_SUPPRESS_DEPRECATED_POP
405313 typedef bool __result_type; // used by valarray
406#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
407 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
408 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
409 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
410#endif
411314 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
412315 bool operator()(const _Tp& __x, const _Tp& __y) const
413316 {return __x == __y;}
......@@ -427,24 +330,15 @@ struct _LIBCPP_TEMPLATE_VIS equal_to<void>
427330};
428331#endif
429332
430_LIBCPP_SUPPRESS_DEPRECATED_PUSH
431333#if _LIBCPP_STD_VER > 11
432334template <class _Tp = void>
433335#else
434336template <class _Tp>
435337#endif
436338struct _LIBCPP_TEMPLATE_VIS not_equal_to
437#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
438 : binary_function<_Tp, _Tp, bool>
439#endif
339 : __binary_function<_Tp, _Tp, bool>
440340{
441_LIBCPP_SUPPRESS_DEPRECATED_POP
442341 typedef bool __result_type; // used by valarray
443#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
444 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
445 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
446 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
447#endif
448342 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
449343 bool operator()(const _Tp& __x, const _Tp& __y) const
450344 {return __x != __y;}
......@@ -464,24 +358,15 @@ struct _LIBCPP_TEMPLATE_VIS not_equal_to<void>
464358};
465359#endif
466360
467_LIBCPP_SUPPRESS_DEPRECATED_PUSH
468361#if _LIBCPP_STD_VER > 11
469362template <class _Tp = void>
470363#else
471364template <class _Tp>
472365#endif
473366struct _LIBCPP_TEMPLATE_VIS less
474#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
475 : binary_function<_Tp, _Tp, bool>
476#endif
367 : __binary_function<_Tp, _Tp, bool>
477368{
478_LIBCPP_SUPPRESS_DEPRECATED_POP
479369 typedef bool __result_type; // used by valarray
480#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
481 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
482 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
483 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
484#endif
485370 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
486371 bool operator()(const _Tp& __x, const _Tp& __y) const
487372 {return __x < __y;}
......@@ -501,24 +386,15 @@ struct _LIBCPP_TEMPLATE_VIS less<void>
501386};
502387#endif
503388
504_LIBCPP_SUPPRESS_DEPRECATED_PUSH
505389#if _LIBCPP_STD_VER > 11
506390template <class _Tp = void>
507391#else
508392template <class _Tp>
509393#endif
510394struct _LIBCPP_TEMPLATE_VIS less_equal
511#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
512 : binary_function<_Tp, _Tp, bool>
513#endif
395 : __binary_function<_Tp, _Tp, bool>
514396{
515_LIBCPP_SUPPRESS_DEPRECATED_POP
516397 typedef bool __result_type; // used by valarray
517#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
518 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
519 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
520 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
521#endif
522398 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
523399 bool operator()(const _Tp& __x, const _Tp& __y) const
524400 {return __x <= __y;}
......@@ -538,24 +414,15 @@ struct _LIBCPP_TEMPLATE_VIS less_equal<void>
538414};
539415#endif
540416
541_LIBCPP_SUPPRESS_DEPRECATED_PUSH
542417#if _LIBCPP_STD_VER > 11
543418template <class _Tp = void>
544419#else
545420template <class _Tp>
546421#endif
547422struct _LIBCPP_TEMPLATE_VIS greater_equal
548#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
549 : binary_function<_Tp, _Tp, bool>
550#endif
423 : __binary_function<_Tp, _Tp, bool>
551424{
552_LIBCPP_SUPPRESS_DEPRECATED_POP
553425 typedef bool __result_type; // used by valarray
554#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
555 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
556 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
557 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
558#endif
559426 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
560427 bool operator()(const _Tp& __x, const _Tp& __y) const
561428 {return __x >= __y;}
......@@ -575,24 +442,15 @@ struct _LIBCPP_TEMPLATE_VIS greater_equal<void>
575442};
576443#endif
577444
578_LIBCPP_SUPPRESS_DEPRECATED_PUSH
579445#if _LIBCPP_STD_VER > 11
580446template <class _Tp = void>
581447#else
582448template <class _Tp>
583449#endif
584450struct _LIBCPP_TEMPLATE_VIS greater
585#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
586 : binary_function<_Tp, _Tp, bool>
587#endif
451 : __binary_function<_Tp, _Tp, bool>
588452{
589_LIBCPP_SUPPRESS_DEPRECATED_POP
590453 typedef bool __result_type; // used by valarray
591#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
592 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
593 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
594 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
595#endif
596454 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
597455 bool operator()(const _Tp& __x, const _Tp& __y) const
598456 {return __x > __y;}
......@@ -614,24 +472,15 @@ struct _LIBCPP_TEMPLATE_VIS greater<void>
614472
615473// Logical operations
616474
617_LIBCPP_SUPPRESS_DEPRECATED_PUSH
618475#if _LIBCPP_STD_VER > 11
619476template <class _Tp = void>
620477#else
621478template <class _Tp>
622479#endif
623480struct _LIBCPP_TEMPLATE_VIS logical_and
624#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
625 : binary_function<_Tp, _Tp, bool>
626#endif
481 : __binary_function<_Tp, _Tp, bool>
627482{
628_LIBCPP_SUPPRESS_DEPRECATED_POP
629483 typedef bool __result_type; // used by valarray
630#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
631 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
632 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
633 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
634#endif
635484 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
636485 bool operator()(const _Tp& __x, const _Tp& __y) const
637486 {return __x && __y;}
......@@ -651,23 +500,15 @@ struct _LIBCPP_TEMPLATE_VIS logical_and<void>
651500};
652501#endif
653502
654_LIBCPP_SUPPRESS_DEPRECATED_PUSH
655503#if _LIBCPP_STD_VER > 11
656504template <class _Tp = void>
657505#else
658506template <class _Tp>
659507#endif
660508struct _LIBCPP_TEMPLATE_VIS logical_not
661#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
662 : unary_function<_Tp, bool>
663#endif
509 : __unary_function<_Tp, bool>
664510{
665_LIBCPP_SUPPRESS_DEPRECATED_POP
666511 typedef bool __result_type; // used by valarray
667#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
668 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
669 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp argument_type;
670#endif
671512 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
672513 bool operator()(const _Tp& __x) const
673514 {return !__x;}
......@@ -687,24 +528,15 @@ struct _LIBCPP_TEMPLATE_VIS logical_not<void>
687528};
688529#endif
689530
690_LIBCPP_SUPPRESS_DEPRECATED_PUSH
691531#if _LIBCPP_STD_VER > 11
692532template <class _Tp = void>
693533#else
694534template <class _Tp>
695535#endif
696536struct _LIBCPP_TEMPLATE_VIS logical_or
697#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
698 : binary_function<_Tp, _Tp, bool>
699#endif
537 : __binary_function<_Tp, _Tp, bool>
700538{
701_LIBCPP_SUPPRESS_DEPRECATED_POP
702539 typedef bool __result_type; // used by valarray
703#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
704 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
705 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
706 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
707#endif
708540 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
709541 bool operator()(const _Tp& __x, const _Tp& __y) const
710542 {return __x || __y;}
lib/libcxx/include/__functional/perfect_forward.h+52-53
......@@ -18,70 +18,69 @@
1818#include <type_traits>
1919
2020#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21#pragma GCC system_header
21# pragma GCC system_header
2222#endif
2323
2424_LIBCPP_BEGIN_NAMESPACE_STD
2525
2626#if _LIBCPP_STD_VER > 14
2727
28template <class _Op, class _Indices, class ..._Bound>
28template <class _Op, class _Indices, class... _BoundArgs>
2929struct __perfect_forward_impl;
3030
31template <class _Op, size_t ..._Idx, class ..._Bound>
32struct __perfect_forward_impl<_Op, index_sequence<_Idx...>, _Bound...> {
31template <class _Op, size_t... _Idx, class... _BoundArgs>
32struct __perfect_forward_impl<_Op, index_sequence<_Idx...>, _BoundArgs...> {
3333private:
34 tuple<_Bound...> __bound_;
34 tuple<_BoundArgs...> __bound_args_;
3535
3636public:
37 template <class ..._BoundArgs, class = enable_if_t<
38 is_constructible_v<tuple<_Bound...>, _BoundArgs&&...>
39 >>
40 explicit constexpr __perfect_forward_impl(_BoundArgs&& ...__bound)
41 : __bound_(_VSTD::forward<_BoundArgs>(__bound)...)
42 { }
43
44 __perfect_forward_impl(__perfect_forward_impl const&) = default;
45 __perfect_forward_impl(__perfect_forward_impl&&) = default;
46
47 __perfect_forward_impl& operator=(__perfect_forward_impl const&) = default;
48 __perfect_forward_impl& operator=(__perfect_forward_impl&&) = default;
49
50 template <class ..._Args, class = enable_if_t<is_invocable_v<_Op, _Bound&..., _Args...>>>
51 _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Args&&... __args) &
52 noexcept(noexcept(_Op()(_VSTD::get<_Idx>(__bound_)..., _VSTD::forward<_Args>(__args)...)))
53 -> decltype( _Op()(_VSTD::get<_Idx>(__bound_)..., _VSTD::forward<_Args>(__args)...))
54 { return _Op()(_VSTD::get<_Idx>(__bound_)..., _VSTD::forward<_Args>(__args)...); }
55
56 template <class ..._Args, class = enable_if_t<!is_invocable_v<_Op, _Bound&..., _Args...>>>
57 auto operator()(_Args&&...) & = delete;
58
59 template <class ..._Args, class = enable_if_t<is_invocable_v<_Op, _Bound const&..., _Args...>>>
60 _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Args&&... __args) const&
61 noexcept(noexcept(_Op()(_VSTD::get<_Idx>(__bound_)..., _VSTD::forward<_Args>(__args)...)))
62 -> decltype( _Op()(_VSTD::get<_Idx>(__bound_)..., _VSTD::forward<_Args>(__args)...))
63 { return _Op()(_VSTD::get<_Idx>(__bound_)..., _VSTD::forward<_Args>(__args)...); }
64
65 template <class ..._Args, class = enable_if_t<!is_invocable_v<_Op, _Bound const&..., _Args...>>>
66 auto operator()(_Args&&...) const& = delete;
67
68 template <class ..._Args, class = enable_if_t<is_invocable_v<_Op, _Bound..., _Args...>>>
69 _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Args&&... __args) &&
70 noexcept(noexcept(_Op()(_VSTD::get<_Idx>(_VSTD::move(__bound_))..., _VSTD::forward<_Args>(__args)...)))
71 -> decltype( _Op()(_VSTD::get<_Idx>(_VSTD::move(__bound_))..., _VSTD::forward<_Args>(__args)...))
72 { return _Op()(_VSTD::get<_Idx>(_VSTD::move(__bound_))..., _VSTD::forward<_Args>(__args)...); }
73
74 template <class ..._Args, class = enable_if_t<!is_invocable_v<_Op, _Bound..., _Args...>>>
75 auto operator()(_Args&&...) && = delete;
76
77 template <class ..._Args, class = enable_if_t<is_invocable_v<_Op, _Bound const..., _Args...>>>
78 _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Args&&... __args) const&&
79 noexcept(noexcept(_Op()(_VSTD::get<_Idx>(_VSTD::move(__bound_))..., _VSTD::forward<_Args>(__args)...)))
80 -> decltype( _Op()(_VSTD::get<_Idx>(_VSTD::move(__bound_))..., _VSTD::forward<_Args>(__args)...))
81 { return _Op()(_VSTD::get<_Idx>(_VSTD::move(__bound_))..., _VSTD::forward<_Args>(__args)...); }
82
83 template <class ..._Args, class = enable_if_t<!is_invocable_v<_Op, _Bound const..., _Args...>>>
84 auto operator()(_Args&&...) const&& = delete;
37 template <class... _Args, class = enable_if_t<
38 is_constructible_v<tuple<_BoundArgs...>, _Args&&...>
39 >>
40 explicit constexpr __perfect_forward_impl(_Args&&... __bound_args)
41 : __bound_args_(_VSTD::forward<_Args>(__bound_args)...) {}
42
43 __perfect_forward_impl(__perfect_forward_impl const&) = default;
44 __perfect_forward_impl(__perfect_forward_impl&&) = default;
45
46 __perfect_forward_impl& operator=(__perfect_forward_impl const&) = default;
47 __perfect_forward_impl& operator=(__perfect_forward_impl&&) = default;
48
49 template <class... _Args, class = enable_if_t<is_invocable_v<_Op, _BoundArgs&..., _Args...>>>
50 _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Args&&... __args) &
51 noexcept(noexcept(_Op()(_VSTD::get<_Idx>(__bound_args_)..., _VSTD::forward<_Args>(__args)...)))
52 -> decltype( _Op()(_VSTD::get<_Idx>(__bound_args_)..., _VSTD::forward<_Args>(__args)...))
53 { return _Op()(_VSTD::get<_Idx>(__bound_args_)..., _VSTD::forward<_Args>(__args)...); }
54
55 template <class... _Args, class = enable_if_t<!is_invocable_v<_Op, _BoundArgs&..., _Args...>>>
56 auto operator()(_Args&&...) & = delete;
57
58 template <class... _Args, class = enable_if_t<is_invocable_v<_Op, _BoundArgs const&..., _Args...>>>
59 _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Args&&... __args) const&
60 noexcept(noexcept(_Op()(_VSTD::get<_Idx>(__bound_args_)..., _VSTD::forward<_Args>(__args)...)))
61 -> decltype( _Op()(_VSTD::get<_Idx>(__bound_args_)..., _VSTD::forward<_Args>(__args)...))
62 { return _Op()(_VSTD::get<_Idx>(__bound_args_)..., _VSTD::forward<_Args>(__args)...); }
63
64 template <class... _Args, class = enable_if_t<!is_invocable_v<_Op, _BoundArgs const&..., _Args...>>>
65 auto operator()(_Args&&...) const& = delete;
66
67 template <class... _Args, class = enable_if_t<is_invocable_v<_Op, _BoundArgs..., _Args...>>>
68 _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Args&&... __args) &&
69 noexcept(noexcept(_Op()(_VSTD::get<_Idx>(_VSTD::move(__bound_args_))..., _VSTD::forward<_Args>(__args)...)))
70 -> decltype( _Op()(_VSTD::get<_Idx>(_VSTD::move(__bound_args_))..., _VSTD::forward<_Args>(__args)...))
71 { return _Op()(_VSTD::get<_Idx>(_VSTD::move(__bound_args_))..., _VSTD::forward<_Args>(__args)...); }
72
73 template <class... _Args, class = enable_if_t<!is_invocable_v<_Op, _BoundArgs..., _Args...>>>
74 auto operator()(_Args&&...) && = delete;
75
76 template <class... _Args, class = enable_if_t<is_invocable_v<_Op, _BoundArgs const..., _Args...>>>
77 _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Args&&... __args) const&&
78 noexcept(noexcept(_Op()(_VSTD::get<_Idx>(_VSTD::move(__bound_args_))..., _VSTD::forward<_Args>(__args)...)))
79 -> decltype( _Op()(_VSTD::get<_Idx>(_VSTD::move(__bound_args_))..., _VSTD::forward<_Args>(__args)...))
80 { return _Op()(_VSTD::get<_Idx>(_VSTD::move(__bound_args_))..., _VSTD::forward<_Args>(__args)...); }
81
82 template <class... _Args, class = enable_if_t<!is_invocable_v<_Op, _BoundArgs const..., _Args...>>>
83 auto operator()(_Args&&...) const&& = delete;
8584};
8685
8786// __perfect_forward implements a perfect-forwarding call wrapper as explained in [func.require].
lib/libcxx/include/__functional/pointer_to_binary_function.h+2-2
......@@ -14,7 +14,7 @@
1414#include <__functional/binary_function.h>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
17# pragma GCC system_header
1818#endif
1919
2020_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -23,7 +23,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2323
2424template <class _Arg1, class _Arg2, class _Result>
2525class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 pointer_to_binary_function
26 : public binary_function<_Arg1, _Arg2, _Result>
26 : public __binary_function<_Arg1, _Arg2, _Result>
2727{
2828 _Result (*__f_)(_Arg1, _Arg2);
2929public:
lib/libcxx/include/__functional/pointer_to_unary_function.h+2-2
......@@ -14,7 +14,7 @@
1414#include <__functional/unary_function.h>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
17# pragma GCC system_header
1818#endif
1919
2020_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -23,7 +23,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2323
2424template <class _Arg, class _Result>
2525class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 pointer_to_unary_function
26 : public unary_function<_Arg, _Result>
26 : public __unary_function<_Arg, _Result>
2727{
2828 _Result (*__f_)(_Arg);
2929public:
lib/libcxx/include/__functional/ranges_operations.h+5-4
......@@ -11,16 +11,16 @@
1111#define _LIBCPP___FUNCTIONAL_RANGES_OPERATIONS_H
1212
1313#include <__config>
14#include <__utility/forward.h>
1415#include <concepts>
15#include <utility>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
2222
23#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
23#if _LIBCPP_STD_VER > 17
2424
2525namespace ranges {
2626
......@@ -91,7 +91,8 @@ struct greater_equal {
9191};
9292
9393} // namespace ranges
94#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
94
95#endif // _LIBCPP_STD_VER > 17
9596
9697_LIBCPP_END_NAMESPACE_STD
9798
lib/libcxx/include/__functional/reference_wrapper.h+3-113
......@@ -17,16 +17,13 @@
1717#include <type_traits>
1818
1919#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20#pragma GCC system_header
20# pragma GCC system_header
2121#endif
2222
2323_LIBCPP_BEGIN_NAMESPACE_STD
2424
2525template <class _Tp>
26class _LIBCPP_TEMPLATE_VIS reference_wrapper
27#if _LIBCPP_STD_VER <= 17 || !defined(_LIBCPP_ABI_NO_BINDER_BASES)
28 : public __weak_result_type<_Tp>
29#endif
26class _LIBCPP_TEMPLATE_VIS reference_wrapper : public __weak_result_type<_Tp>
3027{
3128public:
3229 // types
......@@ -51,120 +48,13 @@ public:
5148 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
5249 type& get() const _NOEXCEPT {return *__f_;}
5350
54#ifndef _LIBCPP_CXX03_LANG
5551 // invoke
5652 template <class... _ArgTypes>
5753 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
5854 typename __invoke_of<type&, _ArgTypes...>::type
5955 operator() (_ArgTypes&&... __args) const {
60 return _VSTD::__invoke(get(), _VSTD::forward<_ArgTypes>(__args)...);
61 }
62#else
63
64 _LIBCPP_INLINE_VISIBILITY
65 typename __invoke_return<type>::type
66 operator() () const {
67 return _VSTD::__invoke(get());
68 }
69
70 template <class _A0>
71 _LIBCPP_INLINE_VISIBILITY
72 typename __invoke_return0<type, _A0>::type
73 operator() (_A0& __a0) const {
74 return _VSTD::__invoke(get(), __a0);
75 }
76
77 template <class _A0>
78 _LIBCPP_INLINE_VISIBILITY
79 typename __invoke_return0<type, _A0 const>::type
80 operator() (_A0 const& __a0) const {
81 return _VSTD::__invoke(get(), __a0);
82 }
83
84 template <class _A0, class _A1>
85 _LIBCPP_INLINE_VISIBILITY
86 typename __invoke_return1<type, _A0, _A1>::type
87 operator() (_A0& __a0, _A1& __a1) const {
88 return _VSTD::__invoke(get(), __a0, __a1);
89 }
90
91 template <class _A0, class _A1>
92 _LIBCPP_INLINE_VISIBILITY
93 typename __invoke_return1<type, _A0 const, _A1>::type
94 operator() (_A0 const& __a0, _A1& __a1) const {
95 return _VSTD::__invoke(get(), __a0, __a1);
96 }
97
98 template <class _A0, class _A1>
99 _LIBCPP_INLINE_VISIBILITY
100 typename __invoke_return1<type, _A0, _A1 const>::type
101 operator() (_A0& __a0, _A1 const& __a1) const {
102 return _VSTD::__invoke(get(), __a0, __a1);
103 }
104
105 template <class _A0, class _A1>
106 _LIBCPP_INLINE_VISIBILITY
107 typename __invoke_return1<type, _A0 const, _A1 const>::type
108 operator() (_A0 const& __a0, _A1 const& __a1) const {
109 return _VSTD::__invoke(get(), __a0, __a1);
110 }
111
112 template <class _A0, class _A1, class _A2>
113 _LIBCPP_INLINE_VISIBILITY
114 typename __invoke_return2<type, _A0, _A1, _A2>::type
115 operator() (_A0& __a0, _A1& __a1, _A2& __a2) const {
116 return _VSTD::__invoke(get(), __a0, __a1, __a2);
117 }
118
119 template <class _A0, class _A1, class _A2>
120 _LIBCPP_INLINE_VISIBILITY
121 typename __invoke_return2<type, _A0 const, _A1, _A2>::type
122 operator() (_A0 const& __a0, _A1& __a1, _A2& __a2) const {
123 return _VSTD::__invoke(get(), __a0, __a1, __a2);
124 }
125
126 template <class _A0, class _A1, class _A2>
127 _LIBCPP_INLINE_VISIBILITY
128 typename __invoke_return2<type, _A0, _A1 const, _A2>::type
129 operator() (_A0& __a0, _A1 const& __a1, _A2& __a2) const {
130 return _VSTD::__invoke(get(), __a0, __a1, __a2);
131 }
132
133 template <class _A0, class _A1, class _A2>
134 _LIBCPP_INLINE_VISIBILITY
135 typename __invoke_return2<type, _A0, _A1, _A2 const>::type
136 operator() (_A0& __a0, _A1& __a1, _A2 const& __a2) const {
137 return _VSTD::__invoke(get(), __a0, __a1, __a2);
138 }
139
140 template <class _A0, class _A1, class _A2>
141 _LIBCPP_INLINE_VISIBILITY
142 typename __invoke_return2<type, _A0 const, _A1 const, _A2>::type
143 operator() (_A0 const& __a0, _A1 const& __a1, _A2& __a2) const {
144 return _VSTD::__invoke(get(), __a0, __a1, __a2);
145 }
146
147 template <class _A0, class _A1, class _A2>
148 _LIBCPP_INLINE_VISIBILITY
149 typename __invoke_return2<type, _A0 const, _A1, _A2 const>::type
150 operator() (_A0 const& __a0, _A1& __a1, _A2 const& __a2) const {
151 return _VSTD::__invoke(get(), __a0, __a1, __a2);
152 }
153
154 template <class _A0, class _A1, class _A2>
155 _LIBCPP_INLINE_VISIBILITY
156 typename __invoke_return2<type, _A0, _A1 const, _A2 const>::type
157 operator() (_A0& __a0, _A1 const& __a1, _A2 const& __a2) const {
158 return _VSTD::__invoke(get(), __a0, __a1, __a2);
159 }
160
161 template <class _A0, class _A1, class _A2>
162 _LIBCPP_INLINE_VISIBILITY
163 typename __invoke_return2<type, _A0 const, _A1 const, _A2 const>::type
164 operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const {
165 return _VSTD::__invoke(get(), __a0, __a1, __a2);
56 return std::__invoke(get(), std::forward<_ArgTypes>(__args)...);
16657 }
167#endif // _LIBCPP_CXX03_LANG
16858};
16959
17060#if _LIBCPP_STD_VER > 14
lib/libcxx/include/__functional/unary_function.h+24-2
......@@ -12,18 +12,40 @@
1212#include <__config>
1313
1414#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15#pragma GCC system_header
15# pragma GCC system_header
1616#endif
1717
1818_LIBCPP_BEGIN_NAMESPACE_STD
1919
20#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION)
21
2022template <class _Arg, class _Result>
21struct _LIBCPP_TEMPLATE_VIS unary_function
23struct _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 unary_function
2224{
2325 typedef _Arg argument_type;
2426 typedef _Result result_type;
2527};
2628
29#endif // _LIBCPP_STD_VER <= 14
30
31template <class _Arg, class _Result> struct __unary_function_keep_layout_base {
32#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
33 using argument_type _LIBCPP_DEPRECATED_IN_CXX17 = _Arg;
34 using result_type _LIBCPP_DEPRECATED_IN_CXX17 = _Result;
35#endif
36};
37
38#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION)
39_LIBCPP_DIAGNOSTIC_PUSH
40_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
41template <class _Arg, class _Result>
42using __unary_function = unary_function<_Arg, _Result>;
43_LIBCPP_DIAGNOSTIC_POP
44#else
45template <class _Arg, class _Result>
46using __unary_function = __unary_function_keep_layout_base<_Arg, _Result>;
47#endif
48
2749_LIBCPP_END_NAMESPACE_STD
2850
2951#endif // _LIBCPP___FUNCTIONAL_UNARY_FUNCTION_H
lib/libcxx/include/__functional/unary_negate.h+2-2
......@@ -14,7 +14,7 @@
1414#include <__functional/unary_function.h>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
17# pragma GCC system_header
1818#endif
1919
2020_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -23,7 +23,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2323
2424template <class _Predicate>
2525class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 unary_negate
26 : public unary_function<typename _Predicate::argument_type, bool>
26 : public __unary_function<typename _Predicate::argument_type, bool>
2727{
2828 _Predicate __pred_;
2929public:
lib/libcxx/include/__functional/unwrap_ref.h+1-1
......@@ -12,7 +12,7 @@
1212#include <__config>
1313
1414#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15#pragma GCC system_header
15# pragma GCC system_header
1616#endif
1717
1818_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__functional/weak_result_type.h+57-247
......@@ -16,7 +16,7 @@
1616#include <type_traits>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
19# pragma GCC system_header
2020#endif
2121
2222_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -25,11 +25,10 @@ template <class _Tp>
2525struct __has_result_type
2626{
2727private:
28 struct __two {char __lx; char __lxx;};
29 template <class _Up> static __two __test(...);
30 template <class _Up> static char __test(typename _Up::result_type* = 0);
28 template <class _Up> static false_type __test(...);
29 template <class _Up> static true_type __test(typename _Up::result_type* = 0);
3130public:
32 static const bool value = sizeof(__test<_Tp>(0)) == 1;
31 static const bool value = decltype(__test<_Tp>(0))::value;
3332};
3433
3534// __weak_result_type
......@@ -41,8 +40,9 @@ private:
4140 struct __two {char __lx; char __lxx;};
4241 static __two __test(...);
4342 template <class _Ap, class _Rp>
44 static unary_function<_Ap, _Rp>
45 __test(const volatile unary_function<_Ap, _Rp>*);
43 static __unary_function<_Ap, _Rp>
44 __test(const volatile __unary_function<_Ap, _Rp>*);
45
4646public:
4747 static const bool value = !is_same<decltype(__test((_Tp*)0)), __two>::value;
4848 typedef decltype(__test((_Tp*)0)) type;
......@@ -55,8 +55,9 @@ private:
5555 struct __two {char __lx; char __lxx;};
5656 static __two __test(...);
5757 template <class _A1, class _A2, class _Rp>
58 static binary_function<_A1, _A2, _Rp>
59 __test(const volatile binary_function<_A1, _A2, _Rp>*);
58 static __binary_function<_A1, _A2, _Rp>
59 __test(const volatile __binary_function<_A1, _A2, _Rp>*);
60
6061public:
6162 static const bool value = !is_same<decltype(__test((_Tp*)0)), __two>::value;
6263 typedef decltype(__test((_Tp*)0)) type;
......@@ -89,7 +90,9 @@ struct __weak_result_type_imp // bool is true
8990 : public __maybe_derive_from_unary_function<_Tp>,
9091 public __maybe_derive_from_binary_function<_Tp>
9192{
92 typedef _LIBCPP_NODEBUG typename _Tp::result_type result_type;
93#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
94 using result_type _LIBCPP_NODEBUG _LIBCPP_DEPRECATED_IN_CXX17 = typename _Tp::result_type;
95#endif
9396};
9497
9598template <class _Tp>
......@@ -110,62 +113,68 @@ struct __weak_result_type
110113template <class _Rp>
111114struct __weak_result_type<_Rp ()>
112115{
113 typedef _LIBCPP_NODEBUG _Rp result_type;
116#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
117 using result_type _LIBCPP_NODEBUG _LIBCPP_DEPRECATED_IN_CXX17 = _Rp;
118#endif
114119};
115120
116121template <class _Rp>
117122struct __weak_result_type<_Rp (&)()>
118123{
119 typedef _LIBCPP_NODEBUG _Rp result_type;
124#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
125 using result_type _LIBCPP_NODEBUG _LIBCPP_DEPRECATED_IN_CXX17 = _Rp;
126#endif
120127};
121128
122129template <class _Rp>
123130struct __weak_result_type<_Rp (*)()>
124131{
125 typedef _LIBCPP_NODEBUG _Rp result_type;
132#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
133 using result_type _LIBCPP_NODEBUG _LIBCPP_DEPRECATED_IN_CXX17 = _Rp;
134#endif
126135};
127136
128137// 1 argument case
129138
130139template <class _Rp, class _A1>
131140struct __weak_result_type<_Rp (_A1)>
132 : public unary_function<_A1, _Rp>
141 : public __unary_function<_A1, _Rp>
133142{
134143};
135144
136145template <class _Rp, class _A1>
137146struct __weak_result_type<_Rp (&)(_A1)>
138 : public unary_function<_A1, _Rp>
147 : public __unary_function<_A1, _Rp>
139148{
140149};
141150
142151template <class _Rp, class _A1>
143152struct __weak_result_type<_Rp (*)(_A1)>
144 : public unary_function<_A1, _Rp>
153 : public __unary_function<_A1, _Rp>
145154{
146155};
147156
148157template <class _Rp, class _Cp>
149158struct __weak_result_type<_Rp (_Cp::*)()>
150 : public unary_function<_Cp*, _Rp>
159 : public __unary_function<_Cp*, _Rp>
151160{
152161};
153162
154163template <class _Rp, class _Cp>
155164struct __weak_result_type<_Rp (_Cp::*)() const>
156 : public unary_function<const _Cp*, _Rp>
165 : public __unary_function<const _Cp*, _Rp>
157166{
158167};
159168
160169template <class _Rp, class _Cp>
161170struct __weak_result_type<_Rp (_Cp::*)() volatile>
162 : public unary_function<volatile _Cp*, _Rp>
171 : public __unary_function<volatile _Cp*, _Rp>
163172{
164173};
165174
166175template <class _Rp, class _Cp>
167176struct __weak_result_type<_Rp (_Cp::*)() const volatile>
168 : public unary_function<const volatile _Cp*, _Rp>
177 : public __unary_function<const volatile _Cp*, _Rp>
169178{
170179};
171180
......@@ -173,90 +182,102 @@ struct __weak_result_type<_Rp (_Cp::*)() const volatile>
173182
174183template <class _Rp, class _A1, class _A2>
175184struct __weak_result_type<_Rp (_A1, _A2)>
176 : public binary_function<_A1, _A2, _Rp>
185 : public __binary_function<_A1, _A2, _Rp>
177186{
178187};
179188
180189template <class _Rp, class _A1, class _A2>
181190struct __weak_result_type<_Rp (*)(_A1, _A2)>
182 : public binary_function<_A1, _A2, _Rp>
191 : public __binary_function<_A1, _A2, _Rp>
183192{
184193};
185194
186195template <class _Rp, class _A1, class _A2>
187196struct __weak_result_type<_Rp (&)(_A1, _A2)>
188 : public binary_function<_A1, _A2, _Rp>
197 : public __binary_function<_A1, _A2, _Rp>
189198{
190199};
191200
192201template <class _Rp, class _Cp, class _A1>
193202struct __weak_result_type<_Rp (_Cp::*)(_A1)>
194 : public binary_function<_Cp*, _A1, _Rp>
203 : public __binary_function<_Cp*, _A1, _Rp>
195204{
196205};
197206
198207template <class _Rp, class _Cp, class _A1>
199208struct __weak_result_type<_Rp (_Cp::*)(_A1) const>
200 : public binary_function<const _Cp*, _A1, _Rp>
209 : public __binary_function<const _Cp*, _A1, _Rp>
201210{
202211};
203212
204213template <class _Rp, class _Cp, class _A1>
205214struct __weak_result_type<_Rp (_Cp::*)(_A1) volatile>
206 : public binary_function<volatile _Cp*, _A1, _Rp>
215 : public __binary_function<volatile _Cp*, _A1, _Rp>
207216{
208217};
209218
210219template <class _Rp, class _Cp, class _A1>
211220struct __weak_result_type<_Rp (_Cp::*)(_A1) const volatile>
212 : public binary_function<const volatile _Cp*, _A1, _Rp>
221 : public __binary_function<const volatile _Cp*, _A1, _Rp>
213222{
214223};
215224
216
217#ifndef _LIBCPP_CXX03_LANG
218225// 3 or more arguments
219226
220227template <class _Rp, class _A1, class _A2, class _A3, class ..._A4>
221228struct __weak_result_type<_Rp (_A1, _A2, _A3, _A4...)>
222229{
223 typedef _Rp result_type;
230#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
231 using result_type _LIBCPP_NODEBUG _LIBCPP_DEPRECATED_IN_CXX17 = _Rp;
232#endif
224233};
225234
226235template <class _Rp, class _A1, class _A2, class _A3, class ..._A4>
227236struct __weak_result_type<_Rp (&)(_A1, _A2, _A3, _A4...)>
228237{
229 typedef _Rp result_type;
238#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
239 using result_type _LIBCPP_NODEBUG _LIBCPP_DEPRECATED_IN_CXX17 = _Rp;
240#endif
230241};
231242
232243template <class _Rp, class _A1, class _A2, class _A3, class ..._A4>
233244struct __weak_result_type<_Rp (*)(_A1, _A2, _A3, _A4...)>
234245{
235 typedef _Rp result_type;
246#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
247 using result_type _LIBCPP_NODEBUG _LIBCPP_DEPRECATED_IN_CXX17 = _Rp;
248#endif
236249};
237250
238251template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
239252struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...)>
240253{
241 typedef _Rp result_type;
254#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
255 using result_type _LIBCPP_NODEBUG _LIBCPP_DEPRECATED_IN_CXX17 = _Rp;
256#endif
242257};
243258
244259template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
245260struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) const>
246261{
247 typedef _Rp result_type;
262#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
263 using result_type _LIBCPP_NODEBUG _LIBCPP_DEPRECATED_IN_CXX17 = _Rp;
264#endif
248265};
249266
250267template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
251268struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) volatile>
252269{
253 typedef _Rp result_type;
270#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
271 using result_type _LIBCPP_NODEBUG _LIBCPP_DEPRECATED_IN_CXX17 = _Rp;
272#endif
254273};
255274
256275template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
257276struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) const volatile>
258277{
259 typedef _Rp result_type;
278#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
279 using result_type _LIBCPP_NODEBUG _LIBCPP_DEPRECATED_IN_CXX17 = _Rp;
280#endif
260281};
261282
262283template <class _Tp, class ..._Args>
......@@ -265,217 +286,6 @@ struct __invoke_return
265286 typedef decltype(_VSTD::__invoke(declval<_Tp>(), declval<_Args>()...)) type;
266287};
267288
268#else // defined(_LIBCPP_CXX03_LANG)
269
270template <class _Ret, class _T1, bool _IsFunc, bool _IsBase>
271struct __enable_invoke_imp;
272
273template <class _Ret, class _T1>
274struct __enable_invoke_imp<_Ret, _T1, true, true> {
275 typedef _Ret _Bullet1;
276 typedef _Bullet1 type;
277};
278
279template <class _Ret, class _T1>
280struct __enable_invoke_imp<_Ret, _T1, true, false> {
281 typedef _Ret _Bullet2;
282 typedef _Bullet2 type;
283};
284
285template <class _Ret, class _T1>
286struct __enable_invoke_imp<_Ret, _T1, false, true> {
287 typedef typename add_lvalue_reference<
288 typename __apply_cv<_T1, _Ret>::type
289 >::type _Bullet3;
290 typedef _Bullet3 type;
291};
292
293template <class _Ret, class _T1>
294struct __enable_invoke_imp<_Ret, _T1, false, false> {
295 typedef typename add_lvalue_reference<
296 typename __apply_cv<decltype(*declval<_T1>()), _Ret>::type
297 >::type _Bullet4;
298 typedef _Bullet4 type;
299};
300
301template <class _Ret, class _T1>
302struct __enable_invoke_imp<_Ret, _T1*, false, false> {
303 typedef typename add_lvalue_reference<
304 typename __apply_cv<_T1, _Ret>::type
305 >::type _Bullet4;
306 typedef _Bullet4 type;
307};
308
309template <class _Fn, class _T1,
310 class _Traits = __member_pointer_traits<_Fn>,
311 class _Ret = typename _Traits::_ReturnType,
312 class _Class = typename _Traits::_ClassType>
313struct __enable_invoke : __enable_invoke_imp<
314 _Ret, _T1,
315 is_member_function_pointer<_Fn>::value,
316 is_base_of<_Class, typename remove_reference<_T1>::type>::value>
317{
318};
319
320__nat __invoke(__any, ...);
321
322// first bullet
323
324template <class _Fn, class _T1>
325inline _LIBCPP_INLINE_VISIBILITY
326typename __enable_invoke<_Fn, _T1>::_Bullet1
327__invoke(_Fn __f, _T1& __t1) {
328 return (__t1.*__f)();
329}
330
331template <class _Fn, class _T1, class _A0>
332inline _LIBCPP_INLINE_VISIBILITY
333typename __enable_invoke<_Fn, _T1>::_Bullet1
334__invoke(_Fn __f, _T1& __t1, _A0& __a0) {
335 return (__t1.*__f)(__a0);
336}
337
338template <class _Fn, class _T1, class _A0, class _A1>
339inline _LIBCPP_INLINE_VISIBILITY
340typename __enable_invoke<_Fn, _T1>::_Bullet1
341__invoke(_Fn __f, _T1& __t1, _A0& __a0, _A1& __a1) {
342 return (__t1.*__f)(__a0, __a1);
343}
344
345template <class _Fn, class _T1, class _A0, class _A1, class _A2>
346inline _LIBCPP_INLINE_VISIBILITY
347typename __enable_invoke<_Fn, _T1>::_Bullet1
348__invoke(_Fn __f, _T1& __t1, _A0& __a0, _A1& __a1, _A2& __a2) {
349 return (__t1.*__f)(__a0, __a1, __a2);
350}
351
352template <class _Fn, class _T1>
353inline _LIBCPP_INLINE_VISIBILITY
354typename __enable_invoke<_Fn, _T1>::_Bullet2
355__invoke(_Fn __f, _T1& __t1) {
356 return ((*__t1).*__f)();
357}
358
359template <class _Fn, class _T1, class _A0>
360inline _LIBCPP_INLINE_VISIBILITY
361typename __enable_invoke<_Fn, _T1>::_Bullet2
362__invoke(_Fn __f, _T1& __t1, _A0& __a0) {
363 return ((*__t1).*__f)(__a0);
364}
365
366template <class _Fn, class _T1, class _A0, class _A1>
367inline _LIBCPP_INLINE_VISIBILITY
368typename __enable_invoke<_Fn, _T1>::_Bullet2
369__invoke(_Fn __f, _T1& __t1, _A0& __a0, _A1& __a1) {
370 return ((*__t1).*__f)(__a0, __a1);
371}
372
373template <class _Fn, class _T1, class _A0, class _A1, class _A2>
374inline _LIBCPP_INLINE_VISIBILITY
375typename __enable_invoke<_Fn, _T1>::_Bullet2
376__invoke(_Fn __f, _T1& __t1, _A0& __a0, _A1& __a1, _A2& __a2) {
377 return ((*__t1).*__f)(__a0, __a1, __a2);
378}
379
380template <class _Fn, class _T1>
381inline _LIBCPP_INLINE_VISIBILITY
382typename __enable_invoke<_Fn, _T1>::_Bullet3
383__invoke(_Fn __f, _T1& __t1) {
384 return __t1.*__f;
385}
386
387template <class _Fn, class _T1>
388inline _LIBCPP_INLINE_VISIBILITY
389typename __enable_invoke<_Fn, _T1>::_Bullet4
390__invoke(_Fn __f, _T1& __t1) {
391 return (*__t1).*__f;
392}
393
394// fifth bullet
395
396template <class _Fp>
397inline _LIBCPP_INLINE_VISIBILITY
398decltype(declval<_Fp&>()())
399__invoke(_Fp& __f)
400{
401 return __f();
402}
403
404template <class _Fp, class _A0>
405inline _LIBCPP_INLINE_VISIBILITY
406decltype(declval<_Fp&>()(declval<_A0&>()))
407__invoke(_Fp& __f, _A0& __a0)
408{
409 return __f(__a0);
410}
411
412template <class _Fp, class _A0, class _A1>
413inline _LIBCPP_INLINE_VISIBILITY
414decltype(declval<_Fp&>()(declval<_A0&>(), declval<_A1&>()))
415__invoke(_Fp& __f, _A0& __a0, _A1& __a1)
416{
417 return __f(__a0, __a1);
418}
419
420template <class _Fp, class _A0, class _A1, class _A2>
421inline _LIBCPP_INLINE_VISIBILITY
422decltype(declval<_Fp&>()(declval<_A0&>(), declval<_A1&>(), declval<_A2&>()))
423__invoke(_Fp& __f, _A0& __a0, _A1& __a1, _A2& __a2)
424{
425 return __f(__a0, __a1, __a2);
426}
427
428template <class _Fp, bool = __has_result_type<__weak_result_type<_Fp> >::value>
429struct __invoke_return
430{
431 typedef typename __weak_result_type<_Fp>::result_type type;
432};
433
434template <class _Fp>
435struct __invoke_return<_Fp, false>
436{
437 typedef decltype(_VSTD::__invoke(declval<_Fp&>())) type;
438};
439
440template <class _Tp, class _A0>
441struct __invoke_return0
442{
443 typedef decltype(_VSTD::__invoke(declval<_Tp&>(), declval<_A0&>())) type;
444};
445
446template <class _Rp, class _Tp, class _A0>
447struct __invoke_return0<_Rp _Tp::*, _A0>
448{
449 typedef typename __enable_invoke<_Rp _Tp::*, _A0>::type type;
450};
451
452template <class _Tp, class _A0, class _A1>
453struct __invoke_return1
454{
455 typedef decltype(_VSTD::__invoke(declval<_Tp&>(), declval<_A0&>(),
456 declval<_A1&>())) type;
457};
458
459template <class _Rp, class _Class, class _A0, class _A1>
460struct __invoke_return1<_Rp _Class::*, _A0, _A1> {
461 typedef typename __enable_invoke<_Rp _Class::*, _A0>::type type;
462};
463
464template <class _Tp, class _A0, class _A1, class _A2>
465struct __invoke_return2
466{
467 typedef decltype(_VSTD::__invoke(declval<_Tp&>(), declval<_A0&>(),
468 declval<_A1&>(),
469 declval<_A2&>())) type;
470};
471
472template <class _Ret, class _Class, class _A0, class _A1, class _A2>
473struct __invoke_return2<_Ret _Class::*, _A0, _A1, _A2> {
474 typedef typename __enable_invoke<_Ret _Class::*, _A0>::type type;
475};
476
477#endif // !defined(_LIBCPP_CXX03_LANG)
478
479289_LIBCPP_END_NAMESPACE_STD
480290
481291#endif // _LIBCPP___FUNCTIONAL_WEAK_RESULT_TYPE_H
lib/libcxx/include/__functional_base deleted-32
......@@ -1,32 +0,0 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_FUNCTIONAL_BASE
11#define _LIBCPP_FUNCTIONAL_BASE
12
13#include <__config>
14#include <__functional/binary_function.h>
15#include <__functional/invoke.h>
16#include <__functional/operations.h>
17#include <__functional/reference_wrapper.h>
18#include <__functional/unary_function.h>
19#include <__functional/weak_result_type.h>
20#include <__memory/allocator_arg_t.h>
21#include <__memory/uses_allocator.h>
22#include <exception>
23#include <new>
24#include <type_traits>
25#include <typeinfo>
26#include <utility>
27
28#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
29#pragma GCC system_header
30#endif
31
32#endif // _LIBCPP_FUNCTIONAL_BASE
lib/libcxx/include/__fwd/span.h created+37
......@@ -0,0 +1,37 @@
1// -*- C++ -*-
2//===---------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===---------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_FWD_SPAN_H
11#define _LIBCPP_FWD_SPAN_H
12
13#include <__config>
14#include <cstddef>
15#include <limits>
16
17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18# pragma GCC system_header
19#endif
20
21_LIBCPP_PUSH_MACROS
22#include <__undef_macros>
23
24_LIBCPP_BEGIN_NAMESPACE_STD
25
26#if _LIBCPP_STD_VER > 17
27
28inline constexpr size_t dynamic_extent = numeric_limits<size_t>::max();
29template <typename _Tp, size_t _Extent = dynamic_extent> class span;
30
31#endif
32
33_LIBCPP_END_NAMESPACE_STD
34
35_LIBCPP_POP_MACROS
36
37#endif // _LIBCPP_FWD_SPAN_H
lib/libcxx/include/__fwd/string_view.h created+37
......@@ -0,0 +1,37 @@
1// -*- C++ -*-
2//===---------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===---------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_FWD_STRING_VIEW_H
11#define _LIBCPP_FWD_STRING_VIEW_H
12
13#include <__config>
14#include <iosfwd> // char_traits
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
20_LIBCPP_BEGIN_NAMESPACE_STD
21
22template<class _CharT, class _Traits = char_traits<_CharT> >
23class _LIBCPP_TEMPLATE_VIS basic_string_view;
24
25typedef basic_string_view<char> string_view;
26#ifndef _LIBCPP_HAS_NO_CHAR8_T
27typedef basic_string_view<char8_t> u8string_view;
28#endif
29typedef basic_string_view<char16_t> u16string_view;
30typedef basic_string_view<char32_t> u32string_view;
31#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
32typedef basic_string_view<wchar_t> wstring_view;
33#endif
34
35_LIBCPP_END_NAMESPACE_STD
36
37#endif // _LIBCPP_FWD_STRING_VIEW_H
lib/libcxx/include/__hash_table+87-176
......@@ -7,22 +7,26 @@
77//
88//===----------------------------------------------------------------------===//
99
10#ifndef _LIBCPP__HASH_TABLE
11#define _LIBCPP__HASH_TABLE
10#ifndef _LIBCPP___HASH_TABLE
11#define _LIBCPP___HASH_TABLE
1212
13#include <__algorithm/max.h>
14#include <__algorithm/min.h>
15#include <__assert>
1316#include <__bits> // __libcpp_clz
1417#include <__config>
1518#include <__debug>
16#include <algorithm>
19#include <__functional/hash.h>
20#include <__iterator/iterator_traits.h>
21#include <__memory/swap_allocator.h>
22#include <__utility/swap.h>
1723#include <cmath>
1824#include <initializer_list>
19#include <iterator>
2025#include <memory>
2126#include <type_traits>
22#include <utility>
2327
2428#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
25#pragma GCC system_header
29# pragma GCC system_header
2630#endif
2731
2832_LIBCPP_PUSH_MACROS
......@@ -44,7 +48,7 @@ template <class ..._Args>
4448struct __is_hash_value_type : false_type {};
4549
4650template <class _One>
47struct __is_hash_value_type<_One> : __is_hash_value_type_imp<typename __uncvref<_One>::type> {};
51struct __is_hash_value_type<_One> : __is_hash_value_type_imp<__uncvref_t<_One> > {};
4852
4953_LIBCPP_FUNC_VIS
5054size_t __next_prime(size_t __n);
......@@ -175,16 +179,14 @@ struct __hash_key_value_types<__hash_value_type<_Key, _Tp> > {
175179
176180 template <class _Up>
177181 _LIBCPP_INLINE_VISIBILITY
178 static typename enable_if<__is_same_uncvref<_Up, __node_value_type>::value,
179 __container_value_type const&>::type
182 static __enable_if_t<__is_same_uncvref<_Up, __node_value_type>::value, __container_value_type const&>
180183 __get_value(_Up& __t) {
181184 return __t.__get_value();
182185 }
183186
184187 template <class _Up>
185188 _LIBCPP_INLINE_VISIBILITY
186 static typename enable_if<__is_same_uncvref<_Up, __container_value_type>::value,
187 __container_value_type const&>::type
189 static __enable_if_t<__is_same_uncvref<_Up, __container_value_type>::value, __container_value_type const&>
188190 __get_value(_Up& __t) {
189191 return __t;
190192 }
......@@ -291,7 +293,7 @@ public:
291293 _VSTD::__debug_db_insert_i(this);
292294 }
293295
294#if _LIBCPP_DEBUG_LEVEL == 2
296#ifdef _LIBCPP_ENABLE_DEBUG_MODE
295297 _LIBCPP_INLINE_VISIBILITY
296298 __hash_iterator(const __hash_iterator& __i)
297299 : __node_(__i.__node_)
......@@ -315,7 +317,7 @@ public:
315317 }
316318 return *this;
317319 }
318#endif // _LIBCPP_DEBUG_LEVEL == 2
320#endif // _LIBCPP_ENABLE_DEBUG_MODE
319321
320322 _LIBCPP_INLINE_VISIBILITY
321323 reference operator*() const {
......@@ -357,19 +359,15 @@ public:
357359 {return !(__x == __y);}
358360
359361private:
360#if _LIBCPP_DEBUG_LEVEL == 2
361362 _LIBCPP_INLINE_VISIBILITY
362 __hash_iterator(__next_pointer __node, const void* __c) _NOEXCEPT
363 explicit __hash_iterator(__next_pointer __node, const void* __c) _NOEXCEPT
363364 : __node_(__node)
364365 {
366 (void)__c;
367#ifdef _LIBCPP_ENABLE_DEBUG_MODE
365368 __get_db()->__insert_ic(this, __c);
366 }
367#else
368 _LIBCPP_INLINE_VISIBILITY
369 __hash_iterator(__next_pointer __node) _NOEXCEPT
370 : __node_(__node)
371 {}
372369#endif
370 }
373371 template <class, class, class, class> friend class __hash_table;
374372 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator;
375373 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_iterator;
......@@ -405,12 +403,12 @@ public:
405403 __hash_const_iterator(const __non_const_iterator& __x) _NOEXCEPT
406404 : __node_(__x.__node_)
407405 {
408#if _LIBCPP_DEBUG_LEVEL == 2
406#ifdef _LIBCPP_ENABLE_DEBUG_MODE
409407 __get_db()->__iterator_copy(this, _VSTD::addressof(__x));
410408#endif
411409 }
412410
413#if _LIBCPP_DEBUG_LEVEL == 2
411#ifdef _LIBCPP_ENABLE_DEBUG_MODE
414412 _LIBCPP_INLINE_VISIBILITY
415413 __hash_const_iterator(const __hash_const_iterator& __i)
416414 : __node_(__i.__node_)
......@@ -434,7 +432,7 @@ public:
434432 }
435433 return *this;
436434 }
437#endif // _LIBCPP_DEBUG_LEVEL == 2
435#endif // _LIBCPP_ENABLE_DEBUG_MODE
438436
439437 _LIBCPP_INLINE_VISIBILITY
440438 reference operator*() const {
......@@ -475,19 +473,15 @@ public:
475473 {return !(__x == __y);}
476474
477475private:
478#if _LIBCPP_DEBUG_LEVEL == 2
479476 _LIBCPP_INLINE_VISIBILITY
480 __hash_const_iterator(__next_pointer __node, const void* __c) _NOEXCEPT
477 explicit __hash_const_iterator(__next_pointer __node, const void* __c) _NOEXCEPT
481478 : __node_(__node)
482479 {
480 (void)__c;
481#ifdef _LIBCPP_ENABLE_DEBUG_MODE
483482 __get_db()->__insert_ic(this, __c);
484 }
485#else
486 _LIBCPP_INLINE_VISIBILITY
487 __hash_const_iterator(__next_pointer __node) _NOEXCEPT
488 : __node_(__node)
489 {}
490483#endif
484 }
491485 template <class, class, class, class> friend class __hash_table;
492486 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator;
493487 template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map;
......@@ -516,7 +510,7 @@ public:
516510 _VSTD::__debug_db_insert_i(this);
517511 }
518512
519#if _LIBCPP_DEBUG_LEVEL == 2
513#ifdef _LIBCPP_ENABLE_DEBUG_MODE
520514 _LIBCPP_INLINE_VISIBILITY
521515 __hash_local_iterator(const __hash_local_iterator& __i)
522516 : __node_(__i.__node_),
......@@ -544,7 +538,7 @@ public:
544538 }
545539 return *this;
546540 }
547#endif // _LIBCPP_DEBUG_LEVEL == 2
541#endif // _LIBCPP_ENABLE_DEBUG_MODE
548542
549543 _LIBCPP_INLINE_VISIBILITY
550544 reference operator*() const {
......@@ -588,30 +582,20 @@ public:
588582 {return !(__x == __y);}
589583
590584private:
591#if _LIBCPP_DEBUG_LEVEL == 2
592585 _LIBCPP_INLINE_VISIBILITY
593 __hash_local_iterator(__next_pointer __node, size_t __bucket,
594 size_t __bucket_count, const void* __c) _NOEXCEPT
586 explicit __hash_local_iterator(__next_pointer __node, size_t __bucket,
587 size_t __bucket_count, const void* __c) _NOEXCEPT
595588 : __node_(__node),
596589 __bucket_(__bucket),
597590 __bucket_count_(__bucket_count)
598591 {
592 (void)__c;
593#ifdef _LIBCPP_ENABLE_DEBUG_MODE
599594 __get_db()->__insert_ic(this, __c);
595#endif
600596 if (__node_ != nullptr)
601597 __node_ = __node_->__next_;
602598 }
603#else
604 _LIBCPP_INLINE_VISIBILITY
605 __hash_local_iterator(__next_pointer __node, size_t __bucket,
606 size_t __bucket_count) _NOEXCEPT
607 : __node_(__node),
608 __bucket_(__bucket),
609 __bucket_count_(__bucket_count)
610 {
611 if (__node_ != nullptr)
612 __node_ = __node_->__next_;
613 }
614#endif
615599 template <class, class, class, class> friend class __hash_table;
616600 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator;
617601 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_iterator;
......@@ -654,12 +638,12 @@ public:
654638 __bucket_(__x.__bucket_),
655639 __bucket_count_(__x.__bucket_count_)
656640 {
657#if _LIBCPP_DEBUG_LEVEL == 2
641#ifdef _LIBCPP_ENABLE_DEBUG_MODE
658642 __get_db()->__iterator_copy(this, _VSTD::addressof(__x));
659643#endif
660644 }
661645
662#if _LIBCPP_DEBUG_LEVEL == 2
646#ifdef _LIBCPP_ENABLE_DEBUG_MODE
663647 _LIBCPP_INLINE_VISIBILITY
664648 __hash_const_local_iterator(const __hash_const_local_iterator& __i)
665649 : __node_(__i.__node_),
......@@ -687,7 +671,7 @@ public:
687671 }
688672 return *this;
689673 }
690#endif // _LIBCPP_DEBUG_LEVEL == 2
674#endif // _LIBCPP_ENABLE_DEBUG_MODE
691675
692676 _LIBCPP_INLINE_VISIBILITY
693677 reference operator*() const {
......@@ -731,30 +715,20 @@ public:
731715 {return !(__x == __y);}
732716
733717private:
734#if _LIBCPP_DEBUG_LEVEL == 2
735718 _LIBCPP_INLINE_VISIBILITY
736 __hash_const_local_iterator(__next_pointer __node_ptr, size_t __bucket,
737 size_t __bucket_count, const void* __c) _NOEXCEPT
719 explicit __hash_const_local_iterator(__next_pointer __node_ptr, size_t __bucket,
720 size_t __bucket_count, const void* __c) _NOEXCEPT
738721 : __node_(__node_ptr),
739722 __bucket_(__bucket),
740723 __bucket_count_(__bucket_count)
741724 {
725 (void)__c;
726#ifdef _LIBCPP_ENABLE_DEBUG_MODE
742727 __get_db()->__insert_ic(this, __c);
728#endif
743729 if (__node_ != nullptr)
744730 __node_ = __node_->__next_;
745731 }
746#else
747 _LIBCPP_INLINE_VISIBILITY
748 __hash_const_local_iterator(__next_pointer __node_ptr, size_t __bucket,
749 size_t __bucket_count) _NOEXCEPT
750 : __node_(__node_ptr),
751 __bucket_(__bucket),
752 __bucket_count_(__bucket_count)
753 {
754 if (__node_ != nullptr)
755 __node_ = __node_->__next_;
756 }
757#endif
758732 template <class, class, class, class> friend class __hash_table;
759733 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator;
760734};
......@@ -1074,10 +1048,8 @@ public:
10741048
10751049 template <class _First, class _Second>
10761050 _LIBCPP_INLINE_VISIBILITY
1077 typename enable_if<
1078 __can_extract_map_key<_First, key_type, __container_value_type>::value,
1079 pair<iterator, bool>
1080 >::type __emplace_unique(_First&& __f, _Second&& __s) {
1051 __enable_if_t<__can_extract_map_key<_First, key_type, __container_value_type>::value, pair<iterator, bool> >
1052 __emplace_unique(_First&& __f, _Second&& __s) {
10811053 return __emplace_unique_key_args(__f, _VSTD::forward<_First>(__f),
10821054 _VSTD::forward<_Second>(__s));
10831055 }
......@@ -1121,9 +1093,7 @@ public:
11211093 return __emplace_unique_key_args(_NodeTypes::__get_key(__x), _VSTD::move(__x));
11221094 }
11231095
1124 template <class _Pp, class = typename enable_if<
1125 !__is_same_uncvref<_Pp, __container_value_type>::value
1126 >::type>
1096 template <class _Pp, class = __enable_if_t<!__is_same_uncvref<_Pp, __container_value_type>::value> >
11271097 _LIBCPP_INLINE_VISIBILITY
11281098 pair<iterator, bool> __insert_unique(_Pp&& __x) {
11291099 return __emplace_unique(_VSTD::forward<_Pp>(__x));
......@@ -1177,9 +1147,16 @@ public:
11771147#endif
11781148
11791149 void clear() _NOEXCEPT;
1180 void rehash(size_type __n);
1181 _LIBCPP_INLINE_VISIBILITY void reserve(size_type __n)
1182 {rehash(static_cast<size_type>(ceil(__n / max_load_factor())));}
1150 _LIBCPP_INLINE_VISIBILITY void __rehash_unique(size_type __n) { __rehash<true>(__n); }
1151 _LIBCPP_INLINE_VISIBILITY void __rehash_multi(size_type __n) { __rehash<false>(__n); }
1152 _LIBCPP_INLINE_VISIBILITY void __reserve_unique(size_type __n)
1153 {
1154 __rehash_unique(static_cast<size_type>(ceil(__n / max_load_factor())));
1155 }
1156 _LIBCPP_INLINE_VISIBILITY void __reserve_multi(size_type __n)
1157 {
1158 __rehash_multi(static_cast<size_type>(ceil(__n / max_load_factor())));
1159 }
11831160
11841161 _LIBCPP_INLINE_VISIBILITY
11851162 size_type bucket_count() const _NOEXCEPT
......@@ -1276,11 +1253,7 @@ public:
12761253 {
12771254 _LIBCPP_ASSERT(__n < bucket_count(),
12781255 "unordered container::begin(n) called with n >= bucket_count()");
1279#if _LIBCPP_DEBUG_LEVEL == 2
12801256 return local_iterator(__bucket_list_[__n], __n, bucket_count(), this);
1281#else
1282 return local_iterator(__bucket_list_[__n], __n, bucket_count());
1283#endif
12841257 }
12851258
12861259 _LIBCPP_INLINE_VISIBILITY
......@@ -1289,11 +1262,7 @@ public:
12891262 {
12901263 _LIBCPP_ASSERT(__n < bucket_count(),
12911264 "unordered container::end(n) called with n >= bucket_count()");
1292#if _LIBCPP_DEBUG_LEVEL == 2
12931265 return local_iterator(nullptr, __n, bucket_count(), this);
1294#else
1295 return local_iterator(nullptr, __n, bucket_count());
1296#endif
12971266 }
12981267
12991268 _LIBCPP_INLINE_VISIBILITY
......@@ -1302,11 +1271,7 @@ public:
13021271 {
13031272 _LIBCPP_ASSERT(__n < bucket_count(),
13041273 "unordered container::cbegin(n) called with n >= bucket_count()");
1305#if _LIBCPP_DEBUG_LEVEL == 2
13061274 return const_local_iterator(__bucket_list_[__n], __n, bucket_count(), this);
1307#else
1308 return const_local_iterator(__bucket_list_[__n], __n, bucket_count());
1309#endif
13101275 }
13111276
13121277 _LIBCPP_INLINE_VISIBILITY
......@@ -1315,24 +1280,21 @@ public:
13151280 {
13161281 _LIBCPP_ASSERT(__n < bucket_count(),
13171282 "unordered container::cend(n) called with n >= bucket_count()");
1318#if _LIBCPP_DEBUG_LEVEL == 2
13191283 return const_local_iterator(nullptr, __n, bucket_count(), this);
1320#else
1321 return const_local_iterator(nullptr, __n, bucket_count());
1322#endif
13231284 }
13241285
1325#if _LIBCPP_DEBUG_LEVEL == 2
1286#ifdef _LIBCPP_ENABLE_DEBUG_MODE
13261287
13271288 bool __dereferenceable(const const_iterator* __i) const;
13281289 bool __decrementable(const const_iterator* __i) const;
13291290 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
13301291 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
13311292
1332#endif // _LIBCPP_DEBUG_LEVEL == 2
1293#endif // _LIBCPP_ENABLE_DEBUG_MODE
13331294
13341295private:
1335 void __rehash(size_type __n);
1296 template <bool _UniqueKeys> void __rehash(size_type __n);
1297 template <bool _UniqueKeys> void __do_rehash(size_type __n);
13361298
13371299 template <class ..._Args>
13381300 __node_holder __construct_node(_Args&& ...__args);
......@@ -1509,9 +1471,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::~__hash_table()
15091471#endif
15101472
15111473 __deallocate_node(__p1_.first().__next_);
1512#if _LIBCPP_DEBUG_LEVEL == 2
1513 __get_db()->__erase_c(this);
1514#endif
1474 std::__debug_db_erase_c(this);
15151475}
15161476
15171477template <class _Tp, class _Hash, class _Equal, class _Alloc>
......@@ -1553,7 +1513,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__deallocate_node(__next_pointer __np)
15531513 while (__np != nullptr)
15541514 {
15551515 __next_pointer __next = __np->__next_;
1556#if _LIBCPP_DEBUG_LEVEL == 2
1516#ifdef _LIBCPP_ENABLE_DEBUG_MODE
15571517 __c_node* __c = __get_db()->__find_c_and_lock(this);
15581518 for (__i_node** __p = __c->end_; __p != __c->beg_; )
15591519 {
......@@ -1614,9 +1574,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign(
16141574 __u.__p1_.first().__next_ = nullptr;
16151575 __u.size() = 0;
16161576 }
1617#if _LIBCPP_DEBUG_LEVEL == 2
1618 __get_db()->swap(this, _VSTD::addressof(__u));
1619#endif
1577 std::__debug_db_swap(this, std::addressof(__u));
16201578}
16211579
16221580template <class _Tp, class _Hash, class _Equal, class _Alloc>
......@@ -1766,11 +1724,7 @@ inline
17661724typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
17671725__hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() _NOEXCEPT
17681726{
1769#if _LIBCPP_DEBUG_LEVEL == 2
17701727 return iterator(__p1_.first().__next_, this);
1771#else
1772 return iterator(__p1_.first().__next_);
1773#endif
17741728}
17751729
17761730template <class _Tp, class _Hash, class _Equal, class _Alloc>
......@@ -1778,11 +1732,7 @@ inline
17781732typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
17791733__hash_table<_Tp, _Hash, _Equal, _Alloc>::end() _NOEXCEPT
17801734{
1781#if _LIBCPP_DEBUG_LEVEL == 2
17821735 return iterator(nullptr, this);
1783#else
1784 return iterator(nullptr);
1785#endif
17861736}
17871737
17881738template <class _Tp, class _Hash, class _Equal, class _Alloc>
......@@ -1790,11 +1740,7 @@ inline
17901740typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator
17911741__hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() const _NOEXCEPT
17921742{
1793#if _LIBCPP_DEBUG_LEVEL == 2
17941743 return const_iterator(__p1_.first().__next_, this);
1795#else
1796 return const_iterator(__p1_.first().__next_);
1797#endif
17981744}
17991745
18001746template <class _Tp, class _Hash, class _Equal, class _Alloc>
......@@ -1802,11 +1748,7 @@ inline
18021748typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator
18031749__hash_table<_Tp, _Hash, _Equal, _Alloc>::end() const _NOEXCEPT
18041750{
1805#if _LIBCPP_DEBUG_LEVEL == 2
18061751 return const_iterator(nullptr, this);
1807#else
1808 return const_iterator(nullptr);
1809#endif
18101752}
18111753
18121754template <class _Tp, class _Hash, class _Equal, class _Alloc>
......@@ -1857,7 +1799,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique_prepare(
18571799 }
18581800 if (size()+1 > __bc * max_load_factor() || __bc == 0)
18591801 {
1860 rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc),
1802 __rehash_unique(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc),
18611803 size_type(ceil(float(size() + 1) / max_load_factor()))));
18621804 }
18631805 return nullptr;
......@@ -1911,11 +1853,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique(__node_pointer __
19111853 __existing_node = __nd->__ptr();
19121854 __inserted = true;
19131855 }
1914#if _LIBCPP_DEBUG_LEVEL == 2
19151856 return pair<iterator, bool>(iterator(__existing_node, this), __inserted);
1916#else
1917 return pair<iterator, bool>(iterator(__existing_node), __inserted);
1918#endif
19191857}
19201858
19211859// Prepare the container for an insertion of the value __cp_val with the hash
......@@ -1933,7 +1871,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi_prepare(
19331871 size_type __bc = bucket_count();
19341872 if (size()+1 > __bc * max_load_factor() || __bc == 0)
19351873 {
1936 rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc),
1874 __rehash_multi(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc),
19371875 size_type(ceil(float(size() + 1) / max_load_factor()))));
19381876 __bc = bucket_count();
19391877 }
......@@ -2009,11 +1947,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(__node_pointer __c
20091947 __next_pointer __pn = __node_insert_multi_prepare(__cp->__hash(), __cp->__value_);
20101948 __node_insert_multi_perform(__cp, __pn);
20111949
2012#if _LIBCPP_DEBUG_LEVEL == 2
20131950 return iterator(__cp->__ptr(), this);
2014#else
2015 return iterator(__cp->__ptr());
2016#endif
20171951}
20181952
20191953template <class _Tp, class _Hash, class _Equal, class _Alloc>
......@@ -2031,7 +1965,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(
20311965 size_type __bc = bucket_count();
20321966 if (size()+1 > __bc * max_load_factor() || __bc == 0)
20331967 {
2034 rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc),
1968 __rehash_multi(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc),
20351969 size_type(ceil(float(size() + 1) / max_load_factor()))));
20361970 __bc = bucket_count();
20371971 }
......@@ -2042,11 +1976,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(
20421976 __cp->__next_ = __np;
20431977 __pp->__next_ = static_cast<__next_pointer>(__cp);
20441978 ++size();
2045#if _LIBCPP_DEBUG_LEVEL == 2
20461979 return iterator(static_cast<__next_pointer>(__cp), this);
2047#else
2048 return iterator(static_cast<__next_pointer>(__cp));
2049#endif
20501980 }
20511981 return __node_insert_multi(__cp);
20521982}
......@@ -2083,7 +2013,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const&
20832013 __node_holder __h = __construct_node_hash(__hash, _VSTD::forward<_Args>(__args)...);
20842014 if (size()+1 > __bc * max_load_factor() || __bc == 0)
20852015 {
2086 rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc),
2016 __rehash_unique(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc),
20872017 size_type(ceil(float(size() + 1) / max_load_factor()))));
20882018 __bc = bucket_count();
20892019 __chash = __constrain_hash(__hash, __bc);
......@@ -2112,11 +2042,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const&
21122042 __inserted = true;
21132043 }
21142044__done:
2115#if _LIBCPP_DEBUG_LEVEL == 2
21162045 return pair<iterator, bool>(iterator(__nd, this), __inserted);
2117#else
2118 return pair<iterator, bool>(iterator(__nd), __inserted);
2119#endif
21202046}
21212047
21222048template <class _Tp, class _Hash, class _Equal, class _Alloc>
......@@ -2290,8 +2216,9 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_merge_multi(
22902216#endif // _LIBCPP_STD_VER > 14
22912217
22922218template <class _Tp, class _Hash, class _Equal, class _Alloc>
2219template <bool _UniqueKeys>
22932220void
2294__hash_table<_Tp, _Hash, _Equal, _Alloc>::rehash(size_type __n)
2221__hash_table<_Tp, _Hash, _Equal, _Alloc>::__rehash(size_type __n)
22952222_LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
22962223{
22972224 if (__n == 1)
......@@ -2300,7 +2227,7 @@ _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
23002227 __n = __next_prime(__n);
23012228 size_type __bc = bucket_count();
23022229 if (__n > __bc)
2303 __rehash(__n);
2230 __do_rehash<_UniqueKeys>(__n);
23042231 else if (__n < __bc)
23052232 {
23062233 __n = _VSTD::max<size_type>
......@@ -2310,17 +2237,16 @@ _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
23102237 __next_prime(size_t(ceil(float(size()) / max_load_factor())))
23112238 );
23122239 if (__n < __bc)
2313 __rehash(__n);
2240 __do_rehash<_UniqueKeys>(__n);
23142241 }
23152242}
23162243
23172244template <class _Tp, class _Hash, class _Equal, class _Alloc>
2245template <bool _UniqueKeys>
23182246void
2319__hash_table<_Tp, _Hash, _Equal, _Alloc>::__rehash(size_type __nbc)
2247__hash_table<_Tp, _Hash, _Equal, _Alloc>::__do_rehash(size_type __nbc)
23202248{
2321#if _LIBCPP_DEBUG_LEVEL == 2
2322 __get_db()->__invalidate_all(this);
2323#endif
2249 std::__debug_db_invalidate_all(this);
23242250 __pointer_allocator& __npa = __bucket_list_.get_deleter().__alloc();
23252251 __bucket_list_.reset(__nbc > 0 ?
23262252 __pointer_alloc_traits::allocate(__npa, __nbc) : nullptr);
......@@ -2353,11 +2279,14 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__rehash(size_type __nbc)
23532279 else
23542280 {
23552281 __next_pointer __np = __cp;
2356 for (; __np->__next_ != nullptr &&
2357 key_eq()(__cp->__upcast()->__value_,
2358 __np->__next_->__upcast()->__value_);
2359 __np = __np->__next_)
2360 ;
2282 if _LIBCPP_CONSTEXPR_AFTER_CXX14 (!_UniqueKeys)
2283 {
2284 for (; __np->__next_ != nullptr &&
2285 key_eq()(__cp->__upcast()->__value_,
2286 __np->__next_->__upcast()->__value_);
2287 __np = __np->__next_)
2288 ;
2289 }
23612290 __pp->__next_ = __np->__next_;
23622291 __np->__next_ = __bucket_list_[__chash]->__next_;
23632292 __bucket_list_[__chash]->__next_ = __cp;
......@@ -2389,11 +2318,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k)
23892318 {
23902319 if ((__nd->__hash() == __hash)
23912320 && key_eq()(__nd->__upcast()->__value_, __k))
2392#if _LIBCPP_DEBUG_LEVEL == 2
23932321 return iterator(__nd, this);
2394#else
2395 return iterator(__nd);
2396#endif
23972322 }
23982323 }
23992324 }
......@@ -2420,11 +2345,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k) const
24202345 {
24212346 if ((__nd->__hash() == __hash)
24222347 && key_eq()(__nd->__upcast()->__value_, __k))
2423#if _LIBCPP_DEBUG_LEVEL == 2
24242348 return const_iterator(__nd, this);
2425#else
2426 return const_iterator(__nd);
2427#endif
24282349 }
24292350 }
24302351
......@@ -2475,13 +2396,9 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __p)
24752396 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
24762397 "unordered container erase(iterator) called with an iterator not"
24772398 " referring to this container");
2478 _LIBCPP_DEBUG_ASSERT(__p != end(),
2479 "unordered container erase(iterator) called with a non-dereferenceable iterator");
2480#if _LIBCPP_DEBUG_LEVEL == 2
2399 _LIBCPP_ASSERT(__p != end(),
2400 "unordered container erase(iterator) called with a non-dereferenceable iterator");
24812401 iterator __r(__np, this);
2482#else
2483 iterator __r(__np);
2484#endif
24852402 ++__r;
24862403 remove(__p);
24872404 return __r;
......@@ -2504,11 +2421,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __first,
25042421 erase(__p);
25052422 }
25062423 __next_pointer __np = __last.__node_;
2507#if _LIBCPP_DEBUG_LEVEL == 2
25082424 return iterator (__np, this);
2509#else
2510 return iterator (__np);
2511#endif
25122425}
25132426
25142427template <class _Tp, class _Hash, class _Equal, class _Alloc>
......@@ -2575,7 +2488,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::remove(const_iterator __p) _NOEXCEPT
25752488 __pn->__next_ = __cn->__next_;
25762489 __cn->__next_ = nullptr;
25772490 --size();
2578#if _LIBCPP_DEBUG_LEVEL == 2
2491#ifdef _LIBCPP_ENABLE_DEBUG_MODE
25792492 __c_node* __c = __get_db()->__find_c_and_lock(this);
25802493 for (__i_node** __dp = __c->end_; __dp != __c->beg_; )
25812494 {
......@@ -2726,9 +2639,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::swap(__hash_table& __u)
27262639 if (__u.size() > 0)
27272640 __u.__bucket_list_[__constrain_hash(__u.__p1_.first().__next_->__hash(), __u.bucket_count())] =
27282641 __u.__p1_.first().__ptr();
2729#if _LIBCPP_DEBUG_LEVEL == 2
2730 __get_db()->swap(this, _VSTD::addressof(__u));
2731#endif
2642 std::__debug_db_swap(this, std::addressof(__u));
27322643}
27332644
27342645template <class _Tp, class _Hash, class _Equal, class _Alloc>
......@@ -2760,7 +2671,7 @@ swap(__hash_table<_Tp, _Hash, _Equal, _Alloc>& __x,
27602671 __x.swap(__y);
27612672}
27622673
2763#if _LIBCPP_DEBUG_LEVEL == 2
2674#ifdef _LIBCPP_ENABLE_DEBUG_MODE
27642675
27652676template <class _Tp, class _Hash, class _Equal, class _Alloc>
27662677bool
......@@ -2790,10 +2701,10 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__subscriptable(const const_iterator*,
27902701 return false;
27912702}
27922703
2793#endif // _LIBCPP_DEBUG_LEVEL == 2
2704#endif // _LIBCPP_ENABLE_DEBUG_MODE
27942705
27952706_LIBCPP_END_NAMESPACE_STD
27962707
27972708_LIBCPP_POP_MACROS
27982709
2799#endif // _LIBCPP__HASH_TABLE
2710#endif // _LIBCPP___HASH_TABLE
lib/libcxx/include/__ios/fpos.h created+79
......@@ -0,0 +1,79 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___IOS_FPOS_H
11#define _LIBCPP___IOS_FPOS_H
12
13#include <__config>
14#include <iosfwd>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
20_LIBCPP_BEGIN_NAMESPACE_STD
21
22template <class _StateT>
23class _LIBCPP_TEMPLATE_VIS fpos {
24private:
25 _StateT __st_;
26 streamoff __off_;
27
28public:
29 _LIBCPP_HIDE_FROM_ABI fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {}
30
31 _LIBCPP_HIDE_FROM_ABI operator streamoff() const { return __off_; }
32
33 _LIBCPP_HIDE_FROM_ABI _StateT state() const { return __st_; }
34 _LIBCPP_HIDE_FROM_ABI void state(_StateT __st) { __st_ = __st; }
35
36 _LIBCPP_HIDE_FROM_ABI fpos& operator+=(streamoff __off) {
37 __off_ += __off;
38 return *this;
39 }
40
41 _LIBCPP_HIDE_FROM_ABI fpos operator+(streamoff __off) const {
42 fpos __t(*this);
43 __t += __off;
44 return __t;
45 }
46
47 _LIBCPP_HIDE_FROM_ABI fpos& operator-=(streamoff __off) {
48 __off_ -= __off;
49 return *this;
50 }
51
52 _LIBCPP_HIDE_FROM_ABI fpos operator-(streamoff __off) const {
53 fpos __t(*this);
54 __t -= __off;
55 return __t;
56 }
57};
58
59template <class _StateT>
60inline _LIBCPP_HIDE_FROM_ABI
61streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y) {
62 return streamoff(__x) - streamoff(__y);
63}
64
65template <class _StateT>
66inline _LIBCPP_HIDE_FROM_ABI
67bool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y) {
68 return streamoff(__x) == streamoff(__y);
69}
70
71template <class _StateT>
72inline _LIBCPP_HIDE_FROM_ABI
73bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y) {
74 return streamoff(__x) != streamoff(__y);
75}
76
77_LIBCPP_END_NAMESPACE_STD
78
79#endif // _LIBCPP___IOS_FPOS_H
lib/libcxx/include/__iterator/access.h+1-1
......@@ -14,7 +14,7 @@
1414#include <cstddef>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
17# pragma GCC system_header
1818#endif
1919
2020_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__iterator/advance.h+27-27
......@@ -10,19 +10,20 @@
1010#ifndef _LIBCPP___ITERATOR_ADVANCE_H
1111#define _LIBCPP___ITERATOR_ADVANCE_H
1212
13#include <__assert>
1314#include <__config>
14#include <__debug>
1515#include <__iterator/concepts.h>
1616#include <__iterator/incrementable_traits.h>
1717#include <__iterator/iterator_traits.h>
1818#include <__utility/move.h>
19#include <__utility/unreachable.h>
1920#include <concepts>
2021#include <cstdlib>
2122#include <limits>
2223#include <type_traits>
2324
2425#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
25#pragma GCC system_header
26# pragma GCC system_header
2627#endif
2728
2829_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -64,7 +65,7 @@ void advance(_InputIter& __i, _Distance __orig_n) {
6465 _VSTD::__advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
6566}
6667
67#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
68#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
6869
6970// [range.iter.op.advance]
7071
......@@ -116,47 +117,46 @@ public:
116117 }
117118 }
118119
119 // Preconditions: Either `assignable_from<I&, S> || sized_sentinel_for<S, I>` is modeled, or [i, bound) denotes a range.
120 // Preconditions: Either `assignable_from<I&, S> || sized_sentinel_for<S, I>` is modeled, or [i, bound_sentinel) denotes a range.
120121 template <input_or_output_iterator _Ip, sentinel_for<_Ip> _Sp>
121 _LIBCPP_HIDE_FROM_ABI
122 constexpr void operator()(_Ip& __i, _Sp __bound) const {
123 // If `I` and `S` model `assignable_from<I&, S>`, equivalent to `i = std::move(bound)`.
122 _LIBCPP_HIDE_FROM_ABI constexpr void operator()(_Ip& __i, _Sp __bound_sentinel) const {
123 // If `I` and `S` model `assignable_from<I&, S>`, equivalent to `i = std::move(bound_sentinel)`.
124124 if constexpr (assignable_from<_Ip&, _Sp>) {
125 __i = _VSTD::move(__bound);
125 __i = _VSTD::move(__bound_sentinel);
126126 }
127 // Otherwise, if `S` and `I` model `sized_sentinel_for<S, I>`, equivalent to `ranges::advance(i, bound - i)`.
127 // Otherwise, if `S` and `I` model `sized_sentinel_for<S, I>`, equivalent to `ranges::advance(i, bound_sentinel - i)`.
128128 else if constexpr (sized_sentinel_for<_Sp, _Ip>) {
129 (*this)(__i, __bound - __i);
129 (*this)(__i, __bound_sentinel - __i);
130130 }
131 // Otherwise, while `bool(i != bound)` is true, increments `i`.
131 // Otherwise, while `bool(i != bound_sentinel)` is true, increments `i`.
132132 else {
133 while (__i != __bound) {
133 while (__i != __bound_sentinel) {
134134 ++__i;
135135 }
136136 }
137137 }
138138
139139 // Preconditions:
140 // * If `n > 0`, [i, bound) denotes a range.
141 // * If `n == 0`, [i, bound) or [bound, i) denotes a range.
142 // * If `n < 0`, [bound, i) denotes a range, `I` models `bidirectional_iterator`, and `I` and `S` model `same_as<I, S>`.
143 // Returns: `n - M`, where `M` is the difference between the the ending and starting position.
140 // * If `n > 0`, [i, bound_sentinel) denotes a range.
141 // * If `n == 0`, [i, bound_sentinel) or [bound_sentinel, i) denotes a range.
142 // * If `n < 0`, [bound_sentinel, i) denotes a range, `I` models `bidirectional_iterator`, and `I` and `S` model `same_as<I, S>`.
143 // Returns: `n - M`, where `M` is the difference between the ending and starting position.
144144 template <input_or_output_iterator _Ip, sentinel_for<_Ip> _Sp>
145 _LIBCPP_HIDE_FROM_ABI
146 constexpr iter_difference_t<_Ip> operator()(_Ip& __i, iter_difference_t<_Ip> __n, _Sp __bound) const {
145 _LIBCPP_HIDE_FROM_ABI constexpr iter_difference_t<_Ip> operator()(_Ip& __i, iter_difference_t<_Ip> __n,
146 _Sp __bound_sentinel) const {
147147 _LIBCPP_ASSERT((__n >= 0) || (bidirectional_iterator<_Ip> && same_as<_Ip, _Sp>),
148148 "If `n < 0`, then `bidirectional_iterator<I> && same_as<I, S>` must be true.");
149149 // If `S` and `I` model `sized_sentinel_for<S, I>`:
150150 if constexpr (sized_sentinel_for<_Sp, _Ip>) {
151 // If |n| >= |bound - i|, equivalent to `ranges::advance(i, bound)`.
151 // If |n| >= |bound_sentinel - i|, equivalent to `ranges::advance(i, bound_sentinel)`.
152152 // __magnitude_geq(a, b) returns |a| >= |b|, assuming they have the same sign.
153153 auto __magnitude_geq = [](auto __a, auto __b) {
154154 return __a == 0 ? __b == 0 :
155155 __a > 0 ? __a >= __b :
156156 __a <= __b;
157157 };
158 if (const auto __M = __bound - __i; __magnitude_geq(__n, __M)) {
159 (*this)(__i, __bound);
158 if (const auto __M = __bound_sentinel - __i; __magnitude_geq(__n, __M)) {
159 (*this)(__i, __bound_sentinel);
160160 return __n - __M;
161161 }
162162
......@@ -164,16 +164,16 @@ public:
164164 (*this)(__i, __n);
165165 return 0;
166166 } else {
167 // Otherwise, if `n` is non-negative, while `bool(i != bound)` is true, increments `i` but at
167 // Otherwise, if `n` is non-negative, while `bool(i != bound_sentinel)` is true, increments `i` but at
168168 // most `n` times.
169 while (__i != __bound && __n > 0) {
169 while (__i != __bound_sentinel && __n > 0) {
170170 ++__i;
171171 --__n;
172172 }
173173
174 // Otherwise, while `bool(i != bound)` is true, decrements `i` but at most `-n` times.
174 // Otherwise, while `bool(i != bound_sentinel)` is true, decrements `i` but at most `-n` times.
175175 if constexpr (bidirectional_iterator<_Ip> && same_as<_Ip, _Sp>) {
176 while (__i != __bound && __n < 0) {
176 while (__i != __bound_sentinel && __n < 0) {
177177 --__i;
178178 ++__n;
179179 }
......@@ -181,7 +181,7 @@ public:
181181 return __n;
182182 }
183183
184 _LIBCPP_UNREACHABLE();
184 __libcpp_unreachable();
185185 }
186186};
187187
......@@ -192,7 +192,7 @@ inline namespace __cpo {
192192} // namespace __cpo
193193} // namespace ranges
194194
195#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
195#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
196196
197197_LIBCPP_END_NAMESPACE_STD
198198
lib/libcxx/include/__iterator/back_insert_iterator.h+7-5
......@@ -18,7 +18,7 @@
1818#include <cstddef>
1919
2020#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21#pragma GCC system_header
21# pragma GCC system_header
2222#endif
2323
2424_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -46,15 +46,17 @@ public:
4646 typedef _Container container_type;
4747
4848 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
49 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(const typename _Container::value_type& __value_)
50 {container->push_back(__value_); return *this;}
49 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(const typename _Container::value_type& __value)
50 {container->push_back(__value); return *this;}
5151#ifndef _LIBCPP_CXX03_LANG
52 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(typename _Container::value_type&& __value_)
53 {container->push_back(_VSTD::move(__value_)); return *this;}
52 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(typename _Container::value_type&& __value)
53 {container->push_back(_VSTD::move(__value)); return *this;}
5454#endif // _LIBCPP_CXX03_LANG
5555 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator*() {return *this;}
5656 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator++() {return *this;}
5757 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator operator++(int) {return *this;}
58
59 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _Container* __get_container() const { return container; }
5860};
5961
6062template <class _Container>
lib/libcxx/include/__iterator/bounded_iter.h created+229
......@@ -0,0 +1,229 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___ITERATOR_BOUNDED_ITER_H
11#define _LIBCPP___ITERATOR_BOUNDED_ITER_H
12
13#include <__assert>
14#include <__config>
15#include <__iterator/iterator_traits.h>
16#include <__memory/pointer_traits.h>
17#include <__utility/move.h>
18#include <type_traits>
19
20#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21# pragma GCC system_header
22#endif
23
24_LIBCPP_BEGIN_NAMESPACE_STD
25
26// Iterator wrapper that carries the valid range it is allowed to access.
27//
28// This is a simple iterator wrapper for contiguous iterators that points
29// within a [begin, end) range and carries these bounds with it. The iterator
30// ensures that it is pointing within that [begin, end) range when it is
31// dereferenced.
32//
33// Arithmetic operations are allowed and the bounds of the resulting iterator
34// are not checked. Hence, it is possible to create an iterator pointing outside
35// its range, but it is not possible to dereference it.
36template <class _Iterator, class = __enable_if_t< __is_cpp17_contiguous_iterator<_Iterator>::value > >
37struct __bounded_iter {
38 using value_type = typename iterator_traits<_Iterator>::value_type;
39 using difference_type = typename iterator_traits<_Iterator>::difference_type;
40 using pointer = typename iterator_traits<_Iterator>::pointer;
41 using reference = typename iterator_traits<_Iterator>::reference;
42 using iterator_category = typename iterator_traits<_Iterator>::iterator_category;
43#if _LIBCPP_STD_VER > 17
44 using iterator_concept = contiguous_iterator_tag;
45#endif
46
47 // Create a singular iterator.
48 //
49 // Such an iterator does not point to any object and is conceptually out of bounds, so it is
50 // not dereferenceable. Observing operations like comparison and assignment are valid.
51 _LIBCPP_HIDE_FROM_ABI __bounded_iter() = default;
52
53 _LIBCPP_HIDE_FROM_ABI __bounded_iter(__bounded_iter const&) = default;
54 _LIBCPP_HIDE_FROM_ABI __bounded_iter(__bounded_iter&&) = default;
55
56 template <class _OtherIterator, class = __enable_if_t< is_convertible<_OtherIterator, _Iterator>::value > >
57 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __bounded_iter(__bounded_iter<_OtherIterator> const& __other) _NOEXCEPT
58 : __current_(__other.__current_),
59 __begin_(__other.__begin_),
60 __end_(__other.__end_) {}
61
62 // Assign a bounded iterator to another one, rebinding the bounds of the iterator as well.
63 _LIBCPP_HIDE_FROM_ABI __bounded_iter& operator=(__bounded_iter const&) = default;
64 _LIBCPP_HIDE_FROM_ABI __bounded_iter& operator=(__bounded_iter&&) = default;
65
66private:
67 // Create an iterator wrapping the given iterator, and whose bounds are described
68 // by the provided [begin, end) range.
69 //
70 // This constructor does not check whether the resulting iterator is within its bounds.
71 // However, it does check that the provided [begin, end) range is a valid range (that
72 // is, begin <= end).
73 //
74 // Since it is non-standard for iterators to have this constructor, __bounded_iter must
75 // be created via `std::__make_bounded_iter`.
76 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit __bounded_iter(
77 _Iterator __current, _Iterator __begin, _Iterator __end)
78 : __current_(__current), __begin_(__begin), __end_(__end) {
79 _LIBCPP_ASSERT(__begin <= __end, "__bounded_iter(current, begin, end): [begin, end) is not a valid range");
80 }
81
82 template <class _It>
83 friend _LIBCPP_CONSTEXPR __bounded_iter<_It> __make_bounded_iter(_It, _It, _It);
84
85public:
86 // Dereference and indexing operations.
87 //
88 // These operations check that the iterator is dereferenceable, that is within [begin, end).
89 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 reference operator*() const _NOEXCEPT {
90 _LIBCPP_ASSERT(
91 __in_bounds(__current_), "__bounded_iter::operator*: Attempt to dereference an out-of-range iterator");
92 return *__current_;
93 }
94
95 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 pointer operator->() const _NOEXCEPT {
96 _LIBCPP_ASSERT(
97 __in_bounds(__current_), "__bounded_iter::operator->: Attempt to dereference an out-of-range iterator");
98 return std::__to_address(__current_);
99 }
100
101 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 reference operator[](difference_type __n) const _NOEXCEPT {
102 _LIBCPP_ASSERT(
103 __in_bounds(__current_ + __n), "__bounded_iter::operator[]: Attempt to index an iterator out-of-range");
104 return __current_[__n];
105 }
106
107 // Arithmetic operations.
108 //
109 // These operations do not check that the resulting iterator is within the bounds, since that
110 // would make it impossible to create a past-the-end iterator.
111 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __bounded_iter& operator++() _NOEXCEPT {
112 ++__current_;
113 return *this;
114 }
115 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __bounded_iter operator++(int) _NOEXCEPT {
116 __bounded_iter __tmp(*this);
117 ++*this;
118 return __tmp;
119 }
120
121 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __bounded_iter& operator--() _NOEXCEPT {
122 --__current_;
123 return *this;
124 }
125 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __bounded_iter operator--(int) _NOEXCEPT {
126 __bounded_iter __tmp(*this);
127 --*this;
128 return __tmp;
129 }
130
131 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __bounded_iter& operator+=(difference_type __n) _NOEXCEPT {
132 __current_ += __n;
133 return *this;
134 }
135 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 friend __bounded_iter
136 operator+(__bounded_iter const& __self, difference_type __n) _NOEXCEPT {
137 __bounded_iter __tmp(__self);
138 __tmp += __n;
139 return __tmp;
140 }
141 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 friend __bounded_iter
142 operator+(difference_type __n, __bounded_iter const& __self) _NOEXCEPT {
143 __bounded_iter __tmp(__self);
144 __tmp += __n;
145 return __tmp;
146 }
147
148 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __bounded_iter& operator-=(difference_type __n) _NOEXCEPT {
149 __current_ -= __n;
150 return *this;
151 }
152 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 friend __bounded_iter
153 operator-(__bounded_iter const& __self, difference_type __n) _NOEXCEPT {
154 __bounded_iter __tmp(__self);
155 __tmp -= __n;
156 return __tmp;
157 }
158 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 friend difference_type
159 operator-(__bounded_iter const& __x, __bounded_iter const& __y) _NOEXCEPT {
160 return __x.__current_ - __y.__current_;
161 }
162
163 // Comparison operations.
164 //
165 // These operations do not check whether the iterators are within their bounds.
166 // The valid range for each iterator is also not considered as part of the comparison,
167 // i.e. two iterators pointing to the same location will be considered equal even
168 // if they have different validity ranges.
169 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR friend bool
170 operator==(__bounded_iter const& __x, __bounded_iter const& __y) _NOEXCEPT {
171 return __x.__current_ == __y.__current_;
172 }
173 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR friend bool
174 operator!=(__bounded_iter const& __x, __bounded_iter const& __y) _NOEXCEPT {
175 return __x.__current_ != __y.__current_;
176 }
177 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR friend bool
178 operator<(__bounded_iter const& __x, __bounded_iter const& __y) _NOEXCEPT {
179 return __x.__current_ < __y.__current_;
180 }
181 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR friend bool
182 operator>(__bounded_iter const& __x, __bounded_iter const& __y) _NOEXCEPT {
183 return __x.__current_ > __y.__current_;
184 }
185 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR friend bool
186 operator<=(__bounded_iter const& __x, __bounded_iter const& __y) _NOEXCEPT {
187 return __x.__current_ <= __y.__current_;
188 }
189 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR friend bool
190 operator>=(__bounded_iter const& __x, __bounded_iter const& __y) _NOEXCEPT {
191 return __x.__current_ >= __y.__current_;
192 }
193
194private:
195 // Return whether the given iterator is in the bounds of this __bounded_iter.
196 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool __in_bounds(_Iterator const& __iter) const {
197 return __iter >= __begin_ && __iter < __end_;
198 }
199
200 template <class>
201 friend struct pointer_traits;
202 _Iterator __current_; // current iterator
203 _Iterator __begin_, __end_; // valid range represented as [begin, end)
204};
205
206template <class _It>
207_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __bounded_iter<_It> __make_bounded_iter(_It __it, _It __begin, _It __end) {
208 return __bounded_iter<_It>(std::move(__it), std::move(__begin), std::move(__end));
209}
210
211#if _LIBCPP_STD_VER <= 17
212template <class _Iterator>
213struct __is_cpp17_contiguous_iterator<__bounded_iter<_Iterator> > : true_type {};
214#endif
215
216template <class _Iterator>
217struct pointer_traits<__bounded_iter<_Iterator> > {
218 using pointer = __bounded_iter<_Iterator>;
219 using element_type = typename pointer_traits<_Iterator>::element_type;
220 using difference_type = typename pointer_traits<_Iterator>::difference_type;
221
222 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR static element_type* to_address(pointer __it) _NOEXCEPT {
223 return std::__to_address(__it.__current_);
224 }
225};
226
227_LIBCPP_END_NAMESPACE_STD
228
229#endif // _LIBCPP___ITERATOR_BOUNDED_ITER_H
lib/libcxx/include/__iterator/common_iterator.h+13-26
......@@ -10,8 +10,8 @@
1010#ifndef _LIBCPP___ITERATOR_COMMON_ITERATOR_H
1111#define _LIBCPP___ITERATOR_COMMON_ITERATOR_H
1212
13#include <__assert>
1314#include <__config>
14#include <__debug>
1515#include <__iterator/concepts.h>
1616#include <__iterator/incrementable_traits.h>
1717#include <__iterator/iter_move.h>
......@@ -22,12 +22,12 @@
2222#include <variant>
2323
2424#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
25#pragma GCC system_header
25# pragma GCC system_header
2626#endif
2727
2828_LIBCPP_BEGIN_NAMESPACE_STD
2929
30#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
30#if _LIBCPP_STD_VER > 17
3131
3232template<class _Iter>
3333concept __can_use_postfix_proxy =
......@@ -37,31 +37,18 @@ concept __can_use_postfix_proxy =
3737template<input_or_output_iterator _Iter, sentinel_for<_Iter> _Sent>
3838 requires (!same_as<_Iter, _Sent> && copyable<_Iter>)
3939class common_iterator {
40 class __proxy {
41 friend common_iterator;
42
43 iter_value_t<_Iter> __value;
44 // We can move __x because the only caller verifies that __x is not a reference.
45 constexpr __proxy(iter_reference_t<_Iter>&& __x)
46 : __value(_VSTD::move(__x)) {}
47
48 public:
40 struct __proxy {
4941 constexpr const iter_value_t<_Iter>* operator->() const noexcept {
50 return _VSTD::addressof(__value);
42 return _VSTD::addressof(__value_);
5143 }
44 iter_value_t<_Iter> __value_;
5245 };
5346
54 class __postfix_proxy {
55 friend common_iterator;
56
57 iter_value_t<_Iter> __value;
58 constexpr __postfix_proxy(iter_reference_t<_Iter>&& __x)
59 : __value(_VSTD::forward<iter_reference_t<_Iter>>(__x)) {}
60
61 public:
47 struct __postfix_proxy {
6248 constexpr const iter_value_t<_Iter>& operator*() const noexcept {
63 return __value;
49 return __value_;
6450 }
51 iter_value_t<_Iter> __value_;
6552 };
6653
6754public:
......@@ -133,7 +120,7 @@ public:
133120 auto&& __tmp = *_VSTD::__unchecked_get<_Iter>(__hold_);
134121 return _VSTD::addressof(__tmp);
135122 } else {
136 return __proxy(*_VSTD::__unchecked_get<_Iter>(__hold_));
123 return __proxy{*_VSTD::__unchecked_get<_Iter>(__hold_)};
137124 }
138125 }
139126
......@@ -148,11 +135,11 @@ public:
148135 auto __tmp = *this;
149136 ++*this;
150137 return __tmp;
151 } else if constexpr (requires (_Iter& __i) { { *__i++ } -> __referenceable; } ||
138 } else if constexpr (requires (_Iter& __i) { { *__i++ } -> __can_reference; } ||
152139 !__can_use_postfix_proxy<_Iter>) {
153140 return _VSTD::__unchecked_get<_Iter>(__hold_)++;
154141 } else {
155 __postfix_proxy __p(**this);
142 auto __p = __postfix_proxy{**this};
156143 ++*this;
157144 return __p;
158145 }
......@@ -276,7 +263,7 @@ struct iterator_traits<common_iterator<_Iter, _Sent>> {
276263 using reference = iter_reference_t<_Iter>;
277264};
278265
279#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
266#endif // _LIBCPP_STD_VER > 17
280267
281268_LIBCPP_END_NAMESPACE_STD
282269
lib/libcxx/include/__iterator/concepts.h+20-4
......@@ -21,12 +21,12 @@
2121#include <type_traits>
2222
2323#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
24#pragma GCC system_header
24# pragma GCC system_header
2525#endif
2626
2727_LIBCPP_BEGIN_NAMESPACE_STD
2828
29#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
29#if _LIBCPP_STD_VER > 17
3030
3131// [iterator.concept.readable]
3232template<class _In>
......@@ -90,7 +90,7 @@ concept incrementable =
9090template<class _Ip>
9191concept input_or_output_iterator =
9292 requires(_Ip __i) {
93 { *__i } -> __referenceable;
93 { *__i } -> __can_reference;
9494 } &&
9595 weakly_incrementable<_Ip>;
9696
......@@ -254,10 +254,26 @@ concept indirectly_movable_storable =
254254 constructible_from<iter_value_t<_In>, iter_rvalue_reference_t<_In>> &&
255255 assignable_from<iter_value_t<_In>&, iter_rvalue_reference_t<_In>>;
256256
257template<class _In, class _Out>
258concept indirectly_copyable =
259 indirectly_readable<_In> &&
260 indirectly_writable<_Out, iter_reference_t<_In>>;
261
262template<class _In, class _Out>
263concept indirectly_copyable_storable =
264 indirectly_copyable<_In, _Out> &&
265 indirectly_writable<_Out, iter_value_t<_In>&> &&
266 indirectly_writable<_Out, const iter_value_t<_In>&> &&
267 indirectly_writable<_Out, iter_value_t<_In>&&> &&
268 indirectly_writable<_Out, const iter_value_t<_In>&&> &&
269 copyable<iter_value_t<_In>> &&
270 constructible_from<iter_value_t<_In>, iter_reference_t<_In>> &&
271 assignable_from<iter_value_t<_In>&, iter_reference_t<_In>>;
272
257273// Note: indirectly_swappable is located in iter_swap.h to prevent a dependency cycle
258274// (both iter_swap and indirectly_swappable require indirectly_readable).
259275
260#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
276#endif // _LIBCPP_STD_VER > 17
261277
262278_LIBCPP_END_NAMESPACE_STD
263279
lib/libcxx/include/__iterator/counted_iterator.h+5-5
......@@ -9,8 +9,8 @@
99#ifndef _LIBCPP___ITERATOR_COUNTED_ITERATOR_H
1010#define _LIBCPP___ITERATOR_COUNTED_ITERATOR_H
1111
12#include <__assert>
1213#include <__config>
13#include <__debug>
1414#include <__iterator/concepts.h>
1515#include <__iterator/default_sentinel.h>
1616#include <__iterator/incrementable_traits.h>
......@@ -25,12 +25,12 @@
2525#include <type_traits>
2626
2727#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
28#pragma GCC system_header
28# pragma GCC system_header
2929#endif
3030
3131_LIBCPP_BEGIN_NAMESPACE_STD
3232
33#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
33#if _LIBCPP_STD_VER > 17
3434
3535template<class>
3636struct __counted_iterator_concept {};
......@@ -65,7 +65,7 @@ class counted_iterator
6565 , public __counted_iterator_value_type<_Iter>
6666{
6767public:
68 [[no_unique_address]] _Iter __current_ = _Iter();
68 _LIBCPP_NO_UNIQUE_ADDRESS _Iter __current_ = _Iter();
6969 iter_difference_t<_Iter> __count_ = 0;
7070
7171 using iterator_type = _Iter;
......@@ -296,7 +296,7 @@ struct iterator_traits<counted_iterator<_Iter>> : iterator_traits<_Iter> {
296296 add_pointer_t<iter_reference_t<_Iter>>, void>;
297297};
298298
299#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
299#endif // _LIBCPP_STD_VER > 17
300300
301301_LIBCPP_END_NAMESPACE_STD
302302
lib/libcxx/include/__iterator/data.h+1-1
......@@ -15,7 +15,7 @@
1515#include <initializer_list>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__iterator/default_sentinel.h+3-3
......@@ -13,17 +13,17 @@
1313#include <__config>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16#pragma GCC system_header
16# pragma GCC system_header
1717#endif
1818
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
21#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
21#if _LIBCPP_STD_VER > 17
2222
2323struct default_sentinel_t { };
2424inline constexpr default_sentinel_t default_sentinel{};
2525
26#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
26#endif // _LIBCPP_STD_VER > 17
2727
2828_LIBCPP_END_NAMESPACE_STD
2929
lib/libcxx/include/__iterator/distance.h+3-3
......@@ -20,7 +20,7 @@
2020#include <type_traits>
2121
2222#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23#pragma GCC system_header
23# pragma GCC system_header
2424#endif
2525
2626_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -52,7 +52,7 @@ distance(_InputIter __first, _InputIter __last)
5252 return _VSTD::__distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
5353}
5454
55#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
55#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
5656
5757// [range.iter.op.distance]
5858
......@@ -100,7 +100,7 @@ inline namespace __cpo {
100100} // namespace __cpo
101101} // namespace ranges
102102
103#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
103#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
104104
105105_LIBCPP_END_NAMESPACE_STD
106106
lib/libcxx/include/__iterator/empty.h+1-1
......@@ -15,7 +15,7 @@
1515#include <initializer_list>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__iterator/erase_if_container.h+1-1
......@@ -13,7 +13,7 @@
1313#include <__config>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16#pragma GCC system_header
16# pragma GCC system_header
1717#endif
1818
1919_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__iterator/front_insert_iterator.h+5-5
......@@ -18,7 +18,7 @@
1818#include <cstddef>
1919
2020#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21#pragma GCC system_header
21# pragma GCC system_header
2222#endif
2323
2424_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -46,11 +46,11 @@ public:
4646 typedef _Container container_type;
4747
4848 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
49 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(const typename _Container::value_type& __value_)
50 {container->push_front(__value_); return *this;}
49 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(const typename _Container::value_type& __value)
50 {container->push_front(__value); return *this;}
5151#ifndef _LIBCPP_CXX03_LANG
52 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(typename _Container::value_type&& __value_)
53 {container->push_front(_VSTD::move(__value_)); return *this;}
52 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(typename _Container::value_type&& __value)
53 {container->push_front(_VSTD::move(__value)); return *this;}
5454#endif // _LIBCPP_CXX03_LANG
5555 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator*() {return *this;}
5656 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator++() {return *this;}
lib/libcxx/include/__iterator/incrementable_traits.h+4-3
......@@ -11,16 +11,17 @@
1111#define _LIBCPP___ITERATOR_INCREMENTABLE_TRAITS_H
1212
1313#include <__config>
14#include <__type_traits/is_primary_template.h>
1415#include <concepts>
1516#include <type_traits>
1617
1718#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
19# pragma GCC system_header
1920#endif
2021
2122_LIBCPP_BEGIN_NAMESPACE_STD
2223
23#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
24#if _LIBCPP_STD_VER > 17
2425
2526// [incrementable.traits]
2627template<class> struct incrementable_traits {};
......@@ -65,7 +66,7 @@ using iter_difference_t = typename conditional_t<__is_primary_template<iterator_
6566 incrementable_traits<remove_cvref_t<_Ip> >,
6667 iterator_traits<remove_cvref_t<_Ip> > >::difference_type;
6768
68#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
69#endif // _LIBCPP_STD_VER > 17
6970
7071_LIBCPP_END_NAMESPACE_STD
7172
lib/libcxx/include/__iterator/indirectly_comparable.h+6-2
......@@ -15,15 +15,19 @@
1515#include <__iterator/concepts.h>
1616#include <__iterator/projected.h>
1717
18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19# pragma GCC system_header
20#endif
21
1822_LIBCPP_BEGIN_NAMESPACE_STD
1923
20#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
24#if _LIBCPP_STD_VER > 17
2125
2226template <class _I1, class _I2, class _Rp, class _P1 = identity, class _P2 = identity>
2327concept indirectly_comparable =
2428 indirect_binary_predicate<_Rp, projected<_I1, _P1>, projected<_I2, _P2>>;
2529
26#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
30#endif // _LIBCPP_STD_VER > 17
2731
2832_LIBCPP_END_NAMESPACE_STD
2933
lib/libcxx/include/__iterator/insert_iterator.h+6-6
......@@ -19,12 +19,12 @@
1919#include <cstddef>
2020
2121#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22#pragma GCC system_header
22# pragma GCC system_header
2323#endif
2424
2525_LIBCPP_BEGIN_NAMESPACE_STD
2626
27#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
27#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
2828template <class _Container>
2929using __insert_iterator_iter_t = ranges::iterator_t<_Container>;
3030#else
......@@ -57,11 +57,11 @@ public:
5757
5858 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator(_Container& __x, __insert_iterator_iter_t<_Container> __i)
5959 : container(_VSTD::addressof(__x)), iter(__i) {}
60 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(const typename _Container::value_type& __value_)
61 {iter = container->insert(iter, __value_); ++iter; return *this;}
60 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(const typename _Container::value_type& __value)
61 {iter = container->insert(iter, __value); ++iter; return *this;}
6262#ifndef _LIBCPP_CXX03_LANG
63 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(typename _Container::value_type&& __value_)
64 {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
63 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(typename _Container::value_type&& __value)
64 {iter = container->insert(iter, _VSTD::move(__value)); ++iter; return *this;}
6565#endif // _LIBCPP_CXX03_LANG
6666 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator*() {return *this;}
6767 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++() {return *this;}
lib/libcxx/include/__iterator/istream_iterator.h+14-1
......@@ -11,13 +11,15 @@
1111#define _LIBCPP___ITERATOR_ISTREAM_ITERATOR_H
1212
1313#include <__config>
14#include <__iterator/default_sentinel.h>
1415#include <__iterator/iterator.h>
1516#include <__iterator/iterator_traits.h>
1617#include <__memory/addressof.h>
18#include <cstddef>
1719#include <iosfwd> // for forward declarations of char_traits and basic_istream
1820
1921#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20#pragma GCC system_header
22# pragma GCC system_header
2123#endif
2224
2325_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -45,6 +47,9 @@ private:
4547 _Tp __value_;
4648public:
4749 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(nullptr), __value_() {}
50#if _LIBCPP_STD_VER > 17
51 _LIBCPP_HIDE_FROM_ABI constexpr istream_iterator(default_sentinel_t) : istream_iterator() {}
52#endif // _LIBCPP_STD_VER > 17
4853 _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(_VSTD::addressof(__s))
4954 {
5055 if (!(*__in_stream_ >> __value_))
......@@ -67,6 +72,12 @@ public:
6772 bool
6873 operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
6974 const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
75
76#if _LIBCPP_STD_VER > 17
77 friend _LIBCPP_HIDE_FROM_ABI bool operator==(const istream_iterator& __i, default_sentinel_t) {
78 return __i.__in_stream_ == nullptr;
79 }
80#endif // _LIBCPP_STD_VER > 17
7081};
7182
7283template <class _Tp, class _CharT, class _Traits, class _Distance>
......@@ -78,6 +89,7 @@ operator==(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
7889 return __x.__in_stream_ == __y.__in_stream_;
7990}
8091
92#if _LIBCPP_STD_VER <= 17
8193template <class _Tp, class _CharT, class _Traits, class _Distance>
8294inline _LIBCPP_INLINE_VISIBILITY
8395bool
......@@ -86,6 +98,7 @@ operator!=(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
8698{
8799 return !(__x == __y);
88100}
101#endif // _LIBCPP_STD_VER <= 17
89102
90103_LIBCPP_END_NAMESPACE_STD
91104
lib/libcxx/include/__iterator/istreambuf_iterator.h+16-2
......@@ -11,12 +11,13 @@
1111#define _LIBCPP___ITERATOR_ISTREAMBUF_ITERATOR_H
1212
1313#include <__config>
14#include <__iterator/default_sentinel.h>
1415#include <__iterator/iterator.h>
1516#include <__iterator/iterator_traits.h>
1617#include <iosfwd> // for forward declaration of basic_streambuf
1718
1819#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
20# pragma GCC system_header
2021#endif
2122
2223_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -49,7 +50,8 @@ private:
4950 {
5051 char_type __keep_;
5152 streambuf_type* __sbuf_;
52 _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
53 _LIBCPP_INLINE_VISIBILITY
54 explicit __proxy(char_type __c, streambuf_type* __s)
5355 : __keep_(__c), __sbuf_(__s) {}
5456 friend class istreambuf_iterator;
5557 public:
......@@ -65,6 +67,10 @@ private:
6567 }
6668public:
6769 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(nullptr) {}
70#if _LIBCPP_STD_VER > 17
71 _LIBCPP_INLINE_VISIBILITY constexpr istreambuf_iterator(default_sentinel_t) noexcept
72 : istreambuf_iterator() {}
73#endif // _LIBCPP_STD_VER > 17
6874 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
6975 : __sbuf_(__s.rdbuf()) {}
7076 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
......@@ -86,6 +92,12 @@ public:
8692
8793 _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
8894 {return __test_for_eof() == __b.__test_for_eof();}
95
96#if _LIBCPP_STD_VER > 17
97 friend _LIBCPP_HIDE_FROM_ABI bool operator==(const istreambuf_iterator& __i, default_sentinel_t) {
98 return __i.__test_for_eof();
99 }
100#endif // _LIBCPP_STD_VER > 17
89101};
90102
91103template <class _CharT, class _Traits>
......@@ -94,11 +106,13 @@ bool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
94106 const istreambuf_iterator<_CharT,_Traits>& __b)
95107 {return __a.equal(__b);}
96108
109#if _LIBCPP_STD_VER <= 17
97110template <class _CharT, class _Traits>
98111inline _LIBCPP_INLINE_VISIBILITY
99112bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
100113 const istreambuf_iterator<_CharT,_Traits>& __b)
101114 {return !__a.equal(__b);}
115#endif // _LIBCPP_STD_VER <= 17
102116
103117_LIBCPP_END_NAMESPACE_STD
104118
lib/libcxx/include/__iterator/iter_move.h+40-34
......@@ -10,20 +10,20 @@
1010#ifndef _LIBCPP___ITERATOR_ITER_MOVE_H
1111#define _LIBCPP___ITERATOR_ITER_MOVE_H
1212
13#include <__concepts/class_or_enum.h>
1314#include <__config>
1415#include <__iterator/iterator_traits.h>
1516#include <__utility/forward.h>
16#include <concepts> // __class_or_enum
17#include <__utility/move.h>
1718#include <type_traits>
18#include <utility>
1919
2020#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21#pragma GCC system_header
21# pragma GCC system_header
2222#endif
2323
2424_LIBCPP_BEGIN_NAMESPACE_STD
2525
26#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
26#if _LIBCPP_STD_VER > 17
2727
2828// [iterator.cust.move]
2929
......@@ -36,44 +36,50 @@ template <class _Tp>
3636concept __unqualified_iter_move =
3737 __class_or_enum<remove_cvref_t<_Tp>> &&
3838 requires (_Tp&& __t) {
39 iter_move(_VSTD::forward<_Tp>(__t));
39 iter_move(std::forward<_Tp>(__t));
4040 };
4141
42// [iterator.cust.move]/1
43// The name ranges::iter_move denotes a customization point object.
44// The expression ranges::iter_move(E) for a subexpression E is
45// expression-equivalent to:
42template<class _Tp>
43concept __move_deref =
44 !__unqualified_iter_move<_Tp> &&
45 requires (_Tp&& __t) {
46 *__t;
47 requires is_lvalue_reference_v<decltype(*__t)>;
48 };
49
50template<class _Tp>
51concept __just_deref =
52 !__unqualified_iter_move<_Tp> &&
53 !__move_deref<_Tp> &&
54 requires (_Tp&& __t) {
55 *__t;
56 requires (!is_lvalue_reference_v<decltype(*__t)>);
57 };
58
59// [iterator.cust.move]
60
4661struct __fn {
47 // [iterator.cust.move]/1.1
48 // iter_move(E), if E has class or enumeration type and iter_move(E) is a
49 // well-formed expression when treated as an unevaluated operand, [...]
5062 template<class _Ip>
51 requires __class_or_enum<remove_cvref_t<_Ip>> && __unqualified_iter_move<_Ip>
63 requires __unqualified_iter_move<_Ip>
5264 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator()(_Ip&& __i) const
53 noexcept(noexcept(iter_move(_VSTD::forward<_Ip>(__i))))
65 noexcept(noexcept(iter_move(std::forward<_Ip>(__i))))
5466 {
55 return iter_move(_VSTD::forward<_Ip>(__i));
67 return iter_move(std::forward<_Ip>(__i));
5668 }
5769
58 // [iterator.cust.move]/1.2
59 // Otherwise, if the expression *E is well-formed:
60 // 1.2.1 if *E is an lvalue, std::move(*E);
61 // 1.2.2 otherwise, *E.
6270 template<class _Ip>
63 requires (!(__class_or_enum<remove_cvref_t<_Ip>> && __unqualified_iter_move<_Ip>)) &&
64 requires(_Ip&& __i) { *_VSTD::forward<_Ip>(__i); }
65 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator()(_Ip&& __i) const
66 noexcept(noexcept(*_VSTD::forward<_Ip>(__i)))
67 {
68 if constexpr (is_lvalue_reference_v<decltype(*_VSTD::forward<_Ip>(__i))>) {
69 return _VSTD::move(*_VSTD::forward<_Ip>(__i));
70 } else {
71 return *_VSTD::forward<_Ip>(__i);
72 }
73 }
71 requires __move_deref<_Ip>
72 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Ip&& __i) const
73 noexcept(noexcept(std::move(*std::forward<_Ip>(__i))))
74 -> decltype( std::move(*std::forward<_Ip>(__i)))
75 { return std::move(*std::forward<_Ip>(__i)); }
7476
75 // [iterator.cust.move]/1.3
76 // Otherwise, ranges::iter_move(E) is ill-formed.
77 template<class _Ip>
78 requires __just_deref<_Ip>
79 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Ip&& __i) const
80 noexcept(noexcept(*std::forward<_Ip>(__i)))
81 -> decltype( *std::forward<_Ip>(__i))
82 { return *std::forward<_Ip>(__i); }
7783};
7884} // namespace __iter_move
7985
......@@ -83,10 +89,10 @@ inline namespace __cpo {
8389} // namespace ranges
8490
8591template<__dereferenceable _Tp>
86 requires requires(_Tp& __t) { { ranges::iter_move(__t) } -> __referenceable; }
92 requires requires(_Tp& __t) { { ranges::iter_move(__t) } -> __can_reference; }
8793using iter_rvalue_reference_t = decltype(ranges::iter_move(declval<_Tp&>()));
8894
89#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
95#endif // _LIBCPP_STD_VER > 17
9096
9197_LIBCPP_END_NAMESPACE_STD
9298
lib/libcxx/include/__iterator/iter_swap.h+3-3
......@@ -20,12 +20,12 @@
2020#include <type_traits>
2121
2222#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23#pragma GCC system_header
23# pragma GCC system_header
2424#endif
2525
2626_LIBCPP_BEGIN_NAMESPACE_STD
2727
28#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
28#if _LIBCPP_STD_VER > 17
2929
3030// [iter.cust.swap]
3131
......@@ -99,7 +99,7 @@ concept indirectly_swappable =
9999 ranges::iter_swap(__i2, __i1);
100100 };
101101
102#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
102#endif // _LIBCPP_STD_VER > 17
103103
104104_LIBCPP_END_NAMESPACE_STD
105105
lib/libcxx/include/__iterator/iterator.h+1-1
......@@ -14,7 +14,7 @@
1414#include <cstddef>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
17# pragma GCC system_header
1818#endif
1919
2020_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__iterator/iterator_traits.h+51-34
......@@ -17,31 +17,31 @@
1717#include <type_traits>
1818
1919#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20#pragma GCC system_header
20# pragma GCC system_header
2121#endif
2222
2323_LIBCPP_BEGIN_NAMESPACE_STD
2424
25#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
25#if _LIBCPP_STD_VER > 17
2626
2727template <class _Tp>
2828using __with_reference = _Tp&;
2929
3030template <class _Tp>
31concept __referenceable = requires {
31concept __can_reference = requires {
3232 typename __with_reference<_Tp>;
3333};
3434
3535template <class _Tp>
3636concept __dereferenceable = requires(_Tp& __t) {
37 { *__t } -> __referenceable; // not required to be equality-preserving
37 { *__t } -> __can_reference; // not required to be equality-preserving
3838};
3939
4040// [iterator.traits]
4141template<__dereferenceable _Tp>
4242using iter_reference_t = decltype(*declval<_Tp&>());
4343
44#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
44#endif // _LIBCPP_STD_VER > 17
4545
4646template <class _Iter>
4747struct _LIBCPP_TEMPLATE_VIS iterator_traits;
......@@ -105,15 +105,14 @@ template <class _Tp>
105105struct __has_iterator_typedefs
106106{
107107private:
108 struct __two {char __lx; char __lxx;};
109 template <class _Up> static __two __test(...);
110 template <class _Up> static char __test(typename __void_t<typename _Up::iterator_category>::type* = 0,
111 typename __void_t<typename _Up::difference_type>::type* = 0,
112 typename __void_t<typename _Up::value_type>::type* = 0,
113 typename __void_t<typename _Up::reference>::type* = 0,
114 typename __void_t<typename _Up::pointer>::type* = 0);
108 template <class _Up> static false_type __test(...);
109 template <class _Up> static true_type __test(typename __void_t<typename _Up::iterator_category>::type* = 0,
110 typename __void_t<typename _Up::difference_type>::type* = 0,
111 typename __void_t<typename _Up::value_type>::type* = 0,
112 typename __void_t<typename _Up::reference>::type* = 0,
113 typename __void_t<typename _Up::pointer>::type* = 0);
115114public:
116 static const bool value = sizeof(__test<_Tp>(0,0,0,0,0)) == 1;
115 static const bool value = decltype(__test<_Tp>(0,0,0,0,0))::value;
117116};
118117
119118
......@@ -121,35 +120,34 @@ template <class _Tp>
121120struct __has_iterator_category
122121{
123122private:
124 struct __two {char __lx; char __lxx;};
125 template <class _Up> static __two __test(...);
126 template <class _Up> static char __test(typename _Up::iterator_category* = nullptr);
123 template <class _Up> static false_type __test(...);
124 template <class _Up> static true_type __test(typename _Up::iterator_category* = nullptr);
127125public:
128 static const bool value = sizeof(__test<_Tp>(nullptr)) == 1;
126 static const bool value = decltype(__test<_Tp>(nullptr))::value;
129127};
130128
131129template <class _Tp>
132130struct __has_iterator_concept
133131{
134132private:
135 struct __two {char __lx; char __lxx;};
136 template <class _Up> static __two __test(...);
137 template <class _Up> static char __test(typename _Up::iterator_concept* = nullptr);
133 template <class _Up> static false_type __test(...);
134 template <class _Up> static true_type __test(typename _Up::iterator_concept* = nullptr);
138135public:
139 static const bool value = sizeof(__test<_Tp>(nullptr)) == 1;
136 static const bool value = decltype(__test<_Tp>(nullptr))::value;
140137};
141138
142#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
139#if _LIBCPP_STD_VER > 17
143140
144// The `cpp17-*-iterator` exposition-only concepts are easily confused with the Cpp17*Iterator tables,
145// so they've been banished to a namespace that makes it obvious they have a niche use-case.
141// The `cpp17-*-iterator` exposition-only concepts have very similar names to the `Cpp17*Iterator` named requirements
142// from `[iterator.cpp17]`. To avoid confusion between the two, the exposition-only concepts have been banished to
143// a "detail" namespace indicating they have a niche use-case.
146144namespace __iterator_traits_detail {
147145template<class _Ip>
148146concept __cpp17_iterator =
149147 requires(_Ip __i) {
150 { *__i } -> __referenceable;
148 { *__i } -> __can_reference;
151149 { ++__i } -> same_as<_Ip&>;
152 { *__i++ } -> __referenceable;
150 { *__i++ } -> __can_reference;
153151 } &&
154152 copyable<_Ip>;
155153
......@@ -198,7 +196,7 @@ concept __cpp17_random_access_iterator =
198196 { __i + __n } -> same_as<_Ip>;
199197 { __n + __i } -> same_as<_Ip>;
200198 { __i - __n } -> same_as<_Ip>;
201 { __i - __i } -> same_as<decltype(__n)>;
199 { __i - __i } -> same_as<decltype(__n)>; // NOLINT(misc-redundant-expression) ; This is llvm.org/PR54114
202200 { __i[__n] } -> convertible_to<iter_reference_t<_Ip>>;
203201 };
204202} // namespace __iterator_traits_detail
......@@ -362,7 +360,7 @@ struct iterator_traits : __iterator_traits<_Ip> {
362360 using __primary_template = iterator_traits;
363361};
364362
365#else // !defined(_LIBCPP_HAS_NO_CONCEPTS)
363#else // _LIBCPP_STD_VER > 17
366364
367365template <class _Iter, bool> struct __iterator_traits {};
368366
......@@ -399,10 +397,10 @@ struct _LIBCPP_TEMPLATE_VIS iterator_traits
399397
400398 using __primary_template = iterator_traits;
401399};
402#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
400#endif // _LIBCPP_STD_VER > 17
403401
404402template<class _Tp>
405#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
403#if _LIBCPP_STD_VER > 17
406404requires is_object_v<_Tp>
407405#endif
408406struct _LIBCPP_TEMPLATE_VIS iterator_traits<_Tp*>
......@@ -468,27 +466,46 @@ template <class _Up>
468466struct __is_cpp17_contiguous_iterator<_Up*> : true_type {};
469467
470468
469template <class _Iter>
470class __wrap_iter;
471
471472template <class _Tp>
472473struct __is_exactly_cpp17_input_iterator
473474 : public integral_constant<bool,
474475 __has_iterator_category_convertible_to<_Tp, input_iterator_tag>::value &&
475476 !__has_iterator_category_convertible_to<_Tp, forward_iterator_tag>::value> {};
476477
477#if _LIBCPP_STD_VER >= 17
478template <class _Tp>
479struct __is_exactly_cpp17_forward_iterator
480 : public integral_constant<bool,
481 __has_iterator_category_convertible_to<_Tp, forward_iterator_tag>::value &&
482 !__has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag>::value> {};
483
484template <class _Tp>
485struct __is_exactly_cpp17_bidirectional_iterator
486 : public integral_constant<bool,
487 __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag>::value &&
488 !__has_iterator_category_convertible_to<_Tp, random_access_iterator_tag>::value> {};
489
478490template<class _InputIterator>
479491using __iter_value_type = typename iterator_traits<_InputIterator>::value_type;
480492
481493template<class _InputIterator>
482using __iter_key_type = remove_const_t<typename iterator_traits<_InputIterator>::value_type::first_type>;
494using __iter_key_type = typename remove_const<typename iterator_traits<_InputIterator>::value_type::first_type>::type;
483495
484496template<class _InputIterator>
485497using __iter_mapped_type = typename iterator_traits<_InputIterator>::value_type::second_type;
486498
487499template<class _InputIterator>
488500using __iter_to_alloc_type = pair<
489 add_const_t<typename iterator_traits<_InputIterator>::value_type::first_type>,
501 typename add_const<typename iterator_traits<_InputIterator>::value_type::first_type>::type,
490502 typename iterator_traits<_InputIterator>::value_type::second_type>;
491#endif // _LIBCPP_STD_VER >= 17
503
504template <class _Iter>
505using __iterator_category_type = typename iterator_traits<_Iter>::iterator_category;
506
507template <class _Iter>
508using __iterator_pointer_type = typename iterator_traits<_Iter>::pointer;
492509
493510_LIBCPP_END_NAMESPACE_STD
494511
lib/libcxx/include/__iterator/mergeable.h created+41
......@@ -0,0 +1,41 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___ITERATOR_MERGEABLE_H
11#define _LIBCPP___ITERATOR_MERGEABLE_H
12
13#include <__config>
14#include <__functional/identity.h>
15#include <__functional/ranges_operations.h>
16#include <__iterator/concepts.h>
17#include <__iterator/projected.h>
18
19#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20# pragma GCC system_header
21#endif
22
23_LIBCPP_BEGIN_NAMESPACE_STD
24
25#if _LIBCPP_STD_VER > 17
26
27template <class _Input1, class _Input2, class _Output,
28 class _Comp = ranges::less, class _Proj1 = identity, class _Proj2 = identity>
29concept mergeable =
30 input_iterator<_Input1> &&
31 input_iterator<_Input2> &&
32 weakly_incrementable<_Output> &&
33 indirectly_copyable<_Input1, _Output> &&
34 indirectly_copyable<_Input2, _Output> &&
35 indirect_strict_weak_order<_Comp, projected<_Input1, _Proj1>, projected<_Input2, _Proj2>>;
36
37#endif // _LIBCPP_STD_VER > 17
38
39_LIBCPP_END_NAMESPACE_STD
40
41#endif // _LIBCPP___ITERATOR_MERGEABLE_H
lib/libcxx/include/__iterator/move_iterator.h+158-17
......@@ -10,51 +10,131 @@
1010#ifndef _LIBCPP___ITERATOR_MOVE_ITERATOR_H
1111#define _LIBCPP___ITERATOR_MOVE_ITERATOR_H
1212
13#include <__compare/compare_three_way_result.h>
14#include <__compare/three_way_comparable.h>
15#include <__concepts/assignable.h>
16#include <__concepts/convertible_to.h>
17#include <__concepts/derived_from.h>
18#include <__concepts/same_as.h>
1319#include <__config>
20#include <__iterator/concepts.h>
21#include <__iterator/incrementable_traits.h>
22#include <__iterator/iter_move.h>
23#include <__iterator/iter_swap.h>
1424#include <__iterator/iterator_traits.h>
25#include <__iterator/move_sentinel.h>
26#include <__iterator/readable_traits.h>
1527#include <__utility/move.h>
1628#include <type_traits>
1729
1830#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
31# pragma GCC system_header
2032#endif
2133
2234_LIBCPP_BEGIN_NAMESPACE_STD
2335
36#if _LIBCPP_STD_VER > 17
37template<class _Iter, class = void>
38struct __move_iter_category_base {};
39
40template<class _Iter>
41 requires requires { typename iterator_traits<_Iter>::iterator_category; }
42struct __move_iter_category_base<_Iter> {
43 using iterator_category = _If<
44 derived_from<typename iterator_traits<_Iter>::iterator_category, random_access_iterator_tag>,
45 random_access_iterator_tag,
46 typename iterator_traits<_Iter>::iterator_category
47 >;
48};
49
50template<class _Iter, class _Sent>
51concept __move_iter_comparable = requires {
52 { declval<const _Iter&>() == declval<_Sent>() } -> convertible_to<bool>;
53};
54#endif // _LIBCPP_STD_VER > 17
55
2456template <class _Iter>
2557class _LIBCPP_TEMPLATE_VIS move_iterator
58#if _LIBCPP_STD_VER > 17
59 : public __move_iter_category_base<_Iter>
60#endif
2661{
2762public:
2863#if _LIBCPP_STD_VER > 17
29 typedef input_iterator_tag iterator_concept;
30#endif
31
64 using iterator_type = _Iter;
65 using iterator_concept = input_iterator_tag;
66 // iterator_category is inherited and not always present
67 using value_type = iter_value_t<_Iter>;
68 using difference_type = iter_difference_t<_Iter>;
69 using pointer = _Iter;
70 using reference = iter_rvalue_reference_t<_Iter>;
71#else
3272 typedef _Iter iterator_type;
3373 typedef _If<
3474 __is_cpp17_random_access_iterator<_Iter>::value,
3575 random_access_iterator_tag,
3676 typename iterator_traits<_Iter>::iterator_category
37 > iterator_category;
77 > iterator_category;
3878 typedef typename iterator_traits<iterator_type>::value_type value_type;
3979 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
4080 typedef iterator_type pointer;
4181
42#ifndef _LIBCPP_CXX03_LANG
4382 typedef typename iterator_traits<iterator_type>::reference __reference;
4483 typedef typename conditional<
4584 is_reference<__reference>::value,
4685 typename remove_reference<__reference>::type&&,
4786 __reference
4887 >::type reference;
49#else
50 typedef typename iterator_traits<iterator_type>::reference reference;
51#endif
88#endif // _LIBCPP_STD_VER > 17
5289
5390 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
54 move_iterator() : __current_() {}
91 explicit move_iterator(_Iter __i) : __current_(std::move(__i)) {}
92
93 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
94 move_iterator& operator++() { ++__current_; return *this; }
95
96 _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
97 pointer operator->() const { return __current_; }
98
99#if _LIBCPP_STD_VER > 17
100 _LIBCPP_HIDE_FROM_ABI constexpr
101 move_iterator() requires is_constructible_v<_Iter> : __current_() {}
102
103 template <class _Up>
104 requires (!_IsSame<_Up, _Iter>::value) && convertible_to<const _Up&, _Iter>
105 _LIBCPP_HIDE_FROM_ABI constexpr
106 move_iterator(const move_iterator<_Up>& __u) : __current_(__u.base()) {}
107
108 template <class _Up>
109 requires (!_IsSame<_Up, _Iter>::value) &&
110 convertible_to<const _Up&, _Iter> &&
111 assignable_from<_Iter&, const _Up&>
112 _LIBCPP_HIDE_FROM_ABI constexpr
113 move_iterator& operator=(const move_iterator<_Up>& __u) {
114 __current_ = __u.base();
115 return *this;
116 }
117
118 _LIBCPP_HIDE_FROM_ABI constexpr const _Iter& base() const & noexcept { return __current_; }
119 _LIBCPP_HIDE_FROM_ABI constexpr _Iter base() && { return std::move(__current_); }
55120
121 _LIBCPP_HIDE_FROM_ABI constexpr
122 reference operator*() const { return ranges::iter_move(__current_); }
123 _LIBCPP_HIDE_FROM_ABI constexpr
124 reference operator[](difference_type __n) const { return ranges::iter_move(__current_ + __n); }
125
126 _LIBCPP_HIDE_FROM_ABI constexpr
127 auto operator++(int)
128 requires forward_iterator<_Iter>
129 {
130 move_iterator __tmp(*this); ++__current_; return __tmp;
131 }
132
133 _LIBCPP_HIDE_FROM_ABI constexpr
134 void operator++(int) { ++__current_; }
135#else
56136 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
57 explicit move_iterator(_Iter __i) : __current_(_VSTD::move(__i)) {}
137 move_iterator() : __current_() {}
58138
59139 template <class _Up, class = __enable_if_t<
60140 !is_same<_Up, _Iter>::value && is_convertible<const _Up&, _Iter>::value
......@@ -79,14 +159,12 @@ public:
79159 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
80160 reference operator*() const { return static_cast<reference>(*__current_); }
81161 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
82 pointer operator->() const { return __current_; }
83 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
84162 reference operator[](difference_type __n) const { return static_cast<reference>(__current_[__n]); }
85163
86 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
87 move_iterator& operator++() { ++__current_; return *this; }
88164 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
89165 move_iterator operator++(int) { move_iterator __tmp(*this); ++__current_; return __tmp; }
166#endif // _LIBCPP_STD_VER > 17
167
90168 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
91169 move_iterator& operator--() { --__current_; return *this; }
92170 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
......@@ -100,7 +178,48 @@ public:
100178 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
101179 move_iterator& operator-=(difference_type __n) { __current_ -= __n; return *this; }
102180
181#if _LIBCPP_STD_VER > 17
182 template<sentinel_for<_Iter> _Sent>
183 friend _LIBCPP_HIDE_FROM_ABI constexpr
184 bool operator==(const move_iterator& __x, const move_sentinel<_Sent>& __y)
185 requires __move_iter_comparable<_Iter, _Sent>
186 {
187 return __x.base() == __y.base();
188 }
189
190 template<sized_sentinel_for<_Iter> _Sent>
191 friend _LIBCPP_HIDE_FROM_ABI constexpr
192 iter_difference_t<_Iter> operator-(const move_sentinel<_Sent>& __x, const move_iterator& __y)
193 {
194 return __x.base() - __y.base();
195 }
196
197 template<sized_sentinel_for<_Iter> _Sent>
198 friend _LIBCPP_HIDE_FROM_ABI constexpr
199 iter_difference_t<_Iter> operator-(const move_iterator& __x, const move_sentinel<_Sent>& __y)
200 {
201 return __x.base() - __y.base();
202 }
203
204 friend _LIBCPP_HIDE_FROM_ABI constexpr
205 iter_rvalue_reference_t<_Iter> iter_move(const move_iterator& __i)
206 noexcept(noexcept(ranges::iter_move(__i.__current_)))
207 {
208 return ranges::iter_move(__i.__current_);
209 }
210
211 template<indirectly_swappable<_Iter> _It2>
212 friend _LIBCPP_HIDE_FROM_ABI constexpr
213 void iter_swap(const move_iterator& __x, const move_iterator<_It2>& __y)
214 noexcept(noexcept(ranges::iter_swap(__x.__current_, __y.__current_)))
215 {
216 return ranges::iter_swap(__x.__current_, __y.__current_);
217 }
218#endif // _LIBCPP_STD_VER > 17
219
103220private:
221 template<class _It2> friend class move_iterator;
222
104223 _Iter __current_;
105224};
106225
......@@ -111,12 +230,14 @@ bool operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& _
111230 return __x.base() == __y.base();
112231}
113232
233#if _LIBCPP_STD_VER <= 17
114234template <class _Iter1, class _Iter2>
115235inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
116236bool operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
117237{
118238 return __x.base() != __y.base();
119239}
240#endif // _LIBCPP_STD_VER <= 17
120241
121242template <class _Iter1, class _Iter2>
122243inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
......@@ -146,6 +267,16 @@ bool operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& _
146267 return __x.base() >= __y.base();
147268}
148269
270#if _LIBCPP_STD_VER > 17
271template <class _Iter1, three_way_comparable_with<_Iter1> _Iter2>
272inline _LIBCPP_HIDE_FROM_ABI constexpr
273auto operator<=>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
274 -> compare_three_way_result_t<_Iter1, _Iter2>
275{
276 return __x.base() <=> __y.base();
277}
278#endif // _LIBCPP_STD_VER > 17
279
149280#ifndef _LIBCPP_CXX03_LANG
150281template <class _Iter1, class _Iter2>
151282inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
......@@ -162,8 +293,17 @@ operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
162293{
163294 return __x.base() - __y.base();
164295}
165#endif
296#endif // !_LIBCPP_CXX03_LANG
166297
298#if _LIBCPP_STD_VER > 17
299template <class _Iter>
300inline _LIBCPP_HIDE_FROM_ABI constexpr
301move_iterator<_Iter> operator+(iter_difference_t<_Iter> __n, const move_iterator<_Iter>& __x)
302 requires requires { { __x.base() + __n } -> same_as<_Iter>; }
303{
304 return __x + __n;
305}
306#else
167307template <class _Iter>
168308inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
169309move_iterator<_Iter>
......@@ -171,13 +311,14 @@ operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterato
171311{
172312 return move_iterator<_Iter>(__x.base() + __n);
173313}
314#endif // _LIBCPP_STD_VER > 17
174315
175316template <class _Iter>
176317inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
177318move_iterator<_Iter>
178319make_move_iterator(_Iter __i)
179320{
180 return move_iterator<_Iter>(_VSTD::move(__i));
321 return move_iterator<_Iter>(std::move(__i));
181322}
182323
183324_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__iterator/move_sentinel.h created+57
......@@ -0,0 +1,57 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ITERATOR_MOVE_SENTINEL_H
10#define _LIBCPP___ITERATOR_MOVE_SENTINEL_H
11
12#include <__concepts/assignable.h>
13#include <__concepts/convertible_to.h>
14#include <__concepts/semiregular.h>
15#include <__config>
16#include <__utility/move.h>
17
18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19# pragma GCC system_header
20#endif
21
22_LIBCPP_BEGIN_NAMESPACE_STD
23
24#if _LIBCPP_STD_VER > 17
25
26template <semiregular _Sent>
27class _LIBCPP_TEMPLATE_VIS move_sentinel
28{
29public:
30 _LIBCPP_HIDE_FROM_ABI
31 move_sentinel() = default;
32
33 _LIBCPP_HIDE_FROM_ABI constexpr
34 explicit move_sentinel(_Sent __s) : __last_(std::move(__s)) {}
35
36 template <class _S2>
37 requires convertible_to<const _S2&, _Sent>
38 _LIBCPP_HIDE_FROM_ABI constexpr
39 move_sentinel(const move_sentinel<_S2>& __s) : __last_(__s.base()) {}
40
41 template <class _S2>
42 requires assignable_from<_Sent&, const _S2&>
43 _LIBCPP_HIDE_FROM_ABI constexpr
44 move_sentinel& operator=(const move_sentinel<_S2>& __s)
45 { __last_ = __s.base(); return *this; }
46
47 constexpr _Sent base() const { return __last_; }
48
49private:
50 _Sent __last_ = _Sent();
51};
52
53#endif // _LIBCPP_STD_VER > 17
54
55_LIBCPP_END_NAMESPACE_STD
56
57#endif // _LIBCPP___ITERATOR_MOVE_SENTINEL_H
lib/libcxx/include/__iterator/next.h+8-10
......@@ -10,8 +10,8 @@
1010#ifndef _LIBCPP___ITERATOR_NEXT_H
1111#define _LIBCPP___ITERATOR_NEXT_H
1212
13#include <__assert>
1314#include <__config>
14#include <__debug>
1515#include <__iterator/advance.h>
1616#include <__iterator/concepts.h>
1717#include <__iterator/incrementable_traits.h>
......@@ -19,7 +19,7 @@
1919#include <type_traits>
2020
2121#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22#pragma GCC system_header
22# pragma GCC system_header
2323#endif
2424
2525_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -35,7 +35,7 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
3535 return __x;
3636}
3737
38#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
38#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
3939
4040// [range.iter.op.next]
4141
......@@ -58,16 +58,14 @@ struct __fn {
5858 }
5959
6060 template <input_or_output_iterator _Ip, sentinel_for<_Ip> _Sp>
61 _LIBCPP_HIDE_FROM_ABI
62 constexpr _Ip operator()(_Ip __x, _Sp __bound) const {
63 ranges::advance(__x, __bound);
61 _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x, _Sp __bound_sentinel) const {
62 ranges::advance(__x, __bound_sentinel);
6463 return __x;
6564 }
6665
6766 template <input_or_output_iterator _Ip, sentinel_for<_Ip> _Sp>
68 _LIBCPP_HIDE_FROM_ABI
69 constexpr _Ip operator()(_Ip __x, iter_difference_t<_Ip> __n, _Sp __bound) const {
70 ranges::advance(__x, __n, __bound);
67 _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x, iter_difference_t<_Ip> __n, _Sp __bound_sentinel) const {
68 ranges::advance(__x, __n, __bound_sentinel);
7169 return __x;
7270 }
7371};
......@@ -79,7 +77,7 @@ inline namespace __cpo {
7977} // namespace __cpo
8078} // namespace ranges
8179
82#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
80#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
8381
8482_LIBCPP_END_NAMESPACE_STD
8583
lib/libcxx/include/__iterator/ostream_iterator.h+4-3
......@@ -14,10 +14,11 @@
1414#include <__iterator/iterator.h>
1515#include <__iterator/iterator_traits.h>
1616#include <__memory/addressof.h>
17#include <cstddef>
1718#include <iosfwd> // for forward declarations of char_traits and basic_ostream
1819
1920#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20#pragma GCC system_header
21# pragma GCC system_header
2122#endif
2223
2324_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -52,9 +53,9 @@ public:
5253 : __out_stream_(_VSTD::addressof(__s)), __delim_(nullptr) {}
5354 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT
5455 : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {}
55 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
56 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value)
5657 {
57 *__out_stream_ << __value_;
58 *__out_stream_ << __value;
5859 if (__delim_)
5960 *__out_stream_ << __delim_;
6061 return *this;
lib/libcxx/include/__iterator/ostreambuf_iterator.h+2-1
......@@ -13,10 +13,11 @@
1313#include <__config>
1414#include <__iterator/iterator.h>
1515#include <__iterator/iterator_traits.h>
16#include <cstddef>
1617#include <iosfwd> // for forward declaration of basic_streambuf
1718
1819#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
20# pragma GCC system_header
2021#endif
2122
2223_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__iterator/permutable.h created+35
......@@ -0,0 +1,35 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___ITERATOR_PERMUTABLE_H
11#define _LIBCPP___ITERATOR_PERMUTABLE_H
12
13#include <__config>
14#include <__iterator/concepts.h>
15#include <__iterator/iter_swap.h>
16
17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18# pragma GCC system_header
19#endif
20
21_LIBCPP_BEGIN_NAMESPACE_STD
22
23#if _LIBCPP_STD_VER > 17
24
25template <class _Iterator>
26concept permutable =
27 forward_iterator<_Iterator> &&
28 indirectly_movable_storable<_Iterator, _Iterator> &&
29 indirectly_swappable<_Iterator, _Iterator>;
30
31#endif // _LIBCPP_STD_VER > 17
32
33_LIBCPP_END_NAMESPACE_STD
34
35#endif // _LIBCPP___ITERATOR_PERMUTABLE_H
lib/libcxx/include/__iterator/prev.h+6-7
......@@ -10,8 +10,8 @@
1010#ifndef _LIBCPP___ITERATOR_PREV_H
1111#define _LIBCPP___ITERATOR_PREV_H
1212
13#include <__assert>
1314#include <__config>
14#include <__debug>
1515#include <__iterator/advance.h>
1616#include <__iterator/concepts.h>
1717#include <__iterator/incrementable_traits.h>
......@@ -19,7 +19,7 @@
1919#include <type_traits>
2020
2121#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22#pragma GCC system_header
22# pragma GCC system_header
2323#endif
2424
2525_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -34,7 +34,7 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
3434 return __x;
3535}
3636
37#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
37#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
3838
3939// [range.iter.op.prev]
4040
......@@ -57,9 +57,8 @@ struct __fn {
5757 }
5858
5959 template <bidirectional_iterator _Ip>
60 _LIBCPP_HIDE_FROM_ABI
61 constexpr _Ip operator()(_Ip __x, iter_difference_t<_Ip> __n, _Ip __bound) const {
62 ranges::advance(__x, -__n, __bound);
60 _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x, iter_difference_t<_Ip> __n, _Ip __bound_iter) const {
61 ranges::advance(__x, -__n, __bound_iter);
6362 return __x;
6463 }
6564};
......@@ -71,7 +70,7 @@ inline namespace __cpo {
7170} // namespace __cpo
7271} // namespace ranges
7372
74#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
73#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
7574
7675_LIBCPP_END_NAMESPACE_STD
7776
lib/libcxx/include/__iterator/projected.h+3-3
......@@ -15,12 +15,12 @@
1515#include <type_traits>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
2222
23#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
23#if _LIBCPP_STD_VER > 17
2424
2525template<indirectly_readable _It, indirectly_regular_unary_invocable<_It> _Proj>
2626struct projected {
......@@ -33,7 +33,7 @@ struct incrementable_traits<projected<_It, _Proj>> {
3333 using difference_type = iter_difference_t<_It>;
3434};
3535
36#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
36#endif // _LIBCPP_STD_VER > 17
3737
3838_LIBCPP_END_NAMESPACE_STD
3939
lib/libcxx/include/__iterator/readable_traits.h+3-3
......@@ -15,12 +15,12 @@
1515#include <type_traits>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
2222
23#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
23#if _LIBCPP_STD_VER > 17
2424
2525// [readable.traits]
2626template<class> struct __cond_value_type {};
......@@ -79,7 +79,7 @@ using iter_value_t = typename conditional_t<__is_primary_template<iterator_trait
7979 indirectly_readable_traits<remove_cvref_t<_Ip> >,
8080 iterator_traits<remove_cvref_t<_Ip> > >::value_type;
8181
82#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
82#endif // _LIBCPP_STD_VER > 17
8383
8484_LIBCPP_END_NAMESPACE_STD
8585
lib/libcxx/include/__iterator/reverse_access.h+2-6
......@@ -16,13 +16,11 @@
1616#include <initializer_list>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
19# pragma GCC system_header
2020#endif
2121
2222_LIBCPP_BEGIN_NAMESPACE_STD
2323
24#if !defined(_LIBCPP_CXX03_LANG)
25
2624#if _LIBCPP_STD_VER > 11
2725
2826template <class _Tp, size_t _Np>
......@@ -95,9 +93,7 @@ auto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c))
9593 return _VSTD::rend(__c);
9694}
9795
98#endif
99
100#endif // !defined(_LIBCPP_CXX03_LANG)
96#endif // _LIBCPP_STD_VER > 11
10197
10298_LIBCPP_END_NAMESPACE_STD
10399
lib/libcxx/include/__iterator/reverse_iterator.h+311-20
......@@ -10,16 +10,30 @@
1010#ifndef _LIBCPP___ITERATOR_REVERSE_ITERATOR_H
1111#define _LIBCPP___ITERATOR_REVERSE_ITERATOR_H
1212
13#include <__algorithm/unwrap_iter.h>
1314#include <__compare/compare_three_way_result.h>
1415#include <__compare/three_way_comparable.h>
16#include <__concepts/convertible_to.h>
1517#include <__config>
18#include <__iterator/advance.h>
19#include <__iterator/concepts.h>
20#include <__iterator/incrementable_traits.h>
21#include <__iterator/iter_move.h>
22#include <__iterator/iter_swap.h>
1623#include <__iterator/iterator.h>
1724#include <__iterator/iterator_traits.h>
25#include <__iterator/next.h>
26#include <__iterator/prev.h>
27#include <__iterator/readable_traits.h>
1828#include <__memory/addressof.h>
29#include <__ranges/access.h>
30#include <__ranges/concepts.h>
31#include <__ranges/subrange.h>
32#include <__utility/move.h>
1933#include <type_traits>
2034
2135#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22#pragma GCC system_header
36# pragma GCC system_header
2337#endif
2438
2539_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -41,22 +55,29 @@ private:
4155 _Iter __t; // no longer used as of LWG #2360, not removed due to ABI break
4256#endif
4357
58#if _LIBCPP_STD_VER > 17
59 static_assert(__is_cpp17_bidirectional_iterator<_Iter>::value || bidirectional_iterator<_Iter>,
60 "reverse_iterator<It> requires It to be a bidirectional iterator.");
61#endif // _LIBCPP_STD_VER > 17
62
4463protected:
4564 _Iter current;
4665public:
47 typedef _Iter iterator_type;
48 typedef typename iterator_traits<_Iter>::difference_type difference_type;
49 typedef typename iterator_traits<_Iter>::reference reference;
50 typedef typename iterator_traits<_Iter>::pointer pointer;
51 typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
52 random_access_iterator_tag,
53 typename iterator_traits<_Iter>::iterator_category> iterator_category;
54 typedef typename iterator_traits<_Iter>::value_type value_type;
66 using iterator_type = _Iter;
5567
68 using iterator_category = _If<__is_cpp17_random_access_iterator<_Iter>::value,
69 random_access_iterator_tag,
70 typename iterator_traits<_Iter>::iterator_category>;
71 using pointer = typename iterator_traits<_Iter>::pointer;
5672#if _LIBCPP_STD_VER > 17
57 typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
58 random_access_iterator_tag,
59 bidirectional_iterator_tag> iterator_concept;
73 using iterator_concept = _If<random_access_iterator<_Iter>, random_access_iterator_tag, bidirectional_iterator_tag>;
74 using value_type = iter_value_t<_Iter>;
75 using difference_type = iter_difference_t<_Iter>;
76 using reference = iter_reference_t<_Iter>;
77#else
78 using value_type = typename iterator_traits<_Iter>::value_type;
79 using difference_type = typename iterator_traits<_Iter>::difference_type;
80 using reference = typename iterator_traits<_Iter>::reference;
6081#endif
6182
6283#ifndef _LIBCPP_ABI_NO_ITERATOR_BASES
......@@ -114,32 +135,81 @@ public:
114135 _Iter base() const {return current;}
115136 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
116137 reference operator*() const {_Iter __tmp = current; return *--__tmp;}
138
139#if _LIBCPP_STD_VER > 17
140 _LIBCPP_INLINE_VISIBILITY
141 constexpr pointer operator->() const
142 requires is_pointer_v<_Iter> || requires(const _Iter __i) { __i.operator->(); }
143 {
144 if constexpr (is_pointer_v<_Iter>) {
145 return std::prev(current);
146 } else {
147 return std::prev(current).operator->();
148 }
149 }
150#else
117151 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
118 pointer operator->() const {return _VSTD::addressof(operator*());}
152 pointer operator->() const {
153 return std::addressof(operator*());
154 }
155#endif // _LIBCPP_STD_VER > 17
156
119157 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
120158 reverse_iterator& operator++() {--current; return *this;}
121159 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
122 reverse_iterator operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;}
160 reverse_iterator operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;}
123161 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
124162 reverse_iterator& operator--() {++current; return *this;}
125163 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
126 reverse_iterator operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;}
164 reverse_iterator operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;}
127165 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
128 reverse_iterator operator+ (difference_type __n) const {return reverse_iterator(current - __n);}
166 reverse_iterator operator+(difference_type __n) const {return reverse_iterator(current - __n);}
129167 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
130168 reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;}
131169 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
132 reverse_iterator operator- (difference_type __n) const {return reverse_iterator(current + __n);}
170 reverse_iterator operator-(difference_type __n) const {return reverse_iterator(current + __n);}
133171 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
134172 reverse_iterator& operator-=(difference_type __n) {current += __n; return *this;}
135173 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
136 reference operator[](difference_type __n) const {return *(*this + __n);}
174 reference operator[](difference_type __n) const {return *(*this + __n);}
175
176#if _LIBCPP_STD_VER > 17
177 _LIBCPP_HIDE_FROM_ABI friend constexpr
178 iter_rvalue_reference_t<_Iter> iter_move(const reverse_iterator& __i)
179 noexcept(is_nothrow_copy_constructible_v<_Iter> &&
180 noexcept(ranges::iter_move(--declval<_Iter&>()))) {
181 auto __tmp = __i.base();
182 return ranges::iter_move(--__tmp);
183 }
184
185 template <indirectly_swappable<_Iter> _Iter2>
186 _LIBCPP_HIDE_FROM_ABI friend constexpr
187 void iter_swap(const reverse_iterator& __x, const reverse_iterator<_Iter2>& __y)
188 noexcept(is_nothrow_copy_constructible_v<_Iter> &&
189 is_nothrow_copy_constructible_v<_Iter2> &&
190 noexcept(ranges::iter_swap(--declval<_Iter&>(), --declval<_Iter2&>()))) {
191 auto __xtmp = __x.base();
192 auto __ytmp = __y.base();
193 ranges::iter_swap(--__xtmp, --__ytmp);
194 }
195#endif // _LIBCPP_STD_VER > 17
137196};
138197
198template <class _Iter>
199struct __is_reverse_iterator : false_type {};
200
201template <class _Iter>
202struct __is_reverse_iterator<reverse_iterator<_Iter> > : true_type {};
203
139204template <class _Iter1, class _Iter2>
140205inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
141206bool
142207operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
208#if _LIBCPP_STD_VER > 17
209 requires requires {
210 { __x.base() == __y.base() } -> convertible_to<bool>;
211 }
212#endif // _LIBCPP_STD_VER > 17
143213{
144214 return __x.base() == __y.base();
145215}
......@@ -148,6 +218,11 @@ template <class _Iter1, class _Iter2>
148218inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
149219bool
150220operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
221#if _LIBCPP_STD_VER > 17
222 requires requires {
223 { __x.base() > __y.base() } -> convertible_to<bool>;
224 }
225#endif // _LIBCPP_STD_VER > 17
151226{
152227 return __x.base() > __y.base();
153228}
......@@ -156,6 +231,11 @@ template <class _Iter1, class _Iter2>
156231inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
157232bool
158233operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
234#if _LIBCPP_STD_VER > 17
235 requires requires {
236 { __x.base() != __y.base() } -> convertible_to<bool>;
237 }
238#endif // _LIBCPP_STD_VER > 17
159239{
160240 return __x.base() != __y.base();
161241}
......@@ -164,6 +244,11 @@ template <class _Iter1, class _Iter2>
164244inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
165245bool
166246operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
247#if _LIBCPP_STD_VER > 17
248 requires requires {
249 { __x.base() < __y.base() } -> convertible_to<bool>;
250 }
251#endif // _LIBCPP_STD_VER > 17
167252{
168253 return __x.base() < __y.base();
169254}
......@@ -172,6 +257,11 @@ template <class _Iter1, class _Iter2>
172257inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
173258bool
174259operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
260#if _LIBCPP_STD_VER > 17
261 requires requires {
262 { __x.base() <= __y.base() } -> convertible_to<bool>;
263 }
264#endif // _LIBCPP_STD_VER > 17
175265{
176266 return __x.base() <= __y.base();
177267}
......@@ -180,11 +270,16 @@ template <class _Iter1, class _Iter2>
180270inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
181271bool
182272operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
273#if _LIBCPP_STD_VER > 17
274 requires requires {
275 { __x.base() >= __y.base() } -> convertible_to<bool>;
276 }
277#endif // _LIBCPP_STD_VER > 17
183278{
184279 return __x.base() >= __y.base();
185280}
186281
187#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
282#if _LIBCPP_STD_VER > 17
188283template <class _Iter1, three_way_comparable_with<_Iter1> _Iter2>
189284_LIBCPP_HIDE_FROM_ABI constexpr
190285compare_three_way_result_t<_Iter1, _Iter2>
......@@ -192,7 +287,7 @@ operator<=>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>&
192287{
193288 return __y.base() <=> __x.base();
194289}
195#endif
290#endif // _LIBCPP_STD_VER > 17
196291
197292#ifndef _LIBCPP_CXX03_LANG
198293template <class _Iter1, class _Iter2>
......@@ -221,6 +316,12 @@ operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_i
221316 return reverse_iterator<_Iter>(__x.base() - __n);
222317}
223318
319#if _LIBCPP_STD_VER > 17
320template <class _Iter1, class _Iter2>
321 requires (!sized_sentinel_for<_Iter1, _Iter2>)
322inline constexpr bool disable_sized_sentinel_for<reverse_iterator<_Iter1>, reverse_iterator<_Iter2>> = true;
323#endif // _LIBCPP_STD_VER > 17
324
224325#if _LIBCPP_STD_VER > 11
225326template <class _Iter>
226327inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
......@@ -230,6 +331,196 @@ reverse_iterator<_Iter> make_reverse_iterator(_Iter __i)
230331}
231332#endif
232333
334#if _LIBCPP_STD_VER <= 17
335template <class _Iter>
336using __unconstrained_reverse_iterator = reverse_iterator<_Iter>;
337#else
338
339// __unconstrained_reverse_iterator allows us to use reverse iterators in the implementation of algorithms by working
340// around a language issue in C++20.
341// In C++20, when a reverse iterator wraps certain C++20-hostile iterators, calling comparison operators on it will
342// result in a compilation error. However, calling comparison operators on the pristine hostile iterator is not
343// an error. Thus, we cannot use reverse_iterators in the implementation of an algorithm that accepts a
344// C++20-hostile iterator. This class is an internal workaround -- it is a copy of reverse_iterator with
345// tweaks to make it support hostile iterators.
346//
347// A C++20-hostile iterator is one that defines a comparison operator where one of the arguments is an exact match
348// and the other requires an implicit conversion, for example:
349// friend bool operator==(const BaseIter&, const DerivedIter&);
350//
351// C++20 rules for rewriting equality operators create another overload of this function with parameters reversed:
352// friend bool operator==(const DerivedIter&, const BaseIter&);
353//
354// This creates an ambiguity in overload resolution.
355//
356// Clang treats this ambiguity differently in different contexts. When operator== is actually called in the function
357// body, the code is accepted with a warning. When a concept requires operator== to be a valid expression, however,
358// it evaluates to false. Thus, the implementation of reverse_iterator::operator== can actually call operator== on its
359// base iterators, but the constraints on reverse_iterator::operator== prevent it from being considered during overload
360// resolution. This class simply removes the problematic constraints from comparison functions.
361template <class _Iter>
362class __unconstrained_reverse_iterator {
363 _Iter __iter_;
364
365public:
366 static_assert(__is_cpp17_bidirectional_iterator<_Iter>::value);
367
368 using iterator_type = _Iter;
369 using iterator_category =
370 _If<__is_cpp17_random_access_iterator<_Iter>::value, random_access_iterator_tag, __iterator_category_type<_Iter>>;
371 using pointer = __iterator_pointer_type<_Iter>;
372 using value_type = iter_value_t<_Iter>;
373 using difference_type = iter_difference_t<_Iter>;
374 using reference = iter_reference_t<_Iter>;
375
376 _LIBCPP_HIDE_FROM_ABI constexpr __unconstrained_reverse_iterator() = default;
377 _LIBCPP_HIDE_FROM_ABI constexpr __unconstrained_reverse_iterator(const __unconstrained_reverse_iterator&) = default;
378 _LIBCPP_HIDE_FROM_ABI constexpr explicit __unconstrained_reverse_iterator(_Iter __iter) : __iter_(__iter) {}
379
380 _LIBCPP_HIDE_FROM_ABI constexpr _Iter base() const { return __iter_; }
381 _LIBCPP_HIDE_FROM_ABI constexpr reference operator*() const {
382 auto __tmp = __iter_;
383 return *--__tmp;
384 }
385
386 _LIBCPP_HIDE_FROM_ABI constexpr pointer operator->() const {
387 if constexpr (is_pointer_v<_Iter>) {
388 return std::prev(__iter_);
389 } else {
390 return std::prev(__iter_).operator->();
391 }
392 }
393
394 _LIBCPP_HIDE_FROM_ABI constexpr __unconstrained_reverse_iterator& operator++() {
395 --__iter_;
396 return *this;
397 }
398
399 _LIBCPP_HIDE_FROM_ABI constexpr __unconstrained_reverse_iterator operator++(int) {
400 auto __tmp = *this;
401 --__iter_;
402 return __tmp;
403 }
404
405 _LIBCPP_HIDE_FROM_ABI constexpr __unconstrained_reverse_iterator& operator--() {
406 ++__iter_;
407 return *this;
408 }
409
410 _LIBCPP_HIDE_FROM_ABI constexpr __unconstrained_reverse_iterator operator--(int) {
411 auto __tmp = *this;
412 ++__iter_;
413 return __tmp;
414 }
415
416 _LIBCPP_HIDE_FROM_ABI constexpr __unconstrained_reverse_iterator& operator+=(difference_type __n) {
417 __iter_ -= __n;
418 return *this;
419 }
420
421 _LIBCPP_HIDE_FROM_ABI constexpr __unconstrained_reverse_iterator& operator-=(difference_type __n) {
422 __iter_ += __n;
423 return *this;
424 }
425
426 _LIBCPP_HIDE_FROM_ABI constexpr __unconstrained_reverse_iterator operator+(difference_type __n) const {
427 return __unconstrained_reverse_iterator(__iter_ - __n);
428 }
429
430 _LIBCPP_HIDE_FROM_ABI constexpr __unconstrained_reverse_iterator operator-(difference_type __n) const {
431 return __unconstrained_reverse_iterator(__iter_ + __n);
432 }
433
434 _LIBCPP_HIDE_FROM_ABI constexpr difference_type operator-(const __unconstrained_reverse_iterator& __other) const {
435 return __other.__iter_ - __iter_;
436 }
437
438 _LIBCPP_HIDE_FROM_ABI constexpr auto operator[](difference_type __n) const { return *(*this + __n); }
439
440 // Deliberately unconstrained unlike the comparison functions in `reverse_iterator` -- see the class comment for the
441 // rationale.
442 _LIBCPP_HIDE_FROM_ABI friend constexpr bool
443 operator==(const __unconstrained_reverse_iterator& __lhs, const __unconstrained_reverse_iterator& __rhs) {
444 return __lhs.base() == __rhs.base();
445 }
446
447 _LIBCPP_HIDE_FROM_ABI friend constexpr bool
448 operator!=(const __unconstrained_reverse_iterator& __lhs, const __unconstrained_reverse_iterator& __rhs) {
449 return __lhs.base() != __rhs.base();
450 }
451
452 _LIBCPP_HIDE_FROM_ABI friend constexpr bool
453 operator<(const __unconstrained_reverse_iterator& __lhs, const __unconstrained_reverse_iterator& __rhs) {
454 return __lhs.base() > __rhs.base();
455 }
456
457 _LIBCPP_HIDE_FROM_ABI friend constexpr bool
458 operator>(const __unconstrained_reverse_iterator& __lhs, const __unconstrained_reverse_iterator& __rhs) {
459 return __lhs.base() < __rhs.base();
460 }
461
462 _LIBCPP_HIDE_FROM_ABI friend constexpr bool
463 operator<=(const __unconstrained_reverse_iterator& __lhs, const __unconstrained_reverse_iterator& __rhs) {
464 return __lhs.base() >= __rhs.base();
465 }
466
467 _LIBCPP_HIDE_FROM_ABI friend constexpr bool
468 operator>=(const __unconstrained_reverse_iterator& __lhs, const __unconstrained_reverse_iterator& __rhs) {
469 return __lhs.base() <= __rhs.base();
470 }
471};
472
473template <class _Iter>
474struct __is_reverse_iterator<__unconstrained_reverse_iterator<_Iter>> : true_type {};
475
476#endif // _LIBCPP_STD_VER <= 17
477
478template <template <class> class _RevIter1, template <class> class _RevIter2, class _Iter>
479struct __unwrap_reverse_iter_impl {
480 using _UnwrappedIter = decltype(__unwrap_iter_impl<_Iter>::__unwrap(std::declval<_Iter>()));
481 using _ReverseWrapper = _RevIter1<_RevIter2<_Iter> >;
482
483 static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ReverseWrapper
484 __rewrap(_ReverseWrapper __orig_iter, _UnwrappedIter __unwrapped_iter) {
485 return _ReverseWrapper(
486 _RevIter2<_Iter>(__unwrap_iter_impl<_Iter>::__rewrap(__orig_iter.base().base(), __unwrapped_iter)));
487 }
488
489 static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _UnwrappedIter __unwrap(_ReverseWrapper __i) _NOEXCEPT {
490 return __unwrap_iter_impl<_Iter>::__unwrap(__i.base().base());
491 }
492};
493
494#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
495template <ranges::bidirectional_range _Range>
496_LIBCPP_HIDE_FROM_ABI constexpr ranges::
497 subrange<reverse_iterator<ranges::iterator_t<_Range>>, reverse_iterator<ranges::iterator_t<_Range>>>
498 __reverse_range(_Range&& __range) {
499 auto __first = ranges::begin(__range);
500 return {std::make_reverse_iterator(ranges::next(__first, ranges::end(__range))), std::make_reverse_iterator(__first)};
501}
502#endif
503
504template <class _Iter, bool __b>
505struct __unwrap_iter_impl<reverse_iterator<reverse_iterator<_Iter> >, __b>
506 : __unwrap_reverse_iter_impl<reverse_iterator, reverse_iterator, _Iter> {};
507
508#if _LIBCPP_STD_VER > 17
509
510template <class _Iter, bool __b>
511struct __unwrap_iter_impl<reverse_iterator<__unconstrained_reverse_iterator<_Iter>>, __b>
512 : __unwrap_reverse_iter_impl<reverse_iterator, __unconstrained_reverse_iterator, _Iter> {};
513
514template <class _Iter, bool __b>
515struct __unwrap_iter_impl<__unconstrained_reverse_iterator<reverse_iterator<_Iter>>, __b>
516 : __unwrap_reverse_iter_impl<__unconstrained_reverse_iterator, reverse_iterator, _Iter> {};
517
518template <class _Iter, bool __b>
519struct __unwrap_iter_impl<__unconstrained_reverse_iterator<__unconstrained_reverse_iterator<_Iter>>, __b>
520 : __unwrap_reverse_iter_impl<__unconstrained_reverse_iterator, __unconstrained_reverse_iterator, _Iter> {};
521
522#endif // _LIBCPP_STD_VER > 17
523
233524_LIBCPP_END_NAMESPACE_STD
234525
235526#endif // _LIBCPP___ITERATOR_REVERSE_ITERATOR_H
lib/libcxx/include/__iterator/size.h+6-1
......@@ -15,7 +15,7 @@
1515#include <type_traits>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -41,9 +41,14 @@ _NOEXCEPT_(noexcept(static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(
4141-> common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>
4242{ return static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size()); }
4343
44// GCC complains about the implicit conversion from ptrdiff_t to size_t in
45// the array bound.
46_LIBCPP_DIAGNOSTIC_PUSH
47_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wsign-conversion")
4448template <class _Tp, ptrdiff_t _Sz>
4549_LIBCPP_INLINE_VISIBILITY
4650constexpr ptrdiff_t ssize(const _Tp (&)[_Sz]) noexcept { return _Sz; }
51_LIBCPP_DIAGNOSTIC_POP
4752#endif
4853
4954#endif // _LIBCPP_STD_VER > 14
lib/libcxx/include/__iterator/sortable.h created+37
......@@ -0,0 +1,37 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___ITERATOR_SORTABLE_H
11#define _LIBCPP___ITERATOR_SORTABLE_H
12
13#include <__config>
14#include <__functional/identity.h>
15#include <__functional/ranges_operations.h>
16#include <__iterator/concepts.h>
17#include <__iterator/permutable.h>
18#include <__iterator/projected.h>
19
20#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21# pragma GCC system_header
22#endif
23
24_LIBCPP_BEGIN_NAMESPACE_STD
25
26#if _LIBCPP_STD_VER > 17
27
28template <class _Iter, class _Comp = ranges::less, class _Proj = identity>
29concept sortable =
30 permutable<_Iter> &&
31 indirect_strict_weak_order<_Comp, projected<_Iter, _Proj>>;
32
33#endif // _LIBCPP_STD_VER > 17
34
35_LIBCPP_END_NAMESPACE_STD
36
37#endif // _LIBCPP___ITERATOR_SORTABLE_H
lib/libcxx/include/__iterator/unreachable_sentinel.h+3-3
......@@ -14,12 +14,12 @@
1414#include <__iterator/concepts.h>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
17# pragma GCC system_header
1818#endif
1919
2020_LIBCPP_BEGIN_NAMESPACE_STD
2121
22#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
22#if _LIBCPP_STD_VER > 17
2323
2424struct unreachable_sentinel_t {
2525 template<weakly_incrementable _Iter>
......@@ -31,7 +31,7 @@ struct unreachable_sentinel_t {
3131
3232inline constexpr unreachable_sentinel_t unreachable_sentinel{};
3333
34#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
34#endif // _LIBCPP_STD_VER > 17
3535
3636_LIBCPP_END_NAMESPACE_STD
3737
lib/libcxx/include/__iterator/wrap_iter.h+8-8
......@@ -18,7 +18,7 @@
1818#include <type_traits>
1919
2020#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21#pragma GCC system_header
21# pragma GCC system_header
2222#endif
2323
2424_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -50,12 +50,12 @@ public:
5050 typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = nullptr) _NOEXCEPT
5151 : __i(__u.base())
5252 {
53#if _LIBCPP_DEBUG_LEVEL == 2
53#ifdef _LIBCPP_ENABLE_DEBUG_MODE
5454 if (!__libcpp_is_constant_evaluated())
5555 __get_db()->__iterator_copy(this, _VSTD::addressof(__u));
5656#endif
5757 }
58#if _LIBCPP_DEBUG_LEVEL == 2
58#ifdef _LIBCPP_ENABLE_DEBUG_MODE
5959 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
6060 __wrap_iter(const __wrap_iter& __x)
6161 : __i(__x.base())
......@@ -135,15 +135,15 @@ public:
135135 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 iterator_type base() const _NOEXCEPT {return __i;}
136136
137137private:
138#if _LIBCPP_DEBUG_LEVEL == 2
139 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
138 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
139 explicit __wrap_iter(const void* __p, iterator_type __x) _NOEXCEPT : __i(__x)
140140 {
141 (void)__p;
142#ifdef _LIBCPP_ENABLE_DEBUG_MODE
141143 if (!__libcpp_is_constant_evaluated())
142144 __get_db()->__insert_ic(this, __p);
143 }
144#else
145 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
146145#endif
146 }
147147
148148 template <class _Up> friend class __wrap_iter;
149149 template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
lib/libcxx/include/__libcpp_version deleted-1
......@@ -1 +0,0 @@
114000
lib/libcxx/include/__locale+17-17
......@@ -18,24 +18,22 @@
1818#include <memory>
1919#include <mutex>
2020#include <string>
21#include <utility>
2221
2322#if defined(_LIBCPP_MSVCRT_LIKE)
24# include <cstring>
2523# include <__support/win32/locale_win32.h>
24# include <cstring>
2625#elif defined(_AIX) || defined(__MVS__)
2726# include <__support/ibm/xlocale.h>
2827#elif defined(__ANDROID__)
2928# include <__support/android/locale_bionic.h>
3029#elif defined(__sun__)
31# include <xlocale.h>
3230# include <__support/solaris/xlocale.h>
31# include <xlocale.h>
3332#elif defined(_NEWLIB_VERSION)
3433# include <__support/newlib/xlocale.h>
3534#elif defined(__OpenBSD__)
3635# include <__support/openbsd/xlocale.h>
37#elif (defined(__APPLE__) || defined(__FreeBSD__) \
38 || defined(__EMSCRIPTEN__) || defined(__IBMCPP__))
36#elif (defined(__APPLE__) || defined(__FreeBSD__))
3937# include <xlocale.h>
4038#elif defined(__Fuchsia__)
4139# include <__support/fuchsia/xlocale.h>
......@@ -47,7 +45,7 @@
4745#endif
4846
4947#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
50#pragma GCC system_header
48# pragma GCC system_header
5149#endif
5250
5351_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -339,9 +337,9 @@ collate<_CharT>::do_hash(const char_type* __lo, const char_type* __hi) const
339337 return static_cast<long>(__h);
340338}
341339
342_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<char>)
340extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<char>;
343341#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
344_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<wchar_t>)
342extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<wchar_t>;
345343#endif
346344
347345// template <class CharT> class collate_byname;
......@@ -454,6 +452,7 @@ public:
454452 static const mask blank = _BLANK;
455453 static const mask __regex_word = 0x4000; // 0x8000 and 0x0100 and 0x00ff are used
456454# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
455# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA
457456#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__)
458457# ifdef __APPLE__
459458 typedef __uint32_t mask;
......@@ -493,7 +492,11 @@ public:
493492 static const mask punct = _ISPUNCT;
494493 static const mask xdigit = _ISXDIGIT;
495494 static const mask blank = _ISBLANK;
495# if defined(_AIX)
496 static const mask __regex_word = 0x8000;
497# else
496498 static const mask __regex_word = 0x80;
499# endif
497500#elif defined(_NEWLIB_VERSION)
498501 // Same type as Newlib's _ctype_ array in newlib/libc/include/ctype.h.
499502 typedef char mask;
......@@ -546,11 +549,8 @@ public:
546549
547550 _LIBCPP_INLINE_VISIBILITY ctype_base() {}
548551
549// TODO: Remove the ifndef when the assert no longer fails on AIX.
550#ifndef _AIX
551552 static_assert((__regex_word & ~(space | print | cntrl | upper | lower | alpha | digit | punct | xdigit | blank)) == __regex_word,
552553 "__regex_word can't overlap other bits");
553#endif
554554};
555555
556556template <class _CharT> class _LIBCPP_TEMPLATE_VIS ctype;
......@@ -1498,15 +1498,15 @@ codecvt_byname<_InternT, _ExternT, _StateT>::~codecvt_byname()
14981498}
14991499_LIBCPP_SUPPRESS_DEPRECATED_POP
15001500
1501_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char, char, mbstate_t>)
1501extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char, char, mbstate_t>;
15021502#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1503_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<wchar_t, char, mbstate_t>)
1503extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<wchar_t, char, mbstate_t>;
15041504#endif
1505_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char, mbstate_t>) // deprecated in C++20
1506_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char32_t, char, mbstate_t>) // deprecated in C++20
1505extern template class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char, mbstate_t>; // deprecated in C++20
1506extern template class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char32_t, char, mbstate_t>; // deprecated in C++20
15071507#ifndef _LIBCPP_HAS_NO_CHAR8_T
1508_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char8_t, mbstate_t>) // C++20
1509_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char32_t, char8_t, mbstate_t>) // C++20
1508extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char8_t, mbstate_t>; // C++20
1509extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char32_t, char8_t, mbstate_t>; // C++20
15101510#endif
15111511
15121512template <size_t _Np>
lib/libcxx/include/__mbstate_t.h+1-1
......@@ -13,7 +13,7 @@
1313#include <__config>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16#pragma GCC system_header
16# pragma GCC system_header
1717#endif
1818
1919// TODO(ldionne):
lib/libcxx/include/__memory/addressof.h+1-1
......@@ -13,7 +13,7 @@
1313#include <__config>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16#pragma GCC system_header
16# pragma GCC system_header
1717#endif
1818
1919_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__memory/allocate_at_least.h created+61
......@@ -0,0 +1,61 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___MEMORY_ALLOCATE_AT_LEAST_H
10#define _LIBCPP___MEMORY_ALLOCATE_AT_LEAST_H
11
12#include <__config>
13#include <__memory/allocator_traits.h>
14#include <cstddef>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
20_LIBCPP_BEGIN_NAMESPACE_STD
21
22#if _LIBCPP_STD_VER > 20
23template <class _Pointer>
24struct allocation_result {
25 _Pointer ptr;
26 size_t count;
27};
28
29template <class _Alloc>
30[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr
31allocation_result<typename allocator_traits<_Alloc>::pointer> allocate_at_least(_Alloc& __alloc, size_t __n) {
32 if constexpr (requires { __alloc.allocate_at_least(__n); }) {
33 return __alloc.allocate_at_least(__n);
34 } else {
35 return {__alloc.allocate(__n), __n};
36 }
37}
38
39template <class _Alloc>
40[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr
41auto __allocate_at_least(_Alloc& __alloc, size_t __n) {
42 return std::allocate_at_least(__alloc, __n);
43}
44#else
45template <class _Pointer>
46struct __allocation_result {
47 _Pointer ptr;
48 size_t count;
49};
50
51template <class _Alloc>
52_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
53__allocation_result<typename allocator_traits<_Alloc>::pointer> __allocate_at_least(_Alloc& __alloc, size_t __n) {
54 return {__alloc.allocate(__n), __n};
55}
56
57#endif // _LIBCPP_STD_VER > 20
58
59_LIBCPP_END_NAMESPACE_STD
60
61#endif // _LIBCPP___MEMORY_ALLOCATE_AT_LEAST_H
lib/libcxx/include/__memory/allocation_guard.h+2-2
......@@ -12,11 +12,11 @@
1212
1313#include <__config>
1414#include <__memory/allocator_traits.h>
15#include <__utility/move.h>
1516#include <cstddef>
16#include <utility>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
19# pragma GCC system_header
2020#endif
2121
2222_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__memory/allocator.h+23-2
......@@ -11,6 +11,7 @@
1111#define _LIBCPP___MEMORY_ALLOCATOR_H
1212
1313#include <__config>
14#include <__memory/allocate_at_least.h>
1415#include <__memory/allocator_traits.h>
1516#include <__utility/forward.h>
1617#include <cstddef>
......@@ -19,34 +20,40 @@
1920#include <type_traits>
2021
2122#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22#pragma GCC system_header
23# pragma GCC system_header
2324#endif
2425
2526_LIBCPP_BEGIN_NAMESPACE_STD
2627
2728template <class _Tp> class allocator;
2829
29#if _LIBCPP_STD_VER <= 17
30#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_VOID_SPECIALIZATION)
31// These specializations shouldn't be marked _LIBCPP_DEPRECATED_IN_CXX17.
32// Specializing allocator<void> is deprecated, but not using it.
3033template <>
3134class _LIBCPP_TEMPLATE_VIS allocator<void>
3235{
36#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS)
3337public:
3438 _LIBCPP_DEPRECATED_IN_CXX17 typedef void* pointer;
3539 _LIBCPP_DEPRECATED_IN_CXX17 typedef const void* const_pointer;
3640 _LIBCPP_DEPRECATED_IN_CXX17 typedef void value_type;
3741
3842 template <class _Up> struct _LIBCPP_DEPRECATED_IN_CXX17 rebind {typedef allocator<_Up> other;};
43#endif
3944};
4045
4146template <>
4247class _LIBCPP_TEMPLATE_VIS allocator<const void>
4348{
49#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS)
4450public:
4551 _LIBCPP_DEPRECATED_IN_CXX17 typedef const void* pointer;
4652 _LIBCPP_DEPRECATED_IN_CXX17 typedef const void* const_pointer;
4753 _LIBCPP_DEPRECATED_IN_CXX17 typedef const void value_type;
4854
4955 template <class _Up> struct _LIBCPP_DEPRECATED_IN_CXX17 rebind {typedef allocator<_Up> other;};
56#endif
5057};
5158#endif
5259
......@@ -106,6 +113,13 @@ public:
106113 }
107114 }
108115
116#if _LIBCPP_STD_VER > 20
117 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr
118 allocation_result<_Tp*> allocate_at_least(size_t __n) {
119 return {allocate(__n), __n};
120 }
121#endif
122
109123 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
110124 void deallocate(_Tp* __p, size_t __n) _NOEXCEPT {
111125 if (__libcpp_is_constant_evaluated()) {
......@@ -188,6 +202,13 @@ public:
188202 }
189203 }
190204
205#if _LIBCPP_STD_VER > 20
206 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr
207 allocation_result<const _Tp*> allocate_at_least(size_t __n) {
208 return {allocate(__n), __n};
209 }
210#endif
211
191212 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
192213 void deallocate(const _Tp* __p, size_t __n) {
193214 if (__libcpp_is_constant_evaluated()) {
lib/libcxx/include/__memory/allocator_arg_t.h+2-2
......@@ -16,7 +16,7 @@
1616#include <type_traits>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
19# pragma GCC system_header
2020#endif
2121
2222_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -36,7 +36,7 @@ extern _LIBCPP_EXPORTED_FROM_ABI const allocator_arg_t allocator_arg;
3636template <class _Tp, class _Alloc, class ..._Args>
3737struct __uses_alloc_ctor_imp
3838{
39 typedef _LIBCPP_NODEBUG typename __uncvref<_Alloc>::type _RawAlloc;
39 typedef _LIBCPP_NODEBUG __uncvref_t<_Alloc> _RawAlloc;
4040 static const bool __ua = uses_allocator<_Tp, _RawAlloc>::value;
4141 static const bool __ic =
4242 is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>::value;
lib/libcxx/include/__memory/allocator_traits.h+1-1
......@@ -18,7 +18,7 @@
1818#include <type_traits>
1919
2020#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21#pragma GCC system_header
21# pragma GCC system_header
2222#endif
2323
2424_LIBCPP_PUSH_MACROS
lib/libcxx/include/__memory/assume_aligned.h created+46
......@@ -0,0 +1,46 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___MEMORY_ASSUME_ALIGNED_H
11#define _LIBCPP___MEMORY_ASSUME_ALIGNED_H
12
13#include <__assert>
14#include <__config>
15#include <cstddef>
16#include <cstdint>
17#include <type_traits> // for is_constant_evaluated()
18
19#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20# pragma GCC system_header
21#endif
22
23_LIBCPP_BEGIN_NAMESPACE_STD
24
25#if _LIBCPP_STD_VER > 17
26
27template <size_t _Np, class _Tp>
28[[nodiscard]]
29_LIBCPP_HIDE_FROM_ABI
30constexpr _Tp* assume_aligned(_Tp* __ptr) {
31 static_assert(_Np != 0 && (_Np & (_Np - 1)) == 0,
32 "std::assume_aligned<N>(p) requires N to be a power of two");
33
34 if (is_constant_evaluated()) {
35 return __ptr;
36 } else {
37 _LIBCPP_ASSERT(reinterpret_cast<uintptr_t>(__ptr) % _Np == 0, "Alignment assumption is violated");
38 return static_cast<_Tp*>(__builtin_assume_aligned(__ptr, _Np));
39 }
40}
41
42#endif // _LIBCPP_STD_VER > 17
43
44_LIBCPP_END_NAMESPACE_STD
45
46#endif // _LIBCPP___MEMORY_ASSUME_ALIGNED_H
lib/libcxx/include/__memory/auto_ptr.h+5-2
......@@ -11,12 +11,13 @@
1111#define _LIBCPP___MEMORY_AUTO_PTR_H
1212
1313#include <__config>
14#include <__nullptr>
1514
1615#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
16# pragma GCC system_header
1817#endif
1918
19#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
20
2021_LIBCPP_BEGIN_NAMESPACE_STD
2122
2223template <class _Tp>
......@@ -78,4 +79,6 @@ public:
7879
7980_LIBCPP_END_NAMESPACE_STD
8081
82#endif // _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
83
8184#endif // _LIBCPP___MEMORY_AUTO_PTR_H
lib/libcxx/include/__memory/compressed_pair.h+69-88
......@@ -12,12 +12,12 @@
1212
1313#include <__config>
1414#include <__utility/forward.h>
15#include <__utility/move.h>
1516#include <tuple> // needed in c++03 for some constructors
1617#include <type_traits>
17#include <utility>
1818
1919#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20#pragma GCC system_header
20# pragma GCC system_header
2121#endif
2222
2323_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -26,40 +26,28 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2626struct __default_init_tag {};
2727struct __value_init_tag {};
2828
29template <class _Tp, int _Idx,
30 bool _CanBeEmptyBase =
31 is_empty<_Tp>::value && !__libcpp_is_final<_Tp>::value>
29template <class _Tp, int _Idx, bool _CanBeEmptyBase = is_empty<_Tp>::value && !__libcpp_is_final<_Tp>::value>
3230struct __compressed_pair_elem {
33 typedef _Tp _ParamT;
34 typedef _Tp& reference;
35 typedef const _Tp& const_reference;
36
37 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
38 __compressed_pair_elem(__default_init_tag) {}
39 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
40 __compressed_pair_elem(__value_init_tag) : __value_() {}
41
42 template <class _Up, class = typename enable_if<
43 !is_same<__compressed_pair_elem, typename decay<_Up>::type>::value
44 >::type>
45 _LIBCPP_INLINE_VISIBILITY
46 _LIBCPP_CONSTEXPR explicit
47 __compressed_pair_elem(_Up&& __u)
48 : __value_(_VSTD::forward<_Up>(__u))
49 {
50 }
31 using _ParamT = _Tp;
32 using reference = _Tp&;
33 using const_reference = const _Tp&;
5134
35 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(__default_init_tag) {}
36 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(__value_init_tag) : __value_() {}
37
38 template <class _Up, class = __enable_if_t<!is_same<__compressed_pair_elem, typename decay<_Up>::type>::value> >
39 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
40 explicit __compressed_pair_elem(_Up&& __u) : __value_(std::forward<_Up>(__u)) {}
5241
5342#ifndef _LIBCPP_CXX03_LANG
54 template <class... _Args, size_t... _Indexes>
55 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
56 __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args,
57 __tuple_indices<_Indexes...>)
58 : __value_(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {}
43 template <class... _Args, size_t... _Indices>
44 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
45 explicit __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args, __tuple_indices<_Indices...>)
46 : __value_(std::forward<_Args>(std::get<_Indices>(__args))...) {}
5947#endif
6048
61 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 reference __get() _NOEXCEPT { return __value_; }
62 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __get() const _NOEXCEPT { return __value_; }
49 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 reference __get() _NOEXCEPT { return __value_; }
50 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference __get() const _NOEXCEPT { return __value_; }
6351
6452private:
6553 _Tp __value_;
......@@ -67,36 +55,28 @@ private:
6755
6856template <class _Tp, int _Idx>
6957struct __compressed_pair_elem<_Tp, _Idx, true> : private _Tp {
70 typedef _Tp _ParamT;
71 typedef _Tp& reference;
72 typedef const _Tp& const_reference;
73 typedef _Tp __value_type;
74
75 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __compressed_pair_elem() = default;
76 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
77 __compressed_pair_elem(__default_init_tag) {}
78 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
79 __compressed_pair_elem(__value_init_tag) : __value_type() {}
80
81 template <class _Up, class = typename enable_if<
82 !is_same<__compressed_pair_elem, typename decay<_Up>::type>::value
83 >::type>
84 _LIBCPP_INLINE_VISIBILITY
85 _LIBCPP_CONSTEXPR explicit
86 __compressed_pair_elem(_Up&& __u)
87 : __value_type(_VSTD::forward<_Up>(__u))
88 {}
58 using _ParamT = _Tp;
59 using reference = _Tp&;
60 using const_reference = const _Tp&;
61 using __value_type = _Tp;
62
63 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem() = default;
64 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(__default_init_tag) {}
65 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(__value_init_tag) : __value_type() {}
66
67 template <class _Up, class = __enable_if_t<!is_same<__compressed_pair_elem, typename decay<_Up>::type>::value> >
68 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
69 explicit __compressed_pair_elem(_Up&& __u) : __value_type(std::forward<_Up>(__u)) {}
8970
9071#ifndef _LIBCPP_CXX03_LANG
91 template <class... _Args, size_t... _Indexes>
92 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
93 __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args,
94 __tuple_indices<_Indexes...>)
95 : __value_type(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {}
72 template <class... _Args, size_t... _Indices>
73 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
74 __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args, __tuple_indices<_Indices...>)
75 : __value_type(std::forward<_Args>(std::get<_Indices>(__args))...) {}
9676#endif
9777
98 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 reference __get() _NOEXCEPT { return *this; }
99 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __get() const _NOEXCEPT { return *this; }
78 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 reference __get() _NOEXCEPT { return *this; }
79 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference __get() const _NOEXCEPT { return *this; }
10080};
10181
10282template <class _T1, class _T2>
......@@ -109,72 +89,73 @@ public:
10989 // object and the allocator have the same type).
11090 static_assert((!is_same<_T1, _T2>::value),
11191 "__compressed_pair cannot be instantiated when T1 and T2 are the same type; "
112 "The current implementation is NOT ABI-compatible with the previous "
113 "implementation for this configuration");
92 "The current implementation is NOT ABI-compatible with the previous implementation for this configuration");
11493
115 typedef _LIBCPP_NODEBUG __compressed_pair_elem<_T1, 0> _Base1;
116 typedef _LIBCPP_NODEBUG __compressed_pair_elem<_T2, 1> _Base2;
94 using _Base1 _LIBCPP_NODEBUG = __compressed_pair_elem<_T1, 0>;
95 using _Base2 _LIBCPP_NODEBUG = __compressed_pair_elem<_T2, 1>;
11796
118 template <bool _Dummy = true,
119 class = typename enable_if<
120 __dependent_type<is_default_constructible<_T1>, _Dummy>::value &&
121 __dependent_type<is_default_constructible<_T2>, _Dummy>::value
122 >::type
97 template <bool _Dummy = true,
98 class = __enable_if_t<
99 __dependent_type<is_default_constructible<_T1>, _Dummy>::value &&
100 __dependent_type<is_default_constructible<_T2>, _Dummy>::value
101 >
123102 >
124 _LIBCPP_INLINE_VISIBILITY
125 _LIBCPP_CONSTEXPR __compressed_pair() : _Base1(__value_init_tag()), _Base2(__value_init_tag()) {}
103 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
104 explicit __compressed_pair() : _Base1(__value_init_tag()), _Base2(__value_init_tag()) {}
126105
127106 template <class _U1, class _U2>
128 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
129 __compressed_pair(_U1&& __t1, _U2&& __t2)
130 : _Base1(_VSTD::forward<_U1>(__t1)), _Base2(_VSTD::forward<_U2>(__t2)) {}
107 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
108 explicit __compressed_pair(_U1&& __t1, _U2&& __t2) : _Base1(std::forward<_U1>(__t1)), _Base2(std::forward<_U2>(__t2)) {}
131109
132110#ifndef _LIBCPP_CXX03_LANG
133111 template <class... _Args1, class... _Args2>
134 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
135 __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
136 tuple<_Args2...> __second_args)
137 : _Base1(__pc, _VSTD::move(__first_args),
138 typename __make_tuple_indices<sizeof...(_Args1)>::type()),
139 _Base2(__pc, _VSTD::move(__second_args),
140 typename __make_tuple_indices<sizeof...(_Args2)>::type()) {}
112 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
113 explicit __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
114 tuple<_Args2...> __second_args)
115 : _Base1(__pc, std::move(__first_args), typename __make_tuple_indices<sizeof...(_Args1)>::type()),
116 _Base2(__pc, std::move(__second_args), typename __make_tuple_indices<sizeof...(_Args2)>::type()) {}
141117#endif
142118
143 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 typename _Base1::reference first() _NOEXCEPT {
119 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
120 typename _Base1::reference first() _NOEXCEPT {
144121 return static_cast<_Base1&>(*this).__get();
145122 }
146123
147 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename _Base1::const_reference first() const _NOEXCEPT {
124 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
125 typename _Base1::const_reference first() const _NOEXCEPT {
148126 return static_cast<_Base1 const&>(*this).__get();
149127 }
150128
151 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 typename _Base2::reference second() _NOEXCEPT {
129 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
130 typename _Base2::reference second() _NOEXCEPT {
152131 return static_cast<_Base2&>(*this).__get();
153132 }
154133
155 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename _Base2::const_reference second() const _NOEXCEPT {
134 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
135 typename _Base2::const_reference second() const _NOEXCEPT {
156136 return static_cast<_Base2 const&>(*this).__get();
157137 }
158138
159 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
160 static _Base1* __get_first_base(__compressed_pair* __pair) _NOEXCEPT {
139 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR static
140 _Base1* __get_first_base(__compressed_pair* __pair) _NOEXCEPT {
161141 return static_cast<_Base1*>(__pair);
162142 }
163 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
164 static _Base2* __get_second_base(__compressed_pair* __pair) _NOEXCEPT {
143 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR static
144 _Base2* __get_second_base(__compressed_pair* __pair) _NOEXCEPT {
165145 return static_cast<_Base2*>(__pair);
166146 }
167147
168 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 void swap(__compressed_pair& __x)
148 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
149 void swap(__compressed_pair& __x)
169150 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && __is_nothrow_swappable<_T2>::value) {
170 using _VSTD::swap;
151 using std::swap;
171152 swap(first(), __x.first());
172153 swap(second(), __x.second());
173154 }
174155};
175156
176157template <class _T1, class _T2>
177inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
158inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
178159void swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y)
179160 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && __is_nothrow_swappable<_T2>::value) {
180161 __x.swap(__y);
lib/libcxx/include/__memory/concepts.h+3-3
......@@ -20,12 +20,12 @@
2020#include <type_traits>
2121
2222#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23#pragma GCC system_header
23# pragma GCC system_header
2424#endif
2525
2626_LIBCPP_BEGIN_NAMESPACE_STD
2727
28#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
28#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
2929
3030namespace ranges {
3131
......@@ -61,7 +61,7 @@ concept __nothrow_forward_range =
6161
6262} // namespace ranges
6363
64#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
64#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
6565
6666_LIBCPP_END_NAMESPACE_STD
6767
lib/libcxx/include/__memory/construct_at.h+19-12
......@@ -10,17 +10,17 @@
1010#ifndef _LIBCPP___MEMORY_CONSTRUCT_AT_H
1111#define _LIBCPP___MEMORY_CONSTRUCT_AT_H
1212
13#include <__assert>
1314#include <__config>
14#include <__debug>
1515#include <__iterator/access.h>
1616#include <__memory/addressof.h>
1717#include <__memory/voidify.h>
1818#include <__utility/forward.h>
19#include <__utility/move.h>
1920#include <type_traits>
20#include <utility>
2121
2222#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23#pragma GCC system_header
23# pragma GCC system_header
2424#endif
2525
2626_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -29,17 +29,24 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2929
3030#if _LIBCPP_STD_VER > 17
3131
32template<class _Tp, class ..._Args, class = decltype(
33 ::new (declval<void*>()) _Tp(declval<_Args>()...)
34)>
35_LIBCPP_HIDE_FROM_ABI
36constexpr _Tp* construct_at(_Tp* __location, _Args&& ...__args) {
37 _LIBCPP_ASSERT(__location, "null pointer given to construct_at");
38 return ::new (_VSTD::__voidify(*__location)) _Tp(_VSTD::forward<_Args>(__args)...);
32template <class _Tp, class... _Args, class = decltype(::new(declval<void*>()) _Tp(declval<_Args>()...))>
33_LIBCPP_HIDE_FROM_ABI constexpr _Tp* construct_at(_Tp* __location, _Args&&... __args) {
34 _LIBCPP_ASSERT(__location != nullptr, "null pointer given to construct_at");
35 return ::new (_VSTD::__voidify(*__location)) _Tp(_VSTD::forward<_Args>(__args)...);
3936}
4037
4138#endif
4239
40template <class _Tp, class... _Args, class = decltype(::new(declval<void*>()) _Tp(declval<_Args>()...))>
41_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp* __construct_at(_Tp* __location, _Args&&... __args) {
42#if _LIBCPP_STD_VER > 17
43 return std::construct_at(__location, std::forward<_Args>(__args)...);
44#else
45 return _LIBCPP_ASSERT(__location != nullptr, "null pointer given to construct_at"),
46 ::new (std::__voidify(*__location)) _Tp(std::forward<_Args>(__args)...);
47#endif
48}
49
4350// destroy_at
4451
4552// The internal functions are available regardless of the language version (with the exception of the `__destroy_at`
......@@ -52,7 +59,7 @@ _ForwardIterator __destroy(_ForwardIterator, _ForwardIterator);
5259template <class _Tp, typename enable_if<!is_array<_Tp>::value, int>::type = 0>
5360_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
5461void __destroy_at(_Tp* __loc) {
55 _LIBCPP_ASSERT(__loc, "null pointer given to destroy_at");
62 _LIBCPP_ASSERT(__loc != nullptr, "null pointer given to destroy_at");
5663 __loc->~_Tp();
5764}
5865
......@@ -60,7 +67,7 @@ void __destroy_at(_Tp* __loc) {
6067template <class _Tp, typename enable_if<is_array<_Tp>::value, int>::type = 0>
6168_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
6269void __destroy_at(_Tp* __loc) {
63 _LIBCPP_ASSERT(__loc, "null pointer given to destroy_at");
70 _LIBCPP_ASSERT(__loc != nullptr, "null pointer given to destroy_at");
6471 _VSTD::__destroy(_VSTD::begin(*__loc), _VSTD::end(*__loc));
6572}
6673#endif
lib/libcxx/include/__memory/pointer_traits.h+5-6
......@@ -15,7 +15,7 @@
1515#include <type_traits>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -71,13 +71,12 @@ template <class _Tp, class _Up>
7171struct __has_rebind
7272{
7373private:
74 struct __two {char __lx; char __lxx;};
75 template <class _Xp> static __two __test(...);
74 template <class _Xp> static false_type __test(...);
7675 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
77 template <class _Xp> static char __test(typename _Xp::template rebind<_Up>* = 0);
76 template <class _Xp> static true_type __test(typename _Xp::template rebind<_Up>* = 0);
7877 _LIBCPP_SUPPRESS_DEPRECATED_POP
7978public:
80 static const bool value = sizeof(__test<_Tp>(0)) == 1;
79 static const bool value = decltype(__test<_Tp>(0))::value;
8180};
8281
8382template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
......@@ -123,7 +122,7 @@ struct _LIBCPP_TEMPLATE_VIS pointer_traits
123122private:
124123 struct __nat {};
125124public:
126 _LIBCPP_INLINE_VISIBILITY
125 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
127126 static pointer pointer_to(typename conditional<is_void<element_type>::value,
128127 __nat, element_type>::type& __r)
129128 {return pointer::pointer_to(__r);}
lib/libcxx/include/__memory/ranges_construct_at.h+3-3
......@@ -24,12 +24,12 @@
2424#include <__utility/move.h>
2525
2626#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
27#pragma GCC system_header
27# pragma GCC system_header
2828#endif
2929
3030_LIBCPP_BEGIN_NAMESPACE_STD
3131
32#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
32#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
3333namespace ranges {
3434
3535// construct_at
......@@ -117,7 +117,7 @@ inline namespace __cpo {
117117
118118} // namespace ranges
119119
120#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
120#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
121121
122122_LIBCPP_END_NAMESPACE_STD
123123
lib/libcxx/include/__memory/ranges_uninitialized_algorithms.h+3-3
......@@ -27,12 +27,12 @@
2727#include <type_traits>
2828
2929#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
30#pragma GCC system_header
30# pragma GCC system_header
3131#endif
3232
3333_LIBCPP_BEGIN_NAMESPACE_STD
3434
35#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
35#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
3636
3737namespace ranges {
3838
......@@ -311,7 +311,7 @@ inline namespace __cpo {
311311
312312} // namespace ranges
313313
314#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
314#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
315315
316316_LIBCPP_END_NAMESPACE_STD
317317
lib/libcxx/include/__memory/raw_storage_iterator.h+4-3
......@@ -11,13 +11,14 @@
1111#define _LIBCPP___MEMORY_RAW_STORAGE_ITERATOR_H
1212
1313#include <__config>
14#include <__iterator/iterator.h>
15#include <__iterator/iterator_traits.h>
1416#include <__memory/addressof.h>
17#include <__utility/move.h>
1518#include <cstddef>
16#include <iterator>
17#include <utility>
1819
1920#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20#pragma GCC system_header
21# pragma GCC system_header
2122#endif
2223
2324_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__memory/shared_ptr.h+236-41
......@@ -15,32 +15,33 @@
1515#include <__functional/binary_function.h>
1616#include <__functional/operations.h>
1717#include <__functional/reference_wrapper.h>
18#include <__functional_base>
18#include <__iterator/access.h>
1919#include <__memory/addressof.h>
2020#include <__memory/allocation_guard.h>
2121#include <__memory/allocator.h>
2222#include <__memory/allocator_traits.h>
23#include <__memory/auto_ptr.h>
2324#include <__memory/compressed_pair.h>
25#include <__memory/construct_at.h>
2426#include <__memory/pointer_traits.h>
27#include <__memory/uninitialized_algorithms.h>
2528#include <__memory/unique_ptr.h>
2629#include <__utility/forward.h>
30#include <__utility/move.h>
31#include <__utility/swap.h>
2732#include <cstddef>
2833#include <cstdlib> // abort
2934#include <iosfwd>
3035#include <stdexcept>
3136#include <type_traits>
3237#include <typeinfo>
33#include <utility>
3438#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
3539# include <atomic>
3640#endif
3741
38#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
39# include <__memory/auto_ptr.h>
40#endif
4142
4243#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
43#pragma GCC system_header
44# pragma GCC system_header
4445#endif
4546
4647_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -159,10 +160,9 @@ public:
159160 explicit __shared_count(long __refs = 0) _NOEXCEPT
160161 : __shared_owners_(__refs) {}
161162
162#if defined(_LIBCPP_BUILDING_LIBRARY) && \
163 defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
164 void __add_shared() _NOEXCEPT;
165 bool __release_shared() _NOEXCEPT;
163#if defined(_LIBCPP_SHARED_PTR_DEFINE_LEGACY_INLINE_FUNCTIONS)
164 void __add_shared() noexcept;
165 bool __release_shared() noexcept;
166166#else
167167 _LIBCPP_INLINE_VISIBILITY
168168 void __add_shared() _NOEXCEPT {
......@@ -197,11 +197,10 @@ protected:
197197 virtual ~__shared_weak_count();
198198
199199public:
200#if defined(_LIBCPP_BUILDING_LIBRARY) && \
201 defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
202 void __add_shared() _NOEXCEPT;
203 void __add_weak() _NOEXCEPT;
204 void __release_shared() _NOEXCEPT;
200#if defined(_LIBCPP_SHARED_PTR_DEFINE_LEGACY_INLINE_FUNCTIONS)
201 void __add_shared() noexcept;
202 void __add_weak() noexcept;
203 void __release_shared() noexcept;
205204#else
206205 _LIBCPP_INLINE_VISIBILITY
207206 void __add_shared() _NOEXCEPT {
......@@ -457,7 +456,7 @@ public:
457456 explicit shared_ptr(_Yp* __p) : __ptr_(__p) {
458457 unique_ptr<_Yp> __hold(__p);
459458 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
460 typedef __shared_ptr_pointer<_Yp*, __shared_ptr_default_delete<_Tp, _Yp>, _AllocT > _CntrlBlk;
459 typedef __shared_ptr_pointer<_Yp*, __shared_ptr_default_delete<_Tp, _Yp>, _AllocT> _CntrlBlk;
461460 __cntrl_ = new _CntrlBlk(__p, __shared_ptr_default_delete<_Tp, _Yp>(), _AllocT());
462461 __hold.release();
463462 __enable_weak_this(__p, __p);
......@@ -473,7 +472,7 @@ public:
473472 {
474473#endif // _LIBCPP_NO_EXCEPTIONS
475474 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
476 typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk;
475 typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT> _CntrlBlk;
477476#ifndef _LIBCPP_CXX03_LANG
478477 __cntrl_ = new _CntrlBlk(__p, _VSTD::move(__d), _AllocT());
479478#else
......@@ -532,7 +531,7 @@ public:
532531 {
533532#endif // _LIBCPP_NO_EXCEPTIONS
534533 typedef typename __shared_ptr_default_allocator<_Tp>::type _AllocT;
535 typedef __shared_ptr_pointer<nullptr_t, _Dp, _AllocT > _CntrlBlk;
534 typedef __shared_ptr_pointer<nullptr_t, _Dp, _AllocT> _CntrlBlk;
536535#ifndef _LIBCPP_CXX03_LANG
537536 __cntrl_ = new _CntrlBlk(__p, _VSTD::move(__d), _AllocT());
538537#else
......@@ -665,8 +664,8 @@ public:
665664#endif
666665 {
667666 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
668 typedef __shared_ptr_pointer<typename unique_ptr<_Yp, _Dp>::pointer, _Dp, _AllocT > _CntrlBlk;
669 __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), _AllocT());
667 typedef __shared_ptr_pointer<typename unique_ptr<_Yp, _Dp>::pointer, _Dp, _AllocT> _CntrlBlk;
668 __cntrl_ = new _CntrlBlk(__r.get(), std::move(__r.get_deleter()), _AllocT());
670669 __enable_weak_this(__r.get(), __r.get());
671670 }
672671 __r.release();
......@@ -689,7 +688,7 @@ public:
689688 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
690689 typedef __shared_ptr_pointer<typename unique_ptr<_Yp, _Dp>::pointer,
691690 reference_wrapper<typename remove_reference<_Dp>::type>,
692 _AllocT > _CntrlBlk;
691 _AllocT> _CntrlBlk;
693692 __cntrl_ = new _CntrlBlk(__r.get(), _VSTD::ref(__r.get_deleter()), _AllocT());
694693 __enable_weak_this(__r.get(), __r.get());
695694 }
......@@ -963,6 +962,220 @@ shared_ptr<_Tp> make_shared(_Args&& ...__args)
963962 return _VSTD::allocate_shared<_Tp>(allocator<_Tp>(), _VSTD::forward<_Args>(__args)...);
964963}
965964
965#if _LIBCPP_STD_VER > 14
966
967template <size_t _Alignment>
968struct __sp_aligned_storage {
969 alignas(_Alignment) char __storage[_Alignment];
970};
971
972template <class _Tp, class _Alloc>
973struct __unbounded_array_control_block;
974
975template <class _Tp, class _Alloc>
976struct __unbounded_array_control_block<_Tp[], _Alloc> : __shared_weak_count
977{
978 _LIBCPP_HIDE_FROM_ABI constexpr
979 _Tp* __get_data() noexcept { return __data_; }
980
981 _LIBCPP_HIDE_FROM_ABI
982 explicit __unbounded_array_control_block(_Alloc const& __alloc, size_t __count, _Tp const& __arg)
983 : __alloc_(__alloc), __count_(__count)
984 {
985 std::__uninitialized_allocator_fill_n(__alloc_, std::begin(__data_), __count_, __arg);
986 }
987
988 _LIBCPP_HIDE_FROM_ABI
989 explicit __unbounded_array_control_block(_Alloc const& __alloc, size_t __count)
990 : __alloc_(__alloc), __count_(__count)
991 {
992 std::__uninitialized_allocator_value_construct_n(__alloc_, std::begin(__data_), __count_);
993 }
994
995 // Returns the number of bytes required to store a control block followed by the given number
996 // of elements of _Tp, with the whole storage being aligned to a multiple of _Tp's alignment.
997 _LIBCPP_HIDE_FROM_ABI
998 static constexpr size_t __bytes_for(size_t __elements) {
999 // When there's 0 elements, the control block alone is enough since it holds one element.
1000 // Otherwise, we allocate one fewer element than requested because the control block already
1001 // holds one. Also, we use the bitwise formula below to ensure that we allocate enough bytes
1002 // for the whole allocation to be a multiple of _Tp's alignment. That formula is taken from [1].
1003 //
1004 // [1]: https://en.wikipedia.org/wiki/Data_structure_alignment#Computing_padding
1005 size_t __bytes = __elements == 0 ? sizeof(__unbounded_array_control_block)
1006 : (__elements - 1) * sizeof(_Tp) + sizeof(__unbounded_array_control_block);
1007 constexpr size_t __align = alignof(_Tp);
1008 return (__bytes + __align - 1) & ~(__align - 1);
1009 }
1010
1011 _LIBCPP_HIDE_FROM_ABI
1012 ~__unbounded_array_control_block() override { } // can't be `= default` because of the sometimes-non-trivial union member __data_
1013
1014private:
1015 void __on_zero_shared() _NOEXCEPT override {
1016 __allocator_traits_rebind_t<_Alloc, _Tp> __value_alloc(__alloc_);
1017 std::__allocator_destroy_multidimensional(__value_alloc, __data_, __data_ + __count_);
1018 }
1019
1020 void __on_zero_shared_weak() _NOEXCEPT override {
1021 using _AlignedStorage = __sp_aligned_storage<alignof(__unbounded_array_control_block)>;
1022 using _StorageAlloc = __allocator_traits_rebind_t<_Alloc, _AlignedStorage>;
1023 using _PointerTraits = pointer_traits<typename allocator_traits<_StorageAlloc>::pointer>;
1024
1025 _StorageAlloc __tmp(__alloc_);
1026 __alloc_.~_Alloc();
1027 size_t __size = __unbounded_array_control_block::__bytes_for(__count_);
1028 _AlignedStorage* __storage = reinterpret_cast<_AlignedStorage*>(this);
1029 allocator_traits<_StorageAlloc>::deallocate(__tmp, _PointerTraits::pointer_to(*__storage), __size);
1030 }
1031
1032 _LIBCPP_NO_UNIQUE_ADDRESS _Alloc __alloc_;
1033 size_t __count_;
1034 union {
1035 _Tp __data_[1];
1036 };
1037};
1038
1039template<class _Array, class _Alloc, class... _Arg>
1040_LIBCPP_HIDE_FROM_ABI
1041shared_ptr<_Array> __allocate_shared_unbounded_array(const _Alloc& __a, size_t __n, _Arg&& ...__arg)
1042{
1043 static_assert(__libcpp_is_unbounded_array<_Array>::value);
1044 // We compute the number of bytes necessary to hold the control block and the
1045 // array elements. Then, we allocate an array of properly-aligned dummy structs
1046 // large enough to hold the control block and array. This allows shifting the
1047 // burden of aligning memory properly from us to the allocator.
1048 using _ControlBlock = __unbounded_array_control_block<_Array, _Alloc>;
1049 using _AlignedStorage = __sp_aligned_storage<alignof(_ControlBlock)>;
1050 using _StorageAlloc = __allocator_traits_rebind_t<_Alloc, _AlignedStorage>;
1051 __allocation_guard<_StorageAlloc> __guard(__a, _ControlBlock::__bytes_for(__n) / sizeof(_AlignedStorage));
1052 _ControlBlock* __control_block = reinterpret_cast<_ControlBlock*>(std::addressof(*__guard.__get()));
1053 std::__construct_at(__control_block, __a, __n, std::forward<_Arg>(__arg)...);
1054 __guard.__release_ptr();
1055 return shared_ptr<_Array>::__create_with_control_block(__control_block->__get_data(), __control_block);
1056}
1057
1058template <class _Tp, class _Alloc>
1059struct __bounded_array_control_block;
1060
1061template <class _Tp, size_t _Count, class _Alloc>
1062struct __bounded_array_control_block<_Tp[_Count], _Alloc>
1063 : __shared_weak_count
1064{
1065 _LIBCPP_HIDE_FROM_ABI constexpr
1066 _Tp* __get_data() noexcept { return __data_; }
1067
1068 _LIBCPP_HIDE_FROM_ABI
1069 explicit __bounded_array_control_block(_Alloc const& __alloc, _Tp const& __arg) : __alloc_(__alloc) {
1070 std::__uninitialized_allocator_fill_n(__alloc_, std::addressof(__data_[0]), _Count, __arg);
1071 }
1072
1073 _LIBCPP_HIDE_FROM_ABI
1074 explicit __bounded_array_control_block(_Alloc const& __alloc) : __alloc_(__alloc) {
1075 std::__uninitialized_allocator_value_construct_n(__alloc_, std::addressof(__data_[0]), _Count);
1076 }
1077
1078 _LIBCPP_HIDE_FROM_ABI
1079 ~__bounded_array_control_block() override { } // can't be `= default` because of the sometimes-non-trivial union member __data_
1080
1081private:
1082 void __on_zero_shared() _NOEXCEPT override {
1083 __allocator_traits_rebind_t<_Alloc, _Tp> __value_alloc(__alloc_);
1084 std::__allocator_destroy_multidimensional(__value_alloc, __data_, __data_ + _Count);
1085 }
1086
1087 void __on_zero_shared_weak() _NOEXCEPT override {
1088 using _ControlBlockAlloc = __allocator_traits_rebind_t<_Alloc, __bounded_array_control_block>;
1089 using _PointerTraits = pointer_traits<typename allocator_traits<_ControlBlockAlloc>::pointer>;
1090
1091 _ControlBlockAlloc __tmp(__alloc_);
1092 __alloc_.~_Alloc();
1093 allocator_traits<_ControlBlockAlloc>::deallocate(__tmp, _PointerTraits::pointer_to(*this), sizeof(*this));
1094 }
1095
1096 _LIBCPP_NO_UNIQUE_ADDRESS _Alloc __alloc_;
1097 union {
1098 _Tp __data_[_Count];
1099 };
1100};
1101
1102template<class _Array, class _Alloc, class... _Arg>
1103_LIBCPP_HIDE_FROM_ABI
1104shared_ptr<_Array> __allocate_shared_bounded_array(const _Alloc& __a, _Arg&& ...__arg)
1105{
1106 static_assert(__libcpp_is_bounded_array<_Array>::value);
1107 using _ControlBlock = __bounded_array_control_block<_Array, _Alloc>;
1108 using _ControlBlockAlloc = __allocator_traits_rebind_t<_Alloc, _ControlBlock>;
1109
1110 __allocation_guard<_ControlBlockAlloc> __guard(__a, 1);
1111 _ControlBlock* __control_block = reinterpret_cast<_ControlBlock*>(std::addressof(*__guard.__get()));
1112 std::__construct_at(__control_block, __a, std::forward<_Arg>(__arg)...);
1113 __guard.__release_ptr();
1114 return shared_ptr<_Array>::__create_with_control_block(__control_block->__get_data(), __control_block);
1115}
1116
1117#endif // _LIBCPP_STD_VER > 14
1118
1119#if _LIBCPP_STD_VER > 17
1120
1121template<class _Tp, class _Alloc, class = __enable_if_t<is_bounded_array<_Tp>::value>>
1122_LIBCPP_HIDE_FROM_ABI
1123shared_ptr<_Tp> allocate_shared(const _Alloc& __a)
1124{
1125 return std::__allocate_shared_bounded_array<_Tp>(__a);
1126}
1127
1128template<class _Tp, class _Alloc, class = __enable_if_t<is_bounded_array<_Tp>::value>>
1129_LIBCPP_HIDE_FROM_ABI
1130shared_ptr<_Tp> allocate_shared(const _Alloc& __a, const remove_extent_t<_Tp>& __u)
1131{
1132 return std::__allocate_shared_bounded_array<_Tp>(__a, __u);
1133}
1134
1135template<class _Tp, class _Alloc, class = __enable_if_t<is_unbounded_array<_Tp>::value>>
1136_LIBCPP_HIDE_FROM_ABI
1137shared_ptr<_Tp> allocate_shared(const _Alloc& __a, size_t __n)
1138{
1139 return std::__allocate_shared_unbounded_array<_Tp>(__a, __n);
1140}
1141
1142template<class _Tp, class _Alloc, class = __enable_if_t<is_unbounded_array<_Tp>::value>>
1143_LIBCPP_HIDE_FROM_ABI
1144shared_ptr<_Tp> allocate_shared(const _Alloc& __a, size_t __n, const remove_extent_t<_Tp>& __u)
1145{
1146 return std::__allocate_shared_unbounded_array<_Tp>(__a, __n, __u);
1147}
1148
1149template<class _Tp, class = __enable_if_t<is_bounded_array<_Tp>::value>>
1150_LIBCPP_HIDE_FROM_ABI
1151shared_ptr<_Tp> make_shared()
1152{
1153 return std::__allocate_shared_bounded_array<_Tp>(allocator<_Tp>());
1154}
1155
1156template<class _Tp, class = __enable_if_t<is_bounded_array<_Tp>::value>>
1157_LIBCPP_HIDE_FROM_ABI
1158shared_ptr<_Tp> make_shared(const remove_extent_t<_Tp>& __u)
1159{
1160 return std::__allocate_shared_bounded_array<_Tp>(allocator<_Tp>(), __u);
1161}
1162
1163template<class _Tp, class = __enable_if_t<is_unbounded_array<_Tp>::value>>
1164_LIBCPP_HIDE_FROM_ABI
1165shared_ptr<_Tp> make_shared(size_t __n)
1166{
1167 return std::__allocate_shared_unbounded_array<_Tp>(allocator<_Tp>(), __n);
1168}
1169
1170template<class _Tp, class = __enable_if_t<is_unbounded_array<_Tp>::value>>
1171_LIBCPP_HIDE_FROM_ABI
1172shared_ptr<_Tp> make_shared(size_t __n, const remove_extent_t<_Tp>& __u)
1173{
1174 return std::__allocate_shared_unbounded_array<_Tp>(allocator<_Tp>(), __n, __u);
1175}
1176
1177#endif // _LIBCPP_STD_VER > 17
1178
9661179template<class _Tp, class _Up>
9671180inline _LIBCPP_INLINE_VISIBILITY
9681181bool
......@@ -1442,19 +1655,10 @@ template <class _Tp> struct owner_less;
14421655#endif
14431656
14441657
1445_LIBCPP_SUPPRESS_DEPRECATED_PUSH
14461658template <class _Tp>
14471659struct _LIBCPP_TEMPLATE_VIS owner_less<shared_ptr<_Tp> >
1448#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
1449 : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool>
1450#endif
1660 : __binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool>
14511661{
1452_LIBCPP_SUPPRESS_DEPRECATED_POP
1453#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
1454 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
1455 _LIBCPP_DEPRECATED_IN_CXX17 typedef shared_ptr<_Tp> first_argument_type;
1456 _LIBCPP_DEPRECATED_IN_CXX17 typedef shared_ptr<_Tp> second_argument_type;
1457#endif
14581662 _LIBCPP_INLINE_VISIBILITY
14591663 bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT
14601664 {return __x.owner_before(__y);}
......@@ -1466,19 +1670,10 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
14661670 {return __x.owner_before(__y);}
14671671};
14681672
1469_LIBCPP_SUPPRESS_DEPRECATED_PUSH
14701673template <class _Tp>
14711674struct _LIBCPP_TEMPLATE_VIS owner_less<weak_ptr<_Tp> >
1472#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
1473 : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool>
1474#endif
1675 : __binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool>
14751676{
1476_LIBCPP_SUPPRESS_DEPRECATED_POP
1477#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
1478 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
1479 _LIBCPP_DEPRECATED_IN_CXX17 typedef weak_ptr<_Tp> first_argument_type;
1480 _LIBCPP_DEPRECATED_IN_CXX17 typedef weak_ptr<_Tp> second_argument_type;
1481#endif
14821677 _LIBCPP_INLINE_VISIBILITY
14831678 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT
14841679 {return __x.owner_before(__y);}
lib/libcxx/include/__memory/swap_allocator.h created+53
......@@ -0,0 +1,53 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___MEMORY_SWAP_ALLOCATOR_H
10#define _LIBCPP___MEMORY_SWAP_ALLOCATOR_H
11
12#include <__config>
13#include <__memory/allocator_traits.h>
14#include <__type_traits/integral_constant.h>
15#include <__utility/swap.h>
16
17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18# pragma GCC system_header
19#endif
20
21_LIBCPP_BEGIN_NAMESPACE_STD
22
23template <typename _Alloc>
24_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 void __swap_allocator(_Alloc& __a1, _Alloc& __a2, true_type)
25#if _LIBCPP_STD_VER > 11
26 _NOEXCEPT
27#else
28 _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
29#endif
30{
31 using _VSTD::swap;
32 swap(__a1, __a2);
33}
34
35template <typename _Alloc>
36inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 void
37__swap_allocator(_Alloc&, _Alloc&, false_type) _NOEXCEPT {}
38
39template <typename _Alloc>
40inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 void __swap_allocator(_Alloc& __a1, _Alloc& __a2)
41#if _LIBCPP_STD_VER > 11
42 _NOEXCEPT
43#else
44 _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
45#endif
46{
47 _VSTD::__swap_allocator(
48 __a1, __a2, integral_constant<bool, allocator_traits<_Alloc>::propagate_on_container_swap::value>());
49}
50
51_LIBCPP_END_NAMESPACE_STD
52
53#endif // _LIBCPP___MEMORY_SWAP_ALLOCATOR_H
lib/libcxx/include/__memory/temporary_buffer.h+7-4
......@@ -11,18 +11,19 @@
1111#define _LIBCPP___MEMORY_TEMPORARY_BUFFER_H
1212
1313#include <__config>
14#include <__type_traits/alignment_of.h>
15#include <__utility/pair.h>
1416#include <cstddef>
1517#include <new>
16#include <utility> // pair
1718
1819#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
20# pragma GCC system_header
2021#endif
2122
2223_LIBCPP_BEGIN_NAMESPACE_STD
2324
2425template <class _Tp>
25_LIBCPP_NODISCARD_EXT _LIBCPP_NO_CFI
26_LIBCPP_NODISCARD_EXT _LIBCPP_NO_CFI _LIBCPP_DEPRECATED_IN_CXX17
2627pair<_Tp*, ptrdiff_t>
2728get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT
2829{
......@@ -67,7 +68,7 @@ get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT
6768}
6869
6970template <class _Tp>
70inline _LIBCPP_INLINE_VISIBILITY
71inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_DEPRECATED_IN_CXX17
7172void return_temporary_buffer(_Tp* __p) _NOEXCEPT
7273{
7374 _VSTD::__libcpp_deallocate_unsized((void*)__p, _LIBCPP_ALIGNOF(_Tp));
......@@ -75,8 +76,10 @@ void return_temporary_buffer(_Tp* __p) _NOEXCEPT
7576
7677struct __return_temporary_buffer
7778{
79_LIBCPP_SUPPRESS_DEPRECATED_PUSH
7880 template <class _Tp>
7981 _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) const {_VSTD::return_temporary_buffer(__p);}
82_LIBCPP_SUPPRESS_DEPRECATED_POP
8083};
8184
8285_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__memory/uninitialized_algorithms.h+295-3
......@@ -10,15 +10,24 @@
1010#ifndef _LIBCPP___MEMORY_UNINITIALIZED_ALGORITHMS_H
1111#define _LIBCPP___MEMORY_UNINITIALIZED_ALGORITHMS_H
1212
13#include <__algorithm/copy.h>
14#include <__algorithm/move.h>
1315#include <__config>
16#include <__iterator/iterator_traits.h>
17#include <__iterator/reverse_iterator.h>
1418#include <__memory/addressof.h>
19#include <__memory/allocator_traits.h>
1520#include <__memory/construct_at.h>
21#include <__memory/pointer_traits.h>
1622#include <__memory/voidify.h>
17#include <iterator>
18#include <utility>
23#include <__type_traits/is_constant_evaluated.h>
24#include <__utility/move.h>
25#include <__utility/pair.h>
26#include <__utility/transaction.h>
27#include <type_traits>
1928
2029#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21#pragma GCC system_header
30# pragma GCC system_header
2231#endif
2332
2433_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -343,8 +352,291 @@ uninitialized_move_n(_InputIterator __ifirst, _Size __n, _ForwardIterator __ofir
343352 __unreachable_sentinel(), __iter_move);
344353}
345354
355// TODO: Rewrite this to iterate left to right and use reverse_iterators when calling
356// Destroys every element in the range [first, last) FROM RIGHT TO LEFT using allocator
357// destruction. If elements are themselves C-style arrays, they are recursively destroyed
358// in the same manner.
359//
360// This function assumes that destructors do not throw, and that the allocator is bound to
361// the correct type.
362template<class _Alloc, class _BidirIter, class = __enable_if_t<
363 __is_cpp17_bidirectional_iterator<_BidirIter>::value
364>>
365_LIBCPP_HIDE_FROM_ABI
366constexpr void __allocator_destroy_multidimensional(_Alloc& __alloc, _BidirIter __first, _BidirIter __last) noexcept {
367 using _ValueType = typename iterator_traits<_BidirIter>::value_type;
368 static_assert(is_same_v<typename allocator_traits<_Alloc>::value_type, _ValueType>,
369 "The allocator should already be rebound to the correct type");
370
371 if (__first == __last)
372 return;
373
374 if constexpr (is_array_v<_ValueType>) {
375 static_assert(!__libcpp_is_unbounded_array<_ValueType>::value,
376 "arrays of unbounded arrays don't exist, but if they did we would mess up here");
377
378 using _Element = remove_extent_t<_ValueType>;
379 __allocator_traits_rebind_t<_Alloc, _Element> __elem_alloc(__alloc);
380 do {
381 --__last;
382 decltype(auto) __array = *__last;
383 std::__allocator_destroy_multidimensional(__elem_alloc, __array, __array + extent_v<_ValueType>);
384 } while (__last != __first);
385 } else {
386 do {
387 --__last;
388 allocator_traits<_Alloc>::destroy(__alloc, std::addressof(*__last));
389 } while (__last != __first);
390 }
391}
392
393// Constructs the object at the given location using the allocator's construct method.
394//
395// If the object being constructed is an array, each element of the array is allocator-constructed,
396// recursively. If an exception is thrown during the construction of an array, the initialized
397// elements are destroyed in reverse order of initialization using allocator destruction.
398//
399// This function assumes that the allocator is bound to the correct type.
400template<class _Alloc, class _Tp>
401_LIBCPP_HIDE_FROM_ABI
402constexpr void __allocator_construct_at(_Alloc& __alloc, _Tp* __loc) {
403 static_assert(is_same_v<typename allocator_traits<_Alloc>::value_type, _Tp>,
404 "The allocator should already be rebound to the correct type");
405
406 if constexpr (is_array_v<_Tp>) {
407 using _Element = remove_extent_t<_Tp>;
408 __allocator_traits_rebind_t<_Alloc, _Element> __elem_alloc(__alloc);
409 size_t __i = 0;
410 _Tp& __array = *__loc;
411
412 // If an exception is thrown, destroy what we have constructed so far in reverse order.
413 __transaction __guard([&]() { std::__allocator_destroy_multidimensional(__elem_alloc, __array, __array + __i); });
414 for (; __i != extent_v<_Tp>; ++__i) {
415 std::__allocator_construct_at(__elem_alloc, std::addressof(__array[__i]));
416 }
417 __guard.__complete();
418 } else {
419 allocator_traits<_Alloc>::construct(__alloc, __loc);
420 }
421}
422
423// Constructs the object at the given location using the allocator's construct method, passing along
424// the provided argument.
425//
426// If the object being constructed is an array, the argument is also assumed to be an array. Each
427// each element of the array being constructed is allocator-constructed from the corresponding
428// element of the argument array. If an exception is thrown during the construction of an array,
429// the initialized elements are destroyed in reverse order of initialization using allocator
430// destruction.
431//
432// This function assumes that the allocator is bound to the correct type.
433template<class _Alloc, class _Tp, class _Arg>
434_LIBCPP_HIDE_FROM_ABI
435constexpr void __allocator_construct_at(_Alloc& __alloc, _Tp* __loc, _Arg const& __arg) {
436 static_assert(is_same_v<typename allocator_traits<_Alloc>::value_type, _Tp>,
437 "The allocator should already be rebound to the correct type");
438
439 if constexpr (is_array_v<_Tp>) {
440 static_assert(is_array_v<_Arg>,
441 "Provided non-array initialization argument to __allocator_construct_at when "
442 "trying to construct an array.");
443
444 using _Element = remove_extent_t<_Tp>;
445 __allocator_traits_rebind_t<_Alloc, _Element> __elem_alloc(__alloc);
446 size_t __i = 0;
447 _Tp& __array = *__loc;
448
449 // If an exception is thrown, destroy what we have constructed so far in reverse order.
450 __transaction __guard([&]() { std::__allocator_destroy_multidimensional(__elem_alloc, __array, __array + __i); });
451 for (; __i != extent_v<_Tp>; ++__i) {
452 std::__allocator_construct_at(__elem_alloc, std::addressof(__array[__i]), __arg[__i]);
453 }
454 __guard.__complete();
455 } else {
456 allocator_traits<_Alloc>::construct(__alloc, __loc, __arg);
457 }
458}
459
460// Given a range starting at it and containing n elements, initializes each element in the
461// range from left to right using the construct method of the allocator (rebound to the
462// correct type).
463//
464// If an exception is thrown, the initialized elements are destroyed in reverse order of
465// initialization using allocator_traits destruction. If the elements in the range are C-style
466// arrays, they are initialized element-wise using allocator construction, and recursively so.
467template<class _Alloc, class _BidirIter, class _Tp, class _Size = typename iterator_traits<_BidirIter>::difference_type>
468_LIBCPP_HIDE_FROM_ABI
469constexpr void __uninitialized_allocator_fill_n(_Alloc& __alloc, _BidirIter __it, _Size __n, _Tp const& __value) {
470 using _ValueType = typename iterator_traits<_BidirIter>::value_type;
471 __allocator_traits_rebind_t<_Alloc, _ValueType> __value_alloc(__alloc);
472 _BidirIter __begin = __it;
473
474 // If an exception is thrown, destroy what we have constructed so far in reverse order.
475 __transaction __guard([&]() { std::__allocator_destroy_multidimensional(__value_alloc, __begin, __it); });
476 for (; __n != 0; --__n, ++__it) {
477 std::__allocator_construct_at(__value_alloc, std::addressof(*__it), __value);
478 }
479 __guard.__complete();
480}
481
482// Same as __uninitialized_allocator_fill_n, but doesn't pass any initialization argument
483// to the allocator's construct method, which results in value initialization.
484template<class _Alloc, class _BidirIter, class _Size = typename iterator_traits<_BidirIter>::difference_type>
485_LIBCPP_HIDE_FROM_ABI
486constexpr void __uninitialized_allocator_value_construct_n(_Alloc& __alloc, _BidirIter __it, _Size __n) {
487 using _ValueType = typename iterator_traits<_BidirIter>::value_type;
488 __allocator_traits_rebind_t<_Alloc, _ValueType> __value_alloc(__alloc);
489 _BidirIter __begin = __it;
490
491 // If an exception is thrown, destroy what we have constructed so far in reverse order.
492 __transaction __guard([&]() { std::__allocator_destroy_multidimensional(__value_alloc, __begin, __it); });
493 for (; __n != 0; --__n, ++__it) {
494 std::__allocator_construct_at(__value_alloc, std::addressof(*__it));
495 }
496 __guard.__complete();
497}
498
346499#endif // _LIBCPP_STD_VER > 14
347500
501// Destroy all elements in [__first, __last) from left to right using allocator destruction.
502template <class _Alloc, class _Iter, class _Sent>
503_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 void
504__allocator_destroy(_Alloc& __alloc, _Iter __first, _Sent __last) {
505 for (; __first != __last; ++__first)
506 allocator_traits<_Alloc>::destroy(__alloc, std::__to_address(__first));
507}
508
509template <class _Alloc, class _Iter>
510class _AllocatorDestroyRangeReverse {
511public:
512 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
513 _AllocatorDestroyRangeReverse(_Alloc& __alloc, _Iter& __first, _Iter& __last)
514 : __alloc_(__alloc), __first_(__first), __last_(__last) {}
515
516 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 void operator()() const {
517 std::__allocator_destroy(__alloc_, std::reverse_iterator<_Iter>(__last_), std::reverse_iterator<_Iter>(__first_));
518 }
519
520private:
521 _Alloc& __alloc_;
522 _Iter& __first_;
523 _Iter& __last_;
524};
525
526// Copy-construct [__first1, __last1) in [__first2, __first2 + N), where N is distance(__first1, __last1).
527//
528// The caller has to ensure that __first2 can hold at least N uninitialized elements. If an exception is thrown the
529// already copied elements are destroyed in reverse order of their construction.
530template <class _Alloc, class _Iter1, class _Sent1, class _Iter2>
531_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _Iter2
532__uninitialized_allocator_copy(_Alloc& __alloc, _Iter1 __first1, _Sent1 __last1, _Iter2 __first2) {
533#ifndef _LIBCPP_NO_EXCEPTIONS
534 auto __destruct_first = __first2;
535 try {
536#endif
537 while (__first1 != __last1) {
538 allocator_traits<_Alloc>::construct(__alloc, std::__to_address(__first2), *__first1);
539 ++__first1;
540 ++__first2;
541 }
542#ifndef _LIBCPP_NO_EXCEPTIONS
543 } catch (...) {
544 _AllocatorDestroyRangeReverse<_Alloc, _Iter2>(__alloc, __destruct_first, __first2)();
545 throw;
546 }
547#endif
548 return __first2;
549}
550
551template <class _Alloc, class _Type>
552struct __allocator_has_trivial_copy_construct : _Not<__has_construct<_Alloc, _Type*, const _Type&> > {};
553
554template <class _Type>
555struct __allocator_has_trivial_copy_construct<allocator<_Type>, _Type> : true_type {};
556
557template <class _Alloc,
558 class _Type,
559 class _RawType = typename remove_const<_Type>::type,
560 __enable_if_t<
561 // using _RawType because of the allocator<T const> extension
562 is_trivially_copy_constructible<_RawType>::value && is_trivially_copy_assignable<_RawType>::value &&
563 __allocator_has_trivial_copy_construct<_Alloc, _RawType>::value>* = nullptr>
564_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _Type*
565__uninitialized_allocator_copy(_Alloc&, const _Type* __first1, const _Type* __last1, _Type* __first2) {
566 // TODO: Remove the const_cast once we drop support for std::allocator<T const>
567 if (__libcpp_is_constant_evaluated()) {
568 while (__first1 != __last1) {
569 std::__construct_at(std::__to_address(__first2), *__first1);
570 ++__first1;
571 ++__first2;
572 }
573 return __first2;
574 } else {
575 return std::copy(__first1, __last1, const_cast<_RawType*>(__first2));
576 }
577}
578
579// Move-construct the elements [__first1, __last1) into [__first2, __first2 + N)
580// if the move constructor is noexcept, where N is distance(__first1, __last1).
581//
582// Otherwise try to copy all elements. If an exception is thrown the already copied
583// elements are destroyed in reverse order of their construction.
584template <class _Alloc, class _Iter1, class _Sent1, class _Iter2>
585_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _Iter2 __uninitialized_allocator_move_if_noexcept(
586 _Alloc& __alloc, _Iter1 __first1, _Sent1 __last1, _Iter2 __first2) {
587 static_assert(__is_cpp17_move_insertable<_Alloc>::value,
588 "The specified type does not meet the requirements of Cpp17MoveInsertable");
589#ifndef _LIBCPP_NO_EXCEPTIONS
590 auto __destruct_first = __first2;
591 try {
592#endif
593 while (__first1 != __last1) {
594#ifndef _LIBCPP_NO_EXCEPTIONS
595 allocator_traits<_Alloc>::construct(__alloc, std::__to_address(__first2), std::move_if_noexcept(*__first1));
596#else
597 allocator_traits<_Alloc>::construct(__alloc, std::__to_address(__first2), std::move(*__first1));
598#endif
599 ++__first1;
600 ++__first2;
601 }
602#ifndef _LIBCPP_NO_EXCEPTIONS
603 } catch (...) {
604 _AllocatorDestroyRangeReverse<_Alloc, _Iter2>(__alloc, __destruct_first, __first2)();
605 throw;
606 }
607#endif
608 return __first2;
609}
610
611template <class _Alloc, class _Type>
612struct __allocator_has_trivial_move_construct : _Not<__has_construct<_Alloc, _Type*, _Type&&> > {};
613
614template <class _Type>
615struct __allocator_has_trivial_move_construct<allocator<_Type>, _Type> : true_type {};
616
617#ifndef _LIBCPP_COMPILER_GCC
618template <
619 class _Alloc,
620 class _Iter1,
621 class _Iter2,
622 class _Type = typename iterator_traits<_Iter1>::value_type,
623 class = __enable_if_t<is_trivially_move_constructible<_Type>::value && is_trivially_move_assignable<_Type>::value &&
624 __allocator_has_trivial_move_construct<_Alloc, _Type>::value> >
625_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _Iter2
626__uninitialized_allocator_move_if_noexcept(_Alloc&, _Iter1 __first1, _Iter1 __last1, _Iter2 __first2) {
627 if (__libcpp_is_constant_evaluated()) {
628 while (__first1 != __last1) {
629 std::__construct_at(std::__to_address(__first2), std::move(*__first1));
630 ++__first1;
631 ++__first2;
632 }
633 return __first2;
634 } else {
635 return std::move(__first1, __last1, __first2);
636 }
637}
638#endif // _LIBCPP_COMPILER_GCC
639
348640_LIBCPP_END_NAMESPACE_STD
349641
350642#endif // _LIBCPP___MEMORY_UNINITIALIZED_ALGORITHMS_H
lib/libcxx/include/__memory/unique_ptr.h+8-19
......@@ -13,20 +13,16 @@
1313#include <__config>
1414#include <__functional/hash.h>
1515#include <__functional/operations.h>
16#include <__functional_base>
1716#include <__memory/allocator_traits.h> // __pointer
17#include <__memory/auto_ptr.h>
1818#include <__memory/compressed_pair.h>
1919#include <__utility/forward.h>
20#include <__utility/move.h>
2021#include <cstddef>
2122#include <type_traits>
22#include <utility>
23
24#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
25# include <__memory/auto_ptr.h>
26#endif
2723
2824#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
29#pragma GCC system_header
25# pragma GCC system_header
3026#endif
3127
3228_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -47,10 +43,8 @@ struct _LIBCPP_TEMPLATE_VIS default_delete {
4743 0) _NOEXCEPT {}
4844
4945 _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __ptr) const _NOEXCEPT {
50 static_assert(sizeof(_Tp) > 0,
51 "default_delete can not delete incomplete type");
52 static_assert(!is_void<_Tp>::value,
53 "default_delete can not delete incomplete type");
46 static_assert(sizeof(_Tp) >= 0, "cannot delete an incomplete type");
47 static_assert(!is_void<_Tp>::value, "cannot delete an incomplete type");
5448 delete __ptr;
5549 }
5650};
......@@ -78,10 +72,7 @@ public:
7872 _LIBCPP_INLINE_VISIBILITY
7973 typename _EnableIfConvertible<_Up>::type
8074 operator()(_Up* __ptr) const _NOEXCEPT {
81 static_assert(sizeof(_Tp) > 0,
82 "default_delete can not delete incomplete type");
83 static_assert(!is_void<_Tp>::value,
84 "default_delete can not delete void type");
75 static_assert(sizeof(_Up) >= 0, "cannot delete an incomplete type");
8576 delete[] __ptr;
8677 }
8778};
......@@ -144,7 +135,7 @@ private:
144135 typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type;
145136
146137 template <bool _Dummy, class _Deleter = typename __dependent_type<
147 __identity<deleter_type>, _Dummy>::type>
138 __type_identity<deleter_type>, _Dummy>::type>
148139 using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG =
149140 typename enable_if<is_default_constructible<_Deleter>::value &&
150141 !is_pointer<_Deleter>::value>::type;
......@@ -264,7 +255,6 @@ public:
264255 unique_ptr& operator=(unique_ptr const&) = delete;
265256#endif
266257
267
268258 _LIBCPP_INLINE_VISIBILITY
269259 ~unique_ptr() { reset(); }
270260
......@@ -359,7 +349,7 @@ private:
359349 typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type;
360350
361351 template <bool _Dummy, class _Deleter = typename __dependent_type<
362 __identity<deleter_type>, _Dummy>::type>
352 __type_identity<deleter_type>, _Dummy>::type>
363353 using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG =
364354 typename enable_if<is_default_constructible<_Deleter>::value &&
365355 !is_pointer<_Deleter>::value>::type;
......@@ -486,7 +476,6 @@ public:
486476 unique_ptr(unique_ptr const&) = delete;
487477 unique_ptr& operator=(unique_ptr const&) = delete;
488478#endif
489
490479public:
491480 _LIBCPP_INLINE_VISIBILITY
492481 ~unique_ptr() { reset(); }
lib/libcxx/include/__memory/uses_allocator.h+4-5
......@@ -15,7 +15,7 @@
1515#include <type_traits>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -24,11 +24,10 @@ template <class _Tp>
2424struct __has_allocator_type
2525{
2626private:
27 struct __two {char __lx; char __lxx;};
28 template <class _Up> static __two __test(...);
29 template <class _Up> static char __test(typename _Up::allocator_type* = 0);
27 template <class _Up> static false_type __test(...);
28 template <class _Up> static true_type __test(typename _Up::allocator_type* = 0);
3029public:
31 static const bool value = sizeof(__test<_Tp>(0)) == 1;
30 static const bool value = decltype(__test<_Tp>(0))::value;
3231};
3332
3433template <class _Tp, class _Alloc, bool = __has_allocator_type<_Tp>::value>
lib/libcxx/include/__mutex_base+7-12
......@@ -10,15 +10,18 @@
1010#ifndef _LIBCPP___MUTEX_BASE
1111#define _LIBCPP___MUTEX_BASE
1212
13#include <__chrono/duration.h>
14#include <__chrono/steady_clock.h>
15#include <__chrono/system_clock.h>
16#include <__chrono/time_point.h>
1317#include <__config>
1418#include <__threading_support>
15#include <chrono>
1619#include <ratio>
1720#include <system_error>
1821#include <time.h>
1922
2023#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21#pragma GCC system_header
24# pragma GCC system_header
2225#endif
2326
2427_LIBCPP_PUSH_MACROS
......@@ -335,11 +338,7 @@ private:
335338
336339template <class _Rep, class _Period>
337340inline _LIBCPP_INLINE_VISIBILITY
338typename enable_if
339<
340 is_floating_point<_Rep>::value,
341 chrono::nanoseconds
342>::type
341__enable_if_t<is_floating_point<_Rep>::value, chrono::nanoseconds>
343342__safe_nanosecond_cast(chrono::duration<_Rep, _Period> __d)
344343{
345344 using namespace chrono;
......@@ -362,11 +361,7 @@ __safe_nanosecond_cast(chrono::duration<_Rep, _Period> __d)
362361
363362template <class _Rep, class _Period>
364363inline _LIBCPP_INLINE_VISIBILITY
365typename enable_if
366<
367 !is_floating_point<_Rep>::value,
368 chrono::nanoseconds
369>::type
364__enable_if_t<!is_floating_point<_Rep>::value, chrono::nanoseconds>
370365__safe_nanosecond_cast(chrono::duration<_Rep, _Period> __d)
371366{
372367 using namespace chrono;
lib/libcxx/include/__node_handle+2-2
......@@ -58,13 +58,13 @@ public:
5858
5959*/
6060
61#include <__assert>
6162#include <__config>
62#include <__debug>
6363#include <memory>
6464#include <optional>
6565
6666#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
67#pragma GCC system_header
67# pragma GCC system_header
6868#endif
6969
7070_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__nullptr deleted-61
......@@ -1,61 +0,0 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_NULLPTR
11#define _LIBCPP_NULLPTR
12
13#include <__config>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16#pragma GCC system_header
17#endif
18
19#ifdef _LIBCPP_HAS_NO_NULLPTR
20
21_LIBCPP_BEGIN_NAMESPACE_STD
22
23struct _LIBCPP_TEMPLATE_VIS nullptr_t
24{
25 void* __lx;
26
27 struct __nat {int __for_bool_;};
28
29 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR nullptr_t() : __lx(0) {}
30 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR nullptr_t(int __nat::*) : __lx(0) {}
31
32 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR operator int __nat::*() const {return 0;}
33
34 template <class _Tp>
35 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
36 operator _Tp* () const {return 0;}
37
38 template <class _Tp, class _Up>
39 _LIBCPP_INLINE_VISIBILITY
40 operator _Tp _Up::* () const {return 0;}
41
42 friend _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bool operator==(nullptr_t, nullptr_t) {return true;}
43 friend _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bool operator!=(nullptr_t, nullptr_t) {return false;}
44};
45
46inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR nullptr_t __get_nullptr_t() {return nullptr_t(0);}
47
48#define nullptr _VSTD::__get_nullptr_t()
49
50_LIBCPP_END_NAMESPACE_STD
51
52#else // _LIBCPP_HAS_NO_NULLPTR
53
54namespace std
55{
56 typedef decltype(nullptr) nullptr_t;
57} // namespace std
58
59#endif // _LIBCPP_HAS_NO_NULLPTR
60
61#endif // _LIBCPP_NULLPTR
lib/libcxx/include/__numeric/accumulate.h+1-1
......@@ -14,7 +14,7 @@
1414#include <__utility/move.h>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
17# pragma GCC system_header
1818#endif
1919
2020_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__numeric/gcd_lcm.h+1-1
......@@ -10,8 +10,8 @@
1010#ifndef _LIBCPP___NUMERIC_GCD_LCM_H
1111#define _LIBCPP___NUMERIC_GCD_LCM_H
1212
13#include <__assert>
1314#include <__config>
14#include <__debug>
1515#include <limits>
1616#include <type_traits>
1717
lib/libcxx/include/__numeric/inner_product.h+1-1
......@@ -14,7 +14,7 @@
1414#include <__utility/move.h>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
17# pragma GCC system_header
1818#endif
1919
2020_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__numeric/iota.h+3-3
......@@ -21,10 +21,10 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2121template <class _ForwardIterator, class _Tp>
2222_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
2323void
24iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value_)
24iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value)
2525{
26 for (; __first != __last; ++__first, (void) ++__value_)
27 *__first = __value_;
26 for (; __first != __last; ++__first, (void) ++__value)
27 *__first = __value;
2828}
2929
3030_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__random/bernoulli_distribution.h+3-1
......@@ -10,11 +10,12 @@
1010#define _LIBCPP___RANDOM_BERNOULLI_DISTRIBUTION_H
1111
1212#include <__config>
13#include <__random/is_valid.h>
1314#include <__random/uniform_real_distribution.h>
1415#include <iosfwd>
1516
1617#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
18# pragma GCC system_header
1819#endif
1920
2021_LIBCPP_PUSH_MACROS
......@@ -103,6 +104,7 @@ inline
103104bernoulli_distribution::result_type
104105bernoulli_distribution::operator()(_URNG& __g, const param_type& __p)
105106{
107 static_assert(__libcpp_random_is_valid_urng<_URNG>::value, "");
106108 uniform_real_distribution<double> __gen;
107109 return __gen(__g) < __p.p();
108110}
lib/libcxx/include/__random/binomial_distribution.h+4-1
......@@ -10,12 +10,13 @@
1010#define _LIBCPP___RANDOM_BINOMIAL_DISTRIBUTION_H
1111
1212#include <__config>
13#include <__random/is_valid.h>
1314#include <__random/uniform_real_distribution.h>
1415#include <cmath>
1516#include <iosfwd>
1617
1718#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
19# pragma GCC system_header
1920#endif
2021
2122_LIBCPP_PUSH_MACROS
......@@ -26,6 +27,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2627template<class _IntType = int>
2728class _LIBCPP_TEMPLATE_VIS binomial_distribution
2829{
30 static_assert(__libcpp_random_is_valid_inttype<_IntType>::value, "IntType must be a supported integer type");
2931public:
3032 // types
3133 typedef _IntType result_type;
......@@ -146,6 +148,7 @@ template<class _URNG>
146148_IntType
147149binomial_distribution<_IntType>::operator()(_URNG& __g, const param_type& __pr)
148150{
151 static_assert(__libcpp_random_is_valid_urng<_URNG>::value, "");
149152 if (__pr.__t_ == 0 || __pr.__p_ == 0)
150153 return 0;
151154 if (__pr.__p_ == 1)
lib/libcxx/include/__random/cauchy_distribution.h+3-1
......@@ -10,13 +10,14 @@
1010#define _LIBCPP___RANDOM_CAUCHY_DISTRIBUTION_H
1111
1212#include <__config>
13#include <__random/is_valid.h>
1314#include <__random/uniform_real_distribution.h>
1415#include <cmath>
1516#include <iosfwd>
1617#include <limits>
1718
1819#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
20# pragma GCC system_header
2021#endif
2122
2223_LIBCPP_PUSH_MACROS
......@@ -116,6 +117,7 @@ inline
116117_RealType
117118cauchy_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
118119{
120 static_assert(__libcpp_random_is_valid_urng<_URNG>::value, "");
119121 uniform_real_distribution<result_type> __gen;
120122 // purposefully let tan arg get as close to pi/2 as it wants, tan will return a finite
121123 return __p.a() + __p.b() * _VSTD::tan(3.1415926535897932384626433832795 * __gen(__g));
lib/libcxx/include/__random/chi_squared_distribution.h+1-1
......@@ -15,7 +15,7 @@
1515#include <limits>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121_LIBCPP_PUSH_MACROS
lib/libcxx/include/__random/clamp_to_integral.h+1-1
......@@ -15,7 +15,7 @@
1515#include <type_traits>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121_LIBCPP_PUSH_MACROS
lib/libcxx/include/__random/default_random_engine.h+1-1
......@@ -13,7 +13,7 @@
1313#include <__random/linear_congruential_engine.h>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16#pragma GCC system_header
16# pragma GCC system_header
1717#endif
1818
1919_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__random/discard_block_engine.h+1-1
......@@ -17,7 +17,7 @@
1717#include <type_traits>
1818
1919#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20#pragma GCC system_header
20# pragma GCC system_header
2121#endif
2222
2323_LIBCPP_PUSH_MACROS
lib/libcxx/include/__random/discrete_distribution.h+4-1
......@@ -11,6 +11,7 @@
1111
1212#include <__algorithm/upper_bound.h>
1313#include <__config>
14#include <__random/is_valid.h>
1415#include <__random/uniform_real_distribution.h>
1516#include <cstddef>
1617#include <iosfwd>
......@@ -18,7 +19,7 @@
1819#include <vector>
1920
2021#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21#pragma GCC system_header
22# pragma GCC system_header
2223#endif
2324
2425_LIBCPP_PUSH_MACROS
......@@ -29,6 +30,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2930template<class _IntType = int>
3031class _LIBCPP_TEMPLATE_VIS discrete_distribution
3132{
33 static_assert(__libcpp_random_is_valid_inttype<_IntType>::value, "IntType must be a supported integer type");
3234public:
3335 // types
3436 typedef _IntType result_type;
......@@ -211,6 +213,7 @@ template<class _URNG>
211213_IntType
212214discrete_distribution<_IntType>::operator()(_URNG& __g, const param_type& __p)
213215{
216 static_assert(__libcpp_random_is_valid_urng<_URNG>::value, "");
214217 uniform_real_distribution<double> __gen;
215218 return static_cast<_IntType>(
216219 _VSTD::upper_bound(__p.__p_.begin(), __p.__p_.end(), __gen(__g)) -
lib/libcxx/include/__random/exponential_distribution.h+3-1
......@@ -11,13 +11,14 @@
1111
1212#include <__config>
1313#include <__random/generate_canonical.h>
14#include <__random/is_valid.h>
1415#include <__random/uniform_real_distribution.h>
1516#include <cmath>
1617#include <iosfwd>
1718#include <limits>
1819
1920#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20#pragma GCC system_header
21# pragma GCC system_header
2122#endif
2223
2324_LIBCPP_PUSH_MACROS
......@@ -109,6 +110,7 @@ template<class _URNG>
109110_RealType
110111exponential_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
111112{
113 static_assert(__libcpp_random_is_valid_urng<_URNG>::value, "");
112114 return -_VSTD::log
113115 (
114116 result_type(1) -
lib/libcxx/include/__random/extreme_value_distribution.h+3-1
......@@ -10,13 +10,14 @@
1010#define _LIBCPP___RANDOM_EXTREME_VALUE_DISTRIBUTION_H
1111
1212#include <__config>
13#include <__random/is_valid.h>
1314#include <__random/uniform_real_distribution.h>
1415#include <cmath>
1516#include <iosfwd>
1617#include <limits>
1718
1819#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
20# pragma GCC system_header
2021#endif
2122
2223_LIBCPP_PUSH_MACROS
......@@ -116,6 +117,7 @@ template<class _URNG>
116117_RealType
117118extreme_value_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
118119{
120 static_assert(__libcpp_random_is_valid_urng<_URNG>::value, "");
119121 return __p.a() - __p.b() *
120122 _VSTD::log(-_VSTD::log(1-uniform_real_distribution<result_type>()(__g)));
121123}
lib/libcxx/include/__random/fisher_f_distribution.h+3-1
......@@ -11,11 +11,12 @@
1111
1212#include <__config>
1313#include <__random/gamma_distribution.h>
14#include <__random/is_valid.h>
1415#include <iosfwd>
1516#include <limits>
1617
1718#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
19# pragma GCC system_header
1920#endif
2021
2122_LIBCPP_PUSH_MACROS
......@@ -114,6 +115,7 @@ template<class _URNG>
114115_RealType
115116fisher_f_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
116117{
118 static_assert(__libcpp_random_is_valid_urng<_URNG>::value, "");
117119 gamma_distribution<result_type> __gdm(__p.m() * result_type(.5));
118120 gamma_distribution<result_type> __gdn(__p.n() * result_type(.5));
119121 return __p.n() * __gdm(__g) / (__p.m() * __gdn(__g));
lib/libcxx/include/__random/gamma_distribution.h+3-1
......@@ -11,13 +11,14 @@
1111
1212#include <__config>
1313#include <__random/exponential_distribution.h>
14#include <__random/is_valid.h>
1415#include <__random/uniform_real_distribution.h>
1516#include <cmath>
1617#include <iosfwd>
1718#include <limits>
1819
1920#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20#pragma GCC system_header
21# pragma GCC system_header
2122#endif
2223
2324_LIBCPP_PUSH_MACROS
......@@ -117,6 +118,7 @@ template<class _URNG>
117118_RealType
118119gamma_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
119120{
121 static_assert(__libcpp_random_is_valid_urng<_URNG>::value, "");
120122 result_type __a = __p.alpha();
121123 uniform_real_distribution<result_type> __gen(0, 1);
122124 exponential_distribution<result_type> __egen;
lib/libcxx/include/__random/generate_canonical.h+1-1
......@@ -16,7 +16,7 @@
1616#include <limits>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
19# pragma GCC system_header
2020#endif
2121
2222_LIBCPP_PUSH_MACROS
lib/libcxx/include/__random/geometric_distribution.h+3-1
......@@ -10,12 +10,13 @@
1010#define _LIBCPP___RANDOM_GEOMETRIC_DISTRIBUTION_H
1111
1212#include <__config>
13#include <__random/is_valid.h>
1314#include <__random/negative_binomial_distribution.h>
1415#include <iosfwd>
1516#include <limits>
1617
1718#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
19# pragma GCC system_header
1920#endif
2021
2122_LIBCPP_PUSH_MACROS
......@@ -26,6 +27,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2627template<class _IntType = int>
2728class _LIBCPP_TEMPLATE_VIS geometric_distribution
2829{
30 static_assert(__libcpp_random_is_valid_inttype<_IntType>::value, "IntType must be a supported integer type");
2931public:
3032 // types
3133 typedef _IntType result_type;
lib/libcxx/include/__random/independent_bits_engine.h+1-1
......@@ -18,7 +18,7 @@
1818#include <type_traits>
1919
2020#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21#pragma GCC system_header
21# pragma GCC system_header
2222#endif
2323
2424_LIBCPP_PUSH_MACROS
lib/libcxx/include/__random/is_seed_sequence.h+1-1
......@@ -13,7 +13,7 @@
1313#include <type_traits>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16#pragma GCC system_header
16# pragma GCC system_header
1717#endif
1818
1919_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__random/is_valid.h created+61
......@@ -0,0 +1,61 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___RANDOM_IS_VALID_H
10#define _LIBCPP___RANDOM_IS_VALID_H
11
12#include <__config>
13#include <cstdint>
14#include <type_traits>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
20_LIBCPP_BEGIN_NAMESPACE_STD
21
22// [rand.req.genl]/1.5:
23// The effect of instantiating a template that has a template type parameter
24// named IntType is undefined unless the corresponding template argument is
25// cv-unqualified and is one of short, int, long, long long, unsigned short,
26// unsigned int, unsigned long, or unsigned long long.
27
28template<class> struct __libcpp_random_is_valid_inttype : false_type {};
29template<> struct __libcpp_random_is_valid_inttype<int8_t> : true_type {}; // extension
30template<> struct __libcpp_random_is_valid_inttype<short> : true_type {};
31template<> struct __libcpp_random_is_valid_inttype<int> : true_type {};
32template<> struct __libcpp_random_is_valid_inttype<long> : true_type {};
33template<> struct __libcpp_random_is_valid_inttype<long long> : true_type {};
34template<> struct __libcpp_random_is_valid_inttype<uint8_t> : true_type {}; // extension
35template<> struct __libcpp_random_is_valid_inttype<unsigned short> : true_type {};
36template<> struct __libcpp_random_is_valid_inttype<unsigned int> : true_type {};
37template<> struct __libcpp_random_is_valid_inttype<unsigned long> : true_type {};
38template<> struct __libcpp_random_is_valid_inttype<unsigned long long> : true_type {};
39
40#ifndef _LIBCPP_HAS_NO_INT128
41template<> struct __libcpp_random_is_valid_inttype<__int128_t> : true_type {}; // extension
42template<> struct __libcpp_random_is_valid_inttype<__uint128_t> : true_type {}; // extension
43#endif // _LIBCPP_HAS_NO_INT128
44
45// [rand.req.urng]/3:
46// A class G meets the uniform random bit generator requirements if G models
47// uniform_random_bit_generator, invoke_result_t<G&> is an unsigned integer type,
48// and G provides a nested typedef-name result_type that denotes the same type
49// as invoke_result_t<G&>.
50// (In particular, reject URNGs with signed result_types; our distributions cannot
51// handle such generator types.)
52
53template<class, class = void> struct __libcpp_random_is_valid_urng : false_type {};
54template<class _Gp> struct __libcpp_random_is_valid_urng<_Gp, __enable_if_t<
55 is_unsigned<typename _Gp::result_type>::value &&
56 _IsSame<decltype(declval<_Gp&>()()), typename _Gp::result_type>::value
57> > : true_type {};
58
59_LIBCPP_END_NAMESPACE_STD
60
61#endif // _LIBCPP___RANDOM_IS_VALID_H
lib/libcxx/include/__random/knuth_b.h+1-1
......@@ -14,7 +14,7 @@
1414#include <__random/shuffle_order_engine.h>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
17# pragma GCC system_header
1818#endif
1919
2020_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__random/linear_congruential_engine.h+3-3
......@@ -16,7 +16,7 @@
1616#include <type_traits>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
19# pragma GCC system_header
2020#endif
2121
2222_LIBCPP_PUSH_MACROS
......@@ -218,8 +218,8 @@ private:
218218 static_assert(__m == 0 || __c < __m, "linear_congruential_engine invalid parameters");
219219 static_assert(is_unsigned<_UIntType>::value, "_UIntType must be unsigned type");
220220public:
221 static _LIBCPP_CONSTEXPR const result_type _Min = __c == 0u ? 1u: 0u;
222 static _LIBCPP_CONSTEXPR const result_type _Max = __m - 1u;
221 static _LIBCPP_CONSTEXPR const result_type _Min = __c == 0u ? 1u : 0u;
222 static _LIBCPP_CONSTEXPR const result_type _Max = __m - _UIntType(1u);
223223 static_assert(_Min < _Max, "linear_congruential_engine invalid parameters");
224224
225225 // engine characteristics
lib/libcxx/include/__random/log2.h+1-1
......@@ -14,7 +14,7 @@
1414#include <type_traits>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
17# pragma GCC system_header
1818#endif
1919
2020_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__random/lognormal_distribution.h+1-1
......@@ -16,7 +16,7 @@
1616#include <limits>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
19# pragma GCC system_header
2020#endif
2121
2222_LIBCPP_PUSH_MACROS
lib/libcxx/include/__random/mersenne_twister_engine.h+1-1
......@@ -20,7 +20,7 @@
2020#include <type_traits>
2121
2222#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23#pragma GCC system_header
23# pragma GCC system_header
2424#endif
2525
2626_LIBCPP_PUSH_MACROS
lib/libcxx/include/__random/negative_binomial_distribution.h+9-2
......@@ -12,12 +12,13 @@
1212#include <__config>
1313#include <__random/bernoulli_distribution.h>
1414#include <__random/gamma_distribution.h>
15#include <__random/is_valid.h>
1516#include <__random/poisson_distribution.h>
1617#include <iosfwd>
1718#include <limits>
1819
1920#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20#pragma GCC system_header
21# pragma GCC system_header
2122#endif
2223
2324_LIBCPP_PUSH_MACROS
......@@ -28,6 +29,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2829template<class _IntType = int>
2930class _LIBCPP_TEMPLATE_VIS negative_binomial_distribution
3031{
32 static_assert(__libcpp_random_is_valid_inttype<_IntType>::value, "IntType must be a supported integer type");
3133public:
3234 // types
3335 typedef _IntType result_type;
......@@ -116,9 +118,12 @@ template<class _URNG>
116118_IntType
117119negative_binomial_distribution<_IntType>::operator()(_URNG& __urng, const param_type& __pr)
118120{
121 static_assert(__libcpp_random_is_valid_urng<_URNG>::value, "");
119122 result_type __k = __pr.k();
120123 double __p = __pr.p();
121 if (__k <= 21 * __p)
124 // When the number of bits in _IntType is small, we are too likely to
125 // overflow __f below to use this technique.
126 if (__k <= 21 * __p && sizeof(_IntType) > 1)
122127 {
123128 bernoulli_distribution __gen(__p);
124129 result_type __f = 0;
......@@ -130,6 +135,8 @@ negative_binomial_distribution<_IntType>::operator()(_URNG& __urng, const param_
130135 else
131136 ++__f;
132137 }
138 _LIBCPP_ASSERT(__f >= 0, "std::negative_binomial_distribution should never produce negative values. "
139 "This is almost certainly a signed integer overflow issue on __f.");
133140 return __f;
134141 }
135142 return poisson_distribution<result_type>(gamma_distribution<double>
lib/libcxx/include/__random/normal_distribution.h+3-1
......@@ -10,13 +10,14 @@
1010#define _LIBCPP___RANDOM_NORMAL_DISTRIBUTION_H
1111
1212#include <__config>
13#include <__random/is_valid.h>
1314#include <__random/uniform_real_distribution.h>
1415#include <cmath>
1516#include <iosfwd>
1617#include <limits>
1718
1819#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
20# pragma GCC system_header
2021#endif
2122
2223_LIBCPP_PUSH_MACROS
......@@ -131,6 +132,7 @@ template<class _URNG>
131132_RealType
132133normal_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
133134{
135 static_assert(__libcpp_random_is_valid_urng<_URNG>::value, "");
134136 result_type _Up;
135137 if (_V_hot_)
136138 {
lib/libcxx/include/__random/piecewise_constant_distribution.h+13-11
......@@ -11,13 +11,14 @@
1111
1212#include <__algorithm/upper_bound.h>
1313#include <__config>
14#include <__random/is_valid.h>
1415#include <__random/uniform_real_distribution.h>
1516#include <iosfwd>
1617#include <numeric>
1718#include <vector>
1819
1920#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20#pragma GCC system_header
21# pragma GCC system_header
2122#endif
2223
2324_LIBCPP_PUSH_MACROS
......@@ -42,8 +43,8 @@ public:
4243
4344 param_type();
4445 template<class _InputIteratorB, class _InputIteratorW>
45 param_type(_InputIteratorB __fB, _InputIteratorB __lB,
46 _InputIteratorW __fW);
46 param_type(_InputIteratorB __f_b, _InputIteratorB __l_b,
47 _InputIteratorW __f_w);
4748#ifndef _LIBCPP_CXX03_LANG
4849 template<class _UnaryOperation>
4950 param_type(initializer_list<result_type> __bl, _UnaryOperation __fw);
......@@ -93,10 +94,10 @@ public:
9394 piecewise_constant_distribution() {}
9495 template<class _InputIteratorB, class _InputIteratorW>
9596 _LIBCPP_INLINE_VISIBILITY
96 piecewise_constant_distribution(_InputIteratorB __fB,
97 _InputIteratorB __lB,
98 _InputIteratorW __fW)
99 : __p_(__fB, __lB, __fW) {}
97 piecewise_constant_distribution(_InputIteratorB __f_b,
98 _InputIteratorB __l_b,
99 _InputIteratorW __f_w)
100 : __p_(__f_b, __l_b, __f_w) {}
100101
101102#ifndef _LIBCPP_CXX03_LANG
102103 template<class _UnaryOperation>
......@@ -214,8 +215,8 @@ piecewise_constant_distribution<_RealType>::param_type::param_type()
214215template<class _RealType>
215216template<class _InputIteratorB, class _InputIteratorW>
216217piecewise_constant_distribution<_RealType>::param_type::param_type(
217 _InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW)
218 : __b_(__fB, __lB)
218 _InputIteratorB __f_b, _InputIteratorB __l_b, _InputIteratorW __f_w)
219 : __b_(__f_b, __l_b)
219220{
220221 if (__b_.size() < 2)
221222 {
......@@ -228,8 +229,8 @@ piecewise_constant_distribution<_RealType>::param_type::param_type(
228229 else
229230 {
230231 __densities_.reserve(__b_.size() - 1);
231 for (size_t __i = 0; __i < __b_.size() - 1; ++__i, ++__fW)
232 __densities_.push_back(*__fW);
232 for (size_t __i = 0; __i < __b_.size() - 1; ++__i, ++__f_w)
233 __densities_.push_back(*__f_w);
233234 __init();
234235 }
235236}
......@@ -284,6 +285,7 @@ template<class _URNG>
284285_RealType
285286piecewise_constant_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
286287{
288 static_assert(__libcpp_random_is_valid_urng<_URNG>::value, "");
287289 typedef uniform_real_distribution<result_type> _Gen;
288290 result_type __u = _Gen()(__g);
289291 ptrdiff_t __k = _VSTD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(),
lib/libcxx/include/__random/piecewise_linear_distribution.h+13-11
......@@ -11,13 +11,14 @@
1111
1212#include <__algorithm/upper_bound.h>
1313#include <__config>
14#include <__random/is_valid.h>
1415#include <__random/uniform_real_distribution.h>
1516#include <iosfwd>
1617#include <numeric>
1718#include <vector>
1819
1920#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20#pragma GCC system_header
21# pragma GCC system_header
2122#endif
2223
2324_LIBCPP_PUSH_MACROS
......@@ -42,8 +43,8 @@ public:
4243
4344 param_type();
4445 template<class _InputIteratorB, class _InputIteratorW>
45 param_type(_InputIteratorB __fB, _InputIteratorB __lB,
46 _InputIteratorW __fW);
46 param_type(_InputIteratorB __f_b, _InputIteratorB __l_b,
47 _InputIteratorW __f_w);
4748#ifndef _LIBCPP_CXX03_LANG
4849 template<class _UnaryOperation>
4950 param_type(initializer_list<result_type> __bl, _UnaryOperation __fw);
......@@ -93,10 +94,10 @@ public:
9394 piecewise_linear_distribution() {}
9495 template<class _InputIteratorB, class _InputIteratorW>
9596 _LIBCPP_INLINE_VISIBILITY
96 piecewise_linear_distribution(_InputIteratorB __fB,
97 _InputIteratorB __lB,
98 _InputIteratorW __fW)
99 : __p_(__fB, __lB, __fW) {}
97 piecewise_linear_distribution(_InputIteratorB __f_b,
98 _InputIteratorB __l_b,
99 _InputIteratorW __f_w)
100 : __p_(__f_b, __l_b, __f_w) {}
100101
101102#ifndef _LIBCPP_CXX03_LANG
102103 template<class _UnaryOperation>
......@@ -218,8 +219,8 @@ piecewise_linear_distribution<_RealType>::param_type::param_type()
218219template<class _RealType>
219220template<class _InputIteratorB, class _InputIteratorW>
220221piecewise_linear_distribution<_RealType>::param_type::param_type(
221 _InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW)
222 : __b_(__fB, __lB)
222 _InputIteratorB __f_b, _InputIteratorB __l_b, _InputIteratorW __f_w)
223 : __b_(__f_b, __l_b)
223224{
224225 if (__b_.size() < 2)
225226 {
......@@ -232,8 +233,8 @@ piecewise_linear_distribution<_RealType>::param_type::param_type(
232233 else
233234 {
234235 __densities_.reserve(__b_.size());
235 for (size_t __i = 0; __i < __b_.size(); ++__i, ++__fW)
236 __densities_.push_back(*__fW);
236 for (size_t __i = 0; __i < __b_.size(); ++__i, ++__f_w)
237 __densities_.push_back(*__f_w);
237238 __init();
238239 }
239240}
......@@ -289,6 +290,7 @@ template<class _URNG>
289290_RealType
290291piecewise_linear_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
291292{
293 static_assert(__libcpp_random_is_valid_urng<_URNG>::value, "");
292294 typedef uniform_real_distribution<result_type> _Gen;
293295 result_type __u = _Gen()(__g);
294296 ptrdiff_t __k = _VSTD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(),
lib/libcxx/include/__random/poisson_distribution.h+4-1
......@@ -12,6 +12,7 @@
1212#include <__config>
1313#include <__random/clamp_to_integral.h>
1414#include <__random/exponential_distribution.h>
15#include <__random/is_valid.h>
1516#include <__random/normal_distribution.h>
1617#include <__random/uniform_real_distribution.h>
1718#include <cmath>
......@@ -19,7 +20,7 @@
1920#include <limits>
2021
2122#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22#pragma GCC system_header
23# pragma GCC system_header
2324#endif
2425
2526_LIBCPP_PUSH_MACROS
......@@ -30,6 +31,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
3031template<class _IntType = int>
3132class _LIBCPP_TEMPLATE_VIS poisson_distribution
3233{
34 static_assert(__libcpp_random_is_valid_inttype<_IntType>::value, "IntType must be a supported integer type");
3335public:
3436 // types
3537 typedef _IntType result_type;
......@@ -157,6 +159,7 @@ template<class _URNG>
157159_IntType
158160poisson_distribution<_IntType>::operator()(_URNG& __urng, const param_type& __pr)
159161{
162 static_assert(__libcpp_random_is_valid_urng<_URNG>::value, "");
160163 double __tx;
161164 uniform_real_distribution<double> __urd;
162165 if (__pr.__mean_ < 10)
lib/libcxx/include/__random/random_device.h+4-8
......@@ -13,7 +13,7 @@
1313#include <string>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16#pragma GCC system_header
16# pragma GCC system_header
1717#endif
1818
1919_LIBCPP_PUSH_MACROS
......@@ -28,10 +28,8 @@ class _LIBCPP_TYPE_VIS random_device
2828#ifdef _LIBCPP_USING_DEV_RANDOM
2929 int __f_;
3030#elif !defined(_LIBCPP_ABI_NO_RANDOM_DEVICE_COMPATIBILITY_LAYOUT)
31# if defined(__clang__)
32# pragma clang diagnostic push
33# pragma clang diagnostic ignored "-Wunused-private-field"
34# endif
31 _LIBCPP_DIAGNOSTIC_PUSH
32 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wunused-private-field")
3533
3634 // Apple platforms used to use the `_LIBCPP_USING_DEV_RANDOM` code path, and now
3735 // use `arc4random()` as of this comment. In order to avoid breaking the ABI, we
......@@ -42,9 +40,7 @@ class _LIBCPP_TYPE_VIS random_device
4240
4341 // ... vendors can add workarounds here if they switch to a different representation ...
4442
45# if defined(__clang__)
46# pragma clang diagnostic pop
47# endif
43 _LIBCPP_DIAGNOSTIC_POP
4844#endif
4945
5046public:
lib/libcxx/include/__random/ranlux.h+1-1
......@@ -15,7 +15,7 @@
1515#include <cstdint>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__random/seed_seq.h+50-26
......@@ -17,7 +17,7 @@
1717#include <vector>
1818
1919#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20#pragma GCC system_header
20# pragma GCC system_header
2121#endif
2222
2323_LIBCPP_PUSH_MACROS
......@@ -109,39 +109,63 @@ seed_seq::generate(_RandomAccessIterator __first, _RandomAccessIterator __last)
109109 __first[__q] += __r;
110110 __first[0] = __r;
111111 }
112 // Initialize indexing terms used with if statements as an optimization to
113 // avoid calculating modulo n on every loop iteration for each term.
114 size_t __kmodn = 0; // __k % __n
115 size_t __k1modn = __n - 1; // (__k - 1) % __n
116 size_t __kpmodn = __p % __n; // (__k + __p) % __n
117 size_t __kqmodn = __q % __n; // (__k + __q) % __n
118
112119 for (size_t __k = 1; __k <= __s; ++__k)
113120 {
114 const size_t __kmodn = __k % __n;
115 const size_t __kpmodn = (__k + __p) % __n;
116 result_type __r = 1664525 * _Tp(__first[__kmodn] ^ __first[__kpmodn]
117 ^ __first[(__k - 1) % __n]);
118 __first[__kpmodn] += __r;
119 __r += __kmodn + __v_[__k-1];
120 __first[(__k + __q) % __n] += __r;
121 __first[__kmodn] = __r;
121 if (++__kmodn == __n)
122 __kmodn = 0;
123 if (++__k1modn == __n)
124 __k1modn = 0;
125 if (++__kpmodn == __n)
126 __kpmodn = 0;
127 if (++__kqmodn == __n)
128 __kqmodn = 0;
129
130 result_type __r = 1664525 * _Tp(__first[__kmodn] ^ __first[__kpmodn] ^ __first[__k1modn]);
131 __first[__kpmodn] += __r;
132 __r += __kmodn + __v_[__k - 1];
133 __first[__kqmodn] += __r;
134 __first[__kmodn] = __r;
122135 }
123136 for (size_t __k = __s + 1; __k < __m; ++__k)
124137 {
125 const size_t __kmodn = __k % __n;
126 const size_t __kpmodn = (__k + __p) % __n;
127 result_type __r = 1664525 * _Tp(__first[__kmodn] ^ __first[__kpmodn]
128 ^ __first[(__k - 1) % __n]);
129 __first[__kpmodn] += __r;
130 __r += __kmodn;
131 __first[(__k + __q) % __n] += __r;
132 __first[__kmodn] = __r;
138 if (++__kmodn == __n)
139 __kmodn = 0;
140 if (++__k1modn == __n)
141 __k1modn = 0;
142 if (++__kpmodn == __n)
143 __kpmodn = 0;
144 if (++__kqmodn == __n)
145 __kqmodn = 0;
146
147 result_type __r = 1664525 * _Tp(__first[__kmodn] ^ __first[__kpmodn] ^ __first[__k1modn]);
148 __first[__kpmodn] += __r;
149 __r += __kmodn;
150 __first[__kqmodn] += __r;
151 __first[__kmodn] = __r;
133152 }
134153 for (size_t __k = __m; __k < __m + __n; ++__k)
135154 {
136 const size_t __kmodn = __k % __n;
137 const size_t __kpmodn = (__k + __p) % __n;
138 result_type __r = 1566083941 * _Tp(__first[__kmodn] +
139 __first[__kpmodn] +
140 __first[(__k - 1) % __n]);
141 __first[__kpmodn] ^= __r;
142 __r -= __kmodn;
143 __first[(__k + __q) % __n] ^= __r;
144 __first[__kmodn] = __r;
155 if (++__kmodn == __n)
156 __kmodn = 0;
157 if (++__k1modn == __n)
158 __k1modn = 0;
159 if (++__kpmodn == __n)
160 __kpmodn = 0;
161 if (++__kqmodn == __n)
162 __kqmodn = 0;
163
164 result_type __r = 1566083941 * _Tp(__first[__kmodn] + __first[__kpmodn] + __first[__k1modn]);
165 __first[__kpmodn] ^= __r;
166 __r -= __kmodn;
167 __first[__kqmodn] ^= __r;
168 __first[__kmodn] = __r;
145169 }
146170 }
147171}
lib/libcxx/include/__random/shuffle_order_engine.h+1-1
......@@ -18,7 +18,7 @@
1818#include <type_traits>
1919
2020#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21#pragma GCC system_header
21# pragma GCC system_header
2222#endif
2323
2424_LIBCPP_PUSH_MACROS
lib/libcxx/include/__random/student_t_distribution.h+3-1
......@@ -11,13 +11,14 @@
1111
1212#include <__config>
1313#include <__random/gamma_distribution.h>
14#include <__random/is_valid.h>
1415#include <__random/normal_distribution.h>
1516#include <cmath>
1617#include <iosfwd>
1718#include <limits>
1819
1920#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20#pragma GCC system_header
21# pragma GCC system_header
2122#endif
2223
2324_LIBCPP_PUSH_MACROS
......@@ -111,6 +112,7 @@ template<class _URNG>
111112_RealType
112113student_t_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
113114{
115 static_assert(__libcpp_random_is_valid_urng<_URNG>::value, "");
114116 gamma_distribution<result_type> __gd(__p.n() * .5, 2);
115117 return __nd_(__g) * _VSTD::sqrt(__p.n()/__gd(__g));
116118}
lib/libcxx/include/__random/subtract_with_carry_engine.h+1-1
......@@ -21,7 +21,7 @@
2121#include <type_traits>
2222
2323#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
24#pragma GCC system_header
24# pragma GCC system_header
2525#endif
2626
2727_LIBCPP_PUSH_MACROS
lib/libcxx/include/__random/uniform_int_distribution.h+5-2
......@@ -11,6 +11,7 @@
1111
1212#include <__bits>
1313#include <__config>
14#include <__random/is_valid.h>
1415#include <__random/log2.h>
1516#include <bit>
1617#include <cstddef>
......@@ -20,7 +21,7 @@
2021#include <type_traits>
2122
2223#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23#pragma GCC system_header
24# pragma GCC system_header
2425#endif
2526
2627_LIBCPP_PUSH_MACROS
......@@ -155,9 +156,10 @@ __independent_bits_engine<_Engine, _UIntType>::__eval(true_type)
155156 return _Sp;
156157}
157158
158template<class _IntType = int> // __int128_t is also supported as an extension here
159template<class _IntType = int>
159160class uniform_int_distribution
160161{
162 static_assert(__libcpp_random_is_valid_inttype<_IntType>::value, "IntType must be a supported integer type");
161163public:
162164 // types
163165 typedef _IntType result_type;
......@@ -230,6 +232,7 @@ typename uniform_int_distribution<_IntType>::result_type
230232uniform_int_distribution<_IntType>::operator()(_URNG& __g, const param_type& __p)
231233_LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
232234{
235 static_assert(__libcpp_random_is_valid_urng<_URNG>::value, "");
233236 typedef typename conditional<sizeof(result_type) <= sizeof(uint32_t), uint32_t,
234237 typename make_unsigned<result_type>::type>::type _UIntType;
235238 const _UIntType _Rp = _UIntType(__p.b()) - _UIntType(__p.a()) + _UIntType(1);
lib/libcxx/include/__random/uniform_random_bit_generator.h+3-3
......@@ -16,7 +16,7 @@
1616#include <type_traits>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
19# pragma GCC system_header
2020#endif
2121
2222_LIBCPP_PUSH_MACROS
......@@ -24,7 +24,7 @@ _LIBCPP_PUSH_MACROS
2424
2525_LIBCPP_BEGIN_NAMESPACE_STD
2626
27#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
27#if _LIBCPP_STD_VER > 17
2828
2929// [rand.req.urng]
3030template<class _Gen>
......@@ -36,7 +36,7 @@ concept uniform_random_bit_generator =
3636 requires bool_constant<(_Gen::min() < _Gen::max())>::value;
3737 };
3838
39#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
39#endif // _LIBCPP_STD_VER > 17
4040
4141_LIBCPP_END_NAMESPACE_STD
4242
lib/libcxx/include/__random/uniform_real_distribution.h+3-1
......@@ -11,12 +11,13 @@
1111
1212#include <__config>
1313#include <__random/generate_canonical.h>
14#include <__random/is_valid.h>
1415#include <iosfwd>
1516#include <limits>
1617#include <type_traits>
1718
1819#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
20# pragma GCC system_header
2021#endif
2122
2223_LIBCPP_PUSH_MACROS
......@@ -115,6 +116,7 @@ inline
115116typename uniform_real_distribution<_RealType>::result_type
116117uniform_real_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
117118{
119 static_assert(__libcpp_random_is_valid_urng<_URNG>::value, "");
118120 return (__p.b() - __p.a())
119121 * _VSTD::generate_canonical<_RealType, numeric_limits<_RealType>::digits>(__g)
120122 + __p.a();
lib/libcxx/include/__random/weibull_distribution.h+1-1
......@@ -16,7 +16,7 @@
1616#include <limits>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
19# pragma GCC system_header
2020#endif
2121
2222_LIBCPP_PUSH_MACROS
lib/libcxx/include/__ranges/access.h+7-10
......@@ -14,18 +14,16 @@
1414#include <__iterator/concepts.h>
1515#include <__iterator/readable_traits.h>
1616#include <__ranges/enable_borrowed_range.h>
17#include <__utility/as_const.h>
1817#include <__utility/auto_cast.h>
19#include <concepts>
2018#include <type_traits>
2119
2220#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23#pragma GCC system_header
21# pragma GCC system_header
2422#endif
2523
2624_LIBCPP_BEGIN_NAMESPACE_STD
2725
28#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
26#if _LIBCPP_STD_VER > 17
2927
3028namespace ranges {
3129 template <class _Tp>
......@@ -60,14 +58,14 @@ namespace __begin {
6058 struct __fn {
6159 template <class _Tp>
6260 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp (&__t)[]) const noexcept
63 requires (sizeof(_Tp) != 0) // Disallow incomplete element types.
61 requires (sizeof(_Tp) >= 0) // Disallow incomplete element types.
6462 {
6563 return __t + 0;
6664 }
6765
6866 template <class _Tp, size_t _Np>
6967 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp (&__t)[_Np]) const noexcept
70 requires (sizeof(_Tp) != 0) // Disallow incomplete element types.
68 requires (sizeof(_Tp) >= 0) // Disallow incomplete element types.
7169 {
7270 return __t + 0;
7371 }
......@@ -130,11 +128,10 @@ namespace __end {
130128 { _LIBCPP_AUTO_CAST(end(__t)) } -> sentinel_for<iterator_t<_Tp>>;
131129 };
132130
133 class __fn {
134 public:
131 struct __fn {
135132 template <class _Tp, size_t _Np>
136133 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp (&__t)[_Np]) const noexcept
137 requires (sizeof(_Tp) != 0) // Disallow incomplete element types.
134 requires (sizeof(_Tp) >= 0) // Disallow incomplete element types.
138135 {
139136 return __t + _Np;
140137 }
......@@ -220,7 +217,7 @@ inline namespace __cpo {
220217} // namespace __cpo
221218} // namespace ranges
222219
223#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
220#endif // _LIBCPP_STD_VER > 17
224221
225222_LIBCPP_END_NAMESPACE_STD
226223
lib/libcxx/include/__ranges/all.h+13-12
......@@ -23,12 +23,12 @@
2323#include <type_traits>
2424
2525#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
26#pragma GCC system_header
26# pragma GCC system_header
2727#endif
2828
2929_LIBCPP_BEGIN_NAMESPACE_STD
3030
31#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
31#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
3232
3333namespace ranges::views {
3434
......@@ -38,30 +38,31 @@ namespace __all {
3838 requires ranges::view<decay_t<_Tp>>
3939 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
4040 constexpr auto operator()(_Tp&& __t) const
41 noexcept(noexcept(_LIBCPP_AUTO_CAST(_VSTD::forward<_Tp>(__t))))
41 noexcept(noexcept(_LIBCPP_AUTO_CAST(std::forward<_Tp>(__t))))
42 -> decltype(_LIBCPP_AUTO_CAST(std::forward<_Tp>(__t)))
4243 {
43 return _LIBCPP_AUTO_CAST(_VSTD::forward<_Tp>(__t));
44 return _LIBCPP_AUTO_CAST(std::forward<_Tp>(__t));
4445 }
4546
4647 template<class _Tp>
4748 requires (!ranges::view<decay_t<_Tp>>) &&
48 requires (_Tp&& __t) { ranges::ref_view{_VSTD::forward<_Tp>(__t)}; }
49 requires (_Tp&& __t) { ranges::ref_view{std::forward<_Tp>(__t)}; }
4950 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
5051 constexpr auto operator()(_Tp&& __t) const
51 noexcept(noexcept(ranges::ref_view{_VSTD::forward<_Tp>(__t)}))
52 noexcept(noexcept(ranges::ref_view{std::forward<_Tp>(__t)}))
5253 {
53 return ranges::ref_view{_VSTD::forward<_Tp>(__t)};
54 return ranges::ref_view{std::forward<_Tp>(__t)};
5455 }
5556
5657 template<class _Tp>
5758 requires (!ranges::view<decay_t<_Tp>> &&
58 !requires (_Tp&& __t) { ranges::ref_view{_VSTD::forward<_Tp>(__t)}; } &&
59 requires (_Tp&& __t) { ranges::owning_view{_VSTD::forward<_Tp>(__t)}; })
59 !requires (_Tp&& __t) { ranges::ref_view{std::forward<_Tp>(__t)}; } &&
60 requires (_Tp&& __t) { ranges::owning_view{std::forward<_Tp>(__t)}; })
6061 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
6162 constexpr auto operator()(_Tp&& __t) const
62 noexcept(noexcept(ranges::owning_view{_VSTD::forward<_Tp>(__t)}))
63 noexcept(noexcept(ranges::owning_view{std::forward<_Tp>(__t)}))
6364 {
64 return ranges::owning_view{_VSTD::forward<_Tp>(__t)};
65 return ranges::owning_view{std::forward<_Tp>(__t)};
6566 }
6667 };
6768} // namespace __all
......@@ -75,7 +76,7 @@ using all_t = decltype(views::all(declval<_Range>()));
7576
7677} // namespace ranges::views
7778
78#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
79#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
7980
8081_LIBCPP_END_NAMESPACE_STD
8182
lib/libcxx/include/__ranges/common_view.h+11-11
......@@ -25,12 +25,12 @@
2525#include <type_traits>
2626
2727#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
28#pragma GCC system_header
28# pragma GCC system_header
2929#endif
3030
3131_LIBCPP_BEGIN_NAMESPACE_STD
3232
33#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
33#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
3434
3535namespace ranges {
3636
......@@ -44,13 +44,13 @@ public:
4444 common_view() requires default_initializable<_View> = default;
4545
4646 _LIBCPP_HIDE_FROM_ABI
47 constexpr explicit common_view(_View __v) : __base_(_VSTD::move(__v)) { }
47 constexpr explicit common_view(_View __v) : __base_(std::move(__v)) { }
4848
4949 _LIBCPP_HIDE_FROM_ABI
5050 constexpr _View base() const& requires copy_constructible<_View> { return __base_; }
5151
5252 _LIBCPP_HIDE_FROM_ABI
53 constexpr _View base() && { return _VSTD::move(__base_); }
53 constexpr _View base() && { return std::move(__base_); }
5454
5555 _LIBCPP_HIDE_FROM_ABI
5656 constexpr auto begin() {
......@@ -109,16 +109,16 @@ namespace __common {
109109 requires common_range<_Range>
110110 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
111111 constexpr auto operator()(_Range&& __range) const
112 noexcept(noexcept(views::all(_VSTD::forward<_Range>(__range))))
113 -> decltype( views::all(_VSTD::forward<_Range>(__range)))
114 { return views::all(_VSTD::forward<_Range>(__range)); }
112 noexcept(noexcept(views::all(std::forward<_Range>(__range))))
113 -> decltype( views::all(std::forward<_Range>(__range)))
114 { return views::all(std::forward<_Range>(__range)); }
115115
116116 template<class _Range>
117117 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
118118 constexpr auto operator()(_Range&& __range) const
119 noexcept(noexcept(common_view{_VSTD::forward<_Range>(__range)}))
120 -> decltype( common_view{_VSTD::forward<_Range>(__range)})
121 { return common_view{_VSTD::forward<_Range>(__range)}; }
119 noexcept(noexcept(common_view{std::forward<_Range>(__range)}))
120 -> decltype( common_view{std::forward<_Range>(__range)})
121 { return common_view{std::forward<_Range>(__range)}; }
122122 };
123123} // namespace __common
124124
......@@ -128,7 +128,7 @@ inline namespace __cpo {
128128} // namespace views
129129} // namespace ranges
130130
131#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
131#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
132132
133133_LIBCPP_END_NAMESPACE_STD
134134
lib/libcxx/include/__ranges/concepts.h+3-3
......@@ -27,12 +27,12 @@
2727#include <type_traits>
2828
2929#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
30#pragma GCC system_header
30# pragma GCC system_header
3131#endif
3232
3333_LIBCPP_BEGIN_NAMESPACE_STD
3434
35#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
35#if _LIBCPP_STD_VER > 17
3636
3737namespace ranges {
3838
......@@ -135,7 +135,7 @@ namespace ranges {
135135
136136} // namespace ranges
137137
138#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
138#endif // _LIBCPP_STD_VER > 17
139139
140140_LIBCPP_END_NAMESPACE_STD
141141
lib/libcxx/include/__ranges/copyable_box.h+18-18
......@@ -19,12 +19,12 @@
1919#include <type_traits>
2020
2121#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22#pragma GCC system_header
22# pragma GCC system_header
2323#endif
2424
2525_LIBCPP_BEGIN_NAMESPACE_STD
2626
27#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
27#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
2828
2929// __copyable_box allows turning a type that is copy-constructible (but maybe not copy-assignable) into
3030// a type that is both copy-constructible and copy-assignable. It does that by introducing an empty state
......@@ -41,7 +41,7 @@ namespace ranges {
4141 // Primary template - uses std::optional and introduces an empty state in case assignment fails.
4242 template<__copy_constructible_object _Tp>
4343 class __copyable_box {
44 [[no_unique_address]] optional<_Tp> __val_;
44 _LIBCPP_NO_UNIQUE_ADDRESS optional<_Tp> __val_;
4545
4646 public:
4747 template<class ..._Args>
......@@ -49,7 +49,7 @@ namespace ranges {
4949 _LIBCPP_HIDE_FROM_ABI
5050 constexpr explicit __copyable_box(in_place_t, _Args&& ...__args)
5151 noexcept(is_nothrow_constructible_v<_Tp, _Args...>)
52 : __val_(in_place, _VSTD::forward<_Args>(__args)...)
52 : __val_(in_place, std::forward<_Args>(__args)...)
5353 { }
5454
5555 _LIBCPP_HIDE_FROM_ABI
......@@ -65,7 +65,7 @@ namespace ranges {
6565 constexpr __copyable_box& operator=(__copyable_box const& __other)
6666 noexcept(is_nothrow_copy_constructible_v<_Tp>)
6767 {
68 if (this != _VSTD::addressof(__other)) {
68 if (this != std::addressof(__other)) {
6969 if (__other.__has_value()) __val_.emplace(*__other);
7070 else __val_.reset();
7171 }
......@@ -79,8 +79,8 @@ namespace ranges {
7979 constexpr __copyable_box& operator=(__copyable_box&& __other)
8080 noexcept(is_nothrow_move_constructible_v<_Tp>)
8181 {
82 if (this != _VSTD::addressof(__other)) {
83 if (__other.__has_value()) __val_.emplace(_VSTD::move(*__other));
82 if (this != std::addressof(__other)) {
83 if (__other.__has_value()) __val_.emplace(std::move(*__other));
8484 else __val_.reset();
8585 }
8686 return *this;
......@@ -116,7 +116,7 @@ namespace ranges {
116116 template<__copy_constructible_object _Tp>
117117 requires __doesnt_need_empty_state_for_copy<_Tp> && __doesnt_need_empty_state_for_move<_Tp>
118118 class __copyable_box<_Tp> {
119 [[no_unique_address]] _Tp __val_;
119 _LIBCPP_NO_UNIQUE_ADDRESS _Tp __val_;
120120
121121 public:
122122 template<class ..._Args>
......@@ -124,7 +124,7 @@ namespace ranges {
124124 _LIBCPP_HIDE_FROM_ABI
125125 constexpr explicit __copyable_box(in_place_t, _Args&& ...__args)
126126 noexcept(is_nothrow_constructible_v<_Tp, _Args...>)
127 : __val_(_VSTD::forward<_Args>(__args)...)
127 : __val_(std::forward<_Args>(__args)...)
128128 { }
129129
130130 _LIBCPP_HIDE_FROM_ABI
......@@ -144,9 +144,9 @@ namespace ranges {
144144 _LIBCPP_HIDE_FROM_ABI
145145 constexpr __copyable_box& operator=(__copyable_box const& __other) noexcept {
146146 static_assert(is_nothrow_copy_constructible_v<_Tp>);
147 if (this != _VSTD::addressof(__other)) {
148 _VSTD::destroy_at(_VSTD::addressof(__val_));
149 _VSTD::construct_at(_VSTD::addressof(__val_), __other.__val_);
147 if (this != std::addressof(__other)) {
148 std::destroy_at(std::addressof(__val_));
149 std::construct_at(std::addressof(__val_), __other.__val_);
150150 }
151151 return *this;
152152 }
......@@ -154,9 +154,9 @@ namespace ranges {
154154 _LIBCPP_HIDE_FROM_ABI
155155 constexpr __copyable_box& operator=(__copyable_box&& __other) noexcept {
156156 static_assert(is_nothrow_move_constructible_v<_Tp>);
157 if (this != _VSTD::addressof(__other)) {
158 _VSTD::destroy_at(_VSTD::addressof(__val_));
159 _VSTD::construct_at(_VSTD::addressof(__val_), _VSTD::move(__other.__val_));
157 if (this != std::addressof(__other)) {
158 std::destroy_at(std::addressof(__val_));
159 std::construct_at(std::addressof(__val_), std::move(__other.__val_));
160160 }
161161 return *this;
162162 }
......@@ -164,14 +164,14 @@ namespace ranges {
164164 _LIBCPP_HIDE_FROM_ABI constexpr _Tp const& operator*() const noexcept { return __val_; }
165165 _LIBCPP_HIDE_FROM_ABI constexpr _Tp& operator*() noexcept { return __val_; }
166166
167 _LIBCPP_HIDE_FROM_ABI constexpr const _Tp *operator->() const noexcept { return _VSTD::addressof(__val_); }
168 _LIBCPP_HIDE_FROM_ABI constexpr _Tp *operator->() noexcept { return _VSTD::addressof(__val_); }
167 _LIBCPP_HIDE_FROM_ABI constexpr const _Tp *operator->() const noexcept { return std::addressof(__val_); }
168 _LIBCPP_HIDE_FROM_ABI constexpr _Tp *operator->() noexcept { return std::addressof(__val_); }
169169
170170 _LIBCPP_HIDE_FROM_ABI constexpr bool __has_value() const noexcept { return true; }
171171 };
172172} // namespace ranges
173173
174#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
174#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
175175
176176_LIBCPP_END_NAMESPACE_STD
177177
lib/libcxx/include/__ranges/counted.h+11-11
......@@ -24,12 +24,12 @@
2424#include <type_traits>
2525
2626#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
27#pragma GCC system_header
27# pragma GCC system_header
2828#endif
2929
3030_LIBCPP_BEGIN_NAMESPACE_STD
3131
32#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
32#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
3333
3434namespace ranges::views {
3535
......@@ -39,9 +39,9 @@ namespace __counted {
3939 template<contiguous_iterator _It>
4040 _LIBCPP_HIDE_FROM_ABI
4141 static constexpr auto __go(_It __it, iter_difference_t<_It> __count)
42 noexcept(noexcept(span(_VSTD::to_address(__it), static_cast<size_t>(__count))))
42 noexcept(noexcept(span(std::to_address(__it), static_cast<size_t>(__count))))
4343 // Deliberately omit return-type SFINAE, because to_address is not SFINAE-friendly
44 { return span(_VSTD::to_address(__it), static_cast<size_t>(__count)); }
44 { return span(std::to_address(__it), static_cast<size_t>(__count)); }
4545
4646 template<random_access_iterator _It>
4747 _LIBCPP_HIDE_FROM_ABI
......@@ -53,17 +53,17 @@ namespace __counted {
5353 template<class _It>
5454 _LIBCPP_HIDE_FROM_ABI
5555 static constexpr auto __go(_It __it, iter_difference_t<_It> __count)
56 noexcept(noexcept(subrange(counted_iterator(_VSTD::move(__it), __count), default_sentinel)))
57 -> decltype( subrange(counted_iterator(_VSTD::move(__it), __count), default_sentinel))
58 { return subrange(counted_iterator(_VSTD::move(__it), __count), default_sentinel); }
56 noexcept(noexcept(subrange(counted_iterator(std::move(__it), __count), default_sentinel)))
57 -> decltype( subrange(counted_iterator(std::move(__it), __count), default_sentinel))
58 { return subrange(counted_iterator(std::move(__it), __count), default_sentinel); }
5959
6060 template<class _It, convertible_to<iter_difference_t<_It>> _Diff>
6161 requires input_or_output_iterator<decay_t<_It>>
6262 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
6363 constexpr auto operator()(_It&& __it, _Diff&& __count) const
64 noexcept(noexcept(__go(_VSTD::forward<_It>(__it), _VSTD::forward<_Diff>(__count))))
65 -> decltype( __go(_VSTD::forward<_It>(__it), _VSTD::forward<_Diff>(__count)))
66 { return __go(_VSTD::forward<_It>(__it), _VSTD::forward<_Diff>(__count)); }
64 noexcept(noexcept(__go(std::forward<_It>(__it), std::forward<_Diff>(__count))))
65 -> decltype( __go(std::forward<_It>(__it), std::forward<_Diff>(__count)))
66 { return __go(std::forward<_It>(__it), std::forward<_Diff>(__count)); }
6767 };
6868
6969} // namespace __counted
......@@ -74,7 +74,7 @@ inline namespace __cpo {
7474
7575} // namespace ranges::views
7676
77#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
77#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
7878
7979_LIBCPP_END_NAMESPACE_STD
8080
lib/libcxx/include/__ranges/dangling.h+3-3
......@@ -16,12 +16,12 @@
1616#include <type_traits>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
19# pragma GCC system_header
2020#endif
2121
2222_LIBCPP_BEGIN_NAMESPACE_STD
2323
24#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
24#if _LIBCPP_STD_VER > 17
2525
2626namespace ranges {
2727struct dangling {
......@@ -35,7 +35,7 @@ using borrowed_iterator_t = _If<borrowed_range<_Rp>, iterator_t<_Rp>, dangling>;
3535// borrowed_subrange_t defined in <__ranges/subrange.h>
3636} // namespace ranges
3737
38#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
38#endif // _LIBCPP_STD_VER > 17
3939
4040_LIBCPP_END_NAMESPACE_STD
4141
lib/libcxx/include/__ranges/data.h+5-5
......@@ -19,12 +19,12 @@
1919#include <type_traits>
2020
2121#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22#pragma GCC system_header
22# pragma GCC system_header
2323#endif
2424
2525_LIBCPP_BEGIN_NAMESPACE_STD
2626
27#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
27#if _LIBCPP_STD_VER > 17
2828
2929// [range.prim.data]
3030
......@@ -60,8 +60,8 @@ namespace __data {
6060 template<__ranges_begin_invocable _Tp>
6161 _LIBCPP_HIDE_FROM_ABI
6262 constexpr auto operator()(_Tp&& __t) const
63 noexcept(noexcept(_VSTD::to_address(ranges::begin(__t)))) {
64 return _VSTD::to_address(ranges::begin(__t));
63 noexcept(noexcept(std::to_address(ranges::begin(__t)))) {
64 return std::to_address(ranges::begin(__t));
6565 }
6666 };
6767} // namespace __data
......@@ -99,7 +99,7 @@ inline namespace __cpo {
9999} // namespace __cpo
100100} // namespace ranges
101101
102#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
102#endif // _LIBCPP_STD_VER > 17
103103
104104_LIBCPP_END_NAMESPACE_STD
105105
lib/libcxx/include/__ranges/drop_view.h+190-11
......@@ -9,29 +9,43 @@
99#ifndef _LIBCPP___RANGES_DROP_VIEW_H
1010#define _LIBCPP___RANGES_DROP_VIEW_H
1111
12#include <__algorithm/min.h>
13#include <__assert>
1214#include <__config>
13#include <__debug>
15#include <__functional/bind_back.h>
16#include <__fwd/span.h>
17#include <__fwd/string_view.h>
1418#include <__iterator/concepts.h>
19#include <__iterator/distance.h>
1520#include <__iterator/iterator_traits.h>
1621#include <__iterator/next.h>
1722#include <__ranges/access.h>
1823#include <__ranges/all.h>
1924#include <__ranges/concepts.h>
25#include <__ranges/empty_view.h>
2026#include <__ranges/enable_borrowed_range.h>
27#include <__ranges/iota_view.h>
2128#include <__ranges/non_propagating_cache.h>
29#include <__ranges/range_adaptor.h>
2230#include <__ranges/size.h>
31#include <__ranges/subrange.h>
2332#include <__ranges/view_interface.h>
33#include <__utility/auto_cast.h>
34#include <__utility/forward.h>
2435#include <__utility/move.h>
2536#include <concepts>
2637#include <type_traits>
2738
2839#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
29#pragma GCC system_header
40# pragma GCC system_header
3041#endif
3142
43_LIBCPP_PUSH_MACROS
44#include <__undef_macros>
45
3246_LIBCPP_BEGIN_NAMESPACE_STD
3347
34#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
48#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
3549
3650namespace ranges {
3751 template<view _View>
......@@ -45,7 +59,7 @@ namespace ranges {
4559 // one can't call begin() on it more than once.
4660 static constexpr bool _UseCache = forward_range<_View> && !(random_access_range<_View> && sized_range<_View>);
4761 using _Cache = _If<_UseCache, __non_propagating_cache<iterator_t<_View>>, __empty_cache>;
48 [[no_unique_address]] _Cache __cached_begin_ = _Cache();
62 _LIBCPP_NO_UNIQUE_ADDRESS _Cache __cached_begin_ = _Cache();
4963 range_difference_t<_View> __count_ = 0;
5064 _View __base_ = _View();
5165
......@@ -55,13 +69,13 @@ public:
5569 _LIBCPP_HIDE_FROM_ABI
5670 constexpr drop_view(_View __base, range_difference_t<_View> __count)
5771 : __count_(__count)
58 , __base_(_VSTD::move(__base))
72 , __base_(std::move(__base))
5973 {
6074 _LIBCPP_ASSERT(__count_ >= 0, "count must be greater than or equal to zero.");
6175 }
6276
6377 _LIBCPP_HIDE_FROM_ABI constexpr _View base() const& requires copy_constructible<_View> { return __base_; }
64 _LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return _VSTD::move(__base_); }
78 _LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__base_); }
6579
6680 _LIBCPP_HIDE_FROM_ABI
6781 constexpr auto begin()
......@@ -113,15 +127,180 @@ public:
113127 { return __size(*this); }
114128 };
115129
116 template<class _Range>
117 drop_view(_Range&&, range_difference_t<_Range>) -> drop_view<views::all_t<_Range>>;
130template<class _Range>
131drop_view(_Range&&, range_difference_t<_Range>) -> drop_view<views::all_t<_Range>>;
132
133template<class _Tp>
134inline constexpr bool enable_borrowed_range<drop_view<_Tp>> = enable_borrowed_range<_Tp>;
135
136namespace views {
137namespace __drop {
138
139template <class _Tp>
140inline constexpr bool __is_empty_view = false;
141
142template <class _Tp>
143inline constexpr bool __is_empty_view<empty_view<_Tp>> = true;
144
145template <class _Tp>
146inline constexpr bool __is_passthrough_specialization = false;
147
148template <class _Tp, size_t _Extent>
149inline constexpr bool __is_passthrough_specialization<span<_Tp, _Extent>> = true;
150
151template <class _CharT, class _Traits>
152inline constexpr bool __is_passthrough_specialization<basic_string_view<_CharT, _Traits>> = true;
153
154template <class _Np, class _Bound>
155inline constexpr bool __is_passthrough_specialization<iota_view<_Np, _Bound>> = true;
156
157template <class _Iter, class _Sent, subrange_kind _Kind>
158inline constexpr bool __is_passthrough_specialization<subrange<_Iter, _Sent, _Kind>> =
159 !subrange<_Iter, _Sent, _Kind>::_StoreSize;
160
161template <class _Tp>
162inline constexpr bool __is_subrange_specialization_with_store_size = false;
163
164template <class _Iter, class _Sent, subrange_kind _Kind>
165inline constexpr bool __is_subrange_specialization_with_store_size<subrange<_Iter, _Sent, _Kind>> =
166 subrange<_Iter, _Sent, _Kind>::_StoreSize;
167
168template <class _Tp>
169struct __passthrough_type;
170
171template <class _Tp, size_t _Extent>
172struct __passthrough_type<span<_Tp, _Extent>> {
173 using type = span<_Tp>;
174};
175
176template <class _CharT, class _Traits>
177struct __passthrough_type<basic_string_view<_CharT, _Traits>> {
178 using type = basic_string_view<_CharT, _Traits>;
179};
180
181template <class _Np, class _Bound>
182struct __passthrough_type<iota_view<_Np, _Bound>> {
183 using type = iota_view<_Np, _Bound>;
184};
185
186template <class _Iter, class _Sent, subrange_kind _Kind>
187struct __passthrough_type<subrange<_Iter, _Sent, _Kind>> {
188 using type = subrange<_Iter, _Sent, _Kind>;
189};
190
191template <class _Tp>
192using __passthrough_type_t = typename __passthrough_type<_Tp>::type;
193
194struct __fn {
195 // [range.drop.overview]: the `empty_view` case.
196 template <class _Range, convertible_to<range_difference_t<_Range>> _Np>
197 requires __is_empty_view<remove_cvref_t<_Range>>
198 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
199 constexpr auto operator()(_Range&& __range, _Np&&) const
200 noexcept(noexcept(_LIBCPP_AUTO_CAST(std::forward<_Range>(__range))))
201 -> decltype( _LIBCPP_AUTO_CAST(std::forward<_Range>(__range)))
202 { return _LIBCPP_AUTO_CAST(std::forward<_Range>(__range)); }
203
204 // [range.drop.overview]: the `span | basic_string_view | iota_view | subrange (StoreSize == false)` case.
205 template <class _Range,
206 convertible_to<range_difference_t<_Range>> _Np,
207 class _RawRange = remove_cvref_t<_Range>,
208 class _Dist = range_difference_t<_Range>>
209 requires (!__is_empty_view<_RawRange> &&
210 random_access_range<_RawRange> &&
211 sized_range<_RawRange> &&
212 __is_passthrough_specialization<_RawRange>)
213 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
214 constexpr auto operator()(_Range&& __rng, _Np&& __n) const
215 noexcept(noexcept(__passthrough_type_t<_RawRange>(
216 ranges::begin(__rng) + std::min<_Dist>(ranges::distance(__rng), std::forward<_Np>(__n)),
217 ranges::end(__rng)
218 )))
219 -> decltype( __passthrough_type_t<_RawRange>(
220 // Note: deliberately not forwarding `__rng` to guard against double moves.
221 ranges::begin(__rng) + std::min<_Dist>(ranges::distance(__rng), std::forward<_Np>(__n)),
222 ranges::end(__rng)
223 ))
224 { return __passthrough_type_t<_RawRange>(
225 ranges::begin(__rng) + std::min<_Dist>(ranges::distance(__rng), std::forward<_Np>(__n)),
226 ranges::end(__rng)
227 ); }
228
229 // [range.drop.overview]: the `subrange (StoreSize == true)` case.
230 template <class _Range,
231 convertible_to<range_difference_t<_Range>> _Np,
232 class _RawRange = remove_cvref_t<_Range>,
233 class _Dist = range_difference_t<_Range>>
234 requires (!__is_empty_view<_RawRange> &&
235 random_access_range<_RawRange> &&
236 sized_range<_RawRange> &&
237 __is_subrange_specialization_with_store_size<_RawRange>)
238 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
239 constexpr auto operator()(_Range&& __rng, _Np&& __n) const
240 noexcept(noexcept(_RawRange(
241 ranges::begin(__rng) + std::min<_Dist>(ranges::distance(__rng), std::forward<_Np>(__n)),
242 ranges::end(__rng),
243 std::__to_unsigned_like(ranges::distance(__rng) -
244 std::min<_Dist>(ranges::distance(__rng), std::forward<_Np>(__n)))
245 )))
246 -> decltype( _RawRange(
247 // Note: deliberately not forwarding `__rng` to guard against double moves.
248 ranges::begin(__rng) + std::min<_Dist>(ranges::distance(__rng), std::forward<_Np>(__n)),
249 ranges::end(__rng),
250 std::__to_unsigned_like(ranges::distance(__rng) -
251 std::min<_Dist>(ranges::distance(__rng), std::forward<_Np>(__n)))
252 ))
253 {
254 // Introducing local variables avoids calculating `min` and `distance` twice (at the cost of diverging from the
255 // expression used in the `noexcept` clause and the return statement).
256 auto dist = ranges::distance(__rng);
257 auto clamped = std::min<_Dist>(dist, std::forward<_Np>(__n));
258 return _RawRange(
259 ranges::begin(__rng) + clamped,
260 ranges::end(__rng),
261 std::__to_unsigned_like(dist - clamped)
262 );}
263
264 // [range.drop.overview]: the "otherwise" case.
265 template <class _Range, convertible_to<range_difference_t<_Range>> _Np,
266 class _RawRange = remove_cvref_t<_Range>>
267 // Note: without specifically excluding the other cases, GCC sees this overload as ambiguous with the other
268 // overloads.
269 requires (!(__is_empty_view<_RawRange> ||
270 (__is_subrange_specialization_with_store_size<_RawRange> &&
271 sized_range<_RawRange> &&
272 random_access_range<_RawRange>) ||
273 (__is_passthrough_specialization<_RawRange> &&
274 sized_range<_RawRange> &&
275 random_access_range<_RawRange>)
276 ))
277 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
278 constexpr auto operator()(_Range&& __range, _Np&& __n) const
279 noexcept(noexcept(drop_view(std::forward<_Range>(__range), std::forward<_Np>(__n))))
280 -> decltype( drop_view(std::forward<_Range>(__range), std::forward<_Np>(__n)))
281 { return drop_view(std::forward<_Range>(__range), std::forward<_Np>(__n)); }
282
283 template <class _Np>
284 requires constructible_from<decay_t<_Np>, _Np>
285 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
286 constexpr auto operator()(_Np&& __n) const
287 noexcept(is_nothrow_constructible_v<decay_t<_Np>, _Np>)
288 { return __range_adaptor_closure_t(std::__bind_back(*this, std::forward<_Np>(__n))); }
289};
290
291} // namespace __drop
292
293inline namespace __cpo {
294 inline constexpr auto drop = __drop::__fn{};
295} // namespace __cpo
296} // namespace views
118297
119 template<class _Tp>
120 inline constexpr bool enable_borrowed_range<drop_view<_Tp>> = enable_borrowed_range<_Tp>;
121298} // namespace ranges
122299
123#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
300#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
124301
125302_LIBCPP_END_NAMESPACE_STD
126303
304_LIBCPP_POP_MACROS
305
127306#endif // _LIBCPP___RANGES_DROP_VIEW_H
lib/libcxx/include/__ranges/empty.h+3-3
......@@ -17,12 +17,12 @@
1717#include <type_traits>
1818
1919#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20#pragma GCC system_header
20# pragma GCC system_header
2121#endif
2222
2323_LIBCPP_BEGIN_NAMESPACE_STD
2424
25#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
25#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
2626
2727// [range.prim.empty]
2828
......@@ -75,7 +75,7 @@ inline namespace __cpo {
7575} // namespace __cpo
7676} // namespace ranges
7777
78#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
78#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
7979
8080_LIBCPP_END_NAMESPACE_STD
8181
lib/libcxx/include/__ranges/empty_view.h+10-3
......@@ -15,12 +15,12 @@
1515#include <type_traits>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
2222
23#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
23#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
2424
2525namespace ranges {
2626 template<class _Tp>
......@@ -36,9 +36,16 @@ namespace ranges {
3636
3737 template<class _Tp>
3838 inline constexpr bool enable_borrowed_range<empty_view<_Tp>> = true;
39
40 namespace views {
41
42 template <class _Tp>
43 inline constexpr empty_view<_Tp> empty{};
44
45 } // namespace views
3946} // namespace ranges
4047
41#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
48#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
4249
4350_LIBCPP_END_NAMESPACE_STD
4451
lib/libcxx/include/__ranges/enable_borrowed_range.h+3-3
......@@ -17,12 +17,12 @@
1717#include <__config>
1818
1919#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20#pragma GCC system_header
20# pragma GCC system_header
2121#endif
2222
2323_LIBCPP_BEGIN_NAMESPACE_STD
2424
25#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
25#if _LIBCPP_STD_VER > 17
2626
2727namespace ranges {
2828
......@@ -33,7 +33,7 @@ inline constexpr bool enable_borrowed_range = false;
3333
3434} // namespace ranges
3535
36#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
36#endif // _LIBCPP_STD_VER > 17
3737
3838_LIBCPP_END_NAMESPACE_STD
3939
lib/libcxx/include/__ranges/enable_view.h+3-3
......@@ -15,12 +15,12 @@
1515#include <type_traits>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
2222
23#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
23#if _LIBCPP_STD_VER > 17
2424
2525namespace ranges {
2626
......@@ -40,7 +40,7 @@ inline constexpr bool enable_view = derived_from<_Tp, view_base> ||
4040
4141} // namespace ranges
4242
43#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
43#endif // _LIBCPP_STD_VER > 17
4444
4545_LIBCPP_END_NAMESPACE_STD
4646
lib/libcxx/include/__ranges/filter_view.h created+259
......@@ -0,0 +1,259 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9#ifndef _LIBCPP___RANGES_FILTER_VIEW_H
10#define _LIBCPP___RANGES_FILTER_VIEW_H
11
12#include <__algorithm/ranges_find_if.h>
13#include <__config>
14#include <__debug>
15#include <__functional/bind_back.h>
16#include <__functional/invoke.h>
17#include <__functional/reference_wrapper.h>
18#include <__iterator/concepts.h>
19#include <__iterator/iter_move.h>
20#include <__iterator/iter_swap.h>
21#include <__iterator/iterator_traits.h>
22#include <__memory/addressof.h>
23#include <__ranges/access.h>
24#include <__ranges/all.h>
25#include <__ranges/concepts.h>
26#include <__ranges/copyable_box.h>
27#include <__ranges/non_propagating_cache.h>
28#include <__ranges/range_adaptor.h>
29#include <__ranges/view_interface.h>
30#include <__utility/forward.h>
31#include <__utility/in_place.h>
32#include <__utility/move.h>
33#include <concepts>
34#include <type_traits>
35
36#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
37# pragma GCC system_header
38#endif
39
40_LIBCPP_BEGIN_NAMESPACE_STD
41
42#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
43
44namespace ranges {
45 template<input_range _View, indirect_unary_predicate<iterator_t<_View>> _Pred>
46 requires view<_View> && is_object_v<_Pred>
47 class filter_view : public view_interface<filter_view<_View, _Pred>> {
48 _LIBCPP_NO_UNIQUE_ADDRESS _View __base_ = _View();
49 _LIBCPP_NO_UNIQUE_ADDRESS __copyable_box<_Pred> __pred_;
50
51 // We cache the result of begin() to allow providing an amortized O(1) begin() whenever
52 // the underlying range is at least a forward_range.
53 static constexpr bool _UseCache = forward_range<_View>;
54 using _Cache = _If<_UseCache, __non_propagating_cache<iterator_t<_View>>, __empty_cache>;
55 _LIBCPP_NO_UNIQUE_ADDRESS _Cache __cached_begin_ = _Cache();
56
57 class __iterator;
58 class __sentinel;
59
60 public:
61 _LIBCPP_HIDE_FROM_ABI
62 filter_view() requires default_initializable<_View> && default_initializable<_Pred> = default;
63
64 _LIBCPP_HIDE_FROM_ABI
65 constexpr filter_view(_View __base, _Pred __pred)
66 : __base_(std::move(__base)), __pred_(in_place, std::move(__pred))
67 { }
68
69 template<class _Vp = _View>
70 _LIBCPP_HIDE_FROM_ABI
71 constexpr _View base() const& requires copy_constructible<_Vp> { return __base_; }
72 _LIBCPP_HIDE_FROM_ABI
73 constexpr _View base() && { return std::move(__base_); }
74
75 _LIBCPP_HIDE_FROM_ABI
76 constexpr _Pred const& pred() const { return *__pred_; }
77
78 _LIBCPP_HIDE_FROM_ABI
79 constexpr __iterator begin() {
80 _LIBCPP_ASSERT(__pred_.__has_value(), "Trying to call begin() on a filter_view that does not have a valid predicate.");
81 if constexpr (_UseCache) {
82 if (!__cached_begin_.__has_value()) {
83 __cached_begin_.__emplace(ranges::find_if(__base_, std::ref(*__pred_)));
84 }
85 return {*this, *__cached_begin_};
86 } else {
87 return {*this, ranges::find_if(__base_, std::ref(*__pred_))};
88 }
89 }
90
91 _LIBCPP_HIDE_FROM_ABI
92 constexpr auto end() {
93 if constexpr (common_range<_View>)
94 return __iterator{*this, ranges::end(__base_)};
95 else
96 return __sentinel{*this};
97 }
98 };
99
100 template<class _Range, class _Pred>
101 filter_view(_Range&&, _Pred) -> filter_view<views::all_t<_Range>, _Pred>;
102
103 template<class _View>
104 struct __filter_iterator_category { };
105
106 template<forward_range _View>
107 struct __filter_iterator_category<_View> {
108 using _Cat = typename iterator_traits<iterator_t<_View>>::iterator_category;
109 using iterator_category =
110 _If<derived_from<_Cat, bidirectional_iterator_tag>, bidirectional_iterator_tag,
111 _If<derived_from<_Cat, forward_iterator_tag>, forward_iterator_tag,
112 /* else */ _Cat
113 >>;
114 };
115
116 template<input_range _View, indirect_unary_predicate<iterator_t<_View>> _Pred>
117 requires view<_View> && is_object_v<_Pred>
118 class filter_view<_View, _Pred>::__iterator : public __filter_iterator_category<_View> {
119 public:
120 _LIBCPP_NO_UNIQUE_ADDRESS iterator_t<_View> __current_ = iterator_t<_View>();
121 _LIBCPP_NO_UNIQUE_ADDRESS filter_view* __parent_ = nullptr;
122
123 using iterator_concept =
124 _If<bidirectional_range<_View>, bidirectional_iterator_tag,
125 _If<forward_range<_View>, forward_iterator_tag,
126 /* else */ input_iterator_tag
127 >>;
128 // using iterator_category = inherited;
129 using value_type = range_value_t<_View>;
130 using difference_type = range_difference_t<_View>;
131
132 _LIBCPP_HIDE_FROM_ABI
133 __iterator() requires default_initializable<iterator_t<_View>> = default;
134
135 _LIBCPP_HIDE_FROM_ABI
136 constexpr __iterator(filter_view& __parent, iterator_t<_View> __current)
137 : __current_(std::move(__current)), __parent_(std::addressof(__parent))
138 { }
139
140 _LIBCPP_HIDE_FROM_ABI
141 constexpr iterator_t<_View> const& base() const& noexcept { return __current_; }
142 _LIBCPP_HIDE_FROM_ABI
143 constexpr iterator_t<_View> base() && { return std::move(__current_); }
144
145 _LIBCPP_HIDE_FROM_ABI
146 constexpr range_reference_t<_View> operator*() const { return *__current_; }
147 _LIBCPP_HIDE_FROM_ABI
148 constexpr iterator_t<_View> operator->() const
149 requires __has_arrow<iterator_t<_View>> && copyable<iterator_t<_View>>
150 {
151 return __current_;
152 }
153
154 _LIBCPP_HIDE_FROM_ABI
155 constexpr __iterator& operator++() {
156 __current_ = ranges::find_if(std::move(++__current_), ranges::end(__parent_->__base_),
157 std::ref(*__parent_->__pred_));
158 return *this;
159 }
160 _LIBCPP_HIDE_FROM_ABI
161 constexpr void operator++(int) { ++*this; }
162 _LIBCPP_HIDE_FROM_ABI
163 constexpr __iterator operator++(int) requires forward_range<_View> {
164 auto __tmp = *this;
165 ++*this;
166 return __tmp;
167 }
168
169 _LIBCPP_HIDE_FROM_ABI
170 constexpr __iterator& operator--() requires bidirectional_range<_View> {
171 do {
172 --__current_;
173 } while (!std::invoke(*__parent_->__pred_, *__current_));
174 return *this;
175 }
176 _LIBCPP_HIDE_FROM_ABI
177 constexpr __iterator operator--(int) requires bidirectional_range<_View> {
178 auto tmp = *this;
179 --*this;
180 return tmp;
181 }
182
183 _LIBCPP_HIDE_FROM_ABI
184 friend constexpr bool operator==(__iterator const& __x, __iterator const& __y)
185 requires equality_comparable<iterator_t<_View>>
186 {
187 return __x.__current_ == __y.__current_;
188 }
189
190 _LIBCPP_HIDE_FROM_ABI
191 friend constexpr range_rvalue_reference_t<_View> iter_move(__iterator const& __it)
192 noexcept(noexcept(ranges::iter_move(__it.__current_)))
193 {
194 return ranges::iter_move(__it.__current_);
195 }
196
197 _LIBCPP_HIDE_FROM_ABI
198 friend constexpr void iter_swap(__iterator const& __x, __iterator const& __y)
199 noexcept(noexcept(ranges::iter_swap(__x.__current_, __y.__current_)))
200 requires indirectly_swappable<iterator_t<_View>>
201 {
202 return ranges::iter_swap(__x.__current_, __y.__current_);
203 }
204 };
205
206 template<input_range _View, indirect_unary_predicate<iterator_t<_View>> _Pred>
207 requires view<_View> && is_object_v<_Pred>
208 class filter_view<_View, _Pred>::__sentinel {
209 public:
210 sentinel_t<_View> __end_ = sentinel_t<_View>();
211
212 _LIBCPP_HIDE_FROM_ABI
213 __sentinel() = default;
214
215 _LIBCPP_HIDE_FROM_ABI
216 constexpr explicit __sentinel(filter_view& __parent)
217 : __end_(ranges::end(__parent.__base_))
218 { }
219
220 _LIBCPP_HIDE_FROM_ABI
221 constexpr sentinel_t<_View> base() const { return __end_; }
222
223 _LIBCPP_HIDE_FROM_ABI
224 friend constexpr bool operator==(__iterator const& __x, __sentinel const& __y) {
225 return __x.__current_ == __y.__end_;
226 }
227 };
228
229namespace views {
230namespace __filter {
231 struct __fn {
232 template<class _Range, class _Pred>
233 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
234 constexpr auto operator()(_Range&& __range, _Pred&& __pred) const
235 noexcept(noexcept(filter_view(std::forward<_Range>(__range), std::forward<_Pred>(__pred))))
236 -> decltype( filter_view(std::forward<_Range>(__range), std::forward<_Pred>(__pred)))
237 { return filter_view(std::forward<_Range>(__range), std::forward<_Pred>(__pred)); }
238
239 template<class _Pred>
240 requires constructible_from<decay_t<_Pred>, _Pred>
241 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
242 constexpr auto operator()(_Pred&& __pred) const
243 noexcept(is_nothrow_constructible_v<decay_t<_Pred>, _Pred>)
244 { return __range_adaptor_closure_t(std::__bind_back(*this, std::forward<_Pred>(__pred))); }
245 };
246} // namespace __filter
247
248inline namespace __cpo {
249 inline constexpr auto filter = __filter::__fn{};
250} // namespace __cpo
251} // namespace views
252
253} // namespace ranges
254
255#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
256
257_LIBCPP_END_NAMESPACE_STD
258
259#endif // _LIBCPP___RANGES_FILTER_VIEW_H
lib/libcxx/include/__ranges/iota_view.h+58-58
......@@ -9,6 +9,7 @@
99#ifndef _LIBCPP___RANGES_IOTA_VIEW_H
1010#define _LIBCPP___RANGES_IOTA_VIEW_H
1111
12#include <__assert>
1213#include <__compare/three_way_comparable.h>
1314#include <__concepts/arithmetic.h>
1415#include <__concepts/constructible.h>
......@@ -20,7 +21,6 @@
2021#include <__concepts/semiregular.h>
2122#include <__concepts/totally_ordered.h>
2223#include <__config>
23#include <__debug>
2424#include <__functional/ranges_operations.h>
2525#include <__iterator/concepts.h>
2626#include <__iterator/incrementable_traits.h>
......@@ -34,12 +34,12 @@
3434#include <type_traits>
3535
3636#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
37#pragma GCC system_header
37# pragma GCC system_header
3838#endif
3939
4040_LIBCPP_BEGIN_NAMESPACE_STD
4141
42#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
42#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
4343
4444namespace ranges {
4545 template<class _Int>
......@@ -90,9 +90,9 @@ namespace ranges {
9090 using iterator_category = input_iterator_tag;
9191 };
9292
93 template<weakly_incrementable _Start, semiregular _Bound = unreachable_sentinel_t>
94 requires __weakly_equality_comparable_with<_Start, _Bound> && copyable<_Start>
95 class iota_view : public view_interface<iota_view<_Start, _Bound>> {
93 template <weakly_incrementable _Start, semiregular _BoundSentinel = unreachable_sentinel_t>
94 requires __weakly_equality_comparable_with<_Start, _BoundSentinel> && copyable<_Start>
95 class iota_view : public view_interface<iota_view<_Start, _BoundSentinel>> {
9696 struct __iterator : public __iota_iterator_category<_Start> {
9797 friend class iota_view;
9898
......@@ -111,7 +111,7 @@ namespace ranges {
111111 __iterator() requires default_initializable<_Start> = default;
112112
113113 _LIBCPP_HIDE_FROM_ABI
114 constexpr explicit __iterator(_Start __value) : __value_(_VSTD::move(__value)) {}
114 constexpr explicit __iterator(_Start __value) : __value_(std::move(__value)) {}
115115
116116 _LIBCPP_HIDE_FROM_ABI
117117 constexpr _Start operator*() const noexcept(is_nothrow_copy_constructible_v<_Start>) {
......@@ -271,127 +271,127 @@ namespace ranges {
271271 friend class iota_view;
272272
273273 private:
274 _Bound __bound_ = _Bound();
274 _BoundSentinel __bound_sentinel_ = _BoundSentinel();
275275
276276 public:
277277 _LIBCPP_HIDE_FROM_ABI
278278 __sentinel() = default;
279 constexpr explicit __sentinel(_Bound __bound) : __bound_(_VSTD::move(__bound)) {}
279 constexpr explicit __sentinel(_BoundSentinel __bound_sentinel) : __bound_sentinel_(std::move(__bound_sentinel)) {}
280280
281281 _LIBCPP_HIDE_FROM_ABI
282282 friend constexpr bool operator==(const __iterator& __x, const __sentinel& __y) {
283 return __x.__value_ == __y.__bound_;
283 return __x.__value_ == __y.__bound_sentinel_;
284284 }
285285
286286 _LIBCPP_HIDE_FROM_ABI
287287 friend constexpr iter_difference_t<_Start> operator-(const __iterator& __x, const __sentinel& __y)
288 requires sized_sentinel_for<_Bound, _Start>
288 requires sized_sentinel_for<_BoundSentinel, _Start>
289289 {
290 return __x.__value_ - __y.__bound_;
290 return __x.__value_ - __y.__bound_sentinel_;
291291 }
292292
293293 _LIBCPP_HIDE_FROM_ABI
294294 friend constexpr iter_difference_t<_Start> operator-(const __sentinel& __x, const __iterator& __y)
295 requires sized_sentinel_for<_Bound, _Start>
295 requires sized_sentinel_for<_BoundSentinel, _Start>
296296 {
297297 return -(__y - __x);
298298 }
299299 };
300300
301301 _Start __value_ = _Start();
302 _Bound __bound_ = _Bound();
302 _BoundSentinel __bound_sentinel_ = _BoundSentinel();
303303
304304 public:
305305 _LIBCPP_HIDE_FROM_ABI
306306 iota_view() requires default_initializable<_Start> = default;
307307
308308 _LIBCPP_HIDE_FROM_ABI
309 constexpr explicit iota_view(_Start __value) : __value_(_VSTD::move(__value)) { }
309 constexpr explicit iota_view(_Start __value) : __value_(std::move(__value)) { }
310310
311311 _LIBCPP_HIDE_FROM_ABI
312 constexpr iota_view(type_identity_t<_Start> __value, type_identity_t<_Bound> __bound)
313 : __value_(_VSTD::move(__value)), __bound_(_VSTD::move(__bound)) {
312 constexpr iota_view(type_identity_t<_Start> __value, type_identity_t<_BoundSentinel> __bound_sentinel)
313 : __value_(std::move(__value)), __bound_sentinel_(std::move(__bound_sentinel)) {
314314 // Validate the precondition if possible.
315 if constexpr (totally_ordered_with<_Start, _Bound>) {
316 _LIBCPP_ASSERT(ranges::less_equal()(__value_, __bound_),
315 if constexpr (totally_ordered_with<_Start, _BoundSentinel>) {
316 _LIBCPP_ASSERT(ranges::less_equal()(__value_, __bound_sentinel_),
317317 "Precondition violated: value is greater than bound.");
318318 }
319319 }
320320
321321 _LIBCPP_HIDE_FROM_ABI
322322 constexpr iota_view(__iterator __first, __iterator __last)
323 requires same_as<_Start, _Bound>
324 : iota_view(_VSTD::move(__first.__value_), _VSTD::move(__last.__value_)) {}
323 requires same_as<_Start, _BoundSentinel>
324 : iota_view(std::move(__first.__value_), std::move(__last.__value_)) {}
325325
326326 _LIBCPP_HIDE_FROM_ABI
327 constexpr iota_view(__iterator __first, _Bound __last)
328 requires same_as<_Bound, unreachable_sentinel_t>
329 : iota_view(_VSTD::move(__first.__value_), _VSTD::move(__last)) {}
327 constexpr iota_view(__iterator __first, _BoundSentinel __last)
328 requires same_as<_BoundSentinel, unreachable_sentinel_t>
329 : iota_view(std::move(__first.__value_), std::move(__last)) {}
330330
331331 _LIBCPP_HIDE_FROM_ABI
332332 constexpr iota_view(__iterator __first, __sentinel __last)
333 requires (!same_as<_Start, _Bound> && !same_as<_Start, unreachable_sentinel_t>)
334 : iota_view(_VSTD::move(__first.__value_), _VSTD::move(__last.__bound_)) {}
333 requires(!same_as<_Start, _BoundSentinel> && !same_as<_Start, unreachable_sentinel_t>)
334 : iota_view(std::move(__first.__value_), std::move(__last.__bound_sentinel_)) {}
335335
336336 _LIBCPP_HIDE_FROM_ABI
337337 constexpr __iterator begin() const { return __iterator{__value_}; }
338338
339339 _LIBCPP_HIDE_FROM_ABI
340340 constexpr auto end() const {
341 if constexpr (same_as<_Bound, unreachable_sentinel_t>)
341 if constexpr (same_as<_BoundSentinel, unreachable_sentinel_t>)
342342 return unreachable_sentinel;
343343 else
344 return __sentinel{__bound_};
344 return __sentinel{__bound_sentinel_};
345345 }
346346
347347 _LIBCPP_HIDE_FROM_ABI
348 constexpr __iterator end() const requires same_as<_Start, _Bound> {
349 return __iterator{__bound_};
348 constexpr __iterator end() const
349 requires same_as<_Start, _BoundSentinel>
350 {
351 return __iterator{__bound_sentinel_};
350352 }
351353
352354 _LIBCPP_HIDE_FROM_ABI
353355 constexpr auto size() const
354 requires (same_as<_Start, _Bound> && __advanceable<_Start>) ||
355 (integral<_Start> && integral<_Bound>) ||
356 sized_sentinel_for<_Bound, _Start>
356 requires(same_as<_Start, _BoundSentinel> && __advanceable<_Start>) ||
357 (integral<_Start> && integral<_BoundSentinel>) || sized_sentinel_for<_BoundSentinel, _Start>
357358 {
358 if constexpr (__integer_like<_Start> && __integer_like<_Bound>) {
359 if constexpr (__integer_like<_Start> && __integer_like<_BoundSentinel>) {
359360 if (__value_ < 0) {
360 if (__bound_ < 0) {
361 return _VSTD::__to_unsigned_like(-__value_) - _VSTD::__to_unsigned_like(-__bound_);
361 if (__bound_sentinel_ < 0) {
362 return std::__to_unsigned_like(-__value_) - std::__to_unsigned_like(-__bound_sentinel_);
362363 }
363 return _VSTD::__to_unsigned_like(__bound_) + _VSTD::__to_unsigned_like(-__value_);
364 return std::__to_unsigned_like(__bound_sentinel_) + std::__to_unsigned_like(-__value_);
364365 }
365 return _VSTD::__to_unsigned_like(__bound_) - _VSTD::__to_unsigned_like(__value_);
366 return std::__to_unsigned_like(__bound_sentinel_) - std::__to_unsigned_like(__value_);
366367 }
367 return _VSTD::__to_unsigned_like(__bound_ - __value_);
368 return std::__to_unsigned_like(__bound_sentinel_ - __value_);
368369 }
369370 };
370371
371 template<class _Start, class _Bound>
372 requires (!__integer_like<_Start> || !__integer_like<_Bound> ||
373 (__signed_integer_like<_Start> == __signed_integer_like<_Bound>))
374 iota_view(_Start, _Bound) -> iota_view<_Start, _Bound>;
372 template <class _Start, class _BoundSentinel>
373 requires(!__integer_like<_Start> || !__integer_like<_BoundSentinel> ||
374 (__signed_integer_like<_Start> == __signed_integer_like<_BoundSentinel>))
375 iota_view(_Start, _BoundSentinel) -> iota_view<_Start, _BoundSentinel>;
375376
376 template<class _Start, class _Bound>
377 inline constexpr bool enable_borrowed_range<iota_view<_Start, _Bound>> = true;
377 template <class _Start, class _BoundSentinel>
378 inline constexpr bool enable_borrowed_range<iota_view<_Start, _BoundSentinel>> = true;
378379
379namespace views {
380namespace __iota {
380 namespace views {
381 namespace __iota {
381382 struct __fn {
382383 template<class _Start>
383384 _LIBCPP_HIDE_FROM_ABI
384385 constexpr auto operator()(_Start&& __start) const
385 noexcept(noexcept(ranges::iota_view(_VSTD::forward<_Start>(__start))))
386 -> decltype( ranges::iota_view(_VSTD::forward<_Start>(__start)))
387 { return ranges::iota_view(_VSTD::forward<_Start>(__start)); }
388
389 template<class _Start, class _Bound>
390 _LIBCPP_HIDE_FROM_ABI
391 constexpr auto operator()(_Start&& __start, _Bound&& __bound) const
392 noexcept(noexcept(ranges::iota_view(_VSTD::forward<_Start>(__start), _VSTD::forward<_Bound>(__bound))))
393 -> decltype( ranges::iota_view(_VSTD::forward<_Start>(__start), _VSTD::forward<_Bound>(__bound)))
394 { return ranges::iota_view(_VSTD::forward<_Start>(__start), _VSTD::forward<_Bound>(__bound)); }
386 noexcept(noexcept(ranges::iota_view(std::forward<_Start>(__start))))
387 -> decltype( ranges::iota_view(std::forward<_Start>(__start)))
388 { return ranges::iota_view(std::forward<_Start>(__start)); }
389
390 template <class _Start, class _BoundSentinel>
391 _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Start&& __start, _BoundSentinel&& __bound_sentinel) const
392 noexcept(noexcept(ranges::iota_view(std::forward<_Start>(__start), std::forward<_BoundSentinel>(__bound_sentinel))))
393 -> decltype( ranges::iota_view(std::forward<_Start>(__start), std::forward<_BoundSentinel>(__bound_sentinel)))
394 { return ranges::iota_view(std::forward<_Start>(__start), std::forward<_BoundSentinel>(__bound_sentinel)); }
395395 };
396396} // namespace __iota
397397
......@@ -401,7 +401,7 @@ inline namespace __cpo {
401401} // namespace views
402402} // namespace ranges
403403
404#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
404#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
405405
406406_LIBCPP_END_NAMESPACE_STD
407407
lib/libcxx/include/__ranges/join_view.h+40-20
......@@ -9,28 +9,33 @@
99#ifndef _LIBCPP___RANGES_JOIN_VIEW_H
1010#define _LIBCPP___RANGES_JOIN_VIEW_H
1111
12#include <__concepts/constructible.h>
13#include <__concepts/convertible_to.h>
14#include <__concepts/copyable.h>
15#include <__concepts/derived_from.h>
16#include <__concepts/equality_comparable.h>
1217#include <__config>
1318#include <__iterator/concepts.h>
19#include <__iterator/iter_move.h>
20#include <__iterator/iter_swap.h>
1421#include <__iterator/iterator_traits.h>
1522#include <__ranges/access.h>
1623#include <__ranges/all.h>
1724#include <__ranges/concepts.h>
1825#include <__ranges/non_propagating_cache.h>
19#include <__ranges/ref_view.h>
20#include <__ranges/subrange.h>
26#include <__ranges/range_adaptor.h>
2127#include <__ranges/view_interface.h>
22#include <__utility/declval.h>
2328#include <__utility/forward.h>
2429#include <optional>
2530#include <type_traits>
2631
2732#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
28#pragma GCC system_header
33# pragma GCC system_header
2934#endif
3035
3136_LIBCPP_BEGIN_NAMESPACE_STD
3237
33#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
38#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
3439
3540namespace ranges {
3641 template<class>
......@@ -45,7 +50,8 @@ namespace ranges {
4550 using _InnerC = typename iterator_traits<iterator_t<range_reference_t<_View>>>::iterator_category;
4651
4752 using iterator_category = _If<
48 derived_from<_OuterC, bidirectional_iterator_tag> && derived_from<_InnerC, bidirectional_iterator_tag>,
53 derived_from<_OuterC, bidirectional_iterator_tag> && derived_from<_InnerC, bidirectional_iterator_tag> &&
54 common_range<range_reference_t<_View>>,
4955 bidirectional_iterator_tag,
5056 _If<
5157 derived_from<_OuterC, forward_iterator_tag> && derived_from<_InnerC, forward_iterator_tag>,
......@@ -67,8 +73,8 @@ namespace ranges {
6773
6874 static constexpr bool _UseCache = !is_reference_v<_InnerRange>;
6975 using _Cache = _If<_UseCache, __non_propagating_cache<remove_cvref_t<_InnerRange>>, __empty_cache>;
70 [[no_unique_address]] _Cache __cache_;
71 _View __base_ = _View(); // TODO: [[no_unique_address]] makes clang crash! File a bug :)
76 _LIBCPP_NO_UNIQUE_ADDRESS _Cache __cache_;
77 _LIBCPP_NO_UNIQUE_ADDRESS _View __base_ = _View();
7278
7379 public:
7480 _LIBCPP_HIDE_FROM_ABI
......@@ -76,13 +82,13 @@ namespace ranges {
7682
7783 _LIBCPP_HIDE_FROM_ABI
7884 constexpr explicit join_view(_View __base)
79 : __base_(_VSTD::move(__base)) {}
85 : __base_(std::move(__base)) {}
8086
8187 _LIBCPP_HIDE_FROM_ABI
8288 constexpr _View base() const& requires copy_constructible<_View> { return __base_; }
8389
8490 _LIBCPP_HIDE_FROM_ABI
85 constexpr _View base() && { return _VSTD::move(__base_); }
91 constexpr _View base() && { return std::move(__base_); }
8692
8793 _LIBCPP_HIDE_FROM_ABI
8894 constexpr auto begin() {
......@@ -152,7 +158,7 @@ namespace ranges {
152158 _LIBCPP_HIDE_FROM_ABI
153159 constexpr __sentinel(__sentinel<!_Const> __s)
154160 requires _Const && convertible_to<sentinel_t<_View>, sentinel_t<_Base>>
155 : __end_(_VSTD::move(__s.__end_)) {}
161 : __end_(std::move(__s.__end_)) {}
156162
157163 template<bool _OtherConst>
158164 requires sentinel_for<sentinel_t<_Base>, iterator_t<__maybe_const<_OtherConst, _View>>>
......@@ -204,7 +210,8 @@ namespace ranges {
204210
205211 public:
206212 using iterator_concept = _If<
207 __ref_is_glvalue && bidirectional_range<_Base> && bidirectional_range<range_reference_t<_Base>>,
213 __ref_is_glvalue && bidirectional_range<_Base> && bidirectional_range<range_reference_t<_Base>> &&
214 common_range<range_reference_t<_Base>>,
208215 bidirectional_iterator_tag,
209216 _If<
210217 __ref_is_glvalue && forward_range<_Base> && forward_range<range_reference_t<_Base>>,
......@@ -223,8 +230,8 @@ namespace ranges {
223230
224231 _LIBCPP_HIDE_FROM_ABI
225232 constexpr __iterator(_Parent& __parent, _Outer __outer)
226 : __outer_(_VSTD::move(__outer))
227 , __parent_(_VSTD::addressof(__parent)) {
233 : __outer_(std::move(__outer))
234 , __parent_(std::addressof(__parent)) {
228235 __satisfy();
229236 }
230237
......@@ -233,8 +240,8 @@ namespace ranges {
233240 requires _Const &&
234241 convertible_to<iterator_t<_View>, _Outer> &&
235242 convertible_to<iterator_t<_InnerRange>, _Inner>
236 : __outer_(_VSTD::move(__i.__outer_))
237 , __inner_(_VSTD::move(__i.__inner_))
243 : __outer_(std::move(__i.__outer_))
244 , __inner_(std::move(__i.__inner_))
238245 , __parent_(__i.__parent_) {}
239246
240247 _LIBCPP_HIDE_FROM_ABI
......@@ -338,12 +345,25 @@ namespace ranges {
338345
339346 template<class _Range>
340347 explicit join_view(_Range&&) -> join_view<views::all_t<_Range>>;
341
348
349namespace views {
350namespace __join_view {
351struct __fn : __range_adaptor_closure<__fn> {
352 template<class _Range>
353 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
354 constexpr auto operator()(_Range&& __range) const
355 noexcept(noexcept(join_view<all_t<_Range&&>>(std::forward<_Range>(__range))))
356 -> decltype( join_view<all_t<_Range&&>>(std::forward<_Range>(__range)))
357 { return join_view<all_t<_Range&&>>(std::forward<_Range>(__range)); }
358};
359} // namespace __join_view
360inline namespace __cpo {
361 inline constexpr auto join = __join_view::__fn{};
362} // namespace __cpo
363} // namespace views
342364} // namespace ranges
343365
344#undef _CONSTEXPR_TERNARY
345
346#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
366#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
347367
348368_LIBCPP_END_NAMESPACE_STD
349369
lib/libcxx/include/__ranges/lazy_split_view.h created+465
......@@ -0,0 +1,465 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___RANGES_LAZY_SPLIT_VIEW_H
11#define _LIBCPP___RANGES_LAZY_SPLIT_VIEW_H
12
13#include <__algorithm/in_in_result.h>
14#include <__algorithm/ranges_find.h>
15#include <__algorithm/ranges_mismatch.h>
16#include <__concepts/constructible.h>
17#include <__concepts/convertible_to.h>
18#include <__concepts/derived_from.h>
19#include <__config>
20#include <__functional/bind_back.h>
21#include <__functional/ranges_operations.h>
22#include <__iterator/concepts.h>
23#include <__iterator/default_sentinel.h>
24#include <__iterator/incrementable_traits.h>
25#include <__iterator/indirectly_comparable.h>
26#include <__iterator/iter_move.h>
27#include <__iterator/iter_swap.h>
28#include <__iterator/iterator_traits.h>
29#include <__memory/addressof.h>
30#include <__ranges/access.h>
31#include <__ranges/all.h>
32#include <__ranges/concepts.h>
33#include <__ranges/non_propagating_cache.h>
34#include <__ranges/range_adaptor.h>
35#include <__ranges/single_view.h>
36#include <__ranges/subrange.h>
37#include <__ranges/view_interface.h>
38#include <__utility/forward.h>
39#include <__utility/move.h>
40#include <type_traits>
41
42#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
43# pragma GCC system_header
44#endif
45
46_LIBCPP_BEGIN_NAMESPACE_STD
47
48#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
49
50namespace ranges {
51
52template <auto> struct __require_constant;
53
54template <class _Range>
55concept __tiny_range =
56 sized_range<_Range> &&
57 requires { typename __require_constant<remove_reference_t<_Range>::size()>; } &&
58 (remove_reference_t<_Range>::size() <= 1);
59
60template <input_range _View, forward_range _Pattern>
61 requires view<_View> && view<_Pattern> &&
62 indirectly_comparable<iterator_t<_View>, iterator_t<_Pattern>, ranges::equal_to> &&
63 (forward_range<_View> || __tiny_range<_Pattern>)
64class lazy_split_view : public view_interface<lazy_split_view<_View, _Pattern>> {
65
66 _LIBCPP_NO_UNIQUE_ADDRESS _View __base_ = _View();
67 _LIBCPP_NO_UNIQUE_ADDRESS _Pattern __pattern_ = _Pattern();
68
69 using _MaybeCurrent = _If<!forward_range<_View>, __non_propagating_cache<iterator_t<_View>>, __empty_cache>;
70 _LIBCPP_NO_UNIQUE_ADDRESS _MaybeCurrent __current_ = _MaybeCurrent();
71
72 template <bool> struct __outer_iterator;
73 template <bool> struct __inner_iterator;
74
75public:
76 _LIBCPP_HIDE_FROM_ABI
77 lazy_split_view()
78 requires default_initializable<_View> && default_initializable<_Pattern> = default;
79
80 _LIBCPP_HIDE_FROM_ABI
81 constexpr lazy_split_view(_View __base, _Pattern __pattern)
82 : __base_(std::move(__base)), __pattern_(std::move(__pattern)) {}
83
84 template <input_range _Range>
85 requires constructible_from<_View, views::all_t<_Range>> &&
86 constructible_from<_Pattern, single_view<range_value_t<_Range>>>
87 _LIBCPP_HIDE_FROM_ABI
88 constexpr lazy_split_view(_Range&& __r, range_value_t<_Range> __e)
89 : __base_(views::all(std::forward<_Range>(__r)))
90 , __pattern_(views::single(std::move(__e))) {}
91
92 _LIBCPP_HIDE_FROM_ABI
93 constexpr _View base() const& requires copy_constructible<_View> { return __base_; }
94 _LIBCPP_HIDE_FROM_ABI
95 constexpr _View base() && { return std::move(__base_); }
96
97 _LIBCPP_HIDE_FROM_ABI
98 constexpr auto begin() {
99 if constexpr (forward_range<_View>) {
100 return __outer_iterator<__simple_view<_View> && __simple_view<_Pattern>>{*this, ranges::begin(__base_)};
101 } else {
102 __current_.__emplace(ranges::begin(__base_));
103 return __outer_iterator<false>{*this};
104 }
105 }
106
107 _LIBCPP_HIDE_FROM_ABI
108 constexpr auto begin() const requires forward_range<_View> && forward_range<const _View> {
109 return __outer_iterator<true>{*this, ranges::begin(__base_)};
110 }
111
112 _LIBCPP_HIDE_FROM_ABI
113 constexpr auto end() requires forward_range<_View> && common_range<_View> {
114 return __outer_iterator<__simple_view<_View> && __simple_view<_Pattern>>{*this, ranges::end(__base_)};
115 }
116
117 _LIBCPP_HIDE_FROM_ABI
118 constexpr auto end() const {
119 if constexpr (forward_range<_View> && forward_range<const _View> && common_range<const _View>) {
120 return __outer_iterator<true>{*this, ranges::end(__base_)};
121 } else {
122 return default_sentinel;
123 }
124 }
125
126private:
127
128 template <class>
129 struct __outer_iterator_category {};
130
131 template <forward_range _Tp>
132 struct __outer_iterator_category<_Tp> {
133 using iterator_category = input_iterator_tag;
134 };
135
136 template <bool _Const>
137 struct __outer_iterator : __outer_iterator_category<__maybe_const<_Const, _View>> {
138 private:
139 template <bool>
140 friend struct __inner_iterator;
141 friend __outer_iterator<true>;
142
143 using _Parent = __maybe_const<_Const, lazy_split_view>;
144 using _Base = __maybe_const<_Const, _View>;
145
146 _Parent* __parent_ = nullptr;
147 using _MaybeCurrent = _If<forward_range<_View>, iterator_t<_Base>, __empty_cache>;
148 _LIBCPP_NO_UNIQUE_ADDRESS _MaybeCurrent __current_ = _MaybeCurrent();
149 bool __trailing_empty_ = false;
150
151 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
152 constexpr auto& __current() noexcept {
153 if constexpr (forward_range<_View>) {
154 return __current_;
155 } else {
156 return *__parent_->__current_;
157 }
158 }
159
160 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
161 constexpr const auto& __current() const noexcept {
162 if constexpr (forward_range<_View>) {
163 return __current_;
164 } else {
165 return *__parent_->__current_;
166 }
167 }
168
169 // Workaround for the GCC issue that doesn't allow calling `__parent_->__base_` from friend functions (because
170 // `__base_` is private).
171 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
172 constexpr auto& __parent_base() const noexcept {
173 return __parent_->__base_;
174 }
175
176 public:
177 // using iterator_category = inherited;
178 using iterator_concept = conditional_t<forward_range<_Base>, forward_iterator_tag, input_iterator_tag>;
179 using difference_type = range_difference_t<_Base>;
180
181 struct value_type : view_interface<value_type> {
182 private:
183 __outer_iterator __i_ = __outer_iterator();
184
185 public:
186 _LIBCPP_HIDE_FROM_ABI
187 value_type() = default;
188 _LIBCPP_HIDE_FROM_ABI
189 constexpr explicit value_type(__outer_iterator __i)
190 : __i_(std::move(__i)) {}
191
192 _LIBCPP_HIDE_FROM_ABI
193 constexpr __inner_iterator<_Const> begin() const { return __inner_iterator<_Const>{__i_}; }
194 _LIBCPP_HIDE_FROM_ABI
195 constexpr default_sentinel_t end() const noexcept { return default_sentinel; }
196 };
197
198 _LIBCPP_HIDE_FROM_ABI
199 __outer_iterator() = default;
200
201 _LIBCPP_HIDE_FROM_ABI
202 constexpr explicit __outer_iterator(_Parent& __parent)
203 requires (!forward_range<_Base>)
204 : __parent_(std::addressof(__parent)) {}
205
206 _LIBCPP_HIDE_FROM_ABI
207 constexpr __outer_iterator(_Parent& __parent, iterator_t<_Base> __current)
208 requires forward_range<_Base>
209 : __parent_(std::addressof(__parent)), __current_(std::move(__current)) {}
210
211 _LIBCPP_HIDE_FROM_ABI
212 constexpr __outer_iterator(__outer_iterator<!_Const> __i)
213 requires _Const && convertible_to<iterator_t<_View>, iterator_t<_Base>>
214 : __parent_(__i.__parent_), __current_(std::move(__i.__current_)) {}
215
216 _LIBCPP_HIDE_FROM_ABI
217 constexpr value_type operator*() const { return value_type{*this}; }
218
219 _LIBCPP_HIDE_FROM_ABI
220 constexpr __outer_iterator& operator++() {
221 const auto __end = ranges::end(__parent_->__base_);
222 if (__current() == __end) {
223 __trailing_empty_ = false;
224 return *this;
225 }
226
227 const auto [__pbegin, __pend] = ranges::subrange{__parent_->__pattern_};
228 if (__pbegin == __pend) {
229 // Empty pattern: split on every element in the input range
230 ++__current();
231
232 } else if constexpr (__tiny_range<_Pattern>) {
233 // One-element pattern: we can use `ranges::find`.
234 __current() = ranges::find(std::move(__current()), __end, *__pbegin);
235 if (__current() != __end) {
236 // Make sure we point to after the separator we just found.
237 ++__current();
238 if (__current() == __end)
239 __trailing_empty_ = true;
240 }
241
242 } else {
243 // General case for n-element pattern.
244 do {
245 const auto [__b, __p] = ranges::mismatch(__current(), __end, __pbegin, __pend);
246 if (__p == __pend) {
247 __current() = __b;
248 if (__current() == __end) {
249 __trailing_empty_ = true;
250 }
251 break; // The pattern matched; skip it.
252 }
253 } while (++__current() != __end);
254 }
255
256 return *this;
257 }
258
259 _LIBCPP_HIDE_FROM_ABI
260 constexpr decltype(auto) operator++(int) {
261 if constexpr (forward_range<_Base>) {
262 auto __tmp = *this;
263 ++*this;
264 return __tmp;
265
266 } else {
267 ++*this;
268 }
269 }
270
271 _LIBCPP_HIDE_FROM_ABI
272 friend constexpr bool operator==(const __outer_iterator& __x, const __outer_iterator& __y)
273 requires forward_range<_Base> {
274 return __x.__current_ == __y.__current_ && __x.__trailing_empty_ == __y.__trailing_empty_;
275 }
276
277 _LIBCPP_HIDE_FROM_ABI
278 friend constexpr bool operator==(const __outer_iterator& __x, default_sentinel_t) {
279 _LIBCPP_ASSERT(__x.__parent_, "Cannot call comparison on a default-constructed iterator.");
280 return __x.__current() == ranges::end(__x.__parent_base()) && !__x.__trailing_empty_;
281 }
282 };
283
284 template <class>
285 struct __inner_iterator_category {};
286
287 template <forward_range _Tp>
288 struct __inner_iterator_category<_Tp> {
289 using iterator_category = _If<
290 derived_from<typename iterator_traits<iterator_t<_Tp>>::iterator_category, forward_iterator_tag>,
291 forward_iterator_tag,
292 typename iterator_traits<iterator_t<_Tp>>::iterator_category
293 >;
294 };
295
296 template <bool _Const>
297 struct __inner_iterator : __inner_iterator_category<__maybe_const<_Const, _View>> {
298 private:
299 using _Base = __maybe_const<_Const, _View>;
300 // Workaround for a GCC issue.
301 static constexpr bool _OuterConst = _Const;
302 __outer_iterator<_Const> __i_ = __outer_iterator<_OuterConst>();
303 bool __incremented_ = false;
304
305 // Note: these private functions are necessary because GCC doesn't allow calls to private members of `__i_` from
306 // free functions that are friends of `inner-iterator`.
307
308 _LIBCPP_HIDE_FROM_ABI
309 constexpr bool __is_done() const {
310 _LIBCPP_ASSERT(__i_.__parent_, "Cannot call comparison on a default-constructed iterator.");
311
312 auto [__pcur, __pend] = ranges::subrange{__i_.__parent_->__pattern_};
313 auto __end = ranges::end(__i_.__parent_->__base_);
314
315 if constexpr (__tiny_range<_Pattern>) {
316 const auto& __cur = __i_.__current();
317 if (__cur == __end)
318 return true;
319 if (__pcur == __pend)
320 return __incremented_;
321
322 return *__cur == *__pcur;
323
324 } else {
325 auto __cur = __i_.__current();
326 if (__cur == __end)
327 return true;
328 if (__pcur == __pend)
329 return __incremented_;
330
331 do {
332 if (*__cur != *__pcur)
333 return false;
334 if (++__pcur == __pend)
335 return true;
336 } while (++__cur != __end);
337
338 return false;
339 }
340 }
341
342 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
343 constexpr auto& __outer_current() noexcept {
344 return __i_.__current();
345 }
346
347 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
348 constexpr const auto& __outer_current() const noexcept {
349 return __i_.__current();
350 }
351
352 public:
353 // using iterator_category = inherited;
354 using iterator_concept = typename __outer_iterator<_Const>::iterator_concept;
355 using value_type = range_value_t<_Base>;
356 using difference_type = range_difference_t<_Base>;
357
358 _LIBCPP_HIDE_FROM_ABI
359 __inner_iterator() = default;
360
361 _LIBCPP_HIDE_FROM_ABI
362 constexpr explicit __inner_iterator(__outer_iterator<_Const> __i)
363 : __i_(std::move(__i)) {}
364
365 _LIBCPP_HIDE_FROM_ABI
366 constexpr const iterator_t<_Base>& base() const& noexcept { return __i_.__current(); }
367 _LIBCPP_HIDE_FROM_ABI
368 constexpr iterator_t<_Base> base() &&
369 requires forward_range<_View> { return std::move(__i_.__current()); }
370
371 _LIBCPP_HIDE_FROM_ABI
372 constexpr decltype(auto) operator*() const { return *__i_.__current(); }
373
374 _LIBCPP_HIDE_FROM_ABI
375 constexpr __inner_iterator& operator++() {
376 __incremented_ = true;
377
378 if constexpr (!forward_range<_Base>) {
379 if constexpr (_Pattern::size() == 0) {
380 return *this;
381 }
382 }
383
384 ++__i_.__current();
385 return *this;
386 }
387
388 _LIBCPP_HIDE_FROM_ABI
389 constexpr decltype(auto) operator++(int) {
390 if constexpr (forward_range<_Base>) {
391 auto __tmp = *this;
392 ++*this;
393 return __tmp;
394
395 } else {
396 ++*this;
397 }
398 }
399
400 _LIBCPP_HIDE_FROM_ABI
401 friend constexpr bool operator==(const __inner_iterator& __x, const __inner_iterator& __y)
402 requires forward_range<_Base> {
403 return __x.__outer_current() == __y.__outer_current();
404 }
405
406 _LIBCPP_HIDE_FROM_ABI
407 friend constexpr bool operator==(const __inner_iterator& __x, default_sentinel_t) {
408 return __x.__is_done();
409 }
410
411 _LIBCPP_HIDE_FROM_ABI
412 friend constexpr decltype(auto) iter_move(const __inner_iterator& __i)
413 noexcept(noexcept(ranges::iter_move(__i.__outer_current()))) {
414 return ranges::iter_move(__i.__outer_current());
415 }
416
417 _LIBCPP_HIDE_FROM_ABI
418 friend constexpr void iter_swap(const __inner_iterator& __x, const __inner_iterator& __y)
419 noexcept(noexcept(ranges::iter_swap(__x.__outer_current(), __y.__outer_current())))
420 requires indirectly_swappable<iterator_t<_Base>> {
421 ranges::iter_swap(__x.__outer_current(), __y.__outer_current());
422 }
423 };
424
425};
426
427template <class _Range, class _Pattern>
428lazy_split_view(_Range&&, _Pattern&&) -> lazy_split_view<views::all_t<_Range>, views::all_t<_Pattern>>;
429
430template <input_range _Range>
431lazy_split_view(_Range&&, range_value_t<_Range>)
432 -> lazy_split_view<views::all_t<_Range>, single_view<range_value_t<_Range>>>;
433
434namespace views {
435namespace __lazy_split_view {
436struct __fn : __range_adaptor_closure<__fn> {
437 template <class _Range, class _Pattern>
438 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
439 constexpr auto operator()(_Range&& __range, _Pattern&& __pattern) const
440 noexcept(noexcept(lazy_split_view(std::forward<_Range>(__range), std::forward<_Pattern>(__pattern))))
441 -> decltype( lazy_split_view(std::forward<_Range>(__range), std::forward<_Pattern>(__pattern)))
442 { return lazy_split_view(std::forward<_Range>(__range), std::forward<_Pattern>(__pattern)); }
443
444 template <class _Pattern>
445 requires constructible_from<decay_t<_Pattern>, _Pattern>
446 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
447 constexpr auto operator()(_Pattern&& __pattern) const
448 noexcept(is_nothrow_constructible_v<decay_t<_Pattern>, _Pattern>) {
449 return __range_adaptor_closure_t(std::__bind_back(*this, std::forward<_Pattern>(__pattern)));
450 }
451};
452} // namespace __lazy_split_view
453
454inline namespace __cpo {
455 inline constexpr auto lazy_split = __lazy_split_view::__fn{};
456} // namespace __cpo
457} // namespace views
458
459} // namespace ranges
460
461#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
462
463_LIBCPP_END_NAMESPACE_STD
464
465#endif // _LIBCPP___RANGES_LAZY_SPLIT_VIEW_H
lib/libcxx/include/__ranges/non_propagating_cache.h+6-6
......@@ -19,12 +19,12 @@
1919#include <type_traits>
2020
2121#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22#pragma GCC system_header
22# pragma GCC system_header
2323#endif
2424
2525_LIBCPP_BEGIN_NAMESPACE_STD
2626
27#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
27#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
2828
2929namespace ranges {
3030 // __non_propagating_cache is a helper type that allows storing an optional value in it,
......@@ -45,7 +45,7 @@ namespace ranges {
4545 // constructing the contained type from an iterator.
4646 struct __wrapper {
4747 template<class ..._Args>
48 constexpr explicit __wrapper(__forward_tag, _Args&& ...__args) : __t_(_VSTD::forward<_Args>(__args)...) { }
48 constexpr explicit __wrapper(__forward_tag, _Args&& ...__args) : __t_(std::forward<_Args>(__args)...) { }
4949 template<class _Fn>
5050 constexpr explicit __wrapper(__from_tag, _Fn const& __f) : __t_(__f()) { }
5151 _Tp __t_;
......@@ -70,7 +70,7 @@ namespace ranges {
7070
7171 _LIBCPP_HIDE_FROM_ABI
7272 constexpr __non_propagating_cache& operator=(__non_propagating_cache const& __other) noexcept {
73 if (this != _VSTD::addressof(__other)) {
73 if (this != std::addressof(__other)) {
7474 __value_.reset();
7575 }
7676 return *this;
......@@ -100,14 +100,14 @@ namespace ranges {
100100 template<class ..._Args>
101101 _LIBCPP_HIDE_FROM_ABI
102102 constexpr _Tp& __emplace(_Args&& ...__args) {
103 return __value_.emplace(__forward_tag{}, _VSTD::forward<_Args>(__args)...).__t_;
103 return __value_.emplace(__forward_tag{}, std::forward<_Args>(__args)...).__t_;
104104 }
105105 };
106106
107107 struct __empty_cache { };
108108} // namespace ranges
109109
110#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
110#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
111111
112112_LIBCPP_END_NAMESPACE_STD
113113
lib/libcxx/include/__ranges/owning_view.h+6-6
......@@ -23,12 +23,12 @@
2323#include <type_traits>
2424
2525#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
26#pragma GCC system_header
26# pragma GCC system_header
2727#endif
2828
2929_LIBCPP_BEGIN_NAMESPACE_STD
3030
31#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
31#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
3232
3333namespace ranges {
3434 template<range _Rp>
......@@ -38,15 +38,15 @@ namespace ranges {
3838
3939public:
4040 owning_view() requires default_initializable<_Rp> = default;
41 _LIBCPP_HIDE_FROM_ABI constexpr owning_view(_Rp&& __r) : __r_(_VSTD::move(__r)) {}
41 _LIBCPP_HIDE_FROM_ABI constexpr owning_view(_Rp&& __r) : __r_(std::move(__r)) {}
4242
4343 owning_view(owning_view&&) = default;
4444 owning_view& operator=(owning_view&&) = default;
4545
4646 _LIBCPP_HIDE_FROM_ABI constexpr _Rp& base() & noexcept { return __r_; }
4747 _LIBCPP_HIDE_FROM_ABI constexpr const _Rp& base() const& noexcept { return __r_; }
48 _LIBCPP_HIDE_FROM_ABI constexpr _Rp&& base() && noexcept { return _VSTD::move(__r_); }
49 _LIBCPP_HIDE_FROM_ABI constexpr const _Rp&& base() const&& noexcept { return _VSTD::move(__r_); }
48 _LIBCPP_HIDE_FROM_ABI constexpr _Rp&& base() && noexcept { return std::move(__r_); }
49 _LIBCPP_HIDE_FROM_ABI constexpr const _Rp&& base() const&& noexcept { return std::move(__r_); }
5050
5151 _LIBCPP_HIDE_FROM_ABI constexpr iterator_t<_Rp> begin() { return ranges::begin(__r_); }
5252 _LIBCPP_HIDE_FROM_ABI constexpr sentinel_t<_Rp> end() { return ranges::end(__r_); }
......@@ -74,7 +74,7 @@ public:
7474
7575} // namespace ranges
7676
77#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
77#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
7878
7979_LIBCPP_END_NAMESPACE_STD
8080
lib/libcxx/include/__ranges/range_adaptor.h+6-6
......@@ -20,12 +20,12 @@
2020#include <type_traits>
2121
2222#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23#pragma GCC system_header
23# pragma GCC system_header
2424#endif
2525
2626_LIBCPP_BEGIN_NAMESPACE_STD
2727
28#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
28#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
2929
3030// CRTP base that one can derive from in order to be considered a range adaptor closure
3131// by the library. When deriving from this class, a pipe operator will be provided to
......@@ -39,7 +39,7 @@ struct __range_adaptor_closure;
3939// i.e. something that can be called via the `x | f` notation.
4040template <class _Fn>
4141struct __range_adaptor_closure_t : _Fn, __range_adaptor_closure<__range_adaptor_closure_t<_Fn>> {
42 constexpr explicit __range_adaptor_closure_t(_Fn&& __f) : _Fn(_VSTD::move(__f)) { }
42 constexpr explicit __range_adaptor_closure_t(_Fn&& __f) : _Fn(std::move(__f)) { }
4343};
4444
4545template <class _Tp>
......@@ -53,7 +53,7 @@ struct __range_adaptor_closure {
5353 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
5454 friend constexpr decltype(auto) operator|(_View&& __view, _Closure&& __closure)
5555 noexcept(is_nothrow_invocable_v<_Closure, _View>)
56 { return _VSTD::invoke(_VSTD::forward<_Closure>(__closure), _VSTD::forward<_View>(__view)); }
56 { return std::invoke(std::forward<_Closure>(__closure), std::forward<_View>(__view)); }
5757
5858 template <_RangeAdaptorClosure _Closure, _RangeAdaptorClosure _OtherClosure>
5959 requires same_as<_Tp, remove_cvref_t<_Closure>> &&
......@@ -63,10 +63,10 @@ struct __range_adaptor_closure {
6363 friend constexpr auto operator|(_Closure&& __c1, _OtherClosure&& __c2)
6464 noexcept(is_nothrow_constructible_v<decay_t<_Closure>, _Closure> &&
6565 is_nothrow_constructible_v<decay_t<_OtherClosure>, _OtherClosure>)
66 { return __range_adaptor_closure_t(_VSTD::__compose(_VSTD::forward<_OtherClosure>(__c2), _VSTD::forward<_Closure>(__c1))); }
66 { return __range_adaptor_closure_t(std::__compose(std::forward<_OtherClosure>(__c2), std::forward<_Closure>(__c1))); }
6767};
6868
69#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
69#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
7070
7171_LIBCPP_END_NAMESPACE_STD
7272
lib/libcxx/include/__ranges/rbegin.h created+130
......@@ -0,0 +1,130 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9#ifndef _LIBCPP___RANGES_RBEGIN_H
10#define _LIBCPP___RANGES_RBEGIN_H
11
12#include <__concepts/class_or_enum.h>
13#include <__concepts/same_as.h>
14#include <__config>
15#include <__iterator/concepts.h>
16#include <__iterator/readable_traits.h>
17#include <__iterator/reverse_iterator.h>
18#include <__ranges/access.h>
19#include <__utility/auto_cast.h>
20#include <type_traits>
21
22#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23# pragma GCC system_header
24#endif
25
26_LIBCPP_BEGIN_NAMESPACE_STD
27
28#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
29
30// [ranges.access.rbegin]
31
32namespace ranges {
33namespace __rbegin {
34template <class _Tp>
35concept __member_rbegin =
36 __can_borrow<_Tp> &&
37 __workaround_52970<_Tp> &&
38 requires(_Tp&& __t) {
39 { _LIBCPP_AUTO_CAST(__t.rbegin()) } -> input_or_output_iterator;
40 };
41
42void rbegin(auto&) = delete;
43void rbegin(const auto&) = delete;
44
45template <class _Tp>
46concept __unqualified_rbegin =
47 !__member_rbegin<_Tp> &&
48 __can_borrow<_Tp> &&
49 __class_or_enum<remove_cvref_t<_Tp>> &&
50 requires(_Tp&& __t) {
51 { _LIBCPP_AUTO_CAST(rbegin(__t)) } -> input_or_output_iterator;
52 };
53
54template <class _Tp>
55concept __can_reverse =
56 __can_borrow<_Tp> &&
57 !__member_rbegin<_Tp> &&
58 !__unqualified_rbegin<_Tp> &&
59 requires(_Tp&& __t) {
60 { ranges::begin(__t) } -> same_as<decltype(ranges::end(__t))>;
61 { ranges::begin(__t) } -> bidirectional_iterator;
62 };
63
64struct __fn {
65 template <class _Tp>
66 requires __member_rbegin<_Tp>
67 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
68 noexcept(noexcept(_LIBCPP_AUTO_CAST(__t.rbegin())))
69 {
70 return _LIBCPP_AUTO_CAST(__t.rbegin());
71 }
72
73 template <class _Tp>
74 requires __unqualified_rbegin<_Tp>
75 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
76 noexcept(noexcept(_LIBCPP_AUTO_CAST(rbegin(__t))))
77 {
78 return _LIBCPP_AUTO_CAST(rbegin(__t));
79 }
80
81 template <class _Tp>
82 requires __can_reverse<_Tp>
83 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
84 noexcept(noexcept(ranges::end(__t)))
85 {
86 return std::make_reverse_iterator(ranges::end(__t));
87 }
88
89 void operator()(auto&&) const = delete;
90};
91} // namespace __rbegin
92
93inline namespace __cpo {
94 inline constexpr auto rbegin = __rbegin::__fn{};
95} // namespace __cpo
96} // namespace ranges
97
98// [range.access.crbegin]
99
100namespace ranges {
101namespace __crbegin {
102struct __fn {
103 template <class _Tp>
104 requires is_lvalue_reference_v<_Tp&&>
105 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
106 constexpr auto operator()(_Tp&& __t) const
107 noexcept(noexcept(ranges::rbegin(static_cast<const remove_reference_t<_Tp>&>(__t))))
108 -> decltype( ranges::rbegin(static_cast<const remove_reference_t<_Tp>&>(__t)))
109 { return ranges::rbegin(static_cast<const remove_reference_t<_Tp>&>(__t)); }
110
111 template <class _Tp>
112 requires is_rvalue_reference_v<_Tp&&>
113 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
114 constexpr auto operator()(_Tp&& __t) const
115 noexcept(noexcept(ranges::rbegin(static_cast<const _Tp&&>(__t))))
116 -> decltype( ranges::rbegin(static_cast<const _Tp&&>(__t)))
117 { return ranges::rbegin(static_cast<const _Tp&&>(__t)); }
118};
119} // namespace __crbegin
120
121inline namespace __cpo {
122 inline constexpr auto crbegin = __crbegin::__fn{};
123} // namespace __cpo
124} // namespace ranges
125
126#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
127
128_LIBCPP_END_NAMESPACE_STD
129
130#endif // _LIBCPP___RANGES_RBEGIN_H
lib/libcxx/include/__ranges/ref_view.h+4-4
......@@ -26,12 +26,12 @@
2626#include <type_traits>
2727
2828#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
29#pragma GCC system_header
29# pragma GCC system_header
3030#endif
3131
3232_LIBCPP_BEGIN_NAMESPACE_STD
3333
34#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
34#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
3535
3636namespace ranges {
3737 template<range _Range>
......@@ -48,7 +48,7 @@ public:
4848 convertible_to<_Tp, _Range&> && requires { __fun(declval<_Tp>()); }
4949 _LIBCPP_HIDE_FROM_ABI
5050 constexpr ref_view(_Tp&& __t)
51 : __range_(_VSTD::addressof(static_cast<_Range&>(_VSTD::forward<_Tp>(__t))))
51 : __range_(std::addressof(static_cast<_Range&>(std::forward<_Tp>(__t))))
5252 {}
5353
5454 _LIBCPP_HIDE_FROM_ABI constexpr _Range& base() const { return *__range_; }
......@@ -79,7 +79,7 @@ public:
7979 inline constexpr bool enable_borrowed_range<ref_view<_Tp>> = true;
8080} // namespace ranges
8181
82#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
82#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
8383
8484_LIBCPP_END_NAMESPACE_STD
8585
lib/libcxx/include/__ranges/rend.h created+134
......@@ -0,0 +1,134 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9#ifndef _LIBCPP___RANGES_REND_H
10#define _LIBCPP___RANGES_REND_H
11
12#include <__concepts/class_or_enum.h>
13#include <__concepts/same_as.h>
14#include <__config>
15#include <__iterator/concepts.h>
16#include <__iterator/readable_traits.h>
17#include <__iterator/reverse_iterator.h>
18#include <__ranges/access.h>
19#include <__ranges/rbegin.h>
20#include <__utility/auto_cast.h>
21#include <type_traits>
22
23#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
24# pragma GCC system_header
25#endif
26
27_LIBCPP_BEGIN_NAMESPACE_STD
28
29#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
30
31// [range.access.rend]
32
33namespace ranges {
34namespace __rend {
35template <class _Tp>
36concept __member_rend =
37 __can_borrow<_Tp> &&
38 __workaround_52970<_Tp> &&
39 requires(_Tp&& __t) {
40 ranges::rbegin(__t);
41 { _LIBCPP_AUTO_CAST(__t.rend()) } -> sentinel_for<decltype(ranges::rbegin(__t))>;
42 };
43
44void rend(auto&) = delete;
45void rend(const auto&) = delete;
46
47template <class _Tp>
48concept __unqualified_rend =
49 !__member_rend<_Tp> &&
50 __can_borrow<_Tp> &&
51 __class_or_enum<remove_cvref_t<_Tp>> &&
52 requires(_Tp&& __t) {
53 ranges::rbegin(__t);
54 { _LIBCPP_AUTO_CAST(rend(__t)) } -> sentinel_for<decltype(ranges::rbegin(__t))>;
55 };
56
57template <class _Tp>
58concept __can_reverse =
59 __can_borrow<_Tp> &&
60 !__member_rend<_Tp> &&
61 !__unqualified_rend<_Tp> &&
62 requires(_Tp&& __t) {
63 { ranges::begin(__t) } -> same_as<decltype(ranges::end(__t))>;
64 { ranges::begin(__t) } -> bidirectional_iterator;
65 };
66
67class __fn {
68public:
69 template <class _Tp>
70 requires __member_rend<_Tp>
71 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
72 noexcept(noexcept(_LIBCPP_AUTO_CAST(__t.rend())))
73 {
74 return _LIBCPP_AUTO_CAST(__t.rend());
75 }
76
77 template <class _Tp>
78 requires __unqualified_rend<_Tp>
79 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
80 noexcept(noexcept(_LIBCPP_AUTO_CAST(rend(__t))))
81 {
82 return _LIBCPP_AUTO_CAST(rend(__t));
83 }
84
85 template <class _Tp>
86 requires __can_reverse<_Tp>
87 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
88 noexcept(noexcept(ranges::begin(__t)))
89 {
90 return std::make_reverse_iterator(ranges::begin(__t));
91 }
92
93 void operator()(auto&&) const = delete;
94};
95} // namespace __rend
96
97inline namespace __cpo {
98 inline constexpr auto rend = __rend::__fn{};
99} // namespace __cpo
100} // namespace ranges
101
102// [range.access.crend]
103
104namespace ranges {
105namespace __crend {
106struct __fn {
107 template <class _Tp>
108 requires is_lvalue_reference_v<_Tp&&>
109 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
110 constexpr auto operator()(_Tp&& __t) const
111 noexcept(noexcept(ranges::rend(static_cast<const remove_reference_t<_Tp>&>(__t))))
112 -> decltype( ranges::rend(static_cast<const remove_reference_t<_Tp>&>(__t)))
113 { return ranges::rend(static_cast<const remove_reference_t<_Tp>&>(__t)); }
114
115 template <class _Tp>
116 requires is_rvalue_reference_v<_Tp&&>
117 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
118 constexpr auto operator()(_Tp&& __t) const
119 noexcept(noexcept(ranges::rend(static_cast<const _Tp&&>(__t))))
120 -> decltype( ranges::rend(static_cast<const _Tp&&>(__t)))
121 { return ranges::rend(static_cast<const _Tp&&>(__t)); }
122};
123} // namespace __crend
124
125inline namespace __cpo {
126 inline constexpr auto crend = __crend::__fn{};
127} // namespace __cpo
128} // namespace ranges
129
130#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
131
132_LIBCPP_END_NAMESPACE_STD
133
134#endif // _LIBCPP___RANGES_REND_H
lib/libcxx/include/__ranges/reverse_view.h+24-24
......@@ -28,12 +28,12 @@
2828#include <type_traits>
2929
3030#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
31#pragma GCC system_header
31# pragma GCC system_header
3232#endif
3333
3434_LIBCPP_BEGIN_NAMESPACE_STD
3535
36#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
36#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
3737
3838namespace ranges {
3939 template<view _View>
......@@ -43,21 +43,21 @@ namespace ranges {
4343 // amortized O(1) begin() method.
4444 static constexpr bool _UseCache = !random_access_range<_View> && !common_range<_View>;
4545 using _Cache = _If<_UseCache, __non_propagating_cache<reverse_iterator<iterator_t<_View>>>, __empty_cache>;
46 [[no_unique_address]] _Cache __cached_begin_ = _Cache();
47 [[no_unique_address]] _View __base_ = _View();
46 _LIBCPP_NO_UNIQUE_ADDRESS _Cache __cached_begin_ = _Cache();
47 _LIBCPP_NO_UNIQUE_ADDRESS _View __base_ = _View();
4848
4949 public:
5050 _LIBCPP_HIDE_FROM_ABI
5151 reverse_view() requires default_initializable<_View> = default;
5252
5353 _LIBCPP_HIDE_FROM_ABI
54 constexpr explicit reverse_view(_View __view) : __base_(_VSTD::move(__view)) {}
54 constexpr explicit reverse_view(_View __view) : __base_(std::move(__view)) {}
5555
5656 _LIBCPP_HIDE_FROM_ABI
5757 constexpr _View base() const& requires copy_constructible<_View> { return __base_; }
5858
5959 _LIBCPP_HIDE_FROM_ABI
60 constexpr _View base() && { return _VSTD::move(__base_); }
60 constexpr _View base() && { return std::move(__base_); }
6161
6262 _LIBCPP_HIDE_FROM_ABI
6363 constexpr reverse_iterator<iterator_t<_View>> begin() {
......@@ -65,7 +65,7 @@ namespace ranges {
6565 if (__cached_begin_.__has_value())
6666 return *__cached_begin_;
6767
68 auto __tmp = _VSTD::make_reverse_iterator(ranges::next(ranges::begin(__base_), ranges::end(__base_)));
68 auto __tmp = std::make_reverse_iterator(ranges::next(ranges::begin(__base_), ranges::end(__base_)));
6969 if constexpr (_UseCache)
7070 __cached_begin_.__emplace(__tmp);
7171 return __tmp;
......@@ -73,22 +73,22 @@ namespace ranges {
7373
7474 _LIBCPP_HIDE_FROM_ABI
7575 constexpr reverse_iterator<iterator_t<_View>> begin() requires common_range<_View> {
76 return _VSTD::make_reverse_iterator(ranges::end(__base_));
76 return std::make_reverse_iterator(ranges::end(__base_));
7777 }
7878
7979 _LIBCPP_HIDE_FROM_ABI
8080 constexpr auto begin() const requires common_range<const _View> {
81 return _VSTD::make_reverse_iterator(ranges::end(__base_));
81 return std::make_reverse_iterator(ranges::end(__base_));
8282 }
8383
8484 _LIBCPP_HIDE_FROM_ABI
8585 constexpr reverse_iterator<iterator_t<_View>> end() {
86 return _VSTD::make_reverse_iterator(ranges::begin(__base_));
86 return std::make_reverse_iterator(ranges::begin(__base_));
8787 }
8888
8989 _LIBCPP_HIDE_FROM_ABI
9090 constexpr auto end() const requires common_range<const _View> {
91 return _VSTD::make_reverse_iterator(ranges::begin(__base_));
91 return std::make_reverse_iterator(ranges::begin(__base_));
9292 }
9393
9494 _LIBCPP_HIDE_FROM_ABI
......@@ -111,22 +111,22 @@ namespace ranges {
111111 namespace views {
112112 namespace __reverse {
113113 template<class _Tp>
114 constexpr bool __is_reverse_view = false;
114 inline constexpr bool __is_reverse_view = false;
115115
116116 template<class _Tp>
117 constexpr bool __is_reverse_view<reverse_view<_Tp>> = true;
117 inline constexpr bool __is_reverse_view<reverse_view<_Tp>> = true;
118118
119119 template<class _Tp>
120 constexpr bool __is_sized_reverse_subrange = false;
120 inline constexpr bool __is_sized_reverse_subrange = false;
121121
122122 template<class _Iter>
123 constexpr bool __is_sized_reverse_subrange<subrange<reverse_iterator<_Iter>, reverse_iterator<_Iter>, subrange_kind::sized>> = true;
123 inline constexpr bool __is_sized_reverse_subrange<subrange<reverse_iterator<_Iter>, reverse_iterator<_Iter>, subrange_kind::sized>> = true;
124124
125125 template<class _Tp>
126 constexpr bool __is_unsized_reverse_subrange = false;
126 inline constexpr bool __is_unsized_reverse_subrange = false;
127127
128128 template<class _Iter, subrange_kind _Kind>
129 constexpr bool __is_unsized_reverse_subrange<subrange<reverse_iterator<_Iter>, reverse_iterator<_Iter>, _Kind>> = _Kind == subrange_kind::unsized;
129 inline constexpr bool __is_unsized_reverse_subrange<subrange<reverse_iterator<_Iter>, reverse_iterator<_Iter>, _Kind>> = _Kind == subrange_kind::unsized;
130130
131131 template<class _Tp>
132132 struct __unwrapped_reverse_subrange {
......@@ -143,9 +143,9 @@ namespace ranges {
143143 requires __is_reverse_view<remove_cvref_t<_Range>>
144144 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
145145 constexpr auto operator()(_Range&& __range) const
146 noexcept(noexcept(_VSTD::forward<_Range>(__range).base()))
147 -> decltype( _VSTD::forward<_Range>(__range).base())
148 { return _VSTD::forward<_Range>(__range).base(); }
146 noexcept(noexcept(std::forward<_Range>(__range).base()))
147 -> decltype( std::forward<_Range>(__range).base())
148 { return std::forward<_Range>(__range).base(); }
149149
150150 template<class _Range,
151151 class _UnwrappedSubrange = typename __unwrapped_reverse_subrange<remove_cvref_t<_Range>>::type>
......@@ -171,9 +171,9 @@ namespace ranges {
171171 !__is_unsized_reverse_subrange<remove_cvref_t<_Range>>)
172172 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
173173 constexpr auto operator()(_Range&& __range) const
174 noexcept(noexcept(reverse_view{_VSTD::forward<_Range>(__range)}))
175 -> decltype( reverse_view{_VSTD::forward<_Range>(__range)})
176 { return reverse_view{_VSTD::forward<_Range>(__range)}; }
174 noexcept(noexcept(reverse_view{std::forward<_Range>(__range)}))
175 -> decltype( reverse_view{std::forward<_Range>(__range)})
176 { return reverse_view{std::forward<_Range>(__range)}; }
177177 };
178178 } // namespace __reverse
179179
......@@ -183,7 +183,7 @@ namespace ranges {
183183 } // namespace views
184184} // namespace ranges
185185
186#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
186#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
187187
188188_LIBCPP_END_NAMESPACE_STD
189189
lib/libcxx/include/__ranges/single_view.h+27-7
......@@ -11,6 +11,7 @@
1111
1212#include <__config>
1313#include <__ranges/copyable_box.h>
14#include <__ranges/range_adaptor.h>
1415#include <__ranges/view_interface.h>
1516#include <__utility/forward.h>
1617#include <__utility/in_place.h>
......@@ -19,12 +20,12 @@
1920#include <type_traits>
2021
2122#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22#pragma GCC system_header
23# pragma GCC system_header
2324#endif
2425
2526_LIBCPP_BEGIN_NAMESPACE_STD
2627
27#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
28#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
2829
2930namespace ranges {
3031 template<copy_constructible _Tp>
......@@ -40,13 +41,13 @@ namespace ranges {
4041 constexpr explicit single_view(const _Tp& __t) : __value_(in_place, __t) {}
4142
4243 _LIBCPP_HIDE_FROM_ABI
43 constexpr explicit single_view(_Tp&& __t) : __value_(in_place, _VSTD::move(__t)) {}
44 constexpr explicit single_view(_Tp&& __t) : __value_(in_place, std::move(__t)) {}
4445
4546 template<class... _Args>
4647 requires constructible_from<_Tp, _Args...>
4748 _LIBCPP_HIDE_FROM_ABI
4849 constexpr explicit single_view(in_place_t, _Args&&... __args)
49 : __value_{in_place, _VSTD::forward<_Args>(__args)...} {}
50 : __value_{in_place, std::forward<_Args>(__args)...} {}
5051
5152 _LIBCPP_HIDE_FROM_ABI
5253 constexpr _Tp* begin() noexcept { return data(); }
......@@ -70,11 +71,30 @@ namespace ranges {
7071 constexpr const _Tp* data() const noexcept { return __value_.operator->(); }
7172 };
7273
73 template<class _Tp>
74 single_view(_Tp) -> single_view<_Tp>;
74template<class _Tp>
75single_view(_Tp) -> single_view<_Tp>;
76
77namespace views {
78namespace __single_view {
79
80struct __fn : __range_adaptor_closure<__fn> {
81 template<class _Range>
82 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
83 constexpr auto operator()(_Range&& __range) const
84 noexcept(noexcept(single_view<decay_t<_Range&&>>(std::forward<_Range>(__range))))
85 -> decltype( single_view<decay_t<_Range&&>>(std::forward<_Range>(__range)))
86 { return single_view<decay_t<_Range&&>>(std::forward<_Range>(__range)); }
87};
88} // namespace __single_view
89
90inline namespace __cpo {
91 inline constexpr auto single = __single_view::__fn{};
92} // namespace __cpo
93
94} // namespace views
7595} // namespace ranges
7696
77#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
97#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
7898
7999_LIBCPP_END_NAMESPACE_STD
80100
lib/libcxx/include/__ranges/size.h+84-77
......@@ -19,12 +19,12 @@
1919#include <type_traits>
2020
2121#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22#pragma GCC system_header
22# pragma GCC system_header
2323#endif
2424
2525_LIBCPP_BEGIN_NAMESPACE_STD
2626
27#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
27#if _LIBCPP_STD_VER > 17
2828
2929namespace ranges {
3030 template<class>
......@@ -35,68 +35,76 @@ namespace ranges {
3535
3636namespace ranges {
3737namespace __size {
38 void size(auto&) = delete;
39 void size(const auto&) = delete;
40
41 template <class _Tp>
42 concept __size_enabled = !disable_sized_range<remove_cvref_t<_Tp>>;
43
44 template <class _Tp>
45 concept __member_size =
46 __size_enabled<_Tp> &&
47 __workaround_52970<_Tp> &&
48 requires(_Tp&& __t) {
49 { _LIBCPP_AUTO_CAST(__t.size()) } -> __integer_like;
50 };
51
52 template <class _Tp>
53 concept __unqualified_size =
54 __size_enabled<_Tp> &&
55 !__member_size<_Tp> &&
56 __class_or_enum<remove_cvref_t<_Tp>> &&
57 requires(_Tp&& __t) {
58 { _LIBCPP_AUTO_CAST(size(__t)) } -> __integer_like;
59 };
60
61 template <class _Tp>
62 concept __difference =
63 !__member_size<_Tp> &&
64 !__unqualified_size<_Tp> &&
65 __class_or_enum<remove_cvref_t<_Tp>> &&
66 requires(_Tp&& __t) {
67 { ranges::begin(__t) } -> forward_iterator;
68 { ranges::end(__t) } -> sized_sentinel_for<decltype(ranges::begin(declval<_Tp>()))>;
69 };
70
71 struct __fn {
72 template <class _Tp, size_t _Sz>
73 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr size_t operator()(_Tp (&&)[_Sz]) const noexcept {
74 return _Sz;
75 }
76
77 template <class _Tp, size_t _Sz>
78 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr size_t operator()(_Tp (&)[_Sz]) const noexcept {
79 return _Sz;
80 }
81
82 template <__member_size _Tp>
83 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr __integer_like auto operator()(_Tp&& __t) const
84 noexcept(noexcept(_LIBCPP_AUTO_CAST(__t.size()))) {
85 return _LIBCPP_AUTO_CAST(__t.size());
86 }
87
88 template <__unqualified_size _Tp>
89 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr __integer_like auto operator()(_Tp&& __t) const
90 noexcept(noexcept(_LIBCPP_AUTO_CAST(size(__t)))) {
91 return _LIBCPP_AUTO_CAST(size(__t));
92 }
93
94 template<__difference _Tp>
95 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr __integer_like auto operator()(_Tp&& __t) const
96 noexcept(noexcept(ranges::end(__t) - ranges::begin(__t))) {
97 return _VSTD::__to_unsigned_like(ranges::end(__t) - ranges::begin(__t));
98 }
38void size(auto&) = delete;
39void size(const auto&) = delete;
40
41template <class _Tp>
42concept __size_enabled = !disable_sized_range<remove_cvref_t<_Tp>>;
43
44template <class _Tp>
45concept __member_size =
46 __size_enabled<_Tp> &&
47 __workaround_52970<_Tp> &&
48 requires(_Tp&& __t) {
49 { _LIBCPP_AUTO_CAST(__t.size()) } -> __integer_like;
9950 };
51
52template <class _Tp>
53concept __unqualified_size =
54 __size_enabled<_Tp> &&
55 !__member_size<_Tp> &&
56 __class_or_enum<remove_cvref_t<_Tp>> &&
57 requires(_Tp&& __t) {
58 { _LIBCPP_AUTO_CAST(size(__t)) } -> __integer_like;
59 };
60
61template <class _Tp>
62concept __difference =
63 !__member_size<_Tp> &&
64 !__unqualified_size<_Tp> &&
65 __class_or_enum<remove_cvref_t<_Tp>> &&
66 requires(_Tp&& __t) {
67 { ranges::begin(__t) } -> forward_iterator;
68 { ranges::end(__t) } -> sized_sentinel_for<decltype(ranges::begin(declval<_Tp>()))>;
69 };
70
71struct __fn {
72
73 // `[range.prim.size]`: the array case (for rvalues).
74 template <class _Tp, size_t _Sz>
75 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr size_t operator()(_Tp (&&)[_Sz]) const noexcept {
76 return _Sz;
77 }
78
79 // `[range.prim.size]`: the array case (for lvalues).
80 template <class _Tp, size_t _Sz>
81 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr size_t operator()(_Tp (&)[_Sz]) const noexcept {
82 return _Sz;
83 }
84
85 // `[range.prim.size]`: `auto(t.size())` is a valid expression.
86 template <__member_size _Tp>
87 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr __integer_like auto operator()(_Tp&& __t) const
88 noexcept(noexcept(_LIBCPP_AUTO_CAST(__t.size()))) {
89 return _LIBCPP_AUTO_CAST(__t.size());
90 }
91
92 // `[range.prim.size]`: `auto(size(t))` is a valid expression.
93 template <__unqualified_size _Tp>
94 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr __integer_like auto operator()(_Tp&& __t) const
95 noexcept(noexcept(_LIBCPP_AUTO_CAST(size(__t)))) {
96 return _LIBCPP_AUTO_CAST(size(__t));
97 }
98
99 // [range.prim.size]: the `to-unsigned-like` case.
100 template <__difference _Tp>
101 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
102 noexcept(noexcept(std::__to_unsigned_like(ranges::end(__t) - ranges::begin(__t))))
103 -> decltype( std::__to_unsigned_like(ranges::end(__t) - ranges::begin(__t)))
104 { return std::__to_unsigned_like(ranges::end(__t) - ranges::begin(__t));
105 }
106};
107
100108} // namespace __size
101109
102110inline namespace __cpo {
......@@ -108,19 +116,18 @@ inline namespace __cpo {
108116
109117namespace ranges {
110118namespace __ssize {
111 struct __fn {
112 template<class _Tp>
113 requires requires (_Tp&& __t) { ranges::size(__t); }
114 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr integral auto operator()(_Tp&& __t) const
115 noexcept(noexcept(ranges::size(__t)))
116 {
117 using _Signed = make_signed_t<decltype(ranges::size(__t))>;
118 if constexpr (sizeof(ptrdiff_t) > sizeof(_Signed))
119 return static_cast<ptrdiff_t>(ranges::size(__t));
120 else
121 return static_cast<_Signed>(ranges::size(__t));
122 }
123 };
119struct __fn {
120 template<class _Tp>
121 requires requires (_Tp&& __t) { ranges::size(__t); }
122 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr integral auto operator()(_Tp&& __t) const
123 noexcept(noexcept(ranges::size(__t))) {
124 using _Signed = make_signed_t<decltype(ranges::size(__t))>;
125 if constexpr (sizeof(ptrdiff_t) > sizeof(_Signed))
126 return static_cast<ptrdiff_t>(ranges::size(__t));
127 else
128 return static_cast<_Signed>(ranges::size(__t));
129 }
130};
124131} // namespace __ssize
125132
126133inline namespace __cpo {
......@@ -128,7 +135,7 @@ inline namespace __cpo {
128135} // namespace __cpo
129136} // namespace ranges
130137
131#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
138#endif // _LIBCPP_STD_VER > 17
132139
133140_LIBCPP_END_NAMESPACE_STD
134141
lib/libcxx/include/__ranges/subrange.h+20-17
......@@ -9,13 +9,13 @@
99#ifndef _LIBCPP___RANGES_SUBRANGE_H
1010#define _LIBCPP___RANGES_SUBRANGE_H
1111
12#include <__assert>
1213#include <__concepts/constructible.h>
1314#include <__concepts/convertible_to.h>
1415#include <__concepts/copyable.h>
1516#include <__concepts/derived_from.h>
1617#include <__concepts/different_from.h>
1718#include <__config>
18#include <__debug>
1919#include <__iterator/advance.h>
2020#include <__iterator/concepts.h>
2121#include <__iterator/incrementable_traits.h>
......@@ -31,12 +31,12 @@
3131#include <type_traits>
3232
3333#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
34#pragma GCC system_header
34# pragma GCC system_header
3535#endif
3636
3737_LIBCPP_BEGIN_NAMESPACE_STD
3838
39#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
39#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
4040
4141namespace ranges {
4242 template<class _From, class _To>
......@@ -56,8 +56,8 @@ namespace ranges {
5656 requires derived_from<tuple_size<_Tp>, integral_constant<size_t, 2>>;
5757 typename tuple_element_t<0, remove_const_t<_Tp>>;
5858 typename tuple_element_t<1, remove_const_t<_Tp>>;
59 { _VSTD::get<0>(__t) } -> convertible_to<const tuple_element_t<0, _Tp>&>;
60 { _VSTD::get<1>(__t) } -> convertible_to<const tuple_element_t<1, _Tp>&>;
59 { std::get<0>(__t) } -> convertible_to<const tuple_element_t<0, _Tp>&>;
60 { std::get<1>(__t) } -> convertible_to<const tuple_element_t<1, _Tp>&>;
6161 };
6262
6363 template<class _Pair, class _Iter, class _Sent>
......@@ -77,14 +77,17 @@ namespace ranges {
7777 class _LIBCPP_TEMPLATE_VIS subrange
7878 : public view_interface<subrange<_Iter, _Sent, _Kind>>
7979 {
80 private:
80 public:
81 // Note: this is an internal implementation detail that is public only for internal usage.
8182 static constexpr bool _StoreSize = (_Kind == subrange_kind::sized && !sized_sentinel_for<_Sent, _Iter>);
83
84 private:
8285 static constexpr bool _MustProvideSizeAtConstruction = !_StoreSize; // just to improve compiler diagnostics
8386 struct _Empty { constexpr _Empty(auto) noexcept { } };
8487 using _Size = conditional_t<_StoreSize, make_unsigned_t<iter_difference_t<_Iter>>, _Empty>;
85 [[no_unique_address]] _Iter __begin_ = _Iter();
86 [[no_unique_address]] _Sent __end_ = _Sent();
87 [[no_unique_address]] _Size __size_ = 0;
88 _LIBCPP_NO_UNIQUE_ADDRESS _Iter __begin_ = _Iter();
89 _LIBCPP_NO_UNIQUE_ADDRESS _Sent __end_ = _Sent();
90 _LIBCPP_NO_UNIQUE_ADDRESS _Size __size_ = 0;
8891
8992 public:
9093 _LIBCPP_HIDE_FROM_ABI
......@@ -93,14 +96,14 @@ namespace ranges {
9396 _LIBCPP_HIDE_FROM_ABI
9497 constexpr subrange(__convertible_to_non_slicing<_Iter> auto __iter, _Sent __sent)
9598 requires _MustProvideSizeAtConstruction
96 : __begin_(_VSTD::move(__iter)), __end_(_VSTD::move(__sent))
99 : __begin_(std::move(__iter)), __end_(std::move(__sent))
97100 { }
98101
99102 _LIBCPP_HIDE_FROM_ABI
100103 constexpr subrange(__convertible_to_non_slicing<_Iter> auto __iter, _Sent __sent,
101104 make_unsigned_t<iter_difference_t<_Iter>> __n)
102105 requires (_Kind == subrange_kind::sized)
103 : __begin_(_VSTD::move(__iter)), __end_(_VSTD::move(__sent)), __size_(__n)
106 : __begin_(std::move(__iter)), __end_(std::move(__sent)), __size_(__n)
104107 {
105108 if constexpr (sized_sentinel_for<_Sent, _Iter>)
106109 _LIBCPP_ASSERT((__end_ - __begin_) == static_cast<iter_difference_t<_Iter>>(__n),
......@@ -149,7 +152,7 @@ namespace ranges {
149152 }
150153
151154 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Iter begin() requires (!copyable<_Iter>) {
152 return _VSTD::move(__begin_);
155 return std::move(__begin_);
153156 }
154157
155158 _LIBCPP_HIDE_FROM_ABI
......@@ -168,7 +171,7 @@ namespace ranges {
168171 if constexpr (_StoreSize)
169172 return __size_;
170173 else
171 return _VSTD::__to_unsigned_like(__end_ - __begin_);
174 return std::__to_unsigned_like(__end_ - __begin_);
172175 }
173176
174177 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr subrange next(iter_difference_t<_Iter> __n = 1) const&
......@@ -181,7 +184,7 @@ namespace ranges {
181184
182185 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr subrange next(iter_difference_t<_Iter> __n = 1) && {
183186 advance(__n);
184 return _VSTD::move(*this);
187 return std::move(*this);
185188 }
186189
187190 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr subrange prev(iter_difference_t<_Iter> __n = 1) const
......@@ -198,14 +201,14 @@ namespace ranges {
198201 if (__n < 0) {
199202 ranges::advance(__begin_, __n);
200203 if constexpr (_StoreSize)
201 __size_ += _VSTD::__to_unsigned_like(-__n);
204 __size_ += std::__to_unsigned_like(-__n);
202205 return *this;
203206 }
204207 }
205208
206209 auto __d = __n - ranges::advance(__begin_, __n, __end_);
207210 if constexpr (_StoreSize)
208 __size_ -= _VSTD::__to_unsigned_like(__d);
211 __size_ -= std::__to_unsigned_like(__d);
209212 return *this;
210213 }
211214 };
......@@ -282,7 +285,7 @@ struct tuple_element<1, const ranges::subrange<_Ip, _Sp, _Kp>> {
282285 using type = _Sp;
283286};
284287
285#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
288#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
286289
287290_LIBCPP_END_NAMESPACE_STD
288291
lib/libcxx/include/__ranges/take_view.h+274-122
......@@ -10,23 +10,34 @@
1010#define _LIBCPP___RANGES_TAKE_VIEW_H
1111
1212#include <__algorithm/min.h>
13#include <__algorithm/ranges_min.h>
1314#include <__config>
15#include <__functional/bind_back.h>
16#include <__fwd/span.h>
17#include <__fwd/string_view.h>
1418#include <__iterator/concepts.h>
1519#include <__iterator/counted_iterator.h>
1620#include <__iterator/default_sentinel.h>
21#include <__iterator/distance.h>
1722#include <__iterator/iterator_traits.h>
1823#include <__ranges/access.h>
1924#include <__ranges/all.h>
2025#include <__ranges/concepts.h>
26#include <__ranges/empty_view.h>
2127#include <__ranges/enable_borrowed_range.h>
28#include <__ranges/iota_view.h>
29#include <__ranges/range_adaptor.h>
2230#include <__ranges/size.h>
31#include <__ranges/subrange.h>
2332#include <__ranges/view_interface.h>
33#include <__utility/auto_cast.h>
34#include <__utility/forward.h>
2435#include <__utility/move.h>
2536#include <concepts>
2637#include <type_traits>
2738
2839#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
29#pragma GCC system_header
40# pragma GCC system_header
3041#endif
3142
3243_LIBCPP_PUSH_MACROS
......@@ -34,149 +45,290 @@ _LIBCPP_PUSH_MACROS
3445
3546_LIBCPP_BEGIN_NAMESPACE_STD
3647
37#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
48#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
3849
3950namespace ranges {
40 template<view _View>
41 class take_view : public view_interface<take_view<_View>> {
42 [[no_unique_address]] _View __base_ = _View();
43 range_difference_t<_View> __count_ = 0;
44
45 template<bool> class __sentinel;
46
47 public:
48 _LIBCPP_HIDE_FROM_ABI
49 take_view() requires default_initializable<_View> = default;
50
51 _LIBCPP_HIDE_FROM_ABI
52 constexpr take_view(_View __base, range_difference_t<_View> __count)
53 : __base_(_VSTD::move(__base)), __count_(__count) {}
54
55 _LIBCPP_HIDE_FROM_ABI
56 constexpr _View base() const& requires copy_constructible<_View> { return __base_; }
57
58 _LIBCPP_HIDE_FROM_ABI
59 constexpr _View base() && { return _VSTD::move(__base_); }
60
61 _LIBCPP_HIDE_FROM_ABI
62 constexpr auto begin() requires (!__simple_view<_View>) {
63 if constexpr (sized_range<_View>) {
64 if constexpr (random_access_range<_View>) {
65 return ranges::begin(__base_);
66 } else {
67 using _DifferenceT = range_difference_t<_View>;
68 auto __size = size();
69 return counted_iterator(ranges::begin(__base_), static_cast<_DifferenceT>(__size));
70 }
51
52template<view _View>
53class take_view : public view_interface<take_view<_View>> {
54 _LIBCPP_NO_UNIQUE_ADDRESS _View __base_ = _View();
55 range_difference_t<_View> __count_ = 0;
56
57 template<bool> class __sentinel;
58
59public:
60 _LIBCPP_HIDE_FROM_ABI
61 take_view() requires default_initializable<_View> = default;
62
63 _LIBCPP_HIDE_FROM_ABI
64 constexpr take_view(_View __base, range_difference_t<_View> __count)
65 : __base_(std::move(__base)), __count_(__count) {}
66
67 _LIBCPP_HIDE_FROM_ABI
68 constexpr _View base() const& requires copy_constructible<_View> { return __base_; }
69
70 _LIBCPP_HIDE_FROM_ABI
71 constexpr _View base() && { return std::move(__base_); }
72
73 _LIBCPP_HIDE_FROM_ABI
74 constexpr auto begin() requires (!__simple_view<_View>) {
75 if constexpr (sized_range<_View>) {
76 if constexpr (random_access_range<_View>) {
77 return ranges::begin(__base_);
7178 } else {
72 return counted_iterator(ranges::begin(__base_), __count_);
79 using _DifferenceT = range_difference_t<_View>;
80 auto __size = size();
81 return counted_iterator(ranges::begin(__base_), static_cast<_DifferenceT>(__size));
7382 }
83 } else {
84 return counted_iterator(ranges::begin(__base_), __count_);
7485 }
86 }
7587
76 _LIBCPP_HIDE_FROM_ABI
77 constexpr auto begin() const requires range<const _View> {
78 if constexpr (sized_range<const _View>) {
79 if constexpr (random_access_range<const _View>) {
80 return ranges::begin(__base_);
81 } else {
82 using _DifferenceT = range_difference_t<const _View>;
83 auto __size = size();
84 return counted_iterator(ranges::begin(__base_), static_cast<_DifferenceT>(__size));
85 }
88 _LIBCPP_HIDE_FROM_ABI
89 constexpr auto begin() const requires range<const _View> {
90 if constexpr (sized_range<const _View>) {
91 if constexpr (random_access_range<const _View>) {
92 return ranges::begin(__base_);
8693 } else {
87 return counted_iterator(ranges::begin(__base_), __count_);
94 using _DifferenceT = range_difference_t<const _View>;
95 auto __size = size();
96 return counted_iterator(ranges::begin(__base_), static_cast<_DifferenceT>(__size));
8897 }
98 } else {
99 return counted_iterator(ranges::begin(__base_), __count_);
89100 }
101 }
90102
91 _LIBCPP_HIDE_FROM_ABI
92 constexpr auto end() requires (!__simple_view<_View>) {
93 if constexpr (sized_range<_View>) {
94 if constexpr (random_access_range<_View>) {
95 return ranges::begin(__base_) + size();
96 } else {
97 return default_sentinel;
98 }
103 _LIBCPP_HIDE_FROM_ABI
104 constexpr auto end() requires (!__simple_view<_View>) {
105 if constexpr (sized_range<_View>) {
106 if constexpr (random_access_range<_View>) {
107 return ranges::begin(__base_) + size();
99108 } else {
100 return __sentinel<false>{ranges::end(__base_)};
109 return default_sentinel;
101110 }
111 } else {
112 return __sentinel<false>{ranges::end(__base_)};
102113 }
114 }
103115
104 _LIBCPP_HIDE_FROM_ABI
105 constexpr auto end() const requires range<const _View> {
106 if constexpr (sized_range<const _View>) {
107 if constexpr (random_access_range<const _View>) {
108 return ranges::begin(__base_) + size();
109 } else {
110 return default_sentinel;
111 }
116 _LIBCPP_HIDE_FROM_ABI
117 constexpr auto end() const requires range<const _View> {
118 if constexpr (sized_range<const _View>) {
119 if constexpr (random_access_range<const _View>) {
120 return ranges::begin(__base_) + size();
112121 } else {
113 return __sentinel<true>{ranges::end(__base_)};
122 return default_sentinel;
114123 }
124 } else {
125 return __sentinel<true>{ranges::end(__base_)};
115126 }
116
117
118 _LIBCPP_HIDE_FROM_ABI
119 constexpr auto size() requires sized_range<_View> {
120 auto __n = ranges::size(__base_);
121 // TODO: use ranges::min here.
122 return _VSTD::min(__n, static_cast<decltype(__n)>(__count_));
123 }
124
125 _LIBCPP_HIDE_FROM_ABI
126 constexpr auto size() const requires sized_range<const _View> {
127 auto __n = ranges::size(__base_);
128 // TODO: use ranges::min here.
129 return _VSTD::min(__n, static_cast<decltype(__n)>(__count_));
130 }
131 };
132
133 template<view _View>
134 template<bool _Const>
135 class take_view<_View>::__sentinel {
136 using _Base = __maybe_const<_Const, _View>;
137 template<bool _OtherConst>
138 using _Iter = counted_iterator<iterator_t<__maybe_const<_OtherConst, _View>>>;
139 [[no_unique_address]] sentinel_t<_Base> __end_ = sentinel_t<_Base>();
140
141 template<bool>
142 friend class take_view<_View>::__sentinel;
127 }
128
129 _LIBCPP_HIDE_FROM_ABI
130 constexpr auto size() requires sized_range<_View> {
131 auto __n = ranges::size(__base_);
132 return ranges::min(__n, static_cast<decltype(__n)>(__count_));
133 }
134
135 _LIBCPP_HIDE_FROM_ABI
136 constexpr auto size() const requires sized_range<const _View> {
137 auto __n = ranges::size(__base_);
138 return ranges::min(__n, static_cast<decltype(__n)>(__count_));
139 }
140};
141
142template<view _View>
143template<bool _Const>
144class take_view<_View>::__sentinel {
145 using _Base = __maybe_const<_Const, _View>;
146 template<bool _OtherConst>
147 using _Iter = counted_iterator<iterator_t<__maybe_const<_OtherConst, _View>>>;
148 _LIBCPP_NO_UNIQUE_ADDRESS sentinel_t<_Base> __end_ = sentinel_t<_Base>();
149
150 template<bool>
151 friend class take_view<_View>::__sentinel;
143152
144153public:
145 _LIBCPP_HIDE_FROM_ABI
146 __sentinel() = default;
147
148 _LIBCPP_HIDE_FROM_ABI
149 constexpr explicit __sentinel(sentinel_t<_Base> __end) : __end_(_VSTD::move(__end)) {}
150
151 _LIBCPP_HIDE_FROM_ABI
152 constexpr __sentinel(__sentinel<!_Const> __s)
153 requires _Const && convertible_to<sentinel_t<_View>, sentinel_t<_Base>>
154 : __end_(_VSTD::move(__s.__end_)) {}
155
156 _LIBCPP_HIDE_FROM_ABI
157 constexpr sentinel_t<_Base> base() const { return __end_; }
158
159 _LIBCPP_HIDE_FROM_ABI
160 friend constexpr bool operator==(const _Iter<_Const>& __lhs, const __sentinel& __rhs) {
161 return __lhs.count() == 0 || __lhs.base() == __rhs.__end_;
162 }
163
164 template<bool _OtherConst = !_Const>
165 requires sentinel_for<sentinel_t<_Base>, iterator_t<__maybe_const<_OtherConst, _View>>>
166 _LIBCPP_HIDE_FROM_ABI
167 friend constexpr bool operator==(const _Iter<_Const>& __lhs, const __sentinel& __rhs) {
168 return __lhs.count() == 0 || __lhs.base() == __rhs.__end_;
169 }
170 };
171
172 template<class _Range>
173 take_view(_Range&&, range_difference_t<_Range>) -> take_view<views::all_t<_Range>>;
154 _LIBCPP_HIDE_FROM_ABI
155 __sentinel() = default;
156
157 _LIBCPP_HIDE_FROM_ABI
158 constexpr explicit __sentinel(sentinel_t<_Base> __end) : __end_(std::move(__end)) {}
159
160 _LIBCPP_HIDE_FROM_ABI
161 constexpr __sentinel(__sentinel<!_Const> __s)
162 requires _Const && convertible_to<sentinel_t<_View>, sentinel_t<_Base>>
163 : __end_(std::move(__s.__end_)) {}
164
165 _LIBCPP_HIDE_FROM_ABI
166 constexpr sentinel_t<_Base> base() const { return __end_; }
167
168 _LIBCPP_HIDE_FROM_ABI
169 friend constexpr bool operator==(const _Iter<_Const>& __lhs, const __sentinel& __rhs) {
170 return __lhs.count() == 0 || __lhs.base() == __rhs.__end_;
171 }
172
173 template<bool _OtherConst = !_Const>
174 requires sentinel_for<sentinel_t<_Base>, iterator_t<__maybe_const<_OtherConst, _View>>>
175 _LIBCPP_HIDE_FROM_ABI
176 friend constexpr bool operator==(const _Iter<_Const>& __lhs, const __sentinel& __rhs) {
177 return __lhs.count() == 0 || __lhs.base() == __rhs.__end_;
178 }
179};
180
181template<class _Range>
182take_view(_Range&&, range_difference_t<_Range>) -> take_view<views::all_t<_Range>>;
183
184template<class _Tp>
185inline constexpr bool enable_borrowed_range<take_view<_Tp>> = enable_borrowed_range<_Tp>;
186
187namespace views {
188namespace __take {
189
190template <class _Tp>
191inline constexpr bool __is_empty_view = false;
192
193template <class _Tp>
194inline constexpr bool __is_empty_view<empty_view<_Tp>> = true;
195
196template <class _Tp>
197inline constexpr bool __is_passthrough_specialization = false;
198
199template <class _Tp, size_t _Extent>
200inline constexpr bool __is_passthrough_specialization<span<_Tp, _Extent>> = true;
201
202template <class _CharT, class _Traits>
203inline constexpr bool __is_passthrough_specialization<basic_string_view<_CharT, _Traits>> = true;
204
205template <class _Iter, class _Sent, subrange_kind _Kind>
206inline constexpr bool __is_passthrough_specialization<subrange<_Iter, _Sent, _Kind>> = true;
207
208template <class _Tp>
209inline constexpr bool __is_iota_specialization = false;
210
211template <class _Np, class _Bound>
212inline constexpr bool __is_iota_specialization<iota_view<_Np, _Bound>> = true;
213
214template <class _Tp>
215struct __passthrough_type;
216
217template <class _Tp, size_t _Extent>
218struct __passthrough_type<span<_Tp, _Extent>> {
219 using type = span<_Tp>;
220};
221
222template <class _CharT, class _Traits>
223struct __passthrough_type<basic_string_view<_CharT, _Traits>> {
224 using type = basic_string_view<_CharT, _Traits>;
225};
226
227template <class _Iter, class _Sent, subrange_kind _Kind>
228struct __passthrough_type<subrange<_Iter, _Sent, _Kind>> {
229 using type = subrange<_Iter>;
230};
231
232template <class _Tp>
233using __passthrough_type_t = typename __passthrough_type<_Tp>::type;
234
235struct __fn {
236 // [range.take.overview]: the `empty_view` case.
237 template <class _Range, convertible_to<range_difference_t<_Range>> _Np>
238 requires __is_empty_view<remove_cvref_t<_Range>>
239 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
240 constexpr auto operator()(_Range&& __range, _Np&&) const
241 noexcept(noexcept(_LIBCPP_AUTO_CAST(std::forward<_Range>(__range))))
242 -> decltype( _LIBCPP_AUTO_CAST(std::forward<_Range>(__range)))
243 { return _LIBCPP_AUTO_CAST(std::forward<_Range>(__range)); }
244
245 // [range.take.overview]: the `span | basic_string_view | subrange` case.
246 template <class _Range,
247 convertible_to<range_difference_t<_Range>> _Np,
248 class _RawRange = remove_cvref_t<_Range>,
249 class _Dist = range_difference_t<_Range>>
250 requires (!__is_empty_view<_RawRange> &&
251 random_access_range<_RawRange> &&
252 sized_range<_RawRange> &&
253 __is_passthrough_specialization<_RawRange>)
254 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
255 constexpr auto operator()(_Range&& __rng, _Np&& __n) const
256 noexcept(noexcept(__passthrough_type_t<_RawRange>(
257 ranges::begin(__rng),
258 ranges::begin(__rng) + std::min<_Dist>(ranges::distance(__rng), std::forward<_Np>(__n))
259 )))
260 -> decltype( __passthrough_type_t<_RawRange>(
261 // Note: deliberately not forwarding `__rng` to guard against double moves.
262 ranges::begin(__rng),
263 ranges::begin(__rng) + std::min<_Dist>(ranges::distance(__rng), std::forward<_Np>(__n))
264 ))
265 { return __passthrough_type_t<_RawRange>(
266 ranges::begin(__rng),
267 ranges::begin(__rng) + std::min<_Dist>(ranges::distance(__rng), std::forward<_Np>(__n))
268 ); }
269
270 // [range.take.overview]: the `iota_view` case.
271 template <class _Range,
272 convertible_to<range_difference_t<_Range>> _Np,
273 class _RawRange = remove_cvref_t<_Range>,
274 class _Dist = range_difference_t<_Range>>
275 requires (!__is_empty_view<_RawRange> &&
276 random_access_range<_RawRange> &&
277 sized_range<_RawRange> &&
278 __is_iota_specialization<_RawRange>)
279 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
280 constexpr auto operator()(_Range&& __rng, _Np&& __n) const
281 noexcept(noexcept(ranges::iota_view(
282 *ranges::begin(__rng),
283 *ranges::begin(__rng) + std::min<_Dist>(ranges::distance(__rng), std::forward<_Np>(__n))
284 )))
285 -> decltype( ranges::iota_view(
286 // Note: deliberately not forwarding `__rng` to guard against double moves.
287 *ranges::begin(__rng),
288 *ranges::begin(__rng) + std::min<_Dist>(ranges::distance(__rng), std::forward<_Np>(__n))
289 ))
290 { return ranges::iota_view(
291 *ranges::begin(__rng),
292 *ranges::begin(__rng) + std::min<_Dist>(ranges::distance(__rng), std::forward<_Np>(__n))
293 ); }
294
295 // [range.take.overview]: the "otherwise" case.
296 template <class _Range, convertible_to<range_difference_t<_Range>> _Np,
297 class _RawRange = remove_cvref_t<_Range>>
298 // Note: without specifically excluding the other cases, GCC sees this overload as ambiguous with the other
299 // overloads.
300 requires (!(__is_empty_view<_RawRange> ||
301 (__is_iota_specialization<_RawRange> &&
302 sized_range<_RawRange> &&
303 random_access_range<_RawRange>) ||
304 (__is_passthrough_specialization<_RawRange> &&
305 sized_range<_RawRange> &&
306 random_access_range<_RawRange>)
307 ))
308 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
309 constexpr auto operator()(_Range&& __range, _Np&& __n) const
310 noexcept(noexcept(take_view(std::forward<_Range>(__range), std::forward<_Np>(__n))))
311 -> decltype( take_view(std::forward<_Range>(__range), std::forward<_Np>(__n)))
312 { return take_view(std::forward<_Range>(__range), std::forward<_Np>(__n)); }
313
314 template <class _Np>
315 requires constructible_from<decay_t<_Np>, _Np>
316 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
317 constexpr auto operator()(_Np&& __n) const
318 noexcept(is_nothrow_constructible_v<decay_t<_Np>, _Np>)
319 { return __range_adaptor_closure_t(std::__bind_back(*this, std::forward<_Np>(__n))); }
320};
321
322} // namespace __take
323
324inline namespace __cpo {
325 inline constexpr auto take = __take::__fn{};
326} // namespace __cpo
327} // namespace views
174328
175 template<class _Tp>
176 inline constexpr bool enable_borrowed_range<take_view<_Tp>> = enable_borrowed_range<_Tp>;
177329} // namespace ranges
178330
179#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
331#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
180332
181333_LIBCPP_END_NAMESPACE_STD
182334
lib/libcxx/include/__ranges/transform_view.h+21-21
......@@ -36,12 +36,12 @@
3636#include <type_traits>
3737
3838#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
39#pragma GCC system_header
39# pragma GCC system_header
4040#endif
4141
4242_LIBCPP_BEGIN_NAMESPACE_STD
4343
44#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
44#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
4545
4646namespace ranges {
4747
......@@ -53,7 +53,7 @@ template<class _View, class _Fn>
5353concept __transform_view_constraints =
5454 view<_View> && is_object_v<_Fn> &&
5555 regular_invocable<_Fn&, range_reference_t<_View>> &&
56 __referenceable<invoke_result_t<_Fn&, range_reference_t<_View>>>;
56 __can_reference<invoke_result_t<_Fn&, range_reference_t<_View>>>;
5757
5858template<input_range _View, copy_constructible _Fn>
5959 requires __transform_view_constraints<_View, _Fn>
......@@ -61,8 +61,8 @@ class transform_view : public view_interface<transform_view<_View, _Fn>> {
6161 template<bool> class __iterator;
6262 template<bool> class __sentinel;
6363
64 [[no_unique_address]] __copyable_box<_Fn> __func_;
65 [[no_unique_address]] _View __base_ = _View();
64 _LIBCPP_NO_UNIQUE_ADDRESS __copyable_box<_Fn> __func_;
65 _LIBCPP_NO_UNIQUE_ADDRESS _View __base_ = _View();
6666
6767public:
6868 _LIBCPP_HIDE_FROM_ABI
......@@ -71,12 +71,12 @@ public:
7171
7272 _LIBCPP_HIDE_FROM_ABI
7373 constexpr transform_view(_View __base, _Fn __func)
74 : __func_(_VSTD::in_place, _VSTD::move(__func)), __base_(_VSTD::move(__base)) {}
74 : __func_(std::in_place, std::move(__func)), __base_(std::move(__base)) {}
7575
7676 _LIBCPP_HIDE_FROM_ABI
7777 constexpr _View base() const& requires copy_constructible<_View> { return __base_; }
7878 _LIBCPP_HIDE_FROM_ABI
79 constexpr _View base() && { return _VSTD::move(__base_); }
79 constexpr _View base() && { return std::move(__base_); }
8080
8181 _LIBCPP_HIDE_FROM_ABI
8282 constexpr __iterator<false> begin() {
......@@ -183,7 +183,7 @@ public:
183183
184184 _LIBCPP_HIDE_FROM_ABI
185185 constexpr __iterator(_Parent& __parent, iterator_t<_Base> __current)
186 : __parent_(_VSTD::addressof(__parent)), __current_(_VSTD::move(__current)) {}
186 : __parent_(std::addressof(__parent)), __current_(std::move(__current)) {}
187187
188188 // Note: `__i` should always be `__iterator<false>`, but directly using
189189 // `__iterator<false>` is ill-formed when `_Const` is false
......@@ -191,7 +191,7 @@ public:
191191 _LIBCPP_HIDE_FROM_ABI
192192 constexpr __iterator(__iterator<!_Const> __i)
193193 requires _Const && convertible_to<iterator_t<_View>, iterator_t<_Base>>
194 : __parent_(__i.__parent_), __current_(_VSTD::move(__i.__current_)) {}
194 : __parent_(__i.__parent_), __current_(std::move(__i.__current_)) {}
195195
196196 _LIBCPP_HIDE_FROM_ABI
197197 constexpr const iterator_t<_Base>& base() const& noexcept {
......@@ -200,14 +200,14 @@ public:
200200
201201 _LIBCPP_HIDE_FROM_ABI
202202 constexpr iterator_t<_Base> base() && {
203 return _VSTD::move(__current_);
203 return std::move(__current_);
204204 }
205205
206206 _LIBCPP_HIDE_FROM_ABI
207207 constexpr decltype(auto) operator*() const
208 noexcept(noexcept(_VSTD::invoke(*__parent_->__func_, *__current_)))
208 noexcept(noexcept(std::invoke(*__parent_->__func_, *__current_)))
209209 {
210 return _VSTD::invoke(*__parent_->__func_, *__current_);
210 return std::invoke(*__parent_->__func_, *__current_);
211211 }
212212
213213 _LIBCPP_HIDE_FROM_ABI
......@@ -263,10 +263,10 @@ public:
263263
264264 _LIBCPP_HIDE_FROM_ABI
265265 constexpr decltype(auto) operator[](difference_type __n) const
266 noexcept(noexcept(_VSTD::invoke(*__parent_->__func_, __current_[__n])))
266 noexcept(noexcept(std::invoke(*__parent_->__func_, __current_[__n])))
267267 requires random_access_range<_Base>
268268 {
269 return _VSTD::invoke(*__parent_->__func_, __current_[__n]);
269 return std::invoke(*__parent_->__func_, __current_[__n]);
270270 }
271271
272272 _LIBCPP_HIDE_FROM_ABI
......@@ -344,7 +344,7 @@ public:
344344 noexcept(noexcept(*__i))
345345 {
346346 if constexpr (is_lvalue_reference_v<decltype(*__i)>)
347 return _VSTD::move(*__i);
347 return std::move(*__i);
348348 else
349349 return *__i;
350350 }
......@@ -378,7 +378,7 @@ public:
378378 _LIBCPP_HIDE_FROM_ABI
379379 constexpr __sentinel(__sentinel<!_Const> __i)
380380 requires _Const && convertible_to<sentinel_t<_View>, sentinel_t<_Base>>
381 : __end_(_VSTD::move(__i.__end_)) {}
381 : __end_(std::move(__i.__end_)) {}
382382
383383 _LIBCPP_HIDE_FROM_ABI
384384 constexpr sentinel_t<_Base> base() const { return __end_; }
......@@ -413,16 +413,16 @@ namespace __transform {
413413 template<class _Range, class _Fn>
414414 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
415415 constexpr auto operator()(_Range&& __range, _Fn&& __f) const
416 noexcept(noexcept(transform_view(_VSTD::forward<_Range>(__range), _VSTD::forward<_Fn>(__f))))
417 -> decltype( transform_view(_VSTD::forward<_Range>(__range), _VSTD::forward<_Fn>(__f)))
418 { return transform_view(_VSTD::forward<_Range>(__range), _VSTD::forward<_Fn>(__f)); }
416 noexcept(noexcept(transform_view(std::forward<_Range>(__range), std::forward<_Fn>(__f))))
417 -> decltype( transform_view(std::forward<_Range>(__range), std::forward<_Fn>(__f)))
418 { return transform_view(std::forward<_Range>(__range), std::forward<_Fn>(__f)); }
419419
420420 template<class _Fn>
421421 requires constructible_from<decay_t<_Fn>, _Fn>
422422 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
423423 constexpr auto operator()(_Fn&& __f) const
424424 noexcept(is_nothrow_constructible_v<decay_t<_Fn>, _Fn>)
425 { return __range_adaptor_closure_t(_VSTD::__bind_back(*this, _VSTD::forward<_Fn>(__f))); }
425 { return __range_adaptor_closure_t(std::__bind_back(*this, std::forward<_Fn>(__f))); }
426426 };
427427} // namespace __transform
428428
......@@ -433,7 +433,7 @@ inline namespace __cpo {
433433
434434} // namespace ranges
435435
436#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
436#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
437437
438438_LIBCPP_END_NAMESPACE_STD
439439
lib/libcxx/include/__ranges/view_interface.h+12-33
......@@ -9,8 +9,10 @@
99#ifndef _LIBCPP___RANGES_VIEW_INTERFACE_H
1010#define _LIBCPP___RANGES_VIEW_INTERFACE_H
1111
12#include <__assert>
13#include <__concepts/derived_from.h>
14#include <__concepts/same_as.h>
1215#include <__config>
13#include <__debug>
1416#include <__iterator/concepts.h>
1517#include <__iterator/iterator_traits.h>
1618#include <__iterator/prev.h>
......@@ -18,25 +20,18 @@
1820#include <__ranges/access.h>
1921#include <__ranges/concepts.h>
2022#include <__ranges/empty.h>
21#include <concepts>
2223#include <type_traits>
2324
2425#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
25#pragma GCC system_header
26# pragma GCC system_header
2627#endif
2728
2829_LIBCPP_BEGIN_NAMESPACE_STD
2930
30#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
31#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
3132
3233namespace ranges {
3334
34template<class _Tp>
35concept __can_empty = requires(_Tp __t) { ranges::empty(__t); };
36
37template<class _Tp>
38void __implicitly_convert_to(type_identity_t<_Tp>) noexcept;
39
4035template<class _Derived>
4136 requires is_class_v<_Derived> && same_as<_Derived, remove_cv_t<_Derived>>
4237class view_interface {
......@@ -55,7 +50,6 @@ class view_interface {
5550public:
5651 template<class _D2 = _Derived>
5752 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool empty()
58 noexcept(noexcept(__implicitly_convert_to<bool>(ranges::begin(__derived()) == ranges::end(__derived()))))
5953 requires forward_range<_D2>
6054 {
6155 return ranges::begin(__derived()) == ranges::end(__derived());
......@@ -63,7 +57,6 @@ public:
6357
6458 template<class _D2 = _Derived>
6559 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool empty() const
66 noexcept(noexcept(__implicitly_convert_to<bool>(ranges::begin(__derived()) == ranges::end(__derived()))))
6760 requires forward_range<const _D2>
6861 {
6962 return ranges::begin(__derived()) == ranges::end(__derived());
......@@ -72,8 +65,7 @@ public:
7265 template<class _D2 = _Derived>
7366 _LIBCPP_HIDE_FROM_ABI
7467 constexpr explicit operator bool()
75 noexcept(noexcept(ranges::empty(declval<_D2>())))
76 requires __can_empty<_D2>
68 requires requires (_D2& __t) { ranges::empty(__t); }
7769 {
7870 return !ranges::empty(__derived());
7971 }
......@@ -81,8 +73,7 @@ public:
8173 template<class _D2 = _Derived>
8274 _LIBCPP_HIDE_FROM_ABI
8375 constexpr explicit operator bool() const
84 noexcept(noexcept(ranges::empty(declval<const _D2>())))
85 requires __can_empty<const _D2>
76 requires requires (const _D2& __t) { ranges::empty(__t); }
8677 {
8778 return !ranges::empty(__derived());
8879 }
......@@ -90,27 +81,23 @@ public:
9081 template<class _D2 = _Derived>
9182 _LIBCPP_HIDE_FROM_ABI
9283 constexpr auto data()
93 noexcept(noexcept(_VSTD::to_address(ranges::begin(__derived()))))
9484 requires contiguous_iterator<iterator_t<_D2>>
9585 {
96 return _VSTD::to_address(ranges::begin(__derived()));
86 return std::to_address(ranges::begin(__derived()));
9787 }
9888
9989 template<class _D2 = _Derived>
10090 _LIBCPP_HIDE_FROM_ABI
10191 constexpr auto data() const
102 noexcept(noexcept(_VSTD::to_address(ranges::begin(__derived()))))
10392 requires range<const _D2> && contiguous_iterator<iterator_t<const _D2>>
10493 {
105 return _VSTD::to_address(ranges::begin(__derived()));
94 return std::to_address(ranges::begin(__derived()));
10695 }
10796
10897 template<class _D2 = _Derived>
10998 _LIBCPP_HIDE_FROM_ABI
11099 constexpr auto size()
111 noexcept(noexcept(ranges::end(__derived()) - ranges::begin(__derived())))
112 requires forward_range<_D2>
113 && sized_sentinel_for<sentinel_t<_D2>, iterator_t<_D2>>
100 requires forward_range<_D2> && sized_sentinel_for<sentinel_t<_D2>, iterator_t<_D2>>
114101 {
115102 return ranges::end(__derived()) - ranges::begin(__derived());
116103 }
......@@ -118,9 +105,7 @@ public:
118105 template<class _D2 = _Derived>
119106 _LIBCPP_HIDE_FROM_ABI
120107 constexpr auto size() const
121 noexcept(noexcept(ranges::end(__derived()) - ranges::begin(__derived())))
122 requires forward_range<const _D2>
123 && sized_sentinel_for<sentinel_t<const _D2>, iterator_t<const _D2>>
108 requires forward_range<const _D2> && sized_sentinel_for<sentinel_t<const _D2>, iterator_t<const _D2>>
124109 {
125110 return ranges::end(__derived()) - ranges::begin(__derived());
126111 }
......@@ -128,7 +113,6 @@ public:
128113 template<class _D2 = _Derived>
129114 _LIBCPP_HIDE_FROM_ABI
130115 constexpr decltype(auto) front()
131 noexcept(noexcept(*ranges::begin(__derived())))
132116 requires forward_range<_D2>
133117 {
134118 _LIBCPP_ASSERT(!empty(),
......@@ -139,7 +123,6 @@ public:
139123 template<class _D2 = _Derived>
140124 _LIBCPP_HIDE_FROM_ABI
141125 constexpr decltype(auto) front() const
142 noexcept(noexcept(*ranges::begin(__derived())))
143126 requires forward_range<const _D2>
144127 {
145128 _LIBCPP_ASSERT(!empty(),
......@@ -150,7 +133,6 @@ public:
150133 template<class _D2 = _Derived>
151134 _LIBCPP_HIDE_FROM_ABI
152135 constexpr decltype(auto) back()
153 noexcept(noexcept(*ranges::prev(ranges::end(__derived()))))
154136 requires bidirectional_range<_D2> && common_range<_D2>
155137 {
156138 _LIBCPP_ASSERT(!empty(),
......@@ -161,7 +143,6 @@ public:
161143 template<class _D2 = _Derived>
162144 _LIBCPP_HIDE_FROM_ABI
163145 constexpr decltype(auto) back() const
164 noexcept(noexcept(*ranges::prev(ranges::end(__derived()))))
165146 requires bidirectional_range<const _D2> && common_range<const _D2>
166147 {
167148 _LIBCPP_ASSERT(!empty(),
......@@ -172,7 +153,6 @@ public:
172153 template<random_access_range _RARange = _Derived>
173154 _LIBCPP_HIDE_FROM_ABI
174155 constexpr decltype(auto) operator[](range_difference_t<_RARange> __index)
175 noexcept(noexcept(ranges::begin(__derived())[__index]))
176156 {
177157 return ranges::begin(__derived())[__index];
178158 }
......@@ -180,7 +160,6 @@ public:
180160 template<random_access_range _RARange = const _Derived>
181161 _LIBCPP_HIDE_FROM_ABI
182162 constexpr decltype(auto) operator[](range_difference_t<_RARange> __index) const
183 noexcept(noexcept(ranges::begin(__derived())[__index]))
184163 {
185164 return ranges::begin(__derived())[__index];
186165 }
......@@ -188,7 +167,7 @@ public:
188167
189168} // namespace ranges
190169
191#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
170#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
192171
193172_LIBCPP_END_NAMESPACE_STD
194173
lib/libcxx/include/__ranges/zip_view.h created+511
......@@ -0,0 +1,511 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9#ifndef _LIBCPP___RANGES_ZIP_VIEW_H
10#define _LIBCPP___RANGES_ZIP_VIEW_H
11
12#include <__config>
13
14#include <__algorithm/ranges_min.h>
15#include <__compare/three_way_comparable.h>
16#include <__concepts/convertible_to.h>
17#include <__concepts/equality_comparable.h>
18#include <__functional/invoke.h>
19#include <__functional/operations.h>
20#include <__iterator/concepts.h>
21#include <__iterator/incrementable_traits.h>
22#include <__iterator/iter_move.h>
23#include <__iterator/iter_swap.h>
24#include <__iterator/iterator_traits.h>
25#include <__ranges/access.h>
26#include <__ranges/all.h>
27#include <__ranges/concepts.h>
28#include <__ranges/empty_view.h>
29#include <__ranges/enable_borrowed_range.h>
30#include <__ranges/size.h>
31#include <__ranges/view_interface.h>
32#include <__utility/forward.h>
33#include <__utility/integer_sequence.h>
34#include <__utility/move.h>
35#include <tuple>
36#include <type_traits>
37
38#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
39# pragma GCC system_header
40#endif
41
42_LIBCPP_PUSH_MACROS
43#include <__undef_macros>
44
45_LIBCPP_BEGIN_NAMESPACE_STD
46
47#if _LIBCPP_STD_VER > 20 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
48
49namespace ranges {
50
51template <class... _Ranges>
52concept __zip_is_common = (sizeof...(_Ranges) == 1 && (common_range<_Ranges> && ...)) ||
53 (!(bidirectional_range<_Ranges> && ...) && (common_range<_Ranges> && ...)) ||
54 ((random_access_range<_Ranges> && ...) && (sized_range<_Ranges> && ...));
55
56template <typename _Tp, typename _Up>
57auto __tuple_or_pair_test() -> pair<_Tp, _Up>;
58
59template <typename... _Types>
60 requires(sizeof...(_Types) != 2)
61auto __tuple_or_pair_test() -> tuple<_Types...>;
62
63template <class... _Types>
64using __tuple_or_pair = decltype(__tuple_or_pair_test<_Types...>());
65
66template <class _Fun, class _Tuple>
67_LIBCPP_HIDE_FROM_ABI constexpr auto __tuple_transform(_Fun&& __f, _Tuple&& __tuple) {
68 return std::apply(
69 [&]<class... _Types>(_Types&&... __elements) {
70 return __tuple_or_pair<invoke_result_t<_Fun&, _Types>...>(
71 std::invoke(__f, std::forward<_Types>(__elements))...);
72 },
73 std::forward<_Tuple>(__tuple));
74}
75
76template <class _Fun, class _Tuple>
77_LIBCPP_HIDE_FROM_ABI constexpr void __tuple_for_each(_Fun&& __f, _Tuple&& __tuple) {
78 std::apply(
79 [&]<class... _Types>(_Types&&... __elements) { (std::invoke(__f, std::forward<_Types>(__elements)), ...); },
80 std::forward<_Tuple>(__tuple));
81}
82
83template <class _Fun, class _Tuple1, class _Tuple2, size_t... _Indices>
84_LIBCPP_HIDE_FROM_ABI constexpr __tuple_or_pair<
85 invoke_result_t<_Fun&, typename tuple_element<_Indices, remove_cvref_t<_Tuple1>>::type,
86 typename tuple_element<_Indices, remove_cvref_t<_Tuple2>>::type>...>
87__tuple_zip_transform(_Fun&& __f, _Tuple1&& __tuple1, _Tuple2&& __tuple2, index_sequence<_Indices...>) {
88 return {std::invoke(__f, std::get<_Indices>(std::forward<_Tuple1>(__tuple1)),
89 std::get<_Indices>(std::forward<_Tuple2>(__tuple2)))...};
90}
91
92template <class _Fun, class _Tuple1, class _Tuple2>
93_LIBCPP_HIDE_FROM_ABI constexpr auto __tuple_zip_transform(_Fun&& __f, _Tuple1&& __tuple1, _Tuple2&& __tuple2) {
94 return ranges::__tuple_zip_transform(__f, std::forward<_Tuple1>(__tuple1), std::forward<_Tuple2>(__tuple2),
95 std::make_index_sequence<tuple_size<remove_cvref_t<_Tuple1>>::value>());
96}
97
98template <class _Fun, class _Tuple1, class _Tuple2, size_t... _Indices>
99_LIBCPP_HIDE_FROM_ABI constexpr void __tuple_zip_for_each(_Fun&& __f, _Tuple1&& __tuple1, _Tuple2&& __tuple2,
100 index_sequence<_Indices...>) {
101 (std::invoke(__f, std::get<_Indices>(std::forward<_Tuple1>(__tuple1)),
102 std::get<_Indices>(std::forward<_Tuple2>(__tuple2))),
103 ...);
104}
105
106template <class _Fun, class _Tuple1, class _Tuple2>
107_LIBCPP_HIDE_FROM_ABI constexpr auto __tuple_zip_for_each(_Fun&& __f, _Tuple1&& __tuple1, _Tuple2&& __tuple2) {
108 return ranges::__tuple_zip_for_each(__f, std::forward<_Tuple1>(__tuple1), std::forward<_Tuple2>(__tuple2),
109 std::make_index_sequence<tuple_size<remove_cvref_t<_Tuple1>>::value>());
110}
111
112template <class _Tuple1, class _Tuple2>
113_LIBCPP_HIDE_FROM_ABI constexpr bool __tuple_any_equals(const _Tuple1& __tuple1, const _Tuple2& __tuple2) {
114 const auto __equals = ranges::__tuple_zip_transform(std::equal_to<>(), __tuple1, __tuple2);
115 return std::apply([](auto... __bools) { return (__bools || ...); }, __equals);
116}
117
118// abs in cstdlib is not constexpr
119// TODO : remove __abs once P0533R9 is implemented.
120template <class _Tp>
121_LIBCPP_HIDE_FROM_ABI constexpr _Tp __abs(_Tp __t) {
122 return __t < 0 ? -__t : __t;
123}
124
125template <input_range... _Views>
126 requires(view<_Views> && ...) && (sizeof...(_Views) > 0)
127class zip_view : public view_interface<zip_view<_Views...>> {
128
129 _LIBCPP_NO_UNIQUE_ADDRESS tuple<_Views...> __views_;
130
131 template <bool>
132 class __iterator;
133
134 template <bool>
135 class __sentinel;
136
137public:
138 _LIBCPP_HIDE_FROM_ABI
139 zip_view() = default;
140
141 _LIBCPP_HIDE_FROM_ABI
142 constexpr explicit zip_view(_Views... __views) : __views_(std::move(__views)...) {}
143
144 _LIBCPP_HIDE_FROM_ABI
145 constexpr auto begin()
146 requires(!(__simple_view<_Views> && ...)) {
147 return __iterator<false>(ranges::__tuple_transform(ranges::begin, __views_));
148 }
149
150 _LIBCPP_HIDE_FROM_ABI
151 constexpr auto begin() const
152 requires(range<const _Views> && ...) {
153 return __iterator<true>(ranges::__tuple_transform(ranges::begin, __views_));
154 }
155
156 _LIBCPP_HIDE_FROM_ABI
157 constexpr auto end()
158 requires(!(__simple_view<_Views> && ...)) {
159 if constexpr (!__zip_is_common<_Views...>) {
160 return __sentinel<false>(ranges::__tuple_transform(ranges::end, __views_));
161 } else if constexpr ((random_access_range<_Views> && ...)) {
162 return begin() + iter_difference_t<__iterator<false>>(size());
163 } else {
164 return __iterator<false>(ranges::__tuple_transform(ranges::end, __views_));
165 }
166 }
167
168 _LIBCPP_HIDE_FROM_ABI
169 constexpr auto end() const
170 requires(range<const _Views> && ...) {
171 if constexpr (!__zip_is_common<const _Views...>) {
172 return __sentinel<true>(ranges::__tuple_transform(ranges::end, __views_));
173 } else if constexpr ((random_access_range<const _Views> && ...)) {
174 return begin() + iter_difference_t<__iterator<true>>(size());
175 } else {
176 return __iterator<true>(ranges::__tuple_transform(ranges::end, __views_));
177 }
178 }
179
180 _LIBCPP_HIDE_FROM_ABI
181 constexpr auto size()
182 requires(sized_range<_Views> && ...) {
183 return std::apply(
184 [](auto... __sizes) {
185 using _CT = make_unsigned_t<common_type_t<decltype(__sizes)...>>;
186 return ranges::min({_CT(__sizes)...});
187 },
188 ranges::__tuple_transform(ranges::size, __views_));
189 }
190
191 _LIBCPP_HIDE_FROM_ABI
192 constexpr auto size() const
193 requires(sized_range<const _Views> && ...) {
194 return std::apply(
195 [](auto... __sizes) {
196 using _CT = make_unsigned_t<common_type_t<decltype(__sizes)...>>;
197 return ranges::min({_CT(__sizes)...});
198 },
199 ranges::__tuple_transform(ranges::size, __views_));
200 }
201};
202
203template <class... _Ranges>
204zip_view(_Ranges&&...) -> zip_view<views::all_t<_Ranges>...>;
205
206template <bool _Const, class... _Views>
207concept __zip_all_random_access = (random_access_range<__maybe_const<_Const, _Views>> && ...);
208
209template <bool _Const, class... _Views>
210concept __zip_all_bidirectional = (bidirectional_range<__maybe_const<_Const, _Views>> && ...);
211
212template <bool _Const, class... _Views>
213concept __zip_all_forward = (forward_range<__maybe_const<_Const, _Views>> && ...);
214
215template <bool _Const, class... _Views>
216consteval auto __get_zip_view_iterator_tag() {
217 if constexpr (__zip_all_random_access<_Const, _Views...>) {
218 return random_access_iterator_tag();
219 } else if constexpr (__zip_all_bidirectional<_Const, _Views...>) {
220 return bidirectional_iterator_tag();
221 } else if constexpr (__zip_all_forward<_Const, _Views...>) {
222 return forward_iterator_tag();
223 } else {
224 return input_iterator_tag();
225 }
226}
227
228template <bool _Const, class... _Views>
229struct __zip_view_iterator_category_base {};
230
231template <bool _Const, class... _Views>
232 requires __zip_all_forward<_Const, _Views...>
233struct __zip_view_iterator_category_base<_Const, _Views...> {
234 using iterator_category = input_iterator_tag;
235};
236
237template <input_range... _Views>
238 requires(view<_Views> && ...) && (sizeof...(_Views) > 0)
239template <bool _Const>
240class zip_view<_Views...>::__iterator : public __zip_view_iterator_category_base<_Const, _Views...> {
241
242 __tuple_or_pair<iterator_t<__maybe_const<_Const, _Views>>...> __current_;
243
244 _LIBCPP_HIDE_FROM_ABI
245 constexpr explicit __iterator(__tuple_or_pair<iterator_t<__maybe_const<_Const, _Views>>...> __current)
246 : __current_(std::move(__current)) {}
247
248 template <bool>
249 friend class zip_view<_Views...>::__iterator;
250
251 template <bool>
252 friend class zip_view<_Views...>::__sentinel;
253
254 friend class zip_view<_Views...>;
255
256public:
257 using iterator_concept = decltype(__get_zip_view_iterator_tag<_Const, _Views...>());
258 using value_type = __tuple_or_pair<range_value_t<__maybe_const<_Const, _Views>>...>;
259 using difference_type = common_type_t<range_difference_t<__maybe_const<_Const, _Views>>...>;
260
261 _LIBCPP_HIDE_FROM_ABI
262 __iterator() = default;
263
264 _LIBCPP_HIDE_FROM_ABI
265 constexpr __iterator(__iterator<!_Const> __i)
266 requires _Const && (convertible_to<iterator_t<_Views>, iterator_t<__maybe_const<_Const, _Views>>> && ...)
267 : __current_(std::move(__i.__current_)) {}
268
269 _LIBCPP_HIDE_FROM_ABI
270 constexpr auto operator*() const {
271 return ranges::__tuple_transform([](auto& __i) -> decltype(auto) { return *__i; }, __current_);
272 }
273
274 _LIBCPP_HIDE_FROM_ABI
275 constexpr __iterator& operator++() {
276 ranges::__tuple_for_each([](auto& __i) { ++__i; }, __current_);
277 return *this;
278 }
279
280 _LIBCPP_HIDE_FROM_ABI
281 constexpr void operator++(int) { ++*this; }
282
283 _LIBCPP_HIDE_FROM_ABI
284 constexpr __iterator operator++(int)
285 requires __zip_all_forward<_Const, _Views...> {
286 auto __tmp = *this;
287 ++*this;
288 return __tmp;
289 }
290
291 _LIBCPP_HIDE_FROM_ABI
292 constexpr __iterator& operator--()
293 requires __zip_all_bidirectional<_Const, _Views...> {
294 ranges::__tuple_for_each([](auto& __i) { --__i; }, __current_);
295 return *this;
296 }
297
298 _LIBCPP_HIDE_FROM_ABI
299 constexpr __iterator operator--(int)
300 requires __zip_all_bidirectional<_Const, _Views...> {
301 auto __tmp = *this;
302 --*this;
303 return __tmp;
304 }
305
306 _LIBCPP_HIDE_FROM_ABI
307 constexpr __iterator& operator+=(difference_type __x)
308 requires __zip_all_random_access<_Const, _Views...> {
309 ranges::__tuple_for_each([&]<class _Iter>(_Iter& __i) { __i += iter_difference_t<_Iter>(__x); }, __current_);
310 return *this;
311 }
312
313 _LIBCPP_HIDE_FROM_ABI
314 constexpr __iterator& operator-=(difference_type __x)
315 requires __zip_all_random_access<_Const, _Views...> {
316 ranges::__tuple_for_each([&]<class _Iter>(_Iter& __i) { __i -= iter_difference_t<_Iter>(__x); }, __current_);
317 return *this;
318 }
319
320 _LIBCPP_HIDE_FROM_ABI
321 constexpr auto operator[](difference_type __n) const
322 requires __zip_all_random_access<_Const, _Views...> {
323 return ranges::__tuple_transform(
324 [&]<class _Iter>(_Iter& __i) -> decltype(auto) { return __i[iter_difference_t<_Iter>(__n)]; }, __current_);
325 }
326
327 _LIBCPP_HIDE_FROM_ABI
328 friend constexpr bool operator==(const __iterator& __x, const __iterator& __y)
329 requires(equality_comparable<iterator_t<__maybe_const<_Const, _Views>>> && ...) {
330 if constexpr (__zip_all_bidirectional<_Const, _Views...>) {
331 return __x.__current_ == __y.__current_;
332 } else {
333 return ranges::__tuple_any_equals(__x.__current_, __y.__current_);
334 }
335 }
336
337 _LIBCPP_HIDE_FROM_ABI
338 friend constexpr bool operator<(const __iterator& __x, const __iterator& __y)
339 requires __zip_all_random_access<_Const, _Views...> {
340 return __x.__current_ < __y.__current_;
341 }
342
343 _LIBCPP_HIDE_FROM_ABI
344 friend constexpr bool operator>(const __iterator& __x, const __iterator& __y)
345 requires __zip_all_random_access<_Const, _Views...> {
346 return __y < __x;
347 }
348
349 _LIBCPP_HIDE_FROM_ABI
350 friend constexpr bool operator<=(const __iterator& __x, const __iterator& __y)
351 requires __zip_all_random_access<_Const, _Views...> {
352 return !(__y < __x);
353 }
354
355 _LIBCPP_HIDE_FROM_ABI
356 friend constexpr bool operator>=(const __iterator& __x, const __iterator& __y)
357 requires __zip_all_random_access<_Const, _Views...> {
358 return !(__x < __y);
359 }
360
361 _LIBCPP_HIDE_FROM_ABI
362 friend constexpr auto operator<=>(const __iterator& __x, const __iterator& __y)
363 requires __zip_all_random_access<_Const, _Views...> &&
364 (three_way_comparable<iterator_t<__maybe_const<_Const, _Views>>> && ...) {
365 return __x.__current_ <=> __y.__current_;
366 }
367
368 _LIBCPP_HIDE_FROM_ABI
369 friend constexpr __iterator operator+(const __iterator& __i, difference_type __n)
370 requires __zip_all_random_access<_Const, _Views...> {
371 auto __r = __i;
372 __r += __n;
373 return __r;
374 }
375
376 _LIBCPP_HIDE_FROM_ABI
377 friend constexpr __iterator operator+(difference_type __n, const __iterator& __i)
378 requires __zip_all_random_access<_Const, _Views...> {
379 return __i + __n;
380 }
381
382 _LIBCPP_HIDE_FROM_ABI
383 friend constexpr __iterator operator-(const __iterator& __i, difference_type __n)
384 requires __zip_all_random_access<_Const, _Views...> {
385 auto __r = __i;
386 __r -= __n;
387 return __r;
388 }
389
390 _LIBCPP_HIDE_FROM_ABI
391 friend constexpr difference_type operator-(const __iterator& __x, const __iterator& __y)
392 requires(sized_sentinel_for<iterator_t<__maybe_const<_Const, _Views>>, iterator_t<__maybe_const<_Const, _Views>>> &&
393 ...) {
394 const auto __diffs = ranges::__tuple_zip_transform(minus<>(), __x.__current_, __y.__current_);
395 return std::apply(
396 [](auto... __ds) {
397 return ranges::min({difference_type(__ds)...},
398 [](auto __a, auto __b) { return ranges::__abs(__a) < ranges::__abs(__b); });
399 },
400 __diffs);
401 }
402
403 _LIBCPP_HIDE_FROM_ABI
404 friend constexpr auto iter_move(const __iterator& __i) noexcept(
405 (noexcept(ranges::iter_move(declval<const iterator_t<__maybe_const<_Const, _Views>>&>())) && ...) &&
406 (is_nothrow_move_constructible_v<range_rvalue_reference_t<__maybe_const<_Const, _Views>>> && ...)) {
407 return ranges::__tuple_transform(ranges::iter_move, __i.__current_);
408 }
409
410 _LIBCPP_HIDE_FROM_ABI
411 friend constexpr void iter_swap(const __iterator& __l, const __iterator& __r) noexcept(
412 (noexcept(ranges::iter_swap(declval<const iterator_t<__maybe_const<_Const, _Views>>&>(),
413 declval<const iterator_t<__maybe_const<_Const, _Views>>&>())) &&
414 ...))
415 requires(indirectly_swappable<iterator_t<__maybe_const<_Const, _Views>>> && ...) {
416 ranges::__tuple_zip_for_each(ranges::iter_swap, __l.__current_, __r.__current_);
417 }
418};
419
420template <input_range... _Views>
421 requires(view<_Views> && ...) && (sizeof...(_Views) > 0)
422template <bool _Const>
423class zip_view<_Views...>::__sentinel {
424
425 __tuple_or_pair<sentinel_t<__maybe_const<_Const, _Views>>...> __end_;
426
427 _LIBCPP_HIDE_FROM_ABI
428 constexpr explicit __sentinel(__tuple_or_pair<sentinel_t<__maybe_const<_Const, _Views>>...> __end) : __end_(__end) {}
429
430 friend class zip_view<_Views...>;
431
432 // hidden friend cannot access private member of iterator because they are friends of friends
433 template <bool _OtherConst>
434 _LIBCPP_HIDE_FROM_ABI static constexpr decltype(auto)
435 __iter_current(zip_view<_Views...>::__iterator<_OtherConst> const& __it) {
436 return (__it.__current_);
437 }
438
439public:
440 _LIBCPP_HIDE_FROM_ABI
441 __sentinel() = default;
442
443 _LIBCPP_HIDE_FROM_ABI
444 constexpr __sentinel(__sentinel<!_Const> __i)
445 requires _Const && (convertible_to<sentinel_t<_Views>, sentinel_t<__maybe_const<_Const, _Views>>> && ...)
446 : __end_(std::move(__i.__end_)) {}
447
448 template <bool _OtherConst>
449 requires(sentinel_for<sentinel_t<__maybe_const<_Const, _Views>>, iterator_t<__maybe_const<_OtherConst, _Views>>> &&
450 ...)
451 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const __iterator<_OtherConst>& __x, const __sentinel& __y) {
452 return ranges::__tuple_any_equals(__iter_current(__x), __y.__end_);
453 }
454
455 template <bool _OtherConst>
456 requires(
457 sized_sentinel_for<sentinel_t<__maybe_const<_Const, _Views>>, iterator_t<__maybe_const<_OtherConst, _Views>>> &&
458 ...)
459 _LIBCPP_HIDE_FROM_ABI friend constexpr common_type_t<range_difference_t<__maybe_const<_OtherConst, _Views>>...>
460 operator-(const __iterator<_OtherConst>& __x, const __sentinel& __y) {
461 const auto __diffs = ranges::__tuple_zip_transform(minus<>(), __iter_current(__x), __y.__end_);
462 return std::apply(
463 [](auto... __ds) {
464 using _Diff = common_type_t<range_difference_t<__maybe_const<_OtherConst, _Views>>...>;
465 return ranges::min({_Diff(__ds)...},
466 [](auto __a, auto __b) { return ranges::__abs(__a) < ranges::__abs(__b); });
467 },
468 __diffs);
469 }
470
471 template <bool _OtherConst>
472 requires(
473 sized_sentinel_for<sentinel_t<__maybe_const<_Const, _Views>>, iterator_t<__maybe_const<_OtherConst, _Views>>> &&
474 ...)
475 _LIBCPP_HIDE_FROM_ABI friend constexpr common_type_t<range_difference_t<__maybe_const<_OtherConst, _Views>>...>
476 operator-(const __sentinel& __y, const __iterator<_OtherConst>& __x) {
477 return -(__x - __y);
478 }
479};
480
481template <class... _Views>
482inline constexpr bool enable_borrowed_range<zip_view<_Views...>> = (enable_borrowed_range<_Views> && ...);
483
484namespace views {
485namespace __zip {
486
487struct __fn {
488 _LIBCPP_HIDE_FROM_ABI constexpr auto operator()() const noexcept { return empty_view<tuple<>>{}; }
489
490 template <class... _Ranges>
491 _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Ranges&&... __rs) const
492 noexcept(noexcept(zip_view<all_t<_Ranges&&>...>(std::forward<_Ranges>(__rs)...)))
493 -> decltype(zip_view<all_t<_Ranges&&>...>(std::forward<_Ranges>(__rs)...)) {
494 return zip_view<all_t<_Ranges>...>(std::forward<_Ranges>(__rs)...);
495 }
496};
497
498} // namespace __zip
499inline namespace __cpo {
500 inline constexpr auto zip = __zip::__fn{};
501} // namespace __cpo
502} // namespace views
503} // namespace ranges
504
505#endif // _LIBCPP_STD_VER > 20 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
506
507_LIBCPP_END_NAMESPACE_STD
508
509_LIBCPP_POP_MACROS
510
511#endif // _LIBCPP___RANGES_ZIP_VIEW_H
lib/libcxx/include/__split_buffer+112-83
......@@ -1,14 +1,31 @@
11// -*- C++ -*-
2#ifndef _LIBCPP_SPLIT_BUFFER
3#define _LIBCPP_SPLIT_BUFFER
4
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___SPLIT_BUFFER
11#define _LIBCPP___SPLIT_BUFFER
12
13#include <__algorithm/max.h>
14#include <__algorithm/move.h>
15#include <__algorithm/move_backward.h>
516#include <__config>
17#include <__iterator/distance.h>
18#include <__iterator/iterator_traits.h>
19#include <__iterator/move_iterator.h>
20#include <__memory/allocator.h>
21#include <__memory/compressed_pair.h>
22#include <__memory/swap_allocator.h>
623#include <__utility/forward.h>
7#include <algorithm>
24#include <memory>
825#include <type_traits>
926
1027#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
11#pragma GCC system_header
28# pragma GCC system_header
1229#endif
1330
1431_LIBCPP_PUSH_MACROS
......@@ -45,116 +62,107 @@ public:
4562 typedef typename add_lvalue_reference<allocator_type>::type __alloc_ref;
4663 typedef typename add_lvalue_reference<allocator_type>::type __alloc_const_ref;
4764
48 _LIBCPP_INLINE_VISIBILITY __alloc_rr& __alloc() _NOEXCEPT {return __end_cap_.second();}
49 _LIBCPP_INLINE_VISIBILITY const __alloc_rr& __alloc() const _NOEXCEPT {return __end_cap_.second();}
50 _LIBCPP_INLINE_VISIBILITY pointer& __end_cap() _NOEXCEPT {return __end_cap_.first();}
51 _LIBCPP_INLINE_VISIBILITY const pointer& __end_cap() const _NOEXCEPT {return __end_cap_.first();}
65 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY __alloc_rr& __alloc() _NOEXCEPT {return __end_cap_.second();}
66 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY const __alloc_rr& __alloc() const _NOEXCEPT {return __end_cap_.second();}
67 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY pointer& __end_cap() _NOEXCEPT {return __end_cap_.first();}
68 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY const pointer& __end_cap() const _NOEXCEPT {return __end_cap_.first();}
5269
53 _LIBCPP_INLINE_VISIBILITY
70 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
5471 __split_buffer()
5572 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
56 _LIBCPP_INLINE_VISIBILITY
73 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
5774 explicit __split_buffer(__alloc_rr& __a);
58 _LIBCPP_INLINE_VISIBILITY
75 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
5976 explicit __split_buffer(const __alloc_rr& __a);
60 __split_buffer(size_type __cap, size_type __start, __alloc_rr& __a);
61 ~__split_buffer();
77 _LIBCPP_CONSTEXPR_AFTER_CXX17 __split_buffer(size_type __cap, size_type __start, __alloc_rr& __a);
78 _LIBCPP_CONSTEXPR_AFTER_CXX17 ~__split_buffer();
6279
63 __split_buffer(__split_buffer&& __c)
80 _LIBCPP_CONSTEXPR_AFTER_CXX17 __split_buffer(__split_buffer&& __c)
6481 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
65 __split_buffer(__split_buffer&& __c, const __alloc_rr& __a);
66 __split_buffer& operator=(__split_buffer&& __c)
82 _LIBCPP_CONSTEXPR_AFTER_CXX17 __split_buffer(__split_buffer&& __c, const __alloc_rr& __a);
83 _LIBCPP_CONSTEXPR_AFTER_CXX17 __split_buffer& operator=(__split_buffer&& __c)
6784 _NOEXCEPT_((__alloc_traits::propagate_on_container_move_assignment::value &&
6885 is_nothrow_move_assignable<allocator_type>::value) ||
6986 !__alloc_traits::propagate_on_container_move_assignment::value);
7087
71 _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT {return __begin_;}
72 _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT {return __begin_;}
73 _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT {return __end_;}
74 _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT {return __end_;}
88 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT {return __begin_;}
89 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT {return __begin_;}
90 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT {return __end_;}
91 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT {return __end_;}
7592
76 _LIBCPP_INLINE_VISIBILITY
93 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
7794 void clear() _NOEXCEPT
7895 {__destruct_at_end(__begin_);}
79 _LIBCPP_INLINE_VISIBILITY size_type size() const {return static_cast<size_type>(__end_ - __begin_);}
80 _LIBCPP_INLINE_VISIBILITY bool empty() const {return __end_ == __begin_;}
81 _LIBCPP_INLINE_VISIBILITY size_type capacity() const {return static_cast<size_type>(__end_cap() - __first_);}
82 _LIBCPP_INLINE_VISIBILITY size_type __front_spare() const {return static_cast<size_type>(__begin_ - __first_);}
83 _LIBCPP_INLINE_VISIBILITY size_type __back_spare() const {return static_cast<size_type>(__end_cap() - __end_);}
84
85 _LIBCPP_INLINE_VISIBILITY reference front() {return *__begin_;}
86 _LIBCPP_INLINE_VISIBILITY const_reference front() const {return *__begin_;}
87 _LIBCPP_INLINE_VISIBILITY reference back() {return *(__end_ - 1);}
88 _LIBCPP_INLINE_VISIBILITY const_reference back() const {return *(__end_ - 1);}
89
90 void reserve(size_type __n);
91 void shrink_to_fit() _NOEXCEPT;
92 void push_front(const_reference __x);
93 _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
94 void push_front(value_type&& __x);
95 void push_back(value_type&& __x);
96 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY size_type size() const {return static_cast<size_type>(__end_ - __begin_);}
97 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool empty() const {return __end_ == __begin_;}
98 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY size_type capacity() const {return static_cast<size_type>(__end_cap() - __first_);}
99 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY size_type __front_spare() const {return static_cast<size_type>(__begin_ - __first_);}
100 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY size_type __back_spare() const {return static_cast<size_type>(__end_cap() - __end_);}
101
102 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY reference front() {return *__begin_;}
103 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY const_reference front() const {return *__begin_;}
104 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY reference back() {return *(__end_ - 1);}
105 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY const_reference back() const {return *(__end_ - 1);}
106
107 _LIBCPP_CONSTEXPR_AFTER_CXX17 void reserve(size_type __n);
108 _LIBCPP_CONSTEXPR_AFTER_CXX17 void shrink_to_fit() _NOEXCEPT;
109 _LIBCPP_CONSTEXPR_AFTER_CXX17 void push_front(const_reference __x);
110 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
111 _LIBCPP_CONSTEXPR_AFTER_CXX17 void push_front(value_type&& __x);
112 _LIBCPP_CONSTEXPR_AFTER_CXX17 void push_back(value_type&& __x);
96113 template <class... _Args>
97 void emplace_back(_Args&&... __args);
114 _LIBCPP_CONSTEXPR_AFTER_CXX17 void emplace_back(_Args&&... __args);
98115
99 _LIBCPP_INLINE_VISIBILITY void pop_front() {__destruct_at_begin(__begin_+1);}
100 _LIBCPP_INLINE_VISIBILITY void pop_back() {__destruct_at_end(__end_-1);}
116 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY void pop_front() {__destruct_at_begin(__begin_+1);}
117 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY void pop_back() {__destruct_at_end(__end_-1);}
101118
102 void __construct_at_end(size_type __n);
103 void __construct_at_end(size_type __n, const_reference __x);
119 _LIBCPP_CONSTEXPR_AFTER_CXX17 void __construct_at_end(size_type __n);
120 _LIBCPP_CONSTEXPR_AFTER_CXX17 void __construct_at_end(size_type __n, const_reference __x);
104121 template <class _InputIter>
105 typename enable_if
106 <
107 __is_cpp17_input_iterator<_InputIter>::value &&
108 !__is_cpp17_forward_iterator<_InputIter>::value,
109 void
110 >::type
122 _LIBCPP_CONSTEXPR_AFTER_CXX17 __enable_if_t<__is_exactly_cpp17_input_iterator<_InputIter>::value>
111123 __construct_at_end(_InputIter __first, _InputIter __last);
112124 template <class _ForwardIterator>
113 typename enable_if
114 <
115 __is_cpp17_forward_iterator<_ForwardIterator>::value,
116 void
117 >::type
125 _LIBCPP_CONSTEXPR_AFTER_CXX17 __enable_if_t<__is_cpp17_forward_iterator<_ForwardIterator>::value>
118126 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
119127
120 _LIBCPP_INLINE_VISIBILITY void __destruct_at_begin(pointer __new_begin)
128 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY void __destruct_at_begin(pointer __new_begin)
121129 {__destruct_at_begin(__new_begin, is_trivially_destructible<value_type>());}
122 _LIBCPP_INLINE_VISIBILITY
130 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
123131 void __destruct_at_begin(pointer __new_begin, false_type);
124 _LIBCPP_INLINE_VISIBILITY
132 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
125133 void __destruct_at_begin(pointer __new_begin, true_type);
126134
127 _LIBCPP_INLINE_VISIBILITY
135 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
128136 void __destruct_at_end(pointer __new_last) _NOEXCEPT
129137 {__destruct_at_end(__new_last, false_type());}
130 _LIBCPP_INLINE_VISIBILITY
138 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
131139 void __destruct_at_end(pointer __new_last, false_type) _NOEXCEPT;
132 _LIBCPP_INLINE_VISIBILITY
140 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
133141 void __destruct_at_end(pointer __new_last, true_type) _NOEXCEPT;
134142
135 void swap(__split_buffer& __x)
143 _LIBCPP_CONSTEXPR_AFTER_CXX17 void swap(__split_buffer& __x)
136144 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value||
137145 __is_nothrow_swappable<__alloc_rr>::value);
138146
139 bool __invariants() const;
147 _LIBCPP_CONSTEXPR_AFTER_CXX17 bool __invariants() const;
140148
141149private:
142 _LIBCPP_INLINE_VISIBILITY
150 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
143151 void __move_assign_alloc(__split_buffer& __c, true_type)
144152 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
145153 {
146154 __alloc() = _VSTD::move(__c.__alloc());
147155 }
148156
149 _LIBCPP_INLINE_VISIBILITY
157 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
150158 void __move_assign_alloc(__split_buffer&, false_type) _NOEXCEPT
151159 {}
152160
153161 struct _ConstructTransaction {
154 explicit _ConstructTransaction(pointer* __p, size_type __n) _NOEXCEPT
162 _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit _ConstructTransaction(pointer* __p, size_type __n) _NOEXCEPT
155163 : __pos_(*__p), __end_(*__p + __n), __dest_(__p) {
156164 }
157 ~_ConstructTransaction() {
165 _LIBCPP_CONSTEXPR_AFTER_CXX17 ~_ConstructTransaction() {
158166 *__dest_ = __pos_;
159167 }
160168 pointer __pos_;
......@@ -165,6 +173,7 @@ private:
165173};
166174
167175template <class _Tp, class _Allocator>
176_LIBCPP_CONSTEXPR_AFTER_CXX17
168177bool
169178__split_buffer<_Tp, _Allocator>::__invariants() const
170179{
......@@ -195,6 +204,7 @@ __split_buffer<_Tp, _Allocator>::__invariants() const
195204// Precondition: size() + __n <= capacity()
196205// Postcondition: size() == size() + __n
197206template <class _Tp, class _Allocator>
207_LIBCPP_CONSTEXPR_AFTER_CXX17
198208void
199209__split_buffer<_Tp, _Allocator>::__construct_at_end(size_type __n)
200210{
......@@ -211,6 +221,7 @@ __split_buffer<_Tp, _Allocator>::__construct_at_end(size_type __n)
211221// Postcondition: size() == old size() + __n
212222// Postcondition: [i] == __x for all i in [size() - __n, __n)
213223template <class _Tp, class _Allocator>
224_LIBCPP_CONSTEXPR_AFTER_CXX17
214225void
215226__split_buffer<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x)
216227{
......@@ -223,12 +234,7 @@ __split_buffer<_Tp, _Allocator>::__construct_at_end(size_type __n, const_referen
223234
224235template <class _Tp, class _Allocator>
225236template <class _InputIter>
226typename enable_if
227<
228 __is_cpp17_input_iterator<_InputIter>::value &&
229 !__is_cpp17_forward_iterator<_InputIter>::value,
230 void
231>::type
237_LIBCPP_CONSTEXPR_AFTER_CXX17 __enable_if_t<__is_exactly_cpp17_input_iterator<_InputIter>::value>
232238__split_buffer<_Tp, _Allocator>::__construct_at_end(_InputIter __first, _InputIter __last)
233239{
234240 __alloc_rr& __a = this->__alloc();
......@@ -251,11 +257,7 @@ __split_buffer<_Tp, _Allocator>::__construct_at_end(_InputIter __first, _InputIt
251257
252258template <class _Tp, class _Allocator>
253259template <class _ForwardIterator>
254typename enable_if
255<
256 __is_cpp17_forward_iterator<_ForwardIterator>::value,
257 void
258>::type
260_LIBCPP_CONSTEXPR_AFTER_CXX17 __enable_if_t<__is_cpp17_forward_iterator<_ForwardIterator>::value>
259261__split_buffer<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
260262{
261263 _ConstructTransaction __tx(&this->__end_, _VSTD::distance(__first, __last));
......@@ -266,6 +268,7 @@ __split_buffer<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _F
266268}
267269
268270template <class _Tp, class _Allocator>
271_LIBCPP_CONSTEXPR_AFTER_CXX17
269272inline
270273void
271274__split_buffer<_Tp, _Allocator>::__destruct_at_begin(pointer __new_begin, false_type)
......@@ -275,6 +278,7 @@ __split_buffer<_Tp, _Allocator>::__destruct_at_begin(pointer __new_begin, false_
275278}
276279
277280template <class _Tp, class _Allocator>
281_LIBCPP_CONSTEXPR_AFTER_CXX17
278282inline
279283void
280284__split_buffer<_Tp, _Allocator>::__destruct_at_begin(pointer __new_begin, true_type)
......@@ -283,6 +287,7 @@ __split_buffer<_Tp, _Allocator>::__destruct_at_begin(pointer __new_begin, true_t
283287}
284288
285289template <class _Tp, class _Allocator>
290_LIBCPP_CONSTEXPR_AFTER_CXX17
286291inline _LIBCPP_INLINE_VISIBILITY
287292void
288293__split_buffer<_Tp, _Allocator>::__destruct_at_end(pointer __new_last, false_type) _NOEXCEPT
......@@ -292,6 +297,7 @@ __split_buffer<_Tp, _Allocator>::__destruct_at_end(pointer __new_last, false_typ
292297}
293298
294299template <class _Tp, class _Allocator>
300_LIBCPP_CONSTEXPR_AFTER_CXX17
295301inline _LIBCPP_INLINE_VISIBILITY
296302void
297303__split_buffer<_Tp, _Allocator>::__destruct_at_end(pointer __new_last, true_type) _NOEXCEPT
......@@ -300,15 +306,23 @@ __split_buffer<_Tp, _Allocator>::__destruct_at_end(pointer __new_last, true_type
300306}
301307
302308template <class _Tp, class _Allocator>
309_LIBCPP_CONSTEXPR_AFTER_CXX17
303310__split_buffer<_Tp, _Allocator>::__split_buffer(size_type __cap, size_type __start, __alloc_rr& __a)
304311 : __end_cap_(nullptr, __a)
305312{
306 __first_ = __cap != 0 ? __alloc_traits::allocate(__alloc(), __cap) : nullptr;
313 if (__cap == 0) {
314 __first_ = nullptr;
315 } else {
316 auto __allocation = std::__allocate_at_least(__alloc(), __cap);
317 __first_ = __allocation.ptr;
318 __cap = __allocation.count;
319 }
307320 __begin_ = __end_ = __first_ + __start;
308321 __end_cap() = __first_ + __cap;
309322}
310323
311324template <class _Tp, class _Allocator>
325_LIBCPP_CONSTEXPR_AFTER_CXX17
312326inline
313327__split_buffer<_Tp, _Allocator>::__split_buffer()
314328 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
......@@ -317,6 +331,7 @@ __split_buffer<_Tp, _Allocator>::__split_buffer()
317331}
318332
319333template <class _Tp, class _Allocator>
334_LIBCPP_CONSTEXPR_AFTER_CXX17
320335inline
321336__split_buffer<_Tp, _Allocator>::__split_buffer(__alloc_rr& __a)
322337 : __first_(nullptr), __begin_(nullptr), __end_(nullptr), __end_cap_(nullptr, __a)
......@@ -324,6 +339,7 @@ __split_buffer<_Tp, _Allocator>::__split_buffer(__alloc_rr& __a)
324339}
325340
326341template <class _Tp, class _Allocator>
342_LIBCPP_CONSTEXPR_AFTER_CXX17
327343inline
328344__split_buffer<_Tp, _Allocator>::__split_buffer(const __alloc_rr& __a)
329345 : __first_(nullptr), __begin_(nullptr), __end_(nullptr), __end_cap_(nullptr, __a)
......@@ -331,6 +347,7 @@ __split_buffer<_Tp, _Allocator>::__split_buffer(const __alloc_rr& __a)
331347}
332348
333349template <class _Tp, class _Allocator>
350_LIBCPP_CONSTEXPR_AFTER_CXX17
334351__split_buffer<_Tp, _Allocator>::~__split_buffer()
335352{
336353 clear();
......@@ -339,6 +356,7 @@ __split_buffer<_Tp, _Allocator>::~__split_buffer()
339356}
340357
341358template <class _Tp, class _Allocator>
359_LIBCPP_CONSTEXPR_AFTER_CXX17
342360__split_buffer<_Tp, _Allocator>::__split_buffer(__split_buffer&& __c)
343361 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
344362 : __first_(_VSTD::move(__c.__first_)),
......@@ -353,6 +371,7 @@ __split_buffer<_Tp, _Allocator>::__split_buffer(__split_buffer&& __c)
353371}
354372
355373template <class _Tp, class _Allocator>
374_LIBCPP_CONSTEXPR_AFTER_CXX17
356375__split_buffer<_Tp, _Allocator>::__split_buffer(__split_buffer&& __c, const __alloc_rr& __a)
357376 : __end_cap_(nullptr, __a)
358377{
......@@ -369,16 +388,17 @@ __split_buffer<_Tp, _Allocator>::__split_buffer(__split_buffer&& __c, const __al
369388 }
370389 else
371390 {
372 size_type __cap = __c.size();
373 __first_ = __alloc_traits::allocate(__alloc(), __cap);
391 auto __allocation = std::__allocate_at_least(__alloc(), __c.size());
392 __first_ = __allocation.ptr;
374393 __begin_ = __end_ = __first_;
375 __end_cap() = __first_ + __cap;
394 __end_cap() = __first_ + __allocation.count;
376395 typedef move_iterator<iterator> _Ip;
377396 __construct_at_end(_Ip(__c.begin()), _Ip(__c.end()));
378397 }
379398}
380399
381400template <class _Tp, class _Allocator>
401_LIBCPP_CONSTEXPR_AFTER_CXX17
382402__split_buffer<_Tp, _Allocator>&
383403__split_buffer<_Tp, _Allocator>::operator=(__split_buffer&& __c)
384404 _NOEXCEPT_((__alloc_traits::propagate_on_container_move_assignment::value &&
......@@ -399,6 +419,7 @@ __split_buffer<_Tp, _Allocator>::operator=(__split_buffer&& __c)
399419}
400420
401421template <class _Tp, class _Allocator>
422_LIBCPP_CONSTEXPR_AFTER_CXX17
402423void
403424__split_buffer<_Tp, _Allocator>::swap(__split_buffer& __x)
404425 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value||
......@@ -412,6 +433,7 @@ __split_buffer<_Tp, _Allocator>::swap(__split_buffer& __x)
412433}
413434
414435template <class _Tp, class _Allocator>
436_LIBCPP_CONSTEXPR_AFTER_CXX17
415437void
416438__split_buffer<_Tp, _Allocator>::reserve(size_type __n)
417439{
......@@ -428,6 +450,7 @@ __split_buffer<_Tp, _Allocator>::reserve(size_type __n)
428450}
429451
430452template <class _Tp, class _Allocator>
453_LIBCPP_CONSTEXPR_AFTER_CXX17
431454void
432455__split_buffer<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT
433456{
......@@ -455,6 +478,7 @@ __split_buffer<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT
455478}
456479
457480template <class _Tp, class _Allocator>
481_LIBCPP_CONSTEXPR_AFTER_CXX17
458482void
459483__split_buffer<_Tp, _Allocator>::push_front(const_reference __x)
460484{
......@@ -484,6 +508,7 @@ __split_buffer<_Tp, _Allocator>::push_front(const_reference __x)
484508}
485509
486510template <class _Tp, class _Allocator>
511_LIBCPP_CONSTEXPR_AFTER_CXX17
487512void
488513__split_buffer<_Tp, _Allocator>::push_front(value_type&& __x)
489514{
......@@ -514,6 +539,7 @@ __split_buffer<_Tp, _Allocator>::push_front(value_type&& __x)
514539}
515540
516541template <class _Tp, class _Allocator>
542_LIBCPP_CONSTEXPR_AFTER_CXX17
517543inline _LIBCPP_INLINE_VISIBILITY
518544void
519545__split_buffer<_Tp, _Allocator>::push_back(const_reference __x)
......@@ -544,6 +570,7 @@ __split_buffer<_Tp, _Allocator>::push_back(const_reference __x)
544570}
545571
546572template <class _Tp, class _Allocator>
573_LIBCPP_CONSTEXPR_AFTER_CXX17
547574void
548575__split_buffer<_Tp, _Allocator>::push_back(value_type&& __x)
549576{
......@@ -575,6 +602,7 @@ __split_buffer<_Tp, _Allocator>::push_back(value_type&& __x)
575602
576603template <class _Tp, class _Allocator>
577604template <class... _Args>
605_LIBCPP_CONSTEXPR_AFTER_CXX17
578606void
579607__split_buffer<_Tp, _Allocator>::emplace_back(_Args&&... __args)
580608{
......@@ -605,6 +633,7 @@ __split_buffer<_Tp, _Allocator>::emplace_back(_Args&&... __args)
605633}
606634
607635template <class _Tp, class _Allocator>
636_LIBCPP_CONSTEXPR_AFTER_CXX17
608637inline _LIBCPP_INLINE_VISIBILITY
609638void
610639swap(__split_buffer<_Tp, _Allocator>& __x, __split_buffer<_Tp, _Allocator>& __y)
......@@ -617,4 +646,4 @@ _LIBCPP_END_NAMESPACE_STD
617646
618647_LIBCPP_POP_MACROS
619648
620#endif // _LIBCPP_SPLIT_BUFFER
649#endif // _LIBCPP___SPLIT_BUFFER
lib/libcxx/include/__std_stream+1-1
......@@ -17,7 +17,7 @@
1717#include <ostream>
1818
1919#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20#pragma GCC system_header
20# pragma GCC system_header
2121#endif
2222
2323_LIBCPP_PUSH_MACROS
lib/libcxx/include/__string deleted-1175
......@@ -1,1175 +0,0 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___STRING
11#define _LIBCPP___STRING
12
13#include <__algorithm/copy.h>
14#include <__algorithm/copy_backward.h>
15#include <__algorithm/copy_n.h>
16#include <__algorithm/fill_n.h>
17#include <__algorithm/find_end.h>
18#include <__algorithm/find_first_of.h>
19#include <__algorithm/min.h>
20#include <__config>
21#include <__functional/hash.h> // for __murmur2_or_cityhash
22#include <__iterator/iterator_traits.h>
23#include <cstdint> // for uint_least16_t
24#include <cstdio> // for EOF
25#include <cstring> // for memcpy
26#include <iosfwd> // for streampos & friends
27#include <type_traits> // for __libcpp_is_constant_evaluated
28
29#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
30# include <cwchar> // for wmemcpy
31#endif
32
33#include <__debug>
34
35#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
36#pragma GCC system_header
37#endif
38
39_LIBCPP_PUSH_MACROS
40#include <__undef_macros>
41
42
43_LIBCPP_BEGIN_NAMESPACE_STD
44
45// The extern template ABI lists are kept outside of <string> to improve the
46// readability of that header. We maintain 2 ABI lists:
47// - _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST
48// - _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST
49// As the name implies, the ABI lists define the V1 (Stable) and unstable ABI.
50//
51// For unstable, we may explicitly remove function that are external in V1,
52// and add (new) external functions to better control inlining and compiler
53// optimization opportunities.
54//
55// For stable, the ABI list should rarely change, except for adding new
56// functions supporting new c++ version / API changes. Typically entries
57// must never be removed from the stable list.
58#define _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_Func, _CharType) \
59 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, value_type const*, size_type)) \
60 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::rfind(value_type const*, size_type, size_type) const) \
61 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__init(value_type const*, size_type, size_type)) \
62 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::basic_string(basic_string const&)) \
63 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, value_type const*)) \
64 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::basic_string(basic_string const&, allocator<_CharType> const&)) \
65 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find_last_not_of(value_type const*, size_type, size_type) const) \
66 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::~basic_string()) \
67 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find_first_not_of(value_type const*, size_type, size_type) const) \
68 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::insert(size_type, size_type, value_type)) \
69 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::operator=(value_type)) \
70 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__init(value_type const*, size_type)) \
71 _Func(_LIBCPP_FUNC_VIS const _CharType& basic_string<_CharType>::at(size_type) const) \
72 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::insert(size_type, value_type const*, size_type)) \
73 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find_first_of(value_type const*, size_type, size_type) const) \
74 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, size_type, value_type)) \
75 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::assign(value_type const*, size_type)) \
76 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::reserve(size_type)) \
77 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::append(value_type const*, size_type)) \
78 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::assign(basic_string const&, size_type, size_type)) \
79 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::copy(value_type*, size_type, size_type) const) \
80 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::basic_string(basic_string const&, size_type, size_type, allocator<_CharType> const&)) \
81 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find(value_type, size_type) const) \
82 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__init(size_type, value_type)) \
83 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::insert(size_type, value_type const*)) \
84 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find_last_of(value_type const*, size_type, size_type) const) \
85 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__grow_by(size_type, size_type, size_type, size_type, size_type, size_type)) \
86 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__grow_by_and_replace(size_type, size_type, size_type, size_type, size_type, size_type, value_type const*)) \
87 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::push_back(value_type)) \
88 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::append(size_type, value_type)) \
89 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::rfind(value_type, size_type) const) \
90 _Func(_LIBCPP_FUNC_VIS const basic_string<_CharType>::size_type basic_string<_CharType>::npos) \
91 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::assign(size_type, value_type)) \
92 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::erase(size_type, size_type)) \
93 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::append(basic_string const&, size_type, size_type)) \
94 _Func(_LIBCPP_FUNC_VIS int basic_string<_CharType>::compare(value_type const*) const) \
95 _Func(_LIBCPP_FUNC_VIS int basic_string<_CharType>::compare(size_type, size_type, value_type const*) const) \
96 _Func(_LIBCPP_FUNC_VIS _CharType& basic_string<_CharType>::at(size_type)) \
97 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::assign(value_type const*)) \
98 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find(value_type const*, size_type, size_type) const) \
99 _Func(_LIBCPP_FUNC_VIS int basic_string<_CharType>::compare(size_type, size_type, basic_string const&, size_type, size_type) const) \
100 _Func(_LIBCPP_FUNC_VIS int basic_string<_CharType>::compare(size_type, size_type, value_type const*, size_type) const) \
101 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::operator=(basic_string const&)) \
102 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::append(value_type const*)) \
103 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, basic_string const&, size_type, size_type)) \
104 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::iterator basic_string<_CharType>::insert(basic_string::const_iterator, value_type)) \
105 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::resize(size_type, value_type)) \
106 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::insert(size_type, basic_string const&, size_type, size_type))
107
108#define _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_Func, _CharType) \
109 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, value_type const*, size_type)) \
110 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::rfind(value_type const*, size_type, size_type) const) \
111 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__init(value_type const*, size_type, size_type)) \
112 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, value_type const*)) \
113 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find_last_not_of(value_type const*, size_type, size_type) const) \
114 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::~basic_string()) \
115 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find_first_not_of(value_type const*, size_type, size_type) const) \
116 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::insert(size_type, size_type, value_type)) \
117 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::operator=(value_type)) \
118 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__init(value_type const*, size_type)) \
119 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__init_copy_ctor_external(value_type const*, size_type)) \
120 _Func(_LIBCPP_FUNC_VIS const _CharType& basic_string<_CharType>::at(size_type) const) \
121 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::insert(size_type, value_type const*, size_type)) \
122 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find_first_of(value_type const*, size_type, size_type) const) \
123 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, size_type, value_type)) \
124 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::__assign_external(value_type const*, size_type)) \
125 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::__assign_external(value_type const*)) \
126 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::reserve(size_type)) \
127 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::append(value_type const*, size_type)) \
128 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::assign(basic_string const&, size_type, size_type)) \
129 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::copy(value_type*, size_type, size_type) const) \
130 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::basic_string(basic_string const&, size_type, size_type, allocator<_CharType> const&)) \
131 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find(value_type, size_type) const) \
132 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__init(size_type, value_type)) \
133 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::insert(size_type, value_type const*)) \
134 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find_last_of(value_type const*, size_type, size_type) const) \
135 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__grow_by(size_type, size_type, size_type, size_type, size_type, size_type)) \
136 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__grow_by_and_replace(size_type, size_type, size_type, size_type, size_type, size_type, value_type const*)) \
137 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::__assign_no_alias<false>(value_type const*, size_type)) \
138 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::__assign_no_alias<true>(value_type const*, size_type)) \
139 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::push_back(value_type)) \
140 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::append(size_type, value_type)) \
141 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::rfind(value_type, size_type) const) \
142 _Func(_LIBCPP_FUNC_VIS const basic_string<_CharType>::size_type basic_string<_CharType>::npos) \
143 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::assign(size_type, value_type)) \
144 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__erase_external_with_move(size_type, size_type)) \
145 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::append(basic_string const&, size_type, size_type)) \
146 _Func(_LIBCPP_FUNC_VIS int basic_string<_CharType>::compare(value_type const*) const) \
147 _Func(_LIBCPP_FUNC_VIS int basic_string<_CharType>::compare(size_type, size_type, value_type const*) const) \
148 _Func(_LIBCPP_FUNC_VIS _CharType& basic_string<_CharType>::at(size_type)) \
149 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find(value_type const*, size_type, size_type) const) \
150 _Func(_LIBCPP_FUNC_VIS int basic_string<_CharType>::compare(size_type, size_type, basic_string const&, size_type, size_type) const) \
151 _Func(_LIBCPP_FUNC_VIS int basic_string<_CharType>::compare(size_type, size_type, value_type const*, size_type) const) \
152 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::append(value_type const*)) \
153 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, basic_string const&, size_type, size_type)) \
154 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::iterator basic_string<_CharType>::insert(basic_string::const_iterator, value_type)) \
155 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::resize(size_type, value_type)) \
156 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::insert(size_type, basic_string const&, size_type, size_type))
157
158
159// char_traits
160
161template <class _CharT>
162struct _LIBCPP_TEMPLATE_VIS char_traits
163{
164 typedef _CharT char_type;
165 typedef int int_type;
166 typedef streamoff off_type;
167 typedef streampos pos_type;
168 typedef mbstate_t state_type;
169
170 static inline void _LIBCPP_CONSTEXPR_AFTER_CXX14
171 assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;}
172 static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
173 {return __c1 == __c2;}
174 static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
175 {return __c1 < __c2;}
176
177 static _LIBCPP_CONSTEXPR_AFTER_CXX14
178 int compare(const char_type* __s1, const char_type* __s2, size_t __n);
179 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
180 size_t length(const char_type* __s);
181 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
182 const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
183 static _LIBCPP_CONSTEXPR_AFTER_CXX17
184 char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
185 _LIBCPP_INLINE_VISIBILITY
186 static _LIBCPP_CONSTEXPR_AFTER_CXX17
187 char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
188 _LIBCPP_INLINE_VISIBILITY
189 static _LIBCPP_CONSTEXPR_AFTER_CXX17
190 char_type* assign(char_type* __s, size_t __n, char_type __a);
191
192 static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
193 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
194 static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
195 {return char_type(__c);}
196 static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
197 {return int_type(__c);}
198 static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
199 {return __c1 == __c2;}
200 static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
201 {return int_type(EOF);}
202};
203
204template <class _CharT>
205_LIBCPP_CONSTEXPR_AFTER_CXX14 int
206char_traits<_CharT>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
207{
208 for (; __n; --__n, ++__s1, ++__s2)
209 {
210 if (lt(*__s1, *__s2))
211 return -1;
212 if (lt(*__s2, *__s1))
213 return 1;
214 }
215 return 0;
216}
217
218template <class _CharT>
219inline
220_LIBCPP_CONSTEXPR_AFTER_CXX14 size_t
221char_traits<_CharT>::length(const char_type* __s)
222{
223 size_t __len = 0;
224 for (; !eq(*__s, char_type(0)); ++__s)
225 ++__len;
226 return __len;
227}
228
229template <class _CharT>
230inline
231_LIBCPP_CONSTEXPR_AFTER_CXX14 const _CharT*
232char_traits<_CharT>::find(const char_type* __s, size_t __n, const char_type& __a)
233{
234 for (; __n; --__n)
235 {
236 if (eq(*__s, __a))
237 return __s;
238 ++__s;
239 }
240 return nullptr;
241}
242
243template <class _CharT>
244_LIBCPP_CONSTEXPR_AFTER_CXX17 _CharT*
245char_traits<_CharT>::move(char_type* __s1, const char_type* __s2, size_t __n)
246{
247 if (__n == 0) return __s1;
248 char_type* __r = __s1;
249 if (__s1 < __s2)
250 {
251 for (; __n; --__n, ++__s1, ++__s2)
252 assign(*__s1, *__s2);
253 }
254 else if (__s2 < __s1)
255 {
256 __s1 += __n;
257 __s2 += __n;
258 for (; __n; --__n)
259 assign(*--__s1, *--__s2);
260 }
261 return __r;
262}
263
264template <class _CharT>
265inline _LIBCPP_CONSTEXPR_AFTER_CXX17
266_CharT*
267char_traits<_CharT>::copy(char_type* __s1, const char_type* __s2, size_t __n)
268{
269 if (!__libcpp_is_constant_evaluated()) {
270 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
271 }
272 char_type* __r = __s1;
273 for (; __n; --__n, ++__s1, ++__s2)
274 assign(*__s1, *__s2);
275 return __r;
276}
277
278template <class _CharT>
279inline _LIBCPP_CONSTEXPR_AFTER_CXX17
280_CharT*
281char_traits<_CharT>::assign(char_type* __s, size_t __n, char_type __a)
282{
283 char_type* __r = __s;
284 for (; __n; --__n, ++__s)
285 assign(*__s, __a);
286 return __r;
287}
288
289// constexpr versions of move/copy/assign.
290
291template <class _CharT>
292static inline _LIBCPP_CONSTEXPR_AFTER_CXX17
293_CharT* __copy_constexpr(_CharT* __dest, const _CharT* __source, size_t __n) _NOEXCEPT
294{
295 _LIBCPP_ASSERT(__libcpp_is_constant_evaluated(), "__copy_constexpr() should always be constant evaluated");
296 _VSTD::copy_n(__source, __n, __dest);
297 return __dest;
298}
299
300template <class _CharT>
301static inline _LIBCPP_CONSTEXPR_AFTER_CXX17
302_CharT* __move_constexpr(_CharT* __dest, const _CharT* __source, size_t __n) _NOEXCEPT
303{
304 _LIBCPP_ASSERT(__libcpp_is_constant_evaluated(), "__move_constexpr() should always be constant evaluated");
305 if (__n == 0)
306 return __dest;
307 _CharT* __allocation = new _CharT[__n];
308 _VSTD::__copy_constexpr(__allocation, __source, __n);
309 _VSTD::__copy_constexpr(__dest, static_cast<const _CharT*>(__allocation), __n);
310 delete[] __allocation;
311 return __dest;
312}
313
314template <class _CharT>
315static inline _LIBCPP_CONSTEXPR_AFTER_CXX17
316_CharT* __assign_constexpr(_CharT* __s, size_t __n, _CharT __a) _NOEXCEPT
317{
318 _LIBCPP_ASSERT(__libcpp_is_constant_evaluated(), "__assign_constexpr() should always be constant evaluated");
319 _VSTD::fill_n(__s, __n, __a);
320 return __s;
321}
322
323// char_traits<char>
324
325template <>
326struct _LIBCPP_TEMPLATE_VIS char_traits<char>
327{
328 typedef char char_type;
329 typedef int int_type;
330 typedef streamoff off_type;
331 typedef streampos pos_type;
332 typedef mbstate_t state_type;
333
334 static inline _LIBCPP_CONSTEXPR_AFTER_CXX14
335 void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;}
336 static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
337 {return __c1 == __c2;}
338 static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
339 {return (unsigned char)__c1 < (unsigned char)__c2;}
340
341 static _LIBCPP_CONSTEXPR_AFTER_CXX14
342 int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
343
344 static inline size_t _LIBCPP_CONSTEXPR_AFTER_CXX14 length(const char_type* __s) _NOEXCEPT {
345 // GCC currently does not support __builtin_strlen during constant evaluation.
346 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70816
347#ifdef _LIBCPP_COMPILER_GCC
348 if (__libcpp_is_constant_evaluated()) {
349 size_t __i = 0;
350 for (; __s[__i] != char_type('\0'); ++__i)
351 ;
352 return __i;
353 }
354#endif
355 return __builtin_strlen(__s);
356 }
357
358 static _LIBCPP_CONSTEXPR_AFTER_CXX14
359 const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT;
360 static inline _LIBCPP_CONSTEXPR_AFTER_CXX17
361 char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
362 {
363 return __libcpp_is_constant_evaluated()
364 ? _VSTD::__move_constexpr(__s1, __s2, __n)
365 : __n == 0 ? __s1 : (char_type*)_VSTD::memmove(__s1, __s2, __n);
366 }
367 static inline _LIBCPP_CONSTEXPR_AFTER_CXX17
368 char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
369 {
370 if (!__libcpp_is_constant_evaluated()) {
371 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
372 }
373 return __libcpp_is_constant_evaluated()
374 ? _VSTD::__copy_constexpr(__s1, __s2, __n)
375 : __n == 0 ? __s1 : (char_type*)_VSTD::memcpy(__s1, __s2, __n);
376 }
377 static inline _LIBCPP_CONSTEXPR_AFTER_CXX17
378 char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT
379 {
380 return __libcpp_is_constant_evaluated()
381 ? _VSTD::__assign_constexpr(__s, __n, __a)
382 : __n == 0 ? __s : (char_type*)_VSTD::memset(__s, to_int_type(__a), __n);
383 }
384
385 static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
386 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
387 static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
388 {return char_type(__c);}
389 static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
390 {return int_type((unsigned char)__c);}
391 static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
392 {return __c1 == __c2;}
393 static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
394 {return int_type(EOF);}
395};
396
397inline _LIBCPP_CONSTEXPR_AFTER_CXX14
398int
399char_traits<char>::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
400{
401 if (__n == 0)
402 return 0;
403#if __has_feature(cxx_constexpr_string_builtins)
404 return __builtin_memcmp(__s1, __s2, __n);
405#elif _LIBCPP_STD_VER <= 14
406 return _VSTD::memcmp(__s1, __s2, __n);
407#else
408 for (; __n; --__n, ++__s1, ++__s2)
409 {
410 if (lt(*__s1, *__s2))
411 return -1;
412 if (lt(*__s2, *__s1))
413 return 1;
414 }
415 return 0;
416#endif
417}
418
419inline _LIBCPP_CONSTEXPR_AFTER_CXX14
420const char*
421char_traits<char>::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT
422{
423 if (__n == 0)
424 return nullptr;
425#if __has_feature(cxx_constexpr_string_builtins)
426 return __builtin_char_memchr(__s, to_int_type(__a), __n);
427#elif _LIBCPP_STD_VER <= 14
428 return (const char_type*) _VSTD::memchr(__s, to_int_type(__a), __n);
429#else
430 for (; __n; --__n)
431 {
432 if (eq(*__s, __a))
433 return __s;
434 ++__s;
435 }
436 return nullptr;
437#endif
438}
439
440
441// char_traits<wchar_t>
442
443#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
444template <>
445struct _LIBCPP_TEMPLATE_VIS char_traits<wchar_t>
446{
447 typedef wchar_t char_type;
448 typedef wint_t int_type;
449 typedef streamoff off_type;
450 typedef streampos pos_type;
451 typedef mbstate_t state_type;
452
453 static inline _LIBCPP_CONSTEXPR_AFTER_CXX14
454 void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;}
455 static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
456 {return __c1 == __c2;}
457 static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
458 {return __c1 < __c2;}
459
460 static _LIBCPP_CONSTEXPR_AFTER_CXX14
461 int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
462 static _LIBCPP_CONSTEXPR_AFTER_CXX14
463 size_t length(const char_type* __s) _NOEXCEPT;
464 static _LIBCPP_CONSTEXPR_AFTER_CXX14
465 const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT;
466 static inline _LIBCPP_CONSTEXPR_AFTER_CXX17
467 char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
468 {
469 return __libcpp_is_constant_evaluated()
470 ? _VSTD::__move_constexpr(__s1, __s2, __n)
471 : __n == 0 ? __s1 : _VSTD::wmemmove(__s1, __s2, __n);
472 }
473 static inline _LIBCPP_CONSTEXPR_AFTER_CXX17
474 char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
475 {
476 if (!__libcpp_is_constant_evaluated()) {
477 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
478 }
479 return __libcpp_is_constant_evaluated()
480 ? _VSTD::__copy_constexpr(__s1, __s2, __n)
481 : __n == 0 ? __s1 : _VSTD::wmemcpy(__s1, __s2, __n);
482 }
483 static inline _LIBCPP_CONSTEXPR_AFTER_CXX17
484 char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT
485 {
486 return __libcpp_is_constant_evaluated()
487 ? _VSTD::__assign_constexpr(__s, __n, __a)
488 : __n == 0 ? __s : _VSTD::wmemset(__s, __a, __n);
489 }
490 static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
491 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
492 static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
493 {return char_type(__c);}
494 static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
495 {return int_type(__c);}
496 static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
497 {return __c1 == __c2;}
498 static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
499 {return int_type(WEOF);}
500};
501
502inline _LIBCPP_CONSTEXPR_AFTER_CXX14
503int
504char_traits<wchar_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
505{
506 if (__n == 0)
507 return 0;
508#if __has_feature(cxx_constexpr_string_builtins)
509 return __builtin_wmemcmp(__s1, __s2, __n);
510#elif _LIBCPP_STD_VER <= 14
511 return _VSTD::wmemcmp(__s1, __s2, __n);
512#else
513 for (; __n; --__n, ++__s1, ++__s2)
514 {
515 if (lt(*__s1, *__s2))
516 return -1;
517 if (lt(*__s2, *__s1))
518 return 1;
519 }
520 return 0;
521#endif
522}
523
524inline _LIBCPP_CONSTEXPR_AFTER_CXX14
525size_t
526char_traits<wchar_t>::length(const char_type* __s) _NOEXCEPT
527{
528#if __has_feature(cxx_constexpr_string_builtins)
529 return __builtin_wcslen(__s);
530#elif _LIBCPP_STD_VER <= 14
531 return _VSTD::wcslen(__s);
532#else
533 size_t __len = 0;
534 for (; !eq(*__s, char_type(0)); ++__s)
535 ++__len;
536 return __len;
537#endif
538}
539
540inline _LIBCPP_CONSTEXPR_AFTER_CXX14
541const wchar_t*
542char_traits<wchar_t>::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT
543{
544 if (__n == 0)
545 return nullptr;
546#if __has_feature(cxx_constexpr_string_builtins)
547 return __builtin_wmemchr(__s, __a, __n);
548#elif _LIBCPP_STD_VER <= 14
549 return _VSTD::wmemchr(__s, __a, __n);
550#else
551 for (; __n; --__n)
552 {
553 if (eq(*__s, __a))
554 return __s;
555 ++__s;
556 }
557 return nullptr;
558#endif
559}
560#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
561
562template <class _Traits>
563_LIBCPP_INLINE_VISIBILITY
564_LIBCPP_CONSTEXPR
565inline size_t __char_traits_length_checked(const typename _Traits::char_type* __s) _NOEXCEPT {
566#if _LIBCPP_DEBUG_LEVEL >= 1
567 return __s ? _Traits::length(__s) : (_VSTD::__libcpp_debug_function(_VSTD::__libcpp_debug_info(__FILE__, __LINE__, "p == nullptr", "null pointer pass to non-null argument of char_traits<...>::length")), 0);
568#else
569 return _Traits::length(__s);
570#endif
571}
572
573#ifndef _LIBCPP_HAS_NO_CHAR8_T
574
575template <>
576struct _LIBCPP_TEMPLATE_VIS char_traits<char8_t>
577{
578 typedef char8_t char_type;
579 typedef unsigned int int_type;
580 typedef streamoff off_type;
581 typedef u8streampos pos_type;
582 typedef mbstate_t state_type;
583
584 static inline constexpr void assign(char_type& __c1, const char_type& __c2) noexcept
585 {__c1 = __c2;}
586 static inline constexpr bool eq(char_type __c1, char_type __c2) noexcept
587 {return __c1 == __c2;}
588 static inline constexpr bool lt(char_type __c1, char_type __c2) noexcept
589 {return __c1 < __c2;}
590
591 static constexpr
592 int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
593
594 static constexpr
595 size_t length(const char_type* __s) _NOEXCEPT;
596
597 _LIBCPP_INLINE_VISIBILITY static constexpr
598 const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT;
599
600 static _LIBCPP_CONSTEXPR_AFTER_CXX17
601 char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
602 {
603 return __libcpp_is_constant_evaluated()
604 ? _VSTD::__move_constexpr(__s1, __s2, __n)
605 : __n == 0 ? __s1 : (char_type*)_VSTD::memmove(__s1, __s2, __n);
606 }
607
608 static _LIBCPP_CONSTEXPR_AFTER_CXX17
609 char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
610 {
611 if (!__libcpp_is_constant_evaluated()) {
612 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
613 }
614 return __libcpp_is_constant_evaluated()
615 ? _VSTD::__copy_constexpr(__s1, __s2, __n)
616 : __n == 0 ? __s1 : (char_type*)_VSTD::memcpy(__s1, __s2, __n);
617 }
618
619 static _LIBCPP_CONSTEXPR_AFTER_CXX17
620 char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT
621 {
622 return __libcpp_is_constant_evaluated()
623 ? _VSTD::__assign_constexpr(__s, __n, __a)
624 : __n == 0 ? __s : (char_type*)_VSTD::memset(__s, to_int_type(__a), __n);
625 }
626
627 static inline constexpr int_type not_eof(int_type __c) noexcept
628 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
629 static inline constexpr char_type to_char_type(int_type __c) noexcept
630 {return char_type(__c);}
631 static inline constexpr int_type to_int_type(char_type __c) noexcept
632 {return int_type(__c);}
633 static inline constexpr bool eq_int_type(int_type __c1, int_type __c2) noexcept
634 {return __c1 == __c2;}
635 static inline constexpr int_type eof() noexcept
636 {return int_type(EOF);}
637};
638
639// TODO use '__builtin_strlen' if it ever supports char8_t ??
640inline constexpr
641size_t
642char_traits<char8_t>::length(const char_type* __s) _NOEXCEPT
643{
644 size_t __len = 0;
645 for (; !eq(*__s, char_type(0)); ++__s)
646 ++__len;
647 return __len;
648}
649
650inline constexpr
651int
652char_traits<char8_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
653{
654#if __has_feature(cxx_constexpr_string_builtins)
655 return __builtin_memcmp(__s1, __s2, __n);
656#else
657 for (; __n; --__n, ++__s1, ++__s2)
658 {
659 if (lt(*__s1, *__s2))
660 return -1;
661 if (lt(*__s2, *__s1))
662 return 1;
663 }
664 return 0;
665#endif
666}
667
668// TODO use '__builtin_char_memchr' if it ever supports char8_t ??
669inline constexpr
670const char8_t*
671char_traits<char8_t>::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT
672{
673 for (; __n; --__n)
674 {
675 if (eq(*__s, __a))
676 return __s;
677 ++__s;
678 }
679 return nullptr;
680}
681
682#endif // #_LIBCPP_HAS_NO_CHAR8_T
683
684#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
685
686template <>
687struct _LIBCPP_TEMPLATE_VIS char_traits<char16_t>
688{
689 typedef char16_t char_type;
690 typedef uint_least16_t int_type;
691 typedef streamoff off_type;
692 typedef u16streampos pos_type;
693 typedef mbstate_t state_type;
694
695 static inline _LIBCPP_CONSTEXPR_AFTER_CXX14
696 void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;}
697 static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
698 {return __c1 == __c2;}
699 static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
700 {return __c1 < __c2;}
701
702 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
703 int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
704 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
705 size_t length(const char_type* __s) _NOEXCEPT;
706 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
707 const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT;
708 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
709 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
710 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
711 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
712 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
713 static char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT;
714
715 static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
716 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
717 static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
718 {return char_type(__c);}
719 static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
720 {return int_type(__c);}
721 static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
722 {return __c1 == __c2;}
723 static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
724 {return int_type(0xFFFF);}
725};
726
727inline _LIBCPP_CONSTEXPR_AFTER_CXX14
728int
729char_traits<char16_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
730{
731 for (; __n; --__n, ++__s1, ++__s2)
732 {
733 if (lt(*__s1, *__s2))
734 return -1;
735 if (lt(*__s2, *__s1))
736 return 1;
737 }
738 return 0;
739}
740
741inline _LIBCPP_CONSTEXPR_AFTER_CXX14
742size_t
743char_traits<char16_t>::length(const char_type* __s) _NOEXCEPT
744{
745 size_t __len = 0;
746 for (; !eq(*__s, char_type(0)); ++__s)
747 ++__len;
748 return __len;
749}
750
751inline _LIBCPP_CONSTEXPR_AFTER_CXX14
752const char16_t*
753char_traits<char16_t>::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT
754{
755 for (; __n; --__n)
756 {
757 if (eq(*__s, __a))
758 return __s;
759 ++__s;
760 }
761 return nullptr;
762}
763
764inline _LIBCPP_CONSTEXPR_AFTER_CXX17
765char16_t*
766char_traits<char16_t>::move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
767{
768 if (__n == 0) return __s1;
769 char_type* __r = __s1;
770 if (__s1 < __s2)
771 {
772 for (; __n; --__n, ++__s1, ++__s2)
773 assign(*__s1, *__s2);
774 }
775 else if (__s2 < __s1)
776 {
777 __s1 += __n;
778 __s2 += __n;
779 for (; __n; --__n)
780 assign(*--__s1, *--__s2);
781 }
782 return __r;
783}
784
785inline _LIBCPP_CONSTEXPR_AFTER_CXX17
786char16_t*
787char_traits<char16_t>::copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
788{
789 if (!__libcpp_is_constant_evaluated()) {
790 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
791 }
792 char_type* __r = __s1;
793 for (; __n; --__n, ++__s1, ++__s2)
794 assign(*__s1, *__s2);
795 return __r;
796}
797
798inline _LIBCPP_CONSTEXPR_AFTER_CXX17
799char16_t*
800char_traits<char16_t>::assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT
801{
802 char_type* __r = __s;
803 for (; __n; --__n, ++__s)
804 assign(*__s, __a);
805 return __r;
806}
807
808template <>
809struct _LIBCPP_TEMPLATE_VIS char_traits<char32_t>
810{
811 typedef char32_t char_type;
812 typedef uint_least32_t int_type;
813 typedef streamoff off_type;
814 typedef u32streampos pos_type;
815 typedef mbstate_t state_type;
816
817 static inline _LIBCPP_CONSTEXPR_AFTER_CXX14
818 void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;}
819 static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
820 {return __c1 == __c2;}
821 static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
822 {return __c1 < __c2;}
823
824 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
825 int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
826 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
827 size_t length(const char_type* __s) _NOEXCEPT;
828 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
829 const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT;
830 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
831 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
832 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
833 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
834 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
835 static char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT;
836
837 static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
838 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
839 static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
840 {return char_type(__c);}
841 static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
842 {return int_type(__c);}
843 static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
844 {return __c1 == __c2;}
845 static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
846 {return int_type(0xFFFFFFFF);}
847};
848
849inline _LIBCPP_CONSTEXPR_AFTER_CXX14
850int
851char_traits<char32_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
852{
853 for (; __n; --__n, ++__s1, ++__s2)
854 {
855 if (lt(*__s1, *__s2))
856 return -1;
857 if (lt(*__s2, *__s1))
858 return 1;
859 }
860 return 0;
861}
862
863inline _LIBCPP_CONSTEXPR_AFTER_CXX14
864size_t
865char_traits<char32_t>::length(const char_type* __s) _NOEXCEPT
866{
867 size_t __len = 0;
868 for (; !eq(*__s, char_type(0)); ++__s)
869 ++__len;
870 return __len;
871}
872
873inline _LIBCPP_CONSTEXPR_AFTER_CXX14
874const char32_t*
875char_traits<char32_t>::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT
876{
877 for (; __n; --__n)
878 {
879 if (eq(*__s, __a))
880 return __s;
881 ++__s;
882 }
883 return nullptr;
884}
885
886inline _LIBCPP_CONSTEXPR_AFTER_CXX17
887char32_t*
888char_traits<char32_t>::move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
889{
890 if (__n == 0) return __s1;
891 char_type* __r = __s1;
892 if (__s1 < __s2)
893 {
894 for (; __n; --__n, ++__s1, ++__s2)
895 assign(*__s1, *__s2);
896 }
897 else if (__s2 < __s1)
898 {
899 __s1 += __n;
900 __s2 += __n;
901 for (; __n; --__n)
902 assign(*--__s1, *--__s2);
903 }
904 return __r;
905}
906
907inline _LIBCPP_CONSTEXPR_AFTER_CXX17
908char32_t*
909char_traits<char32_t>::copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
910{
911 if (!__libcpp_is_constant_evaluated()) {
912 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
913 }
914 char_type* __r = __s1;
915 for (; __n; --__n, ++__s1, ++__s2)
916 assign(*__s1, *__s2);
917 return __r;
918}
919
920inline _LIBCPP_CONSTEXPR_AFTER_CXX17
921char32_t*
922char_traits<char32_t>::assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT
923{
924 char_type* __r = __s;
925 for (; __n; --__n, ++__s)
926 assign(*__s, __a);
927 return __r;
928}
929
930#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
931
932// helper fns for basic_string and string_view
933
934// __str_find
935template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
936inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
937__str_find(const _CharT *__p, _SizeT __sz,
938 _CharT __c, _SizeT __pos) _NOEXCEPT
939{
940 if (__pos >= __sz)
941 return __npos;
942 const _CharT* __r = _Traits::find(__p + __pos, __sz - __pos, __c);
943 if (__r == nullptr)
944 return __npos;
945 return static_cast<_SizeT>(__r - __p);
946}
947
948template <class _CharT, class _Traits>
949inline _LIBCPP_CONSTEXPR_AFTER_CXX11 const _CharT *
950__search_substring(const _CharT *__first1, const _CharT *__last1,
951 const _CharT *__first2, const _CharT *__last2) _NOEXCEPT {
952 // Take advantage of knowing source and pattern lengths.
953 // Stop short when source is smaller than pattern.
954 const ptrdiff_t __len2 = __last2 - __first2;
955 if (__len2 == 0)
956 return __first1;
957
958 ptrdiff_t __len1 = __last1 - __first1;
959 if (__len1 < __len2)
960 return __last1;
961
962 // First element of __first2 is loop invariant.
963 _CharT __f2 = *__first2;
964 while (true) {
965 __len1 = __last1 - __first1;
966 // Check whether __first1 still has at least __len2 bytes.
967 if (__len1 < __len2)
968 return __last1;
969
970 // Find __f2 the first byte matching in __first1.
971 __first1 = _Traits::find(__first1, __len1 - __len2 + 1, __f2);
972 if (__first1 == nullptr)
973 return __last1;
974
975 // It is faster to compare from the first byte of __first1 even if we
976 // already know that it matches the first byte of __first2: this is because
977 // __first2 is most likely aligned, as it is user's "pattern" string, and
978 // __first1 + 1 is most likely not aligned, as the match is in the middle of
979 // the string.
980 if (_Traits::compare(__first1, __first2, __len2) == 0)
981 return __first1;
982
983 ++__first1;
984 }
985}
986
987template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
988inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
989__str_find(const _CharT *__p, _SizeT __sz,
990 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
991{
992 if (__pos > __sz)
993 return __npos;
994
995 if (__n == 0) // There is nothing to search, just return __pos.
996 return __pos;
997
998 const _CharT *__r = __search_substring<_CharT, _Traits>(
999 __p + __pos, __p + __sz, __s, __s + __n);
1000
1001 if (__r == __p + __sz)
1002 return __npos;
1003 return static_cast<_SizeT>(__r - __p);
1004}
1005
1006
1007// __str_rfind
1008
1009template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
1010inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1011__str_rfind(const _CharT *__p, _SizeT __sz,
1012 _CharT __c, _SizeT __pos) _NOEXCEPT
1013{
1014 if (__sz < 1)
1015 return __npos;
1016 if (__pos < __sz)
1017 ++__pos;
1018 else
1019 __pos = __sz;
1020 for (const _CharT* __ps = __p + __pos; __ps != __p;)
1021 {
1022 if (_Traits::eq(*--__ps, __c))
1023 return static_cast<_SizeT>(__ps - __p);
1024 }
1025 return __npos;
1026}
1027
1028template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
1029inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1030__str_rfind(const _CharT *__p, _SizeT __sz,
1031 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
1032{
1033 __pos = _VSTD::min(__pos, __sz);
1034 if (__n < __sz - __pos)
1035 __pos += __n;
1036 else
1037 __pos = __sz;
1038 const _CharT* __r = _VSTD::__find_end(
1039 __p, __p + __pos, __s, __s + __n, _Traits::eq,
1040 random_access_iterator_tag(), random_access_iterator_tag());
1041 if (__n > 0 && __r == __p + __pos)
1042 return __npos;
1043 return static_cast<_SizeT>(__r - __p);
1044}
1045
1046// __str_find_first_of
1047template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
1048inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1049__str_find_first_of(const _CharT *__p, _SizeT __sz,
1050 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
1051{
1052 if (__pos >= __sz || __n == 0)
1053 return __npos;
1054 const _CharT* __r = _VSTD::__find_first_of_ce
1055 (__p + __pos, __p + __sz, __s, __s + __n, _Traits::eq );
1056 if (__r == __p + __sz)
1057 return __npos;
1058 return static_cast<_SizeT>(__r - __p);
1059}
1060
1061
1062// __str_find_last_of
1063template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
1064inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1065__str_find_last_of(const _CharT *__p, _SizeT __sz,
1066 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
1067 {
1068 if (__n != 0)
1069 {
1070 if (__pos < __sz)
1071 ++__pos;
1072 else
1073 __pos = __sz;
1074 for (const _CharT* __ps = __p + __pos; __ps != __p;)
1075 {
1076 const _CharT* __r = _Traits::find(__s, __n, *--__ps);
1077 if (__r)
1078 return static_cast<_SizeT>(__ps - __p);
1079 }
1080 }
1081 return __npos;
1082}
1083
1084
1085// __str_find_first_not_of
1086template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
1087inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1088__str_find_first_not_of(const _CharT *__p, _SizeT __sz,
1089 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
1090{
1091 if (__pos < __sz)
1092 {
1093 const _CharT* __pe = __p + __sz;
1094 for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps)
1095 if (_Traits::find(__s, __n, *__ps) == nullptr)
1096 return static_cast<_SizeT>(__ps - __p);
1097 }
1098 return __npos;
1099}
1100
1101
1102template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
1103inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1104__str_find_first_not_of(const _CharT *__p, _SizeT __sz,
1105 _CharT __c, _SizeT __pos) _NOEXCEPT
1106{
1107 if (__pos < __sz)
1108 {
1109 const _CharT* __pe = __p + __sz;
1110 for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps)
1111 if (!_Traits::eq(*__ps, __c))
1112 return static_cast<_SizeT>(__ps - __p);
1113 }
1114 return __npos;
1115}
1116
1117
1118// __str_find_last_not_of
1119template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
1120inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1121__str_find_last_not_of(const _CharT *__p, _SizeT __sz,
1122 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
1123{
1124 if (__pos < __sz)
1125 ++__pos;
1126 else
1127 __pos = __sz;
1128 for (const _CharT* __ps = __p + __pos; __ps != __p;)
1129 if (_Traits::find(__s, __n, *--__ps) == nullptr)
1130 return static_cast<_SizeT>(__ps - __p);
1131 return __npos;
1132}
1133
1134
1135template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
1136inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1137__str_find_last_not_of(const _CharT *__p, _SizeT __sz,
1138 _CharT __c, _SizeT __pos) _NOEXCEPT
1139{
1140 if (__pos < __sz)
1141 ++__pos;
1142 else
1143 __pos = __sz;
1144 for (const _CharT* __ps = __p + __pos; __ps != __p;)
1145 if (!_Traits::eq(*--__ps, __c))
1146 return static_cast<_SizeT>(__ps - __p);
1147 return __npos;
1148}
1149
1150template<class _Ptr>
1151inline _LIBCPP_INLINE_VISIBILITY
1152size_t __do_string_hash(_Ptr __p, _Ptr __e)
1153{
1154 typedef typename iterator_traits<_Ptr>::value_type value_type;
1155 return __murmur2_or_cityhash<size_t>()(__p, (__e-__p)*sizeof(value_type));
1156}
1157
1158template <class _CharT, class _Iter, class _Traits=char_traits<_CharT> >
1159struct __quoted_output_proxy
1160{
1161 _Iter __first;
1162 _Iter __last;
1163 _CharT __delim;
1164 _CharT __escape;
1165
1166 __quoted_output_proxy(_Iter __f, _Iter __l, _CharT __d, _CharT __e)
1167 : __first(__f), __last(__l), __delim(__d), __escape(__e) {}
1168 // This would be a nice place for a string_ref
1169};
1170
1171_LIBCPP_END_NAMESPACE_STD
1172
1173_LIBCPP_POP_MACROS
1174
1175#endif // _LIBCPP___STRING
lib/libcxx/include/__string/char_traits.h created+927
......@@ -0,0 +1,927 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___STRING_CHAR_TRAITS_H
10#define _LIBCPP___STRING_CHAR_TRAITS_H
11
12#include <__algorithm/copy_n.h>
13#include <__algorithm/fill_n.h>
14#include <__algorithm/find_end.h>
15#include <__algorithm/find_first_of.h>
16#include <__algorithm/min.h>
17#include <__config>
18#include <__functional/hash.h>
19#include <__iterator/iterator_traits.h>
20#include <cstdint>
21#include <cstdio>
22#include <cstring>
23#include <iosfwd>
24#include <type_traits>
25
26#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
27# include <cwchar> // for wmemcpy
28#endif
29
30#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
31# pragma GCC system_header
32#endif
33
34_LIBCPP_PUSH_MACROS
35#include <__undef_macros>
36
37_LIBCPP_BEGIN_NAMESPACE_STD
38
39template <class _CharT>
40struct _LIBCPP_TEMPLATE_VIS char_traits
41{
42 typedef _CharT char_type;
43 typedef int int_type;
44 typedef streamoff off_type;
45 typedef streampos pos_type;
46 typedef mbstate_t state_type;
47
48 static inline void _LIBCPP_CONSTEXPR_AFTER_CXX14
49 assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;}
50 static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
51 {return __c1 == __c2;}
52 static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
53 {return __c1 < __c2;}
54
55 static _LIBCPP_CONSTEXPR_AFTER_CXX14
56 int compare(const char_type* __s1, const char_type* __s2, size_t __n);
57 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
58 size_t length(const char_type* __s);
59 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
60 const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
61 static _LIBCPP_CONSTEXPR_AFTER_CXX17
62 char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
63 _LIBCPP_INLINE_VISIBILITY
64 static _LIBCPP_CONSTEXPR_AFTER_CXX17
65 char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
66 _LIBCPP_INLINE_VISIBILITY
67 static _LIBCPP_CONSTEXPR_AFTER_CXX17
68 char_type* assign(char_type* __s, size_t __n, char_type __a);
69
70 static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
71 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
72 static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
73 {return char_type(__c);}
74 static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
75 {return int_type(__c);}
76 static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
77 {return __c1 == __c2;}
78 static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
79 {return int_type(EOF);}
80};
81
82template <class _CharT>
83_LIBCPP_CONSTEXPR_AFTER_CXX14 int
84char_traits<_CharT>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
85{
86 for (; __n; --__n, ++__s1, ++__s2)
87 {
88 if (lt(*__s1, *__s2))
89 return -1;
90 if (lt(*__s2, *__s1))
91 return 1;
92 }
93 return 0;
94}
95
96template <class _CharT>
97inline
98_LIBCPP_CONSTEXPR_AFTER_CXX14 size_t
99char_traits<_CharT>::length(const char_type* __s)
100{
101 size_t __len = 0;
102 for (; !eq(*__s, char_type(0)); ++__s)
103 ++__len;
104 return __len;
105}
106
107template <class _CharT>
108inline
109_LIBCPP_CONSTEXPR_AFTER_CXX14 const _CharT*
110char_traits<_CharT>::find(const char_type* __s, size_t __n, const char_type& __a)
111{
112 for (; __n; --__n)
113 {
114 if (eq(*__s, __a))
115 return __s;
116 ++__s;
117 }
118 return nullptr;
119}
120
121template <class _CharT>
122_LIBCPP_CONSTEXPR_AFTER_CXX17 _CharT*
123char_traits<_CharT>::move(char_type* __s1, const char_type* __s2, size_t __n)
124{
125 if (__n == 0) return __s1;
126 char_type* __r = __s1;
127 if (__s1 < __s2)
128 {
129 for (; __n; --__n, ++__s1, ++__s2)
130 assign(*__s1, *__s2);
131 }
132 else if (__s2 < __s1)
133 {
134 __s1 += __n;
135 __s2 += __n;
136 for (; __n; --__n)
137 assign(*--__s1, *--__s2);
138 }
139 return __r;
140}
141
142template <class _CharT>
143inline _LIBCPP_CONSTEXPR_AFTER_CXX17
144_CharT*
145char_traits<_CharT>::copy(char_type* __s1, const char_type* __s2, size_t __n)
146{
147 if (!__libcpp_is_constant_evaluated()) {
148 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
149 }
150 char_type* __r = __s1;
151 for (; __n; --__n, ++__s1, ++__s2)
152 assign(*__s1, *__s2);
153 return __r;
154}
155
156template <class _CharT>
157inline _LIBCPP_CONSTEXPR_AFTER_CXX17
158_CharT*
159char_traits<_CharT>::assign(char_type* __s, size_t __n, char_type __a)
160{
161 char_type* __r = __s;
162 for (; __n; --__n, ++__s)
163 assign(*__s, __a);
164 return __r;
165}
166
167template <class _CharT>
168static inline _LIBCPP_CONSTEXPR_AFTER_CXX17
169_CharT* __char_traits_move(_CharT* __dest, const _CharT* __source, size_t __n) _NOEXCEPT
170{
171#ifdef _LIBCPP_COMPILER_GCC
172 if (__libcpp_is_constant_evaluated()) {
173 if (__n == 0)
174 return __dest;
175 _CharT* __allocation = new _CharT[__n];
176 std::copy_n(__source, __n, __allocation);
177 std::copy_n(static_cast<const _CharT*>(__allocation), __n, __dest);
178 delete[] __allocation;
179 return __dest;
180 }
181#endif
182 ::__builtin_memmove(__dest, __source, __n * sizeof(_CharT));
183 return __dest;
184}
185
186// char_traits<char>
187
188template <>
189struct _LIBCPP_TEMPLATE_VIS char_traits<char>
190{
191 typedef char char_type;
192 typedef int int_type;
193 typedef streamoff off_type;
194 typedef streampos pos_type;
195 typedef mbstate_t state_type;
196
197 static inline _LIBCPP_CONSTEXPR_AFTER_CXX14
198 void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;}
199 static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
200 {return __c1 == __c2;}
201 static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
202 {return (unsigned char)__c1 < (unsigned char)__c2;}
203
204 static _LIBCPP_CONSTEXPR_AFTER_CXX14
205 int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
206
207 static inline size_t _LIBCPP_CONSTEXPR_AFTER_CXX14 length(const char_type* __s) _NOEXCEPT {
208 // GCC currently does not support __builtin_strlen during constant evaluation.
209 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70816
210#ifdef _LIBCPP_COMPILER_GCC
211 if (__libcpp_is_constant_evaluated()) {
212 size_t __i = 0;
213 for (; __s[__i] != char_type('\0'); ++__i)
214 ;
215 return __i;
216 }
217#endif
218 return __builtin_strlen(__s);
219 }
220
221 static _LIBCPP_CONSTEXPR_AFTER_CXX14
222 const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT;
223
224 static inline _LIBCPP_CONSTEXPR_AFTER_CXX17
225 char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT {
226 return std::__char_traits_move(__s1, __s2, __n);
227 }
228
229 static inline _LIBCPP_CONSTEXPR_AFTER_CXX17
230 char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT {
231 if (!__libcpp_is_constant_evaluated())
232 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
233 std::copy_n(__s2, __n, __s1);
234 return __s1;
235 }
236
237 static inline _LIBCPP_CONSTEXPR_AFTER_CXX17
238 char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT {
239 std::fill_n(__s, __n, __a);
240 return __s;
241 }
242
243 static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
244 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
245 static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
246 {return char_type(__c);}
247 static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
248 {return int_type((unsigned char)__c);}
249 static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
250 {return __c1 == __c2;}
251 static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
252 {return int_type(EOF);}
253};
254
255inline _LIBCPP_CONSTEXPR_AFTER_CXX14
256int
257char_traits<char>::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
258{
259 if (__n == 0)
260 return 0;
261#if __has_feature(cxx_constexpr_string_builtins)
262 return __builtin_memcmp(__s1, __s2, __n);
263#elif _LIBCPP_STD_VER <= 14
264 return _VSTD::memcmp(__s1, __s2, __n);
265#else
266 for (; __n; --__n, ++__s1, ++__s2)
267 {
268 if (lt(*__s1, *__s2))
269 return -1;
270 if (lt(*__s2, *__s1))
271 return 1;
272 }
273 return 0;
274#endif
275}
276
277inline _LIBCPP_CONSTEXPR_AFTER_CXX14
278const char*
279char_traits<char>::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT
280{
281 if (__n == 0)
282 return nullptr;
283#if __has_feature(cxx_constexpr_string_builtins)
284 return __builtin_char_memchr(__s, to_int_type(__a), __n);
285#elif _LIBCPP_STD_VER <= 14
286 return (const char_type*) _VSTD::memchr(__s, to_int_type(__a), __n);
287#else
288 for (; __n; --__n)
289 {
290 if (eq(*__s, __a))
291 return __s;
292 ++__s;
293 }
294 return nullptr;
295#endif
296}
297
298
299// char_traits<wchar_t>
300
301#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
302template <>
303struct _LIBCPP_TEMPLATE_VIS char_traits<wchar_t>
304{
305 typedef wchar_t char_type;
306 typedef wint_t int_type;
307 typedef streamoff off_type;
308 typedef streampos pos_type;
309 typedef mbstate_t state_type;
310
311 static inline _LIBCPP_CONSTEXPR_AFTER_CXX14
312 void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;}
313 static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
314 {return __c1 == __c2;}
315 static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
316 {return __c1 < __c2;}
317
318 static _LIBCPP_CONSTEXPR_AFTER_CXX14
319 int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
320 static _LIBCPP_CONSTEXPR_AFTER_CXX14
321 size_t length(const char_type* __s) _NOEXCEPT;
322 static _LIBCPP_CONSTEXPR_AFTER_CXX14
323 const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT;
324
325 static inline _LIBCPP_CONSTEXPR_AFTER_CXX17
326 char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT {
327 return std::__char_traits_move(__s1, __s2, __n);
328 }
329
330 static inline _LIBCPP_CONSTEXPR_AFTER_CXX17
331 char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT {
332 if (!__libcpp_is_constant_evaluated())
333 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
334 std::copy_n(__s2, __n, __s1);
335 return __s1;
336 }
337
338 static inline _LIBCPP_CONSTEXPR_AFTER_CXX17
339 char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT {
340 std::fill_n(__s, __n, __a);
341 return __s;
342 }
343
344 static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
345 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
346 static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
347 {return char_type(__c);}
348 static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
349 {return int_type(__c);}
350 static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
351 {return __c1 == __c2;}
352 static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
353 {return int_type(WEOF);}
354};
355
356inline _LIBCPP_CONSTEXPR_AFTER_CXX14
357int
358char_traits<wchar_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
359{
360 if (__n == 0)
361 return 0;
362#if __has_feature(cxx_constexpr_string_builtins)
363 return __builtin_wmemcmp(__s1, __s2, __n);
364#elif _LIBCPP_STD_VER <= 14
365 return _VSTD::wmemcmp(__s1, __s2, __n);
366#else
367 for (; __n; --__n, ++__s1, ++__s2)
368 {
369 if (lt(*__s1, *__s2))
370 return -1;
371 if (lt(*__s2, *__s1))
372 return 1;
373 }
374 return 0;
375#endif
376}
377
378inline _LIBCPP_CONSTEXPR_AFTER_CXX14
379size_t
380char_traits<wchar_t>::length(const char_type* __s) _NOEXCEPT
381{
382#if __has_feature(cxx_constexpr_string_builtins)
383 return __builtin_wcslen(__s);
384#elif _LIBCPP_STD_VER <= 14
385 return _VSTD::wcslen(__s);
386#else
387 size_t __len = 0;
388 for (; !eq(*__s, char_type(0)); ++__s)
389 ++__len;
390 return __len;
391#endif
392}
393
394inline _LIBCPP_CONSTEXPR_AFTER_CXX14
395const wchar_t*
396char_traits<wchar_t>::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT
397{
398 if (__n == 0)
399 return nullptr;
400#if __has_feature(cxx_constexpr_string_builtins)
401 return __builtin_wmemchr(__s, __a, __n);
402#elif _LIBCPP_STD_VER <= 14
403 return _VSTD::wmemchr(__s, __a, __n);
404#else
405 for (; __n; --__n)
406 {
407 if (eq(*__s, __a))
408 return __s;
409 ++__s;
410 }
411 return nullptr;
412#endif
413}
414#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
415
416#ifndef _LIBCPP_HAS_NO_CHAR8_T
417
418template <>
419struct _LIBCPP_TEMPLATE_VIS char_traits<char8_t>
420{
421 typedef char8_t char_type;
422 typedef unsigned int int_type;
423 typedef streamoff off_type;
424 typedef u8streampos pos_type;
425 typedef mbstate_t state_type;
426
427 static inline constexpr void assign(char_type& __c1, const char_type& __c2) noexcept
428 {__c1 = __c2;}
429 static inline constexpr bool eq(char_type __c1, char_type __c2) noexcept
430 {return __c1 == __c2;}
431 static inline constexpr bool lt(char_type __c1, char_type __c2) noexcept
432 {return __c1 < __c2;}
433
434 static constexpr
435 int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
436
437 static constexpr
438 size_t length(const char_type* __s) _NOEXCEPT;
439
440 _LIBCPP_INLINE_VISIBILITY static constexpr
441 const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT;
442
443 static _LIBCPP_CONSTEXPR_AFTER_CXX17
444 char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT {
445 return std::__char_traits_move(__s1, __s2, __n);
446 }
447
448 static _LIBCPP_CONSTEXPR_AFTER_CXX17
449 char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT {
450 if (!__libcpp_is_constant_evaluated())
451 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
452 std::copy_n(__s2, __n, __s1);
453 return __s1;
454 }
455
456 static _LIBCPP_CONSTEXPR_AFTER_CXX17
457 char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT {
458 std::fill_n(__s, __n, __a);
459 return __s;
460 }
461
462 static inline constexpr int_type not_eof(int_type __c) noexcept
463 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
464 static inline constexpr char_type to_char_type(int_type __c) noexcept
465 {return char_type(__c);}
466 static inline constexpr int_type to_int_type(char_type __c) noexcept
467 {return int_type(__c);}
468 static inline constexpr bool eq_int_type(int_type __c1, int_type __c2) noexcept
469 {return __c1 == __c2;}
470 static inline constexpr int_type eof() noexcept
471 {return int_type(EOF);}
472};
473
474// TODO use '__builtin_strlen' if it ever supports char8_t ??
475inline constexpr
476size_t
477char_traits<char8_t>::length(const char_type* __s) _NOEXCEPT
478{
479 size_t __len = 0;
480 for (; !eq(*__s, char_type(0)); ++__s)
481 ++__len;
482 return __len;
483}
484
485inline constexpr
486int
487char_traits<char8_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
488{
489#if __has_feature(cxx_constexpr_string_builtins)
490 return __builtin_memcmp(__s1, __s2, __n);
491#else
492 for (; __n; --__n, ++__s1, ++__s2)
493 {
494 if (lt(*__s1, *__s2))
495 return -1;
496 if (lt(*__s2, *__s1))
497 return 1;
498 }
499 return 0;
500#endif
501}
502
503// TODO use '__builtin_char_memchr' if it ever supports char8_t ??
504inline constexpr
505const char8_t*
506char_traits<char8_t>::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT
507{
508 for (; __n; --__n)
509 {
510 if (eq(*__s, __a))
511 return __s;
512 ++__s;
513 }
514 return nullptr;
515}
516
517#endif // _LIBCPP_HAS_NO_CHAR8_T
518
519template <>
520struct _LIBCPP_TEMPLATE_VIS char_traits<char16_t>
521{
522 typedef char16_t char_type;
523 typedef uint_least16_t int_type;
524 typedef streamoff off_type;
525 typedef u16streampos pos_type;
526 typedef mbstate_t state_type;
527
528 static inline _LIBCPP_CONSTEXPR_AFTER_CXX14
529 void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;}
530 static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
531 {return __c1 == __c2;}
532 static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
533 {return __c1 < __c2;}
534
535 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
536 int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
537 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
538 size_t length(const char_type* __s) _NOEXCEPT;
539 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
540 const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT;
541
542 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
543 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT {
544 return std::__char_traits_move(__s1, __s2, __n);
545 }
546
547 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
548 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT {
549 if (!__libcpp_is_constant_evaluated())
550 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
551 std::copy_n(__s2, __n, __s1);
552 return __s1;
553 }
554
555 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
556 static char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT {
557 std::fill_n(__s, __n, __a);
558 return __s;
559 }
560
561 static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
562 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
563 static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
564 {return char_type(__c);}
565 static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
566 {return int_type(__c);}
567 static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
568 {return __c1 == __c2;}
569 static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
570 {return int_type(0xFFFF);}
571};
572
573inline _LIBCPP_CONSTEXPR_AFTER_CXX14
574int
575char_traits<char16_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
576{
577 for (; __n; --__n, ++__s1, ++__s2)
578 {
579 if (lt(*__s1, *__s2))
580 return -1;
581 if (lt(*__s2, *__s1))
582 return 1;
583 }
584 return 0;
585}
586
587inline _LIBCPP_CONSTEXPR_AFTER_CXX14
588size_t
589char_traits<char16_t>::length(const char_type* __s) _NOEXCEPT
590{
591 size_t __len = 0;
592 for (; !eq(*__s, char_type(0)); ++__s)
593 ++__len;
594 return __len;
595}
596
597inline _LIBCPP_CONSTEXPR_AFTER_CXX14
598const char16_t*
599char_traits<char16_t>::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT
600{
601 for (; __n; --__n)
602 {
603 if (eq(*__s, __a))
604 return __s;
605 ++__s;
606 }
607 return nullptr;
608}
609
610template <>
611struct _LIBCPP_TEMPLATE_VIS char_traits<char32_t>
612{
613 typedef char32_t char_type;
614 typedef uint_least32_t int_type;
615 typedef streamoff off_type;
616 typedef u32streampos pos_type;
617 typedef mbstate_t state_type;
618
619 static inline _LIBCPP_CONSTEXPR_AFTER_CXX14
620 void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;}
621 static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
622 {return __c1 == __c2;}
623 static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
624 {return __c1 < __c2;}
625
626 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
627 int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
628 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
629 size_t length(const char_type* __s) _NOEXCEPT;
630 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
631 const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT;
632
633 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
634 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT {
635 return std::__char_traits_move(__s1, __s2, __n);
636 }
637
638 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
639 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT {
640 std::copy_n(__s2, __n, __s1);
641 return __s1;
642 }
643
644 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
645 static char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT {
646 std::fill_n(__s, __n, __a);
647 return __s;
648 }
649
650 static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
651 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
652 static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
653 {return char_type(__c);}
654 static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
655 {return int_type(__c);}
656 static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
657 {return __c1 == __c2;}
658 static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
659 {return int_type(0xFFFFFFFF);}
660};
661
662inline _LIBCPP_CONSTEXPR_AFTER_CXX14
663int
664char_traits<char32_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
665{
666 for (; __n; --__n, ++__s1, ++__s2)
667 {
668 if (lt(*__s1, *__s2))
669 return -1;
670 if (lt(*__s2, *__s1))
671 return 1;
672 }
673 return 0;
674}
675
676inline _LIBCPP_CONSTEXPR_AFTER_CXX14
677size_t
678char_traits<char32_t>::length(const char_type* __s) _NOEXCEPT
679{
680 size_t __len = 0;
681 for (; !eq(*__s, char_type(0)); ++__s)
682 ++__len;
683 return __len;
684}
685
686inline _LIBCPP_CONSTEXPR_AFTER_CXX14
687const char32_t*
688char_traits<char32_t>::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT
689{
690 for (; __n; --__n)
691 {
692 if (eq(*__s, __a))
693 return __s;
694 ++__s;
695 }
696 return nullptr;
697}
698
699// helper fns for basic_string and string_view
700
701// __str_find
702template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
703inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
704__str_find(const _CharT *__p, _SizeT __sz,
705 _CharT __c, _SizeT __pos) _NOEXCEPT
706{
707 if (__pos >= __sz)
708 return __npos;
709 const _CharT* __r = _Traits::find(__p + __pos, __sz - __pos, __c);
710 if (__r == nullptr)
711 return __npos;
712 return static_cast<_SizeT>(__r - __p);
713}
714
715template <class _CharT, class _Traits>
716inline _LIBCPP_CONSTEXPR_AFTER_CXX11 const _CharT *
717__search_substring(const _CharT *__first1, const _CharT *__last1,
718 const _CharT *__first2, const _CharT *__last2) _NOEXCEPT {
719 // Take advantage of knowing source and pattern lengths.
720 // Stop short when source is smaller than pattern.
721 const ptrdiff_t __len2 = __last2 - __first2;
722 if (__len2 == 0)
723 return __first1;
724
725 ptrdiff_t __len1 = __last1 - __first1;
726 if (__len1 < __len2)
727 return __last1;
728
729 // First element of __first2 is loop invariant.
730 _CharT __f2 = *__first2;
731 while (true) {
732 __len1 = __last1 - __first1;
733 // Check whether __first1 still has at least __len2 bytes.
734 if (__len1 < __len2)
735 return __last1;
736
737 // Find __f2 the first byte matching in __first1.
738 __first1 = _Traits::find(__first1, __len1 - __len2 + 1, __f2);
739 if (__first1 == nullptr)
740 return __last1;
741
742 // It is faster to compare from the first byte of __first1 even if we
743 // already know that it matches the first byte of __first2: this is because
744 // __first2 is most likely aligned, as it is user's "pattern" string, and
745 // __first1 + 1 is most likely not aligned, as the match is in the middle of
746 // the string.
747 if (_Traits::compare(__first1, __first2, __len2) == 0)
748 return __first1;
749
750 ++__first1;
751 }
752}
753
754template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
755inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
756__str_find(const _CharT *__p, _SizeT __sz,
757 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
758{
759 if (__pos > __sz)
760 return __npos;
761
762 if (__n == 0) // There is nothing to search, just return __pos.
763 return __pos;
764
765 const _CharT *__r = __search_substring<_CharT, _Traits>(
766 __p + __pos, __p + __sz, __s, __s + __n);
767
768 if (__r == __p + __sz)
769 return __npos;
770 return static_cast<_SizeT>(__r - __p);
771}
772
773
774// __str_rfind
775
776template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
777inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
778__str_rfind(const _CharT *__p, _SizeT __sz,
779 _CharT __c, _SizeT __pos) _NOEXCEPT
780{
781 if (__sz < 1)
782 return __npos;
783 if (__pos < __sz)
784 ++__pos;
785 else
786 __pos = __sz;
787 for (const _CharT* __ps = __p + __pos; __ps != __p;)
788 {
789 if (_Traits::eq(*--__ps, __c))
790 return static_cast<_SizeT>(__ps - __p);
791 }
792 return __npos;
793}
794
795template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
796inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
797__str_rfind(const _CharT *__p, _SizeT __sz,
798 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
799{
800 __pos = _VSTD::min(__pos, __sz);
801 if (__n < __sz - __pos)
802 __pos += __n;
803 else
804 __pos = __sz;
805 const _CharT* __r = std::__find_end_classic(__p, __p + __pos, __s, __s + __n, _Traits::eq);
806 if (__n > 0 && __r == __p + __pos)
807 return __npos;
808 return static_cast<_SizeT>(__r - __p);
809}
810
811// __str_find_first_of
812template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
813inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
814__str_find_first_of(const _CharT *__p, _SizeT __sz,
815 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
816{
817 if (__pos >= __sz || __n == 0)
818 return __npos;
819 const _CharT* __r = _VSTD::__find_first_of_ce
820 (__p + __pos, __p + __sz, __s, __s + __n, _Traits::eq );
821 if (__r == __p + __sz)
822 return __npos;
823 return static_cast<_SizeT>(__r - __p);
824}
825
826
827// __str_find_last_of
828template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
829inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
830__str_find_last_of(const _CharT *__p, _SizeT __sz,
831 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
832 {
833 if (__n != 0)
834 {
835 if (__pos < __sz)
836 ++__pos;
837 else
838 __pos = __sz;
839 for (const _CharT* __ps = __p + __pos; __ps != __p;)
840 {
841 const _CharT* __r = _Traits::find(__s, __n, *--__ps);
842 if (__r)
843 return static_cast<_SizeT>(__ps - __p);
844 }
845 }
846 return __npos;
847}
848
849
850// __str_find_first_not_of
851template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
852inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
853__str_find_first_not_of(const _CharT *__p, _SizeT __sz,
854 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
855{
856 if (__pos < __sz)
857 {
858 const _CharT* __pe = __p + __sz;
859 for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps)
860 if (_Traits::find(__s, __n, *__ps) == nullptr)
861 return static_cast<_SizeT>(__ps - __p);
862 }
863 return __npos;
864}
865
866
867template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
868inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
869__str_find_first_not_of(const _CharT *__p, _SizeT __sz,
870 _CharT __c, _SizeT __pos) _NOEXCEPT
871{
872 if (__pos < __sz)
873 {
874 const _CharT* __pe = __p + __sz;
875 for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps)
876 if (!_Traits::eq(*__ps, __c))
877 return static_cast<_SizeT>(__ps - __p);
878 }
879 return __npos;
880}
881
882
883// __str_find_last_not_of
884template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
885inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
886__str_find_last_not_of(const _CharT *__p, _SizeT __sz,
887 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
888{
889 if (__pos < __sz)
890 ++__pos;
891 else
892 __pos = __sz;
893 for (const _CharT* __ps = __p + __pos; __ps != __p;)
894 if (_Traits::find(__s, __n, *--__ps) == nullptr)
895 return static_cast<_SizeT>(__ps - __p);
896 return __npos;
897}
898
899
900template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
901inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
902__str_find_last_not_of(const _CharT *__p, _SizeT __sz,
903 _CharT __c, _SizeT __pos) _NOEXCEPT
904{
905 if (__pos < __sz)
906 ++__pos;
907 else
908 __pos = __sz;
909 for (const _CharT* __ps = __p + __pos; __ps != __p;)
910 if (!_Traits::eq(*--__ps, __c))
911 return static_cast<_SizeT>(__ps - __p);
912 return __npos;
913}
914
915template<class _Ptr>
916inline _LIBCPP_INLINE_VISIBILITY
917size_t __do_string_hash(_Ptr __p, _Ptr __e)
918{
919 typedef typename iterator_traits<_Ptr>::value_type value_type;
920 return __murmur2_or_cityhash<size_t>()(__p, (__e-__p)*sizeof(value_type));
921}
922
923_LIBCPP_END_NAMESPACE_STD
924
925_LIBCPP_POP_MACROS
926
927#endif // _LIBCPP___STRING_CHAR_TRAITS_H
lib/libcxx/include/__string/extern_template_lists.h created+131
......@@ -0,0 +1,131 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___STRING_EXTERN_TEMPLATE_LISTS_H
10#define _LIBCPP___STRING_EXTERN_TEMPLATE_LISTS_H
11
12#include <__config>
13
14#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15# pragma GCC system_header
16#endif
17
18// We maintain 2 ABI lists:
19// - _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST
20// - _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST
21// As the name implies, the ABI lists define the V1 (Stable) and unstable ABI.
22//
23// For unstable, we may explicitly remove function that are external in V1,
24// and add (new) external functions to better control inlining and compiler
25// optimization opportunities.
26//
27// For stable, the ABI list should rarely change, except for adding new
28// functions supporting new c++ version / API changes. Typically entries
29// must never be removed from the stable list.
30#define _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_Func, _CharType) \
31 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, value_type const*, size_type)) \
32 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::rfind(value_type const*, size_type, size_type) const) \
33 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__init(value_type const*, size_type, size_type)) \
34 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::basic_string(basic_string const&)) \
35 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, value_type const*)) \
36 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::basic_string(basic_string const&, allocator<_CharType> const&)) \
37 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find_last_not_of(value_type const*, size_type, size_type) const) \
38 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::~basic_string()) \
39 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find_first_not_of(value_type const*, size_type, size_type) const) \
40 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::insert(size_type, size_type, value_type)) \
41 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::operator=(value_type)) \
42 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__init(value_type const*, size_type)) \
43 _Func(_LIBCPP_FUNC_VIS const _CharType& basic_string<_CharType>::at(size_type) const) \
44 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::insert(size_type, value_type const*, size_type)) \
45 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find_first_of(value_type const*, size_type, size_type) const) \
46 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, size_type, value_type)) \
47 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::assign(value_type const*, size_type)) \
48 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::reserve(size_type)) \
49 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::append(value_type const*, size_type)) \
50 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::assign(basic_string const&, size_type, size_type)) \
51 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::copy(value_type*, size_type, size_type) const) \
52 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::basic_string(basic_string const&, size_type, size_type, allocator<_CharType> const&)) \
53 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find(value_type, size_type) const) \
54 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__init(size_type, value_type)) \
55 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::insert(size_type, value_type const*)) \
56 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find_last_of(value_type const*, size_type, size_type) const) \
57 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__grow_by(size_type, size_type, size_type, size_type, size_type, size_type)) \
58 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__grow_by_and_replace(size_type, size_type, size_type, size_type, size_type, size_type, value_type const*)) \
59 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::push_back(value_type)) \
60 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::append(size_type, value_type)) \
61 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::rfind(value_type, size_type) const) \
62 _Func(_LIBCPP_FUNC_VIS const basic_string<_CharType>::size_type basic_string<_CharType>::npos) \
63 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::assign(size_type, value_type)) \
64 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::erase(size_type, size_type)) \
65 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::append(basic_string const&, size_type, size_type)) \
66 _Func(_LIBCPP_FUNC_VIS int basic_string<_CharType>::compare(value_type const*) const) \
67 _Func(_LIBCPP_FUNC_VIS int basic_string<_CharType>::compare(size_type, size_type, value_type const*) const) \
68 _Func(_LIBCPP_FUNC_VIS _CharType& basic_string<_CharType>::at(size_type)) \
69 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::assign(value_type const*)) \
70 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find(value_type const*, size_type, size_type) const) \
71 _Func(_LIBCPP_FUNC_VIS int basic_string<_CharType>::compare(size_type, size_type, basic_string const&, size_type, size_type) const) \
72 _Func(_LIBCPP_FUNC_VIS int basic_string<_CharType>::compare(size_type, size_type, value_type const*, size_type) const) \
73 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::operator=(basic_string const&)) \
74 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::append(value_type const*)) \
75 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, basic_string const&, size_type, size_type)) \
76 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::iterator basic_string<_CharType>::insert(basic_string::const_iterator, value_type)) \
77 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::resize(size_type, value_type)) \
78 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::insert(size_type, basic_string const&, size_type, size_type))
79
80#define _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_Func, _CharType) \
81 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, value_type const*, size_type)) \
82 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::rfind(value_type const*, size_type, size_type) const) \
83 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__init(value_type const*, size_type, size_type)) \
84 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, value_type const*)) \
85 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find_last_not_of(value_type const*, size_type, size_type) const) \
86 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::~basic_string()) \
87 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find_first_not_of(value_type const*, size_type, size_type) const) \
88 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::insert(size_type, size_type, value_type)) \
89 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::operator=(value_type)) \
90 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__init(value_type const*, size_type)) \
91 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__init_copy_ctor_external(value_type const*, size_type)) \
92 _Func(_LIBCPP_FUNC_VIS const _CharType& basic_string<_CharType>::at(size_type) const) \
93 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::insert(size_type, value_type const*, size_type)) \
94 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find_first_of(value_type const*, size_type, size_type) const) \
95 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, size_type, value_type)) \
96 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::__assign_external(value_type const*, size_type)) \
97 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::__assign_external(value_type const*)) \
98 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::reserve(size_type)) \
99 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::append(value_type const*, size_type)) \
100 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::assign(basic_string const&, size_type, size_type)) \
101 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::copy(value_type*, size_type, size_type) const) \
102 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::basic_string(basic_string const&, size_type, size_type, allocator<_CharType> const&)) \
103 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find(value_type, size_type) const) \
104 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__init(size_type, value_type)) \
105 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::insert(size_type, value_type const*)) \
106 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find_last_of(value_type const*, size_type, size_type) const) \
107 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__grow_by(size_type, size_type, size_type, size_type, size_type, size_type)) \
108 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__grow_by_and_replace(size_type, size_type, size_type, size_type, size_type, size_type, value_type const*)) \
109 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::__assign_no_alias<false>(value_type const*, size_type)) \
110 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::__assign_no_alias<true>(value_type const*, size_type)) \
111 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::push_back(value_type)) \
112 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::append(size_type, value_type)) \
113 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::rfind(value_type, size_type) const) \
114 _Func(_LIBCPP_FUNC_VIS const basic_string<_CharType>::size_type basic_string<_CharType>::npos) \
115 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::assign(size_type, value_type)) \
116 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__erase_external_with_move(size_type, size_type)) \
117 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::append(basic_string const&, size_type, size_type)) \
118 _Func(_LIBCPP_FUNC_VIS int basic_string<_CharType>::compare(value_type const*) const) \
119 _Func(_LIBCPP_FUNC_VIS int basic_string<_CharType>::compare(size_type, size_type, value_type const*) const) \
120 _Func(_LIBCPP_FUNC_VIS _CharType& basic_string<_CharType>::at(size_type)) \
121 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find(value_type const*, size_type, size_type) const) \
122 _Func(_LIBCPP_FUNC_VIS int basic_string<_CharType>::compare(size_type, size_type, basic_string const&, size_type, size_type) const) \
123 _Func(_LIBCPP_FUNC_VIS int basic_string<_CharType>::compare(size_type, size_type, value_type const*, size_type) const) \
124 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::append(value_type const*)) \
125 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, basic_string const&, size_type, size_type)) \
126 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::iterator basic_string<_CharType>::insert(basic_string::const_iterator, value_type)) \
127 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::resize(size_type, value_type)) \
128 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::insert(size_type, basic_string const&, size_type, size_type))
129
130
131#endif // _LIBCPP___STRING_EXTERN_TEMPLATE_LISTS_H
lib/libcxx/include/__support/android/locale_bionic.h+13-7
......@@ -26,10 +26,15 @@ extern "C" {
2626#if defined(__ANDROID__)
2727
2828#include <android/api-level.h>
29#include <android/ndk-version.h>
3029#if __ANDROID_API__ < 21
3130#include <__support/xlocale/__posix_l_fallback.h>
3231#endif
32
33// If we do not have this header, we are in a platform build rather than an NDK
34// build, which will always be at least as new as the ToT NDK, in which case we
35// don't need any of the inlines below since libc provides them.
36#if __has_include(<android/ndk-version.h>)
37#include <android/ndk-version.h>
3338// In NDK versions later than 16, locale-aware functions are provided by
3439// legacy_stdlib_inlines.h
3540#if __NDK_MAJOR__ <= 16
......@@ -41,18 +46,18 @@ extern "C" {
4146extern "C" {
4247#endif
4348
44inline _LIBCPP_INLINE_VISIBILITY float strtof_l(const char* __nptr, char** __endptr,
45 locale_t) {
49inline _LIBCPP_HIDE_FROM_ABI float
50strtof_l(const char* __nptr, char** __endptr, locale_t) {
4651 return ::strtof(__nptr, __endptr);
4752}
4853
49inline _LIBCPP_INLINE_VISIBILITY double strtod_l(const char* __nptr,
50 char** __endptr, locale_t) {
54inline _LIBCPP_HIDE_FROM_ABI double
55strtod_l(const char* __nptr, char** __endptr, locale_t) {
5156 return ::strtod(__nptr, __endptr);
5257}
5358
54inline _LIBCPP_INLINE_VISIBILITY long strtol_l(const char* __nptr, char** __endptr,
55 int __base, locale_t) {
59inline _LIBCPP_HIDE_FROM_ABI long
60strtol_l(const char* __nptr, char** __endptr, int __base, locale_t) {
5661 return ::strtol(__nptr, __endptr, __base);
5762}
5863
......@@ -63,6 +68,7 @@ inline _LIBCPP_INLINE_VISIBILITY long strtol_l(const char* __nptr, char** __endp
6368#endif // __ANDROID_API__ < 26
6469
6570#endif // __NDK_MAJOR__ <= 16
71#endif // __has_include(<android/ndk-version.h>)
6672#endif // defined(__ANDROID__)
6773
6874#endif // defined(__BIONIC__)
lib/libcxx/include/__support/ibm/gettod_zos.h+2-1
......@@ -12,7 +12,8 @@
1212
1313#include <time.h>
1414
15static inline int gettimeofdayMonotonic(struct timespec64* Output) {
15inline _LIBCPP_HIDE_FROM_ABI int
16gettimeofdayMonotonic(struct timespec64* Output) {
1617
1718 // The POSIX gettimeofday() function is not available on z/OS. Therefore,
1819 // we will call stcke and other hardware instructions in implement equivalent.
lib/libcxx/include/__support/ibm/limits.h deleted-98
......@@ -1,98 +0,0 @@
1// -*- C++ -*-
2//===-----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_SUPPORT_IBM_LIMITS_H
11#define _LIBCPP_SUPPORT_IBM_LIMITS_H
12
13#if !defined(_AIX) // Linux
14#include <math.h> // for HUGE_VAL, HUGE_VALF, HUGE_VALL, and NAN
15
16static const unsigned int _QNAN_F = 0x7fc00000;
17#define NANF (*((float *)(&_QNAN_F)))
18static const unsigned int _QNAN_LDBL128[4] = {0x7ff80000, 0x0, 0x0, 0x0};
19#define NANL (*((long double *)(&_QNAN_LDBL128)))
20static const unsigned int _SNAN_F= 0x7f855555;
21#define NANSF (*((float *)(&_SNAN_F)))
22static const unsigned int _SNAN_D[2] = {0x7ff55555, 0x55555555};
23#define NANS (*((double *)(&_SNAN_D)))
24static const unsigned int _SNAN_LDBL128[4] = {0x7ff55555, 0x55555555, 0x0, 0x0};
25#define NANSL (*((long double *)(&_SNAN_LDBL128)))
26
27#define __builtin_huge_val() HUGE_VAL
28#define __builtin_huge_valf() HUGE_VALF
29#define __builtin_huge_vall() HUGE_VALL
30#define __builtin_nan(__dummy) NAN
31#define __builtin_nanf(__dummy) NANF
32#define __builtin_nanl(__dummy) NANL
33#define __builtin_nans(__dummy) NANS
34#define __builtin_nansf(__dummy) NANSF
35#define __builtin_nansl(__dummy) NANSL
36
37#else
38
39#include <math.h>
40#include <float.h> // limit constants
41
42#define __builtin_huge_val() HUGE_VAL //0x7ff0000000000000
43#define __builtin_huge_valf() HUGE_VALF //0x7f800000
44#define __builtin_huge_vall() HUGE_VALL //0x7ff0000000000000
45#define __builtin_nan(__dummy) nan(__dummy) //0x7ff8000000000000
46#define __builtin_nanf(__dummy) nanf(__dummy) // 0x7ff80000
47#define __builtin_nanl(__dummy) nanl(__dummy) //0x7ff8000000000000
48#define __builtin_nans(__dummy) DBL_SNAN //0x7ff5555555555555
49#define __builtin_nansf(__dummy) FLT_SNAN //0x7f855555
50#define __builtin_nansl(__dummy) DBL_SNAN //0x7ff5555555555555
51
52#define __FLT_MANT_DIG__ FLT_MANT_DIG
53#define __FLT_DIG__ FLT_DIG
54#define __FLT_RADIX__ FLT_RADIX
55#define __FLT_MIN_EXP__ FLT_MIN_EXP
56#define __FLT_MIN_10_EXP__ FLT_MIN_10_EXP
57#define __FLT_MAX_EXP__ FLT_MAX_EXP
58#define __FLT_MAX_10_EXP__ FLT_MAX_10_EXP
59#define __FLT_MIN__ FLT_MIN
60#define __FLT_MAX__ FLT_MAX
61#define __FLT_EPSILON__ FLT_EPSILON
62// predefined by XLC on LoP
63#define __FLT_DENORM_MIN__ 1.40129846e-45F
64
65#define __DBL_MANT_DIG__ DBL_MANT_DIG
66#define __DBL_DIG__ DBL_DIG
67#define __DBL_MIN_EXP__ DBL_MIN_EXP
68#define __DBL_MIN_10_EXP__ DBL_MIN_10_EXP
69#define __DBL_MAX_EXP__ DBL_MAX_EXP
70#define __DBL_MAX_10_EXP__ DBL_MAX_10_EXP
71#define __DBL_MIN__ DBL_MIN
72#define __DBL_MAX__ DBL_MAX
73#define __DBL_EPSILON__ DBL_EPSILON
74// predefined by XLC on LoP
75#define __DBL_DENORM_MIN__ 4.9406564584124654e-324
76
77#define __LDBL_MANT_DIG__ LDBL_MANT_DIG
78#define __LDBL_DIG__ LDBL_DIG
79#define __LDBL_MIN_EXP__ LDBL_MIN_EXP
80#define __LDBL_MIN_10_EXP__ LDBL_MIN_10_EXP
81#define __LDBL_MAX_EXP__ LDBL_MAX_EXP
82#define __LDBL_MAX_10_EXP__ LDBL_MAX_10_EXP
83#define __LDBL_MIN__ LDBL_MIN
84#define __LDBL_MAX__ LDBL_MAX
85#define __LDBL_EPSILON__ LDBL_EPSILON
86// predefined by XLC on LoP
87#if __LONGDOUBLE128
88#define __LDBL_DENORM_MIN__ 4.94065645841246544176568792868221e-324L
89#else
90#define __LDBL_DENORM_MIN__ 4.9406564584124654e-324L
91#endif
92
93// predefined by XLC on LoP
94#define __CHAR_BIT__ 8
95
96#endif // _AIX
97
98#endif // _LIBCPP_SUPPORT_IBM_LIMITS_H
lib/libcxx/include/__support/ibm/support.h deleted-53
......@@ -1,53 +0,0 @@
1// -*- C++ -*-
2//===-----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_SUPPORT_IBM_SUPPORT_H
11#define _LIBCPP_SUPPORT_IBM_SUPPORT_H
12
13extern "builtin" int __popcnt4(unsigned int);
14extern "builtin" int __popcnt8(unsigned long long);
15extern "builtin" unsigned int __cnttz4(unsigned int);
16extern "builtin" unsigned int __cnttz8(unsigned long long);
17extern "builtin" unsigned int __cntlz4(unsigned int);
18extern "builtin" unsigned int __cntlz8(unsigned long long);
19
20// Builtin functions for counting population
21#define __builtin_popcount(x) __popcnt4(x)
22#define __builtin_popcountll(x) __popcnt8(x)
23#if defined(__64BIT__)
24#define __builtin_popcountl(x) __builtin_popcountll(x)
25#else
26#define __builtin_popcountl(x) __builtin_popcount(x)
27#endif
28
29// Builtin functions for counting trailing zeros
30#define __builtin_ctz(x) __cnttz4(x)
31#define __builtin_ctzll(x) __cnttz8(x)
32#if defined(__64BIT__)
33#define __builtin_ctzl(x) __builtin_ctzll(x)
34#else
35#define __builtin_ctzl(x) __builtin_ctz(x)
36#endif
37
38// Builtin functions for counting leading zeros
39#define __builtin_clz(x) __cntlz4(x)
40#define __builtin_clzll(x) __cntlz8(x)
41#if defined(__64BIT__)
42#define __builtin_clzl(x) __builtin_clzll(x)
43#else
44#define __builtin_clzl(x) __builtin_clz(x)
45#endif
46
47#if defined(__64BIT__)
48#define __SIZE_WIDTH__ 64
49#else
50#define __SIZE_WIDTH__ 32
51#endif
52
53#endif // _LIBCPP_SUPPORT_IBM_SUPPORT_H
lib/libcxx/include/__support/ibm/xlocale.h+26-30
......@@ -10,7 +10,10 @@
1010#ifndef _LIBCPP_SUPPORT_IBM_XLOCALE_H
1111#define _LIBCPP_SUPPORT_IBM_XLOCALE_H
1212
13#if defined(__MVS__)
1314#include <__support/ibm/locale_mgmt_zos.h>
15#endif // defined(__MVS__)
16
1417#include <stdarg.h>
1518
1619#include "cstdlib"
......@@ -52,57 +55,50 @@ private:
5255
5356// The following are not POSIX routines. These are quick-and-dirty hacks
5457// to make things pretend to work
55static inline
56long long strtoll_l(const char *__nptr, char **__endptr,
57 int __base, locale_t locale) {
58inline _LIBCPP_HIDE_FROM_ABI long long
59strtoll_l(const char *__nptr, char **__endptr, int __base, locale_t locale) {
5860 __setAndRestore __newloc(locale);
59 return strtoll(__nptr, __endptr, __base);
61 return ::strtoll(__nptr, __endptr, __base);
6062}
6163
62static inline
63long strtol_l(const char *__nptr, char **__endptr,
64 int __base, locale_t locale) {
64inline _LIBCPP_HIDE_FROM_ABI long
65strtol_l(const char *__nptr, char **__endptr, int __base, locale_t locale) {
6566 __setAndRestore __newloc(locale);
66 return strtol(__nptr, __endptr, __base);
67 return ::strtol(__nptr, __endptr, __base);
6768}
6869
69static inline
70double strtod_l(const char *__nptr, char **__endptr,
71 locale_t locale) {
70inline _LIBCPP_HIDE_FROM_ABI double
71strtod_l(const char *__nptr, char **__endptr, locale_t locale) {
7272 __setAndRestore __newloc(locale);
73 return strtod(__nptr, __endptr);
73 return ::strtod(__nptr, __endptr);
7474}
7575
76static inline
77float strtof_l(const char *__nptr, char **__endptr,
78 locale_t locale) {
76inline _LIBCPP_HIDE_FROM_ABI float
77strtof_l(const char *__nptr, char **__endptr, locale_t locale) {
7978 __setAndRestore __newloc(locale);
80 return strtof(__nptr, __endptr);
79 return ::strtof(__nptr, __endptr);
8180}
8281
83static inline
84long double strtold_l(const char *__nptr, char **__endptr,
85 locale_t locale) {
82inline _LIBCPP_HIDE_FROM_ABI long double
83strtold_l(const char *__nptr, char **__endptr, locale_t locale) {
8684 __setAndRestore __newloc(locale);
87 return strtold(__nptr, __endptr);
85 return ::strtold(__nptr, __endptr);
8886}
8987
90static inline
91unsigned long long strtoull_l(const char *__nptr, char **__endptr,
92 int __base, locale_t locale) {
88inline _LIBCPP_HIDE_FROM_ABI unsigned long long
89strtoull_l(const char *__nptr, char **__endptr, int __base, locale_t locale) {
9390 __setAndRestore __newloc(locale);
94 return strtoull(__nptr, __endptr, __base);
91 return ::strtoull(__nptr, __endptr, __base);
9592}
9693
97static inline
98unsigned long strtoul_l(const char *__nptr, char **__endptr,
99 int __base, locale_t locale) {
94inline _LIBCPP_HIDE_FROM_ABI unsigned long
95strtoul_l(const char *__nptr, char **__endptr, int __base, locale_t locale) {
10096 __setAndRestore __newloc(locale);
101 return strtoul(__nptr, __endptr, __base);
97 return ::strtoul(__nptr, __endptr, __base);
10298}
10399
104static inline
105int vasprintf(char **strp, const char *fmt, va_list ap) {
100inline _LIBCPP_HIDE_FROM_ABI int
101vasprintf(char **strp, const char *fmt, va_list ap) {
106102 const size_t buff_size = 256;
107103 if ((*strp = (char *)malloc(buff_size)) == NULL) {
108104 return -1;
lib/libcxx/include/__support/musl/xlocale.h+15-16
......@@ -24,30 +24,29 @@
2424extern "C" {
2525#endif
2626
27static inline long long strtoll_l(const char *nptr, char **endptr, int base,
28 locale_t) {
29 return strtoll(nptr, endptr, base);
27inline _LIBCPP_HIDE_FROM_ABI long long
28strtoll_l(const char *__nptr, char **__endptr, int __base, locale_t) {
29 return ::strtoll(__nptr, __endptr, __base);
3030}
3131
32static inline unsigned long long strtoull_l(const char *nptr, char **endptr,
33 int base, locale_t) {
34 return strtoull(nptr, endptr, base);
32inline _LIBCPP_HIDE_FROM_ABI unsigned long long
33strtoull_l(const char *__nptr, char **__endptr, int __base, locale_t) {
34 return ::strtoull(__nptr, __endptr, __base);
3535}
3636
37static inline long long wcstoll_l(const wchar_t *nptr, wchar_t **endptr,
38 int base, locale_t) {
39 return wcstoll(nptr, endptr, base);
37inline _LIBCPP_HIDE_FROM_ABI long long
38wcstoll_l(const wchar_t *__nptr, wchar_t **__endptr, int __base, locale_t) {
39 return ::wcstoll(__nptr, __endptr, __base);
4040}
4141
42static inline unsigned long long wcstoull_l(const wchar_t *nptr,
43 wchar_t **endptr, int base,
44 locale_t) {
45 return wcstoull(nptr, endptr, base);
42inline _LIBCPP_HIDE_FROM_ABI long long
43wcstoull_l(const wchar_t *__nptr, wchar_t **__endptr, int __base, locale_t) {
44 return ::wcstoull(__nptr, __endptr, __base);
4645}
4746
48static inline long double wcstold_l(const wchar_t *nptr, wchar_t **endptr,
49 locale_t) {
50 return wcstold(nptr, endptr);
47inline _LIBCPP_HIDE_FROM_ABI long double
48wcstold_l(const wchar_t *__nptr, wchar_t **__endptr, locale_t) {
49 return ::wcstold(__nptr, __endptr);
5150}
5251
5352#ifdef __cplusplus
lib/libcxx/include/__support/openbsd/xlocale.h+4-4
......@@ -22,13 +22,13 @@ extern "C" {
2222
2323
2424inline _LIBCPP_HIDE_FROM_ABI long
25strtol_l(const char *nptr, char **endptr, int base, locale_t) {
26 return ::strtol(nptr, endptr, base);
25strtol_l(const char *__nptr, char **__endptr, int __base, locale_t) {
26 return ::strtol(__nptr, __endptr, __base);
2727}
2828
2929inline _LIBCPP_HIDE_FROM_ABI unsigned long
30strtoul_l(const char *nptr, char **endptr, int base, locale_t) {
31 return ::strtoul(nptr, endptr, base);
30strtoul_l(const char *__nptr, char **__endptr, int __base, locale_t) {
31 return ::strtoul(__nptr, __endptr, __base);
3232}
3333
3434
lib/libcxx/include/__support/solaris/xlocale.h+27-28
......@@ -32,40 +32,39 @@ struct lconv *localeconv(void);
3232struct lconv *localeconv_l(locale_t __l);
3333
3434// FIXME: These are quick-and-dirty hacks to make things pretend to work
35static inline
36long long strtoll_l(const char *__nptr, char **__endptr,
37 int __base, locale_t __loc) {
38 return strtoll(__nptr, __endptr, __base);
35inline _LIBCPP_HIDE_FROM_ABI long long
36strtoll_l(const char *__nptr, char **__endptr, int __base, locale_t __loc) {
37 return ::strtoll(__nptr, __endptr, __base);
3938}
40static inline
41long strtol_l(const char *__nptr, char **__endptr,
42 int __base, locale_t __loc) {
43 return strtol(__nptr, __endptr, __base);
39
40inline _LIBCPP_HIDE_FROM_ABI long
41strtol_l(const char *__nptr, char **__endptr, int __base, locale_t __loc) {
42 return ::strtol(__nptr, __endptr, __base);
4443}
45static inline
46unsigned long long strtoull_l(const char *__nptr, char **__endptr,
47 int __base, locale_t __loc) {
48 return strtoull(__nptr, __endptr, __base);
44
45inline _LIBCPP_HIDE_FROM_ABI unsigned long long
46strtoull_l(const char *__nptr, char **__endptr, int __base, locale_t __loc)
47 return ::strtoull(__nptr, __endptr, __base);
4948}
50static inline
51unsigned long strtoul_l(const char *__nptr, char **__endptr,
52 int __base, locale_t __loc) {
53 return strtoul(__nptr, __endptr, __base);
49
50inline _LIBCPP_HIDE_FROM_ABI unsigned long
51strtoul_l(const char *__nptr, char **__endptr, int __base, locale_t __loc) {
52 return ::strtoul(__nptr, __endptr, __base);
5453}
55static inline
56float strtof_l(const char *__nptr, char **__endptr,
57 locale_t __loc) {
58 return strtof(__nptr, __endptr);
54
55inline _LIBCPP_HIDE_FROM_ABI float
56strtof_l(const char *__nptr, char **__endptr, locale_t __loc) {
57 return ::strtof(__nptr, __endptr);
5958}
60static inline
61double strtod_l(const char *__nptr, char **__endptr,
62 locale_t __loc) {
63 return strtod(__nptr, __endptr);
59
60inline _LIBCPP_HIDE_FROM_ABI double
61strtod_l(const char *__nptr, char **__endptr, locale_t __loc) {
62 return ::strtod(__nptr, __endptr);
6463}
65static inline
66long double strtold_l(const char *__nptr, char **__endptr,
67 locale_t __loc) {
68 return strtold(__nptr, __endptr);
64
65inline _LIBCPP_HIDE_FROM_ABI long double
66strtold_l(const char *__nptr, char **__endptr, locale_t __loc) {
67 return ::strtold(__nptr, __endptr);
6968}
7069
7170
lib/libcxx/include/__support/win32/locale_win32.h+30-32
......@@ -11,7 +11,7 @@
1111#define _LIBCPP_SUPPORT_WIN32_LOCALE_WIN32_H
1212
1313#include <__config>
14#include <__nullptr>
14#include <cstddef>
1515#include <locale.h> // _locale_t
1616#include <stdio.h>
1717
......@@ -186,28 +186,28 @@ private:
186186// Locale management functions
187187#define freelocale _free_locale
188188// FIXME: base currently unused. Needs manual work to construct the new locale
189locale_t newlocale( int mask, const char * locale, locale_t base );
189locale_t newlocale( int __mask, const char * __locale, locale_t __base );
190190// uselocale can't be implemented on Windows because Windows allows partial modification
191191// of thread-local locale and so _get_current_locale() returns a copy while uselocale does
192192// not create any copies.
193193// We can still implement raii even without uselocale though.
194194
195195
196lconv *localeconv_l( locale_t &loc );
197size_t mbrlen_l( const char *__restrict s, size_t n,
198 mbstate_t *__restrict ps, locale_t loc);
199size_t mbsrtowcs_l( wchar_t *__restrict dst, const char **__restrict src,
200 size_t len, mbstate_t *__restrict ps, locale_t loc );
201size_t wcrtomb_l( char *__restrict s, wchar_t wc, mbstate_t *__restrict ps,
202 locale_t loc);
203size_t mbrtowc_l( wchar_t *__restrict pwc, const char *__restrict s,
204 size_t n, mbstate_t *__restrict ps, locale_t loc);
205size_t mbsnrtowcs_l( wchar_t *__restrict dst, const char **__restrict src,
206 size_t nms, size_t len, mbstate_t *__restrict ps, locale_t loc);
207size_t wcsnrtombs_l( char *__restrict dst, const wchar_t **__restrict src,
208 size_t nwc, size_t len, mbstate_t *__restrict ps, locale_t loc);
209wint_t btowc_l( int c, locale_t loc );
210int wctob_l( wint_t c, locale_t loc );
196lconv *localeconv_l( locale_t & __loc );
197size_t mbrlen_l( const char *__restrict __s, size_t __n,
198 mbstate_t *__restrict __ps, locale_t __loc);
199size_t mbsrtowcs_l( wchar_t *__restrict __dst, const char **__restrict __src,
200 size_t __len, mbstate_t *__restrict __ps, locale_t __loc );
201size_t wcrtomb_l( char *__restrict __s, wchar_t __wc, mbstate_t *__restrict __ps,
202 locale_t __loc);
203size_t mbrtowc_l( wchar_t *__restrict __pwc, const char *__restrict __s,
204 size_t __n, mbstate_t *__restrict __ps, locale_t __loc);
205size_t mbsnrtowcs_l( wchar_t *__restrict __dst, const char **__restrict __src,
206 size_t __nms, size_t __len, mbstate_t *__restrict __ps, locale_t __loc);
207size_t wcsnrtombs_l( char *__restrict __dst, const wchar_t **__restrict __src,
208 size_t __nwc, size_t __len, mbstate_t *__restrict __ps, locale_t __loc);
209wint_t btowc_l( int __c, locale_t __loc );
210int wctob_l( wint_t __c, locale_t __loc );
211211
212212decltype(MB_CUR_MAX) MB_CUR_MAX_L( locale_t __l );
213213
......@@ -223,18 +223,16 @@ decltype(MB_CUR_MAX) MB_CUR_MAX_L( locale_t __l );
223223_LIBCPP_FUNC_VIS float strtof_l(const char*, char**, locale_t);
224224_LIBCPP_FUNC_VIS long double strtold_l(const char*, char**, locale_t);
225225#endif
226inline _LIBCPP_INLINE_VISIBILITY
227int
228islower_l(int c, _locale_t loc)
226inline _LIBCPP_HIDE_FROM_ABI int
227islower_l(int __c, _locale_t __loc)
229228{
230 return _islower_l((int)c, loc);
229 return _islower_l((int)__c, __loc);
231230}
232231
233inline _LIBCPP_INLINE_VISIBILITY
234int
235isupper_l(int c, _locale_t loc)
232inline _LIBCPP_HIDE_FROM_ABI int
233isupper_l(int __c, _locale_t __loc)
236234{
237 return _isupper_l((int)c, loc);
235 return _isupper_l((int)__c, __loc);
238236}
239237
240238#define isdigit_l _isdigit_l
......@@ -266,18 +264,18 @@ _LIBCPP_FUNC_VIS size_t strftime_l(char *ret, size_t n, const char *format,
266264#define sprintf_l( __s, __l, __f, ... ) _sprintf_l( __s, __f, __l, __VA_ARGS__ )
267265#define vsprintf_l( __s, __l, __f, ... ) _vsprintf_l( __s, __f, __l, __VA_ARGS__ )
268266#define vsnprintf_l( __s, __n, __l, __f, ... ) _vsnprintf_l( __s, __n, __f, __l, __VA_ARGS__ )
269_LIBCPP_FUNC_VIS int snprintf_l(char *ret, size_t n, locale_t loc, const char *format, ...);
270_LIBCPP_FUNC_VIS int asprintf_l( char **ret, locale_t loc, const char *format, ... );
271_LIBCPP_FUNC_VIS int vasprintf_l( char **ret, locale_t loc, const char *format, va_list ap );
267_LIBCPP_FUNC_VIS int snprintf_l(char *__ret, size_t __n, locale_t __loc, const char *__format, ...);
268_LIBCPP_FUNC_VIS int asprintf_l( char **__ret, locale_t __loc, const char *__format, ... );
269_LIBCPP_FUNC_VIS int vasprintf_l( char **__ret, locale_t __loc, const char *__format, va_list __ap );
272270
273271// not-so-pressing FIXME: use locale to determine blank characters
274inline int isblank_l( int c, locale_t /*loc*/ )
272inline int isblank_l( int __c, locale_t /*loc*/ )
275273{
276 return ( c == ' ' || c == '\t' );
274 return ( __c == ' ' || __c == '\t' );
277275}
278inline int iswblank_l( wint_t c, locale_t /*loc*/ )
276inline int iswblank_l( wint_t __c, locale_t /*loc*/ )
279277{
280 return ( c == L' ' || c == L'\t' );
278 return ( __c == L' ' || __c == L'\t' );
281279}
282280
283281#endif // _LIBCPP_SUPPORT_WIN32_LOCALE_WIN32_H
lib/libcxx/include/__support/xlocale/__nop_locale_mgmt.h+9-4
......@@ -16,18 +16,23 @@ extern "C" {
1616
1717// Patch over lack of extended locale support
1818typedef void *locale_t;
19static inline locale_t duplocale(locale_t) {
19
20inline _LIBCPP_HIDE_FROM_ABI locale_t
21duplocale(locale_t) {
2022 return NULL;
2123}
2224
23static inline void freelocale(locale_t) {
25inline _LIBCPP_HIDE_FROM_ABI void
26freelocale(locale_t) {
2427}
2528
26static inline locale_t newlocale(int, const char *, locale_t) {
29inline _LIBCPP_HIDE_FROM_ABI locale_t
30newlocale(int, const char *, locale_t) {
2731 return NULL;
2832}
2933
30static inline locale_t uselocale(locale_t) {
34inline _LIBCPP_HIDE_FROM_ABI locale_t
35uselocale(locale_t) {
3136 return NULL;
3237}
3338
lib/libcxx/include/__support/xlocale/__posix_l_fallback.h+72-72
......@@ -19,142 +19,142 @@
1919extern "C" {
2020#endif
2121
22inline _LIBCPP_INLINE_VISIBILITY int isalnum_l(int c, locale_t) {
23 return ::isalnum(c);
22inline _LIBCPP_HIDE_FROM_ABI int isalnum_l(int __c, locale_t) {
23 return ::isalnum(__c);
2424}
2525
26inline _LIBCPP_INLINE_VISIBILITY int isalpha_l(int c, locale_t) {
27 return ::isalpha(c);
26inline _LIBCPP_HIDE_FROM_ABI int isalpha_l(int __c, locale_t) {
27 return ::isalpha(__c);
2828}
2929
30inline _LIBCPP_INLINE_VISIBILITY int isblank_l(int c, locale_t) {
31 return ::isblank(c);
30inline _LIBCPP_HIDE_FROM_ABI int isblank_l(int __c, locale_t) {
31 return ::isblank(__c);
3232}
3333
34inline _LIBCPP_INLINE_VISIBILITY int iscntrl_l(int c, locale_t) {
35 return ::iscntrl(c);
34inline _LIBCPP_HIDE_FROM_ABI int iscntrl_l(int __c, locale_t) {
35 return ::iscntrl(__c);
3636}
3737
38inline _LIBCPP_INLINE_VISIBILITY int isdigit_l(int c, locale_t) {
39 return ::isdigit(c);
38inline _LIBCPP_HIDE_FROM_ABI int isdigit_l(int __c, locale_t) {
39 return ::isdigit(__c);
4040}
4141
42inline _LIBCPP_INLINE_VISIBILITY int isgraph_l(int c, locale_t) {
43 return ::isgraph(c);
42inline _LIBCPP_HIDE_FROM_ABI int isgraph_l(int __c, locale_t) {
43 return ::isgraph(__c);
4444}
4545
46inline _LIBCPP_INLINE_VISIBILITY int islower_l(int c, locale_t) {
47 return ::islower(c);
46inline _LIBCPP_HIDE_FROM_ABI int islower_l(int __c, locale_t) {
47 return ::islower(__c);
4848}
4949
50inline _LIBCPP_INLINE_VISIBILITY int isprint_l(int c, locale_t) {
51 return ::isprint(c);
50inline _LIBCPP_HIDE_FROM_ABI int isprint_l(int __c, locale_t) {
51 return ::isprint(__c);
5252}
5353
54inline _LIBCPP_INLINE_VISIBILITY int ispunct_l(int c, locale_t) {
55 return ::ispunct(c);
54inline _LIBCPP_HIDE_FROM_ABI int ispunct_l(int __c, locale_t) {
55 return ::ispunct(__c);
5656}
5757
58inline _LIBCPP_INLINE_VISIBILITY int isspace_l(int c, locale_t) {
59 return ::isspace(c);
58inline _LIBCPP_HIDE_FROM_ABI int isspace_l(int __c, locale_t) {
59 return ::isspace(__c);
6060}
6161
62inline _LIBCPP_INLINE_VISIBILITY int isupper_l(int c, locale_t) {
63 return ::isupper(c);
62inline _LIBCPP_HIDE_FROM_ABI int isupper_l(int __c, locale_t) {
63 return ::isupper(__c);
6464}
6565
66inline _LIBCPP_INLINE_VISIBILITY int isxdigit_l(int c, locale_t) {
67 return ::isxdigit(c);
66inline _LIBCPP_HIDE_FROM_ABI int isxdigit_l(int __c, locale_t) {
67 return ::isxdigit(__c);
6868}
6969
70inline _LIBCPP_INLINE_VISIBILITY int iswalnum_l(wint_t c, locale_t) {
71 return ::iswalnum(c);
70inline _LIBCPP_HIDE_FROM_ABI int iswalnum_l(wint_t __c, locale_t) {
71 return ::iswalnum(__c);
7272}
7373
74inline _LIBCPP_INLINE_VISIBILITY int iswalpha_l(wint_t c, locale_t) {
75 return ::iswalpha(c);
74inline _LIBCPP_HIDE_FROM_ABI int iswalpha_l(wint_t __c, locale_t) {
75 return ::iswalpha(__c);
7676}
7777
78inline _LIBCPP_INLINE_VISIBILITY int iswblank_l(wint_t c, locale_t) {
79 return ::iswblank(c);
78inline _LIBCPP_HIDE_FROM_ABI int iswblank_l(wint_t __c, locale_t) {
79 return ::iswblank(__c);
8080}
8181
82inline _LIBCPP_INLINE_VISIBILITY int iswcntrl_l(wint_t c, locale_t) {
83 return ::iswcntrl(c);
82inline _LIBCPP_HIDE_FROM_ABI int iswcntrl_l(wint_t __c, locale_t) {
83 return ::iswcntrl(__c);
8484}
8585
86inline _LIBCPP_INLINE_VISIBILITY int iswdigit_l(wint_t c, locale_t) {
87 return ::iswdigit(c);
86inline _LIBCPP_HIDE_FROM_ABI int iswdigit_l(wint_t __c, locale_t) {
87 return ::iswdigit(__c);
8888}
8989
90inline _LIBCPP_INLINE_VISIBILITY int iswgraph_l(wint_t c, locale_t) {
91 return ::iswgraph(c);
90inline _LIBCPP_HIDE_FROM_ABI int iswgraph_l(wint_t __c, locale_t) {
91 return ::iswgraph(__c);
9292}
9393
94inline _LIBCPP_INLINE_VISIBILITY int iswlower_l(wint_t c, locale_t) {
95 return ::iswlower(c);
94inline _LIBCPP_HIDE_FROM_ABI int iswlower_l(wint_t __c, locale_t) {
95 return ::iswlower(__c);
9696}
9797
98inline _LIBCPP_INLINE_VISIBILITY int iswprint_l(wint_t c, locale_t) {
99 return ::iswprint(c);
98inline _LIBCPP_HIDE_FROM_ABI int iswprint_l(wint_t __c, locale_t) {
99 return ::iswprint(__c);
100100}
101101
102inline _LIBCPP_INLINE_VISIBILITY int iswpunct_l(wint_t c, locale_t) {
103 return ::iswpunct(c);
102inline _LIBCPP_HIDE_FROM_ABI int iswpunct_l(wint_t __c, locale_t) {
103 return ::iswpunct(__c);
104104}
105105
106inline _LIBCPP_INLINE_VISIBILITY int iswspace_l(wint_t c, locale_t) {
107 return ::iswspace(c);
106inline _LIBCPP_HIDE_FROM_ABI int iswspace_l(wint_t __c, locale_t) {
107 return ::iswspace(__c);
108108}
109109
110inline _LIBCPP_INLINE_VISIBILITY int iswupper_l(wint_t c, locale_t) {
111 return ::iswupper(c);
110inline _LIBCPP_HIDE_FROM_ABI int iswupper_l(wint_t __c, locale_t) {
111 return ::iswupper(__c);
112112}
113113
114inline _LIBCPP_INLINE_VISIBILITY int iswxdigit_l(wint_t c, locale_t) {
115 return ::iswxdigit(c);
114inline _LIBCPP_HIDE_FROM_ABI int iswxdigit_l(wint_t __c, locale_t) {
115 return ::iswxdigit(__c);
116116}
117117
118inline _LIBCPP_INLINE_VISIBILITY int toupper_l(int c, locale_t) {
119 return ::toupper(c);
118inline _LIBCPP_HIDE_FROM_ABI int toupper_l(int __c, locale_t) {
119 return ::toupper(__c);
120120}
121121
122inline _LIBCPP_INLINE_VISIBILITY int tolower_l(int c, locale_t) {
123 return ::tolower(c);
122inline _LIBCPP_HIDE_FROM_ABI int tolower_l(int __c, locale_t) {
123 return ::tolower(__c);
124124}
125125
126inline _LIBCPP_INLINE_VISIBILITY wint_t towupper_l(wint_t c, locale_t) {
127 return ::towupper(c);
126inline _LIBCPP_HIDE_FROM_ABI wint_t towupper_l(wint_t __c, locale_t) {
127 return ::towupper(__c);
128128}
129129
130inline _LIBCPP_INLINE_VISIBILITY wint_t towlower_l(wint_t c, locale_t) {
131 return ::towlower(c);
130inline _LIBCPP_HIDE_FROM_ABI wint_t towlower_l(wint_t __c, locale_t) {
131 return ::towlower(__c);
132132}
133133
134inline _LIBCPP_INLINE_VISIBILITY int strcoll_l(const char *s1, const char *s2,
135 locale_t) {
136 return ::strcoll(s1, s2);
134inline _LIBCPP_HIDE_FROM_ABI int
135strcoll_l(const char *__s1, const char *__s2, locale_t) {
136 return ::strcoll(__s1, __s2);
137137}
138138
139inline _LIBCPP_INLINE_VISIBILITY size_t strxfrm_l(char *dest, const char *src,
140 size_t n, locale_t) {
141 return ::strxfrm(dest, src, n);
139inline _LIBCPP_HIDE_FROM_ABI size_t
140strxfrm_l(char *__dest, const char *__src, size_t __n, locale_t) {
141 return ::strxfrm(__dest, __src, __n);
142142}
143143
144inline _LIBCPP_INLINE_VISIBILITY size_t strftime_l(char *s, size_t max,
145 const char *format,
146 const struct tm *tm, locale_t) {
147 return ::strftime(s, max, format, tm);
144inline _LIBCPP_HIDE_FROM_ABI size_t
145strftime_l(char *__s, size_t __max, const char *__format, const struct tm *__tm,
146 locale_t) {
147 return ::strftime(__s, __max, __format, __tm);
148148}
149149
150inline _LIBCPP_INLINE_VISIBILITY int wcscoll_l(const wchar_t *ws1,
151 const wchar_t *ws2, locale_t) {
152 return ::wcscoll(ws1, ws2);
150inline _LIBCPP_HIDE_FROM_ABI int
151wcscoll_l(const wchar_t *__ws1, const wchar_t *__ws2, locale_t) {
152 return ::wcscoll(__ws1, __ws2);
153153}
154154
155inline _LIBCPP_INLINE_VISIBILITY size_t wcsxfrm_l(wchar_t *dest, const wchar_t *src,
156 size_t n, locale_t) {
157 return ::wcsxfrm(dest, src, n);
155inline _LIBCPP_HIDE_FROM_ABI size_t
156wcsxfrm_l(wchar_t *__dest, const wchar_t *__src, size_t __n, locale_t) {
157 return ::wcsxfrm(__dest, __src, __n);
158158}
159159
160160#ifdef __cplusplus
lib/libcxx/include/__support/xlocale/__strtonum_fallback.h+24-24
......@@ -19,44 +19,44 @@
1919extern "C" {
2020#endif
2121
22inline _LIBCPP_INLINE_VISIBILITY float strtof_l(const char *nptr,
23 char **endptr, locale_t) {
24 return ::strtof(nptr, endptr);
22inline _LIBCPP_HIDE_FROM_ABI float
23strtof_l(const char *__nptr, char **__endptr, locale_t) {
24 return ::strtof(__nptr, __endptr);
2525}
2626
27inline _LIBCPP_INLINE_VISIBILITY double strtod_l(const char *nptr,
28 char **endptr, locale_t) {
29 return ::strtod(nptr, endptr);
27inline _LIBCPP_HIDE_FROM_ABI double
28strtod_l(const char *__nptr, char **__endptr, locale_t) {
29 return ::strtod(__nptr, __endptr);
3030}
3131
32inline _LIBCPP_INLINE_VISIBILITY long double strtold_l(const char *nptr,
33 char **endptr, locale_t) {
34 return ::strtold(nptr, endptr);
32inline _LIBCPP_HIDE_FROM_ABI long double
33strtold_l(const char *__nptr, char **__endptr, locale_t) {
34 return ::strtold(__nptr, __endptr);
3535}
3636
37inline _LIBCPP_INLINE_VISIBILITY long long
38strtoll_l(const char *nptr, char **endptr, int base, locale_t) {
39 return ::strtoll(nptr, endptr, base);
37inline _LIBCPP_HIDE_FROM_ABI long long
38strtoll_l(const char *__nptr, char **__endptr, int __base, locale_t) {
39 return ::strtoll(__nptr, __endptr, __base);
4040}
4141
42inline _LIBCPP_INLINE_VISIBILITY unsigned long long
43strtoull_l(const char *nptr, char **endptr, int base, locale_t) {
44 return ::strtoull(nptr, endptr, base);
42inline _LIBCPP_HIDE_FROM_ABI unsigned long long
43strtoull_l(const char *__nptr, char **__endptr, int __base, locale_t) {
44 return ::strtoull(__nptr, __endptr, __base);
4545}
4646
47inline _LIBCPP_INLINE_VISIBILITY long long
48wcstoll_l(const wchar_t *nptr, wchar_t **endptr, int base, locale_t) {
49 return ::wcstoll(nptr, endptr, base);
47inline _LIBCPP_HIDE_FROM_ABI long long
48wcstoll_l(const wchar_t *__nptr, wchar_t **__endptr, int __base, locale_t) {
49 return ::wcstoll(__nptr, __endptr, __base);
5050}
5151
52inline _LIBCPP_INLINE_VISIBILITY unsigned long long
53wcstoull_l(const wchar_t *nptr, wchar_t **endptr, int base, locale_t) {
54 return ::wcstoull(nptr, endptr, base);
52inline _LIBCPP_HIDE_FROM_ABI unsigned long long
53wcstoull_l(const wchar_t *__nptr, wchar_t **__endptr, int __base, locale_t) {
54 return ::wcstoull(__nptr, __endptr, __base);
5555}
5656
57inline _LIBCPP_INLINE_VISIBILITY long double wcstold_l(const wchar_t *nptr,
58 wchar_t **endptr, locale_t) {
59 return ::wcstold(nptr, endptr);
57inline _LIBCPP_HIDE_FROM_ABI long double
58wcstold_l(const wchar_t *__nptr, wchar_t **__endptr, locale_t) {
59 return ::wcstold(__nptr, __endptr);
6060}
6161
6262#ifdef __cplusplus
lib/libcxx/include/__thread/poll_with_backoff.h+6-2
......@@ -10,11 +10,15 @@
1010#define _LIBCPP___THREAD_POLL_WITH_BACKOFF_H
1111
1212#include <__availability>
13#include <__chrono/duration.h>
14#include <__chrono/high_resolution_clock.h>
15#include <__chrono/steady_clock.h>
16#include <__chrono/time_point.h>
1317#include <__config>
14#include <chrono>
18#include <__filesystem/file_time_type.h>
1519
1620#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
21# pragma GCC system_header
1822#endif
1923
2024_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__thread/timed_backoff_policy.h+3-3
......@@ -13,11 +13,11 @@
1313
1414#ifndef _LIBCPP_HAS_NO_THREADS
1515
16#include <__threading_support>
17#include <chrono>
16# include <__chrono/duration.h>
17# include <__threading_support>
1818
1919#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20#pragma GCC system_header
20# pragma GCC system_header
2121#endif
2222
2323_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__threading_support+17-16
......@@ -7,13 +7,14 @@
77//
88//===----------------------------------------------------------------------===//
99
10#ifndef _LIBCPP_THREADING_SUPPORT
11#define _LIBCPP_THREADING_SUPPORT
10#ifndef _LIBCPP___THREADING_SUPPORT
11#define _LIBCPP___THREADING_SUPPORT
1212
1313#include <__availability>
14#include <__chrono/convert_to_timespec.h>
15#include <__chrono/duration.h>
1416#include <__config>
1517#include <__thread/poll_with_backoff.h>
16#include <chrono>
1718#include <errno.h>
1819#include <iosfwd>
1920#include <limits>
......@@ -23,7 +24,7 @@
2324#endif
2425
2526#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
26#pragma GCC system_header
27# pragma GCC system_header
2728#endif
2829
2930#if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
......@@ -200,15 +201,15 @@ int __libcpp_condvar_destroy(__libcpp_condvar_t* __cv);
200201
201202// Execute once
202203_LIBCPP_THREAD_ABI_VISIBILITY
203int __libcpp_execute_once(__libcpp_exec_once_flag *flag,
204 void (*init_routine)());
204int __libcpp_execute_once(__libcpp_exec_once_flag *__flag,
205 void (*__init_routine)());
205206
206207// Thread id
207208_LIBCPP_THREAD_ABI_VISIBILITY
208bool __libcpp_thread_id_equal(__libcpp_thread_id t1, __libcpp_thread_id t2);
209bool __libcpp_thread_id_equal(__libcpp_thread_id __t1, __libcpp_thread_id __t2);
209210
210211_LIBCPP_THREAD_ABI_VISIBILITY
211bool __libcpp_thread_id_less(__libcpp_thread_id t1, __libcpp_thread_id t2);
212bool __libcpp_thread_id_less(__libcpp_thread_id __t1, __libcpp_thread_id __t2);
212213
213214// Thread
214215_LIBCPP_THREAD_ABI_VISIBILITY
......@@ -346,22 +347,22 @@ int __libcpp_condvar_destroy(__libcpp_condvar_t *__cv)
346347}
347348
348349// Execute once
349int __libcpp_execute_once(__libcpp_exec_once_flag *flag,
350 void (*init_routine)()) {
351 return pthread_once(flag, init_routine);
350int __libcpp_execute_once(__libcpp_exec_once_flag *__flag,
351 void (*__init_routine)()) {
352 return pthread_once(__flag, __init_routine);
352353}
353354
354355// Thread id
355356// Returns non-zero if the thread ids are equal, otherwise 0
356bool __libcpp_thread_id_equal(__libcpp_thread_id t1, __libcpp_thread_id t2)
357bool __libcpp_thread_id_equal(__libcpp_thread_id __t1, __libcpp_thread_id __t2)
357358{
358 return t1 == t2;
359 return __t1 == __t2;
359360}
360361
361362// Returns non-zero if t1 < t2, otherwise 0
362bool __libcpp_thread_id_less(__libcpp_thread_id t1, __libcpp_thread_id t2)
363bool __libcpp_thread_id_less(__libcpp_thread_id __t1, __libcpp_thread_id __t2)
363364{
364 return t1 < t2;
365 return __t1 < __t2;
365366}
366367
367368// Thread
......@@ -673,4 +674,4 @@ get_id() _NOEXCEPT
673674
674675_LIBCPP_END_NAMESPACE_STD
675676
676#endif // _LIBCPP_THREADING_SUPPORT
677#endif // _LIBCPP___THREADING_SUPPORT
lib/libcxx/include/__tree+37-40
......@@ -10,16 +10,22 @@
1010#ifndef _LIBCPP___TREE
1111#define _LIBCPP___TREE
1212
13#include <__algorithm/min.h>
14#include <__assert>
1315#include <__config>
16#include <__debug>
17#include <__iterator/distance.h>
18#include <__iterator/iterator_traits.h>
19#include <__iterator/next.h>
20#include <__memory/swap_allocator.h>
1421#include <__utility/forward.h>
15#include <algorithm>
16#include <iterator>
22#include <__utility/swap.h>
1723#include <limits>
1824#include <memory>
1925#include <stdexcept>
2026
2127#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22#pragma GCC system_header
28# pragma GCC system_header
2329#endif
2430
2531_LIBCPP_PUSH_MACROS
......@@ -28,12 +34,10 @@ _LIBCPP_PUSH_MACROS
2834
2935_LIBCPP_BEGIN_NAMESPACE_STD
3036
31#if defined(__GNUC__) && !defined(__clang__) // gcc.gnu.org/PR37804
3237template <class, class, class, class> class _LIBCPP_TEMPLATE_VIS map;
3338template <class, class, class, class> class _LIBCPP_TEMPLATE_VIS multimap;
3439template <class, class, class> class _LIBCPP_TEMPLATE_VIS set;
3540template <class, class, class> class _LIBCPP_TEMPLATE_VIS multiset;
36#endif
3741
3842template <class _Tp, class _Compare, class _Allocator> class __tree;
3943template <class _Tp, class _NodePtr, class _DiffType>
......@@ -140,35 +144,35 @@ __tree_invariant(_NodePtr __root)
140144}
141145
142146// Returns: pointer to the left-most node under __x.
143// Precondition: __x != nullptr.
144147template <class _NodePtr>
145148inline _LIBCPP_INLINE_VISIBILITY
146149_NodePtr
147150__tree_min(_NodePtr __x) _NOEXCEPT
148151{
152 _LIBCPP_ASSERT(__x != nullptr, "Root node shouldn't be null");
149153 while (__x->__left_ != nullptr)
150154 __x = __x->__left_;
151155 return __x;
152156}
153157
154158// Returns: pointer to the right-most node under __x.
155// Precondition: __x != nullptr.
156159template <class _NodePtr>
157160inline _LIBCPP_INLINE_VISIBILITY
158161_NodePtr
159162__tree_max(_NodePtr __x) _NOEXCEPT
160163{
164 _LIBCPP_ASSERT(__x != nullptr, "Root node shouldn't be null");
161165 while (__x->__right_ != nullptr)
162166 __x = __x->__right_;
163167 return __x;
164168}
165169
166170// Returns: pointer to the next in-order node after __x.
167// Precondition: __x != nullptr.
168171template <class _NodePtr>
169172_NodePtr
170173__tree_next(_NodePtr __x) _NOEXCEPT
171174{
175 _LIBCPP_ASSERT(__x != nullptr, "node shouldn't be null");
172176 if (__x->__right_ != nullptr)
173177 return _VSTD::__tree_min(__x->__right_);
174178 while (!_VSTD::__tree_is_left_child(__x))
......@@ -181,6 +185,7 @@ inline _LIBCPP_INLINE_VISIBILITY
181185_EndNodePtr
182186__tree_next_iter(_NodePtr __x) _NOEXCEPT
183187{
188 _LIBCPP_ASSERT(__x != nullptr, "node shouldn't be null");
184189 if (__x->__right_ != nullptr)
185190 return static_cast<_EndNodePtr>(_VSTD::__tree_min(__x->__right_));
186191 while (!_VSTD::__tree_is_left_child(__x))
......@@ -189,13 +194,13 @@ __tree_next_iter(_NodePtr __x) _NOEXCEPT
189194}
190195
191196// Returns: pointer to the previous in-order node before __x.
192// Precondition: __x != nullptr.
193197// Note: __x may be the end node.
194198template <class _NodePtr, class _EndNodePtr>
195199inline _LIBCPP_INLINE_VISIBILITY
196200_NodePtr
197201__tree_prev_iter(_EndNodePtr __x) _NOEXCEPT
198202{
203 _LIBCPP_ASSERT(__x != nullptr, "node shouldn't be null");
199204 if (__x->__left_ != nullptr)
200205 return _VSTD::__tree_max(__x->__left_);
201206 _NodePtr __xx = static_cast<_NodePtr>(__x);
......@@ -205,11 +210,11 @@ __tree_prev_iter(_EndNodePtr __x) _NOEXCEPT
205210}
206211
207212// Returns: pointer to a node which has no children
208// Precondition: __x != nullptr.
209213template <class _NodePtr>
210214_NodePtr
211215__tree_leaf(_NodePtr __x) _NOEXCEPT
212216{
217 _LIBCPP_ASSERT(__x != nullptr, "node shouldn't be null");
213218 while (true)
214219 {
215220 if (__x->__left_ != nullptr)
......@@ -229,11 +234,12 @@ __tree_leaf(_NodePtr __x) _NOEXCEPT
229234
230235// Effects: Makes __x->__right_ the subtree root with __x as its left child
231236// while preserving in-order order.
232// Precondition: __x->__right_ != nullptr
233237template <class _NodePtr>
234238void
235239__tree_left_rotate(_NodePtr __x) _NOEXCEPT
236240{
241 _LIBCPP_ASSERT(__x != nullptr, "node shouldn't be null");
242 _LIBCPP_ASSERT(__x->__right_ != nullptr, "node should have a right child");
237243 _NodePtr __y = __x->__right_;
238244 __x->__right_ = __y->__left_;
239245 if (__x->__right_ != nullptr)
......@@ -249,11 +255,12 @@ __tree_left_rotate(_NodePtr __x) _NOEXCEPT
249255
250256// Effects: Makes __x->__left_ the subtree root with __x as its right child
251257// while preserving in-order order.
252// Precondition: __x->__left_ != nullptr
253258template <class _NodePtr>
254259void
255260__tree_right_rotate(_NodePtr __x) _NOEXCEPT
256261{
262 _LIBCPP_ASSERT(__x != nullptr, "node shouldn't be null");
263 _LIBCPP_ASSERT(__x->__left_ != nullptr, "node should have a left child");
257264 _NodePtr __y = __x->__left_;
258265 __x->__left_ = __y->__right_;
259266 if (__x->__left_ != nullptr)
......@@ -268,8 +275,7 @@ __tree_right_rotate(_NodePtr __x) _NOEXCEPT
268275}
269276
270277// Effects: Rebalances __root after attaching __x to a leaf.
271// Precondition: __root != nulptr && __x != nullptr.
272// __x has no children.
278// Precondition: __x has no children.
273279// __x == __root or == a direct or indirect child of __root.
274280// If __x were to be unlinked from __root (setting __root to
275281// nullptr if __root == __x), __tree_invariant(__root) == true.
......@@ -279,6 +285,8 @@ template <class _NodePtr>
279285void
280286__tree_balance_after_insert(_NodePtr __root, _NodePtr __x) _NOEXCEPT
281287{
288 _LIBCPP_ASSERT(__root != nullptr, "Root of the tree shouldn't be null");
289 _LIBCPP_ASSERT(__x != nullptr, "Can't attach null node to a leaf");
282290 __x->__is_black_ = __x == __root;
283291 while (__x != __root && !__x->__parent_unsafe()->__is_black_)
284292 {
......@@ -338,9 +346,7 @@ __tree_balance_after_insert(_NodePtr __root, _NodePtr __x) _NOEXCEPT
338346 }
339347}
340348
341// Precondition: __root != nullptr && __z != nullptr.
342// __tree_invariant(__root) == true.
343// __z == __root or == a direct or indirect child of __root.
349// Precondition: __z == __root or == a direct or indirect child of __root.
344350// Effects: unlinks __z from the tree rooted at __root, rebalancing as needed.
345351// Postcondition: __tree_invariant(end_node->__left_) == true && end_node->__left_
346352// nor any of its children refer to __z. end_node->__left_
......@@ -349,6 +355,9 @@ template <class _NodePtr>
349355void
350356__tree_remove(_NodePtr __root, _NodePtr __z) _NOEXCEPT
351357{
358 _LIBCPP_ASSERT(__root != nullptr, "Root node should not be null");
359 _LIBCPP_ASSERT(__z != nullptr, "The node to remove should not be null");
360 _LIBCPP_DEBUG_ASSERT(__tree_invariant(__root), "The tree invariants should hold");
352361 // __z will be removed from the tree. Client still needs to destruct/deallocate it
353362 // __y is either __z, or if __z has two children, __tree_next(__z).
354363 // __y will have at most one child.
......@@ -545,7 +554,7 @@ template <class ..._Args>
545554struct __is_tree_value_type : false_type {};
546555
547556template <class _One>
548struct __is_tree_value_type<_One> : __is_tree_value_type_imp<typename __uncvref<_One>::type> {};
557struct __is_tree_value_type<_One> : __is_tree_value_type_imp<__uncvref_t<_One> > {};
549558
550559template <class _Tp>
551560struct __tree_key_value_types {
......@@ -589,8 +598,7 @@ struct __tree_key_value_types<__value_type<_Key, _Tp> > {
589598
590599 template <class _Up>
591600 _LIBCPP_INLINE_VISIBILITY
592 static typename enable_if<__is_same_uncvref<_Up, __container_value_type>::value,
593 key_type const&>::type
601 static __enable_if_t<__is_same_uncvref<_Up, __container_value_type>::value, key_type const&>
594602 __get_key(_Up& __t) {
595603 return __t.first;
596604 }
......@@ -603,8 +611,7 @@ struct __tree_key_value_types<__value_type<_Key, _Tp> > {
603611
604612 template <class _Up>
605613 _LIBCPP_INLINE_VISIBILITY
606 static typename enable_if<__is_same_uncvref<_Up, __container_value_type>::value,
607 __container_value_type const&>::type
614 static __enable_if_t<__is_same_uncvref<_Up, __container_value_type>::value, __container_value_type const&>
608615 __get_value(_Up& __t) {
609616 return __t;
610617 }
......@@ -1167,10 +1174,8 @@ public:
11671174
11681175 template <class _First, class _Second>
11691176 _LIBCPP_INLINE_VISIBILITY
1170 typename enable_if<
1171 __can_extract_map_key<_First, key_type, __container_value_type>::value,
1172 pair<iterator, bool>
1173 >::type __emplace_unique(_First&& __f, _Second&& __s) {
1177 __enable_if_t<__can_extract_map_key<_First, key_type, __container_value_type>::value, pair<iterator, bool> >
1178 __emplace_unique(_First&& __f, _Second&& __s) {
11741179 return __emplace_unique_key_args(__f, _VSTD::forward<_First>(__f),
11751180 _VSTD::forward<_Second>(__s));
11761181 }
......@@ -1211,10 +1216,8 @@ public:
12111216
12121217 template <class _First, class _Second>
12131218 _LIBCPP_INLINE_VISIBILITY
1214 typename enable_if<
1215 __can_extract_map_key<_First, key_type, __container_value_type>::value,
1216 iterator
1217 >::type __emplace_hint_unique(const_iterator __p, _First&& __f, _Second&& __s) {
1219 __enable_if_t<__can_extract_map_key<_First, key_type, __container_value_type>::value, iterator>
1220 __emplace_hint_unique(const_iterator __p, _First&& __f, _Second&& __s) {
12181221 return __emplace_hint_unique_key_args(__p, __f,
12191222 _VSTD::forward<_First>(__f),
12201223 _VSTD::forward<_Second>(__s)).first;
......@@ -1267,21 +1270,15 @@ public:
12671270 return __emplace_hint_unique_key_args(__p, _NodeTypes::__get_key(__v), _VSTD::move(__v)).first;
12681271 }
12691272
1270 template <class _Vp, class = typename enable_if<
1271 !is_same<typename __unconstref<_Vp>::type,
1272 __container_value_type
1273 >::value
1274 >::type>
1273 template <class _Vp,
1274 class = __enable_if_t<!is_same<typename __unconstref<_Vp>::type, __container_value_type>::value> >
12751275 _LIBCPP_INLINE_VISIBILITY
12761276 pair<iterator, bool> __insert_unique(_Vp&& __v) {
12771277 return __emplace_unique(_VSTD::forward<_Vp>(__v));
12781278 }
12791279
1280 template <class _Vp, class = typename enable_if<
1281 !is_same<typename __unconstref<_Vp>::type,
1282 __container_value_type
1283 >::value
1284 >::type>
1280 template <class _Vp,
1281 class = __enable_if_t<!is_same<typename __unconstref<_Vp>::type, __container_value_type>::value> >
12851282 _LIBCPP_INLINE_VISIBILITY
12861283 iterator __insert_unique(const_iterator __p, _Vp&& __v) {
12871284 return __emplace_hint_unique(__p, _VSTD::forward<_Vp>(__v));
lib/libcxx/include/__tuple+6-7
......@@ -15,7 +15,7 @@
1515#include <type_traits>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121
......@@ -30,14 +30,14 @@ using __enable_if_tuple_size_imp = _Tp;
3030template <class _Tp>
3131struct _LIBCPP_TEMPLATE_VIS tuple_size<__enable_if_tuple_size_imp<
3232 const _Tp,
33 typename enable_if<!is_volatile<_Tp>::value>::type,
33 __enable_if_t<!is_volatile<_Tp>::value>,
3434 integral_constant<size_t, sizeof(tuple_size<_Tp>)>>>
3535 : public integral_constant<size_t, tuple_size<_Tp>::value> {};
3636
3737template <class _Tp>
3838struct _LIBCPP_TEMPLATE_VIS tuple_size<__enable_if_tuple_size_imp<
3939 volatile _Tp,
40 typename enable_if<!is_const<_Tp>::value>::type,
40 __enable_if_t<!is_const<_Tp>::value>,
4141 integral_constant<size_t, sizeof(tuple_size<_Tp>)>>>
4242 : public integral_constant<size_t, tuple_size<_Tp>::value> {};
4343
......@@ -278,7 +278,7 @@ using __type_pack_element _LIBCPP_NODEBUG = typename decltype(
278278#endif
279279
280280template <size_t _Ip, class ..._Types>
281struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, __tuple_types<_Types...>>
281struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, __tuple_types<_Types...> >
282282{
283283 static_assert(_Ip < sizeof...(_Types), "tuple_element index out of range");
284284 typedef _LIBCPP_NODEBUG __type_pack_element<_Ip, _Types...> type;
......@@ -393,7 +393,7 @@ struct __tuple_sfinae_base {
393393 template <template <class, class...> class _Trait,
394394 class ..._LArgs, class ..._RArgs>
395395 static auto __do_test(__tuple_types<_LArgs...>, __tuple_types<_RArgs...>)
396 -> __all<typename enable_if<_Trait<_LArgs, _RArgs>::value, bool>::type{true}...>;
396 -> __all<__enable_if_t<_Trait<_LArgs, _RArgs>::value, bool>{true}...>;
397397 template <template <class...> class>
398398 static auto __do_test(...) -> false_type;
399399
......@@ -469,8 +469,7 @@ template <class _SizeTrait, size_t _Expected>
469469struct __tuple_like_with_size_imp<true, _SizeTrait, _Expected>
470470 : integral_constant<bool, _SizeTrait::value == _Expected> {};
471471
472template <class _Tuple, size_t _ExpectedSize,
473 class _RawTuple = typename __uncvref<_Tuple>::type>
472template <class _Tuple, size_t _ExpectedSize, class _RawTuple = __uncvref_t<_Tuple> >
474473using __tuple_like_with_size _LIBCPP_NODEBUG = __tuple_like_with_size_imp<
475474 __tuple_like<_RawTuple>::value,
476475 tuple_size<_RawTuple>, _ExpectedSize
lib/libcxx/include/__type_traits/add_const.h created+30
......@@ -0,0 +1,30 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_ADD_CONST_H
10#define _LIBCPP___TYPE_TRAITS_ADD_CONST_H
11
12#include <__config>
13
14#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15# pragma GCC system_header
16#endif
17
18_LIBCPP_BEGIN_NAMESPACE_STD
19
20template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_const {
21 typedef _LIBCPP_NODEBUG const _Tp type;
22};
23
24#if _LIBCPP_STD_VER > 11
25template <class _Tp> using add_const_t = typename add_const<_Tp>::type;
26#endif
27
28_LIBCPP_END_NAMESPACE_STD
29
30#endif // _LIBCPP___TYPE_TRAITS_ADD_CONST_H
lib/libcxx/include/__type_traits/add_cv.h created+30
......@@ -0,0 +1,30 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_ADD_CV_H
10#define _LIBCPP___TYPE_TRAITS_ADD_CV_H
11
12#include <__config>
13
14#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15# pragma GCC system_header
16#endif
17
18_LIBCPP_BEGIN_NAMESPACE_STD
19
20template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_cv {
21 typedef _LIBCPP_NODEBUG const volatile _Tp type;
22};
23
24#if _LIBCPP_STD_VER > 11
25template <class _Tp> using add_cv_t = typename add_cv<_Tp>::type;
26#endif
27
28_LIBCPP_END_NAMESPACE_STD
29
30#endif // _LIBCPP___TYPE_TRAITS_ADD_CV_H
lib/libcxx/include/__type_traits/add_lvalue_reference.h created+33
......@@ -0,0 +1,33 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_ADD_LVALUE_REFERENCE_H
10#define _LIBCPP___TYPE_TRAITS_ADD_LVALUE_REFERENCE_H
11
12#include <__config>
13#include <__type_traits/is_referenceable.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21template <class _Tp, bool = __is_referenceable<_Tp>::value> struct __add_lvalue_reference_impl { typedef _LIBCPP_NODEBUG _Tp type; };
22template <class _Tp > struct __add_lvalue_reference_impl<_Tp, true> { typedef _LIBCPP_NODEBUG _Tp& type; };
23
24template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_lvalue_reference
25{typedef _LIBCPP_NODEBUG typename __add_lvalue_reference_impl<_Tp>::type type;};
26
27#if _LIBCPP_STD_VER > 11
28template <class _Tp> using add_lvalue_reference_t = typename add_lvalue_reference<_Tp>::type;
29#endif
30
31_LIBCPP_END_NAMESPACE_STD
32
33#endif // _LIBCPP___TYPE_TRAITS_ADD_LVALUE_REFERENCE_H
lib/libcxx/include/__type_traits/add_pointer.h created+41
......@@ -0,0 +1,41 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_ADD_POINTER_H
10#define _LIBCPP___TYPE_TRAITS_ADD_POINTER_H
11
12#include <__config>
13#include <__type_traits/is_referenceable.h>
14#include <__type_traits/is_same.h>
15#include <__type_traits/remove_cv.h>
16#include <__type_traits/remove_reference.h>
17
18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19# pragma GCC system_header
20#endif
21
22_LIBCPP_BEGIN_NAMESPACE_STD
23
24template <class _Tp,
25 bool = __is_referenceable<_Tp>::value ||
26 _IsSame<typename remove_cv<_Tp>::type, void>::value>
27struct __add_pointer_impl
28 {typedef _LIBCPP_NODEBUG typename remove_reference<_Tp>::type* type;};
29template <class _Tp> struct __add_pointer_impl<_Tp, false>
30 {typedef _LIBCPP_NODEBUG _Tp type;};
31
32template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_pointer
33 {typedef _LIBCPP_NODEBUG typename __add_pointer_impl<_Tp>::type type;};
34
35#if _LIBCPP_STD_VER > 11
36template <class _Tp> using add_pointer_t = typename add_pointer<_Tp>::type;
37#endif
38
39_LIBCPP_END_NAMESPACE_STD
40
41#endif // _LIBCPP___TYPE_TRAITS_ADD_POINTER_H
lib/libcxx/include/__type_traits/add_rvalue_reference.h created+33
......@@ -0,0 +1,33 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_ADD_RVALUE_REFERENCE_H
10#define _LIBCPP___TYPE_TRAITS_ADD_RVALUE_REFERENCE_H
11
12#include <__config>
13#include <__type_traits/is_referenceable.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21template <class _Tp, bool = __is_referenceable<_Tp>::value> struct __add_rvalue_reference_impl { typedef _LIBCPP_NODEBUG _Tp type; };
22template <class _Tp > struct __add_rvalue_reference_impl<_Tp, true> { typedef _LIBCPP_NODEBUG _Tp&& type; };
23
24template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_rvalue_reference
25{typedef _LIBCPP_NODEBUG typename __add_rvalue_reference_impl<_Tp>::type type;};
26
27#if _LIBCPP_STD_VER > 11
28template <class _Tp> using add_rvalue_reference_t = typename add_rvalue_reference<_Tp>::type;
29#endif
30
31_LIBCPP_END_NAMESPACE_STD
32
33#endif // _LIBCPP___TYPE_TRAITS_ADD_RVALUE_REFERENCE_H
lib/libcxx/include/__type_traits/add_volatile.h created+30
......@@ -0,0 +1,30 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_ADD_VOLATILE_H
10#define _LIBCPP___TYPE_TRAITS_ADD_VOLATILE_H
11
12#include <__config>
13
14#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15# pragma GCC system_header
16#endif
17
18_LIBCPP_BEGIN_NAMESPACE_STD
19
20template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_volatile {
21 typedef _LIBCPP_NODEBUG volatile _Tp type;
22};
23
24#if _LIBCPP_STD_VER > 11
25template <class _Tp> using add_volatile_t = typename add_volatile<_Tp>::type;
26#endif
27
28_LIBCPP_END_NAMESPACE_STD
29
30#endif // _LIBCPP___TYPE_TRAITS_ADD_VOLATILE_H
lib/libcxx/include/__type_traits/aligned_storage.h created+142
......@@ -0,0 +1,142 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_ALIGNED_STORAGE_H
10#define _LIBCPP___TYPE_TRAITS_ALIGNED_STORAGE_H
11
12#include <__config>
13#include <__type_traits/conditional.h>
14#include <__type_traits/integral_constant.h>
15#include <__type_traits/nat.h>
16#include <__type_traits/type_list.h>
17#include <cstddef>
18
19#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20# pragma GCC system_header
21#endif
22
23_LIBCPP_BEGIN_NAMESPACE_STD
24
25template <class _Tp>
26struct __align_type
27{
28 static const size_t value = _LIBCPP_PREFERRED_ALIGNOF(_Tp);
29 typedef _Tp type;
30};
31
32struct __struct_double {long double __lx;};
33struct __struct_double4 {double __lx[4];};
34
35typedef
36 __type_list<__align_type<unsigned char>,
37 __type_list<__align_type<unsigned short>,
38 __type_list<__align_type<unsigned int>,
39 __type_list<__align_type<unsigned long>,
40 __type_list<__align_type<unsigned long long>,
41 __type_list<__align_type<double>,
42 __type_list<__align_type<long double>,
43 __type_list<__align_type<__struct_double>,
44 __type_list<__align_type<__struct_double4>,
45 __type_list<__align_type<int*>,
46 __nat
47 > > > > > > > > > > __all_types;
48
49template <size_t _Align>
50struct _ALIGNAS(_Align) __fallback_overaligned {};
51
52template <class _TL, size_t _Align> struct __find_pod;
53
54template <class _Hp, size_t _Align>
55struct __find_pod<__type_list<_Hp, __nat>, _Align>
56{
57 typedef typename conditional<
58 _Align == _Hp::value,
59 typename _Hp::type,
60 __fallback_overaligned<_Align>
61 >::type type;
62};
63
64template <class _Hp, class _Tp, size_t _Align>
65struct __find_pod<__type_list<_Hp, _Tp>, _Align>
66{
67 typedef typename conditional<
68 _Align == _Hp::value,
69 typename _Hp::type,
70 typename __find_pod<_Tp, _Align>::type
71 >::type type;
72};
73
74template <class _TL, size_t _Len> struct __find_max_align;
75
76template <class _Hp, size_t _Len>
77struct __find_max_align<__type_list<_Hp, __nat>, _Len> : public integral_constant<size_t, _Hp::value> {};
78
79template <size_t _Len, size_t _A1, size_t _A2>
80struct __select_align
81{
82private:
83 static const size_t __min = _A2 < _A1 ? _A2 : _A1;
84 static const size_t __max = _A1 < _A2 ? _A2 : _A1;
85public:
86 static const size_t value = _Len < __max ? __min : __max;
87};
88
89template <class _Hp, class _Tp, size_t _Len>
90struct __find_max_align<__type_list<_Hp, _Tp>, _Len>
91 : public integral_constant<size_t, __select_align<_Len, _Hp::value, __find_max_align<_Tp, _Len>::value>::value> {};
92
93template <size_t _Len, size_t _Align = __find_max_align<__all_types, _Len>::value>
94struct _LIBCPP_TEMPLATE_VIS aligned_storage
95{
96 typedef typename __find_pod<__all_types, _Align>::type _Aligner;
97 union type
98 {
99 _Aligner __align;
100 unsigned char __data[(_Len + _Align - 1)/_Align * _Align];
101 };
102};
103
104#if _LIBCPP_STD_VER > 11
105template <size_t _Len, size_t _Align = __find_max_align<__all_types, _Len>::value>
106 using aligned_storage_t = typename aligned_storage<_Len, _Align>::type;
107#endif
108
109#define _CREATE_ALIGNED_STORAGE_SPECIALIZATION(n) \
110template <size_t _Len>\
111struct _LIBCPP_TEMPLATE_VIS aligned_storage<_Len, n>\
112{\
113 struct _ALIGNAS(n) type\
114 {\
115 unsigned char __lx[(_Len + n - 1)/n * n];\
116 };\
117}
118
119_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x1);
120_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x2);
121_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4);
122_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x8);
123_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x10);
124_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x20);
125_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x40);
126_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x80);
127_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x100);
128_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x200);
129_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x400);
130_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x800);
131_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x1000);
132_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x2000);
133// PE/COFF does not support alignment beyond 8192 (=0x2000)
134#if !defined(_LIBCPP_OBJECT_FORMAT_COFF)
135_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4000);
136#endif // !defined(_LIBCPP_OBJECT_FORMAT_COFF)
137
138#undef _CREATE_ALIGNED_STORAGE_SPECIALIZATION
139
140_LIBCPP_END_NAMESPACE_STD
141
142#endif // _LIBCPP___TYPE_TRAITS_ALIGNED_STORAGE_H
lib/libcxx/include/__type_traits/aligned_union.h created+55
......@@ -0,0 +1,55 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_ALIGNED_UNION_H
10#define _LIBCPP___TYPE_TRAITS_ALIGNED_UNION_H
11
12#include <__config>
13#include <__type_traits/aligned_storage.h>
14#include <__type_traits/integral_constant.h>
15#include <cstddef>
16
17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18# pragma GCC system_header
19#endif
20
21_LIBCPP_BEGIN_NAMESPACE_STD
22
23template <size_t _I0, size_t ..._In>
24struct __static_max;
25
26template <size_t _I0>
27struct __static_max<_I0>
28{
29 static const size_t value = _I0;
30};
31
32template <size_t _I0, size_t _I1, size_t ..._In>
33struct __static_max<_I0, _I1, _In...>
34{
35 static const size_t value = _I0 >= _I1 ? __static_max<_I0, _In...>::value :
36 __static_max<_I1, _In...>::value;
37};
38
39template <size_t _Len, class _Type0, class ..._Types>
40struct aligned_union
41{
42 static const size_t alignment_value = __static_max<_LIBCPP_PREFERRED_ALIGNOF(_Type0),
43 _LIBCPP_PREFERRED_ALIGNOF(_Types)...>::value;
44 static const size_t __len = __static_max<_Len, sizeof(_Type0),
45 sizeof(_Types)...>::value;
46 typedef typename aligned_storage<__len, alignment_value>::type type;
47};
48
49#if _LIBCPP_STD_VER > 11
50template <size_t _Len, class ..._Types> using aligned_union_t = typename aligned_union<_Len, _Types...>::type;
51#endif
52
53_LIBCPP_END_NAMESPACE_STD
54
55#endif // _LIBCPP___TYPE_TRAITS_ALIGNED_UNION_H
lib/libcxx/include/__type_traits/alignment_of.h created+32
......@@ -0,0 +1,32 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_ALIGNMENT_OF_H
10#define _LIBCPP___TYPE_TRAITS_ALIGNMENT_OF_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14#include <cstddef>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
20_LIBCPP_BEGIN_NAMESPACE_STD
21
22template <class _Tp> struct _LIBCPP_TEMPLATE_VIS alignment_of
23 : public integral_constant<size_t, _LIBCPP_ALIGNOF(_Tp)> {};
24
25#if _LIBCPP_STD_VER > 14
26template <class _Tp>
27inline constexpr size_t alignment_of_v = alignment_of<_Tp>::value;
28#endif
29
30_LIBCPP_END_NAMESPACE_STD
31
32#endif // _LIBCPP___TYPE_TRAITS_ALIGNMENT_OF_H
lib/libcxx/include/__type_traits/apply_cv.h created+76
......@@ -0,0 +1,76 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_APPLY_CV_H
10#define _LIBCPP___TYPE_TRAITS_APPLY_CV_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14#include <__type_traits/is_const.h>
15#include <__type_traits/is_volatile.h>
16#include <__type_traits/remove_reference.h>
17#include <cstddef>
18
19#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20# pragma GCC system_header
21#endif
22
23_LIBCPP_BEGIN_NAMESPACE_STD
24
25template <class _Tp, class _Up, bool = is_const<typename remove_reference<_Tp>::type>::value,
26 bool = is_volatile<typename remove_reference<_Tp>::type>::value>
27struct __apply_cv
28{
29 typedef _LIBCPP_NODEBUG _Up type;
30};
31
32template <class _Tp, class _Up>
33struct __apply_cv<_Tp, _Up, true, false>
34{
35 typedef _LIBCPP_NODEBUG const _Up type;
36};
37
38template <class _Tp, class _Up>
39struct __apply_cv<_Tp, _Up, false, true>
40{
41 typedef volatile _Up type;
42};
43
44template <class _Tp, class _Up>
45struct __apply_cv<_Tp, _Up, true, true>
46{
47 typedef const volatile _Up type;
48};
49
50template <class _Tp, class _Up>
51struct __apply_cv<_Tp&, _Up, false, false>
52{
53 typedef _Up& type;
54};
55
56template <class _Tp, class _Up>
57struct __apply_cv<_Tp&, _Up, true, false>
58{
59 typedef const _Up& type;
60};
61
62template <class _Tp, class _Up>
63struct __apply_cv<_Tp&, _Up, false, true>
64{
65 typedef volatile _Up& type;
66};
67
68template <class _Tp, class _Up>
69struct __apply_cv<_Tp&, _Up, true, true>
70{
71 typedef const volatile _Up& type;
72};
73
74_LIBCPP_END_NAMESPACE_STD
75
76#endif // _LIBCPP___TYPE_TRAITS_APPLY_CV_H
lib/libcxx/include/__type_traits/common_reference.h created+188
......@@ -0,0 +1,188 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_COMMON_REFERENCE_H
10#define _LIBCPP___TYPE_TRAITS_COMMON_REFERENCE_H
11
12#include <__config>
13#include <__type_traits/common_type.h>
14#include <__type_traits/copy_cv.h>
15#include <__type_traits/copy_cvref.h>
16#include <__type_traits/is_convertible.h>
17#include <__type_traits/is_reference.h>
18#include <__type_traits/remove_cv.h>
19#include <__type_traits/remove_cvref.h>
20#include <__type_traits/remove_reference.h>
21#include <__utility/declval.h>
22
23#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
24# pragma GCC system_header
25#endif
26
27_LIBCPP_BEGIN_NAMESPACE_STD
28
29// common_reference
30#if _LIBCPP_STD_VER > 17
31// Let COND_RES(X, Y) be:
32template <class _Xp, class _Yp>
33using __cond_res =
34 decltype(false ? declval<_Xp(&)()>()() : declval<_Yp(&)()>()());
35
36// Let `XREF(A)` denote a unary alias template `T` such that `T<U>` denotes the same type as `U`
37// with the addition of `A`'s cv and reference qualifiers, for a non-reference cv-unqualified type
38// `U`.
39// [Note: `XREF(A)` is `__xref<A>::template __apply`]
40template <class _Tp>
41struct __xref {
42 template<class _Up>
43 using __apply = __copy_cvref_t<_Tp, _Up>;
44};
45
46// Given types A and B, let X be remove_reference_t<A>, let Y be remove_reference_t<B>,
47// and let COMMON-REF(A, B) be:
48template<class _Ap, class _Bp, class _Xp = remove_reference_t<_Ap>, class _Yp = remove_reference_t<_Bp>>
49struct __common_ref;
50
51template<class _Xp, class _Yp>
52using __common_ref_t = typename __common_ref<_Xp, _Yp>::__type;
53
54template<class _Xp, class _Yp>
55using __cv_cond_res = __cond_res<__copy_cv_t<_Xp, _Yp>&, __copy_cv_t<_Yp, _Xp>&>;
56
57
58// If A and B are both lvalue reference types, COMMON-REF(A, B) is
59// COND-RES(COPYCV(X, Y)&, COPYCV(Y, X)&) if that type exists and is a reference type.
60template<class _Ap, class _Bp, class _Xp, class _Yp>
61requires requires { typename __cv_cond_res<_Xp, _Yp>; } && is_reference_v<__cv_cond_res<_Xp, _Yp>>
62struct __common_ref<_Ap&, _Bp&, _Xp, _Yp>
63{
64 using __type = __cv_cond_res<_Xp, _Yp>;
65};
66
67// Otherwise, let C be remove_reference_t<COMMON-REF(X&, Y&)>&&. ...
68template <class _Xp, class _Yp>
69using __common_ref_C = remove_reference_t<__common_ref_t<_Xp&, _Yp&>>&&;
70
71
72// .... If A and B are both rvalue reference types, C is well-formed, and
73// is_convertible_v<A, C> && is_convertible_v<B, C> is true, then COMMON-REF(A, B) is C.
74template<class _Ap, class _Bp, class _Xp, class _Yp>
75requires
76 requires { typename __common_ref_C<_Xp, _Yp>; } &&
77 is_convertible_v<_Ap&&, __common_ref_C<_Xp, _Yp>> &&
78 is_convertible_v<_Bp&&, __common_ref_C<_Xp, _Yp>>
79struct __common_ref<_Ap&&, _Bp&&, _Xp, _Yp>
80{
81 using __type = __common_ref_C<_Xp, _Yp>;
82};
83
84// Otherwise, let D be COMMON-REF(const X&, Y&). ...
85template <class _Tp, class _Up>
86using __common_ref_D = __common_ref_t<const _Tp&, _Up&>;
87
88// ... If A is an rvalue reference and B is an lvalue reference and D is well-formed and
89// is_convertible_v<A, D> is true, then COMMON-REF(A, B) is D.
90template<class _Ap, class _Bp, class _Xp, class _Yp>
91requires requires { typename __common_ref_D<_Xp, _Yp>; } &&
92 is_convertible_v<_Ap&&, __common_ref_D<_Xp, _Yp>>
93struct __common_ref<_Ap&&, _Bp&, _Xp, _Yp>
94{
95 using __type = __common_ref_D<_Xp, _Yp>;
96};
97
98// Otherwise, if A is an lvalue reference and B is an rvalue reference, then
99// COMMON-REF(A, B) is COMMON-REF(B, A).
100template<class _Ap, class _Bp, class _Xp, class _Yp>
101struct __common_ref<_Ap&, _Bp&&, _Xp, _Yp> : __common_ref<_Bp&&, _Ap&> {};
102
103// Otherwise, COMMON-REF(A, B) is ill-formed.
104template<class _Ap, class _Bp, class _Xp, class _Yp>
105struct __common_ref {};
106
107// Note C: For the common_reference trait applied to a parameter pack [...]
108
109template <class...>
110struct common_reference;
111
112template <class... _Types>
113using common_reference_t = typename common_reference<_Types...>::type;
114
115// bullet 1 - sizeof...(T) == 0
116template<>
117struct common_reference<> {};
118
119// bullet 2 - sizeof...(T) == 1
120template <class _Tp>
121struct common_reference<_Tp>
122{
123 using type = _Tp;
124};
125
126// bullet 3 - sizeof...(T) == 2
127template <class _Tp, class _Up> struct __common_reference_sub_bullet3;
128template <class _Tp, class _Up> struct __common_reference_sub_bullet2 : __common_reference_sub_bullet3<_Tp, _Up> {};
129template <class _Tp, class _Up> struct __common_reference_sub_bullet1 : __common_reference_sub_bullet2<_Tp, _Up> {};
130
131// sub-bullet 1 - If T1 and T2 are reference types and COMMON-REF(T1, T2) is well-formed, then
132// the member typedef `type` denotes that type.
133template <class _Tp, class _Up> struct common_reference<_Tp, _Up> : __common_reference_sub_bullet1<_Tp, _Up> {};
134
135template <class _Tp, class _Up>
136requires is_reference_v<_Tp> && is_reference_v<_Up> && requires { typename __common_ref_t<_Tp, _Up>; }
137struct __common_reference_sub_bullet1<_Tp, _Up>
138{
139 using type = __common_ref_t<_Tp, _Up>;
140};
141
142// sub-bullet 2 - Otherwise, if basic_common_reference<remove_cvref_t<T1>, remove_cvref_t<T2>, XREF(T1), XREF(T2)>::type
143// is well-formed, then the member typedef `type` denotes that type.
144template <class, class, template <class> class, template <class> class> struct basic_common_reference {};
145
146template <class _Tp, class _Up>
147using __basic_common_reference_t = typename basic_common_reference<
148 remove_cvref_t<_Tp>, remove_cvref_t<_Up>,
149 __xref<_Tp>::template __apply, __xref<_Up>::template __apply>::type;
150
151template <class _Tp, class _Up>
152requires requires { typename __basic_common_reference_t<_Tp, _Up>; }
153struct __common_reference_sub_bullet2<_Tp, _Up>
154{
155 using type = __basic_common_reference_t<_Tp, _Up>;
156};
157
158// sub-bullet 3 - Otherwise, if COND-RES(T1, T2) is well-formed,
159// then the member typedef `type` denotes that type.
160template <class _Tp, class _Up>
161requires requires { typename __cond_res<_Tp, _Up>; }
162struct __common_reference_sub_bullet3<_Tp, _Up>
163{
164 using type = __cond_res<_Tp, _Up>;
165};
166
167
168// sub-bullet 4 & 5 - Otherwise, if common_type_t<T1, T2> is well-formed,
169// then the member typedef `type` denotes that type.
170// - Otherwise, there shall be no member `type`.
171template <class _Tp, class _Up> struct __common_reference_sub_bullet3 : common_type<_Tp, _Up> {};
172
173// bullet 4 - If there is such a type `C`, the member typedef type shall denote the same type, if
174// any, as `common_reference_t<C, Rest...>`.
175template <class _Tp, class _Up, class _Vp, class... _Rest>
176requires requires { typename common_reference_t<_Tp, _Up>; }
177struct common_reference<_Tp, _Up, _Vp, _Rest...>
178 : common_reference<common_reference_t<_Tp, _Up>, _Vp, _Rest...>
179{};
180
181// bullet 5 - Otherwise, there shall be no member `type`.
182template <class...> struct common_reference {};
183
184#endif // _LIBCPP_STD_VER > 17
185
186_LIBCPP_END_NAMESPACE_STD
187
188#endif // _LIBCPP___TYPE_TRAITS_COMMON_REFERENCE_H
lib/libcxx/include/__type_traits/common_type.h created+138
......@@ -0,0 +1,138 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_COMMON_TYPE_H
10#define _LIBCPP___TYPE_TRAITS_COMMON_TYPE_H
11
12#include <__config>
13#include <__type_traits/conditional.h>
14#include <__type_traits/decay.h>
15#include <__type_traits/is_same.h>
16#include <__type_traits/remove_cvref.h>
17#include <__type_traits/void_t.h>
18#include <__utility/declval.h>
19
20#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21# pragma GCC system_header
22#endif
23
24_LIBCPP_BEGIN_NAMESPACE_STD
25
26#if _LIBCPP_STD_VER > 17
27// Let COND_RES(X, Y) be:
28template <class _Tp, class _Up>
29using __cond_type = decltype(false ? declval<_Tp>() : declval<_Up>());
30
31template <class _Tp, class _Up, class = void>
32struct __common_type3 {};
33
34// sub-bullet 4 - "if COND_RES(CREF(D1), CREF(D2)) denotes a type..."
35template <class _Tp, class _Up>
36struct __common_type3<_Tp, _Up, void_t<__cond_type<const _Tp&, const _Up&>>>
37{
38 using type = remove_cvref_t<__cond_type<const _Tp&, const _Up&>>;
39};
40
41template <class _Tp, class _Up, class = void>
42struct __common_type2_imp : __common_type3<_Tp, _Up> {};
43#else
44template <class _Tp, class _Up, class = void>
45struct __common_type2_imp {};
46#endif
47
48// sub-bullet 3 - "if decay_t<decltype(false ? declval<D1>() : declval<D2>())> ..."
49template <class _Tp, class _Up>
50struct __common_type2_imp<_Tp, _Up,
51 typename __void_t<decltype(
52 true ? declval<_Tp>() : declval<_Up>()
53 )>::type>
54{
55 typedef _LIBCPP_NODEBUG typename decay<decltype(
56 true ? declval<_Tp>() : declval<_Up>()
57 )>::type type;
58};
59
60template <class, class = void>
61struct __common_type_impl {};
62
63// Clang provides variadic templates in C++03 as an extension.
64#if !defined(_LIBCPP_CXX03_LANG) || defined(__clang__)
65# define _LIBCPP_OPTIONAL_PACK(...) , __VA_ARGS__
66template <class... _Tp>
67struct __common_types;
68template <class... _Tp>
69struct _LIBCPP_TEMPLATE_VIS common_type;
70#else
71# define _LIBCPP_OPTIONAL_PACK(...)
72struct __no_arg;
73template <class _Tp, class _Up, class = __no_arg>
74struct __common_types;
75template <class _Tp = __no_arg, class _Up = __no_arg, class _Vp = __no_arg,
76 class _Unused = __no_arg>
77struct common_type {
78 static_assert(sizeof(_Unused) == 0,
79 "common_type accepts at most 3 arguments in C++03");
80};
81#endif // _LIBCPP_CXX03_LANG
82
83template <class _Tp, class _Up>
84struct __common_type_impl<
85 __common_types<_Tp, _Up>,
86 typename __void_t<typename common_type<_Tp, _Up>::type>::type>
87{
88 typedef typename common_type<_Tp, _Up>::type type;
89};
90
91template <class _Tp, class _Up, class _Vp _LIBCPP_OPTIONAL_PACK(class... _Rest)>
92struct __common_type_impl<
93 __common_types<_Tp, _Up, _Vp _LIBCPP_OPTIONAL_PACK(_Rest...)>,
94 typename __void_t<typename common_type<_Tp, _Up>::type>::type>
95 : __common_type_impl<__common_types<typename common_type<_Tp, _Up>::type,
96 _Vp _LIBCPP_OPTIONAL_PACK(_Rest...)> > {
97};
98
99// bullet 1 - sizeof...(Tp) == 0
100
101template <>
102struct _LIBCPP_TEMPLATE_VIS common_type<> {};
103
104// bullet 2 - sizeof...(Tp) == 1
105
106template <class _Tp>
107struct _LIBCPP_TEMPLATE_VIS common_type<_Tp>
108 : public common_type<_Tp, _Tp> {};
109
110// bullet 3 - sizeof...(Tp) == 2
111
112// sub-bullet 1 - "If is_same_v<T1, D1> is false or ..."
113template <class _Tp, class _Up>
114struct _LIBCPP_TEMPLATE_VIS common_type<_Tp, _Up>
115 : conditional<
116 _IsSame<_Tp, typename decay<_Tp>::type>::value && _IsSame<_Up, typename decay<_Up>::type>::value,
117 __common_type2_imp<_Tp, _Up>,
118 common_type<typename decay<_Tp>::type, typename decay<_Up>::type>
119 >::type
120{};
121
122// bullet 4 - sizeof...(Tp) > 2
123
124template <class _Tp, class _Up, class _Vp _LIBCPP_OPTIONAL_PACK(class... _Rest)>
125struct _LIBCPP_TEMPLATE_VIS
126 common_type<_Tp, _Up, _Vp _LIBCPP_OPTIONAL_PACK(_Rest...)>
127 : __common_type_impl<
128 __common_types<_Tp, _Up, _Vp _LIBCPP_OPTIONAL_PACK(_Rest...)> > {};
129
130#undef _LIBCPP_OPTIONAL_PACK
131
132#if _LIBCPP_STD_VER > 11
133template <class ..._Tp> using common_type_t = typename common_type<_Tp...>::type;
134#endif
135
136_LIBCPP_END_NAMESPACE_STD
137
138#endif // _LIBCPP___TYPE_TRAITS_COMMON_TYPE_H
lib/libcxx/include/__type_traits/conditional.h created+53
......@@ -0,0 +1,53 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_CONDITIONAL_H
10#define _LIBCPP___TYPE_TRAITS_CONDITIONAL_H
11
12#include <__config>
13
14#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15# pragma GCC system_header
16#endif
17
18_LIBCPP_BEGIN_NAMESPACE_STD
19
20template <bool>
21struct _IfImpl;
22
23template <>
24struct _IfImpl<true> {
25 template <class _IfRes, class _ElseRes>
26 using _Select _LIBCPP_NODEBUG = _IfRes;
27};
28
29template <>
30struct _IfImpl<false> {
31 template <class _IfRes, class _ElseRes>
32 using _Select _LIBCPP_NODEBUG = _ElseRes;
33};
34
35template <bool _Cond, class _IfRes, class _ElseRes>
36using _If _LIBCPP_NODEBUG = typename _IfImpl<_Cond>::template _Select<_IfRes, _ElseRes>;
37
38template <bool _Bp, class _If, class _Then>
39 struct _LIBCPP_TEMPLATE_VIS conditional {typedef _If type;};
40template <class _If, class _Then>
41 struct _LIBCPP_TEMPLATE_VIS conditional<false, _If, _Then> {typedef _Then type;};
42
43#if _LIBCPP_STD_VER > 11
44template <bool _Bp, class _IfRes, class _ElseRes>
45using conditional_t = typename conditional<_Bp, _IfRes, _ElseRes>::type;
46#endif
47
48// Helper so we can use "conditional_t" in all language versions.
49template <bool _Bp, class _If, class _Then> using __conditional_t = typename conditional<_Bp, _If, _Then>::type;
50
51_LIBCPP_END_NAMESPACE_STD
52
53#endif // _LIBCPP___TYPE_TRAITS_CONDITIONAL_H
lib/libcxx/include/__type_traits/conjunction.h created+57
......@@ -0,0 +1,57 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_CONJUNCTION_H
10#define _LIBCPP___TYPE_TRAITS_CONJUNCTION_H
11
12#include <__config>
13#include <__type_traits/conditional.h>
14#include <__type_traits/enable_if.h>
15#include <__type_traits/integral_constant.h>
16
17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18# pragma GCC system_header
19#endif
20
21_LIBCPP_BEGIN_NAMESPACE_STD
22
23#if _LIBCPP_STD_VER > 14
24
25template <class _Arg, class... _Args>
26struct __conjunction_impl {
27 using type = conditional_t<!bool(_Arg::value), _Arg, typename __conjunction_impl<_Args...>::type>;
28};
29
30template <class _Arg>
31struct __conjunction_impl<_Arg> {
32 using type = _Arg;
33};
34
35template <class... _Args>
36struct conjunction : __conjunction_impl<true_type, _Args...>::type {};
37
38template<class... _Args>
39inline constexpr bool conjunction_v = conjunction<_Args...>::value;
40
41#endif // _LIBCPP_STD_VER > 14
42
43template <class...>
44using __expand_to_true = true_type;
45
46template <class... _Pred>
47__expand_to_true<__enable_if_t<_Pred::value>...> __and_helper(int);
48
49template <class...>
50false_type __and_helper(...);
51
52template <class... _Pred>
53using _And _LIBCPP_NODEBUG = decltype(__and_helper<_Pred...>(0));
54
55_LIBCPP_END_NAMESPACE_STD
56
57#endif // _LIBCPP___TYPE_TRAITS_CONJUNCTION_H
lib/libcxx/include/__type_traits/copy_cv.h created+54
......@@ -0,0 +1,54 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_COPY_CV_H
10#define _LIBCPP___TYPE_TRAITS_COPY_CV_H
11
12#include <__config>
13#include <__type_traits/add_const.h>
14#include <__type_traits/add_cv.h>
15#include <__type_traits/add_volatile.h>
16
17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18# pragma GCC system_header
19#endif
20
21_LIBCPP_BEGIN_NAMESPACE_STD
22
23// Let COPYCV(FROM, TO) be an alias for type TO with the addition of FROM's
24// top-level cv-qualifiers.
25template <class _From, class _To>
26struct __copy_cv
27{
28 using type = _To;
29};
30
31template <class _From, class _To>
32struct __copy_cv<const _From, _To>
33{
34 using type = typename add_const<_To>::type;
35};
36
37template <class _From, class _To>
38struct __copy_cv<volatile _From, _To>
39{
40 using type = typename add_volatile<_To>::type;
41};
42
43template <class _From, class _To>
44struct __copy_cv<const volatile _From, _To>
45{
46 using type = typename add_cv<_To>::type;
47};
48
49template <class _From, class _To>
50using __copy_cv_t = typename __copy_cv<_From, _To>::type;
51
52_LIBCPP_END_NAMESPACE_STD
53
54#endif // _LIBCPP___TYPE_TRAITS_COPY_CV_H
lib/libcxx/include/__type_traits/copy_cvref.h created+46
......@@ -0,0 +1,46 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_COPY_CVREF_H
10#define _LIBCPP___TYPE_TRAITS_COPY_CVREF_H
11
12#include <__config>
13#include <__type_traits/add_lvalue_reference.h>
14#include <__type_traits/add_rvalue_reference.h>
15#include <__type_traits/copy_cv.h>
16
17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18# pragma GCC system_header
19#endif
20
21_LIBCPP_BEGIN_NAMESPACE_STD
22
23template <class _From, class _To>
24struct __copy_cvref
25{
26 using type = __copy_cv_t<_From, _To>;
27};
28
29template <class _From, class _To>
30struct __copy_cvref<_From&, _To>
31{
32 using type = typename add_lvalue_reference<__copy_cv_t<_From, _To> >::type;
33};
34
35template <class _From, class _To>
36struct __copy_cvref<_From&&, _To>
37{
38 using type = typename add_rvalue_reference<__copy_cv_t<_From, _To> >::type;
39};
40
41template <class _From, class _To>
42using __copy_cvref_t = typename __copy_cvref<_From, _To>::type;
43
44_LIBCPP_END_NAMESPACE_STD
45
46#endif // _LIBCPP___TYPE_TRAITS_COPY_CVREF_H
lib/libcxx/include/__type_traits/decay.h created+65
......@@ -0,0 +1,65 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_DECAY_H
10#define _LIBCPP___TYPE_TRAITS_DECAY_H
11
12#include <__config>
13#include <__type_traits/add_pointer.h>
14#include <__type_traits/conditional.h>
15#include <__type_traits/integral_constant.h>
16#include <__type_traits/is_array.h>
17#include <__type_traits/is_function.h>
18#include <__type_traits/is_referenceable.h>
19#include <__type_traits/remove_cv.h>
20#include <__type_traits/remove_extent.h>
21#include <__type_traits/remove_reference.h>
22
23#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
24# pragma GCC system_header
25#endif
26
27_LIBCPP_BEGIN_NAMESPACE_STD
28
29template <class _Up, bool>
30struct __decay {
31 typedef _LIBCPP_NODEBUG typename remove_cv<_Up>::type type;
32};
33
34template <class _Up>
35struct __decay<_Up, true> {
36public:
37 typedef _LIBCPP_NODEBUG typename conditional
38 <
39 is_array<_Up>::value,
40 typename remove_extent<_Up>::type*,
41 typename conditional
42 <
43 is_function<_Up>::value,
44 typename add_pointer<_Up>::type,
45 typename remove_cv<_Up>::type
46 >::type
47 >::type type;
48};
49
50template <class _Tp>
51struct _LIBCPP_TEMPLATE_VIS decay
52{
53private:
54 typedef _LIBCPP_NODEBUG typename remove_reference<_Tp>::type _Up;
55public:
56 typedef _LIBCPP_NODEBUG typename __decay<_Up, __is_referenceable<_Up>::value>::type type;
57};
58
59#if _LIBCPP_STD_VER > 11
60template <class _Tp> using decay_t = typename decay<_Tp>::type;
61#endif
62
63_LIBCPP_END_NAMESPACE_STD
64
65#endif // _LIBCPP___TYPE_TRAITS_DECAY_H
lib/libcxx/include/__type_traits/disjunction.h created+53
......@@ -0,0 +1,53 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_DISJUNCTION_H
10#define _LIBCPP___TYPE_TRAITS_DISJUNCTION_H
11
12#include <__config>
13#include <__type_traits/conditional.h>
14#include <__type_traits/integral_constant.h>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
20_LIBCPP_BEGIN_NAMESPACE_STD
21
22template <bool>
23struct _OrImpl;
24
25template <>
26struct _OrImpl<true> {
27 template <class _Res, class _First, class... _Rest>
28 using _Result _LIBCPP_NODEBUG =
29 typename _OrImpl<!bool(_First::value) && sizeof...(_Rest) != 0>::template _Result<_First, _Rest...>;
30};
31
32template <>
33struct _OrImpl<false> {
34 template <class _Res, class...>
35 using _Result = _Res;
36};
37
38template <class... _Args>
39using _Or _LIBCPP_NODEBUG = typename _OrImpl<sizeof...(_Args) != 0>::template _Result<false_type, _Args...>;
40
41#if _LIBCPP_STD_VER > 14
42
43template <class... _Args>
44struct disjunction : _Or<_Args...> {};
45
46template <class... _Args>
47inline constexpr bool disjunction_v = _Or<_Args...>::value;
48
49#endif // _LIBCPP_STD_VER > 14
50
51_LIBCPP_END_NAMESPACE_STD
52
53#endif // _LIBCPP___TYPE_TRAITS_DISJUNCTION_H
lib/libcxx/include/__type_traits/enable_if.h created+31
......@@ -0,0 +1,31 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_ENABLE_IF_H
10#define _LIBCPP___TYPE_TRAITS_ENABLE_IF_H
11
12#include <__config>
13
14#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15# pragma GCC system_header
16#endif
17
18_LIBCPP_BEGIN_NAMESPACE_STD
19
20template <bool, class _Tp = void> struct _LIBCPP_TEMPLATE_VIS enable_if {};
21template <class _Tp> struct _LIBCPP_TEMPLATE_VIS enable_if<true, _Tp> {typedef _Tp type;};
22
23template <bool _Bp, class _Tp = void> using __enable_if_t _LIBCPP_NODEBUG = typename enable_if<_Bp, _Tp>::type;
24
25#if _LIBCPP_STD_VER > 11
26template <bool _Bp, class _Tp = void> using enable_if_t = typename enable_if<_Bp, _Tp>::type;
27#endif
28
29_LIBCPP_END_NAMESPACE_STD
30
31#endif // _LIBCPP___TYPE_TRAITS_ENABLE_IF_H
lib/libcxx/include/__type_traits/extent.h created+55
......@@ -0,0 +1,55 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_EXTENT_H
10#define _LIBCPP___TYPE_TRAITS_EXTENT_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14#include <cstddef>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
20_LIBCPP_BEGIN_NAMESPACE_STD
21
22#if __has_builtin(__array_extent)
23
24template<class _Tp, size_t _Dim = 0>
25struct _LIBCPP_TEMPLATE_VIS extent
26 : integral_constant<size_t, __array_extent(_Tp, _Dim)> { };
27
28#if _LIBCPP_STD_VER > 14
29template <class _Tp, unsigned _Ip = 0>
30inline constexpr size_t extent_v = __array_extent(_Tp, _Ip);
31#endif
32
33#else // __has_builtin(__array_extent)
34
35template <class _Tp, unsigned _Ip = 0> struct _LIBCPP_TEMPLATE_VIS extent
36 : public integral_constant<size_t, 0> {};
37template <class _Tp> struct _LIBCPP_TEMPLATE_VIS extent<_Tp[], 0>
38 : public integral_constant<size_t, 0> {};
39template <class _Tp, unsigned _Ip> struct _LIBCPP_TEMPLATE_VIS extent<_Tp[], _Ip>
40 : public integral_constant<size_t, extent<_Tp, _Ip-1>::value> {};
41template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS extent<_Tp[_Np], 0>
42 : public integral_constant<size_t, _Np> {};
43template <class _Tp, size_t _Np, unsigned _Ip> struct _LIBCPP_TEMPLATE_VIS extent<_Tp[_Np], _Ip>
44 : public integral_constant<size_t, extent<_Tp, _Ip-1>::value> {};
45
46#if _LIBCPP_STD_VER > 14
47template <class _Tp, unsigned _Ip = 0>
48inline constexpr size_t extent_v = extent<_Tp, _Ip>::value;
49#endif
50
51#endif // __has_builtin(__array_extent)
52
53_LIBCPP_END_NAMESPACE_STD
54
55#endif // _LIBCPP___TYPE_TRAITS_EXTENT_H
lib/libcxx/include/__type_traits/has_unique_object_representation.h created+36
......@@ -0,0 +1,36 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_HAS_UNIQUE_OBJECT_REPRESENTATION_H
10#define _LIBCPP___TYPE_TRAITS_HAS_UNIQUE_OBJECT_REPRESENTATION_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14#include <__type_traits/remove_all_extents.h>
15#include <__type_traits/remove_cv.h>
16
17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18# pragma GCC system_header
19#endif
20
21_LIBCPP_BEGIN_NAMESPACE_STD
22
23#if _LIBCPP_STD_VER > 14
24
25template <class _Tp> struct _LIBCPP_TEMPLATE_VIS has_unique_object_representations
26 : public integral_constant<bool,
27 __has_unique_object_representations(remove_cv_t<remove_all_extents_t<_Tp>>)> {};
28
29template <class _Tp>
30inline constexpr bool has_unique_object_representations_v = has_unique_object_representations<_Tp>::value;
31
32#endif
33
34_LIBCPP_END_NAMESPACE_STD
35
36#endif // _LIBCPP___TYPE_TRAITS_HAS_UNIQUE_OBJECT_REPRESENTATION_H
lib/libcxx/include/__type_traits/has_virtual_destructor.h created+40
......@@ -0,0 +1,40 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_HAS_VIRTUAL_DESTRUCTOR_H
10#define _LIBCPP___TYPE_TRAITS_HAS_VIRTUAL_DESTRUCTOR_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21#if __has_builtin(__has_virtual_destructor)
22
23template <class _Tp> struct _LIBCPP_TEMPLATE_VIS has_virtual_destructor
24 : public integral_constant<bool, __has_virtual_destructor(_Tp)> {};
25
26#else
27
28template <class _Tp> struct _LIBCPP_TEMPLATE_VIS has_virtual_destructor
29 : public false_type {};
30
31#endif
32
33#if _LIBCPP_STD_VER > 14
34template <class _Tp>
35inline constexpr bool has_virtual_destructor_v = has_virtual_destructor<_Tp>::value;
36#endif
37
38_LIBCPP_END_NAMESPACE_STD
39
40#endif // _LIBCPP___TYPE_TRAITS_HAS_VIRTUAL_DESTRUCTOR_H
lib/libcxx/include/__type_traits/integral_constant.h created+50
......@@ -0,0 +1,50 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_INTEGRAL_CONSTANT_H
10#define _LIBCPP___TYPE_TRAITS_INTEGRAL_CONSTANT_H
11
12#include <__config>
13
14#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15# pragma GCC system_header
16#endif
17
18_LIBCPP_BEGIN_NAMESPACE_STD
19
20template <class _Tp, _Tp __v>
21struct _LIBCPP_TEMPLATE_VIS integral_constant
22{
23 static _LIBCPP_CONSTEXPR const _Tp value = __v;
24 typedef _Tp value_type;
25 typedef integral_constant type;
26 _LIBCPP_INLINE_VISIBILITY
27 _LIBCPP_CONSTEXPR operator value_type() const _NOEXCEPT {return value;}
28#if _LIBCPP_STD_VER > 11
29 _LIBCPP_INLINE_VISIBILITY
30 constexpr value_type operator ()() const _NOEXCEPT {return value;}
31#endif
32};
33
34template <class _Tp, _Tp __v>
35_LIBCPP_CONSTEXPR const _Tp integral_constant<_Tp, __v>::value;
36
37typedef integral_constant<bool, true> true_type;
38typedef integral_constant<bool, false> false_type;
39
40template <bool _Val>
41using _BoolConstant _LIBCPP_NODEBUG = integral_constant<bool, _Val>;
42
43#if _LIBCPP_STD_VER > 14
44template <bool __b>
45using bool_constant = integral_constant<bool, __b>;
46#endif
47
48_LIBCPP_END_NAMESPACE_STD
49
50#endif // _LIBCPP___TYPE_TRAITS_INTEGRAL_CONSTANT_H
lib/libcxx/include/__type_traits/is_abstract.h created+31
......@@ -0,0 +1,31 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_ABSTRACT_H
10#define _LIBCPP___TYPE_TRAITS_IS_ABSTRACT_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_abstract
22 : public integral_constant<bool, __is_abstract(_Tp)> {};
23
24#if _LIBCPP_STD_VER > 14
25template <class _Tp>
26inline constexpr bool is_abstract_v = __is_abstract(_Tp);
27#endif
28
29_LIBCPP_END_NAMESPACE_STD
30
31#endif // _LIBCPP___TYPE_TRAITS_IS_ABSTRACT_H
lib/libcxx/include/__type_traits/is_aggregate.h created+33
......@@ -0,0 +1,33 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_AGGREGATE_H
10#define _LIBCPP___TYPE_TRAITS_IS_AGGREGATE_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21#if _LIBCPP_STD_VER > 14
22
23template <class _Tp> struct _LIBCPP_TEMPLATE_VIS
24is_aggregate : public integral_constant<bool, __is_aggregate(_Tp)> {};
25
26template <class _Tp>
27inline constexpr bool is_aggregate_v = __is_aggregate(_Tp);
28
29#endif // _LIBCPP_STD_VER > 14
30
31_LIBCPP_END_NAMESPACE_STD
32
33#endif // _LIBCPP___TYPE_TRAITS_IS_AGGREGATE_H
lib/libcxx/include/__type_traits/is_arithmetic.h created+34
......@@ -0,0 +1,34 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_ARITHMETIC_H
10#define _LIBCPP___TYPE_TRAITS_IS_ARITHMETIC_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14#include <__type_traits/is_floating_point.h>
15#include <__type_traits/is_integral.h>
16
17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18# pragma GCC system_header
19#endif
20
21_LIBCPP_BEGIN_NAMESPACE_STD
22
23template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_arithmetic
24 : public integral_constant<bool, is_integral<_Tp>::value ||
25 is_floating_point<_Tp>::value> {};
26
27#if _LIBCPP_STD_VER > 14
28template <class _Tp>
29inline constexpr bool is_arithmetic_v = is_arithmetic<_Tp>::value;
30#endif
31
32_LIBCPP_END_NAMESPACE_STD
33
34#endif // _LIBCPP___TYPE_TRAITS_IS_ARITHMETIC_H
lib/libcxx/include/__type_traits/is_array.h created+52
......@@ -0,0 +1,52 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_ARRAY_H
10#define _LIBCPP___TYPE_TRAITS_IS_ARRAY_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14#include <cstddef>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
20_LIBCPP_BEGIN_NAMESPACE_STD
21
22// TODO: Clang incorrectly reports that __is_array is true for T[0].
23// Re-enable the branch once https://llvm.org/PR54705 is fixed.
24#if __has_builtin(__is_array) && 0
25
26template <class _Tp>
27struct _LIBCPP_TEMPLATE_VIS is_array : _BoolConstant<__is_array(_Tp)> { };
28
29#if _LIBCPP_STD_VER > 14
30template <class _Tp>
31inline constexpr bool is_array_v = __is_array(_Tp);
32#endif
33
34#else
35
36template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_array
37 : public false_type {};
38template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_array<_Tp[]>
39 : public true_type {};
40template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS is_array<_Tp[_Np]>
41 : public true_type {};
42
43#if _LIBCPP_STD_VER > 14
44template <class _Tp>
45inline constexpr bool is_array_v = is_array<_Tp>::value;
46#endif
47
48#endif // __has_builtin(__is_array)
49
50_LIBCPP_END_NAMESPACE_STD
51
52#endif // _LIBCPP___TYPE_TRAITS_IS_ARRAY_H
lib/libcxx/include/__type_traits/is_assignable.h created+66
......@@ -0,0 +1,66 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_ASSIGNABLE_H
10#define _LIBCPP___TYPE_TRAITS_IS_ASSIGNABLE_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21template<typename, typename _Tp> struct __select_2nd { typedef _LIBCPP_NODEBUG _Tp type; };
22
23#if __has_builtin(__is_assignable)
24
25template<class _Tp, class _Up>
26struct _LIBCPP_TEMPLATE_VIS is_assignable : _BoolConstant<__is_assignable(_Tp, _Up)> { };
27
28#if _LIBCPP_STD_VER > 14
29template <class _Tp, class _Arg>
30inline constexpr bool is_assignable_v = __is_assignable(_Tp, _Arg);
31#endif
32
33#else // __has_builtin(__is_assignable)
34
35template <class _Tp, class _Arg>
36typename __select_2nd<decltype((declval<_Tp>() = declval<_Arg>())), true_type>::type
37__is_assignable_test(int);
38
39template <class, class>
40false_type __is_assignable_test(...);
41
42
43template <class _Tp, class _Arg, bool = is_void<_Tp>::value || is_void<_Arg>::value>
44struct __is_assignable_imp
45 : public decltype((_VSTD::__is_assignable_test<_Tp, _Arg>(0))) {};
46
47template <class _Tp, class _Arg>
48struct __is_assignable_imp<_Tp, _Arg, true>
49 : public false_type
50{
51};
52
53template <class _Tp, class _Arg>
54struct is_assignable
55 : public __is_assignable_imp<_Tp, _Arg> {};
56
57#if _LIBCPP_STD_VER > 14
58template <class _Tp, class _Arg>
59inline constexpr bool is_assignable_v = is_assignable<_Tp, _Arg>::value;
60#endif
61
62#endif // __has_builtin(__is_assignable)
63
64_LIBCPP_END_NAMESPACE_STD
65
66#endif // _LIBCPP___TYPE_TRAITS_IS_ASSIGNABLE_H
lib/libcxx/include/__type_traits/is_base_of.h created+32
......@@ -0,0 +1,32 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_BASE_OF_H
10#define _LIBCPP___TYPE_TRAITS_IS_BASE_OF_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21template <class _Bp, class _Dp>
22struct _LIBCPP_TEMPLATE_VIS is_base_of
23 : public integral_constant<bool, __is_base_of(_Bp, _Dp)> {};
24
25#if _LIBCPP_STD_VER > 14
26template <class _Bp, class _Dp>
27inline constexpr bool is_base_of_v = __is_base_of(_Bp, _Dp);
28#endif
29
30_LIBCPP_END_NAMESPACE_STD
31
32#endif // _LIBCPP___TYPE_TRAITS_IS_BASE_OF_H
lib/libcxx/include/__type_traits/is_bounded_array.h created+38
......@@ -0,0 +1,38 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_BOUNDED_ARRAY_H
10#define _LIBCPP___TYPE_TRAITS_IS_BOUNDED_ARRAY_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14#include <cstddef>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
20_LIBCPP_BEGIN_NAMESPACE_STD
21
22template <class> struct _LIBCPP_TEMPLATE_VIS __libcpp_is_bounded_array : false_type {};
23template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS __libcpp_is_bounded_array<_Tp[_Np]> : true_type {};
24
25#if _LIBCPP_STD_VER > 17
26
27template <class> struct _LIBCPP_TEMPLATE_VIS is_bounded_array : false_type {};
28template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS is_bounded_array<_Tp[_Np]> : true_type {};
29
30template <class _Tp>
31inline constexpr
32bool is_bounded_array_v = is_bounded_array<_Tp>::value;
33
34#endif
35
36_LIBCPP_END_NAMESPACE_STD
37
38#endif // _LIBCPP___TYPE_TRAITS_IS_BOUNDED_ARRAY_H
lib/libcxx/include/__type_traits/is_callable.h created+32
......@@ -0,0 +1,32 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_CALLABLE_H
10#define _LIBCPP___TYPE_TRAITS_IS_CALLABLE_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14#include <__utility/declval.h>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
20_LIBCPP_BEGIN_NAMESPACE_STD
21
22template<class _Func, class... _Args, class = decltype(std::declval<_Func>()(std::declval<_Args>()...))>
23true_type __is_callable_helper(int);
24template<class...>
25false_type __is_callable_helper(...);
26
27template<class _Func, class... _Args>
28struct __is_callable : decltype(__is_callable_helper<_Func, _Args...>(0)) {};
29
30_LIBCPP_END_NAMESPACE_STD
31
32#endif // _LIBCPP___TYPE_TRAITS_IS_CALLABLE_H
lib/libcxx/include/__type_traits/is_class.h created+33
......@@ -0,0 +1,33 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_CLASS_H
10#define _LIBCPP___TYPE_TRAITS_IS_CLASS_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14#include <__type_traits/is_union.h>
15#include <__type_traits/remove_cv.h>
16
17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18# pragma GCC system_header
19#endif
20
21_LIBCPP_BEGIN_NAMESPACE_STD
22
23template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_class
24 : public integral_constant<bool, __is_class(_Tp)> {};
25
26#if _LIBCPP_STD_VER > 14
27template <class _Tp>
28inline constexpr bool is_class_v = __is_class(_Tp);
29#endif
30
31_LIBCPP_END_NAMESPACE_STD
32
33#endif // _LIBCPP___TYPE_TRAITS_IS_CLASS_H
lib/libcxx/include/__type_traits/is_compound.h created+46
......@@ -0,0 +1,46 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_COMPOUND_H
10#define _LIBCPP___TYPE_TRAITS_IS_COMPOUND_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14#include <__type_traits/is_fundamental.h>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
20_LIBCPP_BEGIN_NAMESPACE_STD
21
22#if __has_builtin(__is_compound)
23
24template<class _Tp>
25struct _LIBCPP_TEMPLATE_VIS is_compound : _BoolConstant<__is_compound(_Tp)> { };
26
27#if _LIBCPP_STD_VER > 14
28template <class _Tp>
29inline constexpr bool is_compound_v = __is_compound(_Tp);
30#endif
31
32#else // __has_builtin(__is_compound)
33
34template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_compound
35 : public integral_constant<bool, !is_fundamental<_Tp>::value> {};
36
37#if _LIBCPP_STD_VER > 14
38template <class _Tp>
39inline constexpr bool is_compound_v = is_compound<_Tp>::value;
40#endif
41
42#endif // __has_builtin(__is_compound)
43
44_LIBCPP_END_NAMESPACE_STD
45
46#endif // _LIBCPP___TYPE_TRAITS_IS_COMPOUND_H
lib/libcxx/include/__type_traits/is_const.h created+45
......@@ -0,0 +1,45 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_CONST_H
10#define _LIBCPP___TYPE_TRAITS_IS_CONST_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21#if __has_builtin(__is_const)
22
23template <class _Tp>
24struct _LIBCPP_TEMPLATE_VIS is_const : _BoolConstant<__is_const(_Tp)> { };
25
26#if _LIBCPP_STD_VER > 14
27template <class _Tp>
28inline constexpr bool is_const_v = __is_const(_Tp);
29#endif
30
31#else
32
33template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_const : public false_type {};
34template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_const<_Tp const> : public true_type {};
35
36#if _LIBCPP_STD_VER > 14
37template <class _Tp>
38inline constexpr bool is_const_v = is_const<_Tp>::value;
39#endif
40
41#endif // __has_builtin(__is_const)
42
43_LIBCPP_END_NAMESPACE_STD
44
45#endif // _LIBCPP___TYPE_TRAITS_IS_CONST_H
lib/libcxx/include/__type_traits/is_constant_evaluated.h created+32
......@@ -0,0 +1,32 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_CONSTANT_EVALUATED_H
10#define _LIBCPP___TYPE_TRAITS_IS_CONSTANT_EVALUATED_H
11
12#include <__config>
13
14#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15# pragma GCC system_header
16#endif
17
18_LIBCPP_BEGIN_NAMESPACE_STD
19
20#if _LIBCPP_STD_VER > 17
21_LIBCPP_INLINE_VISIBILITY
22inline constexpr bool is_constant_evaluated() noexcept {
23 return __builtin_is_constant_evaluated();
24}
25#endif
26
27inline _LIBCPP_CONSTEXPR
28bool __libcpp_is_constant_evaluated() _NOEXCEPT { return __builtin_is_constant_evaluated(); }
29
30_LIBCPP_END_NAMESPACE_STD
31
32#endif // _LIBCPP___TYPE_TRAITS_IS_CONSTANT_EVALUATED_H
lib/libcxx/include/__type_traits/is_constructible.h created+33
......@@ -0,0 +1,33 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_IS_CONSTRUCTIBLE_H
10#define _LIBCPP___TYPE_IS_CONSTRUCTIBLE_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21template <class _Tp, class ..._Args>
22struct _LIBCPP_TEMPLATE_VIS is_constructible
23 : public integral_constant<bool, __is_constructible(_Tp, _Args...)>
24{ };
25
26#if _LIBCPP_STD_VER > 14
27template <class _Tp, class ..._Args>
28inline constexpr bool is_constructible_v = is_constructible<_Tp, _Args...>::value;
29#endif
30
31_LIBCPP_END_NAMESPACE_STD
32
33#endif // _LIBCPP___TYPE_IS_CONSTRUCTIBLE_H
lib/libcxx/include/__type_traits/is_convertible.h created+108
......@@ -0,0 +1,108 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_CONVERTIBLE_H
10#define _LIBCPP___TYPE_TRAITS_IS_CONVERTIBLE_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14#include <__type_traits/is_array.h>
15#include <__type_traits/is_function.h>
16#include <__type_traits/is_void.h>
17#include <__type_traits/remove_reference.h>
18#include <__utility/declval.h>
19#include <cstddef>
20
21#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22# pragma GCC system_header
23#endif
24
25_LIBCPP_BEGIN_NAMESPACE_STD
26
27#if __has_builtin(__is_convertible_to) && !defined(_LIBCPP_USE_IS_CONVERTIBLE_FALLBACK)
28
29template <class _T1, class _T2> struct _LIBCPP_TEMPLATE_VIS is_convertible
30 : public integral_constant<bool, __is_convertible_to(_T1, _T2)> {};
31
32#else // __has_builtin(__is_convertible_to) && !defined(_LIBCPP_USE_IS_CONVERTIBLE_FALLBACK)
33
34namespace __is_convertible_imp
35{
36template <class _Tp> void __test_convert(_Tp);
37
38template <class _From, class _To, class = void>
39struct __is_convertible_test : public false_type {};
40
41template <class _From, class _To>
42struct __is_convertible_test<_From, _To,
43 decltype(__is_convertible_imp::__test_convert<_To>(declval<_From>()))> : public true_type
44{};
45
46template <class _Tp, bool _IsArray = is_array<_Tp>::value,
47 bool _IsFunction = is_function<_Tp>::value,
48 bool _IsVoid = is_void<_Tp>::value>
49 struct __is_array_function_or_void {enum {value = 0};};
50template <class _Tp> struct __is_array_function_or_void<_Tp, true, false, false> {enum {value = 1};};
51template <class _Tp> struct __is_array_function_or_void<_Tp, false, true, false> {enum {value = 2};};
52template <class _Tp> struct __is_array_function_or_void<_Tp, false, false, true> {enum {value = 3};};
53}
54
55template <class _Tp,
56 unsigned = __is_convertible_imp::__is_array_function_or_void<typename remove_reference<_Tp>::type>::value>
57struct __is_convertible_check
58{
59 static const size_t __v = 0;
60};
61
62template <class _Tp>
63struct __is_convertible_check<_Tp, 0>
64{
65 static const size_t __v = sizeof(_Tp);
66};
67
68template <class _T1, class _T2,
69 unsigned _T1_is_array_function_or_void = __is_convertible_imp::__is_array_function_or_void<_T1>::value,
70 unsigned _T2_is_array_function_or_void = __is_convertible_imp::__is_array_function_or_void<_T2>::value>
71struct __is_convertible
72 : public integral_constant<bool,
73 __is_convertible_imp::__is_convertible_test<_T1, _T2>::value
74 >
75{};
76
77template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 1> : public false_type {};
78template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 1> : public false_type {};
79template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 1> : public false_type {};
80template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 1> : public false_type {};
81
82template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 2> : public false_type {};
83template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 2> : public false_type {};
84template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 2> : public false_type {};
85template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 2> : public false_type {};
86
87template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 3> : public false_type {};
88template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 3> : public false_type {};
89template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 3> : public false_type {};
90template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 3> : public true_type {};
91
92template <class _T1, class _T2> struct _LIBCPP_TEMPLATE_VIS is_convertible
93 : public __is_convertible<_T1, _T2>
94{
95 static const size_t __complete_check1 = __is_convertible_check<_T1>::__v;
96 static const size_t __complete_check2 = __is_convertible_check<_T2>::__v;
97};
98
99#endif // __has_builtin(__is_convertible_to) && !defined(_LIBCPP_USE_IS_CONVERTIBLE_FALLBACK)
100
101#if _LIBCPP_STD_VER > 14
102template <class _From, class _To>
103inline constexpr bool is_convertible_v = is_convertible<_From, _To>::value;
104#endif
105
106_LIBCPP_END_NAMESPACE_STD
107
108#endif // _LIBCPP___TYPE_TRAITS_IS_CONVERTIBLE_H
lib/libcxx/include/__type_traits/is_copy_assignable.h created+35
......@@ -0,0 +1,35 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_COPY_ASSIGNABLE_H
10#define _LIBCPP___TYPE_TRAITS_IS_COPY_ASSIGNABLE_H
11
12#include <__config>
13#include <__type_traits/add_const.h>
14#include <__type_traits/add_lvalue_reference.h>
15#include <__type_traits/integral_constant.h>
16#include <__type_traits/is_assignable.h>
17
18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19# pragma GCC system_header
20#endif
21
22_LIBCPP_BEGIN_NAMESPACE_STD
23
24template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_copy_assignable
25 : public is_assignable<typename add_lvalue_reference<_Tp>::type,
26 typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
27
28#if _LIBCPP_STD_VER > 14
29template <class _Tp>
30inline constexpr bool is_copy_assignable_v = is_copy_assignable<_Tp>::value;
31#endif
32
33_LIBCPP_END_NAMESPACE_STD
34
35#endif // _LIBCPP___TYPE_TRAITS_IS_COPY_ASSIGNABLE_H
lib/libcxx/include/__type_traits/is_copy_constructible.h created+36
......@@ -0,0 +1,36 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_COPY_CONSTRUCTIBLE_H
10#define _LIBCPP___TYPE_TRAITS_IS_COPY_CONSTRUCTIBLE_H
11
12#include <__config>
13#include <__type_traits/add_const.h>
14#include <__type_traits/add_lvalue_reference.h>
15#include <__type_traits/integral_constant.h>
16#include <__type_traits/is_constructible.h>
17
18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19# pragma GCC system_header
20#endif
21
22_LIBCPP_BEGIN_NAMESPACE_STD
23
24template <class _Tp>
25struct _LIBCPP_TEMPLATE_VIS is_copy_constructible
26 : public is_constructible<_Tp,
27 typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
28
29#if _LIBCPP_STD_VER > 14
30template <class _Tp>
31inline constexpr bool is_copy_constructible_v = is_copy_constructible<_Tp>::value;
32#endif
33
34_LIBCPP_END_NAMESPACE_STD
35
36#endif // _LIBCPP___TYPE_TRAITS_IS_COPY_CONSTRUCTIBLE_H
lib/libcxx/include/__type_traits/is_core_convertible.h created+36
......@@ -0,0 +1,36 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_CORE_CONVERTIBLE_H
10#define _LIBCPP___TYPE_TRAITS_IS_CORE_CONVERTIBLE_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21// [conv.general]/3 says "E is convertible to T" whenever "T t=E;" is well-formed.
22// We can't test for that, but we can test implicit convertibility by passing it
23// to a function. Notice that __is_core_convertible<void,void> is false,
24// and __is_core_convertible<immovable-type,immovable-type> is true in C++17 and later.
25
26template <class _Tp, class _Up, class = void>
27struct __is_core_convertible : public false_type {};
28
29template <class _Tp, class _Up>
30struct __is_core_convertible<_Tp, _Up, decltype(
31 static_cast<void(*)(_Up)>(0) ( static_cast<_Tp(*)()>(0)() )
32)> : public true_type {};
33
34_LIBCPP_END_NAMESPACE_STD
35
36#endif // _LIBCPP___TYPE_TRAITS_IS_CORE_CONVERTIBLE_H
lib/libcxx/include/__type_traits/is_default_constructible.h created+34
......@@ -0,0 +1,34 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_DEFAULT_CONSTRUCTIBLE_H
10#define _LIBCPP___TYPE_TRAITS_IS_DEFAULT_CONSTRUCTIBLE_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14#include <__type_traits/is_constructible.h>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
20_LIBCPP_BEGIN_NAMESPACE_STD
21
22template <class _Tp>
23struct _LIBCPP_TEMPLATE_VIS is_default_constructible
24 : public is_constructible<_Tp>
25 {};
26
27#if _LIBCPP_STD_VER > 14
28template <class _Tp>
29inline constexpr bool is_default_constructible_v = is_default_constructible<_Tp>::value;
30#endif
31
32_LIBCPP_END_NAMESPACE_STD
33
34#endif // _LIBCPP___TYPE_TRAITS_IS_DEFAULT_CONSTRUCTIBLE_H
lib/libcxx/include/__type_traits/is_destructible.h created+102
......@@ -0,0 +1,102 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_DESTRUCTIBLE_H
10#define _LIBCPP___TYPE_TRAITS_IS_DESTRUCTIBLE_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14#include <__type_traits/is_function.h>
15#include <__type_traits/is_reference.h>
16#include <__type_traits/remove_all_extents.h>
17#include <__utility/declval.h>
18
19#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20# pragma GCC system_header
21#endif
22
23_LIBCPP_BEGIN_NAMESPACE_STD
24
25#if __has_builtin(__is_destructible)
26
27template<class _Tp>
28struct _LIBCPP_TEMPLATE_VIS is_destructible : _BoolConstant<__is_destructible(_Tp)> { };
29
30#if _LIBCPP_STD_VER > 14
31template <class _Tp>
32inline constexpr bool is_destructible_v = __is_destructible(_Tp);
33#endif
34
35#else // __has_builtin(__is_destructible)
36
37// if it's a reference, return true
38// if it's a function, return false
39// if it's void, return false
40// if it's an array of unknown bound, return false
41// Otherwise, return "declval<_Up&>().~_Up()" is well-formed
42// where _Up is remove_all_extents<_Tp>::type
43
44template <class>
45struct __is_destructible_apply { typedef int type; };
46
47template <typename _Tp>
48struct __is_destructor_wellformed {
49 template <typename _Tp1>
50 static true_type __test (
51 typename __is_destructible_apply<decltype(declval<_Tp1&>().~_Tp1())>::type
52 );
53
54 template <typename _Tp1>
55 static false_type __test (...);
56
57 static const bool value = decltype(__test<_Tp>(12))::value;
58};
59
60template <class _Tp, bool>
61struct __destructible_imp;
62
63template <class _Tp>
64struct __destructible_imp<_Tp, false>
65 : public integral_constant<bool,
66 __is_destructor_wellformed<typename remove_all_extents<_Tp>::type>::value> {};
67
68template <class _Tp>
69struct __destructible_imp<_Tp, true>
70 : public true_type {};
71
72template <class _Tp, bool>
73struct __destructible_false;
74
75template <class _Tp>
76struct __destructible_false<_Tp, false> : public __destructible_imp<_Tp, is_reference<_Tp>::value> {};
77
78template <class _Tp>
79struct __destructible_false<_Tp, true> : public false_type {};
80
81template <class _Tp>
82struct is_destructible
83 : public __destructible_false<_Tp, is_function<_Tp>::value> {};
84
85template <class _Tp>
86struct is_destructible<_Tp[]>
87 : public false_type {};
88
89template <>
90struct is_destructible<void>
91 : public false_type {};
92
93#if _LIBCPP_STD_VER > 14
94template <class _Tp>
95inline constexpr bool is_destructible_v = is_destructible<_Tp>::value;
96#endif
97
98#endif // __has_builtin(__is_destructible)
99
100_LIBCPP_END_NAMESPACE_STD
101
102#endif // _LIBCPP___TYPE_TRAITS_IS_DESTRUCTIBLE_H
lib/libcxx/include/__type_traits/is_empty.h created+32
......@@ -0,0 +1,32 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_EMPTY_H
10#define _LIBCPP___TYPE_TRAITS_IS_EMPTY_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21template <class _Tp>
22struct _LIBCPP_TEMPLATE_VIS is_empty
23 : public integral_constant<bool, __is_empty(_Tp)> {};
24
25#if _LIBCPP_STD_VER > 14
26template <class _Tp>
27inline constexpr bool is_empty_v = __is_empty(_Tp);
28#endif
29
30_LIBCPP_END_NAMESPACE_STD
31
32#endif // _LIBCPP___TYPE_TRAITS_IS_EMPTY_H
lib/libcxx/include/__type_traits/is_enum.h created+32
......@@ -0,0 +1,32 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_ENUM_H
10#define _LIBCPP___TYPE_TRAITS_IS_ENUM_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14#include <__type_traits/remove_cv.h>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
20_LIBCPP_BEGIN_NAMESPACE_STD
21
22template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_enum
23 : public integral_constant<bool, __is_enum(_Tp)> {};
24
25#if _LIBCPP_STD_VER > 14
26template <class _Tp>
27inline constexpr bool is_enum_v = __is_enum(_Tp);
28#endif
29
30_LIBCPP_END_NAMESPACE_STD
31
32#endif // _LIBCPP___TYPE_TRAITS_IS_ENUM_H
lib/libcxx/include/__type_traits/is_final.h created+36
......@@ -0,0 +1,36 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_FINAL_H
10#define _LIBCPP___TYPE_TRAITS_IS_FINAL_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21template <class _Tp> struct _LIBCPP_TEMPLATE_VIS
22__libcpp_is_final : public integral_constant<bool, __is_final(_Tp)> {};
23
24#if _LIBCPP_STD_VER > 11
25template <class _Tp> struct _LIBCPP_TEMPLATE_VIS
26is_final : public integral_constant<bool, __is_final(_Tp)> {};
27#endif
28
29#if _LIBCPP_STD_VER > 14
30template <class _Tp>
31inline constexpr bool is_final_v = __is_final(_Tp);
32#endif
33
34_LIBCPP_END_NAMESPACE_STD
35
36#endif // _LIBCPP___TYPE_TRAITS_IS_FINAL_H
lib/libcxx/include/__type_traits/is_floating_point.h created+37
......@@ -0,0 +1,37 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_FLOATING_POINT_H
10#define _LIBCPP___TYPE_TRAITS_IS_FLOATING_POINT_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14#include <__type_traits/remove_cv.h>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
20_LIBCPP_BEGIN_NAMESPACE_STD
21
22template <class _Tp> struct __libcpp_is_floating_point : public false_type {};
23template <> struct __libcpp_is_floating_point<float> : public true_type {};
24template <> struct __libcpp_is_floating_point<double> : public true_type {};
25template <> struct __libcpp_is_floating_point<long double> : public true_type {};
26
27template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_floating_point
28 : public __libcpp_is_floating_point<typename remove_cv<_Tp>::type> {};
29
30#if _LIBCPP_STD_VER > 14
31template <class _Tp>
32inline constexpr bool is_floating_point_v = is_floating_point<_Tp>::value;
33#endif
34
35_LIBCPP_END_NAMESPACE_STD
36
37#endif // _LIBCPP___TYPE_TRAITS_IS_FLOATING_POINT_H
lib/libcxx/include/__type_traits/is_function.h created+43
......@@ -0,0 +1,43 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_FUNCTIONAL_H
10#define _LIBCPP___TYPE_TRAITS_IS_FUNCTIONAL_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14#include <__type_traits/is_const.h>
15#include <__type_traits/is_reference.h>
16
17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18# pragma GCC system_header
19#endif
20
21_LIBCPP_BEGIN_NAMESPACE_STD
22
23#if __has_builtin(__is_function)
24
25template <class _Tp>
26struct _LIBCPP_TEMPLATE_VIS is_function : integral_constant<bool, __is_function(_Tp)> {};
27
28#else
29
30template <class _Tp>
31struct _LIBCPP_TEMPLATE_VIS is_function
32 : public integral_constant<bool, !(is_reference<_Tp>::value || is_const<const _Tp>::value)> {};
33
34#endif // __has_builtin(__is_function)
35
36#if _LIBCPP_STD_VER > 14
37template <class _Tp>
38inline constexpr bool is_function_v = is_function<_Tp>::value;
39#endif
40
41_LIBCPP_END_NAMESPACE_STD
42
43#endif // _LIBCPP___TYPE_TRAITS_IS_FUNCTIONAL_H
lib/libcxx/include/__type_traits/is_fundamental.h created+49
......@@ -0,0 +1,49 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_FUNDAMENTAL_H
10#define _LIBCPP___TYPE_TRAITS_IS_FUNDAMENTAL_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14#include <__type_traits/is_null_pointer.h>
15#include <__type_traits/is_void.h>
16
17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18# pragma GCC system_header
19#endif
20
21_LIBCPP_BEGIN_NAMESPACE_STD
22
23#if __has_builtin(__is_fundamental)
24
25template<class _Tp>
26struct _LIBCPP_TEMPLATE_VIS is_fundamental : _BoolConstant<__is_fundamental(_Tp)> { };
27
28#if _LIBCPP_STD_VER > 14
29template <class _Tp>
30inline constexpr bool is_fundamental_v = __is_fundamental(_Tp);
31#endif
32
33#else // __has_builtin(__is_fundamental)
34
35template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_fundamental
36 : public integral_constant<bool, is_void<_Tp>::value ||
37 __is_nullptr_t<_Tp>::value ||
38 is_arithmetic<_Tp>::value> {};
39
40#if _LIBCPP_STD_VER > 14
41template <class _Tp>
42inline constexpr bool is_fundamental_v = is_fundamental<_Tp>::value;
43#endif
44
45#endif // __has_builtin(__is_fundamental)
46
47_LIBCPP_END_NAMESPACE_STD
48
49#endif // _LIBCPP___TYPE_TRAITS_IS_FUNDAMENTAL_H
lib/libcxx/include/__type_traits/is_integral.h created+72
......@@ -0,0 +1,72 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_INTEGRAL_H
10#define _LIBCPP___TYPE_TRAITS_IS_INTEGRAL_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14#include <__type_traits/remove_cv.h>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
20_LIBCPP_BEGIN_NAMESPACE_STD
21
22template <class _Tp> struct __libcpp_is_integral { enum { value = 0 }; };
23template <> struct __libcpp_is_integral<bool> { enum { value = 1 }; };
24template <> struct __libcpp_is_integral<char> { enum { value = 1 }; };
25template <> struct __libcpp_is_integral<signed char> { enum { value = 1 }; };
26template <> struct __libcpp_is_integral<unsigned char> { enum { value = 1 }; };
27#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
28template <> struct __libcpp_is_integral<wchar_t> { enum { value = 1 }; };
29#endif
30#ifndef _LIBCPP_HAS_NO_CHAR8_T
31template <> struct __libcpp_is_integral<char8_t> { enum { value = 1 }; };
32#endif
33template <> struct __libcpp_is_integral<char16_t> { enum { value = 1 }; };
34template <> struct __libcpp_is_integral<char32_t> { enum { value = 1 }; };
35template <> struct __libcpp_is_integral<short> { enum { value = 1 }; };
36template <> struct __libcpp_is_integral<unsigned short> { enum { value = 1 }; };
37template <> struct __libcpp_is_integral<int> { enum { value = 1 }; };
38template <> struct __libcpp_is_integral<unsigned int> { enum { value = 1 }; };
39template <> struct __libcpp_is_integral<long> { enum { value = 1 }; };
40template <> struct __libcpp_is_integral<unsigned long> { enum { value = 1 }; };
41template <> struct __libcpp_is_integral<long long> { enum { value = 1 }; };
42template <> struct __libcpp_is_integral<unsigned long long> { enum { value = 1 }; };
43#ifndef _LIBCPP_HAS_NO_INT128
44template <> struct __libcpp_is_integral<__int128_t> { enum { value = 1 }; };
45template <> struct __libcpp_is_integral<__uint128_t> { enum { value = 1 }; };
46#endif
47
48#if __has_builtin(__is_integral)
49
50template <class _Tp>
51struct _LIBCPP_TEMPLATE_VIS is_integral : _BoolConstant<__is_integral(_Tp)> { };
52
53#if _LIBCPP_STD_VER > 14
54template <class _Tp>
55inline constexpr bool is_integral_v = __is_integral(_Tp);
56#endif
57
58#else
59
60template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_integral
61 : public _BoolConstant<__libcpp_is_integral<typename remove_cv<_Tp>::type>::value> {};
62
63#if _LIBCPP_STD_VER > 14
64template <class _Tp>
65inline constexpr bool is_integral_v = is_integral<_Tp>::value;
66#endif
67
68#endif // __has_builtin(__is_integral)
69
70_LIBCPP_END_NAMESPACE_STD
71
72#endif // _LIBCPP___TYPE_TRAITS_IS_INTEGRAL_H
lib/libcxx/include/__type_traits/is_literal_type.h created+34
......@@ -0,0 +1,34 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_LITERAL_TYPE
10#define _LIBCPP___TYPE_TRAITS_IS_LITERAL_TYPE
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS)
22template <class _Tp> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 is_literal_type
23 : public integral_constant<bool, __is_literal_type(_Tp)>
24 {};
25
26#if _LIBCPP_STD_VER > 14
27template <class _Tp>
28_LIBCPP_DEPRECATED_IN_CXX17 inline constexpr bool is_literal_type_v = is_literal_type<_Tp>::value;
29#endif // _LIBCPP_STD_VER > 14
30#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS)
31
32_LIBCPP_END_NAMESPACE_STD
33
34#endif // _LIBCPP___TYPE_TRAITS_IS_LITERAL_TYPE
lib/libcxx/include/__type_traits/is_member_function_pointer.h created+64
......@@ -0,0 +1,64 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_MEMBER_FUNCTION_POINTER_H
10#define _LIBCPP___TYPE_TRAITS_IS_MEMBER_FUNCTION_POINTER_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14#include <__type_traits/is_function.h>
15#include <__type_traits/remove_cv.h>
16#include <cstddef>
17
18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19# pragma GCC system_header
20#endif
21
22_LIBCPP_BEGIN_NAMESPACE_STD
23
24template <class _Tp> struct __libcpp_is_member_pointer {
25 enum {
26 __is_member = false,
27 __is_func = false,
28 __is_obj = false
29 };
30};
31template <class _Tp, class _Up> struct __libcpp_is_member_pointer<_Tp _Up::*> {
32 enum {
33 __is_member = true,
34 __is_func = is_function<_Tp>::value,
35 __is_obj = !__is_func,
36 };
37};
38
39#if __has_builtin(__is_member_function_pointer)
40
41template<class _Tp>
42struct _LIBCPP_TEMPLATE_VIS is_member_function_pointer
43 : _BoolConstant<__is_member_function_pointer(_Tp)> { };
44
45#if _LIBCPP_STD_VER > 14
46template <class _Tp>
47inline constexpr bool is_member_function_pointer_v = __is_member_function_pointer(_Tp);
48#endif
49
50#else // __has_builtin(__is_member_function_pointer)
51
52template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_member_function_pointer
53 : public _BoolConstant< __libcpp_is_member_pointer<typename remove_cv<_Tp>::type>::__is_func > {};
54
55#if _LIBCPP_STD_VER > 14
56template <class _Tp>
57inline constexpr bool is_member_function_pointer_v = is_member_function_pointer<_Tp>::value;
58#endif
59
60#endif // __has_builtin(__is_member_function_pointer)
61
62_LIBCPP_END_NAMESPACE_STD
63
64#endif // _LIBCPP___TYPE_TRAITS_IS_MEMBER_FUNCTION_POINTER_H
lib/libcxx/include/__type_traits/is_member_object_pointer.h created+46
......@@ -0,0 +1,46 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_MEMBER_OBJECT_POINTER_H
10#define _LIBCPP___TYPE_TRAITS_IS_MEMBER_OBJECT_POINTER_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21#if __has_builtin(__is_member_object_pointer)
22
23template<class _Tp>
24struct _LIBCPP_TEMPLATE_VIS is_member_object_pointer
25 : _BoolConstant<__is_member_object_pointer(_Tp)> { };
26
27#if _LIBCPP_STD_VER > 14
28template <class _Tp>
29inline constexpr bool is_member_object_pointer_v = __is_member_object_pointer(_Tp);
30#endif
31
32#else // __has_builtin(__is_member_object_pointer)
33
34template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_member_object_pointer
35 : public _BoolConstant< __libcpp_is_member_pointer<typename remove_cv<_Tp>::type>::__is_obj > {};
36
37#if _LIBCPP_STD_VER > 14
38template <class _Tp>
39inline constexpr bool is_member_object_pointer_v = is_member_object_pointer<_Tp>::value;
40#endif
41
42#endif // __has_builtin(__is_member_object_pointer)
43
44_LIBCPP_END_NAMESPACE_STD
45
46#endif // _LIBCPP___TYPE_TRAITS_IS_MEMBER_FUNCTION_POINTER_H
lib/libcxx/include/__type_traits/is_member_pointer.h created+45
......@@ -0,0 +1,45 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_MEMBER_POINTER_H
10#define _LIBCPP___TYPE_TRAITS_IS_MEMBER_POINTER_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21#if __has_builtin(__is_member_pointer)
22
23template<class _Tp>
24struct _LIBCPP_TEMPLATE_VIS is_member_pointer : _BoolConstant<__is_member_pointer(_Tp)> { };
25
26#if _LIBCPP_STD_VER > 14
27template <class _Tp>
28inline constexpr bool is_member_pointer_v = __is_member_pointer(_Tp);
29#endif
30
31#else // __has_builtin(__is_member_pointer)
32
33template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_member_pointer
34 : public _BoolConstant< __libcpp_is_member_pointer<typename remove_cv<_Tp>::type>::__is_member > {};
35
36#if _LIBCPP_STD_VER > 14
37template <class _Tp>
38inline constexpr bool is_member_pointer_v = is_member_pointer<_Tp>::value;
39#endif
40
41#endif // __has_builtin(__is_member_pointer)
42
43_LIBCPP_END_NAMESPACE_STD
44
45#endif // _LIBCPP___TYPE_TRAITS_IS_MEMBER_POINTER_H
lib/libcxx/include/__type_traits/is_move_assignable.h created+36
......@@ -0,0 +1,36 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_MOVE_ASSIGNABLE_H
10#define _LIBCPP___TYPE_TRAITS_IS_MOVE_ASSIGNABLE_H
11
12#include <__config>
13#include <__type_traits/add_const.h>
14#include <__type_traits/add_lvalue_reference.h>
15#include <__type_traits/add_rvalue_reference.h>
16#include <__type_traits/integral_constant.h>
17#include <__type_traits/is_assignable.h>
18
19#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20# pragma GCC system_header
21#endif
22
23_LIBCPP_BEGIN_NAMESPACE_STD
24
25template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_move_assignable
26 : public is_assignable<typename add_lvalue_reference<_Tp>::type,
27 typename add_rvalue_reference<_Tp>::type> {};
28
29#if _LIBCPP_STD_VER > 14
30template <class _Tp>
31inline constexpr bool is_move_assignable_v = is_move_assignable<_Tp>::value;
32#endif
33
34_LIBCPP_END_NAMESPACE_STD
35
36#endif // _LIBCPP___TYPE_TRAITS_IS_MOVE_ASSIGNABLE_H
lib/libcxx/include/__type_traits/is_move_constructible.h created+35
......@@ -0,0 +1,35 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_MOVE_CONSTRUCTIBLE_H
10#define _LIBCPP___TYPE_TRAITS_IS_MOVE_CONSTRUCTIBLE_H
11
12#include <__config>
13#include <__type_traits/add_rvalue_reference.h>
14#include <__type_traits/integral_constant.h>
15#include <__type_traits/is_constructible.h>
16
17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18# pragma GCC system_header
19#endif
20
21_LIBCPP_BEGIN_NAMESPACE_STD
22
23template <class _Tp>
24struct _LIBCPP_TEMPLATE_VIS is_move_constructible
25 : public is_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
26 {};
27
28#if _LIBCPP_STD_VER > 14
29template <class _Tp>
30inline constexpr bool is_move_constructible_v = is_move_constructible<_Tp>::value;
31#endif
32
33_LIBCPP_END_NAMESPACE_STD
34
35#endif // _LIBCPP___TYPE_TRAITS_IS_MOVE_CONSTRUCTIBLE_H
lib/libcxx/include/__type_traits/is_nothrow_assignable.h created+59
......@@ -0,0 +1,59 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_NOTHROW_ASSIGNABLE_H
10#define _LIBCPP___TYPE_TRAITS_IS_NOTHROW_ASSIGNABLE_H
11
12#include <__config>
13#include <__type_traits/add_const.h>
14#include <__type_traits/integral_constant.h>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
20_LIBCPP_BEGIN_NAMESPACE_STD
21
22#if __has_builtin(__is_nothrow_assignable)
23
24template <class _Tp, class _Arg>
25struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable
26 : public integral_constant<bool, __is_nothrow_assignable(_Tp, _Arg)> {};
27
28#else
29
30template <bool, class _Tp, class _Arg> struct __libcpp_is_nothrow_assignable;
31
32template <class _Tp, class _Arg>
33struct __libcpp_is_nothrow_assignable<false, _Tp, _Arg>
34 : public false_type
35{
36};
37
38template <class _Tp, class _Arg>
39struct __libcpp_is_nothrow_assignable<true, _Tp, _Arg>
40 : public integral_constant<bool, noexcept(declval<_Tp>() = declval<_Arg>()) >
41{
42};
43
44template <class _Tp, class _Arg>
45struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable
46 : public __libcpp_is_nothrow_assignable<is_assignable<_Tp, _Arg>::value, _Tp, _Arg>
47{
48};
49
50#endif // __has_builtin(__is_nothrow_assignable)
51
52#if _LIBCPP_STD_VER > 14
53template <class _Tp, class _Arg>
54inline constexpr bool is_nothrow_assignable_v = is_nothrow_assignable<_Tp, _Arg>::value;
55#endif
56
57_LIBCPP_END_NAMESPACE_STD
58
59#endif // _LIBCPP___TYPE_TRAITS_IS_NOTHROW_ASSIGNABLE_H
lib/libcxx/include/__type_traits/is_nothrow_constructible.h created+75
......@@ -0,0 +1,75 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_NOTHROW_CONSTRUCTIBLE_H
10#define _LIBCPP___TYPE_TRAITS_IS_NOTHROW_CONSTRUCTIBLE_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14#include <__utility/declval.h>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
20_LIBCPP_BEGIN_NAMESPACE_STD
21
22#if __has_builtin(__is_nothrow_constructible)
23
24template <class _Tp, class... _Args>
25struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible
26 : public integral_constant<bool, __is_nothrow_constructible(_Tp, _Args...)> {};
27
28#else
29
30template <bool, bool, class _Tp, class... _Args> struct __libcpp_is_nothrow_constructible;
31
32template <class _Tp, class... _Args>
33struct __libcpp_is_nothrow_constructible</*is constructible*/true, /*is reference*/false, _Tp, _Args...>
34 : public integral_constant<bool, noexcept(_Tp(declval<_Args>()...))>
35{
36};
37
38template <class _Tp>
39void __implicit_conversion_to(_Tp) noexcept { }
40
41template <class _Tp, class _Arg>
42struct __libcpp_is_nothrow_constructible</*is constructible*/true, /*is reference*/true, _Tp, _Arg>
43 : public integral_constant<bool, noexcept(_VSTD::__implicit_conversion_to<_Tp>(declval<_Arg>()))>
44{
45};
46
47template <class _Tp, bool _IsReference, class... _Args>
48struct __libcpp_is_nothrow_constructible</*is constructible*/false, _IsReference, _Tp, _Args...>
49 : public false_type
50{
51};
52
53template <class _Tp, class... _Args>
54struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible
55 : __libcpp_is_nothrow_constructible<is_constructible<_Tp, _Args...>::value, is_reference<_Tp>::value, _Tp, _Args...>
56{
57};
58
59template <class _Tp, size_t _Ns>
60struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp[_Ns]>
61 : __libcpp_is_nothrow_constructible<is_constructible<_Tp>::value, is_reference<_Tp>::value, _Tp>
62{
63};
64
65#endif // __has_builtin(__is_nothrow_constructible)
66
67
68#if _LIBCPP_STD_VER > 14
69template <class _Tp, class ..._Args>
70inline constexpr bool is_nothrow_constructible_v = is_nothrow_constructible<_Tp, _Args...>::value;
71#endif
72
73_LIBCPP_END_NAMESPACE_STD
74
75#endif // _LIBCPP___TYPE_TRAITS_IS_NOTHROW_CONSTRUCTIBLE_H
lib/libcxx/include/__type_traits/is_nothrow_convertible.h created+53
......@@ -0,0 +1,53 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_NOTHROW_CONVERTIBLE_H
10#define _LIBCPP___TYPE_TRAITS_IS_NOTHROW_CONVERTIBLE_H
11
12#include <__config>
13#include <__type_traits/conjunction.h>
14#include <__type_traits/disjunction.h>
15#include <__type_traits/integral_constant.h>
16#include <__type_traits/is_convertible.h>
17#include <__type_traits/is_void.h>
18#include <__type_traits/lazy.h>
19#include <__utility/declval.h>
20
21#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22# pragma GCC system_header
23#endif
24
25_LIBCPP_BEGIN_NAMESPACE_STD
26
27#if _LIBCPP_STD_VER > 17
28
29template <typename _Tp>
30static void __test_noexcept(_Tp) noexcept;
31
32template<typename _Fm, typename _To>
33static bool_constant<noexcept(_VSTD::__test_noexcept<_To>(declval<_Fm>()))>
34__is_nothrow_convertible_test();
35
36template <typename _Fm, typename _To>
37struct __is_nothrow_convertible_helper: decltype(__is_nothrow_convertible_test<_Fm, _To>())
38{ };
39
40template <typename _Fm, typename _To>
41struct is_nothrow_convertible : _Or<
42 _And<is_void<_To>, is_void<_Fm>>,
43 _Lazy<_And, is_convertible<_Fm, _To>, __is_nothrow_convertible_helper<_Fm, _To>>
44>::type { };
45
46template <typename _Fm, typename _To>
47inline constexpr bool is_nothrow_convertible_v = is_nothrow_convertible<_Fm, _To>::value;
48
49#endif // _LIBCPP_STD_VER > 17
50
51_LIBCPP_END_NAMESPACE_STD
52
53#endif // _LIBCPP___TYPE_TRAITS_IS_NOTHROW_CONVERTIBLE_H
lib/libcxx/include/__type_traits/is_nothrow_copy_assignable.h created+35
......@@ -0,0 +1,35 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_NOTHROW_COPY_ASSIGNABLE_H
10#define _LIBCPP___TYPE_TRAITS_IS_NOTHROW_COPY_ASSIGNABLE_H
11
12#include <__config>
13#include <__type_traits/add_const.h>
14#include <__type_traits/add_lvalue_reference.h>
15#include <__type_traits/integral_constant.h>
16#include <__type_traits/is_nothrow_assignable.h>
17
18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19# pragma GCC system_header
20#endif
21
22_LIBCPP_BEGIN_NAMESPACE_STD
23
24template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_copy_assignable
25 : public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type,
26 typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
27
28#if _LIBCPP_STD_VER > 14
29template <class _Tp>
30inline constexpr bool is_nothrow_copy_assignable_v = is_nothrow_copy_assignable<_Tp>::value;
31#endif
32
33_LIBCPP_END_NAMESPACE_STD
34
35#endif // _LIBCPP___TYPE_TRAITS_IS_NOTHROW_COPY_ASSIGNABLE_H
lib/libcxx/include/__type_traits/is_nothrow_copy_constructible.h created+35
......@@ -0,0 +1,35 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_NOTHROW_COPY_CONSTRUCTIBLE_H
10#define _LIBCPP___TYPE_TRAITS_IS_NOTHROW_COPY_CONSTRUCTIBLE_H
11
12#include <__config>
13#include <__type_traits/add_const.h>
14#include <__type_traits/add_lvalue_reference.h>
15#include <__type_traits/integral_constant.h>
16#include <__type_traits/is_nothrow_constructible.h>
17
18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19# pragma GCC system_header
20#endif
21
22_LIBCPP_BEGIN_NAMESPACE_STD
23
24template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_copy_constructible
25 : public is_nothrow_constructible<_Tp,
26 typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
27
28#if _LIBCPP_STD_VER > 14
29template <class _Tp>
30inline constexpr bool is_nothrow_copy_constructible_v = is_nothrow_copy_constructible<_Tp>::value;
31#endif
32
33_LIBCPP_END_NAMESPACE_STD
34
35#endif // _LIBCPP___TYPE_TRAITS_IS_NOTHROW_COPY_CONSTRUCTIBLE_H
lib/libcxx/include/__type_traits/is_nothrow_default_constructible.h created+33
......@@ -0,0 +1,33 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_NOTHROW_DEFAULT_CONSTRUCTIBLE_H
10#define _LIBCPP___TYPE_TRAITS_IS_NOTHROW_DEFAULT_CONSTRUCTIBLE_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14#include <__type_traits/is_nothrow_constructible.h>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
20_LIBCPP_BEGIN_NAMESPACE_STD
21
22template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_default_constructible
23 : public is_nothrow_constructible<_Tp>
24 {};
25
26#if _LIBCPP_STD_VER > 14
27template <class _Tp>
28inline constexpr bool is_nothrow_default_constructible_v = is_nothrow_default_constructible<_Tp>::value;
29#endif
30
31_LIBCPP_END_NAMESPACE_STD
32
33#endif // _LIBCPP___TYPE_TRAITS_IS_NOTHROW_DEFAULT_CONSTRUCTIBLE_H
lib/libcxx/include/__type_traits/is_nothrow_destructible.h created+90
......@@ -0,0 +1,90 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_NOTHROW_DESTRUCTIBLE_H
10#define _LIBCPP___TYPE_TRAITS_IS_NOTHROW_DESTRUCTIBLE_H
11
12#include <__config>
13#include <__type_traits/add_const.h>
14#include <__type_traits/integral_constant.h>
15#include <__type_traits/is_destructible.h>
16#include <__type_traits/is_reference.h>
17#include <__type_traits/is_scalar.h>
18#include <__type_traits/remove_all_extents.h>
19#include <__utility/declval.h>
20#include <cstddef>
21
22#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23# pragma GCC system_header
24#endif
25
26_LIBCPP_BEGIN_NAMESPACE_STD
27
28#if !defined(_LIBCPP_CXX03_LANG)
29
30template <bool, class _Tp> struct __libcpp_is_nothrow_destructible;
31
32template <class _Tp>
33struct __libcpp_is_nothrow_destructible<false, _Tp>
34 : public false_type
35{
36};
37
38template <class _Tp>
39struct __libcpp_is_nothrow_destructible<true, _Tp>
40 : public integral_constant<bool, noexcept(declval<_Tp>().~_Tp()) >
41{
42};
43
44template <class _Tp>
45struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible
46 : public __libcpp_is_nothrow_destructible<is_destructible<_Tp>::value, _Tp>
47{
48};
49
50template <class _Tp, size_t _Ns>
51struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp[_Ns]>
52 : public is_nothrow_destructible<_Tp>
53{
54};
55
56template <class _Tp>
57struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp&>
58 : public true_type
59{
60};
61
62template <class _Tp>
63struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp&&>
64 : public true_type
65{
66};
67
68#else
69
70template <class _Tp> struct __libcpp_nothrow_destructor
71 : public integral_constant<bool, is_scalar<_Tp>::value ||
72 is_reference<_Tp>::value> {};
73
74template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible
75 : public __libcpp_nothrow_destructor<typename remove_all_extents<_Tp>::type> {};
76
77template <class _Tp>
78struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp[]>
79 : public false_type {};
80
81#endif
82
83#if _LIBCPP_STD_VER > 14
84template <class _Tp>
85inline constexpr bool is_nothrow_destructible_v = is_nothrow_destructible<_Tp>::value;
86#endif
87
88_LIBCPP_END_NAMESPACE_STD
89
90#endif // _LIBCPP___TYPE_TRAITS_IS_NOTHROW_DESTRUCTIBLE_H
lib/libcxx/include/__type_traits/is_nothrow_move_assignable.h created+36
......@@ -0,0 +1,36 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_NOTHROW_MOVE_ASSIGNABLE_H
10#define _LIBCPP___TYPE_TRAITS_IS_NOTHROW_MOVE_ASSIGNABLE_H
11
12#include <__config>
13#include <__type_traits/add_lvalue_reference.h>
14#include <__type_traits/add_rvalue_reference.h>
15#include <__type_traits/integral_constant.h>
16#include <__type_traits/is_nothrow_assignable.h>
17
18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19# pragma GCC system_header
20#endif
21
22_LIBCPP_BEGIN_NAMESPACE_STD
23
24template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_move_assignable
25 : public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type,
26 typename add_rvalue_reference<_Tp>::type>
27 {};
28
29#if _LIBCPP_STD_VER > 14
30template <class _Tp>
31inline constexpr bool is_nothrow_move_assignable_v = is_nothrow_move_assignable<_Tp>::value;
32#endif
33
34_LIBCPP_END_NAMESPACE_STD
35
36#endif // _LIBCPP___TYPE_TRAITS_IS_NOTHROW_MOVE_ASSIGNABLE_H
lib/libcxx/include/__type_traits/is_nothrow_move_constructible.h created+34
......@@ -0,0 +1,34 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_NOTHROW_MOVE_CONSTRUCTIBLE_H
10#define _LIBCPP___TYPE_TRAITS_IS_NOTHROW_MOVE_CONSTRUCTIBLE_H
11
12#include <__config>
13#include <__type_traits/add_rvalue_reference.h>
14#include <__type_traits/integral_constant.h>
15#include <__type_traits/is_nothrow_constructible.h>
16
17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18# pragma GCC system_header
19#endif
20
21_LIBCPP_BEGIN_NAMESPACE_STD
22
23template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_move_constructible
24 : public is_nothrow_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
25 {};
26
27#if _LIBCPP_STD_VER > 14
28template <class _Tp>
29inline constexpr bool is_nothrow_move_constructible_v = is_nothrow_move_constructible<_Tp>::value;
30#endif
31
32_LIBCPP_END_NAMESPACE_STD
33
34#endif // _LIBCPP___TYPE_TRAITS_IS_NOTHROW_MOVE_CONSTRUCTIBLE_H
lib/libcxx/include/__type_traits/is_null_pointer.h created+41
......@@ -0,0 +1,41 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_NULL_POINTER_H
10#define _LIBCPP___TYPE_TRAITS_IS_NULL_POINTER_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14#include <__type_traits/remove_cv.h>
15#include <cstddef>
16
17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18# pragma GCC system_header
19#endif
20
21_LIBCPP_BEGIN_NAMESPACE_STD
22
23template <class _Tp> struct __is_nullptr_t_impl : public false_type {};
24template <> struct __is_nullptr_t_impl<nullptr_t> : public true_type {};
25
26template <class _Tp> struct _LIBCPP_TEMPLATE_VIS __is_nullptr_t
27 : public __is_nullptr_t_impl<typename remove_cv<_Tp>::type> {};
28
29#if _LIBCPP_STD_VER > 11
30template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_null_pointer
31 : public __is_nullptr_t_impl<typename remove_cv<_Tp>::type> {};
32
33#if _LIBCPP_STD_VER > 14
34template <class _Tp>
35inline constexpr bool is_null_pointer_v = is_null_pointer<_Tp>::value;
36#endif
37#endif // _LIBCPP_STD_VER > 11
38
39_LIBCPP_END_NAMESPACE_STD
40
41#endif // _LIBCPP___TYPE_TRAITS_IS_NULL_POINTER_H
lib/libcxx/include/__type_traits/is_object.h created+52
......@@ -0,0 +1,52 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_OBJECT_H
10#define _LIBCPP___TYPE_TRAITS_IS_OBJECT_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14#include <__type_traits/is_array.h>
15#include <__type_traits/is_class.h>
16#include <__type_traits/is_scalar.h>
17#include <__type_traits/is_union.h>
18
19#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20# pragma GCC system_header
21#endif
22
23_LIBCPP_BEGIN_NAMESPACE_STD
24
25#if __has_builtin(__is_object)
26
27template<class _Tp>
28struct _LIBCPP_TEMPLATE_VIS is_object : _BoolConstant<__is_object(_Tp)> { };
29
30#if _LIBCPP_STD_VER > 14
31template <class _Tp>
32inline constexpr bool is_object_v = __is_object(_Tp);
33#endif
34
35#else // __has_builtin(__is_object)
36
37template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_object
38 : public integral_constant<bool, is_scalar<_Tp>::value ||
39 is_array<_Tp>::value ||
40 is_union<_Tp>::value ||
41 is_class<_Tp>::value > {};
42
43#if _LIBCPP_STD_VER > 14
44template <class _Tp>
45inline constexpr bool is_object_v = is_object<_Tp>::value;
46#endif
47
48#endif // __has_builtin(__is_object)
49
50_LIBCPP_END_NAMESPACE_STD
51
52#endif // _LIBCPP___TYPE_TRAITS_IS_OBJECT_H
lib/libcxx/include/__type_traits/is_pod.h created+43
......@@ -0,0 +1,43 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_POD_H
10#define _LIBCPP___TYPE_TRAITS_IS_POD_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21#if __has_builtin(__is_pod)
22
23template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_pod
24 : public integral_constant<bool, __is_pod(_Tp)> {};
25
26#else
27
28template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_pod
29 : public integral_constant<bool, is_trivially_default_constructible<_Tp>::value &&
30 is_trivially_copy_constructible<_Tp>::value &&
31 is_trivially_copy_assignable<_Tp>::value &&
32 is_trivially_destructible<_Tp>::value> {};
33
34#endif // __has_builtin(__is_pod)
35
36#if _LIBCPP_STD_VER > 14
37template <class _Tp>
38inline constexpr bool is_pod_v = is_pod<_Tp>::value;
39#endif
40
41_LIBCPP_END_NAMESPACE_STD
42
43#endif // _LIBCPP___TYPE_TRAITS_IS_POD_H
lib/libcxx/include/__type_traits/is_pointer.h created+57
......@@ -0,0 +1,57 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_POINTER_H
10#define _LIBCPP___TYPE_TRAITS_IS_POINTER_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14#include <__type_traits/remove_cv.h>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
20_LIBCPP_BEGIN_NAMESPACE_STD
21
22#if __has_builtin(__is_pointer)
23
24template<class _Tp>
25struct _LIBCPP_TEMPLATE_VIS is_pointer : _BoolConstant<__is_pointer(_Tp)> { };
26
27#if _LIBCPP_STD_VER > 14
28template <class _Tp>
29inline constexpr bool is_pointer_v = __is_pointer(_Tp);
30#endif
31
32#else // __has_builtin(__is_pointer)
33
34template <class _Tp> struct __libcpp_is_pointer : public false_type {};
35template <class _Tp> struct __libcpp_is_pointer<_Tp*> : public true_type {};
36
37template <class _Tp> struct __libcpp_remove_objc_qualifiers { typedef _Tp type; };
38#if defined(_LIBCPP_HAS_OBJC_ARC)
39template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __strong> { typedef _Tp type; };
40template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __weak> { typedef _Tp type; };
41template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __autoreleasing> { typedef _Tp type; };
42template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __unsafe_unretained> { typedef _Tp type; };
43#endif
44
45template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_pointer
46 : public __libcpp_is_pointer<typename __libcpp_remove_objc_qualifiers<typename remove_cv<_Tp>::type>::type> {};
47
48#if _LIBCPP_STD_VER > 14
49template <class _Tp>
50inline constexpr bool is_pointer_v = is_pointer<_Tp>::value;
51#endif
52
53#endif // __has_builtin(__is_pointer)
54
55_LIBCPP_END_NAMESPACE_STD
56
57#endif // _LIBCPP___TYPE_TRAITS_IS_POINTER_H
lib/libcxx/include/__type_traits/is_polymorphic.h created+32
......@@ -0,0 +1,32 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_POLYMORPHIC_H
10#define _LIBCPP___TYPE_TRAITS_IS_POLYMORPHIC_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21template <class _Tp>
22struct _LIBCPP_TEMPLATE_VIS is_polymorphic
23 : public integral_constant<bool, __is_polymorphic(_Tp)> {};
24
25#if _LIBCPP_STD_VER > 14
26template <class _Tp>
27inline constexpr bool is_polymorphic_v = __is_polymorphic(_Tp);
28#endif
29
30_LIBCPP_END_NAMESPACE_STD
31
32#endif // _LIBCPP___TYPE_TRAITS_IS_POLYMORPHIC_H
lib/libcxx/include/__type_traits/is_primary_template.h created+34
......@@ -0,0 +1,34 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_PRIMARY_TEMPLATE_H
10#define _LIBCPP___TYPE_TRAITS_IS_PRIMARY_TEMPLATE_H
11
12#include <__config>
13#include <__type_traits/enable_if.h>
14#include <__type_traits/is_same.h>
15#include <__type_traits/is_valid_expansion.h>
16
17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18# pragma GCC system_header
19#endif
20
21_LIBCPP_BEGIN_NAMESPACE_STD
22
23template <class _Tp>
24using __test_for_primary_template = __enable_if_t<
25 _IsSame<_Tp, typename _Tp::__primary_template>::value
26 >;
27template <class _Tp>
28using __is_primary_template = _IsValidExpansion<
29 __test_for_primary_template, _Tp
30 >;
31
32_LIBCPP_END_NAMESPACE_STD
33
34#endif // _LIBCPP___TYPE_TRAITS_IS_PRIMARY_TEMPLATE_H
lib/libcxx/include/__type_traits/is_reference.h created+70
......@@ -0,0 +1,70 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_REFERENCE_H
10#define _LIBCPP___TYPE_TRAITS_IS_REFERENCE_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21#if __has_builtin(__is_lvalue_reference) && \
22 __has_builtin(__is_rvalue_reference) && \
23 __has_builtin(__is_reference)
24
25template<class _Tp>
26struct _LIBCPP_TEMPLATE_VIS is_lvalue_reference : _BoolConstant<__is_lvalue_reference(_Tp)> { };
27
28template<class _Tp>
29struct _LIBCPP_TEMPLATE_VIS is_rvalue_reference : _BoolConstant<__is_rvalue_reference(_Tp)> { };
30
31template<class _Tp>
32struct _LIBCPP_TEMPLATE_VIS is_reference : _BoolConstant<__is_reference(_Tp)> { };
33
34#if _LIBCPP_STD_VER > 14
35template <class _Tp>
36inline constexpr bool is_reference_v = __is_reference(_Tp);
37template <class _Tp>
38inline constexpr bool is_lvalue_reference_v = __is_lvalue_reference(_Tp);
39template <class _Tp>
40inline constexpr bool is_rvalue_reference_v = __is_rvalue_reference(_Tp);
41#endif
42
43#else // __has_builtin(__is_lvalue_reference) && etc...
44
45template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_lvalue_reference : public false_type {};
46template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_lvalue_reference<_Tp&> : public true_type {};
47
48template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_rvalue_reference : public false_type {};
49template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_rvalue_reference<_Tp&&> : public true_type {};
50
51template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_reference : public false_type {};
52template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_reference<_Tp&> : public true_type {};
53template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_reference<_Tp&&> : public true_type {};
54
55#if _LIBCPP_STD_VER > 14
56template <class _Tp>
57inline constexpr bool is_reference_v = is_reference<_Tp>::value;
58
59template <class _Tp>
60inline constexpr bool is_lvalue_reference_v = is_lvalue_reference<_Tp>::value;
61
62template <class _Tp>
63inline constexpr bool is_rvalue_reference_v = is_rvalue_reference<_Tp>::value;
64#endif
65
66#endif // __has_builtin(__is_lvalue_reference) && etc...
67
68_LIBCPP_END_NAMESPACE_STD
69
70#endif // _LIBCPP___TYPE_TRAITS_IS_REFERENCE_H
lib/libcxx/include/__type_traits/is_reference_wrapper.h created+31
......@@ -0,0 +1,31 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_REFERENCE_WRAPPER_H
10#define _LIBCPP___TYPE_TRAITS_IS_REFERENCE_WRAPPER_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14#include <__type_traits/remove_cv.h>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
20_LIBCPP_BEGIN_NAMESPACE_STD
21
22template <class _Tp> class _LIBCPP_TEMPLATE_VIS reference_wrapper;
23
24template <class _Tp> struct __is_reference_wrapper_impl : public false_type {};
25template <class _Tp> struct __is_reference_wrapper_impl<reference_wrapper<_Tp> > : public true_type {};
26template <class _Tp> struct __is_reference_wrapper
27 : public __is_reference_wrapper_impl<typename remove_cv<_Tp>::type> {};
28
29_LIBCPP_END_NAMESPACE_STD
30
31#endif // _LIBCPP___TYPE_TRAITS_ENABLE_IF_H
lib/libcxx/include/__type_traits/is_referenceable.h created+33
......@@ -0,0 +1,33 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_REFERENCEABLE_H
10#define _LIBCPP___TYPE_TRAITS_IS_REFERENCEABLE_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14#include <__type_traits/is_same.h>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
20_LIBCPP_BEGIN_NAMESPACE_STD
21
22struct __is_referenceable_impl {
23 template <class _Tp> static _Tp& __test(int);
24 template <class _Tp> static false_type __test(...);
25};
26
27template <class _Tp>
28struct __is_referenceable : integral_constant<bool,
29 _IsNotSame<decltype(__is_referenceable_impl::__test<_Tp>(0)), false_type>::value> {};
30
31_LIBCPP_END_NAMESPACE_STD
32
33#endif // _LIBCPP___TYPE_TRAITS_IS_REFERENCEABLE_H
lib/libcxx/include/__type_traits/is_same.h created+44
......@@ -0,0 +1,44 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_SAME_H
10#define _LIBCPP___TYPE_TRAITS_IS_SAME_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21template <class _Tp, class _Up>
22struct _LIBCPP_TEMPLATE_VIS is_same : _BoolConstant<__is_same(_Tp, _Up)> { };
23
24#if _LIBCPP_STD_VER > 14
25template <class _Tp, class _Up>
26inline constexpr bool is_same_v = __is_same(_Tp, _Up);
27#endif
28
29// _IsSame<T,U> has the same effect as is_same<T,U> but instantiates fewer types:
30// is_same<A,B> and is_same<C,D> are guaranteed to be different types, but
31// _IsSame<A,B> and _IsSame<C,D> are the same type (namely, false_type).
32// Neither GCC nor Clang can mangle the __is_same builtin, so _IsSame
33// mustn't be directly used anywhere that contributes to name-mangling
34// (such as in a dependent return type).
35
36template <class _Tp, class _Up>
37using _IsSame = _BoolConstant<__is_same(_Tp, _Up)>;
38
39template <class _Tp, class _Up>
40using _IsNotSame = _BoolConstant<!__is_same(_Tp, _Up)>;
41
42_LIBCPP_END_NAMESPACE_STD
43
44#endif // _LIBCPP___TYPE_TRAITS_IS_SAME_H
lib/libcxx/include/__type_traits/is_scalar.h created+61
......@@ -0,0 +1,61 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_SCALAR_H
10#define _LIBCPP___TYPE_TRAITS_IS_SCALAR_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14#include <__type_traits/is_arithmetic.h>
15#include <__type_traits/is_enum.h>
16#include <__type_traits/is_member_pointer.h>
17#include <__type_traits/is_pointer.h>
18
19#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20# pragma GCC system_header
21#endif
22
23_LIBCPP_BEGIN_NAMESPACE_STD
24
25#if __has_builtin(__is_scalar)
26
27template<class _Tp>
28struct _LIBCPP_TEMPLATE_VIS is_scalar : _BoolConstant<__is_scalar(_Tp)> { };
29
30#if _LIBCPP_STD_VER > 14
31template <class _Tp>
32inline constexpr bool is_scalar_v = __is_scalar(_Tp);
33#endif
34
35#else // __has_builtin(__is_scalar)
36
37template <class _Tp> struct __is_block : false_type {};
38#if defined(_LIBCPP_HAS_EXTENSION_BLOCKS)
39template <class _Rp, class ..._Args> struct __is_block<_Rp (^)(_Args...)> : true_type {};
40#endif
41
42template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_scalar
43 : public integral_constant<bool, is_arithmetic<_Tp>::value ||
44 is_member_pointer<_Tp>::value ||
45 is_pointer<_Tp>::value ||
46 __is_nullptr_t<_Tp>::value ||
47 __is_block<_Tp>::value ||
48 is_enum<_Tp>::value > {};
49
50template <> struct _LIBCPP_TEMPLATE_VIS is_scalar<nullptr_t> : public true_type {};
51
52#if _LIBCPP_STD_VER > 14
53template <class _Tp>
54inline constexpr bool is_scalar_v = is_scalar<_Tp>::value;
55#endif
56
57#endif // __has_builtin(__is_scalar)
58
59_LIBCPP_END_NAMESPACE_STD
60
61#endif // _LIBCPP___TYPE_TRAITS_IS_SCALAR_H
lib/libcxx/include/__type_traits/is_scoped_enum.h created+42
......@@ -0,0 +1,42 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_SCOPED_ENUM_H
10#define _LIBCPP___TYPE_TRAITS_IS_SCOPED_ENUM_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14#include <__type_traits/is_convertible.h>
15#include <__type_traits/is_enum.h>
16#include <__type_traits/underlying_type.h>
17
18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19# pragma GCC system_header
20#endif
21
22_LIBCPP_BEGIN_NAMESPACE_STD
23
24#if _LIBCPP_STD_VER > 20
25template <class _Tp, bool = is_enum_v<_Tp> >
26struct __is_scoped_enum_helper : false_type {};
27
28template <class _Tp>
29struct __is_scoped_enum_helper<_Tp, true>
30 : public bool_constant<!is_convertible_v<_Tp, underlying_type_t<_Tp> > > {};
31
32template <class _Tp>
33struct _LIBCPP_TEMPLATE_VIS is_scoped_enum
34 : public __is_scoped_enum_helper<_Tp> {};
35
36template <class _Tp>
37inline constexpr bool is_scoped_enum_v = is_scoped_enum<_Tp>::value;
38#endif
39
40_LIBCPP_END_NAMESPACE_STD
41
42#endif // _LIBCPP___TYPE_TRAITS_IS_SCOPED_ENUM_H
lib/libcxx/include/__type_traits/is_signed.h created+55
......@@ -0,0 +1,55 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_SIGNED_H
10#define _LIBCPP___TYPE_TRAITS_IS_SIGNED_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21#if __has_builtin(__is_signed)
22
23template<class _Tp>
24struct _LIBCPP_TEMPLATE_VIS is_signed : _BoolConstant<__is_signed(_Tp)> { };
25
26#if _LIBCPP_STD_VER > 14
27template <class _Tp>
28inline constexpr bool is_signed_v = __is_signed(_Tp);
29#endif
30
31#else // __has_builtin(__is_signed)
32
33template <class _Tp, bool = is_integral<_Tp>::value>
34struct __libcpp_is_signed_impl : public _BoolConstant<(_Tp(-1) < _Tp(0))> {};
35
36template <class _Tp>
37struct __libcpp_is_signed_impl<_Tp, false> : public true_type {}; // floating point
38
39template <class _Tp, bool = is_arithmetic<_Tp>::value>
40struct __libcpp_is_signed : public __libcpp_is_signed_impl<_Tp> {};
41
42template <class _Tp> struct __libcpp_is_signed<_Tp, false> : public false_type {};
43
44template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_signed : public __libcpp_is_signed<_Tp> {};
45
46#if _LIBCPP_STD_VER > 14
47template <class _Tp>
48inline constexpr bool is_signed_v = is_signed<_Tp>::value;
49#endif
50
51#endif // __has_builtin(__is_signed)
52
53_LIBCPP_END_NAMESPACE_STD
54
55#endif // _LIBCPP___TYPE_TRAITS_IS_SIGNED_H
lib/libcxx/include/__type_traits/is_signed_integer.h created+33
......@@ -0,0 +1,33 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_SIGNED_INTEGER_H
10#define _LIBCPP___TYPE_TRAITS_IS_SIGNED_INTEGER_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21template <class _Tp> struct __libcpp_is_signed_integer : public false_type {};
22template <> struct __libcpp_is_signed_integer<signed char> : public true_type {};
23template <> struct __libcpp_is_signed_integer<signed short> : public true_type {};
24template <> struct __libcpp_is_signed_integer<signed int> : public true_type {};
25template <> struct __libcpp_is_signed_integer<signed long> : public true_type {};
26template <> struct __libcpp_is_signed_integer<signed long long> : public true_type {};
27#ifndef _LIBCPP_HAS_NO_INT128
28template <> struct __libcpp_is_signed_integer<__int128_t> : public true_type {};
29#endif
30
31_LIBCPP_END_NAMESPACE_STD
32
33#endif // _LIBCPP___TYPE_TRAITS_IS_SIGNED_INTEGER_H
lib/libcxx/include/__type_traits/is_standard_layout.h created+36
......@@ -0,0 +1,36 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_STANDARD_LAYOUT_H
10#define _LIBCPP___TYPE_TRAITS_IS_STANDARD_LAYOUT_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_standard_layout
22#if __has_builtin(__is_standard_layout)
23 : public integral_constant<bool, __is_standard_layout(_Tp)>
24#else
25 : integral_constant<bool, is_scalar<typename remove_all_extents<_Tp>::type>::value>
26#endif
27 {};
28
29#if _LIBCPP_STD_VER > 14
30template <class _Tp>
31inline constexpr bool is_standard_layout_v = is_standard_layout<_Tp>::value;
32#endif
33
34_LIBCPP_END_NAMESPACE_STD
35
36#endif // _LIBCPP___TYPE_TRAITS_IS_STANDARD_LAYOUT_H
lib/libcxx/include/__type_traits/is_trivial.h created+37
......@@ -0,0 +1,37 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_TRIVIAL_H
10#define _LIBCPP___TYPE_TRAITS_IS_TRIVIAL_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivial
22#if __has_builtin(__is_trivial)
23 : public integral_constant<bool, __is_trivial(_Tp)>
24#else
25 : integral_constant<bool, is_trivially_copyable<_Tp>::value &&
26 is_trivially_default_constructible<_Tp>::value>
27#endif
28 {};
29
30#if _LIBCPP_STD_VER > 14
31template <class _Tp>
32inline constexpr bool is_trivial_v = is_trivial<_Tp>::value;
33#endif
34
35_LIBCPP_END_NAMESPACE_STD
36
37#endif // _LIBCPP___TYPE_TRAITS_IS_TRIVIAL_H
lib/libcxx/include/__type_traits/is_trivially_assignable.h created+33
......@@ -0,0 +1,33 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_TRIVIALLY_ASSIGNABLE_H
10#define _LIBCPP___TYPE_TRAITS_IS_TRIVIALLY_ASSIGNABLE_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21template <class _Tp, class _Arg>
22struct is_trivially_assignable
23 : integral_constant<bool, __is_trivially_assignable(_Tp, _Arg)>
24{ };
25
26#if _LIBCPP_STD_VER > 14
27template <class _Tp, class _Arg>
28inline constexpr bool is_trivially_assignable_v = is_trivially_assignable<_Tp, _Arg>::value;
29#endif
30
31_LIBCPP_END_NAMESPACE_STD
32
33#endif // _LIBCPP___TYPE_TRAITS_IS_TRIVIALLY_ASSIGNABLE_H
lib/libcxx/include/__type_traits/is_trivially_constructible.h created+34
......@@ -0,0 +1,34 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_TRIVIALLY_CONSTRUCTIBLE_H
10#define _LIBCPP___TYPE_TRAITS_IS_TRIVIALLY_CONSTRUCTIBLE_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21template <class _Tp, class... _Args>
22struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible
23 : integral_constant<bool, __is_trivially_constructible(_Tp, _Args...)>
24{
25};
26
27#if _LIBCPP_STD_VER > 14
28template <class _Tp, class... _Args>
29inline constexpr bool is_trivially_constructible_v = is_trivially_constructible<_Tp, _Args...>::value;
30#endif
31
32_LIBCPP_END_NAMESPACE_STD
33
34#endif // _LIBCPP___TYPE_TRAITS_IS_TRIVIALLY_CONSTRUCTIBLE_H
lib/libcxx/include/__type_traits/is_trivially_copy_assignable.h created+35
......@@ -0,0 +1,35 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_TRIVIALLY_COPY_ASSIGNABLE_H
10#define _LIBCPP___TYPE_TRAITS_IS_TRIVIALLY_COPY_ASSIGNABLE_H
11
12#include <__config>
13#include <__type_traits/add_const.h>
14#include <__type_traits/add_lvalue_reference.h>
15#include <__type_traits/integral_constant.h>
16#include <__type_traits/is_trivially_assignable.h>
17
18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19# pragma GCC system_header
20#endif
21
22_LIBCPP_BEGIN_NAMESPACE_STD
23
24template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_copy_assignable
25 : public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type,
26 typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
27
28#if _LIBCPP_STD_VER > 14
29template <class _Tp>
30inline constexpr bool is_trivially_copy_assignable_v = is_trivially_copy_assignable<_Tp>::value;
31#endif
32
33_LIBCPP_END_NAMESPACE_STD
34
35#endif // _LIBCPP___TYPE_TRAITS_IS_TRIVIALLY_COPY_ASSIGNABLE_H
lib/libcxx/include/__type_traits/is_trivially_copy_constructible.h created+34
......@@ -0,0 +1,34 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_TRIVIALLY_COPY_CONSTRUCTIBLE_H
10#define _LIBCPP___TYPE_TRAITS_IS_TRIVIALLY_COPY_CONSTRUCTIBLE_H
11
12#include <__config>
13#include <__type_traits/add_lvalue_reference.h>
14#include <__type_traits/integral_constant.h>
15#include <__type_traits/is_trivially_constructible.h>
16
17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18# pragma GCC system_header
19#endif
20
21_LIBCPP_BEGIN_NAMESPACE_STD
22
23template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_copy_constructible
24 : public is_trivially_constructible<_Tp, typename add_lvalue_reference<const _Tp>::type>
25 {};
26
27#if _LIBCPP_STD_VER > 14
28template <class _Tp>
29inline constexpr bool is_trivially_copy_constructible_v = is_trivially_copy_constructible<_Tp>::value;
30#endif
31
32_LIBCPP_END_NAMESPACE_STD
33
34#endif // _LIBCPP___TYPE_TRAITS_IS_TRIVIALLY_COPY_CONSTRUCTIBLE_H
lib/libcxx/include/__type_traits/is_trivially_copyable.h created+32
......@@ -0,0 +1,32 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_TRIVIALLY_COPYABLE_H
10#define _LIBCPP___TYPE_TRAITS_IS_TRIVIALLY_COPYABLE_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_copyable
22 : public integral_constant<bool, __is_trivially_copyable(_Tp)>
23 {};
24
25#if _LIBCPP_STD_VER > 14
26template <class _Tp>
27inline constexpr bool is_trivially_copyable_v = is_trivially_copyable<_Tp>::value;
28#endif
29
30_LIBCPP_END_NAMESPACE_STD
31
32#endif // _LIBCPP___TYPE_TRAITS_IS_TRIVIALLY_COPYABLE_H
lib/libcxx/include/__type_traits/is_trivially_default_constructible.h created+33
......@@ -0,0 +1,33 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_TRIVIALLY_DEFAULT_CONSTRUCTIBLE_H
10#define _LIBCPP___TYPE_TRAITS_IS_TRIVIALLY_DEFAULT_CONSTRUCTIBLE_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14#include <__type_traits/is_trivially_constructible.h>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
20_LIBCPP_BEGIN_NAMESPACE_STD
21
22template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_default_constructible
23 : public is_trivially_constructible<_Tp>
24 {};
25
26#if _LIBCPP_STD_VER > 14
27template <class _Tp>
28inline constexpr bool is_trivially_default_constructible_v = is_trivially_default_constructible<_Tp>::value;
29#endif
30
31_LIBCPP_END_NAMESPACE_STD
32
33#endif // _LIBCPP___TYPE_TRAITS_IS_TRIVIALLY_DEFAULT_CONSTRUCTIBLE_H
lib/libcxx/include/__type_traits/is_trivially_destructible.h created+52
......@@ -0,0 +1,52 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_TRIVIALLY_DESTRUCTIBLE_H
10#define _LIBCPP___TYPE_TRAITS_IS_TRIVIALLY_DESTRUCTIBLE_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21#if __has_builtin(__is_trivially_destructible)
22
23template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible
24 : public integral_constant<bool, __is_trivially_destructible(_Tp)> {};
25
26#elif __has_builtin(__has_trivial_destructor)
27
28template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible
29 : public integral_constant<bool, is_destructible<_Tp>::value && __has_trivial_destructor(_Tp)> {};
30
31#else
32
33template <class _Tp> struct __libcpp_trivial_destructor
34 : public integral_constant<bool, is_scalar<_Tp>::value ||
35 is_reference<_Tp>::value> {};
36
37template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible
38 : public __libcpp_trivial_destructor<typename remove_all_extents<_Tp>::type> {};
39
40template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible<_Tp[]>
41 : public false_type {};
42
43#endif // __has_builtin(__is_trivially_destructible)
44
45#if _LIBCPP_STD_VER > 14
46template <class _Tp>
47inline constexpr bool is_trivially_destructible_v = is_trivially_destructible<_Tp>::value;
48#endif
49
50_LIBCPP_END_NAMESPACE_STD
51
52#endif // _LIBCPP___TYPE_TRAITS_IS_TRIVIALLY_DESTRUCTIBLE_H
lib/libcxx/include/__type_traits/is_trivially_move_assignable.h created+36
......@@ -0,0 +1,36 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_TRIVIALLY_MOVE_ASSIGNABLE_H
10#define _LIBCPP___TYPE_TRAITS_IS_TRIVIALLY_MOVE_ASSIGNABLE_H
11
12#include <__config>
13#include <__type_traits/add_lvalue_reference.h>
14#include <__type_traits/add_rvalue_reference.h>
15#include <__type_traits/integral_constant.h>
16#include <__type_traits/is_trivially_assignable.h>
17
18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19# pragma GCC system_header
20#endif
21
22_LIBCPP_BEGIN_NAMESPACE_STD
23
24template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_move_assignable
25 : public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type,
26 typename add_rvalue_reference<_Tp>::type>
27 {};
28
29#if _LIBCPP_STD_VER > 14
30template <class _Tp>
31inline constexpr bool is_trivially_move_assignable_v = is_trivially_move_assignable<_Tp>::value;
32#endif
33
34_LIBCPP_END_NAMESPACE_STD
35
36#endif // _LIBCPP___TYPE_TRAITS_IS_TRIVIALLY_MOVE_ASSIGNABLE_H
lib/libcxx/include/__type_traits/is_trivially_move_constructible.h created+34
......@@ -0,0 +1,34 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_TRIVIALLY_MOVE_CONSTRUCTIBLE_H
10#define _LIBCPP___TYPE_TRAITS_IS_TRIVIALLY_MOVE_CONSTRUCTIBLE_H
11
12#include <__config>
13#include <__type_traits/add_rvalue_reference.h>
14#include <__type_traits/integral_constant.h>
15#include <__type_traits/is_trivially_constructible.h>
16
17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18# pragma GCC system_header
19#endif
20
21_LIBCPP_BEGIN_NAMESPACE_STD
22
23template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_move_constructible
24 : public is_trivially_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
25 {};
26
27#if _LIBCPP_STD_VER > 14
28template <class _Tp>
29inline constexpr bool is_trivially_move_constructible_v = is_trivially_move_constructible<_Tp>::value;
30#endif
31
32_LIBCPP_END_NAMESPACE_STD
33
34#endif // _LIBCPP___TYPE_TRAITS_IS_TRIVIALLY_MOVE_CONSTRUCTIBLE_H
lib/libcxx/include/__type_traits/is_unbounded_array.h created+37
......@@ -0,0 +1,37 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_UNBOUNDED_ARRAY_H
10#define _LIBCPP___TYPE_TRAITS_IS_UNBOUNDED_ARRAY_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21template <class> struct _LIBCPP_TEMPLATE_VIS __libcpp_is_unbounded_array : false_type {};
22template <class _Tp> struct _LIBCPP_TEMPLATE_VIS __libcpp_is_unbounded_array<_Tp[]> : true_type {};
23
24#if _LIBCPP_STD_VER > 17
25
26template <class> struct _LIBCPP_TEMPLATE_VIS is_unbounded_array : false_type {};
27template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_unbounded_array<_Tp[]> : true_type {};
28
29template <class _Tp>
30inline constexpr
31bool is_unbounded_array_v = is_unbounded_array<_Tp>::value;
32
33#endif
34
35_LIBCPP_END_NAMESPACE_STD
36
37#endif // _LIBCPP___TYPE_TRAITS_IS_UNBOUNDED_ARRAY_H
lib/libcxx/include/__type_traits/is_union.h created+32
......@@ -0,0 +1,32 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_UNION_H
10#define _LIBCPP___TYPE_TRAITS_IS_UNION_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14#include <__type_traits/remove_cv.h>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
20_LIBCPP_BEGIN_NAMESPACE_STD
21
22template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_union
23 : public integral_constant<bool, __is_union(_Tp)> {};
24
25#if _LIBCPP_STD_VER > 14
26template <class _Tp>
27inline constexpr bool is_union_v = __is_union(_Tp);
28#endif
29
30_LIBCPP_END_NAMESPACE_STD
31
32#endif // _LIBCPP___TYPE_TRAITS_IS_UNION_H
lib/libcxx/include/__type_traits/is_unsigned.h created+58
......@@ -0,0 +1,58 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_UNSIGNED_H
10#define _LIBCPP___TYPE_TRAITS_IS_UNSIGNED_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14#include <__type_traits/is_arithmetic.h>
15#include <__type_traits/is_integral.h>
16
17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18# pragma GCC system_header
19#endif
20
21_LIBCPP_BEGIN_NAMESPACE_STD
22
23// Before AppleClang 14, __is_unsigned returned true for enums with signed underlying type.
24#if __has_builtin(__is_unsigned) && !(defined(_LIBCPP_APPLE_CLANG_VER) && _LIBCPP_APPLE_CLANG_VER < 1400)
25
26template<class _Tp>
27struct _LIBCPP_TEMPLATE_VIS is_unsigned : _BoolConstant<__is_unsigned(_Tp)> { };
28
29#if _LIBCPP_STD_VER > 14
30template <class _Tp>
31inline constexpr bool is_unsigned_v = __is_unsigned(_Tp);
32#endif
33
34#else // __has_builtin(__is_unsigned)
35
36template <class _Tp, bool = is_integral<_Tp>::value>
37struct __libcpp_is_unsigned_impl : public _BoolConstant<(_Tp(0) < _Tp(-1))> {};
38
39template <class _Tp>
40struct __libcpp_is_unsigned_impl<_Tp, false> : public false_type {}; // floating point
41
42template <class _Tp, bool = is_arithmetic<_Tp>::value>
43struct __libcpp_is_unsigned : public __libcpp_is_unsigned_impl<_Tp> {};
44
45template <class _Tp> struct __libcpp_is_unsigned<_Tp, false> : public false_type {};
46
47template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_unsigned : public __libcpp_is_unsigned<_Tp> {};
48
49#if _LIBCPP_STD_VER > 14
50template <class _Tp>
51inline constexpr bool is_unsigned_v = is_unsigned<_Tp>::value;
52#endif
53
54#endif // __has_builtin(__is_unsigned)
55
56_LIBCPP_END_NAMESPACE_STD
57
58#endif // _LIBCPP___TYPE_TRAITS_IS_UNSIGNED_H
lib/libcxx/include/__type_traits/is_unsigned_integer.h created+33
......@@ -0,0 +1,33 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_UNSIGNED_INTEGER_H
10#define _LIBCPP___TYPE_TRAITS_IS_UNSIGNED_INTEGER_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21template <class _Tp> struct __libcpp_is_unsigned_integer : public false_type {};
22template <> struct __libcpp_is_unsigned_integer<unsigned char> : public true_type {};
23template <> struct __libcpp_is_unsigned_integer<unsigned short> : public true_type {};
24template <> struct __libcpp_is_unsigned_integer<unsigned int> : public true_type {};
25template <> struct __libcpp_is_unsigned_integer<unsigned long> : public true_type {};
26template <> struct __libcpp_is_unsigned_integer<unsigned long long> : public true_type {};
27#ifndef _LIBCPP_HAS_NO_INT128
28template <> struct __libcpp_is_unsigned_integer<__uint128_t> : public true_type {};
29#endif
30
31_LIBCPP_END_NAMESPACE_STD
32
33#endif // _LIBCPP___TYPE_TRAITS_IS_UNSIGNED_INTEGER_H
lib/libcxx/include/__type_traits/is_valid_expansion.h created+31
......@@ -0,0 +1,31 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_VALID_EXPANSION_H
10#define _LIBCPP___TYPE_TRAITS_IS_VALID_EXPANSION_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21template <template <class...> class _Templ, class ..._Args, class = _Templ<_Args...> >
22true_type __sfinae_test_impl(int);
23template <template <class...> class, class ...>
24false_type __sfinae_test_impl(...);
25
26template <template <class ...> class _Templ, class ..._Args>
27using _IsValidExpansion _LIBCPP_NODEBUG = decltype(__sfinae_test_impl<_Templ, _Args...>(0));
28
29_LIBCPP_END_NAMESPACE_STD
30
31#endif // _LIBCPP___TYPE_TRAITS_IS_VALID_EXPANSION_H
lib/libcxx/include/__type_traits/is_void.h created+45
......@@ -0,0 +1,45 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_VOID_H
10#define _LIBCPP___TYPE_TRAITS_IS_VOID_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21#if __has_builtin(__is_void)
22
23template <class _Tp>
24struct _LIBCPP_TEMPLATE_VIS is_void : _BoolConstant<__is_void(_Tp)> { };
25
26#if _LIBCPP_STD_VER > 14
27template <class _Tp>
28inline constexpr bool is_void_v = __is_void(_Tp);
29#endif
30
31#else
32
33template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_void
34 : public is_same<typename remove_cv<_Tp>::type, void> {};
35
36#if _LIBCPP_STD_VER > 14
37template <class _Tp>
38inline constexpr bool is_void_v = is_void<_Tp>::value;
39#endif
40
41#endif // __has_builtin(__is_void)
42
43_LIBCPP_END_NAMESPACE_STD
44
45#endif // _LIBCPP___TYPE_TRAITS_IS_VOID_H
lib/libcxx/include/__type_traits/is_volatile.h created+45
......@@ -0,0 +1,45 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_VOLATILE_H
10#define _LIBCPP___TYPE_TRAITS_IS_VOLATILE_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21#if __has_builtin(__is_volatile)
22
23template <class _Tp>
24struct _LIBCPP_TEMPLATE_VIS is_volatile : _BoolConstant<__is_volatile(_Tp)> { };
25
26#if _LIBCPP_STD_VER > 14
27template <class _Tp>
28inline constexpr bool is_volatile_v = __is_volatile(_Tp);
29#endif
30
31#else
32
33template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_volatile : public false_type {};
34template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_volatile<_Tp volatile> : public true_type {};
35
36#if _LIBCPP_STD_VER > 14
37template <class _Tp>
38inline constexpr bool is_volatile_v = is_volatile<_Tp>::value;
39#endif
40
41#endif // __has_builtin(__is_volatile)
42
43_LIBCPP_END_NAMESPACE_STD
44
45#endif // _LIBCPP___TYPE_TRAITS_IS_VOLATILE_H
lib/libcxx/include/__type_traits/lazy.h created+25
......@@ -0,0 +1,25 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_LAZY_H
10#define _LIBCPP___TYPE_TRAITS_LAZY_H
11
12#include <__config>
13
14#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15# pragma GCC system_header
16#endif
17
18_LIBCPP_BEGIN_NAMESPACE_STD
19
20template <template <class...> class _Func, class ..._Args>
21struct _Lazy : _Func<_Args...> {};
22
23_LIBCPP_END_NAMESPACE_STD
24
25#endif // _LIBCPP___TYPE_TRAITS_LAZY_H
lib/libcxx/include/__type_traits/make_32_64_or_128_bit.h created+48
......@@ -0,0 +1,48 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_MAKE_32_64_OR_128_BIT_H
10#define _LIBCPP___TYPE_TRAITS_MAKE_32_64_OR_128_BIT_H
11
12#include <__config>
13#include <__type_traits/conditional.h>
14#include <__type_traits/is_same.h>
15#include <__type_traits/is_signed.h>
16#include <__type_traits/is_unsigned.h>
17#include <__type_traits/make_unsigned.h>
18#include <cstdint>
19
20#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21# pragma GCC system_header
22#endif
23
24_LIBCPP_BEGIN_NAMESPACE_STD
25
26/// Helper to promote an integral to smallest 32, 64, or 128 bit representation.
27///
28/// The restriction is the same as the integral version of to_char.
29template <class _Tp>
30#if _LIBCPP_STD_VER > 17
31 requires (is_signed_v<_Tp> || is_unsigned_v<_Tp> || is_same_v<_Tp, char>)
32#endif
33using __make_32_64_or_128_bit_t =
34 __copy_unsigned_t<_Tp,
35 __conditional_t<sizeof(_Tp) <= sizeof(int32_t), int32_t,
36 __conditional_t<sizeof(_Tp) <= sizeof(int64_t), int64_t,
37#ifndef _LIBCPP_HAS_NO_INT128
38 __conditional_t<sizeof(_Tp) <= sizeof(__int128_t), __int128_t,
39 /* else */ void>
40#else
41 /* else */ void
42#endif
43 > >
44 >;
45
46_LIBCPP_END_NAMESPACE_STD
47
48#endif // _LIBCPP___TYPE_TRAITS_MAKE_32_64_OR_128_BIT_H
lib/libcxx/include/__type_traits/make_signed.h created+76
......@@ -0,0 +1,76 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_MAKE_SIGNED_H
10#define _LIBCPP___TYPE_TRAITS_MAKE_SIGNED_H
11
12#include <__config>
13#include <__type_traits/apply_cv.h>
14#include <__type_traits/is_enum.h>
15#include <__type_traits/is_integral.h>
16#include <__type_traits/nat.h>
17#include <__type_traits/remove_cv.h>
18#include <__type_traits/type_list.h>
19
20#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21# pragma GCC system_header
22#endif
23
24_LIBCPP_BEGIN_NAMESPACE_STD
25
26typedef
27 __type_list<signed char,
28 __type_list<signed short,
29 __type_list<signed int,
30 __type_list<signed long,
31 __type_list<signed long long,
32#ifndef _LIBCPP_HAS_NO_INT128
33 __type_list<__int128_t,
34#endif
35 __nat
36#ifndef _LIBCPP_HAS_NO_INT128
37 >
38#endif
39 > > > > > __signed_types;
40
41template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value>
42struct __make_signed {};
43
44template <class _Tp>
45struct __make_signed<_Tp, true>
46{
47 typedef typename __find_first<__signed_types, sizeof(_Tp)>::type type;
48};
49
50template <> struct __make_signed<bool, true> {};
51template <> struct __make_signed< signed short, true> {typedef short type;};
52template <> struct __make_signed<unsigned short, true> {typedef short type;};
53template <> struct __make_signed< signed int, true> {typedef int type;};
54template <> struct __make_signed<unsigned int, true> {typedef int type;};
55template <> struct __make_signed< signed long, true> {typedef long type;};
56template <> struct __make_signed<unsigned long, true> {typedef long type;};
57template <> struct __make_signed< signed long long, true> {typedef long long type;};
58template <> struct __make_signed<unsigned long long, true> {typedef long long type;};
59#ifndef _LIBCPP_HAS_NO_INT128
60template <> struct __make_signed<__int128_t, true> {typedef __int128_t type;};
61template <> struct __make_signed<__uint128_t, true> {typedef __int128_t type;};
62#endif
63
64template <class _Tp>
65struct _LIBCPP_TEMPLATE_VIS make_signed
66{
67 typedef typename __apply_cv<_Tp, typename __make_signed<typename remove_cv<_Tp>::type>::type>::type type;
68};
69
70#if _LIBCPP_STD_VER > 11
71template <class _Tp> using make_signed_t = typename make_signed<_Tp>::type;
72#endif
73
74_LIBCPP_END_NAMESPACE_STD
75
76#endif // _LIBCPP___TYPE_TRAITS_MAKE_SIGNED_H
lib/libcxx/include/__type_traits/make_unsigned.h created+89
......@@ -0,0 +1,89 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_MAKE_UNSIGNED_H
10#define _LIBCPP___TYPE_TRAITS_MAKE_UNSIGNED_H
11
12#include <__config>
13#include <__type_traits/apply_cv.h>
14#include <__type_traits/conditional.h>
15#include <__type_traits/is_enum.h>
16#include <__type_traits/is_integral.h>
17#include <__type_traits/is_unsigned.h>
18#include <__type_traits/nat.h>
19#include <__type_traits/remove_cv.h>
20#include <__type_traits/type_list.h>
21
22#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23# pragma GCC system_header
24#endif
25
26_LIBCPP_BEGIN_NAMESPACE_STD
27
28typedef
29 __type_list<unsigned char,
30 __type_list<unsigned short,
31 __type_list<unsigned int,
32 __type_list<unsigned long,
33 __type_list<unsigned long long,
34#ifndef _LIBCPP_HAS_NO_INT128
35 __type_list<__uint128_t,
36#endif
37 __nat
38#ifndef _LIBCPP_HAS_NO_INT128
39 >
40#endif
41 > > > > > __unsigned_types;
42
43template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value>
44struct __make_unsigned {};
45
46template <class _Tp>
47struct __make_unsigned<_Tp, true>
48{
49 typedef typename __find_first<__unsigned_types, sizeof(_Tp)>::type type;
50};
51
52template <> struct __make_unsigned<bool, true> {};
53template <> struct __make_unsigned< signed short, true> {typedef unsigned short type;};
54template <> struct __make_unsigned<unsigned short, true> {typedef unsigned short type;};
55template <> struct __make_unsigned< signed int, true> {typedef unsigned int type;};
56template <> struct __make_unsigned<unsigned int, true> {typedef unsigned int type;};
57template <> struct __make_unsigned< signed long, true> {typedef unsigned long type;};
58template <> struct __make_unsigned<unsigned long, true> {typedef unsigned long type;};
59template <> struct __make_unsigned< signed long long, true> {typedef unsigned long long type;};
60template <> struct __make_unsigned<unsigned long long, true> {typedef unsigned long long type;};
61#ifndef _LIBCPP_HAS_NO_INT128
62template <> struct __make_unsigned<__int128_t, true> {typedef __uint128_t type;};
63template <> struct __make_unsigned<__uint128_t, true> {typedef __uint128_t type;};
64#endif
65
66template <class _Tp>
67struct _LIBCPP_TEMPLATE_VIS make_unsigned
68{
69 typedef typename __apply_cv<_Tp, typename __make_unsigned<typename remove_cv<_Tp>::type>::type>::type type;
70};
71
72#if _LIBCPP_STD_VER > 11
73template <class _Tp> using make_unsigned_t = typename make_unsigned<_Tp>::type;
74#endif
75
76#ifndef _LIBCPP_CXX03_LANG
77template <class _Tp>
78_LIBCPP_HIDE_FROM_ABI constexpr
79typename make_unsigned<_Tp>::type __to_unsigned_like(_Tp __x) noexcept {
80 return static_cast<typename make_unsigned<_Tp>::type>(__x);
81}
82#endif
83
84template <class _Tp, class _Up>
85using __copy_unsigned_t = __conditional_t<is_unsigned<_Tp>::value, typename make_unsigned<_Up>::type, _Up>;
86
87_LIBCPP_END_NAMESPACE_STD
88
89#endif // _LIBCPP___TYPE_TRAITS_MAKE_UNSIGNED_H
lib/libcxx/include/__type_traits/nat.h created+32
......@@ -0,0 +1,32 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_NAT_H
10#define _LIBCPP___TYPE_TRAITS_NAT_H
11
12#include <__config>
13
14#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15# pragma GCC system_header
16#endif
17
18_LIBCPP_BEGIN_NAMESPACE_STD
19
20struct __nat
21{
22#ifndef _LIBCPP_CXX03_LANG
23 __nat() = delete;
24 __nat(const __nat&) = delete;
25 __nat& operator=(const __nat&) = delete;
26 ~__nat() = delete;
27#endif
28};
29
30_LIBCPP_END_NAMESPACE_STD
31
32#endif // _LIBCPP___TYPE_TRAITS_NAT_H
lib/libcxx/include/__type_traits/negation.h created+33
......@@ -0,0 +1,33 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_NEGATION_H
10#define _LIBCPP___TYPE_TRAITS_NEGATION_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21template <class _Pred>
22struct _Not : _BoolConstant<!_Pred::value> {};
23
24#if _LIBCPP_STD_VER > 14
25template <class _Tp>
26struct negation : _Not<_Tp> {};
27template<class _Tp>
28inline constexpr bool negation_v = negation<_Tp>::value;
29#endif // _LIBCPP_STD_VER > 14
30
31_LIBCPP_END_NAMESPACE_STD
32
33#endif // _LIBCPP___TYPE_TRAITS_NEGATION_H
lib/libcxx/include/__type_traits/promote.h created+95
......@@ -0,0 +1,95 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_PROMOTE_H
10#define _LIBCPP___TYPE_TRAITS_PROMOTE_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14#include <__type_traits/is_same.h>
15#include <__utility/declval.h>
16#include <cstddef>
17
18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19# pragma GCC system_header
20#endif
21
22_LIBCPP_BEGIN_NAMESPACE_STD
23
24template <class _Tp>
25struct __numeric_type
26{
27 static void __test(...);
28 static float __test(float);
29 static double __test(char);
30 static double __test(int);
31 static double __test(unsigned);
32 static double __test(long);
33 static double __test(unsigned long);
34 static double __test(long long);
35 static double __test(unsigned long long);
36 static double __test(double);
37 static long double __test(long double);
38
39 typedef decltype(__test(declval<_Tp>())) type;
40 static const bool value = _IsNotSame<type, void>::value;
41};
42
43template <>
44struct __numeric_type<void>
45{
46 static const bool value = true;
47};
48
49template <class _A1, class _A2 = void, class _A3 = void,
50 bool = __numeric_type<_A1>::value &&
51 __numeric_type<_A2>::value &&
52 __numeric_type<_A3>::value>
53class __promote_imp
54{
55public:
56 static const bool value = false;
57};
58
59template <class _A1, class _A2, class _A3>
60class __promote_imp<_A1, _A2, _A3, true>
61{
62private:
63 typedef typename __promote_imp<_A1>::type __type1;
64 typedef typename __promote_imp<_A2>::type __type2;
65 typedef typename __promote_imp<_A3>::type __type3;
66public:
67 typedef decltype(__type1() + __type2() + __type3()) type;
68 static const bool value = true;
69};
70
71template <class _A1, class _A2>
72class __promote_imp<_A1, _A2, void, true>
73{
74private:
75 typedef typename __promote_imp<_A1>::type __type1;
76 typedef typename __promote_imp<_A2>::type __type2;
77public:
78 typedef decltype(__type1() + __type2()) type;
79 static const bool value = true;
80};
81
82template <class _A1>
83class __promote_imp<_A1, void, void, true>
84{
85public:
86 typedef typename __numeric_type<_A1>::type type;
87 static const bool value = true;
88};
89
90template <class _A1, class _A2 = void, class _A3 = void>
91class __promote : public __promote_imp<_A1, _A2, _A3> {};
92
93_LIBCPP_END_NAMESPACE_STD
94
95#endif // _LIBCPP___TYPE_TRAITS_PROMOTE_H
lib/libcxx/include/__type_traits/rank.h created+36
......@@ -0,0 +1,36 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_RANK_H
10#define _LIBCPP___TYPE_TRAITS_RANK_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14#include <cstddef>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
20_LIBCPP_BEGIN_NAMESPACE_STD
21
22template <class _Tp> struct _LIBCPP_TEMPLATE_VIS rank
23 : public integral_constant<size_t, 0> {};
24template <class _Tp> struct _LIBCPP_TEMPLATE_VIS rank<_Tp[]>
25 : public integral_constant<size_t, rank<_Tp>::value + 1> {};
26template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS rank<_Tp[_Np]>
27 : public integral_constant<size_t, rank<_Tp>::value + 1> {};
28
29#if _LIBCPP_STD_VER > 14
30template <class _Tp>
31inline constexpr size_t rank_v = rank<_Tp>::value;
32#endif
33
34_LIBCPP_END_NAMESPACE_STD
35
36#endif // _LIBCPP___TYPE_TRAITS_RANK_H
lib/libcxx/include/__type_traits/remove_all_extents.h created+34
......@@ -0,0 +1,34 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_REMOVE_ALL_EXTENTS_H
10#define _LIBCPP___TYPE_TRAITS_REMOVE_ALL_EXTENTS_H
11
12#include <__config>
13#include <cstddef>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_all_extents
22 {typedef _Tp type;};
23template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_all_extents<_Tp[]>
24 {typedef typename remove_all_extents<_Tp>::type type;};
25template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS remove_all_extents<_Tp[_Np]>
26 {typedef typename remove_all_extents<_Tp>::type type;};
27
28#if _LIBCPP_STD_VER > 11
29template <class _Tp> using remove_all_extents_t = typename remove_all_extents<_Tp>::type;
30#endif
31
32_LIBCPP_END_NAMESPACE_STD
33
34#endif // _LIBCPP___TYPE_TRAITS_REMOVE_ALL_EXTENTS_H
lib/libcxx/include/__type_traits/remove_const.h created+28
......@@ -0,0 +1,28 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_REMOVE_CONST_H
10#define _LIBCPP___TYPE_TRAITS_REMOVE_CONST_H
11
12#include <__config>
13
14#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15# pragma GCC system_header
16#endif
17
18_LIBCPP_BEGIN_NAMESPACE_STD
19
20template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_const {typedef _Tp type;};
21template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_const<const _Tp> {typedef _Tp type;};
22#if _LIBCPP_STD_VER > 11
23template <class _Tp> using remove_const_t = typename remove_const<_Tp>::type;
24#endif
25
26_LIBCPP_END_NAMESPACE_STD
27
28#endif // _LIBCPP___TYPE_TRAITS_REMOVE_CONST_H
lib/libcxx/include/__type_traits/remove_cv.h created+30
......@@ -0,0 +1,30 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_REMOVE_CV_H
10#define _LIBCPP___TYPE_TRAITS_REMOVE_CV_H
11
12#include <__config>
13#include <__type_traits/remove_const.h>
14#include <__type_traits/remove_volatile.h>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
20_LIBCPP_BEGIN_NAMESPACE_STD
21
22template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_cv
23{typedef typename remove_volatile<typename remove_const<_Tp>::type>::type type;};
24#if _LIBCPP_STD_VER > 11
25template <class _Tp> using remove_cv_t = typename remove_cv<_Tp>::type;
26#endif
27
28_LIBCPP_END_NAMESPACE_STD
29
30#endif // _LIBCPP___TYPE_TRAITS_REMOVE_CV_H
lib/libcxx/include/__type_traits/remove_cvref.h created+41
......@@ -0,0 +1,41 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_REMOVE_CVREF_H
10#define _LIBCPP___TYPE_TRAITS_REMOVE_CVREF_H
11
12#include <__config>
13#include <__type_traits/is_same.h>
14#include <__type_traits/remove_cv.h>
15#include <__type_traits/remove_reference.h>
16
17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18# pragma GCC system_header
19#endif
20
21_LIBCPP_BEGIN_NAMESPACE_STD
22
23template <class _Tp>
24using __uncvref_t _LIBCPP_NODEBUG = typename remove_cv<typename remove_reference<_Tp>::type>::type;
25
26template <class _Tp, class _Up>
27struct __is_same_uncvref : _IsSame<__uncvref_t<_Tp>, __uncvref_t<_Up> > {};
28
29#if _LIBCPP_STD_VER > 17
30// remove_cvref - same as __uncvref
31template <class _Tp>
32struct remove_cvref {
33 using type _LIBCPP_NODEBUG = __uncvref_t<_Tp>;
34};
35
36template <class _Tp> using remove_cvref_t = typename remove_cvref<_Tp>::type;
37#endif
38
39_LIBCPP_END_NAMESPACE_STD
40
41#endif // _LIBCPP___TYPE_TRAITS_REMOVE_CVREF_H
lib/libcxx/include/__type_traits/remove_extent.h created+34
......@@ -0,0 +1,34 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_REMOVE_EXTENT_H
10#define _LIBCPP___TYPE_TRAITS_REMOVE_EXTENT_H
11
12#include <__config>
13#include <cstddef>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_extent
22 {typedef _Tp type;};
23template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_extent<_Tp[]>
24 {typedef _Tp type;};
25template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS remove_extent<_Tp[_Np]>
26 {typedef _Tp type;};
27
28#if _LIBCPP_STD_VER > 11
29template <class _Tp> using remove_extent_t = typename remove_extent<_Tp>::type;
30#endif
31
32_LIBCPP_END_NAMESPACE_STD
33
34#endif // _LIBCPP___TYPE_TRAITS_REMOVE_EXTENT_H
lib/libcxx/include/__type_traits/remove_pointer.h created+32
......@@ -0,0 +1,32 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_REMOVE_POINTER_H
10#define _LIBCPP___TYPE_TRAITS_REMOVE_POINTER_H
11
12#include <__config>
13
14#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15# pragma GCC system_header
16#endif
17
18_LIBCPP_BEGIN_NAMESPACE_STD
19
20template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer {typedef _LIBCPP_NODEBUG _Tp type;};
21template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp*> {typedef _LIBCPP_NODEBUG _Tp type;};
22template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp* const> {typedef _LIBCPP_NODEBUG _Tp type;};
23template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp* volatile> {typedef _LIBCPP_NODEBUG _Tp type;};
24template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp* const volatile> {typedef _LIBCPP_NODEBUG _Tp type;};
25
26#if _LIBCPP_STD_VER > 11
27template <class _Tp> using remove_pointer_t = typename remove_pointer<_Tp>::type;
28#endif
29
30_LIBCPP_END_NAMESPACE_STD
31
32#endif // _LIBCPP___TYPE_TRAITS_REMOVE_POINTER_H
lib/libcxx/include/__type_traits/remove_reference.h created+31
......@@ -0,0 +1,31 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_REMOVE_REFERENCE_H
10#define _LIBCPP___TYPE_TRAITS_REMOVE_REFERENCE_H
11
12#include <__config>
13#include <cstddef>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference {typedef _LIBCPP_NODEBUG _Tp type;};
22template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference<_Tp&> {typedef _LIBCPP_NODEBUG _Tp type;};
23template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference<_Tp&&> {typedef _LIBCPP_NODEBUG _Tp type;};
24
25#if _LIBCPP_STD_VER > 11
26template <class _Tp> using remove_reference_t = typename remove_reference<_Tp>::type;
27#endif
28
29_LIBCPP_END_NAMESPACE_STD
30
31#endif // _LIBCPP___TYPE_TRAITS_REMOVE_REFERENCE_H
lib/libcxx/include/__type_traits/remove_volatile.h created+28
......@@ -0,0 +1,28 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_REMOVE_VOLATILE_H
10#define _LIBCPP___TYPE_TRAITS_REMOVE_VOLATILE_H
11
12#include <__config>
13
14#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15# pragma GCC system_header
16#endif
17
18_LIBCPP_BEGIN_NAMESPACE_STD
19
20template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_volatile {typedef _Tp type;};
21template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_volatile<volatile _Tp> {typedef _Tp type;};
22#if _LIBCPP_STD_VER > 11
23template <class _Tp> using remove_volatile_t = typename remove_volatile<_Tp>::type;
24#endif
25
26_LIBCPP_END_NAMESPACE_STD
27
28#endif // _LIBCPP___TYPE_TRAITS_REMOVE_VOLATILE_H
lib/libcxx/include/__type_traits/type_identity.h created+33
......@@ -0,0 +1,33 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_TYPE_IDENTITY_H
10#define _LIBCPP___TYPE_TRAITS_TYPE_IDENTITY_H
11
12#include <__config>
13
14#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15# pragma GCC system_header
16#endif
17
18_LIBCPP_BEGIN_NAMESPACE_STD
19
20template <class _Tp>
21struct __type_identity { typedef _Tp type; };
22
23template <class _Tp>
24using __type_identity_t _LIBCPP_NODEBUG = typename __type_identity<_Tp>::type;
25
26#if _LIBCPP_STD_VER > 17
27template<class _Tp> struct type_identity { typedef _Tp type; };
28template<class _Tp> using type_identity_t = typename type_identity<_Tp>::type;
29#endif
30
31_LIBCPP_END_NAMESPACE_STD
32
33#endif // _LIBCPP___TYPE_TRAITS_TYPE_IDENTITY_H
lib/libcxx/include/__type_traits/type_list.h created+44
......@@ -0,0 +1,44 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_TYPE_LIST_H
10#define _LIBCPP___TYPE_TRAITS_TYPE_LIST_H
11
12#include <__config>
13#include <cstddef>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21template <class _Hp, class _Tp>
22struct __type_list
23{
24 typedef _Hp _Head;
25 typedef _Tp _Tail;
26};
27
28template <class _TypeList, size_t _Size, bool = _Size <= sizeof(typename _TypeList::_Head)> struct __find_first;
29
30template <class _Hp, class _Tp, size_t _Size>
31struct __find_first<__type_list<_Hp, _Tp>, _Size, true>
32{
33 typedef _LIBCPP_NODEBUG _Hp type;
34};
35
36template <class _Hp, class _Tp, size_t _Size>
37struct __find_first<__type_list<_Hp, _Tp>, _Size, false>
38{
39 typedef _LIBCPP_NODEBUG typename __find_first<_Tp, _Size>::type type;
40};
41
42_LIBCPP_END_NAMESPACE_STD
43
44#endif // _LIBCPP___TYPE_TRAITS_TYPE_LIST_H
lib/libcxx/include/__type_traits/underlying_type.h created+41
......@@ -0,0 +1,41 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_UNDERLYING_TYPE_H
10#define _LIBCPP___TYPE_TRAITS_UNDERLYING_TYPE_H
11
12#include <__config>
13#include <__type_traits/is_enum.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21template <class _Tp, bool = is_enum<_Tp>::value> struct __underlying_type_impl;
22
23template <class _Tp>
24struct __underlying_type_impl<_Tp, false> {};
25
26template <class _Tp>
27struct __underlying_type_impl<_Tp, true>
28{
29 typedef __underlying_type(_Tp) type;
30};
31
32template <class _Tp>
33struct underlying_type : __underlying_type_impl<_Tp, is_enum<_Tp>::value> {};
34
35#if _LIBCPP_STD_VER > 11
36template <class _Tp> using underlying_type_t = typename underlying_type<_Tp>::type;
37#endif
38
39_LIBCPP_END_NAMESPACE_STD
40
41#endif // _LIBCPP___TYPE_TRAITS_UNDERLYING_TYPE_H
lib/libcxx/include/__type_traits/void_t.h created+29
......@@ -0,0 +1,29 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_VOID_T_H
10#define _LIBCPP___TYPE_TRAITS_VOID_T_H
11
12#include <__config>
13
14#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15# pragma GCC system_header
16#endif
17
18_LIBCPP_BEGIN_NAMESPACE_STD
19
20#if _LIBCPP_STD_VER > 14
21template <class...> using void_t = void;
22#endif
23
24template <class>
25struct __void_t { typedef void type; };
26
27_LIBCPP_END_NAMESPACE_STD
28
29#endif // _LIBCPP___TYPE_TRAITS_VOID_T_H
lib/libcxx/include/__undef_macros+2-19
......@@ -7,27 +7,10 @@
77//
88//===----------------------------------------------------------------------===//
99
10
1110#ifdef min
12#if !defined(_LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS)
13#if defined(_LIBCPP_WARNING)
14_LIBCPP_WARNING("macro min is incompatible with C++. Try #define NOMINMAX "
15 "before any Windows header. #undefing min")
16#else
17#warning: macro min is incompatible with C++. #undefing min
18#endif
19#endif
20#undef min
11# undef min
2112#endif
2213
2314#ifdef max
24#if !defined(_LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS)
25#if defined(_LIBCPP_WARNING)
26_LIBCPP_WARNING("macro max is incompatible with C++. Try #define NOMINMAX "
27 "before any Windows header. #undefing max")
28#else
29#warning: macro max is incompatible with C++. #undefing max
30#endif
31#endif
32#undef max
15# undef max
3316#endif
lib/libcxx/include/__utility/as_const.h+1-1
......@@ -15,7 +15,7 @@
1515#include <type_traits>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__utility/auto_cast.h+1-1
......@@ -14,7 +14,7 @@
1414#include <type_traits>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
17# pragma GCC system_header
1818#endif
1919
2020#define _LIBCPP_AUTO_CAST(expr) static_cast<typename decay<decltype((expr))>::type>(expr)
lib/libcxx/include/__utility/cmp.h+4-7
......@@ -16,7 +16,7 @@
1616#include <type_traits>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
19# pragma GCC system_header
2020#endif
2121
2222_LIBCPP_PUSH_MACROS
......@@ -24,19 +24,16 @@ _LIBCPP_PUSH_MACROS
2424
2525_LIBCPP_BEGIN_NAMESPACE_STD
2626
27#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
27#if _LIBCPP_STD_VER > 17
2828template<class _Tp, class... _Up>
2929struct _IsSameAsAny : _Or<_IsSame<_Tp, _Up>...> {};
3030
3131template<class _Tp>
3232concept __is_safe_integral_cmp = is_integral_v<_Tp> &&
33 !_IsSameAsAny<_Tp, bool, char
33 !_IsSameAsAny<_Tp, bool, char, char16_t, char32_t
3434#ifndef _LIBCPP_HAS_NO_CHAR8_T
3535 , char8_t
3636#endif
37#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
38 , char16_t, char32_t
39#endif
4037#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4138 , wchar_t
4239#endif
......@@ -101,7 +98,7 @@ bool in_range(_Up __u) noexcept
10198 return _VSTD::cmp_less_equal(__u, numeric_limits<_Tp>::max()) &&
10299 _VSTD::cmp_greater_equal(__u, numeric_limits<_Tp>::min());
103100}
104#endif
101#endif // _LIBCPP_STD_VER > 17
105102
106103_LIBCPP_END_NAMESPACE_STD
107104
lib/libcxx/include/__utility/declval.h+1-1
......@@ -12,7 +12,7 @@
1212#include <__config>
1313
1414#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15#pragma GCC system_header
15# pragma GCC system_header
1616#endif
1717
1818_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__utility/exchange.h+1-1
......@@ -15,7 +15,7 @@
1515#include <type_traits>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__utility/forward.h+3-2
......@@ -11,10 +11,11 @@
1111#define _LIBCPP___UTILITY_FORWARD_H
1212
1313#include <__config>
14#include <type_traits>
14#include <__type_traits/is_reference.h>
15#include <__type_traits/remove_reference.h>
1516
1617#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
18# pragma GCC system_header
1819#endif
1920
2021_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__utility/in_place.h+1-1
......@@ -13,7 +13,7 @@
1313#include <type_traits>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16#pragma GCC system_header
16# pragma GCC system_header
1717#endif
1818
1919_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__utility/integer_sequence.h+1-1
......@@ -13,7 +13,7 @@
1313#include <type_traits>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16#pragma GCC system_header
16# pragma GCC system_header
1717#endif
1818
1919_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__utility/move.h+1-6
......@@ -14,7 +14,7 @@
1414#include <type_traits>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
17# pragma GCC system_header
1818#endif
1919
2020_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -26,15 +26,10 @@ move(_Tp&& __t) _NOEXCEPT {
2626 return static_cast<_Up&&>(__t);
2727}
2828
29#ifndef _LIBCPP_CXX03_LANG
3029template <class _Tp>
3130using __move_if_noexcept_result_t =
3231 typename conditional<!is_nothrow_move_constructible<_Tp>::value && is_copy_constructible<_Tp>::value, const _Tp&,
3332 _Tp&&>::type;
34#else // _LIBCPP_CXX03_LANG
35template <class _Tp>
36using __move_if_noexcept_result_t = const _Tp&;
37#endif
3833
3934template <class _Tp>
4035_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 __move_if_noexcept_result_t<_Tp>
lib/libcxx/include/__utility/pair.h+21-5
......@@ -21,7 +21,7 @@
2121#include <type_traits>
2222
2323#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
24#pragma GCC system_header
24# pragma GCC system_header
2525#endif
2626
2727_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -315,7 +315,7 @@ private:
315315#endif
316316};
317317
318#if _LIBCPP_STD_VER >= 17
318#if _LIBCPP_STD_VER > 14
319319template<class _T1, class _T2>
320320pair(_T1, _T2) -> pair<_T1, _T2>;
321321#endif
......@@ -330,7 +330,7 @@ operator==(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
330330 return __x.first == __y.first && __x.second == __y.second;
331331}
332332
333#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
333#if _LIBCPP_STD_VER > 17
334334
335335template <class _T1, class _T2>
336336_LIBCPP_HIDE_FROM_ABI constexpr
......@@ -345,7 +345,7 @@ operator<=>(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
345345 return _VSTD::__synth_three_way(__x.second, __y.second);
346346}
347347
348#else // !defined(_LIBCPP_HAS_NO_CONCEPTS)
348#else // _LIBCPP_STD_VER > 17
349349
350350template <class _T1, class _T2>
351351inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
......@@ -387,7 +387,23 @@ operator<=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
387387 return !(__y < __x);
388388}
389389
390#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
390#endif // _LIBCPP_STD_VER > 17
391
392#if _LIBCPP_STD_VER > 20
393template <class _T1, class _T2, class _U1, class _U2, template<class> class _TQual, template<class> class _UQual>
394 requires requires { typename pair<common_reference_t<_TQual<_T1>, _UQual<_U1>>,
395 common_reference_t<_TQual<_T2>, _UQual<_U2>>>; }
396struct basic_common_reference<pair<_T1, _T2>, pair<_U1, _U2>, _TQual, _UQual> {
397 using type = pair<common_reference_t<_TQual<_T1>, _UQual<_U1>>,
398 common_reference_t<_TQual<_T2>, _UQual<_U2>>>;
399};
400
401template <class _T1, class _T2, class _U1, class _U2>
402 requires requires { typename pair<common_type_t<_T1, _U1>, common_type_t<_T2, _U2>>; }
403struct common_type<pair<_T1, _T2>, pair<_U1, _U2>> {
404 using type = pair<common_type_t<_T1, _U1>, common_type_t<_T2, _U2>>;
405};
406#endif // _LIBCPP_STD_VER > 20
391407
392408template <class _T1, class _T2>
393409inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
lib/libcxx/include/__utility/piecewise_construct.h+1-1
......@@ -12,7 +12,7 @@
1212#include <__config>
1313
1414#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15#pragma GCC system_header
15# pragma GCC system_header
1616#endif
1717
1818_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__utility/priority_tag.h+1-1
......@@ -13,7 +13,7 @@
1313#include <cstddef>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16#pragma GCC system_header
16# pragma GCC system_header
1717#endif
1818
1919_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__utility/rel_ops.h+1-1
......@@ -15,7 +15,7 @@
1515#include <type_traits>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__utility/swap.h+1-1
......@@ -16,7 +16,7 @@
1616#include <type_traits>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
19# pragma GCC system_header
2020#endif
2121
2222_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__utility/to_underlying.h+1-1
......@@ -14,7 +14,7 @@
1414#include <type_traits>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
17# pragma GCC system_header
1818#endif
1919
2020_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__utility/transaction.h+6-1
......@@ -15,7 +15,7 @@
1515#include <type_traits>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -86,6 +86,11 @@ private:
8686 bool __completed_;
8787};
8888
89template <class _Rollback>
90_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __transaction<_Rollback> __make_transaction(_Rollback __rollback) {
91 return __transaction<_Rollback>(std::move(__rollback));
92}
93
8994_LIBCPP_END_NAMESPACE_STD
9095
9196#endif // _LIBCPP___UTILITY_TRANSACTION_H
lib/libcxx/include/__utility/unreachable.h created+38
......@@ -0,0 +1,38 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___UTILITY_UNREACHABLE_H
10#define _LIBCPP___UTILITY_UNREACHABLE_H
11
12#include <__config>
13#include <cstdlib>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21_LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI inline void __libcpp_unreachable()
22{
23#if __has_builtin(__builtin_unreachable)
24 __builtin_unreachable();
25#else
26 std::abort();
27#endif
28}
29
30#if _LIBCPP_STD_VER > 20
31
32[[noreturn]] _LIBCPP_HIDE_FROM_ABI inline void unreachable() { __libcpp_unreachable(); }
33
34#endif // _LIBCPP_STD_VER > 20
35
36_LIBCPP_END_NAMESPACE_STD
37
38#endif
lib/libcxx/include/__variant/monostate.h+1-1
......@@ -15,7 +15,7 @@
1515#include <cstddef>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
18# pragma GCC system_header
1919#endif
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/__verbose_abort created+27
......@@ -0,0 +1,27 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___VERBOSE_ABORT
11#define _LIBCPP___VERBOSE_ABORT
12
13#include <__availability>
14#include <__config>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
20_LIBCPP_BEGIN_NAMESPACE_STD
21
22_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_VERBOSE_ABORT _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 1, 2)
23void __libcpp_verbose_abort(const char *__format, ...);
24
25_LIBCPP_END_NAMESPACE_STD
26
27#endif // _LIBCPP___VERBOSE_ABORT
lib/libcxx/include/algorithm+1006-16
......@@ -19,14 +19,901 @@ namespace std
1919{
2020
2121namespace ranges {
22
23 // [algorithms.results], algorithm result types
24 template <class I, class F>
25 struct in_fun_result; // since C++20
26
2227 template <class I1, class I2>
23 struct in_in_result; // since C++20
28 struct in_in_result; // since C++20
29
30 template <class I, class O>
31 struct in_out_result; // since C++20
2432
2533 template <class I1, class I2, class O>
26 struct in_in_out_result; // since C++20
34 struct in_in_out_result; // since C++20
35
36 template <class I, class O1, class O2>
37 struct in_out_out_result; // since C++20
38
39 template <class I1, class I2>
40 struct min_max_result; // since C++20
41
42 template <class I>
43 struct in_found_result; // since C++20
44
45 template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
46 indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less> // since C++20
47 constexpr I min_element(I first, S last, Comp comp = {}, Proj proj = {});
48
49 template<forward_range R, class Proj = identity,
50 indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less> // since C++20
51 constexpr borrowed_iterator_t<R> min_element(R&& r, Comp comp = {}, Proj proj = {});
52
53 template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
54 indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less>
55 constexpr I ranges::max_element(I first, S last, Comp comp = {}, Proj proj = {}); // since C++20
56
57 template<forward_range R, class Proj = identity,
58 indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
59 constexpr borrowed_iterator_t<R> ranges::max_element(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
60
61 template<class I1, class I2>
62 using mismatch_result = in_in_result<I1, I2>;
63
64 template <input_iterator I1, sentinel_for<_I1> S1, input_iterator I2, sentinel_for<_I2> S2,
65 class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
66 requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
67 constexpr mismatch_result<_I1, _I2>
68 mismatch()(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) // since C++20
69
70 template <input_range R1, input_range R2,
71 class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
72 requires indirectly_comparable<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
73 constexpr mismatch_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>>
74 mismatch(R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) // since C++20
75
76 requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>
77 constexpr I find(I first, S last, const T& value, Proj proj = {}); // since C++20
78
79 template<input_range R, class T, class Proj = identity>
80 requires indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
81 constexpr borrowed_iterator_t<R>
82 find(R&& r, const T& value, Proj proj = {}); // since C++20
83
84 template<input_iterator I, sentinel_for<I> S, class Proj = identity,
85 indirect_unary_predicate<projected<I, Proj>> Pred>
86 constexpr I find_if(I first, S last, Pred pred, Proj proj = {}); // since C++20
87
88 template<input_range R, class Proj = identity,
89 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
90 constexpr borrowed_iterator_t<R>
91 find_if(R&& r, Pred pred, Proj proj = {}); // since C++20
92
93 template<input_iterator I, sentinel_for<I> S, class Proj = identity,
94 indirect_unary_predicate<projected<I, Proj>> Pred>
95 constexpr I find_if_not(I first, S last, Pred pred, Proj proj = {}); // since C++20
96
97 template<input_range R, class Proj = identity,
98 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
99 constexpr borrowed_iterator_t<R>
100 find_if_not(R&& r, Pred pred, Proj proj = {}); // since C++20
101
102 template<class T, class Proj = identity,
103 indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
104 constexpr const T& min(const T& a, const T& b, Comp comp = {}, Proj proj = {}); // since C++20
105
106 template<copyable T, class Proj = identity,
107 indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
108 constexpr T min(initializer_list<T> r, Comp comp = {}, Proj proj = {}); // since C++20
109
110 template<input_range R, class Proj = identity,
111 indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
112 requires indirectly_copyable_storable<iterator_t<R>, range_value_t<R>*>
113 constexpr range_value_t<R>
114 min(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
115
116 template<class T, class Proj = identity,
117 indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
118 constexpr const T& max(const T& a, const T& b, Comp comp = {}, Proj proj = {}); // since C++20
119
120 template<copyable T, class Proj = identity,
121 indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
122 constexpr T max(initializer_list<T> r, Comp comp = {}, Proj proj = {}); // since C++20
123
124 template<input_range R, class Proj = identity,
125 indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
126 requires indirectly_copyable_storable<iterator_t<R>, range_value_t<R>*>
127 constexpr range_value_t<R>
128 max(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
129
130 template<class I, class O>
131 using unary_transform_result = in_out_result<I, O>; // since C++20
132
133 template<class I1, class I2, class O>
134 using binary_transform_result = in_in_out_result<I1, I2, O>; // since C++20
135
136 template<input_iterator I, sentinel_for<I> S, weakly_incrementable O,
137 copy_constructible F, class Proj = identity>
138 requires indirectly_writable<O, indirect_result_t<F&, projected<I, Proj>>>
139 constexpr ranges::unary_transform_result<I, O>
140 transform(I first1, S last1, O result, F op, Proj proj = {}); // since C++20
141
142 template<input_range R, weakly_incrementable O, copy_constructible F,
143 class Proj = identity>
144 requires indirectly_writable<O, indirect_result_t<F&, projected<iterator_t<R>, Proj>>>
145 constexpr ranges::unary_transform_result<borrowed_iterator_t<R>, O>
146 transform(R&& r, O result, F op, Proj proj = {}); // since C++20
147
148 template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
149 weakly_incrementable O, copy_constructible F, class Proj1 = identity,
150 class Proj2 = identity>
151 requires indirectly_writable<O, indirect_result_t<F&, projected<I1, Proj1>,
152 projected<I2, Proj2>>>
153 constexpr ranges::binary_transform_result<I1, I2, O>
154 transform(I1 first1, S1 last1, I2 first2, S2 last2, O result,
155 F binary_op, Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
156
157 template<input_range R1, input_range R2, weakly_incrementable O,
158 copy_constructible F, class Proj1 = identity, class Proj2 = identity>
159 requires indirectly_writable<O, indirect_result_t<F&, projected<iterator_t<R1>, Proj1>,
160 projected<iterator_t<R2>, Proj2>>>
161 constexpr ranges::binary_transform_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>, O>
162 transform(R1&& r1, R2&& r2, O result,
163 F binary_op, Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
164
165 template<input_iterator I, sentinel_for<I> S, class T, class Proj = identity>
166 requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>
167 constexpr iter_difference_t<I>
168 count(I first, S last, const T& value, Proj proj = {}); // since C++20
169
170 template<input_range R, class T, class Proj = identity>
171 requires indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
172 constexpr range_difference_t<R>
173 count(R&& r, const T& value, Proj proj = {}); // since C++20
174
175 template<input_iterator I, sentinel_for<I> S, class Proj = identity,
176 indirect_unary_predicate<projected<I, Proj>> Pred>
177 constexpr iter_difference_t<I>
178 count_if(I first, S last, Pred pred, Proj proj = {}); // since C++20
179
180 template<input_range R, class Proj = identity,
181 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
182 constexpr range_difference_t<R>
183 count_if(R&& r, Pred pred, Proj proj = {}); // since C++20
184
185 template<class T>
186 using minmax_result = min_max_result<T>;
187
188 template<class T, class Proj = identity,
189 indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
190 constexpr ranges::minmax_result<const T&>
191 minmax(const T& a, const T& b, Comp comp = {}, Proj proj = {}); // since C++20
192
193 template<copyable T, class Proj = identity,
194 indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
195 constexpr ranges::minmax_result<T>
196 minmax(initializer_list<T> r, Comp comp = {}, Proj proj = {}); // since C++20
197
198 template<input_range R, class Proj = identity,
199 indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
200 requires indirectly_copyable_storable<iterator_t<R>, range_value_t<R>*>
201 constexpr ranges::minmax_result<range_value_t<R>>
202 minmax(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
203
204 template<class I>
205 using minmax_element_result = min_max_result<I>;
206
207 template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
208 indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less>
209 constexpr ranges::minmax_element_result<I>
210 minmax_element(I first, S last, Comp comp = {}, Proj proj = {}); // since C++20
211
212 template<forward_range R, class Proj = identity,
213 indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
214 constexpr ranges::minmax_element_result<borrowed_iterator_t<R>>
215 minmax_element(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
216
217 template<class I, class O>
218 using copy_result = in_out_result<I, O>; // since C++20
219
220 template<class I, class O>
221 using copy_n_result = in_out_result<I, O>; // since C++20
222
223 template<class I, class O>
224 using copy_if_result = in_out_result<I, O>; // since C++20
225
226 template<class I1, class I2>
227 using copy_backward_result = in_out_result<I1, I2>; // since C++20
228
229 template<input_iterator I, sentinel_for<I> S, weakly_incrementable O>
230 requires indirectly_copyable<I, O>
231 constexpr ranges::copy_result<I, O> ranges::copy(I first, S last, O result); // since C++20
232
233 template<input_range R, weakly_incrementable O>
234 requires indirectly_copyable<iterator_t<R>, O>
235 constexpr ranges::copy_result<borrowed_iterator_t<R>, O> ranges::copy(R&& r, O result); // since C++20
236
237 template<input_iterator I, weakly_incrementable O>
238 requires indirectly_copyable<I, O>
239 constexpr ranges::copy_n_result<I, O>
240 ranges::copy_n(I first, iter_difference_t<I> n, O result); // since C++20
241
242 template<input_iterator I, sentinel_for<I> S, weakly_incrementable O, class Proj = identity,
243 indirect_unary_predicate<projected<I, Proj>> Pred>
244 requires indirectly_copyable<I, O>
245 constexpr ranges::copy_if_result<I, O>
246 ranges::copy_if(I first, S last, O result, Pred pred, Proj proj = {}); // since C++20
247
248 template<input_range R, weakly_incrementable O, class Proj = identity,
249 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
250 requires indirectly_copyable<iterator_t<R>, O>
251 constexpr ranges::copy_if_result<borrowed_iterator_t<R>, O>
252 ranges::copy_if(R&& r, O result, Pred pred, Proj proj = {}); // since C++20
253
254 template<bidirectional_iterator I1, sentinel_for<I1> S1, bidirectional_iterator I2>
255 requires indirectly_copyable<I1, I2>
256 constexpr ranges::copy_backward_result<I1, I2>
257 ranges::copy_backward(I1 first, S1 last, I2 result); // since C++20
258
259 template<bidirectional_range R, bidirectional_iterator I>
260 requires indirectly_copyable<iterator_t<R>, I>
261 constexpr ranges::copy_backward_result<borrowed_iterator_t<R>, I>
262 ranges::copy_backward(R&& r, I result); // since C++20
263
264 template<class I, class F>
265 using for_each_result = in_fun_result<I, F>; // since C++20
266
267 template<input_iterator I, sentinel_for<I> S, class Proj = identity,
268 indirectly_unary_invocable<projected<I, Proj>> Fun>
269 constexpr ranges::for_each_result<I, Fun>
270 ranges::for_each(I first, S last, Fun f, Proj proj = {}); // since C++20
271
272 template<input_range R, class Proj = identity,
273 indirectly_unary_invocable<projected<iterator_t<R>, Proj>> Fun>
274 constexpr ranges::for_each_result<borrowed_iterator_t<R>, Fun>
275 ranges::for_each(R&& r, Fun f, Proj proj = {}); // since C++20
276
277 template<input_iterator I, class Proj = identity,
278 indirectly_unary_invocable<projected<I, Proj>> Fun>
279 constexpr ranges::for_each_n_result<I, Fun>
280 ranges::for_each_n(I first, iter_difference_t<I> n, Fun f, Proj proj = {}); // since C++20
281
282 template<input_iterator I, sentinel_for<I> S, class Proj = identity,
283 indirect_unary_predicate<projected<I, Proj>> Pred>
284 constexpr bool ranges::is_partitioned(I first, S last, Pred pred, Proj proj = {}); // since C++20
285
286 template<input_range R, class Proj = identity,
287 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
288 constexpr bool ranges::is_partitioned(R&& r, Pred pred, Proj proj = {}); // since C++20
289
290 template<random_access_iterator I, sentinel_for<I> S, class Comp = ranges::less,
291 class Proj = identity>
292 requires sortable<I, Comp, Proj>
293 constexpr I
294 ranges::push_heap(I first, S last, Comp comp = {}, Proj proj = {}); // since C++20
295
296 template<random_access_range R, class Comp = ranges::less, class Proj = identity>
297 requires sortable<iterator_t<R>, Comp, Proj>
298 constexpr borrowed_iterator_t<R>
299 ranges::push_heap(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
300
301 template<random_access_iterator I, sentinel_for<I> S, class Comp = ranges::less,
302 class Proj = identity>
303 requires sortable<I, Comp, Proj>
304 constexpr I
305 ranges::pop_heap(I first, S last, Comp comp = {}, Proj proj = {}); // since C++20
306
307 template<random_access_range R, class Comp = ranges::less, class Proj = identity>
308 requires sortable<iterator_t<R>, Comp, Proj>
309 constexpr borrowed_iterator_t<R>
310 ranges::pop_heap(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
311
312 template<random_access_iterator I, sentinel_for<I> S, class Comp = ranges::less,
313 class Proj = identity>
314 requires sortable<I, Comp, Proj>
315 constexpr I
316 ranges::make_heap(I first, S last, Comp comp = {}, Proj proj = {}); // since C++20
317
318 template<random_access_range R, class Comp = ranges::less, class Proj = identity>
319 requires sortable<iterator_t<R>, Comp, Proj>
320 constexpr borrowed_iterator_t<R>
321 ranges::make_heap(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
322
323 template<random_access_iterator I, sentinel_for<I> S, class Comp = ranges::less,
324 class Proj = identity>
325 requires sortable<I, Comp, Proj>
326 constexpr I
327 ranges::sort_heap(I first, S last, Comp comp = {}, Proj proj = {}); // since C++20
328
329 template<random_access_range R, class Comp = ranges::less, class Proj = identity>
330 requires sortable<iterator_t<R>, Comp, Proj>
331 constexpr borrowed_iterator_t<R>
332 ranges::sort_heap(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
333
334 template<random_access_iterator I, sentinel_for<I> S, class Proj = identity,
335 indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less>
336 constexpr bool is_heap(I first, S last, Comp comp = {}, Proj proj = {}); // Since C++20
337
338 template<random_access_range R, class Proj = identity,
339 indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
340 constexpr bool is_heap(R&& r, Comp comp = {}, Proj proj = {}); // Since C++20
341
342 template<random_access_iterator I, sentinel_for<I> S, class Proj = identity,
343 indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less>
344 constexpr I is_heap_until(I first, S last, Comp comp = {}, Proj proj = {}); // Since C++20
345
346 template<random_access_range R, class Proj = identity,
347 indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
348 constexpr borrowed_iterator_t<R>
349 is_heap_until(R&& r, Comp comp = {}, Proj proj = {}); // Since C++20
350
351 template<bidirectional_iterator I, sentinel_for<I> S>
352 requires permutable<I>
353 constexpr I ranges::reverse(I first, S last); // since C++20
354
355 template<bidirectional_range R>
356 requires permutable<iterator_t<R>>
357 constexpr borrowed_iterator_t<R> ranges::reverse(R&& r); // since C++20
358
359 template<random_access_iterator I, sentinel_for<I> S, class Comp = ranges::less,
360 class Proj = identity>
361 requires sortable<I, Comp, Proj>
362 constexpr I
363 ranges::sort(I first, S last, Comp comp = {}, Proj proj = {}); // since C++20
364
365 template<random_access_range R, class Comp = ranges::less, class Proj = identity>
366 requires sortable<iterator_t<R>, Comp, Proj>
367 constexpr borrowed_iterator_t<R>
368 ranges::sort(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
369
370 template<random_access_iterator I, sentinel_for<I> S, class Comp = ranges::less,
371 class Proj = identity>
372 requires sortable<I, Comp, Proj>
373 I ranges::stable_sort(I first, S last, Comp comp = {}, Proj proj = {}); // since C++20
374
375 template<random_access_range R, class Comp = ranges::less, class Proj = identity>
376 requires sortable<iterator_t<R>, Comp, Proj>
377 borrowed_iterator_t<R>
378 ranges::stable_sort(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
379
380 template<random_access_iterator I, sentinel_for<I> S, class Comp = ranges::less,
381 class Proj = identity>
382 requires sortable<I, Comp, Proj>
383 constexpr I
384 ranges::partial_sort(I first, I middle, S last, Comp comp = {}, Proj proj = {}); // since C++20
385
386 template<random_access_range R, class Comp = ranges::less, class Proj = identity>
387 requires sortable<iterator_t<R>, Comp, Proj>
388 constexpr borrowed_iterator_t<R>
389 ranges::partial_sort(R&& r, iterator_t<R> middle, Comp comp = {}, Proj proj = {}); // since C++20
390
391 template<class T, output_iterator<const T&> O, sentinel_for<O> S>
392 constexpr O ranges::fill(O first, S last, const T& value); // since C++20
393
394 template<class T, output_range<const T&> R>
395 constexpr borrowed_iterator_t<R> ranges::fill(R&& r, const T& value); // since C++20
396
397 template<class T, output_iterator<const T&> O>
398 constexpr O ranges::fill_n(O first, iter_difference_t<O> n, const T& value); // since C++20
399
400 template<input_or_output_iterator O, sentinel_for<O> S, copy_constructible F>
401 requires invocable<F&> && indirectly_writable<O, invoke_result_t<F&>>
402 constexpr O generate(O first, S last, F gen); // Since C++20
403
404 template<class R, copy_constructible F>
405 requires invocable<F&> && output_range<R, invoke_result_t<F&>>
406 constexpr borrowed_iterator_t<R> generate(R&& r, F gen); // Since C++20
407
408 template<input_or_output_iterator O, copy_constructible F>
409 requires invocable<F&> && indirectly_writable<O, invoke_result_t<F&>>
410 constexpr O generate_n(O first, iter_difference_t<O> n, F gen); // Since C++20
411
412 template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
413 class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
414 requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
415 constexpr bool ranges::equal(I1 first1, S1 last1, I2 first2, S2 last2,
416 Pred pred = {},
417 Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
418
419 template<input_range R1, input_range R2, class Pred = ranges::equal_to,
420 class Proj1 = identity, class Proj2 = identity>
421 requires indirectly_comparable<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
422 constexpr bool ranges::equal(R1&& r1, R2&& r2, Pred pred = {},
423 Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
424
425 template<input_iterator I, sentinel_for<I> S, class Proj = identity,
426 indirect_unary_predicate<projected<I, Proj>> Pred>
427 constexpr bool ranges::all_of(I first, S last, Pred pred, Proj proj = {}); // since C++20
428
429 template<input_range R, class Proj = identity,
430 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
431 constexpr bool ranges::all_of(R&& r, Pred pred, Proj proj = {}); // since C++20
432
433 template<input_iterator I, sentinel_for<I> S, class Proj = identity,
434 indirect_unary_predicate<projected<I, Proj>> Pred>
435 constexpr bool ranges::any_of(I first, S last, Pred pred, Proj proj = {}); // since C++20
436
437 template<input_range R, class Proj = identity,
438 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
439 constexpr bool ranges::any_of(R&& r, Pred pred, Proj proj = {}); // since C++20
440
441 template<input_iterator I, sentinel_for<I> S, class Proj = identity,
442 indirect_unary_predicate<projected<I, Proj>> Pred>
443 constexpr bool ranges::none_of(I first, S last, Pred pred, Proj proj = {}); // since C++20
444
445 template<input_range R, class Proj = identity,
446 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
447 constexpr bool ranges::none_of(R&& r, Pred pred, Proj proj = {}); // since C++20
448
449 template<input_iterator I1, sentinel_for<I1> S1,
450 random_access_iterator I2, sentinel_for<I2> S2,
451 class Comp = ranges::less, class Proj1 = identity, class Proj2 = identity>
452 requires indirectly_copyable<I1, I2> && sortable<I2, Comp, Proj2> &&
453 indirect_strict_weak_order<Comp, projected<I1, Proj1>, projected<I2, Proj2>>
454 constexpr partial_sort_copy_result<I1, I2>
455 partial_sort_copy(I1 first, S1 last, I2 result_first, S2 result_last,
456 Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); // Since C++20
457
458 template<input_range R1, random_access_range R2, class Comp = ranges::less,
459 class Proj1 = identity, class Proj2 = identity>
460 requires indirectly_copyable<iterator_t<R1>, iterator_t<R2>> &&
461 sortable<iterator_t<R2>, Comp, Proj2> &&
462 indirect_strict_weak_order<Comp, projected<iterator_t<R1>, Proj1>,
463 projected<iterator_t<R2>, Proj2>>
464 constexpr partial_sort_copy_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>>
465 partial_sort_copy(R1&& r, R2&& result_r, Comp comp = {},
466 Proj1 proj1 = {}, Proj2 proj2 = {}); // Since C++20
467
468 template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
469 indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less>
470 constexpr bool ranges::is_sorted(I first, S last, Comp comp = {}, Proj proj = {}); // since C++20
471
472 template<forward_range R, class Proj = identity,
473 indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
474 constexpr bool ranges::is_sorted(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
475
476 template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
477 indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less>
478 constexpr I ranges::is_sorted_until(I first, S last, Comp comp = {}, Proj proj = {}); // since C++20
479
480 template<forward_range R, class Proj = identity,
481 indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
482 constexpr borrowed_iterator_t<R>
483 ranges::is_sorted_until(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
484
485 template<random_access_iterator I, sentinel_for<I> S, class Comp = ranges::less,
486 class Proj = identity>
487 requires sortable<I, Comp, Proj>
488 constexpr I
489 ranges::nth_element(I first, I nth, S last, Comp comp = {}, Proj proj = {}); // since C++20
490
491 template<random_access_range R, class Comp = ranges::less, class Proj = identity>
492 requires sortable<iterator_t<R>, Comp, Proj>
493 constexpr borrowed_iterator_t<R>
494 ranges::nth_element(R&& r, iterator_t<R> nth, Comp comp = {}, Proj proj = {}); // since C++20
495
496 template<forward_iterator I, sentinel_for<I> S, class T, class Proj = identity,
497 indirect_strict_weak_order<const T*, projected<I, Proj>> Comp = ranges::less>
498 constexpr I upper_bound(I first, S last, const T& value, Comp comp = {}, Proj proj = {}); // since C++20
499
500 template<forward_range R, class T, class Proj = identity,
501 indirect_strict_weak_order<const T*, projected<iterator_t<R>, Proj>> Comp =
502 ranges::less>
503 constexpr borrowed_iterator_t<R>
504 upper_bound(R&& r, const T& value, Comp comp = {}, Proj proj = {}); // since C++20
505
506 template<forward_iterator I, sentinel_for<I> S, class T, class Proj = identity,
507 indirect_strict_weak_order<const T*, projected<I, Proj>> Comp = ranges::less>
508 constexpr I lower_bound(I first, S last, const T& value, Comp comp = {},
509 Proj proj = {}); // since C++20
510 template<forward_range R, class T, class Proj = identity,
511 indirect_strict_weak_order<const T*, projected<iterator_t<R>, Proj>> Comp =
512 ranges::less>
513 constexpr borrowed_iterator_t<R>
514 lower_bound(R&& r, const T& value, Comp comp = {}, Proj proj = {}); // since C++20
515
516 template<forward_iterator I, sentinel_for<I> S, class T, class Proj = identity,
517 indirect_strict_weak_order<const T*, projected<I, Proj>> Comp = ranges::less>
518 constexpr bool binary_search(I first, S last, const T& value, Comp comp = {},
519 Proj proj = {}); // since C++20
520
521 template<forward_range R, class T, class Proj = identity,
522 indirect_strict_weak_order<const T*, projected<iterator_t<R>, Proj>> Comp =
523 ranges::less>
524 constexpr bool binary_search(R&& r, const T& value, Comp comp = {},
525 Proj proj = {}); // since C++20
526
527 template<permutable I, sentinel_for<I> S, class Proj = identity,
528 indirect_unary_predicate<projected<I, Proj>> Pred>
529 constexpr subrange<I>
530 partition(I first, S last, Pred pred, Proj proj = {}); // Since C++20
531
532 template<forward_range R, class Proj = identity,
533 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
534 requires permutable<iterator_t<R>>
535 constexpr borrowed_subrange_t<R>
536 partition(R&& r, Pred pred, Proj proj = {}); // Since C++20
537
538 template<bidirectional_iterator I, sentinel_for<I> S, class Proj = identity,
539 indirect_unary_predicate<projected<I, Proj>> Pred>
540 requires permutable<I>
541 subrange<I> stable_partition(I first, S last, Pred pred, Proj proj = {}); // Since C++20
542
543 template<bidirectional_range R, class Proj = identity,
544 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
545 requires permutable<iterator_t<R>>
546 borrowed_subrange_t<R> stable_partition(R&& r, Pred pred, Proj proj = {}); // Since C++20
547
548 template<input_iterator I1, sentinel_for<I1> S1, forward_iterator I2, sentinel_for<I2> S2,
549 class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
550 requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
551 constexpr I1 ranges::find_first_of(I1 first1, S1 last1, I2 first2, S2 last2,
552 Pred pred = {},
553 Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
554
555 template<input_range R1, forward_range R2,
556 class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
557 requires indirectly_comparable<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
558 constexpr borrowed_iterator_t<R1>
559 ranges::find_first_of(R1&& r1, R2&& r2,
560 Pred pred = {},
561 Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
562
563 template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
564 indirect_binary_predicate<projected<I, Proj>,
565 projected<I, Proj>> Pred = ranges::equal_to>
566 constexpr I ranges::adjacent_find(I first, S last, Pred pred = {}, Proj proj = {}); // since C+20
567
568 template<forward_range R, class Proj = identity,
569 indirect_binary_predicate<projected<iterator_t<R>, Proj>,
570 projected<iterator_t<R>, Proj>> Pred = ranges::equal_to>
571 constexpr borrowed_iterator_t<R> ranges::adjacent_find(R&& r, Pred pred = {}, Proj proj = {}); // since C++20
572
573 template<input_iterator I, sentinel_for<I> S, class T1, class T2, class Proj = identity>
574 requires indirectly_writable<I, const T2&> &&
575 indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T1*>
576 constexpr I
577 ranges::replace(I first, S last, const T1& old_value, const T2& new_value, Proj proj = {}); // since C++20
578
579 template<input_range R, class T1, class T2, class Proj = identity>
580 requires indirectly_writable<iterator_t<R>, const T2&> &&
581 indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T1*>
582 constexpr borrowed_iterator_t<R>
583 ranges::replace(R&& r, const T1& old_value, const T2& new_value, Proj proj = {}); // since C++20
584
585 template<input_iterator I, sentinel_for<I> S, class T, class Proj = identity,
586 indirect_unary_predicate<projected<I, Proj>> Pred>
587 requires indirectly_writable<I, const T&>
588 constexpr I ranges::replace_if(I first, S last, Pred pred, const T& new_value, Proj proj = {}); // since C++20
589
590 template<input_range R, class T, class Proj = identity,
591 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
592 requires indirectly_writable<iterator_t<R>, const T&>
593 constexpr borrowed_iterator_t<R>
594 ranges::replace_if(R&& r, Pred pred, const T& new_value, Proj proj = {}); // since C++20
595
596 template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
597 class Proj1 = identity, class Proj2 = identity,
598 indirect_strict_weak_order<projected<I1, Proj1>,
599 projected<I2, Proj2>> Comp = ranges::less>
600 constexpr bool
601 ranges::lexicographical_compare(I1 first1, S1 last1, I2 first2, S2 last2,
602 Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
603
604 template<input_range R1, input_range R2, class Proj1 = identity,
605 class Proj2 = identity,
606 indirect_strict_weak_order<projected<iterator_t<R1>, Proj1>,
607 projected<iterator_t<R2>, Proj2>> Comp = ranges::less>
608 constexpr bool
609 ranges::lexicographical_compare(R1&& r1, R2&& r2, Comp comp = {},
610 Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
611
612 template<bidirectional_iterator I1, sentinel_for<I1> S1, bidirectional_iterator I2>
613 requires indirectly_movable<I1, I2>
614 constexpr ranges::move_backward_result<I1, I2>
615 ranges::move_backward(I1 first, S1 last, I2 result); // since C++20
616
617 template<bidirectional_range R, bidirectional_iterator I>
618 requires indirectly_movable<iterator_t<R>, I>
619 constexpr ranges::move_backward_result<borrowed_iterator_t<R>, I>
620 ranges::move_backward(R&& r, I result); // since C++20
621
622 template<input_iterator I, sentinel_for<I> S, weakly_incrementable O>
623 requires indirectly_movable<I, O>
624 constexpr ranges::move_result<I, O>
625 ranges::move(I first, S last, O result); // since C++20
626
627 template<input_range R, weakly_incrementable O>
628 requires indirectly_movable<iterator_t<R>, O>
629 constexpr ranges::move_result<borrowed_iterator_t<R>, O>
630 ranges::move(R&& r, O result); // since C++20
631
632 template<class I, class O1, class O2>
633 using partition_copy_result = in_out_out_result<I, O1, O2>; // since C++20
634
635 template<input_iterator I, sentinel_for<I> S,
636 weakly_incrementable O1, weakly_incrementable O2,
637 class Proj = identity, indirect_unary_predicate<projected<I, Proj>> Pred>
638 requires indirectly_copyable<I, O1> && indirectly_copyable<I, O2>
639 constexpr partition_copy_result<I, O1, O2>
640 partition_copy(I first, S last, O1 out_true, O2 out_false, Pred pred,
641 Proj proj = {}); // Since C++20
642
643 template<input_range R, weakly_incrementable O1, weakly_incrementable O2,
644 class Proj = identity,
645 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
646 requires indirectly_copyable<iterator_t<R>, O1> &&
647 indirectly_copyable<iterator_t<R>, O2>
648 constexpr partition_copy_result<borrowed_iterator_t<R>, O1, O2>
649 partition_copy(R&& r, O1 out_true, O2 out_false, Pred pred, Proj proj = {}); // Since C++20
650
651 template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
652 indirect_unary_predicate<projected<I, Proj>> Pred>
653 constexpr I partition_point(I first, S last, Pred pred, Proj proj = {}); // Since C++20
654
655 template<forward_range R, class Proj = identity,
656 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
657 constexpr borrowed_iterator_t<R>
658 partition_point(R&& r, Pred pred, Proj proj = {}); // Since C++20
659
660 template<class I1, class I2, class O>
661 using merge_result = in_in_out_result<I1, I2, O>; // since C++20
662
663 template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
664 weakly_incrementable O, class Comp = ranges::less, class Proj1 = identity,
665 class Proj2 = identity>
666 requires mergeable<I1, I2, O, Comp, Proj1, Proj2>
667 constexpr merge_result<I1, I2, O>
668 merge(I1 first1, S1 last1, I2 first2, S2 last2, O result,
669 Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
670
671 template<input_range R1, input_range R2, weakly_incrementable O, class Comp = ranges::less,
672 class Proj1 = identity, class Proj2 = identity>
673 requires mergeable<iterator_t<R1>, iterator_t<R2>, O, Comp, Proj1, Proj2>
674 constexpr merge_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>, O>
675 merge(R1&& r1, R2&& r2, O result,
676 Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
677
678 template<permutable I, sentinel_for<I> S, class T, class Proj = identity>
679 requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>
680 constexpr subrange<I> ranges::remove(I first, S last, const T& value, Proj proj = {}); // since C++20
681
682 template<forward_range R, class T, class Proj = identity>
683 requires permutable<iterator_t<R>> &&
684 indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
685 constexpr borrowed_subrange_t<R>
686 ranges::remove(R&& r, const T& value, Proj proj = {}); // since C++20
687
688 template<permutable I, sentinel_for<I> S, class Proj = identity,
689 indirect_unary_predicate<projected<I, Proj>> Pred>
690 constexpr subrange<I> ranges::remove_if(I first, S last, Pred pred, Proj proj = {}); // since C++20
691
692 template<forward_range R, class Proj = identity,
693 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
694 requires permutable<iterator_t<R>>
695 constexpr borrowed_subrange_t<R>
696 ranges::remove_if(R&& r, Pred pred, Proj proj = {}); // since C++20
697
698 template<class I, class O>
699 using set_difference_result = in_out_result<I, O>; // since C++20
700
701 template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
702 weakly_incrementable O, class Comp = ranges::less,
703 class Proj1 = identity, class Proj2 = identity>
704 requires mergeable<I1, I2, O, Comp, Proj1, Proj2>
705 constexpr set_difference_result<I1, O>
706 set_difference(I1 first1, S1 last1, I2 first2, S2 last2, O result,
707 Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
708
709 template<input_range R1, input_range R2, weakly_incrementable O,
710 class Comp = ranges::less, class Proj1 = identity, class Proj2 = identity>
711 requires mergeable<iterator_t<R1>, iterator_t<R2>, O, Comp, Proj1, Proj2>
712 constexpr set_difference_result<borrowed_iterator_t<R1>, O>
713 set_difference(R1&& r1, R2&& r2, O result,
714 Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
715
716 template<class I1, class I2, class O>
717 using set_intersection_result = in_in_out_result<I1, I2, O>; // since C++20
718
719 template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
720 weakly_incrementable O, class Comp = ranges::less,
721 class Proj1 = identity, class Proj2 = identity>
722 requires mergeable<I1, I2, O, Comp, Proj1, Proj2>
723 constexpr set_intersection_result<I1, I2, O>
724 set_intersection(I1 first1, S1 last1, I2 first2, S2 last2, O result,
725 Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
726
727 template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
728 weakly_incrementable O, class Comp = ranges::less,
729 class Proj1 = identity, class Proj2 = identity>
730 requires mergeable<I1, I2, O, Comp, Proj1, Proj2>
731 constexpr set_intersection_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>, O>
732 set_intersection(R1&& r1, R2&& r2, O result,
733 Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
734
735 template <class _InIter, class _OutIter>
736 using reverse_copy_result = in_out_result<_InIter, _OutIter>; // since C++20
737
738 template<bidirectional_iterator I, sentinel_for<I> S, weakly_incrementable O>
739 requires indirectly_copyable<I, O>
740 constexpr ranges::reverse_copy_result<I, O>
741 ranges::reverse_copy(I first, S last, O result); // since C++20
742
743 template<bidirectional_range R, weakly_incrementable O>
744 requires indirectly_copyable<iterator_t<R>, O>
745 constexpr ranges::reverse_copy_result<borrowed_iterator_t<R>, O>
746 ranges::reverse_copy(R&& r, O result); // since C++20
747
748 template <class _InIter, class _OutIter>
749 using rotate_copy_result = in_out_result<_InIter, _OutIter>; // since C++20
750
751 template<forward_iterator I, sentinel_for<I> S, weakly_incrementable O>
752 requires indirectly_copyable<I, O>
753 constexpr ranges::rotate_copy_result<I, O>
754 ranges::rotate_copy(I first, I middle, S last, O result); // since C++20
755
756 template<forward_range R, weakly_incrementable O>
757 requires indirectly_copyable<iterator_t<R>, O>
758 constexpr ranges::rotate_copy_result<borrowed_iterator_t<R>, O>
759 ranges::rotate_copy(R&& r, iterator_t<R> middle, O result); // since C++20
760
761 template<random_access_iterator I, sentinel_for<I> S, class Gen>
762 requires permutable<I> &&
763 uniform_random_bit_generator<remove_reference_t<Gen>>
764 I shuffle(I first, S last, Gen&& g); // Since C++20
765
766 template<random_access_range R, class Gen>
767 requires permutable<iterator_t<R>> &&
768 uniform_random_bit_generator<remove_reference_t<Gen>>
769 borrowed_iterator_t<R> shuffle(R&& r, Gen&& g); // Since C++20
770
771 template<forward_iterator I1, sentinel_for<I1> S1, forward_iterator I2,
772 sentinel_for<I2> S2, class Pred = ranges::equal_to,
773 class Proj1 = identity, class Proj2 = identity>
774 requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
775 constexpr subrange<I1>
776 ranges::search(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {},
777 Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
778
779 template<forward_range R1, forward_range R2, class Pred = ranges::equal_to,
780 class Proj1 = identity, class Proj2 = identity>
781 requires indirectly_comparable<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
782 constexpr borrowed_subrange_t<R1>
783 ranges::search(R1&& r1, R2&& r2, Pred pred = {},
784 Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
785
786 template<forward_iterator I, sentinel_for<I> S, class T,
787 class Pred = ranges::equal_to, class Proj = identity>
788 requires indirectly_comparable<I, const T*, Pred, Proj>
789 constexpr subrange<I>
790 ranges::search_n(I first, S last, iter_difference_t<I> count,
791 const T& value, Pred pred = {}, Proj proj = {}); // since C++20
792
793 template<forward_range R, class T, class Pred = ranges::equal_to,
794 class Proj = identity>
795 requires indirectly_comparable<iterator_t<R>, const T*, Pred, Proj>
796 constexpr borrowed_subrange_t<R>
797 ranges::search_n(R&& r, range_difference_t<R> count,
798 const T& value, Pred pred = {}, Proj proj = {}); // since C++20
799
800 template<forward_iterator I1, sentinel_for<I1> S1, forward_iterator I2, sentinel_for<I2> S2,
801 class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
802 requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
803 constexpr subrange<I1>
804 ranges::find_end(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {},
805 Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
806
807 template<forward_range R1, forward_range R2,
808 class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
809 requires indirectly_comparable<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
810 constexpr borrowed_subrange_t<R1>
811 ranges::find_end(R1&& r1, R2&& r2, Pred pred = {},
812 Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
813
814 template<class I1, class I2, class O>
815 using set_symmetric_difference_result = in_in_out_result<I1, I2, O>; // since C++20
816
817 template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
818 weakly_incrementable O, class Comp = ranges::less,
819 class Proj1 = identity, class Proj2 = identity>
820 requires mergeable<I1, I2, O, Comp, Proj1, Proj2>
821 constexpr set_symmetric_difference_result<I1, I2, O>
822 set_symmetric_difference(I1 first1, S1 last1, I2 first2, S2 last2, O result,
823 Comp comp = {}, Proj1 proj1 = {},
824 Proj2 proj2 = {}); // since C++20
825
826 template<input_range R1, input_range R2, weakly_incrementable O,
827 class Comp = ranges::less, class Proj1 = identity, class Proj2 = identity>
828 requires mergeable<iterator_t<R1>, iterator_t<R2>, O, Comp, Proj1, Proj2>
829 constexpr set_symmetric_difference_result<borrowed_iterator_t<R1>,
830 borrowed_iterator_t<R2>, O>
831 set_symmetric_difference(R1&& r1, R2&& r2, O result, Comp comp = {},
832 Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
833
834 template<forward_iterator I, sentinel_for<I> S, class T, class Proj = identity,
835 indirect_strict_weak_order<const T*, projected<I, Proj>> Comp = ranges::less>
836 constexpr subrange<I>
837 equal_range(I first, S last, const T& value, Comp comp = {}, Proj proj = {}); // since C++20
838
839 template<forward_range R, class T, class Proj = identity,
840 indirect_strict_weak_order<const T*, projected<iterator_t<R>, Proj>> Comp =
841 ranges::less>
842 constexpr borrowed_subrange_t<R>
843 equal_range(R&& r, const T& value, Comp comp = {}, Proj proj = {}); // since C++20
844
845 template<class I1, class I2, class O>
846 using set_union_result = in_in_out_result<I1, I2, O>; // since C++20
847
848 template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
849 weakly_incrementable O, class Comp = ranges::less,
850 class Proj1 = identity, class Proj2 = identity>
851 requires mergeable<I1, I2, O, Comp, Proj1, Proj2>
852 constexpr set_union_result<I1, I2, O>
853 set_union(I1 first1, S1 last1, I2 first2, S2 last2, O result, Comp comp = {},
854 Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
855
856 template<input_range R1, input_range R2, weakly_incrementable O,
857 class Comp = ranges::less, class Proj1 = identity, class Proj2 = identity>
858 requires mergeable<iterator_t<R1>, iterator_t<R2>, O, Comp, Proj1, Proj2>
859 constexpr set_union_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>, O>
860 set_union(R1&& r1, R2&& r2, O result, Comp comp = {},
861 Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
862
863 template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
864 class Proj1 = identity, class Proj2 = identity,
865 indirect_strict_weak_order<projected<I1, Proj1>, projected<I2, Proj2>> Comp =
866 ranges::less>
867 constexpr bool includes(I1 first1, S1 last1, I2 first2, S2 last2, Comp comp = {},
868 Proj1 proj1 = {}, Proj2 proj2 = {}); // Since C++20
869
870 template<input_range R1, input_range R2, class Proj1 = identity,
871 class Proj2 = identity,
872 indirect_strict_weak_order<projected<iterator_t<R1>, Proj1>,
873 projected<iterator_t<R2>, Proj2>> Comp = ranges::less>
874 constexpr bool includes(R1&& r1, R2&& r2, Comp comp = {},
875 Proj1 proj1 = {}, Proj2 proj2 = {}); // Since C++20
876
877 template<bidirectional_iterator I, sentinel_for<I> S, class Comp = ranges::less,
878 class Proj = identity>
879 requires sortable<I, Comp, Proj>
880 I inplace_merge(I first, I middle, S last, Comp comp = {}, Proj proj = {}); // Since C++20
881
882 template<bidirectional_range R, class Comp = ranges::less, class Proj = identity>
883 requires sortable<iterator_t<R>, Comp, Proj>
884 borrowed_iterator_t<R>
885 inplace_merge(R&& r, iterator_t<R> middle, Comp comp = {},
886 Proj proj = {}); // Since C++20
887
888 template<permutable I, sentinel_for<I> S, class Proj = identity,
889 indirect_equivalence_relation<projected<I, Proj>> C = ranges::equal_to>
890 constexpr subrange<I> unique(I first, S last, C comp = {}, Proj proj = {}); // Since C++20
891
892 template<forward_range R, class Proj = identity,
893 indirect_equivalence_relation<projected<iterator_t<R>, Proj>> C = ranges::equal_to>
894 requires permutable<iterator_t<R>>
895 constexpr borrowed_subrange_t<R>
896 unique(R&& r, C comp = {}, Proj proj = {}); // Since C++20
897
898 template<input_iterator I, sentinel_for<I> S, weakly_incrementable O, class Proj = identity,
899 indirect_equivalence_relation<projected<I, Proj>> C = ranges::equal_to>
900 requires indirectly_copyable<I, O> &&
901 (forward_iterator<I> ||
902 (input_iterator<O> && same_as<iter_value_t<I>, iter_value_t<O>>) ||
903 indirectly_copyable_storable<I, O>)
904 constexpr unique_copy_result<I, O>
905 unique_copy(I first, S last, O result, C comp = {}, Proj proj = {}); // Since C++20
906
907 template<input_range R, weakly_incrementable O, class Proj = identity,
908 indirect_equivalence_relation<projected<iterator_t<R>, Proj>> C = ranges::equal_to>
909 requires indirectly_copyable<iterator_t<R>, O> &&
910 (forward_iterator<iterator_t<R>> ||
911 (input_iterator<O> && same_as<range_value_t<R>, iter_value_t<O>>) ||
912 indirectly_copyable_storable<iterator_t<R>, O>)
913 constexpr unique_copy_result<borrowed_iterator_t<R>, O>
914 unique_copy(R&& r, O result, C comp = {}, Proj proj = {}); // Since C++20
27915}
28916
29template <class InputIterator, class Predicate>
30917 constexpr bool // constexpr in C++20
31918 all_of(InputIterator first, InputIterator last, Predicate pred);
32919
......@@ -192,10 +1079,35 @@ template <class BidirectionalIterator1, class BidirectionalIterator2>
1921079 copy_backward(BidirectionalIterator1 first, BidirectionalIterator1 last,
1931080 BidirectionalIterator2 result);
1941081
1082// [alg.move], move
1083template<class InputIterator, class OutputIterator>
1084 constexpr OutputIterator move(InputIterator first, InputIterator last,
1085 OutputIterator result);
1086
1087template<class BidirectionalIterator1, class BidirectionalIterator2>
1088 constexpr BidirectionalIterator2
1089 move_backward(BidirectionalIterator1 first, BidirectionalIterator1 last,
1090 BidirectionalIterator2 result);
1091
1951092template <class ForwardIterator1, class ForwardIterator2>
1961093 constexpr ForwardIterator2 // constexpr in C++20
1971094 swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2);
1981095
1096namespace ranges {
1097 template<class I1, class I2>
1098 using swap_ranges_result = in_in_result<I1, I2>;
1099
1100template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2>
1101 requires indirectly_swappable<I1, I2>
1102 constexpr ranges::swap_ranges_result<I1, I2>
1103 swap_ranges(I1 first1, S1 last1, I2 first2, S2 last2);
1104
1105template<input_range R1, input_range R2>
1106 requires indirectly_swappable<iterator_t<R1>, iterator_t<R2>>
1107 constexpr ranges::swap_ranges_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>>
1108 swap_ranges(R1&& r1, R2&& r2);
1109}
1110
1991111template <class ForwardIterator1, class ForwardIterator2>
2001112 constexpr void // constexpr in C++20
2011113 iter_swap(ForwardIterator1 a, ForwardIterator2 b);
......@@ -648,28 +1560,18 @@ template <class BidirectionalIterator>
6481560template <class BidirectionalIterator, class Compare>
6491561 constexpr bool // constexpr in C++20
6501562 prev_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp);
651
652namespace ranges {
653// [algorithms.results], algorithm result types
654template<class InputIterator, class OutputIterator>
655 struct in_out_result;
656}
657
6581563} // std
6591564
6601565*/
6611566
662#include <__bits> // __libcpp_clz
1567#include <__assert> // all public C++ headers provide the assertion handler
1568#include <__bits>
6631569#include <__config>
6641570#include <__debug>
6651571#include <cstddef>
6661572#include <cstring>
667#include <functional>
668#include <initializer_list>
669#include <iterator>
6701573#include <memory>
6711574#include <type_traits>
672#include <utility> // swap_ranges
6731575#include <version>
6741576
6751577#include <__algorithm/adjacent_find.h>
......@@ -699,8 +1601,11 @@ template<class InputIterator, class OutputIterator>
6991601#include <__algorithm/generate.h>
7001602#include <__algorithm/generate_n.h>
7011603#include <__algorithm/half_positive.h>
1604#include <__algorithm/in_found_result.h>
1605#include <__algorithm/in_fun_result.h>
7021606#include <__algorithm/in_in_out_result.h>
7031607#include <__algorithm/in_in_result.h>
1608#include <__algorithm/in_out_out_result.h>
7041609#include <__algorithm/in_out_result.h>
7051610#include <__algorithm/includes.h>
7061611#include <__algorithm/inplace_merge.h>
......@@ -719,6 +1624,7 @@ template<class InputIterator, class OutputIterator>
7191624#include <__algorithm/merge.h>
7201625#include <__algorithm/min.h>
7211626#include <__algorithm/min_element.h>
1627#include <__algorithm/min_max_result.h>
7221628#include <__algorithm/minmax.h>
7231629#include <__algorithm/minmax_element.h>
7241630#include <__algorithm/mismatch.h>
......@@ -735,6 +1641,81 @@ template<class InputIterator, class OutputIterator>
7351641#include <__algorithm/pop_heap.h>
7361642#include <__algorithm/prev_permutation.h>
7371643#include <__algorithm/push_heap.h>
1644#include <__algorithm/ranges_adjacent_find.h>
1645#include <__algorithm/ranges_all_of.h>
1646#include <__algorithm/ranges_any_of.h>
1647#include <__algorithm/ranges_binary_search.h>
1648#include <__algorithm/ranges_copy.h>
1649#include <__algorithm/ranges_copy_backward.h>
1650#include <__algorithm/ranges_copy_if.h>
1651#include <__algorithm/ranges_copy_n.h>
1652#include <__algorithm/ranges_count.h>
1653#include <__algorithm/ranges_count_if.h>
1654#include <__algorithm/ranges_equal.h>
1655#include <__algorithm/ranges_equal_range.h>
1656#include <__algorithm/ranges_fill.h>
1657#include <__algorithm/ranges_fill_n.h>
1658#include <__algorithm/ranges_find.h>
1659#include <__algorithm/ranges_find_end.h>
1660#include <__algorithm/ranges_find_first_of.h>
1661#include <__algorithm/ranges_find_if.h>
1662#include <__algorithm/ranges_find_if_not.h>
1663#include <__algorithm/ranges_for_each.h>
1664#include <__algorithm/ranges_for_each_n.h>
1665#include <__algorithm/ranges_generate.h>
1666#include <__algorithm/ranges_generate_n.h>
1667#include <__algorithm/ranges_includes.h>
1668#include <__algorithm/ranges_inplace_merge.h>
1669#include <__algorithm/ranges_is_heap.h>
1670#include <__algorithm/ranges_is_heap_until.h>
1671#include <__algorithm/ranges_is_partitioned.h>
1672#include <__algorithm/ranges_is_sorted.h>
1673#include <__algorithm/ranges_is_sorted_until.h>
1674#include <__algorithm/ranges_lexicographical_compare.h>
1675#include <__algorithm/ranges_lower_bound.h>
1676#include <__algorithm/ranges_make_heap.h>
1677#include <__algorithm/ranges_max.h>
1678#include <__algorithm/ranges_max_element.h>
1679#include <__algorithm/ranges_merge.h>
1680#include <__algorithm/ranges_min.h>
1681#include <__algorithm/ranges_min_element.h>
1682#include <__algorithm/ranges_minmax.h>
1683#include <__algorithm/ranges_minmax_element.h>
1684#include <__algorithm/ranges_mismatch.h>
1685#include <__algorithm/ranges_move.h>
1686#include <__algorithm/ranges_move_backward.h>
1687#include <__algorithm/ranges_none_of.h>
1688#include <__algorithm/ranges_nth_element.h>
1689#include <__algorithm/ranges_partial_sort.h>
1690#include <__algorithm/ranges_partial_sort_copy.h>
1691#include <__algorithm/ranges_partition.h>
1692#include <__algorithm/ranges_partition_copy.h>
1693#include <__algorithm/ranges_partition_point.h>
1694#include <__algorithm/ranges_pop_heap.h>
1695#include <__algorithm/ranges_push_heap.h>
1696#include <__algorithm/ranges_remove.h>
1697#include <__algorithm/ranges_remove_if.h>
1698#include <__algorithm/ranges_replace.h>
1699#include <__algorithm/ranges_replace_if.h>
1700#include <__algorithm/ranges_reverse.h>
1701#include <__algorithm/ranges_reverse_copy.h>
1702#include <__algorithm/ranges_rotate_copy.h>
1703#include <__algorithm/ranges_search.h>
1704#include <__algorithm/ranges_search_n.h>
1705#include <__algorithm/ranges_set_difference.h>
1706#include <__algorithm/ranges_set_intersection.h>
1707#include <__algorithm/ranges_set_symmetric_difference.h>
1708#include <__algorithm/ranges_set_union.h>
1709#include <__algorithm/ranges_shuffle.h>
1710#include <__algorithm/ranges_sort.h>
1711#include <__algorithm/ranges_sort_heap.h>
1712#include <__algorithm/ranges_stable_partition.h>
1713#include <__algorithm/ranges_stable_sort.h>
1714#include <__algorithm/ranges_swap_ranges.h>
1715#include <__algorithm/ranges_transform.h>
1716#include <__algorithm/ranges_unique.h>
1717#include <__algorithm/ranges_unique_copy.h>
1718#include <__algorithm/ranges_upper_bound.h>
7381719#include <__algorithm/remove.h>
7391720#include <__algorithm/remove_copy.h>
7401721#include <__algorithm/remove_copy_if.h>
......@@ -769,8 +1750,17 @@ template<class InputIterator, class OutputIterator>
7691750#include <__algorithm/unwrap_iter.h>
7701751#include <__algorithm/upper_bound.h>
7711752
1753#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
1754# include <chrono>
1755# include <iterator>
1756# include <utility>
1757#endif
1758
1759// standard-mandated includes
1760#include <initializer_list>
1761
7721762#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
773#pragma GCC system_header
1763# pragma GCC system_header
7741764#endif
7751765
7761766#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17
lib/libcxx/include/any+14-2
......@@ -80,17 +80,26 @@ namespace std {
8080
8181*/
8282
83#include <__assert> // all public C++ headers provide the assertion handler
8384#include <__availability>
8485#include <__config>
8586#include <__utility/forward.h>
87#include <__utility/in_place.h>
88#include <__utility/move.h>
89#include <__utility/unreachable.h>
8690#include <cstdlib>
91#include <initializer_list>
8792#include <memory>
8893#include <type_traits>
8994#include <typeinfo>
9095#include <version>
9196
97#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
98# include <chrono>
99#endif
100
92101#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
93#pragma GCC system_header
102# pragma GCC system_header
94103#endif
95104
96105namespace std {
......@@ -262,7 +271,7 @@ public:
262271 is_copy_constructible<_Tp>::value>
263272 >
264273 _LIBCPP_INLINE_VISIBILITY
265 _Tp& emplace(_Args&&... args);
274 _Tp& emplace(_Args&&...);
266275
267276 template <class _ValueType, class _Up, class ..._Args,
268277 class _Tp = decay_t<_ValueType>,
......@@ -364,6 +373,7 @@ namespace __any_imp
364373 case _Action::_TypeInfo:
365374 return __type_info();
366375 }
376 __libcpp_unreachable();
367377 }
368378
369379 template <class ..._Args>
......@@ -447,6 +457,7 @@ namespace __any_imp
447457 case _Action::_TypeInfo:
448458 return __type_info();
449459 }
460 __libcpp_unreachable();
450461 }
451462
452463 template <class ..._Args>
......@@ -658,6 +669,7 @@ _RetType __pointer_or_func_cast(void*, /*IsFunction*/true_type) noexcept {
658669}
659670
660671template <class _ValueType>
672_LIBCPP_HIDE_FROM_ABI
661673add_pointer_t<_ValueType>
662674any_cast(any * __any) _NOEXCEPT
663675{
lib/libcxx/include/array+39-21
......@@ -108,19 +108,42 @@ template <size_t I, class T, size_t N> const T&& get(const array<T, N>&&) noexce
108108
109109*/
110110
111#include <__algorithm/equal.h>
112#include <__algorithm/fill_n.h>
113#include <__algorithm/lexicographical_compare.h>
114#include <__algorithm/swap_ranges.h>
115#include <__assert> // all public C++ headers provide the assertion handler
111116#include <__config>
112#include <__debug>
117#include <__iterator/reverse_iterator.h>
113118#include <__tuple>
114#include <algorithm>
115#include <cstdlib> // for _LIBCPP_UNREACHABLE
116#include <iterator>
119#include <__utility/integer_sequence.h>
120#include <__utility/move.h>
121#include <__utility/unreachable.h>
117122#include <stdexcept>
118123#include <type_traits>
119#include <utility>
120124#include <version>
121125
126#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
127# include <algorithm>
128# include <iterator>
129# include <utility>
130#endif
131
132// standard-mandated includes
133
134// [iterator.range]
135#include <__iterator/access.h>
136#include <__iterator/data.h>
137#include <__iterator/empty.h>
138#include <__iterator/reverse_access.h>
139#include <__iterator/size.h>
140
141// [array.syn]
142#include <compare>
143#include <initializer_list>
144
122145#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
123#pragma GCC system_header
146# pragma GCC system_header
124147#endif
125148
126149_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -309,54 +332,54 @@ struct _LIBCPP_TEMPLATE_VIS array<_Tp, 0>
309332 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
310333 reference operator[](size_type) _NOEXCEPT {
311334 _LIBCPP_ASSERT(false, "cannot call array<T, 0>::operator[] on a zero-sized array");
312 _LIBCPP_UNREACHABLE();
335 __libcpp_unreachable();
313336 }
314337
315338 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
316339 const_reference operator[](size_type) const _NOEXCEPT {
317340 _LIBCPP_ASSERT(false, "cannot call array<T, 0>::operator[] on a zero-sized array");
318 _LIBCPP_UNREACHABLE();
341 __libcpp_unreachable();
319342 }
320343
321344 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
322345 reference at(size_type) {
323346 __throw_out_of_range("array<T, 0>::at");
324 _LIBCPP_UNREACHABLE();
347 __libcpp_unreachable();
325348 }
326349
327350 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
328351 const_reference at(size_type) const {
329352 __throw_out_of_range("array<T, 0>::at");
330 _LIBCPP_UNREACHABLE();
353 __libcpp_unreachable();
331354 }
332355
333356 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
334357 reference front() _NOEXCEPT {
335358 _LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array");
336 _LIBCPP_UNREACHABLE();
359 __libcpp_unreachable();
337360 }
338361
339362 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
340363 const_reference front() const _NOEXCEPT {
341364 _LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array");
342 _LIBCPP_UNREACHABLE();
365 __libcpp_unreachable();
343366 }
344367
345368 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
346369 reference back() _NOEXCEPT {
347370 _LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array");
348 _LIBCPP_UNREACHABLE();
371 __libcpp_unreachable();
349372 }
350373
351374 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
352375 const_reference back() const _NOEXCEPT {
353376 _LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array");
354 _LIBCPP_UNREACHABLE();
377 __libcpp_unreachable();
355378 }
356379};
357380
358381
359#if _LIBCPP_STD_VER >= 17
382#if _LIBCPP_STD_VER > 14
360383template<class _Tp, class... _Args,
361384 class = enable_if_t<__all<_IsSame<_Tp, _Args>::value...>::value>
362385 >
......@@ -415,12 +438,7 @@ operator>=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
415438
416439template <class _Tp, size_t _Size>
417440inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
418typename enable_if
419<
420 _Size == 0 ||
421 __is_swappable<_Tp>::value,
422 void
423>::type
441__enable_if_t<_Size == 0 || __is_swappable<_Tp>::value, void>
424442swap(array<_Tp, _Size>& __x, array<_Tp, _Size>& __y)
425443 _NOEXCEPT_(noexcept(__x.swap(__y)))
426444{
lib/libcxx/include/atomic+15-25
......@@ -518,7 +518,9 @@ template <class T>
518518
519519*/
520520
521#include <__assert> // all public C++ headers provide the assertion handler
521522#include <__availability>
523#include <__chrono/duration.h>
522524#include <__config>
523525#include <__thread/poll_with_backoff.h>
524526#include <__thread/timed_backoff_policy.h>
......@@ -532,15 +534,19 @@ template <class T>
532534# include <__threading_support>
533535#endif
534536
537#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
538# include <chrono>
539#endif
540
535541#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
536#pragma GCC system_header
542# pragma GCC system_header
537543#endif
538544
539545#ifdef _LIBCPP_HAS_NO_ATOMIC_HEADER
540546# error <atomic> is not implemented
541547#endif
542548#ifdef kill_dependency
543# error C++ standard library is incompatible with <stdatomic.h>
549# error <atomic> is incompatible with <stdatomic.h> before C++23. Please compile with -std=c++23.
544550#endif
545551
546552#define _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) \
......@@ -900,8 +906,8 @@ struct __cxx_atomic_base_impl {
900906#else
901907 __cxx_atomic_base_impl() _NOEXCEPT : __a_value() {}
902908#endif // _LIBCPP_CXX03_LANG
903 _LIBCPP_CONSTEXPR explicit __cxx_atomic_base_impl(_Tp value) _NOEXCEPT
904 : __a_value(value) {}
909 _LIBCPP_CONSTEXPR explicit __cxx_atomic_base_impl(_Tp __value) _NOEXCEPT
910 : __a_value(__value) {}
905911 _LIBCPP_DISABLE_EXTENSION_WARNING _Atomic(_Tp) __a_value;
906912};
907913
......@@ -1445,15 +1451,15 @@ struct __cxx_atomic_impl : public _Base {
14451451 "std::atomic<T> requires that 'T' be a trivially copyable type");
14461452
14471453 _LIBCPP_INLINE_VISIBILITY __cxx_atomic_impl() _NOEXCEPT = default;
1448 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR explicit __cxx_atomic_impl(_Tp value) _NOEXCEPT
1449 : _Base(value) {}
1454 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR explicit __cxx_atomic_impl(_Tp __value) _NOEXCEPT
1455 : _Base(__value) {}
14501456};
14511457
1452#ifdef __linux__
1458#if defined(__linux__) || (defined(_AIX) && !defined(__64BIT__))
14531459 using __cxx_contention_t = int32_t;
14541460#else
14551461 using __cxx_contention_t = int64_t;
1456#endif //__linux__
1462#endif // __linux__ || (_AIX && !__64BIT__)
14571463
14581464using __cxx_atomic_contention_t = __cxx_atomic_impl<__cxx_contention_t>;
14591465
......@@ -1651,13 +1657,7 @@ struct __atomic_base // false
16511657 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
16521658 __atomic_base(_Tp __d) _NOEXCEPT : __a_(__d) {}
16531659
1654#ifndef _LIBCPP_CXX03_LANG
16551660 __atomic_base(const __atomic_base&) = delete;
1656#else
1657private:
1658 _LIBCPP_INLINE_VISIBILITY
1659 __atomic_base(const __atomic_base&);
1660#endif
16611661};
16621662
16631663#if defined(__cpp_lib_atomic_is_always_lock_free)
......@@ -2439,19 +2439,10 @@ typedef struct atomic_flag
24392439 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
24402440 atomic_flag(bool __b) _NOEXCEPT : __a_(__b) {} // EXTENSION
24412441
2442#ifndef _LIBCPP_CXX03_LANG
24432442 atomic_flag(const atomic_flag&) = delete;
24442443 atomic_flag& operator=(const atomic_flag&) = delete;
24452444 atomic_flag& operator=(const atomic_flag&) volatile = delete;
2446#else
2447private:
2448 _LIBCPP_INLINE_VISIBILITY
2449 atomic_flag(const atomic_flag&);
2450 _LIBCPP_INLINE_VISIBILITY
2451 atomic_flag& operator=(const atomic_flag&);
2452 _LIBCPP_INLINE_VISIBILITY
2453 atomic_flag& operator=(const atomic_flag&) volatile;
2454#endif
2445
24552446} atomic_flag;
24562447
24572448
......@@ -2705,7 +2696,6 @@ typedef atomic<__libcpp_unsigned_lock_free> atomic_unsigned_lock_free;
27052696
27062697#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS)
27072698# if defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER >= 1400
2708# pragma clang deprecated(ATOMIC_FLAG_INIT)
27092699# pragma clang deprecated(ATOMIC_VAR_INIT)
27102700# endif
27112701#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS)
lib/libcxx/include/barrier+28-28
......@@ -45,20 +45,20 @@ namespace std
4545
4646*/
4747
48#include <__assert> // all public C++ headers provide the assertion handler
4849#include <__availability>
4950#include <__config>
5051#include <__thread/timed_backoff_policy.h>
5152#include <atomic>
52#ifndef _LIBCPP_HAS_NO_TREE_BARRIER
53# include <memory>
54#endif
53#include <limits>
54#include <memory>
5555
5656#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
57#pragma GCC system_header
57# pragma GCC system_header
5858#endif
5959
6060#ifdef _LIBCPP_HAS_NO_THREADS
61# error <barrier> is not supported on this single threaded system
61# error "<barrier> is not supported since libc++ has been configured without support for threads."
6262#endif
6363
6464_LIBCPP_PUSH_MACROS
......@@ -108,12 +108,12 @@ void __destroy_barrier_algorithm_base(__barrier_algorithm_base* __barrier);
108108
109109template<class _CompletionF>
110110class __barrier_base {
111 ptrdiff_t __expected;
111 ptrdiff_t __expected_;
112112 unique_ptr<__barrier_algorithm_base,
113 void (*)(__barrier_algorithm_base*)> __base;
114 __atomic_base<ptrdiff_t> __expected_adjustment;
115 _CompletionF __completion;
116 __atomic_base<__barrier_phase_t> __phase;
113 void (*)(__barrier_algorithm_base*)> __base_;
114 __atomic_base<ptrdiff_t> __expected_adjustment_;
115 _CompletionF __completion_;
116 __atomic_base<__barrier_phase_t> __phase_;
117117
118118public:
119119 using arrival_token = __barrier_phase_t;
......@@ -124,22 +124,22 @@ public:
124124
125125 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
126126 __barrier_base(ptrdiff_t __expected, _CompletionF __completion = _CompletionF())
127 : __expected(__expected), __base(__construct_barrier_algorithm_base(this->__expected),
128 &__destroy_barrier_algorithm_base),
129 __expected_adjustment(0), __completion(move(__completion)), __phase(0)
127 : __expected_(__expected), __base_(__construct_barrier_algorithm_base(this->__expected_),
128 &__destroy_barrier_algorithm_base),
129 __expected_adjustment_(0), __completion_(std::move(__completion)), __phase_(0)
130130 {
131131 }
132132 [[nodiscard]] _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
133 arrival_token arrive(ptrdiff_t update)
133 arrival_token arrive(ptrdiff_t __update)
134134 {
135 auto const __old_phase = __phase.load(memory_order_relaxed);
136 for(; update; --update)
137 if(__arrive_barrier_algorithm_base(__base.get(), __old_phase)) {
138 __completion();
139 __expected += __expected_adjustment.load(memory_order_relaxed);
140 __expected_adjustment.store(0, memory_order_relaxed);
141 __phase.store(__old_phase + 2, memory_order_release);
142 __phase.notify_all();
135 auto const __old_phase = __phase_.load(memory_order_relaxed);
136 for(; __update; --__update)
137 if(__arrive_barrier_algorithm_base(__base_.get(), __old_phase)) {
138 __completion_();
139 __expected_ += __expected_adjustment_.load(memory_order_relaxed);
140 __expected_adjustment_.store(0, memory_order_relaxed);
141 __phase_.store(__old_phase + 2, memory_order_release);
142 __phase_.notify_all();
143143 }
144144 return __old_phase;
145145 }
......@@ -147,14 +147,14 @@ public:
147147 void wait(arrival_token&& __old_phase) const
148148 {
149149 auto const __test_fn = [this, __old_phase]() -> bool {
150 return __phase.load(memory_order_acquire) != __old_phase;
150 return __phase_.load(memory_order_acquire) != __old_phase;
151151 };
152152 __libcpp_thread_poll_with_backoff(__test_fn, __libcpp_timed_backoff_policy());
153153 }
154154 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
155155 void arrive_and_drop()
156156 {
157 __expected_adjustment.fetch_sub(1, memory_order_relaxed);
157 __expected_adjustment_.fetch_sub(1, memory_order_relaxed);
158158 (void)arrive(1);
159159 }
160160};
......@@ -190,7 +190,7 @@ public:
190190
191191 _LIBCPP_INLINE_VISIBILITY
192192 __barrier_base(ptrdiff_t __expected, _CompletionF __completion = _CompletionF())
193 : __expected(__expected), __arrived(__expected), __completion(move(__completion)), __phase(false)
193 : __expected(__expected), __arrived(__expected), __completion(std::move(__completion)), __phase(false)
194194 {
195195 }
196196 [[nodiscard]] _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
......@@ -278,7 +278,7 @@ public:
278278 }
279279};
280280
281#endif //_LIBCPP_HAS_NO_TREE_BARRIER
281#endif // !_LIBCPP_HAS_NO_TREE_BARRIER
282282
283283template<class _CompletionF = __empty_completion>
284284class barrier {
......@@ -300,9 +300,9 @@ public:
300300 barrier& operator=(barrier const&) = delete;
301301
302302 [[nodiscard]] _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
303 arrival_token arrive(ptrdiff_t update = 1)
303 arrival_token arrive(ptrdiff_t __update = 1)
304304 {
305 return __b.arrive(update);
305 return __b.arrive(__update);
306306 }
307307 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
308308 void wait(arrival_token&& __phase) const
lib/libcxx/include/bit+107-198
......@@ -30,7 +30,7 @@ namespace std {
3030 template <class T>
3131 constexpr T bit_floor(T x) noexcept; // C++20
3232 template <class T>
33 constexpr T bit_width(T x) noexcept; // C++20
33 constexpr int bit_width(T x) noexcept; // C++20
3434
3535 // [bit.rotate], rotating
3636 template<class T>
......@@ -61,24 +61,26 @@ namespace std {
6161
6262*/
6363
64#include <__assert> // all public C++ headers provide the assertion handler
6465#include <__bit/bit_cast.h>
6566#include <__bit/byteswap.h>
6667#include <__bits> // __libcpp_clz
68#include <__concepts/arithmetic.h>
6769#include <__config>
68#include <__debug>
6970#include <limits>
7071#include <type_traits>
7172#include <version>
7273
73#if defined(__IBMCPP__)
74#include "__support/ibm/support.h"
74#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
75# include <iosfwd>
7576#endif
77
7678#if defined(_LIBCPP_COMPILER_MSVC)
77#include <intrin.h>
79# include <intrin.h>
7880#endif
7981
8082#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
81#pragma GCC system_header
83# pragma GCC system_header
8284#endif
8385
8486_LIBCPP_PUSH_MACROS
......@@ -87,18 +89,7 @@ _LIBCPP_PUSH_MACROS
8789_LIBCPP_BEGIN_NAMESPACE_STD
8890
8991template<class _Tp>
90_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
91_Tp __rotl(_Tp __t, unsigned int __cnt) _NOEXCEPT
92{
93 static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__rotl requires an unsigned integer type");
94 const unsigned int __dig = numeric_limits<_Tp>::digits;
95 if ((__cnt % __dig) == 0)
96 return __t;
97 return (__t << (__cnt % __dig)) | (__t >> (__dig - (__cnt % __dig)));
98}
99
100template<class _Tp>
101_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
92_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
10293_Tp __rotr(_Tp __t, unsigned int __cnt) _NOEXCEPT
10394{
10495 static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__rotr requires an unsigned integer type");
......@@ -109,34 +100,7 @@ _Tp __rotr(_Tp __t, unsigned int __cnt) _NOEXCEPT
109100}
110101
111102template<class _Tp>
112_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
113int __countr_zero(_Tp __t) _NOEXCEPT
114{
115 static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__countr_zero requires an unsigned integer type");
116 if (__t == 0)
117 return numeric_limits<_Tp>::digits;
118
119 if (sizeof(_Tp) <= sizeof(unsigned int))
120 return __libcpp_ctz(static_cast<unsigned int>(__t));
121 else if (sizeof(_Tp) <= sizeof(unsigned long))
122 return __libcpp_ctz(static_cast<unsigned long>(__t));
123 else if (sizeof(_Tp) <= sizeof(unsigned long long))
124 return __libcpp_ctz(static_cast<unsigned long long>(__t));
125 else
126 {
127 int __ret = 0;
128 const unsigned int __ulldigits = numeric_limits<unsigned long long>::digits;
129 while (static_cast<unsigned long long>(__t) == 0uLL)
130 {
131 __ret += __ulldigits;
132 __t >>= __ulldigits;
133 }
134 return __ret + __libcpp_ctz(static_cast<unsigned long long>(__t));
135 }
136}
137
138template<class _Tp>
139_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
103_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
140104int __countl_zero(_Tp __t) _NOEXCEPT
141105{
142106 static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__countl_zero requires an unsigned integer type");
......@@ -144,13 +108,13 @@ int __countl_zero(_Tp __t) _NOEXCEPT
144108 return numeric_limits<_Tp>::digits;
145109
146110 if (sizeof(_Tp) <= sizeof(unsigned int))
147 return __libcpp_clz(static_cast<unsigned int>(__t))
111 return std::__libcpp_clz(static_cast<unsigned int>(__t))
148112 - (numeric_limits<unsigned int>::digits - numeric_limits<_Tp>::digits);
149113 else if (sizeof(_Tp) <= sizeof(unsigned long))
150 return __libcpp_clz(static_cast<unsigned long>(__t))
114 return std::__libcpp_clz(static_cast<unsigned long>(__t))
151115 - (numeric_limits<unsigned long>::digits - numeric_limits<_Tp>::digits);
152116 else if (sizeof(_Tp) <= sizeof(unsigned long long))
153 return __libcpp_clz(static_cast<unsigned long long>(__t))
117 return std::__libcpp_clz(static_cast<unsigned long long>(__t))
154118 - (numeric_limits<unsigned long long>::digits - numeric_limits<_Tp>::digits);
155119 else
156120 {
......@@ -158,8 +122,8 @@ int __countl_zero(_Tp __t) _NOEXCEPT
158122 int __iter = 0;
159123 const unsigned int __ulldigits = numeric_limits<unsigned long long>::digits;
160124 while (true) {
161 __t = __rotr(__t, __ulldigits);
162 if ((__iter = __countl_zero(static_cast<unsigned long long>(__t))) != __ulldigits)
125 __t = std::__rotr(__t, __ulldigits);
126 if ((__iter = std::__countl_zero(static_cast<unsigned long long>(__t))) != __ulldigits)
163127 break;
164128 __ret += __iter;
165129 }
......@@ -167,178 +131,123 @@ int __countl_zero(_Tp __t) _NOEXCEPT
167131 }
168132}
169133
170template<class _Tp>
171_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
172int __countl_one(_Tp __t) _NOEXCEPT
173{
174 static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__countl_one requires an unsigned integer type");
175 return __t != numeric_limits<_Tp>::max()
176 ? __countl_zero(static_cast<_Tp>(~__t))
177 : numeric_limits<_Tp>::digits;
178}
179
180template<class _Tp>
181_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
182int __countr_one(_Tp __t) _NOEXCEPT
183{
184 static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__countr_one requires an unsigned integer type");
185 return __t != numeric_limits<_Tp>::max()
186 ? __countr_zero(static_cast<_Tp>(~__t))
187 : numeric_limits<_Tp>::digits;
188}
189
190template<class _Tp>
191_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
192int __popcount(_Tp __t) _NOEXCEPT
193{
194 static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__popcount requires an unsigned integer type");
195 if (sizeof(_Tp) <= sizeof(unsigned int))
196 return __libcpp_popcount(static_cast<unsigned int>(__t));
197 else if (sizeof(_Tp) <= sizeof(unsigned long))
198 return __libcpp_popcount(static_cast<unsigned long>(__t));
199 else if (sizeof(_Tp) <= sizeof(unsigned long long))
200 return __libcpp_popcount(static_cast<unsigned long long>(__t));
201 else
202 {
203 int __ret = 0;
204 while (__t != 0)
205 {
206 __ret += __libcpp_popcount(static_cast<unsigned long long>(__t));
207 __t >>= numeric_limits<unsigned long long>::digits;
208 }
209 return __ret;
210 }
211}
212
213// integral log base 2
214template<class _Tp>
215_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
216unsigned __bit_log2(_Tp __t) _NOEXCEPT
217{
218 static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__bit_log2 requires an unsigned integer type");
219 return numeric_limits<_Tp>::digits - 1 - __countl_zero(__t);
220}
221
222template <class _Tp>
223_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
224bool __has_single_bit(_Tp __t) _NOEXCEPT
225{
226 static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__has_single_bit requires an unsigned integer type");
227 return __t != 0 && (((__t & (__t - 1)) == 0));
228}
229
230134#if _LIBCPP_STD_VER > 17
231135
232template<class _Tp>
233_LIBCPP_INLINE_VISIBILITY constexpr
234enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, _Tp>
235rotl(_Tp __t, unsigned int __cnt) noexcept
236{
237 return __rotl(__t, __cnt);
136template <__libcpp_unsigned_integer _Tp>
137_LIBCPP_HIDE_FROM_ABI constexpr _Tp rotl(_Tp __t, unsigned int __cnt) noexcept {
138 const unsigned int __dig = numeric_limits<_Tp>::digits;
139 if ((__cnt % __dig) == 0)
140 return __t;
141 return (__t << (__cnt % __dig)) | (__t >> (__dig - (__cnt % __dig)));
238142}
239143
240template<class _Tp>
241_LIBCPP_INLINE_VISIBILITY constexpr
242enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, _Tp>
243rotr(_Tp __t, unsigned int __cnt) noexcept
244{
245 return __rotr(__t, __cnt);
144template <__libcpp_unsigned_integer _Tp>
145_LIBCPP_HIDE_FROM_ABI constexpr _Tp rotr(_Tp __t, unsigned int __cnt) noexcept {
146 return std::__rotr(__t, __cnt);
246147}
247148
248template<class _Tp>
249_LIBCPP_INLINE_VISIBILITY constexpr
250enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, int>
251countl_zero(_Tp __t) noexcept
252{
253 return __countl_zero(__t);
149template <__libcpp_unsigned_integer _Tp>
150_LIBCPP_HIDE_FROM_ABI constexpr int countl_zero(_Tp __t) noexcept {
151 return std::__countl_zero(__t);
254152}
255153
256template<class _Tp>
257_LIBCPP_INLINE_VISIBILITY constexpr
258enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, int>
259countl_one(_Tp __t) noexcept
260{
261 return __countl_one(__t);
154template <__libcpp_unsigned_integer _Tp>
155_LIBCPP_HIDE_FROM_ABI constexpr int countl_one(_Tp __t) noexcept {
156 return __t != numeric_limits<_Tp>::max() ? std::countl_zero(static_cast<_Tp>(~__t)) : numeric_limits<_Tp>::digits;
262157}
263158
264template<class _Tp>
265_LIBCPP_INLINE_VISIBILITY constexpr
266enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, int>
267countr_zero(_Tp __t) noexcept
268{
269 return __countr_zero(__t);
159template <__libcpp_unsigned_integer _Tp>
160_LIBCPP_HIDE_FROM_ABI constexpr int countr_zero(_Tp __t) noexcept {
161 if (__t == 0)
162 return numeric_limits<_Tp>::digits;
163
164 if (sizeof(_Tp) <= sizeof(unsigned int))
165 return std::__libcpp_ctz(static_cast<unsigned int>(__t));
166 else if (sizeof(_Tp) <= sizeof(unsigned long))
167 return std::__libcpp_ctz(static_cast<unsigned long>(__t));
168 else if (sizeof(_Tp) <= sizeof(unsigned long long))
169 return std::__libcpp_ctz(static_cast<unsigned long long>(__t));
170 else {
171 int __ret = 0;
172 const unsigned int __ulldigits = numeric_limits<unsigned long long>::digits;
173 while (static_cast<unsigned long long>(__t) == 0uLL) {
174 __ret += __ulldigits;
175 __t >>= __ulldigits;
176 }
177 return __ret + std::__libcpp_ctz(static_cast<unsigned long long>(__t));
178 }
270179}
271180
272template<class _Tp>
273_LIBCPP_INLINE_VISIBILITY constexpr
274enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, int>
275countr_one(_Tp __t) noexcept
276{
277 return __countr_one(__t);
181template <__libcpp_unsigned_integer _Tp>
182_LIBCPP_HIDE_FROM_ABI constexpr int countr_one(_Tp __t) noexcept {
183 return __t != numeric_limits<_Tp>::max() ? std::countr_zero(static_cast<_Tp>(~__t)) : numeric_limits<_Tp>::digits;
278184}
279185
280template<class _Tp>
281_LIBCPP_INLINE_VISIBILITY constexpr
282enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, int>
283popcount(_Tp __t) noexcept
284{
285 return __popcount(__t);
186template <__libcpp_unsigned_integer _Tp>
187_LIBCPP_HIDE_FROM_ABI constexpr int popcount(_Tp __t) noexcept {
188 if (sizeof(_Tp) <= sizeof(unsigned int))
189 return std::__libcpp_popcount(static_cast<unsigned int>(__t));
190 else if (sizeof(_Tp) <= sizeof(unsigned long))
191 return std::__libcpp_popcount(static_cast<unsigned long>(__t));
192 else if (sizeof(_Tp) <= sizeof(unsigned long long))
193 return std::__libcpp_popcount(static_cast<unsigned long long>(__t));
194 else {
195 int __ret = 0;
196 while (__t != 0) {
197 __ret += std::__libcpp_popcount(static_cast<unsigned long long>(__t));
198 __t >>= numeric_limits<unsigned long long>::digits;
199 }
200 return __ret;
201 }
286202}
287203
288template <class _Tp>
289_LIBCPP_INLINE_VISIBILITY constexpr
290enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, bool>
291has_single_bit(_Tp __t) noexcept
292{
293 return __has_single_bit(__t);
204template <__libcpp_unsigned_integer _Tp>
205_LIBCPP_HIDE_FROM_ABI constexpr bool has_single_bit(_Tp __t) noexcept {
206 return __t != 0 && (((__t & (__t - 1)) == 0));
294207}
295208
296template <class _Tp>
297_LIBCPP_INLINE_VISIBILITY constexpr
298enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, _Tp>
299bit_floor(_Tp __t) noexcept
300{
301 return __t == 0 ? 0 : _Tp{1} << __bit_log2(__t);
209// integral log base 2
210template <__libcpp_unsigned_integer _Tp>
211_LIBCPP_HIDE_FROM_ABI constexpr _Tp __bit_log2(_Tp __t) noexcept {
212 return numeric_limits<_Tp>::digits - 1 - std::countl_zero(__t);
302213}
303214
304template <class _Tp>
305_LIBCPP_INLINE_VISIBILITY constexpr
306enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, _Tp>
307bit_ceil(_Tp __t) noexcept
308{
309 if (__t < 2) return 1;
310 const unsigned __n = numeric_limits<_Tp>::digits - countl_zero((_Tp)(__t - 1u));
311 _LIBCPP_ASSERT(__n != numeric_limits<_Tp>::digits, "Bad input to bit_ceil");
215template <__libcpp_unsigned_integer _Tp>
216_LIBCPP_HIDE_FROM_ABI constexpr _Tp bit_floor(_Tp __t) noexcept {
217 return __t == 0 ? 0 : _Tp{1} << std::__bit_log2(__t);
218}
312219
313 if constexpr (sizeof(_Tp) >= sizeof(unsigned))
314 return _Tp{1} << __n;
315 else
316 {
317 const unsigned __extra = numeric_limits<unsigned>::digits - numeric_limits<_Tp>::digits;
318 const unsigned __retVal = 1u << (__n + __extra);
319 return (_Tp) (__retVal >> __extra);
320 }
220template <__libcpp_unsigned_integer _Tp>
221_LIBCPP_HIDE_FROM_ABI constexpr _Tp bit_ceil(_Tp __t) noexcept {
222 if (__t < 2)
223 return 1;
224 const unsigned __n = numeric_limits<_Tp>::digits - std::countl_zero((_Tp)(__t - 1u));
225 _LIBCPP_ASSERT(__n != numeric_limits<_Tp>::digits, "Bad input to bit_ceil");
226
227 if constexpr (sizeof(_Tp) >= sizeof(unsigned))
228 return _Tp{1} << __n;
229 else {
230 const unsigned __extra = numeric_limits<unsigned>::digits - numeric_limits<_Tp>::digits;
231 const unsigned __retVal = 1u << (__n + __extra);
232 return (_Tp)(__retVal >> __extra);
233 }
321234}
322235
323template <class _Tp>
324_LIBCPP_INLINE_VISIBILITY constexpr
325enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, _Tp>
326bit_width(_Tp __t) noexcept
327{
328 return __t == 0 ? 0 : __bit_log2(__t) + 1;
236template <__libcpp_unsigned_integer _Tp>
237_LIBCPP_HIDE_FROM_ABI constexpr int bit_width(_Tp __t) noexcept {
238 return __t == 0 ? 0 : std::__bit_log2(__t) + 1;
329239}
330240
331enum class endian
332{
333 little = 0xDEAD,
334 big = 0xFACE,
335#if defined(_LIBCPP_LITTLE_ENDIAN)
336 native = little
337#elif defined(_LIBCPP_BIG_ENDIAN)
338 native = big
339#else
340 native = 0xCAFE
341#endif
241enum class endian {
242 little = 0xDEAD,
243 big = 0xFACE,
244# if defined(_LIBCPP_LITTLE_ENDIAN)
245 native = little
246# elif defined(_LIBCPP_BIG_ENDIAN)
247 native = big
248# else
249 native = 0xCAFE
250# endif
342251};
343252
344253#endif // _LIBCPP_STD_VER > 17
lib/libcxx/include/bitset+17-9
......@@ -112,18 +112,23 @@ template <size_t N> struct hash<std::bitset<N>>;
112112
113113*/
114114
115#include <__algorithm/fill.h>
116#include <__assert> // all public C++ headers provide the assertion handler
115117#include <__bit_reference>
116118#include <__config>
117#include <__functional_base>
119#include <__functional/hash.h>
120#include <__functional/unary_function.h>
118121#include <climits>
119122#include <cstddef>
120#include <iosfwd>
121123#include <stdexcept>
122#include <string>
123124#include <version>
124125
126// standard-mandated includes
127#include <iosfwd>
128#include <string>
129
125130#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
126#pragma GCC system_header
131# pragma GCC system_header
127132#endif
128133
129134_LIBCPP_PUSH_MACROS
......@@ -713,9 +718,12 @@ public:
713718 bitset& flip(size_t __pos);
714719
715720 // element access:
716 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
717 const_reference operator[](size_t __p) const {return base::__make_ref(__p);}
718 _LIBCPP_INLINE_VISIBILITY reference operator[](size_t __p) {return base::__make_ref(__p);}
721#ifdef _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL
722 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool operator[](size_t __p) const {return base::__make_ref(__p);}
723#else
724 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference operator[](size_t __p) const {return base::__make_ref(__p);}
725#endif
726 _LIBCPP_HIDE_FROM_ABI reference operator[](size_t __p) {return base::__make_ref(__p);}
719727 _LIBCPP_INLINE_VISIBILITY
720728 unsigned long to_ulong() const;
721729 _LIBCPP_INLINE_VISIBILITY
......@@ -946,7 +954,7 @@ basic_string<_CharT, _Traits, _Allocator>
946954bitset<_Size>::to_string(_CharT __zero, _CharT __one) const
947955{
948956 basic_string<_CharT, _Traits, _Allocator> __r(_Size, __zero);
949 for (size_t __i = 0; __i < _Size; ++__i)
957 for (size_t __i = 0; __i != _Size; ++__i)
950958 {
951959 if ((*this)[__i])
952960 __r[_Size - 1 - __i] = __one;
......@@ -1082,7 +1090,7 @@ operator^(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT
10821090
10831091template <size_t _Size>
10841092struct _LIBCPP_TEMPLATE_VIS hash<bitset<_Size> >
1085 : public unary_function<bitset<_Size>, size_t>
1093 : public __unary_function<bitset<_Size>, size_t>
10861094{
10871095 _LIBCPP_INLINE_VISIBILITY
10881096 size_t operator()(const bitset<_Size>& __bs) const _NOEXCEPT
lib/libcxx/include/cassert+2-1
......@@ -16,9 +16,10 @@ Macros:
1616
1717*/
1818
19#include <__assert> // all public C++ headers provide the assertion handler
1920#include <__config>
2021#include <assert.h>
2122
2223#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23#pragma GCC system_header
24# pragma GCC system_header
2425#endif
lib/libcxx/include/ccomplex+2-3
......@@ -17,12 +17,11 @@
1717
1818*/
1919
20#include <__assert> // all public C++ headers provide the assertion handler
2021#include <complex>
2122
2223#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23#pragma GCC system_header
24# pragma GCC system_header
2425#endif
2526
26// hh 080623 Created
27
2827#endif // _LIBCPP_CCOMPLEX
lib/libcxx/include/cctype+2-1
......@@ -34,11 +34,12 @@ int toupper(int c);
3434} // std
3535*/
3636
37#include <__assert> // all public C++ headers provide the assertion handler
3738#include <__config>
3839#include <ctype.h>
3940
4041#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
41#pragma GCC system_header
42# pragma GCC system_header
4243#endif
4344
4445_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/cerrno+2-1
......@@ -22,11 +22,12 @@ Macros:
2222
2323*/
2424
25#include <__assert> // all public C++ headers provide the assertion handler
2526#include <__config>
2627#include <errno.h>
2728
2829#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
29#pragma GCC system_header
30# pragma GCC system_header
3031#endif
3132
3233#endif // _LIBCPP_CERRNO
lib/libcxx/include/cfenv+2-1
......@@ -52,11 +52,12 @@ int feupdateenv(const fenv_t* envp);
5252} // std
5353*/
5454
55#include <__assert> // all public C++ headers provide the assertion handler
5556#include <__config>
5657#include <fenv.h>
5758
5859#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
59#pragma GCC system_header
60# pragma GCC system_header
6061#endif
6162
6263_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/cfloat+2-1
......@@ -69,11 +69,12 @@ Macros:
6969 LDBL_TRUE_MIN // C11
7070*/
7171
72#include <__assert> // all public C++ headers provide the assertion handler
7273#include <__config>
7374#include <float.h>
7475
7576#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
76#pragma GCC system_header
77# pragma GCC system_header
7778#endif
7879
7980#endif // _LIBCPP_CFLOAT
lib/libcxx/include/charconv+311-123
......@@ -77,24 +77,32 @@ namespace std {
7777
7878*/
7979
80#include <__assert> // all public C++ headers provide the assertion handler
8081#include <__availability>
8182#include <__bits>
8283#include <__charconv/chars_format.h>
8384#include <__charconv/from_chars_result.h>
85#include <__charconv/tables.h>
86#include <__charconv/to_chars_base_10.h>
8487#include <__charconv/to_chars_result.h>
8588#include <__config>
89#include <__debug>
8690#include <__errc>
91#include <__type_traits/make_32_64_or_128_bit.h>
92#include <__utility/unreachable.h>
8793#include <cmath> // for log2f
8894#include <cstdint>
89#include <cstdlib> // for _LIBCPP_UNREACHABLE
95#include <cstdlib>
9096#include <cstring>
9197#include <limits>
9298#include <type_traits>
9399
94#include <__debug>
100#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
101# include <iosfwd>
102#endif
95103
96104#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
97#pragma GCC system_header
105# pragma GCC system_header
98106#endif
99107
100108_LIBCPP_PUSH_MACROS
......@@ -102,11 +110,6 @@ _LIBCPP_PUSH_MACROS
102110
103111_LIBCPP_BEGIN_NAMESPACE_STD
104112
105namespace __itoa {
106_LIBCPP_AVAILABILITY_TO_CHARS _LIBCPP_FUNC_VIS char* __u64toa(uint64_t __value, char* __buffer) _NOEXCEPT;
107_LIBCPP_AVAILABILITY_TO_CHARS _LIBCPP_FUNC_VIS char* __u32toa(uint32_t __value, char* __buffer) _NOEXCEPT;
108} // namespace __itoa
109
110113#ifndef _LIBCPP_CXX03_LANG
111114
112115to_chars_result to_chars(char*, char*, bool, int = 10) = delete;
......@@ -115,79 +118,93 @@ from_chars_result from_chars(const char*, const char*, bool, int = 10) = delete;
115118namespace __itoa
116119{
117120
118static _LIBCPP_CONSTEXPR uint64_t __pow10_64[] = {
119 UINT64_C(0),
120 UINT64_C(10),
121 UINT64_C(100),
122 UINT64_C(1000),
123 UINT64_C(10000),
124 UINT64_C(100000),
125 UINT64_C(1000000),
126 UINT64_C(10000000),
127 UINT64_C(100000000),
128 UINT64_C(1000000000),
129 UINT64_C(10000000000),
130 UINT64_C(100000000000),
131 UINT64_C(1000000000000),
132 UINT64_C(10000000000000),
133 UINT64_C(100000000000000),
134 UINT64_C(1000000000000000),
135 UINT64_C(10000000000000000),
136 UINT64_C(100000000000000000),
137 UINT64_C(1000000000000000000),
138 UINT64_C(10000000000000000000),
139};
140
141static _LIBCPP_CONSTEXPR uint32_t __pow10_32[] = {
142 UINT32_C(0), UINT32_C(10), UINT32_C(100),
143 UINT32_C(1000), UINT32_C(10000), UINT32_C(100000),
144 UINT32_C(1000000), UINT32_C(10000000), UINT32_C(100000000),
145 UINT32_C(1000000000),
146};
147
148121template <typename _Tp, typename = void>
149struct _LIBCPP_HIDDEN __traits_base
122struct _LIBCPP_HIDDEN __traits_base;
123
124template <typename _Tp>
125struct _LIBCPP_HIDDEN __traits_base<_Tp, __enable_if_t<sizeof(_Tp) <= sizeof(uint32_t)>>
150126{
151 using type = uint64_t;
127 using type = uint32_t;
152128
153 static _LIBCPP_INLINE_VISIBILITY int __width(_Tp __v)
129 /// The width estimation using a log10 algorithm.
130 ///
131 /// The algorithm is based on
132 /// http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog10
133 /// Instead of using IntegerLogBase2 it uses __libcpp_clz. Since that
134 /// function requires its input to have at least one bit set the value of
135 /// zero is set to one. This means the first element of the lookup table is
136 /// zero.
137 static _LIBCPP_HIDE_FROM_ABI int __width(_Tp __v)
154138 {
155 auto __t = (64 - _VSTD::__libcpp_clz(static_cast<type>(__v | 1))) * 1233 >> 12;
156 return __t - (__v < __pow10_64[__t]) + 1;
139 auto __t = (32 - std::__libcpp_clz(static_cast<type>(__v | 1))) * 1233 >> 12;
140 return __t - (__v < __table<>::__pow10_32[__t]) + 1;
157141 }
158142
159 _LIBCPP_AVAILABILITY_TO_CHARS
160 static _LIBCPP_INLINE_VISIBILITY char* __convert(_Tp __v, char* __p)
143 static _LIBCPP_HIDE_FROM_ABI char* __convert(char* __p, _Tp __v)
161144 {
162 return __u64toa(__v, __p);
145 return __itoa::__base_10_u32(__p, __v);
163146 }
164147
165 static _LIBCPP_INLINE_VISIBILITY decltype(__pow10_64)& __pow() { return __pow10_64; }
148 static _LIBCPP_HIDE_FROM_ABI decltype(__table<>::__pow10_32)& __pow() { return __table<>::__pow10_32; }
166149};
167150
168151template <typename _Tp>
169152struct _LIBCPP_HIDDEN
170 __traits_base<_Tp, decltype(void(uint32_t{declval<_Tp>()}))>
171{
172 using type = uint32_t;
153 __traits_base<_Tp, __enable_if_t<sizeof(_Tp) == sizeof(uint64_t)>> {
154 using type = uint64_t;
155
156 /// The width estimation using a log10 algorithm.
157 ///
158 /// The algorithm is based on
159 /// http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog10
160 /// Instead of using IntegerLogBase2 it uses __libcpp_clz. Since that
161 /// function requires its input to have at least one bit set the value of
162 /// zero is set to one. This means the first element of the lookup table is
163 /// zero.
164 static _LIBCPP_HIDE_FROM_ABI int __width(_Tp __v) {
165 auto __t = (64 - std::__libcpp_clz(static_cast<type>(__v | 1))) * 1233 >> 12;
166 return __t - (__v < __table<>::__pow10_64[__t]) + 1;
167 }
173168
174 static _LIBCPP_INLINE_VISIBILITY int __width(_Tp __v)
175 {
176 auto __t = (32 - _VSTD::__libcpp_clz(static_cast<type>(__v | 1))) * 1233 >> 12;
177 return __t - (__v < __pow10_32[__t]) + 1;
178 }
169 static _LIBCPP_HIDE_FROM_ABI char* __convert(char* __p, _Tp __v) { return __itoa::__base_10_u64(__p, __v); }
179170
180 _LIBCPP_AVAILABILITY_TO_CHARS
181 static _LIBCPP_INLINE_VISIBILITY char* __convert(_Tp __v, char* __p)
182 {
183 return __u32toa(__v, __p);
184 }
171 static _LIBCPP_HIDE_FROM_ABI decltype(__table<>::__pow10_64)& __pow() { return __table<>::__pow10_64; }
172};
173
174
175# ifndef _LIBCPP_HAS_NO_INT128
176template <typename _Tp>
177struct _LIBCPP_HIDDEN
178 __traits_base<_Tp, __enable_if_t<sizeof(_Tp) == sizeof(__uint128_t)> > {
179 using type = __uint128_t;
180
181 /// The width estimation using a log10 algorithm.
182 ///
183 /// The algorithm is based on
184 /// http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog10
185 /// Instead of using IntegerLogBase2 it uses __libcpp_clz. Since that
186 /// function requires its input to have at least one bit set the value of
187 /// zero is set to one. This means the first element of the lookup table is
188 /// zero.
189 static _LIBCPP_HIDE_FROM_ABI int __width(_Tp __v) {
190 _LIBCPP_ASSERT(__v > numeric_limits<uint64_t>::max(), "The optimizations for this algorithm fail when this isn't true.");
191 // There's always a bit set in the upper 64-bits.
192 auto __t = (128 - std::__libcpp_clz(static_cast<uint64_t>(__v >> 64))) * 1233 >> 12;
193 _LIBCPP_ASSERT(__t >= __table<>::__pow10_128_offset, "Index out of bounds");
194 // __t is adjusted since the lookup table misses the lower entries.
195 return __t - (__v < __table<>::__pow10_128[__t - __table<>::__pow10_128_offset]) + 1;
196 }
197
198 static _LIBCPP_HIDE_FROM_ABI char* __convert(char* __p, _Tp __v) { return __itoa::__base_10_u128(__p, __v); }
185199
186 static _LIBCPP_INLINE_VISIBILITY decltype(__pow10_32)& __pow() { return __pow10_32; }
200 // TODO FMT This pow function should get an index.
201 // By moving this to its own header it can be reused by the pow function in to_chars_base_10.
202 static _LIBCPP_HIDE_FROM_ABI decltype(__table<>::__pow10_128)& __pow() { return __table<>::__pow10_128; }
187203};
204#endif
188205
189206template <typename _Tp>
190inline _LIBCPP_INLINE_VISIBILITY bool
207inline _LIBCPP_HIDE_FROM_ABI bool
191208__mul_overflowed(unsigned char __a, _Tp __b, unsigned char& __r)
192209{
193210 auto __c = __a * __b;
......@@ -196,7 +213,7 @@ __mul_overflowed(unsigned char __a, _Tp __b, unsigned char& __r)
196213}
197214
198215template <typename _Tp>
199inline _LIBCPP_INLINE_VISIBILITY bool
216inline _LIBCPP_HIDE_FROM_ABI bool
200217__mul_overflowed(unsigned short __a, _Tp __b, unsigned short& __r)
201218{
202219 auto __c = __a * __b;
......@@ -205,7 +222,7 @@ __mul_overflowed(unsigned short __a, _Tp __b, unsigned short& __r)
205222}
206223
207224template <typename _Tp>
208inline _LIBCPP_INLINE_VISIBILITY bool
225inline _LIBCPP_HIDE_FROM_ABI bool
209226__mul_overflowed(_Tp __a, _Tp __b, _Tp& __r)
210227{
211228 static_assert(is_unsigned<_Tp>::value, "");
......@@ -219,7 +236,7 @@ __mul_overflowed(_Tp __a, _Tp __b, _Tp& __r)
219236}
220237
221238template <typename _Tp, typename _Up>
222inline _LIBCPP_INLINE_VISIBILITY bool
239inline _LIBCPP_HIDE_FROM_ABI bool
223240__mul_overflowed(_Tp __a, _Up __b, _Tp& __r)
224241{
225242 return __mul_overflowed(__a, static_cast<_Tp>(__b), __r);
......@@ -228,12 +245,12 @@ __mul_overflowed(_Tp __a, _Up __b, _Tp& __r)
228245template <typename _Tp>
229246struct _LIBCPP_HIDDEN __traits : __traits_base<_Tp>
230247{
231 static _LIBCPP_CONSTEXPR int digits = numeric_limits<_Tp>::digits10 + 1;
248 static constexpr int digits = numeric_limits<_Tp>::digits10 + 1;
232249 using __traits_base<_Tp>::__pow;
233250 using typename __traits_base<_Tp>::type;
234251
235252 // precondition: at least one non-zero character available
236 static _LIBCPP_INLINE_VISIBILITY char const*
253 static _LIBCPP_HIDE_FROM_ABI char const*
237254 __read(char const* __p, char const* __ep, type& __a, type& __b)
238255 {
239256 type __cprod[digits];
......@@ -254,7 +271,7 @@ struct _LIBCPP_HIDDEN __traits : __traits_base<_Tp>
254271 }
255272
256273 template <typename _It1, typename _It2, class _Up>
257 static _LIBCPP_INLINE_VISIBILITY _Up
274 static _LIBCPP_HIDE_FROM_ABI _Up
258275 __inner_product(_It1 __first1, _It1 __last1, _It2 __first2, _Up __init)
259276 {
260277 for (; __first1 < __last1; ++__first1, ++__first2)
......@@ -266,7 +283,7 @@ struct _LIBCPP_HIDDEN __traits : __traits_base<_Tp>
266283} // namespace __itoa
267284
268285template <typename _Tp>
269inline _LIBCPP_INLINE_VISIBILITY _Tp
286inline _LIBCPP_HIDE_FROM_ABI _Tp
270287__complement(_Tp __x)
271288{
272289 static_assert(is_unsigned<_Tp>::value, "cast to unsigned first");
......@@ -274,8 +291,7 @@ __complement(_Tp __x)
274291}
275292
276293template <typename _Tp>
277_LIBCPP_AVAILABILITY_TO_CHARS
278inline _LIBCPP_INLINE_VISIBILITY to_chars_result
294inline _LIBCPP_HIDE_FROM_ABI to_chars_result
279295__to_chars_itoa(char* __first, char* __last, _Tp __value, true_type)
280296{
281297 auto __x = __to_unsigned_like(__value);
......@@ -289,22 +305,42 @@ __to_chars_itoa(char* __first, char* __last, _Tp __value, true_type)
289305}
290306
291307template <typename _Tp>
292_LIBCPP_AVAILABILITY_TO_CHARS
293inline _LIBCPP_INLINE_VISIBILITY to_chars_result
308inline _LIBCPP_HIDE_FROM_ABI to_chars_result
294309__to_chars_itoa(char* __first, char* __last, _Tp __value, false_type)
295310{
296311 using __tx = __itoa::__traits<_Tp>;
297312 auto __diff = __last - __first;
298313
299314 if (__tx::digits <= __diff || __tx::__width(__value) <= __diff)
300 return {__tx::__convert(__value, __first), errc(0)};
315 return {__tx::__convert(__first, __value), errc(0)};
316 else
317 return {__last, errc::value_too_large};
318}
319
320# ifndef _LIBCPP_HAS_NO_INT128
321template <>
322inline _LIBCPP_HIDE_FROM_ABI to_chars_result
323__to_chars_itoa(char* __first, char* __last, __uint128_t __value, false_type)
324{
325 // When the value fits in 64-bits use the 64-bit code path. This reduces
326 // the number of expensive calculations on 128-bit values.
327 //
328 // NOTE the 128-bit code path requires this optimization.
329 if(__value <= numeric_limits<uint64_t>::max())
330 return __to_chars_itoa(__first, __last, static_cast<uint64_t>(__value), false_type());
331
332 using __tx = __itoa::__traits<__uint128_t>;
333 auto __diff = __last - __first;
334
335 if (__tx::digits <= __diff || __tx::__width(__value) <= __diff)
336 return {__tx::__convert(__first, __value), errc(0)};
301337 else
302338 return {__last, errc::value_too_large};
303339}
340#endif
304341
305342template <typename _Tp>
306_LIBCPP_AVAILABILITY_TO_CHARS
307inline _LIBCPP_INLINE_VISIBILITY to_chars_result
343inline _LIBCPP_HIDE_FROM_ABI to_chars_result
308344__to_chars_integral(char* __first, char* __last, _Tp __value, int __base,
309345 true_type)
310346{
......@@ -318,8 +354,151 @@ __to_chars_integral(char* __first, char* __last, _Tp __value, int __base,
318354 return __to_chars_integral(__first, __last, __x, __base, false_type());
319355}
320356
357namespace __itoa {
358
359template <unsigned _Base>
360struct _LIBCPP_HIDDEN __integral;
361
362template <>
363struct _LIBCPP_HIDDEN __integral<2> {
364 template <typename _Tp>
365 _LIBCPP_HIDE_FROM_ABI static constexpr int __width(_Tp __value) noexcept {
366 // If value == 0 still need one digit. If the value != this has no
367 // effect since the code scans for the most significant bit set. (Note
368 // that __libcpp_clz doesn't work for 0.)
369 return numeric_limits<_Tp>::digits - std::__libcpp_clz(__value | 1);
370 }
371
372 template <typename _Tp>
373 _LIBCPP_HIDE_FROM_ABI static to_chars_result __to_chars(char* __first, char* __last, _Tp __value) {
374 ptrdiff_t __cap = __last - __first;
375 int __n = __width(__value);
376 if (__n > __cap)
377 return {__last, errc::value_too_large};
378
379 __last = __first + __n;
380 char* __p = __last;
381 const unsigned __divisor = 16;
382 while (__value > __divisor) {
383 unsigned __c = __value % __divisor;
384 __value /= __divisor;
385 __p -= 4;
386 std::memcpy(__p, &__table<>::__base_2_lut[4 * __c], 4);
387 }
388 do {
389 unsigned __c = __value % 2;
390 __value /= 2;
391 *--__p = "01"[__c];
392 } while (__value != 0);
393 return {__last, errc(0)};
394 }
395};
396
397template <>
398struct _LIBCPP_HIDDEN __integral<8> {
399 template <typename _Tp>
400 _LIBCPP_HIDE_FROM_ABI static constexpr int __width(_Tp __value) noexcept {
401 // If value == 0 still need one digit. If the value != this has no
402 // effect since the code scans for the most significat bit set. (Note
403 // that __libcpp_clz doesn't work for 0.)
404 return ((numeric_limits<_Tp>::digits - std::__libcpp_clz(__value | 1)) + 2) / 3;
405 }
406
407 template <typename _Tp>
408 _LIBCPP_HIDE_FROM_ABI static to_chars_result __to_chars(char* __first, char* __last, _Tp __value) {
409 ptrdiff_t __cap = __last - __first;
410 int __n = __width(__value);
411 if (__n > __cap)
412 return {__last, errc::value_too_large};
413
414 __last = __first + __n;
415 char* __p = __last;
416 unsigned __divisor = 64;
417 while (__value > __divisor) {
418 unsigned __c = __value % __divisor;
419 __value /= __divisor;
420 __p -= 2;
421 std::memcpy(__p, &__table<>::__base_8_lut[2 * __c], 2);
422 }
423 do {
424 unsigned __c = __value % 8;
425 __value /= 8;
426 *--__p = "01234567"[__c];
427 } while (__value != 0);
428 return {__last, errc(0)};
429 }
430
431};
432
433template <>
434struct _LIBCPP_HIDDEN __integral<16> {
435 template <typename _Tp>
436 _LIBCPP_HIDE_FROM_ABI static constexpr int __width(_Tp __value) noexcept {
437 // If value == 0 still need one digit. If the value != this has no
438 // effect since the code scans for the most significat bit set. (Note
439 // that __libcpp_clz doesn't work for 0.)
440 return (numeric_limits<_Tp>::digits - std::__libcpp_clz(__value | 1) + 3) / 4;
441 }
442
443 template <typename _Tp>
444 _LIBCPP_HIDE_FROM_ABI static to_chars_result __to_chars(char* __first, char* __last, _Tp __value) {
445 ptrdiff_t __cap = __last - __first;
446 int __n = __width(__value);
447 if (__n > __cap)
448 return {__last, errc::value_too_large};
449
450 __last = __first + __n;
451 char* __p = __last;
452 unsigned __divisor = 256;
453 while (__value > __divisor) {
454 unsigned __c = __value % __divisor;
455 __value /= __divisor;
456 __p -= 2;
457 std::memcpy(__p, &__table<>::__base_16_lut[2 * __c], 2);
458 }
459 if (__first != __last)
460 do {
461 unsigned __c = __value % 16;
462 __value /= 16;
463 *--__p = "0123456789abcdef"[__c];
464 } while (__value != 0);
465 return {__last, errc(0)};
466 }
467};
468
469} // namespace __itoa
470
471template <unsigned _Base, typename _Tp,
472 typename enable_if<(sizeof(_Tp) >= sizeof(unsigned)), int>::type = 0>
473_LIBCPP_HIDE_FROM_ABI int
474__to_chars_integral_width(_Tp __value) {
475 return __itoa::__integral<_Base>::__width(__value);
476}
477
478template <unsigned _Base, typename _Tp,
479 typename enable_if<(sizeof(_Tp) < sizeof(unsigned)), int>::type = 0>
480_LIBCPP_HIDE_FROM_ABI int
481__to_chars_integral_width(_Tp __value) {
482 return std::__to_chars_integral_width<_Base>(static_cast<unsigned>(__value));
483}
484
485template <unsigned _Base, typename _Tp,
486 typename enable_if<(sizeof(_Tp) >= sizeof(unsigned)), int>::type = 0>
487_LIBCPP_HIDE_FROM_ABI to_chars_result
488__to_chars_integral(char* __first, char* __last, _Tp __value) {
489 return __itoa::__integral<_Base>::__to_chars(__first, __last, __value);
490}
491
492template <unsigned _Base, typename _Tp,
493 typename enable_if<(sizeof(_Tp) < sizeof(unsigned)), int>::type = 0>
494_LIBCPP_HIDE_FROM_ABI to_chars_result
495__to_chars_integral(char* __first, char* __last, _Tp __value) {
496 return std::__to_chars_integral<_Base>(__first, __last, static_cast<unsigned>(__value));
497}
498
321499template <typename _Tp>
322_LIBCPP_AVAILABILITY_TO_CHARS _LIBCPP_INLINE_VISIBILITY int __to_chars_integral_width(_Tp __value, unsigned __base) {
500_LIBCPP_HIDE_FROM_ABI int
501__to_chars_integral_width(_Tp __value, unsigned __base) {
323502 _LIBCPP_ASSERT(__value >= 0, "The function requires a non-negative value.");
324503
325504 unsigned __base_2 = __base * __base;
......@@ -341,18 +520,26 @@ _LIBCPP_AVAILABILITY_TO_CHARS _LIBCPP_INLINE_VISIBILITY int __to_chars_integral_
341520 __r += 4;
342521 }
343522
344 _LIBCPP_UNREACHABLE();
523 __libcpp_unreachable();
345524}
346525
347526template <typename _Tp>
348_LIBCPP_AVAILABILITY_TO_CHARS
349inline _LIBCPP_INLINE_VISIBILITY to_chars_result
527inline _LIBCPP_HIDE_FROM_ABI to_chars_result
350528__to_chars_integral(char* __first, char* __last, _Tp __value, int __base,
351529 false_type)
352530{
353 if (__base == 10)
531 if (__base == 10) [[likely]]
354532 return __to_chars_itoa(__first, __last, __value, false_type());
355533
534 switch (__base) {
535 case 2:
536 return __to_chars_integral<2>(__first, __last, __value);
537 case 8:
538 return __to_chars_integral<8>(__first, __last, __value);
539 case 16:
540 return __to_chars_integral<16>(__first, __last, __value);
541 }
542
356543 ptrdiff_t __cap = __last - __first;
357544 int __n = __to_chars_integral_width(__value, __base);
358545 if (__n > __cap)
......@@ -369,25 +556,26 @@ __to_chars_integral(char* __first, char* __last, _Tp __value, int __base,
369556}
370557
371558template <typename _Tp, typename enable_if<is_integral<_Tp>::value, int>::type = 0>
372_LIBCPP_AVAILABILITY_TO_CHARS
373inline _LIBCPP_INLINE_VISIBILITY to_chars_result
559inline _LIBCPP_HIDE_FROM_ABI to_chars_result
374560to_chars(char* __first, char* __last, _Tp __value)
375561{
376 return __to_chars_itoa(__first, __last, __value, is_signed<_Tp>());
562 using _Type = __make_32_64_or_128_bit_t<_Tp>;
563 static_assert(!is_same<_Type, void>::value, "unsupported integral type used in to_chars");
564 return std::__to_chars_itoa(__first, __last, static_cast<_Type>(__value), is_signed<_Tp>());
377565}
378566
379567template <typename _Tp, typename enable_if<is_integral<_Tp>::value, int>::type = 0>
380_LIBCPP_AVAILABILITY_TO_CHARS
381inline _LIBCPP_INLINE_VISIBILITY to_chars_result
568inline _LIBCPP_HIDE_FROM_ABI to_chars_result
382569to_chars(char* __first, char* __last, _Tp __value, int __base)
383570{
384 _LIBCPP_ASSERT(2 <= __base && __base <= 36, "base not in [2, 36]");
385 return __to_chars_integral(__first, __last, __value, __base,
386 is_signed<_Tp>());
571 _LIBCPP_ASSERT(2 <= __base && __base <= 36, "base not in [2, 36]");
572
573 using _Type = __make_32_64_or_128_bit_t<_Tp>;
574 return std::__to_chars_integral(__first, __last, static_cast<_Type>(__value), __base, is_signed<_Tp>());
387575}
388576
389577template <typename _It, typename _Tp, typename _Fn, typename... _Ts>
390inline _LIBCPP_INLINE_VISIBILITY from_chars_result
578inline _LIBCPP_HIDE_FROM_ABI from_chars_result
391579__sign_combinator(_It __first, _It __last, _Tp& __value, _Fn __f, _Ts... __args)
392580{
393581 using __tl = numeric_limits<_Tp>;
......@@ -410,13 +598,13 @@ __sign_combinator(_It __first, _It __last, _Tp& __value, _Fn __f, _Ts... __args)
410598 if (__x <= __complement(__to_unsigned_like(__tl::min())))
411599 {
412600 __x = __complement(__x);
413 _VSTD::memcpy(&__value, &__x, sizeof(__x));
601 std::memcpy(&__value, &__x, sizeof(__x));
414602 return __r;
415603 }
416604 }
417605 else
418606 {
419 if (__x <= __tl::max())
607 if (__x <= __to_unsigned_like(__tl::max()))
420608 {
421609 __value = __x;
422610 return __r;
......@@ -427,7 +615,7 @@ __sign_combinator(_It __first, _It __last, _Tp& __value, _Fn __f, _Ts... __args)
427615}
428616
429617template <typename _Tp>
430inline _LIBCPP_INLINE_VISIBILITY bool
618inline _LIBCPP_HIDE_FROM_ABI bool
431619__in_pattern(_Tp __c)
432620{
433621 return '0' <= __c && __c <= '9';
......@@ -438,11 +626,11 @@ struct _LIBCPP_HIDDEN __in_pattern_result
438626 bool __ok;
439627 int __val;
440628
441 explicit _LIBCPP_INLINE_VISIBILITY operator bool() const { return __ok; }
629 explicit _LIBCPP_HIDE_FROM_ABI operator bool() const { return __ok; }
442630};
443631
444632template <typename _Tp>
445inline _LIBCPP_INLINE_VISIBILITY __in_pattern_result
633inline _LIBCPP_HIDE_FROM_ABI __in_pattern_result
446634__in_pattern(_Tp __c, int __base)
447635{
448636 if (__base <= 10)
......@@ -456,15 +644,15 @@ __in_pattern(_Tp __c, int __base)
456644}
457645
458646template <typename _It, typename _Tp, typename _Fn, typename... _Ts>
459inline _LIBCPP_INLINE_VISIBILITY from_chars_result
647inline _LIBCPP_HIDE_FROM_ABI from_chars_result
460648__subject_seq_combinator(_It __first, _It __last, _Tp& __value, _Fn __f,
461649 _Ts... __args)
462650{
463 auto __find_non_zero = [](_It __first, _It __last) {
464 for (; __first != __last; ++__first)
465 if (*__first != '0')
651 auto __find_non_zero = [](_It __firstit, _It __lastit) {
652 for (; __firstit != __lastit; ++__firstit)
653 if (*__firstit != '0')
466654 break;
467 return __first;
655 return __firstit;
468656 };
469657
470658 auto __p = __find_non_zero(__first, __last);
......@@ -493,7 +681,7 @@ __subject_seq_combinator(_It __first, _It __last, _Tp& __value, _Fn __f,
493681}
494682
495683template <typename _Tp, typename enable_if<is_unsigned<_Tp>::value, int>::type = 0>
496inline _LIBCPP_INLINE_VISIBILITY from_chars_result
684inline _LIBCPP_HIDE_FROM_ABI from_chars_result
497685__from_chars_atoi(const char* __first, const char* __last, _Tp& __value)
498686{
499687 using __tx = __itoa::__traits<_Tp>;
......@@ -501,16 +689,16 @@ __from_chars_atoi(const char* __first, const char* __last, _Tp& __value)
501689
502690 return __subject_seq_combinator(
503691 __first, __last, __value,
504 [](const char* __first, const char* __last,
505 _Tp& __value) -> from_chars_result {
692 [](const char* __f, const char* __l,
693 _Tp& __val) -> from_chars_result {
506694 __output_type __a, __b;
507 auto __p = __tx::__read(__first, __last, __a, __b);
508 if (__p == __last || !__in_pattern(*__p))
695 auto __p = __tx::__read(__f, __l, __a, __b);
696 if (__p == __l || !__in_pattern(*__p))
509697 {
510698 __output_type __m = numeric_limits<_Tp>::max();
511699 if (__m >= __a && __m - __a >= __b)
512700 {
513 __value = __a + __b;
701 __val = __a + __b;
514702 return {__p, {}};
515703 }
516704 }
......@@ -519,7 +707,7 @@ __from_chars_atoi(const char* __first, const char* __last, _Tp& __value)
519707}
520708
521709template <typename _Tp, typename enable_if<is_signed<_Tp>::value, int>::type = 0>
522inline _LIBCPP_INLINE_VISIBILITY from_chars_result
710inline _LIBCPP_HIDE_FROM_ABI from_chars_result
523711__from_chars_atoi(const char* __first, const char* __last, _Tp& __value)
524712{
525713 using __t = decltype(__to_unsigned_like(__value));
......@@ -527,7 +715,7 @@ __from_chars_atoi(const char* __first, const char* __last, _Tp& __value)
527715}
528716
529717template <typename _Tp, typename enable_if<is_unsigned<_Tp>::value, int>::type = 0>
530inline _LIBCPP_INLINE_VISIBILITY from_chars_result
718inline _LIBCPP_HIDE_FROM_ABI from_chars_result
531719__from_chars_integral(const char* __first, const char* __last, _Tp& __value,
532720 int __base)
533721{
......@@ -536,23 +724,23 @@ __from_chars_integral(const char* __first, const char* __last, _Tp& __value,
536724
537725 return __subject_seq_combinator(
538726 __first, __last, __value,
539 [](const char* __p, const char* __lastx, _Tp& __value,
540 int __base) -> from_chars_result {
727 [](const char* __p, const char* __lastp, _Tp& __val,
728 int __b) -> from_chars_result {
541729 using __tl = numeric_limits<_Tp>;
542 auto __digits = __tl::digits / log2f(float(__base));
543 _Tp __a = __in_pattern(*__p++, __base).__val, __b = 0;
730 auto __digits = __tl::digits / log2f(float(__b));
731 _Tp __x = __in_pattern(*__p++, __b).__val, __y = 0;
544732
545 for (int __i = 1; __p != __lastx; ++__i, ++__p)
733 for (int __i = 1; __p != __lastp; ++__i, ++__p)
546734 {
547 if (auto __c = __in_pattern(*__p, __base))
735 if (auto __c = __in_pattern(*__p, __b))
548736 {
549737 if (__i < __digits - 1)
550 __a = __a * __base + __c.__val;
738 __x = __x * __b + __c.__val;
551739 else
552740 {
553 if (!__itoa::__mul_overflowed(__a, __base, __a))
741 if (!__itoa::__mul_overflowed(__x, __b, __x))
554742 ++__p;
555 __b = __c.__val;
743 __y = __c.__val;
556744 break;
557745 }
558746 }
......@@ -560,11 +748,11 @@ __from_chars_integral(const char* __first, const char* __last, _Tp& __value,
560748 break;
561749 }
562750
563 if (__p == __lastx || !__in_pattern(*__p, __base))
751 if (__p == __lastp || !__in_pattern(*__p, __b))
564752 {
565 if (__tl::max() - __a >= __b)
753 if (__tl::max() - __x >= __y)
566754 {
567 __value = __a + __b;
755 __val = __x + __y;
568756 return {__p, {}};
569757 }
570758 }
......@@ -574,7 +762,7 @@ __from_chars_integral(const char* __first, const char* __last, _Tp& __value,
574762}
575763
576764template <typename _Tp, typename enable_if<is_signed<_Tp>::value, int>::type = 0>
577inline _LIBCPP_INLINE_VISIBILITY from_chars_result
765inline _LIBCPP_HIDE_FROM_ABI from_chars_result
578766__from_chars_integral(const char* __first, const char* __last, _Tp& __value,
579767 int __base)
580768{
......@@ -584,14 +772,14 @@ __from_chars_integral(const char* __first, const char* __last, _Tp& __value,
584772}
585773
586774template <typename _Tp, typename enable_if<is_integral<_Tp>::value, int>::type = 0>
587inline _LIBCPP_INLINE_VISIBILITY from_chars_result
775inline _LIBCPP_HIDE_FROM_ABI from_chars_result
588776from_chars(const char* __first, const char* __last, _Tp& __value)
589777{
590778 return __from_chars_atoi(__first, __last, __value);
591779}
592780
593781template <typename _Tp, typename enable_if<is_integral<_Tp>::value, int>::type = 0>
594inline _LIBCPP_INLINE_VISIBILITY from_chars_result
782inline _LIBCPP_HIDE_FROM_ABI from_chars_result
595783from_chars(const char* __first, const char* __last, _Tp& __value, int __base)
596784{
597785 _LIBCPP_ASSERT(2 <= __base && __base <= 36, "base not in [2, 36]");
lib/libcxx/include/chrono+19-7
......@@ -13,6 +13,8 @@
1313/*
1414 chrono synopsis
1515
16#include <compare> // C++20
17
1618namespace std
1719{
1820namespace chrono
......@@ -325,11 +327,7 @@ struct last_spec;
325327
326328class day;
327329constexpr bool operator==(const day& x, const day& y) noexcept;
328constexpr bool operator!=(const day& x, const day& y) noexcept;
329constexpr bool operator< (const day& x, const day& y) noexcept;
330constexpr bool operator> (const day& x, const day& y) noexcept;
331constexpr bool operator<=(const day& x, const day& y) noexcept;
332constexpr bool operator>=(const day& x, const day& y) noexcept;
330constexpr strong_ordering operator<=>(const day& x, const day& y) noexcept;
333331constexpr day operator+(const day& x, const days& y) noexcept;
334332constexpr day operator+(const days& x, const day& y) noexcept;
335333constexpr day operator-(const day& x, const days& y) noexcept;
......@@ -694,20 +692,34 @@ constexpr chrono::year operator ""y(unsigned lo
694692} // std
695693*/
696694
695#include <__assert> // all public C++ headers provide the assertion handler
697696#include <__chrono/calendar.h>
698697#include <__chrono/convert_to_timespec.h>
698#include <__chrono/day.h>
699699#include <__chrono/duration.h>
700700#include <__chrono/file_clock.h>
701#include <__chrono/hh_mm_ss.h>
701702#include <__chrono/high_resolution_clock.h>
703#include <__chrono/literals.h>
704#include <__chrono/month.h>
705#include <__chrono/month_weekday.h>
706#include <__chrono/monthday.h>
702707#include <__chrono/steady_clock.h>
703708#include <__chrono/system_clock.h>
704709#include <__chrono/time_point.h>
710#include <__chrono/weekday.h>
711#include <__chrono/year.h>
712#include <__chrono/year_month.h>
713#include <__chrono/year_month_day.h>
714#include <__chrono/year_month_weekday.h>
705715#include <__config>
706#include <compare>
707716#include <version>
708717
718// standard-mandated includes
719#include <compare>
720
709721#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
710#pragma GCC system_header
722# pragma GCC system_header
711723#endif
712724
713725#endif // _LIBCPP_CHRONO
lib/libcxx/include/cinttypes+2-1
......@@ -234,12 +234,13 @@ uintmax_t wcstoumax(const wchar_t* restrict nptr, wchar_t** restrict endptr, int
234234} // std
235235*/
236236
237#include <__assert> // all public C++ headers provide the assertion handler
237238#include <__config>
238239#include <cstdint>
239240#include <inttypes.h>
240241
241242#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
242#pragma GCC system_header
243# pragma GCC system_header
243244#endif
244245
245246_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/ciso646+2-1
......@@ -15,10 +15,11 @@
1515
1616*/
1717
18#include <__assert> // all public C++ headers provide the assertion handler
1819#include <__config>
1920
2021#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21#pragma GCC system_header
22# pragma GCC system_header
2223#endif
2324
2425#endif // _LIBCPP_CISO646
lib/libcxx/include/climits+2-1
......@@ -37,11 +37,12 @@ Macros:
3737
3838*/
3939
40#include <__assert> // all public C++ headers provide the assertion handler
4041#include <__config>
4142#include <limits.h>
4243
4344#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
44#pragma GCC system_header
45# pragma GCC system_header
4546#endif
4647
4748#endif // _LIBCPP_CLIMITS
lib/libcxx/include/clocale+2-1
......@@ -34,11 +34,12 @@ lconv* localeconv();
3434
3535*/
3636
37#include <__assert> // all public C++ headers provide the assertion handler
3738#include <__config>
3839#include <locale.h>
3940
4041#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
41#pragma GCC system_header
42# pragma GCC system_header
4243#endif
4344
4445_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/cmath+5-4
......@@ -304,13 +304,14 @@ constexpr long double lerp(long double a, long double b, long double t) noexcept
304304
305305*/
306306
307#include <__assert> // all public C++ headers provide the assertion handler
307308#include <__config>
308309#include <math.h>
309310#include <type_traits>
310311#include <version>
311312
312313#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
313#pragma GCC system_header
314# pragma GCC system_header
314315#endif
315316
316317_LIBCPP_PUSH_MACROS
......@@ -529,9 +530,9 @@ using ::tgammal _LIBCPP_USING_IF_EXISTS;
529530using ::truncl _LIBCPP_USING_IF_EXISTS;
530531
531532#if _LIBCPP_STD_VER > 14
532inline _LIBCPP_INLINE_VISIBILITY float hypot( float x, float y, float z ) { return sqrt(x*x + y*y + z*z); }
533inline _LIBCPP_INLINE_VISIBILITY double hypot( double x, double y, double z ) { return sqrt(x*x + y*y + z*z); }
534inline _LIBCPP_INLINE_VISIBILITY long double hypot( long double x, long double y, long double z ) { return sqrt(x*x + y*y + z*z); }
533inline _LIBCPP_INLINE_VISIBILITY float hypot( float __x, float __y, float __z ) { return sqrt(__x*__x + __y*__y + __z*__z); }
534inline _LIBCPP_INLINE_VISIBILITY double hypot( double __x, double __y, double __z ) { return sqrt(__x*__x + __y*__y + __z*__z); }
535inline _LIBCPP_INLINE_VISIBILITY long double hypot( long double __x, long double __y, long double __z ) { return sqrt(__x*__x + __y*__y + __z*__z); }
535536
536537template <class _A1, class _A2, class _A3>
537538inline _LIBCPP_INLINE_VISIBILITY
lib/libcxx/include/codecvt+76-53
......@@ -54,17 +54,18 @@ class codecvt_utf8_utf16
5454
5555*/
5656
57#include <__assert> // all public C++ headers provide the assertion handler
5758#include <__config>
5859#include <__locale>
5960#include <version>
6061
6162#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
62#pragma GCC system_header
63# pragma GCC system_header
6364#endif
6465
6566_LIBCPP_BEGIN_NAMESPACE_STD
6667
67enum codecvt_mode
68enum _LIBCPP_DEPRECATED_IN_CXX17 codecvt_mode
6869{
6970 consume_header = 4,
7071 generate_header = 2,
......@@ -81,17 +82,21 @@ class _LIBCPP_TYPE_VIS __codecvt_utf8<wchar_t>
8182 : public codecvt<wchar_t, char, mbstate_t>
8283{
8384 unsigned long _Maxcode_;
85_LIBCPP_SUPPRESS_DEPRECATED_PUSH
8486 codecvt_mode _Mode_;
87_LIBCPP_SUPPRESS_DEPRECATED_POP
8588public:
8689 typedef wchar_t intern_type;
8790 typedef char extern_type;
8891 typedef mbstate_t state_type;
8992
93_LIBCPP_SUPPRESS_DEPRECATED_PUSH
9094 _LIBCPP_INLINE_VISIBILITY
91 explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode,
92 codecvt_mode _Mode)
93 : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
94 _Mode_(_Mode) {}
95 explicit __codecvt_utf8(size_t __refs, unsigned long __maxcode,
96 codecvt_mode __mode)
97 : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(__maxcode),
98 _Mode_(__mode) {}
99_LIBCPP_SUPPRESS_DEPRECATED_POP
95100protected:
96101 virtual result
97102 do_out(state_type& __st,
......@@ -125,10 +130,10 @@ public:
125130 typedef mbstate_t state_type;
126131
127132 _LIBCPP_INLINE_VISIBILITY
128 explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode,
129 codecvt_mode _Mode)
130 : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
131 _Mode_(_Mode) {}
133 explicit __codecvt_utf8(size_t __refs, unsigned long __maxcode,
134 codecvt_mode __mode)
135 : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(__maxcode),
136 _Mode_(__mode) {}
132137_LIBCPP_SUPPRESS_DEPRECATED_POP
133138
134139protected:
......@@ -163,10 +168,10 @@ public:
163168 typedef mbstate_t state_type;
164169
165170 _LIBCPP_INLINE_VISIBILITY
166 explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode,
167 codecvt_mode _Mode)
168 : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
169 _Mode_(_Mode) {}
171 explicit __codecvt_utf8(size_t __refs, unsigned long __maxcode,
172 codecvt_mode __mode)
173 : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(__maxcode),
174 _Mode_(__mode) {}
170175_LIBCPP_SUPPRESS_DEPRECATED_POP
171176
172177protected:
......@@ -188,9 +193,10 @@ protected:
188193 virtual int do_max_length() const _NOEXCEPT;
189194};
190195
196_LIBCPP_SUPPRESS_DEPRECATED_PUSH
191197template <class _Elem, unsigned long _Maxcode = 0x10ffff,
192198 codecvt_mode _Mode = (codecvt_mode)0>
193class _LIBCPP_TEMPLATE_VIS codecvt_utf8
199class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 codecvt_utf8
194200 : public __codecvt_utf8<_Elem>
195201{
196202public:
......@@ -201,6 +207,7 @@ public:
201207 _LIBCPP_INLINE_VISIBILITY
202208 ~codecvt_utf8() {}
203209};
210_LIBCPP_SUPPRESS_DEPRECATED_POP
204211
205212// codecvt_utf16
206213
......@@ -212,17 +219,21 @@ class _LIBCPP_TYPE_VIS __codecvt_utf16<wchar_t, false>
212219 : public codecvt<wchar_t, char, mbstate_t>
213220{
214221 unsigned long _Maxcode_;
222_LIBCPP_SUPPRESS_DEPRECATED_PUSH
215223 codecvt_mode _Mode_;
224_LIBCPP_SUPPRESS_DEPRECATED_POP
216225public:
217226 typedef wchar_t intern_type;
218227 typedef char extern_type;
219228 typedef mbstate_t state_type;
220229
230_LIBCPP_SUPPRESS_DEPRECATED_PUSH
221231 _LIBCPP_INLINE_VISIBILITY
222 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
223 codecvt_mode _Mode)
224 : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
225 _Mode_(_Mode) {}
232 explicit __codecvt_utf16(size_t __refs, unsigned long __maxcode,
233 codecvt_mode __mode)
234 : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(__maxcode),
235 _Mode_(__mode) {}
236_LIBCPP_SUPPRESS_DEPRECATED_POP
226237protected:
227238 virtual result
228239 do_out(state_type& __st,
......@@ -247,17 +258,21 @@ class _LIBCPP_TYPE_VIS __codecvt_utf16<wchar_t, true>
247258 : public codecvt<wchar_t, char, mbstate_t>
248259{
249260 unsigned long _Maxcode_;
261_LIBCPP_SUPPRESS_DEPRECATED_PUSH
250262 codecvt_mode _Mode_;
263_LIBCPP_SUPPRESS_DEPRECATED_POP
251264public:
252265 typedef wchar_t intern_type;
253266 typedef char extern_type;
254267 typedef mbstate_t state_type;
255268
269_LIBCPP_SUPPRESS_DEPRECATED_PUSH
256270 _LIBCPP_INLINE_VISIBILITY
257 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
258 codecvt_mode _Mode)
259 : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
260 _Mode_(_Mode) {}
271 explicit __codecvt_utf16(size_t __refs, unsigned long __maxcode,
272 codecvt_mode __mode)
273 : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(__maxcode),
274 _Mode_(__mode) {}
275_LIBCPP_SUPPRESS_DEPRECATED_POP
261276protected:
262277 virtual result
263278 do_out(state_type& __st,
......@@ -291,10 +306,10 @@ public:
291306 typedef mbstate_t state_type;
292307
293308 _LIBCPP_INLINE_VISIBILITY
294 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
295 codecvt_mode _Mode)
296 : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
297 _Mode_(_Mode) {}
309 explicit __codecvt_utf16(size_t __refs, unsigned long __maxcode,
310 codecvt_mode __mode)
311 : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(__maxcode),
312 _Mode_(__mode) {}
298313_LIBCPP_SUPPRESS_DEPRECATED_POP
299314
300315protected:
......@@ -329,10 +344,10 @@ public:
329344 typedef mbstate_t state_type;
330345
331346 _LIBCPP_INLINE_VISIBILITY
332 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
333 codecvt_mode _Mode)
334 : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
335 _Mode_(_Mode) {}
347 explicit __codecvt_utf16(size_t __refs, unsigned long __maxcode,
348 codecvt_mode __mode)
349 : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(__maxcode),
350 _Mode_(__mode) {}
336351_LIBCPP_SUPPRESS_DEPRECATED_POP
337352
338353protected:
......@@ -367,10 +382,10 @@ public:
367382 typedef mbstate_t state_type;
368383
369384 _LIBCPP_INLINE_VISIBILITY
370 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
371 codecvt_mode _Mode)
372 : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
373 _Mode_(_Mode) {}
385 explicit __codecvt_utf16(size_t __refs, unsigned long __maxcode,
386 codecvt_mode __mode)
387 : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(__maxcode),
388 _Mode_(__mode) {}
374389_LIBCPP_SUPPRESS_DEPRECATED_POP
375390
376391protected:
......@@ -405,10 +420,10 @@ public:
405420 typedef mbstate_t state_type;
406421
407422 _LIBCPP_INLINE_VISIBILITY
408 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
409 codecvt_mode _Mode)
410 : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
411 _Mode_(_Mode) {}
423 explicit __codecvt_utf16(size_t __refs, unsigned long __maxcode,
424 codecvt_mode __mode)
425 : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(__maxcode),
426 _Mode_(__mode) {}
412427_LIBCPP_SUPPRESS_DEPRECATED_POP
413428
414429protected:
......@@ -430,9 +445,10 @@ protected:
430445 virtual int do_max_length() const _NOEXCEPT;
431446};
432447
448_LIBCPP_SUPPRESS_DEPRECATED_PUSH
433449template <class _Elem, unsigned long _Maxcode = 0x10ffff,
434450 codecvt_mode _Mode = (codecvt_mode)0>
435class _LIBCPP_TEMPLATE_VIS codecvt_utf16
451class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 codecvt_utf16
436452 : public __codecvt_utf16<_Elem, _Mode & little_endian>
437453{
438454public:
......@@ -443,6 +459,7 @@ public:
443459 _LIBCPP_INLINE_VISIBILITY
444460 ~codecvt_utf16() {}
445461};
462_LIBCPP_SUPPRESS_DEPRECATED_POP
446463
447464// codecvt_utf8_utf16
448465
......@@ -454,17 +471,21 @@ class _LIBCPP_TYPE_VIS __codecvt_utf8_utf16<wchar_t>
454471 : public codecvt<wchar_t, char, mbstate_t>
455472{
456473 unsigned long _Maxcode_;
474_LIBCPP_SUPPRESS_DEPRECATED_PUSH
457475 codecvt_mode _Mode_;
476_LIBCPP_SUPPRESS_DEPRECATED_POP
458477public:
459478 typedef wchar_t intern_type;
460479 typedef char extern_type;
461480 typedef mbstate_t state_type;
462481
482_LIBCPP_SUPPRESS_DEPRECATED_PUSH
463483 _LIBCPP_INLINE_VISIBILITY
464 explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode,
465 codecvt_mode _Mode)
466 : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
467 _Mode_(_Mode) {}
484 explicit __codecvt_utf8_utf16(size_t __refs, unsigned long __maxcode,
485 codecvt_mode __mode)
486 : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(__maxcode),
487 _Mode_(__mode) {}
488_LIBCPP_SUPPRESS_DEPRECATED_POP
468489protected:
469490 virtual result
470491 do_out(state_type& __st,
......@@ -498,10 +519,10 @@ public:
498519 typedef mbstate_t state_type;
499520
500521 _LIBCPP_INLINE_VISIBILITY
501 explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode,
502 codecvt_mode _Mode)
503 : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
504 _Mode_(_Mode) {}
522 explicit __codecvt_utf8_utf16(size_t __refs, unsigned long __maxcode,
523 codecvt_mode __mode)
524 : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(__maxcode),
525 _Mode_(__mode) {}
505526_LIBCPP_SUPPRESS_DEPRECATED_POP
506527
507528protected:
......@@ -536,10 +557,10 @@ public:
536557 typedef mbstate_t state_type;
537558
538559 _LIBCPP_INLINE_VISIBILITY
539 explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode,
540 codecvt_mode _Mode)
541 : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
542 _Mode_(_Mode) {}
560 explicit __codecvt_utf8_utf16(size_t __refs, unsigned long __maxcode,
561 codecvt_mode __mode)
562 : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(__maxcode),
563 _Mode_(__mode) {}
543564_LIBCPP_SUPPRESS_DEPRECATED_POP
544565
545566protected:
......@@ -561,9 +582,10 @@ protected:
561582 virtual int do_max_length() const _NOEXCEPT;
562583};
563584
585_LIBCPP_SUPPRESS_DEPRECATED_PUSH
564586template <class _Elem, unsigned long _Maxcode = 0x10ffff,
565587 codecvt_mode _Mode = (codecvt_mode)0>
566class _LIBCPP_TEMPLATE_VIS codecvt_utf8_utf16
588class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 codecvt_utf8_utf16
567589 : public __codecvt_utf8_utf16<_Elem>
568590{
569591public:
......@@ -574,6 +596,7 @@ public:
574596 _LIBCPP_INLINE_VISIBILITY
575597 ~codecvt_utf8_utf16() {}
576598};
599_LIBCPP_SUPPRESS_DEPRECATED_POP
577600
578601_LIBCPP_END_NAMESPACE_STD
579602
lib/libcxx/include/compare+2-1
......@@ -140,6 +140,7 @@ namespace std {
140140}
141141*/
142142
143#include <__assert> // all public C++ headers provide the assertion handler
143144#include <__compare/common_comparison_category.h>
144145#include <__compare/compare_partial_order_fallback.h>
145146#include <__compare/compare_strong_order_fallback.h>
......@@ -156,7 +157,7 @@ namespace std {
156157#include <version>
157158
158159#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
159#pragma GCC system_header
160# pragma GCC system_header
160161#endif
161162
162163#endif // _LIBCPP_COMPARE
lib/libcxx/include/complex+2-1
......@@ -231,6 +231,7 @@ template<class T> complex<T> tanh (const complex<T>&);
231231
232232*/
233233
234#include <__assert> // all public C++ headers provide the assertion handler
234235#include <__config>
235236#include <cmath>
236237#include <iosfwd>
......@@ -243,7 +244,7 @@ template<class T> complex<T> tanh (const complex<T>&);
243244#endif
244245
245246#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
246#pragma GCC system_header
247# pragma GCC system_header
247248#endif
248249
249250_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/complex.h+1-1
......@@ -20,7 +20,7 @@
2020#include <__config>
2121
2222#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23#pragma GCC system_header
23# pragma GCC system_header
2424#endif
2525
2626#ifdef __cplusplus
lib/libcxx/include/concepts+2-1
......@@ -129,6 +129,7 @@ namespace std {
129129
130130*/
131131
132#include <__assert> // all public C++ headers provide the assertion handler
132133#include <__concepts/arithmetic.h>
133134#include <__concepts/assignable.h>
134135#include <__concepts/boolean_testable.h>
......@@ -155,7 +156,7 @@ namespace std {
155156#include <version>
156157
157158#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
158#pragma GCC system_header
159# pragma GCC system_header
159160#endif
160161
161162#endif // _LIBCPP_CONCEPTS
lib/libcxx/include/condition_variable+3-2
......@@ -106,13 +106,14 @@ public:
106106
107107*/
108108
109#include <__assert> // all public C++ headers provide the assertion handler
109110#include <__config>
110111#include <__mutex_base>
111112#include <memory>
112113#include <version>
113114
114115#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
115#pragma GCC system_header
116# pragma GCC system_header
116117#endif
117118
118119#ifndef _LIBCPP_HAS_NO_THREADS
......@@ -260,7 +261,7 @@ condition_variable_any::wait_for(_Lock& __lock,
260261}
261262
262263_LIBCPP_FUNC_VIS
263void notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk);
264void notify_all_at_thread_exit(condition_variable&, unique_lock<mutex>);
264265
265266_LIBCPP_END_NAMESPACE_STD
266267
lib/libcxx/include/coroutine+9-1
......@@ -38,6 +38,7 @@ struct suspend_always;
3838
3939 */
4040
41#include <__assert> // all public C++ headers provide the assertion handler
4142#include <__config>
4243#include <__coroutine/coroutine_handle.h>
4344#include <__coroutine/coroutine_traits.h>
......@@ -45,8 +46,15 @@ struct suspend_always;
4546#include <__coroutine/trivial_awaitables.h>
4647#include <version>
4748
49#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
50# include <iosfwd>
51#endif
52
53// standard-mandated includes
54#include <compare>
55
4856#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
49#pragma GCC system_header
57# pragma GCC system_header
5058#endif
5159
5260#endif // _LIBCPP_COROUTINE
lib/libcxx/include/csetjmp+2-1
......@@ -30,11 +30,12 @@ void longjmp(jmp_buf env, int val);
3030
3131*/
3232
33#include <__assert> // all public C++ headers provide the assertion handler
3334#include <__config>
3435#include <setjmp.h>
3536
3637#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
37#pragma GCC system_header
38# pragma GCC system_header
3839#endif
3940
4041_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/csignal+6-2
......@@ -39,11 +39,15 @@ int raise(int sig);
3939
4040*/
4141
42#include <__assert> // all public C++ headers provide the assertion handler
4243#include <__config>
43#include <signal.h>
44
45#if __has_include(<signal.h>)
46# include <signal.h>
47#endif
4448
4549#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
46#pragma GCC system_header
50# pragma GCC system_header
4751#endif
4852
4953_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/cstdarg+2-1
......@@ -31,11 +31,12 @@ Types:
3131
3232*/
3333
34#include <__assert> // all public C++ headers provide the assertion handler
3435#include <__config>
3536#include <stdarg.h>
3637
3738#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
38#pragma GCC system_header
39# pragma GCC system_header
3940#endif
4041
4142_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/cstdbool+2-1
......@@ -19,10 +19,11 @@ Macros:
1919
2020*/
2121
22#include <__assert> // all public C++ headers provide the assertion handler
2223#include <__config>
2324
2425#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
25#pragma GCC system_header
26# pragma GCC system_header
2627#endif
2728
2829#undef __bool_true_false_are_defined
lib/libcxx/include/cstddef+11-38
......@@ -33,19 +33,21 @@ Types:
3333
3434*/
3535
36#include <__assert> // all public C++ headers provide the assertion handler
3637#include <__config>
38#include <__type_traits/enable_if.h>
39#include <__type_traits/integral_constant.h>
40#include <__type_traits/is_integral.h>
41#include <stddef.h>
3742#include <version>
3843
3944#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
40#pragma GCC system_header
45# pragma GCC system_header
4146#endif
4247
43// Don't include our own <stddef.h>; we don't want to declare ::nullptr_t.
44#include_next <stddef.h>
45#include <__nullptr>
46
4748_LIBCPP_BEGIN_NAMESPACE_STD
4849
50using ::nullptr_t;
4951using ::ptrdiff_t _LIBCPP_USING_IF_EXISTS;
5052using ::size_t _LIBCPP_USING_IF_EXISTS;
5153
......@@ -53,34 +55,6 @@ using ::size_t _LIBCPP_USING_IF_EXISTS;
5355using ::max_align_t _LIBCPP_USING_IF_EXISTS;
5456#endif
5557
56template <class _Tp> struct __libcpp_is_integral { enum { value = 0 }; };
57template <> struct __libcpp_is_integral<bool> { enum { value = 1 }; };
58template <> struct __libcpp_is_integral<char> { enum { value = 1 }; };
59template <> struct __libcpp_is_integral<signed char> { enum { value = 1 }; };
60template <> struct __libcpp_is_integral<unsigned char> { enum { value = 1 }; };
61#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
62template <> struct __libcpp_is_integral<wchar_t> { enum { value = 1 }; };
63#endif
64#ifndef _LIBCPP_HAS_NO_CHAR8_T
65template <> struct __libcpp_is_integral<char8_t> { enum { value = 1 }; };
66#endif
67#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
68template <> struct __libcpp_is_integral<char16_t> { enum { value = 1 }; };
69template <> struct __libcpp_is_integral<char32_t> { enum { value = 1 }; };
70#endif
71template <> struct __libcpp_is_integral<short> { enum { value = 1 }; };
72template <> struct __libcpp_is_integral<unsigned short> { enum { value = 1 }; };
73template <> struct __libcpp_is_integral<int> { enum { value = 1 }; };
74template <> struct __libcpp_is_integral<unsigned int> { enum { value = 1 }; };
75template <> struct __libcpp_is_integral<long> { enum { value = 1 }; };
76template <> struct __libcpp_is_integral<unsigned long> { enum { value = 1 }; };
77template <> struct __libcpp_is_integral<long long> { enum { value = 1 }; };
78template <> struct __libcpp_is_integral<unsigned long long> { enum { value = 1 }; };
79#ifndef _LIBCPP_HAS_NO_INT128
80template <> struct __libcpp_is_integral<__int128_t> { enum { value = 1 }; };
81template <> struct __libcpp_is_integral<__uint128_t> { enum { value = 1 }; };
82#endif
83
8458_LIBCPP_END_NAMESPACE_STD
8559
8660#if _LIBCPP_STD_VER > 14
......@@ -88,11 +62,6 @@ namespace std // purposefully not versioned
8862{
8963enum class byte : unsigned char {};
9064
91
92template <bool> struct __enable_if_integral_imp {};
93template <> struct __enable_if_integral_imp<true> { using type = byte; };
94template <class _Tp> using _EnableByteOverload = typename __enable_if_integral_imp<__libcpp_is_integral<_Tp>::value>::type;
95
9665constexpr byte operator| (byte __lhs, byte __rhs) noexcept
9766{
9867 return static_cast<byte>(
......@@ -133,6 +102,10 @@ constexpr byte operator~ (byte __b) noexcept
133102 ~static_cast<unsigned int>(__b)
134103 ));
135104}
105
106template <class _Tp>
107using _EnableByteOverload = __enable_if_t<is_integral<_Tp>::value, byte>;
108
136109template <class _Integer>
137110 constexpr _EnableByteOverload<_Integer> &
138111 operator<<=(byte& __lhs, _Integer __shift) noexcept
lib/libcxx/include/cstdint+2-1
......@@ -140,11 +140,12 @@ Types:
140140} // std
141141*/
142142
143#include <__assert> // all public C++ headers provide the assertion handler
143144#include <__config>
144145#include <stdint.h>
145146
146147#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
147#pragma GCC system_header
148# pragma GCC system_header
148149#endif
149150
150151_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/cstdio+2-1
......@@ -95,11 +95,12 @@ void perror(const char* s);
9595} // std
9696*/
9797
98#include <__assert> // all public C++ headers provide the assertion handler
9899#include <__config>
99100#include <stdio.h>
100101
101102#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
102#pragma GCC system_header
103# pragma GCC system_header
103104#endif
104105
105106_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/cstdlib+4-11
......@@ -81,17 +81,12 @@ void *aligned_alloc(size_t alignment, size_t size); // C11
8181
8282*/
8383
84#include <__assert> // all public C++ headers provide the assertion handler
8485#include <__config>
8586#include <stdlib.h>
8687
8788#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
88#pragma GCC system_header
89#endif
90
91#ifdef __GNUC__
92#define _LIBCPP_UNREACHABLE() __builtin_unreachable()
93#else
94#define _LIBCPP_UNREACHABLE() _VSTD::abort()
89# pragma GCC system_header
9590#endif
9691
9792_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -121,10 +116,8 @@ using ::abort _LIBCPP_USING_IF_EXISTS;
121116using ::atexit _LIBCPP_USING_IF_EXISTS;
122117using ::exit _LIBCPP_USING_IF_EXISTS;
123118using ::_Exit _LIBCPP_USING_IF_EXISTS;
124#ifndef _LIBCPP_WINDOWS_STORE_APP
125119using ::getenv _LIBCPP_USING_IF_EXISTS;
126120using ::system _LIBCPP_USING_IF_EXISTS;
127#endif
128121using ::bsearch _LIBCPP_USING_IF_EXISTS;
129122using ::qsort _LIBCPP_USING_IF_EXISTS;
130123using ::abs _LIBCPP_USING_IF_EXISTS;
......@@ -138,11 +131,11 @@ using ::mbtowc _LIBCPP_USING_IF_EXISTS;
138131using ::wctomb _LIBCPP_USING_IF_EXISTS;
139132using ::mbstowcs _LIBCPP_USING_IF_EXISTS;
140133using ::wcstombs _LIBCPP_USING_IF_EXISTS;
141#if !defined(_LIBCPP_CXX03_LANG) && defined(_LIBCPP_HAS_QUICK_EXIT)
134#if !defined(_LIBCPP_CXX03_LANG)
142135using ::at_quick_exit _LIBCPP_USING_IF_EXISTS;
143136using ::quick_exit _LIBCPP_USING_IF_EXISTS;
144137#endif
145#if _LIBCPP_STD_VER > 14 && defined(_LIBCPP_HAS_ALIGNED_ALLOC)
138#if _LIBCPP_STD_VER > 14
146139using ::aligned_alloc _LIBCPP_USING_IF_EXISTS;
147140#endif
148141
lib/libcxx/include/cstring+2-1
......@@ -56,11 +56,12 @@ size_t strlen(const char* s);
5656
5757*/
5858
59#include <__assert> // all public C++ headers provide the assertion handler
5960#include <__config>
6061#include <string.h>
6162
6263#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
63#pragma GCC system_header
64# pragma GCC system_header
6465#endif
6566
6667_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/ctgmath+2-1
......@@ -18,11 +18,12 @@
1818
1919*/
2020
21#include <__assert> // all public C++ headers provide the assertion handler
2122#include <ccomplex>
2223#include <cmath>
2324
2425#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
25#pragma GCC system_header
26# pragma GCC system_header
2627#endif
2728
2829#endif // _LIBCPP_CTGMATH
lib/libcxx/include/ctime+4-17
......@@ -45,25 +45,12 @@ int timespec_get( struct timespec *ts, int base); // C++17
4545
4646*/
4747
48#include <__assert> // all public C++ headers provide the assertion handler
4849#include <__config>
4950#include <time.h>
5051
5152#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
52#pragma GCC system_header
53#endif
54
55// FIXME:
56// Apple SDKs don't define ::timespec_get unconditionally in C++ mode. This
57// should be fixed in future SDKs, but for the time being we need to avoid
58// trying to use that declaration when the SDK doesn't provide it. Note that
59// we're detecting this here instead of in <__config> because we can't include
60// system headers from <__config>, since it leads to circular module dependencies.
61// This is also meant to be a very temporary workaround until the SDKs are fixed.
62#if defined(__APPLE__) && !__has_attribute(using_if_exists)
63# include <sys/cdefs.h>
64# if defined(_LIBCPP_HAS_TIMESPEC_GET) && (__DARWIN_C_LEVEL < __DARWIN_C_FULL)
65# define _LIBCPP_HAS_TIMESPEC_GET_NOT_ACTUALLY_PROVIDED
66# endif
53# pragma GCC system_header
6754#endif
6855
6956_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -72,7 +59,7 @@ using ::clock_t _LIBCPP_USING_IF_EXISTS;
7259using ::size_t _LIBCPP_USING_IF_EXISTS;
7360using ::time_t _LIBCPP_USING_IF_EXISTS;
7461using ::tm _LIBCPP_USING_IF_EXISTS;
75#if _LIBCPP_STD_VER > 14 && defined(_LIBCPP_HAS_TIMESPEC_GET)
62#if _LIBCPP_STD_VER > 14
7663using ::timespec _LIBCPP_USING_IF_EXISTS;
7764#endif
7865using ::clock _LIBCPP_USING_IF_EXISTS;
......@@ -84,7 +71,7 @@ using ::ctime _LIBCPP_USING_IF_EXISTS;
8471using ::gmtime _LIBCPP_USING_IF_EXISTS;
8572using ::localtime _LIBCPP_USING_IF_EXISTS;
8673using ::strftime _LIBCPP_USING_IF_EXISTS;
87#if _LIBCPP_STD_VER > 14 && defined(_LIBCPP_HAS_TIMESPEC_GET) && !defined(_LIBCPP_HAS_TIMESPEC_GET_NOT_ACTUALLY_PROVIDED)
74#if _LIBCPP_STD_VER > 14
8875using ::timespec_get _LIBCPP_USING_IF_EXISTS;
8976#endif
9077
lib/libcxx/include/ctype.h+1-1
......@@ -32,7 +32,7 @@ int toupper(int c);
3232#include <__config>
3333
3434#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
35#pragma GCC system_header
35# pragma GCC system_header
3636#endif
3737
3838#include_next <ctype.h>
lib/libcxx/include/cuchar created+61
......@@ -0,0 +1,61 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_CUCHAR
11#define _LIBCPP_CUCHAR
12
13/*
14 cuchar synopsis // since C++11
15
16Macros:
17
18 __STDC_UTF_16__
19 __STDC_UTF_32__
20
21namespace std {
22
23Types:
24
25 mbstate_t
26 size_t
27
28size_t mbrtoc16(char16_t* pc16, const char* s, size_t n, mbstate_t* ps);
29size_t c16rtomb(char* s, char16_t c16, mbstate_t* ps);
30size_t mbrtoc32(char32_t* pc32, const char* s, size_t n, mbstate_t* ps);
31size_t c32rtomb(char* s, char32_t c32, mbstate_t* ps);
32
33} // std
34
35*/
36
37#include <__assert> // all public C++ headers provide the assertion handler
38#include <__config>
39#include <uchar.h>
40
41#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
42# pragma GCC system_header
43#endif
44
45_LIBCPP_BEGIN_NAMESPACE_STD
46
47#if !defined(_LIBCPP_CXX03_LANG)
48
49using ::mbstate_t _LIBCPP_USING_IF_EXISTS;
50using ::size_t _LIBCPP_USING_IF_EXISTS;
51
52using ::mbrtoc16 _LIBCPP_USING_IF_EXISTS;
53using ::c16rtomb _LIBCPP_USING_IF_EXISTS;
54using ::mbrtoc32 _LIBCPP_USING_IF_EXISTS;
55using ::c32rtomb _LIBCPP_USING_IF_EXISTS;
56
57#endif // _LIBCPP_CXX03_LANG
58
59_LIBCPP_END_NAMESPACE_STD
60
61#endif // _LIBCPP_CUCHAR
lib/libcxx/include/cwchar+2-1
......@@ -102,12 +102,13 @@ size_t wcsrtombs(char* restrict dst, const wchar_t** restrict src, size_t len,
102102
103103*/
104104
105#include <__assert> // all public C++ headers provide the assertion handler
105106#include <__config>
106107#include <cwctype>
107108#include <wchar.h>
108109
109110#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
110#pragma GCC system_header
111# pragma GCC system_header
111112#endif
112113
113114_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/cwctype+2-1
......@@ -49,12 +49,13 @@ wctrans_t wctrans(const char* property);
4949
5050*/
5151
52#include <__assert> // all public C++ headers provide the assertion handler
5253#include <__config>
5354#include <cctype>
5455#include <wctype.h>
5556
5657#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
57#pragma GCC system_header
58# pragma GCC system_header
5859#endif
5960
6061_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/deque+54-23
......@@ -160,22 +160,52 @@ template <class T, class Allocator, class Predicate>
160160
161161*/
162162
163#include <__algorithm/copy.h>
164#include <__algorithm/copy_backward.h>
165#include <__algorithm/equal.h>
166#include <__algorithm/fill_n.h>
167#include <__algorithm/lexicographical_compare.h>
168#include <__algorithm/min.h>
169#include <__algorithm/remove.h>
170#include <__algorithm/remove_if.h>
171#include <__algorithm/unwrap_iter.h>
172#include <__assert> // all public C++ headers provide the assertion handler
163173#include <__config>
164#include <__debug>
174#include <__format/enable_insertable.h>
165175#include <__iterator/iterator_traits.h>
176#include <__iterator/next.h>
177#include <__iterator/prev.h>
178#include <__iterator/reverse_iterator.h>
166179#include <__split_buffer>
167180#include <__utility/forward.h>
168#include <algorithm>
169#include <compare>
170#include <initializer_list>
171#include <iterator>
181#include <__utility/move.h>
182#include <__utility/swap.h>
172183#include <limits>
173184#include <stdexcept>
174185#include <type_traits>
175186#include <version>
176187
188#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
189# include <algorithm>
190# include <functional>
191# include <iterator>
192#endif
193
194// standard-mandated includes
195
196// [iterator.range]
197#include <__iterator/access.h>
198#include <__iterator/data.h>
199#include <__iterator/empty.h>
200#include <__iterator/reverse_access.h>
201#include <__iterator/size.h>
202
203// [deque.syn]
204#include <compare>
205#include <initializer_list>
206
177207#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
178#pragma GCC system_header
208# pragma GCC system_header
179209#endif
180210
181211_LIBCPP_PUSH_MACROS
......@@ -442,7 +472,7 @@ public:
442472 {return !(__x < __y);}
443473
444474private:
445 _LIBCPP_INLINE_VISIBILITY __deque_iterator(__map_iterator __m, pointer __p) _NOEXCEPT
475 _LIBCPP_INLINE_VISIBILITY explicit __deque_iterator(__map_iterator __m, pointer __p) _NOEXCEPT
446476 : __m_iter_(__m), __ptr_(__p) {}
447477
448478 template <class _Tp, class _Ap> friend class __deque_base;
......@@ -1304,7 +1334,7 @@ public:
13041334 deque(_InputIter __f, _InputIter __l, const allocator_type& __a,
13051335 typename enable_if<__is_cpp17_input_iterator<_InputIter>::value>::type* = 0);
13061336 deque(const deque& __c);
1307 deque(const deque& __c, const __identity_t<allocator_type>& __a);
1337 deque(const deque& __c, const __type_identity_t<allocator_type>& __a);
13081338
13091339 deque& operator=(const deque& __c);
13101340
......@@ -1318,7 +1348,7 @@ public:
13181348 _LIBCPP_INLINE_VISIBILITY
13191349 deque(deque&& __c) _NOEXCEPT_(is_nothrow_move_constructible<__base>::value);
13201350 _LIBCPP_INLINE_VISIBILITY
1321 deque(deque&& __c, const __identity_t<allocator_type>& __a);
1351 deque(deque&& __c, const __type_identity_t<allocator_type>& __a);
13221352 _LIBCPP_INLINE_VISIBILITY
13231353 deque& operator=(deque&& __c)
13241354 _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
......@@ -1434,12 +1464,10 @@ public:
14341464 iterator insert(const_iterator __p, size_type __n, const value_type& __v);
14351465 template <class _InputIter>
14361466 iterator insert(const_iterator __p, _InputIter __f, _InputIter __l,
1437 typename enable_if<__is_cpp17_input_iterator<_InputIter>::value
1438 &&!__is_cpp17_forward_iterator<_InputIter>::value>::type* = 0);
1467 typename enable_if<__is_exactly_cpp17_input_iterator<_InputIter>::value>::type* = 0);
14391468 template <class _ForwardIterator>
14401469 iterator insert(const_iterator __p, _ForwardIterator __f, _ForwardIterator __l,
1441 typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value
1442 &&!__is_cpp17_bidirectional_iterator<_ForwardIterator>::value>::type* = 0);
1470 typename enable_if<__is_exactly_cpp17_forward_iterator<_ForwardIterator>::value>::type* = 0);
14431471 template <class _BiIter>
14441472 iterator insert(const_iterator __p, _BiIter __f, _BiIter __l,
14451473 typename enable_if<__is_cpp17_bidirectional_iterator<_BiIter>::value>::type* = 0);
......@@ -1526,8 +1554,7 @@ public:
15261554
15271555 template <class _InpIter>
15281556 void __append(_InpIter __f, _InpIter __l,
1529 typename enable_if<__is_cpp17_input_iterator<_InpIter>::value &&
1530 !__is_cpp17_forward_iterator<_InpIter>::value>::type* = 0);
1557 typename enable_if<__is_exactly_cpp17_input_iterator<_InpIter>::value>::type* = 0);
15311558 template <class _ForIter>
15321559 void __append(_ForIter __f, _ForIter __l,
15331560 typename enable_if<__is_cpp17_forward_iterator<_ForIter>::value>::type* = 0);
......@@ -1640,7 +1667,7 @@ deque<_Tp, _Allocator>::deque(const deque& __c)
16401667}
16411668
16421669template <class _Tp, class _Allocator>
1643deque<_Tp, _Allocator>::deque(const deque& __c, const __identity_t<allocator_type>& __a)
1670deque<_Tp, _Allocator>::deque(const deque& __c, const __type_identity_t<allocator_type>& __a)
16441671 : __base(__a)
16451672{
16461673 __append(__c.begin(), __c.end());
......@@ -1683,7 +1710,7 @@ deque<_Tp, _Allocator>::deque(deque&& __c)
16831710
16841711template <class _Tp, class _Allocator>
16851712inline
1686deque<_Tp, _Allocator>::deque(deque&& __c, const __identity_t<allocator_type>& __a)
1713deque<_Tp, _Allocator>::deque(deque&& __c, const __type_identity_t<allocator_type>& __a)
16871714 : __base(_VSTD::move(__c), __a)
16881715{
16891716 if (__a != __c.__alloc())
......@@ -2236,8 +2263,7 @@ template <class _Tp, class _Allocator>
22362263template <class _InputIter>
22372264typename deque<_Tp, _Allocator>::iterator
22382265deque<_Tp, _Allocator>::insert(const_iterator __p, _InputIter __f, _InputIter __l,
2239 typename enable_if<__is_cpp17_input_iterator<_InputIter>::value
2240 &&!__is_cpp17_forward_iterator<_InputIter>::value>::type*)
2266 typename enable_if<__is_exactly_cpp17_input_iterator<_InputIter>::value>::type*)
22412267{
22422268 __split_buffer<value_type, allocator_type&> __buf(__base::__alloc());
22432269 __buf.__construct_at_end(__f, __l);
......@@ -2249,8 +2275,7 @@ template <class _Tp, class _Allocator>
22492275template <class _ForwardIterator>
22502276typename deque<_Tp, _Allocator>::iterator
22512277deque<_Tp, _Allocator>::insert(const_iterator __p, _ForwardIterator __f, _ForwardIterator __l,
2252 typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value
2253 &&!__is_cpp17_bidirectional_iterator<_ForwardIterator>::value>::type*)
2278 typename enable_if<__is_exactly_cpp17_forward_iterator<_ForwardIterator>::value>::type*)
22542279{
22552280 size_type __n = _VSTD::distance(__f, __l);
22562281 __split_buffer<value_type, allocator_type&> __buf(__n, 0, __base::__alloc());
......@@ -2332,8 +2357,7 @@ template <class _Tp, class _Allocator>
23322357template <class _InpIter>
23332358void
23342359deque<_Tp, _Allocator>::__append(_InpIter __f, _InpIter __l,
2335 typename enable_if<__is_cpp17_input_iterator<_InpIter>::value &&
2336 !__is_cpp17_forward_iterator<_InpIter>::value>::type*)
2360 typename enable_if<__is_exactly_cpp17_input_iterator<_InpIter>::value>::type*)
23372361{
23382362 for (; __f != __l; ++__f)
23392363#ifdef _LIBCPP_CXX03_LANG
......@@ -3019,8 +3043,15 @@ erase_if(deque<_Tp, _Allocator>& __c, _Predicate __pred) {
30193043 __c.erase(_VSTD::remove_if(__c.begin(), __c.end(), __pred), __c.end());
30203044 return __old_size - __c.size();
30213045}
3046
3047template <>
3048inline constexpr bool __format::__enable_insertable<std::deque<char>> = true;
3049#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
3050template <>
3051inline constexpr bool __format::__enable_insertable<std::deque<wchar_t>> = true;
30223052#endif
30233053
3054#endif // _LIBCPP_STD_VER > 17
30243055
30253056_LIBCPP_END_NAMESPACE_STD
30263057
lib/libcxx/include/errno.h+1-1
......@@ -25,7 +25,7 @@ Macros:
2525#include <__config>
2626
2727#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
28#pragma GCC system_header
28# pragma GCC system_header
2929#endif
3030
3131#include_next <errno.h>
lib/libcxx/include/exception+10-13
......@@ -76,6 +76,7 @@ template <class E> void rethrow_if_nested(const E& e);
7676
7777*/
7878
79#include <__assert> // all public C++ headers provide the assertion handler
7980#include <__availability>
8081#include <__config>
8182#include <__memory/addressof.h>
......@@ -89,7 +90,7 @@ template <class E> void rethrow_if_nested(const E& e);
8990#endif
9091
9192#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
92#pragma GCC system_header
93# pragma GCC system_header
9394#endif
9495
9596namespace std // purposefully not using versioning namespace
......@@ -189,15 +190,11 @@ make_exception_ptr(_Ep __e) _NOEXCEPT
189190
190191class _LIBCPP_TYPE_VIS exception_ptr
191192{
192#if defined(__clang__)
193#pragma clang diagnostic push
194#pragma clang diagnostic ignored "-Wunused-private-field"
195#endif
193_LIBCPP_DIAGNOSTIC_PUSH
194_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wunused-private-field")
196195 void* __ptr1_;
197196 void* __ptr2_;
198#if defined(__clang__)
199#pragma clang diagnostic pop
200#endif
197_LIBCPP_DIAGNOSTIC_POP
201198public:
202199 exception_ptr() _NOEXCEPT;
203200 exception_ptr(nullptr_t) _NOEXCEPT;
......@@ -219,7 +216,7 @@ _LIBCPP_FUNC_VIS void swap(exception_ptr&, exception_ptr&) _NOEXCEPT;
219216
220217_LIBCPP_FUNC_VIS exception_ptr __copy_exception_ptr(void *__except, const void* __ptr);
221218_LIBCPP_FUNC_VIS exception_ptr current_exception() _NOEXCEPT;
222_LIBCPP_NORETURN _LIBCPP_FUNC_VIS void rethrow_exception(exception_ptr p);
219_LIBCPP_NORETURN _LIBCPP_FUNC_VIS void rethrow_exception(exception_ptr);
223220
224221// This is a built-in template function which automagically extracts the required
225222// information.
......@@ -304,16 +301,16 @@ throw_with_nested(_Tp&& __t)
304301}
305302
306303template <class _From, class _To>
307struct __can_dynamic_cast : public _LIBCPP_BOOL_CONSTANT(
304struct __can_dynamic_cast : _BoolConstant<
308305 is_polymorphic<_From>::value &&
309306 (!is_base_of<_To, _From>::value ||
310 is_convertible<const _From*, const _To*>::value)) {};
307 is_convertible<const _From*, const _To*>::value)> {};
311308
312309template <class _Ep>
313310inline _LIBCPP_INLINE_VISIBILITY
314311void
315312rethrow_if_nested(const _Ep& __e,
316 typename enable_if< __can_dynamic_cast<_Ep, nested_exception>::value>::type* = 0)
313 __enable_if_t< __can_dynamic_cast<_Ep, nested_exception>::value>* = 0)
317314{
318315 const nested_exception* __nep = dynamic_cast<const nested_exception*>(_VSTD::addressof(__e));
319316 if (__nep)
......@@ -324,7 +321,7 @@ template <class _Ep>
324321inline _LIBCPP_INLINE_VISIBILITY
325322void
326323rethrow_if_nested(const _Ep&,
327 typename enable_if<!__can_dynamic_cast<_Ep, nested_exception>::value>::type* = 0)
324 __enable_if_t<!__can_dynamic_cast<_Ep, nested_exception>::value>* = 0)
328325{
329326}
330327
lib/libcxx/include/execution+2-1
......@@ -10,6 +10,7 @@
1010#ifndef _LIBCPP_EXECUTION
1111#define _LIBCPP_EXECUTION
1212
13#include <__assert> // all public C++ headers provide the assertion handler
1314#include <__config>
1415#include <version>
1516
......@@ -18,7 +19,7 @@
1819#endif
1920
2021#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21#pragma GCC system_header
22# pragma GCC system_header
2223#endif
2324
2425#endif // _LIBCPP_EXECUTION
lib/libcxx/include/experimental/__config+1-14
......@@ -13,7 +13,7 @@
1313#include <__config>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16#pragma GCC system_header
16# pragma GCC system_header
1717#endif
1818
1919#define _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL namespace std { namespace experimental {
......@@ -32,19 +32,6 @@
3232#define _LIBCPP_END_NAMESPACE_LFTS_PMR _LIBCPP_END_NAMESPACE_LFTS }
3333#define _VSTD_LFTS_PMR _VSTD_LFTS::pmr
3434
35#if defined(_LIBCPP_NO_EXPERIMENTAL_DEPRECATION_WARNING_FILESYSTEM)
36# define _LIBCPP_DEPRECATED_EXPERIMENTAL_FILESYSTEM /* nothing */
37#else
38# define _LIBCPP_DEPRECATED_EXPERIMENTAL_FILESYSTEM __attribute__((deprecated("std::experimental::filesystem has now been deprecated in favor of C++17's std::filesystem. Please stop using it and start using std::filesystem. This experimental version will be removed in LLVM 11. You can remove this warning by defining the _LIBCPP_NO_EXPERIMENTAL_DEPRECATION_WARNING_FILESYSTEM macro.")))
39#endif
40
41#define _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_FILESYSTEM \
42 _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL namespace filesystem _LIBCPP_DEPRECATED_EXPERIMENTAL_FILESYSTEM { \
43 inline namespace v1 {
44
45#define _LIBCPP_END_NAMESPACE_EXPERIMENTAL_FILESYSTEM \
46 } } _LIBCPP_END_NAMESPACE_EXPERIMENTAL
47
4835#if !defined(__cpp_coroutines) || __cpp_coroutines < 201703L
4936#define _LIBCPP_HAS_NO_EXPERIMENTAL_COROUTINES
5037#endif
lib/libcxx/include/experimental/__memory+1-2
......@@ -10,7 +10,6 @@
1010#ifndef _LIBCPP_EXPERIMENTAL___MEMORY
1111#define _LIBCPP_EXPERIMENTAL___MEMORY
1212
13#include <__functional_base>
1413#include <__memory/allocator_arg_t.h>
1514#include <__memory/uses_allocator.h>
1615#include <experimental/__config>
......@@ -18,7 +17,7 @@
1817#include <type_traits>
1918
2019#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21#pragma GCC system_header
20# pragma GCC system_header
2221#endif
2322
2423_LIBCPP_BEGIN_NAMESPACE_LFTS
lib/libcxx/include/experimental/algorithm+2-1
......@@ -31,13 +31,14 @@ ForwardIterator search(ForwardIterator first, ForwardIterator last,
3131
3232*/
3333
34#include <__assert> // all public C++ headers provide the assertion handler
3435#include <__debug>
3536#include <algorithm>
3637#include <experimental/__config>
3738#include <type_traits>
3839
3940#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
40#pragma GCC system_header
41# pragma GCC system_header
4142#endif
4243
4344_LIBCPP_BEGIN_NAMESPACE_LFTS
lib/libcxx/include/experimental/coroutine+4-11
......@@ -45,24 +45,17 @@ template <class P> struct hash<coroutine_handle<P>>;
4545
4646 */
4747
48#include <__debug>
48#include <__assert> // all public C++ headers provide the assertion handler
49#include <__functional/hash.h>
50#include <__functional/operations.h>
4951#include <cstddef>
5052#include <experimental/__config>
51#include <functional>
5253#include <memory> // for hash<T*>
5354#include <new>
5455#include <type_traits>
5556
5657#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
57#pragma GCC system_header
58#endif
59
60#ifdef _LIBCPP_HAS_NO_EXPERIMENTAL_COROUTINES
61# if defined(_LIBCPP_WARNING)
62 _LIBCPP_WARNING("<experimental/coroutine> cannot be used with this compiler")
63# else
64# warning <experimental/coroutine> cannot be used with this compiler
65# endif
58# pragma GCC system_header
6659#endif
6760
6861#ifndef _LIBCPP_HAS_NO_EXPERIMENTAL_COROUTINES
lib/libcxx/include/experimental/deque+3-1
......@@ -9,6 +9,7 @@
99
1010#ifndef _LIBCPP_EXPERIMENTAL_DEQUE
1111#define _LIBCPP_EXPERIMENTAL_DEQUE
12
1213/*
1314 experimental/deque synopsis
1415
......@@ -28,12 +29,13 @@ namespace pmr {
2829
2930 */
3031
32#include <__assert> // all public C++ headers provide the assertion handler
3133#include <deque>
3234#include <experimental/__config>
3335#include <experimental/memory_resource>
3436
3537#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
36#pragma GCC system_header
38# pragma GCC system_header
3739#endif
3840
3941_LIBCPP_BEGIN_NAMESPACE_LFTS_PMR
lib/libcxx/include/experimental/filesystem deleted-256
......@@ -1,256 +0,0 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9#ifndef _LIBCPP_EXPERIMENTAL_FILESYSTEM
10#define _LIBCPP_EXPERIMENTAL_FILESYSTEM
11/*
12 filesystem synopsis
13
14 namespace std { namespace experimental { namespace filesystem { inline namespace v1 {
15
16 class path;
17
18 void swap(path& lhs, path& rhs) noexcept;
19 size_t hash_value(const path& p) noexcept;
20
21 bool operator==(const path& lhs, const path& rhs) noexcept;
22 bool operator!=(const path& lhs, const path& rhs) noexcept;
23 bool operator< (const path& lhs, const path& rhs) noexcept;
24 bool operator<=(const path& lhs, const path& rhs) noexcept;
25 bool operator> (const path& lhs, const path& rhs) noexcept;
26 bool operator>=(const path& lhs, const path& rhs) noexcept;
27
28 path operator/ (const path& lhs, const path& rhs);
29
30 // fs.path.io operators are friends of path.
31 template <class charT, class traits>
32 friend basic_ostream<charT, traits>&
33 operator<<(basic_ostream<charT, traits>& os, const path& p);
34
35 template <class charT, class traits>
36 friend basic_istream<charT, traits>&
37 operator>>(basic_istream<charT, traits>& is, path& p);
38
39 template <class Source>
40 path u8path(const Source& source);
41 template <class InputIterator>
42 path u8path(InputIterator first, InputIterator last);
43
44 class filesystem_error;
45 class directory_entry;
46
47 class directory_iterator;
48
49 // enable directory_iterator range-based for statements
50 directory_iterator begin(directory_iterator iter) noexcept;
51 directory_iterator end(const directory_iterator&) noexcept;
52
53 class recursive_directory_iterator;
54
55 // enable recursive_directory_iterator range-based for statements
56 recursive_directory_iterator begin(recursive_directory_iterator iter) noexcept;
57 recursive_directory_iterator end(const recursive_directory_iterator&) noexcept;
58
59 class file_status;
60
61 struct space_info
62 {
63 uintmax_t capacity;
64 uintmax_t free;
65 uintmax_t available;
66 };
67
68 enum class file_type;
69 enum class perms;
70 enum class perm_options;
71 enum class copy_options;
72 enum class directory_options;
73
74 typedef chrono::time_point<trivial-clock> file_time_type;
75
76 // operational functions
77
78 path absolute(const path& p);
79 path absolute(const path& p, error_code &ec);
80
81 path canonical(const path& p);
82 path canonical(const path& p, error_code& ec);
83
84 void copy(const path& from, const path& to);
85 void copy(const path& from, const path& to, error_code& ec);
86 void copy(const path& from, const path& to, copy_options options);
87 void copy(const path& from, const path& to, copy_options options,
88 error_code& ec);
89
90 bool copy_file(const path& from, const path& to);
91 bool copy_file(const path& from, const path& to, error_code& ec);
92 bool copy_file(const path& from, const path& to, copy_options option);
93 bool copy_file(const path& from, const path& to, copy_options option,
94 error_code& ec);
95
96 void copy_symlink(const path& existing_symlink, const path& new_symlink);
97 void copy_symlink(const path& existing_symlink, const path& new_symlink,
98 error_code& ec) noexcept;
99
100 bool create_directories(const path& p);
101 bool create_directories(const path& p, error_code& ec);
102
103 bool create_directory(const path& p);
104 bool create_directory(const path& p, error_code& ec) noexcept;
105
106 bool create_directory(const path& p, const path& attributes);
107 bool create_directory(const path& p, const path& attributes,
108 error_code& ec) noexcept;
109
110 void create_directory_symlink(const path& to, const path& new_symlink);
111 void create_directory_symlink(const path& to, const path& new_symlink,
112 error_code& ec) noexcept;
113
114 void create_hard_link(const path& to, const path& new_hard_link);
115 void create_hard_link(const path& to, const path& new_hard_link,
116 error_code& ec) noexcept;
117
118 void create_symlink(const path& to, const path& new_symlink);
119 void create_symlink(const path& to, const path& new_symlink,
120 error_code& ec) noexcept;
121
122 path current_path();
123 path current_path(error_code& ec);
124 void current_path(const path& p);
125 void current_path(const path& p, error_code& ec) noexcept;
126
127 bool exists(file_status s) noexcept;
128 bool exists(const path& p);
129 bool exists(const path& p, error_code& ec) noexcept;
130
131 bool equivalent(const path& p1, const path& p2);
132 bool equivalent(const path& p1, const path& p2, error_code& ec) noexcept;
133
134 uintmax_t file_size(const path& p);
135 uintmax_t file_size(const path& p, error_code& ec) noexcept;
136
137 uintmax_t hard_link_count(const path& p);
138 uintmax_t hard_link_count(const path& p, error_code& ec) noexcept;
139
140 bool is_block_file(file_status s) noexcept;
141 bool is_block_file(const path& p);
142 bool is_block_file(const path& p, error_code& ec) noexcept;
143
144 bool is_character_file(file_status s) noexcept;
145 bool is_character_file(const path& p);
146 bool is_character_file(const path& p, error_code& ec) noexcept;
147
148 bool is_directory(file_status s) noexcept;
149 bool is_directory(const path& p);
150 bool is_directory(const path& p, error_code& ec) noexcept;
151
152 bool is_empty(const path& p);
153 bool is_empty(const path& p, error_code& ec) noexcept;
154
155 bool is_fifo(file_status s) noexcept;
156 bool is_fifo(const path& p);
157 bool is_fifo(const path& p, error_code& ec) noexcept;
158
159 bool is_other(file_status s) noexcept;
160 bool is_other(const path& p);
161 bool is_other(const path& p, error_code& ec) noexcept;
162
163 bool is_regular_file(file_status s) noexcept;
164 bool is_regular_file(const path& p);
165 bool is_regular_file(const path& p, error_code& ec) noexcept;
166
167 bool is_socket(file_status s) noexcept;
168 bool is_socket(const path& p);
169 bool is_socket(const path& p, error_code& ec) noexcept;
170
171 bool is_symlink(file_status s) noexcept;
172 bool is_symlink(const path& p);
173 bool is_symlink(const path& p, error_code& ec) noexcept;
174
175 file_time_type last_write_time(const path& p);
176 file_time_type last_write_time(const path& p, error_code& ec) noexcept;
177 void last_write_time(const path& p, file_time_type new_time);
178 void last_write_time(const path& p, file_time_type new_time,
179 error_code& ec) noexcept;
180
181 void permissions(const path& p, perms prms,
182 perm_options opts=perm_options::replace);
183 void permissions(const path& p, perms prms, error_code& ec) noexcept;
184 void permissions(const path& p, perms prms, perm_options opts,
185 error_code& ec);
186
187 path proximate(const path& p, error_code& ec);
188 path proximate(const path& p, const path& base = current_path());
189 path proximate(const path& p, const path& base, error_code &ec);
190
191 path read_symlink(const path& p);
192 path read_symlink(const path& p, error_code& ec);
193
194 path relative(const path& p, error_code& ec);
195 path relative(const path& p, const path& base=current_path());
196 path relative(const path& p, const path& base, error_code& ec);
197
198 bool remove(const path& p);
199 bool remove(const path& p, error_code& ec) noexcept;
200
201 uintmax_t remove_all(const path& p);
202 uintmax_t remove_all(const path& p, error_code& ec);
203
204 void rename(const path& from, const path& to);
205 void rename(const path& from, const path& to, error_code& ec) noexcept;
206
207 void resize_file(const path& p, uintmax_t size);
208 void resize_file(const path& p, uintmax_t size, error_code& ec) noexcept;
209
210 space_info space(const path& p);
211 space_info space(const path& p, error_code& ec) noexcept;
212
213 file_status status(const path& p);
214 file_status status(const path& p, error_code& ec) noexcept;
215
216 bool status_known(file_status s) noexcept;
217
218 file_status symlink_status(const path& p);
219 file_status symlink_status(const path& p, error_code& ec) noexcept;
220
221 path temp_directory_path();
222 path temp_directory_path(error_code& ec);
223
224 path weakly_canonical(path const& p);
225 path weakly_canonical(path const& p, error_code& ec);
226
227
228} } } } // namespaces std::experimental::filesystem::v1
229
230*/
231
232#include <experimental/__config>
233#include <filesystem>
234
235#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
236#pragma GCC system_header
237#endif
238
239_LIBCPP_PUSH_MACROS
240#include <__undef_macros>
241
242#ifndef _LIBCPP_CXX03_LANG
243
244#define __cpp_lib_experimental_filesystem 201406
245
246_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_FILESYSTEM
247
248using namespace _VSTD_FS;
249
250_LIBCPP_END_NAMESPACE_EXPERIMENTAL_FILESYSTEM
251
252#endif // !_LIBCPP_CXX03_LANG
253
254_LIBCPP_POP_MACROS
255
256#endif // _LIBCPP_EXPERIMENTAL_FILESYSTEM
lib/libcxx/include/experimental/forward_list+3-1
......@@ -9,6 +9,7 @@
99
1010#ifndef _LIBCPP_EXPERIMENTAL_FORWARD_LIST
1111#define _LIBCPP_EXPERIMENTAL_FORWARD_LIST
12
1213/*
1314 experimental/forward_list synopsis
1415
......@@ -28,12 +29,13 @@ namespace pmr {
2829
2930 */
3031
32#include <__assert> // all public C++ headers provide the assertion handler
3133#include <experimental/__config>
3234#include <experimental/memory_resource>
3335#include <forward_list>
3436
3537#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
36#pragma GCC system_header
38# pragma GCC system_header
3739#endif
3840
3941_LIBCPP_BEGIN_NAMESPACE_LFTS_PMR
lib/libcxx/include/experimental/functional+30-51
......@@ -18,29 +18,6 @@
1818namespace std {
1919namespace experimental {
2020inline namespace fundamentals_v1 {
21
22 // See C++14 20.9.9, Function object binders
23 template <class T> constexpr bool is_bind_expression_v
24 = is_bind_expression<T>::value;
25 template <class T> constexpr int is_placeholder_v
26 = is_placeholder<T>::value;
27
28 // 4.2, Class template function
29 template<class> class function; // undefined
30 template<class R, class... ArgTypes> class function<R(ArgTypes...)>;
31
32 template<class R, class... ArgTypes>
33 void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&);
34
35 template<class R, class... ArgTypes>
36 bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
37 template<class R, class... ArgTypes>
38 bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
39 template<class R, class... ArgTypes>
40 bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
41 template<class R, class... ArgTypes>
42 bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
43
4421 // 4.3, Searchers
4522 template<class ForwardIterator, class BinaryPredicate = equal_to<>>
4623 class default_searcher;
......@@ -79,16 +56,14 @@ inline namespace fundamentals_v1 {
7956 } // namespace fundamentals_v1
8057 } // namespace experimental
8158
82 template<class R, class... ArgTypes, class Alloc>
83 struct uses_allocator<experimental::function<R(ArgTypes...)>, Alloc>;
84
8559} // namespace std
8660
8761*/
8862
63#include <__assert> // all public C++ headers provide the assertion handler
8964#include <__debug>
65#include <__functional/identity.h>
9066#include <__memory/uses_allocator.h>
91#include <algorithm>
9267#include <array>
9368#include <experimental/__config>
9469#include <functional>
......@@ -97,7 +72,7 @@ inline namespace fundamentals_v1 {
9772#include <vector>
9873
9974#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
100#pragma GCC system_header
75# pragma GCC system_header
10176#endif
10277
10378_LIBCPP_PUSH_MACROS
......@@ -105,10 +80,20 @@ _LIBCPP_PUSH_MACROS
10580
10681_LIBCPP_BEGIN_NAMESPACE_LFTS
10782
83#ifdef _LIBCPP_NO_EXPERIMENTAL_DEPRECATION_WARNING_SEARCHERS
84# define _LIBCPP_DEPRECATED_DEFAULT_SEARCHER
85# define _LIBCPP_DEPRECATED_BOYER_MOORE_SEARCHER
86# define _LIBCPP_DEPRECATED_BOYER_MOORE_HORSPOOL_SEARCHER
87#else
88# define _LIBCPP_DEPRECATED_DEFAULT_SEARCHER _LIBCPP_DEPRECATED_("std::exprerimental::default_searcher will be removed in LLVM 17. Use std::default_searcher instead")
89# define _LIBCPP_DEPRECATED_BOYER_MOORE_SEARCHER _LIBCPP_DEPRECATED_("std::exprerimental::boyer_moore_searcher will be removed in LLVM 17. Use std::boyer_moore_searcher instead")
90# define _LIBCPP_DEPRECATED_BOYER_MOORE_HORSPOOL_SEARCHER _LIBCPP_DEPRECATED_("std::exprerimental::boyer_moore_horspool_searcher will be removed in LLVM 17. Use std::boyer_moore_horspool_searcher instead")
91#endif
92
10893#if _LIBCPP_STD_VER > 11
10994// default searcher
11095template<class _ForwardIterator, class _BinaryPredicate = equal_to<>>
111class _LIBCPP_TEMPLATE_VIS default_searcher {
96class _LIBCPP_DEPRECATED_DEFAULT_SEARCHER _LIBCPP_TEMPLATE_VIS default_searcher {
11297public:
11398 _LIBCPP_INLINE_VISIBILITY
11499 default_searcher(_ForwardIterator __f, _ForwardIterator __l,
......@@ -120,9 +105,8 @@ public:
120105 pair<_ForwardIterator2, _ForwardIterator2>
121106 operator () (_ForwardIterator2 __f, _ForwardIterator2 __l) const
122107 {
123 return _VSTD::__search(__f, __l, __first_, __last_, __pred_,
124 typename iterator_traits<_ForwardIterator>::iterator_category(),
125 typename iterator_traits<_ForwardIterator2>::iterator_category());
108 auto __proj = __identity();
109 return std::__search_impl(__f, __l, __first_, __last_, __pred_, __proj, __proj);
126110 }
127111
128112private:
......@@ -132,7 +116,7 @@ private:
132116 };
133117
134118template<class _ForwardIterator, class _BinaryPredicate = equal_to<>>
135_LIBCPP_INLINE_VISIBILITY
119_LIBCPP_DEPRECATED_DEFAULT_SEARCHER _LIBCPP_INLINE_VISIBILITY
136120default_searcher<_ForwardIterator, _BinaryPredicate>
137121make_default_searcher( _ForwardIterator __f, _ForwardIterator __l, _BinaryPredicate __p = _BinaryPredicate ())
138122{
......@@ -144,7 +128,6 @@ template<class _Key, class _Value, class _Hash, class _BinaryPredicate, bool /*u
144128// General case for BM data searching; use a map
145129template<class _Key, typename _Value, class _Hash, class _BinaryPredicate>
146130class _BMSkipTable<_Key, _Value, _Hash, _BinaryPredicate, false> {
147public: // TODO private:
148131 typedef _Value value_type;
149132 typedef _Key key_type;
150133
......@@ -179,7 +162,7 @@ private:
179162 typedef _Key key_type;
180163
181164 typedef typename make_unsigned<key_type>::type unsigned_key_type;
182 typedef std::array<value_type, numeric_limits<unsigned_key_type>::max()> skip_map;
165 typedef std::array<value_type, 256> skip_map;
183166 skip_map __table;
184167
185168public:
......@@ -206,7 +189,7 @@ public:
206189template <class _RandomAccessIterator1,
207190 class _Hash = hash<typename iterator_traits<_RandomAccessIterator1>::value_type>,
208191 class _BinaryPredicate = equal_to<>>
209class _LIBCPP_TEMPLATE_VIS boyer_moore_searcher {
192class _LIBCPP_DEPRECATED_BOYER_MOORE_SEARCHER _LIBCPP_TEMPLATE_VIS boyer_moore_searcher {
210193private:
211194 typedef typename std::iterator_traits<_RandomAccessIterator1>::difference_type difference_type;
212195 typedef typename std::iterator_traits<_RandomAccessIterator1>::value_type value_type;
......@@ -236,11 +219,9 @@ public:
236219 pair<_RandomAccessIterator2, _RandomAccessIterator2>
237220 operator ()(_RandomAccessIterator2 __f, _RandomAccessIterator2 __l) const
238221 {
239 static_assert ( std::is_same<
240 typename std::__uncvref<typename std::iterator_traits<_RandomAccessIterator1>::value_type>::type,
241 typename std::__uncvref<typename std::iterator_traits<_RandomAccessIterator2>::value_type>::type
242 >::value,
243 "Corpus and Pattern iterators must point to the same type" );
222 static_assert(__is_same_uncvref<typename iterator_traits<_RandomAccessIterator1>::value_type,
223 typename iterator_traits<_RandomAccessIterator2>::value_type>::value,
224 "Corpus and Pattern iterators must point to the same type");
244225
245226 if (__f == __l ) return make_pair(__l, __l); // empty corpus
246227 if (__first_ == __last_) return make_pair(__f, __f); // empty pattern
......@@ -253,7 +234,7 @@ public:
253234 return this->__search(__f, __l);
254235 }
255236
256public: // TODO private:
237private:
257238 _RandomAccessIterator1 __first_;
258239 _RandomAccessIterator1 __last_;
259240 _BinaryPredicate __pred_;
......@@ -320,7 +301,7 @@ public: // TODO private:
320301 vector<difference_type> & __suffix = *__suffix_.get();
321302 if (__count > 0)
322303 {
323 vector<value_type> __scratch(__count);
304 vector<difference_type> __scratch(__count);
324305
325306 __compute_bm_prefix(__f, __l, __pred, __scratch);
326307 for ( size_t __i = 0; __i <= __count; __i++ )
......@@ -345,7 +326,7 @@ public: // TODO private:
345326template<class _RandomAccessIterator,
346327 class _Hash = hash<typename iterator_traits<_RandomAccessIterator>::value_type>,
347328 class _BinaryPredicate = equal_to<>>
348_LIBCPP_INLINE_VISIBILITY
329_LIBCPP_DEPRECATED_BOYER_MOORE_SEARCHER _LIBCPP_INLINE_VISIBILITY
349330boyer_moore_searcher<_RandomAccessIterator, _Hash, _BinaryPredicate>
350331make_boyer_moore_searcher( _RandomAccessIterator __f, _RandomAccessIterator __l,
351332 _Hash __hf = _Hash(), _BinaryPredicate __p = _BinaryPredicate ())
......@@ -357,7 +338,7 @@ make_boyer_moore_searcher( _RandomAccessIterator __f, _RandomAccessIterator __l,
357338template <class _RandomAccessIterator1,
358339 class _Hash = hash<typename iterator_traits<_RandomAccessIterator1>::value_type>,
359340 class _BinaryPredicate = equal_to<>>
360class _LIBCPP_TEMPLATE_VIS boyer_moore_horspool_searcher {
341class _LIBCPP_DEPRECATED_BOYER_MOORE_HORSPOOL_SEARCHER _LIBCPP_TEMPLATE_VIS boyer_moore_horspool_searcher {
361342private:
362343 typedef typename std::iterator_traits<_RandomAccessIterator1>::difference_type difference_type;
363344 typedef typename std::iterator_traits<_RandomAccessIterator1>::value_type value_type;
......@@ -388,11 +369,9 @@ public:
388369 pair<_RandomAccessIterator2, _RandomAccessIterator2>
389370 operator ()(_RandomAccessIterator2 __f, _RandomAccessIterator2 __l) const
390371 {
391 static_assert ( std::is_same<
392 typename std::__uncvref<typename std::iterator_traits<_RandomAccessIterator1>::value_type>::type,
393 typename std::__uncvref<typename std::iterator_traits<_RandomAccessIterator2>::value_type>::type
394 >::value,
395 "Corpus and Pattern iterators must point to the same type" );
372 static_assert(__is_same_uncvref<typename std::iterator_traits<_RandomAccessIterator1>::value_type,
373 typename std::iterator_traits<_RandomAccessIterator2>::value_type>::value,
374 "Corpus and Pattern iterators must point to the same type");
396375
397376 if (__f == __l ) return make_pair(__l, __l); // empty corpus
398377 if (__first_ == __last_) return make_pair(__f, __f); // empty pattern
......@@ -440,7 +419,7 @@ private:
440419template<class _RandomAccessIterator,
441420 class _Hash = hash<typename iterator_traits<_RandomAccessIterator>::value_type>,
442421 class _BinaryPredicate = equal_to<>>
443_LIBCPP_INLINE_VISIBILITY
422_LIBCPP_DEPRECATED_BOYER_MOORE_HORSPOOL_SEARCHER _LIBCPP_INLINE_VISIBILITY
444423boyer_moore_horspool_searcher<_RandomAccessIterator, _Hash, _BinaryPredicate>
445424make_boyer_moore_horspool_searcher( _RandomAccessIterator __f, _RandomAccessIterator __l,
446425 _Hash __hf = _Hash(), _BinaryPredicate __p = _BinaryPredicate ())
lib/libcxx/include/experimental/iterator+3-1
......@@ -52,14 +52,16 @@ namespace std {
5252
5353*/
5454
55#include <__assert> // all public C++ headers provide the assertion handler
5556#include <__memory/addressof.h>
5657#include <__utility/forward.h>
5758#include <__utility/move.h>
5859#include <experimental/__config>
60#include <iosfwd> // char_traits
5961#include <iterator>
6062
6163#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
62#pragma GCC system_header
64# pragma GCC system_header
6365#endif
6466
6567#if _LIBCPP_STD_VER > 11
lib/libcxx/include/experimental/list+3-1
......@@ -9,6 +9,7 @@
99
1010#ifndef _LIBCPP_EXPERIMENTAL_LIST
1111#define _LIBCPP_EXPERIMENTAL_LIST
12
1213/*
1314 experimental/list synopsis
1415
......@@ -28,12 +29,13 @@ namespace pmr {
2829
2930 */
3031
32#include <__assert> // all public C++ headers provide the assertion handler
3133#include <experimental/__config>
3234#include <experimental/memory_resource>
3335#include <list>
3436
3537#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
36#pragma GCC system_header
38# pragma GCC system_header
3739#endif
3840
3941_LIBCPP_BEGIN_NAMESPACE_LFTS_PMR
lib/libcxx/include/experimental/map+3-1
......@@ -9,6 +9,7 @@
99
1010#ifndef _LIBCPP_EXPERIMENTAL_MAP
1111#define _LIBCPP_EXPERIMENTAL_MAP
12
1213/*
1314 experimental/map synopsis
1415
......@@ -33,12 +34,13 @@ namespace pmr {
3334
3435 */
3536
37#include <__assert> // all public C++ headers provide the assertion handler
3638#include <experimental/__config>
3739#include <experimental/memory_resource>
3840#include <map>
3941
4042#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
41#pragma GCC system_header
43# pragma GCC system_header
4244#endif
4345
4446_LIBCPP_BEGIN_NAMESPACE_LFTS_PMR
lib/libcxx/include/experimental/memory_resource+3-3
......@@ -64,8 +64,9 @@ namespace pmr {
6464
6565 */
6666
67#include <__debug>
67#include <__assert> // all public C++ headers provide the assertion handler
6868#include <__tuple>
69#include <__utility/move.h>
6970#include <cstddef>
7071#include <cstdlib>
7172#include <experimental/__config>
......@@ -75,10 +76,9 @@ namespace pmr {
7576#include <new>
7677#include <stdexcept>
7778#include <type_traits>
78#include <utility>
7979
8080#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
81#pragma GCC system_header
81# pragma GCC system_header
8282#endif
8383
8484_LIBCPP_PUSH_MACROS
lib/libcxx/include/experimental/propagate_const+7-3
......@@ -9,6 +9,7 @@
99
1010#ifndef _LIBCPP_EXPERIMENTAL_PROPAGATE_CONST
1111#define _LIBCPP_EXPERIMENTAL_PROPAGATE_CONST
12
1213/*
1314 propagate_const synopsis
1415
......@@ -106,13 +107,16 @@
106107
107108*/
108109
110#include <__assert> // all public C++ headers provide the assertion handler
111#include <__functional/operations.h>
112#include <__utility/forward.h>
113#include <__utility/move.h>
114#include <__utility/swap.h>
109115#include <experimental/__config>
110#include <functional>
111116#include <type_traits>
112#include <utility>
113117
114118#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
115#pragma GCC system_header
119# pragma GCC system_header
116120#endif
117121
118122#if _LIBCPP_STD_VER > 11
lib/libcxx/include/experimental/regex+3-1
......@@ -9,6 +9,7 @@
99
1010#ifndef _LIBCPP_EXPERIMENTAL_REGEX
1111#define _LIBCPP_EXPERIMENTAL_REGEX
12
1213/*
1314 experimental/regex synopsis
1415
......@@ -35,13 +36,14 @@ namespace pmr {
3536
3637 */
3738
39#include <__assert> // all public C++ headers provide the assertion handler
3840#include <experimental/__config>
3941#include <experimental/memory_resource>
4042#include <experimental/string>
4143#include <regex>
4244
4345#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
44#pragma GCC system_header
46# pragma GCC system_header
4547#endif
4648
4749_LIBCPP_BEGIN_NAMESPACE_LFTS_PMR
lib/libcxx/include/experimental/set+3-1
......@@ -9,6 +9,7 @@
99
1010#ifndef _LIBCPP_EXPERIMENTAL_SET
1111#define _LIBCPP_EXPERIMENTAL_SET
12
1213/*
1314 experimental/set synopsis
1415
......@@ -33,12 +34,13 @@ namespace pmr {
3334
3435 */
3536
37#include <__assert> // all public C++ headers provide the assertion handler
3638#include <experimental/__config>
3739#include <experimental/memory_resource>
3840#include <set>
3941
4042#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
41#pragma GCC system_header
43# pragma GCC system_header
4244#endif
4345
4446_LIBCPP_BEGIN_NAMESPACE_LFTS_PMR
lib/libcxx/include/experimental/simd+19-9
......@@ -649,14 +649,20 @@ public:
649649
650650*/
651651
652#include <algorithm>
652#include <__assert> // all public C++ headers provide the assertion handler
653#include <__functional/operations.h>
653654#include <array>
654655#include <cstddef>
655656#include <experimental/__config>
656#include <functional>
657#include <tuple>
658
659#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
660# include <algorithm>
661# include <functional>
662#endif
657663
658664#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
659#pragma GCC system_header
665# pragma GCC system_header
660666#endif
661667
662668_LIBCPP_PUSH_MACROS
......@@ -1236,32 +1242,32 @@ _Tp reduce(const simd<_Tp, _Abi>&, _BinaryOp = _BinaryOp());
12361242template <class _MaskType, class _SimdType, class _BinaryOp>
12371243typename _SimdType::value_type
12381244reduce(const const_where_expression<_MaskType, _SimdType>&,
1239 typename _SimdType::value_type neutral_element, _BinaryOp binary_op);
1245 typename _SimdType::value_type __neutral_element, _BinaryOp);
12401246
12411247template <class _MaskType, class _SimdType>
12421248typename _SimdType::value_type
12431249reduce(const const_where_expression<_MaskType, _SimdType>&,
1244 plus<typename _SimdType::value_type> binary_op = {});
1250 plus<typename _SimdType::value_type> = {});
12451251
12461252template <class _MaskType, class _SimdType>
12471253typename _SimdType::value_type
12481254reduce(const const_where_expression<_MaskType, _SimdType>&,
1249 multiplies<typename _SimdType::value_type> binary_op);
1255 multiplies<typename _SimdType::value_type>);
12501256
12511257template <class _MaskType, class _SimdType>
12521258typename _SimdType::value_type
12531259reduce(const const_where_expression<_MaskType, _SimdType>&,
1254 bit_and<typename _SimdType::value_type> binary_op);
1260 bit_and<typename _SimdType::value_type>);
12551261
12561262template <class _MaskType, class _SimdType>
12571263typename _SimdType::value_type
12581264reduce(const const_where_expression<_MaskType, _SimdType>&,
1259 bit_or<typename _SimdType::value_type> binary_op);
1265 bit_or<typename _SimdType::value_type>);
12601266
12611267template <class _MaskType, class _SimdType>
12621268typename _SimdType::value_type
12631269reduce(const const_where_expression<_MaskType, _SimdType>&,
1264 bit_xor<typename _SimdType::value_type> binary_op);
1270 bit_xor<typename _SimdType::value_type>);
12651271
12661272template <class _Tp, class _Abi>
12671273_Tp hmin(const simd<_Tp, _Abi>&);
......@@ -1471,6 +1477,7 @@ public:
14711477 simd operator+() const;
14721478 simd operator-() const;
14731479
1480#if 0
14741481 // binary operators [simd.binary]
14751482 friend simd operator+(const simd&, const simd&);
14761483 friend simd operator-(const simd&, const simd&);
......@@ -1507,6 +1514,7 @@ public:
15071514 friend mask_type operator<=(const simd&, const simd&);
15081515 friend mask_type operator>(const simd&, const simd&);
15091516 friend mask_type operator<(const simd&, const simd&);
1517#endif
15101518};
15111519
15121520// [simd.mask.class]
......@@ -1546,6 +1554,7 @@ public:
15461554 // unary operators [simd.mask.unary]
15471555 simd_mask operator!() const noexcept;
15481556
1557#if 0
15491558 // simd_mask binary operators [simd.mask.binary]
15501559 friend simd_mask operator&&(const simd_mask&, const simd_mask&) noexcept;
15511560 friend simd_mask operator||(const simd_mask&, const simd_mask&) noexcept;
......@@ -1561,6 +1570,7 @@ public:
15611570 // simd_mask compares [simd.mask.comparison]
15621571 friend simd_mask operator==(const simd_mask&, const simd_mask&) noexcept;
15631572 friend simd_mask operator!=(const simd_mask&, const simd_mask&) noexcept;
1573#endif
15641574};
15651575
15661576#endif // _LIBCPP_STD_VER >= 17
lib/libcxx/include/experimental/string+3-1
......@@ -9,6 +9,7 @@
99
1010#ifndef _LIBCPP_EXPERIMENTAL_STRING
1111#define _LIBCPP_EXPERIMENTAL_STRING
12
1213/*
1314 experimental/string synopsis
1415
......@@ -37,12 +38,13 @@ namespace pmr {
3738
3839 */
3940
41#include <__assert> // all public C++ headers provide the assertion handler
4042#include <experimental/__config>
4143#include <experimental/memory_resource>
4244#include <string>
4345
4446#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
45#pragma GCC system_header
47# pragma GCC system_header
4648#endif
4749
4850_LIBCPP_BEGIN_NAMESPACE_LFTS_PMR
lib/libcxx/include/experimental/type_traits+2-1
......@@ -68,6 +68,7 @@ inline namespace fundamentals_v1 {
6868
6969 */
7070
71#include <__assert> // all public C++ headers provide the assertion handler
7172#include <experimental/__config>
7273
7374#if _LIBCPP_STD_VER > 11
......@@ -76,7 +77,7 @@ inline namespace fundamentals_v1 {
7677#include <type_traits>
7778
7879#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
79#pragma GCC system_header
80# pragma GCC system_header
8081#endif
8182
8283_LIBCPP_BEGIN_NAMESPACE_LFTS
lib/libcxx/include/experimental/unordered_map+11-1
......@@ -9,6 +9,7 @@
99
1010#ifndef _LIBCPP_EXPERIMENTAL_UNORDERED_MAP
1111#define _LIBCPP_EXPERIMENTAL_UNORDERED_MAP
12
1213/*
1314 experimental/unordered_map synopsis
1415
......@@ -39,12 +40,21 @@ namespace pmr {
3940
4041 */
4142
43#include <__assert> // all public C++ headers provide the assertion handler
4244#include <experimental/__config>
4345#include <experimental/memory_resource>
4446#include <unordered_map>
4547
48#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
49# include <algorithm>
50# include <array>
51# include <bit>
52# include <functional>
53# include <vector>
54#endif
55
4656#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
47#pragma GCC system_header
57# pragma GCC system_header
4858#endif
4959
5060_LIBCPP_BEGIN_NAMESPACE_LFTS_PMR
lib/libcxx/include/experimental/unordered_set+3-1
......@@ -9,6 +9,7 @@
99
1010#ifndef _LIBCPP_EXPERIMENTAL_UNORDERED_SET
1111#define _LIBCPP_EXPERIMENTAL_UNORDERED_SET
12
1213/*
1314 experimental/unordered_set synopsis
1415
......@@ -33,12 +34,13 @@ namespace pmr {
3334
3435 */
3536
37#include <__assert> // all public C++ headers provide the assertion handler
3638#include <experimental/__config>
3739#include <experimental/memory_resource>
3840#include <unordered_set>
3941
4042#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
41#pragma GCC system_header
43# pragma GCC system_header
4244#endif
4345
4446_LIBCPP_BEGIN_NAMESPACE_LFTS_PMR
lib/libcxx/include/experimental/utility+2-1
......@@ -30,11 +30,12 @@ inline namespace fundamentals_v1 {
3030
3131 */
3232
33#include <__assert> // all public C++ headers provide the assertion handler
3334#include <experimental/__config>
3435#include <utility>
3536
3637#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
37#pragma GCC system_header
38# pragma GCC system_header
3839#endif
3940
4041_LIBCPP_BEGIN_NAMESPACE_LFTS
lib/libcxx/include/experimental/vector+3-1
......@@ -9,6 +9,7 @@
99
1010#ifndef _LIBCPP_EXPERIMENTAL_VECTOR
1111#define _LIBCPP_EXPERIMENTAL_VECTOR
12
1213/*
1314 experimental/vector synopsis
1415
......@@ -28,12 +29,13 @@ namespace pmr {
2829
2930 */
3031
32#include <__assert> // all public C++ headers provide the assertion handler
3133#include <experimental/__config>
3234#include <experimental/memory_resource>
3335#include <vector>
3436
3537#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
36#pragma GCC system_header
38# pragma GCC system_header
3739#endif
3840
3941_LIBCPP_BEGIN_NAMESPACE_LFTS_PMR
lib/libcxx/include/ext/__hash+13-13
......@@ -10,9 +10,9 @@
1010#ifndef _LIBCPP_EXT_HASH
1111#define _LIBCPP_EXT_HASH
1212
13#pragma GCC system_header
13# pragma GCC system_header
1414
15#include <__string>
15#include <__config>
1616#include <cstring>
1717#include <string>
1818
......@@ -21,7 +21,7 @@ namespace __gnu_cxx {
2121template <typename _Tp> struct _LIBCPP_TEMPLATE_VIS hash { };
2222
2323template <> struct _LIBCPP_TEMPLATE_VIS hash<const char*>
24 : public std::unary_function<const char*, size_t>
24 : public std::__unary_function<const char*, size_t>
2525{
2626 _LIBCPP_INLINE_VISIBILITY
2727 size_t operator()(const char *__c) const _NOEXCEPT
......@@ -31,7 +31,7 @@ template <> struct _LIBCPP_TEMPLATE_VIS hash<const char*>
3131};
3232
3333template <> struct _LIBCPP_TEMPLATE_VIS hash<char *>
34 : public std::unary_function<char*, size_t>
34 : public std::__unary_function<char*, size_t>
3535{
3636 _LIBCPP_INLINE_VISIBILITY
3737 size_t operator()(char *__c) const _NOEXCEPT
......@@ -41,7 +41,7 @@ template <> struct _LIBCPP_TEMPLATE_VIS hash<char *>
4141};
4242
4343template <> struct _LIBCPP_TEMPLATE_VIS hash<char>
44 : public std::unary_function<char, size_t>
44 : public std::__unary_function<char, size_t>
4545{
4646 _LIBCPP_INLINE_VISIBILITY
4747 size_t operator()(char __c) const _NOEXCEPT
......@@ -51,7 +51,7 @@ template <> struct _LIBCPP_TEMPLATE_VIS hash<char>
5151};
5252
5353template <> struct _LIBCPP_TEMPLATE_VIS hash<signed char>
54 : public std::unary_function<signed char, size_t>
54 : public std::__unary_function<signed char, size_t>
5555{
5656 _LIBCPP_INLINE_VISIBILITY
5757 size_t operator()(signed char __c) const _NOEXCEPT
......@@ -61,7 +61,7 @@ template <> struct _LIBCPP_TEMPLATE_VIS hash<signed char>
6161};
6262
6363template <> struct _LIBCPP_TEMPLATE_VIS hash<unsigned char>
64 : public std::unary_function<unsigned char, size_t>
64 : public std::__unary_function<unsigned char, size_t>
6565{
6666 _LIBCPP_INLINE_VISIBILITY
6767 size_t operator()(unsigned char __c) const _NOEXCEPT
......@@ -71,7 +71,7 @@ template <> struct _LIBCPP_TEMPLATE_VIS hash<unsigned char>
7171};
7272
7373template <> struct _LIBCPP_TEMPLATE_VIS hash<short>
74 : public std::unary_function<short, size_t>
74 : public std::__unary_function<short, size_t>
7575{
7676 _LIBCPP_INLINE_VISIBILITY
7777 size_t operator()(short __c) const _NOEXCEPT
......@@ -81,7 +81,7 @@ template <> struct _LIBCPP_TEMPLATE_VIS hash<short>
8181};
8282
8383template <> struct _LIBCPP_TEMPLATE_VIS hash<unsigned short>
84 : public std::unary_function<unsigned short, size_t>
84 : public std::__unary_function<unsigned short, size_t>
8585{
8686 _LIBCPP_INLINE_VISIBILITY
8787 size_t operator()(unsigned short __c) const _NOEXCEPT
......@@ -91,7 +91,7 @@ template <> struct _LIBCPP_TEMPLATE_VIS hash<unsigned short>
9191};
9292
9393template <> struct _LIBCPP_TEMPLATE_VIS hash<int>
94 : public std::unary_function<int, size_t>
94 : public std::__unary_function<int, size_t>
9595{
9696 _LIBCPP_INLINE_VISIBILITY
9797 size_t operator()(int __c) const _NOEXCEPT
......@@ -101,7 +101,7 @@ template <> struct _LIBCPP_TEMPLATE_VIS hash<int>
101101};
102102
103103template <> struct _LIBCPP_TEMPLATE_VIS hash<unsigned int>
104 : public std::unary_function<unsigned int, size_t>
104 : public std::__unary_function<unsigned int, size_t>
105105{
106106 _LIBCPP_INLINE_VISIBILITY
107107 size_t operator()(unsigned int __c) const _NOEXCEPT
......@@ -111,7 +111,7 @@ template <> struct _LIBCPP_TEMPLATE_VIS hash<unsigned int>
111111};
112112
113113template <> struct _LIBCPP_TEMPLATE_VIS hash<long>
114 : public std::unary_function<long, size_t>
114 : public std::__unary_function<long, size_t>
115115{
116116 _LIBCPP_INLINE_VISIBILITY
117117 size_t operator()(long __c) const _NOEXCEPT
......@@ -121,7 +121,7 @@ template <> struct _LIBCPP_TEMPLATE_VIS hash<long>
121121};
122122
123123template <> struct _LIBCPP_TEMPLATE_VIS hash<unsigned long>
124 : public std::unary_function<unsigned long, size_t>
124 : public std::__unary_function<unsigned long, size_t>
125125{
126126 _LIBCPP_INLINE_VISIBILITY
127127 size_t operator()(unsigned long __c) const _NOEXCEPT
lib/libcxx/include/ext/hash_map+19-13
......@@ -201,13 +201,19 @@ template <class Key, class T, class Hash, class Pred, class Alloc>
201201
202202*/
203203
204#include <__assert> // all public C++ headers provide the assertion handler
204205#include <__config>
205206#include <__hash_table>
207#include <algorithm>
206208#include <ext/__hash>
207209#include <functional>
208210#include <stdexcept>
209211#include <type_traits>
210212
213#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
214# include <iterator>
215#endif
216
211217#if defined(__DEPRECATED) && __DEPRECATED
212218#if defined(_LIBCPP_WARNING)
213219 _LIBCPP_WARNING("Use of the header <ext/hash_map> is deprecated. Migrate to <unordered_map>")
......@@ -217,7 +223,7 @@ template <class Key, class T, class Hash, class Pred, class Alloc>
217223#endif
218224
219225#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
220#pragma GCC system_header
226# pragma GCC system_header
221227#endif
222228
223229namespace __gnu_cxx {
......@@ -599,7 +605,7 @@ public:
599605 {return __table_.bucket_size(__n);}
600606
601607 _LIBCPP_INLINE_VISIBILITY
602 void resize(size_type __n) {__table_.rehash(__n);}
608 void resize(size_type __n) {__table_.__rehash_unique(__n);}
603609
604610private:
605611 __node_holder __construct_node(const key_type& __k);
......@@ -610,7 +616,7 @@ hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map(
610616 size_type __n, const hasher& __hf, const key_equal& __eql)
611617 : __table_(__hf, __eql)
612618{
613 __table_.rehash(__n);
619 __table_.__rehash_unique(__n);
614620}
615621
616622template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
......@@ -619,7 +625,7 @@ hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map(
619625 const allocator_type& __a)
620626 : __table_(__hf, __eql, __a)
621627{
622 __table_.rehash(__n);
628 __table_.__rehash_unique(__n);
623629}
624630
625631template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
......@@ -637,7 +643,7 @@ hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map(
637643 const hasher& __hf, const key_equal& __eql)
638644 : __table_(__hf, __eql)
639645{
640 __table_.rehash(__n);
646 __table_.__rehash_unique(__n);
641647 insert(__first, __last);
642648}
643649
......@@ -648,7 +654,7 @@ hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map(
648654 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
649655 : __table_(__hf, __eql, __a)
650656{
651 __table_.rehash(__n);
657 __table_.__rehash_unique(__n);
652658 insert(__first, __last);
653659}
654660
......@@ -657,7 +663,7 @@ hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map(
657663 const hash_map& __u)
658664 : __table_(__u.__table_)
659665{
660 __table_.rehash(__u.bucket_count());
666 __table_.__rehash_unique(__u.bucket_count());
661667 insert(__u.begin(), __u.end());
662668}
663669
......@@ -868,7 +874,7 @@ public:
868874 {return __table_.bucket_size(__n);}
869875
870876 _LIBCPP_INLINE_VISIBILITY
871 void resize(size_type __n) {__table_.rehash(__n);}
877 void resize(size_type __n) {__table_.__rehash_multi(__n);}
872878};
873879
874880template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
......@@ -876,7 +882,7 @@ hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap(
876882 size_type __n, const hasher& __hf, const key_equal& __eql)
877883 : __table_(__hf, __eql)
878884{
879 __table_.rehash(__n);
885 __table_.__rehash_multi(__n);
880886}
881887
882888template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
......@@ -885,7 +891,7 @@ hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap(
885891 const allocator_type& __a)
886892 : __table_(__hf, __eql, __a)
887893{
888 __table_.rehash(__n);
894 __table_.__rehash_multi(__n);
889895}
890896
891897template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
......@@ -903,7 +909,7 @@ hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap(
903909 const hasher& __hf, const key_equal& __eql)
904910 : __table_(__hf, __eql)
905911{
906 __table_.rehash(__n);
912 __table_.__rehash_multi(__n);
907913 insert(__first, __last);
908914}
909915
......@@ -914,7 +920,7 @@ hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap(
914920 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
915921 : __table_(__hf, __eql, __a)
916922{
917 __table_.rehash(__n);
923 __table_.__rehash_multi(__n);
918924 insert(__first, __last);
919925}
920926
......@@ -923,7 +929,7 @@ hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap(
923929 const hash_multimap& __u)
924930 : __table_(__u.__table_)
925931{
926 __table_.rehash(__u.bucket_count());
932 __table_.__rehash_multi(__u.bucket_count());
927933 insert(__u.begin(), __u.end());
928934}
929935
lib/libcxx/include/ext/hash_set+19-13
......@@ -192,11 +192,17 @@ template <class Value, class Hash, class Pred, class Alloc>
192192
193193*/
194194
195#include <__assert> // all public C++ headers provide the assertion handler
195196#include <__config>
196197#include <__hash_table>
198#include <algorithm>
197199#include <ext/__hash>
198200#include <functional>
199201
202#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
203# include <iterator>
204#endif
205
200206#if defined(__DEPRECATED) && __DEPRECATED
201207#if defined(_LIBCPP_WARNING)
202208 _LIBCPP_WARNING("Use of the header <ext/hash_set> is deprecated. Migrate to <unordered_set>")
......@@ -206,7 +212,7 @@ template <class Value, class Hash, class Pred, class Alloc>
206212#endif
207213
208214#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
209#pragma GCC system_header
215# pragma GCC system_header
210216#endif
211217
212218namespace __gnu_cxx {
......@@ -327,7 +333,7 @@ public:
327333 size_type elems_in_bucket(size_type __n) const {return __table_.bucket_size(__n);}
328334
329335 _LIBCPP_INLINE_VISIBILITY
330 void resize(size_type __n) {__table_.rehash(__n);}
336 void resize(size_type __n) {__table_.__rehash_unique(__n);}
331337};
332338
333339template <class _Value, class _Hash, class _Pred, class _Alloc>
......@@ -335,7 +341,7 @@ hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(size_type __n,
335341 const hasher& __hf, const key_equal& __eql)
336342 : __table_(__hf, __eql)
337343{
338 __table_.rehash(__n);
344 __table_.__rehash_unique(__n);
339345}
340346
341347template <class _Value, class _Hash, class _Pred, class _Alloc>
......@@ -343,7 +349,7 @@ hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(size_type __n,
343349 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
344350 : __table_(__hf, __eql, __a)
345351{
346 __table_.rehash(__n);
352 __table_.__rehash_unique(__n);
347353}
348354
349355template <class _Value, class _Hash, class _Pred, class _Alloc>
......@@ -361,7 +367,7 @@ hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(
361367 const hasher& __hf, const key_equal& __eql)
362368 : __table_(__hf, __eql)
363369{
364 __table_.rehash(__n);
370 __table_.__rehash_unique(__n);
365371 insert(__first, __last);
366372}
367373
......@@ -372,7 +378,7 @@ hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(
372378 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
373379 : __table_(__hf, __eql, __a)
374380{
375 __table_.rehash(__n);
381 __table_.__rehash_unique(__n);
376382 insert(__first, __last);
377383}
378384
......@@ -381,7 +387,7 @@ hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(
381387 const hash_set& __u)
382388 : __table_(__u.__table_)
383389{
384 __table_.rehash(__u.bucket_count());
390 __table_.__rehash_unique(__u.bucket_count());
385391 insert(__u.begin(), __u.end());
386392}
387393
......@@ -547,7 +553,7 @@ public:
547553 size_type elems_in_bucket(size_type __n) const {return __table_.bucket_size(__n);}
548554
549555 _LIBCPP_INLINE_VISIBILITY
550 void resize(size_type __n) {__table_.rehash(__n);}
556 void resize(size_type __n) {__table_.__rehash_multi(__n);}
551557};
552558
553559template <class _Value, class _Hash, class _Pred, class _Alloc>
......@@ -555,7 +561,7 @@ hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset(
555561 size_type __n, const hasher& __hf, const key_equal& __eql)
556562 : __table_(__hf, __eql)
557563{
558 __table_.rehash(__n);
564 __table_.__rehash_multi(__n);
559565}
560566
561567template <class _Value, class _Hash, class _Pred, class _Alloc>
......@@ -564,7 +570,7 @@ hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset(
564570 const allocator_type& __a)
565571 : __table_(__hf, __eql, __a)
566572{
567 __table_.rehash(__n);
573 __table_.__rehash_multi(__n);
568574}
569575
570576template <class _Value, class _Hash, class _Pred, class _Alloc>
......@@ -582,7 +588,7 @@ hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset(
582588 const hasher& __hf, const key_equal& __eql)
583589 : __table_(__hf, __eql)
584590{
585 __table_.rehash(__n);
591 __table_.__rehash_multi(__n);
586592 insert(__first, __last);
587593}
588594
......@@ -593,7 +599,7 @@ hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset(
593599 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
594600 : __table_(__hf, __eql, __a)
595601{
596 __table_.rehash(__n);
602 __table_.__rehash_multi(__n);
597603 insert(__first, __last);
598604}
599605
......@@ -602,7 +608,7 @@ hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset(
602608 const hash_multiset& __u)
603609 : __table_(__u.__table_)
604610{
605 __table_.rehash(__u.bucket_count());
611 __table_.__rehash_multi(__u.bucket_count());
606612 insert(__u.begin(), __u.end());
607613}
608614
lib/libcxx/include/fenv.h+1-1
......@@ -53,7 +53,7 @@ int feupdateenv(const fenv_t* envp);
5353#include <__config>
5454
5555#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
56#pragma GCC system_header
56# pragma GCC system_header
5757#endif
5858
5959#include_next <fenv.h>
lib/libcxx/include/filesystem+7-3
......@@ -8,6 +8,7 @@
88//===----------------------------------------------------------------------===//
99#ifndef _LIBCPP_FILESYSTEM
1010#define _LIBCPP_FILESYSTEM
11
1112/*
1213 filesystem synopsis
1314
......@@ -238,6 +239,7 @@ inline constexpr bool std::ranges::enable_view<std::filesystem::recursive_direct
238239
239240*/
240241
242#include <__assert> // all public C++ headers provide the assertion handler
241243#include <__config>
242244#include <__filesystem/copy_options.h>
243245#include <__filesystem/directory_entry.h>
......@@ -255,15 +257,17 @@ inline constexpr bool std::ranges::enable_view<std::filesystem::recursive_direct
255257#include <__filesystem/recursive_directory_iterator.h>
256258#include <__filesystem/space_info.h>
257259#include <__filesystem/u8path.h>
258#include <compare>
259260#include <version>
260261
262// standard-mandated includes
263#include <compare>
264
261265#if defined(_LIBCPP_HAS_NO_FILESYSTEM_LIBRARY)
262# error "The Filesystem library is not supported since libc++ has been configured with LIBCXX_ENABLE_FILESYSTEM disabled"
266# error "The <filesystem> library is not supported since libc++ has been configured without support for a filesystem."
263267#endif
264268
265269#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
266#pragma GCC system_header
270# pragma GCC system_header
267271#endif
268272
269273#endif // _LIBCPP_FILESYSTEM
lib/libcxx/include/float.h+1-1
......@@ -73,7 +73,7 @@ Macros:
7373#include <__config>
7474
7575#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
76#pragma GCC system_header
76# pragma GCC system_header
7777#endif
7878
7979#include_next <float.h>
lib/libcxx/include/format+383-149
......@@ -23,15 +23,26 @@ namespace std {
2323 using format_args = basic_format_args<format_context>;
2424 using wformat_args = basic_format_args<wformat_context>;
2525
26 // [format.fmt.string], class template basic-format-string
27 template<class charT, class... Args>
28 struct basic-format-string; // exposition only
29
30 template<class... Args>
31 using format-string = // exposition only
32 basic-format-string<char, type_identity_t<Args>...>;
33 template<class... Args>
34 using wformat-string = // exposition only
35 basic-format-string<wchar_t, type_identity_t<Args>...>;
36
2637 // [format.functions], formatting functions
2738 template<class... Args>
28 string format(string_view fmt, const Args&... args);
39 string format(format-string<Args...> fmt, Args&&... args);
2940 template<class... Args>
30 wstring format(wstring_view fmt, const Args&... args);
41 wstring format(wformat-string<Args...> fmt, Args&&... args);
3142 template<class... Args>
32 string format(const locale& loc, string_view fmt, const Args&... args);
43 string format(const locale& loc, format-string<Args...> fmt, Args&&... args);
3344 template<class... Args>
34 wstring format(const locale& loc, wstring_view fmt, const Args&... args);
45 wstring format(const locale& loc, wformat-string<Args...> fmt, Args&&... args);
3546
3647 string vformat(string_view fmt, format_args args);
3748 wstring vformat(wstring_view fmt, wformat_args args);
......@@ -39,13 +50,13 @@ namespace std {
3950 wstring vformat(const locale& loc, wstring_view fmt, wformat_args args);
4051
4152 template<class Out, class... Args>
42 Out format_to(Out out, string_view fmt, const Args&... args);
53 Out format_to(Out out, format-string<Args...> fmt, Args&&... args);
4354 template<class Out, class... Args>
44 Out format_to(Out out, wstring_view fmt, const Args&... args);
55 Out format_to(Out out, wformat-string<Args...> fmt, Args&&... args);
4556 template<class Out, class... Args>
46 Out format_to(Out out, const locale& loc, string_view fmt, const Args&... args);
57 Out format_to(Out out, const locale& loc, format-string<Args...> fmt, Args&&... args);
4758 template<class Out, class... Args>
48 Out format_to(Out out, const locale& loc, wstring_view fmt, const Args&... args);
59 Out format_to(Out out, const locale& loc, wformat-string<Args...> fmt, Args&&... args);
4960
5061 template<class Out>
5162 Out vformat_to(Out out, string_view fmt, format_args args);
......@@ -64,27 +75,27 @@ namespace std {
6475 };
6576 template<class Out, class... Args>
6677 format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n,
67 string_view fmt, const Args&... args);
78 format-string<Args...> fmt, Args&&... args);
6879 template<class Out, class... Args>
6980 format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n,
70 wstring_view fmt, const Args&... args);
81 wformat-string<Args...> fmt, Args&&... args);
7182 template<class Out, class... Args>
7283 format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n,
73 const locale& loc, string_view fmt,
74 const Args&... args);
84 const locale& loc, format-string<Args...> fmt,
85 Args&&... args);
7586 template<class Out, class... Args>
7687 format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n,
77 const locale& loc, wstring_view fmt,
78 const Args&... args);
88 const locale& loc, wformat-string<Args...> fmt,
89 Args&&... args);
7990
8091 template<class... Args>
81 size_t formatted_size(string_view fmt, const Args&... args);
92 size_t formatted_size(format-string<Args...> fmt, Args&&... args);
8293 template<class... Args>
83 size_t formatted_size(wstring_view fmt, const Args&... args);
94 size_t formatted_size(wformat-string<Args...> fmt, Args&&... args);
8495 template<class... Args>
85 size_t formatted_size(const locale& loc, string_view fmt, const Args&... args);
96 size_t formatted_size(const locale& loc, format-string<Args...> fmt, Args&&... args);
8697 template<class... Args>
87 size_t formatted_size(const locale& loc, wstring_view fmt, const Args&... args);
98 size_t formatted_size(const locale& loc, wformat-string<Args...> fmt, Args&&... args);
8899
89100 // [format.formatter], formatter
90101 template<class T, class charT = char> struct formatter;
......@@ -106,10 +117,10 @@ namespace std {
106117
107118 template<class Context = format_context, class... Args>
108119 format-arg-store<Context, Args...>
109 make_format_args(const Args&... args);
120 make_format_args(Args&&... args);
110121 template<class... Args>
111122 format-arg-store<wformat_context, Args...>
112 make_wformat_args(const Args&... args);
123 make_wformat_args(Args&&... args);
113124
114125 // [format.error], class format_error
115126 class format_error;
......@@ -117,14 +128,20 @@ namespace std {
117128
118129*/
119130
131#include <__assert> // all public C++ headers provide the assertion handler
120132// Make sure all feature-test macros are available.
121133#include <version>
122// Enable the contents of the header only when libc++ was built with LIBCXX_ENABLE_INCOMPLETE_FEATURES.
134// Enable the contents of the header only when libc++ was built with experimental features enabled.
123135#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_FORMAT)
124136
137#include <__algorithm/clamp.h>
125138#include <__config>
126139#include <__debug>
140#include <__format/buffer.h>
141#include <__format/concepts.h>
142#include <__format/enable_insertable.h>
127143#include <__format/format_arg.h>
144#include <__format/format_arg_store.h>
128145#include <__format/format_args.h>
129146#include <__format/format_context.h>
130147#include <__format/format_error.h>
......@@ -140,6 +157,9 @@ namespace std {
140157#include <__format/formatter_pointer.h>
141158#include <__format/formatter_string.h>
142159#include <__format/parser_std_format_spec.h>
160#include <__format/unicode.h>
161#include <__iterator/back_insert_iterator.h>
162#include <__iterator/incrementable_traits.h>
143163#include <__variant/monostate.h>
144164#include <array>
145165#include <concepts>
......@@ -152,22 +172,13 @@ namespace std {
152172#endif
153173
154174#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
155#pragma GCC system_header
175# pragma GCC system_header
156176#endif
157177
158_LIBCPP_PUSH_MACROS
159#include <__undef_macros>
160
161178_LIBCPP_BEGIN_NAMESPACE_STD
162179
163180#if _LIBCPP_STD_VER > 17
164181
165// TODO FMT Remove this once we require compilers with proper C++20 support.
166// If the compiler has no concepts support, the format header will be disabled.
167// Without concepts support enable_if needs to be used and that too much effort
168// to support compilers with partial C++20 support.
169#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
170
171182// TODO FMT Move the implementation in this file to its own granular headers.
172183
173184// TODO FMT Evaluate which templates should be external templates. This
......@@ -180,35 +191,193 @@ using format_args = basic_format_args<format_context>;
180191using wformat_args = basic_format_args<wformat_context>;
181192#endif
182193
183template <class _Context, class... _Args>
184struct _LIBCPP_TEMPLATE_VIS __format_arg_store {
185 // TODO FMT Use a built-in array.
186 array<basic_format_arg<_Context>, sizeof...(_Args)> __args;
187};
188
189194template <class _Context = format_context, class... _Args>
190_LIBCPP_HIDE_FROM_ABI __format_arg_store<_Context, _Args...>
191make_format_args(const _Args&... __args) {
192 return {basic_format_arg<_Context>(__args)...};
195_LIBCPP_HIDE_FROM_ABI __format_arg_store<_Context, _Args...> make_format_args(_Args&&... __args) {
196 return _VSTD::__format_arg_store<_Context, _Args...>(__args...);
193197}
194198
195199#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
196200template <class... _Args>
197_LIBCPP_HIDE_FROM_ABI __format_arg_store<wformat_context, _Args...>
198make_wformat_args(const _Args&... __args) {
199 return _VSTD::make_format_args<wformat_context>(__args...);
201_LIBCPP_HIDE_FROM_ABI __format_arg_store<wformat_context, _Args...> make_wformat_args(_Args&&... __args) {
202 return _VSTD::__format_arg_store<wformat_context, _Args...>(__args...);
200203}
201204#endif
202205
203206namespace __format {
204207
208/// Helper class parse and handle argument.
209///
210/// When parsing a handle which is not enabled the code is ill-formed.
211/// This helper uses the parser of the appropriate formatter for the stored type.
212template <class _CharT>
213class _LIBCPP_TEMPLATE_VIS __compile_time_handle {
214public:
215 _LIBCPP_HIDE_FROM_ABI
216 constexpr void __parse(basic_format_parse_context<_CharT>& __parse_ctx) const { __parse_(__parse_ctx); }
217
218 template <class _Tp>
219 _LIBCPP_HIDE_FROM_ABI constexpr void __enable() {
220 __parse_ = [](basic_format_parse_context<_CharT>& __parse_ctx) {
221 formatter<_Tp, _CharT> __f;
222 __parse_ctx.advance_to(__f.parse(__parse_ctx));
223 };
224 }
225
226 // Before calling __parse the proper handler needs to be set with __enable.
227 // The default handler isn't a core constant expression.
228 _LIBCPP_HIDE_FROM_ABI constexpr __compile_time_handle()
229 : __parse_([](basic_format_parse_context<_CharT>&) { __throw_format_error("Not a handle"); }) {}
230
231private:
232 void (*__parse_)(basic_format_parse_context<_CharT>&);
233};
234
235// Dummy format_context only providing the parts used during constant
236// validation of the basic-format-string.
237template <class _CharT>
238struct _LIBCPP_TEMPLATE_VIS __compile_time_basic_format_context {
239public:
240 using char_type = _CharT;
241
242 _LIBCPP_HIDE_FROM_ABI constexpr explicit __compile_time_basic_format_context(
243 const __arg_t* __args, const __compile_time_handle<_CharT>* __handles, size_t __size)
244 : __args_(__args), __handles_(__handles), __size_(__size) {}
245
246 // During the compile-time validation nothing needs to be written.
247 // Therefore all operations of this iterator are a NOP.
248 struct iterator {
249 _LIBCPP_HIDE_FROM_ABI constexpr iterator& operator=(_CharT) { return *this; }
250 _LIBCPP_HIDE_FROM_ABI constexpr iterator& operator*() { return *this; }
251 _LIBCPP_HIDE_FROM_ABI constexpr iterator operator++(int) { return *this; }
252 };
253
254 _LIBCPP_HIDE_FROM_ABI constexpr __arg_t arg(size_t __id) const {
255 if (__id >= __size_)
256 __throw_format_error("Argument index out of bounds");
257 return __args_[__id];
258 }
259
260 _LIBCPP_HIDE_FROM_ABI constexpr const __compile_time_handle<_CharT>& __handle(size_t __id) const {
261 if (__id >= __size_)
262 __throw_format_error("Argument index out of bounds");
263 return __handles_[__id];
264 }
265
266 _LIBCPP_HIDE_FROM_ABI constexpr iterator out() { return {}; }
267 _LIBCPP_HIDE_FROM_ABI constexpr void advance_to(iterator) {}
268
269private:
270 const __arg_t* __args_;
271 const __compile_time_handle<_CharT>* __handles_;
272 size_t __size_;
273};
274
275_LIBCPP_HIDE_FROM_ABI
276constexpr void __compile_time_validate_integral(__arg_t __type) {
277 switch (__type) {
278 case __arg_t::__int:
279 case __arg_t::__long_long:
280 case __arg_t::__i128:
281 case __arg_t::__unsigned:
282 case __arg_t::__unsigned_long_long:
283 case __arg_t::__u128:
284 return;
285
286 default:
287 __throw_format_error("Argument isn't an integral type");
288 }
289}
290
291// _HasPrecision does the formatter have a precision?
292template <class _CharT, class _Tp, bool _HasPrecision = false>
293_LIBCPP_HIDE_FROM_ABI constexpr void
294__compile_time_validate_argument(basic_format_parse_context<_CharT>& __parse_ctx,
295 __compile_time_basic_format_context<_CharT>& __ctx) {
296 formatter<_Tp, _CharT> __formatter;
297 __parse_ctx.advance_to(__formatter.parse(__parse_ctx));
298 // [format.string.std]/7
299 // ... If the corresponding formatting argument is not of integral type, or
300 // its value is negative for precision or non-positive for width, an
301 // exception of type format_error is thrown.
302 //
303 // Validate whether the arguments are integrals.
304 if constexpr (requires(formatter<_Tp, _CharT> __f) { __f.__width_needs_substitution(); }) {
305 // TODO FMT Remove this when parser v1 has been phased out.
306 if (__formatter.__width_needs_substitution())
307 __format::__compile_time_validate_integral(__ctx.arg(__formatter.__width));
308
309 if constexpr (_HasPrecision)
310 if (__formatter.__precision_needs_substitution())
311 __format::__compile_time_validate_integral(__ctx.arg(__formatter.__precision));
312 } else {
313 if (__formatter.__parser_.__width_as_arg_)
314 __format::__compile_time_validate_integral(__ctx.arg(__formatter.__parser_.__width_));
315
316 if constexpr (_HasPrecision)
317 if (__formatter.__parser_.__precision_as_arg_)
318 __format::__compile_time_validate_integral(__ctx.arg(__formatter.__parser_.__precision_));
319 }
320}
321
322template <class _CharT>
323_LIBCPP_HIDE_FROM_ABI constexpr void __compile_time_visit_format_arg(basic_format_parse_context<_CharT>& __parse_ctx,
324 __compile_time_basic_format_context<_CharT>& __ctx,
325 __arg_t __type) {
326 switch (__type) {
327 case __arg_t::__none:
328 __throw_format_error("Invalid argument");
329 case __arg_t::__boolean:
330 return __format::__compile_time_validate_argument<_CharT, bool>(__parse_ctx, __ctx);
331 case __arg_t::__char_type:
332 return __format::__compile_time_validate_argument<_CharT, _CharT>(__parse_ctx, __ctx);
333 case __arg_t::__int:
334 return __format::__compile_time_validate_argument<_CharT, int>(__parse_ctx, __ctx);
335 case __arg_t::__long_long:
336 return __format::__compile_time_validate_argument<_CharT, long long>(__parse_ctx, __ctx);
337 case __arg_t::__i128:
338# ifndef _LIBCPP_HAS_NO_INT128
339 return __format::__compile_time_validate_argument<_CharT, __int128_t>(__parse_ctx, __ctx);
340# else
341 __throw_format_error("Invalid argument");
342# endif
343 return;
344 case __arg_t::__unsigned:
345 return __format::__compile_time_validate_argument<_CharT, unsigned>(__parse_ctx, __ctx);
346 case __arg_t::__unsigned_long_long:
347 return __format::__compile_time_validate_argument<_CharT, unsigned long long>(__parse_ctx, __ctx);
348 case __arg_t::__u128:
349# ifndef _LIBCPP_HAS_NO_INT128
350 return __format::__compile_time_validate_argument<_CharT, __uint128_t>(__parse_ctx, __ctx);
351# else
352 __throw_format_error("Invalid argument");
353# endif
354 return;
355 case __arg_t::__float:
356 return __format::__compile_time_validate_argument<_CharT, float, true>(__parse_ctx, __ctx);
357 case __arg_t::__double:
358 return __format::__compile_time_validate_argument<_CharT, double, true>(__parse_ctx, __ctx);
359 case __arg_t::__long_double:
360 return __format::__compile_time_validate_argument<_CharT, long double, true>(__parse_ctx, __ctx);
361 case __arg_t::__const_char_type_ptr:
362 return __format::__compile_time_validate_argument<_CharT, const _CharT*, true>(__parse_ctx, __ctx);
363 case __arg_t::__string_view:
364 return __format::__compile_time_validate_argument<_CharT, basic_string_view<_CharT>, true>(__parse_ctx, __ctx);
365 case __arg_t::__ptr:
366 return __format::__compile_time_validate_argument<_CharT, const void*>(__parse_ctx, __ctx);
367 case __arg_t::__handle:
368 __throw_format_error("Handle should use __compile_time_validate_handle_argument");
369 }
370 __throw_format_error("Invalid argument");
371}
372
205373template <class _CharT, class _ParseCtx, class _Ctx>
206_LIBCPP_HIDE_FROM_ABI const _CharT*
374_LIBCPP_HIDE_FROM_ABI constexpr const _CharT*
207375__handle_replacement_field(const _CharT* __begin, const _CharT* __end,
208376 _ParseCtx& __parse_ctx, _Ctx& __ctx) {
209377 __format::__parse_number_result __r =
210378 __format::__parse_arg_id(__begin, __end, __parse_ctx);
211379
380 bool __parse = *__r.__ptr == _CharT(':');
212381 switch (*__r.__ptr) {
213382 case _CharT(':'):
214383 // The arg-id has a format-specifier, advance the input to the format-spec.
......@@ -223,19 +392,27 @@ __handle_replacement_field(const _CharT* __begin, const _CharT* __end,
223392 "The replacement field arg-id should terminate at a ':' or '}'");
224393 }
225394
226 _VSTD::visit_format_arg(
227 [&](auto __arg) {
228 if constexpr (same_as<decltype(__arg), monostate>)
229 __throw_format_error("Argument index out of bounds");
230 else if constexpr (same_as<decltype(__arg), typename basic_format_arg<_Ctx>::handle>)
231 __arg.format(__parse_ctx, __ctx);
232 else {
233 formatter<decltype(__arg), _CharT> __formatter;
234 __parse_ctx.advance_to(__formatter.parse(__parse_ctx));
235 __ctx.advance_to(__formatter.format(__arg, __ctx));
236 }
237 },
238 __ctx.arg(__r.__value));
395 if constexpr (same_as<_Ctx, __compile_time_basic_format_context<_CharT>>) {
396 __arg_t __type = __ctx.arg(__r.__value);
397 if (__type == __arg_t::__handle)
398 __ctx.__handle(__r.__value).__parse(__parse_ctx);
399 else
400 __format::__compile_time_visit_format_arg(__parse_ctx, __ctx, __type);
401 } else
402 _VSTD::visit_format_arg(
403 [&](auto __arg) {
404 if constexpr (same_as<decltype(__arg), monostate>)
405 __throw_format_error("Argument index out of bounds");
406 else if constexpr (same_as<decltype(__arg), typename basic_format_arg<_Ctx>::handle>)
407 __arg.format(__parse_ctx, __ctx);
408 else {
409 formatter<decltype(__arg), _CharT> __formatter;
410 if (__parse)
411 __parse_ctx.advance_to(__formatter.parse(__parse_ctx));
412 __ctx.advance_to(__formatter.format(__arg, __ctx));
413 }
414 },
415 __ctx.arg(__r.__value));
239416
240417 __begin = __parse_ctx.begin();
241418 if (__begin == __end || *__begin != _CharT('}'))
......@@ -245,7 +422,7 @@ __handle_replacement_field(const _CharT* __begin, const _CharT* __end,
245422}
246423
247424template <class _ParseCtx, class _Ctx>
248_LIBCPP_HIDE_FROM_ABI typename _Ctx::iterator
425_LIBCPP_HIDE_FROM_ABI constexpr typename _Ctx::iterator
249426__vformat_to(_ParseCtx&& __parse_ctx, _Ctx&& __ctx) {
250427 using _CharT = typename _ParseCtx::char_type;
251428 static_assert(same_as<typename _Ctx::char_type, _CharT>);
......@@ -290,6 +467,56 @@ __vformat_to(_ParseCtx&& __parse_ctx, _Ctx&& __ctx) {
290467
291468} // namespace __format
292469
470template <class _CharT, class... _Args>
471struct _LIBCPP_TEMPLATE_VIS __basic_format_string {
472 basic_string_view<_CharT> __str_;
473
474 template <class _Tp>
475 requires convertible_to<const _Tp&, basic_string_view<_CharT>>
476 consteval __basic_format_string(const _Tp& __str) : __str_{__str} {
477 __format::__vformat_to(basic_format_parse_context<_CharT>{__str_, sizeof...(_Args)},
478 _Context{__types_.data(), __handles_.data(), sizeof...(_Args)});
479 }
480
481private:
482 using _Context = __format::__compile_time_basic_format_context<_CharT>;
483
484 static constexpr array<__format::__arg_t, sizeof...(_Args)> __types_{
485 __format::__determine_arg_t<_Context, remove_cvref_t<_Args>>()...};
486
487 // TODO FMT remove this work-around when the AIX ICE has been resolved.
488# if defined(_AIX) && defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER < 1400
489 template <class _Tp>
490 static constexpr __format::__compile_time_handle<_CharT> __get_handle() {
491 __format::__compile_time_handle<_CharT> __handle;
492 if (__format::__determine_arg_t<_Context, _Tp>() == __format::__arg_t::__handle)
493 __handle.template __enable<_Tp>();
494
495 return __handle;
496 }
497
498 static constexpr array<__format::__compile_time_handle<_CharT>, sizeof...(_Args)> __handles_{
499 __get_handle<_Args>()...};
500# else
501 static constexpr array<__format::__compile_time_handle<_CharT>, sizeof...(_Args)> __handles_{[] {
502 using _Tp = remove_cvref_t<_Args>;
503 __format::__compile_time_handle<_CharT> __handle;
504 if (__format::__determine_arg_t<_Context, _Tp>() == __format::__arg_t::__handle)
505 __handle.template __enable<_Tp>();
506
507 return __handle;
508 }()...};
509# endif
510};
511
512template <class... _Args>
513using __format_string_t = __basic_format_string<char, type_identity_t<_Args>...>;
514
515#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
516template <class... _Args>
517using __wformat_string_t = __basic_format_string<wchar_t, type_identity_t<_Args>...>;
518#endif
519
293520template <class _OutIt, class _CharT, class _FormatOutIt>
294521requires(output_iterator<_OutIt, const _CharT&>) _LIBCPP_HIDE_FROM_ABI _OutIt
295522 __vformat_to(
......@@ -300,14 +527,18 @@ requires(output_iterator<_OutIt, const _CharT&>) _LIBCPP_HIDE_FROM_ABI _OutIt
300527 basic_format_parse_context{__fmt, __args.__size()},
301528 _VSTD::__format_context_create(_VSTD::move(__out_it), __args));
302529 else {
303 basic_string<_CharT> __str;
530 __format::__format_buffer<_OutIt, _CharT> __buffer{_VSTD::move(__out_it)};
304531 _VSTD::__format::__vformat_to(
305532 basic_format_parse_context{__fmt, __args.__size()},
306 _VSTD::__format_context_create(_VSTD::back_inserter(__str), __args));
307 return _VSTD::copy_n(__str.begin(), __str.size(), _VSTD::move(__out_it));
533 _VSTD::__format_context_create(__buffer.make_output_iterator(),
534 __args));
535 return _VSTD::move(__buffer).out();
308536 }
309537}
310538
539// The function is _LIBCPP_ALWAYS_INLINE since the compiler is bad at inlining
540// https://reviews.llvm.org/D110499#inline-1180704
541// TODO FMT Evaluate whether we want to file a Clang bug report regarding this.
311542template <output_iterator<const char&> _OutIt>
312543_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt
313544vformat_to(_OutIt __out_it, string_view __fmt, format_args __args) {
......@@ -324,16 +555,16 @@ vformat_to(_OutIt __out_it, wstring_view __fmt, wformat_args __args) {
324555
325556template <output_iterator<const char&> _OutIt, class... _Args>
326557_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt
327format_to(_OutIt __out_it, string_view __fmt, const _Args&... __args) {
328 return _VSTD::vformat_to(_VSTD::move(__out_it), __fmt,
558format_to(_OutIt __out_it, __format_string_t<_Args...> __fmt, _Args&&... __args) {
559 return _VSTD::vformat_to(_VSTD::move(__out_it), __fmt.__str_,
329560 _VSTD::make_format_args(__args...));
330561}
331562
332563#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
333564template <output_iterator<const wchar_t&> _OutIt, class... _Args>
334565_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt
335format_to(_OutIt __out_it, wstring_view __fmt, const _Args&... __args) {
336 return _VSTD::vformat_to(_VSTD::move(__out_it), __fmt,
566format_to(_OutIt __out_it, __wformat_string_t<_Args...> __fmt, _Args&&... __args) {
567 return _VSTD::vformat_to(_VSTD::move(__out_it), __fmt.__str_,
337568 _VSTD::make_wformat_args(__args...));
338569}
339570#endif
......@@ -355,60 +586,63 @@ vformat(wstring_view __fmt, wformat_args __args) {
355586#endif
356587
357588template <class... _Args>
358_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT string
359format(string_view __fmt, const _Args&... __args) {
360 return _VSTD::vformat(__fmt, _VSTD::make_format_args(__args...));
589_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT string format(__format_string_t<_Args...> __fmt,
590 _Args&&... __args) {
591 return _VSTD::vformat(__fmt.__str_, _VSTD::make_format_args(__args...));
361592}
362593
363594#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
364595template <class... _Args>
365596_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT wstring
366format(wstring_view __fmt, const _Args&... __args) {
367 return _VSTD::vformat(__fmt, _VSTD::make_wformat_args(__args...));
597format(__wformat_string_t<_Args...> __fmt, _Args&&... __args) {
598 return _VSTD::vformat(__fmt.__str_, _VSTD::make_wformat_args(__args...));
368599}
369600#endif
370601
602template <class _Context, class _OutIt, class _CharT>
603_LIBCPP_HIDE_FROM_ABI format_to_n_result<_OutIt> __vformat_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n,
604 basic_string_view<_CharT> __fmt,
605 basic_format_args<_Context> __args) {
606 __format::__format_to_n_buffer<_OutIt, _CharT> __buffer{_VSTD::move(__out_it), __n};
607 _VSTD::__format::__vformat_to(basic_format_parse_context{__fmt, __args.__size()},
608 _VSTD::__format_context_create(__buffer.make_output_iterator(), __args));
609 return _VSTD::move(__buffer).result();
610}
611
371612template <output_iterator<const char&> _OutIt, class... _Args>
372_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT format_to_n_result<_OutIt>
373format_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n, string_view __fmt,
374 const _Args&... __args) {
375 // TODO FMT Improve PoC: using std::string is inefficient.
376 string __str = _VSTD::vformat(__fmt, _VSTD::make_format_args(__args...));
377 iter_difference_t<_OutIt> __s = __str.size();
378 iter_difference_t<_OutIt> __m =
379 _VSTD::clamp(__n, iter_difference_t<_OutIt>(0), __s);
380 __out_it = _VSTD::copy_n(__str.begin(), __m, _VSTD::move(__out_it));
381 return {_VSTD::move(__out_it), __s};
613_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT format_to_n_result<_OutIt>
614format_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n, __format_string_t<_Args...> __fmt, _Args&&... __args) {
615 return _VSTD::__vformat_to_n<format_context>(_VSTD::move(__out_it), __n, __fmt.__str_, _VSTD::make_format_args(__args...));
382616}
383617
384618#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
385619template <output_iterator<const wchar_t&> _OutIt, class... _Args>
386620_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT format_to_n_result<_OutIt>
387format_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n, wstring_view __fmt,
388 const _Args&... __args) {
389 // TODO FMT Improve PoC: using std::string is inefficient.
390 wstring __str = _VSTD::vformat(__fmt, _VSTD::make_wformat_args(__args...));
391 iter_difference_t<_OutIt> __s = __str.size();
392 iter_difference_t<_OutIt> __m =
393 _VSTD::clamp(__n, iter_difference_t<_OutIt>(0), __s);
394 __out_it = _VSTD::copy_n(__str.begin(), __m, _VSTD::move(__out_it));
395 return {_VSTD::move(__out_it), __s};
621format_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n, __wformat_string_t<_Args...> __fmt,
622 _Args&&... __args) {
623 return _VSTD::__vformat_to_n<wformat_context>(_VSTD::move(__out_it), __n, __fmt.__str_, _VSTD::make_wformat_args(__args...));
396624}
397625#endif
398626
627template <class _CharT>
628_LIBCPP_HIDE_FROM_ABI size_t __vformatted_size(basic_string_view<_CharT> __fmt, auto __args) {
629 __format::__formatted_size_buffer<_CharT> __buffer;
630 _VSTD::__format::__vformat_to(basic_format_parse_context{__fmt, __args.__size()},
631 _VSTD::__format_context_create(__buffer.make_output_iterator(), __args));
632 return _VSTD::move(__buffer).result();
633}
634
399635template <class... _Args>
400_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT size_t
401formatted_size(string_view __fmt, const _Args&... __args) {
402 // TODO FMT Improve PoC: using std::string is inefficient.
403 return _VSTD::vformat(__fmt, _VSTD::make_format_args(__args...)).size();
636_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT size_t
637formatted_size(__format_string_t<_Args...> __fmt, _Args&&... __args) {
638 return _VSTD::__vformatted_size(__fmt.__str_, basic_format_args{_VSTD::make_format_args(__args...)});
404639}
405640
406641#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
407642template <class... _Args>
408_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT size_t
409formatted_size(wstring_view __fmt, const _Args&... __args) {
410 // TODO FMT Improve PoC: using std::string is inefficient.
411 return _VSTD::vformat(__fmt, _VSTD::make_wformat_args(__args...)).size();
643_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT size_t
644formatted_size(__wformat_string_t<_Args...> __fmt, _Args&&... __args) {
645 return _VSTD::__vformatted_size(__fmt.__str_, basic_format_args{_VSTD::make_wformat_args(__args...)});
412646}
413647#endif
414648
......@@ -425,12 +659,12 @@ requires(output_iterator<_OutIt, const _CharT&>) _LIBCPP_HIDE_FROM_ABI _OutIt
425659 _VSTD::__format_context_create(_VSTD::move(__out_it), __args,
426660 _VSTD::move(__loc)));
427661 else {
428 basic_string<_CharT> __str;
662 __format::__format_buffer<_OutIt, _CharT> __buffer{_VSTD::move(__out_it)};
429663 _VSTD::__format::__vformat_to(
430664 basic_format_parse_context{__fmt, __args.__size()},
431 _VSTD::__format_context_create(_VSTD::back_inserter(__str), __args,
432 _VSTD::move(__loc)));
433 return _VSTD::copy_n(__str.begin(), __str.size(), _VSTD::move(__out_it));
665 _VSTD::__format_context_create(__buffer.make_output_iterator(),
666 __args, _VSTD::move(__loc)));
667 return _VSTD::move(__buffer).out();
434668 }
435669}
436670
......@@ -451,17 +685,17 @@ _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt v
451685#endif
452686
453687template <output_iterator<const char&> _OutIt, class... _Args>
454_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt format_to(
455 _OutIt __out_it, locale __loc, string_view __fmt, const _Args&... __args) {
456 return _VSTD::vformat_to(_VSTD::move(__out_it), _VSTD::move(__loc), __fmt,
688_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt
689format_to(_OutIt __out_it, locale __loc, __format_string_t<_Args...> __fmt, _Args&&... __args) {
690 return _VSTD::vformat_to(_VSTD::move(__out_it), _VSTD::move(__loc), __fmt.__str_,
457691 _VSTD::make_format_args(__args...));
458692}
459693
460694#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
461695template <output_iterator<const wchar_t&> _OutIt, class... _Args>
462_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt format_to(
463 _OutIt __out_it, locale __loc, wstring_view __fmt, const _Args&... __args) {
464 return _VSTD::vformat_to(_VSTD::move(__out_it), _VSTD::move(__loc), __fmt,
696_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt
697format_to(_OutIt __out_it, locale __loc, __wformat_string_t<_Args...> __fmt, _Args&&... __args) {
698 return _VSTD::vformat_to(_VSTD::move(__out_it), _VSTD::move(__loc), __fmt.__str_,
465699 _VSTD::make_wformat_args(__args...));
466700}
467701#endif
......@@ -485,80 +719,80 @@ vformat(locale __loc, wstring_view __fmt, wformat_args __args) {
485719#endif
486720
487721template <class... _Args>
488_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT string
489format(locale __loc, string_view __fmt, const _Args&... __args) {
490 return _VSTD::vformat(_VSTD::move(__loc), __fmt,
722_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT string format(locale __loc,
723 __format_string_t<_Args...> __fmt,
724 _Args&&... __args) {
725 return _VSTD::vformat(_VSTD::move(__loc), __fmt.__str_,
491726 _VSTD::make_format_args(__args...));
492727}
493728
494729#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
495730template <class... _Args>
496731_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT wstring
497format(locale __loc, wstring_view __fmt, const _Args&... __args) {
498 return _VSTD::vformat(_VSTD::move(__loc), __fmt,
732format(locale __loc, __wformat_string_t<_Args...> __fmt, _Args&&... __args) {
733 return _VSTD::vformat(_VSTD::move(__loc), __fmt.__str_,
499734 _VSTD::make_wformat_args(__args...));
500735}
501736#endif
502737
738template <class _Context, class _OutIt, class _CharT>
739_LIBCPP_HIDE_FROM_ABI format_to_n_result<_OutIt> __vformat_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n,
740 locale __loc, basic_string_view<_CharT> __fmt,
741 basic_format_args<_Context> __args) {
742 __format::__format_to_n_buffer<_OutIt, _CharT> __buffer{_VSTD::move(__out_it), __n};
743 _VSTD::__format::__vformat_to(
744 basic_format_parse_context{__fmt, __args.__size()},
745 _VSTD::__format_context_create(__buffer.make_output_iterator(), __args, _VSTD::move(__loc)));
746 return _VSTD::move(__buffer).result();
747}
748
503749template <output_iterator<const char&> _OutIt, class... _Args>
504_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT format_to_n_result<_OutIt>
505format_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n, locale __loc,
506 string_view __fmt, const _Args&... __args) {
507 // TODO FMT Improve PoC: using std::string is inefficient.
508 string __str = _VSTD::vformat(_VSTD::move(__loc), __fmt,
509 _VSTD::make_format_args(__args...));
510 iter_difference_t<_OutIt> __s = __str.size();
511 iter_difference_t<_OutIt> __m =
512 _VSTD::clamp(__n, iter_difference_t<_OutIt>(0), __s);
513 __out_it = _VSTD::copy_n(__str.begin(), __m, _VSTD::move(__out_it));
514 return {_VSTD::move(__out_it), __s};
750_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT format_to_n_result<_OutIt>
751format_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n, locale __loc, __format_string_t<_Args...> __fmt,
752 _Args&&... __args) {
753 return _VSTD::__vformat_to_n<format_context>(_VSTD::move(__out_it), __n, _VSTD::move(__loc), __fmt.__str_,
754 _VSTD::make_format_args(__args...));
515755}
516756
517757#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
518758template <output_iterator<const wchar_t&> _OutIt, class... _Args>
519_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT format_to_n_result<_OutIt>
520format_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n, locale __loc,
521 wstring_view __fmt, const _Args&... __args) {
522 // TODO FMT Improve PoC: using std::string is inefficient.
523 wstring __str = _VSTD::vformat(_VSTD::move(__loc), __fmt,
524 _VSTD::make_wformat_args(__args...));
525 iter_difference_t<_OutIt> __s = __str.size();
526 iter_difference_t<_OutIt> __m =
527 _VSTD::clamp(__n, iter_difference_t<_OutIt>(0), __s);
528 __out_it = _VSTD::copy_n(__str.begin(), __m, _VSTD::move(__out_it));
529 return {_VSTD::move(__out_it), __s};
759_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT format_to_n_result<_OutIt>
760format_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n, locale __loc, __wformat_string_t<_Args...> __fmt,
761 _Args&&... __args) {
762 return _VSTD::__vformat_to_n<wformat_context>(_VSTD::move(__out_it), __n, _VSTD::move(__loc), __fmt.__str_,
763 _VSTD::make_wformat_args(__args...));
530764}
531765#endif
532766
767template <class _CharT>
768_LIBCPP_HIDE_FROM_ABI size_t __vformatted_size(locale __loc, basic_string_view<_CharT> __fmt, auto __args) {
769 __format::__formatted_size_buffer<_CharT> __buffer;
770 _VSTD::__format::__vformat_to(
771 basic_format_parse_context{__fmt, __args.__size()},
772 _VSTD::__format_context_create(__buffer.make_output_iterator(), __args, _VSTD::move(__loc)));
773 return _VSTD::move(__buffer).result();
774}
775
533776template <class... _Args>
534_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT size_t
535formatted_size(locale __loc, string_view __fmt, const _Args&... __args) {
536 // TODO FMT Improve PoC: using std::string is inefficient.
537 return _VSTD::vformat(_VSTD::move(__loc), __fmt,
538 _VSTD::make_format_args(__args...))
539 .size();
777_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT size_t
778formatted_size(locale __loc, __format_string_t<_Args...> __fmt, _Args&&... __args) {
779 return _VSTD::__vformatted_size(_VSTD::move(__loc), __fmt.__str_, basic_format_args{_VSTD::make_format_args(__args...)});
540780}
541781
542782#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
543783template <class... _Args>
544_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT size_t
545formatted_size(locale __loc, wstring_view __fmt, const _Args&... __args) {
546 // TODO FMT Improve PoC: using std::string is inefficient.
547 return _VSTD::vformat(_VSTD::move(__loc), __fmt,
548 _VSTD::make_wformat_args(__args...))
549 .size();
784_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT size_t
785formatted_size(locale __loc, __wformat_string_t<_Args...> __fmt, _Args&&... __args) {
786 return _VSTD::__vformatted_size(_VSTD::move(__loc), __fmt.__str_, basic_format_args{_VSTD::make_wformat_args(__args...)});
550787}
551788#endif
552789
553790#endif // _LIBCPP_HAS_NO_LOCALIZATION
554791
555#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
556792#endif //_LIBCPP_STD_VER > 17
557793
558794_LIBCPP_END_NAMESPACE_STD
559795
560_LIBCPP_POP_MACROS
561
562796#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_FORMAT)
563797
564798#endif // _LIBCPP_FORMAT
lib/libcxx/include/forward_list+42-41
......@@ -179,18 +179,43 @@ template <class T, class Allocator, class Predicate>
179179
180180*/
181181
182#include <__algorithm/comp.h>
183#include <__algorithm/lexicographical_compare.h>
184#include <__algorithm/min.h>
185#include <__assert> // all public C++ headers provide the assertion handler
182186#include <__config>
187#include <__iterator/distance.h>
188#include <__iterator/iterator_traits.h>
189#include <__iterator/move_iterator.h>
190#include <__iterator/next.h>
191#include <__memory/swap_allocator.h>
183192#include <__utility/forward.h>
184#include <algorithm>
185#include <initializer_list>
186#include <iterator>
187193#include <limits>
188194#include <memory>
189195#include <type_traits>
190196#include <version>
191197
198#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
199# include <algorithm>
200# include <functional>
201# include <iterator>
202#endif
203
204// standard-mandated includes
205
206// [iterator.range]
207#include <__iterator/access.h>
208#include <__iterator/data.h>
209#include <__iterator/empty.h>
210#include <__iterator/reverse_access.h>
211#include <__iterator/size.h>
212
213// [forward.list.syn]
214#include <compare>
215#include <initializer_list>
216
192217#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
193#pragma GCC system_header
218# pragma GCC system_header
194219#endif
195220
196221_LIBCPP_PUSH_MACROS
......@@ -679,17 +704,13 @@ public:
679704
680705 template <class _InputIterator>
681706 forward_list(_InputIterator __f, _InputIterator __l,
682 typename enable_if<
683 __is_cpp17_input_iterator<_InputIterator>::value
684 >::type* = nullptr);
707 __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>* = nullptr);
685708 template <class _InputIterator>
686709 forward_list(_InputIterator __f, _InputIterator __l,
687710 const allocator_type& __a,
688 typename enable_if<
689 __is_cpp17_input_iterator<_InputIterator>::value
690 >::type* = nullptr);
711 __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>* = nullptr);
691712 forward_list(const forward_list& __x);
692 forward_list(const forward_list& __x, const __identity_t<allocator_type>& __a);
713 forward_list(const forward_list& __x, const __type_identity_t<allocator_type>& __a);
693714
694715 forward_list& operator=(const forward_list& __x);
695716
......@@ -698,7 +719,7 @@ public:
698719 forward_list(forward_list&& __x)
699720 _NOEXCEPT_(is_nothrow_move_constructible<base>::value)
700721 : base(_VSTD::move(__x)) {}
701 forward_list(forward_list&& __x, const __identity_t<allocator_type>& __a);
722 forward_list(forward_list&& __x, const __type_identity_t<allocator_type>& __a);
702723
703724 forward_list(initializer_list<value_type> __il);
704725 forward_list(initializer_list<value_type> __il, const allocator_type& __a);
......@@ -719,11 +740,7 @@ public:
719740 // ~forward_list() = default;
720741
721742 template <class _InputIterator>
722 typename enable_if
723 <
724 __is_cpp17_input_iterator<_InputIterator>::value,
725 void
726 >::type
743 __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, void>
727744 assign(_InputIterator __f, _InputIterator __l);
728745 void assign(size_type __n, const value_type& __v);
729746
......@@ -799,12 +816,8 @@ public:
799816 iterator insert_after(const_iterator __p, const value_type& __v);
800817 iterator insert_after(const_iterator __p, size_type __n, const value_type& __v);
801818 template <class _InputIterator>
802 _LIBCPP_INLINE_VISIBILITY
803 typename enable_if
804 <
805 __is_cpp17_input_iterator<_InputIterator>::value,
806 iterator
807 >::type
819 _LIBCPP_INLINE_VISIBILITY
820 __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, iterator>
808821 insert_after(const_iterator __p, _InputIterator __f, _InputIterator __l);
809822
810823 iterator erase_after(const_iterator __p);
......@@ -953,9 +966,7 @@ forward_list<_Tp, _Alloc>::forward_list(size_type __n, const value_type& __v)
953966template <class _Tp, class _Alloc>
954967template <class _InputIterator>
955968forward_list<_Tp, _Alloc>::forward_list(_InputIterator __f, _InputIterator __l,
956 typename enable_if<
957 __is_cpp17_input_iterator<_InputIterator>::value
958 >::type*)
969 __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>*)
959970{
960971 insert_after(cbefore_begin(), __f, __l);
961972}
......@@ -964,9 +975,7 @@ template <class _Tp, class _Alloc>
964975template <class _InputIterator>
965976forward_list<_Tp, _Alloc>::forward_list(_InputIterator __f, _InputIterator __l,
966977 const allocator_type& __a,
967 typename enable_if<
968 __is_cpp17_input_iterator<_InputIterator>::value
969 >::type*)
978 __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>*)
970979 : base(__a)
971980{
972981 insert_after(cbefore_begin(), __f, __l);
......@@ -981,7 +990,7 @@ forward_list<_Tp, _Alloc>::forward_list(const forward_list& __x)
981990
982991template <class _Tp, class _Alloc>
983992forward_list<_Tp, _Alloc>::forward_list(const forward_list& __x,
984 const __identity_t<allocator_type>& __a)
993 const __type_identity_t<allocator_type>& __a)
985994 : base(__a)
986995{
987996 insert_after(cbefore_begin(), __x.begin(), __x.end());
......@@ -1002,7 +1011,7 @@ forward_list<_Tp, _Alloc>::operator=(const forward_list& __x)
10021011#ifndef _LIBCPP_CXX03_LANG
10031012template <class _Tp, class _Alloc>
10041013forward_list<_Tp, _Alloc>::forward_list(forward_list&& __x,
1005 const __identity_t<allocator_type>& __a)
1014 const __type_identity_t<allocator_type>& __a)
10061015 : base(_VSTD::move(__x), __a)
10071016{
10081017 if (base::__alloc() != __x.__alloc())
......@@ -1076,11 +1085,7 @@ forward_list<_Tp, _Alloc>::operator=(initializer_list<value_type> __il)
10761085
10771086template <class _Tp, class _Alloc>
10781087template <class _InputIterator>
1079typename enable_if
1080<
1081 __is_cpp17_input_iterator<_InputIterator>::value,
1082 void
1083>::type
1088__enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, void>
10841089forward_list<_Tp, _Alloc>::assign(_InputIterator __f, _InputIterator __l)
10851090{
10861091 iterator __i = before_begin();
......@@ -1272,11 +1277,7 @@ forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, size_type __n,
12721277
12731278template <class _Tp, class _Alloc>
12741279template <class _InputIterator>
1275typename enable_if
1276<
1277 __is_cpp17_input_iterator<_InputIterator>::value,
1278 typename forward_list<_Tp, _Alloc>::iterator
1279>::type
1280__enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, typename forward_list<_Tp, _Alloc>::iterator>
12801281forward_list<_Tp, _Alloc>::insert_after(const_iterator __p,
12811282 _InputIterator __f, _InputIterator __l)
12821283{
lib/libcxx/include/fstream+31-13
......@@ -179,12 +179,17 @@ typedef basic_fstream<wchar_t> wfstream;
179179
180180*/
181181
182#include <__algorithm/max.h>
183#include <__assert> // all public C++ headers provide the assertion handler
182184#include <__availability>
183185#include <__config>
184#include <__debug>
185186#include <__locale>
187#include <__utility/move.h>
188#include <__utility/swap.h>
189#include <__utility/unreachable.h>
186190#include <cstdio>
187191#include <cstdlib>
192#include <cstring>
188193#include <istream>
189194#include <ostream>
190195#include <version>
......@@ -194,7 +199,7 @@ typedef basic_fstream<wchar_t> wfstream;
194199#endif
195200
196201#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
197#pragma GCC system_header
202# pragma GCC system_header
198203#endif
199204
200205_LIBCPP_PUSH_MACROS
......@@ -414,25 +419,38 @@ basic_filebuf<_CharT, _Traits>::swap(basic_filebuf& __rhs)
414419 basic_streambuf<char_type, traits_type>::swap(__rhs);
415420 if (__extbuf_ != __extbuf_min_ && __rhs.__extbuf_ != __rhs.__extbuf_min_)
416421 {
417 _VSTD::swap(__extbuf_, __rhs.__extbuf_);
418 _VSTD::swap(__extbufnext_, __rhs.__extbufnext_);
419 _VSTD::swap(__extbufend_, __rhs.__extbufend_);
422 // Neither *this nor __rhs uses the small buffer, so we can simply swap the pointers.
423 std::swap(__extbuf_, __rhs.__extbuf_);
424 std::swap(__extbufnext_, __rhs.__extbufnext_);
425 std::swap(__extbufend_, __rhs.__extbufend_);
420426 }
421427 else
422428 {
423 ptrdiff_t __ln = __extbufnext_ - __extbuf_;
424 ptrdiff_t __le = __extbufend_ - __extbuf_;
425 ptrdiff_t __rn = __rhs.__extbufnext_ - __rhs.__extbuf_;
426 ptrdiff_t __re = __rhs.__extbufend_ - __rhs.__extbuf_;
429 ptrdiff_t __ln = __extbufnext_ ? __extbufnext_ - __extbuf_ : 0;
430 ptrdiff_t __le = __extbufend_ ? __extbufend_ - __extbuf_ : 0;
431 ptrdiff_t __rn = __rhs.__extbufnext_ ? __rhs.__extbufnext_ - __rhs.__extbuf_ : 0;
432 ptrdiff_t __re = __rhs.__extbufend_ ? __rhs.__extbufend_ - __rhs.__extbuf_ : 0;
427433 if (__extbuf_ == __extbuf_min_ && __rhs.__extbuf_ != __rhs.__extbuf_min_)
428434 {
435 // *this uses the small buffer, but __rhs doesn't.
429436 __extbuf_ = __rhs.__extbuf_;
430437 __rhs.__extbuf_ = __rhs.__extbuf_min_;
438 std::memmove(__rhs.__extbuf_min_, __extbuf_min_, sizeof(__extbuf_min_));
431439 }
432440 else if (__extbuf_ != __extbuf_min_ && __rhs.__extbuf_ == __rhs.__extbuf_min_)
433441 {
442 // *this doesn't use the small buffer, but __rhs does.
434443 __rhs.__extbuf_ = __extbuf_;
435444 __extbuf_ = __extbuf_min_;
445 std::memmove(__extbuf_min_, __rhs.__extbuf_min_, sizeof(__extbuf_min_));
446 }
447 else
448 {
449 // Both *this and __rhs use the small buffer.
450 char __tmp[sizeof(__extbuf_min_)];
451 std::memmove(__tmp, __extbuf_min_, sizeof(__extbuf_min_));
452 std::memmove(__extbuf_min_, __rhs.__extbuf_min_, sizeof(__extbuf_min_));
453 std::memmove(__rhs.__extbuf_min_, __tmp, sizeof(__extbuf_min_));
436454 }
437455 __extbufnext_ = __extbuf_ + __rn;
438456 __extbufend_ = __extbuf_ + __re;
......@@ -538,7 +556,7 @@ const char* basic_filebuf<_CharT, _Traits>::__make_mdstring(
538556 default:
539557 return nullptr;
540558 }
541 _LIBCPP_UNREACHABLE();
559 __libcpp_unreachable();
542560}
543561
544562template <class _CharT, class _Traits>
......@@ -1716,9 +1734,9 @@ basic_fstream<_CharT, _Traits>::close()
17161734}
17171735
17181736#if defined(_LIBCPP_ABI_ENABLE_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1)
1719_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ifstream<char>)
1720_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ofstream<char>)
1721_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_filebuf<char>)
1737extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ifstream<char>;
1738extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ofstream<char>;
1739extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_filebuf<char>;
17221740#endif
17231741
17241742_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/functional+17-2
......@@ -482,6 +482,16 @@ template <> struct hash<long double>;
482482template<class T> struct hash<T*>;
483483template <> struct hash<nullptr_t>; // C++17
484484
485namespace ranges {
486 // [range.cmp], concept-constrained comparisons
487 struct equal_to;
488 struct not_equal_to;
489 struct greater;
490 struct less;
491 struct greater_equal;
492 struct less_equal;
493}
494
485495} // std
486496
487497POLICY: For non-variadic implementations, the number of arguments is limited
......@@ -491,6 +501,7 @@ POLICY: For non-variadic implementations, the number of arguments is limited
491501*/
492502
493503#include <__algorithm/search.h>
504#include <__assert> // all public C++ headers provide the assertion handler
494505#include <__compare/compare_three_way.h>
495506#include <__config>
496507#include <__debug>
......@@ -501,6 +512,7 @@ POLICY: For non-variadic implementations, the number of arguments is limited
501512#include <__functional/bind_front.h>
502513#include <__functional/binder1st.h>
503514#include <__functional/binder2nd.h>
515#include <__functional/boyer_moore_searcher.h>
504516#include <__functional/compose.h>
505517#include <__functional/default_searcher.h>
506518#include <__functional/function.h>
......@@ -525,11 +537,14 @@ POLICY: For non-variadic implementations, the number of arguments is limited
525537#include <tuple>
526538#include <type_traits>
527539#include <typeinfo>
528#include <utility>
529540#include <version>
530541
542#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
543# include <utility>
544#endif
545
531546#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
532#pragma GCC system_header
547# pragma GCC system_header
533548#endif
534549
535550#endif // _LIBCPP_FUNCTIONAL
lib/libcxx/include/future+22-46
......@@ -361,14 +361,16 @@ template <class R, class Alloc> struct uses_allocator<packaged_task<R>, Alloc>;
361361
362362*/
363363
364#include <__assert> // all public C++ headers provide the assertion handler
364365#include <__availability>
366#include <__chrono/duration.h>
367#include <__chrono/time_point.h>
365368#include <__config>
366#include <__debug>
367369#include <__memory/allocator_arg_t.h>
368370#include <__memory/uses_allocator.h>
369371#include <__utility/auto_cast.h>
370372#include <__utility/forward.h>
371#include <chrono>
373#include <__utility/move.h>
372374#include <exception>
373375#include <memory>
374376#include <mutex>
......@@ -376,13 +378,17 @@ template <class R, class Alloc> struct uses_allocator<packaged_task<R>, Alloc>;
376378#include <thread>
377379#include <version>
378380
381#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
382# include <chrono>
383#endif
384
379385#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
380#pragma GCC system_header
386# pragma GCC system_header
381387#endif
382388
383389#ifdef _LIBCPP_HAS_NO_THREADS
384#error <future> is not supported on this single threaded system
385#else // !_LIBCPP_HAS_NO_THREADS
390# error "<future> is not supported since libc++ has been configured without support for threads."
391#endif
386392
387393_LIBCPP_BEGIN_NAMESPACE_STD
388394
......@@ -399,7 +405,7 @@ _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(future_errc)
399405template <>
400406struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<future_errc> : public true_type {};
401407
402#ifdef _LIBCPP_HAS_NO_STRONG_ENUMS
408#ifdef _LIBCPP_CXX03_LANG
403409template <>
404410struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<future_errc::__lx> : public true_type { };
405411#endif
......@@ -413,7 +419,7 @@ _LIBCPP_DECLARE_STRONG_ENUM(launch)
413419};
414420_LIBCPP_DECLARE_STRONG_ENUM_EPILOG(launch)
415421
416#ifndef _LIBCPP_HAS_NO_STRONG_ENUMS
422#ifndef _LIBCPP_CXX03_LANG
417423
418424typedef underlying_type<launch>::type __launch_underlying_type;
419425
......@@ -473,7 +479,7 @@ operator^=(launch& __x, launch __y)
473479 __x = __x ^ __y; return __x;
474480}
475481
476#endif // !_LIBCPP_HAS_NO_STRONG_ENUMS
482#endif // !_LIBCPP_CXX03_LANG
477483
478484//enum class future_status
479485_LIBCPP_DECLARE_STRONG_ENUM(future_status)
......@@ -519,12 +525,12 @@ _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
519525#ifndef _LIBCPP_NO_EXCEPTIONS
520526_LIBCPP_AVAILABILITY_FUTURE_ERROR
521527#endif
522void __throw_future_error(future_errc _Ev)
528void __throw_future_error(future_errc __ev)
523529{
524530#ifndef _LIBCPP_NO_EXCEPTIONS
525 throw future_error(make_error_code(_Ev));
531 throw future_error(make_error_code(__ev));
526532#else
527 ((void)_Ev);
533 ((void)__ev);
528534 _VSTD::abort();
529535#endif
530536}
......@@ -1100,7 +1106,7 @@ future<_Rp>::future(__assoc_state<_Rp>* __state)
11001106
11011107struct __release_shared_count
11021108{
1103 void operator()(__shared_count* p) {p->__release_shared();}
1109 void operator()(__shared_count* __p) {__p->__release_shared();}
11041110};
11051111
11061112template <class _Rp>
......@@ -1885,25 +1891,11 @@ public:
18851891 _LIBCPP_INLINE_VISIBILITY
18861892 packaged_task() _NOEXCEPT : __p_(nullptr) {}
18871893 template <class _Fp,
1888 class = typename enable_if
1889 <
1890 !is_same<
1891 typename __uncvref<_Fp>::type,
1892 packaged_task
1893 >::value
1894 >::type
1895 >
1894 class = __enable_if_t<!is_same<__uncvref_t<_Fp>, packaged_task>::value> >
18961895 _LIBCPP_INLINE_VISIBILITY
18971896 explicit packaged_task(_Fp&& __f) : __f_(_VSTD::forward<_Fp>(__f)) {}
18981897 template <class _Fp, class _Allocator,
1899 class = typename enable_if
1900 <
1901 !is_same<
1902 typename __uncvref<_Fp>::type,
1903 packaged_task
1904 >::value
1905 >::type
1906 >
1898 class = __enable_if_t<!is_same<__uncvref_t<_Fp>, packaged_task>::value> >
19071899 _LIBCPP_INLINE_VISIBILITY
19081900 packaged_task(allocator_arg_t, const _Allocator& __a, _Fp&& __f)
19091901 : __f_(allocator_arg, __a, _VSTD::forward<_Fp>(__f)),
......@@ -2014,25 +2006,11 @@ public:
20142006 _LIBCPP_INLINE_VISIBILITY
20152007 packaged_task() _NOEXCEPT : __p_(nullptr) {}
20162008 template <class _Fp,
2017 class = typename enable_if
2018 <
2019 !is_same<
2020 typename __uncvref<_Fp>::type,
2021 packaged_task
2022 >::value
2023 >::type
2024 >
2009 class = __enable_if_t<!is_same<__uncvref_t<_Fp>, packaged_task>::value> >
20252010 _LIBCPP_INLINE_VISIBILITY
20262011 explicit packaged_task(_Fp&& __f) : __f_(_VSTD::forward<_Fp>(__f)) {}
20272012 template <class _Fp, class _Allocator,
2028 class = typename enable_if
2029 <
2030 !is_same<
2031 typename __uncvref<_Fp>::type,
2032 packaged_task
2033 >::value
2034 >::type
2035 >
2013 class = __enable_if_t<!is_same<__uncvref_t<_Fp>, packaged_task>::value> >
20362014 _LIBCPP_INLINE_VISIBILITY
20372015 packaged_task(allocator_arg_t, const _Allocator& __a, _Fp&& __f)
20382016 : __f_(allocator_arg, __a, _VSTD::forward<_Fp>(__f)),
......@@ -2458,6 +2436,4 @@ future<void>::share() _NOEXCEPT
24582436
24592437_LIBCPP_END_NAMESPACE_STD
24602438
2461#endif // !_LIBCPP_HAS_NO_THREADS
2462
24632439#endif // _LIBCPP_FUTURE
lib/libcxx/include/initializer_list+2-1
......@@ -42,11 +42,12 @@ template<class E> const E* end(initializer_list<E> il) noexcept; // constexpr in
4242
4343*/
4444
45#include <__assert> // all public C++ headers provide the assertion handler
4546#include <__config>
4647#include <cstddef>
4748
4849#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
49#pragma GCC system_header
50# pragma GCC system_header
5051#endif
5152
5253namespace std // purposefully not versioned
lib/libcxx/include/inttypes.h+1-1
......@@ -238,7 +238,7 @@ uintmax_t wcstoumax(const wchar_t* restrict nptr, wchar_t** restrict endptr, int
238238#include <__config>
239239
240240#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
241#pragma GCC system_header
241# pragma GCC system_header
242242#endif
243243
244244/* C99 stdlib (e.g. glibc < 2.18) does not provide format macros needed
lib/libcxx/include/iomanip+84-91
......@@ -42,13 +42,13 @@ template <class charT, class traits, class Allocator>
4242
4343*/
4444
45#include <__assert> // all public C++ headers provide the assertion handler
4546#include <__config>
46#include <__string>
4747#include <istream>
4848#include <version>
4949
5050#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
51#pragma GCC system_header
51# pragma GCC system_header
5252#endif
5353
5454_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -513,16 +513,17 @@ put_time(const tm* __tm, const _CharT* __fmt)
513513 return __iom_t10<_CharT>(__tm, __fmt);
514514}
515515
516template <class _CharT, class _Traits, class _ForwardIterator>
517basic_ostream<_CharT, _Traits> &
518__quoted_output ( basic_ostream<_CharT, _Traits> &__os,
519 _ForwardIterator __first, _ForwardIterator __last, _CharT __delim, _CharT __escape )
516#if _LIBCPP_STD_VER >= 11
517
518template <class _CharT, class _Traits>
519_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
520__quoted_output(basic_ostream<_CharT, _Traits>& __os,
521 const _CharT *__first, const _CharT *__last, _CharT __delim, _CharT __escape)
520522{
521523 basic_string<_CharT, _Traits> __str;
522524 __str.push_back(__delim);
523 for ( ; __first != __last; ++ __first )
524 {
525 if (_Traits::eq (*__first, __escape) || _Traits::eq (*__first, __delim))
525 for (; __first != __last; ++__first) {
526 if (_Traits::eq(*__first, __escape) || _Traits::eq(*__first, __delim))
526527 __str.push_back(__escape);
527528 __str.push_back(*__first);
528529 }
......@@ -531,139 +532,131 @@ __quoted_output ( basic_ostream<_CharT, _Traits> &__os,
531532}
532533
533534template <class _CharT, class _Traits, class _String>
534basic_istream<_CharT, _Traits> &
535__quoted_input ( basic_istream<_CharT, _Traits> &__is, _String & __string, _CharT __delim, _CharT __escape )
535_LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
536__quoted_input(basic_istream<_CharT, _Traits>& __is, _String& __string, _CharT __delim, _CharT __escape)
536537{
537 __string.clear ();
538 __string.clear();
538539 _CharT __c;
539540 __is >> __c;
540 if ( __is.fail ())
541 if (__is.fail())
541542 return __is;
542543
543 if (!_Traits::eq (__c, __delim)) // no delimiter, read the whole string
544 {
545 __is.unget ();
544 if (!_Traits::eq(__c, __delim)) {
545 // no delimiter, read the whole string
546 __is.unget();
546547 __is >> __string;
547548 return __is;
548549 }
549550
550 __save_flags<_CharT, _Traits> sf(__is);
551 noskipws (__is);
552 while (true)
553 {
551 __save_flags<_CharT, _Traits> __sf(__is);
552 std::noskipws(__is);
553 while (true) {
554554 __is >> __c;
555 if ( __is.fail ())
555 if (__is.fail())
556556 break;
557 if (_Traits::eq (__c, __escape))
558 {
557 if (_Traits::eq(__c, __escape)) {
559558 __is >> __c;
560 if ( __is.fail ())
559 if (__is.fail())
561560 break;
562 }
563 else if (_Traits::eq (__c, __delim))
561 } else if (_Traits::eq(__c, __delim))
564562 break;
565 __string.push_back ( __c );
566 }
563 __string.push_back(__c);
564 }
567565 return __is;
568566}
569567
570
571template <class _CharT, class _Traits, class _Iter>
572basic_ostream<_CharT, _Traits>& operator<<(
573 basic_ostream<_CharT, _Traits>& __os,
574 const __quoted_output_proxy<_CharT, _Iter, _Traits> & __proxy)
568template <class _CharT, class _Traits>
569struct _LIBCPP_HIDDEN __quoted_output_proxy
575570{
576 return __quoted_output (__os, __proxy.__first, __proxy.__last, __proxy.__delim, __proxy.__escape);
577}
571 const _CharT *__first_;
572 const _CharT *__last_;
573 _CharT __delim_;
574 _CharT __escape_;
578575
579template <class _CharT, class _Traits, class _Allocator>
580struct __quoted_proxy
581{
582 basic_string<_CharT, _Traits, _Allocator> &__string;
583 _CharT __delim;
584 _CharT __escape;
576 _LIBCPP_HIDE_FROM_ABI
577 explicit __quoted_output_proxy(const _CharT *__f, const _CharT *__l, _CharT __d, _CharT __e)
578 : __first_(__f), __last_(__l), __delim_(__d), __escape_(__e) {}
585579
586 __quoted_proxy(basic_string<_CharT, _Traits, _Allocator> &__s, _CharT __d, _CharT __e)
587 : __string(__s), __delim(__d), __escape(__e) {}
580 template<class _T2, __enable_if_t<_IsSame<_Traits, void>::value || _IsSame<_Traits, _T2>::value>* = nullptr>
581 friend _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _T2>&
582 operator<<(basic_ostream<_CharT, _T2>& __os, const __quoted_output_proxy& __p) {
583 return std::__quoted_output(__os, __p.__first_, __p.__last_, __p.__delim_, __p.__escape_);
584 }
588585};
589586
590587template <class _CharT, class _Traits, class _Allocator>
591_LIBCPP_INLINE_VISIBILITY
592basic_ostream<_CharT, _Traits>& operator<<(
593 basic_ostream<_CharT, _Traits>& __os,
594 const __quoted_proxy<_CharT, _Traits, _Allocator> & __proxy)
588struct _LIBCPP_HIDDEN __quoted_proxy
595589{
596 return __quoted_output (__os, __proxy.__string.cbegin (), __proxy.__string.cend (), __proxy.__delim, __proxy.__escape);
597}
598
599// extractor for non-const basic_string& proxies
600template <class _CharT, class _Traits, class _Allocator>
601_LIBCPP_INLINE_VISIBILITY
602basic_istream<_CharT, _Traits>& operator>>(
603 basic_istream<_CharT, _Traits>& __is,
604 const __quoted_proxy<_CharT, _Traits, _Allocator> & __proxy)
605{
606 return __quoted_input ( __is, __proxy.__string, __proxy.__delim, __proxy.__escape );
607}
590 basic_string<_CharT, _Traits, _Allocator>& __string_;
591 _CharT __delim_;
592 _CharT __escape_;
608593
594 _LIBCPP_HIDE_FROM_ABI
595 explicit __quoted_proxy(basic_string<_CharT, _Traits, _Allocator>& __s, _CharT __d, _CharT __e)
596 : __string_(__s), __delim_(__d), __escape_(__e) {}
609597
610template <class _CharT>
611_LIBCPP_INLINE_VISIBILITY
612__quoted_output_proxy<_CharT, const _CharT *>
613quoted ( const _CharT *__s, _CharT __delim = _CharT('"'), _CharT __escape =_CharT('\\'))
614{
615 const _CharT *__end = __s;
616 while ( *__end ) ++__end;
617 return __quoted_output_proxy<_CharT, const _CharT *> ( __s, __end, __delim, __escape );
618}
598 friend _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
599 operator<<(basic_ostream<_CharT, _Traits>& __os, const __quoted_proxy& __p) {
600 return std::__quoted_output(__os, __p.__string_.data(), __p.__string_.data() + __p.__string_.size(), __p.__delim_, __p.__escape_);
601 }
619602
603 friend _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
604 operator>>(basic_istream<_CharT, _Traits>& __is, const __quoted_proxy& __p) {
605 return std::__quoted_input(__is, __p.__string_, __p.__delim_, __p.__escape_);
606 }
607};
620608
621609template <class _CharT, class _Traits, class _Allocator>
622_LIBCPP_INLINE_VISIBILITY
623__quoted_output_proxy<_CharT, typename basic_string <_CharT, _Traits, _Allocator>::const_iterator>
624__quoted ( const basic_string <_CharT, _Traits, _Allocator> &__s, _CharT __delim = _CharT('"'), _CharT __escape=_CharT('\\'))
610_LIBCPP_HIDE_FROM_ABI
611__quoted_output_proxy<_CharT, _Traits>
612__quoted(const basic_string<_CharT, _Traits, _Allocator>& __s, _CharT __delim = _CharT('"'), _CharT __escape = _CharT('\\'))
625613{
626 return __quoted_output_proxy<_CharT,
627 typename basic_string <_CharT, _Traits, _Allocator>::const_iterator>
628 ( __s.cbegin(), __s.cend (), __delim, __escape );
614 return __quoted_output_proxy<_CharT, _Traits>(__s.data(), __s.data() + __s.size(), __delim, __escape);
629615}
630616
631617template <class _CharT, class _Traits, class _Allocator>
632_LIBCPP_INLINE_VISIBILITY
618_LIBCPP_HIDE_FROM_ABI
633619__quoted_proxy<_CharT, _Traits, _Allocator>
634__quoted ( basic_string <_CharT, _Traits, _Allocator> &__s, _CharT __delim = _CharT('"'), _CharT __escape=_CharT('\\'))
620__quoted(basic_string<_CharT, _Traits, _Allocator>& __s, _CharT __delim = _CharT('"'), _CharT __escape = _CharT('\\'))
635621{
636 return __quoted_proxy<_CharT, _Traits, _Allocator>( __s, __delim, __escape );
622 return __quoted_proxy<_CharT, _Traits, _Allocator>(__s, __delim, __escape);
637623}
638624
625#endif // _LIBCPP_STD_VER >= 11
639626
640627#if _LIBCPP_STD_VER > 11
641628
629template <class _CharT>
630_LIBCPP_HIDE_FROM_ABI
631auto quoted(const _CharT *__s, _CharT __delim = _CharT('"'), _CharT __escape = _CharT('\\'))
632{
633 const _CharT *__end = __s;
634 while (*__end) ++__end;
635 return __quoted_output_proxy<_CharT, void>(__s, __end, __delim, __escape);
636}
637
642638template <class _CharT, class _Traits, class _Allocator>
643_LIBCPP_INLINE_VISIBILITY
644__quoted_output_proxy<_CharT, typename basic_string <_CharT, _Traits, _Allocator>::const_iterator>
645quoted ( const basic_string <_CharT, _Traits, _Allocator> &__s, _CharT __delim = _CharT('"'), _CharT __escape=_CharT('\\'))
639_LIBCPP_HIDE_FROM_ABI
640auto quoted(const basic_string<_CharT, _Traits, _Allocator>& __s, _CharT __delim = _CharT('"'), _CharT __escape = _CharT('\\'))
646641{
647 return __quoted(__s, __delim, __escape);
642 return __quoted_output_proxy<_CharT, _Traits>(__s.data(), __s.data() + __s.size(), __delim, __escape);
648643}
649644
650645template <class _CharT, class _Traits, class _Allocator>
651_LIBCPP_INLINE_VISIBILITY
652__quoted_proxy<_CharT, _Traits, _Allocator>
653quoted ( basic_string <_CharT, _Traits, _Allocator> &__s, _CharT __delim = _CharT('"'), _CharT __escape=_CharT('\\'))
646_LIBCPP_HIDE_FROM_ABI
647auto quoted(basic_string<_CharT, _Traits, _Allocator>& __s, _CharT __delim = _CharT('"'), _CharT __escape = _CharT('\\'))
654648{
655 return __quoted(__s, __delim, __escape);
649 return __quoted_proxy<_CharT, _Traits, _Allocator>(__s, __delim, __escape);
656650}
657651
658652template <class _CharT, class _Traits>
659__quoted_output_proxy<_CharT, const _CharT *, _Traits>
660quoted (basic_string_view <_CharT, _Traits> __sv,
661 _CharT __delim = _CharT('"'), _CharT __escape=_CharT('\\'))
653_LIBCPP_HIDE_FROM_ABI
654auto quoted(basic_string_view<_CharT, _Traits> __sv, _CharT __delim = _CharT('"'), _CharT __escape = _CharT('\\'))
662655{
663 return __quoted_output_proxy<_CharT, const _CharT *, _Traits>
664 ( __sv.data(), __sv.data() + __sv.size(), __delim, __escape );
656 return __quoted_output_proxy<_CharT, _Traits>(__sv.data(), __sv.data() + __sv.size(), __delim, __escape);
665657}
666#endif
658
659#endif // _LIBCPP_STD_VER > 11
667660
668661_LIBCPP_END_NAMESPACE_STD
669662
lib/libcxx/include/ios+15-3
......@@ -211,17 +211,27 @@ storage-class-specifier const error_category& iostream_category() noexcept;
211211*/
212212
213213#include <__config>
214
215#if defined(_LIBCPP_HAS_NO_LOCALIZATION)
216# error "The iostreams library is not supported since libc++ has been configured without support for localization."
217#endif
218
219#include <__assert> // all public C++ headers provide the assertion handler
220#include <__ios/fpos.h>
214221#include <__locale>
215#include <iosfwd>
222#include <__utility/swap.h>
216223#include <system_error>
217224#include <version>
218225
226// standard-mandated includes
227#include <iosfwd>
228
219229#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
220230#include <atomic> // for __xindex_
221231#endif
222232
223233#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
224#pragma GCC system_header
234# pragma GCC system_header
225235#endif
226236
227237_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -402,7 +412,7 @@ _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(io_errc)
402412template <>
403413struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<io_errc> : public true_type { };
404414
405#ifdef _LIBCPP_HAS_NO_STRONG_ENUMS
415#ifdef _LIBCPP_CXX03_LANG
406416template <>
407417struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<io_errc::__lx> : public true_type { };
408418#endif
......@@ -780,6 +790,8 @@ inline _LIBCPP_INLINE_VISIBILITY
780790_CharT
781791basic_ios<_CharT, _Traits>::fill(char_type __ch)
782792{
793 if (traits_type::eq_int_type(traits_type::eof(), __fill_))
794 __fill_ = widen(' ');
783795 char_type __r = __fill_;
784796 __fill_ = __ch;
785797 return __r;
lib/libcxx/include/iosfwd+2-3
......@@ -94,12 +94,13 @@ using u32streampos = fpos<char_traits<char32_t>::state_type>;
9494
9595*/
9696
97#include <__assert> // all public C++ headers provide the assertion handler
9798#include <__config>
9899#include <__mbstate_t.h>
99100#include <version>
100101
101102#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
102#pragma GCC system_header
103# pragma GCC system_header
103104#endif
104105
105106_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -231,10 +232,8 @@ typedef fpos<mbstate_t> wstreampos;
231232#ifndef _LIBCPP_HAS_NO_CHAR8_T
232233typedef fpos<mbstate_t> u8streampos;
233234#endif
234#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
235235typedef fpos<mbstate_t> u16streampos;
236236typedef fpos<mbstate_t> u32streampos;
237#endif
238237
239238#if defined(_NEWLIB_VERSION)
240239// On newlib, off_t is 'long int'
lib/libcxx/include/iostream+5-2
......@@ -33,15 +33,18 @@ extern wostream wclog;
3333
3434*/
3535
36#include <__assert> // all public C++ headers provide the assertion handler
3637#include <__config>
38#include <version>
39
40// standard-mandated includes
3741#include <ios>
3842#include <istream>
3943#include <ostream>
4044#include <streambuf>
41#include <version>
4245
4346#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
44#pragma GCC system_header
47# pragma GCC system_header
4548#endif
4649
4750_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/istream+7-5
......@@ -158,13 +158,15 @@ template <class Stream, class T>
158158
159159*/
160160
161#include <__assert> // all public C++ headers provide the assertion handler
161162#include <__config>
163#include <__iterator/istreambuf_iterator.h>
162164#include <__utility/forward.h>
163165#include <ostream>
164166#include <version>
165167
166168#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
167#pragma GCC system_header
169# pragma GCC system_header
168170#endif
169171
170172_LIBCPP_PUSH_MACROS
......@@ -1592,7 +1594,7 @@ operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x)
15921594 size_t __c = 0;
15931595 _CharT __zero = __ct.widen('0');
15941596 _CharT __one = __ct.widen('1');
1595 while (__c < _Size)
1597 while (__c != _Size)
15961598 {
15971599 typename _Traits::int_type __i = __is.rdbuf()->sgetc();
15981600 if (_Traits::eq_int_type(__i, _Traits::eof()))
......@@ -1627,11 +1629,11 @@ operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x)
16271629 return __is;
16281630}
16291631
1630_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istream<char>)
1632extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istream<char>;
16311633#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1632_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istream<wchar_t>)
1634extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istream<wchar_t>;
16331635#endif
1634_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_iostream<char>)
1636extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_iostream<char>;
16351637
16361638_LIBCPP_END_NAMESPACE_STD
16371639
lib/libcxx/include/iterator+132-29
......@@ -136,6 +136,13 @@ template<class In, class Out>
136136template<class In, class Out>
137137 concept indirectly_movable_storable = see below; // since C++20
138138
139// [alg.req.ind.copy], concept indirectly_copyable
140template<class In, class Out>
141 concept indirectly_copyable = see below; // since C++20
142
143template<class In, class Out>
144 concept indirectly_copyable_storable = see below; // since C++20
145
139146// [alg.req.ind.swap], concept indirectly_swappable
140147template<class I1, class I2 = I1>
141148 concept indirectly_swappable = see below; // since C++20
......@@ -145,6 +152,19 @@ template<class I1, class I2, class R, class P1 = identity,
145152 concept indirectly_comparable =
146153 indirect_binary_predicate<R, projected<I1, P1>, projected<I2, P2>>; // since C++20
147154
155// [alg.req.permutable], concept permutable
156template<class I>
157 concept permutable = see below; // since C++20
158
159 // [alg.req.mergeable], concept mergeable
160template<class I1, class I2, class Out,
161 class R = ranges::less, class P1 = identity, class P2 = identity>
162 concept mergeable = see below; // since C++20
163
164// [alg.req.sortable], concept sortable
165template<class I, class R = ranges::less, class P = identity>
166 concept sortable = see below; // since C++20
167
148168template<input_or_output_iterator I, sentinel_for<I> S>
149169 requires (!same_as<I, S> && copyable<I>)
150170class common_iterator; // since C++20
......@@ -165,6 +185,7 @@ struct output_iterator_tag {};
165185struct forward_iterator_tag : public input_iterator_tag {};
166186struct bidirectional_iterator_tag : public forward_iterator_tag {};
167187struct random_access_iterator_tag : public bidirectional_iterator_tag {};
188struct contiguous_iterator_tag : public random_access_iterator_tag {};
168189
169190// 27.4.3, iterator operations
170191template <class InputIterator, class Distance> // constexpr in C++17
......@@ -204,10 +225,17 @@ class reverse_iterator
204225protected:
205226 Iterator current;
206227public:
207 typedef Iterator iterator_type;
208 typedef typename iterator_traits<Iterator>::difference_type difference_type;
209 typedef typename iterator_traits<Iterator>::reference reference;
210 typedef typename iterator_traits<Iterator>::pointer pointer;
228 using iterator_type = Iterator;
229 using iterator_concept = see below; // since C++20
230 using iterator_category = typename iterator_traits<Iterator>::iterator_category; // since C++17, until C++20
231 using iterator_category = see below; // since C++20
232 using value_type = typename iterator_traits<Iterator>::value_type; // since C++17, until C++20
233 using value_type = iter_value_t<Iterator>; // since C++20
234 using difference_type = typename iterator_traits<Iterator>::difference_type; // until C++20
235 using difference_type = iter_difference_t<Iterator>; // since C++20
236 using pointer = typename iterator_traits<Iterator>::pointer;
237 using reference = typename iterator_traits<Iterator>::reference; // until C++20
238 using reference = iter_reference_t<Iterator>; // since C++20
211239
212240 constexpr reverse_iterator();
213241 constexpr explicit reverse_iterator(Iterator x);
......@@ -215,7 +243,8 @@ public:
215243 template <class U> constexpr reverse_iterator& operator=(const reverse_iterator<U>& u);
216244 constexpr Iterator base() const;
217245 constexpr reference operator*() const;
218 constexpr pointer operator->() const;
246 constexpr pointer operator->() const; // until C++20
247 constexpr pointer operator->() const requires see below; // since C++20
219248 constexpr reverse_iterator& operator++();
220249 constexpr reverse_iterator operator++(int);
221250 constexpr reverse_iterator& operator--();
......@@ -224,7 +253,14 @@ public:
224253 constexpr reverse_iterator& operator+=(difference_type n);
225254 constexpr reverse_iterator operator- (difference_type n) const;
226255 constexpr reverse_iterator& operator-=(difference_type n);
227 constexpr reference operator[](difference_type n) const;
256 constexpr unspecified operator[](difference_type n) const;
257
258 friend constexpr iter_rvalue_reference_t<Iterator>
259 iter_move(const reverse_iterator& i) noexcept(see below);
260 template<indirectly_swappable<Iterator> Iterator2>
261 friend constexpr void
262 iter_swap(const reverse_iterator& x,
263 const reverse_iterator<Iterator2>& y) noexcept(see below);
228264};
229265
230266template <class Iterator1, class Iterator2>
......@@ -233,11 +269,11 @@ operator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator
233269
234270template <class Iterator1, class Iterator2>
235271constexpr bool // constexpr in C++17
236operator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
272operator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
237273
238274template <class Iterator1, class Iterator2>
239275constexpr bool // constexpr in C++17
240operator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
276operator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
241277
242278template <class Iterator1, class Iterator2>
243279constexpr bool // constexpr in C++17
......@@ -245,11 +281,16 @@ operator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2
245281
246282template <class Iterator1, class Iterator2>
247283constexpr bool // constexpr in C++17
248operator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
284operator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
249285
250286template <class Iterator1, class Iterator2>
251287constexpr bool // constexpr in C++17
252operator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
288operator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
289
290template<class Iterator1, three_way_comparable_with<Iterator1> Iterator2>
291 constexpr compare_three_way_result_t<Iterator1, Iterator2>
292 operator<=>(const reverse_iterator<Iterator1>& x,
293 const reverse_iterator<Iterator2>& y);
253294
254295template <class Iterator1, class Iterator2>
255296constexpr auto
......@@ -264,6 +305,11 @@ operator+(typename reverse_iterator<Iterator>::difference_type n,
264305template <class Iterator>
265306constexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14, constexpr in C++17
266307
308template<class Iterator1, class Iterator2>
309 requires (!sized_sentinel_for<Iterator1, Iterator2>)
310 inline constexpr bool disable_sized_sentinel_for<reverse_iterator<Iterator1>,
311 reverse_iterator<Iterator2>> = true;
312
267313template <class Container>
268314class back_insert_iterator
269315 : public iterator<output_iterator_tag, void, void, void, void> // until C++17
......@@ -332,18 +378,21 @@ public:
332378 insert_iterator& operator++(int); // constexpr in C++20
333379};
334380
335template <class Container, class Iterator>
336insert_iterator<Container> inserter(Container& x, Iterator i); // constexpr in C++20
381template <class Container>
382insert_iterator<Container> inserter(Container& x, typename Container::iterator i); // until C++20
383template <class Container>
384constexpr insert_iterator<Container> inserter(Container& x, ranges::iterator_t<Container> i); // since C++20
337385
338386template <class Iterator>
339387class move_iterator {
340388public:
341 typedef Iterator iterator_type;
342 typedef typename iterator_traits<Iterator>::difference_type difference_type;
343 typedef Iterator pointer;
344 typedef typename iterator_traits<Iterator>::value_type value_type;
345 typedef typename iterator_traits<Iterator>::iterator_category iterator_category;
346 typedef value_type&& reference;
389 using iterator_type = Iterator;
390 using iterator_concept = input_iterator_tag; // From C++20
391 using iterator_category = see below; // not always present starting from C++20
392 using value_type = iter_value_t<Iterator>; // Until C++20, iterator_traits<Iterator>::value_type
393 using difference_type = iter_difference_t<Iterator>; // Until C++20, iterator_traits<Iterator>::difference_type;
394 using pointer = Iterator;
395 using reference = iter_rvalue_reference_t<Iterator>; // Until C++20, value_type&&
347396
348397 constexpr move_iterator(); // all the constexprs are in C++17
349398 constexpr explicit move_iterator(Iterator i);
......@@ -351,18 +400,40 @@ public:
351400 constexpr move_iterator(const move_iterator<U>& u);
352401 template <class U>
353402 constexpr move_iterator& operator=(const move_iterator<U>& u);
354 constexpr iterator_type base() const;
403
404 constexpr iterator_type base() const; // Until C++20
405 constexpr const Iterator& base() const & noexcept; // From C++20
406 constexpr Iterator base() &&; // From C++20
407
355408 constexpr reference operator*() const;
356 constexpr pointer operator->() const;
409 constexpr pointer operator->() const; // Deprecated in C++20
357410 constexpr move_iterator& operator++();
358 constexpr move_iterator operator++(int);
411 constexpr auto operator++(int); // Return type was move_iterator until C++20
359412 constexpr move_iterator& operator--();
360413 constexpr move_iterator operator--(int);
361414 constexpr move_iterator operator+(difference_type n) const;
362415 constexpr move_iterator& operator+=(difference_type n);
363416 constexpr move_iterator operator-(difference_type n) const;
364417 constexpr move_iterator& operator-=(difference_type n);
365 constexpr unspecified operator[](difference_type n) const;
418 constexpr reference operator[](difference_type n) const; // Return type unspecified until C++20
419
420 template<sentinel_for<Iterator> S>
421 friend constexpr bool
422 operator==(const move_iterator& x, const move_sentinel<S>& y); // Since C++20
423 template<sized_sentinel_for<Iterator> S>
424 friend constexpr iter_difference_t<Iterator>
425 operator-(const move_sentinel<S>& x, const move_iterator& y); // Since C++20
426 template<sized_sentinel_for<Iterator> S>
427 friend constexpr iter_difference_t<Iterator>
428 operator-(const move_iterator& x, const move_sentinel<S>& y); // Since C++20
429 friend constexpr iter_rvalue_reference_t<Iterator>
430 iter_move(const move_iterator& i)
431 noexcept(noexcept(ranges::iter_move(i.current))); // Since C++20
432 template<indirectly_swappable<Iterator> Iterator2>
433 friend constexpr void
434 iter_swap(const move_iterator& x, const move_iterator<Iterator2>& y)
435 noexcept(noexcept(ranges::iter_swap(x.current, y.current))); // Since C++20
436
366437private:
367438 Iterator current; // exposition only
368439};
......@@ -404,6 +475,23 @@ constexpr move_iterator<Iterator> operator+( // constexpr in C++17
404475template <class Iterator> // constexpr in C++17
405476constexpr move_iterator<Iterator> make_move_iterator(const Iterator& i);
406477
478template<semiregular S>
479class move_sentinel {
480public:
481 constexpr move_sentinel();
482 constexpr explicit move_sentinel(S s);
483 template<class S2>
484 requires convertible_to<const S2&, S>
485 constexpr move_sentinel(const move_sentinel<S2>& s);
486 template<class S2>
487 requires assignable_from<S&, const S2&>
488 constexpr move_sentinel& operator=(const move_sentinel<S2>& s);
489
490 constexpr S base() const;
491private:
492 S last; // exposition only
493};
494
407495// [default.sentinel], default sentinel
408496struct default_sentinel_t;
409497inline constexpr default_sentinel_t default_sentinel{};
......@@ -434,7 +522,8 @@ public:
434522 typedef traits traits_type;
435523 typedef basic_istream<charT, traits> istream_type;
436524
437 constexpr istream_iterator();
525 istream_iterator(); // constexpr since C++11
526 constexpr istream_iterator(default_sentinel_t); // since C++20
438527 istream_iterator(istream_type& s);
439528 istream_iterator(const istream_iterator& x);
440529 ~istream_iterator();
......@@ -443,6 +532,7 @@ public:
443532 const T* operator->() const;
444533 istream_iterator& operator++();
445534 istream_iterator operator++(int);
535 friend bool operator==(const istream_iterator& i, default_sentinel_t); // since C++20
446536};
447537
448538template <class T, class charT, class traits, class Distance>
......@@ -450,7 +540,7 @@ bool operator==(const istream_iterator<T,charT,traits,Distance>& x,
450540 const istream_iterator<T,charT,traits,Distance>& y);
451541template <class T, class charT, class traits, class Distance>
452542bool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
453 const istream_iterator<T,charT,traits,Distance>& y);
543 const istream_iterator<T,charT,traits,Distance>& y); // until C++20
454544
455545template <class T, class charT = char, class traits = char_traits<charT> >
456546class ostream_iterator
......@@ -496,7 +586,8 @@ public:
496586 typedef basic_streambuf<charT, traits> streambuf_type;
497587 typedef basic_istream<charT, traits> istream_type;
498588
499 istreambuf_iterator() noexcept;
589 istreambuf_iterator() noexcept; // constexpr since C++11
590 constexpr istreambuf_iterator(default_sentinel_t) noexcept; // since C++20
500591 istreambuf_iterator(istream_type& s) noexcept;
501592 istreambuf_iterator(streambuf_type* s) noexcept;
502593 istreambuf_iterator(a-private-type) noexcept;
......@@ -507,6 +598,7 @@ public:
507598 a-private-type operator++(int);
508599
509600 bool equal(const istreambuf_iterator& b) const;
601 friend bool operator==(const istreambuf_iterator& i, default_sentinel_t s); // since C++20
510602};
511603
512604template <class charT, class traits>
......@@ -514,7 +606,7 @@ bool operator==(const istreambuf_iterator<charT,traits>& a,
514606 const istreambuf_iterator<charT,traits>& b);
515607template <class charT, class traits>
516608bool operator!=(const istreambuf_iterator<charT,traits>& a,
517 const istreambuf_iterator<charT,traits>& b);
609 const istreambuf_iterator<charT,traits>& b); // until C++20
518610
519611template <class charT, class traits = char_traits<charT> >
520612class ostreambuf_iterator
......@@ -582,12 +674,13 @@ template <class E> constexpr const E* data(initializer_list<E> il) noexcept;
582674
583675*/
584676
677#include <__assert> // all public C++ headers provide the assertion handler
585678#include <__config>
586679#include <__debug>
587#include <__functional_base>
588680#include <__iterator/access.h>
589681#include <__iterator/advance.h>
590682#include <__iterator/back_insert_iterator.h>
683#include <__iterator/bounded_iter.h>
591684#include <__iterator/common_iterator.h>
592685#include <__iterator/concepts.h>
593686#include <__iterator/counted_iterator.h>
......@@ -606,21 +699,24 @@ template <class E> constexpr const E* data(initializer_list<E> il) noexcept;
606699#include <__iterator/iter_swap.h>
607700#include <__iterator/iterator.h>
608701#include <__iterator/iterator_traits.h>
702#include <__iterator/mergeable.h>
609703#include <__iterator/move_iterator.h>
704#include <__iterator/move_sentinel.h>
610705#include <__iterator/next.h>
611706#include <__iterator/ostream_iterator.h>
612707#include <__iterator/ostreambuf_iterator.h>
708#include <__iterator/permutable.h>
613709#include <__iterator/prev.h>
614710#include <__iterator/projected.h>
615711#include <__iterator/readable_traits.h>
616712#include <__iterator/reverse_access.h>
617713#include <__iterator/reverse_iterator.h>
618714#include <__iterator/size.h>
715#include <__iterator/sortable.h>
619716#include <__iterator/unreachable_sentinel.h>
620717#include <__iterator/wrap_iter.h>
621718#include <__memory/addressof.h>
622719#include <__memory/pointer_traits.h>
623#include <__utility/forward.h>
624720#include <compare>
625721#include <concepts> // Mandated by the Standard.
626722#include <cstddef>
......@@ -628,8 +724,15 @@ template <class E> constexpr const E* data(initializer_list<E> il) noexcept;
628724#include <type_traits>
629725#include <version>
630726
727#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
728# include <exception>
729# include <new>
730# include <typeinfo>
731# include <utility>
732#endif
733
631734#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
632#pragma GCC system_header
735# pragma GCC system_header
633736#endif
634737
635738#endif // _LIBCPP_ITERATOR
lib/libcxx/include/latch+6-5
......@@ -40,17 +40,19 @@ namespace std
4040
4141*/
4242
43#include <__assert> // all public C++ headers provide the assertion handler
4344#include <__availability>
4445#include <__config>
4546#include <atomic>
47#include <limits>
4648#include <version>
4749
4850#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
49#pragma GCC system_header
51# pragma GCC system_header
5052#endif
5153
5254#ifdef _LIBCPP_HAS_NO_THREADS
53# error <latch> is not supported on this single threaded system
55# error "<latch> is not supported since libc++ has been configured without support for threads."
5456#endif
5557
5658_LIBCPP_PUSH_MACROS
......@@ -91,10 +93,9 @@ public:
9193 inline _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
9294 void wait() const
9395 {
94 auto const __test_fn = [=]() -> bool {
96 __cxx_atomic_wait(&__a.__a_, [&]() -> bool {
9597 return try_wait();
96 };
97 __cxx_atomic_wait(&__a.__a_, __test_fn);
98 });
9899 }
99100 inline _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
100101 void arrive_and_wait(ptrdiff_t __update = 1)
lib/libcxx/include/limits+15-5
......@@ -101,6 +101,8 @@ template<> class numeric_limits<cv long double>;
101101} // std
102102
103103*/
104
105#include <__assert> // all public C++ headers provide the assertion handler
104106#include <__config>
105107#include <type_traits>
106108
......@@ -108,12 +110,8 @@ template<> class numeric_limits<cv long double>;
108110#include "__support/win32/limits_msvc_win32.h"
109111#endif // _LIBCPP_MSVCRT
110112
111#if defined(__IBMCPP__)
112#include "__support/ibm/limits.h"
113#endif // __IBMCPP__
114
115113#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
116#pragma GCC system_header
114# pragma GCC system_header
117115#endif
118116
119117_LIBCPP_PUSH_MACROS
......@@ -339,7 +337,11 @@ protected:
339337 static _LIBCPP_CONSTEXPR const bool is_modulo = false;
340338
341339 static _LIBCPP_CONSTEXPR const bool traps = false;
340#if (defined(__arm__) || defined(__aarch64__))
341 static _LIBCPP_CONSTEXPR const bool tinyness_before = true;
342#else
342343 static _LIBCPP_CONSTEXPR const bool tinyness_before = false;
344#endif
343345 static _LIBCPP_CONSTEXPR const float_round_style round_style = round_to_nearest;
344346};
345347
......@@ -385,7 +387,11 @@ protected:
385387 static _LIBCPP_CONSTEXPR const bool is_modulo = false;
386388
387389 static _LIBCPP_CONSTEXPR const bool traps = false;
390#if (defined(__arm__) || defined(__aarch64__))
391 static _LIBCPP_CONSTEXPR const bool tinyness_before = true;
392#else
388393 static _LIBCPP_CONSTEXPR const bool tinyness_before = false;
394#endif
389395 static _LIBCPP_CONSTEXPR const float_round_style round_style = round_to_nearest;
390396};
391397
......@@ -435,7 +441,11 @@ protected:
435441 static _LIBCPP_CONSTEXPR const bool is_modulo = false;
436442
437443 static _LIBCPP_CONSTEXPR const bool traps = false;
444#if (defined(__arm__) || defined(__aarch64__))
445 static _LIBCPP_CONSTEXPR const bool tinyness_before = true;
446#else
438447 static _LIBCPP_CONSTEXPR const bool tinyness_before = false;
448#endif
439449 static _LIBCPP_CONSTEXPR const float_round_style round_style = round_to_nearest;
440450};
441451
lib/libcxx/include/limits.h+1-1
......@@ -40,7 +40,7 @@ Macros:
4040#include <__config>
4141
4242#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
43#pragma GCC system_header
43# pragma GCC system_header
4444#endif
4545
4646#ifndef __GNUC__
lib/libcxx/include/list+97-148
......@@ -180,19 +180,50 @@ template <class T, class Allocator, class Predicate>
180180
181181*/
182182
183#include <__algorithm/comp.h>
184#include <__algorithm/equal.h>
185#include <__algorithm/lexicographical_compare.h>
186#include <__algorithm/min.h>
187#include <__assert> // all public C++ headers provide the assertion handler
183188#include <__config>
184189#include <__debug>
190#include <__format/enable_insertable.h>
191#include <__iterator/distance.h>
192#include <__iterator/iterator_traits.h>
193#include <__iterator/move_iterator.h>
194#include <__iterator/next.h>
195#include <__iterator/prev.h>
196#include <__iterator/reverse_iterator.h>
197#include <__memory/swap_allocator.h>
185198#include <__utility/forward.h>
186#include <algorithm>
187#include <initializer_list>
188#include <iterator>
199#include <__utility/move.h>
200#include <__utility/swap.h>
189201#include <limits>
190202#include <memory>
191203#include <type_traits>
192204#include <version>
193205
206#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
207# include <algorithm>
208# include <functional>
209# include <iterator>
210#endif
211
212// standard-mandated includes
213
214// [iterator.range]
215#include <__iterator/access.h>
216#include <__iterator/data.h>
217#include <__iterator/empty.h>
218#include <__iterator/reverse_access.h>
219#include <__iterator/size.h>
220
221// [list.syn]
222#include <compare>
223#include <initializer_list>
224
194225#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
195#pragma GCC system_header
226# pragma GCC system_header
196227#endif
197228
198229_LIBCPP_PUSH_MACROS
......@@ -292,19 +323,15 @@ class _LIBCPP_TEMPLATE_VIS __list_iterator
292323
293324 __link_pointer __ptr_;
294325
295#if _LIBCPP_DEBUG_LEVEL == 2
296326 _LIBCPP_INLINE_VISIBILITY
297327 explicit __list_iterator(__link_pointer __p, const void* __c) _NOEXCEPT
298328 : __ptr_(__p)
299329 {
330 (void)__c;
331#ifdef _LIBCPP_ENABLE_DEBUG_MODE
300332 __get_db()->__insert_ic(this, __c);
301 }
302#else
303 _LIBCPP_INLINE_VISIBILITY
304 explicit __list_iterator(__link_pointer __p) _NOEXCEPT : __ptr_(__p) {}
305333#endif
306
307
334 }
308335
309336 template<class, class> friend class list;
310337 template<class, class> friend class __list_imp;
......@@ -322,7 +349,7 @@ public:
322349 _VSTD::__debug_db_insert_i(this);
323350 }
324351
325#if _LIBCPP_DEBUG_LEVEL == 2
352#ifdef _LIBCPP_ENABLE_DEBUG_MODE
326353
327354 _LIBCPP_INLINE_VISIBILITY
328355 __list_iterator(const __list_iterator& __p)
......@@ -348,7 +375,7 @@ public:
348375 return *this;
349376 }
350377
351#endif // _LIBCPP_DEBUG_LEVEL == 2
378#endif // _LIBCPP_ENABLE_DEBUG_MODE
352379
353380 _LIBCPP_INLINE_VISIBILITY
354381 reference operator*() const
......@@ -405,17 +432,15 @@ class _LIBCPP_TEMPLATE_VIS __list_const_iterator
405432
406433 __link_pointer __ptr_;
407434
408#if _LIBCPP_DEBUG_LEVEL == 2
409435 _LIBCPP_INLINE_VISIBILITY
410436 explicit __list_const_iterator(__link_pointer __p, const void* __c) _NOEXCEPT
411437 : __ptr_(__p)
412438 {
439 (void)__c;
440#ifdef _LIBCPP_ENABLE_DEBUG_MODE
413441 __get_db()->__insert_ic(this, __c);
414 }
415#else
416 _LIBCPP_INLINE_VISIBILITY
417 explicit __list_const_iterator(__link_pointer __p) _NOEXCEPT : __ptr_(__p) {}
418442#endif
443 }
419444
420445 template<class, class> friend class list;
421446 template<class, class> friend class __list_imp;
......@@ -435,12 +460,12 @@ public:
435460 __list_const_iterator(const __list_iterator<_Tp, _VoidPtr>& __p) _NOEXCEPT
436461 : __ptr_(__p.__ptr_)
437462 {
438#if _LIBCPP_DEBUG_LEVEL == 2
463#ifdef _LIBCPP_ENABLE_DEBUG_MODE
439464 __get_db()->__iterator_copy(this, _VSTD::addressof(__p));
440465#endif
441466 }
442467
443#if _LIBCPP_DEBUG_LEVEL == 2
468#ifdef _LIBCPP_ENABLE_DEBUG_MODE
444469
445470 _LIBCPP_INLINE_VISIBILITY
446471 __list_const_iterator(const __list_const_iterator& __p)
......@@ -466,7 +491,7 @@ public:
466491 return *this;
467492 }
468493
469#endif // _LIBCPP_DEBUG_LEVEL == 2
494#endif // _LIBCPP_ENABLE_DEBUG_MODE
470495 _LIBCPP_INLINE_VISIBILITY
471496 reference operator*() const
472497 {
......@@ -593,38 +618,22 @@ protected:
593618 _LIBCPP_INLINE_VISIBILITY
594619 iterator begin() _NOEXCEPT
595620 {
596#if _LIBCPP_DEBUG_LEVEL == 2
597621 return iterator(__end_.__next_, this);
598#else
599 return iterator(__end_.__next_);
600#endif
601622 }
602623 _LIBCPP_INLINE_VISIBILITY
603624 const_iterator begin() const _NOEXCEPT
604625 {
605#if _LIBCPP_DEBUG_LEVEL == 2
606626 return const_iterator(__end_.__next_, this);
607#else
608 return const_iterator(__end_.__next_);
609#endif
610627 }
611628 _LIBCPP_INLINE_VISIBILITY
612629 iterator end() _NOEXCEPT
613630 {
614#if _LIBCPP_DEBUG_LEVEL == 2
615631 return iterator(__end_as_link(), this);
616#else
617 return iterator(__end_as_link());
618#endif
619632 }
620633 _LIBCPP_INLINE_VISIBILITY
621634 const_iterator end() const _NOEXCEPT
622635 {
623#if _LIBCPP_DEBUG_LEVEL == 2
624636 return const_iterator(__end_as_link(), this);
625#else
626 return const_iterator(__end_as_link());
627#endif
628637 }
629638
630639 void swap(__list_imp& __c)
......@@ -672,13 +681,6 @@ private:
672681 void __move_assign_alloc(__list_imp&, false_type)
673682 _NOEXCEPT
674683 {}
675
676 _LIBCPP_INLINE_VISIBILITY
677 void __invalidate_all_iterators() {
678#if _LIBCPP_DEBUG_LEVEL == 2
679 __get_db()->__invalidate_all(this);
680#endif
681 }
682684};
683685
684686// Unlink nodes [__f, __l]
......@@ -720,9 +722,7 @@ inline __list_imp<_Tp, _Alloc>::__list_imp(__node_allocator&& __a) _NOEXCEPT
720722template <class _Tp, class _Alloc>
721723__list_imp<_Tp, _Alloc>::~__list_imp() {
722724 clear();
723#if _LIBCPP_DEBUG_LEVEL == 2
724 __get_db()->__erase_c(this);
725#endif
725 std::__debug_db_erase_c(this);
726726}
727727
728728template <class _Tp, class _Alloc>
......@@ -743,7 +743,7 @@ __list_imp<_Tp, _Alloc>::clear() _NOEXCEPT
743743 __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
744744 __node_alloc_traits::deallocate(__na, __np, 1);
745745 }
746 __invalidate_all_iterators();
746 std::__debug_db_invalidate_all(this);
747747 }
748748}
749749
......@@ -774,7 +774,7 @@ __list_imp<_Tp, _Alloc>::swap(__list_imp& __c)
774774 else
775775 __c.__end_.__prev_->__next_ = __c.__end_.__next_->__prev_ = __c.__end_as_link();
776776
777#if _LIBCPP_DEBUG_LEVEL == 2
777#ifdef _LIBCPP_ENABLE_DEBUG_MODE
778778 __libcpp_db* __db = __get_db();
779779 __c_node* __cn1 = __db->__find_c_and_lock(this);
780780 __c_node* __cn2 = __db->__find_c(_VSTD::addressof(__c));
......@@ -871,13 +871,13 @@ public:
871871
872872 template <class _InpIter>
873873 list(_InpIter __f, _InpIter __l,
874 typename enable_if<__is_cpp17_input_iterator<_InpIter>::value>::type* = 0);
874 __enable_if_t<__is_cpp17_input_iterator<_InpIter>::value>* = 0);
875875 template <class _InpIter>
876876 list(_InpIter __f, _InpIter __l, const allocator_type& __a,
877 typename enable_if<__is_cpp17_input_iterator<_InpIter>::value>::type* = 0);
877 __enable_if_t<__is_cpp17_input_iterator<_InpIter>::value>* = 0);
878878
879879 list(const list& __c);
880 list(const list& __c, const __identity_t<allocator_type>& __a);
880 list(const list& __c, const __type_identity_t<allocator_type>& __a);
881881 _LIBCPP_INLINE_VISIBILITY
882882 list& operator=(const list& __c);
883883#ifndef _LIBCPP_CXX03_LANG
......@@ -888,7 +888,7 @@ public:
888888 list(list&& __c)
889889 _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value);
890890 _LIBCPP_INLINE_VISIBILITY
891 list(list&& __c, const __identity_t<allocator_type>& __a);
891 list(list&& __c, const __type_identity_t<allocator_type>& __a);
892892 _LIBCPP_INLINE_VISIBILITY
893893 list& operator=(list&& __c)
894894 _NOEXCEPT_(
......@@ -906,7 +906,7 @@ public:
906906
907907 template <class _InpIter>
908908 void assign(_InpIter __f, _InpIter __l,
909 typename enable_if<__is_cpp17_input_iterator<_InpIter>::value>::type* = 0);
909 __enable_if_t<__is_cpp17_input_iterator<_InpIter>::value>* = 0);
910910 void assign(size_type __n, const value_type& __x);
911911
912912 _LIBCPP_INLINE_VISIBILITY
......@@ -1023,7 +1023,7 @@ public:
10231023 iterator insert(const_iterator __p, size_type __n, const value_type& __x);
10241024 template <class _InpIter>
10251025 iterator insert(const_iterator __p, _InpIter __f, _InpIter __l,
1026 typename enable_if<__is_cpp17_input_iterator<_InpIter>::value>::type* = 0);
1026 __enable_if_t<__is_cpp17_input_iterator<_InpIter>::value>* = 0);
10271027
10281028 _LIBCPP_INLINE_VISIBILITY
10291029 void swap(list& __c)
......@@ -1099,14 +1099,14 @@ public:
10991099 return __hold_pointer(__p, __node_destructor(__na, 1));
11001100 }
11011101
1102#if _LIBCPP_DEBUG_LEVEL == 2
1102#ifdef _LIBCPP_ENABLE_DEBUG_MODE
11031103
11041104 bool __dereferenceable(const const_iterator* __i) const;
11051105 bool __decrementable(const const_iterator* __i) const;
11061106 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
11071107 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
11081108
1109#endif // _LIBCPP_DEBUG_LEVEL == 2
1109#endif // _LIBCPP_ENABLE_DEBUG_MODE
11101110
11111111private:
11121112 _LIBCPP_INLINE_VISIBILITY
......@@ -1221,7 +1221,7 @@ list<_Tp, _Alloc>::list(size_type __n, const value_type& __x)
12211221template <class _Tp, class _Alloc>
12221222template <class _InpIter>
12231223list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l,
1224 typename enable_if<__is_cpp17_input_iterator<_InpIter>::value>::type*)
1224 __enable_if_t<__is_cpp17_input_iterator<_InpIter>::value>*)
12251225{
12261226 _VSTD::__debug_db_insert_c(this);
12271227 for (; __f != __l; ++__f)
......@@ -1231,7 +1231,7 @@ list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l,
12311231template <class _Tp, class _Alloc>
12321232template <class _InpIter>
12331233list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l, const allocator_type& __a,
1234 typename enable_if<__is_cpp17_input_iterator<_InpIter>::value>::type*)
1234 __enable_if_t<__is_cpp17_input_iterator<_InpIter>::value>*)
12351235 : base(__a)
12361236{
12371237 _VSTD::__debug_db_insert_c(this);
......@@ -1249,7 +1249,7 @@ list<_Tp, _Alloc>::list(const list& __c)
12491249}
12501250
12511251template <class _Tp, class _Alloc>
1252list<_Tp, _Alloc>::list(const list& __c, const __identity_t<allocator_type>& __a)
1252list<_Tp, _Alloc>::list(const list& __c, const __type_identity_t<allocator_type>& __a)
12531253 : base(__a)
12541254{
12551255 _VSTD::__debug_db_insert_c(this);
......@@ -1288,7 +1288,7 @@ inline list<_Tp, _Alloc>::list(list&& __c)
12881288
12891289template <class _Tp, class _Alloc>
12901290inline
1291list<_Tp, _Alloc>::list(list&& __c, const __identity_t<allocator_type>& __a)
1291list<_Tp, _Alloc>::list(list&& __c, const __type_identity_t<allocator_type>& __a)
12921292 : base(__a)
12931293{
12941294 _VSTD::__debug_db_insert_c(this);
......@@ -1356,7 +1356,7 @@ template <class _Tp, class _Alloc>
13561356template <class _InpIter>
13571357void
13581358list<_Tp, _Alloc>::assign(_InpIter __f, _InpIter __l,
1359 typename enable_if<__is_cpp17_input_iterator<_InpIter>::value>::type*)
1359 __enable_if_t<__is_cpp17_input_iterator<_InpIter>::value>*)
13601360{
13611361 iterator __i = begin();
13621362 iterator __e = end();
......@@ -1366,9 +1366,7 @@ list<_Tp, _Alloc>::assign(_InpIter __f, _InpIter __l,
13661366 insert(__e, __f, __l);
13671367 else
13681368 erase(__i, __e);
1369#if _LIBCPP_DEBUG_LEVEL == 2
1370 __get_db()->__invalidate_all(this);
1371#endif
1369 std::__debug_db_invalidate_all(this);
13721370}
13731371
13741372template <class _Tp, class _Alloc>
......@@ -1383,9 +1381,7 @@ list<_Tp, _Alloc>::assign(size_type __n, const value_type& __x)
13831381 insert(__e, __n, __x);
13841382 else
13851383 erase(__i, __e);
1386#if _LIBCPP_DEBUG_LEVEL == 2
1387 __get_db()->__invalidate_all(this);
1388#endif
1384 std::__debug_db_invalidate_all(this);
13891385}
13901386
13911387template <class _Tp, class _Alloc>
......@@ -1407,11 +1403,7 @@ list<_Tp, _Alloc>::insert(const_iterator __p, const value_type& __x)
14071403 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
14081404 __link_nodes(__p.__ptr_, __hold->__as_link(), __hold->__as_link());
14091405 ++base::__sz();
1410#if _LIBCPP_DEBUG_LEVEL == 2
14111406 return iterator(__hold.release()->__as_link(), this);
1412#else
1413 return iterator(__hold.release()->__as_link());
1414#endif
14151407}
14161408
14171409template <class _Tp, class _Alloc>
......@@ -1420,11 +1412,7 @@ list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& _
14201412{
14211413 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
14221414 "list::insert(iterator, n, x) called with an iterator not referring to this list");
1423#if _LIBCPP_DEBUG_LEVEL == 2
14241415 iterator __r(__p.__ptr_, this);
1425#else
1426 iterator __r(__p.__ptr_);
1427#endif
14281416 if (__n > 0)
14291417 {
14301418 size_type __ds = 0;
......@@ -1432,11 +1420,7 @@ list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& _
14321420 __hold_pointer __hold = __allocate_node(__na);
14331421 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
14341422 ++__ds;
1435#if _LIBCPP_DEBUG_LEVEL == 2
14361423 __r = iterator(__hold->__as_link(), this);
1437#else
1438 __r = iterator(__hold->__as_link());
1439#endif
14401424 __hold.release();
14411425 iterator __e = __r;
14421426#ifndef _LIBCPP_NO_EXCEPTIONS
......@@ -1462,11 +1446,7 @@ list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& _
14621446 __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
14631447 if (__prev == 0)
14641448 break;
1465#if _LIBCPP_DEBUG_LEVEL == 2
14661449 __e = iterator(__prev, this);
1467#else
1468 __e = iterator(__prev);
1469#endif
14701450 }
14711451 throw;
14721452 }
......@@ -1481,15 +1461,11 @@ template <class _Tp, class _Alloc>
14811461template <class _InpIter>
14821462typename list<_Tp, _Alloc>::iterator
14831463list<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l,
1484 typename enable_if<__is_cpp17_input_iterator<_InpIter>::value>::type*)
1464 __enable_if_t<__is_cpp17_input_iterator<_InpIter>::value>*)
14851465{
14861466 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
14871467 "list::insert(iterator, range) called with an iterator not referring to this list");
1488#if _LIBCPP_DEBUG_LEVEL == 2
14891468 iterator __r(__p.__ptr_, this);
1490#else
1491 iterator __r(__p.__ptr_);
1492#endif
14931469 if (__f != __l)
14941470 {
14951471 size_type __ds = 0;
......@@ -1497,11 +1473,7 @@ list<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l,
14971473 __hold_pointer __hold = __allocate_node(__na);
14981474 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f);
14991475 ++__ds;
1500#if _LIBCPP_DEBUG_LEVEL == 2
15011476 __r = iterator(__hold.get()->__as_link(), this);
1502#else
1503 __r = iterator(__hold.get()->__as_link());
1504#endif
15051477 __hold.release();
15061478 iterator __e = __r;
15071479#ifndef _LIBCPP_NO_EXCEPTIONS
......@@ -1527,11 +1499,7 @@ list<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l,
15271499 __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
15281500 if (__prev == 0)
15291501 break;
1530#if _LIBCPP_DEBUG_LEVEL == 2
15311502 __e = iterator(__prev, this);
1532#else
1533 __e = iterator(__prev);
1534#endif
15351503 }
15361504 throw;
15371505 }
......@@ -1650,11 +1618,7 @@ list<_Tp, _Alloc>::emplace(const_iterator __p, _Args&&... __args)
16501618 __link_nodes(__p.__ptr_, __nl, __nl);
16511619 ++base::__sz();
16521620 __hold.release();
1653#if _LIBCPP_DEBUG_LEVEL == 2
16541621 return iterator(__nl, this);
1655#else
1656 return iterator(__nl);
1657#endif
16581622}
16591623
16601624template <class _Tp, class _Alloc>
......@@ -1670,11 +1634,7 @@ list<_Tp, _Alloc>::insert(const_iterator __p, value_type&& __x)
16701634 __link_nodes(__p.__ptr_, __nl, __nl);
16711635 ++base::__sz();
16721636 __hold.release();
1673#if _LIBCPP_DEBUG_LEVEL == 2
16741637 return iterator(__nl, this);
1675#else
1676 return iterator(__nl);
1677#endif
16781638}
16791639
16801640#endif // _LIBCPP_CXX03_LANG
......@@ -1688,7 +1648,7 @@ list<_Tp, _Alloc>::pop_front()
16881648 __link_pointer __n = base::__end_.__next_;
16891649 base::__unlink_nodes(__n, __n);
16901650 --base::__sz();
1691#if _LIBCPP_DEBUG_LEVEL == 2
1651#ifdef _LIBCPP_ENABLE_DEBUG_MODE
16921652 __c_node* __c = __get_db()->__find_c_and_lock(this);
16931653 for (__i_node** __p = __c->end_; __p != __c->beg_; )
16941654 {
......@@ -1717,7 +1677,7 @@ list<_Tp, _Alloc>::pop_back()
17171677 __link_pointer __n = base::__end_.__prev_;
17181678 base::__unlink_nodes(__n, __n);
17191679 --base::__sz();
1720#if _LIBCPP_DEBUG_LEVEL == 2
1680#ifdef _LIBCPP_ENABLE_DEBUG_MODE
17211681 __c_node* __c = __get_db()->__find_c_and_lock(this);
17221682 for (__i_node** __p = __c->end_; __p != __c->beg_; )
17231683 {
......@@ -1750,7 +1710,7 @@ list<_Tp, _Alloc>::erase(const_iterator __p)
17501710 __link_pointer __r = __n->__next_;
17511711 base::__unlink_nodes(__n, __n);
17521712 --base::__sz();
1753#if _LIBCPP_DEBUG_LEVEL == 2
1713#ifdef _LIBCPP_ENABLE_DEBUG_MODE
17541714 __c_node* __c = __get_db()->__find_c_and_lock(this);
17551715 for (__i_node** __ip = __c->end_; __ip != __c->beg_; )
17561716 {
......@@ -1768,11 +1728,7 @@ list<_Tp, _Alloc>::erase(const_iterator __p)
17681728 __node_pointer __np = __n->__as_node();
17691729 __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
17701730 __node_alloc_traits::deallocate(__na, __np, 1);
1771#if _LIBCPP_DEBUG_LEVEL == 2
17721731 return iterator(__r, this);
1773#else
1774 return iterator(__r);
1775#endif
17761732}
17771733
17781734template <class _Tp, class _Alloc>
......@@ -1792,7 +1748,7 @@ list<_Tp, _Alloc>::erase(const_iterator __f, const_iterator __l)
17921748 __link_pointer __n = __f.__ptr_;
17931749 ++__f;
17941750 --base::__sz();
1795#if _LIBCPP_DEBUG_LEVEL == 2
1751#ifdef _LIBCPP_ENABLE_DEBUG_MODE
17961752 __c_node* __c = __get_db()->__find_c_and_lock(this);
17971753 for (__i_node** __p = __c->end_; __p != __c->beg_; )
17981754 {
......@@ -1812,11 +1768,7 @@ list<_Tp, _Alloc>::erase(const_iterator __f, const_iterator __l)
18121768 __node_alloc_traits::deallocate(__na, __np, 1);
18131769 }
18141770 }
1815#if _LIBCPP_DEBUG_LEVEL == 2
18161771 return iterator(__l.__ptr_, this);
1817#else
1818 return iterator(__l.__ptr_);
1819#endif
18201772}
18211773
18221774template <class _Tp, class _Alloc>
......@@ -1833,11 +1785,7 @@ list<_Tp, _Alloc>::resize(size_type __n)
18331785 __hold_pointer __hold = __allocate_node(__na);
18341786 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_));
18351787 ++__ds;
1836#if _LIBCPP_DEBUG_LEVEL == 2
18371788 iterator __r = iterator(__hold.release()->__as_link(), this);
1838#else
1839 iterator __r = iterator(__hold.release()->__as_link());
1840#endif
18411789 iterator __e = __r;
18421790#ifndef _LIBCPP_NO_EXCEPTIONS
18431791 try
......@@ -1862,11 +1810,7 @@ list<_Tp, _Alloc>::resize(size_type __n)
18621810 __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
18631811 if (__prev == 0)
18641812 break;
1865#if _LIBCPP_DEBUG_LEVEL == 2
18661813 __e = iterator(__prev, this);
1867#else
1868 __e = iterator(__prev);
1869#endif
18701814 }
18711815 throw;
18721816 }
......@@ -1891,11 +1835,7 @@ list<_Tp, _Alloc>::resize(size_type __n, const value_type& __x)
18911835 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
18921836 ++__ds;
18931837 __link_pointer __nl = __hold.release()->__as_link();
1894#if _LIBCPP_DEBUG_LEVEL == 2
18951838 iterator __r = iterator(__nl, this);
1896#else
1897 iterator __r = iterator(__nl);
1898#endif
18991839 iterator __e = __r;
19001840#ifndef _LIBCPP_NO_EXCEPTIONS
19011841 try
......@@ -1920,11 +1860,7 @@ list<_Tp, _Alloc>::resize(size_type __n, const value_type& __x)
19201860 __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
19211861 if (__prev == 0)
19221862 break;
1923#if _LIBCPP_DEBUG_LEVEL == 2
19241863 __e = iterator(__prev, this);
1925#else
1926 __e = iterator(__prev);
1927#endif
19281864 }
19291865 throw;
19301866 }
......@@ -1950,7 +1886,7 @@ list<_Tp, _Alloc>::splice(const_iterator __p, list& __c)
19501886 __link_nodes(__p.__ptr_, __f, __l);
19511887 base::__sz() += __c.__sz();
19521888 __c.__sz() = 0;
1953#if _LIBCPP_DEBUG_LEVEL == 2
1889#ifdef _LIBCPP_ENABLE_DEBUG_MODE
19541890 if (_VSTD::addressof(__c) != this) {
19551891 __libcpp_db* __db = __get_db();
19561892 __c_node* __cn1 = __db->__find_c_and_lock(this);
......@@ -1991,7 +1927,7 @@ list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i)
19911927 __link_nodes(__p.__ptr_, __f, __f);
19921928 --__c.__sz();
19931929 ++base::__sz();
1994#if _LIBCPP_DEBUG_LEVEL == 2
1930#ifdef _LIBCPP_ENABLE_DEBUG_MODE
19951931 if (_VSTD::addressof(__c) != this) {
19961932 __libcpp_db* __db = __get_db();
19971933 __c_node* __cn1 = __db->__find_c_and_lock(this);
......@@ -2014,6 +1950,17 @@ list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i)
20141950 }
20151951}
20161952
1953template <class _Iterator>
1954_LIBCPP_HIDE_FROM_ABI
1955bool __iterator_in_range(_Iterator __first, _Iterator __last, _Iterator __it) {
1956 for (_Iterator __p = __first; __p != __last; ++__p) {
1957 if (__p == __it) {
1958 return true;
1959 }
1960 }
1961 return false;
1962}
1963
20171964template <class _Tp, class _Alloc>
20181965void
20191966list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l)
......@@ -2024,16 +1971,10 @@ list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, con
20241971 "list::splice(iterator, list, iterator, iterator) called with second iterator not referring to the list argument");
20251972 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__l)) == _VSTD::addressof(__c),
20261973 "list::splice(iterator, list, iterator, iterator) called with third iterator not referring to the list argument");
1974 _LIBCPP_DEBUG_ASSERT(this != std::addressof(__c) || !std::__iterator_in_range(__f, __l, __p),
1975 "list::splice(iterator, list, iterator, iterator)"
1976 " called with the first iterator within the range of the second and third iterators");
20271977
2028#if _LIBCPP_DEBUG_LEVEL == 2
2029 if (this == _VSTD::addressof(__c))
2030 {
2031 for (const_iterator __i = __f; __i != __l; ++__i)
2032 _LIBCPP_DEBUG_ASSERT(__i != __p,
2033 "list::splice(iterator, list, iterator, iterator)"
2034 " called with the first iterator within the range of the second and third iterators");
2035 }
2036#endif
20371978 if (__f != __l)
20381979 {
20391980 __link_pointer __first = __f.__ptr_;
......@@ -2047,7 +1988,7 @@ list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, con
20471988 }
20481989 base::__unlink_nodes(__first, __last);
20491990 __link_nodes(__p.__ptr_, __first, __last);
2050#if _LIBCPP_DEBUG_LEVEL == 2
1991#ifdef _LIBCPP_ENABLE_DEBUG_MODE
20511992 if (_VSTD::addressof(__c) != this) {
20521993 __libcpp_db* __db = __get_db();
20531994 __c_node* __cn1 = __db->__find_c_and_lock(this);
......@@ -2184,7 +2125,7 @@ list<_Tp, _Alloc>::merge(list& __c, _Comp __comp)
21842125 ++__f1;
21852126 }
21862127 splice(__e1, __c);
2187#if _LIBCPP_DEBUG_LEVEL == 2
2128#ifdef _LIBCPP_ENABLE_DEBUG_MODE
21882129 __libcpp_db* __db = __get_db();
21892130 __c_node* __cn1 = __db->__find_c_and_lock(this);
21902131 __c_node* __cn2 = __db->__find_c(_VSTD::addressof(__c));
......@@ -2308,7 +2249,7 @@ list<_Tp, _Alloc>::__invariants() const
23082249 return size() == _VSTD::distance(begin(), end());
23092250}
23102251
2311#if _LIBCPP_DEBUG_LEVEL == 2
2252#ifdef _LIBCPP_ENABLE_DEBUG_MODE
23122253
23132254template <class _Tp, class _Alloc>
23142255bool
......@@ -2338,7 +2279,7 @@ list<_Tp, _Alloc>::__subscriptable(const const_iterator*, ptrdiff_t) const
23382279 return false;
23392280}
23402281
2341#endif // _LIBCPP_DEBUG_LEVEL == 2
2282#endif // _LIBCPP_ENABLE_DEBUG_MODE
23422283
23432284template <class _Tp, class _Alloc>
23442285inline _LIBCPP_INLINE_VISIBILITY
......@@ -2409,8 +2350,16 @@ inline _LIBCPP_INLINE_VISIBILITY typename list<_Tp, _Allocator>::size_type
24092350erase(list<_Tp, _Allocator>& __c, const _Up& __v) {
24102351 return _VSTD::erase_if(__c, [&](auto& __elem) { return __elem == __v; });
24112352}
2353
2354template <>
2355inline constexpr bool __format::__enable_insertable<std::list<char>> = true;
2356#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
2357template <>
2358inline constexpr bool __format::__enable_insertable<std::list<wchar_t>> = true;
24122359#endif
24132360
2361#endif // _LIBCPP_STD_VER > 17
2362
24142363_LIBCPP_END_NAMESPACE_STD
24152364
24162365_LIBCPP_POP_MACROS
lib/libcxx/include/locale+85-55
......@@ -187,26 +187,37 @@ template <class charT> class messages_byname;
187187
188188*/
189189
190#include <__algorithm/copy.h>
191#include <__algorithm/equal.h>
192#include <__algorithm/find.h>
193#include <__algorithm/max.h>
194#include <__algorithm/reverse.h>
195#include <__algorithm/unwrap_iter.h>
196#include <__assert> // all public C++ headers provide the assertion handler
190197#include <__config>
191198#include <__debug>
199#include <__iterator/access.h>
200#include <__iterator/back_insert_iterator.h>
201#include <__iterator/istreambuf_iterator.h>
202#include <__iterator/ostreambuf_iterator.h>
192203#include <__locale>
193#include <algorithm>
194#ifndef __APPLE__
195# include <cstdarg>
196#endif
204#include <cstdarg> // TODO: Remove this include
197205#include <cstdio>
198206#include <cstdlib>
199207#include <ctime>
200208#include <ios>
201#include <iterator>
202209#include <limits>
203210#include <memory>
204211#include <streambuf>
205212#include <version>
206213
214#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
215# include <iterator>
216#endif
217
207218#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
208219// Most unix variants have catopen. These are the specific ones that don't.
209# if !defined(__BIONIC__) && !defined(_NEWLIB_VERSION)
220# if !defined(__BIONIC__) && !defined(_NEWLIB_VERSION) && !defined(__EMSCRIPTEN__)
210221# define _LIBCPP_HAS_CATOPEN 1
211222# include <nl_types.h>
212223# endif
......@@ -219,7 +230,7 @@ template <class charT> class messages_byname;
219230#endif
220231
221232#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
222#pragma GCC system_header
233# pragma GCC system_header
223234#endif
224235
225236_LIBCPP_PUSH_MACROS
......@@ -572,9 +583,9 @@ __num_get<_CharT>::__stage2_float_loop(_CharT __ct, bool& __in_units, char& __ex
572583 return 0;
573584}
574585
575_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_get<char>)
586extern template struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_get<char>;
576587#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
577_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_get<wchar_t>)
588extern template struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_get<wchar_t>;
578589#endif
579590
580591template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
......@@ -1112,9 +1123,9 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
11121123 return __b;
11131124}
11141125
1115_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_get<char>)
1126extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_get<char>;
11161127#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1117_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_get<wchar_t>)
1128extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_get<wchar_t>;
11181129#endif
11191130
11201131struct _LIBCPP_TYPE_VIS __num_put_base
......@@ -1264,9 +1275,9 @@ __num_put<_CharT>::__widen_and_group_float(char* __nb, char* __np, char* __ne,
12641275 __op = __ob + (__np - __nb);
12651276}
12661277
1267_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_put<char>)
1278extern template struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_put<char>;
12681279#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1269_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_put<wchar_t>)
1280extern template struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_put<wchar_t>;
12701281#endif
12711282
12721283template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
......@@ -1456,7 +1467,7 @@ num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
14561467 return do_put(__s, __iob, __fl, (unsigned long)__v);
14571468 const numpunct<char_type>& __np = use_facet<numpunct<char_type> >(__iob.getloc());
14581469 typedef typename numpunct<char_type>::string_type string_type;
1459#if _LIBCPP_DEBUG_LEVEL == 2
1470#ifdef _LIBCPP_ENABLE_DEBUG_MODE
14601471 string_type __tmp(__v ? __np.truename() : __np.falsename());
14611472 string_type __nm = _VSTD::move(__tmp);
14621473#else
......@@ -1486,10 +1497,11 @@ num_put<_CharT, _OutputIterator>::__do_put_integral(iter_type __s, ios_base& __i
14861497 + ((numeric_limits<_Unsigned>::digits % 3) != 0) // round up
14871498 + 2; // base prefix + terminating null character
14881499 char __nar[__nbuf];
1489#pragma clang diagnostic push
1490#pragma clang diagnostic ignored "-Wformat-nonliteral"
1500 _LIBCPP_DIAGNOSTIC_PUSH
1501 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wformat-nonliteral")
1502 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wformat-nonliteral")
14911503 int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
1492#pragma clang diagnostic pop
1504 _LIBCPP_DIAGNOSTIC_POP
14931505 char* __ne = __nar + __nc;
14941506 char* __np = this->__identify_padding(__nar, __ne, __iob);
14951507 // Stage 2 - Widen __nar while adding thousands separators
......@@ -1549,8 +1561,9 @@ num_put<_CharT, _OutputIterator>::__do_put_floating_point(iter_type __s, ios_bas
15491561 char __nar[__nbuf];
15501562 char* __nb = __nar;
15511563 int __nc;
1552#pragma clang diagnostic push
1553#pragma clang diagnostic ignored "-Wformat-nonliteral"
1564 _LIBCPP_DIAGNOSTIC_PUSH
1565 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wformat-nonliteral")
1566 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wformat-nonliteral")
15541567 if (__specify_precision)
15551568 __nc = __libcpp_snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt,
15561569 (int)__iob.precision(), __v);
......@@ -1567,7 +1580,7 @@ num_put<_CharT, _OutputIterator>::__do_put_floating_point(iter_type __s, ios_bas
15671580 __throw_bad_alloc();
15681581 __nbh.reset(__nb);
15691582 }
1570#pragma clang diagnostic pop
1583 _LIBCPP_DIAGNOSTIC_POP
15711584 char* __ne = __nb + __nc;
15721585 char* __np = this->__identify_padding(__nb, __ne, __iob);
15731586 // Stage 2 - Widen __nar while adding thousands separators
......@@ -1633,9 +1646,9 @@ num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
16331646 return __pad_and_output(__s, __o, __op, __oe, __iob, __fl);
16341647}
16351648
1636_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_put<char>)
1649extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_put<char>;
16371650#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1638_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_put<wchar_t>)
1651extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_put<wchar_t>;
16391652#endif
16401653
16411654template <class _CharT, class _InputIterator>
......@@ -1918,7 +1931,7 @@ time_get<_CharT, _InputIterator>::__get_month(int& __m,
19181931 const ctype<char_type>& __ct) const
19191932{
19201933 int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2) - 1;
1921 if (!(__err & ios_base::failbit) && __t <= 11)
1934 if (!(__err & ios_base::failbit) && 0 <= __t && __t <= 11)
19221935 __m = __t;
19231936 else
19241937 __err |= ios_base::failbit;
......@@ -2323,9 +2336,9 @@ time_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
23232336 return __b;
23242337}
23252338
2326_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get<char>)
2339extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get<char>;
23272340#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
2328_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get<wchar_t>)
2341extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get<wchar_t>;
23292342#endif
23302343
23312344class _LIBCPP_TYPE_VIS __time_get
......@@ -2425,9 +2438,9 @@ private:
24252438 virtual const string_type& __X() const {return this->__X_;}
24262439};
24272440
2428_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get_byname<char>)
2441extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get_byname<char>;
24292442#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
2430_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get_byname<wchar_t>)
2443extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get_byname<wchar_t>;
24312444#endif
24322445
24332446class _LIBCPP_TYPE_VIS __time_put
......@@ -2540,9 +2553,9 @@ time_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base&,
25402553 return _VSTD::copy(__nb, __ne, __s);
25412554}
25422555
2543_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put<char>)
2556extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put<char>;
25442557#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
2545_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put<wchar_t>)
2558extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put<wchar_t>;
25462559#endif
25472560
25482561template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
......@@ -2563,9 +2576,9 @@ protected:
25632576 ~time_put_byname() {}
25642577};
25652578
2566_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put_byname<char>)
2579extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put_byname<char>;
25672580#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
2568_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put_byname<wchar_t>)
2581extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put_byname<wchar_t>;
25692582#endif
25702583
25712584// money_base
......@@ -2632,11 +2645,11 @@ template <class _CharT, bool _International>
26322645const bool
26332646moneypunct<_CharT, _International>::intl;
26342647
2635_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<char, false>)
2636_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<char, true>)
2648extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<char, false>;
2649extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<char, true>;
26372650#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
2638_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<wchar_t, false>)
2639_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<wchar_t, true>)
2651extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<wchar_t, false>;
2652extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<wchar_t, true>;
26402653#endif
26412654
26422655// moneypunct_byname
......@@ -2688,14 +2701,14 @@ private:
26882701
26892702template<> _LIBCPP_FUNC_VIS void moneypunct_byname<char, false>::init(const char*);
26902703template<> _LIBCPP_FUNC_VIS void moneypunct_byname<char, true>::init(const char*);
2691_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<char, false>)
2692_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<char, true>)
2704extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<char, false>;
2705extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<char, true>;
26932706
26942707#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
26952708template<> _LIBCPP_FUNC_VIS void moneypunct_byname<wchar_t, false>::init(const char*);
26962709template<> _LIBCPP_FUNC_VIS void moneypunct_byname<wchar_t, true>::init(const char*);
2697_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<wchar_t, false>)
2698_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<wchar_t, true>)
2710extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<wchar_t, false>;
2711extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<wchar_t, true>;
26992712#endif
27002713
27012714// money_get
......@@ -2752,9 +2765,9 @@ __money_get<_CharT>::__gather_info(bool __intl, const locale& __loc,
27522765 }
27532766}
27542767
2755_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_get<char>)
2768extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_get<char>;
27562769#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
2757_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_get<wchar_t>)
2770extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_get<wchar_t>;
27582771#endif
27592772
27602773template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
......@@ -3121,9 +3134,9 @@ money_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
31213134 return __b;
31223135}
31233136
3124_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_get<char>)
3137extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_get<char>;
31253138#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
3126_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_get<wchar_t>)
3139extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_get<wchar_t>;
31273140#endif
31283141
31293142// money_put
......@@ -3214,9 +3227,9 @@ __money_put<_CharT>::__format(char_type* __mb, char_type*& __mi, char_type*& __m
32143227 int __fd)
32153228{
32163229 __me = __mb;
3217 for (unsigned __p = 0; __p < 4; ++__p)
3230 for (char __p : __pat.field)
32183231 {
3219 switch (__pat.field[__p])
3232 switch (__p)
32203233 {
32213234 case money_base::none:
32223235 __mi = __me;
......@@ -3298,9 +3311,9 @@ __money_put<_CharT>::__format(char_type* __mb, char_type*& __mi, char_type*& __m
32983311 __mi = __mb;
32993312}
33003313
3301_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_put<char>)
3314extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_put<char>;
33023315#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
3303_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_put<wchar_t>)
3316extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_put<wchar_t>;
33043317#endif
33053318
33063319template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
......@@ -3453,9 +3466,9 @@ money_put<_CharT, _OutputIterator>::do_put(iter_type __s, bool __intl,
34533466 return __pad_and_output(__s, __mb, __mi, __me, __iob, __fl);
34543467}
34553468
3456_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_put<char>)
3469extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_put<char>;
34573470#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
3458_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_put<wchar_t>)
3471extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_put<wchar_t>;
34593472#endif
34603473
34613474// messages
......@@ -3571,9 +3584,9 @@ messages<_CharT>::do_close(catalog __c) const
35713584#endif // _LIBCPP_HAS_CATOPEN
35723585}
35733586
3574_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages<char>)
3587extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages<char>;
35753588#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
3576_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages<wchar_t>)
3589extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages<wchar_t>;
35773590#endif
35783591
35793592template <class _CharT>
......@@ -3597,15 +3610,15 @@ protected:
35973610 ~messages_byname() {}
35983611};
35993612
3600_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages_byname<char>)
3613extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages_byname<char>;
36013614#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
3602_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages_byname<wchar_t>)
3615extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages_byname<wchar_t>;
36033616#endif
36043617
36053618template<class _Codecvt, class _Elem = wchar_t,
36063619 class _Wide_alloc = allocator<_Elem>,
36073620 class _Byte_alloc = allocator<char> >
3608class _LIBCPP_TEMPLATE_VIS wstring_convert
3621class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 wstring_convert
36093622{
36103623public:
36113624 typedef basic_string<char, char_traits<char>, _Byte_alloc> byte_string;
......@@ -3672,6 +3685,7 @@ public:
36723685 state_type state() const {return __cvtstate_;}
36733686};
36743687
3688_LIBCPP_SUPPRESS_DEPRECATED_PUSH
36753689template<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc>
36763690inline
36773691wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::
......@@ -3679,6 +3693,7 @@ wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::
36793693 : __cvtptr_(__pcvt), __cvtstate_(), __cvtcount_(0)
36803694{
36813695}
3696_LIBCPP_SUPPRESS_DEPRECATED_POP
36823697
36833698template<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc>
36843699inline
......@@ -3713,6 +3728,7 @@ wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::
37133728
37143729#endif // _LIBCPP_CXX03_LANG
37153730
3731_LIBCPP_SUPPRESS_DEPRECATED_PUSH
37163732template<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc>
37173733wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::~wstring_convert()
37183734{
......@@ -3724,6 +3740,7 @@ typename wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::wide_string
37243740wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::
37253741 from_bytes(const char* __frm, const char* __frm_end)
37263742{
3743_LIBCPP_SUPPRESS_DEPRECATED_POP
37273744 __cvtcount_ = 0;
37283745 if (__cvtptr_ != nullptr)
37293746 {
......@@ -3870,7 +3887,7 @@ wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::
38703887}
38713888
38723889template <class _Codecvt, class _Elem = wchar_t, class _Tr = char_traits<_Elem> >
3873class _LIBCPP_TEMPLATE_VIS wbuffer_convert
3890class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 wbuffer_convert
38743891 : public basic_streambuf<_Elem, _Tr>
38753892{
38763893public:
......@@ -3947,6 +3964,7 @@ private:
39473964 wbuffer_convert* __close();
39483965};
39493966
3967_LIBCPP_SUPPRESS_DEPRECATED_PUSH
39503968template <class _Codecvt, class _Elem, class _Tr>
39513969wbuffer_convert<_Codecvt, _Elem, _Tr>::
39523970 wbuffer_convert(streambuf* __bytebuf, _Codecvt* __pcvt, state_type __state)
......@@ -3982,6 +4000,7 @@ template <class _Codecvt, class _Elem, class _Tr>
39824000typename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type
39834001wbuffer_convert<_Codecvt, _Elem, _Tr>::underflow()
39844002{
4003_LIBCPP_SUPPRESS_DEPRECATED_POP
39854004 if (__cv_ == 0 || __bufptr_ == 0)
39864005 return traits_type::eof();
39874006 bool __initial = __read_mode();
......@@ -4046,10 +4065,12 @@ wbuffer_convert<_Codecvt, _Elem, _Tr>::underflow()
40464065 return __c;
40474066}
40484067
4068_LIBCPP_SUPPRESS_DEPRECATED_PUSH
40494069template <class _Codecvt, class _Elem, class _Tr>
40504070typename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type
40514071wbuffer_convert<_Codecvt, _Elem, _Tr>::pbackfail(int_type __c)
40524072{
4073_LIBCPP_SUPPRESS_DEPRECATED_POP
40534074 if (__cv_ != 0 && __bufptr_ != 0 && this->eback() < this->gptr())
40544075 {
40554076 if (traits_type::eq_int_type(__c, traits_type::eof()))
......@@ -4067,10 +4088,12 @@ wbuffer_convert<_Codecvt, _Elem, _Tr>::pbackfail(int_type __c)
40674088 return traits_type::eof();
40684089}
40694090
4091_LIBCPP_SUPPRESS_DEPRECATED_PUSH
40704092template <class _Codecvt, class _Elem, class _Tr>
40714093typename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type
40724094wbuffer_convert<_Codecvt, _Elem, _Tr>::overflow(int_type __c)
40734095{
4096_LIBCPP_SUPPRESS_DEPRECATED_POP
40744097 if (__cv_ == 0 || __bufptr_ == 0)
40754098 return traits_type::eof();
40764099 __write_mode();
......@@ -4129,10 +4152,12 @@ wbuffer_convert<_Codecvt, _Elem, _Tr>::overflow(int_type __c)
41294152 return traits_type::not_eof(__c);
41304153}
41314154
4155_LIBCPP_SUPPRESS_DEPRECATED_PUSH
41324156template <class _Codecvt, class _Elem, class _Tr>
41334157basic_streambuf<_Elem, _Tr>*
41344158wbuffer_convert<_Codecvt, _Elem, _Tr>::setbuf(char_type* __s, streamsize __n)
41354159{
4160_LIBCPP_SUPPRESS_DEPRECATED_POP
41364161 this->setg(0, 0, 0);
41374162 this->setp(0, 0);
41384163 if (__owns_eb_)
......@@ -4182,6 +4207,7 @@ wbuffer_convert<_Codecvt, _Elem, _Tr>::setbuf(char_type* __s, streamsize __n)
41824207 return this;
41834208}
41844209
4210_LIBCPP_SUPPRESS_DEPRECATED_PUSH
41854211template <class _Codecvt, class _Elem, class _Tr>
41864212typename wbuffer_convert<_Codecvt, _Elem, _Tr>::pos_type
41874213wbuffer_convert<_Codecvt, _Elem, _Tr>::seekoff(off_type __off, ios_base::seekdir __way,
......@@ -4213,6 +4239,7 @@ template <class _Codecvt, class _Elem, class _Tr>
42134239int
42144240wbuffer_convert<_Codecvt, _Elem, _Tr>::sync()
42154241{
4242_LIBCPP_SUPPRESS_DEPRECATED_POP
42164243 if (__cv_ == 0 || __bufptr_ == 0)
42174244 return 0;
42184245 if (__cm_ & ios_base::out)
......@@ -4281,6 +4308,7 @@ wbuffer_convert<_Codecvt, _Elem, _Tr>::sync()
42814308 return 0;
42824309}
42834310
4311_LIBCPP_SUPPRESS_DEPRECATED_PUSH
42844312template <class _Codecvt, class _Elem, class _Tr>
42854313bool
42864314wbuffer_convert<_Codecvt, _Elem, _Tr>::__read_mode()
......@@ -4335,6 +4363,8 @@ wbuffer_convert<_Codecvt, _Elem, _Tr>::__close()
43354363 return __rt;
43364364}
43374365
4366_LIBCPP_SUPPRESS_DEPRECATED_POP
4367
43384368_LIBCPP_END_NAMESPACE_STD
43394369
43404370_LIBCPP_POP_MACROS
lib/libcxx/include/locale.h+2-2
......@@ -36,11 +36,11 @@ Functions:
3636#include <__config>
3737
3838#if defined(_LIBCPP_HAS_NO_LOCALIZATION)
39# error "The Localization library is not supported since libc++ has been configured with LIBCXX_ENABLE_LOCALIZATION disabled"
39# error "<locale.h> is not supported since libc++ has been configured without support for localization."
4040#endif
4141
4242#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
43# pragma GCC system_header
43# pragma GCC system_header
4444#endif
4545
4646#include_next <locale.h>
lib/libcxx/include/map+65-64
......@@ -528,24 +528,45 @@ erase_if(multimap<Key, T, Compare, Allocator>& c, Predicate pred); // C++20
528528
529529*/
530530
531#include <__algorithm/equal.h>
532#include <__algorithm/lexicographical_compare.h>
533#include <__assert> // all public C++ headers provide the assertion handler
531534#include <__config>
532#include <__debug>
535#include <__functional/binary_function.h>
533536#include <__functional/is_transparent.h>
537#include <__functional/operations.h>
538#include <__iterator/erase_if_container.h>
534539#include <__iterator/iterator_traits.h>
540#include <__iterator/reverse_iterator.h>
535541#include <__node_handle>
536542#include <__tree>
537543#include <__utility/forward.h>
538#include <compare>
539#include <functional>
540#include <initializer_list>
541#include <iterator> // __libcpp_erase_if_container
544#include <__utility/swap.h>
542545#include <memory>
543546#include <type_traits>
544#include <utility>
545547#include <version>
546548
549#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
550# include <functional>
551# include <iterator>
552# include <utility>
553#endif
554
555// standard-mandated includes
556
557// [iterator.range]
558#include <__iterator/access.h>
559#include <__iterator/data.h>
560#include <__iterator/empty.h>
561#include <__iterator/reverse_access.h>
562#include <__iterator/size.h>
563
564// [associative.map.syn]
565#include <compare>
566#include <initializer_list>
567
547568#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
548#pragma GCC system_header
569# pragma GCC system_header
549570#endif
550571
551572_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -561,9 +582,9 @@ public:
561582 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
562583 : _Compare() {}
563584 _LIBCPP_INLINE_VISIBILITY
564 __map_value_compare(_Compare c)
585 __map_value_compare(_Compare __c)
565586 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
566 : _Compare(c) {}
587 : _Compare(__c) {}
567588 _LIBCPP_INLINE_VISIBILITY
568589 const _Compare& key_comp() const _NOEXCEPT {return *this;}
569590 _LIBCPP_INLINE_VISIBILITY
......@@ -606,9 +627,9 @@ public:
606627 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
607628 : comp() {}
608629 _LIBCPP_INLINE_VISIBILITY
609 __map_value_compare(_Compare c)
630 __map_value_compare(_Compare __c)
610631 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
611 : comp(c) {}
632 : comp(__c) {}
612633 _LIBCPP_INLINE_VISIBILITY
613634 const _Compare& key_comp() const _NOEXCEPT {return comp;}
614635
......@@ -771,9 +792,7 @@ public:
771792 }
772793
773794 template <class _ValueTp,
774 class = typename enable_if<
775 __is_same_uncvref<_ValueTp, value_type>::value
776 >::type
795 class = __enable_if_t<__is_same_uncvref<_ValueTp, value_type>::value>
777796 >
778797 _LIBCPP_INLINE_VISIBILITY
779798 __value_type& operator=(_ValueTp&& __v)
......@@ -956,32 +975,23 @@ public:
956975 typedef _Key key_type;
957976 typedef _Tp mapped_type;
958977 typedef pair<const key_type, mapped_type> value_type;
959 typedef __identity_t<_Compare> key_compare;
960 typedef __identity_t<_Allocator> allocator_type;
978 typedef __type_identity_t<_Compare> key_compare;
979 typedef __type_identity_t<_Allocator> allocator_type;
961980 typedef value_type& reference;
962981 typedef const value_type& const_reference;
963982
964983 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
965984 "Allocator::value_type must be same type as value_type");
966985
967_LIBCPP_SUPPRESS_DEPRECATED_PUSH
968986 class _LIBCPP_TEMPLATE_VIS value_compare
969#if defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
970 : public binary_function<value_type, value_type, bool>
971#endif
987 : public __binary_function<value_type, value_type, bool>
972988 {
973_LIBCPP_SUPPRESS_DEPRECATED_POP
974989 friend class map;
975990 protected:
976991 key_compare comp;
977992
978 _LIBCPP_INLINE_VISIBILITY value_compare(key_compare c) : comp(c) {}
993 _LIBCPP_INLINE_VISIBILITY value_compare(key_compare __c) : comp(__c) {}
979994 public:
980#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
981 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
982 _LIBCPP_DEPRECATED_IN_CXX17 typedef value_type first_argument_type;
983 _LIBCPP_DEPRECATED_IN_CXX17 typedef value_type second_argument_type;
984#endif
985995 _LIBCPP_INLINE_VISIBILITY
986996 bool operator()(const value_type& __x, const value_type& __y) const
987997 {return comp(__x.first, __y.first);}
......@@ -1218,13 +1228,13 @@ public:
12181228 }
12191229
12201230 template <class _Pp,
1221 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
1231 class = __enable_if_t<is_constructible<value_type, _Pp>::value> >
12221232 _LIBCPP_INLINE_VISIBILITY
12231233 pair<iterator, bool> insert(_Pp&& __p)
12241234 {return __tree_.__insert_unique(_VSTD::forward<_Pp>(__p));}
12251235
12261236 template <class _Pp,
1227 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
1237 class = __enable_if_t<is_constructible<value_type, _Pp>::value> >
12281238 _LIBCPP_INLINE_VISIBILITY
12291239 iterator insert(const_iterator __pos, _Pp&& __p)
12301240 {return __tree_.__insert_unique(__pos.__i_, _VSTD::forward<_Pp>(__p));}
......@@ -1444,11 +1454,11 @@ public:
14441454#if _LIBCPP_STD_VER > 11
14451455 template <typename _K2>
14461456 _LIBCPP_INLINE_VISIBILITY
1447 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1457 __enable_if_t<__is_transparent<_Compare, _K2>::value, iterator>
14481458 find(const _K2& __k) {return __tree_.find(__k);}
14491459 template <typename _K2>
14501460 _LIBCPP_INLINE_VISIBILITY
1451 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1461 __enable_if_t<__is_transparent<_Compare, _K2>::value, const_iterator>
14521462 find(const _K2& __k) const {return __tree_.find(__k);}
14531463#endif
14541464
......@@ -1458,7 +1468,7 @@ public:
14581468#if _LIBCPP_STD_VER > 11
14591469 template <typename _K2>
14601470 _LIBCPP_INLINE_VISIBILITY
1461 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
1471 __enable_if_t<__is_transparent<_Compare, _K2>::value, size_type>
14621472 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
14631473#endif
14641474
......@@ -1467,7 +1477,7 @@ public:
14671477 bool contains(const key_type& __k) const {return find(__k) != end();}
14681478 template <typename _K2>
14691479 _LIBCPP_INLINE_VISIBILITY
1470 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
1480 __enable_if_t<__is_transparent<_Compare, _K2>::value, bool>
14711481 contains(const _K2& __k) const { return find(__k) != end(); }
14721482#endif // _LIBCPP_STD_VER > 17
14731483
......@@ -1480,12 +1490,12 @@ public:
14801490#if _LIBCPP_STD_VER > 11
14811491 template <typename _K2>
14821492 _LIBCPP_INLINE_VISIBILITY
1483 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1493 __enable_if_t<__is_transparent<_Compare, _K2>::value, iterator>
14841494 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
14851495
14861496 template <typename _K2>
14871497 _LIBCPP_INLINE_VISIBILITY
1488 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1498 __enable_if_t<__is_transparent<_Compare, _K2>::value, const_iterator>
14891499 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
14901500#endif
14911501
......@@ -1498,11 +1508,11 @@ public:
14981508#if _LIBCPP_STD_VER > 11
14991509 template <typename _K2>
15001510 _LIBCPP_INLINE_VISIBILITY
1501 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1511 __enable_if_t<__is_transparent<_Compare, _K2>::value, iterator>
15021512 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
15031513 template <typename _K2>
15041514 _LIBCPP_INLINE_VISIBILITY
1505 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1515 __enable_if_t<__is_transparent<_Compare, _K2>::value, const_iterator>
15061516 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
15071517#endif
15081518
......@@ -1515,11 +1525,11 @@ public:
15151525#if _LIBCPP_STD_VER > 11
15161526 template <typename _K2>
15171527 _LIBCPP_INLINE_VISIBILITY
1518 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
1528 __enable_if_t<__is_transparent<_Compare, _K2>::value, pair<iterator,iterator>>
15191529 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
15201530 template <typename _K2>
15211531 _LIBCPP_INLINE_VISIBILITY
1522 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
1532 __enable_if_t<__is_transparent<_Compare, _K2>::value, pair<const_iterator,const_iterator>>
15231533 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
15241534#endif
15251535
......@@ -1741,33 +1751,24 @@ public:
17411751 typedef _Key key_type;
17421752 typedef _Tp mapped_type;
17431753 typedef pair<const key_type, mapped_type> value_type;
1744 typedef __identity_t<_Compare> key_compare;
1745 typedef __identity_t<_Allocator> allocator_type;
1754 typedef __type_identity_t<_Compare> key_compare;
1755 typedef __type_identity_t<_Allocator> allocator_type;
17461756 typedef value_type& reference;
17471757 typedef const value_type& const_reference;
17481758
17491759 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
17501760 "Allocator::value_type must be same type as value_type");
17511761
1752_LIBCPP_SUPPRESS_DEPRECATED_PUSH
17531762 class _LIBCPP_TEMPLATE_VIS value_compare
1754#if defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
1755 : public binary_function<value_type, value_type, bool>
1756#endif
1763 : public __binary_function<value_type, value_type, bool>
17571764 {
1758_LIBCPP_SUPPRESS_DEPRECATED_POP
17591765 friend class multimap;
17601766 protected:
17611767 key_compare comp;
17621768
17631769 _LIBCPP_INLINE_VISIBILITY
1764 value_compare(key_compare c) : comp(c) {}
1770 value_compare(key_compare __c) : comp(__c) {}
17651771 public:
1766#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
1767 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
1768 _LIBCPP_DEPRECATED_IN_CXX17 typedef value_type first_argument_type;
1769 _LIBCPP_DEPRECATED_IN_CXX17 typedef value_type second_argument_type;
1770#endif
17711772 _LIBCPP_INLINE_VISIBILITY
17721773 bool operator()(const value_type& __x, const value_type& __y) const
17731774 {return comp(__x.first, __y.first);}
......@@ -1997,13 +1998,13 @@ public:
19971998 }
19981999
19992000 template <class _Pp,
2000 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
2001 class = __enable_if_t<is_constructible<value_type, _Pp>::value>>
20012002 _LIBCPP_INLINE_VISIBILITY
20022003 iterator insert(_Pp&& __p)
20032004 {return __tree_.__insert_multi(_VSTD::forward<_Pp>(__p));}
20042005
20052006 template <class _Pp,
2006 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
2007 class = __enable_if_t<is_constructible<value_type, _Pp>::value>>
20072008 _LIBCPP_INLINE_VISIBILITY
20082009 iterator insert(const_iterator __pos, _Pp&& __p)
20092010 {return __tree_.__insert_multi(__pos.__i_, _VSTD::forward<_Pp>(__p));}
......@@ -2125,11 +2126,11 @@ public:
21252126#if _LIBCPP_STD_VER > 11
21262127 template <typename _K2>
21272128 _LIBCPP_INLINE_VISIBILITY
2128 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
2129 __enable_if_t<__is_transparent<_Compare, _K2>::value, iterator>
21292130 find(const _K2& __k) {return __tree_.find(__k);}
21302131 template <typename _K2>
21312132 _LIBCPP_INLINE_VISIBILITY
2132 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
2133 __enable_if_t<__is_transparent<_Compare, _K2>::value, const_iterator>
21332134 find(const _K2& __k) const {return __tree_.find(__k);}
21342135#endif
21352136
......@@ -2139,7 +2140,7 @@ public:
21392140#if _LIBCPP_STD_VER > 11
21402141 template <typename _K2>
21412142 _LIBCPP_INLINE_VISIBILITY
2142 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
2143 __enable_if_t<__is_transparent<_Compare, _K2>::value, size_type>
21432144 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
21442145#endif
21452146
......@@ -2148,7 +2149,7 @@ public:
21482149 bool contains(const key_type& __k) const {return find(__k) != end();}
21492150 template <typename _K2>
21502151 _LIBCPP_INLINE_VISIBILITY
2151 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
2152 __enable_if_t<__is_transparent<_Compare, _K2>::value, bool>
21522153 contains(const _K2& __k) const { return find(__k) != end(); }
21532154#endif // _LIBCPP_STD_VER > 17
21542155
......@@ -2161,12 +2162,12 @@ public:
21612162#if _LIBCPP_STD_VER > 11
21622163 template <typename _K2>
21632164 _LIBCPP_INLINE_VISIBILITY
2164 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
2165 __enable_if_t<__is_transparent<_Compare, _K2>::value, iterator>
21652166 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
21662167
21672168 template <typename _K2>
21682169 _LIBCPP_INLINE_VISIBILITY
2169 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
2170 __enable_if_t<__is_transparent<_Compare, _K2>::value, const_iterator>
21702171 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
21712172#endif
21722173
......@@ -2179,11 +2180,11 @@ public:
21792180#if _LIBCPP_STD_VER > 11
21802181 template <typename _K2>
21812182 _LIBCPP_INLINE_VISIBILITY
2182 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
2183 __enable_if_t<__is_transparent<_Compare, _K2>::value, iterator>
21832184 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
21842185 template <typename _K2>
21852186 _LIBCPP_INLINE_VISIBILITY
2186 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
2187 __enable_if_t<__is_transparent<_Compare, _K2>::value, const_iterator>
21872188 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
21882189#endif
21892190
......@@ -2196,11 +2197,11 @@ public:
21962197#if _LIBCPP_STD_VER > 11
21972198 template <typename _K2>
21982199 _LIBCPP_INLINE_VISIBILITY
2199 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
2200 __enable_if_t<__is_transparent<_Compare, _K2>::value, pair<iterator,iterator>>
22002201 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
22012202 template <typename _K2>
22022203 _LIBCPP_INLINE_VISIBILITY
2203 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
2204 __enable_if_t<__is_transparent<_Compare, _K2>::value, pair<const_iterator,const_iterator>>
22042205 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
22052206#endif
22062207
lib/libcxx/include/math.h+45-44
......@@ -294,7 +294,7 @@ long double truncl(long double x);
294294#include <__config>
295295
296296#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
297#pragma GCC system_header
297# pragma GCC system_header
298298#endif
299299
300300#include_next <math.h>
......@@ -305,6 +305,7 @@ long double truncl(long double x);
305305// back to C++ linkage before including these C++ headers.
306306extern "C++" {
307307
308#include <__type_traits/promote.h>
308309#include <limits>
309310#include <stdlib.h>
310311#include <type_traits>
......@@ -788,10 +789,10 @@ isunordered(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
788789
789790// acos
790791
791#if !(defined(_AIX) || defined(__sun__))
792# if !defined(__sun__)
792793inline _LIBCPP_INLINE_VISIBILITY float acos(float __lcpp_x) _NOEXCEPT {return ::acosf(__lcpp_x);}
793794inline _LIBCPP_INLINE_VISIBILITY long double acos(long double __lcpp_x) _NOEXCEPT {return ::acosl(__lcpp_x);}
794#endif
795# endif
795796
796797template <class _A1>
797798inline _LIBCPP_INLINE_VISIBILITY
......@@ -800,10 +801,10 @@ acos(_A1 __lcpp_x) _NOEXCEPT {return ::acos((double)__lcpp_x);}
800801
801802// asin
802803
803#if !(defined(_AIX) || defined(__sun__))
804# if !defined(__sun__)
804805inline _LIBCPP_INLINE_VISIBILITY float asin(float __lcpp_x) _NOEXCEPT {return ::asinf(__lcpp_x);}
805806inline _LIBCPP_INLINE_VISIBILITY long double asin(long double __lcpp_x) _NOEXCEPT {return ::asinl(__lcpp_x);}
806#endif
807# endif
807808
808809template <class _A1>
809810inline _LIBCPP_INLINE_VISIBILITY
......@@ -812,10 +813,10 @@ asin(_A1 __lcpp_x) _NOEXCEPT {return ::asin((double)__lcpp_x);}
812813
813814// atan
814815
815#if !(defined(_AIX) || defined(__sun__))
816# if !defined(__sun__)
816817inline _LIBCPP_INLINE_VISIBILITY float atan(float __lcpp_x) _NOEXCEPT {return ::atanf(__lcpp_x);}
817818inline _LIBCPP_INLINE_VISIBILITY long double atan(long double __lcpp_x) _NOEXCEPT {return ::atanl(__lcpp_x);}
818#endif
819# endif
819820
820821template <class _A1>
821822inline _LIBCPP_INLINE_VISIBILITY
......@@ -824,10 +825,10 @@ atan(_A1 __lcpp_x) _NOEXCEPT {return ::atan((double)__lcpp_x);}
824825
825826// atan2
826827
827#if !(defined(_AIX) || defined(__sun__))
828# if !defined(__sun__)
828829inline _LIBCPP_INLINE_VISIBILITY float atan2(float __lcpp_y, float __lcpp_x) _NOEXCEPT {return ::atan2f(__lcpp_y, __lcpp_x);}
829830inline _LIBCPP_INLINE_VISIBILITY long double atan2(long double __lcpp_y, long double __lcpp_x) _NOEXCEPT {return ::atan2l(__lcpp_y, __lcpp_x);}
830#endif
831# endif
831832
832833template <class _A1, class _A2>
833834inline _LIBCPP_INLINE_VISIBILITY
......@@ -847,10 +848,10 @@ atan2(_A1 __lcpp_y, _A2 __lcpp_x) _NOEXCEPT
847848
848849// ceil
849850
850#if !(defined(_AIX) || defined(__sun__))
851# if !defined(__sun__)
851852inline _LIBCPP_INLINE_VISIBILITY float ceil(float __lcpp_x) _NOEXCEPT {return ::ceilf(__lcpp_x);}
852853inline _LIBCPP_INLINE_VISIBILITY long double ceil(long double __lcpp_x) _NOEXCEPT {return ::ceill(__lcpp_x);}
853#endif
854# endif
854855
855856template <class _A1>
856857inline _LIBCPP_INLINE_VISIBILITY
......@@ -859,10 +860,10 @@ ceil(_A1 __lcpp_x) _NOEXCEPT {return ::ceil((double)__lcpp_x);}
859860
860861// cos
861862
862#if !(defined(_AIX) || defined(__sun__))
863# if !defined(__sun__)
863864inline _LIBCPP_INLINE_VISIBILITY float cos(float __lcpp_x) _NOEXCEPT {return ::cosf(__lcpp_x);}
864865inline _LIBCPP_INLINE_VISIBILITY long double cos(long double __lcpp_x) _NOEXCEPT {return ::cosl(__lcpp_x);}
865#endif
866# endif
866867
867868template <class _A1>
868869inline _LIBCPP_INLINE_VISIBILITY
......@@ -871,10 +872,10 @@ cos(_A1 __lcpp_x) _NOEXCEPT {return ::cos((double)__lcpp_x);}
871872
872873// cosh
873874
874#if !(defined(_AIX) || defined(__sun__))
875# if !defined(__sun__)
875876inline _LIBCPP_INLINE_VISIBILITY float cosh(float __lcpp_x) _NOEXCEPT {return ::coshf(__lcpp_x);}
876877inline _LIBCPP_INLINE_VISIBILITY long double cosh(long double __lcpp_x) _NOEXCEPT {return ::coshl(__lcpp_x);}
877#endif
878# endif
878879
879880template <class _A1>
880881inline _LIBCPP_INLINE_VISIBILITY
......@@ -883,10 +884,10 @@ cosh(_A1 __lcpp_x) _NOEXCEPT {return ::cosh((double)__lcpp_x);}
883884
884885// exp
885886
886#if !(defined(_AIX) || defined(__sun__))
887# if !defined(__sun__)
887888inline _LIBCPP_INLINE_VISIBILITY float exp(float __lcpp_x) _NOEXCEPT {return ::expf(__lcpp_x);}
888889inline _LIBCPP_INLINE_VISIBILITY long double exp(long double __lcpp_x) _NOEXCEPT {return ::expl(__lcpp_x);}
889#endif
890# endif
890891
891892template <class _A1>
892893inline _LIBCPP_INLINE_VISIBILITY
......@@ -895,10 +896,10 @@ exp(_A1 __lcpp_x) _NOEXCEPT {return ::exp((double)__lcpp_x);}
895896
896897// fabs
897898
898#if !(defined(_AIX) || defined(__sun__))
899# if !defined(__sun__)
899900inline _LIBCPP_INLINE_VISIBILITY float fabs(float __lcpp_x) _NOEXCEPT {return ::fabsf(__lcpp_x);}
900901inline _LIBCPP_INLINE_VISIBILITY long double fabs(long double __lcpp_x) _NOEXCEPT {return ::fabsl(__lcpp_x);}
901#endif
902# endif
902903
903904template <class _A1>
904905inline _LIBCPP_INLINE_VISIBILITY
......@@ -907,10 +908,10 @@ fabs(_A1 __lcpp_x) _NOEXCEPT {return ::fabs((double)__lcpp_x);}
907908
908909// floor
909910
910#if !(defined(_AIX) || defined(__sun__))
911# if !defined(__sun__)
911912inline _LIBCPP_INLINE_VISIBILITY float floor(float __lcpp_x) _NOEXCEPT {return ::floorf(__lcpp_x);}
912913inline _LIBCPP_INLINE_VISIBILITY long double floor(long double __lcpp_x) _NOEXCEPT {return ::floorl(__lcpp_x);}
913#endif
914# endif
914915
915916template <class _A1>
916917inline _LIBCPP_INLINE_VISIBILITY
......@@ -919,10 +920,10 @@ floor(_A1 __lcpp_x) _NOEXCEPT {return ::floor((double)__lcpp_x);}
919920
920921// fmod
921922
922#if !(defined(_AIX) || defined(__sun__))
923# if !defined(__sun__)
923924inline _LIBCPP_INLINE_VISIBILITY float fmod(float __lcpp_x, float __lcpp_y) _NOEXCEPT {return ::fmodf(__lcpp_x, __lcpp_y);}
924925inline _LIBCPP_INLINE_VISIBILITY long double fmod(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return ::fmodl(__lcpp_x, __lcpp_y);}
925#endif
926# endif
926927
927928template <class _A1, class _A2>
928929inline _LIBCPP_INLINE_VISIBILITY
......@@ -942,10 +943,10 @@ fmod(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
942943
943944// frexp
944945
945#if !(defined(_AIX) || defined(__sun__))
946# if !defined(__sun__)
946947inline _LIBCPP_INLINE_VISIBILITY float frexp(float __lcpp_x, int* __lcpp_e) _NOEXCEPT {return ::frexpf(__lcpp_x, __lcpp_e);}
947948inline _LIBCPP_INLINE_VISIBILITY long double frexp(long double __lcpp_x, int* __lcpp_e) _NOEXCEPT {return ::frexpl(__lcpp_x, __lcpp_e);}
948#endif
949# endif
949950
950951template <class _A1>
951952inline _LIBCPP_INLINE_VISIBILITY
......@@ -954,10 +955,10 @@ frexp(_A1 __lcpp_x, int* __lcpp_e) _NOEXCEPT {return ::frexp((double)__lcpp_x, _
954955
955956// ldexp
956957
957#if !(defined(_AIX) || defined(__sun__))
958# if !defined(__sun__)
958959inline _LIBCPP_INLINE_VISIBILITY float ldexp(float __lcpp_x, int __lcpp_e) _NOEXCEPT {return ::ldexpf(__lcpp_x, __lcpp_e);}
959960inline _LIBCPP_INLINE_VISIBILITY long double ldexp(long double __lcpp_x, int __lcpp_e) _NOEXCEPT {return ::ldexpl(__lcpp_x, __lcpp_e);}
960#endif
961# endif
961962
962963template <class _A1>
963964inline _LIBCPP_INLINE_VISIBILITY
......@@ -966,10 +967,10 @@ ldexp(_A1 __lcpp_x, int __lcpp_e) _NOEXCEPT {return ::ldexp((double)__lcpp_x, __
966967
967968// log
968969
969#if !(defined(_AIX) || defined(__sun__))
970# if !defined(__sun__)
970971inline _LIBCPP_INLINE_VISIBILITY float log(float __lcpp_x) _NOEXCEPT {return ::logf(__lcpp_x);}
971972inline _LIBCPP_INLINE_VISIBILITY long double log(long double __lcpp_x) _NOEXCEPT {return ::logl(__lcpp_x);}
972#endif
973# endif
973974
974975template <class _A1>
975976inline _LIBCPP_INLINE_VISIBILITY
......@@ -978,10 +979,10 @@ log(_A1 __lcpp_x) _NOEXCEPT {return ::log((double)__lcpp_x);}
978979
979980// log10
980981
981#if !(defined(_AIX) || defined(__sun__))
982# if !defined(__sun__)
982983inline _LIBCPP_INLINE_VISIBILITY float log10(float __lcpp_x) _NOEXCEPT {return ::log10f(__lcpp_x);}
983984inline _LIBCPP_INLINE_VISIBILITY long double log10(long double __lcpp_x) _NOEXCEPT {return ::log10l(__lcpp_x);}
984#endif
985# endif
985986
986987template <class _A1>
987988inline _LIBCPP_INLINE_VISIBILITY
......@@ -990,17 +991,17 @@ log10(_A1 __lcpp_x) _NOEXCEPT {return ::log10((double)__lcpp_x);}
990991
991992// modf
992993
993#if !(defined(_AIX) || defined(__sun__))
994# if !defined(__sun__)
994995inline _LIBCPP_INLINE_VISIBILITY float modf(float __lcpp_x, float* __lcpp_y) _NOEXCEPT {return ::modff(__lcpp_x, __lcpp_y);}
995996inline _LIBCPP_INLINE_VISIBILITY long double modf(long double __lcpp_x, long double* __lcpp_y) _NOEXCEPT {return ::modfl(__lcpp_x, __lcpp_y);}
996#endif
997# endif
997998
998999// pow
9991000
1000#if !(defined(_AIX) || defined(__sun__))
1001# if !defined(__sun__)
10011002inline _LIBCPP_INLINE_VISIBILITY float pow(float __lcpp_x, float __lcpp_y) _NOEXCEPT {return ::powf(__lcpp_x, __lcpp_y);}
10021003inline _LIBCPP_INLINE_VISIBILITY long double pow(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return ::powl(__lcpp_x, __lcpp_y);}
1003#endif
1004# endif
10041005
10051006template <class _A1, class _A2>
10061007inline _LIBCPP_INLINE_VISIBILITY
......@@ -1020,7 +1021,7 @@ pow(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
10201021
10211022// sin
10221023
1023#if !(defined(_AIX) || defined(__sun__))
1024# if !defined(__sun__)
10241025inline _LIBCPP_INLINE_VISIBILITY float sin(float __lcpp_x) _NOEXCEPT {return ::sinf(__lcpp_x);}
10251026inline _LIBCPP_INLINE_VISIBILITY long double sin(long double __lcpp_x) _NOEXCEPT {return ::sinl(__lcpp_x);}
10261027#endif
......@@ -1032,10 +1033,10 @@ sin(_A1 __lcpp_x) _NOEXCEPT {return ::sin((double)__lcpp_x);}
10321033
10331034// sinh
10341035
1035#if !(defined(_AIX) || defined(__sun__))
1036# if !defined(__sun__)
10361037inline _LIBCPP_INLINE_VISIBILITY float sinh(float __lcpp_x) _NOEXCEPT {return ::sinhf(__lcpp_x);}
10371038inline _LIBCPP_INLINE_VISIBILITY long double sinh(long double __lcpp_x) _NOEXCEPT {return ::sinhl(__lcpp_x);}
1038#endif
1039# endif
10391040
10401041template <class _A1>
10411042inline _LIBCPP_INLINE_VISIBILITY
......@@ -1044,10 +1045,10 @@ sinh(_A1 __lcpp_x) _NOEXCEPT {return ::sinh((double)__lcpp_x);}
10441045
10451046// sqrt
10461047
1047#if !(defined(_AIX) || defined(__sun__))
1048# if !defined(__sun__)
10481049inline _LIBCPP_INLINE_VISIBILITY float sqrt(float __lcpp_x) _NOEXCEPT {return ::sqrtf(__lcpp_x);}
10491050inline _LIBCPP_INLINE_VISIBILITY long double sqrt(long double __lcpp_x) _NOEXCEPT {return ::sqrtl(__lcpp_x);}
1050#endif
1051# endif
10511052
10521053template <class _A1>
10531054inline _LIBCPP_INLINE_VISIBILITY
......@@ -1056,10 +1057,10 @@ sqrt(_A1 __lcpp_x) _NOEXCEPT {return ::sqrt((double)__lcpp_x);}
10561057
10571058// tan
10581059
1059#if !(defined(_AIX) || defined(__sun__))
1060# if !defined(__sun__)
10601061inline _LIBCPP_INLINE_VISIBILITY float tan(float __lcpp_x) _NOEXCEPT {return ::tanf(__lcpp_x);}
10611062inline _LIBCPP_INLINE_VISIBILITY long double tan(long double __lcpp_x) _NOEXCEPT {return ::tanl(__lcpp_x);}
1062#endif
1063# endif
10631064
10641065template <class _A1>
10651066inline _LIBCPP_INLINE_VISIBILITY
......@@ -1068,10 +1069,10 @@ tan(_A1 __lcpp_x) _NOEXCEPT {return ::tan((double)__lcpp_x);}
10681069
10691070// tanh
10701071
1071#if !(defined(_AIX) || defined(__sun__))
1072# if !defined(__sun__)
10721073inline _LIBCPP_INLINE_VISIBILITY float tanh(float __lcpp_x) _NOEXCEPT {return ::tanhf(__lcpp_x);}
10731074inline _LIBCPP_INLINE_VISIBILITY long double tanh(long double __lcpp_x) _NOEXCEPT {return ::tanhl(__lcpp_x);}
1074#endif
1075# endif
10751076
10761077template <class _A1>
10771078inline _LIBCPP_INLINE_VISIBILITY
lib/libcxx/include/memory+68-137
......@@ -98,6 +98,16 @@ struct allocator_traits
9898 static allocator_type select_on_container_copy_construction(const allocator_type& a); // constexpr in C++20
9999};
100100
101template<class Pointer>
102struct allocation_result {
103 Pointer ptr;
104 size_t count;
105}; // since C++23
106
107template<class Allocator>
108[[nodiscard]] constexpr allocation_result<typename allocator_traits<Allocator>::pointer>
109 allocate_at_least(Allocator& a, size_t n); // since C++23
110
101111template <>
102112class allocator<void> // removed in C++20
103113{
......@@ -661,9 +671,29 @@ template<class E, class T, class Y>
661671template<class D, class T> D* get_deleter(shared_ptr<T> const& p) noexcept;
662672
663673template<class T, class... Args>
664 shared_ptr<T> make_shared(Args&&... args);
674 shared_ptr<T> make_shared(Args&&... args); // T is not an array
665675template<class T, class A, class... Args>
666 shared_ptr<T> allocate_shared(const A& a, Args&&... args);
676 shared_ptr<T> allocate_shared(const A& a, Args&&... args); // T is not an array
677
678template<class T>
679 shared_ptr<T> make_shared(size_t N); // T is U[] (since C++20)
680template<class T, class A>
681 shared_ptr<T> allocate_shared(const A& a, size_t N); // T is U[] (since C++20)
682
683template<class T>
684 shared_ptr<T> make_shared(); // T is U[N] (since C++20)
685template<class T, class A>
686 shared_ptr<T> allocate_shared(const A& a); // T is U[N] (since C++20)
687
688template<class T>
689 shared_ptr<T> make_shared(size_t N, const remove_extent_t<T>& u); // T is U[] (since C++20)
690template<class T, class A>
691 shared_ptr<T> allocate_shared(const A& a, size_t N, const remove_extent_t<T>& u); // T is U[] (since C++20)
692
693template<class T> shared_ptr<T>
694 make_shared(const remove_extent_t<T>& u); // T is U[N] (since C++20)
695template<class T, class A>
696 shared_ptr<T> allocate_shared(const A& a, const remove_extent_t<T>& u); // T is U[N] (since C++20)
667697
668698template<class T>
669699class weak_ptr
......@@ -798,19 +828,28 @@ template <class T> struct hash<shared_ptr<T> >;
798828template <class T, class Alloc>
799829 inline constexpr bool uses_allocator_v = uses_allocator<T, Alloc>::value;
800830
831// [ptr.align]
801832void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
802833
834template<size_t N, class T>
835[[nodiscard]] constexpr T* assume_aligned(T* ptr); // since C++20
836
803837} // std
804838
805839*/
806840
841#include <__algorithm/copy.h>
842#include <__algorithm/move.h>
843#include <__assert> // all public C++ headers provide the assertion handler
807844#include <__config>
808#include <__functional_base>
809845#include <__memory/addressof.h>
846#include <__memory/allocate_at_least.h>
810847#include <__memory/allocation_guard.h>
811848#include <__memory/allocator.h>
812849#include <__memory/allocator_arg_t.h>
813850#include <__memory/allocator_traits.h>
851#include <__memory/assume_aligned.h>
852#include <__memory/auto_ptr.h>
814853#include <__memory/compressed_pair.h>
815854#include <__memory/concepts.h>
816855#include <__memory/construct_at.h>
......@@ -823,117 +862,31 @@ void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
823862#include <__memory/uninitialized_algorithms.h>
824863#include <__memory/unique_ptr.h>
825864#include <__memory/uses_allocator.h>
826#include <compare>
827865#include <cstddef>
828866#include <cstdint>
829867#include <cstring>
830868#include <iosfwd>
831#include <iterator>
832869#include <new>
833870#include <stdexcept>
834871#include <tuple>
835872#include <type_traits>
836873#include <typeinfo>
837#include <utility>
838874#include <version>
839875
840#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
841# include <__memory/auto_ptr.h>
876#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
877# include <iterator>
878# include <utility>
842879#endif
843880
881// standard-mandated includes
882#include <compare>
883
844884#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
845#pragma GCC system_header
885# pragma GCC system_header
846886#endif
847887
848888_LIBCPP_BEGIN_NAMESPACE_STD
849889
850template <class _Alloc, class _Ptr>
851_LIBCPP_INLINE_VISIBILITY
852void __construct_forward_with_exception_guarantees(_Alloc& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2) {
853 static_assert(__is_cpp17_move_insertable<_Alloc>::value,
854 "The specified type does not meet the requirements of Cpp17MoveInsertable");
855 typedef allocator_traits<_Alloc> _Traits;
856 for (; __begin1 != __end1; ++__begin1, (void)++__begin2) {
857 _Traits::construct(__a, _VSTD::__to_address(__begin2),
858#ifdef _LIBCPP_NO_EXCEPTIONS
859 _VSTD::move(*__begin1)
860#else
861 _VSTD::move_if_noexcept(*__begin1)
862#endif
863 );
864 }
865}
866
867template <class _Alloc, class _Tp, typename enable_if<
868 (__is_default_allocator<_Alloc>::value || !__has_construct<_Alloc, _Tp*, _Tp>::value) &&
869 is_trivially_move_constructible<_Tp>::value
870>::type>
871_LIBCPP_INLINE_VISIBILITY
872void __construct_forward_with_exception_guarantees(_Alloc&, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2) {
873 ptrdiff_t _Np = __end1 - __begin1;
874 if (_Np > 0) {
875 _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp));
876 __begin2 += _Np;
877 }
878}
879
880template <class _Alloc, class _Iter, class _Ptr>
881_LIBCPP_INLINE_VISIBILITY
882void __construct_range_forward(_Alloc& __a, _Iter __begin1, _Iter __end1, _Ptr& __begin2) {
883 typedef allocator_traits<_Alloc> _Traits;
884 for (; __begin1 != __end1; ++__begin1, (void) ++__begin2) {
885 _Traits::construct(__a, _VSTD::__to_address(__begin2), *__begin1);
886 }
887}
888
889template <class _Alloc, class _Source, class _Dest,
890 class _RawSource = typename remove_const<_Source>::type,
891 class _RawDest = typename remove_const<_Dest>::type,
892 class =
893 typename enable_if<
894 is_trivially_copy_constructible<_Dest>::value &&
895 is_same<_RawSource, _RawDest>::value &&
896 (__is_default_allocator<_Alloc>::value || !__has_construct<_Alloc, _Dest*, _Source&>::value)
897 >::type>
898_LIBCPP_INLINE_VISIBILITY
899void __construct_range_forward(_Alloc&, _Source* __begin1, _Source* __end1, _Dest*& __begin2) {
900 ptrdiff_t _Np = __end1 - __begin1;
901 if (_Np > 0) {
902 _VSTD::memcpy(const_cast<_RawDest*>(__begin2), __begin1, _Np * sizeof(_Dest));
903 __begin2 += _Np;
904 }
905}
906
907template <class _Alloc, class _Ptr>
908_LIBCPP_INLINE_VISIBILITY
909void __construct_backward_with_exception_guarantees(_Alloc& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2) {
910 static_assert(__is_cpp17_move_insertable<_Alloc>::value,
911 "The specified type does not meet the requirements of Cpp17MoveInsertable");
912 typedef allocator_traits<_Alloc> _Traits;
913 while (__end1 != __begin1) {
914 _Traits::construct(__a, _VSTD::__to_address(__end2 - 1),
915#ifdef _LIBCPP_NO_EXCEPTIONS
916 _VSTD::move(*--__end1)
917#else
918 _VSTD::move_if_noexcept(*--__end1)
919#endif
920 );
921 --__end2;
922 }
923}
924
925template <class _Alloc, class _Tp, class = typename enable_if<
926 (__is_default_allocator<_Alloc>::value || !__has_construct<_Alloc, _Tp*, _Tp>::value) &&
927 is_trivially_move_constructible<_Tp>::value
928>::type>
929_LIBCPP_INLINE_VISIBILITY
930void __construct_backward_with_exception_guarantees(_Alloc&, _Tp* __begin1, _Tp* __end1, _Tp*& __end2) {
931 ptrdiff_t _Np = __end1 - __begin1;
932 __end2 -= _Np;
933 if (_Np > 0)
934 _VSTD::memcpy(static_cast<void*>(__end2), static_cast<void const*>(__begin1), _Np * sizeof(_Tp));
935}
936
937890struct __destruct_n
938891{
939892private:
......@@ -975,37 +928,6 @@ public:
975928
976929_LIBCPP_FUNC_VIS void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space);
977930
978// --- Helper for container swap --
979template <typename _Alloc>
980_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
981void __swap_allocator(_Alloc & __a1, _Alloc & __a2, true_type)
982#if _LIBCPP_STD_VER > 11
983 _NOEXCEPT
984#else
985 _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
986#endif
987{
988 using _VSTD::swap;
989 swap(__a1, __a2);
990}
991
992template <typename _Alloc>
993inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
994void __swap_allocator(_Alloc &, _Alloc &, false_type) _NOEXCEPT {}
995
996template <typename _Alloc>
997inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
998void __swap_allocator(_Alloc & __a1, _Alloc & __a2)
999#if _LIBCPP_STD_VER > 11
1000 _NOEXCEPT
1001#else
1002 _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
1003#endif
1004{
1005 _VSTD::__swap_allocator(__a1, __a2,
1006 integral_constant<bool, allocator_traits<_Alloc>::propagate_on_container_swap::value>());
1007}
1008
1009931template <typename _Alloc, typename _Traits=allocator_traits<_Alloc> >
1010932struct __noexcept_move_assign_container : public integral_constant<bool,
1011933 _Traits::propagate_on_container_move_assignment::value
......@@ -1021,21 +943,31 @@ template <class _Tp, class _Alloc>
1021943struct __temp_value {
1022944 typedef allocator_traits<_Alloc> _Traits;
1023945
946#ifdef _LIBCPP_CXX03_LANG
1024947 typename aligned_storage<sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)>::type __v;
948#else
949 union { _Tp __v; };
950#endif
1025951 _Alloc &__a;
1026952
1027 _Tp *__addr() { return reinterpret_cast<_Tp *>(addressof(__v)); }
1028 _Tp & get() { return *__addr(); }
953 _LIBCPP_CONSTEXPR_AFTER_CXX17 _Tp *__addr() {
954#ifdef _LIBCPP_CXX03_LANG
955 return reinterpret_cast<_Tp*>(std::addressof(__v));
956#else
957 return std::addressof(__v);
958#endif
959 }
960
961 _LIBCPP_CONSTEXPR_AFTER_CXX17 _Tp & get() { return *__addr(); }
1029962
1030963 template<class... _Args>
1031964 _LIBCPP_NO_CFI
1032 __temp_value(_Alloc &__alloc, _Args&& ... __args) : __a(__alloc) {
1033 _Traits::construct(__a, reinterpret_cast<_Tp*>(addressof(__v)),
1034 _VSTD::forward<_Args>(__args)...);
965 _LIBCPP_CONSTEXPR_AFTER_CXX17 __temp_value(_Alloc &__alloc, _Args&& ... __args) : __a(__alloc) {
966 _Traits::construct(__a, __addr(), std::forward<_Args>(__args)...);
1035967 }
1036968
1037 ~__temp_value() { _Traits::destroy(__a, __addr()); }
1038 };
969 _LIBCPP_CONSTEXPR_AFTER_CXX17 ~__temp_value() { _Traits::destroy(__a, __addr()); }
970};
1039971
1040972template<typename _Alloc, typename = void, typename = void>
1041973struct __is_allocator : false_type {};
......@@ -1058,8 +990,8 @@ struct __builtin_new_allocator {
1058990 _LIBCPP_CONSTEXPR explicit __builtin_new_deleter(size_t __size, size_t __align)
1059991 : __size_(__size), __align_(__align) {}
1060992
1061 void operator()(void* p) const _NOEXCEPT {
1062 _VSTD::__libcpp_deallocate(p, __size_, __align_);
993 void operator()(void* __p) const _NOEXCEPT {
994 _VSTD::__libcpp_deallocate(__p, __size_, __align_);
1063995 }
1064996
1065997 private:
......@@ -1092,7 +1024,6 @@ struct __builtin_new_allocator {
10921024 }
10931025};
10941026
1095
10961027_LIBCPP_END_NAMESPACE_STD
10971028
10981029#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17
lib/libcxx/include/module.modulemap deleted-1092
......@@ -1,1092 +0,0 @@
1// define the module for __config outside of the top level 'std' module
2// since __config may be included from C headers which may create an
3// include cycle.
4module std_config [system] [extern_c] {
5 textual header "__config"
6 textual header "__config_site"
7}
8
9module std [system] {
10 export std_config
11 // FIXME: The standard does not require that each of these submodules
12 // re-exports its imported modules. We should provide an alternative form of
13 // export that issues a warning if a name from the submodule is used, and
14 // use that to provide a 'strict mode' for libc++.
15
16 // Deprecated C-compatibility headers. These can all be included from within
17 // an 'extern "C"' context.
18 module depr [extern_c] {
19 // <assert.h> provided by C library.
20 module ctype_h {
21 header "ctype.h"
22 export *
23 }
24 module errno_h {
25 header "errno.h"
26 export *
27 }
28 module fenv_h {
29 header "fenv.h"
30 export *
31 }
32 // <float.h> provided by compiler or C library.
33 module inttypes_h {
34 header "inttypes.h"
35 export stdint_h
36 export *
37 }
38 // <iso646.h> provided by compiler.
39 // <limits.h> provided by compiler or C library.
40 module locale_h {
41 header "locale.h"
42 export *
43 }
44 module math_h {
45 header "math.h"
46 export *
47 }
48 module setjmp_h {
49 header "setjmp.h"
50 export *
51 }
52 // FIXME: <stdalign.h> is missing.
53 // <signal.h> provided by C library.
54 // <stdarg.h> provided by compiler.
55 // <stdbool.h> provided by compiler.
56 module stddef_h {
57 // <stddef.h>'s __need_* macros require textual inclusion.
58 textual header "stddef.h"
59 }
60 module stdint_h {
61 header "stdint.h"
62 export *
63 // FIXME: This module only exists on OS X and for some reason the
64 // wildcard above doesn't export it.
65 export Darwin.C.stdint
66 }
67 module stdio_h {
68 // <stdio.h>'s __need_* macros require textual inclusion.
69 textual header "stdio.h"
70 export *
71 export Darwin.C.stdio
72 }
73 module stdlib_h {
74 // <stdlib.h>'s __need_* macros require textual inclusion.
75 textual header "stdlib.h"
76 export *
77 }
78 module string_h {
79 header "string.h"
80 export *
81 }
82 // FIXME: <uchar.h> is missing.
83 // <time.h> provided by C library.
84 module wchar_h {
85 // <wchar.h>'s __need_* macros require textual inclusion.
86 textual header "wchar.h"
87 export *
88 }
89 module wctype_h {
90 header "wctype.h"
91 export *
92 }
93 }
94
95 // <complex.h> and <tgmath.h> are not C headers in any real sense, do not
96 // allow their use in extern "C" contexts.
97 module complex_h {
98 header "complex.h"
99 export ccomplex
100 export *
101 }
102 module tgmath_h {
103 header "tgmath.h"
104 export ccomplex
105 export cmath
106 export *
107 }
108
109 // C compatibility headers.
110 module compat {
111 module cassert {
112 // <cassert>'s use of NDEBUG requires textual inclusion.
113 textual header "cassert"
114 }
115 module ccomplex {
116 header "ccomplex"
117 export complex
118 export *
119 }
120 module cctype {
121 header "cctype"
122 export *
123 }
124 module cerrno {
125 header "cerrno"
126 export *
127 }
128 module cfenv {
129 header "cfenv"
130 export *
131 }
132 module cfloat {
133 header "cfloat"
134 export *
135 }
136 module cinttypes {
137 header "cinttypes"
138 export cstdint
139 export *
140 }
141 module ciso646 {
142 header "ciso646"
143 export *
144 }
145 module climits {
146 header "climits"
147 export *
148 }
149 module clocale {
150 header "clocale"
151 export *
152 }
153 module cmath {
154 header "cmath"
155 export *
156 }
157 module csetjmp {
158 header "csetjmp"
159 export *
160 }
161 module csignal {
162 header "csignal"
163 export *
164 }
165 // FIXME: <cstdalign> is missing.
166 module cstdarg {
167 header "cstdarg"
168 export *
169 }
170 module cstdbool {
171 header "cstdbool"
172 export *
173 }
174 module cstddef {
175 header "cstddef"
176 export *
177 }
178 module cstdint {
179 header "cstdint"
180 export depr.stdint_h
181 export *
182 }
183 module cstdio {
184 header "cstdio"
185 export *
186 }
187 module cstdlib {
188 header "cstdlib"
189 export *
190 }
191 module cstring {
192 header "cstring"
193 export *
194 }
195 module ctgmath {
196 header "ctgmath"
197 export ccomplex
198 export cmath
199 export *
200 }
201 module ctime {
202 header "ctime"
203 export *
204 }
205 // FIXME: <cuchar> is missing.
206 module cwchar {
207 header "cwchar"
208 export depr.stdio_h
209 export *
210 }
211 module cwctype {
212 header "cwctype"
213 export *
214 }
215 }
216
217 module algorithm {
218 header "algorithm"
219 export initializer_list
220 export *
221
222 module __algorithm {
223 module adjacent_find { private header "__algorithm/adjacent_find.h" }
224 module all_of { private header "__algorithm/all_of.h" }
225 module any_of { private header "__algorithm/any_of.h" }
226 module binary_search { private header "__algorithm/binary_search.h" }
227 module clamp { private header "__algorithm/clamp.h" }
228 module comp { private header "__algorithm/comp.h" }
229 module comp_ref_type { private header "__algorithm/comp_ref_type.h" }
230 module copy { private header "__algorithm/copy.h" }
231 module copy_backward { private header "__algorithm/copy_backward.h" }
232 module copy_if { private header "__algorithm/copy_if.h" }
233 module copy_n { private header "__algorithm/copy_n.h" }
234 module count { private header "__algorithm/count.h" }
235 module count_if { private header "__algorithm/count_if.h" }
236 module equal { private header "__algorithm/equal.h" }
237 module equal_range { private header "__algorithm/equal_range.h" }
238 module fill { private header "__algorithm/fill.h" }
239 module fill_n { private header "__algorithm/fill_n.h" }
240 module find { private header "__algorithm/find.h" }
241 module find_end { private header "__algorithm/find_end.h" }
242 module find_first_of { private header "__algorithm/find_first_of.h" }
243 module find_if { private header "__algorithm/find_if.h" }
244 module find_if_not { private header "__algorithm/find_if_not.h" }
245 module for_each { private header "__algorithm/for_each.h" }
246 module for_each_n { private header "__algorithm/for_each_n.h" }
247 module generate { private header "__algorithm/generate.h" }
248 module generate_n { private header "__algorithm/generate_n.h" }
249 module half_positive { private header "__algorithm/half_positive.h" }
250 module in_in_out_result { private header "__algorithm/in_in_out_result.h" }
251 module in_in_result { private header "__algorithm/in_in_result.h" }
252 module in_out_result { private header "__algorithm/in_out_result.h" }
253 module includes { private header "__algorithm/includes.h" }
254 module inplace_merge { private header "__algorithm/inplace_merge.h" }
255 module is_heap { private header "__algorithm/is_heap.h" }
256 module is_heap_until { private header "__algorithm/is_heap_until.h" }
257 module is_partitioned { private header "__algorithm/is_partitioned.h" }
258 module is_permutation { private header "__algorithm/is_permutation.h" }
259 module is_sorted { private header "__algorithm/is_sorted.h" }
260 module is_sorted_until { private header "__algorithm/is_sorted_until.h" }
261 module iter_swap { private header "__algorithm/iter_swap.h" }
262 module lexicographical_compare { private header "__algorithm/lexicographical_compare.h" }
263 module lower_bound { private header "__algorithm/lower_bound.h" }
264 module make_heap { private header "__algorithm/make_heap.h" }
265 module max { private header "__algorithm/max.h" }
266 module max_element { private header "__algorithm/max_element.h" }
267 module merge { private header "__algorithm/merge.h" }
268 module min { private header "__algorithm/min.h" }
269 module min_element { private header "__algorithm/min_element.h" }
270 module minmax { private header "__algorithm/minmax.h" }
271 module minmax_element { private header "__algorithm/minmax_element.h" }
272 module mismatch { private header "__algorithm/mismatch.h" }
273 module move { private header "__algorithm/move.h" }
274 module move_backward { private header "__algorithm/move_backward.h" }
275 module next_permutation { private header "__algorithm/next_permutation.h" }
276 module none_of { private header "__algorithm/none_of.h" }
277 module nth_element { private header "__algorithm/nth_element.h" }
278 module partial_sort { private header "__algorithm/partial_sort.h" }
279 module partial_sort_copy { private header "__algorithm/partial_sort_copy.h" }
280 module partition { private header "__algorithm/partition.h" }
281 module partition_copy { private header "__algorithm/partition_copy.h" }
282 module partition_point { private header "__algorithm/partition_point.h" }
283 module pop_heap { private header "__algorithm/pop_heap.h" }
284 module prev_permutation { private header "__algorithm/prev_permutation.h" }
285 module push_heap { private header "__algorithm/push_heap.h" }
286 module remove { private header "__algorithm/remove.h" }
287 module remove_copy { private header "__algorithm/remove_copy.h" }
288 module remove_copy_if { private header "__algorithm/remove_copy_if.h" }
289 module remove_if { private header "__algorithm/remove_if.h" }
290 module replace { private header "__algorithm/replace.h" }
291 module replace_copy { private header "__algorithm/replace_copy.h" }
292 module replace_copy_if { private header "__algorithm/replace_copy_if.h" }
293 module replace_if { private header "__algorithm/replace_if.h" }
294 module reverse { private header "__algorithm/reverse.h" }
295 module reverse_copy { private header "__algorithm/reverse_copy.h" }
296 module rotate { private header "__algorithm/rotate.h" }
297 module rotate_copy { private header "__algorithm/rotate_copy.h" }
298 module sample { private header "__algorithm/sample.h" }
299 module search { private header "__algorithm/search.h" }
300 module search_n { private header "__algorithm/search_n.h" }
301 module set_difference { private header "__algorithm/set_difference.h" }
302 module set_intersection { private header "__algorithm/set_intersection.h" }
303 module set_symmetric_difference { private header "__algorithm/set_symmetric_difference.h" }
304 module set_union { private header "__algorithm/set_union.h" }
305 module shift_left { private header "__algorithm/shift_left.h" }
306 module shift_right { private header "__algorithm/shift_right.h" }
307 module shuffle { private header "__algorithm/shuffle.h" }
308 module sift_down { private header "__algorithm/sift_down.h" }
309 module sort { private header "__algorithm/sort.h" }
310 module sort_heap { private header "__algorithm/sort_heap.h" }
311 module stable_partition { private header "__algorithm/stable_partition.h" }
312 module stable_sort { private header "__algorithm/stable_sort.h" }
313 module swap_ranges { private header "__algorithm/swap_ranges.h" }
314 module transform { private header "__algorithm/transform.h" }
315 module unique { private header "__algorithm/unique.h" }
316 module unique_copy { private header "__algorithm/unique_copy.h" }
317 module unwrap_iter { private header "__algorithm/unwrap_iter.h" }
318 module upper_bound { private header "__algorithm/upper_bound.h" }
319 }
320 }
321 module any {
322 header "any"
323 export *
324 }
325 module array {
326 header "array"
327 export initializer_list
328 export *
329 }
330 module atomic {
331 header "atomic"
332 export *
333 }
334 module barrier {
335 requires cplusplus14
336 header "barrier"
337 export *
338 }
339 module bit {
340 header "bit"
341 export *
342
343 module __bit {
344 module bit_cast { private header "__bit/bit_cast.h" }
345 module byteswap { private header "__bit/byteswap.h" }
346 }
347 }
348 module bitset {
349 header "bitset"
350 export string
351 export iosfwd
352 export *
353 }
354 // No submodule for cassert. It fundamentally needs repeated, textual inclusion.
355 module charconv {
356 header "charconv"
357 export *
358
359 module __charconv {
360 module chars_format { private header "__charconv/chars_format.h" }
361 module from_chars_result { private header "__charconv/from_chars_result.h" }
362 module to_chars_result { private header "__charconv/to_chars_result.h" }
363 }
364
365 }
366 module chrono {
367 header "chrono"
368 export *
369
370 module __chrono {
371 module calendar { private header "__chrono/calendar.h" }
372 module convert_to_timespec { private header "__chrono/convert_to_timespec.h" }
373 module duration { private header "__chrono/duration.h" }
374 module file_clock { private header "__chrono/file_clock.h" }
375 module high_resolution_clock { private header "__chrono/high_resolution_clock.h" }
376 module steady_clock { private header "__chrono/steady_clock.h" }
377 module system_clock { private header "__chrono/system_clock.h" }
378 module time_point { private header "__chrono/time_point.h" }
379 }
380 }
381 module codecvt {
382 header "codecvt"
383 export *
384 }
385 module compare {
386 header "compare"
387 export *
388
389 module __compare {
390 module common_comparison_category { private header "__compare/common_comparison_category.h" }
391 module compare_partial_order_fallback { private header "__compare/compare_partial_order_fallback.h" }
392 module compare_strong_order_fallback { private header "__compare/compare_strong_order_fallback.h" }
393 module compare_three_way { private header "__compare/compare_three_way.h" }
394 module compare_three_way_result { private header "__compare/compare_three_way_result.h" }
395 module compare_weak_order_fallback { private header "__compare/compare_weak_order_fallback.h" }
396 module is_eq { private header "__compare/is_eq.h" }
397 module ordering { private header "__compare/ordering.h" }
398 module partial_order { private header "__compare/partial_order.h" }
399 module strong_order { private header "__compare/strong_order.h" }
400 module synth_three_way { private header "__compare/synth_three_way.h" }
401 module three_way_comparable { private header "__compare/three_way_comparable.h" }
402 module weak_order { private header "__compare/weak_order.h" }
403 }
404 }
405 module complex {
406 header "complex"
407 export *
408 }
409 module concepts {
410 header "concepts"
411 export *
412
413 module __concepts {
414 module arithmetic { private header "__concepts/arithmetic.h" }
415 module assignable { private header "__concepts/assignable.h" }
416 module boolean_testable { private header "__concepts/boolean_testable.h" }
417 module class_or_enum { private header "__concepts/class_or_enum.h" }
418 module common_reference_with { private header "__concepts/common_reference_with.h" }
419 module common_with { private header "__concepts/common_with.h" }
420 module constructible { private header "__concepts/constructible.h" }
421 module convertible_to { private header "__concepts/convertible_to.h" }
422 module copyable { private header "__concepts/copyable.h" }
423 module derived_from { private header "__concepts/derived_from.h" }
424 module destructible { private header "__concepts/destructible.h" }
425 module different_from { private header "__concepts/different_from.h" }
426 module equality_comparable { private header "__concepts/equality_comparable.h" }
427 module invocable { private header "__concepts/invocable.h" }
428 module movable { private header "__concepts/movable.h" }
429 module predicate { private header "__concepts/predicate.h" }
430 module regular { private header "__concepts/regular.h" }
431 module relation { private header "__concepts/relation.h" }
432 module same_as { private header "__concepts/same_as.h" }
433 module semiregular { private header "__concepts/semiregular.h" }
434 module swappable { private header "__concepts/swappable.h" }
435 module totally_ordered { private header "__concepts/totally_ordered.h" }
436 }
437 }
438 module condition_variable {
439 header "condition_variable"
440 export *
441 }
442 module coroutine {
443 requires coroutines
444 header "coroutine"
445 export compare
446 export *
447
448 module __coroutine {
449 module coroutine_handle { private header "__coroutine/coroutine_handle.h" }
450 module coroutine_traits { private header "__coroutine/coroutine_traits.h" }
451 module noop_coroutine_handle { private header "__coroutine/noop_coroutine_handle.h" }
452 module trivial_awaitables { private header "__coroutine/trivial_awaitables.h" }
453 }
454 }
455 module deque {
456 header "deque"
457 export initializer_list
458 export *
459 }
460 module exception {
461 header "exception"
462 export *
463 }
464 module execution {
465 header "execution"
466 export *
467 }
468 module filesystem {
469 header "filesystem"
470 export *
471
472 module __filesystem {
473 module copy_options { private header "__filesystem/copy_options.h" }
474 module directory_entry { private header "__filesystem/directory_entry.h" }
475 module directory_iterator { private header "__filesystem/directory_iterator.h" }
476 module directory_options { private header "__filesystem/directory_options.h" }
477 module file_status { private header "__filesystem/file_status.h" }
478 module file_time_type { private header "__filesystem/file_time_type.h" }
479 module file_type { private header "__filesystem/file_type.h" }
480 module filesystem_error { private header "__filesystem/filesystem_error.h" }
481 module operations { private header "__filesystem/operations.h" }
482 module path { private header "__filesystem/path.h" }
483 module path_iterator { private header "__filesystem/path_iterator.h" }
484 module perm_options { private header "__filesystem/perm_options.h" }
485 module perms { private header "__filesystem/perms.h" }
486 module recursive_directory_iterator { private header "__filesystem/recursive_directory_iterator.h" }
487 module space_info { private header "__filesystem/space_info.h" }
488 module u8path { private header "__filesystem/u8path.h" }
489 }
490 }
491 module format {
492 header "format"
493 export *
494
495 module __format {
496 module format_arg { private header "__format/format_arg.h" }
497 module format_args { private header "__format/format_args.h" }
498 module format_context {
499 private header "__format/format_context.h"
500 export optional
501 export locale
502 }
503 module format_error { private header "__format/format_error.h" }
504 module format_fwd { private header "__format/format_fwd.h" }
505 module format_parse_context { private header "__format/format_parse_context.h" }
506 module format_string { private header "__format/format_string.h" }
507 module format_to_n_result { private header "__format/format_to_n_result.h" }
508 module formatter { private header "__format/formatter.h" }
509 module formatter_bool { private header "__format/formatter_bool.h" }
510 module formatter_char { private header "__format/formatter_char.h" }
511 module formatter_floating_point { private header "__format/formatter_floating_point.h" }
512 module formatter_integer { private header "__format/formatter_integer.h" }
513 module formatter_integral { private header "__format/formatter_integral.h" }
514 module formatter_pointer { private header "__format/formatter_pointer.h" }
515 module formatter_string { private header "__format/formatter_string.h" }
516 module parser_std_format_spec { private header "__format/parser_std_format_spec.h" }
517 }
518 }
519 module forward_list {
520 header "forward_list"
521 export initializer_list
522 export *
523 }
524 module fstream {
525 header "fstream"
526 export *
527 }
528 module functional {
529 header "functional"
530 export *
531
532 module __functional {
533 module binary_function { private header "__functional/binary_function.h" }
534 module binary_negate { private header "__functional/binary_negate.h" }
535 module bind { private header "__functional/bind.h" }
536 module bind_back { private header "__functional/bind_back.h" }
537 module bind_front { private header "__functional/bind_front.h" }
538 module binder1st { private header "__functional/binder1st.h" }
539 module binder2nd { private header "__functional/binder2nd.h" }
540 module compose { private header "__functional/compose.h" }
541 module default_searcher { private header "__functional/default_searcher.h" }
542 module function { private header "__functional/function.h" }
543 module hash { private header "__functional/hash.h" }
544 module identity { private header "__functional/identity.h" }
545 module invoke { private header "__functional/invoke.h" }
546 module is_transparent { private header "__functional/is_transparent.h" }
547 module mem_fn { private header "__functional/mem_fn.h" }
548 module mem_fun_ref { private header "__functional/mem_fun_ref.h" }
549 module not_fn { private header "__functional/not_fn.h" }
550 module operations { private header "__functional/operations.h" }
551 module perfect_forward { private header "__functional/perfect_forward.h" }
552 module pointer_to_binary_function { private header "__functional/pointer_to_binary_function.h" }
553 module pointer_to_unary_function { private header "__functional/pointer_to_unary_function.h" }
554 module ranges_operations { private header "__functional/ranges_operations.h" }
555 module reference_wrapper { private header "__functional/reference_wrapper.h" }
556 module unary_function { private header "__functional/unary_function.h" }
557 module unary_negate { private header "__functional/unary_negate.h" }
558 module unwrap_ref { private header "__functional/unwrap_ref.h" }
559 module weak_result_type { private header "__functional/weak_result_type.h" }
560 }
561 }
562 module future {
563 header "future"
564 export *
565 }
566 module initializer_list {
567 header "initializer_list"
568 export *
569 }
570 module iomanip {
571 header "iomanip"
572 export *
573 }
574 module ios {
575 header "ios"
576 export iosfwd
577 export *
578 }
579 module iosfwd {
580 header "iosfwd"
581 export *
582 }
583 module iostream {
584 header "iostream"
585 export ios
586 export streambuf
587 export istream
588 export ostream
589 export *
590 }
591 module istream {
592 header "istream"
593 // FIXME: should re-export ios, streambuf?
594 export *
595 }
596 module iterator {
597 header "iterator"
598 export *
599
600 module __iterator {
601 module access { private header "__iterator/access.h" }
602 module advance { private header "__iterator/advance.h" }
603 module back_insert_iterator { private header "__iterator/back_insert_iterator.h" }
604 module common_iterator { private header "__iterator/common_iterator.h" }
605 module concepts { private header "__iterator/concepts.h" }
606 module counted_iterator { private header "__iterator/counted_iterator.h" }
607 module data { private header "__iterator/data.h" }
608 module default_sentinel { private header "__iterator/default_sentinel.h" }
609 module distance { private header "__iterator/distance.h" }
610 module empty { private header "__iterator/empty.h" }
611 module erase_if_container { private header "__iterator/erase_if_container.h" }
612 module front_insert_iterator { private header "__iterator/front_insert_iterator.h" }
613 module incrementable_traits { private header "__iterator/incrementable_traits.h" }
614 module indirectly_comparable { private header "__iterator/indirectly_comparable.h" }
615 module insert_iterator { private header "__iterator/insert_iterator.h" }
616 module istream_iterator { private header "__iterator/istream_iterator.h" }
617 module istreambuf_iterator { private header "__iterator/istreambuf_iterator.h" }
618 module iter_move { private header "__iterator/iter_move.h" }
619 module iter_swap { private header "__iterator/iter_swap.h" }
620 module iterator { private header "__iterator/iterator.h" }
621 module iterator_traits { private header "__iterator/iterator_traits.h" }
622 module move_iterator { private header "__iterator/move_iterator.h" }
623 module next { private header "__iterator/next.h" }
624 module ostream_iterator { private header "__iterator/ostream_iterator.h" }
625 module ostreambuf_iterator { private header "__iterator/ostreambuf_iterator.h" }
626 module prev { private header "__iterator/prev.h" }
627 module projected { private header "__iterator/projected.h" }
628 module readable_traits { private header "__iterator/readable_traits.h" }
629 module reverse_access { private header "__iterator/reverse_access.h" }
630 module reverse_iterator { private header "__iterator/reverse_iterator.h" }
631 module size { private header "__iterator/size.h" }
632 module unreachable_sentinel { private header "__iterator/unreachable_sentinel.h" }
633 module wrap_iter { private header "__iterator/wrap_iter.h" }
634 }
635 }
636 module latch {
637 requires cplusplus14
638 header "latch"
639 export *
640 }
641 module limits {
642 header "limits"
643 export *
644 }
645 module list {
646 header "list"
647 export initializer_list
648 export *
649 }
650 module locale {
651 header "locale"
652 export *
653 }
654 module map {
655 header "map"
656 export initializer_list
657 export *
658 }
659 module memory {
660 header "memory"
661 export *
662
663 module __memory {
664 module addressof { private header "__memory/addressof.h" }
665 module allocation_guard { private header "__memory/allocation_guard.h" }
666 module allocator { private header "__memory/allocator.h" }
667 module allocator_arg_t { private header "__memory/allocator_arg_t.h" }
668 module allocator_traits { private header "__memory/allocator_traits.h" }
669 module auto_ptr { private header "__memory/auto_ptr.h" }
670 module compressed_pair { private header "__memory/compressed_pair.h" }
671 module concepts { private header "__memory/concepts.h" }
672 module construct_at { private header "__memory/construct_at.h" }
673 module pointer_traits { private header "__memory/pointer_traits.h" }
674 module ranges_construct_at { private header "__memory/ranges_construct_at.h" }
675 module ranges_uninitialized_algorithms { private header "__memory/ranges_uninitialized_algorithms.h" }
676 module raw_storage_iterator { private header "__memory/raw_storage_iterator.h" }
677 module shared_ptr { private header "__memory/shared_ptr.h" }
678 module temporary_buffer { private header "__memory/temporary_buffer.h" }
679 module uninitialized_algorithms { private header "__memory/uninitialized_algorithms.h" }
680 module unique_ptr { private header "__memory/unique_ptr.h" }
681 module uses_allocator { private header "__memory/uses_allocator.h" }
682 module voidify { private header "__memory/voidify.h" }
683 }
684 }
685 module mutex {
686 header "mutex"
687 export *
688 }
689 module new {
690 header "new"
691 export *
692 }
693 module numbers {
694 header "numbers"
695 export *
696 }
697 module numeric {
698 header "numeric"
699 export *
700
701 module __numeric {
702 module accumulate { private header "__numeric/accumulate.h" }
703 module adjacent_difference { private header "__numeric/adjacent_difference.h" }
704 module exclusive_scan { private header "__numeric/exclusive_scan.h" }
705 module gcd_lcm { private header "__numeric/gcd_lcm.h" }
706 module inclusive_scan { private header "__numeric/inclusive_scan.h" }
707 module inner_product { private header "__numeric/inner_product.h" }
708 module iota { private header "__numeric/iota.h" }
709 module midpoint { private header "__numeric/midpoint.h" }
710 module partial_sum { private header "__numeric/partial_sum.h" }
711 module reduce { private header "__numeric/reduce.h" }
712 module transform_exclusive_scan { private header "__numeric/transform_exclusive_scan.h" }
713 module transform_inclusive_scan { private header "__numeric/transform_inclusive_scan.h" }
714 module transform_reduce { private header "__numeric/transform_reduce.h" }
715 }
716 }
717 module optional {
718 header "optional"
719 export *
720 }
721 module ostream {
722 header "ostream"
723 // FIXME: should re-export ios, streambuf?
724 export *
725 }
726 module queue {
727 header "queue"
728 export initializer_list
729 export *
730 }
731 module random {
732 header "random"
733 export initializer_list
734 export *
735
736 module __random {
737 module bernoulli_distribution { private header "__random/bernoulli_distribution.h" }
738 module binomial_distribution { private header "__random/binomial_distribution.h" }
739 module cauchy_distribution { private header "__random/cauchy_distribution.h" }
740 module chi_squared_distribution { private header "__random/chi_squared_distribution.h" }
741 module clamp_to_integral { private header "__random/clamp_to_integral.h" }
742 module default_random_engine { private header "__random/default_random_engine.h" }
743 module discard_block_engine { private header "__random/discard_block_engine.h" }
744 module discrete_distribution { private header "__random/discrete_distribution.h" }
745 module exponential_distribution { private header "__random/exponential_distribution.h" }
746 module extreme_value_distribution { private header "__random/extreme_value_distribution.h" }
747 module fisher_f_distribution { private header "__random/fisher_f_distribution.h" }
748 module gamma_distribution { private header "__random/gamma_distribution.h" }
749 module generate_canonical { private header "__random/generate_canonical.h" }
750 module geometric_distribution { private header "__random/geometric_distribution.h" }
751 module independent_bits_engine { private header "__random/independent_bits_engine.h" }
752 module is_seed_sequence { private header "__random/is_seed_sequence.h" }
753 module knuth_b { private header "__random/knuth_b.h" }
754 module linear_congruential_engine { private header "__random/linear_congruential_engine.h" }
755 module log2 { private header "__random/log2.h" }
756 module lognormal_distribution { private header "__random/lognormal_distribution.h" }
757 module mersenne_twister_engine { private header "__random/mersenne_twister_engine.h" }
758 module negative_binomial_distribution { private header "__random/negative_binomial_distribution.h" }
759 module normal_distribution { private header "__random/normal_distribution.h" }
760 module piecewise_constant_distribution { private header "__random/piecewise_constant_distribution.h" }
761 module piecewise_linear_distribution { private header "__random/piecewise_linear_distribution.h" }
762 module poisson_distribution { private header "__random/poisson_distribution.h" }
763 module random_device { private header "__random/random_device.h" }
764 module ranlux { private header "__random/ranlux.h" }
765 module seed_seq { private header "__random/seed_seq.h" }
766 module shuffle_order_engine { private header "__random/shuffle_order_engine.h" }
767 module student_t_distribution { private header "__random/student_t_distribution.h" }
768 module subtract_with_carry_engine { private header "__random/subtract_with_carry_engine.h" }
769 module uniform_int_distribution { private header "__random/uniform_int_distribution.h" }
770 module uniform_random_bit_generator { private header "__random/uniform_random_bit_generator.h" }
771 module uniform_real_distribution { private header "__random/uniform_real_distribution.h" }
772 module weibull_distribution { private header "__random/weibull_distribution.h" }
773 }
774 }
775 module ranges {
776 header "ranges"
777 export compare
778 export initializer_list
779 export iterator
780 export *
781
782 module __ranges {
783 module access { private header "__ranges/access.h" }
784 module all {
785 private header "__ranges/all.h"
786 export functional.__functional.compose
787 export functional.__functional.perfect_forward
788 }
789 module common_view { private header "__ranges/common_view.h" }
790 module concepts { private header "__ranges/concepts.h" }
791 module copyable_box { private header "__ranges/copyable_box.h" }
792 module counted {
793 private header "__ranges/counted.h"
794 export span
795 }
796 module dangling { private header "__ranges/dangling.h" }
797 module data { private header "__ranges/data.h" }
798 module drop_view { private header "__ranges/drop_view.h" }
799 module empty { private header "__ranges/empty.h" }
800 module empty_view { private header "__ranges/empty_view.h" }
801 module enable_borrowed_range { private header "__ranges/enable_borrowed_range.h" }
802 module enable_view { private header "__ranges/enable_view.h" }
803 module iota_view { private header "__ranges/iota_view.h" }
804 module join_view { private header "__ranges/join_view.h" }
805 module non_propagating_cache { private header "__ranges/non_propagating_cache.h" }
806 module owning_view { private header "__ranges/owning_view.h" }
807 module range_adaptor { private header "__ranges/range_adaptor.h" }
808 module ref_view { private header "__ranges/ref_view.h" }
809 module reverse_view { private header "__ranges/reverse_view.h" }
810 module single_view { private header "__ranges/single_view.h" }
811 module size { private header "__ranges/size.h" }
812 module subrange { private header "__ranges/subrange.h" }
813 module take_view { private header "__ranges/take_view.h" }
814 module transform_view {
815 private header "__ranges/transform_view.h"
816 export functional.__functional.bind_back
817 export functional.__functional.perfect_forward
818 }
819 module view_interface { private header "__ranges/view_interface.h" }
820 module views { private header "__ranges/views.h" }
821 }
822 }
823 module ratio {
824 header "ratio"
825 export *
826 }
827 module regex {
828 header "regex"
829 export initializer_list
830 export *
831 }
832 module scoped_allocator {
833 header "scoped_allocator"
834 export *
835 }
836 module semaphore {
837 requires cplusplus14
838 header "semaphore"
839 export *
840 }
841 module set {
842 header "set"
843 export initializer_list
844 export *
845 }
846 module shared_mutex {
847 header "shared_mutex"
848 export version
849 }
850 module span {
851 header "span"
852 export ranges.__ranges.enable_borrowed_range
853 export version
854 }
855 module sstream {
856 header "sstream"
857 // FIXME: should re-export istream, ostream, ios, streambuf, string?
858 export *
859 }
860 module stack {
861 header "stack"
862 export initializer_list
863 export *
864 }
865 module stdexcept {
866 header "stdexcept"
867 export *
868 }
869 module streambuf {
870 header "streambuf"
871 export *
872 }
873 module string {
874 header "string"
875 export initializer_list
876 export string_view
877 export __string
878 export *
879 }
880 module string_view {
881 header "string_view"
882 export initializer_list
883 export __string
884 export *
885 }
886 module strstream {
887 header "strstream"
888 export *
889 }
890 module system_error {
891 header "system_error"
892 export *
893 }
894 module thread {
895 header "thread"
896 export *
897
898 module __thread {
899 module poll_with_backoff { private header "__thread/poll_with_backoff.h" }
900 module timed_backoff_policy { private header "__thread/timed_backoff_policy.h" }
901 }
902 }
903 module tuple {
904 header "tuple"
905 export *
906 }
907 module type_traits {
908 header "type_traits"
909 export functional.__functional.unwrap_ref
910 export *
911 }
912 module typeindex {
913 header "typeindex"
914 export *
915 }
916 module typeinfo {
917 header "typeinfo"
918 export *
919 }
920 module unordered_map {
921 header "unordered_map"
922 export initializer_list
923 export *
924 }
925 module unordered_set {
926 header "unordered_set"
927 export initializer_list
928 export *
929 }
930 module utility {
931 header "utility"
932 export initializer_list
933 export *
934
935 module __utility {
936 module as_const { private header "__utility/as_const.h" }
937 module auto_cast { private header "__utility/auto_cast.h" }
938 module cmp { private header "__utility/cmp.h" }
939 module declval { private header "__utility/declval.h" }
940 module exchange { private header "__utility/exchange.h" }
941 module forward { private header "__utility/forward.h" }
942 module in_place { private header "__utility/in_place.h" }
943 module integer_sequence { private header "__utility/integer_sequence.h" }
944 module move { private header "__utility/move.h" }
945 module pair { private header "__utility/pair.h" }
946 module piecewise_construct { private header "__utility/piecewise_construct.h" }
947 module priority_tag { private header "__utility/priority_tag.h" }
948 module rel_ops { private header "__utility/rel_ops.h" }
949 module swap { private header "__utility/swap.h" }
950 module to_underlying { private header "__utility/to_underlying.h" }
951 module transaction { private header "__utility/transaction.h" }
952 }
953 }
954 module valarray {
955 header "valarray"
956 export initializer_list
957 export *
958 }
959 module variant {
960 header "variant"
961 export *
962
963 module __variant {
964 module monostate { private header "__variant/monostate.h" }
965 }
966 }
967 module vector {
968 header "vector"
969 export initializer_list
970 export *
971 }
972 module version {
973 header "version"
974 export *
975 }
976
977 // __config not modularised due to a bug in Clang
978 // FIXME: These should be private.
979 module __availability { private header "__availability" export * }
980 module __bit_reference { private header "__bit_reference" export * }
981 module __bits { private header "__bits" export * }
982 module __debug { header "__debug" export * }
983 module __errc { private header "__errc" export * }
984 module __hash_table { header "__hash_table" export * }
985 module __locale { private header "__locale" export * }
986 module __mbstate_t { private header "__mbstate_t.h" export * }
987 module __mutex_base { private header "__mutex_base" export * }
988 module __node_handle { private header "__node_handle" export * }
989 module __nullptr { header "__nullptr" export * }
990 module __split_buffer { private header "__split_buffer" export * }
991 module __std_stream { private header "__std_stream" export * }
992 module __string { private header "__string" export * }
993 module __threading_support { header "__threading_support" export * }
994 module __tree { header "__tree" export * }
995 module __tuple { private header "__tuple" export * }
996 module __undef_macros { header "__undef_macros" export * }
997
998 module experimental {
999 requires cplusplus11
1000
1001 module algorithm {
1002 header "experimental/algorithm"
1003 export *
1004 }
1005 module coroutine {
1006 requires coroutines
1007 header "experimental/coroutine"
1008 export *
1009 }
1010 module deque {
1011 header "experimental/deque"
1012 export *
1013 }
1014 module filesystem {
1015 header "experimental/filesystem"
1016 export *
1017 }
1018 module forward_list {
1019 header "experimental/forward_list"
1020 export *
1021 }
1022 module functional {
1023 header "experimental/functional"
1024 export *
1025 }
1026 module iterator {
1027 header "experimental/iterator"
1028 export *
1029 }
1030 module list {
1031 header "experimental/list"
1032 export *
1033 }
1034 module map {
1035 header "experimental/map"
1036 export *
1037 }
1038 module memory_resource {
1039 header "experimental/memory_resource"
1040 export *
1041 }
1042 module propagate_const {
1043 header "experimental/propagate_const"
1044 export *
1045 }
1046 module regex {
1047 header "experimental/regex"
1048 export *
1049 }
1050 module simd {
1051 header "experimental/simd"
1052 export *
1053 }
1054 module set {
1055 header "experimental/set"
1056 export *
1057 }
1058 module span {
1059 header "span"
1060 export *
1061 }
1062 module string {
1063 header "experimental/string"
1064 export *
1065 }
1066 module type_traits {
1067 header "experimental/type_traits"
1068 export *
1069 }
1070 module unordered_map {
1071 header "experimental/unordered_map"
1072 export *
1073 }
1074 module unordered_set {
1075 header "experimental/unordered_set"
1076 export *
1077 }
1078 module utility {
1079 header "experimental/utility"
1080 export *
1081 }
1082 module vector {
1083 header "experimental/vector"
1084 export *
1085 }
1086 // FIXME these should be private
1087 module __memory {
1088 header "experimental/__memory"
1089 export *
1090 }
1091 } // end experimental
1092}
lib/libcxx/include/mutex+6-2
......@@ -186,20 +186,24 @@ template<class Callable, class ...Args>
186186
187187*/
188188
189#include <__assert> // all public C++ headers provide the assertion handler
189190#include <__config>
190191#include <__mutex_base>
191192#include <__threading_support>
192193#include <__utility/forward.h>
193194#include <cstdint>
194#include <functional>
195195#include <memory>
196196#ifndef _LIBCPP_CXX03_LANG
197197# include <tuple>
198198#endif
199199#include <version>
200200
201#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
202# include <functional>
203#endif
204
201205#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
202#pragma GCC system_header
206# pragma GCC system_header
203207#endif
204208
205209_LIBCPP_PUSH_MACROS
lib/libcxx/include/new+13-1
......@@ -86,6 +86,7 @@ void operator delete[](void* ptr, void*) noexcept;
8686
8787*/
8888
89#include <__assert> // all public C++ headers provide the assertion handler
8990#include <__availability>
9091#include <__config>
9192#include <cstddef>
......@@ -99,7 +100,7 @@ void operator delete[](void* ptr, void*) noexcept;
99100#endif
100101
101102#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
102#pragma GCC system_header
103# pragma GCC system_header
103104#endif
104105
105106#if !defined(__cpp_sized_deallocation) || __cpp_sized_deallocation < 201309L
......@@ -359,6 +360,17 @@ constexpr _Tp* launder(_Tp* __p) noexcept
359360}
360361#endif
361362
363#if _LIBCPP_STD_VER > 14
364
365#if defined(__GCC_DESTRUCTIVE_SIZE) && defined(__GCC_CONSTRUCTIVE_SIZE)
366
367inline constexpr size_t hardware_destructive_interference_size = __GCC_DESTRUCTIVE_SIZE;
368inline constexpr size_t hardware_constructive_interference_size = __GCC_CONSTRUCTIVE_SIZE;
369
370#endif // defined(__GCC_DESTRUCTIVE_SIZE) && defined(__GCC_CONSTRUCTIVE_SIZE)
371
372#endif // _LIBCPP_STD_VER > 14
373
362374_LIBCPP_END_NAMESPACE_STD
363375
364376#endif // _LIBCPP_NEW
lib/libcxx/include/numbers+4-3
......@@ -58,15 +58,16 @@ namespace std::numbers {
5858}
5959*/
6060
61#include <__assert> // all public C++ headers provide the assertion handler
6162#include <__config>
6263#include <concepts>
6364#include <type_traits>
6465#include <version>
6566
66#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
67#if _LIBCPP_STD_VER > 17
6768
6869#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
69#pragma GCC system_header
70# pragma GCC system_header
7071#endif
7172
7273_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -128,6 +129,6 @@ inline constexpr double phi = phi_v<double>;
128129
129130_LIBCPP_END_NAMESPACE_STD
130131
131#endif //!defined(_LIBCPP_HAS_NO_CONCEPTS)
132#endif // _LIBCPP_STD_VER > 17
132133
133134#endif // _LIBCPP_NUMBERS
lib/libcxx/include/numeric+7-3
......@@ -144,10 +144,9 @@ template<class T>
144144
145145*/
146146
147#include <__assert> // all public C++ headers provide the assertion handler
147148#include <__config>
148149#include <cmath> // for isnormal
149#include <functional>
150#include <iterator>
151150#include <version>
152151
153152#include <__numeric/accumulate.h>
......@@ -164,8 +163,13 @@ template<class T>
164163#include <__numeric/transform_inclusive_scan.h>
165164#include <__numeric/transform_reduce.h>
166165
166#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
167# include <functional>
168# include <iterator>
169#endif
170
167171#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
168#pragma GCC system_header
172# pragma GCC system_header
169173#endif
170174
171175#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17
lib/libcxx/include/optional+42-19
......@@ -93,11 +93,11 @@ namespace std {
9393 template <class U, class... Args>
9494 constexpr explicit optional(in_place_t, initializer_list<U>, Args &&...);
9595 template <class U = T>
96 constexpr EXPLICIT optional(U &&);
96 constexpr explicit(see-below) optional(U &&);
9797 template <class U>
98 EXPLICIT optional(const optional<U> &); // constexpr in C++20
98 explicit(see-below) optional(const optional<U> &); // constexpr in C++20
9999 template <class U>
100 EXPLICIT optional(optional<U> &&); // constexpr in C++20
100 explicit(see-below) optional(optional<U> &&); // constexpr in C++20
101101
102102 // 23.6.3.2, destructor
103103 ~optional(); // constexpr in C++20
......@@ -158,22 +158,45 @@ template<class T>
158158
159159*/
160160
161#include <__assert> // all public C++ headers provide the assertion handler
161162#include <__availability>
162163#include <__concepts/invocable.h>
163164#include <__config>
164#include <__debug>
165#include <__functional_base>
166#include <compare>
167#include <functional>
165#include <__functional/hash.h>
166#include <__functional/invoke.h>
167#include <__functional/unary_function.h>
168#include <__memory/construct_at.h>
169#include <__tuple>
170#include <__utility/forward.h>
171#include <__utility/in_place.h>
172#include <__utility/move.h>
173#include <__utility/swap.h>
168174#include <initializer_list>
169175#include <new>
170176#include <stdexcept>
171177#include <type_traits>
172#include <utility>
173178#include <version>
174179
180#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
181# include <atomic>
182# include <chrono>
183# include <climits>
184# include <concepts>
185# include <ctime>
186# include <iterator>
187# include <memory>
188# include <ratio>
189# include <tuple>
190# include <typeinfo>
191# include <utility>
192# include <variant>
193#endif
194
195// standard-mandated includes
196#include <compare>
197
175198#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
176#pragma GCC system_header
199# pragma GCC system_header
177200#endif
178201
179202namespace std // purposefully not using versioning namespace
......@@ -382,9 +405,9 @@ struct __optional_storage_base : __optional_destruct_base<_Tp>
382405 }
383406};
384407
385// optional<T&> is currently required ill-formed, however it may to be in the
386// future. For this reason it has already been implemented to ensure we can
387// make the change in an ABI compatible manner.
408// optional<T&> is currently required to be ill-formed. However, it may
409// be allowed in the future. For this reason, it has already been implemented
410// to ensure we can make the change in an ABI-compatible manner.
388411template <class _Tp>
389412struct __optional_storage_base<_Tp, true>
390413{
......@@ -1039,7 +1062,7 @@ public:
10391062
10401063#if _LIBCPP_STD_VER > 20
10411064 template<class _Func>
1042 _LIBCPP_HIDE_FROM_ABI
1065 _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS
10431066 constexpr auto and_then(_Func&& __f) & {
10441067 using _Up = invoke_result_t<_Func, value_type&>;
10451068 static_assert(__is_std_optional<remove_cvref_t<_Up>>::value,
......@@ -1050,7 +1073,7 @@ public:
10501073 }
10511074
10521075 template<class _Func>
1053 _LIBCPP_HIDE_FROM_ABI
1076 _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS
10541077 constexpr auto and_then(_Func&& __f) const& {
10551078 using _Up = invoke_result_t<_Func, const value_type&>;
10561079 static_assert(__is_std_optional<remove_cvref_t<_Up>>::value,
......@@ -1061,7 +1084,7 @@ public:
10611084 }
10621085
10631086 template<class _Func>
1064 _LIBCPP_HIDE_FROM_ABI
1087 _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS
10651088 constexpr auto and_then(_Func&& __f) && {
10661089 using _Up = invoke_result_t<_Func, value_type&&>;
10671090 static_assert(__is_std_optional<remove_cvref_t<_Up>>::value,
......@@ -1083,7 +1106,7 @@ public:
10831106 }
10841107
10851108 template<class _Func>
1086 _LIBCPP_HIDE_FROM_ABI
1109 _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS
10871110 constexpr auto transform(_Func&& __f) & {
10881111 using _Up = remove_cv_t<invoke_result_t<_Func, value_type&>>;
10891112 static_assert(!is_array_v<_Up>, "Result of f(value()) should not be an Array");
......@@ -1098,7 +1121,7 @@ public:
10981121 }
10991122
11001123 template<class _Func>
1101 _LIBCPP_HIDE_FROM_ABI
1124 _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS
11021125 constexpr auto transform(_Func&& __f) const& {
11031126 using _Up = remove_cv_t<invoke_result_t<_Func, const value_type&>>;
11041127 static_assert(!is_array_v<_Up>, "Result of f(value()) should not be an Array");
......@@ -1113,7 +1136,7 @@ public:
11131136 }
11141137
11151138 template<class _Func>
1116 _LIBCPP_HIDE_FROM_ABI
1139 _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS
11171140 constexpr auto transform(_Func&& __f) && {
11181141 using _Up = remove_cv_t<invoke_result_t<_Func, value_type&&>>;
11191142 static_assert(!is_array_v<_Up>, "Result of f(std::move(value())) should not be an Array");
......@@ -1128,7 +1151,7 @@ public:
11281151 }
11291152
11301153 template<class _Func>
1131 _LIBCPP_HIDE_FROM_ABI
1154 _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS
11321155 constexpr auto transform(_Func&& __f) const&& {
11331156 using _Up = remove_cvref_t<invoke_result_t<_Func, const value_type&&>>;
11341157 static_assert(!is_array_v<_Up>, "Result of f(std::move(value())) should not be an Array");
lib/libcxx/include/ostream+92-4
......@@ -130,20 +130,53 @@ template <class charT, class traits>
130130template <class Stream, class T>
131131 Stream&& operator<<(Stream&& os, const T& x);
132132
133template<class traits>
134basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, wchar_t) = delete; // since C++20
135template<class traits>
136basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, char8_t) = delete; // since C++20
137template<class traits>
138basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, char16_t) = delete; // since C++20
139template<class traits>
140basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, char32_t) = delete; // since C++20
141template<class traits>
142basic_ostream<wchar_t, traits>& operator<<(basic_ostream<wchar_t, traits>&, char8_t) = delete; // since C++20
143template<class traits>
144basic_ostream<wchar_t, traits>& operator<<(basic_ostream<wchar_t, traits>&, char16_t) = delete; // since C++20
145template<class traits>
146basic_ostream<wchar_t, traits>& operator<<(basic_ostream<wchar_t, traits>&, char32_t) = delete; // since C++20
147template<class traits>
148basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, const wchar_t*) = delete; // since C++20
149template<class traits>
150basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, const char8_t*) = delete; // since C++20
151template<class traits>
152basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, const char16_t*) = delete; // since C++20
153template<class traits>
154basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, const char32_t*) = delete; // since C++20
155template<class traits>
156basic_ostream<wchar_t, traits>& operator<<(basic_ostream<wchar_t, traits>&, const char8_t*) = delete; // since C++20
157template<class traits>
158basic_ostream<wchar_t, traits>& operator<<(basic_ostream<wchar_t, traits>&, const char16_t*) = delete; // since C++20
159template<class traits>
160basic_ostream<wchar_t, traits>& operator<<(basic_ostream<wchar_t, traits>&, const char32_t*) = delete; // since C++20
161
133162} // std
134163
135164*/
136165
166#include <__assert> // all public C++ headers provide the assertion handler
137167#include <__config>
138168#include <bitset>
139169#include <ios>
140#include <iterator>
141170#include <locale>
142171#include <streambuf>
143172#include <version>
144173
174#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
175# include <iterator>
176#endif
177
145178#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
146#pragma GCC system_header
179# pragma GCC system_header
147180#endif
148181
149182_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -221,9 +254,13 @@ public:
221254
222255 basic_ostream& operator<<(basic_streambuf<char_type, traits_type>* __sb);
223256
257#if _LIBCPP_STD_VER > 14
258// LWG 2221 - nullptr. This is not backported to older standards modes.
259// See https://reviews.llvm.org/D127033 for more info on the rationale.
224260 _LIBCPP_INLINE_VISIBILITY
225261 basic_ostream& operator<<(nullptr_t)
226262 { return *this << "nullptr"; }
263#endif
227264
228265 // 27.7.2.7 Unformatted output:
229266 basic_ostream& put(char_type __c);
......@@ -1094,9 +1131,60 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x)
10941131 use_facet<ctype<_CharT> >(__os.getloc()).widen('1'));
10951132}
10961133
1097_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<char>)
1134#if _LIBCPP_STD_VER > 17
1135
1136#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1137template <class _Traits>
1138basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, wchar_t) = delete;
1139
1140template <class _Traits>
1141basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, const wchar_t*) = delete;
1142
1143template <class _Traits>
1144basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, char16_t) = delete;
1145
1146template <class _Traits>
1147basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, char32_t) = delete;
1148
1149template <class _Traits>
1150basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, const char16_t*) = delete;
1151
1152template <class _Traits>
1153basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, const char32_t*) = delete;
1154
1155#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
1156
1157#ifndef _LIBCPP_HAS_NO_CHAR8_T
1158template <class _Traits>
1159basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, char8_t) = delete;
1160
1161template <class _Traits>
1162basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, char8_t) = delete;
1163
1164template <class _Traits>
1165basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, const char8_t*) = delete;
1166
1167template <class _Traits>
1168basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, const char8_t*) = delete;
1169#endif
1170
1171template <class _Traits>
1172basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, char16_t) = delete;
1173
1174template <class _Traits>
1175basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, char32_t) = delete;
1176
1177template <class _Traits>
1178basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, const char16_t*) = delete;
1179
1180template <class _Traits>
1181basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, const char32_t*) = delete;
1182
1183#endif // _LIBCPP_STD_VER > 17
1184
1185extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<char>;
10981186#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1099_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<wchar_t>)
1187extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<wchar_t>;
11001188#endif
11011189
11021190_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/queue+14-4
......@@ -217,20 +217,30 @@ template <class T, class Container, class Compare>
217217
218218*/
219219
220#include <__algorithm/make_heap.h>
221#include <__algorithm/pop_heap.h>
222#include <__algorithm/push_heap.h>
223#include <__assert> // all public C++ headers provide the assertion handler
220224#include <__config>
225#include <__functional/operations.h>
221226#include <__iterator/iterator_traits.h>
222227#include <__memory/uses_allocator.h>
223228#include <__utility/forward.h>
224#include <algorithm>
225#include <compare>
226229#include <deque>
227#include <functional>
228230#include <type_traits>
229231#include <vector>
230232#include <version>
231233
234#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
235# include <functional>
236#endif
237
238// standard-mandated includes
239#include <compare>
240#include <initializer_list>
241
232242#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
233#pragma GCC system_header
243# pragma GCC system_header
234244#endif
235245
236246_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/random+10-3
......@@ -1677,6 +1677,7 @@ class piecewise_linear_distribution
16771677} // std
16781678*/
16791679
1680#include <__assert> // all public C++ headers provide the assertion handler
16801681#include <__config>
16811682#include <__random/bernoulli_distribution.h>
16821683#include <__random/binomial_distribution.h>
......@@ -1694,6 +1695,7 @@ class piecewise_linear_distribution
16941695#include <__random/geometric_distribution.h>
16951696#include <__random/independent_bits_engine.h>
16961697#include <__random/is_seed_sequence.h>
1698#include <__random/is_valid.h>
16971699#include <__random/knuth_b.h>
16981700#include <__random/linear_congruential_engine.h>
16991701#include <__random/log2.h>
......@@ -1714,10 +1716,15 @@ class piecewise_linear_distribution
17141716#include <__random/uniform_random_bit_generator.h>
17151717#include <__random/uniform_real_distribution.h>
17161718#include <__random/weibull_distribution.h>
1717#include <initializer_list>
17181719#include <version>
17191720
1720#include <algorithm> // for backward compatibility; TODO remove it
1721#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
1722# include <algorithm>
1723#endif
1724
1725// standard-mandated includes
1726#include <initializer_list>
1727
17211728#include <cmath> // for backward compatibility; TODO remove it
17221729#include <cstddef> // for backward compatibility; TODO remove it
17231730#include <cstdint> // for backward compatibility; TODO remove it
......@@ -1729,7 +1736,7 @@ class piecewise_linear_distribution
17291736#include <vector> // for backward compatibility; TODO remove it
17301737
17311738#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1732#pragma GCC system_header
1739# pragma GCC system_header
17331740#endif
17341741
17351742#endif // _LIBCPP_RANDOM
lib/libcxx/include/ranges+80-1
......@@ -120,6 +120,14 @@ namespace std::ranges {
120120 requires is_object_v<T>
121121 class empty_view;
122122
123 template<class T>
124 inline constexpr bool enable_borrowed_range<empty_view<T>> = true;
125
126 namespace views {
127 template<class T>
128 inline constexpr empty_view<T> empty{};
129 }
130
123131 // [range.all], all view
124132 namespace views {
125133 inline constexpr unspecified all = unspecified;
......@@ -142,6 +150,15 @@ namespace std::ranges {
142150 template<class T>
143151 inline constexpr bool enable_borrowed_range<owning_view<T>> = enable_borrowed_range<T>;
144152
153 // [range.filter], filter view
154 template<input_range V, indirect_unary_predicate<iterator_t<V>> Pred>
155 requires view<V> && is_object_v<Pred>
156 class filter_view;
157
158 namespace views {
159 inline constexpr unspecified filter = unspecified;
160 }
161
145162 // [range.drop], drop view
146163 template<view V>
147164 class drop_view;
......@@ -196,10 +213,66 @@ namespace std::ranges {
196213 template<input_range V>
197214 requires view<V> && input_range<range_reference_t<V>>
198215 class join_view;
216
217 // [range.lazy.split], lazy split view
218 template<class R>
219 concept tiny-range = see below; // exposition only
220
221 template<input_range V, forward_range Pattern>
222 requires view<V> && view<Pattern> &&
223 indirectly_comparable<iterator_t<V>, iterator_t<Pattern>, ranges::equal_to> &&
224 (forward_range<V> || tiny-range<Pattern>)
225 class lazy_split_view;
226
227 namespace views {
228 inline constexpr unspecified lazy_split = unspecified;
229 }
230
231 // [range.zip], zip view
232 template<input_range... Views>
233 requires (view<Views> && ...) && (sizeof...(Views) > 0)
234 class zip_view; // C++2b
235
236 template<class... Views>
237 inline constexpr bool enable_borrowed_range<zip_view<Views...>> = // C++2b
238 (enable_borrowed_range<Views> && ...);
239
240 namespace views { inline constexpr unspecified zip = unspecified; } // C++2b
199241}
200242
243namespace std {
244 namespace views = ranges::views;
245
246 template<class T> struct tuple_size;
247 template<size_t I, class T> struct tuple_element;
248
249 template<class I, class S, ranges::subrange_kind K>
250 struct tuple_size<ranges::subrange<I, S, K>>
251 : integral_constant<size_t, 2> {};
252
253 template<class I, class S, ranges::subrange_kind K>
254 struct tuple_element<0, ranges::subrange<I, S, K>> {
255 using type = I;
256 };
257
258 template<class I, class S, ranges::subrange_kind K>
259 struct tuple_element<1, ranges::subrange<I, S, K>> {
260 using type = S;
261 };
262
263 template<class I, class S, ranges::subrange_kind K>
264 struct tuple_element<0, const ranges::subrange<I, S, K>> {
265 using type = I;
266 };
267
268 template<class I, class S, ranges::subrange_kind K>
269 struct tuple_element<1, const ranges::subrange<I, S, K>> {
270 using type = S;
271 };
272}
201273*/
202274
275#include <__assert> // all public C++ headers provide the assertion handler
203276#include <__config>
204277#include <__ranges/access.h>
205278#include <__ranges/all.h>
......@@ -213,9 +286,13 @@ namespace std::ranges {
213286#include <__ranges/empty_view.h>
214287#include <__ranges/enable_borrowed_range.h>
215288#include <__ranges/enable_view.h>
289#include <__ranges/filter_view.h>
216290#include <__ranges/iota_view.h>
217291#include <__ranges/join_view.h>
292#include <__ranges/lazy_split_view.h>
293#include <__ranges/rbegin.h>
218294#include <__ranges/ref_view.h>
295#include <__ranges/rend.h>
219296#include <__ranges/reverse_view.h>
220297#include <__ranges/single_view.h>
221298#include <__ranges/size.h>
......@@ -224,6 +301,8 @@ namespace std::ranges {
224301#include <__ranges/transform_view.h>
225302#include <__ranges/view_interface.h>
226303#include <__ranges/views.h>
304#include <__ranges/zip_view.h>
305#include <__tuple> // TODO: <ranges> has to export std::tuple_size. Replace this, once <tuple> is granularized.
227306#include <compare> // Required by the standard.
228307#include <initializer_list> // Required by the standard.
229308#include <iterator> // Required by the standard.
......@@ -231,7 +310,7 @@ namespace std::ranges {
231310#include <version>
232311
233312#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
234#pragma GCC system_header
313# pragma GCC system_header
235314#endif
236315
237316#endif // _LIBCPP_RANGES
lib/libcxx/include/ratio+8-7
......@@ -77,6 +77,7 @@ typedef ratio<1000000000000000000000000, 1> yotta; // not supported
7777}
7878*/
7979
80#include <__assert> // all public C++ headers provide the assertion handler
8081#include <__config>
8182#include <climits>
8283#include <cstdint>
......@@ -84,7 +85,7 @@ typedef ratio<1000000000000000000000000, 1> yotta; // not supported
8485#include <version>
8586
8687#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
87#pragma GCC system_header
88# pragma GCC system_header
8889#endif
8990
9091_LIBCPP_PUSH_MACROS
......@@ -416,11 +417,11 @@ struct _LIBCPP_TEMPLATE_VIS ratio_subtract
416417
417418template <class _R1, class _R2>
418419struct _LIBCPP_TEMPLATE_VIS ratio_equal
419 : public _LIBCPP_BOOL_CONSTANT((_R1::num == _R2::num && _R1::den == _R2::den)) {};
420 : _BoolConstant<(_R1::num == _R2::num && _R1::den == _R2::den)> {};
420421
421422template <class _R1, class _R2>
422423struct _LIBCPP_TEMPLATE_VIS ratio_not_equal
423 : public _LIBCPP_BOOL_CONSTANT((!ratio_equal<_R1, _R2>::value)) {};
424 : _BoolConstant<!ratio_equal<_R1, _R2>::value> {};
424425
425426// ratio_less
426427
......@@ -479,19 +480,19 @@ struct __ratio_less<_R1, _R2, -1LL, -1LL>
479480
480481template <class _R1, class _R2>
481482struct _LIBCPP_TEMPLATE_VIS ratio_less
482 : public _LIBCPP_BOOL_CONSTANT((__ratio_less<_R1, _R2>::value)) {};
483 : _BoolConstant<__ratio_less<_R1, _R2>::value> {};
483484
484485template <class _R1, class _R2>
485486struct _LIBCPP_TEMPLATE_VIS ratio_less_equal
486 : public _LIBCPP_BOOL_CONSTANT((!ratio_less<_R2, _R1>::value)) {};
487 : _BoolConstant<!ratio_less<_R2, _R1>::value> {};
487488
488489template <class _R1, class _R2>
489490struct _LIBCPP_TEMPLATE_VIS ratio_greater
490 : public _LIBCPP_BOOL_CONSTANT((ratio_less<_R2, _R1>::value)) {};
491 : _BoolConstant<ratio_less<_R2, _R1>::value> {};
491492
492493template <class _R1, class _R2>
493494struct _LIBCPP_TEMPLATE_VIS ratio_greater_equal
494 : public _LIBCPP_BOOL_CONSTANT((!ratio_less<_R1, _R2>::value)) {};
495 : _BoolConstant<!ratio_less<_R1, _R2>::value> {};
495496
496497template <class _R1, class _R2>
497498struct __ratio_gcd
lib/libcxx/include/regex+40-26
......@@ -762,23 +762,42 @@ typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
762762} // std
763763*/
764764
765#include <__algorithm/find.h>
766#include <__algorithm/search.h>
767#include <__assert> // all public C++ headers provide the assertion handler
765768#include <__config>
766#include <__debug>
769#include <__iterator/back_insert_iterator.h>
767770#include <__iterator/wrap_iter.h>
768771#include <__locale>
769#include <compare>
772#include <__utility/move.h>
773#include <__utility/swap.h>
770774#include <deque>
771#include <initializer_list>
772#include <iterator>
773775#include <memory>
774776#include <stdexcept>
775777#include <string>
776#include <utility>
777778#include <vector>
778779#include <version>
779780
781#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
782# include <iterator>
783# include <utility>
784#endif
785
786// standard-mandated includes
787
788// [iterator.range]
789#include <__iterator/access.h>
790#include <__iterator/data.h>
791#include <__iterator/empty.h>
792#include <__iterator/reverse_access.h>
793#include <__iterator/size.h>
794
795// [re.syn]
796#include <compare>
797#include <initializer_list>
798
780799#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
781#pragma GCC system_header
800# pragma GCC system_header
782801#endif
783802
784803_LIBCPP_PUSH_MACROS
......@@ -1311,9 +1330,9 @@ regex_traits<_CharT>::isctype(char_type __c, char_class_type __m) const
13111330}
13121331
13131332inline _LIBCPP_INLINE_VISIBILITY
1314bool __is_07(unsigned char c)
1333bool __is_07(unsigned char __c)
13151334{
1316 return (c & 0xF8u) ==
1335 return (__c & 0xF8u) ==
13171336#if defined(__MVS__) && !defined(__NATIVE_ASCII_F)
13181337 0xF0;
13191338#else
......@@ -1322,9 +1341,9 @@ bool __is_07(unsigned char c)
13221341}
13231342
13241343inline _LIBCPP_INLINE_VISIBILITY
1325bool __is_89(unsigned char c)
1344bool __is_89(unsigned char __c)
13261345{
1327 return (c & 0xFEu) ==
1346 return (__c & 0xFEu) ==
13281347#if defined(__MVS__) && !defined(__NATIVE_ASCII_F)
13291348 0xF8;
13301349#else
......@@ -1333,12 +1352,12 @@ bool __is_89(unsigned char c)
13331352}
13341353
13351354inline _LIBCPP_INLINE_VISIBILITY
1336unsigned char __to_lower(unsigned char c)
1355unsigned char __to_lower(unsigned char __c)
13371356{
13381357#if defined(__MVS__) && !defined(__NATIVE_ASCII_F)
13391358 return c & 0xBF;
13401359#else
1341 return c | 0x20;
1360 return __c | 0x20;
13421361#endif
13431362}
13441363
......@@ -2038,9 +2057,9 @@ __word_boundary<_CharT, _Traits>::__exec(__state& __s) const
20382057
20392058template <class _CharT>
20402059_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
2041bool __is_eol(_CharT c)
2060bool __is_eol(_CharT __c)
20422061{
2043 return c == '\r' || c == '\n';
2062 return __c == '\r' || __c == '\n';
20442063}
20452064
20462065template <class _CharT>
......@@ -2093,14 +2112,14 @@ class __r_anchor_multiline
20932112{
20942113 typedef __owns_one_state<_CharT> base;
20952114
2096 bool __multiline;
2115 bool __multiline_;
20972116
20982117public:
20992118 typedef _VSTD::__state<_CharT> __state;
21002119
21012120 _LIBCPP_INLINE_VISIBILITY
21022121 __r_anchor_multiline(bool __multiline, __node<_CharT>* __s)
2103 : base(__s), __multiline(__multiline) {}
2122 : base(__s), __multiline_(__multiline) {}
21042123
21052124 virtual void __exec(__state&) const;
21062125};
......@@ -2115,7 +2134,7 @@ __r_anchor_multiline<_CharT>::__exec(__state& __s) const
21152134 __s.__do_ = __state::__accept_but_not_consume;
21162135 __s.__node_ = this->first();
21172136 }
2118 else if (__multiline && __is_eol(*__s.__current_))
2137 else if (__multiline_ && __is_eol(*__s.__current_))
21192138 {
21202139 __s.__do_ = __state::__accept_but_not_consume;
21212140 __s.__node_ = this->first();
......@@ -2729,12 +2748,7 @@ public:
27292748
27302749 template <class _InputIterator>
27312750 _LIBCPP_INLINE_VISIBILITY
2732 typename enable_if
2733 <
2734 __is_cpp17_input_iterator <_InputIterator>::value &&
2735 !__is_cpp17_forward_iterator<_InputIterator>::value,
2736 basic_regex&
2737 >::type
2751 typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value, basic_regex&>::type
27382752 assign(_InputIterator __first, _InputIterator __last,
27392753 flag_type __f = regex_constants::ECMAScript)
27402754 {
......@@ -2949,7 +2963,7 @@ private:
29492963 __parse_awk_escape(_ForwardIterator __first, _ForwardIterator __last,
29502964 basic_string<_CharT>* __str = nullptr);
29512965
2952 bool __test_back_ref(_CharT c);
2966 bool __test_back_ref(_CharT);
29532967
29542968 _LIBCPP_INLINE_VISIBILITY
29552969 void __push_l_anchor();
......@@ -4768,9 +4782,9 @@ basic_regex<_CharT, _Traits>::__parse_egrep(_ForwardIterator __first,
47684782
47694783template <class _CharT, class _Traits>
47704784bool
4771basic_regex<_CharT, _Traits>::__test_back_ref(_CharT c)
4785basic_regex<_CharT, _Traits>::__test_back_ref(_CharT __c)
47724786{
4773 unsigned __val = __traits_.value(c, 10);
4787 unsigned __val = __traits_.value(__c, 10);
47744788 if (__val >= 1 && __val <= 9)
47754789 {
47764790 if (__val > mark_count())
lib/libcxx/include/scoped_allocator+11-10
......@@ -109,13 +109,14 @@ template <class OuterA1, class OuterA2, class... InnerAllocs>
109109
110110*/
111111
112#include <__assert> // all public C++ headers provide the assertion handler
112113#include <__config>
113114#include <__utility/forward.h>
114115#include <memory>
115116#include <version>
116117
117118#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
118#pragma GCC system_header
119# pragma GCC system_header
119120#endif
120121
121122_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -218,10 +219,10 @@ protected:
218219 is_constructible<outer_allocator_type, _OuterA2>::value
219220 >::type>
220221 _LIBCPP_INLINE_VISIBILITY
221 __scoped_allocator_storage(_OuterA2&& __outerAlloc,
222 const _InnerAllocs& ...__innerAllocs) _NOEXCEPT
223 : outer_allocator_type(_VSTD::forward<_OuterA2>(__outerAlloc)),
224 __inner_(__innerAllocs...) {}
222 __scoped_allocator_storage(_OuterA2&& __outer_alloc,
223 const _InnerAllocs& ...__inner_allocs) _NOEXCEPT
224 : outer_allocator_type(_VSTD::forward<_OuterA2>(__outer_alloc)),
225 __inner_(__inner_allocs...) {}
225226
226227 template <class _OuterA2,
227228 class = typename enable_if<
......@@ -299,8 +300,8 @@ protected:
299300 is_constructible<outer_allocator_type, _OuterA2>::value
300301 >::type>
301302 _LIBCPP_INLINE_VISIBILITY
302 __scoped_allocator_storage(_OuterA2&& __outerAlloc) _NOEXCEPT
303 : outer_allocator_type(_VSTD::forward<_OuterA2>(__outerAlloc)) {}
303 __scoped_allocator_storage(_OuterA2&& __outer_alloc) _NOEXCEPT
304 : outer_allocator_type(_VSTD::forward<_OuterA2>(__outer_alloc)) {}
304305
305306 template <class _OuterA2,
306307 class = typename enable_if<
......@@ -443,9 +444,9 @@ public:
443444 is_constructible<outer_allocator_type, _OuterA2>::value
444445 >::type>
445446 _LIBCPP_INLINE_VISIBILITY
446 scoped_allocator_adaptor(_OuterA2&& __outerAlloc,
447 const _InnerAllocs& ...__innerAllocs) _NOEXCEPT
448 : base(_VSTD::forward<_OuterA2>(__outerAlloc), __innerAllocs...) {}
447 scoped_allocator_adaptor(_OuterA2&& __outer_alloc,
448 const _InnerAllocs& ...__inner_allocs) _NOEXCEPT
449 : base(_VSTD::forward<_OuterA2>(__outer_alloc), __inner_allocs...) {}
449450 // scoped_allocator_adaptor(const scoped_allocator_adaptor& __other) = default;
450451 template <class _OuterA2,
451452 class = typename enable_if<
lib/libcxx/include/semaphore+5-2
......@@ -45,19 +45,22 @@ using binary_semaphore = counting_semaphore<1>;
4545
4646*/
4747
48#include <__assert> // all public C++ headers provide the assertion handler
4849#include <__availability>
50#include <__chrono/time_point.h>
4951#include <__config>
5052#include <__thread/timed_backoff_policy.h>
5153#include <__threading_support>
5254#include <atomic>
55#include <limits>
5356#include <version>
5457
5558#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
56#pragma GCC system_header
59# pragma GCC system_header
5760#endif
5861
5962#ifdef _LIBCPP_HAS_NO_THREADS
60# error <semaphore> is not supported on this single threaded system
63# error "<semaphore> is not supported since libc++ has been configured without support for threads."
6164#endif
6265
6366_LIBCPP_PUSH_MACROS
lib/libcxx/include/set+28-9
......@@ -471,21 +471,40 @@ erase_if(multiset<Key, Compare, Allocator>& c, Predicate pred); // C++20
471471
472472*/
473473
474#include <__algorithm/equal.h>
475#include <__algorithm/lexicographical_compare.h>
476#include <__assert> // all public C++ headers provide the assertion handler
474477#include <__config>
475#include <__debug>
476478#include <__functional/is_transparent.h>
479#include <__functional/operations.h>
480#include <__iterator/erase_if_container.h>
477481#include <__iterator/iterator_traits.h>
482#include <__iterator/reverse_iterator.h>
478483#include <__node_handle>
479484#include <__tree>
480485#include <__utility/forward.h>
486#include <version>
487
488#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
489# include <functional>
490# include <iterator>
491#endif
492
493// standard-mandated includes
494
495// [iterator.range]
496#include <__iterator/access.h>
497#include <__iterator/data.h>
498#include <__iterator/empty.h>
499#include <__iterator/reverse_access.h>
500#include <__iterator/size.h>
501
502// [associative.set.syn]
481503#include <compare>
482#include <functional>
483504#include <initializer_list>
484#include <iterator> // __libcpp_erase_if_container
485#include <version>
486505
487506#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
488#pragma GCC system_header
507# pragma GCC system_header
489508#endif
490509
491510_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -501,9 +520,9 @@ public:
501520 // types:
502521 typedef _Key key_type;
503522 typedef key_type value_type;
504 typedef __identity_t<_Compare> key_compare;
523 typedef __type_identity_t<_Compare> key_compare;
505524 typedef key_compare value_compare;
506 typedef __identity_t<_Allocator> allocator_type;
525 typedef __type_identity_t<_Allocator> allocator_type;
507526 typedef value_type& reference;
508527 typedef const value_type& const_reference;
509528
......@@ -1034,9 +1053,9 @@ public:
10341053 // types:
10351054 typedef _Key key_type;
10361055 typedef key_type value_type;
1037 typedef __identity_t<_Compare> key_compare;
1056 typedef __type_identity_t<_Compare> key_compare;
10381057 typedef key_compare value_compare;
1039 typedef __identity_t<_Allocator> allocator_type;
1058 typedef __type_identity_t<_Allocator> allocator_type;
10401059 typedef value_type& reference;
10411060 typedef const value_type& const_reference;
10421061
lib/libcxx/include/setjmp.h+1-1
......@@ -28,7 +28,7 @@ void longjmp(jmp_buf env, int val);
2828#include <__config>
2929
3030#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
31#pragma GCC system_header
31# pragma GCC system_header
3232#endif
3333
3434#include_next <setjmp.h>
lib/libcxx/include/shared_mutex+6-7
......@@ -122,6 +122,7 @@ template <class Mutex>
122122
123123*/
124124
125#include <__assert> // all public C++ headers provide the assertion handler
125126#include <__availability>
126127#include <__config>
127128#include <version>
......@@ -135,12 +136,12 @@ _LIBCPP_PUSH_MACROS
135136#include <__mutex_base>
136137
137138#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
138#pragma GCC system_header
139# pragma GCC system_header
139140#endif
140141
141142#ifdef _LIBCPP_HAS_NO_THREADS
142#error <shared_mutex> is not supported on this single threaded system
143#else // !_LIBCPP_HAS_NO_THREADS
143# error "<shared_mutex> is not supported since libc++ has been configured without support for threads."
144#endif
144145
145146_LIBCPP_BEGIN_NAMESPACE_STD
146147
......@@ -399,9 +400,9 @@ public:
399400 void lock();
400401 bool try_lock();
401402 template <class Rep, class Period>
402 bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
403 bool try_lock_for(const chrono::duration<Rep, Period>& __rel_time);
403404 template <class Clock, class Duration>
404 bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
405 bool try_lock_until(const chrono::time_point<Clock, Duration>& __abs_time);
405406 void unlock();
406407
407408 // Setters
......@@ -500,8 +501,6 @@ swap(shared_lock<_Mutex>& __x, shared_lock<_Mutex>& __y) _NOEXCEPT
500501
501502_LIBCPP_END_NAMESPACE_STD
502503
503#endif // !_LIBCPP_HAS_NO_THREADS
504
505504#endif // _LIBCPP_STD_VER > 11
506505
507506_LIBCPP_POP_MACROS
lib/libcxx/include/span+129-123
......@@ -127,24 +127,43 @@ template<class R>
127127
128128*/
129129
130#include <__assert> // all public C++ headers provide the assertion handler
130131#include <__config>
131132#include <__debug>
133#include <__fwd/span.h>
134#include <__iterator/bounded_iter.h>
132135#include <__iterator/concepts.h>
136#include <__iterator/iterator_traits.h>
133137#include <__iterator/wrap_iter.h>
138#include <__memory/pointer_traits.h>
134139#include <__ranges/concepts.h>
135140#include <__ranges/data.h>
136141#include <__ranges/enable_borrowed_range.h>
137142#include <__ranges/enable_view.h>
138143#include <__ranges/size.h>
144#include <__utility/forward.h>
139145#include <array> // for array
140146#include <cstddef> // for byte
141#include <iterator> // for iterators
142147#include <limits>
143148#include <type_traits> // for remove_cv, etc
144149#include <version>
145150
151#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
152# include <functional>
153# include <iterator>
154#endif
155
156// standard-mandated includes
157
158// [iterator.range]
159#include <__iterator/access.h>
160#include <__iterator/data.h>
161#include <__iterator/empty.h>
162#include <__iterator/reverse_access.h>
163#include <__iterator/size.h>
164
146165#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
147#pragma GCC system_header
166# pragma GCC system_header
148167#endif
149168
150169_LIBCPP_PUSH_MACROS
......@@ -154,10 +173,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD
154173
155174#if _LIBCPP_STD_VER > 17
156175
157inline constexpr size_t dynamic_extent = numeric_limits<size_t>::max();
158template <typename _Tp, size_t _Extent = dynamic_extent> class span;
159
160
161176template <class _Tp>
162177struct __is_std_array : false_type {};
163178
......@@ -170,24 +185,22 @@ struct __is_std_span : false_type {};
170185template <class _Tp, size_t _Sz>
171186struct __is_std_span<span<_Tp, _Sz>> : true_type {};
172187
173#if defined(_LIBCPP_HAS_NO_CONCEPTS) || defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
188#if defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
174189// This is a temporary workaround until we ship <ranges> -- we've unfortunately been
175190// shipping <span> before its API was finalized, and we used to provide a constructor
176191// from container types that had the requirements below. To avoid breaking code that
177192// has started relying on the range-based constructor until we ship all of <ranges>,
178193// we emulate the constructor requirements like this.
179template <class _Range, class _ElementType, class = void>
180struct __span_compatible_range : false_type { };
181
182194template <class _Range, class _ElementType>
183struct __span_compatible_range<_Range, _ElementType, void_t<
184 enable_if_t<!__is_std_span<remove_cvref_t<_Range>>::value>,
185 enable_if_t<!__is_std_array<remove_cvref_t<_Range>>::value>,
186 enable_if_t<!is_array_v<remove_cvref_t<_Range>>>,
187 decltype(data(declval<_Range>())),
188 decltype(size(declval<_Range>())),
189 enable_if_t<is_convertible_v<remove_pointer_t<decltype(data(declval<_Range&>()))>(*)[], _ElementType(*)[]>>
190>> : true_type { };
195concept __span_compatible_range =
196 !__is_std_span<remove_cvref_t<_Range>>::value &&
197 !__is_std_array<remove_cvref_t<_Range>>::value &&
198 !is_array_v<remove_cvref_t<_Range>> &&
199 requires (_Range&& __r) {
200 data(std::forward<_Range>(__r));
201 size(std::forward<_Range>(__r));
202 } &&
203 is_convertible_v<remove_reference_t<ranges::range_reference_t<_Range>>(*)[], _ElementType(*)[]>;
191204#else
192205template <class _Range, class _ElementType>
193206concept __span_compatible_range =
......@@ -198,7 +211,16 @@ concept __span_compatible_range =
198211 !__is_std_array<remove_cvref_t<_Range>>::value &&
199212 !is_array_v<remove_cvref_t<_Range>> &&
200213 is_convertible_v<remove_reference_t<ranges::range_reference_t<_Range>>(*)[], _ElementType(*)[]>;
201#endif
214#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
215
216template <class _From, class _To>
217concept __span_array_convertible = is_convertible_v<_From(*)[], _To(*)[]>;
218
219template <class _It, class _Tp>
220concept __span_compatible_iterator = contiguous_iterator<_It> && __span_array_convertible<remove_reference_t<iter_reference_t<_It>>, _Tp>;
221
222template <class _Sentinel, class _It>
223concept __span_compatible_sentinel_for = sized_sentinel_for<_Sentinel, _It> && !is_convertible_v<_Sentinel, size_t>;
202224
203225template <typename _Tp, size_t _Extent>
204226class _LIBCPP_TEMPLATE_VIS span {
......@@ -212,8 +234,8 @@ public:
212234 using const_pointer = const _Tp *;
213235 using reference = _Tp &;
214236 using const_reference = const _Tp &;
215#if (_LIBCPP_DEBUG_LEVEL == 2) || defined(_LIBCPP_ABI_SPAN_POINTER_ITERATORS)
216 using iterator = pointer;
237#ifdef _LIBCPP_ENABLE_DEBUG_MODE
238 using iterator = __bounded_iter<pointer>;
217239#else
218240 using iterator = __wrap_iter<pointer>;
219241#endif
......@@ -222,17 +244,13 @@ public:
222244 static constexpr size_type extent = _Extent;
223245
224246// [span.cons], span constructors, copy, assignment, and destructor
225 template <size_t _Sz = _Extent, enable_if_t<_Sz == 0, nullptr_t> = nullptr>
247 template <size_t _Sz = _Extent> requires(_Sz == 0)
226248 _LIBCPP_INLINE_VISIBILITY constexpr span() noexcept : __data{nullptr} {}
227249
228250 constexpr span (const span&) noexcept = default;
229251 constexpr span& operator=(const span&) noexcept = default;
230252
231#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
232 template <class _It,
233 enable_if_t<contiguous_iterator<_It> &&
234 is_convertible_v<remove_reference_t<iter_reference_t<_It>>(*)[], element_type (*)[]>,
235 nullptr_t> = nullptr>
253 template <__span_compatible_iterator<element_type> _It>
236254 _LIBCPP_INLINE_VISIBILITY
237255 constexpr explicit span(_It __first, size_type __count)
238256 : __data{_VSTD::to_address(__first)} {
......@@ -240,11 +258,7 @@ public:
240258 _LIBCPP_ASSERT(_Extent == __count, "size mismatch in span's constructor (iterator, len)");
241259 }
242260
243 template <
244 class _It, class _End,
245 enable_if_t<is_convertible_v<remove_reference_t<iter_reference_t<_It> > (*)[], element_type (*)[]> &&
246 contiguous_iterator<_It> && sized_sentinel_for<_End, _It> && !is_convertible_v<_End, size_t>,
247 nullptr_t> = nullptr>
261 template <__span_compatible_iterator<element_type> _It, __span_compatible_sentinel_for<_It> _End>
248262 _LIBCPP_INLINE_VISIBILITY
249263 constexpr explicit span(_It __first, _End __last) : __data{_VSTD::to_address(__first)} {
250264 (void)__last;
......@@ -252,31 +266,27 @@ public:
252266 _LIBCPP_ASSERT(__last - __first == _Extent,
253267 "invalid range in span's constructor (iterator, sentinel): last - first != extent");
254268 }
255#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
256269
257270 _LIBCPP_INLINE_VISIBILITY constexpr span(type_identity_t<element_type> (&__arr)[_Extent]) noexcept : __data{__arr} {}
258271
259 template <class _OtherElementType,
260 enable_if_t<is_convertible_v<_OtherElementType(*)[], element_type (*)[]>, nullptr_t> = nullptr>
272 template <__span_array_convertible<element_type> _OtherElementType>
261273 _LIBCPP_INLINE_VISIBILITY
262274 constexpr span(array<_OtherElementType, _Extent>& __arr) noexcept : __data{__arr.data()} {}
263275
264 template <class _OtherElementType,
265 enable_if_t<is_convertible_v<const _OtherElementType(*)[], element_type (*)[]>, nullptr_t> = nullptr>
276 template <class _OtherElementType>
277 requires __span_array_convertible<const _OtherElementType, element_type>
266278 _LIBCPP_INLINE_VISIBILITY
267279 constexpr span(const array<_OtherElementType, _Extent>& __arr) noexcept : __data{__arr.data()} {}
268280
269#if defined(_LIBCPP_HAS_NO_CONCEPTS) || defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
270 template <class _Container, class = enable_if_t<
271 __span_compatible_range<_Container, element_type>::value
272 >>
281#if defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
282 template <class _Container>
283 requires __span_compatible_range<_Container, element_type>
273284 _LIBCPP_INLINE_VISIBILITY
274285 constexpr explicit span(_Container& __c) : __data{std::data(__c)} {
275286 _LIBCPP_ASSERT(std::size(__c) == _Extent, "size mismatch in span's constructor (range)");
276287 }
277 template <class _Container, class = enable_if_t<
278 __span_compatible_range<const _Container, element_type>::value
279 >>
288 template <class _Container>
289 requires __span_compatible_range<const _Container, element_type>
280290 _LIBCPP_INLINE_VISIBILITY
281291 constexpr explicit span(const _Container& __c) : __data{std::data(__c)} {
282292 _LIBCPP_ASSERT(std::size(__c) == _Extent, "size mismatch in span's constructor (range)");
......@@ -287,22 +297,16 @@ public:
287297 constexpr explicit span(_Range&& __r) : __data{ranges::data(__r)} {
288298 _LIBCPP_ASSERT(ranges::size(__r) == _Extent, "size mismatch in span's constructor (range)");
289299 }
290#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
300#endif
291301
292 template <class _OtherElementType>
302 template <__span_array_convertible<element_type> _OtherElementType>
293303 _LIBCPP_INLINE_VISIBILITY
294 constexpr span(const span<_OtherElementType, _Extent>& __other,
295 enable_if_t<
296 is_convertible_v<_OtherElementType(*)[], element_type (*)[]>,
297 nullptr_t> = nullptr)
304 constexpr span(const span<_OtherElementType, _Extent>& __other)
298305 : __data{__other.data()} {}
299306
300 template <class _OtherElementType>
307 template <__span_array_convertible<element_type> _OtherElementType>
301308 _LIBCPP_INLINE_VISIBILITY
302 constexpr explicit span(const span<_OtherElementType, dynamic_extent>& __other,
303 enable_if_t<
304 is_convertible_v<_OtherElementType(*)[], element_type (*)[]>,
305 nullptr_t> = nullptr) noexcept
309 constexpr explicit span(const span<_OtherElementType, dynamic_extent>& __other) noexcept
306310 : __data{__other.data()} { _LIBCPP_ASSERT(_Extent == __other.size(), "size mismatch in span's constructor (other span)"); }
307311
308312
......@@ -312,7 +316,7 @@ public:
312316 _LIBCPP_INLINE_VISIBILITY
313317 constexpr span<element_type, _Count> first() const noexcept
314318 {
315 static_assert(_Count <= _Extent, "Count out of range in span::first()");
319 static_assert(_Count <= _Extent, "span<T, N>::first<Count>(): Count out of range");
316320 return span<element_type, _Count>{data(), _Count};
317321 }
318322
......@@ -320,21 +324,21 @@ public:
320324 _LIBCPP_INLINE_VISIBILITY
321325 constexpr span<element_type, _Count> last() const noexcept
322326 {
323 static_assert(_Count <= _Extent, "Count out of range in span::last()");
327 static_assert(_Count <= _Extent, "span<T, N>::last<Count>(): Count out of range");
324328 return span<element_type, _Count>{data() + size() - _Count, _Count};
325329 }
326330
327331 _LIBCPP_INLINE_VISIBILITY
328332 constexpr span<element_type, dynamic_extent> first(size_type __count) const noexcept
329333 {
330 _LIBCPP_ASSERT(__count <= size(), "Count out of range in span::first(count)");
334 _LIBCPP_ASSERT(__count <= size(), "span<T, N>::first(count): count out of range");
331335 return {data(), __count};
332336 }
333337
334338 _LIBCPP_INLINE_VISIBILITY
335339 constexpr span<element_type, dynamic_extent> last(size_type __count) const noexcept
336340 {
337 _LIBCPP_ASSERT(__count <= size(), "Count out of range in span::last(count)");
341 _LIBCPP_ASSERT(__count <= size(), "span<T, N>::last(count): count out of range");
338342 return {data() + size() - __count, __count};
339343 }
340344
......@@ -343,8 +347,8 @@ public:
343347 constexpr auto subspan() const noexcept
344348 -> span<element_type, _Count != dynamic_extent ? _Count : _Extent - _Offset>
345349 {
346 static_assert(_Offset <= _Extent, "Offset out of range in span::subspan()");
347 static_assert(_Count == dynamic_extent || _Count <= _Extent - _Offset, "Offset + count out of range in span::subspan()");
350 static_assert(_Offset <= _Extent, "span<T, N>::subspan<Offset, Count>(): Offset out of range");
351 static_assert(_Count == dynamic_extent || _Count <= _Extent - _Offset, "span<T, N>::subspan<Offset, Count>(): Offset + Count out of range");
348352
349353 using _ReturnType = span<element_type, _Count != dynamic_extent ? _Count : _Extent - _Offset>;
350354 return _ReturnType{data() + _Offset, _Count == dynamic_extent ? size() - _Offset : _Count};
......@@ -355,11 +359,11 @@ public:
355359 constexpr span<element_type, dynamic_extent>
356360 subspan(size_type __offset, size_type __count = dynamic_extent) const noexcept
357361 {
358 _LIBCPP_ASSERT(__offset <= size(), "Offset out of range in span::subspan(offset, count)");
359 _LIBCPP_ASSERT(__count <= size() || __count == dynamic_extent, "Count out of range in span::subspan(offset, count)");
362 _LIBCPP_ASSERT(__offset <= size(), "span<T, N>::subspan(offset, count): offset out of range");
363 _LIBCPP_ASSERT(__count <= size() || __count == dynamic_extent, "span<T, N>::subspan(offset, count): count out of range");
360364 if (__count == dynamic_extent)
361365 return {data() + __offset, size() - __offset};
362 _LIBCPP_ASSERT(__count <= size() - __offset, "Offset + count out of range in span::subspan(offset, count)");
366 _LIBCPP_ASSERT(__count <= size() - __offset, "span<T, N>::subspan(offset, count): offset + count out of range");
363367 return {data() + __offset, __count};
364368 }
365369
......@@ -369,7 +373,7 @@ public:
369373
370374 _LIBCPP_INLINE_VISIBILITY constexpr reference operator[](size_type __idx) const noexcept
371375 {
372 _LIBCPP_ASSERT(__idx < size(), "span<T,N>[] index out of bounds");
376 _LIBCPP_ASSERT(__idx < size(), "span<T, N>::operator[](index): index out of range");
373377 return __data[__idx];
374378 }
375379
......@@ -388,8 +392,20 @@ public:
388392 _LIBCPP_INLINE_VISIBILITY constexpr pointer data() const noexcept { return __data; }
389393
390394// [span.iter], span iterator support
391 _LIBCPP_INLINE_VISIBILITY constexpr iterator begin() const noexcept { return iterator(data()); }
392 _LIBCPP_INLINE_VISIBILITY constexpr iterator end() const noexcept { return iterator(data() + size()); }
395 _LIBCPP_INLINE_VISIBILITY constexpr iterator begin() const noexcept {
396#ifdef _LIBCPP_ENABLE_DEBUG_MODE
397 return std::__make_bounded_iter(data(), data(), data() + size());
398#else
399 return iterator(this, data());
400#endif
401 }
402 _LIBCPP_INLINE_VISIBILITY constexpr iterator end() const noexcept {
403#ifdef _LIBCPP_ENABLE_DEBUG_MODE
404 return std::__make_bounded_iter(data() + size(), data(), data() + size());
405#else
406 return iterator(this, data() + size());
407#endif
408 }
393409 _LIBCPP_INLINE_VISIBILITY constexpr reverse_iterator rbegin() const noexcept { return reverse_iterator(end()); }
394410 _LIBCPP_INLINE_VISIBILITY constexpr reverse_iterator rend() const noexcept { return reverse_iterator(begin()); }
395411
......@@ -401,14 +417,11 @@ public:
401417
402418private:
403419 pointer __data;
404
405420};
406421
407422
408423template <typename _Tp>
409424class _LIBCPP_TEMPLATE_VIS span<_Tp, dynamic_extent> {
410private:
411
412425public:
413426// constants and types
414427 using element_type = _Tp;
......@@ -419,8 +432,8 @@ public:
419432 using const_pointer = const _Tp *;
420433 using reference = _Tp &;
421434 using const_reference = const _Tp &;
422#if (_LIBCPP_DEBUG_LEVEL == 2) || defined(_LIBCPP_ABI_SPAN_POINTER_ITERATORS)
423 using iterator = pointer;
435#ifdef _LIBCPP_ENABLE_DEBUG_MODE
436 using iterator = __bounded_iter<pointer>;
424437#else
425438 using iterator = __wrap_iter<pointer>;
426439#endif
......@@ -434,62 +447,47 @@ public:
434447 constexpr span (const span&) noexcept = default;
435448 constexpr span& operator=(const span&) noexcept = default;
436449
437#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
438 template <class _It,
439 enable_if_t<contiguous_iterator<_It> &&
440 is_convertible_v<remove_reference_t<iter_reference_t<_It> > (*)[], element_type (*)[]>,
441 nullptr_t> = nullptr>
450 template <__span_compatible_iterator<element_type> _It>
442451 _LIBCPP_INLINE_VISIBILITY
443452 constexpr span(_It __first, size_type __count)
444453 : __data{_VSTD::to_address(__first)}, __size{__count} {}
445454
446 template <
447 class _It, class _End,
448 enable_if_t<is_convertible_v<remove_reference_t<iter_reference_t<_It> > (*)[], element_type (*)[]> &&
449 contiguous_iterator<_It> && sized_sentinel_for<_End, _It> && !is_convertible_v<_End, size_t>,
450 nullptr_t> = nullptr>
455 template <__span_compatible_iterator<element_type> _It, __span_compatible_sentinel_for<_It> _End>
451456 _LIBCPP_INLINE_VISIBILITY
452457 constexpr span(_It __first, _End __last)
453458 : __data(_VSTD::to_address(__first)), __size(__last - __first) {}
454#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
455459
456460 template <size_t _Sz>
457461 _LIBCPP_INLINE_VISIBILITY
458462 constexpr span(type_identity_t<element_type> (&__arr)[_Sz]) noexcept : __data{__arr}, __size{_Sz} {}
459463
460 template <class _OtherElementType, size_t _Sz,
461 enable_if_t<is_convertible_v<_OtherElementType(*)[], element_type (*)[]>, nullptr_t> = nullptr>
464 template <__span_array_convertible<element_type> _OtherElementType, size_t _Sz>
462465 _LIBCPP_INLINE_VISIBILITY
463466 constexpr span(array<_OtherElementType, _Sz>& __arr) noexcept : __data{__arr.data()}, __size{_Sz} {}
464467
465 template <class _OtherElementType, size_t _Sz,
466 enable_if_t<is_convertible_v<const _OtherElementType(*)[], element_type (*)[]>, nullptr_t> = nullptr>
468 template <class _OtherElementType, size_t _Sz>
469 requires __span_array_convertible<const _OtherElementType, element_type>
467470 _LIBCPP_INLINE_VISIBILITY
468471 constexpr span(const array<_OtherElementType, _Sz>& __arr) noexcept : __data{__arr.data()}, __size{_Sz} {}
469472
470#if defined(_LIBCPP_HAS_NO_CONCEPTS) || defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
471 template <class _Container, class = enable_if_t<
472 __span_compatible_range<_Container, element_type>::value
473 >>
473#if defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
474 template <class _Container>
475 requires __span_compatible_range<_Container, element_type>
474476 _LIBCPP_INLINE_VISIBILITY
475477 constexpr span(_Container& __c) : __data(std::data(__c)), __size{std::size(__c)} {}
476 template <class _Container, class = enable_if_t<
477 __span_compatible_range<const _Container, element_type>::value
478 >>
478 template <class _Container>
479 requires __span_compatible_range<const _Container, element_type>
479480 _LIBCPP_INLINE_VISIBILITY
480481 constexpr span(const _Container& __c) : __data(std::data(__c)), __size{std::size(__c)} {}
481482#else
482483 template <__span_compatible_range<element_type> _Range>
483484 _LIBCPP_INLINE_VISIBILITY
484485 constexpr span(_Range&& __r) : __data(ranges::data(__r)), __size{ranges::size(__r)} {}
485#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
486#endif
486487
487 template <class _OtherElementType, size_t _OtherExtent>
488 template <__span_array_convertible<element_type> _OtherElementType, size_t _OtherExtent>
488489 _LIBCPP_INLINE_VISIBILITY
489 constexpr span(const span<_OtherElementType, _OtherExtent>& __other,
490 enable_if_t<
491 is_convertible_v<_OtherElementType(*)[], element_type (*)[]>,
492 nullptr_t> = nullptr) noexcept
490 constexpr span(const span<_OtherElementType, _OtherExtent>& __other) noexcept
493491 : __data{__other.data()}, __size{__other.size()} {}
494492
495493// ~span() noexcept = default;
......@@ -498,7 +496,7 @@ public:
498496 _LIBCPP_INLINE_VISIBILITY
499497 constexpr span<element_type, _Count> first() const noexcept
500498 {
501 _LIBCPP_ASSERT(_Count <= size(), "Count out of range in span::first()");
499 _LIBCPP_ASSERT(_Count <= size(), "span<T>::first<Count>(): Count out of range");
502500 return span<element_type, _Count>{data(), _Count};
503501 }
504502
......@@ -506,21 +504,21 @@ public:
506504 _LIBCPP_INLINE_VISIBILITY
507505 constexpr span<element_type, _Count> last() const noexcept
508506 {
509 _LIBCPP_ASSERT(_Count <= size(), "Count out of range in span::last()");
507 _LIBCPP_ASSERT(_Count <= size(), "span<T>::last<Count>(): Count out of range");
510508 return span<element_type, _Count>{data() + size() - _Count, _Count};
511509 }
512510
513511 _LIBCPP_INLINE_VISIBILITY
514512 constexpr span<element_type, dynamic_extent> first(size_type __count) const noexcept
515513 {
516 _LIBCPP_ASSERT(__count <= size(), "Count out of range in span::first(count)");
514 _LIBCPP_ASSERT(__count <= size(), "span<T>::first(count): count out of range");
517515 return {data(), __count};
518516 }
519517
520518 _LIBCPP_INLINE_VISIBILITY
521519 constexpr span<element_type, dynamic_extent> last (size_type __count) const noexcept
522520 {
523 _LIBCPP_ASSERT(__count <= size(), "Count out of range in span::last(count)");
521 _LIBCPP_ASSERT(__count <= size(), "span<T>::last(count): count out of range");
524522 return {data() + size() - __count, __count};
525523 }
526524
......@@ -528,8 +526,8 @@ public:
528526 _LIBCPP_INLINE_VISIBILITY
529527 constexpr span<element_type, _Count> subspan() const noexcept
530528 {
531 _LIBCPP_ASSERT(_Offset <= size(), "Offset out of range in span::subspan()");
532 _LIBCPP_ASSERT(_Count == dynamic_extent || _Count <= size() - _Offset, "Offset + count out of range in span::subspan()");
529 _LIBCPP_ASSERT(_Offset <= size(), "span<T>::subspan<Offset, Count>(): Offset out of range");
530 _LIBCPP_ASSERT(_Count == dynamic_extent || _Count <= size() - _Offset, "span<T>::subspan<Offset, Count>(): Offset + Count out of range");
533531 return span<element_type, _Count>{data() + _Offset, _Count == dynamic_extent ? size() - _Offset : _Count};
534532 }
535533
......@@ -537,11 +535,11 @@ public:
537535 _LIBCPP_INLINE_VISIBILITY
538536 subspan(size_type __offset, size_type __count = dynamic_extent) const noexcept
539537 {
540 _LIBCPP_ASSERT(__offset <= size(), "Offset out of range in span::subspan(offset, count)");
541 _LIBCPP_ASSERT(__count <= size() || __count == dynamic_extent, "count out of range in span::subspan(offset, count)");
538 _LIBCPP_ASSERT(__offset <= size(), "span<T>::subspan(offset, count): offset out of range");
539 _LIBCPP_ASSERT(__count <= size() || __count == dynamic_extent, "span<T>::subspan(offset, count): count out of range");
542540 if (__count == dynamic_extent)
543541 return {data() + __offset, size() - __offset};
544 _LIBCPP_ASSERT(__count <= size() - __offset, "Offset + count out of range in span::subspan(offset, count)");
542 _LIBCPP_ASSERT(__count <= size() - __offset, "span<T>::subspan(offset, count): offset + count out of range");
545543 return {data() + __offset, __count};
546544 }
547545
......@@ -551,19 +549,19 @@ public:
551549
552550 _LIBCPP_INLINE_VISIBILITY constexpr reference operator[](size_type __idx) const noexcept
553551 {
554 _LIBCPP_ASSERT(__idx < size(), "span<T>[] index out of bounds");
552 _LIBCPP_ASSERT(__idx < size(), "span<T>::operator[](index): index out of range");
555553 return __data[__idx];
556554 }
557555
558556 _LIBCPP_INLINE_VISIBILITY constexpr reference front() const noexcept
559557 {
560 _LIBCPP_ASSERT(!empty(), "span<T>[].front() on empty span");
558 _LIBCPP_ASSERT(!empty(), "span<T>::front() on empty span");
561559 return __data[0];
562560 }
563561
564562 _LIBCPP_INLINE_VISIBILITY constexpr reference back() const noexcept
565563 {
566 _LIBCPP_ASSERT(!empty(), "span<T>[].back() on empty span");
564 _LIBCPP_ASSERT(!empty(), "span<T>::back() on empty span");
567565 return __data[size()-1];
568566 }
569567
......@@ -571,8 +569,20 @@ public:
571569 _LIBCPP_INLINE_VISIBILITY constexpr pointer data() const noexcept { return __data; }
572570
573571// [span.iter], span iterator support
574 _LIBCPP_INLINE_VISIBILITY constexpr iterator begin() const noexcept { return iterator(data()); }
575 _LIBCPP_INLINE_VISIBILITY constexpr iterator end() const noexcept { return iterator(data() + size()); }
572 _LIBCPP_INLINE_VISIBILITY constexpr iterator begin() const noexcept {
573#ifdef _LIBCPP_ENABLE_DEBUG_MODE
574 return std::__make_bounded_iter(data(), data(), data() + size());
575#else
576 return iterator(this, data());
577#endif
578 }
579 _LIBCPP_INLINE_VISIBILITY constexpr iterator end() const noexcept {
580#ifdef _LIBCPP_ENABLE_DEBUG_MODE
581 return std::__make_bounded_iter(data() + size(), data(), data() + size());
582#else
583 return iterator(this, data() + size());
584#endif
585 }
576586 _LIBCPP_INLINE_VISIBILITY constexpr reverse_iterator rbegin() const noexcept { return reverse_iterator(end()); }
577587 _LIBCPP_INLINE_VISIBILITY constexpr reverse_iterator rend() const noexcept { return reverse_iterator(begin()); }
578588
......@@ -587,31 +597,27 @@ private:
587597 size_type __size;
588598};
589599
590#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
591600template <class _Tp, size_t _Extent>
592601inline constexpr bool ranges::enable_borrowed_range<span<_Tp, _Extent> > = true;
593602
594603template <class _ElementType, size_t _Extent>
595604inline constexpr bool ranges::enable_view<span<_ElementType, _Extent>> = true;
596#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
597605
598606// as_bytes & as_writable_bytes
599607template <class _Tp, size_t _Extent>
600608_LIBCPP_INLINE_VISIBILITY
601609auto as_bytes(span<_Tp, _Extent> __s) noexcept
602-> decltype(__s.__as_bytes())
603{ return __s.__as_bytes(); }
610{ return __s.__as_bytes(); }
604611
605template <class _Tp, size_t _Extent>
612template <class _Tp, size_t _Extent> requires(!is_const_v<_Tp>)
606613_LIBCPP_INLINE_VISIBILITY
607614auto as_writable_bytes(span<_Tp, _Extent> __s) noexcept
608-> enable_if_t<!is_const_v<_Tp>, decltype(__s.__as_writable_bytes())>
609615{ return __s.__as_writable_bytes(); }
610616
611#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
617#if _LIBCPP_STD_VER > 17
612618template<contiguous_iterator _It, class _EndOrSize>
613619 span(_It, _EndOrSize) -> span<remove_reference_t<iter_reference_t<_It>>>;
614#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
620#endif // _LIBCPP_STD_VER > 17
615621
616622template<class _Tp, size_t _Sz>
617623 span(_Tp (&)[_Sz]) -> span<_Tp, _Sz>;
......@@ -622,7 +628,7 @@ template<class _Tp, size_t _Sz>
622628template<class _Tp, size_t _Sz>
623629 span(const array<_Tp, _Sz>&) -> span<const _Tp, _Sz>;
624630
625#if defined(_LIBCPP_HAS_NO_CONCEPTS) || defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
631#if defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
626632template<class _Container>
627633 span(_Container&) -> span<typename _Container::value_type>;
628634
lib/libcxx/include/sstream+7-5
......@@ -180,14 +180,16 @@ typedef basic_stringstream<wchar_t> wstringstream;
180180
181181*/
182182
183#include <__assert> // all public C++ headers provide the assertion handler
183184#include <__config>
185#include <__utility/swap.h>
184186#include <istream>
185187#include <ostream>
186188#include <string>
187189#include <version>
188190
189191#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
190#pragma GCC system_header
192# pragma GCC system_header
191193#endif
192194
193195_LIBCPP_PUSH_MACROS
......@@ -859,10 +861,10 @@ swap(basic_stringstream<_CharT, _Traits, _Allocator>& __x,
859861}
860862
861863#if defined(_LIBCPP_ABI_ENABLE_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1)
862_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_stringbuf<char>)
863_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_stringstream<char>)
864_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostringstream<char>)
865_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istringstream<char>)
864extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_stringbuf<char>;
865extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_stringstream<char>;
866extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostringstream<char>;
867extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istringstream<char>;
866868#endif
867869
868870_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/stack+10-1
......@@ -98,6 +98,7 @@ template <class T, class Container>
9898
9999*/
100100
101#include <__assert> // all public C++ headers provide the assertion handler
101102#include <__config>
102103#include <__iterator/iterator_traits.h>
103104#include <__memory/uses_allocator.h>
......@@ -106,8 +107,16 @@ template <class T, class Container>
106107#include <type_traits>
107108#include <version>
108109
110#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
111# include <functional>
112#endif
113
114// standard-mandated includes
115#include <compare>
116#include <initializer_list>
117
109118#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
110#pragma GCC system_header
119# pragma GCC system_header
111120#endif
112121
113122_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/stdatomic.h created+235
......@@ -0,0 +1,235 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_STDATOMIC_H
11#define _LIBCPP_STDATOMIC_H
12
13/*
14 stdatomic.h synopsis
15
16template<class T>
17 using std-atomic = std::atomic<T>; // exposition only
18
19#define _Atomic(T) std-atomic<T>
20
21#define ATOMIC_BOOL_LOCK_FREE see below
22#define ATOMIC_CHAR_LOCK_FREE see below
23#define ATOMIC_CHAR16_T_LOCK_FREE see below
24#define ATOMIC_CHAR32_T_LOCK_FREE see below
25#define ATOMIC_WCHAR_T_LOCK_FREE see below
26#define ATOMIC_SHORT_LOCK_FREE see below
27#define ATOMIC_INT_LOCK_FREE see below
28#define ATOMIC_LONG_LOCK_FREE see below
29#define ATOMIC_LLONG_LOCK_FREE see below
30#define ATOMIC_POINTER_LOCK_FREE see below
31
32using std::memory_order // see below
33using std::memory_order_relaxed // see below
34using std::memory_order_consume // see below
35using std::memory_order_acquire // see below
36using std::memory_order_release // see below
37using std::memory_order_acq_rel // see below
38using std::memory_order_seq_cst // see below
39
40using std::atomic_flag // see below
41
42using std::atomic_bool // see below
43using std::atomic_char // see below
44using std::atomic_schar // see below
45using std::atomic_uchar // see below
46using std::atomic_short // see below
47using std::atomic_ushort // see below
48using std::atomic_int // see below
49using std::atomic_uint // see below
50using std::atomic_long // see below
51using std::atomic_ulong // see below
52using std::atomic_llong // see below
53using std::atomic_ullong // see below
54using std::atomic_char8_t // see below
55using std::atomic_char16_t // see below
56using std::atomic_char32_t // see below
57using std::atomic_wchar_t // see below
58using std::atomic_int8_t // see below
59using std::atomic_uint8_t // see below
60using std::atomic_int16_t // see below
61using std::atomic_uint16_t // see below
62using std::atomic_int32_t // see below
63using std::atomic_uint32_t // see below
64using std::atomic_int64_t // see below
65using std::atomic_uint64_t // see below
66using std::atomic_int_least8_t // see below
67using std::atomic_uint_least8_t // see below
68using std::atomic_int_least16_t // see below
69using std::atomic_uint_least16_t // see below
70using std::atomic_int_least32_t // see below
71using std::atomic_uint_least32_t // see below
72using std::atomic_int_least64_t // see below
73using std::atomic_uint_least64_t // see below
74using std::atomic_int_fast8_t // see below
75using std::atomic_uint_fast8_t // see below
76using std::atomic_int_fast16_t // see below
77using std::atomic_uint_fast16_t // see below
78using std::atomic_int_fast32_t // see below
79using std::atomic_uint_fast32_t // see below
80using std::atomic_int_fast64_t // see below
81using std::atomic_uint_fast64_t // see below
82using std::atomic_intptr_t // see below
83using std::atomic_uintptr_t // see below
84using std::atomic_size_t // see below
85using std::atomic_ptrdiff_t // see below
86using std::atomic_intmax_t // see below
87using std::atomic_uintmax_t // see below
88
89using std::atomic_is_lock_free // see below
90using std::atomic_load // see below
91using std::atomic_load_explicit // see below
92using std::atomic_store // see below
93using std::atomic_store_explicit // see below
94using std::atomic_exchange // see below
95using std::atomic_exchange_explicit // see below
96using std::atomic_compare_exchange_strong // see below
97using std::atomic_compare_exchange_strong_explicit // see below
98using std::atomic_compare_exchange_weak // see below
99using std::atomic_compare_exchange_weak_explicit // see below
100using std::atomic_fetch_add // see below
101using std::atomic_fetch_add_explicit // see below
102using std::atomic_fetch_sub // see below
103using std::atomic_fetch_sub_explicit // see below
104using std::atomic_fetch_or // see below
105using std::atomic_fetch_or_explicit // see below
106using std::atomic_fetch_and // see below
107using std::atomic_fetch_and_explicit // see below
108using std::atomic_flag_test_and_set // see below
109using std::atomic_flag_test_and_set_explicit // see below
110using std::atomic_flag_clear // see below
111using std::atomic_flag_clear_explicit // see below
112
113using std::atomic_thread_fence // see below
114using std::atomic_signal_fence // see below
115
116*/
117
118#include <__config>
119
120#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
121# pragma GCC system_header
122#endif
123
124#if _LIBCPP_STD_VER > 20
125
126#include <atomic>
127#include <version>
128
129#ifdef _Atomic
130# undef _Atomic
131#endif
132
133#define _Atomic(_Tp) ::std::atomic<_Tp>
134
135using std::memory_order _LIBCPP_USING_IF_EXISTS;
136using std::memory_order_relaxed _LIBCPP_USING_IF_EXISTS;
137using std::memory_order_consume _LIBCPP_USING_IF_EXISTS;
138using std::memory_order_acquire _LIBCPP_USING_IF_EXISTS;
139using std::memory_order_release _LIBCPP_USING_IF_EXISTS;
140using std::memory_order_acq_rel _LIBCPP_USING_IF_EXISTS;
141using std::memory_order_seq_cst _LIBCPP_USING_IF_EXISTS;
142
143using std::atomic_flag _LIBCPP_USING_IF_EXISTS;
144
145using std::atomic_bool _LIBCPP_USING_IF_EXISTS;
146using std::atomic_char _LIBCPP_USING_IF_EXISTS;
147using std::atomic_schar _LIBCPP_USING_IF_EXISTS;
148using std::atomic_uchar _LIBCPP_USING_IF_EXISTS;
149using std::atomic_short _LIBCPP_USING_IF_EXISTS;
150using std::atomic_ushort _LIBCPP_USING_IF_EXISTS;
151using std::atomic_int _LIBCPP_USING_IF_EXISTS;
152using std::atomic_uint _LIBCPP_USING_IF_EXISTS;
153using std::atomic_long _LIBCPP_USING_IF_EXISTS;
154using std::atomic_ulong _LIBCPP_USING_IF_EXISTS;
155using std::atomic_llong _LIBCPP_USING_IF_EXISTS;
156using std::atomic_ullong _LIBCPP_USING_IF_EXISTS;
157using std::atomic_char8_t _LIBCPP_USING_IF_EXISTS;
158using std::atomic_char16_t _LIBCPP_USING_IF_EXISTS;
159using std::atomic_char32_t _LIBCPP_USING_IF_EXISTS;
160using std::atomic_wchar_t _LIBCPP_USING_IF_EXISTS;
161
162using std::atomic_int8_t _LIBCPP_USING_IF_EXISTS;
163using std::atomic_uint8_t _LIBCPP_USING_IF_EXISTS;
164using std::atomic_int16_t _LIBCPP_USING_IF_EXISTS;
165using std::atomic_uint16_t _LIBCPP_USING_IF_EXISTS;
166using std::atomic_int32_t _LIBCPP_USING_IF_EXISTS;
167using std::atomic_uint32_t _LIBCPP_USING_IF_EXISTS;
168using std::atomic_int64_t _LIBCPP_USING_IF_EXISTS;
169using std::atomic_uint64_t _LIBCPP_USING_IF_EXISTS;
170
171using std::atomic_int_least8_t _LIBCPP_USING_IF_EXISTS;
172using std::atomic_uint_least8_t _LIBCPP_USING_IF_EXISTS;
173using std::atomic_int_least16_t _LIBCPP_USING_IF_EXISTS;
174using std::atomic_uint_least16_t _LIBCPP_USING_IF_EXISTS;
175using std::atomic_int_least32_t _LIBCPP_USING_IF_EXISTS;
176using std::atomic_uint_least32_t _LIBCPP_USING_IF_EXISTS;
177using std::atomic_int_least64_t _LIBCPP_USING_IF_EXISTS;
178using std::atomic_uint_least64_t _LIBCPP_USING_IF_EXISTS;
179
180using std::atomic_int_fast8_t _LIBCPP_USING_IF_EXISTS;
181using std::atomic_uint_fast8_t _LIBCPP_USING_IF_EXISTS;
182using std::atomic_int_fast16_t _LIBCPP_USING_IF_EXISTS;
183using std::atomic_uint_fast16_t _LIBCPP_USING_IF_EXISTS;
184using std::atomic_int_fast32_t _LIBCPP_USING_IF_EXISTS;
185using std::atomic_uint_fast32_t _LIBCPP_USING_IF_EXISTS;
186using std::atomic_int_fast64_t _LIBCPP_USING_IF_EXISTS;
187using std::atomic_uint_fast64_t _LIBCPP_USING_IF_EXISTS;
188
189using std::atomic_intptr_t _LIBCPP_USING_IF_EXISTS;
190using std::atomic_uintptr_t _LIBCPP_USING_IF_EXISTS;
191using std::atomic_size_t _LIBCPP_USING_IF_EXISTS;
192using std::atomic_ptrdiff_t _LIBCPP_USING_IF_EXISTS;
193using std::atomic_intmax_t _LIBCPP_USING_IF_EXISTS;
194using std::atomic_uintmax_t _LIBCPP_USING_IF_EXISTS;
195
196using std::atomic_compare_exchange_strong _LIBCPP_USING_IF_EXISTS;
197using std::atomic_compare_exchange_strong_explicit _LIBCPP_USING_IF_EXISTS;
198using std::atomic_compare_exchange_weak _LIBCPP_USING_IF_EXISTS;
199using std::atomic_compare_exchange_weak_explicit _LIBCPP_USING_IF_EXISTS;
200using std::atomic_exchange _LIBCPP_USING_IF_EXISTS;
201using std::atomic_exchange_explicit _LIBCPP_USING_IF_EXISTS;
202using std::atomic_fetch_add _LIBCPP_USING_IF_EXISTS;
203using std::atomic_fetch_add_explicit _LIBCPP_USING_IF_EXISTS;
204using std::atomic_fetch_and _LIBCPP_USING_IF_EXISTS;
205using std::atomic_fetch_and_explicit _LIBCPP_USING_IF_EXISTS;
206using std::atomic_fetch_or _LIBCPP_USING_IF_EXISTS;
207using std::atomic_fetch_or_explicit _LIBCPP_USING_IF_EXISTS;
208using std::atomic_fetch_sub _LIBCPP_USING_IF_EXISTS;
209using std::atomic_fetch_sub_explicit _LIBCPP_USING_IF_EXISTS;
210using std::atomic_flag_clear _LIBCPP_USING_IF_EXISTS;
211using std::atomic_flag_clear_explicit _LIBCPP_USING_IF_EXISTS;
212using std::atomic_flag_test_and_set _LIBCPP_USING_IF_EXISTS;
213using std::atomic_flag_test_and_set_explicit _LIBCPP_USING_IF_EXISTS;
214using std::atomic_is_lock_free _LIBCPP_USING_IF_EXISTS;
215using std::atomic_load _LIBCPP_USING_IF_EXISTS;
216using std::atomic_load_explicit _LIBCPP_USING_IF_EXISTS;
217using std::atomic_store _LIBCPP_USING_IF_EXISTS;
218using std::atomic_store_explicit _LIBCPP_USING_IF_EXISTS;
219
220using std::atomic_signal_fence _LIBCPP_USING_IF_EXISTS;
221using std::atomic_thread_fence _LIBCPP_USING_IF_EXISTS;
222
223#elif defined(_LIBCPP_COMPILER_CLANG_BASED)
224
225// Before C++23, we include the next <stdatomic.h> on the path to avoid hijacking
226// the header. We do this because Clang has historically shipped a <stdatomic.h>
227// header that would be available in all Standard modes, and we don't want to
228// break that use case.
229# if __has_include_next(<stdatomic.h>)
230# include_next <stdatomic.h>
231# endif
232
233#endif // _LIBCPP_STD_VER > 20
234
235#endif // _LIBCPP_STDATOMIC_H
lib/libcxx/include/stdbool.h+1-2
......@@ -9,7 +9,6 @@
99#ifndef _LIBCPP_STDBOOL_H
1010#define _LIBCPP_STDBOOL_H
1111
12
1312/*
1413 stdbool.h synopsis
1514
......@@ -22,7 +21,7 @@ Macros:
2221#include <__config>
2322
2423#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
25#pragma GCC system_header
24# pragma GCC system_header
2625#endif
2726
2827#include_next <stdbool.h>
lib/libcxx/include/stddef.h+3-8
......@@ -11,7 +11,7 @@
1111 defined(__need_wchar_t) || defined(__need_NULL) || defined(__need_wint_t)
1212
1313#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
14#pragma GCC system_header
14# pragma GCC system_header
1515#endif
1616
1717#include_next <stddef.h>
......@@ -39,18 +39,13 @@ Types:
3939#include <__config>
4040
4141#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
42#pragma GCC system_header
42# pragma GCC system_header
4343#endif
4444
4545#include_next <stddef.h>
4646
4747#ifdef __cplusplus
48
49extern "C++" {
50#include <__nullptr>
51using std::nullptr_t;
52}
53
48 typedef decltype(nullptr) nullptr_t;
5449#endif
5550
5651#endif // _LIBCPP_STDDEF_H
lib/libcxx/include/stdexcept+2-1
......@@ -41,13 +41,14 @@ public:
4141
4242*/
4343
44#include <__assert> // all public C++ headers provide the assertion handler
4445#include <__config>
4546#include <cstdlib>
4647#include <exception>
4748#include <iosfwd> // for string forward decl
4849
4950#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
50#pragma GCC system_header
51# pragma GCC system_header
5152#endif
5253
5354_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/include/stdint.h+1-1
......@@ -106,7 +106,7 @@ Macros:
106106#include <__config>
107107
108108#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
109#pragma GCC system_header
109# pragma GCC system_header
110110#endif
111111
112112/* C99 stdlib (e.g. glibc < 2.18) does not provide macros needed
lib/libcxx/include/stdio.h+2-2
......@@ -10,7 +10,7 @@
1010#if defined(__need_FILE) || defined(__need___FILE)
1111
1212#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
13#pragma GCC system_header
13# pragma GCC system_header
1414#endif
1515
1616#include_next <stdio.h>
......@@ -101,7 +101,7 @@ void perror(const char* s);
101101#include <__config>
102102
103103#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
104#pragma GCC system_header
104# pragma GCC system_header
105105#endif
106106
107107#include_next <stdio.h>
lib/libcxx/include/stdlib.h+2-2
......@@ -10,7 +10,7 @@
1010#if defined(__need_malloc_and_calloc)
1111
1212#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
13#pragma GCC system_header
13# pragma GCC system_header
1414#endif
1515
1616#include_next <stdlib.h>
......@@ -87,7 +87,7 @@ void *aligned_alloc(size_t alignment, size_t size); // C11
8787#include <__config>
8888
8989#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
90#pragma GCC system_header
90# pragma GCC system_header
9191#endif
9292
9393#include_next <stdlib.h>
lib/libcxx/include/streambuf+6-5
......@@ -107,6 +107,7 @@ protected:
107107
108108*/
109109
110#include <__assert> // all public C++ headers provide the assertion handler
110111#include <__config>
111112#include <cstdint>
112113#include <ios>
......@@ -114,7 +115,7 @@ protected:
114115#include <version>
115116
116117#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
117#pragma GCC system_header
118# pragma GCC system_header
118119#endif
119120
120121_LIBCPP_PUSH_MACROS
......@@ -487,11 +488,11 @@ basic_streambuf<_CharT, _Traits>::overflow(int_type)
487488 return traits_type::eof();
488489}
489490
490_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_streambuf<char>)
491_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_streambuf<wchar_t>)
491extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_streambuf<char>;
492extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_streambuf<wchar_t>;
492493
493_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ios<char>)
494_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ios<wchar_t>)
494extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ios<char>;
495extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ios<wchar_t>;
495496
496497_LIBCPP_END_NAMESPACE_STD
497498
lib/libcxx/include/string+1145-942
......@@ -95,248 +95,246 @@ public:
9595 static const size_type npos = -1;
9696
9797 basic_string()
98 noexcept(is_nothrow_default_constructible<allocator_type>::value);
99 explicit basic_string(const allocator_type& a);
100 basic_string(const basic_string& str);
98 noexcept(is_nothrow_default_constructible<allocator_type>::value); // constexpr since C++20
99 explicit basic_string(const allocator_type& a); // constexpr since C++20
100 basic_string(const basic_string& str); // constexpr since C++20
101101 basic_string(basic_string&& str)
102 noexcept(is_nothrow_move_constructible<allocator_type>::value);
102 noexcept(is_nothrow_move_constructible<allocator_type>::value); // constexpr since C++20
103103 basic_string(const basic_string& str, size_type pos,
104 const allocator_type& a = allocator_type());
104 const allocator_type& a = allocator_type()); // constexpr since C++20
105105 basic_string(const basic_string& str, size_type pos, size_type n,
106 const Allocator& a = Allocator());
106 const Allocator& a = Allocator()); // constexpr since C++20
107107 template<class T>
108 basic_string(const T& t, size_type pos, size_type n, const Allocator& a = Allocator()); // C++17
108 basic_string(const T& t, size_type pos, size_type n, const Allocator& a = Allocator()); // C++17, constexpr since C++20
109109 template <class T>
110 explicit basic_string(const T& t, const Allocator& a = Allocator()); // C++17
111 basic_string(const value_type* s, const allocator_type& a = allocator_type());
112 basic_string(const value_type* s, size_type n, const allocator_type& a = allocator_type());
110 explicit basic_string(const T& t, const Allocator& a = Allocator()); // C++17, constexpr since C++20
111 basic_string(const value_type* s, const allocator_type& a = allocator_type()); // constexpr since C++20
112 basic_string(const value_type* s, size_type n, const allocator_type& a = allocator_type()); // constexpr since C++20
113113 basic_string(nullptr_t) = delete; // C++2b
114 basic_string(size_type n, value_type c, const allocator_type& a = allocator_type());
114 basic_string(size_type n, value_type c, const allocator_type& a = allocator_type()); // constexpr since C++20
115115 template<class InputIterator>
116116 basic_string(InputIterator begin, InputIterator end,
117 const allocator_type& a = allocator_type());
118 basic_string(initializer_list<value_type>, const Allocator& = Allocator());
119 basic_string(const basic_string&, const Allocator&);
120 basic_string(basic_string&&, const Allocator&);
117 const allocator_type& a = allocator_type()); // constexpr since C++20
118 basic_string(initializer_list<value_type>, const Allocator& = Allocator()); // constexpr since C++20
119 basic_string(const basic_string&, const Allocator&); // constexpr since C++20
120 basic_string(basic_string&&, const Allocator&); // constexpr since C++20
121121
122 ~basic_string();
122 ~basic_string(); // constexpr since C++20
123123
124 operator basic_string_view<charT, traits>() const noexcept;
124 operator basic_string_view<charT, traits>() const noexcept; // constexpr since C++20
125125
126 basic_string& operator=(const basic_string& str);
126 basic_string& operator=(const basic_string& str); // constexpr since C++20
127127 template <class T>
128 basic_string& operator=(const T& t); // C++17
128 basic_string& operator=(const T& t); // C++17, constexpr since C++20
129129 basic_string& operator=(basic_string&& str)
130130 noexcept(
131131 allocator_type::propagate_on_container_move_assignment::value ||
132 allocator_type::is_always_equal::value ); // C++17
133 basic_string& operator=(const value_type* s);
132 allocator_type::is_always_equal::value ); // C++17, constexpr since C++20
133 basic_string& operator=(const value_type* s); // constexpr since C++20
134134 basic_string& operator=(nullptr_t) = delete; // C++2b
135 basic_string& operator=(value_type c);
136 basic_string& operator=(initializer_list<value_type>);
135 basic_string& operator=(value_type c); // constexpr since C++20
136 basic_string& operator=(initializer_list<value_type>); // constexpr since C++20
137137
138 iterator begin() noexcept;
139 const_iterator begin() const noexcept;
140 iterator end() noexcept;
141 const_iterator end() const noexcept;
138 iterator begin() noexcept; // constexpr since C++20
139 const_iterator begin() const noexcept; // constexpr since C++20
140 iterator end() noexcept; // constexpr since C++20
141 const_iterator end() const noexcept; // constexpr since C++20
142142
143 reverse_iterator rbegin() noexcept;
144 const_reverse_iterator rbegin() const noexcept;
145 reverse_iterator rend() noexcept;
146 const_reverse_iterator rend() const noexcept;
143 reverse_iterator rbegin() noexcept; // constexpr since C++20
144 const_reverse_iterator rbegin() const noexcept; // constexpr since C++20
145 reverse_iterator rend() noexcept; // constexpr since C++20
146 const_reverse_iterator rend() const noexcept; // constexpr since C++20
147147
148 const_iterator cbegin() const noexcept;
149 const_iterator cend() const noexcept;
150 const_reverse_iterator crbegin() const noexcept;
151 const_reverse_iterator crend() const noexcept;
148 const_iterator cbegin() const noexcept; // constexpr since C++20
149 const_iterator cend() const noexcept; // constexpr since C++20
150 const_reverse_iterator crbegin() const noexcept; // constexpr since C++20
151 const_reverse_iterator crend() const noexcept; // constexpr since C++20
152152
153 size_type size() const noexcept;
154 size_type length() const noexcept;
155 size_type max_size() const noexcept;
156 size_type capacity() const noexcept;
153 size_type size() const noexcept; // constexpr since C++20
154 size_type length() const noexcept; // constexpr since C++20
155 size_type max_size() const noexcept; // constexpr since C++20
156 size_type capacity() const noexcept; // constexpr since C++20
157157
158 void resize(size_type n, value_type c);
159 void resize(size_type n);
158 void resize(size_type n, value_type c); // constexpr since C++20
159 void resize(size_type n); // constexpr since C++20
160160
161161 template<class Operation>
162162 constexpr void resize_and_overwrite(size_type n, Operation op); // since C++23
163163
164 void reserve(size_type res_arg);
164 void reserve(size_type res_arg); // constexpr since C++20
165165 void reserve(); // deprecated in C++20
166 void shrink_to_fit();
167 void clear() noexcept;
168 bool empty() const noexcept;
166 void shrink_to_fit(); // constexpr since C++20
167 void clear() noexcept; // constexpr since C++20
168 bool empty() const noexcept; // constexpr since C++20
169169
170 const_reference operator[](size_type pos) const;
171 reference operator[](size_type pos);
170 const_reference operator[](size_type pos) const; // constexpr since C++20
171 reference operator[](size_type pos); // constexpr since C++20
172172
173 const_reference at(size_type n) const;
174 reference at(size_type n);
173 const_reference at(size_type n) const; // constexpr since C++20
174 reference at(size_type n); // constexpr since C++20
175175
176 basic_string& operator+=(const basic_string& str);
176 basic_string& operator+=(const basic_string& str); // constexpr since C++20
177177 template <class T>
178 basic_string& operator+=(const T& t); // C++17
179 basic_string& operator+=(const value_type* s);
180 basic_string& operator+=(value_type c);
181 basic_string& operator+=(initializer_list<value_type>);
178 basic_string& operator+=(const T& t); // C++17, constexpr since C++20
179 basic_string& operator+=(const value_type* s); // constexpr since C++20
180 basic_string& operator+=(value_type c); // constexpr since C++20
181 basic_string& operator+=(initializer_list<value_type>); // constexpr since C++20
182182
183 basic_string& append(const basic_string& str);
183 basic_string& append(const basic_string& str); // constexpr since C++20
184184 template <class T>
185 basic_string& append(const T& t); // C++17
186 basic_string& append(const basic_string& str, size_type pos, size_type n=npos); //C++14
185 basic_string& append(const T& t); // C++17, constexpr since C++20
186 basic_string& append(const basic_string& str, size_type pos, size_type n=npos); // C++14, constexpr since C++20
187187 template <class T>
188 basic_string& append(const T& t, size_type pos, size_type n=npos); // C++17
189 basic_string& append(const value_type* s, size_type n);
190 basic_string& append(const value_type* s);
191 basic_string& append(size_type n, value_type c);
188 basic_string& append(const T& t, size_type pos, size_type n=npos); // C++17, constexpr since C++20
189 basic_string& append(const value_type* s, size_type n); // constexpr since C++20
190 basic_string& append(const value_type* s); // constexpr since C++20
191 basic_string& append(size_type n, value_type c); // constexpr since C++20
192192 template<class InputIterator>
193 basic_string& append(InputIterator first, InputIterator last);
194 basic_string& append(initializer_list<value_type>);
193 basic_string& append(InputIterator first, InputIterator last); // constexpr since C++20
194 basic_string& append(initializer_list<value_type>); // constexpr since C++20
195195
196 void push_back(value_type c);
197 void pop_back();
198 reference front();
199 const_reference front() const;
200 reference back();
201 const_reference back() const;
196 void push_back(value_type c); // constexpr since C++20
197 void pop_back(); // constexpr since C++20
198 reference front(); // constexpr since C++20
199 const_reference front() const; // constexpr since C++20
200 reference back(); // constexpr since C++20
201 const_reference back() const; // constexpr since C++20
202202
203 basic_string& assign(const basic_string& str);
203 basic_string& assign(const basic_string& str); // constexpr since C++20
204204 template <class T>
205 basic_string& assign(const T& t); // C++17
206 basic_string& assign(basic_string&& str);
207 basic_string& assign(const basic_string& str, size_type pos, size_type n=npos); // C++14
205 basic_string& assign(const T& t); // C++17, constexpr since C++20
206 basic_string& assign(basic_string&& str); // constexpr since C++20
207 basic_string& assign(const basic_string& str, size_type pos, size_type n=npos); // C++14, constexpr since C++20
208208 template <class T>
209 basic_string& assign(const T& t, size_type pos, size_type n=npos); // C++17
210 basic_string& assign(const value_type* s, size_type n);
211 basic_string& assign(const value_type* s);
212 basic_string& assign(size_type n, value_type c);
209 basic_string& assign(const T& t, size_type pos, size_type n=npos); // C++17, constexpr since C++20
210 basic_string& assign(const value_type* s, size_type n); // constexpr since C++20
211 basic_string& assign(const value_type* s); // constexpr since C++20
212 basic_string& assign(size_type n, value_type c); // constexpr since C++20
213213 template<class InputIterator>
214 basic_string& assign(InputIterator first, InputIterator last);
215 basic_string& assign(initializer_list<value_type>);
214 basic_string& assign(InputIterator first, InputIterator last); // constexpr since C++20
215 basic_string& assign(initializer_list<value_type>); // constexpr since C++20
216216
217 basic_string& insert(size_type pos1, const basic_string& str);
217 basic_string& insert(size_type pos1, const basic_string& str); // constexpr since C++20
218218 template <class T>
219 basic_string& insert(size_type pos1, const T& t);
219 basic_string& insert(size_type pos1, const T& t); // constexpr since C++20
220220 basic_string& insert(size_type pos1, const basic_string& str,
221 size_type pos2, size_type n);
221 size_type pos2, size_type n); // constexpr since C++20
222222 template <class T>
223 basic_string& insert(size_type pos1, const T& t, size_type pos2, size_type n); // C++17
224 basic_string& insert(size_type pos, const value_type* s, size_type n=npos); //C++14
225 basic_string& insert(size_type pos, const value_type* s);
226 basic_string& insert(size_type pos, size_type n, value_type c);
227 iterator insert(const_iterator p, value_type c);
228 iterator insert(const_iterator p, size_type n, value_type c);
223 basic_string& insert(size_type pos1, const T& t, size_type pos2, size_type n); // C++17, constexpr since C++20
224 basic_string& insert(size_type pos, const value_type* s, size_type n=npos); // C++14, constexpr since C++20
225 basic_string& insert(size_type pos, const value_type* s); // constexpr since C++20
226 basic_string& insert(size_type pos, size_type n, value_type c); // constexpr since C++20
227 iterator insert(const_iterator p, value_type c); // constexpr since C++20
228 iterator insert(const_iterator p, size_type n, value_type c); // constexpr since C++20
229229 template<class InputIterator>
230 iterator insert(const_iterator p, InputIterator first, InputIterator last);
231 iterator insert(const_iterator p, initializer_list<value_type>);
230 iterator insert(const_iterator p, InputIterator first, InputIterator last); // constexpr since C++20
231 iterator insert(const_iterator p, initializer_list<value_type>); // constexpr since C++20
232232
233 basic_string& erase(size_type pos = 0, size_type n = npos);
234 iterator erase(const_iterator position);
235 iterator erase(const_iterator first, const_iterator last);
233 basic_string& erase(size_type pos = 0, size_type n = npos); // constexpr since C++20
234 iterator erase(const_iterator position); // constexpr since C++20
235 iterator erase(const_iterator first, const_iterator last); // constexpr since C++20
236236
237 basic_string& replace(size_type pos1, size_type n1, const basic_string& str);
237 basic_string& replace(size_type pos1, size_type n1, const basic_string& str); // constexpr since C++20
238238 template <class T>
239 basic_string& replace(size_type pos1, size_type n1, const T& t); // C++17
239 basic_string& replace(size_type pos1, size_type n1, const T& t); // C++17, constexpr since C++20
240240 basic_string& replace(size_type pos1, size_type n1, const basic_string& str,
241 size_type pos2, size_type n2=npos); // C++14
241 size_type pos2, size_type n2=npos); // C++14, constexpr since C++20
242242 template <class T>
243243 basic_string& replace(size_type pos1, size_type n1, const T& t,
244 size_type pos2, size_type n); // C++17
245 basic_string& replace(size_type pos, size_type n1, const value_type* s, size_type n2);
246 basic_string& replace(size_type pos, size_type n1, const value_type* s);
247 basic_string& replace(size_type pos, size_type n1, size_type n2, value_type c);
248 basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str);
244 size_type pos2, size_type n); // C++17, constexpr since C++20
245 basic_string& replace(size_type pos, size_type n1, const value_type* s, size_type n2); // constexpr since C++20
246 basic_string& replace(size_type pos, size_type n1, const value_type* s); // constexpr since C++20
247 basic_string& replace(size_type pos, size_type n1, size_type n2, value_type c); // constexpr since C++20
248 basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str); // constexpr since C++20
249249 template <class T>
250 basic_string& replace(const_iterator i1, const_iterator i2, const T& t); // C++17
251 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s, size_type n);
252 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s);
253 basic_string& replace(const_iterator i1, const_iterator i2, size_type n, value_type c);
250 basic_string& replace(const_iterator i1, const_iterator i2, const T& t); // C++17, constexpr since C++20
251 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s, size_type n); // constexpr since C++20
252 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s); // constexpr since C++20
253 basic_string& replace(const_iterator i1, const_iterator i2, size_type n, value_type c); // constexpr since C++20
254254 template<class InputIterator>
255 basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2);
256 basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<value_type>);
255 basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2); // constexpr since C++20
256 basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<value_type>); // constexpr since C++20
257257
258 size_type copy(value_type* s, size_type n, size_type pos = 0) const;
259 basic_string substr(size_type pos = 0, size_type n = npos) const;
258 size_type copy(value_type* s, size_type n, size_type pos = 0) const; // constexpr since C++20
259 basic_string substr(size_type pos = 0, size_type n = npos) const; // constexpr since C++20
260260
261261 void swap(basic_string& str)
262262 noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
263 allocator_traits<allocator_type>::is_always_equal::value); // C++17
263 allocator_traits<allocator_type>::is_always_equal::value); // C++17, constexpr since C++20
264264
265 const value_type* c_str() const noexcept;
266 const value_type* data() const noexcept;
267 value_type* data() noexcept; // C++17
265 const value_type* c_str() const noexcept; // constexpr since C++20
266 const value_type* data() const noexcept; // constexpr since C++20
267 value_type* data() noexcept; // C++17, constexpr since C++20
268268
269 allocator_type get_allocator() const noexcept;
269 allocator_type get_allocator() const noexcept; // constexpr since C++20
270270
271 size_type find(const basic_string& str, size_type pos = 0) const noexcept;
271 size_type find(const basic_string& str, size_type pos = 0) const noexcept; // constexpr since C++20
272272 template <class T>
273 size_type find(const T& t, size_type pos = 0) const noexcept; // C++17, noexcept as an extension
274 size_type find(const value_type* s, size_type pos, size_type n) const noexcept;
275 size_type find(const value_type* s, size_type pos = 0) const noexcept;
276 size_type find(value_type c, size_type pos = 0) const noexcept;
273 size_type find(const T& t, size_type pos = 0) const noexcept; // C++17, noexcept as an extension, constexpr since C++20
274 size_type find(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20
275 size_type find(const value_type* s, size_type pos = 0) const noexcept; // constexpr since C++20
276 size_type find(value_type c, size_type pos = 0) const noexcept; // constexpr since C++20
277277
278 size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;
278 size_type rfind(const basic_string& str, size_type pos = npos) const noexcept; // constexpr since C++20
279279 template <class T>
280 size_type rfind(const T& t, size_type pos = npos) const noexcept; // C++17, noexcept as an extension
281 size_type rfind(const value_type* s, size_type pos, size_type n) const noexcept;
282 size_type rfind(const value_type* s, size_type pos = npos) const noexcept;
283 size_type rfind(value_type c, size_type pos = npos) const noexcept;
280 size_type rfind(const T& t, size_type pos = npos) const noexcept; // C++17, noexcept as an extension, constexpr since C++20
281 size_type rfind(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20
282 size_type rfind(const value_type* s, size_type pos = npos) const noexcept; // constexpr since C++20
283 size_type rfind(value_type c, size_type pos = npos) const noexcept; // constexpr since C++20
284284
285 size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept;
285 size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept; // constexpr since C++20
286286 template <class T>
287 size_type find_first_of(const T& t, size_type pos = 0) const noexcept; // C++17, noexcept as an extension
288 size_type find_first_of(const value_type* s, size_type pos, size_type n) const noexcept;
289 size_type find_first_of(const value_type* s, size_type pos = 0) const noexcept;
290 size_type find_first_of(value_type c, size_type pos = 0) const noexcept;
287 size_type find_first_of(const T& t, size_type pos = 0) const noexcept; // C++17, noexcept as an extension, constexpr since C++20
288 size_type find_first_of(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20
289 size_type find_first_of(const value_type* s, size_type pos = 0) const noexcept; // constexpr since C++20
290 size_type find_first_of(value_type c, size_type pos = 0) const noexcept; // constexpr since C++20
291291
292 size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept;
292 size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept; // constexpr since C++20
293293 template <class T>
294 size_type find_last_of(const T& t, size_type pos = npos) const noexcept noexcept; // C++17, noexcept as an extension
295 size_type find_last_of(const value_type* s, size_type pos, size_type n) const noexcept;
296 size_type find_last_of(const value_type* s, size_type pos = npos) const noexcept;
297 size_type find_last_of(value_type c, size_type pos = npos) const noexcept;
294 size_type find_last_of(const T& t, size_type pos = npos) const noexcept noexcept; // C++17, noexcept as an extension, constexpr since C++20
295 size_type find_last_of(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20
296 size_type find_last_of(const value_type* s, size_type pos = npos) const noexcept; // constexpr since C++20
297 size_type find_last_of(value_type c, size_type pos = npos) const noexcept; // constexpr since C++20
298298
299 size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept;
299 size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept; // constexpr since C++20
300300 template <class T>
301 size_type find_first_not_of(const T& t, size_type pos = 0) const noexcept; // C++17, noexcept as an extension
302 size_type find_first_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
303 size_type find_first_not_of(const value_type* s, size_type pos = 0) const noexcept;
304 size_type find_first_not_of(value_type c, size_type pos = 0) const noexcept;
301 size_type find_first_not_of(const T& t, size_type pos = 0) const noexcept; // C++17, noexcept as an extension, constexpr since C++20
302 size_type find_first_not_of(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20
303 size_type find_first_not_of(const value_type* s, size_type pos = 0) const noexcept; // constexpr since C++20
304 size_type find_first_not_of(value_type c, size_type pos = 0) const noexcept; // constexpr since C++20
305305
306 size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept;
306 size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept; // constexpr since C++20
307307 template <class T>
308 size_type find_last_not_of(const T& t, size_type pos = npos) const noexcept; // C++17, noexcept as an extension
309 size_type find_last_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
310 size_type find_last_not_of(const value_type* s, size_type pos = npos) const noexcept;
311 size_type find_last_not_of(value_type c, size_type pos = npos) const noexcept;
308 size_type find_last_not_of(const T& t, size_type pos = npos) const noexcept; // C++17, noexcept as an extension, constexpr since C++20
309 size_type find_last_not_of(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20
310 size_type find_last_not_of(const value_type* s, size_type pos = npos) const noexcept; // constexpr since C++20
311 size_type find_last_not_of(value_type c, size_type pos = npos) const noexcept; // constexpr since C++20
312312
313 int compare(const basic_string& str) const noexcept;
313 int compare(const basic_string& str) const noexcept; // constexpr since C++20
314314 template <class T>
315 int compare(const T& t) const noexcept; // C++17, noexcept as an extension
316 int compare(size_type pos1, size_type n1, const basic_string& str) const;
315 int compare(const T& t) const noexcept; // C++17, noexcept as an extension, constexpr since C++20
316 int compare(size_type pos1, size_type n1, const basic_string& str) const; // constexpr since C++20
317317 template <class T>
318 int compare(size_type pos1, size_type n1, const T& t) const; // C++17
318 int compare(size_type pos1, size_type n1, const T& t) const; // C++17, constexpr since C++20
319319 int compare(size_type pos1, size_type n1, const basic_string& str,
320 size_type pos2, size_type n2=npos) const; // C++14
320 size_type pos2, size_type n2=npos) const; // C++14, constexpr since C++20
321321 template <class T>
322322 int compare(size_type pos1, size_type n1, const T& t,
323 size_type pos2, size_type n2=npos) const; // C++17
324 int compare(const value_type* s) const noexcept;
325 int compare(size_type pos1, size_type n1, const value_type* s) const;
326 int compare(size_type pos1, size_type n1, const value_type* s, size_type n2) const;
327
328 bool starts_with(basic_string_view<charT, traits> sv) const noexcept; // C++20
329 bool starts_with(charT c) const noexcept; // C++20
330 bool starts_with(const charT* s) const; // C++20
331 bool ends_with(basic_string_view<charT, traits> sv) const noexcept; // C++20
332 bool ends_with(charT c) const noexcept; // C++20
333 bool ends_with(const charT* s) const; // C++20
334
335 constexpr bool contains(basic_string_view<charT, traits> sv) const noexcept; // C++2b
336 constexpr bool contains(charT c) const noexcept; // C++2b
337 constexpr bool contains(const charT* s) const; // C++2b
338
339 bool __invariants() const;
323 size_type pos2, size_type n2=npos) const; // C++17, constexpr since C++20
324 int compare(const value_type* s) const noexcept; // constexpr since C++20
325 int compare(size_type pos1, size_type n1, const value_type* s) const; // constexpr since C++20
326 int compare(size_type pos1, size_type n1, const value_type* s, size_type n2) const; // constexpr since C++20
327
328 constexpr bool starts_with(basic_string_view<charT, traits> sv) const noexcept; // C++20
329 constexpr bool starts_with(charT c) const noexcept; // C++20
330 constexpr bool starts_with(const charT* s) const; // C++20
331 constexpr bool ends_with(basic_string_view<charT, traits> sv) const noexcept; // C++20
332 constexpr bool ends_with(charT c) const noexcept; // C++20
333 constexpr bool ends_with(const charT* s) const; // C++20
334
335 constexpr bool contains(basic_string_view<charT, traits> sv) const noexcept; // C++2b
336 constexpr bool contains(charT c) const noexcept; // C++2b
337 constexpr bool contains(const charT* s) const; // C++2b
340338};
341339
342340template<class InputIterator,
......@@ -349,88 +347,88 @@ basic_string(InputIterator, InputIterator, Allocator = Allocator())
349347template<class charT, class traits, class Allocator>
350348basic_string<charT, traits, Allocator>
351349operator+(const basic_string<charT, traits, Allocator>& lhs,
352 const basic_string<charT, traits, Allocator>& rhs);
350 const basic_string<charT, traits, Allocator>& rhs); // constexpr since C++20
353351
354352template<class charT, class traits, class Allocator>
355353basic_string<charT, traits, Allocator>
356operator+(const charT* lhs , const basic_string<charT,traits,Allocator>&rhs);
354operator+(const charT* lhs , const basic_string<charT,traits,Allocator>&rhs); // constexpr since C++20
357355
358356template<class charT, class traits, class Allocator>
359357basic_string<charT, traits, Allocator>
360operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs);
358operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs); // constexpr since C++20
361359
362360template<class charT, class traits, class Allocator>
363361basic_string<charT, traits, Allocator>
364operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);
362operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs); // constexpr since C++20
365363
366364template<class charT, class traits, class Allocator>
367365basic_string<charT, traits, Allocator>
368operator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs);
366operator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs); // constexpr since C++20
369367
370368template<class charT, class traits, class Allocator>
371369bool operator==(const basic_string<charT, traits, Allocator>& lhs,
372 const basic_string<charT, traits, Allocator>& rhs) noexcept;
370 const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20
373371
374372template<class charT, class traits, class Allocator>
375bool operator==(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
373bool operator==(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20
376374
377375template<class charT, class traits, class Allocator>
378bool operator==(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs) noexcept;
376bool operator==(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs) noexcept; // constexpr since C++20
379377
380378template<class charT, class traits, class Allocator>
381379bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
382 const basic_string<charT, traits, Allocator>& rhs) noexcept;
380 const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20
383381
384382template<class charT, class traits, class Allocator>
385bool operator!=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
383bool operator!=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20
386384
387385template<class charT, class traits, class Allocator>
388bool operator!=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
386bool operator!=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; // constexpr since C++20
389387
390388template<class charT, class traits, class Allocator>
391389bool operator< (const basic_string<charT, traits, Allocator>& lhs,
392 const basic_string<charT, traits, Allocator>& rhs) noexcept;
390 const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20
393391
394392template<class charT, class traits, class Allocator>
395bool operator< (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
393bool operator< (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; // constexpr since C++20
396394
397395template<class charT, class traits, class Allocator>
398bool operator< (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
396bool operator< (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20
399397
400398template<class charT, class traits, class Allocator>
401399bool operator> (const basic_string<charT, traits, Allocator>& lhs,
402 const basic_string<charT, traits, Allocator>& rhs) noexcept;
400 const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20
403401
404402template<class charT, class traits, class Allocator>
405bool operator> (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
403bool operator> (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; // constexpr since C++20
406404
407405template<class charT, class traits, class Allocator>
408bool operator> (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
406bool operator> (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20
409407
410408template<class charT, class traits, class Allocator>
411409bool operator<=(const basic_string<charT, traits, Allocator>& lhs,
412 const basic_string<charT, traits, Allocator>& rhs) noexcept;
410 const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20
413411
414412template<class charT, class traits, class Allocator>
415bool operator<=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
413bool operator<=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; // constexpr since C++20
416414
417415template<class charT, class traits, class Allocator>
418bool operator<=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
416bool operator<=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20
419417
420418template<class charT, class traits, class Allocator>
421419bool operator>=(const basic_string<charT, traits, Allocator>& lhs,
422 const basic_string<charT, traits, Allocator>& rhs) noexcept;
420 const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20
423421
424422template<class charT, class traits, class Allocator>
425bool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
423bool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; // constexpr since C++20
426424
427425template<class charT, class traits, class Allocator>
428bool operator>=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
426bool operator>=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20
429427
430428template<class charT, class traits, class Allocator>
431429void swap(basic_string<charT, traits, Allocator>& lhs,
432430 basic_string<charT, traits, Allocator>& rhs)
433 noexcept(noexcept(lhs.swap(rhs)));
431 noexcept(noexcept(lhs.swap(rhs))); // constexpr since C++20
434432
435433template<class charT, class traits, class Allocator>
436434basic_istream<charT, traits>&
......@@ -508,45 +506,81 @@ template <> struct hash<u16string>;
508506template <> struct hash<u32string>;
509507template <> struct hash<wstring>;
510508
511basic_string<char> operator "" s( const char *str, size_t len ); // C++14
512basic_string<wchar_t> operator "" s( const wchar_t *str, size_t len ); // C++14
513basic_string<char8_t> operator "" s( const char8_t *str, size_t len ); // C++20
514basic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14
515basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++14
509basic_string<char> operator "" s( const char *str, size_t len ); // C++14, constexpr since C++20
510basic_string<wchar_t> operator "" s( const wchar_t *str, size_t len ); // C++14, constexpr since C++20
511constexpr basic_string<char8_t> operator "" s( const char8_t *str, size_t len ); // C++20
512basic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14, constexpr since C++20
513basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++14, constexpr since C++20
516514
517515} // std
518516
519517*/
520518
519#include <__algorithm/max.h>
520#include <__algorithm/min.h>
521#include <__algorithm/remove.h>
522#include <__algorithm/remove_if.h>
523#include <__assert> // all public C++ headers provide the assertion handler
521524#include <__config>
522525#include <__debug>
523#include <__functional_base>
526#include <__format/enable_insertable.h>
527#include <__functional/hash.h>
528#include <__functional/unary_function.h>
529#include <__ios/fpos.h>
530#include <__iterator/distance.h>
531#include <__iterator/iterator_traits.h>
532#include <__iterator/reverse_iterator.h>
524533#include <__iterator/wrap_iter.h>
525#include <algorithm>
526#include <compare>
534#include <__memory/allocate_at_least.h>
535#include <__memory/swap_allocator.h>
536#include <__string/char_traits.h>
537#include <__string/extern_template_lists.h>
538#include <__utility/auto_cast.h>
539#include <__utility/move.h>
540#include <__utility/swap.h>
541#include <__utility/unreachable.h>
542#include <climits>
543#include <cstdint>
527544#include <cstdio> // EOF
528545#include <cstdlib>
529546#include <cstring>
530#include <initializer_list>
531547#include <iosfwd>
532#include <iterator>
548#include <limits>
533549#include <memory>
534550#include <stdexcept>
535551#include <string_view>
536552#include <type_traits>
537#include <utility>
538553#include <version>
539554
540555#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
541# include <cwchar>
556# include <cwchar>
542557#endif
543558
544#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
545# include <cstdint>
559#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
560# include <algorithm>
561# include <functional>
562# include <iterator>
563# include <new>
564# include <typeinfo>
565# include <utility>
566# include <vector>
546567#endif
547568
569// standard-mandated includes
570
571// [iterator.range]
572#include <__iterator/access.h>
573#include <__iterator/data.h>
574#include <__iterator/empty.h>
575#include <__iterator/reverse_access.h>
576#include <__iterator/size.h>
577
578// [string.syn]
579#include <compare>
580#include <initializer_list>
581
548582#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
549#pragma GCC system_header
583# pragma GCC system_header
550584#endif
551585
552586_LIBCPP_PUSH_MACROS
......@@ -555,68 +589,35 @@ _LIBCPP_PUSH_MACROS
555589
556590_LIBCPP_BEGIN_NAMESPACE_STD
557591
558// fpos
559
560template <class _StateT>
561class _LIBCPP_TEMPLATE_VIS fpos
562{
563private:
564 _StateT __st_;
565 streamoff __off_;
566public:
567 _LIBCPP_INLINE_VISIBILITY fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {}
568
569 _LIBCPP_INLINE_VISIBILITY operator streamoff() const {return __off_;}
570
571 _LIBCPP_INLINE_VISIBILITY _StateT state() const {return __st_;}
572 _LIBCPP_INLINE_VISIBILITY void state(_StateT __st) {__st_ = __st;}
573
574 _LIBCPP_INLINE_VISIBILITY fpos& operator+=(streamoff __off) {__off_ += __off; return *this;}
575 _LIBCPP_INLINE_VISIBILITY fpos operator+ (streamoff __off) const {fpos __t(*this); __t += __off; return __t;}
576 _LIBCPP_INLINE_VISIBILITY fpos& operator-=(streamoff __off) {__off_ -= __off; return *this;}
577 _LIBCPP_INLINE_VISIBILITY fpos operator- (streamoff __off) const {fpos __t(*this); __t -= __off; return __t;}
578};
579
580template <class _StateT>
581inline _LIBCPP_INLINE_VISIBILITY
582streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
583 {return streamoff(__x) - streamoff(__y);}
584
585template <class _StateT>
586inline _LIBCPP_INLINE_VISIBILITY
587bool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
588 {return streamoff(__x) == streamoff(__y);}
589
590template <class _StateT>
591inline _LIBCPP_INLINE_VISIBILITY
592bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
593 {return streamoff(__x) != streamoff(__y);}
594
595592// basic_string
596593
597594template<class _CharT, class _Traits, class _Allocator>
598595basic_string<_CharT, _Traits, _Allocator>
596_LIBCPP_CONSTEXPR_AFTER_CXX17
599597operator+(const basic_string<_CharT, _Traits, _Allocator>& __x,
600598 const basic_string<_CharT, _Traits, _Allocator>& __y);
601599
602600template<class _CharT, class _Traits, class _Allocator>
601_LIBCPP_CONSTEXPR_AFTER_CXX17
603602basic_string<_CharT, _Traits, _Allocator>
604603operator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
605604
606605template<class _CharT, class _Traits, class _Allocator>
606_LIBCPP_CONSTEXPR_AFTER_CXX17
607607basic_string<_CharT, _Traits, _Allocator>
608608operator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
609609
610610template<class _CharT, class _Traits, class _Allocator>
611inline _LIBCPP_INLINE_VISIBILITY
611inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
612612basic_string<_CharT, _Traits, _Allocator>
613613operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y);
614614
615615template<class _CharT, class _Traits, class _Allocator>
616_LIBCPP_CONSTEXPR_AFTER_CXX17
616617basic_string<_CharT, _Traits, _Allocator>
617618operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
618619
619_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&))
620extern template _LIBCPP_FUNC_VIS string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&);
620621
621622template <class _Iter>
622623struct __string_is_trivial_iterator : public false_type {};
......@@ -635,29 +636,13 @@ struct __can_be_converted_to_string_view : public _BoolConstant<
635636 !is_convertible<const _Tp&, const _CharT*>::value
636637 > {};
637638
638#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
639
640template <class _CharT, size_t = sizeof(_CharT)>
641struct __padding
642{
643 unsigned char __xx[sizeof(_CharT)-1];
644};
645
646template <class _CharT>
647struct __padding<_CharT, 1>
648{
649};
650
651#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
652
653639#ifndef _LIBCPP_HAS_NO_CHAR8_T
654640typedef basic_string<char8_t> u8string;
655641#endif
656
657#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
658642typedef basic_string<char16_t> u16string;
659643typedef basic_string<char32_t> u32string;
660#endif
644
645struct __uninitialized_size_tag {};
661646
662647template<class _CharT, class _Traits, class _Allocator>
663648class
......@@ -665,10 +650,8 @@ class
665650#ifndef _LIBCPP_HAS_NO_CHAR8_T
666651 _LIBCPP_PREFERRED_NAME(u8string)
667652#endif
668#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
669653 _LIBCPP_PREFERRED_NAME(u16string)
670654 _LIBCPP_PREFERRED_NAME(u32string)
671#endif
672655 basic_string
673656{
674657public:
......@@ -695,10 +678,11 @@ public:
695678
696679 typedef __wrap_iter<pointer> iterator;
697680 typedef __wrap_iter<const_pointer> const_iterator;
698 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
699 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
681 typedef std::reverse_iterator<iterator> reverse_iterator;
682 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
700683
701684private:
685 static_assert(CHAR_BIT == 8, "This implementation assumes that one byte contains 8 bits");
702686
703687#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
704688
......@@ -706,62 +690,79 @@ private:
706690 {
707691 pointer __data_;
708692 size_type __size_;
709 size_type __cap_;
693 size_type __cap_ : sizeof(size_type) * CHAR_BIT - 1;
694 size_type __is_long_ : 1;
710695 };
711696
712#ifdef _LIBCPP_BIG_ENDIAN
713 static const size_type __short_mask = 0x01;
714 static const size_type __long_mask = 0x1ul;
715#else // _LIBCPP_BIG_ENDIAN
716 static const size_type __short_mask = 0x80;
717 static const size_type __long_mask = ~(size_type(~0) >> 1);
718#endif // _LIBCPP_BIG_ENDIAN
719
720697 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
721698 (sizeof(__long) - 1)/sizeof(value_type) : 2};
722699
723700 struct __short
724701 {
725702 value_type __data_[__min_cap];
726 struct
727 : __padding<value_type>
728 {
729 unsigned char __size_;
730 };
703 unsigned char __padding_[sizeof(value_type) - 1];
704 unsigned char __size_ : 7;
705 unsigned char __is_long_ : 1;
731706 };
732707
708// The __endian_factor is required because the field we use to store the size
709// has one fewer bit than it would if it were not a bitfield.
710//
711// If the LSB is used to store the short-flag in the short string representation,
712// we have to multiply the size by two when it is stored and divide it by two when
713// it is loaded to make sure that we always store an even number. In the long string
714// representation, we can ignore this because we can assume that we always allocate
715// an even amount of value_types.
716//
717// If the MSB is used for the short-flag, the max_size() is numeric_limits<size_type>::max() / 2.
718// This does not impact the short string representation, since we never need the MSB
719// for representing the size of a short string anyway.
720
721#ifdef _LIBCPP_BIG_ENDIAN
722 static const size_type __endian_factor = 2;
733723#else
724 static const size_type __endian_factor = 1;
725#endif
734726
727#else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
728
729#ifdef _LIBCPP_BIG_ENDIAN
730 static const size_type __endian_factor = 1;
731#else
732 static const size_type __endian_factor = 2;
733#endif
734
735 // Attribute 'packed' is used to keep the layout compatible with the
736 // previous definition that did not use bit fields. This is because on
737 // some platforms bit fields have a default size rather than the actual
738 // size used, e.g., it is 4 bytes on AIX. See D128285 for details.
735739 struct __long
736740 {
737 size_type __cap_;
741 struct _LIBCPP_PACKED {
742 size_type __is_long_ : 1;
743 size_type __cap_ : sizeof(size_type) * CHAR_BIT - 1;
744 };
738745 size_type __size_;
739746 pointer __data_;
740747 };
741748
742#ifdef _LIBCPP_BIG_ENDIAN
743 static const size_type __short_mask = 0x80;
744 static const size_type __long_mask = ~(size_type(~0) >> 1);
745#else // _LIBCPP_BIG_ENDIAN
746 static const size_type __short_mask = 0x01;
747 static const size_type __long_mask = 0x1ul;
748#endif // _LIBCPP_BIG_ENDIAN
749
750749 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
751750 (sizeof(__long) - 1)/sizeof(value_type) : 2};
752751
753752 struct __short
754753 {
755 union
756 {
757 unsigned char __size_;
758 value_type __lx;
754 struct _LIBCPP_PACKED {
755 unsigned char __is_long_ : 1;
756 unsigned char __size_ : 7;
759757 };
758 char __padding_[sizeof(value_type) - 1];
760759 value_type __data_[__min_cap];
761760 };
762761
763762#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
764763
764 static_assert(sizeof(__short) == (sizeof(value_type) * (__min_cap + 1)), "__short has an unexpected size.");
765
765766 union __ulx{__long __lx; __short __lxx;};
766767
767768 enum {__n_words = sizeof(__ulx) / sizeof(size_type)};
......@@ -783,25 +784,47 @@ private:
783784
784785 __compressed_pair<__rep, allocator_type> __r_;
785786
787 // Construct a string with the given allocator and enough storage to hold `__size` characters, but
788 // don't initialize the characters. The contents of the string, including the null terminator, must be
789 // initialized separately.
790 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
791 explicit basic_string(__uninitialized_size_tag, size_type __size, const allocator_type& __a)
792 : __r_(__default_init_tag(), __a) {
793 if (__size > max_size())
794 __throw_length_error();
795 if (__fits_in_sso(__size)) {
796 __zero();
797 __set_short_size(__size);
798 } else {
799 auto __capacity = __recommend(__size) + 1;
800 auto __allocation = __alloc_traits::allocate(__alloc(), __capacity);
801 __begin_lifetime(__allocation, __capacity);
802 __set_long_cap(__capacity);
803 __set_long_pointer(__allocation);
804 __set_long_size(__size);
805 }
806 std::__debug_db_insert_c(this);
807 }
808
786809public:
787810 _LIBCPP_TEMPLATE_DATA_VIS
788811 static const size_type npos = -1;
789812
790 _LIBCPP_INLINE_VISIBILITY basic_string()
813 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string()
791814 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
792815
793 _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a)
816 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit basic_string(const allocator_type& __a)
794817#if _LIBCPP_STD_VER <= 14
795818 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
796819#else
797820 _NOEXCEPT;
798821#endif
799822
800 basic_string(const basic_string& __str);
801 basic_string(const basic_string& __str, const allocator_type& __a);
823 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string(const basic_string& __str);
824 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string(const basic_string& __str, const allocator_type& __a);
802825
803826#ifndef _LIBCPP_CXX03_LANG
804 _LIBCPP_INLINE_VISIBILITY
827 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
805828 basic_string(basic_string&& __str)
806829#if _LIBCPP_STD_VER <= 14
807830 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
......@@ -809,218 +832,221 @@ public:
809832 _NOEXCEPT;
810833#endif
811834
812 _LIBCPP_INLINE_VISIBILITY
835 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
813836 basic_string(basic_string&& __str, const allocator_type& __a);
814837#endif // _LIBCPP_CXX03_LANG
815838
816839 template <class = __enable_if_t<__is_allocator<_Allocator>::value, nullptr_t> >
817 _LIBCPP_INLINE_VISIBILITY
840 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
818841 basic_string(const _CharT* __s) : __r_(__default_init_tag(), __default_init_tag()) {
819842 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
820843 __init(__s, traits_type::length(__s));
821 _VSTD::__debug_db_insert_c(this);
844 std::__debug_db_insert_c(this);
822845 }
823846
824847 template <class = __enable_if_t<__is_allocator<_Allocator>::value, nullptr_t> >
825 _LIBCPP_INLINE_VISIBILITY
848 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
826849 basic_string(const _CharT* __s, const _Allocator& __a);
827850
828851#if _LIBCPP_STD_VER > 20
829852 basic_string(nullptr_t) = delete;
830853#endif
831854
832 _LIBCPP_INLINE_VISIBILITY
855 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
833856 basic_string(const _CharT* __s, size_type __n);
834 _LIBCPP_INLINE_VISIBILITY
857 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
835858 basic_string(const _CharT* __s, size_type __n, const _Allocator& __a);
836 _LIBCPP_INLINE_VISIBILITY
859 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
837860 basic_string(size_type __n, _CharT __c);
838861
839862 template <class = __enable_if_t<__is_allocator<_Allocator>::value, nullptr_t> >
840 _LIBCPP_INLINE_VISIBILITY
863 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
841864 basic_string(size_type __n, _CharT __c, const _Allocator& __a);
842865
866 _LIBCPP_CONSTEXPR_AFTER_CXX17
843867 basic_string(const basic_string& __str, size_type __pos, size_type __n,
844868 const _Allocator& __a = _Allocator());
845 _LIBCPP_INLINE_VISIBILITY
869 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
846870 basic_string(const basic_string& __str, size_type __pos,
847871 const _Allocator& __a = _Allocator());
848872
849873 template<class _Tp, class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value> >
850 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
874 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
851875 basic_string(const _Tp& __t, size_type __pos, size_type __n,
852876 const allocator_type& __a = allocator_type());
853877
854878 template<class _Tp, class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
855879 !__is_same_uncvref<_Tp, basic_string>::value> >
856 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
880 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
857881 explicit basic_string(const _Tp& __t);
858882
859883 template<class _Tp, class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value> >
860 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
884 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
861885 explicit basic_string(const _Tp& __t, const allocator_type& __a);
862886
863887 template<class _InputIterator, class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value> >
864 _LIBCPP_INLINE_VISIBILITY
888 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
865889 basic_string(_InputIterator __first, _InputIterator __last);
866890 template<class _InputIterator, class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value> >
867 _LIBCPP_INLINE_VISIBILITY
891 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
868892 basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
869893#ifndef _LIBCPP_CXX03_LANG
870 _LIBCPP_INLINE_VISIBILITY
894 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
871895 basic_string(initializer_list<_CharT> __il);
872 _LIBCPP_INLINE_VISIBILITY
896 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
873897 basic_string(initializer_list<_CharT> __il, const _Allocator& __a);
874898#endif // _LIBCPP_CXX03_LANG
875899
876 inline ~basic_string();
900 inline _LIBCPP_CONSTEXPR_AFTER_CXX17 ~basic_string();
877901
878 _LIBCPP_INLINE_VISIBILITY
902 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
879903 operator __self_view() const _NOEXCEPT { return __self_view(data(), size()); }
880904
881 basic_string& operator=(const basic_string& __str);
905 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& operator=(const basic_string& __str);
882906
883 template <class _Tp, class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value> >
884 basic_string& operator=(const _Tp& __t)
885 {__self_view __sv = __t; return assign(__sv);}
907 template <class _Tp, class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
908 !__is_same_uncvref<_Tp, basic_string>::value> >
909 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& operator=(const _Tp& __t) {
910 __self_view __sv = __t;
911 return assign(__sv);
912 }
886913
887914#ifndef _LIBCPP_CXX03_LANG
888 _LIBCPP_INLINE_VISIBILITY
915 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
889916 basic_string& operator=(basic_string&& __str)
890917 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
891 _LIBCPP_INLINE_VISIBILITY
918 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
892919 basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
893920#endif
894 _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);}
921 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
922 basic_string& operator=(const value_type* __s) {return assign(__s);}
895923#if _LIBCPP_STD_VER > 20
896924 basic_string& operator=(nullptr_t) = delete;
897925#endif
898 basic_string& operator=(value_type __c);
926 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& operator=(value_type __c);
899927
900#if _LIBCPP_DEBUG_LEVEL == 2
901 _LIBCPP_INLINE_VISIBILITY
928 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
902929 iterator begin() _NOEXCEPT
903930 {return iterator(this, __get_pointer());}
904 _LIBCPP_INLINE_VISIBILITY
931 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
905932 const_iterator begin() const _NOEXCEPT
906933 {return const_iterator(this, __get_pointer());}
907 _LIBCPP_INLINE_VISIBILITY
934 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
908935 iterator end() _NOEXCEPT
909936 {return iterator(this, __get_pointer() + size());}
910 _LIBCPP_INLINE_VISIBILITY
937 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
911938 const_iterator end() const _NOEXCEPT
912939 {return const_iterator(this, __get_pointer() + size());}
913#else
914 _LIBCPP_INLINE_VISIBILITY
915 iterator begin() _NOEXCEPT
916 {return iterator(__get_pointer());}
917 _LIBCPP_INLINE_VISIBILITY
918 const_iterator begin() const _NOEXCEPT
919 {return const_iterator(__get_pointer());}
920 _LIBCPP_INLINE_VISIBILITY
921 iterator end() _NOEXCEPT
922 {return iterator(__get_pointer() + size());}
923 _LIBCPP_INLINE_VISIBILITY
924 const_iterator end() const _NOEXCEPT
925 {return const_iterator(__get_pointer() + size());}
926#endif // _LIBCPP_DEBUG_LEVEL == 2
927 _LIBCPP_INLINE_VISIBILITY
940
941 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
928942 reverse_iterator rbegin() _NOEXCEPT
929943 {return reverse_iterator(end());}
930 _LIBCPP_INLINE_VISIBILITY
944 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
931945 const_reverse_iterator rbegin() const _NOEXCEPT
932946 {return const_reverse_iterator(end());}
933 _LIBCPP_INLINE_VISIBILITY
947 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
934948 reverse_iterator rend() _NOEXCEPT
935949 {return reverse_iterator(begin());}
936 _LIBCPP_INLINE_VISIBILITY
950 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
937951 const_reverse_iterator rend() const _NOEXCEPT
938952 {return const_reverse_iterator(begin());}
939953
940 _LIBCPP_INLINE_VISIBILITY
954 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
941955 const_iterator cbegin() const _NOEXCEPT
942956 {return begin();}
943 _LIBCPP_INLINE_VISIBILITY
957 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
944958 const_iterator cend() const _NOEXCEPT
945959 {return end();}
946 _LIBCPP_INLINE_VISIBILITY
960 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
947961 const_reverse_iterator crbegin() const _NOEXCEPT
948962 {return rbegin();}
949 _LIBCPP_INLINE_VISIBILITY
963 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
950964 const_reverse_iterator crend() const _NOEXCEPT
951965 {return rend();}
952966
953 _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT
967 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 size_type size() const _NOEXCEPT
954968 {return __is_long() ? __get_long_size() : __get_short_size();}
955 _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();}
956 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT;
957 _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT
958 {return (__is_long() ? __get_long_cap()
959 : static_cast<size_type>(__min_cap)) - 1;}
969 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 size_type length() const _NOEXCEPT {return size();}
970 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 size_type max_size() const _NOEXCEPT;
971 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 size_type capacity() const _NOEXCEPT {
972 return (__is_long() ? __get_long_cap() : static_cast<size_type>(__min_cap)) - 1;
973 }
960974
961 void resize(size_type __n, value_type __c);
962 _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
975 _LIBCPP_CONSTEXPR_AFTER_CXX17 void resize(size_type __n, value_type __c);
976 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 void resize(size_type __n) { resize(__n, value_type()); }
963977
964 void reserve(size_type __requested_capacity);
978 _LIBCPP_CONSTEXPR_AFTER_CXX17 void reserve(size_type __requested_capacity);
965979
966980#if _LIBCPP_STD_VER > 20
967981 template <class _Op>
968982 _LIBCPP_HIDE_FROM_ABI constexpr
969983 void resize_and_overwrite(size_type __n, _Op __op) {
970984 __resize_default_init(__n);
971 __erase_to_end(_VSTD::move(__op)(data(), _LIBCPP_AUTO_CAST(__n)));
985 __erase_to_end(std::move(__op)(data(), _LIBCPP_AUTO_CAST(__n)));
972986 }
973987#endif
974988
975 _LIBCPP_INLINE_VISIBILITY void __resize_default_init(size_type __n);
989 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 void __resize_default_init(size_type __n);
976990
977 _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_INLINE_VISIBILITY
978 void reserve() _NOEXCEPT {shrink_to_fit();}
979 _LIBCPP_INLINE_VISIBILITY
980 void shrink_to_fit() _NOEXCEPT;
981 _LIBCPP_INLINE_VISIBILITY
982 void clear() _NOEXCEPT;
983 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
991 _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_HIDE_FROM_ABI void reserve() _NOEXCEPT { shrink_to_fit(); }
992 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 void shrink_to_fit() _NOEXCEPT;
993 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 void clear() _NOEXCEPT;
994
995 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
984996 bool empty() const _NOEXCEPT {return size() == 0;}
985997
986 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const _NOEXCEPT;
987 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos) _NOEXCEPT;
998 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
999 const_reference operator[](size_type __pos) const _NOEXCEPT;
1000 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 reference operator[](size_type __pos) _NOEXCEPT;
9881001
989 const_reference at(size_type __n) const;
990 reference at(size_type __n);
1002 _LIBCPP_CONSTEXPR_AFTER_CXX17 const_reference at(size_type __n) const;
1003 _LIBCPP_CONSTEXPR_AFTER_CXX17 reference at(size_type __n);
9911004
992 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);}
1005 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& operator+=(const basic_string& __str) {
1006 return append(__str);
1007 }
9931008
9941009 template <class _Tp>
995 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1010 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
9961011 __enable_if_t
9971012 <
9981013 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
9991014 && !__is_same_uncvref<_Tp, basic_string >::value,
10001015 basic_string&
10011016 >
1002 operator+=(const _Tp& __t) {__self_view __sv = __t; return append(__sv);}
1003 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s) {return append(__s);}
1004 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;}
1017 operator+=(const _Tp& __t) {
1018 __self_view __sv = __t; return append(__sv);
1019 }
1020
1021 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& operator+=(const value_type* __s) {
1022 return append(__s);
1023 }
1024
1025 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& operator+=(value_type __c) {
1026 push_back(__c);
1027 return *this;
1028 }
1029
10051030#ifndef _LIBCPP_CXX03_LANG
1006 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
1031 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
1032 basic_string& operator+=(initializer_list<value_type> __il) { return append(__il); }
10071033#endif // _LIBCPP_CXX03_LANG
10081034
1009 _LIBCPP_INLINE_VISIBILITY
1035 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
10101036 basic_string& append(const basic_string& __str);
10111037
10121038 template <class _Tp>
1013 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1039 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
10141040 __enable_if_t<
10151041 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
10161042 && !__is_same_uncvref<_Tp, basic_string>::value,
10171043 basic_string&
10181044 >
10191045 append(const _Tp& __t) { __self_view __sv = __t; return append(__sv.data(), __sv.size()); }
1020 basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos);
1046 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos);
10211047
10221048 template <class _Tp>
1023 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1049 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
10241050 __enable_if_t
10251051 <
10261052 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
......@@ -1028,11 +1054,11 @@ public:
10281054 basic_string&
10291055 >
10301056 append(const _Tp& __t, size_type __pos, size_type __n=npos);
1031 basic_string& append(const value_type* __s, size_type __n);
1032 basic_string& append(const value_type* __s);
1033 basic_string& append(size_type __n, value_type __c);
1057 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& append(const value_type* __s, size_type __n);
1058 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& append(const value_type* __s);
1059 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& append(size_type __n, value_type __c);
10341060
1035 _LIBCPP_INLINE_VISIBILITY
1061 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
10361062 void __append_default_init(size_type __n);
10371063
10381064 template<class _InputIterator>
......@@ -1042,7 +1068,7 @@ public:
10421068 __is_exactly_cpp17_input_iterator<_InputIterator>::value,
10431069 basic_string&
10441070 >
1045 _LIBCPP_INLINE_VISIBILITY
1071 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
10461072 append(_InputIterator __first, _InputIterator __last) {
10471073 const basic_string __temp(__first, __last, __alloc());
10481074 append(__temp.data(), __temp.size());
......@@ -1055,41 +1081,40 @@ public:
10551081 __is_cpp17_forward_iterator<_ForwardIterator>::value,
10561082 basic_string&
10571083 >
1058 _LIBCPP_INLINE_VISIBILITY
1084 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
10591085 append(_ForwardIterator __first, _ForwardIterator __last);
10601086
10611087#ifndef _LIBCPP_CXX03_LANG
1062 _LIBCPP_INLINE_VISIBILITY
1088 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
10631089 basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
10641090#endif // _LIBCPP_CXX03_LANG
10651091
1066 void push_back(value_type __c);
1067 _LIBCPP_INLINE_VISIBILITY
1068 void pop_back();
1069 _LIBCPP_INLINE_VISIBILITY reference front() _NOEXCEPT;
1070 _LIBCPP_INLINE_VISIBILITY const_reference front() const _NOEXCEPT;
1071 _LIBCPP_INLINE_VISIBILITY reference back() _NOEXCEPT;
1072 _LIBCPP_INLINE_VISIBILITY const_reference back() const _NOEXCEPT;
1092 _LIBCPP_CONSTEXPR_AFTER_CXX17 void push_back(value_type __c);
1093 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 void pop_back();
1094 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 reference front() _NOEXCEPT;
1095 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 const_reference front() const _NOEXCEPT;
1096 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 reference back() _NOEXCEPT;
1097 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 const_reference back() const _NOEXCEPT;
10731098
10741099 template <class _Tp>
1075 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1100 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
10761101 __enable_if_t
10771102 <
10781103 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
10791104 basic_string&
10801105 >
10811106 assign(const _Tp & __t) { __self_view __sv = __t; return assign(__sv.data(), __sv.size()); }
1082 _LIBCPP_INLINE_VISIBILITY
1107 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
10831108 basic_string& assign(const basic_string& __str) { return *this = __str; }
10841109#ifndef _LIBCPP_CXX03_LANG
1085 _LIBCPP_INLINE_VISIBILITY
1110 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
10861111 basic_string& assign(basic_string&& __str)
10871112 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
1088 {*this = _VSTD::move(__str); return *this;}
1113 {*this = std::move(__str); return *this;}
10891114#endif
1090 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
1115 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
10911116 template <class _Tp>
1092 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1117 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
10931118 __enable_if_t
10941119 <
10951120 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
......@@ -1097,11 +1122,11 @@ public:
10971122 basic_string&
10981123 >
10991124 assign(const _Tp & __t, size_type __pos, size_type __n=npos);
1100 basic_string& assign(const value_type* __s, size_type __n);
1101 basic_string& assign(const value_type* __s);
1102 basic_string& assign(size_type __n, value_type __c);
1125 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& assign(const value_type* __s, size_type __n);
1126 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& assign(const value_type* __s);
1127 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& assign(size_type __n, value_type __c);
11031128 template<class _InputIterator>
1104 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1129 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
11051130 __enable_if_t
11061131 <
11071132 __is_exactly_cpp17_input_iterator<_InputIterator>::value,
......@@ -1109,7 +1134,7 @@ public:
11091134 >
11101135 assign(_InputIterator __first, _InputIterator __last);
11111136 template<class _ForwardIterator>
1112 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1137 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
11131138 __enable_if_t
11141139 <
11151140 __is_cpp17_forward_iterator<_ForwardIterator>::value,
......@@ -1117,15 +1142,15 @@ public:
11171142 >
11181143 assign(_ForwardIterator __first, _ForwardIterator __last);
11191144#ifndef _LIBCPP_CXX03_LANG
1120 _LIBCPP_INLINE_VISIBILITY
1145 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
11211146 basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
11221147#endif // _LIBCPP_CXX03_LANG
11231148
1124 _LIBCPP_INLINE_VISIBILITY
1149 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
11251150 basic_string& insert(size_type __pos1, const basic_string& __str);
11261151
11271152 template <class _Tp>
1128 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1153 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
11291154 __enable_if_t
11301155 <
11311156 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
......@@ -1135,22 +1160,23 @@ public:
11351160 { __self_view __sv = __t; return insert(__pos1, __sv.data(), __sv.size()); }
11361161
11371162 template <class _Tp>
1138 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1163 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
11391164 __enable_if_t
11401165 <
11411166 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value,
11421167 basic_string&
11431168 >
11441169 insert(size_type __pos1, const _Tp& __t, size_type __pos2, size_type __n=npos);
1170 _LIBCPP_CONSTEXPR_AFTER_CXX17
11451171 basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos);
1146 basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
1147 basic_string& insert(size_type __pos, const value_type* __s);
1148 basic_string& insert(size_type __pos, size_type __n, value_type __c);
1149 iterator insert(const_iterator __pos, value_type __c);
1150 _LIBCPP_INLINE_VISIBILITY
1172 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
1173 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& insert(size_type __pos, const value_type* __s);
1174 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& insert(size_type __pos, size_type __n, value_type __c);
1175 _LIBCPP_CONSTEXPR_AFTER_CXX17 iterator insert(const_iterator __pos, value_type __c);
1176 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
11511177 iterator insert(const_iterator __pos, size_type __n, value_type __c);
11521178 template<class _InputIterator>
1153 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1179 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
11541180 __enable_if_t
11551181 <
11561182 __is_exactly_cpp17_input_iterator<_InputIterator>::value,
......@@ -1158,7 +1184,7 @@ public:
11581184 >
11591185 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
11601186 template<class _ForwardIterator>
1161 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1187 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
11621188 __enable_if_t
11631189 <
11641190 __is_cpp17_forward_iterator<_ForwardIterator>::value,
......@@ -1166,45 +1192,47 @@ public:
11661192 >
11671193 insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
11681194#ifndef _LIBCPP_CXX03_LANG
1169 _LIBCPP_INLINE_VISIBILITY
1195 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
11701196 iterator insert(const_iterator __pos, initializer_list<value_type> __il)
11711197 {return insert(__pos, __il.begin(), __il.end());}
11721198#endif // _LIBCPP_CXX03_LANG
11731199
1174 basic_string& erase(size_type __pos = 0, size_type __n = npos);
1175 _LIBCPP_INLINE_VISIBILITY
1200 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& erase(size_type __pos = 0, size_type __n = npos);
1201 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
11761202 iterator erase(const_iterator __pos);
1177 _LIBCPP_INLINE_VISIBILITY
1203 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
11781204 iterator erase(const_iterator __first, const_iterator __last);
11791205
1180 _LIBCPP_INLINE_VISIBILITY
1206 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
11811207 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
11821208
11831209 template <class _Tp>
1184 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1210 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
11851211 __enable_if_t
11861212 <
11871213 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
11881214 basic_string&
11891215 >
11901216 replace(size_type __pos1, size_type __n1, const _Tp& __t) { __self_view __sv = __t; return replace(__pos1, __n1, __sv.data(), __sv.size()); }
1217 _LIBCPP_CONSTEXPR_AFTER_CXX17
11911218 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos);
11921219 template <class _Tp>
1193 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1220 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
11941221 __enable_if_t
11951222 <
11961223 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value,
11971224 basic_string&
11981225 >
11991226 replace(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos);
1227 _LIBCPP_CONSTEXPR_AFTER_CXX17
12001228 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
1201 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
1202 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
1203 _LIBCPP_INLINE_VISIBILITY
1229 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
1230 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
1231 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
12041232 basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
12051233
12061234 template <class _Tp>
1207 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1235 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
12081236 __enable_if_t
12091237 <
12101238 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
......@@ -1212,14 +1240,14 @@ public:
12121240 >
12131241 replace(const_iterator __i1, const_iterator __i2, const _Tp& __t) { __self_view __sv = __t; return replace(__i1 - begin(), __i2 - __i1, __sv); }
12141242
1215 _LIBCPP_INLINE_VISIBILITY
1243 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
12161244 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n);
1217 _LIBCPP_INLINE_VISIBILITY
1245 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
12181246 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s);
1219 _LIBCPP_INLINE_VISIBILITY
1247 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
12201248 basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
12211249 template<class _InputIterator>
1222 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1250 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
12231251 __enable_if_t
12241252 <
12251253 __is_cpp17_input_iterator<_InputIterator>::value,
......@@ -1227,16 +1255,16 @@ public:
12271255 >
12281256 replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
12291257#ifndef _LIBCPP_CXX03_LANG
1230 _LIBCPP_INLINE_VISIBILITY
1258 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
12311259 basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
12321260 {return replace(__i1, __i2, __il.begin(), __il.end());}
12331261#endif // _LIBCPP_CXX03_LANG
12341262
1235 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
1236 _LIBCPP_INLINE_VISIBILITY
1263 _LIBCPP_CONSTEXPR_AFTER_CXX17 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
1264 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
12371265 basic_string substr(size_type __pos = 0, size_type __n = npos) const;
12381266
1239 _LIBCPP_INLINE_VISIBILITY
1267 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
12401268 void swap(basic_string& __str)
12411269#if _LIBCPP_STD_VER >= 14
12421270 _NOEXCEPT;
......@@ -1245,123 +1273,129 @@ public:
12451273 __is_nothrow_swappable<allocator_type>::value);
12461274#endif
12471275
1248 _LIBCPP_INLINE_VISIBILITY
1276 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
12491277 const value_type* c_str() const _NOEXCEPT {return data();}
1250 _LIBCPP_INLINE_VISIBILITY
1251 const value_type* data() const _NOEXCEPT {return _VSTD::__to_address(__get_pointer());}
1278 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
1279 const value_type* data() const _NOEXCEPT {return std::__to_address(__get_pointer());}
12521280#if _LIBCPP_STD_VER > 14 || defined(_LIBCPP_BUILDING_LIBRARY)
1253 _LIBCPP_INLINE_VISIBILITY
1254 value_type* data() _NOEXCEPT {return _VSTD::__to_address(__get_pointer());}
1281 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
1282 value_type* data() _NOEXCEPT {return std::__to_address(__get_pointer());}
12551283#endif
12561284
1257 _LIBCPP_INLINE_VISIBILITY
1285 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
12581286 allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
12591287
1260 _LIBCPP_INLINE_VISIBILITY
1288 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
12611289 size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
12621290
12631291 template <class _Tp>
1264 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1292 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
12651293 __enable_if_t
12661294 <
12671295 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
12681296 size_type
12691297 >
12701298 find(const _Tp& __t, size_type __pos = 0) const _NOEXCEPT;
1299 _LIBCPP_CONSTEXPR_AFTER_CXX17
12711300 size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1272 _LIBCPP_INLINE_VISIBILITY
1301 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
12731302 size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
1274 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1303 _LIBCPP_CONSTEXPR_AFTER_CXX17 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
12751304
1276 _LIBCPP_INLINE_VISIBILITY
1305 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
12771306 size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
12781307
12791308 template <class _Tp>
1280 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1309 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
12811310 __enable_if_t
12821311 <
12831312 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
12841313 size_type
12851314 >
12861315 rfind(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT;
1316 _LIBCPP_CONSTEXPR_AFTER_CXX17
12871317 size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1288 _LIBCPP_INLINE_VISIBILITY
1318 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
12891319 size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
1290 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1320 _LIBCPP_CONSTEXPR_AFTER_CXX17 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
12911321
1292 _LIBCPP_INLINE_VISIBILITY
1322 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
12931323 size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
12941324
12951325 template <class _Tp>
1296 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1326 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
12971327 __enable_if_t
12981328 <
12991329 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
13001330 size_type
13011331 >
13021332 find_first_of(const _Tp& __t, size_type __pos = 0) const _NOEXCEPT;
1333 _LIBCPP_CONSTEXPR_AFTER_CXX17
13031334 size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1304 _LIBCPP_INLINE_VISIBILITY
1335 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
13051336 size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
1306 _LIBCPP_INLINE_VISIBILITY
1337 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
13071338 size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
13081339
1309 _LIBCPP_INLINE_VISIBILITY
1340 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
13101341 size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
13111342
13121343 template <class _Tp>
1313 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1344 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
13141345 __enable_if_t
13151346 <
13161347 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
13171348 size_type
13181349 >
13191350 find_last_of(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT;
1351 _LIBCPP_CONSTEXPR_AFTER_CXX17
13201352 size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1321 _LIBCPP_INLINE_VISIBILITY
1353 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
13221354 size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
1323 _LIBCPP_INLINE_VISIBILITY
1355 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
13241356 size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
13251357
1326 _LIBCPP_INLINE_VISIBILITY
1358 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
13271359 size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
13281360
13291361 template <class _Tp>
1330 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1362 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
13311363 __enable_if_t
13321364 <
13331365 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
13341366 size_type
13351367 >
13361368 find_first_not_of(const _Tp &__t, size_type __pos = 0) const _NOEXCEPT;
1369 _LIBCPP_CONSTEXPR_AFTER_CXX17
13371370 size_type find_first_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1338 _LIBCPP_INLINE_VISIBILITY
1371 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
13391372 size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
1340 _LIBCPP_INLINE_VISIBILITY
1373 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
13411374 size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
13421375
1343 _LIBCPP_INLINE_VISIBILITY
1376 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
13441377 size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
13451378
13461379 template <class _Tp>
1347 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1380 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
13481381 __enable_if_t
13491382 <
13501383 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
13511384 size_type
13521385 >
13531386 find_last_not_of(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT;
1387 _LIBCPP_CONSTEXPR_AFTER_CXX17
13541388 size_type find_last_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1355 _LIBCPP_INLINE_VISIBILITY
1389 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
13561390 size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
1357 _LIBCPP_INLINE_VISIBILITY
1391 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
13581392 size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
13591393
1360 _LIBCPP_INLINE_VISIBILITY
1394 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
13611395 int compare(const basic_string& __str) const _NOEXCEPT;
13621396
13631397 template <class _Tp>
1364 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1398 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
13651399 __enable_if_t
13661400 <
13671401 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
......@@ -1370,7 +1404,7 @@ public:
13701404 compare(const _Tp &__t) const _NOEXCEPT;
13711405
13721406 template <class _Tp>
1373 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1407 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
13741408 __enable_if_t
13751409 <
13761410 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
......@@ -1378,199 +1412,243 @@ public:
13781412 >
13791413 compare(size_type __pos1, size_type __n1, const _Tp& __t) const;
13801414
1381 _LIBCPP_INLINE_VISIBILITY
1415 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
13821416 int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
1383 int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos) const;
1417 _LIBCPP_CONSTEXPR_AFTER_CXX17
1418 int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2,
1419 size_type __n2 = npos) const;
13841420
13851421 template <class _Tp>
1386 inline _LIBCPP_INLINE_VISIBILITY
1422 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
13871423 __enable_if_t
13881424 <
13891425 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value,
13901426 int
13911427 >
13921428 compare(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos) const;
1393 int compare(const value_type* __s) const _NOEXCEPT;
1394 int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
1429 _LIBCPP_CONSTEXPR_AFTER_CXX17 int compare(const value_type* __s) const _NOEXCEPT;
1430 _LIBCPP_CONSTEXPR_AFTER_CXX17 int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
1431 _LIBCPP_CONSTEXPR_AFTER_CXX17
13951432 int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
13961433
13971434#if _LIBCPP_STD_VER > 17
1398 constexpr _LIBCPP_INLINE_VISIBILITY
1435 constexpr _LIBCPP_HIDE_FROM_ABI
13991436 bool starts_with(__self_view __sv) const noexcept
14001437 { return __self_view(data(), size()).starts_with(__sv); }
14011438
1402 constexpr _LIBCPP_INLINE_VISIBILITY
1439 constexpr _LIBCPP_HIDE_FROM_ABI
14031440 bool starts_with(value_type __c) const noexcept
14041441 { return !empty() && _Traits::eq(front(), __c); }
14051442
1406 constexpr _LIBCPP_INLINE_VISIBILITY
1443 constexpr _LIBCPP_HIDE_FROM_ABI
14071444 bool starts_with(const value_type* __s) const noexcept
14081445 { return starts_with(__self_view(__s)); }
14091446
1410 constexpr _LIBCPP_INLINE_VISIBILITY
1447 constexpr _LIBCPP_HIDE_FROM_ABI
14111448 bool ends_with(__self_view __sv) const noexcept
14121449 { return __self_view(data(), size()).ends_with( __sv); }
14131450
1414 constexpr _LIBCPP_INLINE_VISIBILITY
1451 constexpr _LIBCPP_HIDE_FROM_ABI
14151452 bool ends_with(value_type __c) const noexcept
14161453 { return !empty() && _Traits::eq(back(), __c); }
14171454
1418 constexpr _LIBCPP_INLINE_VISIBILITY
1455 constexpr _LIBCPP_HIDE_FROM_ABI
14191456 bool ends_with(const value_type* __s) const noexcept
14201457 { return ends_with(__self_view(__s)); }
14211458#endif
14221459
14231460#if _LIBCPP_STD_VER > 20
1424 constexpr _LIBCPP_INLINE_VISIBILITY
1461 constexpr _LIBCPP_HIDE_FROM_ABI
14251462 bool contains(__self_view __sv) const noexcept
14261463 { return __self_view(data(), size()).contains(__sv); }
14271464
1428 constexpr _LIBCPP_INLINE_VISIBILITY
1465 constexpr _LIBCPP_HIDE_FROM_ABI
14291466 bool contains(value_type __c) const noexcept
14301467 { return __self_view(data(), size()).contains(__c); }
14311468
1432 constexpr _LIBCPP_INLINE_VISIBILITY
1469 constexpr _LIBCPP_HIDE_FROM_ABI
14331470 bool contains(const value_type* __s) const
14341471 { return __self_view(data(), size()).contains(__s); }
14351472#endif
14361473
1437 _LIBCPP_INLINE_VISIBILITY bool __invariants() const;
1438
1439 _LIBCPP_INLINE_VISIBILITY void __clear_and_shrink() _NOEXCEPT;
1440
1441 _LIBCPP_INLINE_VISIBILITY void __shrink_or_extend(size_type __target_capacity);
1474 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 bool __invariants() const;
14421475
1443 _LIBCPP_INLINE_VISIBILITY
1444 bool __is_long() const _NOEXCEPT
1445 {return bool(__r_.first().__s.__size_ & __short_mask);}
1476 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 void __clear_and_shrink() _NOEXCEPT;
14461477
1447#if _LIBCPP_DEBUG_LEVEL == 2
1478#ifdef _LIBCPP_ENABLE_DEBUG_MODE
14481479
14491480 bool __dereferenceable(const const_iterator* __i) const;
14501481 bool __decrementable(const const_iterator* __i) const;
14511482 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
14521483 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
14531484
1454#endif // _LIBCPP_DEBUG_LEVEL == 2
1485#endif // _LIBCPP_ENABLE_DEBUG_MODE
14551486
14561487private:
1457 _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI static bool __fits_in_sso(size_type __sz) {
1458 // SSO is disabled during constant evaluation because `__is_long` isn't constexpr friendly
1459 return !__libcpp_is_constant_evaluated() && (__sz < __min_cap);
1488 template<class _Alloc>
1489 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
1490 bool friend operator==(const basic_string<char, char_traits<char>, _Alloc>& __lhs,
1491 const basic_string<char, char_traits<char>, _Alloc>& __rhs) _NOEXCEPT;
1492
1493 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 void __shrink_or_extend(size_type __target_capacity);
1494
1495 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
1496 bool __is_long() const _NOEXCEPT {
1497 if (__libcpp_is_constant_evaluated())
1498 return true;
1499 return __r_.first().__s.__is_long_;
14601500 }
14611501
1462 _LIBCPP_INLINE_VISIBILITY
1463 allocator_type& __alloc() _NOEXCEPT
1464 {return __r_.second();}
1465 _LIBCPP_INLINE_VISIBILITY
1466 const allocator_type& __alloc() const _NOEXCEPT
1467 {return __r_.second();}
1502 static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 void __begin_lifetime(pointer __begin, size_type __n) {
1503#if _LIBCPP_STD_VER > 17
1504 if (__libcpp_is_constant_evaluated()) {
1505 for (size_type __i = 0; __i != __n; ++__i)
1506 std::construct_at(std::addressof(__begin[__i]));
1507 }
1508#else
1509 (void)__begin;
1510 (void)__n;
1511#endif // _LIBCPP_STD_VER > 17
1512 }
14681513
1469#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
1514 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 void __default_init() {
1515 __zero();
1516 if (__libcpp_is_constant_evaluated()) {
1517 size_type __sz = __recommend(0) + 1;
1518 pointer __ptr = __alloc_traits::allocate(__alloc(), __sz);
1519 __begin_lifetime(__ptr, __sz);
1520 __set_long_pointer(__ptr);
1521 __set_long_cap(__sz);
1522 __set_long_size(0);
1523 }
1524 }
14701525
1471 _LIBCPP_INLINE_VISIBILITY
1472 void __set_short_size(size_type __s) _NOEXCEPT
1473# ifdef _LIBCPP_BIG_ENDIAN
1474 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1475# else
1476 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1477# endif
1526 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 void __deallocate_constexpr() {
1527 if (__libcpp_is_constant_evaluated() && __get_pointer() != nullptr)
1528 __alloc_traits::deallocate(__alloc(), __get_pointer(), __get_long_cap());
1529 }
14781530
1479 _LIBCPP_INLINE_VISIBILITY
1480 size_type __get_short_size() const _NOEXCEPT
1481# ifdef _LIBCPP_BIG_ENDIAN
1482 {return __r_.first().__s.__size_ >> 1;}
1483# else
1484 {return __r_.first().__s.__size_;}
1485# endif
1531 _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI static bool __fits_in_sso(size_type __sz) {
1532 // SSO is disabled during constant evaluation because `__is_long` isn't constexpr friendly
1533 return !__libcpp_is_constant_evaluated() && (__sz < __min_cap);
1534 }
1535
1536 template <class _ForwardIterator>
1537 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
1538 iterator __insert_from_safe_copy(size_type __n, size_type __ip, _ForwardIterator __first, _ForwardIterator __last) {
1539 size_type __sz = size();
1540 size_type __cap = capacity();
1541 value_type* __p;
1542 if (__cap - __sz >= __n)
1543 {
1544 __p = std::__to_address(__get_pointer());
1545 size_type __n_move = __sz - __ip;
1546 if (__n_move != 0)
1547 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
1548 }
1549 else
1550 {
1551 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
1552 __p = std::__to_address(__get_long_pointer());
1553 }
1554 __sz += __n;
1555 __set_size(__sz);
1556 traits_type::assign(__p[__sz], value_type());
1557 for (__p += __ip; __first != __last; ++__p, ++__first)
1558 traits_type::assign(*__p, *__first);
14861559
1487#else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
1560 return begin() + __ip;
1561 }
14881562
1489 _LIBCPP_INLINE_VISIBILITY
1490 void __set_short_size(size_type __s) _NOEXCEPT
1491# ifdef _LIBCPP_BIG_ENDIAN
1492 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1493# else
1494 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1495# endif
1563 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 allocator_type& __alloc() _NOEXCEPT { return __r_.second(); }
1564 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const allocator_type& __alloc() const _NOEXCEPT { return __r_.second(); }
14961565
1497 _LIBCPP_INLINE_VISIBILITY
1498 size_type __get_short_size() const _NOEXCEPT
1499# ifdef _LIBCPP_BIG_ENDIAN
1500 {return __r_.first().__s.__size_;}
1501# else
1502 {return __r_.first().__s.__size_ >> 1;}
1503# endif
1566 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
1567 void __set_short_size(size_type __s) _NOEXCEPT {
1568 _LIBCPP_ASSERT(__s < __min_cap, "__s should never be greater than or equal to the short string capacity");
1569 __r_.first().__s.__size_ = __s;
1570 __r_.first().__s.__is_long_ = false;
1571 }
15041572
1505#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
1573 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
1574 size_type __get_short_size() const _NOEXCEPT {
1575 _LIBCPP_ASSERT(!__r_.first().__s.__is_long_, "String has to be short when trying to get the short size");
1576 return __r_.first().__s.__size_;
1577 }
15061578
1507 _LIBCPP_INLINE_VISIBILITY
1579 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
15081580 void __set_long_size(size_type __s) _NOEXCEPT
15091581 {__r_.first().__l.__size_ = __s;}
1510 _LIBCPP_INLINE_VISIBILITY
1582 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
15111583 size_type __get_long_size() const _NOEXCEPT
15121584 {return __r_.first().__l.__size_;}
1513 _LIBCPP_INLINE_VISIBILITY
1585 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
15141586 void __set_size(size_type __s) _NOEXCEPT
15151587 {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
15161588
1517 _LIBCPP_INLINE_VISIBILITY
1518 void __set_long_cap(size_type __s) _NOEXCEPT
1519 {__r_.first().__l.__cap_ = __long_mask | __s;}
1520 _LIBCPP_INLINE_VISIBILITY
1521 size_type __get_long_cap() const _NOEXCEPT
1522 {return __r_.first().__l.__cap_ & size_type(~__long_mask);}
1589 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
1590 void __set_long_cap(size_type __s) _NOEXCEPT {
1591 __r_.first().__l.__cap_ = __s / __endian_factor;
1592 __r_.first().__l.__is_long_ = true;
1593 }
15231594
1524 _LIBCPP_INLINE_VISIBILITY
1595 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
1596 size_type __get_long_cap() const _NOEXCEPT {
1597 return __r_.first().__l.__cap_ * __endian_factor;
1598 }
1599
1600 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
15251601 void __set_long_pointer(pointer __p) _NOEXCEPT
15261602 {__r_.first().__l.__data_ = __p;}
1527 _LIBCPP_INLINE_VISIBILITY
1603 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
15281604 pointer __get_long_pointer() _NOEXCEPT
15291605 {return __r_.first().__l.__data_;}
1530 _LIBCPP_INLINE_VISIBILITY
1606 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
15311607 const_pointer __get_long_pointer() const _NOEXCEPT
15321608 {return __r_.first().__l.__data_;}
1533 _LIBCPP_INLINE_VISIBILITY
1609 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
15341610 pointer __get_short_pointer() _NOEXCEPT
15351611 {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);}
1536 _LIBCPP_INLINE_VISIBILITY
1612 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
15371613 const_pointer __get_short_pointer() const _NOEXCEPT
15381614 {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);}
1539 _LIBCPP_INLINE_VISIBILITY
1615 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
15401616 pointer __get_pointer() _NOEXCEPT
15411617 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1542 _LIBCPP_INLINE_VISIBILITY
1618 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
15431619 const_pointer __get_pointer() const _NOEXCEPT
15441620 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
15451621
1546 _LIBCPP_INLINE_VISIBILITY
1547 void __zero() _NOEXCEPT
1548 {
1549 size_type (&__a)[__n_words] = __r_.first().__r.__words;
1550 for (unsigned __i = 0; __i < __n_words; ++__i)
1551 __a[__i] = 0;
1552 }
1622 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
1623 void __zero() _NOEXCEPT {
1624 __r_.first() = __rep();
1625 }
15531626
15541627 template <size_type __a> static
1555 _LIBCPP_INLINE_VISIBILITY
1628 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
15561629 size_type __align_it(size_type __s) _NOEXCEPT
15571630 {return (__s + (__a-1)) & ~(__a-1);}
15581631 enum {__alignment = 16};
1559 static _LIBCPP_INLINE_VISIBILITY
1632 static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
15601633 size_type __recommend(size_type __s) _NOEXCEPT
1561 {
1562 if (__s < __min_cap) return static_cast<size_type>(__min_cap) - 1;
1634 {
1635 if (__s < __min_cap) {
1636 if (__libcpp_is_constant_evaluated())
1637 return static_cast<size_type>(__min_cap);
1638 else
1639 return static_cast<size_type>(__min_cap) - 1;
1640 }
15631641 size_type __guess = __align_it<sizeof(value_type) < __alignment ?
15641642 __alignment/sizeof(value_type) : 1 > (__s+1) - 1;
15651643 if (__guess == __min_cap) ++__guess;
15661644 return __guess;
1567 }
1645 }
15681646
1569 inline
1647 inline _LIBCPP_CONSTEXPR_AFTER_CXX17
15701648 void __init(const value_type* __s, size_type __sz, size_type __reserve);
1571 inline
1649 inline _LIBCPP_CONSTEXPR_AFTER_CXX17
15721650 void __init(const value_type* __s, size_type __sz);
1573 inline
1651 inline _LIBCPP_CONSTEXPR_AFTER_CXX17
15741652 void __init(size_type __n, value_type __c);
15751653
15761654 // Slow path for the (inlined) copy constructor for 'long' strings.
......@@ -1581,10 +1659,10 @@ private:
15811659 // to call the __init() functions as those are marked as inline which may
15821660 // result in over-aggressive inlining by the compiler, where our aim is
15831661 // to only inline the fast path code directly in the ctor.
1584 void __init_copy_ctor_external(const value_type* __s, size_type __sz);
1662 _LIBCPP_CONSTEXPR_AFTER_CXX17 void __init_copy_ctor_external(const value_type* __s, size_type __sz);
15851663
15861664 template <class _InputIterator>
1587 inline
1665 inline _LIBCPP_CONSTEXPR_AFTER_CXX17
15881666 __enable_if_t
15891667 <
15901668 __is_exactly_cpp17_input_iterator<_InputIterator>::value
......@@ -1592,15 +1670,17 @@ private:
15921670 __init(_InputIterator __first, _InputIterator __last);
15931671
15941672 template <class _ForwardIterator>
1595 inline
1673 inline _LIBCPP_CONSTEXPR_AFTER_CXX17
15961674 __enable_if_t
15971675 <
15981676 __is_cpp17_forward_iterator<_ForwardIterator>::value
15991677 >
16001678 __init(_ForwardIterator __first, _ForwardIterator __last);
16011679
1680 _LIBCPP_CONSTEXPR_AFTER_CXX17
16021681 void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
16031682 size_type __n_copy, size_type __n_del, size_type __n_add = 0);
1683 _LIBCPP_CONSTEXPR_AFTER_CXX17
16041684 void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
16051685 size_type __n_copy, size_type __n_del,
16061686 size_type __n_add, const value_type* __p_new_stuff);
......@@ -1609,21 +1689,21 @@ private:
16091689 // have proof that the input does not alias the current instance.
16101690 // For example, operator=(basic_string) performs a 'self' check.
16111691 template <bool __is_short>
1612 basic_string& __assign_no_alias(const value_type* __s, size_type __n);
1692 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& __assign_no_alias(const value_type* __s, size_type __n);
16131693
1614 _LIBCPP_INLINE_VISIBILITY
1694 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
16151695 void __erase_to_end(size_type __pos);
16161696
16171697 // __erase_external_with_move is invoked for erase() invocations where
16181698 // `n ~= npos`, likely requiring memory moves on the string data.
1619 void __erase_external_with_move(size_type __pos, size_type __n);
1699 _LIBCPP_CONSTEXPR_AFTER_CXX17 void __erase_external_with_move(size_type __pos, size_type __n);
16201700
1621 _LIBCPP_INLINE_VISIBILITY
1701 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
16221702 void __copy_assign_alloc(const basic_string& __str)
16231703 {__copy_assign_alloc(__str, integral_constant<bool,
16241704 __alloc_traits::propagate_on_container_copy_assignment::value>());}
16251705
1626 _LIBCPP_INLINE_VISIBILITY
1706 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
16271707 void __copy_assign_alloc(const basic_string& __str, true_type)
16281708 {
16291709 if (__alloc() == __str.__alloc())
......@@ -1638,25 +1718,26 @@ private:
16381718 else
16391719 {
16401720 allocator_type __a = __str.__alloc();
1641 pointer __p = __alloc_traits::allocate(__a, __str.__get_long_cap());
1721 auto __allocation = std::__allocate_at_least(__a, __str.__get_long_cap());
1722 __begin_lifetime(__allocation.ptr, __allocation.count);
16421723 __clear_and_shrink();
1643 __alloc() = _VSTD::move(__a);
1644 __set_long_pointer(__p);
1645 __set_long_cap(__str.__get_long_cap());
1724 __alloc() = std::move(__a);
1725 __set_long_pointer(__allocation.ptr);
1726 __set_long_cap(__allocation.count);
16461727 __set_long_size(__str.size());
16471728 }
16481729 }
16491730 }
16501731
1651 _LIBCPP_INLINE_VISIBILITY
1732 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
16521733 void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
16531734 {}
16541735
16551736#ifndef _LIBCPP_CXX03_LANG
1656 _LIBCPP_INLINE_VISIBILITY
1737 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
16571738 void __move_assign(basic_string& __str, false_type)
16581739 _NOEXCEPT_(__alloc_traits::is_always_equal::value);
1659 _LIBCPP_INLINE_VISIBILITY
1740 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
16601741 void __move_assign(basic_string& __str, true_type)
16611742#if _LIBCPP_STD_VER > 14
16621743 _NOEXCEPT;
......@@ -1665,7 +1746,7 @@ private:
16651746#endif
16661747#endif
16671748
1668 _LIBCPP_INLINE_VISIBILITY
1749 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
16691750 void
16701751 __move_assign_alloc(basic_string& __str)
16711752 _NOEXCEPT_(
......@@ -1674,78 +1755,83 @@ private:
16741755 {__move_assign_alloc(__str, integral_constant<bool,
16751756 __alloc_traits::propagate_on_container_move_assignment::value>());}
16761757
1677 _LIBCPP_INLINE_VISIBILITY
1758 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
16781759 void __move_assign_alloc(basic_string& __c, true_type)
16791760 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
16801761 {
1681 __alloc() = _VSTD::move(__c.__alloc());
1762 __alloc() = std::move(__c.__alloc());
16821763 }
16831764
1684 _LIBCPP_INLINE_VISIBILITY
1765 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
16851766 void __move_assign_alloc(basic_string&, false_type)
16861767 _NOEXCEPT
16871768 {}
16881769
1689 basic_string& __assign_external(const value_type* __s);
1690 basic_string& __assign_external(const value_type* __s, size_type __n);
1770 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& __assign_external(const value_type* __s);
1771 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& __assign_external(const value_type* __s, size_type __n);
16911772
16921773 // Assigns the value in __s, guaranteed to be __n < __min_cap in length.
16931774 inline basic_string& __assign_short(const value_type* __s, size_type __n) {
16941775 pointer __p = __is_long()
16951776 ? (__set_long_size(__n), __get_long_pointer())
16961777 : (__set_short_size(__n), __get_short_pointer());
1697 traits_type::move(_VSTD::__to_address(__p), __s, __n);
1778 traits_type::move(std::__to_address(__p), __s, __n);
16981779 traits_type::assign(__p[__n], value_type());
16991780 return *this;
17001781 }
17011782
1702 _LIBCPP_HIDE_FROM_ABI basic_string& __null_terminate_at(value_type* __p, size_type __newsz) {
1783 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
1784 basic_string& __null_terminate_at(value_type* __p, size_type __newsz) {
17031785 __set_size(__newsz);
17041786 __invalidate_iterators_past(__newsz);
17051787 traits_type::assign(__p[__newsz], value_type());
17061788 return *this;
17071789 }
17081790
1709 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
1710 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
1791 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 void __invalidate_iterators_past(size_type);
17111792
17121793 template<class _Tp>
1713 _LIBCPP_INLINE_VISIBILITY
1794 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
17141795 bool __addr_in_range(_Tp&& __t) const {
1715 const volatile void *__p = _VSTD::addressof(__t);
1796 // assume that the ranges overlap, because we can't check during constant evaluation
1797 if (__libcpp_is_constant_evaluated())
1798 return true;
1799 const volatile void *__p = std::addressof(__t);
17161800 return data() <= __p && __p <= data() + size();
17171801 }
17181802
17191803 _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
17201804 void __throw_length_error() const {
1721 _VSTD::__throw_length_error("basic_string");
1805 std::__throw_length_error("basic_string");
17221806 }
17231807
17241808 _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
17251809 void __throw_out_of_range() const {
1726 _VSTD::__throw_out_of_range("basic_string");
1810 std::__throw_out_of_range("basic_string");
17271811 }
17281812
1729 friend basic_string operator+<>(const basic_string&, const basic_string&);
1730 friend basic_string operator+<>(const value_type*, const basic_string&);
1731 friend basic_string operator+<>(value_type, const basic_string&);
1732 friend basic_string operator+<>(const basic_string&, const value_type*);
1733 friend basic_string operator+<>(const basic_string&, value_type);
1813 friend _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string operator+<>(const basic_string&, const basic_string&);
1814 friend _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string operator+<>(const value_type*, const basic_string&);
1815 friend _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string operator+<>(value_type, const basic_string&);
1816 friend _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string operator+<>(const basic_string&, const value_type*);
1817 friend _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string operator+<>(const basic_string&, value_type);
17341818};
17351819
17361820// These declarations must appear before any functions are implicitly used
17371821// so that they have the correct visibility specifier.
1822#define _LIBCPP_DECLARE(...) extern template __VA_ARGS__;
17381823#ifdef _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
1739 _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, char)
1824 _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_DECLARE, char)
17401825# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1741 _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, wchar_t)
1826 _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_DECLARE, wchar_t)
17421827# endif
17431828#else
1744 _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, char)
1829 _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_DECLARE, char)
17451830# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1746 _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, wchar_t)
1831 _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_DECLARE, wchar_t)
17471832# endif
17481833#endif
1834#undef _LIBCPP_DECLARE
17491835
17501836
17511837#if _LIBCPP_STD_VER >= 17
......@@ -1777,22 +1863,11 @@ basic_string(basic_string_view<_CharT, _Traits>, _Sz, _Sz, const _Allocator& = _
17771863#endif
17781864
17791865template <class _CharT, class _Traits, class _Allocator>
1780inline
1781void
1782basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
1783{
1784#if _LIBCPP_DEBUG_LEVEL == 2
1785 if (!__libcpp_is_constant_evaluated())
1786 __get_db()->__invalidate_all(this);
1787#endif
1788}
1789
1790template <class _CharT, class _Traits, class _Allocator>
1791inline
1866inline _LIBCPP_CONSTEXPR_AFTER_CXX17
17921867void
17931868basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type __pos)
17941869{
1795#if _LIBCPP_DEBUG_LEVEL == 2
1870#ifdef _LIBCPP_ENABLE_DEBUG_MODE
17961871 if (!__libcpp_is_constant_evaluated()) {
17971872 __c_node* __c = __get_db()->__find_c_and_lock(this);
17981873 if (__c)
......@@ -1806,7 +1881,7 @@ basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type
18061881 {
18071882 (*__p)->__c_ = nullptr;
18081883 if (--__c->end_ != __p)
1809 _VSTD::memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1884 std::memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
18101885 }
18111886 }
18121887 __get_db()->unlock();
......@@ -1814,21 +1889,21 @@ basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type
18141889 }
18151890#else
18161891 (void)__pos;
1817#endif // _LIBCPP_DEBUG_LEVEL == 2
1892#endif // _LIBCPP_ENABLE_DEBUG_MODE
18181893}
18191894
18201895template <class _CharT, class _Traits, class _Allocator>
1821inline
1896inline _LIBCPP_CONSTEXPR_AFTER_CXX17
18221897basic_string<_CharT, _Traits, _Allocator>::basic_string()
18231898 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
18241899 : __r_(__default_init_tag(), __default_init_tag())
18251900{
1826 _VSTD::__debug_db_insert_c(this);
1827 __zero();
1901 std::__debug_db_insert_c(this);
1902 __default_init();
18281903}
18291904
18301905template <class _CharT, class _Traits, class _Allocator>
1831inline
1906inline _LIBCPP_CONSTEXPR_AFTER_CXX17
18321907basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
18331908#if _LIBCPP_STD_VER <= 14
18341909 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
......@@ -1837,15 +1912,18 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __
18371912#endif
18381913: __r_(__default_init_tag(), __a)
18391914{
1840 _VSTD::__debug_db_insert_c(this);
1841 __zero();
1915 std::__debug_db_insert_c(this);
1916 __default_init();
18421917}
18431918
18441919template <class _CharT, class _Traits, class _Allocator>
1920_LIBCPP_CONSTEXPR_AFTER_CXX17
18451921void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s,
18461922 size_type __sz,
18471923 size_type __reserve)
18481924{
1925 if (__libcpp_is_constant_evaluated())
1926 __zero();
18491927 if (__reserve > max_size())
18501928 __throw_length_error();
18511929 pointer __p;
......@@ -1856,20 +1934,24 @@ void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s,
18561934 }
18571935 else
18581936 {
1859 size_type __cap = __recommend(__reserve);
1860 __p = __alloc_traits::allocate(__alloc(), __cap+1);
1937 auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__reserve) + 1);
1938 __p = __allocation.ptr;
1939 __begin_lifetime(__p, __allocation.count);
18611940 __set_long_pointer(__p);
1862 __set_long_cap(__cap+1);
1941 __set_long_cap(__allocation.count);
18631942 __set_long_size(__sz);
18641943 }
1865 traits_type::copy(_VSTD::__to_address(__p), __s, __sz);
1944 traits_type::copy(std::__to_address(__p), __s, __sz);
18661945 traits_type::assign(__p[__sz], value_type());
18671946}
18681947
18691948template <class _CharT, class _Traits, class _Allocator>
1949_LIBCPP_CONSTEXPR_AFTER_CXX17
18701950void
18711951basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
18721952{
1953 if (__libcpp_is_constant_evaluated())
1954 __zero();
18731955 if (__sz > max_size())
18741956 __throw_length_error();
18751957 pointer __p;
......@@ -1880,59 +1962,63 @@ basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_ty
18801962 }
18811963 else
18821964 {
1883 size_type __cap = __recommend(__sz);
1884 __p = __alloc_traits::allocate(__alloc(), __cap+1);
1965 auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__sz) + 1);
1966 __p = __allocation.ptr;
1967 __begin_lifetime(__p, __allocation.count);
18851968 __set_long_pointer(__p);
1886 __set_long_cap(__cap+1);
1969 __set_long_cap(__allocation.count);
18871970 __set_long_size(__sz);
18881971 }
1889 traits_type::copy(_VSTD::__to_address(__p), __s, __sz);
1972 traits_type::copy(std::__to_address(__p), __s, __sz);
18901973 traits_type::assign(__p[__sz], value_type());
18911974}
18921975
18931976template <class _CharT, class _Traits, class _Allocator>
18941977template <class>
1978_LIBCPP_CONSTEXPR_AFTER_CXX17
18951979basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, const _Allocator& __a)
18961980 : __r_(__default_init_tag(), __a)
18971981{
18981982 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
18991983 __init(__s, traits_type::length(__s));
1900 _VSTD::__debug_db_insert_c(this);
1984 std::__debug_db_insert_c(this);
19011985}
19021986
19031987template <class _CharT, class _Traits, class _Allocator>
1904inline
1988inline _LIBCPP_CONSTEXPR_AFTER_CXX17
19051989basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n)
19061990 : __r_(__default_init_tag(), __default_init_tag())
19071991{
19081992 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
19091993 __init(__s, __n);
1910 _VSTD::__debug_db_insert_c(this);
1994 std::__debug_db_insert_c(this);
19111995}
19121996
19131997template <class _CharT, class _Traits, class _Allocator>
1914inline
1998inline _LIBCPP_CONSTEXPR_AFTER_CXX17
19151999basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n, const _Allocator& __a)
19162000 : __r_(__default_init_tag(), __a)
19172001{
19182002 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
19192003 __init(__s, __n);
1920 _VSTD::__debug_db_insert_c(this);
2004 std::__debug_db_insert_c(this);
19212005}
19222006
19232007template <class _CharT, class _Traits, class _Allocator>
2008_LIBCPP_CONSTEXPR_AFTER_CXX17
19242009basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
19252010 : __r_(__default_init_tag(), __alloc_traits::select_on_container_copy_construction(__str.__alloc()))
19262011{
19272012 if (!__str.__is_long())
19282013 __r_.first().__r = __str.__r_.first().__r;
19292014 else
1930 __init_copy_ctor_external(_VSTD::__to_address(__str.__get_long_pointer()),
2015 __init_copy_ctor_external(std::__to_address(__str.__get_long_pointer()),
19312016 __str.__get_long_size());
1932 _VSTD::__debug_db_insert_c(this);
2017 std::__debug_db_insert_c(this);
19332018}
19342019
19352020template <class _CharT, class _Traits, class _Allocator>
2021_LIBCPP_CONSTEXPR_AFTER_CXX17
19362022basic_string<_CharT, _Traits, _Allocator>::basic_string(
19372023 const basic_string& __str, const allocator_type& __a)
19382024 : __r_(__default_init_tag(), __a)
......@@ -1940,14 +2026,17 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(
19402026 if (!__str.__is_long())
19412027 __r_.first().__r = __str.__r_.first().__r;
19422028 else
1943 __init_copy_ctor_external(_VSTD::__to_address(__str.__get_long_pointer()),
2029 __init_copy_ctor_external(std::__to_address(__str.__get_long_pointer()),
19442030 __str.__get_long_size());
1945 _VSTD::__debug_db_insert_c(this);
2031 std::__debug_db_insert_c(this);
19462032}
19472033
19482034template <class _CharT, class _Traits, class _Allocator>
2035_LIBCPP_CONSTEXPR_AFTER_CXX17
19492036void basic_string<_CharT, _Traits, _Allocator>::__init_copy_ctor_external(
19502037 const value_type* __s, size_type __sz) {
2038 if (__libcpp_is_constant_evaluated())
2039 __zero();
19512040 pointer __p;
19522041 if (__fits_in_sso(__sz)) {
19532042 __p = __get_short_pointer();
......@@ -1955,60 +2044,65 @@ void basic_string<_CharT, _Traits, _Allocator>::__init_copy_ctor_external(
19552044 } else {
19562045 if (__sz > max_size())
19572046 __throw_length_error();
1958 size_t __cap = __recommend(__sz);
1959 __p = __alloc_traits::allocate(__alloc(), __cap + 1);
2047 auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__sz) + 1);
2048 __p = __allocation.ptr;
2049 __begin_lifetime(__p, __allocation.count);
19602050 __set_long_pointer(__p);
1961 __set_long_cap(__cap + 1);
2051 __set_long_cap(__allocation.count);
19622052 __set_long_size(__sz);
19632053 }
1964 traits_type::copy(_VSTD::__to_address(__p), __s, __sz + 1);
2054 traits_type::copy(std::__to_address(__p), __s, __sz + 1);
19652055}
19662056
19672057#ifndef _LIBCPP_CXX03_LANG
19682058
19692059template <class _CharT, class _Traits, class _Allocator>
1970inline
2060inline _LIBCPP_CONSTEXPR_AFTER_CXX17
19712061basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
19722062#if _LIBCPP_STD_VER <= 14
19732063 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
19742064#else
19752065 _NOEXCEPT
19762066#endif
1977 : __r_(_VSTD::move(__str.__r_))
2067 : __r_(std::move(__str.__r_))
19782068{
1979 __str.__zero();
1980 _VSTD::__debug_db_insert_c(this);
1981#if _LIBCPP_DEBUG_LEVEL == 2
1982 if (!__libcpp_is_constant_evaluated() && __is_long())
1983 __get_db()->swap(this, &__str);
1984#endif
2069 __str.__default_init();
2070 std::__debug_db_insert_c(this);
2071 if (__is_long())
2072 std::__debug_db_swap(this, &__str);
19852073}
19862074
19872075template <class _CharT, class _Traits, class _Allocator>
1988inline
2076inline _LIBCPP_CONSTEXPR_AFTER_CXX17
19892077basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
19902078 : __r_(__default_init_tag(), __a)
19912079{
19922080 if (__str.__is_long() && __a != __str.__alloc()) // copy, not move
1993 __init(_VSTD::__to_address(__str.__get_long_pointer()), __str.__get_long_size());
2081 __init(std::__to_address(__str.__get_long_pointer()), __str.__get_long_size());
19942082 else
19952083 {
1996 __r_.first().__r = __str.__r_.first().__r;
1997 __str.__zero();
2084 if (__libcpp_is_constant_evaluated()) {
2085 __zero();
2086 __r_.first().__l = __str.__r_.first().__l;
2087 } else {
2088 __r_.first().__r = __str.__r_.first().__r;
2089 }
2090 __str.__default_init();
19982091 }
1999 _VSTD::__debug_db_insert_c(this);
2000#if _LIBCPP_DEBUG_LEVEL == 2
2001 if (!__libcpp_is_constant_evaluated() && __is_long())
2002 __get_db()->swap(this, &__str);
2003#endif
2092 std::__debug_db_insert_c(this);
2093 if (__is_long())
2094 std::__debug_db_swap(this, &__str);
20042095}
20052096
20062097#endif // _LIBCPP_CXX03_LANG
20072098
20082099template <class _CharT, class _Traits, class _Allocator>
2100_LIBCPP_CONSTEXPR_AFTER_CXX17
20092101void
20102102basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
20112103{
2104 if (__libcpp_is_constant_evaluated())
2105 __zero();
20122106 if (__n > max_size())
20132107 __throw_length_error();
20142108 pointer __p;
......@@ -2019,35 +2113,38 @@ basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
20192113 }
20202114 else
20212115 {
2022 size_type __cap = __recommend(__n);
2023 __p = __alloc_traits::allocate(__alloc(), __cap+1);
2116 auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__n) + 1);
2117 __p = __allocation.ptr;
2118 __begin_lifetime(__p, __allocation.count);
20242119 __set_long_pointer(__p);
2025 __set_long_cap(__cap+1);
2120 __set_long_cap(__allocation.count);
20262121 __set_long_size(__n);
20272122 }
2028 traits_type::assign(_VSTD::__to_address(__p), __n, __c);
2123 traits_type::assign(std::__to_address(__p), __n, __c);
20292124 traits_type::assign(__p[__n], value_type());
20302125}
20312126
20322127template <class _CharT, class _Traits, class _Allocator>
2033inline
2128inline _LIBCPP_CONSTEXPR_AFTER_CXX17
20342129basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c)
20352130 : __r_(__default_init_tag(), __default_init_tag())
20362131{
20372132 __init(__n, __c);
2038 _VSTD::__debug_db_insert_c(this);
2133 std::__debug_db_insert_c(this);
20392134}
20402135
20412136template <class _CharT, class _Traits, class _Allocator>
20422137template <class>
2138_LIBCPP_CONSTEXPR_AFTER_CXX17
20432139basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c, const _Allocator& __a)
20442140 : __r_(__default_init_tag(), __a)
20452141{
20462142 __init(__n, __c);
2047 _VSTD::__debug_db_insert_c(this);
2143 std::__debug_db_insert_c(this);
20482144}
20492145
20502146template <class _CharT, class _Traits, class _Allocator>
2147_LIBCPP_CONSTEXPR_AFTER_CXX17
20512148basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str,
20522149 size_type __pos, size_type __n,
20532150 const _Allocator& __a)
......@@ -2056,12 +2153,12 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __st
20562153 size_type __str_sz = __str.size();
20572154 if (__pos > __str_sz)
20582155 __throw_out_of_range();
2059 __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
2060 _VSTD::__debug_db_insert_c(this);
2156 __init(__str.data() + __pos, std::min(__n, __str_sz - __pos));
2157 std::__debug_db_insert_c(this);
20612158}
20622159
20632160template <class _CharT, class _Traits, class _Allocator>
2064inline
2161inline _LIBCPP_CONSTEXPR_AFTER_CXX17
20652162basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos,
20662163 const _Allocator& __a)
20672164 : __r_(__default_init_tag(), __a)
......@@ -2070,11 +2167,12 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __st
20702167 if (__pos > __str_sz)
20712168 __throw_out_of_range();
20722169 __init(__str.data() + __pos, __str_sz - __pos);
2073 _VSTD::__debug_db_insert_c(this);
2170 std::__debug_db_insert_c(this);
20742171}
20752172
20762173template <class _CharT, class _Traits, class _Allocator>
20772174template <class _Tp, class>
2175_LIBCPP_CONSTEXPR_AFTER_CXX17
20782176basic_string<_CharT, _Traits, _Allocator>::basic_string(
20792177 const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a)
20802178 : __r_(__default_init_tag(), __a)
......@@ -2082,38 +2180,41 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(
20822180 __self_view __sv0 = __t;
20832181 __self_view __sv = __sv0.substr(__pos, __n);
20842182 __init(__sv.data(), __sv.size());
2085 _VSTD::__debug_db_insert_c(this);
2183 std::__debug_db_insert_c(this);
20862184}
20872185
20882186template <class _CharT, class _Traits, class _Allocator>
20892187template <class _Tp, class>
2188_LIBCPP_CONSTEXPR_AFTER_CXX17
20902189basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t)
20912190 : __r_(__default_init_tag(), __default_init_tag())
20922191{
20932192 __self_view __sv = __t;
20942193 __init(__sv.data(), __sv.size());
2095 _VSTD::__debug_db_insert_c(this);
2194 std::__debug_db_insert_c(this);
20962195}
20972196
20982197template <class _CharT, class _Traits, class _Allocator>
20992198template <class _Tp, class>
2199_LIBCPP_CONSTEXPR_AFTER_CXX17
21002200basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t, const _Allocator& __a)
21012201 : __r_(__default_init_tag(), __a)
21022202{
21032203 __self_view __sv = __t;
21042204 __init(__sv.data(), __sv.size());
2105 _VSTD::__debug_db_insert_c(this);
2205 std::__debug_db_insert_c(this);
21062206}
21072207
21082208template <class _CharT, class _Traits, class _Allocator>
21092209template <class _InputIterator>
2210_LIBCPP_CONSTEXPR_AFTER_CXX17
21102211__enable_if_t
21112212<
21122213 __is_exactly_cpp17_input_iterator<_InputIterator>::value
21132214>
21142215basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
21152216{
2116 __zero();
2217 __default_init();
21172218#ifndef _LIBCPP_NO_EXCEPTIONS
21182219 try
21192220 {
......@@ -2133,13 +2234,16 @@ basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _Input
21332234
21342235template <class _CharT, class _Traits, class _Allocator>
21352236template <class _ForwardIterator>
2237_LIBCPP_CONSTEXPR_AFTER_CXX17
21362238__enable_if_t
21372239<
21382240 __is_cpp17_forward_iterator<_ForwardIterator>::value
21392241>
21402242basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
21412243{
2142 size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
2244 if (__libcpp_is_constant_evaluated())
2245 __zero();
2246 size_type __sz = static_cast<size_type>(std::distance(__first, __last));
21432247 if (__sz > max_size())
21442248 __throw_length_error();
21452249 pointer __p;
......@@ -2150,10 +2254,11 @@ basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _For
21502254 }
21512255 else
21522256 {
2153 size_type __cap = __recommend(__sz);
2154 __p = __alloc_traits::allocate(__alloc(), __cap+1);
2257 auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__sz) + 1);
2258 __p = __allocation.ptr;
2259 __begin_lifetime(__p, __allocation.count);
21552260 __set_long_pointer(__p);
2156 __set_long_cap(__cap+1);
2261 __set_long_cap(__allocation.count);
21572262 __set_long_size(__sz);
21582263 }
21592264
......@@ -2177,62 +2282,60 @@ basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _For
21772282
21782283template <class _CharT, class _Traits, class _Allocator>
21792284template<class _InputIterator, class>
2180inline
2285inline _LIBCPP_CONSTEXPR_AFTER_CXX17
21812286basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
21822287 : __r_(__default_init_tag(), __default_init_tag())
21832288{
21842289 __init(__first, __last);
2185 _VSTD::__debug_db_insert_c(this);
2290 std::__debug_db_insert_c(this);
21862291}
21872292
21882293template <class _CharT, class _Traits, class _Allocator>
21892294template<class _InputIterator, class>
2190inline
2295inline _LIBCPP_CONSTEXPR_AFTER_CXX17
21912296basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
21922297 const allocator_type& __a)
21932298 : __r_(__default_init_tag(), __a)
21942299{
21952300 __init(__first, __last);
2196 _VSTD::__debug_db_insert_c(this);
2301 std::__debug_db_insert_c(this);
21972302}
21982303
21992304#ifndef _LIBCPP_CXX03_LANG
22002305
22012306template <class _CharT, class _Traits, class _Allocator>
2202inline
2307inline _LIBCPP_CONSTEXPR_AFTER_CXX17
22032308basic_string<_CharT, _Traits, _Allocator>::basic_string(
22042309 initializer_list<_CharT> __il)
22052310 : __r_(__default_init_tag(), __default_init_tag())
22062311{
22072312 __init(__il.begin(), __il.end());
2208 _VSTD::__debug_db_insert_c(this);
2313 std::__debug_db_insert_c(this);
22092314}
22102315
22112316template <class _CharT, class _Traits, class _Allocator>
2212inline
2213
2317inline _LIBCPP_CONSTEXPR_AFTER_CXX17
22142318basic_string<_CharT, _Traits, _Allocator>::basic_string(
22152319 initializer_list<_CharT> __il, const _Allocator& __a)
22162320 : __r_(__default_init_tag(), __a)
22172321{
22182322 __init(__il.begin(), __il.end());
2219 _VSTD::__debug_db_insert_c(this);
2323 std::__debug_db_insert_c(this);
22202324}
22212325
22222326#endif // _LIBCPP_CXX03_LANG
22232327
22242328template <class _CharT, class _Traits, class _Allocator>
2329_LIBCPP_CONSTEXPR_AFTER_CXX17
22252330basic_string<_CharT, _Traits, _Allocator>::~basic_string()
22262331{
2227#if _LIBCPP_DEBUG_LEVEL == 2
2228 if (!__libcpp_is_constant_evaluated())
2229 __get_db()->__erase_c(this);
2230#endif
2332 std::__debug_db_erase_c(this);
22312333 if (__is_long())
22322334 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
22332335}
22342336
22352337template <class _CharT, class _Traits, class _Allocator>
2338_LIBCPP_CONSTEXPR_AFTER_CXX17
22362339void
22372340basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
22382341 (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
......@@ -2243,23 +2346,25 @@ basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
22432346 __throw_length_error();
22442347 pointer __old_p = __get_pointer();
22452348 size_type __cap = __old_cap < __ms / 2 - __alignment ?
2246 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
2349 __recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) :
22472350 __ms - 1;
2248 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
2249 __invalidate_all_iterators();
2351 auto __allocation = std::__allocate_at_least(__alloc(), __cap + 1);
2352 pointer __p = __allocation.ptr;
2353 __begin_lifetime(__p, __allocation.count);
2354 std::__debug_db_invalidate_all(this);
22502355 if (__n_copy != 0)
2251 traits_type::copy(_VSTD::__to_address(__p),
2252 _VSTD::__to_address(__old_p), __n_copy);
2356 traits_type::copy(std::__to_address(__p),
2357 std::__to_address(__old_p), __n_copy);
22532358 if (__n_add != 0)
2254 traits_type::copy(_VSTD::__to_address(__p) + __n_copy, __p_new_stuff, __n_add);
2359 traits_type::copy(std::__to_address(__p) + __n_copy, __p_new_stuff, __n_add);
22552360 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
22562361 if (__sec_cp_sz != 0)
2257 traits_type::copy(_VSTD::__to_address(__p) + __n_copy + __n_add,
2258 _VSTD::__to_address(__old_p) + __n_copy + __n_del, __sec_cp_sz);
2259 if (__old_cap+1 != __min_cap)
2362 traits_type::copy(std::__to_address(__p) + __n_copy + __n_add,
2363 std::__to_address(__old_p) + __n_copy + __n_del, __sec_cp_sz);
2364 if (__old_cap+1 != __min_cap || __libcpp_is_constant_evaluated())
22602365 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
22612366 __set_long_pointer(__p);
2262 __set_long_cap(__cap+1);
2367 __set_long_cap(__allocation.count);
22632368 __old_sz = __n_copy + __n_add + __sec_cp_sz;
22642369 __set_long_size(__old_sz);
22652370 traits_type::assign(__p[__old_sz], value_type());
......@@ -2267,6 +2372,7 @@ basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
22672372
22682373template <class _CharT, class _Traits, class _Allocator>
22692374void
2375_LIBCPP_CONSTEXPR_AFTER_CXX17
22702376basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
22712377 size_type __n_copy, size_type __n_del, size_type __n_add)
22722378{
......@@ -2275,36 +2381,39 @@ basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_t
22752381 __throw_length_error();
22762382 pointer __old_p = __get_pointer();
22772383 size_type __cap = __old_cap < __ms / 2 - __alignment ?
2278 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
2384 __recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) :
22792385 __ms - 1;
2280 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
2281 __invalidate_all_iterators();
2386 auto __allocation = std::__allocate_at_least(__alloc(), __cap + 1);
2387 pointer __p = __allocation.ptr;
2388 __begin_lifetime(__p, __allocation.count);
2389 std::__debug_db_invalidate_all(this);
22822390 if (__n_copy != 0)
2283 traits_type::copy(_VSTD::__to_address(__p),
2284 _VSTD::__to_address(__old_p), __n_copy);
2391 traits_type::copy(std::__to_address(__p),
2392 std::__to_address(__old_p), __n_copy);
22852393 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
22862394 if (__sec_cp_sz != 0)
2287 traits_type::copy(_VSTD::__to_address(__p) + __n_copy + __n_add,
2288 _VSTD::__to_address(__old_p) + __n_copy + __n_del,
2395 traits_type::copy(std::__to_address(__p) + __n_copy + __n_add,
2396 std::__to_address(__old_p) + __n_copy + __n_del,
22892397 __sec_cp_sz);
2290 if (__old_cap+1 != __min_cap)
2291 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
2398 if (__libcpp_is_constant_evaluated() || __old_cap + 1 != __min_cap)
2399 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap + 1);
22922400 __set_long_pointer(__p);
2293 __set_long_cap(__cap+1);
2401 __set_long_cap(__allocation.count);
22942402}
22952403
22962404// assign
22972405
22982406template <class _CharT, class _Traits, class _Allocator>
22992407template <bool __is_short>
2408_LIBCPP_CONSTEXPR_AFTER_CXX17
23002409basic_string<_CharT, _Traits, _Allocator>&
23012410basic_string<_CharT, _Traits, _Allocator>::__assign_no_alias(
23022411 const value_type* __s, size_type __n) {
2303 size_type __cap = __is_short ? __min_cap : __get_long_cap();
2412 size_type __cap = __is_short ? static_cast<size_type>(__min_cap) : __get_long_cap();
23042413 if (__n < __cap) {
23052414 pointer __p = __is_short ? __get_short_pointer() : __get_long_pointer();
23062415 __is_short ? __set_short_size(__n) : __set_long_size(__n);
2307 traits_type::copy(_VSTD::__to_address(__p), __s, __n);
2416 traits_type::copy(std::__to_address(__p), __s, __n);
23082417 traits_type::assign(__p[__n], value_type());
23092418 __invalidate_iterators_past(__n);
23102419 } else {
......@@ -2315,12 +2424,13 @@ basic_string<_CharT, _Traits, _Allocator>::__assign_no_alias(
23152424}
23162425
23172426template <class _CharT, class _Traits, class _Allocator>
2427_LIBCPP_CONSTEXPR_AFTER_CXX17
23182428basic_string<_CharT, _Traits, _Allocator>&
23192429basic_string<_CharT, _Traits, _Allocator>::__assign_external(
23202430 const value_type* __s, size_type __n) {
23212431 size_type __cap = capacity();
23222432 if (__cap >= __n) {
2323 value_type* __p = _VSTD::__to_address(__get_pointer());
2433 value_type* __p = std::__to_address(__get_pointer());
23242434 traits_type::move(__p, __s, __n);
23252435 return __null_terminate_at(__p, __n);
23262436 } else {
......@@ -2331,6 +2441,7 @@ basic_string<_CharT, _Traits, _Allocator>::__assign_external(
23312441}
23322442
23332443template <class _CharT, class _Traits, class _Allocator>
2444_LIBCPP_CONSTEXPR_AFTER_CXX17
23342445basic_string<_CharT, _Traits, _Allocator>&
23352446basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
23362447{
......@@ -2341,6 +2452,7 @@ basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_ty
23412452}
23422453
23432454template <class _CharT, class _Traits, class _Allocator>
2455_LIBCPP_CONSTEXPR_AFTER_CXX17
23442456basic_string<_CharT, _Traits, _Allocator>&
23452457basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
23462458{
......@@ -2350,12 +2462,13 @@ basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
23502462 size_type __sz = size();
23512463 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
23522464 }
2353 value_type* __p = _VSTD::__to_address(__get_pointer());
2465 value_type* __p = std::__to_address(__get_pointer());
23542466 traits_type::assign(__p, __n, __c);
23552467 return __null_terminate_at(__p, __n);
23562468}
23572469
23582470template <class _CharT, class _Traits, class _Allocator>
2471_LIBCPP_CONSTEXPR_AFTER_CXX17
23592472basic_string<_CharT, _Traits, _Allocator>&
23602473basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
23612474{
......@@ -2377,6 +2490,7 @@ basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
23772490}
23782491
23792492template <class _CharT, class _Traits, class _Allocator>
2493_LIBCPP_CONSTEXPR_AFTER_CXX17
23802494basic_string<_CharT, _Traits, _Allocator>&
23812495basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
23822496{
......@@ -2398,7 +2512,7 @@ basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
23982512#ifndef _LIBCPP_CXX03_LANG
23992513
24002514template <class _CharT, class _Traits, class _Allocator>
2401inline
2515inline _LIBCPP_CONSTEXPR_AFTER_CXX17
24022516void
24032517basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
24042518 _NOEXCEPT_(__alloc_traits::is_always_equal::value)
......@@ -2410,7 +2524,7 @@ basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, fa
24102524}
24112525
24122526template <class _CharT, class _Traits, class _Allocator>
2413inline
2527inline _LIBCPP_CONSTEXPR_AFTER_CXX17
24142528void
24152529basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
24162530#if _LIBCPP_STD_VER > 14
......@@ -2431,12 +2545,16 @@ basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, tr
24312545 }
24322546 __move_assign_alloc(__str);
24332547 __r_.first() = __str.__r_.first();
2434 __str.__set_short_size(0);
2435 traits_type::assign(__str.__get_short_pointer()[0], value_type());
2548 if (__libcpp_is_constant_evaluated()) {
2549 __str.__default_init();
2550 } else {
2551 __str.__set_short_size(0);
2552 traits_type::assign(__str.__get_short_pointer()[0], value_type());
2553 }
24362554}
24372555
24382556template <class _CharT, class _Traits, class _Allocator>
2439inline
2557inline _LIBCPP_CONSTEXPR_AFTER_CXX17
24402558basic_string<_CharT, _Traits, _Allocator>&
24412559basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
24422560 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
......@@ -2450,6 +2568,7 @@ basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
24502568
24512569template <class _CharT, class _Traits, class _Allocator>
24522570template<class _InputIterator>
2571_LIBCPP_CONSTEXPR_AFTER_CXX17
24532572__enable_if_t
24542573<
24552574 __is_exactly_cpp17_input_iterator<_InputIterator>::value,
......@@ -2464,6 +2583,7 @@ basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _Input
24642583
24652584template <class _CharT, class _Traits, class _Allocator>
24662585template<class _ForwardIterator>
2586_LIBCPP_CONSTEXPR_AFTER_CXX17
24672587__enable_if_t
24682588<
24692589 __is_cpp17_forward_iterator<_ForwardIterator>::value,
......@@ -2473,7 +2593,7 @@ basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _For
24732593{
24742594 size_type __cap = capacity();
24752595 size_type __n = __string_is_trivial_iterator<_ForwardIterator>::value ?
2476 static_cast<size_type>(_VSTD::distance(__first, __last)) : 0;
2596 static_cast<size_type>(std::distance(__first, __last)) : 0;
24772597
24782598 if (__string_is_trivial_iterator<_ForwardIterator>::value &&
24792599 (__cap >= __n || !__addr_in_range(*__first)))
......@@ -2499,17 +2619,19 @@ basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _For
24992619}
25002620
25012621template <class _CharT, class _Traits, class _Allocator>
2622_LIBCPP_CONSTEXPR_AFTER_CXX17
25022623basic_string<_CharT, _Traits, _Allocator>&
25032624basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
25042625{
25052626 size_type __sz = __str.size();
25062627 if (__pos > __sz)
25072628 __throw_out_of_range();
2508 return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
2629 return assign(__str.data() + __pos, std::min(__n, __sz - __pos));
25092630}
25102631
25112632template <class _CharT, class _Traits, class _Allocator>
25122633template <class _Tp>
2634_LIBCPP_CONSTEXPR_AFTER_CXX17
25132635__enable_if_t
25142636<
25152637 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
......@@ -2522,17 +2644,19 @@ basic_string<_CharT, _Traits, _Allocator>::assign(const _Tp & __t, size_type __p
25222644 size_type __sz = __sv.size();
25232645 if (__pos > __sz)
25242646 __throw_out_of_range();
2525 return assign(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2647 return assign(__sv.data() + __pos, std::min(__n, __sz - __pos));
25262648}
25272649
25282650
25292651template <class _CharT, class _Traits, class _Allocator>
2652_LIBCPP_CONSTEXPR_AFTER_CXX17
25302653basic_string<_CharT, _Traits, _Allocator>&
25312654basic_string<_CharT, _Traits, _Allocator>::__assign_external(const value_type* __s) {
25322655 return __assign_external(__s, traits_type::length(__s));
25332656}
25342657
25352658template <class _CharT, class _Traits, class _Allocator>
2659_LIBCPP_CONSTEXPR_AFTER_CXX17
25362660basic_string<_CharT, _Traits, _Allocator>&
25372661basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
25382662{
......@@ -2546,6 +2670,7 @@ basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
25462670// append
25472671
25482672template <class _CharT, class _Traits, class _Allocator>
2673_LIBCPP_CONSTEXPR_AFTER_CXX17
25492674basic_string<_CharT, _Traits, _Allocator>&
25502675basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
25512676{
......@@ -2556,7 +2681,7 @@ basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_ty
25562681 {
25572682 if (__n)
25582683 {
2559 value_type* __p = _VSTD::__to_address(__get_pointer());
2684 value_type* __p = std::__to_address(__get_pointer());
25602685 traits_type::copy(__p + __sz, __s, __n);
25612686 __sz += __n;
25622687 __set_size(__sz);
......@@ -2569,6 +2694,7 @@ basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_ty
25692694}
25702695
25712696template <class _CharT, class _Traits, class _Allocator>
2697_LIBCPP_CONSTEXPR_AFTER_CXX17
25722698basic_string<_CharT, _Traits, _Allocator>&
25732699basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
25742700{
......@@ -2579,7 +2705,7 @@ basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
25792705 if (__cap - __sz < __n)
25802706 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
25812707 pointer __p = __get_pointer();
2582 traits_type::assign(_VSTD::__to_address(__p) + __sz, __n, __c);
2708 traits_type::assign(std::__to_address(__p) + __sz, __n, __c);
25832709 __sz += __n;
25842710 __set_size(__sz);
25852711 traits_type::assign(__p[__sz], value_type());
......@@ -2588,7 +2714,7 @@ basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
25882714}
25892715
25902716template <class _CharT, class _Traits, class _Allocator>
2591inline void
2717_LIBCPP_CONSTEXPR_AFTER_CXX17 inline void
25922718basic_string<_CharT, _Traits, _Allocator>::__append_default_init(size_type __n)
25932719{
25942720 if (__n)
......@@ -2605,6 +2731,7 @@ basic_string<_CharT, _Traits, _Allocator>::__append_default_init(size_type __n)
26052731}
26062732
26072733template <class _CharT, class _Traits, class _Allocator>
2734_LIBCPP_CONSTEXPR_AFTER_CXX17
26082735void
26092736basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
26102737{
......@@ -2626,7 +2753,7 @@ basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
26262753 __grow_by(__cap, 1, __sz, __sz, 0);
26272754 __is_short = false; // the string is always long after __grow_by
26282755 }
2629 pointer __p;
2756 pointer __p = __get_pointer();
26302757 if (__is_short)
26312758 {
26322759 __p = __get_short_pointer() + __sz;
......@@ -2643,6 +2770,7 @@ basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
26432770
26442771template <class _CharT, class _Traits, class _Allocator>
26452772template<class _ForwardIterator>
2773_LIBCPP_CONSTEXPR_AFTER_CXX17
26462774__enable_if_t
26472775<
26482776 __is_cpp17_forward_iterator<_ForwardIterator>::value,
......@@ -2653,7 +2781,7 @@ basic_string<_CharT, _Traits, _Allocator>::append(
26532781{
26542782 size_type __sz = size();
26552783 size_type __cap = capacity();
2656 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
2784 size_type __n = static_cast<size_type>(std::distance(__first, __last));
26572785 if (__n)
26582786 {
26592787 if (__string_is_trivial_iterator<_ForwardIterator>::value &&
......@@ -2677,7 +2805,7 @@ basic_string<_CharT, _Traits, _Allocator>::append(
26772805}
26782806
26792807template <class _CharT, class _Traits, class _Allocator>
2680inline
2808inline _LIBCPP_CONSTEXPR_AFTER_CXX17
26812809basic_string<_CharT, _Traits, _Allocator>&
26822810basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
26832811{
......@@ -2685,17 +2813,19 @@ basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
26852813}
26862814
26872815template <class _CharT, class _Traits, class _Allocator>
2816_LIBCPP_CONSTEXPR_AFTER_CXX17
26882817basic_string<_CharT, _Traits, _Allocator>&
26892818basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
26902819{
26912820 size_type __sz = __str.size();
26922821 if (__pos > __sz)
26932822 __throw_out_of_range();
2694 return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
2823 return append(__str.data() + __pos, std::min(__n, __sz - __pos));
26952824}
26962825
26972826template <class _CharT, class _Traits, class _Allocator>
26982827template <class _Tp>
2828_LIBCPP_CONSTEXPR_AFTER_CXX17
26992829 __enable_if_t
27002830 <
27012831 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
......@@ -2707,10 +2837,11 @@ basic_string<_CharT, _Traits, _Allocator>::append(const _Tp & __t, size_type __p
27072837 size_type __sz = __sv.size();
27082838 if (__pos > __sz)
27092839 __throw_out_of_range();
2710 return append(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2840 return append(__sv.data() + __pos, std::min(__n, __sz - __pos));
27112841}
27122842
27132843template <class _CharT, class _Traits, class _Allocator>
2844_LIBCPP_CONSTEXPR_AFTER_CXX17
27142845basic_string<_CharT, _Traits, _Allocator>&
27152846basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
27162847{
......@@ -2721,6 +2852,7 @@ basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
27212852// insert
27222853
27232854template <class _CharT, class _Traits, class _Allocator>
2855_LIBCPP_CONSTEXPR_AFTER_CXX17
27242856basic_string<_CharT, _Traits, _Allocator>&
27252857basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
27262858{
......@@ -2729,11 +2861,18 @@ basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_t
27292861 if (__pos > __sz)
27302862 __throw_out_of_range();
27312863 size_type __cap = capacity();
2864 if (__libcpp_is_constant_evaluated()) {
2865 if (__cap - __sz >= __n)
2866 __grow_by_and_replace(__cap, 0, __sz, __pos, 0, __n, __s);
2867 else
2868 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2869 return *this;
2870 }
27322871 if (__cap - __sz >= __n)
27332872 {
27342873 if (__n)
27352874 {
2736 value_type* __p = _VSTD::__to_address(__get_pointer());
2875 value_type* __p = std::__to_address(__get_pointer());
27372876 size_type __n_move = __sz - __pos;
27382877 if (__n_move != 0)
27392878 {
......@@ -2753,6 +2892,7 @@ basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_t
27532892}
27542893
27552894template <class _CharT, class _Traits, class _Allocator>
2895_LIBCPP_CONSTEXPR_AFTER_CXX17
27562896basic_string<_CharT, _Traits, _Allocator>&
27572897basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
27582898{
......@@ -2765,7 +2905,7 @@ basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n
27652905 value_type* __p;
27662906 if (__cap - __sz >= __n)
27672907 {
2768 __p = _VSTD::__to_address(__get_pointer());
2908 __p = std::__to_address(__get_pointer());
27692909 size_type __n_move = __sz - __pos;
27702910 if (__n_move != 0)
27712911 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
......@@ -2773,7 +2913,7 @@ basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n
27732913 else
27742914 {
27752915 __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
2776 __p = _VSTD::__to_address(__get_long_pointer());
2916 __p = std::__to_address(__get_long_pointer());
27772917 }
27782918 traits_type::assign(__p + __pos, __n, __c);
27792919 __sz += __n;
......@@ -2785,6 +2925,7 @@ basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n
27852925
27862926template <class _CharT, class _Traits, class _Allocator>
27872927template<class _InputIterator>
2928_LIBCPP_CONSTEXPR_AFTER_CXX17
27882929__enable_if_t
27892930<
27902931 __is_exactly_cpp17_input_iterator<_InputIterator>::value,
......@@ -2801,6 +2942,7 @@ basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIt
28012942
28022943template <class _CharT, class _Traits, class _Allocator>
28032944template<class _ForwardIterator>
2945_LIBCPP_CONSTEXPR_AFTER_CXX17
28042946__enable_if_t
28052947<
28062948 __is_cpp17_forward_iterator<_ForwardIterator>::value,
......@@ -2808,49 +2950,27 @@ __enable_if_t
28082950>
28092951basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
28102952{
2811 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2812 "string::insert(iterator, range) called with an iterator not"
2813 " referring to this string");
2953 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2954 "string::insert(iterator, range) called with an iterator not referring to this string");
28142955
28152956 size_type __ip = static_cast<size_type>(__pos - begin());
2816 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
2817 if (__n)
2957 size_type __n = static_cast<size_type>(std::distance(__first, __last));
2958 if (__n == 0)
2959 return begin() + __ip;
2960
2961 if (__string_is_trivial_iterator<_ForwardIterator>::value && !__addr_in_range(*__first))
28182962 {
2819 if (__string_is_trivial_iterator<_ForwardIterator>::value &&
2820 !__addr_in_range(*__first))
2821 {
2822 size_type __sz = size();
2823 size_type __cap = capacity();
2824 value_type* __p;
2825 if (__cap - __sz >= __n)
2826 {
2827 __p = _VSTD::__to_address(__get_pointer());
2828 size_type __n_move = __sz - __ip;
2829 if (__n_move != 0)
2830 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
2831 }
2832 else
2833 {
2834 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
2835 __p = _VSTD::__to_address(__get_long_pointer());
2836 }
2837 __sz += __n;
2838 __set_size(__sz);
2839 traits_type::assign(__p[__sz], value_type());
2840 for (__p += __ip; __first != __last; ++__p, (void) ++__first)
2841 traits_type::assign(*__p, *__first);
2842 }
2843 else
2844 {
2845 const basic_string __temp(__first, __last, __alloc());
2846 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
2847 }
2963 return __insert_from_safe_copy(__n, __ip, __first, __last);
2964 }
2965 else
2966 {
2967 const basic_string __temp(__first, __last, __alloc());
2968 return __insert_from_safe_copy(__n, __ip, __temp.begin(), __temp.end());
28482969 }
2849 return begin() + __ip;
28502970}
28512971
28522972template <class _CharT, class _Traits, class _Allocator>
2853inline
2973inline _LIBCPP_CONSTEXPR_AFTER_CXX17
28542974basic_string<_CharT, _Traits, _Allocator>&
28552975basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
28562976{
......@@ -2858,6 +2978,7 @@ basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_
28582978}
28592979
28602980template <class _CharT, class _Traits, class _Allocator>
2981_LIBCPP_CONSTEXPR_AFTER_CXX17
28612982basic_string<_CharT, _Traits, _Allocator>&
28622983basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
28632984 size_type __pos2, size_type __n)
......@@ -2865,11 +2986,12 @@ basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_
28652986 size_type __str_sz = __str.size();
28662987 if (__pos2 > __str_sz)
28672988 __throw_out_of_range();
2868 return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
2989 return insert(__pos1, __str.data() + __pos2, std::min(__n, __str_sz - __pos2));
28692990}
28702991
28712992template <class _CharT, class _Traits, class _Allocator>
28722993template <class _Tp>
2994_LIBCPP_CONSTEXPR_AFTER_CXX17
28732995__enable_if_t
28742996<
28752997 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
......@@ -2882,10 +3004,11 @@ basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& _
28823004 size_type __str_sz = __sv.size();
28833005 if (__pos2 > __str_sz)
28843006 __throw_out_of_range();
2885 return insert(__pos1, __sv.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
3007 return insert(__pos1, __sv.data() + __pos2, std::min(__n, __str_sz - __pos2));
28863008}
28873009
28883010template <class _CharT, class _Traits, class _Allocator>
3011_LIBCPP_CONSTEXPR_AFTER_CXX17
28893012basic_string<_CharT, _Traits, _Allocator>&
28903013basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
28913014{
......@@ -2894,6 +3017,7 @@ basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_t
28943017}
28953018
28963019template <class _CharT, class _Traits, class _Allocator>
3020_LIBCPP_CONSTEXPR_AFTER_CXX17
28973021typename basic_string<_CharT, _Traits, _Allocator>::iterator
28983022basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
28993023{
......@@ -2908,11 +3032,11 @@ basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_ty
29083032 if (__cap == __sz)
29093033 {
29103034 __grow_by(__cap, 1, __sz, __ip, 0, 1);
2911 __p = _VSTD::__to_address(__get_long_pointer());
3035 __p = std::__to_address(__get_long_pointer());
29123036 }
29133037 else
29143038 {
2915 __p = _VSTD::__to_address(__get_pointer());
3039 __p = std::__to_address(__get_pointer());
29163040 size_type __n_move = __sz - __ip;
29173041 if (__n_move != 0)
29183042 traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
......@@ -2924,7 +3048,7 @@ basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_ty
29243048}
29253049
29263050template <class _CharT, class _Traits, class _Allocator>
2927inline
3051inline _LIBCPP_CONSTEXPR_AFTER_CXX17
29283052typename basic_string<_CharT, _Traits, _Allocator>::iterator
29293053basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
29303054{
......@@ -2939,6 +3063,7 @@ basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_typ
29393063// replace
29403064
29413065template <class _CharT, class _Traits, class _Allocator>
3066_LIBCPP_CONSTEXPR_AFTER_CXX17
29423067basic_string<_CharT, _Traits, _Allocator>&
29433068basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2)
29443069 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
......@@ -2947,11 +3072,15 @@ basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __
29473072 size_type __sz = size();
29483073 if (__pos > __sz)
29493074 __throw_out_of_range();
2950 __n1 = _VSTD::min(__n1, __sz - __pos);
3075 __n1 = std::min(__n1, __sz - __pos);
29513076 size_type __cap = capacity();
29523077 if (__cap - __sz + __n1 >= __n2)
29533078 {
2954 value_type* __p = _VSTD::__to_address(__get_pointer());
3079 if (__libcpp_is_constant_evaluated()) {
3080 __grow_by_and_replace(__cap, 0, __sz, __pos, __n1, __n2, __s);
3081 return *this;
3082 }
3083 value_type* __p = std::__to_address(__get_pointer());
29553084 if (__n1 != __n2)
29563085 {
29573086 size_type __n_move = __sz - __pos - __n1;
......@@ -2988,18 +3117,19 @@ basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __
29883117}
29893118
29903119template <class _CharT, class _Traits, class _Allocator>
3120_LIBCPP_CONSTEXPR_AFTER_CXX17
29913121basic_string<_CharT, _Traits, _Allocator>&
29923122basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
29933123{
29943124 size_type __sz = size();
29953125 if (__pos > __sz)
29963126 __throw_out_of_range();
2997 __n1 = _VSTD::min(__n1, __sz - __pos);
3127 __n1 = std::min(__n1, __sz - __pos);
29983128 size_type __cap = capacity();
29993129 value_type* __p;
30003130 if (__cap - __sz + __n1 >= __n2)
30013131 {
3002 __p = _VSTD::__to_address(__get_pointer());
3132 __p = std::__to_address(__get_pointer());
30033133 if (__n1 != __n2)
30043134 {
30053135 size_type __n_move = __sz - __pos - __n1;
......@@ -3010,7 +3140,7 @@ basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __
30103140 else
30113141 {
30123142 __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
3013 __p = _VSTD::__to_address(__get_long_pointer());
3143 __p = std::__to_address(__get_long_pointer());
30143144 }
30153145 traits_type::assign(__p + __pos, __n2, __c);
30163146 return __null_terminate_at(__p, __sz - (__n1 - __n2));
......@@ -3018,6 +3148,7 @@ basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __
30183148
30193149template <class _CharT, class _Traits, class _Allocator>
30203150template<class _InputIterator>
3151_LIBCPP_CONSTEXPR_AFTER_CXX17
30213152__enable_if_t
30223153<
30233154 __is_cpp17_input_iterator<_InputIterator>::value,
......@@ -3031,7 +3162,7 @@ basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_it
30313162}
30323163
30333164template <class _CharT, class _Traits, class _Allocator>
3034inline
3165inline _LIBCPP_CONSTEXPR_AFTER_CXX17
30353166basic_string<_CharT, _Traits, _Allocator>&
30363167basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
30373168{
......@@ -3039,6 +3170,7 @@ basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type _
30393170}
30403171
30413172template <class _CharT, class _Traits, class _Allocator>
3173_LIBCPP_CONSTEXPR_AFTER_CXX17
30423174basic_string<_CharT, _Traits, _Allocator>&
30433175basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
30443176 size_type __pos2, size_type __n2)
......@@ -3046,11 +3178,12 @@ basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type _
30463178 size_type __str_sz = __str.size();
30473179 if (__pos2 > __str_sz)
30483180 __throw_out_of_range();
3049 return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
3181 return replace(__pos1, __n1, __str.data() + __pos2, std::min(__n2, __str_sz - __pos2));
30503182}
30513183
30523184template <class _CharT, class _Traits, class _Allocator>
30533185template <class _Tp>
3186_LIBCPP_CONSTEXPR_AFTER_CXX17
30543187__enable_if_t
30553188<
30563189 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
......@@ -3063,10 +3196,11 @@ basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type _
30633196 size_type __str_sz = __sv.size();
30643197 if (__pos2 > __str_sz)
30653198 __throw_out_of_range();
3066 return replace(__pos1, __n1, __sv.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
3199 return replace(__pos1, __n1, __sv.data() + __pos2, std::min(__n2, __str_sz - __pos2));
30673200}
30683201
30693202template <class _CharT, class _Traits, class _Allocator>
3203_LIBCPP_CONSTEXPR_AFTER_CXX17
30703204basic_string<_CharT, _Traits, _Allocator>&
30713205basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
30723206{
......@@ -3075,7 +3209,7 @@ basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __
30753209}
30763210
30773211template <class _CharT, class _Traits, class _Allocator>
3078inline
3212inline _LIBCPP_CONSTEXPR_AFTER_CXX17
30793213basic_string<_CharT, _Traits, _Allocator>&
30803214basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
30813215{
......@@ -3084,7 +3218,7 @@ basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_it
30843218}
30853219
30863220template <class _CharT, class _Traits, class _Allocator>
3087inline
3221inline _LIBCPP_CONSTEXPR_AFTER_CXX17
30883222basic_string<_CharT, _Traits, _Allocator>&
30893223basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n)
30903224{
......@@ -3092,7 +3226,7 @@ basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_it
30923226}
30933227
30943228template <class _CharT, class _Traits, class _Allocator>
3095inline
3229inline _LIBCPP_CONSTEXPR_AFTER_CXX17
30963230basic_string<_CharT, _Traits, _Allocator>&
30973231basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
30983232{
......@@ -3100,7 +3234,7 @@ basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_it
31003234}
31013235
31023236template <class _CharT, class _Traits, class _Allocator>
3103inline
3237inline _LIBCPP_CONSTEXPR_AFTER_CXX17
31043238basic_string<_CharT, _Traits, _Allocator>&
31053239basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
31063240{
......@@ -3112,6 +3246,7 @@ basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_it
31123246// 'externally instantiated' erase() implementation, called when __n != npos.
31133247// Does not check __pos against size()
31143248template <class _CharT, class _Traits, class _Allocator>
3249_LIBCPP_CONSTEXPR_AFTER_CXX17
31153250void
31163251basic_string<_CharT, _Traits, _Allocator>::__erase_external_with_move(
31173252 size_type __pos, size_type __n)
......@@ -3119,8 +3254,8 @@ basic_string<_CharT, _Traits, _Allocator>::__erase_external_with_move(
31193254 if (__n)
31203255 {
31213256 size_type __sz = size();
3122 value_type* __p = _VSTD::__to_address(__get_pointer());
3123 __n = _VSTD::min(__n, __sz - __pos);
3257 value_type* __p = std::__to_address(__get_pointer());
3258 __n = std::min(__n, __sz - __pos);
31243259 size_type __n_move = __sz - __pos - __n;
31253260 if (__n_move != 0)
31263261 traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
......@@ -3129,6 +3264,7 @@ basic_string<_CharT, _Traits, _Allocator>::__erase_external_with_move(
31293264}
31303265
31313266template <class _CharT, class _Traits, class _Allocator>
3267_LIBCPP_CONSTEXPR_AFTER_CXX17
31323268basic_string<_CharT, _Traits, _Allocator>&
31333269basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos,
31343270 size_type __n) {
......@@ -3143,7 +3279,7 @@ basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos,
31433279}
31443280
31453281template <class _CharT, class _Traits, class _Allocator>
3146inline
3282inline _LIBCPP_CONSTEXPR_AFTER_CXX17
31473283typename basic_string<_CharT, _Traits, _Allocator>::iterator
31483284basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
31493285{
......@@ -3159,7 +3295,7 @@ basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
31593295}
31603296
31613297template <class _CharT, class _Traits, class _Allocator>
3162inline
3298inline _LIBCPP_CONSTEXPR_AFTER_CXX17
31633299typename basic_string<_CharT, _Traits, _Allocator>::iterator
31643300basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
31653301{
......@@ -3175,7 +3311,7 @@ basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_i
31753311}
31763312
31773313template <class _CharT, class _Traits, class _Allocator>
3178inline
3314inline _LIBCPP_CONSTEXPR_AFTER_CXX17
31793315void
31803316basic_string<_CharT, _Traits, _Allocator>::pop_back()
31813317{
......@@ -3184,11 +3320,11 @@ basic_string<_CharT, _Traits, _Allocator>::pop_back()
31843320}
31853321
31863322template <class _CharT, class _Traits, class _Allocator>
3187inline
3323inline _LIBCPP_CONSTEXPR_AFTER_CXX17
31883324void
31893325basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
31903326{
3191 __invalidate_all_iterators();
3327 std::__debug_db_invalidate_all(this);
31923328 if (__is_long())
31933329 {
31943330 traits_type::assign(*__get_long_pointer(), value_type());
......@@ -3202,14 +3338,15 @@ basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
32023338}
32033339
32043340template <class _CharT, class _Traits, class _Allocator>
3205inline
3341inline _LIBCPP_CONSTEXPR_AFTER_CXX17
32063342void
32073343basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
32083344{
3209 __null_terminate_at(_VSTD::__to_address(__get_pointer()), __pos);
3345 __null_terminate_at(std::__to_address(__get_pointer()), __pos);
32103346}
32113347
32123348template <class _CharT, class _Traits, class _Allocator>
3349_LIBCPP_CONSTEXPR_AFTER_CXX17
32133350void
32143351basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
32153352{
......@@ -3221,7 +3358,7 @@ basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
32213358}
32223359
32233360template <class _CharT, class _Traits, class _Allocator>
3224inline void
3361_LIBCPP_CONSTEXPR_AFTER_CXX17 inline void
32253362basic_string<_CharT, _Traits, _Allocator>::__resize_default_init(size_type __n)
32263363{
32273364 size_type __sz = size();
......@@ -3232,19 +3369,21 @@ basic_string<_CharT, _Traits, _Allocator>::__resize_default_init(size_type __n)
32323369}
32333370
32343371template <class _CharT, class _Traits, class _Allocator>
3235inline
3372inline _LIBCPP_CONSTEXPR_AFTER_CXX17
32363373typename basic_string<_CharT, _Traits, _Allocator>::size_type
32373374basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
32383375{
32393376 size_type __m = __alloc_traits::max_size(__alloc());
3240#ifdef _LIBCPP_BIG_ENDIAN
3241 return (__m <= ~__long_mask ? __m : __m/2) - __alignment;
3242#else
3243 return __m - __alignment;
3244#endif
3377 if (__m <= std::numeric_limits<size_type>::max() / 2) {
3378 return __m - __alignment;
3379 } else {
3380 bool __uses_lsb = __endian_factor == 2;
3381 return __uses_lsb ? __m - __alignment : (__m / 2) - __alignment;
3382 }
32453383}
32463384
32473385template <class _CharT, class _Traits, class _Allocator>
3386_LIBCPP_CONSTEXPR_AFTER_CXX17
32483387void
32493388basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __requested_capacity)
32503389{
......@@ -3257,7 +3396,7 @@ basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __requested_capacit
32573396 if (__requested_capacity <= capacity())
32583397 return;
32593398
3260 size_type __target_capacity = _VSTD::max(__requested_capacity, size());
3399 size_type __target_capacity = std::max(__requested_capacity, size());
32613400 __target_capacity = __recommend(__target_capacity);
32623401 if (__target_capacity == capacity()) return;
32633402
......@@ -3265,7 +3404,7 @@ basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __requested_capacit
32653404}
32663405
32673406template <class _CharT, class _Traits, class _Allocator>
3268inline
3407inline _LIBCPP_CONSTEXPR_AFTER_CXX17
32693408void
32703409basic_string<_CharT, _Traits, _Allocator>::shrink_to_fit() _NOEXCEPT
32713410{
......@@ -3276,7 +3415,7 @@ basic_string<_CharT, _Traits, _Allocator>::shrink_to_fit() _NOEXCEPT
32763415}
32773416
32783417template <class _CharT, class _Traits, class _Allocator>
3279inline
3418inline _LIBCPP_CONSTEXPR_AFTER_CXX17
32803419void
32813420basic_string<_CharT, _Traits, _Allocator>::__shrink_or_extend(size_type __target_capacity)
32823421{
......@@ -3285,7 +3424,7 @@ basic_string<_CharT, _Traits, _Allocator>::__shrink_or_extend(size_type __target
32853424
32863425 pointer __new_data, __p;
32873426 bool __was_long, __now_long;
3288 if (__target_capacity == __min_cap - 1)
3427 if (__fits_in_sso(__target_capacity))
32893428 {
32903429 __was_long = true;
32913430 __now_long = false;
......@@ -3294,15 +3433,20 @@ basic_string<_CharT, _Traits, _Allocator>::__shrink_or_extend(size_type __target
32943433 }
32953434 else
32963435 {
3297 if (__target_capacity > __cap)
3298 __new_data = __alloc_traits::allocate(__alloc(), __target_capacity+1);
3436 if (__target_capacity > __cap) {
3437 auto __allocation = std::__allocate_at_least(__alloc(), __target_capacity + 1);
3438 __new_data = __allocation.ptr;
3439 __target_capacity = __allocation.count - 1;
3440 }
32993441 else
33003442 {
33013443 #ifndef _LIBCPP_NO_EXCEPTIONS
33023444 try
33033445 {
33043446 #endif // _LIBCPP_NO_EXCEPTIONS
3305 __new_data = __alloc_traits::allocate(__alloc(), __target_capacity+1);
3447 auto __allocation = std::__allocate_at_least(__alloc(), __target_capacity + 1);
3448 __new_data = __allocation.ptr;
3449 __target_capacity = __allocation.count - 1;
33063450 #ifndef _LIBCPP_NO_EXCEPTIONS
33073451 }
33083452 catch (...)
......@@ -3314,12 +3458,13 @@ basic_string<_CharT, _Traits, _Allocator>::__shrink_or_extend(size_type __target
33143458 return;
33153459 #endif // _LIBCPP_NO_EXCEPTIONS
33163460 }
3461 __begin_lifetime(__new_data, __target_capacity + 1);
33173462 __now_long = true;
33183463 __was_long = __is_long();
33193464 __p = __get_pointer();
33203465 }
3321 traits_type::copy(_VSTD::__to_address(__new_data),
3322 _VSTD::__to_address(__p), size()+1);
3466 traits_type::copy(std::__to_address(__new_data),
3467 std::__to_address(__p), size()+1);
33233468 if (__was_long)
33243469 __alloc_traits::deallocate(__alloc(), __p, __cap+1);
33253470 if (__now_long)
......@@ -3330,11 +3475,11 @@ basic_string<_CharT, _Traits, _Allocator>::__shrink_or_extend(size_type __target
33303475 }
33313476 else
33323477 __set_short_size(__sz);
3333 __invalidate_all_iterators();
3478 std::__debug_db_invalidate_all(this);
33343479}
33353480
33363481template <class _CharT, class _Traits, class _Allocator>
3337inline
3482inline _LIBCPP_CONSTEXPR_AFTER_CXX17
33383483typename basic_string<_CharT, _Traits, _Allocator>::const_reference
33393484basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const _NOEXCEPT
33403485{
......@@ -3343,7 +3488,7 @@ basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const _NO
33433488}
33443489
33453490template <class _CharT, class _Traits, class _Allocator>
3346inline
3491inline _LIBCPP_CONSTEXPR_AFTER_CXX17
33473492typename basic_string<_CharT, _Traits, _Allocator>::reference
33483493basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) _NOEXCEPT
33493494{
......@@ -3352,6 +3497,7 @@ basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) _NOEXCEPT
33523497}
33533498
33543499template <class _CharT, class _Traits, class _Allocator>
3500_LIBCPP_CONSTEXPR_AFTER_CXX17
33553501typename basic_string<_CharT, _Traits, _Allocator>::const_reference
33563502basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
33573503{
......@@ -3361,6 +3507,7 @@ basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
33613507}
33623508
33633509template <class _CharT, class _Traits, class _Allocator>
3510_LIBCPP_CONSTEXPR_AFTER_CXX17
33643511typename basic_string<_CharT, _Traits, _Allocator>::reference
33653512basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
33663513{
......@@ -3370,7 +3517,7 @@ basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
33703517}
33713518
33723519template <class _CharT, class _Traits, class _Allocator>
3373inline
3520inline _LIBCPP_CONSTEXPR_AFTER_CXX17
33743521typename basic_string<_CharT, _Traits, _Allocator>::reference
33753522basic_string<_CharT, _Traits, _Allocator>::front() _NOEXCEPT
33763523{
......@@ -3379,7 +3526,7 @@ basic_string<_CharT, _Traits, _Allocator>::front() _NOEXCEPT
33793526}
33803527
33813528template <class _CharT, class _Traits, class _Allocator>
3382inline
3529inline _LIBCPP_CONSTEXPR_AFTER_CXX17
33833530typename basic_string<_CharT, _Traits, _Allocator>::const_reference
33843531basic_string<_CharT, _Traits, _Allocator>::front() const _NOEXCEPT
33853532{
......@@ -3388,7 +3535,7 @@ basic_string<_CharT, _Traits, _Allocator>::front() const _NOEXCEPT
33883535}
33893536
33903537template <class _CharT, class _Traits, class _Allocator>
3391inline
3538inline _LIBCPP_CONSTEXPR_AFTER_CXX17
33923539typename basic_string<_CharT, _Traits, _Allocator>::reference
33933540basic_string<_CharT, _Traits, _Allocator>::back() _NOEXCEPT
33943541{
......@@ -3397,7 +3544,7 @@ basic_string<_CharT, _Traits, _Allocator>::back() _NOEXCEPT
33973544}
33983545
33993546template <class _CharT, class _Traits, class _Allocator>
3400inline
3547inline _LIBCPP_CONSTEXPR_AFTER_CXX17
34013548typename basic_string<_CharT, _Traits, _Allocator>::const_reference
34023549basic_string<_CharT, _Traits, _Allocator>::back() const _NOEXCEPT
34033550{
......@@ -3406,19 +3553,20 @@ basic_string<_CharT, _Traits, _Allocator>::back() const _NOEXCEPT
34063553}
34073554
34083555template <class _CharT, class _Traits, class _Allocator>
3556_LIBCPP_CONSTEXPR_AFTER_CXX17
34093557typename basic_string<_CharT, _Traits, _Allocator>::size_type
34103558basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
34113559{
34123560 size_type __sz = size();
34133561 if (__pos > __sz)
34143562 __throw_out_of_range();
3415 size_type __rlen = _VSTD::min(__n, __sz - __pos);
3563 size_type __rlen = std::min(__n, __sz - __pos);
34163564 traits_type::copy(__s, data() + __pos, __rlen);
34173565 return __rlen;
34183566}
34193567
34203568template <class _CharT, class _Traits, class _Allocator>
3421inline
3569inline _LIBCPP_CONSTEXPR_AFTER_CXX17
34223570basic_string<_CharT, _Traits, _Allocator>
34233571basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
34243572{
......@@ -3426,7 +3574,7 @@ basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n
34263574}
34273575
34283576template <class _CharT, class _Traits, class _Allocator>
3429inline
3577inline _LIBCPP_CONSTEXPR_AFTER_CXX17
34303578void
34313579basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
34323580#if _LIBCPP_STD_VER >= 14
......@@ -3436,21 +3584,18 @@ basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
34363584 __is_nothrow_swappable<allocator_type>::value)
34373585#endif
34383586{
3439#if _LIBCPP_DEBUG_LEVEL == 2
3440 if (!__libcpp_is_constant_evaluated()) {
3441 if (!__is_long())
3442 __get_db()->__invalidate_all(this);
3443 if (!__str.__is_long())
3444 __get_db()->__invalidate_all(&__str);
3445 __get_db()->swap(this, &__str);
3446 }
3447#endif
3587 if (!__is_long())
3588 std::__debug_db_invalidate_all(this);
3589 if (!__str.__is_long())
3590 std::__debug_db_invalidate_all(&__str);
3591 std::__debug_db_swap(this, &__str);
3592
34483593 _LIBCPP_ASSERT(
34493594 __alloc_traits::propagate_on_container_swap::value ||
34503595 __alloc_traits::is_always_equal::value ||
34513596 __alloc() == __str.__alloc(), "swapping non-equal allocators");
3452 _VSTD::swap(__r_.first(), __str.__r_.first());
3453 _VSTD::__swap_allocator(__alloc(), __str.__alloc());
3597 std::swap(__r_.first(), __str.__r_.first());
3598 std::__swap_allocator(__alloc(), __str.__alloc());
34543599}
34553600
34563601// find
......@@ -3459,12 +3604,13 @@ template <class _Traits>
34593604struct _LIBCPP_HIDDEN __traits_eq
34603605{
34613606 typedef typename _Traits::char_type char_type;
3462 _LIBCPP_INLINE_VISIBILITY
3607 _LIBCPP_HIDE_FROM_ABI
34633608 bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
34643609 {return _Traits::eq(__x, __y);}
34653610};
34663611
34673612template<class _CharT, class _Traits, class _Allocator>
3613_LIBCPP_CONSTEXPR_AFTER_CXX17
34683614typename basic_string<_CharT, _Traits, _Allocator>::size_type
34693615basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
34703616 size_type __pos,
......@@ -3476,7 +3622,7 @@ basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
34763622}
34773623
34783624template<class _CharT, class _Traits, class _Allocator>
3479inline
3625inline _LIBCPP_CONSTEXPR_AFTER_CXX17
34803626typename basic_string<_CharT, _Traits, _Allocator>::size_type
34813627basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
34823628 size_type __pos) const _NOEXCEPT
......@@ -3487,6 +3633,7 @@ basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
34873633
34883634template<class _CharT, class _Traits, class _Allocator>
34893635template <class _Tp>
3636_LIBCPP_CONSTEXPR_AFTER_CXX17
34903637__enable_if_t
34913638<
34923639 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
......@@ -3501,7 +3648,7 @@ basic_string<_CharT, _Traits, _Allocator>::find(const _Tp &__t,
35013648}
35023649
35033650template<class _CharT, class _Traits, class _Allocator>
3504inline
3651inline _LIBCPP_CONSTEXPR_AFTER_CXX17
35053652typename basic_string<_CharT, _Traits, _Allocator>::size_type
35063653basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
35073654 size_type __pos) const _NOEXCEPT
......@@ -3512,6 +3659,7 @@ basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
35123659}
35133660
35143661template<class _CharT, class _Traits, class _Allocator>
3662_LIBCPP_CONSTEXPR_AFTER_CXX17
35153663typename basic_string<_CharT, _Traits, _Allocator>::size_type
35163664basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
35173665 size_type __pos) const _NOEXCEPT
......@@ -3523,6 +3671,7 @@ basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
35233671// rfind
35243672
35253673template<class _CharT, class _Traits, class _Allocator>
3674_LIBCPP_CONSTEXPR_AFTER_CXX17
35263675typename basic_string<_CharT, _Traits, _Allocator>::size_type
35273676basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
35283677 size_type __pos,
......@@ -3534,7 +3683,7 @@ basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
35343683}
35353684
35363685template<class _CharT, class _Traits, class _Allocator>
3537inline
3686inline _LIBCPP_CONSTEXPR_AFTER_CXX17
35383687typename basic_string<_CharT, _Traits, _Allocator>::size_type
35393688basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
35403689 size_type __pos) const _NOEXCEPT
......@@ -3545,6 +3694,7 @@ basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
35453694
35463695template<class _CharT, class _Traits, class _Allocator>
35473696template <class _Tp>
3697_LIBCPP_CONSTEXPR_AFTER_CXX17
35483698__enable_if_t
35493699<
35503700 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
......@@ -3559,7 +3709,7 @@ basic_string<_CharT, _Traits, _Allocator>::rfind(const _Tp& __t,
35593709}
35603710
35613711template<class _CharT, class _Traits, class _Allocator>
3562inline
3712inline _LIBCPP_CONSTEXPR_AFTER_CXX17
35633713typename basic_string<_CharT, _Traits, _Allocator>::size_type
35643714basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
35653715 size_type __pos) const _NOEXCEPT
......@@ -3570,6 +3720,7 @@ basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
35703720}
35713721
35723722template<class _CharT, class _Traits, class _Allocator>
3723_LIBCPP_CONSTEXPR_AFTER_CXX17
35733724typename basic_string<_CharT, _Traits, _Allocator>::size_type
35743725basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
35753726 size_type __pos) const _NOEXCEPT
......@@ -3581,6 +3732,7 @@ basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
35813732// find_first_of
35823733
35833734template<class _CharT, class _Traits, class _Allocator>
3735_LIBCPP_CONSTEXPR_AFTER_CXX17
35843736typename basic_string<_CharT, _Traits, _Allocator>::size_type
35853737basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
35863738 size_type __pos,
......@@ -3592,7 +3744,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
35923744}
35933745
35943746template<class _CharT, class _Traits, class _Allocator>
3595inline
3747inline _LIBCPP_CONSTEXPR_AFTER_CXX17
35963748typename basic_string<_CharT, _Traits, _Allocator>::size_type
35973749basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
35983750 size_type __pos) const _NOEXCEPT
......@@ -3603,6 +3755,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __s
36033755
36043756template<class _CharT, class _Traits, class _Allocator>
36053757template <class _Tp>
3758_LIBCPP_CONSTEXPR_AFTER_CXX17
36063759__enable_if_t
36073760<
36083761 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
......@@ -3617,7 +3770,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_first_of(const _Tp& __t,
36173770}
36183771
36193772template<class _CharT, class _Traits, class _Allocator>
3620inline
3773inline _LIBCPP_CONSTEXPR_AFTER_CXX17
36213774typename basic_string<_CharT, _Traits, _Allocator>::size_type
36223775basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
36233776 size_type __pos) const _NOEXCEPT
......@@ -3628,7 +3781,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
36283781}
36293782
36303783template<class _CharT, class _Traits, class _Allocator>
3631inline
3784inline _LIBCPP_CONSTEXPR_AFTER_CXX17
36323785typename basic_string<_CharT, _Traits, _Allocator>::size_type
36333786basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
36343787 size_type __pos) const _NOEXCEPT
......@@ -3639,6 +3792,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
36393792// find_last_of
36403793
36413794template<class _CharT, class _Traits, class _Allocator>
3795inline _LIBCPP_CONSTEXPR_AFTER_CXX17
36423796typename basic_string<_CharT, _Traits, _Allocator>::size_type
36433797basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
36443798 size_type __pos,
......@@ -3650,7 +3804,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
36503804}
36513805
36523806template<class _CharT, class _Traits, class _Allocator>
3653inline
3807inline _LIBCPP_CONSTEXPR_AFTER_CXX17
36543808typename basic_string<_CharT, _Traits, _Allocator>::size_type
36553809basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
36563810 size_type __pos) const _NOEXCEPT
......@@ -3661,6 +3815,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __st
36613815
36623816template<class _CharT, class _Traits, class _Allocator>
36633817template <class _Tp>
3818_LIBCPP_CONSTEXPR_AFTER_CXX17
36643819__enable_if_t
36653820<
36663821 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
......@@ -3675,7 +3830,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_of(const _Tp& __t,
36753830}
36763831
36773832template<class _CharT, class _Traits, class _Allocator>
3678inline
3833inline _LIBCPP_CONSTEXPR_AFTER_CXX17
36793834typename basic_string<_CharT, _Traits, _Allocator>::size_type
36803835basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
36813836 size_type __pos) const _NOEXCEPT
......@@ -3686,7 +3841,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
36863841}
36873842
36883843template<class _CharT, class _Traits, class _Allocator>
3689inline
3844inline _LIBCPP_CONSTEXPR_AFTER_CXX17
36903845typename basic_string<_CharT, _Traits, _Allocator>::size_type
36913846basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
36923847 size_type __pos) const _NOEXCEPT
......@@ -3697,6 +3852,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
36973852// find_first_not_of
36983853
36993854template<class _CharT, class _Traits, class _Allocator>
3855_LIBCPP_CONSTEXPR_AFTER_CXX17
37003856typename basic_string<_CharT, _Traits, _Allocator>::size_type
37013857basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
37023858 size_type __pos,
......@@ -3708,7 +3864,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* _
37083864}
37093865
37103866template<class _CharT, class _Traits, class _Allocator>
3711inline
3867inline _LIBCPP_CONSTEXPR_AFTER_CXX17
37123868typename basic_string<_CharT, _Traits, _Allocator>::size_type
37133869basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
37143870 size_type __pos) const _NOEXCEPT
......@@ -3719,6 +3875,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string&
37193875
37203876template<class _CharT, class _Traits, class _Allocator>
37213877template <class _Tp>
3878_LIBCPP_CONSTEXPR_AFTER_CXX17
37223879__enable_if_t
37233880<
37243881 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
......@@ -3733,7 +3890,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const _Tp& __t,
37333890}
37343891
37353892template<class _CharT, class _Traits, class _Allocator>
3736inline
3893inline _LIBCPP_CONSTEXPR_AFTER_CXX17
37373894typename basic_string<_CharT, _Traits, _Allocator>::size_type
37383895basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
37393896 size_type __pos) const _NOEXCEPT
......@@ -3744,7 +3901,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* _
37443901}
37453902
37463903template<class _CharT, class _Traits, class _Allocator>
3747inline
3904inline _LIBCPP_CONSTEXPR_AFTER_CXX17
37483905typename basic_string<_CharT, _Traits, _Allocator>::size_type
37493906basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
37503907 size_type __pos) const _NOEXCEPT
......@@ -3756,6 +3913,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
37563913// find_last_not_of
37573914
37583915template<class _CharT, class _Traits, class _Allocator>
3916_LIBCPP_CONSTEXPR_AFTER_CXX17
37593917typename basic_string<_CharT, _Traits, _Allocator>::size_type
37603918basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
37613919 size_type __pos,
......@@ -3767,7 +3925,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __
37673925}
37683926
37693927template<class _CharT, class _Traits, class _Allocator>
3770inline
3928inline _LIBCPP_CONSTEXPR_AFTER_CXX17
37713929typename basic_string<_CharT, _Traits, _Allocator>::size_type
37723930basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
37733931 size_type __pos) const _NOEXCEPT
......@@ -3778,6 +3936,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string&
37783936
37793937template<class _CharT, class _Traits, class _Allocator>
37803938template <class _Tp>
3939_LIBCPP_CONSTEXPR_AFTER_CXX17
37813940__enable_if_t
37823941<
37833942 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
......@@ -3792,7 +3951,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const _Tp& __t,
37923951}
37933952
37943953template<class _CharT, class _Traits, class _Allocator>
3795inline
3954inline _LIBCPP_CONSTEXPR_AFTER_CXX17
37963955typename basic_string<_CharT, _Traits, _Allocator>::size_type
37973956basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
37983957 size_type __pos) const _NOEXCEPT
......@@ -3803,7 +3962,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __
38033962}
38043963
38053964template<class _CharT, class _Traits, class _Allocator>
3806inline
3965inline _LIBCPP_CONSTEXPR_AFTER_CXX17
38073966typename basic_string<_CharT, _Traits, _Allocator>::size_type
38083967basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
38093968 size_type __pos) const _NOEXCEPT
......@@ -3816,6 +3975,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
38163975
38173976template <class _CharT, class _Traits, class _Allocator>
38183977template <class _Tp>
3978_LIBCPP_CONSTEXPR_AFTER_CXX17
38193979__enable_if_t
38203980<
38213981 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
......@@ -3827,7 +3987,7 @@ basic_string<_CharT, _Traits, _Allocator>::compare(const _Tp& __t) const _NOEXCE
38273987 size_t __lhs_sz = size();
38283988 size_t __rhs_sz = __sv.size();
38293989 int __result = traits_type::compare(data(), __sv.data(),
3830 _VSTD::min(__lhs_sz, __rhs_sz));
3990 std::min(__lhs_sz, __rhs_sz));
38313991 if (__result != 0)
38323992 return __result;
38333993 if (__lhs_sz < __rhs_sz)
......@@ -3838,7 +3998,7 @@ basic_string<_CharT, _Traits, _Allocator>::compare(const _Tp& __t) const _NOEXCE
38383998}
38393999
38404000template <class _CharT, class _Traits, class _Allocator>
3841inline
4001inline _LIBCPP_CONSTEXPR_AFTER_CXX17
38424002int
38434003basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
38444004{
......@@ -3846,6 +4006,7 @@ basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) co
38464006}
38474007
38484008template <class _CharT, class _Traits, class _Allocator>
4009inline _LIBCPP_CONSTEXPR_AFTER_CXX17
38494010int
38504011basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
38514012 size_type __n1,
......@@ -3856,8 +4017,8 @@ basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
38564017 size_type __sz = size();
38574018 if (__pos1 > __sz || __n2 == npos)
38584019 __throw_out_of_range();
3859 size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
3860 int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
4020 size_type __rlen = std::min(__n1, __sz - __pos1);
4021 int __r = traits_type::compare(data() + __pos1, __s, std::min(__rlen, __n2));
38614022 if (__r == 0)
38624023 {
38634024 if (__rlen < __n2)
......@@ -3870,6 +4031,7 @@ basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
38704031
38714032template <class _CharT, class _Traits, class _Allocator>
38724033template <class _Tp>
4034_LIBCPP_CONSTEXPR_AFTER_CXX17
38734035__enable_if_t
38744036<
38754037 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
......@@ -3884,7 +4046,7 @@ basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
38844046}
38854047
38864048template <class _CharT, class _Traits, class _Allocator>
3887inline
4049inline _LIBCPP_CONSTEXPR_AFTER_CXX17
38884050int
38894051basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
38904052 size_type __n1,
......@@ -3895,6 +4057,7 @@ basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
38954057
38964058template <class _CharT, class _Traits, class _Allocator>
38974059template <class _Tp>
4060_LIBCPP_CONSTEXPR_AFTER_CXX17
38984061__enable_if_t
38994062<
39004063 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
......@@ -3912,6 +4075,7 @@ basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
39124075}
39134076
39144077template <class _CharT, class _Traits, class _Allocator>
4078_LIBCPP_CONSTEXPR_AFTER_CXX17
39154079int
39164080basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
39174081 size_type __n1,
......@@ -3923,6 +4087,7 @@ basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
39234087}
39244088
39254089template <class _CharT, class _Traits, class _Allocator>
4090_LIBCPP_CONSTEXPR_AFTER_CXX17
39264091int
39274092basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
39284093{
......@@ -3931,6 +4096,7 @@ basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const
39314096}
39324097
39334098template <class _CharT, class _Traits, class _Allocator>
4099_LIBCPP_CONSTEXPR_AFTER_CXX17
39344100int
39354101basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
39364102 size_type __n1,
......@@ -3943,7 +4109,7 @@ basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
39434109// __invariants
39444110
39454111template<class _CharT, class _Traits, class _Allocator>
3946inline
4112inline _LIBCPP_CONSTEXPR_AFTER_CXX17
39474113bool
39484114basic_string<_CharT, _Traits, _Allocator>::__invariants() const
39494115{
......@@ -3961,7 +4127,7 @@ basic_string<_CharT, _Traits, _Allocator>::__invariants() const
39614127// __clear_and_shrink
39624128
39634129template<class _CharT, class _Traits, class _Allocator>
3964inline
4130inline _LIBCPP_CONSTEXPR_AFTER_CXX17
39654131void
39664132basic_string<_CharT, _Traits, _Allocator>::__clear_and_shrink() _NOEXCEPT
39674133{
......@@ -3978,7 +4144,7 @@ basic_string<_CharT, _Traits, _Allocator>::__clear_and_shrink() _NOEXCEPT
39784144// operator==
39794145
39804146template<class _CharT, class _Traits, class _Allocator>
3981inline _LIBCPP_INLINE_VISIBILITY
4147inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI
39824148bool
39834149operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
39844150 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
......@@ -3990,7 +4156,7 @@ operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
39904156}
39914157
39924158template<class _Allocator>
3993inline _LIBCPP_INLINE_VISIBILITY
4159inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI
39944160bool
39954161operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
39964162 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
......@@ -4009,7 +4175,7 @@ operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
40094175}
40104176
40114177template<class _CharT, class _Traits, class _Allocator>
4012inline _LIBCPP_INLINE_VISIBILITY
4178inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI
40134179bool
40144180operator==(const _CharT* __lhs,
40154181 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
......@@ -4022,7 +4188,7 @@ operator==(const _CharT* __lhs,
40224188}
40234189
40244190template<class _CharT, class _Traits, class _Allocator>
4025inline _LIBCPP_INLINE_VISIBILITY
4191inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI
40264192bool
40274193operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
40284194 const _CharT* __rhs) _NOEXCEPT
......@@ -4035,7 +4201,7 @@ operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
40354201}
40364202
40374203template<class _CharT, class _Traits, class _Allocator>
4038inline _LIBCPP_INLINE_VISIBILITY
4204inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI
40394205bool
40404206operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
40414207 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
......@@ -4044,7 +4210,7 @@ operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
40444210}
40454211
40464212template<class _CharT, class _Traits, class _Allocator>
4047inline _LIBCPP_INLINE_VISIBILITY
4213inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI
40484214bool
40494215operator!=(const _CharT* __lhs,
40504216 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
......@@ -4053,7 +4219,7 @@ operator!=(const _CharT* __lhs,
40534219}
40544220
40554221template<class _CharT, class _Traits, class _Allocator>
4056inline _LIBCPP_INLINE_VISIBILITY
4222inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI
40574223bool
40584224operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
40594225 const _CharT* __rhs) _NOEXCEPT
......@@ -4064,7 +4230,7 @@ operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
40644230// operator<
40654231
40664232template<class _CharT, class _Traits, class _Allocator>
4067inline _LIBCPP_INLINE_VISIBILITY
4233inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI
40684234bool
40694235operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
40704236 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
......@@ -4073,7 +4239,7 @@ operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
40734239}
40744240
40754241template<class _CharT, class _Traits, class _Allocator>
4076inline _LIBCPP_INLINE_VISIBILITY
4242inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI
40774243bool
40784244operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
40794245 const _CharT* __rhs) _NOEXCEPT
......@@ -4082,7 +4248,7 @@ operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
40824248}
40834249
40844250template<class _CharT, class _Traits, class _Allocator>
4085inline _LIBCPP_INLINE_VISIBILITY
4251inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI
40864252bool
40874253operator< (const _CharT* __lhs,
40884254 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
......@@ -4093,7 +4259,7 @@ operator< (const _CharT* __lhs,
40934259// operator>
40944260
40954261template<class _CharT, class _Traits, class _Allocator>
4096inline _LIBCPP_INLINE_VISIBILITY
4262inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI
40974263bool
40984264operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
40994265 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
......@@ -4102,7 +4268,7 @@ operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
41024268}
41034269
41044270template<class _CharT, class _Traits, class _Allocator>
4105inline _LIBCPP_INLINE_VISIBILITY
4271inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI
41064272bool
41074273operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
41084274 const _CharT* __rhs) _NOEXCEPT
......@@ -4111,7 +4277,7 @@ operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
41114277}
41124278
41134279template<class _CharT, class _Traits, class _Allocator>
4114inline _LIBCPP_INLINE_VISIBILITY
4280inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI
41154281bool
41164282operator> (const _CharT* __lhs,
41174283 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
......@@ -4122,7 +4288,7 @@ operator> (const _CharT* __lhs,
41224288// operator<=
41234289
41244290template<class _CharT, class _Traits, class _Allocator>
4125inline _LIBCPP_INLINE_VISIBILITY
4291inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI
41264292bool
41274293operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
41284294 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
......@@ -4131,7 +4297,7 @@ operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
41314297}
41324298
41334299template<class _CharT, class _Traits, class _Allocator>
4134inline _LIBCPP_INLINE_VISIBILITY
4300inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI
41354301bool
41364302operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
41374303 const _CharT* __rhs) _NOEXCEPT
......@@ -4140,7 +4306,7 @@ operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
41404306}
41414307
41424308template<class _CharT, class _Traits, class _Allocator>
4143inline _LIBCPP_INLINE_VISIBILITY
4309inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI
41444310bool
41454311operator<=(const _CharT* __lhs,
41464312 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
......@@ -4151,7 +4317,7 @@ operator<=(const _CharT* __lhs,
41514317// operator>=
41524318
41534319template<class _CharT, class _Traits, class _Allocator>
4154inline _LIBCPP_INLINE_VISIBILITY
4320inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI
41554321bool
41564322operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
41574323 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
......@@ -4160,7 +4326,7 @@ operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
41604326}
41614327
41624328template<class _CharT, class _Traits, class _Allocator>
4163inline _LIBCPP_INLINE_VISIBILITY
4329inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI
41644330bool
41654331operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
41664332 const _CharT* __rhs) _NOEXCEPT
......@@ -4169,7 +4335,7 @@ operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
41694335}
41704336
41714337template<class _CharT, class _Traits, class _Allocator>
4172inline _LIBCPP_INLINE_VISIBILITY
4338inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI
41734339bool
41744340operator>=(const _CharT* __lhs,
41754341 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
......@@ -4180,123 +4346,152 @@ operator>=(const _CharT* __lhs,
41804346// operator +
41814347
41824348template<class _CharT, class _Traits, class _Allocator>
4349_LIBCPP_CONSTEXPR_AFTER_CXX17
41834350basic_string<_CharT, _Traits, _Allocator>
41844351operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
41854352 const basic_string<_CharT, _Traits, _Allocator>& __rhs)
41864353{
4187 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4188 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4189 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4190 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
4191 __r.append(__rhs.data(), __rhs_sz);
4354 using _String = basic_string<_CharT, _Traits, _Allocator>;
4355 auto __lhs_sz = __lhs.size();
4356 auto __rhs_sz = __rhs.size();
4357 _String __r(__uninitialized_size_tag(),
4358 __lhs_sz + __rhs_sz,
4359 _String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator()));
4360 auto __ptr = std::__to_address(__r.__get_pointer());
4361 _Traits::copy(__ptr, __lhs.data(), __lhs_sz);
4362 _Traits::copy(__ptr + __lhs_sz, __rhs.data(), __rhs_sz);
4363 _Traits::assign(__ptr + __lhs_sz + __rhs_sz, 1, _CharT());
41924364 return __r;
41934365}
41944366
41954367template<class _CharT, class _Traits, class _Allocator>
4368_LIBCPP_CONSTEXPR_AFTER_CXX17
41964369basic_string<_CharT, _Traits, _Allocator>
41974370operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
41984371{
4199 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
4200 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
4201 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4202 __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
4203 __r.append(__rhs.data(), __rhs_sz);
4372 using _String = basic_string<_CharT, _Traits, _Allocator>;
4373 auto __lhs_sz = _Traits::length(__lhs);
4374 auto __rhs_sz = __rhs.size();
4375 _String __r(__uninitialized_size_tag(),
4376 __lhs_sz + __rhs_sz,
4377 _String::__alloc_traits::select_on_container_copy_construction(__rhs.get_allocator()));
4378 auto __ptr = std::__to_address(__r.__get_pointer());
4379 _Traits::copy(__ptr, __lhs, __lhs_sz);
4380 _Traits::copy(__ptr + __lhs_sz, __rhs.data(), __rhs_sz);
4381 _Traits::assign(__ptr + __lhs_sz + __rhs_sz, 1, _CharT());
42044382 return __r;
42054383}
42064384
42074385template<class _CharT, class _Traits, class _Allocator>
4386_LIBCPP_CONSTEXPR_AFTER_CXX17
42084387basic_string<_CharT, _Traits, _Allocator>
42094388operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
42104389{
4211 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
4212 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4213 __r.__init(&__lhs, 1, 1 + __rhs_sz);
4214 __r.append(__rhs.data(), __rhs_sz);
4390 using _String = basic_string<_CharT, _Traits, _Allocator>;
4391 typename _String::size_type __rhs_sz = __rhs.size();
4392 _String __r(__uninitialized_size_tag(),
4393 __rhs_sz + 1,
4394 _String::__alloc_traits::select_on_container_copy_construction(__rhs.get_allocator()));
4395 auto __ptr = std::__to_address(__r.__get_pointer());
4396 _Traits::assign(__ptr, 1, __lhs);
4397 _Traits::copy(__ptr + 1, __rhs.data(), __rhs_sz);
4398 _Traits::assign(__ptr + 1 + __rhs_sz, 1, _CharT());
42154399 return __r;
42164400}
42174401
42184402template<class _CharT, class _Traits, class _Allocator>
4219inline
4403inline _LIBCPP_CONSTEXPR_AFTER_CXX17
42204404basic_string<_CharT, _Traits, _Allocator>
42214405operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
42224406{
4223 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4224 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4225 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
4226 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
4227 __r.append(__rhs, __rhs_sz);
4407 using _String = basic_string<_CharT, _Traits, _Allocator>;
4408 typename _String::size_type __lhs_sz = __lhs.size();
4409 typename _String::size_type __rhs_sz = _Traits::length(__rhs);
4410 _String __r(__uninitialized_size_tag(),
4411 __lhs_sz + __rhs_sz,
4412 _String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator()));
4413 auto __ptr = std::__to_address(__r.__get_pointer());
4414 _Traits::copy(__ptr, __lhs.data(), __lhs_sz);
4415 _Traits::copy(__ptr + __lhs_sz, __rhs, __rhs_sz);
4416 _Traits::assign(__ptr + __lhs_sz + __rhs_sz, 1, _CharT());
42284417 return __r;
42294418}
42304419
42314420template<class _CharT, class _Traits, class _Allocator>
4421_LIBCPP_CONSTEXPR_AFTER_CXX17
42324422basic_string<_CharT, _Traits, _Allocator>
42334423operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
42344424{
4235 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4236 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4237 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
4238 __r.push_back(__rhs);
4425 using _String = basic_string<_CharT, _Traits, _Allocator>;
4426 typename _String::size_type __lhs_sz = __lhs.size();
4427 _String __r(__uninitialized_size_tag(),
4428 __lhs_sz + 1,
4429 _String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator()));
4430 auto __ptr = std::__to_address(__r.__get_pointer());
4431 _Traits::copy(__ptr, __lhs.data(), __lhs_sz);
4432 _Traits::assign(__ptr + __lhs_sz, 1, __rhs);
4433 _Traits::assign(__ptr + 1 + __lhs_sz, 1, _CharT());
42394434 return __r;
42404435}
42414436
42424437#ifndef _LIBCPP_CXX03_LANG
42434438
42444439template<class _CharT, class _Traits, class _Allocator>
4245inline _LIBCPP_INLINE_VISIBILITY
4440inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
42464441basic_string<_CharT, _Traits, _Allocator>
42474442operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
42484443{
4249 return _VSTD::move(__lhs.append(__rhs));
4444 return std::move(__lhs.append(__rhs));
42504445}
42514446
42524447template<class _CharT, class _Traits, class _Allocator>
4253inline _LIBCPP_INLINE_VISIBILITY
4448inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
42544449basic_string<_CharT, _Traits, _Allocator>
42554450operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
42564451{
4257 return _VSTD::move(__rhs.insert(0, __lhs));
4452 return std::move(__rhs.insert(0, __lhs));
42584453}
42594454
42604455template<class _CharT, class _Traits, class _Allocator>
4261inline _LIBCPP_INLINE_VISIBILITY
4456inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
42624457basic_string<_CharT, _Traits, _Allocator>
42634458operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
42644459{
4265 return _VSTD::move(__lhs.append(__rhs));
4460 return std::move(__lhs.append(__rhs));
42664461}
42674462
42684463template<class _CharT, class _Traits, class _Allocator>
4269inline _LIBCPP_INLINE_VISIBILITY
4464inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
42704465basic_string<_CharT, _Traits, _Allocator>
42714466operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
42724467{
4273 return _VSTD::move(__rhs.insert(0, __lhs));
4468 return std::move(__rhs.insert(0, __lhs));
42744469}
42754470
42764471template<class _CharT, class _Traits, class _Allocator>
4277inline _LIBCPP_INLINE_VISIBILITY
4472inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
42784473basic_string<_CharT, _Traits, _Allocator>
42794474operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
42804475{
42814476 __rhs.insert(__rhs.begin(), __lhs);
4282 return _VSTD::move(__rhs);
4477 return std::move(__rhs);
42834478}
42844479
42854480template<class _CharT, class _Traits, class _Allocator>
4286inline _LIBCPP_INLINE_VISIBILITY
4481inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
42874482basic_string<_CharT, _Traits, _Allocator>
42884483operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
42894484{
4290 return _VSTD::move(__lhs.append(__rhs));
4485 return std::move(__lhs.append(__rhs));
42914486}
42924487
42934488template<class _CharT, class _Traits, class _Allocator>
4294inline _LIBCPP_INLINE_VISIBILITY
4489inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
42954490basic_string<_CharT, _Traits, _Allocator>
42964491operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
42974492{
42984493 __lhs.push_back(__rhs);
4299 return _VSTD::move(__lhs);
4494 return std::move(__lhs);
43004495}
43014496
43024497#endif // _LIBCPP_CXX03_LANG
......@@ -4304,7 +4499,7 @@ operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
43044499// swap
43054500
43064501template<class _CharT, class _Traits, class _Allocator>
4307inline _LIBCPP_INLINE_VISIBILITY
4502inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
43084503void
43094504swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
43104505 basic_string<_CharT, _Traits, _Allocator>& __rhs)
......@@ -4363,15 +4558,13 @@ const typename basic_string<_CharT, _Traits, _Allocator>::size_type
43634558template <class _CharT, class _Allocator>
43644559struct _LIBCPP_TEMPLATE_VIS
43654560 hash<basic_string<_CharT, char_traits<_CharT>, _Allocator> >
4366 : public unary_function<
4367 basic_string<_CharT, char_traits<_CharT>, _Allocator>, size_t>
4561 : public __unary_function<basic_string<_CharT, char_traits<_CharT>, _Allocator>, size_t>
43684562{
43694563 size_t
43704564 operator()(const basic_string<_CharT, char_traits<_CharT>, _Allocator>& __val) const _NOEXCEPT
43714565 { return __do_string_hash(__val.data(), __val.data() + __val.size()); }
43724566};
43734567
4374
43754568template<class _CharT, class _Traits, class _Allocator>
43764569basic_ostream<_CharT, _Traits>&
43774570operator<<(basic_ostream<_CharT, _Traits>& __os,
......@@ -4388,68 +4581,68 @@ getline(basic_istream<_CharT, _Traits>& __is,
43884581 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
43894582
43904583template<class _CharT, class _Traits, class _Allocator>
4391inline _LIBCPP_INLINE_VISIBILITY
4584inline _LIBCPP_HIDE_FROM_ABI
43924585basic_istream<_CharT, _Traits>&
43934586getline(basic_istream<_CharT, _Traits>& __is,
43944587 basic_string<_CharT, _Traits, _Allocator>& __str);
43954588
43964589template<class _CharT, class _Traits, class _Allocator>
4397inline _LIBCPP_INLINE_VISIBILITY
4590inline _LIBCPP_HIDE_FROM_ABI
43984591basic_istream<_CharT, _Traits>&
43994592getline(basic_istream<_CharT, _Traits>&& __is,
44004593 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
44014594
44024595template<class _CharT, class _Traits, class _Allocator>
4403inline _LIBCPP_INLINE_VISIBILITY
4596inline _LIBCPP_HIDE_FROM_ABI
44044597basic_istream<_CharT, _Traits>&
44054598getline(basic_istream<_CharT, _Traits>&& __is,
44064599 basic_string<_CharT, _Traits, _Allocator>& __str);
44074600
44084601#if _LIBCPP_STD_VER > 17
44094602template <class _CharT, class _Traits, class _Allocator, class _Up>
4410inline _LIBCPP_INLINE_VISIBILITY
4603inline _LIBCPP_HIDE_FROM_ABI
44114604 typename basic_string<_CharT, _Traits, _Allocator>::size_type
44124605 erase(basic_string<_CharT, _Traits, _Allocator>& __str, const _Up& __v) {
44134606 auto __old_size = __str.size();
4414 __str.erase(_VSTD::remove(__str.begin(), __str.end(), __v), __str.end());
4607 __str.erase(std::remove(__str.begin(), __str.end(), __v), __str.end());
44154608 return __old_size - __str.size();
44164609}
44174610
44184611template <class _CharT, class _Traits, class _Allocator, class _Predicate>
4419inline _LIBCPP_INLINE_VISIBILITY
4612inline _LIBCPP_HIDE_FROM_ABI
44204613 typename basic_string<_CharT, _Traits, _Allocator>::size_type
44214614 erase_if(basic_string<_CharT, _Traits, _Allocator>& __str,
44224615 _Predicate __pred) {
44234616 auto __old_size = __str.size();
4424 __str.erase(_VSTD::remove_if(__str.begin(), __str.end(), __pred),
4617 __str.erase(std::remove_if(__str.begin(), __str.end(), __pred),
44254618 __str.end());
44264619 return __old_size - __str.size();
44274620}
44284621#endif
44294622
4430#if _LIBCPP_DEBUG_LEVEL == 2
4623#ifdef _LIBCPP_ENABLE_DEBUG_MODE
44314624
44324625template<class _CharT, class _Traits, class _Allocator>
44334626bool
44344627basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
44354628{
4436 return data() <= _VSTD::__to_address(__i->base()) &&
4437 _VSTD::__to_address(__i->base()) < data() + size();
4629 return data() <= std::__to_address(__i->base()) &&
4630 std::__to_address(__i->base()) < data() + size();
44384631}
44394632
44404633template<class _CharT, class _Traits, class _Allocator>
44414634bool
44424635basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
44434636{
4444 return data() < _VSTD::__to_address(__i->base()) &&
4445 _VSTD::__to_address(__i->base()) <= data() + size();
4637 return data() < std::__to_address(__i->base()) &&
4638 std::__to_address(__i->base()) <= data() + size();
44464639}
44474640
44484641template<class _CharT, class _Traits, class _Allocator>
44494642bool
44504643basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
44514644{
4452 const value_type* __p = _VSTD::__to_address(__i->base()) + __n;
4645 const value_type* __p = std::__to_address(__i->base()) + __n;
44534646 return data() <= __p && __p <= data() + size();
44544647}
44554648
......@@ -4457,11 +4650,11 @@ template<class _CharT, class _Traits, class _Allocator>
44574650bool
44584651basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
44594652{
4460 const value_type* __p = _VSTD::__to_address(__i->base()) + __n;
4653 const value_type* __p = std::__to_address(__i->base()) + __n;
44614654 return data() <= __p && __p < data() + size();
44624655}
44634656
4464#endif // _LIBCPP_DEBUG_LEVEL == 2
4657#endif // _LIBCPP_ENABLE_DEBUG_MODE
44654658
44664659#if _LIBCPP_STD_VER > 11
44674660// Literal suffixes for basic_string [basic.string.literals]
......@@ -4469,14 +4662,14 @@ inline namespace literals
44694662{
44704663 inline namespace string_literals
44714664 {
4472 inline _LIBCPP_INLINE_VISIBILITY
4665 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
44734666 basic_string<char> operator "" s( const char *__str, size_t __len )
44744667 {
44754668 return basic_string<char> (__str, __len);
44764669 }
44774670
44784671#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4479 inline _LIBCPP_INLINE_VISIBILITY
4672 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
44804673 basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
44814674 {
44824675 return basic_string<wchar_t> (__str, __len);
......@@ -4484,26 +4677,36 @@ inline namespace literals
44844677#endif
44854678
44864679#ifndef _LIBCPP_HAS_NO_CHAR8_T
4487 inline _LIBCPP_INLINE_VISIBILITY
4680 inline _LIBCPP_HIDE_FROM_ABI constexpr
44884681 basic_string<char8_t> operator "" s(const char8_t *__str, size_t __len) _NOEXCEPT
44894682 {
44904683 return basic_string<char8_t> (__str, __len);
44914684 }
44924685#endif
44934686
4494 inline _LIBCPP_INLINE_VISIBILITY
4687 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
44954688 basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
44964689 {
44974690 return basic_string<char16_t> (__str, __len);
44984691 }
44994692
4500 inline _LIBCPP_INLINE_VISIBILITY
4693 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
45014694 basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
45024695 {
45034696 return basic_string<char32_t> (__str, __len);
45044697 }
45054698 } // namespace string_literals
45064699} // namespace literals
4700
4701#if _LIBCPP_STD_VER > 17
4702template <>
4703inline constexpr bool __format::__enable_insertable<std::basic_string<char>> = true;
4704#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4705template <>
4706inline constexpr bool __format::__enable_insertable<std::basic_string<wchar_t>> = true;
4707#endif
4708#endif
4709
45074710#endif
45084711
45094712_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/string.h+1-1
......@@ -54,7 +54,7 @@ size_t strlen(const char* s);
5454#include <__config>
5555
5656#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
57#pragma GCC system_header
57# pragma GCC system_header
5858#endif
5959
6060#include_next <string.h>
lib/libcxx/include/string_view+52-33
......@@ -11,7 +11,8 @@
1111#define _LIBCPP_STRING_VIEW
1212
1313/*
14string_view synopsis
14
15 string_view synopsis
1516
1617namespace std {
1718
......@@ -195,25 +196,48 @@ namespace std {
195196
196197*/
197198
199#include <__algorithm/min.h>
200#include <__assert> // all public C++ headers provide the assertion handler
198201#include <__config>
199#include <__debug>
202#include <__functional/hash.h>
203#include <__functional/unary_function.h>
204#include <__fwd/string_view.h>
205#include <__iterator/concepts.h>
206#include <__iterator/readable_traits.h>
207#include <__iterator/reverse_iterator.h>
208#include <__memory/pointer_traits.h>
200209#include <__ranges/concepts.h>
201210#include <__ranges/data.h>
202211#include <__ranges/enable_borrowed_range.h>
203212#include <__ranges/enable_view.h>
204213#include <__ranges/size.h>
205#include <__string>
206#include <algorithm>
207#include <compare>
214#include <__string/char_traits.h>
208215#include <iosfwd>
209#include <iterator>
210216#include <limits>
211217#include <stdexcept>
212218#include <type_traits>
213219#include <version>
214220
221#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
222# include <algorithm>
223# include <functional>
224# include <iterator>
225#endif
226
227// standard-mandated includes
228
229// [iterator.range]
230#include <__iterator/access.h>
231#include <__iterator/data.h>
232#include <__iterator/empty.h>
233#include <__iterator/reverse_access.h>
234#include <__iterator/size.h>
235
236// [string.view.synop]
237#include <compare>
238
215239#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
216#pragma GCC system_header
240# pragma GCC system_header
217241#endif
218242
219243_LIBCPP_PUSH_MACROS
......@@ -222,18 +246,14 @@ _LIBCPP_PUSH_MACROS
222246
223247_LIBCPP_BEGIN_NAMESPACE_STD
224248
225template<class _CharT, class _Traits = char_traits<_CharT> >
226 class _LIBCPP_TEMPLATE_VIS basic_string_view;
227
228typedef basic_string_view<char> string_view;
229#ifndef _LIBCPP_HAS_NO_CHAR8_T
230typedef basic_string_view<char8_t> u8string_view;
231#endif
232typedef basic_string_view<char16_t> u16string_view;
233typedef basic_string_view<char32_t> u32string_view;
234#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
235typedef basic_string_view<wchar_t> wstring_view;
236#endif
249// TODO: This is a workaround for some vendors to carry a downstream diff to accept `nullptr` in
250// string_view constructors. This can be refactored when this exact form isn't needed anymore.
251template <class _Traits>
252_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
253inline size_t __char_traits_length_checked(const typename _Traits::char_type* __s) _NOEXCEPT {
254 // This needs to be a single statement for C++11 constexpr
255 return _LIBCPP_ASSERT(__s != nullptr, "null pointer passed to non-null argument of char_traits<...>::length"), _Traits::length(__s);
256}
237257
238258template<class _CharT, class _Traits>
239259class
......@@ -286,7 +306,7 @@ public:
286306#endif
287307 }
288308
289#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
309#if _LIBCPP_STD_VER > 17
290310 template <contiguous_iterator _It, sized_sentinel_for<_It> _End>
291311 requires (is_same_v<iter_value_t<_It>, _CharT> && !is_convertible_v<_End, size_type>)
292312 constexpr _LIBCPP_HIDE_FROM_ABI basic_string_view(_It __begin, _End __end)
......@@ -294,9 +314,9 @@ public:
294314 {
295315 _LIBCPP_ASSERT((__end - __begin) >= 0, "std::string_view::string_view(iterator, sentinel) received invalid range");
296316 }
297#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
317#endif // _LIBCPP_STD_VER > 17
298318
299#if _LIBCPP_STD_VER > 20 && !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
319#if _LIBCPP_STD_VER > 20 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
300320 template <class _Range>
301321 requires (
302322 !is_same_v<remove_cvref_t<_Range>, basic_string_view> &&
......@@ -304,8 +324,8 @@ public:
304324 ranges::sized_range<_Range> &&
305325 is_same_v<ranges::range_value_t<_Range>, _CharT> &&
306326 !is_convertible_v<_Range, const _CharT*> &&
307 (!requires(remove_cvref_t<_Range>& d) {
308 d.operator _VSTD::basic_string_view<_CharT, _Traits>();
327 (!requires(remove_cvref_t<_Range>& __d) {
328 __d.operator _VSTD::basic_string_view<_CharT, _Traits>();
309329 }) &&
310330 (!requires {
311331 typename remove_reference_t<_Range>::traits_type;
......@@ -313,7 +333,7 @@ public:
313333 )
314334 constexpr _LIBCPP_HIDE_FROM_ABI
315335 basic_string_view(_Range&& __r) : __data(ranges::data(__r)), __size(ranges::size(__r)) {}
316#endif
336#endif // _LIBCPP_STD_VER > 20 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
317337
318338 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
319339 basic_string_view(const _CharT* __s)
......@@ -707,26 +727,26 @@ private:
707727 size_type __size;
708728};
709729
710#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
730#if _LIBCPP_STD_VER > 17
711731template <class _CharT, class _Traits>
712732inline constexpr bool ranges::enable_view<basic_string_view<_CharT, _Traits>> = true;
713733
714734template <class _CharT, class _Traits>
715735inline constexpr bool ranges::enable_borrowed_range<basic_string_view<_CharT, _Traits> > = true;
716#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
736#endif // _LIBCPP_STD_VER > 17
717737
718738// [string.view.deduct]
719739
720#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
740#if _LIBCPP_STD_VER > 17
721741template <contiguous_iterator _It, sized_sentinel_for<_It> _End>
722742 basic_string_view(_It, _End) -> basic_string_view<iter_value_t<_It>>;
723#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
743#endif // _LIBCPP_STD_VER > 17
724744
725745
726#if _LIBCPP_STD_VER > 20 && !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
746#if _LIBCPP_STD_VER > 20 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
727747template <ranges::contiguous_range _Range>
728748 basic_string_view(_Range) -> basic_string_view<ranges::range_value_t<_Range>>;
729#endif
749#endif // _LIBCPP_STD_VER > 20 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
730750
731751// [string.view.comparison]
732752// operator ==
......@@ -900,7 +920,7 @@ operator<<(basic_ostream<_CharT, _Traits>& __os,
900920// [string.view.hash]
901921template<class _CharT>
902922struct _LIBCPP_TEMPLATE_VIS hash<basic_string_view<_CharT, char_traits<_CharT> > >
903 : public unary_function<basic_string_view<_CharT, char_traits<_CharT> >, size_t>
923 : public __unary_function<basic_string_view<_CharT, char_traits<_CharT> >, size_t>
904924{
905925 _LIBCPP_INLINE_VISIBILITY
906926 size_t operator()(const basic_string_view<_CharT, char_traits<_CharT> > __val) const _NOEXCEPT {
......@@ -908,7 +928,6 @@ struct _LIBCPP_TEMPLATE_VIS hash<basic_string_view<_CharT, char_traits<_CharT> >
908928 }
909929};
910930
911
912931#if _LIBCPP_STD_VER > 11
913932inline namespace literals
914933{
lib/libcxx/include/strstream+5-4
......@@ -129,13 +129,14 @@ private:
129129
130130*/
131131
132#include <__assert> // all public C++ headers provide the assertion handler
132133#include <__config>
133134#include <istream>
134135#include <ostream>
135136#include <version>
136137
137138#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
138#pragma GCC system_header
139# pragma GCC system_header
139140#endif
140141
141142_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -265,8 +266,8 @@ public:
265266 _LIBCPP_INLINE_VISIBILITY
266267 istrstream& operator=(istrstream&& __rhs)
267268 {
268 istream::operator=(_VSTD::move(__rhs));
269269 __sb_ = _VSTD::move(__rhs.__sb_);
270 istream::operator=(_VSTD::move(__rhs));
270271 return *this;
271272 }
272273#endif // _LIBCPP_CXX03_LANG
......@@ -314,8 +315,8 @@ public:
314315 _LIBCPP_INLINE_VISIBILITY
315316 ostrstream& operator=(ostrstream&& __rhs)
316317 {
317 ostream::operator=(_VSTD::move(__rhs));
318318 __sb_ = _VSTD::move(__rhs.__sb_);
319 ostream::operator=(_VSTD::move(__rhs));
319320 return *this;
320321 }
321322#endif // _LIBCPP_CXX03_LANG
......@@ -374,8 +375,8 @@ public:
374375 _LIBCPP_INLINE_VISIBILITY
375376 strstream& operator=(strstream&& __rhs)
376377 {
377 iostream::operator=(_VSTD::move(__rhs));
378378 __sb_ = _VSTD::move(__rhs.__sb_);
379 iostream::operator=(_VSTD::move(__rhs));
379380 return *this;
380381 }
381382#endif // _LIBCPP_CXX03_LANG
lib/libcxx/include/system_error+13-11
......@@ -142,18 +142,21 @@ template <> struct hash<std::error_condition>;
142142
143143*/
144144
145#include <__assert> // all public C++ headers provide the assertion handler
145146#include <__config>
146147#include <__errc>
148#include <__functional/hash.h>
147149#include <__functional/unary_function.h>
148#include <__functional_base>
149#include <compare>
150150#include <stdexcept>
151151#include <string>
152152#include <type_traits>
153153#include <version>
154154
155// standard-mandated includes
156#include <compare>
157
155158#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
156#pragma GCC system_header
159# pragma GCC system_header
157160#endif
158161
159162_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -184,7 +187,7 @@ template <>
184187struct _LIBCPP_TEMPLATE_VIS is_error_condition_enum<errc>
185188 : true_type { };
186189
187#ifdef _LIBCPP_HAS_NO_STRONG_ENUMS
190#ifdef _LIBCPP_CXX03_LANG
188191template <>
189192struct _LIBCPP_TEMPLATE_VIS is_error_condition_enum<errc::__lx>
190193 : true_type { };
......@@ -202,9 +205,8 @@ class _LIBCPP_TYPE_VIS error_category
202205public:
203206 virtual ~error_category() _NOEXCEPT;
204207
205#if defined(_LIBCPP_BUILDING_LIBRARY) && \
206 defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
207 error_category() _NOEXCEPT;
208#if defined(_LIBCPP_ERROR_CATEGORY_DEFINE_LEGACY_INLINE_FUNCTIONS)
209 error_category() noexcept;
208210#else
209211 _LIBCPP_INLINE_VISIBILITY
210212 _LIBCPP_CONSTEXPR_AFTER_CXX11 error_category() _NOEXCEPT = default;
......@@ -234,7 +236,7 @@ class _LIBCPP_HIDDEN __do_message
234236 : public error_category
235237{
236238public:
237 virtual string message(int ev) const;
239 virtual string message(int __ev) const;
238240};
239241
240242_LIBCPP_FUNC_VIS const error_category& generic_category() _NOEXCEPT;
......@@ -436,7 +438,7 @@ operator!=(const error_condition& __x, const error_condition& __y) _NOEXCEPT
436438
437439template <>
438440struct _LIBCPP_TEMPLATE_VIS hash<error_code>
439 : public unary_function<error_code, size_t>
441 : public __unary_function<error_code, size_t>
440442{
441443 _LIBCPP_INLINE_VISIBILITY
442444 size_t operator()(const error_code& __ec) const _NOEXCEPT
......@@ -447,7 +449,7 @@ struct _LIBCPP_TEMPLATE_VIS hash<error_code>
447449
448450template <>
449451struct _LIBCPP_TEMPLATE_VIS hash<error_condition>
450 : public unary_function<error_condition, size_t>
452 : public __unary_function<error_condition, size_t>
451453{
452454 _LIBCPP_INLINE_VISIBILITY
453455 size_t operator()(const error_condition& __ec) const _NOEXCEPT
......@@ -480,7 +482,7 @@ private:
480482};
481483
482484_LIBCPP_NORETURN _LIBCPP_FUNC_VIS
483void __throw_system_error(int ev, const char* what_arg);
485void __throw_system_error(int __ev, const char* __what_arg);
484486
485487_LIBCPP_END_NAMESPACE_STD
486488
lib/libcxx/include/tgmath.h+1-1
......@@ -20,7 +20,7 @@
2020#include <__config>
2121
2222#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23#pragma GCC system_header
23# pragma GCC system_header
2424#endif
2525
2626#ifdef __cplusplus
lib/libcxx/include/thread+15-15
......@@ -82,17 +82,15 @@ void sleep_for(const chrono::duration<Rep, Period>& rel_time);
8282
8383*/
8484
85#include <__assert> // all public C++ headers provide the assertion handler
8586#include <__config>
86#include <__debug>
87#include <__functional_base>
87#include <__functional/hash.h>
8888#include <__mutex_base>
8989#include <__thread/poll_with_backoff.h>
9090#include <__thread/timed_backoff_policy.h>
9191#include <__threading_support>
9292#include <__utility/forward.h>
93#include <chrono>
9493#include <cstddef>
95#include <functional>
9694#include <iosfwd>
9795#include <memory>
9896#include <system_error>
......@@ -100,16 +98,24 @@ void sleep_for(const chrono::duration<Rep, Period>& rel_time);
10098#include <type_traits>
10199#include <version>
102100
101#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
102# include <chrono>
103# include <functional>
104#endif
105
106// standard-mandated includes
107#include <compare>
108
103109#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
104#pragma GCC system_header
110# pragma GCC system_header
105111#endif
106112
107113_LIBCPP_PUSH_MACROS
108114#include <__undef_macros>
109115
110116#ifdef _LIBCPP_HAS_NO_THREADS
111#error <thread> is not supported on this single threaded system
112#else // !_LIBCPP_HAS_NO_THREADS
117# error "<thread> is not supported since libc++ has been configured without support for threads."
118#endif
113119
114120_LIBCPP_BEGIN_NAMESPACE_STD
115121
......@@ -200,7 +206,7 @@ __thread_specific_ptr<_Tp>::set_pointer(pointer __p)
200206
201207template<>
202208struct _LIBCPP_TEMPLATE_VIS hash<__thread_id>
203 : public unary_function<__thread_id, size_t>
209 : public __unary_function<__thread_id, size_t>
204210{
205211 _LIBCPP_INLINE_VISIBILITY
206212 size_t operator()(__thread_id __v) const _NOEXCEPT
......@@ -229,11 +235,7 @@ public:
229235 thread() _NOEXCEPT : __t_(_LIBCPP_NULL_THREAD) {}
230236#ifndef _LIBCPP_CXX03_LANG
231237 template <class _Fp, class ..._Args,
232 class = typename enable_if
233 <
234 !is_same<typename __uncvref<_Fp>::type, thread>::value
235 >::type
236 >
238 class = __enable_if_t<!is_same<__uncvref_t<_Fp>, thread>::value> >
237239 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
238240 explicit thread(_Fp&& __f, _Args&&... __args);
239241#else // _LIBCPP_CXX03_LANG
......@@ -408,8 +410,6 @@ void yield() _NOEXCEPT {__libcpp_thread_yield();}
408410
409411_LIBCPP_END_NAMESPACE_STD
410412
411#endif // !_LIBCPP_HAS_NO_THREADS
412
413413_LIBCPP_POP_MACROS
414414
415415#endif // _LIBCPP_THREAD
lib/libcxx/include/tuple+341-147
......@@ -25,14 +25,24 @@ public:
2525 explicit(see-below) tuple(U&&...); // constexpr in C++14
2626 tuple(const tuple&) = default;
2727 tuple(tuple&&) = default;
28
29 template<class... UTypes>
30 constexpr explicit(see-below) tuple(tuple<UTypes...>&); // C++23
2831 template <class... U>
2932 explicit(see-below) tuple(const tuple<U...>&); // constexpr in C++14
3033 template <class... U>
3134 explicit(see-below) tuple(tuple<U...>&&); // constexpr in C++14
35 template<class... UTypes>
36 constexpr explicit(see-below) tuple(const tuple<UTypes...>&&); // C++23
37
38 template<class U1, class U2>
39 constexpr explicit(see-below) tuple(pair<U1, U2>&); // iff sizeof...(Types) == 2 // C++23
3240 template <class U1, class U2>
3341 explicit(see-below) tuple(const pair<U1, U2>&); // iff sizeof...(T) == 2 // constexpr in C++14
3442 template <class U1, class U2>
3543 explicit(see-below) tuple(pair<U1, U2>&&); // iff sizeof...(T) == 2 // constexpr in C++14
44 template<class U1, class U2>
45 constexpr explicit(see-below) tuple(const pair<U1, U2>&&); // iff sizeof...(Types) == 2 // C++23
3646
3747 // allocator-extended constructors
3848 template <class Alloc>
......@@ -45,25 +55,47 @@ public:
4555 tuple(allocator_arg_t, const Alloc& a, const tuple&); // constexpr in C++20
4656 template <class Alloc>
4757 tuple(allocator_arg_t, const Alloc& a, tuple&&); // constexpr in C++20
58 template<class Alloc, class... UTypes>
59 constexpr explicit(see-below)
60 tuple(allocator_arg_t, const Alloc& a, tuple<UTypes...>&); // C++23
4861 template <class Alloc, class... U>
4962 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const tuple<U...>&); // constexpr in C++20
5063 template <class Alloc, class... U>
5164 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, tuple<U...>&&); // constexpr in C++20
65 template<class Alloc, class... UTypes>
66 constexpr explicit(see-below)
67 tuple(allocator_arg_t, const Alloc& a, const tuple<UTypes...>&&); // C++23
68 template<class Alloc, class U1, class U2>
69 constexpr explicit(see-below)
70 tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&); // C++23
5271 template <class Alloc, class U1, class U2>
5372 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&); // constexpr in C++20
5473 template <class Alloc, class U1, class U2>
5574 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&&); // constexpr in C++20
75 template<class Alloc, class U1, class U2>
76 constexpr explicit(see-below)
77 tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&&); // C++23
5678
5779 tuple& operator=(const tuple&); // constexpr in C++20
80 constexpr const tuple& operator=(const tuple&) const; // C++23
5881 tuple& operator=(tuple&&) noexcept(is_nothrow_move_assignable_v<T> && ...); // constexpr in C++20
82 constexpr const tuple& operator=(tuple&&) const; // C++23
5983 template <class... U>
6084 tuple& operator=(const tuple<U...>&); // constexpr in C++20
85 template<class... UTypes>
86 constexpr const tuple& operator=(const tuple<UTypes...>&) const; // C++23
6187 template <class... U>
6288 tuple& operator=(tuple<U...>&&); // constexpr in C++20
89 template<class... UTypes>
90 constexpr const tuple& operator=(tuple<UTypes...>&&) const; // C++23
6391 template <class U1, class U2>
6492 tuple& operator=(const pair<U1, U2>&); // iff sizeof...(T) == 2 // constexpr in C++20
93 template<class U1, class U2>
94 constexpr const tuple& operator=(const pair<U1, U2>&) const; // iff sizeof...(Types) == 2 // C++23
6595 template <class U1, class U2>
6696 tuple& operator=(pair<U1, U2>&&); // iff sizeof...(T) == 2 // constexpr in C++20
97 template<class U1, class U2>
98 constexpr const tuple& operator=(pair<U1, U2>&&) const; // iff sizeof...(Types) == 2 // C++23
6799
68100 template<class U, size_t N>
69101 tuple& operator=(array<U, N> const&) // iff sizeof...(T) == N, EXTENSION
......@@ -71,6 +103,7 @@ public:
71103 tuple& operator=(array<U, N>&&) // iff sizeof...(T) == N, EXTENSION
72104
73105 void swap(tuple&) noexcept(AND(swap(declval<T&>(), declval<T&>())...)); // constexpr in C++20
106 constexpr void swap(const tuple&) const noexcept(see-below); // C++23
74107};
75108
76109
......@@ -161,29 +194,44 @@ template <class... Types>
161194 void
162195 swap(tuple<Types...>& x, tuple<Types...>& y) noexcept(noexcept(x.swap(y)));
163196
197template <class... Types>
198 constexpr void swap(const tuple<Types...>& x, const tuple<Types...>& y) noexcept(see-below); // C++23
199
164200} // std
165201
166202*/
167203
204#include <__assert> // all public C++ headers provide the assertion handler
168205#include <__compare/common_comparison_category.h>
169206#include <__compare/synth_three_way.h>
170207#include <__config>
171208#include <__functional/unwrap_ref.h>
172#include <__functional_base>
173209#include <__memory/allocator_arg_t.h>
174210#include <__memory/uses_allocator.h>
175211#include <__tuple>
176212#include <__utility/forward.h>
177213#include <__utility/integer_sequence.h>
178214#include <__utility/move.h>
179#include <compare>
215#include <__utility/pair.h>
216#include <__utility/piecewise_construct.h>
217#include <__utility/swap.h>
180218#include <cstddef>
181219#include <type_traits>
182#include <utility>
183220#include <version>
184221
222#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
223# include <exception>
224# include <iosfwd>
225# include <new>
226# include <typeinfo>
227# include <utility>
228#endif
229
230// standard-mandated includes
231#include <compare>
232
185233#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
186#pragma GCC system_header
234# pragma GCC system_header
187235#endif
188236
189237_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -206,6 +254,13 @@ void swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y)
206254 swap(__x.get(), __y.get());
207255}
208256
257template <size_t _Ip, class _Hp, bool _Ep>
258_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
259void swap(const __tuple_leaf<_Ip, _Hp, _Ep>& __x, const __tuple_leaf<_Ip, _Hp, _Ep>& __y)
260 _NOEXCEPT_(__is_nothrow_swappable<const _Hp>::value) {
261 swap(__x.get(), __y.get());
262}
263
209264template <size_t _Ip, class _Hp, bool>
210265class __tuple_leaf
211266{
......@@ -294,6 +349,12 @@ public:
294349 return 0;
295350 }
296351
352 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
353 int swap(const __tuple_leaf& __t) const _NOEXCEPT_(__is_nothrow_swappable<const __tuple_leaf>::value) {
354 _VSTD::swap(*this, __t);
355 return 0;
356 }
357
297358 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return __value_;}
298359 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return __value_;}
299360};
......@@ -360,6 +421,12 @@ public:
360421 return 0;
361422 }
362423
424 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
425 int swap(const __tuple_leaf& __rhs) const _NOEXCEPT_(__is_nothrow_swappable<const __tuple_leaf>::value) {
426 _VSTD::swap(*this, __rhs);
427 return 0;
428 }
429
363430 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return static_cast<_Hp&>(*this);}
364431 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return static_cast<const _Hp&>(*this);}
365432};
......@@ -415,10 +482,7 @@ struct _LIBCPP_DECLSPEC_EMPTY_BASES __tuple_impl<__tuple_indices<_Indx...>, _Tp.
415482 {}
416483
417484 template <class _Tuple,
418 class = typename enable_if
419 <
420 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
421 >::type
485 class = __enable_if_t<__tuple_constructible<_Tuple, tuple<_Tp...> >::value>
422486 >
423487 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
424488 __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx,
......@@ -428,10 +492,7 @@ struct _LIBCPP_DECLSPEC_EMPTY_BASES __tuple_impl<__tuple_indices<_Indx...>, _Tp.
428492 {}
429493
430494 template <class _Alloc, class _Tuple,
431 class = typename enable_if
432 <
433 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
434 >::type
495 class = __enable_if_t<__tuple_constructible<_Tuple, tuple<_Tp...> >::value>
435496 >
436497 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
437498 __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
......@@ -450,6 +511,13 @@ struct _LIBCPP_DECLSPEC_EMPTY_BASES __tuple_impl<__tuple_indices<_Indx...>, _Tp.
450511 {
451512 _VSTD::__swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
452513 }
514
515 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
516 void swap(const __tuple_impl& __t) const
517 _NOEXCEPT_(__all<__is_nothrow_swappable<const _Tp>::value...>::value)
518 {
519 _VSTD::__swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<const __tuple_leaf<_Indx, _Tp>&>(__t))...);
520 }
453521};
454522
455523template<class _Dest, class _Source, size_t ..._Np>
......@@ -685,6 +753,7 @@ public:
685753 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
686754 _And<is_copy_constructible<_Tp>...>::value
687755 , int> = 0>
756 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
688757 tuple(allocator_arg_t, const _Alloc& __alloc, const tuple& __t)
689758 : __base_(allocator_arg_t(), __alloc, __t)
690759 { }
......@@ -692,30 +761,39 @@ public:
692761 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
693762 _And<is_move_constructible<_Tp>...>::value
694763 , int> = 0>
764 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
695765 tuple(allocator_arg_t, const _Alloc& __alloc, tuple&& __t)
696766 : __base_(allocator_arg_t(), __alloc, _VSTD::move(__t))
697767 { }
698768
699769 // tuple(const tuple<U...>&) constructors (including allocator_arg_t variants)
700 template <class ..._Up>
701 struct _EnableCopyFromOtherTuple : _And<
702 _Not<is_same<tuple<_Tp...>, tuple<_Up...> > >,
703 _Lazy<_Or,
704 _BoolConstant<sizeof...(_Tp) != 1>,
770
771 template <class _OtherTuple, class _DecayedOtherTuple = __uncvref_t<_OtherTuple>, class = void>
772 struct _EnableCtorFromUTypesTuple : false_type {};
773
774 template <class _OtherTuple, class... _Up>
775 struct _EnableCtorFromUTypesTuple<_OtherTuple, tuple<_Up...>,
776 // the length of the packs needs to checked first otherwise the 2 packs cannot be expanded simultaneously below
777 __enable_if_t<sizeof...(_Up) == sizeof...(_Tp)>> : _And<
778 // the two conditions below are not in spec. The purpose is to disable the UTypes Ctor when copy/move Ctor can work.
779 // Otherwise, is_constructible can trigger hard error in those cases https://godbolt.org/z/M94cGdKcE
780 _Not<is_same<_OtherTuple, const tuple&> >,
781 _Not<is_same<_OtherTuple, tuple&&> >,
782 is_constructible<_Tp, __copy_cvref_t<_OtherTuple, _Up> >...,
783 _Lazy<_Or, _BoolConstant<sizeof...(_Tp) != 1>,
705784 // _Tp and _Up are 1-element packs - the pack expansions look
706785 // weird to avoid tripping up the type traits in degenerate cases
707786 _Lazy<_And,
708 _Not<is_convertible<const tuple<_Up>&, _Tp> >...,
709 _Not<is_constructible<_Tp, const tuple<_Up>&> >...
787 _Not<is_same<_Tp, _Up> >...,
788 _Not<is_convertible<_OtherTuple, _Tp> >...,
789 _Not<is_constructible<_Tp, _OtherTuple> >...
710790 >
711 >,
712 is_constructible<_Tp, const _Up&>...
713 > { };
791 >
792 > {};
714793
715794 template <class ..._Up, __enable_if_t<
716795 _And<
717 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
718 _EnableCopyFromOtherTuple<_Up...>,
796 _EnableCtorFromUTypesTuple<const tuple<_Up...>&>,
719797 is_convertible<const _Up&, _Tp>... // explicit check
720798 >::value
721799 , int> = 0>
......@@ -727,8 +805,7 @@ public:
727805
728806 template <class ..._Up, __enable_if_t<
729807 _And<
730 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
731 _EnableCopyFromOtherTuple<_Up...>,
808 _EnableCtorFromUTypesTuple<const tuple<_Up...>&>,
732809 _Not<_Lazy<_And, is_convertible<const _Up&, _Tp>...> > // explicit check
733810 >::value
734811 , int> = 0>
......@@ -740,8 +817,7 @@ public:
740817
741818 template <class ..._Up, class _Alloc, __enable_if_t<
742819 _And<
743 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
744 _EnableCopyFromOtherTuple<_Up...>,
820 _EnableCtorFromUTypesTuple<const tuple<_Up...>&>,
745821 is_convertible<const _Up&, _Tp>... // explicit check
746822 >::value
747823 , int> = 0>
......@@ -752,8 +828,7 @@ public:
752828
753829 template <class ..._Up, class _Alloc, __enable_if_t<
754830 _And<
755 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
756 _EnableCopyFromOtherTuple<_Up...>,
831 _EnableCtorFromUTypesTuple<const tuple<_Up...>&>,
757832 _Not<_Lazy<_And, is_convertible<const _Up&, _Tp>...> > // explicit check
758833 >::value
759834 , int> = 0>
......@@ -762,26 +837,27 @@ public:
762837 : __base_(allocator_arg_t(), __a, __t)
763838 { }
764839
840#if _LIBCPP_STD_VER > 20
841 // tuple(tuple<U...>&) constructors (including allocator_arg_t variants)
842
843 template <class... _Up, enable_if_t<
844 _EnableCtorFromUTypesTuple<tuple<_Up...>&>::value>* = nullptr>
845 _LIBCPP_HIDE_FROM_ABI constexpr
846 explicit(!(is_convertible_v<_Up&, _Tp> && ...))
847 tuple(tuple<_Up...>& __t) : __base_(__t) {}
848
849 template <class _Alloc, class... _Up, enable_if_t<
850 _EnableCtorFromUTypesTuple<tuple<_Up...>&>::value>* = nullptr>
851 _LIBCPP_HIDE_FROM_ABI constexpr
852 explicit(!(is_convertible_v<_Up&, _Tp> && ...))
853 tuple(allocator_arg_t, const _Alloc& __alloc, tuple<_Up...>& __t) : __base_(allocator_arg_t(), __alloc, __t) {}
854#endif // _LIBCPP_STD_VER > 20
855
765856 // tuple(tuple<U...>&&) constructors (including allocator_arg_t variants)
766 template <class ..._Up>
767 struct _EnableMoveFromOtherTuple : _And<
768 _Not<is_same<tuple<_Tp...>, tuple<_Up...> > >,
769 _Lazy<_Or,
770 _BoolConstant<sizeof...(_Tp) != 1>,
771 // _Tp and _Up are 1-element packs - the pack expansions look
772 // weird to avoid tripping up the type traits in degenerate cases
773 _Lazy<_And,
774 _Not<is_convertible<tuple<_Up>, _Tp> >...,
775 _Not<is_constructible<_Tp, tuple<_Up> > >...
776 >
777 >,
778 is_constructible<_Tp, _Up>...
779 > { };
780857
781858 template <class ..._Up, __enable_if_t<
782859 _And<
783 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
784 _EnableMoveFromOtherTuple<_Up...>,
860 _EnableCtorFromUTypesTuple<tuple<_Up...>&&>,
785861 is_convertible<_Up, _Tp>... // explicit check
786862 >::value
787863 , int> = 0>
......@@ -793,8 +869,7 @@ public:
793869
794870 template <class ..._Up, __enable_if_t<
795871 _And<
796 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
797 _EnableMoveFromOtherTuple<_Up...>,
872 _EnableCtorFromUTypesTuple<tuple<_Up...>&&>,
798873 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
799874 >::value
800875 , int> = 0>
......@@ -806,8 +881,7 @@ public:
806881
807882 template <class _Alloc, class ..._Up, __enable_if_t<
808883 _And<
809 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
810 _EnableMoveFromOtherTuple<_Up...>,
884 _EnableCtorFromUTypesTuple<tuple<_Up...>&&>,
811885 is_convertible<_Up, _Tp>... // explicit check
812886 >::value
813887 , int> = 0>
......@@ -818,8 +892,7 @@ public:
818892
819893 template <class _Alloc, class ..._Up, __enable_if_t<
820894 _And<
821 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
822 _EnableMoveFromOtherTuple<_Up...>,
895 _EnableCtorFromUTypesTuple<tuple<_Up...>&&>,
823896 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
824897 >::value
825898 , int> = 0>
......@@ -828,57 +901,77 @@ public:
828901 : __base_(allocator_arg_t(), __a, _VSTD::move(__t))
829902 { }
830903
904#if _LIBCPP_STD_VER > 20
905 // tuple(const tuple<U...>&&) constructors (including allocator_arg_t variants)
906
907 template <class... _Up, enable_if_t<
908 _EnableCtorFromUTypesTuple<const tuple<_Up...>&&>::value>* = nullptr>
909 _LIBCPP_HIDE_FROM_ABI constexpr
910 explicit(!(is_convertible_v<const _Up&&, _Tp> && ...))
911 tuple(const tuple<_Up...>&& __t) : __base_(std::move(__t)) {}
912
913 template <class _Alloc, class... _Up, enable_if_t<
914 _EnableCtorFromUTypesTuple<const tuple<_Up...>&&>::value>* = nullptr>
915 _LIBCPP_HIDE_FROM_ABI constexpr
916 explicit(!(is_convertible_v<const _Up&&, _Tp> && ...))
917 tuple(allocator_arg_t, const _Alloc& __alloc, const tuple<_Up...>&& __t)
918 : __base_(allocator_arg_t(), __alloc, std::move(__t)) {}
919#endif // _LIBCPP_STD_VER > 20
920
831921 // tuple(const pair<U1, U2>&) constructors (including allocator_arg_t variants)
832 template <class _Up1, class _Up2, class ..._DependentTp>
833 struct _EnableImplicitCopyFromPair : _And<
834 is_constructible<_FirstType<_DependentTp...>, const _Up1&>,
835 is_constructible<_SecondType<_DependentTp...>, const _Up2&>,
836 is_convertible<const _Up1&, _FirstType<_DependentTp...> >, // explicit check
837 is_convertible<const _Up2&, _SecondType<_DependentTp...> >
838 > { };
839922
840 template <class _Up1, class _Up2, class ..._DependentTp>
841 struct _EnableExplicitCopyFromPair : _And<
842 is_constructible<_FirstType<_DependentTp...>, const _Up1&>,
843 is_constructible<_SecondType<_DependentTp...>, const _Up2&>,
844 _Not<is_convertible<const _Up1&, _FirstType<_DependentTp...> > >, // explicit check
845 _Not<is_convertible<const _Up2&, _SecondType<_DependentTp...> > >
846 > { };
923 template <template <class...> class Pred, class _Pair, class _DecayedPair = __uncvref_t<_Pair>, class _Tuple = tuple>
924 struct _CtorPredicateFromPair : false_type{};
925
926 template <template <class...> class Pred, class _Pair, class _Up1, class _Up2, class _Tp1, class _Tp2>
927 struct _CtorPredicateFromPair<Pred, _Pair, pair<_Up1, _Up2>, tuple<_Tp1, _Tp2> > : _And<
928 Pred<_Tp1, __copy_cvref_t<_Pair, _Up1> >,
929 Pred<_Tp2, __copy_cvref_t<_Pair, _Up2> >
930 > {};
931
932 template <class _Pair>
933 struct _EnableCtorFromPair : _CtorPredicateFromPair<is_constructible, _Pair>{};
934
935 template <class _Pair>
936 struct _NothrowConstructibleFromPair : _CtorPredicateFromPair<is_nothrow_constructible, _Pair>{};
937
938 template <class _Pair, class _DecayedPair = __uncvref_t<_Pair>, class _Tuple = tuple>
939 struct _BothImplicitlyConvertible : false_type{};
940
941 template <class _Pair, class _Up1, class _Up2, class _Tp1, class _Tp2>
942 struct _BothImplicitlyConvertible<_Pair, pair<_Up1, _Up2>, tuple<_Tp1, _Tp2> > : _And<
943 is_convertible<__copy_cvref_t<_Pair, _Up1>, _Tp1>,
944 is_convertible<__copy_cvref_t<_Pair, _Up2>, _Tp2>
945 > {};
847946
848947 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
849948 _And<
850 _BoolConstant<sizeof...(_Tp) == 2>,
851 _EnableImplicitCopyFromPair<_Up1, _Up2, _Tp...>
949 _EnableCtorFromPair<const pair<_Up1, _Up2>&>,
950 _BothImplicitlyConvertible<const pair<_Up1, _Up2>&> // explicit check
852951 >::value
853952 , int> = 0>
854953 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
855954 tuple(const pair<_Up1, _Up2>& __p)
856 _NOEXCEPT_((_And<
857 is_nothrow_constructible<_FirstType<_Tp...>, const _Up1&>,
858 is_nothrow_constructible<_SecondType<_Tp...>, const _Up2&>
859 >::value))
955 _NOEXCEPT_((_NothrowConstructibleFromPair<const pair<_Up1, _Up2>&>::value))
860956 : __base_(__p)
861957 { }
862958
863959 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
864960 _And<
865 _BoolConstant<sizeof...(_Tp) == 2>,
866 _EnableExplicitCopyFromPair<_Up1, _Up2, _Tp...>
961 _EnableCtorFromPair<const pair<_Up1, _Up2>&>,
962 _Not<_BothImplicitlyConvertible<const pair<_Up1, _Up2>&> > // explicit check
867963 >::value
868964 , int> = 0>
869965 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
870966 explicit tuple(const pair<_Up1, _Up2>& __p)
871 _NOEXCEPT_((_And<
872 is_nothrow_constructible<_FirstType<_Tp...>, const _Up1&>,
873 is_nothrow_constructible<_SecondType<_Tp...>, const _Up2&>
874 >::value))
967 _NOEXCEPT_((_NothrowConstructibleFromPair<const pair<_Up1, _Up2>&>::value))
875968 : __base_(__p)
876969 { }
877970
878971 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
879972 _And<
880 _BoolConstant<sizeof...(_Tp) == 2>,
881 _EnableImplicitCopyFromPair<_Up1, _Up2, _Tp...>
973 _EnableCtorFromPair<const pair<_Up1, _Up2>&>,
974 _BothImplicitlyConvertible<const pair<_Up1, _Up2>&> // explicit check
882975 >::value
883976 , int> = 0>
884977 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
......@@ -888,8 +981,8 @@ public:
888981
889982 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
890983 _And<
891 _BoolConstant<sizeof...(_Tp) == 2>,
892 _EnableExplicitCopyFromPair<_Up1, _Up2, _Tp...>
984 _EnableCtorFromPair<const pair<_Up1, _Up2>&>,
985 _Not<_BothImplicitlyConvertible<const pair<_Up1, _Up2>&> > // explicit check
893986 >::value
894987 , int> = 0>
895988 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
......@@ -897,57 +990,52 @@ public:
897990 : __base_(allocator_arg_t(), __a, __p)
898991 { }
899992
900 // tuple(pair<U1, U2>&&) constructors (including allocator_arg_t variants)
901 template <class _Up1, class _Up2, class ..._DependentTp>
902 struct _EnableImplicitMoveFromPair : _And<
903 is_constructible<_FirstType<_DependentTp...>, _Up1>,
904 is_constructible<_SecondType<_DependentTp...>, _Up2>,
905 is_convertible<_Up1, _FirstType<_DependentTp...> >, // explicit check
906 is_convertible<_Up2, _SecondType<_DependentTp...> >
907 > { };
993#if _LIBCPP_STD_VER > 20
994 // tuple(pair<U1, U2>&) constructors (including allocator_arg_t variants)
995
996 template <class _U1, class _U2, enable_if_t<
997 _EnableCtorFromPair<pair<_U1, _U2>&>::value>* = nullptr>
998 _LIBCPP_HIDE_FROM_ABI constexpr
999 explicit(!_BothImplicitlyConvertible<pair<_U1, _U2>&>::value)
1000 tuple(pair<_U1, _U2>& __p) : __base_(__p) {}
1001
1002 template <class _Alloc, class _U1, class _U2, enable_if_t<
1003 _EnableCtorFromPair<std::pair<_U1, _U2>&>::value>* = nullptr>
1004 _LIBCPP_HIDE_FROM_ABI constexpr
1005 explicit(!_BothImplicitlyConvertible<pair<_U1, _U2>&>::value)
1006 tuple(allocator_arg_t, const _Alloc& __alloc, pair<_U1, _U2>& __p) : __base_(allocator_arg_t(), __alloc, __p) {}
1007#endif
9081008
909 template <class _Up1, class _Up2, class ..._DependentTp>
910 struct _EnableExplicitMoveFromPair : _And<
911 is_constructible<_FirstType<_DependentTp...>, _Up1>,
912 is_constructible<_SecondType<_DependentTp...>, _Up2>,
913 _Not<is_convertible<_Up1, _FirstType<_DependentTp...> > >, // explicit check
914 _Not<is_convertible<_Up2, _SecondType<_DependentTp...> > >
915 > { };
1009 // tuple(pair<U1, U2>&&) constructors (including allocator_arg_t variants)
9161010
9171011 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
9181012 _And<
919 _BoolConstant<sizeof...(_Tp) == 2>,
920 _EnableImplicitMoveFromPair<_Up1, _Up2, _Tp...>
1013 _EnableCtorFromPair<pair<_Up1, _Up2>&&>,
1014 _BothImplicitlyConvertible<pair<_Up1, _Up2>&&> // explicit check
9211015 >::value
9221016 , int> = 0>
9231017 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
9241018 tuple(pair<_Up1, _Up2>&& __p)
925 _NOEXCEPT_((_And<
926 is_nothrow_constructible<_FirstType<_Tp...>, _Up1>,
927 is_nothrow_constructible<_SecondType<_Tp...>, _Up2>
928 >::value))
1019 _NOEXCEPT_((_NothrowConstructibleFromPair<pair<_Up1, _Up2>&&>::value))
9291020 : __base_(_VSTD::move(__p))
9301021 { }
9311022
9321023 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
9331024 _And<
934 _BoolConstant<sizeof...(_Tp) == 2>,
935 _EnableExplicitMoveFromPair<_Up1, _Up2, _Tp...>
1025 _EnableCtorFromPair<pair<_Up1, _Up2>&&>,
1026 _Not<_BothImplicitlyConvertible<pair<_Up1, _Up2>&&> > // explicit check
9361027 >::value
9371028 , int> = 0>
9381029 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
9391030 explicit tuple(pair<_Up1, _Up2>&& __p)
940 _NOEXCEPT_((_And<
941 is_nothrow_constructible<_FirstType<_Tp...>, _Up1>,
942 is_nothrow_constructible<_SecondType<_Tp...>, _Up2>
943 >::value))
1031 _NOEXCEPT_((_NothrowConstructibleFromPair<pair<_Up1, _Up2>&&>::value))
9441032 : __base_(_VSTD::move(__p))
9451033 { }
9461034
9471035 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
9481036 _And<
949 _BoolConstant<sizeof...(_Tp) == 2>,
950 _EnableImplicitMoveFromPair<_Up1, _Up2, _Tp...>
1037 _EnableCtorFromPair<pair<_Up1, _Up2>&&>,
1038 _BothImplicitlyConvertible<pair<_Up1, _Up2>&&> // explicit check
9511039 >::value
9521040 , int> = 0>
9531041 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
......@@ -957,8 +1045,8 @@ public:
9571045
9581046 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
9591047 _And<
960 _BoolConstant<sizeof...(_Tp) == 2>,
961 _EnableExplicitMoveFromPair<_Up1, _Up2, _Tp...>
1048 _EnableCtorFromPair<pair<_Up1, _Up2>&&>,
1049 _Not<_BothImplicitlyConvertible<pair<_Up1, _Up2>&&> > // explicit check
9621050 >::value
9631051 , int> = 0>
9641052 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
......@@ -966,6 +1054,23 @@ public:
9661054 : __base_(allocator_arg_t(), __a, _VSTD::move(__p))
9671055 { }
9681056
1057#if _LIBCPP_STD_VER > 20
1058 // tuple(const pair<U1, U2>&&) constructors (including allocator_arg_t variants)
1059
1060 template <class _U1, class _U2, enable_if_t<
1061 _EnableCtorFromPair<const pair<_U1, _U2>&&>::value>* = nullptr>
1062 _LIBCPP_HIDE_FROM_ABI constexpr
1063 explicit(!_BothImplicitlyConvertible<const pair<_U1, _U2>&&>::value)
1064 tuple(const pair<_U1, _U2>&& __p) : __base_(std::move(__p)) {}
1065
1066 template <class _Alloc, class _U1, class _U2, enable_if_t<
1067 _EnableCtorFromPair<const pair<_U1, _U2>&&>::value>* = nullptr>
1068 _LIBCPP_HIDE_FROM_ABI constexpr
1069 explicit(!_BothImplicitlyConvertible<const pair<_U1, _U2>&&>::value)
1070 tuple(allocator_arg_t, const _Alloc& __alloc, const pair<_U1, _U2>&& __p)
1071 : __base_(allocator_arg_t(), __alloc, std::move(__p)) {}
1072#endif // _LIBCPP_STD_VER > 20
1073
9691074 // [tuple.assign]
9701075 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
9711076 tuple& operator=(_If<_And<is_copy_assignable<_Tp>...>::value, tuple, __nat> const& __tuple)
......@@ -976,6 +1081,25 @@ public:
9761081 return *this;
9771082 }
9781083
1084#if _LIBCPP_STD_VER > 20
1085 _LIBCPP_HIDE_FROM_ABI constexpr
1086 const tuple& operator=(tuple const& __tuple) const
1087 requires (_And<is_copy_assignable<const _Tp>...>::value) {
1088 std::__memberwise_copy_assign(*this, __tuple, typename __make_tuple_indices<sizeof...(_Tp)>::type());
1089 return *this;
1090 }
1091
1092 _LIBCPP_HIDE_FROM_ABI constexpr
1093 const tuple& operator=(tuple&& __tuple) const
1094 requires (_And<is_assignable<const _Tp&, _Tp>...>::value) {
1095 std::__memberwise_forward_assign(*this,
1096 std::move(__tuple),
1097 __tuple_types<_Tp...>(),
1098 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1099 return *this;
1100 }
1101#endif // _LIBCPP_STD_VER > 20
1102
9791103 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
9801104 tuple& operator=(_If<_And<is_move_assignable<_Tp>...>::value, tuple, __nat>&& __tuple)
9811105 _NOEXCEPT_((_And<is_nothrow_move_assignable<_Tp>...>::value))
......@@ -1017,38 +1141,89 @@ public:
10171141 return *this;
10181142 }
10191143
1020 template<class _Up1, class _Up2, class _Dep = true_type, __enable_if_t<
1021 _And<_Dep,
1022 _BoolConstant<sizeof...(_Tp) == 2>,
1023 is_assignable<_FirstType<_Tp..., _Dep>&, _Up1 const&>,
1024 is_assignable<_SecondType<_Tp..., _Dep>&, _Up2 const&>
1025 >::value
1144
1145#if _LIBCPP_STD_VER > 20
1146 template <class... _UTypes, enable_if_t<
1147 _And<_BoolConstant<sizeof...(_Tp) == sizeof...(_UTypes)>,
1148 is_assignable<const _Tp&, const _UTypes&>...>::value>* = nullptr>
1149 _LIBCPP_HIDE_FROM_ABI constexpr
1150 const tuple& operator=(const tuple<_UTypes...>& __u) const {
1151 std::__memberwise_copy_assign(*this,
1152 __u,
1153 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1154 return *this;
1155 }
1156
1157 template <class... _UTypes, enable_if_t<
1158 _And<_BoolConstant<sizeof...(_Tp) == sizeof...(_UTypes)>,
1159 is_assignable<const _Tp&, _UTypes>...>::value>* = nullptr>
1160 _LIBCPP_HIDE_FROM_ABI constexpr
1161 const tuple& operator=(tuple<_UTypes...>&& __u) const {
1162 std::__memberwise_forward_assign(*this,
1163 __u,
1164 __tuple_types<_UTypes...>(),
1165 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1166 return *this;
1167 }
1168#endif // _LIBCPP_STD_VER > 20
1169
1170 template <template<class...> class Pred, bool _Const,
1171 class _Pair, class _DecayedPair = __uncvref_t<_Pair>, class _Tuple = tuple>
1172 struct _AssignPredicateFromPair : false_type {};
1173
1174 template <template<class...> class Pred, bool _Const,
1175 class _Pair, class _Up1, class _Up2, class _Tp1, class _Tp2>
1176 struct _AssignPredicateFromPair<Pred, _Const, _Pair, pair<_Up1, _Up2>, tuple<_Tp1, _Tp2> > :
1177 _And<Pred<__maybe_const<_Const, _Tp1>&, __copy_cvref_t<_Pair, _Up1> >,
1178 Pred<__maybe_const<_Const, _Tp2>&, __copy_cvref_t<_Pair, _Up2> >
1179 > {};
1180
1181 template <bool _Const, class _Pair>
1182 struct _EnableAssignFromPair : _AssignPredicateFromPair<is_assignable, _Const, _Pair> {};
1183
1184 template <bool _Const, class _Pair>
1185 struct _NothrowAssignFromPair : _AssignPredicateFromPair<is_nothrow_assignable, _Const, _Pair> {};
1186
1187#if _LIBCPP_STD_VER > 20
1188 template <class _U1, class _U2, enable_if_t<
1189 _EnableAssignFromPair<true, const pair<_U1, _U2>&>::value>* = nullptr>
1190 _LIBCPP_HIDE_FROM_ABI constexpr
1191 const tuple& operator=(const pair<_U1, _U2>& __pair) const
1192 noexcept(_NothrowAssignFromPair<true, const pair<_U1, _U2>&>::value) {
1193 std::get<0>(*this) = __pair.first;
1194 std::get<1>(*this) = __pair.second;
1195 return *this;
1196 }
1197
1198 template <class _U1, class _U2, enable_if_t<
1199 _EnableAssignFromPair<true, pair<_U1, _U2>&&>::value>* = nullptr>
1200 _LIBCPP_HIDE_FROM_ABI constexpr
1201 const tuple& operator=(pair<_U1, _U2>&& __pair) const
1202 noexcept(_NothrowAssignFromPair<true, pair<_U1, _U2>&&>::value) {
1203 std::get<0>(*this) = std::move(__pair.first);
1204 std::get<1>(*this) = std::move(__pair.second);
1205 return *this;
1206 }
1207#endif // _LIBCPP_STD_VER > 20
1208
1209 template<class _Up1, class _Up2, __enable_if_t<
1210 _EnableAssignFromPair<false, pair<_Up1, _Up2> const&>::value
10261211 ,int> = 0>
10271212 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
10281213 tuple& operator=(pair<_Up1, _Up2> const& __pair)
1029 _NOEXCEPT_((_And<
1030 is_nothrow_assignable<_FirstType<_Tp...>&, _Up1 const&>,
1031 is_nothrow_assignable<_SecondType<_Tp...>&, _Up2 const&>
1032 >::value))
1214 _NOEXCEPT_((_NothrowAssignFromPair<false, pair<_Up1, _Up2> const&>::value))
10331215 {
10341216 _VSTD::get<0>(*this) = __pair.first;
10351217 _VSTD::get<1>(*this) = __pair.second;
10361218 return *this;
10371219 }
10381220
1039 template<class _Up1, class _Up2, class _Dep = true_type, __enable_if_t<
1040 _And<_Dep,
1041 _BoolConstant<sizeof...(_Tp) == 2>,
1042 is_assignable<_FirstType<_Tp..., _Dep>&, _Up1>,
1043 is_assignable<_SecondType<_Tp..., _Dep>&, _Up2>
1044 >::value
1221 template<class _Up1, class _Up2, __enable_if_t<
1222 _EnableAssignFromPair<false, pair<_Up1, _Up2>&&>::value
10451223 ,int> = 0>
10461224 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
10471225 tuple& operator=(pair<_Up1, _Up2>&& __pair)
1048 _NOEXCEPT_((_And<
1049 is_nothrow_assignable<_FirstType<_Tp...>&, _Up1>,
1050 is_nothrow_assignable<_SecondType<_Tp...>&, _Up2>
1051 >::value))
1226 _NOEXCEPT_((_NothrowAssignFromPair<false, pair<_Up1, _Up2>&&>::value))
10521227 {
10531228 _VSTD::get<0>(*this) = _VSTD::forward<_Up1>(__pair.first);
10541229 _VSTD::get<1>(*this) = _VSTD::forward<_Up2>(__pair.second);
......@@ -1092,6 +1267,13 @@ public:
10921267 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
10931268 void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
10941269 {__base_.swap(__t.__base_);}
1270
1271#if _LIBCPP_STD_VER > 20
1272 _LIBCPP_HIDE_FROM_ABI constexpr
1273 void swap(const tuple& __t) const noexcept(__all<is_nothrow_swappable_v<const _Tp&>...>::value) {
1274 __base_.swap(__t.__base_);
1275 }
1276#endif // _LIBCPP_STD_VER > 20
10951277};
10961278
10971279template <>
......@@ -1114,6 +1296,9 @@ public:
11141296 tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
11151297 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
11161298 void swap(tuple&) _NOEXCEPT {}
1299#if _LIBCPP_STD_VER > 20
1300 _LIBCPP_HIDE_FROM_ABI constexpr void swap(const tuple&) const noexcept {}
1301#endif
11171302};
11181303
11191304#if _LIBCPP_STD_VER > 20
......@@ -1128,7 +1313,7 @@ template <class... _TTypes, class... _UTypes>
11281313struct common_type<tuple<_TTypes...>, tuple<_UTypes...>> {
11291314 using type = tuple<common_type_t<_TTypes, _UTypes>...>;
11301315};
1131#endif
1316#endif // _LIBCPP_STD_VER > 20
11321317
11331318#if _LIBCPP_STD_VER > 14
11341319template <class ..._Tp>
......@@ -1145,15 +1330,21 @@ tuple(allocator_arg_t, _Alloc, tuple<_Tp...>) -> tuple<_Tp...>;
11451330
11461331template <class ..._Tp>
11471332inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1148typename enable_if
1149<
1150 __all<__is_swappable<_Tp>::value...>::value,
1151 void
1152>::type
1333__enable_if_t<__all<__is_swappable<_Tp>::value...>::value, void>
11531334swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
11541335 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
11551336 {__t.swap(__u);}
11561337
1338#if _LIBCPP_STD_VER > 20
1339template <class... _Tp>
1340_LIBCPP_HIDE_FROM_ABI constexpr
1341enable_if_t<__all<is_swappable_v<const _Tp>...>::value, void>
1342swap(const tuple<_Tp...>& __lhs, const tuple<_Tp...>& __rhs)
1343 noexcept(__all<is_nothrow_swappable_v<const _Tp>...>::value) {
1344 __lhs.swap(__rhs);
1345}
1346#endif
1347
11571348// get
11581349
11591350template <size_t _Ip, class ..._Tp>
......@@ -1333,7 +1524,7 @@ operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
13331524 return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
13341525}
13351526
1336#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
1527#if _LIBCPP_STD_VER > 17
13371528
13381529// operator<=>
13391530
......@@ -1355,7 +1546,7 @@ operator<=>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
13551546 return _VSTD::__tuple_compare_three_way(__x, __y, index_sequence_for<_Tp...>{});
13561547}
13571548
1358#else // !defined(_LIBCPP_HAS_NO_CONCEPTS)
1549#else // _LIBCPP_STD_VER > 17
13591550
13601551template <class ..._Tp, class ..._Up>
13611552inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
......@@ -1425,7 +1616,7 @@ operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
14251616 return !(__y < __x);
14261617}
14271618
1428#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
1619#endif // _LIBCPP_STD_VER > 17
14291620
14301621// tuple_cat
14311622
......@@ -1445,9 +1636,10 @@ struct __tuple_cat_return_1
14451636template <class ..._Types, class _Tuple0>
14461637struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
14471638{
1448 typedef _LIBCPP_NODEBUG typename __tuple_cat_type<tuple<_Types...>,
1449 typename __make_tuple_types<typename __uncvref<_Tuple0>::type>::type>::type
1450 type;
1639 using type _LIBCPP_NODEBUG = typename __tuple_cat_type<
1640 tuple<_Types...>,
1641 typename __make_tuple_types<__uncvref_t<_Tuple0> >::type
1642 >::type;
14511643};
14521644
14531645template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
......@@ -1455,7 +1647,7 @@ struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...
14551647 : public __tuple_cat_return_1<
14561648 typename __tuple_cat_type<
14571649 tuple<_Types...>,
1458 typename __make_tuple_types<typename __uncvref<_Tuple0>::type>::type
1650 typename __make_tuple_types<__uncvref_t<_Tuple0> >::type
14591651 >::type,
14601652 __tuple_like<typename remove_reference<_Tuple1>::type>::value,
14611653 _Tuple1, _Tuples...>
......@@ -1529,6 +1721,7 @@ struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J
15291721 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
15301722 operator()(tuple<_Types...> __t, _Tuple0&& __t0)
15311723 {
1724 (void)__t; // avoid unused parameter warning on GCC when _I0 is empty
15321725 return _VSTD::forward_as_tuple(
15331726 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
15341727 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
......@@ -1539,6 +1732,7 @@ struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J
15391732 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
15401733 operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
15411734 {
1735 (void)__t; // avoid unused parameter warning on GCC when _I0 is empty
15421736 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple0>::type _T0;
15431737 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple1>::type _T1;
15441738 return __tuple_cat<
......@@ -1593,7 +1787,7 @@ inline _LIBCPP_INLINE_VISIBILITY
15931787constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
15941788 __tuple_indices<_Id...>)
15951789_LIBCPP_NOEXCEPT_RETURN(
1596 _VSTD::__invoke_constexpr(
1790 _VSTD::__invoke(
15971791 _VSTD::forward<_Fn>(__f),
15981792 _VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...)
15991793)
lib/libcxx/include/type_traits+132-3477
......@@ -416,3457 +416,178 @@ namespace std
416416}
417417
418418*/
419#include <__assert> // all public C++ headers provide the assertion handler
419420#include <__config>
421#include <__functional/invoke.h>
422#include <__type_traits/add_const.h>
423#include <__type_traits/add_cv.h>
424#include <__type_traits/add_lvalue_reference.h>
425#include <__type_traits/add_pointer.h>
426#include <__type_traits/add_rvalue_reference.h>
427#include <__type_traits/add_volatile.h>
428#include <__type_traits/aligned_storage.h>
429#include <__type_traits/aligned_union.h>
430#include <__type_traits/alignment_of.h>
431#include <__type_traits/apply_cv.h>
432#include <__type_traits/common_reference.h>
433#include <__type_traits/common_type.h>
434#include <__type_traits/conditional.h>
435#include <__type_traits/conjunction.h>
436#include <__type_traits/decay.h>
437#include <__type_traits/disjunction.h>
438#include <__type_traits/enable_if.h>
439#include <__type_traits/extent.h>
440#include <__type_traits/has_unique_object_representation.h>
441#include <__type_traits/has_virtual_destructor.h>
442#include <__type_traits/integral_constant.h>
443#include <__type_traits/is_abstract.h>
444#include <__type_traits/is_aggregate.h>
445#include <__type_traits/is_arithmetic.h>
446#include <__type_traits/is_array.h>
447#include <__type_traits/is_assignable.h>
448#include <__type_traits/is_base_of.h>
449#include <__type_traits/is_bounded_array.h>
450#include <__type_traits/is_callable.h>
451#include <__type_traits/is_class.h>
452#include <__type_traits/is_compound.h>
453#include <__type_traits/is_const.h>
454#include <__type_traits/is_constant_evaluated.h>
455#include <__type_traits/is_constructible.h>
456#include <__type_traits/is_convertible.h>
457#include <__type_traits/is_copy_assignable.h>
458#include <__type_traits/is_copy_constructible.h>
459#include <__type_traits/is_default_constructible.h>
460#include <__type_traits/is_destructible.h>
461#include <__type_traits/is_empty.h>
462#include <__type_traits/is_enum.h>
463#include <__type_traits/is_final.h>
464#include <__type_traits/is_floating_point.h>
465#include <__type_traits/is_function.h>
466#include <__type_traits/is_fundamental.h>
467#include <__type_traits/is_integral.h>
468#include <__type_traits/is_literal_type.h>
469#include <__type_traits/is_member_function_pointer.h>
470#include <__type_traits/is_member_object_pointer.h>
471#include <__type_traits/is_member_pointer.h>
472#include <__type_traits/is_move_assignable.h>
473#include <__type_traits/is_move_constructible.h>
474#include <__type_traits/is_nothrow_assignable.h>
475#include <__type_traits/is_nothrow_constructible.h>
476#include <__type_traits/is_nothrow_convertible.h>
477#include <__type_traits/is_nothrow_copy_assignable.h>
478#include <__type_traits/is_nothrow_copy_constructible.h>
479#include <__type_traits/is_nothrow_default_constructible.h>
480#include <__type_traits/is_nothrow_destructible.h>
481#include <__type_traits/is_nothrow_move_assignable.h>
482#include <__type_traits/is_nothrow_move_constructible.h>
483#include <__type_traits/is_null_pointer.h>
484#include <__type_traits/is_object.h>
485#include <__type_traits/is_pod.h>
486#include <__type_traits/is_pointer.h>
487#include <__type_traits/is_polymorphic.h>
488#include <__type_traits/is_reference.h>
489#include <__type_traits/is_reference_wrapper.h>
490#include <__type_traits/is_referenceable.h>
491#include <__type_traits/is_same.h>
492#include <__type_traits/is_scalar.h>
493#include <__type_traits/is_scoped_enum.h>
494#include <__type_traits/is_signed.h>
495#include <__type_traits/is_standard_layout.h>
496#include <__type_traits/is_trivial.h>
497#include <__type_traits/is_trivially_assignable.h>
498#include <__type_traits/is_trivially_constructible.h>
499#include <__type_traits/is_trivially_copy_assignable.h>
500#include <__type_traits/is_trivially_copy_constructible.h>
501#include <__type_traits/is_trivially_copyable.h>
502#include <__type_traits/is_trivially_default_constructible.h>
503#include <__type_traits/is_trivially_destructible.h>
504#include <__type_traits/is_trivially_move_assignable.h>
505#include <__type_traits/is_trivially_move_constructible.h>
506#include <__type_traits/is_unbounded_array.h>
507#include <__type_traits/is_union.h>
508#include <__type_traits/is_unsigned.h>
509#include <__type_traits/is_void.h>
510#include <__type_traits/is_volatile.h>
511#include <__type_traits/make_signed.h>
512#include <__type_traits/make_unsigned.h>
513#include <__type_traits/negation.h>
514#include <__type_traits/rank.h>
515#include <__type_traits/remove_all_extents.h>
516#include <__type_traits/remove_const.h>
517#include <__type_traits/remove_cv.h>
518#include <__type_traits/remove_extent.h>
519#include <__type_traits/remove_pointer.h>
520#include <__type_traits/remove_reference.h>
521#include <__type_traits/remove_volatile.h>
522#include <__type_traits/type_identity.h>
523#include <__type_traits/underlying_type.h>
524#include <__type_traits/void_t.h>
525#include <__utility/declval.h>
420526#include <cstddef>
527#include <cstdint>
421528#include <version>
422529
423530#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
424#pragma GCC system_header
531# pragma GCC system_header
425532#endif
426533
427534_LIBCPP_BEGIN_NAMESPACE_STD
428535
429536template <class _T1, class _T2> struct _LIBCPP_TEMPLATE_VIS pair;
430template <class _Tp> class _LIBCPP_TEMPLATE_VIS reference_wrapper;
431537template <class _Tp> struct _LIBCPP_TEMPLATE_VIS hash;
432538
433template <class _Tp, _Tp __v>
434struct _LIBCPP_TEMPLATE_VIS integral_constant
435{
436 static _LIBCPP_CONSTEXPR const _Tp value = __v;
437 typedef _Tp value_type;
438 typedef integral_constant type;
439 _LIBCPP_INLINE_VISIBILITY
440 _LIBCPP_CONSTEXPR operator value_type() const _NOEXCEPT {return value;}
441#if _LIBCPP_STD_VER > 11
442 _LIBCPP_INLINE_VISIBILITY
443 constexpr value_type operator ()() const _NOEXCEPT {return value;}
444#endif
445};
446
447template <class _Tp, _Tp __v>
448_LIBCPP_CONSTEXPR const _Tp integral_constant<_Tp, __v>::value;
449
450#if _LIBCPP_STD_VER > 14
451template <bool __b>
452using bool_constant = integral_constant<bool, __b>;
453#define _LIBCPP_BOOL_CONSTANT(__b) bool_constant<(__b)>
454#else
455#define _LIBCPP_BOOL_CONSTANT(__b) integral_constant<bool,(__b)>
456#endif
457
458template <bool, class _Tp = void> struct _LIBCPP_TEMPLATE_VIS enable_if {};
459template <class _Tp> struct _LIBCPP_TEMPLATE_VIS enable_if<true, _Tp> {typedef _Tp type;};
460
461template <bool _Bp, class _Tp = void> using __enable_if_t _LIBCPP_NODEBUG = typename enable_if<_Bp, _Tp>::type;
462
463#if _LIBCPP_STD_VER > 11
464template <bool _Bp, class _Tp = void> using enable_if_t = typename enable_if<_Bp, _Tp>::type;
465#endif
466
467typedef _LIBCPP_BOOL_CONSTANT(true) true_type;
468typedef _LIBCPP_BOOL_CONSTANT(false) false_type;
469
470template <bool _Val>
471using _BoolConstant _LIBCPP_NODEBUG = integral_constant<bool, _Val>;
472
473template <bool> struct _MetaBase;
474template <>
475struct _MetaBase<true> {
476 template <class _Tp, class _Up>
477 using _SelectImpl _LIBCPP_NODEBUG = _Tp;
478 template <template <class...> class _FirstFn, template <class...> class, class ..._Args>
479 using _SelectApplyImpl _LIBCPP_NODEBUG = _FirstFn<_Args...>;
480 template <class _First, class...>
481 using _FirstImpl _LIBCPP_NODEBUG = _First;
482 template <class, class _Second, class...>
483 using _SecondImpl _LIBCPP_NODEBUG = _Second;
484 template <class _Result, class _First, class ..._Rest>
485 using _OrImpl _LIBCPP_NODEBUG = typename _MetaBase<_First::value != true && sizeof...(_Rest) != 0>::template _OrImpl<_First, _Rest...>;
486};
487
488template <>
489struct _MetaBase<false> {
490 template <class _Tp, class _Up>
491 using _SelectImpl _LIBCPP_NODEBUG = _Up;
492 template <template <class...> class, template <class...> class _SecondFn, class ..._Args>
493 using _SelectApplyImpl _LIBCPP_NODEBUG = _SecondFn<_Args...>;
494 template <class _Result, class ...>
495 using _OrImpl _LIBCPP_NODEBUG = _Result;
496};
497template <bool _Cond, class _IfRes, class _ElseRes>
498using _If _LIBCPP_NODEBUG = typename _MetaBase<_Cond>::template _SelectImpl<_IfRes, _ElseRes>;
499template <class ..._Rest>
500using _Or _LIBCPP_NODEBUG = typename _MetaBase< sizeof...(_Rest) != 0 >::template _OrImpl<false_type, _Rest...>;
501template <class _Pred>
502struct _Not : _BoolConstant<!_Pred::value> {};
503template <class ..._Args>
504using _FirstType _LIBCPP_NODEBUG = typename _MetaBase<(sizeof...(_Args) >= 1)>::template _FirstImpl<_Args...>;
505template <class ..._Args>
506using _SecondType _LIBCPP_NODEBUG = typename _MetaBase<(sizeof...(_Args) >= 2)>::template _SecondImpl<_Args...>;
507
508template <class ...> using __expand_to_true = true_type;
509template <class ..._Pred>
510__expand_to_true<__enable_if_t<_Pred::value>...> __and_helper(int);
511template <class ...>
512false_type __and_helper(...);
513template <class ..._Pred>
514using _And _LIBCPP_NODEBUG = decltype(__and_helper<_Pred...>(0));
515
516template <template <class...> class _Func, class ..._Args>
517struct _Lazy : _Func<_Args...> {};
518
519// Member detector base
520
521template <template <class...> class _Templ, class ..._Args, class = _Templ<_Args...> >
522true_type __sfinae_test_impl(int);
523template <template <class...> class, class ...>
524false_type __sfinae_test_impl(...);
525
526template <template <class ...> class _Templ, class ..._Args>
527using _IsValidExpansion _LIBCPP_NODEBUG = decltype(__sfinae_test_impl<_Templ, _Args...>(0));
528
529template <class>
530struct __void_t { typedef void type; };
531
532template <class _Tp>
533struct __identity { typedef _Tp type; };
534
535template <class _Tp>
536using __identity_t _LIBCPP_NODEBUG = typename __identity<_Tp>::type;
537
538template <class _Tp, bool>
539struct _LIBCPP_TEMPLATE_VIS __dependent_type : public _Tp {};
540
541
542template <bool _Bp, class _If, class _Then>
543 struct _LIBCPP_TEMPLATE_VIS conditional {typedef _If type;};
544template <class _If, class _Then>
545 struct _LIBCPP_TEMPLATE_VIS conditional<false, _If, _Then> {typedef _Then type;};
546
547#if _LIBCPP_STD_VER > 11
548template <bool _Bp, class _If, class _Then> using conditional_t = typename conditional<_Bp, _If, _Then>::type;
549#endif
550
551// is_same
552
553template <class _Tp, class _Up>
554struct _LIBCPP_TEMPLATE_VIS is_same : _BoolConstant<__is_same(_Tp, _Up)> { };
555
556#if _LIBCPP_STD_VER > 14
557template <class _Tp, class _Up>
558inline constexpr bool is_same_v = __is_same(_Tp, _Up);
559#endif
560
561// _IsSame<T,U> has the same effect as is_same<T,U> but instantiates fewer types:
562// is_same<A,B> and is_same<C,D> are guaranteed to be different types, but
563// _IsSame<A,B> and _IsSame<C,D> are the same type (namely, false_type).
564// Neither GCC nor Clang can mangle the __is_same builtin, so _IsSame
565// mustn't be directly used anywhere that contributes to name-mangling
566// (such as in a dependent return type).
567
568template <class _Tp, class _Up>
569using _IsSame = _BoolConstant<__is_same(_Tp, _Up)>;
570
571template <class _Tp, class _Up>
572using _IsNotSame = _BoolConstant<!__is_same(_Tp, _Up)>;
573
574template <class _Tp>
575using __test_for_primary_template = __enable_if_t<
576 _IsSame<_Tp, typename _Tp::__primary_template>::value
577 >;
578template <class _Tp>
579using __is_primary_template = _IsValidExpansion<
580 __test_for_primary_template, _Tp
581 >;
582
583// helper class
584
585struct __two {char __lx[2];};
586
587// is_const
588
589#if __has_keyword(__is_const)
590
591template <class _Tp>
592struct _LIBCPP_TEMPLATE_VIS is_const : _BoolConstant<__is_const(_Tp)> { };
593
594#if _LIBCPP_STD_VER > 14
595template <class _Tp>
596inline constexpr bool is_const_v = __is_const(_Tp);
597#endif
598
599#else
600
601template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_const : public false_type {};
602template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_const<_Tp const> : public true_type {};
603
604#if _LIBCPP_STD_VER > 14
605template <class _Tp>
606inline constexpr bool is_const_v = is_const<_Tp>::value;
607#endif
608
609#endif // __has_keyword(__is_const)
610
611// is_volatile
612
613#if __has_keyword(__is_volatile)
614
615template <class _Tp>
616struct _LIBCPP_TEMPLATE_VIS is_volatile : _BoolConstant<__is_volatile(_Tp)> { };
617
618#if _LIBCPP_STD_VER > 14
619template <class _Tp>
620inline constexpr bool is_volatile_v = __is_volatile(_Tp);
621#endif
622
623#else
624
625template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_volatile : public false_type {};
626template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_volatile<_Tp volatile> : public true_type {};
627
628#if _LIBCPP_STD_VER > 14
629template <class _Tp>
630inline constexpr bool is_volatile_v = is_volatile<_Tp>::value;
631#endif
632
633#endif // __has_keyword(__is_volatile)
634
635// remove_const
636
637#if __has_keyword(__remove_const)
638
639template <class _Tp>
640struct _LIBCPP_TEMPLATE_VIS remove_const {typedef __remove_const(_Tp) type;};
641
642#if _LIBCPP_STD_VER > 11
643template <class _Tp> using remove_const_t = __remove_const(_Tp);
644#endif
645
646#else
647
648template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_const {typedef _Tp type;};
649template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_const<const _Tp> {typedef _Tp type;};
650#if _LIBCPP_STD_VER > 11
651template <class _Tp> using remove_const_t = typename remove_const<_Tp>::type;
652#endif
653
654#endif // __has_keyword(__remove_const)
655
656// remove_volatile
657
658#if __has_keyword(__remove_volatile)
659
660template <class _Tp>
661struct _LIBCPP_TEMPLATE_VIS remove_volatile {typedef __remove_volatile(_Tp) type;};
662
663#if _LIBCPP_STD_VER > 11
664template <class _Tp> using remove_volatile_t = __remove_volatile(_Tp);
665#endif
666
667#else
668
669template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_volatile {typedef _Tp type;};
670template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_volatile<volatile _Tp> {typedef _Tp type;};
671#if _LIBCPP_STD_VER > 11
672template <class _Tp> using remove_volatile_t = typename remove_volatile<_Tp>::type;
673#endif
674
675#endif // __has_keyword(__remove_volatile)
676
677// remove_cv
678
679#if __has_keyword(__remove_cv)
680
681template <class _Tp>
682struct _LIBCPP_TEMPLATE_VIS remove_cv {typedef __remove_cv(_Tp) type;};
683
684#if _LIBCPP_STD_VER > 11
685template <class _Tp> using remove_cv_t = __remove_cv(_Tp);
686#endif
687
688#else
689
690template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_cv
691{typedef typename remove_volatile<typename remove_const<_Tp>::type>::type type;};
692#if _LIBCPP_STD_VER > 11
693template <class _Tp> using remove_cv_t = typename remove_cv<_Tp>::type;
694#endif
695
696#endif // __has_keyword(__remove_cv)
697
698// is_void
699
700#if __has_keyword(__is_void)
701
702template <class _Tp>
703struct _LIBCPP_TEMPLATE_VIS is_void : _BoolConstant<__is_void(_Tp)> { };
704
705#if _LIBCPP_STD_VER > 14
706template <class _Tp>
707inline constexpr bool is_void_v = __is_void(_Tp);
708#endif
709
710#else
711
712template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_void
713 : public is_same<typename remove_cv<_Tp>::type, void> {};
714
715#if _LIBCPP_STD_VER > 14
716template <class _Tp>
717inline constexpr bool is_void_v = is_void<_Tp>::value;
718#endif
719
720#endif // __has_keyword(__is_void)
721
722// __is_nullptr_t
723
724template <class _Tp> struct __is_nullptr_t_impl : public false_type {};
725template <> struct __is_nullptr_t_impl<nullptr_t> : public true_type {};
726
727template <class _Tp> struct _LIBCPP_TEMPLATE_VIS __is_nullptr_t
728 : public __is_nullptr_t_impl<typename remove_cv<_Tp>::type> {};
729
730#if _LIBCPP_STD_VER > 11
731template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_null_pointer
732 : public __is_nullptr_t_impl<typename remove_cv<_Tp>::type> {};
733
734#if _LIBCPP_STD_VER > 14
735template <class _Tp>
736inline constexpr bool is_null_pointer_v = is_null_pointer<_Tp>::value;
737#endif
738#endif // _LIBCPP_STD_VER > 11
739
740// is_integral
741
742#if __has_keyword(__is_integral)
743
744template <class _Tp>
745struct _LIBCPP_TEMPLATE_VIS is_integral : _BoolConstant<__is_integral(_Tp)> { };
746
747#if _LIBCPP_STD_VER > 14
748template <class _Tp>
749inline constexpr bool is_integral_v = __is_integral(_Tp);
750#endif
751
752#else
753
754template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_integral
755 : public _BoolConstant<__libcpp_is_integral<typename remove_cv<_Tp>::type>::value> {};
756
757#if _LIBCPP_STD_VER > 14
758template <class _Tp>
759inline constexpr bool is_integral_v = is_integral<_Tp>::value;
760#endif
761
762#endif // __has_keyword(__is_integral)
763
764// [basic.fundamental] defines five standard signed integer types;
765// __int128_t is an extended signed integer type.
766// The signed and unsigned integer types, plus bool and the
767// five types with "char" in their name, compose the "integral" types.
768
769template <class _Tp> struct __libcpp_is_signed_integer : public false_type {};
770template <> struct __libcpp_is_signed_integer<signed char> : public true_type {};
771template <> struct __libcpp_is_signed_integer<signed short> : public true_type {};
772template <> struct __libcpp_is_signed_integer<signed int> : public true_type {};
773template <> struct __libcpp_is_signed_integer<signed long> : public true_type {};
774template <> struct __libcpp_is_signed_integer<signed long long> : public true_type {};
775#ifndef _LIBCPP_HAS_NO_INT128
776template <> struct __libcpp_is_signed_integer<__int128_t> : public true_type {};
777#endif
778
779template <class _Tp> struct __libcpp_is_unsigned_integer : public false_type {};
780template <> struct __libcpp_is_unsigned_integer<unsigned char> : public true_type {};
781template <> struct __libcpp_is_unsigned_integer<unsigned short> : public true_type {};
782template <> struct __libcpp_is_unsigned_integer<unsigned int> : public true_type {};
783template <> struct __libcpp_is_unsigned_integer<unsigned long> : public true_type {};
784template <> struct __libcpp_is_unsigned_integer<unsigned long long> : public true_type {};
785#ifndef _LIBCPP_HAS_NO_INT128
786template <> struct __libcpp_is_unsigned_integer<__uint128_t> : public true_type {};
787#endif
788
789// is_floating_point
790// <concepts> implements __libcpp_floating_point
791
792template <class _Tp> struct __libcpp_is_floating_point : public false_type {};
793template <> struct __libcpp_is_floating_point<float> : public true_type {};
794template <> struct __libcpp_is_floating_point<double> : public true_type {};
795template <> struct __libcpp_is_floating_point<long double> : public true_type {};
796
797template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_floating_point
798 : public __libcpp_is_floating_point<typename remove_cv<_Tp>::type> {};
799
800#if _LIBCPP_STD_VER > 14
801template <class _Tp>
802inline constexpr bool is_floating_point_v = is_floating_point<_Tp>::value;
803#endif
804
805// is_array
806
807#if __has_keyword(__is_array)
808
809template <class _Tp>
810struct _LIBCPP_TEMPLATE_VIS is_array : _BoolConstant<__is_array(_Tp)> { };
811
812#if _LIBCPP_STD_VER > 14
813template <class _Tp>
814inline constexpr bool is_array_v = __is_array(_Tp);
815#endif
816
817#else
818
819template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_array
820 : public false_type {};
821template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_array<_Tp[]>
822 : public true_type {};
823template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS is_array<_Tp[_Np]>
824 : public true_type {};
825
826#if _LIBCPP_STD_VER > 14
827template <class _Tp>
828inline constexpr bool is_array_v = is_array<_Tp>::value;
829#endif
830
831#endif // __has_keyword(__is_array)
832
833// is_pointer
834
835// Before AppleClang 12.0.5, __is_pointer didn't work for Objective-C types.
836#if __has_keyword(__is_pointer) && \
837 !(defined(_LIBCPP_APPLE_CLANG_VER) && _LIBCPP_APPLE_CLANG_VER < 1205)
838
839template<class _Tp>
840struct _LIBCPP_TEMPLATE_VIS is_pointer : _BoolConstant<__is_pointer(_Tp)> { };
841
842#if _LIBCPP_STD_VER > 14
843template <class _Tp>
844inline constexpr bool is_pointer_v = __is_pointer(_Tp);
845#endif
846
847#else // __has_keyword(__is_pointer)
848
849template <class _Tp> struct __libcpp_is_pointer : public false_type {};
850template <class _Tp> struct __libcpp_is_pointer<_Tp*> : public true_type {};
851
852template <class _Tp> struct __libcpp_remove_objc_qualifiers { typedef _Tp type; };
853#if defined(_LIBCPP_HAS_OBJC_ARC)
854template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __strong> { typedef _Tp type; };
855template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __weak> { typedef _Tp type; };
856template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __autoreleasing> { typedef _Tp type; };
857template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __unsafe_unretained> { typedef _Tp type; };
858#endif
859
860template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_pointer
861 : public __libcpp_is_pointer<typename __libcpp_remove_objc_qualifiers<typename remove_cv<_Tp>::type>::type> {};
862
863#if _LIBCPP_STD_VER > 14
864template <class _Tp>
865inline constexpr bool is_pointer_v = is_pointer<_Tp>::value;
866#endif
867
868#endif // __has_keyword(__is_pointer)
869
870// is_reference
871
872#if __has_keyword(__is_lvalue_reference) && \
873 __has_keyword(__is_rvalue_reference) && \
874 __has_keyword(__is_reference)
875
876template<class _Tp>
877struct _LIBCPP_TEMPLATE_VIS is_lvalue_reference : _BoolConstant<__is_lvalue_reference(_Tp)> { };
878
879template<class _Tp>
880struct _LIBCPP_TEMPLATE_VIS is_rvalue_reference : _BoolConstant<__is_rvalue_reference(_Tp)> { };
881
882template<class _Tp>
883struct _LIBCPP_TEMPLATE_VIS is_reference : _BoolConstant<__is_reference(_Tp)> { };
884
885#if _LIBCPP_STD_VER > 14
886template <class _Tp>
887inline constexpr bool is_reference_v = __is_reference(_Tp);
888template <class _Tp>
889inline constexpr bool is_lvalue_reference_v = __is_lvalue_reference(_Tp);
890template <class _Tp>
891inline constexpr bool is_rvalue_reference_v = __is_rvalue_reference(_Tp);
892#endif
893
894#else // __has_keyword(__is_lvalue_reference) && etc...
895
896template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_lvalue_reference : public false_type {};
897template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_lvalue_reference<_Tp&> : public true_type {};
898
899template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_rvalue_reference : public false_type {};
900template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_rvalue_reference<_Tp&&> : public true_type {};
901
902template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_reference : public false_type {};
903template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_reference<_Tp&> : public true_type {};
904template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_reference<_Tp&&> : public true_type {};
905
906#if _LIBCPP_STD_VER > 14
907template <class _Tp>
908inline constexpr bool is_reference_v = is_reference<_Tp>::value;
909
910template <class _Tp>
911inline constexpr bool is_lvalue_reference_v = is_lvalue_reference<_Tp>::value;
912
913template <class _Tp>
914inline constexpr bool is_rvalue_reference_v = is_rvalue_reference<_Tp>::value;
915#endif
916
917#endif // __has_keyword(__is_lvalue_reference) && etc...
918
919// is_union
920
921#if __has_feature(is_union) || defined(_LIBCPP_COMPILER_GCC)
922
923template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_union
924 : public integral_constant<bool, __is_union(_Tp)> {};
925
926#else
927
928template <class _Tp> struct __libcpp_union : public false_type {};
929template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_union
930 : public __libcpp_union<typename remove_cv<_Tp>::type> {};
931
932#endif
933
934#if _LIBCPP_STD_VER > 14
935template <class _Tp>
936inline constexpr bool is_union_v = is_union<_Tp>::value;
937#endif
938
939// is_class
940
941#if __has_feature(is_class) || defined(_LIBCPP_COMPILER_GCC)
942
943template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_class
944 : public integral_constant<bool, __is_class(_Tp)> {};
945
946#else
947
948namespace __is_class_imp
949{
950template <class _Tp> char __test(int _Tp::*);
951template <class _Tp> __two __test(...);
952}
953
954template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_class
955 : public integral_constant<bool, sizeof(__is_class_imp::__test<_Tp>(0)) == 1 && !is_union<_Tp>::value> {};
956
957#endif
958
959#if _LIBCPP_STD_VER > 14
960template <class _Tp>
961inline constexpr bool is_class_v = is_class<_Tp>::value;
962#endif
963
964// is_function
965
966template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_function
967 : public _BoolConstant<
968#ifdef __clang__
969 __is_function(_Tp)
970#else
971 !(is_reference<_Tp>::value || is_const<const _Tp>::value)
972#endif
973 > {};
974
975
976#if _LIBCPP_STD_VER > 14
977template <class _Tp>
978inline constexpr bool is_function_v = is_function<_Tp>::value;
979#endif
980
981template <class _Tp> struct __libcpp_is_member_pointer {
982 enum {
983 __is_member = false,
984 __is_func = false,
985 __is_obj = false
986 };
987};
988template <class _Tp, class _Up> struct __libcpp_is_member_pointer<_Tp _Up::*> {
989 enum {
990 __is_member = true,
991 __is_func = is_function<_Tp>::value,
992 __is_obj = !__is_func,
993 };
994};
995
996#if __has_keyword(__is_member_function_pointer)
997
998template<class _Tp>
999struct _LIBCPP_TEMPLATE_VIS is_member_function_pointer
1000 : _BoolConstant<__is_member_function_pointer(_Tp)> { };
1001
1002#if _LIBCPP_STD_VER > 14
1003template <class _Tp>
1004inline constexpr bool is_member_function_pointer_v = __is_member_function_pointer(_Tp);
1005#endif
1006
1007#else // __has_keyword(__is_member_function_pointer)
1008
1009template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_member_function_pointer
1010 : public _BoolConstant< __libcpp_is_member_pointer<typename remove_cv<_Tp>::type>::__is_func > {};
1011
1012#if _LIBCPP_STD_VER > 14
1013template <class _Tp>
1014inline constexpr bool is_member_function_pointer_v = is_member_function_pointer<_Tp>::value;
1015#endif
1016
1017#endif // __has_keyword(__is_member_function_pointer)
1018
1019// is_member_pointer
1020
1021#if __has_keyword(__is_member_pointer)
1022
1023template<class _Tp>
1024struct _LIBCPP_TEMPLATE_VIS is_member_pointer : _BoolConstant<__is_member_pointer(_Tp)> { };
1025
1026#if _LIBCPP_STD_VER > 14
1027template <class _Tp>
1028inline constexpr bool is_member_pointer_v = __is_member_pointer(_Tp);
1029#endif
1030
1031#else // __has_keyword(__is_member_pointer)
1032
1033template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_member_pointer
1034 : public _BoolConstant< __libcpp_is_member_pointer<typename remove_cv<_Tp>::type>::__is_member > {};
1035
1036#if _LIBCPP_STD_VER > 14
1037template <class _Tp>
1038inline constexpr bool is_member_pointer_v = is_member_pointer<_Tp>::value;
1039#endif
1040
1041#endif // __has_keyword(__is_member_pointer)
1042
1043// is_member_object_pointer
1044
1045#if __has_keyword(__is_member_object_pointer)
1046
1047template<class _Tp>
1048struct _LIBCPP_TEMPLATE_VIS is_member_object_pointer
1049 : _BoolConstant<__is_member_object_pointer(_Tp)> { };
1050
1051#if _LIBCPP_STD_VER > 14
1052template <class _Tp>
1053inline constexpr bool is_member_object_pointer_v = __is_member_object_pointer(_Tp);
1054#endif
1055
1056#else // __has_keyword(__is_member_object_pointer)
1057
1058template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_member_object_pointer
1059 : public _BoolConstant< __libcpp_is_member_pointer<typename remove_cv<_Tp>::type>::__is_obj > {};
1060
1061#if _LIBCPP_STD_VER > 14
1062template <class _Tp>
1063inline constexpr bool is_member_object_pointer_v = is_member_object_pointer<_Tp>::value;
1064#endif
1065
1066#endif // __has_keyword(__is_member_object_pointer)
1067
1068// is_enum
1069
1070#if __has_feature(is_enum) || defined(_LIBCPP_COMPILER_GCC)
1071
1072template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_enum
1073 : public integral_constant<bool, __is_enum(_Tp)> {};
1074
1075#if _LIBCPP_STD_VER > 14
1076template <class _Tp>
1077inline constexpr bool is_enum_v = __is_enum(_Tp);
1078#endif
1079
1080#else
1081
1082template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_enum
1083 : public integral_constant<bool, !is_void<_Tp>::value &&
1084 !is_integral<_Tp>::value &&
1085 !is_floating_point<_Tp>::value &&
1086 !is_array<_Tp>::value &&
1087 !is_pointer<_Tp>::value &&
1088 !is_reference<_Tp>::value &&
1089 !is_member_pointer<_Tp>::value &&
1090 !is_union<_Tp>::value &&
1091 !is_class<_Tp>::value &&
1092 !is_function<_Tp>::value > {};
1093
1094#if _LIBCPP_STD_VER > 14
1095template <class _Tp>
1096inline constexpr bool is_enum_v = is_enum<_Tp>::value;
1097#endif
1098
1099#endif // __has_feature(is_enum) || defined(_LIBCPP_COMPILER_GCC)
1100
1101// is_arithmetic
1102
1103
1104template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_arithmetic
1105 : public integral_constant<bool, is_integral<_Tp>::value ||
1106 is_floating_point<_Tp>::value> {};
1107
1108#if _LIBCPP_STD_VER > 14
1109template <class _Tp>
1110inline constexpr bool is_arithmetic_v = is_arithmetic<_Tp>::value;
1111#endif
1112
1113// is_fundamental
1114
1115// Before Clang 10, __is_fundamental didn't work for nullptr_t.
1116// In C++03 nullptr_t is library-provided but must still count as "fundamental."
1117#if __has_keyword(__is_fundamental) && \
1118 !(defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER < 1000) && \
1119 !defined(_LIBCPP_CXX03_LANG)
1120
1121template<class _Tp>
1122struct _LIBCPP_TEMPLATE_VIS is_fundamental : _BoolConstant<__is_fundamental(_Tp)> { };
1123
1124#if _LIBCPP_STD_VER > 14
1125template <class _Tp>
1126inline constexpr bool is_fundamental_v = __is_fundamental(_Tp);
1127#endif
1128
1129#else // __has_keyword(__is_fundamental)
1130
1131template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_fundamental
1132 : public integral_constant<bool, is_void<_Tp>::value ||
1133 __is_nullptr_t<_Tp>::value ||
1134 is_arithmetic<_Tp>::value> {};
1135
1136#if _LIBCPP_STD_VER > 14
1137template <class _Tp>
1138inline constexpr bool is_fundamental_v = is_fundamental<_Tp>::value;
1139#endif
1140
1141#endif // __has_keyword(__is_fundamental)
1142
1143// is_scalar
1144
1145// In C++03 nullptr_t is library-provided but must still count as "scalar."
1146#if __has_keyword(__is_scalar) && !defined(_LIBCPP_CXX03_LANG)
1147
1148template<class _Tp>
1149struct _LIBCPP_TEMPLATE_VIS is_scalar : _BoolConstant<__is_scalar(_Tp)> { };
1150
1151#if _LIBCPP_STD_VER > 14
1152template <class _Tp>
1153inline constexpr bool is_scalar_v = __is_scalar(_Tp);
1154#endif
1155
1156#else // __has_keyword(__is_scalar)
1157
1158template <class _Tp> struct __is_block : false_type {};
1159#if defined(_LIBCPP_HAS_EXTENSION_BLOCKS)
1160template <class _Rp, class ..._Args> struct __is_block<_Rp (^)(_Args...)> : true_type {};
1161#endif
1162
1163template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_scalar
1164 : public integral_constant<bool, is_arithmetic<_Tp>::value ||
1165 is_member_pointer<_Tp>::value ||
1166 is_pointer<_Tp>::value ||
1167 __is_nullptr_t<_Tp>::value ||
1168 __is_block<_Tp>::value ||
1169 is_enum<_Tp>::value > {};
1170
1171template <> struct _LIBCPP_TEMPLATE_VIS is_scalar<nullptr_t> : public true_type {};
1172
1173#if _LIBCPP_STD_VER > 14
1174template <class _Tp>
1175inline constexpr bool is_scalar_v = is_scalar<_Tp>::value;
1176#endif
1177
1178#endif // __has_keyword(__is_scalar)
1179
1180// is_object
1181
1182#if __has_keyword(__is_object)
1183
1184template<class _Tp>
1185struct _LIBCPP_TEMPLATE_VIS is_object : _BoolConstant<__is_object(_Tp)> { };
1186
1187#if _LIBCPP_STD_VER > 14
1188template <class _Tp>
1189inline constexpr bool is_object_v = __is_object(_Tp);
1190#endif
1191
1192#else // __has_keyword(__is_object)
1193
1194template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_object
1195 : public integral_constant<bool, is_scalar<_Tp>::value ||
1196 is_array<_Tp>::value ||
1197 is_union<_Tp>::value ||
1198 is_class<_Tp>::value > {};
1199
1200#if _LIBCPP_STD_VER > 14
1201template <class _Tp>
1202inline constexpr bool is_object_v = is_object<_Tp>::value;
1203#endif
1204
1205#endif // __has_keyword(__is_object)
1206
1207// is_compound
1208
1209// >= 11 because in C++03 nullptr isn't actually nullptr
1210#if __has_keyword(__is_compound) && !defined(_LIBCPP_CXX03_LANG)
1211
1212template<class _Tp>
1213struct _LIBCPP_TEMPLATE_VIS is_compound : _BoolConstant<__is_compound(_Tp)> { };
1214
1215#if _LIBCPP_STD_VER > 14
1216template <class _Tp>
1217inline constexpr bool is_compound_v = __is_compound(_Tp);
1218#endif
1219
1220#else // __has_keyword(__is_compound)
1221
1222template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_compound
1223 : public integral_constant<bool, !is_fundamental<_Tp>::value> {};
1224
1225#if _LIBCPP_STD_VER > 14
1226template <class _Tp>
1227inline constexpr bool is_compound_v = is_compound<_Tp>::value;
1228#endif
1229
1230#endif // __has_keyword(__is_compound)
1231
1232// __is_referenceable [defns.referenceable]
1233
1234struct __is_referenceable_impl {
1235 template <class _Tp> static _Tp& __test(int);
1236 template <class _Tp> static __two __test(...);
1237};
1238
1239template <class _Tp>
1240struct __is_referenceable : integral_constant<bool,
1241 _IsNotSame<decltype(__is_referenceable_impl::__test<_Tp>(0)), __two>::value> {};
1242
1243
1244// add_const
1245
1246template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_const {
1247 typedef _LIBCPP_NODEBUG const _Tp type;
1248};
1249
1250#if _LIBCPP_STD_VER > 11
1251template <class _Tp> using add_const_t = typename add_const<_Tp>::type;
1252#endif
1253
1254// add_volatile
1255
1256template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_volatile {
1257 typedef _LIBCPP_NODEBUG volatile _Tp type;
1258};
1259
1260#if _LIBCPP_STD_VER > 11
1261template <class _Tp> using add_volatile_t = typename add_volatile<_Tp>::type;
1262#endif
1263
1264// add_cv
1265template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_cv {
1266 typedef _LIBCPP_NODEBUG const volatile _Tp type;
1267};
1268
1269#if _LIBCPP_STD_VER > 11
1270template <class _Tp> using add_cv_t = typename add_cv<_Tp>::type;
1271#endif
1272
1273// remove_reference
1274
1275#if __has_keyword(__remove_reference)
1276
1277template<class _Tp>
1278struct _LIBCPP_TEMPLATE_VIS remove_reference { typedef __remove_reference(_Tp) type; };
1279
1280#else // __has_keyword(__remove_reference)
1281
1282template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference {typedef _LIBCPP_NODEBUG _Tp type;};
1283template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference<_Tp&> {typedef _LIBCPP_NODEBUG _Tp type;};
1284template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference<_Tp&&> {typedef _LIBCPP_NODEBUG _Tp type;};
1285
1286#if _LIBCPP_STD_VER > 11
1287template <class _Tp> using remove_reference_t = typename remove_reference<_Tp>::type;
1288#endif
1289
1290#endif // __has_keyword(__remove_reference)
1291
1292// add_lvalue_reference
1293
1294template <class _Tp, bool = __is_referenceable<_Tp>::value> struct __add_lvalue_reference_impl { typedef _LIBCPP_NODEBUG _Tp type; };
1295template <class _Tp > struct __add_lvalue_reference_impl<_Tp, true> { typedef _LIBCPP_NODEBUG _Tp& type; };
1296
1297template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_lvalue_reference
1298{typedef _LIBCPP_NODEBUG typename __add_lvalue_reference_impl<_Tp>::type type;};
1299
1300#if _LIBCPP_STD_VER > 11
1301template <class _Tp> using add_lvalue_reference_t = typename add_lvalue_reference<_Tp>::type;
1302#endif
1303
1304template <class _Tp, bool = __is_referenceable<_Tp>::value> struct __add_rvalue_reference_impl { typedef _LIBCPP_NODEBUG _Tp type; };
1305template <class _Tp > struct __add_rvalue_reference_impl<_Tp, true> { typedef _LIBCPP_NODEBUG _Tp&& type; };
1306
1307template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_rvalue_reference
1308{typedef _LIBCPP_NODEBUG typename __add_rvalue_reference_impl<_Tp>::type type;};
1309
1310#if _LIBCPP_STD_VER > 11
1311template <class _Tp> using add_rvalue_reference_t = typename add_rvalue_reference<_Tp>::type;
1312#endif
1313
1314// Suppress deprecation notice for volatile-qualified return type resulting
1315// from volatile-qualified types _Tp.
1316_LIBCPP_SUPPRESS_DEPRECATED_PUSH
1317template <class _Tp> _Tp&& __declval(int);
1318template <class _Tp> _Tp __declval(long);
1319_LIBCPP_SUPPRESS_DEPRECATED_POP
1320
1321template <class _Tp>
1322decltype(__declval<_Tp>(0))
1323declval() _NOEXCEPT;
1324
1325// __uncvref
1326
1327template <class _Tp>
1328struct __uncvref {
1329 typedef _LIBCPP_NODEBUG typename remove_cv<typename remove_reference<_Tp>::type>::type type;
1330};
1331
1332template <class _Tp>
1333struct __unconstref {
1334 typedef _LIBCPP_NODEBUG typename remove_const<typename remove_reference<_Tp>::type>::type type;
1335};
1336
1337#ifndef _LIBCPP_CXX03_LANG
1338template <class _Tp>
1339using __uncvref_t _LIBCPP_NODEBUG = typename __uncvref<_Tp>::type;
1340#endif
1341
1342// __is_same_uncvref
1343
1344template <class _Tp, class _Up>
1345struct __is_same_uncvref : _IsSame<typename __uncvref<_Tp>::type,
1346 typename __uncvref<_Up>::type> {};
1347
1348#if _LIBCPP_STD_VER > 17
1349// remove_cvref - same as __uncvref
1350template <class _Tp>
1351struct remove_cvref : public __uncvref<_Tp> {};
1352
1353template <class _Tp> using remove_cvref_t = typename remove_cvref<_Tp>::type;
1354#endif
1355
1356
1357struct __any
1358{
1359 __any(...);
1360};
1361
1362// remove_pointer
1363
1364template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer {typedef _LIBCPP_NODEBUG _Tp type;};
1365template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp*> {typedef _LIBCPP_NODEBUG _Tp type;};
1366template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp* const> {typedef _LIBCPP_NODEBUG _Tp type;};
1367template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp* volatile> {typedef _LIBCPP_NODEBUG _Tp type;};
1368template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp* const volatile> {typedef _LIBCPP_NODEBUG _Tp type;};
1369
1370#if _LIBCPP_STD_VER > 11
1371template <class _Tp> using remove_pointer_t = typename remove_pointer<_Tp>::type;
1372#endif
1373
1374// add_pointer
1375
1376template <class _Tp,
1377 bool = __is_referenceable<_Tp>::value ||
1378 _IsSame<typename remove_cv<_Tp>::type, void>::value>
1379struct __add_pointer_impl
1380 {typedef _LIBCPP_NODEBUG typename remove_reference<_Tp>::type* type;};
1381template <class _Tp> struct __add_pointer_impl<_Tp, false>
1382 {typedef _LIBCPP_NODEBUG _Tp type;};
1383
1384template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_pointer
1385 {typedef _LIBCPP_NODEBUG typename __add_pointer_impl<_Tp>::type type;};
1386
1387#if _LIBCPP_STD_VER > 11
1388template <class _Tp> using add_pointer_t = typename add_pointer<_Tp>::type;
1389#endif
1390
1391// type_identity
1392#if _LIBCPP_STD_VER > 17
1393template<class _Tp> struct type_identity { typedef _Tp type; };
1394template<class _Tp> using type_identity_t = typename type_identity<_Tp>::type;
1395#endif
1396
1397// is_signed
1398
1399#if __has_keyword(__is_signed)
1400
1401template<class _Tp>
1402struct _LIBCPP_TEMPLATE_VIS is_signed : _BoolConstant<__is_signed(_Tp)> { };
1403
1404#if _LIBCPP_STD_VER > 14
1405template <class _Tp>
1406inline constexpr bool is_signed_v = __is_signed(_Tp);
1407#endif
1408
1409#else // __has_keyword(__is_signed)
1410
1411template <class _Tp, bool = is_integral<_Tp>::value>
1412struct __libcpp_is_signed_impl : public _LIBCPP_BOOL_CONSTANT(_Tp(-1) < _Tp(0)) {};
1413
1414template <class _Tp>
1415struct __libcpp_is_signed_impl<_Tp, false> : public true_type {}; // floating point
1416
1417template <class _Tp, bool = is_arithmetic<_Tp>::value>
1418struct __libcpp_is_signed : public __libcpp_is_signed_impl<_Tp> {};
1419
1420template <class _Tp> struct __libcpp_is_signed<_Tp, false> : public false_type {};
1421
1422template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_signed : public __libcpp_is_signed<_Tp> {};
1423
1424#if _LIBCPP_STD_VER > 14
1425template <class _Tp>
1426inline constexpr bool is_signed_v = is_signed<_Tp>::value;
1427#endif
1428
1429#endif // __has_keyword(__is_signed)
1430
1431// is_unsigned
1432
1433// Before Clang 13, __is_unsigned returned true for enums with signed underlying type.
1434// No currently-released version of AppleClang contains the fixed intrinsic.
1435#if __has_keyword(__is_unsigned) && \
1436 !(defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER < 1300) && \
1437 !defined(_LIBCPP_APPLE_CLANG_VER)
1438
1439template<class _Tp>
1440struct _LIBCPP_TEMPLATE_VIS is_unsigned : _BoolConstant<__is_unsigned(_Tp)> { };
1441
1442#if _LIBCPP_STD_VER > 14
1443template <class _Tp>
1444inline constexpr bool is_unsigned_v = __is_unsigned(_Tp);
1445#endif
1446
1447#else // __has_keyword(__is_unsigned)
1448
1449template <class _Tp, bool = is_integral<_Tp>::value>
1450struct __libcpp_is_unsigned_impl : public _LIBCPP_BOOL_CONSTANT(_Tp(0) < _Tp(-1)) {};
1451
1452template <class _Tp>
1453struct __libcpp_is_unsigned_impl<_Tp, false> : public false_type {}; // floating point
1454
1455template <class _Tp, bool = is_arithmetic<_Tp>::value>
1456struct __libcpp_is_unsigned : public __libcpp_is_unsigned_impl<_Tp> {};
1457
1458template <class _Tp> struct __libcpp_is_unsigned<_Tp, false> : public false_type {};
1459
1460template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_unsigned : public __libcpp_is_unsigned<_Tp> {};
1461
1462#if _LIBCPP_STD_VER > 14
1463template <class _Tp>
1464inline constexpr bool is_unsigned_v = is_unsigned<_Tp>::value;
1465#endif
1466
1467#endif // __has_keyword(__is_unsigned)
1468
1469// rank
1470
1471template <class _Tp> struct _LIBCPP_TEMPLATE_VIS rank
1472 : public integral_constant<size_t, 0> {};
1473template <class _Tp> struct _LIBCPP_TEMPLATE_VIS rank<_Tp[]>
1474 : public integral_constant<size_t, rank<_Tp>::value + 1> {};
1475template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS rank<_Tp[_Np]>
1476 : public integral_constant<size_t, rank<_Tp>::value + 1> {};
1477
1478#if _LIBCPP_STD_VER > 14
1479template <class _Tp>
1480inline constexpr size_t rank_v = rank<_Tp>::value;
1481#endif
1482
1483// extent
1484
1485#if __has_keyword(__array_extent)
1486
1487template<class _Tp, size_t _Dim = 0>
1488struct _LIBCPP_TEMPLATE_VIS extent
1489 : integral_constant<size_t, __array_extent(_Tp, _Dim)> { };
1490
1491#if _LIBCPP_STD_VER > 14
1492template <class _Tp, unsigned _Ip = 0>
1493inline constexpr size_t extent_v = __array_extent(_Tp, _Ip);
1494#endif
1495
1496#else // __has_keyword(__array_extent)
1497
1498template <class _Tp, unsigned _Ip = 0> struct _LIBCPP_TEMPLATE_VIS extent
1499 : public integral_constant<size_t, 0> {};
1500template <class _Tp> struct _LIBCPP_TEMPLATE_VIS extent<_Tp[], 0>
1501 : public integral_constant<size_t, 0> {};
1502template <class _Tp, unsigned _Ip> struct _LIBCPP_TEMPLATE_VIS extent<_Tp[], _Ip>
1503 : public integral_constant<size_t, extent<_Tp, _Ip-1>::value> {};
1504template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS extent<_Tp[_Np], 0>
1505 : public integral_constant<size_t, _Np> {};
1506template <class _Tp, size_t _Np, unsigned _Ip> struct _LIBCPP_TEMPLATE_VIS extent<_Tp[_Np], _Ip>
1507 : public integral_constant<size_t, extent<_Tp, _Ip-1>::value> {};
1508
1509#if _LIBCPP_STD_VER > 14
1510template <class _Tp, unsigned _Ip = 0>
1511inline constexpr size_t extent_v = extent<_Tp, _Ip>::value;
1512#endif
1513
1514#endif // __has_keyword(__array_extent)
1515
1516// remove_extent
1517
1518template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_extent
1519 {typedef _Tp type;};
1520template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_extent<_Tp[]>
1521 {typedef _Tp type;};
1522template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS remove_extent<_Tp[_Np]>
1523 {typedef _Tp type;};
1524
1525#if _LIBCPP_STD_VER > 11
1526template <class _Tp> using remove_extent_t = typename remove_extent<_Tp>::type;
1527#endif
1528
1529// remove_all_extents
1530
1531template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_all_extents
1532 {typedef _Tp type;};
1533template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_all_extents<_Tp[]>
1534 {typedef typename remove_all_extents<_Tp>::type type;};
1535template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS remove_all_extents<_Tp[_Np]>
1536 {typedef typename remove_all_extents<_Tp>::type type;};
1537
1538#if _LIBCPP_STD_VER > 11
1539template <class _Tp> using remove_all_extents_t = typename remove_all_extents<_Tp>::type;
1540#endif
1541
1542#if _LIBCPP_STD_VER > 17
1543// is_bounded_array
1544
1545template <class> struct _LIBCPP_TEMPLATE_VIS is_bounded_array : false_type {};
1546template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS is_bounded_array<_Tp[_Np]> : true_type {};
1547
1548template <class _Tp>
1549inline constexpr
1550bool is_bounded_array_v = is_bounded_array<_Tp>::value;
1551
1552// is_unbounded_array
1553
1554template <class> struct _LIBCPP_TEMPLATE_VIS is_unbounded_array : false_type {};
1555template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_unbounded_array<_Tp[]> : true_type {};
1556
1557template <class _Tp>
1558inline constexpr
1559bool is_unbounded_array_v = is_unbounded_array<_Tp>::value;
1560#endif
1561
1562// decay
1563
1564template <class _Up, bool>
1565struct __decay {
1566 typedef _LIBCPP_NODEBUG typename remove_cv<_Up>::type type;
1567};
1568
1569template <class _Up>
1570struct __decay<_Up, true> {
1571public:
1572 typedef _LIBCPP_NODEBUG typename conditional
1573 <
1574 is_array<_Up>::value,
1575 typename remove_extent<_Up>::type*,
1576 typename conditional
1577 <
1578 is_function<_Up>::value,
1579 typename add_pointer<_Up>::type,
1580 typename remove_cv<_Up>::type
1581 >::type
1582 >::type type;
1583};
1584
1585template <class _Tp>
1586struct _LIBCPP_TEMPLATE_VIS decay
1587{
1588private:
1589 typedef _LIBCPP_NODEBUG typename remove_reference<_Tp>::type _Up;
1590public:
1591 typedef _LIBCPP_NODEBUG typename __decay<_Up, __is_referenceable<_Up>::value>::type type;
1592};
1593
1594#if _LIBCPP_STD_VER > 11
1595template <class _Tp> using decay_t = typename decay<_Tp>::type;
1596#endif
1597
1598// is_abstract
1599
1600template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_abstract
1601 : public integral_constant<bool, __is_abstract(_Tp)> {};
1602
1603#if _LIBCPP_STD_VER > 14
1604template <class _Tp>
1605inline constexpr bool is_abstract_v = is_abstract<_Tp>::value;
1606#endif
1607
1608// is_final
1609
1610template <class _Tp> struct _LIBCPP_TEMPLATE_VIS
1611__libcpp_is_final : public integral_constant<bool, __is_final(_Tp)> {};
1612
1613#if _LIBCPP_STD_VER > 11
1614template <class _Tp> struct _LIBCPP_TEMPLATE_VIS
1615is_final : public integral_constant<bool, __is_final(_Tp)> {};
1616#endif
1617
1618#if _LIBCPP_STD_VER > 14
1619template <class _Tp>
1620inline constexpr bool is_final_v = is_final<_Tp>::value;
1621#endif
1622
1623// is_aggregate
1624#if _LIBCPP_STD_VER > 14
1625
1626template <class _Tp> struct _LIBCPP_TEMPLATE_VIS
1627is_aggregate : public integral_constant<bool, __is_aggregate(_Tp)> {};
1628
1629template <class _Tp>
1630inline constexpr bool is_aggregate_v = is_aggregate<_Tp>::value;
1631
1632#endif // _LIBCPP_STD_VER > 14
1633
1634// is_base_of
1635
1636template <class _Bp, class _Dp>
1637struct _LIBCPP_TEMPLATE_VIS is_base_of
1638 : public integral_constant<bool, __is_base_of(_Bp, _Dp)> {};
1639
1640#if _LIBCPP_STD_VER > 14
1641template <class _Bp, class _Dp>
1642inline constexpr bool is_base_of_v = is_base_of<_Bp, _Dp>::value;
1643#endif
1644
1645// __is_core_convertible
1646
1647// [conv.general]/3 says "E is convertible to T" whenever "T t=E;" is well-formed.
1648// We can't test for that, but we can test implicit convertibility by passing it
1649// to a function. Notice that __is_core_convertible<void,void> is false,
1650// and __is_core_convertible<immovable-type,immovable-type> is true in C++17 and later.
1651
1652template <class _Tp, class _Up, class = void>
1653struct __is_core_convertible : public false_type {};
1654
1655template <class _Tp, class _Up>
1656struct __is_core_convertible<_Tp, _Up, decltype(
1657 static_cast<void(*)(_Up)>(0) ( static_cast<_Tp(*)()>(0)() )
1658)> : public true_type {};
1659
1660// is_convertible
1661
1662#if __has_feature(is_convertible_to) && !defined(_LIBCPP_USE_IS_CONVERTIBLE_FALLBACK)
1663
1664template <class _T1, class _T2> struct _LIBCPP_TEMPLATE_VIS is_convertible
1665 : public integral_constant<bool, __is_convertible_to(_T1, _T2)> {};
1666
1667#else // __has_feature(is_convertible_to)
1668
1669namespace __is_convertible_imp
1670{
1671template <class _Tp> void __test_convert(_Tp);
1672
1673template <class _From, class _To, class = void>
1674struct __is_convertible_test : public false_type {};
1675
1676template <class _From, class _To>
1677struct __is_convertible_test<_From, _To,
1678 decltype(__is_convertible_imp::__test_convert<_To>(declval<_From>()))> : public true_type
1679{};
1680
1681template <class _Tp, bool _IsArray = is_array<_Tp>::value,
1682 bool _IsFunction = is_function<_Tp>::value,
1683 bool _IsVoid = is_void<_Tp>::value>
1684 struct __is_array_function_or_void {enum {value = 0};};
1685template <class _Tp> struct __is_array_function_or_void<_Tp, true, false, false> {enum {value = 1};};
1686template <class _Tp> struct __is_array_function_or_void<_Tp, false, true, false> {enum {value = 2};};
1687template <class _Tp> struct __is_array_function_or_void<_Tp, false, false, true> {enum {value = 3};};
1688}
1689
1690template <class _Tp,
1691 unsigned = __is_convertible_imp::__is_array_function_or_void<typename remove_reference<_Tp>::type>::value>
1692struct __is_convertible_check
1693{
1694 static const size_t __v = 0;
1695};
1696
1697template <class _Tp>
1698struct __is_convertible_check<_Tp, 0>
1699{
1700 static const size_t __v = sizeof(_Tp);
1701};
1702
1703template <class _T1, class _T2,
1704 unsigned _T1_is_array_function_or_void = __is_convertible_imp::__is_array_function_or_void<_T1>::value,
1705 unsigned _T2_is_array_function_or_void = __is_convertible_imp::__is_array_function_or_void<_T2>::value>
1706struct __is_convertible
1707 : public integral_constant<bool,
1708 __is_convertible_imp::__is_convertible_test<_T1, _T2>::value
1709 >
1710{};
1711
1712template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 1> : public false_type {};
1713template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 1> : public false_type {};
1714template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 1> : public false_type {};
1715template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 1> : public false_type {};
1716
1717template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 2> : public false_type {};
1718template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 2> : public false_type {};
1719template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 2> : public false_type {};
1720template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 2> : public false_type {};
1721
1722template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 3> : public false_type {};
1723template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 3> : public false_type {};
1724template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 3> : public false_type {};
1725template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 3> : public true_type {};
1726
1727template <class _T1, class _T2> struct _LIBCPP_TEMPLATE_VIS is_convertible
1728 : public __is_convertible<_T1, _T2>
1729{
1730 static const size_t __complete_check1 = __is_convertible_check<_T1>::__v;
1731 static const size_t __complete_check2 = __is_convertible_check<_T2>::__v;
1732};
1733
1734#endif // __has_feature(is_convertible_to)
1735
1736#if _LIBCPP_STD_VER > 14
1737template <class _From, class _To>
1738inline constexpr bool is_convertible_v = is_convertible<_From, _To>::value;
1739#endif
1740
1741// is_nothrow_convertible
1742
1743#if _LIBCPP_STD_VER > 17
1744
1745template <typename _Tp>
1746static void __test_noexcept(_Tp) noexcept;
1747
1748template<typename _Fm, typename _To>
1749static bool_constant<noexcept(_VSTD::__test_noexcept<_To>(declval<_Fm>()))>
1750__is_nothrow_convertible_test();
1751
1752template <typename _Fm, typename _To>
1753struct __is_nothrow_convertible_helper: decltype(__is_nothrow_convertible_test<_Fm, _To>())
1754{ };
1755
1756template <typename _Fm, typename _To>
1757struct is_nothrow_convertible : _Or<
1758 _And<is_void<_To>, is_void<_Fm>>,
1759 _Lazy<_And, is_convertible<_Fm, _To>, __is_nothrow_convertible_helper<_Fm, _To>>
1760>::type { };
1761
1762template <typename _Fm, typename _To>
1763inline constexpr bool is_nothrow_convertible_v = is_nothrow_convertible<_Fm, _To>::value;
1764
1765#endif // _LIBCPP_STD_VER > 17
1766
1767// is_empty
1768
1769#if __has_feature(is_empty) || defined(_LIBCPP_COMPILER_GCC)
1770
1771template <class _Tp>
1772struct _LIBCPP_TEMPLATE_VIS is_empty
1773 : public integral_constant<bool, __is_empty(_Tp)> {};
1774
1775#else // __has_feature(is_empty)
1776
1777template <class _Tp>
1778struct __is_empty1
1779 : public _Tp
1780{
1781 double __lx;
1782};
1783
1784struct __is_empty2
1785{
1786 double __lx;
1787};
1788
1789template <class _Tp, bool = is_class<_Tp>::value>
1790struct __libcpp_empty : public integral_constant<bool, sizeof(__is_empty1<_Tp>) == sizeof(__is_empty2)> {};
1791
1792template <class _Tp> struct __libcpp_empty<_Tp, false> : public false_type {};
1793
1794template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_empty : public __libcpp_empty<_Tp> {};
1795
1796#endif // __has_feature(is_empty)
1797
1798#if _LIBCPP_STD_VER > 14
1799template <class _Tp>
1800inline constexpr bool is_empty_v = is_empty<_Tp>::value;
1801#endif
1802
1803// is_polymorphic
1804
1805#if __has_feature(is_polymorphic) || defined(_LIBCPP_COMPILER_MSVC)
1806
1807template <class _Tp>
1808struct _LIBCPP_TEMPLATE_VIS is_polymorphic
1809 : public integral_constant<bool, __is_polymorphic(_Tp)> {};
1810
1811#else
1812
1813template<typename _Tp> char &__is_polymorphic_impl(
1814 typename enable_if<sizeof((_Tp*)dynamic_cast<const volatile void*>(declval<_Tp*>())) != 0,
1815 int>::type);
1816template<typename _Tp> __two &__is_polymorphic_impl(...);
1817
1818template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_polymorphic
1819 : public integral_constant<bool, sizeof(__is_polymorphic_impl<_Tp>(0)) == 1> {};
1820
1821#endif // __has_feature(is_polymorphic)
1822
1823#if _LIBCPP_STD_VER > 14
1824template <class _Tp>
1825inline constexpr bool is_polymorphic_v = is_polymorphic<_Tp>::value;
1826#endif
1827
1828// has_virtual_destructor
1829
1830#if __has_feature(has_virtual_destructor) || defined(_LIBCPP_COMPILER_GCC)
1831
1832template <class _Tp> struct _LIBCPP_TEMPLATE_VIS has_virtual_destructor
1833 : public integral_constant<bool, __has_virtual_destructor(_Tp)> {};
1834
1835#else
1836
1837template <class _Tp> struct _LIBCPP_TEMPLATE_VIS has_virtual_destructor
1838 : public false_type {};
1839
1840#endif
1841
1842#if _LIBCPP_STD_VER > 14
1843template <class _Tp>
1844inline constexpr bool has_virtual_destructor_v = has_virtual_destructor<_Tp>::value;
1845#endif
1846
1847// has_unique_object_representations
1848
1849#if _LIBCPP_STD_VER > 14
1850
1851template <class _Tp> struct _LIBCPP_TEMPLATE_VIS has_unique_object_representations
1852 : public integral_constant<bool,
1853 __has_unique_object_representations(remove_cv_t<remove_all_extents_t<_Tp>>)> {};
1854
1855template <class _Tp>
1856inline constexpr bool has_unique_object_representations_v = has_unique_object_representations<_Tp>::value;
1857
1858#endif
1859
1860// alignment_of
1861
1862template <class _Tp> struct _LIBCPP_TEMPLATE_VIS alignment_of
1863 : public integral_constant<size_t, _LIBCPP_ALIGNOF(_Tp)> {};
1864
1865#if _LIBCPP_STD_VER > 14
1866template <class _Tp>
1867inline constexpr size_t alignment_of_v = alignment_of<_Tp>::value;
1868#endif
1869
1870// aligned_storage
1871
1872template <class _Hp, class _Tp>
1873struct __type_list
1874{
1875 typedef _Hp _Head;
1876 typedef _Tp _Tail;
1877};
1878
1879struct __nat
1880{
1881#ifndef _LIBCPP_CXX03_LANG
1882 __nat() = delete;
1883 __nat(const __nat&) = delete;
1884 __nat& operator=(const __nat&) = delete;
1885 ~__nat() = delete;
1886#endif
1887};
1888
1889template <class _Tp>
1890struct __align_type
1891{
1892 static const size_t value = _LIBCPP_PREFERRED_ALIGNOF(_Tp);
1893 typedef _Tp type;
1894};
1895
1896struct __struct_double {long double __lx;};
1897struct __struct_double4 {double __lx[4];};
1898
1899typedef
1900 __type_list<__align_type<unsigned char>,
1901 __type_list<__align_type<unsigned short>,
1902 __type_list<__align_type<unsigned int>,
1903 __type_list<__align_type<unsigned long>,
1904 __type_list<__align_type<unsigned long long>,
1905 __type_list<__align_type<double>,
1906 __type_list<__align_type<long double>,
1907 __type_list<__align_type<__struct_double>,
1908 __type_list<__align_type<__struct_double4>,
1909 __type_list<__align_type<int*>,
1910 __nat
1911 > > > > > > > > > > __all_types;
1912
1913template <size_t _Align>
1914struct _ALIGNAS(_Align) __fallback_overaligned {};
1915
1916template <class _TL, size_t _Align> struct __find_pod;
1917
1918template <class _Hp, size_t _Align>
1919struct __find_pod<__type_list<_Hp, __nat>, _Align>
1920{
1921 typedef typename conditional<
1922 _Align == _Hp::value,
1923 typename _Hp::type,
1924 __fallback_overaligned<_Align>
1925 >::type type;
1926};
1927
1928template <class _Hp, class _Tp, size_t _Align>
1929struct __find_pod<__type_list<_Hp, _Tp>, _Align>
1930{
1931 typedef typename conditional<
1932 _Align == _Hp::value,
1933 typename _Hp::type,
1934 typename __find_pod<_Tp, _Align>::type
1935 >::type type;
1936};
1937
1938template <class _TL, size_t _Len> struct __find_max_align;
1939
1940template <class _Hp, size_t _Len>
1941struct __find_max_align<__type_list<_Hp, __nat>, _Len> : public integral_constant<size_t, _Hp::value> {};
1942
1943template <size_t _Len, size_t _A1, size_t _A2>
1944struct __select_align
1945{
1946private:
1947 static const size_t __min = _A2 < _A1 ? _A2 : _A1;
1948 static const size_t __max = _A1 < _A2 ? _A2 : _A1;
1949public:
1950 static const size_t value = _Len < __max ? __min : __max;
1951};
1952
1953template <class _Hp, class _Tp, size_t _Len>
1954struct __find_max_align<__type_list<_Hp, _Tp>, _Len>
1955 : public integral_constant<size_t, __select_align<_Len, _Hp::value, __find_max_align<_Tp, _Len>::value>::value> {};
1956
1957template <size_t _Len, size_t _Align = __find_max_align<__all_types, _Len>::value>
1958struct _LIBCPP_TEMPLATE_VIS aligned_storage
1959{
1960 typedef typename __find_pod<__all_types, _Align>::type _Aligner;
1961 union type
1962 {
1963 _Aligner __align;
1964 unsigned char __data[(_Len + _Align - 1)/_Align * _Align];
1965 };
1966};
1967
1968#if _LIBCPP_STD_VER > 11
1969template <size_t _Len, size_t _Align = __find_max_align<__all_types, _Len>::value>
1970 using aligned_storage_t = typename aligned_storage<_Len, _Align>::type;
1971#endif
1972
1973#define _CREATE_ALIGNED_STORAGE_SPECIALIZATION(n) \
1974template <size_t _Len>\
1975struct _LIBCPP_TEMPLATE_VIS aligned_storage<_Len, n>\
1976{\
1977 struct _ALIGNAS(n) type\
1978 {\
1979 unsigned char __lx[(_Len + n - 1)/n * n];\
1980 };\
1981}
1982
1983_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x1);
1984_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x2);
1985_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4);
1986_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x8);
1987_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x10);
1988_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x20);
1989_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x40);
1990_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x80);
1991_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x100);
1992_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x200);
1993_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x400);
1994_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x800);
1995_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x1000);
1996_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x2000);
1997// PE/COFF does not support alignment beyond 8192 (=0x2000)
1998#if !defined(_LIBCPP_OBJECT_FORMAT_COFF)
1999_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4000);
2000#endif // !defined(_LIBCPP_OBJECT_FORMAT_COFF)
2001
2002#undef _CREATE_ALIGNED_STORAGE_SPECIALIZATION
2003
2004
2005// aligned_union
2006
2007template <size_t _I0, size_t ..._In>
2008struct __static_max;
2009
2010template <size_t _I0>
2011struct __static_max<_I0>
2012{
2013 static const size_t value = _I0;
2014};
2015
2016template <size_t _I0, size_t _I1, size_t ..._In>
2017struct __static_max<_I0, _I1, _In...>
2018{
2019 static const size_t value = _I0 >= _I1 ? __static_max<_I0, _In...>::value :
2020 __static_max<_I1, _In...>::value;
2021};
2022
2023template <size_t _Len, class _Type0, class ..._Types>
2024struct aligned_union
2025{
2026 static const size_t alignment_value = __static_max<_LIBCPP_PREFERRED_ALIGNOF(_Type0),
2027 _LIBCPP_PREFERRED_ALIGNOF(_Types)...>::value;
2028 static const size_t __len = __static_max<_Len, sizeof(_Type0),
2029 sizeof(_Types)...>::value;
2030 typedef typename aligned_storage<__len, alignment_value>::type type;
2031};
2032
2033#if _LIBCPP_STD_VER > 11
2034template <size_t _Len, class ..._Types> using aligned_union_t = typename aligned_union<_Len, _Types...>::type;
2035#endif
2036
2037template <class _Tp>
2038struct __numeric_type
2039{
2040 static void __test(...);
2041 static float __test(float);
2042 static double __test(char);
2043 static double __test(int);
2044 static double __test(unsigned);
2045 static double __test(long);
2046 static double __test(unsigned long);
2047 static double __test(long long);
2048 static double __test(unsigned long long);
2049 static double __test(double);
2050 static long double __test(long double);
2051
2052 typedef decltype(__test(declval<_Tp>())) type;
2053 static const bool value = _IsNotSame<type, void>::value;
2054};
2055
2056template <>
2057struct __numeric_type<void>
2058{
2059 static const bool value = true;
2060};
2061
2062// __promote
2063
2064template <class _A1, class _A2 = void, class _A3 = void,
2065 bool = __numeric_type<_A1>::value &&
2066 __numeric_type<_A2>::value &&
2067 __numeric_type<_A3>::value>
2068class __promote_imp
2069{
2070public:
2071 static const bool value = false;
2072};
2073
2074template <class _A1, class _A2, class _A3>
2075class __promote_imp<_A1, _A2, _A3, true>
2076{
2077private:
2078 typedef typename __promote_imp<_A1>::type __type1;
2079 typedef typename __promote_imp<_A2>::type __type2;
2080 typedef typename __promote_imp<_A3>::type __type3;
2081public:
2082 typedef decltype(__type1() + __type2() + __type3()) type;
2083 static const bool value = true;
2084};
2085
2086template <class _A1, class _A2>
2087class __promote_imp<_A1, _A2, void, true>
2088{
2089private:
2090 typedef typename __promote_imp<_A1>::type __type1;
2091 typedef typename __promote_imp<_A2>::type __type2;
2092public:
2093 typedef decltype(__type1() + __type2()) type;
2094 static const bool value = true;
2095};
2096
2097template <class _A1>
2098class __promote_imp<_A1, void, void, true>
2099{
2100public:
2101 typedef typename __numeric_type<_A1>::type type;
2102 static const bool value = true;
2103};
2104
2105template <class _A1, class _A2 = void, class _A3 = void>
2106class __promote : public __promote_imp<_A1, _A2, _A3> {};
2107
2108// make_signed / make_unsigned
2109
2110typedef
2111 __type_list<signed char,
2112 __type_list<signed short,
2113 __type_list<signed int,
2114 __type_list<signed long,
2115 __type_list<signed long long,
2116#ifndef _LIBCPP_HAS_NO_INT128
2117 __type_list<__int128_t,
2118#endif
2119 __nat
2120#ifndef _LIBCPP_HAS_NO_INT128
2121 >
2122#endif
2123 > > > > > __signed_types;
2124
2125typedef
2126 __type_list<unsigned char,
2127 __type_list<unsigned short,
2128 __type_list<unsigned int,
2129 __type_list<unsigned long,
2130 __type_list<unsigned long long,
2131#ifndef _LIBCPP_HAS_NO_INT128
2132 __type_list<__uint128_t,
2133#endif
2134 __nat
2135#ifndef _LIBCPP_HAS_NO_INT128
2136 >
2137#endif
2138 > > > > > __unsigned_types;
2139
2140template <class _TypeList, size_t _Size, bool = _Size <= sizeof(typename _TypeList::_Head)> struct __find_first;
2141
2142template <class _Hp, class _Tp, size_t _Size>
2143struct __find_first<__type_list<_Hp, _Tp>, _Size, true>
2144{
2145 typedef _LIBCPP_NODEBUG _Hp type;
2146};
2147
2148template <class _Hp, class _Tp, size_t _Size>
2149struct __find_first<__type_list<_Hp, _Tp>, _Size, false>
2150{
2151 typedef _LIBCPP_NODEBUG typename __find_first<_Tp, _Size>::type type;
2152};
2153
2154template <class _Tp, class _Up, bool = is_const<typename remove_reference<_Tp>::type>::value,
2155 bool = is_volatile<typename remove_reference<_Tp>::type>::value>
2156struct __apply_cv
2157{
2158 typedef _LIBCPP_NODEBUG _Up type;
2159};
2160
2161template <class _Tp, class _Up>
2162struct __apply_cv<_Tp, _Up, true, false>
2163{
2164 typedef _LIBCPP_NODEBUG const _Up type;
2165};
2166
2167template <class _Tp, class _Up>
2168struct __apply_cv<_Tp, _Up, false, true>
2169{
2170 typedef volatile _Up type;
2171};
2172
2173template <class _Tp, class _Up>
2174struct __apply_cv<_Tp, _Up, true, true>
2175{
2176 typedef const volatile _Up type;
2177};
2178
2179template <class _Tp, class _Up>
2180struct __apply_cv<_Tp&, _Up, false, false>
2181{
2182 typedef _Up& type;
2183};
2184
2185template <class _Tp, class _Up>
2186struct __apply_cv<_Tp&, _Up, true, false>
2187{
2188 typedef const _Up& type;
2189};
2190
2191template <class _Tp, class _Up>
2192struct __apply_cv<_Tp&, _Up, false, true>
2193{
2194 typedef volatile _Up& type;
2195};
2196
2197template <class _Tp, class _Up>
2198struct __apply_cv<_Tp&, _Up, true, true>
2199{
2200 typedef const volatile _Up& type;
2201};
2202
2203template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value>
2204struct __make_signed {};
2205
2206template <class _Tp>
2207struct __make_signed<_Tp, true>
2208{
2209 typedef typename __find_first<__signed_types, sizeof(_Tp)>::type type;
2210};
2211
2212template <> struct __make_signed<bool, true> {};
2213template <> struct __make_signed< signed short, true> {typedef short type;};
2214template <> struct __make_signed<unsigned short, true> {typedef short type;};
2215template <> struct __make_signed< signed int, true> {typedef int type;};
2216template <> struct __make_signed<unsigned int, true> {typedef int type;};
2217template <> struct __make_signed< signed long, true> {typedef long type;};
2218template <> struct __make_signed<unsigned long, true> {typedef long type;};
2219template <> struct __make_signed< signed long long, true> {typedef long long type;};
2220template <> struct __make_signed<unsigned long long, true> {typedef long long type;};
2221#ifndef _LIBCPP_HAS_NO_INT128
2222template <> struct __make_signed<__int128_t, true> {typedef __int128_t type;};
2223template <> struct __make_signed<__uint128_t, true> {typedef __int128_t type;};
2224#endif
2225
2226template <class _Tp>
2227struct _LIBCPP_TEMPLATE_VIS make_signed
2228{
2229 typedef typename __apply_cv<_Tp, typename __make_signed<typename remove_cv<_Tp>::type>::type>::type type;
2230};
2231
2232#if _LIBCPP_STD_VER > 11
2233template <class _Tp> using make_signed_t = typename make_signed<_Tp>::type;
2234#endif
2235
2236template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value>
2237struct __make_unsigned {};
2238
2239template <class _Tp>
2240struct __make_unsigned<_Tp, true>
2241{
2242 typedef typename __find_first<__unsigned_types, sizeof(_Tp)>::type type;
2243};
2244
2245template <> struct __make_unsigned<bool, true> {};
2246template <> struct __make_unsigned< signed short, true> {typedef unsigned short type;};
2247template <> struct __make_unsigned<unsigned short, true> {typedef unsigned short type;};
2248template <> struct __make_unsigned< signed int, true> {typedef unsigned int type;};
2249template <> struct __make_unsigned<unsigned int, true> {typedef unsigned int type;};
2250template <> struct __make_unsigned< signed long, true> {typedef unsigned long type;};
2251template <> struct __make_unsigned<unsigned long, true> {typedef unsigned long type;};
2252template <> struct __make_unsigned< signed long long, true> {typedef unsigned long long type;};
2253template <> struct __make_unsigned<unsigned long long, true> {typedef unsigned long long type;};
2254#ifndef _LIBCPP_HAS_NO_INT128
2255template <> struct __make_unsigned<__int128_t, true> {typedef __uint128_t type;};
2256template <> struct __make_unsigned<__uint128_t, true> {typedef __uint128_t type;};
2257#endif
2258
2259template <class _Tp>
2260struct _LIBCPP_TEMPLATE_VIS make_unsigned
2261{
2262 typedef typename __apply_cv<_Tp, typename __make_unsigned<typename remove_cv<_Tp>::type>::type>::type type;
2263};
2264
2265#if _LIBCPP_STD_VER > 11
2266template <class _Tp> using make_unsigned_t = typename make_unsigned<_Tp>::type;
2267#endif
2268
2269#ifndef _LIBCPP_CXX03_LANG
2270template <class _Tp>
2271_LIBCPP_HIDE_FROM_ABI constexpr
2272typename make_unsigned<_Tp>::type __to_unsigned_like(_Tp __x) noexcept {
2273 return static_cast<typename make_unsigned<_Tp>::type>(__x);
2274}
2275#endif
2276
2277#if _LIBCPP_STD_VER > 14
2278template <class...> using void_t = void;
2279#endif
2280
2281#if _LIBCPP_STD_VER > 17
2282// Let COND_RES(X, Y) be:
2283template <class _Tp, class _Up>
2284using __cond_type = decltype(false ? declval<_Tp>() : declval<_Up>());
2285
2286template <class _Tp, class _Up, class = void>
2287struct __common_type3 {};
2288
2289// sub-bullet 4 - "if COND_RES(CREF(D1), CREF(D2)) denotes a type..."
2290template <class _Tp, class _Up>
2291struct __common_type3<_Tp, _Up, void_t<__cond_type<const _Tp&, const _Up&>>>
2292{
2293 using type = remove_cvref_t<__cond_type<const _Tp&, const _Up&>>;
2294};
2295
2296template <class _Tp, class _Up, class = void>
2297struct __common_type2_imp : __common_type3<_Tp, _Up> {};
2298#else
2299template <class _Tp, class _Up, class = void>
2300struct __common_type2_imp {};
2301#endif
2302
2303// sub-bullet 3 - "if decay_t<decltype(false ? declval<D1>() : declval<D2>())> ..."
2304template <class _Tp, class _Up>
2305struct __common_type2_imp<_Tp, _Up,
2306 typename __void_t<decltype(
2307 true ? declval<_Tp>() : declval<_Up>()
2308 )>::type>
2309{
2310 typedef _LIBCPP_NODEBUG typename decay<decltype(
2311 true ? declval<_Tp>() : declval<_Up>()
2312 )>::type type;
2313};
2314
2315template <class, class = void>
2316struct __common_type_impl {};
2317
2318// Clang provides variadic templates in C++03 as an extension.
2319#if !defined(_LIBCPP_CXX03_LANG) || defined(__clang__)
2320# define _LIBCPP_OPTIONAL_PACK(...) , __VA_ARGS__
2321template <class... _Tp>
2322struct __common_types;
2323template <class... _Tp>
2324struct _LIBCPP_TEMPLATE_VIS common_type;
2325#else
2326# define _LIBCPP_OPTIONAL_PACK(...)
2327struct __no_arg;
2328template <class _Tp, class _Up, class = __no_arg>
2329struct __common_types;
2330template <class _Tp = __no_arg, class _Up = __no_arg, class _Vp = __no_arg,
2331 class _Unused = __no_arg>
2332struct common_type {
2333 static_assert(sizeof(_Unused) == 0,
2334 "common_type accepts at most 3 arguments in C++03");
2335};
2336#endif // _LIBCPP_CXX03_LANG
2337
2338template <class _Tp, class _Up>
2339struct __common_type_impl<
2340 __common_types<_Tp, _Up>,
2341 typename __void_t<typename common_type<_Tp, _Up>::type>::type>
2342{
2343 typedef typename common_type<_Tp, _Up>::type type;
2344};
2345
2346template <class _Tp, class _Up, class _Vp _LIBCPP_OPTIONAL_PACK(class... _Rest)>
2347struct __common_type_impl<
2348 __common_types<_Tp, _Up, _Vp _LIBCPP_OPTIONAL_PACK(_Rest...)>,
2349 typename __void_t<typename common_type<_Tp, _Up>::type>::type>
2350 : __common_type_impl<__common_types<typename common_type<_Tp, _Up>::type,
2351 _Vp _LIBCPP_OPTIONAL_PACK(_Rest...)> > {
2352};
2353
2354// bullet 1 - sizeof...(Tp) == 0
2355
2356template <>
2357struct _LIBCPP_TEMPLATE_VIS common_type<> {};
2358
2359// bullet 2 - sizeof...(Tp) == 1
2360
2361template <class _Tp>
2362struct _LIBCPP_TEMPLATE_VIS common_type<_Tp>
2363 : public common_type<_Tp, _Tp> {};
2364
2365// bullet 3 - sizeof...(Tp) == 2
2366
2367// sub-bullet 1 - "If is_same_v<T1, D1> is false or ..."
2368template <class _Tp, class _Up>
2369struct _LIBCPP_TEMPLATE_VIS common_type<_Tp, _Up>
2370 : conditional<
2371 _IsSame<_Tp, typename decay<_Tp>::type>::value && _IsSame<_Up, typename decay<_Up>::type>::value,
2372 __common_type2_imp<_Tp, _Up>,
2373 common_type<typename decay<_Tp>::type, typename decay<_Up>::type>
2374 >::type
2375{};
2376
2377// bullet 4 - sizeof...(Tp) > 2
2378
2379template <class _Tp, class _Up, class _Vp _LIBCPP_OPTIONAL_PACK(class... _Rest)>
2380struct _LIBCPP_TEMPLATE_VIS
2381 common_type<_Tp, _Up, _Vp _LIBCPP_OPTIONAL_PACK(_Rest...)>
2382 : __common_type_impl<
2383 __common_types<_Tp, _Up, _Vp _LIBCPP_OPTIONAL_PACK(_Rest...)> > {};
2384
2385#undef _LIBCPP_OPTIONAL_PACK
2386
2387#if _LIBCPP_STD_VER > 11
2388template <class ..._Tp> using common_type_t = typename common_type<_Tp...>::type;
2389#endif
2390
2391#if _LIBCPP_STD_VER > 11
2392// Let COPYCV(FROM, TO) be an alias for type TO with the addition of FROM's
2393// top-level cv-qualifiers.
2394template <class _From, class _To>
2395struct __copy_cv
2396{
2397 using type = _To;
2398};
2399
2400template <class _From, class _To>
2401struct __copy_cv<const _From, _To>
2402{
2403 using type = add_const_t<_To>;
2404};
2405
2406template <class _From, class _To>
2407struct __copy_cv<volatile _From, _To>
2408{
2409 using type = add_volatile_t<_To>;
2410};
2411
2412template <class _From, class _To>
2413struct __copy_cv<const volatile _From, _To>
2414{
2415 using type = add_cv_t<_To>;
2416};
2417
2418template <class _From, class _To>
2419using __copy_cv_t = typename __copy_cv<_From, _To>::type;
2420
2421template <class _From, class _To>
2422struct __copy_cvref
2423{
2424 using type = __copy_cv_t<_From, _To>;
2425};
2426
2427template <class _From, class _To>
2428struct __copy_cvref<_From&, _To>
2429{
2430 using type = add_lvalue_reference_t<__copy_cv_t<_From, _To>>;
2431};
2432
2433template <class _From, class _To>
2434struct __copy_cvref<_From&&, _To>
2435{
2436 using type = add_rvalue_reference_t<__copy_cv_t<_From, _To>>;
2437};
2438
2439template <class _From, class _To>
2440using __copy_cvref_t = typename __copy_cvref<_From, _To>::type;
2441
2442#endif // _LIBCPP_STD_VER > 11
2443
2444// common_reference
2445#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
2446// Let COND_RES(X, Y) be:
2447template <class _Xp, class _Yp>
2448using __cond_res =
2449 decltype(false ? declval<_Xp(&)()>()() : declval<_Yp(&)()>()());
2450
2451// Let `XREF(A)` denote a unary alias template `T` such that `T<U>` denotes the same type as `U`
2452// with the addition of `A`'s cv and reference qualifiers, for a non-reference cv-unqualified type
2453// `U`.
2454// [Note: `XREF(A)` is `__xref<A>::template __apply`]
2455template <class _Tp>
2456struct __xref {
2457 template<class _Up>
2458 using __apply = __copy_cvref_t<_Tp, _Up>;
2459};
2460
2461// Given types A and B, let X be remove_reference_t<A>, let Y be remove_reference_t<B>,
2462// and let COMMON-REF(A, B) be:
2463template<class _Ap, class _Bp, class _Xp = remove_reference_t<_Ap>, class _Yp = remove_reference_t<_Bp>>
2464struct __common_ref;
2465
2466template<class _Xp, class _Yp>
2467using __common_ref_t = typename __common_ref<_Xp, _Yp>::__type;
2468
2469template<class _Xp, class _Yp>
2470using __cv_cond_res = __cond_res<__copy_cv_t<_Xp, _Yp>&, __copy_cv_t<_Yp, _Xp>&>;
2471
2472
2473// If A and B are both lvalue reference types, COMMON-REF(A, B) is
2474// COND-RES(COPYCV(X, Y)&, COPYCV(Y, X)&) if that type exists and is a reference type.
2475template<class _Ap, class _Bp, class _Xp, class _Yp>
2476requires requires { typename __cv_cond_res<_Xp, _Yp>; } && is_reference_v<__cv_cond_res<_Xp, _Yp>>
2477struct __common_ref<_Ap&, _Bp&, _Xp, _Yp>
2478{
2479 using __type = __cv_cond_res<_Xp, _Yp>;
2480};
2481
2482// Otherwise, let C be remove_reference_t<COMMON-REF(X&, Y&)>&&. ...
2483template <class _Xp, class _Yp>
2484using __common_ref_C = remove_reference_t<__common_ref_t<_Xp&, _Yp&>>&&;
2485
2486
2487// .... If A and B are both rvalue reference types, C is well-formed, and
2488// is_convertible_v<A, C> && is_convertible_v<B, C> is true, then COMMON-REF(A, B) is C.
2489template<class _Ap, class _Bp, class _Xp, class _Yp>
2490requires
2491 requires { typename __common_ref_C<_Xp, _Yp>; } &&
2492 is_convertible_v<_Ap&&, __common_ref_C<_Xp, _Yp>> &&
2493 is_convertible_v<_Bp&&, __common_ref_C<_Xp, _Yp>>
2494struct __common_ref<_Ap&&, _Bp&&, _Xp, _Yp>
2495{
2496 using __type = __common_ref_C<_Xp, _Yp>;
2497};
2498
2499// Otherwise, let D be COMMON-REF(const X&, Y&). ...
2500template <class _Tp, class _Up>
2501using __common_ref_D = __common_ref_t<const _Tp&, _Up&>;
2502
2503// ... If A is an rvalue reference and B is an lvalue reference and D is well-formed and
2504// is_convertible_v<A, D> is true, then COMMON-REF(A, B) is D.
2505template<class _Ap, class _Bp, class _Xp, class _Yp>
2506requires requires { typename __common_ref_D<_Xp, _Yp>; } &&
2507 is_convertible_v<_Ap&&, __common_ref_D<_Xp, _Yp>>
2508struct __common_ref<_Ap&&, _Bp&, _Xp, _Yp>
2509{
2510 using __type = __common_ref_D<_Xp, _Yp>;
2511};
2512
2513// Otherwise, if A is an lvalue reference and B is an rvalue reference, then
2514// COMMON-REF(A, B) is COMMON-REF(B, A).
2515template<class _Ap, class _Bp, class _Xp, class _Yp>
2516struct __common_ref<_Ap&, _Bp&&, _Xp, _Yp> : __common_ref<_Bp&&, _Ap&> {};
2517
2518// Otherwise, COMMON-REF(A, B) is ill-formed.
2519template<class _Ap, class _Bp, class _Xp, class _Yp>
2520struct __common_ref {};
2521
2522// Note C: For the common_reference trait applied to a parameter pack [...]
2523
2524template <class...>
2525struct common_reference;
2526
2527template <class... _Types>
2528using common_reference_t = typename common_reference<_Types...>::type;
2529
2530// bullet 1 - sizeof...(T) == 0
2531template<>
2532struct common_reference<> {};
2533
2534// bullet 2 - sizeof...(T) == 1
2535template <class _Tp>
2536struct common_reference<_Tp>
2537{
2538 using type = _Tp;
2539};
2540
2541// bullet 3 - sizeof...(T) == 2
2542template <class _Tp, class _Up> struct __common_reference_sub_bullet3;
2543template <class _Tp, class _Up> struct __common_reference_sub_bullet2 : __common_reference_sub_bullet3<_Tp, _Up> {};
2544template <class _Tp, class _Up> struct __common_reference_sub_bullet1 : __common_reference_sub_bullet2<_Tp, _Up> {};
2545
2546// sub-bullet 1 - If T1 and T2 are reference types and COMMON-REF(T1, T2) is well-formed, then
2547// the member typedef `type` denotes that type.
2548template <class _Tp, class _Up> struct common_reference<_Tp, _Up> : __common_reference_sub_bullet1<_Tp, _Up> {};
2549
2550template <class _Tp, class _Up>
2551requires is_reference_v<_Tp> && is_reference_v<_Up> && requires { typename __common_ref_t<_Tp, _Up>; }
2552struct __common_reference_sub_bullet1<_Tp, _Up>
2553{
2554 using type = __common_ref_t<_Tp, _Up>;
2555};
2556
2557// sub-bullet 2 - Otherwise, if basic_common_reference<remove_cvref_t<T1>, remove_cvref_t<T2>, XREF(T1), XREF(T2)>::type
2558// is well-formed, then the member typedef `type` denotes that type.
2559template <class, class, template <class> class, template <class> class> struct basic_common_reference {};
2560
2561template <class _Tp, class _Up>
2562using __basic_common_reference_t = typename basic_common_reference<
2563 remove_cvref_t<_Tp>, remove_cvref_t<_Up>,
2564 __xref<_Tp>::template __apply, __xref<_Up>::template __apply>::type;
2565
2566template <class _Tp, class _Up>
2567requires requires { typename __basic_common_reference_t<_Tp, _Up>; }
2568struct __common_reference_sub_bullet2<_Tp, _Up>
2569{
2570 using type = __basic_common_reference_t<_Tp, _Up>;
2571};
2572
2573// sub-bullet 3 - Otherwise, if COND-RES(T1, T2) is well-formed,
2574// then the member typedef `type` denotes that type.
2575template <class _Tp, class _Up>
2576requires requires { typename __cond_res<_Tp, _Up>; }
2577struct __common_reference_sub_bullet3<_Tp, _Up>
2578{
2579 using type = __cond_res<_Tp, _Up>;
2580};
2581
2582
2583// sub-bullet 4 & 5 - Otherwise, if common_type_t<T1, T2> is well-formed,
2584// then the member typedef `type` denotes that type.
2585// - Otherwise, there shall be no member `type`.
2586template <class _Tp, class _Up> struct __common_reference_sub_bullet3 : common_type<_Tp, _Up> {};
2587
2588// bullet 4 - If there is such a type `C`, the member typedef type shall denote the same type, if
2589// any, as `common_reference_t<C, Rest...>`.
2590template <class _Tp, class _Up, class _Vp, class... _Rest>
2591requires requires { typename common_reference_t<_Tp, _Up>; }
2592struct common_reference<_Tp, _Up, _Vp, _Rest...>
2593 : common_reference<common_reference_t<_Tp, _Up>, _Vp, _Rest...>
2594{};
2595
2596// bullet 5 - Otherwise, there shall be no member `type`.
2597template <class...> struct common_reference {};
2598
2599#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
2600
2601// is_assignable
2602
2603template<typename, typename _Tp> struct __select_2nd { typedef _LIBCPP_NODEBUG _Tp type; };
2604
2605#if __has_keyword(__is_assignable)
2606
2607template<class _Tp, class _Up>
2608struct _LIBCPP_TEMPLATE_VIS is_assignable : _BoolConstant<__is_assignable(_Tp, _Up)> { };
2609
2610#if _LIBCPP_STD_VER > 14
2611template <class _Tp, class _Arg>
2612inline constexpr bool is_assignable_v = __is_assignable(_Tp, _Arg);
2613#endif
2614
2615#else // __has_keyword(__is_assignable)
2616
2617template <class _Tp, class _Arg>
2618typename __select_2nd<decltype((declval<_Tp>() = declval<_Arg>())), true_type>::type
2619__is_assignable_test(int);
2620
2621template <class, class>
2622false_type __is_assignable_test(...);
2623
2624
2625template <class _Tp, class _Arg, bool = is_void<_Tp>::value || is_void<_Arg>::value>
2626struct __is_assignable_imp
2627 : public decltype((_VSTD::__is_assignable_test<_Tp, _Arg>(0))) {};
2628
2629template <class _Tp, class _Arg>
2630struct __is_assignable_imp<_Tp, _Arg, true>
2631 : public false_type
2632{
2633};
2634
2635template <class _Tp, class _Arg>
2636struct is_assignable
2637 : public __is_assignable_imp<_Tp, _Arg> {};
2638
2639#if _LIBCPP_STD_VER > 14
2640template <class _Tp, class _Arg>
2641inline constexpr bool is_assignable_v = is_assignable<_Tp, _Arg>::value;
2642#endif
2643
2644#endif // __has_keyword(__is_assignable)
2645
2646// is_copy_assignable
2647
2648template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_copy_assignable
2649 : public is_assignable<typename add_lvalue_reference<_Tp>::type,
2650 typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
2651
2652#if _LIBCPP_STD_VER > 14
2653template <class _Tp>
2654inline constexpr bool is_copy_assignable_v = is_copy_assignable<_Tp>::value;
2655#endif
2656
2657// is_move_assignable
2658
2659template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_move_assignable
2660 : public is_assignable<typename add_lvalue_reference<_Tp>::type,
2661 typename add_rvalue_reference<_Tp>::type> {};
2662
2663#if _LIBCPP_STD_VER > 14
2664template <class _Tp>
2665inline constexpr bool is_move_assignable_v = is_move_assignable<_Tp>::value;
2666#endif
2667
2668// is_destructible
2669
2670#if __has_keyword(__is_destructible)
2671
2672template<class _Tp>
2673struct _LIBCPP_TEMPLATE_VIS is_destructible : _BoolConstant<__is_destructible(_Tp)> { };
2674
2675#if _LIBCPP_STD_VER > 14
2676template <class _Tp>
2677inline constexpr bool is_destructible_v = __is_destructible(_Tp);
2678#endif
2679
2680#else // __has_keyword(__is_destructible)
2681
2682// if it's a reference, return true
2683// if it's a function, return false
2684// if it's void, return false
2685// if it's an array of unknown bound, return false
2686// Otherwise, return "declval<_Up&>().~_Up()" is well-formed
2687// where _Up is remove_all_extents<_Tp>::type
2688
2689template <class>
2690struct __is_destructible_apply { typedef int type; };
2691
2692template <typename _Tp>
2693struct __is_destructor_wellformed {
2694 template <typename _Tp1>
2695 static char __test (
2696 typename __is_destructible_apply<decltype(declval<_Tp1&>().~_Tp1())>::type
2697 );
2698
2699 template <typename _Tp1>
2700 static __two __test (...);
2701
2702 static const bool value = sizeof(__test<_Tp>(12)) == sizeof(char);
2703};
2704
2705template <class _Tp, bool>
2706struct __destructible_imp;
2707
2708template <class _Tp>
2709struct __destructible_imp<_Tp, false>
2710 : public integral_constant<bool,
2711 __is_destructor_wellformed<typename remove_all_extents<_Tp>::type>::value> {};
2712
2713template <class _Tp>
2714struct __destructible_imp<_Tp, true>
2715 : public true_type {};
2716
2717template <class _Tp, bool>
2718struct __destructible_false;
2719
2720template <class _Tp>
2721struct __destructible_false<_Tp, false> : public __destructible_imp<_Tp, is_reference<_Tp>::value> {};
2722
2723template <class _Tp>
2724struct __destructible_false<_Tp, true> : public false_type {};
2725
2726template <class _Tp>
2727struct is_destructible
2728 : public __destructible_false<_Tp, is_function<_Tp>::value> {};
2729
2730template <class _Tp>
2731struct is_destructible<_Tp[]>
2732 : public false_type {};
2733
2734template <>
2735struct is_destructible<void>
2736 : public false_type {};
2737
2738#if _LIBCPP_STD_VER > 14
2739template <class _Tp>
2740inline constexpr bool is_destructible_v = is_destructible<_Tp>::value;
2741#endif
2742
2743#endif // __has_keyword(__is_destructible)
2744
2745template <class _MP, bool _IsMemberFunctionPtr, bool _IsMemberObjectPtr>
2746struct __member_pointer_traits_imp
2747{
2748};
2749
2750template <class _Rp, class _Class, class ..._Param>
2751struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...), true, false>
2752{
2753 typedef _Class _ClassType;
2754 typedef _Rp _ReturnType;
2755 typedef _Rp (_FnType) (_Param...);
2756};
2757
2758template <class _Rp, class _Class, class ..._Param>
2759struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...), true, false>
2760{
2761 typedef _Class _ClassType;
2762 typedef _Rp _ReturnType;
2763 typedef _Rp (_FnType) (_Param..., ...);
2764};
2765
2766template <class _Rp, class _Class, class ..._Param>
2767struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const, true, false>
2768{
2769 typedef _Class const _ClassType;
2770 typedef _Rp _ReturnType;
2771 typedef _Rp (_FnType) (_Param...);
2772};
2773
2774template <class _Rp, class _Class, class ..._Param>
2775struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const, true, false>
2776{
2777 typedef _Class const _ClassType;
2778 typedef _Rp _ReturnType;
2779 typedef _Rp (_FnType) (_Param..., ...);
2780};
2781
2782template <class _Rp, class _Class, class ..._Param>
2783struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) volatile, true, false>
2784{
2785 typedef _Class volatile _ClassType;
2786 typedef _Rp _ReturnType;
2787 typedef _Rp (_FnType) (_Param...);
2788};
2789
2790template <class _Rp, class _Class, class ..._Param>
2791struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) volatile, true, false>
2792{
2793 typedef _Class volatile _ClassType;
2794 typedef _Rp _ReturnType;
2795 typedef _Rp (_FnType) (_Param..., ...);
2796};
2797
2798template <class _Rp, class _Class, class ..._Param>
2799struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const volatile, true, false>
2800{
2801 typedef _Class const volatile _ClassType;
2802 typedef _Rp _ReturnType;
2803 typedef _Rp (_FnType) (_Param...);
2804};
2805
2806template <class _Rp, class _Class, class ..._Param>
2807struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const volatile, true, false>
2808{
2809 typedef _Class const volatile _ClassType;
2810 typedef _Rp _ReturnType;
2811 typedef _Rp (_FnType) (_Param..., ...);
2812};
2813
2814#if __has_feature(cxx_reference_qualified_functions) || defined(_LIBCPP_COMPILER_GCC)
2815
2816template <class _Rp, class _Class, class ..._Param>
2817struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) &, true, false>
2818{
2819 typedef _Class& _ClassType;
2820 typedef _Rp _ReturnType;
2821 typedef _Rp (_FnType) (_Param...);
2822};
2823
2824template <class _Rp, class _Class, class ..._Param>
2825struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) &, true, false>
2826{
2827 typedef _Class& _ClassType;
2828 typedef _Rp _ReturnType;
2829 typedef _Rp (_FnType) (_Param..., ...);
2830};
2831
2832template <class _Rp, class _Class, class ..._Param>
2833struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const&, true, false>
2834{
2835 typedef _Class const& _ClassType;
2836 typedef _Rp _ReturnType;
2837 typedef _Rp (_FnType) (_Param...);
2838};
2839
2840template <class _Rp, class _Class, class ..._Param>
2841struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const&, true, false>
2842{
2843 typedef _Class const& _ClassType;
2844 typedef _Rp _ReturnType;
2845 typedef _Rp (_FnType) (_Param..., ...);
2846};
2847
2848template <class _Rp, class _Class, class ..._Param>
2849struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) volatile&, true, false>
2850{
2851 typedef _Class volatile& _ClassType;
2852 typedef _Rp _ReturnType;
2853 typedef _Rp (_FnType) (_Param...);
2854};
2855
2856template <class _Rp, class _Class, class ..._Param>
2857struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) volatile&, true, false>
2858{
2859 typedef _Class volatile& _ClassType;
2860 typedef _Rp _ReturnType;
2861 typedef _Rp (_FnType) (_Param..., ...);
2862};
2863
2864template <class _Rp, class _Class, class ..._Param>
2865struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const volatile&, true, false>
2866{
2867 typedef _Class const volatile& _ClassType;
2868 typedef _Rp _ReturnType;
2869 typedef _Rp (_FnType) (_Param...);
2870};
2871
2872template <class _Rp, class _Class, class ..._Param>
2873struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const volatile&, true, false>
2874{
2875 typedef _Class const volatile& _ClassType;
2876 typedef _Rp _ReturnType;
2877 typedef _Rp (_FnType) (_Param..., ...);
2878};
2879
2880template <class _Rp, class _Class, class ..._Param>
2881struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) &&, true, false>
2882{
2883 typedef _Class&& _ClassType;
2884 typedef _Rp _ReturnType;
2885 typedef _Rp (_FnType) (_Param...);
2886};
2887
2888template <class _Rp, class _Class, class ..._Param>
2889struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) &&, true, false>
2890{
2891 typedef _Class&& _ClassType;
2892 typedef _Rp _ReturnType;
2893 typedef _Rp (_FnType) (_Param..., ...);
2894};
2895
2896template <class _Rp, class _Class, class ..._Param>
2897struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const&&, true, false>
2898{
2899 typedef _Class const&& _ClassType;
2900 typedef _Rp _ReturnType;
2901 typedef _Rp (_FnType) (_Param...);
2902};
2903
2904template <class _Rp, class _Class, class ..._Param>
2905struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const&&, true, false>
2906{
2907 typedef _Class const&& _ClassType;
2908 typedef _Rp _ReturnType;
2909 typedef _Rp (_FnType) (_Param..., ...);
2910};
2911
2912template <class _Rp, class _Class, class ..._Param>
2913struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) volatile&&, true, false>
2914{
2915 typedef _Class volatile&& _ClassType;
2916 typedef _Rp _ReturnType;
2917 typedef _Rp (_FnType) (_Param...);
2918};
2919
2920template <class _Rp, class _Class, class ..._Param>
2921struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) volatile&&, true, false>
2922{
2923 typedef _Class volatile&& _ClassType;
2924 typedef _Rp _ReturnType;
2925 typedef _Rp (_FnType) (_Param..., ...);
2926};
2927
2928template <class _Rp, class _Class, class ..._Param>
2929struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const volatile&&, true, false>
2930{
2931 typedef _Class const volatile&& _ClassType;
2932 typedef _Rp _ReturnType;
2933 typedef _Rp (_FnType) (_Param...);
2934};
2935
2936template <class _Rp, class _Class, class ..._Param>
2937struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const volatile&&, true, false>
2938{
2939 typedef _Class const volatile&& _ClassType;
2940 typedef _Rp _ReturnType;
2941 typedef _Rp (_FnType) (_Param..., ...);
2942};
2943
2944#endif // __has_feature(cxx_reference_qualified_functions) || defined(_LIBCPP_COMPILER_GCC)
2945
2946
2947template <class _Rp, class _Class>
2948struct __member_pointer_traits_imp<_Rp _Class::*, false, true>
2949{
2950 typedef _Class _ClassType;
2951 typedef _Rp _ReturnType;
2952};
2953
2954template <class _MP>
2955struct __member_pointer_traits
2956 : public __member_pointer_traits_imp<typename remove_cv<_MP>::type,
2957 is_member_function_pointer<_MP>::value,
2958 is_member_object_pointer<_MP>::value>
2959{
2960// typedef ... _ClassType;
2961// typedef ... _ReturnType;
2962// typedef ... _FnType;
2963};
2964
2965
2966template <class _DecayedFp>
2967struct __member_pointer_class_type {};
2968
2969template <class _Ret, class _ClassType>
2970struct __member_pointer_class_type<_Ret _ClassType::*> {
2971 typedef _ClassType type;
2972};
2973
2974// template <class T, class... Args> struct is_constructible;
2975
2976template <class _Tp, class ..._Args>
2977struct _LIBCPP_TEMPLATE_VIS is_constructible
2978 : public integral_constant<bool, __is_constructible(_Tp, _Args...)>
2979{ };
2980
2981#if _LIBCPP_STD_VER > 14
2982template <class _Tp, class ..._Args>
2983inline constexpr bool is_constructible_v = is_constructible<_Tp, _Args...>::value;
2984#endif
2985
2986// is_default_constructible
2987
2988template <class _Tp>
2989struct _LIBCPP_TEMPLATE_VIS is_default_constructible
2990 : public is_constructible<_Tp>
2991 {};
2992
2993#if _LIBCPP_STD_VER > 14
2994template <class _Tp>
2995inline constexpr bool is_default_constructible_v = is_default_constructible<_Tp>::value;
2996#endif
2997
2998#ifndef _LIBCPP_CXX03_LANG
2999// First of all, we can't implement this check in C++03 mode because the {}
3000// default initialization syntax isn't valid.
3001// Second, we implement the trait in a funny manner with two defaulted template
3002// arguments to workaround Clang's PR43454.
3003template <class _Tp>
3004void __test_implicit_default_constructible(_Tp);
3005
3006template <class _Tp, class = void, class = typename is_default_constructible<_Tp>::type>
3007struct __is_implicitly_default_constructible
3008 : false_type
3009{ };
3010
3011template <class _Tp>
3012struct __is_implicitly_default_constructible<_Tp, decltype(__test_implicit_default_constructible<_Tp const&>({})), true_type>
3013 : true_type
3014{ };
3015
3016template <class _Tp>
3017struct __is_implicitly_default_constructible<_Tp, decltype(__test_implicit_default_constructible<_Tp const&>({})), false_type>
3018 : false_type
3019{ };
3020#endif // !C++03
3021
3022// is_copy_constructible
3023
3024template <class _Tp>
3025struct _LIBCPP_TEMPLATE_VIS is_copy_constructible
3026 : public is_constructible<_Tp,
3027 typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
3028
3029#if _LIBCPP_STD_VER > 14
3030template <class _Tp>
3031inline constexpr bool is_copy_constructible_v = is_copy_constructible<_Tp>::value;
3032#endif
3033
3034// is_move_constructible
3035
3036template <class _Tp>
3037struct _LIBCPP_TEMPLATE_VIS is_move_constructible
3038 : public is_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
3039 {};
3040
3041#if _LIBCPP_STD_VER > 14
3042template <class _Tp>
3043inline constexpr bool is_move_constructible_v = is_move_constructible<_Tp>::value;
3044#endif
3045
3046// is_trivially_constructible
3047
3048template <class _Tp, class... _Args>
3049struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible
3050 : integral_constant<bool, __is_trivially_constructible(_Tp, _Args...)>
3051{
3052};
3053
3054#if _LIBCPP_STD_VER > 14
3055template <class _Tp, class... _Args>
3056inline constexpr bool is_trivially_constructible_v = is_trivially_constructible<_Tp, _Args...>::value;
3057#endif
3058
3059// is_trivially_default_constructible
3060
3061template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_default_constructible
3062 : public is_trivially_constructible<_Tp>
3063 {};
3064
3065#if _LIBCPP_STD_VER > 14
3066template <class _Tp>
3067inline constexpr bool is_trivially_default_constructible_v = is_trivially_default_constructible<_Tp>::value;
3068#endif
3069
3070// is_trivially_copy_constructible
3071
3072template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_copy_constructible
3073 : public is_trivially_constructible<_Tp, typename add_lvalue_reference<const _Tp>::type>
3074 {};
3075
3076#if _LIBCPP_STD_VER > 14
3077template <class _Tp>
3078inline constexpr bool is_trivially_copy_constructible_v = is_trivially_copy_constructible<_Tp>::value;
3079#endif
3080
3081// is_trivially_move_constructible
3082
3083template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_move_constructible
3084 : public is_trivially_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
3085 {};
3086
3087#if _LIBCPP_STD_VER > 14
3088template <class _Tp>
3089inline constexpr bool is_trivially_move_constructible_v = is_trivially_move_constructible<_Tp>::value;
3090#endif
3091
3092// is_trivially_assignable
3093
3094template <class _Tp, class _Arg>
3095struct is_trivially_assignable
3096 : integral_constant<bool, __is_trivially_assignable(_Tp, _Arg)>
3097{ };
3098
3099#if _LIBCPP_STD_VER > 14
3100template <class _Tp, class _Arg>
3101inline constexpr bool is_trivially_assignable_v = is_trivially_assignable<_Tp, _Arg>::value;
3102#endif
3103
3104// is_trivially_copy_assignable
3105
3106template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_copy_assignable
3107 : public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type,
3108 typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
3109
3110#if _LIBCPP_STD_VER > 14
3111template <class _Tp>
3112inline constexpr bool is_trivially_copy_assignable_v = is_trivially_copy_assignable<_Tp>::value;
3113#endif
3114
3115// is_trivially_move_assignable
3116
3117template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_move_assignable
3118 : public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type,
3119 typename add_rvalue_reference<_Tp>::type>
3120 {};
3121
3122#if _LIBCPP_STD_VER > 14
3123template <class _Tp>
3124inline constexpr bool is_trivially_move_assignable_v = is_trivially_move_assignable<_Tp>::value;
3125#endif
3126
3127// is_trivially_destructible
3128
3129#if __has_keyword(__is_trivially_destructible)
3130
3131template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible
3132 : public integral_constant<bool, __is_trivially_destructible(_Tp)> {};
3133
3134#elif __has_feature(has_trivial_destructor) || defined(_LIBCPP_COMPILER_GCC)
3135
3136template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible
3137 : public integral_constant<bool, is_destructible<_Tp>::value && __has_trivial_destructor(_Tp)> {};
3138
3139#else
3140
3141template <class _Tp> struct __libcpp_trivial_destructor
3142 : public integral_constant<bool, is_scalar<_Tp>::value ||
3143 is_reference<_Tp>::value> {};
3144
3145template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible
3146 : public __libcpp_trivial_destructor<typename remove_all_extents<_Tp>::type> {};
3147
3148template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible<_Tp[]>
3149 : public false_type {};
3150
3151#endif
3152
3153#if _LIBCPP_STD_VER > 14
3154template <class _Tp>
3155inline constexpr bool is_trivially_destructible_v = is_trivially_destructible<_Tp>::value;
3156#endif
3157
3158// is_nothrow_constructible
3159
3160#if __has_keyword(__is_nothrow_constructible)
3161
3162template <class _Tp, class... _Args>
3163struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible
3164 : public integral_constant<bool, __is_nothrow_constructible(_Tp, _Args...)> {};
3165
3166#else
3167
3168template <bool, bool, class _Tp, class... _Args> struct __libcpp_is_nothrow_constructible;
3169
3170template <class _Tp, class... _Args>
3171struct __libcpp_is_nothrow_constructible</*is constructible*/true, /*is reference*/false, _Tp, _Args...>
3172 : public integral_constant<bool, noexcept(_Tp(declval<_Args>()...))>
3173{
3174};
3175
3176template <class _Tp>
3177void __implicit_conversion_to(_Tp) noexcept { }
3178
3179template <class _Tp, class _Arg>
3180struct __libcpp_is_nothrow_constructible</*is constructible*/true, /*is reference*/true, _Tp, _Arg>
3181 : public integral_constant<bool, noexcept(_VSTD::__implicit_conversion_to<_Tp>(declval<_Arg>()))>
3182{
3183};
3184
3185template <class _Tp, bool _IsReference, class... _Args>
3186struct __libcpp_is_nothrow_constructible</*is constructible*/false, _IsReference, _Tp, _Args...>
3187 : public false_type
3188{
3189};
3190
3191template <class _Tp, class... _Args>
3192struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible
3193 : __libcpp_is_nothrow_constructible<is_constructible<_Tp, _Args...>::value, is_reference<_Tp>::value, _Tp, _Args...>
3194{
3195};
3196
3197template <class _Tp, size_t _Ns>
3198struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp[_Ns]>
3199 : __libcpp_is_nothrow_constructible<is_constructible<_Tp>::value, is_reference<_Tp>::value, _Tp>
3200{
3201};
3202
3203#endif // _LIBCPP_HAS_NO_NOEXCEPT
3204
3205
3206#if _LIBCPP_STD_VER > 14
3207template <class _Tp, class ..._Args>
3208inline constexpr bool is_nothrow_constructible_v = is_nothrow_constructible<_Tp, _Args...>::value;
3209#endif
3210
3211// is_nothrow_default_constructible
3212
3213template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_default_constructible
3214 : public is_nothrow_constructible<_Tp>
3215 {};
3216
3217#if _LIBCPP_STD_VER > 14
3218template <class _Tp>
3219inline constexpr bool is_nothrow_default_constructible_v = is_nothrow_default_constructible<_Tp>::value;
3220#endif
3221
3222// is_nothrow_copy_constructible
3223
3224template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_copy_constructible
3225 : public is_nothrow_constructible<_Tp,
3226 typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
3227
3228#if _LIBCPP_STD_VER > 14
3229template <class _Tp>
3230inline constexpr bool is_nothrow_copy_constructible_v = is_nothrow_copy_constructible<_Tp>::value;
3231#endif
3232
3233// is_nothrow_move_constructible
3234
3235template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_move_constructible
3236 : public is_nothrow_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
3237 {};
3238
3239#if _LIBCPP_STD_VER > 14
3240template <class _Tp>
3241inline constexpr bool is_nothrow_move_constructible_v = is_nothrow_move_constructible<_Tp>::value;
3242#endif
3243
3244// is_nothrow_assignable
3245
3246#if __has_keyword(__is_nothrow_assignable)
3247
3248template <class _Tp, class _Arg>
3249struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable
3250 : public integral_constant<bool, __is_nothrow_assignable(_Tp, _Arg)> {};
3251
3252#else
3253
3254template <bool, class _Tp, class _Arg> struct __libcpp_is_nothrow_assignable;
3255
3256template <class _Tp, class _Arg>
3257struct __libcpp_is_nothrow_assignable<false, _Tp, _Arg>
3258 : public false_type
3259{
3260};
3261
3262template <class _Tp, class _Arg>
3263struct __libcpp_is_nothrow_assignable<true, _Tp, _Arg>
3264 : public integral_constant<bool, noexcept(declval<_Tp>() = declval<_Arg>()) >
3265{
3266};
3267
3268template <class _Tp, class _Arg>
3269struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable
3270 : public __libcpp_is_nothrow_assignable<is_assignable<_Tp, _Arg>::value, _Tp, _Arg>
3271{
3272};
3273
3274#endif // _LIBCPP_HAS_NO_NOEXCEPT
3275
3276#if _LIBCPP_STD_VER > 14
3277template <class _Tp, class _Arg>
3278inline constexpr bool is_nothrow_assignable_v = is_nothrow_assignable<_Tp, _Arg>::value;
3279#endif
3280
3281// is_nothrow_copy_assignable
3282
3283template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_copy_assignable
3284 : public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type,
3285 typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
3286
3287#if _LIBCPP_STD_VER > 14
3288template <class _Tp>
3289inline constexpr bool is_nothrow_copy_assignable_v = is_nothrow_copy_assignable<_Tp>::value;
3290#endif
3291
3292// is_nothrow_move_assignable
3293
3294template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_move_assignable
3295 : public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type,
3296 typename add_rvalue_reference<_Tp>::type>
3297 {};
3298
3299#if _LIBCPP_STD_VER > 14
3300template <class _Tp>
3301inline constexpr bool is_nothrow_move_assignable_v = is_nothrow_move_assignable<_Tp>::value;
3302#endif
3303
3304// is_nothrow_destructible
3305
3306#if !defined(_LIBCPP_CXX03_LANG)
3307
3308template <bool, class _Tp> struct __libcpp_is_nothrow_destructible;
3309
3310template <class _Tp>
3311struct __libcpp_is_nothrow_destructible<false, _Tp>
3312 : public false_type
3313{
3314};
3315
3316template <class _Tp>
3317struct __libcpp_is_nothrow_destructible<true, _Tp>
3318 : public integral_constant<bool, noexcept(declval<_Tp>().~_Tp()) >
3319{
3320};
3321
3322template <class _Tp>
3323struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible
3324 : public __libcpp_is_nothrow_destructible<is_destructible<_Tp>::value, _Tp>
3325{
3326};
539// Member detector base
3327540
3328template <class _Tp, size_t _Ns>
3329struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp[_Ns]>
3330 : public is_nothrow_destructible<_Tp>
3331{
3332};
541template <class _Tp, bool>
542struct _LIBCPP_TEMPLATE_VIS __dependent_type : public _Tp {};
3333543
3334template <class _Tp>
3335struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp&>
3336 : public true_type
3337{
3338};
544// is_integral
3339545
3340546template <class _Tp>
3341struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp&&>
3342 : public true_type
3343{
547struct __unconstref {
548 typedef _LIBCPP_NODEBUG typename remove_const<typename remove_reference<_Tp>::type>::type type;
3344549};
3345550
3346#else
3347
3348template <class _Tp> struct __libcpp_nothrow_destructor
3349 : public integral_constant<bool, is_scalar<_Tp>::value ||
3350 is_reference<_Tp>::value> {};
3351
3352template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible
3353 : public __libcpp_nothrow_destructor<typename remove_all_extents<_Tp>::type> {};
3354
3355template <class _Tp>
3356struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp[]>
3357 : public false_type {};
3358
3359#endif
3360
3361#if _LIBCPP_STD_VER > 14
3362template <class _Tp>
3363inline constexpr bool is_nothrow_destructible_v = is_nothrow_destructible<_Tp>::value;
3364#endif
3365
3366// is_pod
3367
3368#if __has_feature(is_pod) || defined(_LIBCPP_COMPILER_GCC)
3369
3370template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_pod
3371 : public integral_constant<bool, __is_pod(_Tp)> {};
3372
3373#else
3374
3375template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_pod
3376 : public integral_constant<bool, is_trivially_default_constructible<_Tp>::value &&
3377 is_trivially_copy_constructible<_Tp>::value &&
3378 is_trivially_copy_assignable<_Tp>::value &&
3379 is_trivially_destructible<_Tp>::value> {};
3380
3381#endif
3382
3383#if _LIBCPP_STD_VER > 14
3384template <class _Tp>
3385inline constexpr bool is_pod_v = is_pod<_Tp>::value;
3386#endif
3387
3388// is_literal_type;
3389
3390#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS)
3391template <class _Tp> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 is_literal_type
3392 : public integral_constant<bool, __is_literal_type(_Tp)>
3393 {};
3394
3395#if _LIBCPP_STD_VER > 14
3396template <class _Tp>
3397_LIBCPP_DEPRECATED_IN_CXX17 inline constexpr bool is_literal_type_v = is_literal_type<_Tp>::value;
3398#endif // _LIBCPP_STD_VER > 14
3399#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS)
3400
3401// is_standard_layout;
3402
3403template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_standard_layout
3404#if __has_feature(is_standard_layout) || defined(_LIBCPP_COMPILER_GCC)
3405 : public integral_constant<bool, __is_standard_layout(_Tp)>
3406#else
3407 : integral_constant<bool, is_scalar<typename remove_all_extents<_Tp>::type>::value>
3408#endif
3409 {};
3410
3411#if _LIBCPP_STD_VER > 14
551#ifndef _LIBCPP_CXX03_LANG
552// First of all, we can't implement this check in C++03 mode because the {}
553// default initialization syntax isn't valid.
554// Second, we implement the trait in a funny manner with two defaulted template
555// arguments to workaround Clang's PR43454.
3412556template <class _Tp>
3413inline constexpr bool is_standard_layout_v = is_standard_layout<_Tp>::value;
3414#endif
3415
3416// is_trivially_copyable;
557void __test_implicit_default_constructible(_Tp);
3417558
3418template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_copyable
3419 : public integral_constant<bool, __is_trivially_copyable(_Tp)>
3420 {};
559template <class _Tp, class = void, class = typename is_default_constructible<_Tp>::type>
560struct __is_implicitly_default_constructible
561 : false_type
562{ };
3421563
3422#if _LIBCPP_STD_VER > 14
3423564template <class _Tp>
3424inline constexpr bool is_trivially_copyable_v = is_trivially_copyable<_Tp>::value;
3425#endif
3426
3427// is_trivial;
3428
3429template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivial
3430#if __has_feature(is_trivial) || defined(_LIBCPP_COMPILER_GCC)
3431 : public integral_constant<bool, __is_trivial(_Tp)>
3432#else
3433 : integral_constant<bool, is_trivially_copyable<_Tp>::value &&
3434 is_trivially_default_constructible<_Tp>::value>
3435#endif
3436 {};
565struct __is_implicitly_default_constructible<_Tp, decltype(__test_implicit_default_constructible<_Tp const&>({})), true_type>
566 : true_type
567{ };
3437568
3438#if _LIBCPP_STD_VER > 14
3439569template <class _Tp>
3440inline constexpr bool is_trivial_v = is_trivial<_Tp>::value;
3441#endif
3442
3443template <class _Tp> struct __is_reference_wrapper_impl : public false_type {};
3444template <class _Tp> struct __is_reference_wrapper_impl<reference_wrapper<_Tp> > : public true_type {};
3445template <class _Tp> struct __is_reference_wrapper
3446 : public __is_reference_wrapper_impl<typename remove_cv<_Tp>::type> {};
3447
3448#ifndef _LIBCPP_CXX03_LANG
3449
3450template <class _Fp, class _A0,
3451 class _DecayFp = typename decay<_Fp>::type,
3452 class _DecayA0 = typename decay<_A0>::type,
3453 class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
3454using __enable_if_bullet1 = typename enable_if
3455 <
3456 is_member_function_pointer<_DecayFp>::value
3457 && is_base_of<_ClassT, _DecayA0>::value
3458 >::type;
3459
3460template <class _Fp, class _A0,
3461 class _DecayFp = typename decay<_Fp>::type,
3462 class _DecayA0 = typename decay<_A0>::type>
3463using __enable_if_bullet2 = typename enable_if
3464 <
3465 is_member_function_pointer<_DecayFp>::value
3466 && __is_reference_wrapper<_DecayA0>::value
3467 >::type;
3468
3469template <class _Fp, class _A0,
3470 class _DecayFp = typename decay<_Fp>::type,
3471 class _DecayA0 = typename decay<_A0>::type,
3472 class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
3473using __enable_if_bullet3 = typename enable_if
3474 <
3475 is_member_function_pointer<_DecayFp>::value
3476 && !is_base_of<_ClassT, _DecayA0>::value
3477 && !__is_reference_wrapper<_DecayA0>::value
3478 >::type;
3479
3480template <class _Fp, class _A0,
3481 class _DecayFp = typename decay<_Fp>::type,
3482 class _DecayA0 = typename decay<_A0>::type,
3483 class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
3484using __enable_if_bullet4 = typename enable_if
3485 <
3486 is_member_object_pointer<_DecayFp>::value
3487 && is_base_of<_ClassT, _DecayA0>::value
3488 >::type;
3489
3490template <class _Fp, class _A0,
3491 class _DecayFp = typename decay<_Fp>::type,
3492 class _DecayA0 = typename decay<_A0>::type>
3493using __enable_if_bullet5 = typename enable_if
3494 <
3495 is_member_object_pointer<_DecayFp>::value
3496 && __is_reference_wrapper<_DecayA0>::value
3497 >::type;
3498
3499template <class _Fp, class _A0,
3500 class _DecayFp = typename decay<_Fp>::type,
3501 class _DecayA0 = typename decay<_A0>::type,
3502 class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
3503using __enable_if_bullet6 = typename enable_if
3504 <
3505 is_member_object_pointer<_DecayFp>::value
3506 && !is_base_of<_ClassT, _DecayA0>::value
3507 && !__is_reference_wrapper<_DecayA0>::value
3508 >::type;
3509
3510// __invoke forward declarations
3511
3512// fall back - none of the bullets
3513
3514template <class ..._Args>
3515auto __invoke(__any, _Args&& ...__args) -> __nat;
3516
3517template <class ..._Args>
3518auto __invoke_constexpr(__any, _Args&& ...__args) -> __nat;
3519
3520// bullets 1, 2 and 3
3521
3522template <class _Fp, class _A0, class ..._Args,
3523 class = __enable_if_bullet1<_Fp, _A0>>
3524inline _LIBCPP_INLINE_VISIBILITY
3525_LIBCPP_CONSTEXPR_AFTER_CXX17 auto
3526__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
3527 noexcept(noexcept((static_cast<_A0&&>(__a0).*__f)(static_cast<_Args&&>(__args)...)))
3528 -> decltype( (static_cast<_A0&&>(__a0).*__f)(static_cast<_Args&&>(__args)...))
3529 { return (static_cast<_A0&&>(__a0).*__f)(static_cast<_Args&&>(__args)...); }
3530
3531template <class _Fp, class _A0, class ..._Args,
3532 class = __enable_if_bullet1<_Fp, _A0>>
3533inline _LIBCPP_INLINE_VISIBILITY
3534_LIBCPP_CONSTEXPR auto
3535__invoke_constexpr(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
3536 noexcept(noexcept((static_cast<_A0&&>(__a0).*__f)(static_cast<_Args&&>(__args)...)))
3537 -> decltype( (static_cast<_A0&&>(__a0).*__f)(static_cast<_Args&&>(__args)...))
3538 { return (static_cast<_A0&&>(__a0).*__f)(static_cast<_Args&&>(__args)...); }
3539
3540template <class _Fp, class _A0, class ..._Args,
3541 class = __enable_if_bullet2<_Fp, _A0>>
3542inline _LIBCPP_INLINE_VISIBILITY
3543_LIBCPP_CONSTEXPR_AFTER_CXX17 auto
3544__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
3545 noexcept(noexcept((__a0.get().*__f)(static_cast<_Args&&>(__args)...)))
3546 -> decltype( (__a0.get().*__f)(static_cast<_Args&&>(__args)...))
3547 { return (__a0.get().*__f)(static_cast<_Args&&>(__args)...); }
3548
3549template <class _Fp, class _A0, class ..._Args,
3550 class = __enable_if_bullet2<_Fp, _A0>>
3551inline _LIBCPP_INLINE_VISIBILITY
3552_LIBCPP_CONSTEXPR auto
3553__invoke_constexpr(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
3554 noexcept(noexcept((__a0.get().*__f)(static_cast<_Args&&>(__args)...)))
3555 -> decltype( (__a0.get().*__f)(static_cast<_Args&&>(__args)...))
3556 { return (__a0.get().*__f)(static_cast<_Args&&>(__args)...); }
3557
3558template <class _Fp, class _A0, class ..._Args,
3559 class = __enable_if_bullet3<_Fp, _A0>>
3560inline _LIBCPP_INLINE_VISIBILITY
3561_LIBCPP_CONSTEXPR_AFTER_CXX17 auto
3562__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
3563 noexcept(noexcept(((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_Args&&>(__args)...)))
3564 -> decltype( ((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_Args&&>(__args)...))
3565 { return ((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_Args&&>(__args)...); }
3566
3567template <class _Fp, class _A0, class ..._Args,
3568 class = __enable_if_bullet3<_Fp, _A0>>
3569inline _LIBCPP_INLINE_VISIBILITY
3570_LIBCPP_CONSTEXPR auto
3571__invoke_constexpr(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
3572 noexcept(noexcept(((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_Args&&>(__args)...)))
3573 -> decltype( ((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_Args&&>(__args)...))
3574 { return ((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_Args&&>(__args)...); }
3575
3576// bullets 4, 5 and 6
3577
3578template <class _Fp, class _A0,
3579 class = __enable_if_bullet4<_Fp, _A0>>
3580inline _LIBCPP_INLINE_VISIBILITY
3581_LIBCPP_CONSTEXPR_AFTER_CXX17 auto
3582__invoke(_Fp&& __f, _A0&& __a0)
3583 noexcept(noexcept(static_cast<_A0&&>(__a0).*__f))
3584 -> decltype( static_cast<_A0&&>(__a0).*__f)
3585 { return static_cast<_A0&&>(__a0).*__f; }
3586
3587template <class _Fp, class _A0,
3588 class = __enable_if_bullet4<_Fp, _A0>>
3589inline _LIBCPP_INLINE_VISIBILITY
3590_LIBCPP_CONSTEXPR auto
3591__invoke_constexpr(_Fp&& __f, _A0&& __a0)
3592 noexcept(noexcept(static_cast<_A0&&>(__a0).*__f))
3593 -> decltype( static_cast<_A0&&>(__a0).*__f)
3594 { return static_cast<_A0&&>(__a0).*__f; }
3595
3596template <class _Fp, class _A0,
3597 class = __enable_if_bullet5<_Fp, _A0>>
3598inline _LIBCPP_INLINE_VISIBILITY
3599_LIBCPP_CONSTEXPR_AFTER_CXX17 auto
3600__invoke(_Fp&& __f, _A0&& __a0)
3601 noexcept(noexcept(__a0.get().*__f))
3602 -> decltype( __a0.get().*__f)
3603 { return __a0.get().*__f; }
3604
3605template <class _Fp, class _A0,
3606 class = __enable_if_bullet5<_Fp, _A0>>
3607inline _LIBCPP_INLINE_VISIBILITY
3608_LIBCPP_CONSTEXPR auto
3609__invoke_constexpr(_Fp&& __f, _A0&& __a0)
3610 noexcept(noexcept(__a0.get().*__f))
3611 -> decltype( __a0.get().*__f)
3612 { return __a0.get().*__f; }
3613
3614template <class _Fp, class _A0,
3615 class = __enable_if_bullet6<_Fp, _A0>>
3616inline _LIBCPP_INLINE_VISIBILITY
3617_LIBCPP_CONSTEXPR_AFTER_CXX17 auto
3618__invoke(_Fp&& __f, _A0&& __a0)
3619 noexcept(noexcept((*static_cast<_A0&&>(__a0)).*__f))
3620 -> decltype( (*static_cast<_A0&&>(__a0)).*__f)
3621 { return (*static_cast<_A0&&>(__a0)).*__f; }
3622
3623template <class _Fp, class _A0,
3624 class = __enable_if_bullet6<_Fp, _A0>>
3625inline _LIBCPP_INLINE_VISIBILITY
3626_LIBCPP_CONSTEXPR auto
3627__invoke_constexpr(_Fp&& __f, _A0&& __a0)
3628 noexcept(noexcept((*static_cast<_A0&&>(__a0)).*__f))
3629 -> decltype( (*static_cast<_A0&&>(__a0)).*__f)
3630 { return (*static_cast<_A0&&>(__a0)).*__f; }
3631
3632// bullet 7
3633
3634template <class _Fp, class ..._Args>
3635inline _LIBCPP_INLINE_VISIBILITY
3636_LIBCPP_CONSTEXPR_AFTER_CXX17 auto
3637__invoke(_Fp&& __f, _Args&& ...__args)
3638 noexcept(noexcept(static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...)))
3639 -> decltype( static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...))
3640 { return static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...); }
3641
3642template <class _Fp, class ..._Args>
3643inline _LIBCPP_INLINE_VISIBILITY
3644_LIBCPP_CONSTEXPR auto
3645__invoke_constexpr(_Fp&& __f, _Args&& ...__args)
3646 noexcept(noexcept(static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...)))
3647 -> decltype( static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...))
3648 { return static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...); }
3649
3650// __invokable
3651template <class _Ret, class _Fp, class ..._Args>
3652struct __invokable_r
3653{
3654 template <class _XFp, class ..._XArgs>
3655 static auto __try_call(int) -> decltype(
3656 _VSTD::__invoke(declval<_XFp>(), declval<_XArgs>()...));
3657 template <class _XFp, class ..._XArgs>
3658 static __nat __try_call(...);
3659
3660 // FIXME: Check that _Ret, _Fp, and _Args... are all complete types, cv void,
3661 // or incomplete array types as required by the standard.
3662 using _Result = decltype(__try_call<_Fp, _Args...>(0));
3663
3664 using type =
3665 typename conditional<
3666 _IsNotSame<_Result, __nat>::value,
3667 typename conditional<
3668 is_void<_Ret>::value,
3669 true_type,
3670 is_convertible<_Result, _Ret>
3671 >::type,
3672 false_type
3673 >::type;
3674 static const bool value = type::value;
3675};
3676template <class _Fp, class ..._Args>
3677using __invokable = __invokable_r<void, _Fp, _Args...>;
3678
3679template <bool _IsInvokable, bool _IsCVVoid, class _Ret, class _Fp, class ..._Args>
3680struct __nothrow_invokable_r_imp {
3681 static const bool value = false;
3682};
3683
3684template <class _Ret, class _Fp, class ..._Args>
3685struct __nothrow_invokable_r_imp<true, false, _Ret, _Fp, _Args...>
3686{
3687 typedef __nothrow_invokable_r_imp _ThisT;
3688
3689 template <class _Tp>
3690 static void __test_noexcept(_Tp) noexcept;
3691
3692 static const bool value = noexcept(_ThisT::__test_noexcept<_Ret>(
3693 _VSTD::__invoke(declval<_Fp>(), declval<_Args>()...)));
3694};
3695
3696template <class _Ret, class _Fp, class ..._Args>
3697struct __nothrow_invokable_r_imp<true, true, _Ret, _Fp, _Args...>
3698{
3699 static const bool value = noexcept(
3700 _VSTD::__invoke(declval<_Fp>(), declval<_Args>()...));
3701};
3702
3703template <class _Ret, class _Fp, class ..._Args>
3704using __nothrow_invokable_r =
3705 __nothrow_invokable_r_imp<
3706 __invokable_r<_Ret, _Fp, _Args...>::value,
3707 is_void<_Ret>::value,
3708 _Ret, _Fp, _Args...
3709 >;
3710
3711template <class _Fp, class ..._Args>
3712using __nothrow_invokable =
3713 __nothrow_invokable_r_imp<
3714 __invokable<_Fp, _Args...>::value,
3715 true, void, _Fp, _Args...
3716 >;
3717
3718template <class _Fp, class ..._Args>
3719struct __invoke_of
3720 : public enable_if<
3721 __invokable<_Fp, _Args...>::value,
3722 typename __invokable_r<void, _Fp, _Args...>::_Result>
3723{
3724};
3725
3726#endif // _LIBCPP_CXX03_LANG
570struct __is_implicitly_default_constructible<_Tp, decltype(__test_implicit_default_constructible<_Tp const&>({})), false_type>
571 : false_type
572{ };
573#endif // !C++03
3727574
3728575// result_of
3729576
3730577#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS)
3731578template <class _Callable> class _LIBCPP_DEPRECATED_IN_CXX17 result_of;
3732579
3733#ifndef _LIBCPP_CXX03_LANG
3734
3735580template <class _Fp, class ..._Args>
3736581class _LIBCPP_TEMPLATE_VIS result_of<_Fp(_Args...)>
3737582 : public __invoke_of<_Fp, _Args...>
3738583{
3739584};
3740585
3741#else // C++03
3742
3743template <class _Fn, bool, bool>
3744class __result_of
3745{
3746};
3747
3748template <class _Fn, class ..._Args>
3749class __result_of<_Fn(_Args...), true, false>
3750{
3751public:
3752 typedef decltype(declval<_Fn>()(declval<_Args>()...)) type;
3753};
3754
3755template <class _MP, class _Tp, bool _IsMemberFunctionPtr>
3756struct __result_of_mp;
3757
3758// member function pointer
3759
3760template <class _MP, class _Tp>
3761struct __result_of_mp<_MP, _Tp, true>
3762{
3763 using type = typename __member_pointer_traits<_MP>::_ReturnType;
3764};
3765
3766// member data pointer
3767
3768template <class _MP, class _Tp, bool>
3769struct __result_of_mdp;
3770
3771template <class _Rp, class _Class, class _Tp>
3772struct __result_of_mdp<_Rp _Class::*, _Tp, false>
3773{
3774 using type = typename __apply_cv<decltype(*declval<_Tp>()), _Rp>::type&;
3775};
3776
3777template <class _Rp, class _Class, class _Tp>
3778struct __result_of_mdp<_Rp _Class::*, _Tp, true>
3779{
3780 using type = typename __apply_cv<_Tp, _Rp>::type&;
3781};
3782
3783template <class _Rp, class _Class, class _Tp>
3784struct __result_of_mp<_Rp _Class::*, _Tp, false>
3785 : public __result_of_mdp<_Rp _Class::*, _Tp,
3786 is_base_of<_Class, typename remove_reference<_Tp>::type>::value>
3787{
3788};
3789
3790template <class _Fn, class _Tp>
3791class __result_of<_Fn(_Tp), false, true> // _Fn must be member pointer
3792 : public __result_of_mp<typename remove_reference<_Fn>::type,
3793 _Tp,
3794 is_member_function_pointer<typename remove_reference<_Fn>::type>::value>
3795{
3796};
3797
3798template <class _Fn, class _Tp, class ..._Args>
3799class __result_of<_Fn(_Tp, _Args...), false, true> // _Fn must be member pointer
3800 : public __result_of_mp<typename remove_reference<_Fn>::type,
3801 _Tp,
3802 is_member_function_pointer<typename remove_reference<_Fn>::type>::value>
3803{
3804};
3805
3806template <class _Fn, class ..._Args>
3807class _LIBCPP_TEMPLATE_VIS result_of<_Fn(_Args...)>
3808 : public __result_of<_Fn(_Args...),
3809 is_class<typename remove_reference<_Fn>::type>::value ||
3810 is_function<typename remove_pointer<typename remove_reference<_Fn>::type>::type>::value,
3811 is_member_pointer<typename remove_reference<_Fn>::type>::value
3812 >
3813{
3814};
3815
3816#endif // C++03
3817
3818586#if _LIBCPP_STD_VER > 11
3819587template <class _Tp> using result_of_t _LIBCPP_DEPRECATED_IN_CXX17 = typename result_of<_Tp>::type;
3820588#endif // _LIBCPP_STD_VER > 11
3821589#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS)
3822590
3823#if _LIBCPP_STD_VER > 14
3824
3825// invoke_result
3826
3827template <class _Fn, class... _Args>
3828struct _LIBCPP_TEMPLATE_VIS invoke_result
3829 : __invoke_of<_Fn, _Args...>
3830{
3831};
3832
3833template <class _Fn, class... _Args>
3834using invoke_result_t = typename invoke_result<_Fn, _Args...>::type;
3835
3836// is_invocable
3837
3838template <class _Fn, class ..._Args>
3839struct _LIBCPP_TEMPLATE_VIS is_invocable
3840 : integral_constant<bool, __invokable<_Fn, _Args...>::value> {};
3841
3842template <class _Ret, class _Fn, class ..._Args>
3843struct _LIBCPP_TEMPLATE_VIS is_invocable_r
3844 : integral_constant<bool, __invokable_r<_Ret, _Fn, _Args...>::value> {};
3845
3846template <class _Fn, class ..._Args>
3847inline constexpr bool is_invocable_v = is_invocable<_Fn, _Args...>::value;
3848
3849template <class _Ret, class _Fn, class ..._Args>
3850inline constexpr bool is_invocable_r_v = is_invocable_r<_Ret, _Fn, _Args...>::value;
3851
3852// is_nothrow_invocable
3853
3854template <class _Fn, class ..._Args>
3855struct _LIBCPP_TEMPLATE_VIS is_nothrow_invocable
3856 : integral_constant<bool, __nothrow_invokable<_Fn, _Args...>::value> {};
3857
3858template <class _Ret, class _Fn, class ..._Args>
3859struct _LIBCPP_TEMPLATE_VIS is_nothrow_invocable_r
3860 : integral_constant<bool, __nothrow_invokable_r<_Ret, _Fn, _Args...>::value> {};
3861
3862template <class _Fn, class ..._Args>
3863inline constexpr bool is_nothrow_invocable_v = is_nothrow_invocable<_Fn, _Args...>::value;
3864
3865template <class _Ret, class _Fn, class ..._Args>
3866inline constexpr bool is_nothrow_invocable_r_v = is_nothrow_invocable_r<_Ret, _Fn, _Args...>::value;
3867
3868#endif // _LIBCPP_STD_VER > 14
3869
3870591// __swappable
3871592
3872593template <class _Tp> struct __is_swappable;
......@@ -3999,24 +720,6 @@ inline constexpr bool is_nothrow_swappable_v = is_nothrow_swappable<_Tp>::value;
3999720
4000721#endif // _LIBCPP_STD_VER > 14
4001722
4002template <class _Tp, bool = is_enum<_Tp>::value> struct __underlying_type_impl;
4003
4004template <class _Tp>
4005struct __underlying_type_impl<_Tp, false> {};
4006
4007template <class _Tp>
4008struct __underlying_type_impl<_Tp, true>
4009{
4010 typedef __underlying_type(_Tp) type;
4011};
4012
4013template <class _Tp>
4014struct underlying_type : __underlying_type_impl<_Tp, is_enum<_Tp>::value> {};
4015
4016#if _LIBCPP_STD_VER > 11
4017template <class _Tp> using underlying_type_t = typename underlying_type<_Tp>::type;
4018#endif
4019
4020723template <class _Tp, bool = is_enum<_Tp>::value>
4021724struct __sfinae_underlying_type
4022725{
......@@ -4063,42 +766,6 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
4063766typename __sfinae_underlying_type<_Tp>::__promoted_type
4064767__convert_to_integral(_Tp __val) { return __val; }
4065768
4066// is_scoped_enum [meta.unary.prop]
4067
4068#if _LIBCPP_STD_VER > 20
4069template <class _Tp, bool = is_enum_v<_Tp> >
4070struct __is_scoped_enum_helper : false_type {};
4071
4072template <class _Tp>
4073struct __is_scoped_enum_helper<_Tp, true>
4074 : public bool_constant<!is_convertible_v<_Tp, underlying_type_t<_Tp> > > {};
4075
4076template <class _Tp>
4077struct _LIBCPP_TEMPLATE_VIS is_scoped_enum
4078 : public __is_scoped_enum_helper<_Tp> {};
4079
4080template <class _Tp>
4081inline constexpr bool is_scoped_enum_v = is_scoped_enum<_Tp>::value;
4082#endif
4083
4084#if _LIBCPP_STD_VER > 14
4085
4086template <class... _Args>
4087struct conjunction : _And<_Args...> {};
4088template<class... _Args>
4089inline constexpr bool conjunction_v = conjunction<_Args...>::value;
4090
4091template <class... _Args>
4092struct disjunction : _Or<_Args...> {};
4093template<class... _Args>
4094inline constexpr bool disjunction_v = disjunction<_Args...>::value;
4095
4096template <class _Tp>
4097struct negation : _Not<_Tp> {};
4098template<class _Tp>
4099inline constexpr bool negation_v = negation<_Tp>::value;
4100#endif // _LIBCPP_STD_VER > 14
4101
4102769// These traits are used in __tree and __hash_table
4103770struct __extract_key_fail_tag {};
4104771struct __extract_key_self_tag {};
......@@ -4129,26 +796,14 @@ template <class _ValTy, class _Key, class _RawValTy>
4129796struct __can_extract_map_key<_ValTy, _Key, _Key, _RawValTy>
4130797 : false_type {};
4131798
4132#if _LIBCPP_STD_VER > 17
4133_LIBCPP_INLINE_VISIBILITY
4134inline constexpr bool is_constant_evaluated() noexcept {
4135 return __builtin_is_constant_evaluated();
4136}
4137#endif
4138
4139inline _LIBCPP_CONSTEXPR
4140bool __libcpp_is_constant_evaluated() _NOEXCEPT { return __builtin_is_constant_evaluated(); }
4141
4142799template <class _CharT>
4143800using _IsCharLikeType = _And<is_standard_layout<_CharT>, is_trivial<_CharT> >;
4144801
4145802template<class _Tp>
4146803using __make_const_lvalue_ref = const typename remove_reference<_Tp>::type&;
4147804
4148#if _LIBCPP_STD_VER > 17
4149805template<bool _Const, class _Tp>
4150using __maybe_const = conditional_t<_Const, const _Tp, _Tp>;
4151#endif // _LIBCPP_STD_VER > 17
806using __maybe_const = typename conditional<_Const, const _Tp, _Tp>::type;
4152807
4153808_LIBCPP_END_NAMESPACE_STD
4154809
lib/libcxx/include/typeindex+12-4
......@@ -44,15 +44,23 @@ struct hash<type_index>
4444
4545*/
4646
47#include <__assert> // all public C++ headers provide the assertion handler
4748#include <__config>
4849#include <__functional/unary_function.h>
49#include <__functional_base>
50#include <compare>
5150#include <typeinfo>
5251#include <version>
5352
53#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
54# include <iosfwd>
55# include <new>
56# include <utility>
57#endif
58
59// standard-mandated includes
60#include <compare>
61
5462#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
55#pragma GCC system_header
63# pragma GCC system_header
5664#endif
5765
5866_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -93,7 +101,7 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS hash;
93101
94102template <>
95103struct _LIBCPP_TEMPLATE_VIS hash<type_index>
96 : public unary_function<type_index, size_t>
104 : public __unary_function<type_index, size_t>
97105{
98106 _LIBCPP_INLINE_VISIBILITY
99107 size_t operator()(type_index __index) const _NOEXCEPT
lib/libcxx/include/typeinfo+2-1
......@@ -56,6 +56,7 @@ public:
5656
5757*/
5858
59#include <__assert> // all public C++ headers provide the assertion handler
5960#include <__availability>
6061#include <__config>
6162#include <cstddef>
......@@ -68,7 +69,7 @@ public:
6869#endif
6970
7071#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
71#pragma GCC system_header
72# pragma GCC system_header
7273#endif
7374
7475#if defined(_LIBCPP_ABI_VCRUNTIME)
lib/libcxx/include/uchar.h created+52
......@@ -0,0 +1,52 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_UCHAR_H
11#define _LIBCPP_UCHAR_H
12
13/*
14 uchar.h synopsis // since C++11
15
16Macros:
17
18 __STDC_UTF_16__
19 __STDC_UTF_32__
20
21Types:
22
23 mbstate_t
24 size_t
25
26size_t mbrtoc16(char16_t* pc16, const char* s, size_t n, mbstate_t* ps);
27size_t c16rtomb(char* s, char16_t c16, mbstate_t* ps);
28size_t mbrtoc32(char32_t* pc32, const char* s, size_t n, mbstate_t* ps);
29size_t c32rtomb(char* s, char32_t c32, mbstate_t* ps);
30
31*/
32
33#include <__config>
34
35#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
36# pragma GCC system_header
37#endif
38
39#if !defined(_LIBCPP_CXX03_LANG)
40
41// Some platforms don't implement <uchar.h> and we don't want to give a hard
42// error on those platforms. When the platform doesn't provide <uchar.h>, at
43// least include <stddef.h> so we get the declaration for size_t.
44#if __has_include_next(<uchar.h>)
45# include_next <uchar.h>
46#else
47# include <stddef.h>
48#endif
49
50#endif // _LIBCPP_CXX03_LANG
51
52#endif // _LIBCPP_UCHAR_H
lib/libcxx/include/unordered_map+64-53
......@@ -514,23 +514,44 @@ template <class Key, class T, class Hash, class Pred, class Alloc>
514514
515515*/
516516
517#include <__algorithm/is_permutation.h>
518#include <__assert> // all public C++ headers provide the assertion handler
517519#include <__config>
518520#include <__debug>
519521#include <__functional/is_transparent.h>
522#include <__functional/operations.h>
520523#include <__hash_table>
524#include <__iterator/distance.h>
525#include <__iterator/erase_if_container.h>
521526#include <__iterator/iterator_traits.h>
522527#include <__memory/addressof.h>
523528#include <__node_handle>
524529#include <__utility/forward.h>
525#include <compare>
526#include <functional>
527#include <iterator> // __libcpp_erase_if_container
528530#include <stdexcept>
529531#include <tuple>
530532#include <version>
531533
534#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
535# include <algorithm>
536# include <bit>
537# include <iterator>
538#endif
539
540// standard-mandated includes
541
542// [iterator.range]
543#include <__iterator/access.h>
544#include <__iterator/data.h>
545#include <__iterator/empty.h>
546#include <__iterator/reverse_access.h>
547#include <__iterator/size.h>
548
549// [unord.map.syn]
550#include <compare>
551#include <initializer_list>
552
532553#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
533#pragma GCC system_header
554# pragma GCC system_header
534555#endif
535556
536557_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -855,9 +876,7 @@ public:
855876 }
856877
857878 template <class _ValueTp,
858 class = typename enable_if<
859 __is_same_uncvref<_ValueTp, value_type>::value
860 >::type
879 class = __enable_if_t<__is_same_uncvref<_ValueTp, value_type>::value>
861880 >
862881 _LIBCPP_INLINE_VISIBILITY
863882 __hash_value_type& operator=(_ValueTp&& __v)
......@@ -1012,9 +1031,9 @@ public:
10121031 // types
10131032 typedef _Key key_type;
10141033 typedef _Tp mapped_type;
1015 typedef __identity_t<_Hash> hasher;
1016 typedef __identity_t<_Pred> key_equal;
1017 typedef __identity_t<_Alloc> allocator_type;
1034 typedef __type_identity_t<_Hash> hasher;
1035 typedef __type_identity_t<_Pred> key_equal;
1036 typedef __type_identity_t<_Alloc> allocator_type;
10181037 typedef pair<const key_type, mapped_type> value_type;
10191038 typedef value_type& reference;
10201039 typedef const value_type& const_reference;
......@@ -1216,13 +1235,13 @@ public:
12161235 }
12171236
12181237 template <class _Pp,
1219 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
1238 class = __enable_if_t<is_constructible<value_type, _Pp>::value> >
12201239 _LIBCPP_INLINE_VISIBILITY
12211240 pair<iterator, bool> insert(_Pp&& __x)
12221241 {return __table_.__insert_unique(_VSTD::forward<_Pp>(__x));}
12231242
12241243 template <class _Pp,
1225 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
1244 class = __enable_if_t<is_constructible<value_type, _Pp>::value> >
12261245 _LIBCPP_INLINE_VISIBILITY
12271246 iterator insert(const_iterator __p, _Pp&& __x)
12281247 {
......@@ -1506,11 +1525,11 @@ public:
15061525 _LIBCPP_INLINE_VISIBILITY
15071526 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
15081527 _LIBCPP_INLINE_VISIBILITY
1509 void rehash(size_type __n) {__table_.rehash(__n);}
1528 void rehash(size_type __n) {__table_.__rehash_unique(__n);}
15101529 _LIBCPP_INLINE_VISIBILITY
1511 void reserve(size_type __n) {__table_.reserve(__n);}
1530 void reserve(size_type __n) {__table_.__reserve_unique(__n);}
15121531
1513#if _LIBCPP_DEBUG_LEVEL == 2
1532#ifdef _LIBCPP_ENABLE_DEBUG_MODE
15141533
15151534 bool __dereferenceable(const const_iterator* __i) const
15161535 {return __table_.__dereferenceable(_VSTD::addressof(__i->__i_));}
......@@ -1521,7 +1540,7 @@ public:
15211540 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
15221541 {return __table_.__addable(_VSTD::addressof(__i->__i_), __n);}
15231542
1524#endif // _LIBCPP_DEBUG_LEVEL == 2
1543#endif // _LIBCPP_ENABLE_DEBUG_MODE
15251544
15261545private:
15271546
......@@ -1607,7 +1626,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
16071626 : __table_(__hf, __eql)
16081627{
16091628 _VSTD::__debug_db_insert_c(this);
1610 __table_.rehash(__n);
1629 __table_.__rehash_unique(__n);
16111630}
16121631
16131632template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
......@@ -1617,7 +1636,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
16171636 : __table_(__hf, __eql, typename __table::allocator_type(__a))
16181637{
16191638 _VSTD::__debug_db_insert_c(this);
1620 __table_.rehash(__n);
1639 __table_.__rehash_unique(__n);
16211640}
16221641
16231642template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
......@@ -1646,7 +1665,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
16461665 : __table_(__hf, __eql)
16471666{
16481667 _VSTD::__debug_db_insert_c(this);
1649 __table_.rehash(__n);
1668 __table_.__rehash_unique(__n);
16501669 insert(__first, __last);
16511670}
16521671
......@@ -1658,7 +1677,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
16581677 : __table_(__hf, __eql, typename __table::allocator_type(__a))
16591678{
16601679 _VSTD::__debug_db_insert_c(this);
1661 __table_.rehash(__n);
1680 __table_.__rehash_unique(__n);
16621681 insert(__first, __last);
16631682}
16641683
......@@ -1668,7 +1687,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
16681687 : __table_(__u.__table_)
16691688{
16701689 _VSTD::__debug_db_insert_c(this);
1671 __table_.rehash(__u.bucket_count());
1690 __table_.__rehash_unique(__u.bucket_count());
16721691 insert(__u.begin(), __u.end());
16731692}
16741693
......@@ -1678,7 +1697,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
16781697 : __table_(__u.__table_, typename __table::allocator_type(__a))
16791698{
16801699 _VSTD::__debug_db_insert_c(this);
1681 __table_.rehash(__u.bucket_count());
1700 __table_.__rehash_unique(__u.bucket_count());
16821701 insert(__u.begin(), __u.end());
16831702}
16841703
......@@ -1692,9 +1711,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
16921711 : __table_(_VSTD::move(__u.__table_))
16931712{
16941713 _VSTD::__debug_db_insert_c(this);
1695#if _LIBCPP_DEBUG_LEVEL == 2
1696 __get_db()->swap(this, _VSTD::addressof(__u));
1697#endif
1714 std::__debug_db_swap(this, std::addressof(__u));
16981715}
16991716
17001717template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
......@@ -1711,10 +1728,8 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
17111728 __u.__table_.remove((__i++).__i_)->__value_.__move());
17121729 }
17131730 }
1714#if _LIBCPP_DEBUG_LEVEL == 2
17151731 else
1716 __get_db()->swap(this, _VSTD::addressof(__u));
1717#endif
1732 std::__debug_db_swap(this, std::addressof(__u));
17181733}
17191734
17201735template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
......@@ -1732,7 +1747,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
17321747 : __table_(__hf, __eql)
17331748{
17341749 _VSTD::__debug_db_insert_c(this);
1735 __table_.rehash(__n);
1750 __table_.__rehash_unique(__n);
17361751 insert(__il.begin(), __il.end());
17371752}
17381753
......@@ -1743,7 +1758,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
17431758 : __table_(__hf, __eql, typename __table::allocator_type(__a))
17441759{
17451760 _VSTD::__debug_db_insert_c(this);
1746 __table_.rehash(__n);
1761 __table_.__rehash_unique(__n);
17471762 insert(__il.begin(), __il.end());
17481763}
17491764
......@@ -1906,9 +1921,9 @@ public:
19061921 // types
19071922 typedef _Key key_type;
19081923 typedef _Tp mapped_type;
1909 typedef __identity_t<_Hash> hasher;
1910 typedef __identity_t<_Pred> key_equal;
1911 typedef __identity_t<_Alloc> allocator_type;
1924 typedef __type_identity_t<_Hash> hasher;
1925 typedef __type_identity_t<_Pred> key_equal;
1926 typedef __type_identity_t<_Alloc> allocator_type;
19121927 typedef pair<const key_type, mapped_type> value_type;
19131928 typedef value_type& reference;
19141929 typedef const value_type& const_reference;
......@@ -2097,13 +2112,13 @@ public:
20972112 {return __table_.__insert_multi(__p.__i_, _VSTD::move(__x));}
20982113
20992114 template <class _Pp,
2100 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
2115 class = __enable_if_t<is_constructible<value_type, _Pp>::value> >
21012116 _LIBCPP_INLINE_VISIBILITY
21022117 iterator insert(_Pp&& __x)
21032118 {return __table_.__insert_multi(_VSTD::forward<_Pp>(__x));}
21042119
21052120 template <class _Pp,
2106 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
2121 class = __enable_if_t<is_constructible<value_type, _Pp>::value> >
21072122 _LIBCPP_INLINE_VISIBILITY
21082123 iterator insert(const_iterator __p, _Pp&& __x)
21092124 {return __table_.__insert_multi(__p.__i_, _VSTD::forward<_Pp>(__x));}
......@@ -2286,11 +2301,11 @@ public:
22862301 _LIBCPP_INLINE_VISIBILITY
22872302 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
22882303 _LIBCPP_INLINE_VISIBILITY
2289 void rehash(size_type __n) {__table_.rehash(__n);}
2304 void rehash(size_type __n) {__table_.__rehash_multi(__n);}
22902305 _LIBCPP_INLINE_VISIBILITY
2291 void reserve(size_type __n) {__table_.reserve(__n);}
2306 void reserve(size_type __n) {__table_.__reserve_multi(__n);}
22922307
2293#if _LIBCPP_DEBUG_LEVEL == 2
2308#ifdef _LIBCPP_ENABLE_DEBUG_MODE
22942309
22952310 bool __dereferenceable(const const_iterator* __i) const
22962311 {return __table_.__dereferenceable(_VSTD::addressof(__i->__i_));}
......@@ -2301,7 +2316,7 @@ public:
23012316 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
23022317 {return __table_.__addable(_VSTD::addressof(__i->__i_), __n);}
23032318
2304#endif // _LIBCPP_DEBUG_LEVEL == 2
2319#endif // _LIBCPP_ENABLE_DEBUG_MODE
23052320
23062321
23072322};
......@@ -2383,7 +2398,7 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
23832398 : __table_(__hf, __eql)
23842399{
23852400 _VSTD::__debug_db_insert_c(this);
2386 __table_.rehash(__n);
2401 __table_.__rehash_multi(__n);
23872402}
23882403
23892404template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
......@@ -2393,7 +2408,7 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
23932408 : __table_(__hf, __eql, typename __table::allocator_type(__a))
23942409{
23952410 _VSTD::__debug_db_insert_c(this);
2396 __table_.rehash(__n);
2411 __table_.__rehash_multi(__n);
23972412}
23982413
23992414template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
......@@ -2413,7 +2428,7 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
24132428 : __table_(__hf, __eql)
24142429{
24152430 _VSTD::__debug_db_insert_c(this);
2416 __table_.rehash(__n);
2431 __table_.__rehash_multi(__n);
24172432 insert(__first, __last);
24182433}
24192434
......@@ -2425,7 +2440,7 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
24252440 : __table_(__hf, __eql, typename __table::allocator_type(__a))
24262441{
24272442 _VSTD::__debug_db_insert_c(this);
2428 __table_.rehash(__n);
2443 __table_.__rehash_multi(__n);
24292444 insert(__first, __last);
24302445}
24312446
......@@ -2444,7 +2459,7 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
24442459 : __table_(__u.__table_)
24452460{
24462461 _VSTD::__debug_db_insert_c(this);
2447 __table_.rehash(__u.bucket_count());
2462 __table_.__rehash_multi(__u.bucket_count());
24482463 insert(__u.begin(), __u.end());
24492464}
24502465
......@@ -2454,7 +2469,7 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
24542469 : __table_(__u.__table_, typename __table::allocator_type(__a))
24552470{
24562471 _VSTD::__debug_db_insert_c(this);
2457 __table_.rehash(__u.bucket_count());
2472 __table_.__rehash_multi(__u.bucket_count());
24582473 insert(__u.begin(), __u.end());
24592474}
24602475
......@@ -2468,9 +2483,7 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
24682483 : __table_(_VSTD::move(__u.__table_))
24692484{
24702485 _VSTD::__debug_db_insert_c(this);
2471#if _LIBCPP_DEBUG_LEVEL == 2
2472 __get_db()->swap(this, _VSTD::addressof(__u));
2473#endif
2486 std::__debug_db_swap(this, std::addressof(__u));
24742487}
24752488
24762489template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
......@@ -2488,10 +2501,8 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
24882501 __u.__table_.remove((__i++).__i_)->__value_.__move());
24892502 }
24902503 }
2491#if _LIBCPP_DEBUG_LEVEL == 2
24922504 else
2493 __get_db()->swap(this, _VSTD::addressof(__u));
2494#endif
2505 std::__debug_db_swap(this, std::addressof(__u));
24952506}
24962507
24972508template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
......@@ -2509,7 +2520,7 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
25092520 : __table_(__hf, __eql)
25102521{
25112522 _VSTD::__debug_db_insert_c(this);
2512 __table_.rehash(__n);
2523 __table_.__rehash_multi(__n);
25132524 insert(__il.begin(), __il.end());
25142525}
25152526
......@@ -2520,7 +2531,7 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
25202531 : __table_(__hf, __eql, typename __table::allocator_type(__a))
25212532{
25222533 _VSTD::__debug_db_insert_c(this);
2523 __table_.rehash(__n);
2534 __table_.__rehash_multi(__n);
25242535 insert(__il.begin(), __il.end());
25252536}
25262537
lib/libcxx/include/unordered_set+82-83
......@@ -459,20 +459,41 @@ template <class Value, class Hash, class Pred, class Alloc>
459459
460460*/
461461
462#include <__algorithm/is_permutation.h>
463#include <__assert> // all public C++ headers provide the assertion handler
462464#include <__config>
463465#include <__debug>
464466#include <__functional/is_transparent.h>
467#include <__functional/operations.h>
465468#include <__hash_table>
469#include <__iterator/distance.h>
470#include <__iterator/erase_if_container.h>
471#include <__iterator/iterator_traits.h>
466472#include <__memory/addressof.h>
467473#include <__node_handle>
468474#include <__utility/forward.h>
469#include <compare>
470#include <functional>
471#include <iterator> // __libcpp_erase_if_container
472475#include <version>
473476
477#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
478# include <functional>
479# include <iterator>
480#endif
481
482// standard-mandated includes
483
484// [iterator.range]
485#include <__iterator/access.h>
486#include <__iterator/data.h>
487#include <__iterator/empty.h>
488#include <__iterator/reverse_access.h>
489#include <__iterator/size.h>
490
491// [unord.set.syn]
492#include <compare>
493#include <initializer_list>
494
474495#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
475#pragma GCC system_header
496# pragma GCC system_header
476497#endif
477498
478499_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -488,9 +509,9 @@ public:
488509 // types
489510 typedef _Value key_type;
490511 typedef key_type value_type;
491 typedef __identity_t<_Hash> hasher;
492 typedef __identity_t<_Pred> key_equal;
493 typedef __identity_t<_Alloc> allocator_type;
512 typedef __type_identity_t<_Hash> hasher;
513 typedef __type_identity_t<_Pred> key_equal;
514 typedef __type_identity_t<_Alloc> allocator_type;
494515 typedef value_type& reference;
495516 typedef const value_type& const_reference;
496517 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
......@@ -637,36 +658,27 @@ public:
637658 pair<iterator, bool> emplace(_Args&&... __args)
638659 {return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...);}
639660 template <class... _Args>
640 _LIBCPP_INLINE_VISIBILITY
641#if _LIBCPP_DEBUG_LEVEL == 2
642 iterator emplace_hint(const_iterator __p, _Args&&... __args)
643 {
644 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
645 "unordered_set::emplace_hint(const_iterator, args...) called with an iterator not"
646 " referring to this unordered_set");
647 return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;
648 }
649#else
650 iterator emplace_hint(const_iterator, _Args&&... __args)
651 {return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;}
652#endif
661 _LIBCPP_INLINE_VISIBILITY
662 iterator emplace_hint(const_iterator __p, _Args&&... __args) {
663 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(std::addressof(__p)) == this,
664 "unordered_set::emplace_hint(const_iterator, args...) called with an iterator not"
665 " referring to this unordered_set");
666 (void)__p;
667 return __table_.__emplace_unique(std::forward<_Args>(__args)...).first;
668 }
653669
654670 _LIBCPP_INLINE_VISIBILITY
655671 pair<iterator, bool> insert(value_type&& __x)
656672 {return __table_.__insert_unique(_VSTD::move(__x));}
657673 _LIBCPP_INLINE_VISIBILITY
658#if _LIBCPP_DEBUG_LEVEL == 2
659 iterator insert(const_iterator __p, value_type&& __x)
660 {
661 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
662 "unordered_set::insert(const_iterator, value_type&&) called with an iterator not"
663 " referring to this unordered_set");
664 return insert(_VSTD::move(__x)).first;
665 }
666#else
667 iterator insert(const_iterator, value_type&& __x)
668 {return insert(_VSTD::move(__x)).first;}
669#endif
674 iterator insert(const_iterator __p, value_type&& __x) {
675 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(std::addressof(__p)) == this,
676 "unordered_set::insert(const_iterator, value_type&&) called with an iterator not"
677 " referring to this unordered_set");
678 (void)__p;
679 return insert(std::move(__x)).first;
680 }
681
670682 _LIBCPP_INLINE_VISIBILITY
671683 void insert(initializer_list<value_type> __il)
672684 {insert(__il.begin(), __il.end());}
......@@ -676,18 +688,13 @@ public:
676688 {return __table_.__insert_unique(__x);}
677689
678690 _LIBCPP_INLINE_VISIBILITY
679#if _LIBCPP_DEBUG_LEVEL == 2
680 iterator insert(const_iterator __p, const value_type& __x)
681 {
682 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
683 "unordered_set::insert(const_iterator, const value_type&) called with an iterator not"
684 " referring to this unordered_set");
685 return insert(__x).first;
686 }
687#else
688 iterator insert(const_iterator, const value_type& __x)
689 {return insert(__x).first;}
690#endif
691 iterator insert(const_iterator __p, const value_type& __x) {
692 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(std::addressof(__p)) == this,
693 "unordered_set::insert(const_iterator, const value_type&) called with an iterator not"
694 " referring to this unordered_set");
695 (void)__p;
696 return insert(__x).first;
697 }
691698 template <class _InputIterator>
692699 _LIBCPP_INLINE_VISIBILITY
693700 void insert(_InputIterator __first, _InputIterator __last);
......@@ -851,11 +858,11 @@ public:
851858 _LIBCPP_INLINE_VISIBILITY
852859 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
853860 _LIBCPP_INLINE_VISIBILITY
854 void rehash(size_type __n) {__table_.rehash(__n);}
861 void rehash(size_type __n) {__table_.__rehash_unique(__n);}
855862 _LIBCPP_INLINE_VISIBILITY
856 void reserve(size_type __n) {__table_.reserve(__n);}
863 void reserve(size_type __n) {__table_.__reserve_unique(__n);}
857864
858#if _LIBCPP_DEBUG_LEVEL == 2
865#ifdef _LIBCPP_ENABLE_DEBUG_MODE
859866
860867 bool __dereferenceable(const const_iterator* __i) const
861868 {return __table_.__dereferenceable(__i);}
......@@ -866,7 +873,7 @@ public:
866873 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
867874 {return __table_.__addable(__i, __n);}
868875
869#endif // _LIBCPP_DEBUG_LEVEL == 2
876#endif // _LIBCPP_ENABLE_DEBUG_MODE
870877
871878};
872879
......@@ -935,7 +942,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(size_type __n,
935942 : __table_(__hf, __eql)
936943{
937944 _VSTD::__debug_db_insert_c(this);
938 __table_.rehash(__n);
945 __table_.__rehash_unique(__n);
939946}
940947
941948template <class _Value, class _Hash, class _Pred, class _Alloc>
......@@ -944,7 +951,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(size_type __n,
944951 : __table_(__hf, __eql, __a)
945952{
946953 _VSTD::__debug_db_insert_c(this);
947 __table_.rehash(__n);
954 __table_.__rehash_unique(__n);
948955}
949956
950957template <class _Value, class _Hash, class _Pred, class _Alloc>
......@@ -964,7 +971,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
964971 : __table_(__hf, __eql)
965972{
966973 _VSTD::__debug_db_insert_c(this);
967 __table_.rehash(__n);
974 __table_.__rehash_unique(__n);
968975 insert(__first, __last);
969976}
970977
......@@ -976,7 +983,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
976983 : __table_(__hf, __eql, __a)
977984{
978985 _VSTD::__debug_db_insert_c(this);
979 __table_.rehash(__n);
986 __table_.__rehash_unique(__n);
980987 insert(__first, __last);
981988}
982989
......@@ -995,7 +1002,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
9951002 : __table_(__u.__table_)
9961003{
9971004 _VSTD::__debug_db_insert_c(this);
998 __table_.rehash(__u.bucket_count());
1005 __table_.__rehash_unique(__u.bucket_count());
9991006 insert(__u.begin(), __u.end());
10001007}
10011008
......@@ -1005,7 +1012,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
10051012 : __table_(__u.__table_, __a)
10061013{
10071014 _VSTD::__debug_db_insert_c(this);
1008 __table_.rehash(__u.bucket_count());
1015 __table_.__rehash_unique(__u.bucket_count());
10091016 insert(__u.begin(), __u.end());
10101017}
10111018
......@@ -1019,9 +1026,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
10191026 : __table_(_VSTD::move(__u.__table_))
10201027{
10211028 _VSTD::__debug_db_insert_c(this);
1022#if _LIBCPP_DEBUG_LEVEL == 2
1023 __get_db()->swap(this, _VSTD::addressof(__u));
1024#endif
1029 std::__debug_db_swap(this, std::addressof(__u));
10251030}
10261031
10271032template <class _Value, class _Hash, class _Pred, class _Alloc>
......@@ -1036,10 +1041,8 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
10361041 while (__u.size() != 0)
10371042 __table_.__insert_unique(_VSTD::move(__u.__table_.remove(__i++)->__value_));
10381043 }
1039#if _LIBCPP_DEBUG_LEVEL == 2
10401044 else
1041 __get_db()->swap(this, _VSTD::addressof(__u));
1042#endif
1045 std::__debug_db_swap(this, std::addressof(__u));
10431046}
10441047
10451048template <class _Value, class _Hash, class _Pred, class _Alloc>
......@@ -1057,7 +1060,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
10571060 : __table_(__hf, __eql)
10581061{
10591062 _VSTD::__debug_db_insert_c(this);
1060 __table_.rehash(__n);
1063 __table_.__rehash_unique(__n);
10611064 insert(__il.begin(), __il.end());
10621065}
10631066
......@@ -1068,7 +1071,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
10681071 : __table_(__hf, __eql, __a)
10691072{
10701073 _VSTD::__debug_db_insert_c(this);
1071 __table_.rehash(__n);
1074 __table_.__rehash_unique(__n);
10721075 insert(__il.begin(), __il.end());
10731076}
10741077
......@@ -1162,9 +1165,9 @@ public:
11621165 // types
11631166 typedef _Value key_type;
11641167 typedef key_type value_type;
1165 typedef __identity_t<_Hash> hasher;
1166 typedef __identity_t<_Pred> key_equal;
1167 typedef __identity_t<_Alloc> allocator_type;
1168 typedef __type_identity_t<_Hash> hasher;
1169 typedef __type_identity_t<_Pred> key_equal;
1170 typedef __type_identity_t<_Alloc> allocator_type;
11681171 typedef value_type& reference;
11691172 typedef const value_type& const_reference;
11701173 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
......@@ -1493,11 +1496,11 @@ public:
14931496 _LIBCPP_INLINE_VISIBILITY
14941497 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
14951498 _LIBCPP_INLINE_VISIBILITY
1496 void rehash(size_type __n) {__table_.rehash(__n);}
1499 void rehash(size_type __n) {__table_.__rehash_multi(__n);}
14971500 _LIBCPP_INLINE_VISIBILITY
1498 void reserve(size_type __n) {__table_.reserve(__n);}
1501 void reserve(size_type __n) {__table_.__reserve_multi(__n);}
14991502
1500#if _LIBCPP_DEBUG_LEVEL == 2
1503#ifdef _LIBCPP_ENABLE_DEBUG_MODE
15011504
15021505 bool __dereferenceable(const const_iterator* __i) const
15031506 {return __table_.__dereferenceable(__i);}
......@@ -1508,7 +1511,7 @@ public:
15081511 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
15091512 {return __table_.__addable(__i, __n);}
15101513
1511#endif // _LIBCPP_DEBUG_LEVEL == 2
1514#endif // _LIBCPP_ENABLE_DEBUG_MODE
15121515
15131516};
15141517
......@@ -1575,7 +1578,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
15751578 : __table_(__hf, __eql)
15761579{
15771580 _VSTD::__debug_db_insert_c(this);
1578 __table_.rehash(__n);
1581 __table_.__rehash_multi(__n);
15791582}
15801583
15811584template <class _Value, class _Hash, class _Pred, class _Alloc>
......@@ -1585,7 +1588,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
15851588 : __table_(__hf, __eql, __a)
15861589{
15871590 _VSTD::__debug_db_insert_c(this);
1588 __table_.rehash(__n);
1591 __table_.__rehash_multi(__n);
15891592}
15901593
15911594template <class _Value, class _Hash, class _Pred, class _Alloc>
......@@ -1605,7 +1608,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
16051608 : __table_(__hf, __eql)
16061609{
16071610 _VSTD::__debug_db_insert_c(this);
1608 __table_.rehash(__n);
1611 __table_.__rehash_multi(__n);
16091612 insert(__first, __last);
16101613}
16111614
......@@ -1617,7 +1620,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
16171620 : __table_(__hf, __eql, __a)
16181621{
16191622 _VSTD::__debug_db_insert_c(this);
1620 __table_.rehash(__n);
1623 __table_.__rehash_multi(__n);
16211624 insert(__first, __last);
16221625}
16231626
......@@ -1636,7 +1639,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
16361639 : __table_(__u.__table_)
16371640{
16381641 _VSTD::__debug_db_insert_c(this);
1639 __table_.rehash(__u.bucket_count());
1642 __table_.__rehash_multi(__u.bucket_count());
16401643 insert(__u.begin(), __u.end());
16411644}
16421645
......@@ -1646,7 +1649,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
16461649 : __table_(__u.__table_, __a)
16471650{
16481651 _VSTD::__debug_db_insert_c(this);
1649 __table_.rehash(__u.bucket_count());
1652 __table_.__rehash_multi(__u.bucket_count());
16501653 insert(__u.begin(), __u.end());
16511654}
16521655
......@@ -1660,9 +1663,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
16601663 : __table_(_VSTD::move(__u.__table_))
16611664{
16621665 _VSTD::__debug_db_insert_c(this);
1663#if _LIBCPP_DEBUG_LEVEL == 2
1664 __get_db()->swap(this, _VSTD::addressof(__u));
1665#endif
1666 std::__debug_db_swap(this, std::addressof(__u));
16661667}
16671668
16681669template <class _Value, class _Hash, class _Pred, class _Alloc>
......@@ -1677,10 +1678,8 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
16771678 while (__u.size() != 0)
16781679 __table_.__insert_multi(_VSTD::move(__u.__table_.remove(__i++)->__value_));
16791680 }
1680#if _LIBCPP_DEBUG_LEVEL == 2
16811681 else
1682 __get_db()->swap(this, _VSTD::addressof(__u));
1683#endif
1682 std::__debug_db_swap(this, std::addressof(__u));
16841683}
16851684
16861685template <class _Value, class _Hash, class _Pred, class _Alloc>
......@@ -1698,7 +1697,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
16981697 : __table_(__hf, __eql)
16991698{
17001699 _VSTD::__debug_db_insert_c(this);
1701 __table_.rehash(__n);
1700 __table_.__rehash_multi(__n);
17021701 insert(__il.begin(), __il.end());
17031702}
17041703
......@@ -1709,7 +1708,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
17091708 : __table_(__hf, __eql, __a)
17101709{
17111710 _VSTD::__debug_db_insert_c(this);
1712 __table_.rehash(__n);
1711 __table_.__rehash_multi(__n);
17131712 insert(__il.begin(), __il.end());
17141713}
17151714
lib/libcxx/include/utility+17-3
......@@ -95,6 +95,12 @@ struct pair
9595 is_nothrow_swappable_v<T2>); // constexpr in C++20
9696};
9797
98template<class T1, class T2, class U1, class U2, template<class> class TQual, template<class> class UQual>
99struct basic_common_reference<pair<T1, T2>, pair<U1, U2>, TQual, UQual>; // since C++23
100
101template<class T1, class T2, class U1, class U2>
102struct common_type<pair<T1, T2>, pair<U1, U2>>; // since C++23
103
98104template<class T1, class T2> pair(T1, T2) -> pair<T1, T2>;
99105
100106template <class T1, class T2> bool operator==(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
......@@ -214,8 +220,8 @@ template <class T>
214220
215221*/
216222
223#include <__assert> // all public C++ headers provide the assertion handler
217224#include <__config>
218#include <__debug>
219225#include <__tuple>
220226#include <__utility/as_const.h>
221227#include <__utility/auto_cast.h>
......@@ -233,12 +239,20 @@ template <class T>
233239#include <__utility/swap.h>
234240#include <__utility/to_underlying.h>
235241#include <__utility/transaction.h>
242#include <__utility/unreachable.h>
243#include <type_traits>
244#include <version>
245
246#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
247# include <iosfwd>
248#endif
249
250// standard-mandated includes
236251#include <compare>
237252#include <initializer_list>
238#include <version>
239253
240254#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
241#pragma GCC system_header
255# pragma GCC system_header
242256#endif
243257
244258#endif // _LIBCPP_UTILITY
lib/libcxx/include/valarray+60-62
......@@ -341,17 +341,35 @@ template <class T> unspecified2 end(const valarray<T>& v);
341341
342342*/
343343
344#include <__algorithm/copy.h>
345#include <__algorithm/count.h>
346#include <__algorithm/fill.h>
347#include <__algorithm/max_element.h>
348#include <__algorithm/min.h>
349#include <__algorithm/min_element.h>
350#include <__algorithm/unwrap_iter.h>
351#include <__assert> // all public C++ headers provide the assertion handler
344352#include <__config>
345#include <algorithm>
353#include <__functional/operations.h>
354#include <__memory/allocator.h>
355#include <__memory/uninitialized_algorithms.h>
356#include <__utility/move.h>
357#include <__utility/swap.h>
346358#include <cmath>
347359#include <cstddef>
348#include <functional>
349#include <initializer_list>
350360#include <new>
351361#include <version>
352362
363#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
364# include <algorithm>
365# include <functional>
366#endif
367
368// standard-mandated includes
369#include <initializer_list>
370
353371#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
354#pragma GCC system_header
372# pragma GCC system_header
355373#endif
356374
357375_LIBCPP_PUSH_MACROS
......@@ -912,10 +930,14 @@ public:
912930#endif // _LIBCPP_CXX03_LANG
913931
914932 // unary operators:
915 valarray operator+() const;
916 valarray operator-() const;
917 valarray operator~() const;
918 valarray<bool> operator!() const;
933 _LIBCPP_INLINE_VISIBILITY
934 __val_expr<_UnaryOp<__unary_plus<_Tp>, const valarray&> > operator+() const;
935 _LIBCPP_INLINE_VISIBILITY
936 __val_expr<_UnaryOp<negate<_Tp>, const valarray&> > operator-() const;
937 _LIBCPP_INLINE_VISIBILITY
938 __val_expr<_UnaryOp<__bit_not<_Tp>, const valarray&> > operator~() const;
939 _LIBCPP_INLINE_VISIBILITY
940 __val_expr<_UnaryOp<logical_not<_Tp>, const valarray&> > operator!() const;
919941
920942 // computed assignment:
921943 _LIBCPP_INLINE_VISIBILITY
......@@ -1089,7 +1111,7 @@ template<class _Tp, size_t _Size>
10891111valarray(const _Tp(&)[_Size], size_t) -> valarray<_Tp>;
10901112#endif
10911113
1092_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void valarray<size_t>::resize(size_t, size_t))
1114extern template _LIBCPP_FUNC_VIS void valarray<size_t>::resize(size_t, size_t);
10931115
10941116template <class _Op, class _Tp>
10951117struct _UnaryOp<_Op, valarray<_Tp> >
......@@ -1530,21 +1552,21 @@ public:
15301552 gslice(size_t __start, const valarray<size_t>& __size,
15311553 valarray<size_t>&& __stride)
15321554 : __size_(__size),
1533 __stride_(move(__stride))
1555 __stride_(std::move(__stride))
15341556 {__init(__start);}
15351557
15361558 _LIBCPP_INLINE_VISIBILITY
15371559 gslice(size_t __start, valarray<size_t>&& __size,
15381560 const valarray<size_t>& __stride)
1539 : __size_(move(__size)),
1561 : __size_(std::move(__size)),
15401562 __stride_(__stride)
15411563 {__init(__start);}
15421564
15431565 _LIBCPP_INLINE_VISIBILITY
15441566 gslice(size_t __start, valarray<size_t>&& __size,
15451567 valarray<size_t>&& __stride)
1546 : __size_(move(__size)),
1547 __stride_(move(__stride))
1568 : __size_(std::move(__size)),
1569 __stride_(std::move(__stride))
15481570 {__init(__start);}
15491571
15501572#endif // _LIBCPP_CXX03_LANG
......@@ -1695,7 +1717,7 @@ private:
16951717#ifndef _LIBCPP_CXX03_LANG
16961718 gslice_array(gslice&& __gs, const valarray<value_type>& __v)
16971719 : __vp_(const_cast<value_type*>(__v.__begin_)),
1698 __1d_(move(__gs.__1d_))
1720 __1d_(std::move(__gs.__1d_))
16991721 {}
17001722#endif // _LIBCPP_CXX03_LANG
17011723
......@@ -2389,7 +2411,7 @@ private:
23892411 _LIBCPP_INLINE_VISIBILITY
23902412 indirect_array(valarray<size_t>&& __ia, const valarray<value_type>& __v)
23912413 : __vp_(const_cast<value_type*>(__v.__begin_)),
2392 __1d_(move(__ia))
2414 __1d_(std::move(__ia))
23932415 {}
23942416
23952417#endif // _LIBCPP_CXX03_LANG
......@@ -2608,7 +2630,7 @@ private:
26082630 _LIBCPP_INLINE_VISIBILITY
26092631 __indirect_expr(valarray<size_t>&& __ia, const _RmExpr& __e)
26102632 : __expr_(__e),
2611 __1d_(move(__ia))
2633 __1d_(std::move(__ia))
26122634 {}
26132635
26142636#endif // _LIBCPP_CXX03_LANG
......@@ -3203,7 +3225,7 @@ inline
32033225__val_expr<__indirect_expr<const valarray<_Tp>&> >
32043226valarray<_Tp>::operator[](gslice&& __gs) const
32053227{
3206 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__gs.__1d_), *this));
3228 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(std::move(__gs.__1d_), *this));
32073229}
32083230
32093231template <class _Tp>
......@@ -3211,7 +3233,7 @@ inline
32113233gslice_array<_Tp>
32123234valarray<_Tp>::operator[](gslice&& __gs)
32133235{
3214 return gslice_array<value_type>(move(__gs), *this);
3236 return gslice_array<value_type>(std::move(__gs), *this);
32153237}
32163238
32173239#endif // _LIBCPP_CXX03_LANG
......@@ -3239,7 +3261,7 @@ inline
32393261__val_expr<__mask_expr<const valarray<_Tp>&> >
32403262valarray<_Tp>::operator[](valarray<bool>&& __vb) const
32413263{
3242 return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(move(__vb), *this));
3264 return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(std::move(__vb), *this));
32433265}
32443266
32453267template <class _Tp>
......@@ -3247,7 +3269,7 @@ inline
32473269mask_array<_Tp>
32483270valarray<_Tp>::operator[](valarray<bool>&& __vb)
32493271{
3250 return mask_array<value_type>(move(__vb), *this);
3272 return mask_array<value_type>(std::move(__vb), *this);
32513273}
32523274
32533275#endif // _LIBCPP_CXX03_LANG
......@@ -3275,7 +3297,7 @@ inline
32753297__val_expr<__indirect_expr<const valarray<_Tp>&> >
32763298valarray<_Tp>::operator[](valarray<size_t>&& __vs) const
32773299{
3278 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__vs), *this));
3300 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(std::move(__vs), *this));
32793301}
32803302
32813303template <class _Tp>
......@@ -3283,69 +3305,45 @@ inline
32833305indirect_array<_Tp>
32843306valarray<_Tp>::operator[](valarray<size_t>&& __vs)
32853307{
3286 return indirect_array<value_type>(move(__vs), *this);
3308 return indirect_array<value_type>(std::move(__vs), *this);
32873309}
32883310
32893311#endif // _LIBCPP_CXX03_LANG
32903312
32913313template <class _Tp>
3292valarray<_Tp>
3314inline
3315__val_expr<_UnaryOp<__unary_plus<_Tp>, const valarray<_Tp>&> >
32933316valarray<_Tp>::operator+() const
32943317{
3295 valarray<value_type> __r;
3296 size_t __n = size();
3297 if (__n)
3298 {
3299 __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
3300 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3301 ::new ((void*)__r.__end_) value_type(+*__p);
3302 }
3303 return __r;
3318 using _Op = _UnaryOp<__unary_plus<_Tp>, const valarray<_Tp>&>;
3319 return __val_expr<_Op>(_Op(__unary_plus<_Tp>(), *this));
33043320}
33053321
33063322template <class _Tp>
3307valarray<_Tp>
3323inline
3324__val_expr<_UnaryOp<negate<_Tp>, const valarray<_Tp>&> >
33083325valarray<_Tp>::operator-() const
33093326{
3310 valarray<value_type> __r;
3311 size_t __n = size();
3312 if (__n)
3313 {
3314 __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
3315 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3316 ::new ((void*)__r.__end_) value_type(-*__p);
3317 }
3318 return __r;
3327 using _Op = _UnaryOp<negate<_Tp>, const valarray<_Tp>&>;
3328 return __val_expr<_Op>(_Op(negate<_Tp>(), *this));
33193329}
33203330
33213331template <class _Tp>
3322valarray<_Tp>
3332inline
3333__val_expr<_UnaryOp<__bit_not<_Tp>, const valarray<_Tp>&> >
33233334valarray<_Tp>::operator~() const
33243335{
3325 valarray<value_type> __r;
3326 size_t __n = size();
3327 if (__n)
3328 {
3329 __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
3330 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3331 ::new ((void*)__r.__end_) value_type(~*__p);
3332 }
3333 return __r;
3336 using _Op = _UnaryOp<__bit_not<_Tp>, const valarray<_Tp>&>;
3337 return __val_expr<_Op>(_Op(__bit_not<_Tp>(), *this));
33343338}
33353339
33363340template <class _Tp>
3337valarray<bool>
3341inline
3342__val_expr<_UnaryOp<logical_not<_Tp>, const valarray<_Tp>&> >
33383343valarray<_Tp>::operator!() const
33393344{
3340 valarray<bool> __r;
3341 size_t __n = size();
3342 if (__n)
3343 {
3344 __r.__begin_ = __r.__end_ = allocator<bool>().allocate(__n);
3345 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3346 ::new ((void*)__r.__end_) bool(!*__p);
3347 }
3348 return __r;
3345 using _Op = _UnaryOp<logical_not<_Tp>, const valarray<_Tp>&>;
3346 return __val_expr<_Op>(_Op(logical_not<_Tp>(), *this));
33493347}
33503348
33513349template <class _Tp>
lib/libcxx/include/variant+33-18
......@@ -199,24 +199,36 @@ namespace std {
199199
200200*/
201201
202#include <__assert> // all public C++ headers provide the assertion handler
202203#include <__availability>
203204#include <__config>
204205#include <__functional/hash.h>
206#include <__functional/operations.h>
207#include <__functional/unary_function.h>
205208#include <__tuple>
206209#include <__utility/forward.h>
210#include <__utility/in_place.h>
211#include <__utility/move.h>
212#include <__utility/swap.h>
207213#include <__variant/monostate.h>
208#include <compare>
209214#include <exception>
210215#include <initializer_list>
211216#include <limits>
212217#include <new>
213218#include <tuple>
214219#include <type_traits>
215#include <utility>
216220#include <version>
217221
222#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
223# include <typeinfo>
224# include <utility>
225#endif
226
227// standard-mandated includes
228#include <compare>
229
218230#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
219#pragma GCC system_header
231# pragma GCC system_header
220232#endif
221233
222234_LIBCPP_PUSH_MACROS
......@@ -533,7 +545,7 @@ private:
533545 template <class _Fp, class... _Vs>
534546 inline _LIBCPP_INLINE_VISIBILITY
535547 static constexpr decltype(auto) __dispatch(_Fp __f, _Vs... __vs) {
536 return _VSTD::__invoke_constexpr(
548 return _VSTD::__invoke(
537549 static_cast<_Fp>(__f),
538550 __access::__base::__get_alt<_Is>(static_cast<_Vs>(__vs))...);
539551 }
......@@ -549,7 +561,7 @@ private:
549561 inline _LIBCPP_INLINE_VISIBILITY
550562 static constexpr auto __make_fdiagonal_impl() {
551563 return __make_dispatch<_Fp, _Vs...>(
552 index_sequence<((void)__identity<_Vs>{}, _Ip)...>{});
564 index_sequence<((void)__type_identity<_Vs>{}, _Ip)...>{});
553565 }
554566
555567 template <class _Fp, class... _Vs, size_t... _Is>
......@@ -653,8 +665,8 @@ private:
653665 __std_visit_exhaustive_visitor_check<
654666 _Visitor,
655667 decltype((_VSTD::forward<_Alts>(__alts).__value))...>();
656 return _VSTD::__invoke_constexpr(_VSTD::forward<_Visitor>(__visitor),
657 _VSTD::forward<_Alts>(__alts).__value...);
668 return _VSTD::__invoke(_VSTD::forward<_Visitor>(__visitor),
669 _VSTD::forward<_Alts>(__alts).__value...);
658670 }
659671 _Visitor&& __visitor;
660672 };
......@@ -669,12 +681,12 @@ private:
669681 _Visitor,
670682 decltype((_VSTD::forward<_Alts>(__alts).__value))...>();
671683 if constexpr (is_void_v<_Rp>) {
672 _VSTD::__invoke_constexpr(_VSTD::forward<_Visitor>(__visitor),
673 _VSTD::forward<_Alts>(__alts).__value...);
684 _VSTD::__invoke(_VSTD::forward<_Visitor>(__visitor),
685 _VSTD::forward<_Alts>(__alts).__value...);
674686 }
675687 else {
676 return _VSTD::__invoke_constexpr(_VSTD::forward<_Visitor>(__visitor),
677 _VSTD::forward<_Alts>(__alts).__value...);
688 return _VSTD::__invoke(_VSTD::forward<_Visitor>(__visitor),
689 _VSTD::forward<_Alts>(__alts).__value...);
678690 }
679691 }
680692
......@@ -765,8 +777,8 @@ public:
765777 using __index_t = __variant_index_t<sizeof...(_Types)>;
766778
767779 inline _LIBCPP_INLINE_VISIBILITY
768 explicit constexpr __base(__valueless_t tag) noexcept
769 : __data(tag), __index(__variant_npos<__index_t>) {}
780 explicit constexpr __base(__valueless_t __tag) noexcept
781 : __data(__tag), __index(__variant_npos<__index_t>) {}
770782
771783 template <size_t _Ip, class... _Args>
772784 inline _LIBCPP_INLINE_VISIBILITY
......@@ -1121,8 +1133,11 @@ class _LIBCPP_TEMPLATE_VIS __impl
11211133 using __base_type = __copy_assignment<__traits<_Types...>>;
11221134
11231135public:
1124 using __base_type::__base_type;
1125 using __base_type::operator=;
1136 using __base_type::__base_type; // get in_place_index_t constructor & friends
1137 __impl(__impl const&) = default;
1138 __impl(__impl&&) = default;
1139 __impl& operator=(__impl const&) = default;
1140 __impl& operator=(__impl&&) = default;
11261141
11271142 template <size_t _Ip, class _Arg>
11281143 inline _LIBCPP_INLINE_VISIBILITY
......@@ -1186,12 +1201,12 @@ private:
11861201
11871202struct __no_narrowing_check {
11881203 template <class _Dest, class _Source>
1189 using _Apply = __identity<_Dest>;
1204 using _Apply = __type_identity<_Dest>;
11901205};
11911206
11921207struct __narrowing_check {
11931208 template <class _Dest>
1194 static auto __test_impl(_Dest (&&)[1]) -> __identity<_Dest>;
1209 static auto __test_impl(_Dest (&&)[1]) -> __type_identity<_Dest>;
11951210 template <class _Dest, class _Source>
11961211 using _Apply _LIBCPP_NODEBUG = decltype(__test_impl<_Dest>({declval<_Source>()}));
11971212};
......@@ -1217,7 +1232,7 @@ template <class _Tp, size_t>
12171232struct __overload_bool {
12181233 template <class _Up, class _Ap = __uncvref_t<_Up>>
12191234 auto operator()(bool, _Up&&) const
1220 -> enable_if_t<is_same_v<_Ap, bool>, __identity<_Tp>>;
1235 -> enable_if_t<is_same_v<_Ap, bool>, __type_identity<_Tp>>;
12211236};
12221237
12231238template <size_t _Idx>
lib/libcxx/include/vector+500-471
......@@ -271,20 +271,35 @@ erase_if(vector<T, Allocator>& c, Predicate pred); // C++20
271271
272272*/
273273
274#include <__algorithm/copy.h>
275#include <__algorithm/equal.h>
276#include <__algorithm/fill_n.h>
277#include <__algorithm/lexicographical_compare.h>
278#include <__algorithm/remove.h>
279#include <__algorithm/remove_if.h>
280#include <__algorithm/rotate.h>
281#include <__algorithm/unwrap_iter.h>
282#include <__assert> // all public C++ headers provide the assertion handler
274283#include <__bit_reference>
275284#include <__config>
276285#include <__debug>
277#include <__functional_base>
286#include <__format/enable_insertable.h>
287#include <__functional/hash.h>
288#include <__functional/unary_function.h>
289#include <__iterator/advance.h>
278290#include <__iterator/iterator_traits.h>
291#include <__iterator/reverse_iterator.h>
279292#include <__iterator/wrap_iter.h>
293#include <__memory/allocate_at_least.h>
294#include <__memory/pointer_traits.h>
295#include <__memory/swap_allocator.h>
280296#include <__split_buffer>
281297#include <__utility/forward.h>
282#include <algorithm>
298#include <__utility/move.h>
299#include <__utility/swap.h>
283300#include <climits>
284#include <compare>
285301#include <cstdlib>
286302#include <cstring>
287#include <initializer_list>
288303#include <iosfwd> // for forward declaration of vector
289304#include <limits>
290305#include <memory>
......@@ -292,8 +307,27 @@ erase_if(vector<T, Allocator>& c, Predicate pred); // C++20
292307#include <type_traits>
293308#include <version>
294309
310#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
311# include <algorithm>
312# include <typeinfo>
313# include <utility>
314#endif
315
316// standard-mandated includes
317
318// [iterator.range]
319#include <__iterator/access.h>
320#include <__iterator/data.h>
321#include <__iterator/empty.h>
322#include <__iterator/reverse_access.h>
323#include <__iterator/size.h>
324
325// [vector.syn]
326#include <compare>
327#include <initializer_list>
328
295329#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
296#pragma GCC system_header
330# pragma GCC system_header
297331#endif
298332
299333_LIBCPP_PUSH_MACROS
......@@ -326,12 +360,12 @@ public:
326360 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
327361 "Allocator::value_type must be same type as value_type");
328362
329 _LIBCPP_INLINE_VISIBILITY
363 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
330364 vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
331365 {
332366 _VSTD::__debug_db_insert_c(this);
333367 }
334 _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
368 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
335369#if _LIBCPP_STD_VER <= 14
336370 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
337371#else
......@@ -341,13 +375,14 @@ public:
341375 {
342376 _VSTD::__debug_db_insert_c(this);
343377 }
344 explicit vector(size_type __n);
378 _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit vector(size_type __n);
345379#if _LIBCPP_STD_VER > 11
346 explicit vector(size_type __n, const allocator_type& __a);
380 _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit vector(size_type __n, const allocator_type& __a);
347381#endif
348 vector(size_type __n, const value_type& __x);
382 _LIBCPP_CONSTEXPR_AFTER_CXX17 vector(size_type __n, const value_type& __x);
349383
350384 template <class = __enable_if_t<__is_allocator<_Allocator>::value> >
385 _LIBCPP_CONSTEXPR_AFTER_CXX17
351386 vector(size_type __n, const value_type& __x, const allocator_type& __a)
352387 : __end_cap_(nullptr, __a)
353388 {
......@@ -360,21 +395,22 @@ public:
360395 }
361396
362397 template <class _InputIterator>
398 _LIBCPP_CONSTEXPR_AFTER_CXX17
363399 vector(_InputIterator __first,
364 typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value &&
365 !__is_cpp17_forward_iterator<_InputIterator>::value &&
400 typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
366401 is_constructible<
367402 value_type,
368403 typename iterator_traits<_InputIterator>::reference>::value,
369404 _InputIterator>::type __last);
370405 template <class _InputIterator>
406 _LIBCPP_CONSTEXPR_AFTER_CXX17
371407 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
372 typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value &&
373 !__is_cpp17_forward_iterator<_InputIterator>::value &&
408 typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
374409 is_constructible<
375410 value_type,
376411 typename iterator_traits<_InputIterator>::reference>::value>::type* = 0);
377412 template <class _ForwardIterator>
413 _LIBCPP_CONSTEXPR_AFTER_CXX17
378414 vector(_ForwardIterator __first,
379415 typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value &&
380416 is_constructible<
......@@ -382,19 +418,18 @@ public:
382418 typename iterator_traits<_ForwardIterator>::reference>::value,
383419 _ForwardIterator>::type __last);
384420 template <class _ForwardIterator>
421 _LIBCPP_CONSTEXPR_AFTER_CXX17
385422 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
386423 typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value &&
387424 is_constructible<
388425 value_type,
389426 typename iterator_traits<_ForwardIterator>::reference>::value>::type* = 0);
390427
391 _LIBCPP_INLINE_VISIBILITY
428 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
392429 ~vector()
393430 {
394431 __annotate_delete();
395#if _LIBCPP_DEBUG_LEVEL == 2
396 __get_db()->__erase_c(this);
397#endif
432 std::__debug_db_erase_c(this);
398433
399434 if (this->__begin_ != nullptr)
400435 {
......@@ -403,43 +438,39 @@ public:
403438 }
404439 }
405440
406 vector(const vector& __x);
407 vector(const vector& __x, const __identity_t<allocator_type>& __a);
408 _LIBCPP_INLINE_VISIBILITY
441 _LIBCPP_CONSTEXPR_AFTER_CXX17 vector(const vector& __x);
442 _LIBCPP_CONSTEXPR_AFTER_CXX17 vector(const vector& __x, const __type_identity_t<allocator_type>& __a);
443 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
409444 vector& operator=(const vector& __x);
410445
411446#ifndef _LIBCPP_CXX03_LANG
412 _LIBCPP_INLINE_VISIBILITY
447 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
413448 vector(initializer_list<value_type> __il);
414449
415 _LIBCPP_INLINE_VISIBILITY
450 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
416451 vector(initializer_list<value_type> __il, const allocator_type& __a);
417452
418 _LIBCPP_INLINE_VISIBILITY
453 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
454 vector& operator=(initializer_list<value_type> __il)
455 {assign(__il.begin(), __il.end()); return *this;}
456#endif // !_LIBCPP_CXX03_LANG
457
458 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
419459 vector(vector&& __x)
420460#if _LIBCPP_STD_VER > 14
421 _NOEXCEPT;
461 noexcept;
422462#else
423463 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
424464#endif
425465
426 _LIBCPP_INLINE_VISIBILITY
427 vector(vector&& __x, const __identity_t<allocator_type>& __a);
428 _LIBCPP_INLINE_VISIBILITY
466 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
467 vector(vector&& __x, const __type_identity_t<allocator_type>& __a);
468 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
429469 vector& operator=(vector&& __x)
430470 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
431471
432 _LIBCPP_INLINE_VISIBILITY
433 vector& operator=(initializer_list<value_type> __il)
434 {assign(__il.begin(), __il.end()); return *this;}
435
436#endif // !_LIBCPP_CXX03_LANG
437
438472 template <class _InputIterator>
439 typename enable_if
440 <
441 __is_cpp17_input_iterator <_InputIterator>::value &&
442 !__is_cpp17_forward_iterator<_InputIterator>::value &&
473 _LIBCPP_CONSTEXPR_AFTER_CXX17 typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
443474 is_constructible<
444475 value_type,
445476 typename iterator_traits<_InputIterator>::reference>::value,
......@@ -447,6 +478,7 @@ public:
447478 >::type
448479 assign(_InputIterator __first, _InputIterator __last);
449480 template <class _ForwardIterator>
481 _LIBCPP_CONSTEXPR_AFTER_CXX17
450482 typename enable_if
451483 <
452484 __is_cpp17_forward_iterator<_ForwardIterator>::value &&
......@@ -457,137 +489,120 @@ public:
457489 >::type
458490 assign(_ForwardIterator __first, _ForwardIterator __last);
459491
460 void assign(size_type __n, const_reference __u);
492 _LIBCPP_CONSTEXPR_AFTER_CXX17 void assign(size_type __n, const_reference __u);
461493
462494#ifndef _LIBCPP_CXX03_LANG
463 _LIBCPP_INLINE_VISIBILITY
495 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
464496 void assign(initializer_list<value_type> __il)
465497 {assign(__il.begin(), __il.end());}
466498#endif
467499
468 _LIBCPP_INLINE_VISIBILITY
500 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
469501 allocator_type get_allocator() const _NOEXCEPT
470502 {return this->__alloc();}
471503
472 _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT;
473 _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT;
474 _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT;
475 _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT;
504 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT;
505 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT;
506 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT;
507 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT;
476508
477 _LIBCPP_INLINE_VISIBILITY
509 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
478510 reverse_iterator rbegin() _NOEXCEPT
479511 {return reverse_iterator(end());}
480 _LIBCPP_INLINE_VISIBILITY
512 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
481513 const_reverse_iterator rbegin() const _NOEXCEPT
482514 {return const_reverse_iterator(end());}
483 _LIBCPP_INLINE_VISIBILITY
515 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
484516 reverse_iterator rend() _NOEXCEPT
485517 {return reverse_iterator(begin());}
486 _LIBCPP_INLINE_VISIBILITY
518 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
487519 const_reverse_iterator rend() const _NOEXCEPT
488520 {return const_reverse_iterator(begin());}
489521
490 _LIBCPP_INLINE_VISIBILITY
522 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
491523 const_iterator cbegin() const _NOEXCEPT
492524 {return begin();}
493 _LIBCPP_INLINE_VISIBILITY
525 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
494526 const_iterator cend() const _NOEXCEPT
495527 {return end();}
496 _LIBCPP_INLINE_VISIBILITY
528 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
497529 const_reverse_iterator crbegin() const _NOEXCEPT
498530 {return rbegin();}
499 _LIBCPP_INLINE_VISIBILITY
531 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
500532 const_reverse_iterator crend() const _NOEXCEPT
501533 {return rend();}
502534
503 _LIBCPP_INLINE_VISIBILITY
535 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
504536 size_type size() const _NOEXCEPT
505537 {return static_cast<size_type>(this->__end_ - this->__begin_);}
506 _LIBCPP_INLINE_VISIBILITY
538 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
507539 size_type capacity() const _NOEXCEPT
508540 {return static_cast<size_type>(__end_cap() - this->__begin_);}
509 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
541 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
510542 bool empty() const _NOEXCEPT
511543 {return this->__begin_ == this->__end_;}
512 size_type max_size() const _NOEXCEPT;
513 void reserve(size_type __n);
514 void shrink_to_fit() _NOEXCEPT;
544 _LIBCPP_CONSTEXPR_AFTER_CXX17 size_type max_size() const _NOEXCEPT;
545 _LIBCPP_CONSTEXPR_AFTER_CXX17 void reserve(size_type __n);
546 _LIBCPP_CONSTEXPR_AFTER_CXX17 void shrink_to_fit() _NOEXCEPT;
515547
516 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) _NOEXCEPT;
517 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const _NOEXCEPT;
518 reference at(size_type __n);
519 const_reference at(size_type __n) const;
548 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) _NOEXCEPT;
549 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const _NOEXCEPT;
550 _LIBCPP_CONSTEXPR_AFTER_CXX17 reference at(size_type __n);
551 _LIBCPP_CONSTEXPR_AFTER_CXX17 const_reference at(size_type __n) const;
520552
521 _LIBCPP_INLINE_VISIBILITY reference front() _NOEXCEPT
553 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY reference front() _NOEXCEPT
522554 {
523555 _LIBCPP_ASSERT(!empty(), "front() called on an empty vector");
524556 return *this->__begin_;
525557 }
526 _LIBCPP_INLINE_VISIBILITY const_reference front() const _NOEXCEPT
558 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY const_reference front() const _NOEXCEPT
527559 {
528560 _LIBCPP_ASSERT(!empty(), "front() called on an empty vector");
529561 return *this->__begin_;
530562 }
531 _LIBCPP_INLINE_VISIBILITY reference back() _NOEXCEPT
563 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY reference back() _NOEXCEPT
532564 {
533565 _LIBCPP_ASSERT(!empty(), "back() called on an empty vector");
534566 return *(this->__end_ - 1);
535567 }
536 _LIBCPP_INLINE_VISIBILITY const_reference back() const _NOEXCEPT
568 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY const_reference back() const _NOEXCEPT
537569 {
538570 _LIBCPP_ASSERT(!empty(), "back() called on an empty vector");
539571 return *(this->__end_ - 1);
540572 }
541573
542 _LIBCPP_INLINE_VISIBILITY
574 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
543575 value_type* data() _NOEXCEPT
544576 {return _VSTD::__to_address(this->__begin_);}
545 _LIBCPP_INLINE_VISIBILITY
577
578 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
546579 const value_type* data() const _NOEXCEPT
547580 {return _VSTD::__to_address(this->__begin_);}
548581
549#ifdef _LIBCPP_CXX03_LANG
550 _LIBCPP_INLINE_VISIBILITY
551 void __emplace_back(const value_type& __x) { push_back(__x); }
552#else
553 template <class _Arg>
554 _LIBCPP_INLINE_VISIBILITY
555 void __emplace_back(_Arg&& __arg) {
556 emplace_back(_VSTD::forward<_Arg>(__arg));
557 }
558#endif
559
560 _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
582 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
561583
562#ifndef _LIBCPP_CXX03_LANG
563 _LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x);
584 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x);
564585
565586 template <class... _Args>
566 _LIBCPP_INLINE_VISIBILITY
587 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
567588#if _LIBCPP_STD_VER > 14
568589 reference emplace_back(_Args&&... __args);
569590#else
570591 void emplace_back(_Args&&... __args);
571592#endif
572#endif // !_LIBCPP_CXX03_LANG
573593
574 _LIBCPP_INLINE_VISIBILITY
594 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
575595 void pop_back();
576596
577 iterator insert(const_iterator __position, const_reference __x);
597 _LIBCPP_CONSTEXPR_AFTER_CXX17 iterator insert(const_iterator __position, const_reference __x);
578598
579#ifndef _LIBCPP_CXX03_LANG
580 iterator insert(const_iterator __position, value_type&& __x);
599 _LIBCPP_CONSTEXPR_AFTER_CXX17 iterator insert(const_iterator __position, value_type&& __x);
581600 template <class... _Args>
582 iterator emplace(const_iterator __position, _Args&&... __args);
583#endif // !_LIBCPP_CXX03_LANG
601 _LIBCPP_CONSTEXPR_AFTER_CXX17 iterator emplace(const_iterator __position, _Args&&... __args);
584602
585 iterator insert(const_iterator __position, size_type __n, const_reference __x);
603 _LIBCPP_CONSTEXPR_AFTER_CXX17 iterator insert(const_iterator __position, size_type __n, const_reference __x);
586604 template <class _InputIterator>
587 typename enable_if
588 <
589 __is_cpp17_input_iterator <_InputIterator>::value &&
590 !__is_cpp17_forward_iterator<_InputIterator>::value &&
605 _LIBCPP_CONSTEXPR_AFTER_CXX17 typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
591606 is_constructible<
592607 value_type,
593608 typename iterator_traits<_InputIterator>::reference>::value,
......@@ -595,6 +610,7 @@ public:
595610 >::type
596611 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
597612 template <class _ForwardIterator>
613 _LIBCPP_CONSTEXPR_AFTER_CXX17
598614 typename enable_if
599615 <
600616 __is_cpp17_forward_iterator<_ForwardIterator>::value &&
......@@ -606,27 +622,27 @@ public:
606622 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
607623
608624#ifndef _LIBCPP_CXX03_LANG
609 _LIBCPP_INLINE_VISIBILITY
625 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
610626 iterator insert(const_iterator __position, initializer_list<value_type> __il)
611627 {return insert(__position, __il.begin(), __il.end());}
612628#endif
613629
614 _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
615 iterator erase(const_iterator __first, const_iterator __last);
630 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
631 _LIBCPP_CONSTEXPR_AFTER_CXX17 iterator erase(const_iterator __first, const_iterator __last);
616632
617 _LIBCPP_INLINE_VISIBILITY
633 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
618634 void clear() _NOEXCEPT
619635 {
620636 size_type __old_size = size();
621637 __clear();
622638 __annotate_shrink(__old_size);
623 __invalidate_all_iterators();
639 std::__debug_db_invalidate_all(this);
624640 }
625641
626 void resize(size_type __sz);
627 void resize(size_type __sz, const_reference __x);
642 _LIBCPP_CONSTEXPR_AFTER_CXX17 void resize(size_type __sz);
643 _LIBCPP_CONSTEXPR_AFTER_CXX17 void resize(size_type __sz, const_reference __x);
628644
629 void swap(vector&)
645 _LIBCPP_CONSTEXPR_AFTER_CXX17 void swap(vector&)
630646#if _LIBCPP_STD_VER >= 14
631647 _NOEXCEPT;
632648#else
......@@ -634,16 +650,16 @@ public:
634650 __is_nothrow_swappable<allocator_type>::value);
635651#endif
636652
637 bool __invariants() const;
653 _LIBCPP_CONSTEXPR_AFTER_CXX17 bool __invariants() const;
638654
639#if _LIBCPP_DEBUG_LEVEL == 2
655#ifdef _LIBCPP_ENABLE_DEBUG_MODE
640656
641657 bool __dereferenceable(const const_iterator* __i) const;
642658 bool __decrementable(const const_iterator* __i) const;
643659 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
644660 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
645661
646#endif // _LIBCPP_DEBUG_LEVEL == 2
662#endif // _LIBCPP_ENABLE_DEBUG_MODE
647663
648664private:
649665 pointer __begin_ = nullptr;
......@@ -651,95 +667,108 @@ private:
651667 __compressed_pair<pointer, allocator_type> __end_cap_ =
652668 __compressed_pair<pointer, allocator_type>(nullptr, __default_init_tag());
653669
654 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
655670 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(pointer __new_last);
656 void __vallocate(size_type __n);
657 void __vdeallocate() _NOEXCEPT;
658 _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
659 void __construct_at_end(size_type __n);
660 _LIBCPP_INLINE_VISIBILITY
671
672 // Allocate space for __n objects
673 // throws length_error if __n > max_size()
674 // throws (probably bad_alloc) if memory run out
675 // Precondition: __begin_ == __end_ == __end_cap() == 0
676 // Precondition: __n > 0
677 // Postcondition: capacity() >= __n
678 // Postcondition: size() == 0
679 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI void __vallocate(size_type __n) {
680 if (__n > max_size())
681 __throw_length_error();
682 auto __allocation = std::__allocate_at_least(__alloc(), __n);
683 __begin_ = __allocation.ptr;
684 __end_ = __allocation.ptr;
685 __end_cap() = __begin_ + __allocation.count;
686 __annotate_new(0);
687 }
688
689 _LIBCPP_CONSTEXPR_AFTER_CXX17 void __vdeallocate() _NOEXCEPT;
690 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
691 _LIBCPP_CONSTEXPR_AFTER_CXX17 void __construct_at_end(size_type __n);
692 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
661693 void __construct_at_end(size_type __n, const_reference __x);
662694 template <class _ForwardIterator>
695 _LIBCPP_CONSTEXPR_AFTER_CXX17
663696 typename enable_if
664697 <
665698 __is_cpp17_forward_iterator<_ForwardIterator>::value,
666699 void
667700 >::type
668701 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n);
669 void __append(size_type __n);
670 void __append(size_type __n, const_reference __x);
671 _LIBCPP_INLINE_VISIBILITY
702 _LIBCPP_CONSTEXPR_AFTER_CXX17 void __append(size_type __n);
703 _LIBCPP_CONSTEXPR_AFTER_CXX17 void __append(size_type __n, const_reference __x);
704 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
672705 iterator __make_iter(pointer __p) _NOEXCEPT;
673 _LIBCPP_INLINE_VISIBILITY
706 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
674707 const_iterator __make_iter(const_pointer __p) const _NOEXCEPT;
675 void __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v);
676 pointer __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p);
677 void __move_range(pointer __from_s, pointer __from_e, pointer __to);
678 void __move_assign(vector& __c, true_type)
708 _LIBCPP_CONSTEXPR_AFTER_CXX17 void __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v);
709 _LIBCPP_CONSTEXPR_AFTER_CXX17 pointer __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p);
710 _LIBCPP_CONSTEXPR_AFTER_CXX17 void __move_range(pointer __from_s, pointer __from_e, pointer __to);
711 _LIBCPP_CONSTEXPR_AFTER_CXX17 void __move_assign(vector& __c, true_type)
679712 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
680 void __move_assign(vector& __c, false_type)
713 _LIBCPP_CONSTEXPR_AFTER_CXX17 void __move_assign(vector& __c, false_type)
681714 _NOEXCEPT_(__alloc_traits::is_always_equal::value);
682 _LIBCPP_INLINE_VISIBILITY
715 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
683716 void __destruct_at_end(pointer __new_last) _NOEXCEPT
684717 {
685 __invalidate_iterators_past(__new_last);
718 if (!__libcpp_is_constant_evaluated())
719 __invalidate_iterators_past(__new_last);
686720 size_type __old_size = size();
687721 __base_destruct_at_end(__new_last);
688722 __annotate_shrink(__old_size);
689723 }
690724
691#ifndef _LIBCPP_CXX03_LANG
692725 template <class _Up>
693 _LIBCPP_INLINE_VISIBILITY
726 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
694727 inline void __push_back_slow_path(_Up&& __x);
695728
696729 template <class... _Args>
697 _LIBCPP_INLINE_VISIBILITY
730 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
698731 inline void __emplace_back_slow_path(_Args&&... __args);
699#else
700 template <class _Up>
701 _LIBCPP_INLINE_VISIBILITY
702 inline void __push_back_slow_path(_Up& __x);
703#endif
704732
705733 // The following functions are no-ops outside of AddressSanitizer mode.
706734 // We call annotatations only for the default Allocator because other allocators
707735 // may not meet the AddressSanitizer alignment constraints.
708736 // See the documentation for __sanitizer_annotate_contiguous_container for more details.
709737#ifndef _LIBCPP_HAS_NO_ASAN
738 _LIBCPP_CONSTEXPR_AFTER_CXX17
710739 void __annotate_contiguous_container(const void *__beg, const void *__end,
711740 const void *__old_mid,
712741 const void *__new_mid) const
713742 {
714743
715 if (__beg && is_same<allocator_type, __default_allocator_type>::value)
744 if (!__libcpp_is_constant_evaluated() && __beg && is_same<allocator_type, __default_allocator_type>::value)
716745 __sanitizer_annotate_contiguous_container(__beg, __end, __old_mid, __new_mid);
717746 }
718747#else
719 _LIBCPP_INLINE_VISIBILITY
748 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
720749 void __annotate_contiguous_container(const void*, const void*, const void*,
721750 const void*) const _NOEXCEPT {}
722751#endif
723 _LIBCPP_INLINE_VISIBILITY
752 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
724753 void __annotate_new(size_type __current_size) const _NOEXCEPT {
725754 __annotate_contiguous_container(data(), data() + capacity(),
726755 data() + capacity(), data() + __current_size);
727756 }
728757
729 _LIBCPP_INLINE_VISIBILITY
758 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
730759 void __annotate_delete() const _NOEXCEPT {
731760 __annotate_contiguous_container(data(), data() + capacity(),
732761 data() + size(), data() + capacity());
733762 }
734763
735 _LIBCPP_INLINE_VISIBILITY
764 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
736765 void __annotate_increase(size_type __n) const _NOEXCEPT
737766 {
738767 __annotate_contiguous_container(data(), data() + capacity(),
739768 data() + size(), data() + size() + __n);
740769 }
741770
742 _LIBCPP_INLINE_VISIBILITY
771 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
743772 void __annotate_shrink(size_type __old_size) const _NOEXCEPT
744773 {
745774 __annotate_contiguous_container(data(), data() + capacity(),
......@@ -747,13 +776,14 @@ private:
747776 }
748777
749778 struct _ConstructTransaction {
779 _LIBCPP_CONSTEXPR_AFTER_CXX17
750780 explicit _ConstructTransaction(vector &__v, size_type __n)
751781 : __v_(__v), __pos_(__v.__end_), __new_end_(__v.__end_ + __n) {
752782#ifndef _LIBCPP_HAS_NO_ASAN
753783 __v_.__annotate_increase(__n);
754784#endif
755785 }
756 ~_ConstructTransaction() {
786 _LIBCPP_CONSTEXPR_AFTER_CXX17 ~_ConstructTransaction() {
757787 __v_.__end_ = __pos_;
758788#ifndef _LIBCPP_HAS_NO_ASAN
759789 if (__pos_ != __new_end_) {
......@@ -772,7 +802,7 @@ private:
772802 };
773803
774804 template <class ..._Args>
775 _LIBCPP_INLINE_VISIBILITY
805 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
776806 void __construct_one_at_end(_Args&& ...__args) {
777807 _ConstructTransaction __tx(*this, 1);
778808 __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__tx.__pos_),
......@@ -780,23 +810,23 @@ private:
780810 ++__tx.__pos_;
781811 }
782812
783 _LIBCPP_INLINE_VISIBILITY
813 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
784814 allocator_type& __alloc() _NOEXCEPT
785815 {return this->__end_cap_.second();}
786 _LIBCPP_INLINE_VISIBILITY
816 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
787817 const allocator_type& __alloc() const _NOEXCEPT
788818 {return this->__end_cap_.second();}
789 _LIBCPP_INLINE_VISIBILITY
819 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
790820 pointer& __end_cap() _NOEXCEPT
791821 {return this->__end_cap_.first();}
792 _LIBCPP_INLINE_VISIBILITY
822 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
793823 const pointer& __end_cap() const _NOEXCEPT
794824 {return this->__end_cap_.first();}
795825
796 _LIBCPP_INLINE_VISIBILITY
826 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
797827 void __clear() _NOEXCEPT {__base_destruct_at_end(this->__begin_);}
798828
799 _LIBCPP_INLINE_VISIBILITY
829 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
800830 void __base_destruct_at_end(pointer __new_last) _NOEXCEPT {
801831 pointer __soon_to_be_end = this->__end_;
802832 while (__new_last != __soon_to_be_end)
......@@ -804,12 +834,12 @@ private:
804834 this->__end_ = __new_last;
805835 }
806836
807 _LIBCPP_INLINE_VISIBILITY
837 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
808838 void __copy_assign_alloc(const vector& __c)
809839 {__copy_assign_alloc(__c, integral_constant<bool,
810840 __alloc_traits::propagate_on_container_copy_assignment::value>());}
811841
812 _LIBCPP_INLINE_VISIBILITY
842 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
813843 void __move_assign_alloc(vector& __c)
814844 _NOEXCEPT_(
815845 !__alloc_traits::propagate_on_container_move_assignment::value ||
......@@ -827,7 +857,7 @@ private:
827857 _VSTD::__throw_out_of_range("vector");
828858 }
829859
830 _LIBCPP_INLINE_VISIBILITY
860 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
831861 void __copy_assign_alloc(const vector& __c, true_type)
832862 {
833863 if (__alloc() != __c.__alloc())
......@@ -839,18 +869,18 @@ private:
839869 __alloc() = __c.__alloc();
840870 }
841871
842 _LIBCPP_INLINE_VISIBILITY
872 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
843873 void __copy_assign_alloc(const vector&, false_type)
844874 {}
845875
846 _LIBCPP_INLINE_VISIBILITY
876 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
847877 void __move_assign_alloc(vector& __c, true_type)
848878 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
849879 {
850880 __alloc() = _VSTD::move(__c.__alloc());
851881 }
852882
853 _LIBCPP_INLINE_VISIBILITY
883 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
854884 void __move_assign_alloc(vector&, false_type)
855885 _NOEXCEPT
856886 {}
......@@ -875,56 +905,46 @@ vector(_InputIterator, _InputIterator, _Alloc)
875905#endif
876906
877907template <class _Tp, class _Allocator>
908_LIBCPP_CONSTEXPR_AFTER_CXX17
878909void
879910vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v)
880911{
881
882912 __annotate_delete();
883 _VSTD::__construct_backward_with_exception_guarantees(this->__alloc(), this->__begin_, this->__end_, __v.__begin_);
913 using _RevIter = std::reverse_iterator<pointer>;
914 __v.__begin_ = std::__uninitialized_allocator_move_if_noexcept(
915 __alloc(), _RevIter(__end_), _RevIter(__begin_), _RevIter(__v.__begin_))
916 .base();
884917 _VSTD::swap(this->__begin_, __v.__begin_);
885918 _VSTD::swap(this->__end_, __v.__end_);
886919 _VSTD::swap(this->__end_cap(), __v.__end_cap());
887920 __v.__first_ = __v.__begin_;
888921 __annotate_new(size());
889 __invalidate_all_iterators();
922 std::__debug_db_invalidate_all(this);
890923}
891924
892925template <class _Tp, class _Allocator>
926_LIBCPP_CONSTEXPR_AFTER_CXX17
893927typename vector<_Tp, _Allocator>::pointer
894928vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p)
895929{
896930 __annotate_delete();
897931 pointer __r = __v.__begin_;
898 _VSTD::__construct_backward_with_exception_guarantees(this->__alloc(), this->__begin_, __p, __v.__begin_);
899 _VSTD::__construct_forward_with_exception_guarantees(this->__alloc(), __p, this->__end_, __v.__end_);
932 using _RevIter = std::reverse_iterator<pointer>;
933 __v.__begin_ = std::__uninitialized_allocator_move_if_noexcept(
934 __alloc(), _RevIter(__p), _RevIter(__begin_), _RevIter(__v.__begin_))
935 .base();
936 __v.__end_ = std::__uninitialized_allocator_move_if_noexcept(__alloc(), __p, __end_, __v.__end_);
900937 _VSTD::swap(this->__begin_, __v.__begin_);
901938 _VSTD::swap(this->__end_, __v.__end_);
902939 _VSTD::swap(this->__end_cap(), __v.__end_cap());
903940 __v.__first_ = __v.__begin_;
904941 __annotate_new(size());
905 __invalidate_all_iterators();
942 std::__debug_db_invalidate_all(this);
906943 return __r;
907944}
908945
909// Allocate space for __n objects
910// throws length_error if __n > max_size()
911// throws (probably bad_alloc) if memory run out
912// Precondition: __begin_ == __end_ == __end_cap() == 0
913// Precondition: __n > 0
914// Postcondition: capacity() == __n
915// Postcondition: size() == 0
916template <class _Tp, class _Allocator>
917void
918vector<_Tp, _Allocator>::__vallocate(size_type __n)
919{
920 if (__n > max_size())
921 this->__throw_length_error();
922 this->__begin_ = this->__end_ = __alloc_traits::allocate(this->__alloc(), __n);
923 this->__end_cap() = this->__begin_ + __n;
924 __annotate_new(0);
925}
926
927946template <class _Tp, class _Allocator>
947_LIBCPP_CONSTEXPR_AFTER_CXX17
928948void
929949vector<_Tp, _Allocator>::__vdeallocate() _NOEXCEPT
930950{
......@@ -937,6 +957,7 @@ vector<_Tp, _Allocator>::__vdeallocate() _NOEXCEPT
937957}
938958
939959template <class _Tp, class _Allocator>
960_LIBCPP_CONSTEXPR_AFTER_CXX17
940961typename vector<_Tp, _Allocator>::size_type
941962vector<_Tp, _Allocator>::max_size() const _NOEXCEPT
942963{
......@@ -946,6 +967,7 @@ vector<_Tp, _Allocator>::max_size() const _NOEXCEPT
946967
947968// Precondition: __new_size > capacity()
948969template <class _Tp, class _Allocator>
970_LIBCPP_CONSTEXPR_AFTER_CXX17
949971inline _LIBCPP_INLINE_VISIBILITY
950972typename vector<_Tp, _Allocator>::size_type
951973vector<_Tp, _Allocator>::__recommend(size_type __new_size) const
......@@ -965,6 +987,7 @@ vector<_Tp, _Allocator>::__recommend(size_type __new_size) const
965987// Precondition: size() + __n <= capacity()
966988// Postcondition: size() == size() + __n
967989template <class _Tp, class _Allocator>
990_LIBCPP_CONSTEXPR_AFTER_CXX17
968991void
969992vector<_Tp, _Allocator>::__construct_at_end(size_type __n)
970993{
......@@ -982,6 +1005,7 @@ vector<_Tp, _Allocator>::__construct_at_end(size_type __n)
9821005// Postcondition: size() == old size() + __n
9831006// Postcondition: [i] == __x for all i in [size() - __n, __n)
9841007template <class _Tp, class _Allocator>
1008_LIBCPP_CONSTEXPR_AFTER_CXX17
9851009inline
9861010void
9871011vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x)
......@@ -995,6 +1019,7 @@ vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x)
9951019
9961020template <class _Tp, class _Allocator>
9971021template <class _ForwardIterator>
1022_LIBCPP_CONSTEXPR_AFTER_CXX17
9981023typename enable_if
9991024<
10001025 __is_cpp17_forward_iterator<_ForwardIterator>::value,
......@@ -1002,8 +1027,8 @@ typename enable_if
10021027>::type
10031028vector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n)
10041029{
1005 _ConstructTransaction __tx(*this, __n);
1006 _VSTD::__construct_range_forward(this->__alloc(), __first, __last, __tx.__pos_);
1030 _ConstructTransaction __tx(*this, __n);
1031 __tx.__pos_ = std::__uninitialized_allocator_copy(__alloc(), __first, __last, __tx.__pos_);
10071032}
10081033
10091034// Default constructs __n objects starting at __end_
......@@ -1011,6 +1036,7 @@ vector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIt
10111036// Postcondition: size() == size() + __n
10121037// Exception safety: strong.
10131038template <class _Tp, class _Allocator>
1039_LIBCPP_CONSTEXPR_AFTER_CXX17
10141040void
10151041vector<_Tp, _Allocator>::__append(size_type __n)
10161042{
......@@ -1030,6 +1056,7 @@ vector<_Tp, _Allocator>::__append(size_type __n)
10301056// Postcondition: size() == size() + __n
10311057// Exception safety: strong.
10321058template <class _Tp, class _Allocator>
1059_LIBCPP_CONSTEXPR_AFTER_CXX17
10331060void
10341061vector<_Tp, _Allocator>::__append(size_type __n, const_reference __x)
10351062{
......@@ -1045,6 +1072,7 @@ vector<_Tp, _Allocator>::__append(size_type __n, const_reference __x)
10451072}
10461073
10471074template <class _Tp, class _Allocator>
1075_LIBCPP_CONSTEXPR_AFTER_CXX17
10481076vector<_Tp, _Allocator>::vector(size_type __n)
10491077{
10501078 _VSTD::__debug_db_insert_c(this);
......@@ -1057,6 +1085,7 @@ vector<_Tp, _Allocator>::vector(size_type __n)
10571085
10581086#if _LIBCPP_STD_VER > 11
10591087template <class _Tp, class _Allocator>
1088_LIBCPP_CONSTEXPR_AFTER_CXX17
10601089vector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a)
10611090 : __end_cap_(nullptr, __a)
10621091{
......@@ -1070,6 +1099,7 @@ vector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a)
10701099#endif
10711100
10721101template <class _Tp, class _Allocator>
1102_LIBCPP_CONSTEXPR_AFTER_CXX17
10731103vector<_Tp, _Allocator>::vector(size_type __n, const value_type& __x)
10741104{
10751105 _VSTD::__debug_db_insert_c(this);
......@@ -1082,9 +1112,9 @@ vector<_Tp, _Allocator>::vector(size_type __n, const value_type& __x)
10821112
10831113template <class _Tp, class _Allocator>
10841114template <class _InputIterator>
1115_LIBCPP_CONSTEXPR_AFTER_CXX17
10851116vector<_Tp, _Allocator>::vector(_InputIterator __first,
1086 typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value &&
1087 !__is_cpp17_forward_iterator<_InputIterator>::value &&
1117 typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
10881118 is_constructible<
10891119 value_type,
10901120 typename iterator_traits<_InputIterator>::reference>::value,
......@@ -1092,14 +1122,14 @@ vector<_Tp, _Allocator>::vector(_InputIterator __first,
10921122{
10931123 _VSTD::__debug_db_insert_c(this);
10941124 for (; __first != __last; ++__first)
1095 __emplace_back(*__first);
1125 emplace_back(*__first);
10961126}
10971127
10981128template <class _Tp, class _Allocator>
10991129template <class _InputIterator>
1130_LIBCPP_CONSTEXPR_AFTER_CXX17
11001131vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
1101 typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value &&
1102 !__is_cpp17_forward_iterator<_InputIterator>::value &&
1132 typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
11031133 is_constructible<
11041134 value_type,
11051135 typename iterator_traits<_InputIterator>::reference>::value>::type*)
......@@ -1107,11 +1137,12 @@ vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, c
11071137{
11081138 _VSTD::__debug_db_insert_c(this);
11091139 for (; __first != __last; ++__first)
1110 __emplace_back(*__first);
1140 emplace_back(*__first);
11111141}
11121142
11131143template <class _Tp, class _Allocator>
11141144template <class _ForwardIterator>
1145_LIBCPP_CONSTEXPR_AFTER_CXX17
11151146vector<_Tp, _Allocator>::vector(_ForwardIterator __first,
11161147 typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value &&
11171148 is_constructible<
......@@ -1130,6 +1161,7 @@ vector<_Tp, _Allocator>::vector(_ForwardIterator __first,
11301161
11311162template <class _Tp, class _Allocator>
11321163template <class _ForwardIterator>
1164_LIBCPP_CONSTEXPR_AFTER_CXX17
11331165vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
11341166 typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value &&
11351167 is_constructible<
......@@ -1147,6 +1179,7 @@ vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __las
11471179}
11481180
11491181template <class _Tp, class _Allocator>
1182_LIBCPP_CONSTEXPR_AFTER_CXX17
11501183vector<_Tp, _Allocator>::vector(const vector& __x)
11511184 : __end_cap_(nullptr, __alloc_traits::select_on_container_copy_construction(__x.__alloc()))
11521185{
......@@ -1160,7 +1193,8 @@ vector<_Tp, _Allocator>::vector(const vector& __x)
11601193}
11611194
11621195template <class _Tp, class _Allocator>
1163vector<_Tp, _Allocator>::vector(const vector& __x, const __identity_t<allocator_type>& __a)
1196_LIBCPP_CONSTEXPR_AFTER_CXX17
1197vector<_Tp, _Allocator>::vector(const vector& __x, const __type_identity_t<allocator_type>& __a)
11641198 : __end_cap_(nullptr, __a)
11651199{
11661200 _VSTD::__debug_db_insert_c(this);
......@@ -1172,22 +1206,19 @@ vector<_Tp, _Allocator>::vector(const vector& __x, const __identity_t<allocator_
11721206 }
11731207}
11741208
1175#ifndef _LIBCPP_CXX03_LANG
1176
11771209template <class _Tp, class _Allocator>
1210_LIBCPP_CONSTEXPR_AFTER_CXX17
11781211inline _LIBCPP_INLINE_VISIBILITY
11791212vector<_Tp, _Allocator>::vector(vector&& __x)
11801213#if _LIBCPP_STD_VER > 14
1181 _NOEXCEPT
1214 noexcept
11821215#else
11831216 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
11841217#endif
11851218 : __end_cap_(nullptr, _VSTD::move(__x.__alloc()))
11861219{
11871220 _VSTD::__debug_db_insert_c(this);
1188#if _LIBCPP_DEBUG_LEVEL == 2
1189 __get_db()->swap(this, _VSTD::addressof(__x));
1190#endif
1221 std::__debug_db_swap(this, std::addressof(__x));
11911222 this->__begin_ = __x.__begin_;
11921223 this->__end_ = __x.__end_;
11931224 this->__end_cap() = __x.__end_cap();
......@@ -1195,8 +1226,9 @@ vector<_Tp, _Allocator>::vector(vector&& __x)
11951226}
11961227
11971228template <class _Tp, class _Allocator>
1229_LIBCPP_CONSTEXPR_AFTER_CXX17
11981230inline _LIBCPP_INLINE_VISIBILITY
1199vector<_Tp, _Allocator>::vector(vector&& __x, const __identity_t<allocator_type>& __a)
1231vector<_Tp, _Allocator>::vector(vector&& __x, const __type_identity_t<allocator_type>& __a)
12001232 : __end_cap_(nullptr, __a)
12011233{
12021234 _VSTD::__debug_db_insert_c(this);
......@@ -1206,9 +1238,7 @@ vector<_Tp, _Allocator>::vector(vector&& __x, const __identity_t<allocator_type>
12061238 this->__end_ = __x.__end_;
12071239 this->__end_cap() = __x.__end_cap();
12081240 __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
1209#if _LIBCPP_DEBUG_LEVEL == 2
1210 __get_db()->swap(this, _VSTD::addressof(__x));
1211#endif
1241 std::__debug_db_swap(this, std::addressof(__x));
12121242 }
12131243 else
12141244 {
......@@ -1217,7 +1247,10 @@ vector<_Tp, _Allocator>::vector(vector&& __x, const __identity_t<allocator_type>
12171247 }
12181248}
12191249
1250#ifndef _LIBCPP_CXX03_LANG
1251
12201252template <class _Tp, class _Allocator>
1253_LIBCPP_CONSTEXPR_AFTER_CXX17
12211254inline _LIBCPP_INLINE_VISIBILITY
12221255vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il)
12231256{
......@@ -1230,6 +1263,7 @@ vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il)
12301263}
12311264
12321265template <class _Tp, class _Allocator>
1266_LIBCPP_CONSTEXPR_AFTER_CXX17
12331267inline _LIBCPP_INLINE_VISIBILITY
12341268vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
12351269 : __end_cap_(nullptr, __a)
......@@ -1242,7 +1276,10 @@ vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocat
12421276 }
12431277}
12441278
1279#endif // _LIBCPP_CXX03_LANG
1280
12451281template <class _Tp, class _Allocator>
1282_LIBCPP_CONSTEXPR_AFTER_CXX17
12461283inline _LIBCPP_INLINE_VISIBILITY
12471284vector<_Tp, _Allocator>&
12481285vector<_Tp, _Allocator>::operator=(vector&& __x)
......@@ -1254,6 +1291,7 @@ vector<_Tp, _Allocator>::operator=(vector&& __x)
12541291}
12551292
12561293template <class _Tp, class _Allocator>
1294_LIBCPP_CONSTEXPR_AFTER_CXX17
12571295void
12581296vector<_Tp, _Allocator>::__move_assign(vector& __c, false_type)
12591297 _NOEXCEPT_(__alloc_traits::is_always_equal::value)
......@@ -1268,6 +1306,7 @@ vector<_Tp, _Allocator>::__move_assign(vector& __c, false_type)
12681306}
12691307
12701308template <class _Tp, class _Allocator>
1309_LIBCPP_CONSTEXPR_AFTER_CXX17
12711310void
12721311vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type)
12731312 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
......@@ -1278,14 +1317,11 @@ vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type)
12781317 this->__end_ = __c.__end_;
12791318 this->__end_cap() = __c.__end_cap();
12801319 __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr;
1281#if _LIBCPP_DEBUG_LEVEL == 2
1282 __get_db()->swap(this, _VSTD::addressof(__c));
1283#endif
1320 std::__debug_db_swap(this, std::addressof(__c));
12841321}
12851322
1286#endif // !_LIBCPP_CXX03_LANG
1287
12881323template <class _Tp, class _Allocator>
1324_LIBCPP_CONSTEXPR_AFTER_CXX17
12891325inline _LIBCPP_INLINE_VISIBILITY
12901326vector<_Tp, _Allocator>&
12911327vector<_Tp, _Allocator>::operator=(const vector& __x)
......@@ -1300,10 +1336,7 @@ vector<_Tp, _Allocator>::operator=(const vector& __x)
13001336
13011337template <class _Tp, class _Allocator>
13021338template <class _InputIterator>
1303typename enable_if
1304<
1305 __is_cpp17_input_iterator <_InputIterator>::value &&
1306 !__is_cpp17_forward_iterator<_InputIterator>::value &&
1339_LIBCPP_CONSTEXPR_AFTER_CXX17 typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
13071340 is_constructible<
13081341 _Tp,
13091342 typename iterator_traits<_InputIterator>::reference>::value,
......@@ -1313,11 +1346,12 @@ vector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
13131346{
13141347 clear();
13151348 for (; __first != __last; ++__first)
1316 __emplace_back(*__first);
1349 emplace_back(*__first);
13171350}
13181351
13191352template <class _Tp, class _Allocator>
13201353template <class _ForwardIterator>
1354_LIBCPP_CONSTEXPR_AFTER_CXX17
13211355typename enable_if
13221356<
13231357 __is_cpp17_forward_iterator<_ForwardIterator>::value &&
......@@ -1351,10 +1385,11 @@ vector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __las
13511385 __vallocate(__recommend(__new_size));
13521386 __construct_at_end(__first, __last, __new_size);
13531387 }
1354 __invalidate_all_iterators();
1388 std::__debug_db_invalidate_all(this);
13551389}
13561390
13571391template <class _Tp, class _Allocator>
1392_LIBCPP_CONSTEXPR_AFTER_CXX17
13581393void
13591394vector<_Tp, _Allocator>::assign(size_type __n, const_reference __u)
13601395{
......@@ -1373,66 +1408,47 @@ vector<_Tp, _Allocator>::assign(size_type __n, const_reference __u)
13731408 __vallocate(__recommend(static_cast<size_type>(__n)));
13741409 __construct_at_end(__n, __u);
13751410 }
1376 __invalidate_all_iterators();
1377}
1378
1379template <class _Tp, class _Allocator>
1380inline _LIBCPP_INLINE_VISIBILITY
1381typename vector<_Tp, _Allocator>::iterator
1382vector<_Tp, _Allocator>::__make_iter(pointer __p) _NOEXCEPT
1383{
1384#if _LIBCPP_DEBUG_LEVEL == 2
1385 return iterator(this, __p);
1386#else
1387 return iterator(__p);
1388#endif
1389}
1390
1391template <class _Tp, class _Allocator>
1392inline _LIBCPP_INLINE_VISIBILITY
1393typename vector<_Tp, _Allocator>::const_iterator
1394vector<_Tp, _Allocator>::__make_iter(const_pointer __p) const _NOEXCEPT
1395{
1396#if _LIBCPP_DEBUG_LEVEL == 2
1397 return const_iterator(this, __p);
1398#else
1399 return const_iterator(__p);
1400#endif
1411 std::__debug_db_invalidate_all(this);
14011412}
14021413
14031414template <class _Tp, class _Allocator>
1415_LIBCPP_CONSTEXPR_AFTER_CXX17
14041416inline _LIBCPP_INLINE_VISIBILITY
14051417typename vector<_Tp, _Allocator>::iterator
14061418vector<_Tp, _Allocator>::begin() _NOEXCEPT
14071419{
1408 return __make_iter(this->__begin_);
1420 return iterator(this, this->__begin_);
14091421}
14101422
14111423template <class _Tp, class _Allocator>
1424_LIBCPP_CONSTEXPR_AFTER_CXX17
14121425inline _LIBCPP_INLINE_VISIBILITY
14131426typename vector<_Tp, _Allocator>::const_iterator
14141427vector<_Tp, _Allocator>::begin() const _NOEXCEPT
14151428{
1416 return __make_iter(this->__begin_);
1429 return const_iterator(this, this->__begin_);
14171430}
14181431
14191432template <class _Tp, class _Allocator>
1433_LIBCPP_CONSTEXPR_AFTER_CXX17
14201434inline _LIBCPP_INLINE_VISIBILITY
14211435typename vector<_Tp, _Allocator>::iterator
14221436vector<_Tp, _Allocator>::end() _NOEXCEPT
14231437{
1424 return __make_iter(this->__end_);
1438 return iterator(this, this->__end_);
14251439}
14261440
14271441template <class _Tp, class _Allocator>
1442_LIBCPP_CONSTEXPR_AFTER_CXX17
14281443inline _LIBCPP_INLINE_VISIBILITY
14291444typename vector<_Tp, _Allocator>::const_iterator
14301445vector<_Tp, _Allocator>::end() const _NOEXCEPT
14311446{
1432 return __make_iter(this->__end_);
1447 return const_iterator(this, this->__end_);
14331448}
14341449
14351450template <class _Tp, class _Allocator>
1451_LIBCPP_CONSTEXPR_AFTER_CXX17
14361452inline _LIBCPP_INLINE_VISIBILITY
14371453typename vector<_Tp, _Allocator>::reference
14381454vector<_Tp, _Allocator>::operator[](size_type __n) _NOEXCEPT
......@@ -1442,6 +1458,7 @@ vector<_Tp, _Allocator>::operator[](size_type __n) _NOEXCEPT
14421458}
14431459
14441460template <class _Tp, class _Allocator>
1461_LIBCPP_CONSTEXPR_AFTER_CXX17
14451462inline _LIBCPP_INLINE_VISIBILITY
14461463typename vector<_Tp, _Allocator>::const_reference
14471464vector<_Tp, _Allocator>::operator[](size_type __n) const _NOEXCEPT
......@@ -1451,6 +1468,7 @@ vector<_Tp, _Allocator>::operator[](size_type __n) const _NOEXCEPT
14511468}
14521469
14531470template <class _Tp, class _Allocator>
1471_LIBCPP_CONSTEXPR_AFTER_CXX17
14541472typename vector<_Tp, _Allocator>::reference
14551473vector<_Tp, _Allocator>::at(size_type __n)
14561474{
......@@ -1460,6 +1478,7 @@ vector<_Tp, _Allocator>::at(size_type __n)
14601478}
14611479
14621480template <class _Tp, class _Allocator>
1481_LIBCPP_CONSTEXPR_AFTER_CXX17
14631482typename vector<_Tp, _Allocator>::const_reference
14641483vector<_Tp, _Allocator>::at(size_type __n) const
14651484{
......@@ -1469,6 +1488,7 @@ vector<_Tp, _Allocator>::at(size_type __n) const
14691488}
14701489
14711490template <class _Tp, class _Allocator>
1491_LIBCPP_CONSTEXPR_AFTER_CXX17
14721492void
14731493vector<_Tp, _Allocator>::reserve(size_type __n)
14741494{
......@@ -1483,6 +1503,7 @@ vector<_Tp, _Allocator>::reserve(size_type __n)
14831503}
14841504
14851505template <class _Tp, class _Allocator>
1506_LIBCPP_CONSTEXPR_AFTER_CXX17
14861507void
14871508vector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT
14881509{
......@@ -1506,12 +1527,9 @@ vector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT
15061527
15071528template <class _Tp, class _Allocator>
15081529template <class _Up>
1530_LIBCPP_CONSTEXPR_AFTER_CXX17
15091531void
1510#ifndef _LIBCPP_CXX03_LANG
15111532vector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x)
1512#else
1513vector<_Tp, _Allocator>::__push_back_slow_path(_Up& __x)
1514#endif
15151533{
15161534 allocator_type& __a = this->__alloc();
15171535 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
......@@ -1522,6 +1540,7 @@ vector<_Tp, _Allocator>::__push_back_slow_path(_Up& __x)
15221540}
15231541
15241542template <class _Tp, class _Allocator>
1543_LIBCPP_CONSTEXPR_AFTER_CXX17
15251544inline _LIBCPP_INLINE_VISIBILITY
15261545void
15271546vector<_Tp, _Allocator>::push_back(const_reference __x)
......@@ -1534,9 +1553,8 @@ vector<_Tp, _Allocator>::push_back(const_reference __x)
15341553 __push_back_slow_path(__x);
15351554}
15361555
1537#ifndef _LIBCPP_CXX03_LANG
1538
15391556template <class _Tp, class _Allocator>
1557_LIBCPP_CONSTEXPR_AFTER_CXX17
15401558inline _LIBCPP_INLINE_VISIBILITY
15411559void
15421560vector<_Tp, _Allocator>::push_back(value_type&& __x)
......@@ -1551,6 +1569,7 @@ vector<_Tp, _Allocator>::push_back(value_type&& __x)
15511569
15521570template <class _Tp, class _Allocator>
15531571template <class... _Args>
1572_LIBCPP_CONSTEXPR_AFTER_CXX17
15541573void
15551574vector<_Tp, _Allocator>::__emplace_back_slow_path(_Args&&... __args)
15561575{
......@@ -1564,6 +1583,7 @@ vector<_Tp, _Allocator>::__emplace_back_slow_path(_Args&&... __args)
15641583
15651584template <class _Tp, class _Allocator>
15661585template <class... _Args>
1586_LIBCPP_CONSTEXPR_AFTER_CXX17
15671587inline
15681588#if _LIBCPP_STD_VER > 14
15691589typename vector<_Tp, _Allocator>::reference
......@@ -1583,9 +1603,8 @@ vector<_Tp, _Allocator>::emplace_back(_Args&&... __args)
15831603#endif
15841604}
15851605
1586#endif // !_LIBCPP_CXX03_LANG
1587
15881606template <class _Tp, class _Allocator>
1607_LIBCPP_CONSTEXPR_AFTER_CXX17
15891608inline
15901609void
15911610vector<_Tp, _Allocator>::pop_back()
......@@ -1595,6 +1614,7 @@ vector<_Tp, _Allocator>::pop_back()
15951614}
15961615
15971616template <class _Tp, class _Allocator>
1617_LIBCPP_CONSTEXPR_AFTER_CXX17
15981618inline _LIBCPP_INLINE_VISIBILITY
15991619typename vector<_Tp, _Allocator>::iterator
16001620vector<_Tp, _Allocator>::erase(const_iterator __position)
......@@ -1606,12 +1626,14 @@ vector<_Tp, _Allocator>::erase(const_iterator __position)
16061626 difference_type __ps = __position - cbegin();
16071627 pointer __p = this->__begin_ + __ps;
16081628 this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p));
1609 this->__invalidate_iterators_past(__p-1);
1610 iterator __r = __make_iter(__p);
1629 if (!__libcpp_is_constant_evaluated())
1630 this->__invalidate_iterators_past(__p - 1);
1631 iterator __r = iterator(this, __p);
16111632 return __r;
16121633}
16131634
16141635template <class _Tp, class _Allocator>
1636_LIBCPP_CONSTEXPR_AFTER_CXX17
16151637typename vector<_Tp, _Allocator>::iterator
16161638vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last)
16171639{
......@@ -1624,13 +1646,15 @@ vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last)
16241646 pointer __p = this->__begin_ + (__first - begin());
16251647 if (__first != __last) {
16261648 this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p));
1627 this->__invalidate_iterators_past(__p - 1);
1649 if (!__libcpp_is_constant_evaluated())
1650 this->__invalidate_iterators_past(__p - 1);
16281651 }
1629 iterator __r = __make_iter(__p);
1652 iterator __r = iterator(this, __p);
16301653 return __r;
16311654}
16321655
16331656template <class _Tp, class _Allocator>
1657_LIBCPP_CONSTEXPR_AFTER_CXX17
16341658void
16351659vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to)
16361660{
......@@ -1650,13 +1674,15 @@ vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointe
16501674}
16511675
16521676template <class _Tp, class _Allocator>
1677_LIBCPP_CONSTEXPR_AFTER_CXX17
16531678typename vector<_Tp, _Allocator>::iterator
16541679vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
16551680{
16561681 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this,
16571682 "vector::insert(iterator, x) called with an iterator not referring to this vector");
16581683 pointer __p = this->__begin_ + (__position - begin());
1659 if (this->__end_ < this->__end_cap())
1684 // We can't compare unrelated pointers inside constant expressions
1685 if (!__libcpp_is_constant_evaluated() && this->__end_ < this->__end_cap())
16601686 {
16611687 if (__p == this->__end_)
16621688 {
......@@ -1678,12 +1704,11 @@ vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
16781704 __v.push_back(__x);
16791705 __p = __swap_out_circular_buffer(__v, __p);
16801706 }
1681 return __make_iter(__p);
1707 return iterator(this, __p);
16821708}
16831709
1684#ifndef _LIBCPP_CXX03_LANG
1685
16861710template <class _Tp, class _Allocator>
1711_LIBCPP_CONSTEXPR_AFTER_CXX17
16871712typename vector<_Tp, _Allocator>::iterator
16881713vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x)
16891714{
......@@ -1709,11 +1734,12 @@ vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x)
17091734 __v.push_back(_VSTD::move(__x));
17101735 __p = __swap_out_circular_buffer(__v, __p);
17111736 }
1712 return __make_iter(__p);
1737 return iterator(this, __p);
17131738}
17141739
17151740template <class _Tp, class _Allocator>
17161741template <class... _Args>
1742_LIBCPP_CONSTEXPR_AFTER_CXX17
17171743typename vector<_Tp, _Allocator>::iterator
17181744vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args)
17191745{
......@@ -1740,12 +1766,11 @@ vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args)
17401766 __v.emplace_back(_VSTD::forward<_Args>(__args)...);
17411767 __p = __swap_out_circular_buffer(__v, __p);
17421768 }
1743 return __make_iter(__p);
1769 return iterator(this, __p);
17441770}
17451771
1746#endif // !_LIBCPP_CXX03_LANG
1747
17481772template <class _Tp, class _Allocator>
1773_LIBCPP_CONSTEXPR_AFTER_CXX17
17491774typename vector<_Tp, _Allocator>::iterator
17501775vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x)
17511776{
......@@ -1754,7 +1779,8 @@ vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_
17541779 pointer __p = this->__begin_ + (__position - begin());
17551780 if (__n > 0)
17561781 {
1757 if (__n <= static_cast<size_type>(this->__end_cap() - this->__end_))
1782 // We can't compare unrelated pointers inside constant expressions
1783 if (!__libcpp_is_constant_evaluated() && __n <= static_cast<size_type>(this->__end_cap() - this->__end_))
17581784 {
17591785 size_type __old_n = __n;
17601786 pointer __old_last = this->__end_;
......@@ -1781,15 +1807,12 @@ vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_
17811807 __p = __swap_out_circular_buffer(__v, __p);
17821808 }
17831809 }
1784 return __make_iter(__p);
1810 return iterator(this, __p);
17851811}
17861812
17871813template <class _Tp, class _Allocator>
17881814template <class _InputIterator>
1789typename enable_if
1790<
1791 __is_cpp17_input_iterator <_InputIterator>::value &&
1792 !__is_cpp17_forward_iterator<_InputIterator>::value &&
1815_LIBCPP_CONSTEXPR_AFTER_CXX17 typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
17931816 is_constructible<
17941817 _Tp,
17951818 typename iterator_traits<_InputIterator>::reference>::value,
......@@ -1824,19 +1847,20 @@ vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __firs
18241847 }
18251848 catch (...)
18261849 {
1827 erase(__make_iter(__old_last), end());
1850 erase(iterator(this, __old_last), end());
18281851 throw;
18291852 }
18301853#endif // _LIBCPP_NO_EXCEPTIONS
18311854 }
18321855 __p = _VSTD::rotate(__p, __old_last, this->__end_);
1833 insert(__make_iter(__p), _VSTD::make_move_iterator(__v.begin()),
1834 _VSTD::make_move_iterator(__v.end()));
1856 insert(iterator(this, __p), _VSTD::make_move_iterator(__v.begin()),
1857 _VSTD::make_move_iterator(__v.end()));
18351858 return begin() + __off;
18361859}
18371860
18381861template <class _Tp, class _Allocator>
18391862template <class _ForwardIterator>
1863_LIBCPP_CONSTEXPR_AFTER_CXX17
18401864typename enable_if
18411865<
18421866 __is_cpp17_forward_iterator<_ForwardIterator>::value &&
......@@ -1881,10 +1905,11 @@ vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __fi
18811905 __p = __swap_out_circular_buffer(__v, __p);
18821906 }
18831907 }
1884 return __make_iter(__p);
1908 return iterator(this, __p);
18851909}
18861910
18871911template <class _Tp, class _Allocator>
1912_LIBCPP_CONSTEXPR_AFTER_CXX17
18881913void
18891914vector<_Tp, _Allocator>::resize(size_type __sz)
18901915{
......@@ -1896,6 +1921,7 @@ vector<_Tp, _Allocator>::resize(size_type __sz)
18961921}
18971922
18981923template <class _Tp, class _Allocator>
1924_LIBCPP_CONSTEXPR_AFTER_CXX17
18991925void
19001926vector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x)
19011927{
......@@ -1907,6 +1933,7 @@ vector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x)
19071933}
19081934
19091935template <class _Tp, class _Allocator>
1936_LIBCPP_CONSTEXPR_AFTER_CXX17
19101937void
19111938vector<_Tp, _Allocator>::swap(vector& __x)
19121939#if _LIBCPP_STD_VER >= 14
......@@ -1925,12 +1952,11 @@ vector<_Tp, _Allocator>::swap(vector& __x)
19251952 _VSTD::swap(this->__end_cap(), __x.__end_cap());
19261953 _VSTD::__swap_allocator(this->__alloc(), __x.__alloc(),
19271954 integral_constant<bool,__alloc_traits::propagate_on_container_swap::value>());
1928#if _LIBCPP_DEBUG_LEVEL == 2
1929 __get_db()->swap(this, _VSTD::addressof(__x));
1930#endif
1955 std::__debug_db_swap(this, std::addressof(__x));
19311956}
19321957
19331958template <class _Tp, class _Allocator>
1959_LIBCPP_CONSTEXPR_AFTER_CXX17
19341960bool
19351961vector<_Tp, _Allocator>::__invariants() const
19361962{
......@@ -1951,7 +1977,7 @@ vector<_Tp, _Allocator>::__invariants() const
19511977 return true;
19521978}
19531979
1954#if _LIBCPP_DEBUG_LEVEL == 2
1980#ifdef _LIBCPP_ENABLE_DEBUG_MODE
19551981
19561982template <class _Tp, class _Allocator>
19571983bool
......@@ -1983,24 +2009,13 @@ vector<_Tp, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __
19832009 return this->__begin_ <= __p && __p < this->__end_;
19842010}
19852011
1986#endif // _LIBCPP_DEBUG_LEVEL == 2
1987
1988template <class _Tp, class _Allocator>
1989inline _LIBCPP_INLINE_VISIBILITY
1990void
1991vector<_Tp, _Allocator>::__invalidate_all_iterators()
1992{
1993#if _LIBCPP_DEBUG_LEVEL == 2
1994 __get_db()->__invalidate_all(this);
1995#endif
1996}
1997
2012#endif // _LIBCPP_ENABLE_DEBUG_MODE
19982013
19992014template <class _Tp, class _Allocator>
20002015inline _LIBCPP_INLINE_VISIBILITY
20012016void
20022017vector<_Tp, _Allocator>::__invalidate_iterators_past(pointer __new_last) {
2003#if _LIBCPP_DEBUG_LEVEL == 2
2018#ifdef _LIBCPP_ENABLE_DEBUG_MODE
20042019 __c_node* __c = __get_db()->__find_c_and_lock(this);
20052020 for (__i_node** __p = __c->end_; __p != __c->beg_; ) {
20062021 --__p;
......@@ -2058,182 +2073,181 @@ private:
20582073 __compressed_pair<size_type, __storage_allocator> __cap_alloc_;
20592074public:
20602075 typedef __bit_reference<vector> reference;
2076#ifdef _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL
2077 using const_reference = bool;
2078#else
20612079 typedef __bit_const_reference<vector> const_reference;
2080#endif
20622081private:
2063 _LIBCPP_INLINE_VISIBILITY
2082 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
20642083 size_type& __cap() _NOEXCEPT
20652084 {return __cap_alloc_.first();}
2066 _LIBCPP_INLINE_VISIBILITY
2085 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
20672086 const size_type& __cap() const _NOEXCEPT
20682087 {return __cap_alloc_.first();}
2069 _LIBCPP_INLINE_VISIBILITY
2088 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
20702089 __storage_allocator& __alloc() _NOEXCEPT
20712090 {return __cap_alloc_.second();}
2072 _LIBCPP_INLINE_VISIBILITY
2091 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
20732092 const __storage_allocator& __alloc() const _NOEXCEPT
20742093 {return __cap_alloc_.second();}
20752094
20762095 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
20772096
2078 _LIBCPP_INLINE_VISIBILITY
2097 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
20792098 static size_type __internal_cap_to_external(size_type __n) _NOEXCEPT
20802099 {return __n * __bits_per_word;}
2081 _LIBCPP_INLINE_VISIBILITY
2100 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
20822101 static size_type __external_cap_to_internal(size_type __n) _NOEXCEPT
20832102 {return (__n - 1) / __bits_per_word + 1;}
20842103
20852104public:
2086 _LIBCPP_INLINE_VISIBILITY
2105 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
20872106 vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
20882107
2089 _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
2108 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit vector(const allocator_type& __a)
20902109#if _LIBCPP_STD_VER <= 14
20912110 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
20922111#else
20932112 _NOEXCEPT;
20942113#endif
2095 ~vector();
2096 explicit vector(size_type __n);
2114 _LIBCPP_CONSTEXPR_AFTER_CXX17 ~vector();
2115 _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit vector(size_type __n);
20972116#if _LIBCPP_STD_VER > 11
2098 explicit vector(size_type __n, const allocator_type& __a);
2117 _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit vector(size_type __n, const allocator_type& __a);
20992118#endif
2100 vector(size_type __n, const value_type& __v);
2101 vector(size_type __n, const value_type& __v, const allocator_type& __a);
2119 _LIBCPP_CONSTEXPR_AFTER_CXX17 vector(size_type __n, const value_type& __v);
2120 _LIBCPP_CONSTEXPR_AFTER_CXX17 vector(size_type __n, const value_type& __v, const allocator_type& __a);
21022121 template <class _InputIterator>
2103 vector(_InputIterator __first, _InputIterator __last,
2104 typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value &&
2105 !__is_cpp17_forward_iterator<_InputIterator>::value>::type* = 0);
2122 _LIBCPP_CONSTEXPR_AFTER_CXX17 vector(_InputIterator __first, _InputIterator __last,
2123 typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value>::type* = 0);
21062124 template <class _InputIterator>
2107 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2108 typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value &&
2109 !__is_cpp17_forward_iterator<_InputIterator>::value>::type* = 0);
2125 _LIBCPP_CONSTEXPR_AFTER_CXX17 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2126 typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value>::type* = 0);
21102127 template <class _ForwardIterator>
2111 vector(_ForwardIterator __first, _ForwardIterator __last,
2128 _LIBCPP_CONSTEXPR_AFTER_CXX17 vector(_ForwardIterator __first, _ForwardIterator __last,
21122129 typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type* = 0);
21132130 template <class _ForwardIterator>
2114 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2131 _LIBCPP_CONSTEXPR_AFTER_CXX17 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
21152132 typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type* = 0);
21162133
2117 vector(const vector& __v);
2118 vector(const vector& __v, const allocator_type& __a);
2119 vector& operator=(const vector& __v);
2134 _LIBCPP_CONSTEXPR_AFTER_CXX17 vector(const vector& __v);
2135 _LIBCPP_CONSTEXPR_AFTER_CXX17 vector(const vector& __v, const allocator_type& __a);
2136 _LIBCPP_CONSTEXPR_AFTER_CXX17 vector& operator=(const vector& __v);
21202137
21212138#ifndef _LIBCPP_CXX03_LANG
2122 vector(initializer_list<value_type> __il);
2123 vector(initializer_list<value_type> __il, const allocator_type& __a);
2139 _LIBCPP_CONSTEXPR_AFTER_CXX17 vector(initializer_list<value_type> __il);
2140 _LIBCPP_CONSTEXPR_AFTER_CXX17 vector(initializer_list<value_type> __il, const allocator_type& __a);
2141
2142 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
2143 vector& operator=(initializer_list<value_type> __il)
2144 {assign(__il.begin(), __il.end()); return *this;}
2145
2146#endif // !_LIBCPP_CXX03_LANG
21242147
2125 _LIBCPP_INLINE_VISIBILITY
2148 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
21262149 vector(vector&& __v)
21272150#if _LIBCPP_STD_VER > 14
2128 _NOEXCEPT;
2151 noexcept;
21292152#else
21302153 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
21312154#endif
2132 vector(vector&& __v, const __identity_t<allocator_type>& __a);
2133 _LIBCPP_INLINE_VISIBILITY
2155 _LIBCPP_CONSTEXPR_AFTER_CXX17 vector(vector&& __v, const __type_identity_t<allocator_type>& __a);
2156 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
21342157 vector& operator=(vector&& __v)
21352158 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
21362159
2137 _LIBCPP_INLINE_VISIBILITY
2138 vector& operator=(initializer_list<value_type> __il)
2139 {assign(__il.begin(), __il.end()); return *this;}
2140
2141#endif // !_LIBCPP_CXX03_LANG
2142
21432160 template <class _InputIterator>
2144 typename enable_if
2145 <
2146 __is_cpp17_input_iterator<_InputIterator>::value &&
2147 !__is_cpp17_forward_iterator<_InputIterator>::value,
2161 typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value,
21482162 void
21492163 >::type
2150 assign(_InputIterator __first, _InputIterator __last);
2164 _LIBCPP_CONSTEXPR_AFTER_CXX17 assign(_InputIterator __first, _InputIterator __last);
21512165 template <class _ForwardIterator>
21522166 typename enable_if
21532167 <
21542168 __is_cpp17_forward_iterator<_ForwardIterator>::value,
21552169 void
21562170 >::type
2157 assign(_ForwardIterator __first, _ForwardIterator __last);
2171 _LIBCPP_CONSTEXPR_AFTER_CXX17 assign(_ForwardIterator __first, _ForwardIterator __last);
21582172
2159 void assign(size_type __n, const value_type& __x);
2173 _LIBCPP_CONSTEXPR_AFTER_CXX17 void assign(size_type __n, const value_type& __x);
21602174
21612175#ifndef _LIBCPP_CXX03_LANG
2162 _LIBCPP_INLINE_VISIBILITY
2176 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
21632177 void assign(initializer_list<value_type> __il)
21642178 {assign(__il.begin(), __il.end());}
21652179#endif
21662180
2167 _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT
2181 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 allocator_type get_allocator() const _NOEXCEPT
21682182 {return allocator_type(this->__alloc());}
21692183
2170 size_type max_size() const _NOEXCEPT;
2171 _LIBCPP_INLINE_VISIBILITY
2184 _LIBCPP_CONSTEXPR_AFTER_CXX17 size_type max_size() const _NOEXCEPT;
2185 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
21722186 size_type capacity() const _NOEXCEPT
21732187 {return __internal_cap_to_external(__cap());}
2174 _LIBCPP_INLINE_VISIBILITY
2188 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
21752189 size_type size() const _NOEXCEPT
21762190 {return __size_;}
2177 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
2191 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
21782192 bool empty() const _NOEXCEPT
21792193 {return __size_ == 0;}
2180 void reserve(size_type __n);
2181 void shrink_to_fit() _NOEXCEPT;
2194 _LIBCPP_CONSTEXPR_AFTER_CXX17 void reserve(size_type __n);
2195 _LIBCPP_CONSTEXPR_AFTER_CXX17 void shrink_to_fit() _NOEXCEPT;
21822196
2183 _LIBCPP_INLINE_VISIBILITY
2197 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
21842198 iterator begin() _NOEXCEPT
21852199 {return __make_iter(0);}
2186 _LIBCPP_INLINE_VISIBILITY
2200 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
21872201 const_iterator begin() const _NOEXCEPT
21882202 {return __make_iter(0);}
2189 _LIBCPP_INLINE_VISIBILITY
2203 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
21902204 iterator end() _NOEXCEPT
21912205 {return __make_iter(__size_);}
2192 _LIBCPP_INLINE_VISIBILITY
2206 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
21932207 const_iterator end() const _NOEXCEPT
21942208 {return __make_iter(__size_);}
21952209
2196 _LIBCPP_INLINE_VISIBILITY
2210 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
21972211 reverse_iterator rbegin() _NOEXCEPT
21982212 {return reverse_iterator(end());}
2199 _LIBCPP_INLINE_VISIBILITY
2213 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
22002214 const_reverse_iterator rbegin() const _NOEXCEPT
22012215 {return const_reverse_iterator(end());}
2202 _LIBCPP_INLINE_VISIBILITY
2216 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
22032217 reverse_iterator rend() _NOEXCEPT
22042218 {return reverse_iterator(begin());}
2205 _LIBCPP_INLINE_VISIBILITY
2219 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
22062220 const_reverse_iterator rend() const _NOEXCEPT
22072221 {return const_reverse_iterator(begin());}
22082222
2209 _LIBCPP_INLINE_VISIBILITY
2223 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
22102224 const_iterator cbegin() const _NOEXCEPT
22112225 {return __make_iter(0);}
2212 _LIBCPP_INLINE_VISIBILITY
2226 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
22132227 const_iterator cend() const _NOEXCEPT
22142228 {return __make_iter(__size_);}
2215 _LIBCPP_INLINE_VISIBILITY
2229 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
22162230 const_reverse_iterator crbegin() const _NOEXCEPT
22172231 {return rbegin();}
2218 _LIBCPP_INLINE_VISIBILITY
2232 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
22192233 const_reverse_iterator crend() const _NOEXCEPT
22202234 {return rend();}
22212235
2222 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) {return __make_ref(__n);}
2223 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const {return __make_ref(__n);}
2236 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 reference operator[](size_type __n) {return __make_ref(__n);}
2237 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 const_reference operator[](size_type __n) const {return __make_ref(__n);}
22242238 reference at(size_type __n);
22252239 const_reference at(size_type __n) const;
22262240
2227 _LIBCPP_INLINE_VISIBILITY reference front() {return __make_ref(0);}
2228 _LIBCPP_INLINE_VISIBILITY const_reference front() const {return __make_ref(0);}
2229 _LIBCPP_INLINE_VISIBILITY reference back() {return __make_ref(__size_ - 1);}
2230 _LIBCPP_INLINE_VISIBILITY const_reference back() const {return __make_ref(__size_ - 1);}
2241 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 reference front() {return __make_ref(0);}
2242 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 const_reference front() const {return __make_ref(0);}
2243 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 reference back() {return __make_ref(__size_ - 1);}
2244 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 const_reference back() const {return __make_ref(__size_ - 1);}
22312245
2232 void push_back(const value_type& __x);
2246 _LIBCPP_CONSTEXPR_AFTER_CXX17 void push_back(const value_type& __x);
22332247#if _LIBCPP_STD_VER > 11
22342248 template <class... _Args>
22352249#if _LIBCPP_STD_VER > 14
2236 _LIBCPP_INLINE_VISIBILITY reference emplace_back(_Args&&... __args)
2250 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 reference emplace_back(_Args&&... __args)
22372251#else
22382252 _LIBCPP_INLINE_VISIBILITY void emplace_back(_Args&&... __args)
22392253#endif
......@@ -2245,58 +2259,54 @@ public:
22452259 }
22462260#endif
22472261
2248 _LIBCPP_INLINE_VISIBILITY void pop_back() {--__size_;}
2262 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 void pop_back() {--__size_;}
22492263
22502264#if _LIBCPP_STD_VER > 11
22512265 template <class... _Args>
2252 _LIBCPP_INLINE_VISIBILITY iterator emplace(const_iterator position, _Args&&... __args)
2253 { return insert ( position, value_type ( _VSTD::forward<_Args>(__args)... )); }
2266 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 iterator emplace(const_iterator __position, _Args&&... __args)
2267 { return insert ( __position, value_type ( _VSTD::forward<_Args>(__args)... )); }
22542268#endif
22552269
2256 iterator insert(const_iterator __position, const value_type& __x);
2257 iterator insert(const_iterator __position, size_type __n, const value_type& __x);
2258 iterator insert(const_iterator __position, size_type __n, const_reference __x);
2270 _LIBCPP_CONSTEXPR_AFTER_CXX17 iterator insert(const_iterator __position, const value_type& __x);
2271 _LIBCPP_CONSTEXPR_AFTER_CXX17 iterator insert(const_iterator __position, size_type __n, const value_type& __x);
22592272 template <class _InputIterator>
2260 typename enable_if
2261 <
2262 __is_cpp17_input_iterator <_InputIterator>::value &&
2263 !__is_cpp17_forward_iterator<_InputIterator>::value,
2273 typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value,
22642274 iterator
22652275 >::type
2266 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
2276 _LIBCPP_CONSTEXPR_AFTER_CXX17 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
22672277 template <class _ForwardIterator>
22682278 typename enable_if
22692279 <
22702280 __is_cpp17_forward_iterator<_ForwardIterator>::value,
22712281 iterator
22722282 >::type
2273 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
2283 _LIBCPP_CONSTEXPR_AFTER_CXX17 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
22742284
22752285#ifndef _LIBCPP_CXX03_LANG
2276 _LIBCPP_INLINE_VISIBILITY
2286 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
22772287 iterator insert(const_iterator __position, initializer_list<value_type> __il)
22782288 {return insert(__position, __il.begin(), __il.end());}
22792289#endif
22802290
2281 _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
2282 iterator erase(const_iterator __first, const_iterator __last);
2291 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 iterator erase(const_iterator __position);
2292 _LIBCPP_CONSTEXPR_AFTER_CXX17 iterator erase(const_iterator __first, const_iterator __last);
22832293
2284 _LIBCPP_INLINE_VISIBILITY
2294 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
22852295 void clear() _NOEXCEPT {__size_ = 0;}
22862296
2287 void swap(vector&)
2297 _LIBCPP_CONSTEXPR_AFTER_CXX17 void swap(vector&)
22882298#if _LIBCPP_STD_VER >= 14
22892299 _NOEXCEPT;
22902300#else
22912301 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
22922302 __is_nothrow_swappable<allocator_type>::value);
22932303#endif
2294 static void swap(reference __x, reference __y) _NOEXCEPT { _VSTD::swap(__x, __y); }
2304 _LIBCPP_CONSTEXPR_AFTER_CXX17 static void swap(reference __x, reference __y) _NOEXCEPT { _VSTD::swap(__x, __y); }
22952305
2296 void resize(size_type __sz, value_type __x = false);
2297 void flip() _NOEXCEPT;
2306 _LIBCPP_CONSTEXPR_AFTER_CXX17 void resize(size_type __sz, value_type __x = false);
2307 _LIBCPP_CONSTEXPR_AFTER_CXX17 void flip() _NOEXCEPT;
22982308
2299 bool __invariants() const;
2309 _LIBCPP_CONSTEXPR_AFTER_CXX17 bool __invariants() const;
23002310
23012311private:
23022312 _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
......@@ -2309,43 +2319,63 @@ private:
23092319 _VSTD::__throw_out_of_range("vector");
23102320 }
23112321
2312 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
2313 void __vallocate(size_type __n);
2314 void __vdeallocate() _NOEXCEPT;
2315 _LIBCPP_INLINE_VISIBILITY
2322 // Allocate space for __n objects
2323 // throws length_error if __n > max_size()
2324 // throws (probably bad_alloc) if memory run out
2325 // Precondition: __begin_ == __end_ == __cap() == 0
2326 // Precondition: __n > 0
2327 // Postcondition: capacity() >= __n
2328 // Postcondition: size() == 0
2329 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 void __vallocate(size_type __n) {
2330 if (__n > max_size())
2331 __throw_length_error();
2332 auto __allocation = std::__allocate_at_least(__alloc(), __external_cap_to_internal(__n));
2333 __begin_ = __allocation.ptr;
2334 __size_ = 0;
2335 __cap() = __allocation.count;
2336 if (__libcpp_is_constant_evaluated()) {
2337 for (size_type __i = 0; __i != __cap(); ++__i)
2338 std::__construct_at(std::__to_address(__begin_) + __i);
2339 }
2340 }
2341
2342 _LIBCPP_CONSTEXPR_AFTER_CXX17 void __vdeallocate() _NOEXCEPT;
2343 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
23162344 static size_type __align_it(size_type __new_size) _NOEXCEPT
2317 {return __new_size + (__bits_per_word-1) & ~((size_type)__bits_per_word-1);}
2318 _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
2319 _LIBCPP_INLINE_VISIBILITY void __construct_at_end(size_type __n, bool __x);
2345 {return (__new_size + (__bits_per_word-1)) & ~((size_type)__bits_per_word-1);}
2346 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 size_type __recommend(size_type __new_size) const;
2347 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 void __construct_at_end(size_type __n, bool __x);
23202348 template <class _ForwardIterator>
23212349 typename enable_if
23222350 <
23232351 __is_cpp17_forward_iterator<_ForwardIterator>::value,
23242352 void
23252353 >::type
2326 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
2327 void __append(size_type __n, const_reference __x);
2328 _LIBCPP_INLINE_VISIBILITY
2354 _LIBCPP_CONSTEXPR_AFTER_CXX17 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
2355 _LIBCPP_CONSTEXPR_AFTER_CXX17 void __append(size_type __n, const_reference __x);
2356 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
23292357 reference __make_ref(size_type __pos) _NOEXCEPT
23302358 {return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
2331 _LIBCPP_INLINE_VISIBILITY
2332 const_reference __make_ref(size_type __pos) const _NOEXCEPT
2333 {return const_reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
2334 _LIBCPP_INLINE_VISIBILITY
2359 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
2360 const_reference __make_ref(size_type __pos) const _NOEXCEPT {
2361 return __bit_const_reference<vector>(__begin_ + __pos / __bits_per_word,
2362 __storage_type(1) << __pos % __bits_per_word);
2363 }
2364 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
23352365 iterator __make_iter(size_type __pos) _NOEXCEPT
23362366 {return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
2337 _LIBCPP_INLINE_VISIBILITY
2367 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
23382368 const_iterator __make_iter(size_type __pos) const _NOEXCEPT
23392369 {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
2340 _LIBCPP_INLINE_VISIBILITY
2370 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
23412371 iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT
23422372 {return begin() + (__p - cbegin());}
23432373
2344 _LIBCPP_INLINE_VISIBILITY
2374 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
23452375 void __copy_assign_alloc(const vector& __v)
23462376 {__copy_assign_alloc(__v, integral_constant<bool,
23472377 __storage_traits::propagate_on_container_copy_assignment::value>());}
2348 _LIBCPP_INLINE_VISIBILITY
2378 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
23492379 void __copy_assign_alloc(const vector& __c, true_type)
23502380 {
23512381 if (__alloc() != __c.__alloc())
......@@ -2353,33 +2383,33 @@ private:
23532383 __alloc() = __c.__alloc();
23542384 }
23552385
2356 _LIBCPP_INLINE_VISIBILITY
2386 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
23572387 void __copy_assign_alloc(const vector&, false_type)
23582388 {}
23592389
2360 void __move_assign(vector& __c, false_type);
2361 void __move_assign(vector& __c, true_type)
2390 _LIBCPP_CONSTEXPR_AFTER_CXX17 void __move_assign(vector& __c, false_type);
2391 _LIBCPP_CONSTEXPR_AFTER_CXX17 void __move_assign(vector& __c, true_type)
23622392 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
2363 _LIBCPP_INLINE_VISIBILITY
2393 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
23642394 void __move_assign_alloc(vector& __c)
23652395 _NOEXCEPT_(
23662396 !__storage_traits::propagate_on_container_move_assignment::value ||
23672397 is_nothrow_move_assignable<allocator_type>::value)
23682398 {__move_assign_alloc(__c, integral_constant<bool,
23692399 __storage_traits::propagate_on_container_move_assignment::value>());}
2370 _LIBCPP_INLINE_VISIBILITY
2400 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
23712401 void __move_assign_alloc(vector& __c, true_type)
23722402 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
23732403 {
23742404 __alloc() = _VSTD::move(__c.__alloc());
23752405 }
23762406
2377 _LIBCPP_INLINE_VISIBILITY
2407 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
23782408 void __move_assign_alloc(vector&, false_type)
23792409 _NOEXCEPT
23802410 {}
23812411
2382 size_t __hash_code() const _NOEXCEPT;
2412 _LIBCPP_CONSTEXPR_AFTER_CXX17 size_t __hash_code() const _NOEXCEPT;
23832413
23842414 friend class __bit_reference<vector>;
23852415 friend class __bit_const_reference<vector>;
......@@ -2390,45 +2420,20 @@ private:
23902420};
23912421
23922422template <class _Allocator>
2393inline _LIBCPP_INLINE_VISIBILITY
2394void
2395vector<bool, _Allocator>::__invalidate_all_iterators()
2396{
2397}
2398
2399// Allocate space for __n objects
2400// throws length_error if __n > max_size()
2401// throws (probably bad_alloc) if memory run out
2402// Precondition: __begin_ == __end_ == __cap() == 0
2403// Precondition: __n > 0
2404// Postcondition: capacity() == __n
2405// Postcondition: size() == 0
2406template <class _Allocator>
2407void
2408vector<bool, _Allocator>::__vallocate(size_type __n)
2409{
2410 if (__n > max_size())
2411 this->__throw_length_error();
2412 __n = __external_cap_to_internal(__n);
2413 this->__begin_ = __storage_traits::allocate(this->__alloc(), __n);
2414 this->__size_ = 0;
2415 this->__cap() = __n;
2416}
2417
2418template <class _Allocator>
2419void
2423_LIBCPP_CONSTEXPR_AFTER_CXX17 void
24202424vector<bool, _Allocator>::__vdeallocate() _NOEXCEPT
24212425{
24222426 if (this->__begin_ != nullptr)
24232427 {
24242428 __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap());
2425 __invalidate_all_iterators();
2429 std::__debug_db_invalidate_all(this);
24262430 this->__begin_ = nullptr;
24272431 this->__size_ = this->__cap() = 0;
24282432 }
24292433}
24302434
24312435template <class _Allocator>
2436_LIBCPP_CONSTEXPR_AFTER_CXX17
24322437typename vector<bool, _Allocator>::size_type
24332438vector<bool, _Allocator>::max_size() const _NOEXCEPT
24342439{
......@@ -2441,7 +2446,7 @@ vector<bool, _Allocator>::max_size() const _NOEXCEPT
24412446
24422447// Precondition: __new_size > capacity()
24432448template <class _Allocator>
2444inline _LIBCPP_INLINE_VISIBILITY
2449inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
24452450typename vector<bool, _Allocator>::size_type
24462451vector<bool, _Allocator>::__recommend(size_type __new_size) const
24472452{
......@@ -2459,7 +2464,7 @@ vector<bool, _Allocator>::__recommend(size_type __new_size) const
24592464// Precondition: size() + __n <= capacity()
24602465// Postcondition: size() == size() + __n
24612466template <class _Allocator>
2462inline _LIBCPP_INLINE_VISIBILITY
2467inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
24632468void
24642469vector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x)
24652470{
......@@ -2477,6 +2482,7 @@ vector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x)
24772482
24782483template <class _Allocator>
24792484template <class _ForwardIterator>
2485_LIBCPP_CONSTEXPR_AFTER_CXX17
24802486typename enable_if
24812487<
24822488 __is_cpp17_forward_iterator<_ForwardIterator>::value,
......@@ -2497,7 +2503,7 @@ vector<bool, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardI
24972503}
24982504
24992505template <class _Allocator>
2500inline _LIBCPP_INLINE_VISIBILITY
2506inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
25012507vector<bool, _Allocator>::vector()
25022508 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
25032509 : __begin_(nullptr),
......@@ -2507,7 +2513,7 @@ vector<bool, _Allocator>::vector()
25072513}
25082514
25092515template <class _Allocator>
2510inline _LIBCPP_INLINE_VISIBILITY
2516inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
25112517vector<bool, _Allocator>::vector(const allocator_type& __a)
25122518#if _LIBCPP_STD_VER <= 14
25132519 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
......@@ -2521,6 +2527,7 @@ vector<bool, _Allocator>::vector(const allocator_type& __a)
25212527}
25222528
25232529template <class _Allocator>
2530_LIBCPP_CONSTEXPR_AFTER_CXX17
25242531vector<bool, _Allocator>::vector(size_type __n)
25252532 : __begin_(nullptr),
25262533 __size_(0),
......@@ -2535,6 +2542,7 @@ vector<bool, _Allocator>::vector(size_type __n)
25352542
25362543#if _LIBCPP_STD_VER > 11
25372544template <class _Allocator>
2545_LIBCPP_CONSTEXPR_AFTER_CXX17
25382546vector<bool, _Allocator>::vector(size_type __n, const allocator_type& __a)
25392547 : __begin_(nullptr),
25402548 __size_(0),
......@@ -2549,6 +2557,7 @@ vector<bool, _Allocator>::vector(size_type __n, const allocator_type& __a)
25492557#endif
25502558
25512559template <class _Allocator>
2560_LIBCPP_CONSTEXPR_AFTER_CXX17
25522561vector<bool, _Allocator>::vector(size_type __n, const value_type& __x)
25532562 : __begin_(nullptr),
25542563 __size_(0),
......@@ -2562,6 +2571,7 @@ vector<bool, _Allocator>::vector(size_type __n, const value_type& __x)
25622571}
25632572
25642573template <class _Allocator>
2574_LIBCPP_CONSTEXPR_AFTER_CXX17
25652575vector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a)
25662576 : __begin_(nullptr),
25672577 __size_(0),
......@@ -2576,9 +2586,9 @@ vector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const all
25762586
25772587template <class _Allocator>
25782588template <class _InputIterator>
2589_LIBCPP_CONSTEXPR_AFTER_CXX17
25792590vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
2580 typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value &&
2581 !__is_cpp17_forward_iterator<_InputIterator>::value>::type*)
2591 typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value>::type*)
25822592 : __begin_(nullptr),
25832593 __size_(0),
25842594 __cap_alloc_(0, __default_init_tag())
......@@ -2595,7 +2605,7 @@ vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
25952605 {
25962606 if (__begin_ != nullptr)
25972607 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2598 __invalidate_all_iterators();
2608 std::__debug_db_invalidate_all(this);
25992609 throw;
26002610 }
26012611#endif // _LIBCPP_NO_EXCEPTIONS
......@@ -2603,9 +2613,9 @@ vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
26032613
26042614template <class _Allocator>
26052615template <class _InputIterator>
2616_LIBCPP_CONSTEXPR_AFTER_CXX17
26062617vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2607 typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value &&
2608 !__is_cpp17_forward_iterator<_InputIterator>::value>::type*)
2618 typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value>::type*)
26092619 : __begin_(nullptr),
26102620 __size_(0),
26112621 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
......@@ -2622,7 +2632,7 @@ vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
26222632 {
26232633 if (__begin_ != nullptr)
26242634 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2625 __invalidate_all_iterators();
2635 std::__debug_db_invalidate_all(this);
26262636 throw;
26272637 }
26282638#endif // _LIBCPP_NO_EXCEPTIONS
......@@ -2630,6 +2640,7 @@ vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
26302640
26312641template <class _Allocator>
26322642template <class _ForwardIterator>
2643_LIBCPP_CONSTEXPR_AFTER_CXX17
26332644vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
26342645 typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type*)
26352646 : __begin_(nullptr),
......@@ -2646,6 +2657,7 @@ vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __la
26462657
26472658template <class _Allocator>
26482659template <class _ForwardIterator>
2660_LIBCPP_CONSTEXPR_AFTER_CXX17
26492661vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
26502662 typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type*)
26512663 : __begin_(nullptr),
......@@ -2663,6 +2675,7 @@ vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __la
26632675#ifndef _LIBCPP_CXX03_LANG
26642676
26652677template <class _Allocator>
2678_LIBCPP_CONSTEXPR_AFTER_CXX17
26662679vector<bool, _Allocator>::vector(initializer_list<value_type> __il)
26672680 : __begin_(nullptr),
26682681 __size_(0),
......@@ -2677,6 +2690,7 @@ vector<bool, _Allocator>::vector(initializer_list<value_type> __il)
26772690}
26782691
26792692template <class _Allocator>
2693_LIBCPP_CONSTEXPR_AFTER_CXX17
26802694vector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
26812695 : __begin_(nullptr),
26822696 __size_(0),
......@@ -2693,14 +2707,16 @@ vector<bool, _Allocator>::vector(initializer_list<value_type> __il, const alloca
26932707#endif // _LIBCPP_CXX03_LANG
26942708
26952709template <class _Allocator>
2710_LIBCPP_CONSTEXPR_AFTER_CXX17
26962711vector<bool, _Allocator>::~vector()
26972712{
26982713 if (__begin_ != nullptr)
26992714 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2700 __invalidate_all_iterators();
2715 std::__debug_db_invalidate_all(this);
27012716}
27022717
27032718template <class _Allocator>
2719_LIBCPP_CONSTEXPR_AFTER_CXX17
27042720vector<bool, _Allocator>::vector(const vector& __v)
27052721 : __begin_(nullptr),
27062722 __size_(0),
......@@ -2714,6 +2730,7 @@ vector<bool, _Allocator>::vector(const vector& __v)
27142730}
27152731
27162732template <class _Allocator>
2733_LIBCPP_CONSTEXPR_AFTER_CXX17
27172734vector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a)
27182735 : __begin_(nullptr),
27192736 __size_(0),
......@@ -2727,6 +2744,7 @@ vector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a)
27272744}
27282745
27292746template <class _Allocator>
2747_LIBCPP_CONSTEXPR_AFTER_CXX17
27302748vector<bool, _Allocator>&
27312749vector<bool, _Allocator>::operator=(const vector& __v)
27322750{
......@@ -2747,10 +2765,8 @@ vector<bool, _Allocator>::operator=(const vector& __v)
27472765 return *this;
27482766}
27492767
2750#ifndef _LIBCPP_CXX03_LANG
2751
27522768template <class _Allocator>
2753inline _LIBCPP_INLINE_VISIBILITY vector<bool, _Allocator>::vector(vector&& __v)
2769inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 vector<bool, _Allocator>::vector(vector&& __v)
27542770#if _LIBCPP_STD_VER > 14
27552771 _NOEXCEPT
27562772#else
......@@ -2765,7 +2781,8 @@ inline _LIBCPP_INLINE_VISIBILITY vector<bool, _Allocator>::vector(vector&& __v)
27652781}
27662782
27672783template <class _Allocator>
2768vector<bool, _Allocator>::vector(vector&& __v, const __identity_t<allocator_type>& __a)
2784_LIBCPP_CONSTEXPR_AFTER_CXX17
2785vector<bool, _Allocator>::vector(vector&& __v, const __type_identity_t<allocator_type>& __a)
27692786 : __begin_(nullptr),
27702787 __size_(0),
27712788 __cap_alloc_(0, __a)
......@@ -2786,7 +2803,7 @@ vector<bool, _Allocator>::vector(vector&& __v, const __identity_t<allocator_type
27862803}
27872804
27882805template <class _Allocator>
2789inline _LIBCPP_INLINE_VISIBILITY
2806inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
27902807vector<bool, _Allocator>&
27912808vector<bool, _Allocator>::operator=(vector&& __v)
27922809 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
......@@ -2797,7 +2814,7 @@ vector<bool, _Allocator>::operator=(vector&& __v)
27972814}
27982815
27992816template <class _Allocator>
2800void
2817_LIBCPP_CONSTEXPR_AFTER_CXX17 void
28012818vector<bool, _Allocator>::__move_assign(vector& __c, false_type)
28022819{
28032820 if (__alloc() != __c.__alloc())
......@@ -2807,7 +2824,7 @@ vector<bool, _Allocator>::__move_assign(vector& __c, false_type)
28072824}
28082825
28092826template <class _Allocator>
2810void
2827_LIBCPP_CONSTEXPR_AFTER_CXX17 void
28112828vector<bool, _Allocator>::__move_assign(vector& __c, true_type)
28122829 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
28132830{
......@@ -2820,10 +2837,8 @@ vector<bool, _Allocator>::__move_assign(vector& __c, true_type)
28202837 __c.__cap() = __c.__size_ = 0;
28212838}
28222839
2823#endif // !_LIBCPP_CXX03_LANG
2824
28252840template <class _Allocator>
2826void
2841_LIBCPP_CONSTEXPR_AFTER_CXX17 void
28272842vector<bool, _Allocator>::assign(size_type __n, const value_type& __x)
28282843{
28292844 __size_ = 0;
......@@ -2841,15 +2856,12 @@ vector<bool, _Allocator>::assign(size_type __n, const value_type& __x)
28412856 }
28422857 _VSTD::fill_n(begin(), __n, __x);
28432858 }
2844 __invalidate_all_iterators();
2859 std::__debug_db_invalidate_all(this);
28452860}
28462861
28472862template <class _Allocator>
28482863template <class _InputIterator>
2849typename enable_if
2850<
2851 __is_cpp17_input_iterator<_InputIterator>::value &&
2852 !__is_cpp17_forward_iterator<_InputIterator>::value,
2864_LIBCPP_CONSTEXPR_AFTER_CXX17 typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value,
28532865 void
28542866>::type
28552867vector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
......@@ -2861,6 +2873,7 @@ vector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
28612873
28622874template <class _Allocator>
28632875template <class _ForwardIterator>
2876_LIBCPP_CONSTEXPR_AFTER_CXX17
28642877typename enable_if
28652878<
28662879 __is_cpp17_forward_iterator<_ForwardIterator>::value,
......@@ -2884,7 +2897,7 @@ vector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __la
28842897}
28852898
28862899template <class _Allocator>
2887void
2900_LIBCPP_CONSTEXPR_AFTER_CXX17 void
28882901vector<bool, _Allocator>::reserve(size_type __n)
28892902{
28902903 if (__n > capacity())
......@@ -2895,12 +2908,12 @@ vector<bool, _Allocator>::reserve(size_type __n)
28952908 __v.__vallocate(__n);
28962909 __v.__construct_at_end(this->begin(), this->end());
28972910 swap(__v);
2898 __invalidate_all_iterators();
2911 std::__debug_db_invalidate_all(this);
28992912 }
29002913}
29012914
29022915template <class _Allocator>
2903void
2916_LIBCPP_CONSTEXPR_AFTER_CXX17 void
29042917vector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT
29052918{
29062919 if (__external_cap_to_internal(size()) > __cap())
......@@ -2938,7 +2951,7 @@ vector<bool, _Allocator>::at(size_type __n) const
29382951}
29392952
29402953template <class _Allocator>
2941void
2954_LIBCPP_CONSTEXPR_AFTER_CXX17 void
29422955vector<bool, _Allocator>::push_back(const value_type& __x)
29432956{
29442957 if (this->__size_ == this->capacity())
......@@ -2948,7 +2961,7 @@ vector<bool, _Allocator>::push_back(const value_type& __x)
29482961}
29492962
29502963template <class _Allocator>
2951typename vector<bool, _Allocator>::iterator
2964_LIBCPP_CONSTEXPR_AFTER_CXX17 typename vector<bool, _Allocator>::iterator
29522965vector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x)
29532966{
29542967 iterator __r;
......@@ -2973,7 +2986,7 @@ vector<bool, _Allocator>::insert(const_iterator __position, const value_type& __
29732986}
29742987
29752988template <class _Allocator>
2976typename vector<bool, _Allocator>::iterator
2989_LIBCPP_CONSTEXPR_AFTER_CXX17 typename vector<bool, _Allocator>::iterator
29772990vector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x)
29782991{
29792992 iterator __r;
......@@ -3000,10 +3013,7 @@ vector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const
30003013
30013014template <class _Allocator>
30023015template <class _InputIterator>
3003typename enable_if
3004<
3005 __is_cpp17_input_iterator <_InputIterator>::value &&
3006 !__is_cpp17_forward_iterator<_InputIterator>::value,
3016_LIBCPP_CONSTEXPR_AFTER_CXX17 typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value,
30073017 typename vector<bool, _Allocator>::iterator
30083018>::type
30093019vector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
......@@ -3045,6 +3055,7 @@ vector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __fir
30453055
30463056template <class _Allocator>
30473057template <class _ForwardIterator>
3058_LIBCPP_CONSTEXPR_AFTER_CXX17
30483059typename enable_if
30493060<
30503061 __is_cpp17_forward_iterator<_ForwardIterator>::value,
......@@ -3078,7 +3089,7 @@ vector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __f
30783089}
30793090
30803091template <class _Allocator>
3081inline _LIBCPP_INLINE_VISIBILITY
3092inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
30823093typename vector<bool, _Allocator>::iterator
30833094vector<bool, _Allocator>::erase(const_iterator __position)
30843095{
......@@ -3089,6 +3100,7 @@ vector<bool, _Allocator>::erase(const_iterator __position)
30893100}
30903101
30913102template <class _Allocator>
3103_LIBCPP_CONSTEXPR_AFTER_CXX17
30923104typename vector<bool, _Allocator>::iterator
30933105vector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last)
30943106{
......@@ -3100,7 +3112,7 @@ vector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last)
31003112}
31013113
31023114template <class _Allocator>
3103void
3115_LIBCPP_CONSTEXPR_AFTER_CXX17 void
31043116vector<bool, _Allocator>::swap(vector& __x)
31053117#if _LIBCPP_STD_VER >= 14
31063118 _NOEXCEPT
......@@ -3117,7 +3129,7 @@ vector<bool, _Allocator>::swap(vector& __x)
31173129}
31183130
31193131template <class _Allocator>
3120void
3132_LIBCPP_CONSTEXPR_AFTER_CXX17 void
31213133vector<bool, _Allocator>::resize(size_type __sz, value_type __x)
31223134{
31233135 size_type __cs = size();
......@@ -3146,7 +3158,7 @@ vector<bool, _Allocator>::resize(size_type __sz, value_type __x)
31463158}
31473159
31483160template <class _Allocator>
3149void
3161_LIBCPP_CONSTEXPR_AFTER_CXX17 void
31503162vector<bool, _Allocator>::flip() _NOEXCEPT
31513163{
31523164 // do middle whole words
......@@ -3165,7 +3177,7 @@ vector<bool, _Allocator>::flip() _NOEXCEPT
31653177}
31663178
31673179template <class _Allocator>
3168bool
3180_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
31693181vector<bool, _Allocator>::__invariants() const
31703182{
31713183 if (this->__begin_ == nullptr)
......@@ -3184,7 +3196,7 @@ vector<bool, _Allocator>::__invariants() const
31843196}
31853197
31863198template <class _Allocator>
3187size_t
3199_LIBCPP_CONSTEXPR_AFTER_CXX17 size_t
31883200vector<bool, _Allocator>::__hash_code() const _NOEXCEPT
31893201{
31903202 size_t __h = 0;
......@@ -3204,14 +3216,15 @@ vector<bool, _Allocator>::__hash_code() const _NOEXCEPT
32043216
32053217template <class _Allocator>
32063218struct _LIBCPP_TEMPLATE_VIS hash<vector<bool, _Allocator> >
3207 : public unary_function<vector<bool, _Allocator>, size_t>
3219 : public __unary_function<vector<bool, _Allocator>, size_t>
32083220{
3209 _LIBCPP_INLINE_VISIBILITY
3221 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
32103222 size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT
32113223 {return __vec.__hash_code();}
32123224};
32133225
32143226template <class _Tp, class _Allocator>
3227_LIBCPP_CONSTEXPR_AFTER_CXX17
32153228inline _LIBCPP_INLINE_VISIBILITY
32163229bool
32173230operator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
......@@ -3221,6 +3234,7 @@ operator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __
32213234}
32223235
32233236template <class _Tp, class _Allocator>
3237_LIBCPP_CONSTEXPR_AFTER_CXX17
32243238inline _LIBCPP_INLINE_VISIBILITY
32253239bool
32263240operator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
......@@ -3229,6 +3243,7 @@ operator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __
32293243}
32303244
32313245template <class _Tp, class _Allocator>
3246_LIBCPP_CONSTEXPR_AFTER_CXX17
32323247inline _LIBCPP_INLINE_VISIBILITY
32333248bool
32343249operator< (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
......@@ -3237,6 +3252,7 @@ operator< (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __
32373252}
32383253
32393254template <class _Tp, class _Allocator>
3255_LIBCPP_CONSTEXPR_AFTER_CXX17
32403256inline _LIBCPP_INLINE_VISIBILITY
32413257bool
32423258operator> (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
......@@ -3245,6 +3261,7 @@ operator> (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __
32453261}
32463262
32473263template <class _Tp, class _Allocator>
3264_LIBCPP_CONSTEXPR_AFTER_CXX17
32483265inline _LIBCPP_INLINE_VISIBILITY
32493266bool
32503267operator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
......@@ -3253,6 +3270,7 @@ operator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __
32533270}
32543271
32553272template <class _Tp, class _Allocator>
3273_LIBCPP_CONSTEXPR_AFTER_CXX17
32563274inline _LIBCPP_INLINE_VISIBILITY
32573275bool
32583276operator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
......@@ -3261,6 +3279,7 @@ operator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __
32613279}
32623280
32633281template <class _Tp, class _Allocator>
3282_LIBCPP_CONSTEXPR_AFTER_CXX17
32643283inline _LIBCPP_INLINE_VISIBILITY
32653284void
32663285swap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y)
......@@ -3271,6 +3290,7 @@ swap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y)
32713290
32723291#if _LIBCPP_STD_VER > 17
32733292template <class _Tp, class _Allocator, class _Up>
3293_LIBCPP_CONSTEXPR_AFTER_CXX17
32743294inline _LIBCPP_INLINE_VISIBILITY typename vector<_Tp, _Allocator>::size_type
32753295erase(vector<_Tp, _Allocator>& __c, const _Up& __v) {
32763296 auto __old_size = __c.size();
......@@ -3279,14 +3299,23 @@ erase(vector<_Tp, _Allocator>& __c, const _Up& __v) {
32793299}
32803300
32813301template <class _Tp, class _Allocator, class _Predicate>
3302_LIBCPP_CONSTEXPR_AFTER_CXX17
32823303inline _LIBCPP_INLINE_VISIBILITY typename vector<_Tp, _Allocator>::size_type
32833304erase_if(vector<_Tp, _Allocator>& __c, _Predicate __pred) {
32843305 auto __old_size = __c.size();
32853306 __c.erase(_VSTD::remove_if(__c.begin(), __c.end(), __pred), __c.end());
32863307 return __old_size - __c.size();
32873308}
3309
3310template <>
3311inline constexpr bool __format::__enable_insertable<std::vector<char>> = true;
3312#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
3313template <>
3314inline constexpr bool __format::__enable_insertable<std::vector<wchar_t>> = true;
32883315#endif
32893316
3317#endif // _LIBCPP_STD_VER > 17
3318
32903319_LIBCPP_END_NAMESPACE_STD
32913320
32923321_LIBCPP_POP_MACROS
lib/libcxx/include/version+46-20
......@@ -38,6 +38,7 @@ __cpp_lib_atomic_shared_ptr 201711L <atomic>
3838__cpp_lib_atomic_value_initialization 201911L <atomic> <memory>
3939__cpp_lib_atomic_wait 201907L <atomic>
4040__cpp_lib_barrier 201907L <barrier>
41__cpp_lib_bind_back 202202L <functional>
4142__cpp_lib_bind_front 201907L <functional>
4243__cpp_lib_bit_cast 201806L <bit>
4344__cpp_lib_bitops 201907L <bit>
......@@ -46,7 +47,7 @@ __cpp_lib_bounded_array_traits 201902L <type_traits>
4647__cpp_lib_boyer_moore_searcher 201603L <functional>
4748__cpp_lib_byte 201603L <cstddef>
4849__cpp_lib_byteswap 202110L <bit>
49__cpp_lib_char8_t 201811L <atomic> <filesystem> <istream>
50__cpp_lib_char8_t 201907L <atomic> <filesystem> <istream>
5051 <limits> <locale> <ostream>
5152 <string> <string_view>
5253__cpp_lib_chrono 201611L <chrono>
......@@ -55,13 +56,14 @@ __cpp_lib_clamp 201603L <algorithm>
5556__cpp_lib_complex_udls 201309L <complex>
5657__cpp_lib_concepts 202002L <concepts>
5758__cpp_lib_constexpr_algorithms 201806L <algorithm>
59__cpp_lib_constexpr_cmath 202202L <cmath> <cstdlib>
5860__cpp_lib_constexpr_complex 201711L <complex>
5961__cpp_lib_constexpr_dynamic_alloc 201907L <memory>
6062__cpp_lib_constexpr_functional 201907L <functional>
6163__cpp_lib_constexpr_iterator 201811L <iterator>
6264__cpp_lib_constexpr_memory 201811L <memory>
6365__cpp_lib_constexpr_numeric 201911L <numeric>
64__cpp_lib_constexpr_string 201811L <string>
66__cpp_lib_constexpr_string 201907L <string>
6567__cpp_lib_constexpr_string_view 201811L <string_view>
6668__cpp_lib_constexpr_tuple 201811L <tuple>
6769__cpp_lib_constexpr_typeinfo 202106L <typeinfo>
......@@ -115,7 +117,6 @@ __cpp_lib_map_try_emplace 201411L <map>
115117__cpp_lib_math_constants 201907L <numbers>
116118__cpp_lib_math_special_functions 201603L <cmath>
117119__cpp_lib_memory_resource 201603L <memory_resource>
118__cpp_lib_monadic_optional 202110L <optional>
119120__cpp_lib_move_only_function 202110L <functional>
120121__cpp_lib_node_extract 201606L <map> <set> <unordered_map>
121122 <unordered_set>
......@@ -125,16 +126,27 @@ __cpp_lib_nonmember_container_access 201411L <array> <deque>
125126 <unordered_map> <unordered_set> <vector>
126127__cpp_lib_not_fn 201603L <functional>
127128__cpp_lib_null_iterators 201304L <iterator>
128__cpp_lib_optional 201606L <optional>
129__cpp_lib_optional 202110L <optional>
130 201606L // C++17
129131__cpp_lib_out_ptr 202106L <memory>
130132__cpp_lib_parallel_algorithm 201603L <algorithm> <numeric>
131133__cpp_lib_polymorphic_allocator 201902L <memory_resource>
132134__cpp_lib_quoted_string_io 201304L <iomanip>
133135__cpp_lib_ranges 201811L <algorithm> <functional> <iterator>
134136 <memory> <ranges>
137__cpp_lib_ranges_chunk 202202L <ranges>
138__cpp_lib_ranges_chunk_by 202202L <ranges>
139__cpp_lib_ranges_iota 202202L <numeric>
140__cpp_lib_ranges_join_with 202202L <ranges>
141__cpp_lib_ranges_slide 202202L <ranges>
135142__cpp_lib_ranges_starts_ends_with 202106L <algorithm>
143__cpp_lib_ranges_to_container 202202L <deque> <forward_list> <list>
144 <map> <priority_queue> <queue>
145 <set> <stack> <string>
146 <unordered_map> <unordered_set> <vector>
136147__cpp_lib_ranges_zip 202110L <ranges> <tuple> <utility>
137148__cpp_lib_raw_memory_algorithms 201606L <memory>
149__cpp_lib_reference_from_temporary 202202L <type_traits>
138150__cpp_lib_remove_cvref 201711L <type_traits>
139151__cpp_lib_result_of_sfinae 201210L <functional> <type_traits>
140152__cpp_lib_robust_nonmodifying_seq_ops 201304L <algorithm>
......@@ -142,7 +154,8 @@ __cpp_lib_sample 201603L <algorithm>
142154__cpp_lib_scoped_lock 201703L <mutex>
143155__cpp_lib_semaphore 201907L <semaphore>
144156__cpp_lib_shared_mutex 201505L <shared_mutex>
145__cpp_lib_shared_ptr_arrays 201611L <memory>
157__cpp_lib_shared_ptr_arrays 201707L <memory>
158 201611L // C++17
146159__cpp_lib_shared_ptr_weak_type 201606L <memory>
147160__cpp_lib_shared_timed_mutex 201402L <shared_mutex>
148161__cpp_lib_shift 201806L <algorithm>
......@@ -174,16 +187,18 @@ __cpp_lib_type_identity 201806L <type_traits>
174187__cpp_lib_type_trait_variable_templates 201510L <type_traits>
175188__cpp_lib_uncaught_exceptions 201411L <exception>
176189__cpp_lib_unordered_map_try_emplace 201411L <unordered_map>
190__cpp_lib_unreachable 202202L <utility>
177191__cpp_lib_unwrap_ref 201811L <functional>
178192__cpp_lib_variant 202102L <variant>
179193__cpp_lib_void_t 201411L <type_traits>
180194
181195*/
182196
197#include <__assert> // all public C++ headers provide the assertion handler
183198#include <__config>
184199
185200#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
186#pragma GCC system_header
201# pragma GCC system_header
187202#endif
188203
189204// clang-format off
......@@ -222,7 +237,7 @@ __cpp_lib_void_t 201411L <type_traits>
222237# define __cpp_lib_as_const 201510L
223238# define __cpp_lib_atomic_is_always_lock_free 201603L
224239# define __cpp_lib_bool_constant 201505L
225// # define __cpp_lib_boyer_moore_searcher 201603L
240# define __cpp_lib_boyer_moore_searcher 201603L
226241# define __cpp_lib_byte 201603L
227242# define __cpp_lib_chrono 201611L
228243# define __cpp_lib_clamp 201603L
......@@ -232,7 +247,9 @@ __cpp_lib_void_t 201411L <type_traits>
232247# define __cpp_lib_filesystem 201703L
233248# endif
234249# define __cpp_lib_gcd_lcm 201606L
235// # define __cpp_lib_hardware_interference_size 201703L
250# if defined(__GCC_DESTRUCTIVE_SIZE) && defined(__GCC_CONSTRUCTIVE_SIZE)
251# define __cpp_lib_hardware_interference_size 201703L
252# endif
236253# define __cpp_lib_has_unique_object_representations 201606L
237254# define __cpp_lib_hypot 201603L
238255# define __cpp_lib_incomplete_container_elements 201505L
......@@ -273,7 +290,7 @@ __cpp_lib_void_t 201411L <type_traits>
273290#if _LIBCPP_STD_VER > 17
274291# undef __cpp_lib_array_constexpr
275292# define __cpp_lib_array_constexpr 201811L
276// # define __cpp_lib_assume_aligned 201811L
293# define __cpp_lib_assume_aligned 201811L
277294# define __cpp_lib_atomic_flag_test 201907L
278295// # define __cpp_lib_atomic_float 201711L
279296# define __cpp_lib_atomic_lock_free_type_aliases 201907L
......@@ -291,7 +308,7 @@ __cpp_lib_void_t 201411L <type_traits>
291308// # define __cpp_lib_bitops 201907L
292309# define __cpp_lib_bounded_array_traits 201902L
293310# if !defined(_LIBCPP_HAS_NO_CHAR8_T)
294# define __cpp_lib_char8_t 201811L
311# define __cpp_lib_char8_t 201907L
295312# endif
296313# define __cpp_lib_concepts 202002L
297314# define __cpp_lib_constexpr_algorithms 201806L
......@@ -301,7 +318,7 @@ __cpp_lib_void_t 201411L <type_traits>
301318# define __cpp_lib_constexpr_iterator 201811L
302319# define __cpp_lib_constexpr_memory 201811L
303320# define __cpp_lib_constexpr_numeric 201911L
304# define __cpp_lib_constexpr_string 201811L
321# define __cpp_lib_constexpr_string 201907L
305322# define __cpp_lib_constexpr_string_view 201811L
306323# define __cpp_lib_constexpr_tuple 201811L
307324# define __cpp_lib_constexpr_utility 201811L
......@@ -319,9 +336,7 @@ __cpp_lib_void_t 201411L <type_traits>
319336# endif
320337# define __cpp_lib_generic_unordered_lookup 201811L
321338# define __cpp_lib_int_pow2 202002L
322# if !defined(_LIBCPP_HAS_NO_CONCEPTS)
323# define __cpp_lib_integer_comparison_functions 202002L
324# endif
339# define __cpp_lib_integer_comparison_functions 202002L
325340# define __cpp_lib_interpolate 201902L
326341# define __cpp_lib_is_constant_evaluated 201811L
327342// # define __cpp_lib_is_layout_compatible 201907L
......@@ -334,15 +349,15 @@ __cpp_lib_void_t 201411L <type_traits>
334349# define __cpp_lib_latch 201907L
335350# endif
336351# define __cpp_lib_list_remove_return_type 201806L
337# if !defined(_LIBCPP_HAS_NO_CONCEPTS)
338# define __cpp_lib_math_constants 201907L
339# endif
352# define __cpp_lib_math_constants 201907L
340353// # define __cpp_lib_polymorphic_allocator 201902L
341354// # define __cpp_lib_ranges 201811L
342355# define __cpp_lib_remove_cvref 201711L
343356# if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_semaphore)
344357# define __cpp_lib_semaphore 201907L
345358# endif
359# undef __cpp_lib_shared_ptr_arrays
360# define __cpp_lib_shared_ptr_arrays 201707L
346361# define __cpp_lib_shift 201806L
347362// # define __cpp_lib_smart_ptr_for_overwrite 202002L
348363// # define __cpp_lib_source_location 201907L
......@@ -361,23 +376,34 @@ __cpp_lib_void_t 201411L <type_traits>
361376
362377#if _LIBCPP_STD_VER > 20
363378# define __cpp_lib_adaptor_iterator_pair_constructor 202106L
364// # define __cpp_lib_allocate_at_least 202106L
379# define __cpp_lib_allocate_at_least 202106L
365380// # define __cpp_lib_associative_heterogeneous_erasure 202110L
381// # define __cpp_lib_bind_back 202202L
366382# define __cpp_lib_byteswap 202110L
383// # define __cpp_lib_constexpr_cmath 202202L
367384// # define __cpp_lib_constexpr_typeinfo 202106L
368385// # define __cpp_lib_invoke_r 202106L
369386# define __cpp_lib_is_scoped_enum 202011L
370# define __cpp_lib_monadic_optional 202110L
371387// # define __cpp_lib_move_only_function 202110L
388# undef __cpp_lib_optional
389# define __cpp_lib_optional 202110L
372390// # define __cpp_lib_out_ptr 202106L
391// # define __cpp_lib_ranges_chunk 202202L
392// # define __cpp_lib_ranges_chunk_by 202202L
393// # define __cpp_lib_ranges_iota 202202L
394// # define __cpp_lib_ranges_join_with 202202L
395// # define __cpp_lib_ranges_slide 202202L
373396// # define __cpp_lib_ranges_starts_ends_with 202106L
397// # define __cpp_lib_ranges_to_container 202202L
374398// # define __cpp_lib_ranges_zip 202110L
399// # define __cpp_lib_reference_from_temporary 202202L
375400// # define __cpp_lib_spanstream 202106L
376401// # define __cpp_lib_stacktrace 202011L
377// # define __cpp_lib_stdatomic_h 202011L
402# define __cpp_lib_stdatomic_h 202011L
378403# define __cpp_lib_string_contains 202011L
379404# define __cpp_lib_string_resize_and_overwrite 202110L
380405# define __cpp_lib_to_underlying 202102L
406# define __cpp_lib_unreachable 202202L
381407#endif
382408
383409// clang-format on
lib/libcxx/include/wchar.h+6-6
......@@ -10,7 +10,7 @@
1010#if defined(__need_wint_t) || defined(__need_mbstate_t)
1111
1212#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
13#pragma GCC system_header
13# pragma GCC system_header
1414#endif
1515
1616#include_next <wchar.h>
......@@ -113,7 +113,7 @@ size_t wcsrtombs(char* restrict dst, const wchar_t** restrict src, size_t len,
113113#endif
114114
115115#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
116#pragma GCC system_header
116# pragma GCC system_header
117117#endif
118118
119119#ifdef __cplusplus
......@@ -176,10 +176,10 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
176176
177177#if defined(__cplusplus) && (defined(_LIBCPP_MSVCRT_LIKE) || defined(__MVS__))
178178extern "C" {
179size_t mbsnrtowcs(wchar_t *__restrict dst, const char **__restrict src,
180 size_t nmc, size_t len, mbstate_t *__restrict ps);
181size_t wcsnrtombs(char *__restrict dst, const wchar_t **__restrict src,
182 size_t nwc, size_t len, mbstate_t *__restrict ps);
179size_t mbsnrtowcs(wchar_t *__restrict __dst, const char **__restrict __src,
180 size_t __nmc, size_t __len, mbstate_t *__restrict __ps);
181size_t wcsnrtombs(char *__restrict __dst, const wchar_t **__restrict __src,
182 size_t __nwc, size_t __len, mbstate_t *__restrict __ps);
183183} // extern "C"
184184#endif // __cplusplus && (_LIBCPP_MSVCRT || __MVS__)
185185
lib/libcxx/include/wctype.h+1-1
......@@ -51,7 +51,7 @@ wctrans_t wctrans(const char* property);
5151#endif
5252
5353#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
54#pragma GCC system_header
54# pragma GCC system_header
5555#endif
5656
5757// TODO:
lib/libcxx/src/algorithm.cpp+3-1
......@@ -6,10 +6,12 @@
66//
77//===----------------------------------------------------------------------===//
88
9#include "algorithm"
9#include <algorithm>
1010
1111_LIBCPP_BEGIN_NAMESPACE_STD
1212
13// TODO(varconst): this currently doesn't benefit `ranges::sort` because it uses `ranges::less` instead of `__less`.
14
1315template void __sort<__less<char>&, char*>(char*, char*, __less<char>&);
1416#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1517template void __sort<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&);
lib/libcxx/src/any.cpp+1-1
......@@ -6,7 +6,7 @@
66//
77//===----------------------------------------------------------------------===//
88
9#include "any"
9#include <any>
1010
1111namespace std {
1212const char* bad_any_cast::what() const noexcept {
lib/libcxx/src/barrier.cpp+1-1
......@@ -90,7 +90,7 @@ void __destroy_barrier_algorithm_base(__barrier_algorithm_base* __barrier)
9090 delete __barrier;
9191}
9292
93#endif //!defined(_LIBCPP_HAS_NO_TREE_BARRIER)
93#endif // !defined(_LIBCPP_HAS_NO_TREE_BARRIER)
9494
9595_LIBCPP_END_NAMESPACE_STD
9696
lib/libcxx/src/bind.cpp+1-1
......@@ -6,7 +6,7 @@
66//
77//===----------------------------------------------------------------------===//
88
9#include "functional"
9#include <functional>
1010
1111_LIBCPP_BEGIN_NAMESPACE_STD
1212
lib/libcxx/src/charconv.cpp+9-119
......@@ -6,144 +6,34 @@
66//
77//===----------------------------------------------------------------------===//
88
9#include "charconv"
9#include <charconv>
1010#include <string.h>
1111
12#include "include/ryu/digit_table.h"
1312#include "include/to_chars_floating_point.h"
1413
1514_LIBCPP_BEGIN_NAMESPACE_STD
1615
17namespace __itoa
18{
19
20template <typename T>
21inline _LIBCPP_INLINE_VISIBILITY char*
22append1(char* buffer, T i) noexcept
23{
24 *buffer = '0' + static_cast<char>(i);
25 return buffer + 1;
26}
27
28template <typename T>
29inline _LIBCPP_INLINE_VISIBILITY char*
30append2(char* buffer, T i) noexcept
31{
32 memcpy(buffer, &__DIGIT_TABLE[(i)*2], 2);
33 return buffer + 2;
34}
35
36template <typename T>
37inline _LIBCPP_INLINE_VISIBILITY char*
38append3(char* buffer, T i) noexcept
39{
40 return append2(append1(buffer, (i) / 100), (i) % 100);
41}
16#ifndef _LIBCPP_ABI_DO_NOT_EXPORT_TO_CHARS_BASE_10
4217
43template <typename T>
44inline _LIBCPP_INLINE_VISIBILITY char*
45append4(char* buffer, T i) noexcept
46{
47 return append2(append2(buffer, (i) / 100), (i) % 100);
48}
49
50template <typename T>
51inline _LIBCPP_INLINE_VISIBILITY char*
52append2_no_zeros(char* buffer, T v) noexcept
53{
54 if (v < 10)
55 return append1(buffer, v);
56 else
57 return append2(buffer, v);
58}
59
60template <typename T>
61inline _LIBCPP_INLINE_VISIBILITY char*
62append4_no_zeros(char* buffer, T v) noexcept
63{
64 if (v < 100)
65 return append2_no_zeros(buffer, v);
66 else if (v < 1000)
67 return append3(buffer, v);
68 else
69 return append4(buffer, v);
70}
71
72template <typename T>
73inline _LIBCPP_INLINE_VISIBILITY char*
74append8_no_zeros(char* buffer, T v) noexcept
18namespace __itoa
7519{
76 if (v < 10000)
77 {
78 buffer = append4_no_zeros(buffer, v);
79 }
80 else
81 {
82 buffer = append4_no_zeros(buffer, v / 10000);
83 buffer = append4(buffer, v % 10000);
84 }
85 return buffer;
86}
8720
88char*
21_LIBCPP_FUNC_VIS char*
8922__u32toa(uint32_t value, char* buffer) noexcept
9023{
91 if (value < 100000000)
92 {
93 buffer = append8_no_zeros(buffer, value);
94 }
95 else
96 {
97 // value = aabbbbcccc in decimal
98 const uint32_t a = value / 100000000; // 1 to 42
99 value %= 100000000;
100
101 buffer = append2_no_zeros(buffer, a);
102 buffer = append4(buffer, value / 10000);
103 buffer = append4(buffer, value % 10000);
104 }
105
106 return buffer;
24 return __base_10_u32(buffer, value);
10725}
10826
109char*
27_LIBCPP_FUNC_VIS char*
11028__u64toa(uint64_t value, char* buffer) noexcept
11129{
112 if (value < 100000000)
113 {
114 uint32_t v = static_cast<uint32_t>(value);
115 buffer = append8_no_zeros(buffer, v);
116 }
117 else if (value < 10000000000000000)
118 {
119 const uint32_t v0 = static_cast<uint32_t>(value / 100000000);
120 const uint32_t v1 = static_cast<uint32_t>(value % 100000000);
121
122 buffer = append8_no_zeros(buffer, v0);
123 buffer = append4(buffer, v1 / 10000);
124 buffer = append4(buffer, v1 % 10000);
125 }
126 else
127 {
128 const uint32_t a =
129 static_cast<uint32_t>(value / 10000000000000000); // 1 to 1844
130 value %= 10000000000000000;
131
132 buffer = append4_no_zeros(buffer, a);
133
134 const uint32_t v0 = static_cast<uint32_t>(value / 100000000);
135 const uint32_t v1 = static_cast<uint32_t>(value % 100000000);
136 buffer = append4(buffer, v0 / 10000);
137 buffer = append4(buffer, v0 % 10000);
138 buffer = append4(buffer, v1 / 10000);
139 buffer = append4(buffer, v1 % 10000);
140 }
141
142 return buffer;
30 return __base_10_u64(buffer, value);
14331}
14432
14533} // namespace __itoa
14634
35#endif // _LIBCPP_ABI_DO_NOT_EXPORT_TO_CHARS_BASE_10
36
14737// The original version of floating-point to_chars was written by Microsoft and
14838// contributed with the following license.
14939
lib/libcxx/src/chrono.cpp+3-3
......@@ -12,9 +12,9 @@
1212#define _LARGE_TIME_API
1313#endif
1414
15#include "chrono"
16#include "cerrno" // errno
17#include "system_error" // __throw_system_error
15#include <cerrno> // errno
16#include <chrono>
17#include <system_error> // __throw_system_error
1818
1919#if defined(__MVS__)
2020#include <__support/ibm/gettod_zos.h> // gettimeofdayMonotonic
lib/libcxx/src/condition_variable.cpp+10-6
......@@ -6,19 +6,21 @@
66//
77//===----------------------------------------------------------------------===//
88
9#include "__config"
9#include <__config>
1010
1111#ifndef _LIBCPP_HAS_NO_THREADS
1212
13#include "condition_variable"
14#include "thread"
15#include "system_error"
16#include "__undef_macros"
13#include <condition_variable>
14#include <thread>
15#include <system_error>
1716
1817#if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
19#pragma comment(lib, "pthread")
18# pragma comment(lib, "pthread")
2019#endif
2120
21_LIBCPP_PUSH_MACROS
22#include <__undef_macros>
23
2224_LIBCPP_BEGIN_NAMESPACE_STD
2325
2426// ~condition_variable is defined elsewhere.
......@@ -90,4 +92,6 @@ notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk)
9092
9193_LIBCPP_END_NAMESPACE_STD
9294
95_LIBCPP_POP_MACROS
96
9397#endif // !_LIBCPP_HAS_NO_THREADS
lib/libcxx/src/condition_variable_destructor.cpp+2-2
......@@ -11,8 +11,8 @@
1111// On some platforms ~condition_variable has been made trivial and the
1212// definition is only provided for ABI compatibility.
1313
14#include "__config"
15#include "__threading_support"
14#include <__config>
15#include <__threading_support>
1616
1717#if !defined(_LIBCPP_HAS_NO_THREADS)
1818# if _LIBCPP_ABI_VERSION == 1 || !defined(_LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION)
lib/libcxx/src/debug.cpp+13-32
......@@ -6,43 +6,24 @@
66//
77//===----------------------------------------------------------------------===//
88
9#include "__config"
10#include "__debug"
11#include "functional"
12#include "algorithm"
13#include "string"
14#include "cstdio"
15#include "__hash_table"
9#include <__assert>
10#include <__config>
11#include <__debug>
12#include <__hash_table>
13#include <algorithm>
14#include <cstdio>
15#include <functional>
16#include <string>
17
1618#ifndef _LIBCPP_HAS_NO_THREADS
17#include "mutex"
18#if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
19#pragma comment(lib, "pthread")
20#endif
19# include <mutex>
20# if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
21# pragma comment(lib, "pthread")
22# endif
2123#endif
2224
2325_LIBCPP_BEGIN_NAMESPACE_STD
2426
25std::string __libcpp_debug_info::what() const {
26 string msg = __file_;
27 msg += ":" + to_string(__line_) + ": _LIBCPP_ASSERT '";
28 msg += __pred_;
29 msg += "' failed. ";
30 msg += __msg_;
31 return msg;
32}
33_LIBCPP_NORETURN void __libcpp_abort_debug_function(__libcpp_debug_info const& info) {
34 std::fprintf(stderr, "%s\n", info.what().c_str());
35 std::abort();
36}
37
38_LIBCPP_SAFE_STATIC __libcpp_debug_function_type
39 __libcpp_debug_function = __libcpp_abort_debug_function;
40
41bool __libcpp_set_debug_function(__libcpp_debug_function_type __func) {
42 __libcpp_debug_function = __func;
43 return true;
44}
45
4627_LIBCPP_FUNC_VIS
4728__libcpp_db*
4829__get_db()
lib/libcxx/src/exception.cpp+3-3
......@@ -6,9 +6,9 @@
66//
77//===----------------------------------------------------------------------===//
88
9#include "exception"
10#include "new"
11#include "typeinfo"
9#include <exception>
10#include <new>
11#include <typeinfo>
1212
1313#if defined(LIBCXXRT) || defined(LIBCXX_BUILDING_LIBCXXABI)
1414 #include <cxxabi.h>
lib/libcxx/src/experimental/memory_resource.cpp+9-9
......@@ -6,15 +6,15 @@
66//
77//===----------------------------------------------------------------------===//
88
9#include "experimental/memory_resource"
9#include <experimental/memory_resource>
1010
1111#ifndef _LIBCPP_HAS_NO_ATOMIC_HEADER
12#include "atomic"
12# include <atomic>
1313#elif !defined(_LIBCPP_HAS_NO_THREADS)
14#include "mutex"
15#if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
16#pragma comment(lib, "pthread")
17#endif
14# include <mutex>
15# if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
16# pragma comment(lib, "pthread")
17# endif
1818#endif
1919
2020_LIBCPP_BEGIN_NAMESPACE_LFTS_PMR
......@@ -97,7 +97,7 @@ static memory_resource *
9797__default_memory_resource(bool set = false, memory_resource * new_res = nullptr) noexcept
9898{
9999#ifndef _LIBCPP_HAS_NO_ATOMIC_HEADER
100 _LIBCPP_SAFE_STATIC static atomic<memory_resource*> __res{&res_init.resources.new_delete_res};
100 static constinit atomic<memory_resource*> __res{&res_init.resources.new_delete_res};
101101 if (set) {
102102 new_res = new_res ? new_res : new_delete_resource();
103103 // TODO: Can a weaker ordering be used?
......@@ -109,7 +109,7 @@ __default_memory_resource(bool set = false, memory_resource * new_res = nullptr)
109109 &__res, memory_order_acquire);
110110 }
111111#elif !defined(_LIBCPP_HAS_NO_THREADS)
112 _LIBCPP_SAFE_STATIC static memory_resource * res = &res_init.resources.new_delete_res;
112 static constinit memory_resource *res = &res_init.resources.new_delete_res;
113113 static mutex res_lock;
114114 if (set) {
115115 new_res = new_res ? new_res : new_delete_resource();
......@@ -122,7 +122,7 @@ __default_memory_resource(bool set = false, memory_resource * new_res = nullptr)
122122 return res;
123123 }
124124#else
125 _LIBCPP_SAFE_STATIC static memory_resource* res = &res_init.resources.new_delete_res;
125 static constinit memory_resource *res = &res_init.resources.new_delete_res;
126126 if (set) {
127127 new_res = new_res ? new_res : new_delete_resource();
128128 memory_resource * old_res = res;
lib/libcxx/src/experimental/memory_resource_init_helper.h+1-1
......@@ -1,2 +1,2 @@
11#pragma GCC system_header
2_LIBCPP_SAFE_STATIC ResourceInitHelper res_init _LIBCPP_INIT_PRIORITY_MAX;
2static constinit ResourceInitHelper res_init _LIBCPP_INIT_PRIORITY_MAX;
lib/libcxx/src/filesystem/directory_iterator.cpp+13-12
......@@ -6,10 +6,11 @@
66//
77//===----------------------------------------------------------------------===//
88
9#include "__config"
10#include "filesystem"
11#include "stack"
9#include <__assert>
10#include <__config>
1211#include <errno.h>
12#include <filesystem>
13#include <stack>
1314
1415#include "filesystem_common.h"
1516
......@@ -24,8 +25,8 @@ public:
2425 __dir_stream& operator=(const __dir_stream&) = delete;
2526
2627 __dir_stream(__dir_stream&& __ds) noexcept : __stream_(__ds.__stream_),
27 __root_(move(__ds.__root_)),
28 __entry_(move(__ds.__entry_)) {
28 __root_(std::move(__ds.__root_)),
29 __entry_(std::move(__ds.__entry_)) {
2930 __ds.__stream_ = INVALID_HANDLE_VALUE;
3031 }
3132
......@@ -103,8 +104,8 @@ public:
103104 __dir_stream& operator=(const __dir_stream&) = delete;
104105
105106 __dir_stream(__dir_stream&& other) noexcept : __stream_(other.__stream_),
106 __root_(move(other.__root_)),
107 __entry_(move(other.__entry_)) {
107 __root_(std::move(other.__root_)),
108 __entry_(std::move(other.__entry_)) {
108109 other.__stream_ = nullptr;
109110 }
110111
......@@ -186,7 +187,7 @@ directory_iterator& directory_iterator::__increment(error_code* ec) {
186187
187188 error_code m_ec;
188189 if (!__imp_->advance(m_ec)) {
189 path root = move(__imp_->__root_);
190 path root = std::move(__imp_->__root_);
190191 __imp_.reset();
191192 if (m_ec)
192193 err.report(m_ec, "at root " PATH_CSTR_FMT, root.c_str());
......@@ -220,7 +221,7 @@ recursive_directory_iterator::recursive_directory_iterator(
220221
221222 __imp_ = make_shared<__shared_imp>();
222223 __imp_->__options_ = opt;
223 __imp_->__stack_.push(move(new_s));
224 __imp_->__stack_.push(std::move(new_s));
224225}
225226
226227void recursive_directory_iterator::__pop(error_code* ec) {
......@@ -274,7 +275,7 @@ void recursive_directory_iterator::__advance(error_code* ec) {
274275 }
275276
276277 if (m_ec) {
277 path root = move(stack.top().__root_);
278 path root = std::move(stack.top().__root_);
278279 __imp_.reset();
279280 err.report(m_ec, "at root " PATH_CSTR_FMT, root.c_str());
280281 } else {
......@@ -308,7 +309,7 @@ bool recursive_directory_iterator::__try_recursion(error_code* ec) {
308309 if (!skip_rec) {
309310 __dir_stream new_it(curr_it.__entry_.path(), __imp_->__options_, m_ec);
310311 if (new_it.good()) {
311 __imp_->__stack_.push(move(new_it));
312 __imp_->__stack_.push(std::move(new_it));
312313 return true;
313314 }
314315 }
......@@ -319,7 +320,7 @@ bool recursive_directory_iterator::__try_recursion(error_code* ec) {
319320 if (ec)
320321 ec->clear();
321322 } else {
322 path at_ent = move(curr_it.__entry_.__p_);
323 path at_ent = std::move(curr_it.__entry_.__p_);
323324 __imp_.reset();
324325 err.report(m_ec, "attempting recursion into " PATH_CSTR_FMT,
325326 at_ent.c_str());
lib/libcxx/src/filesystem/filesystem_common.h+25-25
......@@ -9,31 +9,30 @@
99#ifndef FILESYSTEM_COMMON_H
1010#define FILESYSTEM_COMMON_H
1111
12#include "__config"
13#include "array"
14#include "chrono"
15#include "climits"
16#include "cstdarg"
17#include "cstdlib"
18#include "ctime"
19#include "filesystem"
20#include "ratio"
21#include "system_error"
12#include <__assert>
13#include <__config>
14#include <array>
15#include <chrono>
16#include <climits>
17#include <cstdarg>
18#include <ctime>
19#include <filesystem>
20#include <ratio>
21#include <system_error>
22#include <utility>
2223
2324#if defined(_LIBCPP_WIN32API)
2425# define WIN32_LEAN_AND_MEAN
2526# define NOMINMAX
2627# include <windows.h>
27#endif
28
29#if !defined(_LIBCPP_WIN32API)
28#else
3029# include <dirent.h> // for DIR & friends
3130# include <fcntl.h> /* values for fchmodat */
3231# include <sys/stat.h>
3332# include <sys/statvfs.h>
3433# include <sys/time.h> // for ::utimes as used in __last_write_time
3534# include <unistd.h>
36#endif
35#endif // defined(_LIBCPP_WIN32API)
3736
3837#include "../include/apple_availability.h"
3938
......@@ -45,17 +44,16 @@
4544#endif
4645#endif
4746
48#if defined(__GNUC__) || defined(__clang__)
49#pragma GCC diagnostic push
50#pragma GCC diagnostic ignored "-Wunused-function"
51#endif
47_LIBCPP_DIAGNOSTIC_PUSH
48_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wunused-function")
49_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wunused-function")
5250
5351#if defined(_LIBCPP_WIN32API)
54#define PS(x) (L##x)
55#define PATH_CSTR_FMT "\"%ls\""
52# define PATHSTR(x) (L##x)
53# define PATH_CSTR_FMT "\"%ls\""
5654#else
57#define PS(x) (x)
58#define PATH_CSTR_FMT "\"%s\""
55# define PATHSTR(x) (x)
56# define PATH_CSTR_FMT "\"%s\""
5957#endif
6058
6159_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
......@@ -113,7 +111,7 @@ format_string(const char* msg, ...) {
113111}
114112
115113error_code capture_errno() {
116 _LIBCPP_ASSERT(errno, "Expected errno to be non-zero");
114 _LIBCPP_ASSERT(errno != 0, "Expected errno to be non-zero");
117115 return error_code(errno, generic_category());
118116}
119117
......@@ -178,7 +176,7 @@ struct ErrorHandler {
178176 case 2:
179177 __throw_filesystem_error(what, *p1_, *p2_, ec);
180178 }
181 _LIBCPP_UNREACHABLE();
179 __libcpp_unreachable();
182180 }
183181
184182 _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 3, 0)
......@@ -197,7 +195,7 @@ struct ErrorHandler {
197195 case 2:
198196 __throw_filesystem_error(what, *p1_, *p2_, ec);
199197 }
200 _LIBCPP_UNREACHABLE();
198 __libcpp_unreachable();
201199 }
202200
203201 _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 3, 4)
......@@ -610,4 +608,6 @@ static file_time_type get_write_time(const WIN32_FIND_DATAW& data) {
610608
611609_LIBCPP_END_NAMESPACE_FILESYSTEM
612610
611_LIBCPP_DIAGNOSTIC_POP
612
613613#endif // FILESYSTEM_COMMON_H
lib/libcxx/src/filesystem/int128_builtins.cpp+2-2
......@@ -13,8 +13,8 @@
1313 *
1414 * ===----------------------------------------------------------------------===
1515 */
16#include "__config"
17#include "climits"
16#include <__config>
17#include <climits>
1818
1919#if !defined(_LIBCPP_HAS_NO_INT128)
2020
lib/libcxx/src/filesystem/operations.cpp+40-38
......@@ -6,14 +6,16 @@
66//
77//===----------------------------------------------------------------------===//
88
9#include "filesystem"
10#include "array"
11#include "iterator"
12#include "string_view"
13#include "type_traits"
14#include "vector"
15#include "cstdlib"
16#include "climits"
9#include <__assert>
10#include <__utility/unreachable.h>
11#include <array>
12#include <climits>
13#include <cstdlib>
14#include <filesystem>
15#include <iterator>
16#include <string_view>
17#include <type_traits>
18#include <vector>
1719
1820#include "filesystem_common.h"
1921
......@@ -39,7 +41,7 @@
3941# include <copyfile.h>
4042# define _LIBCPP_FILESYSTEM_USE_COPYFILE
4143#else
42# include "fstream"
44# include <fstream>
4345# define _LIBCPP_FILESYSTEM_USE_FSTREAM
4446#endif
4547
......@@ -154,7 +156,7 @@ public:
154156 return makeState(PS_AtEnd);
155157
156158 case PS_AtEnd:
157 _LIBCPP_UNREACHABLE();
159 __libcpp_unreachable();
158160 }
159161 }
160162
......@@ -202,7 +204,7 @@ public:
202204 return makeState(PS_InRootName, Path.data(), RStart + 1);
203205 case PS_InRootName:
204206 case PS_BeforeBegin:
205 _LIBCPP_UNREACHABLE();
207 __libcpp_unreachable();
206208 }
207209 }
208210
......@@ -212,19 +214,19 @@ public:
212214 switch (State) {
213215 case PS_BeforeBegin:
214216 case PS_AtEnd:
215 return PS("");
217 return PATHSTR("");
216218 case PS_InRootDir:
217219 if (RawEntry[0] == '\\')
218 return PS("\\");
220 return PATHSTR("\\");
219221 else
220 return PS("/");
222 return PATHSTR("/");
221223 case PS_InTrailingSep:
222 return PS("");
224 return PATHSTR("");
223225 case PS_InRootName:
224226 case PS_InFilenames:
225227 return RawEntry;
226228 }
227 _LIBCPP_UNREACHABLE();
229 __libcpp_unreachable();
228230 }
229231
230232 explicit operator bool() const noexcept {
......@@ -285,7 +287,7 @@ private:
285287 case PS_AtEnd:
286288 return getAfterBack();
287289 }
288 _LIBCPP_UNREACHABLE();
290 __libcpp_unreachable();
289291 }
290292
291293 /// \brief Return a pointer to the first character in the currently lexed
......@@ -302,7 +304,7 @@ private:
302304 case PS_AtEnd:
303305 return &Path.back() + 1;
304306 }
305 _LIBCPP_UNREACHABLE();
307 __libcpp_unreachable();
306308 }
307309
308310 // Consume all consecutive separators.
......@@ -385,8 +387,8 @@ private:
385387};
386388
387389string_view_pair separate_filename(string_view_t const& s) {
388 if (s == PS(".") || s == PS("..") || s.empty())
389 return string_view_pair{s, PS("")};
390 if (s == PATHSTR(".") || s == PATHSTR("..") || s.empty())
391 return string_view_pair{s, PATHSTR("")};
390392 auto pos = s.find_last_of('.');
391393 if (pos == string_view_t::npos || pos == 0)
392394 return string_view_pair{s, string_view_t{}};
......@@ -681,7 +683,7 @@ void filesystem_error::__create_what(int __num_paths) {
681683 return detail::format_string("filesystem error: %s [" PATH_CSTR_FMT "] [" PATH_CSTR_FMT "]",
682684 derived_what, path1().c_str(), path2().c_str());
683685 }
684 _LIBCPP_UNREACHABLE();
686 __libcpp_unreachable();
685687 }();
686688}
687689
......@@ -1188,7 +1190,7 @@ bool __fs_is_empty(const path& p, error_code* ec) {
11881190 } else if (is_regular_file(st))
11891191 return static_cast<uintmax_t>(pst.st_size) == 0;
11901192
1191 _LIBCPP_UNREACHABLE();
1193 __libcpp_unreachable();
11921194}
11931195
11941196static file_time_type __extract_last_write_time(const path& p, const StatT& st,
......@@ -1614,7 +1616,7 @@ path& path::replace_extension(path const& replacement) {
16141616 }
16151617 if (!replacement.empty()) {
16161618 if (replacement.native()[0] != '.') {
1617 __pn_ += PS(".");
1619 __pn_ += PATHSTR(".");
16181620 }
16191621 __pn_.append(replacement.__pn_);
16201622 }
......@@ -1736,14 +1738,14 @@ enum PathPartKind : unsigned char {
17361738static PathPartKind ClassifyPathPart(string_view_t Part) {
17371739 if (Part.empty())
17381740 return PK_TrailingSep;
1739 if (Part == PS("."))
1741 if (Part == PATHSTR("."))
17401742 return PK_Dot;
1741 if (Part == PS(".."))
1743 if (Part == PATHSTR(".."))
17421744 return PK_DotDot;
1743 if (Part == PS("/"))
1745 if (Part == PATHSTR("/"))
17441746 return PK_RootSep;
17451747#if defined(_LIBCPP_WIN32API)
1746 if (Part == PS("\\"))
1748 if (Part == PATHSTR("\\"))
17471749 return PK_RootSep;
17481750#endif
17491751 return PK_Filename;
......@@ -1793,7 +1795,7 @@ path path::lexically_normal() const {
17931795 NewPathSize -= Parts.back().first.size();
17941796 Parts.pop_back();
17951797 } else if (LastKind != PK_RootSep)
1796 AddPart(PK_DotDot, PS(".."));
1798 AddPart(PK_DotDot, PATHSTR(".."));
17971799 MaybeNeedTrailingSep = LastKind == PK_Filename;
17981800 break;
17991801 }
......@@ -1803,12 +1805,12 @@ path path::lexically_normal() const {
18031805 break;
18041806 }
18051807 case PK_None:
1806 _LIBCPP_UNREACHABLE();
1808 __libcpp_unreachable();
18071809 }
18081810 }
18091811 // [fs.path.generic]p6.8: If the path is empty, add a dot.
18101812 if (Parts.empty())
1811 return PS(".");
1813 return PATHSTR(".");
18121814
18131815 // [fs.path.generic]p6.7: If the last filename is dot-dot, remove any
18141816 // trailing directory-separator.
......@@ -1820,7 +1822,7 @@ path path::lexically_normal() const {
18201822 Result /= PK.first;
18211823
18221824 if (NeedTrailingSep)
1823 Result /= PS("");
1825 Result /= PATHSTR("");
18241826
18251827 Result.make_preferred();
18261828 return Result;
......@@ -1830,9 +1832,9 @@ static int DetermineLexicalElementCount(PathParser PP) {
18301832 int Count = 0;
18311833 for (; PP; ++PP) {
18321834 auto Elem = *PP;
1833 if (Elem == PS(".."))
1835 if (Elem == PATHSTR(".."))
18341836 --Count;
1835 else if (Elem != PS(".") && Elem != PS(""))
1837 else if (Elem != PATHSTR(".") && Elem != PATHSTR(""))
18361838 ++Count;
18371839 }
18381840 return Count;
......@@ -1879,15 +1881,15 @@ path path::lexically_relative(const path& base) const {
18791881 return {};
18801882
18811883 // if n == 0 and (a == end() || a->empty()), returns path("."); otherwise
1882 if (ElemCount == 0 && (PP.atEnd() || *PP == PS("")))
1883 return PS(".");
1884 if (ElemCount == 0 && (PP.atEnd() || *PP == PATHSTR("")))
1885 return PATHSTR(".");
18841886
1885 // return a path constructed with 'n' dot-dot elements, followed by the the
1887 // return a path constructed with 'n' dot-dot elements, followed by the
18861888 // elements of '*this' after the mismatch.
18871889 path Result;
18881890 // FIXME: Reserve enough room in Result that it won't have to re-allocate.
18891891 while (ElemCount--)
1890 Result /= PS("..");
1892 Result /= PATHSTR("..");
18911893 for (; PP; ++PP)
18921894 Result /= *PP;
18931895 return Result;
......@@ -1900,7 +1902,7 @@ static int CompareRootName(PathParser *LHS, PathParser *RHS) {
19001902 return 0;
19011903
19021904 auto GetRootName = [](PathParser *Parser) -> string_view_t {
1903 return Parser->inRootName() ? **Parser : PS("");
1905 return Parser->inRootName() ? **Parser : PATHSTR("");
19041906 };
19051907 int res = GetRootName(LHS).compare(GetRootName(RHS));
19061908 ConsumeRootName(LHS);
lib/libcxx/src/filesystem/posix_compat.h+2-1
......@@ -23,7 +23,8 @@
2323#ifndef POSIX_COMPAT_H
2424#define POSIX_COMPAT_H
2525
26#include "filesystem"
26#include <__assert>
27#include <filesystem>
2728
2829#include "filesystem_common.h"
2930
lib/libcxx/src/format.cpp+1-1
......@@ -6,7 +6,7 @@
66//
77//===----------------------------------------------------------------------===//
88
9#include "format"
9#include <format>
1010
1111_LIBCPP_BEGIN_NAMESPACE_STD
1212
lib/libcxx/src/functional.cpp+1-1
......@@ -6,7 +6,7 @@
66//
77//===----------------------------------------------------------------------===//
88
9#include "functional"
9#include <functional>
1010
1111_LIBCPP_BEGIN_NAMESPACE_STD
1212
lib/libcxx/src/future.cpp+7-15
......@@ -6,12 +6,12 @@
66//
77//===----------------------------------------------------------------------===//
88
9#include "__config"
9#include <__config>
1010
1111#ifndef _LIBCPP_HAS_NO_THREADS
1212
13#include "future"
14#include "string"
13#include <future>
14#include <string>
1515
1616_LIBCPP_BEGIN_NAMESPACE_STD
1717
......@@ -29,13 +29,9 @@ __future_error_category::name() const noexcept
2929 return "future";
3030}
3131
32#if defined(__clang__)
33#pragma clang diagnostic push
34#pragma clang diagnostic ignored "-Wswitch"
35#elif defined(__GNUC__) || defined(__GNUG__)
36#pragma GCC diagnostic push
37#pragma GCC diagnostic ignored "-Wswitch"
38#endif
32_LIBCPP_DIAGNOSTIC_PUSH
33_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wswitch")
34_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wswitch")
3935
4036string
4137__future_error_category::message(int ev) const
......@@ -58,11 +54,7 @@ __future_error_category::message(int ev) const
5854 return string("unspecified future_errc value\n");
5955}
6056
61#if defined(__clang__)
62#pragma clang diagnostic pop
63#elif defined(__GNUC__) || defined(__GNUG__)
64#pragma GCC diagnostic pop
65#endif
57_LIBCPP_DIAGNOSTIC_POP
6658
6759const error_category&
6860future_category() noexcept
lib/libcxx/src/hash.cpp+6-8
......@@ -6,14 +6,12 @@
66//
77//===----------------------------------------------------------------------===//
88
9#include "__hash_table"
10#include "algorithm"
11#include "stdexcept"
12#include "type_traits"
13
14#ifdef __clang__
15#pragma clang diagnostic ignored "-Wtautological-constant-out-of-range-compare"
16#endif
9#include <__hash_table>
10#include <algorithm>
11#include <stdexcept>
12#include <type_traits>
13
14_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wtautological-constant-out-of-range-compare")
1715
1816_LIBCPP_BEGIN_NAMESPACE_STD
1917
lib/libcxx/src/include/atomic_support.h+2-2
......@@ -9,8 +9,8 @@
99#ifndef ATOMIC_SUPPORT_H
1010#define ATOMIC_SUPPORT_H
1111
12#include "__config"
13#include "memory" // for __libcpp_relaxed_load
12#include <__config>
13#include <memory> // for __libcpp_relaxed_load
1414
1515#if defined(__clang__) && __has_builtin(__atomic_load_n) \
1616 && __has_builtin(__atomic_store_n) \
lib/libcxx/src/include/config_elast.h+2
......@@ -29,6 +29,8 @@
2929// No _LIBCPP_ELAST needed on Fuchsia
3030#elif defined(__wasi__)
3131// No _LIBCPP_ELAST needed on WASI
32#elif defined(__EMSCRIPTEN__)
33// No _LIBCPP_ELAST needed on Emscripten
3234#elif defined(__linux__) || defined(_LIBCPP_HAS_MUSL_LIBC)
3335#define _LIBCPP_ELAST 4095
3436#elif defined(__APPLE__)
lib/libcxx/src/include/ryu/common.h+1
......@@ -42,6 +42,7 @@
4242// Avoid formatting to keep the changes with the original code minimal.
4343// clang-format off
4444
45#include <__assert>
4546#include "__config"
4647
4748_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/src/include/ryu/d2fixed.h+2-2
......@@ -42,8 +42,8 @@
4242// Avoid formatting to keep the changes with the original code minimal.
4343// clang-format off
4444
45#include "__config"
46#include "cstdint"
45#include <__config>
46#include <cstdint>
4747
4848_LIBCPP_BEGIN_NAMESPACE_STD
4949
lib/libcxx/src/include/ryu/d2fixed_full_table.h+1-1
......@@ -42,7 +42,7 @@
4242// Avoid formatting to keep the changes with the original code minimal.
4343// clang-format off
4444
45#include "__config"
45#include <__config>
4646
4747_LIBCPP_BEGIN_NAMESPACE_STD
4848
lib/libcxx/src/include/ryu/d2s.h+1-1
......@@ -42,7 +42,7 @@
4242// Avoid formatting to keep the changes with the original code minimal.
4343// clang-format off
4444
45#include "__config"
45#include <__config>
4646
4747_LIBCPP_BEGIN_NAMESPACE_STD
4848
lib/libcxx/src/include/ryu/d2s_full_table.h+1-1
......@@ -42,7 +42,7 @@
4242// Avoid formatting to keep the changes with the original code minimal.
4343// clang-format off
4444
45#include "__config"
45#include <__config>
4646
4747_LIBCPP_BEGIN_NAMESPACE_STD
4848
lib/libcxx/src/include/ryu/d2s_intrinsics.h+4-1
......@@ -42,7 +42,10 @@
4242// Avoid formatting to keep the changes with the original code minimal.
4343// clang-format off
4444
45#include "__config"
45#include <__assert>
46#include <__config>
47
48#include "include/ryu/ryu.h"
4649
4750_LIBCPP_BEGIN_NAMESPACE_STD
4851
lib/libcxx/src/include/ryu/digit_table.h+7-18
......@@ -39,30 +39,19 @@
3939#ifndef _LIBCPP_SRC_INCLUDE_RYU_DIGIT_TABLE_H
4040#define _LIBCPP_SRC_INCLUDE_RYU_DIGIT_TABLE_H
4141
42// Avoid formatting to keep the changes with the original code minimal.
43// clang-format off
44
45#include "__config"
42#include <__charconv/tables.h>
43#include <__config>
4644
4745_LIBCPP_BEGIN_NAMESPACE_STD
4846
4947// A table of all two-digit numbers. This is used to speed up decimal digit
5048// generation by copying pairs of digits into the final output.
51inline constexpr char __DIGIT_TABLE[200] = {
52 '0','0','0','1','0','2','0','3','0','4','0','5','0','6','0','7','0','8','0','9',
53 '1','0','1','1','1','2','1','3','1','4','1','5','1','6','1','7','1','8','1','9',
54 '2','0','2','1','2','2','2','3','2','4','2','5','2','6','2','7','2','8','2','9',
55 '3','0','3','1','3','2','3','3','3','4','3','5','3','6','3','7','3','8','3','9',
56 '4','0','4','1','4','2','4','3','4','4','4','5','4','6','4','7','4','8','4','9',
57 '5','0','5','1','5','2','5','3','5','4','5','5','5','6','5','7','5','8','5','9',
58 '6','0','6','1','6','2','6','3','6','4','6','5','6','6','6','7','6','8','6','9',
59 '7','0','7','1','7','2','7','3','7','4','7','5','7','6','7','7','7','8','7','9',
60 '8','0','8','1','8','2','8','3','8','4','8','5','8','6','8','7','8','8','8','9',
61 '9','0','9','1','9','2','9','3','9','4','9','5','9','6','9','7','9','8','9','9'
62};
49//
50// In order to minimize the diff in the Ryu code between MSVC STL and libc++
51// the code uses the name __DIGIT_TABLE. In order to avoid code duplication it
52// reuses the table already available in libc++.
53inline constexpr auto& __DIGIT_TABLE = __itoa::__table<>::__digits_base_10;
6354
6455_LIBCPP_END_NAMESPACE_STD
6556
66// clang-format on
67
6857#endif // _LIBCPP_SRC_INCLUDE_RYU_DIGIT_TABLE_H
lib/libcxx/src/include/ryu/f2s.h+1-1
......@@ -42,7 +42,7 @@
4242// Avoid formatting to keep the changes with the original code minimal.
4343// clang-format off
4444
45#include "__config"
45#include <__config>
4646
4747_LIBCPP_BEGIN_NAMESPACE_STD
4848
lib/libcxx/src/include/ryu/ryu.h+14-13
......@@ -44,21 +44,22 @@
4444// Avoid formatting to keep the changes with the original code minimal.
4545// clang-format off
4646
47#include "__charconv/chars_format.h"
48#include "__charconv/to_chars_result.h"
49#include "__config"
50#include "__debug"
51#include "__errc"
52#include "cstdint"
53#include "cstring"
54#include "type_traits"
47#include <__charconv/chars_format.h>
48#include <__charconv/to_chars_result.h>
49#include <__config>
50#include <__debug>
51#include <__errc>
52#include <cstdint>
53#include <cstring>
54#include <type_traits>
55
5556#include "include/ryu/f2s.h"
5657#include "include/ryu/d2s.h"
5758#include "include/ryu/d2fixed.h"
5859
59#if defined(_M_X64) && defined(_LIBCPP_COMPILER_MSVC)
60#include <intrin0.h> // for _umul128() and __shiftright128()
61#endif // defined(_M_X64) && defined(_LIBCPP_COMPILER_MSVC)
60#if defined(_MSC_VER)
61#include <intrin.h> // for _umul128(), __shiftright128(), _BitScanForward{,64}
62#endif // defined(_MSC_VER)
6263
6364#if defined(_WIN64) || defined(_M_AMD64) || defined(__x86_64__) || defined(__aarch64__)
6465#define _LIBCPP_64_BIT
......@@ -68,7 +69,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
6869
6970// https://github.com/ulfjack/ryu/tree/59661c3/ryu
7071
71#if !defined(_LIBCPP_COMPILER_MSVC)
72#if !defined(_MSC_VER)
7273_LIBCPP_HIDE_FROM_ABI inline unsigned char _BitScanForward64(unsigned long* __index, unsigned long long __mask) {
7374 if (__mask == 0) {
7475 return false;
......@@ -84,7 +85,7 @@ _LIBCPP_HIDE_FROM_ABI inline unsigned char _BitScanForward(unsigned long* __inde
8485 *__index = __builtin_ctz(__mask);
8586 return true;
8687}
87#endif // _LIBCPP_COMPILER_MSVC
88#endif // !_MSC_VER
8889
8990template <class _Floating>
9091[[nodiscard]] to_chars_result _Floating_to_chars_ryu(
lib/libcxx/src/include/sso_allocator.h+5
......@@ -41,6 +41,11 @@ public:
4141 typedef _Tp* pointer;
4242 typedef _Tp value_type;
4343
44 template <class U>
45 struct rebind {
46 using other = __sso_allocator<U, _Np>;
47 };
48
4449 _LIBCPP_INLINE_VISIBILITY __sso_allocator() throw() : __allocated_(false) {}
4550 _LIBCPP_INLINE_VISIBILITY __sso_allocator(const __sso_allocator&) throw() : __allocated_(false) {}
4651 template <class _Up> _LIBCPP_INLINE_VISIBILITY __sso_allocator(const __sso_allocator<_Up, _Np>&) throw()
lib/libcxx/src/include/to_chars_floating_point.h+13-10
......@@ -17,16 +17,19 @@
1717// Avoid formatting to keep the changes with the original code minimal.
1818// clang-format off
1919
20#include "__algorithm/find.h"
21#include "__algorithm/find_if.h"
22#include "__algorithm/lower_bound.h"
23#include "__algorithm/min.h"
24#include "__config"
25#include "__iterator/access.h"
26#include "__iterator/size.h"
27#include "bit"
28#include "cfloat"
29#include "climits"
20#include <__algorithm/find.h>
21#include <__algorithm/find_if.h>
22#include <__algorithm/lower_bound.h>
23#include <__algorithm/min.h>
24#include <__assert>
25#include <__config>
26#include <__functional/operations.h>
27#include <__iterator/access.h>
28#include <__iterator/size.h>
29#include <bit>
30#include <cfloat>
31#include <climits>
32
3033#include "include/ryu/ryu.h"
3134
3235_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/src/ios.cpp+13-11
......@@ -6,20 +6,20 @@
66//
77//===----------------------------------------------------------------------===//
88
9#include "__config"
10
11#include "ios"
12
9#include <__config>
10#include <__locale>
11#include <algorithm>
12#include <ios>
13#include <limits>
14#include <memory>
15#include <new>
1316#include <stdlib.h>
17#include <string>
1418
15#include "__locale"
16#include "algorithm"
1719#include "include/config_elast.h"
18#include "limits"
19#include "memory"
20#include "new"
21#include "string"
22#include "__undef_macros"
20
21_LIBCPP_PUSH_MACROS
22#include <__undef_macros>
2323
2424_LIBCPP_BEGIN_NAMESPACE_STD
2525
......@@ -439,3 +439,5 @@ ios_base::sync_with_stdio(bool sync)
439439}
440440
441441_LIBCPP_END_NAMESPACE_STD
442
443_LIBCPP_POP_MACROS
lib/libcxx/src/ios.instantiations.cpp+7-8
......@@ -6,14 +6,13 @@
66//
77//===----------------------------------------------------------------------===//
88
9#include "__config"
10#include "fstream"
11#include "ios"
12#include "istream"
13#include "ostream"
14#include "sstream"
15#include "streambuf"
16
9#include <__config>
10#include <fstream>
11#include <ios>
12#include <istream>
13#include <ostream>
14#include <sstream>
15#include <streambuf>
1716
1817_LIBCPP_BEGIN_NAMESPACE_STD
1918
lib/libcxx/src/iostream.cpp+4-4
......@@ -6,10 +6,10 @@
66//
77//===----------------------------------------------------------------------===//
88
9#include "__std_stream"
10#include "__locale"
11#include "string"
12#include "new"
9#include <__locale>
10#include <__std_stream>
11#include <new>
12#include <string>
1313
1414#define _str(s) #s
1515#define str(s) _str(s)
lib/libcxx/src/legacy_debug_handler.cpp created+54
......@@ -0,0 +1,54 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include <__config>
10#include <cstdio>
11#include <cstdlib>
12#include <string>
13
14// This file defines the legacy default debug handler and related mechanisms
15// to set it. This is for backwards ABI compatibility with code that has been
16// using this debug handler previously.
17
18_LIBCPP_BEGIN_NAMESPACE_STD
19
20struct _LIBCPP_TEMPLATE_VIS __libcpp_debug_info {
21 _LIBCPP_EXPORTED_FROM_ABI string what() const;
22
23 const char* __file_;
24 int __line_;
25 const char* __pred_;
26 const char* __msg_;
27};
28
29std::string __libcpp_debug_info::what() const {
30 string msg = __file_;
31 msg += ":" + std::to_string(__line_) + ": _LIBCPP_ASSERT '";
32 msg += __pred_;
33 msg += "' failed. ";
34 msg += __msg_;
35 return msg;
36}
37
38_LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __libcpp_abort_debug_function(__libcpp_debug_info const& info) {
39 std::fprintf(stderr, "%s\n", info.what().c_str());
40 std::abort();
41}
42
43typedef void (*__libcpp_debug_function_type)(__libcpp_debug_info const&);
44
45_LIBCPP_EXPORTED_FROM_ABI
46constinit __libcpp_debug_function_type __libcpp_debug_function = __libcpp_abort_debug_function;
47
48_LIBCPP_EXPORTED_FROM_ABI
49bool __libcpp_set_debug_function(__libcpp_debug_function_type __func) {
50 __libcpp_debug_function = __func;
51 return true;
52}
53
54_LIBCPP_END_NAMESPACE_STD
lib/libcxx/src/legacy_pointer_safety.cpp+1-1
......@@ -6,7 +6,7 @@
66//
77//===----------------------------------------------------------------------===//
88
9#include "__config"
9#include <__config>
1010#include <memory>
1111
1212// Support for garbage collection was removed in C++23 by https://wg21.link/P2186R2. Libc++ implements
lib/libcxx/src/locale.cpp+45-33
......@@ -12,20 +12,21 @@
1212#define _LCONV_C99
1313#endif
1414
15#include "algorithm"
16#include "clocale"
17#include "codecvt"
18#include "cstdio"
19#include "cstdlib"
20#include "cstring"
21#include "locale"
22#include "string"
23#include "type_traits"
24#include "typeinfo"
25#include "vector"
15#include <__utility/unreachable.h>
16#include <algorithm>
17#include <clocale>
18#include <codecvt>
19#include <cstdio>
20#include <cstdlib>
21#include <cstring>
22#include <locale>
23#include <string>
24#include <type_traits>
25#include <typeinfo>
26#include <vector>
2627
2728#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
28# include "cwctype"
29# include <cwctype>
2930#endif
3031
3132#if defined(_AIX)
......@@ -44,13 +45,13 @@
4445
4546#include "include/atomic_support.h"
4647#include "include/sso_allocator.h"
47#include "__undef_macros"
4848
4949// On Linux, wint_t and wchar_t have different signed-ness, and this causes
5050// lots of noise in the build log, but no bugs that I know of.
51#if defined(__clang__)
52#pragma clang diagnostic ignored "-Wsign-conversion"
53#endif
51_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wsign-conversion")
52
53_LIBCPP_PUSH_MACROS
54#include <__undef_macros>
5455
5556_LIBCPP_BEGIN_NAMESPACE_STD
5657
......@@ -127,11 +128,6 @@ _LIBCPP_NORETURN static void __throw_runtime_error(const string &msg)
127128
128129}
129130
130#if defined(_AIX)
131// Set priority to INT_MIN + 256 + 150
132# pragma priority ( -2147483242 )
133#endif
134
135131const locale::category locale::none;
136132const locale::category locale::collate;
137133const locale::category locale::ctype;
......@@ -1528,7 +1524,7 @@ char
15281524ctype_byname<wchar_t>::do_narrow(char_type c, char dfault) const
15291525{
15301526 int r = __libcpp_wctob_l(c, __l);
1531 return r != static_cast<int>(WEOF) ? static_cast<char>(r) : dfault;
1527 return (r != EOF) ? static_cast<char>(r) : dfault;
15321528}
15331529
15341530const wchar_t*
......@@ -1537,7 +1533,7 @@ ctype_byname<wchar_t>::do_narrow(const char_type* low, const char_type* high, ch
15371533 for (; low != high; ++low, ++dest)
15381534 {
15391535 int r = __libcpp_wctob_l(*low, __l);
1540 *dest = r != static_cast<int>(WEOF) ? static_cast<char>(r) : dfault;
1536 *dest = (r != EOF) ? static_cast<char>(r) : dfault;
15411537 }
15421538 return low;
15431539}
......@@ -1835,6 +1831,7 @@ codecvt<wchar_t, char, mbstate_t>::do_max_length() const noexcept
18351831// 040000 - 0FFFFF D8C0 - DBBF, DC00 - DFFF F1 - F3, 80 - BF, 80 - BF, 80 - BF 786432
18361832// 100000 - 10FFFF DBC0 - DBFF, DC00 - DFFF F4 - F4, 80 - 8F, 80 - BF, 80 - BF 65536
18371833
1834_LIBCPP_SUPPRESS_DEPRECATED_PUSH
18381835static
18391836codecvt_base::result
18401837utf16_to_utf8(const uint16_t* frm, const uint16_t* frm_end, const uint16_t*& frm_nxt,
......@@ -3208,6 +3205,8 @@ utf16le_to_ucs2_length(const uint8_t* frm, const uint8_t* frm_end,
32083205 return static_cast<int>(frm_nxt - frm);
32093206}
32103207
3208_LIBCPP_SUPPRESS_DEPRECATED_POP
3209
32113210// template <> class codecvt<char16_t, char, mbstate_t>
32123211
32133212locale::id codecvt<char16_t, char, mbstate_t>::id;
......@@ -3615,6 +3614,7 @@ __codecvt_utf8<wchar_t>::do_length(state_type&,
36153614#endif
36163615}
36173616
3617_LIBCPP_SUPPRESS_DEPRECATED_PUSH
36183618int
36193619__codecvt_utf8<wchar_t>::do_max_length() const noexcept
36203620{
......@@ -3697,6 +3697,7 @@ __codecvt_utf8<char16_t>::do_length(state_type&,
36973697 return utf8_to_ucs2_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
36983698}
36993699
3700_LIBCPP_SUPPRESS_DEPRECATED_PUSH
37003701int
37013702__codecvt_utf8<char16_t>::do_max_length() const noexcept
37023703{
......@@ -3704,6 +3705,7 @@ __codecvt_utf8<char16_t>::do_max_length() const noexcept
37043705 return 6;
37053706 return 3;
37063707}
3708_LIBCPP_SUPPRESS_DEPRECATED_POP
37073709
37083710// __codecvt_utf8<char32_t>
37093711
......@@ -3772,6 +3774,7 @@ __codecvt_utf8<char32_t>::do_length(state_type&,
37723774 return utf8_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
37733775}
37743776
3777_LIBCPP_SUPPRESS_DEPRECATED_PUSH
37753778int
37763779__codecvt_utf8<char32_t>::do_max_length() const noexcept
37773780{
......@@ -3779,6 +3782,7 @@ __codecvt_utf8<char32_t>::do_max_length() const noexcept
37793782 return 7;
37803783 return 4;
37813784}
3785_LIBCPP_SUPPRESS_DEPRECATED_POP
37823786
37833787// __codecvt_utf16<wchar_t, false>
37843788
......@@ -4057,6 +4061,7 @@ __codecvt_utf16<char16_t, false>::do_length(state_type&,
40574061 return utf16be_to_ucs2_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
40584062}
40594063
4064_LIBCPP_SUPPRESS_DEPRECATED_PUSH
40604065int
40614066__codecvt_utf16<char16_t, false>::do_max_length() const noexcept
40624067{
......@@ -4064,6 +4069,7 @@ __codecvt_utf16<char16_t, false>::do_max_length() const noexcept
40644069 return 4;
40654070 return 2;
40664071}
4072_LIBCPP_SUPPRESS_DEPRECATED_POP
40674073
40684074// __codecvt_utf16<char16_t, true>
40694075
......@@ -4132,6 +4138,7 @@ __codecvt_utf16<char16_t, true>::do_length(state_type&,
41324138 return utf16le_to_ucs2_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
41334139}
41344140
4141_LIBCPP_SUPPRESS_DEPRECATED_PUSH
41354142int
41364143__codecvt_utf16<char16_t, true>::do_max_length() const noexcept
41374144{
......@@ -4139,6 +4146,7 @@ __codecvt_utf16<char16_t, true>::do_max_length() const noexcept
41394146 return 4;
41404147 return 2;
41414148}
4149_LIBCPP_SUPPRESS_DEPRECATED_POP
41424150
41434151// __codecvt_utf16<char32_t, false>
41444152
......@@ -4207,6 +4215,7 @@ __codecvt_utf16<char32_t, false>::do_length(state_type&,
42074215 return utf16be_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
42084216}
42094217
4218_LIBCPP_SUPPRESS_DEPRECATED_PUSH
42104219int
42114220__codecvt_utf16<char32_t, false>::do_max_length() const noexcept
42124221{
......@@ -4214,6 +4223,7 @@ __codecvt_utf16<char32_t, false>::do_max_length() const noexcept
42144223 return 6;
42154224 return 4;
42164225}
4226_LIBCPP_SUPPRESS_DEPRECATED_POP
42174227
42184228// __codecvt_utf16<char32_t, true>
42194229
......@@ -4282,6 +4292,7 @@ __codecvt_utf16<char32_t, true>::do_length(state_type&,
42824292 return utf16le_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
42834293}
42844294
4295_LIBCPP_SUPPRESS_DEPRECATED_PUSH
42854296int
42864297__codecvt_utf16<char32_t, true>::do_max_length() const noexcept
42874298{
......@@ -4289,6 +4300,7 @@ __codecvt_utf16<char32_t, true>::do_max_length() const noexcept
42894300 return 6;
42904301 return 4;
42914302}
4303_LIBCPP_SUPPRESS_DEPRECATED_POP
42924304
42934305// __codecvt_utf8_utf16<wchar_t>
42944306
......@@ -4446,6 +4458,7 @@ __codecvt_utf8_utf16<char16_t>::do_length(state_type&,
44464458 return utf8_to_utf16_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
44474459}
44484460
4461_LIBCPP_SUPPRESS_DEPRECATED_PUSH
44494462int
44504463__codecvt_utf8_utf16<char16_t>::do_max_length() const noexcept
44514464{
......@@ -4453,6 +4466,7 @@ __codecvt_utf8_utf16<char16_t>::do_max_length() const noexcept
44534466 return 7;
44544467 return 4;
44554468}
4469_LIBCPP_SUPPRESS_DEPRECATED_POP
44564470
44574471// __codecvt_utf8_utf16<char32_t>
44584472
......@@ -4521,6 +4535,7 @@ __codecvt_utf8_utf16<char32_t>::do_length(state_type&,
45214535 return utf8_to_utf16_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
45224536}
45234537
4538_LIBCPP_SUPPRESS_DEPRECATED_PUSH
45244539int
45254540__codecvt_utf8_utf16<char32_t>::do_max_length() const noexcept
45264541{
......@@ -4528,6 +4543,7 @@ __codecvt_utf8_utf16<char32_t>::do_max_length() const noexcept
45284543 return 7;
45294544 return 4;
45304545}
4546_LIBCPP_SUPPRESS_DEPRECATED_POP
45314547
45324548// __narrow_to_utf8<16>
45334549
......@@ -4623,7 +4639,7 @@ static bool checked_string_to_char_convert(char& dest,
46234639
46244640 return false;
46254641#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
4626 _LIBCPP_UNREACHABLE();
4642 __libcpp_unreachable();
46274643}
46284644
46294645
......@@ -5200,12 +5216,8 @@ __time_get::~__time_get()
52005216{
52015217 freelocale(__loc_);
52025218}
5203#if defined(__clang__)
5204#pragma clang diagnostic ignored "-Wmissing-field-initializers"
5205#endif
5206#if defined(__GNUG__)
5207#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
5208#endif
5219
5220_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wmissing-field-initializers")
52095221
52105222template <>
52115223string
......@@ -5351,9 +5363,7 @@ __time_get_storage<char>::__analyze(char fmt, const ctype<char>& ct)
53515363 return result;
53525364}
53535365
5354#if defined(__clang__)
5355#pragma clang diagnostic ignored "-Wmissing-braces"
5356#endif
5366_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wmissing-braces")
53575367
53585368#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
53595369template <>
......@@ -6599,3 +6609,5 @@ template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS codecvt_byname<char32_t,
65996609#endif
66006610
66016611_LIBCPP_END_NAMESPACE_STD
6612
6613_LIBCPP_POP_MACROS
lib/libcxx/src/memory.cpp+28-24
......@@ -6,14 +6,21 @@
66//
77//===----------------------------------------------------------------------===//
88
9#include "memory"
9#include <__config>
10#ifdef _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS
11# define _LIBCPP_SHARED_PTR_DEFINE_LEGACY_INLINE_FUNCTIONS
12#endif
13
14#include <memory>
15
1016#ifndef _LIBCPP_HAS_NO_THREADS
11# include "mutex"
12# include "thread"
13# if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
14# pragma comment(lib, "pthread")
15# endif
17# include <mutex>
18# include <thread>
19# if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
20# pragma comment(lib, "pthread")
21# endif
1622#endif
23
1724#include "include/atomic_support.h"
1825
1926_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -36,7 +43,7 @@ __shared_weak_count::~__shared_weak_count()
3643{
3744}
3845
39#if defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
46#if defined(_LIBCPP_SHARED_PTR_DEFINE_LEGACY_INLINE_FUNCTIONS)
4047void
4148__shared_count::__add_shared() noexcept
4249{
......@@ -72,8 +79,7 @@ __shared_weak_count::__release_shared() noexcept
7279 if (__shared_count::__release_shared())
7380 __release_weak();
7481}
75
76#endif // _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS
82#endif // _LIBCPP_SHARED_PTR_DEFINE_LEGACY_INLINE_FUNCTIONS
7783
7884void
7985__shared_weak_count::__release_weak() noexcept
......@@ -132,9 +138,13 @@ __shared_weak_count::__get_deleter(const type_info&) const noexcept
132138
133139#if !defined(_LIBCPP_HAS_NO_THREADS)
134140
135_LIBCPP_SAFE_STATIC static const std::size_t __sp_mut_count = 16;
136_LIBCPP_SAFE_STATIC static __libcpp_mutex_t mut_back[__sp_mut_count] =
141static constexpr std::size_t __sp_mut_count = 32;
142static constinit __libcpp_mutex_t mut_back[__sp_mut_count] =
137143{
144 _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER,
145 _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER,
146 _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER,
147 _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER,
138148 _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER,
139149 _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER,
140150 _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER,
......@@ -150,16 +160,7 @@ void
150160__sp_mut::lock() noexcept
151161{
152162 auto m = static_cast<__libcpp_mutex_t*>(__lx);
153 unsigned count = 0;
154 while (!__libcpp_mutex_trylock(m))
155 {
156 if (++count > 16)
157 {
158 __libcpp_mutex_lock(m);
159 break;
160 }
161 this_thread::yield();
162 }
163 __libcpp_mutex_lock(m);
163164}
164165
165166void
......@@ -171,12 +172,15 @@ __sp_mut::unlock() noexcept
171172__sp_mut&
172173__get_sp_mut(const void* p)
173174{
174 static __sp_mut muts[__sp_mut_count]
175 {
175 static constinit __sp_mut muts[__sp_mut_count] = {
176176 &mut_back[ 0], &mut_back[ 1], &mut_back[ 2], &mut_back[ 3],
177177 &mut_back[ 4], &mut_back[ 5], &mut_back[ 6], &mut_back[ 7],
178178 &mut_back[ 8], &mut_back[ 9], &mut_back[10], &mut_back[11],
179 &mut_back[12], &mut_back[13], &mut_back[14], &mut_back[15]
179 &mut_back[12], &mut_back[13], &mut_back[14], &mut_back[15],
180 &mut_back[16], &mut_back[17], &mut_back[18], &mut_back[19],
181 &mut_back[20], &mut_back[21], &mut_back[22], &mut_back[23],
182 &mut_back[24], &mut_back[25], &mut_back[26], &mut_back[27],
183 &mut_back[28], &mut_back[29], &mut_back[30], &mut_back[31]
180184 };
181185 return muts[hash<const void*>()(p) & (__sp_mut_count-1)];
182186}
lib/libcxx/src/mutex.cpp+16-9
......@@ -6,19 +6,24 @@
66//
77//===----------------------------------------------------------------------===//
88
9#include "mutex"
10#include "limits"
11#include "system_error"
9#include <__assert>
10#include <limits>
11#include <mutex>
12#include <system_error>
13
1214#include "include/atomic_support.h"
13#include "__undef_macros"
1415
1516#ifndef _LIBCPP_HAS_NO_THREADS
16#if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
17#pragma comment(lib, "pthread")
18#endif
17# if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
18# pragma comment(lib, "pthread")
19# endif
1920#endif
2021
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
2125_LIBCPP_BEGIN_NAMESPACE_STD
26
2227#ifndef _LIBCPP_HAS_NO_THREADS
2328
2429const defer_lock_t defer_lock{};
......@@ -196,8 +201,8 @@ recursive_timed_mutex::unlock() noexcept
196201// keep in sync with: 7741191.
197202
198203#ifndef _LIBCPP_HAS_NO_THREADS
199_LIBCPP_SAFE_STATIC static __libcpp_mutex_t mut = _LIBCPP_MUTEX_INITIALIZER;
200_LIBCPP_SAFE_STATIC static __libcpp_condvar_t cv = _LIBCPP_CONDVAR_INITIALIZER;
204static constinit __libcpp_mutex_t mut = _LIBCPP_MUTEX_INITIALIZER;
205static constinit __libcpp_condvar_t cv = _LIBCPP_CONDVAR_INITIALIZER;
201206#endif
202207
203208void __call_once(volatile once_flag::_State_type& flag, void* arg,
......@@ -258,3 +263,5 @@ void __call_once(volatile once_flag::_State_type& flag, void* arg,
258263}
259264
260265_LIBCPP_END_NAMESPACE_STD
266
267_LIBCPP_POP_MACROS
lib/libcxx/src/mutex_destructor.cpp+5-5
......@@ -16,13 +16,13 @@
1616// we re-declare the entire class in this file instead of using
1717// _LIBCPP_BUILDING_LIBRARY to change the definition in the headers.
1818
19#include "__config"
20#include "__threading_support"
19#include <__config>
20#include <__threading_support>
2121
2222#if !defined(_LIBCPP_HAS_NO_THREADS)
23#if _LIBCPP_ABI_VERSION == 1 || !defined(_LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION)
24#define NEEDS_MUTEX_DESTRUCTOR
25#endif
23# if _LIBCPP_ABI_VERSION == 1 || !defined(_LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION)
24# define NEEDS_MUTEX_DESTRUCTOR
25# endif
2626#endif
2727
2828_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/src/new.cpp+1-1
......@@ -6,9 +6,9 @@
66//
77//===----------------------------------------------------------------------===//
88
9#include <new>
910#include <stdlib.h>
1011
11#include "new"
1212#include "include/atomic_support.h"
1313
1414#if defined(_LIBCPP_ABI_MICROSOFT)
lib/libcxx/src/optional.cpp+2-2
......@@ -6,8 +6,8 @@
66//
77//===----------------------------------------------------------------------===//
88
9#include "optional"
10#include "__availability"
9#include <__availability>
10#include <optional>
1111
1212namespace std
1313{
lib/libcxx/src/random.cpp+3-3
......@@ -13,9 +13,9 @@
1313# define _CRT_RAND_S
1414#endif // defined(_LIBCPP_USING_WIN32_RANDOM)
1515
16#include "limits"
17#include "random"
18#include "system_error"
16#include <limits>
17#include <random>
18#include <system_error>
1919
2020#if defined(__sun__)
2121# define rename solaris_headers_are_broken
lib/libcxx/src/random_shuffle.cpp+8-7
......@@ -6,19 +6,20 @@
66//
77//===----------------------------------------------------------------------===//
88
9#include "algorithm"
10#include "random"
9#include <algorithm>
10#include <random>
11
1112#ifndef _LIBCPP_HAS_NO_THREADS
12# include "mutex"
13# if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
14# pragma comment(lib, "pthread")
15# endif
13# include <mutex>
14# if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
15# pragma comment(lib, "pthread")
16# endif
1617#endif
1718
1819_LIBCPP_BEGIN_NAMESPACE_STD
1920
2021#ifndef _LIBCPP_HAS_NO_THREADS
21_LIBCPP_SAFE_STATIC static __libcpp_mutex_t __rs_mut = _LIBCPP_MUTEX_INITIALIZER;
22static constinit __libcpp_mutex_t __rs_mut = _LIBCPP_MUTEX_INITIALIZER;
2223#endif
2324unsigned __rs_default::__c_ = 0;
2425
lib/libcxx/src/regex.cpp+3-3
......@@ -6,9 +6,9 @@
66//
77//===----------------------------------------------------------------------===//
88
9#include "regex"
10#include "algorithm"
11#include "iterator"
9#include <algorithm>
10#include <iterator>
11#include <regex>
1212
1313_LIBCPP_BEGIN_NAMESPACE_STD
1414
lib/libcxx/src/ryu/d2fixed.cpp+5-4
......@@ -39,10 +39,11 @@
3939// Avoid formatting to keep the changes with the original code minimal.
4040// clang-format off
4141
42#include "__config"
43#include "charconv"
44#include "cstring"
45#include "system_error"
42#include <__assert>
43#include <__config>
44#include <charconv>
45#include <cstring>
46#include <system_error>
4647
4748#include "include/ryu/common.h"
4849#include "include/ryu/d2fixed.h"
lib/libcxx/src/ryu/d2s.cpp+3-2
......@@ -39,8 +39,9 @@
3939// Avoid formatting to keep the changes with the original code minimal.
4040// clang-format off
4141
42#include "__config"
43#include "charconv"
42#include <__assert>
43#include <__config>
44#include <charconv>
4445
4546#include "include/ryu/common.h"
4647#include "include/ryu/d2fixed.h"
lib/libcxx/src/ryu/f2s.cpp+3-2
......@@ -39,8 +39,9 @@
3939// Avoid formatting to keep the changes with the original code minimal.
4040// clang-format off
4141
42#include "__config"
43#include "charconv"
42#include <__assert>
43#include <__config>
44#include <charconv>
4445
4546#include "include/ryu/common.h"
4647#include "include/ryu/d2fixed.h"
lib/libcxx/src/shared_mutex.cpp+4-3
......@@ -6,12 +6,13 @@
66//
77//===----------------------------------------------------------------------===//
88
9#include "__config"
9#include <__config>
10
1011#ifndef _LIBCPP_HAS_NO_THREADS
1112
12#include "shared_mutex"
13#include <shared_mutex>
1314#if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
14#pragma comment(lib, "pthread")
15# pragma comment(lib, "pthread")
1516#endif
1617
1718_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/src/stdexcept.cpp+4-5
......@@ -6,11 +6,10 @@
66//
77//===----------------------------------------------------------------------===//
88
9#include "stdexcept"
10#include "new"
11#include "string"
12#include "system_error"
13
9#include <new>
10#include <stdexcept>
11#include <string>
12#include <system_error>
1413
1514#ifdef _LIBCPP_ABI_VCRUNTIME
1615#include "support/runtime/stdexcept_vcruntime.ipp"
lib/libcxx/src/string.cpp+94-216
......@@ -6,17 +6,17 @@
66//
77//===----------------------------------------------------------------------===//
88
9#include "string"
10#include "charconv"
11#include "cstdlib"
12#include "cerrno"
13#include "limits"
14#include "stdexcept"
9#include <__assert>
10#include <cerrno>
11#include <charconv>
12#include <cstdlib>
13#include <limits>
14#include <stdexcept>
1515#include <stdio.h>
16#include "__debug"
16#include <string>
1717
1818#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
19# include "cwchar"
19# include <cwchar>
2020#endif
2121
2222_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -56,42 +56,33 @@ void __basic_string_common<true>::__throw_out_of_range() const {
5656#endif
5757#undef _LIBCPP_EXTERN_TEMPLATE_DEFINE
5858
59template string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&);
59template string operator+<char, char_traits<char>, allocator<char>>(char const*, string const&);
6060
6161namespace
6262{
6363
6464template<typename T>
65inline
66void throw_helper( const string& msg )
67{
65inline void throw_helper(const string& msg) {
6866#ifndef _LIBCPP_NO_EXCEPTIONS
69 throw T( msg );
67 throw T(msg);
7068#else
7169 fprintf(stderr, "%s\n", msg.c_str());
7270 _VSTD::abort();
7371#endif
7472}
7573
76inline
77void throw_from_string_out_of_range( const string& func )
78{
74inline void throw_from_string_out_of_range(const string& func) {
7975 throw_helper<out_of_range>(func + ": out of range");
8076}
8177
82inline
83void throw_from_string_invalid_arg( const string& func )
84{
78inline void throw_from_string_invalid_arg(const string& func) {
8579 throw_helper<invalid_argument>(func + ": no conversion");
8680}
8781
8882// as_integer
8983
9084template<typename V, typename S, typename F>
91inline
92V
93as_integer_helper(const string& func, const S& str, size_t* idx, int base, F f)
94{
85inline V as_integer_helper(const string& func, const S& str, size_t* idx, int base, F f) {
9586 typename S::value_type* ptr = nullptr;
9687 const typename S::value_type* const p = str.c_str();
9788 typename remove_reference<decltype(errno)>::type errno_save = errno;
......@@ -108,109 +99,77 @@ as_integer_helper(const string& func, const S& str, size_t* idx, int base, F f)
10899}
109100
110101template<typename V, typename S>
111inline
112V
113as_integer(const string& func, const S& s, size_t* idx, int base);
102inline V as_integer(const string& func, const S& s, size_t* idx, int base);
114103
115104// string
116105template<>
117inline
118int
119as_integer(const string& func, const string& s, size_t* idx, int base )
120{
106inline int as_integer(const string& func, const string& s, size_t* idx, int base) {
121107 // Use long as no Standard string to integer exists.
122 long r = as_integer_helper<long>( func, s, idx, base, strtol );
108 long r = as_integer_helper<long>(func, s, idx, base, strtol);
123109 if (r < numeric_limits<int>::min() || numeric_limits<int>::max() < r)
124110 throw_from_string_out_of_range(func);
125111 return static_cast<int>(r);
126112}
127113
128114template<>
129inline
130long
131as_integer(const string& func, const string& s, size_t* idx, int base )
132{
133 return as_integer_helper<long>( func, s, idx, base, strtol );
115inline long as_integer(const string& func, const string& s, size_t* idx, int base) {
116 return as_integer_helper<long>(func, s, idx, base, strtol);
134117}
135118
136119template<>
137inline
138unsigned long
139as_integer( const string& func, const string& s, size_t* idx, int base )
140{
141 return as_integer_helper<unsigned long>( func, s, idx, base, strtoul );
120inline unsigned long as_integer(const string& func, const string& s, size_t* idx, int base) {
121 return as_integer_helper<unsigned long>(func, s, idx, base, strtoul);
142122}
143123
144124template<>
145inline
146long long
147as_integer( const string& func, const string& s, size_t* idx, int base )
148{
149 return as_integer_helper<long long>( func, s, idx, base, strtoll );
125inline long long as_integer(const string& func, const string& s, size_t* idx, int base) {
126 return as_integer_helper<long long>(func, s, idx, base, strtoll);
150127}
151128
152129template<>
153inline
154unsigned long long
155as_integer( const string& func, const string& s, size_t* idx, int base )
156{
157 return as_integer_helper<unsigned long long>( func, s, idx, base, strtoull );
130inline unsigned long long as_integer(const string& func, const string& s, size_t* idx, int base) {
131 return as_integer_helper<unsigned long long>(func, s, idx, base, strtoull);
158132}
159133
160134#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
161135// wstring
162136template<>
163inline
164int
165as_integer( const string& func, const wstring& s, size_t* idx, int base )
166{
137inline int as_integer(const string& func, const wstring& s, size_t* idx, int base) {
167138 // Use long as no Stantard string to integer exists.
168 long r = as_integer_helper<long>( func, s, idx, base, wcstol );
139 long r = as_integer_helper<long>(func, s, idx, base, wcstol);
169140 if (r < numeric_limits<int>::min() || numeric_limits<int>::max() < r)
170141 throw_from_string_out_of_range(func);
171142 return static_cast<int>(r);
172143}
173144
174145template<>
175inline
176long
177as_integer( const string& func, const wstring& s, size_t* idx, int base )
178{
179 return as_integer_helper<long>( func, s, idx, base, wcstol );
146inline long as_integer(const string& func, const wstring& s, size_t* idx, int base) {
147 return as_integer_helper<long>(func, s, idx, base, wcstol);
180148}
181149
182150template<>
183151inline
184152unsigned long
185as_integer( const string& func, const wstring& s, size_t* idx, int base )
153as_integer(const string& func, const wstring& s, size_t* idx, int base)
186154{
187 return as_integer_helper<unsigned long>( func, s, idx, base, wcstoul );
155 return as_integer_helper<unsigned long>(func, s, idx, base, wcstoul);
188156}
189157
190158template<>
191inline
192long long
193as_integer( const string& func, const wstring& s, size_t* idx, int base )
194{
195 return as_integer_helper<long long>( func, s, idx, base, wcstoll );
159inline long long as_integer(const string& func, const wstring& s, size_t* idx, int base) {
160 return as_integer_helper<long long>(func, s, idx, base, wcstoll);
196161}
197162
198163template<>
199inline
200unsigned long long
201as_integer( const string& func, const wstring& s, size_t* idx, int base )
202{
203 return as_integer_helper<unsigned long long>( func, s, idx, base, wcstoull );
164inline unsigned long long as_integer(const string& func, const wstring& s, size_t* idx, int base) {
165 return as_integer_helper<unsigned long long>(func, s, idx, base, wcstoull);
204166}
205167#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
206168
207169// as_float
208170
209171template<typename V, typename S, typename F>
210inline
211V
212as_float_helper(const string& func, const S& str, size_t* idx, F f )
213{
172inline V as_float_helper(const string& func, const S& str, size_t* idx, F f) {
214173 typename S::value_type* ptr = nullptr;
215174 const typename S::value_type* const p = str.c_str();
216175 typename remove_reference<decltype(errno)>::type errno_save = errno;
......@@ -227,172 +186,107 @@ as_float_helper(const string& func, const S& str, size_t* idx, F f )
227186}
228187
229188template<typename V, typename S>
230inline
231V as_float( const string& func, const S& s, size_t* idx = nullptr );
189inline V as_float(const string& func, const S& s, size_t* idx = nullptr);
232190
233191template<>
234inline
235float
236as_float( const string& func, const string& s, size_t* idx )
237{
238 return as_float_helper<float>( func, s, idx, strtof );
192inline float as_float(const string& func, const string& s, size_t* idx) {
193 return as_float_helper<float>(func, s, idx, strtof);
239194}
240195
241196template<>
242inline
243double
244as_float(const string& func, const string& s, size_t* idx )
245{
246 return as_float_helper<double>( func, s, idx, strtod );
197inline double as_float(const string& func, const string& s, size_t* idx) {
198 return as_float_helper<double>(func, s, idx, strtod);
247199}
248200
249201template<>
250inline
251long double
252as_float( const string& func, const string& s, size_t* idx )
253{
254 return as_float_helper<long double>( func, s, idx, strtold );
202inline long double as_float(const string& func, const string& s, size_t* idx) {
203 return as_float_helper<long double>(func, s, idx, strtold);
255204}
256205
257206#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
258207template<>
259inline
260float
261as_float( const string& func, const wstring& s, size_t* idx )
262{
263 return as_float_helper<float>( func, s, idx, wcstof );
208inline float as_float(const string& func, const wstring& s, size_t* idx) {
209 return as_float_helper<float>(func, s, idx, wcstof);
264210}
265211
266212template<>
267inline
268double
269as_float( const string& func, const wstring& s, size_t* idx )
270{
271 return as_float_helper<double>( func, s, idx, wcstod );
213inline double as_float(const string& func, const wstring& s, size_t* idx) {
214 return as_float_helper<double>(func, s, idx, wcstod);
272215}
273216
274217template<>
275inline
276long double
277as_float( const string& func, const wstring& s, size_t* idx )
278{
279 return as_float_helper<long double>( func, s, idx, wcstold );
218inline long double as_float(const string& func, const wstring& s, size_t* idx) {
219 return as_float_helper<long double>(func, s, idx, wcstold);
280220}
281221#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
282222
283223} // unnamed namespace
284224
285int
286stoi(const string& str, size_t* idx, int base)
287{
288 return as_integer<int>( "stoi", str, idx, base );
225int stoi(const string& str, size_t* idx, int base) {
226 return as_integer<int>("stoi", str, idx, base);
289227}
290228
291#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
292int
293stoi(const wstring& str, size_t* idx, int base)
294{
295 return as_integer<int>( "stoi", str, idx, base );
229long stol(const string& str, size_t* idx, int base) {
230 return as_integer<long>("stol", str, idx, base);
296231}
297#endif
298232
299long
300stol(const string& str, size_t* idx, int base)
301{
302 return as_integer<long>( "stol", str, idx, base );
233unsigned long stoul(const string& str, size_t* idx, int base) {
234 return as_integer<unsigned long>("stoul", str, idx, base);
303235}
304236
305#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
306long
307stol(const wstring& str, size_t* idx, int base)
308{
309 return as_integer<long>( "stol", str, idx, base );
237long long stoll(const string& str, size_t* idx, int base) {
238 return as_integer<long long>("stoll", str, idx, base);
310239}
311#endif
312240
313unsigned long
314stoul(const string& str, size_t* idx, int base)
315{
316 return as_integer<unsigned long>( "stoul", str, idx, base );
241unsigned long long stoull(const string& str, size_t* idx, int base) {
242 return as_integer<unsigned long long>("stoull", str, idx, base);
317243}
318244
319#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
320unsigned long
321stoul(const wstring& str, size_t* idx, int base)
322{
323 return as_integer<unsigned long>( "stoul", str, idx, base );
245float stof(const string& str, size_t* idx) {
246 return as_float<float>("stof", str, idx);
324247}
325#endif
326248
327long long
328stoll(const string& str, size_t* idx, int base)
329{
330 return as_integer<long long>( "stoll", str, idx, base );
249double stod(const string& str, size_t* idx) {
250 return as_float<double>("stod", str, idx);
331251}
332252
333#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
334long long
335stoll(const wstring& str, size_t* idx, int base)
336{
337 return as_integer<long long>( "stoll", str, idx, base );
253long double stold(const string& str, size_t* idx) {
254 return as_float<long double>("stold", str, idx);
338255}
339#endif
340256
341unsigned long long
342stoull(const string& str, size_t* idx, int base)
343{
344 return as_integer<unsigned long long>( "stoull", str, idx, base );
257#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
258int stoi(const wstring& str, size_t* idx, int base) {
259 return as_integer<int>("stoi", str, idx, base);
345260}
346261
347#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
348unsigned long long
349stoull(const wstring& str, size_t* idx, int base)
350{
351 return as_integer<unsigned long long>( "stoull", str, idx, base );
262long stol(const wstring& str, size_t* idx, int base) {
263 return as_integer<long>("stol", str, idx, base);
352264}
353#endif
354265
355float
356stof(const string& str, size_t* idx)
357{
358 return as_float<float>( "stof", str, idx );
266unsigned long stoul(const wstring& str, size_t* idx, int base) {
267 return as_integer<unsigned long>("stoul", str, idx, base);
359268}
360269
361#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
362float
363stof(const wstring& str, size_t* idx)
364{
365 return as_float<float>( "stof", str, idx );
270long long stoll(const wstring& str, size_t* idx, int base) {
271 return as_integer<long long>("stoll", str, idx, base);
366272}
367#endif
368273
369double
370stod(const string& str, size_t* idx)
371{
372 return as_float<double>( "stod", str, idx );
274unsigned long long stoull(const wstring& str, size_t* idx, int base) {
275 return as_integer<unsigned long long>("stoull", str, idx, base);
373276}
374277
375#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
376double
377stod(const wstring& str, size_t* idx)
378{
379 return as_float<double>( "stod", str, idx );
278float stof(const wstring& str, size_t* idx) {
279 return as_float<float>("stof", str, idx);
380280}
381#endif
382281
383long double
384stold(const string& str, size_t* idx)
385{
386 return as_float<long double>( "stold", str, idx );
282double stod(const wstring& str, size_t* idx) {
283 return as_float<double>("stod", str, idx);
387284}
388285
389#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
390long double
391stold(const wstring& str, size_t* idx)
392{
393 return as_float<long double>( "stold", str, idx );
286long double stold(const wstring& str, size_t* idx) {
287 return as_float<long double>("stold", str, idx);
394288}
395#endif
289#endif // !_LIBCPP_HAS_NO_WIDE_CHARACTERS
396290
397291// to_string
398292
......@@ -402,21 +296,15 @@ namespace
402296// as_string
403297
404298template<typename S, typename P, typename V >
405inline
406S
407as_string(P sprintf_like, S s, const typename S::value_type* fmt, V a)
408{
299inline S as_string(P sprintf_like, S s, const typename S::value_type* fmt, V a) {
409300 typedef typename S::size_type size_type;
410301 size_type available = s.size();
411 while (true)
412 {
302 while (true) {
413303 int status = sprintf_like(&s[0], available + 1, fmt, a);
414 if ( status >= 0 )
415 {
304 if (status >= 0) {
416305 size_type used = static_cast<size_type>(status);
417 if ( used <= available )
418 {
419 s.resize( used );
306 if (used <= available) {
307 s.resize(used);
420308 break;
421309 }
422310 available = used; // Assume this is advice of how much space we need.
......@@ -432,11 +320,8 @@ template <class S>
432320struct initial_string;
433321
434322template <>
435struct initial_string<string>
436{
437 string
438 operator()() const
439 {
323struct initial_string<string> {
324 string operator()() const {
440325 string s;
441326 s.resize(s.capacity());
442327 return s;
......@@ -445,11 +330,8 @@ struct initial_string<string>
445330
446331#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
447332template <>
448struct initial_string<wstring>
449{
450 wstring
451 operator()() const
452 {
333struct initial_string<wstring> {
334 wstring operator()() const {
453335 wstring s(20, wchar_t());
454336 s.resize(s.capacity());
455337 return s;
......@@ -458,10 +340,7 @@ struct initial_string<wstring>
458340
459341typedef int (*wide_printf)(wchar_t* __restrict, size_t, const wchar_t*__restrict, ...);
460342
461inline
462wide_printf
463get_swprintf()
464{
343inline wide_printf get_swprintf() {
465344#ifndef _LIBCPP_MSVCRT
466345 return swprintf;
467346#else
......@@ -471,8 +350,7 @@ get_swprintf()
471350#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
472351
473352template <typename S, typename V>
474S i_to_string(V v)
475{
353S i_to_string(V v) {
476354// numeric_limits::digits10 returns value less on 1 than desired for unsigned numbers.
477355// For example, for 1-byte unsigned value digits10 is 2 (999 can not be represented),
478356// so we need +1 here.
lib/libcxx/src/strstream.cpp+13-8
......@@ -6,13 +6,16 @@
66//
77//===----------------------------------------------------------------------===//
88
9#include "strstream"
10#include "algorithm"
11#include "climits"
12#include "cstring"
13#include "cstdlib"
14#include "__debug"
15#include "__undef_macros"
9#include <__assert>
10#include <__utility/unreachable.h>
11#include <algorithm>
12#include <climits>
13#include <cstdlib>
14#include <cstring>
15#include <strstream>
16
17_LIBCPP_PUSH_MACROS
18#include <__undef_macros>
1619
1720_LIBCPP_BEGIN_NAMESPACE_STD
1821
......@@ -268,7 +271,7 @@ strstreambuf::seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmod
268271 newoff = seekhigh - eback();
269272 break;
270273 default:
271 _LIBCPP_UNREACHABLE();
274 __libcpp_unreachable();
272275 }
273276 newoff += __off;
274277 if (0 <= newoff && newoff <= seekhigh - eback())
......@@ -333,3 +336,5 @@ strstream::~strstream()
333336}
334337
335338_LIBCPP_END_NAMESPACE_STD
339
340_LIBCPP_POP_MACROS
lib/libcxx/src/support/ibm/xlocale_zos.cpp+9-8
......@@ -6,6 +6,7 @@
66//
77//===----------------------------------------------------------------------===//
88
9#include <__assert>
910#include <__support/ibm/xlocale.h>
1011#include <sstream>
1112#include <vector>
......@@ -31,7 +32,7 @@ locale_t newlocale(int category_mask, const char* locale, locale_t base) {
3132 }
3233 }
3334 }
34
35
3536 // Create new locale.
3637 locale_t newloc = new locale_struct();
3738
......@@ -74,18 +75,18 @@ locale_t uselocale(locale_t newloc) {
7475
7576 if (newloc) {
7677 // Set locales and check for errors.
77 bool is_error =
78 (newloc->category_mask & LC_COLLATE_MASK &&
78 bool is_error =
79 (newloc->category_mask & LC_COLLATE_MASK &&
7980 setlocale(LC_COLLATE, newloc->lc_collate.c_str()) == NULL) ||
80 (newloc->category_mask & LC_CTYPE_MASK &&
81 (newloc->category_mask & LC_CTYPE_MASK &&
8182 setlocale(LC_CTYPE, newloc->lc_ctype.c_str()) == NULL) ||
82 (newloc->category_mask & LC_MONETARY_MASK &&
83 (newloc->category_mask & LC_MONETARY_MASK &&
8384 setlocale(LC_MONETARY, newloc->lc_monetary.c_str()) == NULL) ||
84 (newloc->category_mask & LC_NUMERIC_MASK &&
85 (newloc->category_mask & LC_NUMERIC_MASK &&
8586 setlocale(LC_NUMERIC, newloc->lc_numeric.c_str()) == NULL) ||
86 (newloc->category_mask & LC_TIME_MASK &&
87 (newloc->category_mask & LC_TIME_MASK &&
8788 setlocale(LC_TIME, newloc->lc_time.c_str()) == NULL) ||
88 (newloc->category_mask & LC_MESSAGES_MASK &&
89 (newloc->category_mask & LC_MESSAGES_MASK &&
8990 setlocale(LC_MESSAGES, newloc->lc_messages.c_str()) == NULL);
9091
9192 if (is_error) {
lib/libcxx/src/support/runtime/exception_fallback.ipp+2-4
......@@ -11,9 +11,8 @@
1111
1212namespace std {
1313
14_LIBCPP_SAFE_STATIC static std::terminate_handler __terminate_handler;
15_LIBCPP_SAFE_STATIC static std::unexpected_handler __unexpected_handler;
16
14static constinit std::terminate_handler __terminate_handler = nullptr;
15static constinit std::unexpected_handler __unexpected_handler = nullptr;
1716
1817// libcxxrt provides implementations of these functions itself.
1918unexpected_handler
......@@ -26,7 +25,6 @@ unexpected_handler
2625get_unexpected() noexcept
2726{
2827 return __libcpp_atomic_load(&__unexpected_handler);
29
3028}
3129
3230_LIBCPP_NORETURN
lib/libcxx/src/support/runtime/new_handler_fallback.ipp+1-1
......@@ -9,7 +9,7 @@
99
1010namespace std {
1111
12_LIBCPP_SAFE_STATIC static std::new_handler __new_handler;
12static constinit std::new_handler __new_handler = nullptr;
1313
1414new_handler
1515set_new_handler(new_handler handler) noexcept
lib/libcxx/src/support/win32/locale_win32.cpp+3-3
......@@ -97,10 +97,10 @@ int snprintf_l(char *ret, size_t n, locale_t loc, const char *format, ...)
9797 ret, n, format, loc, ap);
9898#else
9999 __libcpp_locale_guard __current(loc);
100#pragma clang diagnostic push
101#pragma clang diagnostic ignored "-Wformat-nonliteral"
100 _LIBCPP_DIAGNOSTIC_PUSH
101 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wformat-nonliteral")
102102 int result = vsnprintf( ret, n, format, ap );
103#pragma clang diagnostic pop
103 _LIBCPP_DIAGNOSTIC_POP
104104#endif
105105 va_end(ap);
106106 return result;
lib/libcxx/src/support/win32/support.cpp+6-6
......@@ -23,10 +23,10 @@ int __libcpp_vasprintf( char **sptr, const char *__restrict format, va_list ap )
2323 // Query the count required.
2424 va_list ap_copy;
2525 va_copy(ap_copy, ap);
26#pragma clang diagnostic push
27#pragma clang diagnostic ignored "-Wformat-nonliteral"
26 _LIBCPP_DIAGNOSTIC_PUSH
27 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wformat-nonliteral")
2828 int count = vsnprintf( NULL, 0, format, ap_copy );
29#pragma clang diagnostic pop
29 _LIBCPP_DIAGNOSTIC_POP
3030 va_end(ap_copy);
3131 if (count < 0)
3232 return count;
......@@ -36,10 +36,10 @@ int __libcpp_vasprintf( char **sptr, const char *__restrict format, va_list ap )
3636 return -1;
3737 // If we haven't used exactly what was required, something is wrong.
3838 // Maybe bug in vsnprintf. Report the error and return.
39#pragma clang diagnostic push
40#pragma clang diagnostic ignored "-Wformat-nonliteral"
39 _LIBCPP_DIAGNOSTIC_PUSH
40 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wformat-nonliteral")
4141 if (vsnprintf(p, buffer_size, format, ap) != count) {
42#pragma clang diagnostic pop
42 _LIBCPP_DIAGNOSTIC_POP
4343 free(p);
4444 return -1;
4545 }
lib/libcxx/src/system_error.cpp+13-10
......@@ -6,18 +6,21 @@
66//
77//===----------------------------------------------------------------------===//
88
9#include "__config"
9#include <__config>
10#ifdef _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS
11# define _LIBCPP_ERROR_CATEGORY_DEFINE_LEGACY_INLINE_FUNCTIONS
12#endif
1013
11#include "system_error"
14#include <__assert>
15#include <cerrno>
16#include <cstdio>
17#include <cstdlib>
18#include <cstring>
19#include <string>
20#include <string.h>
21#include <system_error>
1222
1323#include "include/config_elast.h"
14#include "cerrno"
15#include "cstring"
16#include "cstdio"
17#include "cstdlib"
18#include "string"
19#include "string.h"
20#include "__debug"
2124
2225#if defined(__ANDROID__)
2326#include <android/api-level.h>
......@@ -27,7 +30,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2730
2831// class error_category
2932
30#if defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
33#if defined(_LIBCPP_ERROR_CATEGORY_DEFINE_LEGACY_INLINE_FUNCTIONS)
3134error_category::error_category() noexcept
3235{
3336}
lib/libcxx/src/thread.cpp+14-8
......@@ -6,14 +6,15 @@
66//
77//===----------------------------------------------------------------------===//
88
9#include "__config"
9#include <__config>
10
1011#ifndef _LIBCPP_HAS_NO_THREADS
1112
12#include "thread"
13#include "exception"
14#include "vector"
15#include "future"
16#include "limits"
13#include <exception>
14#include <future>
15#include <limits>
16#include <thread>
17#include <vector>
1718
1819#if __has_include(<unistd.h>)
1920# include <unistd.h> // for sysconf
......@@ -114,8 +115,13 @@ sleep_for(const chrono::nanoseconds& ns)
114115__thread_specific_ptr<__thread_struct>&
115116__thread_local_data()
116117{
117 static __thread_specific_ptr<__thread_struct> __p;
118 return __p;
118 // Even though __thread_specific_ptr's destructor doesn't actually destroy
119 // anything (see comments there), we can't call it at all because threads may
120 // outlive the static variable and calling its destructor means accessing an
121 // object outside of its lifetime, which is UB.
122 alignas(__thread_specific_ptr<__thread_struct>) static char __b[sizeof(__thread_specific_ptr<__thread_struct>)];
123 static __thread_specific_ptr<__thread_struct>* __p = new (__b) __thread_specific_ptr<__thread_struct>();
124 return *__p;
119125}
120126
121127// __thread_struct_imp
lib/libcxx/src/typeinfo.cpp+2-1
......@@ -6,9 +6,10 @@
66//
77//===----------------------------------------------------------------------===//
88
9#include "typeinfo"
9#include <typeinfo>
1010
1111#if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_ABI_VCRUNTIME)
12
1213#include <string.h>
1314
1415int std::type_info::__compare(const type_info &__rhs) const noexcept {
lib/libcxx/src/utility.cpp+1-1
......@@ -6,7 +6,7 @@
66//
77//===----------------------------------------------------------------------===//
88
9#include "utility"
9#include <utility>
1010
1111_LIBCPP_BEGIN_NAMESPACE_STD
1212
lib/libcxx/src/valarray.cpp+1-1
......@@ -6,7 +6,7 @@
66//
77//===----------------------------------------------------------------------===//
88
9#include "valarray"
9#include <valarray>
1010
1111_LIBCPP_BEGIN_NAMESPACE_STD
1212
lib/libcxx/src/variant.cpp+1-1
......@@ -6,7 +6,7 @@
66//
77//===----------------------------------------------------------------------===//
88
9#include "variant"
9#include <variant>
1010
1111namespace std {
1212
lib/libcxx/src/vector.cpp+1-1
......@@ -6,7 +6,7 @@
66//
77//===----------------------------------------------------------------------===//
88
9#include "vector"
9#include <vector>
1010
1111_LIBCPP_BEGIN_NAMESPACE_STD
1212
lib/libcxx/src/verbose_abort.cpp created+77
......@@ -0,0 +1,77 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include <__config>
10#include <__verbose_abort>
11#include <cstdarg>
12#include <cstdio>
13#include <cstdlib>
14
15#ifdef __BIONIC__
16# include <android/api-level.h>
17# if __ANDROID_API__ >= 21
18# include <syslog.h>
19extern "C" void android_set_abort_message(const char* msg);
20# else
21# include <assert.h>
22# endif // __ANDROID_API__ >= 21
23#endif // __BIONIC__
24
25#if defined(__APPLE__) && __has_include(<CrashReporterClient.h>)
26# include <CrashReporterClient.h>
27#endif
28
29_LIBCPP_BEGIN_NAMESPACE_STD
30
31_LIBCPP_WEAK
32void __libcpp_verbose_abort(char const* format, ...) {
33 // Write message to stderr. We do this before formatting into a
34 // buffer so that we still get some information out if that fails.
35 {
36 va_list list;
37 va_start(list, format);
38 std::vfprintf(stderr, format, list);
39 va_end(list);
40 }
41
42 // Format the arguments into an allocated buffer for CrashReport & friends.
43 // We leak the buffer on purpose, since we're about to abort() anyway.
44 char* buffer; (void)buffer;
45 va_list list;
46 va_start(list, format);
47
48#if defined(__APPLE__) && __has_include(<CrashReporterClient.h>)
49 // Note that we should technically synchronize accesses here (by e.g. taking a lock),
50 // however concretely we're only setting a pointer, so the likelihood of a race here
51 // is low.
52 vasprintf(&buffer, format, list);
53 CRSetCrashLogMessage(buffer);
54#elif defined(__BIONIC__)
55 vasprintf(&buffer, format, list);
56
57# if __ANDROID_API__ >= 21
58 // Show error in tombstone.
59 android_set_abort_message(buffer);
60
61 // Show error in logcat.
62 openlog("libc++", 0, 0);
63 syslog(LOG_CRIT, "%s", buffer);
64 closelog();
65# else
66 // The good error reporting wasn't available in Android until L. Since we're
67 // about to abort anyway, just call __assert2, which will log _somewhere_
68 // (tombstone and/or logcat) in older releases.
69 __assert2(__FILE__, __LINE__, __func__, buffer);
70# endif // __ANDROID_API__ >= 21
71#endif
72 va_end(list);
73
74 std::abort();
75}
76
77_LIBCPP_END_NAMESPACE_STD
src/libcxx.zig+2
......@@ -54,6 +54,7 @@ const libcxx_files = [_][]const u8{
5454 "src/ios.cpp",
5555 "src/ios.instantiations.cpp",
5656 "src/iostream.cpp",
57 "src/legacy_debug_handler.cpp",
5758 "src/legacy_pointer_safety.cpp",
5859 "src/locale.cpp",
5960 "src/memory.cpp",
......@@ -85,6 +86,7 @@ const libcxx_files = [_][]const u8{
8586 "src/valarray.cpp",
8687 "src/variant.cpp",
8788 "src/vector.cpp",
89 "src/verbose_abort.cpp",
8890};
8991
9092pub fn buildLibCXX(comp: *Compilation) !void {