authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-01 16:31:47-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-01 16:31:47-07:00
logbd680139d084b673d1f56d0e63e01936c4680a91
treef066c89b83db70814a23e5be9731686610fea92c
parentc89dd15e1be4959800dc7092d7dd4375253db7bc

update libcxx to llvm 14.0.6


585 files changed, 40096 insertions(+), 19622 deletions(-)

lib/libcxx/include/__algorithm/adjacent_find.h+1-6
......@@ -10,17 +10,14 @@
1010#ifndef _LIBCPP___ALGORITHM_ADJACENT_FIND_H
1111#define _LIBCPP___ALGORITHM_ADJACENT_FIND_H
1212
13#include <__config>
1413#include <__algorithm/comp.h>
14#include <__config>
1515#include <__iterator/iterator_traits.h>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1818#pragma GCC system_header
1919#endif
2020
21_LIBCPP_PUSH_MACROS
22#include <__undef_macros>
23
2421_LIBCPP_BEGIN_NAMESPACE_STD
2522
2623template <class _ForwardIterator, class _BinaryPredicate>
......@@ -46,6 +43,4 @@ adjacent_find(_ForwardIterator __first, _ForwardIterator __last) {
4643
4744_LIBCPP_END_NAMESPACE_STD
4845
49_LIBCPP_POP_MACROS
50
5146#endif // _LIBCPP___ALGORITHM_ADJACENT_FIND_H
lib/libcxx/include/__algorithm/all_of.h-5
......@@ -16,9 +16,6 @@
1616#pragma GCC system_header
1717#endif
1818
19_LIBCPP_PUSH_MACROS
20#include <__undef_macros>
21
2219_LIBCPP_BEGIN_NAMESPACE_STD
2320
2421template <class _InputIterator, class _Predicate>
......@@ -32,6 +29,4 @@ all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
3229
3330_LIBCPP_END_NAMESPACE_STD
3431
35_LIBCPP_POP_MACROS
36
3732#endif // _LIBCPP___ALGORITHM_ALL_OF_H
lib/libcxx/include/__algorithm/any_of.h-5
......@@ -16,9 +16,6 @@
1616#pragma GCC system_header
1717#endif
1818
19_LIBCPP_PUSH_MACROS
20#include <__undef_macros>
21
2219_LIBCPP_BEGIN_NAMESPACE_STD
2320
2421template <class _InputIterator, class _Predicate>
......@@ -32,6 +29,4 @@ any_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
3229
3330_LIBCPP_END_NAMESPACE_STD
3431
35_LIBCPP_POP_MACROS
36
3732#endif // _LIBCPP___ALGORITHM_ANY_OF_H
lib/libcxx/include/__algorithm/binary_search.h+2-8
......@@ -9,19 +9,16 @@
99#ifndef _LIBCPP___ALGORITHM_BINARY_SEARCH_H
1010#define _LIBCPP___ALGORITHM_BINARY_SEARCH_H
1111
12#include <__config>
1312#include <__algorithm/comp.h>
14#include <__algorithm/lower_bound.h>
1513#include <__algorithm/comp_ref_type.h>
14#include <__algorithm/lower_bound.h>
15#include <__config>
1616#include <__iterator/iterator_traits.h>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1919#pragma GCC system_header
2020#endif
2121
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
2522_LIBCPP_BEGIN_NAMESPACE_STD
2623
2724template <class _Compare, class _ForwardIterator, class _Tp>
......@@ -53,9 +50,6 @@ binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __va
5350 __less<typename iterator_traits<_ForwardIterator>::value_type, _Tp>());
5451}
5552
56
5753_LIBCPP_END_NAMESPACE_STD
5854
59_LIBCPP_POP_MACROS
60
6155#endif // _LIBCPP___ALGORITHM_BINARY_SEARCH_H
lib/libcxx/include/__algorithm/clamp.h+1-7
......@@ -9,21 +9,17 @@
99#ifndef _LIBCPP___ALGORITHM_CLAMP_H
1010#define _LIBCPP___ALGORITHM_CLAMP_H
1111
12#include <__algorithm/comp.h>
1213#include <__config>
1314#include <__debug>
14#include <__algorithm/comp.h>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1717#pragma GCC system_header
1818#endif
1919
20_LIBCPP_PUSH_MACROS
21#include <__undef_macros>
22
2320_LIBCPP_BEGIN_NAMESPACE_STD
2421
2522#if _LIBCPP_STD_VER > 14
26// clamp
2723template<class _Tp, class _Compare>
2824_LIBCPP_NODISCARD_EXT inline
2925_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
......@@ -47,6 +43,4 @@ clamp(const _Tp& __v, const _Tp& __lo, const _Tp& __hi)
4743
4844_LIBCPP_END_NAMESPACE_STD
4945
50_LIBCPP_POP_MACROS
51
5246#endif // _LIBCPP___ALGORITHM_CLAMP_H
lib/libcxx/include/__algorithm/comp.h-5
......@@ -15,9 +15,6 @@
1515#pragma GCC system_header
1616#endif
1717
18_LIBCPP_PUSH_MACROS
19#include <__undef_macros>
20
2118_LIBCPP_BEGIN_NAMESPACE_STD
2219
2320// I'd like to replace these with _VSTD::equal_to<void>, but can't because:
......@@ -92,6 +89,4 @@ struct __less<_T1, const _T1>
9289
9390_LIBCPP_END_NAMESPACE_STD
9491
95_LIBCPP_POP_MACROS
96
9792#endif // _LIBCPP___ALGORITHM_COMP_H
lib/libcxx/include/__algorithm/comp_ref_type.h+11-13
......@@ -10,15 +10,16 @@
1010#define _LIBCPP___ALGORITHM_COMP_REF_TYPE_H
1111
1212#include <__config>
13#include <type_traits>
13
14#ifdef _LIBCPP_DEBUG
15# include <__debug>
16# include <__utility/declval.h>
17#endif
1418
1519#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1620#pragma GCC system_header
1721#endif
1822
19_LIBCPP_PUSH_MACROS
20#include <__undef_macros>
21
2223_LIBCPP_BEGIN_NAMESPACE_STD
2324
2425#ifdef _LIBCPP_DEBUG
......@@ -27,11 +28,11 @@ template <class _Compare>
2728struct __debug_less
2829{
2930 _Compare &__comp_;
30 _LIBCPP_CONSTEXPR_AFTER_CXX17
31 _LIBCPP_CONSTEXPR_AFTER_CXX11
3132 __debug_less(_Compare& __c) : __comp_(__c) {}
3233
3334 template <class _Tp, class _Up>
34 _LIBCPP_CONSTEXPR_AFTER_CXX17
35 _LIBCPP_CONSTEXPR_AFTER_CXX11
3536 bool operator()(const _Tp& __x, const _Up& __y)
3637 {
3738 bool __r = __comp_(__x, __y);
......@@ -41,7 +42,7 @@ struct __debug_less
4142 }
4243
4344 template <class _Tp, class _Up>
44 _LIBCPP_CONSTEXPR_AFTER_CXX17
45 _LIBCPP_CONSTEXPR_AFTER_CXX11
4546 bool operator()(_Tp& __x, _Up& __y)
4647 {
4748 bool __r = __comp_(__x, __y);
......@@ -51,7 +52,7 @@ struct __debug_less
5152 }
5253
5354 template <class _LHS, class _RHS>
54 _LIBCPP_CONSTEXPR_AFTER_CXX17
55 _LIBCPP_CONSTEXPR_AFTER_CXX11
5556 inline _LIBCPP_INLINE_VISIBILITY
5657 decltype((void)declval<_Compare&>()(
5758 declval<_LHS &>(), declval<_RHS &>()))
......@@ -61,7 +62,7 @@ struct __debug_less
6162 }
6263
6364 template <class _LHS, class _RHS>
64 _LIBCPP_CONSTEXPR_AFTER_CXX17
65 _LIBCPP_CONSTEXPR_AFTER_CXX11
6566 inline _LIBCPP_INLINE_VISIBILITY
6667 void __do_compare_assert(long, _LHS &, _RHS &) {}
6768};
......@@ -73,15 +74,12 @@ struct __comp_ref_type {
7374 // Pass the comparator by lvalue reference. Or in debug mode, using a
7475 // debugging wrapper that stores a reference.
7576#ifndef _LIBCPP_DEBUG
76 typedef typename add_lvalue_reference<_Comp>::type type;
77 typedef _Comp& type;
7778#else
7879 typedef __debug_less<_Comp> type;
7980#endif
8081};
8182
82
8383_LIBCPP_END_NAMESPACE_STD
8484
85_LIBCPP_POP_MACROS
86
8785#endif // _LIBCPP___ALGORITHM_COMP_REF_TYPE_H
lib/libcxx/include/__algorithm/copy.h+1-6
......@@ -9,8 +9,8 @@
99#ifndef _LIBCPP___ALGORITHM_COPY_H
1010#define _LIBCPP___ALGORITHM_COPY_H
1111
12#include <__config>
1312#include <__algorithm/unwrap_iter.h>
13#include <__config>
1414#include <__iterator/iterator_traits.h>
1515#include <cstring>
1616#include <type_traits>
......@@ -19,9 +19,6 @@
1919#pragma GCC system_header
2020#endif
2121
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
2522_LIBCPP_BEGIN_NAMESPACE_STD
2623
2724// copy
......@@ -77,6 +74,4 @@ copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
7774
7875_LIBCPP_END_NAMESPACE_STD
7976
80_LIBCPP_POP_MACROS
81
8277#endif // _LIBCPP___ALGORITHM_COPY_H
lib/libcxx/include/__algorithm/copy_backward.h+1-6
......@@ -9,8 +9,8 @@
99#ifndef _LIBCPP___ALGORITHM_COPY_BACKWARD_H
1010#define _LIBCPP___ALGORITHM_COPY_BACKWARD_H
1111
12#include <__config>
1312#include <__algorithm/unwrap_iter.h>
13#include <__config>
1414#include <__iterator/iterator_traits.h>
1515#include <cstring>
1616#include <type_traits>
......@@ -19,9 +19,6 @@
1919#pragma GCC system_header
2020#endif
2121
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
2522_LIBCPP_BEGIN_NAMESPACE_STD
2623
2724template <class _BidirectionalIterator, class _OutputIterator>
......@@ -79,6 +76,4 @@ copy_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last,
7976
8077_LIBCPP_END_NAMESPACE_STD
8178
82_LIBCPP_POP_MACROS
83
8479#endif // _LIBCPP___ALGORITHM_COPY_BACKWARD_H
lib/libcxx/include/__algorithm/copy_if.h-9
......@@ -10,18 +10,11 @@
1010#define _LIBCPP___ALGORITHM_COPY_IF_H
1111
1212#include <__config>
13#include <__algorithm/unwrap_iter.h>
14#include <__iterator/iterator_traits.h>
15#include <cstring>
16#include <type_traits>
1713
1814#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1915#pragma GCC system_header
2016#endif
2117
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
2518_LIBCPP_BEGIN_NAMESPACE_STD
2619
2720template<class _InputIterator, class _OutputIterator, class _Predicate>
......@@ -43,6 +36,4 @@ copy_if(_InputIterator __first, _InputIterator __last,
4336
4437_LIBCPP_END_NAMESPACE_STD
4538
46_LIBCPP_POP_MACROS
47
4839#endif // _LIBCPP___ALGORITHM_COPY_IF_H
lib/libcxx/include/__algorithm/copy_n.h+3-9
......@@ -9,20 +9,15 @@
99#ifndef _LIBCPP___ALGORITHM_COPY_N_H
1010#define _LIBCPP___ALGORITHM_COPY_N_H
1111
12#include <__config>
1312#include <__algorithm/copy.h>
14#include <__algorithm/unwrap_iter.h>
13#include <__config>
1514#include <__iterator/iterator_traits.h>
16#include <cstring>
1715#include <type_traits>
1816
1917#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2018#pragma GCC system_header
2119#endif
2220
23_LIBCPP_PUSH_MACROS
24#include <__undef_macros>
25
2621_LIBCPP_BEGIN_NAMESPACE_STD
2722
2823template<class _InputIterator, class _Size, class _OutputIterator>
......@@ -60,13 +55,12 @@ typename enable_if
6055>::type
6156copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result)
6257{
58 typedef typename iterator_traits<_InputIterator>::difference_type difference_type;
6359 typedef decltype(_VSTD::__convert_to_integral(__orig_n)) _IntegralSize;
6460 _IntegralSize __n = __orig_n;
65 return _VSTD::copy(__first, __first + __n, __result);
61 return _VSTD::copy(__first, __first + difference_type(__n), __result);
6662}
6763
6864_LIBCPP_END_NAMESPACE_STD
6965
70_LIBCPP_POP_MACROS
71
7266#endif // _LIBCPP___ALGORITHM_COPY_N_H
lib/libcxx/include/__algorithm/count.h-5
......@@ -17,9 +17,6 @@
1717#pragma GCC system_header
1818#endif
1919
20_LIBCPP_PUSH_MACROS
21#include <__undef_macros>
22
2320_LIBCPP_BEGIN_NAMESPACE_STD
2421
2522template <class _InputIterator, class _Tp>
......@@ -35,6 +32,4 @@ _LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_C
3532
3633_LIBCPP_END_NAMESPACE_STD
3734
38_LIBCPP_POP_MACROS
39
4035#endif // _LIBCPP___ALGORITHM_COUNT_H
lib/libcxx/include/__algorithm/count_if.h-5
......@@ -17,9 +17,6 @@
1717#pragma GCC system_header
1818#endif
1919
20_LIBCPP_PUSH_MACROS
21#include <__undef_macros>
22
2320_LIBCPP_BEGIN_NAMESPACE_STD
2421
2522template <class _InputIterator, class _Predicate>
......@@ -35,6 +32,4 @@ _LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_C
3532
3633_LIBCPP_END_NAMESPACE_STD
3734
38_LIBCPP_POP_MACROS
39
4035#endif // _LIBCPP___ALGORITHM_COUNT_IF_H
lib/libcxx/include/__algorithm/equal.h+4-9
......@@ -10,18 +10,15 @@
1010#ifndef _LIBCPP___ALGORITHM_EQUAL_H
1111#define _LIBCPP___ALGORITHM_EQUAL_H
1212
13#include <__config>
1413#include <__algorithm/comp.h>
14#include <__config>
15#include <__iterator/distance.h>
1516#include <__iterator/iterator_traits.h>
16#include <iterator> // FIXME: replace with <__iterator/distance.h> when it lands
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1919#pragma GCC system_header
2020#endif
2121
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
2522_LIBCPP_BEGIN_NAMESPACE_STD
2623
2724template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
......@@ -60,14 +57,14 @@ __equal(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _Random
6057 if (_VSTD::distance(__first1, __last1) != _VSTD::distance(__first2, __last2))
6158 return false;
6259 return _VSTD::equal<_RandomAccessIterator1, _RandomAccessIterator2,
63 typename add_lvalue_reference<_BinaryPredicate>::type>(__first1, __last1, __first2, __pred);
60 _BinaryPredicate&>(__first1, __last1, __first2, __pred);
6461}
6562
6663template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
6764_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 bool
6865equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2,
6966 _BinaryPredicate __pred) {
70 return _VSTD::__equal<typename add_lvalue_reference<_BinaryPredicate>::type>(
67 return _VSTD::__equal<_BinaryPredicate&>(
7168 __first1, __last1, __first2, __last2, __pred, typename iterator_traits<_InputIterator1>::iterator_category(),
7269 typename iterator_traits<_InputIterator2>::iterator_category());
7370}
......@@ -85,6 +82,4 @@ equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first
8582
8683_LIBCPP_END_NAMESPACE_STD
8784
88_LIBCPP_POP_MACROS
89
9085#endif // _LIBCPP___ALGORITHM_EQUAL_H
lib/libcxx/include/__algorithm/equal_range.h+1-6
......@@ -9,21 +9,18 @@
99#ifndef _LIBCPP___ALGORITHM_EQUAL_RANGE_H
1010#define _LIBCPP___ALGORITHM_EQUAL_RANGE_H
1111
12#include <__config>
1312#include <__algorithm/comp.h>
1413#include <__algorithm/comp_ref_type.h>
1514#include <__algorithm/half_positive.h>
1615#include <__algorithm/lower_bound.h>
1716#include <__algorithm/upper_bound.h>
17#include <__config>
1818#include <iterator>
1919
2020#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2121#pragma GCC system_header
2222#endif
2323
24_LIBCPP_PUSH_MACROS
25#include <__undef_macros>
26
2724_LIBCPP_BEGIN_NAMESPACE_STD
2825
2926template <class _Compare, class _ForwardIterator, class _Tp>
......@@ -82,6 +79,4 @@ equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __valu
8279
8380_LIBCPP_END_NAMESPACE_STD
8481
85_LIBCPP_POP_MACROS
86
8782#endif // _LIBCPP___ALGORITHM_EQUAL_RANGE_H
lib/libcxx/include/__algorithm/fill.h+1-6
......@@ -9,8 +9,8 @@
99#ifndef _LIBCPP___ALGORITHM_FILL_H
1010#define _LIBCPP___ALGORITHM_FILL_H
1111
12#include <__config>
1312#include <__algorithm/fill_n.h>
13#include <__config>
1414#include <__iterator/iterator_traits.h>
1515#include <type_traits>
1616
......@@ -18,9 +18,6 @@
1818#pragma GCC system_header
1919#endif
2020
21_LIBCPP_PUSH_MACROS
22#include <__undef_macros>
23
2421_LIBCPP_BEGIN_NAMESPACE_STD
2522
2623template <class _ForwardIterator, class _Tp>
......@@ -50,6 +47,4 @@ fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_)
5047
5148_LIBCPP_END_NAMESPACE_STD
5249
53_LIBCPP_POP_MACROS
54
5550#endif // _LIBCPP___ALGORITHM_FILL_H
lib/libcxx/include/__algorithm/fill_n.h-5
......@@ -17,9 +17,6 @@
1717#pragma GCC system_header
1818#endif
1919
20_LIBCPP_PUSH_MACROS
21#include <__undef_macros>
22
2320_LIBCPP_BEGIN_NAMESPACE_STD
2421
2522template <class _OutputIterator, class _Size, class _Tp>
......@@ -42,6 +39,4 @@ fill_n(_OutputIterator __first, _Size __n, const _Tp& __value_)
4239
4340_LIBCPP_END_NAMESPACE_STD
4441
45_LIBCPP_POP_MACROS
46
4742#endif // _LIBCPP___ALGORITHM_FILL_N_H
lib/libcxx/include/__algorithm/find.h-5
......@@ -16,9 +16,6 @@
1616#pragma GCC system_header
1717#endif
1818
19_LIBCPP_PUSH_MACROS
20#include <__undef_macros>
21
2219_LIBCPP_BEGIN_NAMESPACE_STD
2320
2421template <class _InputIterator, class _Tp>
......@@ -32,6 +29,4 @@ find(_InputIterator __first, _InputIterator __last, const _Tp& __value_) {
3229
3330_LIBCPP_END_NAMESPACE_STD
3431
35_LIBCPP_POP_MACROS
36
3732#endif // _LIBCPP___ALGORITHM_FIND_H
lib/libcxx/include/__algorithm/find_end.h+7-11
......@@ -10,18 +10,14 @@
1010#ifndef _LIBCPP___ALGORITHM_FIND_END_OF_H
1111#define _LIBCPP___ALGORITHM_FIND_END_OF_H
1212
13#include <__config>
1413#include <__algorithm/comp.h>
14#include <__config>
1515#include <__iterator/iterator_traits.h>
16#include <type_traits>
1716
1817#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1918#pragma GCC system_header
2019#endif
2120
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
2521_LIBCPP_BEGIN_NAMESPACE_STD
2622
2723template <class _BinaryPredicate, class _ForwardIterator1, class _ForwardIterator2>
......@@ -99,14 +95,16 @@ template <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAcc
9995_LIBCPP_CONSTEXPR_AFTER_CXX11 _RandomAccessIterator1 __find_end(
10096 _RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2,
10197 _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;
102100 // Take advantage of knowing source and pattern lengths. Stop short when source is smaller than pattern
103 typename iterator_traits<_RandomAccessIterator2>::difference_type __len2 = __last2 - __first2;
101 _D2 __len2 = __last2 - __first2;
104102 if (__len2 == 0)
105103 return __last1;
106 typename iterator_traits<_RandomAccessIterator1>::difference_type __len1 = __last1 - __first1;
104 _D1 __len1 = __last1 - __first1;
107105 if (__len1 < __len2)
108106 return __last1;
109 const _RandomAccessIterator1 __s = __first1 + (__len2 - 1); // End of pattern match can't go before here
107 const _RandomAccessIterator1 __s = __first1 + _D1(__len2 - 1); // End of pattern match can't go before here
110108 _RandomAccessIterator1 __l1 = __last1;
111109 _RandomAccessIterator2 __l2 = __last2;
112110 --__l2;
......@@ -134,7 +132,7 @@ template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredica
134132_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator1
135133find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2,
136134 _BinaryPredicate __pred) {
137 return _VSTD::__find_end<typename add_lvalue_reference<_BinaryPredicate>::type>(
135 return _VSTD::__find_end<_BinaryPredicate&>(
138136 __first1, __last1, __first2, __last2, __pred, typename iterator_traits<_ForwardIterator1>::iterator_category(),
139137 typename iterator_traits<_ForwardIterator2>::iterator_category());
140138}
......@@ -149,6 +147,4 @@ find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator
149147
150148_LIBCPP_END_NAMESPACE_STD
151149
152_LIBCPP_POP_MACROS
153
154150#endif // _LIBCPP___ALGORITHM_FIND_END_OF_H
lib/libcxx/include/__algorithm/find_first_of.h+1-6
......@@ -10,17 +10,14 @@
1010#ifndef _LIBCPP___ALGORITHM_FIND_FIRST_OF_H
1111#define _LIBCPP___ALGORITHM_FIND_FIRST_OF_H
1212
13#include <__config>
1413#include <__algorithm/comp.h>
14#include <__config>
1515#include <__iterator/iterator_traits.h>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1818#pragma GCC system_header
1919#endif
2020
21_LIBCPP_PUSH_MACROS
22#include <__undef_macros>
23
2421_LIBCPP_BEGIN_NAMESPACE_STD
2522
2623template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
......@@ -52,6 +49,4 @@ _LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_C
5249
5350_LIBCPP_END_NAMESPACE_STD
5451
55_LIBCPP_POP_MACROS
56
5752#endif // _LIBCPP___ALGORITHM_FIND_FIRST_OF_H
lib/libcxx/include/__algorithm/find_if.h-5
......@@ -16,9 +16,6 @@
1616#pragma GCC system_header
1717#endif
1818
19_LIBCPP_PUSH_MACROS
20#include <__undef_macros>
21
2219_LIBCPP_BEGIN_NAMESPACE_STD
2320
2421template <class _InputIterator, class _Predicate>
......@@ -32,6 +29,4 @@ find_if(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
3229
3330_LIBCPP_END_NAMESPACE_STD
3431
35_LIBCPP_POP_MACROS
36
3732#endif // _LIBCPP___ALGORITHM_FIND_IF_H
lib/libcxx/include/__algorithm/find_if_not.h-5
......@@ -16,9 +16,6 @@
1616#pragma GCC system_header
1717#endif
1818
19_LIBCPP_PUSH_MACROS
20#include <__undef_macros>
21
2219_LIBCPP_BEGIN_NAMESPACE_STD
2320
2421template <class _InputIterator, class _Predicate>
......@@ -32,6 +29,4 @@ find_if_not(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
3229
3330_LIBCPP_END_NAMESPACE_STD
3431
35_LIBCPP_POP_MACROS
36
3732#endif // _LIBCPP___ALGORITHM_FIND_IF_NOT_H
lib/libcxx/include/__algorithm/for_each.h-5
......@@ -16,9 +16,6 @@
1616#pragma GCC system_header
1717#endif
1818
19_LIBCPP_PUSH_MACROS
20#include <__undef_macros>
21
2219_LIBCPP_BEGIN_NAMESPACE_STD
2320
2421template <class _InputIterator, class _Function>
......@@ -32,6 +29,4 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _Function for_eac
3229
3330_LIBCPP_END_NAMESPACE_STD
3431
35_LIBCPP_POP_MACROS
36
3732#endif // _LIBCPP___ALGORITHM_FOR_EACH_H
lib/libcxx/include/__algorithm/for_each_n.h-5
......@@ -17,9 +17,6 @@
1717#pragma GCC system_header
1818#endif
1919
20_LIBCPP_PUSH_MACROS
21#include <__undef_macros>
22
2320_LIBCPP_BEGIN_NAMESPACE_STD
2421
2522#if _LIBCPP_STD_VER > 14
......@@ -42,6 +39,4 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _InputIterator fo
4239
4340_LIBCPP_END_NAMESPACE_STD
4441
45_LIBCPP_POP_MACROS
46
4742#endif // _LIBCPP___ALGORITHM_FOR_EACH_N_H
lib/libcxx/include/__algorithm/generate.h-5
......@@ -15,9 +15,6 @@
1515#pragma GCC system_header
1616#endif
1717
18_LIBCPP_PUSH_MACROS
19#include <__undef_macros>
20
2118_LIBCPP_BEGIN_NAMESPACE_STD
2219
2320template <class _ForwardIterator, class _Generator>
......@@ -31,6 +28,4 @@ generate(_ForwardIterator __first, _ForwardIterator __last, _Generator __gen)
3128
3229_LIBCPP_END_NAMESPACE_STD
3330
34_LIBCPP_POP_MACROS
35
3631#endif // _LIBCPP___ALGORITHM_GENERATE_H
lib/libcxx/include/__algorithm/generate_n.h-5
......@@ -16,9 +16,6 @@
1616#pragma GCC system_header
1717#endif
1818
19_LIBCPP_PUSH_MACROS
20#include <__undef_macros>
21
2219_LIBCPP_BEGIN_NAMESPACE_STD
2320
2421template <class _OutputIterator, class _Size, class _Generator>
......@@ -35,6 +32,4 @@ generate_n(_OutputIterator __first, _Size __orig_n, _Generator __gen)
3532
3633_LIBCPP_END_NAMESPACE_STD
3734
38_LIBCPP_POP_MACROS
39
4035#endif // _LIBCPP___ALGORITHM_GENERATE_N_H
lib/libcxx/include/__algorithm/half_positive.h-5
......@@ -16,9 +16,6 @@
1616#pragma GCC system_header
1717#endif
1818
19_LIBCPP_PUSH_MACROS
20#include <__undef_macros>
21
2219_LIBCPP_BEGIN_NAMESPACE_STD
2320
2421// Perform division by two quickly for positive integers (llvm.org/PR39129)
......@@ -49,6 +46,4 @@ __half_positive(_Tp __value)
4946
5047_LIBCPP_END_NAMESPACE_STD
5148
52_LIBCPP_POP_MACROS
53
5449#endif // _LIBCPP___ALGORITHM_HALF_POSITIVE_H
lib/libcxx/include/__algorithm/in_in_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_IN_OUT_RESULT_H
11#define _LIBCPP___ALGORITHM_IN_IN_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 !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
24
25namespace ranges {
26
27template <class _I1, class _I2, class _O1>
28struct in_in_out_result {
29 [[no_unique_address]] _I1 in1;
30 [[no_unique_address]] _I2 in2;
31 [[no_unique_address]] _O1 out;
32
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>
35 _LIBCPP_HIDE_FROM_ABI constexpr
36 operator in_in_out_result<_II1, _II2, _OO1>() const& {
37 return {in1, in2, out};
38 }
39
40 template <class _II1, class _II2, class _OO1>
41 requires convertible_to<_I1, _II1> && convertible_to<_I2, _II2> && convertible_to<_O1, _OO1>
42 _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 }
46};
47
48} // namespace ranges
49
50#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
51
52_LIBCPP_END_NAMESPACE_STD
53
54#endif // _LIBCPP___ALGORITHM_IN_IN_OUT_RESULT_H
lib/libcxx/include/__algorithm/in_in_result.h created+51
......@@ -0,0 +1,51 @@
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_IN_RESULT_H
11#define _LIBCPP___ALGORITHM_IN_IN_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 !defined(_LIBCPP_HAS_NO_CONCEPTS)
24
25namespace ranges {
26
27template <class _I1, class _I2>
28struct in_in_result {
29 [[no_unique_address]] _I1 in1;
30 [[no_unique_address]] _I2 in2;
31
32 template <class _II1, class _II2>
33 requires convertible_to<const _I1&, _II1> && convertible_to<const _I2&, _II2>
34 _LIBCPP_HIDE_FROM_ABI constexpr
35 operator in_in_result<_II1, _II2>() const & {
36 return {in1, in2};
37 }
38
39 template <class _II1, class _II2>
40 requires convertible_to<_I1, _II1> && convertible_to<_I2, _II2>
41 _LIBCPP_HIDE_FROM_ABI constexpr
42 operator in_in_result<_II1, _II2>() && { return {_VSTD::move(in1), _VSTD::move(in2)}; }
43};
44
45} // namespace ranges
46
47#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
48
49_LIBCPP_END_NAMESPACE_STD
50
51#endif // _LIBCPP___ALGORITHM_IN_IN_RESULT_H
lib/libcxx/include/__algorithm/in_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_RESULT_H
11#define _LIBCPP___ALGORITHM_IN_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 !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
24
25namespace ranges {
26
27template<class _InputIterator, class _OutputIterator>
28struct in_out_result {
29 [[no_unique_address]] _InputIterator in;
30 [[no_unique_address]] _OutputIterator out;
31
32 template <class _InputIterator2, class _OutputIterator2>
33 requires convertible_to<const _InputIterator&, _InputIterator2> && convertible_to<const _OutputIterator&,
34 _OutputIterator2>
35 _LIBCPP_HIDE_FROM_ABI
36 constexpr operator in_out_result<_InputIterator2, _OutputIterator2>() const & {
37 return {in, out};
38 }
39
40 template <class _InputIterator2, class _OutputIterator2>
41 requires convertible_to<_InputIterator, _InputIterator2> && convertible_to<_OutputIterator, _OutputIterator2>
42 _LIBCPP_HIDE_FROM_ABI
43 constexpr operator in_out_result<_InputIterator2, _OutputIterator2>() && {
44 return {_VSTD::move(in), _VSTD::move(out)};
45 }
46};
47
48} // namespace ranges
49
50#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
51
52_LIBCPP_END_NAMESPACE_STD
53
54#endif // _LIBCPP___ALGORITHM_IN_OUT_RESULT_H
lib/libcxx/include/__algorithm/includes.h+1-6
......@@ -9,18 +9,15 @@
99#ifndef _LIBCPP___ALGORITHM_INCLUDES_H
1010#define _LIBCPP___ALGORITHM_INCLUDES_H
1111
12#include <__config>
1312#include <__algorithm/comp.h>
1413#include <__algorithm/comp_ref_type.h>
14#include <__config>
1515#include <__iterator/iterator_traits.h>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1818#pragma GCC system_header
1919#endif
2020
21_LIBCPP_PUSH_MACROS
22#include <__undef_macros>
23
2421_LIBCPP_BEGIN_NAMESPACE_STD
2522
2623template <class _Compare, class _InputIterator1, class _InputIterator2>
......@@ -62,6 +59,4 @@ includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __fi
6259
6360_LIBCPP_END_NAMESPACE_STD
6461
65_LIBCPP_POP_MACROS
66
6762#endif // _LIBCPP___ALGORITHM_INCLUDES_H
lib/libcxx/include/__algorithm/inplace_merge.h+2-2
......@@ -9,14 +9,14 @@
99#ifndef _LIBCPP___ALGORITHM_INPLACE_MERGE_H
1010#define _LIBCPP___ALGORITHM_INPLACE_MERGE_H
1111
12#include <__config>
13#include <__algorithm/comp_ref_type.h>
1412#include <__algorithm/comp.h>
13#include <__algorithm/comp_ref_type.h>
1514#include <__algorithm/lower_bound.h>
1615#include <__algorithm/min.h>
1716#include <__algorithm/move.h>
1817#include <__algorithm/rotate.h>
1918#include <__algorithm/upper_bound.h>
19#include <__config>
2020#include <__iterator/iterator_traits.h>
2121#include <__utility/swap.h>
2222#include <memory>
lib/libcxx/include/__algorithm/is_heap.h+4-7
......@@ -9,18 +9,16 @@
99#ifndef _LIBCPP___ALGORITHM_IS_HEAP_H
1010#define _LIBCPP___ALGORITHM_IS_HEAP_H
1111
12#include <__config>
1312#include <__algorithm/comp.h>
13#include <__algorithm/comp_ref_type.h>
1414#include <__algorithm/is_heap_until.h>
15#include <__config>
1516#include <__iterator/iterator_traits.h>
1617
1718#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1819#pragma GCC system_header
1920#endif
2021
21_LIBCPP_PUSH_MACROS
22#include <__undef_macros>
23
2422_LIBCPP_BEGIN_NAMESPACE_STD
2523
2624template <class _RandomAccessIterator, class _Compare>
......@@ -29,7 +27,8 @@ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
2927bool
3028is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
3129{
32 return _VSTD::is_heap_until(__first, __last, __comp) == __last;
30 typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
31 return _VSTD::__is_heap_until<_Comp_ref>(__first, __last, __comp) == __last;
3332}
3433
3534template<class _RandomAccessIterator>
......@@ -43,6 +42,4 @@ is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
4342
4443_LIBCPP_END_NAMESPACE_STD
4544
46_LIBCPP_POP_MACROS
47
4845#endif // _LIBCPP___ALGORITHM_IS_HEAP_H
lib/libcxx/include/__algorithm/is_heap_until.h+15-13
......@@ -9,22 +9,20 @@
99#ifndef _LIBCPP___ALGORITHM_IS_HEAP_UNTIL_H
1010#define _LIBCPP___ALGORITHM_IS_HEAP_UNTIL_H
1111
12#include <__config>
1312#include <__algorithm/comp.h>
13#include <__algorithm/comp_ref_type.h>
14#include <__config>
1415#include <__iterator/iterator_traits.h>
1516
1617#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1718#pragma GCC system_header
1819#endif
1920
20_LIBCPP_PUSH_MACROS
21#include <__undef_macros>
22
2321_LIBCPP_BEGIN_NAMESPACE_STD
2422
25template <class _RandomAccessIterator, class _Compare>
26_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 _RandomAccessIterator
27is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
23template <class _Compare, class _RandomAccessIterator>
24_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _RandomAccessIterator
25__is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
2826{
2927 typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
3028 difference_type __len = __last - __first;
......@@ -49,17 +47,21 @@ is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp
4947 return __last;
5048}
5149
50template <class _RandomAccessIterator, class _Compare>
51_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _RandomAccessIterator
52is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
53{
54 typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
55 return _VSTD::__is_heap_until<_Comp_ref>(__first, __last, __comp);
56}
57
5258template<class _RandomAccessIterator>
53_LIBCPP_NODISCARD_EXT inline
54_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
55_RandomAccessIterator
59_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _RandomAccessIterator
5660is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last)
5761{
58 return _VSTD::is_heap_until(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
62 return _VSTD::__is_heap_until(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
5963}
6064
6165_LIBCPP_END_NAMESPACE_STD
6266
63_LIBCPP_POP_MACROS
64
6567#endif // _LIBCPP___ALGORITHM_IS_HEAP_UNTIL_H
lib/libcxx/include/__algorithm/is_partitioned.h-5
......@@ -15,9 +15,6 @@
1515#pragma GCC system_header
1616#endif
1717
18_LIBCPP_PUSH_MACROS
19#include <__undef_macros>
20
2118_LIBCPP_BEGIN_NAMESPACE_STD
2219
2320template <class _InputIterator, class _Predicate>
......@@ -38,6 +35,4 @@ is_partitioned(_InputIterator __first, _InputIterator __last, _Predicate __pred)
3835
3936_LIBCPP_END_NAMESPACE_STD
4037
41_LIBCPP_POP_MACROS
42
4338#endif // _LIBCPP___ALGORITHM_IS_PARTITIONED_H
lib/libcxx/include/__algorithm/is_permutation.h+3-9
......@@ -12,17 +12,14 @@
1212
1313#include <__algorithm/comp.h>
1414#include <__config>
15#include <__iterator/distance.h>
1516#include <__iterator/iterator_traits.h>
1617#include <__iterator/next.h>
17#include <iterator> // FIXME: replace with <__iterator/distance.h> when it lands
1818
1919#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2020#pragma GCC system_header
2121#endif
2222
23_LIBCPP_PUSH_MACROS
24#include <__undef_macros>
25
2623_LIBCPP_BEGIN_NAMESPACE_STD
2724
2825template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
......@@ -136,15 +133,14 @@ _LIBCPP_CONSTEXPR_AFTER_CXX17 bool __is_permutation(_RandomAccessIterator1 __fir
136133 if (_VSTD::distance(__first1, __last1) != _VSTD::distance(__first2, __last2))
137134 return false;
138135 return _VSTD::is_permutation<_RandomAccessIterator1, _RandomAccessIterator2,
139 typename add_lvalue_reference<_BinaryPredicate>::type>(__first1, __last1, __first2,
140 __pred);
136 _BinaryPredicate&>(__first1, __last1, __first2, __pred);
141137}
142138
143139template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
144140_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 bool
145141is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
146142 _ForwardIterator2 __last2, _BinaryPredicate __pred) {
147 return _VSTD::__is_permutation<typename add_lvalue_reference<_BinaryPredicate>::type>(
143 return _VSTD::__is_permutation<_BinaryPredicate&>(
148144 __first1, __last1, __first2, __last2, __pred, typename iterator_traits<_ForwardIterator1>::iterator_category(),
149145 typename iterator_traits<_ForwardIterator2>::iterator_category());
150146}
......@@ -163,6 +159,4 @@ is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIt
163159
164160_LIBCPP_END_NAMESPACE_STD
165161
166_LIBCPP_POP_MACROS
167
168162#endif // _LIBCPP___ALGORITHM_IS_PERMUTATION_H
lib/libcxx/include/__algorithm/is_sorted.h+3-6
......@@ -10,6 +10,7 @@
1010#define _LIBCPP___ALGORITHM_IS_SORTED_H
1111
1212#include <__algorithm/comp.h>
13#include <__algorithm/comp_ref_type.h>
1314#include <__algorithm/is_sorted_until.h>
1415#include <__config>
1516#include <__iterator/iterator_traits.h>
......@@ -18,9 +19,6 @@
1819#pragma GCC system_header
1920#endif
2021
21_LIBCPP_PUSH_MACROS
22#include <__undef_macros>
23
2422_LIBCPP_BEGIN_NAMESPACE_STD
2523
2624template <class _ForwardIterator, class _Compare>
......@@ -29,7 +27,8 @@ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
2927bool
3028is_sorted(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
3129{
32 return _VSTD::is_sorted_until(__first, __last, __comp) == __last;
30 typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
31 return _VSTD::__is_sorted_until<_Comp_ref>(__first, __last, __comp) == __last;
3332}
3433
3534template<class _ForwardIterator>
......@@ -43,6 +42,4 @@ is_sorted(_ForwardIterator __first, _ForwardIterator __last)
4342
4443_LIBCPP_END_NAMESPACE_STD
4544
46_LIBCPP_POP_MACROS
47
4845#endif // _LIBCPP___ALGORITHM_IS_SORTED_H
lib/libcxx/include/__algorithm/is_sorted_until.h+14-12
......@@ -9,22 +9,20 @@
99#ifndef _LIBCPP___ALGORITHM_IS_SORTED_UNTIL_H
1010#define _LIBCPP___ALGORITHM_IS_SORTED_UNTIL_H
1111
12#include <__config>
1312#include <__algorithm/comp.h>
13#include <__algorithm/comp_ref_type.h>
14#include <__config>
1415#include <__iterator/iterator_traits.h>
1516
1617#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1718#pragma GCC system_header
1819#endif
1920
20_LIBCPP_PUSH_MACROS
21#include <__undef_macros>
22
2321_LIBCPP_BEGIN_NAMESPACE_STD
2422
25template <class _ForwardIterator, class _Compare>
26_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
27is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
23template <class _Compare, class _ForwardIterator>
24_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
25__is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
2826{
2927 if (__first != __last)
3028 {
......@@ -39,10 +37,16 @@ is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __co
3937 return __last;
4038}
4139
40template <class _ForwardIterator, class _Compare>
41_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
42is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
43{
44 typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
45 return _VSTD::__is_sorted_until<_Comp_ref>(__first, __last, __comp);
46}
47
4248template<class _ForwardIterator>
43_LIBCPP_NODISCARD_EXT inline
44_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
45_ForwardIterator
49_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
4650is_sorted_until(_ForwardIterator __first, _ForwardIterator __last)
4751{
4852 return _VSTD::is_sorted_until(__first, __last, __less<typename iterator_traits<_ForwardIterator>::value_type>());
......@@ -50,6 +54,4 @@ is_sorted_until(_ForwardIterator __first, _ForwardIterator __last)
5054
5155_LIBCPP_END_NAMESPACE_STD
5256
53_LIBCPP_POP_MACROS
54
5557#endif // _LIBCPP___ALGORITHM_IS_SORTED_UNTIL_H
lib/libcxx/include/__algorithm/iter_swap.h-5
......@@ -17,9 +17,6 @@
1717#pragma GCC system_header
1818#endif
1919
20_LIBCPP_PUSH_MACROS
21#include <__undef_macros>
22
2320_LIBCPP_BEGIN_NAMESPACE_STD
2421
2522template <class _ForwardIterator1, class _ForwardIterator2>
......@@ -32,6 +29,4 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 void iter_swap(_F
3229
3330_LIBCPP_END_NAMESPACE_STD
3431
35_LIBCPP_POP_MACROS
36
3732#endif // _LIBCPP___ALGORITHM_ITER_SWAP_H
lib/libcxx/include/__algorithm/lexicographical_compare.h+1-6
......@@ -9,18 +9,15 @@
99#ifndef _LIBCPP___ALGORITHM_LEXICOGRAPHICAL_COMPARE_H
1010#define _LIBCPP___ALGORITHM_LEXICOGRAPHICAL_COMPARE_H
1111
12#include <__config>
1312#include <__algorithm/comp.h>
1413#include <__algorithm/comp_ref_type.h>
14#include <__config>
1515#include <__iterator/iterator_traits.h>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1818#pragma GCC system_header
1919#endif
2020
21_LIBCPP_PUSH_MACROS
22#include <__undef_macros>
23
2421_LIBCPP_BEGIN_NAMESPACE_STD
2522
2623template <class _Compare, class _InputIterator1, class _InputIterator2>
......@@ -63,6 +60,4 @@ lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1,
6360
6461_LIBCPP_END_NAMESPACE_STD
6562
66_LIBCPP_POP_MACROS
67
6863#endif // _LIBCPP___ALGORITHM_LEXICOGRAPHICAL_COMPARE_H
lib/libcxx/include/__algorithm/lower_bound.h+2-8
......@@ -9,18 +9,15 @@
99#ifndef _LIBCPP___ALGORITHM_LOWER_BOUND_H
1010#define _LIBCPP___ALGORITHM_LOWER_BOUND_H
1111
12#include <__config>
1312#include <__algorithm/comp.h>
1413#include <__algorithm/half_positive.h>
14#include <__config>
1515#include <iterator>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1818#pragma GCC system_header
1919#endif
2020
21_LIBCPP_PUSH_MACROS
22#include <__undef_macros>
23
2421_LIBCPP_BEGIN_NAMESPACE_STD
2522
2623template <class _Compare, class _ForwardIterator, class _Tp>
......@@ -51,8 +48,7 @@ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
5148_ForwardIterator
5249lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
5350{
54 typedef typename add_lvalue_reference<_Compare>::type _Comp_ref;
55 return _VSTD::__lower_bound<_Comp_ref>(__first, __last, __value_, __comp);
51 return _VSTD::__lower_bound<_Compare&>(__first, __last, __value_, __comp);
5652}
5753
5854template <class _ForwardIterator, class _Tp>
......@@ -67,6 +63,4 @@ lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __valu
6763
6864_LIBCPP_END_NAMESPACE_STD
6965
70_LIBCPP_POP_MACROS
71
7266#endif // _LIBCPP___ALGORITHM_LOWER_BOUND_H
lib/libcxx/include/__algorithm/make_heap.h+2-7
......@@ -9,19 +9,16 @@
99#ifndef _LIBCPP___ALGORITHM_MAKE_HEAP_H
1010#define _LIBCPP___ALGORITHM_MAKE_HEAP_H
1111
12#include <__config>
1312#include <__algorithm/comp.h>
1413#include <__algorithm/comp_ref_type.h>
1514#include <__algorithm/sift_down.h>
15#include <__config>
1616#include <__iterator/iterator_traits.h>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1919#pragma GCC system_header
2020#endif
2121
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
2522_LIBCPP_BEGIN_NAMESPACE_STD
2623
2724template <class _Compare, class _RandomAccessIterator>
......@@ -35,7 +32,7 @@ __make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compar
3532 // start from the first parent, there is no need to consider children
3633 for (difference_type __start = (__n - 2) / 2; __start >= 0; --__start)
3734 {
38 _VSTD::__sift_down<_Compare>(__first, __last, __comp, __n, __first + __start);
35 _VSTD::__sift_down<_Compare>(__first, __comp, __n, __first + __start);
3936 }
4037 }
4138}
......@@ -59,6 +56,4 @@ make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
5956
6057_LIBCPP_END_NAMESPACE_STD
6158
62_LIBCPP_POP_MACROS
63
6459#endif // _LIBCPP___ALGORITHM_MAKE_HEAP_H
lib/libcxx/include/__algorithm/max.h+4-2
......@@ -9,9 +9,10 @@
99#ifndef _LIBCPP___ALGORITHM_MAX_H
1010#define _LIBCPP___ALGORITHM_MAX_H
1111
12#include <__config>
1312#include <__algorithm/comp.h>
13#include <__algorithm/comp_ref_type.h>
1414#include <__algorithm/max_element.h>
15#include <__config>
1516#include <initializer_list>
1617
1718#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -49,7 +50,8 @@ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
4950_Tp
5051max(initializer_list<_Tp> __t, _Compare __comp)
5152{
52 return *_VSTD::max_element(__t.begin(), __t.end(), __comp);
53 typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
54 return *_VSTD::__max_element<_Comp_ref>(__t.begin(), __t.end(), __comp);
5355}
5456
5557template<class _Tp>
lib/libcxx/include/__algorithm/max_element.h+14-14
......@@ -9,24 +9,20 @@
99#ifndef _LIBCPP___ALGORITHM_MAX_ELEMENT_H
1010#define _LIBCPP___ALGORITHM_MAX_ELEMENT_H
1111
12#include <__config>
1312#include <__algorithm/comp.h>
13#include <__algorithm/comp_ref_type.h>
14#include <__config>
1415#include <__iterator/iterator_traits.h>
1516
1617#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1718#pragma GCC system_header
1819#endif
1920
20_LIBCPP_PUSH_MACROS
21#include <__undef_macros>
22
2321_LIBCPP_BEGIN_NAMESPACE_STD
2422
25template <class _ForwardIterator, class _Compare>
26_LIBCPP_NODISCARD_EXT inline
27_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
28_ForwardIterator
29max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
23template <class _Compare, class _ForwardIterator>
24inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator
25__max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
3026{
3127 static_assert(__is_cpp17_forward_iterator<_ForwardIterator>::value,
3228 "std::max_element requires a ForwardIterator");
......@@ -40,11 +36,17 @@ max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
4036 return __first;
4137}
4238
39template <class _ForwardIterator, class _Compare>
40_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator
41max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
42{
43 typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
44 return _VSTD::__max_element<_Comp_ref>(__first, __last, __comp);
45}
46
4347
4448template <class _ForwardIterator>
45_LIBCPP_NODISCARD_EXT inline
46_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
47_ForwardIterator
49_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator
4850max_element(_ForwardIterator __first, _ForwardIterator __last)
4951{
5052 return _VSTD::max_element(__first, __last,
......@@ -53,6 +55,4 @@ max_element(_ForwardIterator __first, _ForwardIterator __last)
5355
5456_LIBCPP_END_NAMESPACE_STD
5557
56_LIBCPP_POP_MACROS
57
5858#endif // _LIBCPP___ALGORITHM_MAX_ELEMENT_H
lib/libcxx/include/__algorithm/merge.h+1-6
......@@ -9,19 +9,16 @@
99#ifndef _LIBCPP___ALGORITHM_MERGE_H
1010#define _LIBCPP___ALGORITHM_MERGE_H
1111
12#include <__config>
1312#include <__algorithm/comp.h>
1413#include <__algorithm/comp_ref_type.h>
1514#include <__algorithm/copy.h>
15#include <__config>
1616#include <__iterator/iterator_traits.h>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1919#pragma GCC system_header
2020#endif
2121
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
2522_LIBCPP_BEGIN_NAMESPACE_STD
2623
2724template <class _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator>
......@@ -71,6 +68,4 @@ merge(_InputIterator1 __first1, _InputIterator1 __last1,
7168
7269_LIBCPP_END_NAMESPACE_STD
7370
74_LIBCPP_POP_MACROS
75
7671#endif // _LIBCPP___ALGORITHM_MERGE_H
lib/libcxx/include/__algorithm/min.h+4-2
......@@ -9,9 +9,10 @@
99#ifndef _LIBCPP___ALGORITHM_MIN_H
1010#define _LIBCPP___ALGORITHM_MIN_H
1111
12#include <__config>
1312#include <__algorithm/comp.h>
13#include <__algorithm/comp_ref_type.h>
1414#include <__algorithm/min_element.h>
15#include <__config>
1516#include <initializer_list>
1617
1718#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -49,7 +50,8 @@ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
4950_Tp
5051min(initializer_list<_Tp> __t, _Compare __comp)
5152{
52 return *_VSTD::min_element(__t.begin(), __t.end(), __comp);
53 typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
54 return *_VSTD::__min_element<_Comp_ref>(__t.begin(), __t.end(), __comp);
5355}
5456
5557template<class _Tp>
lib/libcxx/include/__algorithm/min_element.h+14-14
......@@ -9,24 +9,20 @@
99#ifndef _LIBCPP___ALGORITHM_MIN_ELEMENT_H
1010#define _LIBCPP___ALGORITHM_MIN_ELEMENT_H
1111
12#include <__config>
1312#include <__algorithm/comp.h>
13#include <__algorithm/comp_ref_type.h>
14#include <__config>
1415#include <__iterator/iterator_traits.h>
1516
1617#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1718#pragma GCC system_header
1819#endif
1920
20_LIBCPP_PUSH_MACROS
21#include <__undef_macros>
22
2321_LIBCPP_BEGIN_NAMESPACE_STD
2422
25template <class _ForwardIterator, class _Compare>
26_LIBCPP_NODISCARD_EXT inline
27_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
28_ForwardIterator
29min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
23template <class _Compare, class _ForwardIterator>
24inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator
25__min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
3026{
3127 static_assert(__is_cpp17_forward_iterator<_ForwardIterator>::value,
3228 "std::min_element requires a ForwardIterator");
......@@ -40,10 +36,16 @@ min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
4036 return __first;
4137}
4238
39template <class _ForwardIterator, class _Compare>
40_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator
41min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
42{
43 typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
44 return _VSTD::__min_element<_Comp_ref>(__first, __last, __comp);
45}
46
4347template <class _ForwardIterator>
44_LIBCPP_NODISCARD_EXT inline
45_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
46_ForwardIterator
48_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator
4749min_element(_ForwardIterator __first, _ForwardIterator __last)
4850{
4951 return _VSTD::min_element(__first, __last,
......@@ -52,6 +54,4 @@ min_element(_ForwardIterator __first, _ForwardIterator __last)
5254
5355_LIBCPP_END_NAMESPACE_STD
5456
55_LIBCPP_POP_MACROS
56
5757#endif // _LIBCPP___ALGORITHM_MIN_ELEMENT_H
lib/libcxx/include/__algorithm/minmax.h+1-7
......@@ -9,19 +9,15 @@
99#ifndef _LIBCPP___ALGORITHM_MINMAX_H
1010#define _LIBCPP___ALGORITHM_MINMAX_H
1111
12#include <__config>
1312#include <__algorithm/comp.h>
13#include <__config>
1414#include <initializer_list>
1515#include <utility>
1616
17
1817#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1918#pragma GCC system_header
2019#endif
2120
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
2521_LIBCPP_BEGIN_NAMESPACE_STD
2622
2723template<class _Tp, class _Compare>
......@@ -96,6 +92,4 @@ minmax(initializer_list<_Tp> __t)
9692
9793_LIBCPP_END_NAMESPACE_STD
9894
99_LIBCPP_POP_MACROS
100
10195#endif // _LIBCPP___ALGORITHM_MINMAX_H
lib/libcxx/include/__algorithm/minmax_element.h+1-6
......@@ -9,8 +9,8 @@
99#ifndef _LIBCPP___ALGORITHM_MINMAX_ELEMENT_H
1010#define _LIBCPP___ALGORITHM_MINMAX_ELEMENT_H
1111
12#include <__config>
1312#include <__algorithm/comp.h>
13#include <__config>
1414#include <__iterator/iterator_traits.h>
1515#include <utility>
1616
......@@ -18,9 +18,6 @@
1818#pragma GCC system_header
1919#endif
2020
21_LIBCPP_PUSH_MACROS
22#include <__undef_macros>
23
2421_LIBCPP_BEGIN_NAMESPACE_STD
2522
2623template <class _ForwardIterator, class _Compare>
......@@ -85,6 +82,4 @@ minmax_element(_ForwardIterator __first, _ForwardIterator __last)
8582
8683_LIBCPP_END_NAMESPACE_STD
8784
88_LIBCPP_POP_MACROS
89
9085#endif // _LIBCPP___ALGORITHM_MINMAX_ELEMENT_H
lib/libcxx/include/__algorithm/mismatch.h+1-6
......@@ -10,8 +10,8 @@
1010#ifndef _LIBCPP___ALGORITHM_MISMATCH_H
1111#define _LIBCPP___ALGORITHM_MISMATCH_H
1212
13#include <__config>
1413#include <__algorithm/comp.h>
14#include <__config>
1515#include <__iterator/iterator_traits.h>
1616#include <utility>
1717
......@@ -19,9 +19,6 @@
1919#pragma GCC system_header
2020#endif
2121
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
2522_LIBCPP_BEGIN_NAMESPACE_STD
2623
2724template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
......@@ -67,6 +64,4 @@ _LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY
6764
6865_LIBCPP_END_NAMESPACE_STD
6966
70_LIBCPP_POP_MACROS
71
7267#endif // _LIBCPP___ALGORITHM_MISMATCH_H
lib/libcxx/include/__algorithm/move.h+2-7
......@@ -9,20 +9,17 @@
99#ifndef _LIBCPP___ALGORITHM_MOVE_H
1010#define _LIBCPP___ALGORITHM_MOVE_H
1111
12#include <__config>
1312#include <__algorithm/unwrap_iter.h>
13#include <__config>
1414#include <__utility/move.h>
1515#include <cstring>
16#include <utility>
1716#include <type_traits>
17#include <utility>
1818
1919#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2020#pragma GCC system_header
2121#endif
2222
23_LIBCPP_PUSH_MACROS
24#include <__undef_macros>
25
2623_LIBCPP_BEGIN_NAMESPACE_STD
2724
2825// move
......@@ -78,6 +75,4 @@ move(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
7875
7976_LIBCPP_END_NAMESPACE_STD
8077
81_LIBCPP_POP_MACROS
82
8378#endif // _LIBCPP___ALGORITHM_MOVE_H
lib/libcxx/include/__algorithm/move_backward.h+2-7
......@@ -9,19 +9,16 @@
99#ifndef _LIBCPP___ALGORITHM_MOVE_BACKWARD_H
1010#define _LIBCPP___ALGORITHM_MOVE_BACKWARD_H
1111
12#include <__config>
1312#include <__algorithm/unwrap_iter.h>
13#include <__config>
1414#include <cstring>
15#include <utility>
1615#include <type_traits>
16#include <utility>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1919#pragma GCC system_header
2020#endif
2121
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
2522_LIBCPP_BEGIN_NAMESPACE_STD
2623
2724template <class _InputIterator, class _OutputIterator>
......@@ -79,6 +76,4 @@ move_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last,
7976
8077_LIBCPP_END_NAMESPACE_STD
8178
82_LIBCPP_POP_MACROS
83
8479#endif // _LIBCPP___ALGORITHM_MOVE_BACKWARD_H
lib/libcxx/include/__algorithm/next_permutation.h+1-6
......@@ -9,10 +9,10 @@
99#ifndef _LIBCPP___ALGORITHM_NEXT_PERMUTATION_H
1010#define _LIBCPP___ALGORITHM_NEXT_PERMUTATION_H
1111
12#include <__config>
1312#include <__algorithm/comp.h>
1413#include <__algorithm/comp_ref_type.h>
1514#include <__algorithm/reverse.h>
15#include <__config>
1616#include <__iterator/iterator_traits.h>
1717#include <__utility/swap.h>
1818
......@@ -20,9 +20,6 @@
2020#pragma GCC system_header
2121#endif
2222
23_LIBCPP_PUSH_MACROS
24#include <__undef_macros>
25
2623_LIBCPP_BEGIN_NAMESPACE_STD
2724
2825template <class _Compare, class _BidirectionalIterator>
......@@ -72,6 +69,4 @@ next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last)
7269
7370_LIBCPP_END_NAMESPACE_STD
7471
75_LIBCPP_POP_MACROS
76
7772#endif // _LIBCPP___ALGORITHM_NEXT_PERMUTATION_H
lib/libcxx/include/__algorithm/none_of.h-5
......@@ -16,9 +16,6 @@
1616#pragma GCC system_header
1717#endif
1818
19_LIBCPP_PUSH_MACROS
20#include <__undef_macros>
21
2219_LIBCPP_BEGIN_NAMESPACE_STD
2320
2421template <class _InputIterator, class _Predicate>
......@@ -32,6 +29,4 @@ none_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
3229
3330_LIBCPP_END_NAMESPACE_STD
3431
35_LIBCPP_POP_MACROS
36
3732#endif // _LIBCPP___ALGORITHM_NONE_OF_H
lib/libcxx/include/__algorithm/nth_element.h+12-8
......@@ -9,20 +9,21 @@
99#ifndef _LIBCPP___ALGORITHM_NTH_ELEMENT_H
1010#define _LIBCPP___ALGORITHM_NTH_ELEMENT_H
1111
12#include <__config>
1312#include <__algorithm/comp.h>
1413#include <__algorithm/comp_ref_type.h>
1514#include <__algorithm/sort.h>
15#include <__config>
1616#include <__iterator/iterator_traits.h>
1717#include <__utility/swap.h>
1818
19#if defined(_LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY)
20# include <__algorithm/shuffle.h>
21#endif
22
1923#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2024#pragma GCC system_header
2125#endif
2226
23_LIBCPP_PUSH_MACROS
24#include <__undef_macros>
25
2627_LIBCPP_BEGIN_NAMESPACE_STD
2728
2829template<class _Compare, class _RandomAccessIterator>
......@@ -225,8 +226,13 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
225226void
226227nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare __comp)
227228{
228 typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
229 _VSTD::__nth_element<_Comp_ref>(__first, __nth, __last, __comp);
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);
233 if (__nth != __last) {
234 _LIBCPP_DEBUG_RANDOMIZE_RANGE(++__nth, __last);
235 }
230236}
231237
232238template <class _RandomAccessIterator>
......@@ -239,6 +245,4 @@ nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomA
239245
240246_LIBCPP_END_NAMESPACE_STD
241247
242_LIBCPP_POP_MACROS
243
244248#endif // _LIBCPP___ALGORITHM_NTH_ELEMENT_H
lib/libcxx/include/__algorithm/partial_sort.h+14-11
......@@ -9,29 +9,32 @@
99#ifndef _LIBCPP___ALGORITHM_PARTIAL_SORT_H
1010#define _LIBCPP___ALGORITHM_PARTIAL_SORT_H
1111
12#include <__config>
1312#include <__algorithm/comp.h>
1413#include <__algorithm/comp_ref_type.h>
1514#include <__algorithm/make_heap.h>
1615#include <__algorithm/sift_down.h>
1716#include <__algorithm/sort_heap.h>
17#include <__config>
1818#include <__iterator/iterator_traits.h>
1919#include <__utility/swap.h>
2020
21#if defined(_LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY)
22# include <__algorithm/shuffle.h>
23#endif
24
2125#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2226#pragma GCC system_header
2327#endif
2428
25_LIBCPP_PUSH_MACROS
26#include <__undef_macros>
27
2829_LIBCPP_BEGIN_NAMESPACE_STD
2930
3031template <class _Compare, class _RandomAccessIterator>
3132_LIBCPP_CONSTEXPR_AFTER_CXX17 void
3233__partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last,
33 _Compare __comp)
34 _Compare __comp)
3435{
36 if (__first == __middle)
37 return;
3538 _VSTD::__make_heap<_Compare>(__first, __middle, __comp);
3639 typename iterator_traits<_RandomAccessIterator>::difference_type __len = __middle - __first;
3740 for (_RandomAccessIterator __i = __middle; __i != __last; ++__i)
......@@ -39,7 +42,7 @@ __partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _R
3942 if (__comp(*__i, *__first))
4043 {
4144 swap(*__i, *__first);
42 _VSTD::__sift_down<_Compare>(__first, __middle, __comp, __len, __first);
45 _VSTD::__sift_down<_Compare>(__first, __comp, __len, __first);
4346 }
4447 }
4548 _VSTD::__sort_heap<_Compare>(__first, __middle, __comp);
......@@ -51,8 +54,10 @@ void
5154partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last,
5255 _Compare __comp)
5356{
54 typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
55 _VSTD::__partial_sort<_Comp_ref>(__first, __middle, __last, __comp);
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);
5661}
5762
5863template <class _RandomAccessIterator>
......@@ -61,11 +66,9 @@ void
6166partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last)
6267{
6368 _VSTD::partial_sort(__first, __middle, __last,
64 __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
69 __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
6570}
6671
6772_LIBCPP_END_NAMESPACE_STD
6873
69_LIBCPP_POP_MACROS
70
7174#endif // _LIBCPP___ALGORITHM_PARTIAL_SORT_H
lib/libcxx/include/__algorithm/partial_sort_copy.h+2-8
......@@ -9,22 +9,18 @@
99#ifndef _LIBCPP___ALGORITHM_PARTIAL_SORT_COPY_H
1010#define _LIBCPP___ALGORITHM_PARTIAL_SORT_COPY_H
1111
12#include <__config>
1312#include <__algorithm/comp.h>
1413#include <__algorithm/comp_ref_type.h>
1514#include <__algorithm/make_heap.h>
1615#include <__algorithm/sift_down.h>
1716#include <__algorithm/sort_heap.h>
17#include <__config>
1818#include <__iterator/iterator_traits.h>
19#include <type_traits> // swap
2019
2120#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2221#pragma GCC system_header
2322#endif
2423
25_LIBCPP_PUSH_MACROS
26#include <__undef_macros>
27
2824_LIBCPP_BEGIN_NAMESPACE_STD
2925
3026template <class _Compare, class _InputIterator, class _RandomAccessIterator>
......@@ -43,7 +39,7 @@ __partial_sort_copy(_InputIterator __first, _InputIterator __last,
4339 if (__comp(*__first, *__result_first))
4440 {
4541 *__result_first = *__first;
46 _VSTD::__sift_down<_Compare>(__result_first, __r, __comp, __len, __result_first);
42 _VSTD::__sift_down<_Compare>(__result_first, __comp, __len, __result_first);
4743 }
4844 _VSTD::__sort_heap<_Compare>(__result_first, __r, __comp);
4945 }
......@@ -72,6 +68,4 @@ partial_sort_copy(_InputIterator __first, _InputIterator __last,
7268
7369_LIBCPP_END_NAMESPACE_STD
7470
75_LIBCPP_POP_MACROS
76
7771#endif // _LIBCPP___ALGORITHM_PARTIAL_SORT_COPY_H
lib/libcxx/include/__algorithm/partition.h+2-9
......@@ -12,16 +12,11 @@
1212#include <__config>
1313#include <__iterator/iterator_traits.h>
1414#include <__utility/swap.h>
15#include <utility> // pair
16#include <type_traits>
1715
1816#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1917#pragma GCC system_header
2018#endif
2119
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
2520_LIBCPP_BEGIN_NAMESPACE_STD
2621
2722template <class _Predicate, class _ForwardIterator>
......@@ -77,12 +72,10 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
7772_ForwardIterator
7873partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
7974{
80 return _VSTD::__partition<typename add_lvalue_reference<_Predicate>::type>
81 (__first, __last, __pred, typename iterator_traits<_ForwardIterator>::iterator_category());
75 return _VSTD::__partition<_Predicate&>(
76 __first, __last, __pred, typename iterator_traits<_ForwardIterator>::iterator_category());
8277}
8378
8479_LIBCPP_END_NAMESPACE_STD
8580
86_LIBCPP_POP_MACROS
87
8881#endif // _LIBCPP___ALGORITHM_PARTITION_H
lib/libcxx/include/__algorithm/partition_copy.h-5
......@@ -17,9 +17,6 @@
1717#pragma GCC system_header
1818#endif
1919
20_LIBCPP_PUSH_MACROS
21#include <__undef_macros>
22
2320_LIBCPP_BEGIN_NAMESPACE_STD
2421
2522template <class _InputIterator, class _OutputIterator1,
......@@ -47,6 +44,4 @@ partition_copy(_InputIterator __first, _InputIterator __last,
4744
4845_LIBCPP_END_NAMESPACE_STD
4946
50_LIBCPP_POP_MACROS
51
5247#endif // _LIBCPP___ALGORITHM_PARTITION_COPY_H
lib/libcxx/include/__algorithm/partition_point.h+1-6
......@@ -9,17 +9,14 @@
99#ifndef _LIBCPP___ALGORITHM_PARTITION_POINT_H
1010#define _LIBCPP___ALGORITHM_PARTITION_POINT_H
1111
12#include <__config>
1312#include <__algorithm/half_positive.h>
13#include <__config>
1414#include <iterator>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1717#pragma GCC system_header
1818#endif
1919
20_LIBCPP_PUSH_MACROS
21#include <__undef_macros>
22
2320_LIBCPP_BEGIN_NAMESPACE_STD
2421
2522template<class _ForwardIterator, class _Predicate>
......@@ -46,6 +43,4 @@ partition_point(_ForwardIterator __first, _ForwardIterator __last, _Predicate __
4643
4744_LIBCPP_END_NAMESPACE_STD
4845
49_LIBCPP_POP_MACROS
50
5146#endif // _LIBCPP___ALGORITHM_PARTITION_POINT_H
lib/libcxx/include/__algorithm/pop_heap.h+2-7
......@@ -9,10 +9,10 @@
99#ifndef _LIBCPP___ALGORITHM_POP_HEAP_H
1010#define _LIBCPP___ALGORITHM_POP_HEAP_H
1111
12#include <__config>
1312#include <__algorithm/comp.h>
1413#include <__algorithm/comp_ref_type.h>
1514#include <__algorithm/sift_down.h>
15#include <__config>
1616#include <__iterator/iterator_traits.h>
1717#include <__utility/swap.h>
1818
......@@ -20,9 +20,6 @@
2020#pragma GCC system_header
2121#endif
2222
23_LIBCPP_PUSH_MACROS
24#include <__undef_macros>
25
2623_LIBCPP_BEGIN_NAMESPACE_STD
2724
2825template <class _Compare, class _RandomAccessIterator>
......@@ -34,7 +31,7 @@ __pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare
3431 if (__len > 1)
3532 {
3633 swap(*__first, *--__last);
37 _VSTD::__sift_down<_Compare>(__first, __last, __comp, __len - 1, __first);
34 _VSTD::__sift_down<_Compare>(__first, __comp, __len - 1, __first);
3835 }
3936}
4037
......@@ -57,6 +54,4 @@ pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
5754
5855_LIBCPP_END_NAMESPACE_STD
5956
60_LIBCPP_POP_MACROS
61
6257#endif // _LIBCPP___ALGORITHM_POP_HEAP_H
lib/libcxx/include/__algorithm/prev_permutation.h+1-6
......@@ -9,10 +9,10 @@
99#ifndef _LIBCPP___ALGORITHM_PREV_PERMUTATION_H
1010#define _LIBCPP___ALGORITHM_PREV_PERMUTATION_H
1111
12#include <__config>
1312#include <__algorithm/comp.h>
1413#include <__algorithm/comp_ref_type.h>
1514#include <__algorithm/reverse.h>
15#include <__config>
1616#include <__iterator/iterator_traits.h>
1717#include <__utility/swap.h>
1818
......@@ -20,9 +20,6 @@
2020#pragma GCC system_header
2121#endif
2222
23_LIBCPP_PUSH_MACROS
24#include <__undef_macros>
25
2623_LIBCPP_BEGIN_NAMESPACE_STD
2724
2825template <class _Compare, class _BidirectionalIterator>
......@@ -72,6 +69,4 @@ prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last)
7269
7370_LIBCPP_END_NAMESPACE_STD
7471
75_LIBCPP_POP_MACROS
76
7772#endif // _LIBCPP___ALGORITHM_PREV_PERMUTATION_H
lib/libcxx/include/__algorithm/push_heap.h+1-6
......@@ -9,9 +9,9 @@
99#ifndef _LIBCPP___ALGORITHM_PUSH_HEAP_H
1010#define _LIBCPP___ALGORITHM_PUSH_HEAP_H
1111
12#include <__config>
1312#include <__algorithm/comp.h>
1413#include <__algorithm/comp_ref_type.h>
14#include <__config>
1515#include <__iterator/iterator_traits.h>
1616#include <__utility/move.h>
1717
......@@ -19,9 +19,6 @@
1919#pragma GCC system_header
2020#endif
2121
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
2522_LIBCPP_BEGIN_NAMESPACE_STD
2623
2724template <class _Compare, class _RandomAccessIterator>
......@@ -70,6 +67,4 @@ push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
7067
7168_LIBCPP_END_NAMESPACE_STD
7269
73_LIBCPP_POP_MACROS
74
7570#endif // _LIBCPP___ALGORITHM_PUSH_HEAP_H
lib/libcxx/include/__algorithm/remove.h+1-6
......@@ -9,18 +9,15 @@
99#ifndef _LIBCPP___ALGORITHM_REMOVE_H
1010#define _LIBCPP___ALGORITHM_REMOVE_H
1111
12#include <__config>
1312#include <__algorithm/find.h>
1413#include <__algorithm/find_if.h>
14#include <__config>
1515#include <__utility/move.h>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1818#pragma GCC system_header
1919#endif
2020
21_LIBCPP_PUSH_MACROS
22#include <__undef_macros>
23
2421_LIBCPP_BEGIN_NAMESPACE_STD
2522
2623template <class _ForwardIterator, class _Tp>
......@@ -45,6 +42,4 @@ remove(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_)
4542
4643_LIBCPP_END_NAMESPACE_STD
4744
48_LIBCPP_POP_MACROS
49
5045#endif // _LIBCPP___ALGORITHM_REMOVE_H
lib/libcxx/include/__algorithm/remove_copy.h-5
......@@ -15,9 +15,6 @@
1515#pragma GCC system_header
1616#endif
1717
18_LIBCPP_PUSH_MACROS
19#include <__undef_macros>
20
2118_LIBCPP_BEGIN_NAMESPACE_STD
2219
2320template <class _InputIterator, class _OutputIterator, class _Tp>
......@@ -38,6 +35,4 @@ remove_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __res
3835
3936_LIBCPP_END_NAMESPACE_STD
4037
41_LIBCPP_POP_MACROS
42
4338#endif // _LIBCPP___ALGORITHM_REMOVE_COPY_H
lib/libcxx/include/__algorithm/remove_copy_if.h-5
......@@ -15,9 +15,6 @@
1515#pragma GCC system_header
1616#endif
1717
18_LIBCPP_PUSH_MACROS
19#include <__undef_macros>
20
2118_LIBCPP_BEGIN_NAMESPACE_STD
2219
2320template <class _InputIterator, class _OutputIterator, class _Predicate>
......@@ -38,6 +35,4 @@ remove_copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __
3835
3936_LIBCPP_END_NAMESPACE_STD
4037
41_LIBCPP_POP_MACROS
42
4338#endif // _LIBCPP___ALGORITHM_REMOVE_COPY_IF_H
lib/libcxx/include/__algorithm/remove_if.h+2-9
......@@ -9,26 +9,21 @@
99#ifndef _LIBCPP___ALGORITHM_REMOVE_IF_H
1010#define _LIBCPP___ALGORITHM_REMOVE_IF_H
1111
12#include <__config>
1312#include <__algorithm/find_if.h>
13#include <__config>
1414#include <utility>
15#include <type_traits>
1615
1716#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1817#pragma GCC system_header
1918#endif
2019
21_LIBCPP_PUSH_MACROS
22#include <__undef_macros>
23
2420_LIBCPP_BEGIN_NAMESPACE_STD
2521
2622template <class _ForwardIterator, class _Predicate>
2723_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
2824remove_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
2925{
30 __first = _VSTD::find_if<_ForwardIterator, typename add_lvalue_reference<_Predicate>::type>
31 (__first, __last, __pred);
26 __first = _VSTD::find_if<_ForwardIterator, _Predicate&>(__first, __last, __pred);
3227 if (__first != __last)
3328 {
3429 _ForwardIterator __i = __first;
......@@ -46,6 +41,4 @@ remove_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
4641
4742_LIBCPP_END_NAMESPACE_STD
4843
49_LIBCPP_POP_MACROS
50
5144#endif // _LIBCPP___ALGORITHM_REMOVE_IF_H
lib/libcxx/include/__algorithm/replace.h-5
......@@ -15,9 +15,6 @@
1515#pragma GCC system_header
1616#endif
1717
18_LIBCPP_PUSH_MACROS
19#include <__undef_macros>
20
2118_LIBCPP_BEGIN_NAMESPACE_STD
2219
2320template <class _ForwardIterator, class _Tp>
......@@ -32,6 +29,4 @@ replace(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __old_valu
3229
3330_LIBCPP_END_NAMESPACE_STD
3431
35_LIBCPP_POP_MACROS
36
3732#endif // _LIBCPP___ALGORITHM_REPLACE_H
lib/libcxx/include/__algorithm/replace_copy.h-5
......@@ -15,9 +15,6 @@
1515#pragma GCC system_header
1616#endif
1717
18_LIBCPP_PUSH_MACROS
19#include <__undef_macros>
20
2118_LIBCPP_BEGIN_NAMESPACE_STD
2219
2320template <class _InputIterator, class _OutputIterator, class _Tp>
......@@ -36,6 +33,4 @@ replace_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __re
3633
3734_LIBCPP_END_NAMESPACE_STD
3835
39_LIBCPP_POP_MACROS
40
4136#endif // _LIBCPP___ALGORITHM_REPLACE_COPY_H
lib/libcxx/include/__algorithm/replace_copy_if.h-5
......@@ -15,9 +15,6 @@
1515#pragma GCC system_header
1616#endif
1717
18_LIBCPP_PUSH_MACROS
19#include <__undef_macros>
20
2118_LIBCPP_BEGIN_NAMESPACE_STD
2219
2320template <class _InputIterator, class _OutputIterator, class _Predicate, class _Tp>
......@@ -36,6 +33,4 @@ replace_copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator _
3633
3734_LIBCPP_END_NAMESPACE_STD
3835
39_LIBCPP_POP_MACROS
40
4136#endif // _LIBCPP___ALGORITHM_REPLACE_COPY_IF_H
lib/libcxx/include/__algorithm/replace_if.h-5
......@@ -15,9 +15,6 @@
1515#pragma GCC system_header
1616#endif
1717
18_LIBCPP_PUSH_MACROS
19#include <__undef_macros>
20
2118_LIBCPP_BEGIN_NAMESPACE_STD
2219
2320template <class _ForwardIterator, class _Predicate, class _Tp>
......@@ -32,6 +29,4 @@ replace_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred,
3229
3330_LIBCPP_END_NAMESPACE_STD
3431
35_LIBCPP_POP_MACROS
36
3732#endif // _LIBCPP___ALGORITHM_REPLACE_IF_H
lib/libcxx/include/__algorithm/reverse.h+1-6
......@@ -9,17 +9,14 @@
99#ifndef _LIBCPP___ALGORITHM_REVERSE_H
1010#define _LIBCPP___ALGORITHM_REVERSE_H
1111
12#include <__config>
1312#include <__algorithm/iter_swap.h>
13#include <__config>
1414#include <__iterator/iterator_traits.h>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1717#pragma GCC system_header
1818#endif
1919
20_LIBCPP_PUSH_MACROS
21#include <__undef_macros>
22
2320_LIBCPP_BEGIN_NAMESPACE_STD
2421
2522template <class _BidirectionalIterator>
......@@ -56,6 +53,4 @@ reverse(_BidirectionalIterator __first, _BidirectionalIterator __last)
5653
5754_LIBCPP_END_NAMESPACE_STD
5855
59_LIBCPP_POP_MACROS
60
6156#endif // _LIBCPP___ALGORITHM_REVERSE_H
lib/libcxx/include/__algorithm/reverse_copy.h-5
......@@ -15,9 +15,6 @@
1515#pragma GCC system_header
1616#endif
1717
18_LIBCPP_PUSH_MACROS
19#include <__undef_macros>
20
2118_LIBCPP_BEGIN_NAMESPACE_STD
2219
2320template <class _BidirectionalIterator, class _OutputIterator>
......@@ -32,6 +29,4 @@ reverse_copy(_BidirectionalIterator __first, _BidirectionalIterator __last, _Out
3229
3330_LIBCPP_END_NAMESPACE_STD
3431
35_LIBCPP_POP_MACROS
36
3732#endif // _LIBCPP___ALGORITHM_REVERSE_COPY_H
lib/libcxx/include/__algorithm/rotate.h-5
......@@ -23,9 +23,6 @@
2323#pragma GCC system_header
2424#endif
2525
26_LIBCPP_PUSH_MACROS
27#include <__undef_macros>
28
2926_LIBCPP_BEGIN_NAMESPACE_STD
3027
3128template <class _ForwardIterator>
......@@ -200,6 +197,4 @@ rotate(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __l
200197
201198_LIBCPP_END_NAMESPACE_STD
202199
203_LIBCPP_POP_MACROS
204
205200#endif // _LIBCPP___ALGORITHM_ROTATE_H
lib/libcxx/include/__algorithm/rotate_copy.h+1-8
......@@ -9,18 +9,13 @@
99#ifndef _LIBCPP___ALGORITHM_ROTATE_COPY_H
1010#define _LIBCPP___ALGORITHM_ROTATE_COPY_H
1111
12#include <__config>
1312#include <__algorithm/copy.h>
14#include <iterator>
15#include <type_traits>
13#include <__config>
1614
1715#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1816#pragma GCC system_header
1917#endif
2018
21_LIBCPP_PUSH_MACROS
22#include <__undef_macros>
23
2419_LIBCPP_BEGIN_NAMESPACE_STD
2520
2621template <class _ForwardIterator, class _OutputIterator>
......@@ -33,6 +28,4 @@ rotate_copy(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterato
3328
3429_LIBCPP_END_NAMESPACE_STD
3530
36_LIBCPP_POP_MACROS
37
3831#endif // _LIBCPP___ALGORITHM_ROTATE_COPY_H
lib/libcxx/include/__algorithm/sample.h+2-1
......@@ -9,8 +9,9 @@
99#ifndef _LIBCPP___ALGORITHM_SAMPLE_H
1010#define _LIBCPP___ALGORITHM_SAMPLE_H
1111
12#include <__config>
1312#include <__algorithm/min.h>
13#include <__config>
14#include <__debug>
1415#include <__random/uniform_int_distribution.h>
1516#include <iterator>
1617
lib/libcxx/include/__algorithm/search.h+3-9
......@@ -13,16 +13,12 @@
1313#include <__algorithm/comp.h>
1414#include <__config>
1515#include <__iterator/iterator_traits.h>
16#include <type_traits>
1716#include <utility>
1817
1918#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2019#pragma GCC system_header
2120#endif
2221
23_LIBCPP_PUSH_MACROS
24#include <__undef_macros>
25
2622_LIBCPP_BEGIN_NAMESPACE_STD
2723
2824template <class _BinaryPredicate, class _ForwardIterator1, class _ForwardIterator2>
......@@ -72,7 +68,7 @@ __search(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _Rando
7268 const _D1 __len1 = __last1 - __first1;
7369 if (__len1 < __len2)
7470 return _VSTD::make_pair(__last1, __last1);
75 const _RandomAccessIterator1 __s = __last1 - (__len2 - 1); // Start of pattern match can't go beyond here
71 const _RandomAccessIterator1 __s = __last1 - _D1(__len2 - 1); // Start of pattern match can't go beyond here
7672
7773 while (true) {
7874 while (true) {
......@@ -87,7 +83,7 @@ __search(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _Rando
8783 _RandomAccessIterator2 __m2 = __first2;
8884 while (true) {
8985 if (++__m2 == __last2)
90 return _VSTD::make_pair(__first1, __first1 + __len2);
86 return _VSTD::make_pair(__first1, __first1 + _D1(__len2));
9187 ++__m1; // no need to check range on __m1 because __s guarantees we have enough source
9288 if (!__pred(*__m1, *__m2)) {
9389 ++__first1;
......@@ -101,7 +97,7 @@ template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredica
10197_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator1
10298search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2,
10399 _BinaryPredicate __pred) {
104 return _VSTD::__search<typename add_lvalue_reference<_BinaryPredicate>::type>(
100 return _VSTD::__search<_BinaryPredicate&>(
105101 __first1, __last1, __first2, __last2, __pred,
106102 typename iterator_traits<_ForwardIterator1>::iterator_category(),
107103 typename iterator_traits<_ForwardIterator2>::iterator_category()).first;
......@@ -126,6 +122,4 @@ search(_ForwardIterator __f, _ForwardIterator __l, const _Searcher& __s) {
126122
127123_LIBCPP_END_NAMESPACE_STD
128124
129_LIBCPP_POP_MACROS
130
131125#endif // _LIBCPP___ALGORITHM_SEARCH_H
lib/libcxx/include/__algorithm/search_n.h+5-9
......@@ -10,18 +10,15 @@
1010#ifndef _LIBCPP___ALGORITHM_SEARCH_N_H
1111#define _LIBCPP___ALGORITHM_SEARCH_N_H
1212
13#include <__config>
1413#include <__algorithm/comp.h>
14#include <__config>
1515#include <__iterator/iterator_traits.h>
16#include <type_traits>
16#include <type_traits> // __convert_to_integral
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1919#pragma GCC system_header
2020#endif
2121
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
2522_LIBCPP_BEGIN_NAMESPACE_STD
2623
2724template <class _BinaryPredicate, class _ForwardIterator, class _Size, class _Tp>
......@@ -62,12 +59,13 @@ _LIBCPP_CONSTEXPR_AFTER_CXX17 _RandomAccessIterator __search_n(_RandomAccessIter
6259 _RandomAccessIterator __last, _Size __count,
6360 const _Tp& __value_, _BinaryPredicate __pred,
6461 random_access_iterator_tag) {
62 typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
6563 if (__count <= 0)
6664 return __first;
6765 _Size __len = static_cast<_Size>(__last - __first);
6866 if (__len < __count)
6967 return __last;
70 const _RandomAccessIterator __s = __last - (__count - 1); // Start of pattern match can't go beyond here
68 const _RandomAccessIterator __s = __last - difference_type(__count - 1); // Start of pattern match can't go beyond here
7169 while (true) {
7270 // Find first element in sequence that matchs __value_, with a mininum of loop checks
7371 while (true) {
......@@ -97,7 +95,7 @@ _LIBCPP_CONSTEXPR_AFTER_CXX17 _RandomAccessIterator __search_n(_RandomAccessIter
9795template <class _ForwardIterator, class _Size, class _Tp, class _BinaryPredicate>
9896_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator search_n(
9997 _ForwardIterator __first, _ForwardIterator __last, _Size __count, const _Tp& __value_, _BinaryPredicate __pred) {
100 return _VSTD::__search_n<typename add_lvalue_reference<_BinaryPredicate>::type>(
98 return _VSTD::__search_n<_BinaryPredicate&>(
10199 __first, __last, _VSTD::__convert_to_integral(__count), __value_, __pred,
102100 typename iterator_traits<_ForwardIterator>::iterator_category());
103101}
......@@ -111,6 +109,4 @@ search_n(_ForwardIterator __first, _ForwardIterator __last, _Size __count, const
111109
112110_LIBCPP_END_NAMESPACE_STD
113111
114_LIBCPP_POP_MACROS
115
116112#endif // _LIBCPP___ALGORITHM_SEARCH_N_H
lib/libcxx/include/__algorithm/set_difference.h+1-6
......@@ -9,19 +9,16 @@
99#ifndef _LIBCPP___ALGORITHM_SET_DIFFERENCE_H
1010#define _LIBCPP___ALGORITHM_SET_DIFFERENCE_H
1111
12#include <__config>
1312#include <__algorithm/comp.h>
1413#include <__algorithm/comp_ref_type.h>
1514#include <__algorithm/copy.h>
15#include <__config>
1616#include <__iterator/iterator_traits.h>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1919#pragma GCC system_header
2020#endif
2121
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
2522_LIBCPP_BEGIN_NAMESPACE_STD
2623
2724template <class _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator>
......@@ -72,6 +69,4 @@ set_difference(_InputIterator1 __first1, _InputIterator1 __last1,
7269
7370_LIBCPP_END_NAMESPACE_STD
7471
75_LIBCPP_POP_MACROS
76
7772#endif // _LIBCPP___ALGORITHM_SET_DIFFERENCE_H
lib/libcxx/include/__algorithm/set_intersection.h+1-6
......@@ -9,18 +9,15 @@
99#ifndef _LIBCPP___ALGORITHM_SET_INTERSECTION_H
1010#define _LIBCPP___ALGORITHM_SET_INTERSECTION_H
1111
12#include <__config>
1312#include <__algorithm/comp.h>
1413#include <__algorithm/comp_ref_type.h>
14#include <__config>
1515#include <__iterator/iterator_traits.h>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1818#pragma GCC system_header
1919#endif
2020
21_LIBCPP_PUSH_MACROS
22#include <__undef_macros>
23
2421_LIBCPP_BEGIN_NAMESPACE_STD
2522
2623template <class _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator>
......@@ -69,6 +66,4 @@ set_intersection(_InputIterator1 __first1, _InputIterator1 __last1,
6966
7067_LIBCPP_END_NAMESPACE_STD
7168
72_LIBCPP_POP_MACROS
73
7469#endif // _LIBCPP___ALGORITHM_SET_INTERSECTION_H
lib/libcxx/include/__algorithm/set_symmetric_difference.h+1-6
......@@ -9,19 +9,16 @@
99#ifndef _LIBCPP___ALGORITHM_SET_SYMMETRIC_DIFFERENCE_H
1010#define _LIBCPP___ALGORITHM_SET_SYMMETRIC_DIFFERENCE_H
1111
12#include <__config>
1312#include <__algorithm/comp.h>
1413#include <__algorithm/comp_ref_type.h>
1514#include <__algorithm/copy.h>
15#include <__config>
1616#include <__iterator/iterator_traits.h>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1919#pragma GCC system_header
2020#endif
2121
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
2522_LIBCPP_BEGIN_NAMESPACE_STD
2623
2724template <class _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator>
......@@ -77,6 +74,4 @@ set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 __last1,
7774
7875_LIBCPP_END_NAMESPACE_STD
7976
80_LIBCPP_POP_MACROS
81
8277#endif // _LIBCPP___ALGORITHM_SET_SYMMETRIC_DIFFERENCE_H
lib/libcxx/include/__algorithm/set_union.h+1-6
......@@ -9,19 +9,16 @@
99#ifndef _LIBCPP___ALGORITHM_SET_UNION_H
1010#define _LIBCPP___ALGORITHM_SET_UNION_H
1111
12#include <__config>
1312#include <__algorithm/comp.h>
1413#include <__algorithm/comp_ref_type.h>
1514#include <__algorithm/copy.h>
15#include <__config>
1616#include <__iterator/iterator_traits.h>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1919#pragma GCC system_header
2020#endif
2121
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
2522_LIBCPP_BEGIN_NAMESPACE_STD
2623
2724template <class _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator>
......@@ -72,6 +69,4 @@ set_union(_InputIterator1 __first1, _InputIterator1 __last1,
7269
7370_LIBCPP_END_NAMESPACE_STD
7471
75_LIBCPP_POP_MACROS
76
7772#endif // _LIBCPP___ALGORITHM_SET_UNION_H
lib/libcxx/include/__algorithm/shift_left.h+2-7
......@@ -9,18 +9,15 @@
99#ifndef _LIBCPP___ALGORITHM_SHIFT_LEFT_H
1010#define _LIBCPP___ALGORITHM_SHIFT_LEFT_H
1111
12#include <__config>
1312#include <__algorithm/move.h>
13#include <__config>
1414#include <__iterator/iterator_traits.h>
15#include <type_traits> // swap
15#include <type_traits>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1818#pragma GCC system_header
1919#endif
2020
21_LIBCPP_PUSH_MACROS
22#include <__undef_macros>
23
2421_LIBCPP_BEGIN_NAMESPACE_STD
2522
2623#if _LIBCPP_STD_VER > 17
......@@ -56,6 +53,4 @@ shift_left(_ForwardIterator __first, _ForwardIterator __last,
5653
5754_LIBCPP_END_NAMESPACE_STD
5855
59_LIBCPP_POP_MACROS
60
6156#endif // _LIBCPP___ALGORITHM_SHIFT_LEFT_H
lib/libcxx/include/__algorithm/shift_right.h+3-7
......@@ -9,20 +9,18 @@
99#ifndef _LIBCPP___ALGORITHM_SHIFT_RIGHT_H
1010#define _LIBCPP___ALGORITHM_SHIFT_RIGHT_H
1111
12#include <__config>
1312#include <__algorithm/move.h>
1413#include <__algorithm/move_backward.h>
1514#include <__algorithm/swap_ranges.h>
15#include <__config>
1616#include <__iterator/iterator_traits.h>
17#include <type_traits> // swap
17#include <__utility/swap.h>
18#include <type_traits>
1819
1920#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2021#pragma GCC system_header
2122#endif
2223
23_LIBCPP_PUSH_MACROS
24#include <__undef_macros>
25
2624_LIBCPP_BEGIN_NAMESPACE_STD
2725
2826#if _LIBCPP_STD_VER > 17
......@@ -101,6 +99,4 @@ shift_right(_ForwardIterator __first, _ForwardIterator __last,
10199
102100_LIBCPP_END_NAMESPACE_STD
103101
104_LIBCPP_POP_MACROS
105
106102#endif // _LIBCPP___ALGORITHM_SHIFT_RIGHT_H
lib/libcxx/include/__algorithm/shuffle.h+33
......@@ -25,6 +25,39 @@ _LIBCPP_PUSH_MACROS
2525
2626_LIBCPP_BEGIN_NAMESPACE_STD
2727
28class _LIBCPP_TYPE_VIS __libcpp_debug_randomizer {
29public:
30 __libcpp_debug_randomizer() {
31 __state = __seed();
32 __inc = __state + 0xda3e39cb94b95bdbULL;
33 __inc = (__inc << 1) | 1;
34 }
35 typedef uint_fast32_t result_type;
36
37 static const result_type _Min = 0;
38 static const result_type _Max = 0xFFFFFFFF;
39
40 _LIBCPP_HIDE_FROM_ABI result_type operator()() {
41 uint_fast64_t __oldstate = __state;
42 __state = __oldstate * 6364136223846793005ULL + __inc;
43 return __oldstate >> 32;
44 }
45
46 static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR result_type min() { return _Min; }
47 static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR result_type max() { return _Max; }
48
49private:
50 uint_fast64_t __state;
51 uint_fast64_t __inc;
52 _LIBCPP_HIDE_FROM_ABI static uint_fast64_t __seed() {
53#ifdef _LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY_SEED
54 return _LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY_SEED;
55#else
56 static char __x;
57 return reinterpret_cast<uintptr_t>(&__x);
58#endif
59 }
60};
2861
2962#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE) \
3063 || defined(_LIBCPP_BUILDING_LIBRARY)
lib/libcxx/include/__algorithm/sift_down.h+4-10
......@@ -17,15 +17,11 @@
1717#pragma GCC system_header
1818#endif
1919
20_LIBCPP_PUSH_MACROS
21#include <__undef_macros>
22
2320_LIBCPP_BEGIN_NAMESPACE_STD
2421
2522template <class _Compare, class _RandomAccessIterator>
2623_LIBCPP_CONSTEXPR_AFTER_CXX11 void
27__sift_down(_RandomAccessIterator __first, _RandomAccessIterator /*__last*/,
28 _Compare __comp,
24__sift_down(_RandomAccessIterator __first, _Compare __comp,
2925 typename iterator_traits<_RandomAccessIterator>::difference_type __len,
3026 _RandomAccessIterator __start)
3127{
......@@ -41,7 +37,7 @@ __sift_down(_RandomAccessIterator __first, _RandomAccessIterator /*__last*/,
4137 __child = 2 * __child + 1;
4238 _RandomAccessIterator __child_i = __first + __child;
4339
44 if ((__child + 1) < __len && __comp(*__child_i, *(__child_i + 1))) {
40 if ((__child + 1) < __len && __comp(*__child_i, *(__child_i + difference_type(1)))) {
4541 // right-child exists and is greater than left-child
4642 ++__child_i;
4743 ++__child;
......@@ -49,7 +45,7 @@ __sift_down(_RandomAccessIterator __first, _RandomAccessIterator /*__last*/,
4945
5046 // check if we are in heap-order
5147 if (__comp(*__child_i, *__start))
52 // we are, __start is larger than it's largest child
48 // we are, __start is larger than its largest child
5349 return;
5450
5551 value_type __top(_VSTD::move(*__start));
......@@ -66,7 +62,7 @@ __sift_down(_RandomAccessIterator __first, _RandomAccessIterator /*__last*/,
6662 __child = 2 * __child + 1;
6763 __child_i = __first + __child;
6864
69 if ((__child + 1) < __len && __comp(*__child_i, *(__child_i + 1))) {
65 if ((__child + 1) < __len && __comp(*__child_i, *(__child_i + difference_type(1)))) {
7066 // right-child exists and is greater than left-child
7167 ++__child_i;
7268 ++__child;
......@@ -79,6 +75,4 @@ __sift_down(_RandomAccessIterator __first, _RandomAccessIterator /*__last*/,
7975
8076_LIBCPP_END_NAMESPACE_STD
8177
82_LIBCPP_POP_MACROS
83
8478#endif // _LIBCPP___ALGORITHM_SIFT_DOWN_H
lib/libcxx/include/__algorithm/sort.h+62-36
......@@ -9,23 +9,23 @@
99#ifndef _LIBCPP___ALGORITHM_SORT_H
1010#define _LIBCPP___ALGORITHM_SORT_H
1111
12#include <__config>
1312#include <__algorithm/comp.h>
1413#include <__algorithm/comp_ref_type.h>
1514#include <__algorithm/min_element.h>
1615#include <__algorithm/partial_sort.h>
1716#include <__algorithm/unwrap_iter.h>
17#include <__config>
1818#include <__utility/swap.h>
1919#include <memory>
20#include <type_traits> // swap
20
21#if defined(_LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY)
22# include <__algorithm/shuffle.h>
23#endif
2124
2225#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2326#pragma GCC system_header
2427#endif
2528
26_LIBCPP_PUSH_MACROS
27#include <__undef_macros>
28
2929_LIBCPP_BEGIN_NAMESPACE_STD
3030
3131// stable, 2-3 compares, 0-2 swaps
......@@ -131,9 +131,7 @@ __selection_sort(_BidirectionalIterator __first, _BidirectionalIterator __last,
131131 _BidirectionalIterator __lm1 = __last;
132132 for (--__lm1; __first != __lm1; ++__first)
133133 {
134 _BidirectionalIterator __i = _VSTD::min_element<_BidirectionalIterator,
135 typename add_lvalue_reference<_Compare>::type>
136 (__first, __last, __comp);
134 _BidirectionalIterator __i = _VSTD::min_element(__first, __last, __comp);
137135 if (__i != __first)
138136 swap(*__first, *__i);
139137 }
......@@ -162,10 +160,11 @@ template <class _Compare, class _RandomAccessIterator>
162160void
163161__insertion_sort_3(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
164162{
163 typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
165164 typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
166 _RandomAccessIterator __j = __first+2;
167 _VSTD::__sort3<_Compare>(__first, __first+1, __j, __comp);
168 for (_RandomAccessIterator __i = __j+1; __i != __last; ++__i)
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)
169168 {
170169 if (__comp(*__i, *__j))
171170 {
......@@ -187,6 +186,7 @@ template <class _Compare, class _RandomAccessIterator>
187186bool
188187__insertion_sort_incomplete(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
189188{
189 typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
190190 switch (__last - __first)
191191 {
192192 case 0:
......@@ -197,21 +197,21 @@ __insertion_sort_incomplete(_RandomAccessIterator __first, _RandomAccessIterator
197197 swap(*__first, *__last);
198198 return true;
199199 case 3:
200 _VSTD::__sort3<_Compare>(__first, __first+1, --__last, __comp);
200 _VSTD::__sort3<_Compare>(__first, __first+difference_type(1), --__last, __comp);
201201 return true;
202202 case 4:
203 _VSTD::__sort4<_Compare>(__first, __first+1, __first+2, --__last, __comp);
203 _VSTD::__sort4<_Compare>(__first, __first+difference_type(1), __first+difference_type(2), --__last, __comp);
204204 return true;
205205 case 5:
206 _VSTD::__sort5<_Compare>(__first, __first+1, __first+2, __first+3, --__last, __comp);
206 _VSTD::__sort5<_Compare>(__first, __first+difference_type(1), __first+difference_type(2), __first+difference_type(3), --__last, __comp);
207207 return true;
208208 }
209209 typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
210 _RandomAccessIterator __j = __first+2;
211 _VSTD::__sort3<_Compare>(__first, __first+1, __j, __comp);
210 _RandomAccessIterator __j = __first+difference_type(2);
211 _VSTD::__sort3<_Compare>(__first, __first+difference_type(1), __j, __comp);
212212 const unsigned __limit = 8;
213213 unsigned __count = 0;
214 for (_RandomAccessIterator __i = __j+1; __i != __last; ++__i)
214 for (_RandomAccessIterator __i = __j+difference_type(1); __i != __last; ++__i)
215215 {
216216 if (__comp(*__i, *__j))
217217 {
......@@ -269,7 +269,8 @@ __insertion_sort_move(_BidirectionalIterator __first1, _BidirectionalIterator __
269269
270270template <class _Compare, class _RandomAccessIterator>
271271void
272__sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
272__introsort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp,
273 typename iterator_traits<_RandomAccessIterator>::difference_type __depth)
273274{
274275 typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
275276 typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
......@@ -289,13 +290,13 @@ __sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __c
289290 swap(*__first, *__last);
290291 return;
291292 case 3:
292 _VSTD::__sort3<_Compare>(__first, __first+1, --__last, __comp);
293 _VSTD::__sort3<_Compare>(__first, __first+difference_type(1), --__last, __comp);
293294 return;
294295 case 4:
295 _VSTD::__sort4<_Compare>(__first, __first+1, __first+2, --__last, __comp);
296 _VSTD::__sort4<_Compare>(__first, __first+difference_type(1), __first+difference_type(2), --__last, __comp);
296297 return;
297298 case 5:
298 _VSTD::__sort5<_Compare>(__first, __first+1, __first+2, __first+3, --__last, __comp);
299 _VSTD::__sort5<_Compare>(__first, __first+difference_type(1), __first+difference_type(2), __first+difference_type(3), --__last, __comp);
299300 return;
300301 }
301302 if (__len <= __limit)
......@@ -304,6 +305,13 @@ __sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __c
304305 return;
305306 }
306307 // __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;
307315 _RandomAccessIterator __m = __first;
308316 _RandomAccessIterator __lm1 = __last;
309317 --__lm1;
......@@ -427,7 +435,7 @@ __sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __c
427435 if (__n_swaps == 0)
428436 {
429437 bool __fs = _VSTD::__insertion_sort_incomplete<_Compare>(__first, __i, __comp);
430 if (_VSTD::__insertion_sort_incomplete<_Compare>(__i+1, __last, __comp))
438 if (_VSTD::__insertion_sort_incomplete<_Compare>(__i+difference_type(1), __last, __comp))
431439 {
432440 if (__fs)
433441 return;
......@@ -446,19 +454,34 @@ __sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __c
446454 // sort smaller range with recursive call and larger with tail recursion elimination
447455 if (__i - __first < __last - __i)
448456 {
449 _VSTD::__sort<_Compare>(__first, __i, __comp);
450 // _VSTD::__sort<_Compare>(__i+1, __last, __comp);
451 __first = ++__i;
457 _VSTD::__introsort<_Compare>(__first, __i, __comp, __depth);
458 __first = ++__i;
452459 }
453460 else
454461 {
455 _VSTD::__sort<_Compare>(__i+1, __last, __comp);
456 // _VSTD::__sort<_Compare>(__first, __i, __comp);
457 __last = __i;
462 _VSTD::__introsort<_Compare>(__i + difference_type(1), __last, __comp, __depth);
463 __last = __i;
458464 }
459465 }
460466}
461467
468template <typename _Number>
469inline _LIBCPP_HIDE_FROM_ABI _Number __log2i(_Number __n) {
470 _Number __log2 = 0;
471 while (__n > 1) {
472 __log2++;
473 __n >>= 1;
474 }
475 return __log2;
476}
477
478template <class _Compare, class _RandomAccessIterator>
479void __sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) {
480 typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
481 difference_type __depth_limit = 2 * __log2i(__last - __first);
482 _VSTD::__introsort<_Compare>(__first, __last, __comp, __depth_limit);
483}
484
462485template <class _Compare, class _Tp>
463486inline _LIBCPP_INLINE_VISIBILITY
464487void
......@@ -469,7 +492,9 @@ __sort(_Tp** __first, _Tp** __last, __less<_Tp*>&)
469492}
470493
471494_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<char>&, char*>(char*, char*, __less<char>&))
495#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
472496_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&))
497#endif
473498_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&))
474499_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<unsigned char>&, unsigned char*>(unsigned char*, unsigned char*, __less<unsigned char>&))
475500_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<short>&, short*>(short*, short*, __less<short>&))
......@@ -485,7 +510,9 @@ _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<double>&, double*>(d
485510_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<long double>&, long double*>(long double*, long double*, __less<long double>&))
486511
487512_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<char>&, char*>(char*, char*, __less<char>&))
513#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
488514_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&))
515#endif
489516_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&))
490517_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<unsigned char>&, unsigned char*>(unsigned char*, unsigned char*, __less<unsigned char>&))
491518_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<short>&, short*>(short*, short*, __less<short>&))
......@@ -507,12 +534,13 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
507534void
508535sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
509536{
510 typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
511 if (__libcpp_is_constant_evaluated()) {
512 _VSTD::__partial_sort<_Comp_ref>(__first, __last, __last, _Comp_ref(__comp));
513 } else {
514 _VSTD::__sort<_Comp_ref>(_VSTD::__unwrap_iter(__first), _VSTD::__unwrap_iter(__last), _Comp_ref(__comp));
515 }
537 _LIBCPP_DEBUG_RANDOMIZE_RANGE(__first, __last);
538 typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
539 if (__libcpp_is_constant_evaluated()) {
540 _VSTD::__partial_sort<_Comp_ref>(__first, __last, __last, _Comp_ref(__comp));
541 } else {
542 _VSTD::__sort<_Comp_ref>(_VSTD::__unwrap_iter(__first), _VSTD::__unwrap_iter(__last), _Comp_ref(__comp));
543 }
516544}
517545
518546template <class _RandomAccessIterator>
......@@ -525,6 +553,4 @@ sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
525553
526554_LIBCPP_END_NAMESPACE_STD
527555
528_LIBCPP_POP_MACROS
529
530556#endif // _LIBCPP___ALGORITHM_SORT_H
lib/libcxx/include/__algorithm/sort_heap.h+1-6
......@@ -9,10 +9,10 @@
99#ifndef _LIBCPP___ALGORITHM_SORT_HEAP_H
1010#define _LIBCPP___ALGORITHM_SORT_HEAP_H
1111
12#include <__config>
1312#include <__algorithm/comp.h>
1413#include <__algorithm/comp_ref_type.h>
1514#include <__algorithm/pop_heap.h>
15#include <__config>
1616#include <__iterator/iterator_traits.h>
1717#include <type_traits> // swap
1818
......@@ -20,9 +20,6 @@
2020#pragma GCC system_header
2121#endif
2222
23_LIBCPP_PUSH_MACROS
24#include <__undef_macros>
25
2623_LIBCPP_BEGIN_NAMESPACE_STD
2724
2825template <class _Compare, class _RandomAccessIterator>
......@@ -53,6 +50,4 @@ sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
5350
5451_LIBCPP_END_NAMESPACE_STD
5552
56_LIBCPP_POP_MACROS
57
5853#endif // _LIBCPP___ALGORITHM_SORT_HEAP_H
lib/libcxx/include/__algorithm/stable_partition.h+8-18
......@@ -9,8 +9,8 @@
99#ifndef _LIBCPP___ALGORITHM_STABLE_PARTITION_H
1010#define _LIBCPP___ALGORITHM_STABLE_PARTITION_H
1111
12#include <__config>
1312#include <__algorithm/rotate.h>
13#include <__config>
1414#include <__iterator/iterator_traits.h>
1515#include <__utility/swap.h>
1616#include <memory>
......@@ -19,9 +19,6 @@
1919#pragma GCC system_header
2020#endif
2121
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
2522_LIBCPP_BEGIN_NAMESPACE_STD
2623
2724template <class _Predicate, class _ForwardIterator, class _Distance, class _Pair>
......@@ -85,8 +82,7 @@ __stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate
8582 // recurse on [__first, __m), *__first know to be false
8683 // F?????????????????
8784 // f m l
88 typedef typename add_lvalue_reference<_Predicate>::type _PredRef;
89 _ForwardIterator __first_false = _VSTD::__stable_partition<_PredRef>(__first, __m, __pred, __len2, __p, __fit);
85 _ForwardIterator __first_false = _VSTD::__stable_partition<_Predicate&>(__first, __m, __pred, __len2, __p, __fit);
9086 // TTTFFFFF??????????
9187 // f ff m l
9288 // recurse on [__m, __last], except increase __m until *(__m) is false, *__last know to be true
......@@ -101,7 +97,7 @@ __stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate
10197 }
10298 // TTTFFFFFTTTF??????
10399 // f ff m m1 l
104 __second_false = _VSTD::__stable_partition<_PredRef>(__m1, __last, __pred, __len_half, __p, __fit);
100 __second_false = _VSTD::__stable_partition<_Predicate&>(__m1, __last, __pred, __len_half, __p, __fit);
105101__second_half_done:
106102 // TTTFFFFFTTTTTFFFFF
107103 // f ff m sf l
......@@ -137,8 +133,7 @@ __stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate
137133 __p = _VSTD::get_temporary_buffer<value_type>(__len);
138134 __h.reset(__p.first);
139135 }
140 return _VSTD::__stable_partition<typename add_lvalue_reference<_Predicate>::type>
141 (__first, __last, __pred, __len, __p, forward_iterator_tag());
136 return _VSTD::__stable_partition<_Predicate&>(__first, __last, __pred, __len, __p, forward_iterator_tag());
142137}
143138
144139template <class _Predicate, class _BidirectionalIterator, class _Distance, class _Pair>
......@@ -222,8 +217,7 @@ __stable_partition(_BidirectionalIterator __first, _BidirectionalIterator __last
222217 }
223218 // F???TFFF?????????T
224219 // f m1 m l
225 typedef typename add_lvalue_reference<_Predicate>::type _PredRef;
226 __first_false = _VSTD::__stable_partition<_PredRef>(__first, __m1, __pred, __len_half, __p, __bit);
220 __first_false = _VSTD::__stable_partition<_Predicate&>(__first, __m1, __pred, __len_half, __p, __bit);
227221__first_half_done:
228222 // TTTFFFFF?????????T
229223 // f ff m l
......@@ -240,7 +234,7 @@ __first_half_done:
240234 }
241235 // TTTFFFFFTTTF?????T
242236 // f ff m m1 l
243 __second_false = _VSTD::__stable_partition<_PredRef>(__m1, __last, __pred, __len_half, __p, __bit);
237 __second_false = _VSTD::__stable_partition<_Predicate&>(__m1, __last, __pred, __len_half, __p, __bit);
244238__second_half_done:
245239 // TTTFFFFFTTTTTFFFFF
246240 // f ff m sf l
......@@ -285,8 +279,7 @@ __stable_partition(_BidirectionalIterator __first, _BidirectionalIterator __last
285279 __p = _VSTD::get_temporary_buffer<value_type>(__len);
286280 __h.reset(__p.first);
287281 }
288 return _VSTD::__stable_partition<typename add_lvalue_reference<_Predicate>::type>
289 (__first, __last, __pred, __len, __p, bidirectional_iterator_tag());
282 return _VSTD::__stable_partition<_Predicate&>(__first, __last, __pred, __len, __p, bidirectional_iterator_tag());
290283}
291284
292285template <class _ForwardIterator, class _Predicate>
......@@ -294,12 +287,9 @@ inline _LIBCPP_INLINE_VISIBILITY
294287_ForwardIterator
295288stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
296289{
297 return _VSTD::__stable_partition<typename add_lvalue_reference<_Predicate>::type>
298 (__first, __last, __pred, typename iterator_traits<_ForwardIterator>::iterator_category());
290 return _VSTD::__stable_partition<_Predicate&>(__first, __last, __pred, typename iterator_traits<_ForwardIterator>::iterator_category());
299291}
300292
301293_LIBCPP_END_NAMESPACE_STD
302294
303_LIBCPP_POP_MACROS
304
305295#endif // _LIBCPP___ALGORITHM_STABLE_PARTITION_H
lib/libcxx/include/__algorithm/stable_sort.h+4-9
......@@ -9,23 +9,20 @@
99#ifndef _LIBCPP___ALGORITHM_STABLE_SORT_H
1010#define _LIBCPP___ALGORITHM_STABLE_SORT_H
1111
12#include <__config>
1312#include <__algorithm/comp.h>
1413#include <__algorithm/comp_ref_type.h>
1514#include <__algorithm/inplace_merge.h>
1615#include <__algorithm/sort.h>
16#include <__config>
1717#include <__iterator/iterator_traits.h>
1818#include <__utility/swap.h>
1919#include <memory>
20#include <type_traits> // swap
20#include <type_traits>
2121
2222#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2323#pragma GCC system_header
2424#endif
2525
26_LIBCPP_PUSH_MACROS
27#include <__undef_macros>
28
2926_LIBCPP_BEGIN_NAMESPACE_STD
3027
3128template <class _Compare, class _InputIterator1, class _InputIterator2>
......@@ -41,14 +38,14 @@ __merge_move_construct(_InputIterator1 __first1, _InputIterator1 __last1,
4138 {
4239 if (__first1 == __last1)
4340 {
44 for (; __first2 != __last2; ++__first2, ++__result, (void)__d.template __incr<value_type>())
41 for (; __first2 != __last2; ++__first2, (void) ++__result, __d.template __incr<value_type>())
4542 ::new ((void*)__result) value_type(_VSTD::move(*__first2));
4643 __h.release();
4744 return;
4845 }
4946 if (__first2 == __last2)
5047 {
51 for (; __first1 != __last1; ++__first1, ++__result, (void)__d.template __incr<value_type>())
48 for (; __first1 != __last1; ++__first1, (void) ++__result, __d.template __incr<value_type>())
5249 ::new ((void*)__result) value_type(_VSTD::move(*__first1));
5350 __h.release();
5451 return;
......@@ -230,6 +227,4 @@ stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
230227
231228_LIBCPP_END_NAMESPACE_STD
232229
233_LIBCPP_POP_MACROS
234
235230#endif // _LIBCPP___ALGORITHM_STABLE_SORT_H
lib/libcxx/include/__algorithm/swap_ranges.h-5
......@@ -17,9 +17,6 @@
1717#pragma GCC system_header
1818#endif
1919
20_LIBCPP_PUSH_MACROS
21#include <__undef_macros>
22
2320_LIBCPP_BEGIN_NAMESPACE_STD
2421
2522template <class _ForwardIterator1, class _ForwardIterator2>
......@@ -32,6 +29,4 @@ swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardItera
3229
3330_LIBCPP_END_NAMESPACE_STD
3431
35_LIBCPP_POP_MACROS
36
3732#endif // _LIBCPP___ALGORITHM_SWAP_RANGES_H
lib/libcxx/include/__algorithm/transform.h-5
......@@ -15,9 +15,6 @@
1515#pragma GCC system_header
1616#endif
1717
18_LIBCPP_PUSH_MACROS
19#include <__undef_macros>
20
2118_LIBCPP_BEGIN_NAMESPACE_STD
2219
2320template <class _InputIterator, class _OutputIterator, class _UnaryOperation>
......@@ -43,6 +40,4 @@ transform(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __f
4340
4441_LIBCPP_END_NAMESPACE_STD
4542
46_LIBCPP_POP_MACROS
47
4843#endif // _LIBCPP___ALGORITHM_TRANSFORM_H
lib/libcxx/include/__algorithm/unique.h+3-10
......@@ -9,20 +9,16 @@
99#ifndef _LIBCPP___ALGORITHM_UNIQUE_H
1010#define _LIBCPP___ALGORITHM_UNIQUE_H
1111
12#include <__config>
13#include <__algorithm/comp.h>
1412#include <__algorithm/adjacent_find.h>
13#include <__algorithm/comp.h>
14#include <__config>
1515#include <__iterator/iterator_traits.h>
1616#include <__utility/move.h>
17#include <type_traits>
1817
1918#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2019#pragma GCC system_header
2120#endif
2221
23_LIBCPP_PUSH_MACROS
24#include <__undef_macros>
25
2622_LIBCPP_BEGIN_NAMESPACE_STD
2723
2824// unique
......@@ -31,8 +27,7 @@ template <class _ForwardIterator, class _BinaryPredicate>
3127_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
3228unique(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred)
3329{
34 __first = _VSTD::adjacent_find<_ForwardIterator, typename add_lvalue_reference<_BinaryPredicate>::type>
35 (__first, __last, __pred);
30 __first = _VSTD::adjacent_find<_ForwardIterator, _BinaryPredicate&>(__first, __last, __pred);
3631 if (__first != __last)
3732 {
3833 // ... a a ? ...
......@@ -58,6 +53,4 @@ unique(_ForwardIterator __first, _ForwardIterator __last)
5853
5954_LIBCPP_END_NAMESPACE_STD
6055
61_LIBCPP_POP_MACROS
62
6356#endif // _LIBCPP___ALGORITHM_UNIQUE_H
lib/libcxx/include/__algorithm/unique_copy.h+2-9
......@@ -9,19 +9,15 @@
99#ifndef _LIBCPP___ALGORITHM_UNIQUE_COPY_H
1010#define _LIBCPP___ALGORITHM_UNIQUE_COPY_H
1111
12#include <__config>
1312#include <__algorithm/comp.h>
13#include <__config>
1414#include <__iterator/iterator_traits.h>
1515#include <utility>
16#include <type_traits>
1716
1817#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1918#pragma GCC system_header
2019#endif
2120
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
2521_LIBCPP_BEGIN_NAMESPACE_STD
2622
2723template <class _BinaryPredicate, class _InputIterator, class _OutputIterator>
......@@ -91,8 +87,7 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
9187_OutputIterator
9288unique_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryPredicate __pred)
9389{
94 return _VSTD::__unique_copy<typename add_lvalue_reference<_BinaryPredicate>::type>
95 (__first, __last, __result, __pred,
90 return _VSTD::__unique_copy<_BinaryPredicate&>(__first, __last, __result, __pred,
9691 typename iterator_traits<_InputIterator>::iterator_category(),
9792 typename iterator_traits<_OutputIterator>::iterator_category());
9893}
......@@ -109,6 +104,4 @@ unique_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __res
109104
110105_LIBCPP_END_NAMESPACE_STD
111106
112_LIBCPP_POP_MACROS
113
114107#endif // _LIBCPP___ALGORITHM_UNIQUE_COPY_H
lib/libcxx/include/__algorithm/unwrap_iter.h+3-6
......@@ -10,17 +10,14 @@
1010#define _LIBCPP___ALGORITHM_UNWRAP_ITER_H
1111
1212#include <__config>
13#include <iterator>
1413#include <__memory/pointer_traits.h>
14#include <iterator>
1515#include <type_traits>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1818#pragma GCC system_header
1919#endif
2020
21_LIBCPP_PUSH_MACROS
22#include <__undef_macros>
23
2421_LIBCPP_BEGIN_NAMESPACE_STD
2522
2623// The job of __unwrap_iter is to lower contiguous iterators (such as
......@@ -67,12 +64,14 @@ __unwrap_iter(_Iter __i) _NOEXCEPT
6764}
6865
6966template<class _OrigIter>
67_LIBCPP_HIDE_FROM_ABI
7068_OrigIter __rewrap_iter(_OrigIter, _OrigIter __result)
7169{
7270 return __result;
7371}
7472
7573template<class _OrigIter, class _UnwrappedIter>
74_LIBCPP_HIDE_FROM_ABI
7675_OrigIter __rewrap_iter(_OrigIter __first, _UnwrappedIter __result)
7776{
7877 // Precondition: __result is reachable from __first
......@@ -82,6 +81,4 @@ _OrigIter __rewrap_iter(_OrigIter __first, _UnwrappedIter __result)
8281
8382_LIBCPP_END_NAMESPACE_STD
8483
85_LIBCPP_POP_MACROS
86
8784#endif // _LIBCPP___ALGORITHM_UNWRAP_ITER_H
lib/libcxx/include/__algorithm/upper_bound.h+2-8
......@@ -9,18 +9,15 @@
99#ifndef _LIBCPP___ALGORITHM_UPPER_BOUND_H
1010#define _LIBCPP___ALGORITHM_UPPER_BOUND_H
1111
12#include <__config>
1312#include <__algorithm/comp.h>
1413#include <__algorithm/half_positive.h>
14#include <__config>
1515#include <iterator>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1818#pragma GCC system_header
1919#endif
2020
21_LIBCPP_PUSH_MACROS
22#include <__undef_macros>
23
2421_LIBCPP_BEGIN_NAMESPACE_STD
2522
2623template <class _Compare, class _ForwardIterator, class _Tp>
......@@ -51,8 +48,7 @@ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
5148_ForwardIterator
5249upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
5350{
54 typedef typename add_lvalue_reference<_Compare>::type _Comp_ref;
55 return _VSTD::__upper_bound<_Comp_ref>(__first, __last, __value_, __comp);
51 return _VSTD::__upper_bound<_Compare&>(__first, __last, __value_, __comp);
5652}
5753
5854template <class _ForwardIterator, class _Tp>
......@@ -67,6 +63,4 @@ upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __valu
6763
6864_LIBCPP_END_NAMESPACE_STD
6965
70_LIBCPP_POP_MACROS
71
7266#endif // _LIBCPP___ALGORITHM_UPPER_BOUND_H
lib/libcxx/include/__availability+13-6
......@@ -129,6 +129,10 @@
129129 // This controls the availability of std::to_chars.
130130# define _LIBCPP_AVAILABILITY_TO_CHARS
131131
132 // This controls the availability of floating-point std::to_chars functions.
133 // These overloads were added later than the integer overloads.
134# define _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT
135
132136 // This controls the availability of the C++20 synchronization library,
133137 // which requires shared library support for various operations
134138 // (see libcxx/src/atomic.cpp).
......@@ -139,9 +143,9 @@
139143// # define _LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_semaphore
140144
141145 // This controls the availability of the C++20 format library.
142 // The library is in development and not ABI stable yet. Currently
143 // P2216 is aiming to be retroactively accepted in C++20. This paper
144 // contains ABI breaking changes.
146 // The library is in development and not ABI stable yet. P2216 is
147 // retroactively accepted in C++20. This paper contains ABI breaking
148 // changes.
145149# define _LIBCPP_AVAILABILITY_FORMAT
146150// # define _LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_format
147151
......@@ -222,6 +226,9 @@
222226# define _LIBCPP_AVAILABILITY_TO_CHARS \
223227 _LIBCPP_AVAILABILITY_FILESYSTEM
224228
229# define _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT \
230 __attribute__((unavailable))
231
225232# define _LIBCPP_AVAILABILITY_SYNC \
226233 __attribute__((availability(macosx,strict,introduced=11.0))) \
227234 __attribute__((availability(ios,strict,introduced=14.0))) \
......@@ -238,9 +245,9 @@
238245# endif
239246
240247 // This controls the availability of the C++20 format library.
241 // The library is in development and not ABI stable yet. Currently
242 // P2216 is aiming to be retroactively accepted in C++20. This paper
243 // contains ABI breaking changes.
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.
244251# define _LIBCPP_AVAILABILITY_FORMAT \
245252 __attribute__((unavailable))
246253# define _LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_format
lib/libcxx/include/__bit/bit_cast.h created+38
......@@ -0,0 +1,38 @@
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___BIT_BIT_CAST_H
11#define _LIBCPP___BIT_BIT_CAST_H
12
13#include <__config>
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#if _LIBCPP_STD_VER > 17
23
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);
32}
33
34#endif // _LIBCPP_STD_VER > 17
35
36_LIBCPP_END_NAMESPACE_STD
37
38#endif // _LIBCPP___BIT_BIT_CAST_H
lib/libcxx/include/__bit/byteswap.h created+55
......@@ -0,0 +1,55 @@
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___BIT_BYTESWAP_H
11#define _LIBCPP___BIT_BYTESWAP_H
12
13#include <__concepts/arithmetic.h>
14#include <__config>
15#include <cstdint>
16#include <cstdlib>
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 && !defined(_LIBCPP_HAS_NO_CONCEPTS)
25
26template <integral _Tp>
27_LIBCPP_HIDE_FROM_ABI constexpr _Tp byteswap(_Tp __val) noexcept {
28
29 if constexpr (sizeof(_Tp) == 1) {
30 return __val;
31 } else if constexpr (sizeof(_Tp) == 2) {
32 return __builtin_bswap16(__val);
33 } else if constexpr (sizeof(_Tp) == 4) {
34 return __builtin_bswap32(__val);
35 } else if constexpr (sizeof(_Tp) == 8) {
36 return __builtin_bswap64(__val);
37#ifndef _LIBCPP_HAS_NO_INT128
38 } else if constexpr (sizeof(_Tp) == 16) {
39#if __has_builtin(__builtin_bswap128)
40 return __builtin_bswap128(__val);
41#else
42 return static_cast<_Tp>(byteswap(static_cast<uint64_t>(__val))) << 64 |
43 static_cast<_Tp>(byteswap(static_cast<uint64_t>(__val >> 64)));
44#endif // __has_builtin(__builtin_bswap128)
45#endif // _LIBCPP_HAS_NO_INT128
46 } else {
47 static_assert(sizeof(_Tp) == 0, "byteswap is unimplemented for integral types of this size");
48 }
49}
50
51#endif // _LIBCPP_STD_VER > 20 && !defined(_LIBCPP_HAS_NO_CONCEPTS)
52
53_LIBCPP_END_NAMESPACE_STD
54
55#endif // _LIBCPP___BIT_BYTESWAP_H
lib/libcxx/include/__bit_reference+1-1
......@@ -10,8 +10,8 @@
1010#ifndef _LIBCPP___BIT_REFERENCE
1111#define _LIBCPP___BIT_REFERENCE
1212
13#include <__config>
1413#include <__bits>
14#include <__config>
1515#include <algorithm>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
lib/libcxx/include/__bsd_locale_defaults.h+1-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===---------------------- __bsd_locale_defaults.h -----------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/__bsd_locale_fallbacks.h+8-4
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===---------------------- __bsd_locale_fallbacks.h ----------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -30,6 +30,7 @@ decltype(MB_CUR_MAX) __libcpp_mb_cur_max_l(locale_t __l)
3030 return MB_CUR_MAX;
3131}
3232
33#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
3334inline _LIBCPP_INLINE_VISIBILITY
3435wint_t __libcpp_btowc_l(int __c, locale_t __l)
3536{
......@@ -88,6 +89,7 @@ size_t __libcpp_mbrlen_l(const char *__s, size_t __n, mbstate_t *__ps, locale_t
8889 __libcpp_locale_guard __current(__l);
8990 return mbrlen(__s, __n, __ps);
9091}
92#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
9193
9294inline _LIBCPP_INLINE_VISIBILITY
9395lconv *__libcpp_localeconv_l(locale_t __l)
......@@ -96,6 +98,7 @@ lconv *__libcpp_localeconv_l(locale_t __l)
9698 return localeconv();
9799}
98100
101#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
99102inline _LIBCPP_INLINE_VISIBILITY
100103size_t __libcpp_mbsrtowcs_l(wchar_t *__dest, const char **__src, size_t __len,
101104 mbstate_t *__ps, locale_t __l)
......@@ -103,8 +106,9 @@ size_t __libcpp_mbsrtowcs_l(wchar_t *__dest, const char **__src, size_t __len,
103106 __libcpp_locale_guard __current(__l);
104107 return mbsrtowcs(__dest, __src, __len, __ps);
105108}
109#endif
106110
107inline
111inline _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 4, 5)
108112int __libcpp_snprintf_l(char *__s, size_t __n, locale_t __l, const char *__format, ...) {
109113 va_list __va;
110114 va_start(__va, __format);
......@@ -114,7 +118,7 @@ int __libcpp_snprintf_l(char *__s, size_t __n, locale_t __l, const char *__forma
114118 return __res;
115119}
116120
117inline
121inline _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 3, 4)
118122int __libcpp_asprintf_l(char **__s, locale_t __l, const char *__format, ...) {
119123 va_list __va;
120124 va_start(__va, __format);
......@@ -124,7 +128,7 @@ int __libcpp_asprintf_l(char **__s, locale_t __l, const char *__format, ...) {
124128 return __res;
125129}
126130
127inline
131inline _LIBCPP_ATTRIBUTE_FORMAT(__scanf__, 3, 4)
128132int __libcpp_sscanf_l(const char *__s, locale_t __l, const char *__format, ...) {
129133 va_list __va;
130134 va_start(__va, __format);
lib/libcxx/include/__charconv/chars_format.h created+77
......@@ -0,0 +1,77 @@
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_CHARS_FORMAT_H
11#define _LIBCPP___CHARCONV_CHARS_FORMAT_H
12
13#include <__config>
14#include <__utility/to_underlying.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#ifndef _LIBCPP_CXX03_LANG
23
24enum class _LIBCPP_ENUM_VIS chars_format
25{
26 scientific = 0x1,
27 fixed = 0x2,
28 hex = 0x4,
29 general = fixed | scientific
30};
31
32inline _LIBCPP_INLINE_VISIBILITY constexpr chars_format
33operator~(chars_format __x) {
34 return chars_format(~_VSTD::__to_underlying(__x));
35}
36
37inline _LIBCPP_INLINE_VISIBILITY constexpr chars_format
38operator&(chars_format __x, chars_format __y) {
39 return chars_format(_VSTD::__to_underlying(__x) &
40 _VSTD::__to_underlying(__y));
41}
42
43inline _LIBCPP_INLINE_VISIBILITY constexpr chars_format
44operator|(chars_format __x, chars_format __y) {
45 return chars_format(_VSTD::__to_underlying(__x) |
46 _VSTD::__to_underlying(__y));
47}
48
49inline _LIBCPP_INLINE_VISIBILITY constexpr chars_format
50operator^(chars_format __x, chars_format __y) {
51 return chars_format(_VSTD::__to_underlying(__x) ^
52 _VSTD::__to_underlying(__y));
53}
54
55inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 chars_format&
56operator&=(chars_format& __x, chars_format __y) {
57 __x = __x & __y;
58 return __x;
59}
60
61inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 chars_format&
62operator|=(chars_format& __x, chars_format __y) {
63 __x = __x | __y;
64 return __x;
65}
66
67inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 chars_format&
68operator^=(chars_format& __x, chars_format __y) {
69 __x = __x ^ __y;
70 return __x;
71}
72
73#endif // _LIBCPP_CXX03_LANG
74
75_LIBCPP_END_NAMESPACE_STD
76
77#endif // _LIBCPP___CHARCONV_CHARS_FORMAT_H
lib/libcxx/include/__charconv/from_chars_result.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___CHARCONV_FROM_CHARS_RESULT_H
11#define _LIBCPP___CHARCONV_FROM_CHARS_RESULT_H
12
13#include <__config>
14#include <__errc>
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
24struct _LIBCPP_TYPE_VIS from_chars_result
25{
26 const char* ptr;
27 errc ec;
28# if _LIBCPP_STD_VER > 17
29 _LIBCPP_HIDE_FROM_ABI friend bool operator==(const from_chars_result&, const from_chars_result&) = default;
30# endif
31};
32
33#endif // _LIBCPP_CXX03_LANG
34
35_LIBCPP_END_NAMESPACE_STD
36
37#endif // _LIBCPP___CHARCONV_FROM_CHARS_RESULT_H
lib/libcxx/include/__charconv/to_chars_result.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___CHARCONV_TO_CHARS_RESULT_H
11#define _LIBCPP___CHARCONV_TO_CHARS_RESULT_H
12
13#include <__config>
14#include <__errc>
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
24struct _LIBCPP_TYPE_VIS to_chars_result
25{
26 char* ptr;
27 errc ec;
28# if _LIBCPP_STD_VER > 17
29 _LIBCPP_HIDE_FROM_ABI friend bool operator==(const to_chars_result&, const to_chars_result&) = default;
30# endif
31};
32
33#endif // _LIBCPP_CXX03_LANG
34
35_LIBCPP_END_NAMESPACE_STD
36
37#endif // _LIBCPP___CHARCONV_TO_CHARS_RESULT_H
lib/libcxx/include/__chrono/calendar.h created+1276
......@@ -0,0 +1,1276 @@
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_CALENDAR_H
11#define _LIBCPP___CHRONO_CALENDAR_H
12
13#include <__chrono/duration.h>
14#include <__chrono/system_clock.h>
15#include <__chrono/time_point.h>
16#include <__config>
17#include <limits>
18#include <ratio>
19#include <type_traits>
20
21#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22#pragma GCC system_header
23#endif
24
25_LIBCPP_PUSH_MACROS
26#include <__undef_macros>
27
28#if _LIBCPP_STD_VER > 17
29
30_LIBCPP_BEGIN_NAMESPACE_STD
31
32namespace chrono
33{
34
35struct local_t {};
36template<class Duration>
37using local_time = time_point<local_t, Duration>;
38using local_seconds = local_time<seconds>;
39using local_days = local_time<days>;
40
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
389inline 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); }
504
505inline constexpr
506bool operator< (const month_day_last& __lhs, const month_day_last& __rhs) noexcept
507{ return __lhs.month() < __rhs.month(); }
508
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;
1268} // namespace chrono
1269
1270_LIBCPP_END_NAMESPACE_STD
1271
1272#endif // _LIBCPP_STD_VER > 17
1273
1274_LIBCPP_POP_MACROS
1275
1276#endif // _LIBCPP___CHRONO_CALENDAR_H
lib/libcxx/include/__chrono/convert_to_timespec.h created+55
......@@ -0,0 +1,55 @@
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___CHRONO_CONVERT_TO_TIMESPEC_H
10#define _LIBCPP___CHRONO_CONVERT_TO_TIMESPEC_H
11
12#include <__chrono/duration.h>
13#include <__config>
14#include <limits>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
18#endif
19
20_LIBCPP_PUSH_MACROS
21#include <__undef_macros>
22
23_LIBCPP_BEGIN_NAMESPACE_STD
24
25// Convert a nanoseconds duration to the given TimeSpec type, which must have
26// the same properties as std::timespec.
27template <class _TimeSpec>
28_LIBCPP_HIDE_FROM_ABI inline
29_TimeSpec __convert_to_timespec(const chrono::nanoseconds& __ns)
30{
31 using namespace chrono;
32 seconds __s = duration_cast<seconds>(__ns);
33 _TimeSpec __ts;
34 typedef decltype(__ts.tv_sec) __ts_sec;
35 const __ts_sec __ts_sec_max = numeric_limits<__ts_sec>::max();
36
37 if (__s.count() < __ts_sec_max)
38 {
39 __ts.tv_sec = static_cast<__ts_sec>(__s.count());
40 __ts.tv_nsec = static_cast<decltype(__ts.tv_nsec)>((__ns - __s).count());
41 }
42 else
43 {
44 __ts.tv_sec = __ts_sec_max;
45 __ts.tv_nsec = 999999999; // (10^9 - 1)
46 }
47
48 return __ts;
49}
50
51_LIBCPP_END_NAMESPACE_STD
52
53_LIBCPP_POP_MACROS
54
55#endif // _LIBCPP___CHRONO_CONVERT_TO_TIMESPEC_H
lib/libcxx/include/__chrono/duration.h created+615
......@@ -0,0 +1,615 @@
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_DURATION_H
11#define _LIBCPP___CHRONO_DURATION_H
12
13#include <__config>
14#include <limits>
15#include <ratio>
16#include <type_traits>
17
18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
20#endif
21
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
25_LIBCPP_BEGIN_NAMESPACE_STD
26
27namespace chrono
28{
29
30template <class _Rep, class _Period = ratio<1> > class _LIBCPP_TEMPLATE_VIS duration;
31
32template <class _Tp>
33struct __is_duration : false_type {};
34
35template <class _Rep, class _Period>
36struct __is_duration<duration<_Rep, _Period> > : true_type {};
37
38template <class _Rep, class _Period>
39struct __is_duration<const duration<_Rep, _Period> > : true_type {};
40
41template <class _Rep, class _Period>
42struct __is_duration<volatile duration<_Rep, _Period> > : true_type {};
43
44template <class _Rep, class _Period>
45struct __is_duration<const volatile duration<_Rep, _Period> > : true_type {};
46
47} // namespace chrono
48
49template <class _Rep1, class _Period1, class _Rep2, class _Period2>
50struct _LIBCPP_TEMPLATE_VIS common_type<chrono::duration<_Rep1, _Period1>,
51 chrono::duration<_Rep2, _Period2> >
52{
53 typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type,
54 typename __ratio_gcd<_Period1, _Period2>::type> type;
55};
56
57namespace chrono {
58
59// duration_cast
60
61template <class _FromDuration, class _ToDuration,
62 class _Period = typename ratio_divide<typename _FromDuration::period, typename _ToDuration::period>::type,
63 bool = _Period::num == 1,
64 bool = _Period::den == 1>
65struct __duration_cast;
66
67template <class _FromDuration, class _ToDuration, class _Period>
68struct __duration_cast<_FromDuration, _ToDuration, _Period, true, true>
69{
70 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
71 _ToDuration operator()(const _FromDuration& __fd) const
72 {
73 return _ToDuration(static_cast<typename _ToDuration::rep>(__fd.count()));
74 }
75};
76
77template <class _FromDuration, class _ToDuration, class _Period>
78struct __duration_cast<_FromDuration, _ToDuration, _Period, true, false>
79{
80 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
81 _ToDuration operator()(const _FromDuration& __fd) const
82 {
83 typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
84 return _ToDuration(static_cast<typename _ToDuration::rep>(
85 static_cast<_Ct>(__fd.count()) / static_cast<_Ct>(_Period::den)));
86 }
87};
88
89template <class _FromDuration, class _ToDuration, class _Period>
90struct __duration_cast<_FromDuration, _ToDuration, _Period, false, true>
91{
92 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
93 _ToDuration operator()(const _FromDuration& __fd) const
94 {
95 typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
96 return _ToDuration(static_cast<typename _ToDuration::rep>(
97 static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num)));
98 }
99};
100
101template <class _FromDuration, class _ToDuration, class _Period>
102struct __duration_cast<_FromDuration, _ToDuration, _Period, false, false>
103{
104 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
105 _ToDuration operator()(const _FromDuration& __fd) const
106 {
107 typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
108 return _ToDuration(static_cast<typename _ToDuration::rep>(
109 static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num)
110 / static_cast<_Ct>(_Period::den)));
111 }
112};
113
114template <class _ToDuration, class _Rep, class _Period>
115inline _LIBCPP_INLINE_VISIBILITY
116_LIBCPP_CONSTEXPR
117typename enable_if
118<
119 __is_duration<_ToDuration>::value,
120 _ToDuration
121>::type
122duration_cast(const duration<_Rep, _Period>& __fd)
123{
124 return __duration_cast<duration<_Rep, _Period>, _ToDuration>()(__fd);
125}
126
127template <class _Rep>
128struct _LIBCPP_TEMPLATE_VIS treat_as_floating_point : is_floating_point<_Rep> {};
129
130#if _LIBCPP_STD_VER > 14
131template <class _Rep>
132inline constexpr bool treat_as_floating_point_v = treat_as_floating_point<_Rep>::value;
133#endif
134
135template <class _Rep>
136struct _LIBCPP_TEMPLATE_VIS duration_values
137{
138public:
139 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep zero() _NOEXCEPT {return _Rep(0);}
140 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep max() _NOEXCEPT {return numeric_limits<_Rep>::max();}
141 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep min() _NOEXCEPT {return numeric_limits<_Rep>::lowest();}
142};
143
144#if _LIBCPP_STD_VER > 14
145template <class _ToDuration, class _Rep, class _Period>
146inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
147typename enable_if
148<
149 __is_duration<_ToDuration>::value,
150 _ToDuration
151>::type
152floor(const duration<_Rep, _Period>& __d)
153{
154 _ToDuration __t = duration_cast<_ToDuration>(__d);
155 if (__t > __d)
156 __t = __t - _ToDuration{1};
157 return __t;
158}
159
160template <class _ToDuration, class _Rep, class _Period>
161inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
162typename enable_if
163<
164 __is_duration<_ToDuration>::value,
165 _ToDuration
166>::type
167ceil(const duration<_Rep, _Period>& __d)
168{
169 _ToDuration __t = duration_cast<_ToDuration>(__d);
170 if (__t < __d)
171 __t = __t + _ToDuration{1};
172 return __t;
173}
174
175template <class _ToDuration, class _Rep, class _Period>
176inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
177typename enable_if
178<
179 __is_duration<_ToDuration>::value,
180 _ToDuration
181>::type
182round(const duration<_Rep, _Period>& __d)
183{
184 _ToDuration __lower = floor<_ToDuration>(__d);
185 _ToDuration __upper = __lower + _ToDuration{1};
186 auto __lowerDiff = __d - __lower;
187 auto __upperDiff = __upper - __d;
188 if (__lowerDiff < __upperDiff)
189 return __lower;
190 if (__lowerDiff > __upperDiff)
191 return __upper;
192 return __lower.count() & 1 ? __upper : __lower;
193}
194#endif
195
196// duration
197
198template <class _Rep, class _Period>
199class _LIBCPP_TEMPLATE_VIS duration
200{
201 static_assert(!__is_duration<_Rep>::value, "A duration representation can not be a duration");
202 static_assert(__is_ratio<_Period>::value, "Second template parameter of duration must be a std::ratio");
203 static_assert(_Period::num > 0, "duration period must be positive");
204
205 template <class _R1, class _R2>
206 struct __no_overflow
207 {
208 private:
209 static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value;
210 static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value;
211 static const intmax_t __n1 = _R1::num / __gcd_n1_n2;
212 static const intmax_t __d1 = _R1::den / __gcd_d1_d2;
213 static const intmax_t __n2 = _R2::num / __gcd_n1_n2;
214 static const intmax_t __d2 = _R2::den / __gcd_d1_d2;
215 static const intmax_t max = -((intmax_t(1) << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1);
216
217 template <intmax_t _Xp, intmax_t _Yp, bool __overflow>
218 struct __mul // __overflow == false
219 {
220 static const intmax_t value = _Xp * _Yp;
221 };
222
223 template <intmax_t _Xp, intmax_t _Yp>
224 struct __mul<_Xp, _Yp, true>
225 {
226 static const intmax_t value = 1;
227 };
228
229 public:
230 static const bool value = (__n1 <= max / __d2) && (__n2 <= max / __d1);
231 typedef ratio<__mul<__n1, __d2, !value>::value,
232 __mul<__n2, __d1, !value>::value> type;
233 };
234
235public:
236 typedef _Rep rep;
237 typedef typename _Period::type period;
238private:
239 rep __rep_;
240public:
241
242 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
243#ifndef _LIBCPP_CXX03_LANG
244 duration() = default;
245#else
246 duration() {}
247#endif
248
249 template <class _Rep2>
250 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
251 explicit duration(const _Rep2& __r,
252 typename enable_if
253 <
254 is_convertible<const _Rep2&, rep>::value &&
255 (treat_as_floating_point<rep>::value ||
256 !treat_as_floating_point<_Rep2>::value)
257 >::type* = nullptr)
258 : __rep_(__r) {}
259
260 // conversions
261 template <class _Rep2, class _Period2>
262 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
263 duration(const duration<_Rep2, _Period2>& __d,
264 typename enable_if
265 <
266 __no_overflow<_Period2, period>::value && (
267 treat_as_floating_point<rep>::value ||
268 (__no_overflow<_Period2, period>::type::den == 1 &&
269 !treat_as_floating_point<_Rep2>::value))
270 >::type* = nullptr)
271 : __rep_(chrono::duration_cast<duration>(__d).count()) {}
272
273 // observer
274
275 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR rep count() const {return __rep_;}
276
277 // arithmetic
278
279 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type<duration>::type operator+() const {return typename common_type<duration>::type(*this);}
280 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type<duration>::type operator-() const {return typename common_type<duration>::type(-__rep_);}
281 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator++() {++__rep_; return *this;}
282 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration operator++(int) {return duration(__rep_++);}
283 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator--() {--__rep_; return *this;}
284 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration operator--(int) {return duration(__rep_--);}
285
286 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator+=(const duration& __d) {__rep_ += __d.count(); return *this;}
287 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator-=(const duration& __d) {__rep_ -= __d.count(); return *this;}
288
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;}
293
294 // special values
295
296 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration zero() _NOEXCEPT {return duration(duration_values<rep>::zero());}
297 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration min() _NOEXCEPT {return duration(duration_values<rep>::min());}
298 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration max() _NOEXCEPT {return duration(duration_values<rep>::max());}
299};
300
301typedef duration<long long, nano> nanoseconds;
302typedef duration<long long, micro> microseconds;
303typedef duration<long long, milli> milliseconds;
304typedef duration<long long > seconds;
305typedef duration< long, ratio< 60> > minutes;
306typedef duration< long, ratio<3600> > hours;
307#if _LIBCPP_STD_VER > 17
308typedef duration< int, ratio_multiply<ratio<24>, hours::period>> days;
309typedef duration< int, ratio_multiply<ratio<7>, days::period>> weeks;
310typedef duration< int, ratio_multiply<ratio<146097, 400>, days::period>> years;
311typedef duration< int, ratio_divide<years::period, ratio<12>>> months;
312#endif
313// Duration ==
314
315template <class _LhsDuration, class _RhsDuration>
316struct __duration_eq
317{
318 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
319 bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const
320 {
321 typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
322 return _Ct(__lhs).count() == _Ct(__rhs).count();
323 }
324};
325
326template <class _LhsDuration>
327struct __duration_eq<_LhsDuration, _LhsDuration>
328{
329 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
330 bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const
331 {return __lhs.count() == __rhs.count();}
332};
333
334template <class _Rep1, class _Period1, class _Rep2, class _Period2>
335inline _LIBCPP_INLINE_VISIBILITY
336_LIBCPP_CONSTEXPR
337bool
338operator==(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
339{
340 return __duration_eq<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
341}
342
343// Duration !=
344
345template <class _Rep1, class _Period1, class _Rep2, class _Period2>
346inline _LIBCPP_INLINE_VISIBILITY
347_LIBCPP_CONSTEXPR
348bool
349operator!=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
350{
351 return !(__lhs == __rhs);
352}
353
354// Duration <
355
356template <class _LhsDuration, class _RhsDuration>
357struct __duration_lt
358{
359 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
360 bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const
361 {
362 typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
363 return _Ct(__lhs).count() < _Ct(__rhs).count();
364 }
365};
366
367template <class _LhsDuration>
368struct __duration_lt<_LhsDuration, _LhsDuration>
369{
370 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
371 bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const
372 {return __lhs.count() < __rhs.count();}
373};
374
375template <class _Rep1, class _Period1, class _Rep2, class _Period2>
376inline _LIBCPP_INLINE_VISIBILITY
377_LIBCPP_CONSTEXPR
378bool
379operator< (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
380{
381 return __duration_lt<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
382}
383
384// Duration >
385
386template <class _Rep1, class _Period1, class _Rep2, class _Period2>
387inline _LIBCPP_INLINE_VISIBILITY
388_LIBCPP_CONSTEXPR
389bool
390operator> (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
391{
392 return __rhs < __lhs;
393}
394
395// Duration <=
396
397template <class _Rep1, class _Period1, class _Rep2, class _Period2>
398inline _LIBCPP_INLINE_VISIBILITY
399_LIBCPP_CONSTEXPR
400bool
401operator<=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
402{
403 return !(__rhs < __lhs);
404}
405
406// Duration >=
407
408template <class _Rep1, class _Period1, class _Rep2, class _Period2>
409inline _LIBCPP_INLINE_VISIBILITY
410_LIBCPP_CONSTEXPR
411bool
412operator>=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
413{
414 return !(__lhs < __rhs);
415}
416
417// Duration +
418
419template <class _Rep1, class _Period1, class _Rep2, class _Period2>
420inline _LIBCPP_INLINE_VISIBILITY
421_LIBCPP_CONSTEXPR
422typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
423operator+(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
424{
425 typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
426 return _Cd(_Cd(__lhs).count() + _Cd(__rhs).count());
427}
428
429// Duration -
430
431template <class _Rep1, class _Period1, class _Rep2, class _Period2>
432inline _LIBCPP_INLINE_VISIBILITY
433_LIBCPP_CONSTEXPR
434typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
435operator-(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
436{
437 typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
438 return _Cd(_Cd(__lhs).count() - _Cd(__rhs).count());
439}
440
441// Duration *
442
443template <class _Rep1, class _Period, class _Rep2>
444inline _LIBCPP_INLINE_VISIBILITY
445_LIBCPP_CONSTEXPR
446typename enable_if
447<
448 is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value,
449 duration<typename common_type<_Rep1, _Rep2>::type, _Period>
450>::type
451operator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
452{
453 typedef typename common_type<_Rep1, _Rep2>::type _Cr;
454 typedef duration<_Cr, _Period> _Cd;
455 return _Cd(_Cd(__d).count() * static_cast<_Cr>(__s));
456}
457
458template <class _Rep1, class _Period, class _Rep2>
459inline _LIBCPP_INLINE_VISIBILITY
460_LIBCPP_CONSTEXPR
461typename enable_if
462<
463 is_convertible<_Rep1, typename common_type<_Rep1, _Rep2>::type>::value,
464 duration<typename common_type<_Rep1, _Rep2>::type, _Period>
465>::type
466operator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d)
467{
468 return __d * __s;
469}
470
471// Duration /
472
473template <class _Rep1, class _Period, class _Rep2>
474inline _LIBCPP_INLINE_VISIBILITY
475_LIBCPP_CONSTEXPR
476typename enable_if
477<
478 !__is_duration<_Rep2>::value &&
479 is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value,
480 duration<typename common_type<_Rep1, _Rep2>::type, _Period>
481>::type
482operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
483{
484 typedef typename common_type<_Rep1, _Rep2>::type _Cr;
485 typedef duration<_Cr, _Period> _Cd;
486 return _Cd(_Cd(__d).count() / static_cast<_Cr>(__s));
487}
488
489template <class _Rep1, class _Period1, class _Rep2, class _Period2>
490inline _LIBCPP_INLINE_VISIBILITY
491_LIBCPP_CONSTEXPR
492typename common_type<_Rep1, _Rep2>::type
493operator/(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
494{
495 typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Ct;
496 return _Ct(__lhs).count() / _Ct(__rhs).count();
497}
498
499// Duration %
500
501template <class _Rep1, class _Period, class _Rep2>
502inline _LIBCPP_INLINE_VISIBILITY
503_LIBCPP_CONSTEXPR
504typename enable_if
505<
506 !__is_duration<_Rep2>::value &&
507 is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value,
508 duration<typename common_type<_Rep1, _Rep2>::type, _Period>
509>::type
510operator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
511{
512 typedef typename common_type<_Rep1, _Rep2>::type _Cr;
513 typedef duration<_Cr, _Period> _Cd;
514 return _Cd(_Cd(__d).count() % static_cast<_Cr>(__s));
515}
516
517template <class _Rep1, class _Period1, class _Rep2, class _Period2>
518inline _LIBCPP_INLINE_VISIBILITY
519_LIBCPP_CONSTEXPR
520typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
521operator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
522{
523 typedef typename common_type<_Rep1, _Rep2>::type _Cr;
524 typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
525 return _Cd(static_cast<_Cr>(_Cd(__lhs).count()) % static_cast<_Cr>(_Cd(__rhs).count()));
526}
527
528} // namespace chrono
529
530#if _LIBCPP_STD_VER > 11
531// Suffixes for duration literals [time.duration.literals]
532inline namespace literals
533{
534 inline namespace chrono_literals
535 {
536
537 constexpr chrono::hours operator""h(unsigned long long __h)
538 {
539 return chrono::hours(static_cast<chrono::hours::rep>(__h));
540 }
541
542 constexpr chrono::duration<long double, ratio<3600,1>> operator""h(long double __h)
543 {
544 return chrono::duration<long double, ratio<3600,1>>(__h);
545 }
546
547
548 constexpr chrono::minutes operator""min(unsigned long long __m)
549 {
550 return chrono::minutes(static_cast<chrono::minutes::rep>(__m));
551 }
552
553 constexpr chrono::duration<long double, ratio<60,1>> operator""min(long double __m)
554 {
555 return chrono::duration<long double, ratio<60,1>> (__m);
556 }
557
558
559 constexpr chrono::seconds operator""s(unsigned long long __s)
560 {
561 return chrono::seconds(static_cast<chrono::seconds::rep>(__s));
562 }
563
564 constexpr chrono::duration<long double> operator""s(long double __s)
565 {
566 return chrono::duration<long double> (__s);
567 }
568
569
570 constexpr chrono::milliseconds operator""ms(unsigned long long __ms)
571 {
572 return chrono::milliseconds(static_cast<chrono::milliseconds::rep>(__ms));
573 }
574
575 constexpr chrono::duration<long double, milli> operator""ms(long double __ms)
576 {
577 return chrono::duration<long double, milli>(__ms);
578 }
579
580
581 constexpr chrono::microseconds operator""us(unsigned long long __us)
582 {
583 return chrono::microseconds(static_cast<chrono::microseconds::rep>(__us));
584 }
585
586 constexpr chrono::duration<long double, micro> operator""us(long double __us)
587 {
588 return chrono::duration<long double, micro> (__us);
589 }
590
591
592 constexpr chrono::nanoseconds operator""ns(unsigned long long __ns)
593 {
594 return chrono::nanoseconds(static_cast<chrono::nanoseconds::rep>(__ns));
595 }
596
597 constexpr chrono::duration<long double, nano> operator""ns(long double __ns)
598 {
599 return chrono::duration<long double, nano> (__ns);
600 }
601
602} // namespace chrono_literals
603} // namespace literals
604
605namespace chrono { // hoist the literals into namespace std::chrono
606 using namespace literals::chrono_literals;
607} // namespace chrono
608
609#endif // _LIBCPP_STD_VER > 11
610
611_LIBCPP_END_NAMESPACE_STD
612
613_LIBCPP_POP_MACROS
614
615#endif // _LIBCPP___CHRONO_DURATION_H
lib/libcxx/include/__chrono/file_clock.h created+85
......@@ -0,0 +1,85 @@
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_FILE_CLOCK_H
11#define _LIBCPP___CHRONO_FILE_CLOCK_H
12
13#include <__availability>
14#include <__chrono/duration.h>
15#include <__chrono/system_clock.h>
16#include <__chrono/time_point.h>
17#include <__config>
18#include <ratio>
19
20#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21#pragma GCC system_header
22#endif
23
24#ifndef _LIBCPP_CXX03_LANG
25_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
26struct _FilesystemClock;
27_LIBCPP_END_NAMESPACE_FILESYSTEM
28#endif // !_LIBCPP_CXX03_LANG
29
30#if _LIBCPP_STD_VER > 17
31
32_LIBCPP_BEGIN_NAMESPACE_STD
33
34namespace chrono
35{
36
37// [time.clock.file], type file_clock
38using file_clock = _VSTD_FS::_FilesystemClock;
39
40template<class _Duration>
41using file_time = time_point<file_clock, _Duration>;
42
43} // namespace chrono
44
45_LIBCPP_END_NAMESPACE_STD
46
47#endif // _LIBCPP_STD_VER > 17
48
49#ifndef _LIBCPP_CXX03_LANG
50_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
51struct _FilesystemClock {
52#if !defined(_LIBCPP_HAS_NO_INT128)
53 typedef __int128_t rep;
54 typedef nano period;
55#else
56 typedef long long rep;
57 typedef nano period;
58#endif
59
60 typedef chrono::duration<rep, period> duration;
61 typedef chrono::time_point<_FilesystemClock> time_point;
62
63 _LIBCPP_EXPORTED_FROM_ABI
64 static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false;
65
66 _LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_FUNC_VIS static time_point now() noexcept;
67
68#if _LIBCPP_STD_VER > 17
69 template <class _Duration>
70 _LIBCPP_HIDE_FROM_ABI
71 static chrono::sys_time<_Duration> to_sys(const chrono::file_time<_Duration>& __t) {
72 return chrono::sys_time<_Duration>(__t.time_since_epoch());
73 }
74
75 template <class _Duration>
76 _LIBCPP_HIDE_FROM_ABI
77 static chrono::file_time<_Duration> from_sys(const chrono::sys_time<_Duration>& __t) {
78 return chrono::file_time<_Duration>(__t.time_since_epoch());
79 }
80#endif // _LIBCPP_STD_VER > 17
81};
82_LIBCPP_END_NAMESPACE_FILESYSTEM
83#endif // !_LIBCPP_CXX03_LANG
84
85#endif // _LIBCPP___CHRONO_FILE_CLOCK_H
lib/libcxx/include/__chrono/high_resolution_clock.h created+36
......@@ -0,0 +1,36 @@
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_HIGH_RESOLUTION_CLOCK_H
11#define _LIBCPP___CHRONO_HIGH_RESOLUTION_CLOCK_H
12
13#include <__chrono/steady_clock.h>
14#include <__chrono/system_clock.h>
15#include <__config>
16
17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
19#endif
20
21_LIBCPP_BEGIN_NAMESPACE_STD
22
23namespace chrono
24{
25
26#ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK
27typedef steady_clock high_resolution_clock;
28#else
29typedef system_clock high_resolution_clock;
30#endif
31
32} // namespace chrono
33
34_LIBCPP_END_NAMESPACE_STD
35
36#endif // _LIBCPP___CHRONO_HIGH_RESOLUTION_CLOCK_H
lib/libcxx/include/__chrono/steady_clock.h created+44
......@@ -0,0 +1,44 @@
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_STEADY_CLOCK_H
11#define _LIBCPP___CHRONO_STEADY_CLOCK_H
12
13#include <__chrono/duration.h>
14#include <__chrono/time_point.h>
15#include <__config>
16
17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
19#endif
20
21_LIBCPP_BEGIN_NAMESPACE_STD
22
23namespace chrono
24{
25
26#ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK
27class _LIBCPP_TYPE_VIS steady_clock
28{
29public:
30 typedef nanoseconds duration;
31 typedef duration::rep rep;
32 typedef duration::period period;
33 typedef chrono::time_point<steady_clock, duration> time_point;
34 static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = true;
35
36 static time_point now() _NOEXCEPT;
37};
38#endif
39
40} // namespace chrono
41
42_LIBCPP_END_NAMESPACE_STD
43
44#endif // _LIBCPP___CHRONO_STEADY_CLOCK_H
lib/libcxx/include/__chrono/system_clock.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___CHRONO_SYSTEM_CLOCK_H
11#define _LIBCPP___CHRONO_SYSTEM_CLOCK_H
12
13#include <__chrono/duration.h>
14#include <__chrono/time_point.h>
15#include <__config>
16#include <ctime>
17
18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
20#endif
21
22_LIBCPP_BEGIN_NAMESPACE_STD
23
24namespace chrono
25{
26
27class _LIBCPP_TYPE_VIS system_clock
28{
29public:
30 typedef microseconds duration;
31 typedef duration::rep rep;
32 typedef duration::period period;
33 typedef chrono::time_point<system_clock> time_point;
34 static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false;
35
36 static time_point now() _NOEXCEPT;
37 static time_t to_time_t (const time_point& __t) _NOEXCEPT;
38 static time_point from_time_t(time_t __t) _NOEXCEPT;
39};
40
41#if _LIBCPP_STD_VER > 17
42
43template <class _Duration>
44using sys_time = time_point<system_clock, _Duration>;
45using sys_seconds = sys_time<seconds>;
46using sys_days = sys_time<days>;
47
48#endif
49
50} // namespace chrono
51
52_LIBCPP_END_NAMESPACE_STD
53
54#endif // _LIBCPP___CHRONO_SYSTEM_CLOCK_H
lib/libcxx/include/__chrono/time_point.h created+249
......@@ -0,0 +1,249 @@
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_TIME_POINT_H
11#define _LIBCPP___CHRONO_TIME_POINT_H
12
13#include <__chrono/duration.h>
14#include <__config>
15#include <limits>
16#include <type_traits>
17
18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
20#endif
21
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
25_LIBCPP_BEGIN_NAMESPACE_STD
26
27namespace chrono
28{
29
30template <class _Clock, class _Duration = typename _Clock::duration>
31class _LIBCPP_TEMPLATE_VIS time_point
32{
33 static_assert(__is_duration<_Duration>::value,
34 "Second template parameter of time_point must be a std::chrono::duration");
35public:
36 typedef _Clock clock;
37 typedef _Duration duration;
38 typedef typename duration::rep rep;
39 typedef typename duration::period period;
40private:
41 duration __d_;
42
43public:
44 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point() : __d_(duration::zero()) {}
45 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit time_point(const duration& __d) : __d_(__d) {}
46
47 // conversions
48 template <class _Duration2>
49 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
50 time_point(const time_point<clock, _Duration2>& t,
51 typename enable_if
52 <
53 is_convertible<_Duration2, duration>::value
54 >::type* = nullptr)
55 : __d_(t.time_since_epoch()) {}
56
57 // observer
58
59 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 duration time_since_epoch() const {return __d_;}
60
61 // arithmetic
62
63 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 time_point& operator+=(const duration& __d) {__d_ += __d; return *this;}
64 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 time_point& operator-=(const duration& __d) {__d_ -= __d; return *this;}
65
66 // special values
67
68 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point min() _NOEXCEPT {return time_point(duration::min());}
69 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point max() _NOEXCEPT {return time_point(duration::max());}
70};
71
72} // namespace chrono
73
74template <class _Clock, class _Duration1, class _Duration2>
75struct _LIBCPP_TEMPLATE_VIS common_type<chrono::time_point<_Clock, _Duration1>,
76 chrono::time_point<_Clock, _Duration2> >
77{
78 typedef chrono::time_point<_Clock, typename common_type<_Duration1, _Duration2>::type> type;
79};
80
81namespace chrono {
82
83template <class _ToDuration, class _Clock, class _Duration>
84inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
85time_point<_Clock, _ToDuration>
86time_point_cast(const time_point<_Clock, _Duration>& __t)
87{
88 return time_point<_Clock, _ToDuration>(chrono::duration_cast<_ToDuration>(__t.time_since_epoch()));
89}
90
91#if _LIBCPP_STD_VER > 14
92template <class _ToDuration, class _Clock, class _Duration>
93inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
94typename enable_if
95<
96 __is_duration<_ToDuration>::value,
97 time_point<_Clock, _ToDuration>
98>::type
99floor(const time_point<_Clock, _Duration>& __t)
100{
101 return time_point<_Clock, _ToDuration>{floor<_ToDuration>(__t.time_since_epoch())};
102}
103
104template <class _ToDuration, class _Clock, class _Duration>
105inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
106typename enable_if
107<
108 __is_duration<_ToDuration>::value,
109 time_point<_Clock, _ToDuration>
110>::type
111ceil(const time_point<_Clock, _Duration>& __t)
112{
113 return time_point<_Clock, _ToDuration>{ceil<_ToDuration>(__t.time_since_epoch())};
114}
115
116template <class _ToDuration, class _Clock, class _Duration>
117inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
118typename enable_if
119<
120 __is_duration<_ToDuration>::value,
121 time_point<_Clock, _ToDuration>
122>::type
123round(const time_point<_Clock, _Duration>& __t)
124{
125 return time_point<_Clock, _ToDuration>{round<_ToDuration>(__t.time_since_epoch())};
126}
127
128template <class _Rep, class _Period>
129inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
130typename enable_if
131<
132 numeric_limits<_Rep>::is_signed,
133 duration<_Rep, _Period>
134>::type
135abs(duration<_Rep, _Period> __d)
136{
137 return __d >= __d.zero() ? +__d : -__d;
138}
139#endif // _LIBCPP_STD_VER > 14
140
141// time_point ==
142
143template <class _Clock, class _Duration1, class _Duration2>
144inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
145bool
146operator==(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
147{
148 return __lhs.time_since_epoch() == __rhs.time_since_epoch();
149}
150
151// time_point !=
152
153template <class _Clock, class _Duration1, class _Duration2>
154inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
155bool
156operator!=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
157{
158 return !(__lhs == __rhs);
159}
160
161// time_point <
162
163template <class _Clock, class _Duration1, class _Duration2>
164inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
165bool
166operator<(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
167{
168 return __lhs.time_since_epoch() < __rhs.time_since_epoch();
169}
170
171// time_point >
172
173template <class _Clock, class _Duration1, class _Duration2>
174inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
175bool
176operator>(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
177{
178 return __rhs < __lhs;
179}
180
181// time_point <=
182
183template <class _Clock, class _Duration1, class _Duration2>
184inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
185bool
186operator<=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
187{
188 return !(__rhs < __lhs);
189}
190
191// time_point >=
192
193template <class _Clock, class _Duration1, class _Duration2>
194inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
195bool
196operator>=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
197{
198 return !(__lhs < __rhs);
199}
200
201// time_point operator+(time_point x, duration y);
202
203template <class _Clock, class _Duration1, class _Rep2, class _Period2>
204inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
205time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
206operator+(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
207{
208 typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Tr;
209 return _Tr (__lhs.time_since_epoch() + __rhs);
210}
211
212// time_point operator+(duration x, time_point y);
213
214template <class _Rep1, class _Period1, class _Clock, class _Duration2>
215inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
216time_point<_Clock, typename common_type<duration<_Rep1, _Period1>, _Duration2>::type>
217operator+(const duration<_Rep1, _Period1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
218{
219 return __rhs + __lhs;
220}
221
222// time_point operator-(time_point x, duration y);
223
224template <class _Clock, class _Duration1, class _Rep2, class _Period2>
225inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
226time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
227operator-(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
228{
229 typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Ret;
230 return _Ret(__lhs.time_since_epoch() -__rhs);
231}
232
233// duration operator-(time_point x, time_point y);
234
235template <class _Clock, class _Duration1, class _Duration2>
236inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
237typename common_type<_Duration1, _Duration2>::type
238operator-(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
239{
240 return __lhs.time_since_epoch() - __rhs.time_since_epoch();
241}
242
243} // namespace chrono
244
245_LIBCPP_END_NAMESPACE_STD
246
247_LIBCPP_POP_MACROS
248
249#endif // _LIBCPP___CHRONO_TIME_POINT_H
lib/libcxx/include/__compare/common_comparison_category.h created+94
......@@ -0,0 +1,94 @@
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___COMPARE_COMMON_COMPARISON_CATEGORY_H
10#define _LIBCPP___COMPARE_COMMON_COMPARISON_CATEGORY_H
11
12#include <__compare/ordering.h>
13#include <__config>
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#if _LIBCPP_STD_VER > 17
23
24namespace __comp_detail {
25
26enum _ClassifyCompCategory : unsigned {
27 _None,
28 _PartialOrd,
29 _WeakOrd,
30 _StrongOrd,
31 _CCC_Size
32};
33
34template <class _Tp>
35_LIBCPP_HIDE_FROM_ABI
36constexpr _ClassifyCompCategory __type_to_enum() noexcept {
37 if (is_same_v<_Tp, partial_ordering>)
38 return _PartialOrd;
39 if (is_same_v<_Tp, weak_ordering>)
40 return _WeakOrd;
41 if (is_same_v<_Tp, strong_ordering>)
42 return _StrongOrd;
43 return _None;
44}
45
46template <size_t _Size>
47_LIBCPP_HIDE_FROM_ABI
48constexpr _ClassifyCompCategory
49__compute_comp_type(const _ClassifyCompCategory (&__types)[_Size]) {
50 int __seen[_CCC_Size] = {};
51 for (auto __type : __types)
52 ++__seen[__type];
53 if (__seen[_None])
54 return _None;
55 if (__seen[_PartialOrd])
56 return _PartialOrd;
57 if (__seen[_WeakOrd])
58 return _WeakOrd;
59 return _StrongOrd;
60}
61
62template <class ..._Ts, bool _False = false>
63_LIBCPP_HIDE_FROM_ABI
64constexpr auto __get_comp_type() {
65 using _CCC = _ClassifyCompCategory;
66 constexpr _CCC __type_kinds[] = {_StrongOrd, __type_to_enum<_Ts>()...};
67 constexpr _CCC _Cat = __compute_comp_type(__type_kinds);
68 if constexpr (_Cat == _None)
69 return void();
70 else if constexpr (_Cat == _PartialOrd)
71 return partial_ordering::equivalent;
72 else if constexpr (_Cat == _WeakOrd)
73 return weak_ordering::equivalent;
74 else if constexpr (_Cat == _StrongOrd)
75 return strong_ordering::equivalent;
76 else
77 static_assert(_False, "unhandled case");
78}
79} // namespace __comp_detail
80
81// [cmp.common], common comparison category type
82template<class... _Ts>
83struct _LIBCPP_TEMPLATE_VIS common_comparison_category {
84 using type = decltype(__comp_detail::__get_comp_type<_Ts...>());
85};
86
87template<class... _Ts>
88using common_comparison_category_t = typename common_comparison_category<_Ts...>::type;
89
90#endif // _LIBCPP_STD_VER > 17
91
92_LIBCPP_END_NAMESPACE_STD
93
94#endif // _LIBCPP___COMPARE_COMMON_COMPARISON_CATEGORY_H
lib/libcxx/include/__compare/compare_partial_order_fallback.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___COMPARE_COMPARE_PARTIAL_ORDER_FALLBACK
10#define _LIBCPP___COMPARE_COMPARE_PARTIAL_ORDER_FALLBACK
11
12#include <__compare/ordering.h>
13#include <__compare/partial_order.h>
14#include <__config>
15#include <__utility/forward.h>
16#include <__utility/priority_tag.h>
17#include <type_traits>
18
19#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
20#pragma GCC system_header
21#endif
22
23_LIBCPP_BEGIN_NAMESPACE_STD
24
25#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
26
27// [cmp.alg]
28namespace __compare_partial_order_fallback {
29 struct __fn {
30 template<class _Tp, class _Up>
31 requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
32 _LIBCPP_HIDE_FROM_ABI static constexpr auto
33 __go(_Tp&& __t, _Up&& __u, __priority_tag<1>)
34 noexcept(noexcept(_VSTD::partial_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
35 -> decltype( _VSTD::partial_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))
36 { return _VSTD::partial_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)); }
37
38 template<class _Tp, class _Up>
39 requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
40 _LIBCPP_HIDE_FROM_ABI static constexpr auto
41 __go(_Tp&& __t, _Up&& __u, __priority_tag<0>)
42 noexcept(noexcept(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u) ? partial_ordering::equivalent :
43 _VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u) ? partial_ordering::less :
44 _VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t) ? partial_ordering::greater :
45 partial_ordering::unordered))
46 -> decltype( _VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u) ? partial_ordering::equivalent :
47 _VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u) ? partial_ordering::less :
48 _VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t) ? partial_ordering::greater :
49 partial_ordering::unordered)
50 {
51 return _VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u) ? partial_ordering::equivalent :
52 _VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u) ? partial_ordering::less :
53 _VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t) ? partial_ordering::greater :
54 partial_ordering::unordered;
55 }
56
57 template<class _Tp, class _Up>
58 _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t, _Up&& __u) const
59 noexcept(noexcept(__go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<1>())))
60 -> decltype( __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<1>()))
61 { return __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<1>()); }
62 };
63} // namespace __compare_partial_order_fallback
64
65inline namespace __cpo {
66 inline constexpr auto compare_partial_order_fallback = __compare_partial_order_fallback::__fn{};
67} // namespace __cpo
68
69#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
70
71_LIBCPP_END_NAMESPACE_STD
72
73#endif // _LIBCPP___COMPARE_COMPARE_PARTIAL_ORDER_FALLBACK
lib/libcxx/include/__compare/compare_strong_order_fallback.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___COMPARE_COMPARE_STRONG_ORDER_FALLBACK
10#define _LIBCPP___COMPARE_COMPARE_STRONG_ORDER_FALLBACK
11
12#include <__compare/ordering.h>
13#include <__compare/strong_order.h>
14#include <__config>
15#include <__utility/forward.h>
16#include <__utility/priority_tag.h>
17#include <type_traits>
18
19#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
20#pragma GCC system_header
21#endif
22
23_LIBCPP_BEGIN_NAMESPACE_STD
24
25#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
26
27// [cmp.alg]
28namespace __compare_strong_order_fallback {
29 struct __fn {
30 template<class _Tp, class _Up>
31 requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
32 _LIBCPP_HIDE_FROM_ABI static constexpr auto
33 __go(_Tp&& __t, _Up&& __u, __priority_tag<1>)
34 noexcept(noexcept(_VSTD::strong_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
35 -> decltype( _VSTD::strong_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))
36 { return _VSTD::strong_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)); }
37
38 template<class _Tp, class _Up>
39 requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
40 _LIBCPP_HIDE_FROM_ABI static constexpr auto
41 __go(_Tp&& __t, _Up&& __u, __priority_tag<0>)
42 noexcept(noexcept(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u) ? strong_ordering::equal :
43 _VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u) ? strong_ordering::less :
44 strong_ordering::greater))
45 -> decltype( _VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u) ? strong_ordering::equal :
46 _VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u) ? strong_ordering::less :
47 strong_ordering::greater)
48 {
49 return _VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u) ? strong_ordering::equal :
50 _VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u) ? strong_ordering::less :
51 strong_ordering::greater;
52 }
53
54 template<class _Tp, class _Up>
55 _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t, _Up&& __u) const
56 noexcept(noexcept(__go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<1>())))
57 -> decltype( __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<1>()))
58 { return __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<1>()); }
59 };
60} // namespace __compare_strong_order_fallback
61
62inline namespace __cpo {
63 inline constexpr auto compare_strong_order_fallback = __compare_strong_order_fallback::__fn{};
64} // namespace __cpo
65
66#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
67
68_LIBCPP_END_NAMESPACE_STD
69
70#endif // _LIBCPP___COMPARE_COMPARE_STRONG_ORDER_FALLBACK
lib/libcxx/include/__compare/compare_three_way.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___COMPARE_COMPARE_THREE_WAY_H
11#define _LIBCPP___COMPARE_COMPARE_THREE_WAY_H
12
13#include <__compare/three_way_comparable.h>
14#include <__config>
15#include <__utility/forward.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 !defined(_LIBCPP_HAS_NO_CONCEPTS)
24
25struct _LIBCPP_TEMPLATE_VIS compare_three_way
26{
27 template<class _T1, class _T2>
28 requires three_way_comparable_with<_T1, _T2>
29 constexpr _LIBCPP_HIDE_FROM_ABI
30 auto operator()(_T1&& __t, _T2&& __u) const
31 noexcept(noexcept(_VSTD::forward<_T1>(__t) <=> _VSTD::forward<_T2>(__u)))
32 { return _VSTD::forward<_T1>(__t) <=> _VSTD::forward<_T2>(__u); }
33
34 using is_transparent = void;
35};
36
37#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
38
39_LIBCPP_END_NAMESPACE_STD
40
41#endif // _LIBCPP___COMPARE_COMPARE_THREE_WAY_H
lib/libcxx/include/__compare/compare_three_way_result.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___COMPARE_COMPARE_THREE_WAY_RESULT_H
10#define _LIBCPP___COMPARE_COMPARE_THREE_WAY_RESULT_H
11
12#include <__config>
13#include <type_traits>
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
23template<class, class, class>
24struct _LIBCPP_HIDE_FROM_ABI __compare_three_way_result { };
25
26template<class _Tp, class _Up>
27struct _LIBCPP_HIDE_FROM_ABI __compare_three_way_result<_Tp, _Up, decltype(
28 declval<__make_const_lvalue_ref<_Tp>>() <=> declval<__make_const_lvalue_ref<_Up>>(), void()
29)> {
30 using type = decltype(declval<__make_const_lvalue_ref<_Tp>>() <=> declval<__make_const_lvalue_ref<_Up>>());
31};
32
33template<class _Tp, class _Up = _Tp>
34struct _LIBCPP_TEMPLATE_VIS compare_three_way_result : __compare_three_way_result<_Tp, _Up, void> { };
35
36template<class _Tp, class _Up = _Tp>
37using compare_three_way_result_t = typename compare_three_way_result<_Tp, _Up>::type;
38
39#endif // _LIBCPP_STD_VER > 17
40
41_LIBCPP_END_NAMESPACE_STD
42
43#endif // _LIBCPP___COMPARE_COMPARE_THREE_WAY_RESULT_H
lib/libcxx/include/__compare/compare_weak_order_fallback.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___COMPARE_COMPARE_WEAK_ORDER_FALLBACK
10#define _LIBCPP___COMPARE_COMPARE_WEAK_ORDER_FALLBACK
11
12#include <__compare/ordering.h>
13#include <__compare/weak_order.h>
14#include <__config>
15#include <__utility/forward.h>
16#include <__utility/priority_tag.h>
17#include <type_traits>
18
19#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
20#pragma GCC system_header
21#endif
22
23_LIBCPP_BEGIN_NAMESPACE_STD
24
25#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
26
27// [cmp.alg]
28namespace __compare_weak_order_fallback {
29 struct __fn {
30 template<class _Tp, class _Up>
31 requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
32 _LIBCPP_HIDE_FROM_ABI static constexpr auto
33 __go(_Tp&& __t, _Up&& __u, __priority_tag<1>)
34 noexcept(noexcept(_VSTD::weak_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
35 -> decltype( _VSTD::weak_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))
36 { return _VSTD::weak_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)); }
37
38 template<class _Tp, class _Up>
39 requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
40 _LIBCPP_HIDE_FROM_ABI static constexpr auto
41 __go(_Tp&& __t, _Up&& __u, __priority_tag<0>)
42 noexcept(noexcept(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u) ? weak_ordering::equivalent :
43 _VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u) ? weak_ordering::less :
44 weak_ordering::greater))
45 -> decltype( _VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u) ? weak_ordering::equivalent :
46 _VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u) ? weak_ordering::less :
47 weak_ordering::greater)
48 {
49 return _VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u) ? weak_ordering::equivalent :
50 _VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u) ? weak_ordering::less :
51 weak_ordering::greater;
52 }
53
54 template<class _Tp, class _Up>
55 _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t, _Up&& __u) const
56 noexcept(noexcept(__go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<1>())))
57 -> decltype( __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<1>()))
58 { return __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<1>()); }
59 };
60} // namespace __compare_weak_order_fallback
61
62inline namespace __cpo {
63 inline constexpr auto compare_weak_order_fallback = __compare_weak_order_fallback::__fn{};
64} // namespace __cpo
65
66#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
67
68_LIBCPP_END_NAMESPACE_STD
69
70#endif // _LIBCPP___COMPARE_COMPARE_WEAK_ORDER_FALLBACK
lib/libcxx/include/__compare/is_eq.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___COMPARE_IS_EQ_H
10#define _LIBCPP___COMPARE_IS_EQ_H
11
12#include <__compare/ordering.h>
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
23_LIBCPP_HIDE_FROM_ABI inline constexpr bool is_eq(partial_ordering __c) noexcept { return __c == 0; }
24_LIBCPP_HIDE_FROM_ABI inline constexpr bool is_neq(partial_ordering __c) noexcept { return __c != 0; }
25_LIBCPP_HIDE_FROM_ABI inline constexpr bool is_lt(partial_ordering __c) noexcept { return __c < 0; }
26_LIBCPP_HIDE_FROM_ABI inline constexpr bool is_lteq(partial_ordering __c) noexcept { return __c <= 0; }
27_LIBCPP_HIDE_FROM_ABI inline constexpr bool is_gt(partial_ordering __c) noexcept { return __c > 0; }
28_LIBCPP_HIDE_FROM_ABI inline constexpr bool is_gteq(partial_ordering __c) noexcept { return __c >= 0; }
29
30#endif // _LIBCPP_STD_VER > 17
31
32_LIBCPP_END_NAMESPACE_STD
33
34#endif // _LIBCPP___COMPARE_IS_EQ_H
lib/libcxx/include/__compare/ordering.h created+319
......@@ -0,0 +1,319 @@
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___COMPARE_ORDERING_H
10#define _LIBCPP___COMPARE_ORDERING_H
11
12#include <__config>
13#include <type_traits>
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
23// exposition only
24enum class _LIBCPP_ENUM_VIS _OrdResult : signed char {
25 __less = -1,
26 __equiv = 0,
27 __greater = 1
28};
29
30enum class _LIBCPP_ENUM_VIS _NCmpResult : signed char {
31 __unordered = -127
32};
33
34class partial_ordering;
35class weak_ordering;
36class strong_ordering;
37
38template<class _Tp, class... _Args>
39inline constexpr bool __one_of_v = (is_same_v<_Tp, _Args> || ...);
40
41struct _CmpUnspecifiedParam {
42 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEVAL
43 _CmpUnspecifiedParam(int _CmpUnspecifiedParam::*) noexcept {}
44
45 template<class _Tp, class = enable_if_t<!__one_of_v<_Tp, int, partial_ordering, weak_ordering, strong_ordering>>>
46 _CmpUnspecifiedParam(_Tp) = delete;
47};
48
49class partial_ordering {
50 using _ValueT = signed char;
51
52 _LIBCPP_HIDE_FROM_ABI
53 explicit constexpr partial_ordering(_OrdResult __v) noexcept
54 : __value_(_ValueT(__v)) {}
55
56 _LIBCPP_HIDE_FROM_ABI
57 explicit constexpr partial_ordering(_NCmpResult __v) noexcept
58 : __value_(_ValueT(__v)) {}
59
60 _LIBCPP_HIDE_FROM_ABI
61 constexpr bool __is_ordered() const noexcept {
62 return __value_ != _ValueT(_NCmpResult::__unordered);
63 }
64public:
65 // valid values
66 static const partial_ordering less;
67 static const partial_ordering equivalent;
68 static const partial_ordering greater;
69 static const partial_ordering unordered;
70
71 // comparisons
72 _LIBCPP_HIDE_FROM_ABI
73 friend constexpr bool operator==(partial_ordering, partial_ordering) noexcept = default;
74
75 _LIBCPP_HIDE_FROM_ABI
76 friend constexpr bool operator==(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
77 return __v.__is_ordered() && __v.__value_ == 0;
78 }
79
80 _LIBCPP_HIDE_FROM_ABI
81 friend constexpr bool operator< (partial_ordering __v, _CmpUnspecifiedParam) noexcept {
82 return __v.__is_ordered() && __v.__value_ < 0;
83 }
84
85 _LIBCPP_HIDE_FROM_ABI
86 friend constexpr bool operator<=(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
87 return __v.__is_ordered() && __v.__value_ <= 0;
88 }
89
90 _LIBCPP_HIDE_FROM_ABI
91 friend constexpr bool operator> (partial_ordering __v, _CmpUnspecifiedParam) noexcept {
92 return __v.__is_ordered() && __v.__value_ > 0;
93 }
94
95 _LIBCPP_HIDE_FROM_ABI
96 friend constexpr bool operator>=(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
97 return __v.__is_ordered() && __v.__value_ >= 0;
98 }
99
100 _LIBCPP_HIDE_FROM_ABI
101 friend constexpr bool operator< (_CmpUnspecifiedParam, partial_ordering __v) noexcept {
102 return __v.__is_ordered() && 0 < __v.__value_;
103 }
104
105 _LIBCPP_HIDE_FROM_ABI
106 friend constexpr bool operator<=(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
107 return __v.__is_ordered() && 0 <= __v.__value_;
108 }
109
110 _LIBCPP_HIDE_FROM_ABI
111 friend constexpr bool operator> (_CmpUnspecifiedParam, partial_ordering __v) noexcept {
112 return __v.__is_ordered() && 0 > __v.__value_;
113 }
114
115 _LIBCPP_HIDE_FROM_ABI
116 friend constexpr bool operator>=(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
117 return __v.__is_ordered() && 0 >= __v.__value_;
118 }
119
120 _LIBCPP_HIDE_FROM_ABI
121 friend constexpr partial_ordering operator<=>(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
122 return __v;
123 }
124
125 _LIBCPP_HIDE_FROM_ABI
126 friend constexpr partial_ordering operator<=>(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
127 return __v < 0 ? partial_ordering::greater : (__v > 0 ? partial_ordering::less : __v);
128 }
129private:
130 _ValueT __value_;
131};
132
133inline constexpr partial_ordering partial_ordering::less(_OrdResult::__less);
134inline constexpr partial_ordering partial_ordering::equivalent(_OrdResult::__equiv);
135inline constexpr partial_ordering partial_ordering::greater(_OrdResult::__greater);
136inline constexpr partial_ordering partial_ordering::unordered(_NCmpResult ::__unordered);
137
138class weak_ordering {
139 using _ValueT = signed char;
140
141 _LIBCPP_HIDE_FROM_ABI
142 explicit constexpr weak_ordering(_OrdResult __v) noexcept : __value_(_ValueT(__v)) {}
143
144public:
145 static const weak_ordering less;
146 static const weak_ordering equivalent;
147 static const weak_ordering greater;
148
149 _LIBCPP_HIDE_FROM_ABI
150 constexpr operator partial_ordering() const noexcept {
151 return __value_ == 0 ? partial_ordering::equivalent
152 : (__value_ < 0 ? partial_ordering::less : partial_ordering::greater);
153 }
154
155 // comparisons
156 _LIBCPP_HIDE_FROM_ABI
157 friend constexpr bool operator==(weak_ordering, weak_ordering) noexcept = default;
158
159 _LIBCPP_HIDE_FROM_ABI
160 friend constexpr bool operator==(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
161 return __v.__value_ == 0;
162 }
163
164 _LIBCPP_HIDE_FROM_ABI
165 friend constexpr bool operator< (weak_ordering __v, _CmpUnspecifiedParam) noexcept {
166 return __v.__value_ < 0;
167 }
168
169 _LIBCPP_HIDE_FROM_ABI
170 friend constexpr bool operator<=(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
171 return __v.__value_ <= 0;
172 }
173
174 _LIBCPP_HIDE_FROM_ABI
175 friend constexpr bool operator> (weak_ordering __v, _CmpUnspecifiedParam) noexcept {
176 return __v.__value_ > 0;
177 }
178
179 _LIBCPP_HIDE_FROM_ABI
180 friend constexpr bool operator>=(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
181 return __v.__value_ >= 0;
182 }
183
184 _LIBCPP_HIDE_FROM_ABI
185 friend constexpr bool operator< (_CmpUnspecifiedParam, weak_ordering __v) noexcept {
186 return 0 < __v.__value_;
187 }
188
189 _LIBCPP_HIDE_FROM_ABI
190 friend constexpr bool operator<=(_CmpUnspecifiedParam, weak_ordering __v) noexcept {
191 return 0 <= __v.__value_;
192 }
193
194 _LIBCPP_HIDE_FROM_ABI
195 friend constexpr bool operator> (_CmpUnspecifiedParam, weak_ordering __v) noexcept {
196 return 0 > __v.__value_;
197 }
198
199 _LIBCPP_HIDE_FROM_ABI
200 friend constexpr bool operator>=(_CmpUnspecifiedParam, weak_ordering __v) noexcept {
201 return 0 >= __v.__value_;
202 }
203
204 _LIBCPP_HIDE_FROM_ABI
205 friend constexpr weak_ordering operator<=>(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
206 return __v;
207 }
208
209 _LIBCPP_HIDE_FROM_ABI
210 friend constexpr weak_ordering operator<=>(_CmpUnspecifiedParam, weak_ordering __v) noexcept {
211 return __v < 0 ? weak_ordering::greater : (__v > 0 ? weak_ordering::less : __v);
212 }
213
214private:
215 _ValueT __value_;
216};
217
218inline constexpr weak_ordering weak_ordering::less(_OrdResult::__less);
219inline constexpr weak_ordering weak_ordering::equivalent(_OrdResult::__equiv);
220inline constexpr weak_ordering weak_ordering::greater(_OrdResult::__greater);
221
222class strong_ordering {
223 using _ValueT = signed char;
224
225 _LIBCPP_HIDE_FROM_ABI
226 explicit constexpr strong_ordering(_OrdResult __v) noexcept : __value_(_ValueT(__v)) {}
227
228public:
229 static const strong_ordering less;
230 static const strong_ordering equal;
231 static const strong_ordering equivalent;
232 static const strong_ordering greater;
233
234 // conversions
235 _LIBCPP_HIDE_FROM_ABI
236 constexpr operator partial_ordering() const noexcept {
237 return __value_ == 0 ? partial_ordering::equivalent
238 : (__value_ < 0 ? partial_ordering::less : partial_ordering::greater);
239 }
240
241 _LIBCPP_HIDE_FROM_ABI
242 constexpr operator weak_ordering() const noexcept {
243 return __value_ == 0 ? weak_ordering::equivalent
244 : (__value_ < 0 ? weak_ordering::less : weak_ordering::greater);
245 }
246
247 // comparisons
248 _LIBCPP_HIDE_FROM_ABI
249 friend constexpr bool operator==(strong_ordering, strong_ordering) noexcept = default;
250
251 _LIBCPP_HIDE_FROM_ABI
252 friend constexpr bool operator==(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
253 return __v.__value_ == 0;
254 }
255
256 _LIBCPP_HIDE_FROM_ABI
257 friend constexpr bool operator< (strong_ordering __v, _CmpUnspecifiedParam) noexcept {
258 return __v.__value_ < 0;
259 }
260
261 _LIBCPP_HIDE_FROM_ABI
262 friend constexpr bool operator<=(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
263 return __v.__value_ <= 0;
264 }
265
266 _LIBCPP_HIDE_FROM_ABI
267 friend constexpr bool operator> (strong_ordering __v, _CmpUnspecifiedParam) noexcept {
268 return __v.__value_ > 0;
269 }
270
271 _LIBCPP_HIDE_FROM_ABI
272 friend constexpr bool operator>=(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
273 return __v.__value_ >= 0;
274 }
275
276 _LIBCPP_HIDE_FROM_ABI
277 friend constexpr bool operator< (_CmpUnspecifiedParam, strong_ordering __v) noexcept {
278 return 0 < __v.__value_;
279 }
280
281 _LIBCPP_HIDE_FROM_ABI
282 friend constexpr bool operator<=(_CmpUnspecifiedParam, strong_ordering __v) noexcept {
283 return 0 <= __v.__value_;
284 }
285
286 _LIBCPP_HIDE_FROM_ABI
287 friend constexpr bool operator> (_CmpUnspecifiedParam, strong_ordering __v) noexcept {
288 return 0 > __v.__value_;
289 }
290
291 _LIBCPP_HIDE_FROM_ABI
292 friend constexpr bool operator>=(_CmpUnspecifiedParam, strong_ordering __v) noexcept {
293 return 0 >= __v.__value_;
294 }
295
296 _LIBCPP_HIDE_FROM_ABI
297 friend constexpr strong_ordering operator<=>(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
298 return __v;
299 }
300
301 _LIBCPP_HIDE_FROM_ABI
302 friend constexpr strong_ordering operator<=>(_CmpUnspecifiedParam, strong_ordering __v) noexcept {
303 return __v < 0 ? strong_ordering::greater : (__v > 0 ? strong_ordering::less : __v);
304 }
305
306private:
307 _ValueT __value_;
308};
309
310inline constexpr strong_ordering strong_ordering::less(_OrdResult::__less);
311inline constexpr strong_ordering strong_ordering::equal(_OrdResult::__equiv);
312inline constexpr strong_ordering strong_ordering::equivalent(_OrdResult::__equiv);
313inline constexpr strong_ordering strong_ordering::greater(_OrdResult::__greater);
314
315#endif // _LIBCPP_STD_VER > 17
316
317_LIBCPP_END_NAMESPACE_STD
318
319#endif // _LIBCPP___COMPARE_ORDERING_H
lib/libcxx/include/__compare/partial_order.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___COMPARE_PARTIAL_ORDER
10#define _LIBCPP___COMPARE_PARTIAL_ORDER
11
12#include <__compare/compare_three_way.h>
13#include <__compare/ordering.h>
14#include <__compare/weak_order.h>
15#include <__config>
16#include <__utility/forward.h>
17#include <__utility/priority_tag.h>
18#include <type_traits>
19
20#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
21#pragma GCC system_header
22#endif
23
24_LIBCPP_BEGIN_NAMESPACE_STD
25
26#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
27
28// [cmp.alg]
29namespace __partial_order {
30 struct __fn {
31 template<class _Tp, class _Up>
32 requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
33 _LIBCPP_HIDE_FROM_ABI static constexpr auto
34 __go(_Tp&& __t, _Up&& __u, __priority_tag<2>)
35 noexcept(noexcept(partial_ordering(partial_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))))
36 -> decltype( partial_ordering(partial_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
37 { return partial_ordering(partial_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))); }
38
39 template<class _Tp, class _Up>
40 requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
41 _LIBCPP_HIDE_FROM_ABI static constexpr auto
42 __go(_Tp&& __t, _Up&& __u, __priority_tag<1>)
43 noexcept(noexcept(partial_ordering(compare_three_way()(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))))
44 -> decltype( partial_ordering(compare_three_way()(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
45 { return partial_ordering(compare_three_way()(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))); }
46
47 template<class _Tp, class _Up>
48 requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
49 _LIBCPP_HIDE_FROM_ABI static constexpr auto
50 __go(_Tp&& __t, _Up&& __u, __priority_tag<0>)
51 noexcept(noexcept(partial_ordering(_VSTD::weak_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))))
52 -> decltype( partial_ordering(_VSTD::weak_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
53 { return partial_ordering(_VSTD::weak_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))); }
54
55 template<class _Tp, class _Up>
56 _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t, _Up&& __u) const
57 noexcept(noexcept(__go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<2>())))
58 -> decltype( __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<2>()))
59 { return __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<2>()); }
60 };
61} // namespace __partial_order
62
63inline namespace __cpo {
64 inline constexpr auto partial_order = __partial_order::__fn{};
65} // namespace __cpo
66
67#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
68
69_LIBCPP_END_NAMESPACE_STD
70
71#endif // _LIBCPP___COMPARE_PARTIAL_ORDER
lib/libcxx/include/__compare/strong_order.h created+136
......@@ -0,0 +1,136 @@
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___COMPARE_STRONG_ORDER
10#define _LIBCPP___COMPARE_STRONG_ORDER
11
12#include <__bit/bit_cast.h>
13#include <__compare/compare_three_way.h>
14#include <__compare/ordering.h>
15#include <__config>
16#include <__utility/forward.h>
17#include <__utility/priority_tag.h>
18#include <cmath>
19#include <cstdint>
20#include <limits>
21#include <type_traits>
22
23#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
24#pragma GCC system_header
25#endif
26
27_LIBCPP_PUSH_MACROS
28#include <__undef_macros>
29
30_LIBCPP_BEGIN_NAMESPACE_STD
31
32#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
33
34// [cmp.alg]
35namespace __strong_order {
36 struct __fn {
37 template<class _Tp, class _Up>
38 requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
39 _LIBCPP_HIDE_FROM_ABI static constexpr auto
40 __go(_Tp&& __t, _Up&& __u, __priority_tag<2>)
41 noexcept(noexcept(strong_ordering(strong_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))))
42 -> decltype( strong_ordering(strong_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
43 { return strong_ordering(strong_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))); }
44
45 template<class _Tp, class _Up, class _Dp = decay_t<_Tp>>
46 requires is_same_v<_Dp, decay_t<_Up>> && is_floating_point_v<_Dp>
47 _LIBCPP_HIDE_FROM_ABI static constexpr strong_ordering
48 __go(_Tp&& __t, _Up&& __u, __priority_tag<1>) noexcept
49 {
50 if constexpr (numeric_limits<_Dp>::is_iec559 && sizeof(_Dp) == sizeof(int32_t)) {
51 int32_t __rx = _VSTD::bit_cast<int32_t>(__t);
52 int32_t __ry = _VSTD::bit_cast<int32_t>(__u);
53 __rx = (__rx < 0) ? (numeric_limits<int32_t>::min() - __rx - 1) : __rx;
54 __ry = (__ry < 0) ? (numeric_limits<int32_t>::min() - __ry - 1) : __ry;
55 return (__rx <=> __ry);
56 } else if constexpr (numeric_limits<_Dp>::is_iec559 && sizeof(_Dp) == sizeof(int64_t)) {
57 int64_t __rx = _VSTD::bit_cast<int64_t>(__t);
58 int64_t __ry = _VSTD::bit_cast<int64_t>(__u);
59 __rx = (__rx < 0) ? (numeric_limits<int64_t>::min() - __rx - 1) : __rx;
60 __ry = (__ry < 0) ? (numeric_limits<int64_t>::min() - __ry - 1) : __ry;
61 return (__rx <=> __ry);
62 } else if (__t < __u) {
63 return strong_ordering::less;
64 } else if (__t > __u) {
65 return strong_ordering::greater;
66 } else if (__t == __u) {
67 if constexpr (numeric_limits<_Dp>::radix == 2) {
68 return _VSTD::signbit(__u) <=> _VSTD::signbit(__t);
69 } else {
70 // This is bullet 3 of the IEEE754 algorithm, relevant
71 // only for decimal floating-point;
72 // see https://stackoverflow.com/questions/69068075/
73 if (__t == 0 || _VSTD::isinf(__t)) {
74 return _VSTD::signbit(__u) <=> _VSTD::signbit(__t);
75 } else {
76 int __texp, __uexp;
77 (void)_VSTD::frexp(__t, &__texp);
78 (void)_VSTD::frexp(__u, &__uexp);
79 return (__t < 0) ? (__texp <=> __uexp) : (__uexp <=> __texp);
80 }
81 }
82 } else {
83 // They're unordered, so one of them must be a NAN.
84 // The order is -QNAN, -SNAN, numbers, +SNAN, +QNAN.
85 bool __t_is_nan = _VSTD::isnan(__t);
86 bool __u_is_nan = _VSTD::isnan(__u);
87 bool __t_is_negative = _VSTD::signbit(__t);
88 bool __u_is_negative = _VSTD::signbit(__u);
89 using _IntType = conditional_t<
90 sizeof(__t) == sizeof(int32_t), int32_t, conditional_t<
91 sizeof(__t) == sizeof(int64_t), int64_t, void>
92 >;
93 if constexpr (is_same_v<_IntType, void>) {
94 static_assert(sizeof(_Dp) == 0, "std::strong_order is unimplemented for this floating-point type");
95 } else if (__t_is_nan && __u_is_nan) {
96 // Order by sign bit, then by "payload bits" (we'll just use bit_cast).
97 if (__t_is_negative != __u_is_negative) {
98 return (__u_is_negative <=> __t_is_negative);
99 } else {
100 return _VSTD::bit_cast<_IntType>(__t) <=> _VSTD::bit_cast<_IntType>(__u);
101 }
102 } else if (__t_is_nan) {
103 return __t_is_negative ? strong_ordering::less : strong_ordering::greater;
104 } else {
105 return __u_is_negative ? strong_ordering::greater : strong_ordering::less;
106 }
107 }
108 }
109
110 template<class _Tp, class _Up>
111 requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
112 _LIBCPP_HIDE_FROM_ABI static constexpr auto
113 __go(_Tp&& __t, _Up&& __u, __priority_tag<0>)
114 noexcept(noexcept(strong_ordering(compare_three_way()(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))))
115 -> decltype( strong_ordering(compare_three_way()(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
116 { return strong_ordering(compare_three_way()(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))); }
117
118 template<class _Tp, class _Up>
119 _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t, _Up&& __u) const
120 noexcept(noexcept(__go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<2>())))
121 -> decltype( __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<2>()))
122 { return __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<2>()); }
123 };
124} // namespace __strong_order
125
126inline namespace __cpo {
127 inline constexpr auto strong_order = __strong_order::__fn{};
128} // namespace __cpo
129
130#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
131
132_LIBCPP_END_NAMESPACE_STD
133
134_LIBCPP_POP_MACROS
135
136#endif // _LIBCPP___COMPARE_STRONG_ORDER
lib/libcxx/include/__compare/synth_three_way.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___COMPARE_SYNTH_THREE_WAY_H
10#define _LIBCPP___COMPARE_SYNTH_THREE_WAY_H
11
12#include <__compare/ordering.h>
13#include <__compare/three_way_comparable.h>
14#include <__concepts/boolean_testable.h>
15#include <__config>
16#include <__utility/declval.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 !defined(_LIBCPP_HAS_NO_CONCEPTS)
25
26// [expos.only.func]
27
28_LIBCPP_HIDE_FROM_ABI inline constexpr auto __synth_three_way =
29 []<class _Tp, class _Up>(const _Tp& __t, const _Up& __u)
30 requires requires {
31 { __t < __u } -> __boolean_testable;
32 { __u < __t } -> __boolean_testable;
33 }
34 {
35 if constexpr (three_way_comparable_with<_Tp, _Up>) {
36 return __t <=> __u;
37 } else {
38 if (__t < __u) return weak_ordering::less;
39 if (__u < __t) return weak_ordering::greater;
40 return weak_ordering::equivalent;
41 }
42 };
43
44template <class _Tp, class _Up = _Tp>
45using __synth_three_way_result = decltype(__synth_three_way(declval<_Tp&>(), declval<_Up&>()));
46
47#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
48
49_LIBCPP_END_NAMESPACE_STD
50
51#endif // _LIBCPP___COMPARE_SYNTH_THREE_WAY_H
lib/libcxx/include/__compare/three_way_comparable.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___COMPARE_THREE_WAY_COMPARABLE_H
10#define _LIBCPP___COMPARE_THREE_WAY_COMPARABLE_H
11
12#include <__compare/common_comparison_category.h>
13#include <__compare/ordering.h>
14#include <__concepts/common_reference_with.h>
15#include <__concepts/equality_comparable.h>
16#include <__concepts/same_as.h>
17#include <__concepts/totally_ordered.h>
18#include <__config>
19#include <type_traits>
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 !defined(_LIBCPP_HAS_NO_CONCEPTS)
28
29template<class _Tp, class _Cat>
30concept __compares_as =
31 same_as<common_comparison_category_t<_Tp, _Cat>, _Cat>;
32
33template<class _Tp, class _Cat = partial_ordering>
34concept three_way_comparable =
35 __weakly_equality_comparable_with<_Tp, _Tp> &&
36 __partially_ordered_with<_Tp, _Tp> &&
37 requires(__make_const_lvalue_ref<_Tp> __a, __make_const_lvalue_ref<_Tp> __b) {
38 { __a <=> __b } -> __compares_as<_Cat>;
39 };
40
41template<class _Tp, class _Up, class _Cat = partial_ordering>
42concept three_way_comparable_with =
43 three_way_comparable<_Tp, _Cat> &&
44 three_way_comparable<_Up, _Cat> &&
45 common_reference_with<__make_const_lvalue_ref<_Tp>, __make_const_lvalue_ref<_Up>> &&
46 three_way_comparable<common_reference_t<__make_const_lvalue_ref<_Tp>, __make_const_lvalue_ref<_Up>>, _Cat> &&
47 __weakly_equality_comparable_with<_Tp, _Up> &&
48 __partially_ordered_with<_Tp, _Up> &&
49 requires(__make_const_lvalue_ref<_Tp> __t, __make_const_lvalue_ref<_Up> __u) {
50 { __t <=> __u } -> __compares_as<_Cat>;
51 { __u <=> __t } -> __compares_as<_Cat>;
52 };
53
54#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
55
56_LIBCPP_END_NAMESPACE_STD
57
58#endif // _LIBCPP___COMPARE_THREE_WAY_COMPARABLE_H
lib/libcxx/include/__compare/weak_order.h created+100
......@@ -0,0 +1,100 @@
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___COMPARE_WEAK_ORDER
10#define _LIBCPP___COMPARE_WEAK_ORDER
11
12#include <__compare/compare_three_way.h>
13#include <__compare/ordering.h>
14#include <__compare/strong_order.h>
15#include <__config>
16#include <__utility/forward.h>
17#include <__utility/priority_tag.h>
18#include <cmath>
19#include <type_traits>
20
21#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
22#pragma GCC system_header
23#endif
24
25_LIBCPP_BEGIN_NAMESPACE_STD
26
27#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
28
29// [cmp.alg]
30namespace __weak_order {
31 struct __fn {
32 template<class _Tp, class _Up>
33 requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
34 _LIBCPP_HIDE_FROM_ABI static constexpr auto
35 __go(_Tp&& __t, _Up&& __u, __priority_tag<3>)
36 noexcept(noexcept(weak_ordering(weak_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))))
37 -> decltype( weak_ordering(weak_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
38 { return weak_ordering(weak_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))); }
39
40 template<class _Tp, class _Up, class _Dp = decay_t<_Tp>>
41 requires is_same_v<_Dp, decay_t<_Up>> && is_floating_point_v<_Dp>
42 _LIBCPP_HIDE_FROM_ABI static constexpr weak_ordering
43 __go(_Tp&& __t, _Up&& __u, __priority_tag<2>) noexcept
44 {
45 partial_ordering __po = (__t <=> __u);
46 if (__po == partial_ordering::less) {
47 return weak_ordering::less;
48 } else if (__po == partial_ordering::equivalent) {
49 return weak_ordering::equivalent;
50 } else if (__po == partial_ordering::greater) {
51 return weak_ordering::greater;
52 } else {
53 // Otherwise, at least one of them is a NaN.
54 bool __t_is_nan = _VSTD::isnan(__t);
55 bool __u_is_nan = _VSTD::isnan(__u);
56 bool __t_is_negative = _VSTD::signbit(__t);
57 bool __u_is_negative = _VSTD::signbit(__u);
58 if (__t_is_nan && __u_is_nan) {
59 return (__u_is_negative <=> __t_is_negative);
60 } else if (__t_is_nan) {
61 return __t_is_negative ? weak_ordering::less : weak_ordering::greater;
62 } else {
63 return __u_is_negative ? weak_ordering::greater : weak_ordering::less;
64 }
65 }
66 }
67
68 template<class _Tp, class _Up>
69 requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
70 _LIBCPP_HIDE_FROM_ABI static constexpr auto
71 __go(_Tp&& __t, _Up&& __u, __priority_tag<1>)
72 noexcept(noexcept(weak_ordering(compare_three_way()(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))))
73 -> decltype( weak_ordering(compare_three_way()(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
74 { return weak_ordering(compare_three_way()(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))); }
75
76 template<class _Tp, class _Up>
77 requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
78 _LIBCPP_HIDE_FROM_ABI static constexpr auto
79 __go(_Tp&& __t, _Up&& __u, __priority_tag<0>)
80 noexcept(noexcept(weak_ordering(_VSTD::strong_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))))
81 -> decltype( weak_ordering(_VSTD::strong_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
82 { return weak_ordering(_VSTD::strong_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))); }
83
84 template<class _Tp, class _Up>
85 _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t, _Up&& __u) const
86 noexcept(noexcept(__go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<3>())))
87 -> decltype( __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<3>()))
88 { return __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<3>()); }
89 };
90} // namespace __weak_order
91
92inline namespace __cpo {
93 inline constexpr auto weak_order = __weak_order::__fn{};
94} // namespace __cpo
95
96#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
97
98_LIBCPP_END_NAMESPACE_STD
99
100#endif // _LIBCPP___COMPARE_WEAK_ORDER
lib/libcxx/include/__concepts/arithmetic.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___CONCEPTS_ARITHMETIC_H
10#define _LIBCPP___CONCEPTS_ARITHMETIC_H
11
12#include <__config>
13#include <type_traits>
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 !defined(_LIBCPP_HAS_NO_CONCEPTS)
22
23// [concepts.arithmetic], arithmetic concepts
24
25template<class _Tp>
26concept integral = is_integral_v<_Tp>;
27
28template<class _Tp>
29concept signed_integral = integral<_Tp> && is_signed_v<_Tp>;
30
31template<class _Tp>
32concept unsigned_integral = integral<_Tp> && !signed_integral<_Tp>;
33
34template<class _Tp>
35concept floating_point = is_floating_point_v<_Tp>;
36
37// Concept helpers for the internal type traits for the fundamental types.
38
39template <class _Tp>
40concept __libcpp_unsigned_integer = __libcpp_is_unsigned_integer<_Tp>::value;
41template <class _Tp>
42concept __libcpp_signed_integer = __libcpp_is_signed_integer<_Tp>::value;
43
44#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
45
46_LIBCPP_END_NAMESPACE_STD
47
48#endif // _LIBCPP___CONCEPTS_ARITHMETIC_H
lib/libcxx/include/__concepts/assignable.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___CONCEPTS_ASSIGNABLE_H
10#define _LIBCPP___CONCEPTS_ASSIGNABLE_H
11
12#include <__concepts/common_reference_with.h>
13#include <__concepts/same_as.h>
14#include <__config>
15#include <__utility/forward.h>
16#include <type_traits>
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 !defined(_LIBCPP_HAS_NO_CONCEPTS)
25
26// [concept.assignable]
27
28template<class _Lhs, class _Rhs>
29concept assignable_from =
30 is_lvalue_reference_v<_Lhs> &&
31 common_reference_with<__make_const_lvalue_ref<_Lhs>, __make_const_lvalue_ref<_Rhs>> &&
32 requires (_Lhs __lhs, _Rhs&& __rhs) {
33 { __lhs = _VSTD::forward<_Rhs>(__rhs) } -> same_as<_Lhs>;
34 };
35
36#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
37
38_LIBCPP_END_NAMESPACE_STD
39
40#endif // _LIBCPP___CONCEPTS_ASSIGNABLE_H
lib/libcxx/include/__concepts/boolean_testable.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___CONCEPTS_BOOLEAN_TESTABLE_H
10#define _LIBCPP___CONCEPTS_BOOLEAN_TESTABLE_H
11
12#include <__concepts/convertible_to.h>
13#include <__config>
14#include <__utility/forward.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 !defined(_LIBCPP_HAS_NO_CONCEPTS)
23
24// [concepts.booleantestable]
25
26template<class _Tp>
27concept __boolean_testable_impl = convertible_to<_Tp, bool>;
28
29template<class _Tp>
30concept __boolean_testable = __boolean_testable_impl<_Tp> && requires(_Tp&& __t) {
31 { !_VSTD::forward<_Tp>(__t) } -> __boolean_testable_impl;
32};
33
34#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
35
36_LIBCPP_END_NAMESPACE_STD
37
38#endif // _LIBCPP___CONCEPTS_BOOLEAN_TESTABLE_H
lib/libcxx/include/__concepts/class_or_enum.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___CONCEPTS_CLASS_OR_ENUM_H
10#define _LIBCPP___CONCEPTS_CLASS_OR_ENUM_H
11
12#include <__config>
13#include <type_traits>
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 !defined(_LIBCPP_HAS_NO_CONCEPTS)
22
23// Whether a type is a class type or enumeration type according to the Core wording.
24
25template<class _Tp>
26concept __class_or_enum = is_class_v<_Tp> || is_union_v<_Tp> || is_enum_v<_Tp>;
27
28// Work around Clang bug https://llvm.org/PR52970
29template<class _Tp>
30concept __workaround_52970 = is_class_v<__uncvref_t<_Tp>> || is_union_v<__uncvref_t<_Tp>>;
31
32#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
33
34_LIBCPP_END_NAMESPACE_STD
35
36#endif // _LIBCPP___CONCEPTS_CLASS_OR_ENUM_H
lib/libcxx/include/__concepts/common_reference_with.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___CONCEPTS_COMMON_REFERENCE_WITH_H
10#define _LIBCPP___CONCEPTS_COMMON_REFERENCE_WITH_H
11
12#include <__concepts/convertible_to.h>
13#include <__concepts/same_as.h>
14#include <__config>
15#include <type_traits>
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 !defined(_LIBCPP_HAS_NO_CONCEPTS)
24
25// [concept.commonref]
26
27template<class _Tp, class _Up>
28concept common_reference_with =
29 same_as<common_reference_t<_Tp, _Up>, common_reference_t<_Up, _Tp>> &&
30 convertible_to<_Tp, common_reference_t<_Tp, _Up>> &&
31 convertible_to<_Up, common_reference_t<_Tp, _Up>>;
32
33#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
34
35_LIBCPP_END_NAMESPACE_STD
36
37#endif // _LIBCPP___CONCEPTS_COMMON_REFERENCE_WITH_H
lib/libcxx/include/__concepts/common_with.h created+47
......@@ -0,0 +1,47 @@
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___CONCEPTS_COMMON_WITH_H
10#define _LIBCPP___CONCEPTS_COMMON_WITH_H
11
12#include <__concepts/common_reference_with.h>
13#include <__concepts/same_as.h>
14#include <__config>
15#include <type_traits>
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 !defined(_LIBCPP_HAS_NO_CONCEPTS)
24
25// [concept.common]
26
27template<class _Tp, class _Up>
28concept common_with =
29 same_as<common_type_t<_Tp, _Up>, common_type_t<_Up, _Tp>> &&
30 requires {
31 static_cast<common_type_t<_Tp, _Up>>(declval<_Tp>());
32 static_cast<common_type_t<_Tp, _Up>>(declval<_Up>());
33 } &&
34 common_reference_with<
35 add_lvalue_reference_t<const _Tp>,
36 add_lvalue_reference_t<const _Up>> &&
37 common_reference_with<
38 add_lvalue_reference_t<common_type_t<_Tp, _Up>>,
39 common_reference_t<
40 add_lvalue_reference_t<const _Tp>,
41 add_lvalue_reference_t<const _Up>>>;
42
43#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
44
45_LIBCPP_END_NAMESPACE_STD
46
47#endif // _LIBCPP___CONCEPTS_COMMON_WITH_H
lib/libcxx/include/__concepts/constructible.h created+56
......@@ -0,0 +1,56 @@
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___CONCEPTS_CONSTRUCTIBLE_H
10#define _LIBCPP___CONCEPTS_CONSTRUCTIBLE_H
11
12#include <__concepts/convertible_to.h>
13#include <__concepts/destructible.h>
14#include <__config>
15#include <type_traits>
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 !defined(_LIBCPP_HAS_NO_CONCEPTS)
24
25// [concept.constructible]
26template<class _Tp, class... _Args>
27concept constructible_from =
28 destructible<_Tp> && is_constructible_v<_Tp, _Args...>;
29
30// [concept.default.init]
31
32template<class _Tp>
33concept __default_initializable = requires { ::new _Tp; };
34
35template<class _Tp>
36concept default_initializable = constructible_from<_Tp> &&
37 requires { _Tp{}; } && __default_initializable<_Tp>;
38
39// [concept.moveconstructible]
40template<class _Tp>
41concept move_constructible =
42 constructible_from<_Tp, _Tp> && convertible_to<_Tp, _Tp>;
43
44// [concept.copyconstructible]
45template<class _Tp>
46concept copy_constructible =
47 move_constructible<_Tp> &&
48 constructible_from<_Tp, _Tp&> && convertible_to<_Tp&, _Tp> &&
49 constructible_from<_Tp, const _Tp&> && convertible_to<const _Tp&, _Tp> &&
50 constructible_from<_Tp, const _Tp> && convertible_to<const _Tp, _Tp>;
51
52#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
53
54_LIBCPP_END_NAMESPACE_STD
55
56#endif // _LIBCPP___CONCEPTS_CONSTRUCTIBLE_H
lib/libcxx/include/__concepts/convertible_to.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___CONCEPTS_CONVERTIBLE_TO_H
10#define _LIBCPP___CONCEPTS_CONVERTIBLE_TO_H
11
12#include <__config>
13#include <__utility/declval.h>
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#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
23
24// [concept.convertible]
25
26template<class _From, class _To>
27concept convertible_to =
28 is_convertible_v<_From, _To> &&
29 requires {
30 static_cast<_To>(declval<_From>());
31 };
32
33#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
34
35_LIBCPP_END_NAMESPACE_STD
36
37#endif // _LIBCPP___CONCEPTS_CONVERTIBLE_TO_H
lib/libcxx/include/__concepts/copyable.h created+39
......@@ -0,0 +1,39 @@
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___CONCEPTS_COPYABLE_H
10#define _LIBCPP___CONCEPTS_COPYABLE_H
11
12#include <__concepts/assignable.h>
13#include <__concepts/constructible.h>
14#include <__concepts/movable.h>
15#include <__config>
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 !defined(_LIBCPP_HAS_NO_CONCEPTS)
24
25// [concepts.object]
26
27template<class _Tp>
28concept copyable =
29 copy_constructible<_Tp> &&
30 movable<_Tp> &&
31 assignable_from<_Tp&, _Tp&> &&
32 assignable_from<_Tp&, const _Tp&> &&
33 assignable_from<_Tp&, const _Tp>;
34
35#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
36
37_LIBCPP_END_NAMESPACE_STD
38
39#endif // _LIBCPP___CONCEPTS_COPYABLE_H
lib/libcxx/include/__concepts/derived_from.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___CONCEPTS_DERIVED_FROM_H
10#define _LIBCPP___CONCEPTS_DERIVED_FROM_H
11
12#include <__config>
13#include <type_traits>
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 !defined(_LIBCPP_HAS_NO_CONCEPTS)
22
23// [concept.derived]
24
25template<class _Dp, class _Bp>
26concept derived_from =
27 is_base_of_v<_Bp, _Dp> &&
28 is_convertible_v<const volatile _Dp*, const volatile _Bp*>;
29
30#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
31
32_LIBCPP_END_NAMESPACE_STD
33
34#endif // _LIBCPP___CONCEPTS_DERIVED_FROM_H
lib/libcxx/include/__concepts/destructible.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___CONCEPTS_DESTRUCTIBLE_H
10#define _LIBCPP___CONCEPTS_DESTRUCTIBLE_H
11
12#include <__config>
13#include <type_traits>
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 !defined(_LIBCPP_HAS_NO_CONCEPTS)
22
23// [concept.destructible]
24
25template<class _Tp>
26concept destructible = is_nothrow_destructible_v<_Tp>;
27
28#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
29
30_LIBCPP_END_NAMESPACE_STD
31
32#endif // _LIBCPP___CONCEPTS_DESTRUCTIBLE_H
lib/libcxx/include/__concepts/different_from.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___CONCEPTS_DIFFERENT_FROM_H
10#define _LIBCPP___CONCEPTS_DIFFERENT_FROM_H
11
12#include <__concepts/same_as.h>
13#include <__config>
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#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
23
24template<class _Tp, class _Up>
25concept __different_from = !same_as<remove_cvref_t<_Tp>, remove_cvref_t<_Up>>;
26
27#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
28
29_LIBCPP_END_NAMESPACE_STD
30
31#endif // _LIBCPP___CONCEPTS_DIFFERENT_FROM_H
lib/libcxx/include/__concepts/equality_comparable.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___CONCEPTS_EQUALITY_COMPARABLE_H
10#define _LIBCPP___CONCEPTS_EQUALITY_COMPARABLE_H
11
12#include <__concepts/boolean_testable.h>
13#include <__concepts/common_reference_with.h>
14#include <__config>
15#include <type_traits>
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 !defined(_LIBCPP_HAS_NO_CONCEPTS)
24
25// [concept.equalitycomparable]
26
27template<class _Tp, class _Up>
28concept __weakly_equality_comparable_with =
29 requires(__make_const_lvalue_ref<_Tp> __t, __make_const_lvalue_ref<_Up> __u) {
30 { __t == __u } -> __boolean_testable;
31 { __t != __u } -> __boolean_testable;
32 { __u == __t } -> __boolean_testable;
33 { __u != __t } -> __boolean_testable;
34 };
35
36template<class _Tp>
37concept equality_comparable = __weakly_equality_comparable_with<_Tp, _Tp>;
38
39template<class _Tp, class _Up>
40concept equality_comparable_with =
41 equality_comparable<_Tp> && equality_comparable<_Up> &&
42 common_reference_with<__make_const_lvalue_ref<_Tp>, __make_const_lvalue_ref<_Up>> &&
43 equality_comparable<
44 common_reference_t<
45 __make_const_lvalue_ref<_Tp>,
46 __make_const_lvalue_ref<_Up>>> &&
47 __weakly_equality_comparable_with<_Tp, _Up>;
48
49#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
50
51_LIBCPP_END_NAMESPACE_STD
52
53#endif // _LIBCPP___CONCEPTS_EQUALITY_COMPARABLE_H
lib/libcxx/include/__concepts/invocable.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___CONCEPTS_INVOCABLE_H
10#define _LIBCPP___CONCEPTS_INVOCABLE_H
11
12#include <__config>
13#include <__functional/invoke.h>
14#include <__utility/forward.h>
15#include <type_traits>
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 !defined(_LIBCPP_HAS_NO_CONCEPTS)
24
25// [concept.invocable]
26
27template<class _Fn, class... _Args>
28concept invocable = requires(_Fn&& __fn, _Args&&... __args) {
29 _VSTD::invoke(_VSTD::forward<_Fn>(__fn), _VSTD::forward<_Args>(__args)...); // not required to be equality preserving
30};
31
32// [concept.regular.invocable]
33
34template<class _Fn, class... _Args>
35concept regular_invocable = invocable<_Fn, _Args...>;
36
37#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
38
39_LIBCPP_END_NAMESPACE_STD
40
41#endif // _LIBCPP___CONCEPTS_INVOCABLE_H
lib/libcxx/include/__concepts/movable.h created+39
......@@ -0,0 +1,39 @@
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___CONCEPTS_MOVABLE_H
10#define _LIBCPP___CONCEPTS_MOVABLE_H
11
12#include <__concepts/assignable.h>
13#include <__concepts/constructible.h>
14#include <__concepts/swappable.h>
15#include <__config>
16#include <type_traits>
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 !defined(_LIBCPP_HAS_NO_CONCEPTS)
25
26// [concepts.object]
27
28template<class _Tp>
29concept movable =
30 is_object_v<_Tp> &&
31 move_constructible<_Tp> &&
32 assignable_from<_Tp&, _Tp> &&
33 swappable<_Tp>;
34
35#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
36
37_LIBCPP_END_NAMESPACE_STD
38
39#endif // _LIBCPP___CONCEPTS_MOVABLE_H
lib/libcxx/include/__concepts/predicate.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___CONCEPTS_PREDICATE_H
10#define _LIBCPP___CONCEPTS_PREDICATE_H
11
12#include <__concepts/boolean_testable.h>
13#include <__concepts/invocable.h>
14#include <__config>
15#include <type_traits>
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 !defined(_LIBCPP_HAS_NO_CONCEPTS)
24
25// [concept.predicate]
26
27template<class _Fn, class... _Args>
28concept predicate =
29 regular_invocable<_Fn, _Args...> && __boolean_testable<invoke_result_t<_Fn, _Args...>>;
30
31#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
32
33_LIBCPP_END_NAMESPACE_STD
34
35#endif // _LIBCPP___CONCEPTS_PREDICATE_H
lib/libcxx/include/__concepts/regular.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___CONCEPTS_REGULAR_H
10#define _LIBCPP___CONCEPTS_REGULAR_H
11
12#include <__concepts/equality_comparable.h>
13#include <__concepts/semiregular.h>
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#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
23
24// [concept.object]
25
26template<class _Tp>
27concept regular = semiregular<_Tp> && equality_comparable<_Tp>;
28
29#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
30
31_LIBCPP_END_NAMESPACE_STD
32
33#endif // _LIBCPP___CONCEPTS_REGULAR_H
lib/libcxx/include/__concepts/relation.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___CONCEPTS_RELATION_H
10#define _LIBCPP___CONCEPTS_RELATION_H
11
12#include <__concepts/predicate.h>
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 !defined(_LIBCPP_HAS_NO_CONCEPTS)
22
23// [concept.relation]
24
25template<class _Rp, class _Tp, class _Up>
26concept relation =
27 predicate<_Rp, _Tp, _Tp> && predicate<_Rp, _Up, _Up> &&
28 predicate<_Rp, _Tp, _Up> && predicate<_Rp, _Up, _Tp>;
29
30// [concept.equiv]
31
32template<class _Rp, class _Tp, class _Up>
33concept equivalence_relation = relation<_Rp, _Tp, _Up>;
34
35// [concept.strictweakorder]
36
37template<class _Rp, class _Tp, class _Up>
38concept strict_weak_order = relation<_Rp, _Tp, _Up>;
39
40#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
41
42_LIBCPP_END_NAMESPACE_STD
43
44#endif // _LIBCPP___CONCEPTS_RELATION_H
lib/libcxx/include/__concepts/same_as.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___CONCEPTS_SAME_AS_H
10#define _LIBCPP___CONCEPTS_SAME_AS_H
11
12#include <__config>
13#include <type_traits>
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 !defined(_LIBCPP_HAS_NO_CONCEPTS)
22
23// [concept.same]
24
25template<class _Tp, class _Up>
26concept __same_as_impl = _IsSame<_Tp, _Up>::value;
27
28template<class _Tp, class _Up>
29concept same_as = __same_as_impl<_Tp, _Up> && __same_as_impl<_Up, _Tp>;
30
31#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
32
33_LIBCPP_END_NAMESPACE_STD
34
35#endif // _LIBCPP___CONCEPTS_SAME_AS_H
lib/libcxx/include/__concepts/semiregular.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___CONCEPTS_SEMIREGULAR_H
10#define _LIBCPP___CONCEPTS_SEMIREGULAR_H
11
12#include <__concepts/constructible.h>
13#include <__concepts/copyable.h>
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#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
23
24// [concept.object]
25
26template<class _Tp>
27concept semiregular = copyable<_Tp> && default_initializable<_Tp>;
28
29#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
30
31_LIBCPP_END_NAMESPACE_STD
32
33#endif // _LIBCPP___CONCEPTS_SEMIREGULAR_H
lib/libcxx/include/__concepts/swappable.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___CONCEPTS_SWAPPABLE_H
10#define _LIBCPP___CONCEPTS_SWAPPABLE_H
11
12#include <__concepts/assignable.h>
13#include <__concepts/class_or_enum.h>
14#include <__concepts/common_reference_with.h>
15#include <__concepts/constructible.h>
16#include <__config>
17#include <__utility/exchange.h>
18#include <__utility/forward.h>
19#include <__utility/move.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 !defined(_LIBCPP_HAS_NO_CONCEPTS)
29
30// [concept.swappable]
31
32namespace ranges {
33namespace __swap {
34
35 template<class _Tp>
36 void swap(_Tp&, _Tp&) = delete;
37
38 template<class _Tp, class _Up>
39 concept __unqualified_swappable_with =
40 (__class_or_enum<remove_cvref_t<_Tp>> || __class_or_enum<remove_cvref_t<_Up>>) &&
41 requires(_Tp&& __t, _Up&& __u) {
42 swap(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u));
43 };
44
45 struct __fn;
46
47 template<class _Tp, class _Up, size_t _Size>
48 concept __swappable_arrays =
49 !__unqualified_swappable_with<_Tp(&)[_Size], _Up(&)[_Size]> &&
50 extent_v<_Tp> == extent_v<_Up> &&
51 requires(_Tp(& __t)[_Size], _Up(& __u)[_Size], const __fn& __swap) {
52 __swap(__t[0], __u[0]);
53 };
54
55 template<class _Tp>
56 concept __exchangeable =
57 !__unqualified_swappable_with<_Tp&, _Tp&> &&
58 move_constructible<_Tp> &&
59 assignable_from<_Tp&, _Tp>;
60
61 struct __fn {
62 // 2.1 `S` is `(void)swap(E1, E2)`* if `E1` or `E2` has class or enumeration type and...
63 // *The name `swap` is used here unqualified.
64 template<class _Tp, class _Up>
65 requires __unqualified_swappable_with<_Tp, _Up>
66 constexpr void operator()(_Tp&& __t, _Up&& __u) const
67 noexcept(noexcept(swap(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
68 {
69 swap(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u));
70 }
71
72 // 2.2 Otherwise, if `E1` and `E2` are lvalues of array types with equal extent and...
73 template<class _Tp, class _Up, size_t _Size>
74 requires __swappable_arrays<_Tp, _Up, _Size>
75 constexpr void operator()(_Tp(& __t)[_Size], _Up(& __u)[_Size]) const
76 noexcept(noexcept((*this)(*__t, *__u)))
77 {
78 // TODO(cjdb): replace with `ranges::swap_ranges`.
79 for (size_t __i = 0; __i < _Size; ++__i) {
80 (*this)(__t[__i], __u[__i]);
81 }
82 }
83
84 // 2.3 Otherwise, if `E1` and `E2` are lvalues of the same type `T` that models...
85 template<__exchangeable _Tp>
86 constexpr void operator()(_Tp& __x, _Tp& __y) const
87 noexcept(is_nothrow_move_constructible_v<_Tp> && is_nothrow_move_assignable_v<_Tp>)
88 {
89 __y = _VSTD::exchange(__x, _VSTD::move(__y));
90 }
91 };
92} // namespace __swap
93
94inline namespace __cpo {
95 inline constexpr auto swap = __swap::__fn{};
96} // namespace __cpo
97} // namespace ranges
98
99template<class _Tp>
100concept swappable = requires(_Tp& __a, _Tp& __b) { ranges::swap(__a, __b); };
101
102template<class _Tp, class _Up>
103concept swappable_with =
104 common_reference_with<_Tp, _Up> &&
105 requires(_Tp&& __t, _Up&& __u) {
106 ranges::swap(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Tp>(__t));
107 ranges::swap(_VSTD::forward<_Up>(__u), _VSTD::forward<_Up>(__u));
108 ranges::swap(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u));
109 ranges::swap(_VSTD::forward<_Up>(__u), _VSTD::forward<_Tp>(__t));
110 };
111
112#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
113
114_LIBCPP_END_NAMESPACE_STD
115
116#endif // _LIBCPP___CONCEPTS_SWAPPABLE_H
lib/libcxx/include/__concepts/totally_ordered.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___CONCEPTS_TOTALLY_ORDERED_H
10#define _LIBCPP___CONCEPTS_TOTALLY_ORDERED_H
11
12#include <__concepts/boolean_testable.h>
13#include <__concepts/equality_comparable.h>
14#include <__config>
15#include <type_traits>
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 !defined(_LIBCPP_HAS_NO_CONCEPTS)
24
25// [concept.totallyordered]
26
27template<class _Tp, class _Up>
28concept __partially_ordered_with =
29 requires(__make_const_lvalue_ref<_Tp> __t, __make_const_lvalue_ref<_Up> __u) {
30 { __t < __u } -> __boolean_testable;
31 { __t > __u } -> __boolean_testable;
32 { __t <= __u } -> __boolean_testable;
33 { __t >= __u } -> __boolean_testable;
34 { __u < __t } -> __boolean_testable;
35 { __u > __t } -> __boolean_testable;
36 { __u <= __t } -> __boolean_testable;
37 { __u >= __t } -> __boolean_testable;
38 };
39
40template<class _Tp>
41concept totally_ordered = equality_comparable<_Tp> && __partially_ordered_with<_Tp, _Tp>;
42
43template<class _Tp, class _Up>
44concept totally_ordered_with =
45 totally_ordered<_Tp> && totally_ordered<_Up> &&
46 equality_comparable_with<_Tp, _Up> &&
47 totally_ordered<
48 common_reference_t<
49 __make_const_lvalue_ref<_Tp>,
50 __make_const_lvalue_ref<_Up>>> &&
51 __partially_ordered_with<_Tp, _Up>;
52
53#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
54
55_LIBCPP_END_NAMESPACE_STD
56
57#endif // _LIBCPP___CONCEPTS_TOTALLY_ORDERED_H
lib/libcxx/include/__config+175-211
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- __config ---------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -10,6 +10,8 @@
1010#ifndef _LIBCPP_CONFIG
1111#define _LIBCPP_CONFIG
1212
13#include <__config_site>
14
1315#if defined(_MSC_VER) && !defined(__clang__)
1416# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1517# define _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
......@@ -22,17 +24,7 @@
2224
2325#ifdef __cplusplus
2426
25#ifdef __GNUC__
26# define _GNUC_VER (__GNUC__ * 100 + __GNUC_MINOR__)
27// The _GNUC_VER_NEW macro better represents the new GCC versioning scheme
28// introduced in GCC 5.0.
29# define _GNUC_VER_NEW (_GNUC_VER * 10 + __GNUC_PATCHLEVEL__)
30#else
31# define _GNUC_VER 0
32# define _GNUC_VER_NEW 0
33#endif
34
35#define _LIBCPP_VERSION 13000
27#define _LIBCPP_VERSION 14000
3628
3729#ifndef _LIBCPP_ABI_VERSION
3830# define _LIBCPP_ABI_VERSION 1
......@@ -82,14 +74,15 @@
8274# define _LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB
8375# define _LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB
8476# define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE
85// Don't use a nullptr_t simulation type in C++03 instead using C++11 nullptr
86// provided under the alternate keyword __nullptr, which changes the mangling
87// of nullptr_t. This option is ABI incompatible with GCC in C++03 mode.
88# define _LIBCPP_ABI_ALWAYS_USE_CXX11_NULLPTR
8977// Define a key function for `bad_function_call` in the library, to centralize
9078// its vtable and typeinfo to libc++ rather than having all other libraries
9179// using that class define their own copies.
9280# define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
81// Override the default return value of exception::what() for
82// bad_function_call::what() with a string that is specific to
83// bad_function_call (see http://wg21.link/LWG2233). This is an ABI break
84// because it changes the vtable layout of bad_function_call.
85# define _LIBCPP_ABI_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE
9386// Enable optimized version of __do_get_(un)signed which avoids redundant copies.
9487# define _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
9588// In C++20 and later, don't derive std::plus from std::binary_function,
......@@ -114,6 +107,17 @@
114107# define _LIBCPP_ABI_ENABLE_UNIQUE_PTR_TRIVIAL_ABI
115108// Enable clang::trivial_abi on std::shared_ptr and std::weak_ptr
116109# define _LIBCPP_ABI_ENABLE_SHARED_PTR_TRIVIAL_ABI
110// std::random_device holds some state when it uses an implementation that gets
111// entropy from a file (see _LIBCPP_USING_DEV_RANDOM). When switching from this
112// implementation to another one on a platform that has already shipped
113// std::random_device, one needs to retain the same object layout to remain ABI
114// compatible. This switch removes these workarounds for platforms that don't care
115// about ABI compatibility.
116# define _LIBCPP_ABI_NO_RANDOM_DEVICE_COMPATIBILITY_LAYOUT
117// Remove basic_string common base
118# define _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON
119// Remove vector base class
120# define _LIBCPP_ABI_DO_NOT_EXPORT_VECTOR_BASE_COMMON
117121#elif _LIBCPP_ABI_VERSION == 1
118122# if !defined(_LIBCPP_OBJECT_FORMAT_COFF)
119123// Enable compiling copies of now inline methods into the dylib to support
......@@ -125,16 +129,38 @@
125129# endif
126130// Feature macros for disabling pre ABI v1 features. All of these options
127131// are deprecated.
128# if defined(__FreeBSD__) || defined(__DragonFly__)
132# if defined(__FreeBSD__)
129133# define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR
130134# endif
131135#endif
132136
137// By default, don't use a nullptr_t emulation type in C++03.
138//
139// This is technically an ABI break from previous releases, however it is
140// very unlikely to impact anyone. If a user is impacted by this break,
141// they can return to using the C++03 nullptr emulation by defining
142// _LIBCPP_ABI_USE_CXX03_NULLPTR_EMULATION.
143//
144// This switch will be removed entirely in favour of never providing a
145// C++03 emulation after one release.
146//
147// IMPORTANT: IF YOU ARE READING THIS AND YOU TURN THIS MACRO ON, PLEASE LEAVE
148// A COMMENT ON https://reviews.llvm.org/D109459 OR YOU WILL BE BROKEN
149// IN THE FUTURE WHEN WE REMOVE THE ABILITY TO USE THE C++03 EMULATION.
150#ifndef _LIBCPP_ABI_USE_CXX03_NULLPTR_EMULATION
151# define _LIBCPP_ABI_ALWAYS_USE_CXX11_NULLPTR
152#endif
153
133154#if defined(_LIBCPP_BUILDING_LIBRARY) || defined(_LIBCPP_ABI_UNSTABLE) || _LIBCPP_ABI_VERSION >= 2
134155// Enable additional explicit instantiations of iostreams components. This
135156// reduces the number of weak definitions generated in programs that use
136157// iostreams by providing a single strong definition in the shared library.
137158# define _LIBCPP_ABI_ENABLE_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1
159
160// Define a key function for `bad_function_call` in the library, to centralize
161// its vtable and typeinfo to libc++ rather than having all other libraries
162// using that class define their own copies.
163# define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
138164#endif
139165
140166#define _LIBCPP_CONCAT1(_LIBCPP_X,_LIBCPP_Y) _LIBCPP_X##_LIBCPP_Y
......@@ -235,6 +261,10 @@
235261# endif // defined(__GLIBC_PREREQ)
236262#endif // defined(__linux__)
237263
264#if defined(__MVS__)
265# include <features.h> // for __NATIVE_ASCII_F
266#endif
267
238268#ifdef __LITTLE_ENDIAN__
239269# if __LITTLE_ENDIAN__
240270# define _LIBCPP_LITTLE_ENDIAN
......@@ -263,9 +293,6 @@
263293# else // _BYTE_ORDER == _LITTLE_ENDIAN
264294# define _LIBCPP_BIG_ENDIAN
265295# endif // _BYTE_ORDER == _LITTLE_ENDIAN
266# ifndef __LONG_LONG_SUPPORTED
267# define _LIBCPP_HAS_NO_LONG_LONG
268# endif // __LONG_LONG_SUPPORTED
269296#endif // __FreeBSD__
270297
271298#if defined(__NetBSD__) || defined(__OpenBSD__)
......@@ -316,18 +343,56 @@
316343# endif
317344#endif // __sun__
318345
319#if defined(__OpenBSD__) || defined(__CloudABI__)
320 // Certain architectures provide arc4random(). Prefer using
321 // arc4random() over /dev/{u,}random to make it possible to obtain
322 // random data even when using sandboxing mechanisms such as chroots,
323 // Capsicum, etc.
346#if defined(_AIX) && !defined(__64BIT__)
347 // The size of wchar is 2 byte on 32-bit mode on AIX.
348# define _LIBCPP_SHORT_WCHAR 1
349#endif
350
351// Libc++ supports various implementations of std::random_device.
352//
353// _LIBCPP_USING_DEV_RANDOM
354// Read entropy from the given file, by default `/dev/urandom`.
355// If a token is provided, it is assumed to be the path to a file
356// to read entropy from. This is the default behavior if nothing
357// else is specified. This implementation requires storing state
358// inside `std::random_device`.
359//
360// _LIBCPP_USING_ARC4_RANDOM
361// Use arc4random(). This allows obtaining random data even when
362// using sandboxing mechanisms. On some platforms like Apple, this
363// is the recommended source of entropy for user-space programs.
364// When this option is used, the token passed to `std::random_device`'s
365// constructor *must* be "/dev/urandom" -- anything else is an error.
366//
367// _LIBCPP_USING_GETENTROPY
368// Use getentropy().
369// When this option is used, the token passed to `std::random_device`'s
370// constructor *must* be "/dev/urandom" -- anything else is an error.
371//
372// _LIBCPP_USING_FUCHSIA_CPRNG
373// Use Fuchsia's zx_cprng_draw() system call, which is specified to
374// deliver high-quality entropy and cannot fail.
375// When this option is used, the token passed to `std::random_device`'s
376// constructor *must* be "/dev/urandom" -- anything else is an error.
377//
378// _LIBCPP_USING_NACL_RANDOM
379// NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access,
380// including accesses to the special files under `/dev`. This implementation
381// uses the NaCL syscall `nacl_secure_random_init()` to get entropy.
382// When this option is used, the token passed to `std::random_device`'s
383// constructor *must* be "/dev/urandom" -- anything else is an error.
384//
385// _LIBCPP_USING_WIN32_RANDOM
386// Use rand_s(), for use on Windows.
387// When this option is used, the token passed to `std::random_device`'s
388// constructor *must* be "/dev/urandom" -- anything else is an error.
389#if defined(__OpenBSD__) || defined(__APPLE__)
324390# define _LIBCPP_USING_ARC4_RANDOM
325#elif defined(__Fuchsia__) || defined(__wasi__)
391#elif defined(__wasi__)
326392# define _LIBCPP_USING_GETENTROPY
393#elif defined(__Fuchsia__)
394# define _LIBCPP_USING_FUCHSIA_CPRNG
327395#elif defined(__native_client__)
328 // NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access,
329 // including accesses to the special files under /dev. C++11's
330 // std::random_device is instead exposed through a NaCl syscall.
331396# define _LIBCPP_USING_NACL_RANDOM
332397#elif defined(_LIBCPP_WIN32API)
333398# define _LIBCPP_USING_WIN32_RANDOM
......@@ -380,7 +445,7 @@
380445# if __ANDROID_API__ >= 29
381446# define _LIBCPP_HAS_TIMESPEC_GET
382447# endif
383# elif defined(__Fuchsia__) || defined(__wasi__) || defined(__NetBSD__) || defined(__DragonFly__)
448# elif defined(__Fuchsia__) || defined(__wasi__) || defined(__NetBSD__)
384449# define _LIBCPP_HAS_ALIGNED_ALLOC
385450# define _LIBCPP_HAS_QUICK_EXIT
386451# define _LIBCPP_HAS_TIMESPEC_GET
......@@ -490,14 +555,6 @@ typedef __char32_t char32_t;
490555# define _LIBCPP_HAS_BLOCKS_RUNTIME
491556#endif
492557
493#if !(__has_feature(cxx_relaxed_constexpr))
494#define _LIBCPP_HAS_NO_CXX14_CONSTEXPR
495#endif
496
497#if !(__has_feature(cxx_variable_templates))
498#define _LIBCPP_HAS_NO_VARIABLE_TEMPLATES
499#endif
500
501558#if !(__has_feature(cxx_noexcept))
502559#define _LIBCPP_HAS_NO_NOEXCEPT
503560#endif
......@@ -511,26 +568,8 @@ typedef __char32_t char32_t;
511568#define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow")))
512569#endif
513570
514#if __has_builtin(__builtin_launder)
515#define _LIBCPP_COMPILER_HAS_BUILTIN_LAUNDER
516#endif
517
518#if __has_builtin(__builtin_constant_p)
519#define _LIBCPP_COMPILER_HAS_BUILTIN_CONSTANT_P
520#endif
521
522#if !__is_identifier(__has_unique_object_representations)
523#define _LIBCPP_HAS_UNIQUE_OBJECT_REPRESENTATIONS
524#endif
525
526571#define _LIBCPP_ALWAYS_INLINE __attribute__ ((__always_inline__))
527572
528// Literal operators ""d and ""y are supported starting with LLVM Clang 8 and AppleClang 10.0.1
529#if (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER < 800) || \
530 (defined(_LIBCPP_APPLE_CLANG_VER) && _LIBCPP_APPLE_CLANG_VER < 1001)
531#define _LIBCPP_HAS_NO_CXX20_CHRONO_LITERALS
532#endif
533
534573#define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
535574
536575#elif defined(_LIBCPP_COMPILER_GCC)
......@@ -544,26 +583,10 @@ typedef __char32_t char32_t;
544583# define _LIBCPP_NO_EXCEPTIONS
545584#endif
546585
547// Determine if GCC supports relaxed constexpr
548#if !defined(__cpp_constexpr) || __cpp_constexpr < 201304L
549#define _LIBCPP_HAS_NO_CXX14_CONSTEXPR
550#endif
551
552// GCC 5 supports variable templates
553#if !defined(__cpp_variable_templates) || __cpp_variable_templates < 201304L
554#define _LIBCPP_HAS_NO_VARIABLE_TEMPLATES
555#endif
556
557586#if !defined(__SANITIZE_ADDRESS__)
558587#define _LIBCPP_HAS_NO_ASAN
559588#endif
560589
561#if _GNUC_VER >= 700
562#define _LIBCPP_COMPILER_HAS_BUILTIN_LAUNDER
563#define _LIBCPP_COMPILER_HAS_BUILTIN_CONSTANT_P
564#define _LIBCPP_HAS_UNIQUE_OBJECT_REPRESENTATIONS
565#endif
566
567590#define _LIBCPP_ALWAYS_INLINE __attribute__ ((__always_inline__))
568591
569592#define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
......@@ -578,8 +601,6 @@ typedef __char32_t char32_t;
578601#error "MSVC versions prior to Visual Studio 2015 are not supported"
579602#endif
580603
581#define _LIBCPP_HAS_NO_CXX14_CONSTEXPR
582#define _LIBCPP_HAS_NO_VARIABLE_TEMPLATES
583604#define __alignof__ __alignof
584605#define _LIBCPP_NORETURN __declspec(noreturn)
585606#define _ALIGNAS(x) __declspec(align(x))
......@@ -603,7 +624,6 @@ typedef __char32_t char32_t;
603624#define _LIBCPP_NORETURN __attribute__((noreturn))
604625
605626#define _LIBCPP_HAS_NO_UNICODE_CHARS
606#define _LIBCPP_HAS_NO_VARIABLE_TEMPLATES
607627
608628#if defined(_AIX)
609629#define __MULTILOCALE_API
......@@ -803,10 +823,10 @@ typedef __char32_t char32_t;
803823// Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect.
804824#define _LIBCPP_BEGIN_NAMESPACE_STD namespace std { inline namespace _LIBCPP_ABI_NAMESPACE {
805825#define _LIBCPP_END_NAMESPACE_STD } }
806#define _VSTD std::_LIBCPP_ABI_NAMESPACE
826#define _VSTD std
807827_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD
808828
809#if _LIBCPP_STD_VER >= 17
829#if _LIBCPP_STD_VER > 14
810830#define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM \
811831 _LIBCPP_BEGIN_NAMESPACE_STD inline namespace __fs { namespace filesystem {
812832#else
......@@ -834,7 +854,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD
834854#ifdef _LIBCPP_HAS_NO_UNICODE_CHARS
835855typedef unsigned short char16_t;
836856typedef unsigned int char32_t;
837#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
857#endif
838858
839859#ifndef __SIZEOF_INT128__
840860#define _LIBCPP_HAS_NO_INT128
......@@ -857,26 +877,10 @@ typedef unsigned int char32_t;
857877# define _LIBCPP_CONSTEVAL consteval
858878#endif
859879
860#if !defined(__cpp_concepts) || __cpp_concepts < 201907L
880#if _LIBCPP_STD_VER <= 17 || !defined(__cpp_concepts) || __cpp_concepts < 201907L
861881#define _LIBCPP_HAS_NO_CONCEPTS
862882#endif
863883
864#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_HAS_NO_CONCEPTS)
865#define _LIBCPP_HAS_NO_RANGES
866#endif
867
868#ifdef _LIBCPP_CXX03_LANG
869# define _LIBCPP_DEFAULT {}
870#else
871# define _LIBCPP_DEFAULT = default;
872#endif
873
874#ifdef _LIBCPP_CXX03_LANG
875# define _LIBCPP_EQUAL_DELETE
876#else
877# define _LIBCPP_EQUAL_DELETE = delete
878#endif
879
880884#ifdef __GNUC__
881885# define _LIBCPP_NOALIAS __attribute__((__malloc__))
882886#else
......@@ -905,16 +909,35 @@ typedef unsigned int char32_t;
905909// _LIBCPP_DEBUG potential values:
906910// - undefined: No assertions. This is the default.
907911// - 0: Basic assertions
908// - 1: Basic assertions + iterator validity checks.
909#if !defined(_LIBCPP_DEBUG)
910# define _LIBCPP_DEBUG_LEVEL 0
911#elif _LIBCPP_DEBUG == 0
912# define _LIBCPP_DEBUG_LEVEL 1
913#elif _LIBCPP_DEBUG == 1
914# define _LIBCPP_DEBUG_LEVEL 2
915#else
916# error Supported values for _LIBCPP_DEBUG are 0 and 1
917#endif
912// - 1: Basic assertions + iterator validity checks + unspecified behavior randomization.
913# if !defined(_LIBCPP_DEBUG)
914# define _LIBCPP_DEBUG_LEVEL 0
915# elif _LIBCPP_DEBUG == 0
916# define _LIBCPP_DEBUG_LEVEL 1
917# elif _LIBCPP_DEBUG == 1
918# define _LIBCPP_DEBUG_LEVEL 2
919# else
920# error Supported values for _LIBCPP_DEBUG are 0 and 1
921# endif
922
923# if _LIBCPP_DEBUG_LEVEL >= 2 && !defined(_LIBCPP_CXX03_LANG)
924# define _LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY
925# endif
926
927# if defined(_LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY)
928# if defined(_LIBCPP_CXX03_LANG)
929# error Support for unspecified stability is only for C++11 and higher
930# endif
931# define _LIBCPP_DEBUG_RANDOMIZE_RANGE(__first, __last) \
932 do { \
933 if (!__builtin_is_constant_evaluated()) \
934 _VSTD::shuffle(__first, __last, __libcpp_debug_randomizer()); \
935 } while (false)
936# else
937# define _LIBCPP_DEBUG_RANDOMIZE_RANGE(__first, __last) \
938 do { \
939 } while (false)
940# endif
918941
919942// Libc++ allows disabling extern template instantiation declarations by
920943// means of users defining _LIBCPP_DISABLE_EXTERN_TEMPLATE.
......@@ -938,11 +961,11 @@ typedef unsigned int char32_t;
938961#endif
939962
940963#if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || \
941 defined(__sun__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__CloudABI__)
964 defined(__sun__) || defined(__NetBSD__)
942965#define _LIBCPP_LOCALE__L_EXTENSIONS 1
943966#endif
944967
945#if defined(__FreeBSD__) || defined(__DragonFly__)
968#ifdef __FreeBSD__
946969#define _DECLARE_C99_LDBL_MATH 1
947970#endif
948971
......@@ -958,23 +981,16 @@ typedef unsigned int char32_t;
958981# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
959982#endif
960983
961#if defined(__APPLE__)
962# if !defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && \
963 defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)
964# define __MAC_OS_X_VERSION_MIN_REQUIRED __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
965# endif
966#endif // defined(__APPLE__)
967
968984#if defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) || \
969985 (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606)
970986# define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
971987#endif
972988
973#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__)
989#if defined(__APPLE__) || defined(__FreeBSD__)
974990#define _LIBCPP_HAS_DEFAULTRUNELOCALE
975991#endif
976992
977#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__) || defined(__sun__)
993#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__sun__)
978994#define _LIBCPP_WCTYPE_IS_MASK
979995#endif
980996
......@@ -1047,64 +1063,50 @@ typedef unsigned int char32_t;
10471063# define _LIBCPP_EXPLICIT_AFTER_CXX11 explicit
10481064#endif
10491065
1050#if _LIBCPP_STD_VER > 11 && !defined(_LIBCPP_HAS_NO_CXX14_CONSTEXPR)
1066#if _LIBCPP_STD_VER > 11
10511067# define _LIBCPP_CONSTEXPR_AFTER_CXX11 constexpr
10521068#else
10531069# define _LIBCPP_CONSTEXPR_AFTER_CXX11
10541070#endif
10551071
1056#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_CXX14_CONSTEXPR)
1072#if _LIBCPP_STD_VER > 14
10571073# define _LIBCPP_CONSTEXPR_AFTER_CXX14 constexpr
10581074#else
10591075# define _LIBCPP_CONSTEXPR_AFTER_CXX14
10601076#endif
10611077
1062#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX14_CONSTEXPR)
1078#if _LIBCPP_STD_VER > 17
10631079# define _LIBCPP_CONSTEXPR_AFTER_CXX17 constexpr
10641080#else
10651081# define _LIBCPP_CONSTEXPR_AFTER_CXX17
10661082#endif
10671083
1068// The _LIBCPP_NODISCARD_ATTRIBUTE should only be used to define other
1069// NODISCARD macros to the correct attribute.
10701084#if __has_cpp_attribute(nodiscard) || defined(_LIBCPP_COMPILER_MSVC)
1071# define _LIBCPP_NODISCARD_ATTRIBUTE [[nodiscard]]
1085# define _LIBCPP_NODISCARD [[nodiscard]]
10721086#elif defined(_LIBCPP_COMPILER_CLANG_BASED) && !defined(_LIBCPP_CXX03_LANG)
1073# define _LIBCPP_NODISCARD_ATTRIBUTE [[clang::warn_unused_result]]
1087# define _LIBCPP_NODISCARD [[clang::warn_unused_result]]
10741088#else
10751089// We can't use GCC's [[gnu::warn_unused_result]] and
10761090// __attribute__((warn_unused_result)), because GCC does not silence them via
10771091// (void) cast.
1078# define _LIBCPP_NODISCARD_ATTRIBUTE
1092# define _LIBCPP_NODISCARD
10791093#endif
10801094
10811095// _LIBCPP_NODISCARD_EXT may be used to apply [[nodiscard]] to entities not
10821096// specified as such as an extension.
10831097#if defined(_LIBCPP_ENABLE_NODISCARD) && !defined(_LIBCPP_DISABLE_NODISCARD_EXT)
1084# define _LIBCPP_NODISCARD_EXT _LIBCPP_NODISCARD_ATTRIBUTE
1098# define _LIBCPP_NODISCARD_EXT _LIBCPP_NODISCARD
10851099#else
10861100# define _LIBCPP_NODISCARD_EXT
10871101#endif
10881102
10891103#if !defined(_LIBCPP_DISABLE_NODISCARD_AFTER_CXX17) && \
10901104 (_LIBCPP_STD_VER > 17 || defined(_LIBCPP_ENABLE_NODISCARD))
1091# define _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_NODISCARD_ATTRIBUTE
1105# define _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_NODISCARD
10921106#else
10931107# define _LIBCPP_NODISCARD_AFTER_CXX17
10941108#endif
10951109
1096#if _LIBCPP_STD_VER > 14 && defined(__cpp_inline_variables) && (__cpp_inline_variables >= 201606L)
1097# define _LIBCPP_INLINE_VAR inline
1098#else
1099# define _LIBCPP_INLINE_VAR
1100#endif
1101
1102#if defined(_LIBCPP_DEBUG) || defined(_LIBCPP_HAS_NO_CXX14_CONSTEXPR)
1103# define _LIBCPP_CONSTEXPR_IF_NODEBUG
1104#else
1105# define _LIBCPP_CONSTEXPR_IF_NODEBUG constexpr
1106#endif
1107
11081110#if __has_attribute(no_destroy)
11091111# define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__))
11101112#else
......@@ -1138,16 +1140,13 @@ extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
11381140 defined(__wasi__) || \
11391141 defined(__NetBSD__) || \
11401142 defined(__OpenBSD__) || \
1141 defined(__DragonFly__) || \
11421143 defined(__NuttX__) || \
11431144 defined(__linux__) || \
11441145 defined(__GNU__) || \
11451146 defined(__APPLE__) || \
1146 defined(__CloudABI__) || \
11471147 defined(__sun__) || \
11481148 defined(__MVS__) || \
1149 defined(_AIX) || \
1150 (defined(__MINGW32__) && __has_include(<pthread.h>))
1149 defined(_AIX)
11511150# define _LIBCPP_HAS_THREAD_API_PTHREAD
11521151# elif defined(__Fuchsia__)
11531152 // TODO(44575): Switch to C11 thread API when possible.
......@@ -1217,21 +1216,6 @@ extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
12171216# define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION
12181217#endif
12191218
1220// Systems that use capability-based security (FreeBSD with Capsicum,
1221// Nuxi CloudABI) may only provide local filesystem access (using *at()).
1222// Functions like open(), rename(), unlink() and stat() should not be
1223// used, as they attempt to access the global filesystem namespace.
1224#ifdef __CloudABI__
1225#define _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
1226#endif
1227
1228// CloudABI is intended for running networked services. Processes do not
1229// have standard input and output channels.
1230#ifdef __CloudABI__
1231#define _LIBCPP_HAS_NO_STDIN
1232#define _LIBCPP_HAS_NO_STDOUT
1233#endif
1234
12351219// Some systems do not provide gets() in their C library, for security reasons.
12361220#if defined(_LIBCPP_MSVCRT) || \
12371221 (defined(__FreeBSD_version) && __FreeBSD_version >= 1300043) || \
......@@ -1239,28 +1223,21 @@ extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
12391223# define _LIBCPP_C_HAS_NO_GETS
12401224#endif
12411225
1242#if defined(__BIONIC__) || defined(__CloudABI__) || defined(__NuttX__) || \
1243 defined(__Fuchsia__) || defined(__wasi__) || defined(_LIBCPP_HAS_MUSL_LIBC) || \
1244 defined(__MVS__) || defined(__OpenBSD__)
1226#if defined(__BIONIC__) || defined(__NuttX__) || \
1227 defined(__Fuchsia__) || defined(__wasi__) || \
1228 defined(_LIBCPP_HAS_MUSL_LIBC) || defined(__OpenBSD__)
12451229#define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
12461230#endif
12471231
1248// Thread-unsafe functions such as strtok() and localtime()
1249// are not available.
1250#ifdef __CloudABI__
1251#define _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS
1252#endif
1253
12541232#if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic)
12551233# define _LIBCPP_HAS_C_ATOMIC_IMP
12561234#elif defined(_LIBCPP_COMPILER_GCC)
12571235# define _LIBCPP_HAS_GCC_ATOMIC_IMP
12581236#endif
12591237
1260#if (!defined(_LIBCPP_HAS_C_ATOMIC_IMP) && \
1261 !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) && \
1262 !defined(_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP)) \
1263 || defined(_LIBCPP_HAS_NO_THREADS)
1238#if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && \
1239 !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) && \
1240 !defined(_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP)
12641241# define _LIBCPP_HAS_NO_ATOMIC_HEADER
12651242#else
12661243# ifndef _LIBCPP_ATOMIC_FLAG_TYPE
......@@ -1279,8 +1256,9 @@ extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
12791256# if defined(__clang__) && __has_attribute(acquire_capability)
12801257// Work around the attribute handling in clang. When both __declspec and
12811258// __attribute__ are present, the processing goes awry preventing the definition
1282// of the types.
1283# if !defined(_LIBCPP_OBJECT_FORMAT_COFF)
1259// of the types. In MinGW mode, __declspec evaluates to __attribute__, and thus
1260// combining the two does work.
1261# if !defined(_MSC_VER)
12841262# define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
12851263# endif
12861264# endif
......@@ -1298,14 +1276,6 @@ extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
12981276# define _LIBCPP_SAFE_STATIC
12991277#endif
13001278
1301#if !__has_builtin(__builtin_addressof) && _GNUC_VER < 700
1302#define _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF
1303#endif
1304
1305#if !__has_builtin(__builtin_is_constant_evaluated) && _GNUC_VER < 900
1306#define _LIBCPP_HAS_NO_BUILTIN_IS_CONSTANT_EVALUATED
1307#endif
1308
13091279#if __has_attribute(diagnose_if) && !defined(_LIBCPP_DISABLE_ADDITIONAL_DIAGNOSTICS)
13101280# define _LIBCPP_DIAGNOSE_WARNING(...) \
13111281 __attribute__((diagnose_if(__VA_ARGS__, "warning")))
......@@ -1321,7 +1291,7 @@ extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
13211291# define _LIBCPP_FALLTHROUGH() [[fallthrough]]
13221292#elif __has_cpp_attribute(clang::fallthrough)
13231293# define _LIBCPP_FALLTHROUGH() [[clang::fallthrough]]
1324#elif __has_attribute(fallthrough) || _GNUC_VER >= 700
1294#elif __has_attribute(__fallthrough__)
13251295# define _LIBCPP_FALLTHROUGH() __attribute__((__fallthrough__))
13261296#else
13271297# define _LIBCPP_FALLTHROUGH() ((void)0)
......@@ -1333,12 +1303,6 @@ extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
13331303#define _LIBCPP_NODEBUG
13341304#endif
13351305
1336#if __has_attribute(__nodebug__) && (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER >= 900)
1337# define _LIBCPP_NODEBUG_TYPE __attribute__((nodebug))
1338#else
1339# define _LIBCPP_NODEBUG_TYPE
1340#endif
1341
13421306#if __has_attribute(__standalone_debug__)
13431307#define _LIBCPP_STANDALONE_DEBUG __attribute__((__standalone_debug__))
13441308#else
......@@ -1351,6 +1315,16 @@ extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
13511315#define _LIBCPP_PREFERRED_NAME(x)
13521316#endif
13531317
1318// We often repeat things just for handling wide characters in the library.
1319// When wide characters are disabled, it can be useful to have a quick way of
1320// disabling it without having to resort to #if-#endif, which has a larger
1321// impact on readability.
1322#if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
1323# define _LIBCPP_IF_WIDE_CHARACTERS(...)
1324#else
1325# define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__
1326#endif
1327
13541328#if defined(_LIBCPP_ABI_MICROSOFT) && \
13551329 (defined(_LIBCPP_COMPILER_MSVC) || __has_declspec_attribute(empty_bases))
13561330# define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases)
......@@ -1373,20 +1347,8 @@ extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
13731347#define _LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS
13741348#endif // _LIBCPP_ENABLE_CXX20_REMOVED_FEATURES
13751349
1376#if !defined(__cpp_deduction_guides) || __cpp_deduction_guides < 201611
1377#define _LIBCPP_HAS_NO_DEDUCTION_GUIDES
1378#endif
1379
1380#if !__has_keyword(__is_aggregate) && (_GNUC_VER_NEW < 7001)
1381#define _LIBCPP_HAS_NO_IS_AGGREGATE
1382#endif
1383
1384#if !defined(__cpp_coroutines) || __cpp_coroutines < 201703L
1385#define _LIBCPP_HAS_NO_COROUTINES
1386#endif
1387
1388#if !defined(__cpp_impl_three_way_comparison) || __cpp_impl_three_way_comparison < 201907L
1389#define _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
1350#if !defined(__cpp_impl_coroutine) || __cpp_impl_coroutine < 201902L
1351#define _LIBCPP_HAS_NO_CXX20_COROUTINES
13901352#endif
13911353
13921354#if defined(_LIBCPP_COMPILER_IBM)
......@@ -1440,12 +1402,6 @@ extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
14401402# define _LIBCPP_FOPEN_CLOEXEC_MODE
14411403#endif
14421404
1443#ifdef _LIBCPP_COMPILER_HAS_BUILTIN_CONSTANT_P
1444#define _LIBCPP_BUILTIN_CONSTANT_P(x) __builtin_constant_p(x)
1445#else
1446#define _LIBCPP_BUILTIN_CONSTANT_P(x) false
1447#endif
1448
14491405// Support for _FILE_OFFSET_BITS=64 landed gradually in Android, so the full set
14501406// of functions used in cstdio may not be available for low API levels when
14511407// using 64-bit file offsets on LP32.
......@@ -1454,16 +1410,24 @@ extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
14541410#endif
14551411
14561412#if __has_attribute(init_priority)
1457# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(101)))
1413 // TODO: Remove this once we drop support for building libc++ with old Clangs
1414# if (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER < 1200) || \
1415 (defined(__apple_build_version__) && __apple_build_version__ < 13000000)
1416# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(101)))
1417# else
1418# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(100)))
1419# endif
14581420#else
14591421# define _LIBCPP_INIT_PRIORITY_MAX
14601422#endif
14611423
14621424#if defined(__GNUC__) || defined(__clang__)
1463#define _LIBCPP_FORMAT_PRINTF(a, b) \
1464 __attribute__((__format__(__printf__, a, b)))
1425 // The attribute uses 1-based indices for ordinary and static member functions.
1426 // The attribute uses 2-based indices for non-static member functions.
1427# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) \
1428 __attribute__((__format__(archetype, format_string_index, first_format_arg_index)))
14651429#else
1466#define _LIBCPP_FORMAT_PRINTF(a, b)
1430# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */
14671431#endif
14681432
14691433#endif // __cplusplus
lib/libcxx/include/__coroutine/coroutine_handle.h created+202
......@@ -0,0 +1,202 @@
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___COROUTINE_COROUTINE_HANDLE_H
10#define _LIBCPP___COROUTINE_COROUTINE_HANDLE_H
11
12#include <__config>
13#include <__debug>
14#include <__functional/hash.h>
15#include <__memory/addressof.h>
16#include <compare>
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 && !defined(_LIBCPP_HAS_NO_CXX20_COROUTINES)
24
25_LIBCPP_BEGIN_NAMESPACE_STD
26
27// [coroutine.handle]
28template <class _Promise = void>
29struct _LIBCPP_TEMPLATE_VIS coroutine_handle;
30
31template <>
32struct _LIBCPP_TEMPLATE_VIS coroutine_handle<void> {
33public:
34 // [coroutine.handle.con], construct/reset
35 _LIBCPP_HIDE_FROM_ABI
36 constexpr coroutine_handle() noexcept = default;
37
38 _LIBCPP_HIDE_FROM_ABI
39 constexpr coroutine_handle(nullptr_t) noexcept {}
40
41 _LIBCPP_HIDE_FROM_ABI
42 coroutine_handle& operator=(nullptr_t) noexcept {
43 __handle_ = nullptr;
44 return *this;
45 }
46
47 // [coroutine.handle.export.import], export/import
48 _LIBCPP_HIDE_FROM_ABI
49 constexpr void* address() const noexcept { return __handle_; }
50
51 _LIBCPP_HIDE_FROM_ABI
52 static constexpr coroutine_handle from_address(void* __addr) noexcept {
53 coroutine_handle __tmp;
54 __tmp.__handle_ = __addr;
55 return __tmp;
56 }
57
58 // [coroutine.handle.observers], observers
59 _LIBCPP_HIDE_FROM_ABI
60 constexpr explicit operator bool() const noexcept {
61 return __handle_ != nullptr;
62 }
63
64 _LIBCPP_HIDE_FROM_ABI
65 bool done() const {
66 _LIBCPP_ASSERT(__is_suspended(), "done() can be called only on suspended coroutines");
67 return __builtin_coro_done(__handle_);
68 }
69
70 // [coroutine.handle.resumption], resumption
71 _LIBCPP_HIDE_FROM_ABI
72 void operator()() const { resume(); }
73
74 _LIBCPP_HIDE_FROM_ABI
75 void resume() const {
76 _LIBCPP_ASSERT(__is_suspended(), "resume() can be called only on suspended coroutines");
77 _LIBCPP_ASSERT(!done(), "resume() has undefined behavior when the coroutine is done");
78 __builtin_coro_resume(__handle_);
79 }
80
81 _LIBCPP_HIDE_FROM_ABI
82 void destroy() const {
83 _LIBCPP_ASSERT(__is_suspended(), "destroy() can be called only on suspended coroutines");
84 __builtin_coro_destroy(__handle_);
85 }
86
87private:
88 bool __is_suspended() const {
89 // FIXME actually implement a check for if the coro is suspended.
90 return __handle_ != nullptr;
91 }
92
93 void* __handle_ = nullptr;
94};
95
96// [coroutine.handle.compare]
97inline _LIBCPP_HIDE_FROM_ABI
98constexpr bool operator==(coroutine_handle<> __x, coroutine_handle<> __y) noexcept {
99 return __x.address() == __y.address();
100}
101inline _LIBCPP_HIDE_FROM_ABI
102constexpr strong_ordering operator<=>(coroutine_handle<> __x, coroutine_handle<> __y) noexcept {
103 return compare_three_way()(__x.address(), __y.address());
104}
105
106template <class _Promise>
107struct _LIBCPP_TEMPLATE_VIS coroutine_handle {
108public:
109 // [coroutine.handle.con], construct/reset
110 _LIBCPP_HIDE_FROM_ABI
111 constexpr coroutine_handle() noexcept = default;
112
113 _LIBCPP_HIDE_FROM_ABI
114 constexpr coroutine_handle(nullptr_t) noexcept {}
115
116 _LIBCPP_HIDE_FROM_ABI
117 static coroutine_handle from_promise(_Promise& __promise) {
118 using _RawPromise = typename remove_cv<_Promise>::type;
119 coroutine_handle __tmp;
120 __tmp.__handle_ =
121 __builtin_coro_promise(_VSTD::addressof(const_cast<_RawPromise&>(__promise)), alignof(_Promise), true);
122 return __tmp;
123 }
124
125 _LIBCPP_HIDE_FROM_ABI
126 coroutine_handle& operator=(nullptr_t) noexcept {
127 __handle_ = nullptr;
128 return *this;
129 }
130
131 // [coroutine.handle.export.import], export/import
132 _LIBCPP_HIDE_FROM_ABI
133 constexpr void* address() const noexcept { return __handle_; }
134
135 _LIBCPP_HIDE_FROM_ABI
136 static constexpr coroutine_handle from_address(void* __addr) noexcept {
137 coroutine_handle __tmp;
138 __tmp.__handle_ = __addr;
139 return __tmp;
140 }
141
142 // [coroutine.handle.conv], conversion
143 _LIBCPP_HIDE_FROM_ABI
144 constexpr operator coroutine_handle<>() const noexcept {
145 return coroutine_handle<>::from_address(address());
146 }
147
148 // [coroutine.handle.observers], observers
149 _LIBCPP_HIDE_FROM_ABI
150 constexpr explicit operator bool() const noexcept {
151 return __handle_ != nullptr;
152 }
153
154 _LIBCPP_HIDE_FROM_ABI
155 bool done() const {
156 _LIBCPP_ASSERT(__is_suspended(), "done() can be called only on suspended coroutines");
157 return __builtin_coro_done(__handle_);
158 }
159
160 // [coroutine.handle.resumption], resumption
161 _LIBCPP_HIDE_FROM_ABI
162 void operator()() const { resume(); }
163
164 _LIBCPP_HIDE_FROM_ABI
165 void resume() const {
166 _LIBCPP_ASSERT(__is_suspended(), "resume() can be called only on suspended coroutines");
167 _LIBCPP_ASSERT(!done(), "resume() has undefined behavior when the coroutine is done");
168 __builtin_coro_resume(__handle_);
169 }
170
171 _LIBCPP_HIDE_FROM_ABI
172 void destroy() const {
173 _LIBCPP_ASSERT(__is_suspended(), "destroy() can be called only on suspended coroutines");
174 __builtin_coro_destroy(__handle_);
175 }
176
177 // [coroutine.handle.promise], promise access
178 _LIBCPP_HIDE_FROM_ABI
179 _Promise& promise() const {
180 return *static_cast<_Promise*>(__builtin_coro_promise(this->__handle_, alignof(_Promise), false));
181 }
182
183private:
184 bool __is_suspended() const {
185 // FIXME actually implement a check for if the coro is suspended.
186 return __handle_ != nullptr;
187 }
188 void* __handle_ = nullptr;
189};
190
191// [coroutine.handle.hash]
192template <class _Tp>
193struct hash<coroutine_handle<_Tp>> {
194 _LIBCPP_HIDE_FROM_ABI
195 size_t operator()(const coroutine_handle<_Tp>& __v) const noexcept { return hash<void*>()(__v.address()); }
196};
197
198_LIBCPP_END_NAMESPACE_STD
199
200#endif // __LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_COROUTINES)
201
202#endif // _LIBCPP___COROUTINE_COROUTINE_HANDLE_H
lib/libcxx/include/__coroutine/coroutine_traits.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___COROUTINE_COROUTINE_TRAITS_H
10#define _LIBCPP___COROUTINE_COROUTINE_TRAITS_H
11
12#include <__config>
13#include <type_traits>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16#pragma GCC system_header
17#endif
18
19#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_COROUTINES)
20
21_LIBCPP_BEGIN_NAMESPACE_STD
22
23// [coroutine.traits]
24// [coroutine.traits.primary]
25// The header <coroutine> defined the primary template coroutine_traits such that
26// if ArgTypes is a parameter pack of types and if the qualified-id R::promise_type
27// is valid and denotes a type ([temp.deduct]), then coroutine_traits<R, ArgTypes...>
28// has the following publicly accessible memebr:
29//
30// using promise_type = typename R::promise_type;
31//
32// Otherwise, coroutine_traits<R, ArgTypes...> has no members.
33template <class _Tp, class = void>
34struct __coroutine_traits_sfinae {};
35
36template <class _Tp>
37struct __coroutine_traits_sfinae<
38 _Tp, typename __void_t<typename _Tp::promise_type>::type>
39{
40 using promise_type = typename _Tp::promise_type;
41};
42
43template <class _Ret, class... _Args>
44struct coroutine_traits
45 : public __coroutine_traits_sfinae<_Ret>
46{
47};
48
49_LIBCPP_END_NAMESPACE_STD
50
51#endif // __LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_COROUTINES)
52
53#endif // _LIBCPP___COROUTINE_COROUTINE_TRAITS_H
lib/libcxx/include/__coroutine/noop_coroutine_handle.h created+112
......@@ -0,0 +1,112 @@
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___COROUTINE_NOOP_COROUTINE_HANDLE_H
10#define _LIBCPP___COROUTINE_NOOP_COROUTINE_HANDLE_H
11
12#include <__config>
13#include <__coroutine/coroutine_handle.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16#pragma GCC system_header
17#endif
18
19#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_COROUTINES)
20
21_LIBCPP_BEGIN_NAMESPACE_STD
22
23#if __has_builtin(__builtin_coro_noop) || defined(_LIBCPP_COMPILER_GCC)
24
25// [coroutine.noop]
26// [coroutine.promise.noop]
27struct noop_coroutine_promise {};
28
29// [coroutine.handle.noop]
30template <>
31struct _LIBCPP_TEMPLATE_VIS coroutine_handle<noop_coroutine_promise> {
32public:
33 // [coroutine.handle.noop.conv], conversion
34 _LIBCPP_HIDE_FROM_ABI
35 constexpr operator coroutine_handle<>() const noexcept {
36 return coroutine_handle<>::from_address(address());
37 }
38
39 // [coroutine.handle.noop.observers], observers
40 _LIBCPP_HIDE_FROM_ABI
41 constexpr explicit operator bool() const noexcept { return true; }
42 _LIBCPP_HIDE_FROM_ABI
43 constexpr bool done() const noexcept { return false; }
44
45 // [coroutine.handle.noop.resumption], resumption
46 _LIBCPP_HIDE_FROM_ABI
47 constexpr void operator()() const noexcept {}
48 _LIBCPP_HIDE_FROM_ABI
49 constexpr void resume() const noexcept {}
50 _LIBCPP_HIDE_FROM_ABI
51 constexpr void destroy() const noexcept {}
52
53 // [coroutine.handle.noop.promise], promise access
54 _LIBCPP_HIDE_FROM_ABI
55 noop_coroutine_promise& promise() const noexcept {
56 return *static_cast<noop_coroutine_promise*>(
57 __builtin_coro_promise(this->__handle_, alignof(noop_coroutine_promise), false));
58 }
59
60 // [coroutine.handle.noop.address], address
61 _LIBCPP_HIDE_FROM_ABI
62 constexpr void* address() const noexcept { return __handle_; }
63
64private:
65 _LIBCPP_HIDE_FROM_ABI
66 friend coroutine_handle<noop_coroutine_promise> noop_coroutine() noexcept;
67
68#if __has_builtin(__builtin_coro_noop)
69 _LIBCPP_HIDE_FROM_ABI coroutine_handle() noexcept {
70 this->__handle_ = __builtin_coro_noop();
71 }
72
73 void* __handle_ = nullptr;
74
75#elif defined(_LIBCPP_COMPILER_GCC)
76 // GCC doesn't implement __builtin_coro_noop().
77 // Construct the coroutine frame manually instead.
78 struct __noop_coroutine_frame_ty_ {
79 static void __dummy_resume_destroy_func() { }
80
81 void (*__resume_)() = __dummy_resume_destroy_func;
82 void (*__destroy_)() = __dummy_resume_destroy_func;
83 struct noop_coroutine_promise __promise_;
84 };
85
86 static __noop_coroutine_frame_ty_ __noop_coroutine_frame_;
87
88 void* __handle_ = &__noop_coroutine_frame_;
89
90 _LIBCPP_HIDE_FROM_ABI coroutine_handle() noexcept = default;
91
92#endif // __has_builtin(__builtin_coro_noop)
93};
94
95using noop_coroutine_handle = coroutine_handle<noop_coroutine_promise>;
96
97#if defined(_LIBCPP_COMPILER_GCC)
98inline noop_coroutine_handle::__noop_coroutine_frame_ty_
99 noop_coroutine_handle::__noop_coroutine_frame_{};
100#endif
101
102// [coroutine.noop.coroutine]
103inline _LIBCPP_HIDE_FROM_ABI
104noop_coroutine_handle noop_coroutine() noexcept { return noop_coroutine_handle(); }
105
106#endif // __has_builtin(__builtin_coro_noop) || defined(_LIBCPP_COMPILER_GCC)
107
108_LIBCPP_END_NAMESPACE_STD
109
110#endif // __LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_COROUTINES)
111
112#endif // _LIBCPP___COROUTINE_NOOP_COROUTINE_HANDLE_H
lib/libcxx/include/__coroutine/trivial_awaitables.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___COROUTINE_TRIVIAL_AWAITABLES_H
10#define __LIBCPP___COROUTINE_TRIVIAL_AWAITABLES_H
11
12#include <__config>
13#include <__coroutine/coroutine_handle.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16#pragma GCC system_header
17#endif
18
19#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_COROUTINES)
20
21_LIBCPP_BEGIN_NAMESPACE_STD
22
23// [coroutine.trivial.awaitables]
24struct suspend_never {
25 _LIBCPP_HIDE_FROM_ABI
26 constexpr bool await_ready() const noexcept { return true; }
27 _LIBCPP_HIDE_FROM_ABI
28 constexpr void await_suspend(coroutine_handle<>) const noexcept {}
29 _LIBCPP_HIDE_FROM_ABI
30 constexpr void await_resume() const noexcept {}
31};
32
33struct suspend_always {
34 _LIBCPP_HIDE_FROM_ABI
35 constexpr bool await_ready() const noexcept { return false; }
36 _LIBCPP_HIDE_FROM_ABI
37 constexpr void await_suspend(coroutine_handle<>) const noexcept {}
38 _LIBCPP_HIDE_FROM_ABI
39 constexpr void await_resume() const noexcept {}
40};
41
42_LIBCPP_END_NAMESPACE_STD
43
44#endif // __LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_COROUTINES)
45
46#endif // __LIBCPP___COROUTINE_TRIVIAL_AWAITABLES_H
lib/libcxx/include/__debug+25-4
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- __debug ----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -12,6 +12,7 @@
1212
1313#include <__config>
1414#include <iosfwd>
15#include <type_traits>
1516
1617#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1718#pragma GCC system_header
......@@ -22,9 +23,9 @@
2223#endif
2324
2425#if _LIBCPP_DEBUG_LEVEL >= 1 || defined(_LIBCPP_BUILDING_LIBRARY)
25# include <cstdlib>
26# include <cstdio>
2726# include <cstddef>
27# include <cstdio>
28# include <cstdlib>
2829#endif
2930
3031#if _LIBCPP_DEBUG_LEVEL == 0
......@@ -34,7 +35,7 @@
3435# define _LIBCPP_DEBUG_ASSERT(x, m) ((void)0)
3536# define _LIBCPP_ASSERT_IMPL(x, m) ((x) ? (void)0 : _VSTD::__libcpp_debug_function(_VSTD::__libcpp_debug_info(__FILE__, __LINE__, #x, m)))
3637#elif _LIBCPP_DEBUG_LEVEL == 2
37# define _LIBCPP_DEBUG_ASSERT(x, m) _LIBCPP_ASSERT(x, m)
38# define _LIBCPP_DEBUG_ASSERT(x, m) _LIBCPP_ASSERT(__libcpp_is_constant_evaluated() || (x), m)
3839# define _LIBCPP_ASSERT_IMPL(x, m) ((x) ? (void)0 : _VSTD::__libcpp_debug_function(_VSTD::__libcpp_debug_info(__FILE__, __LINE__, #x, m)))
3940#else
4041# error _LIBCPP_DEBUG_LEVEL must be one of 0, 1, 2
......@@ -268,6 +269,26 @@ _LIBCPP_FUNC_VIS const __libcpp_db* __get_const_db();
268269
269270#endif // _LIBCPP_DEBUG_LEVEL == 2 || defined(_LIBCPP_BUILDING_LIBRARY)
270271
272template <class _Tp>
273_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 inline void __debug_db_insert_c(_Tp* __c) {
274#if _LIBCPP_DEBUG_LEVEL == 2
275 if (!__libcpp_is_constant_evaluated())
276 __get_db()->__insert_c(__c);
277#else
278 (void)(__c);
279#endif
280}
281
282template <class _Tp>
283_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 inline void __debug_db_insert_i(_Tp* __i) {
284#if _LIBCPP_DEBUG_LEVEL == 2
285 if (!__libcpp_is_constant_evaluated())
286 __get_db()->__insert_i(__i);
287#else
288 (void)(__i);
289#endif
290}
291
271292_LIBCPP_END_NAMESPACE_STD
272293
273294#endif // _LIBCPP_DEBUG_H
lib/libcxx/include/__errc+1-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===---------------------------- __errc ----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/__filesystem/copy_options.h created+80
......@@ -0,0 +1,80 @@
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___FILESYSTEM_COPY_OPTIONS_H
11#define _LIBCPP___FILESYSTEM_COPY_OPTIONS_H
12
13#include <__availability>
14#include <__config>
15
16#ifndef _LIBCPP_CXX03_LANG
17
18_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
19
20_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH
21
22enum class _LIBCPP_ENUM_VIS copy_options : unsigned short {
23 none = 0,
24 skip_existing = 1,
25 overwrite_existing = 2,
26 update_existing = 4,
27 recursive = 8,
28 copy_symlinks = 16,
29 skip_symlinks = 32,
30 directories_only = 64,
31 create_symlinks = 128,
32 create_hard_links = 256,
33 __in_recursive_copy = 512,
34};
35
36_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));
40}
41
42_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));
46}
47
48_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));
52}
53
54_LIBCPP_INLINE_VISIBILITY
55inline constexpr copy_options operator~(copy_options _LHS) {
56 return static_cast<copy_options>(~static_cast<unsigned short>(_LHS));
57}
58
59_LIBCPP_INLINE_VISIBILITY
60inline copy_options& operator&=(copy_options& _LHS, copy_options _RHS) {
61 return _LHS = _LHS & _RHS;
62}
63
64_LIBCPP_INLINE_VISIBILITY
65inline copy_options& operator|=(copy_options& _LHS, copy_options _RHS) {
66 return _LHS = _LHS | _RHS;
67}
68
69_LIBCPP_INLINE_VISIBILITY
70inline copy_options& operator^=(copy_options& _LHS, copy_options _RHS) {
71 return _LHS = _LHS ^ _RHS;
72}
73
74_LIBCPP_AVAILABILITY_FILESYSTEM_POP
75
76_LIBCPP_END_NAMESPACE_FILESYSTEM
77
78#endif // _LIBCPP_CXX03_LANG
79
80#endif // _LIBCPP___FILESYSTEM_COPY_OPTIONS_H
lib/libcxx/include/__filesystem/directory_entry.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
10#ifndef _LIBCPP___FILESYSTEM_DIRECTORY_ENTRY_H
11#define _LIBCPP___FILESYSTEM_DIRECTORY_ENTRY_H
12
13#include <__availability>
14#include <__config>
15#include <__errc>
16#include <__filesystem/file_status.h>
17#include <__filesystem/file_time_type.h>
18#include <__filesystem/file_type.h>
19#include <__filesystem/filesystem_error.h>
20#include <__filesystem/operations.h>
21#include <__filesystem/path.h>
22#include <__filesystem/perms.h>
23#include <chrono>
24#include <cstdint>
25#include <cstdlib>
26#include <iosfwd>
27#include <system_error>
28
29_LIBCPP_PUSH_MACROS
30#include <__undef_macros>
31
32#ifndef _LIBCPP_CXX03_LANG
33
34_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
35
36_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH
37
38
39class directory_entry {
40 typedef _VSTD_FS::path _Path;
41
42public:
43 // constructors and destructors
44 directory_entry() noexcept = default;
45 directory_entry(directory_entry const&) = default;
46 directory_entry(directory_entry&&) noexcept = default;
47
48 _LIBCPP_INLINE_VISIBILITY
49 explicit directory_entry(_Path const& __p) : __p_(__p) {
50 error_code __ec;
51 __refresh(&__ec);
52 }
53
54 _LIBCPP_INLINE_VISIBILITY
55 directory_entry(_Path const& __p, error_code& __ec) : __p_(__p) {
56 __refresh(&__ec);
57 }
58
59 ~directory_entry() {}
60
61 directory_entry& operator=(directory_entry const&) = default;
62 directory_entry& operator=(directory_entry&&) noexcept = default;
63
64 _LIBCPP_INLINE_VISIBILITY
65 void assign(_Path const& __p) {
66 __p_ = __p;
67 error_code __ec;
68 __refresh(&__ec);
69 }
70
71 _LIBCPP_INLINE_VISIBILITY
72 void assign(_Path const& __p, error_code& __ec) {
73 __p_ = __p;
74 __refresh(&__ec);
75 }
76
77 _LIBCPP_INLINE_VISIBILITY
78 void replace_filename(_Path const& __p) {
79 __p_.replace_filename(__p);
80 error_code __ec;
81 __refresh(&__ec);
82 }
83
84 _LIBCPP_INLINE_VISIBILITY
85 void replace_filename(_Path const& __p, error_code& __ec) {
86 __p_ = __p_.parent_path() / __p;
87 __refresh(&__ec);
88 }
89
90 _LIBCPP_INLINE_VISIBILITY
91 void refresh() { __refresh(); }
92
93 _LIBCPP_INLINE_VISIBILITY
94 void refresh(error_code& __ec) noexcept { __refresh(&__ec); }
95
96 _LIBCPP_INLINE_VISIBILITY
97 _Path const& path() const noexcept { return __p_; }
98
99 _LIBCPP_INLINE_VISIBILITY
100 operator const _Path&() const noexcept { return __p_; }
101
102 _LIBCPP_INLINE_VISIBILITY
103 bool exists() const { return _VSTD_FS::exists(file_status{__get_ft()}); }
104
105 _LIBCPP_INLINE_VISIBILITY
106 bool exists(error_code& __ec) const noexcept {
107 return _VSTD_FS::exists(file_status{__get_ft(&__ec)});
108 }
109
110 _LIBCPP_INLINE_VISIBILITY
111 bool is_block_file() const { return __get_ft() == file_type::block; }
112
113 _LIBCPP_INLINE_VISIBILITY
114 bool is_block_file(error_code& __ec) const noexcept {
115 return __get_ft(&__ec) == file_type::block;
116 }
117
118 _LIBCPP_INLINE_VISIBILITY
119 bool is_character_file() const { return __get_ft() == file_type::character; }
120
121 _LIBCPP_INLINE_VISIBILITY
122 bool is_character_file(error_code& __ec) const noexcept {
123 return __get_ft(&__ec) == file_type::character;
124 }
125
126 _LIBCPP_INLINE_VISIBILITY
127 bool is_directory() const { return __get_ft() == file_type::directory; }
128
129 _LIBCPP_INLINE_VISIBILITY
130 bool is_directory(error_code& __ec) const noexcept {
131 return __get_ft(&__ec) == file_type::directory;
132 }
133
134 _LIBCPP_INLINE_VISIBILITY
135 bool is_fifo() const { return __get_ft() == file_type::fifo; }
136
137 _LIBCPP_INLINE_VISIBILITY
138 bool is_fifo(error_code& __ec) const noexcept {
139 return __get_ft(&__ec) == file_type::fifo;
140 }
141
142 _LIBCPP_INLINE_VISIBILITY
143 bool is_other() const { return _VSTD_FS::is_other(file_status{__get_ft()}); }
144
145 _LIBCPP_INLINE_VISIBILITY
146 bool is_other(error_code& __ec) const noexcept {
147 return _VSTD_FS::is_other(file_status{__get_ft(&__ec)});
148 }
149
150 _LIBCPP_INLINE_VISIBILITY
151 bool is_regular_file() const { return __get_ft() == file_type::regular; }
152
153 _LIBCPP_INLINE_VISIBILITY
154 bool is_regular_file(error_code& __ec) const noexcept {
155 return __get_ft(&__ec) == file_type::regular;
156 }
157
158 _LIBCPP_INLINE_VISIBILITY
159 bool is_socket() const { return __get_ft() == file_type::socket; }
160
161 _LIBCPP_INLINE_VISIBILITY
162 bool is_socket(error_code& __ec) const noexcept {
163 return __get_ft(&__ec) == file_type::socket;
164 }
165
166 _LIBCPP_INLINE_VISIBILITY
167 bool is_symlink() const { return __get_sym_ft() == file_type::symlink; }
168
169 _LIBCPP_INLINE_VISIBILITY
170 bool is_symlink(error_code& __ec) const noexcept {
171 return __get_sym_ft(&__ec) == file_type::symlink;
172 }
173 _LIBCPP_INLINE_VISIBILITY
174 uintmax_t file_size() const { return __get_size(); }
175
176 _LIBCPP_INLINE_VISIBILITY
177 uintmax_t file_size(error_code& __ec) const noexcept {
178 return __get_size(&__ec);
179 }
180
181 _LIBCPP_INLINE_VISIBILITY
182 uintmax_t hard_link_count() const { return __get_nlink(); }
183
184 _LIBCPP_INLINE_VISIBILITY
185 uintmax_t hard_link_count(error_code& __ec) const noexcept {
186 return __get_nlink(&__ec);
187 }
188
189 _LIBCPP_INLINE_VISIBILITY
190 file_time_type last_write_time() const { return __get_write_time(); }
191
192 _LIBCPP_INLINE_VISIBILITY
193 file_time_type last_write_time(error_code& __ec) const noexcept {
194 return __get_write_time(&__ec);
195 }
196
197 _LIBCPP_INLINE_VISIBILITY
198 file_status status() const { return __get_status(); }
199
200 _LIBCPP_INLINE_VISIBILITY
201 file_status status(error_code& __ec) const noexcept {
202 return __get_status(&__ec);
203 }
204
205 _LIBCPP_INLINE_VISIBILITY
206 file_status symlink_status() const { return __get_symlink_status(); }
207
208 _LIBCPP_INLINE_VISIBILITY
209 file_status symlink_status(error_code& __ec) const noexcept {
210 return __get_symlink_status(&__ec);
211 }
212
213 _LIBCPP_INLINE_VISIBILITY
214 bool operator<(directory_entry const& __rhs) const noexcept {
215 return __p_ < __rhs.__p_;
216 }
217
218 _LIBCPP_INLINE_VISIBILITY
219 bool operator==(directory_entry const& __rhs) const noexcept {
220 return __p_ == __rhs.__p_;
221 }
222
223 _LIBCPP_INLINE_VISIBILITY
224 bool operator!=(directory_entry const& __rhs) const noexcept {
225 return __p_ != __rhs.__p_;
226 }
227
228 _LIBCPP_INLINE_VISIBILITY
229 bool operator<=(directory_entry const& __rhs) const noexcept {
230 return __p_ <= __rhs.__p_;
231 }
232
233 _LIBCPP_INLINE_VISIBILITY
234 bool operator>(directory_entry const& __rhs) const noexcept {
235 return __p_ > __rhs.__p_;
236 }
237
238 _LIBCPP_INLINE_VISIBILITY
239 bool operator>=(directory_entry const& __rhs) const noexcept {
240 return __p_ >= __rhs.__p_;
241 }
242
243 template <class _CharT, class _Traits>
244 _LIBCPP_INLINE_VISIBILITY
245 friend basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const directory_entry& __d) {
246 return __os << __d.path();
247 }
248
249private:
250 friend class directory_iterator;
251 friend class recursive_directory_iterator;
252 friend class _LIBCPP_HIDDEN __dir_stream;
253
254 enum _CacheType : unsigned char {
255 _Empty,
256 _IterSymlink,
257 _IterNonSymlink,
258 _RefreshSymlink,
259 _RefreshSymlinkUnresolved,
260 _RefreshNonSymlink
261 };
262
263 struct __cached_data {
264 uintmax_t __size_;
265 uintmax_t __nlink_;
266 file_time_type __write_time_;
267 perms __sym_perms_;
268 perms __non_sym_perms_;
269 file_type __type_;
270 _CacheType __cache_type_;
271
272 _LIBCPP_INLINE_VISIBILITY
273 __cached_data() noexcept { __reset(); }
274
275 _LIBCPP_INLINE_VISIBILITY
276 void __reset() {
277 __cache_type_ = _Empty;
278 __type_ = file_type::none;
279 __sym_perms_ = __non_sym_perms_ = perms::unknown;
280 __size_ = __nlink_ = uintmax_t(-1);
281 __write_time_ = file_time_type::min();
282 }
283 };
284
285 _LIBCPP_INLINE_VISIBILITY
286 static __cached_data __create_iter_result(file_type __ft) {
287 __cached_data __data;
288 __data.__type_ = __ft;
289 __data.__cache_type_ = [&]() {
290 switch (__ft) {
291 case file_type::none:
292 return _Empty;
293 case file_type::symlink:
294 return _IterSymlink;
295 default:
296 return _IterNonSymlink;
297 }
298 }();
299 return __data;
300 }
301
302 _LIBCPP_INLINE_VISIBILITY
303 void __assign_iter_entry(_Path&& __p, __cached_data __dt) {
304 __p_ = _VSTD::move(__p);
305 __data_ = __dt;
306 }
307
308 _LIBCPP_FUNC_VIS
309 error_code __do_refresh() noexcept;
310
311 _LIBCPP_INLINE_VISIBILITY
312 static bool __is_dne_error(error_code const& __ec) {
313 if (!__ec)
314 return true;
315 switch (static_cast<errc>(__ec.value())) {
316 case errc::no_such_file_or_directory:
317 case errc::not_a_directory:
318 return true;
319 default:
320 return false;
321 }
322 }
323
324 _LIBCPP_INLINE_VISIBILITY
325 void __handle_error(const char* __msg, error_code* __dest_ec,
326 error_code const& __ec, bool __allow_dne = false) const {
327 if (__dest_ec) {
328 *__dest_ec = __ec;
329 return;
330 }
331 if (__ec && (!__allow_dne || !__is_dne_error(__ec)))
332 __throw_filesystem_error(__msg, __p_, __ec);
333 }
334
335 _LIBCPP_INLINE_VISIBILITY
336 void __refresh(error_code* __ec = nullptr) {
337 __handle_error("in directory_entry::refresh", __ec, __do_refresh(),
338 /*allow_dne*/ true);
339 }
340
341 _LIBCPP_INLINE_VISIBILITY
342 file_type __get_sym_ft(error_code* __ec = nullptr) const {
343 switch (__data_.__cache_type_) {
344 case _Empty:
345 return __symlink_status(__p_, __ec).type();
346 case _IterSymlink:
347 case _RefreshSymlink:
348 case _RefreshSymlinkUnresolved:
349 if (__ec)
350 __ec->clear();
351 return file_type::symlink;
352 case _IterNonSymlink:
353 case _RefreshNonSymlink:
354 file_status __st(__data_.__type_);
355 if (__ec && !_VSTD_FS::exists(__st))
356 *__ec = make_error_code(errc::no_such_file_or_directory);
357 else if (__ec)
358 __ec->clear();
359 return __data_.__type_;
360 }
361 _LIBCPP_UNREACHABLE();
362 }
363
364 _LIBCPP_INLINE_VISIBILITY
365 file_type __get_ft(error_code* __ec = nullptr) const {
366 switch (__data_.__cache_type_) {
367 case _Empty:
368 case _IterSymlink:
369 case _RefreshSymlinkUnresolved:
370 return __status(__p_, __ec).type();
371 case _IterNonSymlink:
372 case _RefreshNonSymlink:
373 case _RefreshSymlink: {
374 file_status __st(__data_.__type_);
375 if (__ec && !_VSTD_FS::exists(__st))
376 *__ec = make_error_code(errc::no_such_file_or_directory);
377 else if (__ec)
378 __ec->clear();
379 return __data_.__type_;
380 }
381 }
382 _LIBCPP_UNREACHABLE();
383 }
384
385 _LIBCPP_INLINE_VISIBILITY
386 file_status __get_status(error_code* __ec = nullptr) const {
387 switch (__data_.__cache_type_) {
388 case _Empty:
389 case _IterNonSymlink:
390 case _IterSymlink:
391 case _RefreshSymlinkUnresolved:
392 return __status(__p_, __ec);
393 case _RefreshNonSymlink:
394 case _RefreshSymlink:
395 return file_status(__get_ft(__ec), __data_.__non_sym_perms_);
396 }
397 _LIBCPP_UNREACHABLE();
398 }
399
400 _LIBCPP_INLINE_VISIBILITY
401 file_status __get_symlink_status(error_code* __ec = nullptr) const {
402 switch (__data_.__cache_type_) {
403 case _Empty:
404 case _IterNonSymlink:
405 case _IterSymlink:
406 return __symlink_status(__p_, __ec);
407 case _RefreshNonSymlink:
408 return file_status(__get_sym_ft(__ec), __data_.__non_sym_perms_);
409 case _RefreshSymlink:
410 case _RefreshSymlinkUnresolved:
411 return file_status(__get_sym_ft(__ec), __data_.__sym_perms_);
412 }
413 _LIBCPP_UNREACHABLE();
414 }
415
416 _LIBCPP_INLINE_VISIBILITY
417 uintmax_t __get_size(error_code* __ec = nullptr) const {
418 switch (__data_.__cache_type_) {
419 case _Empty:
420 case _IterNonSymlink:
421 case _IterSymlink:
422 case _RefreshSymlinkUnresolved:
423 return _VSTD_FS::__file_size(__p_, __ec);
424 case _RefreshSymlink:
425 case _RefreshNonSymlink: {
426 error_code __m_ec;
427 file_status __st(__get_ft(&__m_ec));
428 __handle_error("in directory_entry::file_size", __ec, __m_ec);
429 if (_VSTD_FS::exists(__st) && !_VSTD_FS::is_regular_file(__st)) {
430 errc __err_kind = _VSTD_FS::is_directory(__st) ? errc::is_a_directory
431 : errc::not_supported;
432 __handle_error("in directory_entry::file_size", __ec,
433 make_error_code(__err_kind));
434 }
435 return __data_.__size_;
436 }
437 }
438 _LIBCPP_UNREACHABLE();
439 }
440
441 _LIBCPP_INLINE_VISIBILITY
442 uintmax_t __get_nlink(error_code* __ec = nullptr) const {
443 switch (__data_.__cache_type_) {
444 case _Empty:
445 case _IterNonSymlink:
446 case _IterSymlink:
447 case _RefreshSymlinkUnresolved:
448 return _VSTD_FS::__hard_link_count(__p_, __ec);
449 case _RefreshSymlink:
450 case _RefreshNonSymlink: {
451 error_code __m_ec;
452 (void)__get_ft(&__m_ec);
453 __handle_error("in directory_entry::hard_link_count", __ec, __m_ec);
454 return __data_.__nlink_;
455 }
456 }
457 _LIBCPP_UNREACHABLE();
458 }
459
460 _LIBCPP_INLINE_VISIBILITY
461 file_time_type __get_write_time(error_code* __ec = nullptr) const {
462 switch (__data_.__cache_type_) {
463 case _Empty:
464 case _IterNonSymlink:
465 case _IterSymlink:
466 case _RefreshSymlinkUnresolved:
467 return _VSTD_FS::__last_write_time(__p_, __ec);
468 case _RefreshSymlink:
469 case _RefreshNonSymlink: {
470 error_code __m_ec;
471 file_status __st(__get_ft(&__m_ec));
472 __handle_error("in directory_entry::last_write_time", __ec, __m_ec);
473 if (_VSTD_FS::exists(__st) &&
474 __data_.__write_time_ == file_time_type::min())
475 __handle_error("in directory_entry::last_write_time", __ec,
476 make_error_code(errc::value_too_large));
477 return __data_.__write_time_;
478 }
479 }
480 _LIBCPP_UNREACHABLE();
481 }
482
483private:
484 _Path __p_;
485 __cached_data __data_;
486};
487
488class __dir_element_proxy {
489public:
490 inline _LIBCPP_INLINE_VISIBILITY directory_entry operator*() {
491 return _VSTD::move(__elem_);
492 }
493
494private:
495 friend class directory_iterator;
496 friend class recursive_directory_iterator;
497 explicit __dir_element_proxy(directory_entry const& __e) : __elem_(__e) {}
498 __dir_element_proxy(__dir_element_proxy&& __o)
499 : __elem_(_VSTD::move(__o.__elem_)) {}
500 directory_entry __elem_;
501};
502
503_LIBCPP_AVAILABILITY_FILESYSTEM_POP
504
505_LIBCPP_END_NAMESPACE_FILESYSTEM
506
507#endif // _LIBCPP_CXX03_LANG
508
509_LIBCPP_POP_MACROS
510
511#endif // _LIBCPP___FILESYSTEM_DIRECTORY_ENTRY_H
lib/libcxx/include/__filesystem/directory_iterator.h created+150
......@@ -0,0 +1,150 @@
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___FILESYSTEM_DIRECTORY_ITERATOR_H
11#define _LIBCPP___FILESYSTEM_DIRECTORY_ITERATOR_H
12
13#include <__availability>
14#include <__config>
15#include <__debug>
16#include <__filesystem/directory_entry.h>
17#include <__filesystem/directory_options.h>
18#include <__filesystem/path.h>
19#include <__iterator/iterator_traits.h>
20#include <__memory/shared_ptr.h>
21#include <__ranges/enable_borrowed_range.h>
22#include <__ranges/enable_view.h>
23#include <cstddef>
24#include <system_error>
25
26#ifndef _LIBCPP_CXX03_LANG
27
28_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
29
30_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH
31
32class _LIBCPP_HIDDEN __dir_stream;
33class directory_iterator {
34public:
35 typedef directory_entry value_type;
36 typedef ptrdiff_t difference_type;
37 typedef value_type const* pointer;
38 typedef value_type const& reference;
39 typedef input_iterator_tag iterator_category;
40
41public:
42 //ctor & dtor
43 directory_iterator() noexcept {}
44
45 explicit directory_iterator(const path& __p)
46 : directory_iterator(__p, nullptr) {}
47
48 directory_iterator(const path& __p, directory_options __opts)
49 : directory_iterator(__p, nullptr, __opts) {}
50
51 directory_iterator(const path& __p, error_code& __ec)
52 : directory_iterator(__p, &__ec) {}
53
54 directory_iterator(const path& __p, directory_options __opts,
55 error_code& __ec)
56 : directory_iterator(__p, &__ec, __opts) {}
57
58 directory_iterator(const directory_iterator&) = default;
59 directory_iterator(directory_iterator&&) = default;
60 directory_iterator& operator=(const directory_iterator&) = default;
61
62 directory_iterator& operator=(directory_iterator&& __o) noexcept {
63 // non-default implementation provided to support self-move assign.
64 if (this != &__o) {
65 __imp_ = _VSTD::move(__o.__imp_);
66 }
67 return *this;
68 }
69
70 ~directory_iterator() = default;
71
72 const directory_entry& operator*() const {
73 _LIBCPP_ASSERT(__imp_, "The end iterator cannot be dereferenced");
74 return __dereference();
75 }
76
77 const directory_entry* operator->() const { return &**this; }
78
79 directory_iterator& operator++() { return __increment(); }
80
81 __dir_element_proxy operator++(int) {
82 __dir_element_proxy __p(**this);
83 __increment();
84 return __p;
85 }
86
87 directory_iterator& increment(error_code& __ec) { return __increment(&__ec); }
88
89private:
90 inline _LIBCPP_INLINE_VISIBILITY friend bool
91 operator==(const directory_iterator& __lhs,
92 const directory_iterator& __rhs) noexcept;
93
94 // construct the dir_stream
95 _LIBCPP_FUNC_VIS
96 directory_iterator(const path&, error_code*,
97 directory_options = directory_options::none);
98
99 _LIBCPP_FUNC_VIS
100 directory_iterator& __increment(error_code* __ec = nullptr);
101
102 _LIBCPP_FUNC_VIS
103 const directory_entry& __dereference() const;
104
105private:
106 shared_ptr<__dir_stream> __imp_;
107};
108
109inline _LIBCPP_INLINE_VISIBILITY bool
110operator==(const directory_iterator& __lhs,
111 const directory_iterator& __rhs) noexcept {
112 return __lhs.__imp_ == __rhs.__imp_;
113}
114
115inline _LIBCPP_INLINE_VISIBILITY bool
116operator!=(const directory_iterator& __lhs,
117 const directory_iterator& __rhs) noexcept {
118 return !(__lhs == __rhs);
119}
120
121// enable directory_iterator range-based for statements
122inline _LIBCPP_INLINE_VISIBILITY directory_iterator
123begin(directory_iterator __iter) noexcept {
124 return __iter;
125}
126
127inline _LIBCPP_INLINE_VISIBILITY directory_iterator
128end(directory_iterator) noexcept {
129 return directory_iterator();
130}
131
132_LIBCPP_AVAILABILITY_FILESYSTEM_POP
133
134_LIBCPP_END_NAMESPACE_FILESYSTEM
135
136#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
137
138template <>
139_LIBCPP_AVAILABILITY_FILESYSTEM
140inline constexpr bool _VSTD::ranges::enable_borrowed_range<_VSTD_FS::directory_iterator> = true;
141
142template <>
143_LIBCPP_AVAILABILITY_FILESYSTEM
144inline constexpr bool _VSTD::ranges::enable_view<_VSTD_FS::directory_iterator> = true;
145
146#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
147
148#endif // _LIBCPP_CXX03_LANG
149
150#endif // _LIBCPP___FILESYSTEM_DIRECTORY_ITERATOR_H
lib/libcxx/include/__filesystem/directory_options.h created+78
......@@ -0,0 +1,78 @@
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___FILESYSTEM_DIRECTORY_OPTIONS_H
11#define _LIBCPP___FILESYSTEM_DIRECTORY_OPTIONS_H
12
13#include <__availability>
14#include <__config>
15
16#ifndef _LIBCPP_CXX03_LANG
17
18_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
19
20_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH
21
22enum class _LIBCPP_ENUM_VIS directory_options : unsigned char {
23 none = 0,
24 follow_directory_symlink = 1,
25 skip_permission_denied = 2
26};
27
28_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));
33}
34
35_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));
40}
41
42_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));
47}
48
49_LIBCPP_INLINE_VISIBILITY
50inline constexpr directory_options operator~(directory_options _LHS) {
51 return static_cast<directory_options>(~static_cast<unsigned char>(_LHS));
52}
53
54_LIBCPP_INLINE_VISIBILITY
55inline directory_options& operator&=(directory_options& _LHS,
56 directory_options _RHS) {
57 return _LHS = _LHS & _RHS;
58}
59
60_LIBCPP_INLINE_VISIBILITY
61inline directory_options& operator|=(directory_options& _LHS,
62 directory_options _RHS) {
63 return _LHS = _LHS | _RHS;
64}
65
66_LIBCPP_INLINE_VISIBILITY
67inline directory_options& operator^=(directory_options& _LHS,
68 directory_options _RHS) {
69 return _LHS = _LHS ^ _RHS;
70}
71
72_LIBCPP_AVAILABILITY_FILESYSTEM_POP
73
74_LIBCPP_END_NAMESPACE_FILESYSTEM
75
76#endif // _LIBCPP_CXX03_LANG
77
78#endif // _LIBCPP___FILESYSTEM_DIRECTORY_OPTIONS_H
lib/libcxx/include/__filesystem/file_status.h created+68
......@@ -0,0 +1,68 @@
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___FILESYSTEM_FILE_STATUS_H
11#define _LIBCPP___FILESYSTEM_FILE_STATUS_H
12
13#include <__availability>
14#include <__config>
15#include <__filesystem/file_type.h>
16#include <__filesystem/perms.h>
17
18#ifndef _LIBCPP_CXX03_LANG
19
20_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
21
22_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH
23
24class _LIBCPP_TYPE_VIS file_status {
25public:
26 // constructors
27 _LIBCPP_INLINE_VISIBILITY
28 file_status() noexcept : file_status(file_type::none) {}
29 _LIBCPP_INLINE_VISIBILITY
30 explicit file_status(file_type __ft, perms __prms = perms::unknown) noexcept
31 : __ft_(__ft),
32 __prms_(__prms) {}
33
34 file_status(const file_status&) noexcept = default;
35 file_status(file_status&&) noexcept = default;
36
37 _LIBCPP_INLINE_VISIBILITY
38 ~file_status() {}
39
40 file_status& operator=(const file_status&) noexcept = default;
41 file_status& operator=(file_status&&) noexcept = default;
42
43 // observers
44 _LIBCPP_INLINE_VISIBILITY
45 file_type type() const noexcept { return __ft_; }
46
47 _LIBCPP_INLINE_VISIBILITY
48 perms permissions() const noexcept { return __prms_; }
49
50 // modifiers
51 _LIBCPP_INLINE_VISIBILITY
52 void type(file_type __ft) noexcept { __ft_ = __ft; }
53
54 _LIBCPP_INLINE_VISIBILITY
55 void permissions(perms __p) noexcept { __prms_ = __p; }
56
57private:
58 file_type __ft_;
59 perms __prms_;
60};
61
62_LIBCPP_AVAILABILITY_FILESYSTEM_POP
63
64_LIBCPP_END_NAMESPACE_FILESYSTEM
65
66#endif // _LIBCPP_CXX03_LANG
67
68#endif // _LIBCPP___FILESYSTEM_FILE_STATUS_H
lib/libcxx/include/__filesystem/file_time_type.h 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___FILESYSTEM_FILE_TIME_TYPE_H
11#define _LIBCPP___FILESYSTEM_FILE_TIME_TYPE_H
12
13#include <__availability>
14#include <__config>
15#include <chrono>
16
17#ifndef _LIBCPP_CXX03_LANG
18
19_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
20
21typedef chrono::time_point<_FilesystemClock> file_time_type;
22
23_LIBCPP_END_NAMESPACE_FILESYSTEM
24
25#endif // _LIBCPP_CXX03_LANG
26
27#endif // _LIBCPP___FILESYSTEM_FILE_TIME_TYPE_H
lib/libcxx/include/__filesystem/file_type.h created+39
......@@ -0,0 +1,39 @@
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___FILESYSTEM_FILE_TYPE_H
11#define _LIBCPP___FILESYSTEM_FILE_TYPE_H
12
13#include <__availability>
14#include <__config>
15
16#ifndef _LIBCPP_CXX03_LANG
17
18_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
19
20// On Windows, the library never identifies files as block, character, fifo
21// or socket.
22enum class _LIBCPP_ENUM_VIS file_type : signed char {
23 none = 0,
24 not_found = -1,
25 regular = 1,
26 directory = 2,
27 symlink = 3,
28 block = 4,
29 character = 5,
30 fifo = 6,
31 socket = 7,
32 unknown = 8
33};
34
35_LIBCPP_END_NAMESPACE_FILESYSTEM
36
37#endif // _LIBCPP_CXX03_LANG
38
39#endif // _LIBCPP___FILESYSTEM_FILE_TYPE_H
lib/libcxx/include/__filesystem/filesystem_error.h created+99
......@@ -0,0 +1,99 @@
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___FILESYSTEM_FILESYSTEM_ERROR_H
11#define _LIBCPP___FILESYSTEM_FILESYSTEM_ERROR_H
12
13#include <__availability>
14#include <__config>
15#include <__filesystem/path.h>
16#include <__memory/shared_ptr.h>
17#include <iosfwd>
18#include <new>
19#include <system_error>
20#include <type_traits>
21
22#ifndef _LIBCPP_CXX03_LANG
23
24_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
25
26class _LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_EXCEPTION_ABI filesystem_error : public system_error {
27public:
28 _LIBCPP_INLINE_VISIBILITY
29 filesystem_error(const string& __what, error_code __ec)
30 : system_error(__ec, __what),
31 __storage_(make_shared<_Storage>(path(), path())) {
32 __create_what(0);
33 }
34
35 _LIBCPP_INLINE_VISIBILITY
36 filesystem_error(const string& __what, const path& __p1, error_code __ec)
37 : system_error(__ec, __what),
38 __storage_(make_shared<_Storage>(__p1, path())) {
39 __create_what(1);
40 }
41
42 _LIBCPP_INLINE_VISIBILITY
43 filesystem_error(const string& __what, const path& __p1, const path& __p2,
44 error_code __ec)
45 : system_error(__ec, __what),
46 __storage_(make_shared<_Storage>(__p1, __p2)) {
47 __create_what(2);
48 }
49
50 _LIBCPP_INLINE_VISIBILITY
51 const path& path1() const noexcept { return __storage_->__p1_; }
52
53 _LIBCPP_INLINE_VISIBILITY
54 const path& path2() const noexcept { return __storage_->__p2_; }
55
56 filesystem_error(const filesystem_error&) = default;
57 ~filesystem_error() override; // key function
58
59 _LIBCPP_INLINE_VISIBILITY
60 const char* what() const noexcept override {
61 return __storage_->__what_.c_str();
62 }
63
64 void __create_what(int __num_paths);
65
66private:
67 struct _LIBCPP_HIDDEN _Storage {
68 _LIBCPP_INLINE_VISIBILITY
69 _Storage(const path& __p1, const path& __p2) : __p1_(__p1), __p2_(__p2) {}
70
71 path __p1_;
72 path __p2_;
73 string __what_;
74 };
75 shared_ptr<_Storage> __storage_;
76};
77
78// TODO(ldionne): We need to pop the pragma and push it again after
79// filesystem_error to work around PR41078.
80_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH
81
82template <class... _Args>
83_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
84#ifndef _LIBCPP_NO_EXCEPTIONS
85void __throw_filesystem_error(_Args&&... __args) {
86 throw filesystem_error(_VSTD::forward<_Args>(__args)...);
87}
88#else
89void __throw_filesystem_error(_Args&&...) {
90 _VSTD::abort();
91}
92#endif
93_LIBCPP_AVAILABILITY_FILESYSTEM_POP
94
95_LIBCPP_END_NAMESPACE_FILESYSTEM
96
97#endif // _LIBCPP_CXX03_LANG
98
99#endif // _LIBCPP___FILESYSTEM_FILESYSTEM_ERROR_H
lib/libcxx/include/__filesystem/operations.h created+197
......@@ -0,0 +1,197 @@
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___FILESYSTEM_OPERATIONS_H
11#define _LIBCPP___FILESYSTEM_OPERATIONS_H
12
13#include <__availability>
14#include <__config>
15#include <__filesystem/copy_options.h>
16#include <__filesystem/file_status.h>
17#include <__filesystem/file_time_type.h>
18#include <__filesystem/file_type.h>
19#include <__filesystem/path.h>
20#include <__filesystem/perm_options.h>
21#include <__filesystem/perms.h>
22#include <__filesystem/space_info.h>
23#include <chrono>
24#include <cstdint>
25#include <system_error>
26
27#ifndef _LIBCPP_CXX03_LANG
28
29_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
30
31_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH
32
33_LIBCPP_FUNC_VIS path __absolute(const path&, error_code* __ec = nullptr);
34_LIBCPP_FUNC_VIS path __canonical(const path&, error_code* __ec = nullptr);
35_LIBCPP_FUNC_VIS bool __copy_file(const path& __from, const path& __to, copy_options __opt, error_code* __ec = nullptr);
36_LIBCPP_FUNC_VIS void __copy_symlink(const path& __existing_symlink, const path& __new_symlink, error_code* __ec = nullptr);
37_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);
39_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);
42_LIBCPP_FUNC_VIS void __create_hard_link(const path& __to, const path& __new_hard_link, error_code* __ec = nullptr);
43_LIBCPP_FUNC_VIS void __create_symlink(const path& __to, const path& __new_symlink, error_code* __ec = nullptr);
44_LIBCPP_FUNC_VIS path __current_path(error_code* __ec = nullptr);
45_LIBCPP_FUNC_VIS void __current_path(const path&, error_code* __ec = nullptr);
46_LIBCPP_FUNC_VIS bool __equivalent(const path&, const path&, error_code* __ec = nullptr);
47_LIBCPP_FUNC_VIS file_status __status(const path&, error_code* __ec = nullptr);
48_LIBCPP_FUNC_VIS uintmax_t __file_size(const path&, error_code* __ec = nullptr);
49_LIBCPP_FUNC_VIS uintmax_t __hard_link_count(const path&, error_code* __ec = nullptr);
50_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);
53_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);
59_LIBCPP_FUNC_VIS path __temp_directory_path(error_code* __ec = nullptr);
60
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)); }
96
97inline _LIBCPP_INLINE_VISIBILITY bool exists(const path& __p, error_code& __ec) noexcept {
98 auto __s = __status(__p, &__ec);
99 if (status_known(__s))
100 __ec.clear();
101 return exists(__s);
102}
103
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); }
139_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); }
143
144inline _LIBCPP_INLINE_VISIBILITY path proximate(const path& __p, const path& __base, error_code& __ec) {
145 path __tmp = __weakly_canonical(__p, &__ec);
146 if (__ec)
147 return {};
148 path __tmp_base = __weakly_canonical(__base, &__ec);
149 if (__ec)
150 return {};
151 return __tmp.lexically_proximate(__tmp_base);
152}
153
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); }
158
159inline _LIBCPP_INLINE_VISIBILITY path relative(const path& __p, const path& __base, error_code& __ec) {
160 path __tmp = __weakly_canonical(__p, &__ec);
161 if (__ec)
162 return path();
163 path __tmpbase = __weakly_canonical(__base, &__ec);
164 if (__ec)
165 return path();
166 return __tmp.lexically_relative(__tmpbase);
167}
168
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); }
179_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); }
190
191_LIBCPP_AVAILABILITY_FILESYSTEM_POP
192
193_LIBCPP_END_NAMESPACE_FILESYSTEM
194
195#endif // _LIBCPP_CXX03_LANG
196
197#endif // _LIBCPP___FILESYSTEM_OPERATIONS_H
lib/libcxx/include/__filesystem/path.h created+1018
......@@ -0,0 +1,1018 @@
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___FILESYSTEM_PATH_H
11#define _LIBCPP___FILESYSTEM_PATH_H
12
13#include <__availability>
14#include <__config>
15#include <__iterator/back_insert_iterator.h>
16#include <__iterator/iterator_traits.h>
17#include <cstddef>
18#include <string>
19#include <string_view>
20#include <type_traits>
21
22#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
23# include <iomanip> // for quoted
24# include <locale>
25#endif
26
27#ifndef _LIBCPP_CXX03_LANG
28
29_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
30
31_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH
32
33template <class _Tp>
34struct __can_convert_char {
35 static const bool value = false;
36};
37template <class _Tp>
38struct __can_convert_char<const _Tp> : public __can_convert_char<_Tp> {};
39template <>
40struct __can_convert_char<char> {
41 static const bool value = true;
42 using __char_type = char;
43};
44template <>
45struct __can_convert_char<wchar_t> {
46 static const bool value = true;
47 using __char_type = wchar_t;
48};
49#ifndef _LIBCPP_HAS_NO_CHAR8_T
50template <>
51struct __can_convert_char<char8_t> {
52 static const bool value = true;
53 using __char_type = char8_t;
54};
55#endif
56template <>
57struct __can_convert_char<char16_t> {
58 static const bool value = true;
59 using __char_type = char16_t;
60};
61template <>
62struct __can_convert_char<char32_t> {
63 static const bool value = true;
64 using __char_type = char32_t;
65};
66
67template <class _ECharT>
68typename enable_if<__can_convert_char<_ECharT>::value, bool>::type
69__is_separator(_ECharT __e) {
70#if defined(_LIBCPP_WIN32API)
71 return __e == _ECharT('/') || __e == _ECharT('\\');
72#else
73 return __e == _ECharT('/');
74#endif
75}
76
77#ifndef _LIBCPP_HAS_NO_CHAR8_T
78typedef u8string __u8_string;
79#else
80typedef string __u8_string;
81#endif
82
83struct _NullSentinel {};
84
85template <class _Tp>
86using _Void = void;
87
88template <class _Tp, class = void>
89struct __is_pathable_string : public false_type {};
90
91template <class _ECharT, class _Traits, class _Alloc>
92struct __is_pathable_string<
93 basic_string<_ECharT, _Traits, _Alloc>,
94 _Void<typename __can_convert_char<_ECharT>::__char_type> >
95 : public __can_convert_char<_ECharT> {
96 using _Str = basic_string<_ECharT, _Traits, _Alloc>;
97 using _Base = __can_convert_char<_ECharT>;
98 static _ECharT const* __range_begin(_Str const& __s) { return __s.data(); }
99 static _ECharT const* __range_end(_Str const& __s) {
100 return __s.data() + __s.length();
101 }
102 static _ECharT __first_or_null(_Str const& __s) {
103 return __s.empty() ? _ECharT{} : __s[0];
104 }
105};
106
107template <class _ECharT, class _Traits>
108struct __is_pathable_string<
109 basic_string_view<_ECharT, _Traits>,
110 _Void<typename __can_convert_char<_ECharT>::__char_type> >
111 : public __can_convert_char<_ECharT> {
112 using _Str = basic_string_view<_ECharT, _Traits>;
113 using _Base = __can_convert_char<_ECharT>;
114 static _ECharT const* __range_begin(_Str const& __s) { return __s.data(); }
115 static _ECharT const* __range_end(_Str const& __s) {
116 return __s.data() + __s.length();
117 }
118 static _ECharT __first_or_null(_Str const& __s) {
119 return __s.empty() ? _ECharT{} : __s[0];
120 }
121};
122
123template <class _Source, class _DS = typename decay<_Source>::type,
124 class _UnqualPtrType =
125 typename remove_const<typename remove_pointer<_DS>::type>::type,
126 bool _IsCharPtr = is_pointer<_DS>::value&&
127 __can_convert_char<_UnqualPtrType>::value>
128struct __is_pathable_char_array : false_type {};
129
130template <class _Source, class _ECharT, class _UPtr>
131struct __is_pathable_char_array<_Source, _ECharT*, _UPtr, true>
132 : __can_convert_char<typename remove_const<_ECharT>::type> {
133 using _Base = __can_convert_char<typename remove_const<_ECharT>::type>;
134
135 static _ECharT const* __range_begin(const _ECharT* __b) { return __b; }
136 static _ECharT const* __range_end(const _ECharT* __b) {
137 using _Iter = const _ECharT*;
138 const _ECharT __sentinel = _ECharT{};
139 _Iter __e = __b;
140 for (; *__e != __sentinel; ++__e)
141 ;
142 return __e;
143 }
144
145 static _ECharT __first_or_null(const _ECharT* __b) { return *__b; }
146};
147
148template <class _Iter, bool _IsIt = __is_cpp17_input_iterator<_Iter>::value,
149 class = void>
150struct __is_pathable_iter : false_type {};
151
152template <class _Iter>
153struct __is_pathable_iter<
154 _Iter, true,
155 _Void<typename __can_convert_char<
156 typename iterator_traits<_Iter>::value_type>::__char_type> >
157 : __can_convert_char<typename iterator_traits<_Iter>::value_type> {
158 using _ECharT = typename iterator_traits<_Iter>::value_type;
159 using _Base = __can_convert_char<_ECharT>;
160
161 static _Iter __range_begin(_Iter __b) { return __b; }
162 static _NullSentinel __range_end(_Iter) { return _NullSentinel{}; }
163
164 static _ECharT __first_or_null(_Iter __b) { return *__b; }
165};
166
167template <class _Tp, bool _IsStringT = __is_pathable_string<_Tp>::value,
168 bool _IsCharIterT = __is_pathable_char_array<_Tp>::value,
169 bool _IsIterT = !_IsCharIterT && __is_pathable_iter<_Tp>::value>
170struct __is_pathable : false_type {
171 static_assert(!_IsStringT && !_IsCharIterT && !_IsIterT, "Must all be false");
172};
173
174template <class _Tp>
175struct __is_pathable<_Tp, true, false, false> : __is_pathable_string<_Tp> {};
176
177template <class _Tp>
178struct __is_pathable<_Tp, false, true, false> : __is_pathable_char_array<_Tp> {
179};
180
181template <class _Tp>
182struct __is_pathable<_Tp, false, false, true> : __is_pathable_iter<_Tp> {};
183
184#if defined(_LIBCPP_WIN32API)
185typedef wstring __path_string;
186typedef wchar_t __path_value;
187#else
188typedef string __path_string;
189typedef char __path_value;
190#endif
191
192#if defined(_LIBCPP_WIN32API)
193_LIBCPP_FUNC_VIS
194size_t __wide_to_char(const wstring&, char*, size_t);
195_LIBCPP_FUNC_VIS
196size_t __char_to_wide(const string&, wchar_t*, size_t);
197#endif
198
199template <class _ECharT>
200struct _PathCVT;
201
202#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
203template <class _ECharT>
204struct _PathCVT {
205 static_assert(__can_convert_char<_ECharT>::value,
206 "Char type not convertible");
207
208 typedef __narrow_to_utf8<sizeof(_ECharT) * __CHAR_BIT__> _Narrower;
209#if defined(_LIBCPP_WIN32API)
210 typedef __widen_from_utf8<sizeof(wchar_t) * __CHAR_BIT__> _Widener;
211#endif
212
213 static void __append_range(__path_string& __dest, _ECharT const* __b,
214 _ECharT const* __e) {
215#if defined(_LIBCPP_WIN32API)
216 string __utf8;
217 _Narrower()(back_inserter(__utf8), __b, __e);
218 _Widener()(back_inserter(__dest), __utf8.data(), __utf8.data() + __utf8.size());
219#else
220 _Narrower()(back_inserter(__dest), __b, __e);
221#endif
222 }
223
224 template <class _Iter>
225 static void __append_range(__path_string& __dest, _Iter __b, _Iter __e) {
226 static_assert(!is_same<_Iter, _ECharT*>::value, "Call const overload");
227 if (__b == __e)
228 return;
229 basic_string<_ECharT> __tmp(__b, __e);
230#if defined(_LIBCPP_WIN32API)
231 string __utf8;
232 _Narrower()(back_inserter(__utf8), __tmp.data(),
233 __tmp.data() + __tmp.length());
234 _Widener()(back_inserter(__dest), __utf8.data(), __utf8.data() + __utf8.size());
235#else
236 _Narrower()(back_inserter(__dest), __tmp.data(),
237 __tmp.data() + __tmp.length());
238#endif
239 }
240
241 template <class _Iter>
242 static void __append_range(__path_string& __dest, _Iter __b, _NullSentinel) {
243 static_assert(!is_same<_Iter, _ECharT*>::value, "Call const overload");
244 const _ECharT __sentinel = _ECharT{};
245 if (*__b == __sentinel)
246 return;
247 basic_string<_ECharT> __tmp;
248 for (; *__b != __sentinel; ++__b)
249 __tmp.push_back(*__b);
250#if defined(_LIBCPP_WIN32API)
251 string __utf8;
252 _Narrower()(back_inserter(__utf8), __tmp.data(),
253 __tmp.data() + __tmp.length());
254 _Widener()(back_inserter(__dest), __utf8.data(), __utf8.data() + __utf8.size());
255#else
256 _Narrower()(back_inserter(__dest), __tmp.data(),
257 __tmp.data() + __tmp.length());
258#endif
259 }
260
261 template <class _Source>
262 static void __append_source(__path_string& __dest, _Source const& __s) {
263 using _Traits = __is_pathable<_Source>;
264 __append_range(__dest, _Traits::__range_begin(__s),
265 _Traits::__range_end(__s));
266 }
267};
268#endif // !_LIBCPP_HAS_NO_LOCALIZATION
269
270template <>
271struct _PathCVT<__path_value> {
272
273 template <class _Iter>
274 static typename enable_if<__is_exactly_cpp17_input_iterator<_Iter>::value>::type
275 __append_range(__path_string& __dest, _Iter __b, _Iter __e) {
276 for (; __b != __e; ++__b)
277 __dest.push_back(*__b);
278 }
279
280 template <class _Iter>
281 static typename enable_if<__is_cpp17_forward_iterator<_Iter>::value>::type
282 __append_range(__path_string& __dest, _Iter __b, _Iter __e) {
283 __dest.append(__b, __e);
284 }
285
286 template <class _Iter>
287 static void __append_range(__path_string& __dest, _Iter __b, _NullSentinel) {
288 const char __sentinel = char{};
289 for (; *__b != __sentinel; ++__b)
290 __dest.push_back(*__b);
291 }
292
293 template <class _Source>
294 static void __append_source(__path_string& __dest, _Source const& __s) {
295 using _Traits = __is_pathable<_Source>;
296 __append_range(__dest, _Traits::__range_begin(__s),
297 _Traits::__range_end(__s));
298 }
299};
300
301#if defined(_LIBCPP_WIN32API)
302template <>
303struct _PathCVT<char> {
304
305 static void
306 __append_string(__path_string& __dest, const basic_string<char> &__str) {
307 size_t __size = __char_to_wide(__str, nullptr, 0);
308 size_t __pos = __dest.size();
309 __dest.resize(__pos + __size);
310 __char_to_wide(__str, const_cast<__path_value*>(__dest.data()) + __pos, __size);
311 }
312
313 template <class _Iter>
314 static typename enable_if<__is_exactly_cpp17_input_iterator<_Iter>::value>::type
315 __append_range(__path_string& __dest, _Iter __b, _Iter __e) {
316 basic_string<char> __tmp(__b, __e);
317 __append_string(__dest, __tmp);
318 }
319
320 template <class _Iter>
321 static typename enable_if<__is_cpp17_forward_iterator<_Iter>::value>::type
322 __append_range(__path_string& __dest, _Iter __b, _Iter __e) {
323 basic_string<char> __tmp(__b, __e);
324 __append_string(__dest, __tmp);
325 }
326
327 template <class _Iter>
328 static void __append_range(__path_string& __dest, _Iter __b, _NullSentinel) {
329 const char __sentinel = char{};
330 basic_string<char> __tmp;
331 for (; *__b != __sentinel; ++__b)
332 __tmp.push_back(*__b);
333 __append_string(__dest, __tmp);
334 }
335
336 template <class _Source>
337 static void __append_source(__path_string& __dest, _Source const& __s) {
338 using _Traits = __is_pathable<_Source>;
339 __append_range(__dest, _Traits::__range_begin(__s),
340 _Traits::__range_end(__s));
341 }
342};
343
344template <class _ECharT>
345struct _PathExport {
346 typedef __narrow_to_utf8<sizeof(wchar_t) * __CHAR_BIT__> _Narrower;
347 typedef __widen_from_utf8<sizeof(_ECharT) * __CHAR_BIT__> _Widener;
348
349 template <class _Str>
350 static void __append(_Str& __dest, const __path_string& __src) {
351 string __utf8;
352 _Narrower()(back_inserter(__utf8), __src.data(), __src.data() + __src.size());
353 _Widener()(back_inserter(__dest), __utf8.data(), __utf8.data() + __utf8.size());
354 }
355};
356
357template <>
358struct _PathExport<char> {
359 template <class _Str>
360 static void __append(_Str& __dest, const __path_string& __src) {
361 size_t __size = __wide_to_char(__src, nullptr, 0);
362 size_t __pos = __dest.size();
363 __dest.resize(__size);
364 __wide_to_char(__src, const_cast<char*>(__dest.data()) + __pos, __size);
365 }
366};
367
368template <>
369struct _PathExport<wchar_t> {
370 template <class _Str>
371 static void __append(_Str& __dest, const __path_string& __src) {
372 __dest.append(__src.begin(), __src.end());
373 }
374};
375
376template <>
377struct _PathExport<char16_t> {
378 template <class _Str>
379 static void __append(_Str& __dest, const __path_string& __src) {
380 __dest.append(__src.begin(), __src.end());
381 }
382};
383
384#ifndef _LIBCPP_HAS_NO_CHAR8_T
385template <>
386struct _PathExport<char8_t> {
387 typedef __narrow_to_utf8<sizeof(wchar_t) * __CHAR_BIT__> _Narrower;
388
389 template <class _Str>
390 static void __append(_Str& __dest, const __path_string& __src) {
391 _Narrower()(back_inserter(__dest), __src.data(), __src.data() + __src.size());
392 }
393};
394#endif /* !_LIBCPP_HAS_NO_CHAR8_T */
395#endif /* _LIBCPP_WIN32API */
396
397class _LIBCPP_TYPE_VIS path {
398 template <class _SourceOrIter, class _Tp = path&>
399 using _EnableIfPathable =
400 typename enable_if<__is_pathable<_SourceOrIter>::value, _Tp>::type;
401
402 template <class _Tp>
403 using _SourceChar = typename __is_pathable<_Tp>::__char_type;
404
405 template <class _Tp>
406 using _SourceCVT = _PathCVT<_SourceChar<_Tp> >;
407
408public:
409#if defined(_LIBCPP_WIN32API)
410 typedef wchar_t value_type;
411 static constexpr value_type preferred_separator = L'\\';
412#else
413 typedef char value_type;
414 static constexpr value_type preferred_separator = '/';
415#endif
416 typedef basic_string<value_type> string_type;
417 typedef basic_string_view<value_type> __string_view;
418
419 enum _LIBCPP_ENUM_VIS format : unsigned char {
420 auto_format,
421 native_format,
422 generic_format
423 };
424
425 // 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
429 : __pn_(_VSTD::move(__p.__pn_)) {}
430
431 _LIBCPP_INLINE_VISIBILITY
432 path(string_type&& __s, format = format::auto_format) noexcept
433 : __pn_(_VSTD::move(__s)) {}
434
435 template <class _Source, class = _EnableIfPathable<_Source, void> >
436 path(const _Source& __src, format = format::auto_format) {
437 _SourceCVT<_Source>::__append_source(__pn_, __src);
438 }
439
440 template <class _InputIt>
441 path(_InputIt __first, _InputIt __last, format = format::auto_format) {
442 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
443 _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
444 }
445
446/*
447#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
448 // TODO Implement locale conversions.
449 template <class _Source, class = _EnableIfPathable<_Source, void> >
450 path(const _Source& __src, const locale& __loc, format = format::auto_format);
451 template <class _InputIt>
452 path(_InputIt __first, _InputIt _last, const locale& __loc,
453 format = format::auto_format);
454#endif
455*/
456
457 _LIBCPP_INLINE_VISIBILITY
458 ~path() = default;
459
460 // assignments
461 _LIBCPP_INLINE_VISIBILITY
462 path& operator=(const path& __p) {
463 __pn_ = __p.__pn_;
464 return *this;
465 }
466
467 _LIBCPP_INLINE_VISIBILITY
468 path& operator=(path&& __p) noexcept {
469 __pn_ = _VSTD::move(__p.__pn_);
470 return *this;
471 }
472
473 _LIBCPP_INLINE_VISIBILITY
474 path& operator=(string_type&& __s) noexcept {
475 __pn_ = _VSTD::move(__s);
476 return *this;
477 }
478
479 _LIBCPP_INLINE_VISIBILITY
480 path& assign(string_type&& __s) noexcept {
481 __pn_ = _VSTD::move(__s);
482 return *this;
483 }
484
485 template <class _Source>
486 _LIBCPP_INLINE_VISIBILITY _EnableIfPathable<_Source>
487 operator=(const _Source& __src) {
488 return this->assign(__src);
489 }
490
491 template <class _Source>
492 _EnableIfPathable<_Source> assign(const _Source& __src) {
493 __pn_.clear();
494 _SourceCVT<_Source>::__append_source(__pn_, __src);
495 return *this;
496 }
497
498 template <class _InputIt>
499 path& assign(_InputIt __first, _InputIt __last) {
500 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
501 __pn_.clear();
502 _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
503 return *this;
504 }
505
506public:
507 // appends
508#if defined(_LIBCPP_WIN32API)
509 path& operator/=(const path& __p) {
510 auto __p_root_name = __p.__root_name();
511 auto __p_root_name_size = __p_root_name.size();
512 if (__p.is_absolute() ||
513 (!__p_root_name.empty() && __p_root_name != __string_view(root_name().__pn_))) {
514 __pn_ = __p.__pn_;
515 return *this;
516 }
517 if (__p.has_root_directory()) {
518 path __root_name_str = root_name();
519 __pn_ = __root_name_str.native();
520 __pn_ += __string_view(__p.__pn_).substr(__p_root_name_size);
521 return *this;
522 }
523 if (has_filename() || (!has_root_directory() && is_absolute()))
524 __pn_ += preferred_separator;
525 __pn_ += __string_view(__p.__pn_).substr(__p_root_name_size);
526 return *this;
527 }
528 template <class _Source>
529 _LIBCPP_INLINE_VISIBILITY _EnableIfPathable<_Source>
530 operator/=(const _Source& __src) {
531 return operator/=(path(__src));
532 }
533
534 template <class _Source>
535 _EnableIfPathable<_Source> append(const _Source& __src) {
536 return operator/=(path(__src));
537 }
538
539 template <class _InputIt>
540 path& append(_InputIt __first, _InputIt __last) {
541 return operator/=(path(__first, __last));
542 }
543#else
544 path& operator/=(const path& __p) {
545 if (__p.is_absolute()) {
546 __pn_ = __p.__pn_;
547 return *this;
548 }
549 if (has_filename())
550 __pn_ += preferred_separator;
551 __pn_ += __p.native();
552 return *this;
553 }
554
555 // FIXME: Use _LIBCPP_DIAGNOSE_WARNING to produce a diagnostic when __src
556 // is known at compile time to be "/' since the user almost certainly intended
557 // to append a separator instead of overwriting the path with "/"
558 template <class _Source>
559 _LIBCPP_INLINE_VISIBILITY _EnableIfPathable<_Source>
560 operator/=(const _Source& __src) {
561 return this->append(__src);
562 }
563
564 template <class _Source>
565 _EnableIfPathable<_Source> append(const _Source& __src) {
566 using _Traits = __is_pathable<_Source>;
567 using _CVT = _PathCVT<_SourceChar<_Source> >;
568 bool __source_is_absolute = __is_separator(_Traits::__first_or_null(__src));
569 if (__source_is_absolute)
570 __pn_.clear();
571 else if (has_filename())
572 __pn_ += preferred_separator;
573 _CVT::__append_source(__pn_, __src);
574 return *this;
575 }
576
577 template <class _InputIt>
578 path& append(_InputIt __first, _InputIt __last) {
579 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
580 static_assert(__can_convert_char<_ItVal>::value, "Must convertible");
581 using _CVT = _PathCVT<_ItVal>;
582 if (__first != __last && __is_separator(*__first))
583 __pn_.clear();
584 else if (has_filename())
585 __pn_ += preferred_separator;
586 _CVT::__append_range(__pn_, __first, __last);
587 return *this;
588 }
589#endif
590
591 // concatenation
592 _LIBCPP_INLINE_VISIBILITY
593 path& operator+=(const path& __x) {
594 __pn_ += __x.__pn_;
595 return *this;
596 }
597
598 _LIBCPP_INLINE_VISIBILITY
599 path& operator+=(const string_type& __x) {
600 __pn_ += __x;
601 return *this;
602 }
603
604 _LIBCPP_INLINE_VISIBILITY
605 path& operator+=(__string_view __x) {
606 __pn_ += __x;
607 return *this;
608 }
609
610 _LIBCPP_INLINE_VISIBILITY
611 path& operator+=(const value_type* __x) {
612 __pn_ += __x;
613 return *this;
614 }
615
616 _LIBCPP_INLINE_VISIBILITY
617 path& operator+=(value_type __x) {
618 __pn_ += __x;
619 return *this;
620 }
621
622 template <class _ECharT>
623 typename enable_if<__can_convert_char<_ECharT>::value, path&>::type
624 operator+=(_ECharT __x) {
625 _PathCVT<_ECharT>::__append_source(__pn_,
626 basic_string_view<_ECharT>(&__x, 1));
627 return *this;
628 }
629
630 template <class _Source>
631 _EnableIfPathable<_Source> operator+=(const _Source& __x) {
632 return this->concat(__x);
633 }
634
635 template <class _Source>
636 _EnableIfPathable<_Source> concat(const _Source& __x) {
637 _SourceCVT<_Source>::__append_source(__pn_, __x);
638 return *this;
639 }
640
641 template <class _InputIt>
642 path& concat(_InputIt __first, _InputIt __last) {
643 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
644 _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
645 return *this;
646 }
647
648 // modifiers
649 _LIBCPP_INLINE_VISIBILITY
650 void clear() noexcept { __pn_.clear(); }
651
652 path& make_preferred() {
653#if defined(_LIBCPP_WIN32API)
654 _VSTD::replace(__pn_.begin(), __pn_.end(), L'/', L'\\');
655#endif
656 return *this;
657 }
658
659 _LIBCPP_INLINE_VISIBILITY
660 path& remove_filename() {
661 auto __fname = __filename();
662 if (!__fname.empty())
663 __pn_.erase(__fname.data() - __pn_.data());
664 return *this;
665 }
666
667 path& replace_filename(const path& __replacement) {
668 remove_filename();
669 return (*this /= __replacement);
670 }
671
672 path& replace_extension(const path& __replacement = path());
673
674 _LIBCPP_INLINE_VISIBILITY
675 void swap(path& __rhs) noexcept { __pn_.swap(__rhs.__pn_); }
676
677 // private helper to allow reserving memory in the path
678 _LIBCPP_INLINE_VISIBILITY
679 void __reserve(size_t __s) { __pn_.reserve(__s); }
680
681 // native format observers
682 _LIBCPP_INLINE_VISIBILITY
683 const string_type& native() const noexcept { return __pn_; }
684
685 _LIBCPP_INLINE_VISIBILITY
686 const value_type* c_str() const noexcept { return __pn_.c_str(); }
687
688 _LIBCPP_INLINE_VISIBILITY operator string_type() const { return __pn_; }
689
690#if defined(_LIBCPP_WIN32API)
691 _LIBCPP_INLINE_VISIBILITY _VSTD::wstring wstring() const { return __pn_; }
692
693 _VSTD::wstring generic_wstring() const {
694 _VSTD::wstring __s;
695 __s.resize(__pn_.size());
696 _VSTD::replace_copy(__pn_.begin(), __pn_.end(), __s.begin(), '\\', '/');
697 return __s;
698 }
699
700#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
701 template <class _ECharT, class _Traits = char_traits<_ECharT>,
702 class _Allocator = allocator<_ECharT> >
703 basic_string<_ECharT, _Traits, _Allocator>
704 string(const _Allocator& __a = _Allocator()) const {
705 using _Str = basic_string<_ECharT, _Traits, _Allocator>;
706 _Str __s(__a);
707 __s.reserve(__pn_.size());
708 _PathExport<_ECharT>::__append(__s, __pn_);
709 return __s;
710 }
711
712 _LIBCPP_INLINE_VISIBILITY _VSTD::string string() const {
713 return string<char>();
714 }
715 _LIBCPP_INLINE_VISIBILITY __u8_string u8string() const {
716 using _CVT = __narrow_to_utf8<sizeof(wchar_t) * __CHAR_BIT__>;
717 __u8_string __s;
718 __s.reserve(__pn_.size());
719 _CVT()(back_inserter(__s), __pn_.data(), __pn_.data() + __pn_.size());
720 return __s;
721 }
722
723 _LIBCPP_INLINE_VISIBILITY _VSTD::u16string u16string() const {
724 return string<char16_t>();
725 }
726 _LIBCPP_INLINE_VISIBILITY _VSTD::u32string u32string() const {
727 return string<char32_t>();
728 }
729
730 // generic format observers
731 template <class _ECharT, class _Traits = char_traits<_ECharT>,
732 class _Allocator = allocator<_ECharT> >
733 basic_string<_ECharT, _Traits, _Allocator>
734 generic_string(const _Allocator& __a = _Allocator()) const {
735 using _Str = basic_string<_ECharT, _Traits, _Allocator>;
736 _Str __s = string<_ECharT, _Traits, _Allocator>(__a);
737 // Note: This (and generic_u8string below) is slightly suboptimal as
738 // it iterates twice over the string; once to convert it to the right
739 // character type, and once to replace path delimiters.
740 _VSTD::replace(__s.begin(), __s.end(),
741 static_cast<_ECharT>('\\'), static_cast<_ECharT>('/'));
742 return __s;
743 }
744
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>(); }
748 __u8_string generic_u8string() const {
749 __u8_string __s = u8string();
750 _VSTD::replace(__s.begin(), __s.end(), '\\', '/');
751 return __s;
752 }
753#endif /* !_LIBCPP_HAS_NO_LOCALIZATION */
754#else /* _LIBCPP_WIN32API */
755
756 _LIBCPP_INLINE_VISIBILITY _VSTD::string string() const { return __pn_; }
757#ifndef _LIBCPP_HAS_NO_CHAR8_T
758 _LIBCPP_INLINE_VISIBILITY _VSTD::u8string u8string() const { return _VSTD::u8string(__pn_.begin(), __pn_.end()); }
759#else
760 _LIBCPP_INLINE_VISIBILITY _VSTD::string u8string() const { return __pn_; }
761#endif
762
763#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
764 template <class _ECharT, class _Traits = char_traits<_ECharT>,
765 class _Allocator = allocator<_ECharT> >
766 basic_string<_ECharT, _Traits, _Allocator>
767 string(const _Allocator& __a = _Allocator()) const {
768 using _CVT = __widen_from_utf8<sizeof(_ECharT) * __CHAR_BIT__>;
769 using _Str = basic_string<_ECharT, _Traits, _Allocator>;
770 _Str __s(__a);
771 __s.reserve(__pn_.size());
772 _CVT()(back_inserter(__s), __pn_.data(), __pn_.data() + __pn_.size());
773 return __s;
774 }
775
776#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
777 _LIBCPP_INLINE_VISIBILITY _VSTD::wstring wstring() const {
778 return string<wchar_t>();
779 }
780#endif
781 _LIBCPP_INLINE_VISIBILITY _VSTD::u16string u16string() const {
782 return string<char16_t>();
783 }
784 _LIBCPP_INLINE_VISIBILITY _VSTD::u32string u32string() const {
785 return string<char32_t>();
786 }
787#endif /* !_LIBCPP_HAS_NO_LOCALIZATION */
788
789 // generic format observers
790 _VSTD::string generic_string() const { return __pn_; }
791#ifndef _LIBCPP_HAS_NO_CHAR8_T
792 _VSTD::u8string generic_u8string() const { return _VSTD::u8string(__pn_.begin(), __pn_.end()); }
793#else
794 _VSTD::string generic_u8string() const { return __pn_; }
795#endif
796
797#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
798 template <class _ECharT, class _Traits = char_traits<_ECharT>,
799 class _Allocator = allocator<_ECharT> >
800 basic_string<_ECharT, _Traits, _Allocator>
801 generic_string(const _Allocator& __a = _Allocator()) const {
802 return string<_ECharT, _Traits, _Allocator>(__a);
803 }
804
805#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
806 _VSTD::wstring generic_wstring() const { return string<wchar_t>(); }
807#endif
808 _VSTD::u16string generic_u16string() const { return string<char16_t>(); }
809 _VSTD::u32string generic_u32string() const { return string<char32_t>(); }
810#endif /* !_LIBCPP_HAS_NO_LOCALIZATION */
811#endif /* !_LIBCPP_WIN32API */
812
813private:
814 int __compare(__string_view) const;
815 __string_view __root_name() const;
816 __string_view __root_directory() const;
817 __string_view __root_path_raw() const;
818 __string_view __relative_path() const;
819 __string_view __parent_path() const;
820 __string_view __filename() const;
821 __string_view __stem() const;
822 __string_view __extension() const;
823
824public:
825 // compare
826 _LIBCPP_INLINE_VISIBILITY int compare(const path& __p) const noexcept {
827 return __compare(__p.__pn_);
828 }
829 _LIBCPP_INLINE_VISIBILITY int compare(const string_type& __s) const {
830 return __compare(__s);
831 }
832 _LIBCPP_INLINE_VISIBILITY int compare(__string_view __s) const {
833 return __compare(__s);
834 }
835 _LIBCPP_INLINE_VISIBILITY int compare(const value_type* __s) const {
836 return __compare(__s);
837 }
838
839 // decomposition
840 _LIBCPP_INLINE_VISIBILITY path root_name() const {
841 return string_type(__root_name());
842 }
843 _LIBCPP_INLINE_VISIBILITY path root_directory() const {
844 return string_type(__root_directory());
845 }
846 _LIBCPP_INLINE_VISIBILITY path root_path() const {
847#if defined(_LIBCPP_WIN32API)
848 return string_type(__root_path_raw());
849#else
850 return root_name().append(string_type(__root_directory()));
851#endif
852 }
853 _LIBCPP_INLINE_VISIBILITY path relative_path() const {
854 return string_type(__relative_path());
855 }
856 _LIBCPP_INLINE_VISIBILITY path parent_path() const {
857 return string_type(__parent_path());
858 }
859 _LIBCPP_INLINE_VISIBILITY path filename() const {
860 return string_type(__filename());
861 }
862 _LIBCPP_INLINE_VISIBILITY path stem() const { return string_type(__stem()); }
863 _LIBCPP_INLINE_VISIBILITY path extension() const {
864 return string_type(__extension());
865 }
866
867 // query
868 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool
869 empty() const noexcept {
870 return __pn_.empty();
871 }
872
873 _LIBCPP_INLINE_VISIBILITY bool has_root_name() const {
874 return !__root_name().empty();
875 }
876 _LIBCPP_INLINE_VISIBILITY bool has_root_directory() const {
877 return !__root_directory().empty();
878 }
879 _LIBCPP_INLINE_VISIBILITY bool has_root_path() const {
880 return !__root_path_raw().empty();
881 }
882 _LIBCPP_INLINE_VISIBILITY bool has_relative_path() const {
883 return !__relative_path().empty();
884 }
885 _LIBCPP_INLINE_VISIBILITY bool has_parent_path() const {
886 return !__parent_path().empty();
887 }
888 _LIBCPP_INLINE_VISIBILITY bool has_filename() const {
889 return !__filename().empty();
890 }
891 _LIBCPP_INLINE_VISIBILITY bool has_stem() const { return !__stem().empty(); }
892 _LIBCPP_INLINE_VISIBILITY bool has_extension() const {
893 return !__extension().empty();
894 }
895
896 _LIBCPP_INLINE_VISIBILITY bool is_absolute() const {
897#if defined(_LIBCPP_WIN32API)
898 __string_view __root_name_str = __root_name();
899 __string_view __root_dir = __root_directory();
900 if (__root_name_str.size() == 2 && __root_name_str[1] == ':') {
901 // A drive letter with no root directory is relative, e.g. x:example.
902 return !__root_dir.empty();
903 }
904 // If no root name, it's relative, e.g. \example is relative to the current drive
905 if (__root_name_str.empty())
906 return false;
907 if (__root_name_str.size() < 3)
908 return false;
909 // A server root name, like \\server, is always absolute
910 if (__root_name_str[0] != '/' && __root_name_str[0] != '\\')
911 return false;
912 if (__root_name_str[1] != '/' && __root_name_str[1] != '\\')
913 return false;
914 // Seems to be a server root name
915 return true;
916#else
917 return has_root_directory();
918#endif
919 }
920 _LIBCPP_INLINE_VISIBILITY bool is_relative() const { return !is_absolute(); }
921
922 // relative paths
923 path lexically_normal() const;
924 path lexically_relative(const path& __base) const;
925
926 _LIBCPP_INLINE_VISIBILITY path lexically_proximate(const path& __base) const {
927 path __result = this->lexically_relative(__base);
928 if (__result.native().empty())
929 return *this;
930 return __result;
931 }
932
933 // iterators
934 class _LIBCPP_TYPE_VIS iterator;
935 typedef iterator const_iterator;
936
937 iterator begin() const;
938 iterator end() const;
939
940#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
941 template <class _CharT, class _Traits>
942 _LIBCPP_INLINE_VISIBILITY friend
943 typename enable_if<is_same<_CharT, value_type>::value &&
944 is_same<_Traits, char_traits<value_type> >::value,
945 basic_ostream<_CharT, _Traits>&>::type
946 operator<<(basic_ostream<_CharT, _Traits>& __os, const path& __p) {
947 __os << _VSTD::__quoted(__p.native());
948 return __os;
949 }
950
951 template <class _CharT, class _Traits>
952 _LIBCPP_INLINE_VISIBILITY friend
953 typename enable_if<!is_same<_CharT, value_type>::value ||
954 !is_same<_Traits, char_traits<value_type> >::value,
955 basic_ostream<_CharT, _Traits>&>::type
956 operator<<(basic_ostream<_CharT, _Traits>& __os, const path& __p) {
957 __os << _VSTD::__quoted(__p.string<_CharT, _Traits>());
958 return __os;
959 }
960
961 template <class _CharT, class _Traits>
962 _LIBCPP_INLINE_VISIBILITY friend basic_istream<_CharT, _Traits>&
963 operator>>(basic_istream<_CharT, _Traits>& __is, path& __p) {
964 basic_string<_CharT, _Traits> __tmp;
965 __is >> __quoted(__tmp);
966 __p = __tmp;
967 return __is;
968 }
969#endif // !_LIBCPP_HAS_NO_LOCALIZATION
970
971 friend _LIBCPP_INLINE_VISIBILITY bool operator==(const path& __lhs, const path& __rhs) noexcept {
972 return __lhs.__compare(__rhs.__pn_) == 0;
973 }
974 friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const path& __lhs, const path& __rhs) noexcept {
975 return __lhs.__compare(__rhs.__pn_) != 0;
976 }
977 friend _LIBCPP_INLINE_VISIBILITY bool operator<(const path& __lhs, const path& __rhs) noexcept {
978 return __lhs.__compare(__rhs.__pn_) < 0;
979 }
980 friend _LIBCPP_INLINE_VISIBILITY bool operator<=(const path& __lhs, const path& __rhs) noexcept {
981 return __lhs.__compare(__rhs.__pn_) <= 0;
982 }
983 friend _LIBCPP_INLINE_VISIBILITY bool operator>(const path& __lhs, const path& __rhs) noexcept {
984 return __lhs.__compare(__rhs.__pn_) > 0;
985 }
986 friend _LIBCPP_INLINE_VISIBILITY bool operator>=(const path& __lhs, const path& __rhs) noexcept {
987 return __lhs.__compare(__rhs.__pn_) >= 0;
988 }
989
990 friend _LIBCPP_INLINE_VISIBILITY path operator/(const path& __lhs,
991 const path& __rhs) {
992 path __result(__lhs);
993 __result /= __rhs;
994 return __result;
995 }
996private:
997 inline _LIBCPP_INLINE_VISIBILITY path&
998 __assign_view(__string_view const& __s) noexcept {
999 __pn_ = string_type(__s);
1000 return *this;
1001 }
1002 string_type __pn_;
1003};
1004
1005inline _LIBCPP_INLINE_VISIBILITY void swap(path& __lhs, path& __rhs) noexcept {
1006 __lhs.swap(__rhs);
1007}
1008
1009_LIBCPP_FUNC_VIS
1010size_t hash_value(const path& __p) noexcept;
1011
1012_LIBCPP_AVAILABILITY_FILESYSTEM_POP
1013
1014_LIBCPP_END_NAMESPACE_FILESYSTEM
1015
1016#endif // _LIBCPP_CXX03_LANG
1017
1018#endif // _LIBCPP___FILESYSTEM_PATH_H
lib/libcxx/include/__filesystem/path_iterator.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
10#ifndef _LIBCPP___FILESYSTEM_PATH_ITERATOR_H
11#define _LIBCPP___FILESYSTEM_PATH_ITERATOR_H
12
13#include <__availability>
14#include <__config>
15#include <__debug>
16#include <__filesystem/path.h>
17#include <__iterator/iterator_traits.h>
18#include <cstddef>
19#include <string>
20#include <string_view>
21
22#ifndef _LIBCPP_CXX03_LANG
23
24_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
25
26_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH
27
28class _LIBCPP_TYPE_VIS path::iterator {
29public:
30 enum _ParserState : unsigned char {
31 _Singular,
32 _BeforeBegin,
33 _InRootName,
34 _InRootDir,
35 _InFilenames,
36 _InTrailingSep,
37 _AtEnd
38 };
39
40public:
41 typedef input_iterator_tag iterator_category;
42 typedef bidirectional_iterator_tag iterator_concept;
43
44 typedef path value_type;
45 typedef ptrdiff_t difference_type;
46 typedef const path* pointer;
47 typedef path reference;
48
49public:
50 _LIBCPP_INLINE_VISIBILITY
51 iterator()
52 : __stashed_elem_(), __path_ptr_(nullptr), __entry_(),
53 __state_(_Singular) {}
54
55 iterator(const iterator&) = default;
56 ~iterator() = default;
57
58 iterator& operator=(const iterator&) = default;
59
60 _LIBCPP_INLINE_VISIBILITY
61 reference operator*() const { return __stashed_elem_; }
62
63 _LIBCPP_INLINE_VISIBILITY
64 pointer operator->() const { return &__stashed_elem_; }
65
66 _LIBCPP_INLINE_VISIBILITY
67 iterator& operator++() {
68 _LIBCPP_ASSERT(__state_ != _Singular,
69 "attempting to increment a singular iterator");
70 _LIBCPP_ASSERT(__state_ != _AtEnd,
71 "attempting to increment the end iterator");
72 return __increment();
73 }
74
75 _LIBCPP_INLINE_VISIBILITY
76 iterator operator++(int) {
77 iterator __it(*this);
78 this->operator++();
79 return __it;
80 }
81
82 _LIBCPP_INLINE_VISIBILITY
83 iterator& operator--() {
84 _LIBCPP_ASSERT(__state_ != _Singular,
85 "attempting to decrement a singular iterator");
86 _LIBCPP_ASSERT(__entry_.data() != __path_ptr_->native().data(),
87 "attempting to decrement the begin iterator");
88 return __decrement();
89 }
90
91 _LIBCPP_INLINE_VISIBILITY
92 iterator operator--(int) {
93 iterator __it(*this);
94 this->operator--();
95 return __it;
96 }
97
98private:
99 friend class path;
100
101 inline _LIBCPP_INLINE_VISIBILITY friend bool operator==(const iterator&,
102 const iterator&);
103
104 iterator& __increment();
105 iterator& __decrement();
106
107 path __stashed_elem_;
108 const path* __path_ptr_;
109 path::__string_view __entry_;
110 _ParserState __state_;
111};
112
113inline _LIBCPP_INLINE_VISIBILITY bool operator==(const path::iterator& __lhs,
114 const path::iterator& __rhs) {
115 return __lhs.__path_ptr_ == __rhs.__path_ptr_ &&
116 __lhs.__entry_.data() == __rhs.__entry_.data();
117}
118
119inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const path::iterator& __lhs,
120 const path::iterator& __rhs) {
121 return !(__lhs == __rhs);
122}
123
124_LIBCPP_AVAILABILITY_FILESYSTEM_POP
125
126_LIBCPP_END_NAMESPACE_FILESYSTEM
127
128#endif // _LIBCPP_CXX03_LANG
129
130#endif // _LIBCPP___FILESYSTEM_PATH_ITERATOR_H
lib/libcxx/include/__filesystem/perm_options.h created+73
......@@ -0,0 +1,73 @@
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___FILESYSTEM_PERM_OPTIONS_H
11#define _LIBCPP___FILESYSTEM_PERM_OPTIONS_H
12
13#include <__availability>
14#include <__config>
15
16#ifndef _LIBCPP_CXX03_LANG
17
18_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
19
20_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH
21
22enum class _LIBCPP_ENUM_VIS perm_options : unsigned char {
23 replace = 1,
24 add = 2,
25 remove = 4,
26 nofollow = 8
27};
28
29_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));
33}
34
35_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));
39}
40
41_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));
45}
46
47_LIBCPP_INLINE_VISIBILITY
48inline constexpr perm_options operator~(perm_options _LHS) {
49 return static_cast<perm_options>(~static_cast<unsigned>(_LHS));
50}
51
52_LIBCPP_INLINE_VISIBILITY
53inline perm_options& operator&=(perm_options& _LHS, perm_options _RHS) {
54 return _LHS = _LHS & _RHS;
55}
56
57_LIBCPP_INLINE_VISIBILITY
58inline perm_options& operator|=(perm_options& _LHS, perm_options _RHS) {
59 return _LHS = _LHS | _RHS;
60}
61
62_LIBCPP_INLINE_VISIBILITY
63inline perm_options& operator^=(perm_options& _LHS, perm_options _RHS) {
64 return _LHS = _LHS ^ _RHS;
65}
66
67_LIBCPP_AVAILABILITY_FILESYSTEM_POP
68
69_LIBCPP_END_NAMESPACE_FILESYSTEM
70
71#endif // _LIBCPP_CXX03_LANG
72
73#endif // _LIBCPP___FILESYSTEM_PERM_OPTIONS_H
lib/libcxx/include/__filesystem/perms.h created+91
......@@ -0,0 +1,91 @@
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___FILESYSTEM_PERMS_H
11#define _LIBCPP___FILESYSTEM_PERMS_H
12
13#include <__availability>
14#include <__config>
15
16#ifndef _LIBCPP_CXX03_LANG
17
18_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
19
20_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH
21
22// On Windows, these permission bits map to one single readonly flag per
23// file, and the executable bit is always returned as set. When setting
24// permissions, as long as the write bit is set for either owner, group or
25// others, the readonly flag is cleared.
26enum class _LIBCPP_ENUM_VIS perms : unsigned {
27 none = 0,
28
29 owner_read = 0400,
30 owner_write = 0200,
31 owner_exec = 0100,
32 owner_all = 0700,
33
34 group_read = 040,
35 group_write = 020,
36 group_exec = 010,
37 group_all = 070,
38
39 others_read = 04,
40 others_write = 02,
41 others_exec = 01,
42 others_all = 07,
43
44 all = 0777,
45
46 set_uid = 04000,
47 set_gid = 02000,
48 sticky_bit = 01000,
49 mask = 07777,
50 unknown = 0xFFFF,
51};
52
53_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));
57}
58
59_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));
63}
64
65_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));
69}
70
71_LIBCPP_INLINE_VISIBILITY
72inline constexpr perms operator~(perms _LHS) {
73 return static_cast<perms>(~static_cast<unsigned>(_LHS));
74}
75
76_LIBCPP_INLINE_VISIBILITY
77inline perms& operator&=(perms& _LHS, perms _RHS) { return _LHS = _LHS & _RHS; }
78
79_LIBCPP_INLINE_VISIBILITY
80inline perms& operator|=(perms& _LHS, perms _RHS) { return _LHS = _LHS | _RHS; }
81
82_LIBCPP_INLINE_VISIBILITY
83inline perms& operator^=(perms& _LHS, perms _RHS) { return _LHS = _LHS ^ _RHS; }
84
85_LIBCPP_AVAILABILITY_FILESYSTEM_POP
86
87_LIBCPP_END_NAMESPACE_FILESYSTEM
88
89#endif // _LIBCPP_CXX03_LANG
90
91#endif // _LIBCPP___FILESYSTEM_PERMS_H
lib/libcxx/include/__filesystem/recursive_directory_iterator.h created+181
......@@ -0,0 +1,181 @@
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___FILESYSTEM_RECURSIVE_DIRECTORY_ITERATOR_H
11#define _LIBCPP___FILESYSTEM_RECURSIVE_DIRECTORY_ITERATOR_H
12
13#include <__availability>
14#include <__config>
15#include <__filesystem/directory_entry.h>
16#include <__filesystem/directory_options.h>
17#include <__filesystem/path.h>
18#include <__iterator/iterator_traits.h>
19#include <__memory/shared_ptr.h>
20#include <__ranges/enable_borrowed_range.h>
21#include <__ranges/enable_view.h>
22#include <cstddef>
23#include <system_error>
24
25#ifndef _LIBCPP_CXX03_LANG
26
27_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
28
29_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH
30
31class recursive_directory_iterator {
32public:
33 using value_type = directory_entry;
34 using difference_type = ptrdiff_t;
35 using pointer = directory_entry const*;
36 using reference = directory_entry const&;
37 using iterator_category = input_iterator_tag;
38
39public:
40 // constructors and destructor
41 _LIBCPP_INLINE_VISIBILITY
42 recursive_directory_iterator() noexcept : __rec_(false) {}
43
44 _LIBCPP_INLINE_VISIBILITY
45 explicit recursive_directory_iterator(
46 const path& __p, directory_options __xoptions = directory_options::none)
47 : recursive_directory_iterator(__p, __xoptions, nullptr) {}
48
49 _LIBCPP_INLINE_VISIBILITY
50 recursive_directory_iterator(const path& __p, directory_options __xoptions,
51 error_code& __ec)
52 : recursive_directory_iterator(__p, __xoptions, &__ec) {}
53
54 _LIBCPP_INLINE_VISIBILITY
55 recursive_directory_iterator(const path& __p, error_code& __ec)
56 : recursive_directory_iterator(__p, directory_options::none, &__ec) {}
57
58 recursive_directory_iterator(const recursive_directory_iterator&) = default;
59 recursive_directory_iterator(recursive_directory_iterator&&) = default;
60
61 recursive_directory_iterator&
62 operator=(const recursive_directory_iterator&) = default;
63
64 _LIBCPP_INLINE_VISIBILITY
65 recursive_directory_iterator&
66 operator=(recursive_directory_iterator&& __o) noexcept {
67 // non-default implementation provided to support self-move assign.
68 if (this != &__o) {
69 __imp_ = _VSTD::move(__o.__imp_);
70 __rec_ = __o.__rec_;
71 }
72 return *this;
73 }
74
75 ~recursive_directory_iterator() = default;
76
77 _LIBCPP_INLINE_VISIBILITY
78 const directory_entry& operator*() const { return __dereference(); }
79
80 _LIBCPP_INLINE_VISIBILITY
81 const directory_entry* operator->() const { return &__dereference(); }
82
83 recursive_directory_iterator& operator++() { return __increment(); }
84
85 _LIBCPP_INLINE_VISIBILITY
86 __dir_element_proxy operator++(int) {
87 __dir_element_proxy __p(**this);
88 __increment();
89 return __p;
90 }
91
92 _LIBCPP_INLINE_VISIBILITY
93 recursive_directory_iterator& increment(error_code& __ec) {
94 return __increment(&__ec);
95 }
96
97 _LIBCPP_FUNC_VIS directory_options options() const;
98 _LIBCPP_FUNC_VIS int depth() const;
99
100 _LIBCPP_INLINE_VISIBILITY
101 void pop() { __pop(); }
102
103 _LIBCPP_INLINE_VISIBILITY
104 void pop(error_code& __ec) { __pop(&__ec); }
105
106 _LIBCPP_INLINE_VISIBILITY
107 bool recursion_pending() const { return __rec_; }
108
109 _LIBCPP_INLINE_VISIBILITY
110 void disable_recursion_pending() { __rec_ = false; }
111
112private:
113 _LIBCPP_FUNC_VIS
114 recursive_directory_iterator(const path& __p, directory_options __opt,
115 error_code* __ec);
116
117 _LIBCPP_FUNC_VIS
118 const directory_entry& __dereference() const;
119
120 _LIBCPP_FUNC_VIS
121 bool __try_recursion(error_code* __ec);
122
123 _LIBCPP_FUNC_VIS
124 void __advance(error_code* __ec = nullptr);
125
126 _LIBCPP_FUNC_VIS
127 recursive_directory_iterator& __increment(error_code* __ec = nullptr);
128
129 _LIBCPP_FUNC_VIS
130 void __pop(error_code* __ec = nullptr);
131
132 inline _LIBCPP_INLINE_VISIBILITY friend bool
133 operator==(const recursive_directory_iterator&,
134 const recursive_directory_iterator&) noexcept;
135
136 struct _LIBCPP_HIDDEN __shared_imp;
137 shared_ptr<__shared_imp> __imp_;
138 bool __rec_;
139}; // class recursive_directory_iterator
140
141inline _LIBCPP_INLINE_VISIBILITY bool
142operator==(const recursive_directory_iterator& __lhs,
143 const recursive_directory_iterator& __rhs) noexcept {
144 return __lhs.__imp_ == __rhs.__imp_;
145}
146
147_LIBCPP_INLINE_VISIBILITY
148inline bool operator!=(const recursive_directory_iterator& __lhs,
149 const recursive_directory_iterator& __rhs) noexcept {
150 return !(__lhs == __rhs);
151}
152// enable recursive_directory_iterator range-based for statements
153inline _LIBCPP_INLINE_VISIBILITY recursive_directory_iterator
154begin(recursive_directory_iterator __iter) noexcept {
155 return __iter;
156}
157
158inline _LIBCPP_INLINE_VISIBILITY recursive_directory_iterator
159end(recursive_directory_iterator) noexcept {
160 return recursive_directory_iterator();
161}
162
163_LIBCPP_AVAILABILITY_FILESYSTEM_POP
164
165_LIBCPP_END_NAMESPACE_FILESYSTEM
166
167#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
168
169template <>
170_LIBCPP_AVAILABILITY_FILESYSTEM
171inline constexpr bool _VSTD::ranges::enable_borrowed_range<_VSTD_FS::recursive_directory_iterator> = true;
172
173template <>
174_LIBCPP_AVAILABILITY_FILESYSTEM
175inline constexpr bool _VSTD::ranges::enable_view<_VSTD_FS::recursive_directory_iterator> = true;
176
177#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
178
179#endif // _LIBCPP_CXX03_LANG
180
181#endif // _LIBCPP___FILESYSTEM_RECURSIVE_DIRECTORY_ITERATOR_H
lib/libcxx/include/__filesystem/space_info.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___FILESYSTEM_SPACE_INFO_H
11#define _LIBCPP___FILESYSTEM_SPACE_INFO_H
12
13#include <__availability>
14#include <__config>
15#include <cstdint>
16
17#ifndef _LIBCPP_CXX03_LANG
18
19_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
20
21_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH
22
23struct _LIBCPP_TYPE_VIS space_info {
24 uintmax_t capacity;
25 uintmax_t free;
26 uintmax_t available;
27};
28
29_LIBCPP_AVAILABILITY_FILESYSTEM_POP
30
31_LIBCPP_END_NAMESPACE_FILESYSTEM
32
33#endif // _LIBCPP_CXX03_LANG
34
35#endif // _LIBCPP___FILESYSTEM_SPACE_INFO_H
lib/libcxx/include/__filesystem/u8path.h created+96
......@@ -0,0 +1,96 @@
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___FILESYSTEM_U8PATH_H
11#define _LIBCPP___FILESYSTEM_U8PATH_H
12
13#include <__availability>
14#include <__config>
15#include <__filesystem/path.h>
16#include <type_traits>
17
18#ifndef _LIBCPP_CXX03_LANG
19
20_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
21
22_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH
23
24template <class _InputIt>
25_LIBCPP_INLINE_VISIBILITY _LIBCPP_DEPRECATED_WITH_CHAR8_T
26 typename enable_if<__is_pathable<_InputIt>::value, path>::type
27 u8path(_InputIt __f, _InputIt __l) {
28 static_assert(
29#ifndef _LIBCPP_HAS_NO_CHAR8_T
30 is_same<typename __is_pathable<_InputIt>::__char_type, char8_t>::value ||
31#endif
32 is_same<typename __is_pathable<_InputIt>::__char_type, char>::value,
33 "u8path(Iter, Iter) requires Iter have a value_type of type 'char'"
34 " or 'char8_t'");
35#if defined(_LIBCPP_WIN32API)
36 string __tmp(__f, __l);
37 using _CVT = __widen_from_utf8<sizeof(wchar_t) * __CHAR_BIT__>;
38 _VSTD::wstring __w;
39 __w.reserve(__tmp.size());
40 _CVT()(back_inserter(__w), __tmp.data(), __tmp.data() + __tmp.size());
41 return path(__w);
42#else
43 return path(__f, __l);
44#endif /* !_LIBCPP_WIN32API */
45}
46
47#if defined(_LIBCPP_WIN32API)
48template <class _InputIt>
49_LIBCPP_INLINE_VISIBILITY _LIBCPP_DEPRECATED_WITH_CHAR8_T
50 typename enable_if<__is_pathable<_InputIt>::value, path>::type
51 u8path(_InputIt __f, _NullSentinel) {
52 static_assert(
53#ifndef _LIBCPP_HAS_NO_CHAR8_T
54 is_same<typename __is_pathable<_InputIt>::__char_type, char8_t>::value ||
55#endif
56 is_same<typename __is_pathable<_InputIt>::__char_type, char>::value,
57 "u8path(Iter, Iter) requires Iter have a value_type of type 'char'"
58 " or 'char8_t'");
59 string __tmp;
60 const char __sentinel = char{};
61 for (; *__f != __sentinel; ++__f)
62 __tmp.push_back(*__f);
63 using _CVT = __widen_from_utf8<sizeof(wchar_t) * __CHAR_BIT__>;
64 _VSTD::wstring __w;
65 __w.reserve(__tmp.size());
66 _CVT()(back_inserter(__w), __tmp.data(), __tmp.data() + __tmp.size());
67 return path(__w);
68}
69#endif /* _LIBCPP_WIN32API */
70
71template <class _Source>
72_LIBCPP_INLINE_VISIBILITY _LIBCPP_DEPRECATED_WITH_CHAR8_T
73 typename enable_if<__is_pathable<_Source>::value, path>::type
74 u8path(const _Source& __s) {
75 static_assert(
76#ifndef _LIBCPP_HAS_NO_CHAR8_T
77 is_same<typename __is_pathable<_Source>::__char_type, char8_t>::value ||
78#endif
79 is_same<typename __is_pathable<_Source>::__char_type, char>::value,
80 "u8path(Source const&) requires Source have a character type of type "
81 "'char' or 'char8_t'");
82#if defined(_LIBCPP_WIN32API)
83 using _Traits = __is_pathable<_Source>;
84 return u8path(_VSTD::__unwrap_iter(_Traits::__range_begin(__s)), _VSTD::__unwrap_iter(_Traits::__range_end(__s)));
85#else
86 return path(__s);
87#endif
88}
89
90_LIBCPP_AVAILABILITY_FILESYSTEM_POP
91
92_LIBCPP_END_NAMESPACE_FILESYSTEM
93
94#endif // _LIBCPP_CXX03_LANG
95
96#endif // _LIBCPP___FILESYSTEM_U8PATH_H
lib/libcxx/include/__format/format_arg.h created+292
......@@ -0,0 +1,292 @@
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_H
11#define _LIBCPP___FORMAT_FORMAT_ARG_H
12
13#include <__concepts/arithmetic.h>
14#include <__config>
15#include <__format/format_error.h>
16#include <__format/format_fwd.h>
17#include <__format/format_parse_context.h>
18#include <__functional_base>
19#include <__memory/addressof.h>
20#include <__variant/monostate.h>
21#include <string>
22#include <string_view>
23
24#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
25#pragma GCC system_header
26#endif
27
28_LIBCPP_PUSH_MACROS
29#include <__undef_macros>
30
31_LIBCPP_BEGIN_NAMESPACE_STD
32
33#if _LIBCPP_STD_VER > 17
34
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
41namespace __format {
42/// The type stored in @ref basic_format_arg.
43///
44/// @note The 128-bit types are unconditionally in the list to avoid the values
45/// of the enums to depend on the availability of 128-bit integers.
46enum class _LIBCPP_ENUM_VIS __arg_t : uint8_t {
47 __none,
48 __boolean,
49 __char_type,
50 __int,
51 __long_long,
52 __i128,
53 __unsigned,
54 __unsigned_long_long,
55 __u128,
56 __float,
57 __double,
58 __long_double,
59 __const_char_type_ptr,
60 __string_view,
61 __ptr,
62 __handle
63};
64} // namespace __format
65
66template <class _Visitor, class _Context>
67_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT decltype(auto)
68visit_format_arg(_Visitor&& __vis, basic_format_arg<_Context> __arg) {
69 switch (__arg.__type_) {
70 case __format::__arg_t::__none:
71 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), monostate{});
72 case __format::__arg_t::__boolean:
73 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__boolean);
74 case __format::__arg_t::__char_type:
75 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__char_type);
76 case __format::__arg_t::__int:
77 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__int);
78 case __format::__arg_t::__long_long:
79 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__long_long);
80 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
86 case __format::__arg_t::__unsigned:
87 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__unsigned);
88 case __format::__arg_t::__unsigned_long_long:
89 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis),
90 __arg.__unsigned_long_long);
91 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
97 case __format::__arg_t::__float:
98 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__float);
99 case __format::__arg_t::__double:
100 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__double);
101 case __format::__arg_t::__long_double:
102 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__long_double);
103 case __format::__arg_t::__const_char_type_ptr:
104 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis),
105 __arg.__const_char_type_ptr);
106 case __format::__arg_t::__string_view:
107 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__string_view);
108 case __format::__arg_t::__ptr:
109 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__ptr);
110 case __format::__arg_t::__handle:
111 return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__handle);
112 }
113 _LIBCPP_UNREACHABLE();
114}
115
116template <class _Context>
117class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT basic_format_arg {
118public:
119 class _LIBCPP_TEMPLATE_VIS handle;
120
121 _LIBCPP_HIDE_FROM_ABI basic_format_arg() noexcept
122 : __type_{__format::__arg_t::__none} {}
123
124 _LIBCPP_HIDE_FROM_ABI explicit operator bool() const noexcept {
125 return __type_ != __format::__arg_t::__none;
126 }
127
128private:
129 using char_type = typename _Context::char_type;
130
131 // TODO FMT Implement constrain [format.arg]/4
132 // Constraints: The template specialization
133 // typename Context::template formatter_type<T>
134 // meets the Formatter requirements ([formatter.requirements]). The extent
135 // to which an implementation determines that the specialization meets the
136 // Formatter requirements is unspecified, except that as a minimum the
137 // expression
138 // typename Context::template formatter_type<T>()
139 // .format(declval<const T&>(), declval<Context&>())
140 // shall be well-formed when treated as an unevaluated operand.
141
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 };
169 __format::__arg_t __type_;
170
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) {}
258};
259
260template <class _Context>
261class _LIBCPP_TEMPLATE_VIS basic_format_arg<_Context>::handle {
262 friend class basic_format_arg<_Context>;
263
264public:
265 _LIBCPP_HIDE_FROM_ABI
266 void format(basic_format_parse_context<char_type>& __parse_ctx, _Context& __ctx) const {
267 __format_(__parse_ctx, __ctx, __ptr_);
268 }
269
270private:
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 }) {}
282};
283
284#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
285
286#endif //_LIBCPP_STD_VER > 17
287
288_LIBCPP_END_NAMESPACE_STD
289
290_LIBCPP_POP_MACROS
291
292#endif // _LIBCPP___FORMAT_FORMAT_ARG_H
lib/libcxx/include/__format/format_args.h created+71
......@@ -0,0 +1,71 @@
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_ARGS_H
11#define _LIBCPP___FORMAT_FORMAT_ARGS_H
12
13#include <__availability>
14#include <__config>
15#include <__format/format_fwd.h>
16#include <cstddef>
17
18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
20#endif
21
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
25_LIBCPP_BEGIN_NAMESPACE_STD
26
27#if _LIBCPP_STD_VER > 17
28
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
35template <class _Context>
36class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT basic_format_args {
37public:
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.
44 _LIBCPP_HIDE_FROM_ABI basic_format_args() noexcept = default;
45
46 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()) {}
50
51 _LIBCPP_HIDE_FROM_ABI
52 basic_format_arg<_Context> get(size_t __id) const noexcept {
53 return __id < __size_ ? __data_[__id] : basic_format_arg<_Context>{};
54 }
55
56 _LIBCPP_HIDE_FROM_ABI size_t __size() const noexcept { return __size_; }
57
58private:
59 size_t __size_{0};
60 const basic_format_arg<_Context>* __data_{nullptr};
61};
62
63#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
64
65#endif //_LIBCPP_STD_VER > 17
66
67_LIBCPP_END_NAMESPACE_STD
68
69_LIBCPP_POP_MACROS
70
71#endif // _LIBCPP___FORMAT_FORMAT_ARGS_H
lib/libcxx/include/__format/format_context.h created+165
......@@ -0,0 +1,165 @@
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_CONTEXT_H
11#define _LIBCPP___FORMAT_FORMAT_CONTEXT_H
12
13#include <__availability>
14#include <__config>
15#include <__format/format_args.h>
16#include <__format/format_fwd.h>
17#include <__iterator/back_insert_iterator.h>
18#include <__iterator/concepts.h>
19#include <concepts>
20
21#ifndef _LIBCPP_HAS_NO_LOCALIZATION
22#include <locale>
23#include <optional>
24#endif
25
26#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
27#pragma GCC system_header
28#endif
29
30_LIBCPP_PUSH_MACROS
31#include <__undef_macros>
32
33_LIBCPP_BEGIN_NAMESPACE_STD
34
35#if _LIBCPP_STD_VER > 17
36
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
43template <class _OutIt, class _CharT>
44requires output_iterator<_OutIt, const _CharT&>
45class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT basic_format_context;
46
47#ifndef _LIBCPP_HAS_NO_LOCALIZATION
48/**
49 * Helper to create a basic_format_context.
50 *
51 * This is needed since the constructor is private.
52 */
53template <class _OutIt, class _CharT>
54_LIBCPP_HIDE_FROM_ABI basic_format_context<_OutIt, _CharT>
55__format_context_create(
56 _OutIt __out_it,
57 basic_format_args<basic_format_context<_OutIt, _CharT>> __args,
58 optional<_VSTD::locale>&& __loc = nullopt) {
59 return _VSTD::basic_format_context(_VSTD::move(__out_it), __args,
60 _VSTD::move(__loc));
61}
62#else
63template <class _OutIt, class _CharT>
64_LIBCPP_HIDE_FROM_ABI basic_format_context<_OutIt, _CharT>
65__format_context_create(
66 _OutIt __out_it,
67 basic_format_args<basic_format_context<_OutIt, _CharT>> __args) {
68 return _VSTD::basic_format_context(_VSTD::move(__out_it), __args);
69}
70#endif
71
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>;
80#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
81using wformat_context = basic_format_context<back_insert_iterator<wstring>, wchar_t>;
82#endif
83
84template <class _OutIt, class _CharT>
85requires output_iterator<_OutIt, const _CharT&>
86class
87 // clang-format off
88 _LIBCPP_TEMPLATE_VIS
89 _LIBCPP_AVAILABILITY_FORMAT
90 _LIBCPP_PREFERRED_NAME(format_context)
91 _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wformat_context))
92 // clang-format on
93 basic_format_context {
94public:
95 using iterator = _OutIt;
96 using char_type = _CharT;
97 template <class _Tp>
98 using formatter_type = formatter<_Tp, _CharT>;
99
100 basic_format_context(const basic_format_context&) = delete;
101 basic_format_context& operator=(const basic_format_context&) = delete;
102
103 _LIBCPP_HIDE_FROM_ABI basic_format_arg<basic_format_context>
104 arg(size_t __id) const {
105 return __args_.get(__id);
106 }
107#ifndef _LIBCPP_HAS_NO_LOCALIZATION
108 _LIBCPP_HIDE_FROM_ABI _VSTD::locale locale() {
109 if (!__loc_)
110 __loc_ = _VSTD::locale{};
111 return *__loc_;
112 }
113#endif
114 _LIBCPP_HIDE_FROM_ABI iterator out() { return __out_it_; }
115 _LIBCPP_HIDE_FROM_ABI void advance_to(iterator __it) { __out_it_ = __it; }
116
117private:
118 iterator __out_it_;
119 basic_format_args<basic_format_context> __args_;
120#ifndef _LIBCPP_HAS_NO_LOCALIZATION
121
122 // The Standard doesn't specify how the locale is stored.
123 // [format.context]/6
124 // std::locale locale();
125 // Returns: The locale passed to the formatting function if the latter
126 // takes one, and std::locale() otherwise.
127 // This is done by storing the locale of the constructor in this optional. If
128 // locale() is called and the optional has no value the value will be created.
129 // This allows the implementation to lazily create the locale.
130 // TODO FMT Validate whether lazy creation is the best solution.
131 optional<_VSTD::locale> __loc_;
132
133 template <class __OutIt, class __CharT>
134 friend _LIBCPP_HIDE_FROM_ABI basic_format_context<__OutIt, __CharT>
135 __format_context_create(__OutIt, basic_format_args<basic_format_context<__OutIt, __CharT>>,
136 optional<_VSTD::locale>&&);
137
138 // Note: the Standard doesn't specify the required constructors.
139 _LIBCPP_HIDE_FROM_ABI
140 explicit basic_format_context(_OutIt __out_it,
141 basic_format_args<basic_format_context> __args,
142 optional<_VSTD::locale>&& __loc)
143 : __out_it_(_VSTD::move(__out_it)), __args_(__args),
144 __loc_(_VSTD::move(__loc)) {}
145#else
146 template <class __OutIt, class __CharT>
147 friend _LIBCPP_HIDE_FROM_ABI basic_format_context<__OutIt, __CharT>
148 __format_context_create(__OutIt, basic_format_args<basic_format_context<__OutIt, __CharT>>);
149
150 _LIBCPP_HIDE_FROM_ABI
151 explicit basic_format_context(_OutIt __out_it,
152 basic_format_args<basic_format_context> __args)
153 : __out_it_(_VSTD::move(__out_it)), __args_(__args) {}
154#endif
155};
156
157#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
158
159#endif //_LIBCPP_STD_VER > 17
160
161_LIBCPP_END_NAMESPACE_STD
162
163_LIBCPP_POP_MACROS
164
165#endif // _LIBCPP___FORMAT_FORMAT_CONTEXT_H
lib/libcxx/include/__format/format_error.h-5
......@@ -21,9 +21,6 @@
2121#pragma GCC system_header
2222#endif
2323
24_LIBCPP_PUSH_MACROS
25#include <__undef_macros>
26
2724_LIBCPP_BEGIN_NAMESPACE_STD
2825
2926#if _LIBCPP_STD_VER > 17
......@@ -51,6 +48,4 @@ __throw_format_error(const char* __s) {
5148
5249_LIBCPP_END_NAMESPACE_STD
5350
54_LIBCPP_POP_MACROS
55
5651#endif // _LIBCPP___FORMAT_FORMAT_ERROR_H
lib/libcxx/include/__format/format_fwd.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___FORMAT_FORMAT_FWD_H
11#define _LIBCPP___FORMAT_FORMAT_FWD_H
12
13#include <__availability>
14#include <__config>
15#include <__iterator/concepts.h>
16#include <__utility/forward.h>
17
18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
20#endif
21
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
25_LIBCPP_BEGIN_NAMESPACE_STD
26
27#if _LIBCPP_STD_VER > 17
28
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
35template <class _Context>
36class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT basic_format_arg;
37
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&...);
44
45template <class _Tp, class _CharT = char>
46struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter;
47
48#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
49
50#endif //_LIBCPP_STD_VER > 17
51
52_LIBCPP_END_NAMESPACE_STD
53
54_LIBCPP_POP_MACROS
55
56#endif // _LIBCPP___FORMAT_FORMAT_FWD_H
lib/libcxx/include/__format/format_parse_context.h+4-8
......@@ -18,9 +18,6 @@
1818#pragma GCC system_header
1919#endif
2020
21_LIBCPP_PUSH_MACROS
22#include <__undef_macros>
23
2421_LIBCPP_BEGIN_NAMESPACE_STD
2522
2623#if _LIBCPP_STD_VER > 17
......@@ -29,8 +26,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2926// If the compiler has no concepts support, the format header will be disabled.
3027// Without concepts support enable_if needs to be used and that too much effort
3128// to support compilers with partial C++20 support.
32#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && \
33 !defined(_LIBCPP_HAS_NO_BUILTIN_IS_CONSTANT_EVALUATED)
29#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
3430
3531template <class _CharT>
3632class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT basic_format_parse_context {
......@@ -100,14 +96,14 @@ private:
10096};
10197
10298using format_parse_context = basic_format_parse_context<char>;
99#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
103100using wformat_parse_context = basic_format_parse_context<wchar_t>;
101#endif
104102
105#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_BUILTIN_IS_CONSTANT_EVALUATED)
103#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
106104
107105#endif //_LIBCPP_STD_VER > 17
108106
109107_LIBCPP_END_NAMESPACE_STD
110108
111_LIBCPP_POP_MACROS
112
113109#endif // _LIBCPP___FORMAT_FORMAT_PARSE_CONTEXT_H
lib/libcxx/include/__format/format_string.h created+169
......@@ -0,0 +1,169 @@
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_STRING_H
11#define _LIBCPP___FORMAT_FORMAT_STRING_H
12
13#include <__config>
14#include <__debug>
15#include <__format/format_error.h>
16#include <cstddef>
17#include <cstdint>
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// 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
33namespace __format {
34
35template <class _CharT>
36struct _LIBCPP_TEMPLATE_VIS __parse_number_result {
37 const _CharT* __ptr;
38 uint32_t __value;
39};
40
41template <class _CharT>
42_LIBCPP_HIDE_FROM_ABI constexpr __parse_number_result<_CharT>
43__parse_number(const _CharT* __begin, const _CharT* __end);
44
45/**
46 * The maximum value of a numeric argument.
47 *
48 * This is used for:
49 * * arg-id
50 * * width as value or arg-id.
51 * * precision as value or arg-id.
52 *
53 * The value is compatible with the maximum formatting width and precision
54 * using the `%*` syntax on a 32-bit system.
55 */
56inline constexpr uint32_t __number_max = INT32_MAX;
57
58namespace __detail {
59template <class _CharT>
60_LIBCPP_HIDE_FROM_ABI constexpr __parse_number_result<_CharT>
61__parse_zero(const _CharT* __begin, const _CharT*, auto& __parse_ctx) {
62 __parse_ctx.check_arg_id(0);
63 return {++__begin, 0}; // can never be larger than the maximum.
64}
65
66template <class _CharT>
67_LIBCPP_HIDE_FROM_ABI constexpr __parse_number_result<_CharT>
68__parse_automatic(const _CharT* __begin, const _CharT*, auto& __parse_ctx) {
69 size_t __value = __parse_ctx.next_arg_id();
70 _LIBCPP_ASSERT(__value <= __number_max,
71 "Compilers don't support this number of arguments");
72
73 return {__begin, uint32_t(__value)};
74}
75
76template <class _CharT>
77_LIBCPP_HIDE_FROM_ABI constexpr __parse_number_result<_CharT>
78__parse_manual(const _CharT* __begin, const _CharT* __end, auto& __parse_ctx) {
79 __parse_number_result<_CharT> __r = __parse_number(__begin, __end);
80 __parse_ctx.check_arg_id(__r.__value);
81 return __r;
82}
83
84} // namespace __detail
85
86/**
87 * Parses a number.
88 *
89 * The number is used for the 31-bit values @em width and @em precision. This
90 * allows a maximum value of 2147483647.
91 */
92template <class _CharT>
93_LIBCPP_HIDE_FROM_ABI constexpr __parse_number_result<_CharT>
94__parse_number(const _CharT* __begin, const _CharT* __end_input) {
95 static_assert(__format::__number_max == INT32_MAX,
96 "The algorithm is implemented based on this value.");
97 /*
98 * Limit the input to 9 digits, otherwise we need two checks during every
99 * iteration:
100 * - Are we at the end of the input?
101 * - Does the value exceed width of an uint32_t? (Switching to uint64_t would
102 * have the same issue, but with a higher maximum.)
103 */
104 const _CharT* __end = __end_input - __begin > 9 ? __begin + 9 : __end_input;
105 uint32_t __value = *__begin - _CharT('0');
106 while (++__begin != __end) {
107 if (*__begin < _CharT('0') || *__begin > _CharT('9'))
108 return {__begin, __value};
109
110 __value = __value * 10 + *__begin - _CharT('0');
111 }
112
113 if (__begin != __end_input && *__begin >= _CharT('0') &&
114 *__begin <= _CharT('9')) {
115
116 /*
117 * There are more than 9 digits, do additional validations:
118 * - Does the 10th digit exceed the maximum allowed value?
119 * - Are there more than 10 digits?
120 * (More than 10 digits always overflows the maximum.)
121 */
122 uint64_t __v = uint64_t(__value) * 10 + *__begin++ - _CharT('0');
123 if (__v > __number_max ||
124 (__begin != __end_input && *__begin >= _CharT('0') &&
125 *__begin <= _CharT('9')))
126 __throw_format_error("The numeric value of the format-spec is too large");
127
128 __value = __v;
129 }
130
131 return {__begin, __value};
132}
133
134/**
135 * Multiplexer for all parse functions.
136 *
137 * The parser will return a pointer beyond the last consumed character. This
138 * should be the closing '}' of the arg-id.
139 */
140template <class _CharT>
141_LIBCPP_HIDE_FROM_ABI constexpr __parse_number_result<_CharT>
142__parse_arg_id(const _CharT* __begin, const _CharT* __end, auto& __parse_ctx) {
143 switch (*__begin) {
144 case _CharT('0'):
145 return __detail::__parse_zero(__begin, __end, __parse_ctx);
146
147 case _CharT(':'):
148 // This case is conditionally valid. It's allowed in an arg-id in the
149 // replacement-field, but not in the std-format-spec. The caller can
150 // provide a better diagnostic, so accept it here unconditionally.
151 case _CharT('}'):
152 return __detail::__parse_automatic(__begin, __end, __parse_ctx);
153 }
154 if (*__begin < _CharT('0') || *__begin > _CharT('9'))
155 __throw_format_error(
156 "The arg-id of the format-spec starts with an invalid character");
157
158 return __detail::__parse_manual(__begin, __end, __parse_ctx);
159}
160
161} // namespace __format
162
163#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
164
165#endif //_LIBCPP_STD_VER > 17
166
167_LIBCPP_END_NAMESPACE_STD
168
169#endif // _LIBCPP___FORMAT_FORMAT_STRING_H
lib/libcxx/include/__format/format_to_n_result.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___FORMAT_FORMAT_TO_N_RESULT_H
11#define _LIBCPP___FORMAT_FORMAT_TO_N_RESULT_H
12
13#include <__config>
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_LIBCPP_BEGIN_NAMESPACE_STD
21
22#if _LIBCPP_STD_VER > 17
23
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
30template <class _OutIt>
31struct _LIBCPP_TEMPLATE_VIS format_to_n_result {
32 _OutIt out;
33 iter_difference_t<_OutIt> size;
34};
35
36#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
37#endif //_LIBCPP_STD_VER > 17
38
39_LIBCPP_END_NAMESPACE_STD
40
41#endif // _LIBCPP___FORMAT_FORMAT_TO_N_RESULT_H
lib/libcxx/include/__format/formatter.h created+290
......@@ -0,0 +1,290 @@
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_H
11#define _LIBCPP___FORMAT_FORMATTER_H
12
13#include <__algorithm/copy.h>
14#include <__algorithm/fill_n.h>
15#include <__availability>
16#include <__config>
17#include <__format/format_error.h>
18#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>
23
24#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
25#pragma GCC system_header
26#endif
27
28_LIBCPP_PUSH_MACROS
29#include <__undef_macros>
30
31_LIBCPP_BEGIN_NAMESPACE_STD
32
33#if _LIBCPP_STD_VER > 17
34
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
41/// The default formatter template.
42///
43/// [format.formatter.spec]/5
44/// If F is a disabled specialization of formatter, these values are false:
45/// - is_default_constructible_v<F>,
46/// - is_copy_constructible_v<F>,
47/// - is_move_constructible_v<F>,
48/// - is_copy_assignable<F>, and
49/// - is_move_assignable<F>.
50template <class _Tp, class _CharT>
51struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter {
52 formatter() = delete;
53 formatter(const formatter&) = delete;
54 formatter& operator=(const formatter&) = delete;
55};
56
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
100namespace __formatter {
101
102/** The character types that formatters are specialized for. */
103template <class _CharT>
104concept __char_type = same_as<_CharT, char> || same_as<_CharT, wchar_t>;
105
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
280} // namespace __formatter
281
282#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
283
284#endif //_LIBCPP_STD_VER > 17
285
286_LIBCPP_END_NAMESPACE_STD
287
288_LIBCPP_POP_MACROS
289
290#endif // _LIBCPP___FORMAT_FORMATTER_H
lib/libcxx/include/__format/formatter_bool.h created+147
......@@ -0,0 +1,147 @@
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_BOOL_H
11#define _LIBCPP___FORMAT_FORMATTER_BOOL_H
12
13#include <__availability>
14#include <__config>
15#include <__format/format_error.h>
16#include <__format/format_fwd.h>
17#include <__format/formatter.h>
18#include <__format/formatter_integral.h>
19#include <__format/parser_std_format_spec.h>
20#include <string_view>
21
22#ifndef _LIBCPP_HAS_NO_LOCALIZATION
23#include <locale>
24#endif
25
26#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
27#pragma GCC system_header
28#endif
29
30_LIBCPP_BEGIN_NAMESPACE_STD
31
32#if _LIBCPP_STD_VER > 17
33
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> {
44public:
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;
60
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;
69
70 default:
71 __throw_format_error(
72 "The format-spec type has a type not supported for a bool argument");
73 }
74
75 return __it;
76 }
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
95
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 }
139};
140
141#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
142
143#endif //_LIBCPP_STD_VER > 17
144
145_LIBCPP_END_NAMESPACE_STD
146
147#endif // _LIBCPP___FORMAT_FORMATTER_BOOL_H
lib/libcxx/include/__format/formatter_char.h created+104
......@@ -0,0 +1,104 @@
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_CHAR_H
11#define _LIBCPP___FORMAT_FORMATTER_CHAR_H
12
13#include <__availability>
14#include <__config>
15#include <__format/format_error.h>
16#include <__format/format_fwd.h>
17#include <__format/formatter.h>
18#include <__format/formatter_integral.h>
19#include <__format/parser_std_format_spec.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
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> {
39public:
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;
67 }
68};
69
70template <class _CharT>
71using __formatter_char = __formatter_integral<__parser_char<_CharT>>;
72
73} // namespace __format_spec
74
75// [format.formatter.spec]/2.1 The specializations
76
77template <>
78struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<char, char>
79 : public __format_spec::__formatter_char<char> {};
80
81#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
82template <>
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>;
86
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 }
91};
92
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)
99
100#endif //_LIBCPP_STD_VER > 17
101
102_LIBCPP_END_NAMESPACE_STD
103
104#endif // _LIBCPP___FORMAT_FORMATTER_CHAR_H
lib/libcxx/include/__format/formatter_floating_point.h created+717
......@@ -0,0 +1,717 @@
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_FLOATING_POINT_H
11#define _LIBCPP___FORMAT_FORMATTER_FLOATING_POINT_H
12
13#include <__algorithm/copy.h>
14#include <__algorithm/copy_n.h>
15#include <__algorithm/fill_n.h>
16#include <__algorithm/find.h>
17#include <__algorithm/min.h>
18#include <__algorithm/rotate.h>
19#include <__algorithm/transform.h>
20#include <__concepts/arithmetic.h>
21#include <__config>
22#include <__debug>
23#include <__format/format_error.h>
24#include <__format/format_fwd.h>
25#include <__format/format_string.h>
26#include <__format/formatter.h>
27#include <__format/formatter_integral.h>
28#include <__format/parser_std_format_spec.h>
29#include <__utility/move.h>
30#include <charconv>
31#include <cmath>
32
33#ifndef _LIBCPP_HAS_NO_LOCALIZATION
34# include <locale>
35#endif
36
37#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
38# pragma GCC system_header
39#endif
40
41_LIBCPP_PUSH_MACROS
42#include <__undef_macros>
43
44_LIBCPP_BEGIN_NAMESPACE_STD
45
46#if _LIBCPP_STD_VER > 17
47
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 {
55
56template <floating_point _Tp>
57_LIBCPP_HIDE_FROM_ABI char* __to_buffer(char* __first, char* __last, _Tp __value) {
58 to_chars_result __r = _VSTD::to_chars(__first, __last, __value);
59 _LIBCPP_ASSERT(__r.ec == errc(0), "Internal buffer too small");
60 return __r.ptr;
61}
62
63template <floating_point _Tp>
64_LIBCPP_HIDE_FROM_ABI char* __to_buffer(char* __first, char* __last, _Tp __value, chars_format __fmt) {
65 to_chars_result __r = _VSTD::to_chars(__first, __last, __value, __fmt);
66 _LIBCPP_ASSERT(__r.ec == errc(0), "Internal buffer too small");
67 return __r.ptr;
68}
69
70template <floating_point _Tp>
71_LIBCPP_HIDE_FROM_ABI char* __to_buffer(char* __first, char* __last, _Tp __value, chars_format __fmt, int __precision) {
72 to_chars_result __r = _VSTD::to_chars(__first, __last, __value, __fmt, __precision);
73 _LIBCPP_ASSERT(__r.ec == errc(0), "Internal buffer too small");
74 return __r.ptr;
75}
76
77// https://en.cppreference.com/w/cpp/language/types#cite_note-1
78// float min subnormal: +/-0x1p-149 max: +/- 3.402,823,4 10^38
79// double min subnormal: +/-0x1p-1074 max +/- 1.797,693,134,862,315,7 10^308
80// long double (x86) min subnormal: +/-0x1p-16446 max: +/- 1.189,731,495,357,231,765,021 10^4932
81//
82// The maximum number of digits required for the integral part is based on the
83// maximum's value power of 10. Every power of 10 requires one additional
84// decimal digit.
85// The maximum number of digits required for the fractional part is based on
86// the minimal subnormal hexadecimal output's power of 10. Every division of a
87// fraction's binary 1 by 2, requires one additional decimal digit.
88//
89// The maximum size of a formatted value depends on the selected output format.
90// Ignoring the fact the format string can request a precision larger than the
91// values maximum required, these values are:
92//
93// sign 1 code unit
94// __max_integral
95// radix point 1 code unit
96// __max_fractional
97// exponent character 1 code unit
98// sign 1 code unit
99// __max_fractional_value
100// -----------------------------------
101// total 4 code units extra required.
102//
103// TODO FMT Optimize the storage to avoid storing digits that are known to be zero.
104// https://www.exploringbinary.com/maximum-number-of-decimal-digits-in-binary-floating-point-numbers/
105
106// TODO FMT Add long double specialization when to_chars has proper long double support.
107template <class _Tp>
108struct __traits;
109
110template <floating_point _Fp>
111static constexpr size_t __float_buffer_size(int __precision) {
112 using _Traits = __traits<_Fp>;
113 return 4 + _Traits::__max_integral + __precision + _Traits::__max_fractional_value;
114}
115
116template <>
117struct __traits<float> {
118 static constexpr int __max_integral = 38;
119 static constexpr int __max_fractional = 149;
120 static constexpr int __max_fractional_value = 3;
121 static constexpr size_t __stack_buffer_size = 256;
122
123 static constexpr int __hex_precision_digits = 3;
124};
125
126template <>
127struct __traits<double> {
128 static constexpr int __max_integral = 308;
129 static constexpr int __max_fractional = 1074;
130 static constexpr int __max_fractional_value = 4;
131 static constexpr size_t __stack_buffer_size = 1024;
132
133 static constexpr int __hex_precision_digits = 4;
134};
135
136/// Helper class to store the conversion buffer.
137///
138/// Depending on the maxium size required for a value, the buffer is allocated
139/// on the stack or the heap.
140template <floating_point _Fp>
141class _LIBCPP_TEMPLATE_VIS __float_buffer {
142 using _Traits = __traits<_Fp>;
143
144public:
145 // TODO FMT Improve this constructor to do a better estimate.
146 // When using a scientific formatting with a precision of 6 a stack buffer
147 // will always suffice. At the moment that isn't important since floats and
148 // doubles use a stack buffer, unless the precision used in the format string
149 // is large.
150 // When supporting long doubles the __max_integral part becomes 4932 which
151 // may be too much for some platforms. For these cases a better estimate is
152 // required.
153 explicit _LIBCPP_HIDE_FROM_ABI __float_buffer(int __precision)
154 : __precision_(__precision != -1 ? __precision : _Traits::__max_fractional) {
155
156 // When the precision is larger than _Traits::__max_fractional the digits in
157 // the range (_Traits::__max_fractional, precision] will contain the value
158 // zero. There's no need to request to_chars to write these zeros:
159 // - When the value is large a temporary heap buffer needs to be allocated.
160 // - When to_chars writes the values they need to be "copied" to the output:
161 // - char: std::fill on the output iterator is faster than std::copy.
162 // - wchar_t: same argument as char, but additional std::copy won't work.
163 // The input is always a char buffer, so every char in the buffer needs
164 // to be converted from a char to a wchar_t.
165 if (__precision_ > _Traits::__max_fractional) {
166 __num_trailing_zeros_ = __precision_ - _Traits::__max_fractional;
167 __precision_ = _Traits::__max_fractional;
168 }
169
170 __size_ = __format_spec::__float_buffer_size<_Fp>(__precision_);
171 if (__size_ > _Traits::__stack_buffer_size)
172 // The allocated buffer's contents don't need initialization.
173 __begin_ = allocator<char>{}.allocate(__size_);
174 else
175 __begin_ = __buffer_;
176 }
177
178 _LIBCPP_HIDE_FROM_ABI ~__float_buffer() {
179 if (__size_ > _Traits::__stack_buffer_size)
180 allocator<char>{}.deallocate(__begin_, __size_);
181 }
182 _LIBCPP_HIDE_FROM_ABI __float_buffer(const __float_buffer&) = delete;
183 _LIBCPP_HIDE_FROM_ABI __float_buffer& operator=(const __float_buffer&) = delete;
184
185 _LIBCPP_HIDE_FROM_ABI char* begin() const { return __begin_; }
186 _LIBCPP_HIDE_FROM_ABI char* end() const { return __begin_ + __size_; }
187
188 _LIBCPP_HIDE_FROM_ABI int __precision() const { return __precision_; }
189 _LIBCPP_HIDE_FROM_ABI int __num_trailing_zeros() const { return __num_trailing_zeros_; }
190 _LIBCPP_HIDE_FROM_ABI void __remove_trailing_zeros() { __num_trailing_zeros_ = 0; }
191
192private:
193 int __precision_;
194 int __num_trailing_zeros_{0};
195 size_t __size_;
196 char* __begin_;
197 char __buffer_[_Traits::__stack_buffer_size];
198};
199
200struct __float_result {
201 /// Points at the beginning of the integral part in the buffer.
202 ///
203 /// When there's no sign character this points at the start of the buffer.
204 char* __integral;
205
206 /// Points at the radix point, when not present it's the same as \ref __last.
207 char* __radix_point;
208
209 /// Points at the exponent character, when not present it's the same as \ref __last.
210 char* __exponent;
211
212 /// Points beyond the last written element in the buffer.
213 char* __last;
214};
215
216/// Finds the position of the exponent character 'e' at the end of the buffer.
217///
218/// Assuming there is an exponent the input will terminate with
219/// eSdd and eSdddd (S = sign, d = digit)
220///
221/// \returns a pointer to the exponent or __last when not found.
222constexpr inline _LIBCPP_HIDE_FROM_ABI char* __find_exponent(char* __first, char* __last) {
223 ptrdiff_t __size = __last - __first;
224 if (__size > 4) {
225 __first = __last - _VSTD::min(__size, ptrdiff_t(6));
226 for (; __first != __last - 3; ++__first) {
227 if (*__first == 'e')
228 return __first;
229 }
230 }
231 return __last;
232}
233
234template <class _Fp, class _Tp>
235_LIBCPP_HIDE_FROM_ABI __float_result __format_buffer_default(const __float_buffer<_Fp>& __buffer, _Tp __value,
236 char* __integral) {
237 __float_result __result;
238 __result.__integral = __integral;
239 __result.__last = __format_spec::__to_buffer(__integral, __buffer.end(), __value);
240
241 __result.__exponent = __format_spec::__find_exponent(__result.__integral, __result.__last);
242
243 // Constrains:
244 // - There's at least one decimal digit before the radix point.
245 // - The radix point, when present, is placed before the exponent.
246 __result.__radix_point = _VSTD::find(__result.__integral + 1, __result.__exponent, '.');
247
248 // When the radix point isn't found its position is the exponent instead of
249 // __result.__last.
250 if (__result.__radix_point == __result.__exponent)
251 __result.__radix_point = __result.__last;
252
253 // clang-format off
254 _LIBCPP_ASSERT((__result.__integral != __result.__last) &&
255 (__result.__radix_point == __result.__last || *__result.__radix_point == '.') &&
256 (__result.__exponent == __result.__last || *__result.__exponent == 'e'),
257 "Post-condition failure.");
258 // clang-format on
259
260 return __result;
261}
262
263template <class _Fp, class _Tp>
264_LIBCPP_HIDE_FROM_ABI __float_result __format_buffer_hexadecimal_lower_case(const __float_buffer<_Fp>& __buffer,
265 _Tp __value, int __precision,
266 char* __integral) {
267 __float_result __result;
268 __result.__integral = __integral;
269 if (__precision == -1)
270 __result.__last = __format_spec::__to_buffer(__integral, __buffer.end(), __value, chars_format::hex);
271 else
272 __result.__last = __format_spec::__to_buffer(__integral, __buffer.end(), __value, chars_format::hex, __precision);
273
274 // H = one or more hex-digits
275 // S = sign
276 // D = one or more decimal-digits
277 // When the fractional part is zero and no precision the output is 0p+0
278 // else the output is 0.HpSD
279 // So testing the second position can differentiate between these two cases.
280 char* __first = __integral + 1;
281 if (*__first == '.') {
282 __result.__radix_point = __first;
283 // One digit is the minimum
284 // 0.hpSd
285 // ^-- last
286 // ^---- integral = end of search
287 // ^-------- start of search
288 // 0123456
289 //
290 // Four digits is the maximum
291 // 0.hpSdddd
292 // ^-- last
293 // ^---- integral = end of search
294 // ^-------- start of search
295 // 0123456789
296 static_assert(__traits<_Fp>::__hex_precision_digits <= 4, "Guard against possible underflow.");
297
298 char* __last = __result.__last - 2;
299 __first = __last - __traits<_Fp>::__hex_precision_digits;
300 __result.__exponent = _VSTD::find(__first, __last, 'p');
301 } else {
302 __result.__radix_point = __result.__last;
303 __result.__exponent = __first;
304 }
305
306 // clang-format off
307 _LIBCPP_ASSERT((__result.__integral != __result.__last) &&
308 (__result.__radix_point == __result.__last || *__result.__radix_point == '.') &&
309 (__result.__exponent != __result.__last && *__result.__exponent == 'p'),
310 "Post-condition failure.");
311 // clang-format on
312
313 return __result;
314}
315
316template <class _Fp, class _Tp>
317_LIBCPP_HIDE_FROM_ABI __float_result __format_buffer_hexadecimal_upper_case(const __float_buffer<_Fp>& __buffer,
318 _Tp __value, int __precision,
319 char* __integral) {
320 __float_result __result =
321 __format_spec::__format_buffer_hexadecimal_lower_case(__buffer, __value, __precision, __integral);
322 _VSTD::transform(__result.__integral, __result.__exponent, __result.__integral, __hex_to_upper);
323 *__result.__exponent = 'P';
324 return __result;
325}
326
327template <class _Fp, class _Tp>
328_LIBCPP_HIDE_FROM_ABI __float_result __format_buffer_scientific_lower_case(const __float_buffer<_Fp>& __buffer,
329 _Tp __value, int __precision,
330 char* __integral) {
331 __float_result __result;
332 __result.__integral = __integral;
333 __result.__last =
334 __format_spec::__to_buffer(__integral, __buffer.end(), __value, chars_format::scientific, __precision);
335
336 char* __first = __integral + 1;
337 _LIBCPP_ASSERT(__first != __result.__last, "No exponent present");
338 if (*__first == '.') {
339 __result.__radix_point = __first;
340 __result.__exponent = __format_spec::__find_exponent(__first + 1, __result.__last);
341 } else {
342 __result.__radix_point = __result.__last;
343 __result.__exponent = __first;
344 }
345
346 // clang-format off
347 _LIBCPP_ASSERT((__result.__integral != __result.__last) &&
348 (__result.__radix_point == __result.__last || *__result.__radix_point == '.') &&
349 (__result.__exponent != __result.__last && *__result.__exponent == 'e'),
350 "Post-condition failure.");
351 // clang-format on
352 return __result;
353}
354
355template <class _Fp, class _Tp>
356_LIBCPP_HIDE_FROM_ABI __float_result __format_buffer_scientific_upper_case(const __float_buffer<_Fp>& __buffer,
357 _Tp __value, int __precision,
358 char* __integral) {
359 __float_result __result =
360 __format_spec::__format_buffer_scientific_lower_case(__buffer, __value, __precision, __integral);
361 *__result.__exponent = 'E';
362 return __result;
363}
364
365template <class _Fp, class _Tp>
366_LIBCPP_HIDE_FROM_ABI __float_result __format_buffer_fixed(const __float_buffer<_Fp>& __buffer, _Tp __value,
367 int __precision, char* __integral) {
368 __float_result __result;
369 __result.__integral = __integral;
370 __result.__last = __format_spec::__to_buffer(__integral, __buffer.end(), __value, chars_format::fixed, __precision);
371
372 // When there's no precision there's no radix point.
373 // Else the radix point is placed at __precision + 1 from the end.
374 // By converting __precision to a bool the subtraction can be done
375 // unconditionally.
376 __result.__radix_point = __result.__last - (__precision + bool(__precision));
377 __result.__exponent = __result.__last;
378
379 // clang-format off
380 _LIBCPP_ASSERT((__result.__integral != __result.__last) &&
381 (__result.__radix_point == __result.__last || *__result.__radix_point == '.') &&
382 (__result.__exponent == __result.__last),
383 "Post-condition failure.");
384 // clang-format on
385 return __result;
386}
387
388template <class _Fp, class _Tp>
389_LIBCPP_HIDE_FROM_ABI __float_result __format_buffer_general_lower_case(__float_buffer<_Fp>& __buffer, _Tp __value,
390 int __precision, char* __integral) {
391
392 __buffer.__remove_trailing_zeros();
393
394 __float_result __result;
395 __result.__integral = __integral;
396 __result.__last = __format_spec::__to_buffer(__integral, __buffer.end(), __value, chars_format::general, __precision);
397
398 char* __first = __integral + 1;
399 if (__first == __result.__last) {
400 __result.__radix_point = __result.__last;
401 __result.__exponent = __result.__last;
402 } else {
403 __result.__exponent = __format_spec::__find_exponent(__first, __result.__last);
404 if (__result.__exponent != __result.__last)
405 // In scientific mode if there's a radix point it will always be after
406 // the first digit. (This is the position __first points at).
407 __result.__radix_point = *__first == '.' ? __first : __result.__last;
408 else {
409 // In fixed mode the algorithm truncates trailing spaces and possibly the
410 // radix point. There's no good guess for the position of the radix point
411 // therefore scan the output after the first digit.
412 __result.__radix_point = _VSTD::find(__first, __result.__last, '.');
413 }
414 }
415
416 // clang-format off
417 _LIBCPP_ASSERT((__result.__integral != __result.__last) &&
418 (__result.__radix_point == __result.__last || *__result.__radix_point == '.') &&
419 (__result.__exponent == __result.__last || *__result.__exponent == 'e'),
420 "Post-condition failure.");
421 // clang-format on
422
423 return __result;
424}
425
426template <class _Fp, class _Tp>
427_LIBCPP_HIDE_FROM_ABI __float_result __format_buffer_general_upper_case(__float_buffer<_Fp>& __buffer, _Tp __value,
428 int __precision, char* __integral) {
429 __float_result __result =
430 __format_spec::__format_buffer_general_lower_case(__buffer, __value, __precision, __integral);
431 if (__result.__exponent != __result.__last)
432 *__result.__exponent = 'E';
433 return __result;
434}
435
436# ifndef _LIBCPP_HAS_NO_LOCALIZATION
437template <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) {
442 const auto& __np = use_facet<numpunct<_CharT>>(__loc);
443 string __grouping = __np.grouping();
444 char* __first = __result.__integral;
445 // When no radix point or exponent are present __last will be __result.__last.
446 char* __last = _VSTD::min(__result.__radix_point, __result.__exponent);
447
448 ptrdiff_t __digits = __last - __first;
449 if (!__grouping.empty()) {
450 if (__digits <= __grouping[0])
451 __grouping.clear();
452 else
453 __grouping = __determine_grouping(__digits, __grouping);
454 }
455
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
460
461 __formatter::__padding_size_result __padding = {0, 0};
462 bool __zero_padding = __alignment == _Flags::_Alignment::__default;
463 if (__size < __width) {
464 if (__zero_padding) {
465 __alignment = _Flags::_Alignment::__right;
466 __fill = _CharT('0');
467 }
468
469 __padding = __formatter::__padding_size(__size, __width, __alignment);
470 }
471
472 // sign and (zero padding or alignment)
473 if (__zero_padding && __first != __buffer.begin())
474 *__out_it++ = *__buffer.begin();
475 __out_it = _VSTD::fill_n(_VSTD::move(__out_it), __padding.__before, __fill);
476 if (!__zero_padding && __first != __buffer.begin())
477 *__out_it++ = *__buffer.begin();
478
479 // integral part
480 if (__grouping.empty()) {
481 __out_it = _VSTD::copy_n(__first, __digits, _VSTD::move(__out_it));
482 } else {
483 auto __r = __grouping.rbegin();
484 auto __e = __grouping.rend() - 1;
485 _CharT __sep = __np.thousands_sep();
486 // The output is divided in small groups of numbers to write:
487 // - A group before the first separator.
488 // - A separator and a group, repeated for the number of separators.
489 // - A group after the last separator.
490 // This loop achieves that process by testing the termination condition
491 // midway in the loop.
492 while (true) {
493 __out_it = _VSTD::copy_n(__first, *__r, _VSTD::move(__out_it));
494 __first += *__r;
495
496 if (__r == __e)
497 break;
498
499 ++__r;
500 *__out_it++ = __sep;
501 }
502 }
503
504 // fractional part
505 if (__result.__radix_point != __result.__last) {
506 *__out_it++ = __np.decimal_point();
507 __out_it = _VSTD::copy(__result.__radix_point + 1, __result.__exponent, _VSTD::move(__out_it));
508 __out_it = _VSTD::fill_n(_VSTD::move(__out_it), __buffer.__num_trailing_zeros(), _CharT('0'));
509 }
510
511 // exponent
512 if (__result.__exponent != __result.__last)
513 __out_it = _VSTD::copy(__result.__exponent, __result.__last, _VSTD::move(__out_it));
514
515 // alignment
516 return _VSTD::fill_n(_VSTD::move(__out_it), __padding.__after, __fill);
517}
518
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 }
569
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 }
588
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 }
602
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);
606
607 return __formatter::__write(_VSTD::move(__out_it), __first, __result.__last, __size, this->__width, this->__fill,
608 this->__alignment);
609 }
610
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);
640 }
641
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);
676
677 case _Flags::_Type::__scientific_upper_case:
678 return __format_spec::__format_buffer_scientific_upper_case(__buffer, __value, __buffer.__precision(), __first);
679
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);
683
684 case _Flags::_Type::__general_lower_case:
685 return __format_spec::__format_buffer_general_lower_case(__buffer, __value, __buffer.__precision(), __first);
686
687 case _Flags::_Type::__general_upper_case:
688 return __format_spec::__format_buffer_general_upper_case(__buffer, __value, __buffer.__precision(), __first);
689
690 default:
691 _LIBCPP_ASSERT(false, "The parser should have validated the type");
692 _LIBCPP_UNREACHABLE();
693 }
694 }
695};
696
697} //namespace __format_spec
698
699template <__formatter::__char_type _CharT>
700struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<float, _CharT>
701 : public __format_spec::__formatter_floating_point<_CharT> {};
702template <__formatter::__char_type _CharT>
703struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<double, _CharT>
704 : public __format_spec::__formatter_floating_point<_CharT> {};
705template <__formatter::__char_type _CharT>
706struct _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)
710
711#endif //_LIBCPP_STD_VER > 17
712
713_LIBCPP_END_NAMESPACE_STD
714
715_LIBCPP_POP_MACROS
716
717#endif // _LIBCPP___FORMAT_FORMATTER_FLOATING_POINT_H
lib/libcxx/include/__format/formatter_integer.h created+170
......@@ -0,0 +1,170 @@
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_INTEGER_H
11#define _LIBCPP___FORMAT_FORMATTER_INTEGER_H
12
13#include <__availability>
14#include <__config>
15#include <__format/format_error.h>
16#include <__format/format_fwd.h>
17#include <__format/formatter.h>
18#include <__format/formatter_integral.h>
19#include <__format/parser_std_format_spec.h>
20#include <limits>
21
22#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23#pragma GCC system_header
24#endif
25
26_LIBCPP_PUSH_MACROS
27#include <__undef_macros>
28
29_LIBCPP_BEGIN_NAMESPACE_STD
30
31#if _LIBCPP_STD_VER > 17
32
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 {
40
41template <class _CharT>
42class _LIBCPP_TEMPLATE_VIS __parser_integer : public __parser_integral<_CharT> {
43public:
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;
71 }
72};
73
74template <class _CharT>
75using __formatter_integer = __formatter_integral<__parser_integer<_CharT>>;
76
77} // namespace __format_spec
78
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
82
83// Signed integral types.
84template <__formatter::__char_type _CharT>
85struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT
86 formatter<signed char, _CharT>
87 : public __format_spec::__formatter_integer<_CharT> {};
88template <__formatter::__char_type _CharT>
89struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<short, _CharT>
90 : public __format_spec::__formatter_integer<_CharT> {};
91template <__formatter::__char_type _CharT>
92struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<int, _CharT>
93 : public __format_spec::__formatter_integer<_CharT> {};
94template <__formatter::__char_type _CharT>
95struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<long, _CharT>
96 : public __format_spec::__formatter_integer<_CharT> {};
97template <__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
102template <__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
120
121// Unsigned integral types.
122template <__formatter::__char_type _CharT>
123struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT
124 formatter<unsigned char, _CharT>
125 : public __format_spec::__formatter_integer<_CharT> {};
126template <__formatter::__char_type _CharT>
127struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT
128 formatter<unsigned short, _CharT>
129 : public __format_spec::__formatter_integer<_CharT> {};
130template <__formatter::__char_type _CharT>
131struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT
132 formatter<unsigned, _CharT>
133 : public __format_spec::__formatter_integer<_CharT> {};
134template <__formatter::__char_type _CharT>
135struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT
136 formatter<unsigned long, _CharT>
137 : public __format_spec::__formatter_integer<_CharT> {};
138template <__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
143template <__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)
163
164#endif //_LIBCPP_STD_VER > 17
165
166_LIBCPP_END_NAMESPACE_STD
167
168_LIBCPP_POP_MACROS
169
170#endif // _LIBCPP___FORMAT_FORMATTER_INTEGER_H
lib/libcxx/include/__format/formatter_integral.h created+463
......@@ -0,0 +1,463 @@
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_INTEGRAL_H
11#define _LIBCPP___FORMAT_FORMATTER_INTEGRAL_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/format_error.h>
19#include <__format/format_fwd.h>
20#include <__format/formatter.h>
21#include <__format/parser_std_format_spec.h>
22#include <array>
23#include <charconv>
24#include <concepts>
25#include <limits>
26#include <string>
27
28#ifndef _LIBCPP_HAS_NO_LOCALIZATION
29#include <locale>
30#endif
31
32#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
33#pragma GCC system_header
34#endif
35
36_LIBCPP_PUSH_MACROS
37#include <__undef_macros>
38
39_LIBCPP_BEGIN_NAMESPACE_STD
40
41#if _LIBCPP_STD_VER > 17
42
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)
48
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}
118
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}
126
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.
134}
135
136/**
137 * Determines the required grouping based on the size of the input.
138 *
139 * The grouping's last element will be repeated. For simplicity this repeating
140 * is unwrapped based on the length of the input. (When the input is short some
141 * groups are not processed.)
142 *
143 * @returns The size of the groups to write. This means the number of
144 * separator characters written is size() - 1.
145 *
146 * @note Since zero-sized groups cause issues they are silently ignored.
147 *
148 * @note The grouping field of the locale is always a @c std::string,
149 * regardless whether the @c std::numpunct's type is @c char or @c wchar_t.
150 */
151_LIBCPP_HIDE_FROM_ABI inline string
152__determine_grouping(ptrdiff_t __size, const string& __grouping) {
153 _LIBCPP_ASSERT(!__grouping.empty() && __size > __grouping[0],
154 "The slow grouping formatting is used while there will be no "
155 "separators written");
156 string __r;
157 auto __end = __grouping.end() - 1;
158 auto __ptr = __grouping.begin();
159
160 while (true) {
161 __size -= *__ptr;
162 if (__size > 0)
163 __r.push_back(*__ptr);
164 else {
165 // __size <= 0 so the value pushed will be <= *__ptr.
166 __r.push_back(*__ptr + __size);
167 return __r;
168 }
169
170 // Proceed to the next group.
171 if (__ptr != __end) {
172 do {
173 ++__ptr;
174 // Skip grouping with a width of 0.
175 } while (*__ptr == 0 && __ptr != __end);
176 }
177 }
178
179 _LIBCPP_UNREACHABLE();
180}
181
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);
196
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);
212 }
213 }
214
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 }
245
246 const auto __c = static_cast<_CharT>(__value);
247 return __write(_VSTD::addressof(__c), _VSTD::addressof(__c) + 1,
248 __ctx.out());
249 }
250
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 }
298
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) {
303
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));
308
309 return __formatter::__write(_VSTD::move(__out_it), __first, __last,
310 __size, this->__width, this->__fill,
311 this->__alignment);
312 }
313
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);
328 }
329
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 }
371
372 return __write(__first, __last, _VSTD::move(__out_it));
373 }
374
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 }
413
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 }
446
447 return _VSTD::fill_n(_VSTD::move(__out_it), __padding.__after,
448 this->__fill);
449 }
450#endif // _LIBCPP_HAS_NO_LOCALIZATION
451};
452
453} // namespace __format_spec
454
455#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
456
457#endif //_LIBCPP_STD_VER > 17
458
459_LIBCPP_END_NAMESPACE_STD
460
461_LIBCPP_POP_MACROS
462
463#endif // _LIBCPP___FORMAT_FORMATTER_INTEGRAL_H
lib/libcxx/include/__format/formatter_pointer.h created+91
......@@ -0,0 +1,91 @@
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_POINTER_H
11#define _LIBCPP___FORMAT_FORMATTER_POINTER_H
12
13#include <__algorithm/copy.h>
14#include <__availability>
15#include <__config>
16#include <__debug>
17#include <__format/format_error.h>
18#include <__format/format_fwd.h>
19#include <__format/formatter.h>
20#include <__format/formatter_integral.h>
21#include <__format/parser_std_format_spec.h>
22#include <__iterator/access.h>
23#include <__nullptr>
24#include <cstdint>
25
26#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
27# pragma GCC system_header
28#endif
29
30_LIBCPP_BEGIN_NAMESPACE_STD
31
32#if _LIBCPP_STD_VER > 17
33
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 <__formatter::__char_type _CharT>
43class _LIBCPP_TEMPLATE_VIS __formatter_pointer : public __parser_pointer<_CharT> {
44public:
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));
50
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());
63
64 return __formatter::__write(__ctx.out(), __buffer, __last, __size, this->__width, this->__fill, this->__alignment);
65 }
66};
67
68} // namespace __format_spec
69
70// [format.formatter.spec]/2.4
71// For each charT, the pointer type specializations template<>
72// - struct formatter<nullptr_t, charT>;
73// - template<> struct formatter<void*, charT>;
74// - template<> struct formatter<const void*, charT>;
75template <__formatter::__char_type _CharT>
76struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<nullptr_t, _CharT>
77 : public __format_spec::__formatter_pointer<_CharT> {};
78template <__formatter::__char_type _CharT>
79struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<void*, _CharT>
80 : public __format_spec::__formatter_pointer<_CharT> {};
81template <__formatter::__char_type _CharT>
82struct _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)
86
87#endif //_LIBCPP_STD_VER > 17
88
89_LIBCPP_END_NAMESPACE_STD
90
91#endif // _LIBCPP___FORMAT_FORMATTER_POINTER_H
lib/libcxx/include/__format/formatter_string.h created+162
......@@ -0,0 +1,162 @@
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_STRING_H
11#define _LIBCPP___FORMAT_FORMATTER_STRING_H
12
13#include <__config>
14#include <__format/format_error.h>
15#include <__format/format_fwd.h>
16#include <__format/format_string.h>
17#include <__format/formatter.h>
18#include <__format/parser_std_format_spec.h>
19#include <string_view>
20
21#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22#pragma GCC system_header
23#endif
24
25_LIBCPP_PUSH_MACROS
26#include <__undef_macros>
27
28_LIBCPP_BEGIN_NAMESPACE_STD
29
30#if _LIBCPP_STD_VER > 17
31
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
40template <__formatter::__char_type _CharT>
41class _LIBCPP_TEMPLATE_VIS __formatter_string : public __parser_string<_CharT> {
42public:
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);
59 }
60};
61
62} //namespace __format_spec
63
64// [format.formatter.spec]/2.2 For each charT, the string type specializations
65
66// Formatter const char*.
67template <__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>;
72
73 _LIBCPP_HIDE_FROM_ABI auto format(const _CharT* __str, auto& __ctx)
74 -> decltype(__ctx.out()) {
75 _LIBCPP_ASSERT(__str, "The basic_format_arg constructor should have "
76 "prevented an invalid pointer.");
77
78 // When using a center or right alignment and the width option the length
79 // of __str must be known to add the padding upfront. This case is handled
80 // by the base class by converting the argument to a basic_string_view.
81 //
82 // When using left alignment and the width option the padding is added
83 // after outputting __str so the length can be determined while outputting
84 // __str. The same holds true for the precision, during outputting __str it
85 // can be validated whether the precision threshold has been reached. For
86 // now these optimizations aren't implemented. Instead the base class
87 // handles these options.
88 // TODO FMT Implement these improvements.
89 if (this->__has_width_field() || this->__has_precision_field())
90 return _Base::format(__str, __ctx);
91
92 // No formatting required, copy the string to the output.
93 auto __out_it = __ctx.out();
94 while (*__str)
95 *__out_it++ = *__str++;
96 return __out_it;
97 }
98};
99
100// Formatter char*.
101template <__formatter::__char_type _CharT>
102struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT
103 formatter<_CharT*, _CharT> : public formatter<const _CharT*, _CharT> {
104 using _Base = formatter<const _CharT*, _CharT>;
105
106 _LIBCPP_HIDE_FROM_ABI auto format(_CharT* __str, auto& __ctx)
107 -> decltype(__ctx.out()) {
108 return _Base::format(__str, __ctx);
109 }
110};
111
112// Formatter const char[].
113template <__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>;
118
119 _LIBCPP_HIDE_FROM_ABI auto format(const _CharT __str[_Size], auto& __ctx)
120 -> decltype(__ctx.out()) {
121 return _Base::format(basic_string_view<_CharT>(__str, _Size), __ctx);
122 }
123};
124
125// Formatter std::string.
126template <__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>;
131
132 _LIBCPP_HIDE_FROM_ABI auto
133 format(const basic_string<_CharT, _Traits, _Allocator>& __str, auto& __ctx)
134 -> decltype(__ctx.out()) {
135 // drop _Traits and _Allocator
136 return _Base::format(basic_string_view<_CharT>(__str.data(), __str.size()), __ctx);
137 }
138};
139
140// Formatter std::string_view.
141template <__formatter::__char_type _CharT, class _Traits>
142struct _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>;
145
146 _LIBCPP_HIDE_FROM_ABI auto
147 format(basic_string_view<_CharT, _Traits> __str, auto& __ctx)
148 -> decltype(__ctx.out()) {
149 // drop _Traits
150 return _Base::format(basic_string_view<_CharT>(__str.data(), __str.size()), __ctx);
151 }
152};
153
154#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
155
156#endif //_LIBCPP_STD_VER > 17
157
158_LIBCPP_END_NAMESPACE_STD
159
160_LIBCPP_POP_MACROS
161
162#endif // _LIBCPP___FORMAT_FORMATTER_STRING_H
lib/libcxx/include/__format/parser_std_format_spec.h created+1398
......@@ -0,0 +1,1398 @@
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_PARSER_STD_FORMAT_SPEC_H
11#define _LIBCPP___FORMAT_PARSER_STD_FORMAT_SPEC_H
12
13#include <__algorithm/find_if.h>
14#include <__algorithm/min.h>
15#include <__config>
16#include <__debug>
17#include <__format/format_arg.h>
18#include <__format/format_error.h>
19#include <__format/format_string.h>
20#include <__variant/monostate.h>
21#include <bit>
22#include <concepts>
23#include <cstdint>
24#include <type_traits>
25
26#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
27# pragma GCC system_header
28#endif
29
30_LIBCPP_PUSH_MACROS
31#include <__undef_macros>
32
33_LIBCPP_BEGIN_NAMESPACE_STD
34
35#if _LIBCPP_STD_VER > 17
36
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
43namespace __format_spec {
44
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
205template <class _CharT>
206_LIBCPP_HIDE_FROM_ABI constexpr __format::__parse_number_result< _CharT>
207__parse_arg_id(const _CharT* __begin, const _CharT* __end, auto& __parse_ctx) {
208 // This function is a wrapper to call the real parser. But it does the
209 // validation for the pre-conditions and post-conditions.
210 if (__begin == __end)
211 __throw_format_error("End of input while parsing format-spec arg-id");
212
213 __format::__parse_number_result __r =
214 __format::__parse_arg_id(__begin, __end, __parse_ctx);
215
216 if (__r.__ptr == __end || *__r.__ptr != _CharT('}'))
217 __throw_format_error("Invalid arg-id");
218
219 ++__r.__ptr;
220 return __r;
221}
222
223template <class _Context>
224_LIBCPP_HIDE_FROM_ABI constexpr uint32_t
225__substitute_arg_id(basic_format_arg<_Context> __arg) {
226 return visit_format_arg(
227 [](auto __arg) -> uint32_t {
228 using _Type = decltype(__arg);
229 if constexpr (integral<_Type>) {
230 if constexpr (signed_integral<_Type>) {
231 if (__arg < 0)
232 __throw_format_error("A format-spec arg-id replacement shouldn't "
233 "have a negative value");
234 }
235
236 using _CT = common_type_t<_Type, decltype(__format::__number_max)>;
237 if (static_cast<_CT>(__arg) >
238 static_cast<_CT>(__format::__number_max))
239 __throw_format_error("A format-spec arg-id replacement exceeds "
240 "the maximum supported value");
241
242 return __arg;
243 } else if constexpr (same_as<_Type, monostate>)
244 __throw_format_error("Argument index out of bounds");
245 else
246 __throw_format_error("A format-spec arg-id replacement argument "
247 "isn't an integral type");
248 },
249 __arg);
250}
251
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 }
293
294 if (*__begin < _CharT('0') || *__begin > _CharT('9'))
295 return __begin;
296
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 }
305
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 }
318};
319
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 }
346
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 }
355
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;
361
362 ++__begin;
363 if (__begin == __end)
364 __throw_format_error("End of input while parsing format-spec precision");
365
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 }
375
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 }
386
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");
392
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 }
398};
399
400template <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{
519public:
520 using char_type = _CharT;
521
522 _LIBCPP_HIDE_FROM_ABI constexpr __parser_string() {
523 this->__alignment = _Flags::_Alignment::__left;
524 }
525
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 }
542
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()) {
554
555 auto __begin = __parse_ctx.begin();
556 auto __end = __parse_ctx.end();
557 if (__begin == __end)
558 return __begin;
559
560 __begin = __parser_fill_align<_CharT>::__parse(__begin, __end,
561 static_cast<_Flags&>(*this));
562 if (__begin == __end)
563 return __begin;
564
565 __begin = __parser_width::__parse(__begin, __end, __parse_ctx);
566 if (__begin == __end)
567 return __begin;
568
569 __begin = __parser_precision::__parse(__begin, __end, __parse_ctx);
570 if (__begin == __end)
571 return __begin;
572
573 __begin = __parse_type(__begin, static_cast<_Flags&>(*this));
574
575 if (__begin != __end && *__begin != _CharT('}'))
576 __throw_format_error(
577 "The format-spec should consume the input or end with a '}'");
578
579 return __begin;
580 }
581
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;
588
589 default:
590 __throw_format_error("The format-spec type has a type not supported for "
591 "a string argument");
592 }
593 }
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;
630
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;
643
644 __begin = __parse_zero_padding(__begin, static_cast<_Flags&>(*this));
645 if (__begin == __end)
646 return __begin;
647
648 __begin = __parser_width::__parse(__begin, __end, __parse_ctx);
649 if (__begin == __end)
650 return __begin;
651
652 __begin =
653 __parse_locale_specific_form(__begin, static_cast<_Flags&>(*this));
654 if (__begin == __end)
655 return __begin;
656
657 __begin = __parse_type(__begin, static_cast<_Flags&>(*this));
658
659 if (__begin != __end && *__begin != _CharT('}'))
660 __throw_format_error(
661 "The format-spec should consume the input or end with a '}'");
662
663 return __begin;
664 }
665
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 }
670
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;
702 }
703};
704
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;
756
757 __begin = __parser_fill_align<_CharT>::__parse(__begin, __end,
758 static_cast<_Flags&>(*this));
759 if (__begin == __end)
760 return __begin;
761
762 __begin = __parse_sign(__begin, static_cast<_Flags&>(*this));
763 if (__begin == __end)
764 return __begin;
765
766 __begin = __parse_alternate_form(__begin, static_cast<_Flags&>(*this));
767 if (__begin == __end)
768 return __begin;
769
770 __begin = __parse_zero_padding(__begin, static_cast<_Flags&>(*this));
771 if (__begin == __end)
772 return __begin;
773
774 __begin = __parser_width::__parse(__begin, __end, __parse_ctx);
775 if (__begin == __end)
776 return __begin;
777
778 __begin = __parser_precision::__parse(__begin, __end, __parse_ctx);
779 if (__begin == __end)
780 return __begin;
781
782 __begin =
783 __parse_locale_specific_form(__begin, static_cast<_Flags&>(*this));
784 if (__begin == __end)
785 return __begin;
786
787 __begin = __parse_type(__begin, static_cast<_Flags&>(*this));
788
789 if (__begin != __end && *__begin != _CharT('}'))
790 __throw_format_error(
791 "The format-spec should consume the input or end with a '}'");
792
793 return __begin;
794 }
795
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;
804 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.
808 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 }
820 break;
821
822 default:
823 __throw_format_error("The format-spec type has a type not supported for "
824 "a floating-point argument");
825 }
826 }
827};
828
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;
843
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;
851 }
852
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;
867 }
868
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;
885
886 __begin = __parser_fill_align<_CharT>::__parse(__begin, __end, static_cast<_Flags&>(*this));
887 if (__begin == __end)
888 return __begin;
889
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.
905
906 __begin = __parser_width::__parse(__begin, __end, __parse_ctx);
907 if (__begin == __end)
908 return __begin;
909
910 __begin = __parse_type(__begin, static_cast<_Flags&>(*this));
911
912 if (__begin != __end && *__begin != _CharT('}'))
913 __throw_format_error("The format-spec should consume the input or end with a '}'");
914
915 return __begin;
916 }
917
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};
931
932/** Helper struct returned from @ref __get_string_alignment. */
933template <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};
966
967#ifndef _LIBCPP_HAS_NO_UNICODE
968namespace __detail {
969
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. */
1020template <class _CharT>
1021concept __utf8_character = same_as<_CharT, char> || same_as<_CharT, char8_t>;
1022
1023/** Helper concept for an UTF-16 character type. */
1024template <class _CharT>
1025concept __utf16_character = (same_as<_CharT, wchar_t> && sizeof(wchar_t) == 2) || same_as<_CharT, char16_t>;
1026
1027/** Helper concept for an UTF-32 character type. */
1028template <class _CharT>
1029concept __utf32_character = (same_as<_CharT, wchar_t> && sizeof(wchar_t) == 4) || same_as<_CharT, char32_t>;
1030
1031/** Helper concept for an UTF-16 or UTF-32 character type. */
1032template <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");
1046
1047 // clang-format off
1048 return 1 + (__c >= 0x1100 && (__c <= 0x115f ||
1049 (__c >= 0x2329 && (__c <= 0x232a ||
1050 (__c >= 0x2e80 && (__c <= 0x303e ||
1051 (__c >= 0x3040 && (__c <= 0xa4cf ||
1052 (__c >= 0xac00 && (__c <= 0xd7a3 ||
1053 (__c >= 0xf900 && (__c <= 0xfaff ||
1054 (__c >= 0xfe10 && (__c <= 0xfe19 ||
1055 (__c >= 0xfe30 && (__c <= 0xfe6f ||
1056 (__c >= 0xff00 && (__c <= 0xff60 ||
1057 (__c >= 0xffe0 && (__c <= 0xffe6
1058 ))))))))))))))))))));
1059 // clang-format on
1060}
1061
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");
1071
1072 // clang-format off
1073 return 1 + (__c >= 0x1'f300 && (__c <= 0x1'f64f ||
1074 (__c >= 0x1'f900 && (__c <= 0x1'f9ff ||
1075 (__c >= 0x2'0000 && (__c <= 0x2'fffd ||
1076 (__c >= 0x3'0000 && (__c <= 0x3'fffd
1077 ))))))));
1078 // clang-format on
1079}
1080
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);
1089
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; });
1115}
1116
1117template <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}
1144
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;
1173
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;
1182
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};
1225 }
1226 return {__result, __first};
1227}
1228
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};
1286}
1287
1288} // namespace __detail
1289
1290template <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};
1344 }
1345
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 }
1370
1371 __size = __lengh_info.__width + __prefix;
1372 return {__last, __size, __size < __width};
1373}
1374#else // _LIBCPP_HAS_NO_UNICODE
1375template <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};
1385}
1386#endif // _LIBCPP_HAS_NO_UNICODE
1387
1388} // namespace __format_spec
1389
1390# endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
1391
1392#endif //_LIBCPP_STD_VER > 17
1393
1394_LIBCPP_END_NAMESPACE_STD
1395
1396_LIBCPP_POP_MACROS
1397
1398#endif // _LIBCPP___FORMAT_PARSER_STD_FORMAT_SPEC_H
lib/libcxx/include/__function_like.h deleted-56
......@@ -1,56 +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___ITERATOR_FUNCTION_LIKE_H
11#define _LIBCPP___ITERATOR_FUNCTION_LIKE_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_PUSH_MACROS
20#include <__undef_macros>
21
22_LIBCPP_BEGIN_NAMESPACE_STD
23
24#if !defined(_LIBCPP_HAS_NO_RANGES)
25
26namespace ranges {
27// Per [range.iter.ops.general] and [algorithms.requirements], functions in namespace std::ranges
28// can't be found by ADL and inhibit ADL when found by unqualified lookup. The easiest way to
29// facilitate this is to use function objects.
30//
31// Since these are still standard library functions, we use `__function_like` to eliminate most of
32// the properties that function objects get by default (e.g. semiregularity, addressability), to
33// limit the surface area of the unintended public interface, so as to curb the effect of Hyrum's
34// law.
35struct __function_like {
36 __function_like() = delete;
37 __function_like(__function_like const&) = delete;
38 __function_like& operator=(__function_like const&) = delete;
39
40 void operator&() const = delete;
41
42 struct __tag { };
43
44protected:
45 constexpr explicit __function_like(__tag) noexcept {}
46 ~__function_like() = default;
47};
48} // namespace ranges
49
50#endif // !defined(_LIBCPP_HAS_NO_RANGES)
51
52_LIBCPP_END_NAMESPACE_STD
53
54_LIBCPP_POP_MACROS
55
56#endif // _LIBCPP___ITERATOR_FUNCTION_LIKE_H
lib/libcxx/include/__functional/bind.h+30-24
......@@ -11,8 +11,8 @@
1111#define _LIBCPP___FUNCTIONAL_BIND_H
1212
1313#include <__config>
14#include <__functional/weak_result_type.h>
1514#include <__functional/invoke.h>
15#include <__functional/weak_result_type.h>
1616#include <cstddef>
1717#include <tuple>
1818#include <type_traits>
......@@ -23,22 +23,28 @@
2323
2424_LIBCPP_BEGIN_NAMESPACE_STD
2525
26template<class _Tp> struct __is_bind_expression : public false_type {};
27template<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_bind_expression
28 : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
26template<class _Tp>
27struct is_bind_expression : _If<
28 _IsSame<_Tp, typename __uncvref<_Tp>::type>::value,
29 false_type,
30 is_bind_expression<typename __uncvref<_Tp>::type>
31> {};
2932
3033#if _LIBCPP_STD_VER > 14
3134template <class _Tp>
32_LIBCPP_INLINE_VAR constexpr size_t is_bind_expression_v = is_bind_expression<_Tp>::value;
35inline constexpr size_t is_bind_expression_v = is_bind_expression<_Tp>::value;
3336#endif
3437
35template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
36template<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_placeholder
37 : public __is_placeholder<typename remove_cv<_Tp>::type> {};
38template<class _Tp>
39struct is_placeholder : _If<
40 _IsSame<_Tp, typename __uncvref<_Tp>::type>::value,
41 integral_constant<int, 0>,
42 is_placeholder<typename __uncvref<_Tp>::type>
43> {};
3844
3945#if _LIBCPP_STD_VER > 14
4046template <class _Tp>
41_LIBCPP_INLINE_VAR constexpr size_t is_placeholder_v = is_placeholder<_Tp>::value;
47inline constexpr size_t is_placeholder_v = is_placeholder<_Tp>::value;
4248#endif
4349
4450namespace placeholders
......@@ -58,22 +64,22 @@ _LIBCPP_FUNC_VIS extern const __ph<8> _8;
5864_LIBCPP_FUNC_VIS extern const __ph<9> _9;
5965_LIBCPP_FUNC_VIS extern const __ph<10> _10;
6066#else
61/* _LIBCPP_INLINE_VAR */ constexpr __ph<1> _1{};
62/* _LIBCPP_INLINE_VAR */ constexpr __ph<2> _2{};
63/* _LIBCPP_INLINE_VAR */ constexpr __ph<3> _3{};
64/* _LIBCPP_INLINE_VAR */ constexpr __ph<4> _4{};
65/* _LIBCPP_INLINE_VAR */ constexpr __ph<5> _5{};
66/* _LIBCPP_INLINE_VAR */ constexpr __ph<6> _6{};
67/* _LIBCPP_INLINE_VAR */ constexpr __ph<7> _7{};
68/* _LIBCPP_INLINE_VAR */ constexpr __ph<8> _8{};
69/* _LIBCPP_INLINE_VAR */ constexpr __ph<9> _9{};
70/* _LIBCPP_INLINE_VAR */ constexpr __ph<10> _10{};
67/* inline */ constexpr __ph<1> _1{};
68/* inline */ constexpr __ph<2> _2{};
69/* inline */ constexpr __ph<3> _3{};
70/* inline */ constexpr __ph<4> _4{};
71/* inline */ constexpr __ph<5> _5{};
72/* inline */ constexpr __ph<6> _6{};
73/* inline */ constexpr __ph<7> _7{};
74/* inline */ constexpr __ph<8> _8{};
75/* inline */ constexpr __ph<9> _9{};
76/* inline */ constexpr __ph<10> _10{};
7177#endif // defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
7278
73} // placeholders
79} // namespace placeholders
7480
7581template<int _Np>
76struct __is_placeholder<placeholders::__ph<_Np> >
82struct is_placeholder<placeholders::__ph<_Np> >
7783 : public integral_constant<int, _Np> {};
7884
7985
......@@ -97,7 +103,7 @@ __mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>)
97103
98104template <class _Ti, class ..._Uj>
99105inline _LIBCPP_INLINE_VISIBILITY
100typename _EnableIf
106typename __enable_if_t
101107<
102108 is_bind_expression<_Ti>::value,
103109 __invoke_of<_Ti&, _Uj...>
......@@ -304,7 +310,7 @@ public:
304310};
305311
306312template<class _Fp, class ..._BoundArgs>
307struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {};
313struct is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {};
308314
309315template<class _Rp, class _Fp, class ..._BoundArgs>
310316class __bind_r
......@@ -359,7 +365,7 @@ public:
359365};
360366
361367template<class _Rp, class _Fp, class ..._BoundArgs>
362struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {};
368struct is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {};
363369
364370template<class _Fp, class ..._BoundArgs>
365371inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
lib/libcxx/include/__functional/bind_back.h created+65
......@@ -0,0 +1,65 @@
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_BIND_BACK_H
11#define _LIBCPP___FUNCTIONAL_BIND_BACK_H
12
13#include <__config>
14#include <__functional/invoke.h>
15#include <__functional/perfect_forward.h>
16#include <__utility/forward.h>
17#include <__utility/integer_sequence.h>
18#include <tuple>
19#include <type_traits>
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 <size_t _NBound, class = make_index_sequence<_NBound>>
30struct __bind_back_op;
31
32template <size_t _NBound, size_t ..._Ip>
33struct __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))...); }
40};
41
42template <class _Fn, class _BoundArgs>
43struct __bind_back_t : __perfect_forward<__bind_back_op<tuple_size_v<_BoundArgs>>, _Fn, _BoundArgs> {
44 using __perfect_forward<__bind_back_op<tuple_size_v<_BoundArgs>>, _Fn, _BoundArgs>::__perfect_forward;
45};
46
47template <class _Fn, class ..._Args, class = enable_if_t<
48 _And<
49 is_constructible<decay_t<_Fn>, _Fn>,
50 is_move_constructible<decay_t<_Fn>>,
51 is_constructible<decay_t<_Args>, _Args>...,
52 is_move_constructible<decay_t<_Args>>...
53 >::value
54>>
55_LIBCPP_HIDE_FROM_ABI
56constexpr auto __bind_back(_Fn&& __f, _Args&&... __args)
57 noexcept(noexcept(__bind_back_t<decay_t<_Fn>, tuple<decay_t<_Args>...>>(_VSTD::forward<_Fn>(__f), _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...))))
58 -> decltype( __bind_back_t<decay_t<_Fn>, tuple<decay_t<_Args>...>>(_VSTD::forward<_Fn>(__f), _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)))
59 { return __bind_back_t<decay_t<_Fn>, tuple<decay_t<_Args>...>>(_VSTD::forward<_Fn>(__f), _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)); }
60
61#endif // _LIBCPP_STD_VER > 17
62
63_LIBCPP_END_NAMESPACE_STD
64
65#endif // _LIBCPP___FUNCTIONAL_BIND_BACK_H
lib/libcxx/include/__functional/bind_front.h+24-18
......@@ -11,8 +11,8 @@
1111#define _LIBCPP___FUNCTIONAL_BIND_FRONT_H
1212
1313#include <__config>
14#include <__functional/perfect_forward.h>
1514#include <__functional/invoke.h>
15#include <__functional/perfect_forward.h>
1616#include <type_traits>
1717#include <utility>
1818
......@@ -24,25 +24,31 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2424
2525#if _LIBCPP_STD_VER > 17
2626
27struct __bind_front_op
28{
29 template<class... _Args>
30 constexpr static auto __call(_Args&&... __args)
31 noexcept(noexcept(_VSTD::invoke(_VSTD::forward<_Args>(__args)...)))
32 -> decltype( _VSTD::invoke(_VSTD::forward<_Args>(__args)...))
33 { return _VSTD::invoke(_VSTD::forward<_Args>(__args)...); }
27struct __bind_front_op {
28 template <class ..._Args>
29 _LIBCPP_HIDE_FROM_ABI
30 constexpr auto operator()(_Args&& ...__args) const
31 noexcept(noexcept(_VSTD::invoke(_VSTD::forward<_Args>(__args)...)))
32 -> decltype( _VSTD::invoke(_VSTD::forward<_Args>(__args)...))
33 { return _VSTD::invoke(_VSTD::forward<_Args>(__args)...); }
34};
35
36template <class _Fn, class ..._BoundArgs>
37struct __bind_front_t : __perfect_forward<__bind_front_op, _Fn, _BoundArgs...> {
38 using __perfect_forward<__bind_front_op, _Fn, _BoundArgs...>::__perfect_forward;
3439};
3540
36template<class _Fn, class... _Args,
37 class = _EnableIf<conjunction<is_constructible<decay_t<_Fn>, _Fn>,
38 is_move_constructible<decay_t<_Fn>>,
39 is_constructible<decay_t<_Args>, _Args>...,
40 is_move_constructible<decay_t<_Args>>...
41 >::value>>
42constexpr auto bind_front(_Fn&& __f, _Args&&... __args)
43{
44 return __perfect_forward<__bind_front_op, _Fn, _Args...>(_VSTD::forward<_Fn>(__f),
45 _VSTD::forward<_Args>(__args)...);
41template <class _Fn, class... _Args, class = enable_if_t<
42 _And<
43 is_constructible<decay_t<_Fn>, _Fn>,
44 is_move_constructible<decay_t<_Fn>>,
45 is_constructible<decay_t<_Args>, _Args>...,
46 is_move_constructible<decay_t<_Args>>...
47 >::value
48>>
49_LIBCPP_HIDE_FROM_ABI
50constexpr auto bind_front(_Fn&& __f, _Args&&... __args) {
51 return __bind_front_t<decay_t<_Fn>, decay_t<_Args>...>(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...);
4652}
4753
4854#endif // _LIBCPP_STD_VER > 17
lib/libcxx/include/__functional/compose.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___FUNCTIONAL_COMPOSE_H
11#define _LIBCPP___FUNCTIONAL_COMPOSE_H
12
13#include <__config>
14#include <__functional/invoke.h>
15#include <__functional/perfect_forward.h>
16#include <__utility/forward.h>
17#include <type_traits>
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
27struct __compose_op {
28 template<class _Fn1, class _Fn2, class ..._Args>
29 _LIBCPP_HIDE_FROM_ABI
30 constexpr auto operator()(_Fn1&& __f1, _Fn2&& __f2, _Args&&... __args) const
31 noexcept(noexcept(_VSTD::invoke(_VSTD::forward<_Fn1>(__f1), _VSTD::invoke(_VSTD::forward<_Fn2>(__f2), _VSTD::forward<_Args>(__args)...))))
32 -> decltype( _VSTD::invoke(_VSTD::forward<_Fn1>(__f1), _VSTD::invoke(_VSTD::forward<_Fn2>(__f2), _VSTD::forward<_Args>(__args)...)))
33 { return _VSTD::invoke(_VSTD::forward<_Fn1>(__f1), _VSTD::invoke(_VSTD::forward<_Fn2>(__f2), _VSTD::forward<_Args>(__args)...)); }
34};
35
36template <class _Fn1, class _Fn2>
37struct __compose_t : __perfect_forward<__compose_op, _Fn1, _Fn2> {
38 using __perfect_forward<__compose_op, _Fn1, _Fn2>::__perfect_forward;
39};
40
41template <class _Fn1, class _Fn2>
42_LIBCPP_HIDE_FROM_ABI
43constexpr auto __compose(_Fn1&& __f1, _Fn2&& __f2)
44 noexcept(noexcept(__compose_t<decay_t<_Fn1>, decay_t<_Fn2>>(_VSTD::forward<_Fn1>(__f1), _VSTD::forward<_Fn2>(__f2))))
45 -> decltype( __compose_t<decay_t<_Fn1>, decay_t<_Fn2>>(_VSTD::forward<_Fn1>(__f1), _VSTD::forward<_Fn2>(__f2)))
46 { return __compose_t<decay_t<_Fn1>, decay_t<_Fn2>>(_VSTD::forward<_Fn1>(__f1), _VSTD::forward<_Fn2>(__f2)); }
47
48#endif // _LIBCPP_STD_VER > 17
49
50_LIBCPP_END_NAMESPACE_STD
51
52#endif // _LIBCPP___FUNCTIONAL_COMPOSE_H
lib/libcxx/include/__functional/function.h+31-30
......@@ -11,10 +11,12 @@
1111#define _LIBCPP___FUNCTIONAL_FUNCTION_H
1212
1313#include <__config>
14#include <__debug>
1415#include <__functional/binary_function.h>
1516#include <__functional/invoke.h>
1617#include <__functional/unary_function.h>
1718#include <__iterator/iterator_traits.h>
19#include <__memory/addressof.h>
1820#include <__memory/allocator_traits.h>
1921#include <__memory/compressed_pair.h>
2022#include <__memory/shared_ptr.h>
......@@ -34,10 +36,17 @@ _LIBCPP_BEGIN_NAMESPACE_STD
3436class _LIBCPP_EXCEPTION_ABI bad_function_call
3537 : public exception
3638{
37#ifdef _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
3839public:
40// Note that when a key function is not used, every translation unit that uses
41// bad_function_call will end up containing a weak definition of the vtable and
42// typeinfo.
43#ifdef _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
3944 virtual ~bad_function_call() _NOEXCEPT;
45#else
46 virtual ~bad_function_call() _NOEXCEPT {}
47#endif
4048
49#ifdef _LIBCPP_ABI_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE
4150 virtual const char* what() const _NOEXCEPT;
4251#endif
4352};
......@@ -126,8 +135,8 @@ class __alloc_func<_Fp, _Ap, _Rp(_ArgTypes...)>
126135 __compressed_pair<_Fp, _Ap> __f_;
127136
128137 public:
129 typedef _LIBCPP_NODEBUG_TYPE _Fp _Target;
130 typedef _LIBCPP_NODEBUG_TYPE _Ap _Alloc;
138 typedef _LIBCPP_NODEBUG _Fp _Target;
139 typedef _LIBCPP_NODEBUG _Ap _Alloc;
131140
132141 _LIBCPP_INLINE_VISIBILITY
133142 const _Target& __target() const { return __f_.first(); }
......@@ -204,7 +213,7 @@ class __default_alloc_func<_Fp, _Rp(_ArgTypes...)> {
204213 _Fp __f_;
205214
206215public:
207 typedef _LIBCPP_NODEBUG_TYPE _Fp _Target;
216 typedef _LIBCPP_NODEBUG _Fp _Target;
208217
209218 _LIBCPP_INLINE_VISIBILITY
210219 const _Target& __target() const { return __f_; }
......@@ -352,7 +361,7 @@ const void*
352361__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT
353362{
354363 if (__ti == typeid(_Fp))
355 return &__f_.__target();
364 return _VSTD::addressof(__f_.__target());
356365 return nullptr;
357366}
358367
......@@ -938,7 +947,7 @@ public:
938947
939948#endif // _LIBCPP_HAS_EXTENSION_BLOCKS && !_LIBCPP_HAS_OBJC_ARC
940949
941} // __function
950} // namespace __function
942951
943952template<class _Rp, class ..._ArgTypes>
944953class _LIBCPP_TEMPLATE_VIS function<_Rp(_ArgTypes...)>
......@@ -1044,7 +1053,7 @@ public:
10441053#endif // _LIBCPP_NO_RTTI
10451054};
10461055
1047#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
1056#if _LIBCPP_STD_VER >= 17
10481057template<class _Rp, class ..._Ap>
10491058function(_Rp(*)(_Ap...)) -> function<_Rp(_Ap...)>;
10501059
......@@ -1089,7 +1098,7 @@ struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile & noexcept> { usin
10891098
10901099template<class _Fp, class _Stripped = typename __strip_signature<decltype(&_Fp::operator())>::type>
10911100function(_Fp) -> function<_Stripped>;
1092#endif // !_LIBCPP_HAS_NO_DEDUCTION_GUIDES
1101#endif // _LIBCPP_STD_VER >= 17
10931102
10941103template<class _Rp, class ..._ArgTypes>
10951104function<_Rp(_ArgTypes...)>::function(const function& __f) : __f_(__f.__f_) {}
......@@ -1384,7 +1393,7 @@ const void*
13841393__func<_Fp, _Alloc, _Rp()>::target(const type_info& __ti) const
13851394{
13861395 if (__ti == typeid(_Fp))
1387 return &__f_.first();
1396 return _VSTD::addressof(__f_.first());
13881397 return (const void*)0;
13891398}
13901399
......@@ -1655,7 +1664,7 @@ __func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::target_type() const
16551664
16561665#endif // _LIBCPP_NO_RTTI
16571666
1658} // __function
1667} // namespace __function
16591668
16601669template<class _Rp>
16611670class _LIBCPP_TEMPLATE_VIS function<_Rp()>
......@@ -1709,13 +1718,11 @@ public:
17091718 // 20.7.16.2.3, function capacity:
17101719 _LIBCPP_INLINE_VISIBILITY explicit operator bool() const {return __f_;}
17111720
1712private:
1713 // deleted overloads close possible hole in the type system
17141721 template<class _R2>
1715 bool operator==(const function<_R2()>&) const;// = delete;
1722 bool operator==(const function<_R2()>&) const = delete;
17161723 template<class _R2>
1717 bool operator!=(const function<_R2()>&) const;// = delete;
1718public:
1724 bool operator!=(const function<_R2()>&) const = delete;
1725
17191726 // 20.7.16.2.4, function invocation:
17201727 _Rp operator()() const;
17211728
......@@ -1989,13 +1996,11 @@ public:
19891996 // 20.7.16.2.3, function capacity:
19901997 _LIBCPP_INLINE_VISIBILITY explicit operator bool() const {return __f_;}
19911998
1992private:
1993 // deleted overloads close possible hole in the type system
19941999 template<class _R2, class _B0>
1995 bool operator==(const function<_R2(_B0)>&) const;// = delete;
2000 bool operator==(const function<_R2(_B0)>&) const = delete;
19962001 template<class _R2, class _B0>
1997 bool operator!=(const function<_R2(_B0)>&) const;// = delete;
1998public:
2002 bool operator!=(const function<_R2(_B0)>&) const = delete;
2003
19992004 // 20.7.16.2.4, function invocation:
20002005 _Rp operator()(_A0) const;
20012006
......@@ -2269,13 +2274,11 @@ public:
22692274 // 20.7.16.2.3, function capacity:
22702275 _LIBCPP_INLINE_VISIBILITY explicit operator bool() const {return __f_;}
22712276
2272private:
2273 // deleted overloads close possible hole in the type system
22742277 template<class _R2, class _B0, class _B1>
2275 bool operator==(const function<_R2(_B0, _B1)>&) const;// = delete;
2278 bool operator==(const function<_R2(_B0, _B1)>&) const = delete;
22762279 template<class _R2, class _B0, class _B1>
2277 bool operator!=(const function<_R2(_B0, _B1)>&) const;// = delete;
2278public:
2280 bool operator!=(const function<_R2(_B0, _B1)>&) const = delete;
2281
22792282 // 20.7.16.2.4, function invocation:
22802283 _Rp operator()(_A0, _A1) const;
22812284
......@@ -2548,13 +2551,11 @@ public:
25482551 // 20.7.16.2.3, function capacity:
25492552 _LIBCPP_INLINE_VISIBILITY explicit operator bool() const {return __f_;}
25502553
2551private:
2552 // deleted overloads close possible hole in the type system
25532554 template<class _R2, class _B0, class _B1, class _B2>
2554 bool operator==(const function<_R2(_B0, _B1, _B2)>&) const;// = delete;
2555 bool operator==(const function<_R2(_B0, _B1, _B2)>&) const = delete;
25552556 template<class _R2, class _B0, class _B1, class _B2>
2556 bool operator!=(const function<_R2(_B0, _B1, _B2)>&) const;// = delete;
2557public:
2557 bool operator!=(const function<_R2(_B0, _B1, _B2)>&) const = delete;
2558
25582559 // 20.7.16.2.4, function invocation:
25592560 _Rp operator()(_A0, _A1, _A2) const;
25602561
lib/libcxx/include/__functional/hash.h+8-11
......@@ -16,9 +16,9 @@
1616#include <__utility/move.h>
1717#include <__utility/pair.h>
1818#include <__utility/swap.h>
19#include <cstddef>
1920#include <cstdint>
2021#include <cstring>
21#include <cstddef>
2222#include <limits>
2323#include <type_traits>
2424
......@@ -26,9 +26,6 @@
2626#pragma GCC system_header
2727#endif
2828
29_LIBCPP_PUSH_MACROS
30#include <__undef_macros>
31
3229_LIBCPP_BEGIN_NAMESPACE_STD
3330
3431template <class _Size>
......@@ -564,6 +561,7 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
564561
565562#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
566563
564#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
567565_LIBCPP_SUPPRESS_DEPRECATED_PUSH
568566template <>
569567struct _LIBCPP_TEMPLATE_VIS hash<wchar_t>
......@@ -579,6 +577,7 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
579577 _LIBCPP_INLINE_VISIBILITY
580578 size_t operator()(wchar_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
581579};
580#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
582581
583582_LIBCPP_SUPPRESS_DEPRECATED_PUSH
584583template <>
......@@ -839,35 +838,33 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
839838
840839#ifndef _LIBCPP_CXX03_LANG
841840template <class _Key, class _Hash>
842using __check_hash_requirements _LIBCPP_NODEBUG_TYPE = integral_constant<bool,
841using __check_hash_requirements _LIBCPP_NODEBUG = integral_constant<bool,
843842 is_copy_constructible<_Hash>::value &&
844843 is_move_constructible<_Hash>::value &&
845844 __invokable_r<size_t, _Hash, _Key const&>::value
846845>;
847846
848847template <class _Key, class _Hash = hash<_Key> >
849using __has_enabled_hash _LIBCPP_NODEBUG_TYPE = integral_constant<bool,
848using __has_enabled_hash _LIBCPP_NODEBUG = integral_constant<bool,
850849 __check_hash_requirements<_Key, _Hash>::value &&
851850 is_default_constructible<_Hash>::value
852851>;
853852
854853#if _LIBCPP_STD_VER > 14
855854template <class _Type, class>
856using __enable_hash_helper_imp _LIBCPP_NODEBUG_TYPE = _Type;
855using __enable_hash_helper_imp _LIBCPP_NODEBUG = _Type;
857856
858857template <class _Type, class ..._Keys>
859using __enable_hash_helper _LIBCPP_NODEBUG_TYPE = __enable_hash_helper_imp<_Type,
858using __enable_hash_helper _LIBCPP_NODEBUG = __enable_hash_helper_imp<_Type,
860859 typename enable_if<__all<__has_enabled_hash<_Keys>::value...>::value>::type
861860>;
862861#else
863862template <class _Type, class ...>
864using __enable_hash_helper _LIBCPP_NODEBUG_TYPE = _Type;
863using __enable_hash_helper _LIBCPP_NODEBUG = _Type;
865864#endif
866865
867866#endif // !_LIBCPP_CXX03_LANG
868867
869868_LIBCPP_END_NAMESPACE_STD
870869
871_LIBCPP_POP_MACROS
872
873870#endif // _LIBCPP___FUNCTIONAL_HASH_H
lib/libcxx/include/__functional/mem_fn.h+1-1
......@@ -11,9 +11,9 @@
1111#define _LIBCPP___FUNCTIONAL_MEM_FN_H
1212
1313#include <__config>
14#include <__functional/weak_result_type.h>
1514#include <__functional/binary_function.h>
1615#include <__functional/invoke.h>
16#include <__functional/weak_result_type.h>
1717#include <utility>
1818
1919#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
lib/libcxx/include/__functional/mem_fun_ref.h+1-1
......@@ -11,8 +11,8 @@
1111#define _LIBCPP___FUNCTIONAL_MEM_FUN_REF_H
1212
1313#include <__config>
14#include <__functional/unary_function.h>
1514#include <__functional/binary_function.h>
15#include <__functional/unary_function.h>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1818#pragma GCC system_header
lib/libcxx/include/__functional/not_fn.h+20-14
......@@ -11,8 +11,8 @@
1111#define _LIBCPP___FUNCTIONAL_NOT_FN_H
1212
1313#include <__config>
14#include <__functional/perfect_forward.h>
1514#include <__functional/invoke.h>
15#include <__functional/perfect_forward.h>
1616#include <utility>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -23,21 +23,27 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2323
2424#if _LIBCPP_STD_VER > 14
2525
26struct __not_fn_op
27{
28 template<class... _Args>
29 static _LIBCPP_CONSTEXPR_AFTER_CXX17 auto __call(_Args&&... __args)
30 noexcept(noexcept(!_VSTD::invoke(_VSTD::forward<_Args>(__args)...)))
31 -> decltype( !_VSTD::invoke(_VSTD::forward<_Args>(__args)...))
32 { return !_VSTD::invoke(_VSTD::forward<_Args>(__args)...); }
26struct __not_fn_op {
27 template <class... _Args>
28 _LIBCPP_HIDE_FROM_ABI
29 _LIBCPP_CONSTEXPR_AFTER_CXX17 auto operator()(_Args&&... __args) const
30 noexcept(noexcept(!_VSTD::invoke(_VSTD::forward<_Args>(__args)...)))
31 -> decltype( !_VSTD::invoke(_VSTD::forward<_Args>(__args)...))
32 { return !_VSTD::invoke(_VSTD::forward<_Args>(__args)...); }
33};
34
35template <class _Fn>
36struct __not_fn_t : __perfect_forward<__not_fn_op, _Fn> {
37 using __perfect_forward<__not_fn_op, _Fn>::__perfect_forward;
3338};
3439
35template<class _Fn,
36 class = _EnableIf<is_constructible_v<decay_t<_Fn>, _Fn> &&
37 is_move_constructible_v<_Fn>>>
38_LIBCPP_CONSTEXPR_AFTER_CXX17 auto not_fn(_Fn&& __f)
39{
40 return __perfect_forward<__not_fn_op, _Fn>(_VSTD::forward<_Fn>(__f));
40template <class _Fn, class = enable_if_t<
41 is_constructible_v<decay_t<_Fn>, _Fn> &&
42 is_move_constructible_v<decay_t<_Fn>>
43>>
44_LIBCPP_HIDE_FROM_ABI
45_LIBCPP_CONSTEXPR_AFTER_CXX17 auto not_fn(_Fn&& __f) {
46 return __not_fn_t<decay_t<_Fn>>(_VSTD::forward<_Fn>(__f));
4147}
4248
4349#endif // _LIBCPP_STD_VER > 14
lib/libcxx/include/__functional/operations.h+57-57
......@@ -53,9 +53,9 @@ struct _LIBCPP_TEMPLATE_VIS plus<void>
5353 template <class _T1, class _T2>
5454 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
5555 auto operator()(_T1&& __t, _T2&& __u) const
56 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
57 -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
58 { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
56 noexcept(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
57 -> decltype( _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
58 { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
5959 typedef void is_transparent;
6060};
6161#endif
......@@ -90,9 +90,9 @@ struct _LIBCPP_TEMPLATE_VIS minus<void>
9090 template <class _T1, class _T2>
9191 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
9292 auto operator()(_T1&& __t, _T2&& __u) const
93 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u)))
94 -> decltype (_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u))
95 { return _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u); }
93 noexcept(noexcept(_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u)))
94 -> decltype( _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u))
95 { return _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u); }
9696 typedef void is_transparent;
9797};
9898#endif
......@@ -127,9 +127,9 @@ struct _LIBCPP_TEMPLATE_VIS multiplies<void>
127127 template <class _T1, class _T2>
128128 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
129129 auto operator()(_T1&& __t, _T2&& __u) const
130 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u)))
131 -> decltype (_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u))
132 { return _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); }
130 noexcept(noexcept(_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u)))
131 -> decltype( _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u))
132 { return _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); }
133133 typedef void is_transparent;
134134};
135135#endif
......@@ -164,9 +164,9 @@ struct _LIBCPP_TEMPLATE_VIS divides<void>
164164 template <class _T1, class _T2>
165165 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
166166 auto operator()(_T1&& __t, _T2&& __u) const
167 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u)))
168 -> decltype (_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u))
169 { return _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); }
167 noexcept(noexcept(_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u)))
168 -> decltype( _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u))
169 { return _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); }
170170 typedef void is_transparent;
171171};
172172#endif
......@@ -201,9 +201,9 @@ struct _LIBCPP_TEMPLATE_VIS modulus<void>
201201 template <class _T1, class _T2>
202202 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
203203 auto operator()(_T1&& __t, _T2&& __u) const
204 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u)))
205 -> decltype (_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u))
206 { return _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); }
204 noexcept(noexcept(_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u)))
205 -> decltype( _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u))
206 { return _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); }
207207 typedef void is_transparent;
208208};
209209#endif
......@@ -237,9 +237,9 @@ struct _LIBCPP_TEMPLATE_VIS negate<void>
237237 template <class _Tp>
238238 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
239239 auto operator()(_Tp&& __x) const
240 _NOEXCEPT_(noexcept(- _VSTD::forward<_Tp>(__x)))
241 -> decltype (- _VSTD::forward<_Tp>(__x))
242 { return - _VSTD::forward<_Tp>(__x); }
240 noexcept(noexcept(- _VSTD::forward<_Tp>(__x)))
241 -> decltype( - _VSTD::forward<_Tp>(__x))
242 { return - _VSTD::forward<_Tp>(__x); }
243243 typedef void is_transparent;
244244};
245245#endif
......@@ -276,9 +276,9 @@ struct _LIBCPP_TEMPLATE_VIS bit_and<void>
276276 template <class _T1, class _T2>
277277 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
278278 auto operator()(_T1&& __t, _T2&& __u) const
279 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u)))
280 -> decltype (_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u))
281 { return _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); }
279 noexcept(noexcept(_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u)))
280 -> decltype( _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u))
281 { return _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); }
282282 typedef void is_transparent;
283283};
284284#endif
......@@ -307,9 +307,9 @@ struct _LIBCPP_TEMPLATE_VIS bit_not<void>
307307 template <class _Tp>
308308 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
309309 auto operator()(_Tp&& __x) const
310 _NOEXCEPT_(noexcept(~_VSTD::forward<_Tp>(__x)))
311 -> decltype (~_VSTD::forward<_Tp>(__x))
312 { return ~_VSTD::forward<_Tp>(__x); }
310 noexcept(noexcept(~_VSTD::forward<_Tp>(__x)))
311 -> decltype( ~_VSTD::forward<_Tp>(__x))
312 { return ~_VSTD::forward<_Tp>(__x); }
313313 typedef void is_transparent;
314314};
315315#endif
......@@ -344,9 +344,9 @@ struct _LIBCPP_TEMPLATE_VIS bit_or<void>
344344 template <class _T1, class _T2>
345345 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
346346 auto operator()(_T1&& __t, _T2&& __u) const
347 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u)))
348 -> decltype (_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u))
349 { return _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); }
347 noexcept(noexcept(_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u)))
348 -> decltype( _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u))
349 { return _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); }
350350 typedef void is_transparent;
351351};
352352#endif
......@@ -381,9 +381,9 @@ struct _LIBCPP_TEMPLATE_VIS bit_xor<void>
381381 template <class _T1, class _T2>
382382 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
383383 auto operator()(_T1&& __t, _T2&& __u) const
384 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u)))
385 -> decltype (_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u))
386 { return _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); }
384 noexcept(noexcept(_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u)))
385 -> decltype( _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u))
386 { return _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); }
387387 typedef void is_transparent;
388388};
389389#endif
......@@ -420,9 +420,9 @@ struct _LIBCPP_TEMPLATE_VIS equal_to<void>
420420 template <class _T1, class _T2>
421421 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
422422 auto operator()(_T1&& __t, _T2&& __u) const
423 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u)))
424 -> decltype (_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u))
425 { return _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); }
423 noexcept(noexcept(_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u)))
424 -> decltype( _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u))
425 { return _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); }
426426 typedef void is_transparent;
427427};
428428#endif
......@@ -457,9 +457,9 @@ struct _LIBCPP_TEMPLATE_VIS not_equal_to<void>
457457 template <class _T1, class _T2>
458458 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
459459 auto operator()(_T1&& __t, _T2&& __u) const
460 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u)))
461 -> decltype (_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u))
462 { return _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); }
460 noexcept(noexcept(_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u)))
461 -> decltype( _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u))
462 { return _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); }
463463 typedef void is_transparent;
464464};
465465#endif
......@@ -494,9 +494,9 @@ struct _LIBCPP_TEMPLATE_VIS less<void>
494494 template <class _T1, class _T2>
495495 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
496496 auto operator()(_T1&& __t, _T2&& __u) const
497 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u)))
498 -> decltype (_VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u))
499 { return _VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u); }
497 noexcept(noexcept(_VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u)))
498 -> decltype( _VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u))
499 { return _VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u); }
500500 typedef void is_transparent;
501501};
502502#endif
......@@ -531,9 +531,9 @@ struct _LIBCPP_TEMPLATE_VIS less_equal<void>
531531 template <class _T1, class _T2>
532532 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
533533 auto operator()(_T1&& __t, _T2&& __u) const
534 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u)))
535 -> decltype (_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u))
536 { return _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); }
534 noexcept(noexcept(_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u)))
535 -> decltype( _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u))
536 { return _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); }
537537 typedef void is_transparent;
538538};
539539#endif
......@@ -568,9 +568,9 @@ struct _LIBCPP_TEMPLATE_VIS greater_equal<void>
568568 template <class _T1, class _T2>
569569 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
570570 auto operator()(_T1&& __t, _T2&& __u) const
571 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u)))
572 -> decltype (_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u))
573 { return _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); }
571 noexcept(noexcept(_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u)))
572 -> decltype( _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u))
573 { return _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); }
574574 typedef void is_transparent;
575575};
576576#endif
......@@ -605,9 +605,9 @@ struct _LIBCPP_TEMPLATE_VIS greater<void>
605605 template <class _T1, class _T2>
606606 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
607607 auto operator()(_T1&& __t, _T2&& __u) const
608 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u)))
609 -> decltype (_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u))
610 { return _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u); }
608 noexcept(noexcept(_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u)))
609 -> decltype( _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u))
610 { return _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u); }
611611 typedef void is_transparent;
612612};
613613#endif
......@@ -644,9 +644,9 @@ struct _LIBCPP_TEMPLATE_VIS logical_and<void>
644644 template <class _T1, class _T2>
645645 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
646646 auto operator()(_T1&& __t, _T2&& __u) const
647 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u)))
648 -> decltype (_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u))
649 { return _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); }
647 noexcept(noexcept(_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u)))
648 -> decltype( _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u))
649 { return _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); }
650650 typedef void is_transparent;
651651};
652652#endif
......@@ -680,9 +680,9 @@ struct _LIBCPP_TEMPLATE_VIS logical_not<void>
680680 template <class _Tp>
681681 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
682682 auto operator()(_Tp&& __x) const
683 _NOEXCEPT_(noexcept(!_VSTD::forward<_Tp>(__x)))
684 -> decltype (!_VSTD::forward<_Tp>(__x))
685 { return !_VSTD::forward<_Tp>(__x); }
683 noexcept(noexcept(!_VSTD::forward<_Tp>(__x)))
684 -> decltype( !_VSTD::forward<_Tp>(__x))
685 { return !_VSTD::forward<_Tp>(__x); }
686686 typedef void is_transparent;
687687};
688688#endif
......@@ -717,9 +717,9 @@ struct _LIBCPP_TEMPLATE_VIS logical_or<void>
717717 template <class _T1, class _T2>
718718 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
719719 auto operator()(_T1&& __t, _T2&& __u) const
720 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u)))
721 -> decltype (_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u))
722 { return _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); }
720 noexcept(noexcept(_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u)))
721 -> decltype( _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u))
722 { return _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); }
723723 typedef void is_transparent;
724724};
725725#endif
lib/libcxx/include/__functional/perfect_forward.h+59-52
......@@ -11,9 +11,11 @@
1111#define _LIBCPP___FUNCTIONAL_PERFECT_FORWARD_H
1212
1313#include <__config>
14#include <__utility/declval.h>
15#include <__utility/forward.h>
16#include <__utility/move.h>
1417#include <tuple>
1518#include <type_traits>
16#include <utility>
1719
1820#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1921#pragma GCC system_header
......@@ -23,63 +25,68 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2325
2426#if _LIBCPP_STD_VER > 14
2527
26template<class _Op, class _Tuple,
27 class _Idxs = typename __make_tuple_indices<tuple_size<_Tuple>::value>::type>
28template <class _Op, class _Indices, class ..._Bound>
2829struct __perfect_forward_impl;
2930
30template<class _Op, class... _Bound, size_t... _Idxs>
31struct __perfect_forward_impl<_Op, __tuple_types<_Bound...>, __tuple_indices<_Idxs...>>
32{
31template <class _Op, size_t ..._Idx, class ..._Bound>
32struct __perfect_forward_impl<_Op, index_sequence<_Idx...>, _Bound...> {
33private:
3334 tuple<_Bound...> __bound_;
3435
35 template<class... _Args>
36 _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) &
37 noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...)))
38 -> decltype( _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...))
39 {return _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...);}
40
41 template<class... _Args>
42 _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) const&
43 noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...)))
44 -> decltype( _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...))
45 {return _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...);}
46
47 template<class... _Args>
48 _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) &&
49 noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
50 _VSTD::forward<_Args>(__args)...)))
51 -> decltype( _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
52 _VSTD::forward<_Args>(__args)...))
53 {return _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
54 _VSTD::forward<_Args>(__args)...);}
55
56 template<class... _Args>
57 _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) const&&
58 noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
59 _VSTD::forward<_Args>(__args)...)))
60 -> decltype( _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
61 _VSTD::forward<_Args>(__args)...))
62 {return _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
63 _VSTD::forward<_Args>(__args)...);}
64
65 template<class _Fn = typename tuple_element<0, tuple<_Bound...>>::type,
66 class = _EnableIf<is_copy_constructible_v<_Fn>>>
67 constexpr __perfect_forward_impl(__perfect_forward_impl const& __other)
68 : __bound_(__other.__bound_) {}
69
70 template<class _Fn = typename tuple_element<0, tuple<_Bound...>>::type,
71 class = _EnableIf<is_move_constructible_v<_Fn>>>
72 constexpr __perfect_forward_impl(__perfect_forward_impl && __other)
73 : __bound_(_VSTD::move(__other.__bound_)) {}
74
75 template<class... _BoundArgs>
76 explicit constexpr __perfect_forward_impl(_BoundArgs&&... __bound) :
77 __bound_(_VSTD::forward<_BoundArgs>(__bound)...) { }
36public:
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;
7885};
7986
80template<class _Op, class... _Args>
81using __perfect_forward =
82 __perfect_forward_impl<_Op, __tuple_types<decay_t<_Args>...>>;
87// __perfect_forward implements a perfect-forwarding call wrapper as explained in [func.require].
88template <class _Op, class ..._Args>
89using __perfect_forward = __perfect_forward_impl<_Op, index_sequence_for<_Args...>, _Args...>;
8390
8491#endif // _LIBCPP_STD_VER > 14
8592
lib/libcxx/include/__functional/ranges_operations.h+3-2
......@@ -20,7 +20,8 @@
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
2222
23#if !defined(_LIBCPP_HAS_NO_RANGES)
23#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
24
2425namespace ranges {
2526
2627struct equal_to {
......@@ -90,7 +91,7 @@ struct greater_equal {
9091};
9192
9293} // namespace ranges
93#endif // !defined(_LIBCPP_HAS_NO_RANGES)
94#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
9495
9596_LIBCPP_END_NAMESPACE_STD
9697
lib/libcxx/include/__functional/reference_wrapper.h+4-15
......@@ -34,25 +34,16 @@ public:
3434private:
3535 type* __f_;
3636
37#ifndef _LIBCPP_CXX03_LANG
3837 static void __fun(_Tp&) _NOEXCEPT;
3938 static void __fun(_Tp&&) = delete;
40#endif
4139
4240public:
43 // construct/copy/destroy
44#ifdef _LIBCPP_CXX03_LANG
45 _LIBCPP_INLINE_VISIBILITY
46 reference_wrapper(type& __f) _NOEXCEPT
47 : __f_(_VSTD::addressof(__f)) {}
48#else
49 template <class _Up, class = _EnableIf<!__is_same_uncvref<_Up, reference_wrapper>::value, decltype(__fun(declval<_Up>())) >>
41 template <class _Up, class = __enable_if_t<!__is_same_uncvref<_Up, reference_wrapper>::value, decltype(__fun(declval<_Up>())) > >
5042 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
5143 reference_wrapper(_Up&& __u) _NOEXCEPT_(noexcept(__fun(declval<_Up>()))) {
5244 type& __f = static_cast<_Up&&>(__u);
5345 __f_ = _VSTD::addressof(__f);
5446 }
55#endif
5647
5748 // access
5849 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
......@@ -176,7 +167,7 @@ public:
176167#endif // _LIBCPP_CXX03_LANG
177168};
178169
179#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
170#if _LIBCPP_STD_VER > 14
180171template <class _Tp>
181172reference_wrapper(_Tp&) -> reference_wrapper<_Tp>;
182173#endif
......@@ -194,7 +185,7 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
194185reference_wrapper<_Tp>
195186ref(reference_wrapper<_Tp> __t) _NOEXCEPT
196187{
197 return _VSTD::ref(__t.get());
188 return __t;
198189}
199190
200191template <class _Tp>
......@@ -210,13 +201,11 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
210201reference_wrapper<const _Tp>
211202cref(reference_wrapper<_Tp> __t) _NOEXCEPT
212203{
213 return _VSTD::cref(__t.get());
204 return __t;
214205}
215206
216#ifndef _LIBCPP_CXX03_LANG
217207template <class _Tp> void ref(const _Tp&&) = delete;
218208template <class _Tp> void cref(const _Tp&&) = delete;
219#endif
220209
221210_LIBCPP_END_NAMESPACE_STD
222211
lib/libcxx/include/__functional/unary_function.h-5
......@@ -15,9 +15,6 @@
1515#pragma GCC system_header
1616#endif
1717
18_LIBCPP_PUSH_MACROS
19#include <__undef_macros>
20
2118_LIBCPP_BEGIN_NAMESPACE_STD
2219
2320template <class _Arg, class _Result>
......@@ -29,6 +26,4 @@ struct _LIBCPP_TEMPLATE_VIS unary_function
2926
3027_LIBCPP_END_NAMESPACE_STD
3128
32_LIBCPP_POP_MACROS
33
3429#endif // _LIBCPP___FUNCTIONAL_UNARY_FUNCTION_H
lib/libcxx/include/__functional/unwrap_ref.h+2-7
......@@ -15,19 +15,16 @@
1515#pragma GCC system_header
1616#endif
1717
18_LIBCPP_PUSH_MACROS
19#include <__undef_macros>
20
2118_LIBCPP_BEGIN_NAMESPACE_STD
2219
2320template <class _Tp>
24struct __unwrap_reference { typedef _LIBCPP_NODEBUG_TYPE _Tp type; };
21struct __unwrap_reference { typedef _LIBCPP_NODEBUG _Tp type; };
2522
2623template <class _Tp>
2724class reference_wrapper;
2825
2926template <class _Tp>
30struct __unwrap_reference<reference_wrapper<_Tp> > { typedef _LIBCPP_NODEBUG_TYPE _Tp& type; };
27struct __unwrap_reference<reference_wrapper<_Tp> > { typedef _LIBCPP_NODEBUG _Tp& type; };
3128
3229template <class _Tp>
3330struct decay;
......@@ -57,6 +54,4 @@ struct __unwrap_ref_decay
5754
5855_LIBCPP_END_NAMESPACE_STD
5956
60_LIBCPP_POP_MACROS
61
6257#endif // _LIBCPP___FUNCTIONAL_UNWRAP_REF_H
lib/libcxx/include/__functional/weak_result_type.h+4-4
......@@ -89,7 +89,7 @@ struct __weak_result_type_imp // bool is true
8989 : public __maybe_derive_from_unary_function<_Tp>,
9090 public __maybe_derive_from_binary_function<_Tp>
9191{
92 typedef _LIBCPP_NODEBUG_TYPE typename _Tp::result_type result_type;
92 typedef _LIBCPP_NODEBUG typename _Tp::result_type result_type;
9393};
9494
9595template <class _Tp>
......@@ -110,19 +110,19 @@ struct __weak_result_type
110110template <class _Rp>
111111struct __weak_result_type<_Rp ()>
112112{
113 typedef _LIBCPP_NODEBUG_TYPE _Rp result_type;
113 typedef _LIBCPP_NODEBUG _Rp result_type;
114114};
115115
116116template <class _Rp>
117117struct __weak_result_type<_Rp (&)()>
118118{
119 typedef _LIBCPP_NODEBUG_TYPE _Rp result_type;
119 typedef _LIBCPP_NODEBUG _Rp result_type;
120120};
121121
122122template <class _Rp>
123123struct __weak_result_type<_Rp (*)()>
124124{
125 typedef _LIBCPP_NODEBUG_TYPE _Rp result_type;
125 typedef _LIBCPP_NODEBUG _Rp result_type;
126126};
127127
128128// 1 argument case
lib/libcxx/include/__hash_table+40-54
......@@ -288,9 +288,7 @@ public:
288288 typedef typename _NodeTypes::__node_value_type_pointer pointer;
289289
290290 _LIBCPP_INLINE_VISIBILITY __hash_iterator() _NOEXCEPT : __node_(nullptr) {
291#if _LIBCPP_DEBUG_LEVEL == 2
292 __get_db()->__insert_i(this);
293#endif
291 _VSTD::__debug_db_insert_i(this);
294292 }
295293
296294#if _LIBCPP_DEBUG_LEVEL == 2
......@@ -298,7 +296,7 @@ public:
298296 __hash_iterator(const __hash_iterator& __i)
299297 : __node_(__i.__node_)
300298 {
301 __get_db()->__iterator_copy(this, &__i);
299 __get_db()->__iterator_copy(this, _VSTD::addressof(__i));
302300 }
303301
304302 _LIBCPP_INLINE_VISIBILITY
......@@ -310,9 +308,9 @@ public:
310308 _LIBCPP_INLINE_VISIBILITY
311309 __hash_iterator& operator=(const __hash_iterator& __i)
312310 {
313 if (this != &__i)
311 if (this != _VSTD::addressof(__i))
314312 {
315 __get_db()->__iterator_copy(this, &__i);
313 __get_db()->__iterator_copy(this, _VSTD::addressof(__i));
316314 __node_ = __i.__node_;
317315 }
318316 return *this;
......@@ -400,9 +398,7 @@ public:
400398
401399
402400 _LIBCPP_INLINE_VISIBILITY __hash_const_iterator() _NOEXCEPT : __node_(nullptr) {
403#if _LIBCPP_DEBUG_LEVEL == 2
404 __get_db()->__insert_i(this);
405#endif
401 _VSTD::__debug_db_insert_i(this);
406402 }
407403
408404 _LIBCPP_INLINE_VISIBILITY
......@@ -410,7 +406,7 @@ public:
410406 : __node_(__x.__node_)
411407 {
412408#if _LIBCPP_DEBUG_LEVEL == 2
413 __get_db()->__iterator_copy(this, &__x);
409 __get_db()->__iterator_copy(this, _VSTD::addressof(__x));
414410#endif
415411 }
416412
......@@ -419,7 +415,7 @@ public:
419415 __hash_const_iterator(const __hash_const_iterator& __i)
420416 : __node_(__i.__node_)
421417 {
422 __get_db()->__iterator_copy(this, &__i);
418 __get_db()->__iterator_copy(this, _VSTD::addressof(__i));
423419 }
424420
425421 _LIBCPP_INLINE_VISIBILITY
......@@ -431,9 +427,9 @@ public:
431427 _LIBCPP_INLINE_VISIBILITY
432428 __hash_const_iterator& operator=(const __hash_const_iterator& __i)
433429 {
434 if (this != &__i)
430 if (this != _VSTD::addressof(__i))
435431 {
436 __get_db()->__iterator_copy(this, &__i);
432 __get_db()->__iterator_copy(this, _VSTD::addressof(__i));
437433 __node_ = __i.__node_;
438434 }
439435 return *this;
......@@ -517,9 +513,7 @@ public:
517513 typedef typename _NodeTypes::__node_value_type_pointer pointer;
518514
519515 _LIBCPP_INLINE_VISIBILITY __hash_local_iterator() _NOEXCEPT : __node_(nullptr) {
520#if _LIBCPP_DEBUG_LEVEL == 2
521 __get_db()->__insert_i(this);
522#endif
516 _VSTD::__debug_db_insert_i(this);
523517 }
524518
525519#if _LIBCPP_DEBUG_LEVEL == 2
......@@ -529,7 +523,7 @@ public:
529523 __bucket_(__i.__bucket_),
530524 __bucket_count_(__i.__bucket_count_)
531525 {
532 __get_db()->__iterator_copy(this, &__i);
526 __get_db()->__iterator_copy(this, _VSTD::addressof(__i));
533527 }
534528
535529 _LIBCPP_INLINE_VISIBILITY
......@@ -541,9 +535,9 @@ public:
541535 _LIBCPP_INLINE_VISIBILITY
542536 __hash_local_iterator& operator=(const __hash_local_iterator& __i)
543537 {
544 if (this != &__i)
538 if (this != _VSTD::addressof(__i))
545539 {
546 __get_db()->__iterator_copy(this, &__i);
540 __get_db()->__iterator_copy(this, _VSTD::addressof(__i));
547541 __node_ = __i.__node_;
548542 __bucket_ = __i.__bucket_;
549543 __bucket_count_ = __i.__bucket_count_;
......@@ -651,9 +645,7 @@ public:
651645
652646
653647 _LIBCPP_INLINE_VISIBILITY __hash_const_local_iterator() _NOEXCEPT : __node_(nullptr) {
654#if _LIBCPP_DEBUG_LEVEL == 2
655 __get_db()->__insert_i(this);
656#endif
648 _VSTD::__debug_db_insert_i(this);
657649 }
658650
659651 _LIBCPP_INLINE_VISIBILITY
......@@ -663,7 +655,7 @@ public:
663655 __bucket_count_(__x.__bucket_count_)
664656 {
665657#if _LIBCPP_DEBUG_LEVEL == 2
666 __get_db()->__iterator_copy(this, &__x);
658 __get_db()->__iterator_copy(this, _VSTD::addressof(__x));
667659#endif
668660 }
669661
......@@ -674,7 +666,7 @@ public:
674666 __bucket_(__i.__bucket_),
675667 __bucket_count_(__i.__bucket_count_)
676668 {
677 __get_db()->__iterator_copy(this, &__i);
669 __get_db()->__iterator_copy(this, _VSTD::addressof(__i));
678670 }
679671
680672 _LIBCPP_INLINE_VISIBILITY
......@@ -686,9 +678,9 @@ public:
686678 _LIBCPP_INLINE_VISIBILITY
687679 __hash_const_local_iterator& operator=(const __hash_const_local_iterator& __i)
688680 {
689 if (this != &__i)
681 if (this != _VSTD::addressof(__i))
690682 {
691 __get_db()->__iterator_copy(this, &__i);
683 __get_db()->__iterator_copy(this, _VSTD::addressof(__i));
692684 __node_ = __i.__node_;
693685 __bucket_ = __i.__bucket_;
694686 __bucket_count_ = __i.__bucket_count_;
......@@ -1541,7 +1533,7 @@ template <class _Tp, class _Hash, class _Equal, class _Alloc>
15411533__hash_table<_Tp, _Hash, _Equal, _Alloc>&
15421534__hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(const __hash_table& __u)
15431535{
1544 if (this != &__u)
1536 if (this != _VSTD::addressof(__u))
15451537 {
15461538 __copy_assign_alloc(__u);
15471539 hash_function() = __u.hash_function();
......@@ -1623,7 +1615,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign(
16231615 __u.size() = 0;
16241616 }
16251617#if _LIBCPP_DEBUG_LEVEL == 2
1626 __get_db()->swap(this, &__u);
1618 __get_db()->swap(this, _VSTD::addressof(__u));
16271619#endif
16281620}
16291621
......@@ -2029,11 +2021,9 @@ typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
20292021__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(
20302022 const_iterator __p, __node_pointer __cp)
20312023{
2032#if _LIBCPP_DEBUG_LEVEL == 2
2033 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
2034 "unordered container::emplace_hint(const_iterator, args...) called with an iterator not"
2035 " referring to this unordered container");
2036#endif
2024 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
2025 "unordered container::emplace_hint(const_iterator, args...) called with an iterator not"
2026 " referring to this unordered container");
20372027 if (__p != end() && key_eq()(*__p, __cp->__value_))
20382028 {
20392029 __next_pointer __np = __p.__node_;
......@@ -2158,11 +2148,9 @@ typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
21582148__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_hint_multi(
21592149 const_iterator __p, _Args&&... __args)
21602150{
2161#if _LIBCPP_DEBUG_LEVEL == 2
2162 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
2163 "unordered container::emplace_hint(const_iterator, args...) called with an iterator not"
2164 " referring to this unordered container");
2165#endif
2151 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
2152 "unordered container::emplace_hint(const_iterator, args...) called with an iterator not"
2153 " referring to this unordered container");
21662154 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
21672155 iterator __r = __node_insert_multi(__p, __h.get());
21682156 __h.release();
......@@ -2348,7 +2336,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__rehash(size_type __nbc)
23482336 size_type __chash = __constrain_hash(__cp->__hash(), __nbc);
23492337 __bucket_list_[__chash] = __pp;
23502338 size_type __phash = __chash;
2351 for (__pp = __cp, __cp = __cp->__next_; __cp != nullptr;
2339 for (__pp = __cp, void(), __cp = __cp->__next_; __cp != nullptr;
23522340 __cp = __pp->__next_)
23532341 {
23542342 __chash = __constrain_hash(__cp->__hash(), __nbc);
......@@ -2484,12 +2472,12 @@ typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
24842472__hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __p)
24852473{
24862474 __next_pointer __np = __p.__node_;
2475 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
2476 "unordered container erase(iterator) called with an iterator not"
2477 " referring to this container");
2478 _LIBCPP_DEBUG_ASSERT(__p != end(),
2479 "unordered container erase(iterator) called with a non-dereferenceable iterator");
24872480#if _LIBCPP_DEBUG_LEVEL == 2
2488 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
2489 "unordered container erase(iterator) called with an iterator not"
2490 " referring to this container");
2491 _LIBCPP_ASSERT(__p != end(),
2492 "unordered container erase(iterator) called with a non-dereferenceable iterator");
24932481 iterator __r(__np, this);
24942482#else
24952483 iterator __r(__np);
......@@ -2504,14 +2492,12 @@ typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
25042492__hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __first,
25052493 const_iterator __last)
25062494{
2507#if _LIBCPP_DEBUG_LEVEL == 2
2508 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
2509 "unordered container::erase(iterator, iterator) called with an iterator not"
2510 " referring to this container");
2511 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__last) == this,
2512 "unordered container::erase(iterator, iterator) called with an iterator not"
2513 " referring to this container");
2514#endif
2495 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__first)) == this,
2496 "unordered container::erase(iterator, iterator) called with an iterator not"
2497 " referring to this container");
2498 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__last)) == this,
2499 "unordered container::erase(iterator, iterator) called with an iterator not"
2500 " referring to this container");
25152501 for (const_iterator __p = __first; __first != __last; __p = __first)
25162502 {
25172503 ++__first;
......@@ -2741,7 +2727,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::swap(__hash_table& __u)
27412727 __u.__bucket_list_[__constrain_hash(__u.__p1_.first().__next_->__hash(), __u.bucket_count())] =
27422728 __u.__p1_.first().__ptr();
27432729#if _LIBCPP_DEBUG_LEVEL == 2
2744 __get_db()->swap(this, &__u);
2730 __get_db()->swap(this, _VSTD::addressof(__u));
27452731#endif
27462732}
27472733
......@@ -2758,7 +2744,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::bucket_size(size_type __n) const
27582744 {
27592745 for (__np = __np->__next_; __np != nullptr &&
27602746 __constrain_hash(__np->__hash(), __bc) == __n;
2761 __np = __np->__next_, ++__r)
2747 __np = __np->__next_, (void) ++__r)
27622748 ;
27632749 }
27642750 return __r;
lib/libcxx/include/__iterator/access.h-5
......@@ -17,9 +17,6 @@
1717#pragma GCC system_header
1818#endif
1919
20_LIBCPP_PUSH_MACROS
21#include <__undef_macros>
22
2320_LIBCPP_BEGIN_NAMESPACE_STD
2421
2522template <class _Tp, size_t _Np>
......@@ -129,6 +126,4 @@ end(const _Cp& __c)
129126
130127_LIBCPP_END_NAMESPACE_STD
131128
132_LIBCPP_POP_MACROS
133
134129#endif // _LIBCPP___ITERATOR_ACCESS_H
lib/libcxx/include/__iterator/advance.h+20-21
......@@ -12,13 +12,12 @@
1212
1313#include <__config>
1414#include <__debug>
15#include <__function_like.h>
1615#include <__iterator/concepts.h>
1716#include <__iterator/incrementable_traits.h>
1817#include <__iterator/iterator_traits.h>
1918#include <__utility/move.h>
20#include <cstdlib>
2119#include <concepts>
20#include <cstdlib>
2221#include <limits>
2322#include <type_traits>
2423
......@@ -26,9 +25,6 @@
2625#pragma GCC system_header
2726#endif
2827
29_LIBCPP_PUSH_MACROS
30#include <__undef_macros>
31
3228_LIBCPP_BEGIN_NAMESPACE_STD
3329
3430template <class _InputIter>
......@@ -58,7 +54,7 @@ void __advance(_RandIter& __i, typename iterator_traits<_RandIter>::difference_t
5854template <
5955 class _InputIter, class _Distance,
6056 class _IntegralDistance = decltype(_VSTD::__convert_to_integral(declval<_Distance>())),
61 class = _EnableIf<is_integral<_IntegralDistance>::value> >
57 class = __enable_if_t<is_integral<_IntegralDistance>::value> >
6258_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
6359void advance(_InputIter& __i, _Distance __orig_n) {
6460 typedef typename iterator_traits<_InputIter>::difference_type _Difference;
......@@ -68,18 +64,15 @@ void advance(_InputIter& __i, _Distance __orig_n) {
6864 _VSTD::__advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
6965}
7066
71#if !defined(_LIBCPP_HAS_NO_RANGES)
67#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
7268
73namespace ranges {
7469// [range.iter.op.advance]
75struct __advance_fn final : private __function_like {
76private:
77 template <class _Tp>
78 _LIBCPP_HIDE_FROM_ABI
79 static constexpr _Tp __magnitude_geq(_Tp __a, _Tp __b) noexcept {
80 return __a < 0 ? (__a <= __b) : (__a >= __b);
81 }
8270
71namespace ranges {
72namespace __advance {
73
74struct __fn {
75private:
8376 template <class _Ip>
8477 _LIBCPP_HIDE_FROM_ABI
8578 static constexpr void __advance_forward(_Ip& __i, iter_difference_t<_Ip> __n) {
......@@ -99,8 +92,6 @@ private:
9992 }
10093
10194public:
102 constexpr explicit __advance_fn(__tag __x) noexcept : __function_like(__x) {}
103
10495 // Preconditions: If `I` does not model `bidirectional_iterator`, `n` is not negative.
10596 template <input_or_output_iterator _Ip>
10697 _LIBCPP_HIDE_FROM_ABI
......@@ -158,6 +149,12 @@ public:
158149 // If `S` and `I` model `sized_sentinel_for<S, I>`:
159150 if constexpr (sized_sentinel_for<_Sp, _Ip>) {
160151 // If |n| >= |bound - i|, equivalent to `ranges::advance(i, bound)`.
152 // __magnitude_geq(a, b) returns |a| >= |b|, assuming they have the same sign.
153 auto __magnitude_geq = [](auto __a, auto __b) {
154 return __a == 0 ? __b == 0 :
155 __a > 0 ? __a >= __b :
156 __a <= __b;
157 };
161158 if (const auto __M = __bound - __i; __magnitude_geq(__n, __M)) {
162159 (*this)(__i, __bound);
163160 return __n - __M;
......@@ -188,13 +185,15 @@ public:
188185 }
189186};
190187
191inline constexpr auto advance = __advance_fn(__function_like::__tag());
188} // namespace __advance
189
190inline namespace __cpo {
191 inline constexpr auto advance = __advance::__fn{};
192} // namespace __cpo
192193} // namespace ranges
193194
194#endif // !defined(_LIBCPP_HAS_NO_RANGES)
195#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
195196
196197_LIBCPP_END_NAMESPACE_STD
197198
198_LIBCPP_POP_MACROS
199
200199#endif // _LIBCPP___ITERATOR_ADVANCE_H
lib/libcxx/include/__iterator/back_insert_iterator.h+7-12
......@@ -21,9 +21,6 @@
2121#pragma GCC system_header
2222#endif
2323
24_LIBCPP_PUSH_MACROS
25#include <__undef_macros>
26
2724_LIBCPP_BEGIN_NAMESPACE_STD
2825
2926_LIBCPP_SUPPRESS_DEPRECATED_PUSH
......@@ -48,20 +45,20 @@ public:
4845 typedef void reference;
4946 typedef _Container container_type;
5047
51 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
52 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(const typename _Container::value_type& __value_)
48 _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_)
5350 {container->push_back(__value_); return *this;}
5451#ifndef _LIBCPP_CXX03_LANG
55 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(typename _Container::value_type&& __value_)
52 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(typename _Container::value_type&& __value_)
5653 {container->push_back(_VSTD::move(__value_)); return *this;}
5754#endif // _LIBCPP_CXX03_LANG
58 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator*() {return *this;}
59 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator++() {return *this;}
60 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator operator++(int) {return *this;}
55 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator*() {return *this;}
56 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator++() {return *this;}
57 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator operator++(int) {return *this;}
6158};
6259
6360template <class _Container>
64inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
61inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
6562back_insert_iterator<_Container>
6663back_inserter(_Container& __x)
6764{
......@@ -70,6 +67,4 @@ back_inserter(_Container& __x)
7067
7168_LIBCPP_END_NAMESPACE_STD
7269
73_LIBCPP_POP_MACROS
74
7570#endif // _LIBCPP___ITERATOR_BACK_INSERT_ITERATOR_H
lib/libcxx/include/__iterator/common_iterator.h+36-54
......@@ -25,12 +25,14 @@
2525#pragma GCC system_header
2626#endif
2727
28_LIBCPP_PUSH_MACROS
29#include <__undef_macros>
30
3128_LIBCPP_BEGIN_NAMESPACE_STD
3229
33#if !defined(_LIBCPP_HAS_NO_RANGES)
30#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
31
32template<class _Iter>
33concept __can_use_postfix_proxy =
34 constructible_from<iter_value_t<_Iter>, iter_reference_t<_Iter>> &&
35 move_constructible<iter_value_t<_Iter>>;
3436
3537template<input_or_output_iterator _Iter, sentinel_for<_Iter> _Sent>
3638 requires (!same_as<_Iter, _Sent> && copyable<_Iter>)
......@@ -44,7 +46,7 @@ class common_iterator {
4446 : __value(_VSTD::move(__x)) {}
4547
4648 public:
47 const iter_value_t<_Iter>* operator->() const {
49 constexpr const iter_value_t<_Iter>* operator->() const noexcept {
4850 return _VSTD::addressof(__value);
4951 }
5052 };
......@@ -57,11 +59,7 @@ class common_iterator {
5759 : __value(_VSTD::forward<iter_reference_t<_Iter>>(__x)) {}
5860
5961 public:
60 constexpr static bool __valid_for_iter =
61 constructible_from<iter_value_t<_Iter>, iter_reference_t<_Iter>> &&
62 move_constructible<iter_value_t<_Iter>>;
63
64 const iter_value_t<_Iter>& operator*() const {
62 constexpr const iter_value_t<_Iter>& operator*() const noexcept {
6563 return __value;
6664 }
6765 };
......@@ -78,7 +76,7 @@ public:
7876 requires convertible_to<const _I2&, _Iter> && convertible_to<const _S2&, _Sent>
7977 constexpr common_iterator(const common_iterator<_I2, _S2>& __other)
8078 : __hold_([&]() -> variant<_Iter, _Sent> {
81 _LIBCPP_ASSERT(!__other.__hold_.valueless_by_exception(), "Constructed from valueless iterator.");
79 _LIBCPP_ASSERT(!__other.__hold_.valueless_by_exception(), "Attempted to construct from a valueless common_iterator");
8280 if (__other.__hold_.index() == 0)
8381 return variant<_Iter, _Sent>{in_place_index<0>, _VSTD::__unchecked_get<0>(__other.__hold_)};
8482 return variant<_Iter, _Sent>{in_place_index<1>, _VSTD::__unchecked_get<1>(__other.__hold_)};
......@@ -88,7 +86,7 @@ public:
8886 requires convertible_to<const _I2&, _Iter> && convertible_to<const _S2&, _Sent> &&
8987 assignable_from<_Iter&, const _I2&> && assignable_from<_Sent&, const _S2&>
9088 common_iterator& operator=(const common_iterator<_I2, _S2>& __other) {
91 _LIBCPP_ASSERT(!__other.__hold_.valueless_by_exception(), "Assigned from valueless iterator.");
89 _LIBCPP_ASSERT(!__other.__hold_.valueless_by_exception(), "Attempted to assign from a valueless common_iterator");
9290
9391 auto __idx = __hold_.index();
9492 auto __other_idx = __other.__hold_.index();
......@@ -108,18 +106,16 @@ public:
108106 return *this;
109107 }
110108
111 decltype(auto) operator*()
109 constexpr decltype(auto) operator*()
112110 {
113 _LIBCPP_ASSERT(holds_alternative<_Iter>(__hold_),
114 "Cannot dereference sentinel. Common iterator not holding an iterator.");
111 _LIBCPP_ASSERT(holds_alternative<_Iter>(__hold_), "Attempted to dereference a non-dereferenceable common_iterator");
115112 return *_VSTD::__unchecked_get<_Iter>(__hold_);
116113 }
117114
118 decltype(auto) operator*() const
115 constexpr decltype(auto) operator*() const
119116 requires __dereferenceable<const _Iter>
120117 {
121 _LIBCPP_ASSERT(holds_alternative<_Iter>(__hold_),
122 "Cannot dereference sentinel. Common iterator not holding an iterator.");
118 _LIBCPP_ASSERT(holds_alternative<_Iter>(__hold_), "Attempted to dereference a non-dereferenceable common_iterator");
123119 return *_VSTD::__unchecked_get<_Iter>(__hold_);
124120 }
125121
......@@ -130,9 +126,7 @@ public:
130126 is_reference_v<iter_reference_t<_I2>> ||
131127 constructible_from<iter_value_t<_I2>, iter_reference_t<_I2>>)
132128 {
133 _LIBCPP_ASSERT(holds_alternative<_Iter>(__hold_),
134 "Cannot dereference sentinel. Common iterator not holding an iterator.");
135
129 _LIBCPP_ASSERT(holds_alternative<_Iter>(__hold_), "Attempted to dereference a non-dereferenceable common_iterator");
136130 if constexpr (is_pointer_v<_Iter> || requires(const _Iter& __i) { __i.operator->(); }) {
137131 return _VSTD::__unchecked_get<_Iter>(__hold_);
138132 } else if constexpr (is_reference_v<iter_reference_t<_Iter>>) {
......@@ -144,21 +138,18 @@ public:
144138 }
145139
146140 common_iterator& operator++() {
147 _LIBCPP_ASSERT(holds_alternative<_Iter>(__hold_),
148 "Cannot increment sentinel. Common iterator not holding an iterator.");
141 _LIBCPP_ASSERT(holds_alternative<_Iter>(__hold_), "Attempted to increment a non-dereferenceable common_iterator");
149142 ++_VSTD::__unchecked_get<_Iter>(__hold_); return *this;
150143 }
151144
152145 decltype(auto) operator++(int) {
153 _LIBCPP_ASSERT(holds_alternative<_Iter>(__hold_),
154 "Cannot increment sentinel. Common iterator not holding an iterator.");
155
146 _LIBCPP_ASSERT(holds_alternative<_Iter>(__hold_), "Attempted to increment a non-dereferenceable common_iterator");
156147 if constexpr (forward_iterator<_Iter>) {
157148 auto __tmp = *this;
158149 ++*this;
159150 return __tmp;
160151 } else if constexpr (requires (_Iter& __i) { { *__i++ } -> __referenceable; } ||
161 !__postfix_proxy::__valid_for_iter) {
152 !__can_use_postfix_proxy<_Iter>) {
162153 return _VSTD::__unchecked_get<_Iter>(__hold_)++;
163154 } else {
164155 __postfix_proxy __p(**this);
......@@ -169,10 +160,9 @@ public:
169160
170161 template<class _I2, sentinel_for<_Iter> _S2>
171162 requires sentinel_for<_Sent, _I2>
172 friend bool operator==(const common_iterator& __x, const common_iterator<_I2, _S2>& __y) {
173 _LIBCPP_ASSERT(!__x.__hold_.valueless_by_exception() &&
174 !__y.__hold_.valueless_by_exception(),
175 "One or both common_iterators are valueless. (Cannot compare valueless iterators.)");
163 friend constexpr bool operator==(const common_iterator& __x, const common_iterator<_I2, _S2>& __y) {
164 _LIBCPP_ASSERT(!__x.__hold_.valueless_by_exception(), "Attempted to compare a valueless common_iterator");
165 _LIBCPP_ASSERT(!__y.__hold_.valueless_by_exception(), "Attempted to compare a valueless common_iterator");
176166
177167 auto __x_index = __x.__hold_.index();
178168 auto __y_index = __y.__hold_.index();
......@@ -188,10 +178,9 @@ public:
188178
189179 template<class _I2, sentinel_for<_Iter> _S2>
190180 requires sentinel_for<_Sent, _I2> && equality_comparable_with<_Iter, _I2>
191 friend bool operator==(const common_iterator& __x, const common_iterator<_I2, _S2>& __y) {
192 _LIBCPP_ASSERT(!__x.__hold_.valueless_by_exception() &&
193 !__y.__hold_.valueless_by_exception(),
194 "One or both common_iterators are valueless. (Cannot compare valueless iterators.)");
181 friend constexpr bool operator==(const common_iterator& __x, const common_iterator<_I2, _S2>& __y) {
182 _LIBCPP_ASSERT(!__x.__hold_.valueless_by_exception(), "Attempted to compare a valueless common_iterator");
183 _LIBCPP_ASSERT(!__y.__hold_.valueless_by_exception(), "Attempted to compare a valueless common_iterator");
195184
196185 auto __x_index = __x.__hold_.index();
197186 auto __y_index = __y.__hold_.index();
......@@ -210,10 +199,9 @@ public:
210199
211200 template<sized_sentinel_for<_Iter> _I2, sized_sentinel_for<_Iter> _S2>
212201 requires sized_sentinel_for<_Sent, _I2>
213 friend iter_difference_t<_I2> operator-(const common_iterator& __x, const common_iterator<_I2, _S2>& __y) {
214 _LIBCPP_ASSERT(!__x.__hold_.valueless_by_exception() &&
215 !__y.__hold_.valueless_by_exception(),
216 "One or both common_iterators are valueless. (Cannot subtract valueless iterators.)");
202 friend constexpr iter_difference_t<_I2> operator-(const common_iterator& __x, const common_iterator<_I2, _S2>& __y) {
203 _LIBCPP_ASSERT(!__x.__hold_.valueless_by_exception(), "Attempted to subtract from a valueless common_iterator");
204 _LIBCPP_ASSERT(!__y.__hold_.valueless_by_exception(), "Attempted to subtract a valueless common_iterator");
217205
218206 auto __x_index = __x.__hold_.index();
219207 auto __y_index = __y.__hold_.index();
......@@ -230,24 +218,21 @@ public:
230218 return _VSTD::__unchecked_get<_Sent>(__x.__hold_) - _VSTD::__unchecked_get<_I2>(__y.__hold_);
231219 }
232220
233 friend iter_rvalue_reference_t<_Iter> iter_move(const common_iterator& __i)
221 friend constexpr iter_rvalue_reference_t<_Iter> iter_move(const common_iterator& __i)
234222 noexcept(noexcept(ranges::iter_move(declval<const _Iter&>())))
235223 requires input_iterator<_Iter>
236224 {
237 _LIBCPP_ASSERT(holds_alternative<_Iter>(__i.__hold_),
238 "Cannot iter_move a sentinel. Common iterator not holding an iterator.");
225 _LIBCPP_ASSERT(holds_alternative<_Iter>(__i.__hold_), "Attempted to iter_move a non-dereferenceable common_iterator");
239226 return ranges::iter_move( _VSTD::__unchecked_get<_Iter>(__i.__hold_));
240227 }
241228
242229 template<indirectly_swappable<_Iter> _I2, class _S2>
243 friend void iter_swap(const common_iterator& __x, const common_iterator<_I2, _S2>& __y)
230 friend constexpr void iter_swap(const common_iterator& __x, const common_iterator<_I2, _S2>& __y)
244231 noexcept(noexcept(ranges::iter_swap(declval<const _Iter&>(), declval<const _I2&>())))
245232 {
246 _LIBCPP_ASSERT(holds_alternative<_Iter>(__x.__hold_),
247 "Cannot swap __y with a sentinel. Common iterator (__x) not holding an iterator.");
248 _LIBCPP_ASSERT(holds_alternative<_Iter>(__y.__hold_),
249 "Cannot swap __x with a sentinel. Common iterator (__y) not holding an iterator.");
250 return ranges::iter_swap( _VSTD::__unchecked_get<_Iter>(__x.__hold_), _VSTD::__unchecked_get<_Iter>(__y.__hold_));
233 _LIBCPP_ASSERT(holds_alternative<_Iter>(__x.__hold_), "Attempted to iter_swap a non-dereferenceable common_iterator");
234 _LIBCPP_ASSERT(holds_alternative<_I2>(__y.__hold_), "Attempted to iter_swap a non-dereferenceable common_iterator");
235 return ranges::iter_swap(_VSTD::__unchecked_get<_Iter>(__x.__hold_), _VSTD::__unchecked_get<_I2>(__y.__hold_));
251236 }
252237};
253238
......@@ -274,10 +259,10 @@ struct __arrow_type_or_void {
274259template<class _Iter, class _Sent>
275260 requires __common_iter_has_ptr_op<_Iter, _Sent>
276261struct __arrow_type_or_void<_Iter, _Sent> {
277 using type = decltype(declval<const common_iterator<_Iter, _Sent>>().operator->());
262 using type = decltype(declval<const common_iterator<_Iter, _Sent>&>().operator->());
278263};
279264
280template<class _Iter, class _Sent>
265template<input_iterator _Iter, class _Sent>
281266struct iterator_traits<common_iterator<_Iter, _Sent>> {
282267 using iterator_concept = _If<forward_iterator<_Iter>,
283268 forward_iterator_tag,
......@@ -291,11 +276,8 @@ struct iterator_traits<common_iterator<_Iter, _Sent>> {
291276 using reference = iter_reference_t<_Iter>;
292277};
293278
294
295#endif // !defined(_LIBCPP_HAS_NO_RANGES)
279#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
296280
297281_LIBCPP_END_NAMESPACE_STD
298282
299_LIBCPP_POP_MACROS
300
301283#endif // _LIBCPP___ITERATOR_COMMON_ITERATOR_H
lib/libcxx/include/__iterator/concepts.h+4-12
......@@ -24,14 +24,9 @@
2424#pragma GCC system_header
2525#endif
2626
27_LIBCPP_PUSH_MACROS
28#include <__undef_macros>
29
3027_LIBCPP_BEGIN_NAMESPACE_STD
3128
32#if !defined(_LIBCPP_HAS_NO_RANGES)
33
34// clang-format off
29#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
3530
3631// [iterator.concept.readable]
3732template<class _In>
......@@ -72,6 +67,8 @@ concept __signed_integer_like = signed_integral<_Tp>;
7267
7368template<class _Ip>
7469concept weakly_incrementable =
70 // TODO: remove this once the clang bug is fixed (bugs.llvm.org/PR48173).
71 !same_as<_Ip, bool> && // Currently, clang does not handle bool correctly.
7572 movable<_Ip> &&
7673 requires(_Ip __i) {
7774 typename iter_difference_t<_Ip>;
......@@ -172,7 +169,6 @@ concept contiguous_iterator =
172169 derived_from<_ITER_CONCEPT<_Ip>, contiguous_iterator_tag> &&
173170 is_lvalue_reference_v<iter_reference_t<_Ip>> &&
174171 same_as<iter_value_t<_Ip>, remove_cvref_t<iter_reference_t<_Ip>>> &&
175 (is_pointer_v<_Ip> || requires { sizeof(__pointer_traits_element_type<_Ip>); }) &&
176172 requires(const _Ip& __i) {
177173 { _VSTD::to_address(__i) } -> same_as<add_pointer_t<iter_reference_t<_Ip>>>;
178174 };
......@@ -261,12 +257,8 @@ concept indirectly_movable_storable =
261257// Note: indirectly_swappable is located in iter_swap.h to prevent a dependency cycle
262258// (both iter_swap and indirectly_swappable require indirectly_readable).
263259
264// clang-format on
265
266#endif // !defined(_LIBCPP_HAS_NO_RANGES)
260#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
267261
268262_LIBCPP_END_NAMESPACE_STD
269263
270_LIBCPP_POP_MACROS
271
272264#endif // _LIBCPP___ITERATOR_CONCEPTS_H
lib/libcxx/include/__iterator/counted_iterator.h+6-9
......@@ -13,12 +13,14 @@
1313#include <__debug>
1414#include <__iterator/concepts.h>
1515#include <__iterator/default_sentinel.h>
16#include <__iterator/incrementable_traits.h>
1617#include <__iterator/iter_move.h>
1718#include <__iterator/iter_swap.h>
18#include <__iterator/incrementable_traits.h>
1919#include <__iterator/iterator_traits.h>
2020#include <__iterator/readable_traits.h>
2121#include <__memory/pointer_traits.h>
22#include <__utility/move.h>
23#include <compare>
2224#include <concepts>
2325#include <type_traits>
2426
......@@ -26,12 +28,9 @@
2628#pragma GCC system_header
2729#endif
2830
29_LIBCPP_PUSH_MACROS
30#include <__undef_macros>
31
3231_LIBCPP_BEGIN_NAMESPACE_STD
3332
34#if !defined(_LIBCPP_HAS_NO_RANGES)
33#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
3534
3635template<class>
3736struct __counted_iterator_concept {};
......@@ -97,7 +96,7 @@ public:
9796 }
9897
9998 _LIBCPP_HIDE_FROM_ABI
100 constexpr const _Iter& base() const& { return __current_; }
99 constexpr const _Iter& base() const& noexcept { return __current_; }
101100
102101 _LIBCPP_HIDE_FROM_ABI
103102 constexpr _Iter base() && { return _VSTD::move(__current_); }
......@@ -297,10 +296,8 @@ struct iterator_traits<counted_iterator<_Iter>> : iterator_traits<_Iter> {
297296 add_pointer_t<iter_reference_t<_Iter>>, void>;
298297};
299298
300#endif // !defined(_LIBCPP_HAS_NO_RANGES)
299#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
301300
302301_LIBCPP_END_NAMESPACE_STD
303302
304_LIBCPP_POP_MACROS
305
306303#endif // _LIBCPP___ITERATOR_COUNTED_ITERATOR_H
lib/libcxx/include/__iterator/data.h-5
......@@ -18,9 +18,6 @@
1818#pragma GCC system_header
1919#endif
2020
21_LIBCPP_PUSH_MACROS
22#include <__undef_macros>
23
2421_LIBCPP_BEGIN_NAMESPACE_STD
2522
2623#if _LIBCPP_STD_VER > 14
......@@ -51,6 +48,4 @@ constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.beg
5148
5249_LIBCPP_END_NAMESPACE_STD
5350
54_LIBCPP_POP_MACROS
55
5651#endif // _LIBCPP___ITERATOR_DATA_H
lib/libcxx/include/__iterator/default_sentinel.h+2-7
......@@ -16,20 +16,15 @@
1616#pragma GCC system_header
1717#endif
1818
19_LIBCPP_PUSH_MACROS
20#include <__undef_macros>
21
2219_LIBCPP_BEGIN_NAMESPACE_STD
2320
24#if !defined(_LIBCPP_HAS_NO_RANGES)
21#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
2522
2623struct default_sentinel_t { };
2724inline constexpr default_sentinel_t default_sentinel{};
2825
29#endif // !defined(_LIBCPP_HAS_NO_RANGES)
26#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
3027
3128_LIBCPP_END_NAMESPACE_STD
3229
33_LIBCPP_POP_MACROS
34
3530#endif // _LIBCPP___ITERATOR_DEFAULT_SENTINEL_H
lib/libcxx/include/__iterator/distance.h+56-5
......@@ -11,15 +11,18 @@
1111#define _LIBCPP___ITERATOR_DISTANCE_H
1212
1313#include <__config>
14#include <__iterator/concepts.h>
15#include <__iterator/incrementable_traits.h>
1416#include <__iterator/iterator_traits.h>
17#include <__ranges/access.h>
18#include <__ranges/concepts.h>
19#include <__ranges/size.h>
20#include <type_traits>
1521
1622#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1723#pragma GCC system_header
1824#endif
1925
20_LIBCPP_PUSH_MACROS
21#include <__undef_macros>
22
2326_LIBCPP_BEGIN_NAMESPACE_STD
2427
2528template <class _InputIter>
......@@ -49,8 +52,56 @@ distance(_InputIter __first, _InputIter __last)
4952 return _VSTD::__distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
5053}
5154
52_LIBCPP_END_NAMESPACE_STD
55#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
56
57// [range.iter.op.distance]
58
59namespace ranges {
60namespace __distance {
61
62struct __fn {
63 template<class _Ip, sentinel_for<_Ip> _Sp>
64 requires (!sized_sentinel_for<_Sp, _Ip>)
65 _LIBCPP_HIDE_FROM_ABI
66 constexpr iter_difference_t<_Ip> operator()(_Ip __first, _Sp __last) const {
67 iter_difference_t<_Ip> __n = 0;
68 while (__first != __last) {
69 ++__first;
70 ++__n;
71 }
72 return __n;
73 }
74
75 template<class _Ip, sized_sentinel_for<decay_t<_Ip>> _Sp>
76 _LIBCPP_HIDE_FROM_ABI
77 constexpr iter_difference_t<_Ip> operator()(_Ip&& __first, _Sp __last) const {
78 if constexpr (sized_sentinel_for<_Sp, __uncvref_t<_Ip>>) {
79 return __last - __first;
80 } else {
81 return __last - decay_t<_Ip>(__first);
82 }
83 }
5384
54_LIBCPP_POP_MACROS
85 template<range _Rp>
86 _LIBCPP_HIDE_FROM_ABI
87 constexpr range_difference_t<_Rp> operator()(_Rp&& __r) const {
88 if constexpr (sized_range<_Rp>) {
89 return static_cast<range_difference_t<_Rp>>(ranges::size(__r));
90 } else {
91 return operator()(ranges::begin(__r), ranges::end(__r));
92 }
93 }
94};
95
96} // namespace __distance
97
98inline namespace __cpo {
99 inline constexpr auto distance = __distance::__fn{};
100} // namespace __cpo
101} // namespace ranges
102
103#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
104
105_LIBCPP_END_NAMESPACE_STD
55106
56107#endif // _LIBCPP___ITERATOR_DISTANCE_H
lib/libcxx/include/__iterator/empty.h-5
......@@ -18,9 +18,6 @@
1818#pragma GCC system_header
1919#endif
2020
21_LIBCPP_PUSH_MACROS
22#include <__undef_macros>
23
2421_LIBCPP_BEGIN_NAMESPACE_STD
2522
2623#if _LIBCPP_STD_VER > 14
......@@ -44,6 +41,4 @@ constexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() =
4441
4542_LIBCPP_END_NAMESPACE_STD
4643
47_LIBCPP_POP_MACROS
48
4944#endif // _LIBCPP___ITERATOR_EMPTY_H
lib/libcxx/include/__iterator/erase_if_container.h-5
......@@ -16,9 +16,6 @@
1616#pragma GCC system_header
1717#endif
1818
19_LIBCPP_PUSH_MACROS
20#include <__undef_macros>
21
2219_LIBCPP_BEGIN_NAMESPACE_STD
2320
2421template <class _Container, class _Predicate>
......@@ -40,6 +37,4 @@ __libcpp_erase_if_container(_Container& __c, _Predicate& __pred) {
4037
4138_LIBCPP_END_NAMESPACE_STD
4239
43_LIBCPP_POP_MACROS
44
4540#endif // _LIBCPP___ITERATOR_ERASE_IF_CONTAINER_H
lib/libcxx/include/__iterator/front_insert_iterator.h-5
......@@ -21,9 +21,6 @@
2121#pragma GCC system_header
2222#endif
2323
24_LIBCPP_PUSH_MACROS
25#include <__undef_macros>
26
2724_LIBCPP_BEGIN_NAMESPACE_STD
2825
2926_LIBCPP_SUPPRESS_DEPRECATED_PUSH
......@@ -70,6 +67,4 @@ front_inserter(_Container& __x)
7067
7168_LIBCPP_END_NAMESPACE_STD
7269
73_LIBCPP_POP_MACROS
74
7570#endif // _LIBCPP___ITERATOR_FRONT_INSERT_ITERATOR_H
lib/libcxx/include/__iterator/incrementable_traits.h+2-7
......@@ -18,12 +18,9 @@
1818#pragma GCC system_header
1919#endif
2020
21_LIBCPP_PUSH_MACROS
22#include <__undef_macros>
23
2421_LIBCPP_BEGIN_NAMESPACE_STD
2522
26#if !defined(_LIBCPP_HAS_NO_RANGES)
23#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
2724
2825// [incrementable.traits]
2926template<class> struct incrementable_traits {};
......@@ -68,10 +65,8 @@ using iter_difference_t = typename conditional_t<__is_primary_template<iterator_
6865 incrementable_traits<remove_cvref_t<_Ip> >,
6966 iterator_traits<remove_cvref_t<_Ip> > >::difference_type;
7067
71#endif // !defined(_LIBCPP_HAS_NO_RANGES)
68#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
7269
7370_LIBCPP_END_NAMESPACE_STD
7471
75_LIBCPP_POP_MACROS
76
7772#endif // _LIBCPP___ITERATOR_INCREMENTABLE_TRAITS_H
lib/libcxx/include/__iterator/indirectly_comparable.h created+30
......@@ -0,0 +1,30 @@
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_INDIRECTLY_COMPARABLE_H
11#define _LIBCPP___ITERATOR_INDIRECTLY_COMPARABLE_H
12
13#include <__config>
14#include <__functional/identity.h>
15#include <__iterator/concepts.h>
16#include <__iterator/projected.h>
17
18_LIBCPP_BEGIN_NAMESPACE_STD
19
20#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
21
22template <class _I1, class _I2, class _Rp, class _P1 = identity, class _P2 = identity>
23concept indirectly_comparable =
24 indirect_binary_predicate<_Rp, projected<_I1, _P1>, projected<_I2, _P2>>;
25
26#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
27
28_LIBCPP_END_NAMESPACE_STD
29
30#endif // _LIBCPP___ITERATOR_INDIRECTLY_COMPARABLE_H
lib/libcxx/include/__iterator/insert_iterator.h+12-8
......@@ -14,6 +14,7 @@
1414#include <__iterator/iterator.h>
1515#include <__iterator/iterator_traits.h>
1616#include <__memory/addressof.h>
17#include <__ranges/access.h>
1718#include <__utility/move.h>
1819#include <cstddef>
1920
......@@ -21,11 +22,16 @@
2122#pragma GCC system_header
2223#endif
2324
24_LIBCPP_PUSH_MACROS
25#include <__undef_macros>
26
2725_LIBCPP_BEGIN_NAMESPACE_STD
2826
27#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
28template <class _Container>
29using __insert_iterator_iter_t = ranges::iterator_t<_Container>;
30#else
31template <class _Container>
32using __insert_iterator_iter_t = typename _Container::iterator;
33#endif
34
2935_LIBCPP_SUPPRESS_DEPRECATED_PUSH
3036template <class _Container>
3137class _LIBCPP_TEMPLATE_VIS insert_iterator
......@@ -36,7 +42,7 @@ class _LIBCPP_TEMPLATE_VIS insert_iterator
3642_LIBCPP_SUPPRESS_DEPRECATED_POP
3743protected:
3844 _Container* container;
39 typename _Container::iterator iter; // FIXME: `ranges::iterator_t<Container>` in C++20 mode
45 __insert_iterator_iter_t<_Container> iter;
4046public:
4147 typedef output_iterator_tag iterator_category;
4248 typedef void value_type;
......@@ -49,7 +55,7 @@ public:
4955 typedef void reference;
5056 typedef _Container container_type;
5157
52 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator(_Container& __x, typename _Container::iterator __i)
58 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator(_Container& __x, __insert_iterator_iter_t<_Container> __i)
5359 : container(_VSTD::addressof(__x)), iter(__i) {}
5460 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(const typename _Container::value_type& __value_)
5561 {iter = container->insert(iter, __value_); ++iter; return *this;}
......@@ -65,13 +71,11 @@ public:
6571template <class _Container>
6672inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
6773insert_iterator<_Container>
68inserter(_Container& __x, typename _Container::iterator __i)
74inserter(_Container& __x, __insert_iterator_iter_t<_Container> __i)
6975{
7076 return insert_iterator<_Container>(__x, __i);
7177}
7278
7379_LIBCPP_END_NAMESPACE_STD
7480
75_LIBCPP_POP_MACROS
76
7781#endif // _LIBCPP___ITERATOR_INSERT_ITERATOR_H
lib/libcxx/include/__iterator/istream_iterator.h-11
......@@ -20,9 +20,6 @@
2020#pragma GCC system_header
2121#endif
2222
23_LIBCPP_PUSH_MACROS
24#include <__undef_macros>
25
2623_LIBCPP_BEGIN_NAMESPACE_STD
2724
2825_LIBCPP_SUPPRESS_DEPRECATED_PUSH
......@@ -70,12 +67,6 @@ public:
7067 bool
7168 operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
7269 const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
73
74 template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
75 friend _LIBCPP_INLINE_VISIBILITY
76 bool
77 operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
78 const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
7970};
8071
8172template <class _Tp, class _CharT, class _Traits, class _Distance>
......@@ -98,6 +89,4 @@ operator!=(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
9889
9990_LIBCPP_END_NAMESPACE_STD
10091
101_LIBCPP_POP_MACROS
102
10392#endif // _LIBCPP___ITERATOR_ISTREAM_ITERATOR_H
lib/libcxx/include/__iterator/istreambuf_iterator.h-5
......@@ -19,9 +19,6 @@
1919#pragma GCC system_header
2020#endif
2121
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
2522_LIBCPP_BEGIN_NAMESPACE_STD
2623
2724_LIBCPP_SUPPRESS_DEPRECATED_PUSH
......@@ -105,6 +102,4 @@ bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
105102
106103_LIBCPP_END_NAMESPACE_STD
107104
108_LIBCPP_POP_MACROS
109
110105#endif // _LIBCPP___ITERATOR_ISTREAMBUF_ITERATOR_H
lib/libcxx/include/__iterator/iter_move.h+18-16
......@@ -21,20 +21,23 @@
2121#pragma GCC system_header
2222#endif
2323
24_LIBCPP_PUSH_MACROS
25#include <__undef_macros>
26
2724_LIBCPP_BEGIN_NAMESPACE_STD
2825
29#if !defined(_LIBCPP_HAS_NO_RANGES)
26#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
27
28// [iterator.cust.move]
29
30namespace ranges {
31namespace __iter_move {
3032
31namespace ranges::__iter_move {
3233void iter_move();
3334
34template<class _Ip>
35concept __unqualified_iter_move = requires(_Ip&& __i) {
36 iter_move(_VSTD::forward<_Ip>(__i));
37};
35template <class _Tp>
36concept __unqualified_iter_move =
37 __class_or_enum<remove_cvref_t<_Tp>> &&
38 requires (_Tp&& __t) {
39 iter_move(_VSTD::forward<_Tp>(__t));
40 };
3841
3942// [iterator.cust.move]/1
4043// The name ranges::iter_move denotes a customization point object.
......@@ -72,20 +75,19 @@ struct __fn {
7275 // [iterator.cust.move]/1.3
7376 // Otherwise, ranges::iter_move(E) is ill-formed.
7477};
75} // namespace ranges::__iter_move
78} // namespace __iter_move
7679
77namespace ranges::inline __cpo {
80inline namespace __cpo {
7881 inline constexpr auto iter_move = __iter_move::__fn{};
79}
82} // namespace __cpo
83} // namespace ranges
8084
8185template<__dereferenceable _Tp>
82requires requires(_Tp& __t) { { ranges::iter_move(__t) } -> __referenceable; }
86 requires requires(_Tp& __t) { { ranges::iter_move(__t) } -> __referenceable; }
8387using iter_rvalue_reference_t = decltype(ranges::iter_move(declval<_Tp&>()));
8488
85#endif // !_LIBCPP_HAS_NO_RANGES
89#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
8690
8791_LIBCPP_END_NAMESPACE_STD
8892
89_LIBCPP_POP_MACROS
90
9193#endif // _LIBCPP___ITERATOR_ITER_MOVE_H
lib/libcxx/include/__iterator/iter_swap.h+12-13
......@@ -14,7 +14,8 @@
1414#include <__iterator/iter_move.h>
1515#include <__iterator/iterator_traits.h>
1616#include <__iterator/readable_traits.h>
17#include <__ranges/access.h>
17#include <__utility/forward.h>
18#include <__utility/move.h>
1819#include <concepts>
1920#include <type_traits>
2021
......@@ -22,12 +23,11 @@
2223#pragma GCC system_header
2324#endif
2425
25_LIBCPP_PUSH_MACROS
26#include <__undef_macros>
27
2826_LIBCPP_BEGIN_NAMESPACE_STD
2927
30#if !defined(_LIBCPP_HAS_NO_RANGES)
28#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
29
30// [iter.cust.swap]
3131
3232namespace ranges {
3333namespace __iter_swap {
......@@ -35,9 +35,11 @@ namespace __iter_swap {
3535 void iter_swap(_I1, _I2) = delete;
3636
3737 template<class _T1, class _T2>
38 concept __unqualified_iter_swap = requires(_T1&& __x, _T2&& __y) {
39 iter_swap(_VSTD::forward<_T1>(__x), _VSTD::forward<_T2>(__y));
40 };
38 concept __unqualified_iter_swap =
39 (__class_or_enum<remove_cvref_t<_T1>> || __class_or_enum<remove_cvref_t<_T2>>) &&
40 requires (_T1&& __x, _T2&& __y) {
41 iter_swap(_VSTD::forward<_T1>(__x), _VSTD::forward<_T2>(__y));
42 };
4143
4244 template<class _T1, class _T2>
4345 concept __readable_swappable =
......@@ -80,12 +82,11 @@ namespace __iter_swap {
8082 *_VSTD::forward<_T1>(__x) = _VSTD::move(__old);
8183 }
8284 };
83} // end namespace __iter_swap
85} // namespace __iter_swap
8486
8587inline namespace __cpo {
8688 inline constexpr auto iter_swap = __iter_swap::__fn{};
8789} // namespace __cpo
88
8990} // namespace ranges
9091
9192template<class _I1, class _I2 = _I1>
......@@ -98,10 +99,8 @@ concept indirectly_swappable =
9899 ranges::iter_swap(__i2, __i1);
99100 };
100101
101#endif // !defined(_LIBCPP_HAS_NO_RANGES)
102#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
102103
103104_LIBCPP_END_NAMESPACE_STD
104105
105_LIBCPP_POP_MACROS
106
107106#endif // _LIBCPP___ITERATOR_ITER_SWAP_H
lib/libcxx/include/__iterator/iterator.h-5
......@@ -17,9 +17,6 @@
1717#pragma GCC system_header
1818#endif
1919
20_LIBCPP_PUSH_MACROS
21#include <__undef_macros>
22
2320_LIBCPP_BEGIN_NAMESPACE_STD
2421
2522template<class _Category, class _Tp, class _Distance = ptrdiff_t,
......@@ -35,6 +32,4 @@ struct _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 iterator
3532
3633_LIBCPP_END_NAMESPACE_STD
3734
38_LIBCPP_POP_MACROS
39
4035#endif // _LIBCPP___ITERATOR_ITERATOR_H
lib/libcxx/include/__iterator/iterator_traits.h+9-14
......@@ -20,12 +20,9 @@
2020#pragma GCC system_header
2121#endif
2222
23_LIBCPP_PUSH_MACROS
24#include <__undef_macros>
25
2623_LIBCPP_BEGIN_NAMESPACE_STD
2724
28#if !defined(_LIBCPP_HAS_NO_RANGES)
25#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
2926
3027template <class _Tp>
3128using __with_reference = _Tp&;
......@@ -44,7 +41,7 @@ concept __dereferenceable = requires(_Tp& __t) {
4441template<__dereferenceable _Tp>
4542using iter_reference_t = decltype(*declval<_Tp&>());
4643
47#endif // !defined(_LIBCPP_HAS_NO_RANGES)
44#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
4845
4946template <class _Iter>
5047struct _LIBCPP_TEMPLATE_VIS iterator_traits;
......@@ -79,7 +76,7 @@ struct __iter_concept_category_test {
7976};
8077struct __iter_concept_random_fallback {
8178 template <class _Iter>
82 using _Apply = _EnableIf<
79 using _Apply = __enable_if_t<
8380 __is_primary_template<iterator_traits<_Iter> >::value,
8481 random_access_iterator_tag
8582 >;
......@@ -142,7 +139,7 @@ public:
142139 static const bool value = sizeof(__test<_Tp>(nullptr)) == 1;
143140};
144141
145#if !defined(_LIBCPP_HAS_NO_RANGES)
142#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
146143
147144// The `cpp17-*-iterator` exposition-only concepts are easily confused with the Cpp17*Iterator tables,
148145// so they've been banished to a namespace that makes it obvious they have a niche use-case.
......@@ -365,7 +362,7 @@ struct iterator_traits : __iterator_traits<_Ip> {
365362 using __primary_template = iterator_traits;
366363};
367364
368#else // !defined(_LIBCPP_HAS_NO_RANGES)
365#else // !defined(_LIBCPP_HAS_NO_CONCEPTS)
369366
370367template <class _Iter, bool> struct __iterator_traits {};
371368
......@@ -402,10 +399,10 @@ struct _LIBCPP_TEMPLATE_VIS iterator_traits
402399
403400 using __primary_template = iterator_traits;
404401};
405#endif // !defined(_LIBCPP_HAS_NO_RANGES)
402#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
406403
407404template<class _Tp>
408#if !defined(_LIBCPP_HAS_NO_RANGES)
405#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
409406requires is_object_v<_Tp>
410407#endif
411408struct _LIBCPP_TEMPLATE_VIS iterator_traits<_Tp*>
......@@ -477,7 +474,7 @@ struct __is_exactly_cpp17_input_iterator
477474 __has_iterator_category_convertible_to<_Tp, input_iterator_tag>::value &&
478475 !__has_iterator_category_convertible_to<_Tp, forward_iterator_tag>::value> {};
479476
480#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
477#if _LIBCPP_STD_VER >= 17
481478template<class _InputIterator>
482479using __iter_value_type = typename iterator_traits<_InputIterator>::value_type;
483480
......@@ -491,10 +488,8 @@ template<class _InputIterator>
491488using __iter_to_alloc_type = pair<
492489 add_const_t<typename iterator_traits<_InputIterator>::value_type::first_type>,
493490 typename iterator_traits<_InputIterator>::value_type::second_type>;
494#endif // _LIBCPP_HAS_NO_DEDUCTION_GUIDES
491#endif // _LIBCPP_STD_VER >= 17
495492
496493_LIBCPP_END_NAMESPACE_STD
497494
498_LIBCPP_POP_MACROS
499
500495#endif // _LIBCPP___ITERATOR_ITERATOR_TRAITS_H
lib/libcxx/include/__iterator/move_iterator.h+76-80
......@@ -12,33 +12,32 @@
1212
1313#include <__config>
1414#include <__iterator/iterator_traits.h>
15#include <__utility/move.h>
1516#include <type_traits>
1617
1718#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1819#pragma GCC system_header
1920#endif
2021
21_LIBCPP_PUSH_MACROS
22#include <__undef_macros>
23
2422_LIBCPP_BEGIN_NAMESPACE_STD
2523
2624template <class _Iter>
2725class _LIBCPP_TEMPLATE_VIS move_iterator
2826{
29private:
30 _Iter __i;
3127public:
32 typedef _Iter iterator_type;
28#if _LIBCPP_STD_VER > 17
29 typedef input_iterator_tag iterator_concept;
30#endif
31
32 typedef _Iter iterator_type;
33 typedef _If<
34 __is_cpp17_random_access_iterator<_Iter>::value,
35 random_access_iterator_tag,
36 typename iterator_traits<_Iter>::iterator_category
37 > iterator_category;
3338 typedef typename iterator_traits<iterator_type>::value_type value_type;
3439 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
3540 typedef iterator_type pointer;
36 typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
37 random_access_iterator_tag,
38 typename iterator_traits<_Iter>::iterator_category> iterator_category;
39#if _LIBCPP_STD_VER > 17
40 typedef input_iterator_tag iterator_concept;
41#endif
4241
4342#ifndef _LIBCPP_CXX03_LANG
4443 typedef typename iterator_traits<iterator_type>::reference __reference;
......@@ -51,114 +50,113 @@ public:
5150 typedef typename iterator_traits<iterator_type>::reference reference;
5251#endif
5352
54 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
55 move_iterator() : __i() {}
53 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
54 move_iterator() : __current_() {}
5655
57 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
58 explicit move_iterator(_Iter __x) : __i(__x) {}
56 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
57 explicit move_iterator(_Iter __i) : __current_(_VSTD::move(__i)) {}
5958
60 template <class _Up, class = _EnableIf<
61 !is_same<_Up, _Iter>::value && is_convertible<_Up const&, _Iter>::value
59 template <class _Up, class = __enable_if_t<
60 !is_same<_Up, _Iter>::value && is_convertible<const _Up&, _Iter>::value
6261 > >
63 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
64 move_iterator(const move_iterator<_Up>& __u) : __i(__u.base()) {}
62 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
63 move_iterator(const move_iterator<_Up>& __u) : __current_(__u.base()) {}
6564
66 template <class _Up, class = _EnableIf<
65 template <class _Up, class = __enable_if_t<
6766 !is_same<_Up, _Iter>::value &&
68 is_convertible<_Up const&, _Iter>::value &&
69 is_assignable<_Iter&, _Up const&>::value
67 is_convertible<const _Up&, _Iter>::value &&
68 is_assignable<_Iter&, const _Up&>::value
7069 > >
71 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
70 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
7271 move_iterator& operator=(const move_iterator<_Up>& __u) {
73 __i = __u.base();
72 __current_ = __u.base();
7473 return *this;
7574 }
7675
77 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 _Iter base() const {return __i;}
78 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
79 reference operator*() const { return static_cast<reference>(*__i); }
80 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
81 pointer operator->() const { return __i;}
82 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
83 move_iterator& operator++() {++__i; return *this;}
84 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
85 move_iterator operator++(int) {move_iterator __tmp(*this); ++__i; return __tmp;}
86 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
87 move_iterator& operator--() {--__i; return *this;}
88 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
89 move_iterator operator--(int) {move_iterator __tmp(*this); --__i; return __tmp;}
90 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
91 move_iterator operator+ (difference_type __n) const {return move_iterator(__i + __n);}
92 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
93 move_iterator& operator+=(difference_type __n) {__i += __n; return *this;}
94 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
95 move_iterator operator- (difference_type __n) const {return move_iterator(__i - __n);}
96 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
97 move_iterator& operator-=(difference_type __n) {__i -= __n; return *this;}
98 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
99 reference operator[](difference_type __n) const { return static_cast<reference>(__i[__n]); }
76 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
77 _Iter base() const { return __current_; }
78
79 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
80 reference operator*() const { return static_cast<reference>(*__current_); }
81 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
82 pointer operator->() const { return __current_; }
83 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
84 reference operator[](difference_type __n) const { return static_cast<reference>(__current_[__n]); }
85
86 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
87 move_iterator& operator++() { ++__current_; return *this; }
88 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
89 move_iterator operator++(int) { move_iterator __tmp(*this); ++__current_; return __tmp; }
90 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
91 move_iterator& operator--() { --__current_; return *this; }
92 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
93 move_iterator operator--(int) { move_iterator __tmp(*this); --__current_; return __tmp; }
94 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
95 move_iterator operator+(difference_type __n) const { return move_iterator(__current_ + __n); }
96 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
97 move_iterator& operator+=(difference_type __n) { __current_ += __n; return *this; }
98 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
99 move_iterator operator-(difference_type __n) const { return move_iterator(__current_ - __n); }
100 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
101 move_iterator& operator-=(difference_type __n) { __current_ -= __n; return *this; }
102
103private:
104 _Iter __current_;
100105};
101106
102107template <class _Iter1, class _Iter2>
103inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
104bool
105operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
108inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
109bool operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
106110{
107111 return __x.base() == __y.base();
108112}
109113
110114template <class _Iter1, class _Iter2>
111inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
112bool
113operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
115inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
116bool operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
114117{
115 return __x.base() < __y.base();
118 return __x.base() != __y.base();
116119}
117120
118121template <class _Iter1, class _Iter2>
119inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
120bool
121operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
122inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
123bool operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
122124{
123 return __x.base() != __y.base();
125 return __x.base() < __y.base();
124126}
125127
126128template <class _Iter1, class _Iter2>
127inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
128bool
129operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
129inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
130bool operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
130131{
131132 return __x.base() > __y.base();
132133}
133134
134135template <class _Iter1, class _Iter2>
135inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
136bool
137operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
136inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
137bool operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
138138{
139 return __x.base() >= __y.base();
139 return __x.base() <= __y.base();
140140}
141141
142142template <class _Iter1, class _Iter2>
143inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
144bool
145operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
143inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
144bool operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
146145{
147 return __x.base() <= __y.base();
146 return __x.base() >= __y.base();
148147}
149148
150149#ifndef _LIBCPP_CXX03_LANG
151150template <class _Iter1, class _Iter2>
152inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
153auto
154operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
155-> decltype(__x.base() - __y.base())
151inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
152auto operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
153 -> decltype(__x.base() - __y.base())
156154{
157155 return __x.base() - __y.base();
158156}
159157#else
160158template <class _Iter1, class _Iter2>
161inline _LIBCPP_INLINE_VISIBILITY
159inline _LIBCPP_HIDE_FROM_ABI
162160typename move_iterator<_Iter1>::difference_type
163161operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
164162{
......@@ -167,7 +165,7 @@ operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
167165#endif
168166
169167template <class _Iter>
170inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
168inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
171169move_iterator<_Iter>
172170operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
173171{
......@@ -175,15 +173,13 @@ operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterato
175173}
176174
177175template <class _Iter>
178inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
176inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
179177move_iterator<_Iter>
180178make_move_iterator(_Iter __i)
181179{
182 return move_iterator<_Iter>(__i);
180 return move_iterator<_Iter>(_VSTD::move(__i));
183181}
184182
185183_LIBCPP_END_NAMESPACE_STD
186184
187_LIBCPP_POP_MACROS
188
189185#endif // _LIBCPP___ITERATOR_MOVE_ITERATOR_H
lib/libcxx/include/__iterator/next.h+12-13
......@@ -12,7 +12,6 @@
1212
1313#include <__config>
1414#include <__debug>
15#include <__function_like.h>
1615#include <__iterator/advance.h>
1716#include <__iterator/concepts.h>
1817#include <__iterator/incrementable_traits.h>
......@@ -23,9 +22,6 @@
2322#pragma GCC system_header
2423#endif
2524
26_LIBCPP_PUSH_MACROS
27#include <__undef_macros>
28
2925_LIBCPP_BEGIN_NAMESPACE_STD
3026
3127template <class _InputIter>
......@@ -39,13 +35,14 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
3935 return __x;
4036}
4137
42#if !defined(_LIBCPP_HAS_NO_RANGES)
38#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
39
40// [range.iter.op.next]
4341
4442namespace ranges {
45struct __next_fn final : private __function_like {
46 _LIBCPP_HIDE_FROM_ABI
47 constexpr explicit __next_fn(__tag __x) noexcept : __function_like(__x) {}
43namespace __next {
4844
45struct __fn {
4946 template <input_or_output_iterator _Ip>
5047 _LIBCPP_HIDE_FROM_ABI
5148 constexpr _Ip operator()(_Ip __x) const {
......@@ -75,13 +72,15 @@ struct __next_fn final : private __function_like {
7572 }
7673};
7774
78inline constexpr auto next = __next_fn(__function_like::__tag());
75} // namespace __next
76
77inline namespace __cpo {
78 inline constexpr auto next = __next::__fn{};
79} // namespace __cpo
7980} // namespace ranges
8081
81#endif // !defined(_LIBCPP_HAS_NO_RANGES)
82#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
8283
8384_LIBCPP_END_NAMESPACE_STD
8485
85_LIBCPP_POP_MACROS
86
87#endif // _LIBCPP___ITERATOR_PRIMITIVES_H
86#endif // _LIBCPP___ITERATOR_NEXT_H
lib/libcxx/include/__iterator/ostream_iterator.h-5
......@@ -20,9 +20,6 @@
2020#pragma GCC system_header
2121#endif
2222
23_LIBCPP_PUSH_MACROS
24#include <__undef_macros>
25
2623_LIBCPP_BEGIN_NAMESPACE_STD
2724
2825_LIBCPP_SUPPRESS_DEPRECATED_PUSH
......@@ -70,6 +67,4 @@ public:
7067
7168_LIBCPP_END_NAMESPACE_STD
7269
73_LIBCPP_POP_MACROS
74
7570#endif // _LIBCPP___ITERATOR_OSTREAM_ITERATOR_H
lib/libcxx/include/__iterator/ostreambuf_iterator.h-5
......@@ -19,9 +19,6 @@
1919#pragma GCC system_header
2020#endif
2121
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
2522_LIBCPP_BEGIN_NAMESPACE_STD
2623
2724_LIBCPP_SUPPRESS_DEPRECATED_PUSH
......@@ -76,6 +73,4 @@ public:
7673
7774_LIBCPP_END_NAMESPACE_STD
7875
79_LIBCPP_POP_MACROS
80
8176#endif // _LIBCPP___ITERATOR_OSTREAMBUF_ITERATOR_H
lib/libcxx/include/__iterator/prev.h+11-12
......@@ -12,7 +12,6 @@
1212
1313#include <__config>
1414#include <__debug>
15#include <__function_like.h>
1615#include <__iterator/advance.h>
1716#include <__iterator/concepts.h>
1817#include <__iterator/incrementable_traits.h>
......@@ -23,9 +22,6 @@
2322#pragma GCC system_header
2423#endif
2524
26_LIBCPP_PUSH_MACROS
27#include <__undef_macros>
28
2925_LIBCPP_BEGIN_NAMESPACE_STD
3026
3127template <class _InputIter>
......@@ -38,13 +34,14 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
3834 return __x;
3935}
4036
41#if !defined(_LIBCPP_HAS_NO_RANGES)
37#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
38
39// [range.iter.op.prev]
4240
4341namespace ranges {
44struct __prev_fn final : private __function_like {
45 _LIBCPP_HIDE_FROM_ABI
46 constexpr explicit __prev_fn(__tag __x) noexcept : __function_like(__x) {}
42namespace __prev {
4743
44struct __fn {
4845 template <bidirectional_iterator _Ip>
4946 _LIBCPP_HIDE_FROM_ABI
5047 constexpr _Ip operator()(_Ip __x) const {
......@@ -67,13 +64,15 @@ struct __prev_fn final : private __function_like {
6764 }
6865};
6966
70inline constexpr auto prev = __prev_fn(__function_like::__tag());
67} // namespace __prev
68
69inline namespace __cpo {
70 inline constexpr auto prev = __prev::__fn{};
71} // namespace __cpo
7172} // namespace ranges
7273
73#endif // !defined(_LIBCPP_HAS_NO_RANGES)
74#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
7475
7576_LIBCPP_END_NAMESPACE_STD
7677
77_LIBCPP_POP_MACROS
78
7978#endif // _LIBCPP___ITERATOR_PREV_H
lib/libcxx/include/__iterator/projected.h+2-7
......@@ -18,12 +18,9 @@
1818#pragma GCC system_header
1919#endif
2020
21_LIBCPP_PUSH_MACROS
22#include <__undef_macros>
23
2421_LIBCPP_BEGIN_NAMESPACE_STD
2522
26#if !defined(_LIBCPP_HAS_NO_RANGES)
23#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
2724
2825template<indirectly_readable _It, indirectly_regular_unary_invocable<_It> _Proj>
2926struct projected {
......@@ -36,10 +33,8 @@ struct incrementable_traits<projected<_It, _Proj>> {
3633 using difference_type = iter_difference_t<_It>;
3734};
3835
39#endif // !defined(_LIBCPP_HAS_NO_RANGES)
36#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
4037
4138_LIBCPP_END_NAMESPACE_STD
4239
43_LIBCPP_POP_MACROS
44
4540#endif // _LIBCPP___ITERATOR_PROJECTED_H
lib/libcxx/include/__iterator/readable_traits.h+7-12
......@@ -18,12 +18,9 @@
1818#pragma GCC system_header
1919#endif
2020
21_LIBCPP_PUSH_MACROS
22#include <__undef_macros>
23
2421_LIBCPP_BEGIN_NAMESPACE_STD
2522
26#if !defined(_LIBCPP_HAS_NO_RANGES)
23#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
2724
2825// [readable.traits]
2926template<class> struct __cond_value_type {};
......@@ -60,14 +57,14 @@ template<__has_member_element_type _Tp>
6057struct indirectly_readable_traits<_Tp>
6158 : __cond_value_type<typename _Tp::element_type> {};
6259
63// Pre-emptively applies LWG3541
6460template<__has_member_value_type _Tp>
65requires __has_member_element_type<_Tp>
61 requires __has_member_element_type<_Tp>
6662struct indirectly_readable_traits<_Tp> {};
63
6764template<__has_member_value_type _Tp>
68requires __has_member_element_type<_Tp> &&
69 same_as<remove_cv_t<typename _Tp::element_type>,
70 remove_cv_t<typename _Tp::value_type>>
65 requires __has_member_element_type<_Tp> &&
66 same_as<remove_cv_t<typename _Tp::element_type>,
67 remove_cv_t<typename _Tp::value_type>>
7168struct indirectly_readable_traits<_Tp>
7269 : __cond_value_type<typename _Tp::value_type> {};
7370
......@@ -82,10 +79,8 @@ using iter_value_t = typename conditional_t<__is_primary_template<iterator_trait
8279 indirectly_readable_traits<remove_cvref_t<_Ip> >,
8380 iterator_traits<remove_cvref_t<_Ip> > >::value_type;
8481
85#endif // !defined(_LIBCPP_HAS_NO_RANGES)
82#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
8683
8784_LIBCPP_END_NAMESPACE_STD
8885
89_LIBCPP_POP_MACROS
90
9186#endif // _LIBCPP___ITERATOR_READABLE_TRAITS_H
lib/libcxx/include/__iterator/reverse_access.h-5
......@@ -19,9 +19,6 @@
1919#pragma GCC system_header
2020#endif
2121
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
2522_LIBCPP_BEGIN_NAMESPACE_STD
2623
2724#if !defined(_LIBCPP_CXX03_LANG)
......@@ -104,6 +101,4 @@ auto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c))
104101
105102_LIBCPP_END_NAMESPACE_STD
106103
107_LIBCPP_POP_MACROS
108
109104#endif // _LIBCPP___ITERATOR_REVERSE_ACCESS_H
lib/libcxx/include/__iterator/reverse_iterator.h+18-22
......@@ -10,6 +10,8 @@
1010#ifndef _LIBCPP___ITERATOR_REVERSE_ITERATOR_H
1111#define _LIBCPP___ITERATOR_REVERSE_ITERATOR_H
1212
13#include <__compare/compare_three_way_result.h>
14#include <__compare/three_way_comparable.h>
1315#include <__config>
1416#include <__iterator/iterator.h>
1517#include <__iterator/iterator_traits.h>
......@@ -20,18 +22,8 @@
2022#pragma GCC system_header
2123#endif
2224
23_LIBCPP_PUSH_MACROS
24#include <__undef_macros>
25
2625_LIBCPP_BEGIN_NAMESPACE_STD
2726
28template <class _Tp, class = void>
29struct __is_stashing_iterator : false_type {};
30
31template <class _Tp>
32struct __is_stashing_iterator<_Tp, typename __void_t<typename _Tp::__stashing_iterator_tag>::type>
33 : true_type {};
34
3527_LIBCPP_SUPPRESS_DEPRECATED_PUSH
3628template <class _Iter>
3729class _LIBCPP_TEMPLATE_VIS reverse_iterator
......@@ -49,10 +41,6 @@ private:
4941 _Iter __t; // no longer used as of LWG #2360, not removed due to ABI break
5042#endif
5143
52 static_assert(!__is_stashing_iterator<_Iter>::value,
53 "The specified iterator type cannot be used with reverse_iterator; "
54 "Using stashing iterators with reverse_iterator causes undefined behavior");
55
5644protected:
5745 _Iter current;
5846public:
......@@ -78,7 +66,7 @@ public:
7866 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7967 explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
8068
81 template <class _Up, class = _EnableIf<
69 template <class _Up, class = __enable_if_t<
8270 !is_same<_Up, _Iter>::value && is_convertible<_Up const&, _Iter>::value
8371 > >
8472 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
......@@ -86,10 +74,10 @@ public:
8674 : __t(__u.base()), current(__u.base())
8775 { }
8876
89 template <class _Up, class = _EnableIf<
77 template <class _Up, class = __enable_if_t<
9078 !is_same<_Up, _Iter>::value &&
9179 is_convertible<_Up const&, _Iter>::value &&
92 is_assignable<_Up const&, _Iter>::value
80 is_assignable<_Iter&, _Up const&>::value
9381 > >
9482 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
9583 reverse_iterator& operator=(const reverse_iterator<_Up>& __u) {
......@@ -103,7 +91,7 @@ public:
10391 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
10492 explicit reverse_iterator(_Iter __x) : current(__x) {}
10593
106 template <class _Up, class = _EnableIf<
94 template <class _Up, class = __enable_if_t<
10795 !is_same<_Up, _Iter>::value && is_convertible<_Up const&, _Iter>::value
10896 > >
10997 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
......@@ -111,10 +99,10 @@ public:
11199 : current(__u.base())
112100 { }
113101
114 template <class _Up, class = _EnableIf<
102 template <class _Up, class = __enable_if_t<
115103 !is_same<_Up, _Iter>::value &&
116104 is_convertible<_Up const&, _Iter>::value &&
117 is_assignable<_Up const&, _Iter>::value
105 is_assignable<_Iter&, _Up const&>::value
118106 > >
119107 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
120108 reverse_iterator& operator=(const reverse_iterator<_Up>& __u) {
......@@ -196,6 +184,16 @@ operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>&
196184 return __x.base() >= __y.base();
197185}
198186
187#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
188template <class _Iter1, three_way_comparable_with<_Iter1> _Iter2>
189_LIBCPP_HIDE_FROM_ABI constexpr
190compare_three_way_result_t<_Iter1, _Iter2>
191operator<=>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
192{
193 return __y.base() <=> __x.base();
194}
195#endif
196
199197#ifndef _LIBCPP_CXX03_LANG
200198template <class _Iter1, class _Iter2>
201199inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
......@@ -234,6 +232,4 @@ reverse_iterator<_Iter> make_reverse_iterator(_Iter __i)
234232
235233_LIBCPP_END_NAMESPACE_STD
236234
237_LIBCPP_POP_MACROS
238
239235#endif // _LIBCPP___ITERATOR_REVERSE_ITERATOR_H
lib/libcxx/include/__iterator/size.h-5
......@@ -18,9 +18,6 @@
1818#pragma GCC system_header
1919#endif
2020
21_LIBCPP_PUSH_MACROS
22#include <__undef_macros>
23
2421_LIBCPP_BEGIN_NAMESPACE_STD
2522
2623#if _LIBCPP_STD_VER > 14
......@@ -53,6 +50,4 @@ constexpr ptrdiff_t ssize(const _Tp (&)[_Sz]) noexcept { return _Sz; }
5350
5451_LIBCPP_END_NAMESPACE_STD
5552
56_LIBCPP_POP_MACROS
57
5853#endif // _LIBCPP___ITERATOR_SIZE_H
lib/libcxx/include/__iterator/unreachable_sentinel.h created+38
......@@ -0,0 +1,38 @@
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_UNREACHABLE_SENTINEL_H
11#define _LIBCPP___ITERATOR_UNREACHABLE_SENTINEL_H
12
13#include <__config>
14#include <__iterator/concepts.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 !defined(_LIBCPP_HAS_NO_CONCEPTS)
23
24struct unreachable_sentinel_t {
25 template<weakly_incrementable _Iter>
26 _LIBCPP_HIDE_FROM_ABI
27 friend constexpr bool operator==(unreachable_sentinel_t, const _Iter&) noexcept {
28 return false;
29 }
30};
31
32inline constexpr unreachable_sentinel_t unreachable_sentinel{};
33
34#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
35
36_LIBCPP_END_NAMESPACE_STD
37
38#endif // _LIBCPP___ITERATOR_UNREACHABLE_SENTINEL_H
lib/libcxx/include/__iterator/wrap_iter.h+76-91
......@@ -13,16 +13,14 @@
1313#include <__config>
1414#include <__debug>
1515#include <__iterator/iterator_traits.h>
16#include <__memory/pointer_traits.h> // __to_address
16#include <__memory/addressof.h>
17#include <__memory/pointer_traits.h>
1718#include <type_traits>
1819
1920#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2021#pragma GCC system_header
2122#endif
2223
23_LIBCPP_PUSH_MACROS
24#include <__undef_macros>
25
2624_LIBCPP_BEGIN_NAMESPACE_STD
2725
2826template <class _Iter>
......@@ -42,120 +40,109 @@ public:
4240private:
4341 iterator_type __i;
4442public:
45 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter() _NOEXCEPT
46#if _LIBCPP_STD_VER > 11
47 : __i{}
48#endif
43 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __wrap_iter() _NOEXCEPT
44 : __i()
4945 {
50#if _LIBCPP_DEBUG_LEVEL == 2
51 __get_db()->__insert_i(this);
52#endif
46 _VSTD::__debug_db_insert_i(this);
5347 }
54 template <class _Up> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
48 template <class _Up> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
5549 __wrap_iter(const __wrap_iter<_Up>& __u,
5650 typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = nullptr) _NOEXCEPT
5751 : __i(__u.base())
5852 {
5953#if _LIBCPP_DEBUG_LEVEL == 2
60 __get_db()->__iterator_copy(this, &__u);
54 if (!__libcpp_is_constant_evaluated())
55 __get_db()->__iterator_copy(this, _VSTD::addressof(__u));
6156#endif
6257 }
6358#if _LIBCPP_DEBUG_LEVEL == 2
64 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
59 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
6560 __wrap_iter(const __wrap_iter& __x)
6661 : __i(__x.base())
6762 {
68 __get_db()->__iterator_copy(this, &__x);
63 if (!__libcpp_is_constant_evaluated())
64 __get_db()->__iterator_copy(this, _VSTD::addressof(__x));
6965 }
70 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
66 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
7167 __wrap_iter& operator=(const __wrap_iter& __x)
7268 {
73 if (this != &__x)
69 if (this != _VSTD::addressof(__x))
7470 {
75 __get_db()->__iterator_copy(this, &__x);
71 if (!__libcpp_is_constant_evaluated())
72 __get_db()->__iterator_copy(this, _VSTD::addressof(__x));
7673 __i = __x.__i;
7774 }
7875 return *this;
7976 }
80 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
77 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
8178 ~__wrap_iter()
8279 {
80 if (!__libcpp_is_constant_evaluated())
8381 __get_db()->__erase_i(this);
8482 }
8583#endif
86 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator*() const _NOEXCEPT
84 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 reference operator*() const _NOEXCEPT
8785 {
88#if _LIBCPP_DEBUG_LEVEL == 2
89 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
90 "Attempted to dereference a non-dereferenceable iterator");
91#endif
86 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
87 "Attempted to dereference a non-dereferenceable iterator");
9288 return *__i;
9389 }
94 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG pointer operator->() const _NOEXCEPT
90 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 pointer operator->() const _NOEXCEPT
9591 {
96#if _LIBCPP_DEBUG_LEVEL == 2
97 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
98 "Attempted to dereference a non-dereferenceable iterator");
99#endif
92 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
93 "Attempted to dereference a non-dereferenceable iterator");
10094 return _VSTD::__to_address(__i);
10195 }
102 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator++() _NOEXCEPT
96 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __wrap_iter& operator++() _NOEXCEPT
10397 {
104#if _LIBCPP_DEBUG_LEVEL == 2
105 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
106 "Attempted to increment a non-incrementable iterator");
107#endif
98 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
99 "Attempted to increment a non-incrementable iterator");
108100 ++__i;
109101 return *this;
110102 }
111 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator++(int) _NOEXCEPT
103 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __wrap_iter operator++(int) _NOEXCEPT
112104 {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
113105
114 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator--() _NOEXCEPT
106 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __wrap_iter& operator--() _NOEXCEPT
115107 {
116#if _LIBCPP_DEBUG_LEVEL == 2
117 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
118 "Attempted to decrement a non-decrementable iterator");
119#endif
108 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__decrementable(this),
109 "Attempted to decrement a non-decrementable iterator");
120110 --__i;
121111 return *this;
122112 }
123 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator--(int) _NOEXCEPT
113 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __wrap_iter operator--(int) _NOEXCEPT
124114 {__wrap_iter __tmp(*this); --(*this); return __tmp;}
125 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator+ (difference_type __n) const _NOEXCEPT
115 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __wrap_iter operator+ (difference_type __n) const _NOEXCEPT
126116 {__wrap_iter __w(*this); __w += __n; return __w;}
127 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator+=(difference_type __n) _NOEXCEPT
117 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __wrap_iter& operator+=(difference_type __n) _NOEXCEPT
128118 {
129#if _LIBCPP_DEBUG_LEVEL == 2
130 _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
131 "Attempted to add/subtract an iterator outside its valid range");
132#endif
119 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__addable(this, __n),
120 "Attempted to add/subtract an iterator outside its valid range");
133121 __i += __n;
134122 return *this;
135123 }
136 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator- (difference_type __n) const _NOEXCEPT
124 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __wrap_iter operator- (difference_type __n) const _NOEXCEPT
137125 {return *this + (-__n);}
138 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator-=(difference_type __n) _NOEXCEPT
126 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __wrap_iter& operator-=(difference_type __n) _NOEXCEPT
139127 {*this += -__n; return *this;}
140 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator[](difference_type __n) const _NOEXCEPT
128 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 reference operator[](difference_type __n) const _NOEXCEPT
141129 {
142#if _LIBCPP_DEBUG_LEVEL == 2
143 _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
144 "Attempted to subscript an iterator outside its valid range");
145#endif
130 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__subscriptable(this, __n),
131 "Attempted to subscript an iterator outside its valid range");
146132 return __i[__n];
147133 }
148134
149 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG iterator_type base() const _NOEXCEPT {return __i;}
135 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 iterator_type base() const _NOEXCEPT {return __i;}
150136
151137private:
152138#if _LIBCPP_DEBUG_LEVEL == 2
153 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
139 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
154140 {
141 if (!__libcpp_is_constant_evaluated())
155142 __get_db()->__insert_ic(this, __p);
156143 }
157144#else
158 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
145 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
159146#endif
160147
161148 template <class _Up> friend class __wrap_iter;
......@@ -165,99 +152,95 @@ private:
165152};
166153
167154template <class _Iter1>
168_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
155_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
169156bool operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
170157{
171158 return __x.base() == __y.base();
172159}
173160
174161template <class _Iter1, class _Iter2>
175_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
162_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
176163bool operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
177164{
178165 return __x.base() == __y.base();
179166}
180167
181168template <class _Iter1>
182_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
169_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
183170bool operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
184171{
185#if _LIBCPP_DEBUG_LEVEL == 2
186 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
187 "Attempted to compare incomparable iterators");
188#endif
172 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__less_than_comparable(_VSTD::addressof(__x), _VSTD::addressof(__y)),
173 "Attempted to compare incomparable iterators");
189174 return __x.base() < __y.base();
190175}
191176
192177template <class _Iter1, class _Iter2>
193_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
178_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
194179bool operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
195180{
196#if _LIBCPP_DEBUG_LEVEL == 2
197 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
198 "Attempted to compare incomparable iterators");
199#endif
181 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
182 "Attempted to compare incomparable iterators");
200183 return __x.base() < __y.base();
201184}
202185
203186template <class _Iter1>
204_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
187_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
205188bool operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
206189{
207190 return !(__x == __y);
208191}
209192
210193template <class _Iter1, class _Iter2>
211_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
194_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
212195bool operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
213196{
214197 return !(__x == __y);
215198}
216199
217200template <class _Iter1>
218_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
201_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
219202bool operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
220203{
221204 return __y < __x;
222205}
223206
224207template <class _Iter1, class _Iter2>
225_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
208_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
226209bool operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
227210{
228211 return __y < __x;
229212}
230213
231214template <class _Iter1>
232_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
215_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
233216bool operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
234217{
235218 return !(__x < __y);
236219}
237220
238221template <class _Iter1, class _Iter2>
239_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
222_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
240223bool operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
241224{
242225 return !(__x < __y);
243226}
244227
245228template <class _Iter1>
246_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
229_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
247230bool operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
248231{
249232 return !(__y < __x);
250233}
251234
252235template <class _Iter1, class _Iter2>
253_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
236_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
254237bool operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
255238{
256239 return !(__y < __x);
257240}
258241
259242template <class _Iter1, class _Iter2>
260_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
243_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
261244#ifndef _LIBCPP_CXX03_LANG
262245auto operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
263246 -> decltype(__x.base() - __y.base())
......@@ -266,15 +249,13 @@ typename __wrap_iter<_Iter1>::difference_type
266249operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
267250#endif // C++03
268251{
269#if _LIBCPP_DEBUG_LEVEL == 2
270 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
271 "Attempted to subtract incompatible iterators");
272#endif
252 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__less_than_comparable(_VSTD::addressof(__x), _VSTD::addressof(__y)),
253 "Attempted to subtract incompatible iterators");
273254 return __x.base() - __y.base();
274255}
275256
276257template <class _Iter1>
277_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
258_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
278259__wrap_iter<_Iter1> operator+(typename __wrap_iter<_Iter1>::difference_type __n, __wrap_iter<_Iter1> __x) _NOEXCEPT
279260{
280261 __x += __n;
......@@ -286,15 +267,19 @@ template <class _It>
286267struct __is_cpp17_contiguous_iterator<__wrap_iter<_It> > : true_type {};
287268#endif
288269
289template <class _Iter>
290_LIBCPP_CONSTEXPR
291decltype(_VSTD::__to_address(declval<_Iter>()))
292__to_address(__wrap_iter<_Iter> __w) _NOEXCEPT {
293 return _VSTD::__to_address(__w.base());
294}
270template <class _It>
271struct _LIBCPP_TEMPLATE_VIS pointer_traits<__wrap_iter<_It> >
272{
273 typedef __wrap_iter<_It> pointer;
274 typedef typename pointer_traits<_It>::element_type element_type;
275 typedef typename pointer_traits<_It>::difference_type difference_type;
295276
296_LIBCPP_END_NAMESPACE_STD
277 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
278 static element_type *to_address(pointer __w) _NOEXCEPT {
279 return _VSTD::__to_address(__w.base());
280 }
281};
297282
298_LIBCPP_POP_MACROS
283_LIBCPP_END_NAMESPACE_STD
299284
300285#endif // _LIBCPP___ITERATOR_WRAP_ITER_H
lib/libcxx/include/__libcpp_version+1-1
......@@ -1 +1 @@
113000
114000
lib/libcxx/include/__locale+66-13
......@@ -12,18 +12,17 @@
1212
1313#include <__availability>
1414#include <__config>
15#include <string>
16#include <memory>
17#include <utility>
18#include <mutex>
19#include <cstdint>
2015#include <cctype>
16#include <cstdint>
2117#include <locale.h>
18#include <memory>
19#include <mutex>
20#include <string>
21#include <utility>
22
2223#if defined(_LIBCPP_MSVCRT_LIKE)
2324# include <cstring>
2425# include <__support/win32/locale_win32.h>
25#elif defined(__NuttX__)
26# include <__support/nuttx/xlocale.h>
2726#elif defined(_AIX) || defined(__MVS__)
2827# include <__support/ibm/xlocale.h>
2928#elif defined(__ANDROID__)
......@@ -35,7 +34,7 @@
3534# include <__support/newlib/xlocale.h>
3635#elif defined(__OpenBSD__)
3736# include <__support/openbsd/xlocale.h>
38#elif (defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__) \
37#elif (defined(__APPLE__) || defined(__FreeBSD__) \
3938 || defined(__EMSCRIPTEN__) || defined(__IBMCPP__))
4039# include <xlocale.h>
4140#elif defined(__Fuchsia__)
......@@ -210,10 +209,11 @@ class _LIBCPP_TYPE_VIS locale::id
210209 static int32_t __next_id;
211210public:
212211 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR id() :__id_(0) {}
212 void operator=(const id&) = delete;
213 id(const id&) = delete;
214
213215private:
214216 void __init();
215 void operator=(const id&); // = delete;
216 id(const id&); // = delete;
217217public: // only needed for tests
218218 long __get();
219219
......@@ -340,7 +340,9 @@ collate<_CharT>::do_hash(const char_type* __lo, const char_type* __hi) const
340340}
341341
342342_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<char>)
343#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
343344_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<wchar_t>)
345#endif
344346
345347// template <class CharT> class collate_byname;
346348
......@@ -365,6 +367,7 @@ protected:
365367 virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const;
366368};
367369
370#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
368371template <>
369372class _LIBCPP_TYPE_VIS collate_byname<wchar_t>
370373 : public collate<wchar_t>
......@@ -384,6 +387,7 @@ protected:
384387 const char_type* __lo2, const char_type* __hi2) const;
385388 virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const;
386389};
390#endif
387391
388392template <class _CharT, class _Traits, class _Allocator>
389393bool
......@@ -448,12 +452,12 @@ public:
448452 static const mask punct = _PUNCT;
449453 static const mask xdigit = _HEX;
450454 static const mask blank = _BLANK;
451 static const mask __regex_word = 0x80;
455 static const mask __regex_word = 0x4000; // 0x8000 and 0x0100 and 0x00ff are used
452456# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
453#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) || defined(__DragonFly__)
457#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__)
454458# ifdef __APPLE__
455459 typedef __uint32_t mask;
456# elif defined(__FreeBSD__) || defined(__DragonFly__)
460# elif defined(__FreeBSD__)
457461 typedef unsigned long mask;
458462# elif defined(__EMSCRIPTEN__) || defined(__NetBSD__)
459463 typedef unsigned short mask;
......@@ -507,6 +511,33 @@ public:
507511# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
508512# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA
509513# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_XDIGIT
514#elif defined(__MVS__)
515# if defined(__NATIVE_ASCII_F)
516 typedef unsigned int mask;
517 static const mask space = _ISSPACE_A;
518 static const mask print = _ISPRINT_A;
519 static const mask cntrl = _ISCNTRL_A;
520 static const mask upper = _ISUPPER_A;
521 static const mask lower = _ISLOWER_A;
522 static const mask alpha = _ISALPHA_A;
523 static const mask digit = _ISDIGIT_A;
524 static const mask punct = _ISPUNCT_A;
525 static const mask xdigit = _ISXDIGIT_A;
526 static const mask blank = _ISBLANK_A;
527# else
528 typedef unsigned short mask;
529 static const mask space = __ISSPACE;
530 static const mask print = __ISPRINT;
531 static const mask cntrl = __ISCNTRL;
532 static const mask upper = __ISUPPER;
533 static const mask lower = __ISLOWER;
534 static const mask alpha = __ISALPHA;
535 static const mask digit = __ISDIGIT;
536 static const mask punct = __ISPUNCT;
537 static const mask xdigit = __ISXDIGIT;
538 static const mask blank = __ISBLANK;
539# endif
540 static const mask __regex_word = 0x8000;
510541#else
511542# error unknown rune table for this platform -- do you mean to define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE?
512543#endif
......@@ -514,10 +545,17 @@ public:
514545 static const mask graph = alnum | punct;
515546
516547 _LIBCPP_INLINE_VISIBILITY ctype_base() {}
548
549// TODO: Remove the ifndef when the assert no longer fails on AIX.
550#ifndef _AIX
551 static_assert((__regex_word & ~(space | print | cntrl | upper | lower | alpha | digit | punct | xdigit | blank)) == __regex_word,
552 "__regex_word can't overlap other bits");
553#endif
517554};
518555
519556template <class _CharT> class _LIBCPP_TEMPLATE_VIS ctype;
520557
558#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
521559template <>
522560class _LIBCPP_TYPE_VIS ctype<wchar_t>
523561 : public locale::facet,
......@@ -619,6 +657,7 @@ protected:
619657 virtual char do_narrow(char_type, char __dfault) const;
620658 virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;
621659};
660#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
622661
623662template <>
624663class _LIBCPP_TYPE_VIS ctype<char>
......@@ -728,6 +767,10 @@ public:
728767 static const short* __classic_upper_table() _NOEXCEPT;
729768 static const short* __classic_lower_table() _NOEXCEPT;
730769#endif
770#if defined(__MVS__)
771 static const unsigned short* __classic_upper_table() _NOEXCEPT;
772 static const unsigned short* __classic_lower_table() _NOEXCEPT;
773#endif
731774
732775protected:
733776 ~ctype();
......@@ -763,6 +806,7 @@ protected:
763806 virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
764807};
765808
809#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
766810template <>
767811class _LIBCPP_TYPE_VIS ctype_byname<wchar_t>
768812 : public ctype<wchar_t>
......@@ -788,6 +832,7 @@ protected:
788832 virtual char do_narrow(char_type, char __dfault) const;
789833 virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;
790834};
835#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
791836
792837template <class _CharT>
793838inline _LIBCPP_INLINE_VISIBILITY
......@@ -994,6 +1039,7 @@ protected:
9941039
9951040// template <> class codecvt<wchar_t, char, mbstate_t>
9961041
1042#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
9971043template <>
9981044class _LIBCPP_TYPE_VIS codecvt<wchar_t, char, mbstate_t>
9991045 : public locale::facet,
......@@ -1074,6 +1120,7 @@ protected:
10741120 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
10751121 virtual int do_max_length() const _NOEXCEPT;
10761122};
1123#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
10771124
10781125// template <> class codecvt<char16_t, char, mbstate_t> // deprecated in C++20
10791126
......@@ -1452,7 +1499,9 @@ codecvt_byname<_InternT, _ExternT, _StateT>::~codecvt_byname()
14521499_LIBCPP_SUPPRESS_DEPRECATED_POP
14531500
14541501_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char, char, mbstate_t>)
1502#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
14551503_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<wchar_t, char, mbstate_t>)
1504#endif
14561505_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
14571506_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
14581507#ifndef _LIBCPP_HAS_NO_CHAR8_T
......@@ -1683,6 +1732,7 @@ protected:
16831732 string __grouping_;
16841733};
16851734
1735#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
16861736template <>
16871737class _LIBCPP_TYPE_VIS numpunct<wchar_t>
16881738 : public locale::facet
......@@ -1713,6 +1763,7 @@ protected:
17131763 char_type __thousands_sep_;
17141764 string __grouping_;
17151765};
1766#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
17161767
17171768// template <class charT> class numpunct_byname
17181769
......@@ -1736,6 +1787,7 @@ private:
17361787 void __init(const char*);
17371788};
17381789
1790#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
17391791template <>
17401792class _LIBCPP_TYPE_VIS numpunct_byname<wchar_t>
17411793: public numpunct<wchar_t>
......@@ -1753,6 +1805,7 @@ protected:
17531805private:
17541806 void __init(const char*);
17551807};
1808#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
17561809
17571810_LIBCPP_END_NAMESPACE_STD
17581811
lib/libcxx/include/__mbstate_t.h created+44
......@@ -0,0 +1,44 @@
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___MBSTATE_T_H
11#define _LIBCPP___MBSTATE_T_H
12
13#include <__config>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16#pragma GCC system_header
17#endif
18
19// TODO(ldionne):
20// The goal of this header is to provide mbstate_t without having to pull in
21// <wchar.h> or <uchar.h>. This is necessary because we need that type even
22// when we don't have (or try to provide) support for wchar_t, because several
23// types like std::fpos are defined in terms of mbstate_t.
24//
25// This is a gruesome hack, but I don't know how to make it cleaner for
26// the time being.
27
28#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
29# include <wchar.h> // for mbstate_t
30#elif __has_include(<bits/types/mbstate_t.h>)
31# include <bits/types/mbstate_t.h> // works on most Unixes
32#elif __has_include(<sys/_types/_mbstate_t.h>)
33# include <sys/_types/_mbstate_t.h> // works on Darwin
34#else
35# error "The library was configured without support for wide-characters, but we don't know how to get the definition of mbstate_t without <wchar.h> on your platform."
36#endif
37
38_LIBCPP_BEGIN_NAMESPACE_STD
39
40using ::mbstate_t _LIBCPP_USING_IF_EXISTS;
41
42_LIBCPP_END_NAMESPACE_STD
43
44#endif // _LIBCPP___MBSTATE_T_H
lib/libcxx/include/__memory/addressof.h-20
......@@ -16,13 +16,8 @@
1616#pragma GCC system_header
1717#endif
1818
19_LIBCPP_PUSH_MACROS
20#include <__undef_macros>
21
2219_LIBCPP_BEGIN_NAMESPACE_STD
2320
24#ifndef _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF
25
2621template <class _Tp>
2722inline _LIBCPP_CONSTEXPR_AFTER_CXX14
2823_LIBCPP_NO_CFI _LIBCPP_INLINE_VISIBILITY
......@@ -32,19 +27,6 @@ addressof(_Tp& __x) _NOEXCEPT
3227 return __builtin_addressof(__x);
3328}
3429
35#else
36
37template <class _Tp>
38inline _LIBCPP_NO_CFI _LIBCPP_INLINE_VISIBILITY
39_Tp*
40addressof(_Tp& __x) _NOEXCEPT
41{
42 return reinterpret_cast<_Tp *>(
43 const_cast<char *>(&reinterpret_cast<const volatile char &>(__x)));
44}
45
46#endif // _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF
47
4830#if defined(_LIBCPP_HAS_OBJC_ARC) && !defined(_LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF)
4931// Objective-C++ Automatic Reference Counting uses qualified pointers
5032// that require special addressof() signatures. When
......@@ -91,6 +73,4 @@ template <class _Tp> _Tp* addressof(const _Tp&&) noexcept = delete;
9173
9274_LIBCPP_END_NAMESPACE_STD
9375
94_LIBCPP_POP_MACROS
95
9676#endif // _LIBCPP___MEMORY_ADDRESSOF_H
lib/libcxx/include/__memory/allocation_guard.h-6
......@@ -19,10 +19,6 @@
1919#pragma GCC system_header
2020#endif
2121
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
25
2622_LIBCPP_BEGIN_NAMESPACE_STD
2723
2824// Helper class to allocate memory using an Allocator in an exception safe
......@@ -84,6 +80,4 @@ private:
8480
8581_LIBCPP_END_NAMESPACE_STD
8682
87_LIBCPP_POP_MACROS
88
8983#endif // _LIBCPP___MEMORY_ALLOCATION_GUARD_H
lib/libcxx/include/__memory/allocator.h+6-11
......@@ -22,9 +22,6 @@
2222#pragma GCC system_header
2323#endif
2424
25_LIBCPP_PUSH_MACROS
26#include <__undef_macros>
27
2825_LIBCPP_BEGIN_NAMESPACE_STD
2926
3027template <class _Tp> class allocator;
......@@ -83,6 +80,7 @@ template <class _Tp>
8380class _LIBCPP_TEMPLATE_VIS allocator
8481 : private __non_trivial_if<!is_void<_Tp>::value, allocator<_Tp> >
8582{
83 static_assert(!is_volatile<_Tp>::value, "std::allocator does not support volatile types");
8684public:
8785 typedef size_t size_type;
8886 typedef ptrdiff_t difference_type;
......@@ -91,7 +89,7 @@ public:
9189 typedef true_type is_always_equal;
9290
9391 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
94 allocator() _NOEXCEPT _LIBCPP_DEFAULT
92 allocator() _NOEXCEPT = default;
9593
9694 template <class _Up>
9795 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
......@@ -100,8 +98,7 @@ public:
10098 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
10199 _Tp* allocate(size_t __n) {
102100 if (__n > allocator_traits<allocator>::max_size(*this))
103 __throw_length_error("allocator<T>::allocate(size_t n)"
104 " 'n' exceeds maximum supported size");
101 __throw_bad_array_new_length();
105102 if (__libcpp_is_constant_evaluated()) {
106103 return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp)));
107104 } else {
......@@ -165,6 +162,7 @@ template <class _Tp>
165162class _LIBCPP_TEMPLATE_VIS allocator<const _Tp>
166163 : private __non_trivial_if<!is_void<_Tp>::value, allocator<const _Tp> >
167164{
165 static_assert(!is_volatile<_Tp>::value, "std::allocator does not support volatile types");
168166public:
169167 typedef size_t size_type;
170168 typedef ptrdiff_t difference_type;
......@@ -173,7 +171,7 @@ public:
173171 typedef true_type is_always_equal;
174172
175173 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
176 allocator() _NOEXCEPT _LIBCPP_DEFAULT
174 allocator() _NOEXCEPT = default;
177175
178176 template <class _Up>
179177 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
......@@ -182,8 +180,7 @@ public:
182180 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
183181 const _Tp* allocate(size_t __n) {
184182 if (__n > allocator_traits<allocator>::max_size(*this))
185 __throw_length_error("allocator<const T>::allocate(size_t n)"
186 " 'n' exceeds maximum supported size");
183 __throw_bad_array_new_length();
187184 if (__libcpp_is_constant_evaluated()) {
188185 return static_cast<const _Tp*>(::operator new(__n * sizeof(_Tp)));
189186 } else {
......@@ -249,6 +246,4 @@ bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return
249246
250247_LIBCPP_END_NAMESPACE_STD
251248
252_LIBCPP_POP_MACROS
253
254249#endif // _LIBCPP___MEMORY_ALLOCATOR_H
lib/libcxx/include/__memory/allocator_arg_t.h+5-5
......@@ -7,8 +7,8 @@
77//
88//===----------------------------------------------------------------------===//
99
10#ifndef _LIBCPP___FUNCTIONAL___ALLOCATOR_ARG_T_H
11#define _LIBCPP___FUNCTIONAL___ALLOCATOR_ARG_T_H
10#ifndef _LIBCPP___FUNCTIONAL_ALLOCATOR_ARG_T_H
11#define _LIBCPP___FUNCTIONAL_ALLOCATOR_ARG_T_H
1212
1313#include <__config>
1414#include <__memory/uses_allocator.h>
......@@ -26,7 +26,7 @@ struct _LIBCPP_TEMPLATE_VIS allocator_arg_t { explicit allocator_arg_t() = defau
2626#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
2727extern _LIBCPP_EXPORTED_FROM_ABI const allocator_arg_t allocator_arg;
2828#else
29/* _LIBCPP_INLINE_VAR */ constexpr allocator_arg_t allocator_arg = allocator_arg_t();
29/* inline */ constexpr allocator_arg_t allocator_arg = allocator_arg_t();
3030#endif
3131
3232#ifndef _LIBCPP_CXX03_LANG
......@@ -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_TYPE typename __uncvref<_Alloc>::type _RawAlloc;
39 typedef _LIBCPP_NODEBUG typename __uncvref<_Alloc>::type _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;
......@@ -75,4 +75,4 @@ void __user_alloc_construct_impl (integral_constant<int, 2>, _Tp *__storage, con
7575
7676_LIBCPP_END_NAMESPACE_STD
7777
78#endif // _LIBCPP___FUNCTIONAL___ALLOCATOR_ARG_T_H
78#endif // _LIBCPP___FUNCTIONAL_ALLOCATOR_ARG_T_H
lib/libcxx/include/__memory/allocator_traits.h+33-33
......@@ -36,11 +36,11 @@ template <class _Tp, class _Alloc,
3636 class _RawAlloc = typename remove_reference<_Alloc>::type,
3737 bool = __has_pointer<_RawAlloc>::value>
3838struct __pointer {
39 using type _LIBCPP_NODEBUG_TYPE = typename _RawAlloc::pointer;
39 using type _LIBCPP_NODEBUG = typename _RawAlloc::pointer;
4040};
4141template <class _Tp, class _Alloc, class _RawAlloc>
4242struct __pointer<_Tp, _Alloc, _RawAlloc, false> {
43 using type _LIBCPP_NODEBUG_TYPE = _Tp*;
43 using type _LIBCPP_NODEBUG = _Tp*;
4444};
4545
4646// __const_pointer
......@@ -48,14 +48,14 @@ _LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_const_pointer, const_pointer);
4848template <class _Tp, class _Ptr, class _Alloc,
4949 bool = __has_const_pointer<_Alloc>::value>
5050struct __const_pointer {
51 using type _LIBCPP_NODEBUG_TYPE = typename _Alloc::const_pointer;
51 using type _LIBCPP_NODEBUG = typename _Alloc::const_pointer;
5252};
5353template <class _Tp, class _Ptr, class _Alloc>
5454struct __const_pointer<_Tp, _Ptr, _Alloc, false> {
5555#ifdef _LIBCPP_CXX03_LANG
5656 using type = typename pointer_traits<_Ptr>::template rebind<const _Tp>::other;
5757#else
58 using type _LIBCPP_NODEBUG_TYPE = typename pointer_traits<_Ptr>::template rebind<const _Tp>;
58 using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<const _Tp>;
5959#endif
6060};
6161
......@@ -64,14 +64,14 @@ _LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_void_pointer, void_pointer);
6464template <class _Ptr, class _Alloc,
6565 bool = __has_void_pointer<_Alloc>::value>
6666struct __void_pointer {
67 using type _LIBCPP_NODEBUG_TYPE = typename _Alloc::void_pointer;
67 using type _LIBCPP_NODEBUG = typename _Alloc::void_pointer;
6868};
6969template <class _Ptr, class _Alloc>
7070struct __void_pointer<_Ptr, _Alloc, false> {
7171#ifdef _LIBCPP_CXX03_LANG
72 using type _LIBCPP_NODEBUG_TYPE = typename pointer_traits<_Ptr>::template rebind<void>::other;
72 using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<void>::other;
7373#else
74 using type _LIBCPP_NODEBUG_TYPE = typename pointer_traits<_Ptr>::template rebind<void>;
74 using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<void>;
7575#endif
7676};
7777
......@@ -80,14 +80,14 @@ _LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_const_void_pointer, const_void_pointer);
8080template <class _Ptr, class _Alloc,
8181 bool = __has_const_void_pointer<_Alloc>::value>
8282struct __const_void_pointer {
83 using type _LIBCPP_NODEBUG_TYPE = typename _Alloc::const_void_pointer;
83 using type _LIBCPP_NODEBUG = typename _Alloc::const_void_pointer;
8484};
8585template <class _Ptr, class _Alloc>
8686struct __const_void_pointer<_Ptr, _Alloc, false> {
8787#ifdef _LIBCPP_CXX03_LANG
88 using type _LIBCPP_NODEBUG_TYPE = typename pointer_traits<_Ptr>::template rebind<const void>::other;
88 using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<const void>::other;
8989#else
90 using type _LIBCPP_NODEBUG_TYPE = typename pointer_traits<_Ptr>::template rebind<const void>;
90 using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<const void>;
9191#endif
9292};
9393
......@@ -97,18 +97,18 @@ template <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value>
9797struct __size_type : make_unsigned<_DiffType> { };
9898template <class _Alloc, class _DiffType>
9999struct __size_type<_Alloc, _DiffType, true> {
100 using type _LIBCPP_NODEBUG_TYPE = typename _Alloc::size_type;
100 using type _LIBCPP_NODEBUG = typename _Alloc::size_type;
101101};
102102
103103// __alloc_traits_difference_type
104104_LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_alloc_traits_difference_type, difference_type);
105105template <class _Alloc, class _Ptr, bool = __has_alloc_traits_difference_type<_Alloc>::value>
106106struct __alloc_traits_difference_type {
107 using type _LIBCPP_NODEBUG_TYPE = typename pointer_traits<_Ptr>::difference_type;
107 using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::difference_type;
108108};
109109template <class _Alloc, class _Ptr>
110110struct __alloc_traits_difference_type<_Alloc, _Ptr, true> {
111 using type _LIBCPP_NODEBUG_TYPE = typename _Alloc::difference_type;
111 using type _LIBCPP_NODEBUG = typename _Alloc::difference_type;
112112};
113113
114114// __propagate_on_container_copy_assignment
......@@ -117,7 +117,7 @@ template <class _Alloc, bool = __has_propagate_on_container_copy_assignment<_All
117117struct __propagate_on_container_copy_assignment : false_type { };
118118template <class _Alloc>
119119struct __propagate_on_container_copy_assignment<_Alloc, true> {
120 using type _LIBCPP_NODEBUG_TYPE = typename _Alloc::propagate_on_container_copy_assignment;
120 using type _LIBCPP_NODEBUG = typename _Alloc::propagate_on_container_copy_assignment;
121121};
122122
123123// __propagate_on_container_move_assignment
......@@ -126,7 +126,7 @@ template <class _Alloc, bool = __has_propagate_on_container_move_assignment<_All
126126struct __propagate_on_container_move_assignment : false_type { };
127127template <class _Alloc>
128128struct __propagate_on_container_move_assignment<_Alloc, true> {
129 using type _LIBCPP_NODEBUG_TYPE = typename _Alloc::propagate_on_container_move_assignment;
129 using type _LIBCPP_NODEBUG = typename _Alloc::propagate_on_container_move_assignment;
130130};
131131
132132// __propagate_on_container_swap
......@@ -135,7 +135,7 @@ template <class _Alloc, bool = __has_propagate_on_container_swap<_Alloc>::value>
135135struct __propagate_on_container_swap : false_type { };
136136template <class _Alloc>
137137struct __propagate_on_container_swap<_Alloc, true> {
138 using type _LIBCPP_NODEBUG_TYPE = typename _Alloc::propagate_on_container_swap;
138 using type _LIBCPP_NODEBUG = typename _Alloc::propagate_on_container_swap;
139139};
140140
141141// __is_always_equal
......@@ -144,7 +144,7 @@ template <class _Alloc, bool = __has_is_always_equal<_Alloc>::value>
144144struct __is_always_equal : is_empty<_Alloc> { };
145145template <class _Alloc>
146146struct __is_always_equal<_Alloc, true> {
147 using type _LIBCPP_NODEBUG_TYPE = typename _Alloc::is_always_equal;
147 using type _LIBCPP_NODEBUG = typename _Alloc::is_always_equal;
148148};
149149
150150// __allocator_traits_rebind
......@@ -158,15 +158,15 @@ struct __has_rebind_other<_Tp, _Up, typename __void_t<
158158
159159template <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value>
160160struct __allocator_traits_rebind {
161 using type _LIBCPP_NODEBUG_TYPE = typename _Tp::template rebind<_Up>::other;
161 using type _LIBCPP_NODEBUG = typename _Tp::template rebind<_Up>::other;
162162};
163163template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
164164struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, true> {
165 using type _LIBCPP_NODEBUG_TYPE = typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other;
165 using type _LIBCPP_NODEBUG = typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other;
166166};
167167template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
168168struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false> {
169 using type _LIBCPP_NODEBUG_TYPE = _Alloc<_Up, _Args...>;
169 using type _LIBCPP_NODEBUG = _Alloc<_Up, _Args...>;
170170};
171171_LIBCPP_SUPPRESS_DEPRECATED_POP
172172
......@@ -263,7 +263,7 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits
263263 }
264264
265265 template <class _Ap = _Alloc, class =
266 _EnableIf<__has_allocate_hint<_Ap, size_type, const_void_pointer>::value> >
266 __enable_if_t<__has_allocate_hint<_Ap, size_type, const_void_pointer>::value> >
267267 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
268268 static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint) {
269269 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
......@@ -271,7 +271,7 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits
271271 _LIBCPP_SUPPRESS_DEPRECATED_POP
272272 }
273273 template <class _Ap = _Alloc, class = void, class =
274 _EnableIf<!__has_allocate_hint<_Ap, size_type, const_void_pointer>::value> >
274 __enable_if_t<!__has_allocate_hint<_Ap, size_type, const_void_pointer>::value> >
275275 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
276276 static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer) {
277277 return __a.allocate(__n);
......@@ -283,7 +283,7 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits
283283 }
284284
285285 template <class _Tp, class... _Args, class =
286 _EnableIf<__has_construct<allocator_type, _Tp*, _Args...>::value> >
286 __enable_if_t<__has_construct<allocator_type, _Tp*, _Args...>::value> >
287287 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
288288 static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args) {
289289 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
......@@ -291,7 +291,7 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits
291291 _LIBCPP_SUPPRESS_DEPRECATED_POP
292292 }
293293 template <class _Tp, class... _Args, class = void, class =
294 _EnableIf<!__has_construct<allocator_type, _Tp*, _Args...>::value> >
294 __enable_if_t<!__has_construct<allocator_type, _Tp*, _Args...>::value> >
295295 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
296296 static void construct(allocator_type&, _Tp* __p, _Args&&... __args) {
297297#if _LIBCPP_STD_VER > 17
......@@ -302,7 +302,7 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits
302302 }
303303
304304 template <class _Tp, class =
305 _EnableIf<__has_destroy<allocator_type, _Tp*>::value> >
305 __enable_if_t<__has_destroy<allocator_type, _Tp*>::value> >
306306 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
307307 static void destroy(allocator_type& __a, _Tp* __p) {
308308 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
......@@ -310,7 +310,7 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits
310310 _LIBCPP_SUPPRESS_DEPRECATED_POP
311311 }
312312 template <class _Tp, class = void, class =
313 _EnableIf<!__has_destroy<allocator_type, _Tp*>::value> >
313 __enable_if_t<!__has_destroy<allocator_type, _Tp*>::value> >
314314 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
315315 static void destroy(allocator_type&, _Tp* __p) {
316316#if _LIBCPP_STD_VER > 17
......@@ -321,7 +321,7 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits
321321 }
322322
323323 template <class _Ap = _Alloc, class =
324 _EnableIf<__has_max_size<const _Ap>::value> >
324 __enable_if_t<__has_max_size<const _Ap>::value> >
325325 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
326326 static size_type max_size(const allocator_type& __a) _NOEXCEPT {
327327 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
......@@ -329,20 +329,20 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits
329329 _LIBCPP_SUPPRESS_DEPRECATED_POP
330330 }
331331 template <class _Ap = _Alloc, class = void, class =
332 _EnableIf<!__has_max_size<const _Ap>::value> >
332 __enable_if_t<!__has_max_size<const _Ap>::value> >
333333 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
334334 static size_type max_size(const allocator_type&) _NOEXCEPT {
335335 return numeric_limits<size_type>::max() / sizeof(value_type);
336336 }
337337
338338 template <class _Ap = _Alloc, class =
339 _EnableIf<__has_select_on_container_copy_construction<const _Ap>::value> >
339 __enable_if_t<__has_select_on_container_copy_construction<const _Ap>::value> >
340340 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
341341 static allocator_type select_on_container_copy_construction(const allocator_type& __a) {
342342 return __a.select_on_container_copy_construction();
343343 }
344344 template <class _Ap = _Alloc, class = void, class =
345 _EnableIf<!__has_select_on_container_copy_construction<const _Ap>::value> >
345 __enable_if_t<!__has_select_on_container_copy_construction<const _Ap>::value> >
346346 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
347347 static allocator_type select_on_container_copy_construction(const allocator_type& __a) {
348348 return __a;
......@@ -352,7 +352,7 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits
352352template <class _Traits, class _Tp>
353353struct __rebind_alloc_helper {
354354#ifndef _LIBCPP_CXX03_LANG
355 using type _LIBCPP_NODEBUG_TYPE = typename _Traits::template rebind_alloc<_Tp>;
355 using type _LIBCPP_NODEBUG = typename _Traits::template rebind_alloc<_Tp>;
356356#else
357357 using type = typename _Traits::template rebind_alloc<_Tp>::other;
358358#endif
......@@ -374,7 +374,7 @@ struct __is_cpp17_move_insertable
374374{ };
375375
376376template <class _Alloc>
377struct __is_cpp17_move_insertable<_Alloc, _EnableIf<
377struct __is_cpp17_move_insertable<_Alloc, __enable_if_t<
378378 !__is_default_allocator<_Alloc>::value &&
379379 __has_construct<_Alloc, typename _Alloc::value_type*, typename _Alloc::value_type&&>::value
380380> > : true_type { };
......@@ -389,7 +389,7 @@ struct __is_cpp17_copy_insertable
389389{ };
390390
391391template <class _Alloc>
392struct __is_cpp17_copy_insertable<_Alloc, _EnableIf<
392struct __is_cpp17_copy_insertable<_Alloc, __enable_if_t<
393393 !__is_default_allocator<_Alloc>::value &&
394394 __has_construct<_Alloc, typename _Alloc::value_type*, const typename _Alloc::value_type&>::value
395395> >
lib/libcxx/include/__memory/auto_ptr.h-5
......@@ -17,9 +17,6 @@
1717#pragma GCC system_header
1818#endif
1919
20_LIBCPP_PUSH_MACROS
21#include <__undef_macros>
22
2320_LIBCPP_BEGIN_NAMESPACE_STD
2421
2522template <class _Tp>
......@@ -81,6 +78,4 @@ public:
8178
8279_LIBCPP_END_NAMESPACE_STD
8380
84_LIBCPP_POP_MACROS
85
8681#endif // _LIBCPP___MEMORY_AUTO_PTR_H
lib/libcxx/include/__memory/compressed_pair.h+14-30
......@@ -20,9 +20,6 @@
2020#pragma GCC system_header
2121#endif
2222
23_LIBCPP_PUSH_MACROS
24#include <__undef_macros>
25
2623_LIBCPP_BEGIN_NAMESPACE_STD
2724
2825// Tag used to default initialize one or both of the pair's elements.
......@@ -61,10 +58,8 @@ struct __compressed_pair_elem {
6158 : __value_(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {}
6259#endif
6360
64
65 _LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return __value_; }
66 _LIBCPP_INLINE_VISIBILITY
67 const_reference __get() const _NOEXCEPT { return __value_; }
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_; }
6863
6964private:
7065 _Tp __value_;
......@@ -100,9 +95,8 @@ struct __compressed_pair_elem<_Tp, _Idx, true> : private _Tp {
10095 : __value_type(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {}
10196#endif
10297
103 _LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return *this; }
104 _LIBCPP_INLINE_VISIBILITY
105 const_reference __get() const _NOEXCEPT { return *this; }
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; }
106100};
107101
108102template <class _T1, class _T2>
......@@ -118,8 +112,8 @@ public:
118112 "The current implementation is NOT ABI-compatible with the previous "
119113 "implementation for this configuration");
120114
121 typedef _LIBCPP_NODEBUG_TYPE __compressed_pair_elem<_T1, 0> _Base1;
122 typedef _LIBCPP_NODEBUG_TYPE __compressed_pair_elem<_T2, 1> _Base2;
115 typedef _LIBCPP_NODEBUG __compressed_pair_elem<_T1, 0> _Base1;
116 typedef _LIBCPP_NODEBUG __compressed_pair_elem<_T2, 1> _Base2;
123117
124118 template <bool _Dummy = true,
125119 class = typename enable_if<
......@@ -146,23 +140,19 @@ public:
146140 typename __make_tuple_indices<sizeof...(_Args2)>::type()) {}
147141#endif
148142
149 _LIBCPP_INLINE_VISIBILITY
150 typename _Base1::reference first() _NOEXCEPT {
143 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 typename _Base1::reference first() _NOEXCEPT {
151144 return static_cast<_Base1&>(*this).__get();
152145 }
153146
154 _LIBCPP_INLINE_VISIBILITY
155 typename _Base1::const_reference first() const _NOEXCEPT {
147 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename _Base1::const_reference first() const _NOEXCEPT {
156148 return static_cast<_Base1 const&>(*this).__get();
157149 }
158150
159 _LIBCPP_INLINE_VISIBILITY
160 typename _Base2::reference second() _NOEXCEPT {
151 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 typename _Base2::reference second() _NOEXCEPT {
161152 return static_cast<_Base2&>(*this).__get();
162153 }
163154
164 _LIBCPP_INLINE_VISIBILITY
165 typename _Base2::const_reference second() const _NOEXCEPT {
155 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename _Base2::const_reference second() const _NOEXCEPT {
166156 return static_cast<_Base2 const&>(*this).__get();
167157 }
168158
......@@ -175,11 +165,8 @@ public:
175165 return static_cast<_Base2*>(__pair);
176166 }
177167
178 _LIBCPP_INLINE_VISIBILITY
179 void swap(__compressed_pair& __x)
180 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
181 __is_nothrow_swappable<_T2>::value)
182 {
168 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 void swap(__compressed_pair& __x)
169 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && __is_nothrow_swappable<_T2>::value) {
183170 using _VSTD::swap;
184171 swap(first(), __x.first());
185172 swap(second(), __x.second());
......@@ -187,15 +174,12 @@ public:
187174};
188175
189176template <class _T1, class _T2>
190inline _LIBCPP_INLINE_VISIBILITY
177inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
191178void swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y)
192 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
193 __is_nothrow_swappable<_T2>::value) {
179 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && __is_nothrow_swappable<_T2>::value) {
194180 __x.swap(__y);
195181}
196182
197183_LIBCPP_END_NAMESPACE_STD
198184
199_LIBCPP_POP_MACROS
200
201185#endif // _LIBCPP___MEMORY_COMPRESSED_PAIR_H
lib/libcxx/include/__memory/concepts.h created+68
......@@ -0,0 +1,68 @@
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_CONCEPTS_H
11#define _LIBCPP___MEMORY_CONCEPTS_H
12
13#include <__config>
14#include <__iterator/concepts.h>
15#include <__iterator/iterator_traits.h>
16#include <__iterator/readable_traits.h>
17#include <__ranges/access.h>
18#include <__ranges/concepts.h>
19#include <concepts>
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 !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
29
30namespace ranges {
31
32// [special.mem.concepts]
33
34// This concept ensures that uninitialized algorithms can construct an object
35// at the address pointed-to by the iterator, which requires an lvalue.
36template <class _Ip>
37concept __nothrow_input_iterator =
38 input_iterator<_Ip> &&
39 is_lvalue_reference_v<iter_reference_t<_Ip>> &&
40 same_as<remove_cvref_t<iter_reference_t<_Ip>>, iter_value_t<_Ip>>;
41
42template <class _Sp, class _Ip>
43concept __nothrow_sentinel_for = sentinel_for<_Sp, _Ip>;
44
45template <class _Rp>
46concept __nothrow_input_range =
47 range<_Rp> &&
48 __nothrow_input_iterator<iterator_t<_Rp>> &&
49 __nothrow_sentinel_for<sentinel_t<_Rp>, iterator_t<_Rp>>;
50
51template <class _Ip>
52concept __nothrow_forward_iterator =
53 __nothrow_input_iterator<_Ip> &&
54 forward_iterator<_Ip> &&
55 __nothrow_sentinel_for<_Ip, _Ip>;
56
57template <class _Rp>
58concept __nothrow_forward_range =
59 __nothrow_input_range<_Rp> &&
60 __nothrow_forward_iterator<iterator_t<_Rp>>;
61
62} // namespace ranges
63
64#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
65
66_LIBCPP_END_NAMESPACE_STD
67
68#endif // _LIBCPP___MEMORY_CONCEPTS_H
lib/libcxx/include/__memory/construct_at.h+62-11
......@@ -12,16 +12,17 @@
1212
1313#include <__config>
1414#include <__debug>
15#include <__iterator/access.h>
16#include <__memory/addressof.h>
17#include <__memory/voidify.h>
1518#include <__utility/forward.h>
19#include <type_traits>
1620#include <utility>
1721
1822#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1923#pragma GCC system_header
2024#endif
2125
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
2526_LIBCPP_BEGIN_NAMESPACE_STD
2627
2728// construct_at
......@@ -31,29 +32,79 @@ _LIBCPP_BEGIN_NAMESPACE_STD
3132template<class _Tp, class ..._Args, class = decltype(
3233 ::new (declval<void*>()) _Tp(declval<_Args>()...)
3334)>
34_LIBCPP_INLINE_VISIBILITY
35_LIBCPP_HIDE_FROM_ABI
3536constexpr _Tp* construct_at(_Tp* __location, _Args&& ...__args) {
3637 _LIBCPP_ASSERT(__location, "null pointer given to construct_at");
37 return ::new ((void*)__location) _Tp(_VSTD::forward<_Args>(__args)...);
38 return ::new (_VSTD::__voidify(*__location)) _Tp(_VSTD::forward<_Args>(__args)...);
3839}
3940
4041#endif
4142
4243// destroy_at
4344
44#if _LIBCPP_STD_VER > 14
45// The internal functions are available regardless of the language version (with the exception of the `__destroy_at`
46// taking an array).
4547
46template <class _Tp>
47inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
48void destroy_at(_Tp* __loc) {
48template <class _ForwardIterator>
49_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
50_ForwardIterator __destroy(_ForwardIterator, _ForwardIterator);
51
52template <class _Tp, typename enable_if<!is_array<_Tp>::value, int>::type = 0>
53_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
54void __destroy_at(_Tp* __loc) {
4955 _LIBCPP_ASSERT(__loc, "null pointer given to destroy_at");
5056 __loc->~_Tp();
5157}
5258
59#if _LIBCPP_STD_VER > 17
60template <class _Tp, typename enable_if<is_array<_Tp>::value, int>::type = 0>
61_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
62void __destroy_at(_Tp* __loc) {
63 _LIBCPP_ASSERT(__loc, "null pointer given to destroy_at");
64 _VSTD::__destroy(_VSTD::begin(*__loc), _VSTD::end(*__loc));
65}
5366#endif
5467
55_LIBCPP_END_NAMESPACE_STD
68template <class _ForwardIterator>
69_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
70_ForwardIterator __destroy(_ForwardIterator __first, _ForwardIterator __last) {
71 for (; __first != __last; ++__first)
72 _VSTD::__destroy_at(_VSTD::addressof(*__first));
73 return __first;
74}
75
76#if _LIBCPP_STD_VER > 14
5677
57_LIBCPP_POP_MACROS
78template <class _Tp, enable_if_t<!is_array_v<_Tp>, int> = 0>
79_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
80void destroy_at(_Tp* __loc) {
81 _VSTD::__destroy_at(__loc);
82}
83
84#if _LIBCPP_STD_VER > 17
85template <class _Tp, enable_if_t<is_array_v<_Tp>, int> = 0>
86_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
87void destroy_at(_Tp* __loc) {
88 _VSTD::__destroy_at(__loc);
89}
90#endif
91
92template <class _ForwardIterator>
93_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
94void destroy(_ForwardIterator __first, _ForwardIterator __last) {
95 (void)_VSTD::__destroy(_VSTD::move(__first), _VSTD::move(__last));
96}
97
98template <class _ForwardIterator, class _Size>
99_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
100_ForwardIterator destroy_n(_ForwardIterator __first, _Size __n) {
101 for (; __n > 0; (void)++__first, --__n)
102 _VSTD::__destroy_at(_VSTD::addressof(*__first));
103 return __first;
104}
105
106#endif // _LIBCPP_STD_VER > 14
107
108_LIBCPP_END_NAMESPACE_STD
58109
59110#endif // _LIBCPP___MEMORY_CONSTRUCT_AT_H
lib/libcxx/include/__memory/pointer_safety.h deleted-57
......@@ -1,57 +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___MEMORY_POINTER_SAFETY_H
11#define _LIBCPP___MEMORY_POINTER_SAFETY_H
12
13#include <__config>
14#include <cstddef>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
18#endif
19
20_LIBCPP_PUSH_MACROS
21#include <__undef_macros>
22
23_LIBCPP_BEGIN_NAMESPACE_STD
24
25#if !defined(_LIBCPP_CXX03_LANG)
26
27enum class pointer_safety : unsigned char {
28 relaxed,
29 preferred,
30 strict
31};
32
33inline _LIBCPP_INLINE_VISIBILITY
34pointer_safety get_pointer_safety() _NOEXCEPT {
35 return pointer_safety::relaxed;
36}
37
38_LIBCPP_FUNC_VIS void declare_reachable(void* __p);
39_LIBCPP_FUNC_VIS void declare_no_pointers(char* __p, size_t __n);
40_LIBCPP_FUNC_VIS void undeclare_no_pointers(char* __p, size_t __n);
41_LIBCPP_FUNC_VIS void* __undeclare_reachable(void* __p);
42
43template <class _Tp>
44inline _LIBCPP_INLINE_VISIBILITY
45_Tp*
46undeclare_reachable(_Tp* __p)
47{
48 return static_cast<_Tp*>(__undeclare_reachable(__p));
49}
50
51#endif // !C++03
52
53_LIBCPP_END_NAMESPACE_STD
54
55_LIBCPP_POP_MACROS
56
57#endif // _LIBCPP___MEMORY_POINTER_SAFETY_H
lib/libcxx/include/__memory/pointer_traits.h+20-17
......@@ -18,9 +18,6 @@
1818#pragma GCC system_header
1919#endif
2020
21_LIBCPP_PUSH_MACROS
22#include <__undef_macros>
23
2421_LIBCPP_BEGIN_NAMESPACE_STD
2522
2623template <class _Tp, class = void>
......@@ -36,19 +33,19 @@ struct __pointer_traits_element_type;
3633template <class _Ptr>
3734struct __pointer_traits_element_type<_Ptr, true>
3835{
39 typedef _LIBCPP_NODEBUG_TYPE typename _Ptr::element_type type;
36 typedef _LIBCPP_NODEBUG typename _Ptr::element_type type;
4037};
4138
4239template <template <class, class...> class _Sp, class _Tp, class ..._Args>
4340struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, true>
4441{
45 typedef _LIBCPP_NODEBUG_TYPE typename _Sp<_Tp, _Args...>::element_type type;
42 typedef _LIBCPP_NODEBUG typename _Sp<_Tp, _Args...>::element_type type;
4643};
4744
4845template <template <class, class...> class _Sp, class _Tp, class ..._Args>
4946struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, false>
5047{
51 typedef _LIBCPP_NODEBUG_TYPE _Tp type;
48 typedef _LIBCPP_NODEBUG _Tp type;
5249};
5350
5451template <class _Tp, class = void>
......@@ -61,13 +58,13 @@ struct __has_difference_type<_Tp,
6158template <class _Ptr, bool = __has_difference_type<_Ptr>::value>
6259struct __pointer_traits_difference_type
6360{
64 typedef _LIBCPP_NODEBUG_TYPE ptrdiff_t type;
61 typedef _LIBCPP_NODEBUG ptrdiff_t type;
6562};
6663
6764template <class _Ptr>
6865struct __pointer_traits_difference_type<_Ptr, true>
6966{
70 typedef _LIBCPP_NODEBUG_TYPE typename _Ptr::difference_type type;
67 typedef _LIBCPP_NODEBUG typename _Ptr::difference_type type;
7168};
7269
7370template <class _Tp, class _Up>
......@@ -87,9 +84,9 @@ template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
8784struct __pointer_traits_rebind
8885{
8986#ifndef _LIBCPP_CXX03_LANG
90 typedef _LIBCPP_NODEBUG_TYPE typename _Tp::template rebind<_Up> type;
87 typedef _LIBCPP_NODEBUG typename _Tp::template rebind<_Up> type;
9188#else
92 typedef _LIBCPP_NODEBUG_TYPE typename _Tp::template rebind<_Up>::other type;
89 typedef _LIBCPP_NODEBUG typename _Tp::template rebind<_Up>::other type;
9390#endif
9491};
9592
......@@ -97,9 +94,9 @@ template <template <class, class...> class _Sp, class _Tp, class ..._Args, class
9794struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, true>
9895{
9996#ifndef _LIBCPP_CXX03_LANG
100 typedef _LIBCPP_NODEBUG_TYPE typename _Sp<_Tp, _Args...>::template rebind<_Up> type;
97 typedef _LIBCPP_NODEBUG typename _Sp<_Tp, _Args...>::template rebind<_Up> type;
10198#else
102 typedef _LIBCPP_NODEBUG_TYPE typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type;
99 typedef _LIBCPP_NODEBUG typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type;
103100#endif
104101};
105102
......@@ -176,7 +173,9 @@ _Tp* __to_address(_Tp* __p) _NOEXCEPT {
176173}
177174
178175// enable_if is needed here to avoid instantiating checks for fancy pointers on raw pointers
179template <class _Pointer, class = _EnableIf<!is_pointer<_Pointer>::value> >
176template <class _Pointer, class = __enable_if_t<
177 !is_pointer<_Pointer>::value && !is_array<_Pointer>::value && !is_function<_Pointer>::value
178> >
180179_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
181180typename decay<decltype(__to_address_helper<_Pointer>::__call(declval<const _Pointer&>()))>::type
182181__to_address(const _Pointer& __p) _NOEXCEPT {
......@@ -187,7 +186,7 @@ template <class _Pointer, class>
187186struct __to_address_helper {
188187 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
189188 static decltype(_VSTD::__to_address(declval<const _Pointer&>().operator->()))
190 __call(const _Pointer&__p) _NOEXCEPT {
189 __call(const _Pointer& __p) _NOEXCEPT {
191190 return _VSTD::__to_address(__p.operator->());
192191 }
193192};
......@@ -196,12 +195,18 @@ template <class _Pointer>
196195struct __to_address_helper<_Pointer, decltype((void)pointer_traits<_Pointer>::to_address(declval<const _Pointer&>()))> {
197196 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
198197 static decltype(pointer_traits<_Pointer>::to_address(declval<const _Pointer&>()))
199 __call(const _Pointer&__p) _NOEXCEPT {
198 __call(const _Pointer& __p) _NOEXCEPT {
200199 return pointer_traits<_Pointer>::to_address(__p);
201200 }
202201};
203202
204203#if _LIBCPP_STD_VER > 17
204template <class _Tp>
205inline _LIBCPP_INLINE_VISIBILITY constexpr
206auto to_address(_Tp *__p) noexcept {
207 return _VSTD::__to_address(__p);
208}
209
205210template <class _Pointer>
206211inline _LIBCPP_INLINE_VISIBILITY constexpr
207212auto to_address(const _Pointer& __p) noexcept {
......@@ -211,6 +216,4 @@ auto to_address(const _Pointer& __p) noexcept {
211216
212217_LIBCPP_END_NAMESPACE_STD
213218
214_LIBCPP_POP_MACROS
215
216219#endif // _LIBCPP___MEMORY_POINTER_TRAITS_H
lib/libcxx/include/__memory/ranges_construct_at.h created+124
......@@ -0,0 +1,124 @@
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_RANGES_CONSTRUCT_AT_H
11#define _LIBCPP___MEMORY_RANGES_CONSTRUCT_AT_H
12
13#include <__concepts/destructible.h>
14#include <__config>
15#include <__iterator/incrementable_traits.h>
16#include <__iterator/readable_traits.h>
17#include <__memory/concepts.h>
18#include <__memory/construct_at.h>
19#include <__ranges/access.h>
20#include <__ranges/concepts.h>
21#include <__ranges/dangling.h>
22#include <__utility/declval.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_LIBCPP_BEGIN_NAMESPACE_STD
31
32#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
33namespace ranges {
34
35// construct_at
36
37namespace __construct_at {
38
39struct __fn {
40 template<class _Tp, class... _Args, class = decltype(
41 ::new (declval<void*>()) _Tp(declval<_Args>()...)
42 )>
43 _LIBCPP_HIDE_FROM_ABI
44 constexpr _Tp* operator()(_Tp* __location, _Args&& ...__args) const {
45 return _VSTD::construct_at(__location, _VSTD::forward<_Args>(__args)...);
46 }
47};
48
49} // namespace __construct_at
50
51inline namespace __cpo {
52 inline constexpr auto construct_at = __construct_at::__fn{};
53} // namespace __cpo
54
55// destroy_at
56
57namespace __destroy_at {
58
59struct __fn {
60 template <destructible _Tp>
61 _LIBCPP_HIDE_FROM_ABI
62 constexpr void operator()(_Tp* __location) const noexcept {
63 _VSTD::destroy_at(__location);
64 }
65};
66
67} // namespace __destroy_at
68
69inline namespace __cpo {
70 inline constexpr auto destroy_at = __destroy_at::__fn{};
71} // namespace __cpo
72
73// destroy
74
75namespace __destroy {
76
77struct __fn {
78 template <__nothrow_input_iterator _InputIterator, __nothrow_sentinel_for<_InputIterator> _Sentinel>
79 requires destructible<iter_value_t<_InputIterator>>
80 _LIBCPP_HIDE_FROM_ABI
81 constexpr _InputIterator operator()(_InputIterator __first, _Sentinel __last) const noexcept {
82 return _VSTD::__destroy(_VSTD::move(__first), _VSTD::move(__last));
83 }
84
85 template <__nothrow_input_range _InputRange>
86 requires destructible<range_value_t<_InputRange>>
87 _LIBCPP_HIDE_FROM_ABI
88 constexpr borrowed_iterator_t<_InputRange> operator()(_InputRange&& __range) const noexcept {
89 return (*this)(ranges::begin(__range), ranges::end(__range));
90 }
91};
92
93} // namespace __destroy
94
95inline namespace __cpo {
96 inline constexpr auto destroy = __destroy::__fn{};
97} // namespace __cpo
98
99// destroy_n
100
101namespace __destroy_n {
102
103struct __fn {
104 template <__nothrow_input_iterator _InputIterator>
105 requires destructible<iter_value_t<_InputIterator>>
106 _LIBCPP_HIDE_FROM_ABI
107 constexpr _InputIterator operator()(_InputIterator __first, iter_difference_t<_InputIterator> __n) const noexcept {
108 return _VSTD::destroy_n(_VSTD::move(__first), __n);
109 }
110};
111
112} // namespace __destroy_n
113
114inline namespace __cpo {
115 inline constexpr auto destroy_n = __destroy_n::__fn{};
116} // namespace __cpo
117
118} // namespace ranges
119
120#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
121
122_LIBCPP_END_NAMESPACE_STD
123
124#endif // _LIBCPP___MEMORY_RANGES_CONSTRUCT_AT_H
lib/libcxx/include/__memory/ranges_uninitialized_algorithms.h created+318
......@@ -0,0 +1,318 @@
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_RANGES_UNINITIALIZED_ALGORITHMS_H
11#define _LIBCPP___MEMORY_RANGES_UNINITIALIZED_ALGORITHMS_H
12
13#include <__algorithm/in_out_result.h>
14#include <__concepts/constructible.h>
15#include <__config>
16#include <__iterator/concepts.h>
17#include <__iterator/incrementable_traits.h>
18#include <__iterator/iter_move.h>
19#include <__iterator/iterator_traits.h>
20#include <__iterator/readable_traits.h>
21#include <__memory/concepts.h>
22#include <__memory/uninitialized_algorithms.h>
23#include <__ranges/access.h>
24#include <__ranges/concepts.h>
25#include <__ranges/dangling.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_LIBCPP_BEGIN_NAMESPACE_STD
34
35#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
36
37namespace ranges {
38
39// uninitialized_default_construct
40
41namespace __uninitialized_default_construct {
42
43struct __fn {
44 template <__nothrow_forward_iterator _ForwardIterator,
45 __nothrow_sentinel_for<_ForwardIterator> _Sentinel>
46 requires default_initializable<iter_value_t<_ForwardIterator>>
47 _ForwardIterator operator()(_ForwardIterator __first, _Sentinel __last) const {
48 using _ValueType = remove_reference_t<iter_reference_t<_ForwardIterator>>;
49 return _VSTD::__uninitialized_default_construct<_ValueType>(
50 _VSTD::move(__first), _VSTD::move(__last));
51 }
52
53 template <__nothrow_forward_range _ForwardRange>
54 requires default_initializable<range_value_t<_ForwardRange>>
55 borrowed_iterator_t<_ForwardRange> operator()(_ForwardRange&& __range) const {
56 return (*this)(ranges::begin(__range), ranges::end(__range));
57 }
58};
59
60} // namespace __uninitialized_default_construct
61
62inline namespace __cpo {
63 inline constexpr auto uninitialized_default_construct = __uninitialized_default_construct::__fn{};
64} // namespace __cpo
65
66// uninitialized_default_construct_n
67
68namespace __uninitialized_default_construct_n {
69
70struct __fn {
71 template <__nothrow_forward_iterator _ForwardIterator>
72 requires default_initializable<iter_value_t<_ForwardIterator>>
73 _ForwardIterator operator()(_ForwardIterator __first,
74 iter_difference_t<_ForwardIterator> __n) const {
75 using _ValueType = remove_reference_t<iter_reference_t<_ForwardIterator>>;
76 return _VSTD::__uninitialized_default_construct_n<_ValueType>(_VSTD::move(__first), __n);
77 }
78};
79
80} // namespace __uninitialized_default_construct_n
81
82inline namespace __cpo {
83 inline constexpr auto uninitialized_default_construct_n = __uninitialized_default_construct_n::__fn{};
84} // namespace __cpo
85
86// uninitialized_value_construct
87
88namespace __uninitialized_value_construct {
89
90struct __fn {
91 template <__nothrow_forward_iterator _ForwardIterator,
92 __nothrow_sentinel_for<_ForwardIterator> _Sentinel>
93 requires default_initializable<iter_value_t<_ForwardIterator>>
94 _ForwardIterator operator()(_ForwardIterator __first, _Sentinel __last) const {
95 using _ValueType = remove_reference_t<iter_reference_t<_ForwardIterator>>;
96 return _VSTD::__uninitialized_value_construct<_ValueType>(
97 _VSTD::move(__first), _VSTD::move(__last));
98 }
99
100 template <__nothrow_forward_range _ForwardRange>
101 requires default_initializable<range_value_t<_ForwardRange>>
102 borrowed_iterator_t<_ForwardRange> operator()(_ForwardRange&& __range) const {
103 return (*this)(ranges::begin(__range), ranges::end(__range));
104 }
105};
106
107} // namespace __uninitialized_value_construct
108
109inline namespace __cpo {
110 inline constexpr auto uninitialized_value_construct = __uninitialized_value_construct::__fn{};
111} // namespace __cpo
112
113// uninitialized_value_construct_n
114
115namespace __uninitialized_value_construct_n {
116
117struct __fn {
118 template <__nothrow_forward_iterator _ForwardIterator>
119 requires default_initializable<iter_value_t<_ForwardIterator>>
120 _ForwardIterator operator()(_ForwardIterator __first,
121 iter_difference_t<_ForwardIterator> __n) const {
122 using _ValueType = remove_reference_t<iter_reference_t<_ForwardIterator>>;
123 return _VSTD::__uninitialized_value_construct_n<_ValueType>(_VSTD::move(__first), __n);
124 }
125};
126
127} // namespace __uninitialized_value_construct_n
128
129inline namespace __cpo {
130 inline constexpr auto uninitialized_value_construct_n = __uninitialized_value_construct_n::__fn{};
131} // namespace __cpo
132
133// uninitialized_fill
134
135namespace __uninitialized_fill {
136
137struct __fn {
138 template <__nothrow_forward_iterator _ForwardIterator,
139 __nothrow_sentinel_for<_ForwardIterator> _Sentinel,
140 class _Tp>
141 requires constructible_from<iter_value_t<_ForwardIterator>, const _Tp&>
142 _ForwardIterator operator()(_ForwardIterator __first, _Sentinel __last, const _Tp& __x) const {
143 using _ValueType = remove_reference_t<iter_reference_t<_ForwardIterator>>;
144 return _VSTD::__uninitialized_fill<_ValueType>(_VSTD::move(__first), _VSTD::move(__last), __x);
145 }
146
147 template <__nothrow_forward_range _ForwardRange, class _Tp>
148 requires constructible_from<range_value_t<_ForwardRange>, const _Tp&>
149 borrowed_iterator_t<_ForwardRange> operator()(_ForwardRange&& __range, const _Tp& __x) const {
150 return (*this)(ranges::begin(__range), ranges::end(__range), __x);
151 }
152};
153
154} // namespace __uninitialized_fill
155
156inline namespace __cpo {
157 inline constexpr auto uninitialized_fill = __uninitialized_fill::__fn{};
158} // namespace __cpo
159
160// uninitialized_fill_n
161
162namespace __uninitialized_fill_n {
163
164struct __fn {
165 template <__nothrow_forward_iterator _ForwardIterator, class _Tp>
166 requires constructible_from<iter_value_t<_ForwardIterator>, const _Tp&>
167 _ForwardIterator operator()(_ForwardIterator __first,
168 iter_difference_t<_ForwardIterator> __n,
169 const _Tp& __x) const {
170 using _ValueType = remove_reference_t<iter_reference_t<_ForwardIterator>>;
171 return _VSTD::__uninitialized_fill_n<_ValueType>(_VSTD::move(__first), __n, __x);
172 }
173};
174
175} // namespace __uninitialized_fill_n
176
177inline namespace __cpo {
178 inline constexpr auto uninitialized_fill_n = __uninitialized_fill_n::__fn{};
179} // namespace __cpo
180
181// uninitialized_copy
182
183template <class _InputIterator, class _OutputIterator>
184using uninitialized_copy_result = in_out_result<_InputIterator, _OutputIterator>;
185
186namespace __uninitialized_copy {
187
188struct __fn {
189 template <input_iterator _InputIterator,
190 sentinel_for<_InputIterator> _Sentinel1,
191 __nothrow_forward_iterator _OutputIterator,
192 __nothrow_sentinel_for<_OutputIterator> _Sentinel2>
193 requires constructible_from<iter_value_t<_OutputIterator>, iter_reference_t<_InputIterator>>
194 uninitialized_copy_result<_InputIterator, _OutputIterator>
195 operator()(_InputIterator __ifirst, _Sentinel1 __ilast, _OutputIterator __ofirst, _Sentinel2 __olast) const {
196 using _ValueType = remove_reference_t<iter_reference_t<_OutputIterator>>;
197
198 auto __result = _VSTD::__uninitialized_copy<_ValueType>(_VSTD::move(__ifirst), _VSTD::move(__ilast),
199 _VSTD::move(__ofirst), _VSTD::move(__olast));
200 return {_VSTD::move(__result.first), _VSTD::move(__result.second)};
201 }
202
203 template <input_range _InputRange, __nothrow_forward_range _OutputRange>
204 requires constructible_from<range_value_t<_OutputRange>, range_reference_t<_InputRange>>
205 uninitialized_copy_result<borrowed_iterator_t<_InputRange>, borrowed_iterator_t<_OutputRange>>
206 operator()( _InputRange&& __in_range, _OutputRange&& __out_range) const {
207 return (*this)(ranges::begin(__in_range), ranges::end(__in_range),
208 ranges::begin(__out_range), ranges::end(__out_range));
209 }
210};
211
212} // namespace __uninitialized_copy
213
214inline namespace __cpo {
215 inline constexpr auto uninitialized_copy = __uninitialized_copy::__fn{};
216} // namespace __cpo
217
218// uninitialized_copy_n
219
220template <class _InputIterator, class _OutputIterator>
221using uninitialized_copy_n_result = in_out_result<_InputIterator, _OutputIterator>;
222
223namespace __uninitialized_copy_n {
224
225struct __fn {
226 template <input_iterator _InputIterator,
227 __nothrow_forward_iterator _OutputIterator,
228 __nothrow_sentinel_for<_OutputIterator> _Sentinel>
229 requires constructible_from<iter_value_t<_OutputIterator>, iter_reference_t<_InputIterator>>
230 uninitialized_copy_n_result<_InputIterator, _OutputIterator>
231 operator()(_InputIterator __ifirst, iter_difference_t<_InputIterator> __n,
232 _OutputIterator __ofirst, _Sentinel __olast) const {
233 using _ValueType = remove_reference_t<iter_reference_t<_OutputIterator>>;
234 auto __result = _VSTD::__uninitialized_copy_n<_ValueType>(_VSTD::move(__ifirst), __n,
235 _VSTD::move(__ofirst), _VSTD::move(__olast));
236 return {_VSTD::move(__result.first), _VSTD::move(__result.second)};
237 }
238};
239
240} // namespace __uninitialized_copy_n
241
242inline namespace __cpo {
243 inline constexpr auto uninitialized_copy_n = __uninitialized_copy_n::__fn{};
244} // namespace __cpo
245
246// uninitialized_move
247
248template <class _InputIterator, class _OutputIterator>
249using uninitialized_move_result = in_out_result<_InputIterator, _OutputIterator>;
250
251namespace __uninitialized_move {
252
253struct __fn {
254 template <input_iterator _InputIterator,
255 sentinel_for<_InputIterator> _Sentinel1,
256 __nothrow_forward_iterator _OutputIterator,
257 __nothrow_sentinel_for<_OutputIterator> _Sentinel2>
258 requires constructible_from<iter_value_t<_OutputIterator>, iter_reference_t<_InputIterator>>
259 uninitialized_move_result<_InputIterator, _OutputIterator>
260 operator()(_InputIterator __ifirst, _Sentinel1 __ilast, _OutputIterator __ofirst, _Sentinel2 __olast) const {
261 using _ValueType = remove_reference_t<iter_reference_t<_OutputIterator>>;
262 auto __iter_move = [](auto&& __iter) -> decltype(auto) { return ranges::iter_move(__iter); };
263 auto __result = _VSTD::__uninitialized_move<_ValueType>(_VSTD::move(__ifirst), _VSTD::move(__ilast),
264 _VSTD::move(__ofirst), _VSTD::move(__olast), __iter_move);
265 return {_VSTD::move(__result.first), _VSTD::move(__result.second)};
266 }
267
268 template <input_range _InputRange, __nothrow_forward_range _OutputRange>
269 requires constructible_from<range_value_t<_OutputRange>, range_reference_t<_InputRange>>
270 uninitialized_move_result<borrowed_iterator_t<_InputRange>, borrowed_iterator_t<_OutputRange>>
271 operator()(_InputRange&& __in_range, _OutputRange&& __out_range) const {
272 return (*this)(ranges::begin(__in_range), ranges::end(__in_range),
273 ranges::begin(__out_range), ranges::end(__out_range));
274 }
275};
276
277} // namespace __uninitialized_move
278
279inline namespace __cpo {
280 inline constexpr auto uninitialized_move = __uninitialized_move::__fn{};
281} // namespace __cpo
282
283// uninitialized_move_n
284
285template <class _InputIterator, class _OutputIterator>
286using uninitialized_move_n_result = in_out_result<_InputIterator, _OutputIterator>;
287
288namespace __uninitialized_move_n {
289
290struct __fn {
291 template <input_iterator _InputIterator,
292 __nothrow_forward_iterator _OutputIterator,
293 __nothrow_sentinel_for<_OutputIterator> _Sentinel>
294 requires constructible_from<iter_value_t<_OutputIterator>, iter_reference_t<_InputIterator>>
295 uninitialized_move_n_result<_InputIterator, _OutputIterator>
296 operator()(_InputIterator __ifirst, iter_difference_t<_InputIterator> __n,
297 _OutputIterator __ofirst, _Sentinel __olast) const {
298 using _ValueType = remove_reference_t<iter_reference_t<_OutputIterator>>;
299 auto __iter_move = [](auto&& __iter) -> decltype(auto) { return ranges::iter_move(__iter); };
300 auto __result = _VSTD::__uninitialized_move_n<_ValueType>(_VSTD::move(__ifirst), __n,
301 _VSTD::move(__ofirst), _VSTD::move(__olast), __iter_move);
302 return {_VSTD::move(__result.first), _VSTD::move(__result.second)};
303 }
304};
305
306} // namespace __uninitialized_move_n
307
308inline namespace __cpo {
309 inline constexpr auto uninitialized_move_n = __uninitialized_move_n::__fn{};
310} // namespace __cpo
311
312} // namespace ranges
313
314#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
315
316_LIBCPP_END_NAMESPACE_STD
317
318#endif // _LIBCPP___MEMORY_RANGES_UNINITIALIZED_ALGORITHMS_H
lib/libcxx/include/__memory/raw_storage_iterator.h-5
......@@ -20,9 +20,6 @@
2020#pragma GCC system_header
2121#endif
2222
23_LIBCPP_PUSH_MACROS
24#include <__undef_macros>
25
2623_LIBCPP_BEGIN_NAMESPACE_STD
2724
2825#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR)
......@@ -68,6 +65,4 @@ public:
6865
6966_LIBCPP_END_NAMESPACE_STD
7067
71_LIBCPP_POP_MACROS
72
7368#endif // _LIBCPP___MEMORY_RAW_STORAGE_ITERATOR_H
lib/libcxx/include/__memory/shared_ptr.h+446-606
......@@ -12,14 +12,14 @@
1212
1313#include <__availability>
1414#include <__config>
15#include <__functional_base>
1615#include <__functional/binary_function.h>
1716#include <__functional/operations.h>
1817#include <__functional/reference_wrapper.h>
18#include <__functional_base>
1919#include <__memory/addressof.h>
2020#include <__memory/allocation_guard.h>
21#include <__memory/allocator_traits.h>
2221#include <__memory/allocator.h>
22#include <__memory/allocator_traits.h>
2323#include <__memory/compressed_pair.h>
2424#include <__memory/pointer_traits.h>
2525#include <__memory/unique_ptr.h>
......@@ -28,8 +28,8 @@
2828#include <cstdlib> // abort
2929#include <iosfwd>
3030#include <stdexcept>
31#include <typeinfo>
3231#include <type_traits>
32#include <typeinfo>
3333#include <utility>
3434#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
3535# include <atomic>
......@@ -43,18 +43,15 @@
4343#pragma GCC system_header
4444#endif
4545
46_LIBCPP_PUSH_MACROS
47#include <__undef_macros>
48
4946_LIBCPP_BEGIN_NAMESPACE_STD
5047
5148template <class _Alloc>
5249class __allocator_destructor
5350{
54 typedef _LIBCPP_NODEBUG_TYPE allocator_traits<_Alloc> __alloc_traits;
51 typedef _LIBCPP_NODEBUG allocator_traits<_Alloc> __alloc_traits;
5552public:
56 typedef _LIBCPP_NODEBUG_TYPE typename __alloc_traits::pointer pointer;
57 typedef _LIBCPP_NODEBUG_TYPE typename __alloc_traits::size_type size_type;
53 typedef _LIBCPP_NODEBUG typename __alloc_traits::pointer pointer;
54 typedef _LIBCPP_NODEBUG typename __alloc_traits::size_type size_type;
5855private:
5956 _Alloc& __alloc_;
6057 size_type __s_;
......@@ -433,14 +430,20 @@ private:
433430 element_type* __ptr_;
434431 __shared_weak_count* __cntrl_;
435432
436 struct __nat {int __for_bool_;};
437433public:
438 _LIBCPP_INLINE_VISIBILITY
439 _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT;
440 _LIBCPP_INLINE_VISIBILITY
441 _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT;
434 _LIBCPP_HIDE_FROM_ABI
435 _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT
436 : __ptr_(nullptr),
437 __cntrl_(nullptr)
438 { }
439
440 _LIBCPP_HIDE_FROM_ABI
441 _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT
442 : __ptr_(nullptr),
443 __cntrl_(nullptr)
444 { }
442445
443 template<class _Yp, class = _EnableIf<
446 template<class _Yp, class = __enable_if_t<
444447 _And<
445448 __compatible_with<_Yp, _Tp>
446449 // In C++03 we get errors when trying to do SFINAE with the
......@@ -460,643 +463,488 @@ public:
460463 __enable_weak_this(__p, __p);
461464 }
462465
463 template<class _Yp, class _Dp>
464 shared_ptr(_Yp* __p, _Dp __d,
465 typename enable_if<__shared_ptr_deleter_ctor_reqs<_Dp, _Yp, element_type>::value, __nat>::type = __nat());
466 template<class _Yp, class _Dp, class _Alloc>
467 shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
468 typename enable_if<__shared_ptr_deleter_ctor_reqs<_Dp, _Yp, element_type>::value, __nat>::type = __nat());
469 template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d);
470 template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a);
471 template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT;
472 _LIBCPP_INLINE_VISIBILITY
473 shared_ptr(const shared_ptr& __r) _NOEXCEPT;
474 template<class _Yp>
475 _LIBCPP_INLINE_VISIBILITY
476 shared_ptr(const shared_ptr<_Yp>& __r,
477 typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type = __nat())
478 _NOEXCEPT;
479 _LIBCPP_INLINE_VISIBILITY
480 shared_ptr(shared_ptr&& __r) _NOEXCEPT;
481 template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(shared_ptr<_Yp>&& __r,
482 typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type = __nat())
483 _NOEXCEPT;
484 template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r,
485 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type= __nat());
486#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
487 template<class _Yp>
488 shared_ptr(auto_ptr<_Yp>&& __r,
489 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
490#endif
491 template <class _Yp, class _Dp>
492 shared_ptr(unique_ptr<_Yp, _Dp>&&,
493 typename enable_if
494 <
495 !is_lvalue_reference<_Dp>::value &&
496 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
497 __nat
498 >::type = __nat());
499 template <class _Yp, class _Dp>
500 shared_ptr(unique_ptr<_Yp, _Dp>&&,
501 typename enable_if
502 <
503 is_lvalue_reference<_Dp>::value &&
504 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
505 __nat
506 >::type = __nat());
507
508 ~shared_ptr();
466 template<class _Yp, class _Dp, class = __enable_if_t<__shared_ptr_deleter_ctor_reqs<_Dp, _Yp, element_type>::value> >
467 _LIBCPP_HIDE_FROM_ABI
468 shared_ptr(_Yp* __p, _Dp __d)
469 : __ptr_(__p)
470 {
471#ifndef _LIBCPP_NO_EXCEPTIONS
472 try
473 {
474#endif // _LIBCPP_NO_EXCEPTIONS
475 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
476 typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk;
477#ifndef _LIBCPP_CXX03_LANG
478 __cntrl_ = new _CntrlBlk(__p, _VSTD::move(__d), _AllocT());
479#else
480 __cntrl_ = new _CntrlBlk(__p, __d, _AllocT());
481#endif // not _LIBCPP_CXX03_LANG
482 __enable_weak_this(__p, __p);
483#ifndef _LIBCPP_NO_EXCEPTIONS
484 }
485 catch (...)
486 {
487 __d(__p);
488 throw;
489 }
490#endif // _LIBCPP_NO_EXCEPTIONS
491 }
509492
510 _LIBCPP_INLINE_VISIBILITY
511 shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT;
512 template<class _Yp>
513 typename enable_if
514 <
515 __compatible_with<_Yp, element_type>::value,
516 shared_ptr&
517 >::type
518 _LIBCPP_INLINE_VISIBILITY
519 operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT;
520 _LIBCPP_INLINE_VISIBILITY
521 shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT;
522 template<class _Yp>
523 typename enable_if
524 <
525 __compatible_with<_Yp, element_type>::value,
526 shared_ptr&
527 >::type
528 _LIBCPP_INLINE_VISIBILITY
529 operator=(shared_ptr<_Yp>&& __r);
530#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
531 template<class _Yp>
532 _LIBCPP_INLINE_VISIBILITY
533 typename enable_if
534 <
535 !is_array<_Yp>::value &&
536 is_convertible<_Yp*, element_type*>::value,
537 shared_ptr
538 >::type&
539 operator=(auto_ptr<_Yp>&& __r);
540#endif
541 template <class _Yp, class _Dp>
542 typename enable_if
543 <
544 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
545 shared_ptr&
546 >::type
547 _LIBCPP_INLINE_VISIBILITY
548 operator=(unique_ptr<_Yp, _Dp>&& __r);
493 template<class _Yp, class _Dp, class _Alloc, class = __enable_if_t<__shared_ptr_deleter_ctor_reqs<_Dp, _Yp, element_type>::value> >
494 _LIBCPP_HIDE_FROM_ABI
495 shared_ptr(_Yp* __p, _Dp __d, _Alloc __a)
496 : __ptr_(__p)
497 {
498#ifndef _LIBCPP_NO_EXCEPTIONS
499 try
500 {
501#endif // _LIBCPP_NO_EXCEPTIONS
502 typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk;
503 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
504 typedef __allocator_destructor<_A2> _D2;
505 _A2 __a2(__a);
506 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
507 ::new ((void*)_VSTD::addressof(*__hold2.get()))
508#ifndef _LIBCPP_CXX03_LANG
509 _CntrlBlk(__p, _VSTD::move(__d), __a);
510#else
511 _CntrlBlk(__p, __d, __a);
512#endif // not _LIBCPP_CXX03_LANG
513 __cntrl_ = _VSTD::addressof(*__hold2.release());
514 __enable_weak_this(__p, __p);
515#ifndef _LIBCPP_NO_EXCEPTIONS
516 }
517 catch (...)
518 {
519 __d(__p);
520 throw;
521 }
522#endif // _LIBCPP_NO_EXCEPTIONS
523 }
524
525 template<class _Dp>
526 _LIBCPP_HIDE_FROM_ABI
527 shared_ptr(nullptr_t __p, _Dp __d)
528 : __ptr_(nullptr)
529 {
530#ifndef _LIBCPP_NO_EXCEPTIONS
531 try
532 {
533#endif // _LIBCPP_NO_EXCEPTIONS
534 typedef typename __shared_ptr_default_allocator<_Tp>::type _AllocT;
535 typedef __shared_ptr_pointer<nullptr_t, _Dp, _AllocT > _CntrlBlk;
536#ifndef _LIBCPP_CXX03_LANG
537 __cntrl_ = new _CntrlBlk(__p, _VSTD::move(__d), _AllocT());
538#else
539 __cntrl_ = new _CntrlBlk(__p, __d, _AllocT());
540#endif // not _LIBCPP_CXX03_LANG
541#ifndef _LIBCPP_NO_EXCEPTIONS
542 }
543 catch (...)
544 {
545 __d(__p);
546 throw;
547 }
548#endif // _LIBCPP_NO_EXCEPTIONS
549 }
550
551 template<class _Dp, class _Alloc>
552 _LIBCPP_HIDE_FROM_ABI
553 shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a)
554 : __ptr_(nullptr)
555 {
556#ifndef _LIBCPP_NO_EXCEPTIONS
557 try
558 {
559#endif // _LIBCPP_NO_EXCEPTIONS
560 typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk;
561 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
562 typedef __allocator_destructor<_A2> _D2;
563 _A2 __a2(__a);
564 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
565 ::new ((void*)_VSTD::addressof(*__hold2.get()))
566#ifndef _LIBCPP_CXX03_LANG
567 _CntrlBlk(__p, _VSTD::move(__d), __a);
568#else
569 _CntrlBlk(__p, __d, __a);
570#endif // not _LIBCPP_CXX03_LANG
571 __cntrl_ = _VSTD::addressof(*__hold2.release());
572#ifndef _LIBCPP_NO_EXCEPTIONS
573 }
574 catch (...)
575 {
576 __d(__p);
577 throw;
578 }
579#endif // _LIBCPP_NO_EXCEPTIONS
580 }
549581
550 _LIBCPP_INLINE_VISIBILITY
551 void swap(shared_ptr& __r) _NOEXCEPT;
552 _LIBCPP_INLINE_VISIBILITY
553 void reset() _NOEXCEPT;
554582 template<class _Yp>
555 typename enable_if
556 <
557 __compatible_with<_Yp, element_type>::value,
558 void
559 >::type
560 _LIBCPP_INLINE_VISIBILITY
561 reset(_Yp* __p);
562 template<class _Yp, class _Dp>
563 typename enable_if
564 <
565 __compatible_with<_Yp, element_type>::value,
566 void
567 >::type
568 _LIBCPP_INLINE_VISIBILITY
569 reset(_Yp* __p, _Dp __d);
570 template<class _Yp, class _Dp, class _Alloc>
571 typename enable_if
572 <
573 __compatible_with<_Yp, element_type>::value,
574 void
575 >::type
576 _LIBCPP_INLINE_VISIBILITY
577 reset(_Yp* __p, _Dp __d, _Alloc __a);
583 _LIBCPP_HIDE_FROM_ABI
584 shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT
585 : __ptr_(__p),
586 __cntrl_(__r.__cntrl_)
587 {
588 if (__cntrl_)
589 __cntrl_->__add_shared();
590 }
578591
579 _LIBCPP_INLINE_VISIBILITY
580 element_type* get() const _NOEXCEPT {return __ptr_;}
581 _LIBCPP_INLINE_VISIBILITY
582 typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT
583 {return *__ptr_;}
584 _LIBCPP_INLINE_VISIBILITY
585 element_type* operator->() const _NOEXCEPT
592 _LIBCPP_HIDE_FROM_ABI
593 shared_ptr(const shared_ptr& __r) _NOEXCEPT
594 : __ptr_(__r.__ptr_),
595 __cntrl_(__r.__cntrl_)
586596 {
587 static_assert(!is_array<_Tp>::value,
588 "std::shared_ptr<T>::operator-> is only valid when T is not an array type.");
589 return __ptr_;
597 if (__cntrl_)
598 __cntrl_->__add_shared();
590599 }
591 _LIBCPP_INLINE_VISIBILITY
592 long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;}
593 _LIBCPP_INLINE_VISIBILITY
594 bool unique() const _NOEXCEPT {return use_count() == 1;}
595 _LIBCPP_INLINE_VISIBILITY
596 explicit operator bool() const _NOEXCEPT {return get() != nullptr;}
597 template <class _Up>
598 _LIBCPP_INLINE_VISIBILITY
599 bool owner_before(shared_ptr<_Up> const& __p) const _NOEXCEPT
600 {return __cntrl_ < __p.__cntrl_;}
601 template <class _Up>
602 _LIBCPP_INLINE_VISIBILITY
603 bool owner_before(weak_ptr<_Up> const& __p) const _NOEXCEPT
604 {return __cntrl_ < __p.__cntrl_;}
605 _LIBCPP_INLINE_VISIBILITY
606 bool
607 __owner_equivalent(const shared_ptr& __p) const
608 {return __cntrl_ == __p.__cntrl_;}
609600
610#if _LIBCPP_STD_VER > 14
611 typename add_lvalue_reference<element_type>::type
612 _LIBCPP_INLINE_VISIBILITY
613 operator[](ptrdiff_t __i) const
601 template<class _Yp, class = __enable_if_t<__compatible_with<_Yp, _Tp>::value> >
602 _LIBCPP_HIDE_FROM_ABI
603 shared_ptr(const shared_ptr<_Yp>& __r) _NOEXCEPT
604 : __ptr_(__r.__ptr_),
605 __cntrl_(__r.__cntrl_)
614606 {
615 static_assert(is_array<_Tp>::value,
616 "std::shared_ptr<T>::operator[] is only valid when T is an array type.");
617 return __ptr_[__i];
607 if (__cntrl_)
608 __cntrl_->__add_shared();
618609 }
619#endif
620610
621#ifndef _LIBCPP_NO_RTTI
622 template <class _Dp>
623 _LIBCPP_INLINE_VISIBILITY
624 _Dp* __get_deleter() const _NOEXCEPT
625 {return static_cast<_Dp*>(__cntrl_
626 ? const_cast<void *>(__cntrl_->__get_deleter(typeid(_Dp)))
627 : nullptr);}
628#endif // _LIBCPP_NO_RTTI
611 _LIBCPP_HIDE_FROM_ABI
612 shared_ptr(shared_ptr&& __r) _NOEXCEPT
613 : __ptr_(__r.__ptr_),
614 __cntrl_(__r.__cntrl_)
615 {
616 __r.__ptr_ = nullptr;
617 __r.__cntrl_ = nullptr;
618 }
629619
630 template<class _Yp, class _CntrlBlk>
631 static shared_ptr<_Tp>
632 __create_with_control_block(_Yp* __p, _CntrlBlk* __cntrl) _NOEXCEPT
620 template<class _Yp, class = __enable_if_t<__compatible_with<_Yp, _Tp>::value> >
621 _LIBCPP_HIDE_FROM_ABI
622 shared_ptr(shared_ptr<_Yp>&& __r) _NOEXCEPT
623 : __ptr_(__r.__ptr_),
624 __cntrl_(__r.__cntrl_)
633625 {
634 shared_ptr<_Tp> __r;
635 __r.__ptr_ = __p;
636 __r.__cntrl_ = __cntrl;
637 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
638 return __r;
626 __r.__ptr_ = nullptr;
627 __r.__cntrl_ = nullptr;
639628 }
640629
641private:
642 template <class _Yp, bool = is_function<_Yp>::value>
643 struct __shared_ptr_default_allocator
644 {
645 typedef allocator<_Yp> type;
646 };
630 template<class _Yp, class = __enable_if_t<__compatible_with<_Yp, _Tp>::value> >
631 _LIBCPP_HIDE_FROM_ABI
632 explicit shared_ptr(const weak_ptr<_Yp>& __r)
633 : __ptr_(__r.__ptr_),
634 __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_)
635 {
636 if (__cntrl_ == nullptr)
637 __throw_bad_weak_ptr();
638 }
647639
648 template <class _Yp>
649 struct __shared_ptr_default_allocator<_Yp, true>
640#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
641 template<class _Yp, class = __enable_if_t<is_convertible<_Yp*, element_type*>::value> >
642 _LIBCPP_HIDE_FROM_ABI
643 shared_ptr(auto_ptr<_Yp>&& __r)
644 : __ptr_(__r.get())
645 {
646 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
647 __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>());
648 __enable_weak_this(__r.get(), __r.get());
649 __r.release();
650 }
651#endif
652
653 template <class _Yp, class _Dp, class = __enable_if_t<
654 !is_lvalue_reference<_Dp>::value &&
655 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
656 > >
657 _LIBCPP_HIDE_FROM_ABI
658 shared_ptr(unique_ptr<_Yp, _Dp>&& __r)
659 : __ptr_(__r.get())
660 {
661#if _LIBCPP_STD_VER > 11
662 if (__ptr_ == nullptr)
663 __cntrl_ = nullptr;
664 else
665#endif
650666 {
651 typedef allocator<__shared_ptr_dummy_rebind_allocator_type> type;
652 };
667 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());
670 __enable_weak_this(__r.get(), __r.get());
671 }
672 __r.release();
673 }
653674
654 template <class _Yp, class _OrigPtr>
655 _LIBCPP_INLINE_VISIBILITY
656 typename enable_if<is_convertible<_OrigPtr*,
657 const enable_shared_from_this<_Yp>*
658 >::value,
659 void>::type
660 __enable_weak_this(const enable_shared_from_this<_Yp>* __e,
661 _OrigPtr* __ptr) _NOEXCEPT
675 template <class _Yp, class _Dp, class = void, class = __enable_if_t<
676 is_lvalue_reference<_Dp>::value &&
677 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
678 > >
679 _LIBCPP_HIDE_FROM_ABI
680 shared_ptr(unique_ptr<_Yp, _Dp>&& __r)
681 : __ptr_(__r.get())
682 {
683#if _LIBCPP_STD_VER > 11
684 if (__ptr_ == nullptr)
685 __cntrl_ = nullptr;
686 else
687#endif
662688 {
663 typedef typename remove_cv<_Yp>::type _RawYp;
664 if (__e && __e->__weak_this_.expired())
665 {
666 __e->__weak_this_ = shared_ptr<_RawYp>(*this,
667 const_cast<_RawYp*>(static_cast<const _Yp*>(__ptr)));
668 }
689 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
690 typedef __shared_ptr_pointer<typename unique_ptr<_Yp, _Dp>::pointer,
691 reference_wrapper<typename remove_reference<_Dp>::type>,
692 _AllocT > _CntrlBlk;
693 __cntrl_ = new _CntrlBlk(__r.get(), _VSTD::ref(__r.get_deleter()), _AllocT());
694 __enable_weak_this(__r.get(), __r.get());
669695 }
696 __r.release();
697 }
670698
671 _LIBCPP_INLINE_VISIBILITY void __enable_weak_this(...) _NOEXCEPT {}
699 _LIBCPP_HIDE_FROM_ABI
700 ~shared_ptr()
701 {
702 if (__cntrl_)
703 __cntrl_->__release_shared();
704 }
672705
673 template <class, class _Yp>
674 struct __shared_ptr_default_delete
675 : default_delete<_Yp> {};
706 _LIBCPP_HIDE_FROM_ABI
707 shared_ptr<_Tp>& operator=(const shared_ptr& __r) _NOEXCEPT
708 {
709 shared_ptr(__r).swap(*this);
710 return *this;
711 }
676712
677 template <class _Yp, class _Un, size_t _Sz>
678 struct __shared_ptr_default_delete<_Yp[_Sz], _Un>
679 : default_delete<_Yp[]> {};
713 template<class _Yp, class = __enable_if_t<__compatible_with<_Yp, _Tp>::value> >
714 _LIBCPP_HIDE_FROM_ABI
715 shared_ptr<_Tp>& operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT
716 {
717 shared_ptr(__r).swap(*this);
718 return *this;
719 }
680720
681 template <class _Yp, class _Un>
682 struct __shared_ptr_default_delete<_Yp[], _Un>
683 : default_delete<_Yp[]> {};
721 _LIBCPP_HIDE_FROM_ABI
722 shared_ptr<_Tp>& operator=(shared_ptr&& __r) _NOEXCEPT
723 {
724 shared_ptr(_VSTD::move(__r)).swap(*this);
725 return *this;
726 }
684727
685 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr;
686 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr;
687};
728 template<class _Yp, class = __enable_if_t<__compatible_with<_Yp, _Tp>::value> >
729 _LIBCPP_HIDE_FROM_ABI
730 shared_ptr<_Tp>& operator=(shared_ptr<_Yp>&& __r)
731 {
732 shared_ptr(_VSTD::move(__r)).swap(*this);
733 return *this;
734 }
688735
689#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
690template<class _Tp>
691shared_ptr(weak_ptr<_Tp>) -> shared_ptr<_Tp>;
692template<class _Tp, class _Dp>
693shared_ptr(unique_ptr<_Tp, _Dp>) -> shared_ptr<_Tp>;
736#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
737 template<class _Yp, class = __enable_if_t<
738 !is_array<_Yp>::value &&
739 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value
740 > >
741 _LIBCPP_HIDE_FROM_ABI
742 shared_ptr<_Tp>& operator=(auto_ptr<_Yp>&& __r)
743 {
744 shared_ptr(_VSTD::move(__r)).swap(*this);
745 return *this;
746 }
694747#endif
695748
696template<class _Tp>
697inline
698_LIBCPP_CONSTEXPR
699shared_ptr<_Tp>::shared_ptr() _NOEXCEPT
700 : __ptr_(nullptr),
701 __cntrl_(nullptr)
702{
703}
749 template <class _Yp, class _Dp, class = __enable_if_t<
750 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
751 > >
752 _LIBCPP_HIDE_FROM_ABI
753 shared_ptr<_Tp>& operator=(unique_ptr<_Yp, _Dp>&& __r)
754 {
755 shared_ptr(_VSTD::move(__r)).swap(*this);
756 return *this;
757 }
704758
705template<class _Tp>
706inline
707_LIBCPP_CONSTEXPR
708shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT
709 : __ptr_(nullptr),
710 __cntrl_(nullptr)
711{
712}
759 _LIBCPP_HIDE_FROM_ABI
760 void swap(shared_ptr& __r) _NOEXCEPT
761 {
762 _VSTD::swap(__ptr_, __r.__ptr_);
763 _VSTD::swap(__cntrl_, __r.__cntrl_);
764 }
713765
714template<class _Tp>
715template<class _Yp, class _Dp>
716shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d,
717 typename enable_if<__shared_ptr_deleter_ctor_reqs<_Dp, _Yp, element_type>::value, __nat>::type)
718 : __ptr_(__p)
719{
720#ifndef _LIBCPP_NO_EXCEPTIONS
721 try
766 _LIBCPP_HIDE_FROM_ABI
767 void reset() _NOEXCEPT
722768 {
723#endif // _LIBCPP_NO_EXCEPTIONS
724 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
725 typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk;
726#ifndef _LIBCPP_CXX03_LANG
727 __cntrl_ = new _CntrlBlk(__p, _VSTD::move(__d), _AllocT());
728#else
729 __cntrl_ = new _CntrlBlk(__p, __d, _AllocT());
730#endif // not _LIBCPP_CXX03_LANG
731 __enable_weak_this(__p, __p);
732#ifndef _LIBCPP_NO_EXCEPTIONS
769 shared_ptr().swap(*this);
733770 }
734 catch (...)
771
772 template<class _Yp, class = __enable_if_t<
773 __compatible_with<_Yp, _Tp>::value
774 > >
775 _LIBCPP_HIDE_FROM_ABI
776 void reset(_Yp* __p)
735777 {
736 __d(__p);
737 throw;
778 shared_ptr(__p).swap(*this);
738779 }
739#endif // _LIBCPP_NO_EXCEPTIONS
740}
741780
742template<class _Tp>
743template<class _Dp>
744shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d)
745 : __ptr_(nullptr)
746{
747#ifndef _LIBCPP_NO_EXCEPTIONS
748 try
781 template<class _Yp, class _Dp, class = __enable_if_t<
782 __compatible_with<_Yp, _Tp>::value
783 > >
784 _LIBCPP_HIDE_FROM_ABI
785 void reset(_Yp* __p, _Dp __d)
749786 {
750#endif // _LIBCPP_NO_EXCEPTIONS
751 typedef typename __shared_ptr_default_allocator<_Tp>::type _AllocT;
752 typedef __shared_ptr_pointer<nullptr_t, _Dp, _AllocT > _CntrlBlk;
753#ifndef _LIBCPP_CXX03_LANG
754 __cntrl_ = new _CntrlBlk(__p, _VSTD::move(__d), _AllocT());
755#else
756 __cntrl_ = new _CntrlBlk(__p, __d, _AllocT());
757#endif // not _LIBCPP_CXX03_LANG
758#ifndef _LIBCPP_NO_EXCEPTIONS
787 shared_ptr(__p, __d).swap(*this);
759788 }
760 catch (...)
789
790 template<class _Yp, class _Dp, class _Alloc, class = __enable_if_t<
791 __compatible_with<_Yp, _Tp>::value
792 > >
793 _LIBCPP_HIDE_FROM_ABI
794 void reset(_Yp* __p, _Dp __d, _Alloc __a)
761795 {
762 __d(__p);
763 throw;
796 shared_ptr(__p, __d, __a).swap(*this);
764797 }
765#endif // _LIBCPP_NO_EXCEPTIONS
766}
767798
768template<class _Tp>
769template<class _Yp, class _Dp, class _Alloc>
770shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
771 typename enable_if<__shared_ptr_deleter_ctor_reqs<_Dp, _Yp, element_type>::value, __nat>::type)
772 : __ptr_(__p)
773{
774#ifndef _LIBCPP_NO_EXCEPTIONS
775 try
799 _LIBCPP_HIDE_FROM_ABI
800 element_type* get() const _NOEXCEPT
776801 {
777#endif // _LIBCPP_NO_EXCEPTIONS
778 typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk;
779 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
780 typedef __allocator_destructor<_A2> _D2;
781 _A2 __a2(__a);
782 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
783 ::new ((void*)_VSTD::addressof(*__hold2.get()))
784#ifndef _LIBCPP_CXX03_LANG
785 _CntrlBlk(__p, _VSTD::move(__d), __a);
786#else
787 _CntrlBlk(__p, __d, __a);
788#endif // not _LIBCPP_CXX03_LANG
789 __cntrl_ = _VSTD::addressof(*__hold2.release());
790 __enable_weak_this(__p, __p);
791#ifndef _LIBCPP_NO_EXCEPTIONS
802 return __ptr_;
792803 }
793 catch (...)
804
805 _LIBCPP_HIDE_FROM_ABI
806 typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT
794807 {
795 __d(__p);
796 throw;
808 return *__ptr_;
797809 }
798#endif // _LIBCPP_NO_EXCEPTIONS
799}
800810
801template<class _Tp>
802template<class _Dp, class _Alloc>
803shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a)
804 : __ptr_(nullptr)
805{
806#ifndef _LIBCPP_NO_EXCEPTIONS
807 try
811 _LIBCPP_HIDE_FROM_ABI
812 element_type* operator->() const _NOEXCEPT
808813 {
809#endif // _LIBCPP_NO_EXCEPTIONS
810 typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk;
811 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
812 typedef __allocator_destructor<_A2> _D2;
813 _A2 __a2(__a);
814 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
815 ::new ((void*)_VSTD::addressof(*__hold2.get()))
816#ifndef _LIBCPP_CXX03_LANG
817 _CntrlBlk(__p, _VSTD::move(__d), __a);
818#else
819 _CntrlBlk(__p, __d, __a);
820#endif // not _LIBCPP_CXX03_LANG
821 __cntrl_ = _VSTD::addressof(*__hold2.release());
822#ifndef _LIBCPP_NO_EXCEPTIONS
814 static_assert(!is_array<_Tp>::value,
815 "std::shared_ptr<T>::operator-> is only valid when T is not an array type.");
816 return __ptr_;
823817 }
824 catch (...)
818
819 _LIBCPP_HIDE_FROM_ABI
820 long use_count() const _NOEXCEPT
825821 {
826 __d(__p);
827 throw;
822 return __cntrl_ ? __cntrl_->use_count() : 0;
828823 }
829#endif // _LIBCPP_NO_EXCEPTIONS
830}
831824
832template<class _Tp>
833template<class _Yp>
834inline
835shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT
836 : __ptr_(__p),
837 __cntrl_(__r.__cntrl_)
838{
839 if (__cntrl_)
840 __cntrl_->__add_shared();
841}
825 _LIBCPP_HIDE_FROM_ABI
826 bool unique() const _NOEXCEPT
827 {
828 return use_count() == 1;
829 }
842830
843template<class _Tp>
844inline
845shared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT
846 : __ptr_(__r.__ptr_),
847 __cntrl_(__r.__cntrl_)
848{
849 if (__cntrl_)
850 __cntrl_->__add_shared();
851}
831 _LIBCPP_HIDE_FROM_ABI
832 explicit operator bool() const _NOEXCEPT
833 {
834 return get() != nullptr;
835 }
852836
853template<class _Tp>
854template<class _Yp>
855inline
856shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r,
857 typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type)
858 _NOEXCEPT
859 : __ptr_(__r.__ptr_),
860 __cntrl_(__r.__cntrl_)
861{
862 if (__cntrl_)
863 __cntrl_->__add_shared();
864}
837 template <class _Up>
838 _LIBCPP_HIDE_FROM_ABI
839 bool owner_before(shared_ptr<_Up> const& __p) const _NOEXCEPT
840 {
841 return __cntrl_ < __p.__cntrl_;
842 }
865843
866template<class _Tp>
867inline
868shared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT
869 : __ptr_(__r.__ptr_),
870 __cntrl_(__r.__cntrl_)
871{
872 __r.__ptr_ = nullptr;
873 __r.__cntrl_ = nullptr;
874}
844 template <class _Up>
845 _LIBCPP_HIDE_FROM_ABI
846 bool owner_before(weak_ptr<_Up> const& __p) const _NOEXCEPT
847 {
848 return __cntrl_ < __p.__cntrl_;
849 }
875850
876template<class _Tp>
877template<class _Yp>
878inline
879shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r,
880 typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type)
881 _NOEXCEPT
882 : __ptr_(__r.__ptr_),
883 __cntrl_(__r.__cntrl_)
884{
885 __r.__ptr_ = nullptr;
886 __r.__cntrl_ = nullptr;
887}
851 _LIBCPP_HIDE_FROM_ABI
852 bool __owner_equivalent(const shared_ptr& __p) const
853 {
854 return __cntrl_ == __p.__cntrl_;
855 }
888856
889#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
890template<class _Tp>
891template<class _Yp>
892shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r,
893 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
894 : __ptr_(__r.get())
895{
896 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
897 __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>());
898 __enable_weak_this(__r.get(), __r.get());
899 __r.release();
900}
857#if _LIBCPP_STD_VER > 14
858 _LIBCPP_HIDE_FROM_ABI
859 typename add_lvalue_reference<element_type>::type operator[](ptrdiff_t __i) const
860 {
861 static_assert(is_array<_Tp>::value,
862 "std::shared_ptr<T>::operator[] is only valid when T is an array type.");
863 return __ptr_[__i];
864 }
901865#endif
902866
903template<class _Tp>
904template <class _Yp, class _Dp>
905shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
906 typename enable_if
907 <
908 !is_lvalue_reference<_Dp>::value &&
909 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
910 __nat
911 >::type)
912 : __ptr_(__r.get())
913{
914#if _LIBCPP_STD_VER > 11
915 if (__ptr_ == nullptr)
916 __cntrl_ = nullptr;
917 else
918#endif
867#ifndef _LIBCPP_NO_RTTI
868 template <class _Dp>
869 _LIBCPP_HIDE_FROM_ABI
870 _Dp* __get_deleter() const _NOEXCEPT
919871 {
920 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
921 typedef __shared_ptr_pointer<typename unique_ptr<_Yp, _Dp>::pointer, _Dp, _AllocT > _CntrlBlk;
922 __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), _AllocT());
923 __enable_weak_this(__r.get(), __r.get());
872 return static_cast<_Dp*>(__cntrl_
873 ? const_cast<void *>(__cntrl_->__get_deleter(typeid(_Dp)))
874 : nullptr);
924875 }
925 __r.release();
926}
876#endif // _LIBCPP_NO_RTTI
927877
928template<class _Tp>
929template <class _Yp, class _Dp>
930shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
931 typename enable_if
932 <
933 is_lvalue_reference<_Dp>::value &&
934 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
935 __nat
936 >::type)
937 : __ptr_(__r.get())
938{
939#if _LIBCPP_STD_VER > 11
940 if (__ptr_ == nullptr)
941 __cntrl_ = nullptr;
942 else
943#endif
878 template<class _Yp, class _CntrlBlk>
879 _LIBCPP_HIDE_FROM_ABI
880 static shared_ptr<_Tp> __create_with_control_block(_Yp* __p, _CntrlBlk* __cntrl) _NOEXCEPT
944881 {
945 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
946 typedef __shared_ptr_pointer<typename unique_ptr<_Yp, _Dp>::pointer,
947 reference_wrapper<typename remove_reference<_Dp>::type>,
948 _AllocT > _CntrlBlk;
949 __cntrl_ = new _CntrlBlk(__r.get(), _VSTD::ref(__r.get_deleter()), _AllocT());
950 __enable_weak_this(__r.get(), __r.get());
882 shared_ptr<_Tp> __r;
883 __r.__ptr_ = __p;
884 __r.__cntrl_ = __cntrl;
885 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
886 return __r;
951887 }
952 __r.release();
953}
954
955template<class _Tp>
956shared_ptr<_Tp>::~shared_ptr()
957{
958 if (__cntrl_)
959 __cntrl_->__release_shared();
960}
961
962template<class _Tp>
963inline
964shared_ptr<_Tp>&
965shared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT
966{
967 shared_ptr(__r).swap(*this);
968 return *this;
969}
970
971template<class _Tp>
972template<class _Yp>
973inline
974typename enable_if
975<
976 __compatible_with<_Yp, typename shared_ptr<_Tp>::element_type>::value,
977 shared_ptr<_Tp>&
978>::type
979shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT
980{
981 shared_ptr(__r).swap(*this);
982 return *this;
983}
984888
985template<class _Tp>
986inline
987shared_ptr<_Tp>&
988shared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT
989{
990 shared_ptr(_VSTD::move(__r)).swap(*this);
991 return *this;
992}
889private:
890 template <class _Yp, bool = is_function<_Yp>::value>
891 struct __shared_ptr_default_allocator
892 {
893 typedef allocator<_Yp> type;
894 };
993895
994template<class _Tp>
995template<class _Yp>
996inline
997typename enable_if
998<
999 __compatible_with<_Yp, typename shared_ptr<_Tp>::element_type>::value,
1000 shared_ptr<_Tp>&
1001>::type
1002shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r)
1003{
1004 shared_ptr(_VSTD::move(__r)).swap(*this);
1005 return *this;
1006}
896 template <class _Yp>
897 struct __shared_ptr_default_allocator<_Yp, true>
898 {
899 typedef allocator<__shared_ptr_dummy_rebind_allocator_type> type;
900 };
1007901
1008#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
1009template<class _Tp>
1010template<class _Yp>
1011inline
1012typename enable_if
1013<
1014 !is_array<_Yp>::value &&
1015 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
1016 shared_ptr<_Tp>
1017>::type&
1018shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r)
1019{
1020 shared_ptr(_VSTD::move(__r)).swap(*this);
1021 return *this;
1022}
1023#endif
902 template <class _Yp, class _OrigPtr, class = __enable_if_t<
903 is_convertible<_OrigPtr*, const enable_shared_from_this<_Yp>*>::value
904 > >
905 _LIBCPP_HIDE_FROM_ABI
906 void __enable_weak_this(const enable_shared_from_this<_Yp>* __e, _OrigPtr* __ptr) _NOEXCEPT
907 {
908 typedef typename remove_cv<_Yp>::type _RawYp;
909 if (__e && __e->__weak_this_.expired())
910 {
911 __e->__weak_this_ = shared_ptr<_RawYp>(*this,
912 const_cast<_RawYp*>(static_cast<const _Yp*>(__ptr)));
913 }
914 }
1024915
1025template<class _Tp>
1026template <class _Yp, class _Dp>
1027inline
1028typename enable_if
1029<
1030 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer,
1031 typename shared_ptr<_Tp>::element_type*>::value,
1032 shared_ptr<_Tp>&
1033>::type
1034shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r)
1035{
1036 shared_ptr(_VSTD::move(__r)).swap(*this);
1037 return *this;
1038}
916 _LIBCPP_HIDE_FROM_ABI void __enable_weak_this(...) _NOEXCEPT { }
1039917
1040template<class _Tp>
1041inline
1042void
1043shared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT
1044{
1045 _VSTD::swap(__ptr_, __r.__ptr_);
1046 _VSTD::swap(__cntrl_, __r.__cntrl_);
1047}
918 template <class, class _Yp>
919 struct __shared_ptr_default_delete
920 : default_delete<_Yp>
921 { };
1048922
1049template<class _Tp>
1050inline
1051void
1052shared_ptr<_Tp>::reset() _NOEXCEPT
1053{
1054 shared_ptr().swap(*this);
1055}
923 template <class _Yp, class _Un, size_t _Sz>
924 struct __shared_ptr_default_delete<_Yp[_Sz], _Un>
925 : default_delete<_Yp[]>
926 { };
1056927
1057template<class _Tp>
1058template<class _Yp>
1059inline
1060typename enable_if
1061<
1062 __compatible_with<_Yp, typename shared_ptr<_Tp>::element_type>::value,
1063 void
1064>::type
1065shared_ptr<_Tp>::reset(_Yp* __p)
1066{
1067 shared_ptr(__p).swap(*this);
1068}
928 template <class _Yp, class _Un>
929 struct __shared_ptr_default_delete<_Yp[], _Un>
930 : default_delete<_Yp[]>
931 { };
1069932
1070template<class _Tp>
1071template<class _Yp, class _Dp>
1072inline
1073typename enable_if
1074<
1075 __compatible_with<_Yp, typename shared_ptr<_Tp>::element_type>::value,
1076 void
1077>::type
1078shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d)
1079{
1080 shared_ptr(__p, __d).swap(*this);
1081}
933 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr;
934 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr;
935};
1082936
937#if _LIBCPP_STD_VER > 14
1083938template<class _Tp>
1084template<class _Yp, class _Dp, class _Alloc>
1085inline
1086typename enable_if
1087<
1088 __compatible_with<_Yp, typename shared_ptr<_Tp>::element_type>::value,
1089 void
1090>::type
1091shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a)
1092{
1093 shared_ptr(__p, __d, __a).swap(*this);
1094}
939shared_ptr(weak_ptr<_Tp>) -> shared_ptr<_Tp>;
940template<class _Tp, class _Dp>
941shared_ptr(unique_ptr<_Tp, _Dp>) -> shared_ptr<_Tp>;
942#endif
1095943
1096944//
1097945// std::allocate_shared and std::make_shared
1098946//
1099template<class _Tp, class _Alloc, class ..._Args, class = _EnableIf<!is_array<_Tp>::value> >
947template<class _Tp, class _Alloc, class ..._Args, class = __enable_if_t<!is_array<_Tp>::value> >
1100948_LIBCPP_HIDE_FROM_ABI
1101949shared_ptr<_Tp> allocate_shared(const _Alloc& __a, _Args&& ...__args)
1102950{
......@@ -1108,7 +956,7 @@ shared_ptr<_Tp> allocate_shared(const _Alloc& __a, _Args&& ...__args)
1108956 return shared_ptr<_Tp>::__create_with_control_block((*__control_block).__get_elem(), _VSTD::addressof(*__control_block));
1109957}
1110958
1111template<class _Tp, class ..._Args, class = _EnableIf<!is_array<_Tp>::value> >
959template<class _Tp, class ..._Args, class = __enable_if_t<!is_array<_Tp>::value> >
1112960_LIBCPP_HIDE_FROM_ABI
1113961shared_ptr<_Tp> make_shared(_Args&& ...__args)
1114962{
......@@ -1326,7 +1174,12 @@ template<class _Tp>
13261174class _LIBCPP_SHARED_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS weak_ptr
13271175{
13281176public:
1177#if _LIBCPP_STD_VER > 14
1178 typedef remove_extent_t<_Tp> element_type;
1179#else
13291180 typedef _Tp element_type;
1181#endif
1182
13301183private:
13311184 element_type* __ptr_;
13321185 __shared_weak_count* __cntrl_;
......@@ -1335,18 +1188,18 @@ public:
13351188 _LIBCPP_INLINE_VISIBILITY
13361189 _LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT;
13371190 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(shared_ptr<_Yp> const& __r,
1338 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
1191 typename enable_if<__compatible_with<_Yp, _Tp>::value, __nat*>::type = 0)
13391192 _NOEXCEPT;
13401193 _LIBCPP_INLINE_VISIBILITY
13411194 weak_ptr(weak_ptr const& __r) _NOEXCEPT;
13421195 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp> const& __r,
1343 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
1196 typename enable_if<__compatible_with<_Yp, _Tp>::value, __nat*>::type = 0)
13441197 _NOEXCEPT;
13451198
13461199 _LIBCPP_INLINE_VISIBILITY
13471200 weak_ptr(weak_ptr&& __r) _NOEXCEPT;
13481201 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp>&& __r,
1349 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
1202 typename enable_if<__compatible_with<_Yp, _Tp>::value, __nat*>::type = 0)
13501203 _NOEXCEPT;
13511204 ~weak_ptr();
13521205
......@@ -1355,7 +1208,7 @@ public:
13551208 template<class _Yp>
13561209 typename enable_if
13571210 <
1358 is_convertible<_Yp*, element_type*>::value,
1211 __compatible_with<_Yp, _Tp>::value,
13591212 weak_ptr&
13601213 >::type
13611214 _LIBCPP_INLINE_VISIBILITY
......@@ -1366,7 +1219,7 @@ public:
13661219 template<class _Yp>
13671220 typename enable_if
13681221 <
1369 is_convertible<_Yp*, element_type*>::value,
1222 __compatible_with<_Yp, _Tp>::value,
13701223 weak_ptr&
13711224 >::type
13721225 _LIBCPP_INLINE_VISIBILITY
......@@ -1375,7 +1228,7 @@ public:
13751228 template<class _Yp>
13761229 typename enable_if
13771230 <
1378 is_convertible<_Yp*, element_type*>::value,
1231 __compatible_with<_Yp, _Tp>::value,
13791232 weak_ptr&
13801233 >::type
13811234 _LIBCPP_INLINE_VISIBILITY
......@@ -1406,7 +1259,7 @@ public:
14061259 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr;
14071260};
14081261
1409#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
1262#if _LIBCPP_STD_VER > 14
14101263template<class _Tp>
14111264weak_ptr(shared_ptr<_Tp>) -> weak_ptr<_Tp>;
14121265#endif
......@@ -1434,7 +1287,7 @@ template<class _Tp>
14341287template<class _Yp>
14351288inline
14361289weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r,
1437 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
1290 typename enable_if<__compatible_with<_Yp, _Tp>::value, __nat*>::type)
14381291 _NOEXCEPT
14391292 : __ptr_(__r.__ptr_),
14401293 __cntrl_(__r.__cntrl_)
......@@ -1447,7 +1300,7 @@ template<class _Tp>
14471300template<class _Yp>
14481301inline
14491302weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r,
1450 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
1303 typename enable_if<__compatible_with<_Yp, _Tp>::value, __nat*>::type)
14511304 _NOEXCEPT
14521305 : __ptr_(__r.__ptr_),
14531306 __cntrl_(__r.__cntrl_)
......@@ -1470,7 +1323,7 @@ template<class _Tp>
14701323template<class _Yp>
14711324inline
14721325weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r,
1473 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
1326 typename enable_if<__compatible_with<_Yp, _Tp>::value, __nat*>::type)
14741327 _NOEXCEPT
14751328 : __ptr_(__r.__ptr_),
14761329 __cntrl_(__r.__cntrl_)
......@@ -1500,7 +1353,7 @@ template<class _Yp>
15001353inline
15011354typename enable_if
15021355<
1503 is_convertible<_Yp*, _Tp*>::value,
1356 __compatible_with<_Yp, _Tp>::value,
15041357 weak_ptr<_Tp>&
15051358>::type
15061359weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT
......@@ -1523,7 +1376,7 @@ template<class _Yp>
15231376inline
15241377typename enable_if
15251378<
1526 is_convertible<_Yp*, _Tp*>::value,
1379 __compatible_with<_Yp, _Tp>::value,
15271380 weak_ptr<_Tp>&
15281381>::type
15291382weak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT
......@@ -1537,7 +1390,7 @@ template<class _Yp>
15371390inline
15381391typename enable_if
15391392<
1540 is_convertible<_Yp*, _Tp*>::value,
1393 __compatible_with<_Yp, _Tp>::value,
15411394 weak_ptr<_Tp>&
15421395>::type
15431396weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT
......@@ -1571,17 +1424,6 @@ weak_ptr<_Tp>::reset() _NOEXCEPT
15711424 weak_ptr().swap(*this);
15721425}
15731426
1574template<class _Tp>
1575template<class _Yp>
1576shared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r,
1577 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
1578 : __ptr_(__r.__ptr_),
1579 __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_)
1580{
1581 if (__cntrl_ == nullptr)
1582 __throw_bad_weak_ptr();
1583}
1584
15851427template<class _Tp>
15861428shared_ptr<_Tp>
15871429weak_ptr<_Tp>::lock() const _NOEXCEPT
......@@ -1730,7 +1572,7 @@ basic_ostream<_CharT, _Traits>&
17301572operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p);
17311573
17321574
1733#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
1575#if !defined(_LIBCPP_HAS_NO_THREADS)
17341576
17351577class _LIBCPP_TYPE_VIS __sp_mut
17361578{
......@@ -1870,10 +1712,8 @@ atomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v
18701712 return atomic_compare_exchange_weak(__p, __v, __w);
18711713}
18721714
1873#endif // !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
1715#endif // !defined(_LIBCPP_HAS_NO_THREADS)
18741716
18751717_LIBCPP_END_NAMESPACE_STD
18761718
1877_LIBCPP_POP_MACROS
1878
18791719#endif // _LIBCPP___MEMORY_SHARED_PTR_H
lib/libcxx/include/__memory/temporary_buffer.h-5
......@@ -19,9 +19,6 @@
1919#pragma GCC system_header
2020#endif
2121
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
2522_LIBCPP_BEGIN_NAMESPACE_STD
2623
2724template <class _Tp>
......@@ -84,6 +81,4 @@ struct __return_temporary_buffer
8481
8582_LIBCPP_END_NAMESPACE_STD
8683
87_LIBCPP_POP_MACROS
88
8984#endif // _LIBCPP___MEMORY_TEMPORARY_BUFFER_H
lib/libcxx/include/__memory/uninitialized_algorithms.h+216-127
......@@ -13,6 +13,7 @@
1313#include <__config>
1414#include <__memory/addressof.h>
1515#include <__memory/construct_at.h>
16#include <__memory/voidify.h>
1617#include <iterator>
1718#include <utility>
1819
......@@ -20,242 +21,330 @@
2021#pragma GCC system_header
2122#endif
2223
23_LIBCPP_PUSH_MACROS
24#include <__undef_macros>
25
2624_LIBCPP_BEGIN_NAMESPACE_STD
2725
26// This is a simplified version of C++20 `unreachable_sentinel` that doesn't use concepts and thus can be used in any
27// language mode.
28struct __unreachable_sentinel {
29 template <class _Iter>
30 _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR bool operator!=(const _Iter&, __unreachable_sentinel) _NOEXCEPT {
31 return true;
32 }
33};
34
35// uninitialized_copy
36
37template <class _ValueType, class _InputIterator, class _Sentinel1, class _ForwardIterator, class _Sentinel2>
38inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator>
39__uninitialized_copy(_InputIterator __ifirst, _Sentinel1 __ilast,
40 _ForwardIterator __ofirst, _Sentinel2 __olast) {
41 _ForwardIterator __idx = __ofirst;
42#ifndef _LIBCPP_NO_EXCEPTIONS
43 try {
44#endif
45 for (; __ifirst != __ilast && __idx != __olast; ++__ifirst, (void)++__idx)
46 ::new (_VSTD::__voidify(*__idx)) _ValueType(*__ifirst);
47#ifndef _LIBCPP_NO_EXCEPTIONS
48 } catch (...) {
49 _VSTD::__destroy(__ofirst, __idx);
50 throw;
51 }
52#endif
53
54 return pair<_InputIterator, _ForwardIterator>(_VSTD::move(__ifirst), _VSTD::move(__idx));
55}
56
2857template <class _InputIterator, class _ForwardIterator>
29_ForwardIterator
30uninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r)
31{
32 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
58_ForwardIterator uninitialized_copy(_InputIterator __ifirst, _InputIterator __ilast,
59 _ForwardIterator __ofirst) {
60 typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
61 auto __result = _VSTD::__uninitialized_copy<_ValueType>(_VSTD::move(__ifirst), _VSTD::move(__ilast),
62 _VSTD::move(__ofirst), __unreachable_sentinel());
63 return _VSTD::move(__result.second);
64}
65
66// uninitialized_copy_n
67
68template <class _ValueType, class _InputIterator, class _Size, class _ForwardIterator, class _Sentinel>
69inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator>
70__uninitialized_copy_n(_InputIterator __ifirst, _Size __n,
71 _ForwardIterator __ofirst, _Sentinel __olast) {
72 _ForwardIterator __idx = __ofirst;
3373#ifndef _LIBCPP_NO_EXCEPTIONS
34 _ForwardIterator __s = __r;
35 try
36 {
74 try {
3775#endif
38 for (; __f != __l; ++__f, (void) ++__r)
39 ::new ((void*)_VSTD::addressof(*__r)) value_type(*__f);
76 for (; __n > 0 && __idx != __olast; ++__ifirst, (void)++__idx, (void)--__n)
77 ::new (_VSTD::__voidify(*__idx)) _ValueType(*__ifirst);
4078#ifndef _LIBCPP_NO_EXCEPTIONS
41 }
42 catch (...)
43 {
44 for (; __s != __r; ++__s)
45 __s->~value_type();
46 throw;
47 }
79 } catch (...) {
80 _VSTD::__destroy(__ofirst, __idx);
81 throw;
82 }
4883#endif
49 return __r;
84
85 return pair<_InputIterator, _ForwardIterator>(_VSTD::move(__ifirst), _VSTD::move(__idx));
5086}
5187
5288template <class _InputIterator, class _Size, class _ForwardIterator>
53_ForwardIterator
54uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r)
89inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator uninitialized_copy_n(_InputIterator __ifirst, _Size __n,
90 _ForwardIterator __ofirst) {
91 typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
92 auto __result = _VSTD::__uninitialized_copy_n<_ValueType>(_VSTD::move(__ifirst), __n, _VSTD::move(__ofirst),
93 __unreachable_sentinel());
94 return _VSTD::move(__result.second);
95}
96
97// uninitialized_fill
98
99template <class _ValueType, class _ForwardIterator, class _Sentinel, class _Tp>
100inline _LIBCPP_HIDE_FROM_ABI
101_ForwardIterator __uninitialized_fill(_ForwardIterator __first, _Sentinel __last, const _Tp& __x)
55102{
56 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
103 _ForwardIterator __idx = __first;
57104#ifndef _LIBCPP_NO_EXCEPTIONS
58 _ForwardIterator __s = __r;
59105 try
60106 {
61107#endif
62 for (; __n > 0; ++__f, (void) ++__r, (void) --__n)
63 ::new ((void*)_VSTD::addressof(*__r)) value_type(*__f);
108 for (; __idx != __last; ++__idx)
109 ::new (_VSTD::__voidify(*__idx)) _ValueType(__x);
64110#ifndef _LIBCPP_NO_EXCEPTIONS
65111 }
66112 catch (...)
67113 {
68 for (; __s != __r; ++__s)
69 __s->~value_type();
114 _VSTD::__destroy(__first, __idx);
70115 throw;
71116 }
72117#endif
73 return __r;
118
119 return __idx;
74120}
75121
76122template <class _ForwardIterator, class _Tp>
77void
78uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x)
123inline _LIBCPP_HIDE_FROM_ABI
124void uninitialized_fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __x)
79125{
80 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
126 typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
127 (void)_VSTD::__uninitialized_fill<_ValueType>(__first, __last, __x);
128}
129
130// uninitialized_fill_n
131
132template <class _ValueType, class _ForwardIterator, class _Size, class _Tp>
133inline _LIBCPP_HIDE_FROM_ABI
134_ForwardIterator __uninitialized_fill_n(_ForwardIterator __first, _Size __n, const _Tp& __x)
135{
136 _ForwardIterator __idx = __first;
81137#ifndef _LIBCPP_NO_EXCEPTIONS
82 _ForwardIterator __s = __f;
83138 try
84139 {
85140#endif
86 for (; __f != __l; ++__f)
87 ::new ((void*)_VSTD::addressof(*__f)) value_type(__x);
141 for (; __n > 0; ++__idx, (void) --__n)
142 ::new (_VSTD::__voidify(*__idx)) _ValueType(__x);
88143#ifndef _LIBCPP_NO_EXCEPTIONS
89144 }
90145 catch (...)
91146 {
92 for (; __s != __f; ++__s)
93 __s->~value_type();
147 _VSTD::__destroy(__first, __idx);
94148 throw;
95149 }
96150#endif
151
152 return __idx;
97153}
98154
99155template <class _ForwardIterator, class _Size, class _Tp>
100_ForwardIterator
101uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x)
156inline _LIBCPP_HIDE_FROM_ABI
157_ForwardIterator uninitialized_fill_n(_ForwardIterator __first, _Size __n, const _Tp& __x)
102158{
103 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
159 typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
160 return _VSTD::__uninitialized_fill_n<_ValueType>(__first, __n, __x);
161}
162
163#if _LIBCPP_STD_VER > 14
164
165// uninitialized_default_construct
166
167template <class _ValueType, class _ForwardIterator, class _Sentinel>
168inline _LIBCPP_HIDE_FROM_ABI
169_ForwardIterator __uninitialized_default_construct(_ForwardIterator __first, _Sentinel __last) {
170 auto __idx = __first;
104171#ifndef _LIBCPP_NO_EXCEPTIONS
105 _ForwardIterator __s = __f;
106 try
107 {
172 try {
108173#endif
109 for (; __n > 0; ++__f, (void) --__n)
110 ::new ((void*)_VSTD::addressof(*__f)) value_type(__x);
174 for (; __idx != __last; ++__idx)
175 ::new (_VSTD::__voidify(*__idx)) _ValueType;
111176#ifndef _LIBCPP_NO_EXCEPTIONS
112 }
113 catch (...)
114 {
115 for (; __s != __f; ++__s)
116 __s->~value_type();
177 } catch (...) {
178 _VSTD::__destroy(__first, __idx);
117179 throw;
118180 }
119181#endif
120 return __f;
121}
122182
123#if _LIBCPP_STD_VER > 14
183 return __idx;
184}
124185
125186template <class _ForwardIterator>
126inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
127void destroy(_ForwardIterator __first, _ForwardIterator __last) {
128 for (; __first != __last; ++__first)
129 _VSTD::destroy_at(_VSTD::addressof(*__first));
187inline _LIBCPP_HIDE_FROM_ABI
188void uninitialized_default_construct(_ForwardIterator __first, _ForwardIterator __last) {
189 using _ValueType = typename iterator_traits<_ForwardIterator>::value_type;
190 (void)_VSTD::__uninitialized_default_construct<_ValueType>(
191 _VSTD::move(__first), _VSTD::move(__last));
130192}
131193
132template <class _ForwardIterator, class _Size>
133inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
134_ForwardIterator destroy_n(_ForwardIterator __first, _Size __n) {
135 for (; __n > 0; (void)++__first, --__n)
136 _VSTD::destroy_at(_VSTD::addressof(*__first));
137 return __first;
138}
194// uninitialized_default_construct_n
139195
140template <class _ForwardIterator>
141inline _LIBCPP_INLINE_VISIBILITY
142void uninitialized_default_construct(_ForwardIterator __first, _ForwardIterator __last) {
143 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
196template <class _ValueType, class _ForwardIterator, class _Size>
197inline _LIBCPP_HIDE_FROM_ABI
198_ForwardIterator __uninitialized_default_construct_n(_ForwardIterator __first, _Size __n) {
144199 auto __idx = __first;
145200#ifndef _LIBCPP_NO_EXCEPTIONS
146201 try {
147202#endif
148 for (; __idx != __last; ++__idx)
149 ::new ((void*)_VSTD::addressof(*__idx)) _Vt;
203 for (; __n > 0; ++__idx, (void) --__n)
204 ::new (_VSTD::__voidify(*__idx)) _ValueType;
150205#ifndef _LIBCPP_NO_EXCEPTIONS
151206 } catch (...) {
152 _VSTD::destroy(__first, __idx);
207 _VSTD::__destroy(__first, __idx);
153208 throw;
154209 }
155210#endif
211
212 return __idx;
156213}
157214
158215template <class _ForwardIterator, class _Size>
159inline _LIBCPP_INLINE_VISIBILITY
216inline _LIBCPP_HIDE_FROM_ABI
160217_ForwardIterator uninitialized_default_construct_n(_ForwardIterator __first, _Size __n) {
161 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
218 using _ValueType = typename iterator_traits<_ForwardIterator>::value_type;
219 return _VSTD::__uninitialized_default_construct_n<_ValueType>(_VSTD::move(__first), __n);
220}
221
222// uninitialized_value_construct
223
224template <class _ValueType, class _ForwardIterator, class _Sentinel>
225inline _LIBCPP_HIDE_FROM_ABI
226_ForwardIterator __uninitialized_value_construct(_ForwardIterator __first, _Sentinel __last) {
162227 auto __idx = __first;
163228#ifndef _LIBCPP_NO_EXCEPTIONS
164229 try {
165230#endif
166 for (; __n > 0; (void)++__idx, --__n)
167 ::new ((void*)_VSTD::addressof(*__idx)) _Vt;
168 return __idx;
231 for (; __idx != __last; ++__idx)
232 ::new (_VSTD::__voidify(*__idx)) _ValueType();
169233#ifndef _LIBCPP_NO_EXCEPTIONS
170234 } catch (...) {
171 _VSTD::destroy(__first, __idx);
235 _VSTD::__destroy(__first, __idx);
172236 throw;
173237 }
174238#endif
175}
176239
240 return __idx;
241}
177242
178243template <class _ForwardIterator>
179inline _LIBCPP_INLINE_VISIBILITY
244inline _LIBCPP_HIDE_FROM_ABI
180245void uninitialized_value_construct(_ForwardIterator __first, _ForwardIterator __last) {
181 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
246 using _ValueType = typename iterator_traits<_ForwardIterator>::value_type;
247 (void)_VSTD::__uninitialized_value_construct<_ValueType>(
248 _VSTD::move(__first), _VSTD::move(__last));
249}
250
251// uninitialized_value_construct_n
252
253template <class _ValueType, class _ForwardIterator, class _Size>
254inline _LIBCPP_HIDE_FROM_ABI
255_ForwardIterator __uninitialized_value_construct_n(_ForwardIterator __first, _Size __n) {
182256 auto __idx = __first;
183257#ifndef _LIBCPP_NO_EXCEPTIONS
184258 try {
185259#endif
186 for (; __idx != __last; ++__idx)
187 ::new ((void*)_VSTD::addressof(*__idx)) _Vt();
260 for (; __n > 0; ++__idx, (void) --__n)
261 ::new (_VSTD::__voidify(*__idx)) _ValueType();
188262#ifndef _LIBCPP_NO_EXCEPTIONS
189263 } catch (...) {
190 _VSTD::destroy(__first, __idx);
264 _VSTD::__destroy(__first, __idx);
191265 throw;
192266 }
193267#endif
268
269 return __idx;
194270}
195271
196272template <class _ForwardIterator, class _Size>
197inline _LIBCPP_INLINE_VISIBILITY
273inline _LIBCPP_HIDE_FROM_ABI
198274_ForwardIterator uninitialized_value_construct_n(_ForwardIterator __first, _Size __n) {
199 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
200 auto __idx = __first;
201#ifndef _LIBCPP_NO_EXCEPTIONS
202 try {
203#endif
204 for (; __n > 0; (void)++__idx, --__n)
205 ::new ((void*)_VSTD::addressof(*__idx)) _Vt();
206 return __idx;
207#ifndef _LIBCPP_NO_EXCEPTIONS
208 } catch (...) {
209 _VSTD::destroy(__first, __idx);
210 throw;
211 }
212#endif
275 using _ValueType = typename iterator_traits<_ForwardIterator>::value_type;
276 return __uninitialized_value_construct_n<_ValueType>(_VSTD::move(__first), __n);
213277}
214278
279// uninitialized_move
215280
216template <class _InputIt, class _ForwardIt>
217inline _LIBCPP_INLINE_VISIBILITY
218_ForwardIt uninitialized_move(_InputIt __first, _InputIt __last, _ForwardIt __first_res) {
219 using _Vt = typename iterator_traits<_ForwardIt>::value_type;
220 auto __idx = __first_res;
281template <class _ValueType, class _InputIterator, class _Sentinel1, class _ForwardIterator, class _Sentinel2,
282 class _IterMove>
283inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator>
284__uninitialized_move(_InputIterator __ifirst, _Sentinel1 __ilast,
285 _ForwardIterator __ofirst, _Sentinel2 __olast, _IterMove __iter_move) {
286 auto __idx = __ofirst;
221287#ifndef _LIBCPP_NO_EXCEPTIONS
222 try {
288 try {
223289#endif
224 for (; __first != __last; (void)++__idx, ++__first)
225 ::new ((void*)_VSTD::addressof(*__idx)) _Vt(_VSTD::move(*__first));
226 return __idx;
227#ifndef _LIBCPP_NO_EXCEPTIONS
228 } catch (...) {
229 _VSTD::destroy(__first_res, __idx);
230 throw;
290 for (; __ifirst != __ilast && __idx != __olast; ++__idx, (void)++__ifirst) {
291 ::new (_VSTD::__voidify(*__idx)) _ValueType(__iter_move(__ifirst));
231292 }
293#ifndef _LIBCPP_NO_EXCEPTIONS
294 } catch (...) {
295 _VSTD::__destroy(__ofirst, __idx);
296 throw;
297 }
232298#endif
299
300 return {_VSTD::move(__ifirst), _VSTD::move(__idx)};
301}
302
303template <class _InputIterator, class _ForwardIterator>
304inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator uninitialized_move(_InputIterator __ifirst, _InputIterator __ilast,
305 _ForwardIterator __ofirst) {
306 using _ValueType = typename iterator_traits<_ForwardIterator>::value_type;
307 auto __iter_move = [](auto&& __iter) -> decltype(auto) { return _VSTD::move(*__iter); };
308
309 auto __result = _VSTD::__uninitialized_move<_ValueType>(_VSTD::move(__ifirst), _VSTD::move(__ilast),
310 _VSTD::move(__ofirst), __unreachable_sentinel(), __iter_move);
311 return _VSTD::move(__result.second);
233312}
234313
235template <class _InputIt, class _Size, class _ForwardIt>
236inline _LIBCPP_INLINE_VISIBILITY
237pair<_InputIt, _ForwardIt>
238uninitialized_move_n(_InputIt __first, _Size __n, _ForwardIt __first_res) {
239 using _Vt = typename iterator_traits<_ForwardIt>::value_type;
240 auto __idx = __first_res;
314// uninitialized_move_n
315
316template <class _ValueType, class _InputIterator, class _Size, class _ForwardIterator, class _Sentinel, class _IterMove>
317inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator>
318__uninitialized_move_n(_InputIterator __ifirst, _Size __n,
319 _ForwardIterator __ofirst, _Sentinel __olast, _IterMove __iter_move) {
320 auto __idx = __ofirst;
241321#ifndef _LIBCPP_NO_EXCEPTIONS
242 try {
322 try {
243323#endif
244 for (; __n > 0; ++__idx, (void)++__first, --__n)
245 ::new ((void*)_VSTD::addressof(*__idx)) _Vt(_VSTD::move(*__first));
246 return {__first, __idx};
324 for (; __n > 0 && __idx != __olast; ++__idx, (void)++__ifirst, --__n)
325 ::new (_VSTD::__voidify(*__idx)) _ValueType(__iter_move(__ifirst));
247326#ifndef _LIBCPP_NO_EXCEPTIONS
248 } catch (...) {
249 _VSTD::destroy(__first_res, __idx);
250 throw;
251 }
327 } catch (...) {
328 _VSTD::__destroy(__ofirst, __idx);
329 throw;
330 }
252331#endif
332
333 return {_VSTD::move(__ifirst), _VSTD::move(__idx)};
334}
335
336template <class _InputIterator, class _Size, class _ForwardIterator>
337inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator>
338uninitialized_move_n(_InputIterator __ifirst, _Size __n, _ForwardIterator __ofirst) {
339 using _ValueType = typename iterator_traits<_ForwardIterator>::value_type;
340 auto __iter_move = [](auto&& __iter) -> decltype(auto) { return _VSTD::move(*__iter); };
341
342 return _VSTD::__uninitialized_move_n<_ValueType>(_VSTD::move(__ifirst), __n, _VSTD::move(__ofirst),
343 __unreachable_sentinel(), __iter_move);
253344}
254345
255346#endif // _LIBCPP_STD_VER > 14
256347
257348_LIBCPP_END_NAMESPACE_STD
258349
259_LIBCPP_POP_MACROS
260
261350#endif // _LIBCPP___MEMORY_UNINITIALIZED_ALGORITHMS_H
lib/libcxx/include/__memory/unique_ptr.h+26-31
......@@ -11,9 +11,9 @@
1111#define _LIBCPP___MEMORY_UNIQUE_PTR_H
1212
1313#include <__config>
14#include <__functional_base>
1514#include <__functional/hash.h>
1615#include <__functional/operations.h>
16#include <__functional_base>
1717#include <__memory/allocator_traits.h> // __pointer
1818#include <__memory/compressed_pair.h>
1919#include <__utility/forward.h>
......@@ -29,9 +29,6 @@
2929#pragma GCC system_header
3030#endif
3131
32_LIBCPP_PUSH_MACROS
33#include <__undef_macros>
34
3532_LIBCPP_BEGIN_NAMESPACE_STD
3633
3734template <class _Tp>
......@@ -122,7 +119,7 @@ class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr {
122119public:
123120 typedef _Tp element_type;
124121 typedef _Dp deleter_type;
125 typedef _LIBCPP_NODEBUG_TYPE typename __pointer<_Tp, deleter_type>::type pointer;
122 typedef _LIBCPP_NODEBUG typename __pointer<_Tp, deleter_type>::type pointer;
126123
127124 static_assert(!is_rvalue_reference<deleter_type>::value,
128125 "the specified deleter type cannot be an rvalue reference");
......@@ -132,38 +129,38 @@ private:
132129
133130 struct __nat { int __for_bool_; };
134131
135 typedef _LIBCPP_NODEBUG_TYPE __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE;
132 typedef _LIBCPP_NODEBUG __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE;
136133
137134 template <bool _Dummy>
138 using _LValRefType _LIBCPP_NODEBUG_TYPE =
135 using _LValRefType _LIBCPP_NODEBUG =
139136 typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type;
140137
141138 template <bool _Dummy>
142 using _GoodRValRefType _LIBCPP_NODEBUG_TYPE =
139 using _GoodRValRefType _LIBCPP_NODEBUG =
143140 typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type;
144141
145142 template <bool _Dummy>
146 using _BadRValRefType _LIBCPP_NODEBUG_TYPE =
143 using _BadRValRefType _LIBCPP_NODEBUG =
147144 typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type;
148145
149146 template <bool _Dummy, class _Deleter = typename __dependent_type<
150147 __identity<deleter_type>, _Dummy>::type>
151 using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG_TYPE =
148 using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG =
152149 typename enable_if<is_default_constructible<_Deleter>::value &&
153150 !is_pointer<_Deleter>::value>::type;
154151
155152 template <class _ArgType>
156 using _EnableIfDeleterConstructible _LIBCPP_NODEBUG_TYPE =
153 using _EnableIfDeleterConstructible _LIBCPP_NODEBUG =
157154 typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type;
158155
159156 template <class _UPtr, class _Up>
160 using _EnableIfMoveConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if<
157 using _EnableIfMoveConvertible _LIBCPP_NODEBUG = typename enable_if<
161158 is_convertible<typename _UPtr::pointer, pointer>::value &&
162159 !is_array<_Up>::value
163160 >::type;
164161
165162 template <class _UDel>
166 using _EnableIfDeleterConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if<
163 using _EnableIfDeleterConvertible _LIBCPP_NODEBUG = typename enable_if<
167164 (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) ||
168165 (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value)
169166 >::type;
......@@ -177,17 +174,17 @@ public:
177174 template <bool _Dummy = true,
178175 class = _EnableIfDeleterDefaultConstructible<_Dummy> >
179176 _LIBCPP_INLINE_VISIBILITY
180 _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(pointer(), __default_init_tag()) {}
177 _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(__value_init_tag(), __value_init_tag()) {}
181178
182179 template <bool _Dummy = true,
183180 class = _EnableIfDeleterDefaultConstructible<_Dummy> >
184181 _LIBCPP_INLINE_VISIBILITY
185 _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(pointer(), __default_init_tag()) {}
182 _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(__value_init_tag(), __value_init_tag()) {}
186183
187184 template <bool _Dummy = true,
188185 class = _EnableIfDeleterDefaultConstructible<_Dummy> >
189186 _LIBCPP_INLINE_VISIBILITY
190 explicit unique_ptr(pointer __p) _NOEXCEPT : __ptr_(__p, __default_init_tag()) {}
187 explicit unique_ptr(pointer __p) _NOEXCEPT : __ptr_(__p, __value_init_tag()) {}
191188
192189 template <bool _Dummy = true,
193190 class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> > >
......@@ -229,7 +226,7 @@ public:
229226 typename enable_if<is_convertible<_Up*, _Tp*>::value &&
230227 is_same<_Dp, default_delete<_Tp> >::value,
231228 __nat>::type = __nat()) _NOEXCEPT
232 : __ptr_(__p.release(), __default_init_tag()) {}
229 : __ptr_(__p.release(), __value_init_tag()) {}
233230#endif
234231
235232 _LIBCPP_INLINE_VISIBILITY
......@@ -350,35 +347,35 @@ private:
350347 typedef __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE;
351348
352349 template <bool _Dummy>
353 using _LValRefType _LIBCPP_NODEBUG_TYPE =
350 using _LValRefType _LIBCPP_NODEBUG =
354351 typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type;
355352
356353 template <bool _Dummy>
357 using _GoodRValRefType _LIBCPP_NODEBUG_TYPE =
354 using _GoodRValRefType _LIBCPP_NODEBUG =
358355 typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type;
359356
360357 template <bool _Dummy>
361 using _BadRValRefType _LIBCPP_NODEBUG_TYPE =
358 using _BadRValRefType _LIBCPP_NODEBUG =
362359 typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type;
363360
364361 template <bool _Dummy, class _Deleter = typename __dependent_type<
365362 __identity<deleter_type>, _Dummy>::type>
366 using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG_TYPE =
363 using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG =
367364 typename enable_if<is_default_constructible<_Deleter>::value &&
368365 !is_pointer<_Deleter>::value>::type;
369366
370367 template <class _ArgType>
371 using _EnableIfDeleterConstructible _LIBCPP_NODEBUG_TYPE =
368 using _EnableIfDeleterConstructible _LIBCPP_NODEBUG =
372369 typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type;
373370
374371 template <class _Pp>
375 using _EnableIfPointerConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if<
372 using _EnableIfPointerConvertible _LIBCPP_NODEBUG = typename enable_if<
376373 _CheckArrayPointerConversion<_Pp>::value
377374 >::type;
378375
379376 template <class _UPtr, class _Up,
380377 class _ElemT = typename _UPtr::element_type>
381 using _EnableIfMoveConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if<
378 using _EnableIfMoveConvertible _LIBCPP_NODEBUG = typename enable_if<
382379 is_array<_Up>::value &&
383380 is_same<pointer, element_type*>::value &&
384381 is_same<typename _UPtr::pointer, _ElemT*>::value &&
......@@ -386,13 +383,13 @@ private:
386383 >::type;
387384
388385 template <class _UDel>
389 using _EnableIfDeleterConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if<
386 using _EnableIfDeleterConvertible _LIBCPP_NODEBUG = typename enable_if<
390387 (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) ||
391388 (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value)
392389 >::type;
393390
394391 template <class _UDel>
395 using _EnableIfDeleterAssignable _LIBCPP_NODEBUG_TYPE = typename enable_if<
392 using _EnableIfDeleterAssignable _LIBCPP_NODEBUG = typename enable_if<
396393 is_assignable<_Dp&, _UDel&&>::value
397394 >::type;
398395
......@@ -400,19 +397,19 @@ public:
400397 template <bool _Dummy = true,
401398 class = _EnableIfDeleterDefaultConstructible<_Dummy> >
402399 _LIBCPP_INLINE_VISIBILITY
403 _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(pointer(), __default_init_tag()) {}
400 _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(__value_init_tag(), __value_init_tag()) {}
404401
405402 template <bool _Dummy = true,
406403 class = _EnableIfDeleterDefaultConstructible<_Dummy> >
407404 _LIBCPP_INLINE_VISIBILITY
408 _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(pointer(), __default_init_tag()) {}
405 _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(__value_init_tag(), __value_init_tag()) {}
409406
410407 template <class _Pp, bool _Dummy = true,
411408 class = _EnableIfDeleterDefaultConstructible<_Dummy>,
412409 class = _EnableIfPointerConvertible<_Pp> >
413410 _LIBCPP_INLINE_VISIBILITY
414411 explicit unique_ptr(_Pp __p) _NOEXCEPT
415 : __ptr_(__p, __default_init_tag()) {}
412 : __ptr_(__p, __value_init_tag()) {}
416413
417414 template <class _Pp, bool _Dummy = true,
418415 class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> >,
......@@ -768,6 +765,4 @@ struct _LIBCPP_TEMPLATE_VIS hash<__enable_hash_helper<
768765
769766_LIBCPP_END_NAMESPACE_STD
770767
771_LIBCPP_POP_MACROS
772
773768#endif // _LIBCPP___MEMORY_UNIQUE_PTR_H
lib/libcxx/include/__memory/uses_allocator.h+1-1
......@@ -52,7 +52,7 @@ struct _LIBCPP_TEMPLATE_VIS uses_allocator
5252
5353#if _LIBCPP_STD_VER > 14
5454template <class _Tp, class _Alloc>
55_LIBCPP_INLINE_VAR constexpr size_t uses_allocator_v = uses_allocator<_Tp, _Alloc>::value;
55inline constexpr size_t uses_allocator_v = uses_allocator<_Tp, _Alloc>::value;
5656#endif
5757
5858_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__memory/voidify.h created+30
......@@ -0,0 +1,30 @@
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_VOIDIFY_H
11#define _LIBCPP___MEMORY_VOIDIFY_H
12
13#include <__config>
14#include <__memory/addressof.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 <typename _Tp>
23_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 void* __voidify(_Tp& __from) {
24 // Cast away cv-qualifiers to allow modifying elements of a range through const iterators.
25 return const_cast<void*>(static_cast<const volatile void*>(_VSTD::addressof(__from)));
26}
27
28_LIBCPP_END_NAMESPACE_STD
29
30#endif // _LIBCPP___MEMORY_VOIDIFY_H
lib/libcxx/include/__mutex_base+8-9
......@@ -13,6 +13,7 @@
1313#include <__config>
1414#include <__threading_support>
1515#include <chrono>
16#include <ratio>
1617#include <system_error>
1718#include <time.h>
1819
......@@ -68,9 +69,9 @@ extern _LIBCPP_EXPORTED_FROM_ABI const adopt_lock_t adopt_lock;
6869
6970#else
7071
71/* _LIBCPP_INLINE_VAR */ constexpr defer_lock_t defer_lock = defer_lock_t();
72/* _LIBCPP_INLINE_VAR */ constexpr try_to_lock_t try_to_lock = try_to_lock_t();
73/* _LIBCPP_INLINE_VAR */ constexpr adopt_lock_t adopt_lock = adopt_lock_t();
72/* inline */ constexpr defer_lock_t defer_lock = defer_lock_t();
73/* inline */ constexpr try_to_lock_t try_to_lock = try_to_lock_t();
74/* inline */ constexpr adopt_lock_t adopt_lock = adopt_lock_t();
7475
7576#endif
7677
......@@ -96,8 +97,8 @@ public:
9697 ~lock_guard() _LIBCPP_THREAD_SAFETY_ANNOTATION(release_capability()) {__m_.unlock();}
9798
9899private:
99 lock_guard(lock_guard const&) _LIBCPP_EQUAL_DELETE;
100 lock_guard& operator=(lock_guard const&) _LIBCPP_EQUAL_DELETE;
100 lock_guard(lock_guard const&) = delete;
101 lock_guard& operator=(lock_guard const&) = delete;
101102};
102103
103104template <class _Mutex>
......@@ -140,11 +141,9 @@ public:
140141 __m_->unlock();
141142 }
142143
143private:
144 unique_lock(unique_lock const&); // = delete;
145 unique_lock& operator=(unique_lock const&); // = delete;
144 unique_lock(unique_lock const&) = delete;
145 unique_lock& operator=(unique_lock const&) = delete;
146146
147public:
148147 _LIBCPP_INLINE_VISIBILITY
149148 unique_lock(unique_lock&& __u) _NOEXCEPT
150149 : __m_(__u.__m_), __owns_(__u.__owns_)
lib/libcxx/include/__node_handle+48-4
......@@ -10,6 +10,54 @@
1010#ifndef _LIBCPP___NODE_HANDLE
1111#define _LIBCPP___NODE_HANDLE
1212
13/*
14
15template<unspecified>
16class node-handle {
17public:
18 using value_type = see below; // not present for map containers
19 using key_type = see below; // not present for set containers
20 using mapped_type = see below; // not present for set containers
21 using allocator_type = see below;
22
23private:
24 using container_node_type = unspecified; // exposition only
25 using ator_traits = allocator_traits<allocator_type>; // exposition only
26
27 typename ator_traits::template
28 rebind_traits<container_node_type>::pointer ptr_; // exposition only
29 optional<allocator_type> alloc_; // exposition only
30
31public:
32 // [container.node.cons], constructors, copy, and assignment
33 constexpr node-handle() noexcept : ptr_(), alloc_() {}
34 node-handle(node-handle&&) noexcept;
35 node-handle& operator=(node-handle&&);
36
37 // [container.node.dtor], destructor
38 ~node-handle();
39
40 // [container.node.observers], observers
41 value_type& value() const; // not present for map containers
42 key_type& key() const; // not present for set containers
43 mapped_type& mapped() const; // not present for set containers
44
45 allocator_type get_allocator() const;
46 explicit operator bool() const noexcept;
47 [[nodiscard]] bool empty() const noexcept; // nodiscard since C++20
48
49 // [container.node.modifiers], modifiers
50 void swap(node-handle&)
51 noexcept(ator_traits::propagate_on_container_swap::value ||
52 ator_traits::is_always_equal::value);
53
54 friend void swap(node-handle& x, node-handle& y) noexcept(noexcept(x.swap(y))) {
55 x.swap(y);
56 }
57};
58
59*/
60
1361#include <__config>
1462#include <__debug>
1563#include <memory>
......@@ -19,9 +67,6 @@
1967#pragma GCC system_header
2068#endif
2169
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
2570_LIBCPP_BEGIN_NAMESPACE_STD
2671
2772#if _LIBCPP_STD_VER > 14
......@@ -204,6 +249,5 @@ struct _LIBCPP_TEMPLATE_VIS __insert_return_type
204249#endif // _LIBCPP_STD_VER > 14
205250
206251_LIBCPP_END_NAMESPACE_STD
207_LIBCPP_POP_MACROS
208252
209253#endif // _LIBCPP___NODE_HANDLE
lib/libcxx/include/__nullptr+2-2
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- __nullptr --------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -54,7 +54,7 @@ _LIBCPP_END_NAMESPACE_STD
5454namespace std
5555{
5656 typedef decltype(nullptr) nullptr_t;
57}
57} // namespace std
5858
5959#endif // _LIBCPP_HAS_NO_NULLPTR
6060
lib/libcxx/include/__numeric/accumulate.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___NUMERIC_ACCUMULATE_H
11#define _LIBCPP___NUMERIC_ACCUMULATE_H
12
13#include <__config>
14#include <__utility/move.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 _InputIterator, class _Tp>
23_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
24_Tp
25accumulate(_InputIterator __first, _InputIterator __last, _Tp __init)
26{
27 for (; __first != __last; ++__first)
28#if _LIBCPP_STD_VER > 17
29 __init = _VSTD::move(__init) + *__first;
30#else
31 __init = __init + *__first;
32#endif
33 return __init;
34}
35
36template <class _InputIterator, class _Tp, class _BinaryOperation>
37_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
38_Tp
39accumulate(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOperation __binary_op)
40{
41 for (; __first != __last; ++__first)
42#if _LIBCPP_STD_VER > 17
43 __init = __binary_op(_VSTD::move(__init), *__first);
44#else
45 __init = __binary_op(__init, *__first);
46#endif
47 return __init;
48}
49
50_LIBCPP_END_NAMESPACE_STD
51
52#endif // _LIBCPP___NUMERIC_ACCUMULATE_H
lib/libcxx/include/__numeric/adjacent_difference.h created+72
......@@ -0,0 +1,72 @@
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___NUMERIC_ADJACENT_DIFFERENCE_H
11#define _LIBCPP___NUMERIC_ADJACENT_DIFFERENCE_H
12
13#include <__config>
14#include <__iterator/iterator_traits.h>
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
23template <class _InputIterator, class _OutputIterator>
24_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
25_OutputIterator
26adjacent_difference(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
27{
28 if (__first != __last)
29 {
30 typename iterator_traits<_InputIterator>::value_type __acc(*__first);
31 *__result = __acc;
32 for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result)
33 {
34 typename iterator_traits<_InputIterator>::value_type __val(*__first);
35#if _LIBCPP_STD_VER > 17
36 *__result = __val - _VSTD::move(__acc);
37#else
38 *__result = __val - __acc;
39#endif
40 __acc = _VSTD::move(__val);
41 }
42 }
43 return __result;
44}
45
46template <class _InputIterator, class _OutputIterator, class _BinaryOperation>
47_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
48_OutputIterator
49adjacent_difference(_InputIterator __first, _InputIterator __last, _OutputIterator __result,
50 _BinaryOperation __binary_op)
51{
52 if (__first != __last)
53 {
54 typename iterator_traits<_InputIterator>::value_type __acc(*__first);
55 *__result = __acc;
56 for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result)
57 {
58 typename iterator_traits<_InputIterator>::value_type __val(*__first);
59#if _LIBCPP_STD_VER > 17
60 *__result = __binary_op(__val, _VSTD::move(__acc));
61#else
62 *__result = __binary_op(__val, __acc);
63#endif
64 __acc = _VSTD::move(__val);
65 }
66 }
67 return __result;
68}
69
70_LIBCPP_END_NAMESPACE_STD
71
72#endif // _LIBCPP___NUMERIC_ADJACENT_DIFFERENCE_H
lib/libcxx/include/__numeric/exclusive_scan.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___NUMERIC_EXCLUSIVE_SCAN_H
11#define _LIBCPP___NUMERIC_EXCLUSIVE_SCAN_H
12
13#include <__config>
14#include <__functional/operations.h>
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 > 14
24
25template <class _InputIterator, class _OutputIterator, class _Tp, class _BinaryOp>
26_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator
27exclusive_scan(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Tp __init, _BinaryOp __b) {
28 if (__first != __last) {
29 _Tp __tmp(__b(__init, *__first));
30 while (true) {
31 *__result = _VSTD::move(__init);
32 ++__result;
33 ++__first;
34 if (__first == __last)
35 break;
36 __init = _VSTD::move(__tmp);
37 __tmp = __b(__init, *__first);
38 }
39 }
40 return __result;
41}
42
43template <class _InputIterator, class _OutputIterator, class _Tp>
44_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator
45exclusive_scan(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Tp __init) {
46 return _VSTD::exclusive_scan(__first, __last, __result, __init, _VSTD::plus<>());
47}
48
49#endif // _LIBCPP_STD_VER > 14
50
51_LIBCPP_END_NAMESPACE_STD
52
53#endif // _LIBCPP___NUMERIC_EXCLUSIVE_SCAN_H
lib/libcxx/include/__numeric/gcd_lcm.h created+96
......@@ -0,0 +1,96 @@
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___NUMERIC_GCD_LCM_H
11#define _LIBCPP___NUMERIC_GCD_LCM_H
12
13#include <__config>
14#include <__debug>
15#include <limits>
16#include <type_traits>
17
18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19# pragma GCC system_header
20#endif
21
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
25_LIBCPP_BEGIN_NAMESPACE_STD
26
27#if _LIBCPP_STD_VER > 14
28
29template <typename _Result, typename _Source, bool _IsSigned = is_signed<_Source>::value> struct __ct_abs;
30
31template <typename _Result, typename _Source>
32struct __ct_abs<_Result, _Source, true> {
33 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
34 _Result operator()(_Source __t) const noexcept
35 {
36 if (__t >= 0) return __t;
37 if (__t == numeric_limits<_Source>::min()) return -static_cast<_Result>(__t);
38 return -__t;
39 }
40};
41
42template <typename _Result, typename _Source>
43struct __ct_abs<_Result, _Source, false> {
44 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
45 _Result operator()(_Source __t) const noexcept { return __t; }
46};
47
48
49template<class _Tp>
50_LIBCPP_CONSTEXPR _LIBCPP_HIDDEN
51_Tp __gcd(_Tp __m, _Tp __n)
52{
53 static_assert((!is_signed<_Tp>::value), "");
54 return __n == 0 ? __m : _VSTD::__gcd<_Tp>(__n, __m % __n);
55}
56
57template<class _Tp, class _Up>
58_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
59common_type_t<_Tp,_Up>
60gcd(_Tp __m, _Up __n)
61{
62 static_assert((is_integral<_Tp>::value && is_integral<_Up>::value), "Arguments to gcd must be integer types");
63 static_assert((!is_same<typename remove_cv<_Tp>::type, bool>::value), "First argument to gcd cannot be bool" );
64 static_assert((!is_same<typename remove_cv<_Up>::type, bool>::value), "Second argument to gcd cannot be bool" );
65 using _Rp = common_type_t<_Tp,_Up>;
66 using _Wp = make_unsigned_t<_Rp>;
67 return static_cast<_Rp>(_VSTD::__gcd(
68 static_cast<_Wp>(__ct_abs<_Rp, _Tp>()(__m)),
69 static_cast<_Wp>(__ct_abs<_Rp, _Up>()(__n))));
70}
71
72template<class _Tp, class _Up>
73_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
74common_type_t<_Tp,_Up>
75lcm(_Tp __m, _Up __n)
76{
77 static_assert((is_integral<_Tp>::value && is_integral<_Up>::value), "Arguments to lcm must be integer types");
78 static_assert((!is_same<typename remove_cv<_Tp>::type, bool>::value), "First argument to lcm cannot be bool" );
79 static_assert((!is_same<typename remove_cv<_Up>::type, bool>::value), "Second argument to lcm cannot be bool" );
80 if (__m == 0 || __n == 0)
81 return 0;
82
83 using _Rp = common_type_t<_Tp,_Up>;
84 _Rp __val1 = __ct_abs<_Rp, _Tp>()(__m) / _VSTD::gcd(__m, __n);
85 _Rp __val2 = __ct_abs<_Rp, _Up>()(__n);
86 _LIBCPP_ASSERT((numeric_limits<_Rp>::max() / __val1 > __val2), "Overflow in lcm");
87 return __val1 * __val2;
88}
89
90#endif // _LIBCPP_STD_VER
91
92_LIBCPP_END_NAMESPACE_STD
93
94_LIBCPP_POP_MACROS
95
96#endif // _LIBCPP___NUMERIC_GCD_LCM_H
lib/libcxx/include/__numeric/inclusive_scan.h created+60
......@@ -0,0 +1,60 @@
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___NUMERIC_INCLUSIVE_SCAN_H
11#define _LIBCPP___NUMERIC_INCLUSIVE_SCAN_H
12
13#include <__config>
14#include <__functional/operations.h>
15#include <__iterator/iterator_traits.h>
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 > 14
25
26template <class _InputIterator, class _OutputIterator, class _Tp, class _BinaryOp>
27_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator
28inclusive_scan(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryOp __b, _Tp __init) {
29 for (; __first != __last; ++__first, (void)++__result) {
30 __init = __b(__init, *__first);
31 *__result = __init;
32 }
33 return __result;
34}
35
36template <class _InputIterator, class _OutputIterator, class _BinaryOp>
37_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator
38inclusive_scan(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryOp __b) {
39 if (__first != __last) {
40 typename iterator_traits<_InputIterator>::value_type __init = *__first;
41 *__result++ = __init;
42 if (++__first != __last)
43 return _VSTD::inclusive_scan(__first, __last, __result, __b, __init);
44 }
45
46 return __result;
47}
48
49template <class _InputIterator, class _OutputIterator>
50_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator inclusive_scan(_InputIterator __first,
51 _InputIterator __last,
52 _OutputIterator __result) {
53 return _VSTD::inclusive_scan(__first, __last, __result, _VSTD::plus<>());
54}
55
56#endif // _LIBCPP_STD_VER > 14
57
58_LIBCPP_END_NAMESPACE_STD
59
60#endif // _LIBCPP___NUMERIC_INCLUSIVE_SCAN_H
lib/libcxx/include/__numeric/inner_product.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___NUMERIC_INNER_PRODUCT_H
11#define _LIBCPP___NUMERIC_INNER_PRODUCT_H
12
13#include <__config>
14#include <__utility/move.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 _InputIterator1, class _InputIterator2, class _Tp>
23_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
24_Tp
25inner_product(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _Tp __init)
26{
27 for (; __first1 != __last1; ++__first1, (void) ++__first2)
28#if _LIBCPP_STD_VER > 17
29 __init = _VSTD::move(__init) + *__first1 * *__first2;
30#else
31 __init = __init + *__first1 * *__first2;
32#endif
33 return __init;
34}
35
36template <class _InputIterator1, class _InputIterator2, class _Tp, class _BinaryOperation1, class _BinaryOperation2>
37_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
38_Tp
39inner_product(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2,
40 _Tp __init, _BinaryOperation1 __binary_op1, _BinaryOperation2 __binary_op2)
41{
42 for (; __first1 != __last1; ++__first1, (void) ++__first2)
43#if _LIBCPP_STD_VER > 17
44 __init = __binary_op1(_VSTD::move(__init), __binary_op2(*__first1, *__first2));
45#else
46 __init = __binary_op1(__init, __binary_op2(*__first1, *__first2));
47#endif
48 return __init;
49}
50
51_LIBCPP_END_NAMESPACE_STD
52
53#endif // _LIBCPP___NUMERIC_INNER_PRODUCT_H
lib/libcxx/include/__numeric/iota.h created+32
......@@ -0,0 +1,32 @@
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___NUMERIC_IOTA_H
11#define _LIBCPP___NUMERIC_IOTA_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
21template <class _ForwardIterator, class _Tp>
22_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
23void
24iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value_)
25{
26 for (; __first != __last; ++__first, (void) ++__value_)
27 *__first = __value_;
28}
29
30_LIBCPP_END_NAMESPACE_STD
31
32#endif // _LIBCPP___NUMERIC_IOTA_H
lib/libcxx/include/__numeric/midpoint.h created+85
......@@ -0,0 +1,85 @@
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___NUMERIC_MIDPOINT_H
11#define _LIBCPP___NUMERIC_MIDPOINT_H
12
13#include <__config>
14#include <limits>
15#include <type_traits>
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
27template <class _Tp>
28_LIBCPP_INLINE_VISIBILITY constexpr
29enable_if_t<is_integral_v<_Tp> && !is_same_v<bool, _Tp> && !is_null_pointer_v<_Tp>, _Tp>
30midpoint(_Tp __a, _Tp __b) noexcept
31_LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
32{
33 using _Up = make_unsigned_t<_Tp>;
34 constexpr _Up __bitshift = numeric_limits<_Up>::digits - 1;
35
36 _Up __diff = _Up(__b) - _Up(__a);
37 _Up __sign_bit = __b < __a;
38
39 _Up __half_diff = (__diff / 2) + (__sign_bit << __bitshift) + (__sign_bit & __diff);
40
41 return __a + __half_diff;
42}
43
44
45template <class _TPtr>
46_LIBCPP_INLINE_VISIBILITY constexpr
47enable_if_t<is_pointer_v<_TPtr>
48 && is_object_v<remove_pointer_t<_TPtr>>
49 && ! is_void_v<remove_pointer_t<_TPtr>>
50 && (sizeof(remove_pointer_t<_TPtr>) > 0), _TPtr>
51midpoint(_TPtr __a, _TPtr __b) noexcept
52{
53 return __a + _VSTD::midpoint(ptrdiff_t(0), __b - __a);
54}
55
56
57template <typename _Tp>
58constexpr int __sign(_Tp __val) {
59 return (_Tp(0) < __val) - (__val < _Tp(0));
60}
61
62template <typename _Fp>
63constexpr _Fp __fp_abs(_Fp __f) { return __f >= 0 ? __f : -__f; }
64
65template <class _Fp>
66_LIBCPP_INLINE_VISIBILITY constexpr
67enable_if_t<is_floating_point_v<_Fp>, _Fp>
68midpoint(_Fp __a, _Fp __b) noexcept
69{
70 constexpr _Fp __lo = numeric_limits<_Fp>::min()*2;
71 constexpr _Fp __hi = numeric_limits<_Fp>::max()/2;
72 return __fp_abs(__a) <= __hi && __fp_abs(__b) <= __hi ? // typical case: overflow is impossible
73 (__a + __b)/2 : // always correctly rounded
74 __fp_abs(__a) < __lo ? __a + __b/2 : // not safe to halve a
75 __fp_abs(__b) < __lo ? __a/2 + __b : // not safe to halve b
76 __a/2 + __b/2; // otherwise correctly rounded
77}
78
79#endif // _LIBCPP_STD_VER > 17
80
81_LIBCPP_END_NAMESPACE_STD
82
83_LIBCPP_POP_MACROS
84
85#endif // _LIBCPP___NUMERIC_MIDPOINT_H
lib/libcxx/include/__numeric/partial_sum.h created+70
......@@ -0,0 +1,70 @@
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___NUMERIC_PARTIAL_SUM_H
11#define _LIBCPP___NUMERIC_PARTIAL_SUM_H
12
13#include <__config>
14#include <__iterator/iterator_traits.h>
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
23template <class _InputIterator, class _OutputIterator>
24_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
25_OutputIterator
26partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
27{
28 if (__first != __last)
29 {
30 typename iterator_traits<_InputIterator>::value_type __t(*__first);
31 *__result = __t;
32 for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result)
33 {
34#if _LIBCPP_STD_VER > 17
35 __t = _VSTD::move(__t) + *__first;
36#else
37 __t = __t + *__first;
38#endif
39 *__result = __t;
40 }
41 }
42 return __result;
43}
44
45template <class _InputIterator, class _OutputIterator, class _BinaryOperation>
46_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
47_OutputIterator
48partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result,
49 _BinaryOperation __binary_op)
50{
51 if (__first != __last)
52 {
53 typename iterator_traits<_InputIterator>::value_type __t(*__first);
54 *__result = __t;
55 for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result)
56 {
57#if _LIBCPP_STD_VER > 17
58 __t = __binary_op(_VSTD::move(__t), *__first);
59#else
60 __t = __binary_op(__t, *__first);
61#endif
62 *__result = __t;
63 }
64 }
65 return __result;
66}
67
68_LIBCPP_END_NAMESPACE_STD
69
70#endif // _LIBCPP___NUMERIC_PARTIAL_SUM_H
lib/libcxx/include/__numeric/reduce.h created+47
......@@ -0,0 +1,47 @@
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___NUMERIC_REDUCE_H
11#define _LIBCPP___NUMERIC_REDUCE_H
12
13#include <__config>
14#include <__functional/operations.h>
15#include <__iterator/iterator_traits.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
24template <class _InputIterator, class _Tp, class _BinaryOp>
25_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _Tp reduce(_InputIterator __first, _InputIterator __last,
26 _Tp __init, _BinaryOp __b) {
27 for (; __first != __last; ++__first)
28 __init = __b(__init, *__first);
29 return __init;
30}
31
32template <class _InputIterator, class _Tp>
33_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _Tp reduce(_InputIterator __first, _InputIterator __last,
34 _Tp __init) {
35 return _VSTD::reduce(__first, __last, __init, _VSTD::plus<>());
36}
37
38template <class _InputIterator>
39_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 typename iterator_traits<_InputIterator>::value_type
40reduce(_InputIterator __first, _InputIterator __last) {
41 return _VSTD::reduce(__first, __last, typename iterator_traits<_InputIterator>::value_type{});
42}
43#endif
44
45_LIBCPP_END_NAMESPACE_STD
46
47#endif // _LIBCPP___NUMERIC_REDUCE_H
lib/libcxx/include/__numeric/transform_exclusive_scan.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___NUMERIC_TRANSFORM_EXCLUSIVE_SCAN_H
11#define _LIBCPP___NUMERIC_TRANSFORM_EXCLUSIVE_SCAN_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 > 14
22
23template <class _InputIterator, class _OutputIterator, class _Tp,
24 class _BinaryOp, class _UnaryOp>
25_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
26_OutputIterator
27transform_exclusive_scan(_InputIterator __first, _InputIterator __last,
28 _OutputIterator __result, _Tp __init,
29 _BinaryOp __b, _UnaryOp __u)
30{
31 if (__first != __last)
32 {
33 _Tp __saved = __init;
34 do
35 {
36 __init = __b(__init, __u(*__first));
37 *__result = __saved;
38 __saved = __init;
39 ++__result;
40 } while (++__first != __last);
41 }
42 return __result;
43}
44
45#endif // _LIBCPP_STD_VER > 14
46
47_LIBCPP_END_NAMESPACE_STD
48
49#endif // _LIBCPP___NUMERIC_TRANSFORM_EXCLUSIVE_SCAN_H
lib/libcxx/include/__numeric/transform_inclusive_scan.h created+58
......@@ -0,0 +1,58 @@
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___NUMERIC_TRANSFORM_INCLUSIVE_SCAN_H
11#define _LIBCPP___NUMERIC_TRANSFORM_INCLUSIVE_SCAN_H
12
13#include <__config>
14#include <__iterator/iterator_traits.h>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
20_LIBCPP_BEGIN_NAMESPACE_STD
21
22#if _LIBCPP_STD_VER > 14
23
24template <class _InputIterator, class _OutputIterator, class _Tp, class _BinaryOp, class _UnaryOp>
25_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
26_OutputIterator
27transform_inclusive_scan(_InputIterator __first, _InputIterator __last,
28 _OutputIterator __result, _BinaryOp __b, _UnaryOp __u, _Tp __init)
29{
30 for (; __first != __last; ++__first, (void) ++__result) {
31 __init = __b(__init, __u(*__first));
32 *__result = __init;
33 }
34
35 return __result;
36}
37
38template <class _InputIterator, class _OutputIterator, class _BinaryOp, class _UnaryOp>
39_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
40_OutputIterator
41transform_inclusive_scan(_InputIterator __first, _InputIterator __last,
42 _OutputIterator __result, _BinaryOp __b, _UnaryOp __u)
43{
44 if (__first != __last) {
45 typename iterator_traits<_InputIterator>::value_type __init = __u(*__first);
46 *__result++ = __init;
47 if (++__first != __last)
48 return _VSTD::transform_inclusive_scan(__first, __last, __result, __b, __u, __init);
49 }
50
51 return __result;
52}
53
54#endif // _LIBCPP_STD_VER > 14
55
56_LIBCPP_END_NAMESPACE_STD
57
58#endif // _LIBCPP___NUMERIC_TRANSFORM_INCLUSIVE_SCAN_H
lib/libcxx/include/__numeric/transform_reduce.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___NUMERIC_TRANSFORM_REDUCE_H
11#define _LIBCPP___NUMERIC_TRANSFORM_REDUCE_H
12
13#include <__config>
14#include <__functional/operations.h>
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 > 14
24template <class _InputIterator, class _Tp, class _BinaryOp, class _UnaryOp>
25_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _Tp transform_reduce(_InputIterator __first,
26 _InputIterator __last, _Tp __init,
27 _BinaryOp __b, _UnaryOp __u) {
28 for (; __first != __last; ++__first)
29 __init = __b(__init, __u(*__first));
30 return __init;
31}
32
33template <class _InputIterator1, class _InputIterator2, class _Tp, class _BinaryOp1, class _BinaryOp2>
34_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _Tp transform_reduce(_InputIterator1 __first1,
35 _InputIterator1 __last1,
36 _InputIterator2 __first2, _Tp __init,
37 _BinaryOp1 __b1, _BinaryOp2 __b2) {
38 for (; __first1 != __last1; ++__first1, (void)++__first2)
39 __init = __b1(__init, __b2(*__first1, *__first2));
40 return __init;
41}
42
43template <class _InputIterator1, class _InputIterator2, class _Tp>
44_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _Tp transform_reduce(_InputIterator1 __first1,
45 _InputIterator1 __last1,
46 _InputIterator2 __first2, _Tp __init) {
47 return _VSTD::transform_reduce(__first1, __last1, __first2, _VSTD::move(__init), _VSTD::plus<>(),
48 _VSTD::multiplies<>());
49}
50#endif
51
52_LIBCPP_END_NAMESPACE_STD
53
54#endif // _LIBCPP___NUMERIC_TRANSFORM_REDUCE_H
lib/libcxx/include/__random/bernoulli_distribution.h created+143
......@@ -0,0 +1,143 @@
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_BERNOULLI_DISTRIBUTION_H
10#define _LIBCPP___RANDOM_BERNOULLI_DISTRIBUTION_H
11
12#include <__config>
13#include <__random/uniform_real_distribution.h>
14#include <iosfwd>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
18#endif
19
20_LIBCPP_PUSH_MACROS
21#include <__undef_macros>
22
23_LIBCPP_BEGIN_NAMESPACE_STD
24
25class _LIBCPP_TEMPLATE_VIS bernoulli_distribution
26{
27public:
28 // types
29 typedef bool result_type;
30
31 class _LIBCPP_TEMPLATE_VIS param_type
32 {
33 double __p_;
34 public:
35 typedef bernoulli_distribution distribution_type;
36
37 _LIBCPP_INLINE_VISIBILITY
38 explicit param_type(double __p = 0.5) : __p_(__p) {}
39
40 _LIBCPP_INLINE_VISIBILITY
41 double p() const {return __p_;}
42
43 friend _LIBCPP_INLINE_VISIBILITY
44 bool operator==(const param_type& __x, const param_type& __y)
45 {return __x.__p_ == __y.__p_;}
46 friend _LIBCPP_INLINE_VISIBILITY
47 bool operator!=(const param_type& __x, const param_type& __y)
48 {return !(__x == __y);}
49 };
50
51private:
52 param_type __p_;
53
54public:
55 // constructors and reset functions
56#ifndef _LIBCPP_CXX03_LANG
57 _LIBCPP_INLINE_VISIBILITY
58 bernoulli_distribution() : bernoulli_distribution(0.5) {}
59 _LIBCPP_INLINE_VISIBILITY
60 explicit bernoulli_distribution(double __p) : __p_(param_type(__p)) {}
61#else
62 _LIBCPP_INLINE_VISIBILITY
63 explicit bernoulli_distribution(double __p = 0.5) : __p_(param_type(__p)) {}
64#endif
65 _LIBCPP_INLINE_VISIBILITY
66 explicit bernoulli_distribution(const param_type& __p) : __p_(__p) {}
67 _LIBCPP_INLINE_VISIBILITY
68 void reset() {}
69
70 // generating functions
71 template<class _URNG>
72 _LIBCPP_INLINE_VISIBILITY
73 result_type operator()(_URNG& __g)
74 {return (*this)(__g, __p_);}
75 template<class _URNG> _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g, const param_type& __p);
76
77 // property functions
78 _LIBCPP_INLINE_VISIBILITY
79 double p() const {return __p_.p();}
80
81 _LIBCPP_INLINE_VISIBILITY
82 param_type param() const {return __p_;}
83 _LIBCPP_INLINE_VISIBILITY
84 void param(const param_type& __p) {__p_ = __p;}
85
86 _LIBCPP_INLINE_VISIBILITY
87 result_type min() const {return false;}
88 _LIBCPP_INLINE_VISIBILITY
89 result_type max() const {return true;}
90
91 friend _LIBCPP_INLINE_VISIBILITY
92 bool operator==(const bernoulli_distribution& __x,
93 const bernoulli_distribution& __y)
94 {return __x.__p_ == __y.__p_;}
95 friend _LIBCPP_INLINE_VISIBILITY
96 bool operator!=(const bernoulli_distribution& __x,
97 const bernoulli_distribution& __y)
98 {return !(__x == __y);}
99};
100
101template<class _URNG>
102inline
103bernoulli_distribution::result_type
104bernoulli_distribution::operator()(_URNG& __g, const param_type& __p)
105{
106 uniform_real_distribution<double> __gen;
107 return __gen(__g) < __p.p();
108}
109
110template <class _CharT, class _Traits>
111basic_ostream<_CharT, _Traits>&
112operator<<(basic_ostream<_CharT, _Traits>& __os, const bernoulli_distribution& __x)
113{
114 __save_flags<_CharT, _Traits> __lx(__os);
115 typedef basic_ostream<_CharT, _Traits> _OStream;
116 __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
117 _OStream::scientific);
118 _CharT __sp = __os.widen(' ');
119 __os.fill(__sp);
120 return __os << __x.p();
121}
122
123template <class _CharT, class _Traits>
124basic_istream<_CharT, _Traits>&
125operator>>(basic_istream<_CharT, _Traits>& __is, bernoulli_distribution& __x)
126{
127 typedef bernoulli_distribution _Eng;
128 typedef typename _Eng::param_type param_type;
129 __save_flags<_CharT, _Traits> __lx(__is);
130 typedef basic_istream<_CharT, _Traits> _Istream;
131 __is.flags(_Istream::dec | _Istream::skipws);
132 double __p;
133 __is >> __p;
134 if (!__is.fail())
135 __x.param(param_type(__p));
136 return __is;
137}
138
139_LIBCPP_END_NAMESPACE_STD
140
141_LIBCPP_POP_MACROS
142
143#endif // _LIBCPP___RANDOM_BERNOULLI_DISTRIBUTION_H
lib/libcxx/include/__random/binomial_distribution.h created+225
......@@ -0,0 +1,225 @@
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_BINOMIAL_DISTRIBUTION_H
10#define _LIBCPP___RANDOM_BINOMIAL_DISTRIBUTION_H
11
12#include <__config>
13#include <__random/uniform_real_distribution.h>
14#include <cmath>
15#include <iosfwd>
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
26template<class _IntType = int>
27class _LIBCPP_TEMPLATE_VIS binomial_distribution
28{
29public:
30 // types
31 typedef _IntType result_type;
32
33 class _LIBCPP_TEMPLATE_VIS param_type
34 {
35 result_type __t_;
36 double __p_;
37 double __pr_;
38 double __odds_ratio_;
39 result_type __r0_;
40 public:
41 typedef binomial_distribution distribution_type;
42
43 explicit param_type(result_type __t = 1, double __p = 0.5);
44
45 _LIBCPP_INLINE_VISIBILITY
46 result_type t() const {return __t_;}
47 _LIBCPP_INLINE_VISIBILITY
48 double p() const {return __p_;}
49
50 friend _LIBCPP_INLINE_VISIBILITY
51 bool operator==(const param_type& __x, const param_type& __y)
52 {return __x.__t_ == __y.__t_ && __x.__p_ == __y.__p_;}
53 friend _LIBCPP_INLINE_VISIBILITY
54 bool operator!=(const param_type& __x, const param_type& __y)
55 {return !(__x == __y);}
56
57 friend class binomial_distribution;
58 };
59
60private:
61 param_type __p_;
62
63public:
64 // constructors and reset functions
65#ifndef _LIBCPP_CXX03_LANG
66 _LIBCPP_INLINE_VISIBILITY
67 binomial_distribution() : binomial_distribution(1) {}
68 _LIBCPP_INLINE_VISIBILITY
69 explicit binomial_distribution(result_type __t, double __p = 0.5)
70 : __p_(param_type(__t, __p)) {}
71#else
72 _LIBCPP_INLINE_VISIBILITY
73 explicit binomial_distribution(result_type __t = 1, double __p = 0.5)
74 : __p_(param_type(__t, __p)) {}
75#endif
76 _LIBCPP_INLINE_VISIBILITY
77 explicit binomial_distribution(const param_type& __p) : __p_(__p) {}
78 _LIBCPP_INLINE_VISIBILITY
79 void reset() {}
80
81 // generating functions
82 template<class _URNG>
83 _LIBCPP_INLINE_VISIBILITY
84 result_type operator()(_URNG& __g)
85 {return (*this)(__g, __p_);}
86 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
87
88 // property functions
89 _LIBCPP_INLINE_VISIBILITY
90 result_type t() const {return __p_.t();}
91 _LIBCPP_INLINE_VISIBILITY
92 double p() const {return __p_.p();}
93
94 _LIBCPP_INLINE_VISIBILITY
95 param_type param() const {return __p_;}
96 _LIBCPP_INLINE_VISIBILITY
97 void param(const param_type& __p) {__p_ = __p;}
98
99 _LIBCPP_INLINE_VISIBILITY
100 result_type min() const {return 0;}
101 _LIBCPP_INLINE_VISIBILITY
102 result_type max() const {return t();}
103
104 friend _LIBCPP_INLINE_VISIBILITY
105 bool operator==(const binomial_distribution& __x,
106 const binomial_distribution& __y)
107 {return __x.__p_ == __y.__p_;}
108 friend _LIBCPP_INLINE_VISIBILITY
109 bool operator!=(const binomial_distribution& __x,
110 const binomial_distribution& __y)
111 {return !(__x == __y);}
112};
113
114#ifndef _LIBCPP_MSVCRT_LIKE
115extern "C" double lgamma_r(double, int *);
116#endif
117
118inline _LIBCPP_INLINE_VISIBILITY double __libcpp_lgamma(double __d) {
119#if defined(_LIBCPP_MSVCRT_LIKE)
120 return lgamma(__d);
121#else
122 int __sign;
123 return lgamma_r(__d, &__sign);
124#endif
125}
126
127template<class _IntType>
128binomial_distribution<_IntType>::param_type::param_type(result_type __t, double __p)
129 : __t_(__t), __p_(__p)
130{
131 if (0 < __p_ && __p_ < 1)
132 {
133 __r0_ = static_cast<result_type>((__t_ + 1) * __p_);
134 __pr_ = _VSTD::exp(__libcpp_lgamma(__t_ + 1.) -
135 __libcpp_lgamma(__r0_ + 1.) -
136 __libcpp_lgamma(__t_ - __r0_ + 1.) + __r0_ * _VSTD::log(__p_) +
137 (__t_ - __r0_) * _VSTD::log(1 - __p_));
138 __odds_ratio_ = __p_ / (1 - __p_);
139 }
140}
141
142// Reference: Kemp, C.D. (1986). `A modal method for generating binomial
143// variables', Commun. Statist. - Theor. Meth. 15(3), 805-813.
144template<class _IntType>
145template<class _URNG>
146_IntType
147binomial_distribution<_IntType>::operator()(_URNG& __g, const param_type& __pr)
148{
149 if (__pr.__t_ == 0 || __pr.__p_ == 0)
150 return 0;
151 if (__pr.__p_ == 1)
152 return __pr.__t_;
153 uniform_real_distribution<double> __gen;
154 double __u = __gen(__g) - __pr.__pr_;
155 if (__u < 0)
156 return __pr.__r0_;
157 double __pu = __pr.__pr_;
158 double __pd = __pu;
159 result_type __ru = __pr.__r0_;
160 result_type __rd = __ru;
161 while (true)
162 {
163 bool __break = true;
164 if (__rd >= 1)
165 {
166 __pd *= __rd / (__pr.__odds_ratio_ * (__pr.__t_ - __rd + 1));
167 __u -= __pd;
168 __break = false;
169 if (__u < 0)
170 return __rd - 1;
171 }
172 if ( __rd != 0 )
173 --__rd;
174 ++__ru;
175 if (__ru <= __pr.__t_)
176 {
177 __pu *= (__pr.__t_ - __ru + 1) * __pr.__odds_ratio_ / __ru;
178 __u -= __pu;
179 __break = false;
180 if (__u < 0)
181 return __ru;
182 }
183 if (__break)
184 return 0;
185 }
186}
187
188template <class _CharT, class _Traits, class _IntType>
189basic_ostream<_CharT, _Traits>&
190operator<<(basic_ostream<_CharT, _Traits>& __os,
191 const binomial_distribution<_IntType>& __x)
192{
193 __save_flags<_CharT, _Traits> __lx(__os);
194 typedef basic_ostream<_CharT, _Traits> _OStream;
195 __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
196 _OStream::scientific);
197 _CharT __sp = __os.widen(' ');
198 __os.fill(__sp);
199 return __os << __x.t() << __sp << __x.p();
200}
201
202template <class _CharT, class _Traits, class _IntType>
203basic_istream<_CharT, _Traits>&
204operator>>(basic_istream<_CharT, _Traits>& __is,
205 binomial_distribution<_IntType>& __x)
206{
207 typedef binomial_distribution<_IntType> _Eng;
208 typedef typename _Eng::result_type result_type;
209 typedef typename _Eng::param_type param_type;
210 __save_flags<_CharT, _Traits> __lx(__is);
211 typedef basic_istream<_CharT, _Traits> _Istream;
212 __is.flags(_Istream::dec | _Istream::skipws);
213 result_type __t;
214 double __p;
215 __is >> __t >> __p;
216 if (!__is.fail())
217 __x.param(param_type(__t, __p));
218 return __is;
219}
220
221_LIBCPP_END_NAMESPACE_STD
222
223_LIBCPP_POP_MACROS
224
225#endif // _LIBCPP___RANDOM_BINOMIAL_DISTRIBUTION_H
lib/libcxx/include/__random/cauchy_distribution.h created+162
......@@ -0,0 +1,162 @@
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_CAUCHY_DISTRIBUTION_H
10#define _LIBCPP___RANDOM_CAUCHY_DISTRIBUTION_H
11
12#include <__config>
13#include <__random/uniform_real_distribution.h>
14#include <cmath>
15#include <iosfwd>
16#include <limits>
17
18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
20#endif
21
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
25_LIBCPP_BEGIN_NAMESPACE_STD
26
27template<class _RealType = double>
28class _LIBCPP_TEMPLATE_VIS cauchy_distribution
29{
30public:
31 // types
32 typedef _RealType result_type;
33
34 class _LIBCPP_TEMPLATE_VIS param_type
35 {
36 result_type __a_;
37 result_type __b_;
38 public:
39 typedef cauchy_distribution distribution_type;
40
41 _LIBCPP_INLINE_VISIBILITY
42 explicit param_type(result_type __a = 0, result_type __b = 1)
43 : __a_(__a), __b_(__b) {}
44
45 _LIBCPP_INLINE_VISIBILITY
46 result_type a() const {return __a_;}
47 _LIBCPP_INLINE_VISIBILITY
48 result_type b() const {return __b_;}
49
50 friend _LIBCPP_INLINE_VISIBILITY
51 bool operator==(const param_type& __x, const param_type& __y)
52 {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;}
53 friend _LIBCPP_INLINE_VISIBILITY
54 bool operator!=(const param_type& __x, const param_type& __y)
55 {return !(__x == __y);}
56 };
57
58private:
59 param_type __p_;
60
61public:
62 // constructor and reset functions
63#ifndef _LIBCPP_CXX03_LANG
64 _LIBCPP_INLINE_VISIBILITY
65 cauchy_distribution() : cauchy_distribution(0) {}
66 _LIBCPP_INLINE_VISIBILITY
67 explicit cauchy_distribution(result_type __a, result_type __b = 1)
68 : __p_(param_type(__a, __b)) {}
69#else
70 _LIBCPP_INLINE_VISIBILITY
71 explicit cauchy_distribution(result_type __a = 0, result_type __b = 1)
72 : __p_(param_type(__a, __b)) {}
73#endif
74 _LIBCPP_INLINE_VISIBILITY
75 explicit cauchy_distribution(const param_type& __p)
76 : __p_(__p) {}
77 _LIBCPP_INLINE_VISIBILITY
78 void reset() {}
79
80 // generating functions
81 template<class _URNG>
82 _LIBCPP_INLINE_VISIBILITY
83 result_type operator()(_URNG& __g)
84 {return (*this)(__g, __p_);}
85 template<class _URNG> _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g, const param_type& __p);
86
87 // property functions
88 _LIBCPP_INLINE_VISIBILITY
89 result_type a() const {return __p_.a();}
90 _LIBCPP_INLINE_VISIBILITY
91 result_type b() const {return __p_.b();}
92
93 _LIBCPP_INLINE_VISIBILITY
94 param_type param() const {return __p_;}
95 _LIBCPP_INLINE_VISIBILITY
96 void param(const param_type& __p) {__p_ = __p;}
97
98 _LIBCPP_INLINE_VISIBILITY
99 result_type min() const {return -numeric_limits<result_type>::infinity();}
100 _LIBCPP_INLINE_VISIBILITY
101 result_type max() const {return numeric_limits<result_type>::infinity();}
102
103 friend _LIBCPP_INLINE_VISIBILITY
104 bool operator==(const cauchy_distribution& __x,
105 const cauchy_distribution& __y)
106 {return __x.__p_ == __y.__p_;}
107 friend _LIBCPP_INLINE_VISIBILITY
108 bool operator!=(const cauchy_distribution& __x,
109 const cauchy_distribution& __y)
110 {return !(__x == __y);}
111};
112
113template <class _RealType>
114template<class _URNG>
115inline
116_RealType
117cauchy_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
118{
119 uniform_real_distribution<result_type> __gen;
120 // purposefully let tan arg get as close to pi/2 as it wants, tan will return a finite
121 return __p.a() + __p.b() * _VSTD::tan(3.1415926535897932384626433832795 * __gen(__g));
122}
123
124template <class _CharT, class _Traits, class _RT>
125basic_ostream<_CharT, _Traits>&
126operator<<(basic_ostream<_CharT, _Traits>& __os,
127 const cauchy_distribution<_RT>& __x)
128{
129 __save_flags<_CharT, _Traits> __lx(__os);
130 typedef basic_ostream<_CharT, _Traits> _OStream;
131 __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
132 _OStream::scientific);
133 _CharT __sp = __os.widen(' ');
134 __os.fill(__sp);
135 __os << __x.a() << __sp << __x.b();
136 return __os;
137}
138
139template <class _CharT, class _Traits, class _RT>
140basic_istream<_CharT, _Traits>&
141operator>>(basic_istream<_CharT, _Traits>& __is,
142 cauchy_distribution<_RT>& __x)
143{
144 typedef cauchy_distribution<_RT> _Eng;
145 typedef typename _Eng::result_type result_type;
146 typedef typename _Eng::param_type param_type;
147 __save_flags<_CharT, _Traits> __lx(__is);
148 typedef basic_istream<_CharT, _Traits> _Istream;
149 __is.flags(_Istream::dec | _Istream::skipws);
150 result_type __a;
151 result_type __b;
152 __is >> __a >> __b;
153 if (!__is.fail())
154 __x.param(param_type(__a, __b));
155 return __is;
156}
157
158_LIBCPP_END_NAMESPACE_STD
159
160_LIBCPP_POP_MACROS
161
162#endif // _LIBCPP___RANDOM_CAUCHY_DISTRIBUTION_H
lib/libcxx/include/__random/chi_squared_distribution.h created+144
......@@ -0,0 +1,144 @@
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_CHI_SQUARED_DISTRIBUTION_H
10#define _LIBCPP___RANDOM_CHI_SQUARED_DISTRIBUTION_H
11
12#include <__config>
13#include <__random/gamma_distribution.h>
14#include <iosfwd>
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
26template<class _RealType = double>
27class _LIBCPP_TEMPLATE_VIS chi_squared_distribution
28{
29public:
30 // types
31 typedef _RealType result_type;
32
33 class _LIBCPP_TEMPLATE_VIS param_type
34 {
35 result_type __n_;
36 public:
37 typedef chi_squared_distribution distribution_type;
38
39 _LIBCPP_INLINE_VISIBILITY
40 explicit param_type(result_type __n = 1) : __n_(__n) {}
41
42 _LIBCPP_INLINE_VISIBILITY
43 result_type n() const {return __n_;}
44
45 friend _LIBCPP_INLINE_VISIBILITY
46 bool operator==(const param_type& __x, const param_type& __y)
47 {return __x.__n_ == __y.__n_;}
48 friend _LIBCPP_INLINE_VISIBILITY
49 bool operator!=(const param_type& __x, const param_type& __y)
50 {return !(__x == __y);}
51 };
52
53private:
54 param_type __p_;
55
56public:
57 // constructor and reset functions
58#ifndef _LIBCPP_CXX03_LANG
59 _LIBCPP_INLINE_VISIBILITY
60 chi_squared_distribution() : chi_squared_distribution(1) {}
61 _LIBCPP_INLINE_VISIBILITY
62 explicit chi_squared_distribution(result_type __n)
63 : __p_(param_type(__n)) {}
64#else
65 _LIBCPP_INLINE_VISIBILITY
66 explicit chi_squared_distribution(result_type __n = 1)
67 : __p_(param_type(__n)) {}
68#endif
69 _LIBCPP_INLINE_VISIBILITY
70 explicit chi_squared_distribution(const param_type& __p)
71 : __p_(__p) {}
72 _LIBCPP_INLINE_VISIBILITY
73 void reset() {}
74
75 // generating functions
76 template<class _URNG>
77 _LIBCPP_INLINE_VISIBILITY
78 result_type operator()(_URNG& __g)
79 {return (*this)(__g, __p_);}
80 template<class _URNG>
81 _LIBCPP_INLINE_VISIBILITY
82 result_type operator()(_URNG& __g, const param_type& __p)
83 {return gamma_distribution<result_type>(__p.n() / 2, 2)(__g);}
84
85 // property functions
86 _LIBCPP_INLINE_VISIBILITY
87 result_type n() const {return __p_.n();}
88
89 _LIBCPP_INLINE_VISIBILITY
90 param_type param() const {return __p_;}
91 _LIBCPP_INLINE_VISIBILITY
92 void param(const param_type& __p) {__p_ = __p;}
93
94 _LIBCPP_INLINE_VISIBILITY
95 result_type min() const {return 0;}
96 _LIBCPP_INLINE_VISIBILITY
97 result_type max() const {return numeric_limits<result_type>::infinity();}
98
99 friend _LIBCPP_INLINE_VISIBILITY
100 bool operator==(const chi_squared_distribution& __x,
101 const chi_squared_distribution& __y)
102 {return __x.__p_ == __y.__p_;}
103 friend _LIBCPP_INLINE_VISIBILITY
104 bool operator!=(const chi_squared_distribution& __x,
105 const chi_squared_distribution& __y)
106 {return !(__x == __y);}
107};
108
109template <class _CharT, class _Traits, class _RT>
110basic_ostream<_CharT, _Traits>&
111operator<<(basic_ostream<_CharT, _Traits>& __os,
112 const chi_squared_distribution<_RT>& __x)
113{
114 __save_flags<_CharT, _Traits> __lx(__os);
115 typedef basic_ostream<_CharT, _Traits> _OStream;
116 __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
117 _OStream::scientific);
118 __os << __x.n();
119 return __os;
120}
121
122template <class _CharT, class _Traits, class _RT>
123basic_istream<_CharT, _Traits>&
124operator>>(basic_istream<_CharT, _Traits>& __is,
125 chi_squared_distribution<_RT>& __x)
126{
127 typedef chi_squared_distribution<_RT> _Eng;
128 typedef typename _Eng::result_type result_type;
129 typedef typename _Eng::param_type param_type;
130 __save_flags<_CharT, _Traits> __lx(__is);
131 typedef basic_istream<_CharT, _Traits> _Istream;
132 __is.flags(_Istream::dec | _Istream::skipws);
133 result_type __n;
134 __is >> __n;
135 if (!__is.fail())
136 __x.param(param_type(__n));
137 return __is;
138}
139
140_LIBCPP_END_NAMESPACE_STD
141
142_LIBCPP_POP_MACROS
143
144#endif // _LIBCPP___RANDOM_CHI_SQUARED_DISTRIBUTION_H
lib/libcxx/include/__random/clamp_to_integral.h created+60
......@@ -0,0 +1,60 @@
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_CLAMP_TO_INTEGRAL_H
10#define _LIBCPP___RANDOM_CLAMP_TO_INTEGRAL_H
11
12#include <__config>
13#include <cmath>
14#include <limits>
15#include <type_traits>
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
26template <class _IntT, class _FloatT,
27 bool _FloatBigger = (numeric_limits<_FloatT>::digits > numeric_limits<_IntT>::digits),
28 int _Bits = (numeric_limits<_IntT>::digits - numeric_limits<_FloatT>::digits)>
29_LIBCPP_INLINE_VISIBILITY
30_LIBCPP_CONSTEXPR _IntT __max_representable_int_for_float() _NOEXCEPT {
31 static_assert(is_floating_point<_FloatT>::value, "must be a floating point type");
32 static_assert(is_integral<_IntT>::value, "must be an integral type");
33 static_assert(numeric_limits<_FloatT>::radix == 2, "FloatT has incorrect radix");
34 static_assert((_IsSame<_FloatT, float>::value || _IsSame<_FloatT, double>::value
35 || _IsSame<_FloatT,long double>::value), "unsupported floating point type");
36 return _FloatBigger ? numeric_limits<_IntT>::max() : (numeric_limits<_IntT>::max() >> _Bits << _Bits);
37}
38
39// Convert a floating point number to the specified integral type after
40// clamping to the integral type's representable range.
41//
42// The behavior is undefined if `__r` is NaN.
43template <class _IntT, class _RealT>
44_LIBCPP_INLINE_VISIBILITY
45_IntT __clamp_to_integral(_RealT __r) _NOEXCEPT {
46 using _Lim = numeric_limits<_IntT>;
47 const _IntT _MaxVal = __max_representable_int_for_float<_IntT, _RealT>();
48 if (__r >= ::nextafter(static_cast<_RealT>(_MaxVal), INFINITY)) {
49 return _Lim::max();
50 } else if (__r <= _Lim::lowest()) {
51 return _Lim::min();
52 }
53 return static_cast<_IntT>(__r);
54}
55
56_LIBCPP_END_NAMESPACE_STD
57
58_LIBCPP_POP_MACROS
59
60#endif // _LIBCPP___RANDOM_CLAMP_TO_INTEGRAL_H
lib/libcxx/include/__random/default_random_engine.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___RANDOM_DEFAULT_RANDOM_ENGINE_H
10#define _LIBCPP___RANDOM_DEFAULT_RANDOM_ENGINE_H
11
12#include <__config>
13#include <__random/linear_congruential_engine.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
21typedef minstd_rand default_random_engine;
22
23_LIBCPP_END_NAMESPACE_STD
24
25#endif // _LIBCPP___RANDOM_DEFAULT_RANDOM_ENGINE_H
lib/libcxx/include/__random/discard_block_engine.h created+203
......@@ -0,0 +1,203 @@
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_DISCARD_BLOCK_ENGINE_H
10#define _LIBCPP___RANDOM_DISCARD_BLOCK_ENGINE_H
11
12#include <__config>
13#include <__random/is_seed_sequence.h>
14#include <__utility/move.h>
15#include <climits>
16#include <iosfwd>
17#include <type_traits>
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
28template<class _Engine, size_t __p, size_t __r>
29class _LIBCPP_TEMPLATE_VIS discard_block_engine
30{
31 _Engine __e_;
32 int __n_;
33
34 static_assert( 0 < __r, "discard_block_engine invalid parameters");
35 static_assert(__r <= __p, "discard_block_engine invalid parameters");
36 static_assert(__r <= INT_MAX, "discard_block_engine invalid parameters");
37public:
38 // types
39 typedef typename _Engine::result_type result_type;
40
41 // engine characteristics
42 static _LIBCPP_CONSTEXPR const size_t block_size = __p;
43 static _LIBCPP_CONSTEXPR const size_t used_block = __r;
44
45#ifdef _LIBCPP_CXX03_LANG
46 static const result_type _Min = _Engine::_Min;
47 static const result_type _Max = _Engine::_Max;
48#else
49 static _LIBCPP_CONSTEXPR const result_type _Min = _Engine::min();
50 static _LIBCPP_CONSTEXPR const result_type _Max = _Engine::max();
51#endif
52
53 _LIBCPP_INLINE_VISIBILITY
54 static _LIBCPP_CONSTEXPR result_type min() { return _Engine::min(); }
55 _LIBCPP_INLINE_VISIBILITY
56 static _LIBCPP_CONSTEXPR result_type max() { return _Engine::max(); }
57
58 // constructors and seeding functions
59 _LIBCPP_INLINE_VISIBILITY
60 discard_block_engine() : __n_(0) {}
61 _LIBCPP_INLINE_VISIBILITY
62 explicit discard_block_engine(const _Engine& __e)
63 : __e_(__e), __n_(0) {}
64#ifndef _LIBCPP_CXX03_LANG
65 _LIBCPP_INLINE_VISIBILITY
66 explicit discard_block_engine(_Engine&& __e)
67 : __e_(_VSTD::move(__e)), __n_(0) {}
68#endif // _LIBCPP_CXX03_LANG
69 _LIBCPP_INLINE_VISIBILITY
70 explicit discard_block_engine(result_type __sd) : __e_(__sd), __n_(0) {}
71 template<class _Sseq>
72 _LIBCPP_INLINE_VISIBILITY
73 explicit discard_block_engine(_Sseq& __q,
74 typename enable_if<__is_seed_sequence<_Sseq, discard_block_engine>::value &&
75 !is_convertible<_Sseq, _Engine>::value>::type* = 0)
76 : __e_(__q), __n_(0) {}
77 _LIBCPP_INLINE_VISIBILITY
78 void seed() {__e_.seed(); __n_ = 0;}
79 _LIBCPP_INLINE_VISIBILITY
80 void seed(result_type __sd) {__e_.seed(__sd); __n_ = 0;}
81 template<class _Sseq>
82 _LIBCPP_INLINE_VISIBILITY
83 typename enable_if
84 <
85 __is_seed_sequence<_Sseq, discard_block_engine>::value,
86 void
87 >::type
88 seed(_Sseq& __q) {__e_.seed(__q); __n_ = 0;}
89
90 // generating functions
91 result_type operator()();
92 _LIBCPP_INLINE_VISIBILITY
93 void discard(unsigned long long __z) {for (; __z; --__z) operator()();}
94
95 // property functions
96 _LIBCPP_INLINE_VISIBILITY
97 const _Engine& base() const _NOEXCEPT {return __e_;}
98
99 template<class _Eng, size_t _Pp, size_t _Rp>
100 friend
101 bool
102 operator==(
103 const discard_block_engine<_Eng, _Pp, _Rp>& __x,
104 const discard_block_engine<_Eng, _Pp, _Rp>& __y);
105
106 template<class _Eng, size_t _Pp, size_t _Rp>
107 friend
108 bool
109 operator!=(
110 const discard_block_engine<_Eng, _Pp, _Rp>& __x,
111 const discard_block_engine<_Eng, _Pp, _Rp>& __y);
112
113 template <class _CharT, class _Traits,
114 class _Eng, size_t _Pp, size_t _Rp>
115 friend
116 basic_ostream<_CharT, _Traits>&
117 operator<<(basic_ostream<_CharT, _Traits>& __os,
118 const discard_block_engine<_Eng, _Pp, _Rp>& __x);
119
120 template <class _CharT, class _Traits,
121 class _Eng, size_t _Pp, size_t _Rp>
122 friend
123 basic_istream<_CharT, _Traits>&
124 operator>>(basic_istream<_CharT, _Traits>& __is,
125 discard_block_engine<_Eng, _Pp, _Rp>& __x);
126};
127
128template<class _Engine, size_t __p, size_t __r>
129 _LIBCPP_CONSTEXPR const size_t discard_block_engine<_Engine, __p, __r>::block_size;
130
131template<class _Engine, size_t __p, size_t __r>
132 _LIBCPP_CONSTEXPR const size_t discard_block_engine<_Engine, __p, __r>::used_block;
133
134template<class _Engine, size_t __p, size_t __r>
135typename discard_block_engine<_Engine, __p, __r>::result_type
136discard_block_engine<_Engine, __p, __r>::operator()()
137{
138 if (__n_ >= static_cast<int>(__r))
139 {
140 __e_.discard(__p - __r);
141 __n_ = 0;
142 }
143 ++__n_;
144 return __e_();
145}
146
147template<class _Eng, size_t _Pp, size_t _Rp>
148inline _LIBCPP_INLINE_VISIBILITY
149bool
150operator==(const discard_block_engine<_Eng, _Pp, _Rp>& __x,
151 const discard_block_engine<_Eng, _Pp, _Rp>& __y)
152{
153 return __x.__n_ == __y.__n_ && __x.__e_ == __y.__e_;
154}
155
156template<class _Eng, size_t _Pp, size_t _Rp>
157inline _LIBCPP_INLINE_VISIBILITY
158bool
159operator!=(const discard_block_engine<_Eng, _Pp, _Rp>& __x,
160 const discard_block_engine<_Eng, _Pp, _Rp>& __y)
161{
162 return !(__x == __y);
163}
164
165template <class _CharT, class _Traits,
166 class _Eng, size_t _Pp, size_t _Rp>
167basic_ostream<_CharT, _Traits>&
168operator<<(basic_ostream<_CharT, _Traits>& __os,
169 const discard_block_engine<_Eng, _Pp, _Rp>& __x)
170{
171 __save_flags<_CharT, _Traits> __lx(__os);
172 typedef basic_ostream<_CharT, _Traits> _Ostream;
173 __os.flags(_Ostream::dec | _Ostream::left);
174 _CharT __sp = __os.widen(' ');
175 __os.fill(__sp);
176 return __os << __x.__e_ << __sp << __x.__n_;
177}
178
179template <class _CharT, class _Traits,
180 class _Eng, size_t _Pp, size_t _Rp>
181basic_istream<_CharT, _Traits>&
182operator>>(basic_istream<_CharT, _Traits>& __is,
183 discard_block_engine<_Eng, _Pp, _Rp>& __x)
184{
185 __save_flags<_CharT, _Traits> __lx(__is);
186 typedef basic_istream<_CharT, _Traits> _Istream;
187 __is.flags(_Istream::dec | _Istream::skipws);
188 _Eng __e;
189 int __n;
190 __is >> __e >> __n;
191 if (!__is.fail())
192 {
193 __x.__e_ = __e;
194 __x.__n_ = __n;
195 }
196 return __is;
197}
198
199_LIBCPP_END_NAMESPACE_STD
200
201_LIBCPP_POP_MACROS
202
203#endif // _LIBCPP___RANDOM_DISCARD_BLOCK_ENGINE_H
lib/libcxx/include/__random/discrete_distribution.h created+260
......@@ -0,0 +1,260 @@
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_DISCRETE_DISTRIBUTION_H
10#define _LIBCPP___RANDOM_DISCRETE_DISTRIBUTION_H
11
12#include <__algorithm/upper_bound.h>
13#include <__config>
14#include <__random/uniform_real_distribution.h>
15#include <cstddef>
16#include <iosfwd>
17#include <numeric>
18#include <vector>
19
20#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21#pragma GCC system_header
22#endif
23
24_LIBCPP_PUSH_MACROS
25#include <__undef_macros>
26
27_LIBCPP_BEGIN_NAMESPACE_STD
28
29template<class _IntType = int>
30class _LIBCPP_TEMPLATE_VIS discrete_distribution
31{
32public:
33 // types
34 typedef _IntType result_type;
35
36 class _LIBCPP_TEMPLATE_VIS param_type
37 {
38 vector<double> __p_;
39 public:
40 typedef discrete_distribution distribution_type;
41
42 _LIBCPP_INLINE_VISIBILITY
43 param_type() {}
44 template<class _InputIterator>
45 _LIBCPP_INLINE_VISIBILITY
46 param_type(_InputIterator __f, _InputIterator __l)
47 : __p_(__f, __l) {__init();}
48#ifndef _LIBCPP_CXX03_LANG
49 _LIBCPP_INLINE_VISIBILITY
50 param_type(initializer_list<double> __wl)
51 : __p_(__wl.begin(), __wl.end()) {__init();}
52#endif // _LIBCPP_CXX03_LANG
53 template<class _UnaryOperation>
54 param_type(size_t __nw, double __xmin, double __xmax,
55 _UnaryOperation __fw);
56
57 vector<double> probabilities() const;
58
59 friend _LIBCPP_INLINE_VISIBILITY
60 bool operator==(const param_type& __x, const param_type& __y)
61 {return __x.__p_ == __y.__p_;}
62 friend _LIBCPP_INLINE_VISIBILITY
63 bool operator!=(const param_type& __x, const param_type& __y)
64 {return !(__x == __y);}
65
66 private:
67 void __init();
68
69 friend class discrete_distribution;
70
71 template <class _CharT, class _Traits, class _IT>
72 friend
73 basic_ostream<_CharT, _Traits>&
74 operator<<(basic_ostream<_CharT, _Traits>& __os,
75 const discrete_distribution<_IT>& __x);
76
77 template <class _CharT, class _Traits, class _IT>
78 friend
79 basic_istream<_CharT, _Traits>&
80 operator>>(basic_istream<_CharT, _Traits>& __is,
81 discrete_distribution<_IT>& __x);
82 };
83
84private:
85 param_type __p_;
86
87public:
88 // constructor and reset functions
89 _LIBCPP_INLINE_VISIBILITY
90 discrete_distribution() {}
91 template<class _InputIterator>
92 _LIBCPP_INLINE_VISIBILITY
93 discrete_distribution(_InputIterator __f, _InputIterator __l)
94 : __p_(__f, __l) {}
95#ifndef _LIBCPP_CXX03_LANG
96 _LIBCPP_INLINE_VISIBILITY
97 discrete_distribution(initializer_list<double> __wl)
98 : __p_(__wl) {}
99#endif // _LIBCPP_CXX03_LANG
100 template<class _UnaryOperation>
101 _LIBCPP_INLINE_VISIBILITY
102 discrete_distribution(size_t __nw, double __xmin, double __xmax,
103 _UnaryOperation __fw)
104 : __p_(__nw, __xmin, __xmax, __fw) {}
105 _LIBCPP_INLINE_VISIBILITY
106 explicit discrete_distribution(const param_type& __p)
107 : __p_(__p) {}
108 _LIBCPP_INLINE_VISIBILITY
109 void reset() {}
110
111 // generating functions
112 template<class _URNG>
113 _LIBCPP_INLINE_VISIBILITY
114 result_type operator()(_URNG& __g)
115 {return (*this)(__g, __p_);}
116 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
117
118 // property functions
119 _LIBCPP_INLINE_VISIBILITY
120 vector<double> probabilities() const {return __p_.probabilities();}
121
122 _LIBCPP_INLINE_VISIBILITY
123 param_type param() const {return __p_;}
124 _LIBCPP_INLINE_VISIBILITY
125 void param(const param_type& __p) {__p_ = __p;}
126
127 _LIBCPP_INLINE_VISIBILITY
128 result_type min() const {return 0;}
129 _LIBCPP_INLINE_VISIBILITY
130 result_type max() const {return __p_.__p_.size();}
131
132 friend _LIBCPP_INLINE_VISIBILITY
133 bool operator==(const discrete_distribution& __x,
134 const discrete_distribution& __y)
135 {return __x.__p_ == __y.__p_;}
136 friend _LIBCPP_INLINE_VISIBILITY
137 bool operator!=(const discrete_distribution& __x,
138 const discrete_distribution& __y)
139 {return !(__x == __y);}
140
141 template <class _CharT, class _Traits, class _IT>
142 friend
143 basic_ostream<_CharT, _Traits>&
144 operator<<(basic_ostream<_CharT, _Traits>& __os,
145 const discrete_distribution<_IT>& __x);
146
147 template <class _CharT, class _Traits, class _IT>
148 friend
149 basic_istream<_CharT, _Traits>&
150 operator>>(basic_istream<_CharT, _Traits>& __is,
151 discrete_distribution<_IT>& __x);
152};
153
154template<class _IntType>
155template<class _UnaryOperation>
156discrete_distribution<_IntType>::param_type::param_type(size_t __nw,
157 double __xmin,
158 double __xmax,
159 _UnaryOperation __fw)
160{
161 if (__nw > 1)
162 {
163 __p_.reserve(__nw - 1);
164 double __d = (__xmax - __xmin) / __nw;
165 double __d2 = __d / 2;
166 for (size_t __k = 0; __k < __nw; ++__k)
167 __p_.push_back(__fw(__xmin + __k * __d + __d2));
168 __init();
169 }
170}
171
172template<class _IntType>
173void
174discrete_distribution<_IntType>::param_type::__init()
175{
176 if (!__p_.empty())
177 {
178 if (__p_.size() > 1)
179 {
180 double __s = _VSTD::accumulate(__p_.begin(), __p_.end(), 0.0);
181 for (vector<double>::iterator __i = __p_.begin(), __e = __p_.end(); __i < __e; ++__i)
182 *__i /= __s;
183 vector<double> __t(__p_.size() - 1);
184 _VSTD::partial_sum(__p_.begin(), __p_.end() - 1, __t.begin());
185 swap(__p_, __t);
186 }
187 else
188 {
189 __p_.clear();
190 __p_.shrink_to_fit();
191 }
192 }
193}
194
195template<class _IntType>
196vector<double>
197discrete_distribution<_IntType>::param_type::probabilities() const
198{
199 size_t __n = __p_.size();
200 vector<double> __p(__n+1);
201 _VSTD::adjacent_difference(__p_.begin(), __p_.end(), __p.begin());
202 if (__n > 0)
203 __p[__n] = 1 - __p_[__n-1];
204 else
205 __p[0] = 1;
206 return __p;
207}
208
209template<class _IntType>
210template<class _URNG>
211_IntType
212discrete_distribution<_IntType>::operator()(_URNG& __g, const param_type& __p)
213{
214 uniform_real_distribution<double> __gen;
215 return static_cast<_IntType>(
216 _VSTD::upper_bound(__p.__p_.begin(), __p.__p_.end(), __gen(__g)) -
217 __p.__p_.begin());
218}
219
220template <class _CharT, class _Traits, class _IT>
221basic_ostream<_CharT, _Traits>&
222operator<<(basic_ostream<_CharT, _Traits>& __os,
223 const discrete_distribution<_IT>& __x)
224{
225 __save_flags<_CharT, _Traits> __lx(__os);
226 typedef basic_ostream<_CharT, _Traits> _OStream;
227 __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
228 _OStream::scientific);
229 _CharT __sp = __os.widen(' ');
230 __os.fill(__sp);
231 size_t __n = __x.__p_.__p_.size();
232 __os << __n;
233 for (size_t __i = 0; __i < __n; ++__i)
234 __os << __sp << __x.__p_.__p_[__i];
235 return __os;
236}
237
238template <class _CharT, class _Traits, class _IT>
239basic_istream<_CharT, _Traits>&
240operator>>(basic_istream<_CharT, _Traits>& __is,
241 discrete_distribution<_IT>& __x)
242{
243 __save_flags<_CharT, _Traits> __lx(__is);
244 typedef basic_istream<_CharT, _Traits> _Istream;
245 __is.flags(_Istream::dec | _Istream::skipws);
246 size_t __n;
247 __is >> __n;
248 vector<double> __p(__n);
249 for (size_t __i = 0; __i < __n; ++__i)
250 __is >> __p[__i];
251 if (!__is.fail())
252 swap(__x.__p_.__p_, __p);
253 return __is;
254}
255
256_LIBCPP_END_NAMESPACE_STD
257
258_LIBCPP_POP_MACROS
259
260#endif // _LIBCPP___RANDOM_DISCRETE_DISTRIBUTION_H
lib/libcxx/include/__random/exponential_distribution.h created+155
......@@ -0,0 +1,155 @@
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_EXPONENTIAL_DISTRIBUTION_H
10#define _LIBCPP___RANDOM_EXPONENTIAL_DISTRIBUTION_H
11
12#include <__config>
13#include <__random/generate_canonical.h>
14#include <__random/uniform_real_distribution.h>
15#include <cmath>
16#include <iosfwd>
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
28template<class _RealType = double>
29class _LIBCPP_TEMPLATE_VIS exponential_distribution
30{
31public:
32 // types
33 typedef _RealType result_type;
34
35 class _LIBCPP_TEMPLATE_VIS param_type
36 {
37 result_type __lambda_;
38 public:
39 typedef exponential_distribution distribution_type;
40
41 _LIBCPP_INLINE_VISIBILITY
42 explicit param_type(result_type __lambda = 1) : __lambda_(__lambda) {}
43
44 _LIBCPP_INLINE_VISIBILITY
45 result_type lambda() const {return __lambda_;}
46
47 friend _LIBCPP_INLINE_VISIBILITY
48 bool operator==(const param_type& __x, const param_type& __y)
49 {return __x.__lambda_ == __y.__lambda_;}
50 friend _LIBCPP_INLINE_VISIBILITY
51 bool operator!=(const param_type& __x, const param_type& __y)
52 {return !(__x == __y);}
53 };
54
55private:
56 param_type __p_;
57
58public:
59 // constructors and reset functions
60#ifndef _LIBCPP_CXX03_LANG
61 _LIBCPP_INLINE_VISIBILITY
62 exponential_distribution() : exponential_distribution(1) {}
63 _LIBCPP_INLINE_VISIBILITY
64 explicit exponential_distribution(result_type __lambda)
65 : __p_(param_type(__lambda)) {}
66#else
67 _LIBCPP_INLINE_VISIBILITY
68 explicit exponential_distribution(result_type __lambda = 1)
69 : __p_(param_type(__lambda)) {}
70#endif
71 _LIBCPP_INLINE_VISIBILITY
72 explicit exponential_distribution(const param_type& __p) : __p_(__p) {}
73 _LIBCPP_INLINE_VISIBILITY
74 void reset() {}
75
76 // generating functions
77 template<class _URNG>
78 _LIBCPP_INLINE_VISIBILITY
79 result_type operator()(_URNG& __g)
80 {return (*this)(__g, __p_);}
81 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
82
83 // property functions
84 _LIBCPP_INLINE_VISIBILITY
85 result_type lambda() const {return __p_.lambda();}
86
87 _LIBCPP_INLINE_VISIBILITY
88 param_type param() const {return __p_;}
89 _LIBCPP_INLINE_VISIBILITY
90 void param(const param_type& __p) {__p_ = __p;}
91
92 _LIBCPP_INLINE_VISIBILITY
93 result_type min() const {return 0;}
94 _LIBCPP_INLINE_VISIBILITY
95 result_type max() const {return numeric_limits<result_type>::infinity();}
96
97 friend _LIBCPP_INLINE_VISIBILITY
98 bool operator==(const exponential_distribution& __x,
99 const exponential_distribution& __y)
100 {return __x.__p_ == __y.__p_;}
101 friend _LIBCPP_INLINE_VISIBILITY
102 bool operator!=(const exponential_distribution& __x,
103 const exponential_distribution& __y)
104 {return !(__x == __y);}
105};
106
107template <class _RealType>
108template<class _URNG>
109_RealType
110exponential_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
111{
112 return -_VSTD::log
113 (
114 result_type(1) -
115 _VSTD::generate_canonical<result_type,
116 numeric_limits<result_type>::digits>(__g)
117 )
118 / __p.lambda();
119}
120
121template <class _CharT, class _Traits, class _RealType>
122basic_ostream<_CharT, _Traits>&
123operator<<(basic_ostream<_CharT, _Traits>& __os,
124 const exponential_distribution<_RealType>& __x)
125{
126 __save_flags<_CharT, _Traits> __lx(__os);
127 typedef basic_ostream<_CharT, _Traits> _OStream;
128 __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
129 _OStream::scientific);
130 return __os << __x.lambda();
131}
132
133template <class _CharT, class _Traits, class _RealType>
134basic_istream<_CharT, _Traits>&
135operator>>(basic_istream<_CharT, _Traits>& __is,
136 exponential_distribution<_RealType>& __x)
137{
138 typedef exponential_distribution<_RealType> _Eng;
139 typedef typename _Eng::result_type result_type;
140 typedef typename _Eng::param_type param_type;
141 __save_flags<_CharT, _Traits> __lx(__is);
142 typedef basic_istream<_CharT, _Traits> _Istream;
143 __is.flags(_Istream::dec | _Istream::skipws);
144 result_type __lambda;
145 __is >> __lambda;
146 if (!__is.fail())
147 __x.param(param_type(__lambda));
148 return __is;
149}
150
151_LIBCPP_END_NAMESPACE_STD
152
153_LIBCPP_POP_MACROS
154
155#endif // _LIBCPP___RANDOM_EXPONENTIAL_DISTRIBUTION_H
lib/libcxx/include/__random/extreme_value_distribution.h created+161
......@@ -0,0 +1,161 @@
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_EXTREME_VALUE_DISTRIBUTION_H
10#define _LIBCPP___RANDOM_EXTREME_VALUE_DISTRIBUTION_H
11
12#include <__config>
13#include <__random/uniform_real_distribution.h>
14#include <cmath>
15#include <iosfwd>
16#include <limits>
17
18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
20#endif
21
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
25_LIBCPP_BEGIN_NAMESPACE_STD
26
27template<class _RealType = double>
28class _LIBCPP_TEMPLATE_VIS extreme_value_distribution
29{
30public:
31 // types
32 typedef _RealType result_type;
33
34 class _LIBCPP_TEMPLATE_VIS param_type
35 {
36 result_type __a_;
37 result_type __b_;
38 public:
39 typedef extreme_value_distribution distribution_type;
40
41 _LIBCPP_INLINE_VISIBILITY
42 explicit param_type(result_type __a = 0, result_type __b = 1)
43 : __a_(__a), __b_(__b) {}
44
45 _LIBCPP_INLINE_VISIBILITY
46 result_type a() const {return __a_;}
47 _LIBCPP_INLINE_VISIBILITY
48 result_type b() const {return __b_;}
49
50 friend _LIBCPP_INLINE_VISIBILITY
51 bool operator==(const param_type& __x, const param_type& __y)
52 {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;}
53 friend _LIBCPP_INLINE_VISIBILITY
54 bool operator!=(const param_type& __x, const param_type& __y)
55 {return !(__x == __y);}
56 };
57
58private:
59 param_type __p_;
60
61public:
62 // constructor and reset functions
63#ifndef _LIBCPP_CXX03_LANG
64 _LIBCPP_INLINE_VISIBILITY
65 extreme_value_distribution() : extreme_value_distribution(0) {}
66 _LIBCPP_INLINE_VISIBILITY
67 explicit extreme_value_distribution(result_type __a, result_type __b = 1)
68 : __p_(param_type(__a, __b)) {}
69#else
70 _LIBCPP_INLINE_VISIBILITY
71 explicit extreme_value_distribution(result_type __a = 0,
72 result_type __b = 1)
73 : __p_(param_type(__a, __b)) {}
74#endif
75 _LIBCPP_INLINE_VISIBILITY
76 explicit extreme_value_distribution(const param_type& __p)
77 : __p_(__p) {}
78 _LIBCPP_INLINE_VISIBILITY
79 void reset() {}
80
81 // generating functions
82 template<class _URNG>
83 _LIBCPP_INLINE_VISIBILITY
84 result_type operator()(_URNG& __g)
85 {return (*this)(__g, __p_);}
86 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
87
88 // property functions
89 _LIBCPP_INLINE_VISIBILITY
90 result_type a() const {return __p_.a();}
91 _LIBCPP_INLINE_VISIBILITY
92 result_type b() const {return __p_.b();}
93
94 _LIBCPP_INLINE_VISIBILITY
95 param_type param() const {return __p_;}
96 _LIBCPP_INLINE_VISIBILITY
97 void param(const param_type& __p) {__p_ = __p;}
98
99 _LIBCPP_INLINE_VISIBILITY
100 result_type min() const {return -numeric_limits<result_type>::infinity();}
101 _LIBCPP_INLINE_VISIBILITY
102 result_type max() const {return numeric_limits<result_type>::infinity();}
103
104 friend _LIBCPP_INLINE_VISIBILITY
105 bool operator==(const extreme_value_distribution& __x,
106 const extreme_value_distribution& __y)
107 {return __x.__p_ == __y.__p_;}
108 friend _LIBCPP_INLINE_VISIBILITY
109 bool operator!=(const extreme_value_distribution& __x,
110 const extreme_value_distribution& __y)
111 {return !(__x == __y);}
112};
113
114template<class _RealType>
115template<class _URNG>
116_RealType
117extreme_value_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
118{
119 return __p.a() - __p.b() *
120 _VSTD::log(-_VSTD::log(1-uniform_real_distribution<result_type>()(__g)));
121}
122
123template <class _CharT, class _Traits, class _RT>
124basic_ostream<_CharT, _Traits>&
125operator<<(basic_ostream<_CharT, _Traits>& __os,
126 const extreme_value_distribution<_RT>& __x)
127{
128 __save_flags<_CharT, _Traits> __lx(__os);
129 typedef basic_ostream<_CharT, _Traits> _OStream;
130 __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
131 _OStream::scientific);
132 _CharT __sp = __os.widen(' ');
133 __os.fill(__sp);
134 __os << __x.a() << __sp << __x.b();
135 return __os;
136}
137
138template <class _CharT, class _Traits, class _RT>
139basic_istream<_CharT, _Traits>&
140operator>>(basic_istream<_CharT, _Traits>& __is,
141 extreme_value_distribution<_RT>& __x)
142{
143 typedef extreme_value_distribution<_RT> _Eng;
144 typedef typename _Eng::result_type result_type;
145 typedef typename _Eng::param_type param_type;
146 __save_flags<_CharT, _Traits> __lx(__is);
147 typedef basic_istream<_CharT, _Traits> _Istream;
148 __is.flags(_Istream::dec | _Istream::skipws);
149 result_type __a;
150 result_type __b;
151 __is >> __a >> __b;
152 if (!__is.fail())
153 __x.param(param_type(__a, __b));
154 return __is;
155}
156
157_LIBCPP_END_NAMESPACE_STD
158
159_LIBCPP_POP_MACROS
160
161#endif // _LIBCPP___RANDOM_EXTREME_VALUE_DISTRIBUTION_H
lib/libcxx/include/__random/fisher_f_distribution.h created+160
......@@ -0,0 +1,160 @@
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_FISHER_F_DISTRIBUTION_H
10#define _LIBCPP___RANDOM_FISHER_F_DISTRIBUTION_H
11
12#include <__config>
13#include <__random/gamma_distribution.h>
14#include <iosfwd>
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
26template<class _RealType = double>
27class _LIBCPP_TEMPLATE_VIS fisher_f_distribution
28{
29public:
30 // types
31 typedef _RealType result_type;
32
33 class _LIBCPP_TEMPLATE_VIS param_type
34 {
35 result_type __m_;
36 result_type __n_;
37 public:
38 typedef fisher_f_distribution distribution_type;
39
40 _LIBCPP_INLINE_VISIBILITY
41 explicit param_type(result_type __m = 1, result_type __n = 1)
42 : __m_(__m), __n_(__n) {}
43
44 _LIBCPP_INLINE_VISIBILITY
45 result_type m() const {return __m_;}
46 _LIBCPP_INLINE_VISIBILITY
47 result_type n() const {return __n_;}
48
49 friend _LIBCPP_INLINE_VISIBILITY
50 bool operator==(const param_type& __x, const param_type& __y)
51 {return __x.__m_ == __y.__m_ && __x.__n_ == __y.__n_;}
52 friend _LIBCPP_INLINE_VISIBILITY
53 bool operator!=(const param_type& __x, const param_type& __y)
54 {return !(__x == __y);}
55 };
56
57private:
58 param_type __p_;
59
60public:
61 // constructor and reset functions
62#ifndef _LIBCPP_CXX03_LANG
63 _LIBCPP_INLINE_VISIBILITY
64 fisher_f_distribution() : fisher_f_distribution(1) {}
65 _LIBCPP_INLINE_VISIBILITY
66 explicit fisher_f_distribution(result_type __m, result_type __n = 1)
67 : __p_(param_type(__m, __n)) {}
68#else
69 _LIBCPP_INLINE_VISIBILITY
70 explicit fisher_f_distribution(result_type __m = 1, result_type __n = 1)
71 : __p_(param_type(__m, __n)) {}
72#endif
73 _LIBCPP_INLINE_VISIBILITY
74 explicit fisher_f_distribution(const param_type& __p)
75 : __p_(__p) {}
76 _LIBCPP_INLINE_VISIBILITY
77 void reset() {}
78
79 // generating functions
80 template<class _URNG>
81 _LIBCPP_INLINE_VISIBILITY
82 result_type operator()(_URNG& __g)
83 {return (*this)(__g, __p_);}
84 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
85
86 // property functions
87 _LIBCPP_INLINE_VISIBILITY
88 result_type m() const {return __p_.m();}
89 _LIBCPP_INLINE_VISIBILITY
90 result_type n() const {return __p_.n();}
91
92 _LIBCPP_INLINE_VISIBILITY
93 param_type param() const {return __p_;}
94 _LIBCPP_INLINE_VISIBILITY
95 void param(const param_type& __p) {__p_ = __p;}
96
97 _LIBCPP_INLINE_VISIBILITY
98 result_type min() const {return 0;}
99 _LIBCPP_INLINE_VISIBILITY
100 result_type max() const {return numeric_limits<result_type>::infinity();}
101
102 friend _LIBCPP_INLINE_VISIBILITY
103 bool operator==(const fisher_f_distribution& __x,
104 const fisher_f_distribution& __y)
105 {return __x.__p_ == __y.__p_;}
106 friend _LIBCPP_INLINE_VISIBILITY
107 bool operator!=(const fisher_f_distribution& __x,
108 const fisher_f_distribution& __y)
109 {return !(__x == __y);}
110};
111
112template <class _RealType>
113template<class _URNG>
114_RealType
115fisher_f_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
116{
117 gamma_distribution<result_type> __gdm(__p.m() * result_type(.5));
118 gamma_distribution<result_type> __gdn(__p.n() * result_type(.5));
119 return __p.n() * __gdm(__g) / (__p.m() * __gdn(__g));
120}
121
122template <class _CharT, class _Traits, class _RT>
123basic_ostream<_CharT, _Traits>&
124operator<<(basic_ostream<_CharT, _Traits>& __os,
125 const fisher_f_distribution<_RT>& __x)
126{
127 __save_flags<_CharT, _Traits> __lx(__os);
128 typedef basic_ostream<_CharT, _Traits> _OStream;
129 __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
130 _OStream::scientific);
131 _CharT __sp = __os.widen(' ');
132 __os.fill(__sp);
133 __os << __x.m() << __sp << __x.n();
134 return __os;
135}
136
137template <class _CharT, class _Traits, class _RT>
138basic_istream<_CharT, _Traits>&
139operator>>(basic_istream<_CharT, _Traits>& __is,
140 fisher_f_distribution<_RT>& __x)
141{
142 typedef fisher_f_distribution<_RT> _Eng;
143 typedef typename _Eng::result_type result_type;
144 typedef typename _Eng::param_type param_type;
145 __save_flags<_CharT, _Traits> __lx(__is);
146 typedef basic_istream<_CharT, _Traits> _Istream;
147 __is.flags(_Istream::dec | _Istream::skipws);
148 result_type __m;
149 result_type __n;
150 __is >> __m >> __n;
151 if (!__is.fail())
152 __x.param(param_type(__m, __n));
153 return __is;
154}
155
156_LIBCPP_END_NAMESPACE_STD
157
158_LIBCPP_POP_MACROS
159
160#endif // _LIBCPP___RANDOM_FISHER_F_DISTRIBUTION_H
lib/libcxx/include/__random/gamma_distribution.h created+213
......@@ -0,0 +1,213 @@
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_GAMMA_DISTRIBUTION_H
10#define _LIBCPP___RANDOM_GAMMA_DISTRIBUTION_H
11
12#include <__config>
13#include <__random/exponential_distribution.h>
14#include <__random/uniform_real_distribution.h>
15#include <cmath>
16#include <iosfwd>
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
28template<class _RealType = double>
29class _LIBCPP_TEMPLATE_VIS gamma_distribution
30{
31public:
32 // types
33 typedef _RealType result_type;
34
35 class _LIBCPP_TEMPLATE_VIS param_type
36 {
37 result_type __alpha_;
38 result_type __beta_;
39 public:
40 typedef gamma_distribution distribution_type;
41
42 _LIBCPP_INLINE_VISIBILITY
43 explicit param_type(result_type __alpha = 1, result_type __beta = 1)
44 : __alpha_(__alpha), __beta_(__beta) {}
45
46 _LIBCPP_INLINE_VISIBILITY
47 result_type alpha() const {return __alpha_;}
48 _LIBCPP_INLINE_VISIBILITY
49 result_type beta() const {return __beta_;}
50
51 friend _LIBCPP_INLINE_VISIBILITY
52 bool operator==(const param_type& __x, const param_type& __y)
53 {return __x.__alpha_ == __y.__alpha_ && __x.__beta_ == __y.__beta_;}
54 friend _LIBCPP_INLINE_VISIBILITY
55 bool operator!=(const param_type& __x, const param_type& __y)
56 {return !(__x == __y);}
57 };
58
59private:
60 param_type __p_;
61
62public:
63 // constructors and reset functions
64#ifndef _LIBCPP_CXX03_LANG
65 _LIBCPP_INLINE_VISIBILITY
66 gamma_distribution() : gamma_distribution(1) {}
67 _LIBCPP_INLINE_VISIBILITY
68 explicit gamma_distribution(result_type __alpha, result_type __beta = 1)
69 : __p_(param_type(__alpha, __beta)) {}
70#else
71 _LIBCPP_INLINE_VISIBILITY
72 explicit gamma_distribution(result_type __alpha = 1,
73 result_type __beta = 1)
74 : __p_(param_type(__alpha, __beta)) {}
75#endif
76 _LIBCPP_INLINE_VISIBILITY
77 explicit gamma_distribution(const param_type& __p)
78 : __p_(__p) {}
79 _LIBCPP_INLINE_VISIBILITY
80 void reset() {}
81
82 // generating functions
83 template<class _URNG>
84 _LIBCPP_INLINE_VISIBILITY
85 result_type operator()(_URNG& __g)
86 {return (*this)(__g, __p_);}
87 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
88
89 // property functions
90 _LIBCPP_INLINE_VISIBILITY
91 result_type alpha() const {return __p_.alpha();}
92 _LIBCPP_INLINE_VISIBILITY
93 result_type beta() const {return __p_.beta();}
94
95 _LIBCPP_INLINE_VISIBILITY
96 param_type param() const {return __p_;}
97 _LIBCPP_INLINE_VISIBILITY
98 void param(const param_type& __p) {__p_ = __p;}
99
100 _LIBCPP_INLINE_VISIBILITY
101 result_type min() const {return 0;}
102 _LIBCPP_INLINE_VISIBILITY
103 result_type max() const {return numeric_limits<result_type>::infinity();}
104
105 friend _LIBCPP_INLINE_VISIBILITY
106 bool operator==(const gamma_distribution& __x,
107 const gamma_distribution& __y)
108 {return __x.__p_ == __y.__p_;}
109 friend _LIBCPP_INLINE_VISIBILITY
110 bool operator!=(const gamma_distribution& __x,
111 const gamma_distribution& __y)
112 {return !(__x == __y);}
113};
114
115template <class _RealType>
116template<class _URNG>
117_RealType
118gamma_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
119{
120 result_type __a = __p.alpha();
121 uniform_real_distribution<result_type> __gen(0, 1);
122 exponential_distribution<result_type> __egen;
123 result_type __x;
124 if (__a == 1)
125 __x = __egen(__g);
126 else if (__a > 1)
127 {
128 const result_type __b = __a - 1;
129 const result_type __c = 3 * __a - result_type(0.75);
130 while (true)
131 {
132 const result_type __u = __gen(__g);
133 const result_type __v = __gen(__g);
134 const result_type __w = __u * (1 - __u);
135 if (__w != 0)
136 {
137 const result_type __y = _VSTD::sqrt(__c / __w) *
138 (__u - result_type(0.5));
139 __x = __b + __y;
140 if (__x >= 0)
141 {
142 const result_type __z = 64 * __w * __w * __w * __v * __v;
143 if (__z <= 1 - 2 * __y * __y / __x)
144 break;
145 if (_VSTD::log(__z) <= 2 * (__b * _VSTD::log(__x / __b) - __y))
146 break;
147 }
148 }
149 }
150 }
151 else // __a < 1
152 {
153 while (true)
154 {
155 const result_type __u = __gen(__g);
156 const result_type __es = __egen(__g);
157 if (__u <= 1 - __a)
158 {
159 __x = _VSTD::pow(__u, 1 / __a);
160 if (__x <= __es)
161 break;
162 }
163 else
164 {
165 const result_type __e = -_VSTD::log((1-__u)/__a);
166 __x = _VSTD::pow(1 - __a + __a * __e, 1 / __a);
167 if (__x <= __e + __es)
168 break;
169 }
170 }
171 }
172 return __x * __p.beta();
173}
174
175template <class _CharT, class _Traits, class _RT>
176basic_ostream<_CharT, _Traits>&
177operator<<(basic_ostream<_CharT, _Traits>& __os,
178 const gamma_distribution<_RT>& __x)
179{
180 __save_flags<_CharT, _Traits> __lx(__os);
181 typedef basic_ostream<_CharT, _Traits> _OStream;
182 __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
183 _OStream::scientific);
184 _CharT __sp = __os.widen(' ');
185 __os.fill(__sp);
186 __os << __x.alpha() << __sp << __x.beta();
187 return __os;
188}
189
190template <class _CharT, class _Traits, class _RT>
191basic_istream<_CharT, _Traits>&
192operator>>(basic_istream<_CharT, _Traits>& __is,
193 gamma_distribution<_RT>& __x)
194{
195 typedef gamma_distribution<_RT> _Eng;
196 typedef typename _Eng::result_type result_type;
197 typedef typename _Eng::param_type param_type;
198 __save_flags<_CharT, _Traits> __lx(__is);
199 typedef basic_istream<_CharT, _Traits> _Istream;
200 __is.flags(_Istream::dec | _Istream::skipws);
201 result_type __alpha;
202 result_type __beta;
203 __is >> __alpha >> __beta;
204 if (!__is.fail())
205 __x.param(param_type(__alpha, __beta));
206 return __is;
207}
208
209_LIBCPP_END_NAMESPACE_STD
210
211_LIBCPP_POP_MACROS
212
213#endif // _LIBCPP___RANDOM_GAMMA_DISTRIBUTION_H
lib/libcxx/include/__random/generate_canonical.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___RANDOM_GENERATE_CANONICAL_H
10#define _LIBCPP___RANDOM_GENERATE_CANONICAL_H
11
12#include <__config>
13#include <__random/log2.h>
14#include <cstdint>
15#include <initializer_list>
16#include <limits>
17
18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
20#endif
21
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
25_LIBCPP_BEGIN_NAMESPACE_STD
26
27// generate_canonical
28
29template<class _RealType, size_t __bits, class _URNG>
30_RealType
31generate_canonical(_URNG& __g)
32{
33 const size_t _Dt = numeric_limits<_RealType>::digits;
34 const size_t __b = _Dt < __bits ? _Dt : __bits;
35#ifdef _LIBCPP_CXX03_LANG
36 const size_t __logR = __log2<uint64_t, _URNG::_Max - _URNG::_Min + uint64_t(1)>::value;
37#else
38 const size_t __logR = __log2<uint64_t, _URNG::max() - _URNG::min() + uint64_t(1)>::value;
39#endif
40 const size_t __k = __b / __logR + (__b % __logR != 0) + (__b == 0);
41 const _RealType _Rp = static_cast<_RealType>(_URNG::max() - _URNG::min()) + _RealType(1);
42 _RealType __base = _Rp;
43 _RealType _Sp = __g() - _URNG::min();
44 for (size_t __i = 1; __i < __k; ++__i, __base *= _Rp)
45 _Sp += (__g() - _URNG::min()) * __base;
46 return _Sp / __base;
47}
48
49_LIBCPP_END_NAMESPACE_STD
50
51_LIBCPP_POP_MACROS
52
53#endif // _LIBCPP___RANDOM_GENERATE_CANONICAL_H
lib/libcxx/include/__random/geometric_distribution.h created+141
......@@ -0,0 +1,141 @@
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_GEOMETRIC_DISTRIBUTION_H
10#define _LIBCPP___RANDOM_GEOMETRIC_DISTRIBUTION_H
11
12#include <__config>
13#include <__random/negative_binomial_distribution.h>
14#include <iosfwd>
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
26template<class _IntType = int>
27class _LIBCPP_TEMPLATE_VIS geometric_distribution
28{
29public:
30 // types
31 typedef _IntType result_type;
32
33 class _LIBCPP_TEMPLATE_VIS param_type
34 {
35 double __p_;
36 public:
37 typedef geometric_distribution distribution_type;
38
39 _LIBCPP_INLINE_VISIBILITY
40 explicit param_type(double __p = 0.5) : __p_(__p) {}
41
42 _LIBCPP_INLINE_VISIBILITY
43 double p() const {return __p_;}
44
45 friend _LIBCPP_INLINE_VISIBILITY
46 bool operator==(const param_type& __x, const param_type& __y)
47 {return __x.__p_ == __y.__p_;}
48 friend _LIBCPP_INLINE_VISIBILITY
49 bool operator!=(const param_type& __x, const param_type& __y)
50 {return !(__x == __y);}
51 };
52
53private:
54 param_type __p_;
55
56public:
57 // constructors and reset functions
58#ifndef _LIBCPP_CXX03_LANG
59 _LIBCPP_INLINE_VISIBILITY
60 geometric_distribution() : geometric_distribution(0.5) {}
61 _LIBCPP_INLINE_VISIBILITY
62 explicit geometric_distribution(double __p)
63 : __p_(__p) {}
64#else
65 _LIBCPP_INLINE_VISIBILITY
66 explicit geometric_distribution(double __p = 0.5)
67 : __p_(__p) {}
68#endif
69 _LIBCPP_INLINE_VISIBILITY
70 explicit geometric_distribution(const param_type& __p) : __p_(__p) {}
71 _LIBCPP_INLINE_VISIBILITY
72 void reset() {}
73
74 // generating functions
75 template<class _URNG>
76 _LIBCPP_INLINE_VISIBILITY
77 result_type operator()(_URNG& __g)
78 {return (*this)(__g, __p_);}
79 template<class _URNG>
80 _LIBCPP_INLINE_VISIBILITY
81 result_type operator()(_URNG& __g, const param_type& __p)
82 {return negative_binomial_distribution<result_type>(1, __p.p())(__g);}
83
84 // property functions
85 _LIBCPP_INLINE_VISIBILITY
86 double p() const {return __p_.p();}
87
88 _LIBCPP_INLINE_VISIBILITY
89 param_type param() const {return __p_;}
90 _LIBCPP_INLINE_VISIBILITY
91 void param(const param_type& __p) {__p_ = __p;}
92
93 _LIBCPP_INLINE_VISIBILITY
94 result_type min() const {return 0;}
95 _LIBCPP_INLINE_VISIBILITY
96 result_type max() const {return numeric_limits<result_type>::max();}
97
98 friend _LIBCPP_INLINE_VISIBILITY
99 bool operator==(const geometric_distribution& __x,
100 const geometric_distribution& __y)
101 {return __x.__p_ == __y.__p_;}
102 friend _LIBCPP_INLINE_VISIBILITY
103 bool operator!=(const geometric_distribution& __x,
104 const geometric_distribution& __y)
105 {return !(__x == __y);}
106};
107
108template <class _CharT, class _Traits, class _IntType>
109basic_ostream<_CharT, _Traits>&
110operator<<(basic_ostream<_CharT, _Traits>& __os,
111 const geometric_distribution<_IntType>& __x)
112{
113 __save_flags<_CharT, _Traits> __lx(__os);
114 typedef basic_ostream<_CharT, _Traits> _OStream;
115 __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
116 _OStream::scientific);
117 return __os << __x.p();
118}
119
120template <class _CharT, class _Traits, class _IntType>
121basic_istream<_CharT, _Traits>&
122operator>>(basic_istream<_CharT, _Traits>& __is,
123 geometric_distribution<_IntType>& __x)
124{
125 typedef geometric_distribution<_IntType> _Eng;
126 typedef typename _Eng::param_type param_type;
127 __save_flags<_CharT, _Traits> __lx(__is);
128 typedef basic_istream<_CharT, _Traits> _Istream;
129 __is.flags(_Istream::dec | _Istream::skipws);
130 double __p;
131 __is >> __p;
132 if (!__is.fail())
133 __x.param(param_type(__p));
134 return __is;
135}
136
137_LIBCPP_END_NAMESPACE_STD
138
139_LIBCPP_POP_MACROS
140
141#endif // _LIBCPP___RANDOM_GEOMETRIC_DISTRIBUTION_H
lib/libcxx/include/__random/independent_bits_engine.h created+271
......@@ -0,0 +1,271 @@
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_INDEPENDENT_BITS_ENGINE_H
10#define _LIBCPP___RANDOM_INDEPENDENT_BITS_ENGINE_H
11
12#include <__config>
13#include <__random/is_seed_sequence.h>
14#include <__random/log2.h>
15#include <__utility/move.h>
16#include <iosfwd>
17#include <limits>
18#include <type_traits>
19
20#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21#pragma GCC system_header
22#endif
23
24_LIBCPP_PUSH_MACROS
25#include <__undef_macros>
26
27_LIBCPP_BEGIN_NAMESPACE_STD
28
29template<class _Engine, size_t __w, class _UIntType>
30class _LIBCPP_TEMPLATE_VIS independent_bits_engine
31{
32 template <class _UInt, _UInt _R0, size_t _Wp, size_t _Mp>
33 class __get_n
34 {
35 static _LIBCPP_CONSTEXPR const size_t _Dt = numeric_limits<_UInt>::digits;
36 static _LIBCPP_CONSTEXPR const size_t _Np = _Wp / _Mp + (_Wp % _Mp != 0);
37 static _LIBCPP_CONSTEXPR const size_t _W0 = _Wp / _Np;
38 static _LIBCPP_CONSTEXPR const _UInt _Y0 = _W0 >= _Dt ? 0 : (_R0 >> _W0) << _W0;
39 public:
40 static _LIBCPP_CONSTEXPR const size_t value = _R0 - _Y0 > _Y0 / _Np ? _Np + 1 : _Np;
41 };
42public:
43 // types
44 typedef _UIntType result_type;
45
46private:
47 _Engine __e_;
48
49 static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits;
50 static_assert( 0 < __w, "independent_bits_engine invalid parameters");
51 static_assert(__w <= _Dt, "independent_bits_engine invalid parameters");
52
53 typedef typename _Engine::result_type _Engine_result_type;
54 typedef typename conditional
55 <
56 sizeof(_Engine_result_type) <= sizeof(result_type),
57 result_type,
58 _Engine_result_type
59 >::type _Working_result_type;
60#ifdef _LIBCPP_CXX03_LANG
61 static const _Working_result_type _Rp = _Engine::_Max - _Engine::_Min
62 + _Working_result_type(1);
63#else
64 static _LIBCPP_CONSTEXPR const _Working_result_type _Rp = _Engine::max() - _Engine::min()
65 + _Working_result_type(1);
66#endif
67 static _LIBCPP_CONSTEXPR const size_t __m = __log2<_Working_result_type, _Rp>::value;
68 static _LIBCPP_CONSTEXPR const size_t __n = __get_n<_Working_result_type, _Rp, __w, __m>::value;
69 static _LIBCPP_CONSTEXPR const size_t __w0 = __w / __n;
70 static _LIBCPP_CONSTEXPR const size_t __n0 = __n - __w % __n;
71 static _LIBCPP_CONSTEXPR const size_t _WDt = numeric_limits<_Working_result_type>::digits;
72 static _LIBCPP_CONSTEXPR const size_t _EDt = numeric_limits<_Engine_result_type>::digits;
73 static _LIBCPP_CONSTEXPR const _Working_result_type __y0 = __w0 >= _WDt ? 0 :
74 (_Rp >> __w0) << __w0;
75 static _LIBCPP_CONSTEXPR const _Working_result_type __y1 = __w0 >= _WDt - 1 ? 0 :
76 (_Rp >> (__w0+1)) << (__w0+1);
77 static _LIBCPP_CONSTEXPR const _Engine_result_type __mask0 = __w0 > 0 ?
78 _Engine_result_type(~0) >> (_EDt - __w0) :
79 _Engine_result_type(0);
80 static _LIBCPP_CONSTEXPR const _Engine_result_type __mask1 = __w0 < _EDt - 1 ?
81 _Engine_result_type(~0) >> (_EDt - (__w0 + 1)) :
82 _Engine_result_type(~0);
83public:
84 static _LIBCPP_CONSTEXPR const result_type _Min = 0;
85 static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) :
86 (result_type(1) << __w) - result_type(1);
87 static_assert(_Min < _Max, "independent_bits_engine invalid parameters");
88
89 // engine characteristics
90 _LIBCPP_INLINE_VISIBILITY
91 static _LIBCPP_CONSTEXPR result_type min() { return _Min; }
92 _LIBCPP_INLINE_VISIBILITY
93 static _LIBCPP_CONSTEXPR result_type max() { return _Max; }
94
95 // constructors and seeding functions
96 _LIBCPP_INLINE_VISIBILITY
97 independent_bits_engine() {}
98 _LIBCPP_INLINE_VISIBILITY
99 explicit independent_bits_engine(const _Engine& __e)
100 : __e_(__e) {}
101#ifndef _LIBCPP_CXX03_LANG
102 _LIBCPP_INLINE_VISIBILITY
103 explicit independent_bits_engine(_Engine&& __e)
104 : __e_(_VSTD::move(__e)) {}
105#endif // _LIBCPP_CXX03_LANG
106 _LIBCPP_INLINE_VISIBILITY
107 explicit independent_bits_engine(result_type __sd) : __e_(__sd) {}
108 template<class _Sseq>
109 _LIBCPP_INLINE_VISIBILITY
110 explicit independent_bits_engine(_Sseq& __q,
111 typename enable_if<__is_seed_sequence<_Sseq, independent_bits_engine>::value &&
112 !is_convertible<_Sseq, _Engine>::value>::type* = 0)
113 : __e_(__q) {}
114 _LIBCPP_INLINE_VISIBILITY
115 void seed() {__e_.seed();}
116 _LIBCPP_INLINE_VISIBILITY
117 void seed(result_type __sd) {__e_.seed(__sd);}
118 template<class _Sseq>
119 _LIBCPP_INLINE_VISIBILITY
120 typename enable_if
121 <
122 __is_seed_sequence<_Sseq, independent_bits_engine>::value,
123 void
124 >::type
125 seed(_Sseq& __q) {__e_.seed(__q);}
126
127 // generating functions
128 _LIBCPP_INLINE_VISIBILITY
129 result_type operator()() {return __eval(integral_constant<bool, _Rp != 0>());}
130 _LIBCPP_INLINE_VISIBILITY
131 void discard(unsigned long long __z) {for (; __z; --__z) operator()();}
132
133 // property functions
134 _LIBCPP_INLINE_VISIBILITY
135 const _Engine& base() const _NOEXCEPT {return __e_;}
136
137 template<class _Eng, size_t _Wp, class _UInt>
138 friend
139 bool
140 operator==(
141 const independent_bits_engine<_Eng, _Wp, _UInt>& __x,
142 const independent_bits_engine<_Eng, _Wp, _UInt>& __y);
143
144 template<class _Eng, size_t _Wp, class _UInt>
145 friend
146 bool
147 operator!=(
148 const independent_bits_engine<_Eng, _Wp, _UInt>& __x,
149 const independent_bits_engine<_Eng, _Wp, _UInt>& __y);
150
151 template <class _CharT, class _Traits,
152 class _Eng, size_t _Wp, class _UInt>
153 friend
154 basic_ostream<_CharT, _Traits>&
155 operator<<(basic_ostream<_CharT, _Traits>& __os,
156 const independent_bits_engine<_Eng, _Wp, _UInt>& __x);
157
158 template <class _CharT, class _Traits,
159 class _Eng, size_t _Wp, class _UInt>
160 friend
161 basic_istream<_CharT, _Traits>&
162 operator>>(basic_istream<_CharT, _Traits>& __is,
163 independent_bits_engine<_Eng, _Wp, _UInt>& __x);
164
165private:
166 _LIBCPP_INLINE_VISIBILITY
167 result_type __eval(false_type);
168 result_type __eval(true_type);
169
170 template <size_t __count>
171 _LIBCPP_INLINE_VISIBILITY
172 static
173 typename enable_if
174 <
175 __count < _Dt,
176 result_type
177 >::type
178 __lshift(result_type __x) {return __x << __count;}
179
180 template <size_t __count>
181 _LIBCPP_INLINE_VISIBILITY
182 static
183 typename enable_if
184 <
185 (__count >= _Dt),
186 result_type
187 >::type
188 __lshift(result_type) {return result_type(0);}
189};
190
191template<class _Engine, size_t __w, class _UIntType>
192inline
193_UIntType
194independent_bits_engine<_Engine, __w, _UIntType>::__eval(false_type)
195{
196 return static_cast<result_type>(__e_() & __mask0);
197}
198
199template<class _Engine, size_t __w, class _UIntType>
200_UIntType
201independent_bits_engine<_Engine, __w, _UIntType>::__eval(true_type)
202{
203 result_type _Sp = 0;
204 for (size_t __k = 0; __k < __n0; ++__k)
205 {
206 _Engine_result_type __u;
207 do
208 {
209 __u = __e_() - _Engine::min();
210 } while (__u >= __y0);
211 _Sp = static_cast<result_type>(__lshift<__w0>(_Sp) + (__u & __mask0));
212 }
213 for (size_t __k = __n0; __k < __n; ++__k)
214 {
215 _Engine_result_type __u;
216 do
217 {
218 __u = __e_() - _Engine::min();
219 } while (__u >= __y1);
220 _Sp = static_cast<result_type>(__lshift<__w0+1>(_Sp) + (__u & __mask1));
221 }
222 return _Sp;
223}
224
225template<class _Eng, size_t _Wp, class _UInt>
226inline _LIBCPP_INLINE_VISIBILITY
227bool
228operator==(
229 const independent_bits_engine<_Eng, _Wp, _UInt>& __x,
230 const independent_bits_engine<_Eng, _Wp, _UInt>& __y)
231{
232 return __x.base() == __y.base();
233}
234
235template<class _Eng, size_t _Wp, class _UInt>
236inline _LIBCPP_INLINE_VISIBILITY
237bool
238operator!=(
239 const independent_bits_engine<_Eng, _Wp, _UInt>& __x,
240 const independent_bits_engine<_Eng, _Wp, _UInt>& __y)
241{
242 return !(__x == __y);
243}
244
245template <class _CharT, class _Traits,
246 class _Eng, size_t _Wp, class _UInt>
247basic_ostream<_CharT, _Traits>&
248operator<<(basic_ostream<_CharT, _Traits>& __os,
249 const independent_bits_engine<_Eng, _Wp, _UInt>& __x)
250{
251 return __os << __x.base();
252}
253
254template <class _CharT, class _Traits,
255 class _Eng, size_t _Wp, class _UInt>
256basic_istream<_CharT, _Traits>&
257operator>>(basic_istream<_CharT, _Traits>& __is,
258 independent_bits_engine<_Eng, _Wp, _UInt>& __x)
259{
260 _Eng __e;
261 __is >> __e;
262 if (!__is.fail())
263 __x.__e_ = __e;
264 return __is;
265}
266
267_LIBCPP_END_NAMESPACE_STD
268
269_LIBCPP_POP_MACROS
270
271#endif // _LIBCPP___RANDOM_INDEPENDENT_BITS_ENGINE_H
lib/libcxx/include/__random/is_seed_sequence.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___RANDOM_IS_SEED_SEQUENCE_H
10#define _LIBCPP___RANDOM_IS_SEED_SEQUENCE_H
11
12#include <__config>
13#include <type_traits>
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 _Sseq, class _Engine>
22struct __is_seed_sequence
23{
24 static _LIBCPP_CONSTEXPR const bool value =
25 !is_convertible<_Sseq, typename _Engine::result_type>::value &&
26 !is_same<typename remove_cv<_Sseq>::type, _Engine>::value;
27};
28
29_LIBCPP_END_NAMESPACE_STD
30
31#endif // _LIBCPP___RANDOM_IS_SEED_SEQUENCE_H
lib/libcxx/include/__random/knuth_b.h created+26
......@@ -0,0 +1,26 @@
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_KNUTH_B_H
10#define _LIBCPP___RANDOM_KNUTH_B_H
11
12#include <__config>
13#include <__random/linear_congruential_engine.h>
14#include <__random/shuffle_order_engine.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
22typedef shuffle_order_engine<minstd_rand0, 256> knuth_b;
23
24_LIBCPP_END_NAMESPACE_STD
25
26#endif // _LIBCPP___RANDOM_KNUTH_B_H
lib/libcxx/include/__random/linear_congruential_engine.h created+398
......@@ -0,0 +1,398 @@
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_LINEAR_CONGRUENTIAL_ENGINE_H
10#define _LIBCPP___RANDOM_LINEAR_CONGRUENTIAL_ENGINE_H
11
12#include <__config>
13#include <__random/is_seed_sequence.h>
14#include <cstdint>
15#include <iosfwd>
16#include <type_traits>
17
18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
20#endif
21
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
25_LIBCPP_BEGIN_NAMESPACE_STD
26
27template <unsigned long long __a, unsigned long long __c,
28 unsigned long long __m, unsigned long long _Mp,
29 bool _MightOverflow = (__a != 0 && __m != 0 && __m-1 > (_Mp-__c)/__a),
30 bool _OverflowOK = ((__m | (__m-1)) > __m), // m = 2^n
31 bool _SchrageOK = (__a != 0 && __m != 0 && __m % __a <= __m / __a)> // r <= q
32struct __lce_alg_picker
33{
34 static_assert(__a != 0 || __m != 0 || !_MightOverflow || _OverflowOK || _SchrageOK,
35 "The current values of a, c, and m cannot generate a number "
36 "within bounds of linear_congruential_engine.");
37
38 static _LIBCPP_CONSTEXPR const bool __use_schrage = _MightOverflow &&
39 !_OverflowOK &&
40 _SchrageOK;
41};
42
43template <unsigned long long __a, unsigned long long __c,
44 unsigned long long __m, unsigned long long _Mp,
45 bool _UseSchrage = __lce_alg_picker<__a, __c, __m, _Mp>::__use_schrage>
46struct __lce_ta;
47
48// 64
49
50template <unsigned long long __a, unsigned long long __c, unsigned long long __m>
51struct __lce_ta<__a, __c, __m, (unsigned long long)(~0), true>
52{
53 typedef unsigned long long result_type;
54 _LIBCPP_INLINE_VISIBILITY
55 static result_type next(result_type __x)
56 {
57 // Schrage's algorithm
58 const result_type __q = __m / __a;
59 const result_type __r = __m % __a;
60 const result_type __t0 = __a * (__x % __q);
61 const result_type __t1 = __r * (__x / __q);
62 __x = __t0 + (__t0 < __t1) * __m - __t1;
63 __x += __c - (__x >= __m - __c) * __m;
64 return __x;
65 }
66};
67
68template <unsigned long long __a, unsigned long long __m>
69struct __lce_ta<__a, 0, __m, (unsigned long long)(~0), true>
70{
71 typedef unsigned long long result_type;
72 _LIBCPP_INLINE_VISIBILITY
73 static result_type next(result_type __x)
74 {
75 // Schrage's algorithm
76 const result_type __q = __m / __a;
77 const result_type __r = __m % __a;
78 const result_type __t0 = __a * (__x % __q);
79 const result_type __t1 = __r * (__x / __q);
80 __x = __t0 + (__t0 < __t1) * __m - __t1;
81 return __x;
82 }
83};
84
85template <unsigned long long __a, unsigned long long __c, unsigned long long __m>
86struct __lce_ta<__a, __c, __m, (unsigned long long)(~0), false>
87{
88 typedef unsigned long long result_type;
89 _LIBCPP_INLINE_VISIBILITY
90 static result_type next(result_type __x)
91 {
92 return (__a * __x + __c) % __m;
93 }
94};
95
96template <unsigned long long __a, unsigned long long __c>
97struct __lce_ta<__a, __c, 0, (unsigned long long)(~0), false>
98{
99 typedef unsigned long long result_type;
100 _LIBCPP_INLINE_VISIBILITY
101 static result_type next(result_type __x)
102 {
103 return __a * __x + __c;
104 }
105};
106
107// 32
108
109template <unsigned long long _Ap, unsigned long long _Cp, unsigned long long _Mp>
110struct __lce_ta<_Ap, _Cp, _Mp, unsigned(~0), true>
111{
112 typedef unsigned result_type;
113 _LIBCPP_INLINE_VISIBILITY
114 static result_type next(result_type __x)
115 {
116 const result_type __a = static_cast<result_type>(_Ap);
117 const result_type __c = static_cast<result_type>(_Cp);
118 const result_type __m = static_cast<result_type>(_Mp);
119 // Schrage's algorithm
120 const result_type __q = __m / __a;
121 const result_type __r = __m % __a;
122 const result_type __t0 = __a * (__x % __q);
123 const result_type __t1 = __r * (__x / __q);
124 __x = __t0 + (__t0 < __t1) * __m - __t1;
125 __x += __c - (__x >= __m - __c) * __m;
126 return __x;
127 }
128};
129
130template <unsigned long long _Ap, unsigned long long _Mp>
131struct __lce_ta<_Ap, 0, _Mp, unsigned(~0), true>
132{
133 typedef unsigned result_type;
134 _LIBCPP_INLINE_VISIBILITY
135 static result_type next(result_type __x)
136 {
137 const result_type __a = static_cast<result_type>(_Ap);
138 const result_type __m = static_cast<result_type>(_Mp);
139 // Schrage's algorithm
140 const result_type __q = __m / __a;
141 const result_type __r = __m % __a;
142 const result_type __t0 = __a * (__x % __q);
143 const result_type __t1 = __r * (__x / __q);
144 __x = __t0 + (__t0 < __t1) * __m - __t1;
145 return __x;
146 }
147};
148
149template <unsigned long long _Ap, unsigned long long _Cp, unsigned long long _Mp>
150struct __lce_ta<_Ap, _Cp, _Mp, unsigned(~0), false>
151{
152 typedef unsigned result_type;
153 _LIBCPP_INLINE_VISIBILITY
154 static result_type next(result_type __x)
155 {
156 const result_type __a = static_cast<result_type>(_Ap);
157 const result_type __c = static_cast<result_type>(_Cp);
158 const result_type __m = static_cast<result_type>(_Mp);
159 return (__a * __x + __c) % __m;
160 }
161};
162
163template <unsigned long long _Ap, unsigned long long _Cp>
164struct __lce_ta<_Ap, _Cp, 0, unsigned(~0), false>
165{
166 typedef unsigned result_type;
167 _LIBCPP_INLINE_VISIBILITY
168 static result_type next(result_type __x)
169 {
170 const result_type __a = static_cast<result_type>(_Ap);
171 const result_type __c = static_cast<result_type>(_Cp);
172 return __a * __x + __c;
173 }
174};
175
176// 16
177
178template <unsigned long long __a, unsigned long long __c, unsigned long long __m, bool __b>
179struct __lce_ta<__a, __c, __m, (unsigned short)(~0), __b>
180{
181 typedef unsigned short result_type;
182 _LIBCPP_INLINE_VISIBILITY
183 static result_type next(result_type __x)
184 {
185 return static_cast<result_type>(__lce_ta<__a, __c, __m, unsigned(~0)>::next(__x));
186 }
187};
188
189template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
190class _LIBCPP_TEMPLATE_VIS linear_congruential_engine;
191
192template <class _CharT, class _Traits,
193 class _Up, _Up _Ap, _Up _Cp, _Up _Np>
194_LIBCPP_INLINE_VISIBILITY
195basic_ostream<_CharT, _Traits>&
196operator<<(basic_ostream<_CharT, _Traits>& __os,
197 const linear_congruential_engine<_Up, _Ap, _Cp, _Np>&);
198
199template <class _CharT, class _Traits,
200 class _Up, _Up _Ap, _Up _Cp, _Up _Np>
201basic_istream<_CharT, _Traits>&
202operator>>(basic_istream<_CharT, _Traits>& __is,
203 linear_congruential_engine<_Up, _Ap, _Cp, _Np>& __x);
204
205template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
206class _LIBCPP_TEMPLATE_VIS linear_congruential_engine
207{
208public:
209 // types
210 typedef _UIntType result_type;
211
212private:
213 result_type __x_;
214
215 static _LIBCPP_CONSTEXPR const result_type _Mp = result_type(~0);
216
217 static_assert(__m == 0 || __a < __m, "linear_congruential_engine invalid parameters");
218 static_assert(__m == 0 || __c < __m, "linear_congruential_engine invalid parameters");
219 static_assert(is_unsigned<_UIntType>::value, "_UIntType must be unsigned type");
220public:
221 static _LIBCPP_CONSTEXPR const result_type _Min = __c == 0u ? 1u: 0u;
222 static _LIBCPP_CONSTEXPR const result_type _Max = __m - 1u;
223 static_assert(_Min < _Max, "linear_congruential_engine invalid parameters");
224
225 // engine characteristics
226 static _LIBCPP_CONSTEXPR const result_type multiplier = __a;
227 static _LIBCPP_CONSTEXPR const result_type increment = __c;
228 static _LIBCPP_CONSTEXPR const result_type modulus = __m;
229 _LIBCPP_INLINE_VISIBILITY
230 static _LIBCPP_CONSTEXPR result_type min() {return _Min;}
231 _LIBCPP_INLINE_VISIBILITY
232 static _LIBCPP_CONSTEXPR result_type max() {return _Max;}
233 static _LIBCPP_CONSTEXPR const result_type default_seed = 1u;
234
235 // constructors and seeding functions
236#ifndef _LIBCPP_CXX03_LANG
237 _LIBCPP_INLINE_VISIBILITY
238 linear_congruential_engine() : linear_congruential_engine(default_seed) {}
239 _LIBCPP_INLINE_VISIBILITY
240 explicit linear_congruential_engine(result_type __s) { seed(__s); }
241#else
242 _LIBCPP_INLINE_VISIBILITY
243 explicit linear_congruential_engine(result_type __s = default_seed) {
244 seed(__s);
245 }
246#endif
247 template<class _Sseq>
248 _LIBCPP_INLINE_VISIBILITY
249 explicit linear_congruential_engine(_Sseq& __q,
250 typename enable_if<__is_seed_sequence<_Sseq, linear_congruential_engine>::value>::type* = 0)
251 {seed(__q);}
252 _LIBCPP_INLINE_VISIBILITY
253 void seed(result_type __s = default_seed)
254 {seed(integral_constant<bool, __m == 0>(),
255 integral_constant<bool, __c == 0>(), __s);}
256 template<class _Sseq>
257 _LIBCPP_INLINE_VISIBILITY
258 typename enable_if
259 <
260 __is_seed_sequence<_Sseq, linear_congruential_engine>::value,
261 void
262 >::type
263 seed(_Sseq& __q)
264 {__seed(__q, integral_constant<unsigned,
265 1 + (__m == 0 ? (sizeof(result_type) * __CHAR_BIT__ - 1)/32
266 : (__m > 0x100000000ull))>());}
267
268 // generating functions
269 _LIBCPP_INLINE_VISIBILITY
270 result_type operator()()
271 {return __x_ = static_cast<result_type>(__lce_ta<__a, __c, __m, _Mp>::next(__x_));}
272 _LIBCPP_INLINE_VISIBILITY
273 void discard(unsigned long long __z) {for (; __z; --__z) operator()();}
274
275 friend _LIBCPP_INLINE_VISIBILITY
276 bool operator==(const linear_congruential_engine& __x,
277 const linear_congruential_engine& __y)
278 {return __x.__x_ == __y.__x_;}
279 friend _LIBCPP_INLINE_VISIBILITY
280 bool operator!=(const linear_congruential_engine& __x,
281 const linear_congruential_engine& __y)
282 {return !(__x == __y);}
283
284private:
285
286 _LIBCPP_INLINE_VISIBILITY
287 void seed(true_type, true_type, result_type __s) {__x_ = __s == 0 ? 1 : __s;}
288 _LIBCPP_INLINE_VISIBILITY
289 void seed(true_type, false_type, result_type __s) {__x_ = __s;}
290 _LIBCPP_INLINE_VISIBILITY
291 void seed(false_type, true_type, result_type __s) {__x_ = __s % __m == 0 ?
292 1 : __s % __m;}
293 _LIBCPP_INLINE_VISIBILITY
294 void seed(false_type, false_type, result_type __s) {__x_ = __s % __m;}
295
296 template<class _Sseq>
297 void __seed(_Sseq& __q, integral_constant<unsigned, 1>);
298 template<class _Sseq>
299 void __seed(_Sseq& __q, integral_constant<unsigned, 2>);
300
301 template <class _CharT, class _Traits,
302 class _Up, _Up _Ap, _Up _Cp, _Up _Np>
303 friend
304 basic_ostream<_CharT, _Traits>&
305 operator<<(basic_ostream<_CharT, _Traits>& __os,
306 const linear_congruential_engine<_Up, _Ap, _Cp, _Np>&);
307
308 template <class _CharT, class _Traits,
309 class _Up, _Up _Ap, _Up _Cp, _Up _Np>
310 friend
311 basic_istream<_CharT, _Traits>&
312 operator>>(basic_istream<_CharT, _Traits>& __is,
313 linear_congruential_engine<_Up, _Ap, _Cp, _Np>& __x);
314};
315
316template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
317 _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type
318 linear_congruential_engine<_UIntType, __a, __c, __m>::multiplier;
319
320template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
321 _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type
322 linear_congruential_engine<_UIntType, __a, __c, __m>::increment;
323
324template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
325 _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type
326 linear_congruential_engine<_UIntType, __a, __c, __m>::modulus;
327
328template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
329 _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type
330 linear_congruential_engine<_UIntType, __a, __c, __m>::default_seed;
331
332template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
333template<class _Sseq>
334void
335linear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q,
336 integral_constant<unsigned, 1>)
337{
338 const unsigned __k = 1;
339 uint32_t __ar[__k+3];
340 __q.generate(__ar, __ar + __k + 3);
341 result_type __s = static_cast<result_type>(__ar[3] % __m);
342 __x_ = __c == 0 && __s == 0 ? result_type(1) : __s;
343}
344
345template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
346template<class _Sseq>
347void
348linear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q,
349 integral_constant<unsigned, 2>)
350{
351 const unsigned __k = 2;
352 uint32_t __ar[__k+3];
353 __q.generate(__ar, __ar + __k + 3);
354 result_type __s = static_cast<result_type>((__ar[3] +
355 ((uint64_t)__ar[4] << 32)) % __m);
356 __x_ = __c == 0 && __s == 0 ? result_type(1) : __s;
357}
358
359template <class _CharT, class _Traits,
360 class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
361inline _LIBCPP_INLINE_VISIBILITY
362basic_ostream<_CharT, _Traits>&
363operator<<(basic_ostream<_CharT, _Traits>& __os,
364 const linear_congruential_engine<_UIntType, __a, __c, __m>& __x)
365{
366 __save_flags<_CharT, _Traits> __lx(__os);
367 typedef basic_ostream<_CharT, _Traits> _Ostream;
368 __os.flags(_Ostream::dec | _Ostream::left);
369 __os.fill(__os.widen(' '));
370 return __os << __x.__x_;
371}
372
373template <class _CharT, class _Traits,
374 class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
375basic_istream<_CharT, _Traits>&
376operator>>(basic_istream<_CharT, _Traits>& __is,
377 linear_congruential_engine<_UIntType, __a, __c, __m>& __x)
378{
379 __save_flags<_CharT, _Traits> __lx(__is);
380 typedef basic_istream<_CharT, _Traits> _Istream;
381 __is.flags(_Istream::dec | _Istream::skipws);
382 _UIntType __t;
383 __is >> __t;
384 if (!__is.fail())
385 __x.__x_ = __t;
386 return __is;
387}
388
389typedef linear_congruential_engine<uint_fast32_t, 16807, 0, 2147483647>
390 minstd_rand0;
391typedef linear_congruential_engine<uint_fast32_t, 48271, 0, 2147483647>
392 minstd_rand;
393
394_LIBCPP_END_NAMESPACE_STD
395
396_LIBCPP_POP_MACROS
397
398#endif // _LIBCPP___RANDOM_LINEAR_CONGRUENTIAL_ENGINE_H
lib/libcxx/include/__random/log2.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___RANDOM_LOG2_H
10#define _LIBCPP___RANDOM_LOG2_H
11
12#include <__config>
13#include <cstddef>
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
22template <class _UIntType, _UIntType _Xp, size_t _Rp>
23struct __log2_imp;
24
25template <unsigned long long _Xp, size_t _Rp>
26struct __log2_imp<unsigned long long, _Xp, _Rp>
27{
28 static const size_t value = _Xp & ((unsigned long long)(1) << _Rp) ? _Rp
29 : __log2_imp<unsigned long long, _Xp, _Rp - 1>::value;
30};
31
32template <unsigned long long _Xp>
33struct __log2_imp<unsigned long long, _Xp, 0>
34{
35 static const size_t value = 0;
36};
37
38template <size_t _Rp>
39struct __log2_imp<unsigned long long, 0, _Rp>
40{
41 static const size_t value = _Rp + 1;
42};
43
44#ifndef _LIBCPP_HAS_NO_INT128
45
46template <__uint128_t _Xp, size_t _Rp>
47struct __log2_imp<__uint128_t, _Xp, _Rp>
48{
49 static const size_t value = (_Xp >> 64)
50 ? (64 + __log2_imp<unsigned long long, (_Xp >> 64), 63>::value)
51 : __log2_imp<unsigned long long, _Xp, 63>::value;
52};
53
54#endif // _LIBCPP_HAS_NO_INT128
55
56template <class _UIntType, _UIntType _Xp>
57struct __log2
58{
59 static const size_t value = __log2_imp<
60#ifndef _LIBCPP_HAS_NO_INT128
61 typename conditional<
62 sizeof(_UIntType) <= sizeof(unsigned long long),
63 unsigned long long,
64 __uint128_t
65 >::type,
66#else
67 unsigned long long,
68#endif // _LIBCPP_HAS_NO_INT128
69 _Xp, sizeof(_UIntType) * __CHAR_BIT__ - 1>::value;
70};
71
72_LIBCPP_END_NAMESPACE_STD
73
74#endif // _LIBCPP___RANDOM_LOG2_H
lib/libcxx/include/__random/lognormal_distribution.h created+299
......@@ -0,0 +1,299 @@
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_LOGNORMAL_DISTRIBUTION_H
10#define _LIBCPP___RANDOM_LOGNORMAL_DISTRIBUTION_H
11
12#include <__config>
13#include <__random/normal_distribution.h>
14#include <cmath>
15#include <iosfwd>
16#include <limits>
17
18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
20#endif
21
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
25_LIBCPP_BEGIN_NAMESPACE_STD
26
27#ifdef _LIBCPP_ABI_OLD_LOGNORMAL_DISTRIBUTION
28
29template<class _RealType = double>
30class _LIBCPP_TEMPLATE_VIS lognormal_distribution
31{
32public:
33 // types
34 typedef _RealType result_type;
35
36 class _LIBCPP_TEMPLATE_VIS param_type
37 {
38 normal_distribution<result_type> __nd_;
39 public:
40 typedef lognormal_distribution distribution_type;
41
42 _LIBCPP_INLINE_VISIBILITY
43 explicit param_type(result_type __m = 0, result_type __s = 1)
44 : __nd_(__m, __s) {}
45
46 _LIBCPP_INLINE_VISIBILITY
47 result_type m() const {return __nd_.mean();}
48 _LIBCPP_INLINE_VISIBILITY
49 result_type s() const {return __nd_.stddev();}
50
51 friend _LIBCPP_INLINE_VISIBILITY
52 bool operator==(const param_type& __x, const param_type& __y)
53 {return __x.__nd_ == __y.__nd_;}
54 friend _LIBCPP_INLINE_VISIBILITY
55 bool operator!=(const param_type& __x, const param_type& __y)
56 {return !(__x == __y);}
57 friend class lognormal_distribution;
58
59 template <class _CharT, class _Traits, class _RT>
60 friend
61 basic_ostream<_CharT, _Traits>&
62 operator<<(basic_ostream<_CharT, _Traits>& __os,
63 const lognormal_distribution<_RT>& __x);
64
65 template <class _CharT, class _Traits, class _RT>
66 friend
67 basic_istream<_CharT, _Traits>&
68 operator>>(basic_istream<_CharT, _Traits>& __is,
69 lognormal_distribution<_RT>& __x);
70 };
71
72private:
73 param_type __p_;
74
75public:
76 // constructor and reset functions
77#ifndef _LIBCPP_CXX03_LANG
78 _LIBCPP_INLINE_VISIBILITY
79 lognormal_distribution() : lognormal_distribution(0) {}
80 _LIBCPP_INLINE_VISIBILITY
81 explicit lognormal_distribution(result_type __m, result_type __s = 1)
82 : __p_(param_type(__m, __s)) {}
83#else
84 _LIBCPP_INLINE_VISIBILITY
85 explicit lognormal_distribution(result_type __m = 0,
86 result_type __s = 1)
87 : __p_(param_type(__m, __s)) {}
88#endif
89 _LIBCPP_INLINE_VISIBILITY
90 explicit lognormal_distribution(const param_type& __p)
91 : __p_(__p) {}
92 _LIBCPP_INLINE_VISIBILITY
93 void reset() {__p_.__nd_.reset();}
94
95 // generating functions
96 template<class _URNG>
97 _LIBCPP_INLINE_VISIBILITY
98 result_type operator()(_URNG& __g)
99 {return (*this)(__g, __p_);}
100 template<class _URNG>
101 _LIBCPP_INLINE_VISIBILITY
102 result_type operator()(_URNG& __g, const param_type& __p)
103 {return _VSTD::exp(const_cast<normal_distribution<result_type>&>(__p.__nd_)(__g));}
104
105 // property functions
106 _LIBCPP_INLINE_VISIBILITY
107 result_type m() const {return __p_.m();}
108 _LIBCPP_INLINE_VISIBILITY
109 result_type s() const {return __p_.s();}
110
111 _LIBCPP_INLINE_VISIBILITY
112 param_type param() const {return __p_;}
113 _LIBCPP_INLINE_VISIBILITY
114 void param(const param_type& __p) {__p_ = __p;}
115
116 _LIBCPP_INLINE_VISIBILITY
117 result_type min() const {return 0;}
118 _LIBCPP_INLINE_VISIBILITY
119 result_type max() const {return numeric_limits<result_type>::infinity();}
120
121 friend _LIBCPP_INLINE_VISIBILITY
122 bool operator==(const lognormal_distribution& __x,
123 const lognormal_distribution& __y)
124 {return __x.__p_ == __y.__p_;}
125 friend _LIBCPP_INLINE_VISIBILITY
126 bool operator!=(const lognormal_distribution& __x,
127 const lognormal_distribution& __y)
128 {return !(__x == __y);}
129
130 template <class _CharT, class _Traits, class _RT>
131 friend
132 basic_ostream<_CharT, _Traits>&
133 operator<<(basic_ostream<_CharT, _Traits>& __os,
134 const lognormal_distribution<_RT>& __x);
135
136 template <class _CharT, class _Traits, class _RT>
137 friend
138 basic_istream<_CharT, _Traits>&
139 operator>>(basic_istream<_CharT, _Traits>& __is,
140 lognormal_distribution<_RT>& __x);
141};
142
143template <class _CharT, class _Traits, class _RT>
144inline _LIBCPP_INLINE_VISIBILITY
145basic_ostream<_CharT, _Traits>&
146operator<<(basic_ostream<_CharT, _Traits>& __os,
147 const lognormal_distribution<_RT>& __x)
148{
149 return __os << __x.__p_.__nd_;
150}
151
152template <class _CharT, class _Traits, class _RT>
153inline _LIBCPP_INLINE_VISIBILITY
154basic_istream<_CharT, _Traits>&
155operator>>(basic_istream<_CharT, _Traits>& __is,
156 lognormal_distribution<_RT>& __x)
157{
158 return __is >> __x.__p_.__nd_;
159}
160
161#else // _LIBCPP_ABI_OLD_LOGNORMAL_DISTRIBUTION
162
163template<class _RealType = double>
164class _LIBCPP_TEMPLATE_VIS lognormal_distribution
165{
166public:
167 // types
168 typedef _RealType result_type;
169
170 class _LIBCPP_TEMPLATE_VIS param_type
171 {
172 result_type __m_;
173 result_type __s_;
174 public:
175 typedef lognormal_distribution distribution_type;
176
177 _LIBCPP_INLINE_VISIBILITY
178 explicit param_type(result_type __m = 0, result_type __s = 1)
179 : __m_(__m), __s_(__s) {}
180
181 _LIBCPP_INLINE_VISIBILITY
182 result_type m() const {return __m_;}
183 _LIBCPP_INLINE_VISIBILITY
184 result_type s() const {return __s_;}
185
186 friend _LIBCPP_INLINE_VISIBILITY
187 bool operator==(const param_type& __x, const param_type& __y)
188 {return __x.__m_ == __y.__m_ && __x.__s_ == __y.__s_;}
189 friend _LIBCPP_INLINE_VISIBILITY
190 bool operator!=(const param_type& __x, const param_type& __y)
191 {return !(__x == __y);}
192 };
193
194private:
195 normal_distribution<result_type> __nd_;
196
197public:
198 // constructor and reset functions
199#ifndef _LIBCPP_CXX03_LANG
200 _LIBCPP_INLINE_VISIBILITY
201 lognormal_distribution() : lognormal_distribution(0) {}
202 _LIBCPP_INLINE_VISIBILITY
203 explicit lognormal_distribution(result_type __m, result_type __s = 1)
204 : __nd_(__m, __s) {}
205#else
206 _LIBCPP_INLINE_VISIBILITY
207 explicit lognormal_distribution(result_type __m = 0,
208 result_type __s = 1)
209 : __nd_(__m, __s) {}
210#endif
211 _LIBCPP_INLINE_VISIBILITY
212 explicit lognormal_distribution(const param_type& __p)
213 : __nd_(__p.m(), __p.s()) {}
214 _LIBCPP_INLINE_VISIBILITY
215 void reset() {__nd_.reset();}
216
217 // generating functions
218 template<class _URNG>
219 _LIBCPP_INLINE_VISIBILITY
220 result_type operator()(_URNG& __g)
221 {
222 return _VSTD::exp(__nd_(__g));
223 }
224
225 template<class _URNG>
226 _LIBCPP_INLINE_VISIBILITY
227 result_type operator()(_URNG& __g, const param_type& __p)
228 {
229 typename normal_distribution<result_type>::param_type __pn(__p.m(), __p.s());
230 return _VSTD::exp(__nd_(__g, __pn));
231 }
232
233 // property functions
234 _LIBCPP_INLINE_VISIBILITY
235 result_type m() const {return __nd_.mean();}
236 _LIBCPP_INLINE_VISIBILITY
237 result_type s() const {return __nd_.stddev();}
238
239 _LIBCPP_INLINE_VISIBILITY
240 param_type param() const {return param_type(__nd_.mean(), __nd_.stddev());}
241 _LIBCPP_INLINE_VISIBILITY
242 void param(const param_type& __p)
243 {
244 typename normal_distribution<result_type>::param_type __pn(__p.m(), __p.s());
245 __nd_.param(__pn);
246 }
247
248 _LIBCPP_INLINE_VISIBILITY
249 result_type min() const {return 0;}
250 _LIBCPP_INLINE_VISIBILITY
251 result_type max() const {return numeric_limits<result_type>::infinity();}
252
253 friend _LIBCPP_INLINE_VISIBILITY
254 bool operator==(const lognormal_distribution& __x,
255 const lognormal_distribution& __y)
256 {return __x.__nd_ == __y.__nd_;}
257 friend _LIBCPP_INLINE_VISIBILITY
258 bool operator!=(const lognormal_distribution& __x,
259 const lognormal_distribution& __y)
260 {return !(__x == __y);}
261
262 template <class _CharT, class _Traits, class _RT>
263 friend
264 basic_ostream<_CharT, _Traits>&
265 operator<<(basic_ostream<_CharT, _Traits>& __os,
266 const lognormal_distribution<_RT>& __x);
267
268 template <class _CharT, class _Traits, class _RT>
269 friend
270 basic_istream<_CharT, _Traits>&
271 operator>>(basic_istream<_CharT, _Traits>& __is,
272 lognormal_distribution<_RT>& __x);
273};
274
275template <class _CharT, class _Traits, class _RT>
276inline _LIBCPP_INLINE_VISIBILITY
277basic_ostream<_CharT, _Traits>&
278operator<<(basic_ostream<_CharT, _Traits>& __os,
279 const lognormal_distribution<_RT>& __x)
280{
281 return __os << __x.__nd_;
282}
283
284template <class _CharT, class _Traits, class _RT>
285inline _LIBCPP_INLINE_VISIBILITY
286basic_istream<_CharT, _Traits>&
287operator>>(basic_istream<_CharT, _Traits>& __is,
288 lognormal_distribution<_RT>& __x)
289{
290 return __is >> __x.__nd_;
291}
292
293#endif // _LIBCPP_ABI_OLD_LOGNORMAL_DISTRIBUTION
294
295_LIBCPP_END_NAMESPACE_STD
296
297_LIBCPP_POP_MACROS
298
299#endif // _LIBCPP___RANDOM_LOGNORMAL_DISTRIBUTION_H
lib/libcxx/include/__random/mersenne_twister_engine.h created+534
......@@ -0,0 +1,534 @@
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_MERSENNE_TWISTER_ENGINE_H
10#define _LIBCPP___RANDOM_MERSENNE_TWISTER_ENGINE_H
11
12#include <__algorithm/equal.h>
13#include <__algorithm/min.h>
14#include <__config>
15#include <__random/is_seed_sequence.h>
16#include <cstddef>
17#include <cstdint>
18#include <iosfwd>
19#include <limits>
20#include <type_traits>
21
22#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23#pragma GCC system_header
24#endif
25
26_LIBCPP_PUSH_MACROS
27#include <__undef_macros>
28
29_LIBCPP_BEGIN_NAMESPACE_STD
30
31template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
32 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
33 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
34class _LIBCPP_TEMPLATE_VIS mersenne_twister_engine;
35
36template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
37 _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
38 _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
39bool
40operator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
41 _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
42 const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
43 _Bp, _Tp, _Cp, _Lp, _Fp>& __y);
44
45template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
46 _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
47 _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
48_LIBCPP_INLINE_VISIBILITY
49bool
50operator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
51 _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
52 const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
53 _Bp, _Tp, _Cp, _Lp, _Fp>& __y);
54
55template <class _CharT, class _Traits,
56 class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
57 _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
58 _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
59basic_ostream<_CharT, _Traits>&
60operator<<(basic_ostream<_CharT, _Traits>& __os,
61 const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
62 _Bp, _Tp, _Cp, _Lp, _Fp>& __x);
63
64template <class _CharT, class _Traits,
65 class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
66 _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
67 _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
68basic_istream<_CharT, _Traits>&
69operator>>(basic_istream<_CharT, _Traits>& __is,
70 mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
71 _Bp, _Tp, _Cp, _Lp, _Fp>& __x);
72
73template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
74 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
75 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
76class _LIBCPP_TEMPLATE_VIS mersenne_twister_engine
77{
78public:
79 // types
80 typedef _UIntType result_type;
81
82private:
83 result_type __x_[__n];
84 size_t __i_;
85
86 static_assert( 0 < __m, "mersenne_twister_engine invalid parameters");
87 static_assert(__m <= __n, "mersenne_twister_engine invalid parameters");
88 static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits;
89 static_assert(__w <= _Dt, "mersenne_twister_engine invalid parameters");
90 static_assert( 2 <= __w, "mersenne_twister_engine invalid parameters");
91 static_assert(__r <= __w, "mersenne_twister_engine invalid parameters");
92 static_assert(__u <= __w, "mersenne_twister_engine invalid parameters");
93 static_assert(__s <= __w, "mersenne_twister_engine invalid parameters");
94 static_assert(__t <= __w, "mersenne_twister_engine invalid parameters");
95 static_assert(__l <= __w, "mersenne_twister_engine invalid parameters");
96public:
97 static _LIBCPP_CONSTEXPR const result_type _Min = 0;
98 static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) :
99 (result_type(1) << __w) - result_type(1);
100 static_assert(_Min < _Max, "mersenne_twister_engine invalid parameters");
101 static_assert(__a <= _Max, "mersenne_twister_engine invalid parameters");
102 static_assert(__b <= _Max, "mersenne_twister_engine invalid parameters");
103 static_assert(__c <= _Max, "mersenne_twister_engine invalid parameters");
104 static_assert(__d <= _Max, "mersenne_twister_engine invalid parameters");
105 static_assert(__f <= _Max, "mersenne_twister_engine invalid parameters");
106
107 // engine characteristics
108 static _LIBCPP_CONSTEXPR const size_t word_size = __w;
109 static _LIBCPP_CONSTEXPR const size_t state_size = __n;
110 static _LIBCPP_CONSTEXPR const size_t shift_size = __m;
111 static _LIBCPP_CONSTEXPR const size_t mask_bits = __r;
112 static _LIBCPP_CONSTEXPR const result_type xor_mask = __a;
113 static _LIBCPP_CONSTEXPR const size_t tempering_u = __u;
114 static _LIBCPP_CONSTEXPR const result_type tempering_d = __d;
115 static _LIBCPP_CONSTEXPR const size_t tempering_s = __s;
116 static _LIBCPP_CONSTEXPR const result_type tempering_b = __b;
117 static _LIBCPP_CONSTEXPR const size_t tempering_t = __t;
118 static _LIBCPP_CONSTEXPR const result_type tempering_c = __c;
119 static _LIBCPP_CONSTEXPR const size_t tempering_l = __l;
120 static _LIBCPP_CONSTEXPR const result_type initialization_multiplier = __f;
121 _LIBCPP_INLINE_VISIBILITY
122 static _LIBCPP_CONSTEXPR result_type min() { return _Min; }
123 _LIBCPP_INLINE_VISIBILITY
124 static _LIBCPP_CONSTEXPR result_type max() { return _Max; }
125 static _LIBCPP_CONSTEXPR const result_type default_seed = 5489u;
126
127 // constructors and seeding functions
128#ifndef _LIBCPP_CXX03_LANG
129 _LIBCPP_INLINE_VISIBILITY
130 mersenne_twister_engine() : mersenne_twister_engine(default_seed) {}
131 _LIBCPP_INLINE_VISIBILITY
132 explicit mersenne_twister_engine(result_type __sd) { seed(__sd); }
133#else
134 _LIBCPP_INLINE_VISIBILITY
135 explicit mersenne_twister_engine(result_type __sd = default_seed) {
136 seed(__sd);
137 }
138#endif
139 template<class _Sseq>
140 _LIBCPP_INLINE_VISIBILITY
141 explicit mersenne_twister_engine(_Sseq& __q,
142 typename enable_if<__is_seed_sequence<_Sseq, mersenne_twister_engine>::value>::type* = 0)
143 {seed(__q);}
144 void seed(result_type __sd = default_seed);
145 template<class _Sseq>
146 _LIBCPP_INLINE_VISIBILITY
147 typename enable_if
148 <
149 __is_seed_sequence<_Sseq, mersenne_twister_engine>::value,
150 void
151 >::type
152 seed(_Sseq& __q)
153 {__seed(__q, integral_constant<unsigned, 1 + (__w - 1) / 32>());}
154
155 // generating functions
156 result_type operator()();
157 _LIBCPP_INLINE_VISIBILITY
158 void discard(unsigned long long __z) {for (; __z; --__z) operator()();}
159
160 template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
161 _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
162 _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
163 friend
164 bool
165 operator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
166 _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
167 const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
168 _Bp, _Tp, _Cp, _Lp, _Fp>& __y);
169
170 template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
171 _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
172 _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
173 friend
174 bool
175 operator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
176 _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
177 const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
178 _Bp, _Tp, _Cp, _Lp, _Fp>& __y);
179
180 template <class _CharT, class _Traits,
181 class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
182 _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
183 _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
184 friend
185 basic_ostream<_CharT, _Traits>&
186 operator<<(basic_ostream<_CharT, _Traits>& __os,
187 const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
188 _Bp, _Tp, _Cp, _Lp, _Fp>& __x);
189
190 template <class _CharT, class _Traits,
191 class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
192 _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
193 _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
194 friend
195 basic_istream<_CharT, _Traits>&
196 operator>>(basic_istream<_CharT, _Traits>& __is,
197 mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
198 _Bp, _Tp, _Cp, _Lp, _Fp>& __x);
199private:
200
201 template<class _Sseq>
202 void __seed(_Sseq& __q, integral_constant<unsigned, 1>);
203 template<class _Sseq>
204 void __seed(_Sseq& __q, integral_constant<unsigned, 2>);
205
206 template <size_t __count>
207 _LIBCPP_INLINE_VISIBILITY
208 static
209 typename enable_if
210 <
211 __count < __w,
212 result_type
213 >::type
214 __lshift(result_type __x) {return (__x << __count) & _Max;}
215
216 template <size_t __count>
217 _LIBCPP_INLINE_VISIBILITY
218 static
219 typename enable_if
220 <
221 (__count >= __w),
222 result_type
223 >::type
224 __lshift(result_type) {return result_type(0);}
225
226 template <size_t __count>
227 _LIBCPP_INLINE_VISIBILITY
228 static
229 typename enable_if
230 <
231 __count < _Dt,
232 result_type
233 >::type
234 __rshift(result_type __x) {return __x >> __count;}
235
236 template <size_t __count>
237 _LIBCPP_INLINE_VISIBILITY
238 static
239 typename enable_if
240 <
241 (__count >= _Dt),
242 result_type
243 >::type
244 __rshift(result_type) {return result_type(0);}
245};
246
247template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
248 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
249 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
250 _LIBCPP_CONSTEXPR const size_t
251 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::word_size;
252
253template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
254 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
255 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
256 _LIBCPP_CONSTEXPR const size_t
257 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::state_size;
258
259template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
260 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
261 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
262 _LIBCPP_CONSTEXPR const size_t
263 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::shift_size;
264
265template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
266 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
267 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
268 _LIBCPP_CONSTEXPR const size_t
269 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::mask_bits;
270
271template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
272 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
273 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
274 _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type
275 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::xor_mask;
276
277template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
278 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
279 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
280 _LIBCPP_CONSTEXPR const size_t
281 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_u;
282
283template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
284 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
285 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
286 _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type
287 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_d;
288
289template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
290 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
291 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
292 _LIBCPP_CONSTEXPR const size_t
293 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_s;
294
295template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
296 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
297 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
298 _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type
299 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_b;
300
301template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
302 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
303 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
304 _LIBCPP_CONSTEXPR const size_t
305 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_t;
306
307template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
308 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
309 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
310 _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type
311 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_c;
312
313template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
314 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
315 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
316 _LIBCPP_CONSTEXPR const size_t
317 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_l;
318
319template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
320 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
321 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
322 _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type
323 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::initialization_multiplier;
324
325template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
326 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
327 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
328 _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type
329 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::default_seed;
330
331template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
332 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
333 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
334void
335mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b,
336 __t, __c, __l, __f>::seed(result_type __sd)
337 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
338{ // __w >= 2
339 __x_[0] = __sd & _Max;
340 for (size_t __i = 1; __i < __n; ++__i)
341 __x_[__i] = (__f * (__x_[__i-1] ^ __rshift<__w - 2>(__x_[__i-1])) + __i) & _Max;
342 __i_ = 0;
343}
344
345template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
346 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
347 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
348template<class _Sseq>
349void
350mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b,
351 __t, __c, __l, __f>::__seed(_Sseq& __q, integral_constant<unsigned, 1>)
352{
353 const unsigned __k = 1;
354 uint32_t __ar[__n * __k];
355 __q.generate(__ar, __ar + __n * __k);
356 for (size_t __i = 0; __i < __n; ++__i)
357 __x_[__i] = static_cast<result_type>(__ar[__i] & _Max);
358 const result_type __mask = __r == _Dt ? result_type(~0) :
359 (result_type(1) << __r) - result_type(1);
360 __i_ = 0;
361 if ((__x_[0] & ~__mask) == 0)
362 {
363 for (size_t __i = 1; __i < __n; ++__i)
364 if (__x_[__i] != 0)
365 return;
366 __x_[0] = result_type(1) << (__w - 1);
367 }
368}
369
370template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
371 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
372 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
373template<class _Sseq>
374void
375mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b,
376 __t, __c, __l, __f>::__seed(_Sseq& __q, integral_constant<unsigned, 2>)
377{
378 const unsigned __k = 2;
379 uint32_t __ar[__n * __k];
380 __q.generate(__ar, __ar + __n * __k);
381 for (size_t __i = 0; __i < __n; ++__i)
382 __x_[__i] = static_cast<result_type>(
383 (__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max);
384 const result_type __mask = __r == _Dt ? result_type(~0) :
385 (result_type(1) << __r) - result_type(1);
386 __i_ = 0;
387 if ((__x_[0] & ~__mask) == 0)
388 {
389 for (size_t __i = 1; __i < __n; ++__i)
390 if (__x_[__i] != 0)
391 return;
392 __x_[0] = result_type(1) << (__w - 1);
393 }
394}
395
396template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
397 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
398 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
399_UIntType
400mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b,
401 __t, __c, __l, __f>::operator()()
402{
403 const size_t __j = (__i_ + 1) % __n;
404 const result_type __mask = __r == _Dt ? result_type(~0) :
405 (result_type(1) << __r) - result_type(1);
406 const result_type _Yp = (__x_[__i_] & ~__mask) | (__x_[__j] & __mask);
407 const size_t __k = (__i_ + __m) % __n;
408 __x_[__i_] = __x_[__k] ^ __rshift<1>(_Yp) ^ (__a * (_Yp & 1));
409 result_type __z = __x_[__i_] ^ (__rshift<__u>(__x_[__i_]) & __d);
410 __i_ = __j;
411 __z ^= __lshift<__s>(__z) & __b;
412 __z ^= __lshift<__t>(__z) & __c;
413 return __z ^ __rshift<__l>(__z);
414}
415
416template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
417 _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
418 _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
419bool
420operator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
421 _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
422 const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
423 _Bp, _Tp, _Cp, _Lp, _Fp>& __y)
424{
425 if (__x.__i_ == __y.__i_)
426 return _VSTD::equal(__x.__x_, __x.__x_ + _Np, __y.__x_);
427 if (__x.__i_ == 0 || __y.__i_ == 0)
428 {
429 size_t __j = _VSTD::min(_Np - __x.__i_, _Np - __y.__i_);
430 if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + __x.__i_ + __j,
431 __y.__x_ + __y.__i_))
432 return false;
433 if (__x.__i_ == 0)
434 return _VSTD::equal(__x.__x_ + __j, __x.__x_ + _Np, __y.__x_);
435 return _VSTD::equal(__x.__x_, __x.__x_ + (_Np - __j), __y.__x_ + __j);
436 }
437 if (__x.__i_ < __y.__i_)
438 {
439 size_t __j = _Np - __y.__i_;
440 if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + (__x.__i_ + __j),
441 __y.__x_ + __y.__i_))
442 return false;
443 if (!_VSTD::equal(__x.__x_ + (__x.__i_ + __j), __x.__x_ + _Np,
444 __y.__x_))
445 return false;
446 return _VSTD::equal(__x.__x_, __x.__x_ + __x.__i_,
447 __y.__x_ + (_Np - (__x.__i_ + __j)));
448 }
449 size_t __j = _Np - __x.__i_;
450 if (!_VSTD::equal(__y.__x_ + __y.__i_, __y.__x_ + (__y.__i_ + __j),
451 __x.__x_ + __x.__i_))
452 return false;
453 if (!_VSTD::equal(__y.__x_ + (__y.__i_ + __j), __y.__x_ + _Np,
454 __x.__x_))
455 return false;
456 return _VSTD::equal(__y.__x_, __y.__x_ + __y.__i_,
457 __x.__x_ + (_Np - (__y.__i_ + __j)));
458}
459
460template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
461 _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
462 _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
463inline _LIBCPP_INLINE_VISIBILITY
464bool
465operator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
466 _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
467 const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
468 _Bp, _Tp, _Cp, _Lp, _Fp>& __y)
469{
470 return !(__x == __y);
471}
472
473template <class _CharT, class _Traits,
474 class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
475 _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
476 _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
477basic_ostream<_CharT, _Traits>&
478operator<<(basic_ostream<_CharT, _Traits>& __os,
479 const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
480 _Bp, _Tp, _Cp, _Lp, _Fp>& __x)
481{
482 __save_flags<_CharT, _Traits> __lx(__os);
483 typedef basic_ostream<_CharT, _Traits> _Ostream;
484 __os.flags(_Ostream::dec | _Ostream::left);
485 _CharT __sp = __os.widen(' ');
486 __os.fill(__sp);
487 __os << __x.__x_[__x.__i_];
488 for (size_t __j = __x.__i_ + 1; __j < _Np; ++__j)
489 __os << __sp << __x.__x_[__j];
490 for (size_t __j = 0; __j < __x.__i_; ++__j)
491 __os << __sp << __x.__x_[__j];
492 return __os;
493}
494
495template <class _CharT, class _Traits,
496 class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
497 _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
498 _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
499basic_istream<_CharT, _Traits>&
500operator>>(basic_istream<_CharT, _Traits>& __is,
501 mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
502 _Bp, _Tp, _Cp, _Lp, _Fp>& __x)
503{
504 __save_flags<_CharT, _Traits> __lx(__is);
505 typedef basic_istream<_CharT, _Traits> _Istream;
506 __is.flags(_Istream::dec | _Istream::skipws);
507 _UInt __t[_Np];
508 for (size_t __i = 0; __i < _Np; ++__i)
509 __is >> __t[__i];
510 if (!__is.fail())
511 {
512 for (size_t __i = 0; __i < _Np; ++__i)
513 __x.__x_[__i] = __t[__i];
514 __x.__i_ = 0;
515 }
516 return __is;
517}
518
519typedef mersenne_twister_engine<uint_fast32_t, 32, 624, 397, 31,
520 0x9908b0df, 11, 0xffffffff,
521 7, 0x9d2c5680,
522 15, 0xefc60000,
523 18, 1812433253> mt19937;
524typedef mersenne_twister_engine<uint_fast64_t, 64, 312, 156, 31,
525 0xb5026f5aa96619e9ULL, 29, 0x5555555555555555ULL,
526 17, 0x71d67fffeda60000ULL,
527 37, 0xfff7eee000000000ULL,
528 43, 6364136223846793005ULL> mt19937_64;
529
530_LIBCPP_END_NAMESPACE_STD
531
532_LIBCPP_POP_MACROS
533
534#endif // _LIBCPP___RANDOM_MERSENNE_TWISTER_ENGINE_H
lib/libcxx/include/__random/negative_binomial_distribution.h created+176
......@@ -0,0 +1,176 @@
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_NEGATIVE_BINOMIAL_DISTRIBUTION_H
10#define _LIBCPP___RANDOM_NEGATIVE_BINOMIAL_DISTRIBUTION_H
11
12#include <__config>
13#include <__random/bernoulli_distribution.h>
14#include <__random/gamma_distribution.h>
15#include <__random/poisson_distribution.h>
16#include <iosfwd>
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
28template<class _IntType = int>
29class _LIBCPP_TEMPLATE_VIS negative_binomial_distribution
30{
31public:
32 // types
33 typedef _IntType result_type;
34
35 class _LIBCPP_TEMPLATE_VIS param_type
36 {
37 result_type __k_;
38 double __p_;
39 public:
40 typedef negative_binomial_distribution distribution_type;
41
42 _LIBCPP_INLINE_VISIBILITY
43 explicit param_type(result_type __k = 1, double __p = 0.5)
44 : __k_(__k), __p_(__p) {}
45
46 _LIBCPP_INLINE_VISIBILITY
47 result_type k() const {return __k_;}
48 _LIBCPP_INLINE_VISIBILITY
49 double p() const {return __p_;}
50
51 friend _LIBCPP_INLINE_VISIBILITY
52 bool operator==(const param_type& __x, const param_type& __y)
53 {return __x.__k_ == __y.__k_ && __x.__p_ == __y.__p_;}
54 friend _LIBCPP_INLINE_VISIBILITY
55 bool operator!=(const param_type& __x, const param_type& __y)
56 {return !(__x == __y);}
57 };
58
59private:
60 param_type __p_;
61
62public:
63 // constructor and reset functions
64#ifndef _LIBCPP_CXX03_LANG
65 _LIBCPP_INLINE_VISIBILITY
66 negative_binomial_distribution() : negative_binomial_distribution(1) {}
67 _LIBCPP_INLINE_VISIBILITY
68 explicit negative_binomial_distribution(result_type __k, double __p = 0.5)
69 : __p_(__k, __p) {}
70#else
71 _LIBCPP_INLINE_VISIBILITY
72 explicit negative_binomial_distribution(result_type __k = 1,
73 double __p = 0.5)
74 : __p_(__k, __p) {}
75#endif
76 _LIBCPP_INLINE_VISIBILITY
77 explicit negative_binomial_distribution(const param_type& __p) : __p_(__p) {}
78 _LIBCPP_INLINE_VISIBILITY
79 void reset() {}
80
81 // generating functions
82 template<class _URNG>
83 _LIBCPP_INLINE_VISIBILITY
84 result_type operator()(_URNG& __g)
85 {return (*this)(__g, __p_);}
86 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
87
88 // property functions
89 _LIBCPP_INLINE_VISIBILITY
90 result_type k() const {return __p_.k();}
91 _LIBCPP_INLINE_VISIBILITY
92 double p() const {return __p_.p();}
93
94 _LIBCPP_INLINE_VISIBILITY
95 param_type param() const {return __p_;}
96 _LIBCPP_INLINE_VISIBILITY
97 void param(const param_type& __p) {__p_ = __p;}
98
99 _LIBCPP_INLINE_VISIBILITY
100 result_type min() const {return 0;}
101 _LIBCPP_INLINE_VISIBILITY
102 result_type max() const {return numeric_limits<result_type>::max();}
103
104 friend _LIBCPP_INLINE_VISIBILITY
105 bool operator==(const negative_binomial_distribution& __x,
106 const negative_binomial_distribution& __y)
107 {return __x.__p_ == __y.__p_;}
108 friend _LIBCPP_INLINE_VISIBILITY
109 bool operator!=(const negative_binomial_distribution& __x,
110 const negative_binomial_distribution& __y)
111 {return !(__x == __y);}
112};
113
114template <class _IntType>
115template<class _URNG>
116_IntType
117negative_binomial_distribution<_IntType>::operator()(_URNG& __urng, const param_type& __pr)
118{
119 result_type __k = __pr.k();
120 double __p = __pr.p();
121 if (__k <= 21 * __p)
122 {
123 bernoulli_distribution __gen(__p);
124 result_type __f = 0;
125 result_type __s = 0;
126 while (__s < __k)
127 {
128 if (__gen(__urng))
129 ++__s;
130 else
131 ++__f;
132 }
133 return __f;
134 }
135 return poisson_distribution<result_type>(gamma_distribution<double>
136 (__k, (1-__p)/__p)(__urng))(__urng);
137}
138
139template <class _CharT, class _Traits, class _IntType>
140basic_ostream<_CharT, _Traits>&
141operator<<(basic_ostream<_CharT, _Traits>& __os,
142 const negative_binomial_distribution<_IntType>& __x)
143{
144 __save_flags<_CharT, _Traits> __lx(__os);
145 typedef basic_ostream<_CharT, _Traits> _OStream;
146 __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
147 _OStream::scientific);
148 _CharT __sp = __os.widen(' ');
149 __os.fill(__sp);
150 return __os << __x.k() << __sp << __x.p();
151}
152
153template <class _CharT, class _Traits, class _IntType>
154basic_istream<_CharT, _Traits>&
155operator>>(basic_istream<_CharT, _Traits>& __is,
156 negative_binomial_distribution<_IntType>& __x)
157{
158 typedef negative_binomial_distribution<_IntType> _Eng;
159 typedef typename _Eng::result_type result_type;
160 typedef typename _Eng::param_type param_type;
161 __save_flags<_CharT, _Traits> __lx(__is);
162 typedef basic_istream<_CharT, _Traits> _Istream;
163 __is.flags(_Istream::dec | _Istream::skipws);
164 result_type __k;
165 double __p;
166 __is >> __k >> __p;
167 if (!__is.fail())
168 __x.param(param_type(__k, __p));
169 return __is;
170}
171
172_LIBCPP_END_NAMESPACE_STD
173
174_LIBCPP_POP_MACROS
175
176#endif // _LIBCPP___RANDOM_NEGATIVE_BINOMIAL_DISTRIBUTION_H
lib/libcxx/include/__random/normal_distribution.h created+208
......@@ -0,0 +1,208 @@
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_NORMAL_DISTRIBUTION_H
10#define _LIBCPP___RANDOM_NORMAL_DISTRIBUTION_H
11
12#include <__config>
13#include <__random/uniform_real_distribution.h>
14#include <cmath>
15#include <iosfwd>
16#include <limits>
17
18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
20#endif
21
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
25_LIBCPP_BEGIN_NAMESPACE_STD
26
27template<class _RealType = double>
28class _LIBCPP_TEMPLATE_VIS normal_distribution
29{
30public:
31 // types
32 typedef _RealType result_type;
33
34 class _LIBCPP_TEMPLATE_VIS param_type
35 {
36 result_type __mean_;
37 result_type __stddev_;
38 public:
39 typedef normal_distribution distribution_type;
40
41 _LIBCPP_INLINE_VISIBILITY
42 explicit param_type(result_type __mean = 0, result_type __stddev = 1)
43 : __mean_(__mean), __stddev_(__stddev) {}
44
45 _LIBCPP_INLINE_VISIBILITY
46 result_type mean() const {return __mean_;}
47 _LIBCPP_INLINE_VISIBILITY
48 result_type stddev() const {return __stddev_;}
49
50 friend _LIBCPP_INLINE_VISIBILITY
51 bool operator==(const param_type& __x, const param_type& __y)
52 {return __x.__mean_ == __y.__mean_ && __x.__stddev_ == __y.__stddev_;}
53 friend _LIBCPP_INLINE_VISIBILITY
54 bool operator!=(const param_type& __x, const param_type& __y)
55 {return !(__x == __y);}
56 };
57
58private:
59 param_type __p_;
60 result_type _V_;
61 bool _V_hot_;
62
63public:
64 // constructors and reset functions
65#ifndef _LIBCPP_CXX03_LANG
66 _LIBCPP_INLINE_VISIBILITY
67 normal_distribution() : normal_distribution(0) {}
68 _LIBCPP_INLINE_VISIBILITY
69 explicit normal_distribution(result_type __mean, result_type __stddev = 1)
70 : __p_(param_type(__mean, __stddev)), _V_hot_(false) {}
71#else
72 _LIBCPP_INLINE_VISIBILITY
73 explicit normal_distribution(result_type __mean = 0,
74 result_type __stddev = 1)
75 : __p_(param_type(__mean, __stddev)), _V_hot_(false) {}
76#endif
77 _LIBCPP_INLINE_VISIBILITY
78 explicit normal_distribution(const param_type& __p)
79 : __p_(__p), _V_hot_(false) {}
80 _LIBCPP_INLINE_VISIBILITY
81 void reset() {_V_hot_ = false;}
82
83 // generating functions
84 template<class _URNG>
85 _LIBCPP_INLINE_VISIBILITY
86 result_type operator()(_URNG& __g)
87 {return (*this)(__g, __p_);}
88 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
89
90 // property functions
91 _LIBCPP_INLINE_VISIBILITY
92 result_type mean() const {return __p_.mean();}
93 _LIBCPP_INLINE_VISIBILITY
94 result_type stddev() const {return __p_.stddev();}
95
96 _LIBCPP_INLINE_VISIBILITY
97 param_type param() const {return __p_;}
98 _LIBCPP_INLINE_VISIBILITY
99 void param(const param_type& __p) {__p_ = __p;}
100
101 _LIBCPP_INLINE_VISIBILITY
102 result_type min() const {return -numeric_limits<result_type>::infinity();}
103 _LIBCPP_INLINE_VISIBILITY
104 result_type max() const {return numeric_limits<result_type>::infinity();}
105
106 friend _LIBCPP_INLINE_VISIBILITY
107 bool operator==(const normal_distribution& __x,
108 const normal_distribution& __y)
109 {return __x.__p_ == __y.__p_ && __x._V_hot_ == __y._V_hot_ &&
110 (!__x._V_hot_ || __x._V_ == __y._V_);}
111 friend _LIBCPP_INLINE_VISIBILITY
112 bool operator!=(const normal_distribution& __x,
113 const normal_distribution& __y)
114 {return !(__x == __y);}
115
116 template <class _CharT, class _Traits, class _RT>
117 friend
118 basic_ostream<_CharT, _Traits>&
119 operator<<(basic_ostream<_CharT, _Traits>& __os,
120 const normal_distribution<_RT>& __x);
121
122 template <class _CharT, class _Traits, class _RT>
123 friend
124 basic_istream<_CharT, _Traits>&
125 operator>>(basic_istream<_CharT, _Traits>& __is,
126 normal_distribution<_RT>& __x);
127};
128
129template <class _RealType>
130template<class _URNG>
131_RealType
132normal_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
133{
134 result_type _Up;
135 if (_V_hot_)
136 {
137 _V_hot_ = false;
138 _Up = _V_;
139 }
140 else
141 {
142 uniform_real_distribution<result_type> _Uni(-1, 1);
143 result_type __u;
144 result_type __v;
145 result_type __s;
146 do
147 {
148 __u = _Uni(__g);
149 __v = _Uni(__g);
150 __s = __u * __u + __v * __v;
151 } while (__s > 1 || __s == 0);
152 result_type _Fp = _VSTD::sqrt(-2 * _VSTD::log(__s) / __s);
153 _V_ = __v * _Fp;
154 _V_hot_ = true;
155 _Up = __u * _Fp;
156 }
157 return _Up * __p.stddev() + __p.mean();
158}
159
160template <class _CharT, class _Traits, class _RT>
161basic_ostream<_CharT, _Traits>&
162operator<<(basic_ostream<_CharT, _Traits>& __os,
163 const normal_distribution<_RT>& __x)
164{
165 __save_flags<_CharT, _Traits> __lx(__os);
166 typedef basic_ostream<_CharT, _Traits> _OStream;
167 __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
168 _OStream::scientific);
169 _CharT __sp = __os.widen(' ');
170 __os.fill(__sp);
171 __os << __x.mean() << __sp << __x.stddev() << __sp << __x._V_hot_;
172 if (__x._V_hot_)
173 __os << __sp << __x._V_;
174 return __os;
175}
176
177template <class _CharT, class _Traits, class _RT>
178basic_istream<_CharT, _Traits>&
179operator>>(basic_istream<_CharT, _Traits>& __is,
180 normal_distribution<_RT>& __x)
181{
182 typedef normal_distribution<_RT> _Eng;
183 typedef typename _Eng::result_type result_type;
184 typedef typename _Eng::param_type param_type;
185 __save_flags<_CharT, _Traits> __lx(__is);
186 typedef basic_istream<_CharT, _Traits> _Istream;
187 __is.flags(_Istream::dec | _Istream::skipws);
188 result_type __mean;
189 result_type __stddev;
190 result_type _Vp = 0;
191 bool _V_hot = false;
192 __is >> __mean >> __stddev >> _V_hot;
193 if (_V_hot)
194 __is >> _Vp;
195 if (!__is.fail())
196 {
197 __x.param(param_type(__mean, __stddev));
198 __x._V_hot_ = _V_hot;
199 __x._V_ = _Vp;
200 }
201 return __is;
202}
203
204_LIBCPP_END_NAMESPACE_STD
205
206_LIBCPP_POP_MACROS
207
208#endif // _LIBCPP___RANDOM_NORMAL_DISTRIBUTION_H
lib/libcxx/include/__random/piecewise_constant_distribution.h created+356
......@@ -0,0 +1,356 @@
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_PIECEWISE_CONSTANT_DISTRIBUTION_H
10#define _LIBCPP___RANDOM_PIECEWISE_CONSTANT_DISTRIBUTION_H
11
12#include <__algorithm/upper_bound.h>
13#include <__config>
14#include <__random/uniform_real_distribution.h>
15#include <iosfwd>
16#include <numeric>
17#include <vector>
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
28template<class _RealType = double>
29class _LIBCPP_TEMPLATE_VIS piecewise_constant_distribution
30{
31public:
32 // types
33 typedef _RealType result_type;
34
35 class _LIBCPP_TEMPLATE_VIS param_type
36 {
37 vector<result_type> __b_;
38 vector<result_type> __densities_;
39 vector<result_type> __areas_;
40 public:
41 typedef piecewise_constant_distribution distribution_type;
42
43 param_type();
44 template<class _InputIteratorB, class _InputIteratorW>
45 param_type(_InputIteratorB __fB, _InputIteratorB __lB,
46 _InputIteratorW __fW);
47#ifndef _LIBCPP_CXX03_LANG
48 template<class _UnaryOperation>
49 param_type(initializer_list<result_type> __bl, _UnaryOperation __fw);
50#endif // _LIBCPP_CXX03_LANG
51 template<class _UnaryOperation>
52 param_type(size_t __nw, result_type __xmin, result_type __xmax,
53 _UnaryOperation __fw);
54 param_type(param_type const&) = default;
55 param_type & operator=(const param_type& __rhs);
56
57 _LIBCPP_INLINE_VISIBILITY
58 vector<result_type> intervals() const {return __b_;}
59 _LIBCPP_INLINE_VISIBILITY
60 vector<result_type> densities() const {return __densities_;}
61
62 friend _LIBCPP_INLINE_VISIBILITY
63 bool operator==(const param_type& __x, const param_type& __y)
64 {return __x.__densities_ == __y.__densities_ && __x.__b_ == __y.__b_;}
65 friend _LIBCPP_INLINE_VISIBILITY
66 bool operator!=(const param_type& __x, const param_type& __y)
67 {return !(__x == __y);}
68
69 private:
70 void __init();
71
72 friend class piecewise_constant_distribution;
73
74 template <class _CharT, class _Traits, class _RT>
75 friend
76 basic_ostream<_CharT, _Traits>&
77 operator<<(basic_ostream<_CharT, _Traits>& __os,
78 const piecewise_constant_distribution<_RT>& __x);
79
80 template <class _CharT, class _Traits, class _RT>
81 friend
82 basic_istream<_CharT, _Traits>&
83 operator>>(basic_istream<_CharT, _Traits>& __is,
84 piecewise_constant_distribution<_RT>& __x);
85 };
86
87private:
88 param_type __p_;
89
90public:
91 // constructor and reset functions
92 _LIBCPP_INLINE_VISIBILITY
93 piecewise_constant_distribution() {}
94 template<class _InputIteratorB, class _InputIteratorW>
95 _LIBCPP_INLINE_VISIBILITY
96 piecewise_constant_distribution(_InputIteratorB __fB,
97 _InputIteratorB __lB,
98 _InputIteratorW __fW)
99 : __p_(__fB, __lB, __fW) {}
100
101#ifndef _LIBCPP_CXX03_LANG
102 template<class _UnaryOperation>
103 _LIBCPP_INLINE_VISIBILITY
104 piecewise_constant_distribution(initializer_list<result_type> __bl,
105 _UnaryOperation __fw)
106 : __p_(__bl, __fw) {}
107#endif // _LIBCPP_CXX03_LANG
108
109 template<class _UnaryOperation>
110 _LIBCPP_INLINE_VISIBILITY
111 piecewise_constant_distribution(size_t __nw, result_type __xmin,
112 result_type __xmax, _UnaryOperation __fw)
113 : __p_(__nw, __xmin, __xmax, __fw) {}
114
115 _LIBCPP_INLINE_VISIBILITY
116 explicit piecewise_constant_distribution(const param_type& __p)
117 : __p_(__p) {}
118
119 _LIBCPP_INLINE_VISIBILITY
120 void reset() {}
121
122 // generating functions
123 template<class _URNG>
124 _LIBCPP_INLINE_VISIBILITY
125 result_type operator()(_URNG& __g)
126 {return (*this)(__g, __p_);}
127 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
128
129 // property functions
130 _LIBCPP_INLINE_VISIBILITY
131 vector<result_type> intervals() const {return __p_.intervals();}
132 _LIBCPP_INLINE_VISIBILITY
133 vector<result_type> densities() const {return __p_.densities();}
134
135 _LIBCPP_INLINE_VISIBILITY
136 param_type param() const {return __p_;}
137 _LIBCPP_INLINE_VISIBILITY
138 void param(const param_type& __p) {__p_ = __p;}
139
140 _LIBCPP_INLINE_VISIBILITY
141 result_type min() const {return __p_.__b_.front();}
142 _LIBCPP_INLINE_VISIBILITY
143 result_type max() const {return __p_.__b_.back();}
144
145 friend _LIBCPP_INLINE_VISIBILITY
146 bool operator==(const piecewise_constant_distribution& __x,
147 const piecewise_constant_distribution& __y)
148 {return __x.__p_ == __y.__p_;}
149 friend _LIBCPP_INLINE_VISIBILITY
150 bool operator!=(const piecewise_constant_distribution& __x,
151 const piecewise_constant_distribution& __y)
152 {return !(__x == __y);}
153
154 template <class _CharT, class _Traits, class _RT>
155 friend
156 basic_ostream<_CharT, _Traits>&
157 operator<<(basic_ostream<_CharT, _Traits>& __os,
158 const piecewise_constant_distribution<_RT>& __x);
159
160 template <class _CharT, class _Traits, class _RT>
161 friend
162 basic_istream<_CharT, _Traits>&
163 operator>>(basic_istream<_CharT, _Traits>& __is,
164 piecewise_constant_distribution<_RT>& __x);
165};
166
167template<class _RealType>
168typename piecewise_constant_distribution<_RealType>::param_type &
169piecewise_constant_distribution<_RealType>::param_type::operator=
170 (const param_type& __rhs)
171{
172// These can throw
173 __b_.reserve (__rhs.__b_.size ());
174 __densities_.reserve(__rhs.__densities_.size());
175 __areas_.reserve (__rhs.__areas_.size());
176
177// These can not throw
178 __b_ = __rhs.__b_;
179 __densities_ = __rhs.__densities_;
180 __areas_ = __rhs.__areas_;
181 return *this;
182}
183
184template<class _RealType>
185void
186piecewise_constant_distribution<_RealType>::param_type::__init()
187{
188 // __densities_ contains non-normalized areas
189 result_type __total_area = _VSTD::accumulate(__densities_.begin(),
190 __densities_.end(),
191 result_type());
192 for (size_t __i = 0; __i < __densities_.size(); ++__i)
193 __densities_[__i] /= __total_area;
194 // __densities_ contains normalized areas
195 __areas_.assign(__densities_.size(), result_type());
196 _VSTD::partial_sum(__densities_.begin(), __densities_.end() - 1,
197 __areas_.begin() + 1);
198 // __areas_ contains partial sums of normalized areas: [0, __densities_ - 1]
199 __densities_.back() = 1 - __areas_.back(); // correct round off error
200 for (size_t __i = 0; __i < __densities_.size(); ++__i)
201 __densities_[__i] /= (__b_[__i+1] - __b_[__i]);
202 // __densities_ now contains __densities_
203}
204
205template<class _RealType>
206piecewise_constant_distribution<_RealType>::param_type::param_type()
207 : __b_(2),
208 __densities_(1, 1.0),
209 __areas_(1, 0.0)
210{
211 __b_[1] = 1;
212}
213
214template<class _RealType>
215template<class _InputIteratorB, class _InputIteratorW>
216piecewise_constant_distribution<_RealType>::param_type::param_type(
217 _InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW)
218 : __b_(__fB, __lB)
219{
220 if (__b_.size() < 2)
221 {
222 __b_.resize(2);
223 __b_[0] = 0;
224 __b_[1] = 1;
225 __densities_.assign(1, 1.0);
226 __areas_.assign(1, 0.0);
227 }
228 else
229 {
230 __densities_.reserve(__b_.size() - 1);
231 for (size_t __i = 0; __i < __b_.size() - 1; ++__i, ++__fW)
232 __densities_.push_back(*__fW);
233 __init();
234 }
235}
236
237#ifndef _LIBCPP_CXX03_LANG
238
239template<class _RealType>
240template<class _UnaryOperation>
241piecewise_constant_distribution<_RealType>::param_type::param_type(
242 initializer_list<result_type> __bl, _UnaryOperation __fw)
243 : __b_(__bl.begin(), __bl.end())
244{
245 if (__b_.size() < 2)
246 {
247 __b_.resize(2);
248 __b_[0] = 0;
249 __b_[1] = 1;
250 __densities_.assign(1, 1.0);
251 __areas_.assign(1, 0.0);
252 }
253 else
254 {
255 __densities_.reserve(__b_.size() - 1);
256 for (size_t __i = 0; __i < __b_.size() - 1; ++__i)
257 __densities_.push_back(__fw((__b_[__i+1] + __b_[__i])*.5));
258 __init();
259 }
260}
261
262#endif // _LIBCPP_CXX03_LANG
263
264template<class _RealType>
265template<class _UnaryOperation>
266piecewise_constant_distribution<_RealType>::param_type::param_type(
267 size_t __nw, result_type __xmin, result_type __xmax, _UnaryOperation __fw)
268 : __b_(__nw == 0 ? 2 : __nw + 1)
269{
270 size_t __n = __b_.size() - 1;
271 result_type __d = (__xmax - __xmin) / __n;
272 __densities_.reserve(__n);
273 for (size_t __i = 0; __i < __n; ++__i)
274 {
275 __b_[__i] = __xmin + __i * __d;
276 __densities_.push_back(__fw(__b_[__i] + __d*.5));
277 }
278 __b_[__n] = __xmax;
279 __init();
280}
281
282template<class _RealType>
283template<class _URNG>
284_RealType
285piecewise_constant_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
286{
287 typedef uniform_real_distribution<result_type> _Gen;
288 result_type __u = _Gen()(__g);
289 ptrdiff_t __k = _VSTD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(),
290 __u) - __p.__areas_.begin() - 1;
291 return (__u - __p.__areas_[__k]) / __p.__densities_[__k] + __p.__b_[__k];
292}
293
294template <class _CharT, class _Traits, class _RT>
295basic_ostream<_CharT, _Traits>&
296operator<<(basic_ostream<_CharT, _Traits>& __os,
297 const piecewise_constant_distribution<_RT>& __x)
298{
299 __save_flags<_CharT, _Traits> __lx(__os);
300 typedef basic_ostream<_CharT, _Traits> _OStream;
301 __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
302 _OStream::scientific);
303 _CharT __sp = __os.widen(' ');
304 __os.fill(__sp);
305 size_t __n = __x.__p_.__b_.size();
306 __os << __n;
307 for (size_t __i = 0; __i < __n; ++__i)
308 __os << __sp << __x.__p_.__b_[__i];
309 __n = __x.__p_.__densities_.size();
310 __os << __sp << __n;
311 for (size_t __i = 0; __i < __n; ++__i)
312 __os << __sp << __x.__p_.__densities_[__i];
313 __n = __x.__p_.__areas_.size();
314 __os << __sp << __n;
315 for (size_t __i = 0; __i < __n; ++__i)
316 __os << __sp << __x.__p_.__areas_[__i];
317 return __os;
318}
319
320template <class _CharT, class _Traits, class _RT>
321basic_istream<_CharT, _Traits>&
322operator>>(basic_istream<_CharT, _Traits>& __is,
323 piecewise_constant_distribution<_RT>& __x)
324{
325 typedef piecewise_constant_distribution<_RT> _Eng;
326 typedef typename _Eng::result_type result_type;
327 __save_flags<_CharT, _Traits> __lx(__is);
328 typedef basic_istream<_CharT, _Traits> _Istream;
329 __is.flags(_Istream::dec | _Istream::skipws);
330 size_t __n;
331 __is >> __n;
332 vector<result_type> __b(__n);
333 for (size_t __i = 0; __i < __n; ++__i)
334 __is >> __b[__i];
335 __is >> __n;
336 vector<result_type> __densities(__n);
337 for (size_t __i = 0; __i < __n; ++__i)
338 __is >> __densities[__i];
339 __is >> __n;
340 vector<result_type> __areas(__n);
341 for (size_t __i = 0; __i < __n; ++__i)
342 __is >> __areas[__i];
343 if (!__is.fail())
344 {
345 swap(__x.__p_.__b_, __b);
346 swap(__x.__p_.__densities_, __densities);
347 swap(__x.__p_.__areas_, __areas);
348 }
349 return __is;
350}
351
352_LIBCPP_END_NAMESPACE_STD
353
354_LIBCPP_POP_MACROS
355
356#endif // _LIBCPP___RANDOM_PIECEWISE_CONSTANT_DISTRIBUTION_H
lib/libcxx/include/__random/piecewise_linear_distribution.h created+372
......@@ -0,0 +1,372 @@
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_PIECEWISE_LINEAR_DISTRIBUTION_H
10#define _LIBCPP___RANDOM_PIECEWISE_LINEAR_DISTRIBUTION_H
11
12#include <__algorithm/upper_bound.h>
13#include <__config>
14#include <__random/uniform_real_distribution.h>
15#include <iosfwd>
16#include <numeric>
17#include <vector>
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
28template<class _RealType = double>
29class _LIBCPP_TEMPLATE_VIS piecewise_linear_distribution
30{
31public:
32 // types
33 typedef _RealType result_type;
34
35 class _LIBCPP_TEMPLATE_VIS param_type
36 {
37 vector<result_type> __b_;
38 vector<result_type> __densities_;
39 vector<result_type> __areas_;
40 public:
41 typedef piecewise_linear_distribution distribution_type;
42
43 param_type();
44 template<class _InputIteratorB, class _InputIteratorW>
45 param_type(_InputIteratorB __fB, _InputIteratorB __lB,
46 _InputIteratorW __fW);
47#ifndef _LIBCPP_CXX03_LANG
48 template<class _UnaryOperation>
49 param_type(initializer_list<result_type> __bl, _UnaryOperation __fw);
50#endif // _LIBCPP_CXX03_LANG
51 template<class _UnaryOperation>
52 param_type(size_t __nw, result_type __xmin, result_type __xmax,
53 _UnaryOperation __fw);
54 param_type(param_type const&) = default;
55 param_type & operator=(const param_type& __rhs);
56
57 _LIBCPP_INLINE_VISIBILITY
58 vector<result_type> intervals() const {return __b_;}
59 _LIBCPP_INLINE_VISIBILITY
60 vector<result_type> densities() const {return __densities_;}
61
62 friend _LIBCPP_INLINE_VISIBILITY
63 bool operator==(const param_type& __x, const param_type& __y)
64 {return __x.__densities_ == __y.__densities_ && __x.__b_ == __y.__b_;}
65 friend _LIBCPP_INLINE_VISIBILITY
66 bool operator!=(const param_type& __x, const param_type& __y)
67 {return !(__x == __y);}
68
69 private:
70 void __init();
71
72 friend class piecewise_linear_distribution;
73
74 template <class _CharT, class _Traits, class _RT>
75 friend
76 basic_ostream<_CharT, _Traits>&
77 operator<<(basic_ostream<_CharT, _Traits>& __os,
78 const piecewise_linear_distribution<_RT>& __x);
79
80 template <class _CharT, class _Traits, class _RT>
81 friend
82 basic_istream<_CharT, _Traits>&
83 operator>>(basic_istream<_CharT, _Traits>& __is,
84 piecewise_linear_distribution<_RT>& __x);
85 };
86
87private:
88 param_type __p_;
89
90public:
91 // constructor and reset functions
92 _LIBCPP_INLINE_VISIBILITY
93 piecewise_linear_distribution() {}
94 template<class _InputIteratorB, class _InputIteratorW>
95 _LIBCPP_INLINE_VISIBILITY
96 piecewise_linear_distribution(_InputIteratorB __fB,
97 _InputIteratorB __lB,
98 _InputIteratorW __fW)
99 : __p_(__fB, __lB, __fW) {}
100
101#ifndef _LIBCPP_CXX03_LANG
102 template<class _UnaryOperation>
103 _LIBCPP_INLINE_VISIBILITY
104 piecewise_linear_distribution(initializer_list<result_type> __bl,
105 _UnaryOperation __fw)
106 : __p_(__bl, __fw) {}
107#endif // _LIBCPP_CXX03_LANG
108
109 template<class _UnaryOperation>
110 _LIBCPP_INLINE_VISIBILITY
111 piecewise_linear_distribution(size_t __nw, result_type __xmin,
112 result_type __xmax, _UnaryOperation __fw)
113 : __p_(__nw, __xmin, __xmax, __fw) {}
114
115 _LIBCPP_INLINE_VISIBILITY
116 explicit piecewise_linear_distribution(const param_type& __p)
117 : __p_(__p) {}
118
119 _LIBCPP_INLINE_VISIBILITY
120 void reset() {}
121
122 // generating functions
123 template<class _URNG>
124 _LIBCPP_INLINE_VISIBILITY
125 result_type operator()(_URNG& __g)
126 {return (*this)(__g, __p_);}
127 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
128
129 // property functions
130 _LIBCPP_INLINE_VISIBILITY
131 vector<result_type> intervals() const {return __p_.intervals();}
132 _LIBCPP_INLINE_VISIBILITY
133 vector<result_type> densities() const {return __p_.densities();}
134
135 _LIBCPP_INLINE_VISIBILITY
136 param_type param() const {return __p_;}
137 _LIBCPP_INLINE_VISIBILITY
138 void param(const param_type& __p) {__p_ = __p;}
139
140 _LIBCPP_INLINE_VISIBILITY
141 result_type min() const {return __p_.__b_.front();}
142 _LIBCPP_INLINE_VISIBILITY
143 result_type max() const {return __p_.__b_.back();}
144
145 friend _LIBCPP_INLINE_VISIBILITY
146 bool operator==(const piecewise_linear_distribution& __x,
147 const piecewise_linear_distribution& __y)
148 {return __x.__p_ == __y.__p_;}
149 friend _LIBCPP_INLINE_VISIBILITY
150 bool operator!=(const piecewise_linear_distribution& __x,
151 const piecewise_linear_distribution& __y)
152 {return !(__x == __y);}
153
154 template <class _CharT, class _Traits, class _RT>
155 friend
156 basic_ostream<_CharT, _Traits>&
157 operator<<(basic_ostream<_CharT, _Traits>& __os,
158 const piecewise_linear_distribution<_RT>& __x);
159
160 template <class _CharT, class _Traits, class _RT>
161 friend
162 basic_istream<_CharT, _Traits>&
163 operator>>(basic_istream<_CharT, _Traits>& __is,
164 piecewise_linear_distribution<_RT>& __x);
165};
166
167template<class _RealType>
168typename piecewise_linear_distribution<_RealType>::param_type &
169piecewise_linear_distribution<_RealType>::param_type::operator=
170 (const param_type& __rhs)
171{
172// These can throw
173 __b_.reserve (__rhs.__b_.size ());
174 __densities_.reserve(__rhs.__densities_.size());
175 __areas_.reserve (__rhs.__areas_.size());
176
177// These can not throw
178 __b_ = __rhs.__b_;
179 __densities_ = __rhs.__densities_;
180 __areas_ = __rhs.__areas_;
181 return *this;
182}
183
184
185template<class _RealType>
186void
187piecewise_linear_distribution<_RealType>::param_type::__init()
188{
189 __areas_.assign(__densities_.size() - 1, result_type());
190 result_type _Sp = 0;
191 for (size_t __i = 0; __i < __areas_.size(); ++__i)
192 {
193 __areas_[__i] = (__densities_[__i+1] + __densities_[__i]) *
194 (__b_[__i+1] - __b_[__i]) * .5;
195 _Sp += __areas_[__i];
196 }
197 for (size_t __i = __areas_.size(); __i > 1;)
198 {
199 --__i;
200 __areas_[__i] = __areas_[__i-1] / _Sp;
201 }
202 __areas_[0] = 0;
203 for (size_t __i = 1; __i < __areas_.size(); ++__i)
204 __areas_[__i] += __areas_[__i-1];
205 for (size_t __i = 0; __i < __densities_.size(); ++__i)
206 __densities_[__i] /= _Sp;
207}
208
209template<class _RealType>
210piecewise_linear_distribution<_RealType>::param_type::param_type()
211 : __b_(2),
212 __densities_(2, 1.0),
213 __areas_(1, 0.0)
214{
215 __b_[1] = 1;
216}
217
218template<class _RealType>
219template<class _InputIteratorB, class _InputIteratorW>
220piecewise_linear_distribution<_RealType>::param_type::param_type(
221 _InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW)
222 : __b_(__fB, __lB)
223{
224 if (__b_.size() < 2)
225 {
226 __b_.resize(2);
227 __b_[0] = 0;
228 __b_[1] = 1;
229 __densities_.assign(2, 1.0);
230 __areas_.assign(1, 0.0);
231 }
232 else
233 {
234 __densities_.reserve(__b_.size());
235 for (size_t __i = 0; __i < __b_.size(); ++__i, ++__fW)
236 __densities_.push_back(*__fW);
237 __init();
238 }
239}
240
241#ifndef _LIBCPP_CXX03_LANG
242
243template<class _RealType>
244template<class _UnaryOperation>
245piecewise_linear_distribution<_RealType>::param_type::param_type(
246 initializer_list<result_type> __bl, _UnaryOperation __fw)
247 : __b_(__bl.begin(), __bl.end())
248{
249 if (__b_.size() < 2)
250 {
251 __b_.resize(2);
252 __b_[0] = 0;
253 __b_[1] = 1;
254 __densities_.assign(2, 1.0);
255 __areas_.assign(1, 0.0);
256 }
257 else
258 {
259 __densities_.reserve(__b_.size());
260 for (size_t __i = 0; __i < __b_.size(); ++__i)
261 __densities_.push_back(__fw(__b_[__i]));
262 __init();
263 }
264}
265
266#endif // _LIBCPP_CXX03_LANG
267
268template<class _RealType>
269template<class _UnaryOperation>
270piecewise_linear_distribution<_RealType>::param_type::param_type(
271 size_t __nw, result_type __xmin, result_type __xmax, _UnaryOperation __fw)
272 : __b_(__nw == 0 ? 2 : __nw + 1)
273{
274 size_t __n = __b_.size() - 1;
275 result_type __d = (__xmax - __xmin) / __n;
276 __densities_.reserve(__b_.size());
277 for (size_t __i = 0; __i < __n; ++__i)
278 {
279 __b_[__i] = __xmin + __i * __d;
280 __densities_.push_back(__fw(__b_[__i]));
281 }
282 __b_[__n] = __xmax;
283 __densities_.push_back(__fw(__b_[__n]));
284 __init();
285}
286
287template<class _RealType>
288template<class _URNG>
289_RealType
290piecewise_linear_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
291{
292 typedef uniform_real_distribution<result_type> _Gen;
293 result_type __u = _Gen()(__g);
294 ptrdiff_t __k = _VSTD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(),
295 __u) - __p.__areas_.begin() - 1;
296 __u -= __p.__areas_[__k];
297 const result_type __dk = __p.__densities_[__k];
298 const result_type __dk1 = __p.__densities_[__k+1];
299 const result_type __deltad = __dk1 - __dk;
300 const result_type __bk = __p.__b_[__k];
301 if (__deltad == 0)
302 return __u / __dk + __bk;
303 const result_type __bk1 = __p.__b_[__k+1];
304 const result_type __deltab = __bk1 - __bk;
305 return (__bk * __dk1 - __bk1 * __dk +
306 _VSTD::sqrt(__deltab * (__deltab * __dk * __dk + 2 * __deltad * __u))) /
307 __deltad;
308}
309
310template <class _CharT, class _Traits, class _RT>
311basic_ostream<_CharT, _Traits>&
312operator<<(basic_ostream<_CharT, _Traits>& __os,
313 const piecewise_linear_distribution<_RT>& __x)
314{
315 __save_flags<_CharT, _Traits> __lx(__os);
316 typedef basic_ostream<_CharT, _Traits> _OStream;
317 __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
318 _OStream::scientific);
319 _CharT __sp = __os.widen(' ');
320 __os.fill(__sp);
321 size_t __n = __x.__p_.__b_.size();
322 __os << __n;
323 for (size_t __i = 0; __i < __n; ++__i)
324 __os << __sp << __x.__p_.__b_[__i];
325 __n = __x.__p_.__densities_.size();
326 __os << __sp << __n;
327 for (size_t __i = 0; __i < __n; ++__i)
328 __os << __sp << __x.__p_.__densities_[__i];
329 __n = __x.__p_.__areas_.size();
330 __os << __sp << __n;
331 for (size_t __i = 0; __i < __n; ++__i)
332 __os << __sp << __x.__p_.__areas_[__i];
333 return __os;
334}
335
336template <class _CharT, class _Traits, class _RT>
337basic_istream<_CharT, _Traits>&
338operator>>(basic_istream<_CharT, _Traits>& __is,
339 piecewise_linear_distribution<_RT>& __x)
340{
341 typedef piecewise_linear_distribution<_RT> _Eng;
342 typedef typename _Eng::result_type result_type;
343 __save_flags<_CharT, _Traits> __lx(__is);
344 typedef basic_istream<_CharT, _Traits> _Istream;
345 __is.flags(_Istream::dec | _Istream::skipws);
346 size_t __n;
347 __is >> __n;
348 vector<result_type> __b(__n);
349 for (size_t __i = 0; __i < __n; ++__i)
350 __is >> __b[__i];
351 __is >> __n;
352 vector<result_type> __densities(__n);
353 for (size_t __i = 0; __i < __n; ++__i)
354 __is >> __densities[__i];
355 __is >> __n;
356 vector<result_type> __areas(__n);
357 for (size_t __i = 0; __i < __n; ++__i)
358 __is >> __areas[__i];
359 if (!__is.fail())
360 {
361 swap(__x.__p_.__b_, __b);
362 swap(__x.__p_.__densities_, __densities);
363 swap(__x.__p_.__areas_, __areas);
364 }
365 return __is;
366}
367
368_LIBCPP_END_NAMESPACE_STD
369
370_LIBCPP_POP_MACROS
371
372#endif // _LIBCPP___RANDOM_PIECEWISE_LINEAR_DISTRIBUTION_H
lib/libcxx/include/__random/poisson_distribution.h created+277
......@@ -0,0 +1,277 @@
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_POISSON_DISTRIBUTION_H
10#define _LIBCPP___RANDOM_POISSON_DISTRIBUTION_H
11
12#include <__config>
13#include <__random/clamp_to_integral.h>
14#include <__random/exponential_distribution.h>
15#include <__random/normal_distribution.h>
16#include <__random/uniform_real_distribution.h>
17#include <cmath>
18#include <iosfwd>
19#include <limits>
20
21#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22#pragma GCC system_header
23#endif
24
25_LIBCPP_PUSH_MACROS
26#include <__undef_macros>
27
28_LIBCPP_BEGIN_NAMESPACE_STD
29
30template<class _IntType = int>
31class _LIBCPP_TEMPLATE_VIS poisson_distribution
32{
33public:
34 // types
35 typedef _IntType result_type;
36
37 class _LIBCPP_TEMPLATE_VIS param_type
38 {
39 double __mean_;
40 double __s_;
41 double __d_;
42 double __l_;
43 double __omega_;
44 double __c0_;
45 double __c1_;
46 double __c2_;
47 double __c3_;
48 double __c_;
49
50 public:
51 typedef poisson_distribution distribution_type;
52
53 explicit param_type(double __mean = 1.0);
54
55 _LIBCPP_INLINE_VISIBILITY
56 double mean() const {return __mean_;}
57
58 friend _LIBCPP_INLINE_VISIBILITY
59 bool operator==(const param_type& __x, const param_type& __y)
60 {return __x.__mean_ == __y.__mean_;}
61 friend _LIBCPP_INLINE_VISIBILITY
62 bool operator!=(const param_type& __x, const param_type& __y)
63 {return !(__x == __y);}
64
65 friend class poisson_distribution;
66 };
67
68private:
69 param_type __p_;
70
71public:
72 // constructors and reset functions
73#ifndef _LIBCPP_CXX03_LANG
74 _LIBCPP_INLINE_VISIBILITY
75 poisson_distribution() : poisson_distribution(1.0) {}
76 _LIBCPP_INLINE_VISIBILITY
77 explicit poisson_distribution(double __mean)
78 : __p_(__mean) {}
79#else
80 _LIBCPP_INLINE_VISIBILITY
81 explicit poisson_distribution(double __mean = 1.0)
82 : __p_(__mean) {}
83#endif
84 _LIBCPP_INLINE_VISIBILITY
85 explicit poisson_distribution(const param_type& __p) : __p_(__p) {}
86 _LIBCPP_INLINE_VISIBILITY
87 void reset() {}
88
89 // generating functions
90 template<class _URNG>
91 _LIBCPP_INLINE_VISIBILITY
92 result_type operator()(_URNG& __g)
93 {return (*this)(__g, __p_);}
94 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
95
96 // property functions
97 _LIBCPP_INLINE_VISIBILITY
98 double mean() const {return __p_.mean();}
99
100 _LIBCPP_INLINE_VISIBILITY
101 param_type param() const {return __p_;}
102 _LIBCPP_INLINE_VISIBILITY
103 void param(const param_type& __p) {__p_ = __p;}
104
105 _LIBCPP_INLINE_VISIBILITY
106 result_type min() const {return 0;}
107 _LIBCPP_INLINE_VISIBILITY
108 result_type max() const {return numeric_limits<result_type>::max();}
109
110 friend _LIBCPP_INLINE_VISIBILITY
111 bool operator==(const poisson_distribution& __x,
112 const poisson_distribution& __y)
113 {return __x.__p_ == __y.__p_;}
114 friend _LIBCPP_INLINE_VISIBILITY
115 bool operator!=(const poisson_distribution& __x,
116 const poisson_distribution& __y)
117 {return !(__x == __y);}
118};
119
120template<class _IntType>
121poisson_distribution<_IntType>::param_type::param_type(double __mean)
122 // According to the standard `inf` is a valid input, but it causes the
123 // distribution to hang, so we replace it with the maximum representable
124 // mean.
125 : __mean_(isinf(__mean) ? numeric_limits<double>::max() : __mean)
126{
127 if (__mean_ < 10)
128 {
129 __s_ = 0;
130 __d_ = 0;
131 __l_ = _VSTD::exp(-__mean_);
132 __omega_ = 0;
133 __c3_ = 0;
134 __c2_ = 0;
135 __c1_ = 0;
136 __c0_ = 0;
137 __c_ = 0;
138 }
139 else
140 {
141 __s_ = _VSTD::sqrt(__mean_);
142 __d_ = 6 * __mean_ * __mean_;
143 __l_ = _VSTD::trunc(__mean_ - 1.1484);
144 __omega_ = .3989423 / __s_;
145 double __b1_ = .4166667E-1 / __mean_;
146 double __b2_ = .3 * __b1_ * __b1_;
147 __c3_ = .1428571 * __b1_ * __b2_;
148 __c2_ = __b2_ - 15. * __c3_;
149 __c1_ = __b1_ - 6. * __b2_ + 45. * __c3_;
150 __c0_ = 1. - __b1_ + 3. * __b2_ - 15. * __c3_;
151 __c_ = .1069 / __mean_;
152 }
153}
154
155template <class _IntType>
156template<class _URNG>
157_IntType
158poisson_distribution<_IntType>::operator()(_URNG& __urng, const param_type& __pr)
159{
160 double __tx;
161 uniform_real_distribution<double> __urd;
162 if (__pr.__mean_ < 10)
163 {
164 __tx = 0;
165 for (double __p = __urd(__urng); __p > __pr.__l_; ++__tx)
166 __p *= __urd(__urng);
167 }
168 else
169 {
170 double __difmuk;
171 double __g = __pr.__mean_ + __pr.__s_ * normal_distribution<double>()(__urng);
172 double __u;
173 if (__g > 0)
174 {
175 __tx = _VSTD::trunc(__g);
176 if (__tx >= __pr.__l_)
177 return _VSTD::__clamp_to_integral<result_type>(__tx);
178 __difmuk = __pr.__mean_ - __tx;
179 __u = __urd(__urng);
180 if (__pr.__d_ * __u >= __difmuk * __difmuk * __difmuk)
181 return _VSTD::__clamp_to_integral<result_type>(__tx);
182 }
183 exponential_distribution<double> __edist;
184 for (bool __using_exp_dist = false; true; __using_exp_dist = true)
185 {
186 double __e;
187 if (__using_exp_dist || __g <= 0)
188 {
189 double __t;
190 do
191 {
192 __e = __edist(__urng);
193 __u = __urd(__urng);
194 __u += __u - 1;
195 __t = 1.8 + (__u < 0 ? -__e : __e);
196 } while (__t <= -.6744);
197 __tx = _VSTD::trunc(__pr.__mean_ + __pr.__s_ * __t);
198 __difmuk = __pr.__mean_ - __tx;
199 __using_exp_dist = true;
200 }
201 double __px;
202 double __py;
203 if (__tx < 10 && __tx >= 0)
204 {
205 const double __fac[] = {1, 1, 2, 6, 24, 120, 720, 5040,
206 40320, 362880};
207 __px = -__pr.__mean_;
208 __py = _VSTD::pow(__pr.__mean_, (double)__tx) / __fac[static_cast<int>(__tx)];
209 }
210 else
211 {
212 double __del = .8333333E-1 / __tx;
213 __del -= 4.8 * __del * __del * __del;
214 double __v = __difmuk / __tx;
215 if (_VSTD::abs(__v) > 0.25)
216 __px = __tx * _VSTD::log(1 + __v) - __difmuk - __del;
217 else
218 __px = __tx * __v * __v * (((((((.1250060 * __v + -.1384794) *
219 __v + .1421878) * __v + -.1661269) * __v + .2000118) *
220 __v + -.2500068) * __v + .3333333) * __v + -.5) - __del;
221 __py = .3989423 / _VSTD::sqrt(__tx);
222 }
223 double __r = (0.5 - __difmuk) / __pr.__s_;
224 double __r2 = __r * __r;
225 double __fx = -0.5 * __r2;
226 double __fy = __pr.__omega_ * (((__pr.__c3_ * __r2 + __pr.__c2_) *
227 __r2 + __pr.__c1_) * __r2 + __pr.__c0_);
228 if (__using_exp_dist)
229 {
230 if (__pr.__c_ * _VSTD::abs(__u) <= __py * _VSTD::exp(__px + __e) -
231 __fy * _VSTD::exp(__fx + __e))
232 break;
233 }
234 else
235 {
236 if (__fy - __u * __fy <= __py * _VSTD::exp(__px - __fx))
237 break;
238 }
239 }
240 }
241 return _VSTD::__clamp_to_integral<result_type>(__tx);
242}
243
244template <class _CharT, class _Traits, class _IntType>
245basic_ostream<_CharT, _Traits>&
246operator<<(basic_ostream<_CharT, _Traits>& __os,
247 const poisson_distribution<_IntType>& __x)
248{
249 __save_flags<_CharT, _Traits> __lx(__os);
250 typedef basic_ostream<_CharT, _Traits> _OStream;
251 __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
252 _OStream::scientific);
253 return __os << __x.mean();
254}
255
256template <class _CharT, class _Traits, class _IntType>
257basic_istream<_CharT, _Traits>&
258operator>>(basic_istream<_CharT, _Traits>& __is,
259 poisson_distribution<_IntType>& __x)
260{
261 typedef poisson_distribution<_IntType> _Eng;
262 typedef typename _Eng::param_type param_type;
263 __save_flags<_CharT, _Traits> __lx(__is);
264 typedef basic_istream<_CharT, _Traits> _Istream;
265 __is.flags(_Istream::dec | _Istream::skipws);
266 double __mean;
267 __is >> __mean;
268 if (!__is.fail())
269 __x.param(param_type(__mean));
270 return __is;
271}
272
273_LIBCPP_END_NAMESPACE_STD
274
275_LIBCPP_POP_MACROS
276
277#endif // _LIBCPP___RANDOM_POISSON_DISTRIBUTION_H
lib/libcxx/include/__random/random_device.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___RANDOM_RANDOM_DEVICE_H
10#define _LIBCPP___RANDOM_RANDOM_DEVICE_H
11
12#include <__config>
13#include <string>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16#pragma GCC system_header
17#endif
18
19_LIBCPP_PUSH_MACROS
20#include <__undef_macros>
21
22_LIBCPP_BEGIN_NAMESPACE_STD
23
24#if !defined(_LIBCPP_HAS_NO_RANDOM_DEVICE)
25
26class _LIBCPP_TYPE_VIS random_device
27{
28#ifdef _LIBCPP_USING_DEV_RANDOM
29 int __f_;
30#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
35
36 // Apple platforms used to use the `_LIBCPP_USING_DEV_RANDOM` code path, and now
37 // use `arc4random()` as of this comment. In order to avoid breaking the ABI, we
38 // retain the same layout as before.
39# if defined(__APPLE__)
40 int __padding_; // padding to fake the `__f_` field above
41# endif
42
43 // ... vendors can add workarounds here if they switch to a different representation ...
44
45# if defined(__clang__)
46# pragma clang diagnostic pop
47# endif
48#endif
49
50public:
51 // types
52 typedef unsigned result_type;
53
54 // generator characteristics
55 static _LIBCPP_CONSTEXPR const result_type _Min = 0;
56 static _LIBCPP_CONSTEXPR const result_type _Max = 0xFFFFFFFFu;
57
58 _LIBCPP_INLINE_VISIBILITY
59 static _LIBCPP_CONSTEXPR result_type min() { return _Min;}
60 _LIBCPP_INLINE_VISIBILITY
61 static _LIBCPP_CONSTEXPR result_type max() { return _Max;}
62
63 // constructors
64#ifndef _LIBCPP_CXX03_LANG
65 random_device() : random_device("/dev/urandom") {}
66 explicit random_device(const string& __token);
67#else
68 explicit random_device(const string& __token = "/dev/urandom");
69#endif
70 ~random_device();
71
72 // generating functions
73 result_type operator()();
74
75 // property functions
76 double entropy() const _NOEXCEPT;
77
78 random_device(const random_device&) = delete;
79 void operator=(const random_device&) = delete;
80};
81
82#endif // !_LIBCPP_HAS_NO_RANDOM_DEVICE
83
84_LIBCPP_END_NAMESPACE_STD
85
86_LIBCPP_POP_MACROS
87
88#endif // _LIBCPP___RANDOM_RANDOM_DEVICE_H
lib/libcxx/include/__random/ranlux.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___RANDOM_RANLUX_H
10#define _LIBCPP___RANDOM_RANLUX_H
11
12#include <__config>
13#include <__random/discard_block_engine.h>
14#include <__random/subtract_with_carry_engine.h>
15#include <cstdint>
16
17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#pragma GCC system_header
19#endif
20
21_LIBCPP_BEGIN_NAMESPACE_STD
22
23typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24> ranlux24_base;
24typedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12> ranlux48_base;
25
26typedef discard_block_engine<ranlux24_base, 223, 23> ranlux24;
27typedef discard_block_engine<ranlux48_base, 389, 11> ranlux48;
28
29_LIBCPP_END_NAMESPACE_STD
30
31#endif // _LIBCPP___RANDOM_RANLUX_H
lib/libcxx/include/__random/seed_seq.h created+153
......@@ -0,0 +1,153 @@
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_SEED_SEQ_H
10#define _LIBCPP___RANDOM_SEED_SEQ_H
11
12#include <__algorithm/copy.h>
13#include <__algorithm/fill.h>
14#include <__algorithm/max.h>
15#include <__config>
16#include <initializer_list>
17#include <vector>
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
28class _LIBCPP_TEMPLATE_VIS seed_seq
29{
30public:
31 // types
32 typedef uint32_t result_type;
33
34 // constructors
35 _LIBCPP_INLINE_VISIBILITY
36 seed_seq() _NOEXCEPT {}
37#ifndef _LIBCPP_CXX03_LANG
38 template<class _Tp, __enable_if_t<is_integral<_Tp>::value>* = nullptr>
39 _LIBCPP_INLINE_VISIBILITY
40 seed_seq(initializer_list<_Tp> __il) {
41 __init(__il.begin(), __il.end());
42 }
43#endif // _LIBCPP_CXX03_LANG
44
45 template<class _InputIterator>
46 _LIBCPP_INLINE_VISIBILITY
47 seed_seq(_InputIterator __first, _InputIterator __last) {
48 static_assert(is_integral<typename iterator_traits<_InputIterator>::value_type>::value,
49 "Mandates: iterator_traits<InputIterator>::value_type is an integer type");
50 __init(__first, __last);
51 }
52
53 // generating functions
54 template<class _RandomAccessIterator>
55 void generate(_RandomAccessIterator __first, _RandomAccessIterator __last);
56
57 // property functions
58 _LIBCPP_INLINE_VISIBILITY
59 size_t size() const _NOEXCEPT {return __v_.size();}
60 template<class _OutputIterator>
61 _LIBCPP_INLINE_VISIBILITY
62 void param(_OutputIterator __dest) const
63 {_VSTD::copy(__v_.begin(), __v_.end(), __dest);}
64
65 seed_seq(const seed_seq&) = delete;
66 void operator=(const seed_seq&) = delete;
67
68 _LIBCPP_INLINE_VISIBILITY
69 static result_type _Tp(result_type __x) {return __x ^ (__x >> 27);}
70
71private:
72 template<class _InputIterator>
73 void __init(_InputIterator __first, _InputIterator __last);
74
75 vector<result_type> __v_;
76};
77
78template<class _InputIterator>
79void
80seed_seq::__init(_InputIterator __first, _InputIterator __last)
81{
82 for (_InputIterator __s = __first; __s != __last; ++__s)
83 __v_.push_back(*__s & 0xFFFFFFFF);
84}
85
86template<class _RandomAccessIterator>
87void
88seed_seq::generate(_RandomAccessIterator __first, _RandomAccessIterator __last)
89{
90 if (__first != __last)
91 {
92 _VSTD::fill(__first, __last, 0x8b8b8b8b);
93 const size_t __n = static_cast<size_t>(__last - __first);
94 const size_t __s = __v_.size();
95 const size_t __t = (__n >= 623) ? 11
96 : (__n >= 68) ? 7
97 : (__n >= 39) ? 5
98 : (__n >= 7) ? 3
99 : (__n - 1) / 2;
100 const size_t __p = (__n - __t) / 2;
101 const size_t __q = __p + __t;
102 const size_t __m = _VSTD::max(__s + 1, __n);
103 // __k = 0;
104 {
105 result_type __r = 1664525 * _Tp(__first[0] ^ __first[__p]
106 ^ __first[__n - 1]);
107 __first[__p] += __r;
108 __r += __s;
109 __first[__q] += __r;
110 __first[0] = __r;
111 }
112 for (size_t __k = 1; __k <= __s; ++__k)
113 {
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;
122 }
123 for (size_t __k = __s + 1; __k < __m; ++__k)
124 {
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;
133 }
134 for (size_t __k = __m; __k < __m + __n; ++__k)
135 {
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;
145 }
146 }
147}
148
149_LIBCPP_END_NAMESPACE_STD
150
151_LIBCPP_POP_MACROS
152
153#endif // _LIBCPP___RANDOM_SEED_SEQ_H
lib/libcxx/include/__random/shuffle_order_engine.h created+283
......@@ -0,0 +1,283 @@
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_SHUFFLE_ORDER_ENGINE_H
10#define _LIBCPP___RANDOM_SHUFFLE_ORDER_ENGINE_H
11
12#include <__algorithm/equal.h>
13#include <__config>
14#include <__random/is_seed_sequence.h>
15#include <__utility/move.h>
16#include <cstdint>
17#include <iosfwd>
18#include <type_traits>
19
20#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21#pragma GCC system_header
22#endif
23
24_LIBCPP_PUSH_MACROS
25#include <__undef_macros>
26
27_LIBCPP_BEGIN_NAMESPACE_STD
28
29template <uint64_t _Xp, uint64_t _Yp>
30struct __ugcd
31{
32 static _LIBCPP_CONSTEXPR const uint64_t value = __ugcd<_Yp, _Xp % _Yp>::value;
33};
34
35template <uint64_t _Xp>
36struct __ugcd<_Xp, 0>
37{
38 static _LIBCPP_CONSTEXPR const uint64_t value = _Xp;
39};
40
41template <uint64_t _Np, uint64_t _Dp>
42class __uratio
43{
44 static_assert(_Dp != 0, "__uratio divide by 0");
45 static _LIBCPP_CONSTEXPR const uint64_t __gcd = __ugcd<_Np, _Dp>::value;
46public:
47 static _LIBCPP_CONSTEXPR const uint64_t num = _Np / __gcd;
48 static _LIBCPP_CONSTEXPR const uint64_t den = _Dp / __gcd;
49
50 typedef __uratio<num, den> type;
51};
52
53template<class _Engine, size_t __k>
54class _LIBCPP_TEMPLATE_VIS shuffle_order_engine
55{
56 static_assert(0 < __k, "shuffle_order_engine invalid parameters");
57public:
58 // types
59 typedef typename _Engine::result_type result_type;
60
61private:
62 _Engine __e_;
63 result_type _V_[__k];
64 result_type _Y_;
65
66public:
67 // engine characteristics
68 static _LIBCPP_CONSTEXPR const size_t table_size = __k;
69
70#ifdef _LIBCPP_CXX03_LANG
71 static const result_type _Min = _Engine::_Min;
72 static const result_type _Max = _Engine::_Max;
73#else
74 static _LIBCPP_CONSTEXPR const result_type _Min = _Engine::min();
75 static _LIBCPP_CONSTEXPR const result_type _Max = _Engine::max();
76#endif
77 static_assert(_Min < _Max, "shuffle_order_engine invalid parameters");
78 _LIBCPP_INLINE_VISIBILITY
79 static _LIBCPP_CONSTEXPR result_type min() { return _Min; }
80 _LIBCPP_INLINE_VISIBILITY
81 static _LIBCPP_CONSTEXPR result_type max() { return _Max; }
82
83 static _LIBCPP_CONSTEXPR const unsigned long long _Rp = _Max - _Min + 1ull;
84
85 // constructors and seeding functions
86 _LIBCPP_INLINE_VISIBILITY
87 shuffle_order_engine() {__init();}
88 _LIBCPP_INLINE_VISIBILITY
89 explicit shuffle_order_engine(const _Engine& __e)
90 : __e_(__e) {__init();}
91#ifndef _LIBCPP_CXX03_LANG
92 _LIBCPP_INLINE_VISIBILITY
93 explicit shuffle_order_engine(_Engine&& __e)
94 : __e_(_VSTD::move(__e)) {__init();}
95#endif // _LIBCPP_CXX03_LANG
96 _LIBCPP_INLINE_VISIBILITY
97 explicit shuffle_order_engine(result_type __sd) : __e_(__sd) {__init();}
98 template<class _Sseq>
99 _LIBCPP_INLINE_VISIBILITY
100 explicit shuffle_order_engine(_Sseq& __q,
101 typename enable_if<__is_seed_sequence<_Sseq, shuffle_order_engine>::value &&
102 !is_convertible<_Sseq, _Engine>::value>::type* = 0)
103 : __e_(__q) {__init();}
104 _LIBCPP_INLINE_VISIBILITY
105 void seed() {__e_.seed(); __init();}
106 _LIBCPP_INLINE_VISIBILITY
107 void seed(result_type __sd) {__e_.seed(__sd); __init();}
108 template<class _Sseq>
109 _LIBCPP_INLINE_VISIBILITY
110 typename enable_if
111 <
112 __is_seed_sequence<_Sseq, shuffle_order_engine>::value,
113 void
114 >::type
115 seed(_Sseq& __q) {__e_.seed(__q); __init();}
116
117 // generating functions
118 _LIBCPP_INLINE_VISIBILITY
119 result_type operator()() {return __eval(integral_constant<bool, _Rp != 0>());}
120 _LIBCPP_INLINE_VISIBILITY
121 void discard(unsigned long long __z) {for (; __z; --__z) operator()();}
122
123 // property functions
124 _LIBCPP_INLINE_VISIBILITY
125 const _Engine& base() const _NOEXCEPT {return __e_;}
126
127private:
128 template<class _Eng, size_t _Kp>
129 friend
130 bool
131 operator==(
132 const shuffle_order_engine<_Eng, _Kp>& __x,
133 const shuffle_order_engine<_Eng, _Kp>& __y);
134
135 template<class _Eng, size_t _Kp>
136 friend
137 bool
138 operator!=(
139 const shuffle_order_engine<_Eng, _Kp>& __x,
140 const shuffle_order_engine<_Eng, _Kp>& __y);
141
142 template <class _CharT, class _Traits,
143 class _Eng, size_t _Kp>
144 friend
145 basic_ostream<_CharT, _Traits>&
146 operator<<(basic_ostream<_CharT, _Traits>& __os,
147 const shuffle_order_engine<_Eng, _Kp>& __x);
148
149 template <class _CharT, class _Traits,
150 class _Eng, size_t _Kp>
151 friend
152 basic_istream<_CharT, _Traits>&
153 operator>>(basic_istream<_CharT, _Traits>& __is,
154 shuffle_order_engine<_Eng, _Kp>& __x);
155
156 _LIBCPP_INLINE_VISIBILITY
157 void __init()
158 {
159 for (size_t __i = 0; __i < __k; ++__i)
160 _V_[__i] = __e_();
161 _Y_ = __e_();
162 }
163
164 _LIBCPP_INLINE_VISIBILITY
165 result_type __eval(false_type) {return __eval2(integral_constant<bool, __k & 1>());}
166 _LIBCPP_INLINE_VISIBILITY
167 result_type __eval(true_type) {return __eval(__uratio<__k, _Rp>());}
168
169 _LIBCPP_INLINE_VISIBILITY
170 result_type __eval2(false_type) {return __eval(__uratio<__k/2, 0x8000000000000000ull>());}
171 _LIBCPP_INLINE_VISIBILITY
172 result_type __eval2(true_type) {return __evalf<__k, 0>();}
173
174 template <uint64_t _Np, uint64_t _Dp>
175 _LIBCPP_INLINE_VISIBILITY
176 typename enable_if
177 <
178 (__uratio<_Np, _Dp>::num > 0xFFFFFFFFFFFFFFFFull / (_Max - _Min)),
179 result_type
180 >::type
181 __eval(__uratio<_Np, _Dp>)
182 {return __evalf<__uratio<_Np, _Dp>::num, __uratio<_Np, _Dp>::den>();}
183
184 template <uint64_t _Np, uint64_t _Dp>
185 _LIBCPP_INLINE_VISIBILITY
186 typename enable_if
187 <
188 __uratio<_Np, _Dp>::num <= 0xFFFFFFFFFFFFFFFFull / (_Max - _Min),
189 result_type
190 >::type
191 __eval(__uratio<_Np, _Dp>)
192 {
193 const size_t __j = static_cast<size_t>(__uratio<_Np, _Dp>::num * (_Y_ - _Min)
194 / __uratio<_Np, _Dp>::den);
195 _Y_ = _V_[__j];
196 _V_[__j] = __e_();
197 return _Y_;
198 }
199
200 template <uint64_t __n, uint64_t __d>
201 _LIBCPP_INLINE_VISIBILITY
202 result_type __evalf()
203 {
204 const double _Fp = __d == 0 ?
205 __n / (2. * 0x8000000000000000ull) :
206 __n / (double)__d;
207 const size_t __j = static_cast<size_t>(_Fp * (_Y_ - _Min));
208 _Y_ = _V_[__j];
209 _V_[__j] = __e_();
210 return _Y_;
211 }
212};
213
214template<class _Engine, size_t __k>
215 _LIBCPP_CONSTEXPR const size_t shuffle_order_engine<_Engine, __k>::table_size;
216
217template<class _Eng, size_t _Kp>
218bool
219operator==(
220 const shuffle_order_engine<_Eng, _Kp>& __x,
221 const shuffle_order_engine<_Eng, _Kp>& __y)
222{
223 return __x._Y_ == __y._Y_ && _VSTD::equal(__x._V_, __x._V_ + _Kp, __y._V_) &&
224 __x.__e_ == __y.__e_;
225}
226
227template<class _Eng, size_t _Kp>
228inline _LIBCPP_INLINE_VISIBILITY
229bool
230operator!=(
231 const shuffle_order_engine<_Eng, _Kp>& __x,
232 const shuffle_order_engine<_Eng, _Kp>& __y)
233{
234 return !(__x == __y);
235}
236
237template <class _CharT, class _Traits,
238 class _Eng, size_t _Kp>
239basic_ostream<_CharT, _Traits>&
240operator<<(basic_ostream<_CharT, _Traits>& __os,
241 const shuffle_order_engine<_Eng, _Kp>& __x)
242{
243 __save_flags<_CharT, _Traits> __lx(__os);
244 typedef basic_ostream<_CharT, _Traits> _Ostream;
245 __os.flags(_Ostream::dec | _Ostream::left);
246 _CharT __sp = __os.widen(' ');
247 __os.fill(__sp);
248 __os << __x.__e_ << __sp << __x._V_[0];
249 for (size_t __i = 1; __i < _Kp; ++__i)
250 __os << __sp << __x._V_[__i];
251 return __os << __sp << __x._Y_;
252}
253
254template <class _CharT, class _Traits,
255 class _Eng, size_t _Kp>
256basic_istream<_CharT, _Traits>&
257operator>>(basic_istream<_CharT, _Traits>& __is,
258 shuffle_order_engine<_Eng, _Kp>& __x)
259{
260 typedef typename shuffle_order_engine<_Eng, _Kp>::result_type result_type;
261 __save_flags<_CharT, _Traits> __lx(__is);
262 typedef basic_istream<_CharT, _Traits> _Istream;
263 __is.flags(_Istream::dec | _Istream::skipws);
264 _Eng __e;
265 result_type _Vp[_Kp+1];
266 __is >> __e;
267 for (size_t __i = 0; __i < _Kp+1; ++__i)
268 __is >> _Vp[__i];
269 if (!__is.fail())
270 {
271 __x.__e_ = __e;
272 for (size_t __i = 0; __i < _Kp; ++__i)
273 __x._V_[__i] = _Vp[__i];
274 __x._Y_ = _Vp[_Kp];
275 }
276 return __is;
277}
278
279_LIBCPP_END_NAMESPACE_STD
280
281_LIBCPP_POP_MACROS
282
283#endif // _LIBCPP___RANDOM_SHUFFLE_ORDER_ENGINE_H
lib/libcxx/include/__random/student_t_distribution.h created+153
......@@ -0,0 +1,153 @@
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_STUDENT_T_DISTRIBUTION_H
10#define _LIBCPP___RANDOM_STUDENT_T_DISTRIBUTION_H
11
12#include <__config>
13#include <__random/gamma_distribution.h>
14#include <__random/normal_distribution.h>
15#include <cmath>
16#include <iosfwd>
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
28template<class _RealType = double>
29class _LIBCPP_TEMPLATE_VIS student_t_distribution
30{
31public:
32 // types
33 typedef _RealType result_type;
34
35 class _LIBCPP_TEMPLATE_VIS param_type
36 {
37 result_type __n_;
38 public:
39 typedef student_t_distribution distribution_type;
40
41 _LIBCPP_INLINE_VISIBILITY
42 explicit param_type(result_type __n = 1) : __n_(__n) {}
43
44 _LIBCPP_INLINE_VISIBILITY
45 result_type n() const {return __n_;}
46
47 friend _LIBCPP_INLINE_VISIBILITY
48 bool operator==(const param_type& __x, const param_type& __y)
49 {return __x.__n_ == __y.__n_;}
50 friend _LIBCPP_INLINE_VISIBILITY
51 bool operator!=(const param_type& __x, const param_type& __y)
52 {return !(__x == __y);}
53 };
54
55private:
56 param_type __p_;
57 normal_distribution<result_type> __nd_;
58
59public:
60 // constructor and reset functions
61#ifndef _LIBCPP_CXX03_LANG
62 _LIBCPP_INLINE_VISIBILITY
63 student_t_distribution() : student_t_distribution(1) {}
64 _LIBCPP_INLINE_VISIBILITY
65 explicit student_t_distribution(result_type __n)
66 : __p_(param_type(__n)) {}
67#else
68 _LIBCPP_INLINE_VISIBILITY
69 explicit student_t_distribution(result_type __n = 1)
70 : __p_(param_type(__n)) {}
71#endif
72 _LIBCPP_INLINE_VISIBILITY
73 explicit student_t_distribution(const param_type& __p)
74 : __p_(__p) {}
75 _LIBCPP_INLINE_VISIBILITY
76 void reset() {__nd_.reset();}
77
78 // generating functions
79 template<class _URNG>
80 _LIBCPP_INLINE_VISIBILITY
81 result_type operator()(_URNG& __g)
82 {return (*this)(__g, __p_);}
83 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
84
85 // property functions
86 _LIBCPP_INLINE_VISIBILITY
87 result_type n() const {return __p_.n();}
88
89 _LIBCPP_INLINE_VISIBILITY
90 param_type param() const {return __p_;}
91 _LIBCPP_INLINE_VISIBILITY
92 void param(const param_type& __p) {__p_ = __p;}
93
94 _LIBCPP_INLINE_VISIBILITY
95 result_type min() const {return -numeric_limits<result_type>::infinity();}
96 _LIBCPP_INLINE_VISIBILITY
97 result_type max() const {return numeric_limits<result_type>::infinity();}
98
99 friend _LIBCPP_INLINE_VISIBILITY
100 bool operator==(const student_t_distribution& __x,
101 const student_t_distribution& __y)
102 {return __x.__p_ == __y.__p_;}
103 friend _LIBCPP_INLINE_VISIBILITY
104 bool operator!=(const student_t_distribution& __x,
105 const student_t_distribution& __y)
106 {return !(__x == __y);}
107};
108
109template <class _RealType>
110template<class _URNG>
111_RealType
112student_t_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
113{
114 gamma_distribution<result_type> __gd(__p.n() * .5, 2);
115 return __nd_(__g) * _VSTD::sqrt(__p.n()/__gd(__g));
116}
117
118template <class _CharT, class _Traits, class _RT>
119basic_ostream<_CharT, _Traits>&
120operator<<(basic_ostream<_CharT, _Traits>& __os,
121 const student_t_distribution<_RT>& __x)
122{
123 __save_flags<_CharT, _Traits> __lx(__os);
124 typedef basic_ostream<_CharT, _Traits> _OStream;
125 __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
126 _OStream::scientific);
127 __os << __x.n();
128 return __os;
129}
130
131template <class _CharT, class _Traits, class _RT>
132basic_istream<_CharT, _Traits>&
133operator>>(basic_istream<_CharT, _Traits>& __is,
134 student_t_distribution<_RT>& __x)
135{
136 typedef student_t_distribution<_RT> _Eng;
137 typedef typename _Eng::result_type result_type;
138 typedef typename _Eng::param_type param_type;
139 __save_flags<_CharT, _Traits> __lx(__is);
140 typedef basic_istream<_CharT, _Traits> _Istream;
141 __is.flags(_Istream::dec | _Istream::skipws);
142 result_type __n;
143 __is >> __n;
144 if (!__is.fail())
145 __x.param(param_type(__n));
146 return __is;
147}
148
149_LIBCPP_END_NAMESPACE_STD
150
151_LIBCPP_POP_MACROS
152
153#endif // _LIBCPP___RANDOM_STUDENT_T_DISTRIBUTION_H
lib/libcxx/include/__random/subtract_with_carry_engine.h created+352
......@@ -0,0 +1,352 @@
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_SUBTRACT_WITH_CARRY_ENGINE_H
10#define _LIBCPP___RANDOM_SUBTRACT_WITH_CARRY_ENGINE_H
11
12#include <__algorithm/equal.h>
13#include <__algorithm/min.h>
14#include <__config>
15#include <__random/is_seed_sequence.h>
16#include <__random/linear_congruential_engine.h>
17#include <cstddef>
18#include <cstdint>
19#include <iosfwd>
20#include <limits>
21#include <type_traits>
22
23#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
24#pragma GCC system_header
25#endif
26
27_LIBCPP_PUSH_MACROS
28#include <__undef_macros>
29
30_LIBCPP_BEGIN_NAMESPACE_STD
31
32template<class _UIntType, size_t __w, size_t __s, size_t __r>
33class _LIBCPP_TEMPLATE_VIS subtract_with_carry_engine;
34
35template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
36bool
37operator==(
38 const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x,
39 const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y);
40
41template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
42_LIBCPP_INLINE_VISIBILITY
43bool
44operator!=(
45 const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x,
46 const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y);
47
48template <class _CharT, class _Traits,
49 class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
50basic_ostream<_CharT, _Traits>&
51operator<<(basic_ostream<_CharT, _Traits>& __os,
52 const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x);
53
54template <class _CharT, class _Traits,
55 class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
56basic_istream<_CharT, _Traits>&
57operator>>(basic_istream<_CharT, _Traits>& __is,
58 subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x);
59
60template<class _UIntType, size_t __w, size_t __s, size_t __r>
61class _LIBCPP_TEMPLATE_VIS subtract_with_carry_engine
62{
63public:
64 // types
65 typedef _UIntType result_type;
66
67private:
68 result_type __x_[__r];
69 result_type __c_;
70 size_t __i_;
71
72 static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits;
73 static_assert( 0 < __w, "subtract_with_carry_engine invalid parameters");
74 static_assert(__w <= _Dt, "subtract_with_carry_engine invalid parameters");
75 static_assert( 0 < __s, "subtract_with_carry_engine invalid parameters");
76 static_assert(__s < __r, "subtract_with_carry_engine invalid parameters");
77public:
78 static _LIBCPP_CONSTEXPR const result_type _Min = 0;
79 static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) :
80 (result_type(1) << __w) - result_type(1);
81 static_assert(_Min < _Max, "subtract_with_carry_engine invalid parameters");
82
83 // engine characteristics
84 static _LIBCPP_CONSTEXPR const size_t word_size = __w;
85 static _LIBCPP_CONSTEXPR const size_t short_lag = __s;
86 static _LIBCPP_CONSTEXPR const size_t long_lag = __r;
87 _LIBCPP_INLINE_VISIBILITY
88 static _LIBCPP_CONSTEXPR result_type min() { return _Min; }
89 _LIBCPP_INLINE_VISIBILITY
90 static _LIBCPP_CONSTEXPR result_type max() { return _Max; }
91 static _LIBCPP_CONSTEXPR const result_type default_seed = 19780503u;
92
93 // constructors and seeding functions
94#ifndef _LIBCPP_CXX03_LANG
95 _LIBCPP_INLINE_VISIBILITY
96 subtract_with_carry_engine() : subtract_with_carry_engine(default_seed) {}
97 _LIBCPP_INLINE_VISIBILITY
98 explicit subtract_with_carry_engine(result_type __sd) { seed(__sd); }
99#else
100 _LIBCPP_INLINE_VISIBILITY
101 explicit subtract_with_carry_engine(result_type __sd = default_seed) {
102 seed(__sd);
103 }
104#endif
105 template<class _Sseq>
106 _LIBCPP_INLINE_VISIBILITY
107 explicit subtract_with_carry_engine(_Sseq& __q,
108 typename enable_if<__is_seed_sequence<_Sseq, subtract_with_carry_engine>::value>::type* = 0)
109 {seed(__q);}
110 _LIBCPP_INLINE_VISIBILITY
111 void seed(result_type __sd = default_seed)
112 {seed(__sd, integral_constant<unsigned, 1 + (__w - 1) / 32>());}
113 template<class _Sseq>
114 _LIBCPP_INLINE_VISIBILITY
115 typename enable_if
116 <
117 __is_seed_sequence<_Sseq, subtract_with_carry_engine>::value,
118 void
119 >::type
120 seed(_Sseq& __q)
121 {__seed(__q, integral_constant<unsigned, 1 + (__w - 1) / 32>());}
122
123 // generating functions
124 result_type operator()();
125 _LIBCPP_INLINE_VISIBILITY
126 void discard(unsigned long long __z) {for (; __z; --__z) operator()();}
127
128 template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
129 friend
130 bool
131 operator==(
132 const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x,
133 const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y);
134
135 template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
136 friend
137 bool
138 operator!=(
139 const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x,
140 const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y);
141
142 template <class _CharT, class _Traits,
143 class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
144 friend
145 basic_ostream<_CharT, _Traits>&
146 operator<<(basic_ostream<_CharT, _Traits>& __os,
147 const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x);
148
149 template <class _CharT, class _Traits,
150 class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
151 friend
152 basic_istream<_CharT, _Traits>&
153 operator>>(basic_istream<_CharT, _Traits>& __is,
154 subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x);
155
156private:
157
158 void seed(result_type __sd, integral_constant<unsigned, 1>);
159 void seed(result_type __sd, integral_constant<unsigned, 2>);
160 template<class _Sseq>
161 void __seed(_Sseq& __q, integral_constant<unsigned, 1>);
162 template<class _Sseq>
163 void __seed(_Sseq& __q, integral_constant<unsigned, 2>);
164};
165
166template<class _UIntType, size_t __w, size_t __s, size_t __r>
167 _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::word_size;
168
169template<class _UIntType, size_t __w, size_t __s, size_t __r>
170 _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::short_lag;
171
172template<class _UIntType, size_t __w, size_t __s, size_t __r>
173 _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::long_lag;
174
175template<class _UIntType, size_t __w, size_t __s, size_t __r>
176 _LIBCPP_CONSTEXPR const typename subtract_with_carry_engine<_UIntType, __w, __s, __r>::result_type
177 subtract_with_carry_engine<_UIntType, __w, __s, __r>::default_seed;
178
179template<class _UIntType, size_t __w, size_t __s, size_t __r>
180void
181subtract_with_carry_engine<_UIntType, __w, __s, __r>::seed(result_type __sd,
182 integral_constant<unsigned, 1>)
183{
184 linear_congruential_engine<result_type, 40014u, 0u, 2147483563u>
185 __e(__sd == 0u ? default_seed : __sd);
186 for (size_t __i = 0; __i < __r; ++__i)
187 __x_[__i] = static_cast<result_type>(__e() & _Max);
188 __c_ = __x_[__r-1] == 0;
189 __i_ = 0;
190}
191
192template<class _UIntType, size_t __w, size_t __s, size_t __r>
193void
194subtract_with_carry_engine<_UIntType, __w, __s, __r>::seed(result_type __sd,
195 integral_constant<unsigned, 2>)
196{
197 linear_congruential_engine<result_type, 40014u, 0u, 2147483563u>
198 __e(__sd == 0u ? default_seed : __sd);
199 for (size_t __i = 0; __i < __r; ++__i)
200 {
201 result_type __e0 = __e();
202 __x_[__i] = static_cast<result_type>(
203 (__e0 + ((uint64_t)__e() << 32)) & _Max);
204 }
205 __c_ = __x_[__r-1] == 0;
206 __i_ = 0;
207}
208
209template<class _UIntType, size_t __w, size_t __s, size_t __r>
210template<class _Sseq>
211void
212subtract_with_carry_engine<_UIntType, __w, __s, __r>::__seed(_Sseq& __q,
213 integral_constant<unsigned, 1>)
214{
215 const unsigned __k = 1;
216 uint32_t __ar[__r * __k];
217 __q.generate(__ar, __ar + __r * __k);
218 for (size_t __i = 0; __i < __r; ++__i)
219 __x_[__i] = static_cast<result_type>(__ar[__i] & _Max);
220 __c_ = __x_[__r-1] == 0;
221 __i_ = 0;
222}
223
224template<class _UIntType, size_t __w, size_t __s, size_t __r>
225template<class _Sseq>
226void
227subtract_with_carry_engine<_UIntType, __w, __s, __r>::__seed(_Sseq& __q,
228 integral_constant<unsigned, 2>)
229{
230 const unsigned __k = 2;
231 uint32_t __ar[__r * __k];
232 __q.generate(__ar, __ar + __r * __k);
233 for (size_t __i = 0; __i < __r; ++__i)
234 __x_[__i] = static_cast<result_type>(
235 (__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max);
236 __c_ = __x_[__r-1] == 0;
237 __i_ = 0;
238}
239
240template<class _UIntType, size_t __w, size_t __s, size_t __r>
241_UIntType
242subtract_with_carry_engine<_UIntType, __w, __s, __r>::operator()()
243{
244 const result_type& __xs = __x_[(__i_ + (__r - __s)) % __r];
245 result_type& __xr = __x_[__i_];
246 result_type __new_c = __c_ == 0 ? __xs < __xr : __xs != 0 ? __xs <= __xr : 1;
247 __xr = (__xs - __xr - __c_) & _Max;
248 __c_ = __new_c;
249 __i_ = (__i_ + 1) % __r;
250 return __xr;
251}
252
253template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
254bool
255operator==(
256 const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x,
257 const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y)
258{
259 if (__x.__c_ != __y.__c_)
260 return false;
261 if (__x.__i_ == __y.__i_)
262 return _VSTD::equal(__x.__x_, __x.__x_ + _Rp, __y.__x_);
263 if (__x.__i_ == 0 || __y.__i_ == 0)
264 {
265 size_t __j = _VSTD::min(_Rp - __x.__i_, _Rp - __y.__i_);
266 if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + __x.__i_ + __j,
267 __y.__x_ + __y.__i_))
268 return false;
269 if (__x.__i_ == 0)
270 return _VSTD::equal(__x.__x_ + __j, __x.__x_ + _Rp, __y.__x_);
271 return _VSTD::equal(__x.__x_, __x.__x_ + (_Rp - __j), __y.__x_ + __j);
272 }
273 if (__x.__i_ < __y.__i_)
274 {
275 size_t __j = _Rp - __y.__i_;
276 if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + (__x.__i_ + __j),
277 __y.__x_ + __y.__i_))
278 return false;
279 if (!_VSTD::equal(__x.__x_ + (__x.__i_ + __j), __x.__x_ + _Rp,
280 __y.__x_))
281 return false;
282 return _VSTD::equal(__x.__x_, __x.__x_ + __x.__i_,
283 __y.__x_ + (_Rp - (__x.__i_ + __j)));
284 }
285 size_t __j = _Rp - __x.__i_;
286 if (!_VSTD::equal(__y.__x_ + __y.__i_, __y.__x_ + (__y.__i_ + __j),
287 __x.__x_ + __x.__i_))
288 return false;
289 if (!_VSTD::equal(__y.__x_ + (__y.__i_ + __j), __y.__x_ + _Rp,
290 __x.__x_))
291 return false;
292 return _VSTD::equal(__y.__x_, __y.__x_ + __y.__i_,
293 __x.__x_ + (_Rp - (__y.__i_ + __j)));
294}
295
296template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
297inline _LIBCPP_INLINE_VISIBILITY
298bool
299operator!=(
300 const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x,
301 const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y)
302{
303 return !(__x == __y);
304}
305
306template <class _CharT, class _Traits,
307 class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
308basic_ostream<_CharT, _Traits>&
309operator<<(basic_ostream<_CharT, _Traits>& __os,
310 const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x)
311{
312 __save_flags<_CharT, _Traits> __lx(__os);
313 typedef basic_ostream<_CharT, _Traits> _Ostream;
314 __os.flags(_Ostream::dec | _Ostream::left);
315 _CharT __sp = __os.widen(' ');
316 __os.fill(__sp);
317 __os << __x.__x_[__x.__i_];
318 for (size_t __j = __x.__i_ + 1; __j < _Rp; ++__j)
319 __os << __sp << __x.__x_[__j];
320 for (size_t __j = 0; __j < __x.__i_; ++__j)
321 __os << __sp << __x.__x_[__j];
322 __os << __sp << __x.__c_;
323 return __os;
324}
325
326template <class _CharT, class _Traits,
327 class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
328basic_istream<_CharT, _Traits>&
329operator>>(basic_istream<_CharT, _Traits>& __is,
330 subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x)
331{
332 __save_flags<_CharT, _Traits> __lx(__is);
333 typedef basic_istream<_CharT, _Traits> _Istream;
334 __is.flags(_Istream::dec | _Istream::skipws);
335 _UInt __t[_Rp+1];
336 for (size_t __i = 0; __i < _Rp+1; ++__i)
337 __is >> __t[__i];
338 if (!__is.fail())
339 {
340 for (size_t __i = 0; __i < _Rp; ++__i)
341 __x.__x_[__i] = __t[__i];
342 __x.__c_ = __t[_Rp];
343 __x.__i_ = 0;
344 }
345 return __is;
346}
347
348_LIBCPP_END_NAMESPACE_STD
349
350_LIBCPP_POP_MACROS
351
352#endif // _LIBCPP___RANDOM_SUBTRACT_WITH_CARRY_ENGINE_H
lib/libcxx/include/__random/uniform_int_distribution.h+6-32
......@@ -11,6 +11,8 @@
1111
1212#include <__bits>
1313#include <__config>
14#include <__random/log2.h>
15#include <bit>
1416#include <cstddef>
1517#include <cstdint>
1618#include <iosfwd>
......@@ -26,34 +28,6 @@ _LIBCPP_PUSH_MACROS
2628
2729_LIBCPP_BEGIN_NAMESPACE_STD
2830
29// __independent_bits_engine
30
31template <unsigned long long _Xp, size_t _Rp>
32struct __log2_imp
33{
34 static const size_t value = _Xp & ((unsigned long long)(1) << _Rp) ? _Rp
35 : __log2_imp<_Xp, _Rp - 1>::value;
36};
37
38template <unsigned long long _Xp>
39struct __log2_imp<_Xp, 0>
40{
41 static const size_t value = 0;
42};
43
44template <size_t _Rp>
45struct __log2_imp<0, _Rp>
46{
47 static const size_t value = _Rp + 1;
48};
49
50template <class _UIntType, _UIntType _Xp>
51struct __log2
52{
53 static const size_t value = __log2_imp<_Xp,
54 sizeof(_UIntType) * __CHAR_BIT__ - 1>::value;
55};
56
5731template<class _Engine, class _UIntType>
5832class __independent_bits_engine
5933{
......@@ -181,7 +155,7 @@ __independent_bits_engine<_Engine, _UIntType>::__eval(true_type)
181155 return _Sp;
182156}
183157
184template<class _IntType = int>
158template<class _IntType = int> // __int128_t is also supported as an extension here
185159class uniform_int_distribution
186160{
187161public:
......@@ -256,8 +230,8 @@ typename uniform_int_distribution<_IntType>::result_type
256230uniform_int_distribution<_IntType>::operator()(_URNG& __g, const param_type& __p)
257231_LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
258232{
259 typedef typename conditional<sizeof(result_type) <= sizeof(uint32_t),
260 uint32_t, uint64_t>::type _UIntType;
233 typedef typename conditional<sizeof(result_type) <= sizeof(uint32_t), uint32_t,
234 typename make_unsigned<result_type>::type>::type _UIntType;
261235 const _UIntType _Rp = _UIntType(__p.b()) - _UIntType(__p.a()) + _UIntType(1);
262236 if (_Rp == 1)
263237 return __p.a();
......@@ -265,7 +239,7 @@ _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
265239 typedef __independent_bits_engine<_URNG, _UIntType> _Eng;
266240 if (_Rp == 0)
267241 return static_cast<result_type>(_Eng(__g, _Dt)());
268 size_t __w = _Dt - __libcpp_clz(_Rp) - 1;
242 size_t __w = _Dt - __countl_zero(_Rp) - 1;
269243 if ((_Rp & (numeric_limits<_UIntType>::max() >> (_Dt - __w))) != 0)
270244 ++__w;
271245 _Eng __e(__g, __w);
lib/libcxx/include/__random/uniform_random_bit_generator.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___RANDOM_UNIFORM_RANDOM_BIT_GENERATOR_H
10#define _LIBCPP___RANDOM_UNIFORM_RANDOM_BIT_GENERATOR_H
11
12#include <__concepts/arithmetic.h>
13#include <__concepts/invocable.h>
14#include <__concepts/same_as.h>
15#include <__config>
16#include <type_traits>
17
18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
20#endif
21
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
25_LIBCPP_BEGIN_NAMESPACE_STD
26
27#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
28
29// [rand.req.urng]
30template<class _Gen>
31concept uniform_random_bit_generator =
32 invocable<_Gen&> && unsigned_integral<invoke_result_t<_Gen&>> &&
33 requires {
34 { _Gen::min() } -> same_as<invoke_result_t<_Gen&>>;
35 { _Gen::max() } -> same_as<invoke_result_t<_Gen&>>;
36 requires bool_constant<(_Gen::min() < _Gen::max())>::value;
37 };
38
39#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
40
41_LIBCPP_END_NAMESPACE_STD
42
43_LIBCPP_POP_MACROS
44
45#endif // _LIBCPP___RANDOM_UNIFORM_RANDOM_BIT_GENERATOR_H
lib/libcxx/include/__random/uniform_real_distribution.h created+160
......@@ -0,0 +1,160 @@
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_UNIFORM_REAL_DISTRIBUTION_H
10#define _LIBCPP___RANDOM_UNIFORM_REAL_DISTRIBUTION_H
11
12#include <__config>
13#include <__random/generate_canonical.h>
14#include <iosfwd>
15#include <limits>
16#include <type_traits>
17
18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
20#endif
21
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
25_LIBCPP_BEGIN_NAMESPACE_STD
26
27template<class _RealType = double>
28class _LIBCPP_TEMPLATE_VIS uniform_real_distribution
29{
30public:
31 // types
32 typedef _RealType result_type;
33
34 class _LIBCPP_TEMPLATE_VIS param_type
35 {
36 result_type __a_;
37 result_type __b_;
38 public:
39 typedef uniform_real_distribution distribution_type;
40
41 _LIBCPP_INLINE_VISIBILITY
42 explicit param_type(result_type __a = 0,
43 result_type __b = 1)
44 : __a_(__a), __b_(__b) {}
45
46 _LIBCPP_INLINE_VISIBILITY
47 result_type a() const {return __a_;}
48 _LIBCPP_INLINE_VISIBILITY
49 result_type b() const {return __b_;}
50
51 friend _LIBCPP_INLINE_VISIBILITY
52 bool operator==(const param_type& __x, const param_type& __y)
53 {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;}
54 friend _LIBCPP_INLINE_VISIBILITY
55 bool operator!=(const param_type& __x, const param_type& __y)
56 {return !(__x == __y);}
57 };
58
59private:
60 param_type __p_;
61
62public:
63 // constructors and reset functions
64#ifndef _LIBCPP_CXX03_LANG
65 _LIBCPP_INLINE_VISIBILITY
66 uniform_real_distribution() : uniform_real_distribution(0) {}
67 explicit uniform_real_distribution(result_type __a, result_type __b = 1)
68 : __p_(param_type(__a, __b)) {}
69#else
70 _LIBCPP_INLINE_VISIBILITY
71 explicit uniform_real_distribution(result_type __a = 0, result_type __b = 1)
72 : __p_(param_type(__a, __b)) {}
73#endif
74 _LIBCPP_INLINE_VISIBILITY
75 explicit uniform_real_distribution(const param_type& __p) : __p_(__p) {}
76 _LIBCPP_INLINE_VISIBILITY
77 void reset() {}
78
79 // generating functions
80 template<class _URNG>
81 _LIBCPP_INLINE_VISIBILITY
82 result_type operator()(_URNG& __g)
83 {return (*this)(__g, __p_);}
84 template<class _URNG> _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g, const param_type& __p);
85
86 // property functions
87 _LIBCPP_INLINE_VISIBILITY
88 result_type a() const {return __p_.a();}
89 _LIBCPP_INLINE_VISIBILITY
90 result_type b() const {return __p_.b();}
91
92 _LIBCPP_INLINE_VISIBILITY
93 param_type param() const {return __p_;}
94 _LIBCPP_INLINE_VISIBILITY
95 void param(const param_type& __p) {__p_ = __p;}
96
97 _LIBCPP_INLINE_VISIBILITY
98 result_type min() const {return a();}
99 _LIBCPP_INLINE_VISIBILITY
100 result_type max() const {return b();}
101
102 friend _LIBCPP_INLINE_VISIBILITY
103 bool operator==(const uniform_real_distribution& __x,
104 const uniform_real_distribution& __y)
105 {return __x.__p_ == __y.__p_;}
106 friend _LIBCPP_INLINE_VISIBILITY
107 bool operator!=(const uniform_real_distribution& __x,
108 const uniform_real_distribution& __y)
109 {return !(__x == __y);}
110};
111
112template<class _RealType>
113template<class _URNG>
114inline
115typename uniform_real_distribution<_RealType>::result_type
116uniform_real_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
117{
118 return (__p.b() - __p.a())
119 * _VSTD::generate_canonical<_RealType, numeric_limits<_RealType>::digits>(__g)
120 + __p.a();
121}
122
123template <class _CharT, class _Traits, class _RT>
124basic_ostream<_CharT, _Traits>&
125operator<<(basic_ostream<_CharT, _Traits>& __os,
126 const uniform_real_distribution<_RT>& __x)
127{
128 __save_flags<_CharT, _Traits> __lx(__os);
129 typedef basic_ostream<_CharT, _Traits> _OStream;
130 __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
131 _OStream::scientific);
132 _CharT __sp = __os.widen(' ');
133 __os.fill(__sp);
134 return __os << __x.a() << __sp << __x.b();
135}
136
137template <class _CharT, class _Traits, class _RT>
138basic_istream<_CharT, _Traits>&
139operator>>(basic_istream<_CharT, _Traits>& __is,
140 uniform_real_distribution<_RT>& __x)
141{
142 typedef uniform_real_distribution<_RT> _Eng;
143 typedef typename _Eng::result_type result_type;
144 typedef typename _Eng::param_type param_type;
145 __save_flags<_CharT, _Traits> __lx(__is);
146 typedef basic_istream<_CharT, _Traits> _Istream;
147 __is.flags(_Istream::dec | _Istream::skipws);
148 result_type __a;
149 result_type __b;
150 __is >> __a >> __b;
151 if (!__is.fail())
152 __x.param(param_type(__a, __b));
153 return __is;
154}
155
156_LIBCPP_END_NAMESPACE_STD
157
158_LIBCPP_POP_MACROS
159
160#endif // _LIBCPP___RANDOM_UNIFORM_REAL_DISTRIBUTION_H
lib/libcxx/include/__random/weibull_distribution.h created+155
......@@ -0,0 +1,155 @@
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_WEIBULL_DISTRIBUTION_H
10#define _LIBCPP___RANDOM_WEIBULL_DISTRIBUTION_H
11
12#include <__config>
13#include <__random/exponential_distribution.h>
14#include <cmath>
15#include <iosfwd>
16#include <limits>
17
18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
20#endif
21
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
25_LIBCPP_BEGIN_NAMESPACE_STD
26
27template<class _RealType = double>
28class _LIBCPP_TEMPLATE_VIS weibull_distribution
29{
30public:
31 // types
32 typedef _RealType result_type;
33
34 class _LIBCPP_TEMPLATE_VIS param_type
35 {
36 result_type __a_;
37 result_type __b_;
38 public:
39 typedef weibull_distribution distribution_type;
40
41 _LIBCPP_INLINE_VISIBILITY
42 explicit param_type(result_type __a = 1, result_type __b = 1)
43 : __a_(__a), __b_(__b) {}
44
45 _LIBCPP_INLINE_VISIBILITY
46 result_type a() const {return __a_;}
47 _LIBCPP_INLINE_VISIBILITY
48 result_type b() const {return __b_;}
49
50 friend _LIBCPP_INLINE_VISIBILITY
51 bool operator==(const param_type& __x, const param_type& __y)
52 {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;}
53 friend _LIBCPP_INLINE_VISIBILITY
54 bool operator!=(const param_type& __x, const param_type& __y)
55 {return !(__x == __y);}
56 };
57
58private:
59 param_type __p_;
60
61public:
62 // constructor and reset functions
63#ifndef _LIBCPP_CXX03_LANG
64 _LIBCPP_INLINE_VISIBILITY
65 weibull_distribution() : weibull_distribution(1) {}
66 _LIBCPP_INLINE_VISIBILITY
67 explicit weibull_distribution(result_type __a, result_type __b = 1)
68 : __p_(param_type(__a, __b)) {}
69#else
70 _LIBCPP_INLINE_VISIBILITY
71 explicit weibull_distribution(result_type __a = 1, result_type __b = 1)
72 : __p_(param_type(__a, __b)) {}
73#endif
74 _LIBCPP_INLINE_VISIBILITY
75 explicit weibull_distribution(const param_type& __p)
76 : __p_(__p) {}
77 _LIBCPP_INLINE_VISIBILITY
78 void reset() {}
79
80 // generating functions
81 template<class _URNG>
82 _LIBCPP_INLINE_VISIBILITY
83 result_type operator()(_URNG& __g)
84 {return (*this)(__g, __p_);}
85 template<class _URNG>
86 _LIBCPP_INLINE_VISIBILITY
87 result_type operator()(_URNG& __g, const param_type& __p)
88 {return __p.b() *
89 _VSTD::pow(exponential_distribution<result_type>()(__g), 1/__p.a());}
90
91 // property functions
92 _LIBCPP_INLINE_VISIBILITY
93 result_type a() const {return __p_.a();}
94 _LIBCPP_INLINE_VISIBILITY
95 result_type b() const {return __p_.b();}
96
97 _LIBCPP_INLINE_VISIBILITY
98 param_type param() const {return __p_;}
99 _LIBCPP_INLINE_VISIBILITY
100 void param(const param_type& __p) {__p_ = __p;}
101
102 _LIBCPP_INLINE_VISIBILITY
103 result_type min() const {return 0;}
104 _LIBCPP_INLINE_VISIBILITY
105 result_type max() const {return numeric_limits<result_type>::infinity();}
106
107 friend _LIBCPP_INLINE_VISIBILITY
108 bool operator==(const weibull_distribution& __x,
109 const weibull_distribution& __y)
110 {return __x.__p_ == __y.__p_;}
111 friend _LIBCPP_INLINE_VISIBILITY
112 bool operator!=(const weibull_distribution& __x,
113 const weibull_distribution& __y)
114 {return !(__x == __y);}
115};
116
117template <class _CharT, class _Traits, class _RT>
118basic_ostream<_CharT, _Traits>&
119operator<<(basic_ostream<_CharT, _Traits>& __os,
120 const weibull_distribution<_RT>& __x)
121{
122 __save_flags<_CharT, _Traits> __lx(__os);
123 typedef basic_ostream<_CharT, _Traits> _OStream;
124 __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
125 _OStream::scientific);
126 _CharT __sp = __os.widen(' ');
127 __os.fill(__sp);
128 __os << __x.a() << __sp << __x.b();
129 return __os;
130}
131
132template <class _CharT, class _Traits, class _RT>
133basic_istream<_CharT, _Traits>&
134operator>>(basic_istream<_CharT, _Traits>& __is,
135 weibull_distribution<_RT>& __x)
136{
137 typedef weibull_distribution<_RT> _Eng;
138 typedef typename _Eng::result_type result_type;
139 typedef typename _Eng::param_type param_type;
140 __save_flags<_CharT, _Traits> __lx(__is);
141 typedef basic_istream<_CharT, _Traits> _Istream;
142 __is.flags(_Istream::dec | _Istream::skipws);
143 result_type __a;
144 result_type __b;
145 __is >> __a >> __b;
146 if (!__is.fail())
147 __x.param(param_type(__a, __b));
148 return __is;
149}
150
151_LIBCPP_END_NAMESPACE_STD
152
153_LIBCPP_POP_MACROS
154
155#endif // _LIBCPP___RANDOM_WEIBULL_DISTRIBUTION_H
lib/libcxx/include/__ranges/access.h+100-95
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===------------------------ __ranges/access.h ---------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -9,12 +9,13 @@
99#ifndef _LIBCPP___RANGES_ACCESS_H
1010#define _LIBCPP___RANGES_ACCESS_H
1111
12#include <__concepts/class_or_enum.h>
1213#include <__config>
1314#include <__iterator/concepts.h>
1415#include <__iterator/readable_traits.h>
1516#include <__ranges/enable_borrowed_range.h>
16#include <__utility/__decay_copy.h>
17#include <__utility/forward.h>
17#include <__utility/as_const.h>
18#include <__utility/auto_cast.h>
1819#include <concepts>
1920#include <type_traits>
2021
......@@ -22,31 +23,26 @@
2223#pragma GCC system_header
2324#endif
2425
25_LIBCPP_PUSH_MACROS
26#include <__undef_macros>
27
2826_LIBCPP_BEGIN_NAMESPACE_STD
2927
30#if !defined(_LIBCPP_HAS_NO_RANGES)
31
32// clang-format off
28#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
3329
3430namespace ranges {
3531 template <class _Tp>
3632 concept __can_borrow =
37 is_lvalue_reference_v<_Tp> || enable_borrowed_range<remove_cvref_t<_Tp> >;
38
39 template<class _Tp>
40 concept __is_complete = requires { sizeof(_Tp); };
33 is_lvalue_reference_v<_Tp> || enable_borrowed_range<remove_cvref_t<_Tp>>;
4134} // namespace ranges
4235
4336// [range.access.begin]
44namespace ranges::__begin {
37
38namespace ranges {
39namespace __begin {
4540 template <class _Tp>
4641 concept __member_begin =
4742 __can_borrow<_Tp> &&
43 __workaround_52970<_Tp> &&
4844 requires(_Tp&& __t) {
49 { _VSTD::__decay_copy(__t.begin()) } -> input_or_output_iterator;
45 { _LIBCPP_AUTO_CAST(__t.begin()) } -> input_or_output_iterator;
5046 };
5147
5248 void begin(auto&) = delete;
......@@ -56,61 +52,69 @@ namespace ranges::__begin {
5652 concept __unqualified_begin =
5753 !__member_begin<_Tp> &&
5854 __can_borrow<_Tp> &&
59 __class_or_enum<remove_cvref_t<_Tp> > &&
55 __class_or_enum<remove_cvref_t<_Tp>> &&
6056 requires(_Tp && __t) {
61 { _VSTD::__decay_copy(begin(__t)) } -> input_or_output_iterator;
57 { _LIBCPP_AUTO_CAST(begin(__t)) } -> input_or_output_iterator;
6258 };
6359
6460 struct __fn {
6561 template <class _Tp>
66 requires is_array_v<remove_cv_t<_Tp>>
67 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp& __t) const noexcept {
68 constexpr bool __complete = __is_complete<iter_value_t<_Tp> >;
69 if constexpr (__complete) { // used to disable cryptic diagnostic
70 return __t + 0;
71 }
72 else {
73 static_assert(__complete, "`std::ranges::begin` is SFINAE-unfriendly on arrays of an incomplete type.");
74 }
62 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp (&__t)[]) const noexcept
63 requires (sizeof(_Tp) != 0) // Disallow incomplete element types.
64 {
65 return __t + 0;
66 }
67
68 template <class _Tp, size_t _Np>
69 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp (&__t)[_Np]) const noexcept
70 requires (sizeof(_Tp) != 0) // Disallow incomplete element types.
71 {
72 return __t + 0;
7573 }
7674
7775 template <class _Tp>
78 requires __member_begin<_Tp>
76 requires __member_begin<_Tp>
7977 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
80 noexcept(noexcept(_VSTD::__decay_copy(__t.begin())))
78 noexcept(noexcept(_LIBCPP_AUTO_CAST(__t.begin())))
8179 {
82 return __t.begin();
80 return _LIBCPP_AUTO_CAST(__t.begin());
8381 }
8482
8583 template <class _Tp>
86 requires __unqualified_begin<_Tp>
84 requires __unqualified_begin<_Tp>
8785 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
88 noexcept(noexcept(_VSTD::__decay_copy(begin(__t))))
86 noexcept(noexcept(_LIBCPP_AUTO_CAST(begin(__t))))
8987 {
90 return begin(__t);
88 return _LIBCPP_AUTO_CAST(begin(__t));
9189 }
9290
9391 void operator()(auto&&) const = delete;
9492 };
95} // namespace ranges::__begin
93} // namespace __begin
9694
97namespace ranges {
98 inline namespace __cpo {
99 inline constexpr auto begin = __begin::__fn{};
100 } // namespace __cpo
95inline namespace __cpo {
96 inline constexpr auto begin = __begin::__fn{};
97} // namespace __cpo
98} // namespace ranges
10199
100// [range.range]
101
102namespace ranges {
102103 template <class _Tp>
103104 using iterator_t = decltype(ranges::begin(declval<_Tp&>()));
104105} // namespace ranges
105106
106107// [range.access.end]
107namespace ranges::__end {
108
109namespace ranges {
110namespace __end {
108111 template <class _Tp>
109112 concept __member_end =
110113 __can_borrow<_Tp> &&
114 __workaround_52970<_Tp> &&
111115 requires(_Tp&& __t) {
112116 typename iterator_t<_Tp>;
113 { _VSTD::__decay_copy(_VSTD::forward<_Tp>(__t).end()) } -> sentinel_for<iterator_t<_Tp> >;
117 { _LIBCPP_AUTO_CAST(__t.end()) } -> sentinel_for<iterator_t<_Tp>>;
114118 };
115119
116120 void end(auto&) = delete;
......@@ -120,103 +124,104 @@ namespace ranges::__end {
120124 concept __unqualified_end =
121125 !__member_end<_Tp> &&
122126 __can_borrow<_Tp> &&
123 __class_or_enum<remove_cvref_t<_Tp> > &&
127 __class_or_enum<remove_cvref_t<_Tp>> &&
124128 requires(_Tp && __t) {
125129 typename iterator_t<_Tp>;
126 { _VSTD::__decay_copy(end(_VSTD::forward<_Tp>(__t))) } -> sentinel_for<iterator_t<_Tp> >;
130 { _LIBCPP_AUTO_CAST(end(__t)) } -> sentinel_for<iterator_t<_Tp>>;
127131 };
128132
129133 class __fn {
130134 public:
131135 template <class _Tp, size_t _Np>
132 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp (&__t)[_Np]) const noexcept {
133 constexpr bool __complete = __is_complete<remove_cv_t<_Tp> >;
134 if constexpr (__complete) { // used to disable cryptic diagnostic
135 return __t + _Np;
136 }
137 else {
138 static_assert(__complete, "`std::ranges::end` is SFINAE-unfriendly on arrays of an incomplete type.");
139 }
136 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp (&__t)[_Np]) const noexcept
137 requires (sizeof(_Tp) != 0) // Disallow incomplete element types.
138 {
139 return __t + _Np;
140140 }
141141
142142 template <class _Tp>
143 requires __member_end<_Tp>
143 requires __member_end<_Tp>
144144 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
145 noexcept(noexcept(_VSTD::__decay_copy(__t.end())))
145 noexcept(noexcept(_LIBCPP_AUTO_CAST(__t.end())))
146146 {
147 return _VSTD::forward<_Tp>(__t).end();
147 return _LIBCPP_AUTO_CAST(__t.end());
148148 }
149149
150150 template <class _Tp>
151 requires __unqualified_end<_Tp>
151 requires __unqualified_end<_Tp>
152152 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
153 noexcept(noexcept(_VSTD::__decay_copy(end(__t))))
153 noexcept(noexcept(_LIBCPP_AUTO_CAST(end(__t))))
154154 {
155 return end(__t);
155 return _LIBCPP_AUTO_CAST(end(__t));
156156 }
157157
158158 void operator()(auto&&) const = delete;
159159 };
160} // namespace ranges::__end
160} // namespace __end
161161
162namespace ranges::inline __cpo {
162inline namespace __cpo {
163163 inline constexpr auto end = __end::__fn{};
164} // namespace ranges::__cpo
164} // namespace __cpo
165} // namespace ranges
165166
166namespace ranges::__cbegin {
167// [range.access.cbegin]
168
169namespace ranges {
170namespace __cbegin {
167171 struct __fn {
168172 template <class _Tp>
169 requires invocable<decltype(ranges::begin), _Tp const&>
170 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp& __t) const
171 noexcept(noexcept(ranges::begin(_VSTD::as_const(__t))))
172 {
173 return ranges::begin(_VSTD::as_const(__t));
174 }
173 requires is_lvalue_reference_v<_Tp&&>
174 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
175 constexpr auto operator()(_Tp&& __t) const
176 noexcept(noexcept(ranges::begin(static_cast<const remove_reference_t<_Tp>&>(__t))))
177 -> decltype( ranges::begin(static_cast<const remove_reference_t<_Tp>&>(__t)))
178 { return ranges::begin(static_cast<const remove_reference_t<_Tp>&>(__t)); }
175179
176180 template <class _Tp>
177 requires is_rvalue_reference_v<_Tp> && invocable<decltype(ranges::begin), _Tp const&&>
178 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
179 noexcept(noexcept(ranges::begin(static_cast<_Tp const&&>(__t))))
180 {
181 return ranges::begin(static_cast<_Tp const&&>(__t));
182 }
181 requires is_rvalue_reference_v<_Tp&&>
182 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
183 constexpr auto operator()(_Tp&& __t) const
184 noexcept(noexcept(ranges::begin(static_cast<const _Tp&&>(__t))))
185 -> decltype( ranges::begin(static_cast<const _Tp&&>(__t)))
186 { return ranges::begin(static_cast<const _Tp&&>(__t)); }
183187 };
184} // namespace ranges::__cbegin
188} // namespace __cbegin
185189
186namespace ranges::inline __cpo {
190inline namespace __cpo {
187191 inline constexpr auto cbegin = __cbegin::__fn{};
188} // namespace ranges::__cpo
192} // namespace __cpo
193} // namespace ranges
194
195// [range.access.cend]
189196
190namespace ranges::__cend {
197namespace ranges {
198namespace __cend {
191199 struct __fn {
192200 template <class _Tp>
193 requires invocable<decltype(ranges::end), _Tp const&>
194 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp& __t) const
195 noexcept(noexcept(ranges::end(_VSTD::as_const(__t))))
196 {
197 return ranges::end(_VSTD::as_const(__t));
198 }
201 requires is_lvalue_reference_v<_Tp&&>
202 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
203 constexpr auto operator()(_Tp&& __t) const
204 noexcept(noexcept(ranges::end(static_cast<const remove_reference_t<_Tp>&>(__t))))
205 -> decltype( ranges::end(static_cast<const remove_reference_t<_Tp>&>(__t)))
206 { return ranges::end(static_cast<const remove_reference_t<_Tp>&>(__t)); }
199207
200208 template <class _Tp>
201 requires is_rvalue_reference_v<_Tp> && invocable<decltype(ranges::end), _Tp const&&>
202 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
203 noexcept(noexcept(ranges::end(static_cast<_Tp const&&>(__t))))
204 {
205 return ranges::end(static_cast<_Tp const&&>(__t));
206 }
209 requires is_rvalue_reference_v<_Tp&&>
210 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
211 constexpr auto operator()(_Tp&& __t) const
212 noexcept(noexcept(ranges::end(static_cast<const _Tp&&>(__t))))
213 -> decltype( ranges::end(static_cast<const _Tp&&>(__t)))
214 { return ranges::end(static_cast<const _Tp&&>(__t)); }
207215 };
208} // namespace ranges::__cend
216} // namespace __cend
209217
210namespace ranges::inline __cpo {
218inline namespace __cpo {
211219 inline constexpr auto cend = __cend::__fn{};
212} // namespace ranges::__cpo
213
214// clang-format off
220} // namespace __cpo
221} // namespace ranges
215222
216#endif // !defined(_LIBCPP_HAS_NO_RANGES)
223#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
217224
218225_LIBCPP_END_NAMESPACE_STD
219226
220_LIBCPP_POP_MACROS
221
222227#endif // _LIBCPP___RANGES_ACCESS_H
lib/libcxx/include/__ranges/all.h+17-21
......@@ -14,9 +14,10 @@
1414#include <__iterator/iterator_traits.h>
1515#include <__ranges/access.h>
1616#include <__ranges/concepts.h>
17#include <__ranges/owning_view.h>
18#include <__ranges/range_adaptor.h>
1719#include <__ranges/ref_view.h>
18#include <__ranges/subrange.h>
19#include <__utility/__decay_copy.h>
20#include <__utility/auto_cast.h>
2021#include <__utility/declval.h>
2122#include <__utility/forward.h>
2223#include <type_traits>
......@@ -25,30 +26,27 @@
2526#pragma GCC system_header
2627#endif
2728
28_LIBCPP_PUSH_MACROS
29#include <__undef_macros>
30
3129_LIBCPP_BEGIN_NAMESPACE_STD
3230
33#if !defined(_LIBCPP_HAS_NO_RANGES)
31#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
3432
35namespace views {
33namespace ranges::views {
3634
3735namespace __all {
38 struct __fn {
36 struct __fn : __range_adaptor_closure<__fn> {
3937 template<class _Tp>
4038 requires ranges::view<decay_t<_Tp>>
41 _LIBCPP_HIDE_FROM_ABI
39 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
4240 constexpr auto operator()(_Tp&& __t) const
43 noexcept(noexcept(_VSTD::__decay_copy(_VSTD::forward<_Tp>(__t))))
41 noexcept(noexcept(_LIBCPP_AUTO_CAST(_VSTD::forward<_Tp>(__t))))
4442 {
45 return _VSTD::forward<_Tp>(__t);
43 return _LIBCPP_AUTO_CAST(_VSTD::forward<_Tp>(__t));
4644 }
4745
4846 template<class _Tp>
4947 requires (!ranges::view<decay_t<_Tp>>) &&
5048 requires (_Tp&& __t) { ranges::ref_view{_VSTD::forward<_Tp>(__t)}; }
51 _LIBCPP_HIDE_FROM_ABI
49 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
5250 constexpr auto operator()(_Tp&& __t) const
5351 noexcept(noexcept(ranges::ref_view{_VSTD::forward<_Tp>(__t)}))
5452 {
......@@ -58,15 +56,15 @@ namespace __all {
5856 template<class _Tp>
5957 requires (!ranges::view<decay_t<_Tp>> &&
6058 !requires (_Tp&& __t) { ranges::ref_view{_VSTD::forward<_Tp>(__t)}; } &&
61 requires (_Tp&& __t) { ranges::subrange{_VSTD::forward<_Tp>(__t)}; })
62 _LIBCPP_HIDE_FROM_ABI
59 requires (_Tp&& __t) { ranges::owning_view{_VSTD::forward<_Tp>(__t)}; })
60 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
6361 constexpr auto operator()(_Tp&& __t) const
64 noexcept(noexcept(ranges::subrange{_VSTD::forward<_Tp>(__t)}))
62 noexcept(noexcept(ranges::owning_view{_VSTD::forward<_Tp>(__t)}))
6563 {
66 return ranges::subrange{_VSTD::forward<_Tp>(__t)};
64 return ranges::owning_view{_VSTD::forward<_Tp>(__t)};
6765 }
6866 };
69}
67} // namespace __all
7068
7169inline namespace __cpo {
7270 inline constexpr auto all = __all::__fn{};
......@@ -75,12 +73,10 @@ inline namespace __cpo {
7573template<ranges::viewable_range _Range>
7674using all_t = decltype(views::all(declval<_Range>()));
7775
78} // namespace views
76} // namespace ranges::views
7977
80#endif // !defined(_LIBCPP_HAS_NO_RANGES)
78#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
8179
8280_LIBCPP_END_NAMESPACE_STD
8381
84_LIBCPP_POP_MACROS
85
8682#endif // _LIBCPP___RANGES_ALL_H
lib/libcxx/include/__ranges/common_view.h+29-7
......@@ -16,8 +16,11 @@
1616#include <__ranges/all.h>
1717#include <__ranges/concepts.h>
1818#include <__ranges/enable_borrowed_range.h>
19#include <__ranges/range_adaptor.h>
1920#include <__ranges/size.h>
2021#include <__ranges/view_interface.h>
22#include <__utility/forward.h>
23#include <__utility/move.h>
2124#include <concepts>
2225#include <type_traits>
2326
......@@ -25,12 +28,9 @@
2528#pragma GCC system_header
2629#endif
2730
28_LIBCPP_PUSH_MACROS
29#include <__undef_macros>
30
3131_LIBCPP_BEGIN_NAMESPACE_STD
3232
33#if !defined(_LIBCPP_HAS_NO_RANGES)
33#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
3434
3535namespace ranges {
3636
......@@ -102,12 +102,34 @@ common_view(_Range&&)
102102template<class _View>
103103inline constexpr bool enable_borrowed_range<common_view<_View>> = enable_borrowed_range<_View>;
104104
105namespace views {
106namespace __common {
107 struct __fn : __range_adaptor_closure<__fn> {
108 template<class _Range>
109 requires common_range<_Range>
110 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
111 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)); }
115
116 template<class _Range>
117 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
118 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)}; }
122 };
123} // namespace __common
124
125inline namespace __cpo {
126 inline constexpr auto common = __common::__fn{};
127} // namespace __cpo
128} // namespace views
105129} // namespace ranges
106130
107#endif // !defined(_LIBCPP_HAS_NO_RANGES)
131#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
108132
109133_LIBCPP_END_NAMESPACE_STD
110134
111_LIBCPP_POP_MACROS
112
113135#endif // _LIBCPP___RANGES_COMMON_VIEW_H
lib/libcxx/include/__ranges/concepts.h+28-24
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------- __ranges/concepts.h ----------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -9,6 +9,9 @@
99#ifndef _LIBCPP___RANGES_CONCEPTS_H
1010#define _LIBCPP___RANGES_CONCEPTS_H
1111
12#include <__concepts/constructible.h>
13#include <__concepts/movable.h>
14#include <__concepts/same_as.h>
1215#include <__config>
1316#include <__iterator/concepts.h>
1417#include <__iterator/incrementable_traits.h>
......@@ -16,34 +19,34 @@
1619#include <__iterator/iterator_traits.h>
1720#include <__iterator/readable_traits.h>
1821#include <__ranges/access.h>
19#include <__ranges/enable_borrowed_range.h>
2022#include <__ranges/data.h>
23#include <__ranges/enable_borrowed_range.h>
2124#include <__ranges/enable_view.h>
2225#include <__ranges/size.h>
23#include <concepts>
26#include <initializer_list>
2427#include <type_traits>
2528
2629#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2730#pragma GCC system_header
2831#endif
2932
30_LIBCPP_PUSH_MACROS
31#include <__undef_macros>
32
3333_LIBCPP_BEGIN_NAMESPACE_STD
3434
35// clang-format off
36
37#if !defined(_LIBCPP_HAS_NO_RANGES)
35#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
3836
3937namespace ranges {
38
4039 // [range.range]
40
4141 template <class _Tp>
4242 concept range = requires(_Tp& __t) {
4343 ranges::begin(__t); // sometimes equality-preserving
4444 ranges::end(__t);
4545 };
4646
47 template <class _Tp>
48 concept input_range = range<_Tp> && input_iterator<iterator_t<_Tp>>;
49
4750 template<class _Range>
4851 concept borrowed_range = range<_Range> &&
4952 (is_lvalue_reference_v<_Range> || enable_borrowed_range<remove_cvref_t<_Range>>);
......@@ -85,19 +88,16 @@ namespace ranges {
8588 movable<_Tp> &&
8689 enable_view<_Tp>;
8790
88 template<class _Range>
91 template <class _Range>
8992 concept __simple_view =
9093 view<_Range> && range<const _Range> &&
9194 same_as<iterator_t<_Range>, iterator_t<const _Range>> &&
92 same_as<sentinel_t<_Range>, iterator_t<const _Range>>;
95 same_as<sentinel_t<_Range>, sentinel_t<const _Range>>;
9396
9497 // [range.refinements], other range refinements
9598 template <class _Rp, class _Tp>
9699 concept output_range = range<_Rp> && output_iterator<iterator_t<_Rp>, _Tp>;
97100
98 template <class _Tp>
99 concept input_range = range<_Tp> && input_iterator<iterator_t<_Tp>>;
100
101101 template <class _Tp>
102102 concept forward_range = input_range<_Tp> && forward_iterator<iterator_t<_Tp>>;
103103
......@@ -119,20 +119,24 @@ namespace ranges {
119119 template <class _Tp>
120120 concept common_range = range<_Tp> && same_as<iterator_t<_Tp>, sentinel_t<_Tp>>;
121121
122 template<class _Tp>
122 template <class _Tp>
123 inline constexpr bool __is_std_initializer_list = false;
124
125 template <class _Ep>
126 inline constexpr bool __is_std_initializer_list<initializer_list<_Ep>> = true;
127
128 template <class _Tp>
123129 concept viewable_range =
124 range<_Tp> && (
125 (view<remove_cvref_t<_Tp>> && constructible_from<remove_cvref_t<_Tp>, _Tp>) ||
126 (!view<remove_cvref_t<_Tp>> && borrowed_range<_Tp>)
127 );
128} // namespace ranges
130 range<_Tp> &&
131 ((view<remove_cvref_t<_Tp>> && constructible_from<remove_cvref_t<_Tp>, _Tp>) ||
132 (!view<remove_cvref_t<_Tp>> &&
133 (is_lvalue_reference_v<_Tp> ||
134 (movable<remove_reference_t<_Tp>> && !__is_std_initializer_list<remove_cvref_t<_Tp>>))));
129135
130#endif // !defined(_LIBCPP_HAS_NO_RANGES)
136} // namespace ranges
131137
132// clang-format on
138#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
133139
134140_LIBCPP_END_NAMESPACE_STD
135141
136_LIBCPP_POP_MACROS
137
138142#endif // _LIBCPP___RANGES_CONCEPTS_H
lib/libcxx/include/__ranges/copyable_box.h+10-7
......@@ -22,12 +22,9 @@
2222#pragma GCC system_header
2323#endif
2424
25_LIBCPP_PUSH_MACROS
26#include <__undef_macros>
27
2825_LIBCPP_BEGIN_NAMESPACE_STD
2926
30#if !defined(_LIBCPP_HAS_NO_RANGES)
27#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
3128
3229// __copyable_box allows turning a type that is copy-constructible (but maybe not copy-assignable) into
3330// a type that is both copy-constructible and copy-assignable. It does that by introducing an empty state
......@@ -91,6 +88,10 @@ namespace ranges {
9188
9289 _LIBCPP_HIDE_FROM_ABI constexpr _Tp const& operator*() const noexcept { return *__val_; }
9390 _LIBCPP_HIDE_FROM_ABI constexpr _Tp& operator*() noexcept { return *__val_; }
91
92 _LIBCPP_HIDE_FROM_ABI constexpr const _Tp *operator->() const noexcept { return __val_.operator->(); }
93 _LIBCPP_HIDE_FROM_ABI constexpr _Tp *operator->() noexcept { return __val_.operator->(); }
94
9495 _LIBCPP_HIDE_FROM_ABI constexpr bool __has_value() const noexcept { return __val_.has_value(); }
9596 };
9697
......@@ -162,14 +163,16 @@ namespace ranges {
162163
163164 _LIBCPP_HIDE_FROM_ABI constexpr _Tp const& operator*() const noexcept { return __val_; }
164165 _LIBCPP_HIDE_FROM_ABI constexpr _Tp& operator*() noexcept { return __val_; }
166
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_); }
169
165170 _LIBCPP_HIDE_FROM_ABI constexpr bool __has_value() const noexcept { return true; }
166171 };
167172} // namespace ranges
168173
169#endif // !defined(_LIBCPP_HAS_NO_RANGES)
174#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
170175
171176_LIBCPP_END_NAMESPACE_STD
172177
173_LIBCPP_POP_MACROS
174
175178#endif // _LIBCPP___RANGES_COPYABLE_BOX_H
lib/libcxx/include/__ranges/counted.h created+81
......@@ -0,0 +1,81 @@
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_COUNTED_H
10#define _LIBCPP___RANGES_COUNTED_H
11
12#include <__concepts/convertible_to.h>
13#include <__config>
14#include <__iterator/concepts.h>
15#include <__iterator/counted_iterator.h>
16#include <__iterator/default_sentinel.h>
17#include <__iterator/incrementable_traits.h>
18#include <__iterator/iterator_traits.h>
19#include <__memory/pointer_traits.h>
20#include <__ranges/subrange.h>
21#include <__utility/forward.h>
22#include <__utility/move.h>
23#include <span>
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
32#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
33
34namespace ranges::views {
35
36namespace __counted {
37
38 struct __fn {
39 template<contiguous_iterator _It>
40 _LIBCPP_HIDE_FROM_ABI
41 static constexpr auto __go(_It __it, iter_difference_t<_It> __count)
42 noexcept(noexcept(span(_VSTD::to_address(__it), static_cast<size_t>(__count))))
43 // Deliberately omit return-type SFINAE, because to_address is not SFINAE-friendly
44 { return span(_VSTD::to_address(__it), static_cast<size_t>(__count)); }
45
46 template<random_access_iterator _It>
47 _LIBCPP_HIDE_FROM_ABI
48 static constexpr auto __go(_It __it, iter_difference_t<_It> __count)
49 noexcept(noexcept(subrange(__it, __it + __count)))
50 -> decltype( subrange(__it, __it + __count))
51 { return subrange(__it, __it + __count); }
52
53 template<class _It>
54 _LIBCPP_HIDE_FROM_ABI
55 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); }
59
60 template<class _It, convertible_to<iter_difference_t<_It>> _Diff>
61 requires input_or_output_iterator<decay_t<_It>>
62 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
63 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)); }
67 };
68
69} // namespace __counted
70
71inline namespace __cpo {
72 inline constexpr auto counted = __counted::__fn{};
73} // namespace __cpo
74
75} // namespace ranges::views
76
77#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
78
79_LIBCPP_END_NAMESPACE_STD
80
81#endif // _LIBCPP___RANGES_COUNTED_H
lib/libcxx/include/__ranges/dangling.h+2-7
......@@ -19,12 +19,9 @@
1919#pragma GCC system_header
2020#endif
2121
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
2522_LIBCPP_BEGIN_NAMESPACE_STD
2623
27#if !defined(_LIBCPP_HAS_NO_RANGES)
24#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
2825
2926namespace ranges {
3027struct dangling {
......@@ -38,10 +35,8 @@ using borrowed_iterator_t = _If<borrowed_range<_Rp>, iterator_t<_Rp>, dangling>;
3835// borrowed_subrange_t defined in <__ranges/subrange.h>
3936} // namespace ranges
4037
41#endif // !_LIBCPP_HAS_NO_RANGES
38#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
4239
4340_LIBCPP_END_NAMESPACE_STD
4441
45_LIBCPP_POP_MACROS
46
4742#endif // _LIBCPP___RANGES_DANGLING_H
lib/libcxx/include/__ranges/data.h+45-25
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===------------------------ __ranges/data.h ------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -9,78 +9,98 @@
99#ifndef _LIBCPP___RANGES_DATA_H
1010#define _LIBCPP___RANGES_DATA_H
1111
12#include <__concepts/class_or_enum.h>
1213#include <__config>
1314#include <__iterator/concepts.h>
1415#include <__iterator/iterator_traits.h>
1516#include <__memory/pointer_traits.h>
1617#include <__ranges/access.h>
17#include <__utility/forward.h>
18#include <concepts>
18#include <__utility/auto_cast.h>
1919#include <type_traits>
2020
2121#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2222#pragma GCC system_header
2323#endif
2424
25_LIBCPP_PUSH_MACROS
26#include <__undef_macros>
27
2825_LIBCPP_BEGIN_NAMESPACE_STD
2926
30#if !defined(_LIBCPP_HAS_NO_RANGES)
27#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
3128
32// clang-format off
33namespace ranges {
3429// [range.prim.data]
30
31namespace ranges {
3532namespace __data {
3633 template <class _Tp>
3734 concept __ptr_to_object = is_pointer_v<_Tp> && is_object_v<remove_pointer_t<_Tp>>;
3835
3936 template <class _Tp>
4037 concept __member_data =
38 __can_borrow<_Tp> &&
39 __workaround_52970<_Tp> &&
4140 requires(_Tp&& __t) {
42 { _VSTD::forward<_Tp>(__t) } -> __can_borrow;
43 { __t.data() } -> __ptr_to_object;
41 { _LIBCPP_AUTO_CAST(__t.data()) } -> __ptr_to_object;
4442 };
4543
4644 template <class _Tp>
4745 concept __ranges_begin_invocable =
4846 !__member_data<_Tp> &&
47 __can_borrow<_Tp> &&
4948 requires(_Tp&& __t) {
50 { _VSTD::forward<_Tp>(__t) } -> __can_borrow;
51 { ranges::begin(_VSTD::forward<_Tp>(__t)) } -> contiguous_iterator;
49 { ranges::begin(__t) } -> contiguous_iterator;
5250 };
5351
5452 struct __fn {
5553 template <__member_data _Tp>
56 requires __can_borrow<_Tp>
5754 _LIBCPP_HIDE_FROM_ABI
58 constexpr __ptr_to_object auto operator()(_Tp&& __t) const
55 constexpr auto operator()(_Tp&& __t) const
5956 noexcept(noexcept(__t.data())) {
6057 return __t.data();
6158 }
6259
6360 template<__ranges_begin_invocable _Tp>
64 requires __can_borrow<_Tp>
6561 _LIBCPP_HIDE_FROM_ABI
66 constexpr __ptr_to_object auto operator()(_Tp&& __t) const
67 noexcept(noexcept(_VSTD::to_address(ranges::begin(_VSTD::forward<_Tp>(__t))))) {
68 return _VSTD::to_address(ranges::begin(_VSTD::forward<_Tp>(__t)));
62 constexpr auto operator()(_Tp&& __t) const
63 noexcept(noexcept(_VSTD::to_address(ranges::begin(__t)))) {
64 return _VSTD::to_address(ranges::begin(__t));
6965 }
7066 };
71} // end namespace __data
67} // namespace __data
7268
7369inline namespace __cpo {
74 inline constexpr const auto data = __data::__fn{};
70 inline constexpr auto data = __data::__fn{};
7571} // namespace __cpo
7672} // namespace ranges
7773
78// clang-format off
74// [range.prim.cdata]
75
76namespace ranges {
77namespace __cdata {
78 struct __fn {
79 template <class _Tp>
80 requires is_lvalue_reference_v<_Tp&&>
81 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
82 constexpr auto operator()(_Tp&& __t) const
83 noexcept(noexcept(ranges::data(static_cast<const remove_reference_t<_Tp>&>(__t))))
84 -> decltype( ranges::data(static_cast<const remove_reference_t<_Tp>&>(__t)))
85 { return ranges::data(static_cast<const remove_reference_t<_Tp>&>(__t)); }
86
87 template <class _Tp>
88 requires is_rvalue_reference_v<_Tp&&>
89 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
90 constexpr auto operator()(_Tp&& __t) const
91 noexcept(noexcept(ranges::data(static_cast<const _Tp&&>(__t))))
92 -> decltype( ranges::data(static_cast<const _Tp&&>(__t)))
93 { return ranges::data(static_cast<const _Tp&&>(__t)); }
94 };
95} // namespace __cdata
96
97inline namespace __cpo {
98 inline constexpr auto cdata = __cdata::__fn{};
99} // namespace __cpo
100} // namespace ranges
79101
80#endif // !defined(_LIBCPP_HAS_NO_RANGES)
102#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
81103
82104_LIBCPP_END_NAMESPACE_STD
83105
84_LIBCPP_POP_MACROS
85
86106#endif // _LIBCPP___RANGES_DATA_H
lib/libcxx/include/__ranges/drop_view.h+4-8
......@@ -10,6 +10,7 @@
1010#define _LIBCPP___RANGES_DROP_VIEW_H
1111
1212#include <__config>
13#include <__debug>
1314#include <__iterator/concepts.h>
1415#include <__iterator/iterator_traits.h>
1516#include <__iterator/next.h>
......@@ -28,12 +29,9 @@
2829#pragma GCC system_header
2930#endif
3031
31_LIBCPP_PUSH_MACROS
32#include <__undef_macros>
33
3432_LIBCPP_BEGIN_NAMESPACE_STD
3533
36#if !defined(_LIBCPP_HAS_NO_RANGES)
34#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
3735
3836namespace ranges {
3937 template<view _View>
......@@ -76,7 +74,7 @@ public:
7674
7775 auto __tmp = ranges::next(ranges::begin(__base_), __count_, ranges::end(__base_));
7876 if constexpr (_UseCache)
79 __cached_begin_.__set(__tmp);
77 __cached_begin_.__emplace(__tmp);
8078 return __tmp;
8179 }
8280
......@@ -122,10 +120,8 @@ public:
122120 inline constexpr bool enable_borrowed_range<drop_view<_Tp>> = enable_borrowed_range<_Tp>;
123121} // namespace ranges
124122
125#endif // !defined(_LIBCPP_HAS_NO_RANGES)
123#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
126124
127125_LIBCPP_END_NAMESPACE_STD
128126
129_LIBCPP_POP_MACROS
130
131127#endif // _LIBCPP___RANGES_DROP_VIEW_H
lib/libcxx/include/__ranges/empty.h+15-19
......@@ -9,37 +9,36 @@
99#ifndef _LIBCPP___RANGES_EMPTY_H
1010#define _LIBCPP___RANGES_EMPTY_H
1111
12#include <__concepts/class_or_enum.h>
1213#include <__config>
1314#include <__iterator/concepts.h>
1415#include <__ranges/access.h>
1516#include <__ranges/size.h>
16#include <__utility/forward.h>
1717#include <type_traits>
1818
1919#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2020#pragma GCC system_header
2121#endif
2222
23_LIBCPP_PUSH_MACROS
24#include <__undef_macros>
25
2623_LIBCPP_BEGIN_NAMESPACE_STD
2724
28#if !defined(_LIBCPP_HAS_NO_RANGES)
25#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
2926
30// clang-format off
31namespace ranges {
3227// [range.prim.empty]
28
29namespace ranges {
3330namespace __empty {
3431 template <class _Tp>
35 concept __member_empty = requires(_Tp&& __t) {
36 bool(_VSTD::forward<_Tp>(__t).empty());
37 };
32 concept __member_empty =
33 __workaround_52970<_Tp> &&
34 requires(_Tp&& __t) {
35 bool(__t.empty());
36 };
3837
3938 template<class _Tp>
4039 concept __can_invoke_size =
4140 !__member_empty<_Tp> &&
42 requires(_Tp&& __t) { ranges::size(_VSTD::forward<_Tp>(__t)); };
41 requires(_Tp&& __t) { ranges::size(__t); };
4342
4443 template <class _Tp>
4544 concept __can_compare_begin_end =
......@@ -54,13 +53,13 @@ namespace __empty {
5453 template <__member_empty _Tp>
5554 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp&& __t) const
5655 noexcept(noexcept(bool(__t.empty()))) {
57 return __t.empty();
56 return bool(__t.empty());
5857 }
5958
6059 template <__can_invoke_size _Tp>
6160 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp&& __t) const
62 noexcept(noexcept(ranges::size(_VSTD::forward<_Tp>(__t)))) {
63 return ranges::size(_VSTD::forward<_Tp>(__t)) == 0;
61 noexcept(noexcept(ranges::size(__t))) {
62 return ranges::size(__t) == 0;
6463 }
6564
6665 template<__can_compare_begin_end _Tp>
......@@ -69,18 +68,15 @@ namespace __empty {
6968 return ranges::begin(__t) == ranges::end(__t);
7069 }
7170 };
72}
71} // namespace __empty
7372
7473inline namespace __cpo {
7574 inline constexpr auto empty = __empty::__fn{};
7675} // namespace __cpo
7776} // namespace ranges
78// clang-format off
7977
80#endif // !defined(_LIBCPP_HAS_NO_RANGES)
78#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
8179
8280_LIBCPP_END_NAMESPACE_STD
8381
84_LIBCPP_POP_MACROS
85
8682#endif // _LIBCPP___RANGES_EMPTY_H
lib/libcxx/include/__ranges/empty_view.h+6-7
......@@ -10,6 +10,7 @@
1010#define _LIBCPP___RANGES_EMPTY_VIEW_H
1111
1212#include <__config>
13#include <__ranges/enable_borrowed_range.h>
1314#include <__ranges/view_interface.h>
1415#include <type_traits>
1516
......@@ -17,12 +18,9 @@
1718#pragma GCC system_header
1819#endif
1920
20_LIBCPP_PUSH_MACROS
21#include <__undef_macros>
22
2321_LIBCPP_BEGIN_NAMESPACE_STD
2422
25#if !defined(_LIBCPP_HAS_NO_RANGES)
23#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
2624
2725namespace ranges {
2826 template<class _Tp>
......@@ -35,12 +33,13 @@ namespace ranges {
3533 _LIBCPP_HIDE_FROM_ABI static constexpr size_t size() noexcept { return 0; }
3634 _LIBCPP_HIDE_FROM_ABI static constexpr bool empty() noexcept { return true; }
3735 };
36
37 template<class _Tp>
38 inline constexpr bool enable_borrowed_range<empty_view<_Tp>> = true;
3839} // namespace ranges
3940
40#endif // !defined(_LIBCPP_HAS_NO_RANGES)
41#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
4142
4243_LIBCPP_END_NAMESPACE_STD
4344
44_LIBCPP_POP_MACROS
45
4645#endif // _LIBCPP___RANGES_EMPTY_VIEW_H
lib/libcxx/include/__ranges/enable_borrowed_range.h+4-10
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===------------------ __ranges/enable_borrowed_range.h ------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -20,15 +20,11 @@
2020#pragma GCC system_header
2121#endif
2222
23_LIBCPP_PUSH_MACROS
24#include <__undef_macros>
25
2623_LIBCPP_BEGIN_NAMESPACE_STD
2724
28#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_RANGES)
25#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
2926
30namespace ranges
31{
27namespace ranges {
3228
3329// [range.range], ranges
3430
......@@ -37,10 +33,8 @@ inline constexpr bool enable_borrowed_range = false;
3733
3834} // namespace ranges
3935
40#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_RANGES)
36#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
4137
4238_LIBCPP_END_NAMESPACE_STD
4339
44_LIBCPP_POP_MACROS
45
4640#endif // _LIBCPP___RANGES_ENABLE_BORROWED_RANGE_H
lib/libcxx/include/__ranges/enable_view.h+14-9
......@@ -12,31 +12,36 @@
1212
1313#include <__config>
1414#include <concepts>
15#include <type_traits>
1516
1617#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1718#pragma GCC system_header
1819#endif
1920
20_LIBCPP_PUSH_MACROS
21#include <__undef_macros>
22
2321_LIBCPP_BEGIN_NAMESPACE_STD
2422
25#if !defined(_LIBCPP_HAS_NO_RANGES)
23#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
2624
2725namespace ranges {
2826
2927struct view_base { };
3028
29template<class _Derived>
30 requires is_class_v<_Derived> && same_as<_Derived, remove_cv_t<_Derived>>
31class view_interface;
32
33template<class _Op, class _Yp>
34 requires is_convertible_v<_Op*, view_interface<_Yp>*>
35void __is_derived_from_view_interface(const _Op*, const view_interface<_Yp>*);
36
3137template <class _Tp>
32inline constexpr bool enable_view = derived_from<_Tp, view_base>;
38inline constexpr bool enable_view = derived_from<_Tp, view_base> ||
39 requires { ranges::__is_derived_from_view_interface((_Tp*)nullptr, (_Tp*)nullptr); };
3340
34} // end namespace ranges
41} // namespace ranges
3542
36#endif // !_LIBCPP_HAS_NO_RANGES
43#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
3744
3845_LIBCPP_END_NAMESPACE_STD
3946
40_LIBCPP_POP_MACROS
41
4247#endif // _LIBCPP___RANGES_ENABLE_VIEW_H
lib/libcxx/include/__ranges/iota_view.h created+408
......@@ -0,0 +1,408 @@
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_IOTA_VIEW_H
10#define _LIBCPP___RANGES_IOTA_VIEW_H
11
12#include <__compare/three_way_comparable.h>
13#include <__concepts/arithmetic.h>
14#include <__concepts/constructible.h>
15#include <__concepts/convertible_to.h>
16#include <__concepts/copyable.h>
17#include <__concepts/equality_comparable.h>
18#include <__concepts/invocable.h>
19#include <__concepts/same_as.h>
20#include <__concepts/semiregular.h>
21#include <__concepts/totally_ordered.h>
22#include <__config>
23#include <__debug>
24#include <__functional/ranges_operations.h>
25#include <__iterator/concepts.h>
26#include <__iterator/incrementable_traits.h>
27#include <__iterator/iterator_traits.h>
28#include <__iterator/unreachable_sentinel.h>
29#include <__ranges/copyable_box.h>
30#include <__ranges/enable_borrowed_range.h>
31#include <__ranges/view_interface.h>
32#include <__utility/forward.h>
33#include <__utility/move.h>
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 !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
43
44namespace ranges {
45 template<class _Int>
46 struct __get_wider_signed {
47 static auto __call() {
48 if constexpr (sizeof(_Int) < sizeof(short)) return type_identity<short>{};
49 else if constexpr (sizeof(_Int) < sizeof(int)) return type_identity<int>{};
50 else if constexpr (sizeof(_Int) < sizeof(long)) return type_identity<long>{};
51 else return type_identity<long long>{};
52
53 static_assert(sizeof(_Int) <= sizeof(long long),
54 "Found integer-like type that is bigger than largest integer like type.");
55 }
56
57 using type = typename decltype(__call())::type;
58 };
59
60 template<class _Start>
61 using _IotaDiffT = typename _If<
62 (!integral<_Start> || sizeof(iter_difference_t<_Start>) > sizeof(_Start)),
63 type_identity<iter_difference_t<_Start>>,
64 __get_wider_signed<_Start>
65 >::type;
66
67 template<class _Iter>
68 concept __decrementable = incrementable<_Iter> && requires(_Iter __i) {
69 { --__i } -> same_as<_Iter&>;
70 { __i-- } -> same_as<_Iter>;
71 };
72
73 template<class _Iter>
74 concept __advanceable =
75 __decrementable<_Iter> && totally_ordered<_Iter> &&
76 requires(_Iter __i, const _Iter __j, const _IotaDiffT<_Iter> __n) {
77 { __i += __n } -> same_as<_Iter&>;
78 { __i -= __n } -> same_as<_Iter&>;
79 _Iter(__j + __n);
80 _Iter(__n + __j);
81 _Iter(__j - __n);
82 { __j - __j } -> convertible_to<_IotaDiffT<_Iter>>;
83 };
84
85 template<class>
86 struct __iota_iterator_category {};
87
88 template<incrementable _Tp>
89 struct __iota_iterator_category<_Tp> {
90 using iterator_category = input_iterator_tag;
91 };
92
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>> {
96 struct __iterator : public __iota_iterator_category<_Start> {
97 friend class iota_view;
98
99 using iterator_concept =
100 _If<__advanceable<_Start>, random_access_iterator_tag,
101 _If<__decrementable<_Start>, bidirectional_iterator_tag,
102 _If<incrementable<_Start>, forward_iterator_tag,
103 /*Else*/ input_iterator_tag>>>;
104
105 using value_type = _Start;
106 using difference_type = _IotaDiffT<_Start>;
107
108 _Start __value_ = _Start();
109
110 _LIBCPP_HIDE_FROM_ABI
111 __iterator() requires default_initializable<_Start> = default;
112
113 _LIBCPP_HIDE_FROM_ABI
114 constexpr explicit __iterator(_Start __value) : __value_(_VSTD::move(__value)) {}
115
116 _LIBCPP_HIDE_FROM_ABI
117 constexpr _Start operator*() const noexcept(is_nothrow_copy_constructible_v<_Start>) {
118 return __value_;
119 }
120
121 _LIBCPP_HIDE_FROM_ABI
122 constexpr __iterator& operator++() {
123 ++__value_;
124 return *this;
125 }
126
127 _LIBCPP_HIDE_FROM_ABI
128 constexpr void operator++(int) { ++*this; }
129
130 _LIBCPP_HIDE_FROM_ABI
131 constexpr __iterator operator++(int) requires incrementable<_Start> {
132 auto __tmp = *this;
133 ++*this;
134 return __tmp;
135 }
136
137 _LIBCPP_HIDE_FROM_ABI
138 constexpr __iterator& operator--() requires __decrementable<_Start> {
139 --__value_;
140 return *this;
141 }
142
143 _LIBCPP_HIDE_FROM_ABI
144 constexpr __iterator operator--(int) requires __decrementable<_Start> {
145 auto __tmp = *this;
146 --*this;
147 return __tmp;
148 }
149
150 _LIBCPP_HIDE_FROM_ABI
151 constexpr __iterator& operator+=(difference_type __n)
152 requires __advanceable<_Start>
153 {
154 if constexpr (__integer_like<_Start> && !__signed_integer_like<_Start>) {
155 if (__n >= difference_type(0)) {
156 __value_ += static_cast<_Start>(__n);
157 } else {
158 __value_ -= static_cast<_Start>(-__n);
159 }
160 } else {
161 __value_ += __n;
162 }
163 return *this;
164 }
165
166 _LIBCPP_HIDE_FROM_ABI
167 constexpr __iterator& operator-=(difference_type __n)
168 requires __advanceable<_Start>
169 {
170 if constexpr (__integer_like<_Start> && !__signed_integer_like<_Start>) {
171 if (__n >= difference_type(0)) {
172 __value_ -= static_cast<_Start>(__n);
173 } else {
174 __value_ += static_cast<_Start>(-__n);
175 }
176 } else {
177 __value_ -= __n;
178 }
179 return *this;
180 }
181
182 _LIBCPP_HIDE_FROM_ABI
183 constexpr _Start operator[](difference_type __n) const
184 requires __advanceable<_Start>
185 {
186 return _Start(__value_ + __n);
187 }
188
189 _LIBCPP_HIDE_FROM_ABI
190 friend constexpr bool operator==(const __iterator& __x, const __iterator& __y)
191 requires equality_comparable<_Start>
192 {
193 return __x.__value_ == __y.__value_;
194 }
195
196 _LIBCPP_HIDE_FROM_ABI
197 friend constexpr bool operator<(const __iterator& __x, const __iterator& __y)
198 requires totally_ordered<_Start>
199 {
200 return __x.__value_ < __y.__value_;
201 }
202
203 _LIBCPP_HIDE_FROM_ABI
204 friend constexpr bool operator>(const __iterator& __x, const __iterator& __y)
205 requires totally_ordered<_Start>
206 {
207 return __y < __x;
208 }
209
210 _LIBCPP_HIDE_FROM_ABI
211 friend constexpr bool operator<=(const __iterator& __x, const __iterator& __y)
212 requires totally_ordered<_Start>
213 {
214 return !(__y < __x);
215 }
216
217 _LIBCPP_HIDE_FROM_ABI
218 friend constexpr bool operator>=(const __iterator& __x, const __iterator& __y)
219 requires totally_ordered<_Start>
220 {
221 return !(__x < __y);
222 }
223
224 friend constexpr auto operator<=>(const __iterator& __x, const __iterator& __y)
225 requires totally_ordered<_Start> && three_way_comparable<_Start>
226 {
227 return __x.__value_ <=> __y.__value_;
228 }
229
230 _LIBCPP_HIDE_FROM_ABI
231 friend constexpr __iterator operator+(__iterator __i, difference_type __n)
232 requires __advanceable<_Start>
233 {
234 __i += __n;
235 return __i;
236 }
237
238 _LIBCPP_HIDE_FROM_ABI
239 friend constexpr __iterator operator+(difference_type __n, __iterator __i)
240 requires __advanceable<_Start>
241 {
242 return __i + __n;
243 }
244
245 _LIBCPP_HIDE_FROM_ABI
246 friend constexpr __iterator operator-(__iterator __i, difference_type __n)
247 requires __advanceable<_Start>
248 {
249 __i -= __n;
250 return __i;
251 }
252
253 _LIBCPP_HIDE_FROM_ABI
254 friend constexpr difference_type operator-(const __iterator& __x, const __iterator& __y)
255 requires __advanceable<_Start>
256 {
257 if constexpr (__integer_like<_Start>) {
258 if constexpr (__signed_integer_like<_Start>) {
259 return difference_type(difference_type(__x.__value_) - difference_type(__y.__value_));
260 }
261 if (__y.__value_ > __x.__value_) {
262 return difference_type(-difference_type(__y.__value_ - __x.__value_));
263 }
264 return difference_type(__x.__value_ - __y.__value_);
265 }
266 return __x.__value_ - __y.__value_;
267 }
268 };
269
270 struct __sentinel {
271 friend class iota_view;
272
273 private:
274 _Bound __bound_ = _Bound();
275
276 public:
277 _LIBCPP_HIDE_FROM_ABI
278 __sentinel() = default;
279 constexpr explicit __sentinel(_Bound __bound) : __bound_(_VSTD::move(__bound)) {}
280
281 _LIBCPP_HIDE_FROM_ABI
282 friend constexpr bool operator==(const __iterator& __x, const __sentinel& __y) {
283 return __x.__value_ == __y.__bound_;
284 }
285
286 _LIBCPP_HIDE_FROM_ABI
287 friend constexpr iter_difference_t<_Start> operator-(const __iterator& __x, const __sentinel& __y)
288 requires sized_sentinel_for<_Bound, _Start>
289 {
290 return __x.__value_ - __y.__bound_;
291 }
292
293 _LIBCPP_HIDE_FROM_ABI
294 friend constexpr iter_difference_t<_Start> operator-(const __sentinel& __x, const __iterator& __y)
295 requires sized_sentinel_for<_Bound, _Start>
296 {
297 return -(__y - __x);
298 }
299 };
300
301 _Start __value_ = _Start();
302 _Bound __bound_ = _Bound();
303
304 public:
305 _LIBCPP_HIDE_FROM_ABI
306 iota_view() requires default_initializable<_Start> = default;
307
308 _LIBCPP_HIDE_FROM_ABI
309 constexpr explicit iota_view(_Start __value) : __value_(_VSTD::move(__value)) { }
310
311 _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)) {
314 // Validate the precondition if possible.
315 if constexpr (totally_ordered_with<_Start, _Bound>) {
316 _LIBCPP_ASSERT(ranges::less_equal()(__value_, __bound_),
317 "Precondition violated: value is greater than bound.");
318 }
319 }
320
321 _LIBCPP_HIDE_FROM_ABI
322 constexpr iota_view(__iterator __first, __iterator __last)
323 requires same_as<_Start, _Bound>
324 : iota_view(_VSTD::move(__first.__value_), _VSTD::move(__last.__value_)) {}
325
326 _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)) {}
330
331 _LIBCPP_HIDE_FROM_ABI
332 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_)) {}
335
336 _LIBCPP_HIDE_FROM_ABI
337 constexpr __iterator begin() const { return __iterator{__value_}; }
338
339 _LIBCPP_HIDE_FROM_ABI
340 constexpr auto end() const {
341 if constexpr (same_as<_Bound, unreachable_sentinel_t>)
342 return unreachable_sentinel;
343 else
344 return __sentinel{__bound_};
345 }
346
347 _LIBCPP_HIDE_FROM_ABI
348 constexpr __iterator end() const requires same_as<_Start, _Bound> {
349 return __iterator{__bound_};
350 }
351
352 _LIBCPP_HIDE_FROM_ABI
353 constexpr auto size() const
354 requires (same_as<_Start, _Bound> && __advanceable<_Start>) ||
355 (integral<_Start> && integral<_Bound>) ||
356 sized_sentinel_for<_Bound, _Start>
357 {
358 if constexpr (__integer_like<_Start> && __integer_like<_Bound>) {
359 if (__value_ < 0) {
360 if (__bound_ < 0) {
361 return _VSTD::__to_unsigned_like(-__value_) - _VSTD::__to_unsigned_like(-__bound_);
362 }
363 return _VSTD::__to_unsigned_like(__bound_) + _VSTD::__to_unsigned_like(-__value_);
364 }
365 return _VSTD::__to_unsigned_like(__bound_) - _VSTD::__to_unsigned_like(__value_);
366 }
367 return _VSTD::__to_unsigned_like(__bound_ - __value_);
368 }
369 };
370
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>;
375
376 template<class _Start, class _Bound>
377 inline constexpr bool enable_borrowed_range<iota_view<_Start, _Bound>> = true;
378
379namespace views {
380namespace __iota {
381 struct __fn {
382 template<class _Start>
383 _LIBCPP_HIDE_FROM_ABI
384 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)); }
395 };
396} // namespace __iota
397
398inline namespace __cpo {
399 inline constexpr auto iota = __iota::__fn{};
400} // namespace __cpo
401} // namespace views
402} // namespace ranges
403
404#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
405
406_LIBCPP_END_NAMESPACE_STD
407
408#endif // _LIBCPP___RANGES_IOTA_VIEW_H
lib/libcxx/include/__ranges/join_view.h created+350
......@@ -0,0 +1,350 @@
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_JOIN_VIEW_H
10#define _LIBCPP___RANGES_JOIN_VIEW_H
11
12#include <__config>
13#include <__iterator/concepts.h>
14#include <__iterator/iterator_traits.h>
15#include <__ranges/access.h>
16#include <__ranges/all.h>
17#include <__ranges/concepts.h>
18#include <__ranges/non_propagating_cache.h>
19#include <__ranges/ref_view.h>
20#include <__ranges/subrange.h>
21#include <__ranges/view_interface.h>
22#include <__utility/declval.h>
23#include <__utility/forward.h>
24#include <optional>
25#include <type_traits>
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 !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
34
35namespace ranges {
36 template<class>
37 struct __join_view_iterator_category {};
38
39 template<class _View>
40 requires is_reference_v<range_reference_t<_View>> &&
41 forward_range<_View> &&
42 forward_range<range_reference_t<_View>>
43 struct __join_view_iterator_category<_View> {
44 using _OuterC = typename iterator_traits<iterator_t<_View>>::iterator_category;
45 using _InnerC = typename iterator_traits<iterator_t<range_reference_t<_View>>>::iterator_category;
46
47 using iterator_category = _If<
48 derived_from<_OuterC, bidirectional_iterator_tag> && derived_from<_InnerC, bidirectional_iterator_tag>,
49 bidirectional_iterator_tag,
50 _If<
51 derived_from<_OuterC, forward_iterator_tag> && derived_from<_InnerC, forward_iterator_tag>,
52 forward_iterator_tag,
53 input_iterator_tag
54 >
55 >;
56 };
57
58 template<input_range _View>
59 requires view<_View> && input_range<range_reference_t<_View>>
60 class join_view
61 : public view_interface<join_view<_View>> {
62 private:
63 using _InnerRange = range_reference_t<_View>;
64
65 template<bool> struct __iterator;
66 template<bool> struct __sentinel;
67
68 static constexpr bool _UseCache = !is_reference_v<_InnerRange>;
69 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 :)
72
73 public:
74 _LIBCPP_HIDE_FROM_ABI
75 join_view() requires default_initializable<_View> = default;
76
77 _LIBCPP_HIDE_FROM_ABI
78 constexpr explicit join_view(_View __base)
79 : __base_(_VSTD::move(__base)) {}
80
81 _LIBCPP_HIDE_FROM_ABI
82 constexpr _View base() const& requires copy_constructible<_View> { return __base_; }
83
84 _LIBCPP_HIDE_FROM_ABI
85 constexpr _View base() && { return _VSTD::move(__base_); }
86
87 _LIBCPP_HIDE_FROM_ABI
88 constexpr auto begin() {
89 constexpr bool __use_const = __simple_view<_View> &&
90 is_reference_v<range_reference_t<_View>>;
91 return __iterator<__use_const>{*this, ranges::begin(__base_)};
92 }
93
94 template<class _V2 = _View>
95 _LIBCPP_HIDE_FROM_ABI
96 constexpr auto begin() const
97 requires input_range<const _V2> &&
98 is_reference_v<range_reference_t<const _V2>>
99 {
100 return __iterator<true>{*this, ranges::begin(__base_)};
101 }
102
103 _LIBCPP_HIDE_FROM_ABI
104 constexpr auto end() {
105 if constexpr (forward_range<_View> &&
106 is_reference_v<_InnerRange> &&
107 forward_range<_InnerRange> &&
108 common_range<_View> &&
109 common_range<_InnerRange>)
110 return __iterator<__simple_view<_View>>{*this, ranges::end(__base_)};
111 else
112 return __sentinel<__simple_view<_View>>{*this};
113 }
114
115 template<class _V2 = _View>
116 _LIBCPP_HIDE_FROM_ABI
117 constexpr auto end() const
118 requires input_range<const _V2> &&
119 is_reference_v<range_reference_t<const _V2>>
120 {
121 using _ConstInnerRange = range_reference_t<const _View>;
122 if constexpr (forward_range<const _View> &&
123 is_reference_v<_ConstInnerRange> &&
124 forward_range<_ConstInnerRange> &&
125 common_range<const _View> &&
126 common_range<_ConstInnerRange>) {
127 return __iterator<true>{*this, ranges::end(__base_)};
128 } else {
129 return __sentinel<true>{*this};
130 }
131 }
132 };
133
134 template<input_range _View>
135 requires view<_View> && input_range<range_reference_t<_View>>
136 template<bool _Const> struct join_view<_View>::__sentinel {
137 template<bool> friend struct __sentinel;
138
139 private:
140 using _Parent = __maybe_const<_Const, join_view>;
141 using _Base = __maybe_const<_Const, _View>;
142 sentinel_t<_Base> __end_ = sentinel_t<_Base>();
143
144 public:
145 _LIBCPP_HIDE_FROM_ABI
146 __sentinel() = default;
147
148 _LIBCPP_HIDE_FROM_ABI
149 constexpr explicit __sentinel(_Parent& __parent)
150 : __end_(ranges::end(__parent.__base_)) {}
151
152 _LIBCPP_HIDE_FROM_ABI
153 constexpr __sentinel(__sentinel<!_Const> __s)
154 requires _Const && convertible_to<sentinel_t<_View>, sentinel_t<_Base>>
155 : __end_(_VSTD::move(__s.__end_)) {}
156
157 template<bool _OtherConst>
158 requires sentinel_for<sentinel_t<_Base>, iterator_t<__maybe_const<_OtherConst, _View>>>
159 _LIBCPP_HIDE_FROM_ABI
160 friend constexpr bool operator==(const __iterator<_OtherConst>& __x, const __sentinel& __y) {
161 return __x.__outer_ == __y.__end_;
162 }
163 };
164
165 template<input_range _View>
166 requires view<_View> && input_range<range_reference_t<_View>>
167 template<bool _Const> struct join_view<_View>::__iterator
168 : public __join_view_iterator_category<__maybe_const<_Const, _View>> {
169
170 template<bool> friend struct __iterator;
171
172 private:
173 using _Parent = __maybe_const<_Const, join_view>;
174 using _Base = __maybe_const<_Const, _View>;
175 using _Outer = iterator_t<_Base>;
176 using _Inner = iterator_t<range_reference_t<_Base>>;
177
178 static constexpr bool __ref_is_glvalue = is_reference_v<range_reference_t<_Base>>;
179
180 public:
181 _Outer __outer_ = _Outer();
182
183 private:
184 optional<_Inner> __inner_;
185 _Parent *__parent_ = nullptr;
186
187 _LIBCPP_HIDE_FROM_ABI
188 constexpr void __satisfy() {
189 for (; __outer_ != ranges::end(__parent_->__base_); ++__outer_) {
190 auto&& __inner = [&]() -> auto&& {
191 if constexpr (__ref_is_glvalue)
192 return *__outer_;
193 else
194 return __parent_->__cache_.__emplace_from([&]() -> decltype(auto) { return *__outer_; });
195 }();
196 __inner_ = ranges::begin(__inner);
197 if (*__inner_ != ranges::end(__inner))
198 return;
199 }
200
201 if constexpr (__ref_is_glvalue)
202 __inner_.reset();
203 }
204
205 public:
206 using iterator_concept = _If<
207 __ref_is_glvalue && bidirectional_range<_Base> && bidirectional_range<range_reference_t<_Base>>,
208 bidirectional_iterator_tag,
209 _If<
210 __ref_is_glvalue && forward_range<_Base> && forward_range<range_reference_t<_Base>>,
211 forward_iterator_tag,
212 input_iterator_tag
213 >
214 >;
215
216 using value_type = range_value_t<range_reference_t<_Base>>;
217
218 using difference_type = common_type_t<
219 range_difference_t<_Base>, range_difference_t<range_reference_t<_Base>>>;
220
221 _LIBCPP_HIDE_FROM_ABI
222 __iterator() requires default_initializable<_Outer> = default;
223
224 _LIBCPP_HIDE_FROM_ABI
225 constexpr __iterator(_Parent& __parent, _Outer __outer)
226 : __outer_(_VSTD::move(__outer))
227 , __parent_(_VSTD::addressof(__parent)) {
228 __satisfy();
229 }
230
231 _LIBCPP_HIDE_FROM_ABI
232 constexpr __iterator(__iterator<!_Const> __i)
233 requires _Const &&
234 convertible_to<iterator_t<_View>, _Outer> &&
235 convertible_to<iterator_t<_InnerRange>, _Inner>
236 : __outer_(_VSTD::move(__i.__outer_))
237 , __inner_(_VSTD::move(__i.__inner_))
238 , __parent_(__i.__parent_) {}
239
240 _LIBCPP_HIDE_FROM_ABI
241 constexpr decltype(auto) operator*() const {
242 return **__inner_;
243 }
244
245 _LIBCPP_HIDE_FROM_ABI
246 constexpr _Inner operator->() const
247 requires __has_arrow<_Inner> && copyable<_Inner>
248 {
249 return *__inner_;
250 }
251
252 _LIBCPP_HIDE_FROM_ABI
253 constexpr __iterator& operator++() {
254 auto&& __inner = [&]() -> auto&& {
255 if constexpr (__ref_is_glvalue)
256 return *__outer_;
257 else
258 return *__parent_->__cache_;
259 }();
260 if (++*__inner_ == ranges::end(__inner)) {
261 ++__outer_;
262 __satisfy();
263 }
264 return *this;
265 }
266
267 _LIBCPP_HIDE_FROM_ABI
268 constexpr void operator++(int) {
269 ++*this;
270 }
271
272 _LIBCPP_HIDE_FROM_ABI
273 constexpr __iterator operator++(int)
274 requires __ref_is_glvalue &&
275 forward_range<_Base> &&
276 forward_range<range_reference_t<_Base>>
277 {
278 auto __tmp = *this;
279 ++*this;
280 return __tmp;
281 }
282
283 _LIBCPP_HIDE_FROM_ABI
284 constexpr __iterator& operator--()
285 requires __ref_is_glvalue &&
286 bidirectional_range<_Base> &&
287 bidirectional_range<range_reference_t<_Base>> &&
288 common_range<range_reference_t<_Base>>
289 {
290 if (__outer_ == ranges::end(__parent_->__base_))
291 __inner_ = ranges::end(*--__outer_);
292
293 // Skip empty inner ranges when going backwards.
294 while (*__inner_ == ranges::begin(*__outer_)) {
295 __inner_ = ranges::end(*--__outer_);
296 }
297
298 --*__inner_;
299 return *this;
300 }
301
302 _LIBCPP_HIDE_FROM_ABI
303 constexpr __iterator operator--(int)
304 requires __ref_is_glvalue &&
305 bidirectional_range<_Base> &&
306 bidirectional_range<range_reference_t<_Base>> &&
307 common_range<range_reference_t<_Base>>
308 {
309 auto __tmp = *this;
310 --*this;
311 return __tmp;
312 }
313
314 _LIBCPP_HIDE_FROM_ABI
315 friend constexpr bool operator==(const __iterator& __x, const __iterator& __y)
316 requires __ref_is_glvalue &&
317 equality_comparable<iterator_t<_Base>> &&
318 equality_comparable<iterator_t<range_reference_t<_Base>>>
319 {
320 return __x.__outer_ == __y.__outer_ && __x.__inner_ == __y.__inner_;
321 }
322
323 _LIBCPP_HIDE_FROM_ABI
324 friend constexpr decltype(auto) iter_move(const __iterator& __i)
325 noexcept(noexcept(ranges::iter_move(*__i.__inner_)))
326 {
327 return ranges::iter_move(*__i.__inner_);
328 }
329
330 _LIBCPP_HIDE_FROM_ABI
331 friend constexpr void iter_swap(const __iterator& __x, const __iterator& __y)
332 noexcept(noexcept(ranges::iter_swap(*__x.__inner_, *__y.__inner_)))
333 requires indirectly_swappable<_Inner>
334 {
335 return ranges::iter_swap(*__x.__inner_, *__y.__inner_);
336 }
337 };
338
339 template<class _Range>
340 explicit join_view(_Range&&) -> join_view<views::all_t<_Range>>;
341
342} // namespace ranges
343
344#undef _CONSTEXPR_TERNARY
345
346#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
347
348_LIBCPP_END_NAMESPACE_STD
349
350#endif // _LIBCPP___RANGES_JOIN_VIEW_H
lib/libcxx/include/__ranges/non_propagating_cache.h+29-14
......@@ -13,6 +13,7 @@
1313#include <__iterator/concepts.h> // indirectly_readable
1414#include <__iterator/iterator_traits.h> // iter_reference_t
1515#include <__memory/addressof.h>
16#include <__utility/forward.h>
1617#include <concepts> // constructible_from
1718#include <optional>
1819#include <type_traits>
......@@ -21,14 +22,9 @@
2122#pragma GCC system_header
2223#endif
2324
24_LIBCPP_PUSH_MACROS
25#include <__undef_macros>
26
2725_LIBCPP_BEGIN_NAMESPACE_STD
2826
29// clang-format off
30
31#if !defined(_LIBCPP_HAS_NO_RANGES)
27#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
3228
3329namespace ranges {
3430 // __non_propagating_cache is a helper type that allows storing an optional value in it,
......@@ -42,7 +38,20 @@ namespace ranges {
4238 template<class _Tp>
4339 requires is_object_v<_Tp>
4440 class _LIBCPP_TEMPLATE_VIS __non_propagating_cache {
45 optional<_Tp> __value_ = nullopt;
41 struct __from_tag { };
42 struct __forward_tag { };
43
44 // This helper class is needed to perform copy and move elision when
45 // constructing the contained type from an iterator.
46 struct __wrapper {
47 template<class ..._Args>
48 constexpr explicit __wrapper(__forward_tag, _Args&& ...__args) : __t_(_VSTD::forward<_Args>(__args)...) { }
49 template<class _Fn>
50 constexpr explicit __wrapper(__from_tag, _Fn const& __f) : __t_(__f()) { }
51 _Tp __t_;
52 };
53
54 optional<__wrapper> __value_ = nullopt;
4655
4756 public:
4857 _LIBCPP_HIDE_FROM_ABI __non_propagating_cache() = default;
......@@ -75,25 +84,31 @@ namespace ranges {
7584 }
7685
7786 _LIBCPP_HIDE_FROM_ABI
78 constexpr _Tp& operator*() { return *__value_; }
87 constexpr _Tp& operator*() { return __value_->__t_; }
7988 _LIBCPP_HIDE_FROM_ABI
80 constexpr _Tp const& operator*() const { return *__value_; }
89 constexpr _Tp const& operator*() const { return __value_->__t_; }
8190
8291 _LIBCPP_HIDE_FROM_ABI
8392 constexpr bool __has_value() const { return __value_.has_value(); }
93
94 template<class _Fn>
8495 _LIBCPP_HIDE_FROM_ABI
85 constexpr void __set(_Tp const& __value) { __value_.emplace(__value); }
96 constexpr _Tp& __emplace_from(_Fn const& __f) {
97 return __value_.emplace(__from_tag{}, __f).__t_;
98 }
99
100 template<class ..._Args>
86101 _LIBCPP_HIDE_FROM_ABI
87 constexpr void __set(_Tp&& __value) { __value_.emplace(_VSTD::move(__value)); }
102 constexpr _Tp& __emplace(_Args&& ...__args) {
103 return __value_.emplace(__forward_tag{}, _VSTD::forward<_Args>(__args)...).__t_;
104 }
88105 };
89106
90107 struct __empty_cache { };
91108} // namespace ranges
92109
93#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_RANGES)
110#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
94111
95112_LIBCPP_END_NAMESPACE_STD
96113
97_LIBCPP_POP_MACROS
98
99114#endif // _LIBCPP___RANGES_NON_PROPAGATING_CACHE_H
lib/libcxx/include/__ranges/owning_view.h created+81
......@@ -0,0 +1,81 @@
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_OWNING_VIEW_H
10#define _LIBCPP___RANGES_OWNING_VIEW_H
11
12#include <__concepts/constructible.h>
13#include <__concepts/movable.h>
14#include <__config>
15#include <__ranges/access.h>
16#include <__ranges/concepts.h>
17#include <__ranges/data.h>
18#include <__ranges/empty.h>
19#include <__ranges/enable_borrowed_range.h>
20#include <__ranges/size.h>
21#include <__ranges/view_interface.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_LIBCPP_BEGIN_NAMESPACE_STD
30
31#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
32
33namespace ranges {
34 template<range _Rp>
35 requires movable<_Rp> && (!__is_std_initializer_list<remove_cvref_t<_Rp>>)
36 class owning_view : public view_interface<owning_view<_Rp>> {
37 _Rp __r_ = _Rp();
38
39public:
40 owning_view() requires default_initializable<_Rp> = default;
41 _LIBCPP_HIDE_FROM_ABI constexpr owning_view(_Rp&& __r) : __r_(_VSTD::move(__r)) {}
42
43 owning_view(owning_view&&) = default;
44 owning_view& operator=(owning_view&&) = default;
45
46 _LIBCPP_HIDE_FROM_ABI constexpr _Rp& base() & noexcept { return __r_; }
47 _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_); }
50
51 _LIBCPP_HIDE_FROM_ABI constexpr iterator_t<_Rp> begin() { return ranges::begin(__r_); }
52 _LIBCPP_HIDE_FROM_ABI constexpr sentinel_t<_Rp> end() { return ranges::end(__r_); }
53 _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const requires range<const _Rp> { return ranges::begin(__r_); }
54 _LIBCPP_HIDE_FROM_ABI constexpr auto end() const requires range<const _Rp> { return ranges::end(__r_); }
55
56 _LIBCPP_HIDE_FROM_ABI constexpr bool empty() requires requires { ranges::empty(__r_); }
57 { return ranges::empty(__r_); }
58 _LIBCPP_HIDE_FROM_ABI constexpr bool empty() const requires requires { ranges::empty(__r_); }
59 { return ranges::empty(__r_); }
60
61 _LIBCPP_HIDE_FROM_ABI constexpr auto size() requires sized_range<_Rp>
62 { return ranges::size(__r_); }
63 _LIBCPP_HIDE_FROM_ABI constexpr auto size() const requires sized_range<const _Rp>
64 { return ranges::size(__r_); }
65
66 _LIBCPP_HIDE_FROM_ABI constexpr auto data() requires contiguous_range<_Rp>
67 { return ranges::data(__r_); }
68 _LIBCPP_HIDE_FROM_ABI constexpr auto data() const requires contiguous_range<const _Rp>
69 { return ranges::data(__r_); }
70 };
71
72 template<class _Tp>
73 inline constexpr bool enable_borrowed_range<owning_view<_Tp>> = enable_borrowed_range<_Tp>;
74
75} // namespace ranges
76
77#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
78
79_LIBCPP_END_NAMESPACE_STD
80
81#endif // _LIBCPP___RANGES_OWNING_VIEW_H
lib/libcxx/include/__ranges/range_adaptor.h created+73
......@@ -0,0 +1,73 @@
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_RANGE_ADAPTOR_H
11#define _LIBCPP___RANGES_RANGE_ADAPTOR_H
12
13#include <__config>
14#include <__functional/compose.h>
15#include <__functional/invoke.h>
16#include <__ranges/concepts.h>
17#include <__utility/forward.h>
18#include <__utility/move.h>
19#include <concepts>
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 !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
29
30// CRTP base that one can derive from in order to be considered a range adaptor closure
31// by the library. When deriving from this class, a pipe operator will be provided to
32// make the following hold:
33// - `x | f` is equivalent to `f(x)`
34// - `f1 | f2` is an adaptor closure `g` such that `g(x)` is equivalent to `f2(f1(x))`
35template <class _Tp>
36struct __range_adaptor_closure;
37
38// Type that wraps an arbitrary function object and makes it into a range adaptor closure,
39// i.e. something that can be called via the `x | f` notation.
40template <class _Fn>
41struct __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)) { }
43};
44
45template <class _Tp>
46concept _RangeAdaptorClosure = derived_from<remove_cvref_t<_Tp>, __range_adaptor_closure<remove_cvref_t<_Tp>>>;
47
48template <class _Tp>
49struct __range_adaptor_closure {
50 template <ranges::viewable_range _View, _RangeAdaptorClosure _Closure>
51 requires same_as<_Tp, remove_cvref_t<_Closure>> &&
52 invocable<_Closure, _View>
53 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
54 friend constexpr decltype(auto) operator|(_View&& __view, _Closure&& __closure)
55 noexcept(is_nothrow_invocable_v<_Closure, _View>)
56 { return _VSTD::invoke(_VSTD::forward<_Closure>(__closure), _VSTD::forward<_View>(__view)); }
57
58 template <_RangeAdaptorClosure _Closure, _RangeAdaptorClosure _OtherClosure>
59 requires same_as<_Tp, remove_cvref_t<_Closure>> &&
60 constructible_from<decay_t<_Closure>, _Closure> &&
61 constructible_from<decay_t<_OtherClosure>, _OtherClosure>
62 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
63 friend constexpr auto operator|(_Closure&& __c1, _OtherClosure&& __c2)
64 noexcept(is_nothrow_constructible_v<decay_t<_Closure>, _Closure> &&
65 is_nothrow_constructible_v<decay_t<_OtherClosure>, _OtherClosure>)
66 { return __range_adaptor_closure_t(_VSTD::__compose(_VSTD::forward<_OtherClosure>(__c2), _VSTD::forward<_Closure>(__c1))); }
67};
68
69#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
70
71_LIBCPP_END_NAMESPACE_STD
72
73#endif // _LIBCPP___RANGES_RANGE_ADAPTOR_H
lib/libcxx/include/__ranges/ref_view.h+6-7
......@@ -18,8 +18,10 @@
1818#include <__ranges/concepts.h>
1919#include <__ranges/data.h>
2020#include <__ranges/empty.h>
21#include <__ranges/enable_borrowed_range.h>
2122#include <__ranges/size.h>
2223#include <__ranges/view_interface.h>
24#include <__utility/forward.h>
2325#include <concepts>
2426#include <type_traits>
2527
......@@ -27,12 +29,9 @@
2729#pragma GCC system_header
2830#endif
2931
30_LIBCPP_PUSH_MACROS
31#include <__undef_macros>
32
3332_LIBCPP_BEGIN_NAMESPACE_STD
3433
35#if !defined(_LIBCPP_HAS_NO_RANGES)
34#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
3635
3736namespace ranges {
3837 template<range _Range>
......@@ -76,12 +75,12 @@ public:
7675 template<class _Range>
7776 ref_view(_Range&) -> ref_view<_Range>;
7877
78 template<class _Tp>
79 inline constexpr bool enable_borrowed_range<ref_view<_Tp>> = true;
7980} // namespace ranges
8081
81#endif // !defined(_LIBCPP_HAS_NO_RANGES)
82#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
8283
8384_LIBCPP_END_NAMESPACE_STD
8485
85_LIBCPP_POP_MACROS
86
8786#endif // _LIBCPP___RANGES_REF_VIEW_H
lib/libcxx/include/__ranges/reverse_view.h created+190
......@@ -0,0 +1,190 @@
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_REVERSE_VIEW_H
10#define _LIBCPP___RANGES_REVERSE_VIEW_H
11
12#include <__concepts/constructible.h>
13#include <__config>
14#include <__iterator/concepts.h>
15#include <__iterator/next.h>
16#include <__iterator/reverse_iterator.h>
17#include <__ranges/access.h>
18#include <__ranges/all.h>
19#include <__ranges/concepts.h>
20#include <__ranges/enable_borrowed_range.h>
21#include <__ranges/non_propagating_cache.h>
22#include <__ranges/range_adaptor.h>
23#include <__ranges/size.h>
24#include <__ranges/subrange.h>
25#include <__ranges/view_interface.h>
26#include <__utility/forward.h>
27#include <__utility/move.h>
28#include <type_traits>
29
30#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
31#pragma GCC system_header
32#endif
33
34_LIBCPP_BEGIN_NAMESPACE_STD
35
36#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
37
38namespace ranges {
39 template<view _View>
40 requires bidirectional_range<_View>
41 class reverse_view : public view_interface<reverse_view<_View>> {
42 // We cache begin() whenever ranges::next is not guaranteed O(1) to provide an
43 // amortized O(1) begin() method.
44 static constexpr bool _UseCache = !random_access_range<_View> && !common_range<_View>;
45 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();
48
49 public:
50 _LIBCPP_HIDE_FROM_ABI
51 reverse_view() requires default_initializable<_View> = default;
52
53 _LIBCPP_HIDE_FROM_ABI
54 constexpr explicit reverse_view(_View __view) : __base_(_VSTD::move(__view)) {}
55
56 _LIBCPP_HIDE_FROM_ABI
57 constexpr _View base() const& requires copy_constructible<_View> { return __base_; }
58
59 _LIBCPP_HIDE_FROM_ABI
60 constexpr _View base() && { return _VSTD::move(__base_); }
61
62 _LIBCPP_HIDE_FROM_ABI
63 constexpr reverse_iterator<iterator_t<_View>> begin() {
64 if constexpr (_UseCache)
65 if (__cached_begin_.__has_value())
66 return *__cached_begin_;
67
68 auto __tmp = _VSTD::make_reverse_iterator(ranges::next(ranges::begin(__base_), ranges::end(__base_)));
69 if constexpr (_UseCache)
70 __cached_begin_.__emplace(__tmp);
71 return __tmp;
72 }
73
74 _LIBCPP_HIDE_FROM_ABI
75 constexpr reverse_iterator<iterator_t<_View>> begin() requires common_range<_View> {
76 return _VSTD::make_reverse_iterator(ranges::end(__base_));
77 }
78
79 _LIBCPP_HIDE_FROM_ABI
80 constexpr auto begin() const requires common_range<const _View> {
81 return _VSTD::make_reverse_iterator(ranges::end(__base_));
82 }
83
84 _LIBCPP_HIDE_FROM_ABI
85 constexpr reverse_iterator<iterator_t<_View>> end() {
86 return _VSTD::make_reverse_iterator(ranges::begin(__base_));
87 }
88
89 _LIBCPP_HIDE_FROM_ABI
90 constexpr auto end() const requires common_range<const _View> {
91 return _VSTD::make_reverse_iterator(ranges::begin(__base_));
92 }
93
94 _LIBCPP_HIDE_FROM_ABI
95 constexpr auto size() requires sized_range<_View> {
96 return ranges::size(__base_);
97 }
98
99 _LIBCPP_HIDE_FROM_ABI
100 constexpr auto size() const requires sized_range<const _View> {
101 return ranges::size(__base_);
102 }
103 };
104
105 template<class _Range>
106 reverse_view(_Range&&) -> reverse_view<views::all_t<_Range>>;
107
108 template<class _Tp>
109 inline constexpr bool enable_borrowed_range<reverse_view<_Tp>> = enable_borrowed_range<_Tp>;
110
111 namespace views {
112 namespace __reverse {
113 template<class _Tp>
114 constexpr bool __is_reverse_view = false;
115
116 template<class _Tp>
117 constexpr bool __is_reverse_view<reverse_view<_Tp>> = true;
118
119 template<class _Tp>
120 constexpr bool __is_sized_reverse_subrange = false;
121
122 template<class _Iter>
123 constexpr bool __is_sized_reverse_subrange<subrange<reverse_iterator<_Iter>, reverse_iterator<_Iter>, subrange_kind::sized>> = true;
124
125 template<class _Tp>
126 constexpr bool __is_unsized_reverse_subrange = false;
127
128 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;
130
131 template<class _Tp>
132 struct __unwrapped_reverse_subrange {
133 using type = void; // avoid SFINAE-ing out the overload below -- let the concept requirements do it for better diagnostics
134 };
135
136 template<class _Iter, subrange_kind _Kind>
137 struct __unwrapped_reverse_subrange<subrange<reverse_iterator<_Iter>, reverse_iterator<_Iter>, _Kind>> {
138 using type = subrange<_Iter, _Iter, _Kind>;
139 };
140
141 struct __fn : __range_adaptor_closure<__fn> {
142 template<class _Range>
143 requires __is_reverse_view<remove_cvref_t<_Range>>
144 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
145 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(); }
149
150 template<class _Range,
151 class _UnwrappedSubrange = typename __unwrapped_reverse_subrange<remove_cvref_t<_Range>>::type>
152 requires __is_sized_reverse_subrange<remove_cvref_t<_Range>>
153 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
154 constexpr auto operator()(_Range&& __range) const
155 noexcept(noexcept(_UnwrappedSubrange(__range.end().base(), __range.begin().base(), __range.size())))
156 -> decltype( _UnwrappedSubrange(__range.end().base(), __range.begin().base(), __range.size()))
157 { return _UnwrappedSubrange(__range.end().base(), __range.begin().base(), __range.size()); }
158
159 template<class _Range,
160 class _UnwrappedSubrange = typename __unwrapped_reverse_subrange<remove_cvref_t<_Range>>::type>
161 requires __is_unsized_reverse_subrange<remove_cvref_t<_Range>>
162 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
163 constexpr auto operator()(_Range&& __range) const
164 noexcept(noexcept(_UnwrappedSubrange(__range.end().base(), __range.begin().base())))
165 -> decltype( _UnwrappedSubrange(__range.end().base(), __range.begin().base()))
166 { return _UnwrappedSubrange(__range.end().base(), __range.begin().base()); }
167
168 template<class _Range>
169 requires (!__is_reverse_view<remove_cvref_t<_Range>> &&
170 !__is_sized_reverse_subrange<remove_cvref_t<_Range>> &&
171 !__is_unsized_reverse_subrange<remove_cvref_t<_Range>>)
172 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
173 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)}; }
177 };
178 } // namespace __reverse
179
180 inline namespace __cpo {
181 inline constexpr auto reverse = __reverse::__fn{};
182 } // namespace __cpo
183 } // namespace views
184} // namespace ranges
185
186#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
187
188_LIBCPP_END_NAMESPACE_STD
189
190#endif // _LIBCPP___RANGES_REVERSE_VIEW_H
lib/libcxx/include/__ranges/single_view.h created+81
......@@ -0,0 +1,81 @@
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_SINGLE_VIEW_H
10#define _LIBCPP___RANGES_SINGLE_VIEW_H
11
12#include <__config>
13#include <__ranges/copyable_box.h>
14#include <__ranges/view_interface.h>
15#include <__utility/forward.h>
16#include <__utility/in_place.h>
17#include <__utility/move.h>
18#include <concepts>
19#include <type_traits>
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 !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
28
29namespace ranges {
30 template<copy_constructible _Tp>
31 requires is_object_v<_Tp>
32 class single_view : public view_interface<single_view<_Tp>> {
33 __copyable_box<_Tp> __value_;
34
35 public:
36 _LIBCPP_HIDE_FROM_ABI
37 single_view() requires default_initializable<_Tp> = default;
38
39 _LIBCPP_HIDE_FROM_ABI
40 constexpr explicit single_view(const _Tp& __t) : __value_(in_place, __t) {}
41
42 _LIBCPP_HIDE_FROM_ABI
43 constexpr explicit single_view(_Tp&& __t) : __value_(in_place, _VSTD::move(__t)) {}
44
45 template<class... _Args>
46 requires constructible_from<_Tp, _Args...>
47 _LIBCPP_HIDE_FROM_ABI
48 constexpr explicit single_view(in_place_t, _Args&&... __args)
49 : __value_{in_place, _VSTD::forward<_Args>(__args)...} {}
50
51 _LIBCPP_HIDE_FROM_ABI
52 constexpr _Tp* begin() noexcept { return data(); }
53
54 _LIBCPP_HIDE_FROM_ABI
55 constexpr const _Tp* begin() const noexcept { return data(); }
56
57 _LIBCPP_HIDE_FROM_ABI
58 constexpr _Tp* end() noexcept { return data() + 1; }
59
60 _LIBCPP_HIDE_FROM_ABI
61 constexpr const _Tp* end() const noexcept { return data() + 1; }
62
63 _LIBCPP_HIDE_FROM_ABI
64 static constexpr size_t size() noexcept { return 1; }
65
66 _LIBCPP_HIDE_FROM_ABI
67 constexpr _Tp* data() noexcept { return __value_.operator->(); }
68
69 _LIBCPP_HIDE_FROM_ABI
70 constexpr const _Tp* data() const noexcept { return __value_.operator->(); }
71 };
72
73 template<class _Tp>
74 single_view(_Tp) -> single_view<_Tp>;
75} // namespace ranges
76
77#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
78
79_LIBCPP_END_NAMESPACE_STD
80
81#endif // _LIBCPP___RANGES_SINGLE_VIEW_H
lib/libcxx/include/__ranges/size.h+29-26
......@@ -9,12 +9,12 @@
99#ifndef _LIBCPP___RANGES_SIZE_H
1010#define _LIBCPP___RANGES_SIZE_H
1111
12#include <__concepts/class_or_enum.h>
1213#include <__config>
1314#include <__iterator/concepts.h>
1415#include <__iterator/iterator_traits.h>
1516#include <__ranges/access.h>
16#include <__utility/__decay_copy.h>
17#include <__utility/forward.h>
17#include <__utility/auto_cast.h>
1818#include <concepts>
1919#include <type_traits>
2020
......@@ -22,19 +22,18 @@
2222#pragma GCC system_header
2323#endif
2424
25_LIBCPP_PUSH_MACROS
26#include <__undef_macros>
27
2825_LIBCPP_BEGIN_NAMESPACE_STD
2926
30#if !defined(_LIBCPP_HAS_NO_RANGES)
27#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
3128
32// clang-format off
3329namespace ranges {
34template<class>
35inline constexpr bool disable_sized_range = false;
30 template<class>
31 inline constexpr bool disable_sized_range = false;
32} // namespace ranges
3633
3734// [range.prim.size]
35
36namespace ranges {
3837namespace __size {
3938 void size(auto&) = delete;
4039 void size(const auto&) = delete;
......@@ -43,9 +42,12 @@ namespace __size {
4342 concept __size_enabled = !disable_sized_range<remove_cvref_t<_Tp>>;
4443
4544 template <class _Tp>
46 concept __member_size = __size_enabled<_Tp> && requires(_Tp&& __t) {
47 { _VSTD::__decay_copy(_VSTD::forward<_Tp>(__t).size()) } -> __integer_like;
48 };
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 };
4951
5052 template <class _Tp>
5153 concept __unqualified_size =
......@@ -53,7 +55,7 @@ namespace __size {
5355 !__member_size<_Tp> &&
5456 __class_or_enum<remove_cvref_t<_Tp>> &&
5557 requires(_Tp&& __t) {
56 { _VSTD::__decay_copy(size(_VSTD::forward<_Tp>(__t))) } -> __integer_like;
58 { _LIBCPP_AUTO_CAST(size(__t)) } -> __integer_like;
5759 };
5860
5961 template <class _Tp>
......@@ -79,14 +81,14 @@ namespace __size {
7981
8082 template <__member_size _Tp>
8183 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr __integer_like auto operator()(_Tp&& __t) const
82 noexcept(noexcept(_VSTD::forward<_Tp>(__t).size())) {
83 return _VSTD::forward<_Tp>(__t).size();
84 noexcept(noexcept(_LIBCPP_AUTO_CAST(__t.size()))) {
85 return _LIBCPP_AUTO_CAST(__t.size());
8486 }
8587
8688 template <__unqualified_size _Tp>
8789 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr __integer_like auto operator()(_Tp&& __t) const
88 noexcept(noexcept(size(_VSTD::forward<_Tp>(__t)))) {
89 return size(_VSTD::forward<_Tp>(__t));
90 noexcept(noexcept(_LIBCPP_AUTO_CAST(size(__t)))) {
91 return _LIBCPP_AUTO_CAST(size(__t));
9092 }
9193
9294 template<__difference _Tp>
......@@ -95,18 +97,23 @@ namespace __size {
9597 return _VSTD::__to_unsigned_like(ranges::end(__t) - ranges::begin(__t));
9698 }
9799 };
98} // end namespace __size
100} // namespace __size
99101
100102inline namespace __cpo {
101103 inline constexpr auto size = __size::__fn{};
102104} // namespace __cpo
105} // namespace ranges
106
107// [range.prim.ssize]
103108
109namespace ranges {
104110namespace __ssize {
105111 struct __fn {
106112 template<class _Tp>
107113 requires requires (_Tp&& __t) { ranges::size(__t); }
108114 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr integral auto operator()(_Tp&& __t) const
109 noexcept(noexcept(ranges::size(__t))) {
115 noexcept(noexcept(ranges::size(__t)))
116 {
110117 using _Signed = make_signed_t<decltype(ranges::size(__t))>;
111118 if constexpr (sizeof(ptrdiff_t) > sizeof(_Signed))
112119 return static_cast<ptrdiff_t>(ranges::size(__t));
......@@ -114,19 +121,15 @@ namespace __ssize {
114121 return static_cast<_Signed>(ranges::size(__t));
115122 }
116123 };
117}
124} // namespace __ssize
118125
119126inline namespace __cpo {
120 inline constexpr const auto ssize = __ssize::__fn{};
127 inline constexpr auto ssize = __ssize::__fn{};
121128} // namespace __cpo
122129} // namespace ranges
123130
124// clang-format off
125
126#endif // !defined(_LIBCPP_HAS_NO_RANGES)
131#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
127132
128133_LIBCPP_END_NAMESPACE_STD
129134
130_LIBCPP_POP_MACROS
131
132135#endif // _LIBCPP___RANGES_SIZE_H
lib/libcxx/include/__ranges/subrange.h+99-77
......@@ -9,40 +9,45 @@
99#ifndef _LIBCPP___RANGES_SUBRANGE_H
1010#define _LIBCPP___RANGES_SUBRANGE_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/different_from.h>
1217#include <__config>
18#include <__debug>
19#include <__iterator/advance.h>
1320#include <__iterator/concepts.h>
1421#include <__iterator/incrementable_traits.h>
1522#include <__iterator/iterator_traits.h>
16#include <__iterator/advance.h>
1723#include <__ranges/access.h>
1824#include <__ranges/concepts.h>
1925#include <__ranges/dangling.h>
2026#include <__ranges/enable_borrowed_range.h>
2127#include <__ranges/size.h>
2228#include <__ranges/view_interface.h>
23#include <concepts>
29#include <__tuple>
30#include <__utility/move.h>
2431#include <type_traits>
2532
2633#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2734#pragma GCC system_header
2835#endif
2936
30_LIBCPP_PUSH_MACROS
31#include <__undef_macros>
32
3337_LIBCPP_BEGIN_NAMESPACE_STD
3438
35#if !defined(_LIBCPP_HAS_NO_RANGES)
39#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
3640
37// clang-format off
3841namespace ranges {
42 template<class _From, class _To>
43 concept __uses_nonqualification_pointer_conversion =
44 is_pointer_v<_From> && is_pointer_v<_To> &&
45 !convertible_to<remove_pointer_t<_From>(*)[], remove_pointer_t<_To>(*)[]>;
46
3947 template<class _From, class _To>
4048 concept __convertible_to_non_slicing =
4149 convertible_to<_From, _To> &&
42 // If they're both pointers, they must have the same element type.
43 !(is_pointer_v<decay_t<_From>> &&
44 is_pointer_v<decay_t<_To>> &&
45 __different_from<remove_pointer_t<decay_t<_From>>, remove_pointer_t<decay_t<_To>>>);
50 !__uses_nonqualification_pointer_conversion<decay_t<_From>, decay_t<_To>>;
4651
4752 template<class _Tp>
4853 concept __pair_like =
......@@ -64,59 +69,43 @@ namespace ranges {
6469
6570 enum class _LIBCPP_ENUM_VIS subrange_kind : bool { unsized, sized };
6671
67 template<class _Iter, class _Sent, bool>
68 struct __subrange_base {
69 static constexpr bool __store_size = false;
70 _Iter __begin_ = _Iter();
71 _Sent __end_ = _Sent();
72
73 _LIBCPP_HIDE_FROM_ABI
74 constexpr __subrange_base() = default;
75
76 _LIBCPP_HIDE_FROM_ABI
77 constexpr __subrange_base(_Iter __iter, _Sent __sent, make_unsigned_t<iter_difference_t<_Iter>> = 0)
78 : __begin_(_VSTD::move(__iter)), __end_(__sent) { }
79 };
80
81 template<class _Iter, class _Sent>
82 struct __subrange_base<_Iter, _Sent, true> {
83 static constexpr bool __store_size = true;
84 _Iter __begin_ = _Iter();
85 _Sent __end_ = _Sent();
86 make_unsigned_t<iter_difference_t<_Iter>> __size_ = 0;
87
88 _LIBCPP_HIDE_FROM_ABI
89 constexpr __subrange_base() = default;
90
91 _LIBCPP_HIDE_FROM_ABI
92 constexpr __subrange_base(_Iter __iter, _Sent __sent, decltype(__size_) __size)
93 : __begin_(_VSTD::move(__iter)), __end_(__sent), __size_(__size) { }
94 };
95
9672 template<input_or_output_iterator _Iter, sentinel_for<_Iter> _Sent = _Iter,
9773 subrange_kind _Kind = sized_sentinel_for<_Sent, _Iter>
9874 ? subrange_kind::sized
9975 : subrange_kind::unsized>
10076 requires (_Kind == subrange_kind::sized || !sized_sentinel_for<_Sent, _Iter>)
101 struct _LIBCPP_TEMPLATE_VIS subrange
102 : public view_interface<subrange<_Iter, _Sent, _Kind>>,
103 private __subrange_base<_Iter, _Sent, _Kind == subrange_kind::sized && !sized_sentinel_for<_Sent, _Iter>> {
104
105 using _Base = __subrange_base<_Iter, _Sent, _Kind == subrange_kind::sized && !sized_sentinel_for<_Sent, _Iter>>;
106
77 class _LIBCPP_TEMPLATE_VIS subrange
78 : public view_interface<subrange<_Iter, _Sent, _Kind>>
79 {
80 private:
81 static constexpr bool _StoreSize = (_Kind == subrange_kind::sized && !sized_sentinel_for<_Sent, _Iter>);
82 static constexpr bool _MustProvideSizeAtConstruction = !_StoreSize; // just to improve compiler diagnostics
83 struct _Empty { constexpr _Empty(auto) noexcept { } };
84 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
89 public:
10790 _LIBCPP_HIDE_FROM_ABI
10891 subrange() requires default_initializable<_Iter> = default;
10992
11093 _LIBCPP_HIDE_FROM_ABI
11194 constexpr subrange(__convertible_to_non_slicing<_Iter> auto __iter, _Sent __sent)
112 requires (!_Base::__store_size)
113 : _Base(_VSTD::move(__iter), __sent) {}
95 requires _MustProvideSizeAtConstruction
96 : __begin_(_VSTD::move(__iter)), __end_(_VSTD::move(__sent))
97 { }
11498
11599 _LIBCPP_HIDE_FROM_ABI
116100 constexpr subrange(__convertible_to_non_slicing<_Iter> auto __iter, _Sent __sent,
117101 make_unsigned_t<iter_difference_t<_Iter>> __n)
118102 requires (_Kind == subrange_kind::sized)
119 : _Base(_VSTD::move(__iter), __sent, __n) { }
103 : __begin_(_VSTD::move(__iter)), __end_(_VSTD::move(__sent)), __size_(__n)
104 {
105 if constexpr (sized_sentinel_for<_Sent, _Iter>)
106 _LIBCPP_ASSERT((__end_ - __begin_) == static_cast<iter_difference_t<_Iter>>(__n),
107 "std::ranges::subrange was passed an invalid size hint");
108 }
120109
121110 template<__different_from<subrange> _Range>
122111 requires borrowed_range<_Range> &&
......@@ -124,8 +113,9 @@ namespace ranges {
124113 convertible_to<sentinel_t<_Range>, _Sent>
125114 _LIBCPP_HIDE_FROM_ABI
126115 constexpr subrange(_Range&& __range)
127 requires (!_Base::__store_size)
128 : subrange(ranges::begin(__range), ranges::end(__range)) { }
116 requires (!_StoreSize)
117 : subrange(ranges::begin(__range), ranges::end(__range))
118 { }
129119
130120 template<__different_from<subrange> _Range>
131121 requires borrowed_range<_Range> &&
......@@ -133,9 +123,9 @@ namespace ranges {
133123 convertible_to<sentinel_t<_Range>, _Sent>
134124 _LIBCPP_HIDE_FROM_ABI
135125 constexpr subrange(_Range&& __range)
136 requires _Base::__store_size && sized_range<_Range>
137 : subrange(__range, ranges::size(__range)) { }
138
126 requires _StoreSize && sized_range<_Range>
127 : subrange(__range, ranges::size(__range))
128 { }
139129
140130 template<borrowed_range _Range>
141131 requires __convertible_to_non_slicing<iterator_t<_Range>, _Iter> &&
......@@ -143,39 +133,47 @@ namespace ranges {
143133 _LIBCPP_HIDE_FROM_ABI
144134 constexpr subrange(_Range&& __range, make_unsigned_t<iter_difference_t<_Iter>> __n)
145135 requires (_Kind == subrange_kind::sized)
146 : subrange(ranges::begin(__range), ranges::end(__range), __n) { }
136 : subrange(ranges::begin(__range), ranges::end(__range), __n)
137 { }
147138
148139 template<__different_from<subrange> _Pair>
149140 requires __pair_like_convertible_from<_Pair, const _Iter&, const _Sent&>
150141 _LIBCPP_HIDE_FROM_ABI
151 constexpr operator _Pair() const { return _Pair(this->__begin_, this->__end_); }
142 constexpr operator _Pair() const {
143 return _Pair(__begin_, __end_);
144 }
152145
153146 _LIBCPP_HIDE_FROM_ABI
154147 constexpr _Iter begin() const requires copyable<_Iter> {
155 return this->__begin_;
148 return __begin_;
156149 }
157150
158151 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Iter begin() requires (!copyable<_Iter>) {
159 return _VSTD::move(this->__begin_);
152 return _VSTD::move(__begin_);
160153 }
161154
162155 _LIBCPP_HIDE_FROM_ABI
163 constexpr _Sent end() const { return this->__end_; }
156 constexpr _Sent end() const {
157 return __end_;
158 }
164159
165 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool empty() const { return this->__begin_ == this->__end_; }
160 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool empty() const {
161 return __begin_ == __end_;
162 }
166163
167164 _LIBCPP_HIDE_FROM_ABI
168165 constexpr make_unsigned_t<iter_difference_t<_Iter>> size() const
169166 requires (_Kind == subrange_kind::sized)
170167 {
171 if constexpr (_Base::__store_size)
172 return this->__size_;
168 if constexpr (_StoreSize)
169 return __size_;
173170 else
174 return __to_unsigned_like(this->__end_ - this->__begin_);
171 return _VSTD::__to_unsigned_like(__end_ - __begin_);
175172 }
176173
177174 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr subrange next(iter_difference_t<_Iter> __n = 1) const&
178 requires forward_iterator<_Iter> {
175 requires forward_iterator<_Iter>
176 {
179177 auto __tmp = *this;
180178 __tmp.advance(__n);
181179 return __tmp;
......@@ -187,7 +185,8 @@ namespace ranges {
187185 }
188186
189187 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr subrange prev(iter_difference_t<_Iter> __n = 1) const
190 requires bidirectional_iterator<_Iter> {
188 requires bidirectional_iterator<_Iter>
189 {
191190 auto __tmp = *this;
192191 __tmp.advance(-__n);
193192 return __tmp;
......@@ -197,16 +196,16 @@ namespace ranges {
197196 constexpr subrange& advance(iter_difference_t<_Iter> __n) {
198197 if constexpr (bidirectional_iterator<_Iter>) {
199198 if (__n < 0) {
200 ranges::advance(this->__begin_, __n);
201 if constexpr (_Base::__store_size)
202 this->__size_ += _VSTD::__to_unsigned_like(-__n);
199 ranges::advance(__begin_, __n);
200 if constexpr (_StoreSize)
201 __size_ += _VSTD::__to_unsigned_like(-__n);
203202 return *this;
204203 }
205204 }
206205
207 auto __d = __n - ranges::advance(this->__begin_, __n, this->__end_);
208 if constexpr (_Base::__store_size)
209 this->__size_ -= _VSTD::__to_unsigned_like(__d);
206 auto __d = __n - ranges::advance(__begin_, __n, __end_);
207 if constexpr (_StoreSize)
208 __size_ -= _VSTD::__to_unsigned_like(__d);
210209 return *this;
211210 }
212211 };
......@@ -228,7 +227,7 @@ namespace ranges {
228227 -> subrange<iterator_t<_Range>, sentinel_t<_Range>, subrange_kind::sized>;
229228
230229 template<size_t _Index, class _Iter, class _Sent, subrange_kind _Kind>
231 requires (_Index < 2)
230 requires ((_Index == 0 && copyable<_Iter>) || _Index == 1)
232231 _LIBCPP_HIDE_FROM_ABI
233232 constexpr auto get(const subrange<_Iter, _Sent, _Kind>& __subrange) {
234233 if constexpr (_Index == 0)
......@@ -251,17 +250,40 @@ namespace ranges {
251250 inline constexpr bool enable_borrowed_range<subrange<_Ip, _Sp, _Kp>> = true;
252251
253252 template<range _Rp>
254 using borrowed_subrange_t = _If<borrowed_range<_Rp>, subrange<iterator_t<_Rp> >, dangling>;
253 using borrowed_subrange_t = _If<borrowed_range<_Rp>, subrange<iterator_t<_Rp>>, dangling>;
255254} // namespace ranges
256255
256// [range.subrange.general]
257
257258using ranges::get;
258259
259// clang-format off
260// [ranges.syn]
260261
261#endif // !defined(_LIBCPP_HAS_NO_RANGES)
262template<class _Ip, class _Sp, ranges::subrange_kind _Kp>
263struct tuple_size<ranges::subrange<_Ip, _Sp, _Kp>> : integral_constant<size_t, 2> {};
262264
263_LIBCPP_END_NAMESPACE_STD
265template<class _Ip, class _Sp, ranges::subrange_kind _Kp>
266struct tuple_element<0, ranges::subrange<_Ip, _Sp, _Kp>> {
267 using type = _Ip;
268};
269
270template<class _Ip, class _Sp, ranges::subrange_kind _Kp>
271struct tuple_element<1, ranges::subrange<_Ip, _Sp, _Kp>> {
272 using type = _Sp;
273};
264274
265_LIBCPP_POP_MACROS
275template<class _Ip, class _Sp, ranges::subrange_kind _Kp>
276struct tuple_element<0, const ranges::subrange<_Ip, _Sp, _Kp>> {
277 using type = _Ip;
278};
279
280template<class _Ip, class _Sp, ranges::subrange_kind _Kp>
281struct tuple_element<1, const ranges::subrange<_Ip, _Sp, _Kp>> {
282 using type = _Sp;
283};
284
285#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
286
287_LIBCPP_END_NAMESPACE_STD
266288
267289#endif // _LIBCPP___RANGES_SUBRANGE_H
lib/libcxx/include/__ranges/take_view.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#ifndef _LIBCPP___RANGES_TAKE_VIEW_H
10#define _LIBCPP___RANGES_TAKE_VIEW_H
11
12#include <__algorithm/min.h>
13#include <__config>
14#include <__iterator/concepts.h>
15#include <__iterator/counted_iterator.h>
16#include <__iterator/default_sentinel.h>
17#include <__iterator/iterator_traits.h>
18#include <__ranges/access.h>
19#include <__ranges/all.h>
20#include <__ranges/concepts.h>
21#include <__ranges/enable_borrowed_range.h>
22#include <__ranges/size.h>
23#include <__ranges/view_interface.h>
24#include <__utility/move.h>
25#include <concepts>
26#include <type_traits>
27
28#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
29#pragma GCC system_header
30#endif
31
32_LIBCPP_PUSH_MACROS
33#include <__undef_macros>
34
35_LIBCPP_BEGIN_NAMESPACE_STD
36
37#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
38
39namespace 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 }
71 } else {
72 return counted_iterator(ranges::begin(__base_), __count_);
73 }
74 }
75
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 }
86 } else {
87 return counted_iterator(ranges::begin(__base_), __count_);
88 }
89 }
90
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 }
99 } else {
100 return __sentinel<false>{ranges::end(__base_)};
101 }
102 }
103
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 }
112 } else {
113 return __sentinel<true>{ranges::end(__base_)};
114 }
115 }
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;
143
144public:
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>>;
174
175 template<class _Tp>
176 inline constexpr bool enable_borrowed_range<take_view<_Tp>> = enable_borrowed_range<_Tp>;
177} // namespace ranges
178
179#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
180
181_LIBCPP_END_NAMESPACE_STD
182
183_LIBCPP_POP_MACROS
184
185#endif // _LIBCPP___RANGES_TAKE_VIEW_H
lib/libcxx/include/__ranges/transform_view.h+57-25
......@@ -9,38 +9,51 @@
99#ifndef _LIBCPP___RANGES_TRANSFORM_VIEW_H
1010#define _LIBCPP___RANGES_TRANSFORM_VIEW_H
1111
12#include <__compare/three_way_comparable.h>
13#include <__concepts/constructible.h>
14#include <__concepts/convertible_to.h>
15#include <__concepts/copyable.h>
16#include <__concepts/derived_from.h>
17#include <__concepts/equality_comparable.h>
18#include <__concepts/invocable.h>
1219#include <__config>
20#include <__functional/bind_back.h>
21#include <__functional/invoke.h>
1322#include <__iterator/concepts.h>
14#include <__iterator/iter_swap.h>
1523#include <__iterator/iterator_traits.h>
24#include <__memory/addressof.h>
1625#include <__ranges/access.h>
1726#include <__ranges/all.h>
1827#include <__ranges/concepts.h>
1928#include <__ranges/copyable_box.h>
2029#include <__ranges/empty.h>
30#include <__ranges/range_adaptor.h>
2131#include <__ranges/size.h>
2232#include <__ranges/view_interface.h>
23#include <concepts>
33#include <__utility/forward.h>
34#include <__utility/in_place.h>
35#include <__utility/move.h>
2436#include <type_traits>
2537
2638#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2739#pragma GCC system_header
2840#endif
2941
30_LIBCPP_PUSH_MACROS
31#include <__undef_macros>
32
3342_LIBCPP_BEGIN_NAMESPACE_STD
3443
35#if !defined(_LIBCPP_HAS_NO_RANGES)
44#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
3645
3746namespace ranges {
3847
48template<class _Fn, class _View>
49concept __regular_invocable_with_range_ref =
50 regular_invocable<_Fn, range_reference_t<_View>>;
51
3952template<class _View, class _Fn>
4053concept __transform_view_constraints =
41 view<_View> && is_object_v<_Fn> &&
42 regular_invocable<_Fn&, range_reference_t<_View>> &&
43 __referenceable<invoke_result_t<_Fn&, range_reference_t<_View>>>;
54 view<_View> && is_object_v<_Fn> &&
55 regular_invocable<_Fn&, range_reference_t<_View>> &&
56 __referenceable<invoke_result_t<_Fn&, range_reference_t<_View>>>;
4457
4558template<input_range _View, copy_constructible _Fn>
4659 requires __transform_view_constraints<_View, _Fn>
......@@ -72,7 +85,7 @@ public:
7285 _LIBCPP_HIDE_FROM_ABI
7386 constexpr __iterator<true> begin() const
7487 requires range<const _View> &&
75 regular_invocable<const _Fn&, range_reference_t<const _View>>
88 __regular_invocable_with_range_ref<const _Fn&, const _View>
7689 {
7790 return __iterator<true>(*this, ranges::begin(__base_));
7891 }
......@@ -90,14 +103,14 @@ public:
90103 _LIBCPP_HIDE_FROM_ABI
91104 constexpr __sentinel<true> end() const
92105 requires range<const _View> &&
93 regular_invocable<const _Fn&, range_reference_t<const _View>>
106 __regular_invocable_with_range_ref<const _Fn&, const _View>
94107 {
95108 return __sentinel<true>(ranges::end(__base_));
96109 }
97110 _LIBCPP_HIDE_FROM_ABI
98111 constexpr __iterator<true> end() const
99112 requires common_range<const _View> &&
100 regular_invocable<const _Fn&, range_reference_t<const _View>>
113 __regular_invocable_with_range_ref<const _Fn&, const _View>
101114 {
102115 return __iterator<true>(*this, ranges::end(__base_));
103116 }
......@@ -181,9 +194,7 @@ public:
181194 : __parent_(__i.__parent_), __current_(_VSTD::move(__i.__current_)) {}
182195
183196 _LIBCPP_HIDE_FROM_ABI
184 constexpr iterator_t<_Base> base() const&
185 requires copyable<iterator_t<_Base>>
186 {
197 constexpr const iterator_t<_Base>& base() const& noexcept {
187198 return __current_;
188199 }
189200
......@@ -293,13 +304,12 @@ public:
293304 return __x.__current_ >= __y.__current_;
294305 }
295306
296// TODO: Fix this as soon as soon as three_way_comparable is implemented.
297// _LIBCPP_HIDE_FROM_ABI
298// friend constexpr auto operator<=>(const __iterator& __x, const __iterator& __y)
299// requires random_access_range<_Base> && three_way_comparable<iterator_t<_Base>>
300// {
301// return __x.__current_ <=> __y.__current_;
302// }
307 _LIBCPP_HIDE_FROM_ABI
308 friend constexpr auto operator<=>(const __iterator& __x, const __iterator& __y)
309 requires random_access_range<_Base> && three_way_comparable<iterator_t<_Base>>
310 {
311 return __x.__current_ <=> __y.__current_;
312 }
303313
304314 _LIBCPP_HIDE_FROM_ABI
305315 friend constexpr __iterator operator+(__iterator __i, difference_type __n)
......@@ -397,12 +407,34 @@ public:
397407 }
398408};
399409
410namespace views {
411namespace __transform {
412 struct __fn {
413 template<class _Range, class _Fn>
414 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
415 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)); }
419
420 template<class _Fn>
421 requires constructible_from<decay_t<_Fn>, _Fn>
422 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
423 constexpr auto operator()(_Fn&& __f) const
424 noexcept(is_nothrow_constructible_v<decay_t<_Fn>, _Fn>)
425 { return __range_adaptor_closure_t(_VSTD::__bind_back(*this, _VSTD::forward<_Fn>(__f))); }
426 };
427} // namespace __transform
428
429inline namespace __cpo {
430 inline constexpr auto transform = __transform::__fn{};
431} // namespace __cpo
432} // namespace views
433
400434} // namespace ranges
401435
402#endif // !defined(_LIBCPP_HAS_NO_RANGES)
436#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
403437
404438_LIBCPP_END_NAMESPACE_STD
405439
406_LIBCPP_POP_MACROS
407
408440#endif // _LIBCPP___RANGES_TRANSFORM_VIEW_H
lib/libcxx/include/__ranges/view_interface.h+7-10
......@@ -10,6 +10,7 @@
1010#define _LIBCPP___RANGES_VIEW_INTERFACE_H
1111
1212#include <__config>
13#include <__debug>
1314#include <__iterator/concepts.h>
1415#include <__iterator/iterator_traits.h>
1516#include <__iterator/prev.h>
......@@ -17,7 +18,6 @@
1718#include <__ranges/access.h>
1819#include <__ranges/concepts.h>
1920#include <__ranges/empty.h>
20#include <__ranges/enable_view.h>
2121#include <concepts>
2222#include <type_traits>
2323
......@@ -25,12 +25,9 @@
2525#pragma GCC system_header
2626#endif
2727
28_LIBCPP_PUSH_MACROS
29#include <__undef_macros>
30
3128_LIBCPP_BEGIN_NAMESPACE_STD
3229
33#if !defined(_LIBCPP_HAS_NO_RANGES)
30#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
3431
3532namespace ranges {
3633
......@@ -42,14 +39,16 @@ void __implicitly_convert_to(type_identity_t<_Tp>) noexcept;
4239
4340template<class _Derived>
4441 requires is_class_v<_Derived> && same_as<_Derived, remove_cv_t<_Derived>>
45class view_interface : public view_base {
42class view_interface {
4643 _LIBCPP_HIDE_FROM_ABI
4744 constexpr _Derived& __derived() noexcept {
45 static_assert(sizeof(_Derived) && derived_from<_Derived, view_interface> && view<_Derived>);
4846 return static_cast<_Derived&>(*this);
4947 }
5048
5149 _LIBCPP_HIDE_FROM_ABI
5250 constexpr _Derived const& __derived() const noexcept {
51 static_assert(sizeof(_Derived) && derived_from<_Derived, view_interface> && view<_Derived>);
5352 return static_cast<_Derived const&>(*this);
5453 }
5554
......@@ -187,12 +186,10 @@ public:
187186 }
188187};
189188
190}
189} // namespace ranges
191190
192#endif // !defined(_LIBCPP_HAS_NO_RANGES)
191#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
193192
194193_LIBCPP_END_NAMESPACE_STD
195194
196_LIBCPP_POP_MACROS
197
198195#endif // _LIBCPP___RANGES_VIEW_INTERFACE_H
lib/libcxx/include/__ranges/views.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___RANGES_VIEWS
11#define _LIBCPP___RANGES_VIEWS
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 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
22
23namespace ranges {
24
25namespace views { }
26
27} // namespace ranges
28
29namespace views = ranges::views;
30
31#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
32
33_LIBCPP_END_NAMESPACE_STD
34
35#endif // _LIBCPP___RANGES_VIEWS
lib/libcxx/include/__split_buffer+2-11
......@@ -17,17 +17,8 @@ _LIBCPP_PUSH_MACROS
1717
1818_LIBCPP_BEGIN_NAMESPACE_STD
1919
20template <bool>
21class __split_buffer_common
22{
23protected:
24 _LIBCPP_NORETURN void __throw_length_error() const;
25 _LIBCPP_NORETURN void __throw_out_of_range() const;
26};
27
2820template <class _Tp, class _Allocator = allocator<_Tp> >
2921struct __split_buffer
30 : private __split_buffer_common<true>
3122{
3223private:
3324 __split_buffer(const __split_buffer&);
......@@ -248,7 +239,7 @@ __split_buffer<_Tp, _Allocator>::__construct_at_end(_InputIter __first, _InputIt
248239 size_type __old_cap = __end_cap() - __first_;
249240 size_type __new_cap = _VSTD::max<size_type>(2 * __old_cap, 8);
250241 __split_buffer __buf(__new_cap, 0, __a);
251 for (pointer __p = __begin_; __p != __end_; ++__p, ++__buf.__end_)
242 for (pointer __p = __begin_; __p != __end_; ++__p, (void) ++__buf.__end_)
252243 __alloc_traits::construct(__buf.__alloc(),
253244 _VSTD::__to_address(__buf.__end_), _VSTD::move(*__p));
254245 swap(__buf);
......@@ -268,7 +259,7 @@ typename enable_if
268259__split_buffer<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
269260{
270261 _ConstructTransaction __tx(&this->__end_, _VSTD::distance(__first, __last));
271 for (; __tx.__pos_ != __tx.__end_; ++__tx.__pos_, ++__first) {
262 for (; __tx.__pos_ != __tx.__end_; ++__tx.__pos_, (void) ++__first) {
272263 __alloc_traits::construct(this->__alloc(),
273264 _VSTD::__to_address(__tx.__pos_), *__first);
274265 }
lib/libcxx/include/__string+71-42
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===-------------------------- __string ----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -10,22 +10,26 @@
1010#ifndef _LIBCPP___STRING
1111#define _LIBCPP___STRING
1212
13#include <__config>
1413#include <__algorithm/copy.h>
1514#include <__algorithm/copy_backward.h>
1615#include <__algorithm/copy_n.h>
1716#include <__algorithm/fill_n.h>
18#include <__algorithm/find_first_of.h>
1917#include <__algorithm/find_end.h>
18#include <__algorithm/find_first_of.h>
2019#include <__algorithm/min.h>
20#include <__config>
2121#include <__functional/hash.h> // for __murmur2_or_cityhash
2222#include <__iterator/iterator_traits.h>
23#include <cstdio> // for EOF
2423#include <cstdint> // for uint_least16_t
24#include <cstdio> // for EOF
2525#include <cstring> // for memcpy
26#include <cwchar> // for wmemcpy
26#include <iosfwd> // for streampos & friends
2727#include <type_traits> // for __libcpp_is_constant_evaluated
2828
29#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
30# include <cwchar> // for wmemcpy
31#endif
32
2933#include <__debug>
3034
3135#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -38,9 +42,6 @@ _LIBCPP_PUSH_MACROS
3842
3943_LIBCPP_BEGIN_NAMESPACE_STD
4044
41// The the extern template ABI lists are kept outside of <string> to improve the
42// readability of that header.
43
4445// The extern template ABI lists are kept outside of <string> to improve the
4546// readability of that header. We maintain 2 ABI lists:
4647// - _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST
......@@ -265,7 +266,9 @@ inline _LIBCPP_CONSTEXPR_AFTER_CXX17
265266_CharT*
266267char_traits<_CharT>::copy(char_type* __s1, const char_type* __s2, size_t __n)
267268{
268 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
269 if (!__libcpp_is_constant_evaluated()) {
270 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
271 }
269272 char_type* __r = __s1;
270273 for (; __n; --__n, ++__s1, ++__s2)
271274 assign(*__s1, *__s2);
......@@ -287,31 +290,34 @@ char_traits<_CharT>::assign(char_type* __s, size_t __n, char_type __a)
287290
288291template <class _CharT>
289292static inline _LIBCPP_CONSTEXPR_AFTER_CXX17
290_CharT* __move_constexpr(_CharT* __s1, const _CharT* __s2, size_t __n) _NOEXCEPT
293_CharT* __copy_constexpr(_CharT* __dest, const _CharT* __source, size_t __n) _NOEXCEPT
291294{
292 if (__n == 0) return __s1;
293 if (__s1 < __s2) {
294 _VSTD::copy(__s2, __s2 + __n, __s1);
295 } else if (__s2 < __s1) {
296 _VSTD::copy_backward(__s2, __s2 + __n, __s1 + __n);
297 }
298 return __s1;
295 _LIBCPP_ASSERT(__libcpp_is_constant_evaluated(), "__copy_constexpr() should always be constant evaluated");
296 _VSTD::copy_n(__source, __n, __dest);
297 return __dest;
299298}
300299
301300template <class _CharT>
302301static inline _LIBCPP_CONSTEXPR_AFTER_CXX17
303_CharT* __copy_constexpr(_CharT* __s1, const _CharT* __s2, size_t __n) _NOEXCEPT
302_CharT* __move_constexpr(_CharT* __dest, const _CharT* __source, size_t __n) _NOEXCEPT
304303{
305 _VSTD::copy_n(__s2, __n, __s1);
306 return __s1;
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;
307312}
308313
309314template <class _CharT>
310315static inline _LIBCPP_CONSTEXPR_AFTER_CXX17
311316_CharT* __assign_constexpr(_CharT* __s, size_t __n, _CharT __a) _NOEXCEPT
312317{
313 _VSTD::fill_n(__s, __n, __a);
314 return __s;
318 _LIBCPP_ASSERT(__libcpp_is_constant_evaluated(), "__assign_constexpr() should always be constant evaluated");
319 _VSTD::fill_n(__s, __n, __a);
320 return __s;
315321}
316322
317323// char_traits<char>
......@@ -334,8 +340,21 @@ struct _LIBCPP_TEMPLATE_VIS char_traits<char>
334340
335341 static _LIBCPP_CONSTEXPR_AFTER_CXX14
336342 int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
337 static inline size_t _LIBCPP_CONSTEXPR_AFTER_CXX14
338 length(const char_type* __s) _NOEXCEPT {return __builtin_strlen(__s);}
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
339358 static _LIBCPP_CONSTEXPR_AFTER_CXX14
340359 const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT;
341360 static inline _LIBCPP_CONSTEXPR_AFTER_CXX17
......@@ -348,7 +367,9 @@ struct _LIBCPP_TEMPLATE_VIS char_traits<char>
348367 static inline _LIBCPP_CONSTEXPR_AFTER_CXX17
349368 char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
350369 {
351 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
370 if (!__libcpp_is_constant_evaluated()) {
371 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
372 }
352373 return __libcpp_is_constant_evaluated()
353374 ? _VSTD::__copy_constexpr(__s1, __s2, __n)
354375 : __n == 0 ? __s1 : (char_type*)_VSTD::memcpy(__s1, __s2, __n);
......@@ -419,6 +440,7 @@ char_traits<char>::find(const char_type* __s, size_t __n, const char_type& __a)
419440
420441// char_traits<wchar_t>
421442
443#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
422444template <>
423445struct _LIBCPP_TEMPLATE_VIS char_traits<wchar_t>
424446{
......@@ -451,7 +473,9 @@ struct _LIBCPP_TEMPLATE_VIS char_traits<wchar_t>
451473 static inline _LIBCPP_CONSTEXPR_AFTER_CXX17
452474 char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
453475 {
454 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
476 if (!__libcpp_is_constant_evaluated()) {
477 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
478 }
455479 return __libcpp_is_constant_evaluated()
456480 ? _VSTD::__copy_constexpr(__s1, __s2, __n)
457481 : __n == 0 ? __s1 : _VSTD::wmemcpy(__s1, __s2, __n);
......@@ -497,18 +521,6 @@ char_traits<wchar_t>::compare(const char_type* __s1, const char_type* __s2, size
497521#endif
498522}
499523
500
501template <class _Traits>
502_LIBCPP_INLINE_VISIBILITY
503_LIBCPP_CONSTEXPR
504inline size_t __char_traits_length_checked(const typename _Traits::char_type* __s) _NOEXCEPT {
505#if _LIBCPP_DEBUG_LEVEL >= 1
506 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);
507#else
508 return _Traits::length(__s);
509#endif
510}
511
512524inline _LIBCPP_CONSTEXPR_AFTER_CXX14
513525size_t
514526char_traits<wchar_t>::length(const char_type* __s) _NOEXCEPT
......@@ -545,7 +557,18 @@ char_traits<wchar_t>::find(const char_type* __s, size_t __n, const char_type& __
545557 return nullptr;
546558#endif
547559}
560#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
548561
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}
549572
550573#ifndef _LIBCPP_HAS_NO_CHAR8_T
551574
......@@ -584,8 +607,10 @@ struct _LIBCPP_TEMPLATE_VIS char_traits<char8_t>
584607
585608 static _LIBCPP_CONSTEXPR_AFTER_CXX17
586609 char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
587 {
588 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
610 {
611 if (!__libcpp_is_constant_evaluated()) {
612 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
613 }
589614 return __libcpp_is_constant_evaluated()
590615 ? _VSTD::__copy_constexpr(__s1, __s2, __n)
591616 : __n == 0 ? __s1 : (char_type*)_VSTD::memcpy(__s1, __s2, __n);
......@@ -761,7 +786,9 @@ inline _LIBCPP_CONSTEXPR_AFTER_CXX17
761786char16_t*
762787char_traits<char16_t>::copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
763788{
764 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
789 if (!__libcpp_is_constant_evaluated()) {
790 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
791 }
765792 char_type* __r = __s1;
766793 for (; __n; --__n, ++__s1, ++__s2)
767794 assign(*__s1, *__s2);
......@@ -881,7 +908,9 @@ inline _LIBCPP_CONSTEXPR_AFTER_CXX17
881908char32_t*
882909char_traits<char32_t>::copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
883910{
884 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
911 if (!__libcpp_is_constant_evaluated()) {
912 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
913 }
885914 char_type* __r = __s1;
886915 for (; __n; --__n, ++__s1, ++__s2)
887916 assign(*__s1, *__s2);
lib/libcxx/include/__support/ibm/locale_mgmt_aix.h deleted-84
......@@ -1,84 +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_LOCALE_MGMT_AIX_H
11#define _LIBCPP_SUPPORT_IBM_LOCALE_MGMT_AIX_H
12
13#if defined(_AIX)
14#include "cstdlib"
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
20#if !defined(_AIX71)
21// AIX 7.1 and higher has these definitions. Definitions and stubs
22// are provied here as a temporary workaround on AIX 6.1.
23
24#define LC_COLLATE_MASK 1
25#define LC_CTYPE_MASK 2
26#define LC_MESSAGES_MASK 4
27#define LC_MONETARY_MASK 8
28#define LC_NUMERIC_MASK 16
29#define LC_TIME_MASK 32
30#define LC_ALL_MASK (LC_COLLATE_MASK | LC_CTYPE_MASK | \
31 LC_MESSAGES_MASK | LC_MONETARY_MASK |\
32 LC_NUMERIC_MASK | LC_TIME_MASK)
33
34typedef void* locale_t;
35
36// The following are stubs. They are not supported on AIX 6.1.
37static inline
38locale_t newlocale(int category_mask, const char *locale, locale_t base)
39{
40 _LC_locale_t *newloc, *loc;
41 if ((loc = (_LC_locale_t *)__xopen_locale(locale)) == NULL)
42 {
43 errno = EINVAL;
44 return (locale_t)0;
45 }
46 if ((newloc = (_LC_locale_t *)calloc(1, sizeof(_LC_locale_t))) == NULL)
47 {
48 errno = ENOMEM;
49 return (locale_t)0;
50 }
51 if (!base)
52 base = (_LC_locale_t *)__xopen_locale("C");
53 memcpy(newloc, base, sizeof (_LC_locale_t));
54 if (category_mask & LC_COLLATE_MASK)
55 newloc->lc_collate = loc->lc_collate;
56 if (category_mask & LC_CTYPE_MASK)
57 newloc->lc_ctype = loc->lc_ctype;
58 //if (category_mask & LC_MESSAGES_MASK)
59 // newloc->lc_messages = loc->lc_messages;
60 if (category_mask & LC_MONETARY_MASK)
61 newloc->lc_monetary = loc->lc_monetary;
62 if (category_mask & LC_TIME_MASK)
63 newloc->lc_time = loc->lc_time;
64 if (category_mask & LC_NUMERIC_MASK)
65 newloc->lc_numeric = loc->lc_numeric;
66 return (locale_t)newloc;
67}
68static inline
69void freelocale(locale_t locobj)
70{
71 free(locobj);
72}
73static inline
74locale_t uselocale(locale_t newloc)
75{
76 return (locale_t)0;
77}
78#endif // !defined(_AIX71)
79
80#ifdef __cplusplus
81}
82#endif
83#endif // defined(_AIX)
84#endif // _LIBCPP_SUPPORT_IBM_LOCALE_MGMT_AIX_H
lib/libcxx/include/__support/ibm/nanosleep.h+3-4
......@@ -21,14 +21,13 @@ inline int nanosleep(const struct timespec* __req, struct timespec* __rem) {
2121 errno = EINVAL;
2222 return -1;
2323 }
24 useconds_t __micro_sec =
25 static_cast<useconds_t>((__req->tv_nsec + 999) / 1000);
24 long __micro_sec = (__req->tv_nsec + 999) / 1000;
2625 time_t __sec = __req->tv_sec;
2726 if (__micro_sec > 999999) {
2827 ++__sec;
2928 __micro_sec -= 1000000;
3029 }
31 __sec = sleep(static_cast<unsigned int>(__sec));
30 __sec = static_cast<time_t>(sleep(static_cast<unsigned int>(__sec)));
3231 if (__sec) {
3332 if (__rem) {
3433 // Updating the remaining time to sleep in case of unsuccessful call to sleep().
......@@ -39,7 +38,7 @@ inline int nanosleep(const struct timespec* __req, struct timespec* __rem) {
3938 return -1;
4039 }
4140 if (__micro_sec) {
42 int __rt = usleep(__micro_sec);
41 int __rt = usleep(static_cast<unsigned int>(__micro_sec));
4342 if (__rt != 0 && __rem) {
4443 // The usleep() does not provide the amount of remaining time upon its failure,
4544 // so the time slept will be ignored.
lib/libcxx/include/__support/ibm/xlocale.h+1-202
......@@ -10,7 +10,6 @@
1010#ifndef _LIBCPP_SUPPORT_IBM_XLOCALE_H
1111#define _LIBCPP_SUPPORT_IBM_XLOCALE_H
1212
13#include <__support/ibm/locale_mgmt_aix.h>
1413#include <__support/ibm/locale_mgmt_zos.h>
1514#include <stdarg.h>
1615
......@@ -20,207 +19,7 @@
2019extern "C" {
2120#endif
2221
23#if defined(_AIX)
24#if !defined(_AIX71)
25// AIX 7.1 and higher has these definitions. Definitions and stubs
26// are provied here as a temporary workaround on AIX 6.1.
27static inline
28int isalnum_l(int c, locale_t locale)
29{
30 return __xisalnum(locale, c);
31}
32static inline
33int isalpha_l(int c, locale_t locale)
34{
35 return __xisalpha(locale, c);
36}
37static inline
38int isblank_l(int c, locale_t locale)
39{
40 return __xisblank(locale, c);
41}
42static inline
43int iscntrl_l(int c, locale_t locale)
44{
45 return __xiscntrl(locale, c);
46}
47static inline
48int isdigit_l(int c, locale_t locale)
49{
50 return __xisdigit(locale, c);
51}
52static inline
53int isgraph_l(int c, locale_t locale)
54{
55 return __xisgraph(locale, c);
56}
57static inline
58int islower_l(int c, locale_t locale)
59{
60 return __xislower(locale, c);
61}
62static inline
63int isprint_l(int c, locale_t locale)
64{
65 return __xisprint(locale, c);
66}
67
68static inline
69int ispunct_l(int c, locale_t locale)
70{
71 return __xispunct(locale, c);
72}
73static inline
74int isspace_l(int c, locale_t locale)
75{
76 return __xisspace(locale, c);
77}
78static inline
79int isupper_l(int c, locale_t locale)
80{
81 return __xisupper(locale, c);
82}
83
84static inline
85int isxdigit_l(int c, locale_t locale)
86{
87 return __xisxdigit(locale, c);
88}
89
90static inline
91int iswalnum_l(wchar_t wc, locale_t locale)
92{
93 return __xiswalnum(locale, wc);
94}
95
96static inline
97int iswalpha_l(wchar_t wc, locale_t locale)
98{
99 return __xiswalpha(locale, wc);
100}
101
102static inline
103int iswblank_l(wchar_t wc, locale_t locale)
104{
105 return __xiswblank(locale, wc);
106}
107
108static inline
109int iswcntrl_l(wchar_t wc, locale_t locale)
110{
111 return __xiswcntrl(locale, wc);
112}
113
114static inline
115int iswdigit_l(wchar_t wc, locale_t locale)
116{
117 return __xiswdigit(locale, wc);
118}
119
120static inline
121int iswgraph_l(wchar_t wc, locale_t locale)
122{
123 return __xiswgraph(locale, wc);
124}
125
126static inline
127int iswlower_l(wchar_t wc, locale_t locale)
128{
129 return __xiswlower(locale, wc);
130}
131
132static inline
133int iswprint_l(wchar_t wc, locale_t locale)
134{
135 return __xiswprint(locale, wc);
136}
137
138static inline
139int iswpunct_l(wchar_t wc, locale_t locale)
140{
141 return __xiswpunct(locale, wc);
142}
143
144static inline
145int iswspace_l(wchar_t wc, locale_t locale)
146{
147 return __xiswspace(locale, wc);
148}
149
150static inline
151int iswupper_l(wchar_t wc, locale_t locale)
152{
153 return __xiswupper(locale, wc);
154}
155
156static inline
157int iswxdigit_l(wchar_t wc, locale_t locale)
158{
159 return __xiswxdigit(locale, wc);
160}
161
162static inline
163int iswctype_l(wint_t wc, wctype_t desc, locale_t locale)
164{
165 return __xiswctype(locale, wc, desc);
166}
167
168static inline
169int toupper_l(int c, locale_t locale)
170{
171 return __xtoupper(locale, c);
172}
173static inline
174int tolower_l(int c, locale_t locale)
175{
176 return __xtolower(locale, c);
177}
178static inline
179wint_t towupper_l(wint_t wc, locale_t locale)
180{
181 return __xtowupper(locale, wc);
182}
183static inline
184wint_t towlower_l(wint_t wc, locale_t locale)
185{
186 return __xtowlower(locale, wc);
187}
188
189static inline
190int strcoll_l(const char *__s1, const char *__s2, locale_t locale)
191{
192 return __xstrcoll(locale, __s1, __s2);
193}
194static inline
195int wcscoll_l(const wchar_t *__s1, const wchar_t *__s2, locale_t locale)
196{
197 return __xwcscoll(locale, __s1, __s2);
198}
199static inline
200size_t strxfrm_l(char *__s1, const char *__s2, size_t __n, locale_t locale)
201{
202 return __xstrxfrm(locale, __s1, __s2, __n);
203}
204
205static inline
206size_t wcsxfrm_l(wchar_t *__ws1, const wchar_t *__ws2, size_t __n,
207 locale_t locale)
208{
209 return __xwcsxfrm(locale, __ws1, __ws2, __n);
210}
211#endif // !defined(_AIX71)
212
213// strftime_l() is defined by POSIX. However, AIX 7.1 and z/OS do not have it
214// implemented yet. z/OS retrieves it from the POSIX fallbacks.
215#if !defined(_AIX72)
216static inline
217size_t strftime_l(char *__s, size_t __size, const char *__fmt,
218 const struct tm *__tm, locale_t locale) {
219 return __xstrftime(locale, __s, __size, __fmt, __tm);
220}
221#endif
222
223#elif defined(__MVS__)
22#if defined(__MVS__)
22423#include <wctype.h>
22524// POSIX routines
22625#include <__support/xlocale/__posix_l_fallback.h>
lib/libcxx/include/__support/nuttx/xlocale.h deleted-18
......@@ -1,18 +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_NUTTX_XLOCALE_H
11#define _LIBCPP_SUPPORT_NUTTX_XLOCALE_H
12
13#if defined(__NuttX__)
14#include <__support/xlocale/__posix_l_fallback.h>
15#include <__support/xlocale/__strtonum_fallback.h>
16#endif // __NuttX__
17
18#endif
lib/libcxx/include/__support/openbsd/xlocale.h+20
......@@ -16,4 +16,24 @@
1616#include <ctype.h>
1717#include <cwctype>
1818
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23
24inline _LIBCPP_HIDE_FROM_ABI long
25strtol_l(const char *nptr, char **endptr, int base, locale_t) {
26 return ::strtol(nptr, endptr, base);
27}
28
29inline _LIBCPP_HIDE_FROM_ABI unsigned long
30strtoul_l(const char *nptr, char **endptr, int base, locale_t) {
31 return ::strtoul(nptr, endptr, base);
32}
33
34
35#ifdef __cplusplus
36}
37#endif
38
1939#endif
lib/libcxx/include/__support/win32/limits_msvc_win32.h+1-1
......@@ -14,7 +14,7 @@
1414#error "This header complements the Microsoft C Runtime library, and should not be included otherwise."
1515#endif
1616#if defined(__clang__)
17#error "This header should only be included when using Microsofts C1XX frontend"
17#error "This header should only be included when using Microsoft's C1XX frontend"
1818#endif
1919
2020#include <float.h> // limit constants
lib/libcxx/include/__thread/poll_with_backoff.h created+69
......@@ -0,0 +1,69 @@
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___THREAD_POLL_WITH_BACKOFF_H
10#define _LIBCPP___THREAD_POLL_WITH_BACKOFF_H
11
12#include <__availability>
13#include <__config>
14#include <chrono>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
18#endif
19
20_LIBCPP_BEGIN_NAMESPACE_STD
21
22static _LIBCPP_CONSTEXPR const int __libcpp_polling_count = 64;
23
24// Polls a thread for a condition given by a predicate, and backs off based on a backoff policy
25// before polling again.
26//
27// - __f is the "test function" that should return true if polling succeeded, and false if it failed.
28//
29// - __bf is the "backoff policy", which is called with the duration since we started polling. It should
30// return false in order to resume polling, and true if polling should stop entirely for some reason.
31// In general, backoff policies sleep for some time before returning control to the polling loop.
32//
33// - __max_elapsed is the maximum duration to try polling for. If the maximum duration is exceeded,
34// the polling loop will return false to report a timeout.
35template<class _Fn, class _BFn>
36_LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI
37bool __libcpp_thread_poll_with_backoff(_Fn&& __f, _BFn&& __bf, chrono::nanoseconds __max_elapsed = chrono::nanoseconds::zero()) {
38 auto const __start = chrono::high_resolution_clock::now();
39 for (int __count = 0;;) {
40 if (__f())
41 return true; // _Fn completion means success
42 if (__count < __libcpp_polling_count) {
43 __count += 1;
44 continue;
45 }
46 chrono::nanoseconds const __elapsed = chrono::high_resolution_clock::now() - __start;
47 if (__max_elapsed != chrono::nanoseconds::zero() && __max_elapsed < __elapsed)
48 return false; // timeout failure
49 if (__bf(__elapsed))
50 return false; // _BFn completion means failure
51 }
52}
53
54// A trivial backoff policy that always immediately returns the control to
55// the polling loop.
56//
57// This is not very well-behaved since it will cause the polling loop to spin,
58// so this should most likely only be used on single-threaded systems where there
59// are no other threads to compete with.
60struct __spinning_backoff_policy {
61 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
62 bool operator()(chrono::nanoseconds const&) const {
63 return false;
64 }
65};
66
67_LIBCPP_END_NAMESPACE_STD
68
69#endif // _LIBCPP___THREAD_POLL_WITH_BACKOFF_H
lib/libcxx/include/__thread/timed_backoff_policy.h created+45
......@@ -0,0 +1,45 @@
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___THREAD_TIMED_BACKOFF_POLICY_H
10#define _LIBCPP___THREAD_TIMED_BACKOFF_POLICY_H
11
12#include <__config>
13
14#ifndef _LIBCPP_HAS_NO_THREADS
15
16#include <__threading_support>
17#include <chrono>
18
19#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20#pragma GCC system_header
21#endif
22
23_LIBCPP_BEGIN_NAMESPACE_STD
24
25struct __libcpp_timed_backoff_policy {
26 _LIBCPP_INLINE_VISIBILITY
27 bool operator()(chrono::nanoseconds __elapsed) const
28 {
29 if(__elapsed > chrono::milliseconds(128))
30 __libcpp_thread_sleep_for(chrono::milliseconds(8));
31 else if(__elapsed > chrono::microseconds(64))
32 __libcpp_thread_sleep_for(__elapsed / 2);
33 else if(__elapsed > chrono::microseconds(4))
34 __libcpp_thread_yield();
35 else
36 {} // poll
37 return false;
38 }
39};
40
41_LIBCPP_END_NAMESPACE_STD
42
43#endif // _LIBCPP_HAS_NO_THREADS
44
45#endif // _LIBCPP___THREAD_TIMED_BACKOFF_POLICY_H
lib/libcxx/include/__threading_support+5-146
......@@ -12,6 +12,7 @@
1212
1313#include <__availability>
1414#include <__config>
15#include <__thread/poll_with_backoff.h>
1516#include <chrono>
1617#include <errno.h>
1718#include <iosfwd>
......@@ -29,16 +30,9 @@
2930# include <__external_threading>
3031#elif !defined(_LIBCPP_HAS_NO_THREADS)
3132
32#if defined(__APPLE__) || defined(__MVS__)
33# define _LIBCPP_NO_NATIVE_SEMAPHORES
34#endif
35
3633#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
3734# include <pthread.h>
3835# include <sched.h>
39# ifndef _LIBCPP_NO_NATIVE_SEMAPHORES
40# include <semaphore.h>
41# endif
4236#elif defined(_LIBCPP_HAS_THREAD_API_C11)
4337# include <threads.h>
4438#endif
......@@ -60,9 +54,6 @@
6054typedef ::timespec __libcpp_timespec_t;
6155#endif // !defined(_LIBCPP_HAS_NO_THREADS)
6256
63_LIBCPP_PUSH_MACROS
64#include <__undef_macros>
65
6657_LIBCPP_BEGIN_NAMESPACE_STD
6758
6859#if !defined(_LIBCPP_HAS_NO_THREADS)
......@@ -78,12 +69,6 @@ typedef pthread_mutex_t __libcpp_recursive_mutex_t;
7869typedef pthread_cond_t __libcpp_condvar_t;
7970#define _LIBCPP_CONDVAR_INITIALIZER PTHREAD_COND_INITIALIZER
8071
81#ifndef _LIBCPP_NO_NATIVE_SEMAPHORES
82// Semaphore
83typedef sem_t __libcpp_semaphore_t;
84# define _LIBCPP_SEMAPHORE_MAX SEM_VALUE_MAX
85#endif
86
8772// Execute once
8873typedef pthread_once_t __libcpp_exec_once_flag;
8974#define _LIBCPP_EXEC_ONCE_INITIALIZER PTHREAD_ONCE_INIT
......@@ -149,12 +134,6 @@ typedef void* __libcpp_recursive_mutex_t[5];
149134typedef void* __libcpp_condvar_t;
150135#define _LIBCPP_CONDVAR_INITIALIZER 0
151136
152// Semaphore
153typedef void* __libcpp_semaphore_t;
154#if defined(_LIBCPP_HAS_THREAD_API_WIN32)
155# define _LIBCPP_SEMAPHORE_MAX (::std::numeric_limits<long>::max())
156#endif
157
158137// Execute Once
159138typedef void* __libcpp_exec_once_flag;
160139#define _LIBCPP_EXEC_ONCE_INITIALIZER 0
......@@ -219,26 +198,6 @@ int __libcpp_condvar_timedwait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m,
219198_LIBCPP_THREAD_ABI_VISIBILITY
220199int __libcpp_condvar_destroy(__libcpp_condvar_t* __cv);
221200
222#ifndef _LIBCPP_NO_NATIVE_SEMAPHORES
223
224// Semaphore
225_LIBCPP_THREAD_ABI_VISIBILITY
226bool __libcpp_semaphore_init(__libcpp_semaphore_t* __sem, int __init);
227
228_LIBCPP_THREAD_ABI_VISIBILITY
229bool __libcpp_semaphore_destroy(__libcpp_semaphore_t* __sem);
230
231_LIBCPP_THREAD_ABI_VISIBILITY
232bool __libcpp_semaphore_post(__libcpp_semaphore_t* __sem);
233
234_LIBCPP_THREAD_ABI_VISIBILITY
235bool __libcpp_semaphore_wait(__libcpp_semaphore_t* __sem);
236
237_LIBCPP_THREAD_ABI_VISIBILITY
238bool __libcpp_semaphore_wait_timed(__libcpp_semaphore_t* __sem, chrono::nanoseconds const& __ns);
239
240#endif // _LIBCPP_NO_NATIVE_SEMAPHORES
241
242201// Execute once
243202_LIBCPP_THREAD_ABI_VISIBILITY
244203int __libcpp_execute_once(__libcpp_exec_once_flag *flag,
......@@ -290,75 +249,9 @@ int __libcpp_tls_set(__libcpp_tls_key __key, void *__p);
290249
291250#endif // !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
292251
293struct __libcpp_timed_backoff_policy {
294 _LIBCPP_INLINE_VISIBILITY
295 bool operator()(chrono::nanoseconds __elapsed) const
296 {
297 if(__elapsed > chrono::milliseconds(128))
298 __libcpp_thread_sleep_for(chrono::milliseconds(8));
299 else if(__elapsed > chrono::microseconds(64))
300 __libcpp_thread_sleep_for(__elapsed / 2);
301 else if(__elapsed > chrono::microseconds(4))
302 __libcpp_thread_yield();
303 else
304 {} // poll
305 return false;
306 }
307};
308
309static _LIBCPP_CONSTEXPR const int __libcpp_polling_count = 64;
310
311template<class _Fn, class _BFn>
312_LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
313bool __libcpp_thread_poll_with_backoff(
314 _Fn && __f, _BFn && __bf, chrono::nanoseconds __max_elapsed = chrono::nanoseconds::zero())
315{
316 auto const __start = chrono::high_resolution_clock::now();
317 for(int __count = 0;;) {
318 if(__f())
319 return true; // _Fn completion means success
320 if(__count < __libcpp_polling_count) {
321 __count += 1;
322 continue;
323 }
324 chrono::nanoseconds const __elapsed = chrono::high_resolution_clock::now() - __start;
325 if(__max_elapsed != chrono::nanoseconds::zero() && __max_elapsed < __elapsed)
326 return false; // timeout failure
327 if(__bf(__elapsed))
328 return false; // _BFn completion means failure
329 }
330}
331
332252#if (!defined(_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL) || \
333253 defined(_LIBCPP_BUILDING_THREAD_LIBRARY_EXTERNAL))
334254
335
336namespace __thread_detail {
337
338inline __libcpp_timespec_t __convert_to_timespec(const chrono::nanoseconds& __ns)
339{
340 using namespace chrono;
341 seconds __s = duration_cast<seconds>(__ns);
342 __libcpp_timespec_t __ts;
343 typedef decltype(__ts.tv_sec) __ts_sec;
344 const __ts_sec __ts_sec_max = numeric_limits<__ts_sec>::max();
345
346 if (__s.count() < __ts_sec_max)
347 {
348 __ts.tv_sec = static_cast<__ts_sec>(__s.count());
349 __ts.tv_nsec = static_cast<decltype(__ts.tv_nsec)>((__ns - __s).count());
350 }
351 else
352 {
353 __ts.tv_sec = __ts_sec_max;
354 __ts.tv_nsec = 999999999; // (10^9 - 1)
355 }
356
357 return __ts;
358}
359
360}
361
362255#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
363256
364257int __libcpp_recursive_mutex_init(__libcpp_recursive_mutex_t *__m)
......@@ -452,38 +345,6 @@ int __libcpp_condvar_destroy(__libcpp_condvar_t *__cv)
452345 return pthread_cond_destroy(__cv);
453346}
454347
455#ifndef _LIBCPP_NO_NATIVE_SEMAPHORES
456
457// Semaphore
458bool __libcpp_semaphore_init(__libcpp_semaphore_t* __sem, int __init)
459{
460 return sem_init(__sem, 0, __init) == 0;
461}
462
463bool __libcpp_semaphore_destroy(__libcpp_semaphore_t* __sem)
464{
465 return sem_destroy(__sem) == 0;
466}
467
468bool __libcpp_semaphore_post(__libcpp_semaphore_t* __sem)
469{
470 return sem_post(__sem) == 0;
471}
472
473bool __libcpp_semaphore_wait(__libcpp_semaphore_t* __sem)
474{
475 return sem_wait(__sem) == 0;
476}
477
478bool __libcpp_semaphore_wait_timed(__libcpp_semaphore_t* __sem, chrono::nanoseconds const& __ns)
479{
480 auto const __abs_time = chrono::system_clock::now().time_since_epoch() + __ns;
481 __libcpp_timespec_t __ts = __thread_detail::__convert_to_timespec(__abs_time);
482 return sem_timedwait(__sem, &__ts) == 0;
483}
484
485#endif //_LIBCPP_NO_NATIVE_SEMAPHORES
486
487348// Execute once
488349int __libcpp_execute_once(__libcpp_exec_once_flag *flag,
489350 void (*init_routine)()) {
......@@ -546,7 +407,7 @@ void __libcpp_thread_yield()
546407
547408void __libcpp_thread_sleep_for(const chrono::nanoseconds& __ns)
548409{
549 __libcpp_timespec_t __ts = __thread_detail::__convert_to_timespec(__ns);
410 __libcpp_timespec_t __ts = _VSTD::__convert_to_timespec<__libcpp_timespec_t>(__ns);
550411 while (nanosleep(&__ts, &__ts) == -1 && errno == EINTR);
551412}
552413
......@@ -703,7 +564,7 @@ void __libcpp_thread_yield()
703564
704565void __libcpp_thread_sleep_for(const chrono::nanoseconds& __ns)
705566{
706 __libcpp_timespec_t __ts = __thread_detail::__convert_to_timespec(__ns);
567 __libcpp_timespec_t __ts = _VSTD::__convert_to_timespec<__libcpp_timespec_t>(__ns);
707568 thrd_sleep(&__ts, nullptr);
708569}
709570
......@@ -736,7 +597,7 @@ namespace this_thread
736597
737598_LIBCPP_INLINE_VISIBILITY __thread_id get_id() _NOEXCEPT;
738599
739} // this_thread
600} // namespace this_thread
740601
741602template<> struct hash<__thread_id>;
742603
......@@ -806,12 +667,10 @@ get_id() _NOEXCEPT
806667 return __libcpp_thread_get_current_id();
807668}
808669
809} // this_thread
670} // namespace this_thread
810671
811672#endif // !_LIBCPP_HAS_NO_THREADS
812673
813674_LIBCPP_END_NAMESPACE_STD
814675
815_LIBCPP_POP_MACROS
816
817676#endif // _LIBCPP_THREADING_SUPPORT
lib/libcxx/include/__tree+7-7
......@@ -738,9 +738,9 @@ public:
738738 }
739739
740740private:
741 ~__tree_node_base() _LIBCPP_EQUAL_DELETE;
742 __tree_node_base(__tree_node_base const&) _LIBCPP_EQUAL_DELETE;
743 __tree_node_base& operator=(__tree_node_base const&) _LIBCPP_EQUAL_DELETE;
741 ~__tree_node_base() = delete;
742 __tree_node_base(__tree_node_base const&) = delete;
743 __tree_node_base& operator=(__tree_node_base const&) = delete;
744744};
745745
746746template <class _Tp, class _VoidPtr>
......@@ -753,9 +753,9 @@ public:
753753 __node_value_type __value_;
754754
755755private:
756 ~__tree_node() _LIBCPP_EQUAL_DELETE;
757 __tree_node(__tree_node const&) _LIBCPP_EQUAL_DELETE;
758 __tree_node& operator=(__tree_node const&) _LIBCPP_EQUAL_DELETE;
756 ~__tree_node() = delete;
757 __tree_node(__tree_node const&) = delete;
758 __tree_node& operator=(__tree_node const&) = delete;
759759};
760760
761761
......@@ -1612,7 +1612,7 @@ template <class _Tp, class _Compare, class _Allocator>
16121612__tree<_Tp, _Compare, _Allocator>&
16131613__tree<_Tp, _Compare, _Allocator>::operator=(const __tree& __t)
16141614{
1615 if (this != &__t)
1615 if (this != _VSTD::addressof(__t))
16161616 {
16171617 value_comp() = __t.value_comp();
16181618 __copy_assign_alloc(__t);
lib/libcxx/include/__tuple+22-22
......@@ -58,19 +58,19 @@ template <size_t _Ip, class _Tp> struct _LIBCPP_TEMPLATE_VIS tuple_element;
5858template <size_t _Ip, class _Tp>
5959struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, const _Tp>
6060{
61 typedef _LIBCPP_NODEBUG_TYPE typename add_const<typename tuple_element<_Ip, _Tp>::type>::type type;
61 typedef _LIBCPP_NODEBUG typename add_const<typename tuple_element<_Ip, _Tp>::type>::type type;
6262};
6363
6464template <size_t _Ip, class _Tp>
6565struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, volatile _Tp>
6666{
67 typedef _LIBCPP_NODEBUG_TYPE typename add_volatile<typename tuple_element<_Ip, _Tp>::type>::type type;
67 typedef _LIBCPP_NODEBUG typename add_volatile<typename tuple_element<_Ip, _Tp>::type>::type type;
6868};
6969
7070template <size_t _Ip, class _Tp>
7171struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, const volatile _Tp>
7272{
73 typedef _LIBCPP_NODEBUG_TYPE typename add_cv<typename tuple_element<_Ip, _Tp>::type>::type type;
73 typedef _LIBCPP_NODEBUG typename add_cv<typename tuple_element<_Ip, _Tp>::type>::type type;
7474};
7575
7676template <class _Tp> struct __tuple_like : false_type {};
......@@ -99,7 +99,7 @@ namespace __detail {
9999
100100template<typename _Tp, size_t ..._Extra> struct __repeat;
101101template<typename _Tp, _Tp ..._Np, size_t ..._Extra> struct __repeat<__integer_sequence<_Tp, _Np...>, _Extra...> {
102 typedef _LIBCPP_NODEBUG_TYPE __integer_sequence<_Tp,
102 typedef _LIBCPP_NODEBUG __integer_sequence<_Tp,
103103 _Np...,
104104 sizeof...(_Np) + _Np...,
105105 2 * sizeof...(_Np) + _Np...,
......@@ -253,7 +253,7 @@ template <class ..._Tp> struct __tuple_types {};
253253namespace __indexer_detail {
254254
255255template <size_t _Idx, class _Tp>
256struct __indexed { using type _LIBCPP_NODEBUG_TYPE = _Tp; };
256struct __indexed { using type _LIBCPP_NODEBUG = _Tp; };
257257
258258template <class _Types, class _Indexes> struct __indexer;
259259
......@@ -268,7 +268,7 @@ __indexed<_Idx, _Tp> __at_index(__indexed<_Idx, _Tp> const&);
268268} // namespace __indexer_detail
269269
270270template <size_t _Idx, class ..._Types>
271using __type_pack_element _LIBCPP_NODEBUG_TYPE = typename decltype(
271using __type_pack_element _LIBCPP_NODEBUG = typename decltype(
272272 __indexer_detail::__at_index<_Idx>(
273273 __indexer_detail::__indexer<
274274 __tuple_types<_Types...>,
......@@ -281,7 +281,7 @@ template <size_t _Ip, class ..._Types>
281281struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, __tuple_types<_Types...>>
282282{
283283 static_assert(_Ip < sizeof...(_Types), "tuple_element index out of range");
284 typedef _LIBCPP_NODEBUG_TYPE __type_pack_element<_Ip, _Types...> type;
284 typedef _LIBCPP_NODEBUG __type_pack_element<_Ip, _Types...> type;
285285};
286286
287287
......@@ -301,34 +301,34 @@ struct __apply_cv_mf<false, false, false> {
301301};
302302template <>
303303struct __apply_cv_mf<false, true, false> {
304 template <class _Tp> using __apply _LIBCPP_NODEBUG_TYPE = const _Tp;
304 template <class _Tp> using __apply _LIBCPP_NODEBUG = const _Tp;
305305};
306306template <>
307307struct __apply_cv_mf<false, false, true> {
308 template <class _Tp> using __apply _LIBCPP_NODEBUG_TYPE = volatile _Tp;
308 template <class _Tp> using __apply _LIBCPP_NODEBUG = volatile _Tp;
309309};
310310template <>
311311struct __apply_cv_mf<false, true, true> {
312 template <class _Tp> using __apply _LIBCPP_NODEBUG_TYPE = const volatile _Tp;
312 template <class _Tp> using __apply _LIBCPP_NODEBUG = const volatile _Tp;
313313};
314314template <>
315315struct __apply_cv_mf<true, false, false> {
316 template <class _Tp> using __apply _LIBCPP_NODEBUG_TYPE = _Tp&;
316 template <class _Tp> using __apply _LIBCPP_NODEBUG = _Tp&;
317317};
318318template <>
319319struct __apply_cv_mf<true, true, false> {
320 template <class _Tp> using __apply _LIBCPP_NODEBUG_TYPE = const _Tp&;
320 template <class _Tp> using __apply _LIBCPP_NODEBUG = const _Tp&;
321321};
322322template <>
323323struct __apply_cv_mf<true, false, true> {
324 template <class _Tp> using __apply _LIBCPP_NODEBUG_TYPE = volatile _Tp&;
324 template <class _Tp> using __apply _LIBCPP_NODEBUG = volatile _Tp&;
325325};
326326template <>
327327struct __apply_cv_mf<true, true, true> {
328 template <class _Tp> using __apply _LIBCPP_NODEBUG_TYPE = const volatile _Tp&;
328 template <class _Tp> using __apply _LIBCPP_NODEBUG = const volatile _Tp&;
329329};
330330template <class _Tp, class _RawTp = typename remove_reference<_Tp>::type>
331using __apply_cv_t _LIBCPP_NODEBUG_TYPE = __apply_cv_mf<
331using __apply_cv_t _LIBCPP_NODEBUG = __apply_cv_mf<
332332 is_lvalue_reference<_Tp>::value,
333333 is_const<_RawTp>::value,
334334 is_volatile<_RawTp>::value>;
......@@ -347,7 +347,7 @@ template <template <class...> class _Tuple, class ..._Types, size_t ..._Idx>
347347struct __make_tuple_types_flat<_Tuple<_Types...>, __tuple_indices<_Idx...>> {
348348 // Specialization for pair, tuple, and __tuple_types
349349 template <class _Tp, class _ApplyFn = __apply_cv_t<_Tp>>
350 using __apply_quals _LIBCPP_NODEBUG_TYPE = __tuple_types<
350 using __apply_quals _LIBCPP_NODEBUG = __tuple_types<
351351 typename _ApplyFn::template __apply<__type_pack_element<_Idx, _Types...>>...
352352 >;
353353};
......@@ -375,19 +375,19 @@ struct __make_tuple_types
375375
376376template <class ..._Types, size_t _Ep>
377377struct __make_tuple_types<tuple<_Types...>, _Ep, 0, true> {
378 typedef _LIBCPP_NODEBUG_TYPE __tuple_types<_Types...> type;
378 typedef _LIBCPP_NODEBUG __tuple_types<_Types...> type;
379379};
380380
381381template <class ..._Types, size_t _Ep>
382382struct __make_tuple_types<__tuple_types<_Types...>, _Ep, 0, true> {
383 typedef _LIBCPP_NODEBUG_TYPE __tuple_types<_Types...> type;
383 typedef _LIBCPP_NODEBUG __tuple_types<_Types...> type;
384384};
385385
386386template <bool ..._Preds>
387387struct __all_dummy;
388388
389389template <bool ..._Pred>
390using __all = _IsSame<__all_dummy<_Pred...>, __all_dummy<((void)_Pred, true)...>>;
390struct __all : _IsSame<__all_dummy<_Pred...>, __all_dummy<((void)_Pred, true)...>> {};
391391
392392struct __tuple_sfinae_base {
393393 template <template <class, class...> class _Trait,
......@@ -454,12 +454,12 @@ struct __tuple_assignable<_Tp, _Up, true, true>
454454template <size_t _Ip, class ..._Tp>
455455struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, tuple<_Tp...> >
456456{
457 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, __tuple_types<_Tp...> >::type type;
457 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, __tuple_types<_Tp...> >::type type;
458458};
459459
460460#if _LIBCPP_STD_VER > 11
461461template <size_t _Ip, class ..._Tp>
462using tuple_element_t _LIBCPP_NODEBUG_TYPE = typename tuple_element <_Ip, _Tp...>::type;
462using tuple_element_t _LIBCPP_NODEBUG = typename tuple_element <_Ip, _Tp...>::type;
463463#endif
464464
465465template <bool _IsTuple, class _SizeTrait, size_t _Expected>
......@@ -471,7 +471,7 @@ struct __tuple_like_with_size_imp<true, _SizeTrait, _Expected>
471471
472472template <class _Tuple, size_t _ExpectedSize,
473473 class _RawTuple = typename __uncvref<_Tuple>::type>
474using __tuple_like_with_size _LIBCPP_NODEBUG_TYPE = __tuple_like_with_size_imp<
474using __tuple_like_with_size _LIBCPP_NODEBUG = __tuple_like_with_size_imp<
475475 __tuple_like<_RawTuple>::value,
476476 tuple_size<_RawTuple>, _ExpectedSize
477477 >;
lib/libcxx/include/__undef_macros+1-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===------------------------ __undef_macros ------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/__utility/__decay_copy.h deleted-39
......@@ -1,39 +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___TYPE_TRAITS_DECAY_COPY_H
11#define _LIBCPP___TYPE_TRAITS_DECAY_COPY_H
12
13#include <__config>
14#include <__utility/forward.h>
15#include <type_traits>
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
26template <class _Tp>
27inline _LIBCPP_INLINE_VISIBILITY typename decay<_Tp>::type __decay_copy(_Tp&& __t)
28#if _LIBCPP_STD_VER > 17
29 noexcept(is_nothrow_convertible_v<_Tp, remove_reference_t<_Tp> >)
30#endif
31{
32 return _VSTD::forward<_Tp>(__t);
33}
34
35_LIBCPP_END_NAMESPACE_STD
36
37_LIBCPP_POP_MACROS
38
39#endif // _LIBCPP___TYPE_TRAITS_DECAY_COPY_H
lib/libcxx/include/__utility/as_const.h-5
......@@ -18,9 +18,6 @@
1818#pragma GCC system_header
1919#endif
2020
21_LIBCPP_PUSH_MACROS
22#include <__undef_macros>
23
2421_LIBCPP_BEGIN_NAMESPACE_STD
2522
2623#if _LIBCPP_STD_VER > 14
......@@ -33,6 +30,4 @@ void as_const(const _Tp&&) = delete;
3330
3431_LIBCPP_END_NAMESPACE_STD
3532
36_LIBCPP_POP_MACROS
37
3833#endif // _LIBCPP___UTILITY_AS_CONST_H
lib/libcxx/include/__utility/auto_cast.h created+22
......@@ -0,0 +1,22 @@
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___UTILITY_AUTO_CAST_H
11#define _LIBCPP___UTILITY_AUTO_CAST_H
12
13#include <__config>
14#include <type_traits>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
18#endif
19
20#define _LIBCPP_AUTO_CAST(expr) static_cast<typename decay<decltype((expr))>::type>(expr)
21
22#endif // _LIBCPP___UTILITY_AUTO_CAST_H
lib/libcxx/include/__utility/cmp.h+8-5
......@@ -24,20 +24,23 @@ _LIBCPP_PUSH_MACROS
2424
2525_LIBCPP_BEGIN_NAMESPACE_STD
2626
27#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CONCEPTS)
27#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
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
3434#ifndef _LIBCPP_HAS_NO_CHAR8_T
35 char8_t,
35 , char8_t
3636#endif
3737#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
38 char16_t, char32_t,
38 , char16_t, char32_t
3939#endif
40 wchar_t>::value;
40#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
41 , wchar_t
42#endif
43 >::value;
4144
4245template<__is_safe_integral_cmp _Tp, __is_safe_integral_cmp _Up>
4346_LIBCPP_INLINE_VISIBILITY constexpr
lib/libcxx/include/__utility/declval.h-5
......@@ -15,9 +15,6 @@
1515#pragma GCC system_header
1616#endif
1717
18_LIBCPP_PUSH_MACROS
19#include <__undef_macros>
20
2118_LIBCPP_BEGIN_NAMESPACE_STD
2219
2320// Suppress deprecation notice for volatile-qualified return type resulting
......@@ -34,6 +31,4 @@ decltype(__declval<_Tp>(0)) declval() _NOEXCEPT;
3431
3532_LIBCPP_END_NAMESPACE_STD
3633
37_LIBCPP_POP_MACROS
38
3934#endif // _LIBCPP___UTILITY_DECLVAL_H
lib/libcxx/include/__utility/exchange.h+3-6
......@@ -12,20 +12,19 @@
1212#include <__config>
1313#include <__utility/forward.h>
1414#include <__utility/move.h>
15#include <type_traits>
1516
1617#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1718#pragma GCC system_header
1819#endif
1920
20_LIBCPP_PUSH_MACROS
21#include <__undef_macros>
22
2321_LIBCPP_BEGIN_NAMESPACE_STD
2422
2523#if _LIBCPP_STD_VER > 11
2624template<class _T1, class _T2 = _T1>
2725inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
28_T1 exchange(_T1& __obj, _T2 && __new_value)
26_T1 exchange(_T1& __obj, _T2&& __new_value)
27 noexcept(is_nothrow_move_constructible<_T1>::value && is_nothrow_assignable<_T1&, _T2>::value)
2928{
3029 _T1 __old_value = _VSTD::move(__obj);
3130 __obj = _VSTD::forward<_T2>(__new_value);
......@@ -35,6 +34,4 @@ _T1 exchange(_T1& __obj, _T2 && __new_value)
3534
3635_LIBCPP_END_NAMESPACE_STD
3736
38_LIBCPP_POP_MACROS
39
4037#endif // _LIBCPP___UTILITY_EXCHANGE_H
lib/libcxx/include/__utility/forward.h-5
......@@ -17,9 +17,6 @@
1717#pragma GCC system_header
1818#endif
1919
20_LIBCPP_PUSH_MACROS
21#include <__undef_macros>
22
2320_LIBCPP_BEGIN_NAMESPACE_STD
2421
2522template <class _Tp>
......@@ -37,6 +34,4 @@ forward(typename remove_reference<_Tp>::type&& __t) _NOEXCEPT {
3734
3835_LIBCPP_END_NAMESPACE_STD
3936
40_LIBCPP_POP_MACROS
41
4237#endif // _LIBCPP___UTILITY_FORWARD_H
lib/libcxx/include/__utility/in_place.h+3-8
......@@ -16,9 +16,6 @@
1616#pragma GCC system_header
1717#endif
1818
19_LIBCPP_PUSH_MACROS
20#include <__undef_macros>
21
2219_LIBCPP_BEGIN_NAMESPACE_STD
2320
2421#if _LIBCPP_STD_VER > 14
......@@ -26,21 +23,21 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2623struct _LIBCPP_TYPE_VIS in_place_t {
2724 explicit in_place_t() = default;
2825};
29_LIBCPP_INLINE_VAR constexpr in_place_t in_place{};
26inline constexpr in_place_t in_place{};
3027
3128template <class _Tp>
3229struct _LIBCPP_TEMPLATE_VIS in_place_type_t {
3330 explicit in_place_type_t() = default;
3431};
3532template <class _Tp>
36_LIBCPP_INLINE_VAR constexpr in_place_type_t<_Tp> in_place_type{};
33inline constexpr in_place_type_t<_Tp> in_place_type{};
3734
3835template <size_t _Idx>
3936struct _LIBCPP_TEMPLATE_VIS in_place_index_t {
4037 explicit in_place_index_t() = default;
4138};
4239template <size_t _Idx>
43_LIBCPP_INLINE_VAR constexpr in_place_index_t<_Idx> in_place_index{};
40inline constexpr in_place_index_t<_Idx> in_place_index{};
4441
4542template <class _Tp> struct __is_inplace_type_imp : false_type {};
4643template <class _Tp> struct __is_inplace_type_imp<in_place_type_t<_Tp>> : true_type {};
......@@ -58,6 +55,4 @@ using __is_inplace_index = __is_inplace_index_imp<__uncvref_t<_Tp>>;
5855
5956_LIBCPP_END_NAMESPACE_STD
6057
61_LIBCPP_POP_MACROS
62
6358#endif // _LIBCPP___UTILITY_IN_PLACE_H
lib/libcxx/include/__utility/integer_sequence.h+4-9
......@@ -16,9 +16,6 @@
1616#pragma GCC system_header
1717#endif
1818
19_LIBCPP_PUSH_MACROS
20#include <__undef_macros>
21
2219_LIBCPP_BEGIN_NAMESPACE_STD
2320
2421#if _LIBCPP_STD_VER > 11
......@@ -42,11 +39,11 @@ template<size_t... _Ip>
4239#if __has_builtin(__make_integer_seq) && !defined(_LIBCPP_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE)
4340
4441template <class _Tp, _Tp _Ep>
45using __make_integer_sequence _LIBCPP_NODEBUG_TYPE = __make_integer_seq<integer_sequence, _Tp, _Ep>;
42using __make_integer_sequence _LIBCPP_NODEBUG = __make_integer_seq<integer_sequence, _Tp, _Ep>;
4643
4744#else
4845
49template<typename _Tp, _Tp _Np> using __make_integer_sequence_unchecked _LIBCPP_NODEBUG_TYPE =
46template<typename _Tp, _Tp _Np> using __make_integer_sequence_unchecked _LIBCPP_NODEBUG =
5047 typename __detail::__make<_Np>::type::template __convert<integer_sequence, _Tp>;
5148
5249template <class _Tp, _Tp _Ep>
......@@ -57,11 +54,11 @@ struct __make_integer_sequence_checked
5754 static_assert(0 <= _Ep, "std::make_integer_sequence must have a non-negative sequence length");
5855 // Workaround GCC bug by preventing bad installations when 0 <= _Ep
5956 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68929
60 typedef _LIBCPP_NODEBUG_TYPE __make_integer_sequence_unchecked<_Tp, 0 <= _Ep ? _Ep : 0> type;
57 typedef _LIBCPP_NODEBUG __make_integer_sequence_unchecked<_Tp, 0 <= _Ep ? _Ep : 0> type;
6158};
6259
6360template <class _Tp, _Tp _Ep>
64using __make_integer_sequence _LIBCPP_NODEBUG_TYPE = typename __make_integer_sequence_checked<_Tp, _Ep>::type;
61using __make_integer_sequence _LIBCPP_NODEBUG = typename __make_integer_sequence_checked<_Tp, _Ep>::type;
6562
6663#endif
6764
......@@ -78,6 +75,4 @@ template<class... _Tp>
7875
7976_LIBCPP_END_NAMESPACE_STD
8077
81_LIBCPP_POP_MACROS
82
8378#endif // _LIBCPP___UTILITY_INTEGER_SEQUENCE_H
lib/libcxx/include/__utility/move.h+1-6
......@@ -17,15 +17,12 @@
1717#pragma GCC system_header
1818#endif
1919
20_LIBCPP_PUSH_MACROS
21#include <__undef_macros>
22
2320_LIBCPP_BEGIN_NAMESPACE_STD
2421
2522template <class _Tp>
2623_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename remove_reference<_Tp>::type&&
2724move(_Tp&& __t) _NOEXCEPT {
28 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tp>::type _Up;
25 typedef _LIBCPP_NODEBUG typename remove_reference<_Tp>::type _Up;
2926 return static_cast<_Up&&>(__t);
3027}
3128
......@@ -47,6 +44,4 @@ move_if_noexcept(_Tp& __x) _NOEXCEPT {
4744
4845_LIBCPP_END_NAMESPACE_STD
4946
50_LIBCPP_POP_MACROS
51
5247#endif // _LIBCPP___UTILITY_MOVE_H
lib/libcxx/include/__utility/pair.h+67-43
......@@ -9,6 +9,8 @@
99#ifndef _LIBCPP___UTILITY_PAIR_H
1010#define _LIBCPP___UTILITY_PAIR_H
1111
12#include <__compare/common_comparison_category.h>
13#include <__compare/synth_three_way.h>
1214#include <__config>
1315#include <__functional/unwrap_ref.h>
1416#include <__tuple>
......@@ -22,12 +24,8 @@
2224#pragma GCC system_header
2325#endif
2426
25_LIBCPP_PUSH_MACROS
26#include <__undef_macros>
27
2827_LIBCPP_BEGIN_NAMESPACE_STD
2928
30
3129#if defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR)
3230template <class, class>
3331struct __non_trivially_copyable_base {
......@@ -75,9 +73,6 @@ struct _LIBCPP_TEMPLATE_VIS pair
7573 return *this;
7674 }
7775#else
78 template <bool _Val>
79 using _EnableB _LIBCPP_NODEBUG_TYPE = typename enable_if<_Val, bool>::type;
80
8176 struct _CheckArgs {
8277 template <int&...>
8378 static constexpr bool __enable_explicit_default() {
......@@ -110,7 +105,7 @@ struct _LIBCPP_TEMPLATE_VIS pair
110105 };
111106
112107 template <bool _MaybeEnable>
113 using _CheckArgsDep _LIBCPP_NODEBUG_TYPE = typename conditional<
108 using _CheckArgsDep _LIBCPP_NODEBUG = typename conditional<
114109 _MaybeEnable, _CheckArgs, __check_tuple_constructor_fail>::type;
115110
116111 struct _CheckTupleLikeConstructor {
......@@ -132,112 +127,122 @@ struct _LIBCPP_TEMPLATE_VIS pair
132127 };
133128
134129 template <class _Tuple>
135 using _CheckTLC _LIBCPP_NODEBUG_TYPE = typename conditional<
130 using _CheckTLC _LIBCPP_NODEBUG = typename conditional<
136131 __tuple_like_with_size<_Tuple, 2>::value
137132 && !is_same<typename decay<_Tuple>::type, pair>::value,
138133 _CheckTupleLikeConstructor,
139134 __check_tuple_constructor_fail
140135 >::type;
141136
142 template<bool _Dummy = true, _EnableB<
137 template<bool _Dummy = true, typename enable_if<
143138 _CheckArgsDep<_Dummy>::__enable_explicit_default()
144 > = false>
139 >::type* = nullptr>
145140 explicit _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
146141 pair() _NOEXCEPT_(is_nothrow_default_constructible<first_type>::value &&
147142 is_nothrow_default_constructible<second_type>::value)
148143 : first(), second() {}
149144
150 template<bool _Dummy = true, _EnableB<
145 template<bool _Dummy = true, typename enable_if<
151146 _CheckArgsDep<_Dummy>::__enable_implicit_default()
152 > = false>
147 >::type* = nullptr>
153148 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
154149 pair() _NOEXCEPT_(is_nothrow_default_constructible<first_type>::value &&
155150 is_nothrow_default_constructible<second_type>::value)
156151 : first(), second() {}
157152
158 template <bool _Dummy = true, _EnableB<
153 template <bool _Dummy = true, typename enable_if<
159154 _CheckArgsDep<_Dummy>::template __enable_explicit<_T1 const&, _T2 const&>()
160 > = false>
155 >::type* = nullptr>
161156 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
162157 explicit pair(_T1 const& __t1, _T2 const& __t2)
163158 _NOEXCEPT_(is_nothrow_copy_constructible<first_type>::value &&
164159 is_nothrow_copy_constructible<second_type>::value)
165160 : first(__t1), second(__t2) {}
166161
167 template<bool _Dummy = true, _EnableB<
162 template<bool _Dummy = true, typename enable_if<
168163 _CheckArgsDep<_Dummy>::template __enable_implicit<_T1 const&, _T2 const&>()
169 > = false>
164 >::type* = nullptr>
170165 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
171166 pair(_T1 const& __t1, _T2 const& __t2)
172167 _NOEXCEPT_(is_nothrow_copy_constructible<first_type>::value &&
173168 is_nothrow_copy_constructible<second_type>::value)
174169 : first(__t1), second(__t2) {}
175170
176 template<class _U1, class _U2, _EnableB<
177 _CheckArgs::template __enable_explicit<_U1, _U2>()
178 > = false>
171 template <
172#if _LIBCPP_STD_VER > 20 // http://wg21.link/P1951
173 class _U1 = _T1, class _U2 = _T2,
174#else
175 class _U1, class _U2,
176#endif
177 typename enable_if<_CheckArgs::template __enable_explicit<_U1, _U2>()>::type* = nullptr
178 >
179179 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
180180 explicit pair(_U1&& __u1, _U2&& __u2)
181181 _NOEXCEPT_((is_nothrow_constructible<first_type, _U1>::value &&
182182 is_nothrow_constructible<second_type, _U2>::value))
183183 : first(_VSTD::forward<_U1>(__u1)), second(_VSTD::forward<_U2>(__u2)) {}
184184
185 template<class _U1, class _U2, _EnableB<
186 _CheckArgs::template __enable_implicit<_U1, _U2>()
187 > = false>
185 template <
186#if _LIBCPP_STD_VER > 20 // http://wg21.link/P1951
187 class _U1 = _T1, class _U2 = _T2,
188#else
189 class _U1, class _U2,
190#endif
191 typename enable_if<_CheckArgs::template __enable_implicit<_U1, _U2>()>::type* = nullptr
192 >
188193 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
189194 pair(_U1&& __u1, _U2&& __u2)
190195 _NOEXCEPT_((is_nothrow_constructible<first_type, _U1>::value &&
191196 is_nothrow_constructible<second_type, _U2>::value))
192197 : first(_VSTD::forward<_U1>(__u1)), second(_VSTD::forward<_U2>(__u2)) {}
193198
194 template<class _U1, class _U2, _EnableB<
199 template<class _U1, class _U2, typename enable_if<
195200 _CheckArgs::template __enable_explicit<_U1 const&, _U2 const&>()
196 > = false>
201 >::type* = nullptr>
197202 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
198203 explicit pair(pair<_U1, _U2> const& __p)
199204 _NOEXCEPT_((is_nothrow_constructible<first_type, _U1 const&>::value &&
200205 is_nothrow_constructible<second_type, _U2 const&>::value))
201206 : first(__p.first), second(__p.second) {}
202207
203 template<class _U1, class _U2, _EnableB<
208 template<class _U1, class _U2, typename enable_if<
204209 _CheckArgs::template __enable_implicit<_U1 const&, _U2 const&>()
205 > = false>
210 >::type* = nullptr>
206211 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
207212 pair(pair<_U1, _U2> const& __p)
208213 _NOEXCEPT_((is_nothrow_constructible<first_type, _U1 const&>::value &&
209214 is_nothrow_constructible<second_type, _U2 const&>::value))
210215 : first(__p.first), second(__p.second) {}
211216
212 template<class _U1, class _U2, _EnableB<
217 template<class _U1, class _U2, typename enable_if<
213218 _CheckArgs::template __enable_explicit<_U1, _U2>()
214 > = false>
219 >::type* = nullptr>
215220 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
216221 explicit pair(pair<_U1, _U2>&&__p)
217222 _NOEXCEPT_((is_nothrow_constructible<first_type, _U1&&>::value &&
218223 is_nothrow_constructible<second_type, _U2&&>::value))
219224 : first(_VSTD::forward<_U1>(__p.first)), second(_VSTD::forward<_U2>(__p.second)) {}
220225
221 template<class _U1, class _U2, _EnableB<
226 template<class _U1, class _U2, typename enable_if<
222227 _CheckArgs::template __enable_implicit<_U1, _U2>()
223 > = false>
228 >::type* = nullptr>
224229 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
225230 pair(pair<_U1, _U2>&& __p)
226231 _NOEXCEPT_((is_nothrow_constructible<first_type, _U1&&>::value &&
227232 is_nothrow_constructible<second_type, _U2&&>::value))
228233 : first(_VSTD::forward<_U1>(__p.first)), second(_VSTD::forward<_U2>(__p.second)) {}
229234
230 template<class _Tuple, _EnableB<
235 template<class _Tuple, typename enable_if<
231236 _CheckTLC<_Tuple>::template __enable_explicit<_Tuple>()
232 > = false>
237 >::type* = nullptr>
233238 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
234239 explicit pair(_Tuple&& __p)
235240 : first(_VSTD::get<0>(_VSTD::forward<_Tuple>(__p))),
236241 second(_VSTD::get<1>(_VSTD::forward<_Tuple>(__p))) {}
237242
238 template<class _Tuple, _EnableB<
243 template<class _Tuple, typename enable_if<
239244 _CheckTLC<_Tuple>::template __enable_implicit<_Tuple>()
240 > = false>
245 >::type* = nullptr>
241246 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
242247 pair(_Tuple&& __p)
243248 : first(_VSTD::get<0>(_VSTD::forward<_Tuple>(__p))),
......@@ -279,9 +284,9 @@ struct _LIBCPP_TEMPLATE_VIS pair
279284 return *this;
280285 }
281286
282 template <class _Tuple, _EnableB<
287 template <class _Tuple, typename enable_if<
283288 _CheckTLC<_Tuple>::template __enable_assign<_Tuple>()
284 > = false>
289 >::type* = nullptr>
285290 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
286291 pair& operator=(_Tuple&& __p) {
287292 first = _VSTD::get<0>(_VSTD::forward<_Tuple>(__p));
......@@ -310,10 +315,12 @@ private:
310315#endif
311316};
312317
313#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
318#if _LIBCPP_STD_VER >= 17
314319template<class _T1, class _T2>
315320pair(_T1, _T2) -> pair<_T1, _T2>;
316#endif // _LIBCPP_HAS_NO_DEDUCTION_GUIDES
321#endif
322
323// [pairs.spec], specialized algorithms
317324
318325template <class _T1, class _T2>
319326inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
......@@ -323,6 +330,23 @@ operator==(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
323330 return __x.first == __y.first && __x.second == __y.second;
324331}
325332
333#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
334
335template <class _T1, class _T2>
336_LIBCPP_HIDE_FROM_ABI constexpr
337common_comparison_category_t<
338 __synth_three_way_result<_T1>,
339 __synth_three_way_result<_T2> >
340operator<=>(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
341{
342 if (auto __c = _VSTD::__synth_three_way(__x.first, __y.first); __c != 0) {
343 return __c;
344 }
345 return _VSTD::__synth_three_way(__x.second, __y.second);
346}
347
348#else // !defined(_LIBCPP_HAS_NO_CONCEPTS)
349
326350template <class _T1, class _T2>
327351inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
328352bool
......@@ -363,6 +387,8 @@ operator<=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
363387 return !(__y < __x);
364388}
365389
390#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
391
366392template <class _T1, class _T2>
367393inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
368394typename enable_if
......@@ -414,13 +440,13 @@ struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, pair<_T1, _T2> >
414440template <class _T1, class _T2>
415441struct _LIBCPP_TEMPLATE_VIS tuple_element<0, pair<_T1, _T2> >
416442{
417 typedef _LIBCPP_NODEBUG_TYPE _T1 type;
443 typedef _LIBCPP_NODEBUG _T1 type;
418444};
419445
420446template <class _T1, class _T2>
421447struct _LIBCPP_TEMPLATE_VIS tuple_element<1, pair<_T1, _T2> >
422448{
423 typedef _LIBCPP_NODEBUG_TYPE _T2 type;
449 typedef _LIBCPP_NODEBUG _T2 type;
424450};
425451
426452template <size_t _Ip> struct __get_pair;
......@@ -580,6 +606,4 @@ constexpr _T1 const && get(pair<_T2, _T1> const&& __p) _NOEXCEPT
580606
581607_LIBCPP_END_NAMESPACE_STD
582608
583_LIBCPP_POP_MACROS
584
585609#endif // _LIBCPP___UTILITY_PAIR_H
lib/libcxx/include/__utility/piecewise_construct.h+1-6
......@@ -15,20 +15,15 @@
1515#pragma GCC system_header
1616#endif
1717
18_LIBCPP_PUSH_MACROS
19#include <__undef_macros>
20
2118_LIBCPP_BEGIN_NAMESPACE_STD
2219
2320struct _LIBCPP_TEMPLATE_VIS piecewise_construct_t { explicit piecewise_construct_t() = default; };
2421#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
2522extern _LIBCPP_EXPORTED_FROM_ABI const piecewise_construct_t piecewise_construct;// = piecewise_construct_t();
2623#else
27/* _LIBCPP_INLINE_VAR */ constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
24/* inline */ constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
2825#endif
2926
3027_LIBCPP_END_NAMESPACE_STD
3128
32_LIBCPP_POP_MACROS
33
3429#endif // _LIBCPP___UTILITY_PIECEWISE_CONSTRUCT_H
lib/libcxx/include/__utility/priority_tag.h created+26
......@@ -0,0 +1,26 @@
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_PRIORITY_TAG_H
10#define _LIBCPP___UTILITY_PRIORITY_TAG_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<size_t _Ip> struct __priority_tag : __priority_tag<_Ip - 1> {};
22template<> struct __priority_tag<0> {};
23
24_LIBCPP_END_NAMESPACE_STD
25
26#endif // _LIBCPP___UTILITY_PRIORITY_TAG_H
lib/libcxx/include/__utility/rel_ops.h+1-6
......@@ -18,9 +18,6 @@
1818#pragma GCC system_header
1919#endif
2020
21_LIBCPP_PUSH_MACROS
22#include <__undef_macros>
23
2421_LIBCPP_BEGIN_NAMESPACE_STD
2522
2623namespace rel_ops
......@@ -58,10 +55,8 @@ operator>=(const _Tp& __x, const _Tp& __y)
5855 return !(__x < __y);
5956}
6057
61} // rel_ops
58} // namespace rel_ops
6259
6360_LIBCPP_END_NAMESPACE_STD
6461
65_LIBCPP_POP_MACROS
66
6762#endif // _LIBCPP___UTILITY_REL_OPS_H
lib/libcxx/include/__utility/swap.h+1-6
......@@ -12,16 +12,13 @@
1212#include <__config>
1313#include <__utility/declval.h>
1414#include <__utility/move.h>
15#include <type_traits>
1615#include <cstddef>
16#include <type_traits>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1919#pragma GCC system_header
2020#endif
2121
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
2522_LIBCPP_BEGIN_NAMESPACE_STD
2623
2724#ifndef _LIBCPP_CXX03_LANG
......@@ -50,6 +47,4 @@ swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::v
5047
5148_LIBCPP_END_NAMESPACE_STD
5249
53_LIBCPP_POP_MACROS
54
5550#endif // _LIBCPP___UTILITY_SWAP_H
lib/libcxx/include/__utility/to_underlying.h+1-6
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===----------------- __utility/to_underlying.h --------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -17,9 +17,6 @@
1717#pragma GCC system_header
1818#endif
1919
20_LIBCPP_PUSH_MACROS
21#include <__undef_macros>
22
2320_LIBCPP_BEGIN_NAMESPACE_STD
2421
2522#ifndef _LIBCPP_CXX03_LANG
......@@ -40,6 +37,4 @@ to_underlying(_Tp __val) noexcept {
4037
4138_LIBCPP_END_NAMESPACE_STD
4239
43_LIBCPP_POP_MACROS
44
4540#endif // _LIBCPP___UTILITY_TO_UNDERLYING_H
lib/libcxx/include/__utility/transaction.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___UTILITY_TRANSACTION_H
10#define _LIBCPP___UTILITY_TRANSACTION_H
11
12#include <__config>
13#include <__utility/exchange.h>
14#include <__utility/move.h>
15#include <type_traits>
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// __transaction is a helper class for writing code with the strong exception guarantee.
24//
25// When writing code that can throw an exception, one can store rollback instructions in a
26// transaction so that if an exception is thrown at any point during the lifetime of the
27// transaction, it will be rolled back automatically. When the transaction is done, one
28// must mark it as being complete so it isn't rolled back when the transaction is destroyed.
29//
30// Transactions are not default constructible, they can't be copied or assigned to, but
31// they can be moved around for convenience.
32//
33// __transaction can help greatly simplify code that would normally be cluttered by
34// `#if _LIBCPP_NO_EXCEPTIONS`. For example:
35//
36// template <class Iterator, class Size, class OutputIterator>
37// Iterator uninitialized_copy_n(Iterator iter, Size n, OutputIterator out) {
38// typedef typename iterator_traits<Iterator>::value_type value_type;
39// __transaction transaction([start=out, &out] {
40// std::destroy(start, out);
41// });
42//
43// for (; n > 0; ++iter, ++out, --n) {
44// ::new ((void*)std::addressof(*out)) value_type(*iter);
45// }
46// transaction.__complete();
47// return out;
48// }
49//
50template <class _Rollback>
51struct __transaction {
52 __transaction() = delete;
53
54 _LIBCPP_HIDE_FROM_ABI
55 _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit __transaction(_Rollback __rollback)
56 : __rollback_(_VSTD::move(__rollback))
57 , __completed_(false)
58 { }
59
60 _LIBCPP_HIDE_FROM_ABI
61 _LIBCPP_CONSTEXPR_AFTER_CXX17 __transaction(__transaction&& __other)
62 _NOEXCEPT_(is_nothrow_move_constructible<_Rollback>::value)
63 : __rollback_(_VSTD::move(__other.__rollback_))
64 , __completed_(__other.__completed_)
65 {
66 __other.__completed_ = true;
67 }
68
69 __transaction(__transaction const&) = delete;
70 __transaction& operator=(__transaction const&) = delete;
71 __transaction& operator=(__transaction&&) = delete;
72
73 _LIBCPP_HIDE_FROM_ABI
74 _LIBCPP_CONSTEXPR_AFTER_CXX17 void __complete() _NOEXCEPT {
75 __completed_ = true;
76 }
77
78 _LIBCPP_HIDE_FROM_ABI
79 _LIBCPP_CONSTEXPR_AFTER_CXX17 ~__transaction() {
80 if (!__completed_)
81 __rollback_();
82 }
83
84private:
85 _Rollback __rollback_;
86 bool __completed_;
87};
88
89_LIBCPP_END_NAMESPACE_STD
90
91#endif // _LIBCPP___UTILITY_TRANSACTION_H
lib/libcxx/include/__variant/monostate.h-5
......@@ -18,9 +18,6 @@
1818#pragma GCC system_header
1919#endif
2020
21_LIBCPP_PUSH_MACROS
22#include <__undef_macros>
23
2421_LIBCPP_BEGIN_NAMESPACE_STD
2522
2623#if _LIBCPP_STD_VER > 14
......@@ -60,6 +57,4 @@ struct _LIBCPP_TEMPLATE_VIS hash<monostate> {
6057
6158_LIBCPP_END_NAMESPACE_STD
6259
63_LIBCPP_POP_MACROS
64
6560#endif // _LIBCPP___VARIANT_MONOSTATE_H
lib/libcxx/include/algorithm+22-12
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===-------------------------- algorithm ---------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -18,6 +18,14 @@
1818namespace std
1919{
2020
21namespace ranges {
22 template <class I1, class I2>
23 struct in_in_result; // since C++20
24
25 template <class I1, class I2, class O>
26 struct in_in_out_result; // since C++20
27}
28
2129template <class InputIterator, class Predicate>
2230 constexpr bool // constexpr in C++20
2331 all_of(InputIterator first, InputIterator last, Predicate pred);
......@@ -641,19 +649,23 @@ template <class BidirectionalIterator, class Compare>
641649 constexpr bool // constexpr in C++20
642650 prev_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp);
643651
652namespace ranges {
653// [algorithms.results], algorithm result types
654template<class InputIterator, class OutputIterator>
655 struct in_out_result;
656}
657
644658} // std
645659
646660*/
647661
662#include <__bits> // __libcpp_clz
648663#include <__config>
649664#include <__debug>
650#include <__bits> // __libcpp_clz
651665#include <cstddef>
652666#include <cstring>
653667#include <functional>
654668#include <initializer_list>
655#include <utility> // needed to provide swap_ranges.
656#include <memory>
657669#include <iterator>
658670#include <memory>
659671#include <type_traits>
......@@ -675,8 +687,8 @@ template <class BidirectionalIterator, class Compare>
675687#include <__algorithm/count_if.h>
676688#include <__algorithm/equal.h>
677689#include <__algorithm/equal_range.h>
678#include <__algorithm/fill_n.h>
679690#include <__algorithm/fill.h>
691#include <__algorithm/fill_n.h>
680692#include <__algorithm/find.h>
681693#include <__algorithm/find_end.h>
682694#include <__algorithm/find_first_of.h>
......@@ -684,9 +696,12 @@ template <class BidirectionalIterator, class Compare>
684696#include <__algorithm/find_if_not.h>
685697#include <__algorithm/for_each.h>
686698#include <__algorithm/for_each_n.h>
687#include <__algorithm/generate_n.h>
688699#include <__algorithm/generate.h>
700#include <__algorithm/generate_n.h>
689701#include <__algorithm/half_positive.h>
702#include <__algorithm/in_in_out_result.h>
703#include <__algorithm/in_in_result.h>
704#include <__algorithm/in_out_result.h>
690705#include <__algorithm/includes.h>
691706#include <__algorithm/inplace_merge.h>
692707#include <__algorithm/is_heap.h>
......@@ -749,8 +764,8 @@ template <class BidirectionalIterator, class Compare>
749764#include <__algorithm/stable_sort.h>
750765#include <__algorithm/swap_ranges.h>
751766#include <__algorithm/transform.h>
752#include <__algorithm/unique_copy.h>
753767#include <__algorithm/unique.h>
768#include <__algorithm/unique_copy.h>
754769#include <__algorithm/unwrap_iter.h>
755770#include <__algorithm/upper_bound.h>
756771
......@@ -758,11 +773,6 @@ template <class BidirectionalIterator, class Compare>
758773#pragma GCC system_header
759774#endif
760775
761_LIBCPP_PUSH_MACROS
762#include <__undef_macros>
763
764_LIBCPP_POP_MACROS
765
766776#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17
767777# include <__pstl_algorithm>
768778#endif
lib/libcxx/include/any+1-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===------------------------------ any -----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/array+3-3
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===---------------------------- array -----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -356,9 +356,9 @@ struct _LIBCPP_TEMPLATE_VIS array<_Tp, 0>
356356};
357357
358358
359#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
359#if _LIBCPP_STD_VER >= 17
360360template<class _Tp, class... _Args,
361 class = _EnableIf<__all<_IsSame<_Tp, _Args>::value...>::value>
361 class = enable_if_t<__all<_IsSame<_Tp, _Args>::value...>::value>
362362 >
363363array(_Tp, _Args...)
364364 -> array<_Tp, 1 + sizeof...(_Args)>;
lib/libcxx/include/atomic+208-328
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- atomic -----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -263,196 +263,137 @@ struct atomic<T*>
263263};
264264
265265
266template <class T>
267 bool atomic_is_lock_free(const volatile atomic<T>* obj) noexcept;
268
269template <class T>
270 bool atomic_is_lock_free(const atomic<T>* obj) noexcept;
271
272template <class T>
273 void atomic_store(volatile atomic<T>* obj, T desr) noexcept;
274
275template <class T>
276 void atomic_store(atomic<T>* obj, T desr) noexcept;
277
278template <class T>
279 void atomic_store_explicit(volatile atomic<T>* obj, T desr, memory_order m) noexcept;
280
281template <class T>
282 void atomic_store_explicit(atomic<T>* obj, T desr, memory_order m) noexcept;
283
284template <class T>
285 T atomic_load(const volatile atomic<T>* obj) noexcept;
286
287template <class T>
288 T atomic_load(const atomic<T>* obj) noexcept;
289
290template <class T>
291 T atomic_load_explicit(const volatile atomic<T>* obj, memory_order m) noexcept;
292
293template <class T>
294 T atomic_load_explicit(const atomic<T>* obj, memory_order m) noexcept;
295
296template <class T>
297 T atomic_exchange(volatile atomic<T>* obj, T desr) noexcept;
298
299template <class T>
300 T atomic_exchange(atomic<T>* obj, T desr) noexcept;
301
302template <class T>
303 T atomic_exchange_explicit(volatile atomic<T>* obj, T desr, memory_order m) noexcept;
304
305template <class T>
306 T atomic_exchange_explicit(atomic<T>* obj, T desr, memory_order m) noexcept;
307
308template <class T>
309 bool atomic_compare_exchange_weak(volatile atomic<T>* obj, T* expc, T desr) noexcept;
310
311template <class T>
312 bool atomic_compare_exchange_weak(atomic<T>* obj, T* expc, T desr) noexcept;
313
314template <class T>
315 bool atomic_compare_exchange_strong(volatile atomic<T>* obj, T* expc, T desr) noexcept;
316
317template <class T>
318 bool atomic_compare_exchange_strong(atomic<T>* obj, T* expc, T desr) noexcept;
319
320template <class T>
321 bool atomic_compare_exchange_weak_explicit(volatile atomic<T>* obj, T* expc,
322 T desr,
323 memory_order s, memory_order f) noexcept;
324
325template <class T>
326 bool atomic_compare_exchange_weak_explicit(atomic<T>* obj, T* expc, T desr,
327 memory_order s, memory_order f) noexcept;
328
329template <class T>
330 bool atomic_compare_exchange_strong_explicit(volatile atomic<T>* obj,
331 T* expc, T desr,
332 memory_order s, memory_order f) noexcept;
333
334template <class T>
335 bool atomic_compare_exchange_strong_explicit(atomic<T>* obj, T* expc,
336 T desr,
337 memory_order s, memory_order f) noexcept;
338
339template <class T>
340 void atomic_wait(const volatile atomic<T>* obj, T old) noexcept;
341
342template <class T>
343 void atomic_wait(const atomic<T>* obj, T old) noexcept;
344
345template <class T>
346 void atomic_wait_explicit(const volatile atomic<T>* obj, T old, memory_order m) noexcept;
347
348template <class T>
349 void atomic_wait_explicit(const atomic<T>* obj, T old, memory_order m) noexcept;
350
351template <class T>
352 void atomic_one(volatile atomic<T>* obj) noexcept;
353
354template <class T>
355 void atomic_one(atomic<T>* obj) noexcept;
356
357template <class T>
358 void atomic_all(volatile atomic<T>* obj) noexcept;
359
360template <class T>
361 void atomic_all(atomic<T>* obj) noexcept;
362
363template <class Integral>
364 Integral atomic_fetch_add(volatile atomic<Integral>* obj, Integral op) noexcept;
365
366template <class Integral>
367 Integral atomic_fetch_add(atomic<Integral>* obj, Integral op) noexcept;
368
369template <class Integral>
370 Integral atomic_fetch_add_explicit(volatile atomic<Integral>* obj, Integral op,
371 memory_order m) noexcept;
372template <class Integral>
373 Integral atomic_fetch_add_explicit(atomic<Integral>* obj, Integral op,
374 memory_order m) noexcept;
375template <class Integral>
376 Integral atomic_fetch_sub(volatile atomic<Integral>* obj, Integral op) noexcept;
377
378template <class Integral>
379 Integral atomic_fetch_sub(atomic<Integral>* obj, Integral op) noexcept;
380
381template <class Integral>
382 Integral atomic_fetch_sub_explicit(volatile atomic<Integral>* obj, Integral op,
383 memory_order m) noexcept;
384
385template <class Integral>
386 Integral atomic_fetch_sub_explicit(atomic<Integral>* obj, Integral op,
387 memory_order m) noexcept;
388
389template <class Integral>
390 Integral atomic_fetch_and(volatile atomic<Integral>* obj, Integral op) noexcept;
391
392template <class Integral>
393 Integral atomic_fetch_and(atomic<Integral>* obj, Integral op) noexcept;
394
395template <class Integral>
396 Integral atomic_fetch_and_explicit(volatile atomic<Integral>* obj, Integral op,
397 memory_order m) noexcept;
398
399template <class Integral>
400 Integral atomic_fetch_and_explicit(atomic<Integral>* obj, Integral op,
401 memory_order m) noexcept;
402
403template <class Integral>
404 Integral atomic_fetch_or(volatile atomic<Integral>* obj, Integral op) noexcept;
405
406template <class Integral>
407 Integral atomic_fetch_or(atomic<Integral>* obj, Integral op) noexcept;
408
409template <class Integral>
410 Integral atomic_fetch_or_explicit(volatile atomic<Integral>* obj, Integral op,
411 memory_order m) noexcept;
412
413template <class Integral>
414 Integral atomic_fetch_or_explicit(atomic<Integral>* obj, Integral op,
415 memory_order m) noexcept;
416
417template <class Integral>
418 Integral atomic_fetch_xor(volatile atomic<Integral>* obj, Integral op) noexcept;
419
420template <class Integral>
421 Integral atomic_fetch_xor(atomic<Integral>* obj, Integral op) noexcept;
422
423template <class Integral>
424 Integral atomic_fetch_xor_explicit(volatile atomic<Integral>* obj, Integral op,
425 memory_order m) noexcept;
426
427template <class Integral>
428 Integral atomic_fetch_xor_explicit(atomic<Integral>* obj, Integral op,
429 memory_order m) noexcept;
430
431template <class T>
432 T* atomic_fetch_add(volatile atomic<T*>* obj, ptrdiff_t op) noexcept;
433
434template <class T>
435 T* atomic_fetch_add(atomic<T*>* obj, ptrdiff_t op) noexcept;
436
437template <class T>
438 T* atomic_fetch_add_explicit(volatile atomic<T*>* obj, ptrdiff_t op,
439 memory_order m) noexcept;
440
441template <class T>
442 T* atomic_fetch_add_explicit(atomic<T*>* obj, ptrdiff_t op, memory_order m) noexcept;
443
444template <class T>
445 T* atomic_fetch_sub(volatile atomic<T*>* obj, ptrdiff_t op) noexcept;
446
447template <class T>
448 T* atomic_fetch_sub(atomic<T*>* obj, ptrdiff_t op) noexcept;
449
450template <class T>
451 T* atomic_fetch_sub_explicit(volatile atomic<T*>* obj, ptrdiff_t op,
452 memory_order m) noexcept;
453
454template <class T>
455 T* atomic_fetch_sub_explicit(atomic<T*>* obj, ptrdiff_t op, memory_order m) noexcept;
266// [atomics.nonmembers], non-member functions
267template<class T>
268 bool atomic_is_lock_free(const volatile atomic<T>*) noexcept;
269template<class T>
270 bool atomic_is_lock_free(const atomic<T>*) noexcept;
271template<class T>
272 void atomic_store(volatile atomic<T>*, atomic<T>::value_type) noexcept;
273template<class T>
274 void atomic_store(atomic<T>*, atomic<T>::value_type) noexcept;
275template<class T>
276 void atomic_store_explicit(volatile atomic<T>*, atomic<T>::value_type,
277 memory_order) noexcept;
278template<class T>
279 void atomic_store_explicit(atomic<T>*, atomic<T>::value_type,
280 memory_order) noexcept;
281template<class T>
282 T atomic_load(const volatile atomic<T>*) noexcept;
283template<class T>
284 T atomic_load(const atomic<T>*) noexcept;
285template<class T>
286 T atomic_load_explicit(const volatile atomic<T>*, memory_order) noexcept;
287template<class T>
288 T atomic_load_explicit(const atomic<T>*, memory_order) noexcept;
289template<class T>
290 T atomic_exchange(volatile atomic<T>*, atomic<T>::value_type) noexcept;
291template<class T>
292 T atomic_exchange(atomic<T>*, atomic<T>::value_type) noexcept;
293template<class T>
294 T atomic_exchange_explicit(volatile atomic<T>*, atomic<T>::value_type,
295 memory_order) noexcept;
296template<class T>
297 T atomic_exchange_explicit(atomic<T>*, atomic<T>::value_type,
298 memory_order) noexcept;
299template<class T>
300 bool atomic_compare_exchange_weak(volatile atomic<T>*, atomic<T>::value_type*,
301 atomic<T>::value_type) noexcept;
302template<class T>
303 bool atomic_compare_exchange_weak(atomic<T>*, atomic<T>::value_type*,
304 atomic<T>::value_type) noexcept;
305template<class T>
306 bool atomic_compare_exchange_strong(volatile atomic<T>*, atomic<T>::value_type*,
307 atomic<T>::value_type) noexcept;
308template<class T>
309 bool atomic_compare_exchange_strong(atomic<T>*, atomic<T>::value_type*,
310 atomic<T>::value_type) noexcept;
311template<class T>
312 bool atomic_compare_exchange_weak_explicit(volatile atomic<T>*, atomic<T>::value_type*,
313 atomic<T>::value_type,
314 memory_order, memory_order) noexcept;
315template<class T>
316 bool atomic_compare_exchange_weak_explicit(atomic<T>*, atomic<T>::value_type*,
317 atomic<T>::value_type,
318 memory_order, memory_order) noexcept;
319template<class T>
320 bool atomic_compare_exchange_strong_explicit(volatile atomic<T>*, atomic<T>::value_type*,
321 atomic<T>::value_type,
322 memory_order, memory_order) noexcept;
323template<class T>
324 bool atomic_compare_exchange_strong_explicit(atomic<T>*, atomic<T>::value_type*,
325 atomic<T>::value_type,
326 memory_order, memory_order) noexcept;
327
328template<class T>
329 T atomic_fetch_add(volatile atomic<T>*, atomic<T>::difference_type) noexcept;
330template<class T>
331 T atomic_fetch_add(atomic<T>*, atomic<T>::difference_type) noexcept;
332template<class T>
333 T atomic_fetch_add_explicit(volatile atomic<T>*, atomic<T>::difference_type,
334 memory_order) noexcept;
335template<class T>
336 T atomic_fetch_add_explicit(atomic<T>*, atomic<T>::difference_type,
337 memory_order) noexcept;
338template<class T>
339 T atomic_fetch_sub(volatile atomic<T>*, atomic<T>::difference_type) noexcept;
340template<class T>
341 T atomic_fetch_sub(atomic<T>*, atomic<T>::difference_type) noexcept;
342template<class T>
343 T atomic_fetch_sub_explicit(volatile atomic<T>*, atomic<T>::difference_type,
344 memory_order) noexcept;
345template<class T>
346 T atomic_fetch_sub_explicit(atomic<T>*, atomic<T>::difference_type,
347 memory_order) noexcept;
348template<class T>
349 T atomic_fetch_and(volatile atomic<T>*, atomic<T>::value_type) noexcept;
350template<class T>
351 T atomic_fetch_and(atomic<T>*, atomic<T>::value_type) noexcept;
352template<class T>
353 T atomic_fetch_and_explicit(volatile atomic<T>*, atomic<T>::value_type,
354 memory_order) noexcept;
355template<class T>
356 T atomic_fetch_and_explicit(atomic<T>*, atomic<T>::value_type,
357 memory_order) noexcept;
358template<class T>
359 T atomic_fetch_or(volatile atomic<T>*, atomic<T>::value_type) noexcept;
360template<class T>
361 T atomic_fetch_or(atomic<T>*, atomic<T>::value_type) noexcept;
362template<class T>
363 T atomic_fetch_or_explicit(volatile atomic<T>*, atomic<T>::value_type,
364 memory_order) noexcept;
365template<class T>
366 T atomic_fetch_or_explicit(atomic<T>*, atomic<T>::value_type,
367 memory_order) noexcept;
368template<class T>
369 T atomic_fetch_xor(volatile atomic<T>*, atomic<T>::value_type) noexcept;
370template<class T>
371 T atomic_fetch_xor(atomic<T>*, atomic<T>::value_type) noexcept;
372template<class T>
373 T atomic_fetch_xor_explicit(volatile atomic<T>*, atomic<T>::value_type,
374 memory_order) noexcept;
375template<class T>
376 T atomic_fetch_xor_explicit(atomic<T>*, atomic<T>::value_type,
377 memory_order) noexcept;
378
379template<class T>
380 void atomic_wait(const volatile atomic<T>*, atomic<T>::value_type);
381template<class T>
382 void atomic_wait(const atomic<T>*, atomic<T>::value_type);
383template<class T>
384 void atomic_wait_explicit(const volatile atomic<T>*, atomic<T>::value_type,
385 memory_order);
386template<class T>
387 void atomic_wait_explicit(const atomic<T>*, atomic<T>::value_type,
388 memory_order);
389template<class T>
390 void atomic_notify_one(volatile atomic<T>*);
391template<class T>
392 void atomic_notify_one(atomic<T>*);
393template<class T>
394 void atomic_notify_all(volatile atomic<T>*);
395template<class T>
396 void atomic_notify_all(atomic<T>*);
456397
457398// Atomics for standard typedef types
458399
......@@ -564,10 +505,10 @@ void atomic_signal_fence(memory_order m) noexcept;
564505// deprecated
565506
566507template <class T>
567 void atomic_init(volatile atomic<T>* obj, typename atomic<T>::value_type desr) noexcept;
508 void atomic_init(volatile atomic<T>* obj, atomic<T>::value_type desr) noexcept;
568509
569510template <class T>
570 void atomic_init(atomic<T>* obj, typename atomic<T>::value_type desr) noexcept;
511 void atomic_init(atomic<T>* obj, atomic<T>::value_type desr) noexcept;
571512
572513#define ATOMIC_VAR_INIT(value) see below
573514
......@@ -579,20 +520,22 @@ template <class T>
579520
580521#include <__availability>
581522#include <__config>
582#include <__threading_support>
523#include <__thread/poll_with_backoff.h>
524#include <__thread/timed_backoff_policy.h>
583525#include <cstddef>
584526#include <cstdint>
585527#include <cstring>
586528#include <type_traits>
587529#include <version>
588530
531#ifndef _LIBCPP_HAS_NO_THREADS
532# include <__threading_support>
533#endif
534
589535#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
590536#pragma GCC system_header
591537#endif
592538
593#ifdef _LIBCPP_HAS_NO_THREADS
594# error <atomic> is not supported on this single threaded system
595#endif
596539#ifdef _LIBCPP_HAS_NO_ATOMIC_HEADER
597540# error <atomic> is not implemented
598541#endif
......@@ -1473,7 +1416,9 @@ template<> struct __cxx_is_always_lock_free<char8_t> { enum { __value = 2 == ATO
14731416#endif
14741417template<> struct __cxx_is_always_lock_free<char16_t> { enum { __value = 2 == ATOMIC_CHAR16_T_LOCK_FREE }; };
14751418template<> struct __cxx_is_always_lock_free<char32_t> { enum { __value = 2 == ATOMIC_CHAR32_T_LOCK_FREE }; };
1419#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
14761420template<> struct __cxx_is_always_lock_free<wchar_t> { enum { __value = 2 == ATOMIC_WCHAR_T_LOCK_FREE }; };
1421#endif
14771422template<> struct __cxx_is_always_lock_free<short> { enum { __value = 2 == ATOMIC_SHORT_LOCK_FREE }; };
14781423template<> struct __cxx_is_always_lock_free<unsigned short> { enum { __value = 2 == ATOMIC_SHORT_LOCK_FREE }; };
14791424template<> struct __cxx_is_always_lock_free<int> { enum { __value = 2 == ATOMIC_INT_LOCK_FREE }; };
......@@ -1496,13 +1441,10 @@ template <typename _Tp,
14961441 typename _Base = __cxx_atomic_base_impl<_Tp> >
14971442#endif //_LIBCPP_ATOMIC_ONLY_USE_BUILTINS
14981443struct __cxx_atomic_impl : public _Base {
1499
1500#if _GNUC_VER >= 501
15011444 static_assert(is_trivially_copyable<_Tp>::value,
1502 "std::atomic<Tp> requires that 'Tp' be a trivially copyable type");
1503#endif
1445 "std::atomic<T> requires that 'T' be a trivially copyable type");
15041446
1505 _LIBCPP_INLINE_VISIBILITY __cxx_atomic_impl() _NOEXCEPT _LIBCPP_DEFAULT
1447 _LIBCPP_INLINE_VISIBILITY __cxx_atomic_impl() _NOEXCEPT = default;
15061448 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR explicit __cxx_atomic_impl(_Tp value) _NOEXCEPT
15071449 : _Base(value) {}
15081450};
......@@ -1515,6 +1457,16 @@ struct __cxx_atomic_impl : public _Base {
15151457
15161458using __cxx_atomic_contention_t = __cxx_atomic_impl<__cxx_contention_t>;
15171459
1460#if defined(_LIBCPP_HAS_NO_THREADS)
1461# define _LIBCPP_HAS_NO_PLATFORM_WAIT
1462#endif
1463
1464// TODO:
1465// _LIBCPP_HAS_NO_PLATFORM_WAIT is currently a "dead" macro, in the sense that
1466// it is not tied anywhere into the build system or even documented. We should
1467// clean it up because it is technically never defined except when threads are
1468// disabled. We should clean it up in its own changeset in case we break "bad"
1469// users.
15181470#ifndef _LIBCPP_HAS_NO_PLATFORM_WAIT
15191471
15201472_LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI void __cxx_atomic_notify_one(void const volatile*);
......@@ -1566,7 +1518,12 @@ _LIBCPP_INLINE_VISIBILITY void __cxx_atomic_notify_one(__cxx_atomic_impl<_Tp> co
15661518template <class _Atp, class _Fn>
15671519_LIBCPP_INLINE_VISIBILITY bool __cxx_atomic_wait(_Atp*, _Fn && __test_fn)
15681520{
1569 return __libcpp_thread_poll_with_backoff(__test_fn, __libcpp_timed_backoff_policy());
1521#if defined(_LIBCPP_HAS_NO_THREADS)
1522 using _Policy = __spinning_backoff_policy;
1523#else
1524 using _Policy = __libcpp_timed_backoff_policy;
1525#endif
1526 return __libcpp_thread_poll_with_backoff(__test_fn, _Policy());
15701527}
15711528
15721529#endif // _LIBCPP_HAS_NO_PLATFORM_WAIT
......@@ -1688,7 +1645,7 @@ struct __atomic_base // false
16881645 __atomic_base() noexcept(is_nothrow_default_constructible_v<_Tp>) : __a_(_Tp()) {}
16891646#else
16901647 _LIBCPP_INLINE_VISIBILITY
1691 __atomic_base() _NOEXCEPT _LIBCPP_DEFAULT
1648 __atomic_base() _NOEXCEPT = default;
16921649#endif
16931650
16941651 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
......@@ -1717,7 +1674,7 @@ struct __atomic_base<_Tp, true>
17171674 typedef __atomic_base<_Tp, false> __base;
17181675
17191676 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1720 __atomic_base() _NOEXCEPT _LIBCPP_DEFAULT
1677 __atomic_base() _NOEXCEPT = default;
17211678
17221679 _LIBCPP_INLINE_VISIBILITY
17231680 _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __base(__d) {}
......@@ -1806,7 +1763,7 @@ struct atomic
18061763 atomic() = default;
18071764#else
18081765 _LIBCPP_INLINE_VISIBILITY
1809 atomic() _NOEXCEPT _LIBCPP_DEFAULT
1766 atomic() _NOEXCEPT = default;
18101767#endif
18111768
18121769 _LIBCPP_INLINE_VISIBILITY
......@@ -1834,7 +1791,7 @@ struct atomic<_Tp*>
18341791 typedef ptrdiff_t difference_type;
18351792
18361793 _LIBCPP_INLINE_VISIBILITY
1837 atomic() _NOEXCEPT _LIBCPP_DEFAULT
1794 atomic() _NOEXCEPT = default;
18381795
18391796 _LIBCPP_INLINE_VISIBILITY
18401797 _LIBCPP_CONSTEXPR atomic(_Tp* __d) _NOEXCEPT : __base(__d) {}
......@@ -1847,19 +1804,32 @@ struct atomic<_Tp*>
18471804 {__base::store(__d); return __d;}
18481805
18491806 _LIBCPP_INLINE_VISIBILITY
1850 _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst)
1851 volatile _NOEXCEPT
1852 {return __cxx_atomic_fetch_add(&this->__a_, __op, __m);}
1807 _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT {
1808 // __atomic_fetch_add accepts function pointers, guard against them.
1809 static_assert(!is_function<typename remove_pointer<_Tp>::type>::value, "Pointer to function isn't allowed");
1810 return __cxx_atomic_fetch_add(&this->__a_, __op, __m);
1811 }
1812
18531813 _LIBCPP_INLINE_VISIBILITY
1854 _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
1855 {return __cxx_atomic_fetch_add(&this->__a_, __op, __m);}
1814 _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT {
1815 // __atomic_fetch_add accepts function pointers, guard against them.
1816 static_assert(!is_function<typename remove_pointer<_Tp>::type>::value, "Pointer to function isn't allowed");
1817 return __cxx_atomic_fetch_add(&this->__a_, __op, __m);
1818 }
1819
18561820 _LIBCPP_INLINE_VISIBILITY
1857 _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst)
1858 volatile _NOEXCEPT
1859 {return __cxx_atomic_fetch_sub(&this->__a_, __op, __m);}
1821 _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT {
1822 // __atomic_fetch_add accepts function pointers, guard against them.
1823 static_assert(!is_function<typename remove_pointer<_Tp>::type>::value, "Pointer to function isn't allowed");
1824 return __cxx_atomic_fetch_sub(&this->__a_, __op, __m);
1825 }
1826
18601827 _LIBCPP_INLINE_VISIBILITY
1861 _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
1862 {return __cxx_atomic_fetch_sub(&this->__a_, __op, __m);}
1828 _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT {
1829 // __atomic_fetch_add accepts function pointers, guard against them.
1830 static_assert(!is_function<typename remove_pointer<_Tp>::type>::value, "Pointer to function isn't allowed");
1831 return __cxx_atomic_fetch_sub(&this->__a_, __op, __m);
1832 }
18631833
18641834 _LIBCPP_INLINE_VISIBILITY
18651835 _Tp* operator++(int) volatile _NOEXCEPT {return fetch_add(1);}
......@@ -2195,11 +2165,7 @@ void atomic_notify_all(atomic<_Tp>* __o) _NOEXCEPT
21952165
21962166template <class _Tp>
21972167_LIBCPP_INLINE_VISIBILITY
2198typename enable_if
2199<
2200 is_integral<_Tp>::value && !is_same<_Tp, bool>::value && !is_const<_Tp>::value,
2201 _Tp
2202>::type
2168_Tp
22032169atomic_fetch_add(volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op) _NOEXCEPT
22042170{
22052171 return __o->fetch_add(__op);
......@@ -2207,70 +2173,24 @@ atomic_fetch_add(volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_typ
22072173
22082174template <class _Tp>
22092175_LIBCPP_INLINE_VISIBILITY
2210typename enable_if
2211<
2212 is_integral<_Tp>::value && !is_same<_Tp, bool>::value && !is_const<_Tp>::value,
2213 _Tp
2214>::type
2176_Tp
22152177atomic_fetch_add(atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op) _NOEXCEPT
22162178{
22172179 return __o->fetch_add(__op);
22182180}
22192181
2220template <class _Tp>
2221_LIBCPP_INLINE_VISIBILITY
2222_Tp*
2223atomic_fetch_add(volatile atomic<_Tp*>* __o, typename atomic<_Tp*>::difference_type __op) _NOEXCEPT
2224{
2225 return __o->fetch_add(__op);
2226}
2227
2228template <class _Tp>
2229_LIBCPP_INLINE_VISIBILITY
2230_Tp*
2231atomic_fetch_add(atomic<_Tp*>* __o, typename atomic<_Tp*>::difference_type __op) _NOEXCEPT
2232{
2233 return __o->fetch_add(__op);
2234}
2235
22362182// atomic_fetch_add_explicit
22372183
22382184template <class _Tp>
22392185_LIBCPP_INLINE_VISIBILITY
2240typename enable_if
2241<
2242 is_integral<_Tp>::value && !is_same<_Tp, bool>::value && !is_const<_Tp>::value,
2243 _Tp
2244>::type
2245atomic_fetch_add_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT
2186_Tp atomic_fetch_add_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT
22462187{
22472188 return __o->fetch_add(__op, __m);
22482189}
22492190
22502191template <class _Tp>
22512192_LIBCPP_INLINE_VISIBILITY
2252typename enable_if
2253<
2254 is_integral<_Tp>::value && !is_same<_Tp, bool>::value && !is_const<_Tp>::value,
2255 _Tp
2256>::type
2257atomic_fetch_add_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT
2258{
2259 return __o->fetch_add(__op, __m);
2260}
2261
2262template <class _Tp>
2263_LIBCPP_INLINE_VISIBILITY
2264_Tp*
2265atomic_fetch_add_explicit(volatile atomic<_Tp*>* __o, typename atomic<_Tp*>::difference_type __op, memory_order __m) _NOEXCEPT
2266{
2267 return __o->fetch_add(__op, __m);
2268}
2269
2270template <class _Tp>
2271_LIBCPP_INLINE_VISIBILITY
2272_Tp*
2273atomic_fetch_add_explicit(atomic<_Tp*>* __o, typename atomic<_Tp*>::difference_type __op, memory_order __m) _NOEXCEPT
2193_Tp atomic_fetch_add_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT
22742194{
22752195 return __o->fetch_add(__op, __m);
22762196}
......@@ -2279,40 +2199,14 @@ atomic_fetch_add_explicit(atomic<_Tp*>* __o, typename atomic<_Tp*>::difference_t
22792199
22802200template <class _Tp>
22812201_LIBCPP_INLINE_VISIBILITY
2282typename enable_if
2283<
2284 is_integral<_Tp>::value && !is_same<_Tp, bool>::value && !is_const<_Tp>::value,
2285 _Tp
2286>::type
2287atomic_fetch_sub(volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op) _NOEXCEPT
2288{
2289 return __o->fetch_sub(__op);
2290}
2291
2292template <class _Tp>
2293_LIBCPP_INLINE_VISIBILITY
2294typename enable_if
2295<
2296 is_integral<_Tp>::value && !is_same<_Tp, bool>::value && !is_const<_Tp>::value,
2297 _Tp
2298>::type
2299atomic_fetch_sub(atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op) _NOEXCEPT
2300{
2301 return __o->fetch_sub(__op);
2302}
2303
2304template <class _Tp>
2305_LIBCPP_INLINE_VISIBILITY
2306_Tp*
2307atomic_fetch_sub(volatile atomic<_Tp*>* __o, typename atomic<_Tp*>::difference_type __op) _NOEXCEPT
2202_Tp atomic_fetch_sub(volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op) _NOEXCEPT
23082203{
23092204 return __o->fetch_sub(__op);
23102205}
23112206
23122207template <class _Tp>
23132208_LIBCPP_INLINE_VISIBILITY
2314_Tp*
2315atomic_fetch_sub(atomic<_Tp*>* __o, typename atomic<_Tp*>::difference_type __op) _NOEXCEPT
2209_Tp atomic_fetch_sub(atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op) _NOEXCEPT
23162210{
23172211 return __o->fetch_sub(__op);
23182212}
......@@ -2321,40 +2215,14 @@ atomic_fetch_sub(atomic<_Tp*>* __o, typename atomic<_Tp*>::difference_type __op)
23212215
23222216template <class _Tp>
23232217_LIBCPP_INLINE_VISIBILITY
2324typename enable_if
2325<
2326 is_integral<_Tp>::value && !is_same<_Tp, bool>::value && !is_const<_Tp>::value,
2327 _Tp
2328>::type
2329atomic_fetch_sub_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT
2218_Tp atomic_fetch_sub_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT
23302219{
23312220 return __o->fetch_sub(__op, __m);
23322221}
23332222
23342223template <class _Tp>
23352224_LIBCPP_INLINE_VISIBILITY
2336typename enable_if
2337<
2338 is_integral<_Tp>::value && !is_same<_Tp, bool>::value && !is_const<_Tp>::value,
2339 _Tp
2340>::type
2341atomic_fetch_sub_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT
2342{
2343 return __o->fetch_sub(__op, __m);
2344}
2345
2346template <class _Tp>
2347_LIBCPP_INLINE_VISIBILITY
2348_Tp*
2349atomic_fetch_sub_explicit(volatile atomic<_Tp*>* __o, typename atomic<_Tp*>::difference_type __op, memory_order __m) _NOEXCEPT
2350{
2351 return __o->fetch_sub(__op, __m);
2352}
2353
2354template <class _Tp>
2355_LIBCPP_INLINE_VISIBILITY
2356_Tp*
2357atomic_fetch_sub_explicit(atomic<_Tp*>* __o, typename atomic<_Tp*>::difference_type __op, memory_order __m) _NOEXCEPT
2225_Tp atomic_fetch_sub_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT
23582226{
23592227 return __o->fetch_sub(__op, __m);
23602228}
......@@ -2565,7 +2433,7 @@ typedef struct atomic_flag
25652433 atomic_flag() _NOEXCEPT : __a_(false) {}
25662434#else
25672435 _LIBCPP_INLINE_VISIBILITY
2568 atomic_flag() _NOEXCEPT _LIBCPP_DEFAULT
2436 atomic_flag() _NOEXCEPT = default;
25692437#endif
25702438
25712439 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
......@@ -2764,7 +2632,9 @@ typedef atomic<char8_t> atomic_char8_t;
27642632#endif
27652633typedef atomic<char16_t> atomic_char16_t;
27662634typedef atomic<char32_t> atomic_char32_t;
2635#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
27672636typedef atomic<wchar_t> atomic_wchar_t;
2637#endif
27682638
27692639typedef atomic<int_least8_t> atomic_int_least8_t;
27702640typedef atomic<uint_least8_t> atomic_uint_least8_t;
......@@ -2822,14 +2692,24 @@ typedef conditional<_LIBCPP_CONTENTION_LOCK_FREE, __cxx_contention_t, char>::typ
28222692typedef conditional<_LIBCPP_CONTENTION_LOCK_FREE, __cxx_contention_t, unsigned char>::type __libcpp_unsigned_lock_free;
28232693#else
28242694 // No signed/unsigned lock-free types
2695#define _LIBCPP_NO_LOCK_FREE_TYPES
28252696#endif
28262697
2698#if !defined(_LIBCPP_NO_LOCK_FREE_TYPES)
28272699typedef atomic<__libcpp_signed_lock_free> atomic_signed_lock_free;
28282700typedef atomic<__libcpp_unsigned_lock_free> atomic_unsigned_lock_free;
2701#endif
28292702
28302703#define ATOMIC_FLAG_INIT {false}
28312704#define ATOMIC_VAR_INIT(__v) {__v}
28322705
2706#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS)
2707# if defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER >= 1400
2708# pragma clang deprecated(ATOMIC_FLAG_INIT)
2709# pragma clang deprecated(ATOMIC_VAR_INIT)
2710# endif
2711#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS)
2712
28332713_LIBCPP_END_NAMESPACE_STD
28342714
28352715#endif // _LIBCPP_ATOMIC
lib/libcxx/include/barrier+2-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- barrier ----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -47,6 +47,7 @@ namespace std
4747
4848#include <__availability>
4949#include <__config>
50#include <__thread/timed_backoff_policy.h>
5051#include <atomic>
5152#ifndef _LIBCPP_HAS_NO_TREE_BARRIER
5253# include <memory>
lib/libcxx/include/bit+24-15
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===------------------------------ bit ----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -14,6 +14,13 @@
1414 bit synopsis
1515
1616namespace std {
17 // [bit.cast], bit_cast
18 template<class To, class From>
19 constexpr To bit_cast(const From& from) noexcept; // C++20
20
21 // [bit.byteswap], byteswap
22 template<class T>
23 constexpr T byteswap(T value) noexcept; // C++23
1724
1825 // [bit.pow.two], integral powers of 2
1926 template <class T>
......@@ -48,14 +55,16 @@ namespace std {
4855 little = see below, // C++20
4956 big = see below, // C++20
5057 native = see below // C++20
51};
58 };
5259
5360} // namespace std
5461
5562*/
5663
57#include <__config>
64#include <__bit/bit_cast.h>
65#include <__bit/byteswap.h>
5866#include <__bits> // __libcpp_clz
67#include <__config>
5968#include <__debug>
6069#include <limits>
6170#include <type_traits>
......@@ -222,7 +231,7 @@ bool __has_single_bit(_Tp __t) _NOEXCEPT
222231
223232template<class _Tp>
224233_LIBCPP_INLINE_VISIBILITY constexpr
225_EnableIf<__libcpp_is_unsigned_integer<_Tp>::value, _Tp>
234enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, _Tp>
226235rotl(_Tp __t, unsigned int __cnt) noexcept
227236{
228237 return __rotl(__t, __cnt);
......@@ -230,7 +239,7 @@ rotl(_Tp __t, unsigned int __cnt) noexcept
230239
231240template<class _Tp>
232241_LIBCPP_INLINE_VISIBILITY constexpr
233_EnableIf<__libcpp_is_unsigned_integer<_Tp>::value, _Tp>
242enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, _Tp>
234243rotr(_Tp __t, unsigned int __cnt) noexcept
235244{
236245 return __rotr(__t, __cnt);
......@@ -238,7 +247,7 @@ rotr(_Tp __t, unsigned int __cnt) noexcept
238247
239248template<class _Tp>
240249_LIBCPP_INLINE_VISIBILITY constexpr
241_EnableIf<__libcpp_is_unsigned_integer<_Tp>::value, int>
250enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, int>
242251countl_zero(_Tp __t) noexcept
243252{
244253 return __countl_zero(__t);
......@@ -246,7 +255,7 @@ countl_zero(_Tp __t) noexcept
246255
247256template<class _Tp>
248257_LIBCPP_INLINE_VISIBILITY constexpr
249_EnableIf<__libcpp_is_unsigned_integer<_Tp>::value, int>
258enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, int>
250259countl_one(_Tp __t) noexcept
251260{
252261 return __countl_one(__t);
......@@ -254,7 +263,7 @@ countl_one(_Tp __t) noexcept
254263
255264template<class _Tp>
256265_LIBCPP_INLINE_VISIBILITY constexpr
257_EnableIf<__libcpp_is_unsigned_integer<_Tp>::value, int>
266enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, int>
258267countr_zero(_Tp __t) noexcept
259268{
260269 return __countr_zero(__t);
......@@ -262,7 +271,7 @@ countr_zero(_Tp __t) noexcept
262271
263272template<class _Tp>
264273_LIBCPP_INLINE_VISIBILITY constexpr
265_EnableIf<__libcpp_is_unsigned_integer<_Tp>::value, int>
274enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, int>
266275countr_one(_Tp __t) noexcept
267276{
268277 return __countr_one(__t);
......@@ -270,7 +279,7 @@ countr_one(_Tp __t) noexcept
270279
271280template<class _Tp>
272281_LIBCPP_INLINE_VISIBILITY constexpr
273_EnableIf<__libcpp_is_unsigned_integer<_Tp>::value, int>
282enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, int>
274283popcount(_Tp __t) noexcept
275284{
276285 return __popcount(__t);
......@@ -278,7 +287,7 @@ popcount(_Tp __t) noexcept
278287
279288template <class _Tp>
280289_LIBCPP_INLINE_VISIBILITY constexpr
281_EnableIf<__libcpp_is_unsigned_integer<_Tp>::value, bool>
290enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, bool>
282291has_single_bit(_Tp __t) noexcept
283292{
284293 return __has_single_bit(__t);
......@@ -286,7 +295,7 @@ has_single_bit(_Tp __t) noexcept
286295
287296template <class _Tp>
288297_LIBCPP_INLINE_VISIBILITY constexpr
289_EnableIf<__libcpp_is_unsigned_integer<_Tp>::value, _Tp>
298enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, _Tp>
290299bit_floor(_Tp __t) noexcept
291300{
292301 return __t == 0 ? 0 : _Tp{1} << __bit_log2(__t);
......@@ -294,12 +303,12 @@ bit_floor(_Tp __t) noexcept
294303
295304template <class _Tp>
296305_LIBCPP_INLINE_VISIBILITY constexpr
297_EnableIf<__libcpp_is_unsigned_integer<_Tp>::value, _Tp>
306enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, _Tp>
298307bit_ceil(_Tp __t) noexcept
299308{
300309 if (__t < 2) return 1;
301310 const unsigned __n = numeric_limits<_Tp>::digits - countl_zero((_Tp)(__t - 1u));
302 _LIBCPP_DEBUG_ASSERT(__libcpp_is_constant_evaluated() || __n != numeric_limits<_Tp>::digits, "Bad input to bit_ceil");
311 _LIBCPP_ASSERT(__n != numeric_limits<_Tp>::digits, "Bad input to bit_ceil");
303312
304313 if constexpr (sizeof(_Tp) >= sizeof(unsigned))
305314 return _Tp{1} << __n;
......@@ -313,7 +322,7 @@ bit_ceil(_Tp __t) noexcept
313322
314323template <class _Tp>
315324_LIBCPP_INLINE_VISIBILITY constexpr
316_EnableIf<__libcpp_is_unsigned_integer<_Tp>::value, _Tp>
325enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, _Tp>
317326bit_width(_Tp __t) noexcept
318327{
319328 return __t == 0 ? 0 : __bit_log2(__t) + 1;
lib/libcxx/include/bitset+4-3
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===---------------------------- bitset ----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -112,14 +112,15 @@ template <size_t N> struct hash<std::bitset<N>>;
112112
113113*/
114114
115#include <__config>
116115#include <__bit_reference>
116#include <__config>
117117#include <__functional_base>
118118#include <climits>
119119#include <cstddef>
120120#include <iosfwd>
121121#include <stdexcept>
122122#include <string>
123#include <version>
123124
124125#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
125126#pragma GCC system_header
......@@ -679,7 +680,7 @@ public:
679680 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bitset() _NOEXCEPT {}
680681 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
681682 bitset(unsigned long long __v) _NOEXCEPT : base(__v) {}
682 template<class _CharT, class = _EnableIf<_IsCharLikeType<_CharT>::value> >
683 template<class _CharT, class = __enable_if_t<_IsCharLikeType<_CharT>::value> >
683684 explicit bitset(const _CharT* __str,
684685 typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos,
685686 _CharT __zero = _CharT('0'), _CharT __one = _CharT('1'));
lib/libcxx/include/cassert+1-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===-------------------------- cassert -----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/ccomplex+1-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- ccomplex ---------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/cctype+1-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===---------------------------- cctype ----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/cerrno+1-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===-------------------------- cerrno ------------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/cfenv+1-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===---------------------------- cfenv -----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/cfloat+1-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- cfloat -----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/charconv+46-90
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===------------------------------ charconv ------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -27,10 +27,13 @@ namespace std {
2727 struct to_chars_result {
2828 char* ptr;
2929 errc ec;
30 friend bool operator==(const to_chars_result&, const to_chars_result&) = default; // since C++20
3031 };
3132
3233 to_chars_result to_chars(char* first, char* last, see below value,
3334 int base = 10);
35 to_chars_result to_chars(char* first, char* last, bool value,
36 int base = 10) = delete;
3437
3538 to_chars_result to_chars(char* first, char* last, float value);
3639 to_chars_result to_chars(char* first, char* last, double value);
......@@ -54,6 +57,7 @@ namespace std {
5457 struct from_chars_result {
5558 const char* ptr;
5659 errc ec;
60 friend bool operator==(const from_chars_result&, const from_chars_result&) = default; // since C++20
5761 };
5862
5963 from_chars_result from_chars(const char* first, const char* last,
......@@ -74,9 +78,12 @@ namespace std {
7478*/
7579
7680#include <__availability>
81#include <__bits>
82#include <__charconv/chars_format.h>
83#include <__charconv/from_chars_result.h>
84#include <__charconv/to_chars_result.h>
7785#include <__config>
7886#include <__errc>
79#include <__utility/to_underlying.h>
8087#include <cmath> // for log2f
8188#include <cstdint>
8289#include <cstdlib> // for _LIBCPP_UNREACHABLE
......@@ -98,73 +105,12 @@ _LIBCPP_BEGIN_NAMESPACE_STD
98105namespace __itoa {
99106_LIBCPP_AVAILABILITY_TO_CHARS _LIBCPP_FUNC_VIS char* __u64toa(uint64_t __value, char* __buffer) _NOEXCEPT;
100107_LIBCPP_AVAILABILITY_TO_CHARS _LIBCPP_FUNC_VIS char* __u32toa(uint32_t __value, char* __buffer) _NOEXCEPT;
101}
108} // namespace __itoa
102109
103110#ifndef _LIBCPP_CXX03_LANG
104111
105enum class _LIBCPP_ENUM_VIS chars_format
106{
107 scientific = 0x1,
108 fixed = 0x2,
109 hex = 0x4,
110 general = fixed | scientific
111};
112
113inline _LIBCPP_INLINE_VISIBILITY constexpr chars_format
114operator~(chars_format __x) {
115 return chars_format(~_VSTD::__to_underlying(__x));
116}
117
118inline _LIBCPP_INLINE_VISIBILITY constexpr chars_format
119operator&(chars_format __x, chars_format __y) {
120 return chars_format(_VSTD::__to_underlying(__x) &
121 _VSTD::__to_underlying(__y));
122}
123
124inline _LIBCPP_INLINE_VISIBILITY constexpr chars_format
125operator|(chars_format __x, chars_format __y) {
126 return chars_format(_VSTD::__to_underlying(__x) |
127 _VSTD::__to_underlying(__y));
128}
129
130inline _LIBCPP_INLINE_VISIBILITY constexpr chars_format
131operator^(chars_format __x, chars_format __y) {
132 return chars_format(_VSTD::__to_underlying(__x) ^
133 _VSTD::__to_underlying(__y));
134}
135
136inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 chars_format&
137operator&=(chars_format& __x, chars_format __y) {
138 __x = __x & __y;
139 return __x;
140}
141
142inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 chars_format&
143operator|=(chars_format& __x, chars_format __y) {
144 __x = __x | __y;
145 return __x;
146}
147
148inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 chars_format&
149operator^=(chars_format& __x, chars_format __y) {
150 __x = __x ^ __y;
151 return __x;
152}
153
154struct _LIBCPP_TYPE_VIS to_chars_result
155{
156 char* ptr;
157 errc ec;
158};
159
160struct _LIBCPP_TYPE_VIS from_chars_result
161{
162 const char* ptr;
163 errc ec;
164};
165
166void to_chars(char*, char*, bool, int = 10) = delete;
167void from_chars(const char*, const char*, bool, int = 10) = delete;
112to_chars_result to_chars(char*, char*, bool, int = 10) = delete;
113from_chars_result from_chars(const char*, const char*, bool, int = 10) = delete;
168114
169115namespace __itoa
170116{
......@@ -204,13 +150,11 @@ struct _LIBCPP_HIDDEN __traits_base
204150{
205151 using type = uint64_t;
206152
207#if !defined(_LIBCPP_COMPILER_MSVC)
208153 static _LIBCPP_INLINE_VISIBILITY int __width(_Tp __v)
209154 {
210 auto __t = (64 - __builtin_clzll(__v | 1)) * 1233 >> 12;
155 auto __t = (64 - _VSTD::__libcpp_clz(static_cast<type>(__v | 1))) * 1233 >> 12;
211156 return __t - (__v < __pow10_64[__t]) + 1;
212157 }
213#endif
214158
215159 _LIBCPP_AVAILABILITY_TO_CHARS
216160 static _LIBCPP_INLINE_VISIBILITY char* __convert(_Tp __v, char* __p)
......@@ -227,13 +171,11 @@ struct _LIBCPP_HIDDEN
227171{
228172 using type = uint32_t;
229173
230#if !defined(_LIBCPP_COMPILER_MSVC)
231174 static _LIBCPP_INLINE_VISIBILITY int __width(_Tp __v)
232175 {
233 auto __t = (32 - __builtin_clz(__v | 1)) * 1233 >> 12;
176 auto __t = (32 - _VSTD::__libcpp_clz(static_cast<type>(__v | 1))) * 1233 >> 12;
234177 return __t - (__v < __pow10_32[__t]) + 1;
235178 }
236#endif
237179
238180 _LIBCPP_AVAILABILITY_TO_CHARS
239181 static _LIBCPP_INLINE_VISIBILITY char* __convert(_Tp __v, char* __p)
......@@ -354,28 +296,10 @@ __to_chars_itoa(char* __first, char* __last, _Tp __value, false_type)
354296 using __tx = __itoa::__traits<_Tp>;
355297 auto __diff = __last - __first;
356298
357#if !defined(_LIBCPP_COMPILER_MSVC)
358299 if (__tx::digits <= __diff || __tx::__width(__value) <= __diff)
359300 return {__tx::__convert(__value, __first), errc(0)};
360301 else
361302 return {__last, errc::value_too_large};
362#else
363 if (__tx::digits <= __diff)
364 return {__tx::__convert(__value, __first), {}};
365 else
366 {
367 char __buf[__tx::digits];
368 auto __p = __tx::__convert(__value, __buf);
369 auto __len = __p - __buf;
370 if (__len <= __diff)
371 {
372 _VSTD::memcpy(__first, __buf, __len);
373 return {__first + __len, {}};
374 }
375 else
376 return {__last, errc::value_too_large};
377 }
378#endif
379303}
380304
381305template <typename _Tp>
......@@ -674,6 +598,38 @@ from_chars(const char* __first, const char* __last, _Tp& __value, int __base)
674598 return __from_chars_integral(__first, __last, __value, __base);
675599}
676600
601// Floating-point implementation starts here.
602// Unlike the other parts of charconv this is only available in C++17 and newer.
603#if _LIBCPP_STD_VER > 14
604
605_LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT _LIBCPP_FUNC_VIS
606to_chars_result to_chars(char* __first, char* __last, float __value);
607
608_LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT _LIBCPP_FUNC_VIS
609to_chars_result to_chars(char* __first, char* __last, double __value);
610
611_LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT _LIBCPP_FUNC_VIS
612to_chars_result to_chars(char* __first, char* __last, long double __value);
613
614_LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT _LIBCPP_FUNC_VIS
615to_chars_result to_chars(char* __first, char* __last, float __value, chars_format __fmt);
616
617_LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT _LIBCPP_FUNC_VIS
618to_chars_result to_chars(char* __first, char* __last, double __value, chars_format __fmt);
619
620_LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT _LIBCPP_FUNC_VIS
621to_chars_result to_chars(char* __first, char* __last, long double __value, chars_format __fmt);
622
623_LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT _LIBCPP_FUNC_VIS
624to_chars_result to_chars(char* __first, char* __last, float __value, chars_format __fmt, int __precision);
625
626_LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT _LIBCPP_FUNC_VIS
627to_chars_result to_chars(char* __first, char* __last, double __value, chars_format __fmt, int __precision);
628
629_LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT _LIBCPP_FUNC_VIS
630to_chars_result to_chars(char* __first, char* __last, long double __value, chars_format __fmt, int __precision);
631
632# endif // _LIBCPP_STD_VER > 14
677633#endif // _LIBCPP_CXX03_LANG
678634
679635_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/chrono+23-2278
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===---------------------------- chrono ----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -148,11 +148,6 @@ template <class Clock, class Duration1, class Duration2>
148148
149149namespace chrono {
150150
151
152template<class T> struct is_clock; // C++20
153template<class T> inline constexpr bool is_clock_v = is_clock<T>::value; // C++20
154
155
156151// duration arithmetic
157152template <class Rep1, class Period1, class Rep2, class Period2>
158153 constexpr
......@@ -281,19 +276,23 @@ template <class Duration>
281276using sys_seconds = sys_time<seconds>; // C++20
282277using sys_days = sys_time<days>; // C++20
283278
284class utc_clock; // C++20
285
286template <class Duration>
287 using utc_time = time_point<utc_clock, Duration>; // C++20
288using utc_seconds = utc_time<seconds>; // C++20
279class file_clock // C++20
280{
281public:
282 typedef see-below rep;
283 typedef nano period;
284 typedef chrono::duration<rep, period> duration;
285 typedef chrono::time_point<file_clock> time_point;
286 static constexpr bool is_steady = false;
289287
290class tai_clock; // C++20
288 static time_point now() noexcept;
291289
292template <class Duration>
293 using tai_time = time_point<tai_clock, Duration>; // C++20
294using tai_seconds = tai_time<seconds>; // C++20
290 template<class Duration>
291 static sys_time<see-below> to_sys(const file_time<Duration>&);
295292
296class file_clock; // C++20
293 template<class Duration>
294 static file_time<see-below> from_sys(const sys_time<Duration>&);
295};
297296
298297template<class Duration>
299298 using file_time = time_point<file_clock, Duration>; // C++20
......@@ -319,12 +318,6 @@ template<class Duration>
319318using local_seconds = local_time<seconds>;
320319using local_days = local_time<days>;
321320
322// 25.7.9, time_point conversions template<class DestClock, class SourceClock> // C++20
323struct clock_time_conversion;
324
325template<class DestClock, class SourceClock, class Duration>
326 auto clock_cast(const time_point<SourceClock, Duration>& t);
327
328321// 25.8.2, class last_spec // C++20
329322struct last_spec;
330323
......@@ -639,39 +632,12 @@ public:
639632 constexpr precision to_duration() const noexcept;
640633};
641634
642template <class charT, class traits, class Duration>
643 basic_ostream<charT, traits>&
644 operator<<(basic_ostream<charT, traits>& os, hh_mm_ss<Duration> const& hms);
645
646635// 26.10, 12/24 hour functions
647636constexpr bool is_am(hours const& h) noexcept;
648637constexpr bool is_pm(hours const& h) noexcept;
649638constexpr hours make12(const hours& h) noexcept;
650639constexpr hours make24(const hours& h, bool is_pm) noexcept;
651640
652
653// 25.10.2, time zone database // C++20
654struct tzdb;
655class tzdb_list;
656
657// 25.10.2.3, time zone database access // C++20
658const tzdb& get_tzdb();
659tzdb_list& get_tzdb_list();
660const time_zone* locate_zone(string_view tz_name);
661const time_zone* current_zone();
662
663// 25.10.2.4, remote time zone database support // C++20
664const tzdb& reload_tzdb();
665string remote_version();
666
667// 25.10.3, exception classes // C++20
668class nonexistent_local_time;
669class ambiguous_local_time;
670
671// 25.10.4, information classes // C++20
672struct sys_info;
673struct local_info;
674
675641// 25.10.5, class time_zone // C++20
676642enum class choose {earliest, latest};
677643class time_zone;
......@@ -682,101 +648,6 @@ bool operator>(const time_zone& x, const time_zone& y) noexcept;
682648bool operator<=(const time_zone& x, const time_zone& y) noexcept;
683649bool operator>=(const time_zone& x, const time_zone& y) noexcept;
684650
685// 25.10.6, class template zoned_traits // C++20
686template<class T> struct zoned_traits;
687
688// 25.10.7, class template zoned_time // C++20
689template<class Duration, class TimeZonePtr = const time_zone*> class zoned_time;
690using zoned_seconds = zoned_time<seconds>;
691
692template<class Duration1, class Duration2, class TimeZonePtr>
693 bool operator==(const zoned_time<Duration1, TimeZonePtr>& x,
694 const zoned_time<Duration2, TimeZonePtr>& y);
695template<class Duration1, class Duration2, class TimeZonePtr>
696 bool operator!=(const zoned_time<Duration1, TimeZonePtr>& x,
697 const zoned_time<Duration2, TimeZonePtr>& y);
698
699// 25.10.8, leap second support // C++20
700class leap;
701
702bool operator==(const leap& x, const leap& y);
703bool operator!=(const leap& x, const leap& y);
704bool operator< (const leap& x, const leap& y);
705bool operator> (const leap& x, const leap& y);
706bool operator<=(const leap& x, const leap& y);
707bool operator>=(const leap& x, const leap& y);
708template<class Duration>
709 bool operator==(const leap& x, const sys_time<Duration>& y);
710template<class Duration>
711 bool operator==(const sys_time<Duration>& x, const leap& y);
712template<class Duration>
713 bool operator!=(const leap& x, const sys_time<Duration>& y);
714template<class Duration>
715 bool operator!=(const sys_time<Duration>& x, const leap& y);
716template<class Duration>
717 bool operator< (const leap& x, const sys_time<Duration>& y);
718template<class Duration>
719 bool operator< (const sys_time<Duration>& x, const leap& y);
720template<class Duration>
721 bool operator> (const leap& x, const sys_time<Duration>& y);
722template<class Duration>
723 bool operator> (const sys_time<Duration>& x, const leap& y);
724template<class Duration>
725 bool operator<=(const leap& x, const sys_time<Duration>& y);
726template<class Duration>
727 bool operator<=(const sys_time<Duration>& x, const leap& y);
728template<class Duration>
729 bool operator>=(const leap& x, const sys_time<Duration>& y);
730template<class Duration>
731 bool operator>=(const sys_time<Duration>& x, const leap& y);
732
733// 25.10.9, class link // C++20
734class link;
735bool operator==(const link& x, const link& y);
736bool operator!=(const link& x, const link& y);
737bool operator< (const link& x, const link& y);
738bool operator> (const link& x, const link& y);
739bool operator<=(const link& x, const link& y);
740bool operator>=(const link& x, const link& y);
741
742// 25.11, formatting // C++20
743template<class charT, class Streamable>
744 basic_string<charT>
745 format(const charT* fmt, const Streamable& s);
746
747template<class charT, class Streamable>
748 basic_string<charT>
749 format(const locale& loc, const charT* fmt, const Streamable& s);
750
751template<class charT, class traits, class Alloc, class Streamable>
752 basic_string<charT, traits, Alloc>
753 format(const basic_string<charT, traits, Alloc>& fmt, const Streamable& s);
754
755template<class charT, class traits, class Alloc, class Streamable>
756 basic_string<charT, traits, Alloc>
757 format(const locale& loc, const basic_string<charT, traits, Alloc>& fmt,
758 const Streamable& s);
759
760// 25.12, parsing // C++20
761template<class charT, class traits, class Alloc, class Parsable>
762unspecified
763 parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp);
764
765template<class charT, class traits, class Alloc, class Parsable>
766unspecified
767 parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp,
768 basic_string<charT, traits, Alloc>& abbrev);
769
770template<class charT, class traits, class Alloc, class Parsable>
771unspecified
772 parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp,
773 minutes& offset);
774
775template<class charT, class traits, class Alloc, class Parsable>
776unspecified
777 parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp,
778 basic_string<charT, traits, Alloc>& abbrev, minutes& offset);
779
780651// calendrical constants
781652inline constexpr last_spec last{}; // C++20
782653inline constexpr chrono::weekday Sunday{0}; // C++20
......@@ -823,2146 +694,20 @@ constexpr chrono::year operator ""y(unsigned lo
823694} // std
824695*/
825696
826#include <__availability>
697#include <__chrono/calendar.h>
698#include <__chrono/convert_to_timespec.h>
699#include <__chrono/duration.h>
700#include <__chrono/file_clock.h>
701#include <__chrono/high_resolution_clock.h>
702#include <__chrono/steady_clock.h>
703#include <__chrono/system_clock.h>
704#include <__chrono/time_point.h>
827705#include <__config>
828706#include <compare>
829#include <ctime>
830#include <limits>
831#include <ratio>
832#include <type_traits>
833707#include <version>
834708
835709#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
836710#pragma GCC system_header
837711#endif
838712
839_LIBCPP_PUSH_MACROS
840#include <__undef_macros>
841
842#ifndef _LIBCPP_CXX03_LANG
843_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
844struct _FilesystemClock;
845_LIBCPP_END_NAMESPACE_FILESYSTEM
846#endif // !_LIBCPP_CXX03_LANG
847
848_LIBCPP_BEGIN_NAMESPACE_STD
849
850namespace chrono
851{
852
853template <class _Rep, class _Period = ratio<1> > class _LIBCPP_TEMPLATE_VIS duration;
854
855template <class _Tp>
856struct __is_duration : false_type {};
857
858template <class _Rep, class _Period>
859struct __is_duration<duration<_Rep, _Period> > : true_type {};
860
861template <class _Rep, class _Period>
862struct __is_duration<const duration<_Rep, _Period> > : true_type {};
863
864template <class _Rep, class _Period>
865struct __is_duration<volatile duration<_Rep, _Period> > : true_type {};
866
867template <class _Rep, class _Period>
868struct __is_duration<const volatile duration<_Rep, _Period> > : true_type {};
869
870} // chrono
871
872template <class _Rep1, class _Period1, class _Rep2, class _Period2>
873struct _LIBCPP_TEMPLATE_VIS common_type<chrono::duration<_Rep1, _Period1>,
874 chrono::duration<_Rep2, _Period2> >
875{
876 typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type,
877 typename __ratio_gcd<_Period1, _Period2>::type> type;
878};
879
880namespace chrono {
881
882// duration_cast
883
884template <class _FromDuration, class _ToDuration,
885 class _Period = typename ratio_divide<typename _FromDuration::period, typename _ToDuration::period>::type,
886 bool = _Period::num == 1,
887 bool = _Period::den == 1>
888struct __duration_cast;
889
890template <class _FromDuration, class _ToDuration, class _Period>
891struct __duration_cast<_FromDuration, _ToDuration, _Period, true, true>
892{
893 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
894 _ToDuration operator()(const _FromDuration& __fd) const
895 {
896 return _ToDuration(static_cast<typename _ToDuration::rep>(__fd.count()));
897 }
898};
899
900template <class _FromDuration, class _ToDuration, class _Period>
901struct __duration_cast<_FromDuration, _ToDuration, _Period, true, false>
902{
903 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
904 _ToDuration operator()(const _FromDuration& __fd) const
905 {
906 typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
907 return _ToDuration(static_cast<typename _ToDuration::rep>(
908 static_cast<_Ct>(__fd.count()) / static_cast<_Ct>(_Period::den)));
909 }
910};
911
912template <class _FromDuration, class _ToDuration, class _Period>
913struct __duration_cast<_FromDuration, _ToDuration, _Period, false, true>
914{
915 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
916 _ToDuration operator()(const _FromDuration& __fd) const
917 {
918 typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
919 return _ToDuration(static_cast<typename _ToDuration::rep>(
920 static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num)));
921 }
922};
923
924template <class _FromDuration, class _ToDuration, class _Period>
925struct __duration_cast<_FromDuration, _ToDuration, _Period, false, false>
926{
927 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
928 _ToDuration operator()(const _FromDuration& __fd) const
929 {
930 typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
931 return _ToDuration(static_cast<typename _ToDuration::rep>(
932 static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num)
933 / static_cast<_Ct>(_Period::den)));
934 }
935};
936
937template <class _ToDuration, class _Rep, class _Period>
938inline _LIBCPP_INLINE_VISIBILITY
939_LIBCPP_CONSTEXPR
940typename enable_if
941<
942 __is_duration<_ToDuration>::value,
943 _ToDuration
944>::type
945duration_cast(const duration<_Rep, _Period>& __fd)
946{
947 return __duration_cast<duration<_Rep, _Period>, _ToDuration>()(__fd);
948}
949
950template <class _Rep>
951struct _LIBCPP_TEMPLATE_VIS treat_as_floating_point : is_floating_point<_Rep> {};
952
953#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
954template <class _Rep>
955_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool treat_as_floating_point_v
956 = treat_as_floating_point<_Rep>::value;
957#endif
958
959template <class _Rep>
960struct _LIBCPP_TEMPLATE_VIS duration_values
961{
962public:
963 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep zero() _NOEXCEPT {return _Rep(0);}
964 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep max() _NOEXCEPT {return numeric_limits<_Rep>::max();}
965 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep min() _NOEXCEPT {return numeric_limits<_Rep>::lowest();}
966};
967
968#if _LIBCPP_STD_VER > 14
969template <class _ToDuration, class _Rep, class _Period>
970inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
971typename enable_if
972<
973 __is_duration<_ToDuration>::value,
974 _ToDuration
975>::type
976floor(const duration<_Rep, _Period>& __d)
977{
978 _ToDuration __t = duration_cast<_ToDuration>(__d);
979 if (__t > __d)
980 __t = __t - _ToDuration{1};
981 return __t;
982}
983
984template <class _ToDuration, class _Rep, class _Period>
985inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
986typename enable_if
987<
988 __is_duration<_ToDuration>::value,
989 _ToDuration
990>::type
991ceil(const duration<_Rep, _Period>& __d)
992{
993 _ToDuration __t = duration_cast<_ToDuration>(__d);
994 if (__t < __d)
995 __t = __t + _ToDuration{1};
996 return __t;
997}
998
999template <class _ToDuration, class _Rep, class _Period>
1000inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
1001typename enable_if
1002<
1003 __is_duration<_ToDuration>::value,
1004 _ToDuration
1005>::type
1006round(const duration<_Rep, _Period>& __d)
1007{
1008 _ToDuration __lower = floor<_ToDuration>(__d);
1009 _ToDuration __upper = __lower + _ToDuration{1};
1010 auto __lowerDiff = __d - __lower;
1011 auto __upperDiff = __upper - __d;
1012 if (__lowerDiff < __upperDiff)
1013 return __lower;
1014 if (__lowerDiff > __upperDiff)
1015 return __upper;
1016 return __lower.count() & 1 ? __upper : __lower;
1017}
1018#endif
1019
1020// duration
1021
1022template <class _Rep, class _Period>
1023class _LIBCPP_TEMPLATE_VIS duration
1024{
1025 static_assert(!__is_duration<_Rep>::value, "A duration representation can not be a duration");
1026 static_assert(__is_ratio<_Period>::value, "Second template parameter of duration must be a std::ratio");
1027 static_assert(_Period::num > 0, "duration period must be positive");
1028
1029 template <class _R1, class _R2>
1030 struct __no_overflow
1031 {
1032 private:
1033 static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value;
1034 static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value;
1035 static const intmax_t __n1 = _R1::num / __gcd_n1_n2;
1036 static const intmax_t __d1 = _R1::den / __gcd_d1_d2;
1037 static const intmax_t __n2 = _R2::num / __gcd_n1_n2;
1038 static const intmax_t __d2 = _R2::den / __gcd_d1_d2;
1039 static const intmax_t max = -((intmax_t(1) << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1);
1040
1041 template <intmax_t _Xp, intmax_t _Yp, bool __overflow>
1042 struct __mul // __overflow == false
1043 {
1044 static const intmax_t value = _Xp * _Yp;
1045 };
1046
1047 template <intmax_t _Xp, intmax_t _Yp>
1048 struct __mul<_Xp, _Yp, true>
1049 {
1050 static const intmax_t value = 1;
1051 };
1052
1053 public:
1054 static const bool value = (__n1 <= max / __d2) && (__n2 <= max / __d1);
1055 typedef ratio<__mul<__n1, __d2, !value>::value,
1056 __mul<__n2, __d1, !value>::value> type;
1057 };
1058
1059public:
1060 typedef _Rep rep;
1061 typedef typename _Period::type period;
1062private:
1063 rep __rep_;
1064public:
1065
1066 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
1067#ifndef _LIBCPP_CXX03_LANG
1068 duration() = default;
1069#else
1070 duration() {}
1071#endif
1072
1073 template <class _Rep2>
1074 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
1075 explicit duration(const _Rep2& __r,
1076 typename enable_if
1077 <
1078 is_convertible<_Rep2, rep>::value &&
1079 (treat_as_floating_point<rep>::value ||
1080 !treat_as_floating_point<_Rep2>::value)
1081 >::type* = nullptr)
1082 : __rep_(__r) {}
1083
1084 // conversions
1085 template <class _Rep2, class _Period2>
1086 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
1087 duration(const duration<_Rep2, _Period2>& __d,
1088 typename enable_if
1089 <
1090 __no_overflow<_Period2, period>::value && (
1091 treat_as_floating_point<rep>::value ||
1092 (__no_overflow<_Period2, period>::type::den == 1 &&
1093 !treat_as_floating_point<_Rep2>::value))
1094 >::type* = nullptr)
1095 : __rep_(chrono::duration_cast<duration>(__d).count()) {}
1096
1097 // observer
1098
1099 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR rep count() const {return __rep_;}
1100
1101 // arithmetic
1102
1103 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type<duration>::type operator+() const {return typename common_type<duration>::type(*this);}
1104 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type<duration>::type operator-() const {return typename common_type<duration>::type(-__rep_);}
1105 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator++() {++__rep_; return *this;}
1106 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration operator++(int) {return duration(__rep_++);}
1107 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator--() {--__rep_; return *this;}
1108 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration operator--(int) {return duration(__rep_--);}
1109
1110 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator+=(const duration& __d) {__rep_ += __d.count(); return *this;}
1111 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator-=(const duration& __d) {__rep_ -= __d.count(); return *this;}
1112
1113 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator*=(const rep& rhs) {__rep_ *= rhs; return *this;}
1114 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator/=(const rep& rhs) {__rep_ /= rhs; return *this;}
1115 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator%=(const rep& rhs) {__rep_ %= rhs; return *this;}
1116 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator%=(const duration& rhs) {__rep_ %= rhs.count(); return *this;}
1117
1118 // special values
1119
1120 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration zero() _NOEXCEPT {return duration(duration_values<rep>::zero());}
1121 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration min() _NOEXCEPT {return duration(duration_values<rep>::min());}
1122 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration max() _NOEXCEPT {return duration(duration_values<rep>::max());}
1123};
1124
1125typedef duration<long long, nano> nanoseconds;
1126typedef duration<long long, micro> microseconds;
1127typedef duration<long long, milli> milliseconds;
1128typedef duration<long long > seconds;
1129typedef duration< long, ratio< 60> > minutes;
1130typedef duration< long, ratio<3600> > hours;
1131#if _LIBCPP_STD_VER > 17
1132typedef duration< int, ratio_multiply<ratio<24>, hours::period>> days;
1133typedef duration< int, ratio_multiply<ratio<7>, days::period>> weeks;
1134typedef duration< int, ratio_multiply<ratio<146097, 400>, days::period>> years;
1135typedef duration< int, ratio_divide<years::period, ratio<12>>> months;
1136#endif
1137// Duration ==
1138
1139template <class _LhsDuration, class _RhsDuration>
1140struct __duration_eq
1141{
1142 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
1143 bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const
1144 {
1145 typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
1146 return _Ct(__lhs).count() == _Ct(__rhs).count();
1147 }
1148};
1149
1150template <class _LhsDuration>
1151struct __duration_eq<_LhsDuration, _LhsDuration>
1152{
1153 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
1154 bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const
1155 {return __lhs.count() == __rhs.count();}
1156};
1157
1158template <class _Rep1, class _Period1, class _Rep2, class _Period2>
1159inline _LIBCPP_INLINE_VISIBILITY
1160_LIBCPP_CONSTEXPR
1161bool
1162operator==(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
1163{
1164 return __duration_eq<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
1165}
1166
1167// Duration !=
1168
1169template <class _Rep1, class _Period1, class _Rep2, class _Period2>
1170inline _LIBCPP_INLINE_VISIBILITY
1171_LIBCPP_CONSTEXPR
1172bool
1173operator!=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
1174{
1175 return !(__lhs == __rhs);
1176}
1177
1178// Duration <
1179
1180template <class _LhsDuration, class _RhsDuration>
1181struct __duration_lt
1182{
1183 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
1184 bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const
1185 {
1186 typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
1187 return _Ct(__lhs).count() < _Ct(__rhs).count();
1188 }
1189};
1190
1191template <class _LhsDuration>
1192struct __duration_lt<_LhsDuration, _LhsDuration>
1193{
1194 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
1195 bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const
1196 {return __lhs.count() < __rhs.count();}
1197};
1198
1199template <class _Rep1, class _Period1, class _Rep2, class _Period2>
1200inline _LIBCPP_INLINE_VISIBILITY
1201_LIBCPP_CONSTEXPR
1202bool
1203operator< (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
1204{
1205 return __duration_lt<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
1206}
1207
1208// Duration >
1209
1210template <class _Rep1, class _Period1, class _Rep2, class _Period2>
1211inline _LIBCPP_INLINE_VISIBILITY
1212_LIBCPP_CONSTEXPR
1213bool
1214operator> (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
1215{
1216 return __rhs < __lhs;
1217}
1218
1219// Duration <=
1220
1221template <class _Rep1, class _Period1, class _Rep2, class _Period2>
1222inline _LIBCPP_INLINE_VISIBILITY
1223_LIBCPP_CONSTEXPR
1224bool
1225operator<=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
1226{
1227 return !(__rhs < __lhs);
1228}
1229
1230// Duration >=
1231
1232template <class _Rep1, class _Period1, class _Rep2, class _Period2>
1233inline _LIBCPP_INLINE_VISIBILITY
1234_LIBCPP_CONSTEXPR
1235bool
1236operator>=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
1237{
1238 return !(__lhs < __rhs);
1239}
1240
1241// Duration +
1242
1243template <class _Rep1, class _Period1, class _Rep2, class _Period2>
1244inline _LIBCPP_INLINE_VISIBILITY
1245_LIBCPP_CONSTEXPR
1246typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
1247operator+(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
1248{
1249 typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
1250 return _Cd(_Cd(__lhs).count() + _Cd(__rhs).count());
1251}
1252
1253// Duration -
1254
1255template <class _Rep1, class _Period1, class _Rep2, class _Period2>
1256inline _LIBCPP_INLINE_VISIBILITY
1257_LIBCPP_CONSTEXPR
1258typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
1259operator-(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
1260{
1261 typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
1262 return _Cd(_Cd(__lhs).count() - _Cd(__rhs).count());
1263}
1264
1265// Duration *
1266
1267template <class _Rep1, class _Period, class _Rep2>
1268inline _LIBCPP_INLINE_VISIBILITY
1269_LIBCPP_CONSTEXPR
1270typename enable_if
1271<
1272 is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value,
1273 duration<typename common_type<_Rep1, _Rep2>::type, _Period>
1274>::type
1275operator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
1276{
1277 typedef typename common_type<_Rep1, _Rep2>::type _Cr;
1278 typedef duration<_Cr, _Period> _Cd;
1279 return _Cd(_Cd(__d).count() * static_cast<_Cr>(__s));
1280}
1281
1282template <class _Rep1, class _Period, class _Rep2>
1283inline _LIBCPP_INLINE_VISIBILITY
1284_LIBCPP_CONSTEXPR
1285typename enable_if
1286<
1287 is_convertible<_Rep1, typename common_type<_Rep1, _Rep2>::type>::value,
1288 duration<typename common_type<_Rep1, _Rep2>::type, _Period>
1289>::type
1290operator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d)
1291{
1292 return __d * __s;
1293}
1294
1295// Duration /
1296
1297template <class _Rep1, class _Period, class _Rep2>
1298inline _LIBCPP_INLINE_VISIBILITY
1299_LIBCPP_CONSTEXPR
1300typename enable_if
1301<
1302 !__is_duration<_Rep2>::value &&
1303 is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value,
1304 duration<typename common_type<_Rep1, _Rep2>::type, _Period>
1305>::type
1306operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
1307{
1308 typedef typename common_type<_Rep1, _Rep2>::type _Cr;
1309 typedef duration<_Cr, _Period> _Cd;
1310 return _Cd(_Cd(__d).count() / static_cast<_Cr>(__s));
1311}
1312
1313template <class _Rep1, class _Period1, class _Rep2, class _Period2>
1314inline _LIBCPP_INLINE_VISIBILITY
1315_LIBCPP_CONSTEXPR
1316typename common_type<_Rep1, _Rep2>::type
1317operator/(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
1318{
1319 typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Ct;
1320 return _Ct(__lhs).count() / _Ct(__rhs).count();
1321}
1322
1323// Duration %
1324
1325template <class _Rep1, class _Period, class _Rep2>
1326inline _LIBCPP_INLINE_VISIBILITY
1327_LIBCPP_CONSTEXPR
1328typename enable_if
1329<
1330 !__is_duration<_Rep2>::value &&
1331 is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value,
1332 duration<typename common_type<_Rep1, _Rep2>::type, _Period>
1333>::type
1334operator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
1335{
1336 typedef typename common_type<_Rep1, _Rep2>::type _Cr;
1337 typedef duration<_Cr, _Period> _Cd;
1338 return _Cd(_Cd(__d).count() % static_cast<_Cr>(__s));
1339}
1340
1341template <class _Rep1, class _Period1, class _Rep2, class _Period2>
1342inline _LIBCPP_INLINE_VISIBILITY
1343_LIBCPP_CONSTEXPR
1344typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
1345operator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
1346{
1347 typedef typename common_type<_Rep1, _Rep2>::type _Cr;
1348 typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
1349 return _Cd(static_cast<_Cr>(_Cd(__lhs).count()) % static_cast<_Cr>(_Cd(__rhs).count()));
1350}
1351
1352//////////////////////////////////////////////////////////
1353///////////////////// time_point /////////////////////////
1354//////////////////////////////////////////////////////////
1355
1356template <class _Clock, class _Duration = typename _Clock::duration>
1357class _LIBCPP_TEMPLATE_VIS time_point
1358{
1359 static_assert(__is_duration<_Duration>::value,
1360 "Second template parameter of time_point must be a std::chrono::duration");
1361public:
1362 typedef _Clock clock;
1363 typedef _Duration duration;
1364 typedef typename duration::rep rep;
1365 typedef typename duration::period period;
1366private:
1367 duration __d_;
1368
1369public:
1370 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point() : __d_(duration::zero()) {}
1371 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit time_point(const duration& __d) : __d_(__d) {}
1372
1373 // conversions
1374 template <class _Duration2>
1375 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1376 time_point(const time_point<clock, _Duration2>& t,
1377 typename enable_if
1378 <
1379 is_convertible<_Duration2, duration>::value
1380 >::type* = nullptr)
1381 : __d_(t.time_since_epoch()) {}
1382
1383 // observer
1384
1385 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 duration time_since_epoch() const {return __d_;}
1386
1387 // arithmetic
1388
1389 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 time_point& operator+=(const duration& __d) {__d_ += __d; return *this;}
1390 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 time_point& operator-=(const duration& __d) {__d_ -= __d; return *this;}
1391
1392 // special values
1393
1394 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point min() _NOEXCEPT {return time_point(duration::min());}
1395 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point max() _NOEXCEPT {return time_point(duration::max());}
1396};
1397
1398} // chrono
1399
1400template <class _Clock, class _Duration1, class _Duration2>
1401struct _LIBCPP_TEMPLATE_VIS common_type<chrono::time_point<_Clock, _Duration1>,
1402 chrono::time_point<_Clock, _Duration2> >
1403{
1404 typedef chrono::time_point<_Clock, typename common_type<_Duration1, _Duration2>::type> type;
1405};
1406
1407namespace chrono {
1408
1409template <class _ToDuration, class _Clock, class _Duration>
1410inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1411time_point<_Clock, _ToDuration>
1412time_point_cast(const time_point<_Clock, _Duration>& __t)
1413{
1414 return time_point<_Clock, _ToDuration>(chrono::duration_cast<_ToDuration>(__t.time_since_epoch()));
1415}
1416
1417#if _LIBCPP_STD_VER > 14
1418template <class _ToDuration, class _Clock, class _Duration>
1419inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
1420typename enable_if
1421<
1422 __is_duration<_ToDuration>::value,
1423 time_point<_Clock, _ToDuration>
1424>::type
1425floor(const time_point<_Clock, _Duration>& __t)
1426{
1427 return time_point<_Clock, _ToDuration>{floor<_ToDuration>(__t.time_since_epoch())};
1428}
1429
1430template <class _ToDuration, class _Clock, class _Duration>
1431inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
1432typename enable_if
1433<
1434 __is_duration<_ToDuration>::value,
1435 time_point<_Clock, _ToDuration>
1436>::type
1437ceil(const time_point<_Clock, _Duration>& __t)
1438{
1439 return time_point<_Clock, _ToDuration>{ceil<_ToDuration>(__t.time_since_epoch())};
1440}
1441
1442template <class _ToDuration, class _Clock, class _Duration>
1443inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
1444typename enable_if
1445<
1446 __is_duration<_ToDuration>::value,
1447 time_point<_Clock, _ToDuration>
1448>::type
1449round(const time_point<_Clock, _Duration>& __t)
1450{
1451 return time_point<_Clock, _ToDuration>{round<_ToDuration>(__t.time_since_epoch())};
1452}
1453
1454template <class _Rep, class _Period>
1455inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
1456typename enable_if
1457<
1458 numeric_limits<_Rep>::is_signed,
1459 duration<_Rep, _Period>
1460>::type
1461abs(duration<_Rep, _Period> __d)
1462{
1463 return __d >= __d.zero() ? +__d : -__d;
1464}
1465#endif
1466
1467// time_point ==
1468
1469template <class _Clock, class _Duration1, class _Duration2>
1470inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1471bool
1472operator==(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
1473{
1474 return __lhs.time_since_epoch() == __rhs.time_since_epoch();
1475}
1476
1477// time_point !=
1478
1479template <class _Clock, class _Duration1, class _Duration2>
1480inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1481bool
1482operator!=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
1483{
1484 return !(__lhs == __rhs);
1485}
1486
1487// time_point <
1488
1489template <class _Clock, class _Duration1, class _Duration2>
1490inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1491bool
1492operator<(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
1493{
1494 return __lhs.time_since_epoch() < __rhs.time_since_epoch();
1495}
1496
1497// time_point >
1498
1499template <class _Clock, class _Duration1, class _Duration2>
1500inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1501bool
1502operator>(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
1503{
1504 return __rhs < __lhs;
1505}
1506
1507// time_point <=
1508
1509template <class _Clock, class _Duration1, class _Duration2>
1510inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1511bool
1512operator<=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
1513{
1514 return !(__rhs < __lhs);
1515}
1516
1517// time_point >=
1518
1519template <class _Clock, class _Duration1, class _Duration2>
1520inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1521bool
1522operator>=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
1523{
1524 return !(__lhs < __rhs);
1525}
1526
1527// time_point operator+(time_point x, duration y);
1528
1529template <class _Clock, class _Duration1, class _Rep2, class _Period2>
1530inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1531time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
1532operator+(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
1533{
1534 typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Tr;
1535 return _Tr (__lhs.time_since_epoch() + __rhs);
1536}
1537
1538// time_point operator+(duration x, time_point y);
1539
1540template <class _Rep1, class _Period1, class _Clock, class _Duration2>
1541inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1542time_point<_Clock, typename common_type<duration<_Rep1, _Period1>, _Duration2>::type>
1543operator+(const duration<_Rep1, _Period1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
1544{
1545 return __rhs + __lhs;
1546}
1547
1548// time_point operator-(time_point x, duration y);
1549
1550template <class _Clock, class _Duration1, class _Rep2, class _Period2>
1551inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1552time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
1553operator-(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
1554{
1555 typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Ret;
1556 return _Ret(__lhs.time_since_epoch() -__rhs);
1557}
1558
1559// duration operator-(time_point x, time_point y);
1560
1561template <class _Clock, class _Duration1, class _Duration2>
1562inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1563typename common_type<_Duration1, _Duration2>::type
1564operator-(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
1565{
1566 return __lhs.time_since_epoch() - __rhs.time_since_epoch();
1567}
1568
1569//////////////////////////////////////////////////////////
1570/////////////////////// clocks ///////////////////////////
1571//////////////////////////////////////////////////////////
1572
1573class _LIBCPP_TYPE_VIS system_clock
1574{
1575public:
1576 typedef microseconds duration;
1577 typedef duration::rep rep;
1578 typedef duration::period period;
1579 typedef chrono::time_point<system_clock> time_point;
1580 static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false;
1581
1582 static time_point now() _NOEXCEPT;
1583 static time_t to_time_t (const time_point& __t) _NOEXCEPT;
1584 static time_point from_time_t(time_t __t) _NOEXCEPT;
1585};
1586
1587#ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK
1588class _LIBCPP_TYPE_VIS steady_clock
1589{
1590public:
1591 typedef nanoseconds duration;
1592 typedef duration::rep rep;
1593 typedef duration::period period;
1594 typedef chrono::time_point<steady_clock, duration> time_point;
1595 static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = true;
1596
1597 static time_point now() _NOEXCEPT;
1598};
1599
1600typedef steady_clock high_resolution_clock;
1601#else
1602typedef system_clock high_resolution_clock;
1603#endif
1604
1605#if _LIBCPP_STD_VER > 17
1606// [time.clock.file], type file_clock
1607using file_clock = _VSTD_FS::_FilesystemClock;
1608
1609template<class _Duration>
1610using file_time = time_point<file_clock, _Duration>;
1611
1612
1613template <class _Duration>
1614using sys_time = time_point<system_clock, _Duration>;
1615using sys_seconds = sys_time<seconds>;
1616using sys_days = sys_time<days>;
1617
1618struct local_t {};
1619template<class Duration>
1620using local_time = time_point<local_t, Duration>;
1621using local_seconds = local_time<seconds>;
1622using local_days = local_time<days>;
1623
1624
1625struct last_spec { explicit last_spec() = default; };
1626
1627class day {
1628private:
1629 unsigned char __d;
1630public:
1631 day() = default;
1632 explicit inline constexpr day(unsigned __val) noexcept : __d(static_cast<unsigned char>(__val)) {}
1633 inline constexpr day& operator++() noexcept { ++__d; return *this; }
1634 inline constexpr day operator++(int) noexcept { day __tmp = *this; ++(*this); return __tmp; }
1635 inline constexpr day& operator--() noexcept { --__d; return *this; }
1636 inline constexpr day operator--(int) noexcept { day __tmp = *this; --(*this); return __tmp; }
1637 constexpr day& operator+=(const days& __dd) noexcept;
1638 constexpr day& operator-=(const days& __dd) noexcept;
1639 explicit inline constexpr operator unsigned() const noexcept { return __d; }
1640 inline constexpr bool ok() const noexcept { return __d >= 1 && __d <= 31; }
1641 };
1642
1643
1644inline constexpr
1645bool operator==(const day& __lhs, const day& __rhs) noexcept
1646{ return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); }
1647
1648inline constexpr
1649bool operator!=(const day& __lhs, const day& __rhs) noexcept
1650{ return !(__lhs == __rhs); }
1651
1652inline constexpr
1653bool operator< (const day& __lhs, const day& __rhs) noexcept
1654{ return static_cast<unsigned>(__lhs) < static_cast<unsigned>(__rhs); }
1655
1656inline constexpr
1657bool operator> (const day& __lhs, const day& __rhs) noexcept
1658{ return __rhs < __lhs; }
1659
1660inline constexpr
1661bool operator<=(const day& __lhs, const day& __rhs) noexcept
1662{ return !(__rhs < __lhs);}
1663
1664inline constexpr
1665bool operator>=(const day& __lhs, const day& __rhs) noexcept
1666{ return !(__lhs < __rhs); }
1667
1668inline constexpr
1669day operator+ (const day& __lhs, const days& __rhs) noexcept
1670{ return day(static_cast<unsigned>(__lhs) + __rhs.count()); }
1671
1672inline constexpr
1673day operator+ (const days& __lhs, const day& __rhs) noexcept
1674{ return __rhs + __lhs; }
1675
1676inline constexpr
1677day operator- (const day& __lhs, const days& __rhs) noexcept
1678{ return __lhs + -__rhs; }
1679
1680inline constexpr
1681days operator-(const day& __lhs, const day& __rhs) noexcept
1682{ return days(static_cast<int>(static_cast<unsigned>(__lhs)) -
1683 static_cast<int>(static_cast<unsigned>(__rhs))); }
1684
1685inline constexpr day& day::operator+=(const days& __dd) noexcept
1686{ *this = *this + __dd; return *this; }
1687
1688inline constexpr day& day::operator-=(const days& __dd) noexcept
1689{ *this = *this - __dd; return *this; }
1690
1691
1692class month {
1693private:
1694 unsigned char __m;
1695public:
1696 month() = default;
1697 explicit inline constexpr month(unsigned __val) noexcept : __m(static_cast<unsigned char>(__val)) {}
1698 inline constexpr month& operator++() noexcept { ++__m; return *this; }
1699 inline constexpr month operator++(int) noexcept { month __tmp = *this; ++(*this); return __tmp; }
1700 inline constexpr month& operator--() noexcept { --__m; return *this; }
1701 inline constexpr month operator--(int) noexcept { month __tmp = *this; --(*this); return __tmp; }
1702 constexpr month& operator+=(const months& __m1) noexcept;
1703 constexpr month& operator-=(const months& __m1) noexcept;
1704 explicit inline constexpr operator unsigned() const noexcept { return __m; }
1705 inline constexpr bool ok() const noexcept { return __m >= 1 && __m <= 12; }
1706};
1707
1708
1709inline constexpr
1710bool operator==(const month& __lhs, const month& __rhs) noexcept
1711{ return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); }
1712
1713inline constexpr
1714bool operator!=(const month& __lhs, const month& __rhs) noexcept
1715{ return !(__lhs == __rhs); }
1716
1717inline constexpr
1718bool operator< (const month& __lhs, const month& __rhs) noexcept
1719{ return static_cast<unsigned>(__lhs) < static_cast<unsigned>(__rhs); }
1720
1721inline constexpr
1722bool operator> (const month& __lhs, const month& __rhs) noexcept
1723{ return __rhs < __lhs; }
1724
1725inline constexpr
1726bool operator<=(const month& __lhs, const month& __rhs) noexcept
1727{ return !(__rhs < __lhs); }
1728
1729inline constexpr
1730bool operator>=(const month& __lhs, const month& __rhs) noexcept
1731{ return !(__lhs < __rhs); }
1732
1733inline constexpr
1734month operator+ (const month& __lhs, const months& __rhs) noexcept
1735{
1736 auto const __mu = static_cast<long long>(static_cast<unsigned>(__lhs)) + (__rhs.count() - 1);
1737 auto const __yr = (__mu >= 0 ? __mu : __mu - 11) / 12;
1738 return month{static_cast<unsigned>(__mu - __yr * 12 + 1)};
1739}
1740
1741inline constexpr
1742month operator+ (const months& __lhs, const month& __rhs) noexcept
1743{ return __rhs + __lhs; }
1744
1745inline constexpr
1746month operator- (const month& __lhs, const months& __rhs) noexcept
1747{ return __lhs + -__rhs; }
1748
1749inline constexpr
1750months operator-(const month& __lhs, const month& __rhs) noexcept
1751{
1752 auto const __dm = static_cast<unsigned>(__lhs) - static_cast<unsigned>(__rhs);
1753 return months(__dm <= 11 ? __dm : __dm + 12);
1754}
1755
1756inline constexpr month& month::operator+=(const months& __dm) noexcept
1757{ *this = *this + __dm; return *this; }
1758
1759inline constexpr month& month::operator-=(const months& __dm) noexcept
1760{ *this = *this - __dm; return *this; }
1761
1762
1763class year {
1764private:
1765 short __y;
1766public:
1767 year() = default;
1768 explicit inline constexpr year(int __val) noexcept : __y(static_cast<short>(__val)) {}
1769
1770 inline constexpr year& operator++() noexcept { ++__y; return *this; }
1771 inline constexpr year operator++(int) noexcept { year __tmp = *this; ++(*this); return __tmp; }
1772 inline constexpr year& operator--() noexcept { --__y; return *this; }
1773 inline constexpr year operator--(int) noexcept { year __tmp = *this; --(*this); return __tmp; }
1774 constexpr year& operator+=(const years& __dy) noexcept;
1775 constexpr year& operator-=(const years& __dy) noexcept;
1776 inline constexpr year operator+() const noexcept { return *this; }
1777 inline constexpr year operator-() const noexcept { return year{-__y}; }
1778
1779 inline constexpr bool is_leap() const noexcept { return __y % 4 == 0 && (__y % 100 != 0 || __y % 400 == 0); }
1780 explicit inline constexpr operator int() const noexcept { return __y; }
1781 constexpr bool ok() const noexcept;
1782 static inline constexpr year min() noexcept { return year{-32767}; }
1783 static inline constexpr year max() noexcept { return year{ 32767}; }
1784};
1785
1786
1787inline constexpr
1788bool operator==(const year& __lhs, const year& __rhs) noexcept
1789{ return static_cast<int>(__lhs) == static_cast<int>(__rhs); }
1790
1791inline constexpr
1792bool operator!=(const year& __lhs, const year& __rhs) noexcept
1793{ return !(__lhs == __rhs); }
1794
1795inline constexpr
1796bool operator< (const year& __lhs, const year& __rhs) noexcept
1797{ return static_cast<int>(__lhs) < static_cast<int>(__rhs); }
1798
1799inline constexpr
1800bool operator> (const year& __lhs, const year& __rhs) noexcept
1801{ return __rhs < __lhs; }
1802
1803inline constexpr
1804bool operator<=(const year& __lhs, const year& __rhs) noexcept
1805{ return !(__rhs < __lhs); }
1806
1807inline constexpr
1808bool operator>=(const year& __lhs, const year& __rhs) noexcept
1809{ return !(__lhs < __rhs); }
1810
1811inline constexpr
1812year operator+ (const year& __lhs, const years& __rhs) noexcept
1813{ return year(static_cast<int>(__lhs) + __rhs.count()); }
1814
1815inline constexpr
1816year operator+ (const years& __lhs, const year& __rhs) noexcept
1817{ return __rhs + __lhs; }
1818
1819inline constexpr
1820year operator- (const year& __lhs, const years& __rhs) noexcept
1821{ return __lhs + -__rhs; }
1822
1823inline constexpr
1824years operator-(const year& __lhs, const year& __rhs) noexcept
1825{ return years{static_cast<int>(__lhs) - static_cast<int>(__rhs)}; }
1826
1827
1828inline constexpr year& year::operator+=(const years& __dy) noexcept
1829{ *this = *this + __dy; return *this; }
1830
1831inline constexpr year& year::operator-=(const years& __dy) noexcept
1832{ *this = *this - __dy; return *this; }
1833
1834inline constexpr bool year::ok() const noexcept
1835{ return static_cast<int>(min()) <= __y && __y <= static_cast<int>(max()); }
1836
1837class weekday_indexed;
1838class weekday_last;
1839
1840class weekday {
1841private:
1842 unsigned char __wd;
1843public:
1844 weekday() = default;
1845 inline explicit constexpr weekday(unsigned __val) noexcept : __wd(static_cast<unsigned char>(__val == 7 ? 0 : __val)) {}
1846 inline constexpr weekday(const sys_days& __sysd) noexcept
1847 : __wd(__weekday_from_days(__sysd.time_since_epoch().count())) {}
1848 inline explicit constexpr weekday(const local_days& __locd) noexcept
1849 : __wd(__weekday_from_days(__locd.time_since_epoch().count())) {}
1850
1851 inline constexpr weekday& operator++() noexcept { __wd = (__wd == 6 ? 0 : __wd + 1); return *this; }
1852 inline constexpr weekday operator++(int) noexcept { weekday __tmp = *this; ++(*this); return __tmp; }
1853 inline constexpr weekday& operator--() noexcept { __wd = (__wd == 0 ? 6 : __wd - 1); return *this; }
1854 inline constexpr weekday operator--(int) noexcept { weekday __tmp = *this; --(*this); return __tmp; }
1855 constexpr weekday& operator+=(const days& __dd) noexcept;
1856 constexpr weekday& operator-=(const days& __dd) noexcept;
1857 inline constexpr unsigned c_encoding() const noexcept { return __wd; }
1858 inline constexpr unsigned iso_encoding() const noexcept { return __wd == 0u ? 7 : __wd; }
1859 inline constexpr bool ok() const noexcept { return __wd <= 6; }
1860 constexpr weekday_indexed operator[](unsigned __index) const noexcept;
1861 constexpr weekday_last operator[](last_spec) const noexcept;
1862
1863 // TODO: Make private?
1864 static constexpr unsigned char __weekday_from_days(int __days) noexcept;
1865};
1866
1867
1868// https://howardhinnant.github.io/date_algorithms.html#weekday_from_days
1869inline constexpr
1870unsigned char weekday::__weekday_from_days(int __days) noexcept
1871{
1872 return static_cast<unsigned char>(
1873 static_cast<unsigned>(__days >= -4 ? (__days+4) % 7 : (__days+5) % 7 + 6)
1874 );
1875}
1876
1877inline constexpr
1878bool operator==(const weekday& __lhs, const weekday& __rhs) noexcept
1879{ return __lhs.c_encoding() == __rhs.c_encoding(); }
1880
1881inline constexpr
1882bool operator!=(const weekday& __lhs, const weekday& __rhs) noexcept
1883{ return !(__lhs == __rhs); }
1884
1885inline constexpr
1886bool operator< (const weekday& __lhs, const weekday& __rhs) noexcept
1887{ return __lhs.c_encoding() < __rhs.c_encoding(); }
1888
1889inline constexpr
1890bool operator> (const weekday& __lhs, const weekday& __rhs) noexcept
1891{ return __rhs < __lhs; }
1892
1893inline constexpr
1894bool operator<=(const weekday& __lhs, const weekday& __rhs) noexcept
1895{ return !(__rhs < __lhs);}
1896
1897inline constexpr
1898bool operator>=(const weekday& __lhs, const weekday& __rhs) noexcept
1899{ return !(__lhs < __rhs); }
1900
1901constexpr weekday operator+(const weekday& __lhs, const days& __rhs) noexcept
1902{
1903 auto const __mu = static_cast<long long>(__lhs.c_encoding()) + __rhs.count();
1904 auto const __yr = (__mu >= 0 ? __mu : __mu - 6) / 7;
1905 return weekday{static_cast<unsigned>(__mu - __yr * 7)};
1906}
1907
1908constexpr weekday operator+(const days& __lhs, const weekday& __rhs) noexcept
1909{ return __rhs + __lhs; }
1910
1911constexpr weekday operator-(const weekday& __lhs, const days& __rhs) noexcept
1912{ return __lhs + -__rhs; }
1913
1914constexpr days operator-(const weekday& __lhs, const weekday& __rhs) noexcept
1915{
1916 const int __wdu = __lhs.c_encoding() - __rhs.c_encoding();
1917 const int __wk = (__wdu >= 0 ? __wdu : __wdu-6) / 7;
1918 return days{__wdu - __wk * 7};
1919}
1920
1921inline constexpr weekday& weekday::operator+=(const days& __dd) noexcept
1922{ *this = *this + __dd; return *this; }
1923
1924inline constexpr weekday& weekday::operator-=(const days& __dd) noexcept
1925{ *this = *this - __dd; return *this; }
1926
1927
1928class weekday_indexed {
1929private:
1930 chrono::weekday __wd;
1931 unsigned char __idx;
1932public:
1933 weekday_indexed() = default;
1934 inline constexpr weekday_indexed(const chrono::weekday& __wdval, unsigned __idxval) noexcept
1935 : __wd{__wdval}, __idx(__idxval) {}
1936 inline constexpr chrono::weekday weekday() const noexcept { return __wd; }
1937 inline constexpr unsigned index() const noexcept { return __idx; }
1938 inline constexpr bool ok() const noexcept { return __wd.ok() && __idx >= 1 && __idx <= 5; }
1939};
1940
1941inline constexpr
1942bool operator==(const weekday_indexed& __lhs, const weekday_indexed& __rhs) noexcept
1943{ return __lhs.weekday() == __rhs.weekday() && __lhs.index() == __rhs.index(); }
1944
1945inline constexpr
1946bool operator!=(const weekday_indexed& __lhs, const weekday_indexed& __rhs) noexcept
1947{ return !(__lhs == __rhs); }
1948
1949
1950class weekday_last {
1951private:
1952 chrono::weekday __wd;
1953public:
1954 explicit constexpr weekday_last(const chrono::weekday& __val) noexcept
1955 : __wd{__val} {}
1956 constexpr chrono::weekday weekday() const noexcept { return __wd; }
1957 constexpr bool ok() const noexcept { return __wd.ok(); }
1958};
1959
1960inline constexpr
1961bool operator==(const weekday_last& __lhs, const weekday_last& __rhs) noexcept
1962{ return __lhs.weekday() == __rhs.weekday(); }
1963
1964inline constexpr
1965bool operator!=(const weekday_last& __lhs, const weekday_last& __rhs) noexcept
1966{ return !(__lhs == __rhs); }
1967
1968inline constexpr
1969weekday_indexed weekday::operator[](unsigned __index) const noexcept { return weekday_indexed{*this, __index}; }
1970
1971inline constexpr
1972weekday_last weekday::operator[](last_spec) const noexcept { return weekday_last{*this}; }
1973
1974
1975inline constexpr last_spec last{};
1976inline constexpr weekday Sunday{0};
1977inline constexpr weekday Monday{1};
1978inline constexpr weekday Tuesday{2};
1979inline constexpr weekday Wednesday{3};
1980inline constexpr weekday Thursday{4};
1981inline constexpr weekday Friday{5};
1982inline constexpr weekday Saturday{6};
1983
1984inline constexpr month January{1};
1985inline constexpr month February{2};
1986inline constexpr month March{3};
1987inline constexpr month April{4};
1988inline constexpr month May{5};
1989inline constexpr month June{6};
1990inline constexpr month July{7};
1991inline constexpr month August{8};
1992inline constexpr month September{9};
1993inline constexpr month October{10};
1994inline constexpr month November{11};
1995inline constexpr month December{12};
1996
1997
1998class month_day {
1999private:
2000 chrono::month __m;
2001 chrono::day __d;
2002public:
2003 month_day() = default;
2004 constexpr month_day(const chrono::month& __mval, const chrono::day& __dval) noexcept
2005 : __m{__mval}, __d{__dval} {}
2006 inline constexpr chrono::month month() const noexcept { return __m; }
2007 inline constexpr chrono::day day() const noexcept { return __d; }
2008 constexpr bool ok() const noexcept;
2009};
2010
2011inline constexpr
2012bool month_day::ok() const noexcept
2013{
2014 if (!__m.ok()) return false;
2015 const unsigned __dval = static_cast<unsigned>(__d);
2016 if (__dval < 1 || __dval > 31) return false;
2017 if (__dval <= 29) return true;
2018// Now we've got either 30 or 31
2019 const unsigned __mval = static_cast<unsigned>(__m);
2020 if (__mval == 2) return false;
2021 if (__mval == 4 || __mval == 6 || __mval == 9 || __mval == 11)
2022 return __dval == 30;
2023 return true;
2024}
2025
2026inline constexpr
2027bool operator==(const month_day& __lhs, const month_day& __rhs) noexcept
2028{ return __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); }
2029
2030inline constexpr
2031bool operator!=(const month_day& __lhs, const month_day& __rhs) noexcept
2032{ return !(__lhs == __rhs); }
2033
2034inline constexpr
2035month_day operator/(const month& __lhs, const day& __rhs) noexcept
2036{ return month_day{__lhs, __rhs}; }
2037
2038constexpr
2039month_day operator/(const day& __lhs, const month& __rhs) noexcept
2040{ return __rhs / __lhs; }
2041
2042inline constexpr
2043month_day operator/(const month& __lhs, int __rhs) noexcept
2044{ return __lhs / day(__rhs); }
2045
2046constexpr
2047month_day operator/(int __lhs, const day& __rhs) noexcept
2048{ return month(__lhs) / __rhs; }
2049
2050constexpr
2051month_day operator/(const day& __lhs, int __rhs) noexcept
2052{ return month(__rhs) / __lhs; }
2053
2054
2055inline constexpr
2056bool operator< (const month_day& __lhs, const month_day& __rhs) noexcept
2057{ return __lhs.month() != __rhs.month() ? __lhs.month() < __rhs.month() : __lhs.day() < __rhs.day(); }
2058
2059inline constexpr
2060bool operator> (const month_day& __lhs, const month_day& __rhs) noexcept
2061{ return __rhs < __lhs; }
2062
2063inline constexpr
2064bool operator<=(const month_day& __lhs, const month_day& __rhs) noexcept
2065{ return !(__rhs < __lhs);}
2066
2067inline constexpr
2068bool operator>=(const month_day& __lhs, const month_day& __rhs) noexcept
2069{ return !(__lhs < __rhs); }
2070
2071
2072
2073class month_day_last {
2074private:
2075 chrono::month __m;
2076public:
2077 explicit constexpr month_day_last(const chrono::month& __val) noexcept
2078 : __m{__val} {}
2079 inline constexpr chrono::month month() const noexcept { return __m; }
2080 inline constexpr bool ok() const noexcept { return __m.ok(); }
2081};
2082
2083inline constexpr
2084bool operator==(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
2085{ return __lhs.month() == __rhs.month(); }
2086
2087inline constexpr
2088bool operator!=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
2089{ return !(__lhs == __rhs); }
2090
2091inline constexpr
2092bool operator< (const month_day_last& __lhs, const month_day_last& __rhs) noexcept
2093{ return __lhs.month() < __rhs.month(); }
2094
2095inline constexpr
2096bool operator> (const month_day_last& __lhs, const month_day_last& __rhs) noexcept
2097{ return __rhs < __lhs; }
2098
2099inline constexpr
2100bool operator<=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
2101{ return !(__rhs < __lhs);}
2102
2103inline constexpr
2104bool operator>=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
2105{ return !(__lhs < __rhs); }
2106
2107inline constexpr
2108month_day_last operator/(const month& __lhs, last_spec) noexcept
2109{ return month_day_last{__lhs}; }
2110
2111inline constexpr
2112month_day_last operator/(last_spec, const month& __rhs) noexcept
2113{ return month_day_last{__rhs}; }
2114
2115inline constexpr
2116month_day_last operator/(int __lhs, last_spec) noexcept
2117{ return month_day_last{month(__lhs)}; }
2118
2119inline constexpr
2120month_day_last operator/(last_spec, int __rhs) noexcept
2121{ return month_day_last{month(__rhs)}; }
2122
2123
2124class month_weekday {
2125private:
2126 chrono::month __m;
2127 chrono::weekday_indexed __wdi;
2128public:
2129 month_weekday() = default;
2130 constexpr month_weekday(const chrono::month& __mval, const chrono::weekday_indexed& __wdival) noexcept
2131 : __m{__mval}, __wdi{__wdival} {}
2132 inline constexpr chrono::month month() const noexcept { return __m; }
2133 inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { return __wdi; }
2134 inline constexpr bool ok() const noexcept { return __m.ok() && __wdi.ok(); }
2135};
2136
2137inline constexpr
2138bool operator==(const month_weekday& __lhs, const month_weekday& __rhs) noexcept
2139{ return __lhs.month() == __rhs.month() && __lhs.weekday_indexed() == __rhs.weekday_indexed(); }
2140
2141inline constexpr
2142bool operator!=(const month_weekday& __lhs, const month_weekday& __rhs) noexcept
2143{ return !(__lhs == __rhs); }
2144
2145inline constexpr
2146month_weekday operator/(const month& __lhs, const weekday_indexed& __rhs) noexcept
2147{ return month_weekday{__lhs, __rhs}; }
2148
2149inline constexpr
2150month_weekday operator/(int __lhs, const weekday_indexed& __rhs) noexcept
2151{ return month_weekday{month(__lhs), __rhs}; }
2152
2153inline constexpr
2154month_weekday operator/(const weekday_indexed& __lhs, const month& __rhs) noexcept
2155{ return month_weekday{__rhs, __lhs}; }
2156
2157inline constexpr
2158month_weekday operator/(const weekday_indexed& __lhs, int __rhs) noexcept
2159{ return month_weekday{month(__rhs), __lhs}; }
2160
2161
2162class month_weekday_last {
2163 chrono::month __m;
2164 chrono::weekday_last __wdl;
2165 public:
2166 constexpr month_weekday_last(const chrono::month& __mval, const chrono::weekday_last& __wdlval) noexcept
2167 : __m{__mval}, __wdl{__wdlval} {}
2168 inline constexpr chrono::month month() const noexcept { return __m; }
2169 inline constexpr chrono::weekday_last weekday_last() const noexcept { return __wdl; }
2170 inline constexpr bool ok() const noexcept { return __m.ok() && __wdl.ok(); }
2171};
2172
2173inline constexpr
2174bool operator==(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noexcept
2175{ return __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last(); }
2176
2177inline constexpr
2178bool operator!=(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noexcept
2179{ return !(__lhs == __rhs); }
2180
2181
2182inline constexpr
2183month_weekday_last operator/(const month& __lhs, const weekday_last& __rhs) noexcept
2184{ return month_weekday_last{__lhs, __rhs}; }
2185
2186inline constexpr
2187month_weekday_last operator/(int __lhs, const weekday_last& __rhs) noexcept
2188{ return month_weekday_last{month(__lhs), __rhs}; }
2189
2190inline constexpr
2191month_weekday_last operator/(const weekday_last& __lhs, const month& __rhs) noexcept
2192{ return month_weekday_last{__rhs, __lhs}; }
2193
2194inline constexpr
2195month_weekday_last operator/(const weekday_last& __lhs, int __rhs) noexcept
2196{ return month_weekday_last{month(__rhs), __lhs}; }
2197
2198
2199class year_month {
2200 chrono::year __y;
2201 chrono::month __m;
2202public:
2203 year_month() = default;
2204 constexpr year_month(const chrono::year& __yval, const chrono::month& __mval) noexcept
2205 : __y{__yval}, __m{__mval} {}
2206 inline constexpr chrono::year year() const noexcept { return __y; }
2207 inline constexpr chrono::month month() const noexcept { return __m; }
2208 inline constexpr year_month& operator+=(const months& __dm) noexcept { this->__m += __dm; return *this; }
2209 inline constexpr year_month& operator-=(const months& __dm) noexcept { this->__m -= __dm; return *this; }
2210 inline constexpr year_month& operator+=(const years& __dy) noexcept { this->__y += __dy; return *this; }
2211 inline constexpr year_month& operator-=(const years& __dy) noexcept { this->__y -= __dy; return *this; }
2212 inline constexpr bool ok() const noexcept { return __y.ok() && __m.ok(); }
2213};
2214
2215inline constexpr
2216year_month operator/(const year& __y, const month& __m) noexcept { return year_month{__y, __m}; }
2217
2218inline constexpr
2219year_month operator/(const year& __y, int __m) noexcept { return year_month{__y, month(__m)}; }
2220
2221inline constexpr
2222bool operator==(const year_month& __lhs, const year_month& __rhs) noexcept
2223{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month(); }
2224
2225inline constexpr
2226bool operator!=(const year_month& __lhs, const year_month& __rhs) noexcept
2227{ return !(__lhs == __rhs); }
2228
2229inline constexpr
2230bool operator< (const year_month& __lhs, const year_month& __rhs) noexcept
2231{ return __lhs.year() != __rhs.year() ? __lhs.year() < __rhs.year() : __lhs.month() < __rhs.month(); }
2232
2233inline constexpr
2234bool operator> (const year_month& __lhs, const year_month& __rhs) noexcept
2235{ return __rhs < __lhs; }
2236
2237inline constexpr
2238bool operator<=(const year_month& __lhs, const year_month& __rhs) noexcept
2239{ return !(__rhs < __lhs);}
2240
2241inline constexpr
2242bool operator>=(const year_month& __lhs, const year_month& __rhs) noexcept
2243{ return !(__lhs < __rhs); }
2244
2245constexpr year_month operator+(const year_month& __lhs, const months& __rhs) noexcept
2246{
2247 int __dmi = static_cast<int>(static_cast<unsigned>(__lhs.month())) - 1 + __rhs.count();
2248 const int __dy = (__dmi >= 0 ? __dmi : __dmi-11) / 12;
2249 __dmi = __dmi - __dy * 12 + 1;
2250 return (__lhs.year() + years(__dy)) / month(static_cast<unsigned>(__dmi));
2251}
2252
2253constexpr year_month operator+(const months& __lhs, const year_month& __rhs) noexcept
2254{ return __rhs + __lhs; }
2255
2256constexpr year_month operator+(const year_month& __lhs, const years& __rhs) noexcept
2257{ return (__lhs.year() + __rhs) / __lhs.month(); }
2258
2259constexpr year_month operator+(const years& __lhs, const year_month& __rhs) noexcept
2260{ return __rhs + __lhs; }
2261
2262constexpr months operator-(const year_month& __lhs, const year_month& __rhs) noexcept
2263{ return (__lhs.year() - __rhs.year()) + months(static_cast<unsigned>(__lhs.month()) - static_cast<unsigned>(__rhs.month())); }
2264
2265constexpr year_month operator-(const year_month& __lhs, const months& __rhs) noexcept
2266{ return __lhs + -__rhs; }
2267
2268constexpr year_month operator-(const year_month& __lhs, const years& __rhs) noexcept
2269{ return __lhs + -__rhs; }
2270
2271class year_month_day_last;
2272
2273class year_month_day {
2274private:
2275 chrono::year __y;
2276 chrono::month __m;
2277 chrono::day __d;
2278public:
2279 year_month_day() = default;
2280 inline constexpr year_month_day(
2281 const chrono::year& __yval, const chrono::month& __mval, const chrono::day& __dval) noexcept
2282 : __y{__yval}, __m{__mval}, __d{__dval} {}
2283 constexpr year_month_day(const year_month_day_last& __ymdl) noexcept;
2284 inline constexpr year_month_day(const sys_days& __sysd) noexcept
2285 : year_month_day(__from_days(__sysd.time_since_epoch())) {}
2286 inline explicit constexpr year_month_day(const local_days& __locd) noexcept
2287 : year_month_day(__from_days(__locd.time_since_epoch())) {}
2288
2289 constexpr year_month_day& operator+=(const months& __dm) noexcept;
2290 constexpr year_month_day& operator-=(const months& __dm) noexcept;
2291 constexpr year_month_day& operator+=(const years& __dy) noexcept;
2292 constexpr year_month_day& operator-=(const years& __dy) noexcept;
2293
2294 inline constexpr chrono::year year() const noexcept { return __y; }
2295 inline constexpr chrono::month month() const noexcept { return __m; }
2296 inline constexpr chrono::day day() const noexcept { return __d; }
2297 inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; }
2298 inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; }
2299
2300 constexpr bool ok() const noexcept;
2301
2302 static constexpr year_month_day __from_days(days __d) noexcept;
2303 constexpr days __to_days() const noexcept;
2304};
2305
2306
2307// https://howardhinnant.github.io/date_algorithms.html#civil_from_days
2308inline constexpr
2309year_month_day
2310year_month_day::__from_days(days __d) noexcept
2311{
2312 static_assert(numeric_limits<unsigned>::digits >= 18, "");
2313 static_assert(numeric_limits<int>::digits >= 20 , "");
2314 const int __z = __d.count() + 719468;
2315 const int __era = (__z >= 0 ? __z : __z - 146096) / 146097;
2316 const unsigned __doe = static_cast<unsigned>(__z - __era * 146097); // [0, 146096]
2317 const unsigned __yoe = (__doe - __doe/1460 + __doe/36524 - __doe/146096) / 365; // [0, 399]
2318 const int __yr = static_cast<int>(__yoe) + __era * 400;
2319 const unsigned __doy = __doe - (365 * __yoe + __yoe/4 - __yoe/100); // [0, 365]
2320 const unsigned __mp = (5 * __doy + 2)/153; // [0, 11]
2321 const unsigned __dy = __doy - (153 * __mp + 2)/5 + 1; // [1, 31]
2322 const unsigned __mth = __mp + (__mp < 10 ? 3 : -9); // [1, 12]
2323 return year_month_day{chrono::year{__yr + (__mth <= 2)}, chrono::month{__mth}, chrono::day{__dy}};
2324}
2325
2326// https://howardhinnant.github.io/date_algorithms.html#days_from_civil
2327inline constexpr days year_month_day::__to_days() const noexcept
2328{
2329 static_assert(numeric_limits<unsigned>::digits >= 18, "");
2330 static_assert(numeric_limits<int>::digits >= 20 , "");
2331
2332 const int __yr = static_cast<int>(__y) - (__m <= February);
2333 const unsigned __mth = static_cast<unsigned>(__m);
2334 const unsigned __dy = static_cast<unsigned>(__d);
2335
2336 const int __era = (__yr >= 0 ? __yr : __yr - 399) / 400;
2337 const unsigned __yoe = static_cast<unsigned>(__yr - __era * 400); // [0, 399]
2338 const unsigned __doy = (153 * (__mth + (__mth > 2 ? -3 : 9)) + 2) / 5 + __dy-1; // [0, 365]
2339 const unsigned __doe = __yoe * 365 + __yoe/4 - __yoe/100 + __doy; // [0, 146096]
2340 return days{__era * 146097 + static_cast<int>(__doe) - 719468};
2341}
2342
2343inline constexpr
2344bool operator==(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
2345{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); }
2346
2347inline constexpr
2348bool operator!=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
2349{ return !(__lhs == __rhs); }
2350
2351inline constexpr
2352bool operator< (const year_month_day& __lhs, const year_month_day& __rhs) noexcept
2353{
2354 if (__lhs.year() < __rhs.year()) return true;
2355 if (__lhs.year() > __rhs.year()) return false;
2356 if (__lhs.month() < __rhs.month()) return true;
2357 if (__lhs.month() > __rhs.month()) return false;
2358 return __lhs.day() < __rhs.day();
2359}
2360
2361inline constexpr
2362bool operator> (const year_month_day& __lhs, const year_month_day& __rhs) noexcept
2363{ return __rhs < __lhs; }
2364
2365inline constexpr
2366bool operator<=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
2367{ return !(__rhs < __lhs);}
2368
2369inline constexpr
2370bool operator>=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
2371{ return !(__lhs < __rhs); }
2372
2373inline constexpr
2374year_month_day operator/(const year_month& __lhs, const day& __rhs) noexcept
2375{ return year_month_day{__lhs.year(), __lhs.month(), __rhs}; }
2376
2377inline constexpr
2378year_month_day operator/(const year_month& __lhs, int __rhs) noexcept
2379{ return __lhs / day(__rhs); }
2380
2381inline constexpr
2382year_month_day operator/(const year& __lhs, const month_day& __rhs) noexcept
2383{ return __lhs / __rhs.month() / __rhs.day(); }
2384
2385inline constexpr
2386year_month_day operator/(int __lhs, const month_day& __rhs) noexcept
2387{ return year(__lhs) / __rhs; }
2388
2389inline constexpr
2390year_month_day operator/(const month_day& __lhs, const year& __rhs) noexcept
2391{ return __rhs / __lhs; }
2392
2393inline constexpr
2394year_month_day operator/(const month_day& __lhs, int __rhs) noexcept
2395{ return year(__rhs) / __lhs; }
2396
2397
2398inline constexpr
2399year_month_day operator+(const year_month_day& __lhs, const months& __rhs) noexcept
2400{ return (__lhs.year()/__lhs.month() + __rhs)/__lhs.day(); }
2401
2402inline constexpr
2403year_month_day operator+(const months& __lhs, const year_month_day& __rhs) noexcept
2404{ return __rhs + __lhs; }
2405
2406inline constexpr
2407year_month_day operator-(const year_month_day& __lhs, const months& __rhs) noexcept
2408{ return __lhs + -__rhs; }
2409
2410inline constexpr
2411year_month_day operator+(const year_month_day& __lhs, const years& __rhs) noexcept
2412{ return (__lhs.year() + __rhs) / __lhs.month() / __lhs.day(); }
2413
2414inline constexpr
2415year_month_day operator+(const years& __lhs, const year_month_day& __rhs) noexcept
2416{ return __rhs + __lhs; }
2417
2418inline constexpr
2419year_month_day operator-(const year_month_day& __lhs, const years& __rhs) noexcept
2420{ return __lhs + -__rhs; }
2421
2422inline constexpr year_month_day& year_month_day::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
2423inline constexpr year_month_day& year_month_day::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
2424inline constexpr year_month_day& year_month_day::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; }
2425inline constexpr year_month_day& year_month_day::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; }
2426
2427class year_month_day_last {
2428private:
2429 chrono::year __y;
2430 chrono::month_day_last __mdl;
2431public:
2432 constexpr year_month_day_last(const year& __yval, const month_day_last& __mdlval) noexcept
2433 : __y{__yval}, __mdl{__mdlval} {}
2434
2435 constexpr year_month_day_last& operator+=(const months& __m) noexcept;
2436 constexpr year_month_day_last& operator-=(const months& __m) noexcept;
2437 constexpr year_month_day_last& operator+=(const years& __y) noexcept;
2438 constexpr year_month_day_last& operator-=(const years& __y) noexcept;
2439
2440 inline constexpr chrono::year year() const noexcept { return __y; }
2441 inline constexpr chrono::month month() const noexcept { return __mdl.month(); }
2442 inline constexpr chrono::month_day_last month_day_last() const noexcept { return __mdl; }
2443 constexpr chrono::day day() const noexcept;
2444 inline constexpr operator sys_days() const noexcept { return sys_days{year()/month()/day()}; }
2445 inline explicit constexpr operator local_days() const noexcept { return local_days{year()/month()/day()}; }
2446 inline constexpr bool ok() const noexcept { return __y.ok() && __mdl.ok(); }
2447};
2448
2449inline constexpr
2450chrono::day year_month_day_last::day() const noexcept
2451{
2452 constexpr chrono::day __d[] =
2453 {
2454 chrono::day(31), chrono::day(28), chrono::day(31),
2455 chrono::day(30), chrono::day(31), chrono::day(30),
2456 chrono::day(31), chrono::day(31), chrono::day(30),
2457 chrono::day(31), chrono::day(30), chrono::day(31)
2458 };
2459 return (month() != February || !__y.is_leap()) && month().ok() ?
2460 __d[static_cast<unsigned>(month()) - 1] : chrono::day{29};
2461}
2462
2463inline constexpr
2464bool operator==(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
2465{ return __lhs.year() == __rhs.year() && __lhs.month_day_last() == __rhs.month_day_last(); }
2466
2467inline constexpr
2468bool operator!=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
2469{ return !(__lhs == __rhs); }
2470
2471inline constexpr
2472bool operator< (const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
2473{
2474 if (__lhs.year() < __rhs.year()) return true;
2475 if (__lhs.year() > __rhs.year()) return false;
2476 return __lhs.month_day_last() < __rhs.month_day_last();
2477}
2478
2479inline constexpr
2480bool operator> (const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
2481{ return __rhs < __lhs; }
2482
2483inline constexpr
2484bool operator<=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
2485{ return !(__rhs < __lhs);}
2486
2487inline constexpr
2488bool operator>=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
2489{ return !(__lhs < __rhs); }
2490
2491inline constexpr year_month_day_last operator/(const year_month& __lhs, last_spec) noexcept
2492{ return year_month_day_last{__lhs.year(), month_day_last{__lhs.month()}}; }
2493
2494inline constexpr year_month_day_last operator/(const year& __lhs, const month_day_last& __rhs) noexcept
2495{ return year_month_day_last{__lhs, __rhs}; }
2496
2497inline constexpr year_month_day_last operator/(int __lhs, const month_day_last& __rhs) noexcept
2498{ return year_month_day_last{year{__lhs}, __rhs}; }
2499
2500inline constexpr year_month_day_last operator/(const month_day_last& __lhs, const year& __rhs) noexcept
2501{ return __rhs / __lhs; }
2502
2503inline constexpr year_month_day_last operator/(const month_day_last& __lhs, int __rhs) noexcept
2504{ return year{__rhs} / __lhs; }
2505
2506
2507inline constexpr
2508year_month_day_last operator+(const year_month_day_last& __lhs, const months& __rhs) noexcept
2509{ return (__lhs.year() / __lhs.month() + __rhs) / last; }
2510
2511inline constexpr
2512year_month_day_last operator+(const months& __lhs, const year_month_day_last& __rhs) noexcept
2513{ return __rhs + __lhs; }
2514
2515inline constexpr
2516year_month_day_last operator-(const year_month_day_last& __lhs, const months& __rhs) noexcept
2517{ return __lhs + (-__rhs); }
2518
2519inline constexpr
2520year_month_day_last operator+(const year_month_day_last& __lhs, const years& __rhs) noexcept
2521{ return year_month_day_last{__lhs.year() + __rhs, __lhs.month_day_last()}; }
2522
2523inline constexpr
2524year_month_day_last operator+(const years& __lhs, const year_month_day_last& __rhs) noexcept
2525{ return __rhs + __lhs; }
2526
2527inline constexpr
2528year_month_day_last operator-(const year_month_day_last& __lhs, const years& __rhs) noexcept
2529{ return __lhs + (-__rhs); }
2530
2531inline constexpr year_month_day_last& year_month_day_last::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
2532inline constexpr year_month_day_last& year_month_day_last::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
2533inline constexpr year_month_day_last& year_month_day_last::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; }
2534inline constexpr year_month_day_last& year_month_day_last::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; }
2535
2536inline constexpr year_month_day::year_month_day(const year_month_day_last& __ymdl) noexcept
2537 : __y{__ymdl.year()}, __m{__ymdl.month()}, __d{__ymdl.day()} {}
2538
2539inline constexpr bool year_month_day::ok() const noexcept
2540{
2541 if (!__y.ok() || !__m.ok()) return false;
2542 return chrono::day{1} <= __d && __d <= (__y / __m / last).day();
2543}
2544
2545class year_month_weekday {
2546 chrono::year __y;
2547 chrono::month __m;
2548 chrono::weekday_indexed __wdi;
2549public:
2550 year_month_weekday() = default;
2551 constexpr year_month_weekday(const chrono::year& __yval, const chrono::month& __mval,
2552 const chrono::weekday_indexed& __wdival) noexcept
2553 : __y{__yval}, __m{__mval}, __wdi{__wdival} {}
2554 constexpr year_month_weekday(const sys_days& __sysd) noexcept
2555 : year_month_weekday(__from_days(__sysd.time_since_epoch())) {}
2556 inline explicit constexpr year_month_weekday(const local_days& __locd) noexcept
2557 : year_month_weekday(__from_days(__locd.time_since_epoch())) {}
2558 constexpr year_month_weekday& operator+=(const months& m) noexcept;
2559 constexpr year_month_weekday& operator-=(const months& m) noexcept;
2560 constexpr year_month_weekday& operator+=(const years& y) noexcept;
2561 constexpr year_month_weekday& operator-=(const years& y) noexcept;
2562
2563 inline constexpr chrono::year year() const noexcept { return __y; }
2564 inline constexpr chrono::month month() const noexcept { return __m; }
2565 inline constexpr chrono::weekday weekday() const noexcept { return __wdi.weekday(); }
2566 inline constexpr unsigned index() const noexcept { return __wdi.index(); }
2567 inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { return __wdi; }
2568
2569 inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; }
2570 inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; }
2571 inline constexpr bool ok() const noexcept
2572 {
2573 if (!__y.ok() || !__m.ok() || !__wdi.ok()) return false;
2574 if (__wdi.index() <= 4) return true;
2575 auto __nth_weekday_day =
2576 __wdi.weekday() -
2577 chrono::weekday{static_cast<sys_days>(__y / __m / 1)} +
2578 days{(__wdi.index() - 1) * 7 + 1};
2579 return static_cast<unsigned>(__nth_weekday_day.count()) <=
2580 static_cast<unsigned>((__y / __m / last).day());
2581 }
2582
2583 static constexpr year_month_weekday __from_days(days __d) noexcept;
2584 constexpr days __to_days() const noexcept;
2585};
2586
2587inline constexpr
2588year_month_weekday year_month_weekday::__from_days(days __d) noexcept
2589{
2590 const sys_days __sysd{__d};
2591 const chrono::weekday __wd = chrono::weekday(__sysd);
2592 const year_month_day __ymd = year_month_day(__sysd);
2593 return year_month_weekday{__ymd.year(), __ymd.month(),
2594 __wd[(static_cast<unsigned>(__ymd.day())-1)/7+1]};
2595}
2596
2597inline constexpr
2598days year_month_weekday::__to_days() const noexcept
2599{
2600 const sys_days __sysd = sys_days(__y/__m/1);
2601 return (__sysd + (__wdi.weekday() - chrono::weekday(__sysd) + days{(__wdi.index()-1)*7}))
2602 .time_since_epoch();
2603}
2604
2605inline constexpr
2606bool operator==(const year_month_weekday& __lhs, const year_month_weekday& __rhs) noexcept
2607{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.weekday_indexed() == __rhs.weekday_indexed(); }
2608
2609inline constexpr
2610bool operator!=(const year_month_weekday& __lhs, const year_month_weekday& __rhs) noexcept
2611{ return !(__lhs == __rhs); }
2612
2613inline constexpr
2614year_month_weekday operator/(const year_month& __lhs, const weekday_indexed& __rhs) noexcept
2615{ return year_month_weekday{__lhs.year(), __lhs.month(), __rhs}; }
2616
2617inline constexpr
2618year_month_weekday operator/(const year& __lhs, const month_weekday& __rhs) noexcept
2619{ return year_month_weekday{__lhs, __rhs.month(), __rhs.weekday_indexed()}; }
2620
2621inline constexpr
2622year_month_weekday operator/(int __lhs, const month_weekday& __rhs) noexcept
2623{ return year(__lhs) / __rhs; }
2624
2625inline constexpr
2626year_month_weekday operator/(const month_weekday& __lhs, const year& __rhs) noexcept
2627{ return __rhs / __lhs; }
2628
2629inline constexpr
2630year_month_weekday operator/(const month_weekday& __lhs, int __rhs) noexcept
2631{ return year(__rhs) / __lhs; }
2632
2633
2634inline constexpr
2635year_month_weekday operator+(const year_month_weekday& __lhs, const months& __rhs) noexcept
2636{ return (__lhs.year() / __lhs.month() + __rhs) / __lhs.weekday_indexed(); }
2637
2638inline constexpr
2639year_month_weekday operator+(const months& __lhs, const year_month_weekday& __rhs) noexcept
2640{ return __rhs + __lhs; }
2641
2642inline constexpr
2643year_month_weekday operator-(const year_month_weekday& __lhs, const months& __rhs) noexcept
2644{ return __lhs + (-__rhs); }
2645
2646inline constexpr
2647year_month_weekday operator+(const year_month_weekday& __lhs, const years& __rhs) noexcept
2648{ return year_month_weekday{__lhs.year() + __rhs, __lhs.month(), __lhs.weekday_indexed()}; }
2649
2650inline constexpr
2651year_month_weekday operator+(const years& __lhs, const year_month_weekday& __rhs) noexcept
2652{ return __rhs + __lhs; }
2653
2654inline constexpr
2655year_month_weekday operator-(const year_month_weekday& __lhs, const years& __rhs) noexcept
2656{ return __lhs + (-__rhs); }
2657
2658
2659inline constexpr year_month_weekday& year_month_weekday::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
2660inline constexpr year_month_weekday& year_month_weekday::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
2661inline constexpr year_month_weekday& year_month_weekday::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; }
2662inline constexpr year_month_weekday& year_month_weekday::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; }
2663
2664class year_month_weekday_last {
2665private:
2666 chrono::year __y;
2667 chrono::month __m;
2668 chrono::weekday_last __wdl;
2669public:
2670 constexpr year_month_weekday_last(const chrono::year& __yval, const chrono::month& __mval,
2671 const chrono::weekday_last& __wdlval) noexcept
2672 : __y{__yval}, __m{__mval}, __wdl{__wdlval} {}
2673 constexpr year_month_weekday_last& operator+=(const months& __dm) noexcept;
2674 constexpr year_month_weekday_last& operator-=(const months& __dm) noexcept;
2675 constexpr year_month_weekday_last& operator+=(const years& __dy) noexcept;
2676 constexpr year_month_weekday_last& operator-=(const years& __dy) noexcept;
2677
2678 inline constexpr chrono::year year() const noexcept { return __y; }
2679 inline constexpr chrono::month month() const noexcept { return __m; }
2680 inline constexpr chrono::weekday weekday() const noexcept { return __wdl.weekday(); }
2681 inline constexpr chrono::weekday_last weekday_last() const noexcept { return __wdl; }
2682 inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; }
2683 inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; }
2684 inline constexpr bool ok() const noexcept { return __y.ok() && __m.ok() && __wdl.ok(); }
2685
2686 constexpr days __to_days() const noexcept;
2687
2688};
2689
2690inline constexpr
2691days year_month_weekday_last::__to_days() const noexcept
2692{
2693 const sys_days __last = sys_days{__y/__m/last};
2694 return (__last - (chrono::weekday{__last} - __wdl.weekday())).time_since_epoch();
2695
2696}
2697
2698inline constexpr
2699bool operator==(const year_month_weekday_last& __lhs, const year_month_weekday_last& __rhs) noexcept
2700{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last(); }
2701
2702inline constexpr
2703bool operator!=(const year_month_weekday_last& __lhs, const year_month_weekday_last& __rhs) noexcept
2704{ return !(__lhs == __rhs); }
2705
2706
2707inline constexpr
2708year_month_weekday_last operator/(const year_month& __lhs, const weekday_last& __rhs) noexcept
2709{ return year_month_weekday_last{__lhs.year(), __lhs.month(), __rhs}; }
2710
2711inline constexpr
2712year_month_weekday_last operator/(const year& __lhs, const month_weekday_last& __rhs) noexcept
2713{ return year_month_weekday_last{__lhs, __rhs.month(), __rhs.weekday_last()}; }
2714
2715inline constexpr
2716year_month_weekday_last operator/(int __lhs, const month_weekday_last& __rhs) noexcept
2717{ return year(__lhs) / __rhs; }
2718
2719inline constexpr
2720year_month_weekday_last operator/(const month_weekday_last& __lhs, const year& __rhs) noexcept
2721{ return __rhs / __lhs; }
2722
2723inline constexpr
2724year_month_weekday_last operator/(const month_weekday_last& __lhs, int __rhs) noexcept
2725{ return year(__rhs) / __lhs; }
2726
2727
2728inline constexpr
2729year_month_weekday_last operator+(const year_month_weekday_last& __lhs, const months& __rhs) noexcept
2730{ return (__lhs.year() / __lhs.month() + __rhs) / __lhs.weekday_last(); }
2731
2732inline constexpr
2733year_month_weekday_last operator+(const months& __lhs, const year_month_weekday_last& __rhs) noexcept
2734{ return __rhs + __lhs; }
2735
2736inline constexpr
2737year_month_weekday_last operator-(const year_month_weekday_last& __lhs, const months& __rhs) noexcept
2738{ return __lhs + (-__rhs); }
2739
2740inline constexpr
2741year_month_weekday_last operator+(const year_month_weekday_last& __lhs, const years& __rhs) noexcept
2742{ return year_month_weekday_last{__lhs.year() + __rhs, __lhs.month(), __lhs.weekday_last()}; }
2743
2744inline constexpr
2745year_month_weekday_last operator+(const years& __lhs, const year_month_weekday_last& __rhs) noexcept
2746{ return __rhs + __lhs; }
2747
2748inline constexpr
2749year_month_weekday_last operator-(const year_month_weekday_last& __lhs, const years& __rhs) noexcept
2750{ return __lhs + (-__rhs); }
2751
2752inline constexpr year_month_weekday_last& year_month_weekday_last::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
2753inline constexpr year_month_weekday_last& year_month_weekday_last::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
2754inline constexpr year_month_weekday_last& year_month_weekday_last::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; }
2755inline constexpr year_month_weekday_last& year_month_weekday_last::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; }
2756
2757
2758template <class _Duration>
2759class hh_mm_ss
2760{
2761private:
2762 static_assert(__is_duration<_Duration>::value, "template parameter of hh_mm_ss must be a std::chrono::duration");
2763 using __CommonType = common_type_t<_Duration, chrono::seconds>;
2764
2765 static constexpr uint64_t __pow10(unsigned __exp)
2766 {
2767 uint64_t __ret = 1;
2768 for (unsigned __i = 0; __i < __exp; ++__i)
2769 __ret *= 10U;
2770 return __ret;
2771 }
2772
2773 static constexpr unsigned __width(uint64_t __n, uint64_t __d = 10, unsigned __w = 0)
2774 {
2775 if (__n >= 2 && __d != 0 && __w < 19)
2776 return 1 + __width(__n, __d % __n * 10, __w+1);
2777 return 0;
2778 }
2779
2780public:
2781 static unsigned constexpr fractional_width = __width(__CommonType::period::den) < 19 ?
2782 __width(__CommonType::period::den) : 6u;
2783 using precision = duration<typename __CommonType::rep, ratio<1, __pow10(fractional_width)>>;
2784
2785 constexpr hh_mm_ss() noexcept : hh_mm_ss{_Duration::zero()} {}
2786
2787 constexpr explicit hh_mm_ss(_Duration __d) noexcept :
2788 __is_neg(__d < _Duration(0)),
2789 __h(duration_cast<chrono::hours> (abs(__d))),
2790 __m(duration_cast<chrono::minutes>(abs(__d) - hours())),
2791 __s(duration_cast<chrono::seconds>(abs(__d) - hours() - minutes())),
2792 __f(duration_cast<precision> (abs(__d) - hours() - minutes() - seconds()))
2793 {}
2794
2795 constexpr bool is_negative() const noexcept { return __is_neg; }
2796 constexpr chrono::hours hours() const noexcept { return __h; }
2797 constexpr chrono::minutes minutes() const noexcept { return __m; }
2798 constexpr chrono::seconds seconds() const noexcept { return __s; }
2799 constexpr precision subseconds() const noexcept { return __f; }
2800
2801 constexpr precision to_duration() const noexcept
2802 {
2803 auto __dur = __h + __m + __s + __f;
2804 return __is_neg ? -__dur : __dur;
2805 }
2806
2807 constexpr explicit operator precision() const noexcept { return to_duration(); }
2808
2809private:
2810 bool __is_neg;
2811 chrono::hours __h;
2812 chrono::minutes __m;
2813 chrono::seconds __s;
2814 precision __f;
2815};
2816
2817constexpr bool is_am(const hours& __h) noexcept { return __h >= hours( 0) && __h < hours(12); }
2818constexpr bool is_pm(const hours& __h) noexcept { return __h >= hours(12) && __h < hours(24); }
2819
2820constexpr hours make12(const hours& __h) noexcept
2821{
2822 if (__h == hours( 0)) return hours(12);
2823 else if (__h <= hours(12)) return __h;
2824 else return __h - hours(12);
2825}
2826
2827constexpr hours make24(const hours& __h, bool __is_pm) noexcept
2828{
2829 if (__is_pm)
2830 return __h == hours(12) ? __h : __h + hours(12);
2831 else
2832 return __h == hours(12) ? hours(0) : __h;
2833}
2834
2835#endif // _LIBCPP_STD_VER > 17
2836} // chrono
2837
2838#if _LIBCPP_STD_VER > 11
2839// Suffixes for duration literals [time.duration.literals]
2840inline namespace literals
2841{
2842 inline namespace chrono_literals
2843 {
2844
2845 constexpr chrono::hours operator""h(unsigned long long __h)
2846 {
2847 return chrono::hours(static_cast<chrono::hours::rep>(__h));
2848 }
2849
2850 constexpr chrono::duration<long double, ratio<3600,1>> operator""h(long double __h)
2851 {
2852 return chrono::duration<long double, ratio<3600,1>>(__h);
2853 }
2854
2855
2856 constexpr chrono::minutes operator""min(unsigned long long __m)
2857 {
2858 return chrono::minutes(static_cast<chrono::minutes::rep>(__m));
2859 }
2860
2861 constexpr chrono::duration<long double, ratio<60,1>> operator""min(long double __m)
2862 {
2863 return chrono::duration<long double, ratio<60,1>> (__m);
2864 }
2865
2866
2867 constexpr chrono::seconds operator""s(unsigned long long __s)
2868 {
2869 return chrono::seconds(static_cast<chrono::seconds::rep>(__s));
2870 }
2871
2872 constexpr chrono::duration<long double> operator""s(long double __s)
2873 {
2874 return chrono::duration<long double> (__s);
2875 }
2876
2877
2878 constexpr chrono::milliseconds operator""ms(unsigned long long __ms)
2879 {
2880 return chrono::milliseconds(static_cast<chrono::milliseconds::rep>(__ms));
2881 }
2882
2883 constexpr chrono::duration<long double, milli> operator""ms(long double __ms)
2884 {
2885 return chrono::duration<long double, milli>(__ms);
2886 }
2887
2888
2889 constexpr chrono::microseconds operator""us(unsigned long long __us)
2890 {
2891 return chrono::microseconds(static_cast<chrono::microseconds::rep>(__us));
2892 }
2893
2894 constexpr chrono::duration<long double, micro> operator""us(long double __us)
2895 {
2896 return chrono::duration<long double, micro> (__us);
2897 }
2898
2899
2900 constexpr chrono::nanoseconds operator""ns(unsigned long long __ns)
2901 {
2902 return chrono::nanoseconds(static_cast<chrono::nanoseconds::rep>(__ns));
2903 }
2904
2905 constexpr chrono::duration<long double, nano> operator""ns(long double __ns)
2906 {
2907 return chrono::duration<long double, nano> (__ns);
2908 }
2909
2910#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_CHRONO_LITERALS)
2911 constexpr chrono::day operator ""d(unsigned long long __d) noexcept
2912 {
2913 return chrono::day(static_cast<unsigned>(__d));
2914 }
2915
2916 constexpr chrono::year operator ""y(unsigned long long __y) noexcept
2917 {
2918 return chrono::year(static_cast<int>(__y));
2919 }
2920#endif
2921}}
2922
2923namespace chrono { // hoist the literals into namespace std::chrono
2924 using namespace literals::chrono_literals;
2925}
2926
2927#endif
2928
2929_LIBCPP_END_NAMESPACE_STD
2930
2931#ifndef _LIBCPP_CXX03_LANG
2932_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
2933struct _FilesystemClock {
2934#if !defined(_LIBCPP_HAS_NO_INT128)
2935 typedef __int128_t rep;
2936 typedef nano period;
2937#else
2938 typedef long long rep;
2939 typedef nano period;
2940#endif
2941
2942 typedef chrono::duration<rep, period> duration;
2943 typedef chrono::time_point<_FilesystemClock> time_point;
2944
2945 _LIBCPP_EXPORTED_FROM_ABI
2946 static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false;
2947
2948 _LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_FUNC_VIS static time_point now() noexcept;
2949
2950 _LIBCPP_INLINE_VISIBILITY
2951 static time_t to_time_t(const time_point& __t) noexcept {
2952 typedef chrono::duration<rep> __secs;
2953 return time_t(
2954 chrono::duration_cast<__secs>(__t.time_since_epoch()).count());
2955 }
2956
2957 _LIBCPP_INLINE_VISIBILITY
2958 static time_point from_time_t(time_t __t) noexcept {
2959 typedef chrono::duration<rep> __secs;
2960 return time_point(__secs(__t));
2961 }
2962};
2963_LIBCPP_END_NAMESPACE_FILESYSTEM
2964#endif // !_LIBCPP_CXX03_LANG
2965
2966_LIBCPP_POP_MACROS
2967
2968713#endif // _LIBCPP_CHRONO
lib/libcxx/include/cinttypes+1-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- cinttypes --------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/ciso646+1-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- ciso646 ----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/climits+1-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- climits ----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/clocale+1-3
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- clocale ----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -44,9 +44,7 @@ lconv* localeconv();
4444_LIBCPP_BEGIN_NAMESPACE_STD
4545
4646using ::lconv _LIBCPP_USING_IF_EXISTS;
47#ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS
4847using ::setlocale _LIBCPP_USING_IF_EXISTS;
49#endif
5048using ::localeconv _LIBCPP_USING_IF_EXISTS;
5149
5250_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/cmath+20-33
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===---------------------------- cmath -----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -306,8 +306,8 @@ constexpr long double lerp(long double a, long double b, long double t) noexcept
306306
307307#include <__config>
308308#include <math.h>
309#include <version>
310309#include <type_traits>
310#include <version>
311311
312312#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
313313#pragma GCC system_header
......@@ -535,7 +535,7 @@ inline _LIBCPP_INLINE_VISIBILITY long double hypot( long double x, long double y
535535
536536template <class _A1, class _A2, class _A3>
537537inline _LIBCPP_INLINE_VISIBILITY
538typename _EnableIf
538typename enable_if_t
539539<
540540 is_arithmetic<_A1>::value &&
541541 is_arithmetic<_A2>::value &&
......@@ -636,37 +636,24 @@ lerp(double __a, double __b, double __t) _NOEXCEPT { return __ler
636636constexpr long double
637637lerp(long double __a, long double __b, long double __t) _NOEXCEPT { return __lerp(__a, __b, __t); }
638638
639#endif // _LIBCPP_STD_VER > 17
640
641template <class _IntT, class _FloatT,
642 bool _FloatBigger = (numeric_limits<_FloatT>::digits > numeric_limits<_IntT>::digits),
643 int _Bits = (numeric_limits<_IntT>::digits - numeric_limits<_FloatT>::digits)>
644_LIBCPP_INLINE_VISIBILITY
645_LIBCPP_CONSTEXPR _IntT __max_representable_int_for_float() _NOEXCEPT {
646 static_assert(is_floating_point<_FloatT>::value, "must be a floating point type");
647 static_assert(is_integral<_IntT>::value, "must be an integral type");
648 static_assert(numeric_limits<_FloatT>::radix == 2, "FloatT has incorrect radix");
649 static_assert((_IsSame<_FloatT, float>::value || _IsSame<_FloatT, double>::value
650 || _IsSame<_FloatT,long double>::value), "unsupported floating point type");
651 return _FloatBigger ? numeric_limits<_IntT>::max() : (numeric_limits<_IntT>::max() >> _Bits << _Bits);
652}
653
654// Convert a floating point number to the specified integral type after
655// clamping to the integral types representable range.
656//
657// The behavior is undefined if `__r` is NaN.
658template <class _IntT, class _RealT>
659_LIBCPP_INLINE_VISIBILITY
660_IntT __clamp_to_integral(_RealT __r) _NOEXCEPT {
661 using _Lim = numeric_limits<_IntT>;
662 const _IntT _MaxVal = __max_representable_int_for_float<_IntT, _RealT>();
663 if (__r >= ::nextafter(static_cast<_RealT>(_MaxVal), INFINITY)) {
664 return _Lim::max();
665 } else if (__r <= _Lim::lowest()) {
666 return _Lim::min();
667 }
668 return static_cast<_IntT>(__r);
639template <class _A1, class _A2, class _A3>
640inline _LIBCPP_HIDE_FROM_ABI
641constexpr typename enable_if_t
642<
643 is_arithmetic<_A1>::value &&
644 is_arithmetic<_A2>::value &&
645 is_arithmetic<_A3>::value,
646 __promote<_A1, _A2, _A3>
647>::type
648lerp(_A1 __a, _A2 __b, _A3 __t) noexcept
649{
650 typedef typename __promote<_A1, _A2, _A3>::type __result_type;
651 static_assert(!(_IsSame<_A1, __result_type>::value &&
652 _IsSame<_A2, __result_type>::value &&
653 _IsSame<_A3, __result_type>::value));
654 return __lerp((__result_type)__a, (__result_type)__b, (__result_type)__t);
669655}
656#endif // _LIBCPP_STD_VER > 17
670657
671658_LIBCPP_END_NAMESPACE_STD
672659
lib/libcxx/include/codecvt+8-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===-------------------------- codecvt -----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -56,6 +56,7 @@ class codecvt_utf8_utf16
5656
5757#include <__config>
5858#include <__locale>
59#include <version>
5960
6061#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
6162#pragma GCC system_header
......@@ -74,6 +75,7 @@ enum codecvt_mode
7475
7576template <class _Elem> class __codecvt_utf8;
7677
78#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
7779template <>
7880class _LIBCPP_TYPE_VIS __codecvt_utf8<wchar_t>
7981 : public codecvt<wchar_t, char, mbstate_t>
......@@ -108,6 +110,7 @@ protected:
108110 size_t __mx) const;
109111 virtual int do_max_length() const _NOEXCEPT;
110112};
113#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
111114
112115_LIBCPP_SUPPRESS_DEPRECATED_PUSH
113116template <>
......@@ -203,6 +206,7 @@ public:
203206
204207template <class _Elem, bool _LittleEndian> class __codecvt_utf16;
205208
209#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
206210template <>
207211class _LIBCPP_TYPE_VIS __codecvt_utf16<wchar_t, false>
208212 : public codecvt<wchar_t, char, mbstate_t>
......@@ -272,6 +276,7 @@ protected:
272276 size_t __mx) const;
273277 virtual int do_max_length() const _NOEXCEPT;
274278};
279#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
275280
276281_LIBCPP_SUPPRESS_DEPRECATED_PUSH
277282template <>
......@@ -443,6 +448,7 @@ public:
443448
444449template <class _Elem> class __codecvt_utf8_utf16;
445450
451#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
446452template <>
447453class _LIBCPP_TYPE_VIS __codecvt_utf8_utf16<wchar_t>
448454 : public codecvt<wchar_t, char, mbstate_t>
......@@ -477,6 +483,7 @@ protected:
477483 size_t __mx) const;
478484 virtual int do_max_length() const _NOEXCEPT;
479485};
486#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
480487
481488_LIBCPP_SUPPRESS_DEPRECATED_PUSH
482489template <>
lib/libcxx/include/compare+40-367
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===-------------------------- compare -----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -20,8 +20,8 @@ namespace std {
2020 class strong_ordering;
2121
2222 // named comparison functions
23 constexpr bool is_eq (partial_ordering cmp) noexcept { return cmp == 0; }
24 constexpr bool is_neq (partial_ordering cmp) noexcept { return cmp != 0; }
23 constexpr bool is_eq (partial_ordering cmp) noexcept { return cmp == 0; }
24 constexpr bool is_neq (partial_ordering cmp) noexcept { return cmp != 0; }
2525 constexpr bool is_lt (partial_ordering cmp) noexcept { return cmp < 0; }
2626 constexpr bool is_lteq(partial_ordering cmp) noexcept { return cmp <= 0; }
2727 constexpr bool is_gt (partial_ordering cmp) noexcept { return cmp > 0; }
......@@ -35,10 +35,30 @@ namespace std {
3535 template<class... Ts>
3636 using common_comparison_category_t = typename common_comparison_category<Ts...>::type;
3737
38 // [cmp.concept], concept three_way_comparable
39 template<class T, class Cat = partial_ordering>
40 concept three_way_comparable = see below;
41 template<class T, class U, class Cat = partial_ordering>
42 concept three_way_comparable_with = see below;
43
44 // [cmp.result], result of three-way comparison
45 template<class T, class U = T> struct compare_three_way_result;
46
47 template<class T, class U = T>
48 using compare_three_way_result_t = typename compare_three_way_result<T, U>::type;
49
50 // [comparisons.three.way], class compare_three_way
51 struct compare_three_way; // C++20
52
3853 // [cmp.alg], comparison algorithms
39 template<class T> constexpr strong_ordering strong_order(const T& a, const T& b);
40 template<class T> constexpr weak_ordering weak_order(const T& a, const T& b);
41 template<class T> constexpr partial_ordering partial_order(const T& a, const T& b);
54 inline namespace unspecified {
55 inline constexpr unspecified strong_order = unspecified;
56 inline constexpr unspecified weak_order = unspecified;
57 inline constexpr unspecified partial_order = unspecified;
58 inline constexpr unspecified compare_strong_order_fallback = unspecified;
59 inline constexpr unspecified compare_weak_order_fallback = unspecified;
60 inline constexpr unspecified compare_partial_order_fallback = unspecified;
61 }
4262
4363 // [cmp.partialord], Class partial_ordering
4464 class partial_ordering {
......@@ -120,370 +140,23 @@ namespace std {
120140}
121141*/
122142
143#include <__compare/common_comparison_category.h>
144#include <__compare/compare_partial_order_fallback.h>
145#include <__compare/compare_strong_order_fallback.h>
146#include <__compare/compare_three_way.h>
147#include <__compare/compare_three_way_result.h>
148#include <__compare/compare_weak_order_fallback.h>
149#include <__compare/is_eq.h>
150#include <__compare/ordering.h>
151#include <__compare/partial_order.h>
152#include <__compare/strong_order.h>
153#include <__compare/three_way_comparable.h>
154#include <__compare/weak_order.h>
123155#include <__config>
124#include <type_traits>
156#include <version>
125157
126#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
158#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
127159#pragma GCC system_header
128160#endif
129161
130_LIBCPP_BEGIN_NAMESPACE_STD
131
132#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_SPACESHIP_OPERATOR)
133// exposition only
134enum class _LIBCPP_ENUM_VIS _EqResult : unsigned char {
135 __zero = 0,
136 __equal = __zero,
137 __equiv = __equal,
138 __nonequal = 1,
139 __nonequiv = __nonequal
140};
141
142enum class _LIBCPP_ENUM_VIS _OrdResult : signed char {
143 __less = -1,
144 __greater = 1
145};
146
147enum class _LIBCPP_ENUM_VIS _NCmpResult : signed char {
148 __unordered = -127
149};
150
151class partial_ordering;
152class weak_ordering;
153class strong_ordering;
154
155template<class _Tp, class... _Args>
156inline constexpr bool __one_of_v = (is_same_v<_Tp, _Args> || ...);
157
158struct _CmpUnspecifiedParam {
159 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEVAL
160 _CmpUnspecifiedParam(int _CmpUnspecifiedParam::*) noexcept {}
161
162 template<class _Tp, class = enable_if_t<!__one_of_v<_Tp, int, partial_ordering, weak_ordering, strong_ordering>>>
163 _CmpUnspecifiedParam(_Tp) = delete;
164};
165
166class partial_ordering {
167 using _ValueT = signed char;
168
169 _LIBCPP_INLINE_VISIBILITY
170 explicit constexpr partial_ordering(_EqResult __v) noexcept
171 : __value_(_ValueT(__v)) {}
172
173 _LIBCPP_INLINE_VISIBILITY
174 explicit constexpr partial_ordering(_OrdResult __v) noexcept
175 : __value_(_ValueT(__v)) {}
176
177 _LIBCPP_INLINE_VISIBILITY
178 explicit constexpr partial_ordering(_NCmpResult __v) noexcept
179 : __value_(_ValueT(__v)) {}
180
181 constexpr bool __is_ordered() const noexcept {
182 return __value_ != _ValueT(_NCmpResult::__unordered);
183 }
184public:
185 // valid values
186 static const partial_ordering less;
187 static const partial_ordering equivalent;
188 static const partial_ordering greater;
189 static const partial_ordering unordered;
190
191 // comparisons
192 _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(partial_ordering, partial_ordering) noexcept = default;
193
194 _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
195 return __v.__is_ordered() && __v.__value_ == 0;
196 }
197
198 _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator< (partial_ordering __v, _CmpUnspecifiedParam) noexcept {
199 return __v.__is_ordered() && __v.__value_ < 0;
200 }
201
202 _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator<=(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
203 return __v.__is_ordered() && __v.__value_ <= 0;
204 }
205
206 _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator> (partial_ordering __v, _CmpUnspecifiedParam) noexcept {
207 return __v.__is_ordered() && __v.__value_ > 0;
208 }
209
210 _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
211 return __v.__is_ordered() && __v.__value_ >= 0;
212 }
213
214 _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator< (_CmpUnspecifiedParam, partial_ordering __v) noexcept {
215 return __v.__is_ordered() && 0 < __v.__value_;
216 }
217
218 _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator<=(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
219 return __v.__is_ordered() && 0 <= __v.__value_;
220 }
221
222 _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator> (_CmpUnspecifiedParam, partial_ordering __v) noexcept {
223 return __v.__is_ordered() && 0 > __v.__value_;
224 }
225
226 _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
227 return __v.__is_ordered() && 0 >= __v.__value_;
228 }
229
230 _LIBCPP_INLINE_VISIBILITY friend constexpr partial_ordering operator<=>(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
231 return __v;
232 }
233
234 _LIBCPP_INLINE_VISIBILITY friend constexpr partial_ordering operator<=>(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
235 return __v < 0 ? partial_ordering::greater : (__v > 0 ? partial_ordering::less : __v);
236 }
237private:
238 _ValueT __value_;
239};
240
241_LIBCPP_INLINE_VAR constexpr partial_ordering partial_ordering::less(_OrdResult::__less);
242_LIBCPP_INLINE_VAR constexpr partial_ordering partial_ordering::equivalent(_EqResult::__equiv);
243_LIBCPP_INLINE_VAR constexpr partial_ordering partial_ordering::greater(_OrdResult::__greater);
244_LIBCPP_INLINE_VAR constexpr partial_ordering partial_ordering::unordered(_NCmpResult ::__unordered);
245
246class weak_ordering {
247 using _ValueT = signed char;
248
249 _LIBCPP_INLINE_VISIBILITY
250 explicit constexpr weak_ordering(_EqResult __v) noexcept : __value_(_ValueT(__v)) {}
251 _LIBCPP_INLINE_VISIBILITY
252 explicit constexpr weak_ordering(_OrdResult __v) noexcept : __value_(_ValueT(__v)) {}
253
254public:
255 static const weak_ordering less;
256 static const weak_ordering equivalent;
257 static const weak_ordering greater;
258
259 _LIBCPP_INLINE_VISIBILITY
260 constexpr operator partial_ordering() const noexcept {
261 return __value_ == 0 ? partial_ordering::equivalent
262 : (__value_ < 0 ? partial_ordering::less : partial_ordering::greater);
263 }
264
265 // comparisons
266 _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(weak_ordering, weak_ordering) noexcept = default;
267
268 _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
269 return __v.__value_ == 0;
270 }
271
272 _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator< (weak_ordering __v, _CmpUnspecifiedParam) noexcept {
273 return __v.__value_ < 0;
274 }
275
276 _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator<=(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
277 return __v.__value_ <= 0;
278 }
279
280 _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator> (weak_ordering __v, _CmpUnspecifiedParam) noexcept {
281 return __v.__value_ > 0;
282 }
283
284 _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
285 return __v.__value_ >= 0;
286 }
287
288 _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator< (_CmpUnspecifiedParam, weak_ordering __v) noexcept {
289 return 0 < __v.__value_;
290 }
291
292 _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator<=(_CmpUnspecifiedParam, weak_ordering __v) noexcept {
293 return 0 <= __v.__value_;
294 }
295
296 _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator> (_CmpUnspecifiedParam, weak_ordering __v) noexcept {
297 return 0 > __v.__value_;
298 }
299
300 _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(_CmpUnspecifiedParam, weak_ordering __v) noexcept {
301 return 0 >= __v.__value_;
302 }
303
304 _LIBCPP_INLINE_VISIBILITY friend constexpr weak_ordering operator<=>(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
305 return __v;
306 }
307
308 _LIBCPP_INLINE_VISIBILITY friend constexpr weak_ordering operator<=>(_CmpUnspecifiedParam, weak_ordering __v) noexcept {
309 return __v < 0 ? weak_ordering::greater : (__v > 0 ? weak_ordering::less : __v);
310 }
311
312private:
313 _ValueT __value_;
314};
315
316_LIBCPP_INLINE_VAR constexpr weak_ordering weak_ordering::less(_OrdResult::__less);
317_LIBCPP_INLINE_VAR constexpr weak_ordering weak_ordering::equivalent(_EqResult::__equiv);
318_LIBCPP_INLINE_VAR constexpr weak_ordering weak_ordering::greater(_OrdResult::__greater);
319class strong_ordering {
320 using _ValueT = signed char;
321
322 _LIBCPP_INLINE_VISIBILITY
323 explicit constexpr strong_ordering(_EqResult __v) noexcept : __value_(_ValueT(__v)) {}
324 _LIBCPP_INLINE_VISIBILITY
325 explicit constexpr strong_ordering(_OrdResult __v) noexcept : __value_(_ValueT(__v)) {}
326
327public:
328 static const strong_ordering less;
329 static const strong_ordering equal;
330 static const strong_ordering equivalent;
331 static const strong_ordering greater;
332
333 // conversions
334 _LIBCPP_INLINE_VISIBILITY
335 constexpr operator partial_ordering() const noexcept {
336 return __value_ == 0 ? partial_ordering::equivalent
337 : (__value_ < 0 ? partial_ordering::less : partial_ordering::greater);
338 }
339
340 _LIBCPP_INLINE_VISIBILITY
341 constexpr operator weak_ordering() const noexcept {
342 return __value_ == 0 ? weak_ordering::equivalent
343 : (__value_ < 0 ? weak_ordering::less : weak_ordering::greater);
344 }
345
346 // comparisons
347 _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(strong_ordering, strong_ordering) noexcept = default;
348
349 _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
350 return __v.__value_ == 0;
351 }
352
353 _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator< (strong_ordering __v, _CmpUnspecifiedParam) noexcept {
354 return __v.__value_ < 0;
355 }
356
357 _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator<=(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
358 return __v.__value_ <= 0;
359 }
360
361 _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator> (strong_ordering __v, _CmpUnspecifiedParam) noexcept {
362 return __v.__value_ > 0;
363 }
364
365 _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
366 return __v.__value_ >= 0;
367 }
368
369 _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator< (_CmpUnspecifiedParam, strong_ordering __v) noexcept {
370 return 0 < __v.__value_;
371 }
372
373 _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator<=(_CmpUnspecifiedParam, strong_ordering __v) noexcept {
374 return 0 <= __v.__value_;
375 }
376
377 _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator> (_CmpUnspecifiedParam, strong_ordering __v) noexcept {
378 return 0 > __v.__value_;
379 }
380
381 _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(_CmpUnspecifiedParam, strong_ordering __v) noexcept {
382 return 0 >= __v.__value_;
383 }
384
385 _LIBCPP_INLINE_VISIBILITY friend constexpr strong_ordering operator<=>(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
386 return __v;
387 }
388
389 _LIBCPP_INLINE_VISIBILITY friend constexpr strong_ordering operator<=>(_CmpUnspecifiedParam, strong_ordering __v) noexcept {
390 return __v < 0 ? strong_ordering::greater : (__v > 0 ? strong_ordering::less : __v);
391 }
392
393private:
394 _ValueT __value_;
395};
396
397_LIBCPP_INLINE_VAR constexpr strong_ordering strong_ordering::less(_OrdResult::__less);
398_LIBCPP_INLINE_VAR constexpr strong_ordering strong_ordering::equal(_EqResult::__equal);
399_LIBCPP_INLINE_VAR constexpr strong_ordering strong_ordering::equivalent(_EqResult::__equiv);
400_LIBCPP_INLINE_VAR constexpr strong_ordering strong_ordering::greater(_OrdResult::__greater);
401
402// named comparison functions
403_LIBCPP_INLINE_VISIBILITY
404constexpr bool is_lt(partial_ordering __cmp) noexcept { return __cmp < 0; }
405
406_LIBCPP_INLINE_VISIBILITY
407constexpr bool is_lteq(partial_ordering __cmp) noexcept { return __cmp <= 0; }
408
409_LIBCPP_INLINE_VISIBILITY
410constexpr bool is_gt(partial_ordering __cmp) noexcept { return __cmp > 0; }
411
412_LIBCPP_INLINE_VISIBILITY
413constexpr bool is_gteq(partial_ordering __cmp) noexcept { return __cmp >= 0; }
414
415namespace __comp_detail {
416
417enum _ClassifyCompCategory : unsigned{
418 _None,
419 _PartialOrd,
420 _WeakOrd,
421 _StrongOrd,
422 _CCC_Size
423};
424
425template <class _Tp>
426_LIBCPP_INLINE_VISIBILITY
427constexpr _ClassifyCompCategory __type_to_enum() noexcept {
428 if (is_same_v<_Tp, partial_ordering>)
429 return _PartialOrd;
430 if (is_same_v<_Tp, weak_ordering>)
431 return _WeakOrd;
432 if (is_same_v<_Tp, strong_ordering>)
433 return _StrongOrd;
434 return _None;
435}
436
437template <size_t _Size>
438constexpr _ClassifyCompCategory
439__compute_comp_type(const _ClassifyCompCategory (&__types)[_Size]) {
440 int __seen[_CCC_Size] = {};
441 for (auto __type : __types)
442 ++__seen[__type];
443 if (__seen[_None])
444 return _None;
445 if (__seen[_PartialOrd])
446 return _PartialOrd;
447 if (__seen[_WeakOrd])
448 return _WeakOrd;
449 return _StrongOrd;
450}
451
452template <class ..._Ts, bool _False = false>
453constexpr auto __get_comp_type() {
454 using _CCC = _ClassifyCompCategory;
455 constexpr _CCC __type_kinds[] = {_StrongOrd, __type_to_enum<_Ts>()...};
456 constexpr _CCC _Cat = __compute_comp_type(__type_kinds);
457 if constexpr (_Cat == _None)
458 return void();
459 else if constexpr (_Cat == _PartialOrd)
460 return partial_ordering::equivalent;
461 else if constexpr (_Cat == _WeakOrd)
462 return weak_ordering::equivalent;
463 else if constexpr (_Cat == _StrongOrd)
464 return strong_ordering::equivalent;
465 else
466 static_assert(_False, "unhandled case");
467}
468} // namespace __comp_detail
469
470// [cmp.common], common comparison category type
471template<class... _Ts>
472struct _LIBCPP_TEMPLATE_VIS common_comparison_category {
473 using type = decltype(__comp_detail::__get_comp_type<_Ts...>());
474};
475
476template<class... _Ts>
477using common_comparison_category_t = typename common_comparison_category<_Ts...>::type;
478
479// [cmp.alg], comparison algorithms
480// TODO: unimplemented
481template<class _Tp> constexpr strong_ordering strong_order(const _Tp& __lhs, const _Tp& __rhs);
482template<class _Tp> constexpr weak_ordering weak_order(const _Tp& __lhs, const _Tp& __rhs);
483template<class _Tp> constexpr partial_ordering partial_order(const _Tp& __lhs, const _Tp& __rhs);
484
485#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_SPACESHIP_OPERATOR)
486
487_LIBCPP_END_NAMESPACE_STD
488
489162#endif // _LIBCPP_COMPARE
lib/libcxx/include/complex+8-7
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- complex ----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -1056,6 +1056,9 @@ complex<_Tp>
10561056exp(const complex<_Tp>& __x)
10571057{
10581058 _Tp __i = __x.imag();
1059 if (__i == 0) {
1060 return complex<_Tp>(exp(__x.real()), copysign(_Tp(0), __x.imag()));
1061 }
10591062 if (__libcpp_isinf_or_builtin(__x.real()))
10601063 {
10611064 if (__x.real() < _Tp(0))
......@@ -1070,8 +1073,6 @@ exp(const complex<_Tp>& __x)
10701073 return complex<_Tp>(__x.real(), __i);
10711074 }
10721075 }
1073 else if (__libcpp_isnan_or_builtin(__x.real()) && __x.imag() == 0)
1074 return __x;
10751076 _Tp __e = exp(__x.real());
10761077 return complex<_Tp>(__e * cos(__i), __e * sin(__i));
10771078}
......@@ -1269,8 +1270,8 @@ tanh(const complex<_Tp>& __x)
12691270 if (__libcpp_isinf_or_builtin(__x.real()))
12701271 {
12711272 if (!__libcpp_isfinite_or_builtin(__x.imag()))
1272 return complex<_Tp>(_Tp(1), _Tp(0));
1273 return complex<_Tp>(_Tp(1), copysign(_Tp(0), sin(_Tp(2) * __x.imag())));
1273 return complex<_Tp>(copysign(_Tp(1), __x.real()), _Tp(0));
1274 return complex<_Tp>(copysign(_Tp(1), __x.real()), copysign(_Tp(0), sin(_Tp(2) * __x.imag())));
12741275 }
12751276 if (__libcpp_isnan_or_builtin(__x.real()) && __x.imag() == 0)
12761277 return __x;
......@@ -1484,8 +1485,8 @@ inline namespace literals
14841485 {
14851486 return { 0.0f, static_cast<float>(__im) };
14861487 }
1487 }
1488}
1488 } // namespace complex_literals
1489} // namespace literals
14891490#endif
14901491
14911492_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/complex.h+1-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- complex.h --------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/concepts+23-317
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===-------------------------- concepts ----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -129,327 +129,33 @@ namespace std {
129129
130130*/
131131
132#include <__concepts/arithmetic.h>
133#include <__concepts/assignable.h>
134#include <__concepts/boolean_testable.h>
135#include <__concepts/class_or_enum.h>
136#include <__concepts/common_reference_with.h>
137#include <__concepts/common_with.h>
138#include <__concepts/constructible.h>
139#include <__concepts/convertible_to.h>
140#include <__concepts/copyable.h>
141#include <__concepts/derived_from.h>
142#include <__concepts/destructible.h>
143#include <__concepts/different_from.h>
144#include <__concepts/equality_comparable.h>
145#include <__concepts/invocable.h>
146#include <__concepts/movable.h>
147#include <__concepts/predicate.h>
148#include <__concepts/regular.h>
149#include <__concepts/relation.h>
150#include <__concepts/same_as.h>
151#include <__concepts/semiregular.h>
152#include <__concepts/swappable.h>
153#include <__concepts/totally_ordered.h>
132154#include <__config>
133#include <__functional/invoke.h>
134#include <__functional_base>
135#include <type_traits>
136#include <utility>
137155#include <version>
138156
139157#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
140158#pragma GCC system_header
141159#endif
142160
143_LIBCPP_PUSH_MACROS
144#include <__undef_macros>
145
146_LIBCPP_BEGIN_NAMESPACE_STD
147
148#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CONCEPTS)
149
150// [concept.same]
151
152template<class _Tp, class _Up>
153concept __same_as_impl = _VSTD::_IsSame<_Tp, _Up>::value;
154
155template<class _Tp, class _Up>
156concept same_as = __same_as_impl<_Tp, _Up> && __same_as_impl<_Up, _Tp>;
157
158// [concept.derived]
159template<class _Dp, class _Bp>
160concept derived_from =
161 is_base_of_v<_Bp, _Dp> &&
162 is_convertible_v<const volatile _Dp*, const volatile _Bp*>;
163
164// [concept.convertible]
165template<class _From, class _To>
166concept convertible_to =
167 is_convertible_v<_From, _To> &&
168 requires(add_rvalue_reference_t<_From> (&__f)()) {
169 static_cast<_To>(__f());
170 };
171
172// [concept.commonref]
173template<class _Tp, class _Up>
174concept common_reference_with =
175 same_as<common_reference_t<_Tp, _Up>, common_reference_t<_Up, _Tp>> &&
176 convertible_to<_Tp, common_reference_t<_Tp, _Up>> &&
177 convertible_to<_Up, common_reference_t<_Tp, _Up>>;
178
179// [concept.common]
180template<class _Tp, class _Up>
181concept common_with =
182 same_as<common_type_t<_Tp, _Up>, common_type_t<_Up, _Tp>> &&
183 requires {
184 static_cast<common_type_t<_Tp, _Up>>(declval<_Tp>());
185 static_cast<common_type_t<_Tp, _Up>>(declval<_Up>());
186 } &&
187 common_reference_with<
188 add_lvalue_reference_t<const _Tp>,
189 add_lvalue_reference_t<const _Up>> &&
190 common_reference_with<
191 add_lvalue_reference_t<common_type_t<_Tp, _Up>>,
192 common_reference_t<
193 add_lvalue_reference_t<const _Tp>,
194 add_lvalue_reference_t<const _Up>>>;
195
196// [concepts.arithmetic], arithmetic concepts
197template<class _Tp>
198concept integral = is_integral_v<_Tp>;
199
200template<class _Tp>
201concept signed_integral = integral<_Tp> && is_signed_v<_Tp>;
202
203template<class _Tp>
204concept unsigned_integral = integral<_Tp> && !signed_integral<_Tp>;
205
206template<class _Tp>
207concept floating_point = is_floating_point_v<_Tp>;
208
209// [concept.assignable]
210template<class _Lhs, class _Rhs>
211concept assignable_from =
212 is_lvalue_reference_v<_Lhs> &&
213 common_reference_with<__make_const_lvalue_ref<_Lhs>, __make_const_lvalue_ref<_Rhs>> &&
214 requires (_Lhs __lhs, _Rhs&& __rhs) {
215 { __lhs = _VSTD::forward<_Rhs>(__rhs) } -> same_as<_Lhs>;
216 };
217
218// [concept.destructible]
219
220template<class _Tp>
221concept destructible = is_nothrow_destructible_v<_Tp>;
222
223// [concept.constructible]
224template<class _Tp, class... _Args>
225concept constructible_from =
226 destructible<_Tp> && is_constructible_v<_Tp, _Args...>;
227
228// [concept.default.init]
229
230template<class _Tp>
231concept __default_initializable = requires { ::new _Tp; };
232
233template<class _Tp>
234concept default_initializable = constructible_from<_Tp> &&
235 requires { _Tp{}; } && __default_initializable<_Tp>;
236
237// [concept.moveconstructible]
238template<class _Tp>
239concept move_constructible =
240 constructible_from<_Tp, _Tp> && convertible_to<_Tp, _Tp>;
241
242// [concept.copyconstructible]
243template<class _Tp>
244concept copy_constructible =
245 move_constructible<_Tp> &&
246 constructible_from<_Tp, _Tp&> && convertible_to<_Tp&, _Tp> &&
247 constructible_from<_Tp, const _Tp&> && convertible_to<const _Tp&, _Tp> &&
248 constructible_from<_Tp, const _Tp> && convertible_to<const _Tp, _Tp>;
249
250// Whether a type is a class type or enumeration type according to the Core wording.
251template<class _Tp>
252concept __class_or_enum = is_class_v<_Tp> || is_union_v<_Tp> || is_enum_v<_Tp>;
253
254// [concept.swappable]
255namespace ranges::__swap {
256 // Deleted to inhibit ADL
257 template<class _Tp>
258 void swap(_Tp&, _Tp&) = delete;
259
260
261 // [1]
262 template<class _Tp, class _Up>
263 concept __unqualified_swappable_with =
264 (__class_or_enum<remove_cvref_t<_Tp>> || __class_or_enum<remove_cvref_t<_Up>>) &&
265 requires(_Tp&& __t, _Up&& __u) {
266 swap(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u));
267 };
268
269 struct __fn;
270
271 template<class _Tp, class _Up, size_t _Size>
272 concept __swappable_arrays =
273 !__unqualified_swappable_with<_Tp(&)[_Size], _Up(&)[_Size]> &&
274 extent_v<_Tp> == extent_v<_Up> &&
275 requires(_Tp(& __t)[_Size], _Up(& __u)[_Size], const __fn& __swap) {
276 __swap(__t[0], __u[0]);
277 };
278
279 template<class _Tp>
280 concept __exchangeable =
281 !__unqualified_swappable_with<_Tp&, _Tp&> &&
282 move_constructible<_Tp> &&
283 assignable_from<_Tp&, _Tp>;
284
285 struct __fn {
286 // 2.1 `S` is `(void)swap(E1, E2)`* if `E1` or `E2` has class or enumeration type and...
287 // *The name `swap` is used here unqualified.
288 template<class _Tp, class _Up>
289 requires __unqualified_swappable_with<_Tp, _Up>
290 constexpr void operator()(_Tp&& __t, _Up&& __u) const
291 noexcept(noexcept(swap(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
292 {
293 swap(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u));
294 }
295
296 // 2.2 Otherwise, if `E1` and `E2` are lvalues of array types with equal extent and...
297 template<class _Tp, class _Up, size_t _Size>
298 requires __swappable_arrays<_Tp, _Up, _Size>
299 constexpr void operator()(_Tp(& __t)[_Size], _Up(& __u)[_Size]) const
300 noexcept(noexcept((*this)(*__t, *__u)))
301 {
302 // TODO(cjdb): replace with `ranges::swap_ranges`.
303 for (size_t __i = 0; __i < _Size; ++__i) {
304 (*this)(__t[__i], __u[__i]);
305 }
306 }
307
308 // 2.3 Otherwise, if `E1` and `E2` are lvalues of the same type `T` that models...
309 template<__exchangeable _Tp>
310 constexpr void operator()(_Tp& __x, _Tp& __y) const
311 noexcept(is_nothrow_move_constructible_v<_Tp> && is_nothrow_move_assignable_v<_Tp>)
312 {
313 __y = _VSTD::exchange(__x, _VSTD::move(__y));
314 }
315 };
316} // namespace ranges::__swap
317
318namespace ranges::inline __cpo {
319 inline constexpr auto swap = __swap::__fn{};
320} // namespace ranges::__cpo
321
322template<class _Tp>
323concept swappable = requires(_Tp& __a, _Tp& __b) { ranges::swap(__a, __b); };
324
325template<class _Tp, class _Up>
326concept swappable_with =
327 common_reference_with<_Tp, _Up> &&
328 requires(_Tp&& __t, _Up&& __u) {
329 ranges::swap(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Tp>(__t));
330 ranges::swap(_VSTD::forward<_Up>(__u), _VSTD::forward<_Up>(__u));
331 ranges::swap(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u));
332 ranges::swap(_VSTD::forward<_Up>(__u), _VSTD::forward<_Tp>(__t));
333 };
334
335// [concept.booleantestable]
336template<class _Tp>
337concept __boolean_testable_impl = convertible_to<_Tp, bool>;
338
339template<class _Tp>
340concept __boolean_testable = __boolean_testable_impl<_Tp> && requires(_Tp&& __t) {
341 { !std::forward<_Tp>(__t) } -> __boolean_testable_impl;
342};
343
344// [concept.equalitycomparable]
345template<class _Tp, class _Up>
346concept __weakly_equality_comparable_with =
347 requires(__make_const_lvalue_ref<_Tp> __t, __make_const_lvalue_ref<_Up> __u) {
348 { __t == __u } -> __boolean_testable;
349 { __t != __u } -> __boolean_testable;
350 { __u == __t } -> __boolean_testable;
351 { __u != __t } -> __boolean_testable;
352 };
353
354template<class _Tp>
355concept equality_comparable = __weakly_equality_comparable_with<_Tp, _Tp>;
356
357template<class _Tp, class _Up>
358concept equality_comparable_with =
359 equality_comparable<_Tp> && equality_comparable<_Up> &&
360 common_reference_with<__make_const_lvalue_ref<_Tp>, __make_const_lvalue_ref<_Up>> &&
361 equality_comparable<
362 common_reference_t<
363 __make_const_lvalue_ref<_Tp>,
364 __make_const_lvalue_ref<_Up>>> &&
365 __weakly_equality_comparable_with<_Tp, _Up>;
366
367// [concept.totallyordered]
368
369template<class _Tp, class _Up>
370concept __partially_ordered_with =
371 requires(__make_const_lvalue_ref<_Tp> __t, __make_const_lvalue_ref<_Up> __u) {
372 { __t < __u } -> __boolean_testable;
373 { __t > __u } -> __boolean_testable;
374 { __t <= __u } -> __boolean_testable;
375 { __t >= __u } -> __boolean_testable;
376 { __u < __t } -> __boolean_testable;
377 { __u > __t } -> __boolean_testable;
378 { __u <= __t } -> __boolean_testable;
379 { __u >= __t } -> __boolean_testable;
380 };
381
382template<class _Tp>
383concept totally_ordered = equality_comparable<_Tp> && __partially_ordered_with<_Tp, _Tp>;
384
385template<class _Tp, class _Up>
386concept totally_ordered_with =
387 totally_ordered<_Tp> && totally_ordered<_Up> &&
388 equality_comparable_with<_Tp, _Up> &&
389 totally_ordered<
390 common_reference_t<
391 __make_const_lvalue_ref<_Tp>,
392 __make_const_lvalue_ref<_Up>>> &&
393 __partially_ordered_with<_Tp, _Up>;
394
395// [concepts.object]
396template<class _Tp>
397concept movable =
398 is_object_v<_Tp> &&
399 move_constructible<_Tp> &&
400 assignable_from<_Tp&, _Tp> &&
401 swappable<_Tp>;
402
403template<class _Tp>
404concept copyable =
405 copy_constructible<_Tp> &&
406 movable<_Tp> &&
407 assignable_from<_Tp&, _Tp&> &&
408 assignable_from<_Tp&, const _Tp&> &&
409 assignable_from<_Tp&, const _Tp>;
410
411template<class _Tp>
412concept semiregular = copyable<_Tp> && default_initializable<_Tp>;
413
414template<class _Tp>
415concept regular = semiregular<_Tp> && equality_comparable<_Tp>;
416
417// [concept.invocable]
418template<class _Fn, class... _Args>
419concept invocable = requires(_Fn&& __fn, _Args&&... __args) {
420 _VSTD::invoke(_VSTD::forward<_Fn>(__fn), _VSTD::forward<_Args>(__args)...); // not required to be equality preserving
421};
422
423// [concept.regular.invocable]
424template<class _Fn, class... _Args>
425concept regular_invocable = invocable<_Fn, _Args...>;
426
427// [concept.predicate]
428template<class _Fn, class... _Args>
429concept predicate =
430 regular_invocable<_Fn, _Args...> && __boolean_testable<invoke_result_t<_Fn, _Args...>>;
431
432// [concept.relation]
433template<class _Rp, class _Tp, class _Up>
434concept relation =
435 predicate<_Rp, _Tp, _Tp> && predicate<_Rp, _Up, _Up> &&
436 predicate<_Rp, _Tp, _Up> && predicate<_Rp, _Up, _Tp>;
437
438// [concept.equiv]
439template<class _Rp, class _Tp, class _Up>
440concept equivalence_relation = relation<_Rp, _Tp, _Up>;
441
442// [concept.strictweakorder]
443template<class _Rp, class _Tp, class _Up>
444concept strict_weak_order = relation<_Rp, _Tp, _Up>;
445
446template<class _Tp, class _Up>
447concept __different_from = !same_as<remove_cvref_t<_Tp>, remove_cvref_t<_Up>>;
448
449#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CONCEPTS)
450
451_LIBCPP_END_NAMESPACE_STD
452
453_LIBCPP_POP_MACROS
454
455161#endif // _LIBCPP_CONCEPTS
lib/libcxx/include/condition_variable+2-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===---------------------- condition_variable ----------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -109,6 +109,7 @@ public:
109109#include <__config>
110110#include <__mutex_base>
111111#include <memory>
112#include <version>
112113
113114#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
114115#pragma GCC system_header
lib/libcxx/include/coroutine 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_COROUTINE
11#define _LIBCPP_COROUTINE
12
13/**
14 coroutine synopsis
15
16namespace std {
17// [coroutine.traits]
18template <class R, class... ArgTypes>
19 struct coroutine_traits;
20// [coroutine.handle]
21template <class Promise = void>
22 struct coroutine_handle;
23// [coroutine.handle.compare]
24constexpr bool operator==(coroutine_handle<> x, coroutine_handle<> y) noexcept;
25constexpr strong_ordering operator<=>(coroutine_handle<> x, coroutine_handle<> y) noexcept;
26// [coroutine.handle.hash]
27template <class T> struct hash;
28template <class P> struct hash<coroutine_handle<P>>;
29// [coroutine.noop]
30struct noop_coroutine_promise;
31template<> struct coroutine_handle<noop_coroutine_promise>;
32using noop_coroutine_handle = coroutine_handle<noop_coroutine_promise>;
33noop_coroutine_handle noop_coroutine() noexcept;
34// [coroutine.trivial.awaitables]
35struct suspend_never;
36struct suspend_always;
37} // namespace std
38
39 */
40
41#include <__config>
42#include <__coroutine/coroutine_handle.h>
43#include <__coroutine/coroutine_traits.h>
44#include <__coroutine/noop_coroutine_handle.h>
45#include <__coroutine/trivial_awaitables.h>
46#include <version>
47
48#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
49#pragma GCC system_header
50#endif
51
52#endif // _LIBCPP_COROUTINE
lib/libcxx/include/csetjmp+1-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- csetjmp ----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/csignal+1-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- csignal ----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/cstdarg+1-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- cstdarg ----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/cstdbool+1-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- cstdbool ---------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/cstddef+6-3
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- cstddef ----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -58,14 +58,16 @@ template <> struct __libcpp_is_integral<bool> { enum { va
5858template <> struct __libcpp_is_integral<char> { enum { value = 1 }; };
5959template <> struct __libcpp_is_integral<signed char> { enum { value = 1 }; };
6060template <> struct __libcpp_is_integral<unsigned char> { enum { value = 1 }; };
61#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
6162template <> struct __libcpp_is_integral<wchar_t> { enum { value = 1 }; };
63#endif
6264#ifndef _LIBCPP_HAS_NO_CHAR8_T
6365template <> struct __libcpp_is_integral<char8_t> { enum { value = 1 }; };
6466#endif
6567#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
6668template <> struct __libcpp_is_integral<char16_t> { enum { value = 1 }; };
6769template <> struct __libcpp_is_integral<char32_t> { enum { value = 1 }; };
68#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
70#endif
6971template <> struct __libcpp_is_integral<short> { enum { value = 1 }; };
7072template <> struct __libcpp_is_integral<unsigned short> { enum { value = 1 }; };
7173template <> struct __libcpp_is_integral<int> { enum { value = 1 }; };
......@@ -154,7 +156,8 @@ template <class _Integer>
154156template <class _Integer, class = _EnableByteOverload<_Integer> >
155157 _LIBCPP_NODISCARD_EXT constexpr _Integer
156158 to_integer(byte __b) noexcept { return static_cast<_Integer>(__b); }
157}
159
160} // namespace std
158161
159162#endif
160163
lib/libcxx/include/cstdint+1-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- cstdint ----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/cstdio+1-7
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===---------------------------- cstdio ----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -145,30 +145,24 @@ using ::feof _LIBCPP_USING_IF_EXISTS;
145145using ::ferror _LIBCPP_USING_IF_EXISTS;
146146using ::perror _LIBCPP_USING_IF_EXISTS;
147147
148#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
149148using ::fopen _LIBCPP_USING_IF_EXISTS;
150149using ::freopen _LIBCPP_USING_IF_EXISTS;
151150using ::remove _LIBCPP_USING_IF_EXISTS;
152151using ::rename _LIBCPP_USING_IF_EXISTS;
153152using ::tmpfile _LIBCPP_USING_IF_EXISTS;
154153using ::tmpnam _LIBCPP_USING_IF_EXISTS;
155#endif
156154
157#ifndef _LIBCPP_HAS_NO_STDIN
158155using ::getchar _LIBCPP_USING_IF_EXISTS;
159156#if _LIBCPP_STD_VER <= 11 && !defined(_LIBCPP_C_HAS_NO_GETS)
160157using ::gets _LIBCPP_USING_IF_EXISTS;
161158#endif
162159using ::scanf _LIBCPP_USING_IF_EXISTS;
163160using ::vscanf _LIBCPP_USING_IF_EXISTS;
164#endif
165161
166#ifndef _LIBCPP_HAS_NO_STDOUT
167162using ::printf _LIBCPP_USING_IF_EXISTS;
168163using ::putchar _LIBCPP_USING_IF_EXISTS;
169164using ::puts _LIBCPP_USING_IF_EXISTS;
170165using ::vprintf _LIBCPP_USING_IF_EXISTS;
171#endif
172166
173167_LIBCPP_END_NAMESPACE_STD
174168
lib/libcxx/include/cstdlib+1-13
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- cstdlib ----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -99,26 +99,18 @@ _LIBCPP_BEGIN_NAMESPACE_STD
9999using ::size_t _LIBCPP_USING_IF_EXISTS;
100100using ::div_t _LIBCPP_USING_IF_EXISTS;
101101using ::ldiv_t _LIBCPP_USING_IF_EXISTS;
102#ifndef _LIBCPP_HAS_NO_LONG_LONG
103102using ::lldiv_t _LIBCPP_USING_IF_EXISTS;
104#endif // _LIBCPP_HAS_NO_LONG_LONG
105103using ::atof _LIBCPP_USING_IF_EXISTS;
106104using ::atoi _LIBCPP_USING_IF_EXISTS;
107105using ::atol _LIBCPP_USING_IF_EXISTS;
108#ifndef _LIBCPP_HAS_NO_LONG_LONG
109106using ::atoll _LIBCPP_USING_IF_EXISTS;
110#endif // _LIBCPP_HAS_NO_LONG_LONG
111107using ::strtod _LIBCPP_USING_IF_EXISTS;
112108using ::strtof _LIBCPP_USING_IF_EXISTS;
113109using ::strtold _LIBCPP_USING_IF_EXISTS;
114110using ::strtol _LIBCPP_USING_IF_EXISTS;
115#ifndef _LIBCPP_HAS_NO_LONG_LONG
116111using ::strtoll _LIBCPP_USING_IF_EXISTS;
117#endif // _LIBCPP_HAS_NO_LONG_LONG
118112using ::strtoul _LIBCPP_USING_IF_EXISTS;
119#ifndef _LIBCPP_HAS_NO_LONG_LONG
120113using ::strtoull _LIBCPP_USING_IF_EXISTS;
121#endif // _LIBCPP_HAS_NO_LONG_LONG
122114using ::rand _LIBCPP_USING_IF_EXISTS;
123115using ::srand _LIBCPP_USING_IF_EXISTS;
124116using ::calloc _LIBCPP_USING_IF_EXISTS;
......@@ -137,14 +129,10 @@ using ::bsearch _LIBCPP_USING_IF_EXISTS;
137129using ::qsort _LIBCPP_USING_IF_EXISTS;
138130using ::abs _LIBCPP_USING_IF_EXISTS;
139131using ::labs _LIBCPP_USING_IF_EXISTS;
140#ifndef _LIBCPP_HAS_NO_LONG_LONG
141132using ::llabs _LIBCPP_USING_IF_EXISTS;
142#endif // _LIBCPP_HAS_NO_LONG_LONG
143133using ::div _LIBCPP_USING_IF_EXISTS;
144134using ::ldiv _LIBCPP_USING_IF_EXISTS;
145#ifndef _LIBCPP_HAS_NO_LONG_LONG
146135using ::lldiv _LIBCPP_USING_IF_EXISTS;
147#endif // _LIBCPP_HAS_NO_LONG_LONG
148136using ::mblen _LIBCPP_USING_IF_EXISTS;
149137using ::mbtowc _LIBCPP_USING_IF_EXISTS;
150138using ::wctomb _LIBCPP_USING_IF_EXISTS;
lib/libcxx/include/cstring+1-3
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- cstring ----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -84,9 +84,7 @@ using ::strpbrk _LIBCPP_USING_IF_EXISTS;
8484using ::strrchr _LIBCPP_USING_IF_EXISTS;
8585using ::strspn _LIBCPP_USING_IF_EXISTS;
8686using ::strstr _LIBCPP_USING_IF_EXISTS;
87#ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS
8887using ::strtok _LIBCPP_USING_IF_EXISTS;
89#endif
9088using ::memset _LIBCPP_USING_IF_EXISTS;
9189using ::strerror _LIBCPP_USING_IF_EXISTS;
9290using ::strlen _LIBCPP_USING_IF_EXISTS;
lib/libcxx/include/ctgmath+1-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===-------------------------- ctgmath -----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/ctime+1-3
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===---------------------------- ctime -----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -79,12 +79,10 @@ using ::clock _LIBCPP_USING_IF_EXISTS;
7979using ::difftime _LIBCPP_USING_IF_EXISTS;
8080using ::mktime _LIBCPP_USING_IF_EXISTS;
8181using ::time _LIBCPP_USING_IF_EXISTS;
82#ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS
8382using ::asctime _LIBCPP_USING_IF_EXISTS;
8483using ::ctime _LIBCPP_USING_IF_EXISTS;
8584using ::gmtime _LIBCPP_USING_IF_EXISTS;
8685using ::localtime _LIBCPP_USING_IF_EXISTS;
87#endif
8886using ::strftime _LIBCPP_USING_IF_EXISTS;
8987#if _LIBCPP_STD_VER > 14 && defined(_LIBCPP_HAS_TIMESPEC_GET) && !defined(_LIBCPP_HAS_TIMESPEC_GET_NOT_ACTUALLY_PROVIDED)
9088using ::timespec_get _LIBCPP_USING_IF_EXISTS;
lib/libcxx/include/ctype.h+1-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===---------------------------- ctype.h ---------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/cwchar+1-9
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- cwchar -----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -137,13 +137,9 @@ using ::wcstod _LIBCPP_USING_IF_EXISTS;
137137using ::wcstof _LIBCPP_USING_IF_EXISTS;
138138using ::wcstold _LIBCPP_USING_IF_EXISTS;
139139using ::wcstol _LIBCPP_USING_IF_EXISTS;
140#ifndef _LIBCPP_HAS_NO_LONG_LONG
141140using ::wcstoll _LIBCPP_USING_IF_EXISTS;
142#endif // _LIBCPP_HAS_NO_LONG_LONG
143141using ::wcstoul _LIBCPP_USING_IF_EXISTS;
144#ifndef _LIBCPP_HAS_NO_LONG_LONG
145142using ::wcstoull _LIBCPP_USING_IF_EXISTS;
146#endif // _LIBCPP_HAS_NO_LONG_LONG
147143using ::wcscpy _LIBCPP_USING_IF_EXISTS;
148144using ::wcsncpy _LIBCPP_USING_IF_EXISTS;
149145using ::wcscat _LIBCPP_USING_IF_EXISTS;
......@@ -175,17 +171,13 @@ using ::wcrtomb _LIBCPP_USING_IF_EXISTS;
175171using ::mbsrtowcs _LIBCPP_USING_IF_EXISTS;
176172using ::wcsrtombs _LIBCPP_USING_IF_EXISTS;
177173
178#ifndef _LIBCPP_HAS_NO_STDIN
179174using ::getwchar _LIBCPP_USING_IF_EXISTS;
180175using ::vwscanf _LIBCPP_USING_IF_EXISTS;
181176using ::wscanf _LIBCPP_USING_IF_EXISTS;
182#endif
183177
184#ifndef _LIBCPP_HAS_NO_STDOUT
185178using ::putwchar _LIBCPP_USING_IF_EXISTS;
186179using ::vwprintf _LIBCPP_USING_IF_EXISTS;
187180using ::wprintf _LIBCPP_USING_IF_EXISTS;
188#endif
189181
190182_LIBCPP_END_NAMESPACE_STD
191183
lib/libcxx/include/cwctype+1-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- cwctype ----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/deque+42-64
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===---------------------------- deque -----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -129,7 +129,7 @@ public:
129129
130130template <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
131131 deque(InputIterator, InputIterator, Allocator = Allocator())
132 -> deque<typename iterator_traits<InputIterator>::value_type, Allocator>;
132 -> deque<typename iterator_traits<InputIterator>::value_type, Allocator>; // C++17
133133
134134template <class T, class Allocator>
135135 bool operator==(const deque<T,Allocator>& x, const deque<T,Allocator>& y);
......@@ -162,6 +162,7 @@ template <class T, class Allocator, class Predicate>
162162
163163#include <__config>
164164#include <__debug>
165#include <__iterator/iterator_traits.h>
165166#include <__split_buffer>
166167#include <__utility/forward.h>
167168#include <algorithm>
......@@ -908,45 +909,22 @@ move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
908909 return __r;
909910}
910911
911template <bool>
912class __deque_base_common
913{
914protected:
915 _LIBCPP_NORETURN void __throw_length_error() const;
916 _LIBCPP_NORETURN void __throw_out_of_range() const;
917};
918
919template <bool __b>
920void
921__deque_base_common<__b>::__throw_length_error() const
922{
923 _VSTD::__throw_length_error("deque");
924}
925
926template <bool __b>
927void
928__deque_base_common<__b>::__throw_out_of_range() const
929{
930 _VSTD::__throw_out_of_range("deque");
931}
932
933912template <class _Tp, class _Allocator>
934913class __deque_base
935 : protected __deque_base_common<true>
936914{
937915 __deque_base(const __deque_base& __c);
938916 __deque_base& operator=(const __deque_base& __c);
939917public:
940 typedef _Allocator allocator_type;
941 typedef allocator_traits<allocator_type> __alloc_traits;
942 typedef typename __alloc_traits::size_type size_type;
918 typedef _Allocator allocator_type;
919 typedef allocator_traits<allocator_type> __alloc_traits;
920 typedef typename __alloc_traits::size_type size_type;
943921
944 typedef _Tp value_type;
945 typedef value_type& reference;
946 typedef const value_type& const_reference;
947 typedef typename __alloc_traits::difference_type difference_type;
948 typedef typename __alloc_traits::pointer pointer;
949 typedef typename __alloc_traits::const_pointer const_pointer;
922 typedef _Tp value_type;
923 typedef value_type& reference;
924 typedef const value_type& const_reference;
925 typedef typename __alloc_traits::difference_type difference_type;
926 typedef typename __alloc_traits::pointer pointer;
927 typedef typename __alloc_traits::const_pointer const_pointer;
950928
951929 static const difference_type __block_size;
952930
......@@ -1281,20 +1259,20 @@ public:
12811259 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
12821260 "Allocator::value_type must be same type as value_type");
12831261
1284 typedef __deque_base<value_type, allocator_type> __base;
1262 typedef __deque_base<value_type, allocator_type> __base;
12851263
1286 typedef typename __base::__alloc_traits __alloc_traits;
1287 typedef typename __base::reference reference;
1288 typedef typename __base::const_reference const_reference;
1289 typedef typename __base::iterator iterator;
1290 typedef typename __base::const_iterator const_iterator;
1291 typedef typename __base::size_type size_type;
1292 typedef typename __base::difference_type difference_type;
1264 typedef typename __base::__alloc_traits __alloc_traits;
1265 typedef typename __base::reference reference;
1266 typedef typename __base::const_reference const_reference;
1267 typedef typename __base::iterator iterator;
1268 typedef typename __base::const_iterator const_iterator;
1269 typedef typename __base::size_type size_type;
1270 typedef typename __base::difference_type difference_type;
12931271
1294 typedef typename __base::pointer pointer;
1295 typedef typename __base::const_pointer const_pointer;
1296 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1297 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
1272 typedef typename __base::pointer pointer;
1273 typedef typename __base::const_pointer const_pointer;
1274 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1275 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
12981276
12991277 using typename __base::__deque_range;
13001278 using typename __base::__deque_block_range;
......@@ -1311,7 +1289,14 @@ public:
13111289 explicit deque(size_type __n, const _Allocator& __a);
13121290#endif
13131291 deque(size_type __n, const value_type& __v);
1314 deque(size_type __n, const value_type& __v, const allocator_type& __a);
1292
1293 template <class = __enable_if_t<__is_allocator<_Allocator>::value> >
1294 deque(size_type __n, const value_type& __v, const allocator_type& __a) : __base(__a)
1295 {
1296 if (__n > 0)
1297 __append(__n, __v);
1298 }
1299
13151300 template <class _InputIter>
13161301 deque(_InputIter __f, _InputIter __l,
13171302 typename enable_if<__is_cpp17_input_iterator<_InputIter>::value>::type* = 0);
......@@ -1588,23 +1573,24 @@ public:
15881573 void __move_assign(deque& __c, false_type);
15891574};
15901575
1591#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
1576#if _LIBCPP_STD_VER >= 17
15921577template<class _InputIterator,
15931578 class _Alloc = allocator<__iter_value_type<_InputIterator>>,
1594 class = _EnableIf<__is_allocator<_Alloc>::value>
1579 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
1580 class = enable_if_t<__is_allocator<_Alloc>::value>
15951581 >
15961582deque(_InputIterator, _InputIterator)
15971583 -> deque<__iter_value_type<_InputIterator>, _Alloc>;
15981584
15991585template<class _InputIterator,
16001586 class _Alloc,
1601 class = _EnableIf<__is_allocator<_Alloc>::value>
1587 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
1588 class = enable_if_t<__is_allocator<_Alloc>::value>
16021589 >
16031590deque(_InputIterator, _InputIterator, _Alloc)
16041591 -> deque<__iter_value_type<_InputIterator>, _Alloc>;
16051592#endif
16061593
1607
16081594template <class _Tp, class _Allocator>
16091595deque<_Tp, _Allocator>::deque(size_type __n)
16101596{
......@@ -1629,14 +1615,6 @@ deque<_Tp, _Allocator>::deque(size_type __n, const value_type& __v)
16291615 __append(__n, __v);
16301616}
16311617
1632template <class _Tp, class _Allocator>
1633deque<_Tp, _Allocator>::deque(size_type __n, const value_type& __v, const allocator_type& __a)
1634 : __base(__a)
1635{
1636 if (__n > 0)
1637 __append(__n, __v);
1638}
1639
16401618template <class _Tp, class _Allocator>
16411619template <class _InputIter>
16421620deque<_Tp, _Allocator>::deque(_InputIter __f, _InputIter __l,
......@@ -1672,7 +1650,7 @@ template <class _Tp, class _Allocator>
16721650deque<_Tp, _Allocator>&
16731651deque<_Tp, _Allocator>::operator=(const deque& __c)
16741652{
1675 if (this != &__c)
1653 if (this != _VSTD::addressof(__c))
16761654 {
16771655 __copy_assign_alloc(__c);
16781656 assign(__c.begin(), __c.end());
......@@ -1873,7 +1851,7 @@ typename deque<_Tp, _Allocator>::reference
18731851deque<_Tp, _Allocator>::at(size_type __i)
18741852{
18751853 if (__i >= __base::size())
1876 __base::__throw_out_of_range();
1854 _VSTD::__throw_out_of_range("deque");
18771855 size_type __p = __base::__start_ + __i;
18781856 return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size);
18791857}
......@@ -1884,7 +1862,7 @@ typename deque<_Tp, _Allocator>::const_reference
18841862deque<_Tp, _Allocator>::at(size_type __i) const
18851863{
18861864 if (__i >= __base::size())
1887 __base::__throw_out_of_range();
1865 _VSTD::__throw_out_of_range("deque");
18881866 size_type __p = __base::__start_ + __i;
18891867 return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size);
18901868}
......@@ -2237,7 +2215,7 @@ deque<_Tp, _Allocator>::insert(const_iterator __p, size_type __n, const value_ty
22372215 size_type __de = __base::size() - __pos;
22382216 if (__n > __de)
22392217 {
2240 for (size_type __m = __n - __de; __m; --__m, ++__i, ++__base::size())
2218 for (size_type __m = __n - __de; __m; --__m, (void) ++__i, ++__base::size())
22412219 __alloc_traits::construct(__a, _VSTD::addressof(*__i), __v);
22422220 __n = __de;
22432221 }
......@@ -2340,7 +2318,7 @@ deque<_Tp, _Allocator>::insert(const_iterator __p, _BiIter __f, _BiIter __l,
23402318 if (__n > 0)
23412319 {
23422320 iterator __oen = __old_end - __n;
2343 for (iterator __j = __oen; __j != __old_end; ++__i, ++__j, ++__base::size())
2321 for (iterator __j = __oen; __j != __old_end; ++__i, (void) ++__j, ++__base::size())
23442322 __alloc_traits::construct(__a, _VSTD::addressof(*__i), _VSTD::move(*__j));
23452323 if (__n < __de)
23462324 __old_end = _VSTD::move_backward(__old_end - __de, __oen, __old_end);
lib/libcxx/include/errno.h+1-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===-------------------------- errno.h -----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/exception+2-2
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===-------------------------- exception ---------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -328,6 +328,6 @@ rethrow_if_nested(const _Ep&,
328328{
329329}
330330
331} // std
331} // namespace std
332332
333333#endif // _LIBCPP_EXCEPTION
lib/libcxx/include/execution+6-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===------------------------- execution ---------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -11,9 +11,14 @@
1111#define _LIBCPP_EXECUTION
1212
1313#include <__config>
14#include <version>
1415
1516#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17
1617# include <__pstl_execution>
1718#endif
1819
20#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21#pragma GCC system_header
22#endif
23
1924#endif // _LIBCPP_EXECUTION
lib/libcxx/include/experimental/__config+5-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- __config ---------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -45,6 +45,10 @@
4545#define _LIBCPP_END_NAMESPACE_EXPERIMENTAL_FILESYSTEM \
4646 } } _LIBCPP_END_NAMESPACE_EXPERIMENTAL
4747
48#if !defined(__cpp_coroutines) || __cpp_coroutines < 201703L
49#define _LIBCPP_HAS_NO_EXPERIMENTAL_COROUTINES
50#endif
51
4852#define _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_COROUTINES \
4953 _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace coroutines_v1 {
5054
lib/libcxx/include/experimental/__memory+5-1
......@@ -10,13 +10,17 @@
1010#ifndef _LIBCPP_EXPERIMENTAL___MEMORY
1111#define _LIBCPP_EXPERIMENTAL___MEMORY
1212
13#include <__functional_base>
1314#include <__memory/allocator_arg_t.h>
1415#include <__memory/uses_allocator.h>
1516#include <experimental/__config>
1617#include <experimental/utility> // for erased_type
17#include <__functional_base>
1818#include <type_traits>
1919
20#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21#pragma GCC system_header
22#endif
23
2024_LIBCPP_BEGIN_NAMESPACE_LFTS
2125
2226template <
lib/libcxx/include/experimental/algorithm+3-10
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===-------------------------- algorithm ---------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -31,20 +31,15 @@ ForwardIterator search(ForwardIterator first, ForwardIterator last,
3131
3232*/
3333
34#include <experimental/__config>
34#include <__debug>
3535#include <algorithm>
36#include <experimental/__config>
3637#include <type_traits>
3738
38#include <__debug>
39
4039#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
4140#pragma GCC system_header
4241#endif
4342
44_LIBCPP_PUSH_MACROS
45#include <__undef_macros>
46
47
4843_LIBCPP_BEGIN_NAMESPACE_LFTS
4944
5045template <class _ForwardIterator, class _Searcher>
......@@ -54,6 +49,4 @@ _ForwardIterator search(_ForwardIterator __f, _ForwardIterator __l, const _Searc
5449
5550_LIBCPP_END_NAMESPACE_LFTS
5651
57_LIBCPP_POP_MACROS
58
5952#endif /* _LIBCPP_EXPERIMENTAL_ALGORITHM */
lib/libcxx/include/experimental/coroutine+8-8
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===----------------------------- coroutine -----------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -45,19 +45,19 @@ template <class P> struct hash<coroutine_handle<P>>;
4545
4646 */
4747
48#include <__debug>
49#include <cstddef>
4850#include <experimental/__config>
49#include <new>
50#include <type_traits>
5151#include <functional>
5252#include <memory> // for hash<T*>
53#include <cstddef>
54#include <__debug>
53#include <new>
54#include <type_traits>
5555
5656#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
5757#pragma GCC system_header
5858#endif
5959
60#ifdef _LIBCPP_HAS_NO_COROUTINES
60#ifdef _LIBCPP_HAS_NO_EXPERIMENTAL_COROUTINES
6161# if defined(_LIBCPP_WARNING)
6262 _LIBCPP_WARNING("<experimental/coroutine> cannot be used with this compiler")
6363# else
......@@ -65,7 +65,7 @@ template <class P> struct hash<coroutine_handle<P>>;
6565# endif
6666#endif
6767
68#ifndef _LIBCPP_HAS_NO_COROUTINES
68#ifndef _LIBCPP_HAS_NO_EXPERIMENTAL_COROUTINES
6969
7070_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_COROUTINES
7171
......@@ -329,6 +329,6 @@ struct hash<_VSTD_CORO::coroutine_handle<_Tp> > {
329329
330330_LIBCPP_END_NAMESPACE_STD
331331
332#endif // !defined(_LIBCPP_HAS_NO_COROUTINES)
332#endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_COROUTINES)
333333
334334#endif /* _LIBCPP_EXPERIMENTAL_COROUTINE */
lib/libcxx/include/experimental/deque+2-2
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- deque ------------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -28,8 +28,8 @@ namespace pmr {
2828
2929 */
3030
31#include <experimental/__config>
3231#include <deque>
32#include <experimental/__config>
3333#include <experimental/memory_resource>
3434
3535#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
lib/libcxx/include/experimental/filesystem+1-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- filesystem -------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/experimental/forward_list+2-2
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- forward_list -----------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -29,8 +29,8 @@ namespace pmr {
2929 */
3030
3131#include <experimental/__config>
32#include <forward_list>
3332#include <experimental/memory_resource>
33#include <forward_list>
3434
3535#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
3636#pragma GCC system_header
lib/libcxx/include/experimental/functional+5-7
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===-------------------------- functional --------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -86,16 +86,15 @@ inline namespace fundamentals_v1 {
8686
8787*/
8888
89#include <__debug>
8990#include <__memory/uses_allocator.h>
91#include <algorithm>
92#include <array>
9093#include <experimental/__config>
9194#include <functional>
92#include <algorithm>
9395#include <type_traits>
94#include <vector>
95#include <array>
9696#include <unordered_map>
97
98#include <__debug>
97#include <vector>
9998
10099#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
101100#pragma GCC system_header
......@@ -104,7 +103,6 @@ inline namespace fundamentals_v1 {
104103_LIBCPP_PUSH_MACROS
105104#include <__undef_macros>
106105
107
108106_LIBCPP_BEGIN_NAMESPACE_LFTS
109107
110108#if _LIBCPP_STD_VER > 11
lib/libcxx/include/experimental/iterator+10-7
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===----------------------------- iterator -------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -52,15 +52,18 @@ namespace std {
5252
5353*/
5454
55#include <experimental/__config>
56
57#if _LIBCPP_STD_VER > 11
58
5955#include <__memory/addressof.h>
60#include <__utility/move.h>
6156#include <__utility/forward.h>
57#include <__utility/move.h>
58#include <experimental/__config>
6259#include <iterator>
6360
61#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
62#pragma GCC system_header
63#endif
64
65#if _LIBCPP_STD_VER > 11
66
6467_LIBCPP_BEGIN_NAMESPACE_LFTS
6568
6669template <class _Delim, class _CharT = char, class _Traits = char_traits<_CharT>>
......@@ -111,6 +114,6 @@ make_ostream_joiner(basic_ostream<_CharT, _Traits>& __os, _Delim && __d)
111114
112115_LIBCPP_END_NAMESPACE_LFTS
113116
114#endif /* _LIBCPP_STD_VER > 11 */
117#endif // _LIBCPP_STD_VER > 11
115118
116119#endif // _LIBCPP_EXPERIMENTAL_ITERATOR
lib/libcxx/include/experimental/list+2-2
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- list ------------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -29,8 +29,8 @@ namespace pmr {
2929 */
3030
3131#include <experimental/__config>
32#include <list>
3332#include <experimental/memory_resource>
33#include <list>
3434
3535#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
3636#pragma GCC system_header
lib/libcxx/include/experimental/map+2-2
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===----------------------------- map ------------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -34,8 +34,8 @@ namespace pmr {
3434 */
3535
3636#include <experimental/__config>
37#include <map>
3837#include <experimental/memory_resource>
38#include <map>
3939
4040#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
4141#pragma GCC system_header
lib/libcxx/include/experimental/memory_resource+9-15
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===------------------------ memory_resource -----------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -64,18 +64,18 @@ namespace pmr {
6464
6565 */
6666
67#include <__debug>
68#include <__tuple>
69#include <cstddef>
70#include <cstdlib>
6771#include <experimental/__config>
6872#include <experimental/__memory>
6973#include <limits>
7074#include <memory>
7175#include <new>
7276#include <stdexcept>
73#include <__tuple>
7477#include <type_traits>
7578#include <utility>
76#include <cstddef>
77#include <cstdlib>
78#include <__debug>
7979
8080#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
8181#pragma GCC system_header
......@@ -183,11 +183,8 @@ public:
183183 // 8.6.3, memory.polymorphic.allocator.mem
184184 _LIBCPP_INLINE_VISIBILITY
185185 _ValueType* allocate(size_t __n) {
186 if (__n > __max_size()) {
187 __throw_length_error(
188 "std::experimental::pmr::polymorphic_allocator<T>::allocate(size_t n)"
189 " 'n' exceeds maximum supported size");
190 }
186 if (__n > __max_size())
187 __throw_bad_array_new_length();
191188 return static_cast<_ValueType*>(
192189 __res_->allocate(__n * sizeof(_ValueType), _LIBCPP_ALIGNOF(_ValueType))
193190 );
......@@ -384,11 +381,8 @@ public:
384381private:
385382 virtual void * do_allocate(size_t __bytes, size_t)
386383 {
387 if (__bytes > __max_size()) {
388 __throw_length_error(
389 "std::experimental::pmr::resource_adaptor<T>::do_allocate(size_t bytes, size_t align)"
390 " 'bytes' exceeds maximum supported size");
391 }
384 if (__bytes > __max_size())
385 __throw_bad_array_new_length();
392386 size_t __s = __aligned_allocation_size(__bytes, _MaxAlign) / _MaxAlign;
393387 return __alloc_.allocate(__s);
394388 }
lib/libcxx/include/experimental/propagate_const+5-6
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===------------------------ propagate_const -----------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -107,19 +107,18 @@
107107*/
108108
109109#include <experimental/__config>
110#include <functional>
111#include <type_traits>
112#include <utility>
113
110114#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
111115#pragma GCC system_header
112116#endif
113117
114118#if _LIBCPP_STD_VER > 11
115119
116#include <type_traits>
117#include <utility>
118#include <functional>
119
120120_LIBCPP_BEGIN_NAMESPACE_LFTS_V2
121121
122
123122template <class _Tp>
124123class propagate_const;
125124
lib/libcxx/include/experimental/regex+6-4
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===----------------------------- regex ----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -36,9 +36,9 @@ namespace pmr {
3636 */
3737
3838#include <experimental/__config>
39#include <regex>
40#include <experimental/string>
4139#include <experimental/memory_resource>
40#include <experimental/string>
41#include <regex>
4242
4343#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
4444#pragma GCC system_header
......@@ -52,9 +52,11 @@ using match_results =
5252 polymorphic_allocator<_VSTD::sub_match<_BiDirIter>>>;
5353
5454typedef match_results<const char*> cmatch;
55typedef match_results<const wchar_t*> wcmatch;
5655typedef match_results<_VSTD_LFTS_PMR::string::const_iterator> smatch;
56#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
57typedef match_results<const wchar_t*> wcmatch;
5758typedef match_results<_VSTD_LFTS_PMR::wstring::const_iterator> wsmatch;
59#endif
5860
5961_LIBCPP_END_NAMESPACE_LFTS_PMR
6062
lib/libcxx/include/experimental/set+2-2
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- list ------------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -34,8 +34,8 @@ namespace pmr {
3434 */
3535
3636#include <experimental/__config>
37#include <set>
3837#include <experimental/memory_resource>
38#include <set>
3939
4040#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
4141#pragma GCC system_header
lib/libcxx/include/experimental/simd+16-18
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===------------------------------- simd ---------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -649,10 +649,10 @@ public:
649649
650650*/
651651
652#include <experimental/__config>
653652#include <algorithm>
654653#include <array>
655654#include <cstddef>
655#include <experimental/__config>
656656#include <functional>
657657
658658#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -689,7 +689,7 @@ class __simd_storage<_Tp, __simd_abi<_StorageKind::_Array, __num_element>> {
689689 friend struct simd_mask;
690690
691691public:
692 _Tp __get(size_t __index) const noexcept { return __storage_[__index]; };
692 _Tp __get(size_t __index) const noexcept { return __storage_[__index]; }
693693 void __set(size_t __index, _Tp __val) noexcept {
694694 __storage_[__index] = __val;
695695 }
......@@ -706,7 +706,7 @@ class __simd_storage<_Tp, __simd_abi<_StorageKind::_Scalar, 1>> {
706706 friend struct simd_mask;
707707
708708public:
709 _Tp __get(size_t __index) const noexcept { return (&__storage_)[__index]; };
709 _Tp __get(size_t __index) const noexcept { return (&__storage_)[__index]; }
710710 void __set(size_t __index, _Tp __val) noexcept {
711711 (&__storage_)[__index] = __val;
712712 }
......@@ -770,7 +770,7 @@ struct __vec_ext_traits {
770770 _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 29); \
771771 _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 30); \
772772 _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 31); \
773 _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 32);
773 _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 32)
774774
775775_LIBCPP_SPECIALIZE_VEC_EXT_32(char);
776776_LIBCPP_SPECIALIZE_VEC_EXT_32(char16_t);
......@@ -808,7 +808,7 @@ class __simd_storage<_Tp, __simd_abi<_StorageKind::_VecExt, __num_element>> {
808808 friend struct simd_mask;
809809
810810public:
811 _Tp __get(size_t __index) const noexcept { return __storage_[__index]; };
811 _Tp __get(size_t __index) const noexcept { return __storage_[__index]; }
812812 void __set(size_t __index, _Tp __val) noexcept {
813813 __storage_[__index] = __val;
814814 }
......@@ -963,7 +963,7 @@ template <int _Np>
963963using fixed_size = __simd_abi<_StorageKind::_Array, _Np>;
964964
965965template <class _Tp>
966_LIBCPP_INLINE_VAR constexpr size_t max_fixed_size = 32;
966inline constexpr size_t max_fixed_size = 32;
967967
968968template <class _Tp>
969969using compatible = fixed_size<16 / sizeof(_Tp)>;
......@@ -990,10 +990,10 @@ struct element_aligned_tag {};
990990struct vector_aligned_tag {};
991991template <size_t>
992992struct overaligned_tag {};
993_LIBCPP_INLINE_VAR constexpr element_aligned_tag element_aligned{};
994_LIBCPP_INLINE_VAR constexpr vector_aligned_tag vector_aligned{};
993inline constexpr element_aligned_tag element_aligned{};
994inline constexpr vector_aligned_tag vector_aligned{};
995995template <size_t _Np>
996_LIBCPP_INLINE_VAR constexpr overaligned_tag<_Np> overaligned{};
996inline constexpr overaligned_tag<_Np> overaligned{};
997997
998998// traits [simd.traits]
999999template <class _Tp>
......@@ -1032,14 +1032,13 @@ struct is_simd_flag_type<overaligned_tag<_Align>>
10321032 : std::integral_constant<bool, true> {};
10331033
10341034template <class _Tp>
1035_LIBCPP_INLINE_VAR constexpr bool is_abi_tag_v = is_abi_tag<_Tp>::value;
1035inline constexpr bool is_abi_tag_v = is_abi_tag<_Tp>::value;
10361036template <class _Tp>
1037_LIBCPP_INLINE_VAR constexpr bool is_simd_v = is_simd<_Tp>::value;
1037inline constexpr bool is_simd_v = is_simd<_Tp>::value;
10381038template <class _Tp>
1039_LIBCPP_INLINE_VAR constexpr bool is_simd_mask_v = is_simd_mask<_Tp>::value;
1039inline constexpr bool is_simd_mask_v = is_simd_mask<_Tp>::value;
10401040template <class _Tp>
1041_LIBCPP_INLINE_VAR constexpr bool is_simd_flag_type_v =
1042 is_simd_flag_type<_Tp>::value;
1041inline constexpr bool is_simd_flag_type_v = is_simd_flag_type<_Tp>::value;
10431042template <class _Tp, size_t _Np>
10441043struct abi_for_size {
10451044 using type = simd_abi::fixed_size<_Np>;
......@@ -1064,11 +1063,10 @@ template <class _Tp, class _Up = typename _Tp::value_type>
10641063struct memory_alignment;
10651064
10661065template <class _Tp, class _Abi = simd_abi::compatible<_Tp>>
1067_LIBCPP_INLINE_VAR constexpr size_t simd_size_v = simd_size<_Tp, _Abi>::value;
1066inline constexpr size_t simd_size_v = simd_size<_Tp, _Abi>::value;
10681067
10691068template <class _Tp, class _Up = typename _Tp::value_type>
1070_LIBCPP_INLINE_VAR constexpr size_t memory_alignment_v =
1071 memory_alignment<_Tp, _Up>::value;
1069inline constexpr size_t memory_alignment_v = memory_alignment<_Tp, _Up>::value;
10721070
10731071// class template simd [simd.class]
10741072template <class _Tp>
lib/libcxx/include/experimental/string+4-2
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- string ----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -38,8 +38,8 @@ namespace pmr {
3838 */
3939
4040#include <experimental/__config>
41#include <string>
4241#include <experimental/memory_resource>
42#include <string>
4343
4444#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
4545#pragma GCC system_header
......@@ -54,7 +54,9 @@ using basic_string =
5454typedef basic_string<char> string;
5555typedef basic_string<char16_t> u16string;
5656typedef basic_string<char32_t> u32string;
57#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
5758typedef basic_string<wchar_t> wstring;
59#endif
5860
5961_LIBCPP_END_NAMESPACE_LFTS_PMR
6062
lib/libcxx/include/experimental/type_traits+1-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===-------------------------- type_traits -------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/experimental/unordered_map+2-2
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===------------------------- unordered_map ------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -40,8 +40,8 @@ namespace pmr {
4040 */
4141
4242#include <experimental/__config>
43#include <unordered_map>
4443#include <experimental/memory_resource>
44#include <unordered_map>
4545
4646#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
4747#pragma GCC system_header
lib/libcxx/include/experimental/unordered_set+2-2
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===------------------------- unordered_set ------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -34,8 +34,8 @@ namespace pmr {
3434 */
3535
3636#include <experimental/__config>
37#include <unordered_set>
3837#include <experimental/memory_resource>
38#include <unordered_set>
3939
4040#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
4141#pragma GCC system_header
lib/libcxx/include/experimental/utility+1-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===-------------------------- utility ----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/experimental/vector+2-2
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- vector ------------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -29,8 +29,8 @@ namespace pmr {
2929 */
3030
3131#include <experimental/__config>
32#include <vector>
3332#include <experimental/memory_resource>
33#include <vector>
3434
3535#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
3636#pragma GCC system_header
lib/libcxx/include/ext/__hash+3-3
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===------------------------- hash_set ------------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -13,8 +13,8 @@
1313#pragma GCC system_header
1414
1515#include <__string>
16#include <string>
1716#include <cstring>
17#include <string>
1818
1919namespace __gnu_cxx {
2020
......@@ -129,6 +129,6 @@ template <> struct _LIBCPP_TEMPLATE_VIS hash<unsigned long>
129129 return __c;
130130 }
131131};
132}
132} // namespace __gnu_cxx
133133
134134#endif // _LIBCPP_EXT_HASH
lib/libcxx/include/ext/hash_map+3-3
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===-------------------------- hash_map ----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -203,10 +203,10 @@ template <class Key, class T, class Hash, class Pred, class Alloc>
203203
204204#include <__config>
205205#include <__hash_table>
206#include <ext/__hash>
206207#include <functional>
207208#include <stdexcept>
208209#include <type_traits>
209#include <ext/__hash>
210210
211211#if defined(__DEPRECATED) && __DEPRECATED
212212#if defined(_LIBCPP_WARNING)
......@@ -979,6 +979,6 @@ operator!=(const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
979979 return !(__x == __y);
980980}
981981
982} // __gnu_cxx
982} // namespace __gnu_cxx
983983
984984#endif // _LIBCPP_HASH_MAP
lib/libcxx/include/ext/hash_set+7-3
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===------------------------- hash_set ------------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -194,8 +194,8 @@ template <class Value, class Hash, class Pred, class Alloc>
194194
195195#include <__config>
196196#include <__hash_table>
197#include <functional>
198197#include <ext/__hash>
198#include <functional>
199199
200200#if defined(__DEPRECATED) && __DEPRECATED
201201#if defined(_LIBCPP_WARNING)
......@@ -205,6 +205,10 @@ template <class Value, class Hash, class Pred, class Alloc>
205205#endif
206206#endif
207207
208#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
209#pragma GCC system_header
210#endif
211
208212namespace __gnu_cxx {
209213
210214
......@@ -654,6 +658,6 @@ operator!=(const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
654658 return !(__x == __y);
655659}
656660
657} // __gnu_cxx
661} // namespace __gnu_cxx
658662
659663#endif // _LIBCPP_HASH_SET
lib/libcxx/include/fenv.h+1-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===---------------------------- math.h ----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/filesystem+31-2774
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- filesystem -------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -11,7 +11,7 @@
1111/*
1212 filesystem synopsis
1313
14 namespace std { namespace filesystem {
14 namespace std::filesystem {
1515
1616 class path;
1717
......@@ -48,13 +48,13 @@
4848
4949 // enable directory_iterator range-based for statements
5050 directory_iterator begin(directory_iterator iter) noexcept;
51 directory_iterator end(const directory_iterator&) noexcept;
51 directory_iterator end(directory_iterator) noexcept;
5252
5353 class recursive_directory_iterator;
5454
5555 // enable recursive_directory_iterator range-based for statements
5656 recursive_directory_iterator begin(recursive_directory_iterator iter) noexcept;
57 recursive_directory_iterator end(const recursive_directory_iterator&) noexcept;
57 recursive_directory_iterator end(recursive_directory_iterator) noexcept;
5858
5959 class file_status;
6060
......@@ -224,2789 +224,46 @@
224224 path weakly_canonical(path const& p);
225225 path weakly_canonical(path const& p, error_code& ec);
226226
227} // namespace std::filesystem
227228
228} } // namespaces std::filesystem
229template <>
230inline constexpr bool std::ranges::enable_borrowed_range<std::filesystem::directory_iterator> = true;
231template <>
232inline constexpr bool std::ranges::enable_borrowed_range<std::filesystem::recursive_directory_iterator> = true;
233
234template <>
235inline constexpr bool std::ranges::enable_view<std::filesystem::directory_iterator> = true;
236template <>
237inline constexpr bool std::ranges::enable_view<std::filesystem::recursive_directory_iterator> = true;
229238
230239*/
231240
232#include <__availability>
233241#include <__config>
234#include <__debug>
235#include <__utility/forward.h>
236#include <chrono>
242#include <__filesystem/copy_options.h>
243#include <__filesystem/directory_entry.h>
244#include <__filesystem/directory_iterator.h>
245#include <__filesystem/directory_options.h>
246#include <__filesystem/file_status.h>
247#include <__filesystem/file_time_type.h>
248#include <__filesystem/file_type.h>
249#include <__filesystem/filesystem_error.h>
250#include <__filesystem/operations.h>
251#include <__filesystem/path.h>
252#include <__filesystem/path_iterator.h>
253#include <__filesystem/perm_options.h>
254#include <__filesystem/perms.h>
255#include <__filesystem/recursive_directory_iterator.h>
256#include <__filesystem/space_info.h>
257#include <__filesystem/u8path.h>
237258#include <compare>
238#include <cstddef>
239#include <cstdlib>
240#include <iosfwd>
241#include <iterator>
242#include <memory>
243#include <stack>
244#include <string>
245#include <string_view>
246#include <system_error>
247#include <utility>
248259#include <version>
249260
250#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
251# include <locale>
252# include <iomanip> // for quoted
253#endif
254
255261#if defined(_LIBCPP_HAS_NO_FILESYSTEM_LIBRARY)
256# error "The Filesystem library is not supported by this configuration of libc++"
262# error "The Filesystem library is not supported since libc++ has been configured with LIBCXX_ENABLE_FILESYSTEM disabled"
257263#endif
258264
259265#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
260266#pragma GCC system_header
261267#endif
262268
263_LIBCPP_PUSH_MACROS
264#include <__undef_macros>
265
266#ifndef _LIBCPP_CXX03_LANG
267
268_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
269
270_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH
271
272typedef chrono::time_point<_FilesystemClock> file_time_type;
273
274struct _LIBCPP_TYPE_VIS space_info {
275 uintmax_t capacity;
276 uintmax_t free;
277 uintmax_t available;
278};
279
280// On Windows, the library never identifies files as block, character, fifo
281// or socket.
282enum class _LIBCPP_ENUM_VIS file_type : signed char {
283 none = 0,
284 not_found = -1,
285 regular = 1,
286 directory = 2,
287 symlink = 3,
288 block = 4,
289 character = 5,
290 fifo = 6,
291 socket = 7,
292 unknown = 8
293};
294
295// On Windows, these permission bits map to one single readonly flag per
296// file, and the executable bit is always returned as set. When setting
297// permissions, as long as the write bit is set for either owner, group or
298// others, the readonly flag is cleared.
299enum class _LIBCPP_ENUM_VIS perms : unsigned {
300 none = 0,
301
302 owner_read = 0400,
303 owner_write = 0200,
304 owner_exec = 0100,
305 owner_all = 0700,
306
307 group_read = 040,
308 group_write = 020,
309 group_exec = 010,
310 group_all = 070,
311
312 others_read = 04,
313 others_write = 02,
314 others_exec = 01,
315 others_all = 07,
316
317 all = 0777,
318
319 set_uid = 04000,
320 set_gid = 02000,
321 sticky_bit = 01000,
322 mask = 07777,
323 unknown = 0xFFFF,
324};
325
326_LIBCPP_INLINE_VISIBILITY
327inline constexpr perms operator&(perms _LHS, perms _RHS) {
328 return static_cast<perms>(static_cast<unsigned>(_LHS) &
329 static_cast<unsigned>(_RHS));
330}
331
332_LIBCPP_INLINE_VISIBILITY
333inline constexpr perms operator|(perms _LHS, perms _RHS) {
334 return static_cast<perms>(static_cast<unsigned>(_LHS) |
335 static_cast<unsigned>(_RHS));
336}
337
338_LIBCPP_INLINE_VISIBILITY
339inline constexpr perms operator^(perms _LHS, perms _RHS) {
340 return static_cast<perms>(static_cast<unsigned>(_LHS) ^
341 static_cast<unsigned>(_RHS));
342}
343
344_LIBCPP_INLINE_VISIBILITY
345inline constexpr perms operator~(perms _LHS) {
346 return static_cast<perms>(~static_cast<unsigned>(_LHS));
347}
348
349_LIBCPP_INLINE_VISIBILITY
350inline perms& operator&=(perms& _LHS, perms _RHS) { return _LHS = _LHS & _RHS; }
351
352_LIBCPP_INLINE_VISIBILITY
353inline perms& operator|=(perms& _LHS, perms _RHS) { return _LHS = _LHS | _RHS; }
354
355_LIBCPP_INLINE_VISIBILITY
356inline perms& operator^=(perms& _LHS, perms _RHS) { return _LHS = _LHS ^ _RHS; }
357
358enum class _LIBCPP_ENUM_VIS perm_options : unsigned char {
359 replace = 1,
360 add = 2,
361 remove = 4,
362 nofollow = 8
363};
364
365_LIBCPP_INLINE_VISIBILITY
366inline constexpr perm_options operator&(perm_options _LHS, perm_options _RHS) {
367 return static_cast<perm_options>(static_cast<unsigned>(_LHS) &
368 static_cast<unsigned>(_RHS));
369}
370
371_LIBCPP_INLINE_VISIBILITY
372inline constexpr perm_options operator|(perm_options _LHS, perm_options _RHS) {
373 return static_cast<perm_options>(static_cast<unsigned>(_LHS) |
374 static_cast<unsigned>(_RHS));
375}
376
377_LIBCPP_INLINE_VISIBILITY
378inline constexpr perm_options operator^(perm_options _LHS, perm_options _RHS) {
379 return static_cast<perm_options>(static_cast<unsigned>(_LHS) ^
380 static_cast<unsigned>(_RHS));
381}
382
383_LIBCPP_INLINE_VISIBILITY
384inline constexpr perm_options operator~(perm_options _LHS) {
385 return static_cast<perm_options>(~static_cast<unsigned>(_LHS));
386}
387
388_LIBCPP_INLINE_VISIBILITY
389inline perm_options& operator&=(perm_options& _LHS, perm_options _RHS) {
390 return _LHS = _LHS & _RHS;
391}
392
393_LIBCPP_INLINE_VISIBILITY
394inline perm_options& operator|=(perm_options& _LHS, perm_options _RHS) {
395 return _LHS = _LHS | _RHS;
396}
397
398_LIBCPP_INLINE_VISIBILITY
399inline perm_options& operator^=(perm_options& _LHS, perm_options _RHS) {
400 return _LHS = _LHS ^ _RHS;
401}
402
403enum class _LIBCPP_ENUM_VIS copy_options : unsigned short {
404 none = 0,
405 skip_existing = 1,
406 overwrite_existing = 2,
407 update_existing = 4,
408 recursive = 8,
409 copy_symlinks = 16,
410 skip_symlinks = 32,
411 directories_only = 64,
412 create_symlinks = 128,
413 create_hard_links = 256,
414 __in_recursive_copy = 512,
415};
416
417_LIBCPP_INLINE_VISIBILITY
418inline constexpr copy_options operator&(copy_options _LHS, copy_options _RHS) {
419 return static_cast<copy_options>(static_cast<unsigned short>(_LHS) &
420 static_cast<unsigned short>(_RHS));
421}
422
423_LIBCPP_INLINE_VISIBILITY
424inline constexpr copy_options operator|(copy_options _LHS, copy_options _RHS) {
425 return static_cast<copy_options>(static_cast<unsigned short>(_LHS) |
426 static_cast<unsigned short>(_RHS));
427}
428
429_LIBCPP_INLINE_VISIBILITY
430inline constexpr copy_options operator^(copy_options _LHS, copy_options _RHS) {
431 return static_cast<copy_options>(static_cast<unsigned short>(_LHS) ^
432 static_cast<unsigned short>(_RHS));
433}
434
435_LIBCPP_INLINE_VISIBILITY
436inline constexpr copy_options operator~(copy_options _LHS) {
437 return static_cast<copy_options>(~static_cast<unsigned short>(_LHS));
438}
439
440_LIBCPP_INLINE_VISIBILITY
441inline copy_options& operator&=(copy_options& _LHS, copy_options _RHS) {
442 return _LHS = _LHS & _RHS;
443}
444
445_LIBCPP_INLINE_VISIBILITY
446inline copy_options& operator|=(copy_options& _LHS, copy_options _RHS) {
447 return _LHS = _LHS | _RHS;
448}
449
450_LIBCPP_INLINE_VISIBILITY
451inline copy_options& operator^=(copy_options& _LHS, copy_options _RHS) {
452 return _LHS = _LHS ^ _RHS;
453}
454
455enum class _LIBCPP_ENUM_VIS directory_options : unsigned char {
456 none = 0,
457 follow_directory_symlink = 1,
458 skip_permission_denied = 2
459};
460
461_LIBCPP_INLINE_VISIBILITY
462inline constexpr directory_options operator&(directory_options _LHS,
463 directory_options _RHS) {
464 return static_cast<directory_options>(static_cast<unsigned char>(_LHS) &
465 static_cast<unsigned char>(_RHS));
466}
467
468_LIBCPP_INLINE_VISIBILITY
469inline constexpr directory_options operator|(directory_options _LHS,
470 directory_options _RHS) {
471 return static_cast<directory_options>(static_cast<unsigned char>(_LHS) |
472 static_cast<unsigned char>(_RHS));
473}
474
475_LIBCPP_INLINE_VISIBILITY
476inline constexpr directory_options operator^(directory_options _LHS,
477 directory_options _RHS) {
478 return static_cast<directory_options>(static_cast<unsigned char>(_LHS) ^
479 static_cast<unsigned char>(_RHS));
480}
481
482_LIBCPP_INLINE_VISIBILITY
483inline constexpr directory_options operator~(directory_options _LHS) {
484 return static_cast<directory_options>(~static_cast<unsigned char>(_LHS));
485}
486
487_LIBCPP_INLINE_VISIBILITY
488inline directory_options& operator&=(directory_options& _LHS,
489 directory_options _RHS) {
490 return _LHS = _LHS & _RHS;
491}
492
493_LIBCPP_INLINE_VISIBILITY
494inline directory_options& operator|=(directory_options& _LHS,
495 directory_options _RHS) {
496 return _LHS = _LHS | _RHS;
497}
498
499_LIBCPP_INLINE_VISIBILITY
500inline directory_options& operator^=(directory_options& _LHS,
501 directory_options _RHS) {
502 return _LHS = _LHS ^ _RHS;
503}
504
505class _LIBCPP_TYPE_VIS file_status {
506public:
507 // constructors
508 _LIBCPP_INLINE_VISIBILITY
509 file_status() noexcept : file_status(file_type::none) {}
510 _LIBCPP_INLINE_VISIBILITY
511 explicit file_status(file_type __ft, perms __prms = perms::unknown) noexcept
512 : __ft_(__ft),
513 __prms_(__prms) {}
514
515 file_status(const file_status&) noexcept = default;
516 file_status(file_status&&) noexcept = default;
517
518 _LIBCPP_INLINE_VISIBILITY
519 ~file_status() {}
520
521 file_status& operator=(const file_status&) noexcept = default;
522 file_status& operator=(file_status&&) noexcept = default;
523
524 // observers
525 _LIBCPP_INLINE_VISIBILITY
526 file_type type() const noexcept { return __ft_; }
527
528 _LIBCPP_INLINE_VISIBILITY
529 perms permissions() const noexcept { return __prms_; }
530
531 // modifiers
532 _LIBCPP_INLINE_VISIBILITY
533 void type(file_type __ft) noexcept { __ft_ = __ft; }
534
535 _LIBCPP_INLINE_VISIBILITY
536 void permissions(perms __p) noexcept { __prms_ = __p; }
537
538private:
539 file_type __ft_;
540 perms __prms_;
541};
542
543class _LIBCPP_TYPE_VIS directory_entry;
544
545template <class _Tp>
546struct __can_convert_char {
547 static const bool value = false;
548};
549template <class _Tp>
550struct __can_convert_char<const _Tp> : public __can_convert_char<_Tp> {};
551template <>
552struct __can_convert_char<char> {
553 static const bool value = true;
554 using __char_type = char;
555};
556template <>
557struct __can_convert_char<wchar_t> {
558 static const bool value = true;
559 using __char_type = wchar_t;
560};
561#ifndef _LIBCPP_HAS_NO_CHAR8_T
562template <>
563struct __can_convert_char<char8_t> {
564 static const bool value = true;
565 using __char_type = char8_t;
566};
567#endif
568template <>
569struct __can_convert_char<char16_t> {
570 static const bool value = true;
571 using __char_type = char16_t;
572};
573template <>
574struct __can_convert_char<char32_t> {
575 static const bool value = true;
576 using __char_type = char32_t;
577};
578
579template <class _ECharT>
580typename enable_if<__can_convert_char<_ECharT>::value, bool>::type
581__is_separator(_ECharT __e) {
582#if defined(_LIBCPP_WIN32API)
583 return __e == _ECharT('/') || __e == _ECharT('\\');
584#else
585 return __e == _ECharT('/');
586#endif
587}
588
589#ifndef _LIBCPP_HAS_NO_CHAR8_T
590typedef u8string __u8_string;
591#else
592typedef string __u8_string;
593#endif
594
595struct _NullSentinel {};
596
597template <class _Tp>
598using _Void = void;
599
600template <class _Tp, class = void>
601struct __is_pathable_string : public false_type {};
602
603template <class _ECharT, class _Traits, class _Alloc>
604struct __is_pathable_string<
605 basic_string<_ECharT, _Traits, _Alloc>,
606 _Void<typename __can_convert_char<_ECharT>::__char_type> >
607 : public __can_convert_char<_ECharT> {
608 using _Str = basic_string<_ECharT, _Traits, _Alloc>;
609 using _Base = __can_convert_char<_ECharT>;
610 static _ECharT const* __range_begin(_Str const& __s) { return __s.data(); }
611 static _ECharT const* __range_end(_Str const& __s) {
612 return __s.data() + __s.length();
613 }
614 static _ECharT __first_or_null(_Str const& __s) {
615 return __s.empty() ? _ECharT{} : __s[0];
616 }
617};
618
619template <class _ECharT, class _Traits>
620struct __is_pathable_string<
621 basic_string_view<_ECharT, _Traits>,
622 _Void<typename __can_convert_char<_ECharT>::__char_type> >
623 : public __can_convert_char<_ECharT> {
624 using _Str = basic_string_view<_ECharT, _Traits>;
625 using _Base = __can_convert_char<_ECharT>;
626 static _ECharT const* __range_begin(_Str const& __s) { return __s.data(); }
627 static _ECharT const* __range_end(_Str const& __s) {
628 return __s.data() + __s.length();
629 }
630 static _ECharT __first_or_null(_Str const& __s) {
631 return __s.empty() ? _ECharT{} : __s[0];
632 }
633};
634
635template <class _Source, class _DS = typename decay<_Source>::type,
636 class _UnqualPtrType =
637 typename remove_const<typename remove_pointer<_DS>::type>::type,
638 bool _IsCharPtr = is_pointer<_DS>::value&&
639 __can_convert_char<_UnqualPtrType>::value>
640struct __is_pathable_char_array : false_type {};
641
642template <class _Source, class _ECharT, class _UPtr>
643struct __is_pathable_char_array<_Source, _ECharT*, _UPtr, true>
644 : __can_convert_char<typename remove_const<_ECharT>::type> {
645 using _Base = __can_convert_char<typename remove_const<_ECharT>::type>;
646
647 static _ECharT const* __range_begin(const _ECharT* __b) { return __b; }
648 static _ECharT const* __range_end(const _ECharT* __b) {
649 using _Iter = const _ECharT*;
650 const _ECharT __sentinel = _ECharT{};
651 _Iter __e = __b;
652 for (; *__e != __sentinel; ++__e)
653 ;
654 return __e;
655 }
656
657 static _ECharT __first_or_null(const _ECharT* __b) { return *__b; }
658};
659
660template <class _Iter, bool _IsIt = __is_cpp17_input_iterator<_Iter>::value,
661 class = void>
662struct __is_pathable_iter : false_type {};
663
664template <class _Iter>
665struct __is_pathable_iter<
666 _Iter, true,
667 _Void<typename __can_convert_char<
668 typename iterator_traits<_Iter>::value_type>::__char_type> >
669 : __can_convert_char<typename iterator_traits<_Iter>::value_type> {
670 using _ECharT = typename iterator_traits<_Iter>::value_type;
671 using _Base = __can_convert_char<_ECharT>;
672
673 static _Iter __range_begin(_Iter __b) { return __b; }
674 static _NullSentinel __range_end(_Iter) { return _NullSentinel{}; }
675
676 static _ECharT __first_or_null(_Iter __b) { return *__b; }
677};
678
679template <class _Tp, bool _IsStringT = __is_pathable_string<_Tp>::value,
680 bool _IsCharIterT = __is_pathable_char_array<_Tp>::value,
681 bool _IsIterT = !_IsCharIterT && __is_pathable_iter<_Tp>::value>
682struct __is_pathable : false_type {
683 static_assert(!_IsStringT && !_IsCharIterT && !_IsIterT, "Must all be false");
684};
685
686template <class _Tp>
687struct __is_pathable<_Tp, true, false, false> : __is_pathable_string<_Tp> {};
688
689template <class _Tp>
690struct __is_pathable<_Tp, false, true, false> : __is_pathable_char_array<_Tp> {
691};
692
693template <class _Tp>
694struct __is_pathable<_Tp, false, false, true> : __is_pathable_iter<_Tp> {};
695
696#if defined(_LIBCPP_WIN32API)
697typedef wstring __path_string;
698typedef wchar_t __path_value;
699#else
700typedef string __path_string;
701typedef char __path_value;
702#endif
703
704#if defined(_LIBCPP_WIN32API)
705_LIBCPP_FUNC_VIS
706size_t __wide_to_char(const wstring&, char*, size_t);
707_LIBCPP_FUNC_VIS
708size_t __char_to_wide(const string&, wchar_t*, size_t);
709#endif
710
711template <class _ECharT>
712struct _PathCVT;
713
714#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
715template <class _ECharT>
716struct _PathCVT {
717 static_assert(__can_convert_char<_ECharT>::value,
718 "Char type not convertible");
719
720 typedef __narrow_to_utf8<sizeof(_ECharT) * __CHAR_BIT__> _Narrower;
721#if defined(_LIBCPP_WIN32API)
722 typedef __widen_from_utf8<sizeof(wchar_t) * __CHAR_BIT__> _Widener;
723#endif
724
725 static void __append_range(__path_string& __dest, _ECharT const* __b,
726 _ECharT const* __e) {
727#if defined(_LIBCPP_WIN32API)
728 string __utf8;
729 _Narrower()(back_inserter(__utf8), __b, __e);
730 _Widener()(back_inserter(__dest), __utf8.data(), __utf8.data() + __utf8.size());
731#else
732 _Narrower()(back_inserter(__dest), __b, __e);
733#endif
734 }
735
736 template <class _Iter>
737 static void __append_range(__path_string& __dest, _Iter __b, _Iter __e) {
738 static_assert(!is_same<_Iter, _ECharT*>::value, "Call const overload");
739 if (__b == __e)
740 return;
741 basic_string<_ECharT> __tmp(__b, __e);
742#if defined(_LIBCPP_WIN32API)
743 string __utf8;
744 _Narrower()(back_inserter(__utf8), __tmp.data(),
745 __tmp.data() + __tmp.length());
746 _Widener()(back_inserter(__dest), __utf8.data(), __utf8.data() + __utf8.size());
747#else
748 _Narrower()(back_inserter(__dest), __tmp.data(),
749 __tmp.data() + __tmp.length());
750#endif
751 }
752
753 template <class _Iter>
754 static void __append_range(__path_string& __dest, _Iter __b, _NullSentinel) {
755 static_assert(!is_same<_Iter, _ECharT*>::value, "Call const overload");
756 const _ECharT __sentinel = _ECharT{};
757 if (*__b == __sentinel)
758 return;
759 basic_string<_ECharT> __tmp;
760 for (; *__b != __sentinel; ++__b)
761 __tmp.push_back(*__b);
762#if defined(_LIBCPP_WIN32API)
763 string __utf8;
764 _Narrower()(back_inserter(__utf8), __tmp.data(),
765 __tmp.data() + __tmp.length());
766 _Widener()(back_inserter(__dest), __utf8.data(), __utf8.data() + __utf8.size());
767#else
768 _Narrower()(back_inserter(__dest), __tmp.data(),
769 __tmp.data() + __tmp.length());
770#endif
771 }
772
773 template <class _Source>
774 static void __append_source(__path_string& __dest, _Source const& __s) {
775 using _Traits = __is_pathable<_Source>;
776 __append_range(__dest, _Traits::__range_begin(__s),
777 _Traits::__range_end(__s));
778 }
779};
780#endif // !_LIBCPP_HAS_NO_LOCALIZATION
781
782template <>
783struct _PathCVT<__path_value> {
784
785 template <class _Iter>
786 static typename enable_if<__is_exactly_cpp17_input_iterator<_Iter>::value>::type
787 __append_range(__path_string& __dest, _Iter __b, _Iter __e) {
788 for (; __b != __e; ++__b)
789 __dest.push_back(*__b);
790 }
791
792 template <class _Iter>
793 static typename enable_if<__is_cpp17_forward_iterator<_Iter>::value>::type
794 __append_range(__path_string& __dest, _Iter __b, _Iter __e) {
795 __dest.append(__b, __e);
796 }
797
798 template <class _Iter>
799 static void __append_range(__path_string& __dest, _Iter __b, _NullSentinel) {
800 const char __sentinel = char{};
801 for (; *__b != __sentinel; ++__b)
802 __dest.push_back(*__b);
803 }
804
805 template <class _Source>
806 static void __append_source(__path_string& __dest, _Source const& __s) {
807 using _Traits = __is_pathable<_Source>;
808 __append_range(__dest, _Traits::__range_begin(__s),
809 _Traits::__range_end(__s));
810 }
811};
812
813#if defined(_LIBCPP_WIN32API)
814template <>
815struct _PathCVT<char> {
816
817 static void
818 __append_string(__path_string& __dest, const basic_string<char> &__str) {
819 size_t __size = __char_to_wide(__str, nullptr, 0);
820 size_t __pos = __dest.size();
821 __dest.resize(__pos + __size);
822 __char_to_wide(__str, const_cast<__path_value*>(__dest.data()) + __pos, __size);
823 }
824
825 template <class _Iter>
826 static typename enable_if<__is_exactly_cpp17_input_iterator<_Iter>::value>::type
827 __append_range(__path_string& __dest, _Iter __b, _Iter __e) {
828 basic_string<char> __tmp(__b, __e);
829 __append_string(__dest, __tmp);
830 }
831
832 template <class _Iter>
833 static typename enable_if<__is_cpp17_forward_iterator<_Iter>::value>::type
834 __append_range(__path_string& __dest, _Iter __b, _Iter __e) {
835 basic_string<char> __tmp(__b, __e);
836 __append_string(__dest, __tmp);
837 }
838
839 template <class _Iter>
840 static void __append_range(__path_string& __dest, _Iter __b, _NullSentinel) {
841 const char __sentinel = char{};
842 basic_string<char> __tmp;
843 for (; *__b != __sentinel; ++__b)
844 __tmp.push_back(*__b);
845 __append_string(__dest, __tmp);
846 }
847
848 template <class _Source>
849 static void __append_source(__path_string& __dest, _Source const& __s) {
850 using _Traits = __is_pathable<_Source>;
851 __append_range(__dest, _Traits::__range_begin(__s),
852 _Traits::__range_end(__s));
853 }
854};
855
856template <class _ECharT>
857struct _PathExport {
858 typedef __narrow_to_utf8<sizeof(wchar_t) * __CHAR_BIT__> _Narrower;
859 typedef __widen_from_utf8<sizeof(_ECharT) * __CHAR_BIT__> _Widener;
860
861 template <class _Str>
862 static void __append(_Str& __dest, const __path_string& __src) {
863 string __utf8;
864 _Narrower()(back_inserter(__utf8), __src.data(), __src.data() + __src.size());
865 _Widener()(back_inserter(__dest), __utf8.data(), __utf8.data() + __utf8.size());
866 }
867};
868
869template <>
870struct _PathExport<char> {
871 template <class _Str>
872 static void __append(_Str& __dest, const __path_string& __src) {
873 size_t __size = __wide_to_char(__src, nullptr, 0);
874 size_t __pos = __dest.size();
875 __dest.resize(__size);
876 __wide_to_char(__src, const_cast<char*>(__dest.data()) + __pos, __size);
877 }
878};
879
880template <>
881struct _PathExport<wchar_t> {
882 template <class _Str>
883 static void __append(_Str& __dest, const __path_string& __src) {
884 __dest.append(__src.begin(), __src.end());
885 }
886};
887
888template <>
889struct _PathExport<char16_t> {
890 template <class _Str>
891 static void __append(_Str& __dest, const __path_string& __src) {
892 __dest.append(__src.begin(), __src.end());
893 }
894};
895
896#ifndef _LIBCPP_HAS_NO_CHAR8_T
897template <>
898struct _PathExport<char8_t> {
899 typedef __narrow_to_utf8<sizeof(wchar_t) * __CHAR_BIT__> _Narrower;
900
901 template <class _Str>
902 static void __append(_Str& __dest, const __path_string& __src) {
903 _Narrower()(back_inserter(__dest), __src.data(), __src.data() + __src.size());
904 }
905};
906#endif /* !_LIBCPP_HAS_NO_CHAR8_T */
907#endif /* _LIBCPP_WIN32API */
908
909class _LIBCPP_TYPE_VIS path {
910 template <class _SourceOrIter, class _Tp = path&>
911 using _EnableIfPathable =
912 typename enable_if<__is_pathable<_SourceOrIter>::value, _Tp>::type;
913
914 template <class _Tp>
915 using _SourceChar = typename __is_pathable<_Tp>::__char_type;
916
917 template <class _Tp>
918 using _SourceCVT = _PathCVT<_SourceChar<_Tp> >;
919
920public:
921#if defined(_LIBCPP_WIN32API)
922 typedef wchar_t value_type;
923 static constexpr value_type preferred_separator = L'\\';
924#else
925 typedef char value_type;
926 static constexpr value_type preferred_separator = '/';
927#endif
928 typedef basic_string<value_type> string_type;
929 typedef basic_string_view<value_type> __string_view;
930
931 enum _LIBCPP_ENUM_VIS format : unsigned char {
932 auto_format,
933 native_format,
934 generic_format
935 };
936
937 // constructors and destructor
938 _LIBCPP_INLINE_VISIBILITY path() noexcept {}
939 _LIBCPP_INLINE_VISIBILITY path(const path& __p) : __pn_(__p.__pn_) {}
940 _LIBCPP_INLINE_VISIBILITY path(path&& __p) noexcept
941 : __pn_(_VSTD::move(__p.__pn_)) {}
942
943 _LIBCPP_INLINE_VISIBILITY
944 path(string_type&& __s, format = format::auto_format) noexcept
945 : __pn_(_VSTD::move(__s)) {}
946
947 template <class _Source, class = _EnableIfPathable<_Source, void> >
948 path(const _Source& __src, format = format::auto_format) {
949 _SourceCVT<_Source>::__append_source(__pn_, __src);
950 }
951
952 template <class _InputIt>
953 path(_InputIt __first, _InputIt __last, format = format::auto_format) {
954 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
955 _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
956 }
957
958#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
959 // TODO Implement locale conversions.
960 template <class _Source, class = _EnableIfPathable<_Source, void> >
961 path(const _Source& __src, const locale& __loc, format = format::auto_format);
962 template <class _InputIt>
963 path(_InputIt __first, _InputIt _last, const locale& __loc,
964 format = format::auto_format);
965#endif
966
967 _LIBCPP_INLINE_VISIBILITY
968 ~path() = default;
969
970 // assignments
971 _LIBCPP_INLINE_VISIBILITY
972 path& operator=(const path& __p) {
973 __pn_ = __p.__pn_;
974 return *this;
975 }
976
977 _LIBCPP_INLINE_VISIBILITY
978 path& operator=(path&& __p) noexcept {
979 __pn_ = _VSTD::move(__p.__pn_);
980 return *this;
981 }
982
983 _LIBCPP_INLINE_VISIBILITY
984 path& operator=(string_type&& __s) noexcept {
985 __pn_ = _VSTD::move(__s);
986 return *this;
987 }
988
989 _LIBCPP_INLINE_VISIBILITY
990 path& assign(string_type&& __s) noexcept {
991 __pn_ = _VSTD::move(__s);
992 return *this;
993 }
994
995 template <class _Source>
996 _LIBCPP_INLINE_VISIBILITY _EnableIfPathable<_Source>
997 operator=(const _Source& __src) {
998 return this->assign(__src);
999 }
1000
1001 template <class _Source>
1002 _EnableIfPathable<_Source> assign(const _Source& __src) {
1003 __pn_.clear();
1004 _SourceCVT<_Source>::__append_source(__pn_, __src);
1005 return *this;
1006 }
1007
1008 template <class _InputIt>
1009 path& assign(_InputIt __first, _InputIt __last) {
1010 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
1011 __pn_.clear();
1012 _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
1013 return *this;
1014 }
1015
1016public:
1017 // appends
1018#if defined(_LIBCPP_WIN32API)
1019 path& operator/=(const path& __p) {
1020 auto __p_root_name = __p.__root_name();
1021 auto __p_root_name_size = __p_root_name.size();
1022 if (__p.is_absolute() ||
1023 (!__p_root_name.empty() && __p_root_name != root_name())) {
1024 __pn_ = __p.__pn_;
1025 return *this;
1026 }
1027 if (__p.has_root_directory()) {
1028 path __root_name_str = root_name();
1029 __pn_ = __root_name_str.native();
1030 __pn_ += __string_view(__p.__pn_).substr(__p_root_name_size);
1031 return *this;
1032 }
1033 if (has_filename() || (!has_root_directory() && is_absolute()))
1034 __pn_ += preferred_separator;
1035 __pn_ += __string_view(__p.__pn_).substr(__p_root_name_size);
1036 return *this;
1037 }
1038 template <class _Source>
1039 _LIBCPP_INLINE_VISIBILITY _EnableIfPathable<_Source>
1040 operator/=(const _Source& __src) {
1041 return operator/=(path(__src));
1042 }
1043
1044 template <class _Source>
1045 _EnableIfPathable<_Source> append(const _Source& __src) {
1046 return operator/=(path(__src));
1047 }
1048
1049 template <class _InputIt>
1050 path& append(_InputIt __first, _InputIt __last) {
1051 return operator/=(path(__first, __last));
1052 }
1053#else
1054 path& operator/=(const path& __p) {
1055 if (__p.is_absolute()) {
1056 __pn_ = __p.__pn_;
1057 return *this;
1058 }
1059 if (has_filename())
1060 __pn_ += preferred_separator;
1061 __pn_ += __p.native();
1062 return *this;
1063 }
1064
1065 // FIXME: Use _LIBCPP_DIAGNOSE_WARNING to produce a diagnostic when __src
1066 // is known at compile time to be "/' since the user almost certainly intended
1067 // to append a separator instead of overwriting the path with "/"
1068 template <class _Source>
1069 _LIBCPP_INLINE_VISIBILITY _EnableIfPathable<_Source>
1070 operator/=(const _Source& __src) {
1071 return this->append(__src);
1072 }
1073
1074 template <class _Source>
1075 _EnableIfPathable<_Source> append(const _Source& __src) {
1076 using _Traits = __is_pathable<_Source>;
1077 using _CVT = _PathCVT<_SourceChar<_Source> >;
1078 bool __source_is_absolute = __is_separator(_Traits::__first_or_null(__src));
1079 if (__source_is_absolute)
1080 __pn_.clear();
1081 else if (has_filename())
1082 __pn_ += preferred_separator;
1083 _CVT::__append_source(__pn_, __src);
1084 return *this;
1085 }
1086
1087 template <class _InputIt>
1088 path& append(_InputIt __first, _InputIt __last) {
1089 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
1090 static_assert(__can_convert_char<_ItVal>::value, "Must convertible");
1091 using _CVT = _PathCVT<_ItVal>;
1092 if (__first != __last && __is_separator(*__first))
1093 __pn_.clear();
1094 else if (has_filename())
1095 __pn_ += preferred_separator;
1096 _CVT::__append_range(__pn_, __first, __last);
1097 return *this;
1098 }
1099#endif
1100
1101 // concatenation
1102 _LIBCPP_INLINE_VISIBILITY
1103 path& operator+=(const path& __x) {
1104 __pn_ += __x.__pn_;
1105 return *this;
1106 }
1107
1108 _LIBCPP_INLINE_VISIBILITY
1109 path& operator+=(const string_type& __x) {
1110 __pn_ += __x;
1111 return *this;
1112 }
1113
1114 _LIBCPP_INLINE_VISIBILITY
1115 path& operator+=(__string_view __x) {
1116 __pn_ += __x;
1117 return *this;
1118 }
1119
1120 _LIBCPP_INLINE_VISIBILITY
1121 path& operator+=(const value_type* __x) {
1122 __pn_ += __x;
1123 return *this;
1124 }
1125
1126 _LIBCPP_INLINE_VISIBILITY
1127 path& operator+=(value_type __x) {
1128 __pn_ += __x;
1129 return *this;
1130 }
1131
1132 template <class _ECharT>
1133 typename enable_if<__can_convert_char<_ECharT>::value, path&>::type
1134 operator+=(_ECharT __x) {
1135 _PathCVT<_ECharT>::__append_source(__pn_,
1136 basic_string_view<_ECharT>(&__x, 1));
1137 return *this;
1138 }
1139
1140 template <class _Source>
1141 _EnableIfPathable<_Source> operator+=(const _Source& __x) {
1142 return this->concat(__x);
1143 }
1144
1145 template <class _Source>
1146 _EnableIfPathable<_Source> concat(const _Source& __x) {
1147 _SourceCVT<_Source>::__append_source(__pn_, __x);
1148 return *this;
1149 }
1150
1151 template <class _InputIt>
1152 path& concat(_InputIt __first, _InputIt __last) {
1153 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
1154 _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
1155 return *this;
1156 }
1157
1158 // modifiers
1159 _LIBCPP_INLINE_VISIBILITY
1160 void clear() noexcept { __pn_.clear(); }
1161
1162 path& make_preferred() {
1163#if defined(_LIBCPP_WIN32API)
1164 _VSTD::replace(__pn_.begin(), __pn_.end(), L'/', L'\\');
1165#endif
1166 return *this;
1167 }
1168
1169 _LIBCPP_INLINE_VISIBILITY
1170 path& remove_filename() {
1171 auto __fname = __filename();
1172 if (!__fname.empty())
1173 __pn_.erase(__fname.data() - __pn_.data());
1174 return *this;
1175 }
1176
1177 path& replace_filename(const path& __replacement) {
1178 remove_filename();
1179 return (*this /= __replacement);
1180 }
1181
1182 path& replace_extension(const path& __replacement = path());
1183
1184 _LIBCPP_INLINE_VISIBILITY
1185 void swap(path& __rhs) noexcept { __pn_.swap(__rhs.__pn_); }
1186
1187 // private helper to allow reserving memory in the path
1188 _LIBCPP_INLINE_VISIBILITY
1189 void __reserve(size_t __s) { __pn_.reserve(__s); }
1190
1191 // native format observers
1192 _LIBCPP_INLINE_VISIBILITY
1193 const string_type& native() const noexcept { return __pn_; }
1194
1195 _LIBCPP_INLINE_VISIBILITY
1196 const value_type* c_str() const noexcept { return __pn_.c_str(); }
1197
1198 _LIBCPP_INLINE_VISIBILITY operator string_type() const { return __pn_; }
1199
1200#if defined(_LIBCPP_WIN32API)
1201 _LIBCPP_INLINE_VISIBILITY _VSTD::wstring wstring() const { return __pn_; }
1202
1203 _VSTD::wstring generic_wstring() const {
1204 _VSTD::wstring __s;
1205 __s.resize(__pn_.size());
1206 _VSTD::replace_copy(__pn_.begin(), __pn_.end(), __s.begin(), '\\', '/');
1207 return __s;
1208 }
1209
1210#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
1211 template <class _ECharT, class _Traits = char_traits<_ECharT>,
1212 class _Allocator = allocator<_ECharT> >
1213 basic_string<_ECharT, _Traits, _Allocator>
1214 string(const _Allocator& __a = _Allocator()) const {
1215 using _Str = basic_string<_ECharT, _Traits, _Allocator>;
1216 _Str __s(__a);
1217 __s.reserve(__pn_.size());
1218 _PathExport<_ECharT>::__append(__s, __pn_);
1219 return __s;
1220 }
1221
1222 _LIBCPP_INLINE_VISIBILITY _VSTD::string string() const {
1223 return string<char>();
1224 }
1225 _LIBCPP_INLINE_VISIBILITY __u8_string u8string() const {
1226 using _CVT = __narrow_to_utf8<sizeof(wchar_t) * __CHAR_BIT__>;
1227 __u8_string __s;
1228 __s.reserve(__pn_.size());
1229 _CVT()(back_inserter(__s), __pn_.data(), __pn_.data() + __pn_.size());
1230 return __s;
1231 }
1232
1233 _LIBCPP_INLINE_VISIBILITY _VSTD::u16string u16string() const {
1234 return string<char16_t>();
1235 }
1236 _LIBCPP_INLINE_VISIBILITY _VSTD::u32string u32string() const {
1237 return string<char32_t>();
1238 }
1239
1240 // generic format observers
1241 template <class _ECharT, class _Traits = char_traits<_ECharT>,
1242 class _Allocator = allocator<_ECharT> >
1243 basic_string<_ECharT, _Traits, _Allocator>
1244 generic_string(const _Allocator& __a = _Allocator()) const {
1245 using _Str = basic_string<_ECharT, _Traits, _Allocator>;
1246 _Str __s = string<_ECharT, _Traits, _Allocator>(__a);
1247 // Note: This (and generic_u8string below) is slightly suboptimal as
1248 // it iterates twice over the string; once to convert it to the right
1249 // character type, and once to replace path delimiters.
1250 _VSTD::replace(__s.begin(), __s.end(),
1251 static_cast<_ECharT>('\\'), static_cast<_ECharT>('/'));
1252 return __s;
1253 }
1254
1255 _VSTD::string generic_string() const { return generic_string<char>(); }
1256 _VSTD::u16string generic_u16string() const { return generic_string<char16_t>(); }
1257 _VSTD::u32string generic_u32string() const { return generic_string<char32_t>(); }
1258 __u8_string generic_u8string() const {
1259 __u8_string __s = u8string();
1260 _VSTD::replace(__s.begin(), __s.end(), '\\', '/');
1261 return __s;
1262 }
1263#endif /* !_LIBCPP_HAS_NO_LOCALIZATION */
1264#else /* _LIBCPP_WIN32API */
1265
1266 _LIBCPP_INLINE_VISIBILITY _VSTD::string string() const { return __pn_; }
1267#ifndef _LIBCPP_HAS_NO_CHAR8_T
1268 _LIBCPP_INLINE_VISIBILITY _VSTD::u8string u8string() const { return _VSTD::u8string(__pn_.begin(), __pn_.end()); }
1269#else
1270 _LIBCPP_INLINE_VISIBILITY _VSTD::string u8string() const { return __pn_; }
1271#endif
1272
1273#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
1274 template <class _ECharT, class _Traits = char_traits<_ECharT>,
1275 class _Allocator = allocator<_ECharT> >
1276 basic_string<_ECharT, _Traits, _Allocator>
1277 string(const _Allocator& __a = _Allocator()) const {
1278 using _CVT = __widen_from_utf8<sizeof(_ECharT) * __CHAR_BIT__>;
1279 using _Str = basic_string<_ECharT, _Traits, _Allocator>;
1280 _Str __s(__a);
1281 __s.reserve(__pn_.size());
1282 _CVT()(back_inserter(__s), __pn_.data(), __pn_.data() + __pn_.size());
1283 return __s;
1284 }
1285
1286 _LIBCPP_INLINE_VISIBILITY _VSTD::wstring wstring() const {
1287 return string<wchar_t>();
1288 }
1289 _LIBCPP_INLINE_VISIBILITY _VSTD::u16string u16string() const {
1290 return string<char16_t>();
1291 }
1292 _LIBCPP_INLINE_VISIBILITY _VSTD::u32string u32string() const {
1293 return string<char32_t>();
1294 }
1295#endif /* !_LIBCPP_HAS_NO_LOCALIZATION */
1296
1297 // generic format observers
1298 _VSTD::string generic_string() const { return __pn_; }
1299#ifndef _LIBCPP_HAS_NO_CHAR8_T
1300 _VSTD::u8string generic_u8string() const { return _VSTD::u8string(__pn_.begin(), __pn_.end()); }
1301#else
1302 _VSTD::string generic_u8string() const { return __pn_; }
1303#endif
1304
1305#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
1306 template <class _ECharT, class _Traits = char_traits<_ECharT>,
1307 class _Allocator = allocator<_ECharT> >
1308 basic_string<_ECharT, _Traits, _Allocator>
1309 generic_string(const _Allocator& __a = _Allocator()) const {
1310 return string<_ECharT, _Traits, _Allocator>(__a);
1311 }
1312
1313 _VSTD::wstring generic_wstring() const { return string<wchar_t>(); }
1314 _VSTD::u16string generic_u16string() const { return string<char16_t>(); }
1315 _VSTD::u32string generic_u32string() const { return string<char32_t>(); }
1316#endif /* !_LIBCPP_HAS_NO_LOCALIZATION */
1317#endif /* !_LIBCPP_WIN32API */
1318
1319private:
1320 int __compare(__string_view) const;
1321 __string_view __root_name() const;
1322 __string_view __root_directory() const;
1323 __string_view __root_path_raw() const;
1324 __string_view __relative_path() const;
1325 __string_view __parent_path() const;
1326 __string_view __filename() const;
1327 __string_view __stem() const;
1328 __string_view __extension() const;
1329
1330public:
1331 // compare
1332 _LIBCPP_INLINE_VISIBILITY int compare(const path& __p) const noexcept {
1333 return __compare(__p.__pn_);
1334 }
1335 _LIBCPP_INLINE_VISIBILITY int compare(const string_type& __s) const {
1336 return __compare(__s);
1337 }
1338 _LIBCPP_INLINE_VISIBILITY int compare(__string_view __s) const {
1339 return __compare(__s);
1340 }
1341 _LIBCPP_INLINE_VISIBILITY int compare(const value_type* __s) const {
1342 return __compare(__s);
1343 }
1344
1345 // decomposition
1346 _LIBCPP_INLINE_VISIBILITY path root_name() const {
1347 return string_type(__root_name());
1348 }
1349 _LIBCPP_INLINE_VISIBILITY path root_directory() const {
1350 return string_type(__root_directory());
1351 }
1352 _LIBCPP_INLINE_VISIBILITY path root_path() const {
1353#if defined(_LIBCPP_WIN32API)
1354 return string_type(__root_path_raw());
1355#else
1356 return root_name().append(string_type(__root_directory()));
1357#endif
1358 }
1359 _LIBCPP_INLINE_VISIBILITY path relative_path() const {
1360 return string_type(__relative_path());
1361 }
1362 _LIBCPP_INLINE_VISIBILITY path parent_path() const {
1363 return string_type(__parent_path());
1364 }
1365 _LIBCPP_INLINE_VISIBILITY path filename() const {
1366 return string_type(__filename());
1367 }
1368 _LIBCPP_INLINE_VISIBILITY path stem() const { return string_type(__stem()); }
1369 _LIBCPP_INLINE_VISIBILITY path extension() const {
1370 return string_type(__extension());
1371 }
1372
1373 // query
1374 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool
1375 empty() const noexcept {
1376 return __pn_.empty();
1377 }
1378
1379 _LIBCPP_INLINE_VISIBILITY bool has_root_name() const {
1380 return !__root_name().empty();
1381 }
1382 _LIBCPP_INLINE_VISIBILITY bool has_root_directory() const {
1383 return !__root_directory().empty();
1384 }
1385 _LIBCPP_INLINE_VISIBILITY bool has_root_path() const {
1386 return !__root_path_raw().empty();
1387 }
1388 _LIBCPP_INLINE_VISIBILITY bool has_relative_path() const {
1389 return !__relative_path().empty();
1390 }
1391 _LIBCPP_INLINE_VISIBILITY bool has_parent_path() const {
1392 return !__parent_path().empty();
1393 }
1394 _LIBCPP_INLINE_VISIBILITY bool has_filename() const {
1395 return !__filename().empty();
1396 }
1397 _LIBCPP_INLINE_VISIBILITY bool has_stem() const { return !__stem().empty(); }
1398 _LIBCPP_INLINE_VISIBILITY bool has_extension() const {
1399 return !__extension().empty();
1400 }
1401
1402 _LIBCPP_INLINE_VISIBILITY bool is_absolute() const {
1403#if defined(_LIBCPP_WIN32API)
1404 __string_view __root_name_str = __root_name();
1405 __string_view __root_dir = __root_directory();
1406 if (__root_name_str.size() == 2 && __root_name_str[1] == ':') {
1407 // A drive letter with no root directory is relative, e.g. x:example.
1408 return !__root_dir.empty();
1409 }
1410 // If no root name, it's relative, e.g. \example is relative to the current drive
1411 if (__root_name_str.empty())
1412 return false;
1413 if (__root_name_str.size() < 3)
1414 return false;
1415 // A server root name, like \\server, is always absolute
1416 if (__root_name_str[0] != '/' && __root_name_str[0] != '\\')
1417 return false;
1418 if (__root_name_str[1] != '/' && __root_name_str[1] != '\\')
1419 return false;
1420 // Seems to be a server root name
1421 return true;
1422#else
1423 return has_root_directory();
1424#endif
1425 }
1426 _LIBCPP_INLINE_VISIBILITY bool is_relative() const { return !is_absolute(); }
1427
1428 // relative paths
1429 path lexically_normal() const;
1430 path lexically_relative(const path& __base) const;
1431
1432 _LIBCPP_INLINE_VISIBILITY path lexically_proximate(const path& __base) const {
1433 path __result = this->lexically_relative(__base);
1434 if (__result.native().empty())
1435 return *this;
1436 return __result;
1437 }
1438
1439 // iterators
1440 class _LIBCPP_TYPE_VIS iterator;
1441 typedef iterator const_iterator;
1442
1443 iterator begin() const;
1444 iterator end() const;
1445
1446#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
1447 template <class _CharT, class _Traits>
1448 _LIBCPP_INLINE_VISIBILITY friend
1449 typename enable_if<is_same<_CharT, value_type>::value &&
1450 is_same<_Traits, char_traits<value_type> >::value,
1451 basic_ostream<_CharT, _Traits>&>::type
1452 operator<<(basic_ostream<_CharT, _Traits>& __os, const path& __p) {
1453 __os << _VSTD::__quoted(__p.native());
1454 return __os;
1455 }
1456
1457 template <class _CharT, class _Traits>
1458 _LIBCPP_INLINE_VISIBILITY friend
1459 typename enable_if<!is_same<_CharT, value_type>::value ||
1460 !is_same<_Traits, char_traits<value_type> >::value,
1461 basic_ostream<_CharT, _Traits>&>::type
1462 operator<<(basic_ostream<_CharT, _Traits>& __os, const path& __p) {
1463 __os << _VSTD::__quoted(__p.string<_CharT, _Traits>());
1464 return __os;
1465 }
1466
1467 template <class _CharT, class _Traits>
1468 _LIBCPP_INLINE_VISIBILITY friend basic_istream<_CharT, _Traits>&
1469 operator>>(basic_istream<_CharT, _Traits>& __is, path& __p) {
1470 basic_string<_CharT, _Traits> __tmp;
1471 __is >> __quoted(__tmp);
1472 __p = __tmp;
1473 return __is;
1474 }
1475#endif // !_LIBCPP_HAS_NO_LOCALIZATION
1476
1477 friend _LIBCPP_INLINE_VISIBILITY bool operator==(const path& __lhs, const path& __rhs) noexcept {
1478 return __lhs.compare(__rhs) == 0;
1479 }
1480 friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const path& __lhs, const path& __rhs) noexcept {
1481 return __lhs.compare(__rhs) != 0;
1482 }
1483 friend _LIBCPP_INLINE_VISIBILITY bool operator<(const path& __lhs, const path& __rhs) noexcept {
1484 return __lhs.compare(__rhs) < 0;
1485 }
1486 friend _LIBCPP_INLINE_VISIBILITY bool operator<=(const path& __lhs, const path& __rhs) noexcept {
1487 return __lhs.compare(__rhs) <= 0;
1488 }
1489 friend _LIBCPP_INLINE_VISIBILITY bool operator>(const path& __lhs, const path& __rhs) noexcept {
1490 return __lhs.compare(__rhs) > 0;
1491 }
1492 friend _LIBCPP_INLINE_VISIBILITY bool operator>=(const path& __lhs, const path& __rhs) noexcept {
1493 return __lhs.compare(__rhs) >= 0;
1494 }
1495
1496 friend _LIBCPP_INLINE_VISIBILITY path operator/(const path& __lhs,
1497 const path& __rhs) {
1498 path __result(__lhs);
1499 __result /= __rhs;
1500 return __result;
1501 }
1502private:
1503 inline _LIBCPP_INLINE_VISIBILITY path&
1504 __assign_view(__string_view const& __s) noexcept {
1505 __pn_ = string_type(__s);
1506 return *this;
1507 }
1508 string_type __pn_;
1509};
1510
1511inline _LIBCPP_INLINE_VISIBILITY void swap(path& __lhs, path& __rhs) noexcept {
1512 __lhs.swap(__rhs);
1513}
1514
1515_LIBCPP_FUNC_VIS
1516size_t hash_value(const path& __p) noexcept;
1517
1518template <class _InputIt>
1519_LIBCPP_INLINE_VISIBILITY _LIBCPP_DEPRECATED_WITH_CHAR8_T
1520 typename enable_if<__is_pathable<_InputIt>::value, path>::type
1521 u8path(_InputIt __f, _InputIt __l) {
1522 static_assert(
1523#ifndef _LIBCPP_HAS_NO_CHAR8_T
1524 is_same<typename __is_pathable<_InputIt>::__char_type, char8_t>::value ||
1525#endif
1526 is_same<typename __is_pathable<_InputIt>::__char_type, char>::value,
1527 "u8path(Iter, Iter) requires Iter have a value_type of type 'char'"
1528 " or 'char8_t'");
1529#if defined(_LIBCPP_WIN32API)
1530 string __tmp(__f, __l);
1531 using _CVT = __widen_from_utf8<sizeof(wchar_t) * __CHAR_BIT__>;
1532 _VSTD::wstring __w;
1533 __w.reserve(__tmp.size());
1534 _CVT()(back_inserter(__w), __tmp.data(), __tmp.data() + __tmp.size());
1535 return path(__w);
1536#else
1537 return path(__f, __l);
1538#endif /* !_LIBCPP_WIN32API */
1539}
1540
1541#if defined(_LIBCPP_WIN32API)
1542template <class _InputIt>
1543_LIBCPP_INLINE_VISIBILITY _LIBCPP_DEPRECATED_WITH_CHAR8_T
1544 typename enable_if<__is_pathable<_InputIt>::value, path>::type
1545 u8path(_InputIt __f, _NullSentinel) {
1546 static_assert(
1547#ifndef _LIBCPP_HAS_NO_CHAR8_T
1548 is_same<typename __is_pathable<_InputIt>::__char_type, char8_t>::value ||
1549#endif
1550 is_same<typename __is_pathable<_InputIt>::__char_type, char>::value,
1551 "u8path(Iter, Iter) requires Iter have a value_type of type 'char'"
1552 " or 'char8_t'");
1553 string __tmp;
1554 const char __sentinel = char{};
1555 for (; *__f != __sentinel; ++__f)
1556 __tmp.push_back(*__f);
1557 using _CVT = __widen_from_utf8<sizeof(wchar_t) * __CHAR_BIT__>;
1558 _VSTD::wstring __w;
1559 __w.reserve(__tmp.size());
1560 _CVT()(back_inserter(__w), __tmp.data(), __tmp.data() + __tmp.size());
1561 return path(__w);
1562}
1563#endif /* _LIBCPP_WIN32API */
1564
1565template <class _Source>
1566_LIBCPP_INLINE_VISIBILITY _LIBCPP_DEPRECATED_WITH_CHAR8_T
1567 typename enable_if<__is_pathable<_Source>::value, path>::type
1568 u8path(const _Source& __s) {
1569 static_assert(
1570#ifndef _LIBCPP_HAS_NO_CHAR8_T
1571 is_same<typename __is_pathable<_Source>::__char_type, char8_t>::value ||
1572#endif
1573 is_same<typename __is_pathable<_Source>::__char_type, char>::value,
1574 "u8path(Source const&) requires Source have a character type of type "
1575 "'char' or 'char8_t'");
1576#if defined(_LIBCPP_WIN32API)
1577 using _Traits = __is_pathable<_Source>;
1578 return u8path(_VSTD::__unwrap_iter(_Traits::__range_begin(__s)), _VSTD::__unwrap_iter(_Traits::__range_end(__s)));
1579#else
1580 return path(__s);
1581#endif
1582}
1583
1584class _LIBCPP_TYPE_VIS path::iterator {
1585public:
1586 enum _ParserState : unsigned char {
1587 _Singular,
1588 _BeforeBegin,
1589 _InRootName,
1590 _InRootDir,
1591 _InFilenames,
1592 _InTrailingSep,
1593 _AtEnd
1594 };
1595
1596public:
1597 typedef bidirectional_iterator_tag iterator_category;
1598
1599 typedef path value_type;
1600 typedef ptrdiff_t difference_type;
1601 typedef const path* pointer;
1602 typedef const path& reference;
1603
1604 typedef void
1605 __stashing_iterator_tag; // See reverse_iterator and __is_stashing_iterator
1606
1607public:
1608 _LIBCPP_INLINE_VISIBILITY
1609 iterator()
1610 : __stashed_elem_(), __path_ptr_(nullptr), __entry_(),
1611 __state_(_Singular) {}
1612
1613 iterator(const iterator&) = default;
1614 ~iterator() = default;
1615
1616 iterator& operator=(const iterator&) = default;
1617
1618 _LIBCPP_INLINE_VISIBILITY
1619 reference operator*() const { return __stashed_elem_; }
1620
1621 _LIBCPP_INLINE_VISIBILITY
1622 pointer operator->() const { return &__stashed_elem_; }
1623
1624 _LIBCPP_INLINE_VISIBILITY
1625 iterator& operator++() {
1626 _LIBCPP_ASSERT(__state_ != _Singular,
1627 "attempting to increment a singular iterator");
1628 _LIBCPP_ASSERT(__state_ != _AtEnd,
1629 "attempting to increment the end iterator");
1630 return __increment();
1631 }
1632
1633 _LIBCPP_INLINE_VISIBILITY
1634 iterator operator++(int) {
1635 iterator __it(*this);
1636 this->operator++();
1637 return __it;
1638 }
1639
1640 _LIBCPP_INLINE_VISIBILITY
1641 iterator& operator--() {
1642 _LIBCPP_ASSERT(__state_ != _Singular,
1643 "attempting to decrement a singular iterator");
1644 _LIBCPP_ASSERT(__entry_.data() != __path_ptr_->native().data(),
1645 "attempting to decrement the begin iterator");
1646 return __decrement();
1647 }
1648
1649 _LIBCPP_INLINE_VISIBILITY
1650 iterator operator--(int) {
1651 iterator __it(*this);
1652 this->operator--();
1653 return __it;
1654 }
1655
1656private:
1657 friend class path;
1658
1659 inline _LIBCPP_INLINE_VISIBILITY friend bool operator==(const iterator&,
1660 const iterator&);
1661
1662 iterator& __increment();
1663 iterator& __decrement();
1664
1665 path __stashed_elem_;
1666 const path* __path_ptr_;
1667 path::__string_view __entry_;
1668 _ParserState __state_;
1669};
1670
1671inline _LIBCPP_INLINE_VISIBILITY bool operator==(const path::iterator& __lhs,
1672 const path::iterator& __rhs) {
1673 return __lhs.__path_ptr_ == __rhs.__path_ptr_ &&
1674 __lhs.__entry_.data() == __rhs.__entry_.data();
1675}
1676
1677inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const path::iterator& __lhs,
1678 const path::iterator& __rhs) {
1679 return !(__lhs == __rhs);
1680}
1681
1682// TODO(ldionne): We need to pop the pragma and push it again after
1683// filesystem_error to work around PR41078.
1684_LIBCPP_AVAILABILITY_FILESYSTEM_POP
1685
1686class _LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_EXCEPTION_ABI filesystem_error : public system_error {
1687public:
1688 _LIBCPP_INLINE_VISIBILITY
1689 filesystem_error(const string& __what, error_code __ec)
1690 : system_error(__ec, __what),
1691 __storage_(make_shared<_Storage>(path(), path())) {
1692 __create_what(0);
1693 }
1694
1695 _LIBCPP_INLINE_VISIBILITY
1696 filesystem_error(const string& __what, const path& __p1, error_code __ec)
1697 : system_error(__ec, __what),
1698 __storage_(make_shared<_Storage>(__p1, path())) {
1699 __create_what(1);
1700 }
1701
1702 _LIBCPP_INLINE_VISIBILITY
1703 filesystem_error(const string& __what, const path& __p1, const path& __p2,
1704 error_code __ec)
1705 : system_error(__ec, __what),
1706 __storage_(make_shared<_Storage>(__p1, __p2)) {
1707 __create_what(2);
1708 }
1709
1710 _LIBCPP_INLINE_VISIBILITY
1711 const path& path1() const noexcept { return __storage_->__p1_; }
1712
1713 _LIBCPP_INLINE_VISIBILITY
1714 const path& path2() const noexcept { return __storage_->__p2_; }
1715
1716 filesystem_error(const filesystem_error&) = default;
1717 ~filesystem_error() override; // key function
1718
1719 _LIBCPP_INLINE_VISIBILITY
1720 const char* what() const noexcept override {
1721 return __storage_->__what_.c_str();
1722 }
1723
1724 void __create_what(int __num_paths);
1725
1726private:
1727 struct _LIBCPP_HIDDEN _Storage {
1728 _LIBCPP_INLINE_VISIBILITY
1729 _Storage(const path& __p1, const path& __p2) : __p1_(__p1), __p2_(__p2) {}
1730
1731 path __p1_;
1732 path __p2_;
1733 string __what_;
1734 };
1735 shared_ptr<_Storage> __storage_;
1736};
1737
1738_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH
1739
1740template <class... _Args>
1741_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
1742#ifndef _LIBCPP_NO_EXCEPTIONS
1743void __throw_filesystem_error(_Args&&... __args) {
1744 throw filesystem_error(_VSTD::forward<_Args>(__args)...);
1745}
1746#else
1747void __throw_filesystem_error(_Args&&...) {
1748 _VSTD::abort();
1749}
1750#endif
1751
1752// operational functions
1753
1754_LIBCPP_FUNC_VIS
1755path __absolute(const path&, error_code* __ec = nullptr);
1756_LIBCPP_FUNC_VIS
1757path __canonical(const path&, error_code* __ec = nullptr);
1758_LIBCPP_FUNC_VIS
1759void __copy(const path& __from, const path& __to, copy_options __opt,
1760 error_code* __ec = nullptr);
1761_LIBCPP_FUNC_VIS
1762bool __copy_file(const path& __from, const path& __to, copy_options __opt,
1763 error_code* __ec = nullptr);
1764_LIBCPP_FUNC_VIS
1765void __copy_symlink(const path& __existing_symlink, const path& __new_symlink,
1766 error_code* __ec = nullptr);
1767_LIBCPP_FUNC_VIS
1768bool __create_directories(const path& p, error_code* ec = nullptr);
1769_LIBCPP_FUNC_VIS
1770bool __create_directory(const path& p, error_code* ec = nullptr);
1771_LIBCPP_FUNC_VIS
1772bool __create_directory(const path& p, const path& attributes,
1773 error_code* ec = nullptr);
1774_LIBCPP_FUNC_VIS
1775void __create_directory_symlink(const path& __to, const path& __new_symlink,
1776 error_code* __ec = nullptr);
1777_LIBCPP_FUNC_VIS
1778void __create_hard_link(const path& __to, const path& __new_hard_link,
1779 error_code* __ec = nullptr);
1780_LIBCPP_FUNC_VIS
1781void __create_symlink(const path& __to, const path& __new_symlink,
1782 error_code* __ec = nullptr);
1783_LIBCPP_FUNC_VIS
1784path __current_path(error_code* __ec = nullptr);
1785_LIBCPP_FUNC_VIS
1786void __current_path(const path&, error_code* __ec = nullptr);
1787_LIBCPP_FUNC_VIS
1788bool __equivalent(const path&, const path&, error_code* __ec = nullptr);
1789_LIBCPP_FUNC_VIS
1790uintmax_t __file_size(const path&, error_code* __ec = nullptr);
1791_LIBCPP_FUNC_VIS
1792uintmax_t __hard_link_count(const path&, error_code* __ec = nullptr);
1793_LIBCPP_FUNC_VIS
1794bool __fs_is_empty(const path& p, error_code* ec = nullptr);
1795_LIBCPP_FUNC_VIS
1796file_time_type __last_write_time(const path& p, error_code* ec = nullptr);
1797_LIBCPP_FUNC_VIS
1798void __last_write_time(const path& p, file_time_type new_time,
1799 error_code* ec = nullptr);
1800_LIBCPP_FUNC_VIS
1801void __permissions(const path&, perms, perm_options, error_code* = nullptr);
1802_LIBCPP_FUNC_VIS
1803path __read_symlink(const path& p, error_code* ec = nullptr);
1804_LIBCPP_FUNC_VIS
1805bool __remove(const path& p, error_code* ec = nullptr);
1806_LIBCPP_FUNC_VIS
1807uintmax_t __remove_all(const path& p, error_code* ec = nullptr);
1808_LIBCPP_FUNC_VIS
1809void __rename(const path& from, const path& to, error_code* ec = nullptr);
1810_LIBCPP_FUNC_VIS
1811void __resize_file(const path& p, uintmax_t size, error_code* ec = nullptr);
1812_LIBCPP_FUNC_VIS
1813space_info __space(const path&, error_code* __ec = nullptr);
1814_LIBCPP_FUNC_VIS
1815file_status __status(const path&, error_code* __ec = nullptr);
1816_LIBCPP_FUNC_VIS
1817file_status __symlink_status(const path&, error_code* __ec = nullptr);
1818_LIBCPP_FUNC_VIS
1819path __system_complete(const path&, error_code* __ec = nullptr);
1820_LIBCPP_FUNC_VIS
1821path __temp_directory_path(error_code* __ec = nullptr);
1822_LIBCPP_FUNC_VIS
1823path __weakly_canonical(path const& __p, error_code* __ec = nullptr);
1824
1825inline _LIBCPP_INLINE_VISIBILITY path current_path() {
1826 return __current_path();
1827}
1828
1829inline _LIBCPP_INLINE_VISIBILITY path current_path(error_code& __ec) {
1830 return __current_path(&__ec);
1831}
1832
1833inline _LIBCPP_INLINE_VISIBILITY void current_path(const path& __p) {
1834 __current_path(__p);
1835}
1836
1837inline _LIBCPP_INLINE_VISIBILITY void current_path(const path& __p,
1838 error_code& __ec) noexcept {
1839 __current_path(__p, &__ec);
1840}
1841
1842inline _LIBCPP_INLINE_VISIBILITY path absolute(const path& __p) {
1843 return __absolute(__p);
1844}
1845
1846inline _LIBCPP_INLINE_VISIBILITY path absolute(const path& __p,
1847 error_code& __ec) {
1848 return __absolute(__p, &__ec);
1849}
1850
1851inline _LIBCPP_INLINE_VISIBILITY path canonical(const path& __p) {
1852 return __canonical(__p);
1853}
1854
1855inline _LIBCPP_INLINE_VISIBILITY path canonical(const path& __p,
1856 error_code& __ec) {
1857 return __canonical(__p, &__ec);
1858}
1859
1860inline _LIBCPP_INLINE_VISIBILITY void copy(const path& __from,
1861 const path& __to) {
1862 __copy(__from, __to, copy_options::none);
1863}
1864
1865inline _LIBCPP_INLINE_VISIBILITY void copy(const path& __from, const path& __to,
1866 error_code& __ec) {
1867 __copy(__from, __to, copy_options::none, &__ec);
1868}
1869
1870inline _LIBCPP_INLINE_VISIBILITY void copy(const path& __from, const path& __to,
1871 copy_options __opt) {
1872 __copy(__from, __to, __opt);
1873}
1874
1875inline _LIBCPP_INLINE_VISIBILITY void copy(const path& __from, const path& __to,
1876 copy_options __opt,
1877 error_code& __ec) {
1878 __copy(__from, __to, __opt, &__ec);
1879}
1880
1881inline _LIBCPP_INLINE_VISIBILITY bool copy_file(const path& __from,
1882 const path& __to) {
1883 return __copy_file(__from, __to, copy_options::none);
1884}
1885
1886inline _LIBCPP_INLINE_VISIBILITY bool
1887copy_file(const path& __from, const path& __to, error_code& __ec) {
1888 return __copy_file(__from, __to, copy_options::none, &__ec);
1889}
1890
1891inline _LIBCPP_INLINE_VISIBILITY bool
1892copy_file(const path& __from, const path& __to, copy_options __opt) {
1893 return __copy_file(__from, __to, __opt);
1894}
1895
1896inline _LIBCPP_INLINE_VISIBILITY bool copy_file(const path& __from,
1897 const path& __to,
1898 copy_options __opt,
1899 error_code& __ec) {
1900 return __copy_file(__from, __to, __opt, &__ec);
1901}
1902
1903inline _LIBCPP_INLINE_VISIBILITY void copy_symlink(const path& __existing,
1904 const path& __new) {
1905 __copy_symlink(__existing, __new);
1906}
1907
1908inline _LIBCPP_INLINE_VISIBILITY void
1909copy_symlink(const path& __ext, const path& __new, error_code& __ec) noexcept {
1910 __copy_symlink(__ext, __new, &__ec);
1911}
1912
1913inline _LIBCPP_INLINE_VISIBILITY bool create_directories(const path& __p) {
1914 return __create_directories(__p);
1915}
1916
1917inline _LIBCPP_INLINE_VISIBILITY bool create_directories(const path& __p,
1918 error_code& __ec) {
1919 return __create_directories(__p, &__ec);
1920}
1921
1922inline _LIBCPP_INLINE_VISIBILITY bool create_directory(const path& __p) {
1923 return __create_directory(__p);
1924}
1925
1926inline _LIBCPP_INLINE_VISIBILITY bool
1927create_directory(const path& __p, error_code& __ec) noexcept {
1928 return __create_directory(__p, &__ec);
1929}
1930
1931inline _LIBCPP_INLINE_VISIBILITY bool create_directory(const path& __p,
1932 const path& __attrs) {
1933 return __create_directory(__p, __attrs);
1934}
1935
1936inline _LIBCPP_INLINE_VISIBILITY bool
1937create_directory(const path& __p, const path& __attrs,
1938 error_code& __ec) noexcept {
1939 return __create_directory(__p, __attrs, &__ec);
1940}
1941
1942inline _LIBCPP_INLINE_VISIBILITY void
1943create_directory_symlink(const path& __to, const path& __new) {
1944 __create_directory_symlink(__to, __new);
1945}
1946
1947inline _LIBCPP_INLINE_VISIBILITY void
1948create_directory_symlink(const path& __to, const path& __new,
1949 error_code& __ec) noexcept {
1950 __create_directory_symlink(__to, __new, &__ec);
1951}
1952
1953inline _LIBCPP_INLINE_VISIBILITY void create_hard_link(const path& __to,
1954 const path& __new) {
1955 __create_hard_link(__to, __new);
1956}
1957
1958inline _LIBCPP_INLINE_VISIBILITY void
1959create_hard_link(const path& __to, const path& __new,
1960 error_code& __ec) noexcept {
1961 __create_hard_link(__to, __new, &__ec);
1962}
1963
1964inline _LIBCPP_INLINE_VISIBILITY void create_symlink(const path& __to,
1965 const path& __new) {
1966 __create_symlink(__to, __new);
1967}
1968
1969inline _LIBCPP_INLINE_VISIBILITY void
1970create_symlink(const path& __to, const path& __new, error_code& __ec) noexcept {
1971 return __create_symlink(__to, __new, &__ec);
1972}
1973
1974inline _LIBCPP_INLINE_VISIBILITY bool status_known(file_status __s) noexcept {
1975 return __s.type() != file_type::none;
1976}
1977
1978inline _LIBCPP_INLINE_VISIBILITY bool exists(file_status __s) noexcept {
1979 return status_known(__s) && __s.type() != file_type::not_found;
1980}
1981
1982inline _LIBCPP_INLINE_VISIBILITY bool exists(const path& __p) {
1983 return exists(__status(__p));
1984}
1985
1986inline _LIBCPP_INLINE_VISIBILITY bool exists(const path& __p,
1987 error_code& __ec) noexcept {
1988 auto __s = __status(__p, &__ec);
1989 if (status_known(__s))
1990 __ec.clear();
1991 return exists(__s);
1992}
1993
1994inline _LIBCPP_INLINE_VISIBILITY bool equivalent(const path& __p1,
1995 const path& __p2) {
1996 return __equivalent(__p1, __p2);
1997}
1998
1999inline _LIBCPP_INLINE_VISIBILITY bool
2000equivalent(const path& __p1, const path& __p2, error_code& __ec) noexcept {
2001 return __equivalent(__p1, __p2, &__ec);
2002}
2003
2004inline _LIBCPP_INLINE_VISIBILITY uintmax_t file_size(const path& __p) {
2005 return __file_size(__p);
2006}
2007
2008inline _LIBCPP_INLINE_VISIBILITY uintmax_t
2009file_size(const path& __p, error_code& __ec) noexcept {
2010 return __file_size(__p, &__ec);
2011}
2012
2013inline _LIBCPP_INLINE_VISIBILITY uintmax_t hard_link_count(const path& __p) {
2014 return __hard_link_count(__p);
2015}
2016
2017inline _LIBCPP_INLINE_VISIBILITY uintmax_t
2018hard_link_count(const path& __p, error_code& __ec) noexcept {
2019 return __hard_link_count(__p, &__ec);
2020}
2021
2022inline _LIBCPP_INLINE_VISIBILITY bool is_block_file(file_status __s) noexcept {
2023 return __s.type() == file_type::block;
2024}
2025
2026inline _LIBCPP_INLINE_VISIBILITY bool is_block_file(const path& __p) {
2027 return is_block_file(__status(__p));
2028}
2029
2030inline _LIBCPP_INLINE_VISIBILITY bool is_block_file(const path& __p,
2031 error_code& __ec) noexcept {
2032 return is_block_file(__status(__p, &__ec));
2033}
2034
2035inline _LIBCPP_INLINE_VISIBILITY bool
2036is_character_file(file_status __s) noexcept {
2037 return __s.type() == file_type::character;
2038}
2039
2040inline _LIBCPP_INLINE_VISIBILITY bool is_character_file(const path& __p) {
2041 return is_character_file(__status(__p));
2042}
2043
2044inline _LIBCPP_INLINE_VISIBILITY bool
2045is_character_file(const path& __p, error_code& __ec) noexcept {
2046 return is_character_file(__status(__p, &__ec));
2047}
2048
2049inline _LIBCPP_INLINE_VISIBILITY bool is_directory(file_status __s) noexcept {
2050 return __s.type() == file_type::directory;
2051}
2052
2053inline _LIBCPP_INLINE_VISIBILITY bool is_directory(const path& __p) {
2054 return is_directory(__status(__p));
2055}
2056
2057inline _LIBCPP_INLINE_VISIBILITY bool is_directory(const path& __p,
2058 error_code& __ec) noexcept {
2059 return is_directory(__status(__p, &__ec));
2060}
2061
2062inline _LIBCPP_INLINE_VISIBILITY bool is_empty(const path& __p) {
2063 return __fs_is_empty(__p);
2064}
2065
2066inline _LIBCPP_INLINE_VISIBILITY bool is_empty(const path& __p,
2067 error_code& __ec) {
2068 return __fs_is_empty(__p, &__ec);
2069}
2070
2071inline _LIBCPP_INLINE_VISIBILITY bool is_fifo(file_status __s) noexcept {
2072 return __s.type() == file_type::fifo;
2073}
2074inline _LIBCPP_INLINE_VISIBILITY bool is_fifo(const path& __p) {
2075 return is_fifo(__status(__p));
2076}
2077
2078inline _LIBCPP_INLINE_VISIBILITY bool is_fifo(const path& __p,
2079 error_code& __ec) noexcept {
2080 return is_fifo(__status(__p, &__ec));
2081}
2082
2083inline _LIBCPP_INLINE_VISIBILITY bool
2084is_regular_file(file_status __s) noexcept {
2085 return __s.type() == file_type::regular;
2086}
2087
2088inline _LIBCPP_INLINE_VISIBILITY bool is_regular_file(const path& __p) {
2089 return is_regular_file(__status(__p));
2090}
2091
2092inline _LIBCPP_INLINE_VISIBILITY bool
2093is_regular_file(const path& __p, error_code& __ec) noexcept {
2094 return is_regular_file(__status(__p, &__ec));
2095}
2096
2097inline _LIBCPP_INLINE_VISIBILITY bool is_socket(file_status __s) noexcept {
2098 return __s.type() == file_type::socket;
2099}
2100
2101inline _LIBCPP_INLINE_VISIBILITY bool is_socket(const path& __p) {
2102 return is_socket(__status(__p));
2103}
2104
2105inline _LIBCPP_INLINE_VISIBILITY bool is_socket(const path& __p,
2106 error_code& __ec) noexcept {
2107 return is_socket(__status(__p, &__ec));
2108}
2109
2110inline _LIBCPP_INLINE_VISIBILITY bool is_symlink(file_status __s) noexcept {
2111 return __s.type() == file_type::symlink;
2112}
2113
2114inline _LIBCPP_INLINE_VISIBILITY bool is_symlink(const path& __p) {
2115 return is_symlink(__symlink_status(__p));
2116}
2117
2118inline _LIBCPP_INLINE_VISIBILITY bool is_symlink(const path& __p,
2119 error_code& __ec) noexcept {
2120 return is_symlink(__symlink_status(__p, &__ec));
2121}
2122
2123inline _LIBCPP_INLINE_VISIBILITY bool is_other(file_status __s) noexcept {
2124 return exists(__s) && !is_regular_file(__s) && !is_directory(__s) &&
2125 !is_symlink(__s);
2126}
2127
2128inline _LIBCPP_INLINE_VISIBILITY bool is_other(const path& __p) {
2129 return is_other(__status(__p));
2130}
2131
2132inline _LIBCPP_INLINE_VISIBILITY bool is_other(const path& __p,
2133 error_code& __ec) noexcept {
2134 return is_other(__status(__p, &__ec));
2135}
2136
2137inline _LIBCPP_INLINE_VISIBILITY file_time_type
2138last_write_time(const path& __p) {
2139 return __last_write_time(__p);
2140}
2141
2142inline _LIBCPP_INLINE_VISIBILITY file_time_type
2143last_write_time(const path& __p, error_code& __ec) noexcept {
2144 return __last_write_time(__p, &__ec);
2145}
2146
2147inline _LIBCPP_INLINE_VISIBILITY void last_write_time(const path& __p,
2148 file_time_type __t) {
2149 __last_write_time(__p, __t);
2150}
2151
2152inline _LIBCPP_INLINE_VISIBILITY void
2153last_write_time(const path& __p, file_time_type __t,
2154 error_code& __ec) noexcept {
2155 __last_write_time(__p, __t, &__ec);
2156}
2157
2158inline _LIBCPP_INLINE_VISIBILITY void
2159permissions(const path& __p, perms __prms,
2160 perm_options __opts = perm_options::replace) {
2161 __permissions(__p, __prms, __opts);
2162}
2163
2164inline _LIBCPP_INLINE_VISIBILITY void permissions(const path& __p, perms __prms,
2165 error_code& __ec) noexcept {
2166 __permissions(__p, __prms, perm_options::replace, &__ec);
2167}
2168
2169inline _LIBCPP_INLINE_VISIBILITY void permissions(const path& __p, perms __prms,
2170 perm_options __opts,
2171 error_code& __ec) {
2172 __permissions(__p, __prms, __opts, &__ec);
2173}
2174
2175inline _LIBCPP_INLINE_VISIBILITY path proximate(const path& __p,
2176 const path& __base,
2177 error_code& __ec) {
2178 path __tmp = __weakly_canonical(__p, &__ec);
2179 if (__ec)
2180 return {};
2181 path __tmp_base = __weakly_canonical(__base, &__ec);
2182 if (__ec)
2183 return {};
2184 return __tmp.lexically_proximate(__tmp_base);
2185}
2186
2187inline _LIBCPP_INLINE_VISIBILITY path proximate(const path& __p,
2188 error_code& __ec) {
2189 return proximate(__p, current_path(), __ec);
2190}
2191
2192inline _LIBCPP_INLINE_VISIBILITY path
2193proximate(const path& __p, const path& __base = current_path()) {
2194 return __weakly_canonical(__p).lexically_proximate(
2195 __weakly_canonical(__base));
2196}
2197
2198inline _LIBCPP_INLINE_VISIBILITY path read_symlink(const path& __p) {
2199 return __read_symlink(__p);
2200}
2201
2202inline _LIBCPP_INLINE_VISIBILITY path read_symlink(const path& __p,
2203 error_code& __ec) {
2204 return __read_symlink(__p, &__ec);
2205}
2206
2207inline _LIBCPP_INLINE_VISIBILITY path relative(const path& __p,
2208 const path& __base,
2209 error_code& __ec) {
2210 path __tmp = __weakly_canonical(__p, &__ec);
2211 if (__ec)
2212 return path();
2213 path __tmpbase = __weakly_canonical(__base, &__ec);
2214 if (__ec)
2215 return path();
2216 return __tmp.lexically_relative(__tmpbase);
2217}
2218
2219inline _LIBCPP_INLINE_VISIBILITY path relative(const path& __p,
2220 error_code& __ec) {
2221 return relative(__p, current_path(), __ec);
2222}
2223
2224inline _LIBCPP_INLINE_VISIBILITY path
2225relative(const path& __p, const path& __base = current_path()) {
2226 return __weakly_canonical(__p).lexically_relative(__weakly_canonical(__base));
2227}
2228
2229inline _LIBCPP_INLINE_VISIBILITY bool remove(const path& __p) {
2230 return __remove(__p);
2231}
2232
2233inline _LIBCPP_INLINE_VISIBILITY bool remove(const path& __p,
2234 error_code& __ec) noexcept {
2235 return __remove(__p, &__ec);
2236}
2237
2238inline _LIBCPP_INLINE_VISIBILITY uintmax_t remove_all(const path& __p) {
2239 return __remove_all(__p);
2240}
2241
2242inline _LIBCPP_INLINE_VISIBILITY uintmax_t remove_all(const path& __p,
2243 error_code& __ec) {
2244 return __remove_all(__p, &__ec);
2245}
2246
2247inline _LIBCPP_INLINE_VISIBILITY void rename(const path& __from,
2248 const path& __to) {
2249 return __rename(__from, __to);
2250}
2251
2252inline _LIBCPP_INLINE_VISIBILITY void
2253rename(const path& __from, const path& __to, error_code& __ec) noexcept {
2254 return __rename(__from, __to, &__ec);
2255}
2256
2257inline _LIBCPP_INLINE_VISIBILITY void resize_file(const path& __p,
2258 uintmax_t __ns) {
2259 return __resize_file(__p, __ns);
2260}
2261
2262inline _LIBCPP_INLINE_VISIBILITY void
2263resize_file(const path& __p, uintmax_t __ns, error_code& __ec) noexcept {
2264 return __resize_file(__p, __ns, &__ec);
2265}
2266
2267inline _LIBCPP_INLINE_VISIBILITY space_info space(const path& __p) {
2268 return __space(__p);
2269}
2270
2271inline _LIBCPP_INLINE_VISIBILITY space_info space(const path& __p,
2272 error_code& __ec) noexcept {
2273 return __space(__p, &__ec);
2274}
2275
2276inline _LIBCPP_INLINE_VISIBILITY file_status status(const path& __p) {
2277 return __status(__p);
2278}
2279
2280inline _LIBCPP_INLINE_VISIBILITY file_status status(const path& __p,
2281 error_code& __ec) noexcept {
2282 return __status(__p, &__ec);
2283}
2284
2285inline _LIBCPP_INLINE_VISIBILITY file_status symlink_status(const path& __p) {
2286 return __symlink_status(__p);
2287}
2288
2289inline _LIBCPP_INLINE_VISIBILITY file_status
2290symlink_status(const path& __p, error_code& __ec) noexcept {
2291 return __symlink_status(__p, &__ec);
2292}
2293
2294inline _LIBCPP_INLINE_VISIBILITY path temp_directory_path() {
2295 return __temp_directory_path();
2296}
2297
2298inline _LIBCPP_INLINE_VISIBILITY path temp_directory_path(error_code& __ec) {
2299 return __temp_directory_path(&__ec);
2300}
2301
2302inline _LIBCPP_INLINE_VISIBILITY path weakly_canonical(path const& __p) {
2303 return __weakly_canonical(__p);
2304}
2305
2306inline _LIBCPP_INLINE_VISIBILITY path weakly_canonical(path const& __p,
2307 error_code& __ec) {
2308 return __weakly_canonical(__p, &__ec);
2309}
2310
2311class directory_iterator;
2312class recursive_directory_iterator;
2313class _LIBCPP_HIDDEN __dir_stream;
2314
2315class directory_entry {
2316 typedef _VSTD_FS::path _Path;
2317
2318public:
2319 // constructors and destructors
2320 directory_entry() noexcept = default;
2321 directory_entry(directory_entry const&) = default;
2322 directory_entry(directory_entry&&) noexcept = default;
2323
2324 _LIBCPP_INLINE_VISIBILITY
2325 explicit directory_entry(_Path const& __p) : __p_(__p) {
2326 error_code __ec;
2327 __refresh(&__ec);
2328 }
2329
2330 _LIBCPP_INLINE_VISIBILITY
2331 directory_entry(_Path const& __p, error_code& __ec) : __p_(__p) {
2332 __refresh(&__ec);
2333 }
2334
2335 ~directory_entry() {}
2336
2337 directory_entry& operator=(directory_entry const&) = default;
2338 directory_entry& operator=(directory_entry&&) noexcept = default;
2339
2340 _LIBCPP_INLINE_VISIBILITY
2341 void assign(_Path const& __p) {
2342 __p_ = __p;
2343 error_code __ec;
2344 __refresh(&__ec);
2345 }
2346
2347 _LIBCPP_INLINE_VISIBILITY
2348 void assign(_Path const& __p, error_code& __ec) {
2349 __p_ = __p;
2350 __refresh(&__ec);
2351 }
2352
2353 _LIBCPP_INLINE_VISIBILITY
2354 void replace_filename(_Path const& __p) {
2355 __p_.replace_filename(__p);
2356 error_code __ec;
2357 __refresh(&__ec);
2358 }
2359
2360 _LIBCPP_INLINE_VISIBILITY
2361 void replace_filename(_Path const& __p, error_code& __ec) {
2362 __p_ = __p_.parent_path() / __p;
2363 __refresh(&__ec);
2364 }
2365
2366 _LIBCPP_INLINE_VISIBILITY
2367 void refresh() { __refresh(); }
2368
2369 _LIBCPP_INLINE_VISIBILITY
2370 void refresh(error_code& __ec) noexcept { __refresh(&__ec); }
2371
2372 _LIBCPP_INLINE_VISIBILITY
2373 _Path const& path() const noexcept { return __p_; }
2374
2375 _LIBCPP_INLINE_VISIBILITY
2376 operator const _Path&() const noexcept { return __p_; }
2377
2378 _LIBCPP_INLINE_VISIBILITY
2379 bool exists() const { return _VSTD_FS::exists(file_status{__get_ft()}); }
2380
2381 _LIBCPP_INLINE_VISIBILITY
2382 bool exists(error_code& __ec) const noexcept {
2383 return _VSTD_FS::exists(file_status{__get_ft(&__ec)});
2384 }
2385
2386 _LIBCPP_INLINE_VISIBILITY
2387 bool is_block_file() const { return __get_ft() == file_type::block; }
2388
2389 _LIBCPP_INLINE_VISIBILITY
2390 bool is_block_file(error_code& __ec) const noexcept {
2391 return __get_ft(&__ec) == file_type::block;
2392 }
2393
2394 _LIBCPP_INLINE_VISIBILITY
2395 bool is_character_file() const { return __get_ft() == file_type::character; }
2396
2397 _LIBCPP_INLINE_VISIBILITY
2398 bool is_character_file(error_code& __ec) const noexcept {
2399 return __get_ft(&__ec) == file_type::character;
2400 }
2401
2402 _LIBCPP_INLINE_VISIBILITY
2403 bool is_directory() const { return __get_ft() == file_type::directory; }
2404
2405 _LIBCPP_INLINE_VISIBILITY
2406 bool is_directory(error_code& __ec) const noexcept {
2407 return __get_ft(&__ec) == file_type::directory;
2408 }
2409
2410 _LIBCPP_INLINE_VISIBILITY
2411 bool is_fifo() const { return __get_ft() == file_type::fifo; }
2412
2413 _LIBCPP_INLINE_VISIBILITY
2414 bool is_fifo(error_code& __ec) const noexcept {
2415 return __get_ft(&__ec) == file_type::fifo;
2416 }
2417
2418 _LIBCPP_INLINE_VISIBILITY
2419 bool is_other() const { return _VSTD_FS::is_other(file_status{__get_ft()}); }
2420
2421 _LIBCPP_INLINE_VISIBILITY
2422 bool is_other(error_code& __ec) const noexcept {
2423 return _VSTD_FS::is_other(file_status{__get_ft(&__ec)});
2424 }
2425
2426 _LIBCPP_INLINE_VISIBILITY
2427 bool is_regular_file() const { return __get_ft() == file_type::regular; }
2428
2429 _LIBCPP_INLINE_VISIBILITY
2430 bool is_regular_file(error_code& __ec) const noexcept {
2431 return __get_ft(&__ec) == file_type::regular;
2432 }
2433
2434 _LIBCPP_INLINE_VISIBILITY
2435 bool is_socket() const { return __get_ft() == file_type::socket; }
2436
2437 _LIBCPP_INLINE_VISIBILITY
2438 bool is_socket(error_code& __ec) const noexcept {
2439 return __get_ft(&__ec) == file_type::socket;
2440 }
2441
2442 _LIBCPP_INLINE_VISIBILITY
2443 bool is_symlink() const { return __get_sym_ft() == file_type::symlink; }
2444
2445 _LIBCPP_INLINE_VISIBILITY
2446 bool is_symlink(error_code& __ec) const noexcept {
2447 return __get_sym_ft(&__ec) == file_type::symlink;
2448 }
2449 _LIBCPP_INLINE_VISIBILITY
2450 uintmax_t file_size() const { return __get_size(); }
2451
2452 _LIBCPP_INLINE_VISIBILITY
2453 uintmax_t file_size(error_code& __ec) const noexcept {
2454 return __get_size(&__ec);
2455 }
2456
2457 _LIBCPP_INLINE_VISIBILITY
2458 uintmax_t hard_link_count() const { return __get_nlink(); }
2459
2460 _LIBCPP_INLINE_VISIBILITY
2461 uintmax_t hard_link_count(error_code& __ec) const noexcept {
2462 return __get_nlink(&__ec);
2463 }
2464
2465 _LIBCPP_INLINE_VISIBILITY
2466 file_time_type last_write_time() const { return __get_write_time(); }
2467
2468 _LIBCPP_INLINE_VISIBILITY
2469 file_time_type last_write_time(error_code& __ec) const noexcept {
2470 return __get_write_time(&__ec);
2471 }
2472
2473 _LIBCPP_INLINE_VISIBILITY
2474 file_status status() const { return __get_status(); }
2475
2476 _LIBCPP_INLINE_VISIBILITY
2477 file_status status(error_code& __ec) const noexcept {
2478 return __get_status(&__ec);
2479 }
2480
2481 _LIBCPP_INLINE_VISIBILITY
2482 file_status symlink_status() const { return __get_symlink_status(); }
2483
2484 _LIBCPP_INLINE_VISIBILITY
2485 file_status symlink_status(error_code& __ec) const noexcept {
2486 return __get_symlink_status(&__ec);
2487 }
2488
2489 _LIBCPP_INLINE_VISIBILITY
2490 bool operator<(directory_entry const& __rhs) const noexcept {
2491 return __p_ < __rhs.__p_;
2492 }
2493
2494 _LIBCPP_INLINE_VISIBILITY
2495 bool operator==(directory_entry const& __rhs) const noexcept {
2496 return __p_ == __rhs.__p_;
2497 }
2498
2499 _LIBCPP_INLINE_VISIBILITY
2500 bool operator!=(directory_entry const& __rhs) const noexcept {
2501 return __p_ != __rhs.__p_;
2502 }
2503
2504 _LIBCPP_INLINE_VISIBILITY
2505 bool operator<=(directory_entry const& __rhs) const noexcept {
2506 return __p_ <= __rhs.__p_;
2507 }
2508
2509 _LIBCPP_INLINE_VISIBILITY
2510 bool operator>(directory_entry const& __rhs) const noexcept {
2511 return __p_ > __rhs.__p_;
2512 }
2513
2514 _LIBCPP_INLINE_VISIBILITY
2515 bool operator>=(directory_entry const& __rhs) const noexcept {
2516 return __p_ >= __rhs.__p_;
2517 }
2518
2519private:
2520 friend class directory_iterator;
2521 friend class recursive_directory_iterator;
2522 friend class __dir_stream;
2523
2524 enum _CacheType : unsigned char {
2525 _Empty,
2526 _IterSymlink,
2527 _IterNonSymlink,
2528 _RefreshSymlink,
2529 _RefreshSymlinkUnresolved,
2530 _RefreshNonSymlink
2531 };
2532
2533 struct __cached_data {
2534 uintmax_t __size_;
2535 uintmax_t __nlink_;
2536 file_time_type __write_time_;
2537 perms __sym_perms_;
2538 perms __non_sym_perms_;
2539 file_type __type_;
2540 _CacheType __cache_type_;
2541
2542 _LIBCPP_INLINE_VISIBILITY
2543 __cached_data() noexcept { __reset(); }
2544
2545 _LIBCPP_INLINE_VISIBILITY
2546 void __reset() {
2547 __cache_type_ = _Empty;
2548 __type_ = file_type::none;
2549 __sym_perms_ = __non_sym_perms_ = perms::unknown;
2550 __size_ = __nlink_ = uintmax_t(-1);
2551 __write_time_ = file_time_type::min();
2552 }
2553 };
2554
2555 _LIBCPP_INLINE_VISIBILITY
2556 static __cached_data __create_iter_result(file_type __ft) {
2557 __cached_data __data;
2558 __data.__type_ = __ft;
2559 __data.__cache_type_ = [&]() {
2560 switch (__ft) {
2561 case file_type::none:
2562 return _Empty;
2563 case file_type::symlink:
2564 return _IterSymlink;
2565 default:
2566 return _IterNonSymlink;
2567 }
2568 }();
2569 return __data;
2570 }
2571
2572 _LIBCPP_INLINE_VISIBILITY
2573 void __assign_iter_entry(_Path&& __p, __cached_data __dt) {
2574 __p_ = _VSTD::move(__p);
2575 __data_ = __dt;
2576 }
2577
2578 _LIBCPP_FUNC_VIS
2579 error_code __do_refresh() noexcept;
2580
2581 _LIBCPP_INLINE_VISIBILITY
2582 static bool __is_dne_error(error_code const& __ec) {
2583 if (!__ec)
2584 return true;
2585 switch (static_cast<errc>(__ec.value())) {
2586 case errc::no_such_file_or_directory:
2587 case errc::not_a_directory:
2588 return true;
2589 default:
2590 return false;
2591 }
2592 }
2593
2594 _LIBCPP_INLINE_VISIBILITY
2595 void __handle_error(const char* __msg, error_code* __dest_ec,
2596 error_code const& __ec, bool __allow_dne = false) const {
2597 if (__dest_ec) {
2598 *__dest_ec = __ec;
2599 return;
2600 }
2601 if (__ec && (!__allow_dne || !__is_dne_error(__ec)))
2602 __throw_filesystem_error(__msg, __p_, __ec);
2603 }
2604
2605 _LIBCPP_INLINE_VISIBILITY
2606 void __refresh(error_code* __ec = nullptr) {
2607 __handle_error("in directory_entry::refresh", __ec, __do_refresh(),
2608 /*allow_dne*/ true);
2609 }
2610
2611 _LIBCPP_INLINE_VISIBILITY
2612 file_type __get_sym_ft(error_code* __ec = nullptr) const {
2613 switch (__data_.__cache_type_) {
2614 case _Empty:
2615 return __symlink_status(__p_, __ec).type();
2616 case _IterSymlink:
2617 case _RefreshSymlink:
2618 case _RefreshSymlinkUnresolved:
2619 if (__ec)
2620 __ec->clear();
2621 return file_type::symlink;
2622 case _IterNonSymlink:
2623 case _RefreshNonSymlink:
2624 file_status __st(__data_.__type_);
2625 if (__ec && !_VSTD_FS::exists(__st))
2626 *__ec = make_error_code(errc::no_such_file_or_directory);
2627 else if (__ec)
2628 __ec->clear();
2629 return __data_.__type_;
2630 }
2631 _LIBCPP_UNREACHABLE();
2632 }
2633
2634 _LIBCPP_INLINE_VISIBILITY
2635 file_type __get_ft(error_code* __ec = nullptr) const {
2636 switch (__data_.__cache_type_) {
2637 case _Empty:
2638 case _IterSymlink:
2639 case _RefreshSymlinkUnresolved:
2640 return __status(__p_, __ec).type();
2641 case _IterNonSymlink:
2642 case _RefreshNonSymlink:
2643 case _RefreshSymlink: {
2644 file_status __st(__data_.__type_);
2645 if (__ec && !_VSTD_FS::exists(__st))
2646 *__ec = make_error_code(errc::no_such_file_or_directory);
2647 else if (__ec)
2648 __ec->clear();
2649 return __data_.__type_;
2650 }
2651 }
2652 _LIBCPP_UNREACHABLE();
2653 }
2654
2655 _LIBCPP_INLINE_VISIBILITY
2656 file_status __get_status(error_code* __ec = nullptr) const {
2657 switch (__data_.__cache_type_) {
2658 case _Empty:
2659 case _IterNonSymlink:
2660 case _IterSymlink:
2661 case _RefreshSymlinkUnresolved:
2662 return __status(__p_, __ec);
2663 case _RefreshNonSymlink:
2664 case _RefreshSymlink:
2665 return file_status(__get_ft(__ec), __data_.__non_sym_perms_);
2666 }
2667 _LIBCPP_UNREACHABLE();
2668 }
2669
2670 _LIBCPP_INLINE_VISIBILITY
2671 file_status __get_symlink_status(error_code* __ec = nullptr) const {
2672 switch (__data_.__cache_type_) {
2673 case _Empty:
2674 case _IterNonSymlink:
2675 case _IterSymlink:
2676 return __symlink_status(__p_, __ec);
2677 case _RefreshNonSymlink:
2678 return file_status(__get_sym_ft(__ec), __data_.__non_sym_perms_);
2679 case _RefreshSymlink:
2680 case _RefreshSymlinkUnresolved:
2681 return file_status(__get_sym_ft(__ec), __data_.__sym_perms_);
2682 }
2683 _LIBCPP_UNREACHABLE();
2684 }
2685
2686 _LIBCPP_INLINE_VISIBILITY
2687 uintmax_t __get_size(error_code* __ec = nullptr) const {
2688 switch (__data_.__cache_type_) {
2689 case _Empty:
2690 case _IterNonSymlink:
2691 case _IterSymlink:
2692 case _RefreshSymlinkUnresolved:
2693 return _VSTD_FS::__file_size(__p_, __ec);
2694 case _RefreshSymlink:
2695 case _RefreshNonSymlink: {
2696 error_code __m_ec;
2697 file_status __st(__get_ft(&__m_ec));
2698 __handle_error("in directory_entry::file_size", __ec, __m_ec);
2699 if (_VSTD_FS::exists(__st) && !_VSTD_FS::is_regular_file(__st)) {
2700 errc __err_kind = _VSTD_FS::is_directory(__st) ? errc::is_a_directory
2701 : errc::not_supported;
2702 __handle_error("in directory_entry::file_size", __ec,
2703 make_error_code(__err_kind));
2704 }
2705 return __data_.__size_;
2706 }
2707 }
2708 _LIBCPP_UNREACHABLE();
2709 }
2710
2711 _LIBCPP_INLINE_VISIBILITY
2712 uintmax_t __get_nlink(error_code* __ec = nullptr) const {
2713 switch (__data_.__cache_type_) {
2714 case _Empty:
2715 case _IterNonSymlink:
2716 case _IterSymlink:
2717 case _RefreshSymlinkUnresolved:
2718 return _VSTD_FS::__hard_link_count(__p_, __ec);
2719 case _RefreshSymlink:
2720 case _RefreshNonSymlink: {
2721 error_code __m_ec;
2722 (void)__get_ft(&__m_ec);
2723 __handle_error("in directory_entry::hard_link_count", __ec, __m_ec);
2724 return __data_.__nlink_;
2725 }
2726 }
2727 _LIBCPP_UNREACHABLE();
2728 }
2729
2730 _LIBCPP_INLINE_VISIBILITY
2731 file_time_type __get_write_time(error_code* __ec = nullptr) const {
2732 switch (__data_.__cache_type_) {
2733 case _Empty:
2734 case _IterNonSymlink:
2735 case _IterSymlink:
2736 case _RefreshSymlinkUnresolved:
2737 return _VSTD_FS::__last_write_time(__p_, __ec);
2738 case _RefreshSymlink:
2739 case _RefreshNonSymlink: {
2740 error_code __m_ec;
2741 file_status __st(__get_ft(&__m_ec));
2742 __handle_error("in directory_entry::last_write_time", __ec, __m_ec);
2743 if (_VSTD_FS::exists(__st) &&
2744 __data_.__write_time_ == file_time_type::min())
2745 __handle_error("in directory_entry::last_write_time", __ec,
2746 make_error_code(errc::value_too_large));
2747 return __data_.__write_time_;
2748 }
2749 }
2750 _LIBCPP_UNREACHABLE();
2751 }
2752
2753private:
2754 _Path __p_;
2755 __cached_data __data_;
2756};
2757
2758class __dir_element_proxy {
2759public:
2760 inline _LIBCPP_INLINE_VISIBILITY directory_entry operator*() {
2761 return _VSTD::move(__elem_);
2762 }
2763
2764private:
2765 friend class directory_iterator;
2766 friend class recursive_directory_iterator;
2767 explicit __dir_element_proxy(directory_entry const& __e) : __elem_(__e) {}
2768 __dir_element_proxy(__dir_element_proxy&& __o)
2769 : __elem_(_VSTD::move(__o.__elem_)) {}
2770 directory_entry __elem_;
2771};
2772
2773class directory_iterator {
2774public:
2775 typedef directory_entry value_type;
2776 typedef ptrdiff_t difference_type;
2777 typedef value_type const* pointer;
2778 typedef value_type const& reference;
2779 typedef input_iterator_tag iterator_category;
2780
2781public:
2782 //ctor & dtor
2783 directory_iterator() noexcept {}
2784
2785 explicit directory_iterator(const path& __p)
2786 : directory_iterator(__p, nullptr) {}
2787
2788 directory_iterator(const path& __p, directory_options __opts)
2789 : directory_iterator(__p, nullptr, __opts) {}
2790
2791 directory_iterator(const path& __p, error_code& __ec)
2792 : directory_iterator(__p, &__ec) {}
2793
2794 directory_iterator(const path& __p, directory_options __opts,
2795 error_code& __ec)
2796 : directory_iterator(__p, &__ec, __opts) {}
2797
2798 directory_iterator(const directory_iterator&) = default;
2799 directory_iterator(directory_iterator&&) = default;
2800 directory_iterator& operator=(const directory_iterator&) = default;
2801
2802 directory_iterator& operator=(directory_iterator&& __o) noexcept {
2803 // non-default implementation provided to support self-move assign.
2804 if (this != &__o) {
2805 __imp_ = _VSTD::move(__o.__imp_);
2806 }
2807 return *this;
2808 }
2809
2810 ~directory_iterator() = default;
2811
2812 const directory_entry& operator*() const {
2813 _LIBCPP_ASSERT(__imp_, "The end iterator cannot be dereferenced");
2814 return __dereference();
2815 }
2816
2817 const directory_entry* operator->() const { return &**this; }
2818
2819 directory_iterator& operator++() { return __increment(); }
2820
2821 __dir_element_proxy operator++(int) {
2822 __dir_element_proxy __p(**this);
2823 __increment();
2824 return __p;
2825 }
2826
2827 directory_iterator& increment(error_code& __ec) { return __increment(&__ec); }
2828
2829private:
2830 inline _LIBCPP_INLINE_VISIBILITY friend bool
2831 operator==(const directory_iterator& __lhs,
2832 const directory_iterator& __rhs) noexcept;
2833
2834 // construct the dir_stream
2835 _LIBCPP_FUNC_VIS
2836 directory_iterator(const path&, error_code*,
2837 directory_options = directory_options::none);
2838
2839 _LIBCPP_FUNC_VIS
2840 directory_iterator& __increment(error_code* __ec = nullptr);
2841
2842 _LIBCPP_FUNC_VIS
2843 const directory_entry& __dereference() const;
2844
2845private:
2846 shared_ptr<__dir_stream> __imp_;
2847};
2848
2849inline _LIBCPP_INLINE_VISIBILITY bool
2850operator==(const directory_iterator& __lhs,
2851 const directory_iterator& __rhs) noexcept {
2852 return __lhs.__imp_ == __rhs.__imp_;
2853}
2854
2855inline _LIBCPP_INLINE_VISIBILITY bool
2856operator!=(const directory_iterator& __lhs,
2857 const directory_iterator& __rhs) noexcept {
2858 return !(__lhs == __rhs);
2859}
2860
2861// enable directory_iterator range-based for statements
2862inline _LIBCPP_INLINE_VISIBILITY directory_iterator
2863begin(directory_iterator __iter) noexcept {
2864 return __iter;
2865}
2866
2867inline _LIBCPP_INLINE_VISIBILITY directory_iterator
2868end(const directory_iterator&) noexcept {
2869 return directory_iterator();
2870}
2871
2872class recursive_directory_iterator {
2873public:
2874 using value_type = directory_entry;
2875 using difference_type = ptrdiff_t;
2876 using pointer = directory_entry const*;
2877 using reference = directory_entry const&;
2878 using iterator_category = input_iterator_tag;
2879
2880public:
2881 // constructors and destructor
2882 _LIBCPP_INLINE_VISIBILITY
2883 recursive_directory_iterator() noexcept : __rec_(false) {}
2884
2885 _LIBCPP_INLINE_VISIBILITY
2886 explicit recursive_directory_iterator(
2887 const path& __p, directory_options __xoptions = directory_options::none)
2888 : recursive_directory_iterator(__p, __xoptions, nullptr) {}
2889
2890 _LIBCPP_INLINE_VISIBILITY
2891 recursive_directory_iterator(const path& __p, directory_options __xoptions,
2892 error_code& __ec)
2893 : recursive_directory_iterator(__p, __xoptions, &__ec) {}
2894
2895 _LIBCPP_INLINE_VISIBILITY
2896 recursive_directory_iterator(const path& __p, error_code& __ec)
2897 : recursive_directory_iterator(__p, directory_options::none, &__ec) {}
2898
2899 recursive_directory_iterator(const recursive_directory_iterator&) = default;
2900 recursive_directory_iterator(recursive_directory_iterator&&) = default;
2901
2902 recursive_directory_iterator&
2903 operator=(const recursive_directory_iterator&) = default;
2904
2905 _LIBCPP_INLINE_VISIBILITY
2906 recursive_directory_iterator&
2907 operator=(recursive_directory_iterator&& __o) noexcept {
2908 // non-default implementation provided to support self-move assign.
2909 if (this != &__o) {
2910 __imp_ = _VSTD::move(__o.__imp_);
2911 __rec_ = __o.__rec_;
2912 }
2913 return *this;
2914 }
2915
2916 ~recursive_directory_iterator() = default;
2917
2918 _LIBCPP_INLINE_VISIBILITY
2919 const directory_entry& operator*() const { return __dereference(); }
2920
2921 _LIBCPP_INLINE_VISIBILITY
2922 const directory_entry* operator->() const { return &__dereference(); }
2923
2924 recursive_directory_iterator& operator++() { return __increment(); }
2925
2926 _LIBCPP_INLINE_VISIBILITY
2927 __dir_element_proxy operator++(int) {
2928 __dir_element_proxy __p(**this);
2929 __increment();
2930 return __p;
2931 }
2932
2933 _LIBCPP_INLINE_VISIBILITY
2934 recursive_directory_iterator& increment(error_code& __ec) {
2935 return __increment(&__ec);
2936 }
2937
2938 _LIBCPP_FUNC_VIS directory_options options() const;
2939 _LIBCPP_FUNC_VIS int depth() const;
2940
2941 _LIBCPP_INLINE_VISIBILITY
2942 void pop() { __pop(); }
2943
2944 _LIBCPP_INLINE_VISIBILITY
2945 void pop(error_code& __ec) { __pop(&__ec); }
2946
2947 _LIBCPP_INLINE_VISIBILITY
2948 bool recursion_pending() const { return __rec_; }
2949
2950 _LIBCPP_INLINE_VISIBILITY
2951 void disable_recursion_pending() { __rec_ = false; }
2952
2953private:
2954 _LIBCPP_FUNC_VIS
2955 recursive_directory_iterator(const path& __p, directory_options __opt,
2956 error_code* __ec);
2957
2958 _LIBCPP_FUNC_VIS
2959 const directory_entry& __dereference() const;
2960
2961 _LIBCPP_FUNC_VIS
2962 bool __try_recursion(error_code* __ec);
2963
2964 _LIBCPP_FUNC_VIS
2965 void __advance(error_code* __ec = nullptr);
2966
2967 _LIBCPP_FUNC_VIS
2968 recursive_directory_iterator& __increment(error_code* __ec = nullptr);
2969
2970 _LIBCPP_FUNC_VIS
2971 void __pop(error_code* __ec = nullptr);
2972
2973 inline _LIBCPP_INLINE_VISIBILITY friend bool
2974 operator==(const recursive_directory_iterator&,
2975 const recursive_directory_iterator&) noexcept;
2976
2977 struct _LIBCPP_HIDDEN __shared_imp;
2978 shared_ptr<__shared_imp> __imp_;
2979 bool __rec_;
2980}; // class recursive_directory_iterator
2981
2982inline _LIBCPP_INLINE_VISIBILITY bool
2983operator==(const recursive_directory_iterator& __lhs,
2984 const recursive_directory_iterator& __rhs) noexcept {
2985 return __lhs.__imp_ == __rhs.__imp_;
2986}
2987
2988_LIBCPP_INLINE_VISIBILITY
2989inline bool operator!=(const recursive_directory_iterator& __lhs,
2990 const recursive_directory_iterator& __rhs) noexcept {
2991 return !(__lhs == __rhs);
2992}
2993// enable recursive_directory_iterator range-based for statements
2994inline _LIBCPP_INLINE_VISIBILITY recursive_directory_iterator
2995begin(recursive_directory_iterator __iter) noexcept {
2996 return __iter;
2997}
2998
2999inline _LIBCPP_INLINE_VISIBILITY recursive_directory_iterator
3000end(const recursive_directory_iterator&) noexcept {
3001 return recursive_directory_iterator();
3002}
3003
3004_LIBCPP_AVAILABILITY_FILESYSTEM_POP
3005
3006_LIBCPP_END_NAMESPACE_FILESYSTEM
3007
3008#endif // !_LIBCPP_CXX03_LANG
3009
3010_LIBCPP_POP_MACROS
3011
3012269#endif // _LIBCPP_FILESYSTEM
lib/libcxx/include/float.h+1-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- float.h ----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/format+515-37
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- format -----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -13,59 +13,146 @@
1313/*
1414
1515namespace std {
16 // [format.error], class format_error
17 class format_error : public runtime_error {
18 public:
19 explicit format_error(const string& what_arg);
20 explicit format_error(const char* what_arg);
16 // [format.context], class template basic_format_context
17 template<class Out, class charT> class basic_format_context;
18 using format_context = basic_format_context<unspecified, char>;
19 using wformat_context = basic_format_context<unspecified, wchar_t>;
20
21 // [format.args], class template basic_format_args
22 template<class Context> class basic_format_args;
23 using format_args = basic_format_args<format_context>;
24 using wformat_args = basic_format_args<wformat_context>;
25
26 // [format.functions], formatting functions
27 template<class... Args>
28 string format(string_view fmt, const Args&... args);
29 template<class... Args>
30 wstring format(wstring_view fmt, const Args&... args);
31 template<class... Args>
32 string format(const locale& loc, string_view fmt, const Args&... args);
33 template<class... Args>
34 wstring format(const locale& loc, wstring_view fmt, const Args&... args);
35
36 string vformat(string_view fmt, format_args args);
37 wstring vformat(wstring_view fmt, wformat_args args);
38 string vformat(const locale& loc, string_view fmt, format_args args);
39 wstring vformat(const locale& loc, wstring_view fmt, wformat_args args);
40
41 template<class Out, class... Args>
42 Out format_to(Out out, string_view fmt, const Args&... args);
43 template<class Out, class... Args>
44 Out format_to(Out out, wstring_view fmt, const Args&... args);
45 template<class Out, class... Args>
46 Out format_to(Out out, const locale& loc, string_view fmt, const Args&... args);
47 template<class Out, class... Args>
48 Out format_to(Out out, const locale& loc, wstring_view fmt, const Args&... args);
49
50 template<class Out>
51 Out vformat_to(Out out, string_view fmt, format_args args);
52 template<class Out>
53 Out vformat_to(Out out, wstring_view fmt, wformat_args args);
54 template<class Out>
55 Out vformat_to(Out out, const locale& loc, string_view fmt,
56 format_args char> args);
57 template<class Out>
58 Out vformat_to(Out out, const locale& loc, wstring_view fmt,
59 wformat_args args);
60
61 template<class Out> struct format_to_n_result {
62 Out out;
63 iter_difference_t<Out> size;
2164 };
65 template<class Out, class... Args>
66 format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n,
67 string_view fmt, const Args&... args);
68 template<class Out, class... Args>
69 format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n,
70 wstring_view fmt, const Args&... args);
71 template<class Out, class... Args>
72 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);
75 template<class Out, class... Args>
76 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);
79
80 template<class... Args>
81 size_t formatted_size(string_view fmt, const Args&... args);
82 template<class... Args>
83 size_t formatted_size(wstring_view fmt, const Args&... args);
84 template<class... Args>
85 size_t formatted_size(const locale& loc, string_view fmt, const Args&... args);
86 template<class... Args>
87 size_t formatted_size(const locale& loc, wstring_view fmt, const Args&... args);
88
89 // [format.formatter], formatter
90 template<class T, class charT = char> struct formatter;
2291
2392 // [format.parse.ctx], class template basic_format_parse_context
24 template<class charT>
25 class basic_format_parse_context {
26 public:
27 using char_type = charT;
28 using const_iterator = typename basic_string_view<charT>::const_iterator;
29 using iterator = const_iterator;
30
31 private:
32 iterator begin_; // exposition only
33 iterator end_; // exposition only
34 enum indexing { unknown, manual, automatic }; // exposition only
35 indexing indexing_; // exposition only
36 size_t next_arg_id_; // exposition only
37 size_t num_args_; // exposition only
38
39 public:
40 constexpr explicit basic_format_parse_context(basic_string_view<charT> fmt,
41 size_t num_args = 0) noexcept;
42 basic_format_parse_context(const basic_format_parse_context&) = delete;
43 basic_format_parse_context& operator=(const basic_format_parse_context&) = delete;
44
45 constexpr const_iterator begin() const noexcept;
46 constexpr const_iterator end() const noexcept;
47 constexpr void advance_to(const_iterator it);
48
49 constexpr size_t next_arg_id();
50 constexpr void check_arg_id(size_t id);
51 };
93 template<class charT> class basic_format_parse_context;
5294 using format_parse_context = basic_format_parse_context<char>;
5395 using wformat_parse_context = basic_format_parse_context<wchar_t>;
96
97 // [format.arguments], arguments
98 // [format.arg], class template basic_format_arg
99 template<class Context> class basic_format_arg;
100
101 template<class Visitor, class Context>
102 see below visit_format_arg(Visitor&& vis, basic_format_arg<Context> arg);
103
104 // [format.arg.store], class template format-arg-store
105 template<class Context, class... Args> struct format-arg-store; // exposition only
106
107 template<class Context = format_context, class... Args>
108 format-arg-store<Context, Args...>
109 make_format_args(const Args&... args);
110 template<class... Args>
111 format-arg-store<wformat_context, Args...>
112 make_wformat_args(const Args&... args);
113
114 // [format.error], class format_error
115 class format_error;
54116}
55117
56118*/
57119
58// Make sure all feature tests macros are always available.
120// Make sure all feature-test macros are available.
59121#include <version>
60// Only enable the contents of the header when libc++ was build with LIBCXX_ENABLE_INCOMPLETE_FEATURES enabled
122// Enable the contents of the header only when libc++ was built with LIBCXX_ENABLE_INCOMPLETE_FEATURES.
61123#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_FORMAT)
62124
63125#include <__config>
126#include <__debug>
127#include <__format/format_arg.h>
128#include <__format/format_args.h>
129#include <__format/format_context.h>
64130#include <__format/format_error.h>
131#include <__format/format_fwd.h>
65132#include <__format/format_parse_context.h>
133#include <__format/format_string.h>
134#include <__format/format_to_n_result.h>
135#include <__format/formatter.h>
136#include <__format/formatter_bool.h>
137#include <__format/formatter_char.h>
138#include <__format/formatter_floating_point.h>
139#include <__format/formatter_integer.h>
140#include <__format/formatter_pointer.h>
141#include <__format/formatter_string.h>
142#include <__format/parser_std_format_spec.h>
143#include <__variant/monostate.h>
144#include <array>
145#include <concepts>
146#include <string>
147#include <string_view>
148#include <type_traits>
149
150#ifndef _LIBCPP_HAS_NO_LOCALIZATION
151#include <locale>
152#endif
66153
67154#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
68# pragma GCC system_header
155#pragma GCC system_header
69156#endif
70157
71158_LIBCPP_PUSH_MACROS
......@@ -75,6 +162,397 @@ _LIBCPP_BEGIN_NAMESPACE_STD
75162
76163#if _LIBCPP_STD_VER > 17
77164
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
171// TODO FMT Move the implementation in this file to its own granular headers.
172
173// TODO FMT Evaluate which templates should be external templates. This
174// improves the efficiency of the header. However since the header is still
175// under heavy development and not all classes are stable it makes no sense
176// to do this optimization now.
177
178using format_args = basic_format_args<format_context>;
179#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
180using wformat_args = basic_format_args<wformat_context>;
181#endif
182
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
189template <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)...};
193}
194
195#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
196template <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...);
200}
201#endif
202
203namespace __format {
204
205template <class _CharT, class _ParseCtx, class _Ctx>
206_LIBCPP_HIDE_FROM_ABI const _CharT*
207__handle_replacement_field(const _CharT* __begin, const _CharT* __end,
208 _ParseCtx& __parse_ctx, _Ctx& __ctx) {
209 __format::__parse_number_result __r =
210 __format::__parse_arg_id(__begin, __end, __parse_ctx);
211
212 switch (*__r.__ptr) {
213 case _CharT(':'):
214 // The arg-id has a format-specifier, advance the input to the format-spec.
215 __parse_ctx.advance_to(__r.__ptr + 1);
216 break;
217 case _CharT('}'):
218 // The arg-id has no format-specifier.
219 __parse_ctx.advance_to(__r.__ptr);
220 break;
221 default:
222 __throw_format_error(
223 "The replacement field arg-id should terminate at a ':' or '}'");
224 }
225
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));
239
240 __begin = __parse_ctx.begin();
241 if (__begin == __end || *__begin != _CharT('}'))
242 __throw_format_error("The replacement field misses a terminating '}'");
243
244 return ++__begin;
245}
246
247template <class _ParseCtx, class _Ctx>
248_LIBCPP_HIDE_FROM_ABI typename _Ctx::iterator
249__vformat_to(_ParseCtx&& __parse_ctx, _Ctx&& __ctx) {
250 using _CharT = typename _ParseCtx::char_type;
251 static_assert(same_as<typename _Ctx::char_type, _CharT>);
252
253 const _CharT* __begin = __parse_ctx.begin();
254 const _CharT* __end = __parse_ctx.end();
255 typename _Ctx::iterator __out_it = __ctx.out();
256 while (__begin != __end) {
257 switch (*__begin) {
258 case _CharT('{'):
259 ++__begin;
260 if (__begin == __end)
261 __throw_format_error("The format string terminates at a '{'");
262
263 if (*__begin != _CharT('{')) [[likely]] {
264 __ctx.advance_to(_VSTD::move(__out_it));
265 __begin =
266 __handle_replacement_field(__begin, __end, __parse_ctx, __ctx);
267 __out_it = __ctx.out();
268
269 // The output is written and __begin points to the next character. So
270 // start the next iteration.
271 continue;
272 }
273 // The string is an escape character.
274 break;
275
276 case _CharT('}'):
277 ++__begin;
278 if (__begin == __end || *__begin != _CharT('}'))
279 __throw_format_error(
280 "The format string contains an invalid escape sequence");
281
282 break;
283 }
284
285 // Copy the character to the output verbatim.
286 *__out_it++ = *__begin++;
287 }
288 return __out_it;
289}
290
291} // namespace __format
292
293template <class _OutIt, class _CharT, class _FormatOutIt>
294requires(output_iterator<_OutIt, const _CharT&>) _LIBCPP_HIDE_FROM_ABI _OutIt
295 __vformat_to(
296 _OutIt __out_it, basic_string_view<_CharT> __fmt,
297 basic_format_args<basic_format_context<_FormatOutIt, _CharT>> __args) {
298 if constexpr (same_as<_OutIt, _FormatOutIt>)
299 return _VSTD::__format::__vformat_to(
300 basic_format_parse_context{__fmt, __args.__size()},
301 _VSTD::__format_context_create(_VSTD::move(__out_it), __args));
302 else {
303 basic_string<_CharT> __str;
304 _VSTD::__format::__vformat_to(
305 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));
308 }
309}
310
311template <output_iterator<const char&> _OutIt>
312_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt
313vformat_to(_OutIt __out_it, string_view __fmt, format_args __args) {
314 return _VSTD::__vformat_to(_VSTD::move(__out_it), __fmt, __args);
315}
316
317#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
318template <output_iterator<const wchar_t&> _OutIt>
319_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt
320vformat_to(_OutIt __out_it, wstring_view __fmt, wformat_args __args) {
321 return _VSTD::__vformat_to(_VSTD::move(__out_it), __fmt, __args);
322}
323#endif
324
325template <output_iterator<const char&> _OutIt, class... _Args>
326_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,
329 _VSTD::make_format_args(__args...));
330}
331
332#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
333template <output_iterator<const wchar_t&> _OutIt, class... _Args>
334_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,
337 _VSTD::make_wformat_args(__args...));
338}
339#endif
340
341_LIBCPP_ALWAYS_INLINE inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT string
342vformat(string_view __fmt, format_args __args) {
343 string __res;
344 _VSTD::vformat_to(_VSTD::back_inserter(__res), __fmt, __args);
345 return __res;
346}
347
348#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
349_LIBCPP_ALWAYS_INLINE inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT wstring
350vformat(wstring_view __fmt, wformat_args __args) {
351 wstring __res;
352 _VSTD::vformat_to(_VSTD::back_inserter(__res), __fmt, __args);
353 return __res;
354}
355#endif
356
357template <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...));
361}
362
363#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
364template <class... _Args>
365_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...));
368}
369#endif
370
371template <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};
382}
383
384#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
385template <output_iterator<const wchar_t&> _OutIt, class... _Args>
386_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};
396}
397#endif
398
399template <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();
404}
405
406#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
407template <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();
412}
413#endif
414
415#ifndef _LIBCPP_HAS_NO_LOCALIZATION
416
417template <class _OutIt, class _CharT, class _FormatOutIt>
418requires(output_iterator<_OutIt, const _CharT&>) _LIBCPP_HIDE_FROM_ABI _OutIt
419 __vformat_to(
420 _OutIt __out_it, locale __loc, basic_string_view<_CharT> __fmt,
421 basic_format_args<basic_format_context<_FormatOutIt, _CharT>> __args) {
422 if constexpr (same_as<_OutIt, _FormatOutIt>)
423 return _VSTD::__format::__vformat_to(
424 basic_format_parse_context{__fmt, __args.__size()},
425 _VSTD::__format_context_create(_VSTD::move(__out_it), __args,
426 _VSTD::move(__loc)));
427 else {
428 basic_string<_CharT> __str;
429 _VSTD::__format::__vformat_to(
430 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));
434 }
435}
436
437template <output_iterator<const char&> _OutIt>
438_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt vformat_to(
439 _OutIt __out_it, locale __loc, string_view __fmt, format_args __args) {
440 return _VSTD::__vformat_to(_VSTD::move(__out_it), _VSTD::move(__loc), __fmt,
441 __args);
442}
443
444#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
445template <output_iterator<const wchar_t&> _OutIt>
446_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt vformat_to(
447 _OutIt __out_it, locale __loc, wstring_view __fmt, wformat_args __args) {
448 return _VSTD::__vformat_to(_VSTD::move(__out_it), _VSTD::move(__loc), __fmt,
449 __args);
450}
451#endif
452
453template <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,
457 _VSTD::make_format_args(__args...));
458}
459
460#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
461template <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,
465 _VSTD::make_wformat_args(__args...));
466}
467#endif
468
469_LIBCPP_ALWAYS_INLINE inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT string
470vformat(locale __loc, string_view __fmt, format_args __args) {
471 string __res;
472 _VSTD::vformat_to(_VSTD::back_inserter(__res), _VSTD::move(__loc), __fmt,
473 __args);
474 return __res;
475}
476
477#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
478_LIBCPP_ALWAYS_INLINE inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT wstring
479vformat(locale __loc, wstring_view __fmt, wformat_args __args) {
480 wstring __res;
481 _VSTD::vformat_to(_VSTD::back_inserter(__res), _VSTD::move(__loc), __fmt,
482 __args);
483 return __res;
484}
485#endif
486
487template <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,
491 _VSTD::make_format_args(__args...));
492}
493
494#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
495template <class... _Args>
496_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,
499 _VSTD::make_wformat_args(__args...));
500}
501#endif
502
503template <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};
515}
516
517#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
518template <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};
530}
531#endif
532
533template <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();
540}
541
542#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
543template <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();
550}
551#endif
552
553#endif // _LIBCPP_HAS_NO_LOCALIZATION
554
555#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
78556#endif //_LIBCPP_STD_VER > 17
79557
80558_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/forward_list+22-21
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===----------------------- forward_list ---------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -186,6 +186,7 @@ template <class T, class Allocator, class Predicate>
186186#include <iterator>
187187#include <limits>
188188#include <memory>
189#include <type_traits>
189190#include <version>
190191
191192#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -643,12 +644,12 @@ public:
643644 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
644645 "Allocator::value_type must be same type as value_type");
645646
646 typedef value_type& reference;
647 typedef const value_type& const_reference;
648 typedef typename allocator_traits<allocator_type>::pointer pointer;
649 typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
650 typedef typename allocator_traits<allocator_type>::size_type size_type;
651 typedef typename allocator_traits<allocator_type>::difference_type difference_type;
647 typedef value_type& reference;
648 typedef const value_type& const_reference;
649 typedef typename allocator_traits<allocator_type>::pointer pointer;
650 typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
651 typedef typename allocator_traits<allocator_type>::size_type size_type;
652 typedef typename allocator_traits<allocator_type>::difference_type difference_type;
652653
653654 typedef typename base::iterator iterator;
654655 typedef typename base::const_iterator const_iterator;
......@@ -669,7 +670,13 @@ public:
669670 explicit forward_list(size_type __n, const allocator_type& __a);
670671#endif
671672 forward_list(size_type __n, const value_type& __v);
672 forward_list(size_type __n, const value_type& __v, const allocator_type& __a);
673
674 template <class = __enable_if_t<__is_allocator<_Alloc>::value> >
675 forward_list(size_type __n, const value_type& __v, const allocator_type& __a) : base(__a)
676 {
677 insert_after(cbefore_begin(), __n, __v);
678 }
679
673680 template <class _InputIterator>
674681 forward_list(_InputIterator __f, _InputIterator __l,
675682 typename enable_if<
......@@ -870,17 +877,19 @@ private:
870877};
871878
872879
873#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
880#if _LIBCPP_STD_VER >= 17
874881template<class _InputIterator,
875882 class _Alloc = allocator<__iter_value_type<_InputIterator>>,
876 class = _EnableIf<__is_allocator<_Alloc>::value>
883 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
884 class = enable_if_t<__is_allocator<_Alloc>::value>
877885 >
878886forward_list(_InputIterator, _InputIterator)
879887 -> forward_list<__iter_value_type<_InputIterator>, _Alloc>;
880888
881889template<class _InputIterator,
882890 class _Alloc,
883 class = _EnableIf<__is_allocator<_Alloc>::value>
891 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
892 class = enable_if_t<__is_allocator<_Alloc>::value>
884893 >
885894forward_list(_InputIterator, _InputIterator, _Alloc)
886895 -> forward_list<__iter_value_type<_InputIterator>, _Alloc>;
......@@ -941,14 +950,6 @@ forward_list<_Tp, _Alloc>::forward_list(size_type __n, const value_type& __v)
941950 insert_after(cbefore_begin(), __n, __v);
942951}
943952
944template <class _Tp, class _Alloc>
945forward_list<_Tp, _Alloc>::forward_list(size_type __n, const value_type& __v,
946 const allocator_type& __a)
947 : base(__a)
948{
949 insert_after(cbefore_begin(), __n, __v);
950}
951
952953template <class _Tp, class _Alloc>
953954template <class _InputIterator>
954955forward_list<_Tp, _Alloc>::forward_list(_InputIterator __f, _InputIterator __l,
......@@ -990,7 +991,7 @@ template <class _Tp, class _Alloc>
990991forward_list<_Tp, _Alloc>&
991992forward_list<_Tp, _Alloc>::operator=(const forward_list& __x)
992993{
993 if (this != &__x)
994 if (this != _VSTD::addressof(__x))
994995 {
995996 base::__copy_assign_alloc(__x);
996997 assign(__x.begin(), __x.end());
......@@ -1585,7 +1586,7 @@ template <class _Compare>
15851586void
15861587forward_list<_Tp, _Alloc>::merge(forward_list& __x, _Compare __comp)
15871588{
1588 if (this != &__x)
1589 if (this != _VSTD::addressof(__x))
15891590 {
15901591 base::__before_begin()->__next_ = __merge(base::__before_begin()->__next_,
15911592 __x.__before_begin()->__next_,
lib/libcxx/include/fstream+2-27
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===------------------------- fstream ------------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -187,6 +187,7 @@ typedef basic_fstream<wchar_t> wfstream;
187187#include <cstdlib>
188188#include <istream>
189189#include <ostream>
190#include <version>
190191
191192#if !defined(_LIBCPP_HAS_NO_FILESYSTEM_LIBRARY)
192193# include <filesystem>
......@@ -230,7 +231,6 @@ public:
230231 // 27.9.1.4 Members:
231232 _LIBCPP_INLINE_VISIBILITY
232233 bool is_open() const;
233#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
234234 basic_filebuf* open(const char* __s, ios_base::openmode __mode);
235235#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
236236 basic_filebuf* open(const wchar_t* __s, ios_base::openmode __mode);
......@@ -246,7 +246,6 @@ public:
246246#endif
247247 _LIBCPP_INLINE_VISIBILITY
248248 basic_filebuf* __open(int __fd, ios_base::openmode __mode);
249#endif
250249 basic_filebuf* close();
251250
252251 _LIBCPP_INLINE_VISIBILITY
......@@ -542,7 +541,6 @@ const char* basic_filebuf<_CharT, _Traits>::__make_mdstring(
542541 _LIBCPP_UNREACHABLE();
543542}
544543
545#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
546544template <class _CharT, class _Traits>
547545basic_filebuf<_CharT, _Traits>*
548546basic_filebuf<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode)
......@@ -685,7 +683,6 @@ basic_filebuf<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mod
685683{
686684 return open(__s.c_str(), __mode);
687685}
688#endif
689686
690687template <class _CharT, class _Traits>
691688basic_filebuf<_CharT, _Traits>*
......@@ -1141,7 +1138,6 @@ public:
11411138
11421139 _LIBCPP_INLINE_VISIBILITY
11431140 basic_ifstream();
1144#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
11451141 _LIBCPP_INLINE_VISIBILITY
11461142 explicit basic_ifstream(const char* __s, ios_base::openmode __mode = ios_base::in);
11471143#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
......@@ -1155,7 +1151,6 @@ public:
11551151 explicit basic_ifstream(const filesystem::path& __p, ios_base::openmode __mode = ios_base::in)
11561152 : basic_ifstream(__p.c_str(), __mode) {}
11571153#endif // _LIBCPP_STD_VER >= 17
1158#endif
11591154 _LIBCPP_INLINE_VISIBILITY
11601155 basic_ifstream(basic_ifstream&& __rhs);
11611156 _LIBCPP_INLINE_VISIBILITY
......@@ -1167,7 +1162,6 @@ public:
11671162 basic_filebuf<char_type, traits_type>* rdbuf() const;
11681163 _LIBCPP_INLINE_VISIBILITY
11691164 bool is_open() const;
1170#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
11711165 void open(const char* __s, ios_base::openmode __mode = ios_base::in);
11721166#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
11731167 void open(const wchar_t* __s, ios_base::openmode __mode = ios_base::in);
......@@ -1183,7 +1177,6 @@ public:
11831177
11841178 _LIBCPP_INLINE_VISIBILITY
11851179 void __open(int __fd, ios_base::openmode __mode);
1186#endif
11871180 _LIBCPP_INLINE_VISIBILITY
11881181 void close();
11891182
......@@ -1198,7 +1191,6 @@ basic_ifstream<_CharT, _Traits>::basic_ifstream()
11981191{
11991192}
12001193
1201#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
12021194template <class _CharT, class _Traits>
12031195inline
12041196basic_ifstream<_CharT, _Traits>::basic_ifstream(const char* __s, ios_base::openmode __mode)
......@@ -1227,7 +1219,6 @@ basic_ifstream<_CharT, _Traits>::basic_ifstream(const string& __s, ios_base::ope
12271219 if (__sb_.open(__s, __mode | ios_base::in) == nullptr)
12281220 this->setstate(ios_base::failbit);
12291221}
1230#endif
12311222
12321223template <class _CharT, class _Traits>
12331224inline
......@@ -1281,7 +1272,6 @@ basic_ifstream<_CharT, _Traits>::is_open() const
12811272 return __sb_.is_open();
12821273}
12831274
1284#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
12851275template <class _CharT, class _Traits>
12861276void
12871277basic_ifstream<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode)
......@@ -1323,7 +1313,6 @@ void basic_ifstream<_CharT, _Traits>::__open(int __fd,
13231313 else
13241314 this->setstate(ios_base::failbit);
13251315}
1326#endif
13271316
13281317template <class _CharT, class _Traits>
13291318inline
......@@ -1375,7 +1364,6 @@ public:
13751364 basic_filebuf<char_type, traits_type>* rdbuf() const;
13761365 _LIBCPP_INLINE_VISIBILITY
13771366 bool is_open() const;
1378#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
13791367 void open(const char* __s, ios_base::openmode __mode = ios_base::out);
13801368#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
13811369 void open(const wchar_t* __s, ios_base::openmode __mode = ios_base::out);
......@@ -1390,7 +1378,6 @@ public:
13901378
13911379 _LIBCPP_INLINE_VISIBILITY
13921380 void __open(int __fd, ios_base::openmode __mode);
1393#endif
13941381 _LIBCPP_INLINE_VISIBILITY
13951382 void close();
13961383
......@@ -1405,7 +1392,6 @@ basic_ofstream<_CharT, _Traits>::basic_ofstream()
14051392{
14061393}
14071394
1408#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
14091395template <class _CharT, class _Traits>
14101396inline
14111397basic_ofstream<_CharT, _Traits>::basic_ofstream(const char* __s, ios_base::openmode __mode)
......@@ -1434,7 +1420,6 @@ basic_ofstream<_CharT, _Traits>::basic_ofstream(const string& __s, ios_base::ope
14341420 if (__sb_.open(__s, __mode | ios_base::out) == nullptr)
14351421 this->setstate(ios_base::failbit);
14361422}
1437#endif
14381423
14391424template <class _CharT, class _Traits>
14401425inline
......@@ -1488,7 +1473,6 @@ basic_ofstream<_CharT, _Traits>::is_open() const
14881473 return __sb_.is_open();
14891474}
14901475
1491#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
14921476template <class _CharT, class _Traits>
14931477void
14941478basic_ofstream<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode)
......@@ -1530,7 +1514,6 @@ void basic_ofstream<_CharT, _Traits>::__open(int __fd,
15301514 else
15311515 this->setstate(ios_base::failbit);
15321516}
1533#endif
15341517
15351518template <class _CharT, class _Traits>
15361519inline
......@@ -1556,7 +1539,6 @@ public:
15561539
15571540 _LIBCPP_INLINE_VISIBILITY
15581541 basic_fstream();
1559#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
15601542 _LIBCPP_INLINE_VISIBILITY
15611543 explicit basic_fstream(const char* __s, ios_base::openmode __mode = ios_base::in | ios_base::out);
15621544#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
......@@ -1572,7 +1554,6 @@ public:
15721554 : basic_fstream(__p.c_str(), __mode) {}
15731555#endif // _LIBCPP_STD_VER >= 17
15741556
1575#endif
15761557 _LIBCPP_INLINE_VISIBILITY
15771558 basic_fstream(basic_fstream&& __rhs);
15781559
......@@ -1586,7 +1567,6 @@ public:
15861567 basic_filebuf<char_type, traits_type>* rdbuf() const;
15871568 _LIBCPP_INLINE_VISIBILITY
15881569 bool is_open() const;
1589#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
15901570 void open(const char* __s, ios_base::openmode __mode = ios_base::in | ios_base::out);
15911571#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
15921572 void open(const wchar_t* __s, ios_base::openmode __mode = ios_base::in | ios_base::out);
......@@ -1599,7 +1579,6 @@ public:
15991579 { return open(__p.c_str(), __mode); }
16001580#endif // _LIBCPP_STD_VER >= 17
16011581
1602#endif
16031582 _LIBCPP_INLINE_VISIBILITY
16041583 void close();
16051584
......@@ -1614,7 +1593,6 @@ basic_fstream<_CharT, _Traits>::basic_fstream()
16141593{
16151594}
16161595
1617#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
16181596template <class _CharT, class _Traits>
16191597inline
16201598basic_fstream<_CharT, _Traits>::basic_fstream(const char* __s, ios_base::openmode __mode)
......@@ -1643,7 +1621,6 @@ basic_fstream<_CharT, _Traits>::basic_fstream(const string& __s, ios_base::openm
16431621 if (__sb_.open(__s, __mode) == nullptr)
16441622 this->setstate(ios_base::failbit);
16451623}
1646#endif
16471624
16481625template <class _CharT, class _Traits>
16491626inline
......@@ -1697,7 +1674,6 @@ basic_fstream<_CharT, _Traits>::is_open() const
16971674 return __sb_.is_open();
16981675}
16991676
1700#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
17011677template <class _CharT, class _Traits>
17021678void
17031679basic_fstream<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode)
......@@ -1729,7 +1705,6 @@ basic_fstream<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mod
17291705 else
17301706 this->setstate(ios_base::failbit);
17311707}
1732#endif
17331708
17341709template <class _CharT, class _Traits>
17351710inline
lib/libcxx/include/functional+7-1
......@@ -135,6 +135,9 @@ struct less_equal {
135135 bool operator()(const T& x, const T& y) const;
136136};
137137
138// [comparisons.three.way], class compare_three_way
139struct compare_three_way;
140
138141template <class T> // <class T=void> in C++14
139142struct logical_and {
140143 bool operator()(const T& x, const T& y) const;
......@@ -488,14 +491,17 @@ POLICY: For non-variadic implementations, the number of arguments is limited
488491*/
489492
490493#include <__algorithm/search.h>
494#include <__compare/compare_three_way.h>
491495#include <__config>
492496#include <__debug>
493497#include <__functional/binary_function.h> // TODO: deprecate
494498#include <__functional/binary_negate.h>
495#include <__functional/bind_front.h>
496499#include <__functional/bind.h>
500#include <__functional/bind_back.h>
501#include <__functional/bind_front.h>
497502#include <__functional/binder1st.h>
498503#include <__functional/binder2nd.h>
504#include <__functional/compose.h>
499505#include <__functional/default_searcher.h>
500506#include <__functional/function.h>
501507#include <__functional/hash.h>
lib/libcxx/include/future+7-6
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- future -----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -366,7 +366,7 @@ template <class R, class Alloc> struct uses_allocator<packaged_task<R>, Alloc>;
366366#include <__debug>
367367#include <__memory/allocator_arg_t.h>
368368#include <__memory/uses_allocator.h>
369#include <__utility/__decay_copy.h>
369#include <__utility/auto_cast.h>
370370#include <__utility/forward.h>
371371#include <chrono>
372372#include <exception>
......@@ -374,6 +374,7 @@ template <class R, class Alloc> struct uses_allocator<packaged_task<R>, Alloc>;
374374#include <mutex>
375375#include <system_error>
376376#include <thread>
377#include <version>
377378
378379#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
379380#pragma GCC system_header
......@@ -2207,16 +2208,16 @@ async(launch __policy, _Fp&& __f, _Args&&... __args)
22072208 {
22082209#endif
22092210 if (__does_policy_contain(__policy, launch::async))
2210 return _VSTD::__make_async_assoc_state<_Rp>(_BF(_VSTD::__decay_copy(_VSTD::forward<_Fp>(__f)),
2211 _VSTD::__decay_copy(_VSTD::forward<_Args>(__args))...));
2211 return _VSTD::__make_async_assoc_state<_Rp>(_BF(_LIBCPP_AUTO_CAST(_VSTD::forward<_Fp>(__f)),
2212 _LIBCPP_AUTO_CAST(_VSTD::forward<_Args>(__args))...));
22122213#ifndef _LIBCPP_NO_EXCEPTIONS
22132214 }
22142215 catch ( ... ) { if (__policy == launch::async) throw ; }
22152216#endif
22162217
22172218 if (__does_policy_contain(__policy, launch::deferred))
2218 return _VSTD::__make_deferred_assoc_state<_Rp>(_BF(_VSTD::__decay_copy(_VSTD::forward<_Fp>(__f)),
2219 _VSTD::__decay_copy(_VSTD::forward<_Args>(__args))...));
2219 return _VSTD::__make_deferred_assoc_state<_Rp>(_BF(_LIBCPP_AUTO_CAST(_VSTD::forward<_Fp>(__f)),
2220 _LIBCPP_AUTO_CAST(_VSTD::forward<_Args>(__args))...));
22202221 return future<_Rp>{};
22212222}
22222223
lib/libcxx/include/initializer_list+2-2
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===----------------------- initializer_list -----------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -112,6 +112,6 @@ end(initializer_list<_Ep> __il) _NOEXCEPT
112112
113113#endif // !defined(_LIBCPP_CXX03_LANG)
114114
115} // std
115} // namespace std
116116
117117#endif // _LIBCPP_INITIALIZER_LIST
lib/libcxx/include/inttypes.h+1-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- inttypes.h -------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/iomanip+1-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- iomanip ----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/ios+4-5
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===---------------------------- ios -------------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -214,6 +214,7 @@ storage-class-specifier const error_category& iostream_category() noexcept;
214214#include <__locale>
215215#include <iosfwd>
216216#include <system_error>
217#include <version>
217218
218219#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
219220#include <atomic> // for __xindex_
......@@ -308,11 +309,9 @@ public:
308309 typedef void (*event_callback)(event, ios_base&, int __index);
309310 void register_callback(event_callback __fn, int __index);
310311
311private:
312 ios_base(const ios_base&); // = delete;
313 ios_base& operator=(const ios_base&); // = delete;
312 ios_base(const ios_base&) = delete;
313 ios_base& operator=(const ios_base&) = delete;
314314
315public:
316315 static bool sync_with_stdio(bool __sync = true);
317316
318317 _LIBCPP_INLINE_VISIBILITY iostate rdstate() const;
lib/libcxx/include/iosfwd+26-17
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- iosfwd -----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -95,7 +95,8 @@ using u32streampos = fpos<char_traits<char32_t>::state_type>;
9595*/
9696
9797#include <__config>
98#include <wchar.h> // for mbstate_t
98#include <__mbstate_t.h>
99#include <version>
99100
100101#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
101102#pragma GCC system_header
......@@ -112,7 +113,9 @@ template<> struct char_traits<char8_t>;
112113#endif
113114template<> struct char_traits<char16_t>;
114115template<> struct char_traits<char32_t>;
116#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
115117template<> struct char_traits<wchar_t>;
118#endif
116119
117120template<class _Tp> class _LIBCPP_TEMPLATE_VIS allocator;
118121
......@@ -156,7 +159,9 @@ template <class _CharT, class _Traits = char_traits<_CharT> >
156159 class _LIBCPP_TEMPLATE_VIS ostreambuf_iterator;
157160
158161typedef basic_ios<char> ios;
162#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
159163typedef basic_ios<wchar_t> wios;
164#endif
160165
161166typedef basic_streambuf<char> streambuf;
162167typedef basic_istream<char> istream;
......@@ -173,6 +178,7 @@ typedef basic_ifstream<char> ifstream;
173178typedef basic_ofstream<char> ofstream;
174179typedef basic_fstream<char> fstream;
175180
181#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
176182typedef basic_streambuf<wchar_t> wstreambuf;
177183typedef basic_istream<wchar_t> wistream;
178184typedef basic_ostream<wchar_t> wostream;
......@@ -187,36 +193,37 @@ typedef basic_filebuf<wchar_t> wfilebuf;
187193typedef basic_ifstream<wchar_t> wifstream;
188194typedef basic_ofstream<wchar_t> wofstream;
189195typedef basic_fstream<wchar_t> wfstream;
196#endif
190197
191198template <class _CharT, class _Traits>
192 class _LIBCPP_PREFERRED_NAME(ios) _LIBCPP_PREFERRED_NAME(wios) basic_ios;
199 class _LIBCPP_PREFERRED_NAME(ios) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wios)) basic_ios;
193200
194201template <class _CharT, class _Traits>
195 class _LIBCPP_PREFERRED_NAME(streambuf) _LIBCPP_PREFERRED_NAME(wstreambuf) basic_streambuf;
202 class _LIBCPP_PREFERRED_NAME(streambuf) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wstreambuf)) basic_streambuf;
196203template <class _CharT, class _Traits>
197 class _LIBCPP_PREFERRED_NAME(istream) _LIBCPP_PREFERRED_NAME(wistream) basic_istream;
204 class _LIBCPP_PREFERRED_NAME(istream) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wistream)) basic_istream;
198205template <class _CharT, class _Traits>
199 class _LIBCPP_PREFERRED_NAME(ostream) _LIBCPP_PREFERRED_NAME(wostream) basic_ostream;
206 class _LIBCPP_PREFERRED_NAME(ostream) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wostream)) basic_ostream;
200207template <class _CharT, class _Traits>
201 class _LIBCPP_PREFERRED_NAME(iostream) _LIBCPP_PREFERRED_NAME(wiostream) basic_iostream;
208 class _LIBCPP_PREFERRED_NAME(iostream) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wiostream)) basic_iostream;
202209
203210template <class _CharT, class _Traits, class _Allocator>
204 class _LIBCPP_PREFERRED_NAME(stringbuf) _LIBCPP_PREFERRED_NAME(wstringbuf) basic_stringbuf;
211 class _LIBCPP_PREFERRED_NAME(stringbuf) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wstringbuf)) basic_stringbuf;
205212template <class _CharT, class _Traits, class _Allocator>
206 class _LIBCPP_PREFERRED_NAME(istringstream) _LIBCPP_PREFERRED_NAME(wistringstream) basic_istringstream;
213 class _LIBCPP_PREFERRED_NAME(istringstream) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wistringstream)) basic_istringstream;
207214template <class _CharT, class _Traits, class _Allocator>
208 class _LIBCPP_PREFERRED_NAME(ostringstream) _LIBCPP_PREFERRED_NAME(wostringstream) basic_ostringstream;
215 class _LIBCPP_PREFERRED_NAME(ostringstream) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wostringstream)) basic_ostringstream;
209216template <class _CharT, class _Traits, class _Allocator>
210 class _LIBCPP_PREFERRED_NAME(stringstream) _LIBCPP_PREFERRED_NAME(wstringstream) basic_stringstream;
217 class _LIBCPP_PREFERRED_NAME(stringstream) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wstringstream)) basic_stringstream;
211218
212219template <class _CharT, class _Traits>
213 class _LIBCPP_PREFERRED_NAME(filebuf) _LIBCPP_PREFERRED_NAME(wfilebuf) basic_filebuf;
220 class _LIBCPP_PREFERRED_NAME(filebuf) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wfilebuf)) basic_filebuf;
214221template <class _CharT, class _Traits>
215 class _LIBCPP_PREFERRED_NAME(ifstream) _LIBCPP_PREFERRED_NAME(wifstream) basic_ifstream;
222 class _LIBCPP_PREFERRED_NAME(ifstream) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wifstream)) basic_ifstream;
216223template <class _CharT, class _Traits>
217 class _LIBCPP_PREFERRED_NAME(ofstream) _LIBCPP_PREFERRED_NAME(wofstream) basic_ofstream;
224 class _LIBCPP_PREFERRED_NAME(ofstream) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wofstream)) basic_ofstream;
218225template <class _CharT, class _Traits>
219 class _LIBCPP_PREFERRED_NAME(fstream) _LIBCPP_PREFERRED_NAME(wfstream) basic_fstream;
226 class _LIBCPP_PREFERRED_NAME(fstream) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wfstream)) basic_fstream;
220227
221228template <class _State> class _LIBCPP_TEMPLATE_VIS fpos;
222229typedef fpos<mbstate_t> streampos;
......@@ -227,7 +234,7 @@ typedef fpos<mbstate_t> u8streampos;
227234#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
228235typedef fpos<mbstate_t> u16streampos;
229236typedef fpos<mbstate_t> u32streampos;
230#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
237#endif
231238
232239#if defined(_NEWLIB_VERSION)
233240// On newlib, off_t is 'long int'
......@@ -241,10 +248,12 @@ template <class _CharT, // for <stdexcept>
241248 class _Allocator = allocator<_CharT> >
242249 class _LIBCPP_TEMPLATE_VIS basic_string;
243250typedef basic_string<char, char_traits<char>, allocator<char> > string;
251#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
244252typedef basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> > wstring;
253#endif
245254
246255template <class _CharT, class _Traits, class _Allocator>
247 class _LIBCPP_PREFERRED_NAME(string) _LIBCPP_PREFERRED_NAME(wstring) basic_string;
256 class _LIBCPP_PREFERRED_NAME(string) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wstring)) basic_string;
248257
249258// Include other forward declarations here
250259template <class _Tp, class _Alloc = allocator<_Tp> >
lib/libcxx/include/iostream+8-8
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- iostream ---------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -38,6 +38,7 @@ extern wostream wclog;
3838#include <istream>
3939#include <ostream>
4040#include <streambuf>
41#include <version>
4142
4243#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
4344#pragma GCC system_header
......@@ -45,18 +46,17 @@ extern wostream wclog;
4546
4647_LIBCPP_BEGIN_NAMESPACE_STD
4748
48#ifndef _LIBCPP_HAS_NO_STDIN
4949extern _LIBCPP_FUNC_VIS istream cin;
50extern _LIBCPP_FUNC_VIS wistream wcin;
51#endif
52#ifndef _LIBCPP_HAS_NO_STDOUT
5350extern _LIBCPP_FUNC_VIS ostream cout;
54extern _LIBCPP_FUNC_VIS wostream wcout;
55#endif
5651extern _LIBCPP_FUNC_VIS ostream cerr;
57extern _LIBCPP_FUNC_VIS wostream wcerr;
5852extern _LIBCPP_FUNC_VIS ostream clog;
53
54#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
55extern _LIBCPP_FUNC_VIS wistream wcin;
56extern _LIBCPP_FUNC_VIS wostream wcout;
57extern _LIBCPP_FUNC_VIS wostream wcerr;
5958extern _LIBCPP_FUNC_VIS wostream wclog;
59#endif
6060
6161_LIBCPP_END_NAMESPACE_STD
6262
lib/libcxx/include/istream+6-4
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- istream ----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -291,15 +291,15 @@ class _LIBCPP_TEMPLATE_VIS basic_istream<_CharT, _Traits>::sentry
291291{
292292 bool __ok_;
293293
294 sentry(const sentry&); // = delete;
295 sentry& operator=(const sentry&); // = delete;
296
297294public:
298295 explicit sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false);
299296// ~sentry() = default;
300297
301298 _LIBCPP_INLINE_VISIBILITY
302299 explicit operator bool() const {return __ok_;}
300
301 sentry(const sentry&) = delete;
302 sentry& operator=(const sentry&) = delete;
303303};
304304
305305template <class _CharT, class _Traits>
......@@ -1628,7 +1628,9 @@ operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x)
16281628}
16291629
16301630_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istream<char>)
1631#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
16311632_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istream<wchar_t>)
1633#endif
16321634_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_iostream<char>)
16331635
16341636_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/iterator+16-5
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===-------------------------- iterator ----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -140,6 +140,11 @@ template<class In, class Out>
140140template<class I1, class I2 = I1>
141141 concept indirectly_swappable = see below; // since C++20
142142
143template<class I1, class I2, class R, class P1 = identity,
144 class P2 = identity>
145 concept indirectly_comparable =
146 indirect_binary_predicate<R, projected<I1, P1>, projected<I2, P2>>; // since C++20
147
143148template<input_or_output_iterator I, sentinel_for<I> S>
144149 requires (!same_as<I, S> && copyable<I>)
145150class common_iterator; // since C++20
......@@ -410,6 +415,10 @@ template<input_iterator I>
410415 requires see below
411416 struct iterator_traits<counted_iterator<I>>;
412417
418// [unreachable.sentinel], unreachable sentinel
419struct unreachable_sentinel_t;
420inline constexpr unreachable_sentinel_t unreachable_sentinel{};
421
413422template <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t>
414423class istream_iterator
415424 : public iterator<input_iterator_tag, T, Distance, const T*, const T&> // until C++17
......@@ -589,23 +598,25 @@ template <class E> constexpr const E* data(initializer_list<E> il) noexcept;
589598#include <__iterator/erase_if_container.h>
590599#include <__iterator/front_insert_iterator.h>
591600#include <__iterator/incrementable_traits.h>
601#include <__iterator/indirectly_comparable.h>
592602#include <__iterator/insert_iterator.h>
593#include <__iterator/istreambuf_iterator.h>
594603#include <__iterator/istream_iterator.h>
595#include <__iterator/iterator.h>
596#include <__iterator/iterator_traits.h>
604#include <__iterator/istreambuf_iterator.h>
597605#include <__iterator/iter_move.h>
598606#include <__iterator/iter_swap.h>
607#include <__iterator/iterator.h>
608#include <__iterator/iterator_traits.h>
599609#include <__iterator/move_iterator.h>
600610#include <__iterator/next.h>
601#include <__iterator/ostreambuf_iterator.h>
602611#include <__iterator/ostream_iterator.h>
612#include <__iterator/ostreambuf_iterator.h>
603613#include <__iterator/prev.h>
604614#include <__iterator/projected.h>
605615#include <__iterator/readable_traits.h>
606616#include <__iterator/reverse_access.h>
607617#include <__iterator/reverse_iterator.h>
608618#include <__iterator/size.h>
619#include <__iterator/unreachable_sentinel.h>
609620#include <__iterator/wrap_iter.h>
610621#include <__memory/addressof.h>
611622#include <__memory/pointer_traits.h>
lib/libcxx/include/latch+2-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- latch -----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -43,6 +43,7 @@ namespace std
4343#include <__availability>
4444#include <__config>
4545#include <atomic>
46#include <version>
4647
4748#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
4849#pragma GCC system_header
lib/libcxx/include/limits+1-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===---------------------------- limits ----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/limits.h+1-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- limits.h ---------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/list+122-198
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===---------------------------- list ------------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -319,9 +319,7 @@ public:
319319 _LIBCPP_INLINE_VISIBILITY
320320 __list_iterator() _NOEXCEPT : __ptr_(nullptr)
321321 {
322#if _LIBCPP_DEBUG_LEVEL == 2
323 __get_db()->__insert_i(this);
324#endif
322 _VSTD::__debug_db_insert_i(this);
325323 }
326324
327325#if _LIBCPP_DEBUG_LEVEL == 2
......@@ -330,7 +328,7 @@ public:
330328 __list_iterator(const __list_iterator& __p)
331329 : __ptr_(__p.__ptr_)
332330 {
333 __get_db()->__iterator_copy(this, &__p);
331 __get_db()->__iterator_copy(this, _VSTD::addressof(__p));
334332 }
335333
336334 _LIBCPP_INLINE_VISIBILITY
......@@ -342,9 +340,9 @@ public:
342340 _LIBCPP_INLINE_VISIBILITY
343341 __list_iterator& operator=(const __list_iterator& __p)
344342 {
345 if (this != &__p)
343 if (this != _VSTD::addressof(__p))
346344 {
347 __get_db()->__iterator_copy(this, &__p);
345 __get_db()->__iterator_copy(this, _VSTD::addressof(__p));
348346 __ptr_ = __p.__ptr_;
349347 }
350348 return *this;
......@@ -355,29 +353,23 @@ public:
355353 _LIBCPP_INLINE_VISIBILITY
356354 reference operator*() const
357355 {
358#if _LIBCPP_DEBUG_LEVEL == 2
359 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
360 "Attempted to dereference a non-dereferenceable list::iterator");
361#endif
356 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
357 "Attempted to dereference a non-dereferenceable list::iterator");
362358 return __ptr_->__as_node()->__value_;
363359 }
364360 _LIBCPP_INLINE_VISIBILITY
365361 pointer operator->() const
366362 {
367#if _LIBCPP_DEBUG_LEVEL == 2
368 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
369 "Attempted to dereference a non-dereferenceable list::iterator");
370#endif
363 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
364 "Attempted to dereference a non-dereferenceable list::iterator");
371365 return pointer_traits<pointer>::pointer_to(__ptr_->__as_node()->__value_);
372366 }
373367
374368 _LIBCPP_INLINE_VISIBILITY
375369 __list_iterator& operator++()
376370 {
377#if _LIBCPP_DEBUG_LEVEL == 2
378 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
379 "Attempted to increment a non-incrementable list::iterator");
380#endif
371 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
372 "Attempted to increment a non-incrementable list::iterator");
381373 __ptr_ = __ptr_->__next_;
382374 return *this;
383375 }
......@@ -387,10 +379,8 @@ public:
387379 _LIBCPP_INLINE_VISIBILITY
388380 __list_iterator& operator--()
389381 {
390#if _LIBCPP_DEBUG_LEVEL == 2
391 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
392 "Attempted to decrement a non-decrementable list::iterator");
393#endif
382 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__decrementable(this),
383 "Attempted to decrement a non-decrementable list::iterator");
394384 __ptr_ = __ptr_->__prev_;
395385 return *this;
396386 }
......@@ -439,16 +429,14 @@ public:
439429 _LIBCPP_INLINE_VISIBILITY
440430 __list_const_iterator() _NOEXCEPT : __ptr_(nullptr)
441431 {
442#if _LIBCPP_DEBUG_LEVEL == 2
443 __get_db()->__insert_i(this);
444#endif
432 _VSTD::__debug_db_insert_i(this);
445433 }
446434 _LIBCPP_INLINE_VISIBILITY
447435 __list_const_iterator(const __list_iterator<_Tp, _VoidPtr>& __p) _NOEXCEPT
448436 : __ptr_(__p.__ptr_)
449437 {
450438#if _LIBCPP_DEBUG_LEVEL == 2
451 __get_db()->__iterator_copy(this, &__p);
439 __get_db()->__iterator_copy(this, _VSTD::addressof(__p));
452440#endif
453441 }
454442
......@@ -458,7 +446,7 @@ public:
458446 __list_const_iterator(const __list_const_iterator& __p)
459447 : __ptr_(__p.__ptr_)
460448 {
461 __get_db()->__iterator_copy(this, &__p);
449 __get_db()->__iterator_copy(this, _VSTD::addressof(__p));
462450 }
463451
464452 _LIBCPP_INLINE_VISIBILITY
......@@ -470,9 +458,9 @@ public:
470458 _LIBCPP_INLINE_VISIBILITY
471459 __list_const_iterator& operator=(const __list_const_iterator& __p)
472460 {
473 if (this != &__p)
461 if (this != _VSTD::addressof(__p))
474462 {
475 __get_db()->__iterator_copy(this, &__p);
463 __get_db()->__iterator_copy(this, _VSTD::addressof(__p));
476464 __ptr_ = __p.__ptr_;
477465 }
478466 return *this;
......@@ -482,29 +470,23 @@ public:
482470 _LIBCPP_INLINE_VISIBILITY
483471 reference operator*() const
484472 {
485#if _LIBCPP_DEBUG_LEVEL == 2
486 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
487 "Attempted to dereference a non-dereferenceable list::const_iterator");
488#endif
473 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
474 "Attempted to dereference a non-dereferenceable list::const_iterator");
489475 return __ptr_->__as_node()->__value_;
490476 }
491477 _LIBCPP_INLINE_VISIBILITY
492478 pointer operator->() const
493479 {
494#if _LIBCPP_DEBUG_LEVEL == 2
495 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
496 "Attempted to dereference a non-dereferenceable list::const_iterator");
497#endif
480 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
481 "Attempted to dereference a non-dereferenceable list::const_iterator");
498482 return pointer_traits<pointer>::pointer_to(__ptr_->__as_node()->__value_);
499483 }
500484
501485 _LIBCPP_INLINE_VISIBILITY
502486 __list_const_iterator& operator++()
503487 {
504#if _LIBCPP_DEBUG_LEVEL == 2
505 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
506 "Attempted to increment a non-incrementable list::const_iterator");
507#endif
488 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
489 "Attempted to increment a non-incrementable list::const_iterator");
508490 __ptr_ = __ptr_->__next_;
509491 return *this;
510492 }
......@@ -514,10 +496,8 @@ public:
514496 _LIBCPP_INLINE_VISIBILITY
515497 __list_const_iterator& operator--()
516498 {
517#if _LIBCPP_DEBUG_LEVEL == 2
518 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
519 "Attempted to decrement a non-decrementable list::const_iterator");
520#endif
499 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__decrementable(this),
500 "Attempted to decrement a non-decrementable list::const_iterator");
521501 __ptr_ = __ptr_->__prev_;
522502 return *this;
523503 }
......@@ -797,7 +777,7 @@ __list_imp<_Tp, _Alloc>::swap(__list_imp& __c)
797777#if _LIBCPP_DEBUG_LEVEL == 2
798778 __libcpp_db* __db = __get_db();
799779 __c_node* __cn1 = __db->__find_c_and_lock(this);
800 __c_node* __cn2 = __db->__find_c(&__c);
780 __c_node* __cn2 = __db->__find_c(_VSTD::addressof(__c));
801781 _VSTD::swap(__cn1->beg_, __cn2->beg_);
802782 _VSTD::swap(__cn1->end_, __cn2->end_);
803783 _VSTD::swap(__cn1->cap_, __cn2->cap_);
......@@ -845,47 +825,50 @@ class _LIBCPP_TEMPLATE_VIS list
845825 typedef typename base::__link_pointer __link_pointer;
846826
847827public:
848 typedef _Tp value_type;
849 typedef _Alloc allocator_type;
828 typedef _Tp value_type;
829 typedef _Alloc allocator_type;
850830 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
851831 "Invalid allocator::value_type");
852 typedef value_type& reference;
853 typedef const value_type& const_reference;
854 typedef typename base::pointer pointer;
855 typedef typename base::const_pointer const_pointer;
856 typedef typename base::size_type size_type;
857 typedef typename base::difference_type difference_type;
858 typedef typename base::iterator iterator;
859 typedef typename base::const_iterator const_iterator;
860 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
861 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
832 typedef value_type& reference;
833 typedef const value_type& const_reference;
834 typedef typename base::pointer pointer;
835 typedef typename base::const_pointer const_pointer;
836 typedef typename base::size_type size_type;
837 typedef typename base::difference_type difference_type;
838 typedef typename base::iterator iterator;
839 typedef typename base::const_iterator const_iterator;
840 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
841 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
862842#if _LIBCPP_STD_VER > 17
863 typedef size_type __remove_return_type;
843 typedef size_type __remove_return_type;
864844#else
865 typedef void __remove_return_type;
845 typedef void __remove_return_type;
866846#endif
867847
868848 _LIBCPP_INLINE_VISIBILITY
869849 list()
870850 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
871851 {
872#if _LIBCPP_DEBUG_LEVEL == 2
873 __get_db()->__insert_c(this);
874#endif
852 _VSTD::__debug_db_insert_c(this);
875853 }
876854 _LIBCPP_INLINE_VISIBILITY
877855 explicit list(const allocator_type& __a) : base(__a)
878856 {
879#if _LIBCPP_DEBUG_LEVEL == 2
880 __get_db()->__insert_c(this);
881#endif
857 _VSTD::__debug_db_insert_c(this);
882858 }
883859 explicit list(size_type __n);
884860#if _LIBCPP_STD_VER > 11
885861 explicit list(size_type __n, const allocator_type& __a);
886862#endif
887863 list(size_type __n, const value_type& __x);
888 list(size_type __n, const value_type& __x, const allocator_type& __a);
864 template <class = __enable_if_t<__is_allocator<_Alloc>::value> >
865 list(size_type __n, const value_type& __x, const allocator_type& __a) : base(__a)
866 {
867 _VSTD::__debug_db_insert_c(this);
868 for (; __n > 0; --__n)
869 push_back(__x);
870 }
871
889872 template <class _InpIter>
890873 list(_InpIter __f, _InpIter __l,
891874 typename enable_if<__is_cpp17_input_iterator<_InpIter>::value>::type* = 0);
......@@ -1141,17 +1124,19 @@ private:
11411124 void __move_assign(list& __c, false_type);
11421125};
11431126
1144#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
1127#if _LIBCPP_STD_VER >= 17
11451128template<class _InputIterator,
11461129 class _Alloc = allocator<__iter_value_type<_InputIterator>>,
1147 class = _EnableIf<__is_allocator<_Alloc>::value>
1130 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
1131 class = enable_if_t<__is_allocator<_Alloc>::value>
11481132 >
11491133list(_InputIterator, _InputIterator)
11501134 -> list<__iter_value_type<_InputIterator>, _Alloc>;
11511135
11521136template<class _InputIterator,
11531137 class _Alloc,
1154 class = _EnableIf<__is_allocator<_Alloc>::value>
1138 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
1139 class = enable_if_t<__is_allocator<_Alloc>::value>
11551140 >
11561141list(_InputIterator, _InputIterator, _Alloc)
11571142 -> list<__iter_value_type<_InputIterator>, _Alloc>;
......@@ -1206,9 +1191,7 @@ list<_Tp, _Alloc>::__iterator(size_type __n)
12061191template <class _Tp, class _Alloc>
12071192list<_Tp, _Alloc>::list(size_type __n)
12081193{
1209#if _LIBCPP_DEBUG_LEVEL == 2
1210 __get_db()->__insert_c(this);
1211#endif
1194 _VSTD::__debug_db_insert_c(this);
12121195 for (; __n > 0; --__n)
12131196#ifndef _LIBCPP_CXX03_LANG
12141197 emplace_back();
......@@ -1221,9 +1204,7 @@ list<_Tp, _Alloc>::list(size_type __n)
12211204template <class _Tp, class _Alloc>
12221205list<_Tp, _Alloc>::list(size_type __n, const allocator_type& __a) : base(__a)
12231206{
1224#if _LIBCPP_DEBUG_LEVEL == 2
1225 __get_db()->__insert_c(this);
1226#endif
1207 _VSTD::__debug_db_insert_c(this);
12271208 for (; __n > 0; --__n)
12281209 emplace_back();
12291210}
......@@ -1232,20 +1213,7 @@ list<_Tp, _Alloc>::list(size_type __n, const allocator_type& __a) : base(__a)
12321213template <class _Tp, class _Alloc>
12331214list<_Tp, _Alloc>::list(size_type __n, const value_type& __x)
12341215{
1235#if _LIBCPP_DEBUG_LEVEL == 2
1236 __get_db()->__insert_c(this);
1237#endif
1238 for (; __n > 0; --__n)
1239 push_back(__x);
1240}
1241
1242template <class _Tp, class _Alloc>
1243list<_Tp, _Alloc>::list(size_type __n, const value_type& __x, const allocator_type& __a)
1244 : base(__a)
1245{
1246#if _LIBCPP_DEBUG_LEVEL == 2
1247 __get_db()->__insert_c(this);
1248#endif
1216 _VSTD::__debug_db_insert_c(this);
12491217 for (; __n > 0; --__n)
12501218 push_back(__x);
12511219}
......@@ -1255,9 +1223,7 @@ template <class _InpIter>
12551223list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l,
12561224 typename enable_if<__is_cpp17_input_iterator<_InpIter>::value>::type*)
12571225{
1258#if _LIBCPP_DEBUG_LEVEL == 2
1259 __get_db()->__insert_c(this);
1260#endif
1226 _VSTD::__debug_db_insert_c(this);
12611227 for (; __f != __l; ++__f)
12621228 __emplace_back(*__f);
12631229}
......@@ -1268,9 +1234,7 @@ list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l, const allocator_type& __a,
12681234 typename enable_if<__is_cpp17_input_iterator<_InpIter>::value>::type*)
12691235 : base(__a)
12701236{
1271#if _LIBCPP_DEBUG_LEVEL == 2
1272 __get_db()->__insert_c(this);
1273#endif
1237 _VSTD::__debug_db_insert_c(this);
12741238 for (; __f != __l; ++__f)
12751239 __emplace_back(*__f);
12761240}
......@@ -1279,9 +1243,7 @@ template <class _Tp, class _Alloc>
12791243list<_Tp, _Alloc>::list(const list& __c)
12801244 : base(__node_alloc_traits::select_on_container_copy_construction(
12811245 __c.__node_alloc())) {
1282#if _LIBCPP_DEBUG_LEVEL == 2
1283 __get_db()->__insert_c(this);
1284#endif
1246 _VSTD::__debug_db_insert_c(this);
12851247 for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i)
12861248 push_back(*__i);
12871249}
......@@ -1290,9 +1252,7 @@ template <class _Tp, class _Alloc>
12901252list<_Tp, _Alloc>::list(const list& __c, const __identity_t<allocator_type>& __a)
12911253 : base(__a)
12921254{
1293#if _LIBCPP_DEBUG_LEVEL == 2
1294 __get_db()->__insert_c(this);
1295#endif
1255 _VSTD::__debug_db_insert_c(this);
12961256 for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i)
12971257 push_back(*__i);
12981258}
......@@ -1303,9 +1263,7 @@ template <class _Tp, class _Alloc>
13031263list<_Tp, _Alloc>::list(initializer_list<value_type> __il, const allocator_type& __a)
13041264 : base(__a)
13051265{
1306#if _LIBCPP_DEBUG_LEVEL == 2
1307 __get_db()->__insert_c(this);
1308#endif
1266 _VSTD::__debug_db_insert_c(this);
13091267 for (typename initializer_list<value_type>::const_iterator __i = __il.begin(),
13101268 __e = __il.end(); __i != __e; ++__i)
13111269 push_back(*__i);
......@@ -1314,9 +1272,7 @@ list<_Tp, _Alloc>::list(initializer_list<value_type> __il, const allocator_type&
13141272template <class _Tp, class _Alloc>
13151273list<_Tp, _Alloc>::list(initializer_list<value_type> __il)
13161274{
1317#if _LIBCPP_DEBUG_LEVEL == 2
1318 __get_db()->__insert_c(this);
1319#endif
1275 _VSTD::__debug_db_insert_c(this);
13201276 for (typename initializer_list<value_type>::const_iterator __i = __il.begin(),
13211277 __e = __il.end(); __i != __e; ++__i)
13221278 push_back(*__i);
......@@ -1324,11 +1280,9 @@ list<_Tp, _Alloc>::list(initializer_list<value_type> __il)
13241280
13251281template <class _Tp, class _Alloc>
13261282inline list<_Tp, _Alloc>::list(list&& __c)
1327 _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value)
1328 : base(_VSTD::move(__c.__node_alloc())) {
1329#if _LIBCPP_DEBUG_LEVEL == 2
1330 __get_db()->__insert_c(this);
1331#endif
1283 _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value)
1284 : base(_VSTD::move(__c.__node_alloc())) {
1285 _VSTD::__debug_db_insert_c(this);
13321286 splice(end(), __c);
13331287}
13341288
......@@ -1337,9 +1291,7 @@ inline
13371291list<_Tp, _Alloc>::list(list&& __c, const __identity_t<allocator_type>& __a)
13381292 : base(__a)
13391293{
1340#if _LIBCPP_DEBUG_LEVEL == 2
1341 __get_db()->__insert_c(this);
1342#endif
1294 _VSTD::__debug_db_insert_c(this);
13431295 if (__a == __c.get_allocator())
13441296 splice(end(), __c);
13451297 else
......@@ -1392,7 +1344,7 @@ inline
13921344list<_Tp, _Alloc>&
13931345list<_Tp, _Alloc>::operator=(const list& __c)
13941346{
1395 if (this != &__c)
1347 if (this != _VSTD::addressof(__c))
13961348 {
13971349 base::__copy_assign_alloc(__c);
13981350 assign(__c.begin(), __c.end());
......@@ -1408,7 +1360,7 @@ list<_Tp, _Alloc>::assign(_InpIter __f, _InpIter __l,
14081360{
14091361 iterator __i = begin();
14101362 iterator __e = end();
1411 for (; __f != __l && __i != __e; ++__f, ++__i)
1363 for (; __f != __l && __i != __e; ++__f, (void) ++__i)
14121364 *__i = *__f;
14131365 if (__i == __e)
14141366 insert(__e, __f, __l);
......@@ -1425,7 +1377,7 @@ list<_Tp, _Alloc>::assign(size_type __n, const value_type& __x)
14251377{
14261378 iterator __i = begin();
14271379 iterator __e = end();
1428 for (; __n > 0 && __i != __e; --__n, ++__i)
1380 for (; __n > 0 && __i != __e; --__n, (void) ++__i)
14291381 *__i = __x;
14301382 if (__i == __e)
14311383 insert(__e, __n, __x);
......@@ -1448,11 +1400,8 @@ template <class _Tp, class _Alloc>
14481400typename list<_Tp, _Alloc>::iterator
14491401list<_Tp, _Alloc>::insert(const_iterator __p, const value_type& __x)
14501402{
1451#if _LIBCPP_DEBUG_LEVEL == 2
1452 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1453 "list::insert(iterator, x) called with an iterator not"
1454 " referring to this list");
1455#endif
1403 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
1404 "list::insert(iterator, x) called with an iterator not referring to this list");
14561405 __node_allocator& __na = base::__node_alloc();
14571406 __hold_pointer __hold = __allocate_node(__na);
14581407 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
......@@ -1469,10 +1418,9 @@ template <class _Tp, class _Alloc>
14691418typename list<_Tp, _Alloc>::iterator
14701419list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& __x)
14711420{
1421 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
1422 "list::insert(iterator, n, x) called with an iterator not referring to this list");
14721423#if _LIBCPP_DEBUG_LEVEL == 2
1473 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1474 "list::insert(iterator, n, x) called with an iterator not"
1475 " referring to this list");
14761424 iterator __r(__p.__ptr_, this);
14771425#else
14781426 iterator __r(__p.__ptr_);
......@@ -1495,7 +1443,7 @@ list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& _
14951443 try
14961444 {
14971445#endif // _LIBCPP_NO_EXCEPTIONS
1498 for (--__n; __n != 0; --__n, ++__e, ++__ds)
1446 for (--__n; __n != 0; --__n, (void) ++__e, ++__ds)
14991447 {
15001448 __hold.reset(__node_alloc_traits::allocate(__na, 1));
15011449 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
......@@ -1535,10 +1483,9 @@ typename list<_Tp, _Alloc>::iterator
15351483list<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l,
15361484 typename enable_if<__is_cpp17_input_iterator<_InpIter>::value>::type*)
15371485{
1486 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
1487 "list::insert(iterator, range) called with an iterator not referring to this list");
15381488#if _LIBCPP_DEBUG_LEVEL == 2
1539 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1540 "list::insert(iterator, range) called with an iterator not"
1541 " referring to this list");
15421489 iterator __r(__p.__ptr_, this);
15431490#else
15441491 iterator __r(__p.__ptr_);
......@@ -1561,7 +1508,7 @@ list<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l,
15611508 try
15621509 {
15631510#endif // _LIBCPP_NO_EXCEPTIONS
1564 for (++__f; __f != __l; ++__f, (void) ++__e, (void) ++__ds)
1511 for (++__f; __f != __l; ++__f, (void) ++__e, ++__ds)
15651512 {
15661513 __hold.reset(__node_alloc_traits::allocate(__na, 1));
15671514 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f);
......@@ -1694,11 +1641,8 @@ template <class... _Args>
16941641typename list<_Tp, _Alloc>::iterator
16951642list<_Tp, _Alloc>::emplace(const_iterator __p, _Args&&... __args)
16961643{
1697#if _LIBCPP_DEBUG_LEVEL == 2
1698 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1699 "list::emplace(iterator, args...) called with an iterator not"
1700 " referring to this list");
1701#endif
1644 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
1645 "list::emplace(iterator, args...) called with an iterator not referring to this list");
17021646 __node_allocator& __na = base::__node_alloc();
17031647 __hold_pointer __hold = __allocate_node(__na);
17041648 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
......@@ -1717,11 +1661,8 @@ template <class _Tp, class _Alloc>
17171661typename list<_Tp, _Alloc>::iterator
17181662list<_Tp, _Alloc>::insert(const_iterator __p, value_type&& __x)
17191663{
1720#if _LIBCPP_DEBUG_LEVEL == 2
1721 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1722 "list::insert(iterator, x) called with an iterator not"
1723 " referring to this list");
1724#endif
1664 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
1665 "list::insert(iterator, x) called with an iterator not referring to this list");
17251666 __node_allocator& __na = base::__node_alloc();
17261667 __hold_pointer __hold = __allocate_node(__na);
17271668 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
......@@ -1800,11 +1741,8 @@ template <class _Tp, class _Alloc>
18001741typename list<_Tp, _Alloc>::iterator
18011742list<_Tp, _Alloc>::erase(const_iterator __p)
18021743{
1803#if _LIBCPP_DEBUG_LEVEL == 2
1804 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1805 "list::erase(iterator) called with an iterator not"
1806 " referring to this list");
1807#endif
1744 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
1745 "list::erase(iterator) called with an iterator not referring to this list");
18081746 _LIBCPP_ASSERT(__p != end(),
18091747 "list::erase(iterator) called with a non-dereferenceable iterator");
18101748 __node_allocator& __na = base::__node_alloc();
......@@ -1841,14 +1779,10 @@ template <class _Tp, class _Alloc>
18411779typename list<_Tp, _Alloc>::iterator
18421780list<_Tp, _Alloc>::erase(const_iterator __f, const_iterator __l)
18431781{
1844#if _LIBCPP_DEBUG_LEVEL == 2
1845 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == this,
1846 "list::erase(iterator, iterator) called with an iterator not"
1847 " referring to this list");
1848 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__l) == this,
1849 "list::erase(iterator, iterator) called with an iterator not"
1850 " referring to this list");
1851#endif
1782 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__f)) == this,
1783 "list::erase(iterator, iterator) called with an iterator not referring to this list");
1784 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__l)) == this,
1785 "list::erase(iterator, iterator) called with an iterator not referring to this list");
18521786 if (__f != __l)
18531787 {
18541788 __node_allocator& __na = base::__node_alloc();
......@@ -1909,7 +1843,7 @@ list<_Tp, _Alloc>::resize(size_type __n)
19091843 try
19101844 {
19111845#endif // _LIBCPP_NO_EXCEPTIONS
1912 for (--__n; __n != 0; --__n, ++__e, ++__ds)
1846 for (--__n; __n != 0; --__n, (void) ++__e, ++__ds)
19131847 {
19141848 __hold.reset(__node_alloc_traits::allocate(__na, 1));
19151849 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_));
......@@ -1967,7 +1901,7 @@ list<_Tp, _Alloc>::resize(size_type __n, const value_type& __x)
19671901 try
19681902 {
19691903#endif // _LIBCPP_NO_EXCEPTIONS
1970 for (--__n; __n != 0; --__n, ++__e, ++__ds)
1904 for (--__n; __n != 0; --__n, (void) ++__e, ++__ds)
19711905 {
19721906 __hold.reset(__node_alloc_traits::allocate(__na, 1));
19731907 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
......@@ -2004,13 +1938,10 @@ template <class _Tp, class _Alloc>
20041938void
20051939list<_Tp, _Alloc>::splice(const_iterator __p, list& __c)
20061940{
2007 _LIBCPP_ASSERT(this != &__c,
1941 _LIBCPP_ASSERT(this != _VSTD::addressof(__c),
20081942 "list::splice(iterator, list) called with this == &list");
2009#if _LIBCPP_DEBUG_LEVEL == 2
2010 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
2011 "list::splice(iterator, list) called with an iterator not"
2012 " referring to this list");
2013#endif
1943 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
1944 "list::splice(iterator, list) called with an iterator not referring to this list");
20141945 if (!__c.empty())
20151946 {
20161947 __link_pointer __f = __c.__end_.__next_;
......@@ -2020,10 +1951,10 @@ list<_Tp, _Alloc>::splice(const_iterator __p, list& __c)
20201951 base::__sz() += __c.__sz();
20211952 __c.__sz() = 0;
20221953#if _LIBCPP_DEBUG_LEVEL == 2
2023 if (&__c != this) {
1954 if (_VSTD::addressof(__c) != this) {
20241955 __libcpp_db* __db = __get_db();
20251956 __c_node* __cn1 = __db->__find_c_and_lock(this);
2026 __c_node* __cn2 = __db->__find_c(&__c);
1957 __c_node* __cn2 = __db->__find_c(_VSTD::addressof(__c));
20271958 for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;)
20281959 {
20291960 --__ip;
......@@ -2046,17 +1977,13 @@ template <class _Tp, class _Alloc>
20461977void
20471978list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i)
20481979{
2049#if _LIBCPP_DEBUG_LEVEL == 2
2050 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
2051 "list::splice(iterator, list, iterator) called with the first iterator"
2052 " not referring to this list");
2053 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__i) == &__c,
2054 "list::splice(iterator, list, iterator) called with the second iterator"
2055 " not referring to the list argument");
2056 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(&__i),
2057 "list::splice(iterator, list, iterator) called with the second iterator"
2058 " not dereferenceable");
2059#endif
1980 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
1981 "list::splice(iterator, list, iterator) called with the first iterator not referring to this list");
1982 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__i)) == _VSTD::addressof(__c),
1983 "list::splice(iterator, list, iterator) called with the second iterator not referring to the list argument");
1984 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(_VSTD::addressof(__i)),
1985 "list::splice(iterator, list, iterator) called with the second iterator not dereferenceable");
1986
20601987 if (__p.__ptr_ != __i.__ptr_ && __p.__ptr_ != __i.__ptr_->__next_)
20611988 {
20621989 __link_pointer __f = __i.__ptr_;
......@@ -2065,10 +1992,10 @@ list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i)
20651992 --__c.__sz();
20661993 ++base::__sz();
20671994#if _LIBCPP_DEBUG_LEVEL == 2
2068 if (&__c != this) {
1995 if (_VSTD::addressof(__c) != this) {
20691996 __libcpp_db* __db = __get_db();
20701997 __c_node* __cn1 = __db->__find_c_and_lock(this);
2071 __c_node* __cn2 = __db->__find_c(&__c);
1998 __c_node* __cn2 = __db->__find_c(_VSTD::addressof(__c));
20721999 for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;)
20732000 {
20742001 --__ip;
......@@ -2091,23 +2018,20 @@ template <class _Tp, class _Alloc>
20912018void
20922019list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l)
20932020{
2021 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
2022 "list::splice(iterator, list, iterator, iterator) called with first iterator not referring to this list");
2023 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__f)) == _VSTD::addressof(__c),
2024 "list::splice(iterator, list, iterator, iterator) called with second iterator not referring to the list argument");
2025 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__l)) == _VSTD::addressof(__c),
2026 "list::splice(iterator, list, iterator, iterator) called with third iterator not referring to the list argument");
2027
20942028#if _LIBCPP_DEBUG_LEVEL == 2
2095 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
2096 "list::splice(iterator, list, iterator, iterator) called with first iterator not"
2097 " referring to this list");
2098 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == &__c,
2099 "list::splice(iterator, list, iterator, iterator) called with second iterator not"
2100 " referring to the list argument");
2101 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__l) == &__c,
2102 "list::splice(iterator, list, iterator, iterator) called with third iterator not"
2103 " referring to the list argument");
2104 if (this == &__c)
2029 if (this == _VSTD::addressof(__c))
21052030 {
21062031 for (const_iterator __i = __f; __i != __l; ++__i)
2107 _LIBCPP_ASSERT(__i != __p,
2108 "list::splice(iterator, list, iterator, iterator)"
2109 " called with the first iterator within the range"
2110 " of the second and third iterators");
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");
21112035 }
21122036#endif
21132037 if (__f != __l)
......@@ -2115,7 +2039,7 @@ list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, con
21152039 __link_pointer __first = __f.__ptr_;
21162040 --__l;
21172041 __link_pointer __last = __l.__ptr_;
2118 if (this != &__c)
2042 if (this != _VSTD::addressof(__c))
21192043 {
21202044 size_type __s = _VSTD::distance(__f, __l) + 1;
21212045 __c.__sz() -= __s;
......@@ -2124,10 +2048,10 @@ list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, con
21242048 base::__unlink_nodes(__first, __last);
21252049 __link_nodes(__p.__ptr_, __first, __last);
21262050#if _LIBCPP_DEBUG_LEVEL == 2
2127 if (&__c != this) {
2051 if (_VSTD::addressof(__c) != this) {
21282052 __libcpp_db* __db = __get_db();
21292053 __c_node* __cn1 = __db->__find_c_and_lock(this);
2130 __c_node* __cn2 = __db->__find_c(&__c);
2054 __c_node* __cn2 = __db->__find_c(_VSTD::addressof(__c));
21312055 for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;)
21322056 {
21332057 --__ip;
......@@ -2244,7 +2168,7 @@ list<_Tp, _Alloc>::merge(list& __c, _Comp __comp)
22442168 {
22452169 size_type __ds = 1;
22462170 iterator __m2 = _VSTD::next(__f2);
2247 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2, ++__ds)
2171 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2, (void) ++__ds)
22482172 ;
22492173 base::__sz() += __ds;
22502174 __c.__sz() -= __ds;
......@@ -2263,7 +2187,7 @@ list<_Tp, _Alloc>::merge(list& __c, _Comp __comp)
22632187#if _LIBCPP_DEBUG_LEVEL == 2
22642188 __libcpp_db* __db = __get_db();
22652189 __c_node* __cn1 = __db->__find_c_and_lock(this);
2266 __c_node* __cn2 = __db->__find_c(&__c);
2190 __c_node* __cn2 = __db->__find_c(_VSTD::addressof(__c));
22672191 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
22682192 {
22692193 --__p;
lib/libcxx/include/locale+124-172
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===-------------------------- locale ------------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -228,9 +228,9 @@ _LIBCPP_PUSH_MACROS
228228
229229_LIBCPP_BEGIN_NAMESPACE_STD
230230
231#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__)
231#if defined(__APPLE__) || defined(__FreeBSD__)
232232# define _LIBCPP_GET_C_LOCALE 0
233#elif defined(__CloudABI__) || defined(__NetBSD__)
233#elif defined(__NetBSD__)
234234# define _LIBCPP_GET_C_LOCALE LC_C_LOCALE
235235#else
236236# define _LIBCPP_GET_C_LOCALE __cloc()
......@@ -416,11 +416,11 @@ struct __num_get
416416 unsigned& __dc, _CharT __thousands_sep, const string& __grouping,
417417 unsigned* __g, unsigned*& __g_end, const _CharT* __atoms);
418418private:
419 template<typename T>
420 const T* __do_widen_p(ios_base& __iob, T* __atoms) const
419 template<typename _Tp>
420 const _Tp* __do_widen_p(ios_base& __iob, _Tp* __atoms) const
421421 {
422422 locale __loc = __iob.getloc();
423 use_facet<ctype<T> >(__loc).widen(__src, __src + 26, __atoms);
423 use_facet<ctype<_Tp> >(__loc).widen(__src, __src + 26, __atoms);
424424 return __atoms;
425425 }
426426
......@@ -573,7 +573,9 @@ __num_get<_CharT>::__stage2_float_loop(_CharT __ct, bool& __in_units, char& __ex
573573}
574574
575575_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_get<char>)
576#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
576577_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_get<wchar_t>)
578#endif
577579
578580template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
579581class _LIBCPP_TEMPLATE_VIS num_get
......@@ -1111,7 +1113,9 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
11111113}
11121114
11131115_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_get<char>)
1116#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
11141117_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_get<wchar_t>)
1118#endif
11151119
11161120struct _LIBCPP_TYPE_VIS __num_put_base
11171121{
......@@ -1261,7 +1265,9 @@ __num_put<_CharT>::__widen_and_group_float(char* __nb, char* __np, char* __ne,
12611265}
12621266
12631267_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_put<char>)
1268#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
12641269_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_put<wchar_t>)
1270#endif
12651271
12661272template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
12671273class _LIBCPP_TEMPLATE_VIS num_put
......@@ -1354,6 +1360,18 @@ protected:
13541360 long double __v) const;
13551361 virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl,
13561362 const void* __v) const;
1363
1364 template <class _Integral>
1365 _LIBCPP_HIDE_FROM_ABI inline
1366 _OutputIterator __do_put_integral(iter_type __s, ios_base& __iob,
1367 char_type __fl, _Integral __v,
1368 char const* __len) const;
1369
1370 template <class _Float>
1371 _LIBCPP_HIDE_FROM_ABI inline
1372 _OutputIterator __do_put_floating_point(iter_type __s, ios_base& __iob,
1373 char_type __fl, _Float __v,
1374 char const* __len) const;
13571375};
13581376
13591377template <class _CharT, class _OutputIterator>
......@@ -1450,22 +1468,28 @@ num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
14501468}
14511469
14521470template <class _CharT, class _OutputIterator>
1471template <class _Integral>
1472_LIBCPP_HIDE_FROM_ABI inline
14531473_OutputIterator
1454num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
1455 char_type __fl, long __v) const
1474num_put<_CharT, _OutputIterator>::__do_put_integral(iter_type __s, ios_base& __iob,
1475 char_type __fl, _Integral __v,
1476 char const* __len) const
14561477{
14571478 // Stage 1 - Get number in narrow char
1458 char __fmt[6] = {'%', 0};
1459 const char* __len = "l";
1460 this->__format_int(__fmt+1, __len, true, __iob.flags());
1479 char __fmt[8] = {'%', 0};
1480 this->__format_int(__fmt+1, __len, is_signed<_Integral>::value, __iob.flags());
14611481 // Worst case is octal, with showbase enabled. Note that octal is always
14621482 // printed as an unsigned value.
1483 using _Unsigned = typename make_unsigned<_Integral>::type;
14631484 _LIBCPP_CONSTEXPR const unsigned __nbuf
1464 = (numeric_limits<unsigned long>::digits / 3) // 1 char per 3 bits
1465 + ((numeric_limits<unsigned long>::digits % 3) != 0) // round up
1485 = (numeric_limits<_Unsigned>::digits / 3) // 1 char per 3 bits
1486 + ((numeric_limits<_Unsigned>::digits % 3) != 0) // round up
14661487 + 2; // base prefix + terminating null character
14671488 char __nar[__nbuf];
1489#pragma clang diagnostic push
1490#pragma clang diagnostic ignored "-Wformat-nonliteral"
14681491 int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
1492#pragma clang diagnostic pop
14691493 char* __ne = __nar + __nc;
14701494 char* __np = this->__identify_padding(__nar, __ne, __iob);
14711495 // Stage 2 - Widen __nar while adding thousands separators
......@@ -1478,33 +1502,20 @@ num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
14781502 return __pad_and_output(__s, __o, __op, __oe, __iob, __fl);
14791503}
14801504
1505template <class _CharT, class _OutputIterator>
1506_OutputIterator
1507num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
1508 char_type __fl, long __v) const
1509{
1510 return this->__do_put_integral(__s, __iob, __fl, __v, "l");
1511}
1512
14811513template <class _CharT, class _OutputIterator>
14821514_OutputIterator
14831515num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
14841516 char_type __fl, long long __v) const
14851517{
1486 // Stage 1 - Get number in narrow char
1487 char __fmt[8] = {'%', 0};
1488 const char* __len = "ll";
1489 this->__format_int(__fmt+1, __len, true, __iob.flags());
1490 // Worst case is octal, with showbase enabled. Note that octal is always
1491 // printed as an unsigned value.
1492 _LIBCPP_CONSTEXPR const unsigned __nbuf
1493 = (numeric_limits<unsigned long long>::digits / 3) // 1 char per 3 bits
1494 + ((numeric_limits<unsigned long long>::digits % 3) != 0) // round up
1495 + 2; // base prefix + terminating null character
1496 char __nar[__nbuf];
1497 int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
1498 char* __ne = __nar + __nc;
1499 char* __np = this->__identify_padding(__nar, __ne, __iob);
1500 // Stage 2 - Widen __nar while adding thousands separators
1501 char_type __o[2*(__nbuf-1) - 1];
1502 char_type* __op; // pad here
1503 char_type* __oe; // end of output
1504 this->__widen_and_group_int(__nar, __np, __ne, __o, __op, __oe, __iob.getloc());
1505 // [__o, __oe) contains thousands_sep'd wide number
1506 // Stage 3 & 4
1507 return __pad_and_output(__s, __o, __op, __oe, __iob, __fl);
1518 return this->__do_put_integral(__s, __iob, __fl, __v, "ll");
15081519}
15091520
15101521template <class _CharT, class _OutputIterator>
......@@ -1512,27 +1523,7 @@ _OutputIterator
15121523num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
15131524 char_type __fl, unsigned long __v) const
15141525{
1515 // Stage 1 - Get number in narrow char
1516 char __fmt[6] = {'%', 0};
1517 const char* __len = "l";
1518 this->__format_int(__fmt+1, __len, false, __iob.flags());
1519 // Worst case is octal, with showbase enabled.
1520 _LIBCPP_CONSTEXPR const unsigned __nbuf
1521 = (numeric_limits<unsigned long>::digits / 3) // 1 char per 3 bits
1522 + ((numeric_limits<unsigned long>::digits % 3) != 0) // round up
1523 + 2; // base prefix + terminating null character
1524 char __nar[__nbuf];
1525 int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
1526 char* __ne = __nar + __nc;
1527 char* __np = this->__identify_padding(__nar, __ne, __iob);
1528 // Stage 2 - Widen __nar while adding thousands separators
1529 char_type __o[2*(__nbuf-1) - 1];
1530 char_type* __op; // pad here
1531 char_type* __oe; // end of output
1532 this->__widen_and_group_int(__nar, __np, __ne, __o, __op, __oe, __iob.getloc());
1533 // [__o, __oe) contains thousands_sep'd wide number
1534 // Stage 3 & 4
1535 return __pad_and_output(__s, __o, __op, __oe, __iob, __fl);
1526 return this->__do_put_integral(__s, __iob, __fl, __v, "l");
15361527}
15371528
15381529template <class _CharT, class _OutputIterator>
......@@ -1540,42 +1531,26 @@ _OutputIterator
15401531num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
15411532 char_type __fl, unsigned long long __v) const
15421533{
1543 // Stage 1 - Get number in narrow char
1544 char __fmt[8] = {'%', 0};
1545 const char* __len = "ll";
1546 this->__format_int(__fmt+1, __len, false, __iob.flags());
1547 // Worst case is octal, with showbase enabled.
1548 _LIBCPP_CONSTEXPR const unsigned __nbuf
1549 = (numeric_limits<unsigned long long>::digits / 3) // 1 char per 3 bits
1550 + ((numeric_limits<unsigned long long>::digits % 3) != 0) // round up
1551 + 2; // base prefix + terminating null character
1552 char __nar[__nbuf];
1553 int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
1554 char* __ne = __nar + __nc;
1555 char* __np = this->__identify_padding(__nar, __ne, __iob);
1556 // Stage 2 - Widen __nar while adding thousands separators
1557 char_type __o[2*(__nbuf-1) - 1];
1558 char_type* __op; // pad here
1559 char_type* __oe; // end of output
1560 this->__widen_and_group_int(__nar, __np, __ne, __o, __op, __oe, __iob.getloc());
1561 // [__o, __oe) contains thousands_sep'd wide number
1562 // Stage 3 & 4
1563 return __pad_and_output(__s, __o, __op, __oe, __iob, __fl);
1534 return this->__do_put_integral(__s, __iob, __fl, __v, "ll");
15641535}
15651536
15661537template <class _CharT, class _OutputIterator>
1538template <class _Float>
1539_LIBCPP_HIDE_FROM_ABI inline
15671540_OutputIterator
1568num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
1569 char_type __fl, double __v) const
1541num_put<_CharT, _OutputIterator>::__do_put_floating_point(iter_type __s, ios_base& __iob,
1542 char_type __fl, _Float __v,
1543 char const* __len) const
15701544{
15711545 // Stage 1 - Get number in narrow char
15721546 char __fmt[8] = {'%', 0};
1573 const char* __len = "";
15741547 bool __specify_precision = this->__format_float(__fmt+1, __len, __iob.flags());
15751548 const unsigned __nbuf = 30;
15761549 char __nar[__nbuf];
15771550 char* __nb = __nar;
15781551 int __nc;
1552#pragma clang diagnostic push
1553#pragma clang diagnostic ignored "-Wformat-nonliteral"
15791554 if (__specify_precision)
15801555 __nc = __libcpp_snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt,
15811556 (int)__iob.precision(), __v);
......@@ -1592,6 +1567,7 @@ num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
15921567 __throw_bad_alloc();
15931568 __nbh.reset(__nb);
15941569 }
1570#pragma clang diagnostic pop
15951571 char* __ne = __nb + __nc;
15961572 char* __np = this->__identify_padding(__nb, __ne, __iob);
15971573 // Stage 2 - Widen __nar while adding thousands separators
......@@ -1614,55 +1590,20 @@ num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
16141590 return __s;
16151591}
16161592
1593template <class _CharT, class _OutputIterator>
1594_OutputIterator
1595num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
1596 char_type __fl, double __v) const
1597{
1598 return this->__do_put_floating_point(__s, __iob, __fl, __v, "");
1599}
1600
16171601template <class _CharT, class _OutputIterator>
16181602_OutputIterator
16191603num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
16201604 char_type __fl, long double __v) const
16211605{
1622 // Stage 1 - Get number in narrow char
1623 char __fmt[8] = {'%', 0};
1624 const char* __len = "L";
1625 bool __specify_precision = this->__format_float(__fmt+1, __len, __iob.flags());
1626 const unsigned __nbuf = 30;
1627 char __nar[__nbuf];
1628 char* __nb = __nar;
1629 int __nc;
1630 if (__specify_precision)
1631 __nc = __libcpp_snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt,
1632 (int)__iob.precision(), __v);
1633 else
1634 __nc = __libcpp_snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, __v);
1635 unique_ptr<char, void(*)(void*)> __nbh(nullptr, free);
1636 if (__nc > static_cast<int>(__nbuf-1))
1637 {
1638 if (__specify_precision)
1639 __nc = __libcpp_asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, (int)__iob.precision(), __v);
1640 else
1641 __nc = __libcpp_asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, __v);
1642 if (__nc == -1)
1643 __throw_bad_alloc();
1644 __nbh.reset(__nb);
1645 }
1646 char* __ne = __nb + __nc;
1647 char* __np = this->__identify_padding(__nb, __ne, __iob);
1648 // Stage 2 - Widen __nar while adding thousands separators
1649 char_type __o[2*(__nbuf-1) - 1];
1650 char_type* __ob = __o;
1651 unique_ptr<char_type, void(*)(void*)> __obh(0, free);
1652 if (__nb != __nar)
1653 {
1654 __ob = (char_type*)malloc(2*static_cast<size_t>(__nc)*sizeof(char_type));
1655 if (__ob == 0)
1656 __throw_bad_alloc();
1657 __obh.reset(__ob);
1658 }
1659 char_type* __op; // pad here
1660 char_type* __oe; // end of output
1661 this->__widen_and_group_float(__nb, __np, __ne, __ob, __op, __oe, __iob.getloc());
1662 // [__o, __oe) contains thousands_sep'd wide number
1663 // Stage 3 & 4
1664 __s = __pad_and_output(__s, __ob, __op, __oe, __iob, __fl);
1665 return __s;
1606 return this->__do_put_floating_point(__s, __iob, __fl, __v, "L");
16661607}
16671608
16681609template <class _CharT, class _OutputIterator>
......@@ -1671,10 +1612,9 @@ num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
16711612 char_type __fl, const void* __v) const
16721613{
16731614 // Stage 1 - Get pointer in narrow char
1674 char __fmt[6] = "%p";
16751615 const unsigned __nbuf = 20;
16761616 char __nar[__nbuf];
1677 int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
1617 int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, "%p", __v);
16781618 char* __ne = __nar + __nc;
16791619 char* __np = this->__identify_padding(__nar, __ne, __iob);
16801620 // Stage 2 - Widen __nar
......@@ -1694,7 +1634,9 @@ num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
16941634}
16951635
16961636_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_put<char>)
1637#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
16971638_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_put<wchar_t>)
1639#endif
16981640
16991641template <class _CharT, class _InputIterator>
17001642_LIBCPP_HIDDEN
......@@ -1761,6 +1703,7 @@ template <> _LIBCPP_FUNC_VIS const string& __time_get_c_storage<char>::__r() con
17611703template <> _LIBCPP_FUNC_VIS const string& __time_get_c_storage<char>::__x() const;
17621704template <> _LIBCPP_FUNC_VIS const string& __time_get_c_storage<char>::__X() const;
17631705
1706#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
17641707template <> _LIBCPP_FUNC_VIS const wstring* __time_get_c_storage<wchar_t>::__weeks() const;
17651708template <> _LIBCPP_FUNC_VIS const wstring* __time_get_c_storage<wchar_t>::__months() const;
17661709template <> _LIBCPP_FUNC_VIS const wstring* __time_get_c_storage<wchar_t>::__am_pm() const;
......@@ -1768,6 +1711,7 @@ template <> _LIBCPP_FUNC_VIS const wstring& __time_get_c_storage<wchar_t>::__c()
17681711template <> _LIBCPP_FUNC_VIS const wstring& __time_get_c_storage<wchar_t>::__r() const;
17691712template <> _LIBCPP_FUNC_VIS const wstring& __time_get_c_storage<wchar_t>::__x() const;
17701713template <> _LIBCPP_FUNC_VIS const wstring& __time_get_c_storage<wchar_t>::__X() const;
1714#endif
17711715
17721716template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
17731717class _LIBCPP_TEMPLATE_VIS time_get
......@@ -2380,7 +2324,9 @@ time_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
23802324}
23812325
23822326_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get<char>)
2327#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
23832328_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get<wchar_t>)
2329#endif
23842330
23852331class _LIBCPP_TYPE_VIS __time_get
23862332{
......@@ -2480,7 +2426,9 @@ private:
24802426};
24812427
24822428_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get_byname<char>)
2429#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
24832430_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get_byname<wchar_t>)
2431#endif
24842432
24852433class _LIBCPP_TYPE_VIS __time_put
24862434{
......@@ -2593,7 +2541,9 @@ time_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base&,
25932541}
25942542
25952543_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put<char>)
2544#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
25962545_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put<wchar_t>)
2546#endif
25972547
25982548template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
25992549class _LIBCPP_TEMPLATE_VIS time_put_byname
......@@ -2614,7 +2564,9 @@ protected:
26142564};
26152565
26162566_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put_byname<char>)
2567#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
26172568_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put_byname<wchar_t>)
2569#endif
26182570
26192571// money_base
26202572
......@@ -2682,8 +2634,10 @@ moneypunct<_CharT, _International>::intl;
26822634
26832635_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<char, false>)
26842636_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<char, true>)
2637#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
26852638_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<wchar_t, false>)
26862639_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<wchar_t, true>)
2640#endif
26872641
26882642// moneypunct_byname
26892643
......@@ -2734,13 +2688,15 @@ private:
27342688
27352689template<> _LIBCPP_FUNC_VIS void moneypunct_byname<char, false>::init(const char*);
27362690template<> _LIBCPP_FUNC_VIS void moneypunct_byname<char, true>::init(const char*);
2737template<> _LIBCPP_FUNC_VIS void moneypunct_byname<wchar_t, false>::init(const char*);
2738template<> _LIBCPP_FUNC_VIS void moneypunct_byname<wchar_t, true>::init(const char*);
2739
27402691_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<char, false>)
27412692_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<char, true>)
2693
2694#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
2695template<> _LIBCPP_FUNC_VIS void moneypunct_byname<wchar_t, false>::init(const char*);
2696template<> _LIBCPP_FUNC_VIS void moneypunct_byname<wchar_t, true>::init(const char*);
27422697_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<wchar_t, false>)
27432698_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<wchar_t, true>)
2699#endif
27442700
27452701// money_get
27462702
......@@ -2797,7 +2753,9 @@ __money_get<_CharT>::__gather_info(bool __intl, const locale& __loc,
27972753}
27982754
27992755_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_get<char>)
2756#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
28002757_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_get<wchar_t>)
2758#endif
28012759
28022760template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
28032761class _LIBCPP_TEMPLATE_VIS money_get
......@@ -2891,6 +2849,10 @@ money_get<_CharT, _InputIterator>::__do_get(iter_type& __b, iter_type __e,
28912849 unique_ptr<char_type, void(*)(void*)>& __wb,
28922850 char_type*& __wn, char_type* __we)
28932851{
2852 if (__b == __e) {
2853 __err |= ios_base::failbit;
2854 return false;
2855 }
28942856 const unsigned __bz = 100;
28952857 unsigned __gbuf[__bz];
28962858 unique_ptr<unsigned, void(*)(void*)> __gb(__gbuf, __do_nothing);
......@@ -2935,51 +2897,31 @@ money_get<_CharT, _InputIterator>::__do_get(iter_type& __b, iter_type __e,
29352897 }
29362898 break;
29372899 case money_base::sign:
2938 if (__psn.size() + __nsn.size() > 0)
2900 if (__psn.size() > 0 && *__b == __psn[0])
29392901 {
2940 if (__psn.size() == 0 || __nsn.size() == 0)
2941 { // sign is optional
2942 if (__psn.size() > 0)
2943 { // __nsn.size() == 0
2944 if (*__b == __psn[0])
2945 {
2946 ++__b;
2947 if (__psn.size() > 1)
2948 __trailing_sign = &__psn;
2949 }
2950 else
2951 __neg = true;
2952 }
2953 else if (*__b == __nsn[0]) // __nsn.size() > 0 && __psn.size() == 0
2954 {
2955 ++__b;
2956 __neg = true;
2957 if (__nsn.size() > 1)
2958 __trailing_sign = &__nsn;
2959 }
2960 }
2961 else // sign is required
2962 {
2963 if (*__b == __psn[0])
2964 {
2965 ++__b;
2966 if (__psn.size() > 1)
2967 __trailing_sign = &__psn;
2968 }
2969 else if (*__b == __nsn[0])
2970 {
2971 ++__b;
2972 __neg = true;
2973 if (__nsn.size() > 1)
2974 __trailing_sign = &__nsn;
2975 }
2976 else
2977 {
2978 __err |= ios_base::failbit;
2979 return false;
2980 }
2981 }
2902 ++__b;
2903 __neg = false;
2904 if (__psn.size() > 1)
2905 __trailing_sign = &__psn;
2906 break;
2907 }
2908 if (__nsn.size() > 0 && *__b == __nsn[0])
2909 {
2910 ++__b;
2911 __neg = true;
2912 if (__nsn.size() > 1)
2913 __trailing_sign = &__nsn;
2914 break;
29822915 }
2916 if (__psn.size() > 0 && __nsn.size() > 0)
2917 { // sign is required
2918 __err |= ios_base::failbit;
2919 return false;
2920 }
2921 if (__psn.size() == 0 && __nsn.size() == 0)
2922 // locale has no way of specifying a sign. Use the initial value of __neg as a default
2923 break;
2924 __neg = (__nsn.size() == 0);
29832925 break;
29842926 case money_base::symbol:
29852927 {
......@@ -3180,7 +3122,9 @@ money_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
31803122}
31813123
31823124_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_get<char>)
3125#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
31833126_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_get<wchar_t>)
3127#endif
31843128
31853129// money_put
31863130
......@@ -3355,7 +3299,9 @@ __money_put<_CharT>::__format(char_type* __mb, char_type*& __mi, char_type*& __m
33553299}
33563300
33573301_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_put<char>)
3302#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
33583303_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_put<wchar_t>)
3304#endif
33593305
33603306template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
33613307class _LIBCPP_TEMPLATE_VIS money_put
......@@ -3508,7 +3454,9 @@ money_put<_CharT, _OutputIterator>::do_put(iter_type __s, bool __intl,
35083454}
35093455
35103456_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_put<char>)
3457#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
35113458_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_put<wchar_t>)
3459#endif
35123460
35133461// messages
35143462
......@@ -3624,7 +3572,9 @@ messages<_CharT>::do_close(catalog __c) const
36243572}
36253573
36263574_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages<char>)
3575#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
36273576_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages<wchar_t>)
3577#endif
36283578
36293579template <class _CharT>
36303580class _LIBCPP_TEMPLATE_VIS messages_byname
......@@ -3648,7 +3598,9 @@ protected:
36483598};
36493599
36503600_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages_byname<char>)
3601#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
36513602_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages_byname<wchar_t>)
3603#endif
36523604
36533605template<class _Codecvt, class _Elem = wchar_t,
36543606 class _Wide_alloc = allocator<_Elem>,
lib/libcxx/include/locale.h+2-2
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===---------------------------- locale.h --------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -36,7 +36,7 @@ Functions:
3636#include <__config>
3737
3838#if defined(_LIBCPP_HAS_NO_LOCALIZATION)
39# error "Localization is not supported by this configuration of libc++"
39# error "The Localization library is not supported since libc++ has been configured with LIBCXX_ENABLE_LOCALIZATION disabled"
4040#endif
4141
4242#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
lib/libcxx/include/map+75-35
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===----------------------------- map ------------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -223,6 +223,25 @@ public:
223223 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
224224};
225225
226template <class InputIterator,
227 class Compare = less<iter_key_t<InputIterator>>,
228 class Allocator = allocator<iter_to_alloc_t<InputIterator>>>
229map(InputIterator, InputIterator, Compare = Compare(), Allocator = Allocator())
230 -> map<iter_key_t<InputIterator>, iter_val_t<InputIterator>, Compare, Allocator>; // C++17
231
232template<class Key, class T, class Compare = less<Key>,
233 class Allocator = allocator<pair<const Key, T>>>
234map(initializer_list<pair<const Key, T>>, Compare = Compare(), Allocator = Allocator())
235 -> map<Key, T, Compare, Allocator>; // C++17
236
237template <class InputIterator, class Allocator>
238map(InputIterator, InputIterator, Allocator)
239 -> map<iter_key_t<InputIterator>, iter_val_t<InputIterator>, less<iter_key_t<InputIterator>>,
240 Allocator>; // C++17
241
242template<class Key, class T, class Allocator>
243map(initializer_list<pair<const Key, T>>, Allocator) -> map<Key, T, less<Key>, Allocator>; // C++17
244
226245template <class Key, class T, class Compare, class Allocator>
227246bool
228247operator==(const map<Key, T, Compare, Allocator>& x,
......@@ -444,6 +463,26 @@ public:
444463 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
445464};
446465
466template <class InputIterator,
467 class Compare = less<iter_key_t<InputIterator>>,
468 class Allocator = allocator<iter_to_alloc_t<InputIterator>>>
469multimap(InputIterator, InputIterator, Compare = Compare(), Allocator = Allocator())
470 -> multimap<iter_key_t<InputIterator>, iter_val_t<InputIterator>, Compare, Allocator>; // C++17
471
472template<class Key, class T, class Compare = less<Key>,
473 class Allocator = allocator<pair<const Key, T>>>
474multimap(initializer_list<pair<const Key, T>>, Compare = Compare(), Allocator = Allocator())
475 -> multimap<Key, T, Compare, Allocator>; // C++17
476
477template <class InputIterator, class Allocator>
478multimap(InputIterator, InputIterator, Allocator)
479 -> multimap<iter_key_t<InputIterator>, iter_val_t<InputIterator>,
480 less<iter_key_t<InputIterator>>, Allocator>; // C++17
481
482template<class Key, class T, class Allocator>
483multimap(initializer_list<pair<const Key, T>>, Allocator)
484 -> multimap<Key, T, less<Key>, Allocator>; // C++17
485
447486template <class Key, class T, class Compare, class Allocator>
448487bool
449488operator==(const multimap<Key, T, Compare, Allocator>& x,
......@@ -492,6 +531,7 @@ erase_if(multimap<Key, T, Compare, Allocator>& c, Predicate pred); // C++20
492531#include <__config>
493532#include <__debug>
494533#include <__functional/is_transparent.h>
534#include <__iterator/iterator_traits.h>
495535#include <__node_handle>
496536#include <__tree>
497537#include <__utility/forward.h>
......@@ -535,7 +575,7 @@ public:
535575 _LIBCPP_INLINE_VISIBILITY
536576 bool operator()(const _Key& __x, const _CP& __y) const
537577 {return static_cast<const _Compare&>(*this)(__x, __y.__get_value().first);}
538 void swap(__map_value_compare&__y)
578 void swap(__map_value_compare& __y)
539579 _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value)
540580 {
541581 using _VSTD::swap;
......@@ -545,15 +585,13 @@ public:
545585#if _LIBCPP_STD_VER > 11
546586 template <typename _K2>
547587 _LIBCPP_INLINE_VISIBILITY
548 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
549 operator () ( const _K2& __x, const _CP& __y ) const
550 {return static_cast<const _Compare&>(*this) (__x, __y.__get_value().first);}
588 bool operator()(const _K2& __x, const _CP& __y) const
589 {return static_cast<const _Compare&>(*this)(__x, __y.__get_value().first);}
551590
552591 template <typename _K2>
553592 _LIBCPP_INLINE_VISIBILITY
554 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
555 operator () (const _CP& __x, const _K2& __y) const
556 {return static_cast<const _Compare&>(*this) (__x.__get_value().first, __y);}
593 bool operator()(const _CP& __x, const _K2& __y) const
594 {return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y);}
557595#endif
558596};
559597
......@@ -583,7 +621,7 @@ public:
583621 _LIBCPP_INLINE_VISIBILITY
584622 bool operator()(const _Key& __x, const _CP& __y) const
585623 {return comp(__x, __y.__get_value().first);}
586 void swap(__map_value_compare&__y)
624 void swap(__map_value_compare& __y)
587625 _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value)
588626 {
589627 using _VSTD::swap;
......@@ -593,15 +631,13 @@ public:
593631#if _LIBCPP_STD_VER > 11
594632 template <typename _K2>
595633 _LIBCPP_INLINE_VISIBILITY
596 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
597 operator () ( const _K2& __x, const _CP& __y ) const
598 {return comp (__x, __y.__get_value().first);}
634 bool operator()(const _K2& __x, const _CP& __y) const
635 {return comp(__x, __y.__get_value().first);}
599636
600637 template <typename _K2>
601638 _LIBCPP_INLINE_VISIBILITY
602 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
603 operator () (const _CP& __x, const _K2& __y) const
604 {return comp (__x.__get_value().first, __y);}
639 bool operator()(const _CP& __x, const _K2& __y) const
640 {return comp(__x.__get_value().first, __y);}
605641#endif
606642};
607643
......@@ -747,10 +783,10 @@ public:
747783 }
748784
749785private:
750 __value_type() _LIBCPP_EQUAL_DELETE;
751 ~__value_type() _LIBCPP_EQUAL_DELETE;
752 __value_type(const __value_type& __v) _LIBCPP_EQUAL_DELETE;
753 __value_type(__value_type&& __v) _LIBCPP_EQUAL_DELETE;
786 __value_type() = delete;
787 ~__value_type() = delete;
788 __value_type(const __value_type&) = delete;
789 __value_type(__value_type&&) = delete;
754790};
755791
756792#else
......@@ -1040,7 +1076,7 @@ public:
10401076#ifndef _LIBCPP_CXX03_LANG
10411077 __tree_ = __m.__tree_;
10421078#else
1043 if (this != &__m) {
1079 if (this != _VSTD::addressof(__m)) {
10441080 __tree_.clear();
10451081 __tree_.value_comp() = __m.__tree_.value_comp();
10461082 __tree_.__copy_assign_alloc(__m.__tree_);
......@@ -1502,29 +1538,31 @@ private:
15021538#endif
15031539};
15041540
1505#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
1541#if _LIBCPP_STD_VER >= 17
15061542template<class _InputIterator, class _Compare = less<__iter_key_type<_InputIterator>>,
15071543 class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>,
1508 class = _EnableIf<!__is_allocator<_Compare>::value, void>,
1509 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
1544 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, void>,
1545 class = enable_if_t<!__is_allocator<_Compare>::value, void>,
1546 class = enable_if_t<__is_allocator<_Allocator>::value, void>>
15101547map(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
15111548 -> map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Compare, _Allocator>;
15121549
15131550template<class _Key, class _Tp, class _Compare = less<remove_const_t<_Key>>,
15141551 class _Allocator = allocator<pair<const _Key, _Tp>>,
1515 class = _EnableIf<!__is_allocator<_Compare>::value, void>,
1516 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
1552 class = enable_if_t<!__is_allocator<_Compare>::value, void>,
1553 class = enable_if_t<__is_allocator<_Allocator>::value, void>>
15171554map(initializer_list<pair<_Key, _Tp>>, _Compare = _Compare(), _Allocator = _Allocator())
15181555 -> map<remove_const_t<_Key>, _Tp, _Compare, _Allocator>;
15191556
15201557template<class _InputIterator, class _Allocator,
1521 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
1558 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, void>,
1559 class = enable_if_t<__is_allocator<_Allocator>::value, void>>
15221560map(_InputIterator, _InputIterator, _Allocator)
15231561 -> map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
15241562 less<__iter_key_type<_InputIterator>>, _Allocator>;
15251563
15261564template<class _Key, class _Tp, class _Allocator,
1527 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
1565 class = enable_if_t<__is_allocator<_Allocator>::value, void>>
15281566map(initializer_list<pair<_Key, _Tp>>, _Allocator)
15291567 -> map<remove_const_t<_Key>, _Tp, less<remove_const_t<_Key>>, _Allocator>;
15301568#endif
......@@ -1824,7 +1862,7 @@ public:
18241862#ifndef _LIBCPP_CXX03_LANG
18251863 __tree_ = __m.__tree_;
18261864#else
1827 if (this != &__m) {
1865 if (this != _VSTD::addressof(__m)) {
18281866 __tree_.clear();
18291867 __tree_.value_comp() = __m.__tree_.value_comp();
18301868 __tree_.__copy_assign_alloc(__m.__tree_);
......@@ -2175,29 +2213,31 @@ private:
21752213 typedef unique_ptr<__node, _Dp> __node_holder;
21762214};
21772215
2178#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
2216#if _LIBCPP_STD_VER >= 17
21792217template<class _InputIterator, class _Compare = less<__iter_key_type<_InputIterator>>,
21802218 class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>,
2181 class = _EnableIf<!__is_allocator<_Compare>::value, void>,
2182 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
2219 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, void>,
2220 class = enable_if_t<!__is_allocator<_Compare>::value, void>,
2221 class = enable_if_t<__is_allocator<_Allocator>::value, void>>
21832222multimap(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
21842223 -> multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Compare, _Allocator>;
21852224
21862225template<class _Key, class _Tp, class _Compare = less<remove_const_t<_Key>>,
21872226 class _Allocator = allocator<pair<const _Key, _Tp>>,
2188 class = _EnableIf<!__is_allocator<_Compare>::value, void>,
2189 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
2227 class = enable_if_t<!__is_allocator<_Compare>::value, void>,
2228 class = enable_if_t<__is_allocator<_Allocator>::value, void>>
21902229multimap(initializer_list<pair<_Key, _Tp>>, _Compare = _Compare(), _Allocator = _Allocator())
21912230 -> multimap<remove_const_t<_Key>, _Tp, _Compare, _Allocator>;
21922231
21932232template<class _InputIterator, class _Allocator,
2194 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
2233 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, void>,
2234 class = enable_if_t<__is_allocator<_Allocator>::value, void>>
21952235multimap(_InputIterator, _InputIterator, _Allocator)
21962236 -> multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
21972237 less<__iter_key_type<_InputIterator>>, _Allocator>;
21982238
21992239template<class _Key, class _Tp, class _Allocator,
2200 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
2240 class = enable_if_t<__is_allocator<_Allocator>::value, void>>
22012241multimap(initializer_list<pair<_Key, _Tp>>, _Allocator)
22022242 -> multimap<remove_const_t<_Key>, _Tp, less<remove_const_t<_Key>>, _Allocator>;
22032243#endif
lib/libcxx/include/math.h+15-15
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===---------------------------- math.h ----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -305,9 +305,9 @@ long double truncl(long double x);
305305// back to C++ linkage before including these C++ headers.
306306extern "C++" {
307307
308#include <limits>
308309#include <stdlib.h>
309310#include <type_traits>
310#include <limits>
311311
312312// signbit
313313
......@@ -831,7 +831,7 @@ inline _LIBCPP_INLINE_VISIBILITY long double atan2(long double __lcpp_y, long do
831831
832832template <class _A1, class _A2>
833833inline _LIBCPP_INLINE_VISIBILITY
834typename std::_EnableIf
834typename std::__enable_if_t
835835<
836836 std::is_arithmetic<_A1>::value &&
837837 std::is_arithmetic<_A2>::value,
......@@ -926,7 +926,7 @@ inline _LIBCPP_INLINE_VISIBILITY long double fmod(long double __lcpp_x, long dou
926926
927927template <class _A1, class _A2>
928928inline _LIBCPP_INLINE_VISIBILITY
929typename std::_EnableIf
929typename std::__enable_if_t
930930<
931931 std::is_arithmetic<_A1>::value &&
932932 std::is_arithmetic<_A2>::value,
......@@ -1004,7 +1004,7 @@ inline _LIBCPP_INLINE_VISIBILITY long double pow(long double __lcpp_x, long doub
10041004
10051005template <class _A1, class _A2>
10061006inline _LIBCPP_INLINE_VISIBILITY
1007typename std::_EnableIf
1007typename std::__enable_if_t
10081008<
10091009 std::is_arithmetic<_A1>::value &&
10101010 std::is_arithmetic<_A2>::value,
......@@ -1158,7 +1158,7 @@ template <class _A1, class _A2>
11581158_LIBCPP_CONSTEXPR
11591159#endif
11601160inline _LIBCPP_INLINE_VISIBILITY
1161typename std::_EnableIf
1161typename std::__enable_if_t
11621162<
11631163 std::is_arithmetic<_A1>::value &&
11641164 std::is_arithmetic<_A2>::value,
......@@ -1185,7 +1185,7 @@ inline _LIBCPP_INLINE_VISIBILITY long double copysign(long double __lcpp_x, long
11851185
11861186template <class _A1, class _A2>
11871187inline _LIBCPP_INLINE_VISIBILITY
1188typename std::_EnableIf
1188typename std::__enable_if_t
11891189<
11901190 std::is_arithmetic<_A1>::value &&
11911191 std::is_arithmetic<_A2>::value,
......@@ -1242,7 +1242,7 @@ inline _LIBCPP_INLINE_VISIBILITY long double fdim(long double __lcpp_x, long dou
12421242
12431243template <class _A1, class _A2>
12441244inline _LIBCPP_INLINE_VISIBILITY
1245typename std::_EnableIf
1245typename std::__enable_if_t
12461246<
12471247 std::is_arithmetic<_A1>::value &&
12481248 std::is_arithmetic<_A2>::value,
......@@ -1277,7 +1277,7 @@ inline _LIBCPP_INLINE_VISIBILITY long double fma(long double __lcpp_x, long doub
12771277
12781278template <class _A1, class _A2, class _A3>
12791279inline _LIBCPP_INLINE_VISIBILITY
1280typename std::_EnableIf
1280typename std::__enable_if_t
12811281<
12821282 std::is_arithmetic<_A1>::value &&
12831283 std::is_arithmetic<_A2>::value &&
......@@ -1304,7 +1304,7 @@ inline _LIBCPP_INLINE_VISIBILITY long double fmax(long double __lcpp_x, long dou
13041304
13051305template <class _A1, class _A2>
13061306inline _LIBCPP_INLINE_VISIBILITY
1307typename std::_EnableIf
1307typename std::__enable_if_t
13081308<
13091309 std::is_arithmetic<_A1>::value &&
13101310 std::is_arithmetic<_A2>::value,
......@@ -1325,7 +1325,7 @@ inline _LIBCPP_INLINE_VISIBILITY long double fmin(long double __lcpp_x, long dou
13251325
13261326template <class _A1, class _A2>
13271327inline _LIBCPP_INLINE_VISIBILITY
1328typename std::_EnableIf
1328typename std::__enable_if_t
13291329<
13301330 std::is_arithmetic<_A1>::value &&
13311331 std::is_arithmetic<_A2>::value,
......@@ -1346,7 +1346,7 @@ inline _LIBCPP_INLINE_VISIBILITY long double hypot(long double __lcpp_x, long do
13461346
13471347template <class _A1, class _A2>
13481348inline _LIBCPP_INLINE_VISIBILITY
1349typename std::_EnableIf
1349typename std::__enable_if_t
13501350<
13511351 std::is_arithmetic<_A1>::value &&
13521352 std::is_arithmetic<_A2>::value,
......@@ -1553,7 +1553,7 @@ inline _LIBCPP_INLINE_VISIBILITY long double nextafter(long double __lcpp_x, lon
15531553
15541554template <class _A1, class _A2>
15551555inline _LIBCPP_INLINE_VISIBILITY
1556typename std::_EnableIf
1556typename std::__enable_if_t
15571557<
15581558 std::is_arithmetic<_A1>::value &&
15591559 std::is_arithmetic<_A2>::value,
......@@ -1584,7 +1584,7 @@ inline _LIBCPP_INLINE_VISIBILITY long double remainder(long double __lcpp_x, lon
15841584
15851585template <class _A1, class _A2>
15861586inline _LIBCPP_INLINE_VISIBILITY
1587typename std::_EnableIf
1587typename std::__enable_if_t
15881588<
15891589 std::is_arithmetic<_A1>::value &&
15901590 std::is_arithmetic<_A2>::value,
......@@ -1605,7 +1605,7 @@ inline _LIBCPP_INLINE_VISIBILITY long double remquo(long double __lcpp_x, long d
16051605
16061606template <class _A1, class _A2>
16071607inline _LIBCPP_INLINE_VISIBILITY
1608typename std::_EnableIf
1608typename std::__enable_if_t
16091609<
16101610 std::is_arithmetic<_A1>::value &&
16111611 std::is_arithmetic<_A2>::value,
lib/libcxx/include/memory+156-23
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===-------------------------- memory ------------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -181,47 +181,190 @@ template <class InputIterator, class ForwardIterator>
181181ForwardIterator
182182uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result);
183183
184namespace ranges {
185
186template<class InputIterator, class OutputIterator>
187using uninitialized_copy_result = in_out_result<InputIterator, OutputIterator>; // since C++20
188
189template<input_iterator InputIterator, sentinel-for<InputIterator> Sentinel1, nothrow-forward-iterator OutputIterator, nothrow-sentinel-for<OutputIterator> Sentinel2>
190 requires constructible_from<iter_value_t<OutputIterator>, iter_reference_t<InputIterator>>
191uninitialized_copy_result<InputIterator, OutputIterator>
192uninitialized_copy(InputIterator ifirst, Sentinel1 ilast, OutputIterator ofirst, Sentinel2 olast); // since C++20
193
194template<input_range InputRange, nothrow-forward-range OutputRange>
195 requires constructible_from<range_value_t<OutputRange>, range_reference_t<InputRange>>
196uninitialized_copy_result<borrowed_iterator_t<InputRange>, borrowed_iterator_t<OutputRange>>
197uninitialized_copy(InputRange&& in_range, OutputRange&& out_range); // since C++20
198
199}
200
184201template <class InputIterator, class Size, class ForwardIterator>
185202ForwardIterator
186203uninitialized_copy_n(InputIterator first, Size n, ForwardIterator result);
187204
205namespace ranges {
206
207template<class InputIterator, class OutputIterator>
208using uninitialized_copy_n_result = in_out_result<InputIterator, OutputIterator>; // since C++20
209
210template<input_iterator InputIterator, nothrow-forward-iterator OutputIterator, nothrow-sentinel-for<OutputIterator> Sentinel>
211 requires constructible_from<iter_value_t<OutputIterator>, iter_reference_t<InputIterator>>
212uninitialized_copy_n_result<InputIterator, OutputIterator>
213uninitialized_copy_n(InputIterator ifirst, iter_difference_t<InputIterator> n, OutputIterator ofirst, Sentinel olast); // since C++20
214
215}
216
188217template <class ForwardIterator, class T>
189218void uninitialized_fill(ForwardIterator first, ForwardIterator last, const T& x);
190219
220namespace ranges {
221
222template <nothrow-forward-iterator ForwardIterator, nothrow-sentinel-for<ForwardIterator> Sentinel, class T>
223 requires constructible_from<iter_value_t<ForwardIterator>, const T&>
224ForwardIterator uninitialized_fill(ForwardIterator first, Sentinel last, const T& x); // since C++20
225
226template <nothrow-forward-range ForwardRange, class T>
227 requires constructible_from<range_value_t<ForwardRange>, const T&>
228borrowed_iterator_t<ForwardRange> uninitialized_fill(ForwardRange&& range, const T& x); // since C++20
229
230}
231
191232template <class ForwardIterator, class Size, class T>
192233ForwardIterator
193234uninitialized_fill_n(ForwardIterator first, Size n, const T& x);
194235
236namespace ranges {
237
238template <nothrow-forward-iterator ForwardIterator, class T>
239 requires constructible_from<iter_value_t<ForwardIterator>, const T&>
240ForwardIterator uninitialized_fill_n(ForwardIterator first, iter_difference_t<ForwardIterator> n); // since C++20
241
242}
243
195244template <class T, class ...Args>
196245constexpr T* construct_at(T* location, Args&& ...args); // since C++20
197246
247namespace ranges {
248 template<class T, class... Args>
249 constexpr T* construct_at(T* location, Args&&... args); // since C++20
250}
251
198252template <class T>
199253void destroy_at(T* location); // constexpr in C++20
200254
255namespace ranges {
256 template<destructible T>
257 constexpr void destroy_at(T* location) noexcept; // since C++20
258}
259
201260template <class ForwardIterator>
202261void destroy(ForwardIterator first, ForwardIterator last); // constexpr in C++20
203262
263namespace ranges {
264 template<nothrow-input-iterator InputIterator, nothrow-sentinel-for<InputIterator> Sentinel>
265 requires destructible<iter_value_t<InputIterator>>
266 constexpr InputIterator destroy(InputIterator first, Sentinel last) noexcept; // since C++20
267 template<nothrow-input-range InputRange>
268 requires destructible<range_value_t<InputRange>>
269 constexpr borrowed_iterator_t<InputRange> destroy(InputRange&& range) noexcept; // since C++20
270}
271
204272template <class ForwardIterator, class Size>
205273ForwardIterator destroy_n(ForwardIterator first, Size n); // constexpr in C++20
206274
275namespace ranges {
276 template<nothrow-input-iterator InputIterator>
277 requires destructible<iter_value_t<InputIterator>>
278 constexpr InputIterator destroy_n(InputIterator first, iter_difference_t<InputIterator> n) noexcept; // since C++20
279}
280
207281template <class InputIterator, class ForwardIterator>
208282 ForwardIterator uninitialized_move(InputIterator first, InputIterator last, ForwardIterator result);
209283
284namespace ranges {
285
286template<class InputIterator, class OutputIterator>
287using uninitialized_move_result = in_out_result<InputIterator, OutputIterator>; // since C++20
288
289template <input_iterator InputIterator, sentinel_for<InputIterator> Sentinel1, nothrow-forward-iterator OutputIterator, nothrow-sentinel-for<O> Sentinel2>
290 requires constructible_from<iter_value_t<OutputIterator>, iter_rvalue_reference_t<InputIterator>>
291uninitialized_move_result<InputIterator, OutputIterator>
292uninitialized_move(InputIterator ifirst, Sentinel1 ilast, OutputIterator ofirst, Sentinel2 olast); // since C++20
293
294template<input_range InputRange, nothrow-forward-range OutputRange>
295 requires constructible_from<range_value_t<OutputRange>, range_rvalue_reference_t<InputRange>>
296uninitialized_move_result<borrowed_iterator_t<InputRange>, borrowed_iterator_t<OutputRange>>
297uninitialized_move(InputRange&& in_range, OutputRange&& out_range); // since C++20
298
299}
300
210301template <class InputIterator, class Size, class ForwardIterator>
211302 pair<InputIterator,ForwardIterator> uninitialized_move_n(InputIterator first, Size n, ForwardIterator result);
212303
304namespace ranges {
305
306template<class InputIterator, class OutputIterator>
307using uninitialized_move_n_result = in_out_result<InputIterator, OutputIterator>; // since C++20
308
309template<input_iterator InputIterator, nothrow-forward-iterator OutputIterator, nothrow-sentinel-for<OutputIterator> Sentinel>
310 requires constructible_from<iter_value_t<OutputIterator>, iter_rvalue_reference_t<InputIterator>>
311uninitialized_move_n_result<InputIterator, OutputIterator>
312uninitialized_move_n(InputIterator ifirst, iter_difference_t<InputIterator> n, OutputIterator ofirst, Sentinel olast); // since C++20
313
314}
315
213316template <class ForwardIterator>
214317 void uninitialized_value_construct(ForwardIterator first, ForwardIterator last);
215318
319namespace ranges {
320
321template <nothrow-forward-iterator ForwardIterator, nothrow-sentinel-for<ForwardIterator> Sentinel>
322 requires default_initializable<iter_value_t<ForwardIterator>>
323 ForwardIterator uninitialized_value_construct(ForwardIterator first, Sentinel last); // since C++20
324
325template <nothrow-forward-range ForwardRange>
326 requires default_initializable<range_value_t<ForwardRange>>
327 borrowed_iterator_t<ForwardRange> uninitialized_value_construct(ForwardRange&& r); // since C++20
328
329}
330
216331template <class ForwardIterator, class Size>
217332 ForwardIterator uninitialized_value_construct_n(ForwardIterator first, Size n);
218333
334namespace ranges {
335
336template <nothrow-forward-iterator ForwardIterator>
337 requires default_initializable<iter_value_t<ForwardIterator>>
338 ForwardIterator uninitialized_value_construct_n(ForwardIterator first, iter_difference_t<ForwardIterator> n); // since C++20
339
340}
341
219342template <class ForwardIterator>
220343 void uninitialized_default_construct(ForwardIterator first, ForwardIterator last);
221344
345namespace ranges {
346
347template <nothrow-forward-iterator ForwardIterator, nothrow-sentinel-for<ForwardIterator> Sentinel>
348 requires default_initializable<iter_value_t<ForwardIterator>>
349 ForwardIterator uninitialized_default_construct(ForwardIterator first, Sentinel last); // since C++20
350
351template <nothrow-forward-range ForwardRange>
352 requires default_initializable<range_value_t<ForwardRange>>
353 borrowed_iterator_t<ForwardRange> uninitialized_default_construct(ForwardRange&& r); // since C++20
354
355}
356
222357template <class ForwardIterator, class Size>
223358 ForwardIterator uninitialized_default_construct_n(ForwardIterator first, Size n);
224359
360namespace ranges {
361
362template <nothrow-forward-iterator ForwardIterator>
363 requires default_initializable<iter_value_t<ForwardIterator>>
364 ForwardIterator uninitialized_default_construct_n(ForwardIterator first, iter_difference_t<ForwardIterator> n); // since C++20
365
366}
367
225368template <class Y> struct auto_ptr_ref {}; // deprecated in C++11, removed in C++17
226369
227370template<class X>
......@@ -405,7 +548,8 @@ template<class T>
405548class shared_ptr
406549{
407550public:
408 typedef T element_type;
551 typedef T element_type; // until C++17
552 typedef remove_extent_t<T> element_type; // since C++17
409553 typedef weak_ptr<T> weak_type; // C++17
410554
411555 // constructors:
......@@ -525,7 +669,8 @@ template<class T>
525669class weak_ptr
526670{
527671public:
528 typedef T element_type;
672 typedef T element_type; // until C++17
673 typedef remove_extent_t<T> element_type; // since C++17
529674
530675 // constructors
531676 constexpr weak_ptr() noexcept;
......@@ -653,14 +798,6 @@ template <class T> struct hash<shared_ptr<T> >;
653798template <class T, class Alloc>
654799 inline constexpr bool uses_allocator_v = uses_allocator<T, Alloc>::value;
655800
656// Pointer safety
657enum class pointer_safety { relaxed, preferred, strict }; // since C++11
658void declare_reachable(void *p); // since C++11
659template <class T> T *undeclare_reachable(T *p); // since C++11
660void declare_no_pointers(char *p, size_t n); // since C++11
661void undeclare_no_pointers(char *p, size_t n); // since C++11
662pointer_safety get_pointer_safety() noexcept; // since C++11
663
664801void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
665802
666803} // std
......@@ -675,9 +812,11 @@ void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
675812#include <__memory/allocator_arg_t.h>
676813#include <__memory/allocator_traits.h>
677814#include <__memory/compressed_pair.h>
815#include <__memory/concepts.h>
678816#include <__memory/construct_at.h>
679#include <__memory/pointer_safety.h>
680817#include <__memory/pointer_traits.h>
818#include <__memory/ranges_construct_at.h>
819#include <__memory/ranges_uninitialized_algorithms.h>
681820#include <__memory/raw_storage_iterator.h>
682821#include <__memory/shared_ptr.h>
683822#include <__memory/temporary_buffer.h>
......@@ -706,10 +845,6 @@ void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
706845#pragma GCC system_header
707846#endif
708847
709_LIBCPP_PUSH_MACROS
710#include <__undef_macros>
711
712
713848_LIBCPP_BEGIN_NAMESPACE_STD
714849
715850template <class _Alloc, class _Ptr>
......@@ -842,9 +977,9 @@ _LIBCPP_FUNC_VIS void* align(size_t __align, size_t __sz, void*& __ptr, size_t&
842977
843978// --- Helper for container swap --
844979template <typename _Alloc>
845_LIBCPP_INLINE_VISIBILITY
980_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
846981void __swap_allocator(_Alloc & __a1, _Alloc & __a2, true_type)
847#if _LIBCPP_STD_VER >= 14
982#if _LIBCPP_STD_VER > 11
848983 _NOEXCEPT
849984#else
850985 _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
......@@ -855,13 +990,13 @@ void __swap_allocator(_Alloc & __a1, _Alloc & __a2, true_type)
855990}
856991
857992template <typename _Alloc>
858inline _LIBCPP_INLINE_VISIBILITY
993inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
859994void __swap_allocator(_Alloc &, _Alloc &, false_type) _NOEXCEPT {}
860995
861996template <typename _Alloc>
862inline _LIBCPP_INLINE_VISIBILITY
997inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
863998void __swap_allocator(_Alloc & __a1, _Alloc & __a2)
864#if _LIBCPP_STD_VER >= 14
999#if _LIBCPP_STD_VER > 11
8651000 _NOEXCEPT
8661001#else
8671002 _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
......@@ -960,8 +1095,6 @@ struct __builtin_new_allocator {
9601095
9611096_LIBCPP_END_NAMESPACE_STD
9621097
963_LIBCPP_POP_MACROS
964
9651098#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17
9661099# include <__pstl_memory>
9671100#endif
lib/libcxx/include/module.modulemap+266-71
......@@ -2,7 +2,8 @@
22// since __config may be included from C headers which may create an
33// include cycle.
44module std_config [system] [extern_c] {
5 header "__config"
5 textual header "__config"
6 textual header "__config_site"
67}
78
89module std [system] {
......@@ -246,6 +247,9 @@ module std [system] {
246247 module generate { private header "__algorithm/generate.h" }
247248 module generate_n { private header "__algorithm/generate_n.h" }
248249 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" }
249253 module includes { private header "__algorithm/includes.h" }
250254 module inplace_merge { private header "__algorithm/inplace_merge.h" }
251255 module is_heap { private header "__algorithm/is_heap.h" }
......@@ -335,6 +339,11 @@ module std [system] {
335339 module bit {
336340 header "bit"
337341 export *
342
343 module __bit {
344 module bit_cast { private header "__bit/bit_cast.h" }
345 module byteswap { private header "__bit/byteswap.h" }
346 }
338347 }
339348 module bitset {
340349 header "bitset"
......@@ -346,10 +355,28 @@ module std [system] {
346355 module charconv {
347356 header "charconv"
348357 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
349365 }
350366 module chrono {
351367 header "chrono"
352368 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 }
353380 }
354381 module codecvt {
355382 header "codecvt"
......@@ -358,6 +385,22 @@ module std [system] {
358385 module compare {
359386 header "compare"
360387 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 }
361404 }
362405 module complex {
363406 header "complex"
......@@ -366,11 +409,49 @@ module std [system] {
366409 module concepts {
367410 header "concepts"
368411 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 }
369437 }
370438 module condition_variable {
371439 header "condition_variable"
372440 export *
373441 }
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 }
374455 module deque {
375456 header "deque"
376457 export initializer_list
......@@ -387,14 +468,52 @@ module std [system] {
387468 module filesystem {
388469 header "filesystem"
389470 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 }
390490 }
391491 module format {
392492 header "format"
393493 export *
394494
395495 module __format {
396 module format_error { private header "__format/format_error.h" }
397 module format_parse_context { private header "__format/format_parse_context.h" }
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" }
398517 }
399518 }
400519 module forward_list {
......@@ -414,17 +533,19 @@ module std [system] {
414533 module binary_function { private header "__functional/binary_function.h" }
415534 module binary_negate { private header "__functional/binary_negate.h" }
416535 module bind { private header "__functional/bind.h" }
536 module bind_back { private header "__functional/bind_back.h" }
417537 module bind_front { private header "__functional/bind_front.h" }
418538 module binder1st { private header "__functional/binder1st.h" }
419539 module binder2nd { private header "__functional/binder2nd.h" }
540 module compose { private header "__functional/compose.h" }
420541 module default_searcher { private header "__functional/default_searcher.h" }
421542 module function { private header "__functional/function.h" }
422543 module hash { private header "__functional/hash.h" }
423544 module identity { private header "__functional/identity.h" }
424 module is_transparent { private header "__functional/is_transparent.h" }
425545 module invoke { private header "__functional/invoke.h" }
426 module mem_fn { private header "__functional/mem_fn.h" }
427 module mem_fun_ref { private header "__functional/mem_fun_ref.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" }
428549 module not_fn { private header "__functional/not_fn.h" }
429550 module operations { private header "__functional/operations.h" }
430551 module perfect_forward { private header "__functional/perfect_forward.h" }
......@@ -478,10 +599,7 @@ module std [system] {
478599
479600 module __iterator {
480601 module access { private header "__iterator/access.h" }
481 module advance {
482 private header "__iterator/advance.h"
483 export __function_like
484 }
602 module advance { private header "__iterator/advance.h" }
485603 module back_insert_iterator { private header "__iterator/back_insert_iterator.h" }
486604 module common_iterator { private header "__iterator/common_iterator.h" }
487605 module concepts { private header "__iterator/concepts.h" }
......@@ -493,6 +611,7 @@ module std [system] {
493611 module erase_if_container { private header "__iterator/erase_if_container.h" }
494612 module front_insert_iterator { private header "__iterator/front_insert_iterator.h" }
495613 module incrementable_traits { private header "__iterator/incrementable_traits.h" }
614 module indirectly_comparable { private header "__iterator/indirectly_comparable.h" }
496615 module insert_iterator { private header "__iterator/insert_iterator.h" }
497616 module istream_iterator { private header "__iterator/istream_iterator.h" }
498617 module istreambuf_iterator { private header "__iterator/istreambuf_iterator.h" }
......@@ -501,21 +620,16 @@ module std [system] {
501620 module iterator { private header "__iterator/iterator.h" }
502621 module iterator_traits { private header "__iterator/iterator_traits.h" }
503622 module move_iterator { private header "__iterator/move_iterator.h" }
504 module next {
505 private header "__iterator/next.h"
506 export __function_like
507 }
623 module next { private header "__iterator/next.h" }
508624 module ostream_iterator { private header "__iterator/ostream_iterator.h" }
509625 module ostreambuf_iterator { private header "__iterator/ostreambuf_iterator.h" }
510 module prev {
511 private header "__iterator/prev.h"
512 export __function_like
513 }
626 module prev { private header "__iterator/prev.h" }
514627 module projected { private header "__iterator/projected.h" }
515628 module readable_traits { private header "__iterator/readable_traits.h" }
516629 module reverse_access { private header "__iterator/reverse_access.h" }
517630 module reverse_iterator { private header "__iterator/reverse_iterator.h" }
518631 module size { private header "__iterator/size.h" }
632 module unreachable_sentinel { private header "__iterator/unreachable_sentinel.h" }
519633 module wrap_iter { private header "__iterator/wrap_iter.h" }
520634 }
521635 }
......@@ -547,22 +661,25 @@ module std [system] {
547661 export *
548662
549663 module __memory {
550 module addressof { private header "__memory/addressof.h" }
551 module allocation_guard { private header "__memory/allocation_guard.h" }
552 module allocator { private header "__memory/allocator.h" }
553 module allocator_arg_t { private header "__memory/allocator_arg_t.h" }
554 module allocator_traits { private header "__memory/allocator_traits.h" }
555 module auto_ptr { private header "__memory/auto_ptr.h" }
556 module compressed_pair { private header "__memory/compressed_pair.h" }
557 module construct_at { private header "__memory/construct_at.h" }
558 module pointer_safety { private header "__memory/pointer_safety.h" }
559 module pointer_traits { private header "__memory/pointer_traits.h" }
560 module raw_storage_iterator { private header "__memory/raw_storage_iterator.h" }
561 module shared_ptr { private header "__memory/shared_ptr.h" }
562 module temporary_buffer { private header "__memory/temporary_buffer.h" }
563 module uninitialized_algorithms { private header "__memory/uninitialized_algorithms.h" }
564 module unique_ptr { private header "__memory/unique_ptr.h" }
565 module uses_allocator { private header "__memory/uses_allocator.h" }
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" }
566683 }
567684 }
568685 module mutex {
......@@ -580,6 +697,22 @@ module std [system] {
580697 module numeric {
581698 header "numeric"
582699 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 }
583716 }
584717 module optional {
585718 header "optional"
......@@ -601,7 +734,42 @@ module std [system] {
601734 export *
602735
603736 module __random {
604 module uniform_int_distribution { private header "__random/uniform_int_distribution.h" }
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" }
605773 }
606774 }
607775 module ranges {
......@@ -612,24 +780,44 @@ module std [system] {
612780 export *
613781
614782 module __ranges {
615 module access { private header "__ranges/access.h" }
616 module all { private header "__ranges/all.h" }
617 module common_view { private header "__ranges/common_view.h" }
618 module concepts { private header "__ranges/concepts.h" }
619 module copyable_box { private header "__ranges/copyable_box.h" }
620 module dangling { private header "__ranges/dangling.h" }
621 module data { private header "__ranges/data.h" }
622 module drop_view { private header "__ranges/drop_view.h" }
623 module empty { private header "__ranges/empty.h" }
624 module empty_view { private header "__ranges/empty_view.h" }
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" }
625801 module enable_borrowed_range { private header "__ranges/enable_borrowed_range.h" }
626 module enable_view { private header "__ranges/enable_view.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" }
627805 module non_propagating_cache { private header "__ranges/non_propagating_cache.h" }
628 module ref_view { private header "__ranges/ref_view.h" }
629 module size { private header "__ranges/size.h" }
630 module subrange { private header "__ranges/subrange.h" }
631 module transform_view { private header "__ranges/transform_view.h" }
632 module view_interface { private header "__ranges/view_interface.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" }
633821 }
634822 }
635823 module ratio {
......@@ -706,6 +894,11 @@ module std [system] {
706894 module thread {
707895 header "thread"
708896 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 }
709902 }
710903 module tuple {
711904 header "tuple"
......@@ -740,20 +933,22 @@ module std [system] {
740933 export *
741934
742935 module __utility {
743 module __decay_copy { private header "__utility/__decay_copy.h" }
744 module as_const { private header "__utility/as_const.h" }
745 module cmp { private header "__utility/cmp.h" }
746 module declval { private header "__utility/declval.h" }
747 module exchange { private header "__utility/exchange.h" }
748 module forward { private header "__utility/forward.h" }
749 module in_place { private header "__utility/in_place.h" }
750 module integer_sequence { private header "__utility/integer_sequence.h" }
751 module move { private header "__utility/move.h" }
752 module pair { private header "__utility/pair.h" }
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" }
753946 module piecewise_construct { private header "__utility/piecewise_construct.h" }
754 module rel_ops { private header "__utility/rel_ops.h" }
755 module swap { private header "__utility/swap.h" }
756 module to_underlying { private header "__utility/to_underlying.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" }
757952 }
758953 }
759954 module valarray {
......@@ -784,21 +979,21 @@ module std [system] {
784979 module __availability { private header "__availability" export * }
785980 module __bit_reference { private header "__bit_reference" export * }
786981 module __bits { private header "__bits" export * }
787 module __debug { header "__debug" export * }
982 module __debug { header "__debug" export * }
788983 module __errc { private header "__errc" export * }
789 module __function_like { private header "__function_like.h" export * }
790 module __hash_table { header "__hash_table" export * }
984 module __hash_table { header "__hash_table" export * }
791985 module __locale { private header "__locale" export * }
986 module __mbstate_t { private header "__mbstate_t.h" export * }
792987 module __mutex_base { private header "__mutex_base" export * }
793988 module __node_handle { private header "__node_handle" export * }
794 module __nullptr { header "__nullptr" export * }
989 module __nullptr { header "__nullptr" export * }
795990 module __split_buffer { private header "__split_buffer" export * }
796991 module __std_stream { private header "__std_stream" export * }
797992 module __string { private header "__string" export * }
798 module __threading_support { header "__threading_support" export * }
799 module __tree { header "__tree" export * }
993 module __threading_support { header "__threading_support" export * }
994 module __tree { header "__tree" export * }
800995 module __tuple { private header "__tuple" export * }
801 module __undef_macros { header "__undef_macros" export * }
996 module __undef_macros { header "__undef_macros" export * }
802997
803998 module experimental {
804999 requires cplusplus11
lib/libcxx/include/mutex+14-21
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- mutex ------------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -112,7 +112,7 @@ template <class... MutexTypes>
112112class scoped_lock // C++17
113113{
114114public:
115 using mutex_type = Mutex; // If MutexTypes... consists of the single type Mutex
115 using mutex_type = Mutex; // Only if sizeof...(MutexTypes) == 1
116116
117117 explicit scoped_lock(MutexTypes&... m);
118118 scoped_lock(adopt_lock_t, MutexTypes&... m);
......@@ -215,14 +215,12 @@ class _LIBCPP_TYPE_VIS recursive_mutex
215215 __libcpp_recursive_mutex_t __m_;
216216
217217public:
218 recursive_mutex();
219 ~recursive_mutex();
218 recursive_mutex();
219 ~recursive_mutex();
220220
221private:
222 recursive_mutex(const recursive_mutex&); // = delete;
223 recursive_mutex& operator=(const recursive_mutex&); // = delete;
221 recursive_mutex(const recursive_mutex&) = delete;
222 recursive_mutex& operator=(const recursive_mutex&) = delete;
224223
225public:
226224 void lock();
227225 bool try_lock() _NOEXCEPT;
228226 void unlock() _NOEXCEPT;
......@@ -242,9 +240,8 @@ public:
242240 timed_mutex();
243241 ~timed_mutex();
244242
245private:
246 timed_mutex(const timed_mutex&); // = delete;
247 timed_mutex& operator=(const timed_mutex&); // = delete;
243 timed_mutex(const timed_mutex&) = delete;
244 timed_mutex& operator=(const timed_mutex&) = delete;
248245
249246public:
250247 void lock();
......@@ -283,14 +280,12 @@ class _LIBCPP_TYPE_VIS recursive_timed_mutex
283280 size_t __count_;
284281 __thread_id __id_;
285282public:
286 recursive_timed_mutex();
287 ~recursive_timed_mutex();
283 recursive_timed_mutex();
284 ~recursive_timed_mutex();
288285
289private:
290 recursive_timed_mutex(const recursive_timed_mutex&); // = delete;
291 recursive_timed_mutex& operator=(const recursive_timed_mutex&); // = delete;
286 recursive_timed_mutex(const recursive_timed_mutex&) = delete;
287 recursive_timed_mutex& operator=(const recursive_timed_mutex&) = delete;
292288
293public:
294289 void lock();
295290 bool try_lock() _NOEXCEPT;
296291 template <class _Rep, class _Period>
......@@ -576,6 +571,8 @@ struct _LIBCPP_TEMPLATE_VIS once_flag
576571 _LIBCPP_INLINE_VISIBILITY
577572 _LIBCPP_CONSTEXPR
578573 once_flag() _NOEXCEPT : __state_(0) {}
574 once_flag(const once_flag&) = delete;
575 once_flag& operator=(const once_flag&) = delete;
579576
580577#if defined(_LIBCPP_ABI_MICROSOFT)
581578 typedef uintptr_t _State_type;
......@@ -583,11 +580,7 @@ struct _LIBCPP_TEMPLATE_VIS once_flag
583580 typedef unsigned long _State_type;
584581#endif
585582
586
587583private:
588 once_flag(const once_flag&); // = delete;
589 once_flag& operator=(const once_flag&); // = delete;
590
591584 _State_type __state_;
592585
593586#ifndef _LIBCPP_CXX03_LANG
lib/libcxx/include/new+15-10
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===----------------------------- new ------------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -149,6 +149,16 @@ _LIBCPP_FUNC_VIS new_handler get_new_handler() _NOEXCEPT;
149149
150150_LIBCPP_NORETURN _LIBCPP_FUNC_VIS void __throw_bad_alloc(); // not in C++ spec
151151
152_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
153void __throw_bad_array_new_length()
154{
155#ifndef _LIBCPP_NO_EXCEPTIONS
156 throw bad_array_new_length();
157#else
158 _VSTD::abort();
159#endif
160}
161
152162#if !defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) && \
153163 !defined(_LIBCPP_ABI_VCRUNTIME)
154164#ifndef _LIBCPP_CXX03_LANG
......@@ -164,10 +174,10 @@ enum align_val_t { __zero = 0, __max = (size_t)-1 };
164174struct destroying_delete_t {
165175 explicit destroying_delete_t() = default;
166176};
167_LIBCPP_INLINE_VAR constexpr destroying_delete_t destroying_delete{};
177inline constexpr destroying_delete_t destroying_delete{};
168178#endif // _LIBCPP_STD_VER > 17
169179
170} // std
180} // namespace std
171181
172182#if defined(_LIBCPP_CXX03_LANG)
173183#define _THROW_BAD_ALLOC throw(std::bad_alloc)
......@@ -332,22 +342,17 @@ void __libcpp_aligned_free(void* __ptr) {
332342
333343
334344template <class _Tp>
335_LIBCPP_NODISCARD_AFTER_CXX17 inline
345_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_HIDE_FROM_ABI
336346_LIBCPP_CONSTEXPR _Tp* __launder(_Tp* __p) _NOEXCEPT
337347{
338348 static_assert (!(is_function<_Tp>::value), "can't launder functions" );
339349 static_assert (!(is_same<void, typename remove_cv<_Tp>::type>::value), "can't launder cv-void" );
340#ifdef _LIBCPP_COMPILER_HAS_BUILTIN_LAUNDER
341350 return __builtin_launder(__p);
342#else
343 return __p;
344#endif
345351}
346352
347
348353#if _LIBCPP_STD_VER > 14
349354template <class _Tp>
350_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY
355_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_HIDE_FROM_ABI
351356constexpr _Tp* launder(_Tp* __p) noexcept
352357{
353358 return _VSTD::__launder(__p);
lib/libcxx/include/numbers+33-38
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===---------------------------- numbers ---------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -63,55 +63,52 @@ namespace std::numbers {
6363#include <type_traits>
6464#include <version>
6565
66#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CONCEPTS)
66#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
6767
6868#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
6969#pragma GCC system_header
7070#endif
7171
72_LIBCPP_PUSH_MACROS
73#include <__undef_macros>
74
7572_LIBCPP_BEGIN_NAMESPACE_STD
7673
7774namespace numbers {
7875
79template <class T>
76template <class _Tp>
8077inline constexpr bool __false = false;
8178
82template <class T>
79template <class _Tp>
8380struct __illformed
8481{
85 static_assert(__false<T>, "A program that instantiates a primary template of a mathematical constant variable template is ill-formed.");
82 static_assert(__false<_Tp>, "A program that instantiates a primary template of a mathematical constant variable template is ill-formed.");
8683};
8784
88template <class T> inline constexpr T e_v = __illformed<T>{};
89template <class T> inline constexpr T log2e_v = __illformed<T>{};
90template <class T> inline constexpr T log10e_v = __illformed<T>{};
91template <class T> inline constexpr T pi_v = __illformed<T>{};
92template <class T> inline constexpr T inv_pi_v = __illformed<T>{};
93template <class T> inline constexpr T inv_sqrtpi_v = __illformed<T>{};
94template <class T> inline constexpr T ln2_v = __illformed<T>{};
95template <class T> inline constexpr T ln10_v = __illformed<T>{};
96template <class T> inline constexpr T sqrt2_v = __illformed<T>{};
97template <class T> inline constexpr T sqrt3_v = __illformed<T>{};
98template <class T> inline constexpr T inv_sqrt3_v = __illformed<T>{};
99template <class T> inline constexpr T egamma_v = __illformed<T>{};
100template <class T> inline constexpr T phi_v = __illformed<T>{};
101
102template <floating_point T> inline constexpr T e_v<T> = 2.718281828459045235360287471352662;
103template <floating_point T> inline constexpr T log2e_v<T> = 1.442695040888963407359924681001892;
104template <floating_point T> inline constexpr T log10e_v<T> = 0.434294481903251827651128918916605;
105template <floating_point T> inline constexpr T pi_v<T> = 3.141592653589793238462643383279502;
106template <floating_point T> inline constexpr T inv_pi_v<T> = 0.318309886183790671537767526745028;
107template <floating_point T> inline constexpr T inv_sqrtpi_v<T> = 0.564189583547756286948079451560772;
108template <floating_point T> inline constexpr T ln2_v<T> = 0.693147180559945309417232121458176;
109template <floating_point T> inline constexpr T ln10_v<T> = 2.302585092994045684017991454684364;
110template <floating_point T> inline constexpr T sqrt2_v<T> = 1.414213562373095048801688724209698;
111template <floating_point T> inline constexpr T sqrt3_v<T> = 1.732050807568877293527446341505872;
112template <floating_point T> inline constexpr T inv_sqrt3_v<T> = 0.577350269189625764509148780501957;
113template <floating_point T> inline constexpr T egamma_v<T> = 0.577215664901532860606512090082402;
114template <floating_point T> inline constexpr T phi_v<T> = 1.618033988749894848204586834365638;
85template <class _Tp> inline constexpr _Tp e_v = __illformed<_Tp>{};
86template <class _Tp> inline constexpr _Tp log2e_v = __illformed<_Tp>{};
87template <class _Tp> inline constexpr _Tp log10e_v = __illformed<_Tp>{};
88template <class _Tp> inline constexpr _Tp pi_v = __illformed<_Tp>{};
89template <class _Tp> inline constexpr _Tp inv_pi_v = __illformed<_Tp>{};
90template <class _Tp> inline constexpr _Tp inv_sqrtpi_v = __illformed<_Tp>{};
91template <class _Tp> inline constexpr _Tp ln2_v = __illformed<_Tp>{};
92template <class _Tp> inline constexpr _Tp ln10_v = __illformed<_Tp>{};
93template <class _Tp> inline constexpr _Tp sqrt2_v = __illformed<_Tp>{};
94template <class _Tp> inline constexpr _Tp sqrt3_v = __illformed<_Tp>{};
95template <class _Tp> inline constexpr _Tp inv_sqrt3_v = __illformed<_Tp>{};
96template <class _Tp> inline constexpr _Tp egamma_v = __illformed<_Tp>{};
97template <class _Tp> inline constexpr _Tp phi_v = __illformed<_Tp>{};
98
99template <floating_point _Tp> inline constexpr _Tp e_v<_Tp> = 2.718281828459045235360287471352662;
100template <floating_point _Tp> inline constexpr _Tp log2e_v<_Tp> = 1.442695040888963407359924681001892;
101template <floating_point _Tp> inline constexpr _Tp log10e_v<_Tp> = 0.434294481903251827651128918916605;
102template <floating_point _Tp> inline constexpr _Tp pi_v<_Tp> = 3.141592653589793238462643383279502;
103template <floating_point _Tp> inline constexpr _Tp inv_pi_v<_Tp> = 0.318309886183790671537767526745028;
104template <floating_point _Tp> inline constexpr _Tp inv_sqrtpi_v<_Tp> = 0.564189583547756286948079451560772;
105template <floating_point _Tp> inline constexpr _Tp ln2_v<_Tp> = 0.693147180559945309417232121458176;
106template <floating_point _Tp> inline constexpr _Tp ln10_v<_Tp> = 2.302585092994045684017991454684364;
107template <floating_point _Tp> inline constexpr _Tp sqrt2_v<_Tp> = 1.414213562373095048801688724209698;
108template <floating_point _Tp> inline constexpr _Tp sqrt3_v<_Tp> = 1.732050807568877293527446341505872;
109template <floating_point _Tp> inline constexpr _Tp inv_sqrt3_v<_Tp> = 0.577350269189625764509148780501957;
110template <floating_point _Tp> inline constexpr _Tp egamma_v<_Tp> = 0.577215664901532860606512090082402;
111template <floating_point _Tp> inline constexpr _Tp phi_v<_Tp> = 1.618033988749894848204586834365638;
115112
116113inline constexpr double e = e_v<double>;
117114inline constexpr double log2e = log2e_v<double>;
......@@ -131,8 +128,6 @@ inline constexpr double phi = phi_v<double>;
131128
132129_LIBCPP_END_NAMESPACE_STD
133130
134_LIBCPP_POP_MACROS
135
136#endif //_LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CONCEPTS)
131#endif //!defined(_LIBCPP_HAS_NO_CONCEPTS)
137132
138133#endif // _LIBCPP_NUMBERS
lib/libcxx/include/numeric+15-476
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===---------------------------- numeric ---------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -145,490 +145,29 @@ template<class T>
145145*/
146146
147147#include <__config>
148#include <__debug>
149148#include <cmath> // for isnormal
150149#include <functional>
151150#include <iterator>
152#include <limits> // for numeric_limits
153151#include <version>
154152
153#include <__numeric/accumulate.h>
154#include <__numeric/adjacent_difference.h>
155#include <__numeric/exclusive_scan.h>
156#include <__numeric/gcd_lcm.h>
157#include <__numeric/inclusive_scan.h>
158#include <__numeric/inner_product.h>
159#include <__numeric/iota.h>
160#include <__numeric/midpoint.h>
161#include <__numeric/partial_sum.h>
162#include <__numeric/reduce.h>
163#include <__numeric/transform_exclusive_scan.h>
164#include <__numeric/transform_inclusive_scan.h>
165#include <__numeric/transform_reduce.h>
166
155167#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
156168#pragma GCC system_header
157169#endif
158170
159_LIBCPP_PUSH_MACROS
160#include <__undef_macros>
161
162_LIBCPP_BEGIN_NAMESPACE_STD
163
164template <class _InputIterator, class _Tp>
165_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
166_Tp
167accumulate(_InputIterator __first, _InputIterator __last, _Tp __init)
168{
169 for (; __first != __last; ++__first)
170#if _LIBCPP_STD_VER > 17
171 __init = _VSTD::move(__init) + *__first;
172#else
173 __init = __init + *__first;
174#endif
175 return __init;
176}
177
178template <class _InputIterator, class _Tp, class _BinaryOperation>
179_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
180_Tp
181accumulate(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOperation __binary_op)
182{
183 for (; __first != __last; ++__first)
184#if _LIBCPP_STD_VER > 17
185 __init = __binary_op(_VSTD::move(__init), *__first);
186#else
187 __init = __binary_op(__init, *__first);
188#endif
189 return __init;
190}
191
192#if _LIBCPP_STD_VER > 14
193template <class _InputIterator, class _Tp, class _BinaryOp>
194_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
195_Tp
196reduce(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOp __b)
197{
198 for (; __first != __last; ++__first)
199 __init = __b(__init, *__first);
200 return __init;
201}
202
203template <class _InputIterator, class _Tp>
204_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
205_Tp
206reduce(_InputIterator __first, _InputIterator __last, _Tp __init)
207{
208 return _VSTD::reduce(__first, __last, __init, _VSTD::plus<>());
209}
210
211template <class _InputIterator>
212_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
213typename iterator_traits<_InputIterator>::value_type
214reduce(_InputIterator __first, _InputIterator __last)
215{
216 return _VSTD::reduce(__first, __last,
217 typename iterator_traits<_InputIterator>::value_type{});
218}
219#endif
220
221template <class _InputIterator1, class _InputIterator2, class _Tp>
222_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
223_Tp
224inner_product(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _Tp __init)
225{
226 for (; __first1 != __last1; ++__first1, (void) ++__first2)
227#if _LIBCPP_STD_VER > 17
228 __init = _VSTD::move(__init) + *__first1 * *__first2;
229#else
230 __init = __init + *__first1 * *__first2;
231#endif
232 return __init;
233}
234
235template <class _InputIterator1, class _InputIterator2, class _Tp, class _BinaryOperation1, class _BinaryOperation2>
236_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
237_Tp
238inner_product(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2,
239 _Tp __init, _BinaryOperation1 __binary_op1, _BinaryOperation2 __binary_op2)
240{
241 for (; __first1 != __last1; ++__first1, (void) ++__first2)
242#if _LIBCPP_STD_VER > 17
243 __init = __binary_op1(_VSTD::move(__init), __binary_op2(*__first1, *__first2));
244#else
245 __init = __binary_op1(__init, __binary_op2(*__first1, *__first2));
246#endif
247 return __init;
248}
249
250#if _LIBCPP_STD_VER > 14
251template <class _InputIterator, class _Tp, class _BinaryOp, class _UnaryOp>
252_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
253_Tp
254transform_reduce(_InputIterator __first, _InputIterator __last,
255 _Tp __init, _BinaryOp __b, _UnaryOp __u)
256{
257 for (; __first != __last; ++__first)
258 __init = __b(__init, __u(*__first));
259 return __init;
260}
261
262template <class _InputIterator1, class _InputIterator2,
263 class _Tp, class _BinaryOp1, class _BinaryOp2>
264_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
265_Tp
266transform_reduce(_InputIterator1 __first1, _InputIterator1 __last1,
267 _InputIterator2 __first2, _Tp __init, _BinaryOp1 __b1, _BinaryOp2 __b2)
268{
269 for (; __first1 != __last1; ++__first1, (void) ++__first2)
270 __init = __b1(__init, __b2(*__first1, *__first2));
271 return __init;
272}
273
274template <class _InputIterator1, class _InputIterator2, class _Tp>
275_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
276_Tp
277transform_reduce(_InputIterator1 __first1, _InputIterator1 __last1,
278 _InputIterator2 __first2, _Tp __init)
279{
280 return _VSTD::transform_reduce(__first1, __last1, __first2, _VSTD::move(__init),
281 _VSTD::plus<>(), _VSTD::multiplies<>());
282}
283#endif
284
285template <class _InputIterator, class _OutputIterator>
286_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
287_OutputIterator
288partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
289{
290 if (__first != __last)
291 {
292 typename iterator_traits<_InputIterator>::value_type __t(*__first);
293 *__result = __t;
294 for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result)
295 {
296#if _LIBCPP_STD_VER > 17
297 __t = _VSTD::move(__t) + *__first;
298#else
299 __t = __t + *__first;
300#endif
301 *__result = __t;
302 }
303 }
304 return __result;
305}
306
307template <class _InputIterator, class _OutputIterator, class _BinaryOperation>
308_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
309_OutputIterator
310partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result,
311 _BinaryOperation __binary_op)
312{
313 if (__first != __last)
314 {
315 typename iterator_traits<_InputIterator>::value_type __t(*__first);
316 *__result = __t;
317 for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result)
318 {
319#if _LIBCPP_STD_VER > 17
320 __t = __binary_op(_VSTD::move(__t), *__first);
321#else
322 __t = __binary_op(__t, *__first);
323#endif
324 *__result = __t;
325 }
326 }
327 return __result;
328}
329
330#if _LIBCPP_STD_VER > 14
331template <class _InputIterator, class _OutputIterator, class _Tp, class _BinaryOp>
332_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
333_OutputIterator
334exclusive_scan(_InputIterator __first, _InputIterator __last,
335 _OutputIterator __result, _Tp __init, _BinaryOp __b)
336{
337 if (__first != __last)
338 {
339 _Tp __tmp(__b(__init, *__first));
340 while (true)
341 {
342 *__result = _VSTD::move(__init);
343 ++__result;
344 ++__first;
345 if (__first == __last)
346 break;
347 __init = _VSTD::move(__tmp);
348 __tmp = __b(__init, *__first);
349 }
350 }
351 return __result;
352}
353
354template <class _InputIterator, class _OutputIterator, class _Tp>
355_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
356_OutputIterator
357exclusive_scan(_InputIterator __first, _InputIterator __last,
358 _OutputIterator __result, _Tp __init)
359{
360 return _VSTD::exclusive_scan(__first, __last, __result, __init, _VSTD::plus<>());
361}
362
363template <class _InputIterator, class _OutputIterator, class _Tp, class _BinaryOp>
364_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
365_OutputIterator inclusive_scan(_InputIterator __first, _InputIterator __last,
366 _OutputIterator __result, _BinaryOp __b, _Tp __init)
367{
368 for (; __first != __last; ++__first, (void) ++__result) {
369 __init = __b(__init, *__first);
370 *__result = __init;
371 }
372 return __result;
373}
374
375template <class _InputIterator, class _OutputIterator, class _BinaryOp>
376_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
377_OutputIterator inclusive_scan(_InputIterator __first, _InputIterator __last,
378 _OutputIterator __result, _BinaryOp __b)
379{
380 if (__first != __last) {
381 typename iterator_traits<_InputIterator>::value_type __init = *__first;
382 *__result++ = __init;
383 if (++__first != __last)
384 return _VSTD::inclusive_scan(__first, __last, __result, __b, __init);
385 }
386
387 return __result;
388}
389
390template <class _InputIterator, class _OutputIterator>
391_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
392_OutputIterator inclusive_scan(_InputIterator __first, _InputIterator __last,
393 _OutputIterator __result)
394{
395 return _VSTD::inclusive_scan(__first, __last, __result, _VSTD::plus<>());
396}
397
398template <class _InputIterator, class _OutputIterator, class _Tp,
399 class _BinaryOp, class _UnaryOp>
400_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
401_OutputIterator
402transform_exclusive_scan(_InputIterator __first, _InputIterator __last,
403 _OutputIterator __result, _Tp __init,
404 _BinaryOp __b, _UnaryOp __u)
405{
406 if (__first != __last)
407 {
408 _Tp __saved = __init;
409 do
410 {
411 __init = __b(__init, __u(*__first));
412 *__result = __saved;
413 __saved = __init;
414 ++__result;
415 } while (++__first != __last);
416 }
417 return __result;
418}
419
420template <class _InputIterator, class _OutputIterator, class _Tp, class _BinaryOp, class _UnaryOp>
421_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
422_OutputIterator
423transform_inclusive_scan(_InputIterator __first, _InputIterator __last,
424 _OutputIterator __result, _BinaryOp __b, _UnaryOp __u, _Tp __init)
425{
426 for (; __first != __last; ++__first, (void) ++__result) {
427 __init = __b(__init, __u(*__first));
428 *__result = __init;
429 }
430
431 return __result;
432}
433
434template <class _InputIterator, class _OutputIterator, class _BinaryOp, class _UnaryOp>
435_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
436_OutputIterator
437transform_inclusive_scan(_InputIterator __first, _InputIterator __last,
438 _OutputIterator __result, _BinaryOp __b, _UnaryOp __u)
439{
440 if (__first != __last) {
441 typename iterator_traits<_InputIterator>::value_type __init = __u(*__first);
442 *__result++ = __init;
443 if (++__first != __last)
444 return _VSTD::transform_inclusive_scan(__first, __last, __result, __b, __u, __init);
445 }
446
447 return __result;
448}
449#endif
450
451template <class _InputIterator, class _OutputIterator>
452_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
453_OutputIterator
454adjacent_difference(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
455{
456 if (__first != __last)
457 {
458 typename iterator_traits<_InputIterator>::value_type __acc(*__first);
459 *__result = __acc;
460 for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result)
461 {
462 typename iterator_traits<_InputIterator>::value_type __val(*__first);
463#if _LIBCPP_STD_VER > 17
464 *__result = __val - _VSTD::move(__acc);
465#else
466 *__result = __val - __acc;
467#endif
468 __acc = _VSTD::move(__val);
469 }
470 }
471 return __result;
472}
473
474template <class _InputIterator, class _OutputIterator, class _BinaryOperation>
475_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
476_OutputIterator
477adjacent_difference(_InputIterator __first, _InputIterator __last, _OutputIterator __result,
478 _BinaryOperation __binary_op)
479{
480 if (__first != __last)
481 {
482 typename iterator_traits<_InputIterator>::value_type __acc(*__first);
483 *__result = __acc;
484 for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result)
485 {
486 typename iterator_traits<_InputIterator>::value_type __val(*__first);
487#if _LIBCPP_STD_VER > 17
488 *__result = __binary_op(__val, _VSTD::move(__acc));
489#else
490 *__result = __binary_op(__val, __acc);
491#endif
492 __acc = _VSTD::move(__val);
493 }
494 }
495 return __result;
496}
497
498template <class _ForwardIterator, class _Tp>
499_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
500void
501iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value_)
502{
503 for (; __first != __last; ++__first, (void) ++__value_)
504 *__first = __value_;
505}
506
507
508#if _LIBCPP_STD_VER > 14
509template <typename _Result, typename _Source, bool _IsSigned = is_signed<_Source>::value> struct __ct_abs;
510
511template <typename _Result, typename _Source>
512struct __ct_abs<_Result, _Source, true> {
513 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
514 _Result operator()(_Source __t) const noexcept
515 {
516 if (__t >= 0) return __t;
517 if (__t == numeric_limits<_Source>::min()) return -static_cast<_Result>(__t);
518 return -__t;
519 }
520};
521
522template <typename _Result, typename _Source>
523struct __ct_abs<_Result, _Source, false> {
524 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
525 _Result operator()(_Source __t) const noexcept { return __t; }
526};
527
528
529template<class _Tp>
530_LIBCPP_CONSTEXPR _LIBCPP_HIDDEN
531_Tp __gcd(_Tp __m, _Tp __n)
532{
533 static_assert((!is_signed<_Tp>::value), "");
534 return __n == 0 ? __m : _VSTD::__gcd<_Tp>(__n, __m % __n);
535}
536
537
538template<class _Tp, class _Up>
539_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
540common_type_t<_Tp,_Up>
541gcd(_Tp __m, _Up __n)
542{
543 static_assert((is_integral<_Tp>::value && is_integral<_Up>::value), "Arguments to gcd must be integer types");
544 static_assert((!is_same<typename remove_cv<_Tp>::type, bool>::value), "First argument to gcd cannot be bool" );
545 static_assert((!is_same<typename remove_cv<_Up>::type, bool>::value), "Second argument to gcd cannot be bool" );
546 using _Rp = common_type_t<_Tp,_Up>;
547 using _Wp = make_unsigned_t<_Rp>;
548 return static_cast<_Rp>(_VSTD::__gcd(
549 static_cast<_Wp>(__ct_abs<_Rp, _Tp>()(__m)),
550 static_cast<_Wp>(__ct_abs<_Rp, _Up>()(__n))));
551}
552
553template<class _Tp, class _Up>
554_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
555common_type_t<_Tp,_Up>
556lcm(_Tp __m, _Up __n)
557{
558 static_assert((is_integral<_Tp>::value && is_integral<_Up>::value), "Arguments to lcm must be integer types");
559 static_assert((!is_same<typename remove_cv<_Tp>::type, bool>::value), "First argument to lcm cannot be bool" );
560 static_assert((!is_same<typename remove_cv<_Up>::type, bool>::value), "Second argument to lcm cannot be bool" );
561 if (__m == 0 || __n == 0)
562 return 0;
563
564 using _Rp = common_type_t<_Tp,_Up>;
565 _Rp __val1 = __ct_abs<_Rp, _Tp>()(__m) / _VSTD::gcd(__m, __n);
566 _Rp __val2 = __ct_abs<_Rp, _Up>()(__n);
567 _LIBCPP_ASSERT((numeric_limits<_Rp>::max() / __val1 > __val2), "Overflow in lcm");
568 return __val1 * __val2;
569}
570
571#endif /* _LIBCPP_STD_VER > 14 */
572
573#if _LIBCPP_STD_VER > 17
574template <class _Tp>
575_LIBCPP_INLINE_VISIBILITY constexpr
576enable_if_t<is_integral_v<_Tp> && !is_same_v<bool, _Tp> && !is_null_pointer_v<_Tp>, _Tp>
577midpoint(_Tp __a, _Tp __b) noexcept
578_LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
579{
580 using _Up = make_unsigned_t<_Tp>;
581 constexpr _Up __bitshift = numeric_limits<_Up>::digits - 1;
582
583 _Up __diff = _Up(__b) - _Up(__a);
584 _Up __sign_bit = __b < __a;
585
586 _Up __half_diff = (__diff / 2) + (__sign_bit << __bitshift) + (__sign_bit & __diff);
587
588 return __a + __half_diff;
589}
590
591
592template <class _TPtr>
593_LIBCPP_INLINE_VISIBILITY constexpr
594enable_if_t<is_pointer_v<_TPtr>
595 && is_object_v<remove_pointer_t<_TPtr>>
596 && ! is_void_v<remove_pointer_t<_TPtr>>
597 && (sizeof(remove_pointer_t<_TPtr>) > 0), _TPtr>
598midpoint(_TPtr __a, _TPtr __b) noexcept
599{
600 return __a + _VSTD::midpoint(ptrdiff_t(0), __b - __a);
601}
602
603
604template <typename _Tp>
605constexpr int __sign(_Tp __val) {
606 return (_Tp(0) < __val) - (__val < _Tp(0));
607}
608
609template <typename _Fp>
610constexpr _Fp __fp_abs(_Fp __f) { return __f >= 0 ? __f : -__f; }
611
612template <class _Fp>
613_LIBCPP_INLINE_VISIBILITY constexpr
614enable_if_t<is_floating_point_v<_Fp>, _Fp>
615midpoint(_Fp __a, _Fp __b) noexcept
616{
617 constexpr _Fp __lo = numeric_limits<_Fp>::min()*2;
618 constexpr _Fp __hi = numeric_limits<_Fp>::max()/2;
619 return __fp_abs(__a) <= __hi && __fp_abs(__b) <= __hi ? // typical case: overflow is impossible
620 (__a + __b)/2 : // always correctly rounded
621 __fp_abs(__a) < __lo ? __a + __b/2 : // not safe to halve a
622 __fp_abs(__b) < __lo ? __a/2 + __b : // not safe to halve b
623 __a/2 + __b/2; // otherwise correctly rounded
624}
625
626#endif // _LIBCPP_STD_VER > 17
627
628_LIBCPP_END_NAMESPACE_STD
629
630_LIBCPP_POP_MACROS
631
632171#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17
633172# include <__pstl_numeric>
634173#endif
lib/libcxx/include/optional+208-69
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===-------------------------- optional ----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -132,6 +132,18 @@ namespace std {
132132 template <class U> constexpr T value_or(U &&) const &;
133133 template <class U> constexpr T value_or(U &&) &&;
134134
135 // [optional.monadic], monadic operations
136 template<class F> constexpr auto and_then(F&& f) &; // since C++23
137 template<class F> constexpr auto and_then(F&& f) &&; // since C++23
138 template<class F> constexpr auto and_then(F&& f) const&; // since C++23
139 template<class F> constexpr auto and_then(F&& f) const&&; // since C++23
140 template<class F> constexpr auto transform(F&& f) &; // since C++23
141 template<class F> constexpr auto transform(F&& f) &&; // since C++23
142 template<class F> constexpr auto transform(F&& f) const&; // since C++23
143 template<class F> constexpr auto transform(F&& f) const&&; // since C++23
144 template<class F> constexpr optional or_else(F&& f) &&; // since C++23
145 template<class F> constexpr optional or_else(F&& f) const&; // since C++23
146
135147 // 23.6.3.6, modifiers
136148 void reset() noexcept; // constexpr in C++20
137149
......@@ -147,6 +159,7 @@ template<class T>
147159*/
148160
149161#include <__availability>
162#include <__concepts/invocable.h>
150163#include <__config>
151164#include <__debug>
152165#include <__functional_base>
......@@ -163,10 +176,6 @@ template<class T>
163176#pragma GCC system_header
164177#endif
165178
166_LIBCPP_PUSH_MACROS
167#include <__undef_macros>
168
169
170179namespace std // purposefully not using versioning namespace
171180{
172181
......@@ -179,7 +188,7 @@ public:
179188 virtual const char* what() const _NOEXCEPT;
180189};
181190
182} // std
191} // namespace std
183192
184193#if _LIBCPP_STD_VER > 14
185194
......@@ -202,7 +211,9 @@ struct nullopt_t
202211 _LIBCPP_INLINE_VISIBILITY constexpr explicit nullopt_t(__secret_tag, __secret_tag) noexcept {}
203212};
204213
205_LIBCPP_INLINE_VAR constexpr nullopt_t nullopt{nullopt_t::__secret_tag{}, nullopt_t::__secret_tag{}};
214inline constexpr nullopt_t nullopt{nullopt_t::__secret_tag{}, nullopt_t::__secret_tag{}};
215
216struct __optional_construct_from_invoke_tag {};
206217
207218template <class _Tp, bool = is_trivially_destructible<_Tp>::value>
208219struct __optional_destruct_base;
......@@ -238,6 +249,13 @@ struct __optional_destruct_base<_Tp, false>
238249 : __val_(_VSTD::forward<_Args>(__args)...),
239250 __engaged_(true) {}
240251
252#if _LIBCPP_STD_VER > 20
253 template <class _Fp, class... _Args>
254 _LIBCPP_HIDE_FROM_ABI
255 constexpr __optional_destruct_base(__optional_construct_from_invoke_tag, _Fp&& __f, _Args&&... __args)
256 : __val_(_VSTD::invoke(_VSTD::forward<_Fp>(__f), _VSTD::forward<_Args>(__args)...)), __engaged_(true) {}
257#endif
258
241259 _LIBCPP_INLINE_VISIBILITY
242260 _LIBCPP_CONSTEXPR_AFTER_CXX17 void reset() noexcept
243261 {
......@@ -273,6 +291,13 @@ struct __optional_destruct_base<_Tp, true>
273291 : __val_(_VSTD::forward<_Args>(__args)...),
274292 __engaged_(true) {}
275293
294#if _LIBCPP_STD_VER > 20
295 template <class _Fp, class... _Args>
296 _LIBCPP_HIDE_FROM_ABI
297 constexpr __optional_destruct_base(__optional_construct_from_invoke_tag, _Fp&& __f, _Args&&... __args)
298 : __val_(_VSTD::invoke(_VSTD::forward<_Fp>(__f), _VSTD::forward<_Args>(__args)...)), __engaged_(true) {}
299#endif
300
276301 _LIBCPP_INLINE_VISIBILITY
277302 _LIBCPP_CONSTEXPR_AFTER_CXX17 void reset() noexcept
278303 {
......@@ -586,6 +611,12 @@ using __optional_sfinae_assign_base_t = __sfinae_assign_base<
586611 (is_move_constructible<_Tp>::value && is_move_assignable<_Tp>::value)
587612>;
588613
614template<class _Tp>
615class optional;
616template <class _Tp>
617struct __is_std_optional : false_type {};
618template <class _Tp> struct __is_std_optional<optional<_Tp>> : true_type {};
619
589620template <class _Tp>
590621class optional
591622 : private __optional_move_assign_base<_Tp>
......@@ -688,6 +719,7 @@ private:
688719 _CheckOptionalLikeConstructor<_QualUp>,
689720 __check_tuple_constructor_fail
690721 >;
722
691723public:
692724
693725 _LIBCPP_INLINE_VISIBILITY constexpr optional() noexcept {}
......@@ -695,7 +727,7 @@ public:
695727 _LIBCPP_INLINE_VISIBILITY constexpr optional(optional&&) = default;
696728 _LIBCPP_INLINE_VISIBILITY constexpr optional(nullopt_t) noexcept {}
697729
698 template <class _InPlaceT, class... _Args, class = _EnableIf<
730 template <class _InPlaceT, class... _Args, class = enable_if_t<
699731 _And<
700732 _IsSame<_InPlaceT, in_place_t>,
701733 is_constructible<value_type, _Args...>
......@@ -706,21 +738,21 @@ public:
706738 constexpr explicit optional(_InPlaceT, _Args&&... __args)
707739 : __base(in_place, _VSTD::forward<_Args>(__args)...) {}
708740
709 template <class _Up, class... _Args, class = _EnableIf<
741 template <class _Up, class... _Args, class = enable_if_t<
710742 is_constructible_v<value_type, initializer_list<_Up>&, _Args...>>
711743 >
712744 _LIBCPP_INLINE_VISIBILITY
713745 constexpr explicit optional(in_place_t, initializer_list<_Up> __il, _Args&&... __args)
714746 : __base(in_place, __il, _VSTD::forward<_Args>(__args)...) {}
715747
716 template <class _Up = value_type, _EnableIf<
748 template <class _Up = value_type, enable_if_t<
717749 _CheckOptionalArgsCtor<_Up>::template __enable_implicit<_Up>()
718750 , int> = 0>
719751 _LIBCPP_INLINE_VISIBILITY
720752 constexpr optional(_Up&& __v)
721753 : __base(in_place, _VSTD::forward<_Up>(__v)) {}
722754
723 template <class _Up, _EnableIf<
755 template <class _Up, enable_if_t<
724756 _CheckOptionalArgsCtor<_Up>::template __enable_explicit<_Up>()
725757 , int> = 0>
726758 _LIBCPP_INLINE_VISIBILITY
......@@ -728,7 +760,7 @@ public:
728760 : __base(in_place, _VSTD::forward<_Up>(__v)) {}
729761
730762 // LWG2756: conditionally explicit conversion from const optional<_Up>&
731 template <class _Up, _EnableIf<
763 template <class _Up, enable_if_t<
732764 _CheckOptionalLikeCtor<_Up, _Up const&>::template __enable_implicit<_Up>()
733765 , int> = 0>
734766 _LIBCPP_INLINE_VISIBILITY
......@@ -736,7 +768,7 @@ public:
736768 {
737769 this->__construct_from(__v);
738770 }
739 template <class _Up, _EnableIf<
771 template <class _Up, enable_if_t<
740772 _CheckOptionalLikeCtor<_Up, _Up const&>::template __enable_explicit<_Up>()
741773 , int> = 0>
742774 _LIBCPP_INLINE_VISIBILITY
......@@ -746,7 +778,7 @@ public:
746778 }
747779
748780 // LWG2756: conditionally explicit conversion from optional<_Up>&&
749 template <class _Up, _EnableIf<
781 template <class _Up, enable_if_t<
750782 _CheckOptionalLikeCtor<_Up, _Up &&>::template __enable_implicit<_Up>()
751783 , int> = 0>
752784 _LIBCPP_INLINE_VISIBILITY
......@@ -754,7 +786,7 @@ public:
754786 {
755787 this->__construct_from(_VSTD::move(__v));
756788 }
757 template <class _Up, _EnableIf<
789 template <class _Up, enable_if_t<
758790 _CheckOptionalLikeCtor<_Up, _Up &&>::template __enable_explicit<_Up>()
759791 , int> = 0>
760792 _LIBCPP_INLINE_VISIBILITY
......@@ -763,6 +795,14 @@ public:
763795 this->__construct_from(_VSTD::move(__v));
764796 }
765797
798#if _LIBCPP_STD_VER > 20
799 template<class _Fp, class... _Args>
800 _LIBCPP_HIDE_FROM_ABI
801 constexpr explicit optional(__optional_construct_from_invoke_tag, _Fp&& __f, _Args&&... __args)
802 : __base(__optional_construct_from_invoke_tag{}, _VSTD::forward<_Fp>(__f), _VSTD::forward<_Args>(__args)...) {
803 }
804#endif
805
766806 _LIBCPP_INLINE_VISIBILITY
767807 _LIBCPP_CONSTEXPR_AFTER_CXX17 optional& operator=(nullopt_t) noexcept
768808 {
......@@ -775,7 +815,7 @@ public:
775815
776816 // LWG2756
777817 template <class _Up = value_type,
778 class = _EnableIf<
818 class = enable_if_t<
779819 _And<
780820 _IsNotSame<__uncvref_t<_Up>, optional>,
781821 _Or<
......@@ -798,7 +838,7 @@ public:
798838 }
799839
800840 // LWG2756
801 template <class _Up, _EnableIf<
841 template <class _Up, enable_if_t<
802842 _CheckOptionalLikeAssign<_Up, _Up const&>::template __enable_assign<_Up>()
803843 , int> = 0>
804844 _LIBCPP_INLINE_VISIBILITY
......@@ -810,7 +850,7 @@ public:
810850 }
811851
812852 // LWG2756
813 template <class _Up, _EnableIf<
853 template <class _Up, enable_if_t<
814854 _CheckOptionalLikeCtor<_Up, _Up &&>::template __enable_assign<_Up>()
815855 , int> = 0>
816856 _LIBCPP_INLINE_VISIBILITY
......@@ -822,7 +862,7 @@ public:
822862 }
823863
824864 template <class... _Args,
825 class = _EnableIf
865 class = enable_if_t
826866 <
827867 is_constructible_v<value_type, _Args...>
828868 >
......@@ -837,7 +877,7 @@ public:
837877 }
838878
839879 template <class _Up, class... _Args,
840 class = _EnableIf
880 class = enable_if_t
841881 <
842882 is_constructible_v<value_type, initializer_list<_Up>&, _Args...>
843883 >
......@@ -883,11 +923,7 @@ public:
883923 operator->() const
884924 {
885925 _LIBCPP_ASSERT(this->has_value(), "optional operator-> called on a disengaged value");
886#ifndef _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF
887926 return _VSTD::addressof(this->__get());
888#else
889 return __operator_arrow(__has_operator_addressof<value_type>{}, this->__get());
890#endif
891927 }
892928
893929 _LIBCPP_INLINE_VISIBILITY
......@@ -896,11 +932,7 @@ public:
896932 operator->()
897933 {
898934 _LIBCPP_ASSERT(this->has_value(), "optional operator-> called on a disengaged value");
899#ifndef _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF
900935 return _VSTD::addressof(this->__get());
901#else
902 return __operator_arrow(__has_operator_addressof<value_type>{}, this->__get());
903#endif
904936 }
905937
906938 _LIBCPP_INLINE_VISIBILITY
......@@ -1005,35 +1037,144 @@ public:
10051037 static_cast<value_type>(_VSTD::forward<_Up>(__v));
10061038 }
10071039
1008 using __base::reset;
1009
1010private:
1011 template <class _Up>
1012 _LIBCPP_INLINE_VISIBILITY
1013 static _LIBCPP_CONSTEXPR_AFTER_CXX17 _Up*
1014 __operator_arrow(true_type, _Up& __x)
1015 {
1016 return _VSTD::addressof(__x);
1017 }
1040#if _LIBCPP_STD_VER > 20
1041 template<class _Func>
1042 _LIBCPP_HIDE_FROM_ABI
1043 constexpr auto and_then(_Func&& __f) & {
1044 using _Up = invoke_result_t<_Func, value_type&>;
1045 static_assert(__is_std_optional<remove_cvref_t<_Up>>::value,
1046 "Result of f(value()) must be a specialization of std::optional");
1047 if (*this)
1048 return _VSTD::invoke(_VSTD::forward<_Func>(__f), value());
1049 return remove_cvref_t<_Up>();
1050 }
1051
1052 template<class _Func>
1053 _LIBCPP_HIDE_FROM_ABI
1054 constexpr auto and_then(_Func&& __f) const& {
1055 using _Up = invoke_result_t<_Func, const value_type&>;
1056 static_assert(__is_std_optional<remove_cvref_t<_Up>>::value,
1057 "Result of f(value()) must be a specialization of std::optional");
1058 if (*this)
1059 return _VSTD::invoke(_VSTD::forward<_Func>(__f), value());
1060 return remove_cvref_t<_Up>();
1061 }
1062
1063 template<class _Func>
1064 _LIBCPP_HIDE_FROM_ABI
1065 constexpr auto and_then(_Func&& __f) && {
1066 using _Up = invoke_result_t<_Func, value_type&&>;
1067 static_assert(__is_std_optional<remove_cvref_t<_Up>>::value,
1068 "Result of f(std::move(value())) must be a specialization of std::optional");
1069 if (*this)
1070 return _VSTD::invoke(_VSTD::forward<_Func>(__f), _VSTD::move(value()));
1071 return remove_cvref_t<_Up>();
1072 }
1073
1074 template<class _Func>
1075 _LIBCPP_HIDE_FROM_ABI
1076 constexpr auto and_then(_Func&& __f) const&& {
1077 using _Up = invoke_result_t<_Func, const value_type&&>;
1078 static_assert(__is_std_optional<remove_cvref_t<_Up>>::value,
1079 "Result of f(std::move(value())) must be a specialization of std::optional");
1080 if (*this)
1081 return _VSTD::invoke(_VSTD::forward<_Func>(__f), _VSTD::move(value()));
1082 return remove_cvref_t<_Up>();
1083 }
1084
1085 template<class _Func>
1086 _LIBCPP_HIDE_FROM_ABI
1087 constexpr auto transform(_Func&& __f) & {
1088 using _Up = remove_cv_t<invoke_result_t<_Func, value_type&>>;
1089 static_assert(!is_array_v<_Up>, "Result of f(value()) should not be an Array");
1090 static_assert(!is_same_v<_Up, in_place_t>,
1091 "Result of f(value()) should not be std::in_place_t");
1092 static_assert(!is_same_v<_Up, nullopt_t>,
1093 "Result of f(value()) should not be std::nullopt_t");
1094 static_assert(is_object_v<_Up>, "Result of f(value()) should be an object type");
1095 if (*this)
1096 return optional<_Up>(__optional_construct_from_invoke_tag{}, _VSTD::forward<_Func>(__f), value());
1097 return optional<_Up>();
1098 }
1099
1100 template<class _Func>
1101 _LIBCPP_HIDE_FROM_ABI
1102 constexpr auto transform(_Func&& __f) const& {
1103 using _Up = remove_cv_t<invoke_result_t<_Func, const value_type&>>;
1104 static_assert(!is_array_v<_Up>, "Result of f(value()) should not be an Array");
1105 static_assert(!is_same_v<_Up, in_place_t>,
1106 "Result of f(value()) should not be std::in_place_t");
1107 static_assert(!is_same_v<_Up, nullopt_t>,
1108 "Result of f(value()) should not be std::nullopt_t");
1109 static_assert(is_object_v<_Up>, "Result of f(value()) should be an object type");
1110 if (*this)
1111 return optional<_Up>(__optional_construct_from_invoke_tag{}, _VSTD::forward<_Func>(__f), value());
1112 return optional<_Up>();
1113 }
1114
1115 template<class _Func>
1116 _LIBCPP_HIDE_FROM_ABI
1117 constexpr auto transform(_Func&& __f) && {
1118 using _Up = remove_cv_t<invoke_result_t<_Func, value_type&&>>;
1119 static_assert(!is_array_v<_Up>, "Result of f(std::move(value())) should not be an Array");
1120 static_assert(!is_same_v<_Up, in_place_t>,
1121 "Result of f(std::move(value())) should not be std::in_place_t");
1122 static_assert(!is_same_v<_Up, nullopt_t>,
1123 "Result of f(std::move(value())) should not be std::nullopt_t");
1124 static_assert(is_object_v<_Up>, "Result of f(std::move(value())) should be an object type");
1125 if (*this)
1126 return optional<_Up>(__optional_construct_from_invoke_tag{}, _VSTD::forward<_Func>(__f), _VSTD::move(value()));
1127 return optional<_Up>();
1128 }
1129
1130 template<class _Func>
1131 _LIBCPP_HIDE_FROM_ABI
1132 constexpr auto transform(_Func&& __f) const&& {
1133 using _Up = remove_cvref_t<invoke_result_t<_Func, const value_type&&>>;
1134 static_assert(!is_array_v<_Up>, "Result of f(std::move(value())) should not be an Array");
1135 static_assert(!is_same_v<_Up, in_place_t>,
1136 "Result of f(std::move(value())) should not be std::in_place_t");
1137 static_assert(!is_same_v<_Up, nullopt_t>,
1138 "Result of f(std::move(value())) should not be std::nullopt_t");
1139 static_assert(is_object_v<_Up>, "Result of f(std::move(value())) should be an object type");
1140 if (*this)
1141 return optional<_Up>(__optional_construct_from_invoke_tag{}, _VSTD::forward<_Func>(__f), _VSTD::move(value()));
1142 return optional<_Up>();
1143 }
1144
1145 template<invocable _Func>
1146 _LIBCPP_HIDE_FROM_ABI
1147 constexpr optional or_else(_Func&& __f) const& requires is_copy_constructible_v<value_type> {
1148 static_assert(is_same_v<remove_cvref_t<invoke_result_t<_Func>>, optional>,
1149 "Result of f() should be the same type as this optional");
1150 if (*this)
1151 return *this;
1152 return _VSTD::forward<_Func>(__f)();
1153 }
1154
1155 template<invocable _Func>
1156 _LIBCPP_HIDE_FROM_ABI
1157 constexpr optional or_else(_Func&& __f) && requires is_move_constructible_v<value_type> {
1158 static_assert(is_same_v<remove_cvref_t<invoke_result_t<_Func>>, optional>,
1159 "Result of f() should be the same type as this optional");
1160 if (*this)
1161 return _VSTD::move(*this);
1162 return _VSTD::forward<_Func>(__f)();
1163 }
1164#endif // _LIBCPP_STD_VER > 20
10181165
1019 template <class _Up>
1020 _LIBCPP_INLINE_VISIBILITY
1021 static constexpr _Up*
1022 __operator_arrow(false_type, _Up& __x)
1023 {
1024 return &__x;
1025 }
1166 using __base::reset;
10261167};
10271168
1028#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
1029template<class T>
1030 optional(T) -> optional<T>;
1169#if _LIBCPP_STD_VER >= 17
1170template<class _Tp>
1171 optional(_Tp) -> optional<_Tp>;
10311172#endif
10321173
10331174// Comparisons between optionals
10341175template <class _Tp, class _Up>
10351176_LIBCPP_INLINE_VISIBILITY constexpr
1036_EnableIf<
1177enable_if_t<
10371178 is_convertible_v<decltype(declval<const _Tp&>() ==
10381179 declval<const _Up&>()), bool>,
10391180 bool
......@@ -1049,7 +1190,7 @@ operator==(const optional<_Tp>& __x, const optional<_Up>& __y)
10491190
10501191template <class _Tp, class _Up>
10511192_LIBCPP_INLINE_VISIBILITY constexpr
1052_EnableIf<
1193enable_if_t<
10531194 is_convertible_v<decltype(declval<const _Tp&>() !=
10541195 declval<const _Up&>()), bool>,
10551196 bool
......@@ -1065,7 +1206,7 @@ operator!=(const optional<_Tp>& __x, const optional<_Up>& __y)
10651206
10661207template <class _Tp, class _Up>
10671208_LIBCPP_INLINE_VISIBILITY constexpr
1068_EnableIf<
1209enable_if_t<
10691210 is_convertible_v<decltype(declval<const _Tp&>() <
10701211 declval<const _Up&>()), bool>,
10711212 bool
......@@ -1081,7 +1222,7 @@ operator<(const optional<_Tp>& __x, const optional<_Up>& __y)
10811222
10821223template <class _Tp, class _Up>
10831224_LIBCPP_INLINE_VISIBILITY constexpr
1084_EnableIf<
1225enable_if_t<
10851226 is_convertible_v<decltype(declval<const _Tp&>() >
10861227 declval<const _Up&>()), bool>,
10871228 bool
......@@ -1097,7 +1238,7 @@ operator>(const optional<_Tp>& __x, const optional<_Up>& __y)
10971238
10981239template <class _Tp, class _Up>
10991240_LIBCPP_INLINE_VISIBILITY constexpr
1100_EnableIf<
1241enable_if_t<
11011242 is_convertible_v<decltype(declval<const _Tp&>() <=
11021243 declval<const _Up&>()), bool>,
11031244 bool
......@@ -1113,7 +1254,7 @@ operator<=(const optional<_Tp>& __x, const optional<_Up>& __y)
11131254
11141255template <class _Tp, class _Up>
11151256_LIBCPP_INLINE_VISIBILITY constexpr
1116_EnableIf<
1257enable_if_t<
11171258 is_convertible_v<decltype(declval<const _Tp&>() >=
11181259 declval<const _Up&>()), bool>,
11191260 bool
......@@ -1227,7 +1368,7 @@ operator>=(nullopt_t, const optional<_Tp>& __x) noexcept
12271368// Comparisons with T
12281369template <class _Tp, class _Up>
12291370_LIBCPP_INLINE_VISIBILITY constexpr
1230_EnableIf<
1371enable_if_t<
12311372 is_convertible_v<decltype(declval<const _Tp&>() ==
12321373 declval<const _Up&>()), bool>,
12331374 bool
......@@ -1239,7 +1380,7 @@ operator==(const optional<_Tp>& __x, const _Up& __v)
12391380
12401381template <class _Tp, class _Up>
12411382_LIBCPP_INLINE_VISIBILITY constexpr
1242_EnableIf<
1383enable_if_t<
12431384 is_convertible_v<decltype(declval<const _Tp&>() ==
12441385 declval<const _Up&>()), bool>,
12451386 bool
......@@ -1251,7 +1392,7 @@ operator==(const _Tp& __v, const optional<_Up>& __x)
12511392
12521393template <class _Tp, class _Up>
12531394_LIBCPP_INLINE_VISIBILITY constexpr
1254_EnableIf<
1395enable_if_t<
12551396 is_convertible_v<decltype(declval<const _Tp&>() !=
12561397 declval<const _Up&>()), bool>,
12571398 bool
......@@ -1263,7 +1404,7 @@ operator!=(const optional<_Tp>& __x, const _Up& __v)
12631404
12641405template <class _Tp, class _Up>
12651406_LIBCPP_INLINE_VISIBILITY constexpr
1266_EnableIf<
1407enable_if_t<
12671408 is_convertible_v<decltype(declval<const _Tp&>() !=
12681409 declval<const _Up&>()), bool>,
12691410 bool
......@@ -1275,7 +1416,7 @@ operator!=(const _Tp& __v, const optional<_Up>& __x)
12751416
12761417template <class _Tp, class _Up>
12771418_LIBCPP_INLINE_VISIBILITY constexpr
1278_EnableIf<
1419enable_if_t<
12791420 is_convertible_v<decltype(declval<const _Tp&>() <
12801421 declval<const _Up&>()), bool>,
12811422 bool
......@@ -1287,7 +1428,7 @@ operator<(const optional<_Tp>& __x, const _Up& __v)
12871428
12881429template <class _Tp, class _Up>
12891430_LIBCPP_INLINE_VISIBILITY constexpr
1290_EnableIf<
1431enable_if_t<
12911432 is_convertible_v<decltype(declval<const _Tp&>() <
12921433 declval<const _Up&>()), bool>,
12931434 bool
......@@ -1299,7 +1440,7 @@ operator<(const _Tp& __v, const optional<_Up>& __x)
12991440
13001441template <class _Tp, class _Up>
13011442_LIBCPP_INLINE_VISIBILITY constexpr
1302_EnableIf<
1443enable_if_t<
13031444 is_convertible_v<decltype(declval<const _Tp&>() <=
13041445 declval<const _Up&>()), bool>,
13051446 bool
......@@ -1311,7 +1452,7 @@ operator<=(const optional<_Tp>& __x, const _Up& __v)
13111452
13121453template <class _Tp, class _Up>
13131454_LIBCPP_INLINE_VISIBILITY constexpr
1314_EnableIf<
1455enable_if_t<
13151456 is_convertible_v<decltype(declval<const _Tp&>() <=
13161457 declval<const _Up&>()), bool>,
13171458 bool
......@@ -1323,7 +1464,7 @@ operator<=(const _Tp& __v, const optional<_Up>& __x)
13231464
13241465template <class _Tp, class _Up>
13251466_LIBCPP_INLINE_VISIBILITY constexpr
1326_EnableIf<
1467enable_if_t<
13271468 is_convertible_v<decltype(declval<const _Tp&>() >
13281469 declval<const _Up&>()), bool>,
13291470 bool
......@@ -1335,7 +1476,7 @@ operator>(const optional<_Tp>& __x, const _Up& __v)
13351476
13361477template <class _Tp, class _Up>
13371478_LIBCPP_INLINE_VISIBILITY constexpr
1338_EnableIf<
1479enable_if_t<
13391480 is_convertible_v<decltype(declval<const _Tp&>() >
13401481 declval<const _Up&>()), bool>,
13411482 bool
......@@ -1347,7 +1488,7 @@ operator>(const _Tp& __v, const optional<_Up>& __x)
13471488
13481489template <class _Tp, class _Up>
13491490_LIBCPP_INLINE_VISIBILITY constexpr
1350_EnableIf<
1491enable_if_t<
13511492 is_convertible_v<decltype(declval<const _Tp&>() >=
13521493 declval<const _Up&>()), bool>,
13531494 bool
......@@ -1359,7 +1500,7 @@ operator>=(const optional<_Tp>& __x, const _Up& __v)
13591500
13601501template <class _Tp, class _Up>
13611502_LIBCPP_INLINE_VISIBILITY constexpr
1362_EnableIf<
1503enable_if_t<
13631504 is_convertible_v<decltype(declval<const _Tp&>() >=
13641505 declval<const _Up&>()), bool>,
13651506 bool
......@@ -1372,7 +1513,7 @@ operator>=(const _Tp& __v, const optional<_Up>& __x)
13721513
13731514template <class _Tp>
13741515inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1375_EnableIf<
1516enable_if_t<
13761517 is_move_constructible_v<_Tp> && is_swappable_v<_Tp>,
13771518 void
13781519>
......@@ -1423,6 +1564,4 @@ _LIBCPP_END_NAMESPACE_STD
14231564
14241565#endif // _LIBCPP_STD_VER > 14
14251566
1426_LIBCPP_POP_MACROS
1427
14281567#endif // _LIBCPP_OPTIONAL
lib/libcxx/include/ostream+14-4
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===-------------------------- ostream -----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -55,6 +55,7 @@ public:
5555 basic_ostream& operator<<(double f);
5656 basic_ostream& operator<<(long double f);
5757 basic_ostream& operator<<(const void* p);
58 basic_ostream& operator<<(const volatile void* val); // C++23
5859 basic_ostream& operator<<(basic_streambuf<char_type,traits>* sb);
5960 basic_ostream& operator<<(nullptr_t);
6061
......@@ -210,6 +211,14 @@ public:
210211 basic_ostream& operator<<(double __f);
211212 basic_ostream& operator<<(long double __f);
212213 basic_ostream& operator<<(const void* __p);
214
215#if _LIBCPP_STD_VER > 20
216 _LIBCPP_HIDE_FROM_ABI
217 basic_ostream& operator<<(const volatile void* __p) {
218 return operator<<(const_cast<const void*>(__p));
219 }
220#endif
221
213222 basic_ostream& operator<<(basic_streambuf<char_type, traits_type>* __sb);
214223
215224 _LIBCPP_INLINE_VISIBILITY
......@@ -240,12 +249,11 @@ class _LIBCPP_TEMPLATE_VIS basic_ostream<_CharT, _Traits>::sentry
240249 bool __ok_;
241250 basic_ostream<_CharT, _Traits>& __os_;
242251
243 sentry(const sentry&); // = delete;
244 sentry& operator=(const sentry&); // = delete;
245
246252public:
247253 explicit sentry(basic_ostream<_CharT, _Traits>& __os);
248254 ~sentry();
255 sentry(const sentry&) = delete;
256 sentry& operator=(const sentry&) = delete;
249257
250258 _LIBCPP_INLINE_VISIBILITY
251259 explicit operator bool() const {return __ok_;}
......@@ -1087,7 +1095,9 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x)
10871095}
10881096
10891097_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<char>)
1098#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
10901099_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<wchar_t>)
1100#endif
10911101
10921102_LIBCPP_END_NAMESPACE_STD
10931103
lib/libcxx/include/queue+224-49
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- queue ------------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -41,6 +41,8 @@ public:
4141
4242 explicit queue(const container_type& c);
4343 explicit queue(container_type&& c)
44 template<class InputIterator>
45 queue(InputIterator first, InputIterator last); // since C++23
4446 template <class Alloc>
4547 explicit queue(const Alloc& a);
4648 template <class Alloc>
......@@ -51,6 +53,8 @@ public:
5153 queue(const queue& q, const Alloc& a);
5254 template <class Alloc>
5355 queue(queue&& q, const Alloc& a);
56 template <class InputIterator, class Alloc>
57 queue(InputIterator first, InputIterator last, const Alloc&); // since C++23
5458
5559 bool empty() const;
5660 size_type size() const;
......@@ -71,9 +75,17 @@ public:
7175template<class Container>
7276 queue(Container) -> queue<typename Container::value_type, Container>; // C++17
7377
78template<class InputIterator>
79 queue(InputIterator, InputIterator) -> queue<iter-value-type<InputIterator>>; // since C++23
80
7481template<class Container, class Allocator>
7582 queue(Container, Allocator) -> queue<typename Container::value_type, Container>; // C++17
7683
84template<class InputIterator, class Allocator>
85 queue(InputIterator, InputIterator, Allocator)
86 -> queue<iter-value-type<InputIterator>,
87 deque<iter-value-type<InputIterator>, Allocator>>; // since C++23
88
7789template <class T, class Container>
7890 bool operator==(const queue<T, Container>& x,const queue<T, Container>& y);
7991
......@@ -115,27 +127,39 @@ public:
115127 priority_queue() : priority_queue(Compare()) {} // C++20
116128 explicit priority_queue(const Compare& x) : priority_queue(x, Container()) {}
117129 priority_queue(const Compare& x, const Container&);
118 explicit priority_queue(const Compare& x = Compare(), Container&&= Container()); // before C++20
130 explicit priority_queue(const Compare& x = Compare(), Container&& = Container()); // before C++20
119131 priority_queue(const Compare& x, Container&&); // C++20
120132 template <class InputIterator>
121133 priority_queue(InputIterator first, InputIterator last,
122134 const Compare& comp = Compare());
123135 template <class InputIterator>
124136 priority_queue(InputIterator first, InputIterator last,
125 const Compare& comp, const container_type& c);
137 const Compare& comp, const Container& c);
126138 template <class InputIterator>
127139 priority_queue(InputIterator first, InputIterator last,
128 const Compare& comp, container_type&& c);
140 const Compare& comp, Container&& c);
129141 template <class Alloc>
130142 explicit priority_queue(const Alloc& a);
131143 template <class Alloc>
132144 priority_queue(const Compare& comp, const Alloc& a);
133145 template <class Alloc>
134 priority_queue(const Compare& comp, const container_type& c,
146 priority_queue(const Compare& comp, const Container& c,
135147 const Alloc& a);
136148 template <class Alloc>
137 priority_queue(const Compare& comp, container_type&& c,
149 priority_queue(const Compare& comp, Container&& c,
138150 const Alloc& a);
151 template <class InputIterator>
152 priority_queue(InputIterator first, InputIterator last,
153 const Alloc& a);
154 template <class InputIterator>
155 priority_queue(InputIterator first, InputIterator last,
156 const Compare& comp, const Alloc& a);
157 template <class InputIterator>
158 priority_queue(InputIterator first, InputIterator last,
159 const Compare& comp, const Container& c, const Alloc& a);
160 template <class InputIterator>
161 priority_queue(InputIterator first, InputIterator last,
162 const Compare& comp, Container&& c, const Alloc& a);
139163 template <class Alloc>
140164 priority_queue(const priority_queue& q, const Alloc& a);
141165 template <class Alloc>
......@@ -160,15 +184,30 @@ priority_queue(Compare, Container)
160184 -> priority_queue<typename Container::value_type, Container, Compare>; // C++17
161185
162186template<class InputIterator,
163 class Compare = less<typename iterator_traits<InputIterator>::value_type>,
164 class Container = vector<typename iterator_traits<InputIterator>::value_type>>
187 class Compare = less<iter-value-type<InputIterator>>,
188 class Container = vector<iter-value-type<InputIterator>>>
165189priority_queue(InputIterator, InputIterator, Compare = Compare(), Container = Container())
166 -> priority_queue<typename iterator_traits<InputIterator>::value_type, Container, Compare>; // C++17
190 -> priority_queue<iter-value-type<InputIterator>, Container, Compare>; // C++17
167191
168192template<class Compare, class Container, class Allocator>
169193priority_queue(Compare, Container, Allocator)
170194 -> priority_queue<typename Container::value_type, Container, Compare>; // C++17
171195
196template<class InputIterator, class Allocator>
197priority_queue(InputIterator, InputIterator, Allocator)
198 -> priority_queue<iter-value-type<InputIterator>,
199 vector<iter-value-type<InputIterator>, Allocator>,
200 less<iter-value-type<InputIterator>>>; // C++17
201
202template<class InputIterator, class Compare, class Allocator>
203priority_queue(InputIterator, InputIterator, Compare, Allocator)
204 -> priority_queue<iter-value-type<InputIterator>,
205 vector<iter-value-type<InputIterator>, Allocator>, Compare>; // C++17
206
207template<class InputIterator, class Compare, class Container, class Allocator>
208priority_queue(InputIterator, InputIterator, Compare, Container, Allocator)
209 -> priority_queue<typename Container::value_type, Container, Compare>; // C++17
210
172211template <class T, class Container, class Compare>
173212 void swap(priority_queue<T, Container, Compare>& x,
174213 priority_queue<T, Container, Compare>& y)
......@@ -179,13 +218,16 @@ template <class T, class Container, class Compare>
179218*/
180219
181220#include <__config>
221#include <__iterator/iterator_traits.h>
182222#include <__memory/uses_allocator.h>
183223#include <__utility/forward.h>
184224#include <algorithm>
185225#include <compare>
186226#include <deque>
187227#include <functional>
228#include <type_traits>
188229#include <vector>
230#include <version>
189231
190232#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
191233#pragma GCC system_header
......@@ -228,6 +270,20 @@ public:
228270 _LIBCPP_INLINE_VISIBILITY
229271 queue(const queue& __q) : c(__q.c) {}
230272
273#if _LIBCPP_STD_VER > 20
274 template <class _InputIterator,
275 class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>>
276 _LIBCPP_HIDE_FROM_ABI
277 queue(_InputIterator __first, _InputIterator __last) : c(__first, __last) {}
278
279 template <class _InputIterator,
280 class _Alloc,
281 class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
282 class = __enable_if_t<uses_allocator<container_type, _Alloc>::value>>
283 _LIBCPP_HIDE_FROM_ABI
284 queue(_InputIterator __first, _InputIterator __second, const _Alloc& __alloc) : c(__first, __second, __alloc) {}
285#endif
286
231287 _LIBCPP_INLINE_VISIBILITY
232288 queue& operator=(const queue& __q) {c = __q.c; return *this;}
233289
......@@ -252,28 +308,28 @@ public:
252308 template <class _Alloc>
253309 _LIBCPP_INLINE_VISIBILITY
254310 explicit queue(const _Alloc& __a,
255 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0)
311 __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
256312 : c(__a) {}
257313 template <class _Alloc>
258314 _LIBCPP_INLINE_VISIBILITY
259315 queue(const queue& __q, const _Alloc& __a,
260 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0)
316 __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
261317 : c(__q.c, __a) {}
262318 template <class _Alloc>
263319 _LIBCPP_INLINE_VISIBILITY
264320 queue(const container_type& __c, const _Alloc& __a,
265 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0)
321 __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
266322 : c(__c, __a) {}
267323#ifndef _LIBCPP_CXX03_LANG
268324 template <class _Alloc>
269325 _LIBCPP_INLINE_VISIBILITY
270326 queue(container_type&& __c, const _Alloc& __a,
271 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0)
327 __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
272328 : c(_VSTD::move(__c), __a) {}
273329 template <class _Alloc>
274330 _LIBCPP_INLINE_VISIBILITY
275331 queue(queue&& __q, const _Alloc& __a,
276 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0)
332 __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
277333 : c(_VSTD::move(__q.c), __a) {}
278334
279335#endif // _LIBCPP_CXX03_LANG
......@@ -331,22 +387,36 @@ public:
331387 operator< (const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
332388};
333389
334#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
390#if _LIBCPP_STD_VER > 14
335391template<class _Container,
336 class = _EnableIf<!__is_allocator<_Container>::value>
392 class = enable_if_t<!__is_allocator<_Container>::value>
337393>
338394queue(_Container)
339395 -> queue<typename _Container::value_type, _Container>;
340396
341397template<class _Container,
342398 class _Alloc,
343 class = _EnableIf<!__is_allocator<_Container>::value>,
344 class = _EnableIf<uses_allocator<_Container, _Alloc>::value>
399 class = enable_if_t<!__is_allocator<_Container>::value>,
400 class = enable_if_t<uses_allocator<_Container, _Alloc>::value>
345401>
346402queue(_Container, _Alloc)
347403 -> queue<typename _Container::value_type, _Container>;
348404#endif
349405
406#if _LIBCPP_STD_VER > 20
407template <class _InputIterator,
408 class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>>
409queue(_InputIterator, _InputIterator)
410 -> queue<__iter_value_type<_InputIterator>>;
411
412template <class _InputIterator,
413 class _Alloc,
414 class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
415 class = __enable_if_t<__is_allocator<_Alloc>::value>>
416queue(_InputIterator, _InputIterator, _Alloc)
417 -> queue<__iter_value_type<_InputIterator>, deque<__iter_value_type<_InputIterator>, _Alloc>>;
418#endif
419
350420template <class _Tp, class _Container>
351421inline _LIBCPP_INLINE_VISIBILITY
352422bool
......@@ -397,7 +467,7 @@ operator<=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
397467
398468template <class _Tp, class _Container>
399469inline _LIBCPP_INLINE_VISIBILITY
400_EnableIf<__is_swappable<_Container>::value, void>
470__enable_if_t<__is_swappable<_Container>::value, void>
401471swap(queue<_Tp, _Container>& __x, queue<_Tp, _Container>& __y)
402472 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
403473{
......@@ -464,16 +534,16 @@ public:
464534 _LIBCPP_INLINE_VISIBILITY
465535 priority_queue(const value_compare& __comp, container_type&& __c);
466536#endif
467 template <class _InputIter>
537 template <class _InputIter, class = __enable_if_t<__is_cpp17_input_iterator<_InputIter>::value> >
468538 _LIBCPP_INLINE_VISIBILITY
469539 priority_queue(_InputIter __f, _InputIter __l,
470540 const value_compare& __comp = value_compare());
471 template <class _InputIter>
541 template <class _InputIter, class = __enable_if_t<__is_cpp17_input_iterator<_InputIter>::value> >
472542 _LIBCPP_INLINE_VISIBILITY
473543 priority_queue(_InputIter __f, _InputIter __l,
474544 const value_compare& __comp, const container_type& __c);
475545#ifndef _LIBCPP_CXX03_LANG
476 template <class _InputIter>
546 template <class _InputIter, class = __enable_if_t<__is_cpp17_input_iterator<_InputIter>::value> >
477547 _LIBCPP_INLINE_VISIBILITY
478548 priority_queue(_InputIter __f, _InputIter __l,
479549 const value_compare& __comp, container_type&& __c);
......@@ -481,32 +551,57 @@ public:
481551 template <class _Alloc>
482552 _LIBCPP_INLINE_VISIBILITY
483553 explicit priority_queue(const _Alloc& __a,
484 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0);
554 __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
485555 template <class _Alloc>
486556 _LIBCPP_INLINE_VISIBILITY
487557 priority_queue(const value_compare& __comp, const _Alloc& __a,
488 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0);
558 __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
489559 template <class _Alloc>
490560 _LIBCPP_INLINE_VISIBILITY
491561 priority_queue(const value_compare& __comp, const container_type& __c,
492562 const _Alloc& __a,
493 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0);
563 __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
494564 template <class _Alloc>
495565 _LIBCPP_INLINE_VISIBILITY
496566 priority_queue(const priority_queue& __q, const _Alloc& __a,
497 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0);
567 __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
498568#ifndef _LIBCPP_CXX03_LANG
499569 template <class _Alloc>
500570 _LIBCPP_INLINE_VISIBILITY
501571 priority_queue(const value_compare& __comp, container_type&& __c,
502572 const _Alloc& __a,
503 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0);
573 __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
504574 template <class _Alloc>
505575 _LIBCPP_INLINE_VISIBILITY
506576 priority_queue(priority_queue&& __q, const _Alloc& __a,
507 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0);
577 __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
508578#endif // _LIBCPP_CXX03_LANG
509579
580 template <class _InputIter, class _Alloc, class = __enable_if_t<__is_cpp17_input_iterator<_InputIter>::value> >
581 _LIBCPP_INLINE_VISIBILITY
582 priority_queue(_InputIter __f, _InputIter __l, const _Alloc& __a,
583 __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
584
585 template <class _InputIter, class _Alloc, class = __enable_if_t<__is_cpp17_input_iterator<_InputIter>::value> >
586 _LIBCPP_INLINE_VISIBILITY
587 priority_queue(_InputIter __f, _InputIter __l,
588 const value_compare& __comp, const _Alloc& __a,
589 __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
590
591 template <class _InputIter, class _Alloc, class = __enable_if_t<__is_cpp17_input_iterator<_InputIter>::value> >
592 _LIBCPP_INLINE_VISIBILITY
593 priority_queue(_InputIter __f, _InputIter __l,
594 const value_compare& __comp, const container_type& __c, const _Alloc& __a,
595 __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
596
597#ifndef _LIBCPP_CXX03_LANG
598 template <class _InputIter, class _Alloc, class = __enable_if_t<__is_cpp17_input_iterator<_InputIter>::value> >
599 _LIBCPP_INLINE_VISIBILITY
600 priority_queue(_InputIter __f, _InputIter __l,
601 const value_compare& __comp, container_type&& __c, const _Alloc& __a,
602 __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
603#endif // _LIBCPP_CXX03_LANG
604
510605 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
511606 bool empty() const {return c.empty();}
512607 _LIBCPP_INLINE_VISIBILITY
......@@ -532,11 +627,11 @@ public:
532627 __is_nothrow_swappable<value_compare>::value);
533628};
534629
535#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
630#if _LIBCPP_STD_VER >= 17
536631template <class _Compare,
537632 class _Container,
538 class = _EnableIf<!__is_allocator<_Compare>::value>,
539 class = _EnableIf<!__is_allocator<_Container>::value>
633 class = enable_if_t<!__is_allocator<_Compare>::value>,
634 class = enable_if_t<!__is_allocator<_Container>::value>
540635>
541636priority_queue(_Compare, _Container)
542637 -> priority_queue<typename _Container::value_type, _Container, _Compare>;
......@@ -544,9 +639,9 @@ priority_queue(_Compare, _Container)
544639template<class _InputIterator,
545640 class _Compare = less<__iter_value_type<_InputIterator>>,
546641 class _Container = vector<__iter_value_type<_InputIterator>>,
547 class = _EnableIf<__is_cpp17_input_iterator<_InputIterator>::value>,
548 class = _EnableIf<!__is_allocator<_Compare>::value>,
549 class = _EnableIf<!__is_allocator<_Container>::value>
642 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
643 class = enable_if_t<!__is_allocator<_Compare>::value>,
644 class = enable_if_t<!__is_allocator<_Container>::value>
550645>
551646priority_queue(_InputIterator, _InputIterator, _Compare = _Compare(), _Container = _Container())
552647 -> priority_queue<__iter_value_type<_InputIterator>, _Container, _Compare>;
......@@ -554,12 +649,39 @@ priority_queue(_InputIterator, _InputIterator, _Compare = _Compare(), _Container
554649template<class _Compare,
555650 class _Container,
556651 class _Alloc,
557 class = _EnableIf<!__is_allocator<_Compare>::value>,
558 class = _EnableIf<!__is_allocator<_Container>::value>,
559 class = _EnableIf<uses_allocator<_Container, _Alloc>::value>
652 class = enable_if_t<!__is_allocator<_Compare>::value>,
653 class = enable_if_t<!__is_allocator<_Container>::value>,
654 class = enable_if_t<uses_allocator<_Container, _Alloc>::value>
560655>
561656priority_queue(_Compare, _Container, _Alloc)
562657 -> priority_queue<typename _Container::value_type, _Container, _Compare>;
658
659template<class _InputIterator, class _Allocator,
660 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
661 class = enable_if_t<__is_allocator<_Allocator>::value>
662>
663priority_queue(_InputIterator, _InputIterator, _Allocator)
664 -> priority_queue<__iter_value_type<_InputIterator>,
665 vector<__iter_value_type<_InputIterator>, _Allocator>,
666 less<__iter_value_type<_InputIterator>>>;
667
668template<class _InputIterator, class _Compare, class _Allocator,
669 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
670 class = enable_if_t<!__is_allocator<_Compare>::value>,
671 class = enable_if_t<__is_allocator<_Allocator>::value>
672>
673priority_queue(_InputIterator, _InputIterator, _Compare, _Allocator)
674 -> priority_queue<__iter_value_type<_InputIterator>,
675 vector<__iter_value_type<_InputIterator>, _Allocator>, _Compare>;
676
677template<class _InputIterator, class _Compare, class _Container, class _Alloc,
678 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
679 class = enable_if_t<!__is_allocator<_Compare>::value>,
680 class = enable_if_t<!__is_allocator<_Container>::value>,
681 class = enable_if_t<uses_allocator<_Container, _Alloc>::value>
682>
683priority_queue(_InputIterator, _InputIterator, _Compare, _Container, _Alloc)
684 -> priority_queue<typename _Container::value_type, _Container, _Compare>;
563685#endif
564686
565687template <class _Tp, class _Container, class _Compare>
......@@ -587,7 +709,7 @@ priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& _
587709#endif // _LIBCPP_CXX03_LANG
588710
589711template <class _Tp, class _Container, class _Compare>
590template <class _InputIter>
712template <class _InputIter, class>
591713inline
592714priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
593715 const value_compare& __comp)
......@@ -598,7 +720,7 @@ priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _Input
598720}
599721
600722template <class _Tp, class _Container, class _Compare>
601template <class _InputIter>
723template <class _InputIter, class>
602724inline
603725priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
604726 const value_compare& __comp,
......@@ -613,7 +735,7 @@ priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _Input
613735#ifndef _LIBCPP_CXX03_LANG
614736
615737template <class _Tp, class _Container, class _Compare>
616template <class _InputIter>
738template <class _InputIter, class>
617739inline
618740priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
619741 const value_compare& __comp,
......@@ -631,7 +753,7 @@ template <class _Tp, class _Container, class _Compare>
631753template <class _Alloc>
632754inline
633755priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Alloc& __a,
634 _EnableIf<uses_allocator<container_type, _Alloc>::value>*)
756 __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
635757 : c(__a)
636758{
637759}
......@@ -641,7 +763,7 @@ template <class _Alloc>
641763inline
642764priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
643765 const _Alloc& __a,
644 _EnableIf<uses_allocator<container_type, _Alloc>::value>*)
766 __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
645767 : c(__a),
646768 comp(__comp)
647769{
......@@ -653,7 +775,7 @@ inline
653775priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
654776 const container_type& __c,
655777 const _Alloc& __a,
656 _EnableIf<uses_allocator<container_type, _Alloc>::value>*)
778 __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
657779 : c(__c, __a),
658780 comp(__comp)
659781{
......@@ -665,11 +787,10 @@ template <class _Alloc>
665787inline
666788priority_queue<_Tp, _Container, _Compare>::priority_queue(const priority_queue& __q,
667789 const _Alloc& __a,
668 _EnableIf<uses_allocator<container_type, _Alloc>::value>*)
790 __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
669791 : c(__q.c, __a),
670792 comp(__q.comp)
671793{
672 _VSTD::make_heap(c.begin(), c.end(), comp);
673794}
674795
675796#ifndef _LIBCPP_CXX03_LANG
......@@ -680,7 +801,7 @@ inline
680801priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
681802 container_type&& __c,
682803 const _Alloc& __a,
683 _EnableIf<uses_allocator<container_type, _Alloc>::value>*)
804 __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
684805 : c(_VSTD::move(__c), __a),
685806 comp(__comp)
686807{
......@@ -692,14 +813,68 @@ template <class _Alloc>
692813inline
693814priority_queue<_Tp, _Container, _Compare>::priority_queue(priority_queue&& __q,
694815 const _Alloc& __a,
695 _EnableIf<uses_allocator<container_type, _Alloc>::value>*)
816 __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
696817 : c(_VSTD::move(__q.c), __a),
697818 comp(_VSTD::move(__q.comp))
819{
820}
821
822#endif // _LIBCPP_CXX03_LANG
823
824template <class _Tp, class _Container, class _Compare>
825template <class _InputIter, class _Alloc, class>
826inline
827priority_queue<_Tp, _Container, _Compare>::priority_queue(
828 _InputIter __f, _InputIter __l, const _Alloc& __a,
829 __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
830 : c(__f, __l, __a),
831 comp()
698832{
699833 _VSTD::make_heap(c.begin(), c.end(), comp);
700834}
701835
702#endif // _LIBCPP_CXX03_LANG
836template <class _Tp, class _Container, class _Compare>
837template <class _InputIter, class _Alloc, class>
838inline
839priority_queue<_Tp, _Container, _Compare>::priority_queue(
840 _InputIter __f, _InputIter __l,
841 const value_compare& __comp, const _Alloc& __a,
842 __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
843 : c(__f, __l, __a),
844 comp(__comp)
845{
846 _VSTD::make_heap(c.begin(), c.end(), comp);
847}
848
849template <class _Tp, class _Container, class _Compare>
850template <class _InputIter, class _Alloc, class>
851inline
852priority_queue<_Tp, _Container, _Compare>::priority_queue(
853 _InputIter __f, _InputIter __l,
854 const value_compare& __comp, const container_type& __c, const _Alloc& __a,
855 __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
856 : c(__c, __a),
857 comp(__comp)
858{
859 c.insert(c.end(), __f, __l);
860 _VSTD::make_heap(c.begin(), c.end(), comp);
861}
862
863#ifndef _LIBCPP_CXX03_LANG
864template <class _Tp, class _Container, class _Compare>
865template <class _InputIter, class _Alloc, class>
866inline
867priority_queue<_Tp, _Container, _Compare>::priority_queue(
868 _InputIter __f, _InputIter __l, const value_compare& __comp,
869 container_type&& __c, const _Alloc& __a,
870 __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
871 : c(_VSTD::move(__c), __a),
872 comp(__comp)
873{
874 c.insert(c.end(), __f, __l);
875 _VSTD::make_heap(c.begin(), c.end(), comp);
876}
877#endif // _LIBCPP_CXX03_LANG
703878
704879template <class _Tp, class _Container, class _Compare>
705880inline
......@@ -756,7 +931,7 @@ priority_queue<_Tp, _Container, _Compare>::swap(priority_queue& __q)
756931
757932template <class _Tp, class _Container, class _Compare>
758933inline _LIBCPP_INLINE_VISIBILITY
759_EnableIf<
934__enable_if_t<
760935 __is_swappable<_Container>::value && __is_swappable<_Compare>::value,
761936 void
762937>
lib/libcxx/include/random+48-5320
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- random -----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -1678,5330 +1678,58 @@ class piecewise_linear_distribution
16781678*/
16791679
16801680#include <__config>
1681#include <__random/bernoulli_distribution.h>
1682#include <__random/binomial_distribution.h>
1683#include <__random/cauchy_distribution.h>
1684#include <__random/chi_squared_distribution.h>
1685#include <__random/clamp_to_integral.h>
1686#include <__random/default_random_engine.h>
1687#include <__random/discard_block_engine.h>
1688#include <__random/discrete_distribution.h>
1689#include <__random/exponential_distribution.h>
1690#include <__random/extreme_value_distribution.h>
1691#include <__random/fisher_f_distribution.h>
1692#include <__random/gamma_distribution.h>
1693#include <__random/generate_canonical.h>
1694#include <__random/geometric_distribution.h>
1695#include <__random/independent_bits_engine.h>
1696#include <__random/is_seed_sequence.h>
1697#include <__random/knuth_b.h>
1698#include <__random/linear_congruential_engine.h>
1699#include <__random/log2.h>
1700#include <__random/lognormal_distribution.h>
1701#include <__random/mersenne_twister_engine.h>
1702#include <__random/negative_binomial_distribution.h>
1703#include <__random/normal_distribution.h>
1704#include <__random/piecewise_constant_distribution.h>
1705#include <__random/piecewise_linear_distribution.h>
1706#include <__random/poisson_distribution.h>
1707#include <__random/random_device.h>
1708#include <__random/ranlux.h>
1709#include <__random/seed_seq.h>
1710#include <__random/shuffle_order_engine.h>
1711#include <__random/student_t_distribution.h>
1712#include <__random/subtract_with_carry_engine.h>
16811713#include <__random/uniform_int_distribution.h>
1682#include <algorithm>
1683#include <cmath>
1684#include <concepts>
1685#include <cstddef>
1686#include <cstdint>
1714#include <__random/uniform_random_bit_generator.h>
1715#include <__random/uniform_real_distribution.h>
1716#include <__random/weibull_distribution.h>
16871717#include <initializer_list>
1688#include <iosfwd>
1689#include <limits>
1690#include <numeric>
1691#include <string>
1692#include <type_traits>
1693#include <vector>
1718#include <version>
1719
1720#include <algorithm> // for backward compatibility; TODO remove it
1721#include <cmath> // for backward compatibility; TODO remove it
1722#include <cstddef> // for backward compatibility; TODO remove it
1723#include <cstdint> // for backward compatibility; TODO remove it
1724#include <iosfwd> // for backward compatibility; TODO remove it
1725#include <limits> // for backward compatibility; TODO remove it
1726#include <numeric> // for backward compatibility; TODO remove it
1727#include <string> // for backward compatibility; TODO remove it
1728#include <type_traits> // for backward compatibility; TODO remove it
1729#include <vector> // for backward compatibility; TODO remove it
16941730
16951731#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16961732#pragma GCC system_header
16971733#endif
16981734
1699_LIBCPP_PUSH_MACROS
1700#include <__undef_macros>
1701
1702
1703_LIBCPP_BEGIN_NAMESPACE_STD
1704
1705#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CONCEPTS)
1706
1707// [rand.req.urng]
1708template<class _Gen>
1709concept uniform_random_bit_generator =
1710 invocable<_Gen&> && unsigned_integral<invoke_result_t<_Gen&>> &&
1711 requires {
1712 { _Gen::min() } -> same_as<invoke_result_t<_Gen&>>;
1713 { _Gen::max() } -> same_as<invoke_result_t<_Gen&>>;
1714 requires bool_constant<(_Gen::min() < _Gen::max())>::value;
1715 };
1716
1717#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CONCEPTS)
1718
1719// __is_seed_sequence
1720
1721template <class _Sseq, class _Engine>
1722struct __is_seed_sequence
1723{
1724 static _LIBCPP_CONSTEXPR const bool value =
1725 !is_convertible<_Sseq, typename _Engine::result_type>::value &&
1726 !is_same<typename remove_cv<_Sseq>::type, _Engine>::value;
1727};
1728
1729// linear_congruential_engine
1730
1731template <unsigned long long __a, unsigned long long __c,
1732 unsigned long long __m, unsigned long long _Mp,
1733 bool _MightOverflow = (__a != 0 && __m != 0 && __m-1 > (_Mp-__c)/__a),
1734 bool _OverflowOK = ((__m | (__m-1)) > __m), // m = 2^n
1735 bool _SchrageOK = (__a != 0 && __m != 0 && __m % __a <= __m / __a)> // r <= q
1736struct __lce_alg_picker
1737{
1738 static_assert(__a != 0 || __m != 0 || !_MightOverflow || _OverflowOK || _SchrageOK,
1739 "The current values of a, c, and m cannot generate a number "
1740 "within bounds of linear_congruential_engine.");
1741
1742 static _LIBCPP_CONSTEXPR const bool __use_schrage = _MightOverflow &&
1743 !_OverflowOK &&
1744 _SchrageOK;
1745};
1746
1747template <unsigned long long __a, unsigned long long __c,
1748 unsigned long long __m, unsigned long long _Mp,
1749 bool _UseSchrage = __lce_alg_picker<__a, __c, __m, _Mp>::__use_schrage>
1750struct __lce_ta;
1751
1752// 64
1753
1754template <unsigned long long __a, unsigned long long __c, unsigned long long __m>
1755struct __lce_ta<__a, __c, __m, (unsigned long long)(~0), true>
1756{
1757 typedef unsigned long long result_type;
1758 _LIBCPP_INLINE_VISIBILITY
1759 static result_type next(result_type __x)
1760 {
1761 // Schrage's algorithm
1762 const result_type __q = __m / __a;
1763 const result_type __r = __m % __a;
1764 const result_type __t0 = __a * (__x % __q);
1765 const result_type __t1 = __r * (__x / __q);
1766 __x = __t0 + (__t0 < __t1) * __m - __t1;
1767 __x += __c - (__x >= __m - __c) * __m;
1768 return __x;
1769 }
1770};
1771
1772template <unsigned long long __a, unsigned long long __m>
1773struct __lce_ta<__a, 0, __m, (unsigned long long)(~0), true>
1774{
1775 typedef unsigned long long result_type;
1776 _LIBCPP_INLINE_VISIBILITY
1777 static result_type next(result_type __x)
1778 {
1779 // Schrage's algorithm
1780 const result_type __q = __m / __a;
1781 const result_type __r = __m % __a;
1782 const result_type __t0 = __a * (__x % __q);
1783 const result_type __t1 = __r * (__x / __q);
1784 __x = __t0 + (__t0 < __t1) * __m - __t1;
1785 return __x;
1786 }
1787};
1788
1789template <unsigned long long __a, unsigned long long __c, unsigned long long __m>
1790struct __lce_ta<__a, __c, __m, (unsigned long long)(~0), false>
1791{
1792 typedef unsigned long long result_type;
1793 _LIBCPP_INLINE_VISIBILITY
1794 static result_type next(result_type __x)
1795 {
1796 return (__a * __x + __c) % __m;
1797 }
1798};
1799
1800template <unsigned long long __a, unsigned long long __c>
1801struct __lce_ta<__a, __c, 0, (unsigned long long)(~0), false>
1802{
1803 typedef unsigned long long result_type;
1804 _LIBCPP_INLINE_VISIBILITY
1805 static result_type next(result_type __x)
1806 {
1807 return __a * __x + __c;
1808 }
1809};
1810
1811// 32
1812
1813template <unsigned long long _Ap, unsigned long long _Cp, unsigned long long _Mp>
1814struct __lce_ta<_Ap, _Cp, _Mp, unsigned(~0), true>
1815{
1816 typedef unsigned result_type;
1817 _LIBCPP_INLINE_VISIBILITY
1818 static result_type next(result_type __x)
1819 {
1820 const result_type __a = static_cast<result_type>(_Ap);
1821 const result_type __c = static_cast<result_type>(_Cp);
1822 const result_type __m = static_cast<result_type>(_Mp);
1823 // Schrage's algorithm
1824 const result_type __q = __m / __a;
1825 const result_type __r = __m % __a;
1826 const result_type __t0 = __a * (__x % __q);
1827 const result_type __t1 = __r * (__x / __q);
1828 __x = __t0 + (__t0 < __t1) * __m - __t1;
1829 __x += __c - (__x >= __m - __c) * __m;
1830 return __x;
1831 }
1832};
1833
1834template <unsigned long long _Ap, unsigned long long _Mp>
1835struct __lce_ta<_Ap, 0, _Mp, unsigned(~0), true>
1836{
1837 typedef unsigned result_type;
1838 _LIBCPP_INLINE_VISIBILITY
1839 static result_type next(result_type __x)
1840 {
1841 const result_type __a = static_cast<result_type>(_Ap);
1842 const result_type __m = static_cast<result_type>(_Mp);
1843 // Schrage's algorithm
1844 const result_type __q = __m / __a;
1845 const result_type __r = __m % __a;
1846 const result_type __t0 = __a * (__x % __q);
1847 const result_type __t1 = __r * (__x / __q);
1848 __x = __t0 + (__t0 < __t1) * __m - __t1;
1849 return __x;
1850 }
1851};
1852
1853template <unsigned long long _Ap, unsigned long long _Cp, unsigned long long _Mp>
1854struct __lce_ta<_Ap, _Cp, _Mp, unsigned(~0), false>
1855{
1856 typedef unsigned result_type;
1857 _LIBCPP_INLINE_VISIBILITY
1858 static result_type next(result_type __x)
1859 {
1860 const result_type __a = static_cast<result_type>(_Ap);
1861 const result_type __c = static_cast<result_type>(_Cp);
1862 const result_type __m = static_cast<result_type>(_Mp);
1863 return (__a * __x + __c) % __m;
1864 }
1865};
1866
1867template <unsigned long long _Ap, unsigned long long _Cp>
1868struct __lce_ta<_Ap, _Cp, 0, unsigned(~0), false>
1869{
1870 typedef unsigned result_type;
1871 _LIBCPP_INLINE_VISIBILITY
1872 static result_type next(result_type __x)
1873 {
1874 const result_type __a = static_cast<result_type>(_Ap);
1875 const result_type __c = static_cast<result_type>(_Cp);
1876 return __a * __x + __c;
1877 }
1878};
1879
1880// 16
1881
1882template <unsigned long long __a, unsigned long long __c, unsigned long long __m, bool __b>
1883struct __lce_ta<__a, __c, __m, (unsigned short)(~0), __b>
1884{
1885 typedef unsigned short result_type;
1886 _LIBCPP_INLINE_VISIBILITY
1887 static result_type next(result_type __x)
1888 {
1889 return static_cast<result_type>(__lce_ta<__a, __c, __m, unsigned(~0)>::next(__x));
1890 }
1891};
1892
1893template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
1894class _LIBCPP_TEMPLATE_VIS linear_congruential_engine;
1895
1896template <class _CharT, class _Traits,
1897 class _Up, _Up _Ap, _Up _Cp, _Up _Np>
1898_LIBCPP_INLINE_VISIBILITY
1899basic_ostream<_CharT, _Traits>&
1900operator<<(basic_ostream<_CharT, _Traits>& __os,
1901 const linear_congruential_engine<_Up, _Ap, _Cp, _Np>&);
1902
1903template <class _CharT, class _Traits,
1904 class _Up, _Up _Ap, _Up _Cp, _Up _Np>
1905basic_istream<_CharT, _Traits>&
1906operator>>(basic_istream<_CharT, _Traits>& __is,
1907 linear_congruential_engine<_Up, _Ap, _Cp, _Np>& __x);
1908
1909template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
1910class _LIBCPP_TEMPLATE_VIS linear_congruential_engine
1911{
1912public:
1913 // types
1914 typedef _UIntType result_type;
1915
1916private:
1917 result_type __x_;
1918
1919 static _LIBCPP_CONSTEXPR const result_type _Mp = result_type(~0);
1920
1921 static_assert(__m == 0 || __a < __m, "linear_congruential_engine invalid parameters");
1922 static_assert(__m == 0 || __c < __m, "linear_congruential_engine invalid parameters");
1923 static_assert(is_unsigned<_UIntType>::value, "_UIntType must be unsigned type");
1924public:
1925 static _LIBCPP_CONSTEXPR const result_type _Min = __c == 0u ? 1u: 0u;
1926 static _LIBCPP_CONSTEXPR const result_type _Max = __m - 1u;
1927 static_assert(_Min < _Max, "linear_congruential_engine invalid parameters");
1928
1929 // engine characteristics
1930 static _LIBCPP_CONSTEXPR const result_type multiplier = __a;
1931 static _LIBCPP_CONSTEXPR const result_type increment = __c;
1932 static _LIBCPP_CONSTEXPR const result_type modulus = __m;
1933 _LIBCPP_INLINE_VISIBILITY
1934 static _LIBCPP_CONSTEXPR result_type min() {return _Min;}
1935 _LIBCPP_INLINE_VISIBILITY
1936 static _LIBCPP_CONSTEXPR result_type max() {return _Max;}
1937 static _LIBCPP_CONSTEXPR const result_type default_seed = 1u;
1938
1939 // constructors and seeding functions
1940#ifndef _LIBCPP_CXX03_LANG
1941 _LIBCPP_INLINE_VISIBILITY
1942 linear_congruential_engine() : linear_congruential_engine(default_seed) {}
1943 _LIBCPP_INLINE_VISIBILITY
1944 explicit linear_congruential_engine(result_type __s) { seed(__s); }
1945#else
1946 _LIBCPP_INLINE_VISIBILITY
1947 explicit linear_congruential_engine(result_type __s = default_seed) {
1948 seed(__s);
1949 }
1950#endif
1951 template<class _Sseq>
1952 _LIBCPP_INLINE_VISIBILITY
1953 explicit linear_congruential_engine(_Sseq& __q,
1954 typename enable_if<__is_seed_sequence<_Sseq, linear_congruential_engine>::value>::type* = 0)
1955 {seed(__q);}
1956 _LIBCPP_INLINE_VISIBILITY
1957 void seed(result_type __s = default_seed)
1958 {seed(integral_constant<bool, __m == 0>(),
1959 integral_constant<bool, __c == 0>(), __s);}
1960 template<class _Sseq>
1961 _LIBCPP_INLINE_VISIBILITY
1962 typename enable_if
1963 <
1964 __is_seed_sequence<_Sseq, linear_congruential_engine>::value,
1965 void
1966 >::type
1967 seed(_Sseq& __q)
1968 {__seed(__q, integral_constant<unsigned,
1969 1 + (__m == 0 ? (sizeof(result_type) * __CHAR_BIT__ - 1)/32
1970 : (__m > 0x100000000ull))>());}
1971
1972 // generating functions
1973 _LIBCPP_INLINE_VISIBILITY
1974 result_type operator()()
1975 {return __x_ = static_cast<result_type>(__lce_ta<__a, __c, __m, _Mp>::next(__x_));}
1976 _LIBCPP_INLINE_VISIBILITY
1977 void discard(unsigned long long __z) {for (; __z; --__z) operator()();}
1978
1979 friend _LIBCPP_INLINE_VISIBILITY
1980 bool operator==(const linear_congruential_engine& __x,
1981 const linear_congruential_engine& __y)
1982 {return __x.__x_ == __y.__x_;}
1983 friend _LIBCPP_INLINE_VISIBILITY
1984 bool operator!=(const linear_congruential_engine& __x,
1985 const linear_congruential_engine& __y)
1986 {return !(__x == __y);}
1987
1988private:
1989
1990 _LIBCPP_INLINE_VISIBILITY
1991 void seed(true_type, true_type, result_type __s) {__x_ = __s == 0 ? 1 : __s;}
1992 _LIBCPP_INLINE_VISIBILITY
1993 void seed(true_type, false_type, result_type __s) {__x_ = __s;}
1994 _LIBCPP_INLINE_VISIBILITY
1995 void seed(false_type, true_type, result_type __s) {__x_ = __s % __m == 0 ?
1996 1 : __s % __m;}
1997 _LIBCPP_INLINE_VISIBILITY
1998 void seed(false_type, false_type, result_type __s) {__x_ = __s % __m;}
1999
2000 template<class _Sseq>
2001 void __seed(_Sseq& __q, integral_constant<unsigned, 1>);
2002 template<class _Sseq>
2003 void __seed(_Sseq& __q, integral_constant<unsigned, 2>);
2004
2005 template <class _CharT, class _Traits,
2006 class _Up, _Up _Ap, _Up _Cp, _Up _Np>
2007 friend
2008 basic_ostream<_CharT, _Traits>&
2009 operator<<(basic_ostream<_CharT, _Traits>& __os,
2010 const linear_congruential_engine<_Up, _Ap, _Cp, _Np>&);
2011
2012 template <class _CharT, class _Traits,
2013 class _Up, _Up _Ap, _Up _Cp, _Up _Np>
2014 friend
2015 basic_istream<_CharT, _Traits>&
2016 operator>>(basic_istream<_CharT, _Traits>& __is,
2017 linear_congruential_engine<_Up, _Ap, _Cp, _Np>& __x);
2018};
2019
2020template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
2021 _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type
2022 linear_congruential_engine<_UIntType, __a, __c, __m>::multiplier;
2023
2024template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
2025 _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type
2026 linear_congruential_engine<_UIntType, __a, __c, __m>::increment;
2027
2028template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
2029 _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type
2030 linear_congruential_engine<_UIntType, __a, __c, __m>::modulus;
2031
2032template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
2033 _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type
2034 linear_congruential_engine<_UIntType, __a, __c, __m>::default_seed;
2035
2036template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
2037template<class _Sseq>
2038void
2039linear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q,
2040 integral_constant<unsigned, 1>)
2041{
2042 const unsigned __k = 1;
2043 uint32_t __ar[__k+3];
2044 __q.generate(__ar, __ar + __k + 3);
2045 result_type __s = static_cast<result_type>(__ar[3] % __m);
2046 __x_ = __c == 0 && __s == 0 ? result_type(1) : __s;
2047}
2048
2049template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
2050template<class _Sseq>
2051void
2052linear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q,
2053 integral_constant<unsigned, 2>)
2054{
2055 const unsigned __k = 2;
2056 uint32_t __ar[__k+3];
2057 __q.generate(__ar, __ar + __k + 3);
2058 result_type __s = static_cast<result_type>((__ar[3] +
2059 ((uint64_t)__ar[4] << 32)) % __m);
2060 __x_ = __c == 0 && __s == 0 ? result_type(1) : __s;
2061}
2062
2063template <class _CharT, class _Traits,
2064 class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
2065inline _LIBCPP_INLINE_VISIBILITY
2066basic_ostream<_CharT, _Traits>&
2067operator<<(basic_ostream<_CharT, _Traits>& __os,
2068 const linear_congruential_engine<_UIntType, __a, __c, __m>& __x)
2069{
2070 __save_flags<_CharT, _Traits> __lx(__os);
2071 typedef basic_ostream<_CharT, _Traits> _Ostream;
2072 __os.flags(_Ostream::dec | _Ostream::left);
2073 __os.fill(__os.widen(' '));
2074 return __os << __x.__x_;
2075}
2076
2077template <class _CharT, class _Traits,
2078 class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
2079basic_istream<_CharT, _Traits>&
2080operator>>(basic_istream<_CharT, _Traits>& __is,
2081 linear_congruential_engine<_UIntType, __a, __c, __m>& __x)
2082{
2083 __save_flags<_CharT, _Traits> __lx(__is);
2084 typedef basic_istream<_CharT, _Traits> _Istream;
2085 __is.flags(_Istream::dec | _Istream::skipws);
2086 _UIntType __t;
2087 __is >> __t;
2088 if (!__is.fail())
2089 __x.__x_ = __t;
2090 return __is;
2091}
2092
2093typedef linear_congruential_engine<uint_fast32_t, 16807, 0, 2147483647>
2094 minstd_rand0;
2095typedef linear_congruential_engine<uint_fast32_t, 48271, 0, 2147483647>
2096 minstd_rand;
2097typedef minstd_rand default_random_engine;
2098// mersenne_twister_engine
2099
2100template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2101 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2102 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2103class _LIBCPP_TEMPLATE_VIS mersenne_twister_engine;
2104
2105template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
2106 _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
2107 _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
2108bool
2109operator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2110 _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
2111 const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2112 _Bp, _Tp, _Cp, _Lp, _Fp>& __y);
2113
2114template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
2115 _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
2116 _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
2117_LIBCPP_INLINE_VISIBILITY
2118bool
2119operator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2120 _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
2121 const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2122 _Bp, _Tp, _Cp, _Lp, _Fp>& __y);
2123
2124template <class _CharT, class _Traits,
2125 class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
2126 _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
2127 _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
2128basic_ostream<_CharT, _Traits>&
2129operator<<(basic_ostream<_CharT, _Traits>& __os,
2130 const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2131 _Bp, _Tp, _Cp, _Lp, _Fp>& __x);
2132
2133template <class _CharT, class _Traits,
2134 class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
2135 _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
2136 _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
2137basic_istream<_CharT, _Traits>&
2138operator>>(basic_istream<_CharT, _Traits>& __is,
2139 mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2140 _Bp, _Tp, _Cp, _Lp, _Fp>& __x);
2141
2142template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2143 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2144 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2145class _LIBCPP_TEMPLATE_VIS mersenne_twister_engine
2146{
2147public:
2148 // types
2149 typedef _UIntType result_type;
2150
2151private:
2152 result_type __x_[__n];
2153 size_t __i_;
2154
2155 static_assert( 0 < __m, "mersenne_twister_engine invalid parameters");
2156 static_assert(__m <= __n, "mersenne_twister_engine invalid parameters");
2157 static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits;
2158 static_assert(__w <= _Dt, "mersenne_twister_engine invalid parameters");
2159 static_assert( 2 <= __w, "mersenne_twister_engine invalid parameters");
2160 static_assert(__r <= __w, "mersenne_twister_engine invalid parameters");
2161 static_assert(__u <= __w, "mersenne_twister_engine invalid parameters");
2162 static_assert(__s <= __w, "mersenne_twister_engine invalid parameters");
2163 static_assert(__t <= __w, "mersenne_twister_engine invalid parameters");
2164 static_assert(__l <= __w, "mersenne_twister_engine invalid parameters");
2165public:
2166 static _LIBCPP_CONSTEXPR const result_type _Min = 0;
2167 static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) :
2168 (result_type(1) << __w) - result_type(1);
2169 static_assert(_Min < _Max, "mersenne_twister_engine invalid parameters");
2170 static_assert(__a <= _Max, "mersenne_twister_engine invalid parameters");
2171 static_assert(__b <= _Max, "mersenne_twister_engine invalid parameters");
2172 static_assert(__c <= _Max, "mersenne_twister_engine invalid parameters");
2173 static_assert(__d <= _Max, "mersenne_twister_engine invalid parameters");
2174 static_assert(__f <= _Max, "mersenne_twister_engine invalid parameters");
2175
2176 // engine characteristics
2177 static _LIBCPP_CONSTEXPR const size_t word_size = __w;
2178 static _LIBCPP_CONSTEXPR const size_t state_size = __n;
2179 static _LIBCPP_CONSTEXPR const size_t shift_size = __m;
2180 static _LIBCPP_CONSTEXPR const size_t mask_bits = __r;
2181 static _LIBCPP_CONSTEXPR const result_type xor_mask = __a;
2182 static _LIBCPP_CONSTEXPR const size_t tempering_u = __u;
2183 static _LIBCPP_CONSTEXPR const result_type tempering_d = __d;
2184 static _LIBCPP_CONSTEXPR const size_t tempering_s = __s;
2185 static _LIBCPP_CONSTEXPR const result_type tempering_b = __b;
2186 static _LIBCPP_CONSTEXPR const size_t tempering_t = __t;
2187 static _LIBCPP_CONSTEXPR const result_type tempering_c = __c;
2188 static _LIBCPP_CONSTEXPR const size_t tempering_l = __l;
2189 static _LIBCPP_CONSTEXPR const result_type initialization_multiplier = __f;
2190 _LIBCPP_INLINE_VISIBILITY
2191 static _LIBCPP_CONSTEXPR result_type min() { return _Min; }
2192 _LIBCPP_INLINE_VISIBILITY
2193 static _LIBCPP_CONSTEXPR result_type max() { return _Max; }
2194 static _LIBCPP_CONSTEXPR const result_type default_seed = 5489u;
2195
2196 // constructors and seeding functions
2197#ifndef _LIBCPP_CXX03_LANG
2198 _LIBCPP_INLINE_VISIBILITY
2199 mersenne_twister_engine() : mersenne_twister_engine(default_seed) {}
2200 _LIBCPP_INLINE_VISIBILITY
2201 explicit mersenne_twister_engine(result_type __sd) { seed(__sd); }
2202#else
2203 _LIBCPP_INLINE_VISIBILITY
2204 explicit mersenne_twister_engine(result_type __sd = default_seed) {
2205 seed(__sd);
2206 }
2207#endif
2208 template<class _Sseq>
2209 _LIBCPP_INLINE_VISIBILITY
2210 explicit mersenne_twister_engine(_Sseq& __q,
2211 typename enable_if<__is_seed_sequence<_Sseq, mersenne_twister_engine>::value>::type* = 0)
2212 {seed(__q);}
2213 void seed(result_type __sd = default_seed);
2214 template<class _Sseq>
2215 _LIBCPP_INLINE_VISIBILITY
2216 typename enable_if
2217 <
2218 __is_seed_sequence<_Sseq, mersenne_twister_engine>::value,
2219 void
2220 >::type
2221 seed(_Sseq& __q)
2222 {__seed(__q, integral_constant<unsigned, 1 + (__w - 1) / 32>());}
2223
2224 // generating functions
2225 result_type operator()();
2226 _LIBCPP_INLINE_VISIBILITY
2227 void discard(unsigned long long __z) {for (; __z; --__z) operator()();}
2228
2229 template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
2230 _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
2231 _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
2232 friend
2233 bool
2234 operator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2235 _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
2236 const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2237 _Bp, _Tp, _Cp, _Lp, _Fp>& __y);
2238
2239 template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
2240 _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
2241 _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
2242 friend
2243 bool
2244 operator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2245 _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
2246 const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2247 _Bp, _Tp, _Cp, _Lp, _Fp>& __y);
2248
2249 template <class _CharT, class _Traits,
2250 class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
2251 _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
2252 _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
2253 friend
2254 basic_ostream<_CharT, _Traits>&
2255 operator<<(basic_ostream<_CharT, _Traits>& __os,
2256 const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2257 _Bp, _Tp, _Cp, _Lp, _Fp>& __x);
2258
2259 template <class _CharT, class _Traits,
2260 class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
2261 _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
2262 _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
2263 friend
2264 basic_istream<_CharT, _Traits>&
2265 operator>>(basic_istream<_CharT, _Traits>& __is,
2266 mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2267 _Bp, _Tp, _Cp, _Lp, _Fp>& __x);
2268private:
2269
2270 template<class _Sseq>
2271 void __seed(_Sseq& __q, integral_constant<unsigned, 1>);
2272 template<class _Sseq>
2273 void __seed(_Sseq& __q, integral_constant<unsigned, 2>);
2274
2275 template <size_t __count>
2276 _LIBCPP_INLINE_VISIBILITY
2277 static
2278 typename enable_if
2279 <
2280 __count < __w,
2281 result_type
2282 >::type
2283 __lshift(result_type __x) {return (__x << __count) & _Max;}
2284
2285 template <size_t __count>
2286 _LIBCPP_INLINE_VISIBILITY
2287 static
2288 typename enable_if
2289 <
2290 (__count >= __w),
2291 result_type
2292 >::type
2293 __lshift(result_type) {return result_type(0);}
2294
2295 template <size_t __count>
2296 _LIBCPP_INLINE_VISIBILITY
2297 static
2298 typename enable_if
2299 <
2300 __count < _Dt,
2301 result_type
2302 >::type
2303 __rshift(result_type __x) {return __x >> __count;}
2304
2305 template <size_t __count>
2306 _LIBCPP_INLINE_VISIBILITY
2307 static
2308 typename enable_if
2309 <
2310 (__count >= _Dt),
2311 result_type
2312 >::type
2313 __rshift(result_type) {return result_type(0);}
2314};
2315
2316template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2317 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2318 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2319 _LIBCPP_CONSTEXPR const size_t
2320 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::word_size;
2321
2322template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2323 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2324 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2325 _LIBCPP_CONSTEXPR const size_t
2326 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::state_size;
2327
2328template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2329 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2330 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2331 _LIBCPP_CONSTEXPR const size_t
2332 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::shift_size;
2333
2334template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2335 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2336 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2337 _LIBCPP_CONSTEXPR const size_t
2338 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::mask_bits;
2339
2340template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2341 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2342 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2343 _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type
2344 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::xor_mask;
2345
2346template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2347 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2348 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2349 _LIBCPP_CONSTEXPR const size_t
2350 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_u;
2351
2352template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2353 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2354 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2355 _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type
2356 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_d;
2357
2358template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2359 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2360 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2361 _LIBCPP_CONSTEXPR const size_t
2362 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_s;
2363
2364template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2365 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2366 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2367 _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type
2368 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_b;
2369
2370template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2371 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2372 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2373 _LIBCPP_CONSTEXPR const size_t
2374 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_t;
2375
2376template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2377 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2378 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2379 _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type
2380 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_c;
2381
2382template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2383 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2384 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2385 _LIBCPP_CONSTEXPR const size_t
2386 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_l;
2387
2388template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2389 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2390 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2391 _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type
2392 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::initialization_multiplier;
2393
2394template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2395 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2396 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2397 _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type
2398 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::default_seed;
2399
2400template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2401 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2402 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2403void
2404mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b,
2405 __t, __c, __l, __f>::seed(result_type __sd)
2406 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
2407{ // __w >= 2
2408 __x_[0] = __sd & _Max;
2409 for (size_t __i = 1; __i < __n; ++__i)
2410 __x_[__i] = (__f * (__x_[__i-1] ^ __rshift<__w - 2>(__x_[__i-1])) + __i) & _Max;
2411 __i_ = 0;
2412}
2413
2414template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2415 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2416 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2417template<class _Sseq>
2418void
2419mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b,
2420 __t, __c, __l, __f>::__seed(_Sseq& __q, integral_constant<unsigned, 1>)
2421{
2422 const unsigned __k = 1;
2423 uint32_t __ar[__n * __k];
2424 __q.generate(__ar, __ar + __n * __k);
2425 for (size_t __i = 0; __i < __n; ++__i)
2426 __x_[__i] = static_cast<result_type>(__ar[__i] & _Max);
2427 const result_type __mask = __r == _Dt ? result_type(~0) :
2428 (result_type(1) << __r) - result_type(1);
2429 __i_ = 0;
2430 if ((__x_[0] & ~__mask) == 0)
2431 {
2432 for (size_t __i = 1; __i < __n; ++__i)
2433 if (__x_[__i] != 0)
2434 return;
2435 __x_[0] = result_type(1) << (__w - 1);
2436 }
2437}
2438
2439template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2440 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2441 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2442template<class _Sseq>
2443void
2444mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b,
2445 __t, __c, __l, __f>::__seed(_Sseq& __q, integral_constant<unsigned, 2>)
2446{
2447 const unsigned __k = 2;
2448 uint32_t __ar[__n * __k];
2449 __q.generate(__ar, __ar + __n * __k);
2450 for (size_t __i = 0; __i < __n; ++__i)
2451 __x_[__i] = static_cast<result_type>(
2452 (__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max);
2453 const result_type __mask = __r == _Dt ? result_type(~0) :
2454 (result_type(1) << __r) - result_type(1);
2455 __i_ = 0;
2456 if ((__x_[0] & ~__mask) == 0)
2457 {
2458 for (size_t __i = 1; __i < __n; ++__i)
2459 if (__x_[__i] != 0)
2460 return;
2461 __x_[0] = result_type(1) << (__w - 1);
2462 }
2463}
2464
2465template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2466 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2467 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2468_UIntType
2469mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b,
2470 __t, __c, __l, __f>::operator()()
2471{
2472 const size_t __j = (__i_ + 1) % __n;
2473 const result_type __mask = __r == _Dt ? result_type(~0) :
2474 (result_type(1) << __r) - result_type(1);
2475 const result_type _Yp = (__x_[__i_] & ~__mask) | (__x_[__j] & __mask);
2476 const size_t __k = (__i_ + __m) % __n;
2477 __x_[__i_] = __x_[__k] ^ __rshift<1>(_Yp) ^ (__a * (_Yp & 1));
2478 result_type __z = __x_[__i_] ^ (__rshift<__u>(__x_[__i_]) & __d);
2479 __i_ = __j;
2480 __z ^= __lshift<__s>(__z) & __b;
2481 __z ^= __lshift<__t>(__z) & __c;
2482 return __z ^ __rshift<__l>(__z);
2483}
2484
2485template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
2486 _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
2487 _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
2488bool
2489operator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2490 _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
2491 const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2492 _Bp, _Tp, _Cp, _Lp, _Fp>& __y)
2493{
2494 if (__x.__i_ == __y.__i_)
2495 return _VSTD::equal(__x.__x_, __x.__x_ + _Np, __y.__x_);
2496 if (__x.__i_ == 0 || __y.__i_ == 0)
2497 {
2498 size_t __j = _VSTD::min(_Np - __x.__i_, _Np - __y.__i_);
2499 if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + __x.__i_ + __j,
2500 __y.__x_ + __y.__i_))
2501 return false;
2502 if (__x.__i_ == 0)
2503 return _VSTD::equal(__x.__x_ + __j, __x.__x_ + _Np, __y.__x_);
2504 return _VSTD::equal(__x.__x_, __x.__x_ + (_Np - __j), __y.__x_ + __j);
2505 }
2506 if (__x.__i_ < __y.__i_)
2507 {
2508 size_t __j = _Np - __y.__i_;
2509 if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + (__x.__i_ + __j),
2510 __y.__x_ + __y.__i_))
2511 return false;
2512 if (!_VSTD::equal(__x.__x_ + (__x.__i_ + __j), __x.__x_ + _Np,
2513 __y.__x_))
2514 return false;
2515 return _VSTD::equal(__x.__x_, __x.__x_ + __x.__i_,
2516 __y.__x_ + (_Np - (__x.__i_ + __j)));
2517 }
2518 size_t __j = _Np - __x.__i_;
2519 if (!_VSTD::equal(__y.__x_ + __y.__i_, __y.__x_ + (__y.__i_ + __j),
2520 __x.__x_ + __x.__i_))
2521 return false;
2522 if (!_VSTD::equal(__y.__x_ + (__y.__i_ + __j), __y.__x_ + _Np,
2523 __x.__x_))
2524 return false;
2525 return _VSTD::equal(__y.__x_, __y.__x_ + __y.__i_,
2526 __x.__x_ + (_Np - (__y.__i_ + __j)));
2527}
2528
2529template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
2530 _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
2531 _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
2532inline _LIBCPP_INLINE_VISIBILITY
2533bool
2534operator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2535 _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
2536 const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2537 _Bp, _Tp, _Cp, _Lp, _Fp>& __y)
2538{
2539 return !(__x == __y);
2540}
2541
2542template <class _CharT, class _Traits,
2543 class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
2544 _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
2545 _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
2546basic_ostream<_CharT, _Traits>&
2547operator<<(basic_ostream<_CharT, _Traits>& __os,
2548 const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2549 _Bp, _Tp, _Cp, _Lp, _Fp>& __x)
2550{
2551 __save_flags<_CharT, _Traits> __lx(__os);
2552 typedef basic_ostream<_CharT, _Traits> _Ostream;
2553 __os.flags(_Ostream::dec | _Ostream::left);
2554 _CharT __sp = __os.widen(' ');
2555 __os.fill(__sp);
2556 __os << __x.__x_[__x.__i_];
2557 for (size_t __j = __x.__i_ + 1; __j < _Np; ++__j)
2558 __os << __sp << __x.__x_[__j];
2559 for (size_t __j = 0; __j < __x.__i_; ++__j)
2560 __os << __sp << __x.__x_[__j];
2561 return __os;
2562}
2563
2564template <class _CharT, class _Traits,
2565 class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
2566 _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
2567 _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
2568basic_istream<_CharT, _Traits>&
2569operator>>(basic_istream<_CharT, _Traits>& __is,
2570 mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2571 _Bp, _Tp, _Cp, _Lp, _Fp>& __x)
2572{
2573 __save_flags<_CharT, _Traits> __lx(__is);
2574 typedef basic_istream<_CharT, _Traits> _Istream;
2575 __is.flags(_Istream::dec | _Istream::skipws);
2576 _UInt __t[_Np];
2577 for (size_t __i = 0; __i < _Np; ++__i)
2578 __is >> __t[__i];
2579 if (!__is.fail())
2580 {
2581 for (size_t __i = 0; __i < _Np; ++__i)
2582 __x.__x_[__i] = __t[__i];
2583 __x.__i_ = 0;
2584 }
2585 return __is;
2586}
2587
2588typedef mersenne_twister_engine<uint_fast32_t, 32, 624, 397, 31,
2589 0x9908b0df, 11, 0xffffffff,
2590 7, 0x9d2c5680,
2591 15, 0xefc60000,
2592 18, 1812433253> mt19937;
2593typedef mersenne_twister_engine<uint_fast64_t, 64, 312, 156, 31,
2594 0xb5026f5aa96619e9ULL, 29, 0x5555555555555555ULL,
2595 17, 0x71d67fffeda60000ULL,
2596 37, 0xfff7eee000000000ULL,
2597 43, 6364136223846793005ULL> mt19937_64;
2598
2599// subtract_with_carry_engine
2600
2601template<class _UIntType, size_t __w, size_t __s, size_t __r>
2602class _LIBCPP_TEMPLATE_VIS subtract_with_carry_engine;
2603
2604template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
2605bool
2606operator==(
2607 const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x,
2608 const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y);
2609
2610template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
2611_LIBCPP_INLINE_VISIBILITY
2612bool
2613operator!=(
2614 const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x,
2615 const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y);
2616
2617template <class _CharT, class _Traits,
2618 class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
2619basic_ostream<_CharT, _Traits>&
2620operator<<(basic_ostream<_CharT, _Traits>& __os,
2621 const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x);
2622
2623template <class _CharT, class _Traits,
2624 class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
2625basic_istream<_CharT, _Traits>&
2626operator>>(basic_istream<_CharT, _Traits>& __is,
2627 subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x);
2628
2629template<class _UIntType, size_t __w, size_t __s, size_t __r>
2630class _LIBCPP_TEMPLATE_VIS subtract_with_carry_engine
2631{
2632public:
2633 // types
2634 typedef _UIntType result_type;
2635
2636private:
2637 result_type __x_[__r];
2638 result_type __c_;
2639 size_t __i_;
2640
2641 static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits;
2642 static_assert( 0 < __w, "subtract_with_carry_engine invalid parameters");
2643 static_assert(__w <= _Dt, "subtract_with_carry_engine invalid parameters");
2644 static_assert( 0 < __s, "subtract_with_carry_engine invalid parameters");
2645 static_assert(__s < __r, "subtract_with_carry_engine invalid parameters");
2646public:
2647 static _LIBCPP_CONSTEXPR const result_type _Min = 0;
2648 static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) :
2649 (result_type(1) << __w) - result_type(1);
2650 static_assert(_Min < _Max, "subtract_with_carry_engine invalid parameters");
2651
2652 // engine characteristics
2653 static _LIBCPP_CONSTEXPR const size_t word_size = __w;
2654 static _LIBCPP_CONSTEXPR const size_t short_lag = __s;
2655 static _LIBCPP_CONSTEXPR const size_t long_lag = __r;
2656 _LIBCPP_INLINE_VISIBILITY
2657 static _LIBCPP_CONSTEXPR result_type min() { return _Min; }
2658 _LIBCPP_INLINE_VISIBILITY
2659 static _LIBCPP_CONSTEXPR result_type max() { return _Max; }
2660 static _LIBCPP_CONSTEXPR const result_type default_seed = 19780503u;
2661
2662 // constructors and seeding functions
2663#ifndef _LIBCPP_CXX03_LANG
2664 _LIBCPP_INLINE_VISIBILITY
2665 subtract_with_carry_engine() : subtract_with_carry_engine(default_seed) {}
2666 _LIBCPP_INLINE_VISIBILITY
2667 explicit subtract_with_carry_engine(result_type __sd) { seed(__sd); }
2668#else
2669 _LIBCPP_INLINE_VISIBILITY
2670 explicit subtract_with_carry_engine(result_type __sd = default_seed) {
2671 seed(__sd);
2672 }
2673#endif
2674 template<class _Sseq>
2675 _LIBCPP_INLINE_VISIBILITY
2676 explicit subtract_with_carry_engine(_Sseq& __q,
2677 typename enable_if<__is_seed_sequence<_Sseq, subtract_with_carry_engine>::value>::type* = 0)
2678 {seed(__q);}
2679 _LIBCPP_INLINE_VISIBILITY
2680 void seed(result_type __sd = default_seed)
2681 {seed(__sd, integral_constant<unsigned, 1 + (__w - 1) / 32>());}
2682 template<class _Sseq>
2683 _LIBCPP_INLINE_VISIBILITY
2684 typename enable_if
2685 <
2686 __is_seed_sequence<_Sseq, subtract_with_carry_engine>::value,
2687 void
2688 >::type
2689 seed(_Sseq& __q)
2690 {__seed(__q, integral_constant<unsigned, 1 + (__w - 1) / 32>());}
2691
2692 // generating functions
2693 result_type operator()();
2694 _LIBCPP_INLINE_VISIBILITY
2695 void discard(unsigned long long __z) {for (; __z; --__z) operator()();}
2696
2697 template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
2698 friend
2699 bool
2700 operator==(
2701 const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x,
2702 const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y);
2703
2704 template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
2705 friend
2706 bool
2707 operator!=(
2708 const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x,
2709 const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y);
2710
2711 template <class _CharT, class _Traits,
2712 class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
2713 friend
2714 basic_ostream<_CharT, _Traits>&
2715 operator<<(basic_ostream<_CharT, _Traits>& __os,
2716 const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x);
2717
2718 template <class _CharT, class _Traits,
2719 class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
2720 friend
2721 basic_istream<_CharT, _Traits>&
2722 operator>>(basic_istream<_CharT, _Traits>& __is,
2723 subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x);
2724
2725private:
2726
2727 void seed(result_type __sd, integral_constant<unsigned, 1>);
2728 void seed(result_type __sd, integral_constant<unsigned, 2>);
2729 template<class _Sseq>
2730 void __seed(_Sseq& __q, integral_constant<unsigned, 1>);
2731 template<class _Sseq>
2732 void __seed(_Sseq& __q, integral_constant<unsigned, 2>);
2733};
2734
2735template<class _UIntType, size_t __w, size_t __s, size_t __r>
2736 _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::word_size;
2737
2738template<class _UIntType, size_t __w, size_t __s, size_t __r>
2739 _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::short_lag;
2740
2741template<class _UIntType, size_t __w, size_t __s, size_t __r>
2742 _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::long_lag;
2743
2744template<class _UIntType, size_t __w, size_t __s, size_t __r>
2745 _LIBCPP_CONSTEXPR const typename subtract_with_carry_engine<_UIntType, __w, __s, __r>::result_type
2746 subtract_with_carry_engine<_UIntType, __w, __s, __r>::default_seed;
2747
2748template<class _UIntType, size_t __w, size_t __s, size_t __r>
2749void
2750subtract_with_carry_engine<_UIntType, __w, __s, __r>::seed(result_type __sd,
2751 integral_constant<unsigned, 1>)
2752{
2753 linear_congruential_engine<result_type, 40014u, 0u, 2147483563u>
2754 __e(__sd == 0u ? default_seed : __sd);
2755 for (size_t __i = 0; __i < __r; ++__i)
2756 __x_[__i] = static_cast<result_type>(__e() & _Max);
2757 __c_ = __x_[__r-1] == 0;
2758 __i_ = 0;
2759}
2760
2761template<class _UIntType, size_t __w, size_t __s, size_t __r>
2762void
2763subtract_with_carry_engine<_UIntType, __w, __s, __r>::seed(result_type __sd,
2764 integral_constant<unsigned, 2>)
2765{
2766 linear_congruential_engine<result_type, 40014u, 0u, 2147483563u>
2767 __e(__sd == 0u ? default_seed : __sd);
2768 for (size_t __i = 0; __i < __r; ++__i)
2769 {
2770 result_type __e0 = __e();
2771 __x_[__i] = static_cast<result_type>(
2772 (__e0 + ((uint64_t)__e() << 32)) & _Max);
2773 }
2774 __c_ = __x_[__r-1] == 0;
2775 __i_ = 0;
2776}
2777
2778template<class _UIntType, size_t __w, size_t __s, size_t __r>
2779template<class _Sseq>
2780void
2781subtract_with_carry_engine<_UIntType, __w, __s, __r>::__seed(_Sseq& __q,
2782 integral_constant<unsigned, 1>)
2783{
2784 const unsigned __k = 1;
2785 uint32_t __ar[__r * __k];
2786 __q.generate(__ar, __ar + __r * __k);
2787 for (size_t __i = 0; __i < __r; ++__i)
2788 __x_[__i] = static_cast<result_type>(__ar[__i] & _Max);
2789 __c_ = __x_[__r-1] == 0;
2790 __i_ = 0;
2791}
2792
2793template<class _UIntType, size_t __w, size_t __s, size_t __r>
2794template<class _Sseq>
2795void
2796subtract_with_carry_engine<_UIntType, __w, __s, __r>::__seed(_Sseq& __q,
2797 integral_constant<unsigned, 2>)
2798{
2799 const unsigned __k = 2;
2800 uint32_t __ar[__r * __k];
2801 __q.generate(__ar, __ar + __r * __k);
2802 for (size_t __i = 0; __i < __r; ++__i)
2803 __x_[__i] = static_cast<result_type>(
2804 (__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max);
2805 __c_ = __x_[__r-1] == 0;
2806 __i_ = 0;
2807}
2808
2809template<class _UIntType, size_t __w, size_t __s, size_t __r>
2810_UIntType
2811subtract_with_carry_engine<_UIntType, __w, __s, __r>::operator()()
2812{
2813 const result_type& __xs = __x_[(__i_ + (__r - __s)) % __r];
2814 result_type& __xr = __x_[__i_];
2815 result_type __new_c = __c_ == 0 ? __xs < __xr : __xs != 0 ? __xs <= __xr : 1;
2816 __xr = (__xs - __xr - __c_) & _Max;
2817 __c_ = __new_c;
2818 __i_ = (__i_ + 1) % __r;
2819 return __xr;
2820}
2821
2822template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
2823bool
2824operator==(
2825 const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x,
2826 const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y)
2827{
2828 if (__x.__c_ != __y.__c_)
2829 return false;
2830 if (__x.__i_ == __y.__i_)
2831 return _VSTD::equal(__x.__x_, __x.__x_ + _Rp, __y.__x_);
2832 if (__x.__i_ == 0 || __y.__i_ == 0)
2833 {
2834 size_t __j = _VSTD::min(_Rp - __x.__i_, _Rp - __y.__i_);
2835 if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + __x.__i_ + __j,
2836 __y.__x_ + __y.__i_))
2837 return false;
2838 if (__x.__i_ == 0)
2839 return _VSTD::equal(__x.__x_ + __j, __x.__x_ + _Rp, __y.__x_);
2840 return _VSTD::equal(__x.__x_, __x.__x_ + (_Rp - __j), __y.__x_ + __j);
2841 }
2842 if (__x.__i_ < __y.__i_)
2843 {
2844 size_t __j = _Rp - __y.__i_;
2845 if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + (__x.__i_ + __j),
2846 __y.__x_ + __y.__i_))
2847 return false;
2848 if (!_VSTD::equal(__x.__x_ + (__x.__i_ + __j), __x.__x_ + _Rp,
2849 __y.__x_))
2850 return false;
2851 return _VSTD::equal(__x.__x_, __x.__x_ + __x.__i_,
2852 __y.__x_ + (_Rp - (__x.__i_ + __j)));
2853 }
2854 size_t __j = _Rp - __x.__i_;
2855 if (!_VSTD::equal(__y.__x_ + __y.__i_, __y.__x_ + (__y.__i_ + __j),
2856 __x.__x_ + __x.__i_))
2857 return false;
2858 if (!_VSTD::equal(__y.__x_ + (__y.__i_ + __j), __y.__x_ + _Rp,
2859 __x.__x_))
2860 return false;
2861 return _VSTD::equal(__y.__x_, __y.__x_ + __y.__i_,
2862 __x.__x_ + (_Rp - (__y.__i_ + __j)));
2863}
2864
2865template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
2866inline _LIBCPP_INLINE_VISIBILITY
2867bool
2868operator!=(
2869 const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x,
2870 const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y)
2871{
2872 return !(__x == __y);
2873}
2874
2875template <class _CharT, class _Traits,
2876 class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
2877basic_ostream<_CharT, _Traits>&
2878operator<<(basic_ostream<_CharT, _Traits>& __os,
2879 const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x)
2880{
2881 __save_flags<_CharT, _Traits> __lx(__os);
2882 typedef basic_ostream<_CharT, _Traits> _Ostream;
2883 __os.flags(_Ostream::dec | _Ostream::left);
2884 _CharT __sp = __os.widen(' ');
2885 __os.fill(__sp);
2886 __os << __x.__x_[__x.__i_];
2887 for (size_t __j = __x.__i_ + 1; __j < _Rp; ++__j)
2888 __os << __sp << __x.__x_[__j];
2889 for (size_t __j = 0; __j < __x.__i_; ++__j)
2890 __os << __sp << __x.__x_[__j];
2891 __os << __sp << __x.__c_;
2892 return __os;
2893}
2894
2895template <class _CharT, class _Traits,
2896 class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
2897basic_istream<_CharT, _Traits>&
2898operator>>(basic_istream<_CharT, _Traits>& __is,
2899 subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x)
2900{
2901 __save_flags<_CharT, _Traits> __lx(__is);
2902 typedef basic_istream<_CharT, _Traits> _Istream;
2903 __is.flags(_Istream::dec | _Istream::skipws);
2904 _UInt __t[_Rp+1];
2905 for (size_t __i = 0; __i < _Rp+1; ++__i)
2906 __is >> __t[__i];
2907 if (!__is.fail())
2908 {
2909 for (size_t __i = 0; __i < _Rp; ++__i)
2910 __x.__x_[__i] = __t[__i];
2911 __x.__c_ = __t[_Rp];
2912 __x.__i_ = 0;
2913 }
2914 return __is;
2915}
2916
2917typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24> ranlux24_base;
2918typedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12> ranlux48_base;
2919
2920// discard_block_engine
2921
2922template<class _Engine, size_t __p, size_t __r>
2923class _LIBCPP_TEMPLATE_VIS discard_block_engine
2924{
2925 _Engine __e_;
2926 int __n_;
2927
2928 static_assert( 0 < __r, "discard_block_engine invalid parameters");
2929 static_assert(__r <= __p, "discard_block_engine invalid parameters");
2930 static_assert(__r <= INT_MAX, "discard_block_engine invalid parameters");
2931public:
2932 // types
2933 typedef typename _Engine::result_type result_type;
2934
2935 // engine characteristics
2936 static _LIBCPP_CONSTEXPR const size_t block_size = __p;
2937 static _LIBCPP_CONSTEXPR const size_t used_block = __r;
2938
2939#ifdef _LIBCPP_CXX03_LANG
2940 static const result_type _Min = _Engine::_Min;
2941 static const result_type _Max = _Engine::_Max;
2942#else
2943 static _LIBCPP_CONSTEXPR const result_type _Min = _Engine::min();
2944 static _LIBCPP_CONSTEXPR const result_type _Max = _Engine::max();
2945#endif
2946
2947 _LIBCPP_INLINE_VISIBILITY
2948 static _LIBCPP_CONSTEXPR result_type min() { return _Engine::min(); }
2949 _LIBCPP_INLINE_VISIBILITY
2950 static _LIBCPP_CONSTEXPR result_type max() { return _Engine::max(); }
2951
2952 // constructors and seeding functions
2953 _LIBCPP_INLINE_VISIBILITY
2954 discard_block_engine() : __n_(0) {}
2955 _LIBCPP_INLINE_VISIBILITY
2956 explicit discard_block_engine(const _Engine& __e)
2957 : __e_(__e), __n_(0) {}
2958#ifndef _LIBCPP_CXX03_LANG
2959 _LIBCPP_INLINE_VISIBILITY
2960 explicit discard_block_engine(_Engine&& __e)
2961 : __e_(_VSTD::move(__e)), __n_(0) {}
2962#endif // _LIBCPP_CXX03_LANG
2963 _LIBCPP_INLINE_VISIBILITY
2964 explicit discard_block_engine(result_type __sd) : __e_(__sd), __n_(0) {}
2965 template<class _Sseq>
2966 _LIBCPP_INLINE_VISIBILITY
2967 explicit discard_block_engine(_Sseq& __q,
2968 typename enable_if<__is_seed_sequence<_Sseq, discard_block_engine>::value &&
2969 !is_convertible<_Sseq, _Engine>::value>::type* = 0)
2970 : __e_(__q), __n_(0) {}
2971 _LIBCPP_INLINE_VISIBILITY
2972 void seed() {__e_.seed(); __n_ = 0;}
2973 _LIBCPP_INLINE_VISIBILITY
2974 void seed(result_type __sd) {__e_.seed(__sd); __n_ = 0;}
2975 template<class _Sseq>
2976 _LIBCPP_INLINE_VISIBILITY
2977 typename enable_if
2978 <
2979 __is_seed_sequence<_Sseq, discard_block_engine>::value,
2980 void
2981 >::type
2982 seed(_Sseq& __q) {__e_.seed(__q); __n_ = 0;}
2983
2984 // generating functions
2985 result_type operator()();
2986 _LIBCPP_INLINE_VISIBILITY
2987 void discard(unsigned long long __z) {for (; __z; --__z) operator()();}
2988
2989 // property functions
2990 _LIBCPP_INLINE_VISIBILITY
2991 const _Engine& base() const _NOEXCEPT {return __e_;}
2992
2993 template<class _Eng, size_t _Pp, size_t _Rp>
2994 friend
2995 bool
2996 operator==(
2997 const discard_block_engine<_Eng, _Pp, _Rp>& __x,
2998 const discard_block_engine<_Eng, _Pp, _Rp>& __y);
2999
3000 template<class _Eng, size_t _Pp, size_t _Rp>
3001 friend
3002 bool
3003 operator!=(
3004 const discard_block_engine<_Eng, _Pp, _Rp>& __x,
3005 const discard_block_engine<_Eng, _Pp, _Rp>& __y);
3006
3007 template <class _CharT, class _Traits,
3008 class _Eng, size_t _Pp, size_t _Rp>
3009 friend
3010 basic_ostream<_CharT, _Traits>&
3011 operator<<(basic_ostream<_CharT, _Traits>& __os,
3012 const discard_block_engine<_Eng, _Pp, _Rp>& __x);
3013
3014 template <class _CharT, class _Traits,
3015 class _Eng, size_t _Pp, size_t _Rp>
3016 friend
3017 basic_istream<_CharT, _Traits>&
3018 operator>>(basic_istream<_CharT, _Traits>& __is,
3019 discard_block_engine<_Eng, _Pp, _Rp>& __x);
3020};
3021
3022template<class _Engine, size_t __p, size_t __r>
3023 _LIBCPP_CONSTEXPR const size_t discard_block_engine<_Engine, __p, __r>::block_size;
3024
3025template<class _Engine, size_t __p, size_t __r>
3026 _LIBCPP_CONSTEXPR const size_t discard_block_engine<_Engine, __p, __r>::used_block;
3027
3028template<class _Engine, size_t __p, size_t __r>
3029typename discard_block_engine<_Engine, __p, __r>::result_type
3030discard_block_engine<_Engine, __p, __r>::operator()()
3031{
3032 if (__n_ >= static_cast<int>(__r))
3033 {
3034 __e_.discard(__p - __r);
3035 __n_ = 0;
3036 }
3037 ++__n_;
3038 return __e_();
3039}
3040
3041template<class _Eng, size_t _Pp, size_t _Rp>
3042inline _LIBCPP_INLINE_VISIBILITY
3043bool
3044operator==(const discard_block_engine<_Eng, _Pp, _Rp>& __x,
3045 const discard_block_engine<_Eng, _Pp, _Rp>& __y)
3046{
3047 return __x.__n_ == __y.__n_ && __x.__e_ == __y.__e_;
3048}
3049
3050template<class _Eng, size_t _Pp, size_t _Rp>
3051inline _LIBCPP_INLINE_VISIBILITY
3052bool
3053operator!=(const discard_block_engine<_Eng, _Pp, _Rp>& __x,
3054 const discard_block_engine<_Eng, _Pp, _Rp>& __y)
3055{
3056 return !(__x == __y);
3057}
3058
3059template <class _CharT, class _Traits,
3060 class _Eng, size_t _Pp, size_t _Rp>
3061basic_ostream<_CharT, _Traits>&
3062operator<<(basic_ostream<_CharT, _Traits>& __os,
3063 const discard_block_engine<_Eng, _Pp, _Rp>& __x)
3064{
3065 __save_flags<_CharT, _Traits> __lx(__os);
3066 typedef basic_ostream<_CharT, _Traits> _Ostream;
3067 __os.flags(_Ostream::dec | _Ostream::left);
3068 _CharT __sp = __os.widen(' ');
3069 __os.fill(__sp);
3070 return __os << __x.__e_ << __sp << __x.__n_;
3071}
3072
3073template <class _CharT, class _Traits,
3074 class _Eng, size_t _Pp, size_t _Rp>
3075basic_istream<_CharT, _Traits>&
3076operator>>(basic_istream<_CharT, _Traits>& __is,
3077 discard_block_engine<_Eng, _Pp, _Rp>& __x)
3078{
3079 __save_flags<_CharT, _Traits> __lx(__is);
3080 typedef basic_istream<_CharT, _Traits> _Istream;
3081 __is.flags(_Istream::dec | _Istream::skipws);
3082 _Eng __e;
3083 int __n;
3084 __is >> __e >> __n;
3085 if (!__is.fail())
3086 {
3087 __x.__e_ = __e;
3088 __x.__n_ = __n;
3089 }
3090 return __is;
3091}
3092
3093typedef discard_block_engine<ranlux24_base, 223, 23> ranlux24;
3094typedef discard_block_engine<ranlux48_base, 389, 11> ranlux48;
3095
3096// independent_bits_engine
3097
3098template<class _Engine, size_t __w, class _UIntType>
3099class _LIBCPP_TEMPLATE_VIS independent_bits_engine
3100{
3101 template <class _UInt, _UInt _R0, size_t _Wp, size_t _Mp>
3102 class __get_n
3103 {
3104 static _LIBCPP_CONSTEXPR const size_t _Dt = numeric_limits<_UInt>::digits;
3105 static _LIBCPP_CONSTEXPR const size_t _Np = _Wp / _Mp + (_Wp % _Mp != 0);
3106 static _LIBCPP_CONSTEXPR const size_t _W0 = _Wp / _Np;
3107 static _LIBCPP_CONSTEXPR const _UInt _Y0 = _W0 >= _Dt ? 0 : (_R0 >> _W0) << _W0;
3108 public:
3109 static _LIBCPP_CONSTEXPR const size_t value = _R0 - _Y0 > _Y0 / _Np ? _Np + 1 : _Np;
3110 };
3111public:
3112 // types
3113 typedef _UIntType result_type;
3114
3115private:
3116 _Engine __e_;
3117
3118 static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits;
3119 static_assert( 0 < __w, "independent_bits_engine invalid parameters");
3120 static_assert(__w <= _Dt, "independent_bits_engine invalid parameters");
3121
3122 typedef typename _Engine::result_type _Engine_result_type;
3123 typedef typename conditional
3124 <
3125 sizeof(_Engine_result_type) <= sizeof(result_type),
3126 result_type,
3127 _Engine_result_type
3128 >::type _Working_result_type;
3129#ifdef _LIBCPP_CXX03_LANG
3130 static const _Working_result_type _Rp = _Engine::_Max - _Engine::_Min
3131 + _Working_result_type(1);
3132#else
3133 static _LIBCPP_CONSTEXPR const _Working_result_type _Rp = _Engine::max() - _Engine::min()
3134 + _Working_result_type(1);
3135#endif
3136 static _LIBCPP_CONSTEXPR const size_t __m = __log2<_Working_result_type, _Rp>::value;
3137 static _LIBCPP_CONSTEXPR const size_t __n = __get_n<_Working_result_type, _Rp, __w, __m>::value;
3138 static _LIBCPP_CONSTEXPR const size_t __w0 = __w / __n;
3139 static _LIBCPP_CONSTEXPR const size_t __n0 = __n - __w % __n;
3140 static _LIBCPP_CONSTEXPR const size_t _WDt = numeric_limits<_Working_result_type>::digits;
3141 static _LIBCPP_CONSTEXPR const size_t _EDt = numeric_limits<_Engine_result_type>::digits;
3142 static _LIBCPP_CONSTEXPR const _Working_result_type __y0 = __w0 >= _WDt ? 0 :
3143 (_Rp >> __w0) << __w0;
3144 static _LIBCPP_CONSTEXPR const _Working_result_type __y1 = __w0 >= _WDt - 1 ? 0 :
3145 (_Rp >> (__w0+1)) << (__w0+1);
3146 static _LIBCPP_CONSTEXPR const _Engine_result_type __mask0 = __w0 > 0 ?
3147 _Engine_result_type(~0) >> (_EDt - __w0) :
3148 _Engine_result_type(0);
3149 static _LIBCPP_CONSTEXPR const _Engine_result_type __mask1 = __w0 < _EDt - 1 ?
3150 _Engine_result_type(~0) >> (_EDt - (__w0 + 1)) :
3151 _Engine_result_type(~0);
3152public:
3153 static _LIBCPP_CONSTEXPR const result_type _Min = 0;
3154 static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) :
3155 (result_type(1) << __w) - result_type(1);
3156 static_assert(_Min < _Max, "independent_bits_engine invalid parameters");
3157
3158 // engine characteristics
3159 _LIBCPP_INLINE_VISIBILITY
3160 static _LIBCPP_CONSTEXPR result_type min() { return _Min; }
3161 _LIBCPP_INLINE_VISIBILITY
3162 static _LIBCPP_CONSTEXPR result_type max() { return _Max; }
3163
3164 // constructors and seeding functions
3165 _LIBCPP_INLINE_VISIBILITY
3166 independent_bits_engine() {}
3167 _LIBCPP_INLINE_VISIBILITY
3168 explicit independent_bits_engine(const _Engine& __e)
3169 : __e_(__e) {}
3170#ifndef _LIBCPP_CXX03_LANG
3171 _LIBCPP_INLINE_VISIBILITY
3172 explicit independent_bits_engine(_Engine&& __e)
3173 : __e_(_VSTD::move(__e)) {}
3174#endif // _LIBCPP_CXX03_LANG
3175 _LIBCPP_INLINE_VISIBILITY
3176 explicit independent_bits_engine(result_type __sd) : __e_(__sd) {}
3177 template<class _Sseq>
3178 _LIBCPP_INLINE_VISIBILITY
3179 explicit independent_bits_engine(_Sseq& __q,
3180 typename enable_if<__is_seed_sequence<_Sseq, independent_bits_engine>::value &&
3181 !is_convertible<_Sseq, _Engine>::value>::type* = 0)
3182 : __e_(__q) {}
3183 _LIBCPP_INLINE_VISIBILITY
3184 void seed() {__e_.seed();}
3185 _LIBCPP_INLINE_VISIBILITY
3186 void seed(result_type __sd) {__e_.seed(__sd);}
3187 template<class _Sseq>
3188 _LIBCPP_INLINE_VISIBILITY
3189 typename enable_if
3190 <
3191 __is_seed_sequence<_Sseq, independent_bits_engine>::value,
3192 void
3193 >::type
3194 seed(_Sseq& __q) {__e_.seed(__q);}
3195
3196 // generating functions
3197 _LIBCPP_INLINE_VISIBILITY
3198 result_type operator()() {return __eval(integral_constant<bool, _Rp != 0>());}
3199 _LIBCPP_INLINE_VISIBILITY
3200 void discard(unsigned long long __z) {for (; __z; --__z) operator()();}
3201
3202 // property functions
3203 _LIBCPP_INLINE_VISIBILITY
3204 const _Engine& base() const _NOEXCEPT {return __e_;}
3205
3206 template<class _Eng, size_t _Wp, class _UInt>
3207 friend
3208 bool
3209 operator==(
3210 const independent_bits_engine<_Eng, _Wp, _UInt>& __x,
3211 const independent_bits_engine<_Eng, _Wp, _UInt>& __y);
3212
3213 template<class _Eng, size_t _Wp, class _UInt>
3214 friend
3215 bool
3216 operator!=(
3217 const independent_bits_engine<_Eng, _Wp, _UInt>& __x,
3218 const independent_bits_engine<_Eng, _Wp, _UInt>& __y);
3219
3220 template <class _CharT, class _Traits,
3221 class _Eng, size_t _Wp, class _UInt>
3222 friend
3223 basic_ostream<_CharT, _Traits>&
3224 operator<<(basic_ostream<_CharT, _Traits>& __os,
3225 const independent_bits_engine<_Eng, _Wp, _UInt>& __x);
3226
3227 template <class _CharT, class _Traits,
3228 class _Eng, size_t _Wp, class _UInt>
3229 friend
3230 basic_istream<_CharT, _Traits>&
3231 operator>>(basic_istream<_CharT, _Traits>& __is,
3232 independent_bits_engine<_Eng, _Wp, _UInt>& __x);
3233
3234private:
3235 _LIBCPP_INLINE_VISIBILITY
3236 result_type __eval(false_type);
3237 result_type __eval(true_type);
3238
3239 template <size_t __count>
3240 _LIBCPP_INLINE_VISIBILITY
3241 static
3242 typename enable_if
3243 <
3244 __count < _Dt,
3245 result_type
3246 >::type
3247 __lshift(result_type __x) {return __x << __count;}
3248
3249 template <size_t __count>
3250 _LIBCPP_INLINE_VISIBILITY
3251 static
3252 typename enable_if
3253 <
3254 (__count >= _Dt),
3255 result_type
3256 >::type
3257 __lshift(result_type) {return result_type(0);}
3258};
3259
3260template<class _Engine, size_t __w, class _UIntType>
3261inline
3262_UIntType
3263independent_bits_engine<_Engine, __w, _UIntType>::__eval(false_type)
3264{
3265 return static_cast<result_type>(__e_() & __mask0);
3266}
3267
3268template<class _Engine, size_t __w, class _UIntType>
3269_UIntType
3270independent_bits_engine<_Engine, __w, _UIntType>::__eval(true_type)
3271{
3272 result_type _Sp = 0;
3273 for (size_t __k = 0; __k < __n0; ++__k)
3274 {
3275 _Engine_result_type __u;
3276 do
3277 {
3278 __u = __e_() - _Engine::min();
3279 } while (__u >= __y0);
3280 _Sp = static_cast<result_type>(__lshift<__w0>(_Sp) + (__u & __mask0));
3281 }
3282 for (size_t __k = __n0; __k < __n; ++__k)
3283 {
3284 _Engine_result_type __u;
3285 do
3286 {
3287 __u = __e_() - _Engine::min();
3288 } while (__u >= __y1);
3289 _Sp = static_cast<result_type>(__lshift<__w0+1>(_Sp) + (__u & __mask1));
3290 }
3291 return _Sp;
3292}
3293
3294template<class _Eng, size_t _Wp, class _UInt>
3295inline _LIBCPP_INLINE_VISIBILITY
3296bool
3297operator==(
3298 const independent_bits_engine<_Eng, _Wp, _UInt>& __x,
3299 const independent_bits_engine<_Eng, _Wp, _UInt>& __y)
3300{
3301 return __x.base() == __y.base();
3302}
3303
3304template<class _Eng, size_t _Wp, class _UInt>
3305inline _LIBCPP_INLINE_VISIBILITY
3306bool
3307operator!=(
3308 const independent_bits_engine<_Eng, _Wp, _UInt>& __x,
3309 const independent_bits_engine<_Eng, _Wp, _UInt>& __y)
3310{
3311 return !(__x == __y);
3312}
3313
3314template <class _CharT, class _Traits,
3315 class _Eng, size_t _Wp, class _UInt>
3316basic_ostream<_CharT, _Traits>&
3317operator<<(basic_ostream<_CharT, _Traits>& __os,
3318 const independent_bits_engine<_Eng, _Wp, _UInt>& __x)
3319{
3320 return __os << __x.base();
3321}
3322
3323template <class _CharT, class _Traits,
3324 class _Eng, size_t _Wp, class _UInt>
3325basic_istream<_CharT, _Traits>&
3326operator>>(basic_istream<_CharT, _Traits>& __is,
3327 independent_bits_engine<_Eng, _Wp, _UInt>& __x)
3328{
3329 _Eng __e;
3330 __is >> __e;
3331 if (!__is.fail())
3332 __x.__e_ = __e;
3333 return __is;
3334}
3335
3336// shuffle_order_engine
3337
3338template <uint64_t _Xp, uint64_t _Yp>
3339struct __ugcd
3340{
3341 static _LIBCPP_CONSTEXPR const uint64_t value = __ugcd<_Yp, _Xp % _Yp>::value;
3342};
3343
3344template <uint64_t _Xp>
3345struct __ugcd<_Xp, 0>
3346{
3347 static _LIBCPP_CONSTEXPR const uint64_t value = _Xp;
3348};
3349
3350template <uint64_t _Np, uint64_t _Dp>
3351class __uratio
3352{
3353 static_assert(_Dp != 0, "__uratio divide by 0");
3354 static _LIBCPP_CONSTEXPR const uint64_t __gcd = __ugcd<_Np, _Dp>::value;
3355public:
3356 static _LIBCPP_CONSTEXPR const uint64_t num = _Np / __gcd;
3357 static _LIBCPP_CONSTEXPR const uint64_t den = _Dp / __gcd;
3358
3359 typedef __uratio<num, den> type;
3360};
3361
3362template<class _Engine, size_t __k>
3363class _LIBCPP_TEMPLATE_VIS shuffle_order_engine
3364{
3365 static_assert(0 < __k, "shuffle_order_engine invalid parameters");
3366public:
3367 // types
3368 typedef typename _Engine::result_type result_type;
3369
3370private:
3371 _Engine __e_;
3372 result_type _V_[__k];
3373 result_type _Y_;
3374
3375public:
3376 // engine characteristics
3377 static _LIBCPP_CONSTEXPR const size_t table_size = __k;
3378
3379#ifdef _LIBCPP_CXX03_LANG
3380 static const result_type _Min = _Engine::_Min;
3381 static const result_type _Max = _Engine::_Max;
3382#else
3383 static _LIBCPP_CONSTEXPR const result_type _Min = _Engine::min();
3384 static _LIBCPP_CONSTEXPR const result_type _Max = _Engine::max();
3385#endif
3386 static_assert(_Min < _Max, "shuffle_order_engine invalid parameters");
3387 _LIBCPP_INLINE_VISIBILITY
3388 static _LIBCPP_CONSTEXPR result_type min() { return _Min; }
3389 _LIBCPP_INLINE_VISIBILITY
3390 static _LIBCPP_CONSTEXPR result_type max() { return _Max; }
3391
3392 static _LIBCPP_CONSTEXPR const unsigned long long _Rp = _Max - _Min + 1ull;
3393
3394 // constructors and seeding functions
3395 _LIBCPP_INLINE_VISIBILITY
3396 shuffle_order_engine() {__init();}
3397 _LIBCPP_INLINE_VISIBILITY
3398 explicit shuffle_order_engine(const _Engine& __e)
3399 : __e_(__e) {__init();}
3400#ifndef _LIBCPP_CXX03_LANG
3401 _LIBCPP_INLINE_VISIBILITY
3402 explicit shuffle_order_engine(_Engine&& __e)
3403 : __e_(_VSTD::move(__e)) {__init();}
3404#endif // _LIBCPP_CXX03_LANG
3405 _LIBCPP_INLINE_VISIBILITY
3406 explicit shuffle_order_engine(result_type __sd) : __e_(__sd) {__init();}
3407 template<class _Sseq>
3408 _LIBCPP_INLINE_VISIBILITY
3409 explicit shuffle_order_engine(_Sseq& __q,
3410 typename enable_if<__is_seed_sequence<_Sseq, shuffle_order_engine>::value &&
3411 !is_convertible<_Sseq, _Engine>::value>::type* = 0)
3412 : __e_(__q) {__init();}
3413 _LIBCPP_INLINE_VISIBILITY
3414 void seed() {__e_.seed(); __init();}
3415 _LIBCPP_INLINE_VISIBILITY
3416 void seed(result_type __sd) {__e_.seed(__sd); __init();}
3417 template<class _Sseq>
3418 _LIBCPP_INLINE_VISIBILITY
3419 typename enable_if
3420 <
3421 __is_seed_sequence<_Sseq, shuffle_order_engine>::value,
3422 void
3423 >::type
3424 seed(_Sseq& __q) {__e_.seed(__q); __init();}
3425
3426 // generating functions
3427 _LIBCPP_INLINE_VISIBILITY
3428 result_type operator()() {return __eval(integral_constant<bool, _Rp != 0>());}
3429 _LIBCPP_INLINE_VISIBILITY
3430 void discard(unsigned long long __z) {for (; __z; --__z) operator()();}
3431
3432 // property functions
3433 _LIBCPP_INLINE_VISIBILITY
3434 const _Engine& base() const _NOEXCEPT {return __e_;}
3435
3436private:
3437 template<class _Eng, size_t _Kp>
3438 friend
3439 bool
3440 operator==(
3441 const shuffle_order_engine<_Eng, _Kp>& __x,
3442 const shuffle_order_engine<_Eng, _Kp>& __y);
3443
3444 template<class _Eng, size_t _Kp>
3445 friend
3446 bool
3447 operator!=(
3448 const shuffle_order_engine<_Eng, _Kp>& __x,
3449 const shuffle_order_engine<_Eng, _Kp>& __y);
3450
3451 template <class _CharT, class _Traits,
3452 class _Eng, size_t _Kp>
3453 friend
3454 basic_ostream<_CharT, _Traits>&
3455 operator<<(basic_ostream<_CharT, _Traits>& __os,
3456 const shuffle_order_engine<_Eng, _Kp>& __x);
3457
3458 template <class _CharT, class _Traits,
3459 class _Eng, size_t _Kp>
3460 friend
3461 basic_istream<_CharT, _Traits>&
3462 operator>>(basic_istream<_CharT, _Traits>& __is,
3463 shuffle_order_engine<_Eng, _Kp>& __x);
3464
3465 _LIBCPP_INLINE_VISIBILITY
3466 void __init()
3467 {
3468 for (size_t __i = 0; __i < __k; ++__i)
3469 _V_[__i] = __e_();
3470 _Y_ = __e_();
3471 }
3472
3473 _LIBCPP_INLINE_VISIBILITY
3474 result_type __eval(false_type) {return __eval2(integral_constant<bool, __k & 1>());}
3475 _LIBCPP_INLINE_VISIBILITY
3476 result_type __eval(true_type) {return __eval(__uratio<__k, _Rp>());}
3477
3478 _LIBCPP_INLINE_VISIBILITY
3479 result_type __eval2(false_type) {return __eval(__uratio<__k/2, 0x8000000000000000ull>());}
3480 _LIBCPP_INLINE_VISIBILITY
3481 result_type __eval2(true_type) {return __evalf<__k, 0>();}
3482
3483 template <uint64_t _Np, uint64_t _Dp>
3484 _LIBCPP_INLINE_VISIBILITY
3485 typename enable_if
3486 <
3487 (__uratio<_Np, _Dp>::num > 0xFFFFFFFFFFFFFFFFull / (_Max - _Min)),
3488 result_type
3489 >::type
3490 __eval(__uratio<_Np, _Dp>)
3491 {return __evalf<__uratio<_Np, _Dp>::num, __uratio<_Np, _Dp>::den>();}
3492
3493 template <uint64_t _Np, uint64_t _Dp>
3494 _LIBCPP_INLINE_VISIBILITY
3495 typename enable_if
3496 <
3497 __uratio<_Np, _Dp>::num <= 0xFFFFFFFFFFFFFFFFull / (_Max - _Min),
3498 result_type
3499 >::type
3500 __eval(__uratio<_Np, _Dp>)
3501 {
3502 const size_t __j = static_cast<size_t>(__uratio<_Np, _Dp>::num * (_Y_ - _Min)
3503 / __uratio<_Np, _Dp>::den);
3504 _Y_ = _V_[__j];
3505 _V_[__j] = __e_();
3506 return _Y_;
3507 }
3508
3509 template <uint64_t __n, uint64_t __d>
3510 _LIBCPP_INLINE_VISIBILITY
3511 result_type __evalf()
3512 {
3513 const double _Fp = __d == 0 ?
3514 __n / (2. * 0x8000000000000000ull) :
3515 __n / (double)__d;
3516 const size_t __j = static_cast<size_t>(_Fp * (_Y_ - _Min));
3517 _Y_ = _V_[__j];
3518 _V_[__j] = __e_();
3519 return _Y_;
3520 }
3521};
3522
3523template<class _Engine, size_t __k>
3524 _LIBCPP_CONSTEXPR const size_t shuffle_order_engine<_Engine, __k>::table_size;
3525
3526template<class _Eng, size_t _Kp>
3527bool
3528operator==(
3529 const shuffle_order_engine<_Eng, _Kp>& __x,
3530 const shuffle_order_engine<_Eng, _Kp>& __y)
3531{
3532 return __x._Y_ == __y._Y_ && _VSTD::equal(__x._V_, __x._V_ + _Kp, __y._V_) &&
3533 __x.__e_ == __y.__e_;
3534}
3535
3536template<class _Eng, size_t _Kp>
3537inline _LIBCPP_INLINE_VISIBILITY
3538bool
3539operator!=(
3540 const shuffle_order_engine<_Eng, _Kp>& __x,
3541 const shuffle_order_engine<_Eng, _Kp>& __y)
3542{
3543 return !(__x == __y);
3544}
3545
3546template <class _CharT, class _Traits,
3547 class _Eng, size_t _Kp>
3548basic_ostream<_CharT, _Traits>&
3549operator<<(basic_ostream<_CharT, _Traits>& __os,
3550 const shuffle_order_engine<_Eng, _Kp>& __x)
3551{
3552 __save_flags<_CharT, _Traits> __lx(__os);
3553 typedef basic_ostream<_CharT, _Traits> _Ostream;
3554 __os.flags(_Ostream::dec | _Ostream::left);
3555 _CharT __sp = __os.widen(' ');
3556 __os.fill(__sp);
3557 __os << __x.__e_ << __sp << __x._V_[0];
3558 for (size_t __i = 1; __i < _Kp; ++__i)
3559 __os << __sp << __x._V_[__i];
3560 return __os << __sp << __x._Y_;
3561}
3562
3563template <class _CharT, class _Traits,
3564 class _Eng, size_t _Kp>
3565basic_istream<_CharT, _Traits>&
3566operator>>(basic_istream<_CharT, _Traits>& __is,
3567 shuffle_order_engine<_Eng, _Kp>& __x)
3568{
3569 typedef typename shuffle_order_engine<_Eng, _Kp>::result_type result_type;
3570 __save_flags<_CharT, _Traits> __lx(__is);
3571 typedef basic_istream<_CharT, _Traits> _Istream;
3572 __is.flags(_Istream::dec | _Istream::skipws);
3573 _Eng __e;
3574 result_type _Vp[_Kp+1];
3575 __is >> __e;
3576 for (size_t __i = 0; __i < _Kp+1; ++__i)
3577 __is >> _Vp[__i];
3578 if (!__is.fail())
3579 {
3580 __x.__e_ = __e;
3581 for (size_t __i = 0; __i < _Kp; ++__i)
3582 __x._V_[__i] = _Vp[__i];
3583 __x._Y_ = _Vp[_Kp];
3584 }
3585 return __is;
3586}
3587
3588typedef shuffle_order_engine<minstd_rand0, 256> knuth_b;
3589
3590// random_device
3591
3592#if !defined(_LIBCPP_HAS_NO_RANDOM_DEVICE)
3593
3594class _LIBCPP_TYPE_VIS random_device
3595{
3596#ifdef _LIBCPP_USING_DEV_RANDOM
3597 int __f_;
3598#endif // defined(_LIBCPP_USING_DEV_RANDOM)
3599public:
3600 // types
3601 typedef unsigned result_type;
3602
3603 // generator characteristics
3604 static _LIBCPP_CONSTEXPR const result_type _Min = 0;
3605 static _LIBCPP_CONSTEXPR const result_type _Max = 0xFFFFFFFFu;
3606
3607 _LIBCPP_INLINE_VISIBILITY
3608 static _LIBCPP_CONSTEXPR result_type min() { return _Min;}
3609 _LIBCPP_INLINE_VISIBILITY
3610 static _LIBCPP_CONSTEXPR result_type max() { return _Max;}
3611
3612 // constructors
3613#ifndef _LIBCPP_CXX03_LANG
3614 random_device() : random_device("/dev/urandom") {}
3615 explicit random_device(const string& __token);
3616#else
3617 explicit random_device(const string& __token = "/dev/urandom");
3618#endif
3619 ~random_device();
3620
3621 // generating functions
3622 result_type operator()();
3623
3624 // property functions
3625 double entropy() const _NOEXCEPT;
3626
3627private:
3628 // no copy functions
3629 random_device(const random_device&); // = delete;
3630 random_device& operator=(const random_device&); // = delete;
3631};
3632
3633#endif // !_LIBCPP_HAS_NO_RANDOM_DEVICE
3634
3635// seed_seq
3636
3637class _LIBCPP_TEMPLATE_VIS seed_seq
3638{
3639public:
3640 // types
3641 typedef uint32_t result_type;
3642
3643private:
3644 vector<result_type> __v_;
3645
3646 template<class _InputIterator>
3647 void init(_InputIterator __first, _InputIterator __last);
3648public:
3649 // constructors
3650 _LIBCPP_INLINE_VISIBILITY
3651 seed_seq() _NOEXCEPT {}
3652#ifndef _LIBCPP_CXX03_LANG
3653 template<class _Tp>
3654 _LIBCPP_INLINE_VISIBILITY
3655 seed_seq(initializer_list<_Tp> __il) {init(__il.begin(), __il.end());}
3656#endif // _LIBCPP_CXX03_LANG
3657
3658 template<class _InputIterator>
3659 _LIBCPP_INLINE_VISIBILITY
3660 seed_seq(_InputIterator __first, _InputIterator __last)
3661 {init(__first, __last);}
3662
3663 // generating functions
3664 template<class _RandomAccessIterator>
3665 void generate(_RandomAccessIterator __first, _RandomAccessIterator __last);
3666
3667 // property functions
3668 _LIBCPP_INLINE_VISIBILITY
3669 size_t size() const _NOEXCEPT {return __v_.size();}
3670 template<class _OutputIterator>
3671 _LIBCPP_INLINE_VISIBILITY
3672 void param(_OutputIterator __dest) const
3673 {_VSTD::copy(__v_.begin(), __v_.end(), __dest);}
3674
3675private:
3676 // no copy functions
3677 seed_seq(const seed_seq&); // = delete;
3678 void operator=(const seed_seq&); // = delete;
3679
3680 _LIBCPP_INLINE_VISIBILITY
3681 static result_type _Tp(result_type __x) {return __x ^ (__x >> 27);}
3682};
3683
3684template<class _InputIterator>
3685void
3686seed_seq::init(_InputIterator __first, _InputIterator __last)
3687{
3688 for (_InputIterator __s = __first; __s != __last; ++__s)
3689 __v_.push_back(*__s & 0xFFFFFFFF);
3690}
3691
3692template<class _RandomAccessIterator>
3693void
3694seed_seq::generate(_RandomAccessIterator __first, _RandomAccessIterator __last)
3695{
3696 if (__first != __last)
3697 {
3698 _VSTD::fill(__first, __last, 0x8b8b8b8b);
3699 const size_t __n = static_cast<size_t>(__last - __first);
3700 const size_t __s = __v_.size();
3701 const size_t __t = (__n >= 623) ? 11
3702 : (__n >= 68) ? 7
3703 : (__n >= 39) ? 5
3704 : (__n >= 7) ? 3
3705 : (__n - 1) / 2;
3706 const size_t __p = (__n - __t) / 2;
3707 const size_t __q = __p + __t;
3708 const size_t __m = _VSTD::max(__s + 1, __n);
3709 // __k = 0;
3710 {
3711 result_type __r = 1664525 * _Tp(__first[0] ^ __first[__p]
3712 ^ __first[__n - 1]);
3713 __first[__p] += __r;
3714 __r += __s;
3715 __first[__q] += __r;
3716 __first[0] = __r;
3717 }
3718 for (size_t __k = 1; __k <= __s; ++__k)
3719 {
3720 const size_t __kmodn = __k % __n;
3721 const size_t __kpmodn = (__k + __p) % __n;
3722 result_type __r = 1664525 * _Tp(__first[__kmodn] ^ __first[__kpmodn]
3723 ^ __first[(__k - 1) % __n]);
3724 __first[__kpmodn] += __r;
3725 __r += __kmodn + __v_[__k-1];
3726 __first[(__k + __q) % __n] += __r;
3727 __first[__kmodn] = __r;
3728 }
3729 for (size_t __k = __s + 1; __k < __m; ++__k)
3730 {
3731 const size_t __kmodn = __k % __n;
3732 const size_t __kpmodn = (__k + __p) % __n;
3733 result_type __r = 1664525 * _Tp(__first[__kmodn] ^ __first[__kpmodn]
3734 ^ __first[(__k - 1) % __n]);
3735 __first[__kpmodn] += __r;
3736 __r += __kmodn;
3737 __first[(__k + __q) % __n] += __r;
3738 __first[__kmodn] = __r;
3739 }
3740 for (size_t __k = __m; __k < __m + __n; ++__k)
3741 {
3742 const size_t __kmodn = __k % __n;
3743 const size_t __kpmodn = (__k + __p) % __n;
3744 result_type __r = 1566083941 * _Tp(__first[__kmodn] +
3745 __first[__kpmodn] +
3746 __first[(__k - 1) % __n]);
3747 __first[__kpmodn] ^= __r;
3748 __r -= __kmodn;
3749 __first[(__k + __q) % __n] ^= __r;
3750 __first[__kmodn] = __r;
3751 }
3752 }
3753}
3754
3755// generate_canonical
3756
3757template<class _RealType, size_t __bits, class _URNG>
3758_RealType
3759generate_canonical(_URNG& __g)
3760{
3761 const size_t _Dt = numeric_limits<_RealType>::digits;
3762 const size_t __b = _Dt < __bits ? _Dt : __bits;
3763#ifdef _LIBCPP_CXX03_LANG
3764 const size_t __logR = __log2<uint64_t, _URNG::_Max - _URNG::_Min + uint64_t(1)>::value;
3765#else
3766 const size_t __logR = __log2<uint64_t, _URNG::max() - _URNG::min() + uint64_t(1)>::value;
3767#endif
3768 const size_t __k = __b / __logR + (__b % __logR != 0) + (__b == 0);
3769 const _RealType _Rp = static_cast<_RealType>(_URNG::max() - _URNG::min()) + _RealType(1);
3770 _RealType __base = _Rp;
3771 _RealType _Sp = __g() - _URNG::min();
3772 for (size_t __i = 1; __i < __k; ++__i, __base *= _Rp)
3773 _Sp += (__g() - _URNG::min()) * __base;
3774 return _Sp / __base;
3775}
3776
3777// uniform_real_distribution
3778
3779template<class _RealType = double>
3780class _LIBCPP_TEMPLATE_VIS uniform_real_distribution
3781{
3782public:
3783 // types
3784 typedef _RealType result_type;
3785
3786 class _LIBCPP_TEMPLATE_VIS param_type
3787 {
3788 result_type __a_;
3789 result_type __b_;
3790 public:
3791 typedef uniform_real_distribution distribution_type;
3792
3793 _LIBCPP_INLINE_VISIBILITY
3794 explicit param_type(result_type __a = 0,
3795 result_type __b = 1)
3796 : __a_(__a), __b_(__b) {}
3797
3798 _LIBCPP_INLINE_VISIBILITY
3799 result_type a() const {return __a_;}
3800 _LIBCPP_INLINE_VISIBILITY
3801 result_type b() const {return __b_;}
3802
3803 friend _LIBCPP_INLINE_VISIBILITY
3804 bool operator==(const param_type& __x, const param_type& __y)
3805 {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;}
3806 friend _LIBCPP_INLINE_VISIBILITY
3807 bool operator!=(const param_type& __x, const param_type& __y)
3808 {return !(__x == __y);}
3809 };
3810
3811private:
3812 param_type __p_;
3813
3814public:
3815 // constructors and reset functions
3816#ifndef _LIBCPP_CXX03_LANG
3817 _LIBCPP_INLINE_VISIBILITY
3818 uniform_real_distribution() : uniform_real_distribution(0) {}
3819 explicit uniform_real_distribution(result_type __a, result_type __b = 1)
3820 : __p_(param_type(__a, __b)) {}
3821#else
3822 _LIBCPP_INLINE_VISIBILITY
3823 explicit uniform_real_distribution(result_type __a = 0, result_type __b = 1)
3824 : __p_(param_type(__a, __b)) {}
3825#endif
3826 _LIBCPP_INLINE_VISIBILITY
3827 explicit uniform_real_distribution(const param_type& __p) : __p_(__p) {}
3828 _LIBCPP_INLINE_VISIBILITY
3829 void reset() {}
3830
3831 // generating functions
3832 template<class _URNG>
3833 _LIBCPP_INLINE_VISIBILITY
3834 result_type operator()(_URNG& __g)
3835 {return (*this)(__g, __p_);}
3836 template<class _URNG> _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g, const param_type& __p);
3837
3838 // property functions
3839 _LIBCPP_INLINE_VISIBILITY
3840 result_type a() const {return __p_.a();}
3841 _LIBCPP_INLINE_VISIBILITY
3842 result_type b() const {return __p_.b();}
3843
3844 _LIBCPP_INLINE_VISIBILITY
3845 param_type param() const {return __p_;}
3846 _LIBCPP_INLINE_VISIBILITY
3847 void param(const param_type& __p) {__p_ = __p;}
3848
3849 _LIBCPP_INLINE_VISIBILITY
3850 result_type min() const {return a();}
3851 _LIBCPP_INLINE_VISIBILITY
3852 result_type max() const {return b();}
3853
3854 friend _LIBCPP_INLINE_VISIBILITY
3855 bool operator==(const uniform_real_distribution& __x,
3856 const uniform_real_distribution& __y)
3857 {return __x.__p_ == __y.__p_;}
3858 friend _LIBCPP_INLINE_VISIBILITY
3859 bool operator!=(const uniform_real_distribution& __x,
3860 const uniform_real_distribution& __y)
3861 {return !(__x == __y);}
3862};
3863
3864template<class _RealType>
3865template<class _URNG>
3866inline
3867typename uniform_real_distribution<_RealType>::result_type
3868uniform_real_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
3869{
3870 return (__p.b() - __p.a())
3871 * _VSTD::generate_canonical<_RealType, numeric_limits<_RealType>::digits>(__g)
3872 + __p.a();
3873}
3874
3875template <class _CharT, class _Traits, class _RT>
3876basic_ostream<_CharT, _Traits>&
3877operator<<(basic_ostream<_CharT, _Traits>& __os,
3878 const uniform_real_distribution<_RT>& __x)
3879{
3880 __save_flags<_CharT, _Traits> __lx(__os);
3881 typedef basic_ostream<_CharT, _Traits> _OStream;
3882 __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
3883 _OStream::scientific);
3884 _CharT __sp = __os.widen(' ');
3885 __os.fill(__sp);
3886 return __os << __x.a() << __sp << __x.b();
3887}
3888
3889template <class _CharT, class _Traits, class _RT>
3890basic_istream<_CharT, _Traits>&
3891operator>>(basic_istream<_CharT, _Traits>& __is,
3892 uniform_real_distribution<_RT>& __x)
3893{
3894 typedef uniform_real_distribution<_RT> _Eng;
3895 typedef typename _Eng::result_type result_type;
3896 typedef typename _Eng::param_type param_type;
3897 __save_flags<_CharT, _Traits> __lx(__is);
3898 typedef basic_istream<_CharT, _Traits> _Istream;
3899 __is.flags(_Istream::dec | _Istream::skipws);
3900 result_type __a;
3901 result_type __b;
3902 __is >> __a >> __b;
3903 if (!__is.fail())
3904 __x.param(param_type(__a, __b));
3905 return __is;
3906}
3907
3908// bernoulli_distribution
3909
3910class _LIBCPP_TEMPLATE_VIS bernoulli_distribution
3911{
3912public:
3913 // types
3914 typedef bool result_type;
3915
3916 class _LIBCPP_TEMPLATE_VIS param_type
3917 {
3918 double __p_;
3919 public:
3920 typedef bernoulli_distribution distribution_type;
3921
3922 _LIBCPP_INLINE_VISIBILITY
3923 explicit param_type(double __p = 0.5) : __p_(__p) {}
3924
3925 _LIBCPP_INLINE_VISIBILITY
3926 double p() const {return __p_;}
3927
3928 friend _LIBCPP_INLINE_VISIBILITY
3929 bool operator==(const param_type& __x, const param_type& __y)
3930 {return __x.__p_ == __y.__p_;}
3931 friend _LIBCPP_INLINE_VISIBILITY
3932 bool operator!=(const param_type& __x, const param_type& __y)
3933 {return !(__x == __y);}
3934 };
3935
3936private:
3937 param_type __p_;
3938
3939public:
3940 // constructors and reset functions
3941#ifndef _LIBCPP_CXX03_LANG
3942 _LIBCPP_INLINE_VISIBILITY
3943 bernoulli_distribution() : bernoulli_distribution(0.5) {}
3944 _LIBCPP_INLINE_VISIBILITY
3945 explicit bernoulli_distribution(double __p) : __p_(param_type(__p)) {}
3946#else
3947 _LIBCPP_INLINE_VISIBILITY
3948 explicit bernoulli_distribution(double __p = 0.5) : __p_(param_type(__p)) {}
3949#endif
3950 _LIBCPP_INLINE_VISIBILITY
3951 explicit bernoulli_distribution(const param_type& __p) : __p_(__p) {}
3952 _LIBCPP_INLINE_VISIBILITY
3953 void reset() {}
3954
3955 // generating functions
3956 template<class _URNG>
3957 _LIBCPP_INLINE_VISIBILITY
3958 result_type operator()(_URNG& __g)
3959 {return (*this)(__g, __p_);}
3960 template<class _URNG> _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g, const param_type& __p);
3961
3962 // property functions
3963 _LIBCPP_INLINE_VISIBILITY
3964 double p() const {return __p_.p();}
3965
3966 _LIBCPP_INLINE_VISIBILITY
3967 param_type param() const {return __p_;}
3968 _LIBCPP_INLINE_VISIBILITY
3969 void param(const param_type& __p) {__p_ = __p;}
3970
3971 _LIBCPP_INLINE_VISIBILITY
3972 result_type min() const {return false;}
3973 _LIBCPP_INLINE_VISIBILITY
3974 result_type max() const {return true;}
3975
3976 friend _LIBCPP_INLINE_VISIBILITY
3977 bool operator==(const bernoulli_distribution& __x,
3978 const bernoulli_distribution& __y)
3979 {return __x.__p_ == __y.__p_;}
3980 friend _LIBCPP_INLINE_VISIBILITY
3981 bool operator!=(const bernoulli_distribution& __x,
3982 const bernoulli_distribution& __y)
3983 {return !(__x == __y);}
3984};
3985
3986template<class _URNG>
3987inline
3988bernoulli_distribution::result_type
3989bernoulli_distribution::operator()(_URNG& __g, const param_type& __p)
3990{
3991 uniform_real_distribution<double> __gen;
3992 return __gen(__g) < __p.p();
3993}
3994
3995template <class _CharT, class _Traits>
3996basic_ostream<_CharT, _Traits>&
3997operator<<(basic_ostream<_CharT, _Traits>& __os, const bernoulli_distribution& __x)
3998{
3999 __save_flags<_CharT, _Traits> __lx(__os);
4000 typedef basic_ostream<_CharT, _Traits> _OStream;
4001 __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
4002 _OStream::scientific);
4003 _CharT __sp = __os.widen(' ');
4004 __os.fill(__sp);
4005 return __os << __x.p();
4006}
4007
4008template <class _CharT, class _Traits>
4009basic_istream<_CharT, _Traits>&
4010operator>>(basic_istream<_CharT, _Traits>& __is, bernoulli_distribution& __x)
4011{
4012 typedef bernoulli_distribution _Eng;
4013 typedef typename _Eng::param_type param_type;
4014 __save_flags<_CharT, _Traits> __lx(__is);
4015 typedef basic_istream<_CharT, _Traits> _Istream;
4016 __is.flags(_Istream::dec | _Istream::skipws);
4017 double __p;
4018 __is >> __p;
4019 if (!__is.fail())
4020 __x.param(param_type(__p));
4021 return __is;
4022}
4023
4024// binomial_distribution
4025
4026template<class _IntType = int>
4027class _LIBCPP_TEMPLATE_VIS binomial_distribution
4028{
4029public:
4030 // types
4031 typedef _IntType result_type;
4032
4033 class _LIBCPP_TEMPLATE_VIS param_type
4034 {
4035 result_type __t_;
4036 double __p_;
4037 double __pr_;
4038 double __odds_ratio_;
4039 result_type __r0_;
4040 public:
4041 typedef binomial_distribution distribution_type;
4042
4043 explicit param_type(result_type __t = 1, double __p = 0.5);
4044
4045 _LIBCPP_INLINE_VISIBILITY
4046 result_type t() const {return __t_;}
4047 _LIBCPP_INLINE_VISIBILITY
4048 double p() const {return __p_;}
4049
4050 friend _LIBCPP_INLINE_VISIBILITY
4051 bool operator==(const param_type& __x, const param_type& __y)
4052 {return __x.__t_ == __y.__t_ && __x.__p_ == __y.__p_;}
4053 friend _LIBCPP_INLINE_VISIBILITY
4054 bool operator!=(const param_type& __x, const param_type& __y)
4055 {return !(__x == __y);}
4056
4057 friend class binomial_distribution;
4058 };
4059
4060private:
4061 param_type __p_;
4062
4063public:
4064 // constructors and reset functions
4065#ifndef _LIBCPP_CXX03_LANG
4066 _LIBCPP_INLINE_VISIBILITY
4067 binomial_distribution() : binomial_distribution(1) {}
4068 _LIBCPP_INLINE_VISIBILITY
4069 explicit binomial_distribution(result_type __t, double __p = 0.5)
4070 : __p_(param_type(__t, __p)) {}
4071#else
4072 _LIBCPP_INLINE_VISIBILITY
4073 explicit binomial_distribution(result_type __t = 1, double __p = 0.5)
4074 : __p_(param_type(__t, __p)) {}
4075#endif
4076 _LIBCPP_INLINE_VISIBILITY
4077 explicit binomial_distribution(const param_type& __p) : __p_(__p) {}
4078 _LIBCPP_INLINE_VISIBILITY
4079 void reset() {}
4080
4081 // generating functions
4082 template<class _URNG>
4083 _LIBCPP_INLINE_VISIBILITY
4084 result_type operator()(_URNG& __g)
4085 {return (*this)(__g, __p_);}
4086 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
4087
4088 // property functions
4089 _LIBCPP_INLINE_VISIBILITY
4090 result_type t() const {return __p_.t();}
4091 _LIBCPP_INLINE_VISIBILITY
4092 double p() const {return __p_.p();}
4093
4094 _LIBCPP_INLINE_VISIBILITY
4095 param_type param() const {return __p_;}
4096 _LIBCPP_INLINE_VISIBILITY
4097 void param(const param_type& __p) {__p_ = __p;}
4098
4099 _LIBCPP_INLINE_VISIBILITY
4100 result_type min() const {return 0;}
4101 _LIBCPP_INLINE_VISIBILITY
4102 result_type max() const {return t();}
4103
4104 friend _LIBCPP_INLINE_VISIBILITY
4105 bool operator==(const binomial_distribution& __x,
4106 const binomial_distribution& __y)
4107 {return __x.__p_ == __y.__p_;}
4108 friend _LIBCPP_INLINE_VISIBILITY
4109 bool operator!=(const binomial_distribution& __x,
4110 const binomial_distribution& __y)
4111 {return !(__x == __y);}
4112};
4113
4114#ifndef _LIBCPP_MSVCRT_LIKE
4115extern "C" double lgamma_r(double, int *);
4116#endif
4117
4118inline _LIBCPP_INLINE_VISIBILITY double __libcpp_lgamma(double __d) {
4119#if defined(_LIBCPP_MSVCRT_LIKE)
4120 return lgamma(__d);
4121#else
4122 int __sign;
4123 return lgamma_r(__d, &__sign);
4124#endif
4125}
4126
4127template<class _IntType>
4128binomial_distribution<_IntType>::param_type::param_type(result_type __t, double __p)
4129 : __t_(__t), __p_(__p)
4130{
4131 if (0 < __p_ && __p_ < 1)
4132 {
4133 __r0_ = static_cast<result_type>((__t_ + 1) * __p_);
4134 __pr_ = _VSTD::exp(__libcpp_lgamma(__t_ + 1.) -
4135 __libcpp_lgamma(__r0_ + 1.) -
4136 __libcpp_lgamma(__t_ - __r0_ + 1.) + __r0_ * _VSTD::log(__p_) +
4137 (__t_ - __r0_) * _VSTD::log(1 - __p_));
4138 __odds_ratio_ = __p_ / (1 - __p_);
4139 }
4140}
4141
4142// Reference: Kemp, C.D. (1986). `A modal method for generating binomial
4143// variables', Commun. Statist. - Theor. Meth. 15(3), 805-813.
4144template<class _IntType>
4145template<class _URNG>
4146_IntType
4147binomial_distribution<_IntType>::operator()(_URNG& __g, const param_type& __pr)
4148{
4149 if (__pr.__t_ == 0 || __pr.__p_ == 0)
4150 return 0;
4151 if (__pr.__p_ == 1)
4152 return __pr.__t_;
4153 uniform_real_distribution<double> __gen;
4154 double __u = __gen(__g) - __pr.__pr_;
4155 if (__u < 0)
4156 return __pr.__r0_;
4157 double __pu = __pr.__pr_;
4158 double __pd = __pu;
4159 result_type __ru = __pr.__r0_;
4160 result_type __rd = __ru;
4161 while (true)
4162 {
4163 bool __break = true;
4164 if (__rd >= 1)
4165 {
4166 __pd *= __rd / (__pr.__odds_ratio_ * (__pr.__t_ - __rd + 1));
4167 __u -= __pd;
4168 __break = false;
4169 if (__u < 0)
4170 return __rd - 1;
4171 }
4172 if ( __rd != 0 )
4173 --__rd;
4174 ++__ru;
4175 if (__ru <= __pr.__t_)
4176 {
4177 __pu *= (__pr.__t_ - __ru + 1) * __pr.__odds_ratio_ / __ru;
4178 __u -= __pu;
4179 __break = false;
4180 if (__u < 0)
4181 return __ru;
4182 }
4183 if (__break)
4184 return 0;
4185 }
4186}
4187
4188template <class _CharT, class _Traits, class _IntType>
4189basic_ostream<_CharT, _Traits>&
4190operator<<(basic_ostream<_CharT, _Traits>& __os,
4191 const binomial_distribution<_IntType>& __x)
4192{
4193 __save_flags<_CharT, _Traits> __lx(__os);
4194 typedef basic_ostream<_CharT, _Traits> _OStream;
4195 __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
4196 _OStream::scientific);
4197 _CharT __sp = __os.widen(' ');
4198 __os.fill(__sp);
4199 return __os << __x.t() << __sp << __x.p();
4200}
4201
4202template <class _CharT, class _Traits, class _IntType>
4203basic_istream<_CharT, _Traits>&
4204operator>>(basic_istream<_CharT, _Traits>& __is,
4205 binomial_distribution<_IntType>& __x)
4206{
4207 typedef binomial_distribution<_IntType> _Eng;
4208 typedef typename _Eng::result_type result_type;
4209 typedef typename _Eng::param_type param_type;
4210 __save_flags<_CharT, _Traits> __lx(__is);
4211 typedef basic_istream<_CharT, _Traits> _Istream;
4212 __is.flags(_Istream::dec | _Istream::skipws);
4213 result_type __t;
4214 double __p;
4215 __is >> __t >> __p;
4216 if (!__is.fail())
4217 __x.param(param_type(__t, __p));
4218 return __is;
4219}
4220
4221// exponential_distribution
4222
4223template<class _RealType = double>
4224class _LIBCPP_TEMPLATE_VIS exponential_distribution
4225{
4226public:
4227 // types
4228 typedef _RealType result_type;
4229
4230 class _LIBCPP_TEMPLATE_VIS param_type
4231 {
4232 result_type __lambda_;
4233 public:
4234 typedef exponential_distribution distribution_type;
4235
4236 _LIBCPP_INLINE_VISIBILITY
4237 explicit param_type(result_type __lambda = 1) : __lambda_(__lambda) {}
4238
4239 _LIBCPP_INLINE_VISIBILITY
4240 result_type lambda() const {return __lambda_;}
4241
4242 friend _LIBCPP_INLINE_VISIBILITY
4243 bool operator==(const param_type& __x, const param_type& __y)
4244 {return __x.__lambda_ == __y.__lambda_;}
4245 friend _LIBCPP_INLINE_VISIBILITY
4246 bool operator!=(const param_type& __x, const param_type& __y)
4247 {return !(__x == __y);}
4248 };
4249
4250private:
4251 param_type __p_;
4252
4253public:
4254 // constructors and reset functions
4255#ifndef _LIBCPP_CXX03_LANG
4256 _LIBCPP_INLINE_VISIBILITY
4257 exponential_distribution() : exponential_distribution(1) {}
4258 _LIBCPP_INLINE_VISIBILITY
4259 explicit exponential_distribution(result_type __lambda)
4260 : __p_(param_type(__lambda)) {}
4261#else
4262 _LIBCPP_INLINE_VISIBILITY
4263 explicit exponential_distribution(result_type __lambda = 1)
4264 : __p_(param_type(__lambda)) {}
4265#endif
4266 _LIBCPP_INLINE_VISIBILITY
4267 explicit exponential_distribution(const param_type& __p) : __p_(__p) {}
4268 _LIBCPP_INLINE_VISIBILITY
4269 void reset() {}
4270
4271 // generating functions
4272 template<class _URNG>
4273 _LIBCPP_INLINE_VISIBILITY
4274 result_type operator()(_URNG& __g)
4275 {return (*this)(__g, __p_);}
4276 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
4277
4278 // property functions
4279 _LIBCPP_INLINE_VISIBILITY
4280 result_type lambda() const {return __p_.lambda();}
4281
4282 _LIBCPP_INLINE_VISIBILITY
4283 param_type param() const {return __p_;}
4284 _LIBCPP_INLINE_VISIBILITY
4285 void param(const param_type& __p) {__p_ = __p;}
4286
4287 _LIBCPP_INLINE_VISIBILITY
4288 result_type min() const {return 0;}
4289 _LIBCPP_INLINE_VISIBILITY
4290 result_type max() const {return numeric_limits<result_type>::infinity();}
4291
4292 friend _LIBCPP_INLINE_VISIBILITY
4293 bool operator==(const exponential_distribution& __x,
4294 const exponential_distribution& __y)
4295 {return __x.__p_ == __y.__p_;}
4296 friend _LIBCPP_INLINE_VISIBILITY
4297 bool operator!=(const exponential_distribution& __x,
4298 const exponential_distribution& __y)
4299 {return !(__x == __y);}
4300};
4301
4302template <class _RealType>
4303template<class _URNG>
4304_RealType
4305exponential_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
4306{
4307 return -_VSTD::log
4308 (
4309 result_type(1) -
4310 _VSTD::generate_canonical<result_type,
4311 numeric_limits<result_type>::digits>(__g)
4312 )
4313 / __p.lambda();
4314}
4315
4316template <class _CharT, class _Traits, class _RealType>
4317basic_ostream<_CharT, _Traits>&
4318operator<<(basic_ostream<_CharT, _Traits>& __os,
4319 const exponential_distribution<_RealType>& __x)
4320{
4321 __save_flags<_CharT, _Traits> __lx(__os);
4322 typedef basic_ostream<_CharT, _Traits> _OStream;
4323 __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
4324 _OStream::scientific);
4325 return __os << __x.lambda();
4326}
4327
4328template <class _CharT, class _Traits, class _RealType>
4329basic_istream<_CharT, _Traits>&
4330operator>>(basic_istream<_CharT, _Traits>& __is,
4331 exponential_distribution<_RealType>& __x)
4332{
4333 typedef exponential_distribution<_RealType> _Eng;
4334 typedef typename _Eng::result_type result_type;
4335 typedef typename _Eng::param_type param_type;
4336 __save_flags<_CharT, _Traits> __lx(__is);
4337 typedef basic_istream<_CharT, _Traits> _Istream;
4338 __is.flags(_Istream::dec | _Istream::skipws);
4339 result_type __lambda;
4340 __is >> __lambda;
4341 if (!__is.fail())
4342 __x.param(param_type(__lambda));
4343 return __is;
4344}
4345
4346// normal_distribution
4347
4348template<class _RealType = double>
4349class _LIBCPP_TEMPLATE_VIS normal_distribution
4350{
4351public:
4352 // types
4353 typedef _RealType result_type;
4354
4355 class _LIBCPP_TEMPLATE_VIS param_type
4356 {
4357 result_type __mean_;
4358 result_type __stddev_;
4359 public:
4360 typedef normal_distribution distribution_type;
4361
4362 _LIBCPP_INLINE_VISIBILITY
4363 explicit param_type(result_type __mean = 0, result_type __stddev = 1)
4364 : __mean_(__mean), __stddev_(__stddev) {}
4365
4366 _LIBCPP_INLINE_VISIBILITY
4367 result_type mean() const {return __mean_;}
4368 _LIBCPP_INLINE_VISIBILITY
4369 result_type stddev() const {return __stddev_;}
4370
4371 friend _LIBCPP_INLINE_VISIBILITY
4372 bool operator==(const param_type& __x, const param_type& __y)
4373 {return __x.__mean_ == __y.__mean_ && __x.__stddev_ == __y.__stddev_;}
4374 friend _LIBCPP_INLINE_VISIBILITY
4375 bool operator!=(const param_type& __x, const param_type& __y)
4376 {return !(__x == __y);}
4377 };
4378
4379private:
4380 param_type __p_;
4381 result_type _V_;
4382 bool _V_hot_;
4383
4384public:
4385 // constructors and reset functions
4386#ifndef _LIBCPP_CXX03_LANG
4387 _LIBCPP_INLINE_VISIBILITY
4388 normal_distribution() : normal_distribution(0) {}
4389 _LIBCPP_INLINE_VISIBILITY
4390 explicit normal_distribution(result_type __mean, result_type __stddev = 1)
4391 : __p_(param_type(__mean, __stddev)), _V_hot_(false) {}
4392#else
4393 _LIBCPP_INLINE_VISIBILITY
4394 explicit normal_distribution(result_type __mean = 0,
4395 result_type __stddev = 1)
4396 : __p_(param_type(__mean, __stddev)), _V_hot_(false) {}
4397#endif
4398 _LIBCPP_INLINE_VISIBILITY
4399 explicit normal_distribution(const param_type& __p)
4400 : __p_(__p), _V_hot_(false) {}
4401 _LIBCPP_INLINE_VISIBILITY
4402 void reset() {_V_hot_ = false;}
4403
4404 // generating functions
4405 template<class _URNG>
4406 _LIBCPP_INLINE_VISIBILITY
4407 result_type operator()(_URNG& __g)
4408 {return (*this)(__g, __p_);}
4409 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
4410
4411 // property functions
4412 _LIBCPP_INLINE_VISIBILITY
4413 result_type mean() const {return __p_.mean();}
4414 _LIBCPP_INLINE_VISIBILITY
4415 result_type stddev() const {return __p_.stddev();}
4416
4417 _LIBCPP_INLINE_VISIBILITY
4418 param_type param() const {return __p_;}
4419 _LIBCPP_INLINE_VISIBILITY
4420 void param(const param_type& __p) {__p_ = __p;}
4421
4422 _LIBCPP_INLINE_VISIBILITY
4423 result_type min() const {return -numeric_limits<result_type>::infinity();}
4424 _LIBCPP_INLINE_VISIBILITY
4425 result_type max() const {return numeric_limits<result_type>::infinity();}
4426
4427 friend _LIBCPP_INLINE_VISIBILITY
4428 bool operator==(const normal_distribution& __x,
4429 const normal_distribution& __y)
4430 {return __x.__p_ == __y.__p_ && __x._V_hot_ == __y._V_hot_ &&
4431 (!__x._V_hot_ || __x._V_ == __y._V_);}
4432 friend _LIBCPP_INLINE_VISIBILITY
4433 bool operator!=(const normal_distribution& __x,
4434 const normal_distribution& __y)
4435 {return !(__x == __y);}
4436
4437 template <class _CharT, class _Traits, class _RT>
4438 friend
4439 basic_ostream<_CharT, _Traits>&
4440 operator<<(basic_ostream<_CharT, _Traits>& __os,
4441 const normal_distribution<_RT>& __x);
4442
4443 template <class _CharT, class _Traits, class _RT>
4444 friend
4445 basic_istream<_CharT, _Traits>&
4446 operator>>(basic_istream<_CharT, _Traits>& __is,
4447 normal_distribution<_RT>& __x);
4448};
4449
4450template <class _RealType>
4451template<class _URNG>
4452_RealType
4453normal_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
4454{
4455 result_type _Up;
4456 if (_V_hot_)
4457 {
4458 _V_hot_ = false;
4459 _Up = _V_;
4460 }
4461 else
4462 {
4463 uniform_real_distribution<result_type> _Uni(-1, 1);
4464 result_type __u;
4465 result_type __v;
4466 result_type __s;
4467 do
4468 {
4469 __u = _Uni(__g);
4470 __v = _Uni(__g);
4471 __s = __u * __u + __v * __v;
4472 } while (__s > 1 || __s == 0);
4473 result_type _Fp = _VSTD::sqrt(-2 * _VSTD::log(__s) / __s);
4474 _V_ = __v * _Fp;
4475 _V_hot_ = true;
4476 _Up = __u * _Fp;
4477 }
4478 return _Up * __p.stddev() + __p.mean();
4479}
4480
4481template <class _CharT, class _Traits, class _RT>
4482basic_ostream<_CharT, _Traits>&
4483operator<<(basic_ostream<_CharT, _Traits>& __os,
4484 const normal_distribution<_RT>& __x)
4485{
4486 __save_flags<_CharT, _Traits> __lx(__os);
4487 typedef basic_ostream<_CharT, _Traits> _OStream;
4488 __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
4489 _OStream::scientific);
4490 _CharT __sp = __os.widen(' ');
4491 __os.fill(__sp);
4492 __os << __x.mean() << __sp << __x.stddev() << __sp << __x._V_hot_;
4493 if (__x._V_hot_)
4494 __os << __sp << __x._V_;
4495 return __os;
4496}
4497
4498template <class _CharT, class _Traits, class _RT>
4499basic_istream<_CharT, _Traits>&
4500operator>>(basic_istream<_CharT, _Traits>& __is,
4501 normal_distribution<_RT>& __x)
4502{
4503 typedef normal_distribution<_RT> _Eng;
4504 typedef typename _Eng::result_type result_type;
4505 typedef typename _Eng::param_type param_type;
4506 __save_flags<_CharT, _Traits> __lx(__is);
4507 typedef basic_istream<_CharT, _Traits> _Istream;
4508 __is.flags(_Istream::dec | _Istream::skipws);
4509 result_type __mean;
4510 result_type __stddev;
4511 result_type _Vp = 0;
4512 bool _V_hot = false;
4513 __is >> __mean >> __stddev >> _V_hot;
4514 if (_V_hot)
4515 __is >> _Vp;
4516 if (!__is.fail())
4517 {
4518 __x.param(param_type(__mean, __stddev));
4519 __x._V_hot_ = _V_hot;
4520 __x._V_ = _Vp;
4521 }
4522 return __is;
4523}
4524
4525// lognormal_distribution
4526
4527template<class _RealType = double>
4528class _LIBCPP_TEMPLATE_VIS lognormal_distribution
4529{
4530public:
4531 // types
4532 typedef _RealType result_type;
4533
4534 class _LIBCPP_TEMPLATE_VIS param_type
4535 {
4536 normal_distribution<result_type> __nd_;
4537 public:
4538 typedef lognormal_distribution distribution_type;
4539
4540 _LIBCPP_INLINE_VISIBILITY
4541 explicit param_type(result_type __m = 0, result_type __s = 1)
4542 : __nd_(__m, __s) {}
4543
4544 _LIBCPP_INLINE_VISIBILITY
4545 result_type m() const {return __nd_.mean();}
4546 _LIBCPP_INLINE_VISIBILITY
4547 result_type s() const {return __nd_.stddev();}
4548
4549 friend _LIBCPP_INLINE_VISIBILITY
4550 bool operator==(const param_type& __x, const param_type& __y)
4551 {return __x.__nd_ == __y.__nd_;}
4552 friend _LIBCPP_INLINE_VISIBILITY
4553 bool operator!=(const param_type& __x, const param_type& __y)
4554 {return !(__x == __y);}
4555 friend class lognormal_distribution;
4556
4557 template <class _CharT, class _Traits, class _RT>
4558 friend
4559 basic_ostream<_CharT, _Traits>&
4560 operator<<(basic_ostream<_CharT, _Traits>& __os,
4561 const lognormal_distribution<_RT>& __x);
4562
4563 template <class _CharT, class _Traits, class _RT>
4564 friend
4565 basic_istream<_CharT, _Traits>&
4566 operator>>(basic_istream<_CharT, _Traits>& __is,
4567 lognormal_distribution<_RT>& __x);
4568 };
4569
4570private:
4571 param_type __p_;
4572
4573public:
4574 // constructor and reset functions
4575#ifndef _LIBCPP_CXX03_LANG
4576 _LIBCPP_INLINE_VISIBILITY
4577 lognormal_distribution() : lognormal_distribution(0) {}
4578 _LIBCPP_INLINE_VISIBILITY
4579 explicit lognormal_distribution(result_type __m, result_type __s = 1)
4580 : __p_(param_type(__m, __s)) {}
4581#else
4582 _LIBCPP_INLINE_VISIBILITY
4583 explicit lognormal_distribution(result_type __m = 0,
4584 result_type __s = 1)
4585 : __p_(param_type(__m, __s)) {}
4586#endif
4587 _LIBCPP_INLINE_VISIBILITY
4588 explicit lognormal_distribution(const param_type& __p)
4589 : __p_(__p) {}
4590 _LIBCPP_INLINE_VISIBILITY
4591 void reset() {__p_.__nd_.reset();}
4592
4593 // generating functions
4594 template<class _URNG>
4595 _LIBCPP_INLINE_VISIBILITY
4596 result_type operator()(_URNG& __g)
4597 {return (*this)(__g, __p_);}
4598 template<class _URNG>
4599 _LIBCPP_INLINE_VISIBILITY
4600 result_type operator()(_URNG& __g, const param_type& __p)
4601 {return _VSTD::exp(const_cast<normal_distribution<result_type>&>(__p.__nd_)(__g));}
4602
4603 // property functions
4604 _LIBCPP_INLINE_VISIBILITY
4605 result_type m() const {return __p_.m();}
4606 _LIBCPP_INLINE_VISIBILITY
4607 result_type s() const {return __p_.s();}
4608
4609 _LIBCPP_INLINE_VISIBILITY
4610 param_type param() const {return __p_;}
4611 _LIBCPP_INLINE_VISIBILITY
4612 void param(const param_type& __p) {__p_ = __p;}
4613
4614 _LIBCPP_INLINE_VISIBILITY
4615 result_type min() const {return 0;}
4616 _LIBCPP_INLINE_VISIBILITY
4617 result_type max() const {return numeric_limits<result_type>::infinity();}
4618
4619 friend _LIBCPP_INLINE_VISIBILITY
4620 bool operator==(const lognormal_distribution& __x,
4621 const lognormal_distribution& __y)
4622 {return __x.__p_ == __y.__p_;}
4623 friend _LIBCPP_INLINE_VISIBILITY
4624 bool operator!=(const lognormal_distribution& __x,
4625 const lognormal_distribution& __y)
4626 {return !(__x == __y);}
4627
4628 template <class _CharT, class _Traits, class _RT>
4629 friend
4630 basic_ostream<_CharT, _Traits>&
4631 operator<<(basic_ostream<_CharT, _Traits>& __os,
4632 const lognormal_distribution<_RT>& __x);
4633
4634 template <class _CharT, class _Traits, class _RT>
4635 friend
4636 basic_istream<_CharT, _Traits>&
4637 operator>>(basic_istream<_CharT, _Traits>& __is,
4638 lognormal_distribution<_RT>& __x);
4639};
4640
4641template <class _CharT, class _Traits, class _RT>
4642inline _LIBCPP_INLINE_VISIBILITY
4643basic_ostream<_CharT, _Traits>&
4644operator<<(basic_ostream<_CharT, _Traits>& __os,
4645 const lognormal_distribution<_RT>& __x)
4646{
4647 return __os << __x.__p_.__nd_;
4648}
4649
4650template <class _CharT, class _Traits, class _RT>
4651inline _LIBCPP_INLINE_VISIBILITY
4652basic_istream<_CharT, _Traits>&
4653operator>>(basic_istream<_CharT, _Traits>& __is,
4654 lognormal_distribution<_RT>& __x)
4655{
4656 return __is >> __x.__p_.__nd_;
4657}
4658
4659// poisson_distribution
4660
4661template<class _IntType = int>
4662class _LIBCPP_TEMPLATE_VIS poisson_distribution
4663{
4664public:
4665 // types
4666 typedef _IntType result_type;
4667
4668 class _LIBCPP_TEMPLATE_VIS param_type
4669 {
4670 double __mean_;
4671 double __s_;
4672 double __d_;
4673 double __l_;
4674 double __omega_;
4675 double __c0_;
4676 double __c1_;
4677 double __c2_;
4678 double __c3_;
4679 double __c_;
4680
4681 public:
4682 typedef poisson_distribution distribution_type;
4683
4684 explicit param_type(double __mean = 1.0);
4685
4686 _LIBCPP_INLINE_VISIBILITY
4687 double mean() const {return __mean_;}
4688
4689 friend _LIBCPP_INLINE_VISIBILITY
4690 bool operator==(const param_type& __x, const param_type& __y)
4691 {return __x.__mean_ == __y.__mean_;}
4692 friend _LIBCPP_INLINE_VISIBILITY
4693 bool operator!=(const param_type& __x, const param_type& __y)
4694 {return !(__x == __y);}
4695
4696 friend class poisson_distribution;
4697 };
4698
4699private:
4700 param_type __p_;
4701
4702public:
4703 // constructors and reset functions
4704#ifndef _LIBCPP_CXX03_LANG
4705 _LIBCPP_INLINE_VISIBILITY
4706 poisson_distribution() : poisson_distribution(1.0) {}
4707 _LIBCPP_INLINE_VISIBILITY
4708 explicit poisson_distribution(double __mean)
4709 : __p_(__mean) {}
4710#else
4711 _LIBCPP_INLINE_VISIBILITY
4712 explicit poisson_distribution(double __mean = 1.0)
4713 : __p_(__mean) {}
4714#endif
4715 _LIBCPP_INLINE_VISIBILITY
4716 explicit poisson_distribution(const param_type& __p) : __p_(__p) {}
4717 _LIBCPP_INLINE_VISIBILITY
4718 void reset() {}
4719
4720 // generating functions
4721 template<class _URNG>
4722 _LIBCPP_INLINE_VISIBILITY
4723 result_type operator()(_URNG& __g)
4724 {return (*this)(__g, __p_);}
4725 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
4726
4727 // property functions
4728 _LIBCPP_INLINE_VISIBILITY
4729 double mean() const {return __p_.mean();}
4730
4731 _LIBCPP_INLINE_VISIBILITY
4732 param_type param() const {return __p_;}
4733 _LIBCPP_INLINE_VISIBILITY
4734 void param(const param_type& __p) {__p_ = __p;}
4735
4736 _LIBCPP_INLINE_VISIBILITY
4737 result_type min() const {return 0;}
4738 _LIBCPP_INLINE_VISIBILITY
4739 result_type max() const {return numeric_limits<result_type>::max();}
4740
4741 friend _LIBCPP_INLINE_VISIBILITY
4742 bool operator==(const poisson_distribution& __x,
4743 const poisson_distribution& __y)
4744 {return __x.__p_ == __y.__p_;}
4745 friend _LIBCPP_INLINE_VISIBILITY
4746 bool operator!=(const poisson_distribution& __x,
4747 const poisson_distribution& __y)
4748 {return !(__x == __y);}
4749};
4750
4751template<class _IntType>
4752poisson_distribution<_IntType>::param_type::param_type(double __mean)
4753 // According to the standard `inf` is a valid input, but it causes the
4754 // distribution to hang, so we replace it with the maximum representable
4755 // mean.
4756 : __mean_(isinf(__mean) ? numeric_limits<double>::max() : __mean)
4757{
4758 if (__mean_ < 10)
4759 {
4760 __s_ = 0;
4761 __d_ = 0;
4762 __l_ = _VSTD::exp(-__mean_);
4763 __omega_ = 0;
4764 __c3_ = 0;
4765 __c2_ = 0;
4766 __c1_ = 0;
4767 __c0_ = 0;
4768 __c_ = 0;
4769 }
4770 else
4771 {
4772 __s_ = _VSTD::sqrt(__mean_);
4773 __d_ = 6 * __mean_ * __mean_;
4774 __l_ = _VSTD::trunc(__mean_ - 1.1484);
4775 __omega_ = .3989423 / __s_;
4776 double __b1_ = .4166667E-1 / __mean_;
4777 double __b2_ = .3 * __b1_ * __b1_;
4778 __c3_ = .1428571 * __b1_ * __b2_;
4779 __c2_ = __b2_ - 15. * __c3_;
4780 __c1_ = __b1_ - 6. * __b2_ + 45. * __c3_;
4781 __c0_ = 1. - __b1_ + 3. * __b2_ - 15. * __c3_;
4782 __c_ = .1069 / __mean_;
4783 }
4784}
4785
4786template <class _IntType>
4787template<class _URNG>
4788_IntType
4789poisson_distribution<_IntType>::operator()(_URNG& __urng, const param_type& __pr)
4790{
4791 double __tx;
4792 uniform_real_distribution<double> __urd;
4793 if (__pr.__mean_ < 10)
4794 {
4795 __tx = 0;
4796 for (double __p = __urd(__urng); __p > __pr.__l_; ++__tx)
4797 __p *= __urd(__urng);
4798 }
4799 else
4800 {
4801 double __difmuk;
4802 double __g = __pr.__mean_ + __pr.__s_ * normal_distribution<double>()(__urng);
4803 double __u;
4804 if (__g > 0)
4805 {
4806 __tx = _VSTD::trunc(__g);
4807 if (__tx >= __pr.__l_)
4808 return _VSTD::__clamp_to_integral<result_type>(__tx);
4809 __difmuk = __pr.__mean_ - __tx;
4810 __u = __urd(__urng);
4811 if (__pr.__d_ * __u >= __difmuk * __difmuk * __difmuk)
4812 return _VSTD::__clamp_to_integral<result_type>(__tx);
4813 }
4814 exponential_distribution<double> __edist;
4815 for (bool __using_exp_dist = false; true; __using_exp_dist = true)
4816 {
4817 double __e;
4818 if (__using_exp_dist || __g <= 0)
4819 {
4820 double __t;
4821 do
4822 {
4823 __e = __edist(__urng);
4824 __u = __urd(__urng);
4825 __u += __u - 1;
4826 __t = 1.8 + (__u < 0 ? -__e : __e);
4827 } while (__t <= -.6744);
4828 __tx = _VSTD::trunc(__pr.__mean_ + __pr.__s_ * __t);
4829 __difmuk = __pr.__mean_ - __tx;
4830 __using_exp_dist = true;
4831 }
4832 double __px;
4833 double __py;
4834 if (__tx < 10 && __tx >= 0)
4835 {
4836 const double __fac[] = {1, 1, 2, 6, 24, 120, 720, 5040,
4837 40320, 362880};
4838 __px = -__pr.__mean_;
4839 __py = _VSTD::pow(__pr.__mean_, (double)__tx) / __fac[static_cast<int>(__tx)];
4840 }
4841 else
4842 {
4843 double __del = .8333333E-1 / __tx;
4844 __del -= 4.8 * __del * __del * __del;
4845 double __v = __difmuk / __tx;
4846 if (_VSTD::abs(__v) > 0.25)
4847 __px = __tx * _VSTD::log(1 + __v) - __difmuk - __del;
4848 else
4849 __px = __tx * __v * __v * (((((((.1250060 * __v + -.1384794) *
4850 __v + .1421878) * __v + -.1661269) * __v + .2000118) *
4851 __v + -.2500068) * __v + .3333333) * __v + -.5) - __del;
4852 __py = .3989423 / _VSTD::sqrt(__tx);
4853 }
4854 double __r = (0.5 - __difmuk) / __pr.__s_;
4855 double __r2 = __r * __r;
4856 double __fx = -0.5 * __r2;
4857 double __fy = __pr.__omega_ * (((__pr.__c3_ * __r2 + __pr.__c2_) *
4858 __r2 + __pr.__c1_) * __r2 + __pr.__c0_);
4859 if (__using_exp_dist)
4860 {
4861 if (__pr.__c_ * _VSTD::abs(__u) <= __py * _VSTD::exp(__px + __e) -
4862 __fy * _VSTD::exp(__fx + __e))
4863 break;
4864 }
4865 else
4866 {
4867 if (__fy - __u * __fy <= __py * _VSTD::exp(__px - __fx))
4868 break;
4869 }
4870 }
4871 }
4872 return _VSTD::__clamp_to_integral<result_type>(__tx);
4873}
4874
4875template <class _CharT, class _Traits, class _IntType>
4876basic_ostream<_CharT, _Traits>&
4877operator<<(basic_ostream<_CharT, _Traits>& __os,
4878 const poisson_distribution<_IntType>& __x)
4879{
4880 __save_flags<_CharT, _Traits> __lx(__os);
4881 typedef basic_ostream<_CharT, _Traits> _OStream;
4882 __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
4883 _OStream::scientific);
4884 return __os << __x.mean();
4885}
4886
4887template <class _CharT, class _Traits, class _IntType>
4888basic_istream<_CharT, _Traits>&
4889operator>>(basic_istream<_CharT, _Traits>& __is,
4890 poisson_distribution<_IntType>& __x)
4891{
4892 typedef poisson_distribution<_IntType> _Eng;
4893 typedef typename _Eng::param_type param_type;
4894 __save_flags<_CharT, _Traits> __lx(__is);
4895 typedef basic_istream<_CharT, _Traits> _Istream;
4896 __is.flags(_Istream::dec | _Istream::skipws);
4897 double __mean;
4898 __is >> __mean;
4899 if (!__is.fail())
4900 __x.param(param_type(__mean));
4901 return __is;
4902}
4903
4904// weibull_distribution
4905
4906template<class _RealType = double>
4907class _LIBCPP_TEMPLATE_VIS weibull_distribution
4908{
4909public:
4910 // types
4911 typedef _RealType result_type;
4912
4913 class _LIBCPP_TEMPLATE_VIS param_type
4914 {
4915 result_type __a_;
4916 result_type __b_;
4917 public:
4918 typedef weibull_distribution distribution_type;
4919
4920 _LIBCPP_INLINE_VISIBILITY
4921 explicit param_type(result_type __a = 1, result_type __b = 1)
4922 : __a_(__a), __b_(__b) {}
4923
4924 _LIBCPP_INLINE_VISIBILITY
4925 result_type a() const {return __a_;}
4926 _LIBCPP_INLINE_VISIBILITY
4927 result_type b() const {return __b_;}
4928
4929 friend _LIBCPP_INLINE_VISIBILITY
4930 bool operator==(const param_type& __x, const param_type& __y)
4931 {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;}
4932 friend _LIBCPP_INLINE_VISIBILITY
4933 bool operator!=(const param_type& __x, const param_type& __y)
4934 {return !(__x == __y);}
4935 };
4936
4937private:
4938 param_type __p_;
4939
4940public:
4941 // constructor and reset functions
4942#ifndef _LIBCPP_CXX03_LANG
4943 _LIBCPP_INLINE_VISIBILITY
4944 weibull_distribution() : weibull_distribution(1) {}
4945 _LIBCPP_INLINE_VISIBILITY
4946 explicit weibull_distribution(result_type __a, result_type __b = 1)
4947 : __p_(param_type(__a, __b)) {}
4948#else
4949 _LIBCPP_INLINE_VISIBILITY
4950 explicit weibull_distribution(result_type __a = 1, result_type __b = 1)
4951 : __p_(param_type(__a, __b)) {}
4952#endif
4953 _LIBCPP_INLINE_VISIBILITY
4954 explicit weibull_distribution(const param_type& __p)
4955 : __p_(__p) {}
4956 _LIBCPP_INLINE_VISIBILITY
4957 void reset() {}
4958
4959 // generating functions
4960 template<class _URNG>
4961 _LIBCPP_INLINE_VISIBILITY
4962 result_type operator()(_URNG& __g)
4963 {return (*this)(__g, __p_);}
4964 template<class _URNG>
4965 _LIBCPP_INLINE_VISIBILITY
4966 result_type operator()(_URNG& __g, const param_type& __p)
4967 {return __p.b() *
4968 _VSTD::pow(exponential_distribution<result_type>()(__g), 1/__p.a());}
4969
4970 // property functions
4971 _LIBCPP_INLINE_VISIBILITY
4972 result_type a() const {return __p_.a();}
4973 _LIBCPP_INLINE_VISIBILITY
4974 result_type b() const {return __p_.b();}
4975
4976 _LIBCPP_INLINE_VISIBILITY
4977 param_type param() const {return __p_;}
4978 _LIBCPP_INLINE_VISIBILITY
4979 void param(const param_type& __p) {__p_ = __p;}
4980
4981 _LIBCPP_INLINE_VISIBILITY
4982 result_type min() const {return 0;}
4983 _LIBCPP_INLINE_VISIBILITY
4984 result_type max() const {return numeric_limits<result_type>::infinity();}
4985
4986 friend _LIBCPP_INLINE_VISIBILITY
4987 bool operator==(const weibull_distribution& __x,
4988 const weibull_distribution& __y)
4989 {return __x.__p_ == __y.__p_;}
4990 friend _LIBCPP_INLINE_VISIBILITY
4991 bool operator!=(const weibull_distribution& __x,
4992 const weibull_distribution& __y)
4993 {return !(__x == __y);}
4994};
4995
4996template <class _CharT, class _Traits, class _RT>
4997basic_ostream<_CharT, _Traits>&
4998operator<<(basic_ostream<_CharT, _Traits>& __os,
4999 const weibull_distribution<_RT>& __x)
5000{
5001 __save_flags<_CharT, _Traits> __lx(__os);
5002 typedef basic_ostream<_CharT, _Traits> _OStream;
5003 __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
5004 _OStream::scientific);
5005 _CharT __sp = __os.widen(' ');
5006 __os.fill(__sp);
5007 __os << __x.a() << __sp << __x.b();
5008 return __os;
5009}
5010
5011template <class _CharT, class _Traits, class _RT>
5012basic_istream<_CharT, _Traits>&
5013operator>>(basic_istream<_CharT, _Traits>& __is,
5014 weibull_distribution<_RT>& __x)
5015{
5016 typedef weibull_distribution<_RT> _Eng;
5017 typedef typename _Eng::result_type result_type;
5018 typedef typename _Eng::param_type param_type;
5019 __save_flags<_CharT, _Traits> __lx(__is);
5020 typedef basic_istream<_CharT, _Traits> _Istream;
5021 __is.flags(_Istream::dec | _Istream::skipws);
5022 result_type __a;
5023 result_type __b;
5024 __is >> __a >> __b;
5025 if (!__is.fail())
5026 __x.param(param_type(__a, __b));
5027 return __is;
5028}
5029
5030template<class _RealType = double>
5031class _LIBCPP_TEMPLATE_VIS extreme_value_distribution
5032{
5033public:
5034 // types
5035 typedef _RealType result_type;
5036
5037 class _LIBCPP_TEMPLATE_VIS param_type
5038 {
5039 result_type __a_;
5040 result_type __b_;
5041 public:
5042 typedef extreme_value_distribution distribution_type;
5043
5044 _LIBCPP_INLINE_VISIBILITY
5045 explicit param_type(result_type __a = 0, result_type __b = 1)
5046 : __a_(__a), __b_(__b) {}
5047
5048 _LIBCPP_INLINE_VISIBILITY
5049 result_type a() const {return __a_;}
5050 _LIBCPP_INLINE_VISIBILITY
5051 result_type b() const {return __b_;}
5052
5053 friend _LIBCPP_INLINE_VISIBILITY
5054 bool operator==(const param_type& __x, const param_type& __y)
5055 {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;}
5056 friend _LIBCPP_INLINE_VISIBILITY
5057 bool operator!=(const param_type& __x, const param_type& __y)
5058 {return !(__x == __y);}
5059 };
5060
5061private:
5062 param_type __p_;
5063
5064public:
5065 // constructor and reset functions
5066#ifndef _LIBCPP_CXX03_LANG
5067 _LIBCPP_INLINE_VISIBILITY
5068 extreme_value_distribution() : extreme_value_distribution(0) {}
5069 _LIBCPP_INLINE_VISIBILITY
5070 explicit extreme_value_distribution(result_type __a, result_type __b = 1)
5071 : __p_(param_type(__a, __b)) {}
5072#else
5073 _LIBCPP_INLINE_VISIBILITY
5074 explicit extreme_value_distribution(result_type __a = 0,
5075 result_type __b = 1)
5076 : __p_(param_type(__a, __b)) {}
5077#endif
5078 _LIBCPP_INLINE_VISIBILITY
5079 explicit extreme_value_distribution(const param_type& __p)
5080 : __p_(__p) {}
5081 _LIBCPP_INLINE_VISIBILITY
5082 void reset() {}
5083
5084 // generating functions
5085 template<class _URNG>
5086 _LIBCPP_INLINE_VISIBILITY
5087 result_type operator()(_URNG& __g)
5088 {return (*this)(__g, __p_);}
5089 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
5090
5091 // property functions
5092 _LIBCPP_INLINE_VISIBILITY
5093 result_type a() const {return __p_.a();}
5094 _LIBCPP_INLINE_VISIBILITY
5095 result_type b() const {return __p_.b();}
5096
5097 _LIBCPP_INLINE_VISIBILITY
5098 param_type param() const {return __p_;}
5099 _LIBCPP_INLINE_VISIBILITY
5100 void param(const param_type& __p) {__p_ = __p;}
5101
5102 _LIBCPP_INLINE_VISIBILITY
5103 result_type min() const {return -numeric_limits<result_type>::infinity();}
5104 _LIBCPP_INLINE_VISIBILITY
5105 result_type max() const {return numeric_limits<result_type>::infinity();}
5106
5107 friend _LIBCPP_INLINE_VISIBILITY
5108 bool operator==(const extreme_value_distribution& __x,
5109 const extreme_value_distribution& __y)
5110 {return __x.__p_ == __y.__p_;}
5111 friend _LIBCPP_INLINE_VISIBILITY
5112 bool operator!=(const extreme_value_distribution& __x,
5113 const extreme_value_distribution& __y)
5114 {return !(__x == __y);}
5115};
5116
5117template<class _RealType>
5118template<class _URNG>
5119_RealType
5120extreme_value_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
5121{
5122 return __p.a() - __p.b() *
5123 _VSTD::log(-_VSTD::log(1-uniform_real_distribution<result_type>()(__g)));
5124}
5125
5126template <class _CharT, class _Traits, class _RT>
5127basic_ostream<_CharT, _Traits>&
5128operator<<(basic_ostream<_CharT, _Traits>& __os,
5129 const extreme_value_distribution<_RT>& __x)
5130{
5131 __save_flags<_CharT, _Traits> __lx(__os);
5132 typedef basic_ostream<_CharT, _Traits> _OStream;
5133 __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
5134 _OStream::scientific);
5135 _CharT __sp = __os.widen(' ');
5136 __os.fill(__sp);
5137 __os << __x.a() << __sp << __x.b();
5138 return __os;
5139}
5140
5141template <class _CharT, class _Traits, class _RT>
5142basic_istream<_CharT, _Traits>&
5143operator>>(basic_istream<_CharT, _Traits>& __is,
5144 extreme_value_distribution<_RT>& __x)
5145{
5146 typedef extreme_value_distribution<_RT> _Eng;
5147 typedef typename _Eng::result_type result_type;
5148 typedef typename _Eng::param_type param_type;
5149 __save_flags<_CharT, _Traits> __lx(__is);
5150 typedef basic_istream<_CharT, _Traits> _Istream;
5151 __is.flags(_Istream::dec | _Istream::skipws);
5152 result_type __a;
5153 result_type __b;
5154 __is >> __a >> __b;
5155 if (!__is.fail())
5156 __x.param(param_type(__a, __b));
5157 return __is;
5158}
5159
5160// gamma_distribution
5161
5162template<class _RealType = double>
5163class _LIBCPP_TEMPLATE_VIS gamma_distribution
5164{
5165public:
5166 // types
5167 typedef _RealType result_type;
5168
5169 class _LIBCPP_TEMPLATE_VIS param_type
5170 {
5171 result_type __alpha_;
5172 result_type __beta_;
5173 public:
5174 typedef gamma_distribution distribution_type;
5175
5176 _LIBCPP_INLINE_VISIBILITY
5177 explicit param_type(result_type __alpha = 1, result_type __beta = 1)
5178 : __alpha_(__alpha), __beta_(__beta) {}
5179
5180 _LIBCPP_INLINE_VISIBILITY
5181 result_type alpha() const {return __alpha_;}
5182 _LIBCPP_INLINE_VISIBILITY
5183 result_type beta() const {return __beta_;}
5184
5185 friend _LIBCPP_INLINE_VISIBILITY
5186 bool operator==(const param_type& __x, const param_type& __y)
5187 {return __x.__alpha_ == __y.__alpha_ && __x.__beta_ == __y.__beta_;}
5188 friend _LIBCPP_INLINE_VISIBILITY
5189 bool operator!=(const param_type& __x, const param_type& __y)
5190 {return !(__x == __y);}
5191 };
5192
5193private:
5194 param_type __p_;
5195
5196public:
5197 // constructors and reset functions
5198#ifndef _LIBCPP_CXX03_LANG
5199 _LIBCPP_INLINE_VISIBILITY
5200 gamma_distribution() : gamma_distribution(1) {}
5201 _LIBCPP_INLINE_VISIBILITY
5202 explicit gamma_distribution(result_type __alpha, result_type __beta = 1)
5203 : __p_(param_type(__alpha, __beta)) {}
5204#else
5205 _LIBCPP_INLINE_VISIBILITY
5206 explicit gamma_distribution(result_type __alpha = 1,
5207 result_type __beta = 1)
5208 : __p_(param_type(__alpha, __beta)) {}
5209#endif
5210 _LIBCPP_INLINE_VISIBILITY
5211 explicit gamma_distribution(const param_type& __p)
5212 : __p_(__p) {}
5213 _LIBCPP_INLINE_VISIBILITY
5214 void reset() {}
5215
5216 // generating functions
5217 template<class _URNG>
5218 _LIBCPP_INLINE_VISIBILITY
5219 result_type operator()(_URNG& __g)
5220 {return (*this)(__g, __p_);}
5221 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
5222
5223 // property functions
5224 _LIBCPP_INLINE_VISIBILITY
5225 result_type alpha() const {return __p_.alpha();}
5226 _LIBCPP_INLINE_VISIBILITY
5227 result_type beta() const {return __p_.beta();}
5228
5229 _LIBCPP_INLINE_VISIBILITY
5230 param_type param() const {return __p_;}
5231 _LIBCPP_INLINE_VISIBILITY
5232 void param(const param_type& __p) {__p_ = __p;}
5233
5234 _LIBCPP_INLINE_VISIBILITY
5235 result_type min() const {return 0;}
5236 _LIBCPP_INLINE_VISIBILITY
5237 result_type max() const {return numeric_limits<result_type>::infinity();}
5238
5239 friend _LIBCPP_INLINE_VISIBILITY
5240 bool operator==(const gamma_distribution& __x,
5241 const gamma_distribution& __y)
5242 {return __x.__p_ == __y.__p_;}
5243 friend _LIBCPP_INLINE_VISIBILITY
5244 bool operator!=(const gamma_distribution& __x,
5245 const gamma_distribution& __y)
5246 {return !(__x == __y);}
5247};
5248
5249template <class _RealType>
5250template<class _URNG>
5251_RealType
5252gamma_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
5253{
5254 result_type __a = __p.alpha();
5255 uniform_real_distribution<result_type> __gen(0, 1);
5256 exponential_distribution<result_type> __egen;
5257 result_type __x;
5258 if (__a == 1)
5259 __x = __egen(__g);
5260 else if (__a > 1)
5261 {
5262 const result_type __b = __a - 1;
5263 const result_type __c = 3 * __a - result_type(0.75);
5264 while (true)
5265 {
5266 const result_type __u = __gen(__g);
5267 const result_type __v = __gen(__g);
5268 const result_type __w = __u * (1 - __u);
5269 if (__w != 0)
5270 {
5271 const result_type __y = _VSTD::sqrt(__c / __w) *
5272 (__u - result_type(0.5));
5273 __x = __b + __y;
5274 if (__x >= 0)
5275 {
5276 const result_type __z = 64 * __w * __w * __w * __v * __v;
5277 if (__z <= 1 - 2 * __y * __y / __x)
5278 break;
5279 if (_VSTD::log(__z) <= 2 * (__b * _VSTD::log(__x / __b) - __y))
5280 break;
5281 }
5282 }
5283 }
5284 }
5285 else // __a < 1
5286 {
5287 while (true)
5288 {
5289 const result_type __u = __gen(__g);
5290 const result_type __es = __egen(__g);
5291 if (__u <= 1 - __a)
5292 {
5293 __x = _VSTD::pow(__u, 1 / __a);
5294 if (__x <= __es)
5295 break;
5296 }
5297 else
5298 {
5299 const result_type __e = -_VSTD::log((1-__u)/__a);
5300 __x = _VSTD::pow(1 - __a + __a * __e, 1 / __a);
5301 if (__x <= __e + __es)
5302 break;
5303 }
5304 }
5305 }
5306 return __x * __p.beta();
5307}
5308
5309template <class _CharT, class _Traits, class _RT>
5310basic_ostream<_CharT, _Traits>&
5311operator<<(basic_ostream<_CharT, _Traits>& __os,
5312 const gamma_distribution<_RT>& __x)
5313{
5314 __save_flags<_CharT, _Traits> __lx(__os);
5315 typedef basic_ostream<_CharT, _Traits> _OStream;
5316 __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
5317 _OStream::scientific);
5318 _CharT __sp = __os.widen(' ');
5319 __os.fill(__sp);
5320 __os << __x.alpha() << __sp << __x.beta();
5321 return __os;
5322}
5323
5324template <class _CharT, class _Traits, class _RT>
5325basic_istream<_CharT, _Traits>&
5326operator>>(basic_istream<_CharT, _Traits>& __is,
5327 gamma_distribution<_RT>& __x)
5328{
5329 typedef gamma_distribution<_RT> _Eng;
5330 typedef typename _Eng::result_type result_type;
5331 typedef typename _Eng::param_type param_type;
5332 __save_flags<_CharT, _Traits> __lx(__is);
5333 typedef basic_istream<_CharT, _Traits> _Istream;
5334 __is.flags(_Istream::dec | _Istream::skipws);
5335 result_type __alpha;
5336 result_type __beta;
5337 __is >> __alpha >> __beta;
5338 if (!__is.fail())
5339 __x.param(param_type(__alpha, __beta));
5340 return __is;
5341}
5342
5343// negative_binomial_distribution
5344
5345template<class _IntType = int>
5346class _LIBCPP_TEMPLATE_VIS negative_binomial_distribution
5347{
5348public:
5349 // types
5350 typedef _IntType result_type;
5351
5352 class _LIBCPP_TEMPLATE_VIS param_type
5353 {
5354 result_type __k_;
5355 double __p_;
5356 public:
5357 typedef negative_binomial_distribution distribution_type;
5358
5359 _LIBCPP_INLINE_VISIBILITY
5360 explicit param_type(result_type __k = 1, double __p = 0.5)
5361 : __k_(__k), __p_(__p) {}
5362
5363 _LIBCPP_INLINE_VISIBILITY
5364 result_type k() const {return __k_;}
5365 _LIBCPP_INLINE_VISIBILITY
5366 double p() const {return __p_;}
5367
5368 friend _LIBCPP_INLINE_VISIBILITY
5369 bool operator==(const param_type& __x, const param_type& __y)
5370 {return __x.__k_ == __y.__k_ && __x.__p_ == __y.__p_;}
5371 friend _LIBCPP_INLINE_VISIBILITY
5372 bool operator!=(const param_type& __x, const param_type& __y)
5373 {return !(__x == __y);}
5374 };
5375
5376private:
5377 param_type __p_;
5378
5379public:
5380 // constructor and reset functions
5381#ifndef _LIBCPP_CXX03_LANG
5382 _LIBCPP_INLINE_VISIBILITY
5383 negative_binomial_distribution() : negative_binomial_distribution(1) {}
5384 _LIBCPP_INLINE_VISIBILITY
5385 explicit negative_binomial_distribution(result_type __k, double __p = 0.5)
5386 : __p_(__k, __p) {}
5387#else
5388 _LIBCPP_INLINE_VISIBILITY
5389 explicit negative_binomial_distribution(result_type __k = 1,
5390 double __p = 0.5)
5391 : __p_(__k, __p) {}
5392#endif
5393 _LIBCPP_INLINE_VISIBILITY
5394 explicit negative_binomial_distribution(const param_type& __p) : __p_(__p) {}
5395 _LIBCPP_INLINE_VISIBILITY
5396 void reset() {}
5397
5398 // generating functions
5399 template<class _URNG>
5400 _LIBCPP_INLINE_VISIBILITY
5401 result_type operator()(_URNG& __g)
5402 {return (*this)(__g, __p_);}
5403 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
5404
5405 // property functions
5406 _LIBCPP_INLINE_VISIBILITY
5407 result_type k() const {return __p_.k();}
5408 _LIBCPP_INLINE_VISIBILITY
5409 double p() const {return __p_.p();}
5410
5411 _LIBCPP_INLINE_VISIBILITY
5412 param_type param() const {return __p_;}
5413 _LIBCPP_INLINE_VISIBILITY
5414 void param(const param_type& __p) {__p_ = __p;}
5415
5416 _LIBCPP_INLINE_VISIBILITY
5417 result_type min() const {return 0;}
5418 _LIBCPP_INLINE_VISIBILITY
5419 result_type max() const {return numeric_limits<result_type>::max();}
5420
5421 friend _LIBCPP_INLINE_VISIBILITY
5422 bool operator==(const negative_binomial_distribution& __x,
5423 const negative_binomial_distribution& __y)
5424 {return __x.__p_ == __y.__p_;}
5425 friend _LIBCPP_INLINE_VISIBILITY
5426 bool operator!=(const negative_binomial_distribution& __x,
5427 const negative_binomial_distribution& __y)
5428 {return !(__x == __y);}
5429};
5430
5431template <class _IntType>
5432template<class _URNG>
5433_IntType
5434negative_binomial_distribution<_IntType>::operator()(_URNG& __urng, const param_type& __pr)
5435{
5436 result_type __k = __pr.k();
5437 double __p = __pr.p();
5438 if (__k <= 21 * __p)
5439 {
5440 bernoulli_distribution __gen(__p);
5441 result_type __f = 0;
5442 result_type __s = 0;
5443 while (__s < __k)
5444 {
5445 if (__gen(__urng))
5446 ++__s;
5447 else
5448 ++__f;
5449 }
5450 return __f;
5451 }
5452 return poisson_distribution<result_type>(gamma_distribution<double>
5453 (__k, (1-__p)/__p)(__urng))(__urng);
5454}
5455
5456template <class _CharT, class _Traits, class _IntType>
5457basic_ostream<_CharT, _Traits>&
5458operator<<(basic_ostream<_CharT, _Traits>& __os,
5459 const negative_binomial_distribution<_IntType>& __x)
5460{
5461 __save_flags<_CharT, _Traits> __lx(__os);
5462 typedef basic_ostream<_CharT, _Traits> _OStream;
5463 __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
5464 _OStream::scientific);
5465 _CharT __sp = __os.widen(' ');
5466 __os.fill(__sp);
5467 return __os << __x.k() << __sp << __x.p();
5468}
5469
5470template <class _CharT, class _Traits, class _IntType>
5471basic_istream<_CharT, _Traits>&
5472operator>>(basic_istream<_CharT, _Traits>& __is,
5473 negative_binomial_distribution<_IntType>& __x)
5474{
5475 typedef negative_binomial_distribution<_IntType> _Eng;
5476 typedef typename _Eng::result_type result_type;
5477 typedef typename _Eng::param_type param_type;
5478 __save_flags<_CharT, _Traits> __lx(__is);
5479 typedef basic_istream<_CharT, _Traits> _Istream;
5480 __is.flags(_Istream::dec | _Istream::skipws);
5481 result_type __k;
5482 double __p;
5483 __is >> __k >> __p;
5484 if (!__is.fail())
5485 __x.param(param_type(__k, __p));
5486 return __is;
5487}
5488
5489// geometric_distribution
5490
5491template<class _IntType = int>
5492class _LIBCPP_TEMPLATE_VIS geometric_distribution
5493{
5494public:
5495 // types
5496 typedef _IntType result_type;
5497
5498 class _LIBCPP_TEMPLATE_VIS param_type
5499 {
5500 double __p_;
5501 public:
5502 typedef geometric_distribution distribution_type;
5503
5504 _LIBCPP_INLINE_VISIBILITY
5505 explicit param_type(double __p = 0.5) : __p_(__p) {}
5506
5507 _LIBCPP_INLINE_VISIBILITY
5508 double p() const {return __p_;}
5509
5510 friend _LIBCPP_INLINE_VISIBILITY
5511 bool operator==(const param_type& __x, const param_type& __y)
5512 {return __x.__p_ == __y.__p_;}
5513 friend _LIBCPP_INLINE_VISIBILITY
5514 bool operator!=(const param_type& __x, const param_type& __y)
5515 {return !(__x == __y);}
5516 };
5517
5518private:
5519 param_type __p_;
5520
5521public:
5522 // constructors and reset functions
5523#ifndef _LIBCPP_CXX03_LANG
5524 _LIBCPP_INLINE_VISIBILITY
5525 geometric_distribution() : geometric_distribution(0.5) {}
5526 _LIBCPP_INLINE_VISIBILITY
5527 explicit geometric_distribution(double __p)
5528 : __p_(__p) {}
5529#else
5530 _LIBCPP_INLINE_VISIBILITY
5531 explicit geometric_distribution(double __p = 0.5)
5532 : __p_(__p) {}
5533#endif
5534 _LIBCPP_INLINE_VISIBILITY
5535 explicit geometric_distribution(const param_type& __p) : __p_(__p) {}
5536 _LIBCPP_INLINE_VISIBILITY
5537 void reset() {}
5538
5539 // generating functions
5540 template<class _URNG>
5541 _LIBCPP_INLINE_VISIBILITY
5542 result_type operator()(_URNG& __g)
5543 {return (*this)(__g, __p_);}
5544 template<class _URNG>
5545 _LIBCPP_INLINE_VISIBILITY
5546 result_type operator()(_URNG& __g, const param_type& __p)
5547 {return negative_binomial_distribution<result_type>(1, __p.p())(__g);}
5548
5549 // property functions
5550 _LIBCPP_INLINE_VISIBILITY
5551 double p() const {return __p_.p();}
5552
5553 _LIBCPP_INLINE_VISIBILITY
5554 param_type param() const {return __p_;}
5555 _LIBCPP_INLINE_VISIBILITY
5556 void param(const param_type& __p) {__p_ = __p;}
5557
5558 _LIBCPP_INLINE_VISIBILITY
5559 result_type min() const {return 0;}
5560 _LIBCPP_INLINE_VISIBILITY
5561 result_type max() const {return numeric_limits<result_type>::max();}
5562
5563 friend _LIBCPP_INLINE_VISIBILITY
5564 bool operator==(const geometric_distribution& __x,
5565 const geometric_distribution& __y)
5566 {return __x.__p_ == __y.__p_;}
5567 friend _LIBCPP_INLINE_VISIBILITY
5568 bool operator!=(const geometric_distribution& __x,
5569 const geometric_distribution& __y)
5570 {return !(__x == __y);}
5571};
5572
5573template <class _CharT, class _Traits, class _IntType>
5574basic_ostream<_CharT, _Traits>&
5575operator<<(basic_ostream<_CharT, _Traits>& __os,
5576 const geometric_distribution<_IntType>& __x)
5577{
5578 __save_flags<_CharT, _Traits> __lx(__os);
5579 typedef basic_ostream<_CharT, _Traits> _OStream;
5580 __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
5581 _OStream::scientific);
5582 return __os << __x.p();
5583}
5584
5585template <class _CharT, class _Traits, class _IntType>
5586basic_istream<_CharT, _Traits>&
5587operator>>(basic_istream<_CharT, _Traits>& __is,
5588 geometric_distribution<_IntType>& __x)
5589{
5590 typedef geometric_distribution<_IntType> _Eng;
5591 typedef typename _Eng::param_type param_type;
5592 __save_flags<_CharT, _Traits> __lx(__is);
5593 typedef basic_istream<_CharT, _Traits> _Istream;
5594 __is.flags(_Istream::dec | _Istream::skipws);
5595 double __p;
5596 __is >> __p;
5597 if (!__is.fail())
5598 __x.param(param_type(__p));
5599 return __is;
5600}
5601
5602// chi_squared_distribution
5603
5604template<class _RealType = double>
5605class _LIBCPP_TEMPLATE_VIS chi_squared_distribution
5606{
5607public:
5608 // types
5609 typedef _RealType result_type;
5610
5611 class _LIBCPP_TEMPLATE_VIS param_type
5612 {
5613 result_type __n_;
5614 public:
5615 typedef chi_squared_distribution distribution_type;
5616
5617 _LIBCPP_INLINE_VISIBILITY
5618 explicit param_type(result_type __n = 1) : __n_(__n) {}
5619
5620 _LIBCPP_INLINE_VISIBILITY
5621 result_type n() const {return __n_;}
5622
5623 friend _LIBCPP_INLINE_VISIBILITY
5624 bool operator==(const param_type& __x, const param_type& __y)
5625 {return __x.__n_ == __y.__n_;}
5626 friend _LIBCPP_INLINE_VISIBILITY
5627 bool operator!=(const param_type& __x, const param_type& __y)
5628 {return !(__x == __y);}
5629 };
5630
5631private:
5632 param_type __p_;
5633
5634public:
5635 // constructor and reset functions
5636#ifndef _LIBCPP_CXX03_LANG
5637 _LIBCPP_INLINE_VISIBILITY
5638 chi_squared_distribution() : chi_squared_distribution(1) {}
5639 _LIBCPP_INLINE_VISIBILITY
5640 explicit chi_squared_distribution(result_type __n)
5641 : __p_(param_type(__n)) {}
5642#else
5643 _LIBCPP_INLINE_VISIBILITY
5644 explicit chi_squared_distribution(result_type __n = 1)
5645 : __p_(param_type(__n)) {}
5646#endif
5647 _LIBCPP_INLINE_VISIBILITY
5648 explicit chi_squared_distribution(const param_type& __p)
5649 : __p_(__p) {}
5650 _LIBCPP_INLINE_VISIBILITY
5651 void reset() {}
5652
5653 // generating functions
5654 template<class _URNG>
5655 _LIBCPP_INLINE_VISIBILITY
5656 result_type operator()(_URNG& __g)
5657 {return (*this)(__g, __p_);}
5658 template<class _URNG>
5659 _LIBCPP_INLINE_VISIBILITY
5660 result_type operator()(_URNG& __g, const param_type& __p)
5661 {return gamma_distribution<result_type>(__p.n() / 2, 2)(__g);}
5662
5663 // property functions
5664 _LIBCPP_INLINE_VISIBILITY
5665 result_type n() const {return __p_.n();}
5666
5667 _LIBCPP_INLINE_VISIBILITY
5668 param_type param() const {return __p_;}
5669 _LIBCPP_INLINE_VISIBILITY
5670 void param(const param_type& __p) {__p_ = __p;}
5671
5672 _LIBCPP_INLINE_VISIBILITY
5673 result_type min() const {return 0;}
5674 _LIBCPP_INLINE_VISIBILITY
5675 result_type max() const {return numeric_limits<result_type>::infinity();}
5676
5677 friend _LIBCPP_INLINE_VISIBILITY
5678 bool operator==(const chi_squared_distribution& __x,
5679 const chi_squared_distribution& __y)
5680 {return __x.__p_ == __y.__p_;}
5681 friend _LIBCPP_INLINE_VISIBILITY
5682 bool operator!=(const chi_squared_distribution& __x,
5683 const chi_squared_distribution& __y)
5684 {return !(__x == __y);}
5685};
5686
5687template <class _CharT, class _Traits, class _RT>
5688basic_ostream<_CharT, _Traits>&
5689operator<<(basic_ostream<_CharT, _Traits>& __os,
5690 const chi_squared_distribution<_RT>& __x)
5691{
5692 __save_flags<_CharT, _Traits> __lx(__os);
5693 typedef basic_ostream<_CharT, _Traits> _OStream;
5694 __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
5695 _OStream::scientific);
5696 __os << __x.n();
5697 return __os;
5698}
5699
5700template <class _CharT, class _Traits, class _RT>
5701basic_istream<_CharT, _Traits>&
5702operator>>(basic_istream<_CharT, _Traits>& __is,
5703 chi_squared_distribution<_RT>& __x)
5704{
5705 typedef chi_squared_distribution<_RT> _Eng;
5706 typedef typename _Eng::result_type result_type;
5707 typedef typename _Eng::param_type param_type;
5708 __save_flags<_CharT, _Traits> __lx(__is);
5709 typedef basic_istream<_CharT, _Traits> _Istream;
5710 __is.flags(_Istream::dec | _Istream::skipws);
5711 result_type __n;
5712 __is >> __n;
5713 if (!__is.fail())
5714 __x.param(param_type(__n));
5715 return __is;
5716}
5717
5718// cauchy_distribution
5719
5720template<class _RealType = double>
5721class _LIBCPP_TEMPLATE_VIS cauchy_distribution
5722{
5723public:
5724 // types
5725 typedef _RealType result_type;
5726
5727 class _LIBCPP_TEMPLATE_VIS param_type
5728 {
5729 result_type __a_;
5730 result_type __b_;
5731 public:
5732 typedef cauchy_distribution distribution_type;
5733
5734 _LIBCPP_INLINE_VISIBILITY
5735 explicit param_type(result_type __a = 0, result_type __b = 1)
5736 : __a_(__a), __b_(__b) {}
5737
5738 _LIBCPP_INLINE_VISIBILITY
5739 result_type a() const {return __a_;}
5740 _LIBCPP_INLINE_VISIBILITY
5741 result_type b() const {return __b_;}
5742
5743 friend _LIBCPP_INLINE_VISIBILITY
5744 bool operator==(const param_type& __x, const param_type& __y)
5745 {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;}
5746 friend _LIBCPP_INLINE_VISIBILITY
5747 bool operator!=(const param_type& __x, const param_type& __y)
5748 {return !(__x == __y);}
5749 };
5750
5751private:
5752 param_type __p_;
5753
5754public:
5755 // constructor and reset functions
5756#ifndef _LIBCPP_CXX03_LANG
5757 _LIBCPP_INLINE_VISIBILITY
5758 cauchy_distribution() : cauchy_distribution(0) {}
5759 _LIBCPP_INLINE_VISIBILITY
5760 explicit cauchy_distribution(result_type __a, result_type __b = 1)
5761 : __p_(param_type(__a, __b)) {}
5762#else
5763 _LIBCPP_INLINE_VISIBILITY
5764 explicit cauchy_distribution(result_type __a = 0, result_type __b = 1)
5765 : __p_(param_type(__a, __b)) {}
5766#endif
5767 _LIBCPP_INLINE_VISIBILITY
5768 explicit cauchy_distribution(const param_type& __p)
5769 : __p_(__p) {}
5770 _LIBCPP_INLINE_VISIBILITY
5771 void reset() {}
5772
5773 // generating functions
5774 template<class _URNG>
5775 _LIBCPP_INLINE_VISIBILITY
5776 result_type operator()(_URNG& __g)
5777 {return (*this)(__g, __p_);}
5778 template<class _URNG> _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g, const param_type& __p);
5779
5780 // property functions
5781 _LIBCPP_INLINE_VISIBILITY
5782 result_type a() const {return __p_.a();}
5783 _LIBCPP_INLINE_VISIBILITY
5784 result_type b() const {return __p_.b();}
5785
5786 _LIBCPP_INLINE_VISIBILITY
5787 param_type param() const {return __p_;}
5788 _LIBCPP_INLINE_VISIBILITY
5789 void param(const param_type& __p) {__p_ = __p;}
5790
5791 _LIBCPP_INLINE_VISIBILITY
5792 result_type min() const {return -numeric_limits<result_type>::infinity();}
5793 _LIBCPP_INLINE_VISIBILITY
5794 result_type max() const {return numeric_limits<result_type>::infinity();}
5795
5796 friend _LIBCPP_INLINE_VISIBILITY
5797 bool operator==(const cauchy_distribution& __x,
5798 const cauchy_distribution& __y)
5799 {return __x.__p_ == __y.__p_;}
5800 friend _LIBCPP_INLINE_VISIBILITY
5801 bool operator!=(const cauchy_distribution& __x,
5802 const cauchy_distribution& __y)
5803 {return !(__x == __y);}
5804};
5805
5806template <class _RealType>
5807template<class _URNG>
5808inline
5809_RealType
5810cauchy_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
5811{
5812 uniform_real_distribution<result_type> __gen;
5813 // purposefully let tan arg get as close to pi/2 as it wants, tan will return a finite
5814 return __p.a() + __p.b() * _VSTD::tan(3.1415926535897932384626433832795 * __gen(__g));
5815}
5816
5817template <class _CharT, class _Traits, class _RT>
5818basic_ostream<_CharT, _Traits>&
5819operator<<(basic_ostream<_CharT, _Traits>& __os,
5820 const cauchy_distribution<_RT>& __x)
5821{
5822 __save_flags<_CharT, _Traits> __lx(__os);
5823 typedef basic_ostream<_CharT, _Traits> _OStream;
5824 __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
5825 _OStream::scientific);
5826 _CharT __sp = __os.widen(' ');
5827 __os.fill(__sp);
5828 __os << __x.a() << __sp << __x.b();
5829 return __os;
5830}
5831
5832template <class _CharT, class _Traits, class _RT>
5833basic_istream<_CharT, _Traits>&
5834operator>>(basic_istream<_CharT, _Traits>& __is,
5835 cauchy_distribution<_RT>& __x)
5836{
5837 typedef cauchy_distribution<_RT> _Eng;
5838 typedef typename _Eng::result_type result_type;
5839 typedef typename _Eng::param_type param_type;
5840 __save_flags<_CharT, _Traits> __lx(__is);
5841 typedef basic_istream<_CharT, _Traits> _Istream;
5842 __is.flags(_Istream::dec | _Istream::skipws);
5843 result_type __a;
5844 result_type __b;
5845 __is >> __a >> __b;
5846 if (!__is.fail())
5847 __x.param(param_type(__a, __b));
5848 return __is;
5849}
5850
5851// fisher_f_distribution
5852
5853template<class _RealType = double>
5854class _LIBCPP_TEMPLATE_VIS fisher_f_distribution
5855{
5856public:
5857 // types
5858 typedef _RealType result_type;
5859
5860 class _LIBCPP_TEMPLATE_VIS param_type
5861 {
5862 result_type __m_;
5863 result_type __n_;
5864 public:
5865 typedef fisher_f_distribution distribution_type;
5866
5867 _LIBCPP_INLINE_VISIBILITY
5868 explicit param_type(result_type __m = 1, result_type __n = 1)
5869 : __m_(__m), __n_(__n) {}
5870
5871 _LIBCPP_INLINE_VISIBILITY
5872 result_type m() const {return __m_;}
5873 _LIBCPP_INLINE_VISIBILITY
5874 result_type n() const {return __n_;}
5875
5876 friend _LIBCPP_INLINE_VISIBILITY
5877 bool operator==(const param_type& __x, const param_type& __y)
5878 {return __x.__m_ == __y.__m_ && __x.__n_ == __y.__n_;}
5879 friend _LIBCPP_INLINE_VISIBILITY
5880 bool operator!=(const param_type& __x, const param_type& __y)
5881 {return !(__x == __y);}
5882 };
5883
5884private:
5885 param_type __p_;
5886
5887public:
5888 // constructor and reset functions
5889#ifndef _LIBCPP_CXX03_LANG
5890 _LIBCPP_INLINE_VISIBILITY
5891 fisher_f_distribution() : fisher_f_distribution(1) {}
5892 _LIBCPP_INLINE_VISIBILITY
5893 explicit fisher_f_distribution(result_type __m, result_type __n = 1)
5894 : __p_(param_type(__m, __n)) {}
5895#else
5896 _LIBCPP_INLINE_VISIBILITY
5897 explicit fisher_f_distribution(result_type __m = 1, result_type __n = 1)
5898 : __p_(param_type(__m, __n)) {}
5899#endif
5900 _LIBCPP_INLINE_VISIBILITY
5901 explicit fisher_f_distribution(const param_type& __p)
5902 : __p_(__p) {}
5903 _LIBCPP_INLINE_VISIBILITY
5904 void reset() {}
5905
5906 // generating functions
5907 template<class _URNG>
5908 _LIBCPP_INLINE_VISIBILITY
5909 result_type operator()(_URNG& __g)
5910 {return (*this)(__g, __p_);}
5911 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
5912
5913 // property functions
5914 _LIBCPP_INLINE_VISIBILITY
5915 result_type m() const {return __p_.m();}
5916 _LIBCPP_INLINE_VISIBILITY
5917 result_type n() const {return __p_.n();}
5918
5919 _LIBCPP_INLINE_VISIBILITY
5920 param_type param() const {return __p_;}
5921 _LIBCPP_INLINE_VISIBILITY
5922 void param(const param_type& __p) {__p_ = __p;}
5923
5924 _LIBCPP_INLINE_VISIBILITY
5925 result_type min() const {return 0;}
5926 _LIBCPP_INLINE_VISIBILITY
5927 result_type max() const {return numeric_limits<result_type>::infinity();}
5928
5929 friend _LIBCPP_INLINE_VISIBILITY
5930 bool operator==(const fisher_f_distribution& __x,
5931 const fisher_f_distribution& __y)
5932 {return __x.__p_ == __y.__p_;}
5933 friend _LIBCPP_INLINE_VISIBILITY
5934 bool operator!=(const fisher_f_distribution& __x,
5935 const fisher_f_distribution& __y)
5936 {return !(__x == __y);}
5937};
5938
5939template <class _RealType>
5940template<class _URNG>
5941_RealType
5942fisher_f_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
5943{
5944 gamma_distribution<result_type> __gdm(__p.m() * result_type(.5));
5945 gamma_distribution<result_type> __gdn(__p.n() * result_type(.5));
5946 return __p.n() * __gdm(__g) / (__p.m() * __gdn(__g));
5947}
5948
5949template <class _CharT, class _Traits, class _RT>
5950basic_ostream<_CharT, _Traits>&
5951operator<<(basic_ostream<_CharT, _Traits>& __os,
5952 const fisher_f_distribution<_RT>& __x)
5953{
5954 __save_flags<_CharT, _Traits> __lx(__os);
5955 typedef basic_ostream<_CharT, _Traits> _OStream;
5956 __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
5957 _OStream::scientific);
5958 _CharT __sp = __os.widen(' ');
5959 __os.fill(__sp);
5960 __os << __x.m() << __sp << __x.n();
5961 return __os;
5962}
5963
5964template <class _CharT, class _Traits, class _RT>
5965basic_istream<_CharT, _Traits>&
5966operator>>(basic_istream<_CharT, _Traits>& __is,
5967 fisher_f_distribution<_RT>& __x)
5968{
5969 typedef fisher_f_distribution<_RT> _Eng;
5970 typedef typename _Eng::result_type result_type;
5971 typedef typename _Eng::param_type param_type;
5972 __save_flags<_CharT, _Traits> __lx(__is);
5973 typedef basic_istream<_CharT, _Traits> _Istream;
5974 __is.flags(_Istream::dec | _Istream::skipws);
5975 result_type __m;
5976 result_type __n;
5977 __is >> __m >> __n;
5978 if (!__is.fail())
5979 __x.param(param_type(__m, __n));
5980 return __is;
5981}
5982
5983// student_t_distribution
5984
5985template<class _RealType = double>
5986class _LIBCPP_TEMPLATE_VIS student_t_distribution
5987{
5988public:
5989 // types
5990 typedef _RealType result_type;
5991
5992 class _LIBCPP_TEMPLATE_VIS param_type
5993 {
5994 result_type __n_;
5995 public:
5996 typedef student_t_distribution distribution_type;
5997
5998 _LIBCPP_INLINE_VISIBILITY
5999 explicit param_type(result_type __n = 1) : __n_(__n) {}
6000
6001 _LIBCPP_INLINE_VISIBILITY
6002 result_type n() const {return __n_;}
6003
6004 friend _LIBCPP_INLINE_VISIBILITY
6005 bool operator==(const param_type& __x, const param_type& __y)
6006 {return __x.__n_ == __y.__n_;}
6007 friend _LIBCPP_INLINE_VISIBILITY
6008 bool operator!=(const param_type& __x, const param_type& __y)
6009 {return !(__x == __y);}
6010 };
6011
6012private:
6013 param_type __p_;
6014 normal_distribution<result_type> __nd_;
6015
6016public:
6017 // constructor and reset functions
6018#ifndef _LIBCPP_CXX03_LANG
6019 _LIBCPP_INLINE_VISIBILITY
6020 student_t_distribution() : student_t_distribution(1) {}
6021 _LIBCPP_INLINE_VISIBILITY
6022 explicit student_t_distribution(result_type __n)
6023 : __p_(param_type(__n)) {}
6024#else
6025 _LIBCPP_INLINE_VISIBILITY
6026 explicit student_t_distribution(result_type __n = 1)
6027 : __p_(param_type(__n)) {}
6028#endif
6029 _LIBCPP_INLINE_VISIBILITY
6030 explicit student_t_distribution(const param_type& __p)
6031 : __p_(__p) {}
6032 _LIBCPP_INLINE_VISIBILITY
6033 void reset() {__nd_.reset();}
6034
6035 // generating functions
6036 template<class _URNG>
6037 _LIBCPP_INLINE_VISIBILITY
6038 result_type operator()(_URNG& __g)
6039 {return (*this)(__g, __p_);}
6040 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
6041
6042 // property functions
6043 _LIBCPP_INLINE_VISIBILITY
6044 result_type n() const {return __p_.n();}
6045
6046 _LIBCPP_INLINE_VISIBILITY
6047 param_type param() const {return __p_;}
6048 _LIBCPP_INLINE_VISIBILITY
6049 void param(const param_type& __p) {__p_ = __p;}
6050
6051 _LIBCPP_INLINE_VISIBILITY
6052 result_type min() const {return -numeric_limits<result_type>::infinity();}
6053 _LIBCPP_INLINE_VISIBILITY
6054 result_type max() const {return numeric_limits<result_type>::infinity();}
6055
6056 friend _LIBCPP_INLINE_VISIBILITY
6057 bool operator==(const student_t_distribution& __x,
6058 const student_t_distribution& __y)
6059 {return __x.__p_ == __y.__p_;}
6060 friend _LIBCPP_INLINE_VISIBILITY
6061 bool operator!=(const student_t_distribution& __x,
6062 const student_t_distribution& __y)
6063 {return !(__x == __y);}
6064};
6065
6066template <class _RealType>
6067template<class _URNG>
6068_RealType
6069student_t_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
6070{
6071 gamma_distribution<result_type> __gd(__p.n() * .5, 2);
6072 return __nd_(__g) * _VSTD::sqrt(__p.n()/__gd(__g));
6073}
6074
6075template <class _CharT, class _Traits, class _RT>
6076basic_ostream<_CharT, _Traits>&
6077operator<<(basic_ostream<_CharT, _Traits>& __os,
6078 const student_t_distribution<_RT>& __x)
6079{
6080 __save_flags<_CharT, _Traits> __lx(__os);
6081 typedef basic_ostream<_CharT, _Traits> _OStream;
6082 __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
6083 _OStream::scientific);
6084 __os << __x.n();
6085 return __os;
6086}
6087
6088template <class _CharT, class _Traits, class _RT>
6089basic_istream<_CharT, _Traits>&
6090operator>>(basic_istream<_CharT, _Traits>& __is,
6091 student_t_distribution<_RT>& __x)
6092{
6093 typedef student_t_distribution<_RT> _Eng;
6094 typedef typename _Eng::result_type result_type;
6095 typedef typename _Eng::param_type param_type;
6096 __save_flags<_CharT, _Traits> __lx(__is);
6097 typedef basic_istream<_CharT, _Traits> _Istream;
6098 __is.flags(_Istream::dec | _Istream::skipws);
6099 result_type __n;
6100 __is >> __n;
6101 if (!__is.fail())
6102 __x.param(param_type(__n));
6103 return __is;
6104}
6105
6106// discrete_distribution
6107
6108template<class _IntType = int>
6109class _LIBCPP_TEMPLATE_VIS discrete_distribution
6110{
6111public:
6112 // types
6113 typedef _IntType result_type;
6114
6115 class _LIBCPP_TEMPLATE_VIS param_type
6116 {
6117 vector<double> __p_;
6118 public:
6119 typedef discrete_distribution distribution_type;
6120
6121 _LIBCPP_INLINE_VISIBILITY
6122 param_type() {}
6123 template<class _InputIterator>
6124 _LIBCPP_INLINE_VISIBILITY
6125 param_type(_InputIterator __f, _InputIterator __l)
6126 : __p_(__f, __l) {__init();}
6127#ifndef _LIBCPP_CXX03_LANG
6128 _LIBCPP_INLINE_VISIBILITY
6129 param_type(initializer_list<double> __wl)
6130 : __p_(__wl.begin(), __wl.end()) {__init();}
6131#endif // _LIBCPP_CXX03_LANG
6132 template<class _UnaryOperation>
6133 param_type(size_t __nw, double __xmin, double __xmax,
6134 _UnaryOperation __fw);
6135
6136 vector<double> probabilities() const;
6137
6138 friend _LIBCPP_INLINE_VISIBILITY
6139 bool operator==(const param_type& __x, const param_type& __y)
6140 {return __x.__p_ == __y.__p_;}
6141 friend _LIBCPP_INLINE_VISIBILITY
6142 bool operator!=(const param_type& __x, const param_type& __y)
6143 {return !(__x == __y);}
6144
6145 private:
6146 void __init();
6147
6148 friend class discrete_distribution;
6149
6150 template <class _CharT, class _Traits, class _IT>
6151 friend
6152 basic_ostream<_CharT, _Traits>&
6153 operator<<(basic_ostream<_CharT, _Traits>& __os,
6154 const discrete_distribution<_IT>& __x);
6155
6156 template <class _CharT, class _Traits, class _IT>
6157 friend
6158 basic_istream<_CharT, _Traits>&
6159 operator>>(basic_istream<_CharT, _Traits>& __is,
6160 discrete_distribution<_IT>& __x);
6161 };
6162
6163private:
6164 param_type __p_;
6165
6166public:
6167 // constructor and reset functions
6168 _LIBCPP_INLINE_VISIBILITY
6169 discrete_distribution() {}
6170 template<class _InputIterator>
6171 _LIBCPP_INLINE_VISIBILITY
6172 discrete_distribution(_InputIterator __f, _InputIterator __l)
6173 : __p_(__f, __l) {}
6174#ifndef _LIBCPP_CXX03_LANG
6175 _LIBCPP_INLINE_VISIBILITY
6176 discrete_distribution(initializer_list<double> __wl)
6177 : __p_(__wl) {}
6178#endif // _LIBCPP_CXX03_LANG
6179 template<class _UnaryOperation>
6180 _LIBCPP_INLINE_VISIBILITY
6181 discrete_distribution(size_t __nw, double __xmin, double __xmax,
6182 _UnaryOperation __fw)
6183 : __p_(__nw, __xmin, __xmax, __fw) {}
6184 _LIBCPP_INLINE_VISIBILITY
6185 explicit discrete_distribution(const param_type& __p)
6186 : __p_(__p) {}
6187 _LIBCPP_INLINE_VISIBILITY
6188 void reset() {}
6189
6190 // generating functions
6191 template<class _URNG>
6192 _LIBCPP_INLINE_VISIBILITY
6193 result_type operator()(_URNG& __g)
6194 {return (*this)(__g, __p_);}
6195 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
6196
6197 // property functions
6198 _LIBCPP_INLINE_VISIBILITY
6199 vector<double> probabilities() const {return __p_.probabilities();}
6200
6201 _LIBCPP_INLINE_VISIBILITY
6202 param_type param() const {return __p_;}
6203 _LIBCPP_INLINE_VISIBILITY
6204 void param(const param_type& __p) {__p_ = __p;}
6205
6206 _LIBCPP_INLINE_VISIBILITY
6207 result_type min() const {return 0;}
6208 _LIBCPP_INLINE_VISIBILITY
6209 result_type max() const {return __p_.__p_.size();}
6210
6211 friend _LIBCPP_INLINE_VISIBILITY
6212 bool operator==(const discrete_distribution& __x,
6213 const discrete_distribution& __y)
6214 {return __x.__p_ == __y.__p_;}
6215 friend _LIBCPP_INLINE_VISIBILITY
6216 bool operator!=(const discrete_distribution& __x,
6217 const discrete_distribution& __y)
6218 {return !(__x == __y);}
6219
6220 template <class _CharT, class _Traits, class _IT>
6221 friend
6222 basic_ostream<_CharT, _Traits>&
6223 operator<<(basic_ostream<_CharT, _Traits>& __os,
6224 const discrete_distribution<_IT>& __x);
6225
6226 template <class _CharT, class _Traits, class _IT>
6227 friend
6228 basic_istream<_CharT, _Traits>&
6229 operator>>(basic_istream<_CharT, _Traits>& __is,
6230 discrete_distribution<_IT>& __x);
6231};
6232
6233template<class _IntType>
6234template<class _UnaryOperation>
6235discrete_distribution<_IntType>::param_type::param_type(size_t __nw,
6236 double __xmin,
6237 double __xmax,
6238 _UnaryOperation __fw)
6239{
6240 if (__nw > 1)
6241 {
6242 __p_.reserve(__nw - 1);
6243 double __d = (__xmax - __xmin) / __nw;
6244 double __d2 = __d / 2;
6245 for (size_t __k = 0; __k < __nw; ++__k)
6246 __p_.push_back(__fw(__xmin + __k * __d + __d2));
6247 __init();
6248 }
6249}
6250
6251template<class _IntType>
6252void
6253discrete_distribution<_IntType>::param_type::__init()
6254{
6255 if (!__p_.empty())
6256 {
6257 if (__p_.size() > 1)
6258 {
6259 double __s = _VSTD::accumulate(__p_.begin(), __p_.end(), 0.0);
6260 for (vector<double>::iterator __i = __p_.begin(), __e = __p_.end(); __i < __e; ++__i)
6261 *__i /= __s;
6262 vector<double> __t(__p_.size() - 1);
6263 _VSTD::partial_sum(__p_.begin(), __p_.end() - 1, __t.begin());
6264 swap(__p_, __t);
6265 }
6266 else
6267 {
6268 __p_.clear();
6269 __p_.shrink_to_fit();
6270 }
6271 }
6272}
6273
6274template<class _IntType>
6275vector<double>
6276discrete_distribution<_IntType>::param_type::probabilities() const
6277{
6278 size_t __n = __p_.size();
6279 vector<double> __p(__n+1);
6280 _VSTD::adjacent_difference(__p_.begin(), __p_.end(), __p.begin());
6281 if (__n > 0)
6282 __p[__n] = 1 - __p_[__n-1];
6283 else
6284 __p[0] = 1;
6285 return __p;
6286}
6287
6288template<class _IntType>
6289template<class _URNG>
6290_IntType
6291discrete_distribution<_IntType>::operator()(_URNG& __g, const param_type& __p)
6292{
6293 uniform_real_distribution<double> __gen;
6294 return static_cast<_IntType>(
6295 _VSTD::upper_bound(__p.__p_.begin(), __p.__p_.end(), __gen(__g)) -
6296 __p.__p_.begin());
6297}
6298
6299template <class _CharT, class _Traits, class _IT>
6300basic_ostream<_CharT, _Traits>&
6301operator<<(basic_ostream<_CharT, _Traits>& __os,
6302 const discrete_distribution<_IT>& __x)
6303{
6304 __save_flags<_CharT, _Traits> __lx(__os);
6305 typedef basic_ostream<_CharT, _Traits> _OStream;
6306 __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
6307 _OStream::scientific);
6308 _CharT __sp = __os.widen(' ');
6309 __os.fill(__sp);
6310 size_t __n = __x.__p_.__p_.size();
6311 __os << __n;
6312 for (size_t __i = 0; __i < __n; ++__i)
6313 __os << __sp << __x.__p_.__p_[__i];
6314 return __os;
6315}
6316
6317template <class _CharT, class _Traits, class _IT>
6318basic_istream<_CharT, _Traits>&
6319operator>>(basic_istream<_CharT, _Traits>& __is,
6320 discrete_distribution<_IT>& __x)
6321{
6322 __save_flags<_CharT, _Traits> __lx(__is);
6323 typedef basic_istream<_CharT, _Traits> _Istream;
6324 __is.flags(_Istream::dec | _Istream::skipws);
6325 size_t __n;
6326 __is >> __n;
6327 vector<double> __p(__n);
6328 for (size_t __i = 0; __i < __n; ++__i)
6329 __is >> __p[__i];
6330 if (!__is.fail())
6331 swap(__x.__p_.__p_, __p);
6332 return __is;
6333}
6334
6335// piecewise_constant_distribution
6336
6337template<class _RealType = double>
6338class _LIBCPP_TEMPLATE_VIS piecewise_constant_distribution
6339{
6340public:
6341 // types
6342 typedef _RealType result_type;
6343
6344 class _LIBCPP_TEMPLATE_VIS param_type
6345 {
6346 vector<result_type> __b_;
6347 vector<result_type> __densities_;
6348 vector<result_type> __areas_;
6349 public:
6350 typedef piecewise_constant_distribution distribution_type;
6351
6352 param_type();
6353 template<class _InputIteratorB, class _InputIteratorW>
6354 param_type(_InputIteratorB __fB, _InputIteratorB __lB,
6355 _InputIteratorW __fW);
6356#ifndef _LIBCPP_CXX03_LANG
6357 template<class _UnaryOperation>
6358 param_type(initializer_list<result_type> __bl, _UnaryOperation __fw);
6359#endif // _LIBCPP_CXX03_LANG
6360 template<class _UnaryOperation>
6361 param_type(size_t __nw, result_type __xmin, result_type __xmax,
6362 _UnaryOperation __fw);
6363 param_type(param_type const&) = default;
6364 param_type & operator=(const param_type& __rhs);
6365
6366 _LIBCPP_INLINE_VISIBILITY
6367 vector<result_type> intervals() const {return __b_;}
6368 _LIBCPP_INLINE_VISIBILITY
6369 vector<result_type> densities() const {return __densities_;}
6370
6371 friend _LIBCPP_INLINE_VISIBILITY
6372 bool operator==(const param_type& __x, const param_type& __y)
6373 {return __x.__densities_ == __y.__densities_ && __x.__b_ == __y.__b_;}
6374 friend _LIBCPP_INLINE_VISIBILITY
6375 bool operator!=(const param_type& __x, const param_type& __y)
6376 {return !(__x == __y);}
6377
6378 private:
6379 void __init();
6380
6381 friend class piecewise_constant_distribution;
6382
6383 template <class _CharT, class _Traits, class _RT>
6384 friend
6385 basic_ostream<_CharT, _Traits>&
6386 operator<<(basic_ostream<_CharT, _Traits>& __os,
6387 const piecewise_constant_distribution<_RT>& __x);
6388
6389 template <class _CharT, class _Traits, class _RT>
6390 friend
6391 basic_istream<_CharT, _Traits>&
6392 operator>>(basic_istream<_CharT, _Traits>& __is,
6393 piecewise_constant_distribution<_RT>& __x);
6394 };
6395
6396private:
6397 param_type __p_;
6398
6399public:
6400 // constructor and reset functions
6401 _LIBCPP_INLINE_VISIBILITY
6402 piecewise_constant_distribution() {}
6403 template<class _InputIteratorB, class _InputIteratorW>
6404 _LIBCPP_INLINE_VISIBILITY
6405 piecewise_constant_distribution(_InputIteratorB __fB,
6406 _InputIteratorB __lB,
6407 _InputIteratorW __fW)
6408 : __p_(__fB, __lB, __fW) {}
6409
6410#ifndef _LIBCPP_CXX03_LANG
6411 template<class _UnaryOperation>
6412 _LIBCPP_INLINE_VISIBILITY
6413 piecewise_constant_distribution(initializer_list<result_type> __bl,
6414 _UnaryOperation __fw)
6415 : __p_(__bl, __fw) {}
6416#endif // _LIBCPP_CXX03_LANG
6417
6418 template<class _UnaryOperation>
6419 _LIBCPP_INLINE_VISIBILITY
6420 piecewise_constant_distribution(size_t __nw, result_type __xmin,
6421 result_type __xmax, _UnaryOperation __fw)
6422 : __p_(__nw, __xmin, __xmax, __fw) {}
6423
6424 _LIBCPP_INLINE_VISIBILITY
6425 explicit piecewise_constant_distribution(const param_type& __p)
6426 : __p_(__p) {}
6427
6428 _LIBCPP_INLINE_VISIBILITY
6429 void reset() {}
6430
6431 // generating functions
6432 template<class _URNG>
6433 _LIBCPP_INLINE_VISIBILITY
6434 result_type operator()(_URNG& __g)
6435 {return (*this)(__g, __p_);}
6436 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
6437
6438 // property functions
6439 _LIBCPP_INLINE_VISIBILITY
6440 vector<result_type> intervals() const {return __p_.intervals();}
6441 _LIBCPP_INLINE_VISIBILITY
6442 vector<result_type> densities() const {return __p_.densities();}
6443
6444 _LIBCPP_INLINE_VISIBILITY
6445 param_type param() const {return __p_;}
6446 _LIBCPP_INLINE_VISIBILITY
6447 void param(const param_type& __p) {__p_ = __p;}
6448
6449 _LIBCPP_INLINE_VISIBILITY
6450 result_type min() const {return __p_.__b_.front();}
6451 _LIBCPP_INLINE_VISIBILITY
6452 result_type max() const {return __p_.__b_.back();}
6453
6454 friend _LIBCPP_INLINE_VISIBILITY
6455 bool operator==(const piecewise_constant_distribution& __x,
6456 const piecewise_constant_distribution& __y)
6457 {return __x.__p_ == __y.__p_;}
6458 friend _LIBCPP_INLINE_VISIBILITY
6459 bool operator!=(const piecewise_constant_distribution& __x,
6460 const piecewise_constant_distribution& __y)
6461 {return !(__x == __y);}
6462
6463 template <class _CharT, class _Traits, class _RT>
6464 friend
6465 basic_ostream<_CharT, _Traits>&
6466 operator<<(basic_ostream<_CharT, _Traits>& __os,
6467 const piecewise_constant_distribution<_RT>& __x);
6468
6469 template <class _CharT, class _Traits, class _RT>
6470 friend
6471 basic_istream<_CharT, _Traits>&
6472 operator>>(basic_istream<_CharT, _Traits>& __is,
6473 piecewise_constant_distribution<_RT>& __x);
6474};
6475
6476template<class _RealType>
6477typename piecewise_constant_distribution<_RealType>::param_type &
6478piecewise_constant_distribution<_RealType>::param_type::operator=
6479 (const param_type& __rhs)
6480{
6481// These can throw
6482 __b_.reserve (__rhs.__b_.size ());
6483 __densities_.reserve(__rhs.__densities_.size());
6484 __areas_.reserve (__rhs.__areas_.size());
6485
6486// These can not throw
6487 __b_ = __rhs.__b_;
6488 __densities_ = __rhs.__densities_;
6489 __areas_ = __rhs.__areas_;
6490 return *this;
6491}
6492
6493template<class _RealType>
6494void
6495piecewise_constant_distribution<_RealType>::param_type::__init()
6496{
6497 // __densities_ contains non-normalized areas
6498 result_type __total_area = _VSTD::accumulate(__densities_.begin(),
6499 __densities_.end(),
6500 result_type());
6501 for (size_t __i = 0; __i < __densities_.size(); ++__i)
6502 __densities_[__i] /= __total_area;
6503 // __densities_ contains normalized areas
6504 __areas_.assign(__densities_.size(), result_type());
6505 _VSTD::partial_sum(__densities_.begin(), __densities_.end() - 1,
6506 __areas_.begin() + 1);
6507 // __areas_ contains partial sums of normalized areas: [0, __densities_ - 1]
6508 __densities_.back() = 1 - __areas_.back(); // correct round off error
6509 for (size_t __i = 0; __i < __densities_.size(); ++__i)
6510 __densities_[__i] /= (__b_[__i+1] - __b_[__i]);
6511 // __densities_ now contains __densities_
6512}
6513
6514template<class _RealType>
6515piecewise_constant_distribution<_RealType>::param_type::param_type()
6516 : __b_(2),
6517 __densities_(1, 1.0),
6518 __areas_(1, 0.0)
6519{
6520 __b_[1] = 1;
6521}
6522
6523template<class _RealType>
6524template<class _InputIteratorB, class _InputIteratorW>
6525piecewise_constant_distribution<_RealType>::param_type::param_type(
6526 _InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW)
6527 : __b_(__fB, __lB)
6528{
6529 if (__b_.size() < 2)
6530 {
6531 __b_.resize(2);
6532 __b_[0] = 0;
6533 __b_[1] = 1;
6534 __densities_.assign(1, 1.0);
6535 __areas_.assign(1, 0.0);
6536 }
6537 else
6538 {
6539 __densities_.reserve(__b_.size() - 1);
6540 for (size_t __i = 0; __i < __b_.size() - 1; ++__i, ++__fW)
6541 __densities_.push_back(*__fW);
6542 __init();
6543 }
6544}
6545
6546#ifndef _LIBCPP_CXX03_LANG
6547
6548template<class _RealType>
6549template<class _UnaryOperation>
6550piecewise_constant_distribution<_RealType>::param_type::param_type(
6551 initializer_list<result_type> __bl, _UnaryOperation __fw)
6552 : __b_(__bl.begin(), __bl.end())
6553{
6554 if (__b_.size() < 2)
6555 {
6556 __b_.resize(2);
6557 __b_[0] = 0;
6558 __b_[1] = 1;
6559 __densities_.assign(1, 1.0);
6560 __areas_.assign(1, 0.0);
6561 }
6562 else
6563 {
6564 __densities_.reserve(__b_.size() - 1);
6565 for (size_t __i = 0; __i < __b_.size() - 1; ++__i)
6566 __densities_.push_back(__fw((__b_[__i+1] + __b_[__i])*.5));
6567 __init();
6568 }
6569}
6570
6571#endif // _LIBCPP_CXX03_LANG
6572
6573template<class _RealType>
6574template<class _UnaryOperation>
6575piecewise_constant_distribution<_RealType>::param_type::param_type(
6576 size_t __nw, result_type __xmin, result_type __xmax, _UnaryOperation __fw)
6577 : __b_(__nw == 0 ? 2 : __nw + 1)
6578{
6579 size_t __n = __b_.size() - 1;
6580 result_type __d = (__xmax - __xmin) / __n;
6581 __densities_.reserve(__n);
6582 for (size_t __i = 0; __i < __n; ++__i)
6583 {
6584 __b_[__i] = __xmin + __i * __d;
6585 __densities_.push_back(__fw(__b_[__i] + __d*.5));
6586 }
6587 __b_[__n] = __xmax;
6588 __init();
6589}
6590
6591template<class _RealType>
6592template<class _URNG>
6593_RealType
6594piecewise_constant_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
6595{
6596 typedef uniform_real_distribution<result_type> _Gen;
6597 result_type __u = _Gen()(__g);
6598 ptrdiff_t __k = _VSTD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(),
6599 __u) - __p.__areas_.begin() - 1;
6600 return (__u - __p.__areas_[__k]) / __p.__densities_[__k] + __p.__b_[__k];
6601}
6602
6603template <class _CharT, class _Traits, class _RT>
6604basic_ostream<_CharT, _Traits>&
6605operator<<(basic_ostream<_CharT, _Traits>& __os,
6606 const piecewise_constant_distribution<_RT>& __x)
6607{
6608 __save_flags<_CharT, _Traits> __lx(__os);
6609 typedef basic_ostream<_CharT, _Traits> _OStream;
6610 __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
6611 _OStream::scientific);
6612 _CharT __sp = __os.widen(' ');
6613 __os.fill(__sp);
6614 size_t __n = __x.__p_.__b_.size();
6615 __os << __n;
6616 for (size_t __i = 0; __i < __n; ++__i)
6617 __os << __sp << __x.__p_.__b_[__i];
6618 __n = __x.__p_.__densities_.size();
6619 __os << __sp << __n;
6620 for (size_t __i = 0; __i < __n; ++__i)
6621 __os << __sp << __x.__p_.__densities_[__i];
6622 __n = __x.__p_.__areas_.size();
6623 __os << __sp << __n;
6624 for (size_t __i = 0; __i < __n; ++__i)
6625 __os << __sp << __x.__p_.__areas_[__i];
6626 return __os;
6627}
6628
6629template <class _CharT, class _Traits, class _RT>
6630basic_istream<_CharT, _Traits>&
6631operator>>(basic_istream<_CharT, _Traits>& __is,
6632 piecewise_constant_distribution<_RT>& __x)
6633{
6634 typedef piecewise_constant_distribution<_RT> _Eng;
6635 typedef typename _Eng::result_type result_type;
6636 __save_flags<_CharT, _Traits> __lx(__is);
6637 typedef basic_istream<_CharT, _Traits> _Istream;
6638 __is.flags(_Istream::dec | _Istream::skipws);
6639 size_t __n;
6640 __is >> __n;
6641 vector<result_type> __b(__n);
6642 for (size_t __i = 0; __i < __n; ++__i)
6643 __is >> __b[__i];
6644 __is >> __n;
6645 vector<result_type> __densities(__n);
6646 for (size_t __i = 0; __i < __n; ++__i)
6647 __is >> __densities[__i];
6648 __is >> __n;
6649 vector<result_type> __areas(__n);
6650 for (size_t __i = 0; __i < __n; ++__i)
6651 __is >> __areas[__i];
6652 if (!__is.fail())
6653 {
6654 swap(__x.__p_.__b_, __b);
6655 swap(__x.__p_.__densities_, __densities);
6656 swap(__x.__p_.__areas_, __areas);
6657 }
6658 return __is;
6659}
6660
6661// piecewise_linear_distribution
6662
6663template<class _RealType = double>
6664class _LIBCPP_TEMPLATE_VIS piecewise_linear_distribution
6665{
6666public:
6667 // types
6668 typedef _RealType result_type;
6669
6670 class _LIBCPP_TEMPLATE_VIS param_type
6671 {
6672 vector<result_type> __b_;
6673 vector<result_type> __densities_;
6674 vector<result_type> __areas_;
6675 public:
6676 typedef piecewise_linear_distribution distribution_type;
6677
6678 param_type();
6679 template<class _InputIteratorB, class _InputIteratorW>
6680 param_type(_InputIteratorB __fB, _InputIteratorB __lB,
6681 _InputIteratorW __fW);
6682#ifndef _LIBCPP_CXX03_LANG
6683 template<class _UnaryOperation>
6684 param_type(initializer_list<result_type> __bl, _UnaryOperation __fw);
6685#endif // _LIBCPP_CXX03_LANG
6686 template<class _UnaryOperation>
6687 param_type(size_t __nw, result_type __xmin, result_type __xmax,
6688 _UnaryOperation __fw);
6689 param_type(param_type const&) = default;
6690 param_type & operator=(const param_type& __rhs);
6691
6692 _LIBCPP_INLINE_VISIBILITY
6693 vector<result_type> intervals() const {return __b_;}
6694 _LIBCPP_INLINE_VISIBILITY
6695 vector<result_type> densities() const {return __densities_;}
6696
6697 friend _LIBCPP_INLINE_VISIBILITY
6698 bool operator==(const param_type& __x, const param_type& __y)
6699 {return __x.__densities_ == __y.__densities_ && __x.__b_ == __y.__b_;}
6700 friend _LIBCPP_INLINE_VISIBILITY
6701 bool operator!=(const param_type& __x, const param_type& __y)
6702 {return !(__x == __y);}
6703
6704 private:
6705 void __init();
6706
6707 friend class piecewise_linear_distribution;
6708
6709 template <class _CharT, class _Traits, class _RT>
6710 friend
6711 basic_ostream<_CharT, _Traits>&
6712 operator<<(basic_ostream<_CharT, _Traits>& __os,
6713 const piecewise_linear_distribution<_RT>& __x);
6714
6715 template <class _CharT, class _Traits, class _RT>
6716 friend
6717 basic_istream<_CharT, _Traits>&
6718 operator>>(basic_istream<_CharT, _Traits>& __is,
6719 piecewise_linear_distribution<_RT>& __x);
6720 };
6721
6722private:
6723 param_type __p_;
6724
6725public:
6726 // constructor and reset functions
6727 _LIBCPP_INLINE_VISIBILITY
6728 piecewise_linear_distribution() {}
6729 template<class _InputIteratorB, class _InputIteratorW>
6730 _LIBCPP_INLINE_VISIBILITY
6731 piecewise_linear_distribution(_InputIteratorB __fB,
6732 _InputIteratorB __lB,
6733 _InputIteratorW __fW)
6734 : __p_(__fB, __lB, __fW) {}
6735
6736#ifndef _LIBCPP_CXX03_LANG
6737 template<class _UnaryOperation>
6738 _LIBCPP_INLINE_VISIBILITY
6739 piecewise_linear_distribution(initializer_list<result_type> __bl,
6740 _UnaryOperation __fw)
6741 : __p_(__bl, __fw) {}
6742#endif // _LIBCPP_CXX03_LANG
6743
6744 template<class _UnaryOperation>
6745 _LIBCPP_INLINE_VISIBILITY
6746 piecewise_linear_distribution(size_t __nw, result_type __xmin,
6747 result_type __xmax, _UnaryOperation __fw)
6748 : __p_(__nw, __xmin, __xmax, __fw) {}
6749
6750 _LIBCPP_INLINE_VISIBILITY
6751 explicit piecewise_linear_distribution(const param_type& __p)
6752 : __p_(__p) {}
6753
6754 _LIBCPP_INLINE_VISIBILITY
6755 void reset() {}
6756
6757 // generating functions
6758 template<class _URNG>
6759 _LIBCPP_INLINE_VISIBILITY
6760 result_type operator()(_URNG& __g)
6761 {return (*this)(__g, __p_);}
6762 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
6763
6764 // property functions
6765 _LIBCPP_INLINE_VISIBILITY
6766 vector<result_type> intervals() const {return __p_.intervals();}
6767 _LIBCPP_INLINE_VISIBILITY
6768 vector<result_type> densities() const {return __p_.densities();}
6769
6770 _LIBCPP_INLINE_VISIBILITY
6771 param_type param() const {return __p_;}
6772 _LIBCPP_INLINE_VISIBILITY
6773 void param(const param_type& __p) {__p_ = __p;}
6774
6775 _LIBCPP_INLINE_VISIBILITY
6776 result_type min() const {return __p_.__b_.front();}
6777 _LIBCPP_INLINE_VISIBILITY
6778 result_type max() const {return __p_.__b_.back();}
6779
6780 friend _LIBCPP_INLINE_VISIBILITY
6781 bool operator==(const piecewise_linear_distribution& __x,
6782 const piecewise_linear_distribution& __y)
6783 {return __x.__p_ == __y.__p_;}
6784 friend _LIBCPP_INLINE_VISIBILITY
6785 bool operator!=(const piecewise_linear_distribution& __x,
6786 const piecewise_linear_distribution& __y)
6787 {return !(__x == __y);}
6788
6789 template <class _CharT, class _Traits, class _RT>
6790 friend
6791 basic_ostream<_CharT, _Traits>&
6792 operator<<(basic_ostream<_CharT, _Traits>& __os,
6793 const piecewise_linear_distribution<_RT>& __x);
6794
6795 template <class _CharT, class _Traits, class _RT>
6796 friend
6797 basic_istream<_CharT, _Traits>&
6798 operator>>(basic_istream<_CharT, _Traits>& __is,
6799 piecewise_linear_distribution<_RT>& __x);
6800};
6801
6802template<class _RealType>
6803typename piecewise_linear_distribution<_RealType>::param_type &
6804piecewise_linear_distribution<_RealType>::param_type::operator=
6805 (const param_type& __rhs)
6806{
6807// These can throw
6808 __b_.reserve (__rhs.__b_.size ());
6809 __densities_.reserve(__rhs.__densities_.size());
6810 __areas_.reserve (__rhs.__areas_.size());
6811
6812// These can not throw
6813 __b_ = __rhs.__b_;
6814 __densities_ = __rhs.__densities_;
6815 __areas_ = __rhs.__areas_;
6816 return *this;
6817}
6818
6819
6820template<class _RealType>
6821void
6822piecewise_linear_distribution<_RealType>::param_type::__init()
6823{
6824 __areas_.assign(__densities_.size() - 1, result_type());
6825 result_type _Sp = 0;
6826 for (size_t __i = 0; __i < __areas_.size(); ++__i)
6827 {
6828 __areas_[__i] = (__densities_[__i+1] + __densities_[__i]) *
6829 (__b_[__i+1] - __b_[__i]) * .5;
6830 _Sp += __areas_[__i];
6831 }
6832 for (size_t __i = __areas_.size(); __i > 1;)
6833 {
6834 --__i;
6835 __areas_[__i] = __areas_[__i-1] / _Sp;
6836 }
6837 __areas_[0] = 0;
6838 for (size_t __i = 1; __i < __areas_.size(); ++__i)
6839 __areas_[__i] += __areas_[__i-1];
6840 for (size_t __i = 0; __i < __densities_.size(); ++__i)
6841 __densities_[__i] /= _Sp;
6842}
6843
6844template<class _RealType>
6845piecewise_linear_distribution<_RealType>::param_type::param_type()
6846 : __b_(2),
6847 __densities_(2, 1.0),
6848 __areas_(1, 0.0)
6849{
6850 __b_[1] = 1;
6851}
6852
6853template<class _RealType>
6854template<class _InputIteratorB, class _InputIteratorW>
6855piecewise_linear_distribution<_RealType>::param_type::param_type(
6856 _InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW)
6857 : __b_(__fB, __lB)
6858{
6859 if (__b_.size() < 2)
6860 {
6861 __b_.resize(2);
6862 __b_[0] = 0;
6863 __b_[1] = 1;
6864 __densities_.assign(2, 1.0);
6865 __areas_.assign(1, 0.0);
6866 }
6867 else
6868 {
6869 __densities_.reserve(__b_.size());
6870 for (size_t __i = 0; __i < __b_.size(); ++__i, ++__fW)
6871 __densities_.push_back(*__fW);
6872 __init();
6873 }
6874}
6875
6876#ifndef _LIBCPP_CXX03_LANG
6877
6878template<class _RealType>
6879template<class _UnaryOperation>
6880piecewise_linear_distribution<_RealType>::param_type::param_type(
6881 initializer_list<result_type> __bl, _UnaryOperation __fw)
6882 : __b_(__bl.begin(), __bl.end())
6883{
6884 if (__b_.size() < 2)
6885 {
6886 __b_.resize(2);
6887 __b_[0] = 0;
6888 __b_[1] = 1;
6889 __densities_.assign(2, 1.0);
6890 __areas_.assign(1, 0.0);
6891 }
6892 else
6893 {
6894 __densities_.reserve(__b_.size());
6895 for (size_t __i = 0; __i < __b_.size(); ++__i)
6896 __densities_.push_back(__fw(__b_[__i]));
6897 __init();
6898 }
6899}
6900
6901#endif // _LIBCPP_CXX03_LANG
6902
6903template<class _RealType>
6904template<class _UnaryOperation>
6905piecewise_linear_distribution<_RealType>::param_type::param_type(
6906 size_t __nw, result_type __xmin, result_type __xmax, _UnaryOperation __fw)
6907 : __b_(__nw == 0 ? 2 : __nw + 1)
6908{
6909 size_t __n = __b_.size() - 1;
6910 result_type __d = (__xmax - __xmin) / __n;
6911 __densities_.reserve(__b_.size());
6912 for (size_t __i = 0; __i < __n; ++__i)
6913 {
6914 __b_[__i] = __xmin + __i * __d;
6915 __densities_.push_back(__fw(__b_[__i]));
6916 }
6917 __b_[__n] = __xmax;
6918 __densities_.push_back(__fw(__b_[__n]));
6919 __init();
6920}
6921
6922template<class _RealType>
6923template<class _URNG>
6924_RealType
6925piecewise_linear_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
6926{
6927 typedef uniform_real_distribution<result_type> _Gen;
6928 result_type __u = _Gen()(__g);
6929 ptrdiff_t __k = _VSTD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(),
6930 __u) - __p.__areas_.begin() - 1;
6931 __u -= __p.__areas_[__k];
6932 const result_type __dk = __p.__densities_[__k];
6933 const result_type __dk1 = __p.__densities_[__k+1];
6934 const result_type __deltad = __dk1 - __dk;
6935 const result_type __bk = __p.__b_[__k];
6936 if (__deltad == 0)
6937 return __u / __dk + __bk;
6938 const result_type __bk1 = __p.__b_[__k+1];
6939 const result_type __deltab = __bk1 - __bk;
6940 return (__bk * __dk1 - __bk1 * __dk +
6941 _VSTD::sqrt(__deltab * (__deltab * __dk * __dk + 2 * __deltad * __u))) /
6942 __deltad;
6943}
6944
6945template <class _CharT, class _Traits, class _RT>
6946basic_ostream<_CharT, _Traits>&
6947operator<<(basic_ostream<_CharT, _Traits>& __os,
6948 const piecewise_linear_distribution<_RT>& __x)
6949{
6950 __save_flags<_CharT, _Traits> __lx(__os);
6951 typedef basic_ostream<_CharT, _Traits> _OStream;
6952 __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
6953 _OStream::scientific);
6954 _CharT __sp = __os.widen(' ');
6955 __os.fill(__sp);
6956 size_t __n = __x.__p_.__b_.size();
6957 __os << __n;
6958 for (size_t __i = 0; __i < __n; ++__i)
6959 __os << __sp << __x.__p_.__b_[__i];
6960 __n = __x.__p_.__densities_.size();
6961 __os << __sp << __n;
6962 for (size_t __i = 0; __i < __n; ++__i)
6963 __os << __sp << __x.__p_.__densities_[__i];
6964 __n = __x.__p_.__areas_.size();
6965 __os << __sp << __n;
6966 for (size_t __i = 0; __i < __n; ++__i)
6967 __os << __sp << __x.__p_.__areas_[__i];
6968 return __os;
6969}
6970
6971template <class _CharT, class _Traits, class _RT>
6972basic_istream<_CharT, _Traits>&
6973operator>>(basic_istream<_CharT, _Traits>& __is,
6974 piecewise_linear_distribution<_RT>& __x)
6975{
6976 typedef piecewise_linear_distribution<_RT> _Eng;
6977 typedef typename _Eng::result_type result_type;
6978 __save_flags<_CharT, _Traits> __lx(__is);
6979 typedef basic_istream<_CharT, _Traits> _Istream;
6980 __is.flags(_Istream::dec | _Istream::skipws);
6981 size_t __n;
6982 __is >> __n;
6983 vector<result_type> __b(__n);
6984 for (size_t __i = 0; __i < __n; ++__i)
6985 __is >> __b[__i];
6986 __is >> __n;
6987 vector<result_type> __densities(__n);
6988 for (size_t __i = 0; __i < __n; ++__i)
6989 __is >> __densities[__i];
6990 __is >> __n;
6991 vector<result_type> __areas(__n);
6992 for (size_t __i = 0; __i < __n; ++__i)
6993 __is >> __areas[__i];
6994 if (!__is.fail())
6995 {
6996 swap(__x.__p_.__b_, __b);
6997 swap(__x.__p_.__densities_, __densities);
6998 swap(__x.__p_.__areas_, __areas);
6999 }
7000 return __is;
7001}
7002
7003_LIBCPP_END_NAMESPACE_STD
7004
7005_LIBCPP_POP_MACROS
7006
70071735#endif // _LIBCPP_RANDOM
lib/libcxx/include/ranges+50-22
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- ranges -----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -36,7 +36,7 @@ namespace std::ranges {
3636 inline constexpr bool enable_borrowed_range = false;
3737
3838 template<class T>
39 using iterator_t = decltype(ranges::begin(declval<R&>()));
39 using iterator_t = decltype(ranges::begin(declval<T&>()));
4040 template<range R>
4141 using sentinel_t = decltype(ranges::end(declval<R&>()));
4242 template<range R>
......@@ -135,6 +135,13 @@ namespace std::ranges {
135135 template<class T>
136136 inline constexpr bool enable_borrowed_range<ref_view<T>> = true;
137137
138 template<range R>
139 requires see below
140 class owning_view;
141
142 template<class T>
143 inline constexpr bool enable_borrowed_range<owning_view<T>> = enable_borrowed_range<T>;
144
138145 // [range.drop], drop view
139146 template<view V>
140147 class drop_view;
......@@ -149,27 +156,56 @@ namespace std::ranges {
149156 can-reference<invoke_result_t<F&, range_reference_t<V>>>
150157 class transform_view;
151158
159 // [range.counted], counted view
160 namespace views { inline constexpr unspecified counted = unspecified; }
161
152162 // [range.common], common view
153163 template<view V>
154164 requires (!common_range<V> && copyable<iterator_t<V>>)
155165 class common_view;
156166
167 // [range.reverse], reverse view
168 template<view V>
169 requires bidirectional_range<V>
170 class reverse_view;
171
172 template<class T>
173 inline constexpr bool enable_borrowed_range<reverse_view<T>> = enable_borrowed_range<T>;
174
157175 template<class T>
158176 inline constexpr bool enable_borrowed_range<common_view<T>> = enable_borrowed_range<T>;
177
178 // [range.take], take view
179 template<view> class take_view;
180
181 template<class T>
182 inline constexpr bool enable_borrowed_range<take_view<T>> = enable_borrowed_range<T>;
183
184 template<copy_constructible T>
185 requires is_object_v<T>
186 class single_view;
187
188 template<weakly_incrementable W, semiregular Bound = unreachable_sentinel_t>
189 requires weakly-equality-comparable-with<W, Bound> && copyable<W>
190 class iota_view;
191
192 template<class W, class Bound>
193 inline constexpr bool enable_borrowed_range<iota_view<W, Bound>> = true;
194
195 // [range.join], join view
196 template<input_range V>
197 requires view<V> && input_range<range_reference_t<V>>
198 class join_view;
159199}
160200
161201*/
162202
163// Make sure all feature tests macros are always available.
164#include <version>
165// Only enable the contents of the header when libc++ was build with LIBCXX_ENABLE_INCOMPLETE_FEATURES enabled
166#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
167
168203#include <__config>
169204#include <__ranges/access.h>
170205#include <__ranges/all.h>
171206#include <__ranges/common_view.h>
172207#include <__ranges/concepts.h>
208#include <__ranges/counted.h>
173209#include <__ranges/dangling.h>
174210#include <__ranges/data.h>
175211#include <__ranges/drop_view.h>
......@@ -177,33 +213,25 @@ namespace std::ranges {
177213#include <__ranges/empty_view.h>
178214#include <__ranges/enable_borrowed_range.h>
179215#include <__ranges/enable_view.h>
216#include <__ranges/iota_view.h>
217#include <__ranges/join_view.h>
180218#include <__ranges/ref_view.h>
219#include <__ranges/reverse_view.h>
220#include <__ranges/single_view.h>
181221#include <__ranges/size.h>
182222#include <__ranges/subrange.h>
223#include <__ranges/take_view.h>
183224#include <__ranges/transform_view.h>
184225#include <__ranges/view_interface.h>
226#include <__ranges/views.h>
185227#include <compare> // Required by the standard.
186228#include <initializer_list> // Required by the standard.
187229#include <iterator> // Required by the standard.
188230#include <type_traits>
231#include <version>
189232
190233#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
191234#pragma GCC system_header
192235#endif
193236
194_LIBCPP_PUSH_MACROS
195#include <__undef_macros>
196
197_LIBCPP_BEGIN_NAMESPACE_STD
198
199#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_RANGES)
200
201#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_RANGES)
202
203_LIBCPP_END_NAMESPACE_STD
204
205_LIBCPP_POP_MACROS
206
207#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
208
209237#endif // _LIBCPP_RANGES
lib/libcxx/include/ratio+9-14
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===---------------------------- ratio -----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -81,6 +81,7 @@ typedef ratio<1000000000000000000000000, 1> yotta; // not supported
8181#include <climits>
8282#include <cstdint>
8383#include <type_traits>
84#include <version>
8485
8586#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
8687#pragma GCC system_header
......@@ -499,30 +500,24 @@ struct __ratio_gcd
499500 __static_lcm<_R1::den, _R2::den>::value> type;
500501};
501502
502#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
503#if _LIBCPP_STD_VER > 14
503504template <class _R1, class _R2>
504_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool ratio_equal_v
505 = ratio_equal<_R1, _R2>::value;
505inline constexpr bool ratio_equal_v = ratio_equal<_R1, _R2>::value;
506506
507507template <class _R1, class _R2>
508_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool ratio_not_equal_v
509 = ratio_not_equal<_R1, _R2>::value;
508inline constexpr bool ratio_not_equal_v = ratio_not_equal<_R1, _R2>::value;
510509
511510template <class _R1, class _R2>
512_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool ratio_less_v
513 = ratio_less<_R1, _R2>::value;
511inline constexpr bool ratio_less_v = ratio_less<_R1, _R2>::value;
514512
515513template <class _R1, class _R2>
516_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool ratio_less_equal_v
517 = ratio_less_equal<_R1, _R2>::value;
514inline constexpr bool ratio_less_equal_v = ratio_less_equal<_R1, _R2>::value;
518515
519516template <class _R1, class _R2>
520_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool ratio_greater_v
521 = ratio_greater<_R1, _R2>::value;
517inline constexpr bool ratio_greater_v = ratio_greater<_R1, _R2>::value;
522518
523519template <class _R1, class _R2>
524_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool ratio_greater_equal_v
525 = ratio_greater_equal<_R1, _R2>::value;
520inline constexpr bool ratio_greater_equal_v = ratio_greater_equal<_R1, _R2>::value;
526521#endif
527522
528523_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/regex+79-21
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- regex ------------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -978,7 +978,7 @@ enum error_type
978978 __re_err_parse
979979};
980980
981} // regex_constants
981} // namespace regex_constants
982982
983983class _LIBCPP_EXCEPTION_ABI regex_error
984984 : public runtime_error
......@@ -1072,32 +1072,38 @@ private:
10721072 template <class _ForwardIterator>
10731073 string_type
10741074 __transform_primary(_ForwardIterator __f, _ForwardIterator __l, char) const;
1075#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
10751076 template <class _ForwardIterator>
10761077 string_type
10771078 __transform_primary(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
1078
1079#endif
10791080 template <class _ForwardIterator>
10801081 string_type
10811082 __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, char) const;
1083#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
10821084 template <class _ForwardIterator>
10831085 string_type
10841086 __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
1085
1087#endif
10861088 template <class _ForwardIterator>
10871089 char_class_type
10881090 __lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
10891091 bool __icase, char) const;
1092#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
10901093 template <class _ForwardIterator>
10911094 char_class_type
10921095 __lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
10931096 bool __icase, wchar_t) const;
1097#endif
10941098
10951099 static int __regex_traits_value(unsigned char __ch, int __radix);
10961100 _LIBCPP_INLINE_VISIBILITY
10971101 int __regex_traits_value(char __ch, int __radix) const
10981102 {return __regex_traits_value(static_cast<unsigned char>(__ch), __radix);}
1103#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
10991104 _LIBCPP_INLINE_VISIBILITY
11001105 int __regex_traits_value(wchar_t __ch, int __radix) const;
1106#endif
11011107};
11021108
11031109template <class _CharT>
......@@ -1168,6 +1174,7 @@ regex_traits<_CharT>::__transform_primary(_ForwardIterator __f,
11681174 return __d;
11691175}
11701176
1177#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
11711178template <class _CharT>
11721179template <class _ForwardIterator>
11731180typename regex_traits<_CharT>::string_type
......@@ -1189,6 +1196,7 @@ regex_traits<_CharT>::__transform_primary(_ForwardIterator __f,
11891196 }
11901197 return __d;
11911198}
1199#endif
11921200
11931201// lookup_collatename is very FreeBSD-specific
11941202
......@@ -1217,6 +1225,7 @@ regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f,
12171225 return __r;
12181226}
12191227
1228#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
12201229template <class _CharT>
12211230template <class _ForwardIterator>
12221231typename regex_traits<_CharT>::string_type
......@@ -1250,6 +1259,7 @@ regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f,
12501259 }
12511260 return __r;
12521261}
1262#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
12531263
12541264// lookup_classname
12551265
......@@ -1268,6 +1278,7 @@ regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f,
12681278 return __get_classname(__s.c_str(), __icase);
12691279}
12701280
1281#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
12711282template <class _CharT>
12721283template <class _ForwardIterator>
12731284typename regex_traits<_CharT>::char_class_type
......@@ -1288,6 +1299,7 @@ regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f,
12881299 }
12891300 return __get_classname(__n.c_str(), __icase);
12901301}
1302#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
12911303
12921304template <class _CharT>
12931305bool
......@@ -1298,19 +1310,51 @@ regex_traits<_CharT>::isctype(char_type __c, char_class_type __m) const
12981310 return (__c == '_' && (__m & __regex_word));
12991311}
13001312
1313inline _LIBCPP_INLINE_VISIBILITY
1314bool __is_07(unsigned char c)
1315{
1316 return (c & 0xF8u) ==
1317#if defined(__MVS__) && !defined(__NATIVE_ASCII_F)
1318 0xF0;
1319#else
1320 0x30;
1321#endif
1322}
1323
1324inline _LIBCPP_INLINE_VISIBILITY
1325bool __is_89(unsigned char c)
1326{
1327 return (c & 0xFEu) ==
1328#if defined(__MVS__) && !defined(__NATIVE_ASCII_F)
1329 0xF8;
1330#else
1331 0x38;
1332#endif
1333}
1334
1335inline _LIBCPP_INLINE_VISIBILITY
1336unsigned char __to_lower(unsigned char c)
1337{
1338#if defined(__MVS__) && !defined(__NATIVE_ASCII_F)
1339 return c & 0xBF;
1340#else
1341 return c | 0x20;
1342#endif
1343}
1344
13011345template <class _CharT>
13021346int
13031347regex_traits<_CharT>::__regex_traits_value(unsigned char __ch, int __radix)
13041348{
1305 if ((__ch & 0xF8u) == 0x30) // '0' <= __ch && __ch <= '7'
1349 if (__is_07(__ch)) // '0' <= __ch && __ch <= '7'
13061350 return __ch - '0';
13071351 if (__radix != 8)
13081352 {
1309 if ((__ch & 0xFEu) == 0x38) // '8' <= __ch && __ch <= '9'
1353 if (__is_89(__ch)) // '8' <= __ch && __ch <= '9'
13101354 return __ch - '0';
13111355 if (__radix == 16)
13121356 {
1313 __ch |= 0x20; // tolower
1357 __ch = __to_lower(__ch); // tolower
13141358 if ('a' <= __ch && __ch <= 'f')
13151359 return __ch - ('a' - 10);
13161360 }
......@@ -1318,6 +1362,7 @@ regex_traits<_CharT>::__regex_traits_value(unsigned char __ch, int __radix)
13181362 return -1;
13191363}
13201364
1365#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
13211366template <class _CharT>
13221367inline
13231368int
......@@ -1325,6 +1370,7 @@ regex_traits<_CharT>::__regex_traits_value(wchar_t __ch, int __radix) const
13251370{
13261371 return __regex_traits_value(static_cast<unsigned char>(__ct_->narrow(__ch, char_type())), __radix);
13271372}
1373#endif
13281374
13291375template <class _CharT> class __node;
13301376
......@@ -2135,7 +2181,9 @@ public:
21352181};
21362182
21372183template <> _LIBCPP_FUNC_VIS void __match_any_but_newline<char>::__exec(__state&) const;
2184#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
21382185template <> _LIBCPP_FUNC_VIS void __match_any_but_newline<wchar_t>::__exec(__state&) const;
2186#endif
21392187
21402188// __match_char
21412189
......@@ -2542,13 +2590,15 @@ template <class _CharT, class _Traits = regex_traits<_CharT> >
25422590 class _LIBCPP_TEMPLATE_VIS basic_regex;
25432591
25442592typedef basic_regex<char> regex;
2593#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
25452594typedef basic_regex<wchar_t> wregex;
2595#endif
25462596
25472597template <class _CharT, class _Traits>
25482598class
25492599 _LIBCPP_TEMPLATE_VIS
25502600 _LIBCPP_PREFERRED_NAME(regex)
2551 _LIBCPP_PREFERRED_NAME(wregex)
2601 _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wregex))
25522602 basic_regex
25532603{
25542604public:
......@@ -3014,7 +3064,7 @@ private:
30143064 template <class, class> friend class __lookahead;
30153065};
30163066
3017#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
3067#if _LIBCPP_STD_VER >= 17
30183068template <class _ForwardIterator,
30193069 class = typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value, nullptr_t>::type
30203070>
......@@ -4897,17 +4947,19 @@ basic_regex<_CharT, _Traits>::__push_lookahead(const basic_regex& __exp,
48974947// sub_match
48984948
48994949typedef sub_match<const char*> csub_match;
4900typedef sub_match<const wchar_t*> wcsub_match;
49014950typedef sub_match<string::const_iterator> ssub_match;
4951#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4952typedef sub_match<const wchar_t*> wcsub_match;
49024953typedef sub_match<wstring::const_iterator> wssub_match;
4954#endif
49034955
49044956template <class _BidirectionalIterator>
49054957class
49064958 _LIBCPP_TEMPLATE_VIS
49074959 _LIBCPP_PREFERRED_NAME(csub_match)
4908 _LIBCPP_PREFERRED_NAME(wcsub_match)
4960 _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcsub_match))
49094961 _LIBCPP_PREFERRED_NAME(ssub_match)
4910 _LIBCPP_PREFERRED_NAME(wssub_match)
4962 _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wssub_match))
49114963 sub_match
49124964 : public pair<_BidirectionalIterator, _BidirectionalIterator>
49134965{
......@@ -5326,17 +5378,19 @@ operator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m)
53265378}
53275379
53285380typedef match_results<const char*> cmatch;
5329typedef match_results<const wchar_t*> wcmatch;
53305381typedef match_results<string::const_iterator> smatch;
5382#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
5383typedef match_results<const wchar_t*> wcmatch;
53315384typedef match_results<wstring::const_iterator> wsmatch;
5385#endif
53325386
53335387template <class _BidirectionalIterator, class _Allocator>
53345388class
53355389 _LIBCPP_TEMPLATE_VIS
53365390 _LIBCPP_PREFERRED_NAME(cmatch)
5337 _LIBCPP_PREFERRED_NAME(wcmatch)
5391 _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcmatch))
53385392 _LIBCPP_PREFERRED_NAME(smatch)
5339 _LIBCPP_PREFERRED_NAME(wsmatch)
5393 _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wsmatch))
53405394 match_results
53415395{
53425396public:
......@@ -6244,17 +6298,19 @@ template <class _BidirectionalIterator,
62446298 class _LIBCPP_TEMPLATE_VIS regex_iterator;
62456299
62466300typedef regex_iterator<const char*> cregex_iterator;
6247typedef regex_iterator<const wchar_t*> wcregex_iterator;
62486301typedef regex_iterator<string::const_iterator> sregex_iterator;
6302#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
6303typedef regex_iterator<const wchar_t*> wcregex_iterator;
62496304typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
6305#endif
62506306
62516307template <class _BidirectionalIterator, class _CharT, class _Traits>
62526308class
62536309 _LIBCPP_TEMPLATE_VIS
62546310 _LIBCPP_PREFERRED_NAME(cregex_iterator)
6255 _LIBCPP_PREFERRED_NAME(wcregex_iterator)
6311 _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcregex_iterator))
62566312 _LIBCPP_PREFERRED_NAME(sregex_iterator)
6257 _LIBCPP_PREFERRED_NAME(wsregex_iterator)
6313 _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wsregex_iterator))
62586314 regex_iterator
62596315{
62606316public:
......@@ -6372,17 +6428,19 @@ template <class _BidirectionalIterator,
63726428 class _LIBCPP_TEMPLATE_VIS regex_token_iterator;
63736429
63746430typedef regex_token_iterator<const char*> cregex_token_iterator;
6375typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
63766431typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
6432#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
6433typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
63776434typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
6435#endif
63786436
63796437template <class _BidirectionalIterator, class _CharT, class _Traits>
63806438class
63816439 _LIBCPP_TEMPLATE_VIS
63826440 _LIBCPP_PREFERRED_NAME(cregex_token_iterator)
6383 _LIBCPP_PREFERRED_NAME(wcregex_token_iterator)
6441 _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcregex_token_iterator))
63846442 _LIBCPP_PREFERRED_NAME(sregex_token_iterator)
6385 _LIBCPP_PREFERRED_NAME(wsregex_token_iterator)
6443 _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wsregex_token_iterator))
63866444 regex_token_iterator
63876445{
63886446public:
lib/libcxx/include/scoped_allocator+11-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===-------------------------- scoped_allocator --------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -91,6 +91,10 @@ public:
9191 scoped_allocator_adaptor select_on_container_copy_construction() const noexcept;
9292};
9393
94template<class OuterAlloc, class... InnerAllocs>
95 scoped_allocator_adaptor(OuterAlloc, InnerAllocs...)
96 -> scoped_allocator_adaptor<OuterAlloc, InnerAllocs...>;
97
9498template <class OuterA1, class OuterA2, class... InnerAllocs>
9599 bool
96100 operator==(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a,
......@@ -649,6 +653,12 @@ private:
649653 template <class...> friend class __scoped_allocator_storage;
650654};
651655
656#if _LIBCPP_STD_VER > 14
657template<class _OuterAlloc, class... _InnerAllocs>
658 scoped_allocator_adaptor(_OuterAlloc, _InnerAllocs...)
659 -> scoped_allocator_adaptor<_OuterAlloc, _InnerAllocs...>;
660#endif
661
652662template <class _OuterA1, class _OuterA2>
653663inline _LIBCPP_INLINE_VISIBILITY
654664bool
lib/libcxx/include/semaphore+21-73
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- semaphore --------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -47,8 +47,10 @@ using binary_semaphore = counting_semaphore<1>;
4747
4848#include <__availability>
4949#include <__config>
50#include <__thread/timed_backoff_policy.h>
5051#include <__threading_support>
5152#include <atomic>
53#include <version>
5254
5355#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
5456#pragma GCC system_header
......@@ -67,10 +69,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
6769
6870/*
6971
70__atomic_semaphore_base is the general-case implementation, to be used for
71user-requested least-max values that exceed the OS implementation support
72(incl. when the OS has no support of its own) and for binary semaphores.
73
72__atomic_semaphore_base is the general-case implementation.
7473It is a typical Dijkstra semaphore algorithm over atomics, wait and notify
7574functions. It avoids contention against users' own use of those facilities.
7675
......@@ -82,7 +81,7 @@ class __atomic_semaphore_base
8281
8382public:
8483 _LIBCPP_INLINE_VISIBILITY
85 __atomic_semaphore_base(ptrdiff_t __count) : __a(__count)
84 constexpr explicit __atomic_semaphore_base(ptrdiff_t __count) : __a(__count)
8685 {
8786 }
8887 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
......@@ -108,81 +107,30 @@ public:
108107 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
109108 bool try_acquire_for(chrono::duration<Rep, Period> const& __rel_time)
110109 {
111 auto const __test_fn = [this]() -> bool {
112 auto __old = __a.load(memory_order_acquire);
113 while(1) {
114 if (__old == 0)
115 return false;
116 if(__a.compare_exchange_strong(__old, __old - 1, memory_order_acquire, memory_order_relaxed))
117 return true;
118 }
119 };
110 if (__rel_time == chrono::duration<Rep, Period>::zero())
111 return try_acquire();
112 auto const __test_fn = [this]() { return try_acquire(); };
120113 return __libcpp_thread_poll_with_backoff(__test_fn, __libcpp_timed_backoff_policy(), __rel_time);
121114 }
122};
123
124#ifndef _LIBCPP_NO_NATIVE_SEMAPHORES
125
126/*
127
128__platform_semaphore_base a simple wrapper for the OS semaphore type. That
129is, every call is routed to the OS in the most direct manner possible.
130
131*/
132
133class __platform_semaphore_base
134{
135 __libcpp_semaphore_t __semaphore;
136
137public:
138 _LIBCPP_INLINE_VISIBILITY
139 __platform_semaphore_base(ptrdiff_t __count) :
140 __semaphore()
141 {
142 __libcpp_semaphore_init(&__semaphore, __count);
143 }
144 _LIBCPP_INLINE_VISIBILITY
145 ~__platform_semaphore_base() {
146 __libcpp_semaphore_destroy(&__semaphore);
147 }
148 _LIBCPP_INLINE_VISIBILITY
149 void release(ptrdiff_t __update)
150 {
151 for(; __update; --__update)
152 __libcpp_semaphore_post(&__semaphore);
153 }
154 _LIBCPP_INLINE_VISIBILITY
155 void acquire()
156 {
157 __libcpp_semaphore_wait(&__semaphore);
158 }
159 _LIBCPP_INLINE_VISIBILITY
160 bool try_acquire_for(chrono::nanoseconds __rel_time)
115 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
116 bool try_acquire()
161117 {
162 return __libcpp_semaphore_wait_timed(&__semaphore, __rel_time);
118 auto __old = __a.load(memory_order_acquire);
119 while (true) {
120 if (__old == 0)
121 return false;
122 if (__a.compare_exchange_strong(__old, __old - 1, memory_order_acquire, memory_order_relaxed))
123 return true;
124 }
163125 }
164126};
165127
166template<ptrdiff_t __least_max_value>
167using __semaphore_base =
168 typename conditional<(__least_max_value > 1 && __least_max_value <= _LIBCPP_SEMAPHORE_MAX),
169 __platform_semaphore_base,
170 __atomic_semaphore_base>::type;
171
172#else
173
174template<ptrdiff_t __least_max_value>
175using __semaphore_base =
176 __atomic_semaphore_base;
177
178128#define _LIBCPP_SEMAPHORE_MAX (numeric_limits<ptrdiff_t>::max())
179129
180#endif //_LIBCPP_NO_NATIVE_SEMAPHORES
181
182130template<ptrdiff_t __least_max_value = _LIBCPP_SEMAPHORE_MAX>
183131class counting_semaphore
184132{
185 __semaphore_base<__least_max_value> __semaphore;
133 __atomic_semaphore_base __semaphore;
186134
187135public:
188136 static constexpr ptrdiff_t max() noexcept {
......@@ -190,7 +138,7 @@ public:
190138 }
191139
192140 _LIBCPP_INLINE_VISIBILITY
193 counting_semaphore(ptrdiff_t __count = 0) : __semaphore(__count) { }
141 constexpr explicit counting_semaphore(ptrdiff_t __count) : __semaphore(__count) { }
194142 ~counting_semaphore() = default;
195143
196144 counting_semaphore(const counting_semaphore&) = delete;
......@@ -215,14 +163,14 @@ public:
215163 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
216164 bool try_acquire()
217165 {
218 return try_acquire_for(chrono::nanoseconds::zero());
166 return __semaphore.try_acquire();
219167 }
220168 template <class Clock, class Duration>
221169 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
222170 bool try_acquire_until(chrono::time_point<Clock, Duration> const& __abs_time)
223171 {
224172 auto const current = Clock::now();
225 if(current >= __abs_time)
173 if (current >= __abs_time)
226174 return try_acquire();
227175 else
228176 return try_acquire_for(__abs_time - current);
lib/libcxx/include/set+60-19
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===---------------------------- set -------------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -183,6 +183,25 @@ public:
183183 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
184184};
185185
186template <class InputIterator,
187 class Compare = less<typename iterator_traits<InputIterator>::value_type>,
188 class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
189set(InputIterator, InputIterator,
190 Compare = Compare(), Allocator = Allocator())
191 -> set<typename iterator_traits<InputIterator>::value_type, Compare, Allocator>; // C++17
192
193template<class Key, class Compare = less<Key>, class Allocator = allocator<Key>>
194set(initializer_list<Key>, Compare = Compare(), Allocator = Allocator())
195 -> set<Key, Compare, Allocator>; // C++17
196
197template<class InputIterator, class Allocator>
198set(InputIterator, InputIterator, Allocator)
199 -> set<typename iterator_traits<InputIterator>::value_type,
200 less<typename iterator_traits<InputIterator>::value_type>, Allocator>; // C++17
201
202template<class Key, class Allocator>
203set(initializer_list<Key>, Allocator) -> set<Key, less<Key>, Allocator>; // C++17
204
186205template <class Key, class Compare, class Allocator>
187206bool
188207operator==(const set<Key, Compare, Allocator>& x,
......@@ -389,6 +408,25 @@ public:
389408 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
390409};
391410
411template <class InputIterator,
412 class Compare = less<typename iterator_traits<InputIterator>::value_type>,
413 class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
414multiset(InputIterator, InputIterator,
415 Compare = Compare(), Allocator = Allocator())
416 -> multiset<typename iterator_traits<InputIterator>::value_type, Compare, Allocator>; // C++17
417
418template<class Key, class Compare = less<Key>, class Allocator = allocator<Key>>
419multiset(initializer_list<Key>, Compare = Compare(), Allocator = Allocator())
420 -> multiset<Key, Compare, Allocator>; // C++17
421
422template<class InputIterator, class Allocator>
423multiset(InputIterator, InputIterator, Allocator)
424 -> multiset<typename iterator_traits<InputIterator>::value_type,
425 less<typename iterator_traits<InputIterator>::value_type>, Allocator>; // C++17
426
427template<class Key, class Allocator>
428multiset(initializer_list<Key>, Allocator) -> multiset<Key, less<Key>, Allocator>; // C++17
429
392430template <class Key, class Compare, class Allocator>
393431bool
394432operator==(const multiset<Key, Compare, Allocator>& x,
......@@ -436,6 +474,7 @@ erase_if(multiset<Key, Compare, Allocator>& c, Predicate pred); // C++20
436474#include <__config>
437475#include <__debug>
438476#include <__functional/is_transparent.h>
477#include <__iterator/iterator_traits.h>
439478#include <__node_handle>
440479#include <__tree>
441480#include <__utility/forward.h>
......@@ -462,7 +501,7 @@ public:
462501 // types:
463502 typedef _Key key_type;
464503 typedef key_type value_type;
465 typedef _Compare key_compare;
504 typedef __identity_t<_Compare> key_compare;
466505 typedef key_compare value_compare;
467506 typedef __identity_t<_Allocator> allocator_type;
468507 typedef value_type& reference;
......@@ -474,7 +513,6 @@ public:
474513private:
475514 typedef __tree<value_type, value_compare, allocator_type> __base;
476515 typedef allocator_traits<allocator_type> __alloc_traits;
477 typedef typename __base::__node_holder __node_holder;
478516
479517 __base __tree_;
480518
......@@ -868,30 +906,32 @@ public:
868906#endif
869907};
870908
871#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
909#if _LIBCPP_STD_VER >= 17
872910template<class _InputIterator,
873911 class _Compare = less<__iter_value_type<_InputIterator>>,
874912 class _Allocator = allocator<__iter_value_type<_InputIterator>>,
875 class = _EnableIf<__is_allocator<_Allocator>::value, void>,
876 class = _EnableIf<!__is_allocator<_Compare>::value, void>>
913 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, void>,
914 class = enable_if_t<__is_allocator<_Allocator>::value, void>,
915 class = enable_if_t<!__is_allocator<_Compare>::value, void>>
877916set(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
878917 -> set<__iter_value_type<_InputIterator>, _Compare, _Allocator>;
879918
880919template<class _Key, class _Compare = less<_Key>,
881920 class _Allocator = allocator<_Key>,
882 class = _EnableIf<__is_allocator<_Allocator>::value, void>,
883 class = _EnableIf<!__is_allocator<_Compare>::value, void>>
921 class = enable_if_t<!__is_allocator<_Compare>::value, void>,
922 class = enable_if_t<__is_allocator<_Allocator>::value, void>>
884923set(initializer_list<_Key>, _Compare = _Compare(), _Allocator = _Allocator())
885924 -> set<_Key, _Compare, _Allocator>;
886925
887926template<class _InputIterator, class _Allocator,
888 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
927 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, void>,
928 class = enable_if_t<__is_allocator<_Allocator>::value, void>>
889929set(_InputIterator, _InputIterator, _Allocator)
890930 -> set<__iter_value_type<_InputIterator>,
891931 less<__iter_value_type<_InputIterator>>, _Allocator>;
892932
893933template<class _Key, class _Allocator,
894 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
934 class = enable_if_t<__is_allocator<_Allocator>::value, void>>
895935set(initializer_list<_Key>, _Allocator)
896936 -> set<_Key, less<_Key>, _Allocator>;
897937#endif
......@@ -994,7 +1034,7 @@ public:
9941034 // types:
9951035 typedef _Key key_type;
9961036 typedef key_type value_type;
997 typedef _Compare key_compare;
1037 typedef __identity_t<_Compare> key_compare;
9981038 typedef key_compare value_compare;
9991039 typedef __identity_t<_Allocator> allocator_type;
10001040 typedef value_type& reference;
......@@ -1006,7 +1046,6 @@ public:
10061046private:
10071047 typedef __tree<value_type, value_compare, allocator_type> __base;
10081048 typedef allocator_traits<allocator_type> __alloc_traits;
1009 typedef typename __base::__node_holder __node_holder;
10101049
10111050 __base __tree_;
10121051
......@@ -1399,30 +1438,32 @@ public:
13991438#endif
14001439};
14011440
1402#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
1441#if _LIBCPP_STD_VER >= 17
14031442template<class _InputIterator,
14041443 class _Compare = less<__iter_value_type<_InputIterator>>,
14051444 class _Allocator = allocator<__iter_value_type<_InputIterator>>,
1406 class = _EnableIf<__is_allocator<_Allocator>::value, void>,
1407 class = _EnableIf<!__is_allocator<_Compare>::value, void>>
1445 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, void>,
1446 class = enable_if_t<__is_allocator<_Allocator>::value, void>,
1447 class = enable_if_t<!__is_allocator<_Compare>::value, void>>
14081448multiset(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
14091449 -> multiset<__iter_value_type<_InputIterator>, _Compare, _Allocator>;
14101450
14111451template<class _Key, class _Compare = less<_Key>,
14121452 class _Allocator = allocator<_Key>,
1413 class = _EnableIf<__is_allocator<_Allocator>::value, void>,
1414 class = _EnableIf<!__is_allocator<_Compare>::value, void>>
1453 class = enable_if_t<__is_allocator<_Allocator>::value, void>,
1454 class = enable_if_t<!__is_allocator<_Compare>::value, void>>
14151455multiset(initializer_list<_Key>, _Compare = _Compare(), _Allocator = _Allocator())
14161456 -> multiset<_Key, _Compare, _Allocator>;
14171457
14181458template<class _InputIterator, class _Allocator,
1419 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
1459 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, void>,
1460 class = enable_if_t<__is_allocator<_Allocator>::value, void>>
14201461multiset(_InputIterator, _InputIterator, _Allocator)
14211462 -> multiset<__iter_value_type<_InputIterator>,
14221463 less<__iter_value_type<_InputIterator>>, _Allocator>;
14231464
14241465template<class _Key, class _Allocator,
1425 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
1466 class = enable_if_t<__is_allocator<_Allocator>::value, void>>
14261467multiset(initializer_list<_Key>, _Allocator)
14271468 -> multiset<_Key, less<_Key>, _Allocator>;
14281469#endif
lib/libcxx/include/setjmp.h+1-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- setjmp.h ---------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/shared_mutex+1-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===------------------------ shared_mutex --------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/span+150-89
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===------------------------------ span ---------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -56,18 +56,18 @@ public:
5656
5757 // [span.cons], span constructors, copy, assignment, and destructor
5858 constexpr span() noexcept;
59 constexpr explicit(Extent != dynamic_extent) span(pointer ptr, size_type count);
60 constexpr explicit(Extent != dynamic_extent) span(pointer firstElem, pointer lastElem);
59 template <class It>
60 constexpr explicit(Extent != dynamic_extent) span(It first, size_type count);
61 template <class It, class End>
62 constexpr explicit(Extent != dynamic_extent) span(It first, End last);
6163 template <size_t N>
62 constexpr span(element_type (&arr)[N]) noexcept;
64 constexpr span(type_identity_t<element_type> (&arr)[N]) noexcept;
6365 template <size_t N>
6466 constexpr span(array<value_type, N>& arr) noexcept;
6567 template <size_t N>
6668 constexpr span(const array<value_type, N>& arr) noexcept;
67 template <class Container>
68 constexpr explicit(Extent != dynamic_extent) span(Container& cont);
69 template <class Container>
70 constexpr explicit(Extent != dynamic_extent) span(const Container& cont);
69 template<class R>
70 constexpr explicit(Extent != dynamic_extent) span(R&& r);
7171 constexpr span(const span& other) noexcept = default;
7272 template <class OtherElementType, size_t OtherExtent>
7373 constexpr explicit(Extent != dynamic_extent) span(const span<OtherElementType, OtherExtent>& s) noexcept;
......@@ -89,7 +89,7 @@ public:
8989 // [span.obs], span observers
9090 constexpr size_type size() const noexcept;
9191 constexpr size_type size_bytes() const noexcept;
92 constexpr bool empty() const noexcept;
92 [[nodiscard]] constexpr bool empty() const noexcept;
9393
9494 // [span.elem], span element access
9595 constexpr reference operator[](size_type idx) const;
......@@ -108,6 +108,9 @@ private:
108108 size_type size_; // exposition only
109109};
110110
111template<class It, class EndOrSize>
112 span(It, EndOrSize) -> span<remove_reference_t<iter_reference_t<_It>>>;
113
111114template<class T, size_t N>
112115 span(T (&)[N]) -> span<T, N>;
113116
......@@ -117,11 +120,8 @@ template<class T, size_t N>
117120template<class T, size_t N>
118121 span(const array<T, N>&) -> span<const T, N>;
119122
120template<class Container>
121 span(Container&) -> span<typename Container::value_type>;
122
123template<class Container>
124 span(const Container&) -> span<const typename Container::value_type>;
123template<class R>
124 span(R&&) -> span<remove_reference_t<ranges::range_reference_t<R>>>;
125125
126126} // namespace std
127127
......@@ -129,9 +129,13 @@ template<class Container>
129129
130130#include <__config>
131131#include <__debug>
132#include <__iterator/concepts.h>
132133#include <__iterator/wrap_iter.h>
134#include <__ranges/concepts.h>
135#include <__ranges/data.h>
133136#include <__ranges/enable_borrowed_range.h>
134137#include <__ranges/enable_view.h>
138#include <__ranges/size.h>
135139#include <array> // for array
136140#include <cstddef> // for byte
137141#include <iterator> // for iterators
......@@ -155,46 +159,46 @@ template <typename _Tp, size_t _Extent = dynamic_extent> class span;
155159
156160
157161template <class _Tp>
158struct __is_span_impl : public false_type {};
159
160template <class _Tp, size_t _Extent>
161struct __is_span_impl<span<_Tp, _Extent>> : public true_type {};
162
163template <class _Tp>
164struct __is_span : public __is_span_impl<remove_cv_t<_Tp>> {};
165
166template <class _Tp>
167struct __is_std_array_impl : public false_type {};
162struct __is_std_array : false_type {};
168163
169164template <class _Tp, size_t _Sz>
170struct __is_std_array_impl<array<_Tp, _Sz>> : public true_type {};
165struct __is_std_array<array<_Tp, _Sz>> : true_type {};
171166
172167template <class _Tp>
173struct __is_std_array : public __is_std_array_impl<remove_cv_t<_Tp>> {};
174
175template <class _Tp, class _ElementType, class = void>
176struct __is_span_compatible_container : public false_type {};
177
178template <class _Tp, class _ElementType>
179struct __is_span_compatible_container<_Tp, _ElementType,
180 void_t<
181 // is not a specialization of span
182 typename enable_if<!__is_span<_Tp>::value, nullptr_t>::type,
183 // is not a specialization of array
184 typename enable_if<!__is_std_array<_Tp>::value, nullptr_t>::type,
185 // is_array_v<Container> is false,
186 typename enable_if<!is_array_v<_Tp>, nullptr_t>::type,
187 // data(cont) and size(cont) are well formed
188 decltype(data(declval<_Tp>())),
189 decltype(size(declval<_Tp>())),
190 // remove_pointer_t<decltype(data(cont))>(*)[] is convertible to ElementType(*)[]
191 typename enable_if<
192 is_convertible_v<remove_pointer_t<decltype(data(declval<_Tp &>()))>(*)[],
193 _ElementType(*)[]>,
194 nullptr_t>::type
195 >>
196 : public true_type {};
168struct __is_std_span : false_type {};
197169
170template <class _Tp, size_t _Sz>
171struct __is_std_span<span<_Tp, _Sz>> : true_type {};
172
173#if defined(_LIBCPP_HAS_NO_CONCEPTS) || defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
174// This is a temporary workaround until we ship <ranges> -- we've unfortunately been
175// shipping <span> before its API was finalized, and we used to provide a constructor
176// from container types that had the requirements below. To avoid breaking code that
177// has started relying on the range-based constructor until we ship all of <ranges>,
178// we emulate the constructor requirements like this.
179template <class _Range, class _ElementType, class = void>
180struct __span_compatible_range : false_type { };
181
182template <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 { };
191#else
192template <class _Range, class _ElementType>
193concept __span_compatible_range =
194 ranges::contiguous_range<_Range> &&
195 ranges::sized_range<_Range> &&
196 (ranges::borrowed_range<_Range> || is_const_v<_ElementType>) &&
197 !__is_std_span<remove_cvref_t<_Range>>::value &&
198 !__is_std_array<remove_cvref_t<_Range>>::value &&
199 !is_array_v<remove_cvref_t<_Range>> &&
200 is_convertible_v<remove_reference_t<ranges::range_reference_t<_Range>>(*)[], _ElementType(*)[]>;
201#endif
198202
199203template <typename _Tp, size_t _Extent>
200204class _LIBCPP_TEMPLATE_VIS span {
......@@ -224,12 +228,33 @@ public:
224228 constexpr span (const span&) noexcept = default;
225229 constexpr span& operator=(const span&) noexcept = default;
226230
227 _LIBCPP_INLINE_VISIBILITY constexpr explicit span(pointer __ptr, size_type __count) : __data{__ptr}
228 { (void)__count; _LIBCPP_ASSERT(_Extent == __count, "size mismatch in span's constructor (ptr, len)"); }
229 _LIBCPP_INLINE_VISIBILITY constexpr explicit span(pointer __f, pointer __l) : __data{__f}
230 { (void)__l; _LIBCPP_ASSERT(_Extent == distance(__f, __l), "size mismatch in span's constructor (ptr, ptr)"); }
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>
236 _LIBCPP_INLINE_VISIBILITY
237 constexpr explicit span(_It __first, size_type __count)
238 : __data{_VSTD::to_address(__first)} {
239 (void)__count;
240 _LIBCPP_ASSERT(_Extent == __count, "size mismatch in span's constructor (iterator, len)");
241 }
242
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>
248 _LIBCPP_INLINE_VISIBILITY
249 constexpr explicit span(_It __first, _End __last) : __data{_VSTD::to_address(__first)} {
250 (void)__last;
251 _LIBCPP_ASSERT((__last - __first >= 0), "invalid range in span's constructor (iterator, sentinel)");
252 _LIBCPP_ASSERT(__last - __first == _Extent,
253 "invalid range in span's constructor (iterator, sentinel): last - first != extent");
254 }
255#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
231256
232 _LIBCPP_INLINE_VISIBILITY constexpr span(element_type (&__arr)[_Extent]) noexcept : __data{__arr} {}
257 _LIBCPP_INLINE_VISIBILITY constexpr span(type_identity_t<element_type> (&__arr)[_Extent]) noexcept : __data{__arr} {}
233258
234259 template <class _OtherElementType,
235260 enable_if_t<is_convertible_v<_OtherElementType(*)[], element_type (*)[]>, nullptr_t> = nullptr>
......@@ -241,21 +266,28 @@ public:
241266 _LIBCPP_INLINE_VISIBILITY
242267 constexpr span(const array<_OtherElementType, _Extent>& __arr) noexcept : __data{__arr.data()} {}
243268
244 template <class _Container>
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 >>
245273 _LIBCPP_INLINE_VISIBILITY
246 constexpr explicit span( _Container& __c,
247 enable_if_t<__is_span_compatible_container<_Container, _Tp>::value, nullptr_t> = nullptr)
248 : __data{_VSTD::data(__c)} {
249 _LIBCPP_ASSERT(_Extent == _VSTD::size(__c), "size mismatch in span's constructor (range)");
250 }
251
252 template <class _Container>
274 constexpr explicit span(_Container& __c) : __data{std::data(__c)} {
275 _LIBCPP_ASSERT(std::size(__c) == _Extent, "size mismatch in span's constructor (range)");
276 }
277 template <class _Container, class = enable_if_t<
278 __span_compatible_range<const _Container, element_type>::value
279 >>
280 _LIBCPP_INLINE_VISIBILITY
281 constexpr explicit span(const _Container& __c) : __data{std::data(__c)} {
282 _LIBCPP_ASSERT(std::size(__c) == _Extent, "size mismatch in span's constructor (range)");
283 }
284#else
285 template <__span_compatible_range<element_type> _Range>
253286 _LIBCPP_INLINE_VISIBILITY
254 constexpr explicit span(const _Container& __c,
255 enable_if_t<__is_span_compatible_container<const _Container, _Tp>::value, nullptr_t> = nullptr)
256 : __data{_VSTD::data(__c)} {
257 _LIBCPP_ASSERT(_Extent == _VSTD::size(__c), "size mismatch in span's constructor (range)");
258 }
287 constexpr explicit span(_Range&& __r) : __data{ranges::data(__r)} {
288 _LIBCPP_ASSERT(ranges::size(__r) == _Extent, "size mismatch in span's constructor (range)");
289 }
290#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
259291
260292 template <class _OtherElementType>
261293 _LIBCPP_INLINE_VISIBILITY
......@@ -331,9 +363,9 @@ public:
331363 return {data() + __offset, __count};
332364 }
333365
334 _LIBCPP_INLINE_VISIBILITY constexpr size_type size() const noexcept { return _Extent; }
335 _LIBCPP_INLINE_VISIBILITY constexpr size_type size_bytes() const noexcept { return _Extent * sizeof(element_type); }
336 _LIBCPP_INLINE_VISIBILITY constexpr bool empty() const noexcept { return _Extent == 0; }
366 _LIBCPP_INLINE_VISIBILITY constexpr size_type size() const noexcept { return _Extent; }
367 _LIBCPP_INLINE_VISIBILITY constexpr size_type size_bytes() const noexcept { return _Extent * sizeof(element_type); }
368 [[nodiscard]] _LIBCPP_INLINE_VISIBILITY constexpr bool empty() const noexcept { return _Extent == 0; }
337369
338370 _LIBCPP_INLINE_VISIBILITY constexpr reference operator[](size_type __idx) const noexcept
339371 {
......@@ -402,12 +434,28 @@ public:
402434 constexpr span (const span&) noexcept = default;
403435 constexpr span& operator=(const span&) noexcept = default;
404436
405 _LIBCPP_INLINE_VISIBILITY constexpr span(pointer __ptr, size_type __count) : __data{__ptr}, __size{__count} {}
406 _LIBCPP_INLINE_VISIBILITY constexpr span(pointer __f, pointer __l) : __data{__f}, __size{static_cast<size_t>(distance(__f, __l))} {}
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>
442 _LIBCPP_INLINE_VISIBILITY
443 constexpr span(_It __first, size_type __count)
444 : __data{_VSTD::to_address(__first)}, __size{__count} {}
445
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>
451 _LIBCPP_INLINE_VISIBILITY
452 constexpr span(_It __first, _End __last)
453 : __data(_VSTD::to_address(__first)), __size(__last - __first) {}
454#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
407455
408456 template <size_t _Sz>
409457 _LIBCPP_INLINE_VISIBILITY
410 constexpr span(element_type (&__arr)[_Sz]) noexcept : __data{__arr}, __size{_Sz} {}
458 constexpr span(type_identity_t<element_type> (&__arr)[_Sz]) noexcept : __data{__arr}, __size{_Sz} {}
411459
412460 template <class _OtherElementType, size_t _Sz,
413461 enable_if_t<is_convertible_v<_OtherElementType(*)[], element_type (*)[]>, nullptr_t> = nullptr>
......@@ -419,18 +467,22 @@ public:
419467 _LIBCPP_INLINE_VISIBILITY
420468 constexpr span(const array<_OtherElementType, _Sz>& __arr) noexcept : __data{__arr.data()}, __size{_Sz} {}
421469
422 template <class _Container>
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 >>
423474 _LIBCPP_INLINE_VISIBILITY
424 constexpr span( _Container& __c,
425 enable_if_t<__is_span_compatible_container<_Container, _Tp>::value, nullptr_t> = nullptr)
426 : __data{_VSTD::data(__c)}, __size{(size_type) _VSTD::size(__c)} {}
427
428 template <class _Container>
475 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 >>
429479 _LIBCPP_INLINE_VISIBILITY
430 constexpr span(const _Container& __c,
431 enable_if_t<__is_span_compatible_container<const _Container, _Tp>::value, nullptr_t> = nullptr)
432 : __data{_VSTD::data(__c)}, __size{(size_type) _VSTD::size(__c)} {}
433
480 constexpr span(const _Container& __c) : __data(std::data(__c)), __size{std::size(__c)} {}
481#else
482 template <__span_compatible_range<element_type> _Range>
483 _LIBCPP_INLINE_VISIBILITY
484 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)
434486
435487 template <class _OtherElementType, size_t _OtherExtent>
436488 _LIBCPP_INLINE_VISIBILITY
......@@ -493,9 +545,9 @@ public:
493545 return {data() + __offset, __count};
494546 }
495547
496 _LIBCPP_INLINE_VISIBILITY constexpr size_type size() const noexcept { return __size; }
497 _LIBCPP_INLINE_VISIBILITY constexpr size_type size_bytes() const noexcept { return __size * sizeof(element_type); }
498 _LIBCPP_INLINE_VISIBILITY constexpr bool empty() const noexcept { return __size == 0; }
548 _LIBCPP_INLINE_VISIBILITY constexpr size_type size() const noexcept { return __size; }
549 _LIBCPP_INLINE_VISIBILITY constexpr size_type size_bytes() const noexcept { return __size * sizeof(element_type); }
550 [[nodiscard]] _LIBCPP_INLINE_VISIBILITY constexpr bool empty() const noexcept { return __size == 0; }
499551
500552 _LIBCPP_INLINE_VISIBILITY constexpr reference operator[](size_type __idx) const noexcept
501553 {
......@@ -535,13 +587,13 @@ private:
535587 size_type __size;
536588};
537589
538#if !defined(_LIBCPP_HAS_NO_RANGES)
590#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
539591template <class _Tp, size_t _Extent>
540592inline constexpr bool ranges::enable_borrowed_range<span<_Tp, _Extent> > = true;
541593
542594template <class _ElementType, size_t _Extent>
543595inline constexpr bool ranges::enable_view<span<_ElementType, _Extent>> = true;
544#endif // !defined(_LIBCPP_HAS_NO_RANGES)
596#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
545597
546598// as_bytes & as_writable_bytes
547599template <class _Tp, size_t _Extent>
......@@ -556,7 +608,11 @@ auto as_writable_bytes(span<_Tp, _Extent> __s) noexcept
556608-> enable_if_t<!is_const_v<_Tp>, decltype(__s.__as_writable_bytes())>
557609{ return __s.__as_writable_bytes(); }
558610
559// Deduction guides
611#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
612template<contiguous_iterator _It, class _EndOrSize>
613 span(_It, _EndOrSize) -> span<remove_reference_t<iter_reference_t<_It>>>;
614#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
615
560616template<class _Tp, size_t _Sz>
561617 span(_Tp (&)[_Sz]) -> span<_Tp, _Sz>;
562618
......@@ -566,11 +622,16 @@ template<class _Tp, size_t _Sz>
566622template<class _Tp, size_t _Sz>
567623 span(const array<_Tp, _Sz>&) -> span<const _Tp, _Sz>;
568624
625#if defined(_LIBCPP_HAS_NO_CONCEPTS) || defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
569626template<class _Container>
570627 span(_Container&) -> span<typename _Container::value_type>;
571628
572629template<class _Container>
573630 span(const _Container&) -> span<const typename _Container::value_type>;
631#else
632template<ranges::contiguous_range _Range>
633 span(_Range&&) -> span<remove_reference_t<ranges::range_reference_t<_Range>>>;
634#endif
574635
575636#endif // _LIBCPP_STD_VER > 17
576637
lib/libcxx/include/sstream+2-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- sstream ----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -184,6 +184,7 @@ typedef basic_stringstream<wchar_t> wstringstream;
184184#include <istream>
185185#include <ostream>
186186#include <string>
187#include <version>
187188
188189#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
189190#pragma GCC system_header
lib/libcxx/include/stack+53-11
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===---------------------------- stack -----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -41,11 +41,14 @@ public:
4141
4242 explicit stack(const container_type& c);
4343 explicit stack(container_type&& c);
44 template <class InputIterator> stack(InputIterator first, InputIterator last); // since C++23
4445 template <class Alloc> explicit stack(const Alloc& a);
4546 template <class Alloc> stack(const container_type& c, const Alloc& a);
4647 template <class Alloc> stack(container_type&& c, const Alloc& a);
4748 template <class Alloc> stack(const stack& c, const Alloc& a);
4849 template <class Alloc> stack(stack&& c, const Alloc& a);
50 template<class InputIterator, class Alloc>
51 stack(InputIterator first, InputIterator last, const Alloc&); // since C++23
4952
5053 bool empty() const;
5154 size_type size() const;
......@@ -63,9 +66,17 @@ public:
6366template<class Container>
6467 stack(Container) -> stack<typename Container::value_type, Container>; // C++17
6568
69template<class InputIterator>
70 stack(InputIterator, InputIterator) -> stack<iter-value-type<InputIterator>>; // since C++23
71
6672template<class Container, class Allocator>
6773 stack(Container, Allocator) -> stack<typename Container::value_type, Container>; // C++17
6874
75template<class InputIterator, class Allocator>
76 stack(InputIterator, InputIterator, Allocator)
77 -> stack<iter-value-type<InputIterator>,
78 deque<iter-value-type<InputIterator>, Allocator>>; // since C++23
79
6980template <class T, class Container>
7081 bool operator==(const stack<T, Container>& x, const stack<T, Container>& y);
7182template <class T, class Container>
......@@ -88,9 +99,12 @@ template <class T, class Container>
8899*/
89100
90101#include <__config>
102#include <__iterator/iterator_traits.h>
91103#include <__memory/uses_allocator.h>
92104#include <__utility/forward.h>
93105#include <deque>
106#include <type_traits>
107#include <version>
94108
95109#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
96110#pragma GCC system_header
......@@ -158,31 +172,45 @@ public:
158172 template <class _Alloc>
159173 _LIBCPP_INLINE_VISIBILITY
160174 explicit stack(const _Alloc& __a,
161 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0)
175 __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
162176 : c(__a) {}
163177 template <class _Alloc>
164178 _LIBCPP_INLINE_VISIBILITY
165179 stack(const container_type& __c, const _Alloc& __a,
166 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0)
180 __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
167181 : c(__c, __a) {}
168182 template <class _Alloc>
169183 _LIBCPP_INLINE_VISIBILITY
170184 stack(const stack& __s, const _Alloc& __a,
171 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0)
185 __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
172186 : c(__s.c, __a) {}
173187#ifndef _LIBCPP_CXX03_LANG
174188 template <class _Alloc>
175189 _LIBCPP_INLINE_VISIBILITY
176190 stack(container_type&& __c, const _Alloc& __a,
177 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0)
191 __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
178192 : c(_VSTD::move(__c), __a) {}
179193 template <class _Alloc>
180194 _LIBCPP_INLINE_VISIBILITY
181195 stack(stack&& __s, const _Alloc& __a,
182 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0)
196 __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
183197 : c(_VSTD::move(__s.c), __a) {}
184198#endif // _LIBCPP_CXX03_LANG
185199
200#if _LIBCPP_STD_VER > 20
201 template <class _InputIterator,
202 class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>>
203 _LIBCPP_HIDE_FROM_ABI
204 stack(_InputIterator __first, _InputIterator __last) : c(__first, __last) {}
205
206 template <class _InputIterator,
207 class _Alloc,
208 class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
209 class = __enable_if_t<uses_allocator<container_type, _Alloc>::value>>
210 _LIBCPP_HIDE_FROM_ABI
211 stack(_InputIterator __first, _InputIterator __last, const _Alloc& __alloc) : c(__first, __last, __alloc) {}
212#endif
213
186214 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
187215 bool empty() const {return c.empty();}
188216 _LIBCPP_INLINE_VISIBILITY
......@@ -231,22 +259,36 @@ public:
231259 operator< (const stack<T1, _C1>& __x, const stack<T1, _C1>& __y);
232260};
233261
234#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
262#if _LIBCPP_STD_VER > 14
235263template<class _Container,
236 class = _EnableIf<!__is_allocator<_Container>::value>
264 class = enable_if_t<!__is_allocator<_Container>::value>
237265>
238266stack(_Container)
239267 -> stack<typename _Container::value_type, _Container>;
240268
241269template<class _Container,
242270 class _Alloc,
243 class = _EnableIf<!__is_allocator<_Container>::value>,
244 class = _EnableIf<uses_allocator<_Container, _Alloc>::value>
271 class = enable_if_t<!__is_allocator<_Container>::value>,
272 class = enable_if_t<uses_allocator<_Container, _Alloc>::value>
245273 >
246274stack(_Container, _Alloc)
247275 -> stack<typename _Container::value_type, _Container>;
248276#endif
249277
278#if _LIBCPP_STD_VER > 20
279template<class _InputIterator,
280 class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>>
281stack(_InputIterator, _InputIterator)
282 -> stack<__iter_value_type<_InputIterator>>;
283
284template<class _InputIterator,
285 class _Alloc,
286 class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
287 class = __enable_if_t<__is_allocator<_Alloc>::value>>
288stack(_InputIterator, _InputIterator, _Alloc)
289 -> stack<__iter_value_type<_InputIterator>, deque<__iter_value_type<_InputIterator>, _Alloc>>;
290#endif
291
250292template <class _Tp, class _Container>
251293inline _LIBCPP_INLINE_VISIBILITY
252294bool
......@@ -297,7 +339,7 @@ operator<=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y)
297339
298340template <class _Tp, class _Container>
299341inline _LIBCPP_INLINE_VISIBILITY
300_EnableIf<__is_swappable<_Container>::value, void>
342__enable_if_t<__is_swappable<_Container>::value, void>
301343swap(stack<_Tp, _Container>& __x, stack<_Tp, _Container>& __y)
302344 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
303345{
lib/libcxx/include/stdbool.h+1-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- stdbool.h --------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/stddef.h+1-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- stddef.h ---------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/stdexcept+3-3
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- stdexcept --------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -42,9 +42,9 @@ public:
4242*/
4343
4444#include <__config>
45#include <cstdlib>
4546#include <exception>
4647#include <iosfwd> // for string forward decl
47#include <cstdlib>
4848
4949#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
5050#pragma GCC system_header
......@@ -209,7 +209,7 @@ public:
209209#endif
210210};
211211
212} // std
212} // namespace std
213213
214214_LIBCPP_BEGIN_NAMESPACE_STD
215215
lib/libcxx/include/stdint.h+1-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===---------------------------- stdint.h --------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/stdio.h+1-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===---------------------------- stdio.h ---------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/stdlib.h+19-13
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- stdlib.h ---------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -96,10 +96,14 @@ void *aligned_alloc(size_t alignment, size_t size); // C11
9696extern "C++" {
9797// abs
9898
99#undef abs
100#undef labs
101#ifndef _LIBCPP_HAS_NO_LONG_LONG
102#undef llabs
99#ifdef abs
100# undef abs
101#endif
102#ifdef labs
103# undef labs
104#endif
105#ifdef llabs
106# undef llabs
103107#endif
104108
105109// MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined
......@@ -107,11 +111,9 @@ extern "C++" {
107111inline _LIBCPP_INLINE_VISIBILITY long abs(long __x) _NOEXCEPT {
108112 return __builtin_labs(__x);
109113}
110#ifndef _LIBCPP_HAS_NO_LONG_LONG
111114inline _LIBCPP_INLINE_VISIBILITY long long abs(long long __x) _NOEXCEPT {
112115 return __builtin_llabs(__x);
113116}
114#endif // _LIBCPP_HAS_NO_LONG_LONG
115117#endif // !defined(_LIBCPP_MSVCRT) && !defined(__sun__)
116118
117119#if !defined(__sun__)
......@@ -131,10 +133,14 @@ abs(long double __lcpp_x) _NOEXCEPT {
131133
132134// div
133135
134#undef div
135#undef ldiv
136#ifndef _LIBCPP_HAS_NO_LONG_LONG
137#undef lldiv
136#ifdef div
137# undef div
138#endif
139#ifdef ldiv
140# undef ldiv
141#endif
142#ifdef lldiv
143# undef lldiv
138144#endif
139145
140146// MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined
......@@ -142,12 +148,12 @@ abs(long double __lcpp_x) _NOEXCEPT {
142148inline _LIBCPP_INLINE_VISIBILITY ldiv_t div(long __x, long __y) _NOEXCEPT {
143149 return ::ldiv(__x, __y);
144150}
145#ifndef _LIBCPP_HAS_NO_LONG_LONG
151#if !(defined(__FreeBSD__) && !defined(__LONG_LONG_SUPPORTED))
146152inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x,
147153 long long __y) _NOEXCEPT {
148154 return ::lldiv(__x, __y);
149155}
150#endif // _LIBCPP_HAS_NO_LONG_LONG
156#endif
151157#endif // _LIBCPP_MSVCRT / __sun__
152158} // extern "C++"
153159#endif // __cplusplus
lib/libcxx/include/streambuf+3-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===------------------------- streambuf ----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -108,8 +108,10 @@ protected:
108108*/
109109
110110#include <__config>
111#include <cstdint>
111112#include <ios>
112113#include <iosfwd>
114#include <version>
113115
114116#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
115117#pragma GCC system_header
lib/libcxx/include/string+271-343
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- string -----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -158,6 +158,9 @@ public:
158158 void resize(size_type n, value_type c);
159159 void resize(size_type n);
160160
161 template<class Operation>
162 constexpr void resize_and_overwrite(size_type n, Operation op); // since C++23
163
161164 void reserve(size_type res_arg);
162165 void reserve(); // deprecated in C++20
163166 void shrink_to_fit();
......@@ -524,7 +527,6 @@ basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++1
524527#include <cstdio> // EOF
525528#include <cstdlib>
526529#include <cstring>
527#include <cwchar>
528530#include <initializer_list>
529531#include <iosfwd>
530532#include <iterator>
......@@ -535,6 +537,10 @@ basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++1
535537#include <utility>
536538#include <version>
537539
540#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
541# include <cwchar>
542#endif
543
538544#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
539545# include <cstdint>
540546#endif
......@@ -612,30 +618,6 @@ operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
612618
613619_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&))
614620
615template <bool>
616class _LIBCPP_TEMPLATE_VIS __basic_string_common
617{
618protected:
619 _LIBCPP_NORETURN void __throw_length_error() const;
620 _LIBCPP_NORETURN void __throw_out_of_range() const;
621};
622
623template <bool __b>
624void
625__basic_string_common<__b>::__throw_length_error() const
626{
627 _VSTD::__throw_length_error("basic_string");
628}
629
630template <bool __b>
631void
632__basic_string_common<__b>::__throw_out_of_range() const
633{
634 _VSTD::__throw_out_of_range("basic_string");
635}
636
637_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __basic_string_common<true>)
638
639621template <class _Iter>
640622struct __string_is_trivial_iterator : public false_type {};
641623
......@@ -675,7 +657,7 @@ typedef basic_string<char8_t> u8string;
675657#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
676658typedef basic_string<char16_t> u16string;
677659typedef basic_string<char32_t> u32string;
678#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
660#endif
679661
680662template<class _CharT, class _Traits, class _Allocator>
681663class
......@@ -688,7 +670,6 @@ class
688670 _LIBCPP_PREFERRED_NAME(u32string)
689671#endif
690672 basic_string
691 : private __basic_string_common<true>
692673{
693674public:
694675 typedef basic_string __self;
......@@ -832,17 +813,15 @@ public:
832813 basic_string(basic_string&& __str, const allocator_type& __a);
833814#endif // _LIBCPP_CXX03_LANG
834815
835 template <class = _EnableIf<__is_allocator<_Allocator>::value, nullptr_t> >
816 template <class = __enable_if_t<__is_allocator<_Allocator>::value, nullptr_t> >
836817 _LIBCPP_INLINE_VISIBILITY
837818 basic_string(const _CharT* __s) : __r_(__default_init_tag(), __default_init_tag()) {
838819 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
839820 __init(__s, traits_type::length(__s));
840# if _LIBCPP_DEBUG_LEVEL == 2
841 __get_db()->__insert_c(this);
842# endif
821 _VSTD::__debug_db_insert_c(this);
843822 }
844823
845 template <class = _EnableIf<__is_allocator<_Allocator>::value, nullptr_t> >
824 template <class = __enable_if_t<__is_allocator<_Allocator>::value, nullptr_t> >
846825 _LIBCPP_INLINE_VISIBILITY
847826 basic_string(const _CharT* __s, const _Allocator& __a);
848827
......@@ -857,7 +836,7 @@ public:
857836 _LIBCPP_INLINE_VISIBILITY
858837 basic_string(size_type __n, _CharT __c);
859838
860 template <class = _EnableIf<__is_allocator<_Allocator>::value, nullptr_t> >
839 template <class = __enable_if_t<__is_allocator<_Allocator>::value, nullptr_t> >
861840 _LIBCPP_INLINE_VISIBILITY
862841 basic_string(size_type __n, _CharT __c, const _Allocator& __a);
863842
......@@ -867,24 +846,24 @@ public:
867846 basic_string(const basic_string& __str, size_type __pos,
868847 const _Allocator& __a = _Allocator());
869848
870 template<class _Tp, class = _EnableIf<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value> >
849 template<class _Tp, class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value> >
871850 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
872851 basic_string(const _Tp& __t, size_type __pos, size_type __n,
873852 const allocator_type& __a = allocator_type());
874853
875 template<class _Tp, class = _EnableIf<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
854 template<class _Tp, class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
876855 !__is_same_uncvref<_Tp, basic_string>::value> >
877856 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
878857 explicit basic_string(const _Tp& __t);
879858
880 template<class _Tp, class = _EnableIf<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value> >
859 template<class _Tp, class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value> >
881860 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
882861 explicit basic_string(const _Tp& __t, const allocator_type& __a);
883862
884 template<class _InputIterator, class = _EnableIf<__is_cpp17_input_iterator<_InputIterator>::value> >
863 template<class _InputIterator, class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value> >
885864 _LIBCPP_INLINE_VISIBILITY
886865 basic_string(_InputIterator __first, _InputIterator __last);
887 template<class _InputIterator, class = _EnableIf<__is_cpp17_input_iterator<_InputIterator>::value> >
866 template<class _InputIterator, class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value> >
888867 _LIBCPP_INLINE_VISIBILITY
889868 basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
890869#ifndef _LIBCPP_CXX03_LANG
......@@ -901,7 +880,7 @@ public:
901880
902881 basic_string& operator=(const basic_string& __str);
903882
904 template <class _Tp, class = _EnableIf<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value> >
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> >
905884 basic_string& operator=(const _Tp& __t)
906885 {__self_view __sv = __t; return assign(__sv);}
907886
......@@ -983,6 +962,16 @@ public:
983962 _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
984963
985964 void reserve(size_type __requested_capacity);
965
966#if _LIBCPP_STD_VER > 20
967 template <class _Op>
968 _LIBCPP_HIDE_FROM_ABI constexpr
969 void resize_and_overwrite(size_type __n, _Op __op) {
970 __resize_default_init(__n);
971 __erase_to_end(_VSTD::move(__op)(data(), _LIBCPP_AUTO_CAST(__n)));
972 }
973#endif
974
986975 _LIBCPP_INLINE_VISIBILITY void __resize_default_init(size_type __n);
987976
988977 _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_INLINE_VISIBILITY
......@@ -1004,7 +993,7 @@ public:
1004993
1005994 template <class _Tp>
1006995 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1007 _EnableIf
996 __enable_if_t
1008997 <
1009998 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
1010999 && !__is_same_uncvref<_Tp, basic_string >::value,
......@@ -1022,7 +1011,7 @@ public:
10221011
10231012 template <class _Tp>
10241013 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1025 _EnableIf<
1014 __enable_if_t<
10261015 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
10271016 && !__is_same_uncvref<_Tp, basic_string>::value,
10281017 basic_string&
......@@ -1032,7 +1021,7 @@ public:
10321021
10331022 template <class _Tp>
10341023 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1035 _EnableIf
1024 __enable_if_t
10361025 <
10371026 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
10381027 && !__is_same_uncvref<_Tp, basic_string>::value,
......@@ -1048,7 +1037,7 @@ public:
10481037
10491038 template<class _InputIterator>
10501039 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1051 _EnableIf
1040 __enable_if_t
10521041 <
10531042 __is_exactly_cpp17_input_iterator<_InputIterator>::value,
10541043 basic_string&
......@@ -1061,7 +1050,7 @@ public:
10611050 }
10621051 template<class _ForwardIterator>
10631052 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1064 _EnableIf
1053 __enable_if_t
10651054 <
10661055 __is_cpp17_forward_iterator<_ForwardIterator>::value,
10671056 basic_string&
......@@ -1084,7 +1073,7 @@ public:
10841073
10851074 template <class _Tp>
10861075 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1087 _EnableIf
1076 __enable_if_t
10881077 <
10891078 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
10901079 basic_string&
......@@ -1101,7 +1090,7 @@ public:
11011090 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
11021091 template <class _Tp>
11031092 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1104 _EnableIf
1093 __enable_if_t
11051094 <
11061095 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
11071096 && !__is_same_uncvref<_Tp, basic_string>::value,
......@@ -1113,7 +1102,7 @@ public:
11131102 basic_string& assign(size_type __n, value_type __c);
11141103 template<class _InputIterator>
11151104 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1116 _EnableIf
1105 __enable_if_t
11171106 <
11181107 __is_exactly_cpp17_input_iterator<_InputIterator>::value,
11191108 basic_string&
......@@ -1121,7 +1110,7 @@ public:
11211110 assign(_InputIterator __first, _InputIterator __last);
11221111 template<class _ForwardIterator>
11231112 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1124 _EnableIf
1113 __enable_if_t
11251114 <
11261115 __is_cpp17_forward_iterator<_ForwardIterator>::value,
11271116 basic_string&
......@@ -1137,7 +1126,7 @@ public:
11371126
11381127 template <class _Tp>
11391128 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1140 _EnableIf
1129 __enable_if_t
11411130 <
11421131 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
11431132 basic_string&
......@@ -1147,7 +1136,7 @@ public:
11471136
11481137 template <class _Tp>
11491138 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1150 _EnableIf
1139 __enable_if_t
11511140 <
11521141 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value,
11531142 basic_string&
......@@ -1162,7 +1151,7 @@ public:
11621151 iterator insert(const_iterator __pos, size_type __n, value_type __c);
11631152 template<class _InputIterator>
11641153 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1165 _EnableIf
1154 __enable_if_t
11661155 <
11671156 __is_exactly_cpp17_input_iterator<_InputIterator>::value,
11681157 iterator
......@@ -1170,7 +1159,7 @@ public:
11701159 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
11711160 template<class _ForwardIterator>
11721161 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1173 _EnableIf
1162 __enable_if_t
11741163 <
11751164 __is_cpp17_forward_iterator<_ForwardIterator>::value,
11761165 iterator
......@@ -1193,7 +1182,7 @@ public:
11931182
11941183 template <class _Tp>
11951184 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1196 _EnableIf
1185 __enable_if_t
11971186 <
11981187 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
11991188 basic_string&
......@@ -1202,7 +1191,7 @@ public:
12021191 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos);
12031192 template <class _Tp>
12041193 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1205 _EnableIf
1194 __enable_if_t
12061195 <
12071196 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value,
12081197 basic_string&
......@@ -1216,7 +1205,7 @@ public:
12161205
12171206 template <class _Tp>
12181207 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1219 _EnableIf
1208 __enable_if_t
12201209 <
12211210 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
12221211 basic_string&
......@@ -1231,7 +1220,7 @@ public:
12311220 basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
12321221 template<class _InputIterator>
12331222 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1234 _EnableIf
1223 __enable_if_t
12351224 <
12361225 __is_cpp17_input_iterator<_InputIterator>::value,
12371226 basic_string&
......@@ -1273,7 +1262,7 @@ public:
12731262
12741263 template <class _Tp>
12751264 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1276 _EnableIf
1265 __enable_if_t
12771266 <
12781267 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
12791268 size_type
......@@ -1289,7 +1278,7 @@ public:
12891278
12901279 template <class _Tp>
12911280 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1292 _EnableIf
1281 __enable_if_t
12931282 <
12941283 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
12951284 size_type
......@@ -1305,7 +1294,7 @@ public:
13051294
13061295 template <class _Tp>
13071296 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1308 _EnableIf
1297 __enable_if_t
13091298 <
13101299 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
13111300 size_type
......@@ -1322,7 +1311,7 @@ public:
13221311
13231312 template <class _Tp>
13241313 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1325 _EnableIf
1314 __enable_if_t
13261315 <
13271316 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
13281317 size_type
......@@ -1339,7 +1328,7 @@ public:
13391328
13401329 template <class _Tp>
13411330 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1342 _EnableIf
1331 __enable_if_t
13431332 <
13441333 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
13451334 size_type
......@@ -1356,7 +1345,7 @@ public:
13561345
13571346 template <class _Tp>
13581347 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1359 _EnableIf
1348 __enable_if_t
13601349 <
13611350 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
13621351 size_type
......@@ -1373,7 +1362,7 @@ public:
13731362
13741363 template <class _Tp>
13751364 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1376 _EnableIf
1365 __enable_if_t
13771366 <
13781367 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
13791368 int
......@@ -1382,7 +1371,7 @@ public:
13821371
13831372 template <class _Tp>
13841373 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1385 _EnableIf
1374 __enable_if_t
13861375 <
13871376 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
13881377 int
......@@ -1395,7 +1384,7 @@ public:
13951384
13961385 template <class _Tp>
13971386 inline _LIBCPP_INLINE_VISIBILITY
1398 _EnableIf
1387 __enable_if_t
13991388 <
14001389 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value,
14011390 int
......@@ -1406,28 +1395,28 @@ public:
14061395 int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
14071396
14081397#if _LIBCPP_STD_VER > 17
1409 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1410 bool starts_with(__self_view __sv) const _NOEXCEPT
1398 constexpr _LIBCPP_INLINE_VISIBILITY
1399 bool starts_with(__self_view __sv) const noexcept
14111400 { return __self_view(data(), size()).starts_with(__sv); }
14121401
1413 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1414 bool starts_with(value_type __c) const _NOEXCEPT
1402 constexpr _LIBCPP_INLINE_VISIBILITY
1403 bool starts_with(value_type __c) const noexcept
14151404 { return !empty() && _Traits::eq(front(), __c); }
14161405
1417 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1418 bool starts_with(const value_type* __s) const _NOEXCEPT
1406 constexpr _LIBCPP_INLINE_VISIBILITY
1407 bool starts_with(const value_type* __s) const noexcept
14191408 { return starts_with(__self_view(__s)); }
14201409
1421 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1422 bool ends_with(__self_view __sv) const _NOEXCEPT
1410 constexpr _LIBCPP_INLINE_VISIBILITY
1411 bool ends_with(__self_view __sv) const noexcept
14231412 { return __self_view(data(), size()).ends_with( __sv); }
14241413
1425 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1426 bool ends_with(value_type __c) const _NOEXCEPT
1414 constexpr _LIBCPP_INLINE_VISIBILITY
1415 bool ends_with(value_type __c) const noexcept
14271416 { return !empty() && _Traits::eq(back(), __c); }
14281417
1429 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1430 bool ends_with(const value_type* __s) const _NOEXCEPT
1418 constexpr _LIBCPP_INLINE_VISIBILITY
1419 bool ends_with(const value_type* __s) const noexcept
14311420 { return ends_with(__self_view(__s)); }
14321421#endif
14331422
......@@ -1465,6 +1454,11 @@ public:
14651454#endif // _LIBCPP_DEBUG_LEVEL == 2
14661455
14671456private:
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);
1460 }
1461
14681462 _LIBCPP_INLINE_VISIBILITY
14691463 allocator_type& __alloc() _NOEXCEPT
14701464 {return __r_.second();}
......@@ -1591,7 +1585,7 @@ private:
15911585
15921586 template <class _InputIterator>
15931587 inline
1594 _EnableIf
1588 __enable_if_t
15951589 <
15961590 __is_exactly_cpp17_input_iterator<_InputIterator>::value
15971591 >
......@@ -1599,7 +1593,7 @@ private:
15991593
16001594 template <class _ForwardIterator>
16011595 inline
1602 _EnableIf
1596 __enable_if_t
16031597 <
16041598 __is_cpp17_forward_iterator<_ForwardIterator>::value
16051599 >
......@@ -1705,6 +1699,13 @@ private:
17051699 return *this;
17061700 }
17071701
1702 _LIBCPP_HIDE_FROM_ABI basic_string& __null_terminate_at(value_type* __p, size_type __newsz) {
1703 __set_size(__newsz);
1704 __invalidate_iterators_past(__newsz);
1705 traits_type::assign(__p[__newsz], value_type());
1706 return *this;
1707 }
1708
17081709 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
17091710 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
17101711
......@@ -1717,20 +1718,12 @@ private:
17171718
17181719 _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
17191720 void __throw_length_error() const {
1720#ifndef _LIBCPP_NO_EXCEPTIONS
1721 __basic_string_common<true>::__throw_length_error();
1722#else
1723 _VSTD::abort();
1724#endif
1721 _VSTD::__throw_length_error("basic_string");
17251722 }
17261723
17271724 _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
17281725 void __throw_out_of_range() const {
1729#ifndef _LIBCPP_NO_EXCEPTIONS
1730 __basic_string_common<true>::__throw_out_of_range();
1731#else
1732 _VSTD::abort();
1733#endif
1726 _VSTD::__throw_out_of_range("basic_string");
17341727 }
17351728
17361729 friend basic_string operator+<>(const basic_string&, const basic_string&);
......@@ -1743,20 +1736,24 @@ private:
17431736// These declarations must appear before any functions are implicitly used
17441737// so that they have the correct visibility specifier.
17451738#ifdef _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
1746_LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, char)
1747_LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, wchar_t)
1739 _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, char)
1740# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1741 _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, wchar_t)
1742# endif
17481743#else
1749_LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, char)
1750_LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, wchar_t)
1744 _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, char)
1745# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1746 _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, wchar_t)
1747# endif
17511748#endif
17521749
17531750
1754#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
1751#if _LIBCPP_STD_VER >= 17
17551752template<class _InputIterator,
17561753 class _CharT = __iter_value_type<_InputIterator>,
17571754 class _Allocator = allocator<_CharT>,
1758 class = _EnableIf<__is_cpp17_input_iterator<_InputIterator>::value>,
1759 class = _EnableIf<__is_allocator<_Allocator>::value>
1755 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
1756 class = enable_if_t<__is_allocator<_Allocator>::value>
17601757 >
17611758basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator())
17621759 -> basic_string<_CharT, char_traits<_CharT>, _Allocator>;
......@@ -1764,7 +1761,7 @@ basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator())
17641761template<class _CharT,
17651762 class _Traits,
17661763 class _Allocator = allocator<_CharT>,
1767 class = _EnableIf<__is_allocator<_Allocator>::value>
1764 class = enable_if_t<__is_allocator<_Allocator>::value>
17681765 >
17691766explicit basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _Allocator())
17701767 -> basic_string<_CharT, _Traits, _Allocator>;
......@@ -1772,7 +1769,7 @@ explicit basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _A
17721769template<class _CharT,
17731770 class _Traits,
17741771 class _Allocator = allocator<_CharT>,
1775 class = _EnableIf<__is_allocator<_Allocator>::value>,
1772 class = enable_if_t<__is_allocator<_Allocator>::value>,
17761773 class _Sz = typename allocator_traits<_Allocator>::size_type
17771774 >
17781775basic_string(basic_string_view<_CharT, _Traits>, _Sz, _Sz, const _Allocator& = _Allocator())
......@@ -1785,7 +1782,8 @@ void
17851782basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
17861783{
17871784#if _LIBCPP_DEBUG_LEVEL == 2
1788 __get_db()->__invalidate_all(this);
1785 if (!__libcpp_is_constant_evaluated())
1786 __get_db()->__invalidate_all(this);
17891787#endif
17901788}
17911789
......@@ -1795,22 +1793,24 @@ void
17951793basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type __pos)
17961794{
17971795#if _LIBCPP_DEBUG_LEVEL == 2
1798 __c_node* __c = __get_db()->__find_c_and_lock(this);
1799 if (__c)
1800 {
1801 const_pointer __new_last = __get_pointer() + __pos;
1802 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1796 if (!__libcpp_is_constant_evaluated()) {
1797 __c_node* __c = __get_db()->__find_c_and_lock(this);
1798 if (__c)
18031799 {
1804 --__p;
1805 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
1806 if (__i->base() > __new_last)
1800 const_pointer __new_last = __get_pointer() + __pos;
1801 for (__i_node** __p = __c->end_; __p != __c->beg_; )
18071802 {
1808 (*__p)->__c_ = nullptr;
1809 if (--__c->end_ != __p)
1810 _VSTD::memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1803 --__p;
1804 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
1805 if (__i->base() > __new_last)
1806 {
1807 (*__p)->__c_ = nullptr;
1808 if (--__c->end_ != __p)
1809 _VSTD::memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1810 }
18111811 }
1812 __get_db()->unlock();
18121813 }
1813 __get_db()->unlock();
18141814 }
18151815#else
18161816 (void)__pos;
......@@ -1823,9 +1823,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string()
18231823 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
18241824 : __r_(__default_init_tag(), __default_init_tag())
18251825{
1826#if _LIBCPP_DEBUG_LEVEL == 2
1827 __get_db()->__insert_c(this);
1828#endif
1826 _VSTD::__debug_db_insert_c(this);
18291827 __zero();
18301828}
18311829
......@@ -1839,9 +1837,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __
18391837#endif
18401838: __r_(__default_init_tag(), __a)
18411839{
1842#if _LIBCPP_DEBUG_LEVEL == 2
1843 __get_db()->__insert_c(this);
1844#endif
1840 _VSTD::__debug_db_insert_c(this);
18451841 __zero();
18461842}
18471843
......@@ -1851,9 +1847,9 @@ void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s,
18511847 size_type __reserve)
18521848{
18531849 if (__reserve > max_size())
1854 this->__throw_length_error();
1850 __throw_length_error();
18551851 pointer __p;
1856 if (__reserve < __min_cap)
1852 if (__fits_in_sso(__reserve))
18571853 {
18581854 __set_short_size(__sz);
18591855 __p = __get_short_pointer();
......@@ -1875,9 +1871,9 @@ void
18751871basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
18761872{
18771873 if (__sz > max_size())
1878 this->__throw_length_error();
1874 __throw_length_error();
18791875 pointer __p;
1880 if (__sz < __min_cap)
1876 if (__fits_in_sso(__sz))
18811877 {
18821878 __set_short_size(__sz);
18831879 __p = __get_short_pointer();
......@@ -1901,9 +1897,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, const
19011897{
19021898 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
19031899 __init(__s, traits_type::length(__s));
1904#if _LIBCPP_DEBUG_LEVEL == 2
1905 __get_db()->__insert_c(this);
1906#endif
1900 _VSTD::__debug_db_insert_c(this);
19071901}
19081902
19091903template <class _CharT, class _Traits, class _Allocator>
......@@ -1913,9 +1907,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_
19131907{
19141908 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
19151909 __init(__s, __n);
1916#if _LIBCPP_DEBUG_LEVEL == 2
1917 __get_db()->__insert_c(this);
1918#endif
1910 _VSTD::__debug_db_insert_c(this);
19191911}
19201912
19211913template <class _CharT, class _Traits, class _Allocator>
......@@ -1925,9 +1917,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_
19251917{
19261918 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
19271919 __init(__s, __n);
1928#if _LIBCPP_DEBUG_LEVEL == 2
1929 __get_db()->__insert_c(this);
1930#endif
1920 _VSTD::__debug_db_insert_c(this);
19311921}
19321922
19331923template <class _CharT, class _Traits, class _Allocator>
......@@ -1939,10 +1929,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __st
19391929 else
19401930 __init_copy_ctor_external(_VSTD::__to_address(__str.__get_long_pointer()),
19411931 __str.__get_long_size());
1942
1943#if _LIBCPP_DEBUG_LEVEL == 2
1944 __get_db()->__insert_c(this);
1945#endif
1932 _VSTD::__debug_db_insert_c(this);
19461933}
19471934
19481935template <class _CharT, class _Traits, class _Allocator>
......@@ -1955,21 +1942,19 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(
19551942 else
19561943 __init_copy_ctor_external(_VSTD::__to_address(__str.__get_long_pointer()),
19571944 __str.__get_long_size());
1958#if _LIBCPP_DEBUG_LEVEL == 2
1959 __get_db()->__insert_c(this);
1960#endif
1945 _VSTD::__debug_db_insert_c(this);
19611946}
19621947
19631948template <class _CharT, class _Traits, class _Allocator>
19641949void basic_string<_CharT, _Traits, _Allocator>::__init_copy_ctor_external(
19651950 const value_type* __s, size_type __sz) {
19661951 pointer __p;
1967 if (__sz < __min_cap) {
1952 if (__fits_in_sso(__sz)) {
19681953 __p = __get_short_pointer();
19691954 __set_short_size(__sz);
19701955 } else {
19711956 if (__sz > max_size())
1972 this->__throw_length_error();
1957 __throw_length_error();
19731958 size_t __cap = __recommend(__sz);
19741959 __p = __alloc_traits::allocate(__alloc(), __cap + 1);
19751960 __set_long_pointer(__p);
......@@ -1992,9 +1977,9 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
19921977 : __r_(_VSTD::move(__str.__r_))
19931978{
19941979 __str.__zero();
1980 _VSTD::__debug_db_insert_c(this);
19951981#if _LIBCPP_DEBUG_LEVEL == 2
1996 __get_db()->__insert_c(this);
1997 if (__is_long())
1982 if (!__libcpp_is_constant_evaluated() && __is_long())
19981983 __get_db()->swap(this, &__str);
19991984#endif
20001985}
......@@ -2011,9 +1996,9 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, co
20111996 __r_.first().__r = __str.__r_.first().__r;
20121997 __str.__zero();
20131998 }
1999 _VSTD::__debug_db_insert_c(this);
20142000#if _LIBCPP_DEBUG_LEVEL == 2
2015 __get_db()->__insert_c(this);
2016 if (__is_long())
2001 if (!__libcpp_is_constant_evaluated() && __is_long())
20172002 __get_db()->swap(this, &__str);
20182003#endif
20192004}
......@@ -2025,9 +2010,9 @@ void
20252010basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
20262011{
20272012 if (__n > max_size())
2028 this->__throw_length_error();
2013 __throw_length_error();
20292014 pointer __p;
2030 if (__n < __min_cap)
2015 if (__fits_in_sso(__n))
20312016 {
20322017 __set_short_size(__n);
20332018 __p = __get_short_pointer();
......@@ -2050,9 +2035,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __
20502035 : __r_(__default_init_tag(), __default_init_tag())
20512036{
20522037 __init(__n, __c);
2053#if _LIBCPP_DEBUG_LEVEL == 2
2054 __get_db()->__insert_c(this);
2055#endif
2038 _VSTD::__debug_db_insert_c(this);
20562039}
20572040
20582041template <class _CharT, class _Traits, class _Allocator>
......@@ -2061,9 +2044,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __
20612044 : __r_(__default_init_tag(), __a)
20622045{
20632046 __init(__n, __c);
2064#if _LIBCPP_DEBUG_LEVEL == 2
2065 __get_db()->__insert_c(this);
2066#endif
2047 _VSTD::__debug_db_insert_c(this);
20672048}
20682049
20692050template <class _CharT, class _Traits, class _Allocator>
......@@ -2074,11 +2055,9 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __st
20742055{
20752056 size_type __str_sz = __str.size();
20762057 if (__pos > __str_sz)
2077 this->__throw_out_of_range();
2058 __throw_out_of_range();
20782059 __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
2079#if _LIBCPP_DEBUG_LEVEL == 2
2080 __get_db()->__insert_c(this);
2081#endif
2060 _VSTD::__debug_db_insert_c(this);
20822061}
20832062
20842063template <class _CharT, class _Traits, class _Allocator>
......@@ -2089,11 +2068,9 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __st
20892068{
20902069 size_type __str_sz = __str.size();
20912070 if (__pos > __str_sz)
2092 this->__throw_out_of_range();
2071 __throw_out_of_range();
20932072 __init(__str.data() + __pos, __str_sz - __pos);
2094#if _LIBCPP_DEBUG_LEVEL == 2
2095 __get_db()->__insert_c(this);
2096#endif
2073 _VSTD::__debug_db_insert_c(this);
20972074}
20982075
20992076template <class _CharT, class _Traits, class _Allocator>
......@@ -2105,9 +2082,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(
21052082 __self_view __sv0 = __t;
21062083 __self_view __sv = __sv0.substr(__pos, __n);
21072084 __init(__sv.data(), __sv.size());
2108#if _LIBCPP_DEBUG_LEVEL == 2
2109 __get_db()->__insert_c(this);
2110#endif
2085 _VSTD::__debug_db_insert_c(this);
21112086}
21122087
21132088template <class _CharT, class _Traits, class _Allocator>
......@@ -2117,9 +2092,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t)
21172092{
21182093 __self_view __sv = __t;
21192094 __init(__sv.data(), __sv.size());
2120#if _LIBCPP_DEBUG_LEVEL == 2
2121 __get_db()->__insert_c(this);
2122#endif
2095 _VSTD::__debug_db_insert_c(this);
21232096}
21242097
21252098template <class _CharT, class _Traits, class _Allocator>
......@@ -2129,14 +2102,12 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t, const _
21292102{
21302103 __self_view __sv = __t;
21312104 __init(__sv.data(), __sv.size());
2132#if _LIBCPP_DEBUG_LEVEL == 2
2133 __get_db()->__insert_c(this);
2134#endif
2105 _VSTD::__debug_db_insert_c(this);
21352106}
21362107
21372108template <class _CharT, class _Traits, class _Allocator>
21382109template <class _InputIterator>
2139_EnableIf
2110__enable_if_t
21402111<
21412112 __is_exactly_cpp17_input_iterator<_InputIterator>::value
21422113>
......@@ -2162,7 +2133,7 @@ basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _Input
21622133
21632134template <class _CharT, class _Traits, class _Allocator>
21642135template <class _ForwardIterator>
2165_EnableIf
2136__enable_if_t
21662137<
21672138 __is_cpp17_forward_iterator<_ForwardIterator>::value
21682139>
......@@ -2170,9 +2141,9 @@ basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _For
21702141{
21712142 size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
21722143 if (__sz > max_size())
2173 this->__throw_length_error();
2144 __throw_length_error();
21742145 pointer __p;
2175 if (__sz < __min_cap)
2146 if (__fits_in_sso(__sz))
21762147 {
21772148 __set_short_size(__sz);
21782149 __p = __get_short_pointer();
......@@ -2211,9 +2182,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first,
22112182 : __r_(__default_init_tag(), __default_init_tag())
22122183{
22132184 __init(__first, __last);
2214#if _LIBCPP_DEBUG_LEVEL == 2
2215 __get_db()->__insert_c(this);
2216#endif
2185 _VSTD::__debug_db_insert_c(this);
22172186}
22182187
22192188template <class _CharT, class _Traits, class _Allocator>
......@@ -2224,9 +2193,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first,
22242193 : __r_(__default_init_tag(), __a)
22252194{
22262195 __init(__first, __last);
2227#if _LIBCPP_DEBUG_LEVEL == 2
2228 __get_db()->__insert_c(this);
2229#endif
2196 _VSTD::__debug_db_insert_c(this);
22302197}
22312198
22322199#ifndef _LIBCPP_CXX03_LANG
......@@ -2238,9 +2205,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(
22382205 : __r_(__default_init_tag(), __default_init_tag())
22392206{
22402207 __init(__il.begin(), __il.end());
2241#if _LIBCPP_DEBUG_LEVEL == 2
2242 __get_db()->__insert_c(this);
2243#endif
2208 _VSTD::__debug_db_insert_c(this);
22442209}
22452210
22462211template <class _CharT, class _Traits, class _Allocator>
......@@ -2251,9 +2216,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(
22512216 : __r_(__default_init_tag(), __a)
22522217{
22532218 __init(__il.begin(), __il.end());
2254#if _LIBCPP_DEBUG_LEVEL == 2
2255 __get_db()->__insert_c(this);
2256#endif
2219 _VSTD::__debug_db_insert_c(this);
22572220}
22582221
22592222#endif // _LIBCPP_CXX03_LANG
......@@ -2262,7 +2225,8 @@ template <class _CharT, class _Traits, class _Allocator>
22622225basic_string<_CharT, _Traits, _Allocator>::~basic_string()
22632226{
22642227#if _LIBCPP_DEBUG_LEVEL == 2
2265 __get_db()->__erase_c(this);
2228 if (!__libcpp_is_constant_evaluated())
2229 __get_db()->__erase_c(this);
22662230#endif
22672231 if (__is_long())
22682232 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
......@@ -2276,7 +2240,7 @@ basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
22762240{
22772241 size_type __ms = max_size();
22782242 if (__delta_cap > __ms - __old_cap - 1)
2279 this->__throw_length_error();
2243 __throw_length_error();
22802244 pointer __old_p = __get_pointer();
22812245 size_type __cap = __old_cap < __ms / 2 - __alignment ?
22822246 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
......@@ -2308,7 +2272,7 @@ basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_t
23082272{
23092273 size_type __ms = max_size();
23102274 if (__delta_cap > __ms - __old_cap)
2311 this->__throw_length_error();
2275 __throw_length_error();
23122276 pointer __old_p = __get_pointer();
23132277 size_type __cap = __old_cap < __ms / 2 - __alignment ?
23142278 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
......@@ -2358,14 +2322,12 @@ basic_string<_CharT, _Traits, _Allocator>::__assign_external(
23582322 if (__cap >= __n) {
23592323 value_type* __p = _VSTD::__to_address(__get_pointer());
23602324 traits_type::move(__p, __s, __n);
2361 traits_type::assign(__p[__n], value_type());
2362 __set_size(__n);
2363 __invalidate_iterators_past(__n);
2325 return __null_terminate_at(__p, __n);
23642326 } else {
23652327 size_type __sz = size();
23662328 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
2329 return *this;
23672330 }
2368 return *this;
23692331}
23702332
23712333template <class _CharT, class _Traits, class _Allocator>
......@@ -2373,7 +2335,7 @@ basic_string<_CharT, _Traits, _Allocator>&
23732335basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
23742336{
23752337 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
2376 return (_LIBCPP_BUILTIN_CONSTANT_P(__n) && __n < __min_cap)
2338 return (__builtin_constant_p(__n) && __fits_in_sso(__n))
23772339 ? __assign_short(__s, __n)
23782340 : __assign_external(__s, __n);
23792341}
......@@ -2390,10 +2352,7 @@ basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
23902352 }
23912353 value_type* __p = _VSTD::__to_address(__get_pointer());
23922354 traits_type::assign(__p, __n, __c);
2393 traits_type::assign(__p[__n], value_type());
2394 __set_size(__n);
2395 __invalidate_iterators_past(__n);
2396 return *this;
2355 return __null_terminate_at(__p, __n);
23972356}
23982357
23992358template <class _CharT, class _Traits, class _Allocator>
......@@ -2491,7 +2450,7 @@ basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
24912450
24922451template <class _CharT, class _Traits, class _Allocator>
24932452template<class _InputIterator>
2494_EnableIf
2453__enable_if_t
24952454<
24962455 __is_exactly_cpp17_input_iterator<_InputIterator>::value,
24972456 basic_string<_CharT, _Traits, _Allocator>&
......@@ -2505,7 +2464,7 @@ basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _Input
25052464
25062465template <class _CharT, class _Traits, class _Allocator>
25072466template<class _ForwardIterator>
2508_EnableIf
2467__enable_if_t
25092468<
25102469 __is_cpp17_forward_iterator<_ForwardIterator>::value,
25112470 basic_string<_CharT, _Traits, _Allocator>&
......@@ -2525,7 +2484,7 @@ basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _For
25252484 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
25262485 }
25272486 pointer __p = __get_pointer();
2528 for (; __first != __last; ++__first, ++__p)
2487 for (; __first != __last; ++__p, (void) ++__first)
25292488 traits_type::assign(*__p, *__first);
25302489 traits_type::assign(*__p, value_type());
25312490 __set_size(__n);
......@@ -2545,13 +2504,13 @@ basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, siz
25452504{
25462505 size_type __sz = __str.size();
25472506 if (__pos > __sz)
2548 this->__throw_out_of_range();
2507 __throw_out_of_range();
25492508 return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
25502509}
25512510
25522511template <class _CharT, class _Traits, class _Allocator>
25532512template <class _Tp>
2554_EnableIf
2513__enable_if_t
25552514<
25562515 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
25572516 && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
......@@ -2562,7 +2521,7 @@ basic_string<_CharT, _Traits, _Allocator>::assign(const _Tp & __t, size_type __p
25622521 __self_view __sv = __t;
25632522 size_type __sz = __sv.size();
25642523 if (__pos > __sz)
2565 this->__throw_out_of_range();
2524 __throw_out_of_range();
25662525 return assign(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
25672526}
25682527
......@@ -2578,8 +2537,8 @@ basic_string<_CharT, _Traits, _Allocator>&
25782537basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
25792538{
25802539 _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
2581 return _LIBCPP_BUILTIN_CONSTANT_P(*__s)
2582 ? (traits_type::length(__s) < __min_cap
2540 return __builtin_constant_p(*__s)
2541 ? (__fits_in_sso(traits_type::length(__s))
25832542 ? __assign_short(__s, traits_type::length(__s))
25842543 : __assign_external(__s, traits_type::length(__s)))
25852544 : __assign_external(__s);
......@@ -2665,7 +2624,7 @@ basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
26652624 if (__sz == __cap)
26662625 {
26672626 __grow_by(__cap, 1, __sz, __sz, 0);
2668 __is_short = !__is_long();
2627 __is_short = false; // the string is always long after __grow_by
26692628 }
26702629 pointer __p;
26712630 if (__is_short)
......@@ -2684,7 +2643,7 @@ basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
26842643
26852644template <class _CharT, class _Traits, class _Allocator>
26862645template<class _ForwardIterator>
2687_EnableIf
2646__enable_if_t
26882647<
26892648 __is_cpp17_forward_iterator<_ForwardIterator>::value,
26902649 basic_string<_CharT, _Traits, _Allocator>&
......@@ -2703,7 +2662,7 @@ basic_string<_CharT, _Traits, _Allocator>::append(
27032662 if (__cap - __sz < __n)
27042663 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
27052664 pointer __p = __get_pointer() + __sz;
2706 for (; __first != __last; ++__p, ++__first)
2665 for (; __first != __last; ++__p, (void) ++__first)
27072666 traits_type::assign(*__p, *__first);
27082667 traits_type::assign(*__p, value_type());
27092668 __set_size(__sz + __n);
......@@ -2731,13 +2690,13 @@ basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, siz
27312690{
27322691 size_type __sz = __str.size();
27332692 if (__pos > __sz)
2734 this->__throw_out_of_range();
2693 __throw_out_of_range();
27352694 return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
27362695}
27372696
27382697template <class _CharT, class _Traits, class _Allocator>
27392698template <class _Tp>
2740 _EnableIf
2699 __enable_if_t
27412700 <
27422701 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
27432702 basic_string<_CharT, _Traits, _Allocator>&
......@@ -2747,7 +2706,7 @@ basic_string<_CharT, _Traits, _Allocator>::append(const _Tp & __t, size_type __p
27472706 __self_view __sv = __t;
27482707 size_type __sz = __sv.size();
27492708 if (__pos > __sz)
2750 this->__throw_out_of_range();
2709 __throw_out_of_range();
27512710 return append(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
27522711}
27532712
......@@ -2768,7 +2727,7 @@ basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_t
27682727 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr");
27692728 size_type __sz = size();
27702729 if (__pos > __sz)
2771 this->__throw_out_of_range();
2730 __throw_out_of_range();
27722731 size_type __cap = capacity();
27732732 if (__cap - __sz >= __n)
27742733 {
......@@ -2799,7 +2758,7 @@ basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n
27992758{
28002759 size_type __sz = size();
28012760 if (__pos > __sz)
2802 this->__throw_out_of_range();
2761 __throw_out_of_range();
28032762 if (__n)
28042763 {
28052764 size_type __cap = capacity();
......@@ -2826,36 +2785,33 @@ basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n
28262785
28272786template <class _CharT, class _Traits, class _Allocator>
28282787template<class _InputIterator>
2829_EnableIf
2788__enable_if_t
28302789<
28312790 __is_exactly_cpp17_input_iterator<_InputIterator>::value,
28322791 typename basic_string<_CharT, _Traits, _Allocator>::iterator
28332792>
28342793basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
28352794{
2836#if _LIBCPP_DEBUG_LEVEL == 2
2837 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2838 "string::insert(iterator, range) called with an iterator not"
2839 " referring to this string");
2840#endif
2841 const basic_string __temp(__first, __last, __alloc());
2842 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
2795 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2796 "string::insert(iterator, range) called with an iterator not"
2797 " referring to this string");
2798 const basic_string __temp(__first, __last, __alloc());
2799 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
28432800}
28442801
28452802template <class _CharT, class _Traits, class _Allocator>
28462803template<class _ForwardIterator>
2847_EnableIf
2804__enable_if_t
28482805<
28492806 __is_cpp17_forward_iterator<_ForwardIterator>::value,
28502807 typename basic_string<_CharT, _Traits, _Allocator>::iterator
28512808>
28522809basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
28532810{
2854#if _LIBCPP_DEBUG_LEVEL == 2
2855 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2856 "string::insert(iterator, range) called with an iterator not"
2857 " referring to this string");
2858#endif
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");
2814
28592815 size_type __ip = static_cast<size_type>(__pos - begin());
28602816 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
28612817 if (__n)
......@@ -2881,7 +2837,7 @@ basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _Forward
28812837 __sz += __n;
28822838 __set_size(__sz);
28832839 traits_type::assign(__p[__sz], value_type());
2884 for (__p += __ip; __first != __last; ++__p, ++__first)
2840 for (__p += __ip; __first != __last; ++__p, (void) ++__first)
28852841 traits_type::assign(*__p, *__first);
28862842 }
28872843 else
......@@ -2908,13 +2864,13 @@ basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_
29082864{
29092865 size_type __str_sz = __str.size();
29102866 if (__pos2 > __str_sz)
2911 this->__throw_out_of_range();
2867 __throw_out_of_range();
29122868 return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
29132869}
29142870
29152871template <class _CharT, class _Traits, class _Allocator>
29162872template <class _Tp>
2917_EnableIf
2873__enable_if_t
29182874<
29192875 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
29202876 basic_string<_CharT, _Traits, _Allocator>&
......@@ -2925,7 +2881,7 @@ basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& _
29252881 __self_view __sv = __t;
29262882 size_type __str_sz = __sv.size();
29272883 if (__pos2 > __str_sz)
2928 this->__throw_out_of_range();
2884 __throw_out_of_range();
29292885 return insert(__pos1, __sv.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
29302886}
29312887
......@@ -2941,6 +2897,10 @@ template <class _CharT, class _Traits, class _Allocator>
29412897typename basic_string<_CharT, _Traits, _Allocator>::iterator
29422898basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
29432899{
2900 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2901 "string::insert(iterator, character) called with an iterator not"
2902 " referring to this string");
2903
29442904 size_type __ip = static_cast<size_type>(__pos - begin());
29452905 size_type __sz = size();
29462906 size_type __cap = capacity();
......@@ -2968,14 +2928,12 @@ inline
29682928typename basic_string<_CharT, _Traits, _Allocator>::iterator
29692929basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
29702930{
2971#if _LIBCPP_DEBUG_LEVEL == 2
2972 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2973 "string::insert(iterator, n, value) called with an iterator not"
2974 " referring to this string");
2975#endif
2976 difference_type __p = __pos - begin();
2977 insert(static_cast<size_type>(__p), __n, __c);
2978 return begin() + __p;
2931 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2932 "string::insert(iterator, n, value) called with an iterator not"
2933 " referring to this string");
2934 difference_type __p = __pos - begin();
2935 insert(static_cast<size_type>(__p), __n, __c);
2936 return begin() + __p;
29792937}
29802938
29812939// replace
......@@ -2988,7 +2946,7 @@ basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __
29882946 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
29892947 size_type __sz = size();
29902948 if (__pos > __sz)
2991 this->__throw_out_of_range();
2949 __throw_out_of_range();
29922950 __n1 = _VSTD::min(__n1, __sz - __pos);
29932951 size_type __cap = capacity();
29942952 if (__cap - __sz + __n1 >= __n2)
......@@ -3003,7 +2961,7 @@ basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __
30032961 {
30042962 traits_type::move(__p + __pos, __s, __n2);
30052963 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
3006 goto __finish;
2964 return __null_terminate_at(__p, __sz + (__n2 - __n1));
30072965 }
30082966 if (__p + __pos < __s && __s < __p + __sz)
30092967 {
......@@ -3022,13 +2980,7 @@ basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __
30222980 }
30232981 }
30242982 traits_type::move(__p + __pos, __s, __n2);
3025__finish:
3026// __sz += __n2 - __n1; in this and the below function below can cause unsigned
3027// integer overflow, but this is a safe operation, so we disable the check.
3028 __sz += __n2 - __n1;
3029 __set_size(__sz);
3030 __invalidate_iterators_past(__sz);
3031 traits_type::assign(__p[__sz], value_type());
2983 return __null_terminate_at(__p, __sz + (__n2 - __n1));
30322984 }
30332985 else
30342986 __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
......@@ -3038,11 +2990,10 @@ __finish:
30382990template <class _CharT, class _Traits, class _Allocator>
30392991basic_string<_CharT, _Traits, _Allocator>&
30402992basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
3041 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
30422993{
30432994 size_type __sz = size();
30442995 if (__pos > __sz)
3045 this->__throw_out_of_range();
2996 __throw_out_of_range();
30462997 __n1 = _VSTD::min(__n1, __sz - __pos);
30472998 size_type __cap = capacity();
30482999 value_type* __p;
......@@ -3062,16 +3013,12 @@ basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __
30623013 __p = _VSTD::__to_address(__get_long_pointer());
30633014 }
30643015 traits_type::assign(__p + __pos, __n2, __c);
3065 __sz += __n2 - __n1;
3066 __set_size(__sz);
3067 __invalidate_iterators_past(__sz);
3068 traits_type::assign(__p[__sz], value_type());
3069 return *this;
3016 return __null_terminate_at(__p, __sz - (__n1 - __n2));
30703017}
30713018
30723019template <class _CharT, class _Traits, class _Allocator>
30733020template<class _InputIterator>
3074_EnableIf
3021__enable_if_t
30753022<
30763023 __is_cpp17_input_iterator<_InputIterator>::value,
30773024 basic_string<_CharT, _Traits, _Allocator>&
......@@ -3080,7 +3027,7 @@ basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_it
30803027 _InputIterator __j1, _InputIterator __j2)
30813028{
30823029 const basic_string __temp(__j1, __j2, __alloc());
3083 return this->replace(__i1, __i2, __temp);
3030 return replace(__i1, __i2, __temp);
30843031}
30853032
30863033template <class _CharT, class _Traits, class _Allocator>
......@@ -3098,13 +3045,13 @@ basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type _
30983045{
30993046 size_type __str_sz = __str.size();
31003047 if (__pos2 > __str_sz)
3101 this->__throw_out_of_range();
3048 __throw_out_of_range();
31023049 return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
31033050}
31043051
31053052template <class _CharT, class _Traits, class _Allocator>
31063053template <class _Tp>
3107_EnableIf
3054__enable_if_t
31083055<
31093056 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
31103057 basic_string<_CharT, _Traits, _Allocator>&
......@@ -3115,7 +3062,7 @@ basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type _
31153062 __self_view __sv = __t;
31163063 size_type __str_sz = __sv.size();
31173064 if (__pos2 > __str_sz)
3118 this->__throw_out_of_range();
3065 __throw_out_of_range();
31193066 return replace(__pos1, __n1, __sv.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
31203067}
31213068
......@@ -3177,10 +3124,7 @@ basic_string<_CharT, _Traits, _Allocator>::__erase_external_with_move(
31773124 size_type __n_move = __sz - __pos - __n;
31783125 if (__n_move != 0)
31793126 traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
3180 __sz -= __n;
3181 __set_size(__sz);
3182 __invalidate_iterators_past(__sz);
3183 traits_type::assign(__p[__sz], value_type());
3127 __null_terminate_at(__p, __sz - __n);
31843128 }
31853129}
31863130
......@@ -3188,7 +3132,8 @@ template <class _CharT, class _Traits, class _Allocator>
31883132basic_string<_CharT, _Traits, _Allocator>&
31893133basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos,
31903134 size_type __n) {
3191 if (__pos > size()) this->__throw_out_of_range();
3135 if (__pos > size())
3136 __throw_out_of_range();
31923137 if (__n == npos) {
31933138 __erase_to_end(__pos);
31943139 } else {
......@@ -3202,17 +3147,15 @@ inline
32023147typename basic_string<_CharT, _Traits, _Allocator>::iterator
32033148basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
32043149{
3205#if _LIBCPP_DEBUG_LEVEL == 2
3206 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
3207 "string::erase(iterator) called with an iterator not"
3208 " referring to this string");
3209#endif
3210 _LIBCPP_ASSERT(__pos != end(),
3211 "string::erase(iterator) called with a non-dereferenceable iterator");
3212 iterator __b = begin();
3213 size_type __r = static_cast<size_type>(__pos - __b);
3214 erase(__r, 1);
3215 return __b + static_cast<difference_type>(__r);
3150 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
3151 "string::erase(iterator) called with an iterator not"
3152 " referring to this string");
3153
3154 _LIBCPP_ASSERT(__pos != end(), "string::erase(iterator) called with a non-dereferenceable iterator");
3155 iterator __b = begin();
3156 size_type __r = static_cast<size_type>(__pos - __b);
3157 erase(__r, 1);
3158 return __b + static_cast<difference_type>(__r);
32163159}
32173160
32183161template <class _CharT, class _Traits, class _Allocator>
......@@ -3220,16 +3163,15 @@ inline
32203163typename basic_string<_CharT, _Traits, _Allocator>::iterator
32213164basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
32223165{
3223#if _LIBCPP_DEBUG_LEVEL == 2
3224 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
3225 "string::erase(iterator, iterator) called with an iterator not"
3226 " referring to this string");
3227#endif
3228 _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
3229 iterator __b = begin();
3230 size_type __r = static_cast<size_type>(__first - __b);
3231 erase(__r, static_cast<size_type>(__last - __first));
3232 return __b + static_cast<difference_type>(__r);
3166 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
3167 "string::erase(iterator, iterator) called with an iterator not"
3168 " referring to this string");
3169
3170 _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
3171 iterator __b = begin();
3172 size_type __r = static_cast<size_type>(__first - __b);
3173 erase(__r, static_cast<size_type>(__last - __first));
3174 return __b + static_cast<difference_type>(__r);
32333175}
32343176
32353177template <class _CharT, class _Traits, class _Allocator>
......@@ -3238,20 +3180,7 @@ void
32383180basic_string<_CharT, _Traits, _Allocator>::pop_back()
32393181{
32403182 _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
3241 size_type __sz;
3242 if (__is_long())
3243 {
3244 __sz = __get_long_size() - 1;
3245 __set_long_size(__sz);
3246 traits_type::assign(*(__get_long_pointer() + __sz), value_type());
3247 }
3248 else
3249 {
3250 __sz = __get_short_size() - 1;
3251 __set_short_size(__sz);
3252 traits_type::assign(*(__get_short_pointer() + __sz), value_type());
3253 }
3254 __invalidate_iterators_past(__sz);
3183 __erase_to_end(size() - 1);
32553184}
32563185
32573186template <class _CharT, class _Traits, class _Allocator>
......@@ -3277,17 +3206,7 @@ inline
32773206void
32783207basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
32793208{
3280 if (__is_long())
3281 {
3282 traits_type::assign(*(__get_long_pointer() + __pos), value_type());
3283 __set_long_size(__pos);
3284 }
3285 else
3286 {
3287 traits_type::assign(*(__get_short_pointer() + __pos), value_type());
3288 __set_short_size(__pos);
3289 }
3290 __invalidate_iterators_past(__pos);
3209 __null_terminate_at(_VSTD::__to_address(__get_pointer()), __pos);
32913210}
32923211
32933212template <class _CharT, class _Traits, class _Allocator>
......@@ -3330,12 +3249,13 @@ void
33303249basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __requested_capacity)
33313250{
33323251 if (__requested_capacity > max_size())
3333 this->__throw_length_error();
3252 __throw_length_error();
33343253
3335#if _LIBCPP_STD_VER > 17
3336 // Reserve never shrinks as of C++20.
3337 if (__requested_capacity <= capacity()) return;
3338#endif
3254 // Make sure reserve(n) never shrinks. This is technically only required in C++20
3255 // and later (since P0966R1), however we provide consistent behavior in all Standard
3256 // modes because this function is instantiated in the shared library.
3257 if (__requested_capacity <= capacity())
3258 return;
33393259
33403260 size_type __target_capacity = _VSTD::max(__requested_capacity, size());
33413261 __target_capacity = __recommend(__target_capacity);
......@@ -3345,6 +3265,7 @@ basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __requested_capacit
33453265}
33463266
33473267template <class _CharT, class _Traits, class _Allocator>
3268inline
33483269void
33493270basic_string<_CharT, _Traits, _Allocator>::shrink_to_fit() _NOEXCEPT
33503271{
......@@ -3355,6 +3276,7 @@ basic_string<_CharT, _Traits, _Allocator>::shrink_to_fit() _NOEXCEPT
33553276}
33563277
33573278template <class _CharT, class _Traits, class _Allocator>
3279inline
33583280void
33593281basic_string<_CharT, _Traits, _Allocator>::__shrink_or_extend(size_type __target_capacity)
33603282{
......@@ -3434,7 +3356,7 @@ typename basic_string<_CharT, _Traits, _Allocator>::const_reference
34343356basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
34353357{
34363358 if (__n >= size())
3437 this->__throw_out_of_range();
3359 __throw_out_of_range();
34383360 return (*this)[__n];
34393361}
34403362
......@@ -3443,7 +3365,7 @@ typename basic_string<_CharT, _Traits, _Allocator>::reference
34433365basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
34443366{
34453367 if (__n >= size())
3446 this->__throw_out_of_range();
3368 __throw_out_of_range();
34473369 return (*this)[__n];
34483370}
34493371
......@@ -3489,7 +3411,7 @@ basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n,
34893411{
34903412 size_type __sz = size();
34913413 if (__pos > __sz)
3492 this->__throw_out_of_range();
3414 __throw_out_of_range();
34933415 size_type __rlen = _VSTD::min(__n, __sz - __pos);
34943416 traits_type::copy(__s, data() + __pos, __rlen);
34953417 return __rlen;
......@@ -3515,11 +3437,13 @@ basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
35153437#endif
35163438{
35173439#if _LIBCPP_DEBUG_LEVEL == 2
3518 if (!__is_long())
3519 __get_db()->__invalidate_all(this);
3520 if (!__str.__is_long())
3521 __get_db()->__invalidate_all(&__str);
3522 __get_db()->swap(this, &__str);
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 }
35233447#endif
35243448 _LIBCPP_ASSERT(
35253449 __alloc_traits::propagate_on_container_swap::value ||
......@@ -3563,7 +3487,7 @@ basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
35633487
35643488template<class _CharT, class _Traits, class _Allocator>
35653489template <class _Tp>
3566_EnableIf
3490__enable_if_t
35673491<
35683492 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
35693493 typename basic_string<_CharT, _Traits, _Allocator>::size_type
......@@ -3621,7 +3545,7 @@ basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
36213545
36223546template<class _CharT, class _Traits, class _Allocator>
36233547template <class _Tp>
3624_EnableIf
3548__enable_if_t
36253549<
36263550 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
36273551 typename basic_string<_CharT, _Traits, _Allocator>::size_type
......@@ -3679,7 +3603,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __s
36793603
36803604template<class _CharT, class _Traits, class _Allocator>
36813605template <class _Tp>
3682_EnableIf
3606__enable_if_t
36833607<
36843608 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
36853609 typename basic_string<_CharT, _Traits, _Allocator>::size_type
......@@ -3737,7 +3661,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __st
37373661
37383662template<class _CharT, class _Traits, class _Allocator>
37393663template <class _Tp>
3740_EnableIf
3664__enable_if_t
37413665<
37423666 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
37433667 typename basic_string<_CharT, _Traits, _Allocator>::size_type
......@@ -3795,7 +3719,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string&
37953719
37963720template<class _CharT, class _Traits, class _Allocator>
37973721template <class _Tp>
3798_EnableIf
3722__enable_if_t
37993723<
38003724 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
38013725 typename basic_string<_CharT, _Traits, _Allocator>::size_type
......@@ -3854,7 +3778,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string&
38543778
38553779template<class _CharT, class _Traits, class _Allocator>
38563780template <class _Tp>
3857_EnableIf
3781__enable_if_t
38583782<
38593783 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
38603784 typename basic_string<_CharT, _Traits, _Allocator>::size_type
......@@ -3892,7 +3816,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
38923816
38933817template <class _CharT, class _Traits, class _Allocator>
38943818template <class _Tp>
3895_EnableIf
3819__enable_if_t
38963820<
38973821 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
38983822 int
......@@ -3931,7 +3855,7 @@ basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
39313855 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
39323856 size_type __sz = size();
39333857 if (__pos1 > __sz || __n2 == npos)
3934 this->__throw_out_of_range();
3858 __throw_out_of_range();
39353859 size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
39363860 int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
39373861 if (__r == 0)
......@@ -3946,7 +3870,7 @@ basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
39463870
39473871template <class _CharT, class _Traits, class _Allocator>
39483872template <class _Tp>
3949_EnableIf
3873__enable_if_t
39503874<
39513875 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
39523876 int
......@@ -3971,7 +3895,7 @@ basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
39713895
39723896template <class _CharT, class _Traits, class _Allocator>
39733897template <class _Tp>
3974_EnableIf
3898__enable_if_t
39753899<
39763900 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
39773901 && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
......@@ -3995,7 +3919,7 @@ basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
39953919 size_type __pos2,
39963920 size_type __n2) const
39973921{
3998 return compare(__pos1, __n1, __self_view(__str), __pos2, __n2);
3922 return compare(__pos1, __n1, __self_view(__str), __pos2, __n2);
39993923}
40003924
40013925template <class _CharT, class _Traits, class _Allocator>
......@@ -4409,6 +4333,7 @@ _LIBCPP_FUNC_VIS string to_string(float __val);
44094333_LIBCPP_FUNC_VIS string to_string(double __val);
44104334_LIBCPP_FUNC_VIS string to_string(long double __val);
44114335
4336#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
44124337_LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = nullptr, int __base = 10);
44134338_LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = nullptr, int __base = 10);
44144339_LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = nullptr, int __base = 10);
......@@ -4428,6 +4353,7 @@ _LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val);
44284353_LIBCPP_FUNC_VIS wstring to_wstring(float __val);
44294354_LIBCPP_FUNC_VIS wstring to_wstring(double __val);
44304355_LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
4356#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
44314357
44324358template<class _CharT, class _Traits, class _Allocator>
44334359_LIBCPP_TEMPLATE_DATA_VIS
......@@ -4507,16 +4433,16 @@ template<class _CharT, class _Traits, class _Allocator>
45074433bool
45084434basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
45094435{
4510 return this->data() <= _VSTD::__to_address(__i->base()) &&
4511 _VSTD::__to_address(__i->base()) < this->data() + this->size();
4436 return data() <= _VSTD::__to_address(__i->base()) &&
4437 _VSTD::__to_address(__i->base()) < data() + size();
45124438}
45134439
45144440template<class _CharT, class _Traits, class _Allocator>
45154441bool
45164442basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
45174443{
4518 return this->data() < _VSTD::__to_address(__i->base()) &&
4519 _VSTD::__to_address(__i->base()) <= this->data() + this->size();
4444 return data() < _VSTD::__to_address(__i->base()) &&
4445 _VSTD::__to_address(__i->base()) <= data() + size();
45204446}
45214447
45224448template<class _CharT, class _Traits, class _Allocator>
......@@ -4524,7 +4450,7 @@ bool
45244450basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
45254451{
45264452 const value_type* __p = _VSTD::__to_address(__i->base()) + __n;
4527 return this->data() <= __p && __p <= this->data() + this->size();
4453 return data() <= __p && __p <= data() + size();
45284454}
45294455
45304456template<class _CharT, class _Traits, class _Allocator>
......@@ -4532,7 +4458,7 @@ bool
45324458basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
45334459{
45344460 const value_type* __p = _VSTD::__to_address(__i->base()) + __n;
4535 return this->data() <= __p && __p < this->data() + this->size();
4461 return data() <= __p && __p < data() + size();
45364462}
45374463
45384464#endif // _LIBCPP_DEBUG_LEVEL == 2
......@@ -4549,11 +4475,13 @@ inline namespace literals
45494475 return basic_string<char> (__str, __len);
45504476 }
45514477
4478#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
45524479 inline _LIBCPP_INLINE_VISIBILITY
45534480 basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
45544481 {
45554482 return basic_string<wchar_t> (__str, __len);
45564483 }
4484#endif
45574485
45584486#ifndef _LIBCPP_HAS_NO_CHAR8_T
45594487 inline _LIBCPP_INLINE_VISIBILITY
......@@ -4574,8 +4502,8 @@ inline namespace literals
45744502 {
45754503 return basic_string<char32_t> (__str, __len);
45764504 }
4577 }
4578}
4505 } // namespace string_literals
4506} // namespace literals
45794507#endif
45804508
45814509_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/string.h+1-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- string.h ---------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/string_view+95-33
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===------------------------ string_view ---------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -85,6 +85,10 @@ namespace std {
8585 constexpr basic_string_view(const charT* str);
8686 basic_string_view(nullptr_t) = delete; // C++2b
8787 constexpr basic_string_view(const charT* str, size_type len);
88 template <class It, class End>
89 constexpr basic_string_view(It begin, End end); // C++20
90 template <class Range>
91 constexpr basic_string_view(Range&& r); // C++23
8892
8993 // 7.4, basic_string_view iterator support
9094 constexpr const_iterator begin() const noexcept;
......@@ -166,6 +170,12 @@ namespace std {
166170 size_type size_; // exposition only
167171 };
168172
173 // basic_string_view deduction guides
174 template<class It, class End>
175 basic_string_view(It, End) -> basic_string_view<iter_value_t<It>>; // C++20
176 template<class Range>
177 basic_string_view(Range&&) -> basic_string_view<ranges::range_value_t<Range>>; // C++23
178
169179 // 7.11, Hash support
170180 template <class T> struct hash;
171181 template <> struct hash<string_view>;
......@@ -187,8 +197,11 @@ namespace std {
187197
188198#include <__config>
189199#include <__debug>
200#include <__ranges/concepts.h>
201#include <__ranges/data.h>
190202#include <__ranges/enable_borrowed_range.h>
191203#include <__ranges/enable_view.h>
204#include <__ranges/size.h>
192205#include <__string>
193206#include <algorithm>
194207#include <compare>
......@@ -196,6 +209,7 @@ namespace std {
196209#include <iterator>
197210#include <limits>
198211#include <stdexcept>
212#include <type_traits>
199213#include <version>
200214
201215#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -217,7 +231,9 @@ typedef basic_string_view<char8_t> u8string_view;
217231#endif
218232typedef basic_string_view<char16_t> u16string_view;
219233typedef basic_string_view<char32_t> u32string_view;
234#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
220235typedef basic_string_view<wchar_t> wstring_view;
236#endif
221237
222238template<class _CharT, class _Traits>
223239class
......@@ -227,7 +243,7 @@ class
227243#endif
228244 _LIBCPP_PREFERRED_NAME(u16string_view)
229245 _LIBCPP_PREFERRED_NAME(u32string_view)
230 _LIBCPP_PREFERRED_NAME(wstring_view)
246 _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wstring_view))
231247 basic_string_view {
232248public:
233249 // types
......@@ -255,10 +271,10 @@ public:
255271 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
256272 basic_string_view() _NOEXCEPT : __data (nullptr), __size(0) {}
257273
258 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
274 _LIBCPP_INLINE_VISIBILITY
259275 basic_string_view(const basic_string_view&) _NOEXCEPT = default;
260276
261 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
277 _LIBCPP_INLINE_VISIBILITY
262278 basic_string_view& operator=(const basic_string_view&) _NOEXCEPT = default;
263279
264280 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
......@@ -270,6 +286,35 @@ public:
270286#endif
271287 }
272288
289#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
290 template <contiguous_iterator _It, sized_sentinel_for<_It> _End>
291 requires (is_same_v<iter_value_t<_It>, _CharT> && !is_convertible_v<_End, size_type>)
292 constexpr _LIBCPP_HIDE_FROM_ABI basic_string_view(_It __begin, _End __end)
293 : __data(_VSTD::to_address(__begin)), __size(__end - __begin)
294 {
295 _LIBCPP_ASSERT((__end - __begin) >= 0, "std::string_view::string_view(iterator, sentinel) received invalid range");
296 }
297#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
298
299#if _LIBCPP_STD_VER > 20 && !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
300 template <class _Range>
301 requires (
302 !is_same_v<remove_cvref_t<_Range>, basic_string_view> &&
303 ranges::contiguous_range<_Range> &&
304 ranges::sized_range<_Range> &&
305 is_same_v<ranges::range_value_t<_Range>, _CharT> &&
306 !is_convertible_v<_Range, const _CharT*> &&
307 (!requires(remove_cvref_t<_Range>& d) {
308 d.operator _VSTD::basic_string_view<_CharT, _Traits>();
309 }) &&
310 (!requires {
311 typename remove_reference_t<_Range>::traits_type;
312 } || is_same_v<typename remove_reference_t<_Range>::traits_type, _Traits>)
313 )
314 constexpr _LIBCPP_HIDE_FROM_ABI
315 basic_string_view(_Range&& __r) : __data(ranges::data(__r)), __size(ranges::size(__r)) {}
316#endif
317
273318 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
274319 basic_string_view(const _CharT* __s)
275320 : __data(__s), __size(_VSTD::__char_traits_length_checked<_Traits>(__s)) {}
......@@ -311,7 +356,7 @@ public:
311356 size_type length() const _NOEXCEPT { return __size; }
312357
313358 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
314 size_type max_size() const _NOEXCEPT { return numeric_limits<size_type>::max(); }
359 size_type max_size() const _NOEXCEPT { return numeric_limits<size_type>::max() / sizeof(value_type); }
315360
316361 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
317362 bool empty() const _NOEXCEPT { return __size == 0; }
......@@ -618,28 +663,28 @@ public:
618663 }
619664
620665#if _LIBCPP_STD_VER > 17
621 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
622 bool starts_with(basic_string_view __s) const _NOEXCEPT
666 constexpr _LIBCPP_INLINE_VISIBILITY
667 bool starts_with(basic_string_view __s) const noexcept
623668 { return size() >= __s.size() && compare(0, __s.size(), __s) == 0; }
624669
625 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
626 bool starts_with(value_type __c) const _NOEXCEPT
670 constexpr _LIBCPP_INLINE_VISIBILITY
671 bool starts_with(value_type __c) const noexcept
627672 { return !empty() && _Traits::eq(front(), __c); }
628673
629 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
630 bool starts_with(const value_type* __s) const _NOEXCEPT
674 constexpr _LIBCPP_INLINE_VISIBILITY
675 bool starts_with(const value_type* __s) const noexcept
631676 { return starts_with(basic_string_view(__s)); }
632677
633 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
634 bool ends_with(basic_string_view __s) const _NOEXCEPT
678 constexpr _LIBCPP_INLINE_VISIBILITY
679 bool ends_with(basic_string_view __s) const noexcept
635680 { return size() >= __s.size() && compare(size() - __s.size(), npos, __s) == 0; }
636681
637 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
638 bool ends_with(value_type __c) const _NOEXCEPT
682 constexpr _LIBCPP_INLINE_VISIBILITY
683 bool ends_with(value_type __c) const noexcept
639684 { return !empty() && _Traits::eq(back(), __c); }
640685
641 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
642 bool ends_with(const value_type* __s) const _NOEXCEPT
686 constexpr _LIBCPP_INLINE_VISIBILITY
687 bool ends_with(const value_type* __s) const noexcept
643688 { return ends_with(basic_string_view(__s)); }
644689#endif
645690
......@@ -662,13 +707,26 @@ private:
662707 size_type __size;
663708};
664709
665#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_RANGES)
710#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
666711template <class _CharT, class _Traits>
667712inline constexpr bool ranges::enable_view<basic_string_view<_CharT, _Traits>> = true;
668713
669714template <class _CharT, class _Traits>
670715inline constexpr bool ranges::enable_borrowed_range<basic_string_view<_CharT, _Traits> > = true;
671#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_RANGES)
716#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
717
718// [string.view.deduct]
719
720#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
721template <contiguous_iterator _It, sized_sentinel_for<_It> _End>
722 basic_string_view(_It, _End) -> basic_string_view<iter_value_t<_It>>;
723#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
724
725
726#if _LIBCPP_STD_VER > 20 && !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
727template <ranges::contiguous_range _Range>
728 basic_string_view(_Range) -> basic_string_view<ranges::range_value_t<_Range>>;
729#endif
672730
673731// [string.view.comparison]
674732// operator ==
......@@ -681,7 +739,9 @@ bool operator==(basic_string_view<_CharT, _Traits> __lhs,
681739 return __lhs.compare(__rhs) == 0;
682740}
683741
684template<class _CharT, class _Traits>
742// The dummy default template parameters are used to work around a MSVC issue with mangling, see VSO-409326 for details.
743// This applies to the other sufficient overloads below for the other comparison operators.
744template<class _CharT, class _Traits, int = 1>
685745_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
686746bool operator==(basic_string_view<_CharT, _Traits> __lhs,
687747 typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
......@@ -690,7 +750,7 @@ bool operator==(basic_string_view<_CharT, _Traits> __lhs,
690750 return __lhs.compare(__rhs) == 0;
691751}
692752
693template<class _CharT, class _Traits>
753template<class _CharT, class _Traits, int = 2>
694754_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
695755bool operator==(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
696756 basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
......@@ -710,7 +770,7 @@ bool operator!=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_Cha
710770 return __lhs.compare(__rhs) != 0;
711771}
712772
713template<class _CharT, class _Traits>
773template<class _CharT, class _Traits, int = 1>
714774_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
715775bool operator!=(basic_string_view<_CharT, _Traits> __lhs,
716776 typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
......@@ -720,7 +780,7 @@ bool operator!=(basic_string_view<_CharT, _Traits> __lhs,
720780 return __lhs.compare(__rhs) != 0;
721781}
722782
723template<class _CharT, class _Traits>
783template<class _CharT, class _Traits, int = 2>
724784_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
725785bool operator!=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
726786 basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
......@@ -739,7 +799,7 @@ bool operator<(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_Char
739799 return __lhs.compare(__rhs) < 0;
740800}
741801
742template<class _CharT, class _Traits>
802template<class _CharT, class _Traits, int = 1>
743803_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
744804bool operator<(basic_string_view<_CharT, _Traits> __lhs,
745805 typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
......@@ -747,7 +807,7 @@ bool operator<(basic_string_view<_CharT, _Traits> __lhs,
747807 return __lhs.compare(__rhs) < 0;
748808}
749809
750template<class _CharT, class _Traits>
810template<class _CharT, class _Traits, int = 2>
751811_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
752812bool operator<(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
753813 basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
......@@ -764,7 +824,7 @@ bool operator> (basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_Cha
764824 return __lhs.compare(__rhs) > 0;
765825}
766826
767template<class _CharT, class _Traits>
827template<class _CharT, class _Traits, int = 1>
768828_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
769829bool operator>(basic_string_view<_CharT, _Traits> __lhs,
770830 typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
......@@ -772,7 +832,7 @@ bool operator>(basic_string_view<_CharT, _Traits> __lhs,
772832 return __lhs.compare(__rhs) > 0;
773833}
774834
775template<class _CharT, class _Traits>
835template<class _CharT, class _Traits, int = 2>
776836_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
777837bool operator>(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
778838 basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
......@@ -789,7 +849,7 @@ bool operator<=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_Cha
789849 return __lhs.compare(__rhs) <= 0;
790850}
791851
792template<class _CharT, class _Traits>
852template<class _CharT, class _Traits, int = 1>
793853_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
794854bool operator<=(basic_string_view<_CharT, _Traits> __lhs,
795855 typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
......@@ -797,7 +857,7 @@ bool operator<=(basic_string_view<_CharT, _Traits> __lhs,
797857 return __lhs.compare(__rhs) <= 0;
798858}
799859
800template<class _CharT, class _Traits>
860template<class _CharT, class _Traits, int = 2>
801861_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
802862bool operator<=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
803863 basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
......@@ -815,7 +875,7 @@ bool operator>=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_Cha
815875}
816876
817877
818template<class _CharT, class _Traits>
878template<class _CharT, class _Traits, int = 1>
819879_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
820880bool operator>=(basic_string_view<_CharT, _Traits> __lhs,
821881 typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
......@@ -823,7 +883,7 @@ bool operator>=(basic_string_view<_CharT, _Traits> __lhs,
823883 return __lhs.compare(__rhs) >= 0;
824884}
825885
826template<class _CharT, class _Traits>
886template<class _CharT, class _Traits, int = 2>
827887_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
828888bool operator>=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
829889 basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
......@@ -860,11 +920,13 @@ inline namespace literals
860920 return basic_string_view<char> (__str, __len);
861921 }
862922
923#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
863924 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
864925 basic_string_view<wchar_t> operator "" sv(const wchar_t *__str, size_t __len) _NOEXCEPT
865926 {
866927 return basic_string_view<wchar_t> (__str, __len);
867928 }
929#endif
868930
869931#ifndef _LIBCPP_HAS_NO_CHAR8_T
870932 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
......@@ -885,8 +947,8 @@ inline namespace literals
885947 {
886948 return basic_string_view<char32_t> (__str, __len);
887949 }
888 }
889}
950 } // namespace string_view_literals
951} // namespace literals
890952#endif
891953_LIBCPP_END_NAMESPACE_STD
892954
lib/libcxx/include/strstream+2-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- strstream --------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -132,6 +132,7 @@ private:
132132#include <__config>
133133#include <istream>
134134#include <ostream>
135#include <version>
135136
136137#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
137138#pragma GCC system_header
lib/libcxx/include/system_error+9-10
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===---------------------------- system_error ----------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -46,10 +46,10 @@ template <class T> struct is_error_condition_enum
4646 : public false_type {};
4747
4848template <class _Tp>
49inline constexpr size_t is_error_condition_enum_v = is_error_condition_enum<_Tp>::value; // C++17
49inline constexpr bool is_error_condition_enum_v = is_error_condition_enum<_Tp>::value; // C++17
5050
5151template <class _Tp>
52inline constexpr size_t is_error_code_enum_v = is_error_code_enum<_Tp>::value; // C++17
52inline constexpr bool is_error_code_enum_v = is_error_code_enum<_Tp>::value; // C++17
5353
5454class error_code
5555{
......@@ -150,6 +150,7 @@ template <> struct hash<std::error_condition>;
150150#include <stdexcept>
151151#include <string>
152152#include <type_traits>
153#include <version>
153154
154155#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
155156#pragma GCC system_header
......@@ -165,7 +166,7 @@ struct _LIBCPP_TEMPLATE_VIS is_error_code_enum
165166
166167#if _LIBCPP_STD_VER > 14
167168template <class _Tp>
168_LIBCPP_INLINE_VAR constexpr size_t is_error_code_enum_v = is_error_code_enum<_Tp>::value;
169inline constexpr bool is_error_code_enum_v = is_error_code_enum<_Tp>::value;
169170#endif
170171
171172// is_error_condition_enum
......@@ -176,7 +177,7 @@ struct _LIBCPP_TEMPLATE_VIS is_error_condition_enum
176177
177178#if _LIBCPP_STD_VER > 14
178179template <class _Tp>
179_LIBCPP_INLINE_VAR constexpr size_t is_error_condition_enum_v = is_error_condition_enum<_Tp>::value;
180inline constexpr bool is_error_condition_enum_v = is_error_condition_enum<_Tp>::value;
180181#endif
181182
182183template <>
......@@ -206,13 +207,11 @@ public:
206207 error_category() _NOEXCEPT;
207208#else
208209 _LIBCPP_INLINE_VISIBILITY
209 _LIBCPP_CONSTEXPR_AFTER_CXX11 error_category() _NOEXCEPT _LIBCPP_DEFAULT
210 _LIBCPP_CONSTEXPR_AFTER_CXX11 error_category() _NOEXCEPT = default;
210211#endif
211private:
212 error_category(const error_category&);// = delete;
213 error_category& operator=(const error_category&);// = delete;
212 error_category(const error_category&) = delete;
213 error_category& operator=(const error_category&) = delete;
214214
215public:
216215 virtual const char* name() const _NOEXCEPT = 0;
217216 virtual error_condition default_error_condition(int __ev) const _NOEXCEPT;
218217 virtual bool equivalent(int __code, const error_condition& __condition) const _NOEXCEPT;
lib/libcxx/include/tgmath.h+1-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===-------------------------- tgmath.h ----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/thread+7-5
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- thread -----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -86,8 +86,9 @@ void sleep_for(const chrono::duration<Rep, Period>& rel_time);
8686#include <__debug>
8787#include <__functional_base>
8888#include <__mutex_base>
89#include <__thread/poll_with_backoff.h>
90#include <__thread/timed_backoff_policy.h>
8991#include <__threading_support>
90#include <__utility/__decay_copy.h>
9192#include <__utility/forward.h>
9293#include <chrono>
9394#include <cstddef>
......@@ -97,6 +98,7 @@ void sleep_for(const chrono::duration<Rep, Period>& rel_time);
9798#include <system_error>
9899#include <tuple>
99100#include <type_traits>
101#include <version>
100102
101103#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
102104#pragma GCC system_header
......@@ -302,8 +304,8 @@ thread::thread(_Fp&& __f, _Args&&... __args)
302304 typedef tuple<_TSPtr, typename decay<_Fp>::type, typename decay<_Args>::type...> _Gp;
303305 unique_ptr<_Gp> __p(
304306 new _Gp(_VSTD::move(__tsp),
305 _VSTD::__decay_copy(_VSTD::forward<_Fp>(__f)),
306 _VSTD::__decay_copy(_VSTD::forward<_Args>(__args))...));
307 _VSTD::forward<_Fp>(__f),
308 _VSTD::forward<_Args>(__args)...));
307309 int __ec = _VSTD::__libcpp_thread_create(&__t_, &__thread_proxy<_Gp>, __p.get());
308310 if (__ec == 0)
309311 __p.release();
......@@ -402,7 +404,7 @@ sleep_until(const chrono::time_point<chrono::steady_clock, _Duration>& __t)
402404inline _LIBCPP_INLINE_VISIBILITY
403405void yield() _NOEXCEPT {__libcpp_thread_yield();}
404406
405} // this_thread
407} // namespace this_thread
406408
407409_LIBCPP_END_NAMESPACE_STD
408410
lib/libcxx/include/tuple+119-60
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- tuple ------------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -73,6 +73,19 @@ public:
7373 void swap(tuple&) noexcept(AND(swap(declval<T&>(), declval<T&>())...)); // constexpr in C++20
7474};
7575
76
77template<class... TTypes, class... UTypes, template<class> class TQual, template<class> class UQual> // since C++23
78 requires requires { typename tuple<common_reference_t<TQual<TTypes>, UQual<UTypes>>...>; }
79struct basic_common_reference<tuple<TTypes...>, tuple<UTypes...>, TQual, UQual> {
80 using type = tuple<common_reference_t<TQual<TTypes>, UQual<UTypes>>...>;
81};
82
83template<class... TTypes, class... UTypes> // since C++23
84 requires requires { typename tuple<common_type_t<TTypes, UTypes>...>; }
85struct common_type<tuple<TTypes...>, tuple<UTypes...>> {
86 using type = tuple<common_type_t<TTypes, UTypes>...>;
87};
88
7689template <class ...T>
7790tuple(T...) -> tuple<T...>; // since C++17
7891template <class T1, class T2>
......@@ -132,11 +145,14 @@ template <class T1, class... T>
132145
133146// 20.4.1.6, relational operators:
134147template<class... T, class... U> bool operator==(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
135template<class... T, class... U> bool operator<(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
136template<class... T, class... U> bool operator!=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
137template<class... T, class... U> bool operator>(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
138template<class... T, class... U> bool operator<=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
139template<class... T, class... U> bool operator>=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
148template<class... T, class... U> bool operator<(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
149template<class... T, class... U> bool operator!=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
150template<class... T, class... U> bool operator>(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
151template<class... T, class... U> bool operator<=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
152template<class... T, class... U> bool operator>=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
153template<class... T, class... U>
154 constexpr common_comparison_category_t<synth-three-way-result<T, U>...>
155 operator<=>(const tuple<T...>&, const tuple<U...>&); // since C++20
140156
141157template <class... Types, class Alloc>
142158 struct uses_allocator<tuple<Types...>, Alloc>;
......@@ -149,6 +165,8 @@ template <class... Types>
149165
150166*/
151167
168#include <__compare/common_comparison_category.h>
169#include <__compare/synth_three_way.h>
152170#include <__config>
153171#include <__functional/unwrap_ref.h>
154172#include <__functional_base>
......@@ -156,6 +174,7 @@ template <class... Types>
156174#include <__memory/uses_allocator.h>
157175#include <__tuple>
158176#include <__utility/forward.h>
177#include <__utility/integer_sequence.h>
159178#include <__utility/move.h>
160179#include <compare>
161180#include <cstddef>
......@@ -231,7 +250,7 @@ public:
231250 "Attempted to default construct a reference element in a tuple");}
232251
233252 template <class _Tp,
234 class = _EnableIf<
253 class = __enable_if_t<
235254 _And<
236255 _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
237256 is_constructible<_Hp, _Tp>
......@@ -304,7 +323,7 @@ public:
304323 : _Hp(__a) {}
305324
306325 template <class _Tp,
307 class = _EnableIf<
326 class = __enable_if_t<
308327 _And<
309328 _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
310329 is_constructible<_Hp, _Tp>
......@@ -466,7 +485,7 @@ public:
466485 // [tuple.cnstr]
467486
468487 // tuple() constructors (including allocator_arg_t variants)
469 template <template<class...> class _IsImpDefault = __is_implicitly_default_constructible, _EnableIf<
488 template <template<class...> class _IsImpDefault = __is_implicitly_default_constructible, __enable_if_t<
470489 _And<
471490 _IsImpDefault<_Tp>... // explicit check
472491 >::value
......@@ -477,7 +496,7 @@ public:
477496 { }
478497
479498 template <template<class...> class _IsImpDefault = __is_implicitly_default_constructible,
480 template<class...> class _IsDefault = is_default_constructible, _EnableIf<
499 template<class...> class _IsDefault = is_default_constructible, __enable_if_t<
481500 _And<
482501 _IsDefault<_Tp>...,
483502 _Not<_Lazy<_And, _IsImpDefault<_Tp>...> > // explicit check
......@@ -488,7 +507,7 @@ public:
488507 _NOEXCEPT_(_And<is_nothrow_default_constructible<_Tp>...>::value)
489508 { }
490509
491 template <class _Alloc, template<class...> class _IsImpDefault = __is_implicitly_default_constructible, _EnableIf<
510 template <class _Alloc, template<class...> class _IsImpDefault = __is_implicitly_default_constructible, __enable_if_t<
492511 _And<
493512 _IsImpDefault<_Tp>... // explicit check
494513 >::value
......@@ -502,7 +521,7 @@ public:
502521
503522 template <class _Alloc,
504523 template<class...> class _IsImpDefault = __is_implicitly_default_constructible,
505 template<class...> class _IsDefault = is_default_constructible, _EnableIf<
524 template<class...> class _IsDefault = is_default_constructible, __enable_if_t<
506525 _And<
507526 _IsDefault<_Tp>...,
508527 _Not<_Lazy<_And, _IsImpDefault<_Tp>...> > // explicit check
......@@ -516,7 +535,7 @@ public:
516535 __tuple_types<_Tp...>()) {}
517536
518537 // tuple(const T&...) constructors (including allocator_arg_t variants)
519 template <template<class...> class _And = _And, _EnableIf<
538 template <template<class...> class _And = _And, __enable_if_t<
520539 _And<
521540 _BoolConstant<sizeof...(_Tp) >= 1>,
522541 is_copy_constructible<_Tp>...,
......@@ -533,7 +552,7 @@ public:
533552 __t...
534553 ) {}
535554
536 template <template<class...> class _And = _And, _EnableIf<
555 template <template<class...> class _And = _And, __enable_if_t<
537556 _And<
538557 _BoolConstant<sizeof...(_Tp) >= 1>,
539558 is_copy_constructible<_Tp>...,
......@@ -550,7 +569,7 @@ public:
550569 __t...
551570 ) {}
552571
553 template <class _Alloc, template<class...> class _And = _And, _EnableIf<
572 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
554573 _And<
555574 _BoolConstant<sizeof...(_Tp) >= 1>,
556575 is_copy_constructible<_Tp>...,
......@@ -567,7 +586,7 @@ public:
567586 __t...
568587 ) {}
569588
570 template <class _Alloc, template<class...> class _And = _And, _EnableIf<
589 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
571590 _And<
572591 _BoolConstant<sizeof...(_Tp) >= 1>,
573592 is_copy_constructible<_Tp>...,
......@@ -595,7 +614,7 @@ public:
595614 is_constructible<_Tp, _Up>...
596615 > { };
597616
598 template <class ..._Up, _EnableIf<
617 template <class ..._Up, __enable_if_t<
599618 _And<
600619 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
601620 _EnableUTypesCtor<_Up...>,
......@@ -611,7 +630,7 @@ public:
611630 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
612631 _VSTD::forward<_Up>(__u)...) {}
613632
614 template <class ..._Up, _EnableIf<
633 template <class ..._Up, __enable_if_t<
615634 _And<
616635 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
617636 _EnableUTypesCtor<_Up...>,
......@@ -627,7 +646,7 @@ public:
627646 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
628647 _VSTD::forward<_Up>(__u)...) {}
629648
630 template <class _Alloc, class ..._Up, _EnableIf<
649 template <class _Alloc, class ..._Up, __enable_if_t<
631650 _And<
632651 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
633652 _EnableUTypesCtor<_Up...>,
......@@ -643,7 +662,7 @@ public:
643662 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
644663 _VSTD::forward<_Up>(__u)...) {}
645664
646 template <class _Alloc, class ..._Up, _EnableIf<
665 template <class _Alloc, class ..._Up, __enable_if_t<
647666 _And<
648667 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
649668 _EnableUTypesCtor<_Up...>,
......@@ -663,14 +682,14 @@ public:
663682 tuple(const tuple&) = default;
664683 tuple(tuple&&) = default;
665684
666 template <class _Alloc, template<class...> class _And = _And, _EnableIf<
685 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
667686 _And<is_copy_constructible<_Tp>...>::value
668687 , int> = 0>
669688 tuple(allocator_arg_t, const _Alloc& __alloc, const tuple& __t)
670689 : __base_(allocator_arg_t(), __alloc, __t)
671690 { }
672691
673 template <class _Alloc, template<class...> class _And = _And, _EnableIf<
692 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
674693 _And<is_move_constructible<_Tp>...>::value
675694 , int> = 0>
676695 tuple(allocator_arg_t, const _Alloc& __alloc, tuple&& __t)
......@@ -693,7 +712,7 @@ public:
693712 is_constructible<_Tp, const _Up&>...
694713 > { };
695714
696 template <class ..._Up, _EnableIf<
715 template <class ..._Up, __enable_if_t<
697716 _And<
698717 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
699718 _EnableCopyFromOtherTuple<_Up...>,
......@@ -706,7 +725,7 @@ public:
706725 : __base_(__t)
707726 { }
708727
709 template <class ..._Up, _EnableIf<
728 template <class ..._Up, __enable_if_t<
710729 _And<
711730 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
712731 _EnableCopyFromOtherTuple<_Up...>,
......@@ -719,7 +738,7 @@ public:
719738 : __base_(__t)
720739 { }
721740
722 template <class ..._Up, class _Alloc, _EnableIf<
741 template <class ..._Up, class _Alloc, __enable_if_t<
723742 _And<
724743 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
725744 _EnableCopyFromOtherTuple<_Up...>,
......@@ -731,7 +750,7 @@ public:
731750 : __base_(allocator_arg_t(), __a, __t)
732751 { }
733752
734 template <class ..._Up, class _Alloc, _EnableIf<
753 template <class ..._Up, class _Alloc, __enable_if_t<
735754 _And<
736755 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
737756 _EnableCopyFromOtherTuple<_Up...>,
......@@ -759,7 +778,7 @@ public:
759778 is_constructible<_Tp, _Up>...
760779 > { };
761780
762 template <class ..._Up, _EnableIf<
781 template <class ..._Up, __enable_if_t<
763782 _And<
764783 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
765784 _EnableMoveFromOtherTuple<_Up...>,
......@@ -772,7 +791,7 @@ public:
772791 : __base_(_VSTD::move(__t))
773792 { }
774793
775 template <class ..._Up, _EnableIf<
794 template <class ..._Up, __enable_if_t<
776795 _And<
777796 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
778797 _EnableMoveFromOtherTuple<_Up...>,
......@@ -785,7 +804,7 @@ public:
785804 : __base_(_VSTD::move(__t))
786805 { }
787806
788 template <class _Alloc, class ..._Up, _EnableIf<
807 template <class _Alloc, class ..._Up, __enable_if_t<
789808 _And<
790809 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
791810 _EnableMoveFromOtherTuple<_Up...>,
......@@ -797,7 +816,7 @@ public:
797816 : __base_(allocator_arg_t(), __a, _VSTD::move(__t))
798817 { }
799818
800 template <class _Alloc, class ..._Up, _EnableIf<
819 template <class _Alloc, class ..._Up, __enable_if_t<
801820 _And<
802821 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
803822 _EnableMoveFromOtherTuple<_Up...>,
......@@ -826,7 +845,7 @@ public:
826845 _Not<is_convertible<const _Up2&, _SecondType<_DependentTp...> > >
827846 > { };
828847
829 template <class _Up1, class _Up2, template<class...> class _And = _And, _EnableIf<
848 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
830849 _And<
831850 _BoolConstant<sizeof...(_Tp) == 2>,
832851 _EnableImplicitCopyFromPair<_Up1, _Up2, _Tp...>
......@@ -841,7 +860,7 @@ public:
841860 : __base_(__p)
842861 { }
843862
844 template <class _Up1, class _Up2, template<class...> class _And = _And, _EnableIf<
863 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
845864 _And<
846865 _BoolConstant<sizeof...(_Tp) == 2>,
847866 _EnableExplicitCopyFromPair<_Up1, _Up2, _Tp...>
......@@ -856,7 +875,7 @@ public:
856875 : __base_(__p)
857876 { }
858877
859 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, _EnableIf<
878 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
860879 _And<
861880 _BoolConstant<sizeof...(_Tp) == 2>,
862881 _EnableImplicitCopyFromPair<_Up1, _Up2, _Tp...>
......@@ -867,7 +886,7 @@ public:
867886 : __base_(allocator_arg_t(), __a, __p)
868887 { }
869888
870 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, _EnableIf<
889 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
871890 _And<
872891 _BoolConstant<sizeof...(_Tp) == 2>,
873892 _EnableExplicitCopyFromPair<_Up1, _Up2, _Tp...>
......@@ -895,7 +914,7 @@ public:
895914 _Not<is_convertible<_Up2, _SecondType<_DependentTp...> > >
896915 > { };
897916
898 template <class _Up1, class _Up2, template<class...> class _And = _And, _EnableIf<
917 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
899918 _And<
900919 _BoolConstant<sizeof...(_Tp) == 2>,
901920 _EnableImplicitMoveFromPair<_Up1, _Up2, _Tp...>
......@@ -910,7 +929,7 @@ public:
910929 : __base_(_VSTD::move(__p))
911930 { }
912931
913 template <class _Up1, class _Up2, template<class...> class _And = _And, _EnableIf<
932 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
914933 _And<
915934 _BoolConstant<sizeof...(_Tp) == 2>,
916935 _EnableExplicitMoveFromPair<_Up1, _Up2, _Tp...>
......@@ -925,7 +944,7 @@ public:
925944 : __base_(_VSTD::move(__p))
926945 { }
927946
928 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, _EnableIf<
947 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
929948 _And<
930949 _BoolConstant<sizeof...(_Tp) == 2>,
931950 _EnableImplicitMoveFromPair<_Up1, _Up2, _Tp...>
......@@ -936,7 +955,7 @@ public:
936955 : __base_(allocator_arg_t(), __a, _VSTD::move(__p))
937956 { }
938957
939 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, _EnableIf<
958 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
940959 _And<
941960 _BoolConstant<sizeof...(_Tp) == 2>,
942961 _EnableExplicitMoveFromPair<_Up1, _Up2, _Tp...>
......@@ -967,7 +986,7 @@ public:
967986 return *this;
968987 }
969988
970 template<class... _Up, _EnableIf<
989 template<class... _Up, __enable_if_t<
971990 _And<
972991 _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>,
973992 is_assignable<_Tp&, _Up const&>...
......@@ -982,7 +1001,7 @@ public:
9821001 return *this;
9831002 }
9841003
985 template<class... _Up, _EnableIf<
1004 template<class... _Up, __enable_if_t<
9861005 _And<
9871006 _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>,
9881007 is_assignable<_Tp&, _Up>...
......@@ -998,7 +1017,7 @@ public:
9981017 return *this;
9991018 }
10001019
1001 template<class _Up1, class _Up2, class _Dep = true_type, _EnableIf<
1020 template<class _Up1, class _Up2, class _Dep = true_type, __enable_if_t<
10021021 _And<_Dep,
10031022 _BoolConstant<sizeof...(_Tp) == 2>,
10041023 is_assignable<_FirstType<_Tp..., _Dep>&, _Up1 const&>,
......@@ -1017,7 +1036,7 @@ public:
10171036 return *this;
10181037 }
10191038
1020 template<class _Up1, class _Up2, class _Dep = true_type, _EnableIf<
1039 template<class _Up1, class _Up2, class _Dep = true_type, __enable_if_t<
10211040 _And<_Dep,
10221041 _BoolConstant<sizeof...(_Tp) == 2>,
10231042 is_assignable<_FirstType<_Tp..., _Dep>&, _Up1>,
......@@ -1037,7 +1056,7 @@ public:
10371056 }
10381057
10391058 // EXTENSION
1040 template<class _Up, size_t _Np, class = _EnableIf<
1059 template<class _Up, size_t _Np, class = __enable_if_t<
10411060 _And<
10421061 _BoolConstant<_Np == sizeof...(_Tp)>,
10431062 is_assignable<_Tp&, _Up const&>...
......@@ -1053,7 +1072,7 @@ public:
10531072 }
10541073
10551074 // EXTENSION
1056 template<class _Up, size_t _Np, class = void, class = _EnableIf<
1075 template<class _Up, size_t _Np, class = void, class = __enable_if_t<
10571076 _And<
10581077 _BoolConstant<_Np == sizeof...(_Tp)>,
10591078 is_assignable<_Tp&, _Up>...
......@@ -1097,7 +1116,21 @@ public:
10971116 void swap(tuple&) _NOEXCEPT {}
10981117};
10991118
1100#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
1119#if _LIBCPP_STD_VER > 20
1120template <class... _TTypes, class... _UTypes, template<class> class _TQual, template<class> class _UQual>
1121 requires requires { typename tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>; }
1122struct basic_common_reference<tuple<_TTypes...>, tuple<_UTypes...>, _TQual, _UQual> {
1123 using type = tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>;
1124};
1125
1126template <class... _TTypes, class... _UTypes>
1127 requires requires { typename tuple<common_type_t<_TTypes, _UTypes>...>; }
1128struct common_type<tuple<_TTypes...>, tuple<_UTypes...>> {
1129 using type = tuple<common_type_t<_TTypes, _UTypes>...>;
1130};
1131#endif
1132
1133#if _LIBCPP_STD_VER > 14
11011134template <class ..._Tp>
11021135tuple(_Tp...) -> tuple<_Tp...>;
11031136template <class _Tp1, class _Tp2>
......@@ -1128,7 +1161,7 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
11281161typename tuple_element<_Ip, tuple<_Tp...> >::type&
11291162get(tuple<_Tp...>& __t) _NOEXCEPT
11301163{
1131 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
1164 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
11321165 return static_cast<__tuple_leaf<_Ip, type>&>(__t.__base_).get();
11331166}
11341167
......@@ -1137,7 +1170,7 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
11371170const typename tuple_element<_Ip, tuple<_Tp...> >::type&
11381171get(const tuple<_Tp...>& __t) _NOEXCEPT
11391172{
1140 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
1173 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
11411174 return static_cast<const __tuple_leaf<_Ip, type>&>(__t.__base_).get();
11421175}
11431176
......@@ -1146,7 +1179,7 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
11461179typename tuple_element<_Ip, tuple<_Tp...> >::type&&
11471180get(tuple<_Tp...>&& __t) _NOEXCEPT
11481181{
1149 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
1182 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
11501183 return static_cast<type&&>(
11511184 static_cast<__tuple_leaf<_Ip, type>&&>(__t.__base_).get());
11521185}
......@@ -1156,7 +1189,7 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
11561189const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
11571190get(const tuple<_Tp...>&& __t) _NOEXCEPT
11581191{
1159 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
1192 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
11601193 return static_cast<const type&&>(
11611194 static_cast<const __tuple_leaf<_Ip, type>&&>(__t.__base_).get());
11621195}
......@@ -1194,7 +1227,7 @@ struct __find_exactly_one_checked<_T1> {
11941227 static_assert(!is_same<_T1, _T1>::value, "type not in empty type list");
11951228};
11961229
1197} // namespace __find_detail;
1230} // namespace __find_detail
11981231
11991232template <typename _T1, typename... _Args>
12001233struct __find_exactly_one_t
......@@ -1250,8 +1283,8 @@ struct __ignore_t
12501283};
12511284
12521285namespace {
1253 _LIBCPP_INLINE_VAR constexpr __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>();
1254}
1286 constexpr __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>();
1287} // namespace
12551288
12561289template <class... _Tp>
12571290inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
......@@ -1300,6 +1333,30 @@ operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
13001333 return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
13011334}
13021335
1336#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
1337
1338// operator<=>
1339
1340template <class ..._Tp, class ..._Up, size_t ..._Is>
1341_LIBCPP_HIDE_FROM_ABI constexpr
1342auto
1343__tuple_compare_three_way(const tuple<_Tp...>& __x, const tuple<_Up...>& __y, index_sequence<_Is...>) {
1344 common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...> __result = strong_ordering::equal;
1345 static_cast<void>(((__result = _VSTD::__synth_three_way(_VSTD::get<_Is>(__x), _VSTD::get<_Is>(__y)), __result != 0) || ...));
1346 return __result;
1347}
1348
1349template <class ..._Tp, class ..._Up>
1350requires (sizeof...(_Tp) == sizeof...(_Up))
1351_LIBCPP_HIDE_FROM_ABI constexpr
1352common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...>
1353operator<=>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1354{
1355 return _VSTD::__tuple_compare_three_way(__x, __y, index_sequence_for<_Tp...>{});
1356}
1357
1358#else // !defined(_LIBCPP_HAS_NO_CONCEPTS)
1359
13031360template <class ..._Tp, class ..._Up>
13041361inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
13051362bool
......@@ -1368,6 +1425,8 @@ operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
13681425 return !(__y < __x);
13691426}
13701427
1428#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
1429
13711430// tuple_cat
13721431
13731432template <class _Tp, class _Up> struct __tuple_cat_type;
......@@ -1375,7 +1434,7 @@ template <class _Tp, class _Up> struct __tuple_cat_type;
13751434template <class ..._Ttypes, class ..._Utypes>
13761435struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
13771436{
1378 typedef _LIBCPP_NODEBUG_TYPE tuple<_Ttypes..., _Utypes...> type;
1437 typedef _LIBCPP_NODEBUG tuple<_Ttypes..., _Utypes...> type;
13791438};
13801439
13811440template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
......@@ -1386,7 +1445,7 @@ struct __tuple_cat_return_1
13861445template <class ..._Types, class _Tuple0>
13871446struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
13881447{
1389 typedef _LIBCPP_NODEBUG_TYPE typename __tuple_cat_type<tuple<_Types...>,
1448 typedef _LIBCPP_NODEBUG typename __tuple_cat_type<tuple<_Types...>,
13901449 typename __make_tuple_types<typename __uncvref<_Tuple0>::type>::type>::type
13911450 type;
13921451};
......@@ -1416,7 +1475,7 @@ struct __tuple_cat_return<_Tuple0, _Tuples...>
14161475template <>
14171476struct __tuple_cat_return<>
14181477{
1419 typedef _LIBCPP_NODEBUG_TYPE tuple<> type;
1478 typedef _LIBCPP_NODEBUG tuple<> type;
14201479};
14211480
14221481inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
......@@ -1432,7 +1491,7 @@ struct __tuple_cat_return_ref_imp;
14321491template <class ..._Types, size_t ..._I0, class _Tuple0>
14331492struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
14341493{
1435 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
1494 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple0>::type _T0;
14361495 typedef tuple<_Types..., typename __apply_cv<_Tuple0,
14371496 typename tuple_element<_I0, _T0>::type>::type&&...> type;
14381497};
......@@ -1480,8 +1539,8 @@ struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J
14801539 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
14811540 operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
14821541 {
1483 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
1484 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple1>::type _T1;
1542 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple0>::type _T0;
1543 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple1>::type _T1;
14851544 return __tuple_cat<
14861545 tuple<_Types...,
14871546 typename __apply_cv<_Tuple0, typename tuple_element<
......@@ -1501,7 +1560,7 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
15011560typename __tuple_cat_return<_Tuple0, _Tuples...>::type
15021561tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
15031562{
1504 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
1563 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple0>::type _T0;
15051564 return __tuple_cat<tuple<>, __tuple_indices<>,
15061565 typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
15071566 (tuple<>(), _VSTD::forward<_Tuple0>(__t0),
......@@ -1525,7 +1584,7 @@ pair<_T1, _T2>::pair(piecewise_construct_t,
15251584
15261585#if _LIBCPP_STD_VER > 14
15271586template <class _Tp>
1528_LIBCPP_INLINE_VAR constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
1587inline constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
15291588
15301589#define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
15311590
lib/libcxx/include/type_traits+312-650
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===------------------------ type_traits ---------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -455,58 +455,63 @@ using bool_constant = integral_constant<bool, __b>;
455455#define _LIBCPP_BOOL_CONSTANT(__b) integral_constant<bool,(__b)>
456456#endif
457457
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
458467typedef _LIBCPP_BOOL_CONSTANT(true) true_type;
459468typedef _LIBCPP_BOOL_CONSTANT(false) false_type;
460469
461470template <bool _Val>
462using _BoolConstant _LIBCPP_NODEBUG_TYPE = integral_constant<bool, _Val>;
471using _BoolConstant _LIBCPP_NODEBUG = integral_constant<bool, _Val>;
463472
464473template <bool> struct _MetaBase;
465474template <>
466475struct _MetaBase<true> {
467476 template <class _Tp, class _Up>
468 using _SelectImpl _LIBCPP_NODEBUG_TYPE = _Tp;
477 using _SelectImpl _LIBCPP_NODEBUG = _Tp;
469478 template <template <class...> class _FirstFn, template <class...> class, class ..._Args>
470 using _SelectApplyImpl _LIBCPP_NODEBUG_TYPE = _FirstFn<_Args...>;
479 using _SelectApplyImpl _LIBCPP_NODEBUG = _FirstFn<_Args...>;
471480 template <class _First, class...>
472 using _FirstImpl _LIBCPP_NODEBUG_TYPE = _First;
481 using _FirstImpl _LIBCPP_NODEBUG = _First;
473482 template <class, class _Second, class...>
474 using _SecondImpl _LIBCPP_NODEBUG_TYPE = _Second;
475 template <class _Tp = void>
476 using _EnableIfImpl _LIBCPP_NODEBUG_TYPE = _Tp;
483 using _SecondImpl _LIBCPP_NODEBUG = _Second;
477484 template <class _Result, class _First, class ..._Rest>
478 using _OrImpl _LIBCPP_NODEBUG_TYPE = typename _MetaBase<_First::value != true && sizeof...(_Rest) != 0>::template _OrImpl<_First, _Rest...>;
485 using _OrImpl _LIBCPP_NODEBUG = typename _MetaBase<_First::value != true && sizeof...(_Rest) != 0>::template _OrImpl<_First, _Rest...>;
479486};
480487
481488template <>
482489struct _MetaBase<false> {
483490 template <class _Tp, class _Up>
484 using _SelectImpl _LIBCPP_NODEBUG_TYPE = _Up;
491 using _SelectImpl _LIBCPP_NODEBUG = _Up;
485492 template <template <class...> class, template <class...> class _SecondFn, class ..._Args>
486 using _SelectApplyImpl _LIBCPP_NODEBUG_TYPE = _SecondFn<_Args...>;
493 using _SelectApplyImpl _LIBCPP_NODEBUG = _SecondFn<_Args...>;
487494 template <class _Result, class ...>
488 using _OrImpl _LIBCPP_NODEBUG_TYPE = _Result;
495 using _OrImpl _LIBCPP_NODEBUG = _Result;
489496};
490template <bool _Cond, class _Ret = void>
491using _EnableIf _LIBCPP_NODEBUG_TYPE = typename _MetaBase<_Cond>::template _EnableIfImpl<_Ret>;
492497template <bool _Cond, class _IfRes, class _ElseRes>
493using _If _LIBCPP_NODEBUG_TYPE = typename _MetaBase<_Cond>::template _SelectImpl<_IfRes, _ElseRes>;
498using _If _LIBCPP_NODEBUG = typename _MetaBase<_Cond>::template _SelectImpl<_IfRes, _ElseRes>;
494499template <class ..._Rest>
495using _Or _LIBCPP_NODEBUG_TYPE = typename _MetaBase< sizeof...(_Rest) != 0 >::template _OrImpl<false_type, _Rest...>;
500using _Or _LIBCPP_NODEBUG = typename _MetaBase< sizeof...(_Rest) != 0 >::template _OrImpl<false_type, _Rest...>;
496501template <class _Pred>
497502struct _Not : _BoolConstant<!_Pred::value> {};
498503template <class ..._Args>
499using _FirstType _LIBCPP_NODEBUG_TYPE = typename _MetaBase<(sizeof...(_Args) >= 1)>::template _FirstImpl<_Args...>;
504using _FirstType _LIBCPP_NODEBUG = typename _MetaBase<(sizeof...(_Args) >= 1)>::template _FirstImpl<_Args...>;
500505template <class ..._Args>
501using _SecondType _LIBCPP_NODEBUG_TYPE = typename _MetaBase<(sizeof...(_Args) >= 2)>::template _SecondImpl<_Args...>;
506using _SecondType _LIBCPP_NODEBUG = typename _MetaBase<(sizeof...(_Args) >= 2)>::template _SecondImpl<_Args...>;
502507
503508template <class ...> using __expand_to_true = true_type;
504509template <class ..._Pred>
505__expand_to_true<_EnableIf<_Pred::value>...> __and_helper(int);
510__expand_to_true<__enable_if_t<_Pred::value>...> __and_helper(int);
506511template <class ...>
507512false_type __and_helper(...);
508513template <class ..._Pred>
509using _And _LIBCPP_NODEBUG_TYPE = decltype(__and_helper<_Pred...>(0));
514using _And _LIBCPP_NODEBUG = decltype(__and_helper<_Pred...>(0));
510515
511516template <template <class...> class _Func, class ..._Args>
512517struct _Lazy : _Func<_Args...> {};
......@@ -519,7 +524,7 @@ template <template <class...> class, class ...>
519524false_type __sfinae_test_impl(...);
520525
521526template <template <class ...> class _Templ, class ..._Args>
522using _IsValidExpansion _LIBCPP_NODEBUG_TYPE = decltype(__sfinae_test_impl<_Templ, _Args...>(0));
527using _IsValidExpansion _LIBCPP_NODEBUG = decltype(__sfinae_test_impl<_Templ, _Args...>(0));
523528
524529template <class>
525530struct __void_t { typedef void type; };
......@@ -528,7 +533,7 @@ template <class _Tp>
528533struct __identity { typedef _Tp type; };
529534
530535template <class _Tp>
531using __identity_t _LIBCPP_NODEBUG_TYPE = typename __identity<_Tp>::type;
536using __identity_t _LIBCPP_NODEBUG = typename __identity<_Tp>::type;
532537
533538template <class _Tp, bool>
534539struct _LIBCPP_TEMPLATE_VIS __dependent_type : public _Tp {};
......@@ -543,59 +548,31 @@ template <class _If, class _Then>
543548template <bool _Bp, class _If, class _Then> using conditional_t = typename conditional<_Bp, _If, _Then>::type;
544549#endif
545550
546template <bool, class _Tp = void> struct _LIBCPP_TEMPLATE_VIS enable_if {};
547template <class _Tp> struct _LIBCPP_TEMPLATE_VIS enable_if<true, _Tp> {typedef _Tp type;};
548
549#if _LIBCPP_STD_VER > 11
550template <bool _Bp, class _Tp = void> using enable_if_t = typename enable_if<_Bp, _Tp>::type;
551#endif
552
553551// is_same
554552
555#if __has_keyword(__is_same)
556
557553template <class _Tp, class _Up>
558554struct _LIBCPP_TEMPLATE_VIS is_same : _BoolConstant<__is_same(_Tp, _Up)> { };
559555
560#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
556#if _LIBCPP_STD_VER > 14
561557template <class _Tp, class _Up>
562_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_same_v = __is_same(_Tp, _Up);
558inline constexpr bool is_same_v = __is_same(_Tp, _Up);
563559#endif
564560
565#else
566
567template <class _Tp, class _Up> struct _LIBCPP_TEMPLATE_VIS is_same : public false_type {};
568template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_same<_Tp, _Tp> : public true_type {};
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).
569567
570#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
571568template <class _Tp, class _Up>
572_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_same_v
573 = is_same<_Tp, _Up>::value;
574#endif
575
576#endif // __is_same
569using _IsSame = _BoolConstant<__is_same(_Tp, _Up)>;
577570
578571template <class _Tp, class _Up>
579using _IsSame = _BoolConstant<
580#ifdef __clang__
581 __is_same(_Tp, _Up)
582#else
583 is_same<_Tp, _Up>::value
584#endif
585>;
586
587template <class _Tp, class _Up>
588using _IsNotSame = _BoolConstant<
589#ifdef __clang__
590 !__is_same(_Tp, _Up)
591#else
592 !is_same<_Tp, _Up>::value
593#endif
594>;
595
572using _IsNotSame = _BoolConstant<!__is_same(_Tp, _Up)>;
596573
597574template <class _Tp>
598using __test_for_primary_template = _EnableIf<
575using __test_for_primary_template = __enable_if_t<
599576 _IsSame<_Tp, typename _Tp::__primary_template>::value
600577 >;
601578template <class _Tp>
......@@ -603,9 +580,9 @@ using __is_primary_template = _IsValidExpansion<
603580 __test_for_primary_template, _Tp
604581 >;
605582
606struct __two {char __lx[2];};
583// helper class
607584
608// helper class:
585struct __two {char __lx[2];};
609586
610587// is_const
611588
......@@ -614,9 +591,9 @@ struct __two {char __lx[2];};
614591template <class _Tp>
615592struct _LIBCPP_TEMPLATE_VIS is_const : _BoolConstant<__is_const(_Tp)> { };
616593
617#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
594#if _LIBCPP_STD_VER > 14
618595template <class _Tp>
619_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_const_v = __is_const(_Tp);
596inline constexpr bool is_const_v = __is_const(_Tp);
620597#endif
621598
622599#else
......@@ -624,10 +601,9 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_const_v = __is_const(_Tp);
624601template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_const : public false_type {};
625602template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_const<_Tp const> : public true_type {};
626603
627#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
604#if _LIBCPP_STD_VER > 14
628605template <class _Tp>
629_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_const_v
630 = is_const<_Tp>::value;
606inline constexpr bool is_const_v = is_const<_Tp>::value;
631607#endif
632608
633609#endif // __has_keyword(__is_const)
......@@ -639,9 +615,9 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_const_v
639615template <class _Tp>
640616struct _LIBCPP_TEMPLATE_VIS is_volatile : _BoolConstant<__is_volatile(_Tp)> { };
641617
642#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
618#if _LIBCPP_STD_VER > 14
643619template <class _Tp>
644_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_volatile_v = __is_volatile(_Tp);
620inline constexpr bool is_volatile_v = __is_volatile(_Tp);
645621#endif
646622
647623#else
......@@ -649,10 +625,9 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_volatile_v = __is_volatile(_Tp);
649625template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_volatile : public false_type {};
650626template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_volatile<_Tp volatile> : public true_type {};
651627
652#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
628#if _LIBCPP_STD_VER > 14
653629template <class _Tp>
654_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_volatile_v
655 = is_volatile<_Tp>::value;
630inline constexpr bool is_volatile_v = is_volatile<_Tp>::value;
656631#endif
657632
658633#endif // __has_keyword(__is_volatile)
......@@ -727,9 +702,9 @@ template <class _Tp> using remove_cv_t = typename remove_cv<_Tp>::type;
727702template <class _Tp>
728703struct _LIBCPP_TEMPLATE_VIS is_void : _BoolConstant<__is_void(_Tp)> { };
729704
730#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
705#if _LIBCPP_STD_VER > 14
731706template <class _Tp>
732_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_void_v = __is_void(_Tp);
707inline constexpr bool is_void_v = __is_void(_Tp);
733708#endif
734709
735710#else
......@@ -737,10 +712,9 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_void_v = __is_void(_Tp);
737712template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_void
738713 : public is_same<typename remove_cv<_Tp>::type, void> {};
739714
740#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
715#if _LIBCPP_STD_VER > 14
741716template <class _Tp>
742_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_void_v
743 = is_void<_Tp>::value;
717inline constexpr bool is_void_v = is_void<_Tp>::value;
744718#endif
745719
746720#endif // __has_keyword(__is_void)
......@@ -757,10 +731,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS __is_nullptr_t
757731template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_null_pointer
758732 : public __is_nullptr_t_impl<typename remove_cv<_Tp>::type> {};
759733
760#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
734#if _LIBCPP_STD_VER > 14
761735template <class _Tp>
762_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_null_pointer_v
763 = is_null_pointer<_Tp>::value;
736inline constexpr bool is_null_pointer_v = is_null_pointer<_Tp>::value;
764737#endif
765738#endif // _LIBCPP_STD_VER > 11
766739
......@@ -773,7 +746,7 @@ struct _LIBCPP_TEMPLATE_VIS is_integral : _BoolConstant<__is_integral(_Tp)> { };
773746
774747#if _LIBCPP_STD_VER > 14
775748template <class _Tp>
776_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_integral_v = __is_integral(_Tp);
749inline constexpr bool is_integral_v = __is_integral(_Tp);
777750#endif
778751
779752#else
......@@ -781,16 +754,13 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_integral_v = __is_integral(_Tp);
781754template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_integral
782755 : public _BoolConstant<__libcpp_is_integral<typename remove_cv<_Tp>::type>::value> {};
783756
784#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
757#if _LIBCPP_STD_VER > 14
785758template <class _Tp>
786_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_integral_v
787 = is_integral<_Tp>::value;
759inline constexpr bool is_integral_v = is_integral<_Tp>::value;
788760#endif
789761
790762#endif // __has_keyword(__is_integral)
791763
792// __libcpp_is_signed_integer, __libcpp_is_unsigned_integer
793
794764// [basic.fundamental] defines five standard signed integer types;
795765// __int128_t is an extended signed integer type.
796766// The signed and unsigned integer types, plus bool and the
......@@ -817,6 +787,7 @@ template <> struct __libcpp_is_unsigned_integer<__uint128_t> : public tru
817787#endif
818788
819789// is_floating_point
790// <concepts> implements __libcpp_floating_point
820791
821792template <class _Tp> struct __libcpp_is_floating_point : public false_type {};
822793template <> struct __libcpp_is_floating_point<float> : public true_type {};
......@@ -826,10 +797,9 @@ template <> struct __libcpp_is_floating_point<long double> : public tru
826797template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_floating_point
827798 : public __libcpp_is_floating_point<typename remove_cv<_Tp>::type> {};
828799
829#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
800#if _LIBCPP_STD_VER > 14
830801template <class _Tp>
831_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_floating_point_v
832 = is_floating_point<_Tp>::value;
802inline constexpr bool is_floating_point_v = is_floating_point<_Tp>::value;
833803#endif
834804
835805// is_array
......@@ -839,9 +809,9 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_floating_point_v
839809template <class _Tp>
840810struct _LIBCPP_TEMPLATE_VIS is_array : _BoolConstant<__is_array(_Tp)> { };
841811
842#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
812#if _LIBCPP_STD_VER > 14
843813template <class _Tp>
844_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_array_v = __is_array(_Tp);
814inline constexpr bool is_array_v = __is_array(_Tp);
845815#endif
846816
847817#else
......@@ -853,27 +823,25 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_array<_Tp[]>
853823template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS is_array<_Tp[_Np]>
854824 : public true_type {};
855825
856#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
826#if _LIBCPP_STD_VER > 14
857827template <class _Tp>
858_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_array_v
859 = is_array<_Tp>::value;
828inline constexpr bool is_array_v = is_array<_Tp>::value;
860829#endif
861830
862831#endif // __has_keyword(__is_array)
863832
864833// is_pointer
865834
866// Before Clang 11 / AppleClang 12.0.5, __is_pointer didn't work for Objective-C types.
835// Before AppleClang 12.0.5, __is_pointer didn't work for Objective-C types.
867836#if __has_keyword(__is_pointer) && \
868 !(defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER < 1100) && \
869837 !(defined(_LIBCPP_APPLE_CLANG_VER) && _LIBCPP_APPLE_CLANG_VER < 1205)
870838
871839template<class _Tp>
872840struct _LIBCPP_TEMPLATE_VIS is_pointer : _BoolConstant<__is_pointer(_Tp)> { };
873841
874#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
842#if _LIBCPP_STD_VER > 14
875843template <class _Tp>
876_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_pointer_v = __is_pointer(_Tp);
844inline constexpr bool is_pointer_v = __is_pointer(_Tp);
877845#endif
878846
879847#else // __has_keyword(__is_pointer)
......@@ -892,10 +860,9 @@ template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __unsafe_unretai
892860template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_pointer
893861 : public __libcpp_is_pointer<typename __libcpp_remove_objc_qualifiers<typename remove_cv<_Tp>::type>::type> {};
894862
895#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
863#if _LIBCPP_STD_VER > 14
896864template <class _Tp>
897_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_pointer_v
898 = is_pointer<_Tp>::value;
865inline constexpr bool is_pointer_v = is_pointer<_Tp>::value;
899866#endif
900867
901868#endif // __has_keyword(__is_pointer)
......@@ -915,15 +882,13 @@ struct _LIBCPP_TEMPLATE_VIS is_rvalue_reference : _BoolConstant<__is_rvalue_refe
915882template<class _Tp>
916883struct _LIBCPP_TEMPLATE_VIS is_reference : _BoolConstant<__is_reference(_Tp)> { };
917884
918#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
885#if _LIBCPP_STD_VER > 14
919886template <class _Tp>
920_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_reference_v = __is_reference(_Tp);
921
887inline constexpr bool is_reference_v = __is_reference(_Tp);
922888template <class _Tp>
923_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_lvalue_reference_v = __is_lvalue_reference(_Tp);
924
889inline constexpr bool is_lvalue_reference_v = __is_lvalue_reference(_Tp);
925890template <class _Tp>
926_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_rvalue_reference_v = __is_rvalue_reference(_Tp);
891inline constexpr bool is_rvalue_reference_v = __is_rvalue_reference(_Tp);
927892#endif
928893
929894#else // __has_keyword(__is_lvalue_reference) && etc...
......@@ -938,18 +903,15 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_reference : public fa
938903template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_reference<_Tp&> : public true_type {};
939904template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_reference<_Tp&&> : public true_type {};
940905
941#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
906#if _LIBCPP_STD_VER > 14
942907template <class _Tp>
943_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_reference_v
944 = is_reference<_Tp>::value;
908inline constexpr bool is_reference_v = is_reference<_Tp>::value;
945909
946910template <class _Tp>
947_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_lvalue_reference_v
948 = is_lvalue_reference<_Tp>::value;
911inline constexpr bool is_lvalue_reference_v = is_lvalue_reference<_Tp>::value;
949912
950913template <class _Tp>
951_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_rvalue_reference_v
952 = is_rvalue_reference<_Tp>::value;
914inline constexpr bool is_rvalue_reference_v = is_rvalue_reference<_Tp>::value;
953915#endif
954916
955917#endif // __has_keyword(__is_lvalue_reference) && etc...
......@@ -969,10 +931,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_union
969931
970932#endif
971933
972#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
934#if _LIBCPP_STD_VER > 14
973935template <class _Tp>
974_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_union_v
975 = is_union<_Tp>::value;
936inline constexpr bool is_union_v = is_union<_Tp>::value;
976937#endif
977938
978939// is_class
......@@ -995,10 +956,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_class
995956
996957#endif
997958
998#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
959#if _LIBCPP_STD_VER > 14
999960template <class _Tp>
1000_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_class_v
1001 = is_class<_Tp>::value;
961inline constexpr bool is_class_v = is_class<_Tp>::value;
1002962#endif
1003963
1004964// is_function
......@@ -1013,10 +973,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_function
1013973 > {};
1014974
1015975
1016#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
976#if _LIBCPP_STD_VER > 14
1017977template <class _Tp>
1018_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_function_v
1019 = is_function<_Tp>::value;
978inline constexpr bool is_function_v = is_function<_Tp>::value;
1020979#endif
1021980
1022981template <class _Tp> struct __libcpp_is_member_pointer {
......@@ -1040,10 +999,9 @@ template<class _Tp>
1040999struct _LIBCPP_TEMPLATE_VIS is_member_function_pointer
10411000 : _BoolConstant<__is_member_function_pointer(_Tp)> { };
10421001
1043#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1002#if _LIBCPP_STD_VER > 14
10441003template <class _Tp>
1045_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_member_function_pointer_v
1046 = __is_member_function_pointer(_Tp);
1004inline constexpr bool is_member_function_pointer_v = __is_member_function_pointer(_Tp);
10471005#endif
10481006
10491007#else // __has_keyword(__is_member_function_pointer)
......@@ -1051,10 +1009,9 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_member_function_pointer_v
10511009template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_member_function_pointer
10521010 : public _BoolConstant< __libcpp_is_member_pointer<typename remove_cv<_Tp>::type>::__is_func > {};
10531011
1054#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1012#if _LIBCPP_STD_VER > 14
10551013template <class _Tp>
1056_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_member_function_pointer_v
1057 = is_member_function_pointer<_Tp>::value;
1014inline constexpr bool is_member_function_pointer_v = is_member_function_pointer<_Tp>::value;
10581015#endif
10591016
10601017#endif // __has_keyword(__is_member_function_pointer)
......@@ -1066,9 +1023,9 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_member_function_pointer_v
10661023template<class _Tp>
10671024struct _LIBCPP_TEMPLATE_VIS is_member_pointer : _BoolConstant<__is_member_pointer(_Tp)> { };
10681025
1069#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1026#if _LIBCPP_STD_VER > 14
10701027template <class _Tp>
1071_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_member_pointer_v = __is_member_pointer(_Tp);
1028inline constexpr bool is_member_pointer_v = __is_member_pointer(_Tp);
10721029#endif
10731030
10741031#else // __has_keyword(__is_member_pointer)
......@@ -1076,10 +1033,9 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_member_pointer_v = __is_member_poin
10761033template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_member_pointer
10771034 : public _BoolConstant< __libcpp_is_member_pointer<typename remove_cv<_Tp>::type>::__is_member > {};
10781035
1079#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1036#if _LIBCPP_STD_VER > 14
10801037template <class _Tp>
1081_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_member_pointer_v
1082 = is_member_pointer<_Tp>::value;
1038inline constexpr bool is_member_pointer_v = is_member_pointer<_Tp>::value;
10831039#endif
10841040
10851041#endif // __has_keyword(__is_member_pointer)
......@@ -1092,10 +1048,9 @@ template<class _Tp>
10921048struct _LIBCPP_TEMPLATE_VIS is_member_object_pointer
10931049 : _BoolConstant<__is_member_object_pointer(_Tp)> { };
10941050
1095#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1051#if _LIBCPP_STD_VER > 14
10961052template <class _Tp>
1097_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_member_object_pointer_v
1098 = __is_member_object_pointer(_Tp);
1053inline constexpr bool is_member_object_pointer_v = __is_member_object_pointer(_Tp);
10991054#endif
11001055
11011056#else // __has_keyword(__is_member_object_pointer)
......@@ -1103,10 +1058,9 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_member_object_pointer_v
11031058template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_member_object_pointer
11041059 : public _BoolConstant< __libcpp_is_member_pointer<typename remove_cv<_Tp>::type>::__is_obj > {};
11051060
1106#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1061#if _LIBCPP_STD_VER > 14
11071062template <class _Tp>
1108_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_member_object_pointer_v
1109 = is_member_object_pointer<_Tp>::value;
1063inline constexpr bool is_member_object_pointer_v = is_member_object_pointer<_Tp>::value;
11101064#endif
11111065
11121066#endif // __has_keyword(__is_member_object_pointer)
......@@ -1118,9 +1072,9 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_member_object_pointer_v
11181072template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_enum
11191073 : public integral_constant<bool, __is_enum(_Tp)> {};
11201074
1121#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1075#if _LIBCPP_STD_VER > 14
11221076template <class _Tp>
1123_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_enum_v = __is_enum(_Tp);
1077inline constexpr bool is_enum_v = __is_enum(_Tp);
11241078#endif
11251079
11261080#else
......@@ -1137,10 +1091,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_enum
11371091 !is_class<_Tp>::value &&
11381092 !is_function<_Tp>::value > {};
11391093
1140#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1094#if _LIBCPP_STD_VER > 14
11411095template <class _Tp>
1142_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_enum_v
1143 = is_enum<_Tp>::value;
1096inline constexpr bool is_enum_v = is_enum<_Tp>::value;
11441097#endif
11451098
11461099#endif // __has_feature(is_enum) || defined(_LIBCPP_COMPILER_GCC)
......@@ -1152,10 +1105,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_arithmetic
11521105 : public integral_constant<bool, is_integral<_Tp>::value ||
11531106 is_floating_point<_Tp>::value> {};
11541107
1155#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1108#if _LIBCPP_STD_VER > 14
11561109template <class _Tp>
1157_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_arithmetic_v
1158 = is_arithmetic<_Tp>::value;
1110inline constexpr bool is_arithmetic_v = is_arithmetic<_Tp>::value;
11591111#endif
11601112
11611113// is_fundamental
......@@ -1169,9 +1121,9 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_arithmetic_v
11691121template<class _Tp>
11701122struct _LIBCPP_TEMPLATE_VIS is_fundamental : _BoolConstant<__is_fundamental(_Tp)> { };
11711123
1172#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1124#if _LIBCPP_STD_VER > 14
11731125template <class _Tp>
1174_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_fundamental_v = __is_fundamental(_Tp);
1126inline constexpr bool is_fundamental_v = __is_fundamental(_Tp);
11751127#endif
11761128
11771129#else // __has_keyword(__is_fundamental)
......@@ -1181,10 +1133,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_fundamental
11811133 __is_nullptr_t<_Tp>::value ||
11821134 is_arithmetic<_Tp>::value> {};
11831135
1184#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1136#if _LIBCPP_STD_VER > 14
11851137template <class _Tp>
1186_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_fundamental_v
1187 = is_fundamental<_Tp>::value;
1138inline constexpr bool is_fundamental_v = is_fundamental<_Tp>::value;
11881139#endif
11891140
11901141#endif // __has_keyword(__is_fundamental)
......@@ -1197,9 +1148,9 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_fundamental_v
11971148template<class _Tp>
11981149struct _LIBCPP_TEMPLATE_VIS is_scalar : _BoolConstant<__is_scalar(_Tp)> { };
11991150
1200#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1151#if _LIBCPP_STD_VER > 14
12011152template <class _Tp>
1202_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_scalar_v = __is_scalar(_Tp);
1153inline constexpr bool is_scalar_v = __is_scalar(_Tp);
12031154#endif
12041155
12051156#else // __has_keyword(__is_scalar)
......@@ -1219,10 +1170,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_scalar
12191170
12201171template <> struct _LIBCPP_TEMPLATE_VIS is_scalar<nullptr_t> : public true_type {};
12211172
1222#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1173#if _LIBCPP_STD_VER > 14
12231174template <class _Tp>
1224_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_scalar_v
1225 = is_scalar<_Tp>::value;
1175inline constexpr bool is_scalar_v = is_scalar<_Tp>::value;
12261176#endif
12271177
12281178#endif // __has_keyword(__is_scalar)
......@@ -1234,9 +1184,9 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_scalar_v
12341184template<class _Tp>
12351185struct _LIBCPP_TEMPLATE_VIS is_object : _BoolConstant<__is_object(_Tp)> { };
12361186
1237#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1187#if _LIBCPP_STD_VER > 14
12381188template <class _Tp>
1239_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_object_v = __is_object(_Tp);
1189inline constexpr bool is_object_v = __is_object(_Tp);
12401190#endif
12411191
12421192#else // __has_keyword(__is_object)
......@@ -1247,10 +1197,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_object
12471197 is_union<_Tp>::value ||
12481198 is_class<_Tp>::value > {};
12491199
1250#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1200#if _LIBCPP_STD_VER > 14
12511201template <class _Tp>
1252_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_object_v
1253 = is_object<_Tp>::value;
1202inline constexpr bool is_object_v = is_object<_Tp>::value;
12541203#endif
12551204
12561205#endif // __has_keyword(__is_object)
......@@ -1263,9 +1212,9 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_object_v
12631212template<class _Tp>
12641213struct _LIBCPP_TEMPLATE_VIS is_compound : _BoolConstant<__is_compound(_Tp)> { };
12651214
1266#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1215#if _LIBCPP_STD_VER > 14
12671216template <class _Tp>
1268_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_compound_v = __is_compound(_Tp);
1217inline constexpr bool is_compound_v = __is_compound(_Tp);
12691218#endif
12701219
12711220#else // __has_keyword(__is_compound)
......@@ -1273,10 +1222,9 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_compound_v = __is_compound(_Tp);
12731222template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_compound
12741223 : public integral_constant<bool, !is_fundamental<_Tp>::value> {};
12751224
1276#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1225#if _LIBCPP_STD_VER > 14
12771226template <class _Tp>
1278_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_compound_v
1279 = is_compound<_Tp>::value;
1227inline constexpr bool is_compound_v = is_compound<_Tp>::value;
12801228#endif
12811229
12821230#endif // __has_keyword(__is_compound)
......@@ -1296,7 +1244,7 @@ struct __is_referenceable : integral_constant<bool,
12961244// add_const
12971245
12981246template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_const {
1299 typedef _LIBCPP_NODEBUG_TYPE const _Tp type;
1247 typedef _LIBCPP_NODEBUG const _Tp type;
13001248};
13011249
13021250#if _LIBCPP_STD_VER > 11
......@@ -1306,7 +1254,7 @@ template <class _Tp> using add_const_t = typename add_const<_Tp>::type;
13061254// add_volatile
13071255
13081256template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_volatile {
1309 typedef _LIBCPP_NODEBUG_TYPE volatile _Tp type;
1257 typedef _LIBCPP_NODEBUG volatile _Tp type;
13101258};
13111259
13121260#if _LIBCPP_STD_VER > 11
......@@ -1315,7 +1263,7 @@ template <class _Tp> using add_volatile_t = typename add_volatile<_Tp>::type;
13151263
13161264// add_cv
13171265template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_cv {
1318 typedef _LIBCPP_NODEBUG_TYPE const volatile _Tp type;
1266 typedef _LIBCPP_NODEBUG const volatile _Tp type;
13191267};
13201268
13211269#if _LIBCPP_STD_VER > 11
......@@ -1331,9 +1279,9 @@ struct _LIBCPP_TEMPLATE_VIS remove_reference { typedef __remove_reference(_Tp) t
13311279
13321280#else // __has_keyword(__remove_reference)
13331281
1334template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference {typedef _LIBCPP_NODEBUG_TYPE _Tp type;};
1335template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference<_Tp&> {typedef _LIBCPP_NODEBUG_TYPE _Tp type;};
1336template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference<_Tp&&> {typedef _LIBCPP_NODEBUG_TYPE _Tp type;};
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;};
13371285
13381286#if _LIBCPP_STD_VER > 11
13391287template <class _Tp> using remove_reference_t = typename remove_reference<_Tp>::type;
......@@ -1343,21 +1291,21 @@ template <class _Tp> using remove_reference_t = typename remove_reference<_Tp>::
13431291
13441292// add_lvalue_reference
13451293
1346template <class _Tp, bool = __is_referenceable<_Tp>::value> struct __add_lvalue_reference_impl { typedef _LIBCPP_NODEBUG_TYPE _Tp type; };
1347template <class _Tp > struct __add_lvalue_reference_impl<_Tp, true> { typedef _LIBCPP_NODEBUG_TYPE _Tp& type; };
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; };
13481296
13491297template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_lvalue_reference
1350{typedef _LIBCPP_NODEBUG_TYPE typename __add_lvalue_reference_impl<_Tp>::type type;};
1298{typedef _LIBCPP_NODEBUG typename __add_lvalue_reference_impl<_Tp>::type type;};
13511299
13521300#if _LIBCPP_STD_VER > 11
13531301template <class _Tp> using add_lvalue_reference_t = typename add_lvalue_reference<_Tp>::type;
13541302#endif
13551303
1356template <class _Tp, bool = __is_referenceable<_Tp>::value> struct __add_rvalue_reference_impl { typedef _LIBCPP_NODEBUG_TYPE _Tp type; };
1357template <class _Tp > struct __add_rvalue_reference_impl<_Tp, true> { typedef _LIBCPP_NODEBUG_TYPE _Tp&& type; };
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; };
13581306
13591307template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_rvalue_reference
1360{typedef _LIBCPP_NODEBUG_TYPE typename __add_rvalue_reference_impl<_Tp>::type type;};
1308{typedef _LIBCPP_NODEBUG typename __add_rvalue_reference_impl<_Tp>::type type;};
13611309
13621310#if _LIBCPP_STD_VER > 11
13631311template <class _Tp> using add_rvalue_reference_t = typename add_rvalue_reference<_Tp>::type;
......@@ -1378,17 +1326,17 @@ declval() _NOEXCEPT;
13781326
13791327template <class _Tp>
13801328struct __uncvref {
1381 typedef _LIBCPP_NODEBUG_TYPE typename remove_cv<typename remove_reference<_Tp>::type>::type type;
1329 typedef _LIBCPP_NODEBUG typename remove_cv<typename remove_reference<_Tp>::type>::type type;
13821330};
13831331
13841332template <class _Tp>
13851333struct __unconstref {
1386 typedef _LIBCPP_NODEBUG_TYPE typename remove_const<typename remove_reference<_Tp>::type>::type type;
1334 typedef _LIBCPP_NODEBUG typename remove_const<typename remove_reference<_Tp>::type>::type type;
13871335};
13881336
13891337#ifndef _LIBCPP_CXX03_LANG
13901338template <class _Tp>
1391using __uncvref_t _LIBCPP_NODEBUG_TYPE = typename __uncvref<_Tp>::type;
1339using __uncvref_t _LIBCPP_NODEBUG = typename __uncvref<_Tp>::type;
13921340#endif
13931341
13941342// __is_same_uncvref
......@@ -1413,11 +1361,11 @@ struct __any
14131361
14141362// remove_pointer
14151363
1416template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer {typedef _LIBCPP_NODEBUG_TYPE _Tp type;};
1417template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp*> {typedef _LIBCPP_NODEBUG_TYPE _Tp type;};
1418template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp* const> {typedef _LIBCPP_NODEBUG_TYPE _Tp type;};
1419template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp* volatile> {typedef _LIBCPP_NODEBUG_TYPE _Tp type;};
1420template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp* const volatile> {typedef _LIBCPP_NODEBUG_TYPE _Tp type;};
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;};
14211369
14221370#if _LIBCPP_STD_VER > 11
14231371template <class _Tp> using remove_pointer_t = typename remove_pointer<_Tp>::type;
......@@ -1429,12 +1377,12 @@ template <class _Tp,
14291377 bool = __is_referenceable<_Tp>::value ||
14301378 _IsSame<typename remove_cv<_Tp>::type, void>::value>
14311379struct __add_pointer_impl
1432 {typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tp>::type* type;};
1380 {typedef _LIBCPP_NODEBUG typename remove_reference<_Tp>::type* type;};
14331381template <class _Tp> struct __add_pointer_impl<_Tp, false>
1434 {typedef _LIBCPP_NODEBUG_TYPE _Tp type;};
1382 {typedef _LIBCPP_NODEBUG _Tp type;};
14351383
14361384template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_pointer
1437 {typedef _LIBCPP_NODEBUG_TYPE typename __add_pointer_impl<_Tp>::type type;};
1385 {typedef _LIBCPP_NODEBUG typename __add_pointer_impl<_Tp>::type type;};
14381386
14391387#if _LIBCPP_STD_VER > 11
14401388template <class _Tp> using add_pointer_t = typename add_pointer<_Tp>::type;
......@@ -1448,16 +1396,14 @@ template<class _Tp> using type_identity_t = typename type_identity<_Tp>::type;
14481396
14491397// is_signed
14501398
1451// Before Clang 10, __is_signed didn't work for floating-point types or enums.
1452#if __has_keyword(__is_signed) && \
1453 !(defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER < 1000)
1399#if __has_keyword(__is_signed)
14541400
14551401template<class _Tp>
14561402struct _LIBCPP_TEMPLATE_VIS is_signed : _BoolConstant<__is_signed(_Tp)> { };
14571403
1458#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1404#if _LIBCPP_STD_VER > 14
14591405template <class _Tp>
1460_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_signed_v = __is_signed(_Tp);
1406inline constexpr bool is_signed_v = __is_signed(_Tp);
14611407#endif
14621408
14631409#else // __has_keyword(__is_signed)
......@@ -1475,10 +1421,9 @@ template <class _Tp> struct __libcpp_is_signed<_Tp, false> : public false_type {
14751421
14761422template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_signed : public __libcpp_is_signed<_Tp> {};
14771423
1478#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1424#if _LIBCPP_STD_VER > 14
14791425template <class _Tp>
1480_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_signed_v
1481 = is_signed<_Tp>::value;
1426inline constexpr bool is_signed_v = is_signed<_Tp>::value;
14821427#endif
14831428
14841429#endif // __has_keyword(__is_signed)
......@@ -1494,9 +1439,9 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_signed_v
14941439template<class _Tp>
14951440struct _LIBCPP_TEMPLATE_VIS is_unsigned : _BoolConstant<__is_unsigned(_Tp)> { };
14961441
1497#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1442#if _LIBCPP_STD_VER > 14
14981443template <class _Tp>
1499_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_unsigned_v = __is_unsigned(_Tp);
1444inline constexpr bool is_unsigned_v = __is_unsigned(_Tp);
15001445#endif
15011446
15021447#else // __has_keyword(__is_unsigned)
......@@ -1514,10 +1459,9 @@ template <class _Tp> struct __libcpp_is_unsigned<_Tp, false> : public false_type
15141459
15151460template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_unsigned : public __libcpp_is_unsigned<_Tp> {};
15161461
1517#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1462#if _LIBCPP_STD_VER > 14
15181463template <class _Tp>
1519_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_unsigned_v
1520 = is_unsigned<_Tp>::value;
1464inline constexpr bool is_unsigned_v = is_unsigned<_Tp>::value;
15211465#endif
15221466
15231467#endif // __has_keyword(__is_unsigned)
......@@ -1531,10 +1475,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS rank<_Tp[]>
15311475template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS rank<_Tp[_Np]>
15321476 : public integral_constant<size_t, rank<_Tp>::value + 1> {};
15331477
1534#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1478#if _LIBCPP_STD_VER > 14
15351479template <class _Tp>
1536_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR size_t rank_v
1537 = rank<_Tp>::value;
1480inline constexpr size_t rank_v = rank<_Tp>::value;
15381481#endif
15391482
15401483// extent
......@@ -1545,9 +1488,9 @@ template<class _Tp, size_t _Dim = 0>
15451488struct _LIBCPP_TEMPLATE_VIS extent
15461489 : integral_constant<size_t, __array_extent(_Tp, _Dim)> { };
15471490
1548#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1491#if _LIBCPP_STD_VER > 14
15491492template <class _Tp, unsigned _Ip = 0>
1550_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR size_t extent_v = __array_extent(_Tp, _Ip);
1493inline constexpr size_t extent_v = __array_extent(_Tp, _Ip);
15511494#endif
15521495
15531496#else // __has_keyword(__array_extent)
......@@ -1563,10 +1506,9 @@ template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS extent<_Tp[_Np], 0>
15631506template <class _Tp, size_t _Np, unsigned _Ip> struct _LIBCPP_TEMPLATE_VIS extent<_Tp[_Np], _Ip>
15641507 : public integral_constant<size_t, extent<_Tp, _Ip-1>::value> {};
15651508
1566#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1509#if _LIBCPP_STD_VER > 14
15671510template <class _Tp, unsigned _Ip = 0>
1568_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR size_t extent_v
1569 = extent<_Tp, _Ip>::value;
1511inline constexpr size_t extent_v = extent<_Tp, _Ip>::value;
15701512#endif
15711513
15721514#endif // __has_keyword(__array_extent)
......@@ -1604,7 +1546,7 @@ template <class> struct _LIBCPP_TEMPLATE_VIS is_bounded_array
16041546template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS is_bounded_array<_Tp[_Np]> : true_type {};
16051547
16061548template <class _Tp>
1607_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR
1549inline constexpr
16081550bool is_bounded_array_v = is_bounded_array<_Tp>::value;
16091551
16101552// is_unbounded_array
......@@ -1613,7 +1555,7 @@ template <class> struct _LIBCPP_TEMPLATE_VIS is_unbounded_array : fal
16131555template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_unbounded_array<_Tp[]> : true_type {};
16141556
16151557template <class _Tp>
1616_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR
1558inline constexpr
16171559bool is_unbounded_array_v = is_unbounded_array<_Tp>::value;
16181560#endif
16191561
......@@ -1621,13 +1563,13 @@ bool is_unbounded_array_v = is_unbounded_array<_Tp>::value;
16211563
16221564template <class _Up, bool>
16231565struct __decay {
1624 typedef _LIBCPP_NODEBUG_TYPE typename remove_cv<_Up>::type type;
1566 typedef _LIBCPP_NODEBUG typename remove_cv<_Up>::type type;
16251567};
16261568
16271569template <class _Up>
16281570struct __decay<_Up, true> {
16291571public:
1630 typedef _LIBCPP_NODEBUG_TYPE typename conditional
1572 typedef _LIBCPP_NODEBUG typename conditional
16311573 <
16321574 is_array<_Up>::value,
16331575 typename remove_extent<_Up>::type*,
......@@ -1644,9 +1586,9 @@ template <class _Tp>
16441586struct _LIBCPP_TEMPLATE_VIS decay
16451587{
16461588private:
1647 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tp>::type _Up;
1589 typedef _LIBCPP_NODEBUG typename remove_reference<_Tp>::type _Up;
16481590public:
1649 typedef _LIBCPP_NODEBUG_TYPE typename __decay<_Up, __is_referenceable<_Up>::value>::type type;
1591 typedef _LIBCPP_NODEBUG typename __decay<_Up, __is_referenceable<_Up>::value>::type type;
16501592};
16511593
16521594#if _LIBCPP_STD_VER > 11
......@@ -1658,10 +1600,9 @@ template <class _Tp> using decay_t = typename decay<_Tp>::type;
16581600template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_abstract
16591601 : public integral_constant<bool, __is_abstract(_Tp)> {};
16601602
1661#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1603#if _LIBCPP_STD_VER > 14
16621604template <class _Tp>
1663_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_abstract_v
1664 = is_abstract<_Tp>::value;
1605inline constexpr bool is_abstract_v = is_abstract<_Tp>::value;
16651606#endif
16661607
16671608// is_final
......@@ -1674,25 +1615,21 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS
16741615is_final : public integral_constant<bool, __is_final(_Tp)> {};
16751616#endif
16761617
1677#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1618#if _LIBCPP_STD_VER > 14
16781619template <class _Tp>
1679_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_final_v
1680 = is_final<_Tp>::value;
1620inline constexpr bool is_final_v = is_final<_Tp>::value;
16811621#endif
16821622
16831623// is_aggregate
1684#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_IS_AGGREGATE)
1624#if _LIBCPP_STD_VER > 14
16851625
16861626template <class _Tp> struct _LIBCPP_TEMPLATE_VIS
16871627is_aggregate : public integral_constant<bool, __is_aggregate(_Tp)> {};
16881628
1689#if !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
16901629template <class _Tp>
1691_LIBCPP_INLINE_VAR constexpr bool is_aggregate_v
1692 = is_aggregate<_Tp>::value;
1693#endif
1630inline constexpr bool is_aggregate_v = is_aggregate<_Tp>::value;
16941631
1695#endif // _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_IS_AGGREGATE)
1632#endif // _LIBCPP_STD_VER > 14
16961633
16971634// is_base_of
16981635
......@@ -1700,10 +1637,9 @@ template <class _Bp, class _Dp>
17001637struct _LIBCPP_TEMPLATE_VIS is_base_of
17011638 : public integral_constant<bool, __is_base_of(_Bp, _Dp)> {};
17021639
1703#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1640#if _LIBCPP_STD_VER > 14
17041641template <class _Bp, class _Dp>
1705_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_base_of_v
1706 = is_base_of<_Bp, _Dp>::value;
1642inline constexpr bool is_base_of_v = is_base_of<_Bp, _Dp>::value;
17071643#endif
17081644
17091645// __is_core_convertible
......@@ -1797,10 +1733,9 @@ template <class _T1, class _T2> struct _LIBCPP_TEMPLATE_VIS is_convertible
17971733
17981734#endif // __has_feature(is_convertible_to)
17991735
1800#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1736#if _LIBCPP_STD_VER > 14
18011737template <class _From, class _To>
1802_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_convertible_v
1803 = is_convertible<_From, _To>::value;
1738inline constexpr bool is_convertible_v = is_convertible<_From, _To>::value;
18041739#endif
18051740
18061741// is_nothrow_convertible
......@@ -1860,10 +1795,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_empty : public __libcpp_empt
18601795
18611796#endif // __has_feature(is_empty)
18621797
1863#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1798#if _LIBCPP_STD_VER > 14
18641799template <class _Tp>
1865_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_empty_v
1866 = is_empty<_Tp>::value;
1800inline constexpr bool is_empty_v = is_empty<_Tp>::value;
18671801#endif
18681802
18691803// is_polymorphic
......@@ -1886,10 +1820,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_polymorphic
18861820
18871821#endif // __has_feature(is_polymorphic)
18881822
1889#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1823#if _LIBCPP_STD_VER > 14
18901824template <class _Tp>
1891_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_polymorphic_v
1892 = is_polymorphic<_Tp>::value;
1825inline constexpr bool is_polymorphic_v = is_polymorphic<_Tp>::value;
18931826#endif
18941827
18951828// has_virtual_destructor
......@@ -1906,25 +1839,21 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS has_virtual_destructor
19061839
19071840#endif
19081841
1909#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1842#if _LIBCPP_STD_VER > 14
19101843template <class _Tp>
1911_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool has_virtual_destructor_v
1912 = has_virtual_destructor<_Tp>::value;
1844inline constexpr bool has_virtual_destructor_v = has_virtual_destructor<_Tp>::value;
19131845#endif
19141846
19151847// has_unique_object_representations
19161848
1917#if _LIBCPP_STD_VER > 14 && defined(_LIBCPP_HAS_UNIQUE_OBJECT_REPRESENTATIONS)
1849#if _LIBCPP_STD_VER > 14
19181850
19191851template <class _Tp> struct _LIBCPP_TEMPLATE_VIS has_unique_object_representations
19201852 : public integral_constant<bool,
19211853 __has_unique_object_representations(remove_cv_t<remove_all_extents_t<_Tp>>)> {};
19221854
1923#if !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
19241855template <class _Tp>
1925_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool has_unique_object_representations_v
1926 = has_unique_object_representations<_Tp>::value;
1927#endif
1856inline constexpr bool has_unique_object_representations_v = has_unique_object_representations<_Tp>::value;
19281857
19291858#endif
19301859
......@@ -1933,10 +1862,9 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool has_unique_object_representations_v
19331862template <class _Tp> struct _LIBCPP_TEMPLATE_VIS alignment_of
19341863 : public integral_constant<size_t, _LIBCPP_ALIGNOF(_Tp)> {};
19351864
1936#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1865#if _LIBCPP_STD_VER > 14
19371866template <class _Tp>
1938_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR size_t alignment_of_v
1939 = alignment_of<_Tp>::value;
1867inline constexpr size_t alignment_of_v = alignment_of<_Tp>::value;
19401868#endif
19411869
19421870// aligned_storage
......@@ -2214,26 +2142,26 @@ template <class _TypeList, size_t _Size, bool = _Size <= sizeof(typename _TypeLi
22142142template <class _Hp, class _Tp, size_t _Size>
22152143struct __find_first<__type_list<_Hp, _Tp>, _Size, true>
22162144{
2217 typedef _LIBCPP_NODEBUG_TYPE _Hp type;
2145 typedef _LIBCPP_NODEBUG _Hp type;
22182146};
22192147
22202148template <class _Hp, class _Tp, size_t _Size>
22212149struct __find_first<__type_list<_Hp, _Tp>, _Size, false>
22222150{
2223 typedef _LIBCPP_NODEBUG_TYPE typename __find_first<_Tp, _Size>::type type;
2151 typedef _LIBCPP_NODEBUG typename __find_first<_Tp, _Size>::type type;
22242152};
22252153
22262154template <class _Tp, class _Up, bool = is_const<typename remove_reference<_Tp>::type>::value,
22272155 bool = is_volatile<typename remove_reference<_Tp>::type>::value>
22282156struct __apply_cv
22292157{
2230 typedef _LIBCPP_NODEBUG_TYPE _Up type;
2158 typedef _LIBCPP_NODEBUG _Up type;
22312159};
22322160
22332161template <class _Tp, class _Up>
22342162struct __apply_cv<_Tp, _Up, true, false>
22352163{
2236 typedef _LIBCPP_NODEBUG_TYPE const _Up type;
2164 typedef _LIBCPP_NODEBUG const _Up type;
22372165};
22382166
22392167template <class _Tp, class _Up>
......@@ -2340,7 +2268,7 @@ template <class _Tp> using make_unsigned_t = typename make_unsigned<_Tp>::type;
23402268
23412269#ifndef _LIBCPP_CXX03_LANG
23422270template <class _Tp>
2343_LIBCPP_NODISCARD_ATTRIBUTE _LIBCPP_INLINE_VISIBILITY constexpr
2271_LIBCPP_HIDE_FROM_ABI constexpr
23442272typename make_unsigned<_Tp>::type __to_unsigned_like(_Tp __x) noexcept {
23452273 return static_cast<typename make_unsigned<_Tp>::type>(__x);
23462274}
......@@ -2379,7 +2307,7 @@ struct __common_type2_imp<_Tp, _Up,
23792307 true ? declval<_Tp>() : declval<_Up>()
23802308 )>::type>
23812309{
2382 typedef _LIBCPP_NODEBUG_TYPE typename decay<decltype(
2310 typedef _LIBCPP_NODEBUG typename decay<decltype(
23832311 true ? declval<_Tp>() : declval<_Up>()
23842312 )>::type type;
23852313};
......@@ -2390,7 +2318,7 @@ struct __common_type_impl {};
23902318// Clang provides variadic templates in C++03 as an extension.
23912319#if !defined(_LIBCPP_CXX03_LANG) || defined(__clang__)
23922320# define _LIBCPP_OPTIONAL_PACK(...) , __VA_ARGS__
2393template <class... Tp>
2321template <class... _Tp>
23942322struct __common_types;
23952323template <class... _Tp>
23962324struct _LIBCPP_TEMPLATE_VIS common_type;
......@@ -2514,7 +2442,7 @@ using __copy_cvref_t = typename __copy_cvref<_From, _To>::type;
25142442#endif // _LIBCPP_STD_VER > 11
25152443
25162444// common_reference
2517#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CONCEPTS)
2445#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
25182446// Let COND_RES(X, Y) be:
25192447template <class _Xp, class _Yp>
25202448using __cond_res =
......@@ -2668,20 +2596,20 @@ struct common_reference<_Tp, _Up, _Vp, _Rest...>
26682596// bullet 5 - Otherwise, there shall be no member `type`.
26692597template <class...> struct common_reference {};
26702598
2671#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CONCEPTS)
2599#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
26722600
26732601// is_assignable
26742602
2675template<typename, typename _Tp> struct __select_2nd { typedef _LIBCPP_NODEBUG_TYPE _Tp type; };
2603template<typename, typename _Tp> struct __select_2nd { typedef _LIBCPP_NODEBUG _Tp type; };
26762604
26772605#if __has_keyword(__is_assignable)
26782606
26792607template<class _Tp, class _Up>
26802608struct _LIBCPP_TEMPLATE_VIS is_assignable : _BoolConstant<__is_assignable(_Tp, _Up)> { };
26812609
2682#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
2610#if _LIBCPP_STD_VER > 14
26832611template <class _Tp, class _Arg>
2684_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_assignable_v = __is_assignable(_Tp, _Arg);
2612inline constexpr bool is_assignable_v = __is_assignable(_Tp, _Arg);
26852613#endif
26862614
26872615#else // __has_keyword(__is_assignable)
......@@ -2708,10 +2636,9 @@ template <class _Tp, class _Arg>
27082636struct is_assignable
27092637 : public __is_assignable_imp<_Tp, _Arg> {};
27102638
2711#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
2639#if _LIBCPP_STD_VER > 14
27122640template <class _Tp, class _Arg>
2713_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_assignable_v
2714 = is_assignable<_Tp, _Arg>::value;
2641inline constexpr bool is_assignable_v = is_assignable<_Tp, _Arg>::value;
27152642#endif
27162643
27172644#endif // __has_keyword(__is_assignable)
......@@ -2722,10 +2649,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_copy_assignable
27222649 : public is_assignable<typename add_lvalue_reference<_Tp>::type,
27232650 typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
27242651
2725#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
2652#if _LIBCPP_STD_VER > 14
27262653template <class _Tp>
2727_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_copy_assignable_v
2728 = is_copy_assignable<_Tp>::value;
2654inline constexpr bool is_copy_assignable_v = is_copy_assignable<_Tp>::value;
27292655#endif
27302656
27312657// is_move_assignable
......@@ -2734,10 +2660,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_move_assignable
27342660 : public is_assignable<typename add_lvalue_reference<_Tp>::type,
27352661 typename add_rvalue_reference<_Tp>::type> {};
27362662
2737#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
2663#if _LIBCPP_STD_VER > 14
27382664template <class _Tp>
2739_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_move_assignable_v
2740 = is_move_assignable<_Tp>::value;
2665inline constexpr bool is_move_assignable_v = is_move_assignable<_Tp>::value;
27412666#endif
27422667
27432668// is_destructible
......@@ -2747,9 +2672,9 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_move_assignable_v
27472672template<class _Tp>
27482673struct _LIBCPP_TEMPLATE_VIS is_destructible : _BoolConstant<__is_destructible(_Tp)> { };
27492674
2750#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
2675#if _LIBCPP_STD_VER > 14
27512676template <class _Tp>
2752_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_destructible_v = __is_destructible(_Tp);
2677inline constexpr bool is_destructible_v = __is_destructible(_Tp);
27532678#endif
27542679
27552680#else // __has_keyword(__is_destructible)
......@@ -2810,10 +2735,9 @@ template <>
28102735struct is_destructible<void>
28112736 : public false_type {};
28122737
2813#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
2738#if _LIBCPP_STD_VER > 14
28142739template <class _Tp>
2815_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_destructible_v
2816 = is_destructible<_Tp>::value;
2740inline constexpr bool is_destructible_v = is_destructible<_Tp>::value;
28172741#endif
28182742
28192743#endif // __has_keyword(__is_destructible)
......@@ -3049,140 +2973,14 @@ struct __member_pointer_class_type<_Ret _ClassType::*> {
30492973
30502974// template <class T, class... Args> struct is_constructible;
30512975
3052#if defined(_LIBCPP_COMPILER_GCC) && _GNUC_VER_NEW >= 10000
3053# define _LIBCPP_GCC_SUPPORTS_IS_CONSTRUCTIBLE
3054#endif
3055
3056#if !defined(_LIBCPP_CXX03_LANG) && !__has_feature(is_constructible) && !defined(_LIBCPP_GCC_SUPPORTS_IS_CONSTRUCTIBLE)
3057
3058template <class _Tp, class... _Args>
3059struct __libcpp_is_constructible;
3060
3061template <class _To, class _From>
3062struct __is_invalid_base_to_derived_cast {
3063 static_assert(is_reference<_To>::value, "Wrong specialization");
3064 using _RawFrom = __uncvref_t<_From>;
3065 using _RawTo = __uncvref_t<_To>;
3066 static const bool value = _And<
3067 _IsNotSame<_RawFrom, _RawTo>,
3068 is_base_of<_RawFrom, _RawTo>,
3069 _Not<__libcpp_is_constructible<_RawTo, _From>>
3070 >::value;
3071};
3072
3073template <class _To, class _From>
3074struct __is_invalid_lvalue_to_rvalue_cast : false_type {
3075 static_assert(is_reference<_To>::value, "Wrong specialization");
3076};
3077
3078template <class _ToRef, class _FromRef>
3079struct __is_invalid_lvalue_to_rvalue_cast<_ToRef&&, _FromRef&> {
3080 using _RawFrom = __uncvref_t<_FromRef>;
3081 using _RawTo = __uncvref_t<_ToRef>;
3082 static const bool value = _And<
3083 _Not<is_function<_RawTo>>,
3084 _Or<
3085 _IsSame<_RawFrom, _RawTo>,
3086 is_base_of<_RawTo, _RawFrom>>
3087 >::value;
3088};
3089
3090struct __is_constructible_helper
3091{
3092 template <class _To>
3093 static void __eat(_To);
3094
3095 // This overload is needed to work around a Clang bug that disallows
3096 // static_cast<T&&>(e) for non-reference-compatible types.
3097 // Example: static_cast<int&&>(declval<double>());
3098 // NOTE: The static_cast implementation below is required to support
3099 // classes with explicit conversion operators.
3100 template <class _To, class _From,
3101 class = decltype(__eat<_To>(declval<_From>()))>
3102 static true_type __test_cast(int);
3103
3104 template <class _To, class _From,
3105 class = decltype(static_cast<_To>(declval<_From>()))>
3106 static integral_constant<bool,
3107 !__is_invalid_base_to_derived_cast<_To, _From>::value &&
3108 !__is_invalid_lvalue_to_rvalue_cast<_To, _From>::value
3109 > __test_cast(long);
3110
3111 template <class, class>
3112 static false_type __test_cast(...);
3113
3114 template <class _Tp, class ..._Args,
3115 class = decltype(_Tp(declval<_Args>()...))>
3116 static true_type __test_nary(int);
3117 template <class _Tp, class...>
3118 static false_type __test_nary(...);
3119
3120 template <class _Tp, class _A0, class = decltype(::new _Tp(declval<_A0>()))>
3121 static is_destructible<_Tp> __test_unary(int);
3122 template <class, class>
3123 static false_type __test_unary(...);
3124};
3125
3126template <class _Tp, bool = is_void<_Tp>::value>
3127struct __is_default_constructible
3128 : decltype(__is_constructible_helper::__test_nary<_Tp>(0))
3129{};
3130
3131template <class _Tp>
3132struct __is_default_constructible<_Tp, true> : false_type {};
3133
3134template <class _Tp>
3135struct __is_default_constructible<_Tp[], false> : false_type {};
3136
3137template <class _Tp, size_t _Nx>
3138struct __is_default_constructible<_Tp[_Nx], false>
3139 : __is_default_constructible<typename remove_all_extents<_Tp>::type> {};
3140
3141template <class _Tp, class... _Args>
3142struct __libcpp_is_constructible
3143{
3144 static_assert(sizeof...(_Args) > 1, "Wrong specialization");
3145 typedef decltype(__is_constructible_helper::__test_nary<_Tp, _Args...>(0))
3146 type;
3147};
3148
3149template <class _Tp>
3150struct __libcpp_is_constructible<_Tp> : __is_default_constructible<_Tp> {};
3151
3152template <class _Tp, class _A0>
3153struct __libcpp_is_constructible<_Tp, _A0>
3154 : public decltype(__is_constructible_helper::__test_unary<_Tp, _A0>(0))
3155{};
3156
3157template <class _Tp, class _A0>
3158struct __libcpp_is_constructible<_Tp&, _A0>
3159 : public decltype(__is_constructible_helper::
3160 __test_cast<_Tp&, _A0>(0))
3161{};
3162
3163template <class _Tp, class _A0>
3164struct __libcpp_is_constructible<_Tp&&, _A0>
3165 : public decltype(__is_constructible_helper::
3166 __test_cast<_Tp&&, _A0>(0))
3167{};
3168
3169#endif
3170
3171#if __has_feature(is_constructible) || defined(_LIBCPP_GCC_SUPPORTS_IS_CONSTRUCTIBLE)
31722976template <class _Tp, class ..._Args>
31732977struct _LIBCPP_TEMPLATE_VIS is_constructible
31742978 : public integral_constant<bool, __is_constructible(_Tp, _Args...)>
3175 {};
3176#else
3177template <class _Tp, class... _Args>
3178struct _LIBCPP_TEMPLATE_VIS is_constructible
3179 : public __libcpp_is_constructible<_Tp, _Args...>::type {};
3180#endif
2979{ };
31812980
3182#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
2981#if _LIBCPP_STD_VER > 14
31832982template <class _Tp, class ..._Args>
3184_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_constructible_v
3185 = is_constructible<_Tp, _Args...>::value;
2983inline constexpr bool is_constructible_v = is_constructible<_Tp, _Args...>::value;
31862984#endif
31872985
31882986// is_default_constructible
......@@ -3192,10 +2990,9 @@ struct _LIBCPP_TEMPLATE_VIS is_default_constructible
31922990 : public is_constructible<_Tp>
31932991 {};
31942992
3195#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
2993#if _LIBCPP_STD_VER > 14
31962994template <class _Tp>
3197_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_default_constructible_v
3198 = is_default_constructible<_Tp>::value;
2995inline constexpr bool is_default_constructible_v = is_default_constructible<_Tp>::value;
31992996#endif
32002997
32012998#ifndef _LIBCPP_CXX03_LANG
......@@ -3229,10 +3026,9 @@ struct _LIBCPP_TEMPLATE_VIS is_copy_constructible
32293026 : public is_constructible<_Tp,
32303027 typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
32313028
3232#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3029#if _LIBCPP_STD_VER > 14
32333030template <class _Tp>
3234_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_copy_constructible_v
3235 = is_copy_constructible<_Tp>::value;
3031inline constexpr bool is_copy_constructible_v = is_copy_constructible<_Tp>::value;
32363032#endif
32373033
32383034// is_move_constructible
......@@ -3242,65 +3038,22 @@ struct _LIBCPP_TEMPLATE_VIS is_move_constructible
32423038 : public is_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
32433039 {};
32443040
3245#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3041#if _LIBCPP_STD_VER > 14
32463042template <class _Tp>
3247_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_move_constructible_v
3248 = is_move_constructible<_Tp>::value;
3043inline constexpr bool is_move_constructible_v = is_move_constructible<_Tp>::value;
32493044#endif
32503045
32513046// is_trivially_constructible
32523047
3253#if __has_feature(is_trivially_constructible) || _GNUC_VER >= 501
3254
32553048template <class _Tp, class... _Args>
32563049struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible
32573050 : integral_constant<bool, __is_trivially_constructible(_Tp, _Args...)>
32583051{
32593052};
32603053
3261#else // !__has_feature(is_trivially_constructible)
3262
3263template <class _Tp, class... _Args>
3264struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible
3265 : false_type
3266{
3267};
3268
3269template <class _Tp>
3270struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp>
3271#if __has_feature(has_trivial_constructor) || defined(_LIBCPP_COMPILER_GCC)
3272 : integral_constant<bool, __has_trivial_constructor(_Tp)>
3273#else
3274 : integral_constant<bool, is_scalar<_Tp>::value>
3275#endif
3276{
3277};
3278
3279template <class _Tp>
3280struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, _Tp&&>
3281 : integral_constant<bool, is_scalar<_Tp>::value>
3282{
3283};
3284
3285template <class _Tp>
3286struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, const _Tp&>
3287 : integral_constant<bool, is_scalar<_Tp>::value>
3288{
3289};
3290
3291template <class _Tp>
3292struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, _Tp&>
3293 : integral_constant<bool, is_scalar<_Tp>::value>
3294{
3295};
3296
3297#endif // !__has_feature(is_trivially_constructible)
3298
3299
3300#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3054#if _LIBCPP_STD_VER > 14
33013055template <class _Tp, class... _Args>
3302_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_constructible_v
3303 = is_trivially_constructible<_Tp, _Args...>::value;
3056inline constexpr bool is_trivially_constructible_v = is_trivially_constructible<_Tp, _Args...>::value;
33043057#endif
33053058
33063059// is_trivially_default_constructible
......@@ -3309,10 +3062,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_default_constructi
33093062 : public is_trivially_constructible<_Tp>
33103063 {};
33113064
3312#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3065#if _LIBCPP_STD_VER > 14
33133066template <class _Tp>
3314_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_default_constructible_v
3315 = is_trivially_default_constructible<_Tp>::value;
3067inline constexpr bool is_trivially_default_constructible_v = is_trivially_default_constructible<_Tp>::value;
33163068#endif
33173069
33183070// is_trivially_copy_constructible
......@@ -3321,10 +3073,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_copy_constructible
33213073 : public is_trivially_constructible<_Tp, typename add_lvalue_reference<const _Tp>::type>
33223074 {};
33233075
3324#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3076#if _LIBCPP_STD_VER > 14
33253077template <class _Tp>
3326_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_copy_constructible_v
3327 = is_trivially_copy_constructible<_Tp>::value;
3078inline constexpr bool is_trivially_copy_constructible_v = is_trivially_copy_constructible<_Tp>::value;
33283079#endif
33293080
33303081// is_trivially_move_constructible
......@@ -3333,50 +3084,21 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_move_constructible
33333084 : public is_trivially_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
33343085 {};
33353086
3336#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3087#if _LIBCPP_STD_VER > 14
33373088template <class _Tp>
3338_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_move_constructible_v
3339 = is_trivially_move_constructible<_Tp>::value;
3089inline constexpr bool is_trivially_move_constructible_v = is_trivially_move_constructible<_Tp>::value;
33403090#endif
33413091
33423092// is_trivially_assignable
33433093
3344#if __has_feature(is_trivially_assignable) || _GNUC_VER >= 501
3345
33463094template <class _Tp, class _Arg>
33473095struct is_trivially_assignable
33483096 : integral_constant<bool, __is_trivially_assignable(_Tp, _Arg)>
3349{
3350};
3351
3352#else // !__has_feature(is_trivially_assignable)
3353
3354template <class _Tp, class _Arg>
3355struct is_trivially_assignable
3356 : public false_type {};
3357
3358template <class _Tp>
3359struct is_trivially_assignable<_Tp&, _Tp>
3360 : integral_constant<bool, is_scalar<_Tp>::value> {};
3361
3362template <class _Tp>
3363struct is_trivially_assignable<_Tp&, _Tp&>
3364 : integral_constant<bool, is_scalar<_Tp>::value> {};
3365
3366template <class _Tp>
3367struct is_trivially_assignable<_Tp&, const _Tp&>
3368 : integral_constant<bool, is_scalar<_Tp>::value> {};
3369
3370template <class _Tp>
3371struct is_trivially_assignable<_Tp&, _Tp&&>
3372 : integral_constant<bool, is_scalar<_Tp>::value> {};
3373
3374#endif // !__has_feature(is_trivially_assignable)
3097{ };
33753098
3376#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3099#if _LIBCPP_STD_VER > 14
33773100template <class _Tp, class _Arg>
3378_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_assignable_v
3379 = is_trivially_assignable<_Tp, _Arg>::value;
3101inline constexpr bool is_trivially_assignable_v = is_trivially_assignable<_Tp, _Arg>::value;
33803102#endif
33813103
33823104// is_trivially_copy_assignable
......@@ -3385,10 +3107,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_copy_assignable
33853107 : public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type,
33863108 typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
33873109
3388#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3110#if _LIBCPP_STD_VER > 14
33893111template <class _Tp>
3390_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_copy_assignable_v
3391 = is_trivially_copy_assignable<_Tp>::value;
3112inline constexpr bool is_trivially_copy_assignable_v = is_trivially_copy_assignable<_Tp>::value;
33923113#endif
33933114
33943115// is_trivially_move_assignable
......@@ -3398,10 +3119,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_move_assignable
33983119 typename add_rvalue_reference<_Tp>::type>
33993120 {};
34003121
3401#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3122#if _LIBCPP_STD_VER > 14
34023123template <class _Tp>
3403_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_move_assignable_v
3404 = is_trivially_move_assignable<_Tp>::value;
3124inline constexpr bool is_trivially_move_assignable_v = is_trivially_move_assignable<_Tp>::value;
34053125#endif
34063126
34073127// is_trivially_destructible
......@@ -3430,10 +3150,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible<_Tp[]
34303150
34313151#endif
34323152
3433#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3153#if _LIBCPP_STD_VER > 14
34343154template <class _Tp>
3435_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_destructible_v
3436 = is_trivially_destructible<_Tp>::value;
3155inline constexpr bool is_trivially_destructible_v = is_trivially_destructible<_Tp>::value;
34373156#endif
34383157
34393158// is_nothrow_constructible
......@@ -3484,10 +3203,9 @@ struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp[_Ns]>
34843203#endif // _LIBCPP_HAS_NO_NOEXCEPT
34853204
34863205
3487#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3206#if _LIBCPP_STD_VER > 14
34883207template <class _Tp, class ..._Args>
3489_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_constructible_v
3490 = is_nothrow_constructible<_Tp, _Args...>::value;
3208inline constexpr bool is_nothrow_constructible_v = is_nothrow_constructible<_Tp, _Args...>::value;
34913209#endif
34923210
34933211// is_nothrow_default_constructible
......@@ -3496,10 +3214,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_default_constructibl
34963214 : public is_nothrow_constructible<_Tp>
34973215 {};
34983216
3499#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3217#if _LIBCPP_STD_VER > 14
35003218template <class _Tp>
3501_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_default_constructible_v
3502 = is_nothrow_default_constructible<_Tp>::value;
3219inline constexpr bool is_nothrow_default_constructible_v = is_nothrow_default_constructible<_Tp>::value;
35033220#endif
35043221
35053222// is_nothrow_copy_constructible
......@@ -3508,10 +3225,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_copy_constructible
35083225 : public is_nothrow_constructible<_Tp,
35093226 typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
35103227
3511#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3228#if _LIBCPP_STD_VER > 14
35123229template <class _Tp>
3513_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_copy_constructible_v
3514 = is_nothrow_copy_constructible<_Tp>::value;
3230inline constexpr bool is_nothrow_copy_constructible_v = is_nothrow_copy_constructible<_Tp>::value;
35153231#endif
35163232
35173233// is_nothrow_move_constructible
......@@ -3520,10 +3236,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_move_constructible
35203236 : public is_nothrow_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
35213237 {};
35223238
3523#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3239#if _LIBCPP_STD_VER > 14
35243240template <class _Tp>
3525_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_move_constructible_v
3526 = is_nothrow_move_constructible<_Tp>::value;
3241inline constexpr bool is_nothrow_move_constructible_v = is_nothrow_move_constructible<_Tp>::value;
35273242#endif
35283243
35293244// is_nothrow_assignable
......@@ -3558,10 +3273,9 @@ struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable
35583273
35593274#endif // _LIBCPP_HAS_NO_NOEXCEPT
35603275
3561#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3276#if _LIBCPP_STD_VER > 14
35623277template <class _Tp, class _Arg>
3563_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_assignable_v
3564 = is_nothrow_assignable<_Tp, _Arg>::value;
3278inline constexpr bool is_nothrow_assignable_v = is_nothrow_assignable<_Tp, _Arg>::value;
35653279#endif
35663280
35673281// is_nothrow_copy_assignable
......@@ -3570,10 +3284,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_copy_assignable
35703284 : public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type,
35713285 typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
35723286
3573#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3287#if _LIBCPP_STD_VER > 14
35743288template <class _Tp>
3575_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_copy_assignable_v
3576 = is_nothrow_copy_assignable<_Tp>::value;
3289inline constexpr bool is_nothrow_copy_assignable_v = is_nothrow_copy_assignable<_Tp>::value;
35773290#endif
35783291
35793292// is_nothrow_move_assignable
......@@ -3583,10 +3296,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_move_assignable
35833296 typename add_rvalue_reference<_Tp>::type>
35843297 {};
35853298
3586#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3299#if _LIBCPP_STD_VER > 14
35873300template <class _Tp>
3588_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_move_assignable_v
3589 = is_nothrow_move_assignable<_Tp>::value;
3301inline constexpr bool is_nothrow_move_assignable_v = is_nothrow_move_assignable<_Tp>::value;
35903302#endif
35913303
35923304// is_nothrow_destructible
......@@ -3646,10 +3358,9 @@ struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp[]>
36463358
36473359#endif
36483360
3649#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3361#if _LIBCPP_STD_VER > 14
36503362template <class _Tp>
3651_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_destructible_v
3652 = is_nothrow_destructible<_Tp>::value;
3363inline constexpr bool is_nothrow_destructible_v = is_nothrow_destructible<_Tp>::value;
36533364#endif
36543365
36553366// is_pod
......@@ -3669,10 +3380,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_pod
36693380
36703381#endif
36713382
3672#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3383#if _LIBCPP_STD_VER > 14
36733384template <class _Tp>
3674_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_pod_v
3675 = is_pod<_Tp>::value;
3385inline constexpr bool is_pod_v = is_pod<_Tp>::value;
36763386#endif
36773387
36783388// is_literal_type;
......@@ -3682,11 +3392,10 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 is_
36823392 : public integral_constant<bool, __is_literal_type(_Tp)>
36833393 {};
36843394
3685#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3395#if _LIBCPP_STD_VER > 14
36863396template <class _Tp>
3687_LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_literal_type_v
3688 = is_literal_type<_Tp>::value;
3689#endif // _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3397_LIBCPP_DEPRECATED_IN_CXX17 inline constexpr bool is_literal_type_v = is_literal_type<_Tp>::value;
3398#endif // _LIBCPP_STD_VER > 14
36903399#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS)
36913400
36923401// is_standard_layout;
......@@ -3699,28 +3408,20 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_standard_layout
36993408#endif
37003409 {};
37013410
3702#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3411#if _LIBCPP_STD_VER > 14
37033412template <class _Tp>
3704_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_standard_layout_v
3705 = is_standard_layout<_Tp>::value;
3413inline constexpr bool is_standard_layout_v = is_standard_layout<_Tp>::value;
37063414#endif
37073415
37083416// is_trivially_copyable;
37093417
37103418template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_copyable
3711#if __has_feature(is_trivially_copyable)
37123419 : public integral_constant<bool, __is_trivially_copyable(_Tp)>
3713#elif _GNUC_VER >= 501
3714 : public integral_constant<bool, !is_volatile<_Tp>::value && __is_trivially_copyable(_Tp)>
3715#else
3716 : integral_constant<bool, is_scalar<typename remove_all_extents<_Tp>::type>::value>
3717#endif
37183420 {};
37193421
3720#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3422#if _LIBCPP_STD_VER > 14
37213423template <class _Tp>
3722_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_copyable_v
3723 = is_trivially_copyable<_Tp>::value;
3424inline constexpr bool is_trivially_copyable_v = is_trivially_copyable<_Tp>::value;
37243425#endif
37253426
37263427// is_trivial;
......@@ -3734,10 +3435,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivial
37343435#endif
37353436 {};
37363437
3737#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3438#if _LIBCPP_STD_VER > 14
37383439template <class _Tp>
3739_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivial_v
3740 = is_trivial<_Tp>::value;
3440inline constexpr bool is_trivial_v = is_trivial<_Tp>::value;
37413441#endif
37423442
37433443template <class _Tp> struct __is_reference_wrapper_impl : public false_type {};
......@@ -3811,10 +3511,6 @@ using __enable_if_bullet6 = typename enable_if
38113511
38123512// fall back - none of the bullets
38133513
3814#define _LIBCPP_INVOKE_RETURN(...) \
3815 noexcept(noexcept(__VA_ARGS__)) -> decltype(__VA_ARGS__) \
3816 { return __VA_ARGS__; }
3817
38183514template <class ..._Args>
38193515auto __invoke(__any, _Args&& ...__args) -> __nat;
38203516
......@@ -3828,42 +3524,54 @@ template <class _Fp, class _A0, class ..._Args,
38283524inline _LIBCPP_INLINE_VISIBILITY
38293525_LIBCPP_CONSTEXPR_AFTER_CXX17 auto
38303526__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
3831_LIBCPP_INVOKE_RETURN((static_cast<_A0&&>(__a0).*__f)(static_cast<_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)...); }
38323530
38333531template <class _Fp, class _A0, class ..._Args,
38343532 class = __enable_if_bullet1<_Fp, _A0>>
38353533inline _LIBCPP_INLINE_VISIBILITY
38363534_LIBCPP_CONSTEXPR auto
38373535__invoke_constexpr(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
3838_LIBCPP_INVOKE_RETURN((static_cast<_A0&&>(__a0).*__f)(static_cast<_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)...); }
38393539
38403540template <class _Fp, class _A0, class ..._Args,
38413541 class = __enable_if_bullet2<_Fp, _A0>>
38423542inline _LIBCPP_INLINE_VISIBILITY
38433543_LIBCPP_CONSTEXPR_AFTER_CXX17 auto
38443544__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
3845_LIBCPP_INVOKE_RETURN((__a0.get().*__f)(static_cast<_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)...); }
38463548
38473549template <class _Fp, class _A0, class ..._Args,
38483550 class = __enable_if_bullet2<_Fp, _A0>>
38493551inline _LIBCPP_INLINE_VISIBILITY
38503552_LIBCPP_CONSTEXPR auto
38513553__invoke_constexpr(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
3852_LIBCPP_INVOKE_RETURN((__a0.get().*__f)(static_cast<_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)...); }
38533557
38543558template <class _Fp, class _A0, class ..._Args,
38553559 class = __enable_if_bullet3<_Fp, _A0>>
38563560inline _LIBCPP_INLINE_VISIBILITY
38573561_LIBCPP_CONSTEXPR_AFTER_CXX17 auto
38583562__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
3859_LIBCPP_INVOKE_RETURN(((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_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)...); }
38603566
38613567template <class _Fp, class _A0, class ..._Args,
38623568 class = __enable_if_bullet3<_Fp, _A0>>
38633569inline _LIBCPP_INLINE_VISIBILITY
38643570_LIBCPP_CONSTEXPR auto
38653571__invoke_constexpr(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
3866_LIBCPP_INVOKE_RETURN(((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_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)...); }
38673575
38683576// bullets 4, 5 and 6
38693577
......@@ -3872,42 +3580,54 @@ template <class _Fp, class _A0,
38723580inline _LIBCPP_INLINE_VISIBILITY
38733581_LIBCPP_CONSTEXPR_AFTER_CXX17 auto
38743582__invoke(_Fp&& __f, _A0&& __a0)
3875_LIBCPP_INVOKE_RETURN(static_cast<_A0&&>(__a0).*__f)
3583 noexcept(noexcept(static_cast<_A0&&>(__a0).*__f))
3584 -> decltype( static_cast<_A0&&>(__a0).*__f)
3585 { return static_cast<_A0&&>(__a0).*__f; }
38763586
38773587template <class _Fp, class _A0,
38783588 class = __enable_if_bullet4<_Fp, _A0>>
38793589inline _LIBCPP_INLINE_VISIBILITY
38803590_LIBCPP_CONSTEXPR auto
38813591__invoke_constexpr(_Fp&& __f, _A0&& __a0)
3882_LIBCPP_INVOKE_RETURN(static_cast<_A0&&>(__a0).*__f)
3592 noexcept(noexcept(static_cast<_A0&&>(__a0).*__f))
3593 -> decltype( static_cast<_A0&&>(__a0).*__f)
3594 { return static_cast<_A0&&>(__a0).*__f; }
38833595
38843596template <class _Fp, class _A0,
38853597 class = __enable_if_bullet5<_Fp, _A0>>
38863598inline _LIBCPP_INLINE_VISIBILITY
38873599_LIBCPP_CONSTEXPR_AFTER_CXX17 auto
38883600__invoke(_Fp&& __f, _A0&& __a0)
3889_LIBCPP_INVOKE_RETURN(__a0.get().*__f)
3601 noexcept(noexcept(__a0.get().*__f))
3602 -> decltype( __a0.get().*__f)
3603 { return __a0.get().*__f; }
38903604
38913605template <class _Fp, class _A0,
38923606 class = __enable_if_bullet5<_Fp, _A0>>
38933607inline _LIBCPP_INLINE_VISIBILITY
38943608_LIBCPP_CONSTEXPR auto
38953609__invoke_constexpr(_Fp&& __f, _A0&& __a0)
3896_LIBCPP_INVOKE_RETURN(__a0.get().*__f)
3610 noexcept(noexcept(__a0.get().*__f))
3611 -> decltype( __a0.get().*__f)
3612 { return __a0.get().*__f; }
38973613
38983614template <class _Fp, class _A0,
38993615 class = __enable_if_bullet6<_Fp, _A0>>
39003616inline _LIBCPP_INLINE_VISIBILITY
39013617_LIBCPP_CONSTEXPR_AFTER_CXX17 auto
39023618__invoke(_Fp&& __f, _A0&& __a0)
3903_LIBCPP_INVOKE_RETURN((*static_cast<_A0&&>(__a0)).*__f)
3619 noexcept(noexcept((*static_cast<_A0&&>(__a0)).*__f))
3620 -> decltype( (*static_cast<_A0&&>(__a0)).*__f)
3621 { return (*static_cast<_A0&&>(__a0)).*__f; }
39043622
39053623template <class _Fp, class _A0,
39063624 class = __enable_if_bullet6<_Fp, _A0>>
39073625inline _LIBCPP_INLINE_VISIBILITY
39083626_LIBCPP_CONSTEXPR auto
39093627__invoke_constexpr(_Fp&& __f, _A0&& __a0)
3910_LIBCPP_INVOKE_RETURN((*static_cast<_A0&&>(__a0)).*__f)
3628 noexcept(noexcept((*static_cast<_A0&&>(__a0)).*__f))
3629 -> decltype( (*static_cast<_A0&&>(__a0)).*__f)
3630 { return (*static_cast<_A0&&>(__a0)).*__f; }
39113631
39123632// bullet 7
39133633
......@@ -3915,15 +3635,17 @@ template <class _Fp, class ..._Args>
39153635inline _LIBCPP_INLINE_VISIBILITY
39163636_LIBCPP_CONSTEXPR_AFTER_CXX17 auto
39173637__invoke(_Fp&& __f, _Args&& ...__args)
3918_LIBCPP_INVOKE_RETURN(static_cast<_Fp&&>(__f)(static_cast<_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)...); }
39193641
39203642template <class _Fp, class ..._Args>
39213643inline _LIBCPP_INLINE_VISIBILITY
39223644_LIBCPP_CONSTEXPR auto
39233645__invoke_constexpr(_Fp&& __f, _Args&& ...__args)
3924_LIBCPP_INVOKE_RETURN(static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...))
3925
3926#undef _LIBCPP_INVOKE_RETURN
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)...); }
39273649
39283650// __invokable
39293651template <class _Ret, class _Fp, class ..._Args>
......@@ -4122,12 +3844,10 @@ struct _LIBCPP_TEMPLATE_VIS is_invocable_r
41223844 : integral_constant<bool, __invokable_r<_Ret, _Fn, _Args...>::value> {};
41233845
41243846template <class _Fn, class ..._Args>
4125_LIBCPP_INLINE_VAR constexpr bool is_invocable_v
4126 = is_invocable<_Fn, _Args...>::value;
3847inline constexpr bool is_invocable_v = is_invocable<_Fn, _Args...>::value;
41273848
41283849template <class _Ret, class _Fn, class ..._Args>
4129_LIBCPP_INLINE_VAR constexpr bool is_invocable_r_v
4130 = is_invocable_r<_Ret, _Fn, _Args...>::value;
3850inline constexpr bool is_invocable_r_v = is_invocable_r<_Ret, _Fn, _Args...>::value;
41313851
41323852// is_nothrow_invocable
41333853
......@@ -4140,12 +3860,10 @@ struct _LIBCPP_TEMPLATE_VIS is_nothrow_invocable_r
41403860 : integral_constant<bool, __nothrow_invokable_r<_Ret, _Fn, _Args...>::value> {};
41413861
41423862template <class _Fn, class ..._Args>
4143_LIBCPP_INLINE_VAR constexpr bool is_nothrow_invocable_v
4144 = is_nothrow_invocable<_Fn, _Args...>::value;
3863inline constexpr bool is_nothrow_invocable_v = is_nothrow_invocable<_Fn, _Args...>::value;
41453864
41463865template <class _Ret, class _Fn, class ..._Args>
4147_LIBCPP_INLINE_VAR constexpr bool is_nothrow_invocable_r_v
4148 = is_nothrow_invocable_r<_Ret, _Fn, _Args...>::value;
3866inline constexpr bool is_nothrow_invocable_r_v = is_nothrow_invocable_r<_Ret, _Fn, _Args...>::value;
41493867
41503868#endif // _LIBCPP_STD_VER > 14
41513869
......@@ -4215,7 +3933,7 @@ struct __nothrow_swappable_with {
42153933template <class _Tp, class _Up>
42163934struct __nothrow_swappable_with<_Tp, _Up, false> : false_type {};
42173935
4218} // __detail
3936} // namespace __detail
42193937
42203938template <class _Tp>
42213939struct __is_swappable
......@@ -4268,20 +3986,16 @@ struct _LIBCPP_TEMPLATE_VIS is_nothrow_swappable
42683986};
42693987
42703988template <class _Tp, class _Up>
4271_LIBCPP_INLINE_VAR constexpr bool is_swappable_with_v
4272 = is_swappable_with<_Tp, _Up>::value;
3989inline constexpr bool is_swappable_with_v = is_swappable_with<_Tp, _Up>::value;
42733990
42743991template <class _Tp>
4275_LIBCPP_INLINE_VAR constexpr bool is_swappable_v
4276 = is_swappable<_Tp>::value;
3992inline constexpr bool is_swappable_v = is_swappable<_Tp>::value;
42773993
42783994template <class _Tp, class _Up>
4279_LIBCPP_INLINE_VAR constexpr bool is_nothrow_swappable_with_v
4280 = is_nothrow_swappable_with<_Tp, _Up>::value;
3995inline constexpr bool is_nothrow_swappable_with_v = is_nothrow_swappable_with<_Tp, _Up>::value;
42813996
42823997template <class _Tp>
4283_LIBCPP_INLINE_VAR constexpr bool is_nothrow_swappable_v
4284 = is_nothrow_swappable<_Tp>::value;
3998inline constexpr bool is_nothrow_swappable_v = is_nothrow_swappable<_Tp>::value;
42853999
42864000#endif // _LIBCPP_STD_VER > 14
42874001
......@@ -4349,40 +4063,6 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
43494063typename __sfinae_underlying_type<_Tp>::__promoted_type
43504064__convert_to_integral(_Tp __val) { return __val; }
43514065
4352#ifndef _LIBCPP_CXX03_LANG
4353
4354template <class _Tp>
4355struct __has_operator_addressof_member_imp
4356{
4357 template <class _Up>
4358 static auto __test(int)
4359 -> typename __select_2nd<decltype(declval<_Up>().operator&()), true_type>::type;
4360 template <class>
4361 static auto __test(long) -> false_type;
4362
4363 static const bool value = decltype(__test<_Tp>(0))::value;
4364};
4365
4366template <class _Tp>
4367struct __has_operator_addressof_free_imp
4368{
4369 template <class _Up>
4370 static auto __test(int)
4371 -> typename __select_2nd<decltype(operator&(declval<_Up>())), true_type>::type;
4372 template <class>
4373 static auto __test(long) -> false_type;
4374
4375 static const bool value = decltype(__test<_Tp>(0))::value;
4376};
4377
4378template <class _Tp>
4379struct __has_operator_addressof
4380 : public integral_constant<bool, __has_operator_addressof_member_imp<_Tp>::value
4381 || __has_operator_addressof_free_imp<_Tp>::value>
4382{};
4383
4384#endif // _LIBCPP_CXX03_LANG
4385
43864066// is_scoped_enum [meta.unary.prop]
43874067
43884068#if _LIBCPP_STD_VER > 20
......@@ -4398,8 +4078,7 @@ struct _LIBCPP_TEMPLATE_VIS is_scoped_enum
43984078 : public __is_scoped_enum_helper<_Tp> {};
43994079
44004080template <class _Tp>
4401_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_scoped_enum_v =
4402 is_scoped_enum<_Tp>::value;
4081inline constexpr bool is_scoped_enum_v = is_scoped_enum<_Tp>::value;
44034082#endif
44044083
44054084#if _LIBCPP_STD_VER > 14
......@@ -4407,20 +4086,17 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_scoped_enum_v =
44074086template <class... _Args>
44084087struct conjunction : _And<_Args...> {};
44094088template<class... _Args>
4410_LIBCPP_INLINE_VAR constexpr bool conjunction_v
4411 = conjunction<_Args...>::value;
4089inline constexpr bool conjunction_v = conjunction<_Args...>::value;
44124090
44134091template <class... _Args>
44144092struct disjunction : _Or<_Args...> {};
44154093template<class... _Args>
4416_LIBCPP_INLINE_VAR constexpr bool disjunction_v
4417 = disjunction<_Args...>::value;
4094inline constexpr bool disjunction_v = disjunction<_Args...>::value;
44184095
44194096template <class _Tp>
44204097struct negation : _Not<_Tp> {};
44214098template<class _Tp>
4422_LIBCPP_INLINE_VAR constexpr bool negation_v
4423 = negation<_Tp>::value;
4099inline constexpr bool negation_v = negation<_Tp>::value;
44244100#endif // _LIBCPP_STD_VER > 14
44254101
44264102// These traits are used in __tree and __hash_table
......@@ -4453,7 +4129,6 @@ template <class _ValTy, class _Key, class _RawValTy>
44534129struct __can_extract_map_key<_ValTy, _Key, _Key, _RawValTy>
44544130 : false_type {};
44554131
4456#ifndef _LIBCPP_HAS_NO_BUILTIN_IS_CONSTANT_EVALUATED
44574132#if _LIBCPP_STD_VER > 17
44584133_LIBCPP_INLINE_VISIBILITY
44594134inline constexpr bool is_constant_evaluated() noexcept {
......@@ -4463,10 +4138,6 @@ inline constexpr bool is_constant_evaluated() noexcept {
44634138
44644139inline _LIBCPP_CONSTEXPR
44654140bool __libcpp_is_constant_evaluated() _NOEXCEPT { return __builtin_is_constant_evaluated(); }
4466#else
4467inline _LIBCPP_CONSTEXPR
4468bool __libcpp_is_constant_evaluated() _NOEXCEPT { return false; }
4469#endif
44704141
44714142template <class _CharT>
44724143using _IsCharLikeType = _And<is_standard_layout<_CharT>, is_trivial<_CharT> >;
......@@ -4481,13 +4152,4 @@ using __maybe_const = conditional_t<_Const, const _Tp, _Tp>;
44814152
44824153_LIBCPP_END_NAMESPACE_STD
44834154
4484#if _LIBCPP_STD_VER > 14
4485// std::byte
4486namespace std // purposefully not versioned
4487{
4488
4489
4490}
4491#endif
4492
44934155#endif // _LIBCPP_TYPE_TRAITS
lib/libcxx/include/typeindex+2-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===-------------------------- typeindex ---------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -49,6 +49,7 @@ struct hash<type_index>
4949#include <__functional_base>
5050#include <compare>
5151#include <typeinfo>
52#include <version>
5253
5354#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
5455#pragma GCC system_header
lib/libcxx/include/typeinfo+2-2
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===-------------------------- typeinfo ----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -361,7 +361,7 @@ class _LIBCPP_EXCEPTION_ABI bad_typeid
361361 virtual const char* what() const _NOEXCEPT;
362362};
363363
364} // std
364} // namespace std
365365
366366#endif // defined(_LIBCPP_ABI_VCRUNTIME)
367367
lib/libcxx/include/unordered_map+279-256
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===-------------------------- unordered_map -----------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -216,6 +216,47 @@ public:
216216 void reserve(size_type n);
217217};
218218
219template<class InputIterator,
220 class Hash = hash<iter_key_t<InputIterator>>, class Pred = equal_to<iter_key_t<InputIterator>>,
221 class Allocator = allocator<iter_to_alloc_t<InputIterator>>>
222unordered_map(InputIterator, InputIterator, typename see below::size_type = see below,
223 Hash = Hash(), Pred = Pred(), Allocator = Allocator())
224 -> unordered_map<iter_key_t<InputIterator>, iter_value_t<InputIterator>, Hash, Pred,
225 Allocator>; // C++17
226
227template<class Key, class T, class Hash = hash<Key>,
228 class Pred = equal_to<Key>, class Allocator = allocator<pair<const Key, T>>>
229unordered_map(initializer_list<pair<const Key, T>>, typename see below::size_type = see below,
230 Hash = Hash(), Pred = Pred(), Allocator = Allocator())
231 -> unordered_map<Key, T, Hash, Pred, Allocator>; // C++17
232
233template<class InputIterator, class Allocator>
234unordered_map(InputIterator, InputIterator, typename see below::size_type, Allocator)
235 -> unordered_map<iter_key_t<InputIterator>, iter_val_t<InputIterator>,
236 hash<iter_key_t<InputIterator>>, equal_to<iter_key_t<InputIterator>>, Allocator>; // C++17
237
238template<class InputIterator, class Allocator>
239unordered_map(InputIterator, InputIterator, Allocator)
240 -> unordered_map<iter_key_t<InputIterator>, iter_val_t<InputIterator>,
241 hash<iter_key_t<InputIterator>>, equal_to<iter_key_t<InputIterator>>, Allocator>; // C++17
242
243template<class InputIterator, class Hash, class Allocator>
244unordered_map(InputIterator, InputIterator, typename see below::size_type, Hash, Allocator)
245 -> unordered_map<iter_key_t<InputIterator>, iter_val_t<InputIterator>, Hash,
246 equal_to<iter_key_t<InputIterator>>, Allocator>; // C++17
247
248template<class Key, class T, typename Allocator>
249unordered_map(initializer_list<pair<const Key, T>>, typename see below::size_type, Allocator)
250 -> unordered_map<Key, T, hash<Key>, equal_to<Key>, Allocator>; // C++17
251
252template<class Key, class T, typename Allocator>
253unordered_map(initializer_list<pair<const Key, T>>, Allocator)
254 -> unordered_map<Key, T, hash<Key>, equal_to<Key>, Allocator>; // C++17
255
256template<class Key, class T, class Hash, class Allocator>
257unordered_map(initializer_list<pair<const Key, T>>, typename see below::size_type, Hash, Allocator)
258 -> unordered_map<Key, T, Hash, equal_to<Key>, Allocator>; // C++17
259
219260template <class Key, class T, class Hash, class Pred, class Alloc>
220261 void swap(unordered_map<Key, T, Hash, Pred, Alloc>& x,
221262 unordered_map<Key, T, Hash, Pred, Alloc>& y)
......@@ -404,6 +445,48 @@ public:
404445 void reserve(size_type n);
405446};
406447
448template<class InputIterator,
449 class Hash = hash<iter_key_t<InputIterator>>, class Pred = equal_to<iter_key_t<InputIterator>>,
450 class Allocator = allocator<iter_to_alloc_t<InputIterator>>>
451unordered_multimap(InputIterator, InputIterator, typename see below::size_type = see below,
452 Hash = Hash(), Pred = Pred(), Allocator = Allocator())
453 -> unordered_multimap<iter_key_t<InputIterator>, iter_value_t<InputIterator>, Hash, Pred,
454 Allocator>; // C++17
455
456template<class Key, class T, class Hash = hash<Key>,
457 class Pred = equal_to<Key>, class Allocator = allocator<pair<const Key, T>>>
458unordered_multimap(initializer_list<pair<const Key, T>>, typename see below::size_type = see below,
459 Hash = Hash(), Pred = Pred(), Allocator = Allocator())
460 -> unordered_multimap<Key, T, Hash, Pred, Allocator>; // C++17
461
462template<class InputIterator, class Allocator>
463unordered_multimap(InputIterator, InputIterator, typename see below::size_type, Allocator)
464 -> unordered_multimap<iter_key_t<InputIterator>, iter_val_t<InputIterator>,
465 hash<iter_key_t<InputIterator>>, equal_to<iter_key_t<InputIterator>>, Allocator>; // C++17
466
467template<class InputIterator, class Allocator>
468unordered_multimap(InputIterator, InputIterator, Allocator)
469 -> unordered_multimap<iter_key_t<InputIterator>, iter_val_t<InputIterator>,
470 hash<iter_key_t<InputIterator>>, equal_to<iter_key_t<InputIterator>>, Allocator>; // C++17
471
472template<class InputIterator, class Hash, class Allocator>
473unordered_multimap(InputIterator, InputIterator, typename see below::size_type, Hash, Allocator)
474 -> unordered_multimap<iter_key_t<InputIterator>, iter_val_t<InputIterator>, Hash,
475 equal_to<iter_key_t<InputIterator>>, Allocator>; // C++17
476
477template<class Key, class T, typename Allocator>
478unordered_multimap(initializer_list<pair<const Key, T>>, typename see below::size_type, Allocator)
479 -> unordered_multimap<Key, T, hash<Key>, equal_to<Key>, Allocator>; // C++17
480
481template<class Key, class T, typename Allocator>
482unordered_multimap(initializer_list<pair<const Key, T>>, Allocator)
483 -> unordered_multimap<Key, T, hash<Key>, equal_to<Key>, Allocator>; // C++17
484
485template<class Key, class T, class Hash, class Allocator>
486unordered_multimap(initializer_list<pair<const Key, T>>, typename see below::size_type, Hash,
487 Allocator)
488 -> unordered_multimap<Key, T, Hash, equal_to<Key>, Allocator>; // C++17
489
407490template <class Key, class T, class Hash, class Pred, class Alloc>
408491 void swap(unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
409492 unordered_multimap<Key, T, Hash, Pred, Alloc>& y)
......@@ -435,6 +518,8 @@ template <class Key, class T, class Hash, class Pred, class Alloc>
435518#include <__debug>
436519#include <__functional/is_transparent.h>
437520#include <__hash_table>
521#include <__iterator/iterator_traits.h>
522#include <__memory/addressof.h>
438523#include <__node_handle>
439524#include <__utility/forward.h>
440525#include <compare>
......@@ -473,12 +558,13 @@ public:
473558 size_t operator()(const _Key& __x) const
474559 {return static_cast<const _Hash&>(*this)(__x);}
475560#if _LIBCPP_STD_VER > 17
476 template <typename _K2, typename = _EnableIf<__is_transparent<_Hash, _K2>::value && __is_transparent<_Pred, _K2>::value>>
561 template <typename _K2>
477562 _LIBCPP_INLINE_VISIBILITY
478563 size_t operator()(const _K2& __x) const
479564 {return static_cast<const _Hash&>(*this)(__x);}
480565#endif
481 void swap(__unordered_map_hasher&__y)
566 _LIBCPP_INLINE_VISIBILITY
567 void swap(__unordered_map_hasher& __y)
482568 _NOEXCEPT_(__is_nothrow_swappable<_Hash>::value)
483569 {
484570 using _VSTD::swap;
......@@ -508,12 +594,13 @@ public:
508594 size_t operator()(const _Key& __x) const
509595 {return __hash_(__x);}
510596#if _LIBCPP_STD_VER > 17
511 template <typename _K2, typename = _EnableIf<__is_transparent<_Hash, _K2>::value && __is_transparent<_Pred, _K2>::value>>
597 template <typename _K2>
512598 _LIBCPP_INLINE_VISIBILITY
513599 size_t operator()(const _K2& __x) const
514600 {return __hash_(__x);}
515601#endif
516 void swap(__unordered_map_hasher&__y)
602 _LIBCPP_INLINE_VISIBILITY
603 void swap(__unordered_map_hasher& __y)
517604 _NOEXCEPT_(__is_nothrow_swappable<_Hash>::value)
518605 {
519606 using _VSTD::swap;
......@@ -557,24 +644,25 @@ public:
557644 bool operator()(const _Key& __x, const _Cp& __y) const
558645 {return static_cast<const _Pred&>(*this)(__x, __y.__get_value().first);}
559646#if _LIBCPP_STD_VER > 17
560 template <typename _K2, typename = _EnableIf<__is_transparent<_Hash, _K2>::value && __is_transparent<_Pred, _K2>::value>>
647 template <typename _K2>
561648 _LIBCPP_INLINE_VISIBILITY
562649 bool operator()(const _Cp& __x, const _K2& __y) const
563650 {return static_cast<const _Pred&>(*this)(__x.__get_value().first, __y);}
564 template <typename _K2, typename = _EnableIf<__is_transparent<_Hash, _K2>::value && __is_transparent<_Pred, _K2>::value>>
651 template <typename _K2>
565652 _LIBCPP_INLINE_VISIBILITY
566653 bool operator()(const _K2& __x, const _Cp& __y) const
567654 {return static_cast<const _Pred&>(*this)(__x, __y.__get_value().first);}
568 template <typename _K2, typename = _EnableIf<__is_transparent<_Hash, _K2>::value && __is_transparent<_Pred, _K2>::value>>
655 template <typename _K2>
569656 _LIBCPP_INLINE_VISIBILITY
570657 bool operator()(const _Key& __x, const _K2& __y) const
571658 {return static_cast<const _Pred&>(*this)(__x, __y);}
572 template <typename _K2, typename = _EnableIf<__is_transparent<_Hash, _K2>::value && __is_transparent<_Pred, _K2>::value>>
659 template <typename _K2>
573660 _LIBCPP_INLINE_VISIBILITY
574661 bool operator()(const _K2& __x, const _Key& __y) const
575662 {return static_cast<const _Pred&>(*this)(__x, __y);}
576663#endif
577 void swap(__unordered_map_equal&__y)
664 _LIBCPP_INLINE_VISIBILITY
665 void swap(__unordered_map_equal& __y)
578666 _NOEXCEPT_(__is_nothrow_swappable<_Pred>::value)
579667 {
580668 using _VSTD::swap;
......@@ -607,24 +695,25 @@ public:
607695 bool operator()(const _Key& __x, const _Cp& __y) const
608696 {return __pred_(__x, __y.__get_value().first);}
609697#if _LIBCPP_STD_VER > 17
610 template <typename _K2, typename = _EnableIf<__is_transparent<_Hash, _K2>::value && __is_transparent<_Pred, _K2>::value>>
698 template <typename _K2>
611699 _LIBCPP_INLINE_VISIBILITY
612700 bool operator()(const _Cp& __x, const _K2& __y) const
613701 {return __pred_(__x.__get_value().first, __y);}
614 template <typename _K2, typename = _EnableIf<__is_transparent<_Hash, _K2>::value && __is_transparent<_Pred, _K2>::value>>
702 template <typename _K2>
615703 _LIBCPP_INLINE_VISIBILITY
616704 bool operator()(const _K2& __x, const _Cp& __y) const
617705 {return __pred_(__x, __y.__get_value().first);}
618 template <typename _K2, typename = _EnableIf<__is_transparent<_Hash, _K2>::value && __is_transparent<_Pred, _K2>::value>>
706 template <typename _K2>
619707 _LIBCPP_INLINE_VISIBILITY
620708 bool operator()(const _Key& __x, const _K2& __y) const
621709 {return __pred_(__x, __y);}
622 template <typename _K2, typename = _EnableIf<__is_transparent<_Hash, _K2>::value && __is_transparent<_Pred, _K2>::value>>
710 template <typename _K2>
623711 _LIBCPP_INLINE_VISIBILITY
624712 bool operator()(const _K2& __x, const _Key& __y) const
625713 {return __pred_(__x, __y);}
626714#endif
627 void swap(__unordered_map_equal&__y)
715 _LIBCPP_INLINE_VISIBILITY
716 void swap(__unordered_map_equal& __y)
628717 _NOEXCEPT_(__is_nothrow_swappable<_Pred>::value)
629718 {
630719 using _VSTD::swap;
......@@ -980,11 +1069,9 @@ public:
9801069 _LIBCPP_INLINE_VISIBILITY
9811070 unordered_map()
9821071 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
983 {
984#if _LIBCPP_DEBUG_LEVEL == 2
985 __get_db()->__insert_c(this);
986#endif
987 }
1072 {
1073 _VSTD::__debug_db_insert_c(this);
1074 }
9881075 explicit unordered_map(size_type __n, const hasher& __hf = hasher(),
9891076 const key_equal& __eql = key_equal());
9901077 unordered_map(size_type __n, const hasher& __hf,
......@@ -1052,7 +1139,7 @@ public:
10521139#ifndef _LIBCPP_CXX03_LANG
10531140 __table_ = __u.__table_;
10541141#else
1055 if (this != &__u) {
1142 if (this != _VSTD::addressof(__u)) {
10561143 __table_.clear();
10571144 __table_.hash_function() = __u.__table_.hash_function();
10581145 __table_.key_eq() = __u.__table_.key_eq();
......@@ -1100,13 +1187,10 @@ public:
11001187 {return __table_.__insert_unique(__x);}
11011188
11021189 iterator insert(const_iterator __p, const value_type& __x) {
1103#if _LIBCPP_DEBUG_LEVEL == 2
1104 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1105 "unordered_map::insert(const_iterator, const value_type&) called with an iterator not"
1106 " referring to this unordered_map");
1107#else
1190 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
1191 "unordered_map::insert(const_iterator, const value_type&) called with an iterator not "
1192 "referring to this unordered_map");
11081193 ((void)__p);
1109#endif
11101194 return insert(__x).first;
11111195 }
11121196
......@@ -1124,13 +1208,10 @@ public:
11241208 {return __table_.__insert_unique(_VSTD::move(__x));}
11251209
11261210 iterator insert(const_iterator __p, value_type&& __x) {
1127#if _LIBCPP_DEBUG_LEVEL == 2
1128 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1129 "unordered_map::insert(const_iterator, const value_type&) called with an iterator not"
1130 " referring to this unordered_map");
1131#else
1211 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
1212 "unordered_map::insert(const_iterator, const value_type&) called with an iterator not"
1213 " referring to this unordered_map");
11321214 ((void)__p);
1133#endif
11341215 return __table_.__insert_unique(_VSTD::move(__x)).first;
11351216 }
11361217
......@@ -1145,13 +1226,10 @@ public:
11451226 _LIBCPP_INLINE_VISIBILITY
11461227 iterator insert(const_iterator __p, _Pp&& __x)
11471228 {
1148#if _LIBCPP_DEBUG_LEVEL == 2
1149 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1150 "unordered_map::insert(const_iterator, value_type&&) called with an iterator not"
1151 " referring to this unordered_map");
1152#else
1229 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
1230 "unordered_map::insert(const_iterator, value_type&&) called with an iterator not"
1231 " referring to this unordered_map");
11531232 ((void)__p);
1154#endif
11551233 return insert(_VSTD::forward<_Pp>(__x)).first;
11561234 }
11571235
......@@ -1164,13 +1242,10 @@ public:
11641242 template <class... _Args>
11651243 _LIBCPP_INLINE_VISIBILITY
11661244 iterator emplace_hint(const_iterator __p, _Args&&... __args) {
1167#if _LIBCPP_DEBUG_LEVEL == 2
1168 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1169 "unordered_map::emplace_hint(const_iterator, args...) called with an iterator not"
1170 " referring to this unordered_map");
1171#else
1245 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
1246 "unordered_map::emplace_hint(const_iterator, args...) called with an iterator not"
1247 " referring to this unordered_map");
11721248 ((void)__p);
1173#endif
11741249 return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;
11751250 }
11761251
......@@ -1199,13 +1274,10 @@ public:
11991274 _LIBCPP_INLINE_VISIBILITY
12001275 iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args)
12011276 {
1202#if _LIBCPP_DEBUG_LEVEL == 2
1203 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__h) == this,
1204 "unordered_map::try_emplace(const_iterator, key, args...) called with an iterator not"
1205 " referring to this unordered_map");
1206#else
1277 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__h)) == this,
1278 "unordered_map::try_emplace(const_iterator, key, args...) called with an iterator not"
1279 " referring to this unordered_map");
12071280 ((void)__h);
1208#endif
12091281 return try_emplace(__k, _VSTD::forward<_Args>(__args)...).first;
12101282 }
12111283
......@@ -1213,13 +1285,10 @@ public:
12131285 _LIBCPP_INLINE_VISIBILITY
12141286 iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args)
12151287 {
1216#if _LIBCPP_DEBUG_LEVEL == 2
1217 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__h) == this,
1218 "unordered_map::try_emplace(const_iterator, key, args...) called with an iterator not"
1219 " referring to this unordered_map");
1220#else
1288 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__h)) == this,
1289 "unordered_map::try_emplace(const_iterator, key, args...) called with an iterator not"
1290 " referring to this unordered_map");
12211291 ((void)__h);
1222#endif
12231292 return try_emplace(_VSTD::move(__k), _VSTD::forward<_Args>(__args)...).first;
12241293 }
12251294
......@@ -1355,51 +1424,48 @@ public:
13551424 iterator find(const key_type& __k) {return __table_.find(__k);}
13561425 _LIBCPP_INLINE_VISIBILITY
13571426 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
1358
1359 #if _LIBCPP_STD_VER > 17
1360 template <typename _K2>
1361 _LIBCPP_INLINE_VISIBILITY
1362 _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, iterator>
1363 find(const _K2& __k) {return __table_.find(__k);}
1364 template <typename _K2>
1365 _LIBCPP_INLINE_VISIBILITY
1366 _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, const_iterator>
1367 find(const _K2& __k) const {return __table_.find(__k);}
1368 #endif // _LIBCPP_STD_VER > 17
1427#if _LIBCPP_STD_VER > 17
1428 template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
1429 _LIBCPP_INLINE_VISIBILITY
1430 iterator find(const _K2& __k) {return __table_.find(__k);}
1431 template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
1432 _LIBCPP_INLINE_VISIBILITY
1433 const_iterator find(const _K2& __k) const {return __table_.find(__k);}
1434#endif // _LIBCPP_STD_VER > 17
13691435
13701436 _LIBCPP_INLINE_VISIBILITY
13711437 size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
1372 #if _LIBCPP_STD_VER > 17
1373 template <typename _K2>
1374 _LIBCPP_INLINE_VISIBILITY
1375 _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, size_type>
1376 count(const _K2& __k) const {return __table_.__count_unique(__k);}
1377 #endif // _LIBCPP_STD_VER > 17
1378 #if _LIBCPP_STD_VER > 17
1379 _LIBCPP_INLINE_VISIBILITY
1380 bool contains(const key_type& __k) const {return find(__k) != end();}
1438#if _LIBCPP_STD_VER > 17
1439 template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
1440 _LIBCPP_INLINE_VISIBILITY
1441 size_type count(const _K2& __k) const {return __table_.__count_unique(__k);}
1442#endif // _LIBCPP_STD_VER > 17
1443
1444#if _LIBCPP_STD_VER > 17
1445 _LIBCPP_INLINE_VISIBILITY
1446 bool contains(const key_type& __k) const {return find(__k) != end();}
1447
1448 template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
1449 _LIBCPP_INLINE_VISIBILITY
1450 bool contains(const _K2& __k) const {return find(__k) != end();}
1451#endif // _LIBCPP_STD_VER > 17
13811452
1382 template <typename _K2>
1383 _LIBCPP_INLINE_VISIBILITY
1384 _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, bool>
1385 contains(const _K2& __k) const {return find(__k) != end();}
1386 #endif // _LIBCPP_STD_VER > 17
13871453 _LIBCPP_INLINE_VISIBILITY
13881454 pair<iterator, iterator> equal_range(const key_type& __k)
13891455 {return __table_.__equal_range_unique(__k);}
13901456 _LIBCPP_INLINE_VISIBILITY
13911457 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
13921458 {return __table_.__equal_range_unique(__k);}
1393 #if _LIBCPP_STD_VER > 17
1394 template <typename _K2>
1395 _LIBCPP_INLINE_VISIBILITY
1396 _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, pair<iterator, iterator>>
1397 equal_range(const _K2& __k) {return __table_.__equal_range_unique(__k);}
1398 template <typename _K2>
1399 _LIBCPP_INLINE_VISIBILITY
1400 _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, pair<const_iterator, const_iterator>>
1401 equal_range(const _K2& __k) const {return __table_.__equal_range_unique(__k);}
1402 #endif // _LIBCPP_STD_VER > 17
1459#if _LIBCPP_STD_VER > 17
1460 template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
1461 _LIBCPP_INLINE_VISIBILITY
1462 pair<iterator, iterator> equal_range(const _K2& __k)
1463 {return __table_.__equal_range_unique(__k);}
1464 template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
1465 _LIBCPP_INLINE_VISIBILITY
1466 pair<const_iterator, const_iterator> equal_range(const _K2& __k) const
1467 {return __table_.__equal_range_unique(__k);}
1468#endif // _LIBCPP_STD_VER > 17
14031469
14041470 mapped_type& operator[](const key_type& __k);
14051471#ifndef _LIBCPP_CXX03_LANG
......@@ -1447,13 +1513,13 @@ public:
14471513#if _LIBCPP_DEBUG_LEVEL == 2
14481514
14491515 bool __dereferenceable(const const_iterator* __i) const
1450 {return __table_.__dereferenceable(&__i->__i_);}
1516 {return __table_.__dereferenceable(_VSTD::addressof(__i->__i_));}
14511517 bool __decrementable(const const_iterator* __i) const
1452 {return __table_.__decrementable(&__i->__i_);}
1518 {return __table_.__decrementable(_VSTD::addressof(__i->__i_));}
14531519 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
1454 {return __table_.__addable(&__i->__i_, __n);}
1520 {return __table_.__addable(_VSTD::addressof(__i->__i_), __n);}
14551521 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1456 {return __table_.__addable(&__i->__i_, __n);}
1522 {return __table_.__addable(_VSTD::addressof(__i->__i_), __n);}
14571523
14581524#endif // _LIBCPP_DEBUG_LEVEL == 2
14591525
......@@ -1464,15 +1530,16 @@ private:
14641530#endif
14651531};
14661532
1467#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
1533#if _LIBCPP_STD_VER >= 17
14681534template<class _InputIterator,
14691535 class _Hash = hash<__iter_key_type<_InputIterator>>,
14701536 class _Pred = equal_to<__iter_key_type<_InputIterator>>,
14711537 class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>,
1472 class = _EnableIf<!__is_allocator<_Hash>::value>,
1473 class = _EnableIf<!is_integral<_Hash>::value>,
1474 class = _EnableIf<!__is_allocator<_Pred>::value>,
1475 class = _EnableIf<__is_allocator<_Allocator>::value>>
1538 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
1539 class = enable_if_t<!__is_allocator<_Hash>::value>,
1540 class = enable_if_t<!is_integral<_Hash>::value>,
1541 class = enable_if_t<!__is_allocator<_Pred>::value>,
1542 class = enable_if_t<__is_allocator<_Allocator>::value>>
14761543unordered_map(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type = 0,
14771544 _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
14781545 -> unordered_map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Hash, _Pred, _Allocator>;
......@@ -1480,52 +1547,55 @@ unordered_map(_InputIterator, _InputIterator, typename allocator_traits<_Allocat
14801547template<class _Key, class _Tp, class _Hash = hash<remove_const_t<_Key>>,
14811548 class _Pred = equal_to<remove_const_t<_Key>>,
14821549 class _Allocator = allocator<pair<const _Key, _Tp>>,
1483 class = _EnableIf<!__is_allocator<_Hash>::value>,
1484 class = _EnableIf<!is_integral<_Hash>::value>,
1485 class = _EnableIf<!__is_allocator<_Pred>::value>,
1486 class = _EnableIf<__is_allocator<_Allocator>::value>>
1550 class = enable_if_t<!__is_allocator<_Hash>::value>,
1551 class = enable_if_t<!is_integral<_Hash>::value>,
1552 class = enable_if_t<!__is_allocator<_Pred>::value>,
1553 class = enable_if_t<__is_allocator<_Allocator>::value>>
14871554unordered_map(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type = 0,
14881555 _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
14891556 -> unordered_map<remove_const_t<_Key>, _Tp, _Hash, _Pred, _Allocator>;
14901557
14911558template<class _InputIterator, class _Allocator,
1492 class = _EnableIf<__is_allocator<_Allocator>::value>>
1559 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
1560 class = enable_if_t<__is_allocator<_Allocator>::value>>
14931561unordered_map(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Allocator)
14941562 -> unordered_map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
14951563 hash<__iter_key_type<_InputIterator>>, equal_to<__iter_key_type<_InputIterator>>, _Allocator>;
14961564
14971565template<class _InputIterator, class _Allocator,
1498 class = _EnableIf<__is_allocator<_Allocator>::value>>
1566 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
1567 class = enable_if_t<__is_allocator<_Allocator>::value>>
14991568unordered_map(_InputIterator, _InputIterator, _Allocator)
15001569 -> unordered_map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
15011570 hash<__iter_key_type<_InputIterator>>, equal_to<__iter_key_type<_InputIterator>>, _Allocator>;
15021571
15031572template<class _InputIterator, class _Hash, class _Allocator,
1504 class = _EnableIf<!__is_allocator<_Hash>::value>,
1505 class = _EnableIf<!is_integral<_Hash>::value>,
1506 class = _EnableIf<__is_allocator<_Allocator>::value>>
1573 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
1574 class = enable_if_t<!__is_allocator<_Hash>::value>,
1575 class = enable_if_t<!is_integral<_Hash>::value>,
1576 class = enable_if_t<__is_allocator<_Allocator>::value>>
15071577unordered_map(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
15081578 -> unordered_map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
15091579 _Hash, equal_to<__iter_key_type<_InputIterator>>, _Allocator>;
15101580
15111581template<class _Key, class _Tp, class _Allocator,
1512 class = _EnableIf<__is_allocator<_Allocator>::value>>
1582 class = enable_if_t<__is_allocator<_Allocator>::value>>
15131583unordered_map(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type, _Allocator)
15141584 -> unordered_map<remove_const_t<_Key>, _Tp,
15151585 hash<remove_const_t<_Key>>,
15161586 equal_to<remove_const_t<_Key>>, _Allocator>;
15171587
15181588template<class _Key, class _Tp, class _Allocator,
1519 class = _EnableIf<__is_allocator<_Allocator>::value>>
1589 class = enable_if_t<__is_allocator<_Allocator>::value>>
15201590unordered_map(initializer_list<pair<_Key, _Tp>>, _Allocator)
15211591 -> unordered_map<remove_const_t<_Key>, _Tp,
15221592 hash<remove_const_t<_Key>>,
15231593 equal_to<remove_const_t<_Key>>, _Allocator>;
15241594
15251595template<class _Key, class _Tp, class _Hash, class _Allocator,
1526 class = _EnableIf<!__is_allocator<_Hash>::value>,
1527 class = _EnableIf<!is_integral<_Hash>::value>,
1528 class = _EnableIf<__is_allocator<_Allocator>::value>>
1596 class = enable_if_t<!__is_allocator<_Hash>::value>,
1597 class = enable_if_t<!is_integral<_Hash>::value>,
1598 class = enable_if_t<__is_allocator<_Allocator>::value>>
15291599unordered_map(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
15301600 -> unordered_map<remove_const_t<_Key>, _Tp, _Hash,
15311601 equal_to<remove_const_t<_Key>>, _Allocator>;
......@@ -1536,9 +1606,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
15361606 size_type __n, const hasher& __hf, const key_equal& __eql)
15371607 : __table_(__hf, __eql)
15381608{
1539#if _LIBCPP_DEBUG_LEVEL == 2
1540 __get_db()->__insert_c(this);
1541#endif
1609 _VSTD::__debug_db_insert_c(this);
15421610 __table_.rehash(__n);
15431611}
15441612
......@@ -1548,9 +1616,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
15481616 const allocator_type& __a)
15491617 : __table_(__hf, __eql, typename __table::allocator_type(__a))
15501618{
1551#if _LIBCPP_DEBUG_LEVEL == 2
1552 __get_db()->__insert_c(this);
1553#endif
1619 _VSTD::__debug_db_insert_c(this);
15541620 __table_.rehash(__n);
15551621}
15561622
......@@ -1560,9 +1626,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
15601626 const allocator_type& __a)
15611627 : __table_(typename __table::allocator_type(__a))
15621628{
1563#if _LIBCPP_DEBUG_LEVEL == 2
1564 __get_db()->__insert_c(this);
1565#endif
1629 _VSTD::__debug_db_insert_c(this);
15661630}
15671631
15681632template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
......@@ -1570,9 +1634,7 @@ template <class _InputIterator>
15701634unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
15711635 _InputIterator __first, _InputIterator __last)
15721636{
1573#if _LIBCPP_DEBUG_LEVEL == 2
1574 __get_db()->__insert_c(this);
1575#endif
1637 _VSTD::__debug_db_insert_c(this);
15761638 insert(__first, __last);
15771639}
15781640
......@@ -1583,9 +1645,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
15831645 const hasher& __hf, const key_equal& __eql)
15841646 : __table_(__hf, __eql)
15851647{
1586#if _LIBCPP_DEBUG_LEVEL == 2
1587 __get_db()->__insert_c(this);
1588#endif
1648 _VSTD::__debug_db_insert_c(this);
15891649 __table_.rehash(__n);
15901650 insert(__first, __last);
15911651}
......@@ -1597,9 +1657,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
15971657 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
15981658 : __table_(__hf, __eql, typename __table::allocator_type(__a))
15991659{
1600#if _LIBCPP_DEBUG_LEVEL == 2
1601 __get_db()->__insert_c(this);
1602#endif
1660 _VSTD::__debug_db_insert_c(this);
16031661 __table_.rehash(__n);
16041662 insert(__first, __last);
16051663}
......@@ -1609,9 +1667,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
16091667 const unordered_map& __u)
16101668 : __table_(__u.__table_)
16111669{
1612#if _LIBCPP_DEBUG_LEVEL == 2
1613 __get_db()->__insert_c(this);
1614#endif
1670 _VSTD::__debug_db_insert_c(this);
16151671 __table_.rehash(__u.bucket_count());
16161672 insert(__u.begin(), __u.end());
16171673}
......@@ -1621,9 +1677,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
16211677 const unordered_map& __u, const allocator_type& __a)
16221678 : __table_(__u.__table_, typename __table::allocator_type(__a))
16231679{
1624#if _LIBCPP_DEBUG_LEVEL == 2
1625 __get_db()->__insert_c(this);
1626#endif
1680 _VSTD::__debug_db_insert_c(this);
16271681 __table_.rehash(__u.bucket_count());
16281682 insert(__u.begin(), __u.end());
16291683}
......@@ -1637,9 +1691,9 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
16371691 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
16381692 : __table_(_VSTD::move(__u.__table_))
16391693{
1694 _VSTD::__debug_db_insert_c(this);
16401695#if _LIBCPP_DEBUG_LEVEL == 2
1641 __get_db()->__insert_c(this);
1642 __get_db()->swap(this, &__u);
1696 __get_db()->swap(this, _VSTD::addressof(__u));
16431697#endif
16441698}
16451699
......@@ -1648,9 +1702,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
16481702 unordered_map&& __u, const allocator_type& __a)
16491703 : __table_(_VSTD::move(__u.__table_), typename __table::allocator_type(__a))
16501704{
1651#if _LIBCPP_DEBUG_LEVEL == 2
1652 __get_db()->__insert_c(this);
1653#endif
1705 _VSTD::__debug_db_insert_c(this);
16541706 if (__a != __u.get_allocator())
16551707 {
16561708 iterator __i = __u.begin();
......@@ -1661,7 +1713,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
16611713 }
16621714#if _LIBCPP_DEBUG_LEVEL == 2
16631715 else
1664 __get_db()->swap(this, &__u);
1716 __get_db()->swap(this, _VSTD::addressof(__u));
16651717#endif
16661718}
16671719
......@@ -1669,9 +1721,7 @@ template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
16691721unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
16701722 initializer_list<value_type> __il)
16711723{
1672#if _LIBCPP_DEBUG_LEVEL == 2
1673 __get_db()->__insert_c(this);
1674#endif
1724 _VSTD::__debug_db_insert_c(this);
16751725 insert(__il.begin(), __il.end());
16761726}
16771727
......@@ -1681,9 +1731,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
16811731 const key_equal& __eql)
16821732 : __table_(__hf, __eql)
16831733{
1684#if _LIBCPP_DEBUG_LEVEL == 2
1685 __get_db()->__insert_c(this);
1686#endif
1734 _VSTD::__debug_db_insert_c(this);
16871735 __table_.rehash(__n);
16881736 insert(__il.begin(), __il.end());
16891737}
......@@ -1694,9 +1742,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
16941742 const key_equal& __eql, const allocator_type& __a)
16951743 : __table_(__hf, __eql, typename __table::allocator_type(__a))
16961744{
1697#if _LIBCPP_DEBUG_LEVEL == 2
1698 __get_db()->__insert_c(this);
1699#endif
1745 _VSTD::__debug_db_insert_c(this);
17001746 __table_.rehash(__n);
17011747 insert(__il.begin(), __il.end());
17021748}
......@@ -1914,11 +1960,9 @@ public:
19141960 _LIBCPP_INLINE_VISIBILITY
19151961 unordered_multimap()
19161962 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
1917 {
1918#if _LIBCPP_DEBUG_LEVEL == 2
1919 __get_db()->__insert_c(this);
1920#endif
1921 }
1963 {
1964 _VSTD::__debug_db_insert_c(this);
1965 }
19221966 explicit unordered_multimap(size_type __n, const hasher& __hf = hasher(),
19231967 const key_equal& __eql = key_equal());
19241968 unordered_multimap(size_type __n, const hasher& __hf,
......@@ -1987,7 +2031,7 @@ public:
19872031#ifndef _LIBCPP_CXX03_LANG
19882032 __table_ = __u.__table_;
19892033#else
1990 if (this != &__u) {
2034 if (this != _VSTD::addressof(__u)) {
19912035 __table_.clear();
19922036 __table_.hash_function() = __u.__table_.hash_function();
19932037 __table_.key_eq() = __u.__table_.key_eq();
......@@ -2167,49 +2211,48 @@ public:
21672211 iterator find(const key_type& __k) {return __table_.find(__k);}
21682212 _LIBCPP_INLINE_VISIBILITY
21692213 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
2170 #if _LIBCPP_STD_VER > 17
2171 template <typename _K2>
2172 _LIBCPP_INLINE_VISIBILITY
2173 _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, iterator>
2174 find(const _K2& __k) {return __table_.find(__k);}
2175 template <typename _K2>
2176 _LIBCPP_INLINE_VISIBILITY
2177 _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, const_iterator>
2178 find(const _K2& __k) const {return __table_.find(__k);}
2179 #endif // _LIBCPP_STD_VER > 17
2214#if _LIBCPP_STD_VER > 17
2215 template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
2216 _LIBCPP_INLINE_VISIBILITY
2217 iterator find(const _K2& __k) {return __table_.find(__k);}
2218 template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
2219 _LIBCPP_INLINE_VISIBILITY
2220 const_iterator find(const _K2& __k) const {return __table_.find(__k);}
2221#endif // _LIBCPP_STD_VER > 17
2222
21802223 _LIBCPP_INLINE_VISIBILITY
21812224 size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
2182 #if _LIBCPP_STD_VER > 17
2183 template <typename _K2>
2184 _LIBCPP_INLINE_VISIBILITY
2185 _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, size_type>
2186 count(const _K2& __k) const {return __table_.__count_multi(__k);}
2187 #endif // _LIBCPP_STD_VER > 17
2188 #if _LIBCPP_STD_VER > 17
2189 _LIBCPP_INLINE_VISIBILITY
2190 bool contains(const key_type& __k) const {return find(__k) != end();}
2225#if _LIBCPP_STD_VER > 17
2226 template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
2227 _LIBCPP_INLINE_VISIBILITY
2228 size_type count(const _K2& __k) const {return __table_.__count_multi(__k);}
2229#endif // _LIBCPP_STD_VER > 17
2230
2231#if _LIBCPP_STD_VER > 17
2232 _LIBCPP_INLINE_VISIBILITY
2233 bool contains(const key_type& __k) const {return find(__k) != end();}
2234
2235 template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
2236 _LIBCPP_INLINE_VISIBILITY
2237 bool contains(const _K2& __k) const {return find(__k) != end();}
2238#endif // _LIBCPP_STD_VER > 17
21912239
2192 template <typename _K2>
2193 _LIBCPP_INLINE_VISIBILITY
2194 _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, bool>
2195 contains(const _K2& __k) const {return find(__k) != end();}
2196 #endif // _LIBCPP_STD_VER > 17
21972240 _LIBCPP_INLINE_VISIBILITY
21982241 pair<iterator, iterator> equal_range(const key_type& __k)
21992242 {return __table_.__equal_range_multi(__k);}
22002243 _LIBCPP_INLINE_VISIBILITY
22012244 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
22022245 {return __table_.__equal_range_multi(__k);}
2203 #if _LIBCPP_STD_VER > 17
2204 template <typename _K2>
2205 _LIBCPP_INLINE_VISIBILITY
2206 _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, pair<iterator, iterator>>
2207 equal_range(const _K2& __k) {return __table_.__equal_range_multi(__k);}
2208 template <typename _K2>
2209 _LIBCPP_INLINE_VISIBILITY
2210 _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, pair<const_iterator, const_iterator>>
2211 equal_range(const _K2& __k) const {return __table_.__equal_range_multi(__k);}
2212 #endif // _LIBCPP_STD_VER > 17
2246#if _LIBCPP_STD_VER > 17
2247 template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
2248 _LIBCPP_INLINE_VISIBILITY
2249 pair<iterator, iterator> equal_range(const _K2& __k)
2250 {return __table_.__equal_range_multi(__k);}
2251 template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
2252 _LIBCPP_INLINE_VISIBILITY
2253 pair<const_iterator, const_iterator> equal_range(const _K2& __k) const
2254 {return __table_.__equal_range_multi(__k);}
2255#endif // _LIBCPP_STD_VER > 17
22132256
22142257 _LIBCPP_INLINE_VISIBILITY
22152258 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
......@@ -2250,28 +2293,29 @@ public:
22502293#if _LIBCPP_DEBUG_LEVEL == 2
22512294
22522295 bool __dereferenceable(const const_iterator* __i) const
2253 {return __table_.__dereferenceable(&__i->__i_);}
2296 {return __table_.__dereferenceable(_VSTD::addressof(__i->__i_));}
22542297 bool __decrementable(const const_iterator* __i) const
2255 {return __table_.__decrementable(&__i->__i_);}
2298 {return __table_.__decrementable(_VSTD::addressof(__i->__i_));}
22562299 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
2257 {return __table_.__addable(&__i->__i_, __n);}
2300 {return __table_.__addable(_VSTD::addressof(__i->__i_), __n);}
22582301 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
2259 {return __table_.__addable(&__i->__i_, __n);}
2302 {return __table_.__addable(_VSTD::addressof(__i->__i_), __n);}
22602303
22612304#endif // _LIBCPP_DEBUG_LEVEL == 2
22622305
22632306
22642307};
22652308
2266#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
2309#if _LIBCPP_STD_VER >= 17
22672310template<class _InputIterator,
22682311 class _Hash = hash<__iter_key_type<_InputIterator>>,
22692312 class _Pred = equal_to<__iter_key_type<_InputIterator>>,
22702313 class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>,
2271 class = _EnableIf<!__is_allocator<_Hash>::value>,
2272 class = _EnableIf<!is_integral<_Hash>::value>,
2273 class = _EnableIf<!__is_allocator<_Pred>::value>,
2274 class = _EnableIf<__is_allocator<_Allocator>::value>>
2314 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
2315 class = enable_if_t<!__is_allocator<_Hash>::value>,
2316 class = enable_if_t<!is_integral<_Hash>::value>,
2317 class = enable_if_t<!__is_allocator<_Pred>::value>,
2318 class = enable_if_t<__is_allocator<_Allocator>::value>>
22752319unordered_multimap(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type = 0,
22762320 _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
22772321 -> unordered_multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Hash, _Pred, _Allocator>;
......@@ -2279,52 +2323,55 @@ unordered_multimap(_InputIterator, _InputIterator, typename allocator_traits<_Al
22792323template<class _Key, class _Tp, class _Hash = hash<remove_const_t<_Key>>,
22802324 class _Pred = equal_to<remove_const_t<_Key>>,
22812325 class _Allocator = allocator<pair<const _Key, _Tp>>,
2282 class = _EnableIf<!__is_allocator<_Hash>::value>,
2283 class = _EnableIf<!is_integral<_Hash>::value>,
2284 class = _EnableIf<!__is_allocator<_Pred>::value>,
2285 class = _EnableIf<__is_allocator<_Allocator>::value>>
2326 class = enable_if_t<!__is_allocator<_Hash>::value>,
2327 class = enable_if_t<!is_integral<_Hash>::value>,
2328 class = enable_if_t<!__is_allocator<_Pred>::value>,
2329 class = enable_if_t<__is_allocator<_Allocator>::value>>
22862330unordered_multimap(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type = 0,
22872331 _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
22882332 -> unordered_multimap<remove_const_t<_Key>, _Tp, _Hash, _Pred, _Allocator>;
22892333
22902334template<class _InputIterator, class _Allocator,
2291 class = _EnableIf<__is_allocator<_Allocator>::value>>
2335 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
2336 class = enable_if_t<__is_allocator<_Allocator>::value>>
22922337unordered_multimap(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Allocator)
22932338 -> unordered_multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
22942339 hash<__iter_key_type<_InputIterator>>, equal_to<__iter_key_type<_InputIterator>>, _Allocator>;
22952340
22962341template<class _InputIterator, class _Allocator,
2297 class = _EnableIf<__is_allocator<_Allocator>::value>>
2342 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
2343 class = enable_if_t<__is_allocator<_Allocator>::value>>
22982344unordered_multimap(_InputIterator, _InputIterator, _Allocator)
22992345 -> unordered_multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
23002346 hash<__iter_key_type<_InputIterator>>, equal_to<__iter_key_type<_InputIterator>>, _Allocator>;
23012347
23022348template<class _InputIterator, class _Hash, class _Allocator,
2303 class = _EnableIf<!__is_allocator<_Hash>::value>,
2304 class = _EnableIf<!is_integral<_Hash>::value>,
2305 class = _EnableIf<__is_allocator<_Allocator>::value>>
2349 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
2350 class = enable_if_t<!__is_allocator<_Hash>::value>,
2351 class = enable_if_t<!is_integral<_Hash>::value>,
2352 class = enable_if_t<__is_allocator<_Allocator>::value>>
23062353unordered_multimap(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
23072354 -> unordered_multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
23082355 _Hash, equal_to<__iter_key_type<_InputIterator>>, _Allocator>;
23092356
23102357template<class _Key, class _Tp, class _Allocator,
2311 class = _EnableIf<__is_allocator<_Allocator>::value>>
2358 class = enable_if_t<__is_allocator<_Allocator>::value>>
23122359unordered_multimap(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type, _Allocator)
23132360 -> unordered_multimap<remove_const_t<_Key>, _Tp,
23142361 hash<remove_const_t<_Key>>,
23152362 equal_to<remove_const_t<_Key>>, _Allocator>;
23162363
23172364template<class _Key, class _Tp, class _Allocator,
2318 class = _EnableIf<__is_allocator<_Allocator>::value>>
2365 class = enable_if_t<__is_allocator<_Allocator>::value>>
23192366unordered_multimap(initializer_list<pair<_Key, _Tp>>, _Allocator)
23202367 -> unordered_multimap<remove_const_t<_Key>, _Tp,
23212368 hash<remove_const_t<_Key>>,
23222369 equal_to<remove_const_t<_Key>>, _Allocator>;
23232370
23242371template<class _Key, class _Tp, class _Hash, class _Allocator,
2325 class = _EnableIf<!__is_allocator<_Hash>::value>,
2326 class = _EnableIf<!is_integral<_Hash>::value>,
2327 class = _EnableIf<__is_allocator<_Allocator>::value>>
2372 class = enable_if_t<!__is_allocator<_Hash>::value>,
2373 class = enable_if_t<!is_integral<_Hash>::value>,
2374 class = enable_if_t<__is_allocator<_Allocator>::value>>
23282375unordered_multimap(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
23292376 -> unordered_multimap<remove_const_t<_Key>, _Tp, _Hash,
23302377 equal_to<remove_const_t<_Key>>, _Allocator>;
......@@ -2335,9 +2382,7 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
23352382 size_type __n, const hasher& __hf, const key_equal& __eql)
23362383 : __table_(__hf, __eql)
23372384{
2338#if _LIBCPP_DEBUG_LEVEL == 2
2339 __get_db()->__insert_c(this);
2340#endif
2385 _VSTD::__debug_db_insert_c(this);
23412386 __table_.rehash(__n);
23422387}
23432388
......@@ -2347,9 +2392,7 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
23472392 const allocator_type& __a)
23482393 : __table_(__hf, __eql, typename __table::allocator_type(__a))
23492394{
2350#if _LIBCPP_DEBUG_LEVEL == 2
2351 __get_db()->__insert_c(this);
2352#endif
2395 _VSTD::__debug_db_insert_c(this);
23532396 __table_.rehash(__n);
23542397}
23552398
......@@ -2358,9 +2401,7 @@ template <class _InputIterator>
23582401unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
23592402 _InputIterator __first, _InputIterator __last)
23602403{
2361#if _LIBCPP_DEBUG_LEVEL == 2
2362 __get_db()->__insert_c(this);
2363#endif
2404 _VSTD::__debug_db_insert_c(this);
23642405 insert(__first, __last);
23652406}
23662407
......@@ -2371,9 +2412,7 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
23712412 const hasher& __hf, const key_equal& __eql)
23722413 : __table_(__hf, __eql)
23732414{
2374#if _LIBCPP_DEBUG_LEVEL == 2
2375 __get_db()->__insert_c(this);
2376#endif
2415 _VSTD::__debug_db_insert_c(this);
23772416 __table_.rehash(__n);
23782417 insert(__first, __last);
23792418}
......@@ -2385,9 +2424,7 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
23852424 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
23862425 : __table_(__hf, __eql, typename __table::allocator_type(__a))
23872426{
2388#if _LIBCPP_DEBUG_LEVEL == 2
2389 __get_db()->__insert_c(this);
2390#endif
2427 _VSTD::__debug_db_insert_c(this);
23912428 __table_.rehash(__n);
23922429 insert(__first, __last);
23932430}
......@@ -2398,9 +2435,7 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
23982435 const allocator_type& __a)
23992436 : __table_(typename __table::allocator_type(__a))
24002437{
2401#if _LIBCPP_DEBUG_LEVEL == 2
2402 __get_db()->__insert_c(this);
2403#endif
2438 _VSTD::__debug_db_insert_c(this);
24042439}
24052440
24062441template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
......@@ -2408,9 +2443,7 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
24082443 const unordered_multimap& __u)
24092444 : __table_(__u.__table_)
24102445{
2411#if _LIBCPP_DEBUG_LEVEL == 2
2412 __get_db()->__insert_c(this);
2413#endif
2446 _VSTD::__debug_db_insert_c(this);
24142447 __table_.rehash(__u.bucket_count());
24152448 insert(__u.begin(), __u.end());
24162449}
......@@ -2420,9 +2453,7 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
24202453 const unordered_multimap& __u, const allocator_type& __a)
24212454 : __table_(__u.__table_, typename __table::allocator_type(__a))
24222455{
2423#if _LIBCPP_DEBUG_LEVEL == 2
2424 __get_db()->__insert_c(this);
2425#endif
2456 _VSTD::__debug_db_insert_c(this);
24262457 __table_.rehash(__u.bucket_count());
24272458 insert(__u.begin(), __u.end());
24282459}
......@@ -2436,9 +2467,9 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
24362467 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
24372468 : __table_(_VSTD::move(__u.__table_))
24382469{
2470 _VSTD::__debug_db_insert_c(this);
24392471#if _LIBCPP_DEBUG_LEVEL == 2
2440 __get_db()->__insert_c(this);
2441 __get_db()->swap(this, &__u);
2472 __get_db()->swap(this, _VSTD::addressof(__u));
24422473#endif
24432474}
24442475
......@@ -2447,9 +2478,7 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
24472478 unordered_multimap&& __u, const allocator_type& __a)
24482479 : __table_(_VSTD::move(__u.__table_), typename __table::allocator_type(__a))
24492480{
2450#if _LIBCPP_DEBUG_LEVEL == 2
2451 __get_db()->__insert_c(this);
2452#endif
2481 _VSTD::__debug_db_insert_c(this);
24532482 if (__a != __u.get_allocator())
24542483 {
24552484 iterator __i = __u.begin();
......@@ -2461,7 +2490,7 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
24612490 }
24622491#if _LIBCPP_DEBUG_LEVEL == 2
24632492 else
2464 __get_db()->swap(this, &__u);
2493 __get_db()->swap(this, _VSTD::addressof(__u));
24652494#endif
24662495}
24672496
......@@ -2469,9 +2498,7 @@ template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
24692498unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
24702499 initializer_list<value_type> __il)
24712500{
2472#if _LIBCPP_DEBUG_LEVEL == 2
2473 __get_db()->__insert_c(this);
2474#endif
2501 _VSTD::__debug_db_insert_c(this);
24752502 insert(__il.begin(), __il.end());
24762503}
24772504
......@@ -2481,9 +2508,7 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
24812508 const key_equal& __eql)
24822509 : __table_(__hf, __eql)
24832510{
2484#if _LIBCPP_DEBUG_LEVEL == 2
2485 __get_db()->__insert_c(this);
2486#endif
2511 _VSTD::__debug_db_insert_c(this);
24872512 __table_.rehash(__n);
24882513 insert(__il.begin(), __il.end());
24892514}
......@@ -2494,9 +2519,7 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
24942519 const key_equal& __eql, const allocator_type& __a)
24952520 : __table_(__hf, __eql, typename __table::allocator_type(__a))
24962521{
2497#if _LIBCPP_DEBUG_LEVEL == 2
2498 __get_db()->__insert_c(this);
2499#endif
2522 _VSTD::__debug_db_insert_c(this);
25002523 __table_.rehash(__n);
25012524 insert(__il.begin(), __il.end());
25022525}
lib/libcxx/include/unordered_set+220-194
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===-------------------------- unordered_set -----------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -182,6 +182,43 @@ public:
182182 void reserve(size_type n);
183183};
184184
185template<class InputIterator,
186 class Hash = hash<typename iterator_traits<InputIterator>::value_type>,
187 class Pred = equal_to<typename iterator_traits<InputIterator>::value_type>,
188 class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
189unordered_set(InputIterator, InputIterator, typename see below::size_type = see below,
190 Hash = Hash(), Pred = Pred(), Allocator = Allocator())
191 -> unordered_set<typename iterator_traits<InputIterator>::value_type,
192 Hash, Pred, Allocator>; // C++17
193
194template<class T, class Hash = hash<T>,
195 class Pred = equal_to<T>, class Allocator = allocator<T>>
196unordered_set(initializer_list<T>, typename see below::size_type = see below,
197 Hash = Hash(), Pred = Pred(), Allocator = Allocator())
198 -> unordered_set<T, Hash, Pred, Allocator>; // C++17
199
200template<class InputIterator, class Allocator>
201unordered_set(InputIterator, InputIterator, typename see below::size_type, Allocator)
202 -> unordered_set<typename iterator_traits<InputIterator>::value_type,
203 hash<typename iterator_traits<InputIterator>::value_type>,
204 equal_to<typename iterator_traits<InputIterator>::value_type>,
205 Allocator>; // C++17
206
207template<class InputIterator, class Hash, class Allocator>
208unordered_set(InputIterator, InputIterator, typename see below::size_type,
209 Hash, Allocator)
210 -> unordered_set<typename iterator_traits<InputIterator>::value_type, Hash,
211 equal_to<typename iterator_traits<InputIterator>::value_type>,
212 Allocator>; // C++17
213
214template<class T, class Allocator>
215unordered_set(initializer_list<T>, typename see below::size_type, Allocator)
216 -> unordered_set<T, hash<T>, equal_to<T>, Allocator>; // C++17
217
218template<class T, class Hash, class Allocator>
219unordered_set(initializer_list<T>, typename see below::size_type, Hash, Allocator)
220 -> unordered_set<T, Hash, equal_to<T>, Allocator>; // C++17
221
185222template <class Value, class Hash, class Pred, class Alloc>
186223 void swap(unordered_set<Value, Hash, Pred, Alloc>& x,
187224 unordered_set<Value, Hash, Pred, Alloc>& y)
......@@ -359,6 +396,42 @@ public:
359396 void reserve(size_type n);
360397};
361398
399template<class InputIterator,
400 class Hash = hash<typename iterator_traits<InputIterator>::value_type>,
401 class Pred = equal_to<typename iterator_traits<InputIterator>::value_type>,
402 class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
403unordered_multiset(InputIterator, InputIterator, see below::size_type = see below,
404 Hash = Hash(), Pred = Pred(), Allocator = Allocator())
405 -> unordered_multiset<typename iterator_traits<InputIterator>::value_type,
406 Hash, Pred, Allocator>; // C++17
407
408template<class T, class Hash = hash<T>,
409 class Pred = equal_to<T>, class Allocator = allocator<T>>
410unordered_multiset(initializer_list<T>, typename see below::size_type = see below,
411 Hash = Hash(), Pred = Pred(), Allocator = Allocator())
412 -> unordered_multiset<T, Hash, Pred, Allocator>; // C++17
413
414template<class InputIterator, class Allocator>
415unordered_multiset(InputIterator, InputIterator, typename see below::size_type, Allocator)
416 -> unordered_multiset<typename iterator_traits<InputIterator>::value_type,
417 hash<typename iterator_traits<InputIterator>::value_type>,
418 equal_to<typename iterator_traits<InputIterator>::value_type>,
419 Allocator>; // C++17
420
421template<class InputIterator, class Hash, class Allocator>
422unordered_multiset(InputIterator, InputIterator, typename see below::size_type,
423 Hash, Allocator)
424 -> unordered_multiset<typename iterator_traits<InputIterator>::value_type, Hash,
425 equal_to<typename iterator_traits<InputIterator>::value_type>, Allocator>; // C++17
426
427template<class T, class Allocator>
428unordered_multiset(initializer_list<T>, typename see below::size_type, Allocator)
429 -> unordered_multiset<T, hash<T>, equal_to<T>, Allocator>; // C++17
430
431template<class T, class Hash, class Allocator>
432unordered_multiset(initializer_list<T>, typename see below::size_type, Hash, Allocator)
433 -> unordered_multiset<T, Hash, equal_to<T>, Allocator>; // C++17
434
362435template <class Value, class Hash, class Pred, class Alloc>
363436 void swap(unordered_multiset<Value, Hash, Pred, Alloc>& x,
364437 unordered_multiset<Value, Hash, Pred, Alloc>& y)
......@@ -390,6 +463,7 @@ template <class Value, class Hash, class Pred, class Alloc>
390463#include <__debug>
391464#include <__functional/is_transparent.h>
392465#include <__hash_table>
466#include <__memory/addressof.h>
393467#include <__node_handle>
394468#include <__utility/forward.h>
395469#include <compare>
......@@ -451,11 +525,9 @@ public:
451525 _LIBCPP_INLINE_VISIBILITY
452526 unordered_set()
453527 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
454 {
455#if _LIBCPP_DEBUG_LEVEL == 2
456 __get_db()->__insert_c(this);
457#endif
458 }
528 {
529 _VSTD::__debug_db_insert_c(this);
530 }
459531 explicit unordered_set(size_type __n, const hasher& __hf = hasher(),
460532 const key_equal& __eql = key_equal());
461533#if _LIBCPP_STD_VER > 11
......@@ -569,7 +641,7 @@ public:
569641#if _LIBCPP_DEBUG_LEVEL == 2
570642 iterator emplace_hint(const_iterator __p, _Args&&... __args)
571643 {
572 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
644 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
573645 "unordered_set::emplace_hint(const_iterator, args...) called with an iterator not"
574646 " referring to this unordered_set");
575647 return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;
......@@ -586,7 +658,7 @@ public:
586658#if _LIBCPP_DEBUG_LEVEL == 2
587659 iterator insert(const_iterator __p, value_type&& __x)
588660 {
589 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
661 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
590662 "unordered_set::insert(const_iterator, value_type&&) called with an iterator not"
591663 " referring to this unordered_set");
592664 return insert(_VSTD::move(__x)).first;
......@@ -607,7 +679,7 @@ public:
607679#if _LIBCPP_DEBUG_LEVEL == 2
608680 iterator insert(const_iterator __p, const value_type& __x)
609681 {
610 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
682 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
611683 "unordered_set::insert(const_iterator, const value_type&) called with an iterator not"
612684 " referring to this unordered_set");
613685 return insert(__x).first;
......@@ -706,49 +778,48 @@ public:
706778 iterator find(const key_type& __k) {return __table_.find(__k);}
707779 _LIBCPP_INLINE_VISIBILITY
708780 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
709 #if _LIBCPP_STD_VER > 17
710 template <typename _K2>
711 _LIBCPP_INLINE_VISIBILITY
712 _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, iterator>
713 find(const _K2& __k) {return __table_.find(__k);}
714 template <typename _K2>
715 _LIBCPP_INLINE_VISIBILITY
716 _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, const_iterator>
717 find(const _K2& __k) const {return __table_.find(__k);}
718 #endif // _LIBCPP_STD_VER > 17
781#if _LIBCPP_STD_VER > 17
782 template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
783 _LIBCPP_INLINE_VISIBILITY
784 iterator find(const _K2& __k) {return __table_.find(__k);}
785 template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
786 _LIBCPP_INLINE_VISIBILITY
787 const_iterator find(const _K2& __k) const {return __table_.find(__k);}
788#endif // _LIBCPP_STD_VER > 17
789
719790 _LIBCPP_INLINE_VISIBILITY
720791 size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
721 #if _LIBCPP_STD_VER > 17
722 template <typename _K2>
723 _LIBCPP_INLINE_VISIBILITY
724 _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, size_type>
725 count(const _K2& __k) const {return __table_.__count_unique(__k);}
726 #endif // _LIBCPP_STD_VER > 17
727 #if _LIBCPP_STD_VER > 17
728 _LIBCPP_INLINE_VISIBILITY
729 bool contains(const key_type& __k) const {return find(__k) != end();}
792#if _LIBCPP_STD_VER > 17
793 template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
794 _LIBCPP_INLINE_VISIBILITY
795 size_type count(const _K2& __k) const {return __table_.__count_unique(__k);}
796#endif // _LIBCPP_STD_VER > 17
797
798#if _LIBCPP_STD_VER > 17
799 _LIBCPP_INLINE_VISIBILITY
800 bool contains(const key_type& __k) const {return find(__k) != end();}
801
802 template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
803 _LIBCPP_INLINE_VISIBILITY
804 bool contains(const _K2& __k) const {return find(__k) != end();}
805#endif // _LIBCPP_STD_VER > 17
730806
731 template <typename _K2>
732 _LIBCPP_INLINE_VISIBILITY
733 _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, bool>
734 contains(const _K2& __k) const {return find(__k) != end();}
735 #endif // _LIBCPP_STD_VER > 17
736807 _LIBCPP_INLINE_VISIBILITY
737808 pair<iterator, iterator> equal_range(const key_type& __k)
738809 {return __table_.__equal_range_unique(__k);}
739810 _LIBCPP_INLINE_VISIBILITY
740811 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
741812 {return __table_.__equal_range_unique(__k);}
742 #if _LIBCPP_STD_VER > 17
743 template <typename _K2>
744 _LIBCPP_INLINE_VISIBILITY
745 _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, pair<iterator, iterator>>
746 equal_range(const _K2& __k) {return __table_.__equal_range_unique(__k);}
747 template <typename _K2>
748 _LIBCPP_INLINE_VISIBILITY
749 _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, pair<const_iterator, const_iterator>>
750 equal_range(const _K2& __k) const {return __table_.__equal_range_unique(__k);}
751 #endif // _LIBCPP_STD_VER > 17
813#if _LIBCPP_STD_VER > 17
814 template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
815 _LIBCPP_INLINE_VISIBILITY
816 pair<iterator, iterator> equal_range(const _K2& __k)
817 {return __table_.__equal_range_unique(__k);}
818 template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
819 _LIBCPP_INLINE_VISIBILITY
820 pair<const_iterator, const_iterator> equal_range(const _K2& __k) const
821 {return __table_.__equal_range_unique(__k);}
822#endif // _LIBCPP_STD_VER > 17
752823
753824 _LIBCPP_INLINE_VISIBILITY
754825 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
......@@ -799,15 +870,16 @@ public:
799870
800871};
801872
802#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
873#if _LIBCPP_STD_VER >= 17
803874template<class _InputIterator,
804875 class _Hash = hash<__iter_value_type<_InputIterator>>,
805876 class _Pred = equal_to<__iter_value_type<_InputIterator>>,
806877 class _Allocator = allocator<__iter_value_type<_InputIterator>>,
807 class = _EnableIf<!__is_allocator<_Hash>::value>,
808 class = _EnableIf<!is_integral<_Hash>::value>,
809 class = _EnableIf<!__is_allocator<_Pred>::value>,
810 class = _EnableIf<__is_allocator<_Allocator>::value>>
878 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
879 class = enable_if_t<!__is_allocator<_Hash>::value>,
880 class = enable_if_t<!is_integral<_Hash>::value>,
881 class = enable_if_t<!__is_allocator<_Pred>::value>,
882 class = enable_if_t<__is_allocator<_Allocator>::value>>
811883unordered_set(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type = 0,
812884 _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
813885 -> unordered_set<__iter_value_type<_InputIterator>, _Hash, _Pred, _Allocator>;
......@@ -815,16 +887,17 @@ unordered_set(_InputIterator, _InputIterator, typename allocator_traits<_Allocat
815887template<class _Tp, class _Hash = hash<_Tp>,
816888 class _Pred = equal_to<_Tp>,
817889 class _Allocator = allocator<_Tp>,
818 class = _EnableIf<!__is_allocator<_Hash>::value>,
819 class = _EnableIf<!is_integral<_Hash>::value>,
820 class = _EnableIf<!__is_allocator<_Pred>::value>,
821 class = _EnableIf<__is_allocator<_Allocator>::value>>
890 class = enable_if_t<!__is_allocator<_Hash>::value>,
891 class = enable_if_t<!is_integral<_Hash>::value>,
892 class = enable_if_t<!__is_allocator<_Pred>::value>,
893 class = enable_if_t<__is_allocator<_Allocator>::value>>
822894unordered_set(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type = 0,
823895 _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
824896 -> unordered_set<_Tp, _Hash, _Pred, _Allocator>;
825897
826898template<class _InputIterator, class _Allocator,
827 class = _EnableIf<__is_allocator<_Allocator>::value>>
899 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
900 class = enable_if_t<__is_allocator<_Allocator>::value>>
828901unordered_set(_InputIterator, _InputIterator,
829902 typename allocator_traits<_Allocator>::size_type, _Allocator)
830903 -> unordered_set<__iter_value_type<_InputIterator>,
......@@ -833,9 +906,10 @@ unordered_set(_InputIterator, _InputIterator,
833906 _Allocator>;
834907
835908template<class _InputIterator, class _Hash, class _Allocator,
836 class = _EnableIf<!__is_allocator<_Hash>::value>,
837 class = _EnableIf<!is_integral<_Hash>::value>,
838 class = _EnableIf<__is_allocator<_Allocator>::value>>
909 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
910 class = enable_if_t<!__is_allocator<_Hash>::value>,
911 class = enable_if_t<!is_integral<_Hash>::value>,
912 class = enable_if_t<__is_allocator<_Allocator>::value>>
839913unordered_set(_InputIterator, _InputIterator,
840914 typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
841915 -> unordered_set<__iter_value_type<_InputIterator>, _Hash,
......@@ -843,14 +917,14 @@ unordered_set(_InputIterator, _InputIterator,
843917 _Allocator>;
844918
845919template<class _Tp, class _Allocator,
846 class = _EnableIf<__is_allocator<_Allocator>::value>>
920 class = enable_if_t<__is_allocator<_Allocator>::value>>
847921unordered_set(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Allocator)
848922 -> unordered_set<_Tp, hash<_Tp>, equal_to<_Tp>, _Allocator>;
849923
850924template<class _Tp, class _Hash, class _Allocator,
851 class = _EnableIf<!__is_allocator<_Hash>::value>,
852 class = _EnableIf<!is_integral<_Hash>::value>,
853 class = _EnableIf<__is_allocator<_Allocator>::value>>
925 class = enable_if_t<!__is_allocator<_Hash>::value>,
926 class = enable_if_t<!is_integral<_Hash>::value>,
927 class = enable_if_t<__is_allocator<_Allocator>::value>>
854928unordered_set(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
855929 -> unordered_set<_Tp, _Hash, equal_to<_Tp>, _Allocator>;
856930#endif
......@@ -860,9 +934,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(size_type __n,
860934 const hasher& __hf, const key_equal& __eql)
861935 : __table_(__hf, __eql)
862936{
863#if _LIBCPP_DEBUG_LEVEL == 2
864 __get_db()->__insert_c(this);
865#endif
937 _VSTD::__debug_db_insert_c(this);
866938 __table_.rehash(__n);
867939}
868940
......@@ -871,9 +943,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(size_type __n,
871943 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
872944 : __table_(__hf, __eql, __a)
873945{
874#if _LIBCPP_DEBUG_LEVEL == 2
875 __get_db()->__insert_c(this);
876#endif
946 _VSTD::__debug_db_insert_c(this);
877947 __table_.rehash(__n);
878948}
879949
......@@ -882,9 +952,7 @@ template <class _InputIterator>
882952unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
883953 _InputIterator __first, _InputIterator __last)
884954{
885#if _LIBCPP_DEBUG_LEVEL == 2
886 __get_db()->__insert_c(this);
887#endif
955 _VSTD::__debug_db_insert_c(this);
888956 insert(__first, __last);
889957}
890958
......@@ -895,9 +963,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
895963 const hasher& __hf, const key_equal& __eql)
896964 : __table_(__hf, __eql)
897965{
898#if _LIBCPP_DEBUG_LEVEL == 2
899 __get_db()->__insert_c(this);
900#endif
966 _VSTD::__debug_db_insert_c(this);
901967 __table_.rehash(__n);
902968 insert(__first, __last);
903969}
......@@ -909,9 +975,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
909975 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
910976 : __table_(__hf, __eql, __a)
911977{
912#if _LIBCPP_DEBUG_LEVEL == 2
913 __get_db()->__insert_c(this);
914#endif
978 _VSTD::__debug_db_insert_c(this);
915979 __table_.rehash(__n);
916980 insert(__first, __last);
917981}
......@@ -922,9 +986,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
922986 const allocator_type& __a)
923987 : __table_(__a)
924988{
925#if _LIBCPP_DEBUG_LEVEL == 2
926 __get_db()->__insert_c(this);
927#endif
989 _VSTD::__debug_db_insert_c(this);
928990}
929991
930992template <class _Value, class _Hash, class _Pred, class _Alloc>
......@@ -932,9 +994,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
932994 const unordered_set& __u)
933995 : __table_(__u.__table_)
934996{
935#if _LIBCPP_DEBUG_LEVEL == 2
936 __get_db()->__insert_c(this);
937#endif
997 _VSTD::__debug_db_insert_c(this);
938998 __table_.rehash(__u.bucket_count());
939999 insert(__u.begin(), __u.end());
9401000}
......@@ -944,9 +1004,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
9441004 const unordered_set& __u, const allocator_type& __a)
9451005 : __table_(__u.__table_, __a)
9461006{
947#if _LIBCPP_DEBUG_LEVEL == 2
948 __get_db()->__insert_c(this);
949#endif
1007 _VSTD::__debug_db_insert_c(this);
9501008 __table_.rehash(__u.bucket_count());
9511009 insert(__u.begin(), __u.end());
9521010}
......@@ -960,9 +1018,9 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
9601018 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
9611019 : __table_(_VSTD::move(__u.__table_))
9621020{
1021 _VSTD::__debug_db_insert_c(this);
9631022#if _LIBCPP_DEBUG_LEVEL == 2
964 __get_db()->__insert_c(this);
965 __get_db()->swap(this, &__u);
1023 __get_db()->swap(this, _VSTD::addressof(__u));
9661024#endif
9671025}
9681026
......@@ -971,9 +1029,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
9711029 unordered_set&& __u, const allocator_type& __a)
9721030 : __table_(_VSTD::move(__u.__table_), __a)
9731031{
974#if _LIBCPP_DEBUG_LEVEL == 2
975 __get_db()->__insert_c(this);
976#endif
1032 _VSTD::__debug_db_insert_c(this);
9771033 if (__a != __u.get_allocator())
9781034 {
9791035 iterator __i = __u.begin();
......@@ -982,7 +1038,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
9821038 }
9831039#if _LIBCPP_DEBUG_LEVEL == 2
9841040 else
985 __get_db()->swap(this, &__u);
1041 __get_db()->swap(this, _VSTD::addressof(__u));
9861042#endif
9871043}
9881044
......@@ -990,9 +1046,7 @@ template <class _Value, class _Hash, class _Pred, class _Alloc>
9901046unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
9911047 initializer_list<value_type> __il)
9921048{
993#if _LIBCPP_DEBUG_LEVEL == 2
994 __get_db()->__insert_c(this);
995#endif
1049 _VSTD::__debug_db_insert_c(this);
9961050 insert(__il.begin(), __il.end());
9971051}
9981052
......@@ -1002,9 +1056,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
10021056 const key_equal& __eql)
10031057 : __table_(__hf, __eql)
10041058{
1005#if _LIBCPP_DEBUG_LEVEL == 2
1006 __get_db()->__insert_c(this);
1007#endif
1059 _VSTD::__debug_db_insert_c(this);
10081060 __table_.rehash(__n);
10091061 insert(__il.begin(), __il.end());
10101062}
......@@ -1015,9 +1067,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
10151067 const key_equal& __eql, const allocator_type& __a)
10161068 : __table_(__hf, __eql, __a)
10171069{
1018#if _LIBCPP_DEBUG_LEVEL == 2
1019 __get_db()->__insert_c(this);
1020#endif
1070 _VSTD::__debug_db_insert_c(this);
10211071 __table_.rehash(__n);
10221072 insert(__il.begin(), __il.end());
10231073}
......@@ -1148,11 +1198,9 @@ public:
11481198 _LIBCPP_INLINE_VISIBILITY
11491199 unordered_multiset()
11501200 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
1151 {
1152#if _LIBCPP_DEBUG_LEVEL == 2
1153 __get_db()->__insert_c(this);
1154#endif
1155 }
1201 {
1202 _VSTD::__debug_db_insert_c(this);
1203 }
11561204 explicit unordered_multiset(size_type __n, const hasher& __hf = hasher(),
11571205 const key_equal& __eql = key_equal());
11581206 unordered_multiset(size_type __n, const hasher& __hf,
......@@ -1372,49 +1420,48 @@ public:
13721420 iterator find(const key_type& __k) {return __table_.find(__k);}
13731421 _LIBCPP_INLINE_VISIBILITY
13741422 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
1375 #if _LIBCPP_STD_VER > 17
1376 template <typename _K2>
1377 _LIBCPP_INLINE_VISIBILITY
1378 _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, iterator>
1379 find(const _K2& __k) {return __table_.find(__k);}
1380 template <typename _K2>
1381 _LIBCPP_INLINE_VISIBILITY
1382 _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, const_iterator>
1383 find(const _K2& __k) const {return __table_.find(__k);}
1384 #endif // _LIBCPP_STD_VER > 17
1423#if _LIBCPP_STD_VER > 17
1424 template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
1425 _LIBCPP_INLINE_VISIBILITY
1426 iterator find(const _K2& __k) {return __table_.find(__k);}
1427 template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
1428 _LIBCPP_INLINE_VISIBILITY
1429 const_iterator find(const _K2& __k) const {return __table_.find(__k);}
1430#endif // _LIBCPP_STD_VER > 17
1431
13851432 _LIBCPP_INLINE_VISIBILITY
13861433 size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
1387 #if _LIBCPP_STD_VER > 17
1388 template <typename _K2>
1389 _LIBCPP_INLINE_VISIBILITY
1390 _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, size_type>
1391 count(const _K2& __k) const {return __table_.__count_multi(__k);}
1392 #endif // _LIBCPP_STD_VER > 17
1393 #if _LIBCPP_STD_VER > 17
1394 _LIBCPP_INLINE_VISIBILITY
1395 bool contains(const key_type& __k) const {return find(__k) != end();}
1434#if _LIBCPP_STD_VER > 17
1435 template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
1436 _LIBCPP_INLINE_VISIBILITY
1437 size_type count(const _K2& __k) const {return __table_.__count_multi(__k);}
1438#endif // _LIBCPP_STD_VER > 17
1439
1440#if _LIBCPP_STD_VER > 17
1441 _LIBCPP_INLINE_VISIBILITY
1442 bool contains(const key_type& __k) const {return find(__k) != end();}
1443
1444 template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
1445 _LIBCPP_INLINE_VISIBILITY
1446 bool contains(const _K2& __k) const {return find(__k) != end();}
1447#endif // _LIBCPP_STD_VER > 17
13961448
1397 template <typename _K2>
1398 _LIBCPP_INLINE_VISIBILITY
1399 _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, bool>
1400 contains(const _K2& __k) const {return find(__k) != end();}
1401 #endif // _LIBCPP_STD_VER > 17
14021449 _LIBCPP_INLINE_VISIBILITY
14031450 pair<iterator, iterator> equal_range(const key_type& __k)
14041451 {return __table_.__equal_range_multi(__k);}
14051452 _LIBCPP_INLINE_VISIBILITY
14061453 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
14071454 {return __table_.__equal_range_multi(__k);}
1408 #if _LIBCPP_STD_VER > 17
1409 template <typename _K2>
1410 _LIBCPP_INLINE_VISIBILITY
1411 _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, pair<iterator, iterator>>
1412 equal_range(const _K2& __k) {return __table_.__equal_range_multi(__k);}
1413 template <typename _K2>
1414 _LIBCPP_INLINE_VISIBILITY
1415 _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, pair<const_iterator, const_iterator>>
1416 equal_range(const _K2& __k) const {return __table_.__equal_range_multi(__k);}
1417 #endif // _LIBCPP_STD_VER > 17
1455#if _LIBCPP_STD_VER > 17
1456 template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
1457 _LIBCPP_INLINE_VISIBILITY
1458 pair<iterator, iterator> equal_range(const _K2& __k)
1459 {return __table_.__equal_range_multi(__k);}
1460 template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
1461 _LIBCPP_INLINE_VISIBILITY
1462 pair<const_iterator, const_iterator> equal_range(const _K2& __k) const
1463 {return __table_.__equal_range_multi(__k);}
1464#endif // _LIBCPP_STD_VER > 17
14181465
14191466 _LIBCPP_INLINE_VISIBILITY
14201467 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
......@@ -1465,31 +1512,33 @@ public:
14651512
14661513};
14671514
1468#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
1515#if _LIBCPP_STD_VER >= 17
14691516template<class _InputIterator,
14701517 class _Hash = hash<__iter_value_type<_InputIterator>>,
14711518 class _Pred = equal_to<__iter_value_type<_InputIterator>>,
14721519 class _Allocator = allocator<__iter_value_type<_InputIterator>>,
1473 class = _EnableIf<!__is_allocator<_Hash>::value>,
1474 class = _EnableIf<!is_integral<_Hash>::value>,
1475 class = _EnableIf<!__is_allocator<_Pred>::value>,
1476 class = _EnableIf<__is_allocator<_Allocator>::value>>
1520 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
1521 class = enable_if_t<!__is_allocator<_Hash>::value>,
1522 class = enable_if_t<!is_integral<_Hash>::value>,
1523 class = enable_if_t<!__is_allocator<_Pred>::value>,
1524 class = enable_if_t<__is_allocator<_Allocator>::value>>
14771525unordered_multiset(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type = 0,
14781526 _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
14791527 -> unordered_multiset<__iter_value_type<_InputIterator>, _Hash, _Pred, _Allocator>;
14801528
14811529template<class _Tp, class _Hash = hash<_Tp>,
14821530 class _Pred = equal_to<_Tp>, class _Allocator = allocator<_Tp>,
1483 class = _EnableIf<!__is_allocator<_Hash>::value>,
1484 class = _EnableIf<!is_integral<_Hash>::value>,
1485 class = _EnableIf<!__is_allocator<_Pred>::value>,
1486 class = _EnableIf<__is_allocator<_Allocator>::value>>
1531 class = enable_if_t<!__is_allocator<_Hash>::value>,
1532 class = enable_if_t<!is_integral<_Hash>::value>,
1533 class = enable_if_t<!__is_allocator<_Pred>::value>,
1534 class = enable_if_t<__is_allocator<_Allocator>::value>>
14871535unordered_multiset(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type = 0,
14881536 _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
14891537 -> unordered_multiset<_Tp, _Hash, _Pred, _Allocator>;
14901538
14911539template<class _InputIterator, class _Allocator,
1492 class = _EnableIf<__is_allocator<_Allocator>::value>>
1540 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
1541 class = enable_if_t<__is_allocator<_Allocator>::value>>
14931542unordered_multiset(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Allocator)
14941543 -> unordered_multiset<__iter_value_type<_InputIterator>,
14951544 hash<__iter_value_type<_InputIterator>>,
......@@ -1497,9 +1546,10 @@ unordered_multiset(_InputIterator, _InputIterator, typename allocator_traits<_Al
14971546 _Allocator>;
14981547
14991548template<class _InputIterator, class _Hash, class _Allocator,
1500 class = _EnableIf<!__is_allocator<_Hash>::value>,
1501 class = _EnableIf<!is_integral<_Hash>::value>,
1502 class = _EnableIf<__is_allocator<_Allocator>::value>>
1549 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
1550 class = enable_if_t<!__is_allocator<_Hash>::value>,
1551 class = enable_if_t<!is_integral<_Hash>::value>,
1552 class = enable_if_t<__is_allocator<_Allocator>::value>>
15031553unordered_multiset(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type,
15041554 _Hash, _Allocator)
15051555 -> unordered_multiset<__iter_value_type<_InputIterator>, _Hash,
......@@ -1507,14 +1557,14 @@ unordered_multiset(_InputIterator, _InputIterator, typename allocator_traits<_Al
15071557 _Allocator>;
15081558
15091559template<class _Tp, class _Allocator,
1510 class = _EnableIf<__is_allocator<_Allocator>::value>>
1560 class = enable_if_t<__is_allocator<_Allocator>::value>>
15111561unordered_multiset(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Allocator)
15121562 -> unordered_multiset<_Tp, hash<_Tp>, equal_to<_Tp>, _Allocator>;
15131563
15141564template<class _Tp, class _Hash, class _Allocator,
1515 class = _EnableIf<!__is_allocator<_Hash>::value>,
1516 class = _EnableIf<!is_integral<_Hash>::value>,
1517 class = _EnableIf<__is_allocator<_Allocator>::value>>
1565 class = enable_if_t<!__is_allocator<_Hash>::value>,
1566 class = enable_if_t<!is_integral<_Hash>::value>,
1567 class = enable_if_t<__is_allocator<_Allocator>::value>>
15181568unordered_multiset(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
15191569 -> unordered_multiset<_Tp, _Hash, equal_to<_Tp>, _Allocator>;
15201570#endif
......@@ -1524,9 +1574,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
15241574 size_type __n, const hasher& __hf, const key_equal& __eql)
15251575 : __table_(__hf, __eql)
15261576{
1527#if _LIBCPP_DEBUG_LEVEL == 2
1528 __get_db()->__insert_c(this);
1529#endif
1577 _VSTD::__debug_db_insert_c(this);
15301578 __table_.rehash(__n);
15311579}
15321580
......@@ -1536,9 +1584,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
15361584 const allocator_type& __a)
15371585 : __table_(__hf, __eql, __a)
15381586{
1539#if _LIBCPP_DEBUG_LEVEL == 2
1540 __get_db()->__insert_c(this);
1541#endif
1587 _VSTD::__debug_db_insert_c(this);
15421588 __table_.rehash(__n);
15431589}
15441590
......@@ -1547,9 +1593,7 @@ template <class _InputIterator>
15471593unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
15481594 _InputIterator __first, _InputIterator __last)
15491595{
1550#if _LIBCPP_DEBUG_LEVEL == 2
1551 __get_db()->__insert_c(this);
1552#endif
1596 _VSTD::__debug_db_insert_c(this);
15531597 insert(__first, __last);
15541598}
15551599
......@@ -1560,9 +1604,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
15601604 const hasher& __hf, const key_equal& __eql)
15611605 : __table_(__hf, __eql)
15621606{
1563#if _LIBCPP_DEBUG_LEVEL == 2
1564 __get_db()->__insert_c(this);
1565#endif
1607 _VSTD::__debug_db_insert_c(this);
15661608 __table_.rehash(__n);
15671609 insert(__first, __last);
15681610}
......@@ -1574,9 +1616,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
15741616 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
15751617 : __table_(__hf, __eql, __a)
15761618{
1577#if _LIBCPP_DEBUG_LEVEL == 2
1578 __get_db()->__insert_c(this);
1579#endif
1619 _VSTD::__debug_db_insert_c(this);
15801620 __table_.rehash(__n);
15811621 insert(__first, __last);
15821622}
......@@ -1587,9 +1627,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
15871627 const allocator_type& __a)
15881628 : __table_(__a)
15891629{
1590#if _LIBCPP_DEBUG_LEVEL == 2
1591 __get_db()->__insert_c(this);
1592#endif
1630 _VSTD::__debug_db_insert_c(this);
15931631}
15941632
15951633template <class _Value, class _Hash, class _Pred, class _Alloc>
......@@ -1597,9 +1635,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
15971635 const unordered_multiset& __u)
15981636 : __table_(__u.__table_)
15991637{
1600#if _LIBCPP_DEBUG_LEVEL == 2
1601 __get_db()->__insert_c(this);
1602#endif
1638 _VSTD::__debug_db_insert_c(this);
16031639 __table_.rehash(__u.bucket_count());
16041640 insert(__u.begin(), __u.end());
16051641}
......@@ -1609,9 +1645,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
16091645 const unordered_multiset& __u, const allocator_type& __a)
16101646 : __table_(__u.__table_, __a)
16111647{
1612#if _LIBCPP_DEBUG_LEVEL == 2
1613 __get_db()->__insert_c(this);
1614#endif
1648 _VSTD::__debug_db_insert_c(this);
16151649 __table_.rehash(__u.bucket_count());
16161650 insert(__u.begin(), __u.end());
16171651}
......@@ -1625,9 +1659,9 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
16251659 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
16261660 : __table_(_VSTD::move(__u.__table_))
16271661{
1662 _VSTD::__debug_db_insert_c(this);
16281663#if _LIBCPP_DEBUG_LEVEL == 2
1629 __get_db()->__insert_c(this);
1630 __get_db()->swap(this, &__u);
1664 __get_db()->swap(this, _VSTD::addressof(__u));
16311665#endif
16321666}
16331667
......@@ -1636,9 +1670,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
16361670 unordered_multiset&& __u, const allocator_type& __a)
16371671 : __table_(_VSTD::move(__u.__table_), __a)
16381672{
1639#if _LIBCPP_DEBUG_LEVEL == 2
1640 __get_db()->__insert_c(this);
1641#endif
1673 _VSTD::__debug_db_insert_c(this);
16421674 if (__a != __u.get_allocator())
16431675 {
16441676 iterator __i = __u.begin();
......@@ -1647,7 +1679,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
16471679 }
16481680#if _LIBCPP_DEBUG_LEVEL == 2
16491681 else
1650 __get_db()->swap(this, &__u);
1682 __get_db()->swap(this, _VSTD::addressof(__u));
16511683#endif
16521684}
16531685
......@@ -1655,9 +1687,7 @@ template <class _Value, class _Hash, class _Pred, class _Alloc>
16551687unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
16561688 initializer_list<value_type> __il)
16571689{
1658#if _LIBCPP_DEBUG_LEVEL == 2
1659 __get_db()->__insert_c(this);
1660#endif
1690 _VSTD::__debug_db_insert_c(this);
16611691 insert(__il.begin(), __il.end());
16621692}
16631693
......@@ -1667,9 +1697,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
16671697 const key_equal& __eql)
16681698 : __table_(__hf, __eql)
16691699{
1670#if _LIBCPP_DEBUG_LEVEL == 2
1671 __get_db()->__insert_c(this);
1672#endif
1700 _VSTD::__debug_db_insert_c(this);
16731701 __table_.rehash(__n);
16741702 insert(__il.begin(), __il.end());
16751703}
......@@ -1680,9 +1708,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
16801708 const key_equal& __eql, const allocator_type& __a)
16811709 : __table_(__hf, __eql, __a)
16821710{
1683#if _LIBCPP_DEBUG_LEVEL == 2
1684 __get_db()->__insert_c(this);
1685#endif
1711 _VSTD::__debug_db_insert_c(this);
16861712 __table_.rehash(__n);
16871713 insert(__il.begin(), __il.end());
16881714}
lib/libcxx/include/utility+22-8
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===-------------------------- utility -----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -79,7 +79,7 @@ struct pair
7979 pair(pair&&) = default;
8080 explicit(see-below) constexpr pair();
8181 explicit(see-below) pair(const T1& x, const T2& y); // constexpr in C++14
82 template <class U, class V> explicit(see-below) pair(U&& x, V&& y); // constexpr in C++14
82 template <class U = T1, class V = T2> explicit(see-below) pair(U&&, V&&); // constexpr in C++14
8383 template <class U, class V> explicit(see-below) pair(const pair<U, V>& p); // constexpr in C++14
8484 template <class U, class V> explicit(see-below) pair(pair<U, V>&& p); // constexpr in C++14
8585 template <class... Args1, class... Args2>
......@@ -95,12 +95,18 @@ struct pair
9595 is_nothrow_swappable_v<T2>); // constexpr in C++20
9696};
9797
98template<class T1, class T2> pair(T1, T2) -> pair<T1, T2>;
99
98100template <class T1, class T2> bool operator==(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
99template <class T1, class T2> bool operator!=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
100template <class T1, class T2> bool operator< (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
101template <class T1, class T2> bool operator> (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
102template <class T1, class T2> bool operator>=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
103template <class T1, class T2> bool operator<=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
101template <class T1, class T2> bool operator!=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20
102template <class T1, class T2> bool operator< (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20
103template <class T1, class T2> bool operator> (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20
104template <class T1, class T2> bool operator>=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20
105template <class T1, class T2> bool operator<=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20
106template <class T1, class T2>
107 constexpr common_comparison_type_t<synth-three-way-result<T1>,
108 synth-three-way-result<T2>>
109 operator<=>(const pair<T1,T2>&, const pair<T1,T2>&); // C++20
104110
105111template <class T1, class T2> pair<V1, V2> make_pair(T1&&, T2&&); // constexpr in C++14
106112template <class T1, class T2>
......@@ -179,7 +185,8 @@ template<class... T>
179185 using index_sequence_for = make_index_sequence<sizeof...(T)>;
180186
181187template<class T, class U=T>
182 T exchange(T& obj, U&& new_value);
188 constexpr T exchange(T& obj, U&& new_value)
189 noexcept(is_nothrow_move_constructible<T>::value && is_nothrow_assignable<T&, U>::value); // constexpr in C++17, noexcept in C++23
183190
184191// 20.2.7, in-place construction // C++17
185192struct in_place_t {
......@@ -211,6 +218,7 @@ template <class T>
211218#include <__debug>
212219#include <__tuple>
213220#include <__utility/as_const.h>
221#include <__utility/auto_cast.h>
214222#include <__utility/cmp.h>
215223#include <__utility/declval.h>
216224#include <__utility/exchange.h>
......@@ -220,11 +228,17 @@ template <class T>
220228#include <__utility/move.h>
221229#include <__utility/pair.h>
222230#include <__utility/piecewise_construct.h>
231#include <__utility/priority_tag.h>
223232#include <__utility/rel_ops.h>
224233#include <__utility/swap.h>
225234#include <__utility/to_underlying.h>
235#include <__utility/transaction.h>
226236#include <compare>
227237#include <initializer_list>
228238#include <version>
229239
240#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
241#pragma GCC system_header
242#endif
243
230244#endif // _LIBCPP_UTILITY
lib/libcxx/include/valarray+10-2
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===-------------------------- valarray ----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -105,6 +105,8 @@ public:
105105 void resize(size_t n, value_type x = value_type());
106106};
107107
108template<class T, size_t cnt> valarray(const T(&)[cnt], size_t) -> valarray<T>;
109
108110class slice
109111{
110112public:
......@@ -346,6 +348,7 @@ template <class T> unspecified2 end(const valarray<T>& v);
346348#include <functional>
347349#include <initializer_list>
348350#include <new>
351#include <version>
349352
350353#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
351354#pragma GCC system_header
......@@ -1081,6 +1084,11 @@ private:
10811084 valarray& __assign_range(const value_type* __f, const value_type* __l);
10821085};
10831086
1087#if _LIBCPP_STD_VER > 14
1088template<class _Tp, size_t _Size>
1089valarray(const _Tp(&)[_Size], size_t) -> valarray<_Tp>;
1090#endif
1091
10841092_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void valarray<size_t>::resize(size_t, size_t))
10851093
10861094template <class _Op, class _Tp>
......@@ -3048,7 +3056,7 @@ template <class _Tp>
30483056valarray<_Tp>&
30493057valarray<_Tp>::operator=(const valarray& __v)
30503058{
3051 if (this != &__v)
3059 if (this != _VSTD::addressof(__v))
30523060 return __assign_range(__v.__begin_, __v.__end_);
30533061 return *this;
30543062}
lib/libcxx/include/variant+14-18
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===------------------------------ variant -------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -233,10 +233,7 @@ public:
233233
234234_LIBCPP_BEGIN_NAMESPACE_STD
235235
236// TODO: GCC 5 lies about its support for C++17 (it says it supports it but it
237// really doesn't). That breaks variant, which uses some C++17 features.
238// Remove this once we drop support for GCC 5.
239#if _LIBCPP_STD_VER > 14 && !(defined(_LIBCPP_COMPILER_GCC) && _GNUC_VER_NEW < 6000)
236#if _LIBCPP_STD_VER > 14
240237
241238// Light N-dimensional array of function pointers. Used in place of std::array to avoid
242239// adding a dependency.
......@@ -269,7 +266,7 @@ template <class _Tp>
269266struct _LIBCPP_TEMPLATE_VIS variant_size;
270267
271268template <class _Tp>
272_LIBCPP_INLINE_VAR constexpr size_t variant_size_v = variant_size<_Tp>::value;
269inline constexpr size_t variant_size_v = variant_size<_Tp>::value;
273270
274271template <class _Tp>
275272struct _LIBCPP_TEMPLATE_VIS variant_size<const _Tp> : variant_size<_Tp> {};
......@@ -309,7 +306,7 @@ struct _LIBCPP_TEMPLATE_VIS variant_alternative<_Ip, variant<_Types...>> {
309306 using type = __type_pack_element<_Ip, _Types...>;
310307};
311308
312_LIBCPP_INLINE_VAR constexpr size_t variant_npos = static_cast<size_t>(-1);
309inline constexpr size_t variant_npos = static_cast<size_t>(-1);
313310
314311constexpr int __choose_index_type(unsigned int __num_elem) {
315312 if (__num_elem < numeric_limits<unsigned char>::max())
......@@ -552,7 +549,7 @@ private:
552549 inline _LIBCPP_INLINE_VISIBILITY
553550 static constexpr auto __make_fdiagonal_impl() {
554551 return __make_dispatch<_Fp, _Vs...>(
555 index_sequence<(__identity<_Vs>{}, _Ip)...>{});
552 index_sequence<((void)__identity<_Vs>{}, _Ip)...>{});
556553 }
557554
558555 template <class _Fp, class... _Vs, size_t... _Is>
......@@ -1196,11 +1193,11 @@ struct __narrowing_check {
11961193 template <class _Dest>
11971194 static auto __test_impl(_Dest (&&)[1]) -> __identity<_Dest>;
11981195 template <class _Dest, class _Source>
1199 using _Apply _LIBCPP_NODEBUG_TYPE = decltype(__test_impl<_Dest>({declval<_Source>()}));
1196 using _Apply _LIBCPP_NODEBUG = decltype(__test_impl<_Dest>({declval<_Source>()}));
12001197};
12011198
12021199template <class _Dest, class _Source>
1203using __check_for_narrowing _LIBCPP_NODEBUG_TYPE =
1200using __check_for_narrowing _LIBCPP_NODEBUG =
12041201 typename _If<
12051202#ifdef _LIBCPP_ENABLE_NARROWING_CONVERSIONS_IN_VARIANT
12061203 false &&
......@@ -1244,18 +1241,18 @@ struct __make_overloads_imp;
12441241template <size_t ..._Idx>
12451242struct __make_overloads_imp<__tuple_indices<_Idx...> > {
12461243 template <class ..._Types>
1247 using _Apply _LIBCPP_NODEBUG_TYPE = __all_overloads<__overload<_Types, _Idx>...>;
1244 using _Apply _LIBCPP_NODEBUG = __all_overloads<__overload<_Types, _Idx>...>;
12481245};
12491246
12501247template <class ..._Types>
1251using _MakeOverloads _LIBCPP_NODEBUG_TYPE = typename __make_overloads_imp<
1248using _MakeOverloads _LIBCPP_NODEBUG = typename __make_overloads_imp<
12521249 __make_indices_imp<sizeof...(_Types), 0> >::template _Apply<_Types...>;
12531250
12541251template <class _Tp, class... _Types>
12551252using __best_match_t =
12561253 typename invoke_result_t<_MakeOverloads<_Types...>, _Tp, _Tp>::type;
12571254
1258} // __variant_detail
1255} // namespace __variant_detail
12591256
12601257template <class... _Types>
12611258class _LIBCPP_TEMPLATE_VIS variant
......@@ -1718,11 +1715,10 @@ inline _LIBCPP_INLINE_VISIBILITY
17181715
17191716template <class... _Types>
17201717inline _LIBCPP_INLINE_VISIBILITY
1721auto swap(variant<_Types...>& __lhs,
1722 variant<_Types...>& __rhs) noexcept(noexcept(__lhs.swap(__rhs)))
1723 -> decltype(__lhs.swap(__rhs)) {
1724 __lhs.swap(__rhs);
1725}
1718auto swap(variant<_Types...>& __lhs, variant<_Types...>& __rhs)
1719 noexcept(noexcept(__lhs.swap(__rhs)))
1720 -> decltype( __lhs.swap(__rhs))
1721 { return __lhs.swap(__rhs); }
17261722
17271723template <class... _Types>
17281724struct _LIBCPP_TEMPLATE_VIS hash<
lib/libcxx/include/vector+207-349
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===------------------------------ vector --------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -245,7 +245,7 @@ public:
245245
246246template <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
247247 vector(InputIterator, InputIterator, Allocator = Allocator())
248 -> vector<typename iterator_traits<InputIterator>::value_type, Allocator>;
248 -> vector<typename iterator_traits<InputIterator>::value_type, Allocator>; // C++17
249249
250250template <class Allocator> struct hash<std::vector<bool, Allocator>>;
251251
......@@ -271,10 +271,11 @@ erase_if(vector<T, Allocator>& c, Predicate pred); // C++20
271271
272272*/
273273
274#include <__config>
275274#include <__bit_reference>
275#include <__config>
276276#include <__debug>
277277#include <__functional_base>
278#include <__iterator/iterator_traits.h>
278279#include <__iterator/wrap_iter.h>
279280#include <__split_buffer>
280281#include <__utility/forward.h>
......@@ -301,245 +302,63 @@ _LIBCPP_PUSH_MACROS
301302
302303_LIBCPP_BEGIN_NAMESPACE_STD
303304
304template <bool>
305class _LIBCPP_TEMPLATE_VIS __vector_base_common
306{
307protected:
308 _LIBCPP_INLINE_VISIBILITY __vector_base_common() {}
309 _LIBCPP_NORETURN void __throw_length_error() const;
310 _LIBCPP_NORETURN void __throw_out_of_range() const;
311};
312
313template <bool __b>
314void
315__vector_base_common<__b>::__throw_length_error() const
316{
317 _VSTD::__throw_length_error("vector");
318}
319
320template <bool __b>
321void
322__vector_base_common<__b>::__throw_out_of_range() const
323{
324 _VSTD::__throw_out_of_range("vector");
325}
326
327_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __vector_base_common<true>)
328
329template <class _Tp, class _Allocator>
330class __vector_base
331 : protected __vector_base_common<true>
332{
333public:
334 typedef _Allocator allocator_type;
335 typedef allocator_traits<allocator_type> __alloc_traits;
336 typedef typename __alloc_traits::size_type size_type;
337protected:
338 typedef _Tp value_type;
339 typedef value_type& reference;
340 typedef const value_type& const_reference;
341 typedef typename __alloc_traits::difference_type difference_type;
342 typedef typename __alloc_traits::pointer pointer;
343 typedef typename __alloc_traits::const_pointer const_pointer;
344 typedef pointer iterator;
345 typedef const_pointer const_iterator;
346
347 pointer __begin_;
348 pointer __end_;
349 __compressed_pair<pointer, allocator_type> __end_cap_;
350
351 _LIBCPP_INLINE_VISIBILITY
352 allocator_type& __alloc() _NOEXCEPT
353 {return __end_cap_.second();}
354 _LIBCPP_INLINE_VISIBILITY
355 const allocator_type& __alloc() const _NOEXCEPT
356 {return __end_cap_.second();}
357 _LIBCPP_INLINE_VISIBILITY
358 pointer& __end_cap() _NOEXCEPT
359 {return __end_cap_.first();}
360 _LIBCPP_INLINE_VISIBILITY
361 const pointer& __end_cap() const _NOEXCEPT
362 {return __end_cap_.first();}
363
364 _LIBCPP_INLINE_VISIBILITY
365 __vector_base()
366 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
367 _LIBCPP_INLINE_VISIBILITY __vector_base(const allocator_type& __a);
368#ifndef _LIBCPP_CXX03_LANG
369 _LIBCPP_INLINE_VISIBILITY __vector_base(allocator_type&& __a) _NOEXCEPT;
370#endif
371 ~__vector_base();
372
373 _LIBCPP_INLINE_VISIBILITY
374 void clear() _NOEXCEPT {__destruct_at_end(__begin_);}
375 _LIBCPP_INLINE_VISIBILITY
376 size_type capacity() const _NOEXCEPT
377 {return static_cast<size_type>(__end_cap() - __begin_);}
378
379 _LIBCPP_INLINE_VISIBILITY
380 void __destruct_at_end(pointer __new_last) _NOEXCEPT;
381
382 _LIBCPP_INLINE_VISIBILITY
383 void __copy_assign_alloc(const __vector_base& __c)
384 {__copy_assign_alloc(__c, integral_constant<bool,
385 __alloc_traits::propagate_on_container_copy_assignment::value>());}
386
387 _LIBCPP_INLINE_VISIBILITY
388 void __move_assign_alloc(__vector_base& __c)
389 _NOEXCEPT_(
390 !__alloc_traits::propagate_on_container_move_assignment::value ||
391 is_nothrow_move_assignable<allocator_type>::value)
392 {__move_assign_alloc(__c, integral_constant<bool,
393 __alloc_traits::propagate_on_container_move_assignment::value>());}
394
395 _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
396 void __throw_length_error() const {
397#ifndef _LIBCPP_NO_EXCEPTIONS
398 __vector_base_common<true>::__throw_length_error();
399#else
400 _VSTD::abort();
401#endif
402 }
403
404 _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
405 void __throw_out_of_range() const {
406#ifndef _LIBCPP_NO_EXCEPTIONS
407 __vector_base_common<true>::__throw_out_of_range();
408#else
409 _VSTD::abort();
410#endif
411 }
412
413private:
414 _LIBCPP_INLINE_VISIBILITY
415 void __copy_assign_alloc(const __vector_base& __c, true_type)
416 {
417 if (__alloc() != __c.__alloc())
418 {
419 clear();
420 __alloc_traits::deallocate(__alloc(), __begin_, capacity());
421 __begin_ = __end_ = __end_cap() = nullptr;
422 }
423 __alloc() = __c.__alloc();
424 }
425
426 _LIBCPP_INLINE_VISIBILITY
427 void __copy_assign_alloc(const __vector_base&, false_type)
428 {}
429
430 _LIBCPP_INLINE_VISIBILITY
431 void __move_assign_alloc(__vector_base& __c, true_type)
432 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
433 {
434 __alloc() = _VSTD::move(__c.__alloc());
435 }
436
437 _LIBCPP_INLINE_VISIBILITY
438 void __move_assign_alloc(__vector_base&, false_type)
439 _NOEXCEPT
440 {}
441};
442
443template <class _Tp, class _Allocator>
444inline _LIBCPP_INLINE_VISIBILITY
445void
446__vector_base<_Tp, _Allocator>::__destruct_at_end(pointer __new_last) _NOEXCEPT
447{
448 pointer __soon_to_be_end = __end_;
449 while (__new_last != __soon_to_be_end)
450 __alloc_traits::destroy(__alloc(), _VSTD::__to_address(--__soon_to_be_end));
451 __end_ = __new_last;
452}
453
454template <class _Tp, class _Allocator>
455inline _LIBCPP_INLINE_VISIBILITY
456__vector_base<_Tp, _Allocator>::__vector_base()
457 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
458 : __begin_(nullptr),
459 __end_(nullptr),
460 __end_cap_(nullptr, __default_init_tag())
461{
462}
463
464template <class _Tp, class _Allocator>
465inline _LIBCPP_INLINE_VISIBILITY
466__vector_base<_Tp, _Allocator>::__vector_base(const allocator_type& __a)
467 : __begin_(nullptr),
468 __end_(nullptr),
469 __end_cap_(nullptr, __a)
470{
471}
472
473#ifndef _LIBCPP_CXX03_LANG
474template <class _Tp, class _Allocator>
475inline _LIBCPP_INLINE_VISIBILITY
476__vector_base<_Tp, _Allocator>::__vector_base(allocator_type&& __a) _NOEXCEPT
477 : __begin_(nullptr),
478 __end_(nullptr),
479 __end_cap_(nullptr, _VSTD::move(__a)) {}
480#endif
481
482template <class _Tp, class _Allocator>
483__vector_base<_Tp, _Allocator>::~__vector_base()
484{
485 if (__begin_ != nullptr)
486 {
487 clear();
488 __alloc_traits::deallocate(__alloc(), __begin_, capacity());
489 }
490}
491
492305template <class _Tp, class _Allocator /* = allocator<_Tp> */>
493306class _LIBCPP_TEMPLATE_VIS vector
494 : private __vector_base<_Tp, _Allocator>
495307{
496308private:
497 typedef __vector_base<_Tp, _Allocator> __base;
498 typedef allocator<_Tp> __default_allocator_type;
309 typedef allocator<_Tp> __default_allocator_type;
499310public:
500 typedef vector __self;
501 typedef _Tp value_type;
502 typedef _Allocator allocator_type;
503 typedef typename __base::__alloc_traits __alloc_traits;
504 typedef typename __base::reference reference;
505 typedef typename __base::const_reference const_reference;
506 typedef typename __base::size_type size_type;
507 typedef typename __base::difference_type difference_type;
508 typedef typename __base::pointer pointer;
509 typedef typename __base::const_pointer const_pointer;
510 typedef __wrap_iter<pointer> iterator;
511 typedef __wrap_iter<const_pointer> const_iterator;
512 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
513 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
311 typedef vector __self;
312 typedef _Tp value_type;
313 typedef _Allocator allocator_type;
314 typedef allocator_traits<allocator_type> __alloc_traits;
315 typedef value_type& reference;
316 typedef const value_type& const_reference;
317 typedef typename __alloc_traits::size_type size_type;
318 typedef typename __alloc_traits::difference_type difference_type;
319 typedef typename __alloc_traits::pointer pointer;
320 typedef typename __alloc_traits::const_pointer const_pointer;
321 typedef __wrap_iter<pointer> iterator;
322 typedef __wrap_iter<const_pointer> const_iterator;
323 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
324 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
514325
515326 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
516327 "Allocator::value_type must be same type as value_type");
517328
518329 _LIBCPP_INLINE_VISIBILITY
519330 vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
520 {
521#if _LIBCPP_DEBUG_LEVEL == 2
522 __get_db()->__insert_c(this);
523#endif
524 }
331 {
332 _VSTD::__debug_db_insert_c(this);
333 }
525334 _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
526335#if _LIBCPP_STD_VER <= 14
527336 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
528337#else
529338 _NOEXCEPT
530339#endif
531 : __base(__a)
340 : __end_cap_(nullptr, __a)
532341 {
533#if _LIBCPP_DEBUG_LEVEL == 2
534 __get_db()->__insert_c(this);
535#endif
342 _VSTD::__debug_db_insert_c(this);
536343 }
537344 explicit vector(size_type __n);
538345#if _LIBCPP_STD_VER > 11
539346 explicit vector(size_type __n, const allocator_type& __a);
540347#endif
541348 vector(size_type __n, const value_type& __x);
542 vector(size_type __n, const value_type& __x, const allocator_type& __a);
349
350 template <class = __enable_if_t<__is_allocator<_Allocator>::value> >
351 vector(size_type __n, const value_type& __x, const allocator_type& __a)
352 : __end_cap_(nullptr, __a)
353 {
354 _VSTD::__debug_db_insert_c(this);
355 if (__n > 0)
356 {
357 __vallocate(__n);
358 __construct_at_end(__n, __x);
359 }
360 }
361
543362 template <class _InputIterator>
544363 vector(_InputIterator __first,
545364 typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value &&
......@@ -572,10 +391,16 @@ public:
572391 _LIBCPP_INLINE_VISIBILITY
573392 ~vector()
574393 {
575 __annotate_delete();
394 __annotate_delete();
576395#if _LIBCPP_DEBUG_LEVEL == 2
577 __get_db()->__erase_c(this);
396 __get_db()->__erase_c(this);
578397#endif
398
399 if (this->__begin_ != nullptr)
400 {
401 __clear();
402 __alloc_traits::deallocate(__alloc(), this->__begin_, capacity());
403 }
579404 }
580405
581406 vector(const vector& __x);
......@@ -680,7 +505,7 @@ public:
680505 {return static_cast<size_type>(this->__end_ - this->__begin_);}
681506 _LIBCPP_INLINE_VISIBILITY
682507 size_type capacity() const _NOEXCEPT
683 {return __base::capacity();}
508 {return static_cast<size_type>(__end_cap() - this->__begin_);}
684509 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
685510 bool empty() const _NOEXCEPT
686511 {return this->__begin_ == this->__end_;}
......@@ -793,7 +618,7 @@ public:
793618 void clear() _NOEXCEPT
794619 {
795620 size_type __old_size = size();
796 __base::clear();
621 __clear();
797622 __annotate_shrink(__old_size);
798623 __invalidate_all_iterators();
799624 }
......@@ -821,6 +646,11 @@ public:
821646#endif // _LIBCPP_DEBUG_LEVEL == 2
822647
823648private:
649 pointer __begin_ = nullptr;
650 pointer __end_ = nullptr;
651 __compressed_pair<pointer, allocator_type> __end_cap_ =
652 __compressed_pair<pointer, allocator_type>(nullptr, __default_init_tag());
653
824654 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
825655 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(pointer __new_last);
826656 void __vallocate(size_type __n);
......@@ -854,7 +684,7 @@ private:
854684 {
855685 __invalidate_iterators_past(__new_last);
856686 size_type __old_size = size();
857 __base::__destruct_at_end(__new_last);
687 __base_destruct_at_end(__new_last);
858688 __annotate_shrink(__old_size);
859689 }
860690
......@@ -918,7 +748,7 @@ private:
918748
919749 struct _ConstructTransaction {
920750 explicit _ConstructTransaction(vector &__v, size_type __n)
921 : __v_(__v), __pos_(__v.__end_), __new_end_(__v.__end_ + __n) {
751 : __v_(__v), __pos_(__v.__end_), __new_end_(__v.__end_ + __n) {
922752#ifndef _LIBCPP_HAS_NO_ASAN
923753 __v_.__annotate_increase(__n);
924754#endif
......@@ -949,19 +779,96 @@ private:
949779 _VSTD::forward<_Args>(__args)...);
950780 ++__tx.__pos_;
951781 }
782
783 _LIBCPP_INLINE_VISIBILITY
784 allocator_type& __alloc() _NOEXCEPT
785 {return this->__end_cap_.second();}
786 _LIBCPP_INLINE_VISIBILITY
787 const allocator_type& __alloc() const _NOEXCEPT
788 {return this->__end_cap_.second();}
789 _LIBCPP_INLINE_VISIBILITY
790 pointer& __end_cap() _NOEXCEPT
791 {return this->__end_cap_.first();}
792 _LIBCPP_INLINE_VISIBILITY
793 const pointer& __end_cap() const _NOEXCEPT
794 {return this->__end_cap_.first();}
795
796 _LIBCPP_INLINE_VISIBILITY
797 void __clear() _NOEXCEPT {__base_destruct_at_end(this->__begin_);}
798
799 _LIBCPP_INLINE_VISIBILITY
800 void __base_destruct_at_end(pointer __new_last) _NOEXCEPT {
801 pointer __soon_to_be_end = this->__end_;
802 while (__new_last != __soon_to_be_end)
803 __alloc_traits::destroy(__alloc(), _VSTD::__to_address(--__soon_to_be_end));
804 this->__end_ = __new_last;
805 }
806
807 _LIBCPP_INLINE_VISIBILITY
808 void __copy_assign_alloc(const vector& __c)
809 {__copy_assign_alloc(__c, integral_constant<bool,
810 __alloc_traits::propagate_on_container_copy_assignment::value>());}
811
812 _LIBCPP_INLINE_VISIBILITY
813 void __move_assign_alloc(vector& __c)
814 _NOEXCEPT_(
815 !__alloc_traits::propagate_on_container_move_assignment::value ||
816 is_nothrow_move_assignable<allocator_type>::value)
817 {__move_assign_alloc(__c, integral_constant<bool,
818 __alloc_traits::propagate_on_container_move_assignment::value>());}
819
820 _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
821 void __throw_length_error() const {
822 _VSTD::__throw_length_error("vector");
823 }
824
825 _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
826 void __throw_out_of_range() const {
827 _VSTD::__throw_out_of_range("vector");
828 }
829
830 _LIBCPP_INLINE_VISIBILITY
831 void __copy_assign_alloc(const vector& __c, true_type)
832 {
833 if (__alloc() != __c.__alloc())
834 {
835 __clear();
836 __alloc_traits::deallocate(__alloc(), this->__begin_, capacity());
837 this->__begin_ = this->__end_ = __end_cap() = nullptr;
838 }
839 __alloc() = __c.__alloc();
840 }
841
842 _LIBCPP_INLINE_VISIBILITY
843 void __copy_assign_alloc(const vector&, false_type)
844 {}
845
846 _LIBCPP_INLINE_VISIBILITY
847 void __move_assign_alloc(vector& __c, true_type)
848 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
849 {
850 __alloc() = _VSTD::move(__c.__alloc());
851 }
852
853 _LIBCPP_INLINE_VISIBILITY
854 void __move_assign_alloc(vector&, false_type)
855 _NOEXCEPT
856 {}
952857};
953858
954#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
859#if _LIBCPP_STD_VER >= 17
955860template<class _InputIterator,
956861 class _Alloc = allocator<__iter_value_type<_InputIterator>>,
957 class = _EnableIf<__is_allocator<_Alloc>::value>
862 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
863 class = enable_if_t<__is_allocator<_Alloc>::value>
958864 >
959865vector(_InputIterator, _InputIterator)
960866 -> vector<__iter_value_type<_InputIterator>, _Alloc>;
961867
962868template<class _InputIterator,
963869 class _Alloc,
964 class = _EnableIf<__is_allocator<_Alloc>::value>
870 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
871 class = enable_if_t<__is_allocator<_Alloc>::value>
965872 >
966873vector(_InputIterator, _InputIterator, _Alloc)
967874 -> vector<__iter_value_type<_InputIterator>, _Alloc>;
......@@ -1063,7 +970,7 @@ vector<_Tp, _Allocator>::__construct_at_end(size_type __n)
1063970{
1064971 _ConstructTransaction __tx(*this, __n);
1065972 const_pointer __new_end = __tx.__new_end_;
1066 for (pointer __pos = __tx.__pos_; __pos != __new_end; ++__pos, __tx.__pos_ = __pos) {
973 for (pointer __pos = __tx.__pos_; __pos != __new_end; __tx.__pos_ = ++__pos) {
1067974 __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__pos));
1068975 }
1069976}
......@@ -1081,7 +988,7 @@ vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x)
1081988{
1082989 _ConstructTransaction __tx(*this, __n);
1083990 const_pointer __new_end = __tx.__new_end_;
1084 for (pointer __pos = __tx.__pos_; __pos != __new_end; ++__pos, __tx.__pos_ = __pos) {
991 for (pointer __pos = __tx.__pos_; __pos != __new_end; __tx.__pos_ = ++__pos) {
1085992 __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__pos), __x);
1086993 }
1087994}
......@@ -1140,9 +1047,7 @@ vector<_Tp, _Allocator>::__append(size_type __n, const_reference __x)
11401047template <class _Tp, class _Allocator>
11411048vector<_Tp, _Allocator>::vector(size_type __n)
11421049{
1143#if _LIBCPP_DEBUG_LEVEL == 2
1144 __get_db()->__insert_c(this);
1145#endif
1050 _VSTD::__debug_db_insert_c(this);
11461051 if (__n > 0)
11471052 {
11481053 __vallocate(__n);
......@@ -1153,11 +1058,9 @@ vector<_Tp, _Allocator>::vector(size_type __n)
11531058#if _LIBCPP_STD_VER > 11
11541059template <class _Tp, class _Allocator>
11551060vector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a)
1156 : __base(__a)
1061 : __end_cap_(nullptr, __a)
11571062{
1158#if _LIBCPP_DEBUG_LEVEL == 2
1159 __get_db()->__insert_c(this);
1160#endif
1063 _VSTD::__debug_db_insert_c(this);
11611064 if (__n > 0)
11621065 {
11631066 __vallocate(__n);
......@@ -1169,23 +1072,7 @@ vector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a)
11691072template <class _Tp, class _Allocator>
11701073vector<_Tp, _Allocator>::vector(size_type __n, const value_type& __x)
11711074{
1172#if _LIBCPP_DEBUG_LEVEL == 2
1173 __get_db()->__insert_c(this);
1174#endif
1175 if (__n > 0)
1176 {
1177 __vallocate(__n);
1178 __construct_at_end(__n, __x);
1179 }
1180}
1181
1182template <class _Tp, class _Allocator>
1183vector<_Tp, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a)
1184 : __base(__a)
1185{
1186#if _LIBCPP_DEBUG_LEVEL == 2
1187 __get_db()->__insert_c(this);
1188#endif
1075 _VSTD::__debug_db_insert_c(this);
11891076 if (__n > 0)
11901077 {
11911078 __vallocate(__n);
......@@ -1203,9 +1090,7 @@ vector<_Tp, _Allocator>::vector(_InputIterator __first,
12031090 typename iterator_traits<_InputIterator>::reference>::value,
12041091 _InputIterator>::type __last)
12051092{
1206#if _LIBCPP_DEBUG_LEVEL == 2
1207 __get_db()->__insert_c(this);
1208#endif
1093 _VSTD::__debug_db_insert_c(this);
12091094 for (; __first != __last; ++__first)
12101095 __emplace_back(*__first);
12111096}
......@@ -1218,11 +1103,9 @@ vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, c
12181103 is_constructible<
12191104 value_type,
12201105 typename iterator_traits<_InputIterator>::reference>::value>::type*)
1221 : __base(__a)
1106 : __end_cap_(nullptr, __a)
12221107{
1223#if _LIBCPP_DEBUG_LEVEL == 2
1224 __get_db()->__insert_c(this);
1225#endif
1108 _VSTD::__debug_db_insert_c(this);
12261109 for (; __first != __last; ++__first)
12271110 __emplace_back(*__first);
12281111}
......@@ -1236,9 +1119,7 @@ vector<_Tp, _Allocator>::vector(_ForwardIterator __first,
12361119 typename iterator_traits<_ForwardIterator>::reference>::value,
12371120 _ForwardIterator>::type __last)
12381121{
1239#if _LIBCPP_DEBUG_LEVEL == 2
1240 __get_db()->__insert_c(this);
1241#endif
1122 _VSTD::__debug_db_insert_c(this);
12421123 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
12431124 if (__n > 0)
12441125 {
......@@ -1254,11 +1135,9 @@ vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __las
12541135 is_constructible<
12551136 value_type,
12561137 typename iterator_traits<_ForwardIterator>::reference>::value>::type*)
1257 : __base(__a)
1138 : __end_cap_(nullptr, __a)
12581139{
1259#if _LIBCPP_DEBUG_LEVEL == 2
1260 __get_db()->__insert_c(this);
1261#endif
1140 _VSTD::__debug_db_insert_c(this);
12621141 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
12631142 if (__n > 0)
12641143 {
......@@ -1269,11 +1148,9 @@ vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __las
12691148
12701149template <class _Tp, class _Allocator>
12711150vector<_Tp, _Allocator>::vector(const vector& __x)
1272 : __base(__alloc_traits::select_on_container_copy_construction(__x.__alloc()))
1151 : __end_cap_(nullptr, __alloc_traits::select_on_container_copy_construction(__x.__alloc()))
12731152{
1274#if _LIBCPP_DEBUG_LEVEL == 2
1275 __get_db()->__insert_c(this);
1276#endif
1153 _VSTD::__debug_db_insert_c(this);
12771154 size_type __n = __x.size();
12781155 if (__n > 0)
12791156 {
......@@ -1284,11 +1161,9 @@ vector<_Tp, _Allocator>::vector(const vector& __x)
12841161
12851162template <class _Tp, class _Allocator>
12861163vector<_Tp, _Allocator>::vector(const vector& __x, const __identity_t<allocator_type>& __a)
1287 : __base(__a)
1164 : __end_cap_(nullptr, __a)
12881165{
1289#if _LIBCPP_DEBUG_LEVEL == 2
1290 __get_db()->__insert_c(this);
1291#endif
1166 _VSTD::__debug_db_insert_c(this);
12921167 size_type __n = __x.size();
12931168 if (__n > 0)
12941169 {
......@@ -1307,11 +1182,11 @@ vector<_Tp, _Allocator>::vector(vector&& __x)
13071182#else
13081183 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
13091184#endif
1310 : __base(_VSTD::move(__x.__alloc()))
1185 : __end_cap_(nullptr, _VSTD::move(__x.__alloc()))
13111186{
1187 _VSTD::__debug_db_insert_c(this);
13121188#if _LIBCPP_DEBUG_LEVEL == 2
1313 __get_db()->__insert_c(this);
1314 __get_db()->swap(this, &__x);
1189 __get_db()->swap(this, _VSTD::addressof(__x));
13151190#endif
13161191 this->__begin_ = __x.__begin_;
13171192 this->__end_ = __x.__end_;
......@@ -1322,11 +1197,9 @@ vector<_Tp, _Allocator>::vector(vector&& __x)
13221197template <class _Tp, class _Allocator>
13231198inline _LIBCPP_INLINE_VISIBILITY
13241199vector<_Tp, _Allocator>::vector(vector&& __x, const __identity_t<allocator_type>& __a)
1325 : __base(__a)
1200 : __end_cap_(nullptr, __a)
13261201{
1327#if _LIBCPP_DEBUG_LEVEL == 2
1328 __get_db()->__insert_c(this);
1329#endif
1202 _VSTD::__debug_db_insert_c(this);
13301203 if (__a == __x.__alloc())
13311204 {
13321205 this->__begin_ = __x.__begin_;
......@@ -1334,7 +1207,7 @@ vector<_Tp, _Allocator>::vector(vector&& __x, const __identity_t<allocator_type>
13341207 this->__end_cap() = __x.__end_cap();
13351208 __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
13361209#if _LIBCPP_DEBUG_LEVEL == 2
1337 __get_db()->swap(this, &__x);
1210 __get_db()->swap(this, _VSTD::addressof(__x));
13381211#endif
13391212 }
13401213 else
......@@ -1348,9 +1221,7 @@ template <class _Tp, class _Allocator>
13481221inline _LIBCPP_INLINE_VISIBILITY
13491222vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il)
13501223{
1351#if _LIBCPP_DEBUG_LEVEL == 2
1352 __get_db()->__insert_c(this);
1353#endif
1224 _VSTD::__debug_db_insert_c(this);
13541225 if (__il.size() > 0)
13551226 {
13561227 __vallocate(__il.size());
......@@ -1361,11 +1232,9 @@ vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il)
13611232template <class _Tp, class _Allocator>
13621233inline _LIBCPP_INLINE_VISIBILITY
13631234vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
1364 : __base(__a)
1235 : __end_cap_(nullptr, __a)
13651236{
1366#if _LIBCPP_DEBUG_LEVEL == 2
1367 __get_db()->__insert_c(this);
1368#endif
1237 _VSTD::__debug_db_insert_c(this);
13691238 if (__il.size() > 0)
13701239 {
13711240 __vallocate(__il.size());
......@@ -1389,7 +1258,7 @@ void
13891258vector<_Tp, _Allocator>::__move_assign(vector& __c, false_type)
13901259 _NOEXCEPT_(__alloc_traits::is_always_equal::value)
13911260{
1392 if (__base::__alloc() != __c.__alloc())
1261 if (__alloc() != __c.__alloc())
13931262 {
13941263 typedef move_iterator<iterator> _Ip;
13951264 assign(_Ip(__c.begin()), _Ip(__c.end()));
......@@ -1404,13 +1273,13 @@ vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type)
14041273 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
14051274{
14061275 __vdeallocate();
1407 __base::__move_assign_alloc(__c); // this can throw
1276 __move_assign_alloc(__c); // this can throw
14081277 this->__begin_ = __c.__begin_;
14091278 this->__end_ = __c.__end_;
14101279 this->__end_cap() = __c.__end_cap();
14111280 __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr;
14121281#if _LIBCPP_DEBUG_LEVEL == 2
1413 __get_db()->swap(this, &__c);
1282 __get_db()->swap(this, _VSTD::addressof(__c));
14141283#endif
14151284}
14161285
......@@ -1421,9 +1290,9 @@ inline _LIBCPP_INLINE_VISIBILITY
14211290vector<_Tp, _Allocator>&
14221291vector<_Tp, _Allocator>::operator=(const vector& __x)
14231292{
1424 if (this != &__x)
1293 if (this != _VSTD::addressof(__x))
14251294 {
1426 __base::__copy_assign_alloc(__x);
1295 __copy_assign_alloc(__x);
14271296 assign(__x.__begin_, __x.__end_);
14281297 }
14291298 return *this;
......@@ -1605,6 +1474,8 @@ vector<_Tp, _Allocator>::reserve(size_type __n)
16051474{
16061475 if (__n > capacity())
16071476 {
1477 if (__n > max_size())
1478 this->__throw_length_error();
16081479 allocator_type& __a = this->__alloc();
16091480 __split_buffer<value_type, allocator_type&> __v(__n, size(), __a);
16101481 __swap_out_circular_buffer(__v);
......@@ -1728,11 +1599,8 @@ inline _LIBCPP_INLINE_VISIBILITY
17281599typename vector<_Tp, _Allocator>::iterator
17291600vector<_Tp, _Allocator>::erase(const_iterator __position)
17301601{
1731#if _LIBCPP_DEBUG_LEVEL == 2
1732 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1733 "vector::erase(iterator) called with an iterator not"
1734 " referring to this vector");
1735#endif
1602 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this,
1603 "vector::erase(iterator) called with an iterator not referring to this vector");
17361604 _LIBCPP_ASSERT(__position != end(),
17371605 "vector::erase(iterator) called with a non-dereferenceable iterator");
17381606 difference_type __ps = __position - cbegin();
......@@ -1747,14 +1615,11 @@ template <class _Tp, class _Allocator>
17471615typename vector<_Tp, _Allocator>::iterator
17481616vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last)
17491617{
1750#if _LIBCPP_DEBUG_LEVEL == 2
1751 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
1752 "vector::erase(iterator, iterator) called with an iterator not"
1753 " referring to this vector");
1754 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__last) == this,
1755 "vector::erase(iterator, iterator) called with an iterator not"
1756 " referring to this vector");
1757#endif
1618 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__first)) == this,
1619 "vector::erase(iterator, iterator) called with an iterator not referring to this vector");
1620 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__last)) == this,
1621 "vector::erase(iterator, iterator) called with an iterator not referring to this vector");
1622
17581623 _LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range");
17591624 pointer __p = this->__begin_ + (__first - begin());
17601625 if (__first != __last) {
......@@ -1775,7 +1640,7 @@ vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointe
17751640 pointer __i = __from_s + __n;
17761641 _ConstructTransaction __tx(*this, __from_e - __i);
17771642 for (pointer __pos = __tx.__pos_; __i < __from_e;
1778 ++__i, ++__pos, __tx.__pos_ = __pos) {
1643 ++__i, (void) ++__pos, __tx.__pos_ = __pos) {
17791644 __alloc_traits::construct(this->__alloc(),
17801645 _VSTD::__to_address(__pos),
17811646 _VSTD::move(*__i));
......@@ -1788,11 +1653,8 @@ template <class _Tp, class _Allocator>
17881653typename vector<_Tp, _Allocator>::iterator
17891654vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
17901655{
1791#if _LIBCPP_DEBUG_LEVEL == 2
1792 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1793 "vector::insert(iterator, x) called with an iterator not"
1794 " referring to this vector");
1795#endif
1656 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this,
1657 "vector::insert(iterator, x) called with an iterator not referring to this vector");
17961658 pointer __p = this->__begin_ + (__position - begin());
17971659 if (this->__end_ < this->__end_cap())
17981660 {
......@@ -1825,11 +1687,8 @@ template <class _Tp, class _Allocator>
18251687typename vector<_Tp, _Allocator>::iterator
18261688vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x)
18271689{
1828#if _LIBCPP_DEBUG_LEVEL == 2
1829 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1830 "vector::insert(iterator, x) called with an iterator not"
1831 " referring to this vector");
1832#endif
1690 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this,
1691 "vector::insert(iterator, x) called with an iterator not referring to this vector");
18331692 pointer __p = this->__begin_ + (__position - begin());
18341693 if (this->__end_ < this->__end_cap())
18351694 {
......@@ -1858,11 +1717,8 @@ template <class... _Args>
18581717typename vector<_Tp, _Allocator>::iterator
18591718vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args)
18601719{
1861#if _LIBCPP_DEBUG_LEVEL == 2
1862 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1863 "vector::emplace(iterator, x) called with an iterator not"
1864 " referring to this vector");
1865#endif
1720 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this,
1721 "vector::emplace(iterator, x) called with an iterator not referring to this vector");
18661722 pointer __p = this->__begin_ + (__position - begin());
18671723 if (this->__end_ < this->__end_cap())
18681724 {
......@@ -1893,11 +1749,8 @@ template <class _Tp, class _Allocator>
18931749typename vector<_Tp, _Allocator>::iterator
18941750vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x)
18951751{
1896#if _LIBCPP_DEBUG_LEVEL == 2
1897 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1898 "vector::insert(iterator, n, x) called with an iterator not"
1899 " referring to this vector");
1900#endif
1752 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this,
1753 "vector::insert(iterator, n, x) called with an iterator not referring to this vector");
19011754 pointer __p = this->__begin_ + (__position - begin());
19021755 if (__n > 0)
19031756 {
......@@ -1944,11 +1797,8 @@ typename enable_if
19441797>::type
19451798vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
19461799{
1947#if _LIBCPP_DEBUG_LEVEL == 2
1948 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1949 "vector::insert(iterator, range) called with an iterator not"
1950 " referring to this vector");
1951#endif
1800 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this,
1801 "vector::insert(iterator, range) called with an iterator not referring to this vector");
19521802 difference_type __off = __position - begin();
19531803 pointer __p = this->__begin_ + __off;
19541804 allocator_type& __a = this->__alloc();
......@@ -1997,11 +1847,8 @@ typename enable_if
19971847>::type
19981848vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
19991849{
2000#if _LIBCPP_DEBUG_LEVEL == 2
2001 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
2002 "vector::insert(iterator, range) called with an iterator not"
2003 " referring to this vector");
2004#endif
1850 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this,
1851 "vector::insert(iterator, range) called with an iterator not referring to this vector");
20051852 pointer __p = this->__begin_ + (__position - begin());
20061853 difference_type __n = _VSTD::distance(__first, __last);
20071854 if (__n > 0)
......@@ -2079,7 +1926,7 @@ vector<_Tp, _Allocator>::swap(vector& __x)
20791926 _VSTD::__swap_allocator(this->__alloc(), __x.__alloc(),
20801927 integral_constant<bool,__alloc_traits::propagate_on_container_swap::value>());
20811928#if _LIBCPP_DEBUG_LEVEL == 2
2082 __get_db()->swap(this, &__x);
1929 __get_db()->swap(this, _VSTD::addressof(__x));
20831930#endif
20841931}
20851932
......@@ -2184,7 +2031,6 @@ struct __has_storage_type<vector<bool, _Allocator> >
21842031
21852032template <class _Allocator>
21862033class _LIBCPP_TEMPLATE_VIS vector<bool, _Allocator>
2187 : private __vector_base_common<true>
21882034{
21892035public:
21902036 typedef vector __self;
......@@ -2453,6 +2299,16 @@ public:
24532299 bool __invariants() const;
24542300
24552301private:
2302 _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
2303 void __throw_length_error() const {
2304 _VSTD::__throw_length_error("vector");
2305 }
2306
2307 _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
2308 void __throw_out_of_range() const {
2309 _VSTD::__throw_out_of_range("vector");
2310 }
2311
24562312 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
24572313 void __vallocate(size_type __n);
24582314 void __vdeallocate() _NOEXCEPT;
......@@ -2874,7 +2730,7 @@ template <class _Allocator>
28742730vector<bool, _Allocator>&
28752731vector<bool, _Allocator>::operator=(const vector& __v)
28762732{
2877 if (this != &__v)
2733 if (this != _VSTD::addressof(__v))
28782734 {
28792735 __copy_assign_alloc(__v);
28802736 if (__v.__size_)
......@@ -2978,7 +2834,7 @@ vector<bool, _Allocator>::assign(size_type __n, const value_type& __x)
29782834 __size_ = __n;
29792835 else
29802836 {
2981 vector __v(__alloc());
2837 vector __v(get_allocator());
29822838 __v.reserve(__recommend(__n));
29832839 __v.__size_ = __n;
29842840 swap(__v);
......@@ -3033,7 +2889,9 @@ vector<bool, _Allocator>::reserve(size_type __n)
30332889{
30342890 if (__n > capacity())
30352891 {
3036 vector __v(this->__alloc());
2892 if (__n > max_size())
2893 this->__throw_length_error();
2894 vector __v(this->get_allocator());
30372895 __v.__vallocate(__n);
30382896 __v.__construct_at_end(this->begin(), this->end());
30392897 swap(__v);
......@@ -3103,7 +2961,7 @@ vector<bool, _Allocator>::insert(const_iterator __position, const value_type& __
31032961 }
31042962 else
31052963 {
3106 vector __v(__alloc());
2964 vector __v(get_allocator());
31072965 __v.reserve(__recommend(__size_ + 1));
31082966 __v.__size_ = __size_ + 1;
31092967 __r = _VSTD::copy(cbegin(), __position, __v.begin());
......@@ -3129,7 +2987,7 @@ vector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const
31292987 }
31302988 else
31312989 {
3132 vector __v(__alloc());
2990 vector __v(get_allocator());
31332991 __v.reserve(__recommend(__size_ + __n));
31342992 __v.__size_ = __size_ + __n;
31352993 __r = _VSTD::copy(cbegin(), __position, __v.begin());
......@@ -3158,7 +3016,7 @@ vector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __fir
31583016 ++this->__size_;
31593017 back() = *__first;
31603018 }
3161 vector __v(__alloc());
3019 vector __v(get_allocator());
31623020 if (__first != __last)
31633021 {
31643022#ifndef _LIBCPP_NO_EXCEPTIONS
......@@ -3208,7 +3066,7 @@ vector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __f
32083066 }
32093067 else
32103068 {
3211 vector __v(__alloc());
3069 vector __v(get_allocator());
32123070 __v.reserve(__recommend(__size_ + __n));
32133071 __v.__size_ = __size_ + __n;
32143072 __r = _VSTD::copy(cbegin(), __position, __v.begin());
......@@ -3275,7 +3133,7 @@ vector<bool, _Allocator>::resize(size_type __sz, value_type __x)
32753133 }
32763134 else
32773135 {
3278 vector __v(__alloc());
3136 vector __v(get_allocator());
32793137 __v.reserve(__recommend(__size_ + __n));
32803138 __v.__size_ = __size_ + __n;
32813139 __r = _VSTD::copy(cbegin(), cend(), __v.begin());
lib/libcxx/include/version+48-41
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- version ----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -14,7 +14,9 @@
1414 version synopsis
1515
1616Macro name Value Headers
17__cpp_lib_adaptor_iterator_pair_constructor 202106L <queue> <stack>
1718__cpp_lib_addressof_constexpr 201603L <memory>
19__cpp_lib_allocate_at_least 202106L <memory>
1820__cpp_lib_allocator_traits_is_always_equal 201411L <deque> <forward_list> <list>
1921 <map> <memory> <scoped_allocator>
2022 <set> <string> <unordered_map>
......@@ -24,6 +26,8 @@ __cpp_lib_apply 201603L <tuple>
2426__cpp_lib_array_constexpr 201811L <array> <iterator>
2527 201603L // C++17
2628__cpp_lib_as_const 201510L <utility>
29__cpp_lib_associative_heterogeneous_erasure 202110L <map> <set> <unordered_map>
30 <unordered_set>
2731__cpp_lib_assume_aligned 201811L <memory>
2832__cpp_lib_atomic_flag_test 201907L <atomic>
2933__cpp_lib_atomic_float 201711L <atomic>
......@@ -41,6 +45,7 @@ __cpp_lib_bool_constant 201505L <type_traits>
4145__cpp_lib_bounded_array_traits 201902L <type_traits>
4246__cpp_lib_boyer_moore_searcher 201603L <functional>
4347__cpp_lib_byte 201603L <cstddef>
48__cpp_lib_byteswap 202110L <bit>
4449__cpp_lib_char8_t 201811L <atomic> <filesystem> <istream>
4550 <limits> <locale> <ostream>
4651 <string> <string_view>
......@@ -59,6 +64,7 @@ __cpp_lib_constexpr_numeric 201911L <numeric>
5964__cpp_lib_constexpr_string 201811L <string>
6065__cpp_lib_constexpr_string_view 201811L <string_view>
6166__cpp_lib_constexpr_tuple 201811L <tuple>
67__cpp_lib_constexpr_typeinfo 202106L <typeinfo>
6268__cpp_lib_constexpr_utility 201811L <utility>
6369__cpp_lib_constexpr_vector 201907L <vector>
6470__cpp_lib_coroutine 201902L <coroutine>
......@@ -72,7 +78,7 @@ __cpp_lib_exchange_function 201304L <utility>
7278__cpp_lib_execution 201902L <execution>
7379 201603L // C++17
7480__cpp_lib_filesystem 201703L <filesystem>
75__cpp_lib_format 201907L <format>
81__cpp_lib_format 202106L <format>
7682__cpp_lib_gcd_lcm 201606L <numeric>
7783__cpp_lib_generic_associative_lookup 201304L <map> <set>
7884__cpp_lib_generic_unordered_lookup 201811L <unordered_map> <unordered_set>
......@@ -86,6 +92,7 @@ __cpp_lib_integer_sequence 201304L <utility>
8692__cpp_lib_integral_constant_callable 201304L <type_traits>
8793__cpp_lib_interpolate 201902L <cmath> <numeric>
8894__cpp_lib_invoke 201411L <functional>
95__cpp_lib_invoke_r 202106L <functional>
8996__cpp_lib_is_aggregate 201703L <type_traits>
9097__cpp_lib_is_constant_evaluated 201811L <type_traits>
9198__cpp_lib_is_final 201402L <type_traits>
......@@ -108,6 +115,8 @@ __cpp_lib_map_try_emplace 201411L <map>
108115__cpp_lib_math_constants 201907L <numbers>
109116__cpp_lib_math_special_functions 201603L <cmath>
110117__cpp_lib_memory_resource 201603L <memory_resource>
118__cpp_lib_monadic_optional 202110L <optional>
119__cpp_lib_move_only_function 202110L <functional>
111120__cpp_lib_node_extract 201606L <map> <set> <unordered_map>
112121 <unordered_set>
113122__cpp_lib_nonmember_container_access 201411L <array> <deque> <forward_list>
......@@ -117,11 +126,14 @@ __cpp_lib_nonmember_container_access 201411L <array> <deque>
117126__cpp_lib_not_fn 201603L <functional>
118127__cpp_lib_null_iterators 201304L <iterator>
119128__cpp_lib_optional 201606L <optional>
129__cpp_lib_out_ptr 202106L <memory>
120130__cpp_lib_parallel_algorithm 201603L <algorithm> <numeric>
121__cpp_lib_polymorphic_allocator 201902L <memory>
131__cpp_lib_polymorphic_allocator 201902L <memory_resource>
122132__cpp_lib_quoted_string_io 201304L <iomanip>
123133__cpp_lib_ranges 201811L <algorithm> <functional> <iterator>
124134 <memory> <ranges>
135__cpp_lib_ranges_starts_ends_with 202106L <algorithm>
136__cpp_lib_ranges_zip 202110L <ranges> <tuple> <utility>
125137__cpp_lib_raw_memory_algorithms 201606L <memory>
126138__cpp_lib_remove_cvref 201711L <type_traits>
127139__cpp_lib_result_of_sfinae 201210L <functional> <type_traits>
......@@ -137,11 +149,13 @@ __cpp_lib_shift 201806L <algorithm>
137149__cpp_lib_smart_ptr_for_overwrite 202002L <memory>
138150__cpp_lib_source_location 201907L <source_location>
139151__cpp_lib_span 202002L <span>
152__cpp_lib_spanstream 202106L <spanstream>
140153__cpp_lib_ssize 201902L <iterator>
141154__cpp_lib_stacktrace 202011L <stacktrace>
142155__cpp_lib_starts_ends_with 201711L <string> <string_view>
143156__cpp_lib_stdatomic_h 202011L <stdatomic.h>
144157__cpp_lib_string_contains 202011L <string> <string_view>
158__cpp_lib_string_resize_and_overwrite 202110L <string>
145159__cpp_lib_string_udls 201304L <string>
146160__cpp_lib_string_view 201803L <string> <string_view>
147161 201606L // C++17
......@@ -149,13 +163,14 @@ __cpp_lib_syncbuf 201803L <syncstream>
149163__cpp_lib_three_way_comparison 201907L <compare>
150164__cpp_lib_to_address 201711L <memory>
151165__cpp_lib_to_array 201907L <array>
152__cpp_lib_to_chars 201611L <utility>
166__cpp_lib_to_chars 201611L <charconv>
153167__cpp_lib_to_underlying 202102L <utility>
154168__cpp_lib_transformation_trait_aliases 201304L <type_traits>
155169__cpp_lib_transparent_operators 201510L <functional> <memory>
156170 201210L // C++14
157171__cpp_lib_tuple_element_t 201402L <tuple>
158172__cpp_lib_tuples_by_type 201304L <tuple> <utility>
173__cpp_lib_type_identity 201806L <type_traits>
159174__cpp_lib_type_trait_variable_templates 201510L <type_traits>
160175__cpp_lib_uncaught_exceptions 201411L <exception>
161176__cpp_lib_unordered_map_try_emplace 201411L <unordered_map>
......@@ -199,17 +214,13 @@ __cpp_lib_void_t 201411L <type_traits>
199214#endif
200215
201216#if _LIBCPP_STD_VER > 14
202# if !defined(_LIBCPP_HAS_NO_BUILTIN_ADDRESSOF)
203# define __cpp_lib_addressof_constexpr 201603L
204# endif
217# define __cpp_lib_addressof_constexpr 201603L
205218# define __cpp_lib_allocator_traits_is_always_equal 201411L
206219# define __cpp_lib_any 201606L
207220# define __cpp_lib_apply 201603L
208221# define __cpp_lib_array_constexpr 201603L
209222# define __cpp_lib_as_const 201510L
210# if !defined(_LIBCPP_HAS_NO_THREADS)
211# define __cpp_lib_atomic_is_always_lock_free 201603L
212# endif
223# define __cpp_lib_atomic_is_always_lock_free 201603L
213224# define __cpp_lib_bool_constant 201505L
214225// # define __cpp_lib_boyer_moore_searcher 201603L
215226# define __cpp_lib_byte 201603L
......@@ -222,15 +233,11 @@ __cpp_lib_void_t 201411L <type_traits>
222233# endif
223234# define __cpp_lib_gcd_lcm 201606L
224235// # define __cpp_lib_hardware_interference_size 201703L
225# if defined(_LIBCPP_HAS_UNIQUE_OBJECT_REPRESENTATIONS)
226# define __cpp_lib_has_unique_object_representations 201606L
227# endif
236# define __cpp_lib_has_unique_object_representations 201606L
228237# define __cpp_lib_hypot 201603L
229238# define __cpp_lib_incomplete_container_elements 201505L
230239# define __cpp_lib_invoke 201411L
231# if !defined(_LIBCPP_HAS_NO_IS_AGGREGATE)
232# define __cpp_lib_is_aggregate 201703L
233# endif
240# define __cpp_lib_is_aggregate 201703L
234241# define __cpp_lib_is_invocable 201703L
235242# define __cpp_lib_is_swappable 201603L
236243# define __cpp_lib_launder 201606L
......@@ -267,32 +274,20 @@ __cpp_lib_void_t 201411L <type_traits>
267274# undef __cpp_lib_array_constexpr
268275# define __cpp_lib_array_constexpr 201811L
269276// # define __cpp_lib_assume_aligned 201811L
270# if !defined(_LIBCPP_HAS_NO_THREADS)
271# define __cpp_lib_atomic_flag_test 201907L
272# endif
273# if !defined(_LIBCPP_HAS_NO_THREADS)
274// # define __cpp_lib_atomic_float 201711L
275# endif
276# if !defined(_LIBCPP_HAS_NO_THREADS)
277# define __cpp_lib_atomic_lock_free_type_aliases 201907L
278# endif
279# if !defined(_LIBCPP_HAS_NO_THREADS)
280// # define __cpp_lib_atomic_ref 201806L
281# endif
282# if !defined(_LIBCPP_HAS_NO_THREADS)
283// # define __cpp_lib_atomic_shared_ptr 201711L
284# endif
285# if !defined(_LIBCPP_HAS_NO_THREADS)
286# define __cpp_lib_atomic_value_initialization 201911L
287# endif
288# if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_atomic_wait)
277# define __cpp_lib_atomic_flag_test 201907L
278// # define __cpp_lib_atomic_float 201711L
279# define __cpp_lib_atomic_lock_free_type_aliases 201907L
280// # define __cpp_lib_atomic_ref 201806L
281// # define __cpp_lib_atomic_shared_ptr 201711L
282# define __cpp_lib_atomic_value_initialization 201911L
283# if !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_atomic_wait)
289284# define __cpp_lib_atomic_wait 201907L
290285# endif
291286# if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_barrier)
292287# define __cpp_lib_barrier 201907L
293288# endif
294289# define __cpp_lib_bind_front 201907L
295// # define __cpp_lib_bit_cast 201806L
290# define __cpp_lib_bit_cast 201806L
296291// # define __cpp_lib_bitops 201907L
297292# define __cpp_lib_bounded_array_traits 201902L
298293# if !defined(_LIBCPP_HAS_NO_CHAR8_T)
......@@ -311,7 +306,7 @@ __cpp_lib_void_t 201411L <type_traits>
311306# define __cpp_lib_constexpr_tuple 201811L
312307# define __cpp_lib_constexpr_utility 201811L
313308// # define __cpp_lib_constexpr_vector 201907L
314// # define __cpp_lib_coroutine 201902L
309# define __cpp_lib_coroutine 201902L
315310# if _LIBCPP_STD_VER > 17 && defined(__cpp_impl_destroying_delete) && __cpp_impl_destroying_delete >= 201806L
316311# define __cpp_lib_destroying_delete 201806L
317312# endif
......@@ -320,7 +315,7 @@ __cpp_lib_void_t 201411L <type_traits>
320315# undef __cpp_lib_execution
321316// # define __cpp_lib_execution 201902L
322317# if !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_format)
323// # define __cpp_lib_format 201907L
318// # define __cpp_lib_format 202106L
324319# endif
325320# define __cpp_lib_generic_unordered_lookup 201811L
326321# define __cpp_lib_int_pow2 202002L
......@@ -328,9 +323,7 @@ __cpp_lib_void_t 201411L <type_traits>
328323# define __cpp_lib_integer_comparison_functions 202002L
329324# endif
330325# define __cpp_lib_interpolate 201902L
331# if !defined(_LIBCPP_HAS_NO_BUILTIN_IS_CONSTANT_EVALUATED)
332# define __cpp_lib_is_constant_evaluated 201811L
333# endif
326# define __cpp_lib_is_constant_evaluated 201811L
334327// # define __cpp_lib_is_layout_compatible 201907L
335328# define __cpp_lib_is_nothrow_convertible 201806L
336329// # define __cpp_lib_is_pointer_interconvertible 201907L
......@@ -362,14 +355,28 @@ __cpp_lib_void_t 201411L <type_traits>
362355// # define __cpp_lib_three_way_comparison 201907L
363356# define __cpp_lib_to_address 201711L
364357# define __cpp_lib_to_array 201907L
358# define __cpp_lib_type_identity 201806L
365359# define __cpp_lib_unwrap_ref 201811L
366360#endif
367361
368362#if _LIBCPP_STD_VER > 20
363# define __cpp_lib_adaptor_iterator_pair_constructor 202106L
364// # define __cpp_lib_allocate_at_least 202106L
365// # define __cpp_lib_associative_heterogeneous_erasure 202110L
366# define __cpp_lib_byteswap 202110L
367// # define __cpp_lib_constexpr_typeinfo 202106L
368// # define __cpp_lib_invoke_r 202106L
369369# define __cpp_lib_is_scoped_enum 202011L
370# define __cpp_lib_monadic_optional 202110L
371// # define __cpp_lib_move_only_function 202110L
372// # define __cpp_lib_out_ptr 202106L
373// # define __cpp_lib_ranges_starts_ends_with 202106L
374// # define __cpp_lib_ranges_zip 202110L
375// # define __cpp_lib_spanstream 202106L
370376// # define __cpp_lib_stacktrace 202011L
371377// # define __cpp_lib_stdatomic_h 202011L
372378# define __cpp_lib_string_contains 202011L
379# define __cpp_lib_string_resize_and_overwrite 202110L
373380# define __cpp_lib_to_underlying 202102L
374381#endif
375382
lib/libcxx/include/wchar.h+8-4
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- wchar.h ----------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -108,6 +108,10 @@ size_t wcsrtombs(char* restrict dst, const wchar_t** restrict src, size_t len,
108108#include <__config>
109109#include <stddef.h>
110110
111#if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
112# error "The <wchar.h> header is not supported since libc++ has been configured with LIBCXX_ENABLE_WIDE_CHARACTERS disabled"
113#endif
114
111115#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
112116#pragma GCC system_header
113117#endif
......@@ -170,13 +174,13 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
170174}
171175#endif
172176
173#if defined(__cplusplus) && defined(_LIBCPP_MSVCRT_LIKE)
177#if defined(__cplusplus) && (defined(_LIBCPP_MSVCRT_LIKE) || defined(__MVS__))
174178extern "C" {
175179size_t mbsnrtowcs(wchar_t *__restrict dst, const char **__restrict src,
176180 size_t nmc, size_t len, mbstate_t *__restrict ps);
177181size_t wcsnrtombs(char *__restrict dst, const wchar_t **__restrict src,
178182 size_t nwc, size_t len, mbstate_t *__restrict ps);
179} // extern "C++"
180#endif // __cplusplus && _LIBCPP_MSVCRT
183} // extern "C"
184#endif // __cplusplus && (_LIBCPP_MSVCRT || __MVS__)
181185
182186#endif // _LIBCPP_WCHAR_H
lib/libcxx/include/wctype.h+5-1
......@@ -1,5 +1,5 @@
11// -*- C++ -*-
2//===--------------------------- wctype.h ---------------------------------===//
2//===----------------------------------------------------------------------===//
33//
44// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55// See https://llvm.org/LICENSE.txt for license information.
......@@ -46,6 +46,10 @@ wctrans_t wctrans(const char* property);
4646
4747#include <__config>
4848
49#if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
50# error "The <wctype.h> header is not supported since libc++ has been configured with LIBCXX_ENABLE_WIDE_CHARACTERS disabled"
51#endif
52
4953#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
5054#pragma GCC system_header
5155#endif
lib/libcxx/src/algorithm.cpp+5-1
......@@ -1,4 +1,4 @@
1//===----------------------- algorithm.cpp --------------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
......@@ -11,7 +11,9 @@
1111_LIBCPP_BEGIN_NAMESPACE_STD
1212
1313template void __sort<__less<char>&, char*>(char*, char*, __less<char>&);
14#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1415template void __sort<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&);
16#endif
1517template void __sort<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&);
1618template void __sort<__less<unsigned char>&, unsigned char*>(unsigned char*, unsigned char*, __less<unsigned char>&);
1719template void __sort<__less<short>&, short*>(short*, short*, __less<short>&);
......@@ -27,7 +29,9 @@ template void __sort<__less<double>&, double*>(double*, double*, __less<double>&
2729template void __sort<__less<long double>&, long double*>(long double*, long double*, __less<long double>&);
2830
2931template bool __insertion_sort_incomplete<__less<char>&, char*>(char*, char*, __less<char>&);
32#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
3033template bool __insertion_sort_incomplete<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&);
34#endif
3135template bool __insertion_sort_incomplete<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&);
3236template bool __insertion_sort_incomplete<__less<unsigned char>&, unsigned char*>(unsigned char*, unsigned char*, __less<unsigned char>&);
3337template bool __insertion_sort_incomplete<__less<short>&, short*>(short*, short*, __less<short>&);
lib/libcxx/src/any.cpp+1-1
......@@ -1,4 +1,4 @@
1//===---------------------------- any.cpp ---------------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/atomic.cpp+3-2
......@@ -1,4 +1,4 @@
1//===------------------------- atomic.cpp ---------------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
......@@ -9,9 +9,10 @@
99#include <__config>
1010#ifndef _LIBCPP_HAS_NO_THREADS
1111
12#include <climits>
1312#include <atomic>
13#include <climits>
1414#include <functional>
15#include <thread>
1516
1617#ifdef __linux__
1718
lib/libcxx/src/barrier.cpp+4-4
......@@ -1,4 +1,4 @@
1//===------------------------- barrier.cpp ---------------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
......@@ -15,14 +15,14 @@
1515
1616_LIBCPP_BEGIN_NAMESPACE_STD
1717
18#if !defined(_LIBCPP_HAS_NO_TREE_BARRIER) && (_LIBCPP_STD_VER > 11)
18#if !defined(_LIBCPP_HAS_NO_TREE_BARRIER)
1919
2020class __barrier_algorithm_base {
2121public:
2222 struct alignas(64) /* naturally-align the heap state */ __state_t
2323 {
2424 struct {
25 __atomic_base<__barrier_phase_t> __phase = ATOMIC_VAR_INIT(0);
25 __atomic_base<__barrier_phase_t> __phase{0};
2626 } __tickets[64];
2727 };
2828
......@@ -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) && (_LIBCPP_STD_VER >= 11)
93#endif //!defined(_LIBCPP_HAS_NO_TREE_BARRIER)
9494
9595_LIBCPP_END_NAMESPACE_STD
9696
lib/libcxx/src/bind.cpp+1-1
......@@ -1,4 +1,4 @@
1//===-------------------------- bind.cpp ----------------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/charconv.cpp+54-18
......@@ -1,4 +1,4 @@
1//===------------------------- charconv.cpp -------------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
......@@ -9,27 +9,14 @@
99#include "charconv"
1010#include <string.h>
1111
12#include "include/ryu/digit_table.h"
13#include "include/to_chars_floating_point.h"
14
1215_LIBCPP_BEGIN_NAMESPACE_STD
1316
1417namespace __itoa
1518{
1619
17static constexpr char cDigitsLut[200] = {
18 '0', '0', '0', '1', '0', '2', '0', '3', '0', '4', '0', '5', '0', '6', '0',
19 '7', '0', '8', '0', '9', '1', '0', '1', '1', '1', '2', '1', '3', '1', '4',
20 '1', '5', '1', '6', '1', '7', '1', '8', '1', '9', '2', '0', '2', '1', '2',
21 '2', '2', '3', '2', '4', '2', '5', '2', '6', '2', '7', '2', '8', '2', '9',
22 '3', '0', '3', '1', '3', '2', '3', '3', '3', '4', '3', '5', '3', '6', '3',
23 '7', '3', '8', '3', '9', '4', '0', '4', '1', '4', '2', '4', '3', '4', '4',
24 '4', '5', '4', '6', '4', '7', '4', '8', '4', '9', '5', '0', '5', '1', '5',
25 '2', '5', '3', '5', '4', '5', '5', '5', '6', '5', '7', '5', '8', '5', '9',
26 '6', '0', '6', '1', '6', '2', '6', '3', '6', '4', '6', '5', '6', '6', '6',
27 '7', '6', '8', '6', '9', '7', '0', '7', '1', '7', '2', '7', '3', '7', '4',
28 '7', '5', '7', '6', '7', '7', '7', '8', '7', '9', '8', '0', '8', '1', '8',
29 '2', '8', '3', '8', '4', '8', '5', '8', '6', '8', '7', '8', '8', '8', '9',
30 '9', '0', '9', '1', '9', '2', '9', '3', '9', '4', '9', '5', '9', '6', '9',
31 '7', '9', '8', '9', '9'};
32
3320template <typename T>
3421inline _LIBCPP_INLINE_VISIBILITY char*
3522append1(char* buffer, T i) noexcept
......@@ -42,7 +29,7 @@ template <typename T>
4229inline _LIBCPP_INLINE_VISIBILITY char*
4330append2(char* buffer, T i) noexcept
4431{
45 memcpy(buffer, &cDigitsLut[(i)*2], 2);
32 memcpy(buffer, &__DIGIT_TABLE[(i)*2], 2);
4633 return buffer + 2;
4734}
4835
......@@ -157,4 +144,53 @@ __u64toa(uint64_t value, char* buffer) noexcept
157144
158145} // namespace __itoa
159146
147// The original version of floating-point to_chars was written by Microsoft and
148// contributed with the following license.
149
150// Copyright (c) Microsoft Corporation.
151// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
152
153// This implementation is dedicated to the memory of Mary and Thavatchai.
154
155to_chars_result to_chars(char* __first, char* __last, float __value) {
156 return _Floating_to_chars<_Floating_to_chars_overload::_Plain>(__first, __last, __value, chars_format{}, 0);
157}
158
159to_chars_result to_chars(char* __first, char* __last, double __value) {
160 return _Floating_to_chars<_Floating_to_chars_overload::_Plain>(__first, __last, __value, chars_format{}, 0);
161}
162
163to_chars_result to_chars(char* __first, char* __last, long double __value) {
164 return _Floating_to_chars<_Floating_to_chars_overload::_Plain>(__first, __last, static_cast<double>(__value),
165 chars_format{}, 0);
166}
167
168to_chars_result to_chars(char* __first, char* __last, float __value, chars_format __fmt) {
169 return _Floating_to_chars<_Floating_to_chars_overload::_Format_only>(__first, __last, __value, __fmt, 0);
170}
171
172to_chars_result to_chars(char* __first, char* __last, double __value, chars_format __fmt) {
173 return _Floating_to_chars<_Floating_to_chars_overload::_Format_only>(__first, __last, __value, __fmt, 0);
174}
175
176to_chars_result to_chars(char* __first, char* __last, long double __value, chars_format __fmt) {
177 return _Floating_to_chars<_Floating_to_chars_overload::_Format_only>(__first, __last, static_cast<double>(__value),
178 __fmt, 0);
179}
180
181to_chars_result to_chars(char* __first, char* __last, float __value, chars_format __fmt, int __precision) {
182 return _Floating_to_chars<_Floating_to_chars_overload::_Format_precision>(__first, __last, __value, __fmt,
183 __precision);
184}
185
186to_chars_result to_chars(char* __first, char* __last, double __value, chars_format __fmt, int __precision) {
187 return _Floating_to_chars<_Floating_to_chars_overload::_Format_precision>(__first, __last, __value, __fmt,
188 __precision);
189}
190
191to_chars_result to_chars(char* __first, char* __last, long double __value, chars_format __fmt, int __precision) {
192 return _Floating_to_chars<_Floating_to_chars_overload::_Format_precision>(
193 __first, __last, static_cast<double>(__value), __fmt, __precision);
194}
195
160196_LIBCPP_END_NAMESPACE_STD
lib/libcxx/src/chrono.cpp+49-7
......@@ -1,4 +1,4 @@
1//===------------------------- chrono.cpp ---------------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
......@@ -44,6 +44,10 @@
4444# endif
4545#endif // defined(_LIBCPP_WIN32API)
4646
47#if defined(__Fuchsia__)
48# include <zircon/syscalls.h>
49#endif
50
4751#if __has_include(<mach/mach_time.h>)
4852# include <mach/mach_time.h>
4953#endif
......@@ -63,6 +67,30 @@ namespace chrono
6367
6468#if defined(_LIBCPP_WIN32API)
6569
70#if _WIN32_WINNT < _WIN32_WINNT_WIN8
71
72namespace {
73
74typedef void(WINAPI *GetSystemTimeAsFileTimePtr)(LPFILETIME);
75
76class GetSystemTimeInit {
77public:
78 GetSystemTimeInit() {
79 fp = (GetSystemTimeAsFileTimePtr)GetProcAddress(
80 GetModuleHandleW(L"kernel32.dll"), "GetSystemTimePreciseAsFileTime");
81 if (fp == nullptr)
82 fp = GetSystemTimeAsFileTime;
83 }
84 GetSystemTimeAsFileTimePtr fp;
85};
86
87// Pretend we're inside a system header so the compiler doesn't flag the use of the init_priority
88// attribute with a value that's reserved for the implementation (we're the implementation).
89#include "chrono_system_time_init.h"
90} // namespace
91
92#endif
93
6694static system_clock::time_point __libcpp_system_clock_now() {
6795 // FILETIME is in 100ns units
6896 using filetime_duration =
......@@ -74,10 +102,13 @@ static system_clock::time_point __libcpp_system_clock_now() {
74102 static _LIBCPP_CONSTEXPR const seconds nt_to_unix_epoch{11644473600};
75103
76104 FILETIME ft;
77#if _WIN32_WINNT >= _WIN32_WINNT_WIN8 && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
105#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8 && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)) || \
106 (_WIN32_WINNT >= _WIN32_WINNT_WIN10)
78107 GetSystemTimePreciseAsFileTime(&ft);
79#else
108#elif !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
80109 GetSystemTimeAsFileTime(&ft);
110#else
111 GetSystemTimeAsFileTimeFunc.fp(&ft);
81112#endif
82113
83114 filetime_duration d{(static_cast<__int64>(ft.dwHighDateTime) << 32) |
......@@ -239,7 +270,18 @@ static steady_clock::time_point __libcpp_steady_clock_now() {
239270 return steady_clock::time_point(seconds(ts.tv_sec) + nanoseconds(ts.tv_nsec));
240271}
241272
242#elif defined(CLOCK_MONOTONIC)
273# elif defined(__Fuchsia__)
274
275static steady_clock::time_point __libcpp_steady_clock_now() noexcept {
276 // Implicitly link against the vDSO system call ABI without
277 // requiring the final link to specify -lzircon explicitly when
278 // statically linking libc++.
279# pragma comment(lib, "zircon")
280
281 return steady_clock::time_point(nanoseconds(_zx_clock_get_monotonic()));
282}
283
284# elif defined(CLOCK_MONOTONIC)
243285
244286static steady_clock::time_point __libcpp_steady_clock_now() {
245287 struct timespec tp;
......@@ -248,9 +290,9 @@ static steady_clock::time_point __libcpp_steady_clock_now() {
248290 return steady_clock::time_point(seconds(tp.tv_sec) + nanoseconds(tp.tv_nsec));
249291}
250292
251#else
252# error "Monotonic clock not implemented on this platform"
253#endif
293# else
294# error "Monotonic clock not implemented on this platform"
295# endif
254296
255297const bool steady_clock::is_steady;
256298
lib/libcxx/src/chrono_system_time_init.h created+2
......@@ -0,0 +1,2 @@
1#pragma GCC system_header
2GetSystemTimeInit GetSystemTimeAsFileTimeFunc _LIBCPP_INIT_PRIORITY_MAX;
lib/libcxx/src/condition_variable.cpp+1-1
......@@ -1,4 +1,4 @@
1//===-------------------- condition_variable.cpp --------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/condition_variable_destructor.cpp+1-1
......@@ -1,4 +1,4 @@
1//===---------------- condition_variable_destructor.cpp ------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/debug.cpp+1-1
......@@ -1,4 +1,4 @@
1//===-------------------------- debug.cpp ---------------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/exception.cpp+1-1
......@@ -1,4 +1,4 @@
1//===------------------------ exception.cpp -------------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/experimental/memory_resource.cpp+5-4
......@@ -1,4 +1,4 @@
1//===------------------------ memory_resource.cpp -------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
......@@ -76,7 +76,9 @@ union ResourceInitHelper {
7676 ~ResourceInitHelper() {}
7777};
7878
79_LIBCPP_SAFE_STATIC ResourceInitHelper res_init _LIBCPP_INIT_PRIORITY_MAX;
79// Pretend we're inside a system header so the compiler doesn't flag the use of the init_priority
80// attribute with a value that's reserved for the implementation (we're the implementation).
81#include "memory_resource_init_helper.h"
8082
8183} // end namespace
8284
......@@ -95,8 +97,7 @@ static memory_resource *
9597__default_memory_resource(bool set = false, memory_resource * new_res = nullptr) noexcept
9698{
9799#ifndef _LIBCPP_HAS_NO_ATOMIC_HEADER
98 _LIBCPP_SAFE_STATIC static atomic<memory_resource*> __res =
99 ATOMIC_VAR_INIT(&res_init.resources.new_delete_res);
100 _LIBCPP_SAFE_STATIC static atomic<memory_resource*> __res{&res_init.resources.new_delete_res};
100101 if (set) {
101102 new_res = new_res ? new_res : new_delete_resource();
102103 // TODO: Can a weaker ordering be used?
lib/libcxx/src/experimental/memory_resource_init_helper.h created+2
......@@ -0,0 +1,2 @@
1#pragma GCC system_header
2_LIBCPP_SAFE_STATIC ResourceInitHelper res_init _LIBCPP_INIT_PRIORITY_MAX;
lib/libcxx/src/filesystem/directory_iterator.cpp+5-89
......@@ -1,4 +1,4 @@
1//===------------------ directory_iterator.cpp ----------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
......@@ -6,99 +6,15 @@
66//
77//===----------------------------------------------------------------------===//
88
9#include "filesystem"
109#include "__config"
11#if defined(_LIBCPP_WIN32API)
12#define WIN32_LEAN_AND_MEAN
13#define NOMINMAX
14#include <windows.h>
15#else
16#include <dirent.h>
17#endif
10#include "filesystem"
11#include "stack"
1812#include <errno.h>
1913
2014#include "filesystem_common.h"
2115
2216_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
2317
24namespace detail {
25namespace {
26
27#if !defined(_LIBCPP_WIN32API)
28
29#if defined(DT_BLK)
30template <class DirEntT, class = decltype(DirEntT::d_type)>
31static file_type get_file_type(DirEntT* ent, int) {
32 switch (ent->d_type) {
33 case DT_BLK:
34 return file_type::block;
35 case DT_CHR:
36 return file_type::character;
37 case DT_DIR:
38 return file_type::directory;
39 case DT_FIFO:
40 return file_type::fifo;
41 case DT_LNK:
42 return file_type::symlink;
43 case DT_REG:
44 return file_type::regular;
45 case DT_SOCK:
46 return file_type::socket;
47 // Unlike in lstat, hitting "unknown" here simply means that the underlying
48 // filesystem doesn't support d_type. Report is as 'none' so we correctly
49 // set the cache to empty.
50 case DT_UNKNOWN:
51 break;
52 }
53 return file_type::none;
54}
55#endif // defined(DT_BLK)
56
57template <class DirEntT>
58static file_type get_file_type(DirEntT* ent, long) {
59 return file_type::none;
60}
61
62static pair<string_view, file_type> posix_readdir(DIR* dir_stream,
63 error_code& ec) {
64 struct dirent* dir_entry_ptr = nullptr;
65 errno = 0; // zero errno in order to detect errors
66 ec.clear();
67 if ((dir_entry_ptr = ::readdir(dir_stream)) == nullptr) {
68 if (errno)
69 ec = capture_errno();
70 return {};
71 } else {
72 return {dir_entry_ptr->d_name, get_file_type(dir_entry_ptr, 0)};
73 }
74}
75#else
76// defined(_LIBCPP_WIN32API)
77
78static file_type get_file_type(const WIN32_FIND_DATAW& data) {
79 if (data.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT &&
80 data.dwReserved0 == IO_REPARSE_TAG_SYMLINK)
81 return file_type::symlink;
82 if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
83 return file_type::directory;
84 return file_type::regular;
85}
86static uintmax_t get_file_size(const WIN32_FIND_DATAW& data) {
87 return (static_cast<uint64_t>(data.nFileSizeHigh) << 32) + data.nFileSizeLow;
88}
89static file_time_type get_write_time(const WIN32_FIND_DATAW& data) {
90 ULARGE_INTEGER tmp;
91 const FILETIME& time = data.ftLastWriteTime;
92 tmp.u.LowPart = time.dwLowDateTime;
93 tmp.u.HighPart = time.dwHighDateTime;
94 return file_time_type(file_time_type::duration(tmp.QuadPart));
95}
96
97#endif
98
99} // namespace
100} // namespace detail
101
10218using detail::ErrorHandler;
10319
10420#if defined(_LIBCPP_WIN32API)
......@@ -196,9 +112,9 @@ public:
196112 : __stream_(nullptr), __root_(root) {
197113 if ((__stream_ = ::opendir(root.c_str())) == nullptr) {
198114 ec = detail::capture_errno();
199 const bool allow_eacess =
115 const bool allow_eacces =
200116 bool(opts & directory_options::skip_permission_denied);
201 if (allow_eacess && ec.value() == EACCES)
117 if (allow_eacces && ec.value() == EACCES)
202118 ec.clear();
203119 return;
204120 }
lib/libcxx/src/filesystem/filesystem_common.h+88-9
......@@ -10,19 +10,29 @@
1010#define FILESYSTEM_COMMON_H
1111
1212#include "__config"
13#include "filesystem"
1413#include "array"
1514#include "chrono"
1615#include "climits"
16#include "cstdarg"
1717#include "cstdlib"
1818#include "ctime"
19#include "filesystem"
20#include "ratio"
21#include "system_error"
22
23#if defined(_LIBCPP_WIN32API)
24# define WIN32_LEAN_AND_MEAN
25# define NOMINMAX
26# include <windows.h>
27#endif
1928
2029#if !defined(_LIBCPP_WIN32API)
21# include <unistd.h>
30# include <dirent.h> // for DIR & friends
31# include <fcntl.h> /* values for fchmodat */
2232# include <sys/stat.h>
2333# include <sys/statvfs.h>
2434# include <sys/time.h> // for ::utimes as used in __last_write_time
25# include <fcntl.h> /* values for fchmodat */
35# include <unistd.h>
2636#endif
2737
2838#include "../include/apple_availability.h"
......@@ -59,7 +69,7 @@ errc __win_err_to_errc(int err);
5969
6070namespace {
6171
62static _LIBCPP_FORMAT_PRINTF(1, 0) string
72static _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 1, 0) string
6373format_string_impl(const char* msg, va_list ap) {
6474 array<char, 256> buf;
6575
......@@ -83,7 +93,7 @@ format_string_impl(const char* msg, va_list ap) {
8393 return result;
8494}
8595
86static _LIBCPP_FORMAT_PRINTF(1, 2) string
96static _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 1, 2) string
8797format_string(const char* msg, ...) {
8898 string ret;
8999 va_list ap;
......@@ -171,7 +181,7 @@ struct ErrorHandler {
171181 _LIBCPP_UNREACHABLE();
172182 }
173183
174 _LIBCPP_FORMAT_PRINTF(3, 0)
184 _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 3, 0)
175185 void report_impl(const error_code& ec, const char* msg, va_list ap) const {
176186 if (ec_) {
177187 *ec_ = ec;
......@@ -190,7 +200,7 @@ struct ErrorHandler {
190200 _LIBCPP_UNREACHABLE();
191201 }
192202
193 _LIBCPP_FORMAT_PRINTF(3, 4)
203 _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 3, 4)
194204 T report(const error_code& ec, const char* msg, ...) const {
195205 va_list ap;
196206 va_start(ap, msg);
......@@ -212,7 +222,7 @@ struct ErrorHandler {
212222 return report(make_error_code(err));
213223 }
214224
215 _LIBCPP_FORMAT_PRINTF(3, 4)
225 _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 3, 4)
216226 T report(errc const& err, const char* msg, ...) const {
217227 va_list ap;
218228 va_start(ap, msg);
......@@ -524,7 +534,76 @@ bool set_file_times(const path& p, std::array<TimeSpec, 2> const& TS,
524534 return posix_utimensat(p, TS, ec);
525535#endif
526536}
527#endif /* !_LIBCPP_WIN32API */
537
538#if defined(DT_BLK)
539template <class DirEntT, class = decltype(DirEntT::d_type)>
540static file_type get_file_type(DirEntT* ent, int) {
541 switch (ent->d_type) {
542 case DT_BLK:
543 return file_type::block;
544 case DT_CHR:
545 return file_type::character;
546 case DT_DIR:
547 return file_type::directory;
548 case DT_FIFO:
549 return file_type::fifo;
550 case DT_LNK:
551 return file_type::symlink;
552 case DT_REG:
553 return file_type::regular;
554 case DT_SOCK:
555 return file_type::socket;
556 // Unlike in lstat, hitting "unknown" here simply means that the underlying
557 // filesystem doesn't support d_type. Report is as 'none' so we correctly
558 // set the cache to empty.
559 case DT_UNKNOWN:
560 break;
561 }
562 return file_type::none;
563}
564#endif // defined(DT_BLK)
565
566template <class DirEntT>
567static file_type get_file_type(DirEntT*, long) {
568 return file_type::none;
569}
570
571static pair<string_view, file_type> posix_readdir(DIR* dir_stream,
572 error_code& ec) {
573 struct dirent* dir_entry_ptr = nullptr;
574 errno = 0; // zero errno in order to detect errors
575 ec.clear();
576 if ((dir_entry_ptr = ::readdir(dir_stream)) == nullptr) {
577 if (errno)
578 ec = capture_errno();
579 return {};
580 } else {
581 return {dir_entry_ptr->d_name, get_file_type(dir_entry_ptr, 0)};
582 }
583}
584
585#else // _LIBCPP_WIN32API
586
587static file_type get_file_type(const WIN32_FIND_DATAW& data) {
588 if (data.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT &&
589 data.dwReserved0 == IO_REPARSE_TAG_SYMLINK)
590 return file_type::symlink;
591 if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
592 return file_type::directory;
593 return file_type::regular;
594}
595static uintmax_t get_file_size(const WIN32_FIND_DATAW& data) {
596 return (static_cast<uint64_t>(data.nFileSizeHigh) << 32) + data.nFileSizeLow;
597}
598static file_time_type get_write_time(const WIN32_FIND_DATAW& data) {
599 ULARGE_INTEGER tmp;
600 const FILETIME& time = data.ftLastWriteTime;
601 tmp.u.LowPart = time.dwLowDateTime;
602 tmp.u.HighPart = time.dwHighDateTime;
603 return file_time_type(file_time_type::duration(tmp.QuadPart));
604}
605
606#endif // !_LIBCPP_WIN32API
528607
529608} // namespace
530609} // end namespace detail
lib/libcxx/src/filesystem/operations.cpp+109-2
......@@ -1,4 +1,4 @@
1//===--------------------- filesystem/ops.cpp -----------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
......@@ -24,9 +24,10 @@
2424# define NOMINMAX
2525# include <windows.h>
2626#else
27# include <unistd.h>
27# include <dirent.h>
2828# include <sys/stat.h>
2929# include <sys/statvfs.h>
30# include <unistd.h>
3031#endif
3132#include <time.h>
3233#include <fcntl.h> /* values for fchmodat */
......@@ -1338,6 +1339,19 @@ bool __remove(const path& p, error_code* ec) {
13381339 return true;
13391340}
13401341
1342// We currently have two implementations of `__remove_all`. The first one is general and
1343// used on platforms where we don't have access to the `openat()` family of POSIX functions.
1344// That implementation uses `directory_iterator`, however it is vulnerable to some race
1345// conditions, see https://reviews.llvm.org/D118134 for details.
1346//
1347// The second implementation is used on platforms where `openat()` & friends are available,
1348// and it threads file descriptors through recursive calls to avoid such race conditions.
1349#if defined(_LIBCPP_WIN32API)
1350# define REMOVE_ALL_USE_DIRECTORY_ITERATOR
1351#endif
1352
1353#if defined(REMOVE_ALL_USE_DIRECTORY_ITERATOR)
1354
13411355namespace {
13421356
13431357uintmax_t remove_all_impl(path const& p, error_code& ec) {
......@@ -1377,6 +1391,99 @@ uintmax_t __remove_all(const path& p, error_code* ec) {
13771391 return count;
13781392}
13791393
1394#else // !REMOVE_ALL_USE_DIRECTORY_ITERATOR
1395
1396namespace {
1397
1398template <class Cleanup>
1399struct scope_exit {
1400 explicit scope_exit(Cleanup const& cleanup)
1401 : cleanup_(cleanup)
1402 { }
1403
1404 ~scope_exit() { cleanup_(); }
1405
1406private:
1407 Cleanup cleanup_;
1408};
1409
1410uintmax_t remove_all_impl(int parent_directory, const path& p, error_code& ec) {
1411 // First, try to open the path as a directory.
1412 const int options = O_CLOEXEC | O_RDONLY | O_DIRECTORY | O_NOFOLLOW;
1413 int fd = ::openat(parent_directory, p.c_str(), options);
1414 if (fd != -1) {
1415 // If that worked, iterate over the contents of the directory and
1416 // remove everything in it, recursively.
1417 DIR* stream = ::fdopendir(fd);
1418 if (stream == nullptr) {
1419 ::close(fd);
1420 ec = detail::capture_errno();
1421 return 0;
1422 }
1423 // Note: `::closedir` will also close the associated file descriptor, so
1424 // there should be no call to `close(fd)`.
1425 scope_exit close_stream([=] { ::closedir(stream); });
1426
1427 uintmax_t count = 0;
1428 while (true) {
1429 auto [str, type] = detail::posix_readdir(stream, ec);
1430 static_assert(std::is_same_v<decltype(str), std::string_view>);
1431 if (str == "." || str == "..") {
1432 continue;
1433 } else if (ec || str.empty()) {
1434 break; // we're done iterating through the directory
1435 } else {
1436 count += remove_all_impl(fd, str, ec);
1437 }
1438 }
1439
1440 // Then, remove the now-empty directory itself.
1441 if (::unlinkat(parent_directory, p.c_str(), AT_REMOVEDIR) == -1) {
1442 ec = detail::capture_errno();
1443 return count;
1444 }
1445
1446 return count + 1; // the contents of the directory + the directory itself
1447 }
1448
1449 ec = detail::capture_errno();
1450
1451 // If we failed to open `p` because it didn't exist, it's not an
1452 // error -- it might have moved or have been deleted already.
1453 if (ec == errc::no_such_file_or_directory) {
1454 ec.clear();
1455 return 0;
1456 }
1457
1458 // If opening `p` failed because it wasn't a directory, remove it as
1459 // a normal file instead. Note that `openat()` can return either ENOTDIR
1460 // or ELOOP depending on the exact reason of the failure.
1461 if (ec == errc::not_a_directory || ec == errc::too_many_symbolic_link_levels) {
1462 ec.clear();
1463 if (::unlinkat(parent_directory, p.c_str(), /* flags = */0) == -1) {
1464 ec = detail::capture_errno();
1465 return 0;
1466 }
1467 return 1;
1468 }
1469
1470 // Otherwise, it's a real error -- we don't remove anything.
1471 return 0;
1472}
1473
1474} // end namespace
1475
1476uintmax_t __remove_all(const path& p, error_code* ec) {
1477 ErrorHandler<uintmax_t> err("remove_all", ec, &p);
1478 error_code mec;
1479 uintmax_t count = remove_all_impl(AT_FDCWD, p, mec);
1480 if (mec)
1481 return err.report(mec);
1482 return count;
1483}
1484
1485#endif // REMOVE_ALL_USE_DIRECTORY_ITERATOR
1486
13801487void __rename(const path& from, const path& to, error_code* ec) {
13811488 ErrorHandler<void> err("rename", ec, &from, &to);
13821489 if (detail::rename(from.c_str(), to.c_str()) == -1)
lib/libcxx/src/format.cpp+1-5
......@@ -1,4 +1,4 @@
1//===------------------------- format.cpp ---------------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
......@@ -10,10 +10,6 @@
1010
1111_LIBCPP_BEGIN_NAMESPACE_STD
1212
13#if _LIBCPP_STD_VER > 17
14
1513format_error::~format_error() noexcept = default;
1614
17#endif //_LIBCPP_STD_VER > 17
18
1915_LIBCPP_END_NAMESPACE_STD
lib/libcxx/src/functional.cpp+3-1
......@@ -1,4 +1,4 @@
1//===----------------------- functional.cpp -------------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
......@@ -14,7 +14,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD
1414bad_function_call::~bad_function_call() noexcept
1515{
1616}
17#endif
1718
19#ifdef _LIBCPP_ABI_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE
1820const char*
1921bad_function_call::what() const noexcept
2022{
lib/libcxx/src/future.cpp+1-1
......@@ -1,4 +1,4 @@
1//===------------------------- future.cpp ---------------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/hash.cpp+1-1
......@@ -1,4 +1,4 @@
1//===-------------------------- hash.cpp ----------------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/include/apple_availability.h+1-1
......@@ -1,4 +1,4 @@
1//===------------------------ apple_availability.h ------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/include/atomic_support.h+2-2
......@@ -24,7 +24,7 @@
2424 && defined(__ATOMIC_ACQ_REL) \
2525 && defined(__ATOMIC_SEQ_CST)
2626# define _LIBCPP_HAS_ATOMIC_BUILTINS
27#elif !defined(__clang__) && defined(_GNUC_VER) && _GNUC_VER >= 407
27#elif defined(_LIBCPP_COMPILER_GCC)
2828# define _LIBCPP_HAS_ATOMIC_BUILTINS
2929#endif
3030
......@@ -146,7 +146,7 @@ _ValueType __libcpp_atomic_add(_ValueType* __val, _AddType __a,
146146template <class _ValueType>
147147inline _LIBCPP_INLINE_VISIBILITY
148148_ValueType __libcpp_atomic_exchange(_ValueType* __target,
149 _ValueType __value, int __order = _AO_Seq)
149 _ValueType __value, int = _AO_Seq)
150150{
151151 _ValueType old = *__target;
152152 *__target = __value;
lib/libcxx/src/include/config_elast.h+1-1
......@@ -1,4 +1,4 @@
1//===----------------------- config_elast.h -------------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/include/refstring.h+1-1
......@@ -1,4 +1,4 @@
1//===------------------------ __refstring ---------------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/include/ryu/common.h created+107
......@@ -0,0 +1,107 @@
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// Copyright (c) Microsoft Corporation.
10// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
11
12// Copyright 2018 Ulf Adams
13// Copyright (c) Microsoft Corporation. All rights reserved.
14
15// Boost Software License - Version 1.0 - August 17th, 2003
16
17// Permission is hereby granted, free of charge, to any person or organization
18// obtaining a copy of the software and accompanying documentation covered by
19// this license (the "Software") to use, reproduce, display, distribute,
20// execute, and transmit the Software, and to prepare derivative works of the
21// Software, and to permit third-parties to whom the Software is furnished to
22// do so, all subject to the following:
23
24// The copyright notices in the Software and this entire statement, including
25// the above license grant, this restriction and the following disclaimer,
26// must be included in all copies of the Software, in whole or in part, and
27// all derivative works of the Software, unless such copies or derivative
28// works are solely in the form of machine-executable object code generated by
29// a source language processor.
30
31// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
34// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
35// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
36// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
37// DEALINGS IN THE SOFTWARE.
38
39#ifndef _LIBCPP_SRC_INCLUDE_RYU_COMMON_H
40#define _LIBCPP_SRC_INCLUDE_RYU_COMMON_H
41
42// Avoid formatting to keep the changes with the original code minimal.
43// clang-format off
44
45#include "__config"
46
47_LIBCPP_BEGIN_NAMESPACE_STD
48
49[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __decimalLength9(const uint32_t __v) {
50 // Function precondition: __v is not a 10-digit number.
51 // (f2s: 9 digits are sufficient for round-tripping.)
52 // (d2fixed: We print 9-digit blocks.)
53 _LIBCPP_ASSERT(__v < 1000000000, "");
54 if (__v >= 100000000) { return 9; }
55 if (__v >= 10000000) { return 8; }
56 if (__v >= 1000000) { return 7; }
57 if (__v >= 100000) { return 6; }
58 if (__v >= 10000) { return 5; }
59 if (__v >= 1000) { return 4; }
60 if (__v >= 100) { return 3; }
61 if (__v >= 10) { return 2; }
62 return 1;
63}
64
65// Returns __e == 0 ? 1 : ceil(log_2(5^__e)).
66[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline int32_t __pow5bits(const int32_t __e) {
67 // This approximation works up to the point that the multiplication overflows at __e = 3529.
68 // If the multiplication were done in 64 bits, it would fail at 5^4004 which is just greater
69 // than 2^9297.
70 _LIBCPP_ASSERT(__e >= 0, "");
71 _LIBCPP_ASSERT(__e <= 3528, "");
72 return static_cast<int32_t>(((static_cast<uint32_t>(__e) * 1217359) >> 19) + 1);
73}
74
75// Returns floor(log_10(2^__e)).
76[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __log10Pow2(const int32_t __e) {
77 // The first value this approximation fails for is 2^1651 which is just greater than 10^297.
78 _LIBCPP_ASSERT(__e >= 0, "");
79 _LIBCPP_ASSERT(__e <= 1650, "");
80 return (static_cast<uint32_t>(__e) * 78913) >> 18;
81}
82
83// Returns floor(log_10(5^__e)).
84[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __log10Pow5(const int32_t __e) {
85 // The first value this approximation fails for is 5^2621 which is just greater than 10^1832.
86 _LIBCPP_ASSERT(__e >= 0, "");
87 _LIBCPP_ASSERT(__e <= 2620, "");
88 return (static_cast<uint32_t>(__e) * 732923) >> 20;
89}
90
91[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __float_to_bits(const float __f) {
92 uint32_t __bits = 0;
93 _VSTD::memcpy(&__bits, &__f, sizeof(float));
94 return __bits;
95}
96
97[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __double_to_bits(const double __d) {
98 uint64_t __bits = 0;
99 _VSTD::memcpy(&__bits, &__d, sizeof(double));
100 return __bits;
101}
102
103_LIBCPP_END_NAMESPACE_STD
104
105// clang-format on
106
107#endif // _LIBCPP_SRC_INCLUDE_RYU_COMMON_H
lib/libcxx/src/include/ryu/d2fixed.h created+60
......@@ -0,0 +1,60 @@
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// Copyright (c) Microsoft Corporation.
10// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
11
12// Copyright 2018 Ulf Adams
13// Copyright (c) Microsoft Corporation. All rights reserved.
14
15// Boost Software License - Version 1.0 - August 17th, 2003
16
17// Permission is hereby granted, free of charge, to any person or organization
18// obtaining a copy of the software and accompanying documentation covered by
19// this license (the "Software") to use, reproduce, display, distribute,
20// execute, and transmit the Software, and to prepare derivative works of the
21// Software, and to permit third-parties to whom the Software is furnished to
22// do so, all subject to the following:
23
24// The copyright notices in the Software and this entire statement, including
25// the above license grant, this restriction and the following disclaimer,
26// must be included in all copies of the Software, in whole or in part, and
27// all derivative works of the Software, unless such copies or derivative
28// works are solely in the form of machine-executable object code generated by
29// a source language processor.
30
31// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
34// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
35// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
36// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
37// DEALINGS IN THE SOFTWARE.
38
39#ifndef _LIBCPP_SRC_INCLUDE_RYU_D2FIXED_H
40#define _LIBCPP_SRC_INCLUDE_RYU_D2FIXED_H
41
42// Avoid formatting to keep the changes with the original code minimal.
43// clang-format off
44
45#include "__config"
46#include "cstdint"
47
48_LIBCPP_BEGIN_NAMESPACE_STD
49
50void __append_n_digits(const uint32_t __olength, uint32_t __digits, char* const __result);
51void __append_nine_digits(uint32_t __digits, char* const __result);
52
53[[nodiscard]] to_chars_result __d2fixed_buffered_n(char* _First, char* const _Last, const double __d, const uint32_t __precision);
54[[nodiscard]] to_chars_result __d2exp_buffered_n(char* _First, char* const _Last, const double __d, uint32_t __precision);
55
56_LIBCPP_END_NAMESPACE_STD
57
58// clang-format on
59
60#endif // _LIBCPP_SRC_INCLUDE_RYU_D2FIXED_H
lib/libcxx/src/include/ryu/d2fixed_full_table.h created+4451
......@@ -0,0 +1,4451 @@
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// Copyright (c) Microsoft Corporation.
10// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
11
12// Copyright 2018 Ulf Adams
13// Copyright (c) Microsoft Corporation. All rights reserved.
14
15// Boost Software License - Version 1.0 - August 17th, 2003
16
17// Permission is hereby granted, free of charge, to any person or organization
18// obtaining a copy of the software and accompanying documentation covered by
19// this license (the "Software") to use, reproduce, display, distribute,
20// execute, and transmit the Software, and to prepare derivative works of the
21// Software, and to permit third-parties to whom the Software is furnished to
22// do so, all subject to the following:
23
24// The copyright notices in the Software and this entire statement, including
25// the above license grant, this restriction and the following disclaimer,
26// must be included in all copies of the Software, in whole or in part, and
27// all derivative works of the Software, unless such copies or derivative
28// works are solely in the form of machine-executable object code generated by
29// a source language processor.
30
31// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
34// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
35// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
36// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
37// DEALINGS IN THE SOFTWARE.
38
39#ifndef _LIBCPP_SRC_INCLUDE_RYU_D2FIXED_FULL_TABLE_H
40#define _LIBCPP_SRC_INCLUDE_RYU_D2FIXED_FULL_TABLE_H
41
42// Avoid formatting to keep the changes with the original code minimal.
43// clang-format off
44
45#include "__config"
46
47_LIBCPP_BEGIN_NAMESPACE_STD
48
49inline constexpr int __TABLE_SIZE = 64;
50
51inline constexpr uint16_t __POW10_OFFSET[__TABLE_SIZE] = {
52 0, 2, 5, 8, 12, 16, 21, 26, 32, 39,
53 46, 54, 62, 71, 80, 90, 100, 111, 122, 134,
54 146, 159, 173, 187, 202, 217, 233, 249, 266, 283,
55 301, 319, 338, 357, 377, 397, 418, 440, 462, 485,
56 508, 532, 556, 581, 606, 632, 658, 685, 712, 740,
57 769, 798, 828, 858, 889, 920, 952, 984, 1017, 1050,
58 1084, 1118, 1153, 1188
59};
60
61inline constexpr uint64_t __POW10_SPLIT[1224][3] = {
62 { 1u, 72057594037927936u, 0u },
63 { 699646928636035157u, 72057594u, 0u },
64 { 1u, 0u, 256u },
65 { 11902091922964236229u, 4722366482869u, 0u },
66 { 6760415703743915872u, 4722u, 0u },
67 { 1u, 0u, 16777216u },
68 { 13369850649504950658u, 309485009821345068u, 0u },
69 { 15151142278969419334u, 309485009u, 0u },
70 { 1u, 0u, 75511627776u },
71 { 4635408826454083567u, 9437866644873197963u, 1099u },
72 { 12367138975830625353u, 20282409603651u, 0u },
73 { 7555853734021184432u, 20282u, 0u },
74 { 1u, 0u, 250037927936u },
75 { 5171444645924616995u, 699646928636035156u, 72057594u },
76 { 16672297533003297786u, 1329227995784915872u, 0u },
77 { 14479142226848862515u, 1329227995u, 0u },
78 { 1u, 0u, 181645213696u },
79 { 12214193123817091081u, 11902091922964236228u, 114366482869u },
80 { 16592893013671929435u, 6760415703743915871u, 4722u },
81 { 4549827147718617003u, 87112285931760u, 0u },
82 { 5274510003815168971u, 87112u, 0u },
83 { 1u, 0u, 44724781056u },
84 { 9794971998307800535u, 13369850649504950657u, 209821345068u },
85 { 14720142899209240169u, 15151142278969419333u, 309485009u },
86 { 4300745446091561535u, 5708990770823839524u, 0u },
87 { 15197156861335443364u, 5708990770u, 0u },
88 { 1u, 0u, 139251286016u },
89 { 13484604155038683037u, 4635408826454083566u, 67670423947u },
90 { 8356963862052375699u, 12367138975830625352u, 58409603651u },
91 { 5850852848337610021u, 7555853734021184431u, 20282u },
92 { 2712780827214982050u, 374144419156711u, 0u },
93 { 7732076577307618052u, 374144u, 0u },
94 { 1u, 0u, 84280344576u },
95 { 17296309485351745867u, 5171444645924616994u, 160903807060u },
96 { 16598859101615853088u, 16672297533003297785u, 219784915872u },
97 { 7469952526870444257u, 14479142226848862514u, 1329227995u },
98 { 13531654022114669524u, 6073184580144670117u, 1u },
99 { 15757609704383306943u, 24519928653u, 0u },
100 { 9590990814237149590u, 24u, 0u },
101 { 1u, 0u, 196662132736u },
102 { 15408590707489433890u, 12214193123817091080u, 95899502532u },
103 { 18332056844289122710u, 16592893013671929434u, 240246646623u },
104 { 11114572877353986193u, 4549827147718617002u, 72285931760u },
105 { 1703393793997526525u, 5274510003815168970u, 87112u },
106 { 5082852056285196265u, 1606938044258990u, 0u },
107 { 816434266573722365u, 1606938u, 0u },
108 { 1u, 0u, 129530986496u },
109 { 5736523019264798742u, 9794971998307800534u, 69797980545u },
110 { 10129314776268243339u, 14720142899209240168u, 36233143877u },
111 { 16511595775483995364u, 4300745446091561534u, 50823839524u },
112 { 12367293405401453325u, 15197156861335443363u, 5708990770u },
113 { 16934621733248854291u, 13078571300009428617u, 5u },
114 { 10278280417769171336u, 105312291668u, 0u },
115 { 5760764486226151240u, 105u, 0u },
116 { 1u, 0u, 238731001856u },
117 { 4128368337188369761u, 13484604155038683036u, 72453031918u },
118 { 10240941003671005056u, 8356963862052375698u, 175317175368u },
119 { 17933378316822368251u, 5850852848337610020u, 231147060143u },
120 { 8346249813075698616u, 2712780827214982049u, 128419156711u },
121 { 15906203609160902695u, 7732076577307618051u, 374144u },
122 { 14525607416135386328u, 6901746346790563u, 0u },
123 { 6397156777364256320u, 6901746u, 0u },
124 { 1u, 0u, 34937634816u },
125 { 16798760952716600048u, 17296309485351745866u, 249899825954u },
126 { 2419982808370854967u, 16598859101615853087u, 50404946937u },
127 { 2922947087773078956u, 7469952526870444256u, 165733552434u },
128 { 15419220167069510190u, 13531654022114669523u, 77854221733u },
129 { 3452124642157173416u, 15757609704383306942u, 24519928653u },
130 { 5979700067267186899u, 9590990814237149589u, 24u },
131 { 4913998146922579597u, 452312848583u, 0u },
132 { 5771037749337678924u, 452u, 0u },
133 { 1u, 0u, 8835301376u },
134 { 3464734175350698519u, 15408590707489433889u, 90993782792u },
135 { 9334527711335850125u, 18332056844289122709u, 170602522202u },
136 { 7269882896518450106u, 11114572877353986192u, 202092341162u },
137 { 1372511258182263196u, 1703393793997526524u, 174275541962u },
138 { 7571228438575951046u, 5082852056285196264u, 26044258990u },
139 { 2992506536646070406u, 816434266573722364u, 1606938u },
140 { 524517896824344606u, 29642774844752946u, 0u },
141 { 15582941400898702773u, 29642774u, 0u },
142 { 1u, 0u, 214310977536u },
143 { 3846112492507251066u, 5736523019264798741u, 104549111254u },
144 { 16681117750123089487u, 10129314776268243338u, 62895095400u },
145 { 14986314536556547267u, 16511595775483995363u, 163670432318u },
146 { 2573712825027107389u, 12367293405401453324u, 137918027683u },
147 { 7504855874008324928u, 16934621733248854290u, 84557186697u },
148 { 9572138030626879787u, 10278280417769171335u, 105312291668u },
149 { 8520676959353394843u, 5760764486226151239u, 105u },
150 { 13448984662897903496u, 1942668892225u, 0u },
151 { 12338883700918130648u, 1942u, 0u },
152 { 1u, 0u, 156223799296u },
153 { 2517285787892561600u, 4128368337188369760u, 146555162524u },
154 { 4338831817635138103u, 10240941003671005055u, 36972170386u },
155 { 1561495325934523196u, 17933378316822368250u, 161452451108u },
156 { 12262635050079398786u, 8346249813075698615u, 3862277025u },
157 { 11144065765517284188u, 15906203609160902694u, 163787434755u },
158 { 1212260522471875711u, 14525607416135386327u, 242346790563u },
159 { 9695352922247418869u, 6397156777364256319u, 6901746u },
160 { 7227025834627242948u, 127314748520905380u, 0u },
161 { 9609008238705447829u, 127314748u, 0u },
162 { 1u, 0u, 74910662656u },
163 { 3609144142396852269u, 16798760952716600047u, 31131187530u },
164 { 11568848377382068865u, 2419982808370854966u, 224158453279u },
165 { 10068303578029323957u, 2922947087773078955u, 211835877600u },
166 { 11645070846862630231u, 15419220167069510189u, 190187140051u },
167 { 12449386705878485055u, 3452124642157173415u, 149324160190u },
168 { 15025619323517318418u, 5979700067267186898u, 199266388373u },
169 { 14996237555047131272u, 4913998146922579596u, 196312848583u },
170 { 10211005638256058413u, 5771037749337678923u, 452u },
171 { 1014743503555840530u, 8343699359066u, 0u },
172 { 12900897707145290678u, 8343u, 0u },
173 { 1u, 0u, 33187823616u },
174 { 4718003016239473662u, 3464734175350698518u, 149506025761u },
175 { 14865830648693666725u, 9334527711335850124u, 144394101141u },
176 { 14754517212823091778u, 7269882896518450105u, 252074403984u },
177 { 11113946551474911901u, 1372511258182263195u, 232410437116u },
178 { 1963520352638130630u, 7571228438575951045u, 252162224104u },
179 { 13342587341404964200u, 2992506536646070405u, 50028434172u },
180 { 6240392545013573291u, 524517896824344605u, 22844752946u },
181 { 14377490861349714758u, 15582941400898702772u, 29642774u },
182 { 1717863312631397839u, 546812681195752981u, 0u },
183 { 3611005143890591770u, 546812681u, 0u },
184 { 1u, 0u, 21208498176u },
185 { 13168252824351245504u, 3846112492507251065u, 138904285205u },
186 { 735883891883379688u, 16681117750123089486u, 227812409738u },
187 { 10609203866866106404u, 14986314536556547266u, 12139521251u },
188 { 12358191111890306470u, 2573712825027107388u, 18406839052u },
189 { 15229916368406413528u, 7504855874008324927u, 135518906642u },
190 { 7241424335568075942u, 9572138030626879786u, 71461906823u },
191 { 6049715868779871913u, 8520676959353394842u, 65729070919u },
192 { 2000548404719336762u, 13448984662897903495u, 150668892225u },
193 { 1410974761895205301u, 12338883700918130647u, 1942u },
194 { 16000132467694084868u, 35835915874844u, 0u },
195 { 16894908866816792556u, 35835u, 0u },
196 { 1u, 0u, 96136462336u },
197 { 589096329272056762u, 2517285787892561599u, 127235208544u },
198 { 7097729792403256904u, 4338831817635138102u, 250084648831u },
199 { 8553736750439287020u, 1561495325934523195u, 183664758778u },
200 { 2114152625261065696u, 12262635050079398785u, 38604121015u },
201 { 9817523680007641224u, 11144065765517284187u, 215065716774u },
202 { 13047215537500048015u, 1212260522471875710u, 63525586135u },
203 { 16755544192002345880u, 9695352922247418868u, 164391777855u },
204 { 6930119832670648356u, 7227025834627242947u, 60520905380u },
205 { 14560698131901886167u, 9609008238705447828u, 127314748u },
206 { 16408020927503338035u, 2348542582773833227u, 0u },
207 { 14274703510609809116u, 2348542582u, 0u },
208 { 1u, 0u, 239195652096u },
209 { 16428432973129962470u, 3609144142396852268u, 54627148527u },
210 { 3721112279790863774u, 11568848377382068864u, 171545803830u },
211 { 18032764903259620753u, 10068303578029323956u, 45631280555u },
212 { 18058455550468776079u, 11645070846862630230u, 167674882605u },
213 { 15692090139033993190u, 12449386705878485054u, 210814540455u },
214 { 389416944300619393u, 15025619323517318417u, 140812947666u },
215 { 12009691357260487293u, 14996237555047131271u, 75553539724u },
216 { 13494259174449809900u, 10211005638256058412u, 90055009355u },
217 { 18288583400616279877u, 1014743503555840529u, 151699359066u },
218 { 7216107869057472u, 12900897707145290677u, 8343u },
219 { 17237061291959073878u, 153914086704665u, 0u },
220 { 1599418782488783273u, 153914u, 0u },
221 { 1u, 0u, 22255763456u },
222 { 9565464987240335777u, 4718003016239473661u, 140805878294u },
223 { 857713933775880687u, 14865830648693666724u, 185799843980u },
224 { 4621617820081363356u, 14754517212823091777u, 155602488249u },
225 { 9630162611715632528u, 11113946551474911900u, 197106442651u },
226 { 9283986497984645815u, 1963520352638130629u, 133723303109u },
227 { 8981807745082630996u, 13342587341404964199u, 29338292357u },
228 { 18350140531565934622u, 6240392545013573290u, 180779405341u },
229 { 4411619033127524143u, 14377490861349714757u, 21093125556u },
230 { 1852297584111266889u, 1717863312631397838u, 9195752981u },
231 { 11746243463811666096u, 3611005143890591769u, 546812681u },
232 { 6335244004343789147u, 10086913586276986678u, 0u },
233 { 5109502367228239844u, 10086913586u, 0u },
234 { 1603272682579847821u, 10u, 0u },
235 { 1u, 0u, 121713852416u },
236 { 6609546910952910052u, 13168252824351245503u, 78039892345u },
237 { 3911171343112928288u, 735883891883379687u, 194575126094u },
238 { 5254510615100863555u, 10609203866866106403u, 60669938882u },
239 { 3881927570803887650u, 12358191111890306469u, 63825615420u },
240 { 6379348759607163190u, 15229916368406413527u, 42392558399u },
241 { 14595733737222406466u, 7241424335568075941u, 154327955754u },
242 { 14670223432002373542u, 6049715868779871912u, 135108449946u },
243 { 4045087795619708513u, 2000548404719336761u, 215076489095u },
244 { 12598467307137142718u, 1410974761895205300u, 28867368919u },
245 { 734704388050777108u, 16000132467694084867u, 251915874844u },
246 { 5682201693687285822u, 16894908866816792555u, 35835u },
247 { 11048712694145438788u, 661055968790248u, 0u },
248 { 17871025777010319485u, 661055u, 0u },
249 { 1u, 0u, 191031934976u },
250 { 15268761435931663695u, 589096329272056761u, 54384768703u },
251 { 5016238054648555438u, 7097729792403256903u, 59463698998u },
252 { 14236047313993899750u, 8553736750439287019u, 129114608443u },
253 { 6957759675154690848u, 2114152625261065695u, 91532209025u },
254 { 18439367135478514473u, 9817523680007641223u, 126707290971u },
255 { 8539004472540641041u, 13047215537500048014u, 244908319870u },
256 { 1908462039431738399u, 16755544192002345879u, 195375682548u },
257 { 714690453250792146u, 6930119832670648355u, 148789337027u },
258 { 13782189447673929633u, 14560698131901886166u, 11889480596u },
259 { 3584742913798803164u, 16408020927503338034u, 118773833227u },
260 { 4347581515245125291u, 14274703510609809115u, 2348542582u },
261 { 16836742268156371392u, 6429475823218628948u, 2u },
262 { 11764082328865615308u, 43322963970u, 0u },
263 { 5957633711383291746u, 43u, 0u },
264 { 1u, 0u, 44890587136u },
265 { 9917186842884466953u, 16428432973129962469u, 128201721900u },
266 { 4751011869809829335u, 3721112279790863773u, 180977558144u },
267 { 11068497969931435029u, 18032764903259620752u, 86978950836u },
268 { 17118056985122509954u, 18058455550468776078u, 62850669910u },
269 { 14607066080907684459u, 15692090139033993189u, 17021110334u },
270 { 11768892370493391107u, 389416944300619392u, 135651046673u },
271 { 4043396447647747170u, 12009691357260487292u, 44731525255u },
272 { 1670341095362518057u, 13494259174449809899u, 17991426092u },
273 { 3190817644167043165u, 18288583400616279876u, 181000391185u },
274 { 10425820027224322486u, 7216107869057471u, 25934422965u },
275 { 13139964660506311565u, 17237061291959073877u, 58086704665u },
276 { 2297772885416059937u, 1599418782488783272u, 153914u },
277 { 7677687919964523763u, 2839213766779714u, 0u },
278 { 14144589152747892828u, 2839213u, 0u },
279 { 1u, 0u, 253518544896u },
280 { 17069730341503660290u, 9565464987240335776u, 164046496765u },
281 { 18167423787163077107u, 857713933775880686u, 65250538404u },
282 { 3765746945827805904u, 4621617820081363355u, 156522052161u },
283 { 10241734342430761691u, 9630162611715632527u, 197503285916u },
284 { 13345717282537140784u, 9283986497984645814u, 103486904773u },
285 { 9313926784816939953u, 8981807745082630995u, 170994763111u },
286 { 550974205049535019u, 18350140531565934621u, 69239154346u },
287 { 4494692285504086222u, 4411619033127524142u, 206100413253u },
288 { 1134308559863725587u, 1852297584111266888u, 25636765134u },
289 { 17587558045116130233u, 11746243463811666095u, 54343434265u },
290 { 9817142032346161594u, 6335244004343789146u, 50276986678u },
291 { 6071944935834172568u, 5109502367228239843u, 10086913586u },
292 { 11564168293299416955u, 1603272682579847820u, 10u },
293 { 12458266507226064437u, 186070713419u, 0u },
294 { 1304432355328256915u, 186u, 0u },
295 { 1u, 0u, 191358304256u },
296 { 15946798815542087355u, 6609546910952910051u, 231212025023u },
297 { 12082566083831286138u, 3911171343112928287u, 35284847591u },
298 { 11449623684706196411u, 5254510615100863554u, 165210439715u },
299 { 17518743620362604446u, 3881927570803887649u, 215345825189u },
300 { 9451061563087633805u, 6379348759607163189u, 165791236311u },
301 { 13191114787623314926u, 14595733737222406465u, 168795274405u },
302 { 8367349876734474799u, 14670223432002373541u, 57219284648u },
303 { 6544253801674393507u, 4045087795619708512u, 180682964281u },
304 { 16113906253336597498u, 12598467307137142717u, 3039828404u },
305 { 10294087136797312392u, 734704388050777107u, 235308032771u },
306 { 9127173070014462803u, 5682201693687285821u, 232598951915u },
307 { 16266900839595484952u, 11048712694145438787u, 63968790248u },
308 { 3299745387370952632u, 17871025777010319484u, 661055u },
309 { 12061115182604399189u, 12194330274671844u, 0u },
310 { 5066801222582989646u, 12194330u, 0u },
311 { 1u, 0u, 185827721216u },
312 { 7568423425299591513u, 15268761435931663694u, 71271930809u },
313 { 16561505984665207377u, 5016238054648555437u, 235771737671u },
314 { 4329114621856906245u, 14236047313993899749u, 223377180907u },
315 { 1477500474861899139u, 6957759675154690847u, 135999600095u },
316 { 16891579639263969684u, 18439367135478514472u, 142462900359u },
317 { 4684451357140027420u, 8539004472540641040u, 151103457934u },
318 { 14727186580409080709u, 1908462039431738398u, 35038743447u },
319 { 15864176859687308834u, 714690453250792145u, 214747133987u },
320 { 1755486942842684438u, 13782189447673929632u, 50194329302u },
321 { 17417077516652710041u, 3584742913798803163u, 219235682866u },
322 { 4290982361913532783u, 4347581515245125290u, 84912721627u },
323 { 11826659981004351409u, 16836742268156371391u, 2637732180u },
324 { 932930645678090820u, 11764082328865615307u, 43322963970u },
325 { 12707792781328052617u, 5957633711383291745u, 43u },
326 { 16491596426880311906u, 799167628880u, 0u },
327 { 3092207065214166010u, 799u, 0u },
328 { 1u, 0u, 229537611776u },
329 { 8142946531605512550u, 9917186842884466952u, 157257552869u },
330 { 5328402096432654515u, 4751011869809829334u, 144600024477u },
331 { 1932004361303814512u, 11068497969931435028u, 142927971728u },
332 { 2511477647985517771u, 17118056985122509953u, 229791850638u },
333 { 17451375493324716694u, 14607066080907684458u, 128637992933u },
334 { 9489266854478998489u, 11768892370493391106u, 124219192960u },
335 { 8803053132063235169u, 4043396447647747169u, 235090549372u },
336 { 16198682197142616773u, 1670341095362518056u, 68172974571u },
337 { 13696242485403414202u, 3190817644167043164u, 191565184836u },
338 { 16409082426079859931u, 10425820027224322485u, 85712318911u },
339 { 11653410736879597610u, 13139964660506311564u, 168124562517u },
340 { 13589514120653213261u, 2297772885416059936u, 66416208296u },
341 { 8032934885905905774u, 7677687919964523762u, 173766779714u },
342 { 2753021350129449273u, 14144589152747892827u, 2839213u },
343 { 16974897459201404133u, 52374249726338269u, 0u },
344 { 13398576176159101589u, 52374249u, 0u },
345 { 1u, 0u, 160925351936u },
346 { 10284586955251725351u, 17069730341503660289u, 238984858016u },
347 { 5294476488634150891u, 18167423787163077106u, 155204141550u },
348 { 15833244538135063323u, 3765746945827805903u, 143555205531u },
349 { 10348512742273116664u, 10241734342430761690u, 182723472783u },
350 { 13658504610142595663u, 13345717282537140783u, 83504908982u },
351 { 11956362239240850266u, 9313926784816939952u, 29029868371u },
352 { 13415901703662731781u, 550974205049535018u, 46243657757u },
353 { 5161774027546852762u, 4494692285504086221u, 72061490990u },
354 { 15274384838790587711u, 1134308559863725586u, 175953423432u },
355 { 14233354597679374929u, 17587558045116130232u, 90532188335u },
356 { 4274656492162486921u, 9817142032346161593u, 227329160794u },
357 { 12040276505541795046u, 6071944935834172567u, 140626894819u },
358 { 13238307206256765457u, 11564168293299416954u, 75675363980u },
359 { 12850161204172713271u, 12458266507226064436u, 186070713419u },
360 { 17531777095001445154u, 1304432355328256914u, 186u },
361 { 5623628114515245990u, 3432398830065u, 0u },
362 { 7357116143579573377u, 3432u, 0u },
363 { 1u, 0u, 227864477696u },
364 { 3555734177475596582u, 15946798815542087354u, 31654997219u },
365 { 14001876724756424382u, 12082566083831286137u, 66620685343u },
366 { 18159905057231476140u, 11449623684706196410u, 33949692994u },
367 { 5585207679308509467u, 17518743620362604445u, 53512343073u },
368 { 13948697622866724672u, 9451061563087633804u, 65715091765u },
369 { 9807691927739036432u, 13191114787623314925u, 165453594945u },
370 { 15818010096140820918u, 8367349876734474798u, 96354764709u },
371 { 5629845624785010943u, 6544253801674393506u, 189873536608u },
372 { 9517635131137734707u, 16113906253336597497u, 19558043581u },
373 { 619338244618780585u, 10294087136797312391u, 61494785043u },
374 { 11632367007491958899u, 9127173070014462802u, 67881830461u },
375 { 12083314261009739916u, 16266900839595484951u, 124178879555u },
376 { 16880538609458881650u, 3299745387370952631u, 228653834364u },
377 { 17404223674486504228u, 12061115182604399188u, 26274671844u },
378 { 7089067015287185433u, 5066801222582989645u, 12194330u },
379 { 2592264228029443648u, 224945689727159819u, 0u },
380 { 13413731084370224440u, 224945689u, 0u },
381 { 1u, 0u, 78410285056u },
382 { 9323915941641553425u, 7568423425299591512u, 173897801038u },
383 { 12155831029092699564u, 16561505984665207376u, 229234681773u },
384 { 17397171276588232676u, 4329114621856906244u, 31080095461u },
385 { 11874560617553253769u, 1477500474861899138u, 40915694367u },
386 { 13444839516837727954u, 16891579639263969683u, 16253944616u },
387 { 16994416043584590671u, 4684451357140027419u, 30798362384u },
388 { 15879694502877015730u, 14727186580409080708u, 209859998750u },
389 { 4234647645735263359u, 15864176859687308833u, 160095165137u },
390 { 7978589901512919496u, 1755486942842684437u, 219944181664u },
391 { 6114237175390859894u, 17417077516652710040u, 170232614619u },
392 { 8658612872088282708u, 4290982361913532782u, 191641124522u },
393 { 10253813330683324853u, 11826659981004351408u, 203050574271u },
394 { 13289465061747830991u, 932930645678090819u, 97688890827u },
395 { 4123165538545565412u, 12707792781328052616u, 80894011233u },
396 { 7846417485927038481u, 16491596426880311905u, 31167628880u },
397 { 10562273346358018864u, 3092207065214166009u, 799u },
398 { 2691512658346619120u, 14742040721959u, 0u },
399 { 751187558544605998u, 14742u, 0u },
400 { 1u, 0u, 8441430016u },
401 { 3757709791947931308u, 8142946531605512549u, 214288853256u },
402 { 3452755398462519465u, 5328402096432654514u, 20104734166u },
403 { 3105818720159874523u, 1932004361303814511u, 129136147476u },
404 { 16859138458894499364u, 2511477647985517770u, 106946040961u },
405 { 12271894740606233755u, 17451375493324716693u, 2514414186u },
406 { 5429638071845793701u, 9489266854478998488u, 97477214466u },
407 { 145278150038876889u, 8803053132063235168u, 40878132321u },
408 { 9050266019724932450u, 16198682197142616772u, 92742474792u },
409 { 11907016253451490866u, 13696242485403414201u, 181889538140u },
410 { 2472757296513770735u, 16409082426079859930u, 140631732661u },
411 { 10558733798178239360u, 11653410736879597609u, 32736689036u },
412 { 15917322570831255850u, 13589514120653213260u, 242435466272u },
413 { 12254334656791355238u, 8032934885905905773u, 91149241586u },
414 { 7869542424662730262u, 2753021350129449272u, 221920211035u },
415 { 1378558986933000253u, 16974897459201404132u, 233726338269u },
416 { 13521405041909411105u, 13398576176159101588u, 52374249u },
417 { 3206744593298092012u, 966134380754314586u, 0u },
418 { 13914648122214918505u, 966134380u, 0u },
419 { 1u, 0u, 1557528576u },
420 { 1235541077112082496u, 10284586955251725350u, 242287014145u },
421 { 12014985518315533846u, 5294476488634150890u, 207858321906u },
422 { 1561535086344155741u, 15833244538135063322u, 218560993999u },
423 { 12761747276316224577u, 10348512742273116663u, 47740429018u },
424 { 9745594781103966137u, 13658504610142595662u, 176648155695u },
425 { 17514238702394846785u, 11956362239240850265u, 42727277488u },
426 { 2428898913707151713u, 13415901703662731780u, 205279820330u },
427 { 71666709959904945u, 5161774027546852761u, 18828026061u },
428 { 4049380135452919193u, 15274384838790587710u, 184771591698u },
429 { 18422240861777453733u, 14233354597679374928u, 185231729592u },
430 { 2914504416394425696u, 4274656492162486920u, 151652704697u },
431 { 12721377795748989418u, 12040276505541795045u, 122717650071u },
432 { 2626074459217717422u, 13238307206256765456u, 52696608634u },
433 { 4261529925046307655u, 12850161204172713270u, 146950399540u },
434 { 11536038685430305586u, 17531777095001445153u, 241304857490u },
435 { 12555757789435162768u, 5623628114515245989u, 104398830065u },
436 { 11905178684546080059u, 7357116143579573376u, 3432u },
437 { 14032797718924543051u, 63316582777114u, 0u },
438 { 10750340288005853484u, 63316u, 0u },
439 { 1u, 0u, 186192756736u },
440 { 9660290106216358253u, 3555734177475596581u, 121759043258u },
441 { 14820142034615351103u, 14001876724756424381u, 186984450425u },
442 { 12674041783707777619u, 18159905057231476139u, 157302774714u },
443 { 15386686816442679994u, 5585207679308509466u, 140756160413u },
444 { 5679510383719146248u, 13948697622866724671u, 237531676044u },
445 { 1391101719248678506u, 9807691927739036431u, 46857496045u },
446 { 3364596672173710517u, 15818010096140820917u, 162305194542u },
447 { 11276509210104319732u, 5629845624785010942u, 249515952034u },
448 { 5316312656902630164u, 9517635131137734706u, 135033574393u },
449 { 17470981304473644647u, 619338244618780584u, 82630591879u },
450 { 7373293636384920591u, 11632367007491958898u, 23655037778u },
451 { 7616810902585191937u, 12083314261009739915u, 183915095831u },
452 { 12740295655921903924u, 16880538609458881649u, 84943484855u },
453 { 18366635945916526940u, 17404223674486504227u, 77384299092u },
454 { 4472171448243407067u, 7089067015287185432u, 11140526925u },
455 { 229592460858185629u, 2592264228029443647u, 25727159819u },
456 { 12749672866417114996u, 13413731084370224439u, 224945689u },
457 { 9452256722867098693u, 4149515568880992958u, 0u },
458 { 16251451636418604634u, 4149515568u, 0u },
459 { 1u, 0u, 88505450496u },
460 { 4515791283442995454u, 9323915941641553424u, 80658968920u },
461 { 13306155670047701346u, 12155831029092699563u, 4943102544u },
462 { 4456930152933417601u, 17397171276588232675u, 130643721220u },
463 { 9089157128546489637u, 11874560617553253768u, 147728846210u },
464 { 12437332180345515840u, 13444839516837727953u, 27921269139u },
465 { 3433060408790452524u, 16994416043584590670u, 132860839963u },
466 { 8275594526021936172u, 15879694502877015729u, 33229560708u },
467 { 3846512444641107689u, 4234647645735263358u, 21432520225u },
468 { 6210962618469046250u, 7978589901512919495u, 152331453461u },
469 { 7272858906616296575u, 6114237175390859893u, 110469384344u },
470 { 3710743300451225347u, 8658612872088282707u, 176555860334u },
471 { 6424677242672030600u, 10253813330683324852u, 67720423344u },
472 { 11485842256170301862u, 13289465061747830990u, 136223517251u },
473 { 7355797963557024308u, 4123165538545565411u, 97425355144u },
474 { 6358188982569427273u, 7846417485927038480u, 249572581985u },
475 { 12475094728768767402u, 10562273346358018863u, 39145907193u },
476 { 17288154837907896183u, 2691512658346619119u, 150040721959u },
477 { 2983850577727105262u, 751187558544605997u, 14742u },
478 { 13918604635001185935u, 271942652322184u, 0u },
479 { 12033220395769876327u, 271942u, 0u },
480 { 1u, 0u, 101203705856u },
481 { 5782377197813462997u, 3757709791947931307u, 178187174245u },
482 { 17732139848231399226u, 3452755398462519464u, 111168366770u },
483 { 3628839527415562921u, 3105818720159874522u, 202913935727u },
484 { 3188692267613601004u, 16859138458894499363u, 149665260746u },
485 { 5168130193478377352u, 12271894740606233754u, 216294341269u },
486 { 12556227529405091290u, 5429638071845793700u, 96007875544u },
487 { 15087090312791441192u, 145278150038876888u, 196490615904u },
488 { 10281804758610642494u, 9050266019724932449u, 185645480644u },
489 { 14238177586158586580u, 11907016253451490865u, 218134048441u },
490 { 7107927498217678128u, 2472757296513770734u, 41572390106u },
491 { 3845814658485364450u, 10558733798178239359u, 76862879785u },
492 { 714293333681725946u, 15917322570831255849u, 109664308812u },
493 { 16766172658649116982u, 12254334656791355237u, 56426608749u },
494 { 812461421432632215u, 7869542424662730261u, 228074731832u },
495 { 15218024718633799196u, 1378558986933000252u, 148732996836u },
496 { 8110797782612805146u, 13521405041909411104u, 90173837972u },
497 { 15941193964933529227u, 3206744593298092011u, 108754314586u },
498 { 14144280602323277933u, 13914648122214918504u, 966134380u },
499 { 15072402647813125245u, 17822033662586700072u, 0u },
500 { 10822706091283369889u, 17822033662u, 0u },
501 { 15163844593710966731u, 17u, 0u },
502 { 1u, 0u, 38066978816u },
503 { 2408529687792073670u, 1235541077112082495u, 234651333670u },
504 { 3980682212356510808u, 12014985518315533845u, 26084650986u },
505 { 4202670442792148519u, 1561535086344155740u, 247691815706u },
506 { 9419583343154651922u, 12761747276316224576u, 78528309751u },
507 { 16359166491570434575u, 9745594781103966136u, 89949448782u },
508 { 12567727056384237385u, 17514238702394846784u, 4131670873u },
509 { 2068388267923286639u, 2428898913707151712u, 153003885060u },
510 { 5689135844565021196u, 71666709959904944u, 62219517337u },
511 { 3104061965171139313u, 4049380135452919192u, 80998671678u },
512 { 7955173880156328016u, 18422240861777453732u, 136157995600u },
513 { 1445179403240833754u, 2914504416394425695u, 229689627272u },
514 { 12538201164459126715u, 12721377795748989417u, 16142359781u },
515 { 7580606719088482667u, 2626074459217717421u, 54231018000u },
516 { 8168318283218819755u, 4261529925046307654u, 33625369910u },
517 { 5249615277755961676u, 11536038685430305585u, 165680648993u },
518 { 6312997372068219831u, 12555757789435162767u, 128645381029u },
519 { 9183815417025176703u, 11905178684546080058u, 26760719488u },
520 { 10683849953373876937u, 14032797718924543050u, 84582777114u },
521 { 17175012155615667568u, 10750340288005853483u, 63316u },
522 { 18003508288378896912u, 1167984798111281u, 0u },
523 { 14722554560950996951u, 1167984u, 0u },
524 { 1u, 0u, 37523685376u },
525 { 15059324482416394930u, 9660290106216358252u, 189803401509u },
526 { 4134778595813308312u, 14820142034615351102u, 171687061181u },
527 { 16321118342639660948u, 12674041783707777618u, 26834113963u },
528 { 1523550293123468805u, 15386686816442679993u, 63307886874u },
529 { 8016371634569878509u, 5679510383719146247u, 15075411775u },
530 { 9884220139611134110u, 1391101719248678505u, 181182395151u },
531 { 7218073002727840414u, 3364596672173710516u, 254611300789u },
532 { 16062235669481359233u, 11276509210104319731u, 50288197886u },
533 { 15558048660560338002u, 5316312656902630163u, 168947103794u },
534 { 8394398745765058609u, 17470981304473644646u, 114399707048u },
535 { 5693296366442904274u, 7373293636384920590u, 139412908146u },
536 { 11783494675061161358u, 7616810902585191936u, 113690652811u },
537 { 13377293110865447894u, 12740295655921903923u, 35995657329u },
538 { 12840734051093062130u, 18366635945916526939u, 24242436899u },
539 { 7009868331566697505u, 4472171448243407066u, 63012446232u },
540 { 5019690705031194477u, 229592460858185628u, 55691161151u },
541 { 8608277240439804984u, 12749672866417114995u, 190512407863u },
542 { 12172482590657749222u, 9452256722867098692u, 48880992958u },
543 { 16613484892678771990u, 16251451636418604633u, 4149515568u },
544 { 5721488662757049244u, 2758075434182769113u, 4u },
545 { 386931106438877039u, 76545051729u, 0u },
546 { 10054429752182825659u, 76u, 0u },
547 { 1u, 0u, 16244801536u },
548 { 8634592106137071313u, 4515791283442995453u, 171721328144u },
549 { 12626356501369830731u, 13306155670047701345u, 227241610667u },
550 { 4803333258178976933u, 4456930152933417600u, 136492724195u },
551 { 13613083223558209297u, 9089157128546489636u, 209674229128u },
552 { 16106967997237446989u, 12437332180345515839u, 78186106577u },
553 { 14832921244380020170u, 3433060408790452523u, 177448620878u },
554 { 13774024637717231397u, 8275594526021936171u, 126208519857u },
555 { 9673012968505228885u, 3846512444641107688u, 199336696958u },
556 { 5391832334264815667u, 6210962618469046249u, 117394262471u },
557 { 16514436292632703088u, 7272858906616296574u, 83201159797u },
558 { 12025036352783454153u, 3710743300451225346u, 180348282451u },
559 { 7059867105311401050u, 6424677242672030599u, 206622648756u },
560 { 12769210631552594670u, 11485842256170301861u, 227398758606u },
561 { 8328873878884556145u, 7355797963557024307u, 16344678115u },
562 { 1016565892414238685u, 6358188982569427272u, 47676276240u },
563 { 9662978461927250281u, 12475094728768767401u, 239937192751u },
564 { 13729967277551868112u, 17288154837907896182u, 45161754863u },
565 { 6371593776693359475u, 2983850577727105261u, 136754529069u },
566 { 17617208110845643245u, 13918604635001185934u, 70652322184u },
567 { 14960960225633086797u, 12033220395769876326u, 271942u },
568 { 12090634301321662558u, 5016456510113118u, 0u },
569 { 9409926148478635503u, 5016456u, 0u },
570 { 1u, 0u, 171313463296u },
571 { 4307062684900157136u, 5782377197813462996u, 168961261227u },
572 { 15300759383869911853u, 17732139848231399225u, 218196719784u },
573 { 16007534237643445447u, 3628839527415562920u, 35172859354u },
574 { 7138502295759677634u, 3188692267613601003u, 154280164899u },
575 { 8218537071653683708u, 5168130193478377351u, 164680674458u },
576 { 2254219416760329296u, 12556227529405091289u, 216817872804u },
577 { 3057410459568460683u, 15087090312791441191u, 97557377752u },
578 { 8217810929938874370u, 10281804758610642493u, 49771853153u },
579 { 11741126472498340929u, 14238177586158586579u, 238385321521u },
580 { 1175325363726654805u, 7107927498217678127u, 127208482030u },
581 { 9428843070696730900u, 3845814658485364449u, 41038721919u },
582 { 12662500978715131896u, 714293333681725945u, 101908896041u },
583 { 6443045597035184564u, 16766172658649116981u, 21044043621u },
584 { 1921385512639171183u, 812461421432632214u, 60824970773u },
585 { 10469475094355551399u, 15218024718633799195u, 32439687228u },
586 { 14679174489076953574u, 8110797782612805145u, 235864173856u },
587 { 11853074234719825644u, 15941193964933529226u, 104766762987u },
588 { 8270896886596139124u, 14144280602323277932u, 40817076584u },
589 { 16532667046659118126u, 15072402647813125244u, 254586700072u },
590 { 148341279888833483u, 10822706091283369888u, 17822033662u },
591 { 10364629296397276041u, 15163844593710966730u, 17u },
592 { 14265682585545771671u, 328758493846u, 0u },
593 { 13991741872911347878u, 328u, 0u },
594 { 1u, 0u, 63130566656u },
595 { 14029045786848724433u, 2408529687792073669u, 21215793215u },
596 { 4005878521026842341u, 3980682212356510807u, 92227827221u },
597 { 3428326338640386488u, 4202670442792148518u, 64510636636u },
598 { 1010001558294829380u, 9419583343154651921u, 184886832192u },
599 { 2012063724327403418u, 16359166491570434574u, 64681297848u },
600 { 10997154538851372612u, 12567727056384237384u, 96112127552u },
601 { 1917749645489607898u, 2068388267923286638u, 176308408672u },
602 { 9763872523711218805u, 5689135844565021195u, 152168271536u },
603 { 15875699078454059311u, 3104061965171139312u, 164431250840u },
604 { 10966529452671276106u, 7955173880156328015u, 95078343332u },
605 { 18073244132105736913u, 1445179403240833753u, 233679697247u },
606 { 4435241176994913173u, 12538201164459126714u, 173410945513u },
607 { 5464400086219074323u, 7580606719088482666u, 70442805421u },
608 { 2445909179323258812u, 8168318283218819754u, 49284582214u },
609 { 873962058644121211u, 5249615277755961675u, 143342228273u },
610 { 16675872194112650857u, 6312997372068219830u, 58497855631u },
611 { 10680102689274800355u, 9183815417025176702u, 74579172666u },
612 { 2370498083108897524u, 10683849953373876936u, 43931059274u },
613 { 15354400521451334666u, 17175012155615667567u, 49975972139u },
614 { 259991949657381021u, 18003508288378896911u, 112798111281u },
615 { 10335286558772966917u, 14722554560950996950u, 1167984u },
616 { 16337526653906757263u, 21545516652742137u, 0u },
617 { 12040967163702784894u, 21545516u, 0u },
618 { 1u, 0u, 108816367616u },
619 { 3373309160242342187u, 15059324482416394929u, 62224146796u },
620 { 13639841054510584221u, 4134778595813308311u, 82884769598u },
621 { 15898855427739708031u, 16321118342639660947u, 185082591826u },
622 { 4544387940067005419u, 1523550293123468804u, 7434568377u },
623 { 5281598644835398575u, 8016371634569878508u, 105535824647u },
624 { 13675642405083408835u, 9884220139611134109u, 180391292521u },
625 { 3973392623768015721u, 7218073002727840413u, 243870735540u },
626 { 4491285101509114191u, 16062235669481359232u, 19843403507u },
627 { 15002304272810270500u, 15558048660560338001u, 102455061267u },
628 { 17325098540619893468u, 8394398745765058608u, 14308634214u },
629 { 1137212864974584822u, 5693296366442904273u, 638784526u },
630 { 2619406097224859078u, 11783494675061161357u, 51725184512u },
631 { 8281347529729293732u, 13377293110865447893u, 91696097587u },
632 { 11344719666795450104u, 12840734051093062129u, 218380005723u },
633 { 17283870506679425783u, 7009868331566697504u, 156272117978u },
634 { 11054210518010603775u, 5019690705031194476u, 115466655644u },
635 { 6399455551799092885u, 8608277240439804983u, 68659871603u },
636 { 12930529916573967170u, 12172482590657749221u, 89900618820u },
637 { 14550097052337552404u, 16613484892678771989u, 217310162521u },
638 { 12487632712206414748u, 5721488662757049243u, 81020975577u },
639 { 5791017277843595715u, 386931106438877038u, 76545051729u },
640 { 10227264183449036113u, 10054429752182825658u, 76u },
641 { 2006055278511721441u, 1412006979354u, 0u },
642 { 128746359043876333u, 1412u, 0u },
643 { 1u, 0u, 253468082176u },
644 { 7408146306870995754u, 8634592106137071312u, 97684476157u },
645 { 8299024588195267962u, 12626356501369830730u, 128260389217u },
646 { 1497052939192040881u, 4803333258178976932u, 36737966720u },
647 { 16771714264265803747u, 13613083223558209296u, 63873160484u },
648 { 142988846654429432u, 16106967997237446988u, 43804094271u },
649 { 11839838367716104145u, 14832921244380020169u, 43746691371u },
650 { 6019646776647679765u, 13774024637717231396u, 232524375083u },
651 { 4611972391702034948u, 9673012968505228884u, 233292291816u },
652 { 16447182322205429545u, 5391832334264815666u, 126895249385u },
653 { 2113477168726764245u, 16514436292632703087u, 2651878526u },
654 { 3536261187802311516u, 12025036352783454152u, 135382716162u },
655 { 18444381860986709854u, 7059867105311401049u, 165692220295u },
656 { 4734315730275909838u, 12769210631552594669u, 51451509157u },
657 { 9974936316849658174u, 8328873878884556144u, 72055108147u },
658 { 11864423681540657642u, 1016565892414238684u, 169523831112u },
659 { 8207245621417902667u, 9662978461927250280u, 118744303017u },
660 { 7992526918695295028u, 13729967277551868111u, 237345404790u },
661 { 8679354522130259987u, 6371593776693359474u, 142955030765u },
662 { 6065763799692166461u, 17617208110845643244u, 102811035278u },
663 { 18143341109049024976u, 14960960225633086796u, 94655434598u },
664 { 15242492331283350570u, 12090634301321662557u, 136510113118u },
665 { 9986352353182266963u, 9409926148478635502u, 5016456u },
666 { 17340463289911536077u, 92537289398950870u, 0u },
667 { 7359344614214233035u, 92537289u, 0u },
668 { 1u, 0u, 212233486336u },
669 { 419091135888749535u, 4307062684900157135u, 57829455828u },
670 { 1073142712661309790u, 15300759383869911852u, 168867770169u },
671 { 11076438902195672286u, 16007534237643445446u, 235386978984u },
672 { 1820390940081322073u, 7138502295759677633u, 135445527787u },
673 { 18417808973944523597u, 8218537071653683707u, 217122201479u },
674 { 10251294197731582957u, 2254219416760329295u, 39165742553u },
675 { 1502394029870156428u, 3057410459568460682u, 61445488423u },
676 { 321014853559106075u, 8217810929938874369u, 211636487741u },
677 { 2390953058510591778u, 11741126472498340928u, 47063714515u },
678 { 10685224265907994087u, 1175325363726654804u, 225511138607u },
679 { 5967405799190505023u, 9428843070696730899u, 249686435553u },
680 { 11210723659228214761u, 12662500978715131895u, 53349278201u },
681 { 12327123641078462773u, 6443045597035184563u, 150104158517u },
682 { 1709976940107894237u, 1921385512639171182u, 27567551382u },
683 { 16607686590938553511u, 10469475094355551398u, 25795759643u },
684 { 18332088094272679457u, 14679174489076953573u, 138642556441u },
685 { 2946170632136780882u, 11853074234719825643u, 108448366218u },
686 { 4824449494694383419u, 8270896886596139123u, 124896237676u },
687 { 17008332258693407134u, 16532667046659118125u, 160008041596u },
688 { 1773419466622750661u, 148341279888833482u, 202561867680u },
689 { 3892343466023784379u, 10364629296397276040u, 150773344202u },
690 { 12001571085575422796u, 14265682585545771670u, 72758493846u },
691 { 12933506765500977582u, 13991741872911347877u, 328u },
692 { 11884830007749143734u, 6064523798049u, 0u },
693 { 9662368568096205337u, 6064u, 0u },
694 { 1u, 0u, 197760516096u },
695 { 16801499925276664442u, 14029045786848724432u, 87217159109u },
696 { 10492407990787637084u, 4005878521026842340u, 38185849943u },
697 { 7673849751013230269u, 3428326338640386487u, 17054752294u },
698 { 6046724489853072367u, 1010001558294829379u, 14109074193u },
699 { 3723941391207507903u, 2012063724327403417u, 72596156942u },
700 { 16844122108860347659u, 10997154538851372611u, 110103961416u },
701 { 10622020182694668027u, 1917749645489607897u, 11529300590u },
702 { 8741198820686854862u, 9763872523711218804u, 240860623371u },
703 { 6855480461211306807u, 15875699078454059310u, 79594496752u },
704 { 10005708458011566304u, 10966529452671276105u, 217979752527u },
705 { 8932093106442919061u, 18073244132105736912u, 186240434905u },
706 { 9062763476260756743u, 4435241176994913172u, 106296225722u },
707 { 13664977682032775521u, 5464400086219074322u, 170132593002u },
708 { 1078499125430623453u, 2445909179323258811u, 75047377578u },
709 { 6554586738078431161u, 873962058644121210u, 182904000843u },
710 { 12177313698643242883u, 16675872194112650856u, 126578969526u },
711 { 16615072271904633953u, 10680102689274800354u, 200128504958u },
712 { 16375404983106569285u, 2370498083108897523u, 111832363720u },
713 { 13552251831473522729u, 15354400521451334665u, 15014094191u },
714 { 8330500218412111874u, 259991949657381020u, 214560277007u },
715 { 7044338079053294004u, 10335286558772966916u, 249885659094u },
716 { 2688849443046530184u, 16337526653906757262u, 44652742137u },
717 { 855940991879596845u, 12040967163702784893u, 21545516u },
718 { 7344363609485825662u, 397444631628981487u, 0u },
719 { 11602660525134634992u, 397444631u, 0u },
720 { 1u, 0u, 177182867456u },
721 { 16945343208344873835u, 3373309160242342186u, 151739417265u },
722 { 9617992661337889145u, 13639841054510584220u, 147861878679u },
723 { 18280344933262742088u, 15898855427739708030u, 4246351763u },
724 { 5179975582362777795u, 4544387940067005418u, 236286316036u },
725 { 1798918997870037130u, 5281598644835398574u, 157741358060u },
726 { 6327667344756325883u, 13675642405083408834u, 157215398045u },
727 { 18380327574124007701u, 3973392623768015720u, 128243473053u },
728 { 18015447557304295289u, 4491285101509114190u, 81813276544u },
729 { 10315590748073249878u, 15002304272810270499u, 48939195473u },
730 { 7697916092577993382u, 17325098540619893467u, 209061648432u },
731 { 3124132817942110723u, 1137212864974584821u, 141141998289u },
732 { 7448238998520507049u, 2619406097224859077u, 213448932749u },
733 { 13892823322374205297u, 8281347529729293731u, 241614998485u },
734 { 11042137840046332564u, 11344719666795450103u, 32936960497u },
735 { 10513966307445593804u, 17283870506679425782u, 108599249952u },
736 { 9388437460943526958u, 11054210518010603774u, 55346915180u },
737 { 10967228614677896228u, 6399455551799092884u, 229700965431u },
738 { 2310996671540235542u, 12930529916573967169u, 21788762341u },
739 { 4989110555003898587u, 14550097052337552403u, 155676955925u },
740 { 16271452421983657679u, 12487632712206414747u, 110313931675u },
741 { 9523160181437090473u, 5791017277843595714u, 186554421102u },
742 { 13137707423765072250u, 10227264183449036112u, 26108748474u },
743 { 16846859744221860705u, 2006055278511721440u, 132006979354u },
744 { 7767140033449795569u, 128746359043876332u, 1412u },
745 { 17169456915721160017u, 26046931378436u, 0u },
746 { 17180899661833327819u, 26046u, 0u },
747 { 1u, 0u, 208401596416u },
748 { 17572520700934791416u, 7408146306870995753u, 74449891024u },
749 { 17968798858233825417u, 8299024588195267961u, 164081155402u },
750 { 15338423313945305609u, 1497052939192040880u, 16909196452u },
751 { 17895321323836726301u, 16771714264265803746u, 76007751440u },
752 { 814069333008965773u, 142988846654429431u, 201641838924u },
753 { 7200328959852723947u, 11839838367716104144u, 36326325705u },
754 { 759884557248133773u, 6019646776647679764u, 84250015524u },
755 { 13410165861863974851u, 4611972391702034947u, 50891603540u },
756 { 6278452420856351570u, 16447182322205429544u, 111114571826u },
757 { 9072115382556676442u, 2113477168726764244u, 200191701103u },
758 { 2755882551854926563u, 3536261187802311515u, 89999871944u },
759 { 8496072611504649269u, 18444381860986709853u, 237256647769u },
760 { 4122009033579215815u, 4734315730275909837u, 112540742381u },
761 { 10222217724450527221u, 9974936316849658173u, 220643171696u },
762 { 2064539481554006325u, 11864423681540657641u, 104444915676u },
763 { 7935605886598063693u, 8207245621417902666u, 207433275752u },
764 { 7805147585347548429u, 7992526918695295027u, 114470508751u },
765 { 5709020905457661273u, 8679354522130259986u, 236328825714u },
766 { 16257370307404906674u, 6065763799692166460u, 76983552492u },
767 { 14971258192939373646u, 18143341109049024975u, 93826297164u },
768 { 1133404845901376390u, 15242492331283350569u, 238541361245u },
769 { 9460827548162822047u, 9986352353182266962u, 214940028398u },
770 { 1273897659779791346u, 17340463289911536076u, 201398950870u },
771 { 7833262224435092783u, 7359344614214233034u, 92537289u },
772 { 3033420566713364587u, 1707011694817242694u, 0u },
773 { 15075466825360349103u, 1707011694u, 0u },
774 { 1u, 0u, 207022718976u },
775 { 2484134775182816690u, 419091135888749534u, 44058175183u },
776 { 18400539815335991277u, 1073142712661309789u, 198600454956u },
777 { 485494064952118286u, 11076438902195672285u, 193098683590u },
778 { 17577048805241314891u, 1820390940081322072u, 251998431425u },
779 { 2863946907557583807u, 18417808973944523596u, 79555723771u },
780 { 13045307417786230800u, 10251294197731582956u, 138081444943u },
781 { 12032088871615097766u, 1502394029870156427u, 1017402250u },
782 { 8848763446997690580u, 321014853559106074u, 64129613825u },
783 { 10031289150307672684u, 2390953058510591777u, 84579247168u },
784 { 11592215575498656563u, 10685224265907994086u, 19323493716u },
785 { 15894436747956898388u, 5967405799190505022u, 247607734547u },
786 { 2091546719588500923u, 11210723659228214760u, 179668254711u },
787 { 5863809244813756109u, 12327123641078462772u, 110092698035u },
788 { 11303008753675411245u, 1709976940107894236u, 166900304494u },
789 { 13238426537506910532u, 16607686590938553510u, 229993784486u },
790 { 17258458071023005565u, 18332088094272679456u, 235159712229u },
791 { 8385733444777075179u, 2946170632136780881u, 115261533931u },
792 { 9530757096163247300u, 4824449494694383418u, 45922023539u },
793 { 14423000845391072217u, 17008332258693407133u, 202096137261u },
794 { 10953140011159884311u, 1773419466622750660u, 136211004362u },
795 { 12228340237948264127u, 3892343466023784378u, 150650606472u },
796 { 11279134946966259189u, 12001571085575422795u, 165701126806u },
797 { 14640097792684582651u, 12933506765500977581u, 33644277925u },
798 { 6232313315128656728u, 11884830007749143733u, 176523798049u },
799 { 16136121832933322088u, 9662368568096205336u, 6064u },
800 { 15074767079673358271u, 111870718431542u, 0u },
801 { 13252722804829281908u, 111870u, 0u },
802 { 1u, 0u, 208910811136u },
803 { 7740175894281560509u, 16801499925276664441u, 228568794576u },
804 { 15670495392425593226u, 10492407990787637083u, 183416000228u },
805 { 15152257626756992778u, 7673849751013230268u, 67327793591u },
806 { 4090073428152440422u, 6046724489853072366u, 153201875267u },
807 { 14450327772834205584u, 3723941391207507902u, 67913121689u },
808 { 4466091895542494216u, 16844122108860347658u, 217575820867u },
809 { 10454115378553795377u, 10622020182694668026u, 116473861337u },
810 { 2267817233475657788u, 8741198820686854861u, 46371636340u },
811 { 5500455702636497521u, 6855480461211306806u, 73542410542u },
812 { 15178768299492252549u, 10005708458011566303u, 208484209737u },
813 { 7062359872332045590u, 8932093106442919060u, 148491293392u },
814 { 12297347290027942576u, 9062763476260756742u, 18740779924u },
815 { 8030124596941085588u, 13664977682032775520u, 187058465554u },
816 { 6526656990996654843u, 1078499125430623452u, 122355324859u },
817 { 6254287345256979850u, 6554586738078431160u, 104660133498u },
818 { 6642007136244870032u, 12177313698643242882u, 226900704872u },
819 { 2027592955437164718u, 16615072271904633952u, 243887712482u },
820 { 942718349157325567u, 16375404983106569284u, 9734669043u },
821 { 14617066671884002278u, 13552251831473522728u, 156451597321u },
822 { 6831631114396133348u, 8330500218412111873u, 4381874332u },
823 { 14603040013386939258u, 7044338079053294003u, 142145762820u },
824 { 9906106765319401103u, 2688849443046530183u, 125046400654u },
825 { 1396179595609933063u, 855940991879596844u, 239398138749u },
826 { 11524884268464976417u, 7344363609485825661u, 23628981487u },
827 { 382929570730827274u, 11602660525134634991u, 397444631u },
828 { 6109721884461301381u, 7331559403129590068u, 0u },
829 { 2390514825000339691u, 7331559403u, 0u },
830 { 6116191454763441755u, 7u, 0u },
831 { 1u, 0u, 42918608896u },
832 { 11598868771099176310u, 16945343208344873834u, 156521392426u },
833 { 14449966445520085105u, 9617992661337889144u, 126990979484u },
834 { 11675595287405614726u, 18280344933262742087u, 234280807038u },
835 { 15860796398550489897u, 5179975582362777794u, 174097519594u },
836 { 16180408435245829662u, 1798918997870037129u, 194343023534u },
837 { 13756992797154950706u, 6327667344756325882u, 104996399554u },
838 { 8830551328786758466u, 18380327574124007700u, 78976619368u },
839 { 16699955256560951264u, 18015447557304295288u, 35559209294u },
840 { 10038983627153402074u, 10315590748073249877u, 219417304867u },
841 { 15085100736692127346u, 7697916092577993381u, 245169359579u },
842 { 10007783780289711125u, 3124132817942110722u, 197403769845u },
843 { 17596907048353602192u, 7448238998520507048u, 163753131461u },
844 { 13530650344896573509u, 13892823322374205296u, 247598595491u },
845 { 6337724853398437005u, 11042137840046332563u, 246569963255u },
846 { 12768885008904063297u, 10513966307445593803u, 254508948214u },
847 { 2759773619512884114u, 9388437460943526957u, 148594534654u },
848 { 8434364600126655292u, 10967228614677896227u, 65125279380u },
849 { 3843827521199949338u, 2310996671540235541u, 19270460225u },
850 { 4661660852957808994u, 4989110555003898586u, 155882077203u },
851 { 15298044134177324417u, 16271452421983657678u, 194516251547u },
852 { 7747773274913338217u, 9523160181437090472u, 80712196546u },
853 { 10348785912020632966u, 13137707423765072249u, 224913270096u },
854 { 4175372293197190170u, 16846859744221860704u, 236421057504u },
855 { 11326064156813083145u, 7767140033449795568u, 4930758124u },
856 { 8100407170505981763u, 17169456915721160016u, 190931378436u },
857 { 1706556116319916846u, 17180899661833327818u, 26046u },
858 { 15028897280749641942u, 480481077043500u, 0u },
859 { 1421201742071739121u, 480481u, 0u },
860 { 1u, 0u, 41952608256u },
861 { 8480737406125178272u, 17572520700934791415u, 121974090537u },
862 { 10947205650755620361u, 17968798858233825416u, 176831497593u },
863 { 868577942165647781u, 15338423313945305608u, 226970107312u },
864 { 16017710019091388479u, 17895321323836726300u, 247044130786u },
865 { 6610879150827623375u, 814069333008965772u, 208390330615u },
866 { 12110095866223762092u, 7200328959852723946u, 20041193424u },
867 { 7756802952949470775u, 759884557248133772u, 3726966548u },
868 { 2941800790804618759u, 13410165861863974850u, 40340355587u },
869 { 11703600274199927522u, 6278452420856351569u, 212491800360u },
870 { 806737539257940346u, 9072115382556676441u, 91149396692u },
871 { 14579028397110132023u, 2755882551854926562u, 93460573019u },
872 { 14247808875344366934u, 8496072611504649268u, 205223454557u },
873 { 9713379923695279513u, 4122009033579215814u, 61554147533u },
874 { 2246428675703313877u, 10222217724450527220u, 233111918909u },
875 { 3549783776592680620u, 2064539481554006324u, 74430190057u },
876 { 12645029747929213033u, 7935605886598063692u, 51423117898u },
877 { 16279009267476580506u, 7805147585347548428u, 18309486643u },
878 { 343358782242907186u, 5709020905457661272u, 60881313810u },
879 { 10077054739085890321u, 16257370307404906673u, 207811593532u },
880 { 10526715404712173586u, 14971258192939373645u, 41061441999u },
881 { 11438715865125144243u, 1133404845901376389u, 82512872489u },
882 { 5040916178827294801u, 9460827548162822046u, 204069058130u },
883 { 16643761637275849508u, 1273897659779791345u, 202424641996u },
884 { 4852542977279030386u, 7833262224435092782u, 70164442058u },
885 { 7883373066544387129u, 3033420566713364586u, 110817242694u },
886 { 16699064314768500978u, 15075466825360349102u, 1707011694u },
887 { 6805863634444817214u, 13042063791413317777u, 1u },
888 { 2266540253968903500u, 31488807865u, 0u },
889 { 9016913589137908810u, 31u, 0u },
890 { 1u, 0u, 222134665216u },
891 { 11654451024602552034u, 2484134775182816689u, 93997495262u },
892 { 5299013208454526793u, 18400539815335991276u, 221026318685u },
893 { 14918550373926182540u, 485494064952118285u, 88952853725u },
894 { 6225552657491071054u, 17577048805241314890u, 76155254872u },
895 { 10344713496596235785u, 2863946907557583806u, 236707187532u },
896 { 12972405634433280209u, 13045307417786230799u, 139652260844u },
897 { 12911885282402784945u, 12032088871615097765u, 26479692427u },
898 { 6934311832970995868u, 8848763446997690579u, 33543797274u },
899 { 9975729197003430461u, 10031289150307672683u, 230628415265u },
900 { 1982857556803548935u, 11592215575498656562u, 62861639142u },
901 { 2095735223386298223u, 15894436747956898387u, 232113382974u },
902 { 7110931538347639365u, 2091546719588500922u, 52317877736u },
903 { 15822183724630969535u, 5863809244813756108u, 220612737332u },
904 { 16931982690156327501u, 11303008753675411244u, 166717656540u },
905 { 6740069226761666110u, 13238426537506910531u, 32935582886u },
906 { 3138792961008474902u, 17258458071023005564u, 81454591520u },
907 { 12154594426971851390u, 8385733444777075178u, 58516663377u },
908 { 15780127219221910902u, 9530757096163247299u, 157781872442u },
909 { 16421541930960194381u, 14423000845391072216u, 196593770909u },
910 { 7485894627196740576u, 10953140011159884310u, 186662899652u },
911 { 8897269432694476707u, 12228340237948264126u, 75611443130u },
912 { 17189823634941678805u, 11279134946966259188u, 173793641291u },
913 { 9585582064286255216u, 14640097792684582650u, 181337854381u },
914 { 12835472279575022097u, 6232313315128656727u, 24874740917u },
915 { 6776016669542754608u, 16136121832933322087u, 54817204760u },
916 { 18340015775620871027u, 15074767079673358270u, 254718431542u },
917 { 5254188752292365830u, 13252722804829281907u, 111870u },
918 { 6798802596750151183u, 2063650512248692u, 0u },
919 { 9449320530215272000u, 2063650u, 0u },
920 { 1u, 0u, 121419595776u },
921 { 17110720482574968811u, 7740175894281560508u, 91849499257u },
922 { 16172441693558688213u, 15670495392425593225u, 188821405531u },
923 { 6234654946353717320u, 15152257626756992777u, 238221723324u },
924 { 11180283100679445438u, 4090073428152440421u, 190783353838u },
925 { 14852260031176961272u, 14450327772834205583u, 10242107326u },
926 { 4481533167346438750u, 4466091895542494215u, 250566718730u },
927 { 4269718344362365664u, 10454115378553795376u, 205122938618u },
928 { 11520029752381101466u, 2267817233475657787u, 54298180301u },
929 { 16778682550309368417u, 5500455702636497520u, 223822842678u },
930 { 9687587467301363608u, 15178768299492252548u, 148382851295u },
931 { 10093971076828497318u, 7062359872332045589u, 6666640532u },
932 { 1913763026490934696u, 12297347290027942575u, 96435313926u },
933 { 12701450127613557000u, 8030124596941085587u, 220353810784u },
934 { 8974572160711134644u, 6526656990996654842u, 184339045596u },
935 { 9890000077336694124u, 6254287345256979849u, 130360063928u },
936 { 4292326716201059148u, 6642007136244870031u, 96109916034u },
937 { 14644519175104337420u, 2027592955437164717u, 68051104864u },
938 { 5051178622270136798u, 942718349157325566u, 40792392772u },
939 { 675983118348065839u, 14617066671884002277u, 1370343464u },
940 { 4431647660065117244u, 6831631114396133347u, 179791632385u },
941 { 8316115180008411962u, 14603040013386939257u, 135537011123u },
942 { 9621158095544965602u, 9906106765319401102u, 44075687047u },
943 { 15283478958951102072u, 1396179595609933062u, 125624765228u },
944 { 13981553073094447813u, 11524884268464976416u, 239020758653u },
945 { 4558368743929911607u, 382929570730827273u, 52331208687u },
946 { 15217004469858477791u, 6109721884461301380u, 235129590068u },
947 { 11589190369996515737u, 2390514825000339690u, 7331559403u },
948 { 3670624237398152929u, 6116191454763441754u, 7u },
949 { 13471713758418039777u, 135243399970u, 0u },
950 { 4489936967610296411u, 135u, 0u },
951 { 1u, 0u, 106628775936u },
952 { 9052049303222747950u, 11598868771099176309u, 120783334250u },
953 { 1011330006193020538u, 14449966445520085104u, 71632935288u },
954 { 17412075644359478612u, 11675595287405614725u, 194859815495u },
955 { 6358678384745980468u, 15860796398550489896u, 137877141698u },
956 { 15262353928842850919u, 16180408435245829661u, 250745768073u },
957 { 11145257686438581736u, 13756992797154950705u, 20478705146u },
958 { 1600562031807691890u, 8830551328786758465u, 120905306388u },
959 { 6775147337046626724u, 16699955256560951263u, 85544214392u },
960 { 15772127322106297822u, 10038983627153402073u, 165817764949u },
961 { 4141472200527441474u, 15085100736692127345u, 2542523045u },
962 { 18246007807879281267u, 10007783780289711124u, 168953930242u },
963 { 960746958654787123u, 17596907048353602191u, 112733498024u },
964 { 11355981212264408477u, 13530650344896573508u, 147343568752u },
965 { 1573078209576251481u, 6337724853398437004u, 203692202643u },
966 { 6245294478780491367u, 12768885008904063296u, 45149607627u },
967 { 7523292955659721510u, 2759773619512884113u, 35457227821u },
968 { 14454736751015226505u, 8434364600126655291u, 21208374307u },
969 { 7219786377781411316u, 3843827521199949337u, 218252709141u },
970 { 10597123082209392431u, 4661660852957808993u, 206829308634u },
971 { 6922353544343010714u, 15298044134177324416u, 168420007630u },
972 { 14317523356293377430u, 7747773274913338216u, 121561008808u },
973 { 4057766168681892717u, 10348785912020632965u, 96226347385u },
974 { 15214083611901244045u, 4175372293197190169u, 240613987168u },
975 { 8390569016883950721u, 11326064156813083144u, 80439123952u },
976 { 10680472538208175055u, 8100407170505981762u, 202092512592u },
977 { 12173567833130544927u, 1706556116319916845u, 44814718154u },
978 { 1386341248286610026u, 15028897280749641941u, 225077043500u },
979 { 12487300952797237352u, 1421201742071739120u, 480481u },
980 { 2614759871804869720u, 8863311460481781u, 0u },
981 { 8494389567327729477u, 8863311u, 0u },
982 { 1u, 0u, 247459741696u },
983 { 6260469580539185878u, 8480737406125178271u, 136593449207u },
984 { 17818573101084525841u, 10947205650755620360u, 8047085704u },
985 { 2201029069927307150u, 868577942165647780u, 28868321800u },
986 { 10397997613804897039u, 16017710019091388478u, 140358376476u },
987 { 14269915965770103741u, 6610879150827623374u, 234656489612u },
988 { 16776139909196366727u, 12110095866223762091u, 140420497130u },
989 { 6246513436385199720u, 7756802952949470774u, 194159475340u },
990 { 2926026498821554288u, 2941800790804618758u, 81634453442u },
991 { 15725499391028340982u, 11703600274199927521u, 89043733329u },
992 { 8576577277771450827u, 806737539257940345u, 226790330713u },
993 { 15523351176022259335u, 14579028397110132022u, 52772375266u },
994 { 4775158829429176134u, 14247808875344366933u, 198526563380u },
995 { 10141817222123532462u, 9713379923695279512u, 244121779142u },
996 { 12847658900242624586u, 2246428675703313876u, 52192434164u },
997 { 13708197964460514655u, 3549783776592680619u, 76685488436u },
998 { 1951540006613246932u, 12645029747929213032u, 12882486860u },
999 { 9979297327280092199u, 16279009267476580505u, 88018613516u },
1000 { 15381307706282553684u, 343358782242907185u, 177546278232u },
1001 { 10037428657543061177u, 10077054739085890320u, 77570654385u },
1002 { 2584877324547208668u, 10526715404712173585u, 133620094029u },
1003 { 1126624732730703576u, 11438715865125144242u, 158273268613u },
1004 { 1501064139624981020u, 5040916178827294800u, 241902260126u },
1005 { 5219661484955306109u, 16643761637275849507u, 46263056881u },
1006 { 5336997298570282212u, 4852542977279030385u, 106427358510u },
1007 { 12191131175733833362u, 7883373066544387128u, 174905258090u },
1008 { 3707068178994436536u, 16699064314768500977u, 145368946606u },
1009 { 5045484691732942022u, 6805863634444817213u, 185122869393u },
1010 { 14847900542908711232u, 2266540253968903499u, 31488807865u },
1011 { 9097257915916965135u, 9016913589137908809u, 31u },
1012 { 2472027983230314217u, 580865979874u, 0u },
1013 { 15974509111133272205u, 580u, 0u },
1014 { 1u, 0u, 177631789056u },
1015 { 12099486841948187399u, 11654451024602552033u, 236287260081u },
1016 { 5319910566029976328u, 5299013208454526792u, 13808736236u },
1017 { 11549214421017285864u, 14918550373926182539u, 74337487885u },
1018 { 1998791413186046700u, 6225552657491071053u, 190560788042u },
1019 { 17075171930090011210u, 10344713496596235784u, 15703235518u },
1020 { 15158296003813501474u, 12972405634433280208u, 165699954703u },
1021 { 1360083178079384115u, 12911885282402784944u, 211375909797u },
1022 { 6167980558592741158u, 6934311832970995867u, 107540785363u },
1023 { 3630180428124865653u, 9975729197003430460u, 50107490923u },
1024 { 2276550099763657677u, 1982857556803548934u, 83113610034u },
1025 { 407006713016100655u, 2095735223386298222u, 186385484371u },
1026 { 14242579061653496002u, 7110931538347639364u, 204857722298u },
1027 { 17944493332678643704u, 15822183724630969534u, 44917884620u },
1028 { 987185901870869452u, 16931982690156327500u, 67365379884u },
1029 { 5578665155415167745u, 6740069226761666109u, 124170154307u },
1030 { 4849210377429577536u, 3138792961008474901u, 234658901884u },
1031 { 10811995403388891862u, 12154594426971851389u, 195855442410u },
1032 { 7051931074990177294u, 15780127219221910901u, 216890213571u },
1033 { 2030832259446664275u, 16421541930960194380u, 22405811160u },
1034 { 6069512651054767896u, 7485894627196740575u, 190482321942u },
1035 { 10608701253763958799u, 8897269432694476706u, 244931862206u },
1036 { 15700053443426906717u, 17189823634941678804u, 250519635444u },
1037 { 17759719234725541222u, 9585582064286255215u, 87695812346u },
1038 { 15187321568916405210u, 12835472279575022096u, 103367328599u },
1039 { 11040156458113129594u, 6776016669542754607u, 190994214247u },
1040 { 2800727824598008497u, 18340015775620871026u, 115284830142u },
1041 { 2997236166375604479u, 5254188752292365829u, 116368563827u },
1042 { 6260091886451512841u, 6798802596750151182u, 34512248692u },
1043 { 17573059315228347474u, 9449320530215271999u, 2063650u },
1044 { 7519453664590169251u, 38067632857031246u, 0u },
1045 { 15809436065653866529u, 38067632u, 0u },
1046 { 1u, 0u, 188927574016u },
1047 { 228921437623588922u, 17110720482574968810u, 137876709820u },
1048 { 2195862230003073884u, 16172441693558688212u, 9337981321u },
1049 { 960207412233973688u, 6234654946353717319u, 101606084361u },
1050 { 2464387149230492479u, 11180283100679445437u, 143805142629u },
1051 { 3631866936444955213u, 14852260031176961271u, 7242944399u },
1052 { 1578304441149380227u, 4481533167346438749u, 48231461895u },
1053 { 18190538519673445181u, 4269718344362365663u, 59624502064u },
1054 { 1271000736479934749u, 11520029752381101465u, 112909574203u },
1055 { 18292963032817745634u, 16778682550309368416u, 132525165168u },
1056 { 17168014021925537455u, 9687587467301363607u, 21547195268u },
1057 { 18046757712870378949u, 10093971076828497317u, 175103745301u },
1058 { 14857998893911743220u, 1913763026490934695u, 147688546991u },
1059 { 11933607369968684575u, 12701450127613556999u, 250486512531u },
1060 { 3483798509902859162u, 8974572160711134643u, 137536137978u },
1061 { 7378828438829845831u, 9890000077336694123u, 143232687497u },
1062 { 15791137430347699565u, 4292326716201059147u, 173793880975u },
1063 { 17044141236829932641u, 14644519175104337419u, 254273824941u },
1064 { 9075651910862456484u, 5051178622270136797u, 229036645118u },
1065 { 17811207355884564095u, 675983118348065838u, 227240240101u },
1066 { 4438638126207305937u, 4431647660065117243u, 121450817507u },
1067 { 12507972635512950185u, 8316115180008411961u, 142521564025u },
1068 { 14658269128098109408u, 9621158095544965601u, 6828519054u },
1069 { 3642436268910286111u, 15283478958951102071u, 32757941510u },
1070 { 3783099432964819561u, 13981553073094447812u, 9247109664u },
1071 { 9497579866027539638u, 4558368743929911606u, 132824915465u },
1072 { 3395179445046271361u, 15217004469858477790u, 234628251268u },
1073 { 5938502732309497276u, 11589190369996515736u, 90198984938u },
1074 { 5793671185917606255u, 3670624237398152928u, 34730303066u },
1075 { 889272970253526588u, 13471713758418039776u, 135243399970u },
1076 { 8594177504370135501u, 4489936967610296410u, 135u },
1077 { 7374354721120724712u, 2494800386918u, 0u },
1078 { 14764532643665507567u, 2494u, 0u },
1079 { 1u, 0u, 117490712576u },
1080 { 5392404173658087695u, 9052049303222747949u, 112054824309u },
1081 { 4976586473237854316u, 1011330006193020537u, 133943910512u },
1082 { 6308932742419013569u, 17412075644359478611u, 40344704645u },
1083 { 4831846642430703059u, 6358678384745980467u, 29827373864u },
1084 { 18139507855949846901u, 15262353928842850918u, 49604185629u },
1085 { 4865833876326628410u, 11145257686438581735u, 65086766641u },
1086 { 14296661839130179261u, 1600562031807691889u, 223367281473u },
1087 { 9254773150378118248u, 6775147337046626723u, 217855008735u },
1088 { 12174712433727875143u, 15772127322106297821u, 113224509657u },
1089 { 705653145340915199u, 4141472200527441473u, 20989118065u },
1090 { 17763928858962481812u, 18246007807879281266u, 143052082196u },
1091 { 3982836567612046296u, 960746958654787122u, 68615608975u },
1092 { 12730849277561967739u, 11355981212264408476u, 140085276740u },
1093 { 17314488764367235908u, 1573078209576251480u, 64338558092u },
1094 { 15951418930590301119u, 6245294478780491366u, 145407838528u },
1095 { 7193356087283467261u, 7523292955659721509u, 59783592849u },
1096 { 17592945625696089446u, 14454736751015226504u, 25391385403u },
1097 { 3554461664875361428u, 7219786377781411315u, 97574471193u },
1098 { 2213779057785318208u, 10597123082209392430u, 128375261537u },
1099 { 3880940796082421148u, 6922353544343010713u, 104776154496u },
1100 { 4528237545358141043u, 14317523356293377429u, 133219971944u },
1101 { 11681196539088147363u, 4057766168681892716u, 25824757125u },
1102 { 9835005502912643017u, 15214083611901244044u, 8454853657u },
1103 { 4964088126040986696u, 8390569016883950720u, 66578989576u },
1104 { 3355564873147047622u, 10680472538208175054u, 45659930434u },
1105 { 1853093467828272927u, 12173567833130544926u, 213075153709u },
1106 { 14755341584803008677u, 1386341248286610025u, 240676937941u },
1107 { 4701571132542556621u, 12487300952797237351u, 245141746416u },
1108 { 6128849686644853851u, 2614759871804869719u, 79460481781u },
1109 { 12026867901170202094u, 8494389567327729476u, 8863311u },
1110 { 17909760324981426303u, 163499238157084246u, 0u },
1111 { 2897692901883393664u, 163499238u, 0u },
1112 { 1u, 0u, 159339380736u },
1113 { 12323704802554838154u, 6260469580539185877u, 8965946783u },
1114 { 7135886931147821732u, 17818573101084525840u, 164119318024u },
1115 { 15341283120292884947u, 2201029069927307149u, 62563676580u },
1116 { 3092789040392634166u, 10397997613804897038u, 206773573694u },
1117 { 8811761390822097865u, 14269915965770103740u, 171909436366u },
1118 { 16870860798610218169u, 16776139909196366726u, 54338624171u },
1119 { 17452041453591904833u, 6246513436385199719u, 6158620214u },
1120 { 10314783684009874908u, 2926026498821554287u, 225852481030u },
1121 { 4932636630789274903u, 15725499391028340981u, 121464937185u },
1122 { 18143884346082124480u, 8576577277771450826u, 54841522553u },
1123 { 2823209155405527322u, 15523351176022259334u, 85258861878u },
1124 { 16195396106620226251u, 4775158829429176133u, 152549789013u },
1125 { 1150544491807648944u, 10141817222123532461u, 212696472984u },
1126 { 7767455475523884824u, 12847658900242624585u, 171743122900u },
1127 { 15204378045683991808u, 13708197964460514654u, 104105793195u },
1128 { 17239732561718805622u, 1951540006613246931u, 153540978792u },
1129 { 12886430624522800062u, 9979297327280092198u, 49833822361u },
1130 { 18162250541178258136u, 15381307706282553683u, 16544130097u },
1131 { 17028935366700158084u, 10037428657543061176u, 17140126480u },
1132 { 16075467823964198637u, 2584877324547208667u, 178061074449u },
1133 { 9803858825574498304u, 1126624732730703575u, 80081372850u },
1134 { 17464070808143041817u, 1501064139624981019u, 35282958416u },
1135 { 17682703471239266776u, 5219661484955306108u, 113289319203u },
1136 { 18147688354161351336u, 5336997298570282211u, 56660882545u },
1137 { 6663423873348080051u, 12191131175733833361u, 241200960568u },
1138 { 9417270363716235133u, 3707068178994436535u, 61273516273u },
1139 { 9295013721571344179u, 5045484691732942021u, 75804906301u },
1140 { 6199479138350037783u, 14847900542908711231u, 73493163339u },
1141 { 887603005365085688u, 9097257915916965134u, 226134008905u },
1142 { 333989628642975696u, 2472027983230314216u, 68865979874u },
1143 { 4620735991403939439u, 15974509111133272204u, 580u },
1144 { 12418523063962801201u, 10715086071862u, 0u },
1145 { 1587745622680169419u, 10715u, 0u },
1146 { 1u, 0u, 225655914496u },
1147 { 10968905082284365638u, 12099486841948187398u, 72288392929u },
1148 { 14076907092801977812u, 5319910566029976327u, 139626084168u },
1149 { 3438322122816124202u, 11549214421017285863u, 77108354699u },
1150 { 14645413324829073676u, 1998791413186046699u, 8925646925u },
1151 { 12271281439492289999u, 17075171930090011209u, 208821732872u },
1152 { 6233751789862708246u, 15158296003813501473u, 176073730256u },
1153 { 1962644459455827991u, 1360083178079384114u, 155334366896u },
1154 { 8726934184642952500u, 6167980558592741157u, 60196792475u },
1155 { 4531087719737475147u, 3630180428124865652u, 6123412028u },
1156 { 481513520412720775u, 2276550099763657676u, 110022063878u },
1157 { 992149349835802669u, 407006713016100654u, 68772091758u },
1158 { 11165474436676191361u, 14242579061653496001u, 190972772932u },
1159 { 10240785855143707184u, 17944493332678643703u, 76053515454u },
1160 { 10059329918238932466u, 987185901870869451u, 61302420044u },
1161 { 14791716450947031886u, 5578665155415167744u, 21262876221u },
1162 { 15378882314737417403u, 4849210377429577535u, 125586119445u },
1163 { 14726970229242271128u, 10811995403388891861u, 117382285949u },
1164 { 5090110549507128156u, 7051931074990177293u, 76110091637u },
1165 { 17185220781106503841u, 2030832259446664274u, 223329028940u },
1166 { 9858517691519529306u, 6069512651054767895u, 162575098847u },
1167 { 5595905546638020703u, 10608701253763958798u, 212851101602u },
1168 { 15555173226968030256u, 15700053443426906716u, 111962756308u },
1169 { 10745236628845355771u, 17759719234725541221u, 16823306351u },
1170 { 9973314042399760760u, 15187321568916405209u, 47598488080u },
1171 { 4374506813558796576u, 11040156458113129593u, 114151827759u },
1172 { 15960826480426749933u, 2800727824598008496u, 5162480498u },
1173 { 9636454862798615738u, 2997236166375604478u, 14339360261u },
1174 { 17973331528911319269u, 6260091886451512840u, 63952637454u },
1175 { 7366495200039369602u, 17573059315228347473u, 78407630399u },
1176 { 10505831326526933399u, 7519453664590169250u, 176857031246u },
1177 { 2803218632575724145u, 15809436065653866528u, 38067632u },
1178 { 8425731874431741636u, 702223880805592151u, 0u },
1179 { 14860552245711912111u, 702223880u, 0u },
1180 { 1u, 0u, 234012409856u },
1181 { 6993664200669526994u, 228921437623588921u, 212119037930u },
1182 { 4065363582031999356u, 2195862230003073883u, 71052052948u },
1183 { 6899780515342669867u, 960207412233973687u, 189133594695u },
1184 { 17713500890201844939u, 2464387149230492478u, 247196883901u },
1185 { 6445781125105107086u, 3631866936444955212u, 93085560055u },
1186 { 13563044070717478571u, 1578304441149380226u, 223986111069u },
1187 { 13167612994149348885u, 18190538519673445180u, 153068901087u },
1188 { 5505463469596727288u, 1271000736479934748u, 96991663513u },
1189 { 12125446212518819372u, 18292963032817745633u, 151930679904u },
1190 { 12537707724735421794u, 17168014021925537454u, 165978316695u },
1191 { 15173675086703777069u, 18046757712870378948u, 167805453733u },
1192 { 13535510174093048476u, 14857998893911743219u, 7646922151u },
1193 { 10698912997087096629u, 11933607369968684574u, 179188857095u },
1194 { 16952559548431933861u, 3483798509902859161u, 107400007091u },
1195 { 13528255827744249993u, 7378828438829845830u, 75856039275u },
1196 { 14122167436324771955u, 15791137430347699564u, 11923964747u },
1197 { 13071007137740038297u, 17044141236829932640u, 221491992075u },
1198 { 13011887609328904025u, 9075651910862456483u, 46965547485u },
1199 { 3116434332871336590u, 17811207355884564094u, 59240619054u },
1200 { 9050993820536772770u, 4438638126207305936u, 57678058555u },
1201 { 11993719123438634238u, 12507972635512950184u, 225794626361u },
1202 { 1414857165879849301u, 14658269128098109407u, 119197456865u },
1203 { 13819438220812375094u, 3642436268910286110u, 196205082231u },
1204 { 6073063033888264440u, 3783099432964819560u, 54514864836u },
1205 { 6828883869150720294u, 9497579866027539637u, 222184053046u },
1206 { 4548265621068768345u, 3395179445046271360u, 152321926878u },
1207 { 10422524923581371874u, 5938502732309497275u, 224314075544u },
1208 { 1858996082510682634u, 5793671185917606254u, 224048207584u },
1209 { 890276727450878316u, 889272970253526587u, 90465891296u },
1210 { 3886008133802710905u, 8594177504370135500u, 102399764570u },
1211 { 612074409233016757u, 7374354721120724711u, 190800386918u },
1212 { 3927020336901729264u, 14764532643665507566u, 2494u },
1213 { 5298603480094474942u, 46020944252475u, 0u },
1214 { 17418383752590430025u, 46020u, 0u },
1215 { 1u, 0u, 45292322816u },
1216 { 8973799690601597929u, 5392404173658087694u, 121269781293u },
1217 { 1343055462055792431u, 4976586473237854315u, 83342007929u },
1218 { 17425118728683169659u, 6308932742419013568u, 51261934931u },
1219 { 18389781726026675967u, 4831846642430703058u, 102983344691u },
1220 { 272526939565961561u, 18139507855949846900u, 231263777382u },
1221 { 11293026845930963228u, 4865833876326628409u, 113775023591u },
1222 { 13997416438903902597u, 14296661839130179260u, 163501702257u },
1223 { 6186605805999441184u, 9254773150378118247u, 221659992483u },
1224 { 4401776373281836138u, 12174712433727875142u, 65038253533u },
1225 { 16338917089754547008u, 705653145340915198u, 114962984513u },
1226 { 13337700757935003056u, 17763928858962481811u, 50215910002u },
1227 { 14612496890816348693u, 3982836567612046295u, 156690140722u },
1228 { 3219935399907691719u, 12730849277561967738u, 88938620316u },
1229 { 10887238730052330387u, 17314488764367235907u, 102864728152u },
1230 { 360256418697768294u, 15951418930590301118u, 37389952614u },
1231 { 321440824631118565u, 7193356087283467260u, 136953715493u },
1232 { 10069228080701402580u, 17592945625696089445u, 243192687752u },
1233 { 9428069607611622975u, 3554461664875361427u, 46120009203u },
1234 { 14736799017468812344u, 2213779057785318207u, 153210386222u },
1235 { 10875332567307979280u, 3880940796082421147u, 149245476249u },
1236 { 4611492910339012807u, 4528237545358141042u, 108633238933u },
1237 { 10743508637597314786u, 11681196539088147362u, 140533156716u },
1238 { 9356196315668016028u, 9835005502912643016u, 128269103756u },
1239 { 15755598617722189347u, 4964088126040986695u, 206181905536u },
1240 { 1275276394173375542u, 3355564873147047621u, 30100456398u },
1241 { 12644999363867216251u, 1853093467828272926u, 105799888670u },
1242 { 4553830511509832021u, 14755341584803008676u, 103254872681u },
1243 { 8869400642218174412u, 4701571132542556620u, 87332245607u },
1244 { 16570849151159054040u, 6128849686644853850u, 68651977815u },
1245 { 16127119334101797673u, 12026867901170202093u, 86970890052u },
1246 { 9686867250420930550u, 17909760324981426302u, 230157084246u },
1247 { 10678226869774428035u, 2897692901883393663u, 163499238u },
1248 { 7767227962910162068u, 3016028602530220424u, 0u },
1249 { 9780840471948993674u, 3016028602u, 0u },
1250 { 1u, 0u, 213668069376u },
1251 { 6288709332106746357u, 12323704802554838153u, 16386837205u },
1252 { 9066785620141948673u, 7135886931147821731u, 141831652624u },
1253 { 8442375916704414909u, 15341283120292884946u, 14167660429u },
1254 { 11604629218100425803u, 3092789040392634165u, 188477686542u },
1255 { 3877248044010875762u, 8811761390822097864u, 134914571196u },
1256 { 16435137704395217283u, 16870860798610218168u, 103946077062u },
1257 { 14994442577577813271u, 17452041453591904832u, 111559165543u },
1258 { 4410105917142436089u, 10314783684009874907u, 245267398767u },
1259 { 4632574728444936970u, 4932636630789274902u, 202983581941u },
1260 { 9117147535650050359u, 18143884346082124479u, 134153046474u },
1261 { 588939301256904809u, 2823209155405527321u, 69877954182u },
1262 { 324393982565305683u, 16195396106620226250u, 173062371141u },
1263 { 9380909186923521175u, 1150544491807648943u, 73421074605u },
1264 { 4463385697777230217u, 7767455475523884823u, 94824230985u },
1265 { 16378985502426333808u, 15204378045683991807u, 211934567774u },
1266 { 18210894922387834354u, 17239732561718805621u, 38698574803u },
1267 { 1555748035329493205u, 12886430624522800061u, 83984577574u },
1268 { 4277055533891898507u, 18162250541178258135u, 184923140435u },
1269 { 11574429772510874408u, 17028935366700158083u, 219871452856u },
1270 { 17391099253493808815u, 16075467823964198636u, 215531468251u },
1271 { 5791212393959129882u, 9803858825574498303u, 27946729175u },
1272 { 11254268231455680880u, 17464070808143041816u, 124958581275u },
1273 { 16355477587312235322u, 17682703471239266775u, 227983788156u },
1274 { 2411485149249320633u, 18147688354161351335u, 145361224931u },
1275 { 12763114642070638360u, 6663423873348080050u, 183510511249u },
1276 { 1147543073987366419u, 9417270363716235132u, 197503883703u },
1277 { 8410777835225272692u, 9295013721571344178u, 63336074437u },
1278 { 8134725822306818018u, 6199479138350037782u, 14048117055u },
1279 { 8899607004752328377u, 887603005365085687u, 232018105614u },
1280 { 690976506652396830u, 333989628642975695u, 140250490600u },
1281 { 12281570945595192074u, 4620735991403939438u, 54673209484u },
1282 { 12592957291365552899u, 12418523063962801200u, 219086071862u },
1283 { 13595807339013970272u, 1587745622680169418u, 10715u },
1284 { 9698096389749839992u, 197658450495420u, 0u },
1285 { 8310173728816391804u, 197658u, 0u },
1286};
1287
1288inline constexpr int __TABLE_SIZE_2 = 69;
1289inline constexpr int __ADDITIONAL_BITS_2 = 120;
1290
1291inline constexpr uint16_t __POW10_OFFSET_2[__TABLE_SIZE_2] = {
1292 0, 2, 6, 12, 20, 29, 40, 52, 66, 80,
1293 95, 112, 130, 150, 170, 192, 215, 240, 265, 292,
1294 320, 350, 381, 413, 446, 480, 516, 552, 590, 629,
1295 670, 712, 755, 799, 845, 892, 940, 989, 1040, 1092,
1296 1145, 1199, 1254, 1311, 1369, 1428, 1488, 1550, 1613, 1678,
1297 1743, 1810, 1878, 1947, 2017, 2088, 2161, 2235, 2311, 2387,
1298 2465, 2544, 2625, 2706, 2789, 2873, 2959, 3046, 3133
1299};
1300
1301inline constexpr uint8_t __MIN_BLOCK_2[__TABLE_SIZE_2] = {
1302 0, 0, 0, 0, 0, 0, 1, 1, 2, 3,
1303 3, 4, 4, 5, 5, 6, 6, 7, 7, 8,
1304 8, 9, 9, 10, 11, 11, 12, 12, 13, 13,
1305 14, 14, 15, 15, 16, 16, 17, 17, 18, 19,
1306 19, 20, 20, 21, 21, 22, 22, 23, 23, 24,
1307 24, 25, 26, 26, 27, 27, 28, 28, 29, 29,
1308 30, 30, 31, 31, 32, 32, 33, 34, 0
1309};
1310
1311inline constexpr uint64_t __POW10_SPLIT_2[3133][3] = {
1312 { 0u, 0u, 3906250u },
1313 { 0u, 0u, 202000000000u },
1314 { 0u, 11153727427136454656u, 59u },
1315 { 0u, 7205759403792793600u, 59604644775u },
1316 { 0u, 0u, 167390625000u },
1317 { 0u, 0u, 232000000000u },
1318 { 0u, 16777216000000000u, 0u },
1319 { 0u, 12945425605062557696u, 909494u },
1320 { 0u, 4388757836872548352u, 182701772928u },
1321 { 0u, 1152921504606846976u, 128237915039u },
1322 { 0u, 0u, 159062500000u },
1323 { 0u, 0u, 160000000000u },
1324 { 0u, 256000000000u, 0u },
1325 { 0u, 16192327041775828992u, 13u },
1326 { 0u, 15024075324038053888u, 13877787807u },
1327 { 0u, 5449091666327633920u, 159814456755u },
1328 { 0u, 2494994193563254784u, 179295395851u },
1329 { 0u, 4611686018427387904u, 11135253906u },
1330 { 0u, 0u, 146250000000u },
1331 { 0u, 0u, 128000000000u },
1332 { 0u, 3906250u, 0u },
1333 { 0u, 3906250000000000u, 0u },
1334 { 0u, 4368439412768899072u, 211758u },
1335 { 0u, 1563676642168012800u, 46236813575u },
1336 { 0u, 11532349341402398720u, 7084767080u },
1337 { 0u, 9048364970084925440u, 104625169910u },
1338 { 0u, 16609275425742389248u, 246490512847u },
1339 { 0u, 0u, 207900390625u },
1340 { 0u, 0u, 225000000000u },
1341 { 11153727427136454656u, 59u, 0u },
1342 { 7205759403792793600u, 59604644775u, 0u },
1343 { 0u, 4264412554261970152u, 3u },
1344 { 0u, 14485570586272534528u, 3231174267u },
1345 { 0u, 17827675094632103936u, 123785264354u },
1346 { 0u, 7347197909193981952u, 226966440203u },
1347 { 0u, 13677404030777688064u, 11398292396u },
1348 { 0u, 3810326759732150272u, 172741453558u },
1349 { 0u, 9943947977234055168u, 246206558227u },
1350 { 0u, 0u, 19539062500u },
1351 { 0u, 0u, 228000000000u },
1352 { 12945425605062557696u, 909494u, 0u },
1353 { 4388757836872548352u, 909494701772928u, 0u },
1354 { 1152921504606846976u, 14878706826214591391u, 49303u },
1355 { 0u, 4387341015746028192u, 151806576313u },
1356 { 0u, 651726680428265472u, 185237838233u },
1357 { 0u, 2570638187944738816u, 153035330174u },
1358 { 0u, 7419175577111756800u, 126139354575u },
1359 { 0u, 17299322326264840192u, 207402194313u },
1360 { 0u, 7990511638862102528u, 137937798142u },
1361 { 0u, 16717361816799281152u, 254433166503u },
1362 { 0u, 0u, 167906250000u },
1363 { 0u, 0u, 16000000000u },
1364 { 16192327041775828992u, 13u, 0u },
1365 { 15024075324038053888u, 13877787807u, 0u },
1366 { 5449091666327633920u, 13877787807814456755u, 0u },
1367 { 2494994193563254784u, 9707857417284919307u, 752316384u },
1368 { 4611686018427387904u, 1844515466944871826u, 224526264005u },
1369 { 0u, 15167599819856275072u, 197099991383u },
1370 { 0u, 14830185305589481472u, 87822237233u },
1371 { 0u, 6163721531743535104u, 49803945956u },
1372 { 0u, 14122847407012052992u, 228334136013u },
1373 { 0u, 335491783960035328u, 205765601092u },
1374 { 0u, 941252322120433664u, 68018187046u },
1375 { 0u, 11529215046068469760u, 38051025390u },
1376 { 0u, 0u, 238625000000u },
1377 { 0u, 0u, 64000000000u },
1378 { 4368439412768899072u, 211758u, 0u },
1379 { 1563676642168012800u, 211758236813575u, 0u },
1380 { 11532349341402398720u, 8061591463141767016u, 11479u },
1381 { 9048364970084925440u, 16628725344207857142u, 215437019748u },
1382 { 16609275425742389248u, 3555541870038531535u, 100901445007u },
1383 { 0u, 18316647450161853665u, 143192746310u },
1384 { 0u, 16709574568378075648u, 70992947447u },
1385 { 0u, 7696022835795591168u, 247905827852u },
1386 { 0u, 16664449640376041472u, 12417202233u },
1387 { 0u, 3109186955116544000u, 57903381625u },
1388 { 0u, 10515518101817131008u, 121168549362u },
1389 { 0u, 9961962375743537152u, 242570047378u },
1390 { 0u, 9223372036854775808u, 146540039062u },
1391 { 0u, 0u, 150500000000u },
1392 { 14485570586272534528u, 3231174267u, 0u },
1393 { 17827675094632103936u, 3231174267785264354u, 0u },
1394 { 7347197909193981952u, 748977172262750475u, 175162308u },
1395 { 13677404030777688064u, 15965033457315095468u, 196040602133u },
1396 { 3810326759732150272u, 16809402149066729206u, 21865466197u },
1397 { 9943947977234055168u, 7563769067065700371u, 85911239516u },
1398 { 0u, 13550322810840051428u, 92410032742u },
1399 { 0u, 8663209637545764864u, 102734564471u },
1400 { 0u, 8969247575312957440u, 119469633535u },
1401 { 0u, 6193172891660451840u, 255486223885u },
1402 { 0u, 3427954273864908800u, 13335732575u },
1403 { 0u, 10058367555266936832u, 95185829773u },
1404 { 0u, 13907115649320091648u, 141545265197u },
1405 { 0u, 0u, 45753906250u },
1406 { 0u, 0u, 74000000000u },
1407 { 14878706826214591391u, 49303u, 0u },
1408 { 4387341015746028192u, 49303806576313u, 0u },
1409 { 651726680428265472u, 14106411361315920281u, 2672u },
1410 { 2570638187944738816u, 3609034283485221502u, 112764710092u },
1411 { 7419175577111756800u, 9896072247338192335u, 204195646140u },
1412 { 17299322326264840192u, 8889095178479228297u, 188536467151u },
1413 { 7990511638862102528u, 3631796911038383102u, 207481878815u },
1414 { 16717361816799281152u, 898318840772166823u, 31196880105u },
1415 { 0u, 17293677953982795024u, 233048697961u },
1416 { 0u, 7353628266884669440u, 105937492160u },
1417 { 0u, 2404693032470315008u, 192398640987u },
1418 { 0u, 9191155893041889280u, 91130358670u },
1419 { 0u, 6353946855033798656u, 142498253559u },
1420 { 0u, 3767824038248841216u, 247344448149u },
1421 { 0u, 7205759403792793600u, 149204254150u },
1422 { 0u, 0u, 198390625000u },
1423 { 0u, 0u, 232000000000u },
1424 { 9707857417284919307u, 752316384u, 0u },
1425 { 1844515466944871826u, 752316384526264005u, 0u },
1426 { 15167599819856275072u, 17063068157692817751u, 40783152u },
1427 { 14830185305589481472u, 5385330256507239985u, 48924990778u },
1428 { 6163721531743535104u, 3373050282752075748u, 58291939338u },
1429 { 14122847407012052992u, 4116064001262906061u, 10182853422u },
1430 { 335491783960035328u, 11306582046748043076u, 46223132276u },
1431 { 941252322120433664u, 17035410946089626406u, 116612931040u },
1432 { 11529215046068469760u, 15618595715183448558u, 224923491477u },
1433 { 0u, 5141740092277295680u, 149846685770u },
1434 { 0u, 16973644291514990592u, 74278734288u },
1435 { 0u, 14625255268443750400u, 208920143100u },
1436 { 0u, 14021170507320131584u, 252792836676u },
1437 { 0u, 4451355232865091584u, 68760089176u },
1438 { 0u, 12891553933348044800u, 88241308450u },
1439 { 0u, 1152921504606846976u, 34698852539u },
1440 { 0u, 0u, 187062500000u },
1441 { 0u, 0u, 160000000000u },
1442 { 8061591463141767016u, 11479u, 0u },
1443 { 16628725344207857142u, 11479437019748u, 0u },
1444 { 3555541870038531535u, 5562205901560339855u, 622u },
1445 { 18316647450161853665u, 2106077949367544134u, 110301527786u },
1446 { 16709574568378075648u, 7496855998374373623u, 234114170714u },
1447 { 7696022835795591168u, 229183437194837004u, 90406405378u },
1448 { 16664449640376041472u, 465169186276472889u, 2012424059u },
1449 { 3109186955116544000u, 2152980561625316473u, 123025216872u },
1450 { 10515518101817131008u, 2059790725449340402u, 104116713310u },
1451 { 9961962375743537152u, 17891190926410198930u, 94111661478u },
1452 { 9223372036854775808u, 9930696175609809814u, 166969883403u },
1453 { 0u, 7276914261609005312u, 11538344118u },
1454 { 0u, 10539762974036983808u, 182394482312u },
1455 { 0u, 12851089458992250880u, 136571361695u },
1456 { 0u, 9449311677678878720u, 159696658955u },
1457 { 0u, 8699564697382289408u, 11512248212u },
1458 { 0u, 4224376450473525248u, 148471604347u },
1459 { 0u, 4611686018427387904u, 123229003906u },
1460 { 0u, 0u, 130250000000u },
1461 { 0u, 0u, 128000000000u },
1462 { 748977172262750475u, 175162308u, 0u },
1463 { 15965033457315095468u, 175162308040602133u, 0u },
1464 { 16809402149066729206u, 13756840147955779925u, 9495567u },
1465 { 7563769067065700371u, 13788447602092505948u, 15745759798u },
1466 { 13550322810840051428u, 4972540435632173670u, 54747473242u },
1467 { 8663209637545764864u, 2844874687533091959u, 90269561957u },
1468 { 8969247575312957440u, 15377573779532804095u, 101154220965u },
1469 { 6193172891660451840u, 17824715805091194381u, 165833619944u },
1470 { 3427954273864908800u, 18277569135638159711u, 232966279779u },
1471 { 10058367555266936832u, 4254645803379752845u, 99990829008u },
1472 { 13907115649320091648u, 2933643244178200621u, 208230644811u },
1473 { 0u, 17188148801879487562u, 75159033118u },
1474 { 0u, 11069762501163246592u, 30931771413u },
1475 { 0u, 11676570643941818368u, 21600093027u },
1476 { 0u, 17840016768744030208u, 99632988162u },
1477 { 0u, 16463817321652158464u, 2967109246u },
1478 { 0u, 6954191143357644800u, 126892505325u },
1479 { 0u, 5080060379673919488u, 237376987457u },
1480 { 0u, 0u, 65275390625u },
1481 { 0u, 0u, 161000000000u },
1482 { 14106411361315920281u, 2672u, 0u },
1483 { 3609034283485221502u, 2672764710092u, 0u },
1484 { 9896072247338192335u, 16433563478020213436u, 144u },
1485 { 8889095178479228297u, 4194750497955655375u, 144890865261u },
1486 { 3631796911038383102u, 2691539602252904735u, 109227397880u },
1487 { 898318840772166823u, 3775467271962795241u, 248145908654u },
1488 { 17293677953982795024u, 16980212613224918121u, 174204668490u },
1489 { 7353628266884669440u, 4172857038337333440u, 74920499170u },
1490 { 2404693032470315008u, 5936867627376461659u, 226226211033u },
1491 { 9191155893041889280u, 17856837443266866062u, 217321838238u },
1492 { 6353946855033798656u, 8956297047799810807u, 158968021097u },
1493 { 3767824038248841216u, 15356974049716912789u, 105485521835u },
1494 { 7205759403792793600u, 6923608913322982854u, 171832503231u },
1495 { 0u, 4855902993563955944u, 191375329591u },
1496 { 0u, 13835893222288330752u, 55263239028u },
1497 { 0u, 9114973913760137216u, 116750045274u },
1498 { 0u, 17937099003422310400u, 90494123725u },
1499 { 0u, 7007960010734960640u, 205972372085u },
1500 { 0u, 7683422439270776832u, 117379902273u },
1501 { 0u, 720575940379279360u, 65416519165u },
1502 { 0u, 0u, 253039062500u },
1503 { 0u, 0u, 228000000000u },
1504 { 17063068157692817751u, 40783152u, 0u },
1505 { 5385330256507239985u, 40783152924990778u, 0u },
1506 { 3373050282752075748u, 2768933352715741194u, 2210859u },
1507 { 4116064001262906061u, 15201941611824153390u, 43150104177u },
1508 { 11306582046748043076u, 1418128541727000180u, 113824098906u },
1509 { 17035410946089626406u, 5353350204565757408u, 90076876902u },
1510 { 15618595715183448558u, 1721001680354286741u, 102290205696u },
1511 { 5141740092277295680u, 637631411660453962u, 93295688u },
1512 { 16973644291514990592u, 1630012588870568400u, 72034566068u },
1513 { 14625255268443750400u, 9253063571656828156u, 180088363159u },
1514 { 14021170507320131584u, 6029146854993203780u, 151501609581u },
1515 { 4451355232865091584u, 16987401965352759896u, 109326840705u },
1516 { 12891553933348044800u, 14499131620542087970u, 129920888905u },
1517 { 1152921504606846976u, 1978417255298660539u, 73785999500u },
1518 { 0u, 5790079354402454176u, 140107250214u },
1519 { 0u, 13748918935842078720u, 38313880830u },
1520 { 0u, 18047438014740692992u, 254745330388u },
1521 { 0u, 3116889656839372800u, 212978353575u },
1522 { 0u, 15995952446606147584u, 167168966926u },
1523 { 0u, 12530140063251562496u, 14867142319u },
1524 { 0u, 16717361816799281152u, 175679260253u },
1525 { 0u, 0u, 93906250000u },
1526 { 0u, 0u, 16000000000u },
1527 { 5562205901560339855u, 622u, 0u },
1528 { 2106077949367544134u, 622301527786u, 0u },
1529 { 7496855998374373623u, 13558973353698967386u, 33u },
1530 { 229183437194837004u, 6228991722850501890u, 33735033418u },
1531 { 465169186276472889u, 16886831391703377787u, 74337674317u },
1532 { 2152980561625316473u, 1181713637872883048u, 77915436964u },
1533 { 2059790725449340402u, 12393932434925221726u, 164064060824u },
1534 { 17891190926410198930u, 10684799845419711910u, 152671876423u },
1535 { 9930696175609809814u, 4590318792215640843u, 71579224160u },
1536 { 7276914261609005312u, 6383712187366189238u, 96248841680u },
1537 { 10539762974036983808u, 1904270214927675016u, 208346061731u },
1538 { 12851089458992250880u, 3711506775113308575u, 163103230695u },
1539 { 9449311677678878720u, 8091219444738793995u, 231201201185u },
1540 { 8699564697382289408u, 39436684991068052u, 33438625885u },
1541 { 4224376450473525248u, 18025182908196512891u, 93002137866u },
1542 { 4611686018427387904u, 7853924592034603138u, 10977147123u },
1543 { 0u, 4815749283615688320u, 243425762105u },
1544 { 0u, 14242399906544287744u, 57261062291u },
1545 { 0u, 76242322576113664u, 147772082046u },
1546 { 0u, 10858088421377703936u, 126004133104u },
1547 { 0u, 14293835879041466368u, 240588618152u },
1548 { 0u, 12182236992037191680u, 168774870395u },
1549 { 0u, 11529215046068469760u, 123660400390u },
1550 { 0u, 0u, 6625000000u },
1551 { 0u, 0u, 64000000000u },
1552 { 13756840147955779925u, 9495567u, 0u },
1553 { 13788447602092505948u, 9495567745759798u, 0u },
1554 { 4972540435632173670u, 14000097438505379162u, 514755u },
1555 { 2844874687533091959u, 16451062686452429925u, 195758946802u },
1556 { 15377573779532804095u, 4009347599785716645u, 242891813895u },
1557 { 17824715805091194381u, 16544162347546196456u, 7217347168u },
1558 { 18277569135638159711u, 17674258299745817187u, 96896860837u },
1559 { 4254645803379752845u, 5215238411201214416u, 165958123462u },
1560 { 2933643244178200621u, 14253990228345322571u, 198282718640u },
1561 { 17188148801879487562u, 11214836553940194590u, 176772710358u },
1562 { 11069762501163246592u, 14620711348380590101u, 214607957507u },
1563 { 11676570643941818368u, 6638710787931587427u, 3792590350u },
1564 { 17840016768744030208u, 17320000343692853250u, 14359885232u },
1565 { 16463817321652158464u, 75147386268843646u, 176938919100u },
1566 { 6954191143357644800u, 17938801582125480173u, 188004073747u },
1567 { 5080060379673919488u, 6573358613626446145u, 19972464382u },
1568 { 0u, 8688505427903736481u, 254356342484u },
1569 { 0u, 539870168696556032u, 212471004823u },
1570 { 0u, 9002861336394465280u, 151029266420u },
1571 { 0u, 17989846818158018560u, 244488046090u },
1572 { 0u, 2700938287723315200u, 10975231550u },
1573 { 0u, 17800090499088908288u, 62146418157u },
1574 { 0u, 8809040871136690176u, 237964944839u },
1575 { 0u, 9223372036854775808u, 199477539062u },
1576 { 0u, 0u, 246500000000u },
1577 { 16433563478020213436u, 144u, 0u },
1578 { 4194750497955655375u, 144890865261u, 0u },
1579 { 2691539602252904735u, 15763656745260536568u, 7u },
1580 { 3775467271962795241u, 8787336846248645550u, 7854549544u },
1581 { 16980212613224918121u, 17584084447880694346u, 40476362484u },
1582 { 4172857038337333440u, 18041672551129683938u, 244953235127u },
1583 { 5936867627376461659u, 14025886302294509785u, 183978041028u },
1584 { 17856837443266866062u, 18430498103283160734u, 196760344819u },
1585 { 8956297047799810807u, 3292348826238025833u, 243999119304u },
1586 { 15356974049716912789u, 9211721212658275243u, 200178478587u },
1587 { 6923608913322982854u, 10233245872666307519u, 251499368407u },
1588 { 4855902993563955944u, 6200995035623311671u, 215554745370u },
1589 { 13835893222288330752u, 8480542380570450804u, 26336156614u },
1590 { 9114973913760137216u, 11870363864499900506u, 198459731123u },
1591 { 17937099003422310400u, 9301051379839581901u, 179643493714u },
1592 { 7007960010734960640u, 11456694803569638005u, 82504211005u },
1593 { 7683422439270776832u, 14327208890643983169u, 61621068669u },
1594 { 720575940379279360u, 4510081789599866365u, 125776679550u },
1595 { 0u, 13255356976020303332u, 126244492023u },
1596 { 0u, 9658806854127314944u, 247718574341u },
1597 { 0u, 13708435528809971712u, 5523604968u },
1598 { 0u, 1580190652103131136u, 232743135779u },
1599 { 0u, 16557336970347413504u, 35085662306u },
1600 { 0u, 12751520132434493440u, 98897575035u },
1601 { 0u, 9295429630892703744u, 123691261291u },
1602 { 0u, 0u, 107503906250u },
1603 { 0u, 0u, 202000000000u },
1604 { 2768933352715741194u, 2210859u, 0u },
1605 { 15201941611824153390u, 2210859150104177u, 0u },
1606 { 1418128541727000180u, 16872870088062921306u, 119850u },
1607 { 5353350204565757408u, 5112979788807802982u, 42914680120u },
1608 { 1721001680354286741u, 13742728082020150272u, 56277175189u },
1609 { 637631411660453962u, 2217110934613627976u, 149744994782u },
1610 { 1630012588870568400u, 11021433940188610484u, 222120189824u },
1611 { 9253063571656828156u, 1713669895470733463u, 128597473131u },
1612 { 6029146854993203780u, 3313382510572018285u, 107092898231u },
1613 { 16987401965352759896u, 14976595232784069505u, 183179618825u },
1614 { 14499131620542087970u, 7213172372862496841u, 9811882854u },
1615 { 1978417255298660539u, 15836474542502248588u, 102391026857u },
1616 { 5790079354402454176u, 3221099285878340134u, 169858497005u },
1617 { 13748918935842078720u, 3265814602578095358u, 237174616142u },
1618 { 18047438014740692992u, 6502528252282225364u, 78177040164u },
1619 { 3116889656839372800u, 16392476834556790183u, 36352502762u },
1620 { 15995952446606147584u, 15167629413417091342u, 234888637949u },
1621 { 12530140063251562496u, 1366763272626280111u, 253822238838u },
1622 { 16717361816799281152u, 8720523635169216093u, 118074092385u },
1623 { 0u, 9649171375767398672u, 97472740533u },
1624 { 0u, 7647980704001073152u, 181523082628u },
1625 { 0u, 13286434495608651776u, 132414597864u },
1626 { 0u, 4358271637167013888u, 232720259057u },
1627 { 0u, 15954987941890097152u, 241236262378u },
1628 { 0u, 7911135695429697536u, 234864921629u },
1629 { 0u, 7205759403792793600u, 29428863525u },
1630 { 0u, 0u, 37390625000u },
1631 { 0u, 0u, 232000000000u },
1632 { 13558973353698967386u, 33u, 0u },
1633 { 6228991722850501890u, 33735033418u, 0u },
1634 { 16886831391703377787u, 15288289344628122701u, 1u },
1635 { 1181713637872883048u, 952589339068938148u, 1828779826u },
1636 { 12393932434925221726u, 10058155040190817688u, 50051639971u },
1637 { 10684799845419711910u, 5322725640026584391u, 163545253677u },
1638 { 4590318792215640843u, 2269982385930389600u, 45288545535u },
1639 { 6383712187366189238u, 13216683679976310224u, 255123055991u },
1640 { 1904270214927675016u, 17417440642083494819u, 119716477857u },
1641 { 3711506775113308575u, 3029180749090900711u, 161944201349u },
1642 { 8091219444738793995u, 8315443826261908513u, 133164212217u },
1643 { 39436684991068052u, 1488962797247197277u, 249450781113u },
1644 { 18025182908196512891u, 18009099634999034122u, 185080716834u },
1645 { 7853924592034603138u, 8092455412807497971u, 34976275247u },
1646 { 4815749283615688320u, 17808458047236758329u, 47438692886u },
1647 { 14242399906544287744u, 3164591817527425171u, 22965398445u },
1648 { 76242322576113664u, 3314036340472350590u, 173171552866u },
1649 { 10858088421377703936u, 33234902404332784u, 98179654270u },
1650 { 14293835879041466368u, 12349284717857274280u, 126001801667u },
1651 { 12182236992037191680u, 18209607903013119355u, 195669456065u },
1652 { 11529215046068469760u, 7891549145984268038u, 193987144822u },
1653 { 0u, 7703609897518594624u, 118427801736u },
1654 { 0u, 6336912652634587136u, 136417613529u },
1655 { 0u, 4461621834659397632u, 217343524723u },
1656 { 0u, 5484660635557953536u, 115241865004u },
1657 { 0u, 15142619273265938432u, 44297324048u },
1658 { 0u, 12170977992968765440u, 16820883035u },
1659 { 0u, 1152921504606846976u, 91659790039u },
1660 { 0u, 0u, 215062500000u },
1661 { 0u, 0u, 160000000000u },
1662 { 14000097438505379162u, 514755u, 0u },
1663 { 16451062686452429925u, 514755758946802u, 0u },
1664 { 4009347599785716645u, 17812314011563521031u, 27904u },
1665 { 16544162347546196456u, 7684138864490314336u, 965607477u },
1666 { 17674258299745817187u, 9740522787420029605u, 53416558002u },
1667 { 5215238411201214416u, 6701109407732989894u, 178528034798u },
1668 { 14253990228345322571u, 16534886227502443952u, 238363267868u },
1669 { 11214836553940194590u, 8908667306968317910u, 28896357978u },
1670 { 14620711348380590101u, 7531472173477105155u, 90482939822u },
1671 { 6638710787931587427u, 11527371604834801166u, 174408281924u },
1672 { 17320000343692853250u, 15688593496691078576u, 68624900066u },
1673 { 75147386268843646u, 11394944804253312188u, 226850480357u },
1674 { 17938801582125480173u, 11182279880854372627u, 229617721195u },
1675 { 6573358613626446145u, 150579373068361470u, 107606192607u },
1676 { 8688505427903736481u, 3147220002440857300u, 223008162924u },
1677 { 539870168696556032u, 3630514817795505815u, 108170611138u },
1678 { 9002861336394465280u, 11708796588334233588u, 194196810602u },
1679 { 17989846818158018560u, 16844495466426369546u, 106634735134u },
1680 { 2700938287723315200u, 17636655472325475902u, 30913141928u },
1681 { 17800090499088908288u, 17038926655686645229u, 168956085008u },
1682 { 8809040871136690176u, 15602838456783529415u, 16923682064u },
1683 { 9223372036854775808u, 10869815869248876790u, 16845831567u },
1684 { 0u, 18407124180939800832u, 143589253898u },
1685 { 0u, 5705018517251293184u, 10997852201u },
1686 { 0u, 9660452258743058432u, 41309269673u },
1687 { 0u, 5646292272224927744u, 169523694166u },
1688 { 0u, 7410409304047484928u, 86306086117u },
1689 { 0u, 5953758707383795712u, 229401719093u },
1690 { 0u, 4611686018427387904u, 53322753906u },
1691 { 0u, 0u, 114250000000u },
1692 { 0u, 0u, 128000000000u },
1693 { 15763656745260536568u, 7u, 0u },
1694 { 8787336846248645550u, 7854549544u, 0u },
1695 { 17584084447880694346u, 7854549544476362484u, 0u },
1696 { 18041672551129683938u, 15035424419724983u, 425795984u },
1697 { 14025886302294509785u, 18280822466032836292u, 144000815071u },
1698 { 18430498103283160734u, 11524250747302615283u, 223991005371u },
1699 { 3292348826238025833u, 15212285943691810760u, 187624730884u },
1700 { 9211721212658275243u, 7951804027551297019u, 4824659673u },
1701 { 10233245872666307519u, 1706416229965221847u, 217431068160u },
1702 { 6200995035623311671u, 3406023111930700826u, 92505009u },
1703 { 8480542380570450804u, 16132696204133391302u, 177184640882u },
1704 { 11870363864499900506u, 11593846688794356915u, 114874555213u },
1705 { 9301051379839581901u, 6875759884161133906u, 77628503688u },
1706 { 11456694803569638005u, 3593593325323835965u, 136372735690u },
1707 { 14327208890643983169u, 9542049733257388925u, 202194809084u },
1708 { 4510081789599866365u, 9926551925937787518u, 252517275552u },
1709 { 13255356976020303332u, 3128491553219547895u, 160538119458u },
1710 { 9658806854127314944u, 17158408656931354885u, 34169595866u },
1711 { 13708435528809971712u, 2065169543154992616u, 218930159197u },
1712 { 1580190652103131136u, 4832622393556232739u, 93111953065u },
1713 { 16557336970347413504u, 16505930714733656162u, 169261976984u },
1714 { 12751520132434493440u, 18270988073492888699u, 152894788296u },
1715 { 9295429630892703744u, 2525111411519708523u, 200990472248u },
1716 { 0u, 16728989342518570442u, 56136886563u },
1717 { 0u, 7974052022039438336u, 35906880329u },
1718 { 0u, 5356554962386550784u, 73432274226u },
1719 { 0u, 6693869495028547584u, 50290379426u },
1720 { 0u, 8157517147199766528u, 162362875392u },
1721 { 0u, 12065776720423157760u, 442219890u },
1722 { 0u, 11997589407315001344u, 114654087066u },
1723 { 0u, 0u, 154650390625u },
1724 { 0u, 0u, 97000000000u },
1725 { 16872870088062921306u, 119850u, 0u },
1726 { 5112979788807802982u, 119850914680120u, 0u },
1727 { 13742728082020150272u, 2418433229320326037u, 6497u },
1728 { 2217110934613627976u, 1143911773589293534u, 97131103528u },
1729 { 11021433940188610484u, 9276183703610924928u, 40062011581u },
1730 { 1713669895470733463u, 3532180128827684715u, 189502862926u },
1731 { 3313382510572018285u, 8563997501322031543u, 78191479868u },
1732 { 14976595232784069505u, 14843890409658460681u, 60464255234u },
1733 { 7213172372862496841u, 9489417861634552678u, 2804688911u },
1734 { 15836474542502248588u, 1113198223322322089u, 15514422373u },
1735 { 3221099285878340134u, 11190777557146597869u, 101060346596u },
1736 { 3265814602578095358u, 17764553645932638286u, 228606653266u },
1737 { 6502528252282225364u, 14900777150991234852u, 82963018382u },
1738 { 16392476834556790183u, 17364899863357893610u, 142807772747u },
1739 { 15167629413417091342u, 15537570181590167037u, 75941353107u },
1740 { 1366763272626280111u, 5558052627121307766u, 147842293367u },
1741 { 8720523635169216093u, 12095241565795232609u, 119301302636u },
1742 { 9649171375767398672u, 2187936505958366389u, 108655684359u },
1743 { 7647980704001073152u, 12009203621325860228u, 7118608275u },
1744 { 13286434495608651776u, 14814842834750302952u, 147651020232u },
1745 { 4358271637167013888u, 5965296499605198833u, 200803114239u },
1746 { 15954987941890097152u, 4051026394962148842u, 255323379371u },
1747 { 7911135695429697536u, 16799526299141688349u, 171219606580u },
1748 { 7205759403792793600u, 9460214166646215205u, 52910704145u },
1749 { 0u, 10750736995029068008u, 17512839237u },
1750 { 0u, 5377963045376430080u, 69582798620u },
1751 { 0u, 15996910350253424640u, 28291539960u },
1752 { 0u, 13651157529655246848u, 248867194247u },
1753 { 0u, 9771305410219737088u, 135740030732u },
1754 { 0u, 12709439623416250368u, 12529703527u },
1755 { 0u, 9943947977234055168u, 103688980102u },
1756 { 0u, 0u, 134539062500u },
1757 { 0u, 0u, 228000000000u },
1758 { 952589339068938148u, 1828779826u, 0u },
1759 { 10058155040190817688u, 1828779826051639971u, 0u },
1760 { 5322725640026584391u, 371564423966525229u, 99138353u },
1761 { 2269982385930389600u, 14464859121514339583u, 49020142547u },
1762 { 13216683679976310224u, 3913119023023056247u, 211784141584u },
1763 { 17417440642083494819u, 5493396321716566945u, 16212130607u },
1764 { 3029180749090900711u, 5837454566818211973u, 47297797611u },
1765 { 8315443826261908513u, 2886670683193253881u, 235316449046u },
1766 { 1488962797247197277u, 5504823105587173817u, 22156486731u },
1767 { 18009099634999034122u, 9431834277334851106u, 75298417058u },
1768 { 8092455412807497971u, 12921661346456247087u, 162511300760u },
1769 { 17808458047236758329u, 3643076516404724246u, 152700484665u },
1770 { 3164591817527425171u, 12559396953196866477u, 57197491573u },
1771 { 3314036340472350590u, 1626880974916825698u, 117680846273u },
1772 { 33234902404332784u, 6806994170946429566u, 193088193394u },
1773 { 12349284717857274280u, 7596631230206896579u, 114369007893u },
1774 { 18209607903013119355u, 3100480253729502401u, 21411814204u },
1775 { 7891549145984268038u, 6310570748781063286u, 60168077371u },
1776 { 7703609897518594624u, 14251867077375744136u, 59342096725u },
1777 { 6336912652634587136u, 6701165793751570137u, 85772595262u },
1778 { 4461621834659397632u, 10856833140463959923u, 62363270925u },
1779 { 5484660635557953536u, 15867563727561248556u, 13588550103u },
1780 { 15142619273265938432u, 5048961008671491600u, 215860182353u },
1781 { 12170977992968765440u, 13278183119599849051u, 81273704724u },
1782 { 1152921504606846976u, 4547591784941053655u, 20719811749u },
1783 { 0u, 11815437715887182496u, 165246525444u },
1784 { 0u, 398495392178782208u, 4640516162u },
1785 { 0u, 9154841240825495552u, 66021602478u },
1786 { 0u, 1902683298245640192u, 174496284938u },
1787 { 0u, 5081900962138816512u, 10103144668u },
1788 { 0u, 3234710432358858752u, 220275490403u },
1789 { 0u, 16717361816799281152u, 99175354003u },
1790 { 0u, 0u, 147906250000u },
1791 { 0u, 0u, 16000000000u },
1792 { 17812314011563521031u, 27904u, 0u },
1793 { 7684138864490314336u, 27904965607477u, 0u },
1794 { 9740522787420029605u, 13488568028574514610u, 1512u },
1795 { 6701109407732989894u, 275784718433886190u, 232731216738u },
1796 { 16534886227502443952u, 10020568880357102364u, 98014950319u },
1797 { 8908667306968317910u, 8876397213146246746u, 175543216127u },
1798 { 7531472173477105155u, 2155905919114811310u, 255481190457u },
1799 { 11527371604834801166u, 1087100407155601220u, 57116871894u },
1800 { 15688593496691078576u, 2903498381705011170u, 214058931831u },
1801 { 11394944804253312188u, 12223476257006657765u, 119157398962u },
1802 { 11182279880854372627u, 12148657163736735595u, 178662635975u },
1803 { 150579373068361470u, 8951241323311673823u, 199658580024u },
1804 { 3147220002440857300u, 8463862715901576300u, 56485247764u },
1805 { 3630514817795505815u, 3873401978748963266u, 20458826917u },
1806 { 11708796588334233588u, 248364795947002730u, 165209977542u },
1807 { 16844495466426369546u, 10454378025404001822u, 198013463882u },
1808 { 17636655472325475902u, 6574176865628265640u, 74566732968u },
1809 { 17038926655686645229u, 16703315293848336u, 168356386842u },
1810 { 15602838456783529415u, 9896033222450013456u, 26000905488u },
1811 { 10869815869248876790u, 17311376269334085007u, 16536465035u },
1812 { 18407124180939800832u, 18378511316495639306u, 139938451587u },
1813 { 5705018517251293184u, 15120796393727584297u, 131996301094u },
1814 { 9660452258743058432u, 18253447805740347049u, 38819700014u },
1815 { 5646292272224927744u, 5842497225601731158u, 46989521388u },
1816 { 7410409304047484928u, 4369968404176723173u, 236316722409u },
1817 { 5953758707383795712u, 16142207253674488117u, 233236896461u },
1818 { 4611686018427387904u, 12124259227391928178u, 205875070808u },
1819 { 0u, 13019483264566077056u, 88657257409u },
1820 { 0u, 74901376448135168u, 193705787602u },
1821 { 0u, 13897060093813325824u, 210004060411u },
1822 { 0u, 4495486210810052608u, 251753361137u },
1823 { 0u, 14885496280087265280u, 241243700795u },
1824 { 0u, 4976477588244398080u, 59806944370u },
1825 { 0u, 11529215046068469760u, 114269775390u },
1826 { 0u, 0u, 30625000000u },
1827 { 0u, 0u, 64000000000u },
1828 { 15035424419724983u, 425795984u, 0u },
1829 { 18280822466032836292u, 425795984000815071u, 0u },
1830 { 11524250747302615283u, 10043594327130472635u, 23082446u },
1831 { 15212285943691810760u, 8336034337032909060u, 206544464339u },
1832 { 7951804027551297019u, 16717215784895280857u, 211451897326u },
1833 { 1706416229965221847u, 10968831263951212032u, 238906242083u },
1834 { 3406023111930700826u, 5536629379734406065u, 35594621534u },
1835 { 16132696204133391302u, 1618806894932332402u, 94300141280u },
1836 { 11593846688794356915u, 11363331325254998861u, 224087755697u },
1837 { 6875759884161133906u, 8775167772751754888u, 177616007425u },
1838 { 3593593325323835965u, 2898202945316114122u, 1475702798u },
1839 { 9542049733257388925u, 8868842714495185148u, 14157111896u },
1840 { 9926551925937787518u, 17052094667531999136u, 88480780926u },
1841 { 3128491553219547895u, 3658615537031138594u, 126924395904u },
1842 { 17158408656931354885u, 12486952437987190746u, 128198333945u },
1843 { 2065169543154992616u, 912079238520577629u, 249676919048u },
1844 { 4832622393556232739u, 10960072898031888041u, 8049443914u },
1845 { 16505930714733656162u, 6129550094334741912u, 74594146742u },
1846 { 18270988073492888699u, 7965724516573729480u, 182332283576u },
1847 { 2525111411519708523u, 5801761178810791992u, 184431822791u },
1848 { 16728989342518570442u, 13197466483098446115u, 199314514103u },
1849 { 7974052022039438336u, 11326268638393107273u, 183715436091u },
1850 { 5356554962386550784u, 3597339351794947378u, 59613998253u },
1851 { 6693869495028547584u, 353880726151383714u, 173195012157u },
1852 { 8157517147199766528u, 11154818162602073600u, 61019183912u },
1853 { 12065776720423157760u, 5141043976157511026u, 40604703904u },
1854 { 11997589407315001344u, 7188225141808859034u, 160278696552u },
1855 { 0u, 13894168943295705185u, 104389674465u },
1856 { 0u, 12176538069834828288u, 225753204407u },
1857 { 0u, 7994239409235165184u, 183660091451u },
1858 { 0u, 13707777025480065024u, 59433368586u },
1859 { 0u, 10120227247676719104u, 10743100081u },
1860 { 0u, 7358494763030413312u, 177548618618u },
1861 { 0u, 7656119366529843200u, 122398904800u },
1862 { 0u, 9223372036854775808u, 224415039062u },
1863 { 0u, 0u, 86500000000u },
1864 { 2418433229320326037u, 6497u, 0u },
1865 { 1143911773589293534u, 6497131103528u, 0u },
1866 { 9276183703610924928u, 3877189582299842749u, 352u },
1867 { 3532180128827684715u, 7625565791857948238u, 96210182868u },
1868 { 8563997501322031543u, 16568435163612007484u, 212413382749u },
1869 { 14843890409658460681u, 17592071940521808130u, 93898176669u },
1870 { 9489417861634552678u, 15158637878035490831u, 157953668130u },
1871 { 1113198223322322089u, 17789243229146401893u, 34821751405u },
1872 { 11190777557146597869u, 14677686051252896484u, 109964356807u },
1873 { 17764553645932638286u, 3531237481269211986u, 199795678955u },
1874 { 14900777150991234852u, 8074435404989280910u, 235191428767u },
1875 { 17364899863357893610u, 7086549341467684427u, 159437716020u },
1876 { 15537570181590167037u, 10556134770918626963u, 52384162609u },
1877 { 5558052627121307766u, 10772666134712966775u, 49572249212u },
1878 { 12095241565795232609u, 6195173298198112620u, 124583987401u },
1879 { 2187936505958366389u, 8144773843324250887u, 201335841017u },
1880 { 12009203621325860228u, 14144284817150924691u, 249441529074u },
1881 { 14814842834750302952u, 6464447844648863176u, 242766763216u },
1882 { 5965296499605198833u, 15760468443293179135u, 208350438419u },
1883 { 4051026394962148842u, 5172191224908322475u, 19854376706u },
1884 { 16799526299141688349u, 2357554307308969012u, 2280385048u },
1885 { 9460214166646215205u, 1602046917604361745u, 24127803275u },
1886 { 10750736995029068008u, 7830970218109515845u, 139086847137u },
1887 { 5377963045376430080u, 2899479134887821084u, 161424517746u },
1888 { 15996910350253424640u, 15792042302392017912u, 114157181078u },
1889 { 13651157529655246848u, 11286099112296056199u, 150856088328u },
1890 { 9771305410219737088u, 15161477829153947404u, 8611820658u },
1891 { 12709439623416250368u, 423831848142641767u, 114821905360u },
1892 { 9943947977234055168u, 9707413321046312582u, 208022975970u },
1893 { 0u, 10969483299803835620u, 226526239930u },
1894 { 0u, 4326479556120930304u, 186594656881u },
1895 { 0u, 12876227232041795584u, 113234538926u },
1896 { 0u, 16967986827791171584u, 174698021676u },
1897 { 0u, 1288146316538413056u, 44919836409u },
1898 { 0u, 13715290452691779584u, 249069830551u },
1899 { 0u, 4683743612465315840u, 151743507385u },
1900 { 0u, 0u, 185253906250u },
1901 { 0u, 0u, 74000000000u },
1902 { 371564423966525229u, 99138353u, 0u },
1903 { 14464859121514339583u, 99138353020142547u, 0u },
1904 { 3913119023023056247u, 16344805304534272784u, 5374300u },
1905 { 5493396321716566945u, 26429987091348271u, 92886053671u },
1906 { 5837454566818211973u, 8691371289609838059u, 39001432772u },
1907 { 2886670683193253881u, 12980168378493046550u, 196471160181u },
1908 { 5504823105587173817u, 14010125458129496139u, 117703656337u },
1909 { 9431834277334851106u, 17061829677031795106u, 145759490422u },
1910 { 12921661346456247087u, 2227928323072698520u, 118924923640u },
1911 { 3643076516404724246u, 7394752319272287289u, 248120776236u },
1912 { 12559396953196866477u, 8805771303577744757u, 44400870326u },
1913 { 1626880974916825698u, 16371027194302248385u, 182477361818u },
1914 { 6806994170946429566u, 9114324123731231602u, 154887475162u },
1915 { 7596631230206896579u, 14468189808746991893u, 218494088500u },
1916 { 3100480253729502401u, 2376054557800684348u, 52784322141u },
1917 { 6310570748781063286u, 12462238943546048571u, 93128806175u },
1918 { 14251867077375744136u, 15334855370842605909u, 31675579326u },
1919 { 6701165793751570137u, 7211347914013798462u, 190831304175u },
1920 { 10856833140463959923u, 13763642332572548877u, 239390927953u },
1921 { 15867563727561248556u, 16868268377740071383u, 81746128545u },
1922 { 5048961008671491600u, 1120013377627684177u, 161914430661u },
1923 { 13278183119599849051u, 15898107650717274388u, 197060716046u },
1924 { 4547591784941053655u, 12281923376333274277u, 14861838142u },
1925 { 11815437715887182496u, 6383530489286615044u, 62665804400u },
1926 { 398495392178782208u, 4253822060257126466u, 112346051881u },
1927 { 9154841240825495552u, 17614372438391501998u, 41230600155u },
1928 { 1902683298245640192u, 4309951310554333450u, 219954877043u },
1929 { 5081900962138816512u, 13106185988973773020u, 115233642928u },
1930 { 3234710432358858752u, 2070134359761960547u, 176710487766u },
1931 { 16717361816799281152u, 9399359914137865875u, 214112222208u },
1932 { 0u, 17415053284723541264u, 509540321u },
1933 { 0u, 4840502610448261120u, 225944071930u },
1934 { 0u, 5690599259712258048u, 250262404172u },
1935 { 0u, 114769594245185536u, 76308488004u },
1936 { 0u, 3150620882578178048u, 68006221672u },
1937 { 0u, 5136918324969472000u, 104170795500u },
1938 { 0u, 7205759403792793600u, 236278472900u },
1939 { 0u, 0u, 196390625000u },
1940 { 0u, 0u, 232000000000u },
1941 { 13488568028574514610u, 1512u, 0u },
1942 { 275784718433886190u, 1512731216738u, 0u },
1943 { 10020568880357102364u, 98202693831717807u, 82u },
1944 { 8876397213146246746u, 12909287260170414079u, 82005323578u },
1945 { 2155905919114811310u, 11728631949380786233u, 58699813864u },
1946 { 1087100407155601220u, 18263701925522197718u, 232635810411u },
1947 { 2903498381705011170u, 4868886449713321591u, 107990077265u },
1948 { 12223476257006657765u, 5870139507184082354u, 81263942863u },
1949 { 12148657163736735595u, 5978562500822661575u, 207318220900u },
1950 { 8951241323311673823u, 10821136839630268472u, 100324098522u },
1951 { 8463862715901576300u, 9490907630136752916u, 218586615003u },
1952 { 3873401978748963266u, 10564005678001613989u, 219514503133u },
1953 { 248364795947002730u, 5754050547468481222u, 221572675895u },
1954 { 10454378025404001822u, 3833909949855542602u, 55311927705u },
1955 { 6574176865628265640u, 15446538552665967784u, 153207836674u },
1956 { 16703315293848336u, 14924837848804399130u, 2837358532u },
1957 { 9896033222450013456u, 18140170340418344208u, 196809077080u },
1958 { 17311376269334085007u, 11380424819825208971u, 88983380604u },
1959 { 18378511316495639306u, 12416915664152252547u, 124616934065u },
1960 { 15120796393727584297u, 17195282241626289958u, 177673122346u },
1961 { 18253447805740347049u, 2649541045825281326u, 42932158118u },
1962 { 5842497225601731158u, 16577429864268509676u, 166143631907u },
1963 { 4369968404176723173u, 12051257060168107241u, 35898664273u },
1964 { 16142207253674488117u, 5363884561143470797u, 81653299954u },
1965 { 12124259227391928178u, 13054029903083620184u, 242290776764u },
1966 { 13019483264566077056u, 566314952158634945u, 188707660379u },
1967 { 74901376448135168u, 1329472079642345682u, 91030699995u },
1968 { 13897060093813325824u, 15686237486658857211u, 219072070825u },
1969 { 4495486210810052608u, 1069073549290598129u, 169850352638u },
1970 { 14885496280087265280u, 4323599065125928507u, 254057954593u },
1971 { 4976477588244398080u, 17861823329752681586u, 33234382774u },
1972 { 11529215046068469760u, 17220149985412802078u, 182968291382u },
1973 { 0u, 4344934572159429184u, 54933506201u },
1974 { 0u, 2252927464837120000u, 153235539375u },
1975 { 0u, 10910018171964489728u, 175122131442u },
1976 { 0u, 3597328585515335680u, 242591433270u },
1977 { 0u, 6972808074239148032u, 54195011573u },
1978 { 0u, 2227030015734710272u, 245377996683u },
1979 { 0u, 1152921504606846976u, 139120727539u },
1980 { 0u, 0u, 243062500000u },
1981 { 0u, 0u, 160000000000u },
1982 { 10043594327130472635u, 23082446u, 0u },
1983 { 8336034337032909060u, 23082446544464339u, 0u },
1984 { 16717215784895280857u, 17238287503805244910u, 1251301u },
1985 { 10968831263951212032u, 1434575446038410275u, 229934489438u },
1986 { 5536629379734406065u, 14009569747841241694u, 94077768490u },
1987 { 1618806894932332402u, 14938795732275951328u, 42759460297u },
1988 { 11363331325254998861u, 6687653542888983473u, 201809833739u },
1989 { 8775167772751754888u, 28238723295162625u, 11362538425u },
1990 { 2898202945316114122u, 4745270274832691214u, 185001530824u },
1991 { 8868842714495185148u, 926478968112308824u, 200257241617u },
1992 { 17052094667531999136u, 9213681606604198526u, 17050224525u },
1993 { 3658615537031138594u, 13346223820579313024u, 141499474680u },
1994 { 12486952437987190746u, 691642518601291257u, 248723500243u },
1995 { 912079238520577629u, 1153720150033789192u, 211037494016u },
1996 { 10960072898031888041u, 12089015034721780810u, 62543294u },
1997 { 6129550094334741912u, 3555868702841788854u, 190655346818u },
1998 { 7965724516573729480u, 11708406782758214328u, 130192764028u },
1999 { 5801761178810791992u, 9417497762905343943u, 124634714003u },
2000 { 13197466483098446115u, 12838336066957615287u, 147510523576u },
2001 { 11326268638393107273u, 13737708142128207419u, 184695967592u },
2002 { 3597339351794947378u, 11683434809834695853u, 104744722650u },
2003 { 353880726151383714u, 2689114340106315837u, 218633360270u },
2004 { 11154818162602073600u, 8859225263374261032u, 142145777180u },
2005 { 5141043976157511026u, 15761671984578600096u, 28480259563u },
2006 { 7188225141808859034u, 7087267079878005352u, 235854441950u },
2007 { 13894168943295705185u, 4601291730423121377u, 222384201518u },
2008 { 12176538069834828288u, 9559411037059581623u, 46249436524u },
2009 { 7994239409235165184u, 12969820289641388091u, 108518216710u },
2010 { 13707777025480065024u, 13628239920285957130u, 6703095366u },
2011 { 10120227247676719104u, 8049893933765800625u, 70738788366u },
2012 { 7358494763030413312u, 10391755948840250234u, 14436385624u },
2013 { 7656119366529843200u, 14454650777462444512u, 88563338218u },
2014 { 9223372036854775808u, 14244638523341127254u, 234783588188u },
2015 { 0u, 12246016810439753984u, 92772203401u },
2016 { 0u, 9382741764551081984u, 137663857901u },
2017 { 0u, 4608696190291148800u, 237508639450u },
2018 { 0u, 1696483666416369664u, 218249837921u },
2019 { 0u, 15416683541605384192u, 97091966563u },
2020 { 0u, 7683140964294066176u, 99835740089u },
2021 { 0u, 4611686018427387904u, 185416503906u },
2022 { 0u, 0u, 98250000000u },
2023 { 0u, 0u, 128000000000u },
2024 { 3877189582299842749u, 352u, 0u },
2025 { 7625565791857948238u, 352210182868u, 0u },
2026 { 16568435163612007484u, 1722045467931902045u, 19u },
2027 { 17592071940521808130u, 16095324008152856733u, 19093352271u },
2028 { 15158637878035490831u, 15216188060094280738u, 79872529262u },
2029 { 17789243229146401893u, 10793385929903030893u, 110824871207u },
2030 { 14677686051252896484u, 12613277226875940039u, 39585110623u },
2031 { 3531237481269211986u, 10644539625155600107u, 95683767128u },
2032 { 8074435404989280910u, 6181262895644173983u, 88577041649u },
2033 { 7086549341467684427u, 148914399627082292u, 241335086933u },
2034 { 10556134770918626963u, 14379289774887985969u, 85008072665u },
2035 { 10772666134712966775u, 11743339675582627452u, 217779502860u },
2036 { 6195173298198112620u, 7841621929809463497u, 12636607719u },
2037 { 8144773843324250887u, 11168944680251236601u, 231425095176u },
2038 { 14144284817150924691u, 6178560202529287410u, 8605469704u },
2039 { 6464447844648863176u, 13295243308201596112u, 8334940419u },
2040 { 15760468443293179135u, 17040673746172470291u, 3720736583u },
2041 { 5172191224908322475u, 14957442487039409922u, 71923776774u },
2042 { 2357554307308969012u, 17778155426506992152u, 6810844581u },
2043 { 1602046917604361745u, 14945404984219733899u, 165963755736u },
2044 { 7830970218109515845u, 11590754866058681505u, 216810192027u },
2045 { 2899479134887821084u, 6020790784469412466u, 155628336080u },
2046 { 15792042302392017912u, 7934351824569522326u, 208326387722u },
2047 { 11286099112296056199u, 5038361112172116744u, 10430122074u },
2048 { 15161477829153947404u, 3305187319649924210u, 90273130103u },
2049 { 423831848142641767u, 11470175511099161552u, 119179174563u },
2050 { 9707413321046312582u, 7308362160352048610u, 163621799460u },
2051 { 10969483299803835620u, 10666410671225576634u, 36396187106u },
2052 { 4326479556120930304u, 2181639019945820785u, 226578227281u },
2053 { 12876227232041795584u, 4615749499734847918u, 81118266888u },
2054 { 16967986827791171584u, 14076159200958497580u, 8250220281u },
2055 { 1288146316538413056u, 5470405257862074105u, 249763070119u },
2056 { 13715290452691779584u, 4565741478181339543u, 167296551263u },
2057 { 4683743612465315840u, 8901832997861862329u, 95247509341u },
2058 { 0u, 14190141170191714122u, 93482569333u },
2059 { 0u, 4240772322245764096u, 117769249094u },
2060 { 0u, 4422842195340951552u, 70229892728u },
2061 { 0u, 15448426386733137920u, 120239762755u },
2062 { 0u, 9203504548935630848u, 67837460872u },
2063 { 0u, 5936377627571912704u, 136498922981u },
2064 { 0u, 468374361246531584u, 229321811676u },
2065 { 0u, 0u, 220025390625u },
2066 { 0u, 0u, 33000000000u },
2067 { 16344805304534272784u, 5374300u, 0u },
2068 { 26429987091348271u, 5374300886053671u, 0u },
2069 { 8691371289609838059u, 8020875056524075716u, 291341u },
2070 { 12980168378493046550u, 1400288714762747253u, 13434812508u },
2071 { 14010125458129496139u, 6136037711314764689u, 92075909803u },
2072 { 17061829677031795106u, 15735488086392394102u, 171332635270u },
2073 { 2227928323072698520u, 7735094782793634552u, 134853022518u },
2074 { 7394752319272287289u, 7273689191766726188u, 54419320328u },
2075 { 8805771303577744757u, 3410634565056431030u, 8394307481u },
2076 { 16371027194302248385u, 4600927904885215898u, 153184890870u },
2077 { 9114324123731231602u, 9154871331680374746u, 246249416801u },
2078 { 14468189808746991893u, 6117978272461042996u, 97496286569u },
2079 { 2376054557800684348u, 13116904339287496285u, 105331656266u },
2080 { 12462238943546048571u, 867037205615660831u, 74711068809u },
2081 { 15334855370842605909u, 1802487145191504830u, 137047002181u },
2082 { 7211347914013798462u, 17242009718457409007u, 69097713023u },
2083 { 13763642332572548877u, 13620802355488468049u, 127934691219u },
2084 { 16868268377740071383u, 4442227880594435745u, 147738385175u },
2085 { 1120013377627684177u, 17354849212854314181u, 23240813655u },
2086 { 15898107650717274388u, 18202319179831567886u, 87940808260u },
2087 { 12281923376333274277u, 17568634016348874558u, 68986749699u },
2088 { 6383530489286615044u, 7496925598312450672u, 3952397558u },
2089 { 4253822060257126466u, 601870379496813865u, 246406409151u },
2090 { 17614372438391501998u, 11995106565680728027u, 191032627458u },
2091 { 4309951310554333450u, 16331071694764184179u, 2650256029u },
2092 { 13106185988973773020u, 9665962217000524208u, 157885309170u },
2093 { 2070134359761960547u, 13682661374415474390u, 242523992861u },
2094 { 9399359914137865875u, 6940361789924260864u, 29741738559u },
2095 { 17415053284723541264u, 9658039831644010465u, 63376237766u },
2096 { 4840502610448261120u, 6843715893910236922u, 198523563388u },
2097 { 5690599259712258048u, 47089792870595660u, 124370998582u },
2098 { 114769594245185536u, 14510386192097156932u, 54002552742u },
2099 { 3150620882578178048u, 12059931208360040296u, 166786609611u },
2100 { 5136918324969472000u, 14877013468459184620u, 203653770180u },
2101 { 7205759403792793600u, 2397668560671695044u, 196806484516u },
2102 { 0u, 2195572305559232232u, 36129977873u },
2103 { 0u, 3261686279425953792u, 17119022213u },
2104 { 0u, 9333850662059900928u, 133176816367u },
2105 { 0u, 5036522340217782272u, 239505989058u },
2106 { 0u, 2800120215143186432u, 194273030423u },
2107 { 0u, 441634238459019264u, 23151794821u },
2108 { 0u, 720575940379279360u, 133023941040u },
2109 { 0u, 0u, 176039062500u },
2110 { 0u, 0u, 228000000000u },
2111 { 98202693831717807u, 82u, 0u },
2112 { 12909287260170414079u, 82005323578u, 0u },
2113 { 11728631949380786233u, 8218347283861607400u, 4u },
2114 { 18263701925522197718u, 17896200385973633643u, 4445517498u },
2115 { 4868886449713321591u, 16333242102094352209u, 186970154966u },
2116 { 5870139507184082354u, 9981905728606788815u, 214885426828u },
2117 { 5978562500822661575u, 15219470018924839012u, 140541120193u },
2118 { 10821136839630268472u, 17152070168529617370u, 193825049122u },
2119 { 9490907630136752916u, 17841343440958328027u, 34929815586u },
2120 { 10564005678001613989u, 17291078023923990493u, 34967181165u },
2121 { 5754050547468481222u, 16744804581790759223u, 109937351217u },
2122 { 3833909949855542602u, 5001622214111594905u, 49907737675u },
2123 { 15446538552665967784u, 9676746897435398146u, 75271138483u },
2124 { 14924837848804399130u, 8109025833995118532u, 179524577500u },
2125 { 18140170340418344208u, 5495826424046694744u, 220439591171u },
2126 { 11380424819825208971u, 7890288164365705852u, 3297929347u },
2127 { 12416915664152252547u, 8616438349039895217u, 131427733378u },
2128 { 17195282241626289958u, 15787154801788760618u, 130467098058u },
2129 { 2649541045825281326u, 12418659311480782502u, 202855823376u },
2130 { 16577429864268509676u, 4486988874116669987u, 16673216870u },
2131 { 12051257060168107241u, 4828971301551875409u, 102243240154u },
2132 { 5363884561143470797u, 14769106422014442226u, 218261779058u },
2133 { 13054029903083620184u, 7763933466423188156u, 114800634863u },
2134 { 566314952158634945u, 10449097116253839963u, 239420883676u },
2135 { 1329472079642345682u, 12870692502472900571u, 220566446689u },
2136 { 15686237486658857211u, 11597479481311003817u, 97697721638u },
2137 { 1069073549290598129u, 8294994869530047486u, 38628700622u },
2138 { 4323599065125928507u, 16879315829924478241u, 206449672572u },
2139 { 17861823329752681586u, 11873324837601439670u, 124915029544u },
2140 { 17220149985412802078u, 3277599055636107318u, 40643654229u },
2141 { 4344934572159429184u, 15363467897354242201u, 85177679000u },
2142 { 2252927464837120000u, 10351182204479784367u, 152832855263u },
2143 { 10910018171964489728u, 12811517584931924466u, 223561138711u },
2144 { 3597328585515335680u, 16988930699558748726u, 23694513759u },
2145 { 6972808074239148032u, 11683499918824718325u, 95920971778u },
2146 { 2227030015734710272u, 13119300691281647499u, 2633363799u },
2147 { 1152921504606846976u, 10125549106595354099u, 87711198715u },
2148 { 0u, 17505352699870800544u, 251548907116u },
2149 { 0u, 6756039242241163264u, 108948967071u },
2150 { 0u, 3537338758766526464u, 159366245621u },
2151 { 0u, 6522626374119718912u, 245191759518u },
2152 { 0u, 4733294203482669056u, 158353592284u },
2153 { 0u, 16997710893603094528u, 220256592392u },
2154 { 0u, 16717361816799281152u, 8921447753u },
2155 { 0u, 0u, 73906250000u },
2156 { 0u, 0u, 16000000000u },
2157 { 17238287503805244910u, 1251301u, 0u },
2158 { 1434575446038410275u, 1251301934489438u, 0u },
2159 { 14009569747841241694u, 3943737498063000362u, 67833u },
2160 { 14938795732275951328u, 2870731037991212489u, 249213790438u },
2161 { 6687653542888983473u, 7389433400402095883u, 230155622641u },
2162 { 28238723295162625u, 5675049236146197433u, 241400581987u },
2163 { 4745270274832691214u, 9953779846262904264u, 99307645035u },
2164 { 926478968112308824u, 12691978937179636241u, 107539595486u },
2165 { 9213681606604198526u, 15523327331528198029u, 222688033556u },
2166 { 13346223820579313024u, 15722603279568118520u, 20841521260u },
2167 { 691642518601291257u, 11838632364171816147u, 108852324031u },
2168 { 1153720150033789192u, 7832751832367143680u, 191641773546u },
2169 { 12089015034721780810u, 12167724027162940862u, 234424614327u },
2170 { 3555868702841788854u, 4108211144748152962u, 183659613641u },
2171 { 11708406782758214328u, 7530983398136343676u, 201222706572u },
2172 { 9417497762905343943u, 1117587133956542355u, 140408255428u },
2173 { 12838336066957615287u, 17134748625149490872u, 196060584519u },
2174 { 13737708142128207419u, 4039918359454207848u, 71928876584u },
2175 { 11683434809834695853u, 1830218764589441242u, 40219004413u },
2176 { 2689114340106315837u, 637895981480825742u, 253099216358u },
2177 { 8859225263374261032u, 8246879226348334620u, 230034580410u },
2178 { 15761671984578600096u, 12389239568142583275u, 186447064218u },
2179 { 7087267079878005352u, 14041257178803154398u, 154671622022u },
2180 { 4601291730423121377u, 16312515716494630702u, 134761178076u },
2181 { 9559411037059581623u, 17088522799596987756u, 220884303248u },
2182 { 12969820289641388091u, 3588932524637852678u, 144926370677u },
2183 { 13628239920285957130u, 107218049069817414u, 117194556422u },
2184 { 8049893933765800625u, 1596707240462008334u, 6005812302u },
2185 { 10391755948840250234u, 17461913142391587672u, 78086557672u },
2186 { 14454650777462444512u, 4366474266651610090u, 232946612208u },
2187 { 14244638523341127254u, 5539304013194805084u, 240236707044u },
2188 { 12246016810439753984u, 4762470619211987849u, 228300286272u },
2189 { 9382741764551081984u, 10835638458986644717u, 64258174049u },
2190 { 4608696190291148800u, 16141642290510052058u, 97587401137u },
2191 { 1696483666416369664u, 17390568670756355425u, 177875040181u },
2192 { 15416683541605384192u, 12536768491333867107u, 181942744616u },
2193 { 7683140964294066176u, 13145148522871947193u, 40679619581u },
2194 { 4611686018427387904u, 5665349945233068642u, 253712599929u },
2195 { 0u, 17074607537751066240u, 121307119235u },
2196 { 0u, 6241525660962062336u, 131925616329u },
2197 { 0u, 1142860629783085056u, 201338353784u },
2198 { 0u, 16287527416870469632u, 120061954598u },
2199 { 0u, 9028002014738513920u, 38882948630u },
2200 { 0u, 16217462258161156096u, 22489408969u },
2201 { 0u, 11529215046068469760u, 201879150390u },
2202 { 0u, 0u, 54625000000u },
2203 { 0u, 0u, 64000000000u },
2204 { 1722045467931902045u, 19u, 0u },
2205 { 16095324008152856733u, 19093352271u, 0u },
2206 { 15216188060094280738u, 646608198162977646u, 1u },
2207 { 10793385929903030893u, 12170458846894708007u, 1035052700u },
2208 { 12613277226875940039u, 1797330480103086687u, 156659761896u },
2209 { 10644539625155600107u, 10332188564497263448u, 232097433480u },
2210 { 6181262895644173983u, 7524259485079594225u, 136560109064u },
2211 { 148914399627082292u, 62681109059153749u, 8407890924u },
2212 { 14379289774887985969u, 13480636451804037081u, 236003397949u },
2213 { 11743339675582627452u, 6948168233012789004u, 61730786766u },
2214 { 7841621929809463497u, 12015502974041806055u, 206376660954u },
2215 { 11168944680251236601u, 7343801660689004040u, 218651361721u },
2216 { 6178560202529287410u, 13670580858640731144u, 185398108285u },
2217 { 13295243308201596112u, 5605073897566574851u, 125741083673u },
2218 { 17040673746172470291u, 15387788940505247559u, 25303851664u },
2219 { 14957442487039409922u, 17565181499678113030u, 144834173709u },
2220 { 17778155426506992152u, 1893743623847493029u, 13952210397u },
2221 { 14945404984219733899u, 10243498996716269784u, 221102660047u },
2222 { 11590754866058681505u, 5619675836950314139u, 207555301193u },
2223 { 6020790784469412466u, 10224869737511515088u, 73304643237u },
2224 { 7934351824569522326u, 2574495974386198538u, 165554291299u },
2225 { 5038361112172116744u, 7825756347302873178u, 99139563706u },
2226 { 3305187319649924210u, 12071550103794656887u, 186424235101u },
2227 { 11470175511099161552u, 7195875213867606691u, 93654400042u },
2228 { 7308362160352048610u, 18271364438406891044u, 42390089176u },
2229 { 10666410671225576634u, 16966521933952564706u, 216990492650u },
2230 { 2181639019945820785u, 289920862029570129u, 234919756997u },
2231 { 4615749499734847918u, 7804199568098625032u, 197015716641u },
2232 { 14076159200958497580u, 5758118571242446585u, 33423066506u },
2233 { 5470405257862074105u, 4030788293606375591u, 138312148233u },
2234 { 4565741478181339543u, 4387716460037196127u, 9218509471u },
2235 { 8901832997861862329u, 16807506478881285981u, 159237858585u },
2236 { 14190141170191714122u, 17033060604413529717u, 25911136751u },
2237 { 4240772322245764096u, 10498418508292170054u, 239923364065u },
2238 { 4422842195340951552u, 13237752038744465016u, 225569120407u },
2239 { 15448426386733137920u, 17737618428304633155u, 151717619975u },
2240 { 9203504548935630848u, 13546183833248825736u, 7961558221u },
2241 { 5936377627571912704u, 826778452978976229u, 205734340097u },
2242 { 468374361246531584u, 13728076626990147292u, 1044819749u },
2243 { 0u, 2794860281883592225u, 37744200525u },
2244 { 0u, 8680705720425908736u, 77151509679u },
2245 { 0u, 731520517439488000u, 175470582000u },
2246 { 0u, 13120812320768917504u, 240039655806u },
2247 { 0u, 2722954908557901824u, 126711280661u },
2248 { 0u, 6860847004205973504u, 21147611681u },
2249 { 0u, 6503197861922996224u, 33371927261u },
2250 { 0u, 9223372036854775808u, 221352539062u },
2251 { 0u, 0u, 182500000000u },
2252 { 8020875056524075716u, 291341u, 0u },
2253 { 1400288714762747253u, 291341434812508u, 0u },
2254 { 6136037711314764689u, 12005656413127238315u, 15793u },
2255 { 15735488086392394102u, 4821130826186787462u, 177650827938u },
2256 { 7735094782793634552u, 14377899467066168118u, 162261354025u },
2257 { 7273689191766726188u, 16575613239625444872u, 41779427491u },
2258 { 3410634565056431030u, 4317827099179284377u, 163898565794u },
2259 { 4600927904885215898u, 1242354770412171254u, 162234069876u },
2260 { 9154871331680374746u, 994838588328896609u, 116067348187u },
2261 { 6117978272461042996u, 17283309862013060457u, 219053930307u },
2262 { 13116904339287496285u, 124242522249856586u, 67936930105u },
2263 { 867037205615660831u, 11564608014666985609u, 57006735200u },
2264 { 1802487145191504830u, 12401028575581654085u, 96626918656u },
2265 { 17242009718457409007u, 2490725392961465727u, 672261106u },
2266 { 13620802355488468049u, 1949482237120640915u, 242135022494u },
2267 { 4442227880594435745u, 15410502396166200087u, 158105681643u },
2268 { 17354849212854314181u, 15694919529799920727u, 235835405008u },
2269 { 18202319179831567886u, 10324869370171768388u, 208850823292u },
2270 { 17568634016348874558u, 1631866459122189059u, 124559712290u },
2271 { 7496925598312450672u, 172020494461226230u, 34088463658u },
2272 { 601870379496813865u, 12734610307908856767u, 42009325249u },
2273 { 11995106565680728027u, 1467513250829340930u, 193690344608u },
2274 { 16331071694764184179u, 13558759428494307997u, 160079554052u },
2275 { 9665962217000524208u, 7915355143999496434u, 4735021821u },
2276 { 13682661374415474390u, 2876370200608797469u, 253429092262u },
2277 { 6940361789924260864u, 343685370404989503u, 166155928341u },
2278 { 9658039831644010465u, 4837266557407634630u, 21018631221u },
2279 { 6843715893910236922u, 9622591415747161468u, 53262228745u },
2280 { 47089792870595660u, 16503783814424220982u, 9521641725u },
2281 { 14510386192097156932u, 5377083431343591334u, 253894671913u },
2282 { 12059931208360040296u, 16508482371299291595u, 41291492276u },
2283 { 14877013468459184620u, 10515883558812249028u, 180894926622u },
2284 { 2397668560671695044u, 63492062913405476u, 30570067190u },
2285 { 2195572305559232232u, 11571919759617799697u, 246003441911u },
2286 { 3261686279425953792u, 2956602334970088581u, 247627315027u },
2287 { 9333850662059900928u, 13604736747717849839u, 83160277733u },
2288 { 5036522340217782272u, 16573540719338151362u, 229737514256u },
2289 { 2800120215143186432u, 12620703004601168151u, 16898453442u },
2290 { 441634238459019264u, 14649407809089591941u, 194684169680u },
2291 { 720575940379279360u, 11290375247898624432u, 208794145988u },
2292 { 0u, 11020319450292874212u, 196612052468u },
2293 { 0u, 8754634933362354176u, 244597412714u },
2294 { 0u, 12976319450332528640u, 106474589710u },
2295 { 0u, 17447331119627239424u, 14703447686u },
2296 { 0u, 3665184902673858560u, 134945821715u },
2297 { 0u, 12949678516038795264u, 19198690071u },
2298 { 0u, 72057594037927936u, 23702003479u },
2299 { 0u, 0u, 23003906250u },
2300 { 0u, 0u, 202000000000u },
2301 { 8218347283861607400u, 4u, 0u },
2302 { 17896200385973633643u, 4445517498u, 0u },
2303 { 16333242102094352209u, 4445517498970154966u, 0u },
2304 { 9981905728606788815u, 9413159735776077452u, 240991986u },
2305 { 15219470018924839012u, 14279163482889998017u, 242510288411u },
2306 { 17152070168529617370u, 8693044629541194274u, 27774075003u },
2307 { 17841343440958328027u, 11863110253260222498u, 123471250893u },
2308 { 17291078023923990493u, 8319293368489531245u, 205643100495u },
2309 { 16744804581790759223u, 3376307525676489265u, 79450989797u },
2310 { 5001622214111594905u, 13205662254759912523u, 229183029997u },
2311 { 9676746897435398146u, 5276250334231686323u, 237715880385u },
2312 { 8109025833995118532u, 13790198520922745052u, 193286026103u },
2313 { 5495826424046694744u, 14195535250150996227u, 119747568159u },
2314 { 7890288164365705852u, 16425228796427004035u, 31769541507u },
2315 { 8616438349039895217u, 4295900841296269186u, 131890413437u },
2316 { 15787154801788760618u, 4533952595483946442u, 125232881251u },
2317 { 12418659311480782502u, 12885038019373447184u, 99245786062u },
2318 { 4486988874116669987u, 12140736240487831910u, 206698499310u },
2319 { 4828971301551875409u, 6927124077155322074u, 238658150630u },
2320 { 14769106422014442226u, 12477788342407819890u, 230375520148u },
2321 { 7763933466423188156u, 7980854329409711087u, 148676422261u },
2322 { 10449097116253839963u, 2062671021810827996u, 117432642980u },
2323 { 12870692502472900571u, 2739521363598172769u, 164111817620u },
2324 { 11597479481311003817u, 12897585686593465638u, 148148509750u },
2325 { 8294994869530047486u, 1127632646629044686u, 54699179521u },
2326 { 16879315829924478241u, 4833775019274666364u, 1061129088u },
2327 { 11873324837601439670u, 15867662672939849256u, 128262039468u },
2328 { 3277599055636107318u, 2092350330982953557u, 172860187717u },
2329 { 15363467897354242201u, 13330062299842493592u, 69113426538u },
2330 { 10351182204479784367u, 4479193352178519263u, 106722624125u },
2331 { 12811517584931924466u, 3149393938889064983u, 125242817558u },
2332 { 16988930699558748726u, 9736379904070620767u, 22170728987u },
2333 { 11683499918824718325u, 3816238703055069186u, 27527810212u },
2334 { 13119300691281647499u, 11598915938798661975u, 164206878714u },
2335 { 10125549106595354099u, 17821633264606555643u, 250628778492u },
2336 { 17505352699870800544u, 2514623558764574316u, 252966112675u },
2337 { 6756039242241163264u, 4976730480406253215u, 163136318016u },
2338 { 3537338758766526464u, 17276563697191611637u, 64269789099u },
2339 { 6522626374119718912u, 12524734095940998814u, 171936564394u },
2340 { 4733294203482669056u, 15331551308930355164u, 170678967195u },
2341 { 16997710893603094528u, 15417115581125943816u, 155831125061u },
2342 { 16717361816799281152u, 6010750237807115593u, 69835763510u },
2343 { 0u, 5624630987553628432u, 54325843423u },
2344 { 0u, 14881848243837640704u, 223304911856u },
2345 { 0u, 15281613886881529856u, 240806746609u },
2346 { 0u, 14057902358273196032u, 241828417948u },
2347 { 0u, 16075318494433902592u, 156762080413u },
2348 { 0u, 13891916000577716224u, 157871444761u },
2349 { 0u, 7205759403792793600u, 25753082275u },
2350 { 0u, 0u, 163390625000u },
2351 { 0u, 0u, 232000000000u },
2352 { 3943737498063000362u, 67833u, 0u },
2353 { 2870731037991212489u, 67833213790438u, 0u },
2354 { 7389433400402095883u, 4535831408134330609u, 3677u },
2355 { 5675049236146197433u, 6204770794376564579u, 93245887913u },
2356 { 9953779846262904264u, 13869812122751887467u, 169336361298u },
2357 { 12691978937179636241u, 14253229412394467550u, 82751884021u },
2358 { 15523327331528198029u, 12776557610216045332u, 245772669114u },
2359 { 15722603279568118520u, 16493640728678654060u, 186692618575u },
2360 { 11838632364171816147u, 9434398296825833151u, 79894122055u },
2361 { 7832751832367143680u, 8773374058285327850u, 71511439756u },
2362 { 12167724027162940862u, 12932015276748029367u, 140475605560u },
2363 { 4108211144748152962u, 16293958583527755209u, 56701045952u },
2364 { 7530983398136343676u, 13511893936143127948u, 192883297264u },
2365 { 1117587133956542355u, 18409936402005226436u, 240732481237u },
2366 { 17134748625149490872u, 2189663026458466887u, 213998004652u },
2367 { 4039918359454207848u, 9497725274248154664u, 172118701870u },
2368 { 1830218764589441242u, 14766925481127792125u, 46514872718u },
2369 { 637895981480825742u, 6982373971809635814u, 142800516634u },
2370 { 8246879226348334620u, 8616702383006884794u, 26378515251u },
2371 { 12389239568142583275u, 3059473300040871066u, 51467112372u },
2372 { 14041257178803154398u, 17123843157031495558u, 180165854379u },
2373 { 16312515716494630702u, 11210627174210626524u, 171928285397u },
2374 { 17088522799596987756u, 15868067138625928592u, 213607729316u },
2375 { 3588932524637852678u, 4467869511636937589u, 164860209643u },
2376 { 107218049069817414u, 10052108125844341766u, 235242203691u },
2377 { 1596707240462008334u, 7470588003218451534u, 43544925873u },
2378 { 17461913142391587672u, 2613527085490786280u, 177404981387u },
2379 { 4366474266651610090u, 3632919450036549616u, 139141679587u },
2380 { 5539304013194805084u, 179367907231218916u, 227196940958u },
2381 { 4762470619211987849u, 13553068184555874624u, 158009723553u },
2382 { 10835638458986644717u, 8798774862365584481u, 161734713298u },
2383 { 16141642290510052058u, 910911255817064881u, 210476982541u },
2384 { 17390568670756355425u, 2304331144765093813u, 13049380598u },
2385 { 12536768491333867107u, 12248937023083640360u, 246124918041u },
2386 { 13145148522871947193u, 10206039550662130685u, 25664016206u },
2387 { 5665349945233068642u, 12267881323837852537u, 78553270512u },
2388 { 17074607537751066240u, 2858642007937891971u, 240665043179u },
2389 { 6241525660962062336u, 14171330289750320841u, 235154967293u },
2390 { 1142860629783085056u, 6601103619749017720u, 253768229354u },
2391 { 16287527416870469632u, 4919573414486739494u, 234357846544u },
2392 { 9028002014738513920u, 3401998285294974486u, 16266690609u },
2393 { 16217462258161156096u, 10799436256515532233u, 49184422696u },
2394 { 11529215046068469760u, 10083786644665753398u, 40585438612u },
2395 { 0u, 6481194517685688896u, 148546643169u },
2396 { 0u, 15104161756860547072u, 225351346258u },
2397 { 0u, 9556039274244079616u, 82818798249u },
2398 { 0u, 1376343134954323968u, 169518033927u },
2399 { 0u, 15682488278596976640u, 7074611710u },
2400 { 0u, 1506454075355430912u, 254850149393u },
2401 { 0u, 1152921504606846976u, 17081665039u },
2402 { 0u, 0u, 15062500000u },
2403 { 0u, 0u, 160000000000u },
2404 { 12170458846894708007u, 1035052700u, 0u },
2405 { 1797330480103086687u, 1035052700659761896u, 0u },
2406 { 10332188564497263448u, 6172559441576707976u, 56110319u },
2407 { 7524259485079594225u, 15083329738554729992u, 239334615117u },
2408 { 62681109059153749u, 10013126833549229036u, 77817668943u },
2409 { 13480636451804037081u, 5817156823499936061u, 79542812693u },
2410 { 6948168233012789004u, 5282692560913632718u, 21315348703u },
2411 { 12015502974041806055u, 10252307034225766362u, 223286375337u },
2412 { 7343801660689004040u, 17981881283247669689u, 169555778677u },
2413 { 13670580858640731144u, 11689290159733383293u, 117974799737u },
2414 { 5605073897566574851u, 5530668968487988249u, 121633677689u },
2415 { 15387788940505247559u, 10083765740821947024u, 121299818165u },
2416 { 17565181499678113030u, 2798423656816843533u, 181546642036u },
2417 { 1893743623847493029u, 7614494481582904797u, 116151702850u },
2418 { 10243498996716269784u, 17811318500083423695u, 66412782572u },
2419 { 5619675836950314139u, 11641467412200329033u, 236965553510u },
2420 { 10224869737511515088u, 17733593025296340645u, 102631085212u },
2421 { 2574495974386198538u, 3689424000190644835u, 156961340004u },
2422 { 7825756347302873178u, 14966634145516728506u, 100200004075u },
2423 { 12071550103794656887u, 14171681941562070109u, 235811342862u },
2424 { 7195875213867606691u, 8130575762882608170u, 14768248417u },
2425 { 18271364438406891044u, 5234550794400656856u, 97440759395u },
2426 { 16966521933952564706u, 3020576149360486378u, 99283765567u },
2427 { 289920862029570129u, 3038675756589057221u, 63163745761u },
2428 { 7804199568098625032u, 15470260187120878369u, 225164726942u },
2429 { 5758118571242446585u, 3497929414841828746u, 158838644485u },
2430 { 4030788293606375591u, 9935840636861015305u, 5189623133u },
2431 { 4387716460037196127u, 3647355485153741471u, 93538623000u },
2432 { 16807506478881285981u, 766100215038272793u, 24197723537u },
2433 { 17033060604413529717u, 16128087474216800751u, 145041530375u },
2434 { 10498418508292170054u, 16216631732633731297u, 7874305373u },
2435 { 13237752038744465016u, 13760220872779997335u, 93879105367u },
2436 { 17737618428304633155u, 3826276262374222087u, 87745943068u },
2437 { 13546183833248825736u, 14938032745839181005u, 28207422851u },
2438 { 826778452978976229u, 14479259995009508865u, 131809792377u },
2439 { 13728076626990147292u, 2372033248156102437u, 121784922257u },
2440 { 2794860281883592225u, 792005346826701645u, 145128588180u },
2441 { 8680705720425908736u, 16278924527931792559u, 148042934695u },
2442 { 731520517439488000u, 17442516423538940144u, 167882482266u },
2443 { 13120812320768917504u, 13844184233048446u, 90945560710u },
2444 { 2722954908557901824u, 13486193870480782357u, 134000750494u },
2445 { 6860847004205973504u, 11931315179184648737u, 158731088034u },
2446 { 6503197861922996224u, 16492562205587485405u, 162646797891u },
2447 { 9223372036854775808u, 12128987217680380854u, 67894063588u },
2448 { 0u, 10568123814189138176u, 228657513714u },
2449 { 0u, 17007583519117541376u, 242572899139u },
2450 { 0u, 143791533903052800u, 67921982950u },
2451 { 0u, 12398714235792654336u, 230007794954u },
2452 { 0u, 9659957317919047680u, 10672135645u },
2453 { 0u, 9412523221204336640u, 221523667335u },
2454 { 0u, 4611686018427387904u, 135510253906u },
2455 { 0u, 0u, 82250000000u },
2456 { 0u, 0u, 128000000000u },
2457 { 12005656413127238315u, 15793u, 0u },
2458 { 4821130826186787462u, 15793650827938u, 0u },
2459 { 14377899467066168118u, 3237900842885170729u, 856u },
2460 { 16575613239625444872u, 7515893506498066595u, 88175526956u },
2461 { 4317827099179284377u, 7300206309181072546u, 44407437403u },
2462 { 1242354770412171254u, 5999737279837044u, 91395744977u },
2463 { 994838588328896609u, 7556839307242450651u, 209000325246u },
2464 { 17283309862013060457u, 12946035041643640643u, 126409657079u },
2465 { 124242522249856586u, 15885877642352740665u, 247701805965u },
2466 { 11564608014666985609u, 10770818348246089568u, 141861175152u },
2467 { 12401028575581654085u, 11635415503599551744u, 112583887232u },
2468 { 2490725392961465727u, 6248053924100826098u, 128630757138u },
2469 { 1949482237120640915u, 16894170802729859998u, 18338707681u },
2470 { 15410502396166200087u, 6143589029651889899u, 225915834834u },
2471 { 15694919529799920727u, 11812087701837886160u, 210333044628u },
2472 { 10324869370171768388u, 7306705080150829180u, 148640334557u },
2473 { 1631866459122189059u, 1485332570280714274u, 221396097276u },
2474 { 172020494461226230u, 18042602303295630634u, 252080520039u },
2475 { 12734610307908856767u, 13397029889257074369u, 103978091430u },
2476 { 1467513250829340930u, 9948104869613411488u, 166726254445u },
2477 { 13558759428494307997u, 10836066241170646532u, 109539287845u },
2478 { 7915355143999496434u, 18330574781234459389u, 37587424327u },
2479 { 2876370200608797469u, 666297360208433062u, 71993702450u },
2480 { 343685370404989503u, 5035352224889324309u, 50036120052u },
2481 { 4837266557407634630u, 1341745796439923765u, 244272966991u },
2482 { 9622591415747161468u, 6846932182653803785u, 79072736185u },
2483 { 16503783814424220982u, 6727685027257825533u, 185371172937u },
2484 { 5377083431343591334u, 2168538874806877737u, 73364708536u },
2485 { 16508482371299291595u, 17694936100676971444u, 184117556727u },
2486 { 10515883558812249028u, 2163944241059563294u, 247959244408u },
2487 { 63492062913405476u, 6727780864524301558u, 120117307652u },
2488 { 11571919759617799697u, 8599551977795002615u, 4364713731u },
2489 { 2956602334970088581u, 15428264807806859091u, 3466182646u },
2490 { 13604736747717849839u, 2126771385339683557u, 246836367911u },
2491 { 16573540719338151362u, 15094316562082972944u, 39115292507u },
2492 { 12620703004601168151u, 8111300598225956802u, 91818264540u },
2493 { 14649407809089591941u, 9481215200564260304u, 220439714486u },
2494 { 11290375247898624432u, 16836674128623424708u, 182513977705u },
2495 { 11020319450292874212u, 7087243115299722740u, 105912717933u },
2496 { 8754634933362354176u, 2343560867338408810u, 109384200219u },
2497 { 12976319450332528640u, 3431385749090422286u, 27127044689u },
2498 { 17447331119627239424u, 3504545517469224582u, 81186015794u },
2499 { 3665184902673858560u, 3333759805712094227u, 50189981793u },
2500 { 12949678516038795264u, 3595183476205994775u, 97180723481u },
2501 { 72057594037927936u, 14191566632569921303u, 25194895286u },
2502 { 0u, 12917427671358095562u, 182769326368u },
2503 { 0u, 3883793922738316288u, 32700255157u },
2504 { 0u, 7857281689266421760u, 181210540890u },
2505 { 0u, 15987081651486195712u, 90425944093u },
2506 { 0u, 16827562156399525888u, 29866661432u },
2507 { 0u, 7012737938513461248u, 56912223972u },
2508 { 0u, 7385903388887613440u, 228380161285u },
2509 { 0u, 0u, 5400390625u },
2510 { 0u, 0u, 225000000000u },
2511 { 9413159735776077452u, 240991986u, 0u },
2512 { 14279163482889998017u, 240991986510288411u, 0u },
2513 { 8693044629541194274u, 14135788013842776187u, 13064201u },
2514 { 11863110253260222498u, 13284322918167594445u, 9766302603u },
2515 { 8319293368489531245u, 7264587765474046287u, 139720144588u },
2516 { 3376307525676489265u, 16176482219778368741u, 204393814091u },
2517 { 13205662254759912523u, 5401983818872095469u, 75876928858u },
2518 { 5276250334231686323u, 11208857446851049921u, 90292842129u },
2519 { 13790198520922745052u, 13794690008281035639u, 145607633379u },
2520 { 14195535250150996227u, 14519782740993303071u, 227747811643u },
2521 { 16425228796427004035u, 10885858587044789123u, 59787118999u },
2522 { 4295900841296269186u, 8710500938899914621u, 151590123576u },
2523 { 4533952595483946442u, 1284182587483102819u, 56472197202u },
2524 { 12885038019373447184u, 10346074482131502030u, 82069615677u },
2525 { 12140736240487831910u, 9429804686255246574u, 61560861821u },
2526 { 6927124077155322074u, 6412022633845121254u, 125511190736u },
2527 { 12477788342407819890u, 8892351297529018260u, 208347596443u },
2528 { 7980854329409711087u, 14098160105983060597u, 155482055329u },
2529 { 2062671021810827996u, 13793833029739474340u, 161764262790u },
2530 { 2739521363598172769u, 16367653765996977044u, 134747765186u },
2531 { 12897585686593465638u, 10684788343333772342u, 194887292288u },
2532 { 1127632646629044686u, 13272681218705145345u, 128579223536u },
2533 { 4833775019274666364u, 11093568615497829248u, 240719513490u },
2534 { 15867662672939849256u, 12488220765137758124u, 146601383559u },
2535 { 2092350330982953557u, 3727114642519696453u, 135676987804u },
2536 { 13330062299842493592u, 11549865375695057514u, 156202047289u },
2537 { 4479193352178519263u, 11292809154908783229u, 57626119456u },
2538 { 3149393938889064983u, 17723904861837310998u, 32612184410u },
2539 { 9736379904070620767u, 14877674388187150875u, 90960814807u },
2540 { 3816238703055069186u, 12178961950105734308u, 215806520344u },
2541 { 11598915938798661975u, 4540604068069253114u, 24660222850u },
2542 { 17821633264606555643u, 13832478722153359868u, 130246146639u },
2543 { 2514623558764574316u, 1308046668730371491u, 79749860174u },
2544 { 4976730480406253215u, 18400531023544756800u, 78070909351u },
2545 { 17276563697191611637u, 9789823458621466539u, 167997494785u },
2546 { 12524734095940998814u, 1924870562610267306u, 1530707393u },
2547 { 15331551308930355164u, 5290016144582400923u, 193104347442u },
2548 { 15417115581125943816u, 15162883663174059077u, 50286772349u },
2549 { 6010750237807115593u, 8078086116520046390u, 125821981570u },
2550 { 5624630987553628432u, 15731407332173190623u, 130437913925u },
2551 { 14881848243837640704u, 5346389182763011056u, 69852801300u },
2552 { 15281613886881529856u, 6368422217216252401u, 20289828338u },
2553 { 14057902358273196032u, 2961453088119116188u, 242345232860u },
2554 { 16075318494433902592u, 10932141691610170525u, 220160540693u },
2555 { 13891916000577716224u, 11034016191361782553u, 21592632588u },
2556 { 7205759403792793600u, 5455325785621453219u, 12598155216u },
2557 { 0u, 7735615202566149352u, 208295733803u },
2558 { 0u, 7502396497775759360u, 43419348540u },
2559 { 0u, 1601286435751591936u, 60406705729u },
2560 { 0u, 11449383158571597824u, 65086805911u },
2561 { 0u, 13043944595690356736u, 151620672304u },
2562 { 0u, 7773494431818186752u, 48707113653u },
2563 { 0u, 9943947977234055168u, 181421401977u },
2564 { 0u, 0u, 121539062500u },
2565 { 0u, 0u, 228000000000u },
2566 { 4535831408134330609u, 3677u, 0u },
2567 { 6204770794376564579u, 3677245887913u, 0u },
2568 { 13869812122751887467u, 6343817245135589714u, 199u },
2569 { 14253229412394467550u, 17549323075660516085u, 199343899021u },
2570 { 12776557610216045332u, 3948641822109421754u, 141951350710u },
2571 { 16493640728678654060u, 1750739713693534543u, 182214056302u },
2572 { 9434398296825833151u, 962163898128633415u, 110094907790u },
2573 { 8773374058285327850u, 7967320249386531212u, 142052159009u },
2574 { 12932015276748029367u, 3018466665533383224u, 33431909296u },
2575 { 16293958583527755209u, 15076865731854945472u, 176163631405u },
2576 { 13511893936143127948u, 691187172844604400u, 45817318529u },
2577 { 18409936402005226436u, 13274492813370992341u, 129037469331u },
2578 { 2189663026458466887u, 6364168818499152300u, 147719611697u },
2579 { 9497725274248154664u, 17599380787401914158u, 49345002282u },
2580 { 14766925481127792125u, 3782323149461692814u, 42954064344u },
2581 { 6982373971809635814u, 14470163442442237466u, 216205040148u },
2582 { 8616702383006884794u, 476109872130437939u, 20784429132u },
2583 { 3059473300040871066u, 16330548844673355700u, 76025809967u },
2584 { 17123843157031495558u, 14089158961463739563u, 47885280826u },
2585 { 11210627174210626524u, 13385510793074798805u, 58763774837u },
2586 { 15868067138625928592u, 1549401308746959012u, 117725629994u },
2587 { 4467869511636937589u, 4607384943843027435u, 42083993213u },
2588 { 10052108125844341766u, 5157353797716093483u, 125249766838u },
2589 { 7470588003218451534u, 10846828782671550129u, 182279580709u },
2590 { 2613527085490786280u, 9915857350819131531u, 37588007766u },
2591 { 3632919450036549616u, 1673544973504317923u, 86537539704u },
2592 { 179367907231218916u, 14780986291622785694u, 120090723054u },
2593 { 13553068184555874624u, 8168111319515466401u, 238801278872u },
2594 { 8798774862365584481u, 16345760387859734482u, 152442794201u },
2595 { 910911255817064881u, 3177475373321281805u, 217886105446u },
2596 { 2304331144765093813u, 2558676822419554038u, 102172251285u },
2597 { 12248937023083640360u, 8813474062662382873u, 149138706148u },
2598 { 10206039550662130685u, 5426294560236228430u, 228477779386u },
2599 { 12267881323837852537u, 9919177474128333040u, 186294160017u },
2600 { 2858642007937891971u, 6197383943089627371u, 145537719688u },
2601 { 14171330289750320841u, 13673239314867423997u, 136335960856u },
2602 { 6601103619749017720u, 9309584098968723946u, 24741227788u },
2603 { 4919573414486739494u, 4647101757759615504u, 12504673565u },
2604 { 3401998285294974486u, 1405809295505096753u, 29251919891u },
2605 { 10799436256515532233u, 11332704079573859112u, 19076209074u },
2606 { 10083786644665753398u, 2960072434514044308u, 178614347119u },
2607 { 6481194517685688896u, 3887266602785432801u, 111160465848u },
2608 { 15104161756860547072u, 14545546084687849554u, 184210729144u },
2609 { 9556039274244079616u, 4617763804182385321u, 184788515633u },
2610 { 1376343134954323968u, 7857823815580249095u, 49250329477u },
2611 { 15682488278596976640u, 10939326736548364798u, 133425973482u },
2612 { 1506454075355430912u, 12262012446566951953u, 234593022090u },
2613 { 1152921504606846976u, 12555024338687723023u, 138664725026u },
2614 { 0u, 3332969632922829472u, 34680609233u },
2615 { 0u, 15535060143360327680u, 209180680645u },
2616 { 0u, 15794322927987458048u, 197842157297u },
2617 { 0u, 10571474314433921024u, 241856211961u },
2618 { 0u, 16679514427547975680u, 249573080770u },
2619 { 0u, 16925653299565166592u, 194904198288u },
2620 { 0u, 16717361816799281152u, 144917541503u },
2621 { 0u, 0u, 127906250000u },
2622 { 0u, 0u, 16000000000u },
2623 { 6172559441576707976u, 56110319u, 0u },
2624 { 15083329738554729992u, 56110319334615117u, 0u },
2625 { 10013126833549229036u, 9335385384027907407u, 3041746u },
2626 { 5817156823499936061u, 13237828406194798613u, 210506072255u },
2627 { 5282692560913632718u, 15667486867836528863u, 191717624115u },
2628 { 10252307034225766362u, 17982325043592934313u, 51849336164u },
2629 { 17981881283247669689u, 17159117626917379189u, 100974823793u },
2630 { 11689290159733383293u, 8336208968408929657u, 113930197630u },
2631 { 5530668968487988249u, 12767090573379150201u, 126451906793u },
2632 { 10083765740821947024u, 14736070002412246709u, 233692105366u },
2633 { 2798423656816843533u, 9697296975344560756u, 150798843955u },
2634 { 7614494481582904797u, 7291706381199103298u, 51525691522u },
2635 { 17811318500083423695u, 18098546597780825068u, 130395284194u },
2636 { 11641467412200329033u, 132913902678533478u, 226981124177u },
2637 { 17733593025296340645u, 1879347741692007580u, 81007205277u },
2638 { 3689424000190644835u, 4056624629214083684u, 157101879645u },
2639 { 14966634145516728506u, 14713227692042795499u, 93219910061u },
2640 { 14171681941562070109u, 7366415124022528526u, 173797605671u },
2641 { 8130575762882608170u, 825770353378039393u, 39399334164u },
2642 { 5234550794400656856u, 10244023944395357795u, 20044765100u },
2643 { 3020576149360486378u, 14302658294713551167u, 172555329650u },
2644 { 3038675756589057221u, 14246653166206862817u, 114775348659u },
2645 { 15470260187120878369u, 12404486258134291102u, 179772312615u },
2646 { 3497929414841828746u, 8887442218637942533u, 39672448547u },
2647 { 9935840636861015305u, 1186724038081863005u, 35481789208u },
2648 { 3647355485153741471u, 211331772484951576u, 24064332439u },
2649 { 766100215038272793u, 6311919513247413649u, 151011456318u },
2650 { 16128087474216800751u, 8131780018703965703u, 62342169842u },
2651 { 16216631732633731297u, 2262544347226725725u, 242440824678u },
2652 { 13760220872779997335u, 15318188749880522583u, 102122652774u },
2653 { 3826276262374222087u, 1073117094162650652u, 102830400676u },
2654 { 14938032745839181005u, 4447950380665871747u, 164058173794u },
2655 { 14479259995009508865u, 5373227185066463609u, 98241123873u },
2656 { 2372033248156102437u, 6739731406934274193u, 33291283229u },
2657 { 792005346826701645u, 12328812617001239444u, 29365361571u },
2658 { 16278924527931792559u, 3246111484407310759u, 163668346271u },
2659 { 17442516423538940144u, 3250825415176839770u, 159175972056u },
2660 { 13844184233048446u, 16146270540000862342u, 216176227598u },
2661 { 13486193870480782357u, 15686773375425916830u, 14875291079u },
2662 { 11931315179184648737u, 11920791905793880226u, 199850381688u },
2663 { 16492562205587485405u, 1853290561644080707u, 120646227424u },
2664 { 12128987217680380854u, 12157689141506159076u, 224100467082u },
2665 { 10568123814189138176u, 18100318838862562546u, 138659069648u },
2666 { 17007583519117541376u, 7171257882533475139u, 208981220250u },
2667 { 143791533903052800u, 14477550873015039462u, 154388754668u },
2668 { 12398714235792654336u, 8109481182495403274u, 236784829605u },
2669 { 9659957317919047680u, 14565395719337663965u, 165439615855u },
2670 { 9412523221204336640u, 1860318978161305991u, 111789591684u },
2671 { 4611686018427387904u, 16268646275151585618u, 132100848093u },
2672 { 0u, 13759019338835519104u, 221881925081u },
2673 { 0u, 17003783176010661888u, 217745877932u },
2674 { 0u, 18357489540307877888u, 172921776932u },
2675 { 0u, 905481790074912768u, 36995161502u },
2676 { 0u, 3638882110636294144u, 158049086266u },
2677 { 0u, 9011702854368362496u, 58197264194u },
2678 { 0u, 11529215046068469760u, 66488525390u },
2679 { 0u, 0u, 78625000000u },
2680 { 0u, 0u, 64000000000u },
2681 { 3237900842885170729u, 856u, 0u },
2682 { 7515893506498066595u, 856175526956u, 0u },
2683 { 7300206309181072546u, 7625299565768063067u, 46u },
2684 { 5999737279837044u, 13889021769065194705u, 46413368317u },
2685 { 7556839307242450651u, 14498170692313014398u, 253752925378u },
2686 { 12946035041643640643u, 1541631360972245751u, 194785947408u },
2687 { 15885877642352740665u, 9903958882920799117u, 16083572003u },
2688 { 10770818348246089568u, 15744148547788062576u, 35536894686u },
2689 { 11635415503599551744u, 17936061801321712000u, 222853492002u },
2690 { 6248053924100826098u, 9986394078324430610u, 34972315858u },
2691 { 16894170802729859998u, 13849561248103430369u, 210541363507u },
2692 { 6143589029651889899u, 12142378807953854930u, 51750786219u },
2693 { 11812087701837886160u, 2513847703931031444u, 171658239674u },
2694 { 7306705080150829180u, 1752183758129038045u, 186136275957u },
2695 { 1485332570280714274u, 15824833342220556540u, 245094986071u },
2696 { 18042602303295630634u, 8168747198299470695u, 87857865934u },
2697 { 13397029889257074369u, 17414799840149357478u, 206442828672u },
2698 { 9948104869613411488u, 83147520704167789u, 128944058191u },
2699 { 10836066241170646532u, 2383542703041471269u, 79004507436u },
2700 { 18330574781234459389u, 15540952725549257799u, 44129212108u },
2701 { 666297360208433062u, 6949835416232048690u, 204842476735u },
2702 { 5035352224889324309u, 15398868937585367540u, 191376751332u },
2703 { 1341745796439923765u, 14710915985268256079u, 228834774357u },
2704 { 6846932182653803785u, 9665704836873335737u, 85797480353u },
2705 { 6727685027257825533u, 2528789298740305993u, 161523978909u },
2706 { 2168538874806877737u, 10562914675687726264u, 157137085942u },
2707 { 17694936100676971444u, 17671658300096837111u, 246572616751u },
2708 { 2163944241059563294u, 356471401631698552u, 47957982516u },
2709 { 6727780864524301558u, 7450677157218003204u, 52019324353u },
2710 { 8599551977795002615u, 317174560787152643u, 193403902018u },
2711 { 15428264807806859091u, 7251937674440720374u, 66017194067u },
2712 { 2126771385339683557u, 1252631516699038247u, 83393128329u },
2713 { 15094316562082972944u, 10818009768860843867u, 137067905290u },
2714 { 8111300598225956802u, 12330114194950162396u, 10586445484u },
2715 { 9481215200564260304u, 15826681638261168822u, 172668416829u },
2716 { 16836674128623424708u, 14240150078499211625u, 61857966130u },
2717 { 7087243115299722740u, 10725372116242125421u, 50771960082u },
2718 { 2343560867338408810u, 8434925524647833627u, 18581423587u },
2719 { 3431385749090422286u, 17133902668520348241u, 227457258228u },
2720 { 3504545517469224582u, 15093996047981365810u, 244928830724u },
2721 { 3333759805712094227u, 6187974166976813153u, 4818247165u },
2722 { 3595183476205994775u, 13946144707720259865u, 253335450751u },
2723 { 14191566632569921303u, 9138079832881862582u, 127756022019u },
2724 { 12917427671358095562u, 6600697628576225568u, 3495376300u },
2725 { 3883793922738316288u, 8137099536646556597u, 172357824535u },
2726 { 7857281689266421760u, 14169855543453903706u, 23441113049u },
2727 { 15987081651486195712u, 3706403268650100765u, 217768149408u },
2728 { 16827562156399525888u, 14736932266877982264u, 160200924523u },
2729 { 7012737938513461248u, 18004795125138956004u, 107798890698u },
2730 { 7385903388887613440u, 9068489270661002501u, 202976041899u },
2731 { 0u, 7758835715193269217u, 171491603788u },
2732 { 0u, 16943947811135261184u, 76420607326u },
2733 { 0u, 6745843108403216384u, 94918533251u },
2734 { 0u, 12338229654069444608u, 131365692887u },
2735 { 0u, 14358176069683511296u, 215668856769u },
2736 { 0u, 7083775185760813056u, 193778358284u },
2737 { 0u, 5350276357316149248u, 12384012222u },
2738 { 0u, 9223372036854775808u, 190290039062u },
2739 { 0u, 0u, 22500000000u },
2740 { 14135788013842776187u, 13064201u, 0u },
2741 { 13284322918167594445u, 13064201766302603u, 0u },
2742 { 7264587765474046287u, 14699116688460625612u, 708211u },
2743 { 16176482219778368741u, 6684126021499623499u, 115796840712u },
2744 { 5401983818872095469u, 12614606079692508506u, 8362347197u },
2745 { 11208857446851049921u, 15358270276683001489u, 189683839165u },
2746 { 13794690008281035639u, 18077126190953408995u, 189832573499u },
2747 { 14519782740993303071u, 7864121581925945659u, 59979962974u },
2748 { 10885858587044789123u, 3518026639210514839u, 94426314885u },
2749 { 8710500938899914621u, 4698310163811252280u, 133190712606u },
2750 { 1284182587483102819u, 6101155398200416338u, 30254695904u },
2751 { 10346074482131502030u, 16049178580360033341u, 224330744296u },
2752 { 9429804686255246574u, 3167464649127375997u, 232870027714u },
2753 { 6412022633845121254u, 12778923935480989904u, 194171708602u },
2754 { 8892351297529018260u, 11875553912612980379u, 186692746854u },
2755 { 14098160105983060597u, 10628760849351697057u, 102643775067u },
2756 { 13793833029739474340u, 3408944711673234310u, 91576186280u },
2757 { 16367653765996977044u, 2102091496050506178u, 168184799263u },
2758 { 10684788343333772342u, 6254611118630245760u, 31113954608u },
2759 { 13272681218705145345u, 2647941151989776368u, 48339063148u },
2760 { 11093568615497829248u, 8855437735410157458u, 108143545177u },
2761 { 12488220765137758124u, 10184270603132180103u, 89480054241u },
2762 { 3727114642519696453u, 12079083162535627164u, 225552090415u },
2763 { 11549865375695057514u, 5952952868716156729u, 47654808410u },
2764 { 11292809154908783229u, 11958907037815852320u, 90322710221u },
2765 { 17723904861837310998u, 10101562137321697626u, 205648293649u },
2766 { 14877674388187150875u, 13633527411279258327u, 17547606780u },
2767 { 12178961950105734308u, 16555627393501768728u, 252739075001u },
2768 { 4540604068069253114u, 6359650463500280706u, 185897482359u },
2769 { 13832478722153359868u, 8093923611102181967u, 119344757342u },
2770 { 1308046668730371491u, 2848827352928635726u, 94438772478u },
2771 { 18400531023544756800u, 4686723431961561511u, 254154435240u },
2772 { 9789823458621466539u, 6245554925867652609u, 168254067786u },
2773 { 1924870562610267306u, 17527406820792516033u, 74338572210u },
2774 { 5290016144582400923u, 12119966834653692210u, 178950162627u },
2775 { 15162883663174059077u, 11606502845877928061u, 195657024718u },
2776 { 8078086116520046390u, 424311496652297090u, 206629189780u },
2777 { 15731407332173190623u, 5977664048034127173u, 148023001972u },
2778 { 5346389182763011056u, 6702712461535947028u, 116324049817u },
2779 { 6368422217216252401u, 11384349854055020018u, 153363354770u },
2780 { 2961453088119116188u, 3782955013294836188u, 146617146842u },
2781 { 10932141691610170525u, 3531805968821207061u, 218205074402u },
2782 { 11034016191361782553u, 3867566898657193228u, 226191459585u },
2783 { 5455325785621453219u, 12688734637425072080u, 1209661221u },
2784 { 7735615202566149352u, 18435982764454619691u, 37687857682u },
2785 { 7502396497775759360u, 4728836163964677692u, 18999416628u },
2786 { 1601286435751591936u, 2120012917348838977u, 52256350722u },
2787 { 11449383158571597824u, 9856965465824679831u, 2114926130u },
2788 { 13043944595690356736u, 11217197671061248816u, 50534347168u },
2789 { 7773494431818186752u, 3840562972677739189u, 160608085504u },
2790 { 9943947977234055168u, 17104366978925258617u, 208197335u },
2791 { 0u, 16177877219841993444u, 215927229591u },
2792 { 0u, 7338522384267208704u, 151877004481u },
2793 { 0u, 10935240458612244480u, 193397822095u },
2794 { 0u, 1732868046462124032u, 143592800573u },
2795 { 0u, 557965042578882560u, 61093938965u },
2796 { 0u, 10454684322475540480u, 21030247345u },
2797 { 0u, 13907115649320091648u, 177566749572u },
2798 { 0u, 0u, 132753906250u },
2799 { 0u, 0u, 74000000000u },
2800 { 6343817245135589714u, 199u, 0u },
2801 { 17549323075660516085u, 199343899021u, 0u },
2802 { 3948641822109421754u, 14876458284855834550u, 10u },
2803 { 1750739713693534543u, 10450704926982265198u, 10806454419u },
2804 { 962163898128633415u, 5385653213018257806u, 147566533849u },
2805 { 7967320249386531212u, 12735569669880147489u, 217291956845u },
2806 { 3018466665533383224u, 3619762560577729456u, 109690396615u },
2807 { 15076865731854945472u, 11123448126624084269u, 199196227721u },
2808 { 691187172844604400u, 4072715118852885633u, 137603003331u },
2809 { 13274492813370992341u, 18239087231420827283u, 195220782328u },
2810 { 6364168818499152300u, 423431461216085297u, 248988742900u },
2811 { 17599380787401914158u, 9360976716520160042u, 244022954265u },
2812 { 3782323149461692814u, 11655927117263208920u, 25507459564u },
2813 { 14470163442442237466u, 2646622721938364948u, 236631869075u },
2814 { 476109872130437939u, 4496462484548171852u, 147143473705u },
2815 { 16330548844673355700u, 13140258519803350063u, 41243753719u },
2816 { 14089158961463739563u, 13089764333320627770u, 247712334841u },
2817 { 13385510793074798805u, 6926286827289840501u, 249709597546u },
2818 { 1549401308746959012u, 4985580225290866218u, 106375474761u },
2819 { 4607384943843027435u, 10478790837359789693u, 73270268845u },
2820 { 5157353797716093483u, 10041191967455692214u, 173568056389u },
2821 { 10846828782671550129u, 5035461258013813797u, 69544334107u },
2822 { 9915857350819131531u, 14208759661559249750u, 27272972901u },
2823 { 1673544973504317923u, 12347272163241758840u, 101770258404u },
2824 { 14780986291622785694u, 3372534174410277614u, 228669346965u },
2825 { 8168111319515466401u, 17226704187274712984u, 149182825443u },
2826 { 16345760387859734482u, 4250480179449852121u, 227933861505u },
2827 { 3177475373321281805u, 4303723537755414374u, 129230418992u },
2828 { 2558676822419554038u, 8680503847344854165u, 48233305320u },
2829 { 8813474062662382873u, 8817608623911079652u, 232470571056u },
2830 { 5426294560236228430u, 5692030448698539450u, 48478003521u },
2831 { 9919177474128333040u, 16908836314686769809u, 65308565588u },
2832 { 6197383943089627371u, 6073762347067727240u, 84916629853u },
2833 { 13673239314867423997u, 10931066692585106200u, 93329259316u },
2834 { 9309584098968723946u, 14466591364061539596u, 52592574312u },
2835 { 4647101757759615504u, 4958077340960173341u, 104784235489u },
2836 { 1405809295505096753u, 4076890037156765715u, 225268777911u },
2837 { 11332704079573859112u, 14083973146609179058u, 183221008651u },
2838 { 2960072434514044308u, 2565183738039805295u, 11763493714u },
2839 { 3887266602785432801u, 1482420938751351224u, 82139058889u },
2840 { 14545546084687849554u, 2151089495335413944u, 201080362200u },
2841 { 4617763804182385321u, 3738604531753220913u, 216116610795u },
2842 { 7857823815580249095u, 14195686514836005765u, 235202670157u },
2843 { 10939326736548364798u, 17808833916231796970u, 77769549707u },
2844 { 12262012446566951953u, 1302384553035657354u, 139965418821u },
2845 { 12555024338687723023u, 1672033517974833698u, 69070602408u },
2846 { 3332969632922829472u, 11673925532927662545u, 168090641118u },
2847 { 15535060143360327680u, 3905334232240480709u, 222632844771u },
2848 { 15794322927987458048u, 17411087320267472625u, 227211708592u },
2849 { 10571474314433921024u, 16573305231063706617u, 176943856934u },
2850 { 16679514427547975680u, 15481103236037148354u, 38898440676u },
2851 { 16925653299565166592u, 907440704754420880u, 228839232288u },
2852 { 16717361816799281152u, 3224970785139077759u, 32049192459u },
2853 { 0u, 10560826509734608144u, 11174826016u },
2854 { 0u, 4700940027512659968u, 32572503552u },
2855 { 0u, 9733694683502084096u, 254838469u },
2856 { 0u, 1995535635724632064u, 197527664646u },
2857 { 0u, 10629833226245373952u, 6108178203u },
2858 { 0u, 15729384648544878592u, 27576244413u },
2859 { 0u, 7205759403792793600u, 189852691650u },
2860 { 0u, 0u, 194390625000u },
2861 { 0u, 0u, 232000000000u },
2862 { 9335385384027907407u, 3041746u, 0u },
2863 { 13237828406194798613u, 3041746506072255u, 0u },
2864 { 15667486867836528863u, 7535526066623007027u, 164893u },
2865 { 17982325043592934313u, 11302146918409311588u, 29408501686u },
2866 { 17159117626917379189u, 2480833299122194801u, 182612690612u },
2867 { 8336208968408929657u, 11513226205589330558u, 180134486242u },
2868 { 12767090573379150201u, 4073957068281936105u, 226624133243u },
2869 { 14736070002412246709u, 3729887061093812886u, 123220849655u },
2870 { 9697296975344560756u, 13616911779739451443u, 247202197582u },
2871 { 7291706381199103298u, 13039053282195777666u, 78738174266u },
2872 { 18098546597780825068u, 14490756113210417890u, 58706848494u },
2873 { 132913902678533478u, 17432486112977557585u, 238785545462u },
2874 { 1879347741692007580u, 14308820825344039837u, 246945016965u },
2875 { 4056624629214083684u, 4190949538817536349u, 133775682731u },
2876 { 14713227692042795499u, 13616552502810964397u, 171227191829u },
2877 { 7366415124022528526u, 4898145803694965031u, 21738154790u },
2878 { 825770353378039393u, 1399036321001644308u, 38265529016u },
2879 { 10244023944395357795u, 17170331128243738540u, 184075841910u },
2880 { 14302658294713551167u, 10641321388205367410u, 118930805515u },
2881 { 14246653166206862817u, 6648873641312572851u, 11576867188u },
2882 { 12404486258134291102u, 5988456964560374823u, 116360436162u },
2883 { 8887442218637942533u, 9972593758348346915u, 194324634902u },
2884 { 1186724038081863005u, 16709668921872818968u, 22540615390u },
2885 { 211331772484951576u, 6094829131503407767u, 222905832967u },
2886 { 6311919513247413649u, 4892016478899926334u, 7330401349u },
2887 { 8131780018703965703u, 13150857244079031538u, 69265196744u },
2888 { 2262544347226725725u, 12983943395318785894u, 200712909399u },
2889 { 15318188749880522583u, 15341644584614757478u, 87703860981u },
2890 { 1073117094162650652u, 7507635124856644772u, 245831672219u },
2891 { 4447950380665871747u, 11619655367084544354u, 155406989715u },
2892 { 5373227185066463609u, 11553116952478783009u, 147629902779u },
2893 { 6739731406934274193u, 17392150014233193245u, 187626295724u },
2894 { 12328812617001239444u, 8877887560294980515u, 172942830341u },
2895 { 3246111484407310759u, 18404180619915609503u, 5481271248u },
2896 { 3250825415176839770u, 10079413095288181976u, 208997692630u },
2897 { 16146270540000862342u, 14102802966539105550u, 214546406078u },
2898 { 15686773375425916830u, 13333966026135891399u, 190764514480u },
2899 { 11920791905793880226u, 12344968670173516152u, 176722835746u },
2900 { 1853290561644080707u, 10577007819804726752u, 34669222092u },
2901 { 12157689141506159076u, 15337041354031088010u, 204573380742u },
2902 { 18100318838862562546u, 14333607285614673616u, 134831422677u },
2903 { 7171257882533475139u, 17171597563219696538u, 213777026407u },
2904 { 14477550873015039462u, 2849642930482147564u, 103930874169u },
2905 { 8109481182495403274u, 14791248423979435173u, 57154479452u },
2906 { 14565395719337663965u, 13882371364576310127u, 92801835183u },
2907 { 1860318978161305991u, 11735995808941329540u, 175752564859u },
2908 { 16268646275151585618u, 11376996674339273181u, 123636209607u },
2909 { 13759019338835519104u, 9849638057168043481u, 199616748225u },
2910 { 17003783176010661888u, 18241520229279361964u, 193533949948u },
2911 { 18357489540307877888u, 1865852368526961444u, 252988874793u },
2912 { 905481790074912768u, 10601487369276448158u, 41101148059u },
2913 { 3638882110636294144u, 15999931310312762170u, 155574707781u },
2914 { 9011702854368362496u, 5773775867713013570u, 69867358014u },
2915 { 11529215046068469760u, 17726239863982547534u, 62312997016u },
2916 { 0u, 9711316695888316992u, 152960941388u },
2917 { 0u, 17872002620723724288u, 76526451532u },
2918 { 0u, 7429694208660733952u, 76968843203u },
2919 { 0u, 1782821038871019520u, 195402764530u },
2920 { 0u, 3225250234313474048u, 242096646922u },
2921 { 0u, 10009250171830927360u, 10174841165u },
2922 { 0u, 1152921504606846976u, 77542602539u },
2923 { 0u, 0u, 43062500000u },
2924 { 0u, 0u, 160000000000u },
2925 { 7625299565768063067u, 46u, 0u },
2926 { 13889021769065194705u, 46413368317u, 0u },
2927 { 14498170692313014398u, 9519880170333822146u, 2u },
2928 { 1541631360972245751u, 2285186318012886800u, 2516073738u },
2929 { 9903958882920799117u, 9706420951402272035u, 10123880198u },
2930 { 15744148547788062576u, 2369632031840402142u, 6526186134u },
2931 { 17936061801321712000u, 15599123897979399458u, 150128458009u },
2932 { 9986394078324430610u, 17579576584023912658u, 25845630200u },
2933 { 13849561248103430369u, 3480927339588501811u, 248952990756u },
2934 { 12142378807953854930u, 3547346616671294635u, 36188701449u },
2935 { 2513847703931031444u, 7705317123868384954u, 9192302045u },
2936 { 1752183758129038045u, 4969425237478353909u, 221417706078u },
2937 { 15824833342220556540u, 17043246700132217175u, 94269393081u },
2938 { 8168747198299470695u, 17053788362783499470u, 185923916254u },
2939 { 17414799840149357478u, 11102988228454224768u, 222924487719u },
2940 { 83147520704167789u, 16944305387801685839u, 39601894197u },
2941 { 2383542703041471269u, 11725142977459199276u, 53918552635u },
2942 { 15540952725549257799u, 8175984171998533324u, 59635621274u },
2943 { 6949835416232048690u, 1372352885142856895u, 154443220990u },
2944 { 15398868937585367540u, 17975093466502888164u, 254074395398u },
2945 { 14710915985268256079u, 6467823391459085653u, 6974431769u },
2946 { 9665704836873335737u, 11319386883146885025u, 25350621408u },
2947 { 2528789298740305993u, 9141999262922068637u, 224613625192u },
2948 { 10562914675687726264u, 1587330393383478774u, 104495588773u },
2949 { 17671658300096837111u, 884187548095712303u, 165086049353u },
2950 { 356471401631698552u, 488841225726377268u, 73047931903u },
2951 { 7450677157218003204u, 17462624199405856193u, 255026500135u },
2952 { 317174560787152643u, 13183677579115583554u, 39946650754u },
2953 { 7251937674440720374u, 11645015818917277779u, 130714688593u },
2954 { 1252631516699038247u, 8760523002035971977u, 81631277572u },
2955 { 10818009768860843867u, 10068817678491468042u, 4474908903u },
2956 { 12330114194950162396u, 1273658177787418284u, 231545831700u },
2957 { 15826681638261168822u, 3100019384328057661u, 20069045148u },
2958 { 14240150078499211625u, 10363063568089458738u, 156168052387u },
2959 { 10725372116242125421u, 13030756371481403666u, 163561782801u },
2960 { 8434925524647833627u, 6538878900684195299u, 17706398718u },
2961 { 17133902668520348241u, 8984884716779098868u, 254354473335u },
2962 { 15093996047981365810u, 8728727397070363908u, 119487071576u },
2963 { 6187974166976813153u, 6398650562917867005u, 88473185260u },
2964 { 13946144707720259865u, 1190873176164938879u, 236346871542u },
2965 { 9138079832881862582u, 4383628525805121795u, 246064557364u },
2966 { 6600697628576225568u, 10189374699734119852u, 52237636978u },
2967 { 8137099536646556597u, 5276291920541626391u, 114552367109u },
2968 { 14169855543453903706u, 2692252373800386521u, 5286028358u },
2969 { 3706403268650100765u, 11578684995169173920u, 70145947293u },
2970 { 14736932266877982264u, 5799408022254132587u, 157627681771u },
2971 { 18004795125138956004u, 15548569837712345290u, 235314386538u },
2972 { 9068489270661002501u, 15763030464322902955u, 106842889659u },
2973 { 7758835715193269217u, 13257749746581255500u, 187854515593u },
2974 { 16943947811135261184u, 16152470009188707678u, 137718704053u },
2975 { 6745843108403216384u, 13806790848493904003u, 181875627153u },
2976 { 12338229654069444608u, 11981226523265951191u, 145748467631u },
2977 { 14358176069683511296u, 5133628726077003713u, 175649503591u },
2978 { 7083775185760813056u, 16183955741910833164u, 103278294570u },
2979 { 5350276357316149248u, 13640425554331371454u, 42877333998u },
2980 { 9223372036854775808u, 18108120906868035862u, 238739448950u },
2981 { 0u, 6324011669895037184u, 118981643201u },
2982 { 0u, 10444437689515769856u, 193342825359u },
2983 { 0u, 12324712543665782784u, 143566194101u },
2984 { 0u, 13928941951563857920u, 181668124005u },
2985 { 0u, 3975288688270639104u, 101755089456u },
2986 { 0u, 11141905478114607104u, 48215500831u },
2987 { 0u, 4611686018427387904u, 31604003906u },
2988 { 0u, 0u, 66250000000u },
2989 { 0u, 0u, 128000000000u },
2990 { 14699116688460625612u, 708211u, 0u },
2991 { 6684126021499623499u, 708211796840712u, 0u },
2992 { 12614606079692508506u, 4398362855256705725u, 38392u },
2993 { 15358270276683001489u, 2812083125569302717u, 248238435728u },
2994 { 18077126190953408995u, 12868509142973100603u, 144152443331u },
2995 { 7864121581925945659u, 8726243776748165726u, 195697603278u },
2996 { 3518026639210514839u, 358304413426858117u, 206473050623u },
2997 { 4698310163811252280u, 3180720351566429470u, 255019423721u },
2998 { 6101155398200416338u, 14053818240400098784u, 233172427195u },
2999 { 16049178580360033341u, 7340140541492429288u, 187761859013u },
3000 { 3167464649127375997u, 1323571167904965058u, 197397909816u },
3001 { 12778923935480989904u, 14463851737583396026u, 56071750936u },
3002 { 11875553912612980379u, 15122784818916048486u, 24784086973u },
3003 { 10628760849351697057u, 13557974621377508955u, 189819807807u },
3004 { 3408944711673234310u, 17525172074563876264u, 63734979276u },
3005 { 2102091496050506178u, 15148880683074215967u, 204950041481u },
3006 { 6254611118630245760u, 6744828147558597936u, 137821222467u },
3007 { 2647941151989776368u, 9799290779647971692u, 67365637866u },
3008 { 8855437735410157458u, 11170890203898678105u, 234531220617u },
3009 { 10184270603132180103u, 7068779781287527905u, 137605575171u },
3010 { 12079083162535627164u, 14474741922505540911u, 3383199319u },
3011 { 5952952868716156729u, 17107062680405191514u, 87784677331u },
3012 { 11958907037815852320u, 2712598571300237005u, 211927375726u },
3013 { 10101562137321697626u, 3767556054903418641u, 110147050263u },
3014 { 13633527411279258327u, 18158239681706277628u, 23204239622u },
3015 { 16555627393501768728u, 10531652712128330681u, 6984360145u },
3016 { 6359650463500280706u, 9548395326934120567u, 209570922037u },
3017 { 8093923611102181967u, 15875647850297719390u, 53517619547u },
3018 { 2848827352928635726u, 8215825295203192574u, 91860620594u },
3019 { 4686723431961561511u, 12747310908260543144u, 50445380781u },
3020 { 6245554925867652609u, 77706528053613642u, 173691033109u },
3021 { 17527406820792516033u, 6024737704056756146u, 21004212479u },
3022 { 12119966834653692210u, 6819452388570089667u, 255326601685u },
3023 { 11606502845877928061u, 13695926775373186254u, 213369683254u },
3024 { 424311496652297090u, 3746531715392682132u, 54742457678u },
3025 { 5977664048034127173u, 4717376233154528116u, 78203099891u },
3026 { 6702712461535947028u, 385190957950313369u, 243255729478u },
3027 { 11384349854055020018u, 12388374310648616082u, 70020881243u },
3028 { 3782955013294836188u, 1078067332084407770u, 91671575117u },
3029 { 3531805968821207061u, 3257295319358714850u, 77058442147u },
3030 { 3867566898657193228u, 1545453099660723457u, 163176578333u },
3031 { 12688734637425072080u, 7495477664653506341u, 29083779180u },
3032 { 18435982764454619691u, 7225503732673614354u, 108406330658u },
3033 { 4728836163964677692u, 3935478326103643956u, 34391695342u },
3034 { 2120012917348838977u, 10082240682742686210u, 238213342707u },
3035 { 9856965465824679831u, 10838712705567897138u, 243546559362u },
3036 { 11217197671061248816u, 2142546572501643680u, 130587567793u },
3037 { 3840562972677739189u, 7893042119150331392u, 177116147682u },
3038 { 17104366978925258617u, 12084811642251302615u, 226427882670u },
3039 { 16177877219841993444u, 15317234482572954775u, 174655118951u },
3040 { 7338522384267208704u, 2283226355108359361u, 103830348945u },
3041 { 10935240458612244480u, 13359725152575722127u, 145123773948u },
3042 { 1732868046462124032u, 13126551011491594557u, 252724232151u },
3043 { 557965042578882560u, 3598021288691861269u, 215711591756u },
3044 { 10454684322475540480u, 16462621795896662961u, 76195049124u },
3045 { 13907115649320091648u, 14682112756964627332u, 164892440515u },
3046 { 0u, 7174112100896070218u, 195795918927u },
3047 { 0u, 5023109019590616064u, 79388909396u },
3048 { 0u, 10765223023086141440u, 84272303285u },
3049 { 0u, 8228137177297453056u, 181583583909u },
3050 { 0u, 2891199497780592640u, 165446048210u },
3051 { 0u, 15294857653247803392u, 210156732238u },
3052 { 0u, 14303432416528695296u, 78829135894u },
3053 { 0u, 0u, 22775390625u },
3054 { 0u, 0u, 161000000000u },
3055 { 14876458284855834550u, 10u, 0u },
3056 { 10450704926982265198u, 10806454419u, 0u },
3057 { 5385653213018257806u, 10806454419566533849u, 0u },
3058 { 12735569669880147489u, 17118225092618494573u, 585819067u },
3059 { 3619762560577729456u, 13385738875341807559u, 187927980841u },
3060 { 11123448126624084269u, 8272682717439277193u, 41725642358u },
3061 { 4072715118852885633u, 13402436483369350083u, 118448463028u },
3062 { 18239087231420827283u, 10946328903241612536u, 180726547537u },
3063 { 423431461216085297u, 16265808923426731252u, 81593401678u },
3064 { 9360976716520160042u, 11080374459871185177u, 78881771268u },
3065 { 11655927117263208920u, 1240761893433831916u, 4600668303u },
3066 { 2646622721938364948u, 367264070493390483u, 143067261837u },
3067 { 4496462484548171852u, 2863675693461092905u, 141019909425u },
3068 { 13140258519803350063u, 7511929581752138999u, 49155240170u },
3069 { 13089764333320627770u, 11154557789993845753u, 234407222518u },
3070 { 6926286827289840501u, 8325416539745948522u, 246604689789u },
3071 { 4985580225290866218u, 17745129874679852617u, 125451321734u },
3072 { 10478790837359789693u, 1074820986392253357u, 134961965418u },
3073 { 10041191967455692214u, 7820952682162838597u, 106058266162u },
3074 { 5035461258013813797u, 8215518006273528603u, 50423974694u },
3075 { 14208759661559249750u, 9680426791089900133u, 38445364123u },
3076 { 12347272163241758840u, 16128495723604797412u, 155524776987u },
3077 { 3372534174410277614u, 2264789053583348885u, 27874327505u },
3078 { 17226704187274712984u, 11175458488686298083u, 209122774460u },
3079 { 4250480179449852121u, 11026777810412287617u, 188605822818u },
3080 { 4303723537755414374u, 16199890034895598640u, 98597762822u },
3081 { 8680503847344854165u, 9094320719494763752u, 6878197798u },
3082 { 8817608623911079652u, 1250835564687222832u, 38493004114u },
3083 { 5692030448698539450u, 15362466642459337025u, 82067807931u },
3084 { 16908836314686769809u, 7831109835595423828u, 187832800985u },
3085 { 6073762347067727240u, 15426237284335022429u, 217424525314u },
3086 { 10931066692585106200u, 15636308361455434548u, 2836257998u },
3087 { 14466591364061539596u, 13967173875944980328u, 206847645974u },
3088 { 4958077340960173341u, 18245979923595824097u, 22757162012u },
3089 { 4076890037156765715u, 11335054479675278263u, 28989116553u },
3090 { 14083973146609179058u, 11165339882630461707u, 137614474534u },
3091 { 2565183738039805295u, 15944437408299395922u, 38605274287u },
3092 { 1482420938751351224u, 15806416348777321161u, 175864349683u },
3093 { 2151089495335413944u, 4201030477408556248u, 243856867547u },
3094 { 3738604531753220913u, 9485474942554588907u, 219227738318u },
3095 { 14195686514836005765u, 18238757647663230541u, 206514208626u },
3096 { 17808833916231796970u, 4642199687824746379u, 114988725033u },
3097 { 1302384553035657354u, 6134575894869364037u, 41251654149u },
3098 { 1672033517974833698u, 11524208547121316008u, 5332556025u },
3099 { 11673925532927662545u, 2734683241527878366u, 249624728597u },
3100 { 3905334232240480709u, 10629223456178675171u, 21148247475u },
3101 { 17411087320267472625u, 2788042336985254064u, 179576211358u },
3102 { 16573305231063706617u, 17285498758066142502u, 158151140077u },
3103 { 15481103236037148354u, 5525538192421886436u, 237937048765u },
3104 { 907440704754420880u, 11414325503043801888u, 189299540025u },
3105 { 3224970785139077759u, 7246608114685173259u, 57618771825u },
3106 { 10560826509734608144u, 1007884269852184608u, 113392839413u },
3107 { 4700940027512659968u, 13823717876510029312u, 245054637515u },
3108 { 9733694683502084096u, 12487410768239429317u, 203749385247u },
3109 { 1995535635724632064u, 3361062421598631942u, 31676943894u },
3110 { 10629833226245373952u, 17853337379088328475u, 22182203558u },
3111 { 15729384648544878592u, 11551561037491869885u, 166967831358u },
3112 { 7205759403792793600u, 11480877996635204802u, 62626211378u },
3113 { 0u, 5527488381934471912u, 50622379643u },
3114 { 0u, 11143438404407726080u, 123299645745u },
3115 { 0u, 6472279730688098304u, 49604087006u },
3116 { 0u, 4561816853579563008u, 222350862987u },
3117 { 0u, 2888714464062865408u, 139247296587u },
3118 { 0u, 16258276129784201216u, 75156597524u },
3119 { 0u, 720575940379279360u, 20881362915u },
3120 { 0u, 0u, 227039062500u },
3121 { 0u, 0u, 228000000000u },
3122 { 7535526066623007027u, 164893u, 0u },
3123 { 11302146918409311588u, 164893408501686u, 0u },
3124 { 2480833299122194801u, 16409970870640346804u, 8938u },
3125 { 11513226205589330558u, 7721907286269370594u, 234889586303u },
3126 { 4073957068281936105u, 14300743897882155131u, 127418605432u },
3127 { 3729887061093812886u, 2068482633821123575u, 120775244880u },
3128 { 13616911779739451443u, 4922882895416406094u, 80112132668u },
3129 { 13039053282195777666u, 9317632875623428410u, 60266870016u },
3130 { 14490756113210417890u, 5693844901999766254u, 505109890u },
3131 { 17432486112977557585u, 11569484900262102262u, 130308663950u },
3132 { 14308820825344039837u, 3138170119352085637u, 142627183033u },
3133 { 4190949538817536349u, 950584692575235243u, 185170120543u },
3134 { 13616552502810964397u, 8136430299747162645u, 95051531299u },
3135 { 4898145803694965031u, 6698711700804594470u, 35441076770u },
3136 { 1399036321001644308u, 17401191571004302008u, 34363137888u },
3137 { 17170331128243738540u, 4721732028538188150u, 96943320485u },
3138 { 10641321388205367410u, 2984214103553086219u, 165255965606u },
3139 { 6648873641312572851u, 13128675202005662068u, 166161774570u },
3140 { 5988456964560374823u, 14638512997670672834u, 234711706908u },
3141 { 9972593758348346915u, 12942085665769692438u, 28793555379u },
3142 { 16709668921872818968u, 14131134357119205086u, 179701591869u },
3143 { 6094829131503407767u, 8921946894736102919u, 61766050328u },
3144 { 4892016478899926334u, 5601522560505809989u, 24483659710u },
3145 { 13150857244079031538u, 8602606493507716808u, 190303659146u },
3146 { 12983943395318785894u, 8576789731078566487u, 138466348232u },
3147 { 15341644584614757478u, 17881118138842658549u, 200464948702u },
3148 { 7507635124856644772u, 11624372674432704923u, 222969337356u },
3149 { 11619655367084544354u, 6826284072848095635u, 12630158505u },
3150 { 11553116952478783009u, 1646466632033733563u, 169370053601u },
3151 { 17392150014233193245u, 17871081657060299180u, 225089255134u },
3152 { 8877887560294980515u, 15910893124677544709u, 222968793277u },
3153 { 18404180619915609503u, 11031217459450580944u, 189862531244u },
3154 { 10079413095288181976u, 13554987390037243094u, 172598003496u },
3155 { 14102802966539105550u, 15026714590903687870u, 40734817338u },
3156 { 13333966026135891399u, 4406379654994689200u, 58814599830u },
3157 { 12344968670173516152u, 13596329092861950242u, 150238870319u },
3158 { 10577007819804726752u, 284812388227373260u, 47737058477u },
3159 { 15337041354031088010u, 9285079159392309382u, 173015439710u },
3160 { 14333607285614673616u, 15046108141952711893u, 94503345149u },
3161 { 17171597563219696538u, 13795366909944958311u, 253815651156u },
3162 { 2849642930482147564u, 12909920641180059961u, 84747848338u },
3163 { 14791248423979435173u, 5333762939889788252u, 146699848200u },
3164 { 13882371364576310127u, 6411331390005944495u, 8289143868u },
3165 { 11735995808941329540u, 1447104583224217723u, 60347558971u },
3166 { 11376996674339273181u, 11940049226167932871u, 59078447696u },
3167 { 9849638057168043481u, 9772290783590472385u, 80647271365u },
3168 { 18241520229279361964u, 16351989577831528444u, 197529756944u },
3169 { 1865852368526961444u, 4376738725895725097u, 16886443131u },
3170 { 10601487369276448158u, 13851276297739812763u, 123237263481u },
3171 { 15999931310312762170u, 12641996203470333509u, 121750879192u },
3172 { 5773775867713013570u, 7707081716407945022u, 216685323987u },
3173 { 17726239863982547534u, 417638323657040024u, 211417801737u },
3174 { 9711316695888316992u, 16438047707692449100u, 9022640218u },
3175 { 17872002620723724288u, 14850108107043306316u, 90891108351u },
3176 { 7429694208660733952u, 10423290807904720835u, 255805025973u },
3177 { 1782821038871019520u, 16951162310302339314u, 181565047726u },
3178 { 3225250234313474048u, 2752437506572397322u, 174918924350u },
3179 { 10009250171830927360u, 3925815842962784589u, 62149209936u },
3180 { 1152921504606846976u, 5274166674003605291u, 80212818903u },
3181 { 0u, 5538963350863452832u, 215285913148u },
3182 { 0u, 16900671634439028736u, 60300267804u },
3183 { 0u, 2326997710751662080u, 28916187245u },
3184 { 0u, 12327726161625874432u, 109126146798u },
3185 { 0u, 5756455743825903616u, 238668287374u },
3186 { 0u, 3018537650245074944u, 142312058091u },
3187 { 0u, 16717361816799281152u, 235163635253u },
3188 { 0u, 0u, 53906250000u },
3189 { 0u, 0u, 16000000000u },
3190 { 2285186318012886800u, 2516073738u, 0u },
3191 { 9706420951402272035u, 2516073738123880198u, 0u },
3192 { 2369632031840402142u, 11997425759292732054u, 136396630u },
3193 { 15599123897979399458u, 11491152661270395161u, 86650381753u },
3194 { 17579576584023912658u, 18181063258234881272u, 185622936633u },
3195 { 3480927339588501811u, 2466921813123869732u, 57985597414u },
3196 { 3547346616671294635u, 8430880678232179465u, 230133732099u },
3197 { 7705317123868384954u, 6738034873677997533u, 3457038957u },
3198 { 4969425237478353909u, 7678250951042929246u, 109365269602u },
3199 { 17043246700132217175u, 1853560606315563193u, 98416238818u },
3200 { 17053788362783499470u, 14942676593409905118u, 226100481721u },
3201 { 11102988228454224768u, 4909892170837638183u, 185810044121u },
3202 { 16944305387801685839u, 16871149368312132405u, 217266165787u },
3203 { 11725142977459199276u, 16096130589333770811u, 27914586839u },
3204 { 8175984171998533324u, 12512479187631824282u, 215872572987u },
3205 { 1372352885142856895u, 16980304980540557310u, 59678302855u },
3206 { 17975093466502888164u, 8640919162749295366u, 135920504177u },
3207 { 6467823391459085653u, 7862382415464063513u, 113468425166u },
3208 { 11319386883146885025u, 14534157903009925344u, 206426220604u },
3209 { 9141999262922068637u, 12627464554215107944u, 60787898278u },
3210 { 1587330393383478774u, 2456849734836299173u, 166684536225u },
3211 { 884187548095712303u, 18428252197697827913u, 161133186090u },
3212 { 488841225726377268u, 7244734215936736255u, 42998997553u },
3213 { 17462624199405856193u, 14756175050504770087u, 49392737828u },
3214 { 13183677579115583554u, 6764116534566945922u, 36799933852u },
3215 { 11645015818917277779u, 1588822142405565521u, 156366683492u },
3216 { 8760523002035971977u, 17053265624843842052u, 100086130220u },
3217 { 10068817678491468042u, 16996891591759999207u, 44924459381u },
3218 { 1273658177787418284u, 8565556232370585876u, 117921403339u },
3219 { 3100019384328057661u, 14464960359145886620u, 203464339733u },
3220 { 10363063568089458738u, 5813189542048784035u, 21784147072u },
3221 { 13030756371481403666u, 9739241026882027025u, 128315133636u },
3222 { 6538878900684195299u, 18175068535675302910u, 196527965313u },
3223 { 8984884716779098868u, 10562697212061761911u, 129985272439u },
3224 { 8728727397070363908u, 4264834835660801368u, 119572604963u },
3225 { 6398650562917867005u, 13019066443690126316u, 35231197159u },
3226 { 1190873176164938879u, 1828040177823321846u, 231705765006u },
3227 { 4383628525805121795u, 11240369830376975668u, 142099098256u },
3228 { 10189374699734119852u, 8886938465302549874u, 144609341669u },
3229 { 5276291920541626391u, 9985240313589688325u, 229481761899u },
3230 { 2692252373800386521u, 722909126956573766u, 107541300962u },
3231 { 11578684995169173920u, 5493363474638452381u, 226039188982u },
3232 { 5799408022254132587u, 12410535279213120491u, 246297795830u },
3233 { 15548569837712345290u, 10543108918366869098u, 246672776465u },
3234 { 15763030464322902955u, 12953909016524823995u, 17571543079u },
3235 { 13257749746581255500u, 16505942145872588169u, 39702232814u },
3236 { 16152470009188707678u, 12428594380392015797u, 238894788916u },
3237 { 13806790848493904003u, 7528259605829768337u, 52673755451u },
3238 { 11981226523265951191u, 18147447600042811311u, 59408107770u },
3239 { 5133628726077003713u, 12021069431116183911u, 250983775105u },
3240 { 16183955741910833164u, 11819985069665662506u, 129651663479u },
3241 { 13640425554331371454u, 10401877114068152814u, 119640762674u },
3242 { 18108120906868035862u, 4611631138117837942u, 50563886888u },
3243 { 6324011669895037184u, 17200813398607252417u, 40249997024u },
3244 { 10444437689515769856u, 14100466137553658767u, 224932457962u },
3245 { 12324712543665782784u, 17887776768825509301u, 234764387800u },
3246 { 13928941951563857920u, 12632656857970087269u, 216969698321u },
3247 { 3975288688270639104u, 8923681664054686256u, 17684817700u },
3248 { 11141905478114607104u, 6213926103737837599u, 36483753752u },
3249 { 4611686018427387904u, 1233118281776157762u, 24336857609u },
3250 { 0u, 30716279628678784u, 9066847476u },
3251 { 0u, 15775734650898546688u, 244001665132u },
3252 { 0u, 976806005729918976u, 108855204289u },
3253 { 0u, 12460098853279891456u, 193052952759u },
3254 { 0u, 5635665595421687808u, 183675463312u },
3255 { 0u, 1805943450575568896u, 144305510044u },
3256 { 0u, 11529215046068469760u, 156097900390u },
3257 { 0u, 0u, 102625000000u },
3258 { 0u, 0u, 64000000000u },
3259 { 4398362855256705725u, 38392u, 0u },
3260 { 2812083125569302717u, 38392238435728u, 0u },
3261 { 12868509142973100603u, 4564018338575530435u, 2081u },
3262 { 8726243776748165726u, 16553437246451512014u, 33247415929u },
3263 { 358304413426858117u, 4339777136957372927u, 121897363631u },
3264 { 3180720351566429470u, 18439463366554654697u, 175235259789u },
3265 { 14053818240400098784u, 1370067356680643003u, 141999605312u },
3266 { 7340140541492429288u, 4210124040914115013u, 64074271500u },
3267 { 1323571167904965058u, 10692225626142609720u, 12228231281u },
3268 { 14463851737583396026u, 11592856673895384344u, 113579626712u },
3269 { 15122784818916048486u, 10284479231227406269u, 216628450019u },
3270 { 13557974621377508955u, 4961071383534266431u, 227557522736u },
3271 { 17525172074563876264u, 10960611551445686988u, 48268940218u },
3272 { 15148880683074215967u, 14616396723115619209u, 186594175942u },
3273 { 6744828147558597936u, 1025604265437492803u, 198792356454u },
3274 { 9799290779647971692u, 11711588454892179178u, 102055598118u },
3275 { 11170890203898678105u, 5580373263251565705u, 38634886482u },
3276 { 7068779781287527905u, 14109334653033148931u, 82302512640u },
3277 { 14474741922505540911u, 2899414033769399895u, 764868564u },
3278 { 17107062680405191514u, 13233457234892808147u, 212157177549u },
3279 { 2712598571300237005u, 3287946691509034862u, 205717387154u },
3280 { 3767556054903418641u, 5488480288717445911u, 146178239947u },
3281 { 18158239681706277628u, 11687233053874362630u, 203297531112u },
3282 { 10531652712128330681u, 6783772100089274577u, 232633566173u },
3283 { 9548395326934120567u, 7898291058728402485u, 221367749022u },
3284 { 15875647850297719390u, 4423684977486598491u, 158428167216u },
3285 { 8215825295203192574u, 2750833684599526706u, 48239808443u },
3286 { 12747310908260543144u, 15669689830489025709u, 187149122992u },
3287 { 77706528053613642u, 15117307274214954517u, 176849455587u },
3288 { 6024737704056756146u, 8148639818575698175u, 227819510869u },
3289 { 6819452388570089667u, 13006484426078994901u, 85441738649u },
3290 { 13695926775373186254u, 10287496057845513526u, 153705082933u },
3291 { 3746531715392682132u, 14159876032966532430u, 53557686278u },
3292 { 4717376233154528116u, 15742212196465548019u, 6767608417u },
3293 { 385190957950313369u, 2892220461917134150u, 97853387033u },
3294 { 12388374310648616082u, 7487151560715393883u, 25156787585u },
3295 { 1078067332084407770u, 7245756744165177933u, 129405879299u },
3296 { 3257295319358714850u, 3067122860671533987u, 3392793260u },
3297 { 1545453099660723457u, 8135043905834122525u, 172166269063u },
3298 { 7495477664653506341u, 14730019368921022572u, 135441001613u },
3299 { 7225503732673614354u, 495969939682055458u, 141798515950u },
3300 { 3935478326103643956u, 5617761407265775598u, 238026886584u },
3301 { 10082240682742686210u, 2087044847072781811u, 184304539456u },
3302 { 10838712705567897138u, 15929674232061203330u, 64113138927u },
3303 { 2142546572501643680u, 8658086469608285873u, 239863549370u },
3304 { 7893042119150331392u, 18369871790780313570u, 186469355807u },
3305 { 12084811642251302615u, 3545648451947416750u, 31995832745u },
3306 { 15317234482572954775u, 13347376792767929959u, 169192209987u },
3307 { 2283226355108359361u, 14482164459838203025u, 67723562745u },
3308 { 13359725152575722127u, 8899577765623565820u, 249785079708u },
3309 { 13126551011491594557u, 7095320096604405719u, 156482447077u },
3310 { 3598021288691861269u, 2968593824439315788u, 229384638073u },
3311 { 16462621795896662961u, 12621408323612585636u, 121160927793u },
3312 { 14682112756964627332u, 3954422936414648259u, 49684207916u },
3313 { 7174112100896070218u, 17143730087577690191u, 44214369696u },
3314 { 5023109019590616064u, 5033045529399041876u, 160929363470u },
3315 { 10765223023086141440u, 15857648521994521781u, 14272841944u },
3316 { 8228137177297453056u, 16655573486499109541u, 216859644848u },
3317 { 2891199497780592640u, 16652154439190075858u, 176902900447u },
3318 { 15294857653247803392u, 18016950600164130638u, 223902715100u },
3319 { 14303432416528695296u, 2086292996072613910u, 220976700849u },
3320 { 0u, 17324462585194799521u, 177113098169u },
3321 { 0u, 11079151463184927232u, 185939160998u },
3322 { 0u, 5239846817488961536u, 166600602004u },
3323 { 0u, 2778806963520143360u, 148284052665u },
3324 { 0u, 6240890740138835968u, 185150639427u },
3325 { 0u, 17250651344549707776u, 67338319364u },
3326 { 0u, 4197354852709302272u, 4935159683u },
3327 { 0u, 9223372036854775808u, 131227539062u },
3328 { 0u, 0u, 118500000000u },
3329 { 17118225092618494573u, 585819067u, 0u },
3330 { 13385738875341807559u, 585819067927980841u, 0u },
3331 { 8272682717439277193u, 5654803392547571318u, 31757315u },
3332 { 13402436483369350083u, 2931628102185393332u, 3306547506u },
3333 { 10946328903241612536u, 15964697617980212305u, 50158923877u },
3334 { 16265808923426731252u, 450380868305846606u, 101865447992u },
3335 { 11080374459871185177u, 14631133530814566148u, 56024415195u },
3336 { 1240761893433831916u, 31969822783742095u, 219793155338u },
3337 { 367264070493390483u, 10437269029385743245u, 10001733087u },
3338 { 2863675693461092905u, 15196146496377392433u, 223565805487u },
3339 { 7511929581752138999u, 4409099735137480938u, 175823784752u },
3340 { 11154557789993845753u, 10644987914903248118u, 48239017775u },
3341 { 8325416539745948522u, 3154431617534062973u, 47577065951u },
3342 { 17745129874679852617u, 11702056331247960454u, 223171002080u },
3343 { 1074820986392253357u, 15575315065965259114u, 224634369744u },
3344 { 7820952682162838597u, 10759747609480050226u, 208844339521u },
3345 { 8215518006273528603u, 12538236653960743718u, 65583287086u },
3346 { 9680426791089900133u, 17857942663978005403u, 46679699170u },
3347 { 16128495723604797412u, 11443004154750813211u, 226968081011u },
3348 { 2264789053583348885u, 4004313188770806737u, 115620326498u },
3349 { 11175458488686298083u, 17134872954824183228u, 98217074252u },
3350 { 11026777810412287617u, 2659553912986171234u, 76928883324u },
3351 { 16199890034895598640u, 9501854300969137926u, 124144174706u },
3352 { 9094320719494763752u, 14528169966301018150u, 114515096553u },
3353 { 1250835564687222832u, 18172091996515901778u, 233787573671u },
3354 { 15362466642459337025u, 1133541705604751035u, 167985111081u },
3355 { 7831109835595423828u, 18280349987988641497u, 41061449418u },
3356 { 15426237284335022429u, 9936015874712336386u, 202990979758u },
3357 { 15636308361455434548u, 15876720399740689614u, 174538632499u },
3358 { 13967173875944980328u, 8618117825152456982u, 51860678737u },
3359 { 18245979923595824097u, 8085525680745921564u, 81467189103u },
3360 { 11335054479675278263u, 8072355444669730953u, 111438317225u },
3361 { 11165339882630461707u, 9395030504766848294u, 169437603265u },
3362 { 15944437408299395922u, 3537903114058185903u, 193509305624u },
3363 { 15806416348777321161u, 2126094743961928691u, 24191790112u },
3364 { 4201030477408556248u, 289185362555601115u, 32115255827u },
3365 { 9485474942554588907u, 16909937501450129614u, 19015676769u },
3366 { 18238757647663230541u, 14449642060360499058u, 97916689548u },
3367 { 4642199687824746379u, 12433818908498244393u, 140783316665u },
3368 { 6134575894869364037u, 11884444034578008581u, 185674038673u },
3369 { 11524208547121316008u, 988625838444140793u, 145644257002u },
3370 { 2734683241527878366u, 1675370907158909973u, 234053593514u },
3371 { 10629223456178675171u, 15920186275316934067u, 170090822038u },
3372 { 2788042336985254064u, 5600921198503757726u, 150863035027u },
3373 { 17285498758066142502u, 10457357161776341741u, 147303626546u },
3374 { 5525538192421886436u, 12225356765775740093u, 50566894467u },
3375 { 11414325503043801888u, 4486633318598164537u, 131662737918u },
3376 { 7246608114685173259u, 10302486602879381361u, 254243220879u },
3377 { 1007884269852184608u, 15536428611301239541u, 143558498917u },
3378 { 13823717876510029312u, 12026126645955462603u, 101842231482u },
3379 { 12487410768239429317u, 14877968141142123551u, 186651937631u },
3380 { 3361062421598631942u, 734560801645383190u, 95806536269u },
3381 { 17853337379088328475u, 15648943144911081638u, 77039820620u },
3382 { 11551561037491869885u, 13664182862003235646u, 76848330907u },
3383 { 11480877996635204802u, 3895127525902132786u, 155740736837u },
3384 { 5527488381934471912u, 5249187334214137467u, 69211155286u },
3385 { 11143438404407726080u, 10642260063359027505u, 86284559015u },
3386 { 6472279730688098304u, 783598951897779422u, 167576918074u },
3387 { 4561816853579563008u, 5538576558607624843u, 58042478984u },
3388 { 2888714464062865408u, 15974581187564609611u, 136300246836u },
3389 { 16258276129784201216u, 7474269406918257428u, 52865983781u },
3390 { 720575940379279360u, 8045286838779138019u, 37405180956u },
3391 { 0u, 8184246376556341732u, 28436135873u },
3392 { 0u, 1493267152679331840u, 193443668885u },
3393 { 0u, 10179074811222818816u, 149080950174u },
3394 { 0u, 3892499202005008384u, 158551808751u },
3395 { 0u, 10341173215925108736u, 239211012804u },
3396 { 0u, 6230307872002015232u, 196560596123u },
3397 { 0u, 9295429630892703744u, 155337745666u },
3398 { 0u, 0u, 2503906250u },
3399 { 0u, 0u, 202000000000u },
3400 { 16409970870640346804u, 8938u, 0u },
3401 { 7721907286269370594u, 8938889586303u, 0u },
3402 { 14300743897882155131u, 10665454627995623288u, 484u },
3403 { 2068482633821123575u, 16803537892767562832u, 228578175453u },
3404 { 4922882895416406094u, 8099123106849104444u, 221910921614u },
3405 { 9317632875623428410u, 7077413686679401728u, 142439054343u },
3406 { 5693844901999766254u, 13536636358372449666u, 7383667364u },
3407 { 11569484900262102262u, 7280632235418610318u, 164733822527u },
3408 { 3138170119352085637u, 6187823673116858809u, 63394683864u },
3409 { 950584692575235243u, 8624343686231740255u, 216335442593u },
3410 { 8136430299747162645u, 806211610822132771u, 161467526608u },
3411 { 6698711700804594470u, 18388078233202190882u, 208043704818u },
3412 { 17401191571004302008u, 7628864426595573600u, 242996819718u },
3413 { 4721732028538188150u, 4530799784343874981u, 6413561569u },
3414 { 2984214103553086219u, 8561580552078486438u, 225245615148u },
3415 { 13128675202005662068u, 13349114951221999594u, 44464124211u },
3416 { 14638512997670672834u, 10029144738508991772u, 51723656971u },
3417 { 12942085665769692438u, 12601907197916268979u, 11543681025u },
3418 { 14131134357119205086u, 1329580921391066941u, 1683150758u },
3419 { 8921946894736102919u, 3198179786356761112u, 166072076726u },
3420 { 5601522560505809989u, 11406753413634654142u, 182173373673u },
3421 { 8602606493507716808u, 11131812960525182090u, 233618361341u },
3422 { 8576789731078566487u, 14299636753645227208u, 253603456789u },
3423 { 17881118138842658549u, 12964114684643663326u, 21775184861u },
3424 { 11624372674432704923u, 5019257593846306316u, 221702786065u },
3425 { 6826284072848095635u, 6929086798159998121u, 17272094499u },
3426 { 1646466632033733563u, 18359765766933703649u, 35375626547u },
3427 { 17871081657060299180u, 9993076234752063198u, 51995284896u },
3428 { 15910893124677544709u, 3257189215046584509u, 160541725748u },
3429 { 11031217459450580944u, 2905234736672690348u, 52176572581u },
3430 { 13554987390037243094u, 12064985302079670056u, 165157493090u },
3431 { 15026714590903687870u, 14315096064942799930u, 98654044163u },
3432 { 4406379654994689200u, 11943971043551974038u, 3776022912u },
3433 { 13596329092861950242u, 12472773152119929647u, 128647483967u },
3434 { 284812388227373260u, 7791259796982183085u, 63676150387u },
3435 { 9285079159392309382u, 16866829442051086686u, 115422365039u },
3436 { 15046108141952711893u, 3702498393844653053u, 111914352656u },
3437 { 13795366909944958311u, 2057239613841701716u, 16200712840u },
3438 { 12909920641180059961u, 17201969976738286226u, 136111523182u },
3439 { 5333762939889788252u, 18271566505443461640u, 110932520660u },
3440 { 6411331390005944495u, 18368509115417119804u, 212990503604u },
3441 { 1447104583224217723u, 7613923684154518587u, 180995758874u },
3442 { 11940049226167932871u, 17984805084714865232u, 26412751629u },
3443 { 9772290783590472385u, 4220802739051410373u, 13974958237u },
3444 { 16351989577831528444u, 17812459042810815760u, 157228810174u },
3445 { 4376738725895725097u, 10629526089664605307u, 190965615339u },
3446 { 13851276297739812763u, 17437443267816548473u, 235576227763u },
3447 { 12641996203470333509u, 12506371893701049304u, 179945285693u },
3448 { 7707081716407945022u, 15737221540003030739u, 61677971778u },
3449 { 417638323657040024u, 2358380859011605513u, 66853116489u },
3450 { 16438047707692449100u, 10042972713837039706u, 73127848082u },
3451 { 14850108107043306316u, 13424397272769642495u, 146544430641u },
3452 { 10423290807904720835u, 6867102315755663029u, 49727738034u },
3453 { 16951162310302339314u, 8690748404825506734u, 178372266362u },
3454 { 2752437506572397322u, 956229930815387710u, 122471126415u },
3455 { 3925815842962784589u, 7734449506297687888u, 143051837328u },
3456 { 5274166674003605291u, 16332184961683848151u, 144419285347u },
3457 { 5538963350863452832u, 15580777817612768828u, 99885369520u },
3458 { 16900671634439028736u, 17404245271944696092u, 176844635657u },
3459 { 2326997710751662080u, 13201420160494469229u, 9943486026u },
3460 { 12327726161625874432u, 16511717657124068078u, 74715650420u },
3461 { 5756455743825903616u, 14131292492116594062u, 116895102007u },
3462 { 3018537650245074944u, 18429136031865875691u, 55766058900u },
3463 { 16717361816799281152u, 2563978348305862197u, 148999045466u },
3464 { 0u, 14239974392147482896u, 90138993544u },
3465 { 0u, 11164201396098998272u, 136771950558u },
3466 { 0u, 7116971104932986880u, 222605212570u },
3467 { 0u, 12437629862867369984u, 154385811776u },
3468 { 0u, 16501893821638901760u, 64674245265u },
3469 { 0u, 10649324268870959104u, 145894569456u },
3470 { 0u, 7205759403792793600u, 240577301025u },
3471 { 0u, 0u, 33390625000u },
3472 { 0u, 0u, 232000000000u },
3473 { 11997425759292732054u, 136396630u, 0u },
3474 { 11491152661270395161u, 136396630650381753u, 0u },
3475 { 18181063258234881272u, 3016823727048309817u, 7394076u },
3476 { 2466921813123869732u, 17405973192644624358u, 28163542341u },
3477 { 8430880678232179465u, 8937219978302591747u, 69943579697u },
3478 { 6738034873677997533u, 15178463196824222317u, 49484487665u },
3479 { 7678250951042929246u, 11979404627460330594u, 241822826138u },
3480 { 1853560606315563193u, 2006448052689740002u, 154649404826u },
3481 { 14942676593409905118u, 16330465320863239865u, 154108769766u },
3482 { 4909892170837638183u, 17136208883957646553u, 230885276298u },
3483 { 16871149368312132405u, 140455118208931867u, 138928955745u },
3484 { 16096130589333770811u, 3964972929179372247u, 97007614087u },
3485 { 12512479187631824282u, 3378050330022776379u, 135214941613u },
3486 { 16980304980540557310u, 6065353437512901255u, 173183124475u },
3487 { 8640919162749295366u, 12768753059854699889u, 251328803468u },
3488 { 7862382415464063513u, 6848720690951013326u, 140692195490u },
3489 { 14534157903009925344u, 10953228058585475132u, 162371269892u },
3490 { 12627464554215107944u, 15539127852083296166u, 4593775682u },
3491 { 2456849734836299173u, 14534853647735598497u, 66842377808u },
3492 { 18428252197697827913u, 1506909603576368170u, 80787935995u },
3493 { 7244734215936736255u, 5475702579938239025u, 251081689733u },
3494 { 14756175050504770087u, 12039747373985783332u, 133296838431u },
3495 { 6764116534566945922u, 17572399137760898460u, 31652676012u },
3496 { 1588822142405565521u, 869552790852091236u, 172952601666u },
3497 { 17053265624843842052u, 4549585778048181804u, 66047138551u },
3498 { 16996891591759999207u, 4121918231767210357u, 247246633539u },
3499 { 8565556232370585876u, 1558397953312543179u, 67223449635u },
3500 { 14464960359145886620u, 6067524298738069781u, 35084480922u },
3501 { 5813189542048784035u, 5811095224555517056u, 154328921151u },
3502 { 9739241026882027025u, 6440894514158997188u, 63315020103u },
3503 { 18175068535675302910u, 4612748874388784257u, 71349161591u },
3504 { 10562697212061761911u, 9908101430749813367u, 119250057617u },
3505 { 4264834835660801368u, 15150017990912190499u, 145537119254u },
3506 { 13019066443690126316u, 17470426264690059239u, 22821284120u },
3507 { 1828040177823321846u, 9615161096851907726u, 24947073705u },
3508 { 11240369830376975668u, 9227932132124142224u, 169521238927u },
3509 { 8886938465302549874u, 4794113194321211621u, 143500247203u },
3510 { 9985240313589688325u, 391512698859146347u, 163259889397u },
3511 { 722909126956573766u, 17209658878068655842u, 245021223945u },
3512 { 5493363474638452381u, 3077364726606876150u, 9932937477u },
3513 { 12410535279213120491u, 1952989567673965814u, 5166824276u },
3514 { 10543108918366869098u, 11172860676923186449u, 84105871776u },
3515 { 12953909016524823995u, 17338078544784947239u, 160605681990u },
3516 { 16505942145872588169u, 4593380466519703278u, 70939899121u },
3517 { 12428594380392015797u, 786884753602720052u, 241249007654u },
3518 { 7528259605829768337u, 17848875822468020539u, 38042657107u },
3519 { 18147447600042811311u, 2899664567187130618u, 83967589497u },
3520 { 12021069431116183911u, 2973178834961857409u, 121157191131u },
3521 { 11819985069665662506u, 11117453141176836727u, 219161176347u },
3522 { 10401877114068152814u, 7535238370146462002u, 27602678342u },
3523 { 4611631138117837942u, 10246175467290865448u, 70408486090u },
3524 { 17200813398607252417u, 1203128834127050464u, 202555446285u },
3525 { 14100466137553658767u, 14518048959078919658u, 13065221744u },
3526 { 17887776768825509301u, 1553474987376920024u, 112787025011u },
3527 { 12632656857970087269u, 14956572380830948369u, 115084214047u },
3528 { 8923681664054686256u, 7594162606042048292u, 31810797413u },
3529 { 6213926103737837599u, 14461296147288811288u, 101411680379u },
3530 { 1233118281776157762u, 18305427728131488265u, 123783948434u },
3531 { 30716279628678784u, 10253208939347909876u, 146992339225u },
3532 { 15775734650898546688u, 6446028915490812012u, 25555827570u },
3533 { 976806005729918976u, 12986063676957432257u, 114349439927u },
3534 { 12460098853279891456u, 9769714697972762807u, 183703975922u },
3535 { 5635665595421687808u, 97429465146664592u, 242529617295u },
3536 { 1805943450575568896u, 16395571728207795868u, 143005281661u },
3537 { 11529215046068469760u, 6331668478323650406u, 125888805724u },
3538 { 0u, 18129911846294207040u, 92343240435u },
3539 { 0u, 9890094564876124160u, 243982824490u },
3540 { 0u, 12290856656987750400u, 42536143100u },
3541 { 0u, 8498454992640802816u, 252666288674u },
3542 { 0u, 5341660584200896512u, 34460702168u },
3543 { 0u, 9288674231451648000u, 216289572000u },
3544 { 0u, 1152921504606846976u, 160503540039u },
3545 { 0u, 0u, 71062500000u },
3546 { 0u, 0u, 160000000000u },
3547 { 4564018338575530435u, 2081u, 0u },
3548 { 16553437246451512014u, 2081247415929u, 0u },
3549 { 4339777136957372927u, 15212079674427582639u, 112u },
3550 { 18439463366554654697u, 10179808126814248333u, 112824648491u },
3551 { 1370067356680643003u, 6066766544199222848u, 43551848504u },
3552 { 4210124040914115013u, 6625308131806923532u, 56328880073u },
3553 { 10692225626142609720u, 9122786786400665713u, 201359158673u },
3554 { 11592856673895384344u, 11932880778639151320u, 145494547262u },
3555 { 10284479231227406269u, 3884040911779255011u, 62646882763u },
3556 { 4961071383534266431u, 13441817515637357872u, 203210554279u },
3557 { 10960611551445686988u, 11628577856022352826u, 167728682387u },
3558 { 14616396723115619209u, 13296656925520243654u, 147630386468u },
3559 { 1025604265437492803u, 5020720704545399398u, 36720813216u },
3560 { 11711588454892179178u, 14121973606499014694u, 160272173814u },
3561 { 5580373263251565705u, 3642481034345420114u, 246765553723u },
3562 { 14109334653033148931u, 9845536238569696768u, 59197459292u },
3563 { 2899414033769399895u, 17655403572195686356u, 92533727588u },
3564 { 13233457234892808147u, 8377495365136654029u, 100957101345u },
3565 { 3287946691509034862u, 13713682649609025426u, 33454144933u },
3566 { 5488480288717445911u, 1367709905452854731u, 165743420226u },
3567 { 11687233053874362630u, 9981467701727208680u, 66074143702u },
3568 { 6783772100089274577u, 6277920117543306205u, 214541096448u },
3569 { 7898291058728402485u, 9344111460418701726u, 340326731u },
3570 { 4423684977486598491u, 4918507011364617264u, 75506545297u },
3571 { 2750833684599526706u, 6554777203830755259u, 145266632799u },
3572 { 15669689830489025709u, 4198262173120265648u, 95355335184u },
3573 { 15117307274214954517u, 8080325935698446819u, 16227588248u },
3574 { 8148639818575698175u, 12797633874200091733u, 152438035346u },
3575 { 13006484426078994901u, 8376502502208665497u, 146693761122u },
3576 { 10287496057845513526u, 9891973386793349173u, 98454091110u },
3577 { 14159876032966532430u, 14877430279003795462u, 102536244951u },
3578 { 15742212196465548019u, 8759933935842067041u, 215806507111u },
3579 { 2892220461917134150u, 3753418510388703513u, 103474876970u },
3580 { 7487151560715393883u, 2961383332545305985u, 42203473225u },
3581 { 7245756744165177933u, 2497674184068629507u, 73160536912u },
3582 { 3067122860671533987u, 15244544070742305452u, 80135399188u },
3583 { 8135043905834122525u, 45953573565810823u, 20826408390u },
3584 { 14730019368921022572u, 3960077421351906445u, 198002491148u },
3585 { 495969939682055458u, 3173330011013883118u, 12214676227u },
3586 { 5617761407265775598u, 11026266219545759160u, 3172026564u },
3587 { 2087044847072781811u, 8886757764964685632u, 196597735089u },
3588 { 15929674232061203330u, 13952322129918090479u, 177481752103u },
3589 { 8658086469608285873u, 4127250666614902202u, 39756356898u },
3590 { 18369871790780313570u, 17649958504065306911u, 34223738706u },
3591 { 3545648451947416750u, 13269305359002216873u, 82956806167u },
3592 { 13347376792767929959u, 16236593433831947843u, 23719330484u },
3593 { 14482164459838203025u, 13580930396682424057u, 180880187493u },
3594 { 8899577765623565820u, 421976357197961116u, 101736223712u },
3595 { 7095320096604405719u, 2962130818798626533u, 224022875384u },
3596 { 2968593824439315788u, 8234383947306356345u, 248160577433u },
3597 { 12621408323612585636u, 4380469931801381425u, 153446386848u },
3598 { 3954422936414648259u, 15279887469027055916u, 160237465750u },
3599 { 17143730087577690191u, 8534542821713755552u, 150828324359u },
3600 { 5033045529399041876u, 7814613482565088782u, 7462658493u },
3601 { 15857648521994521781u, 13771954404705323224u, 189423631045u },
3602 { 16655573486499109541u, 4568173274762548144u, 197746579144u },
3603 { 16652154439190075858u, 8105292616250821343u, 200247641169u },
3604 { 18016950600164130638u, 2923678426777275612u, 81439388793u },
3605 { 2086292996072613910u, 1808633176918384049u, 121158492925u },
3606 { 17324462585194799521u, 18118642609460438969u, 253098046200u },
3607 { 11079151463184927232u, 18138164175864360870u, 248982213583u },
3608 { 5239846817488961536u, 4031433690465792404u, 207983271850u },
3609 { 2778806963520143360u, 5012226396942308537u, 170218544458u },
3610 { 6240890740138835968u, 7889712298793536835u, 74271713337u },
3611 { 17250651344549707776u, 13500762396543628804u, 57427702160u },
3612 { 4197354852709302272u, 501020624068841347u, 144731877796u },
3613 { 9223372036854775808u, 8370653768288261750u, 164027160382u },
3614 { 0u, 647579990023635200u, 62453774050u },
3615 { 0u, 11106569307181154304u, 226035105381u },
3616 { 0u, 10797461613892861952u, 101602088328u },
3617 { 0u, 17627230675448889344u, 136585331566u },
3618 { 0u, 12197735707942322176u, 110955574089u },
3619 { 0u, 12871287735024877568u, 73661240577u },
3620 { 0u, 4611686018427387904u, 1697753906u },
3621 { 0u, 0u, 50250000000u },
3622 { 0u, 0u, 128000000000u },
3623 { 5654803392547571318u, 31757315u, 0u },
3624 { 2931628102185393332u, 31757315306547506u, 0u },
3625 { 15964697617980212305u, 9451803574512021605u, 1721567u },
3626 { 450380868305846606u, 8662766454758138424u, 223512383298u },
3627 { 14631133530814566148u, 9207992007314947035u, 66469609510u },
3628 { 31969822783742095u, 17118602861291201802u, 38499166246u },
3629 { 10437269029385743245u, 11186560605745599967u, 38928001320u },
3630 { 15196146496377392433u, 10505549821532796847u, 40606424665u },
3631 { 4409099735137480938u, 18133667530488679216u, 89569506996u },
3632 { 10644987914903248118u, 10778135771244330799u, 180983028086u },
3633 { 3154431617534062973u, 17087985777033767391u, 118584283910u },
3634 { 11702056331247960454u, 2639185991757283040u, 6926341565u },
3635 { 15575315065965259114u, 5401720287293896400u, 189143070559u },
3636 { 10759747609480050226u, 9816495392633895233u, 95292827843u },
3637 { 12538236653960743718u, 10042051500090034990u, 195532153281u },
3638 { 17857942663978005403u, 11629689537856384738u, 193544380702u },
3639 { 11443004154750813211u, 2099086731766010483u, 30630446733u },
3640 { 4004313188770806737u, 13665537898516458594u, 141113791719u },
3641 { 17134872954824183228u, 16375672064669490764u, 231740810293u },
3642 { 2659553912986171234u, 7770550512184564348u, 53887726961u },
3643 { 9501854300969137926u, 6197048880720627314u, 113421242387u },
3644 { 14528169966301018150u, 17963594118523106281u, 19335942692u },
3645 { 18172091996515901778u, 8255454642407818663u, 36973808388u },
3646 { 1133541705604751035u, 16744201957549498409u, 4447529092u },
3647 { 18280349987988641497u, 17442505417202859722u, 132907705006u },
3648 { 9936015874712336386u, 6383975767786687150u, 174945560113u },
3649 { 15876720399740689614u, 15245442964998335795u, 49346076019u },
3650 { 8618117825152456982u, 2910016124519524433u, 115826457119u },
3651 { 8085525680745921564u, 3847913871169988463u, 31157752290u },
3652 { 8072355444669730953u, 17210451512590059177u, 226208595828u },
3653 { 9395030504766848294u, 17899408909991454145u, 116932980445u },
3654 { 3537903114058185903u, 5920601932753251608u, 221970328901u },
3655 { 2126094743961928691u, 16521781895108979744u, 69320956473u },
3656 { 289185362555601115u, 3697493405554698771u, 57895647591u },
3657 { 16909937501450129614u, 2816108280295732065u, 103200441519u },
3658 { 14449642060360499058u, 14251078772056398988u, 175152661535u },
3659 { 12433818908498244393u, 4543066550096031417u, 31772552528u },
3660 { 11884444034578008581u, 3099369389734296977u, 80246280131u },
3661 { 988625838444140793u, 5243484113636490986u, 195168017151u },
3662 { 1675370907158909973u, 6823370511605197226u, 255284249843u },
3663 { 15920186275316934067u, 11396290277624641942u, 243369895656u },
3664 { 5600921198503757726u, 15934361408437566099u, 232617794133u },
3665 { 10457357161776341741u, 14939272230935131954u, 85863803462u },
3666 { 12225356765775740093u, 7500666177940329347u, 70809859570u },
3667 { 4486633318598164537u, 4806714453065462270u, 242406611928u },
3668 { 10302486602879381361u, 11557851247268441487u, 216260572512u },
3669 { 15536428611301239541u, 10655523157206817381u, 96626552371u },
3670 { 12026126645955462603u, 14769600176490881210u, 51577637067u },
3671 { 14877968141142123551u, 16688495540925795167u, 203800661629u },
3672 { 734560801645383190u, 909793965395524173u, 125904685156u },
3673 { 15648943144911081638u, 12724590949761703756u, 100049320029u },
3674 { 13664182862003235646u, 10810739657314826395u, 93689801457u },
3675 { 3895127525902132786u, 2431218615388671301u, 241586051371u },
3676 { 5249187334214137467u, 4235001167959059286u, 43131796625u },
3677 { 10642260063359027505u, 6253317787396334247u, 145229579873u },
3678 { 783598951897779422u, 9534525563070371898u, 97338993036u },
3679 { 5538576558607624843u, 8392783992374030728u, 140516867666u },
3680 { 15974581187564609611u, 16356257019231647540u, 82454973731u },
3681 { 7474269406918257428u, 12896334001521091877u, 35886674469u },
3682 { 8045286838779138019u, 1427636373320877084u, 37699111667u },
3683 { 8184246376556341732u, 16116755731295043521u, 243077392322u },
3684 { 1493267152679331840u, 15945633911163986837u, 194873691078u },
3685 { 10179074811222818816u, 7510154241072743838u, 198864414546u },
3686 { 3892499202005008384u, 3571560509790395119u, 82407126277u },
3687 { 10341173215925108736u, 3576991649007035076u, 5193614683u },
3688 { 6230307872002015232u, 15509961892750732443u, 91193909105u },
3689 { 9295429630892703744u, 17789791359353349378u, 113840796718u },
3690 { 0u, 18331227331079738314u, 46964386521u },
3691 { 0u, 15386712883100476416u, 217993737824u },
3692 { 0u, 14082462055028752384u, 96834115376u },
3693 { 0u, 12919043128765186048u, 48763411797u },
3694 { 0u, 6125373368465096704u, 85700342731u },
3695 { 0u, 12335992698065387520u, 203332057155u },
3696 { 0u, 2774217370460225536u, 67668735504u },
3697 { 0u, 0u, 16150390625u },
3698 { 0u, 0u, 97000000000u },
3699 { 10665454627995623288u, 484u, 0u },
3700 { 16803537892767562832u, 484578175453u, 0u },
3701 { 8099123106849104444u, 4962829537462579598u, 26u },
3702 { 7077413686679401728u, 5711259460785241095u, 26269035528u },
3703 { 13536636358372449666u, 13845894607204897444u, 8309607995u },
3704 { 7280632235418610318u, 12116633056637003327u, 59750587450u },
3705 { 6187823673116858809u, 2965791047992089560u, 58656843994u },
3706 { 8624343686231740255u, 16021997451315962529u, 218160775854u },
3707 { 806211610822132771u, 3942052271663803856u, 174868554222u },
3708 { 18388078233202190882u, 15669876414782439922u, 238213699081u },
3709 { 7628864426595573600u, 10594415915406145286u, 9849465702u },
3710 { 4530799784343874981u, 10789820553031921377u, 102574324437u },
3711 { 8561580552078486438u, 3989990218583987244u, 213584917344u },
3712 { 13349114951221999594u, 2937341169808224563u, 96216297803u },
3713 { 10029144738508991772u, 16267436558584536843u, 75159233583u },
3714 { 12601907197916268979u, 16221580362814625793u, 47881859502u },
3715 { 1329580921391066941u, 9695437602320209830u, 174879373633u },
3716 { 3198179786356761112u, 10729753156793715126u, 65525590725u },
3717 { 11406753413634654142u, 2609241432056861929u, 197581661084u },
3718 { 11131812960525182090u, 8462663743997037565u, 156141447261u },
3719 { 14299636753645227208u, 14993422143908194069u, 93458761920u },
3720 { 12964114684643663326u, 1307443894537745373u, 192812795043u },
3721 { 5019257593846306316u, 10017257439419829265u, 163070876675u },
3722 { 6929086798159998121u, 16754772009970777891u, 3543036613u },
3723 { 18359765766933703649u, 11722573031602862387u, 197908278010u },
3724 { 9993076234752063198u, 7363764277467092384u, 250635481957u },
3725 { 3257189215046584509u, 6733958494847390772u, 101399190461u },
3726 { 2905234736672690348u, 8799796600227451045u, 189365048621u },
3727 { 12064985302079670056u, 10512023194742249826u, 45477037929u },
3728 { 14315096064942799930u, 4572542132337197059u, 105569857919u },
3729 { 11943971043551974038u, 12600500455757416832u, 127247878005u },
3730 { 12472773152119929647u, 7873789864743195199u, 117683074498u },
3731 { 7791259796982183085u, 15724851676325671539u, 194426839003u },
3732 { 16866829442051086686u, 8748017220462413167u, 219852445917u },
3733 { 3702498393844653053u, 14172589522760466448u, 221474230963u },
3734 { 2057239613841701716u, 9520545591489413768u, 179768297617u },
3735 { 17201969976738286226u, 12488551088392570222u, 145516109810u },
3736 { 18271566505443461640u, 1135798823651241684u, 242677005711u },
3737 { 18368509115417119804u, 11168725610120161972u, 143061571777u },
3738 { 7613923684154518587u, 9580104948718508826u, 193605457828u },
3739 { 17984805084714865232u, 16638722716909738765u, 164519338529u },
3740 { 4220802739051410373u, 15732724012348272797u, 33901986965u },
3741 { 17812459042810815760u, 12269722190021214142u, 149852872677u },
3742 { 10629526089664605307u, 13110655916311972587u, 229665142972u },
3743 { 17437443267816548473u, 6618112997062866867u, 188710730081u },
3744 { 12506371893701049304u, 8457936459015989309u, 97358768624u },
3745 { 15737221540003030739u, 3329167139937134914u, 240458505654u },
3746 { 2358380859011605513u, 5245511557216705097u, 182180474512u },
3747 { 10042972713837039706u, 5655931353280440466u, 144284359751u },
3748 { 13424397272769642495u, 604622132328697393u, 71306608653u },
3749 { 6867102315755663029u, 8673282619234652338u, 13032776631u },
3750 { 8690748404825506734u, 16929477433058445690u, 183470179592u },
3751 { 956229930815387710u, 11036952409253549455u, 8917748810u },
3752 { 7734449506297687888u, 18199392190170386320u, 74598314388u },
3753 { 16332184961683848151u, 9683116091880335715u, 148986591027u },
3754 { 15580777817612768828u, 2993913337608915120u, 51524922775u },
3755 { 17404245271944696092u, 4490779842162392585u, 151162300367u },
3756 { 13201420160494469229u, 946849923353644618u, 207243445663u },
3757 { 16511717657124068078u, 3613491058474899828u, 159051328837u },
3758 { 14131292492116594062u, 14624054199004410935u, 69195887742u },
3759 { 18429136031865875691u, 12088470271991908244u, 126792771566u },
3760 { 2563978348305862197u, 10071980927725011290u, 238655317286u },
3761 { 14239974392147482896u, 2833441711428854664u, 38546003180u },
3762 { 11164201396098998272u, 17655572411864340446u, 236153601182u },
3763 { 7116971104932986880u, 4997642792058747802u, 158957110498u },
3764 { 12437629862867369984u, 11489200787635734848u, 226270922758u },
3765 { 16501893821638901760u, 12983586226429536913u, 6622830822u },
3766 { 10649324268870959104u, 12311150768725063152u, 230703841619u },
3767 { 7205759403792793600u, 8530052476845967905u, 83667388820u },
3768 { 0u, 6282736361499820264u, 148462415071u },
3769 { 0u, 11337164765929082880u, 223340587820u },
3770 { 0u, 8343856200414134272u, 44614588933u },
3771 { 0u, 17889330377156198400u, 5452321350u },
3772 { 0u, 17730714064155312128u, 70969782542u },
3773 { 0u, 7449235258647511040u, 14961183935u },
3774 { 0u, 9943947977234055168u, 191403823852u },
3775 { 0u, 0u, 236539062500u },
3776 { 0u, 0u, 228000000000u },
3777 { 3016823727048309817u, 7394076u, 0u },
3778 { 17405973192644624358u, 7394076163542341u, 0u },
3779 { 8937219978302591747u, 12396245121240683569u, 400833u },
3780 { 15178463196824222317u, 10248996648596888561u, 193672001794u },
3781 { 11979404627460330594u, 11257495103713935002u, 2555599221u },
3782 { 2006448052689740002u, 7555396579247433114u, 117610270032u },
3783 { 16330465320863239865u, 4805022328730367462u, 80409578869u },
3784 { 17136208883957646553u, 7056637817080232586u, 117260480782u },
3785 { 140455118208931867u, 10811411483818434913u, 14382541102u },
3786 { 3964972929179372247u, 16962406704495245447u, 46586087790u },
3787 { 3378050330022776379u, 18074517319117194669u, 110919533909u },
3788 { 6065353437512901255u, 3702019776117654523u, 85979821547u },
3789 { 12768753059854699889u, 3551977551381082764u, 235200686894u },
3790 { 6848720690951013326u, 16442608985936005282u, 46192553088u },
3791 { 10953228058585475132u, 3580046275479139588u, 128891355619u },
3792 { 15539127852083296166u, 8737412692712715330u, 227194074697u },
3793 { 14534853647735598497u, 3082033243045084752u, 73473656091u },
3794 { 1506909603576368170u, 16401023756841128699u, 27167077356u },
3795 { 5475702579938239025u, 7520296082779572869u, 236889101279u },
3796 { 12039747373985783332u, 9854104766152464159u, 223407676067u },
3797 { 17572399137760898460u, 14169188802648310188u, 163534192089u },
3798 { 869552790852091236u, 2018609909210367042u, 217768113264u },
3799 { 4549585778048181804u, 8270271948267674359u, 112109429062u },
3800 { 4121918231767210357u, 12320338602894572099u, 70448332340u },
3801 { 1558397953312543179u, 17538536685990080547u, 52667886893u },
3802 { 6067524298738069781u, 15833914616956760474u, 45950765978u },
3803 { 5811095224555517056u, 6137696141415969855u, 154858358231u },
3804 { 6440894514158997188u, 9757490468419438919u, 215332725174u },
3805 { 4612748874388784257u, 3566639201356598903u, 182528954618u },
3806 { 9908101430749813367u, 9760900035773954449u, 250193347898u },
3807 { 15150017990912190499u, 3873778773990716438u, 58529139451u },
3808 { 17470426264690059239u, 2295668377270167832u, 251209997968u },
3809 { 9615161096851907726u, 1791721710912807593u, 144124448432u },
3810 { 9227932132124142224u, 10571009006922683279u, 176097129428u },
3811 { 4794113194321211621u, 9840791932778184867u, 212573055546u },
3812 { 391512698859146347u, 11525464956561274613u, 58533470399u },
3813 { 17209658878068655842u, 4435781488897895433u, 191624796707u },
3814 { 3077364726606876150u, 6395563367070996741u, 35240464196u },
3815 { 1952989567673965814u, 15538690795135662932u, 68346704184u },
3816 { 11172860676923186449u, 16294558813563371936u, 56842354115u },
3817 { 17338078544784947239u, 4942096228426070342u, 195883329803u },
3818 { 4593380466519703278u, 6910116424372647153u, 11267911573u },
3819 { 786884753602720052u, 17923400669760829478u, 149374598161u },
3820 { 17848875822468020539u, 4134686917293039955u, 17971629497u },
3821 { 2899664567187130618u, 16857102463116098681u, 185224141826u },
3822 { 2973178834961857409u, 11364321508775167451u, 2913825355u },
3823 { 11117453141176836727u, 7966947780972783899u, 75616061103u },
3824 { 7535238370146462002u, 11261055695926686278u, 175431889104u },
3825 { 10246175467290865448u, 9227040437353594058u, 208610463052u },
3826 { 1203128834127050464u, 7185344074282882061u, 76500198864u },
3827 { 14518048959078919658u, 14197856148610578032u, 208389518282u },
3828 { 1553474987376920024u, 885688687260429427u, 202769667324u },
3829 { 14956572380830948369u, 17407816160380305183u, 252048013279u },
3830 { 7594162606042048292u, 17812728703806357349u, 223943679604u },
3831 { 14461296147288811288u, 17120198191964319867u, 116965629957u },
3832 { 18305427728131488265u, 12091952048375408786u, 5928087803u },
3833 { 10253208939347909876u, 405056939269888281u, 251655506034u },
3834 { 6446028915490812012u, 12485440679452408690u, 114021958180u },
3835 { 12986063676957432257u, 8394369900823444407u, 36676837095u },
3836 { 9769714697972762807u, 2877421667354294258u, 231455059704u },
3837 { 97429465146664592u, 2676980714750756239u, 248155985341u },
3838 { 16395571728207795868u, 6119309228579057021u, 189145119415u },
3839 { 6331668478323650406u, 18203256146533333852u, 183331728417u },
3840 { 18129911846294207040u, 351919978865493747u, 33986800493u },
3841 { 9890094564876124160u, 5190010931882390570u, 109019077620u },
3842 { 12290856656987750400u, 6982466386088036604u, 244281351056u },
3843 { 8498454992640802816u, 4707293888784996898u, 144378520261u },
3844 { 5341660584200896512u, 690306801165964760u, 197255182913u },
3845 { 9288674231451648000u, 12456770961278956704u, 65037421606u },
3846 { 1152921504606846976u, 16946092489294063943u, 38675282906u },
3847 { 0u, 11098404173866185376u, 218918649514u },
3848 { 0u, 15152070965853306880u, 170601645695u },
3849 { 0u, 17370091362040414208u, 127821395412u },
3850 { 0u, 10141938552171134976u, 212941634539u },
3851 { 0u, 10586988556645826560u, 235549795590u },
3852 { 0u, 12169852093061922816u, 6573921799u },
3853 { 0u, 16717361816799281152u, 7659729003u },
3854 { 0u, 0u, 107906250000u },
3855 { 0u, 0u, 16000000000u },
3856 { 15212079674427582639u, 112u, 0u },
3857 { 10179808126814248333u, 112824648491u, 0u },
3858 { 6066766544199222848u, 2144184049294538808u, 6u },
3859 { 6625308131806923532u, 4108002197393276873u, 6116236450u },
3860 { 9122786786400665713u, 6446230217393892753u, 162222695245u },
3861 { 11932880778639151320u, 5571068025259989822u, 77349450840u },
3862 { 3884040911779255011u, 14804812668872528331u, 88302008202u },
3863 { 13441817515637357872u, 17369928488562523047u, 138802570502u },
3864 { 11628577856022352826u, 2967474173531035027u, 6941625710u },
3865 { 13296656925520243654u, 5291425437992807716u, 110160867097u },
3866 { 5020720704545399398u, 14219547193739388064u, 25286848747u },
3867 { 14121973606499014694u, 17720313647158217462u, 235770843197u },
3868 { 3642481034345420114u, 12334850628290578491u, 61960620127u },
3869 { 9845536238569696768u, 7818499847417334620u, 95668673592u },
3870 { 17655403572195686356u, 136007040922198372u, 56423841726u },
3871 { 8377495365136654029u, 8523477092112604449u, 190007372956u },
3872 { 13713682649609025426u, 367934822655966629u, 156462058619u },
3873 { 1367709905452854731u, 12964987687054730050u, 123019945786u },
3874 { 9981467701727208680u, 15267036012420885462u, 58702833390u },
3875 { 6277920117543306205u, 11142900264750765568u, 238827627680u },
3876 { 9344111460418701726u, 13680181547777718603u, 160604057833u },
3877 { 4918507011364617264u, 13001922925761426065u, 233741604127u },
3878 { 6554777203830755259u, 2397730045956515935u, 31704835654u },
3879 { 4198262173120265648u, 4482395522588406288u, 70129981206u },
3880 { 8080325935698446819u, 3255525722490493080u, 22242991148u },
3881 { 12797633874200091733u, 836222287193822098u, 44176482403u },
3882 { 8376502502208665497u, 420898743993182306u, 99045331701u },
3883 { 9891973386793349173u, 11652649973356574054u, 245022816966u },
3884 { 14877430279003795462u, 15058402726661910231u, 198631691420u },
3885 { 8759933935842067041u, 9600134495208339559u, 156816317647u },
3886 { 3753418510388703513u, 14626343323989004842u, 207520424333u },
3887 { 2961383332545305985u, 6813981265331086665u, 141792895660u },
3888 { 2497674184068629507u, 10281745288790487888u, 172369386664u },
3889 { 15244544070742305452u, 17569829347075761940u, 168557374528u },
3890 { 45953573565810823u, 7654580675237889478u, 64952462357u },
3891 { 3960077421351906445u, 16194838649686212364u, 21414955649u },
3892 { 3173330011013883118u, 6495102772252453635u, 129877923962u },
3893 { 11026266219545759160u, 14935159852819761348u, 122352100226u },
3894 { 8886757764964685632u, 17381879863441579697u, 130809636637u },
3895 { 13952322129918090479u, 9062335510435372583u, 29942273595u },
3896 { 4127250666614902202u, 7569219009130126626u, 59491270192u },
3897 { 17649958504065306911u, 12652124168176193362u, 48410328184u },
3898 { 13269305359002216873u, 8940200224697247767u, 120685873025u },
3899 { 16236593433831947843u, 5600570701927432884u, 129484649225u },
3900 { 13580930396682424057u, 2018432801986093157u, 9303607546u },
3901 { 421976357197961116u, 8235849749361824736u, 250109419461u },
3902 { 2962130818798626533u, 9705097287982370040u, 197446466309u },
3903 { 8234383947306356345u, 3517483139049842585u, 5526114378u },
3904 { 4380469931801381425u, 958281614186777760u, 74190683143u },
3905 { 15279887469027055916u, 7336473432636108950u, 7051948550u },
3906 { 8534542821713755552u, 12955383920176764423u, 6397711021u },
3907 { 7814613482565088782u, 10735469126281273789u, 173702312769u },
3908 { 13771954404705323224u, 8637888232514730693u, 65581970947u },
3909 { 4568173274762548144u, 6806336737533581000u, 3468260859u },
3910 { 8105292616250821343u, 16142569672872330321u, 251368972253u },
3911 { 2923678426777275612u, 8141285259947963513u, 221875090455u },
3912 { 1808633176918384049u, 5220241098754220797u, 23441339958u },
3913 { 18118642609460438969u, 154438799943119608u, 54282989837u },
3914 { 18138164175864360870u, 2226876628677628879u, 13008372144u },
3915 { 4031433690465792404u, 17219557081221357482u, 176120719223u },
3916 { 5012226396942308537u, 15401507148161015114u, 119933474059u },
3917 { 7889712298793536835u, 8842629766613985337u, 11834917375u },
3918 { 13500762396543628804u, 3180100571546071440u, 255479359920u },
3919 { 501020624068841347u, 7740848704392475044u, 176172393597u },
3920 { 8370653768288261750u, 2014314126623495998u, 125419632249u },
3921 { 647579990023635200u, 11209566016506885858u, 121109196187u },
3922 { 11106569307181154304u, 7117166613733441125u, 155607671791u },
3923 { 10797461613892861952u, 4197646860931880328u, 239385822375u },
3924 { 17627230675448889344u, 5487263271238026094u, 167227554892u },
3925 { 12197735707942322176u, 18148076225293562697u, 76297465137u },
3926 { 12871287735024877568u, 9127276943027950849u, 49983809183u },
3927 { 4611686018427387904u, 9691696125379324722u, 159494790674u },
3928 { 0u, 13102362262487705216u, 18525387899u },
3929 { 0u, 8929385439893192704u, 123710280481u },
3930 { 0u, 11891353410743566336u, 33484062954u },
3931 { 0u, 1587423090877399040u, 234644631560u },
3932 { 0u, 3489137423026225152u, 8086054378u },
3933 { 0u, 13046928120492326912u, 234189146518u },
3934 { 0u, 11529215046068469760u, 150707275390u },
3935 { 0u, 0u, 126625000000u },
3936 { 0u, 0u, 64000000000u },
3937 { 9451803574512021605u, 1721567u, 0u },
3938 { 8662766454758138424u, 1721567512383298u, 0u },
3939 { 9207992007314947035u, 6674960280855494694u, 93326u },
3940 { 17118602861291201802u, 16378845781483497510u, 142361850321u },
3941 { 11186560605745599967u, 17606907750956804392u, 209887899008u },
3942 { 10505549821532796847u, 13225609159240506969u, 128954472381u },
3943 { 18133667530488679216u, 2668084873338435252u, 189716961709u },
3944 { 10778135771244330799u, 14802814305275861366u, 173144637170u },
3945 { 17087985777033767391u, 8005510553372365574u, 242802462171u },
3946 { 2639185991757283040u, 12748500143273514429u, 219433979596u },
3947 { 5401720287293896400u, 10393733905569036127u, 204691097577u },
3948 { 9816495392633895233u, 603389089974790339u, 233563445444u },
3949 { 10042051500090034990u, 2033494532597735873u, 196032709788u },
3950 { 11629689537856384738u, 9204796763694620958u, 156110235959u },
3951 { 2099086731766010483u, 7826260310402107021u, 55498993032u },
3952 { 13665537898516458594u, 10122690201685169383u, 136424262421u },
3953 { 16375672064669490764u, 7438455564568110133u, 21548752135u },
3954 { 7770550512184564348u, 2805412574380520817u, 7403239484u },
3955 { 6197048880720627314u, 7250965427231182867u, 60152081720u },
3956 { 17963594118523106281u, 8136242944826085924u, 56393075623u },
3957 { 8255454642407818663u, 15357191647956011780u, 167441066613u },
3958 { 16744201957549498409u, 7369614426695395460u, 117832515027u },
3959 { 17442505417202859722u, 10886957545142526638u, 211399507598u },
3960 { 6383975767786687150u, 2030047207417538097u, 142590183151u },
3961 { 15245442964998335795u, 11557093828502314355u, 239110049079u },
3962 { 2910016124519524433u, 15201062539664128543u, 55626511311u },
3963 { 3847913871169988463u, 8846936323343880674u, 207824051251u },
3964 { 17210451512590059177u, 1485291750116245364u, 51479593379u },
3965 { 17899408909991454145u, 2076024439668322013u, 163080517827u },
3966 { 5920601932753251608u, 7029497773682748741u, 195112541510u },
3967 { 16521781895108979744u, 16333533921668749881u, 70381069837u },
3968 { 3697493405554698771u, 2065057316131928423u, 13885442648u },
3969 { 2816108280295732065u, 7800502648925570223u, 88111946981u },
3970 { 14251078772056398988u, 17011619967093802015u, 229422866095u },
3971 { 4543066550096031417u, 5368819344429198672u, 175922201766u },
3972 { 3099369389734296977u, 15598879366754275267u, 166291044279u },
3973 { 5243484113636490986u, 16393893486035835647u, 183845616944u },
3974 { 6823370511605197226u, 12042046205096920307u, 48888714746u },
3975 { 11396290277624641942u, 15437070428008474344u, 250652800632u },
3976 { 15934361408437566099u, 13704569163204647509u, 120836845264u },
3977 { 14939272230935131954u, 18192483750856993350u, 208742926182u },
3978 { 7500666177940329347u, 5152535865317963250u, 102986216520u },
3979 { 4806714453065462270u, 17512614083933854680u, 72279319528u },
3980 { 11557851247268441487u, 14481918350603613536u, 232949360711u },
3981 { 10655523157206817381u, 16124419709964004915u, 71785066366u },
3982 { 14769600176490881210u, 18088011566435813579u, 126874106543u },
3983 { 16688495540925795167u, 15008862380698848893u, 175980553071u },
3984 { 909793965395524173u, 18160498644611827812u, 111813632059u },
3985 { 12724590949761703756u, 3604680497457231965u, 59984482604u },
3986 { 10810739657314826395u, 5957615565551495921u, 44195410121u },
3987 { 2431218615388671301u, 17528455034961565995u, 201322962986u },
3988 { 4235001167959059286u, 8503772325120113809u, 42950219451u },
3989 { 6253317787396334247u, 8501492578048509537u, 187460990421u },
3990 { 9534525563070371898u, 2296237701094386060u, 213460866836u },
3991 { 8392783992374030728u, 3753593040591076946u, 20124479295u },
3992 { 16356257019231647540u, 8518075399775653155u, 63203482686u },
3993 { 12896334001521091877u, 12757855675959554597u, 62461765792u },
3994 { 1427636373320877084u, 121631169379748595u, 160691604742u },
3995 { 16116755731295043521u, 16679062494579173314u, 6006593638u },
3996 { 15945633911163986837u, 10739912744743898054u, 102904173789u },
3997 { 7510154241072743838u, 9367340677776287570u, 221582211836u },
3998 { 3571560509790395119u, 12227321512794715397u, 252507804555u },
3999 { 3576991649007035076u, 7241061891859170651u, 139662844427u },
4000 { 15509961892750732443u, 13148571323079237489u, 11392538751u },
4001 { 17789791359353349378u, 12509763434355012654u, 127712785479u },
4002 { 18331227331079738314u, 11812768946960181977u, 71678155634u },
4003 { 15386712883100476416u, 14170358803552564832u, 114640371487u },
4004 { 14082462055028752384u, 18179989524780635952u, 31768176689u },
4005 { 12919043128765186048u, 17091718978514754901u, 49985539206u },
4006 { 6125373368465096704u, 7394768384359232459u, 134926543942u },
4007 { 12335992698065387520u, 6778628272692852803u, 70400871197u },
4008 { 2774217370460225536u, 18193335045875234320u, 29367470174u },
4009 { 0u, 1378519212560967521u, 94986262669u },
4010 { 0u, 4677732610631043584u, 141074729676u },
4011 { 0u, 17296098591070486528u, 204253580392u },
4012 { 0u, 7343735382392963072u, 104937623383u },
4013 { 0u, 14525996728454217728u, 87398104692u },
4014 { 0u, 9691359370008330240u, 116787455860u },
4015 { 0u, 3044433348102455296u, 116525369644u },
4016 { 0u, 9223372036854775808u, 44165039062u },
4017 { 0u, 0u, 214500000000u },
4018 { 4962829537462579598u, 26u, 0u },
4019 { 5711259460785241095u, 26269035528u, 0u },
4020 { 13845894607204897444u, 7822291454600056379u, 1u },
4021 { 12116633056637003327u, 8201586317771250746u, 1424047269u },
4022 { 2965791047992089560u, 3278889188817135834u, 165444608885u },
4023 { 16021997451315962529u, 1710725240251040430u, 117177748939u },
4024 { 3942052271663803856u, 1850175733663425006u, 203092738601u },
4025 { 15669876414782439922u, 9147599666163914249u, 41100298227u },
4026 { 10594415915406145286u, 10221885933644344166u, 243495892371u },
4027 { 10789820553031921377u, 14901479793736678101u, 147554129546u },
4028 { 3989990218583987244u, 5181831442059703136u, 138807810838u },
4029 { 2937341169808224563u, 6396246577759793483u, 22280907645u },
4030 { 16267436558584536843u, 14167229556464870447u, 125346741221u },
4031 { 16221580362814625793u, 2969982933326311854u, 229768007053u },
4032 { 9695437602320209830u, 7892677766222018881u, 141161003097u },
4033 { 10729753156793715126u, 798698968922663621u, 89427862919u },
4034 { 2609241432056861929u, 15926812109043458972u, 135043297557u },
4035 { 8462663743997037565u, 8663842590352697437u, 21863394214u },
4036 { 14993422143908194069u, 17093523026636671168u, 166469667847u },
4037 { 1307443894537745373u, 839764004742743203u, 7926641740u },
4038 { 10017257439419829265u, 16894643909298232323u, 76045523697u },
4039 { 16754772009970777891u, 9066702926218949317u, 241915860481u },
4040 { 11722573031602862387u, 9119392417260546810u, 1491506950u },
4041 { 7363764277467092384u, 9723021096578315109u, 6494363253u },
4042 { 6733958494847390772u, 14787464248751217597u, 117527086029u },
4043 { 8799796600227451045u, 3733434565920249133u, 205801630043u },
4044 { 10512023194742249826u, 6643788868836820841u, 91202389893u },
4045 { 4572542132337197059u, 4729646697422664063u, 133360160516u },
4046 { 12600500455757416832u, 4090144564201555829u, 4256394661u },
4047 { 7873789864743195199u, 2109480737093400002u, 165221727181u },
4048 { 15724851676325671539u, 16577155033369419739u, 205114355179u },
4049 { 8748017220462413167u, 745377248603805917u, 235898649375u },
4050 { 14172589522760466448u, 11305561465807999667u, 31040406981u },
4051 { 9520545591489413768u, 2211245518782892177u, 197612875715u },
4052 { 12488551088392570222u, 14170095199249735666u, 195119871859u },
4053 { 1135798823651241684u, 17849973668116118927u, 115768162399u },
4054 { 11168725610120161972u, 9020960204585720001u, 95967649011u },
4055 { 9580104948718508826u, 10807134002871850916u, 243489027232u },
4056 { 16638722716909738765u, 3925122626254791201u, 160585855908u },
4057 { 15732724012348272797u, 17208463291312718997u, 164212781323u },
4058 { 12269722190021214142u, 5145077219589447653u, 11932872664u },
4059 { 13110655916311972587u, 17602397765035489468u, 216278915194u },
4060 { 6618112997062866867u, 16422643262490753377u, 122954227894u },
4061 { 8457936459015989309u, 2902509461400906224u, 182890273275u },
4062 { 3329167139937134914u, 3422418805967265206u, 251157345353u },
4063 { 5245511557216705097u, 4228874576277237392u, 73185529695u },
4064 { 5655931353280440466u, 2553488530807495751u, 95229247750u },
4065 { 604622132328697393u, 11546099176912486413u, 6138424890u },
4066 { 8673282619234652338u, 10460791037534167991u, 58625915290u },
4067 { 16929477433058445690u, 8127117908566000904u, 154567080618u },
4068 { 11036952409253549455u, 11541304458088287306u, 170440571944u },
4069 { 18199392190170386320u, 6249718665174839700u, 40625655368u },
4070 { 9683116091880335715u, 13102508413386290995u, 72338797927u },
4071 { 2993913337608915120u, 6274675218640661911u, 103710288404u },
4072 { 4490779842162392585u, 3404497118599817167u, 20340150825u },
4073 { 946849923353644618u, 11258566093988562335u, 41184558158u },
4074 { 3613491058474899828u, 16762592482501635397u, 78610328090u },
4075 { 14624054199004410935u, 5550125446725071998u, 26908701959u },
4076 { 12088470271991908244u, 6370033225258510318u, 7300872903u },
4077 { 10071980927725011290u, 1503521728674735398u, 199345320193u },
4078 { 2833441711428854664u, 4250415082606384364u, 1081506076u },
4079 { 17655572411864340446u, 6020091901030562974u, 28230415463u },
4080 { 4997642792058747802u, 16288222967151527138u, 103326349835u },
4081 { 11489200787635734848u, 6377016228656203782u, 11882986336u },
4082 { 12983586226429536913u, 8378856515587563750u, 96345698742u },
4083 { 12311150768725063152u, 15812881490200838483u, 182454218721u },
4084 { 8530052476845967905u, 4548570371183413652u, 225857218023u },
4085 { 6282736361499820264u, 16731431495283420383u, 231246578493u },
4086 { 11337164765929082880u, 14737727629551135532u, 61907012718u },
4087 { 8343856200414134272u, 12413722258104293893u, 110798933815u },
4088 { 17889330377156198400u, 800899742400762438u, 55672949232u },
4089 { 17730714064155312128u, 603197008376033550u, 240043416862u },
4090 { 7449235258647511040u, 6380777281587743935u, 30032699375u },
4091 { 9943947977234055168u, 10001440249018225388u, 239345902629u },
4092 { 0u, 5505914461980436708u, 37542179162u },
4093 { 0u, 1105464290051876864u, 90298476221u },
4094 { 0u, 4500443576769970176u, 189059927339u },
4095 { 0u, 2843045143185981440u, 43243969535u },
4096 { 0u, 660949699682893824u, 255154121786u },
4097 { 0u, 276549164618219520u, 58035830155u },
4098 { 0u, 4683743612465315840u, 139014991760u },
4099 { 0u, 0u, 144253906250u },
4100 { 0u, 0u, 74000000000u },
4101 { 12396245121240683569u, 400833u, 0u },
4102 { 10248996648596888561u, 400833672001794u, 0u },
4103 { 11257495103713935002u, 4370024159708535157u, 21729u },
4104 { 7555396579247433114u, 7166684413908503888u, 225236899484u },
4105 { 4805022328730367462u, 10217286283215687029u, 156388506740u },
4106 { 7056637817080232586u, 4767369911989629198u, 116553880199u },
4107 { 10811411483818434913u, 14407999214182082862u, 135258439640u },
4108 { 16962406704495245447u, 8472271297615317358u, 216781059202u },
4109 { 18074517319117194669u, 6236024012584764757u, 130459282747u },
4110 { 3702019776117654523u, 1951826556984620523u, 59338055539u },
4111 { 3551977551381082764u, 12357130551551830830u, 115105808729u },
4112 { 16442608985936005282u, 8927758011099278464u, 89669881389u },
4113 { 3580046275479139588u, 10199854049407140323u, 45483974731u },
4114 { 8737412692712715330u, 17895455027038549577u, 75552935195u },
4115 { 3082033243045084752u, 16539200343720527131u, 27970114560u },
4116 { 16401023756841128699u, 3536976106235802604u, 896591847u },
4117 { 7520296082779572869u, 16980391644793590751u, 231191739858u },
4118 { 9854104766152464159u, 10090294316609084067u, 210920508875u },
4119 { 14169188802648310188u, 17603457857266236889u, 203546995950u },
4120 { 2018609909210367042u, 11164962743035868272u, 238954285362u },
4121 { 8270271948267674359u, 1585686890718568774u, 50605253843u },
4122 { 12320338602894572099u, 10882524700472655412u, 211085960258u },
4123 { 17538536685990080547u, 2194808754940947757u, 66589942846u },
4124 { 15833914616956760474u, 274100791137209242u, 62118980821u },
4125 { 6137696141415969855u, 12203404582981010903u, 213014859033u },
4126 { 9757490468419438919u, 541940706340938166u, 25661547888u },
4127 { 3566639201356598903u, 10305434016011833594u, 112029378664u },
4128 { 9760900035773954449u, 7900783531944543546u, 104558658697u },
4129 { 3873778773990716438u, 8920818625012419323u, 137428302333u },
4130 { 2295668377270167832u, 12532363335400447632u, 253483598546u },
4131 { 1791721710912807593u, 13483507182924762800u, 210679380777u },
4132 { 10571009006922683279u, 415911049779278804u, 41730942389u },
4133 { 9840791932778184867u, 3441628281170127418u, 181022546583u },
4134 { 11525464956561274613u, 17830811568183566527u, 151186571042u },
4135 { 4435781488897895433u, 17897295813176613411u, 34966610231u },
4136 { 6395563367070996741u, 2086148701331574596u, 55970214350u },
4137 { 15538690795135662932u, 13015567826878853432u, 206113090347u },
4138 { 16294558813563371936u, 12944531121587846595u, 43705575345u },
4139 { 4942096228426070342u, 3534180912913737995u, 177701724438u },
4140 { 6910116424372647153u, 3447584022400118677u, 22191588331u },
4141 { 17923400669760829478u, 6375676813770849297u, 235186893904u },
4142 { 4134686917293039955u, 11580694081479200185u, 80345626132u },
4143 { 16857102463116098681u, 1872134358882196482u, 20627790684u },
4144 { 11364321508775167451u, 17602652840520938059u, 92101488606u },
4145 { 7966947780972783899u, 10331040597716338351u, 222954241722u },
4146 { 11261055695926686278u, 73785407041056976u, 186560046833u },
4147 { 9227040437353594058u, 17166209109167902028u, 241003999914u },
4148 { 7185344074282882061u, 8762475644006589904u, 170930582060u },
4149 { 14197856148610578032u, 8839001228645872586u, 44475014756u },
4150 { 885688687260429427u, 13558262784529110268u, 100479163216u },
4151 { 17407816160380305183u, 5640853896420358111u, 80734994898u },
4152 { 17812728703806357349u, 8459930353450835572u, 210305791302u },
4153 { 17120198191964319867u, 7643830211500171269u, 70458613743u },
4154 { 12091952048375408786u, 1308629115231236347u, 239414372866u },
4155 { 405056939269888281u, 8957268500971669618u, 2070940926u },
4156 { 12485440679452408690u, 7645679094277669412u, 254485574498u },
4157 { 8394369900823444407u, 3821107497040617191u, 98414473094u },
4158 { 2877421667354294258u, 8847137191985934072u, 134207142652u },
4159 { 2676980714750756239u, 3531126524756088253u, 252479604268u },
4160 { 6119309228579057021u, 8726915034124352183u, 44191422752u },
4161 { 18203256146533333852u, 17611136727168068641u, 32473087011u },
4162 { 351919978865493747u, 18017743272784259949u, 35954701634u },
4163 { 5190010931882390570u, 18113575006829616116u, 66976743819u },
4164 { 6982466386088036604u, 12805550441678740368u, 139981938868u },
4165 { 4707293888784996898u, 8061966093393027781u, 180694190280u },
4166 { 690306801165964760u, 11954593141554100801u, 200437040057u },
4167 { 12456770961278956704u, 14068656112359197734u, 185648059792u },
4168 { 16946092489294063943u, 895878255770467290u, 144762663376u },
4169 { 11098404173866185376u, 10319906489512197802u, 208048565657u },
4170 { 15152070965853306880u, 14551142616794302079u, 153559443251u },
4171 { 17370091362040414208u, 15933181735739307476u, 51788819021u },
4172 { 10141938552171134976u, 11524527334398983147u, 77863739512u },
4173 { 10586988556645826560u, 11828012606225556742u, 120624745878u },
4174 { 12169852093061922816u, 3556238869349799431u, 150641197848u },
4175 { 16717361816799281152u, 7403090230513381483u, 24192784095u },
4176 { 0u, 10172292854665622800u, 223401322325u },
4177 { 0u, 11240746576366182400u, 85551441100u },
4178 { 0u, 17021927826892259328u, 204609362092u },
4179 { 0u, 9046328496309141504u, 172922760556u },
4180 { 0u, 8038996803112140800u, 108490402450u },
4181 { 0u, 17098478935265509376u, 146435794889u },
4182 { 0u, 7205759403792793600u, 201926910400u },
4183 { 0u, 0u, 192390625000u },
4184 { 0u, 0u, 232000000000u },
4185 { 2144184049294538808u, 6u, 0u },
4186 { 4108002197393276873u, 6116236450u, 0u },
4187 { 6446230217393892753u, 6116236450222695245u, 0u },
4188 { 5571068025259989822u, 6240972538554414168u, 331561842u },
4189 { 14804812668872528331u, 4356262642990299018u, 114338323799u },
4190 { 17369928488562523047u, 1335108558830511366u, 87236153471u },
4191 { 2967474173531035027u, 18435704923261947246u, 127072376379u },
4192 { 5291425437992807716u, 8395401931972636441u, 59999401566u },
4193 { 14219547193739388064u, 12482665946362458347u, 94455115650u },
4194 { 17720313647158217462u, 16101242875289374781u, 130676686676u },
4195 { 12334850628290578491u, 4708983440241068127u, 84872850125u },
4196 { 7818499847417334620u, 14856666972541426744u, 205255274503u },
4197 { 136007040922198372u, 6938795288315789246u, 7805381530u },
4198 { 8523477092112604449u, 5556307628265073820u, 154376152846u },
4199 { 367934822655966629u, 1441404248927865979u, 14301208040u },
4200 { 12964987687054730050u, 16710378912353838906u, 232078138680u },
4201 { 15267036012420885462u, 18289940136919312110u, 56905871455u },
4202 { 11142900264750765568u, 10217414145292657824u, 95991499641u },
4203 { 13680181547777718603u, 12461165826430955753u, 121553887130u },
4204 { 13001922925761426065u, 662762458988270879u, 154675521153u },
4205 { 2397730045956515935u, 16488546856395302470u, 129035928424u },
4206 { 4482395522588406288u, 2612816787977180950u, 104893845916u },
4207 { 3255525722490493080u, 16446616379327454252u, 156141641081u },
4208 { 836222287193822098u, 7842178508581740643u, 121891572860u },
4209 { 420898743993182306u, 14779029861369369333u, 124425125348u },
4210 { 11652649973356574054u, 2697664446153849542u, 228801172814u },
4211 { 15058402726661910231u, 12135106444393649308u, 78146240682u },
4212 { 9600134495208339559u, 9550285041205189839u, 170657845438u },
4213 { 14626343323989004842u, 8790318168586740109u, 190517721989u },
4214 { 6813981265331086665u, 14038474217155846828u, 133476524102u },
4215 { 10281745288790487888u, 4263144264274812072u, 70761027212u },
4216 { 17569829347075761940u, 11940456333341715520u, 140231105513u },
4217 { 7654580675237889478u, 15751110736831573013u, 233647293434u },
4218 { 16194838649686212364u, 18384528705472318081u, 250853869423u },
4219 { 6495102772252453635u, 2393654818032310394u, 111996627298u },
4220 { 14935159852819761348u, 12812209822018626434u, 98129760287u },
4221 { 17381879863441579697u, 3110778569433458461u, 31694551286u },
4222 { 9062335510435372583u, 2860264756226872891u, 246168635644u },
4223 { 7569219009130126626u, 2384146980060315184u, 252155055263u },
4224 { 12652124168176193362u, 14117430062880324728u, 159129244866u },
4225 { 8940200224697247767u, 3769610173216737153u, 194765307417u },
4226 { 5600570701927432884u, 17731974340232672009u, 25204350976u },
4227 { 2018432801986093157u, 1971479303384713466u, 961252255u },
4228 { 8235849749361824736u, 3449462959779012549u, 159106874107u },
4229 { 9705097287982370040u, 13743454852043766533u, 251186995761u },
4230 { 3517483139049842585u, 7417711187131879498u, 49745034180u },
4231 { 958281614186777760u, 3650992383501007879u, 196402114929u },
4232 { 7336473432636108950u, 12838770342493958662u, 113197920693u },
4233 { 12955383920176764423u, 16025068246546338477u, 181695991134u },
4234 { 10735469126281273789u, 6579965938260177729u, 94868720690u },
4235 { 8637888232514730693u, 4742939430174291459u, 50356700668u },
4236 { 6806336737533581000u, 13062256857527449083u, 252257115261u },
4237 { 16142569672872330321u, 2301174570202439645u, 125708106363u },
4238 { 8141285259947963513u, 7638687886069412887u, 123124746923u },
4239 { 5220241098754220797u, 936322449610274358u, 171414094100u },
4240 { 154438799943119608u, 12926010544311283981u, 20050758141u },
4241 { 2226876628677628879u, 12647854908989899184u, 253700720435u },
4242 { 17219557081221357482u, 8862093163358513015u, 51685641588u },
4243 { 15401507148161015114u, 444784343917630731u, 116480415033u },
4244 { 8842629766613985337u, 11033952249213387263u, 57024111807u },
4245 { 3180100571546071440u, 18168634046363183536u, 191598151749u },
4246 { 7740848704392475044u, 3837904761417065597u, 69984923625u },
4247 { 2014314126623495998u, 111459007020906105u, 233208053234u },
4248 { 11209566016506885858u, 16191761957496794523u, 242006042204u },
4249 { 7117166613733441125u, 9856250800340378607u, 92877757174u },
4250 { 4197646860931880328u, 9491800102275105959u, 246534308426u },
4251 { 5487263271238026094u, 10777328578953608268u, 74514551514u },
4252 { 18148076225293562697u, 17424440628313779505u, 218584240152u },
4253 { 9127276943027950849u, 3285814872419755679u, 24944580819u },
4254 { 9691696125379324722u, 2824823424107240978u, 211178124381u },
4255 { 13102362262487705216u, 12271707680713669755u, 93153133984u },
4256 { 8929385439893192704u, 6951481875178001185u, 160665250606u },
4257 { 11891353410743566336u, 10202522487003824362u, 46376840587u },
4258 { 1587423090877399040u, 4834668463880990728u, 139553079852u },
4259 { 3489137423026225152u, 10871520987687904746u, 44262087902u },
4260 { 13046928120492326912u, 12057698794225322390u, 222589346333u },
4261 { 11529215046068469760u, 7263351819222681214u, 29653649161u },
4262 { 0u, 1778055686910650944u, 9393747091u },
4263 { 0u, 17108187120491986944u, 147096388591u },
4264 { 0u, 3067636961549221888u, 239927436682u },
4265 { 0u, 16702141595163557888u, 138166296932u },
4266 { 0u, 2432053749942845440u, 100905424910u },
4267 { 0u, 17791470327927144448u, 14131841897u },
4268 { 0u, 1152921504606846976u, 105964477539u },
4269 { 0u, 0u, 99062500000u },
4270 { 0u, 0u, 160000000000u },
4271 { 6674960280855494694u, 93326u, 0u },
4272 { 16378845781483497510u, 93326361850321u, 0u },
4273 { 17606907750956804392u, 4283581425266273664u, 5059u },
4274 { 13225609159240506969u, 6725911039793895357u, 195232213414u },
4275 { 2668084873338435252u, 1188689198788975021u, 166364612368u },
4276 { 14802814305275861366u, 10825527435847761650u, 16064438970u },
4277 { 8005510553372365574u, 3917696829526085083u, 186586853018u },
4278 { 12748500143273514429u, 12646861173976387276u, 154212378770u },
4279 { 10393733905569036127u, 18398576063183996905u, 146685587717u },
4280 { 603389089974790339u, 16919251228485834948u, 5997388806u },
4281 { 2033494532597735873u, 17296019588687185052u, 6917194446u },
4282 { 9204796763694620958u, 12365301604512770359u, 206937619100u },
4283 { 7826260310402107021u, 2814271599679204744u, 156670324343u },
4284 { 10122690201685169383u, 2154994415780170517u, 119152561969u },
4285 { 7438455564568110133u, 6717373824370072839u, 49116822481u },
4286 { 2805412574380520817u, 12709155755801344060u, 209364149564u },
4287 { 7250965427231182867u, 826847911966403896u, 60688964714u },
4288 { 8136242944826085924u, 2277322703890025383u, 106044823515u },
4289 { 15357191647956011780u, 2774508958389496437u, 219123453911u },
4290 { 7369614426695395460u, 245697774950120915u, 215150406432u },
4291 { 10886957545142526638u, 1268929063431863950u, 32013319303u },
4292 { 2030047207417538097u, 6735665673159411439u, 135068788782u },
4293 { 11557093828502314355u, 14734771742997073207u, 46365141167u },
4294 { 15201062539664128543u, 13683287077957612495u, 175798773576u },
4295 { 8846936323343880674u, 15370263741354826803u, 72741772478u },
4296 { 1485291750116245364u, 48035913070297507u, 190833223667u },
4297 { 2076024439668322013u, 1206547475966802115u, 243002604032u },
4298 { 7029497773682748741u, 13512340386605768006u, 65407069u },
4299 { 16333533921668749881u, 2325760467700278797u, 93732505440u },
4300 { 2065057316131928423u, 10848110652847753816u, 96126079727u },
4301 { 7800502648925570223u, 15846378960784301285u, 239588077256u },
4302 { 17011619967093802015u, 14121839924449844911u, 200859033924u },
4303 { 5368819344429198672u, 5147613424753296550u, 68765546476u },
4304 { 15598879366754275267u, 16817040482828810167u, 236279052682u },
4305 { 16393893486035835647u, 5773528746119363888u, 138911653591u },
4306 { 12042046205096920307u, 8716201595536184826u, 215312983620u },
4307 { 15437070428008474344u, 5259122109038474872u, 68472506235u },
4308 { 13704569163204647509u, 14744540084230155984u, 123285097580u },
4309 { 18192483750856993350u, 10719345477982635878u, 108799303119u },
4310 { 5152535865317963250u, 13698037261310555208u, 207581096882u },
4311 { 17512614083933854680u, 16141171632951976936u, 178742572087u },
4312 { 14481918350603613536u, 10060790174955808839u, 55875014667u },
4313 { 16124419709964004915u, 4250043307981877118u, 11545396528u },
4314 { 18088011566435813579u, 7075646198054337199u, 48230395309u },
4315 { 15008862380698848893u, 18141738384245531503u, 173383571548u },
4316 { 18160498644611827812u, 8174370508376809531u, 92983465608u },
4317 { 3604680497457231965u, 3581964982731575596u, 136443133513u },
4318 { 5957615565551495921u, 14798509948722114761u, 73194178710u },
4319 { 17528455034961565995u, 14713923334885122090u, 150802228831u },
4320 { 8503772325120113809u, 5042978054260414139u, 95797643382u },
4321 { 8501492578048509537u, 2052996319372883413u, 118273380388u },
4322 { 2296237701094386060u, 8825683007899981588u, 36111293153u },
4323 { 3753593040591076946u, 9992196755378745151u, 225478441234u },
4324 { 8518075399775653155u, 9301073417573669950u, 18541678071u },
4325 { 12757855675959554597u, 5331614769144850592u, 247504212200u },
4326 { 121631169379748595u, 14354009428310052102u, 232289027415u },
4327 { 16679062494579173314u, 5581221063029119078u, 87778132410u },
4328 { 10739912744743898054u, 1529260335339476189u, 186302558600u },
4329 { 9367340677776287570u, 16483061525949201148u, 136082901368u },
4330 { 12227321512794715397u, 14431217812333089675u, 120893548555u },
4331 { 7241061891859170651u, 3452349151135392267u, 11782317885u },
4332 { 13148571323079237489u, 9075317899834447999u, 61187152222u },
4333 { 12509763434355012654u, 2764331337978901575u, 94491973969u },
4334 { 11812768946960181977u, 1942890683708857202u, 81149854702u },
4335 { 14170358803552564832u, 165089169728028447u, 238105324315u },
4336 { 18179989524780635952u, 15193620741871233073u, 27008949501u },
4337 { 17091718978514754901u, 14995000835194145926u, 253823647830u },
4338 { 7394768384359232459u, 1788823614552255558u, 86812880624u },
4339 { 6778628272692852803u, 8384901184618498845u, 240096972322u },
4340 { 18193335045875234320u, 405511217862281310u, 34454546404u },
4341 { 1378519212560967521u, 3111530463755196557u, 228021982807u },
4342 { 4677732610631043584u, 7893558450035460812u, 87168676404u },
4343 { 17296098591070486528u, 156573858237402216u, 52427910661u },
4344 { 7343735382392963072u, 15915324019419451223u, 5008487885u },
4345 { 14525996728454217728u, 16293363012778802804u, 205862771443u },
4346 { 9691359370008330240u, 14342105318291351412u, 243883264978u },
4347 { 3044433348102455296u, 3788398842525387052u, 210777487087u },
4348 { 9223372036854775808u, 14118764407048307670u, 239205369512u },
4349 { 0u, 2705021334614720768u, 168765379752u },
4350 { 0u, 7017988973805568000u, 168146639500u },
4351 { 0u, 10956732053634154496u, 140380445944u },
4352 { 0u, 14657517938546835456u, 248593965634u },
4353 { 0u, 11268868284797157376u, 66794585639u },
4354 { 0u, 14600669991935148032u, 39610886573u },
4355 { 0u, 4611686018427387904u, 173791503906u },
4356 { 0u, 0u, 34250000000u },
4357 { 0u, 0u, 128000000000u },
4358 { 8201586317771250746u, 1424047269u, 0u },
4359 { 3278889188817135834u, 1424047269444608885u, 0u },
4360 { 1710725240251040430u, 3001188830946823627u, 77197757u },
4361 { 1850175733663425006u, 9732296932705387049u, 189162694772u },
4362 { 9147599666163914249u, 16337535782679529459u, 116527588873u },
4363 { 10221885933644344166u, 7969742269895046547u, 9885659589u },
4364 { 14901479793736678101u, 2923592083903829642u, 197432040594u },
4365 { 5181831442059703136u, 8144196241160608534u, 146158488244u },
4366 { 6396246577759793483u, 16431078457793424253u, 180441497762u },
4367 { 14167229556464870447u, 202362949592775653u, 162890730548u },
4368 { 2969982933326311854u, 8835125248522947981u, 52010970117u },
4369 { 7892677766222018881u, 7959873808777345113u, 5478953099u },
4370 { 798698968922663621u, 14929747122315126151u, 139431505623u },
4371 { 15926812109043458972u, 4310328817360515349u, 215809343213u },
4372 { 8663842590352697437u, 7294899422760201126u, 237233663393u },
4373 { 17093523026636671168u, 2047461597291187207u, 161395457290u },
4374 { 839764004742743203u, 10942374468813517900u, 10110993115u },
4375 { 16894643909298232323u, 10364795403063433969u, 219593187308u },
4376 { 9066702926218949317u, 12330859528790939137u, 236561876684u },
4377 { 9119392417260546810u, 8973160144879916806u, 204668457234u },
4378 { 9723021096578315109u, 2895354388547509877u, 18486435986u },
4379 { 14787464248751217597u, 16766844772497556429u, 146156957475u },
4380 { 3733434565920249133u, 7442407174620948827u, 35908932476u },
4381 { 6643788868836820841u, 6683013428676659077u, 124403453701u },
4382 { 4729646697422664063u, 16713703375071907588u, 5362286883u },
4383 { 4090144564201555829u, 8791044883080637861u, 35906051675u },
4384 { 2109480737093400002u, 602844107089214413u, 91476563498u },
4385 { 16577155033369419739u, 9754832281172880875u, 42032680244u },
4386 { 745377248603805917u, 10587846778003503903u, 52528810517u },
4387 { 11305561465807999667u, 17206244172922947013u, 21573968323u },
4388 { 2211245518782892177u, 11620628420699303875u, 195932752365u },
4389 { 14170095199249735666u, 17864732368219338611u, 237629955528u },
4390 { 17849973668116118927u, 4146383014621345887u, 200968449082u },
4391 { 9020960204585720001u, 11445705075042688243u, 58224775873u },
4392 { 10807134002871850916u, 7369147888966546592u, 193620472915u },
4393 { 3925122626254791201u, 9762476865090597796u, 83399482307u },
4394 { 17208463291312718997u, 5507001428194242827u, 195529224931u },
4395 { 5145077219589447653u, 11371471148365328344u, 227298535145u },
4396 { 17602397765035489468u, 3148788104946538618u, 233616448686u },
4397 { 16422643262490753377u, 3762722308424507574u, 174170696145u },
4398 { 2902509461400906224u, 1156171244825745915u, 209203977585u },
4399 { 3422418805967265206u, 14208921674868257865u, 113062676168u },
4400 { 4228874576277237392u, 7903080886897905503u, 200770267187u },
4401 { 2553488530807495751u, 6367240794154270982u, 51428426873u },
4402 { 11546099176912486413u, 1623672396662369850u, 121345168815u },
4403 { 10460791037534167991u, 18323231215381674394u, 175088019456u },
4404 { 8127117908566000904u, 9842279843006544554u, 993304354u },
4405 { 11541304458088287306u, 7376839231308610600u, 34533551059u },
4406 { 6249718665174839700u, 609751749293657672u, 211399899256u },
4407 { 13102508413386290995u, 10386457966860989799u, 120033054708u },
4408 { 6274675218640661911u, 11160336020836149780u, 244563051014u },
4409 { 3404497118599817167u, 17947559933847409193u, 6605003027u },
4410 { 11258566093988562335u, 10229787001712704590u, 19972939173u },
4411 { 16762592482501635397u, 10441677090043619866u, 165554557864u },
4412 { 5550125446725071998u, 4996681336392922375u, 168566044449u },
4413 { 6370033225258510318u, 124497102381021895u, 33270870638u },
4414 { 1503521728674735398u, 8180812057779384577u, 110006749001u },
4415 { 4250415082606384364u, 5294232873532946716u, 73443482710u },
4416 { 6020091901030562974u, 2885620189169448039u, 86287000939u },
4417 { 16288222967151527138u, 16662526875008170507u, 107156429783u },
4418 { 6377016228656203782u, 15663095032402672480u, 215903277391u },
4419 { 8378856515587563750u, 1824281504410546614u, 79849098083u },
4420 { 15812881490200838483u, 9506565509584809953u, 99098894498u },
4421 { 4548570371183413652u, 16941136942345070055u, 162515351948u },
4422 { 16731431495283420383u, 15924115693705937725u, 140918380873u },
4423 { 14737727629551135532u, 9247807690406628462u, 73863248041u },
4424 { 12413722258104293893u, 7993916633864834871u, 169501324659u },
4425 { 800899742400762438u, 1018504409177639408u, 115433351089u },
4426 { 603197008376033550u, 12097800686634130718u, 177055213234u },
4427 { 6380777281587743935u, 6221488888422637551u, 178655823089u },
4428 { 10001440249018225388u, 8229322865256080421u, 241337267588u },
4429 { 5505914461980436708u, 7927745108183101786u, 132446112486u },
4430 { 1105464290051876864u, 8488683721235326653u, 230429763923u },
4431 { 4500443576769970176u, 11165516518170922283u, 83460172466u },
4432 { 2843045143185981440u, 5463648141113596927u, 178605283863u },
4433 { 660949699682893824u, 3958440403860778042u, 23296184959u },
4434 { 276549164618219520u, 5091534813990256011u, 127214587484u },
4435 { 4683743612465315840u, 6100166970623291280u, 92276012655u },
4436 { 0u, 1913011027739012426u, 111330690714u },
4437 { 0u, 11310957650604221440u, 154103704535u },
4438 { 0u, 16303817257009020928u, 215613168242u },
4439 { 0u, 9090406322154766336u, 114883831704u },
4440 { 0u, 3003279315069566976u, 152492791914u },
4441 { 0u, 16582887146675765248u, 106162808097u },
4442 { 0u, 9691746398101307392u, 33898960113u },
4443 { 0u, 0u, 241525390625u },
4444 { 0u, 0u, 33000000000u },
4445};
4446
4447_LIBCPP_END_NAMESPACE_STD
4448
4449// clang-format on
4450
4451#endif // _LIBCPP_SRC_INCLUDE_RYU_D2FIXED_FULL_TABLE_H
lib/libcxx/src/include/ryu/d2s.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// Copyright (c) Microsoft Corporation.
10// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
11
12// Copyright 2018 Ulf Adams
13// Copyright (c) Microsoft Corporation. All rights reserved.
14
15// Boost Software License - Version 1.0 - August 17th, 2003
16
17// Permission is hereby granted, free of charge, to any person or organization
18// obtaining a copy of the software and accompanying documentation covered by
19// this license (the "Software") to use, reproduce, display, distribute,
20// execute, and transmit the Software, and to prepare derivative works of the
21// Software, and to permit third-parties to whom the Software is furnished to
22// do so, all subject to the following:
23
24// The copyright notices in the Software and this entire statement, including
25// the above license grant, this restriction and the following disclaimer,
26// must be included in all copies of the Software, in whole or in part, and
27// all derivative works of the Software, unless such copies or derivative
28// works are solely in the form of machine-executable object code generated by
29// a source language processor.
30
31// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
34// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
35// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
36// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
37// DEALINGS IN THE SOFTWARE.
38
39#ifndef _LIBCPP_SRC_INCLUDE_RYU_DS2_H
40#define _LIBCPP_SRC_INCLUDE_RYU_DS2_H
41
42// Avoid formatting to keep the changes with the original code minimal.
43// clang-format off
44
45#include "__config"
46
47_LIBCPP_BEGIN_NAMESPACE_STD
48
49inline constexpr int __DOUBLE_MANTISSA_BITS = 52;
50inline constexpr int __DOUBLE_EXPONENT_BITS = 11;
51inline constexpr int __DOUBLE_BIAS = 1023;
52
53inline constexpr int __DOUBLE_POW5_INV_BITCOUNT = 122;
54inline constexpr int __DOUBLE_POW5_BITCOUNT = 121;
55
56[[nodiscard]] to_chars_result __d2s_buffered_n(char* const _First, char* const _Last, const double __f, const chars_format _Fmt);
57
58_LIBCPP_END_NAMESPACE_STD
59
60// clang-format on
61
62#endif // _LIBCPP_SRC_INCLUDE_RYU_DS2_H
lib/libcxx/src/include/ryu/d2s_full_table.h created+368
......@@ -0,0 +1,368 @@
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// Copyright (c) Microsoft Corporation.
10// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
11
12// Copyright 2018 Ulf Adams
13// Copyright (c) Microsoft Corporation. All rights reserved.
14
15// Boost Software License - Version 1.0 - August 17th, 2003
16
17// Permission is hereby granted, free of charge, to any person or organization
18// obtaining a copy of the software and accompanying documentation covered by
19// this license (the "Software") to use, reproduce, display, distribute,
20// execute, and transmit the Software, and to prepare derivative works of the
21// Software, and to permit third-parties to whom the Software is furnished to
22// do so, all subject to the following:
23
24// The copyright notices in the Software and this entire statement, including
25// the above license grant, this restriction and the following disclaimer,
26// must be included in all copies of the Software, in whole or in part, and
27// all derivative works of the Software, unless such copies or derivative
28// works are solely in the form of machine-executable object code generated by
29// a source language processor.
30
31// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
34// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
35// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
36// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
37// DEALINGS IN THE SOFTWARE.
38
39#ifndef _LIBCPP_SRC_INCLUDE_RYU_D2S_FULL_TABLE_H
40#define _LIBCPP_SRC_INCLUDE_RYU_D2S_FULL_TABLE_H
41
42// Avoid formatting to keep the changes with the original code minimal.
43// clang-format off
44
45#include "__config"
46
47_LIBCPP_BEGIN_NAMESPACE_STD
48
49inline constexpr uint64_t __DOUBLE_POW5_INV_SPLIT[292][2] = {
50 { 1u, 288230376151711744u }, { 3689348814741910324u, 230584300921369395u },
51 { 2951479051793528259u, 184467440737095516u }, { 17118578500402463900u, 147573952589676412u },
52 { 12632330341676300947u, 236118324143482260u }, { 10105864273341040758u, 188894659314785808u },
53 { 15463389048156653253u, 151115727451828646u }, { 17362724847566824558u, 241785163922925834u },
54 { 17579528692795369969u, 193428131138340667u }, { 6684925324752475329u, 154742504910672534u },
55 { 18074578149087781173u, 247588007857076054u }, { 18149011334012135262u, 198070406285660843u },
56 { 3451162622983977240u, 158456325028528675u }, { 5521860196774363583u, 253530120045645880u },
57 { 4417488157419490867u, 202824096036516704u }, { 7223339340677503017u, 162259276829213363u },
58 { 7867994130342094503u, 259614842926741381u }, { 2605046489531765280u, 207691874341393105u },
59 { 2084037191625412224u, 166153499473114484u }, { 10713157136084480204u, 265845599156983174u },
60 { 12259874523609494487u, 212676479325586539u }, { 13497248433629505913u, 170141183460469231u },
61 { 14216899864323388813u, 272225893536750770u }, { 11373519891458711051u, 217780714829400616u },
62 { 5409467098425058518u, 174224571863520493u }, { 4965798542738183305u, 278759314981632789u },
63 { 7661987648932456967u, 223007451985306231u }, { 2440241304404055250u, 178405961588244985u },
64 { 3904386087046488400u, 285449538541191976u }, { 17880904128604832013u, 228359630832953580u },
65 { 14304723302883865611u, 182687704666362864u }, { 15133127457049002812u, 146150163733090291u },
66 { 16834306301794583852u, 233840261972944466u }, { 9778096226693756759u, 187072209578355573u },
67 { 15201174610838826053u, 149657767662684458u }, { 2185786488890659746u, 239452428260295134u },
68 { 5437978005854438120u, 191561942608236107u }, { 15418428848909281466u, 153249554086588885u },
69 { 6222742084545298729u, 245199286538542217u }, { 16046240111861969953u, 196159429230833773u },
70 { 1768945645263844993u, 156927543384667019u }, { 10209010661905972635u, 251084069415467230u },
71 { 8167208529524778108u, 200867255532373784u }, { 10223115638361732810u, 160693804425899027u },
72 { 1599589762411131202u, 257110087081438444u }, { 4969020624670815285u, 205688069665150755u },
73 { 3975216499736652228u, 164550455732120604u }, { 13739044029062464211u, 263280729171392966u },
74 { 7301886408508061046u, 210624583337114373u }, { 13220206756290269483u, 168499666669691498u },
75 { 17462981995322520850u, 269599466671506397u }, { 6591687966774196033u, 215679573337205118u },
76 { 12652048002903177473u, 172543658669764094u }, { 9175230360419352987u, 276069853871622551u },
77 { 3650835473593572067u, 220855883097298041u }, { 17678063637842498946u, 176684706477838432u },
78 { 13527506561580357021u, 282695530364541492u }, { 3443307619780464970u, 226156424291633194u },
79 { 6443994910566282300u, 180925139433306555u }, { 5155195928453025840u, 144740111546645244u },
80 { 15627011115008661990u, 231584178474632390u }, { 12501608892006929592u, 185267342779705912u },
81 { 2622589484121723027u, 148213874223764730u }, { 4196143174594756843u, 237142198758023568u },
82 { 10735612169159626121u, 189713759006418854u }, { 12277838550069611220u, 151771007205135083u },
83 { 15955192865369467629u, 242833611528216133u }, { 1696107848069843133u, 194266889222572907u },
84 { 12424932722681605476u, 155413511378058325u }, { 1433148282581017146u, 248661618204893321u },
85 { 15903913885032455010u, 198929294563914656u }, { 9033782293284053685u, 159143435651131725u },
86 { 14454051669254485895u, 254629497041810760u }, { 11563241335403588716u, 203703597633448608u },
87 { 16629290697806691620u, 162962878106758886u }, { 781423413297334329u, 260740604970814219u },
88 { 4314487545379777786u, 208592483976651375u }, { 3451590036303822229u, 166873987181321100u },
89 { 5522544058086115566u, 266998379490113760u }, { 4418035246468892453u, 213598703592091008u },
90 { 10913125826658934609u, 170878962873672806u }, { 10082303693170474728u, 273406340597876490u },
91 { 8065842954536379782u, 218725072478301192u }, { 17520720807854834795u, 174980057982640953u },
92 { 5897060404116273733u, 279968092772225526u }, { 1028299508551108663u, 223974474217780421u },
93 { 15580034865808528224u, 179179579374224336u }, { 17549358155809824511u, 286687326998758938u },
94 { 2971440080422128639u, 229349861599007151u }, { 17134547323305344204u, 183479889279205720u },
95 { 13707637858644275364u, 146783911423364576u }, { 14553522944347019935u, 234854258277383322u },
96 { 4264120725993795302u, 187883406621906658u }, { 10789994210278856888u, 150306725297525326u },
97 { 9885293106962350374u, 240490760476040522u }, { 529536856086059653u, 192392608380832418u },
98 { 7802327114352668369u, 153914086704665934u }, { 1415676938738538420u, 246262538727465495u },
99 { 1132541550990830736u, 197010030981972396u }, { 15663428499760305882u, 157608024785577916u },
100 { 17682787970132668764u, 252172839656924666u }, { 10456881561364224688u, 201738271725539733u },
101 { 15744202878575200397u, 161390617380431786u }, { 17812026976236499989u, 258224987808690858u },
102 { 3181575136763469022u, 206579990246952687u }, { 13613306553636506187u, 165263992197562149u },
103 { 10713244041592678929u, 264422387516099439u }, { 12259944048016053467u, 211537910012879551u },
104 { 6118606423670932450u, 169230328010303641u }, { 2411072648389671274u, 270768524816485826u },
105 { 16686253377679378312u, 216614819853188660u }, { 13349002702143502650u, 173291855882550928u },
106 { 17669055508687693916u, 277266969412081485u }, { 14135244406950155133u, 221813575529665188u },
107 { 240149081334393137u, 177450860423732151u }, { 11452284974360759988u, 283921376677971441u },
108 { 5472479164746697667u, 227137101342377153u }, { 11756680961281178780u, 181709681073901722u },
109 { 2026647139541122378u, 145367744859121378u }, { 18000030682233437097u, 232588391774594204u },
110 { 18089373360528660001u, 186070713419675363u }, { 3403452244197197031u, 148856570735740291u },
111 { 16513570034941246220u, 238170513177184465u }, { 13210856027952996976u, 190536410541747572u },
112 { 3189987192878576934u, 152429128433398058u }, { 1414630693863812771u, 243886605493436893u },
113 { 8510402184574870864u, 195109284394749514u }, { 10497670562401807014u, 156087427515799611u },
114 { 9417575270359070576u, 249739884025279378u }, { 14912757845771077107u, 199791907220223502u },
115 { 4551508647133041040u, 159833525776178802u }, { 10971762650154775986u, 255733641241886083u },
116 { 16156107749607641435u, 204586912993508866u }, { 9235537384944202825u, 163669530394807093u },
117 { 11087511001168814197u, 261871248631691349u }, { 12559357615676961681u, 209496998905353079u },
118 { 13736834907283479668u, 167597599124282463u }, { 18289587036911657145u, 268156158598851941u },
119 { 10942320814787415393u, 214524926879081553u }, { 16132554281313752961u, 171619941503265242u },
120 { 11054691591134363444u, 274591906405224388u }, { 16222450902391311402u, 219673525124179510u },
121 { 12977960721913049122u, 175738820099343608u }, { 17075388340318968271u, 281182112158949773u },
122 { 2592264228029443648u, 224945689727159819u }, { 5763160197165465241u, 179956551781727855u },
123 { 9221056315464744386u, 287930482850764568u }, { 14755542681855616155u, 230344386280611654u },
124 { 15493782960226403247u, 184275509024489323u }, { 1326979923955391628u, 147420407219591459u },
125 { 9501865507812447252u, 235872651551346334u }, { 11290841220991868125u, 188698121241077067u },
126 { 1653975347309673853u, 150958496992861654u }, { 10025058185179298811u, 241533595188578646u },
127 { 4330697733401528726u, 193226876150862917u }, { 14532604630946953951u, 154581500920690333u },
128 { 1116074521063664381u, 247330401473104534u }, { 4582208431592841828u, 197864321178483627u },
129 { 14733813189500004432u, 158291456942786901u }, { 16195403473716186445u, 253266331108459042u },
130 { 5577625149489128510u, 202613064886767234u }, { 8151448934333213131u, 162090451909413787u },
131 { 16731667109675051333u, 259344723055062059u }, { 17074682502481951390u, 207475778444049647u },
132 { 6281048372501740465u, 165980622755239718u }, { 6360328581260874421u, 265568996408383549u },
133 { 8777611679750609860u, 212455197126706839u }, { 10711438158542398211u, 169964157701365471u },
134 { 9759603424184016492u, 271942652322184754u }, { 11497031554089123517u, 217554121857747803u },
135 { 16576322872755119460u, 174043297486198242u }, { 11764721337440549842u, 278469275977917188u },
136 { 16790474699436260520u, 222775420782333750u }, { 13432379759549008416u, 178220336625867000u },
137 { 3045063541568861850u, 285152538601387201u }, { 17193446092222730773u, 228122030881109760u },
138 { 13754756873778184618u, 182497624704887808u }, { 18382503128506368341u, 145998099763910246u },
139 { 3586563302416817083u, 233596959622256395u }, { 2869250641933453667u, 186877567697805116u },
140 { 17052795772514404226u, 149502054158244092u }, { 12527077977055405469u, 239203286653190548u },
141 { 17400360011128145022u, 191362629322552438u }, { 2852241564676785048u, 153090103458041951u },
142 { 15631632947708587046u, 244944165532867121u }, { 8815957543424959314u, 195955332426293697u },
143 { 18120812478965698421u, 156764265941034957u }, { 14235904707377476180u, 250822825505655932u },
144 { 4010026136418160298u, 200658260404524746u }, { 17965416168102169531u, 160526608323619796u },
145 { 2919224165770098987u, 256842573317791675u }, { 2335379332616079190u, 205474058654233340u },
146 { 1868303466092863352u, 164379246923386672u }, { 6678634360490491686u, 263006795077418675u },
147 { 5342907488392393349u, 210405436061934940u }, { 4274325990713914679u, 168324348849547952u },
148 { 10528270399884173809u, 269318958159276723u }, { 15801313949391159694u, 215455166527421378u },
149 { 1573004715287196786u, 172364133221937103u }, { 17274202803427156150u, 275782613155099364u },
150 { 17508711057483635243u, 220626090524079491u }, { 10317620031244997871u, 176500872419263593u },
151 { 12818843235250086271u, 282401395870821749u }, { 13944423402941979340u, 225921116696657399u },
152 { 14844887537095493795u, 180736893357325919u }, { 15565258844418305359u, 144589514685860735u },
153 { 6457670077359736959u, 231343223497377177u }, { 16234182506113520537u, 185074578797901741u },
154 { 9297997190148906106u, 148059663038321393u }, { 11187446689496339446u, 236895460861314229u },
155 { 12639306166338981880u, 189516368689051383u }, { 17490142562555006151u, 151613094951241106u },
156 { 2158786396894637579u, 242580951921985771u }, { 16484424376483351356u, 194064761537588616u },
157 { 9498190686444770762u, 155251809230070893u }, { 11507756283569722895u, 248402894768113429u },
158 { 12895553841597688639u, 198722315814490743u }, { 17695140702761971558u, 158977852651592594u },
159 { 17244178680193423523u, 254364564242548151u }, { 10105994129412828495u, 203491651394038521u },
160 { 4395446488788352473u, 162793321115230817u }, { 10722063196803274280u, 260469313784369307u },
161 { 1198952927958798777u, 208375451027495446u }, { 15716557601334680315u, 166700360821996356u },
162 { 17767794532651667857u, 266720577315194170u }, { 14214235626121334286u, 213376461852155336u },
163 { 7682039686155157106u, 170701169481724269u }, { 1223217053622520399u, 273121871170758831u },
164 { 15735968901865657612u, 218497496936607064u }, { 16278123936234436413u, 174797997549285651u },
165 { 219556594781725998u, 279676796078857043u }, { 7554342905309201445u, 223741436863085634u },
166 { 9732823138989271479u, 178993149490468507u }, { 815121763415193074u, 286389039184749612u },
167 { 11720143854957885429u, 229111231347799689u }, { 13065463898708218666u, 183288985078239751u },
168 { 6763022304224664610u, 146631188062591801u }, { 3442138057275642729u, 234609900900146882u },
169 { 13821756890046245153u, 187687920720117505u }, { 11057405512036996122u, 150150336576094004u },
170 { 6623802375033462826u, 240240538521750407u }, { 16367088344252501231u, 192192430817400325u },
171 { 13093670675402000985u, 153753944653920260u }, { 2503129006933649959u, 246006311446272417u },
172 { 13070549649772650937u, 196805049157017933u }, { 17835137349301941396u, 157444039325614346u },
173 { 2710778055689733971u, 251910462920982955u }, { 2168622444551787177u, 201528370336786364u },
174 { 5424246770383340065u, 161222696269429091u }, { 1300097203129523457u, 257956314031086546u },
175 { 15797473021471260058u, 206365051224869236u }, { 8948629602435097724u, 165092040979895389u },
176 { 3249760919670425388u, 264147265567832623u }, { 9978506365220160957u, 211317812454266098u },
177 { 15361502721659949412u, 169054249963412878u }, { 2442311466204457120u, 270486799941460606u },
178 { 16711244431931206989u, 216389439953168484u }, { 17058344360286875914u, 173111551962534787u },
179 { 12535955717491360170u, 276978483140055660u }, { 10028764573993088136u, 221582786512044528u },
180 { 15401709288678291155u, 177266229209635622u }, { 9885339602917624555u, 283625966735416996u },
181 { 4218922867592189321u, 226900773388333597u }, { 14443184738299482427u, 181520618710666877u },
182 { 4175850161155765295u, 145216494968533502u }, { 10370709072591134795u, 232346391949653603u },
183 { 15675264887556728482u, 185877113559722882u }, { 5161514280561562140u, 148701690847778306u },
184 { 879725219414678777u, 237922705356445290u }, { 703780175531743021u, 190338164285156232u },
185 { 11631070584651125387u, 152270531428124985u }, { 162968861732249003u, 243632850284999977u },
186 { 11198421533611530172u, 194906280227999981u }, { 5269388412147313814u, 155925024182399985u },
187 { 8431021459435702103u, 249480038691839976u }, { 3055468352806651359u, 199584030953471981u },
188 { 17201769941212962380u, 159667224762777584u }, { 16454785461715008838u, 255467559620444135u },
189 { 13163828369372007071u, 204374047696355308u }, { 17909760324981426303u, 163499238157084246u },
190 { 2830174816776909822u, 261598781051334795u }, { 2264139853421527858u, 209279024841067836u },
191 { 16568707141704863579u, 167423219872854268u }, { 4373838538276319787u, 267877151796566830u },
192 { 3499070830621055830u, 214301721437253464u }, { 6488605479238754987u, 171441377149802771u },
193 { 3003071137298187333u, 274306203439684434u }, { 6091805724580460189u, 219444962751747547u },
194 { 15941491023890099121u, 175555970201398037u }, { 10748990379256517301u, 280889552322236860u },
195 { 8599192303405213841u, 224711641857789488u }, { 14258051472207991719u, 179769313486231590u }
196};
197
198inline constexpr uint64_t __DOUBLE_POW5_SPLIT[326][2] = {
199 { 0u, 72057594037927936u }, { 0u, 90071992547409920u },
200 { 0u, 112589990684262400u }, { 0u, 140737488355328000u },
201 { 0u, 87960930222080000u }, { 0u, 109951162777600000u },
202 { 0u, 137438953472000000u }, { 0u, 85899345920000000u },
203 { 0u, 107374182400000000u }, { 0u, 134217728000000000u },
204 { 0u, 83886080000000000u }, { 0u, 104857600000000000u },
205 { 0u, 131072000000000000u }, { 0u, 81920000000000000u },
206 { 0u, 102400000000000000u }, { 0u, 128000000000000000u },
207 { 0u, 80000000000000000u }, { 0u, 100000000000000000u },
208 { 0u, 125000000000000000u }, { 0u, 78125000000000000u },
209 { 0u, 97656250000000000u }, { 0u, 122070312500000000u },
210 { 0u, 76293945312500000u }, { 0u, 95367431640625000u },
211 { 0u, 119209289550781250u }, { 4611686018427387904u, 74505805969238281u },
212 { 10376293541461622784u, 93132257461547851u }, { 8358680908399640576u, 116415321826934814u },
213 { 612489549322387456u, 72759576141834259u }, { 14600669991935148032u, 90949470177292823u },
214 { 13639151471491547136u, 113686837721616029u }, { 3213881284082270208u, 142108547152020037u },
215 { 4314518811765112832u, 88817841970012523u }, { 781462496279003136u, 111022302462515654u },
216 { 10200200157203529728u, 138777878078144567u }, { 13292654125893287936u, 86736173798840354u },
217 { 7392445620511834112u, 108420217248550443u }, { 4628871007212404736u, 135525271560688054u },
218 { 16728102434789916672u, 84703294725430033u }, { 7075069988205232128u, 105879118406787542u },
219 { 18067209522111315968u, 132348898008484427u }, { 8986162942105878528u, 82718061255302767u },
220 { 6621017659204960256u, 103397576569128459u }, { 3664586055578812416u, 129246970711410574u },
221 { 16125424340018921472u, 80779356694631608u }, { 1710036351314100224u, 100974195868289511u },
222 { 15972603494424788992u, 126217744835361888u }, { 9982877184015493120u, 78886090522101180u },
223 { 12478596480019366400u, 98607613152626475u }, { 10986559581596820096u, 123259516440783094u },
224 { 2254913720070624656u, 77037197775489434u }, { 12042014186943056628u, 96296497219361792u },
225 { 15052517733678820785u, 120370621524202240u }, { 9407823583549262990u, 75231638452626400u },
226 { 11759779479436578738u, 94039548065783000u }, { 14699724349295723422u, 117549435082228750u },
227 { 4575641699882439235u, 73468396926392969u }, { 10331238143280436948u, 91835496157991211u },
228 { 8302361660673158281u, 114794370197489014u }, { 1154580038986672043u, 143492962746861268u },
229 { 9944984561221445835u, 89683101716788292u }, { 12431230701526807293u, 112103877145985365u },
230 { 1703980321626345405u, 140129846432481707u }, { 17205888765512323542u, 87581154020301066u },
231 { 12283988920035628619u, 109476442525376333u }, { 1519928094762372062u, 136845553156720417u },
232 { 12479170105294952299u, 85528470722950260u }, { 15598962631618690374u, 106910588403687825u },
233 { 5663645234241199255u, 133638235504609782u }, { 17374836326682913246u, 83523897190381113u },
234 { 7883487353071477846u, 104404871487976392u }, { 9854359191339347308u, 130506089359970490u },
235 { 10770660513014479971u, 81566305849981556u }, { 13463325641268099964u, 101957882312476945u },
236 { 2994098996302961243u, 127447352890596182u }, { 15706369927971514489u, 79654595556622613u },
237 { 5797904354682229399u, 99568244445778267u }, { 2635694424925398845u, 124460305557222834u },
238 { 6258995034005762182u, 77787690973264271u }, { 3212057774079814824u, 97234613716580339u },
239 { 17850130272881932242u, 121543267145725423u }, { 18073860448192289507u, 75964541966078389u },
240 { 8757267504958198172u, 94955677457597987u }, { 6334898362770359811u, 118694596821997484u },
241 { 13182683513586250689u, 74184123013748427u }, { 11866668373555425458u, 92730153767185534u },
242 { 5609963430089506015u, 115912692208981918u }, { 17341285199088104971u, 72445432630613698u },
243 { 12453234462005355406u, 90556790788267123u }, { 10954857059079306353u, 113195988485333904u },
244 { 13693571323849132942u, 141494985606667380u }, { 17781854114260483896u, 88434366004167112u },
245 { 3780573569116053255u, 110542957505208891u }, { 114030942967678664u, 138178696881511114u },
246 { 4682955357782187069u, 86361685550944446u }, { 15077066234082509644u, 107952106938680557u },
247 { 5011274737320973344u, 134940133673350697u }, { 14661261756894078100u, 84337583545844185u },
248 { 4491519140835433913u, 105421979432305232u }, { 5614398926044292391u, 131777474290381540u },
249 { 12732371365632458552u, 82360921431488462u }, { 6692092170185797382u, 102951151789360578u },
250 { 17588487249587022536u, 128688939736700722u }, { 15604490549419276989u, 80430587335437951u },
251 { 14893927168346708332u, 100538234169297439u }, { 14005722942005997511u, 125672792711621799u },
252 { 15671105866394830300u, 78545495444763624u }, { 1142138259283986260u, 98181869305954531u },
253 { 15262730879387146537u, 122727336632443163u }, { 7233363790403272633u, 76704585395276977u },
254 { 13653390756431478696u, 95880731744096221u }, { 3231680390257184658u, 119850914680120277u },
255 { 4325643253124434363u, 74906821675075173u }, { 10018740084832930858u, 93633527093843966u },
256 { 3300053069186387764u, 117041908867304958u }, { 15897591223523656064u, 73151193042065598u },
257 { 10648616992549794273u, 91438991302581998u }, { 4087399203832467033u, 114298739128227498u },
258 { 14332621041645359599u, 142873423910284372u }, { 18181260187883125557u, 89295889943927732u },
259 { 4279831161144355331u, 111619862429909666u }, { 14573160988285219972u, 139524828037387082u },
260 { 13719911636105650386u, 87203017523366926u }, { 7926517508277287175u, 109003771904208658u },
261 { 684774848491833161u, 136254714880260823u }, { 7345513307948477581u, 85159196800163014u },
262 { 18405263671790372785u, 106448996000203767u }, { 18394893571310578077u, 133061245000254709u },
263 { 13802651491282805250u, 83163278125159193u }, { 3418256308821342851u, 103954097656448992u },
264 { 4272820386026678563u, 129942622070561240u }, { 2670512741266674102u, 81214138794100775u },
265 { 17173198981865506339u, 101517673492625968u }, { 3019754653622331308u, 126897091865782461u },
266 { 4193189667727651020u, 79310682416114038u }, { 14464859121514339583u, 99138353020142547u },
267 { 13469387883465536574u, 123922941275178184u }, { 8418367427165960359u, 77451838296986365u },
268 { 15134645302384838353u, 96814797871232956u }, { 471562554271496325u, 121018497339041196u },
269 { 9518098633274461011u, 75636560836900747u }, { 7285937273165688360u, 94545701046125934u },
270 { 18330793628311886258u, 118182126307657417u }, { 4539216990053847055u, 73863828942285886u },
271 { 14897393274422084627u, 92329786177857357u }, { 4786683537745442072u, 115412232722321697u },
272 { 14520892257159371055u, 72132645451451060u }, { 18151115321449213818u, 90165806814313825u },
273 { 8853836096529353561u, 112707258517892282u }, { 1843923083806916143u, 140884073147365353u },
274 { 12681666973447792349u, 88052545717103345u }, { 2017025661527576725u, 110065682146379182u },
275 { 11744654113764246714u, 137582102682973977u }, { 422879793461572340u, 85988814176858736u },
276 { 528599741826965425u, 107486017721073420u }, { 660749677283706782u, 134357522151341775u },
277 { 7330497575943398595u, 83973451344588609u }, { 13774807988356636147u, 104966814180735761u },
278 { 3383451930163631472u, 131208517725919702u }, { 15949715511634433382u, 82005323578699813u },
279 { 6102086334260878016u, 102506654473374767u }, { 3015921899398709616u, 128133318091718459u },
280 { 18025852251620051174u, 80083323807324036u }, { 4085571240815512351u, 100104154759155046u },
281 { 14330336087874166247u, 125130193448943807u }, { 15873989082562435760u, 78206370905589879u },
282 { 15230800334775656796u, 97757963631987349u }, { 5203442363187407284u, 122197454539984187u },
283 { 946308467778435600u, 76373409087490117u }, { 5794571603150432404u, 95466761359362646u },
284 { 16466586540792816313u, 119333451699203307u }, { 7985773578781816244u, 74583407312002067u },
285 { 5370530955049882401u, 93229259140002584u }, { 6713163693812353001u, 116536573925003230u },
286 { 18030785363914884337u, 72835358703127018u }, { 13315109668038829614u, 91044198378908773u },
287 { 2808829029766373305u, 113805247973635967u }, { 17346094342490130344u, 142256559967044958u },
288 { 6229622945628943561u, 88910349979403099u }, { 3175342663608791547u, 111137937474253874u },
289 { 13192550366365765242u, 138922421842817342u }, { 3633657960551215372u, 86826513651760839u },
290 { 18377130505971182927u, 108533142064701048u }, { 4524669058754427043u, 135666427580876311u },
291 { 9745447189362598758u, 84791517238047694u }, { 2958436949848472639u, 105989396547559618u },
292 { 12921418224165366607u, 132486745684449522u }, { 12687572408530742033u, 82804216052780951u },
293 { 11247779492236039638u, 103505270065976189u }, { 224666310012885835u, 129381587582470237u },
294 { 2446259452971747599u, 80863492239043898u }, { 12281196353069460307u, 101079365298804872u },
295 { 15351495441336825384u, 126349206623506090u }, { 14206370669262903769u, 78968254139691306u },
296 { 8534591299723853903u, 98710317674614133u }, { 15279925143082205283u, 123387897093267666u },
297 { 14161639232853766206u, 77117435683292291u }, { 13090363022639819853u, 96396794604115364u },
298 { 16362953778299774816u, 120495993255144205u }, { 12532689120651053212u, 75309995784465128u },
299 { 15665861400813816515u, 94137494730581410u }, { 10358954714162494836u, 117671868413226763u },
300 { 4168503687137865320u, 73544917758266727u }, { 598943590494943747u, 91931147197833409u },
301 { 5360365506546067587u, 114913933997291761u }, { 11312142901609972388u, 143642417496614701u },
302 { 9375932322719926695u, 89776510935384188u }, { 11719915403399908368u, 112220638669230235u },
303 { 10038208235822497557u, 140275798336537794u }, { 10885566165816448877u, 87672373960336121u },
304 { 18218643725697949000u, 109590467450420151u }, { 18161618638695048346u, 136988084313025189u },
305 { 13656854658398099168u, 85617552695640743u }, { 12459382304570236056u, 107021940869550929u },
306 { 1739169825430631358u, 133777426086938662u }, { 14922039196176308311u, 83610891304336663u },
307 { 14040862976792997485u, 104513614130420829u }, { 3716020665709083144u, 130642017663026037u },
308 { 4628355925281870917u, 81651261039391273u }, { 10397130925029726550u, 102064076299239091u },
309 { 8384727637859770284u, 127580095374048864u }, { 5240454773662356427u, 79737559608780540u },
310 { 6550568467077945534u, 99671949510975675u }, { 3576524565420044014u, 124589936888719594u },
311 { 6847013871814915412u, 77868710555449746u }, { 17782139376623420074u, 97335888194312182u },
312 { 13004302183924499284u, 121669860242890228u }, { 17351060901807587860u, 76043662651806392u },
313 { 3242082053549933210u, 95054578314757991u }, { 17887660622219580224u, 118818222893447488u },
314 { 11179787888887237640u, 74261389308404680u }, { 13974734861109047050u, 92826736635505850u },
315 { 8245046539531533005u, 116033420794382313u }, { 16682369133275677888u, 72520887996488945u },
316 { 7017903361312433648u, 90651109995611182u }, { 17995751238495317868u, 113313887494513977u },
317 { 8659630992836983623u, 141642359368142472u }, { 5412269370523114764u, 88526474605089045u },
318 { 11377022731581281359u, 110658093256361306u }, { 4997906377621825891u, 138322616570451633u },
319 { 14652906532082110942u, 86451635356532270u }, { 9092761128247862869u, 108064544195665338u },
320 { 2142579373455052779u, 135080680244581673u }, { 12868327154477877747u, 84425425152863545u },
321 { 2250350887815183471u, 105531781441079432u }, { 2812938609768979339u, 131914726801349290u },
322 { 6369772649532999991u, 82446704250843306u }, { 17185587848771025797u, 103058380313554132u },
323 { 3035240737254230630u, 128822975391942666u }, { 6508711479211282048u, 80514359619964166u },
324 { 17359261385868878368u, 100642949524955207u }, { 17087390713908710056u, 125803686906194009u },
325 { 3762090168551861929u, 78627304316371256u }, { 4702612710689827411u, 98284130395464070u },
326 { 15101637925217060072u, 122855162994330087u }, { 16356052730901744401u, 76784476871456304u },
327 { 1998321839917628885u, 95980596089320381u }, { 7109588318324424010u, 119975745111650476u },
328 { 13666864735807540814u, 74984840694781547u }, { 12471894901332038114u, 93731050868476934u },
329 { 6366496589810271835u, 117163813585596168u }, { 3979060368631419896u, 73227383490997605u },
330 { 9585511479216662775u, 91534229363747006u }, { 2758517312166052660u, 114417786704683758u },
331 { 12671518677062341634u, 143022233380854697u }, { 1002170145522881665u, 89388895863034186u },
332 { 10476084718758377889u, 111736119828792732u }, { 13095105898447972362u, 139670149785990915u },
333 { 5878598177316288774u, 87293843616244322u }, { 16571619758500136775u, 109117304520305402u },
334 { 11491152661270395161u, 136396630650381753u }, { 264441385652915120u, 85247894156488596u },
335 { 330551732066143900u, 106559867695610745u }, { 5024875683510067779u, 133199834619513431u },
336 { 10058076329834874218u, 83249896637195894u }, { 3349223375438816964u, 104062370796494868u },
337 { 4186529219298521205u, 130077963495618585u }, { 14145795808130045513u, 81298727184761615u },
338 { 13070558741735168987u, 101623408980952019u }, { 11726512408741573330u, 127029261226190024u },
339 { 7329070255463483331u, 79393288266368765u }, { 13773023837756742068u, 99241610332960956u },
340 { 17216279797195927585u, 124052012916201195u }, { 8454331864033760789u, 77532508072625747u },
341 { 5956228811614813082u, 96915635090782184u }, { 7445286014518516353u, 121144543863477730u },
342 { 9264989777501460624u, 75715339914673581u }, { 16192923240304213684u, 94644174893341976u },
343 { 1794409976670715490u, 118305218616677471u }, { 8039035263060279037u, 73940761635423419u },
344 { 5437108060397960892u, 92425952044279274u }, { 16019757112352226923u, 115532440055349092u },
345 { 788976158365366019u, 72207775034593183u }, { 14821278253238871236u, 90259718793241478u },
346 { 9303225779693813237u, 112824648491551848u }, { 11629032224617266546u, 141030810614439810u },
347 { 11879831158813179495u, 88144256634024881u }, { 1014730893234310657u, 110180320792531102u },
348 { 10491785653397664129u, 137725400990663877u }, { 8863209042587234033u, 86078375619164923u },
349 { 6467325284806654637u, 107597969523956154u }, { 17307528642863094104u, 134497461904945192u },
350 { 10817205401789433815u, 84060913690590745u }, { 18133192770664180173u, 105076142113238431u },
351 { 18054804944902837312u, 131345177641548039u }, { 18201782118205355176u, 82090736025967524u },
352 { 4305483574047142354u, 102613420032459406u }, { 14605226504413703751u, 128266775040574257u },
353 { 2210737537617482988u, 80166734400358911u }, { 16598479977304017447u, 100208418000448638u },
354 { 11524727934775246001u, 125260522500560798u }, { 2591268940807140847u, 78287826562850499u },
355 { 17074144231291089770u, 97859783203563123u }, { 16730994270686474309u, 122324729004453904u },
356 { 10456871419179046443u, 76452955627783690u }, { 3847717237119032246u, 95566194534729613u },
357 { 9421332564826178211u, 119457743168412016u }, { 5888332853016361382u, 74661089480257510u },
358 { 16583788103125227536u, 93326361850321887u }, { 16118049110479146516u, 116657952312902359u },
359 { 16991309721690548428u, 72911220195563974u }, { 12015765115258409727u, 91139025244454968u },
360 { 15019706394073012159u, 113923781555568710u }, { 9551260955736489391u, 142404726944460888u },
361 { 5969538097335305869u, 89002954340288055u }, { 2850236603241744433u, 111253692925360069u }
362};
363
364_LIBCPP_END_NAMESPACE_STD
365
366// clang-format on
367
368#endif // _LIBCPP_SRC_INCLUDE_RYU_D2S_FULL_TABLE_H
lib/libcxx/src/include/ryu/d2s_intrinsics.h created+257
......@@ -0,0 +1,257 @@
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// Copyright (c) Microsoft Corporation.
10// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
11
12// Copyright 2018 Ulf Adams
13// Copyright (c) Microsoft Corporation. All rights reserved.
14
15// Boost Software License - Version 1.0 - August 17th, 2003
16
17// Permission is hereby granted, free of charge, to any person or organization
18// obtaining a copy of the software and accompanying documentation covered by
19// this license (the "Software") to use, reproduce, display, distribute,
20// execute, and transmit the Software, and to prepare derivative works of the
21// Software, and to permit third-parties to whom the Software is furnished to
22// do so, all subject to the following:
23
24// The copyright notices in the Software and this entire statement, including
25// the above license grant, this restriction and the following disclaimer,
26// must be included in all copies of the Software, in whole or in part, and
27// all derivative works of the Software, unless such copies or derivative
28// works are solely in the form of machine-executable object code generated by
29// a source language processor.
30
31// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
34// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
35// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
36// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
37// DEALINGS IN THE SOFTWARE.
38
39#ifndef _LIBCPP_SRC_INCLUDE_RYU_DS2_INTRINSICS_H
40#define _LIBCPP_SRC_INCLUDE_RYU_DS2_INTRINSICS_H
41
42// Avoid formatting to keep the changes with the original code minimal.
43// clang-format off
44
45#include "__config"
46
47_LIBCPP_BEGIN_NAMESPACE_STD
48
49#if defined(_M_X64) && defined(_MSC_VER)
50#define _LIBCPP_INTRINSIC128 1
51[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __ryu_umul128(const uint64_t __a, const uint64_t __b, uint64_t* const __productHi) {
52 return _umul128(__a, __b, __productHi);
53}
54
55[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __ryu_shiftright128(const uint64_t __lo, const uint64_t __hi, const uint32_t __dist) {
56 // For the __shiftright128 intrinsic, the shift value is always
57 // modulo 64.
58 // In the current implementation of the double-precision version
59 // of Ryu, the shift value is always < 64.
60 // (The shift value is in the range [49, 58].)
61 // Check this here in case a future change requires larger shift
62 // values. In this case this function needs to be adjusted.
63 _LIBCPP_ASSERT(__dist < 64, "");
64 return __shiftright128(__lo, __hi, static_cast<unsigned char>(__dist));
65}
66
67// ^^^ intrinsics available ^^^ / vvv __int128 available vvv
68#elif defined(__SIZEOF_INT128__) && ( \
69 (defined(__clang__) && !defined(_MSC_VER)) || \
70 (defined(__GNUC__) && !defined(__clang__) && !defined(__CUDACC__)))
71#define _LIBCPP_INTRINSIC128 1
72 // We have __uint128 support in clang or gcc
73[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __ryu_umul128(const uint64_t __a, const uint64_t __b, uint64_t* const __productHi) {
74 auto __temp = __a * (unsigned __int128)__b;
75 *__productHi = __temp >> 64;
76 return static_cast<uint64_t>(__temp);
77}
78
79[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __ryu_shiftright128(const uint64_t __lo, const uint64_t __hi, const uint32_t __dist) {
80 // In the current implementation of the double-precision version
81 // of Ryu, the shift value is always < 64.
82 // (The shift value is in the range [49, 58].)
83 // Check this here in case a future change requires larger shift
84 // values. In this case this function needs to be adjusted.
85 _LIBCPP_ASSERT(__dist < 64, "");
86 auto __temp = __lo | ((unsigned __int128)__hi << 64);
87 // For x64 128-bit shfits using the `shrd` instruction and two 64-bit
88 // registers, the shift value is modulo 64. Thus the `& 63` is free.
89 return static_cast<uint64_t>(__temp >> (__dist & 63));
90}
91#else // ^^^ __int128 available ^^^ / vvv intrinsics unavailable vvv
92
93[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_ALWAYS_INLINE uint64_t __ryu_umul128(const uint64_t __a, const uint64_t __b, uint64_t* const __productHi) {
94 // TRANSITION, VSO-634761
95 // The casts here help MSVC to avoid calls to the __allmul library function.
96 const uint32_t __aLo = static_cast<uint32_t>(__a);
97 const uint32_t __aHi = static_cast<uint32_t>(__a >> 32);
98 const uint32_t __bLo = static_cast<uint32_t>(__b);
99 const uint32_t __bHi = static_cast<uint32_t>(__b >> 32);
100
101 const uint64_t __b00 = static_cast<uint64_t>(__aLo) * __bLo;
102 const uint64_t __b01 = static_cast<uint64_t>(__aLo) * __bHi;
103 const uint64_t __b10 = static_cast<uint64_t>(__aHi) * __bLo;
104 const uint64_t __b11 = static_cast<uint64_t>(__aHi) * __bHi;
105
106 const uint32_t __b00Lo = static_cast<uint32_t>(__b00);
107 const uint32_t __b00Hi = static_cast<uint32_t>(__b00 >> 32);
108
109 const uint64_t __mid1 = __b10 + __b00Hi;
110 const uint32_t __mid1Lo = static_cast<uint32_t>(__mid1);
111 const uint32_t __mid1Hi = static_cast<uint32_t>(__mid1 >> 32);
112
113 const uint64_t __mid2 = __b01 + __mid1Lo;
114 const uint32_t __mid2Lo = static_cast<uint32_t>(__mid2);
115 const uint32_t __mid2Hi = static_cast<uint32_t>(__mid2 >> 32);
116
117 const uint64_t __pHi = __b11 + __mid1Hi + __mid2Hi;
118 const uint64_t __pLo = (static_cast<uint64_t>(__mid2Lo) << 32) | __b00Lo;
119
120 *__productHi = __pHi;
121 return __pLo;
122}
123
124[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __ryu_shiftright128(const uint64_t __lo, const uint64_t __hi, const uint32_t __dist) {
125 // We don't need to handle the case __dist >= 64 here (see above).
126 _LIBCPP_ASSERT(__dist < 64, "");
127#ifdef _LIBCPP_64_BIT
128 _LIBCPP_ASSERT(__dist > 0, "");
129 return (__hi << (64 - __dist)) | (__lo >> __dist);
130#else // ^^^ 64-bit ^^^ / vvv 32-bit vvv
131 // Avoid a 64-bit shift by taking advantage of the range of shift values.
132 _LIBCPP_ASSERT(__dist >= 32, "");
133 return (__hi << (64 - __dist)) | (static_cast<uint32_t>(__lo >> 32) >> (__dist - 32));
134#endif // ^^^ 32-bit ^^^
135}
136
137#endif // ^^^ intrinsics unavailable ^^^
138
139#ifndef _LIBCPP_64_BIT
140
141// Returns the high 64 bits of the 128-bit product of __a and __b.
142[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __umulh(const uint64_t __a, const uint64_t __b) {
143 // Reuse the __ryu_umul128 implementation.
144 // Optimizers will likely eliminate the instructions used to compute the
145 // low part of the product.
146 uint64_t __hi;
147 (void) __ryu_umul128(__a, __b, &__hi);
148 return __hi;
149}
150
151// On 32-bit platforms, compilers typically generate calls to library
152// functions for 64-bit divisions, even if the divisor is a constant.
153//
154// TRANSITION, LLVM-37932
155//
156// The functions here perform division-by-constant using multiplications
157// in the same way as 64-bit compilers would do.
158//
159// NB:
160// The multipliers and shift values are the ones generated by clang x64
161// for expressions like x/5, x/10, etc.
162
163[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __div5(const uint64_t __x) {
164 return __umulh(__x, 0xCCCCCCCCCCCCCCCDu) >> 2;
165}
166
167[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __div10(const uint64_t __x) {
168 return __umulh(__x, 0xCCCCCCCCCCCCCCCDu) >> 3;
169}
170
171[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __div100(const uint64_t __x) {
172 return __umulh(__x >> 2, 0x28F5C28F5C28F5C3u) >> 2;
173}
174
175[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __div1e8(const uint64_t __x) {
176 return __umulh(__x, 0xABCC77118461CEFDu) >> 26;
177}
178
179[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __div1e9(const uint64_t __x) {
180 return __umulh(__x >> 9, 0x44B82FA09B5A53u) >> 11;
181}
182
183[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __mod1e9(const uint64_t __x) {
184 // Avoid 64-bit math as much as possible.
185 // Returning static_cast<uint32_t>(__x - 1000000000 * __div1e9(__x)) would
186 // perform 32x64-bit multiplication and 64-bit subtraction.
187 // __x and 1000000000 * __div1e9(__x) are guaranteed to differ by
188 // less than 10^9, so their highest 32 bits must be identical,
189 // so we can truncate both sides to uint32_t before subtracting.
190 // We can also simplify static_cast<uint32_t>(1000000000 * __div1e9(__x)).
191 // We can truncate before multiplying instead of after, as multiplying
192 // the highest 32 bits of __div1e9(__x) can't affect the lowest 32 bits.
193 return static_cast<uint32_t>(__x) - 1000000000 * static_cast<uint32_t>(__div1e9(__x));
194}
195
196#else // ^^^ 32-bit ^^^ / vvv 64-bit vvv
197
198[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __div5(const uint64_t __x) {
199 return __x / 5;
200}
201
202[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __div10(const uint64_t __x) {
203 return __x / 10;
204}
205
206[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __div100(const uint64_t __x) {
207 return __x / 100;
208}
209
210[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __div1e8(const uint64_t __x) {
211 return __x / 100000000;
212}
213
214[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __div1e9(const uint64_t __x) {
215 return __x / 1000000000;
216}
217
218[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __mod1e9(const uint64_t __x) {
219 return static_cast<uint32_t>(__x - 1000000000 * __div1e9(__x));
220}
221
222#endif // ^^^ 64-bit ^^^
223
224[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __pow5Factor(uint64_t __value) {
225 uint32_t __count = 0;
226 for (;;) {
227 _LIBCPP_ASSERT(__value != 0, "");
228 const uint64_t __q = __div5(__value);
229 const uint32_t __r = static_cast<uint32_t>(__value) - 5 * static_cast<uint32_t>(__q);
230 if (__r != 0) {
231 break;
232 }
233 __value = __q;
234 ++__count;
235 }
236 return __count;
237}
238
239// Returns true if __value is divisible by 5^__p.
240[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline bool __multipleOfPowerOf5(const uint64_t __value, const uint32_t __p) {
241 // I tried a case distinction on __p, but there was no performance difference.
242 return __pow5Factor(__value) >= __p;
243}
244
245// Returns true if __value is divisible by 2^__p.
246[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline bool __multipleOfPowerOf2(const uint64_t __value, const uint32_t __p) {
247 _LIBCPP_ASSERT(__value != 0, "");
248 _LIBCPP_ASSERT(__p < 64, "");
249 // __builtin_ctzll doesn't appear to be faster here.
250 return (__value & ((1ull << __p) - 1)) == 0;
251}
252
253_LIBCPP_END_NAMESPACE_STD
254
255// clang-format on
256
257#endif // _LIBCPP_SRC_INCLUDE_RYU_DS2_INTRINSICS_H
lib/libcxx/src/include/ryu/digit_table.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// Copyright (c) Microsoft Corporation.
10// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
11
12// Copyright 2018 Ulf Adams
13// Copyright (c) Microsoft Corporation. All rights reserved.
14
15// Boost Software License - Version 1.0 - August 17th, 2003
16
17// Permission is hereby granted, free of charge, to any person or organization
18// obtaining a copy of the software and accompanying documentation covered by
19// this license (the "Software") to use, reproduce, display, distribute,
20// execute, and transmit the Software, and to prepare derivative works of the
21// Software, and to permit third-parties to whom the Software is furnished to
22// do so, all subject to the following:
23
24// The copyright notices in the Software and this entire statement, including
25// the above license grant, this restriction and the following disclaimer,
26// must be included in all copies of the Software, in whole or in part, and
27// all derivative works of the Software, unless such copies or derivative
28// works are solely in the form of machine-executable object code generated by
29// a source language processor.
30
31// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
34// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
35// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
36// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
37// DEALINGS IN THE SOFTWARE.
38
39#ifndef _LIBCPP_SRC_INCLUDE_RYU_DIGIT_TABLE_H
40#define _LIBCPP_SRC_INCLUDE_RYU_DIGIT_TABLE_H
41
42// Avoid formatting to keep the changes with the original code minimal.
43// clang-format off
44
45#include "__config"
46
47_LIBCPP_BEGIN_NAMESPACE_STD
48
49// A table of all two-digit numbers. This is used to speed up decimal digit
50// 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};
63
64_LIBCPP_END_NAMESPACE_STD
65
66// clang-format on
67
68#endif // _LIBCPP_SRC_INCLUDE_RYU_DIGIT_TABLE_H
lib/libcxx/src/include/ryu/f2s.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// Copyright (c) Microsoft Corporation.
10// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
11
12// Copyright 2018 Ulf Adams
13// Copyright (c) Microsoft Corporation. All rights reserved.
14
15// Boost Software License - Version 1.0 - August 17th, 2003
16
17// Permission is hereby granted, free of charge, to any person or organization
18// obtaining a copy of the software and accompanying documentation covered by
19// this license (the "Software") to use, reproduce, display, distribute,
20// execute, and transmit the Software, and to prepare derivative works of the
21// Software, and to permit third-parties to whom the Software is furnished to
22// do so, all subject to the following:
23
24// The copyright notices in the Software and this entire statement, including
25// the above license grant, this restriction and the following disclaimer,
26// must be included in all copies of the Software, in whole or in part, and
27// all derivative works of the Software, unless such copies or derivative
28// works are solely in the form of machine-executable object code generated by
29// a source language processor.
30
31// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
34// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
35// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
36// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
37// DEALINGS IN THE SOFTWARE.
38
39#ifndef _LIBCPP_SRC_INCLUDE_RYU_FS2_H
40#define _LIBCPP_SRC_INCLUDE_RYU_FS2_H
41
42// Avoid formatting to keep the changes with the original code minimal.
43// clang-format off
44
45#include "__config"
46
47_LIBCPP_BEGIN_NAMESPACE_STD
48
49[[nodiscard]] to_chars_result __f2s_buffered_n(char* const _First, char* const _Last, const float __f, const chars_format _Fmt);
50
51_LIBCPP_END_NAMESPACE_STD
52
53// clang-format on
54
55#endif // _LIBCPP_SRC_INCLUDE_RYU_FS2_H
lib/libcxx/src/include/ryu/ryu.h created+148
......@@ -0,0 +1,148 @@
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// Copyright (c) Microsoft Corporation.
11// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
12
13
14// Copyright 2018 Ulf Adams
15// Copyright (c) Microsoft Corporation. All rights reserved.
16
17// Boost Software License - Version 1.0 - August 17th, 2003
18
19// Permission is hereby granted, free of charge, to any person or organization
20// obtaining a copy of the software and accompanying documentation covered by
21// this license (the "Software") to use, reproduce, display, distribute,
22// execute, and transmit the Software, and to prepare derivative works of the
23// Software, and to permit third-parties to whom the Software is furnished to
24// do so, all subject to the following:
25
26// The copyright notices in the Software and this entire statement, including
27// the above license grant, this restriction and the following disclaimer,
28// must be included in all copies of the Software, in whole or in part, and
29// all derivative works of the Software, unless such copies or derivative
30// works are solely in the form of machine-executable object code generated by
31// a source language processor.
32
33// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
36// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
37// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
38// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
39// DEALINGS IN THE SOFTWARE.
40
41#ifndef _LIBCPP_SRC_INCLUDE_RYU_RYU_H
42#define _LIBCPP_SRC_INCLUDE_RYU_RYU_H
43
44// Avoid formatting to keep the changes with the original code minimal.
45// clang-format off
46
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#include "include/ryu/f2s.h"
56#include "include/ryu/d2s.h"
57#include "include/ryu/d2fixed.h"
58
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)
62
63#if defined(_WIN64) || defined(_M_AMD64) || defined(__x86_64__) || defined(__aarch64__)
64#define _LIBCPP_64_BIT
65#endif
66
67_LIBCPP_BEGIN_NAMESPACE_STD
68
69// https://github.com/ulfjack/ryu/tree/59661c3/ryu
70
71#if !defined(_LIBCPP_COMPILER_MSVC)
72_LIBCPP_HIDE_FROM_ABI inline unsigned char _BitScanForward64(unsigned long* __index, unsigned long long __mask) {
73 if (__mask == 0) {
74 return false;
75 }
76 *__index = __builtin_ctzll(__mask);
77 return true;
78}
79
80_LIBCPP_HIDE_FROM_ABI inline unsigned char _BitScanForward(unsigned long* __index, unsigned int __mask) {
81 if (__mask == 0) {
82 return false;
83 }
84 *__index = __builtin_ctz(__mask);
85 return true;
86}
87#endif // _LIBCPP_COMPILER_MSVC
88
89template <class _Floating>
90[[nodiscard]] to_chars_result _Floating_to_chars_ryu(
91 char* const _First, char* const _Last, const _Floating _Value, const chars_format _Fmt) noexcept {
92 if constexpr (_IsSame<_Floating, float>::value) {
93 return __f2s_buffered_n(_First, _Last, _Value, _Fmt);
94 } else {
95 return __d2s_buffered_n(_First, _Last, _Value, _Fmt);
96 }
97}
98
99template <class _Floating>
100[[nodiscard]] _LIBCPP_HIDE_FROM_ABI to_chars_result _Floating_to_chars_scientific_precision(
101 char* const _First, char* const _Last, const _Floating _Value, int _Precision) noexcept {
102
103 // C11 7.21.6.1 "The fprintf function"/5:
104 // "A negative precision argument is taken as if the precision were omitted."
105 // /8: "e,E [...] if the precision is missing, it is taken as 6"
106
107 if (_Precision < 0) {
108 _Precision = 6;
109 } else if (_Precision < 1'000'000'000) { // Match ' to fix compilation with GCC in C++11 mode
110 // _Precision is ok.
111 } else {
112 // Avoid integer overflow.
113 // (This defensive check is slightly nonconformant; it can be carefully improved in the future.)
114 return {_Last, errc::value_too_large};
115 }
116
117 return __d2exp_buffered_n(_First, _Last, _Value, static_cast<uint32_t>(_Precision));
118}
119
120template <class _Floating>
121[[nodiscard]] _LIBCPP_HIDE_FROM_ABI to_chars_result _Floating_to_chars_fixed_precision(
122 char* const _First, char* const _Last, const _Floating _Value, int _Precision) noexcept {
123
124 // C11 7.21.6.1 "The fprintf function"/5:
125 // "A negative precision argument is taken as if the precision were omitted."
126 // /8: "f,F [...] If the precision is missing, it is taken as 6"
127
128 if (_Precision < 0) {
129 _Precision = 6;
130 } else if (_Precision < 1'000'000'000) { // Match ' to fix compilation with GCC in C++11 mode
131 // _Precision is ok.
132 } else {
133 // Avoid integer overflow.
134 // (This defensive check is slightly nonconformant; it can be carefully improved in the future.)
135 return {_Last, errc::value_too_large};
136 }
137
138 return __d2fixed_buffered_n(_First, _Last, _Value, static_cast<uint32_t>(_Precision));
139}
140
141#undef _LIBCPP_64_BIT
142#undef _LIBCPP_INTRINSIC128
143
144_LIBCPP_END_NAMESPACE_STD
145
146// clang-format on
147
148#endif // _LIBCPP_SRC_INCLUDE_RYU_RYU_H
lib/libcxx/src/include/to_chars_floating_point.h created+1076
......@@ -0,0 +1,1076 @@
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// Copyright (c) Microsoft Corporation.
10// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
11
12// This implementation is dedicated to the memory of Mary and Thavatchai.
13
14#ifndef _LIBCPP_SRC_INCLUDE_TO_CHARS_FLOATING_POINT_H
15#define _LIBCPP_SRC_INCLUDE_TO_CHARS_FLOATING_POINT_H
16
17// Avoid formatting to keep the changes with the original code minimal.
18// clang-format off
19
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"
30#include "include/ryu/ryu.h"
31
32_LIBCPP_BEGIN_NAMESPACE_STD
33
34namespace __itoa {
35inline constexpr char _Charconv_digits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e',
36 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
37static_assert(_VSTD::size(_Charconv_digits) == 36);
38} // __itoa
39
40// vvvvvvvvvv DERIVED FROM corecrt_internal_fltintrn.h vvvvvvvvvv
41
42template <class _FloatingType>
43struct _Floating_type_traits;
44
45template <>
46struct _Floating_type_traits<float> {
47 static constexpr int32_t _Mantissa_bits = FLT_MANT_DIG;
48 static constexpr int32_t _Exponent_bits = sizeof(float) * CHAR_BIT - FLT_MANT_DIG;
49
50 static constexpr int32_t _Maximum_binary_exponent = FLT_MAX_EXP - 1;
51 static constexpr int32_t _Minimum_binary_exponent = FLT_MIN_EXP - 1;
52
53 static constexpr int32_t _Exponent_bias = 127;
54
55 static constexpr int32_t _Sign_shift = _Exponent_bits + _Mantissa_bits - 1;
56 static constexpr int32_t _Exponent_shift = _Mantissa_bits - 1;
57
58 using _Uint_type = uint32_t;
59
60 static constexpr uint32_t _Exponent_mask = (1u << _Exponent_bits) - 1;
61 static constexpr uint32_t _Normal_mantissa_mask = (1u << _Mantissa_bits) - 1;
62 static constexpr uint32_t _Denormal_mantissa_mask = (1u << (_Mantissa_bits - 1)) - 1;
63 static constexpr uint32_t _Special_nan_mantissa_mask = 1u << (_Mantissa_bits - 2);
64 static constexpr uint32_t _Shifted_sign_mask = 1u << _Sign_shift;
65 static constexpr uint32_t _Shifted_exponent_mask = _Exponent_mask << _Exponent_shift;
66};
67
68template <>
69struct _Floating_type_traits<double> {
70 static constexpr int32_t _Mantissa_bits = DBL_MANT_DIG;
71 static constexpr int32_t _Exponent_bits = sizeof(double) * CHAR_BIT - DBL_MANT_DIG;
72
73 static constexpr int32_t _Maximum_binary_exponent = DBL_MAX_EXP - 1;
74 static constexpr int32_t _Minimum_binary_exponent = DBL_MIN_EXP - 1;
75
76 static constexpr int32_t _Exponent_bias = 1023;
77
78 static constexpr int32_t _Sign_shift = _Exponent_bits + _Mantissa_bits - 1;
79 static constexpr int32_t _Exponent_shift = _Mantissa_bits - 1;
80
81 using _Uint_type = uint64_t;
82
83 static constexpr uint64_t _Exponent_mask = (1ULL << _Exponent_bits) - 1;
84 static constexpr uint64_t _Normal_mantissa_mask = (1ULL << _Mantissa_bits) - 1;
85 static constexpr uint64_t _Denormal_mantissa_mask = (1ULL << (_Mantissa_bits - 1)) - 1;
86 static constexpr uint64_t _Special_nan_mantissa_mask = 1ULL << (_Mantissa_bits - 2);
87 static constexpr uint64_t _Shifted_sign_mask = 1ULL << _Sign_shift;
88 static constexpr uint64_t _Shifted_exponent_mask = _Exponent_mask << _Exponent_shift;
89};
90
91// ^^^^^^^^^^ DERIVED FROM corecrt_internal_fltintrn.h ^^^^^^^^^^
92
93// FUNCTION to_chars (FLOATING-POINT TO STRING)
94template <class _Floating>
95[[nodiscard]] _LIBCPP_HIDE_FROM_ABI
96to_chars_result _Floating_to_chars_hex_precision(
97 char* _First, char* const _Last, const _Floating _Value, int _Precision) noexcept {
98
99 // * Determine the effective _Precision.
100 // * Later, we'll decrement _Precision when printing each hexit after the decimal point.
101
102 // The hexits after the decimal point correspond to the explicitly stored fraction bits.
103 // float explicitly stores 23 fraction bits. 23 / 4 == 5.75, which is 6 hexits.
104 // double explicitly stores 52 fraction bits. 52 / 4 == 13, which is 13 hexits.
105 constexpr int _Full_precision = _IsSame<_Floating, float>::value ? 6 : 13;
106 constexpr int _Adjusted_explicit_bits = _Full_precision * 4;
107
108 if (_Precision < 0) {
109 // C11 7.21.6.1 "The fprintf function"/5: "A negative precision argument is taken as if the precision were
110 // omitted." /8: "if the precision is missing and FLT_RADIX is a power of 2, then the precision is sufficient
111 // for an exact representation of the value"
112 _Precision = _Full_precision;
113 }
114
115 // * Extract the _Ieee_mantissa and _Ieee_exponent.
116 using _Traits = _Floating_type_traits<_Floating>;
117 using _Uint_type = typename _Traits::_Uint_type;
118
119 const _Uint_type _Uint_value = _VSTD::bit_cast<_Uint_type>(_Value);
120 const _Uint_type _Ieee_mantissa = _Uint_value & _Traits::_Denormal_mantissa_mask;
121 const int32_t _Ieee_exponent = static_cast<int32_t>(_Uint_value >> _Traits::_Exponent_shift);
122
123 // * Prepare the _Adjusted_mantissa. This is aligned to hexit boundaries,
124 // * with the implicit bit restored (0 for zero values and subnormal values, 1 for normal values).
125 // * Also calculate the _Unbiased_exponent. This unifies the processing of zero, subnormal, and normal values.
126 _Uint_type _Adjusted_mantissa;
127
128 if constexpr (_IsSame<_Floating, float>::value) {
129 _Adjusted_mantissa = _Ieee_mantissa << 1; // align to hexit boundary (23 isn't divisible by 4)
130 } else {
131 _Adjusted_mantissa = _Ieee_mantissa; // already aligned (52 is divisible by 4)
132 }
133
134 int32_t _Unbiased_exponent;
135
136 if (_Ieee_exponent == 0) { // zero or subnormal
137 // implicit bit is 0
138
139 if (_Ieee_mantissa == 0) { // zero
140 // C11 7.21.6.1 "The fprintf function"/8: "If the value is zero, the exponent is zero."
141 _Unbiased_exponent = 0;
142 } else { // subnormal
143 _Unbiased_exponent = 1 - _Traits::_Exponent_bias;
144 }
145 } else { // normal
146 _Adjusted_mantissa |= _Uint_type{1} << _Adjusted_explicit_bits; // implicit bit is 1
147 _Unbiased_exponent = _Ieee_exponent - _Traits::_Exponent_bias;
148 }
149
150 // _Unbiased_exponent is within [-126, 127] for float, [-1022, 1023] for double.
151
152 // * Decompose _Unbiased_exponent into _Sign_character and _Absolute_exponent.
153 char _Sign_character;
154 uint32_t _Absolute_exponent;
155
156 if (_Unbiased_exponent < 0) {
157 _Sign_character = '-';
158 _Absolute_exponent = static_cast<uint32_t>(-_Unbiased_exponent);
159 } else {
160 _Sign_character = '+';
161 _Absolute_exponent = static_cast<uint32_t>(_Unbiased_exponent);
162 }
163
164 // _Absolute_exponent is within [0, 127] for float, [0, 1023] for double.
165
166 // * Perform a single bounds check.
167 {
168 int32_t _Exponent_length;
169
170 if (_Absolute_exponent < 10) {
171 _Exponent_length = 1;
172 } else if (_Absolute_exponent < 100) {
173 _Exponent_length = 2;
174 } else if constexpr (_IsSame<_Floating, float>::value) {
175 _Exponent_length = 3;
176 } else if (_Absolute_exponent < 1000) {
177 _Exponent_length = 3;
178 } else {
179 _Exponent_length = 4;
180 }
181
182 // _Precision might be enormous; avoid integer overflow by testing it separately.
183 ptrdiff_t _Buffer_size = _Last - _First;
184
185 if (_Buffer_size < _Precision) {
186 return {_Last, errc::value_too_large};
187 }
188
189 _Buffer_size -= _Precision;
190
191 const int32_t _Length_excluding_precision = 1 // leading hexit
192 + static_cast<int32_t>(_Precision > 0) // possible decimal point
193 // excluding `+ _Precision`, hexits after decimal point
194 + 2 // "p+" or "p-"
195 + _Exponent_length; // exponent
196
197 if (_Buffer_size < _Length_excluding_precision) {
198 return {_Last, errc::value_too_large};
199 }
200 }
201
202 // * Perform rounding when we've been asked to omit hexits.
203 if (_Precision < _Full_precision) {
204 // _Precision is within [0, 5] for float, [0, 12] for double.
205
206 // _Dropped_bits is within [4, 24] for float, [4, 52] for double.
207 const int _Dropped_bits = (_Full_precision - _Precision) * 4;
208
209 // Perform rounding by adding an appropriately-shifted bit.
210
211 // This can propagate carries all the way into the leading hexit. Examples:
212 // "0.ff9" rounded to a precision of 2 is "1.00".
213 // "1.ff9" rounded to a precision of 2 is "2.00".
214
215 // Note that the leading hexit participates in the rounding decision. Examples:
216 // "0.8" rounded to a precision of 0 is "0".
217 // "1.8" rounded to a precision of 0 is "2".
218
219 // Reference implementation with suboptimal codegen:
220 // bool _Should_round_up(bool _Lsb_bit, bool _Round_bit, bool _Has_tail_bits) {
221 // // If there are no insignificant set bits, the value is exactly-representable and should not be rounded.
222 // //
223 // // If there are insignificant set bits, we need to round according to round_to_nearest.
224 // // We need to handle two cases: we round up if either [1] the value is slightly greater
225 // // than the midpoint between two exactly-representable values or [2] the value is exactly the midpoint
226 // // between two exactly-representable values and the greater of the two is even (this is "round-to-even").
227 // return _Round_bit && (_Has_tail_bits || _Lsb_bit);
228 //}
229 // const bool _Lsb_bit = (_Adjusted_mantissa & (_Uint_type{1} << _Dropped_bits)) != 0;
230 // const bool _Round_bit = (_Adjusted_mantissa & (_Uint_type{1} << (_Dropped_bits - 1))) != 0;
231 // const bool _Has_tail_bits = (_Adjusted_mantissa & ((_Uint_type{1} << (_Dropped_bits - 1)) - 1)) != 0;
232 // const bool _Should_round = _Should_round_up(_Lsb_bit, _Round_bit, _Has_tail_bits);
233 // _Adjusted_mantissa += _Uint_type{_Should_round} << _Dropped_bits;
234
235 // Example for optimized implementation: Let _Dropped_bits be 8.
236 // Bit index: ...[8]76543210
237 // _Adjusted_mantissa: ...[L]RTTTTTTT (not depicting known details, like hexit alignment)
238 // By focusing on the bit at index _Dropped_bits, we can avoid unnecessary branching and shifting.
239
240 // Bit index: ...[8]76543210
241 // _Lsb_bit: ...[L]RTTTTTTT
242 const _Uint_type _Lsb_bit = _Adjusted_mantissa;
243
244 // Bit index: ...9[8]76543210
245 // _Round_bit: ...L[R]TTTTTTT0
246 const _Uint_type _Round_bit = _Adjusted_mantissa << 1;
247
248 // We can detect (without branching) whether any of the trailing bits are set.
249 // Due to _Should_round below, this computation will be used if and only if R is 1, so we can assume that here.
250 // Bit index: ...9[8]76543210
251 // _Round_bit: ...L[1]TTTTTTT0
252 // _Has_tail_bits: ....[H]........
253
254 // If all of the trailing bits T are 0, then `_Round_bit - 1` will produce 0 for H (due to R being 1).
255 // If any of the trailing bits T are 1, then `_Round_bit - 1` will produce 1 for H (due to R being 1).
256 const _Uint_type _Has_tail_bits = _Round_bit - 1;
257
258 // Finally, we can use _Should_round_up() logic with bitwise-AND and bitwise-OR,
259 // selecting just the bit at index _Dropped_bits. This is the appropriately-shifted bit that we want.
260 const _Uint_type _Should_round = _Round_bit & (_Has_tail_bits | _Lsb_bit) & (_Uint_type{1} << _Dropped_bits);
261
262 // This rounding technique is dedicated to the memory of Peppermint. =^..^=
263 _Adjusted_mantissa += _Should_round;
264 }
265
266 // * Print the leading hexit, then mask it away.
267 {
268 const uint32_t _Nibble = static_cast<uint32_t>(_Adjusted_mantissa >> _Adjusted_explicit_bits);
269 _LIBCPP_ASSERT(_Nibble < 3, "");
270 const char _Leading_hexit = static_cast<char>('0' + _Nibble);
271
272 *_First++ = _Leading_hexit;
273
274 constexpr _Uint_type _Mask = (_Uint_type{1} << _Adjusted_explicit_bits) - 1;
275 _Adjusted_mantissa &= _Mask;
276 }
277
278 // * Print the decimal point and trailing hexits.
279
280 // C11 7.21.6.1 "The fprintf function"/8:
281 // "if the precision is zero and the # flag is not specified, no decimal-point character appears."
282 if (_Precision > 0) {
283 *_First++ = '.';
284
285 int32_t _Number_of_bits_remaining = _Adjusted_explicit_bits; // 24 for float, 52 for double
286
287 for (;;) {
288 _LIBCPP_ASSERT(_Number_of_bits_remaining >= 4, "");
289 _LIBCPP_ASSERT(_Number_of_bits_remaining % 4 == 0, "");
290 _Number_of_bits_remaining -= 4;
291
292 const uint32_t _Nibble = static_cast<uint32_t>(_Adjusted_mantissa >> _Number_of_bits_remaining);
293 _LIBCPP_ASSERT(_Nibble < 16, "");
294 const char _Hexit = __itoa::_Charconv_digits[_Nibble];
295
296 *_First++ = _Hexit;
297
298 // _Precision is the number of hexits that still need to be printed.
299 --_Precision;
300 if (_Precision == 0) {
301 break; // We're completely done with this phase.
302 }
303 // Otherwise, we need to keep printing hexits.
304
305 if (_Number_of_bits_remaining == 0) {
306 // We've finished printing _Adjusted_mantissa, so all remaining hexits are '0'.
307 _VSTD::memset(_First, '0', static_cast<size_t>(_Precision));
308 _First += _Precision;
309 break;
310 }
311
312 // Mask away the hexit that we just printed, then keep looping.
313 // (We skip this when breaking out of the loop above, because _Adjusted_mantissa isn't used later.)
314 const _Uint_type _Mask = (_Uint_type{1} << _Number_of_bits_remaining) - 1;
315 _Adjusted_mantissa &= _Mask;
316 }
317 }
318
319 // * Print the exponent.
320
321 // C11 7.21.6.1 "The fprintf function"/8: "The exponent always contains at least one digit, and only as many more
322 // digits as necessary to represent the decimal exponent of 2."
323
324 // Performance note: We should take advantage of the known ranges of possible exponents.
325
326 *_First++ = 'p';
327 *_First++ = _Sign_character;
328
329 // We've already printed '-' if necessary, so uint32_t _Absolute_exponent avoids testing that again.
330 return _VSTD::to_chars(_First, _Last, _Absolute_exponent);
331}
332
333template <class _Floating>
334[[nodiscard]] _LIBCPP_HIDE_FROM_ABI
335to_chars_result _Floating_to_chars_hex_shortest(
336 char* _First, char* const _Last, const _Floating _Value) noexcept {
337
338 // This prints "1.728p+0" instead of "2.e5p-1".
339 // This prints "0.000002p-126" instead of "1p-149" for float.
340 // This prints "0.0000000000001p-1022" instead of "1p-1074" for double.
341 // This prioritizes being consistent with printf's de facto behavior (and hex-precision's behavior)
342 // over minimizing the number of characters printed.
343
344 using _Traits = _Floating_type_traits<_Floating>;
345 using _Uint_type = typename _Traits::_Uint_type;
346
347 const _Uint_type _Uint_value = _VSTD::bit_cast<_Uint_type>(_Value);
348
349 if (_Uint_value == 0) { // zero detected; write "0p+0" and return
350 // C11 7.21.6.1 "The fprintf function"/8: "If the value is zero, the exponent is zero."
351 // Special-casing zero is necessary because of the exponent.
352 const char* const _Str = "0p+0";
353 const size_t _Len = 4;
354
355 if (_Last - _First < static_cast<ptrdiff_t>(_Len)) {
356 return {_Last, errc::value_too_large};
357 }
358
359 _VSTD::memcpy(_First, _Str, _Len);
360
361 return {_First + _Len, errc{}};
362 }
363
364 const _Uint_type _Ieee_mantissa = _Uint_value & _Traits::_Denormal_mantissa_mask;
365 const int32_t _Ieee_exponent = static_cast<int32_t>(_Uint_value >> _Traits::_Exponent_shift);
366
367 char _Leading_hexit; // implicit bit
368 int32_t _Unbiased_exponent;
369
370 if (_Ieee_exponent == 0) { // subnormal
371 _Leading_hexit = '0';
372 _Unbiased_exponent = 1 - _Traits::_Exponent_bias;
373 } else { // normal
374 _Leading_hexit = '1';
375 _Unbiased_exponent = _Ieee_exponent - _Traits::_Exponent_bias;
376 }
377
378 // Performance note: Consider avoiding per-character bounds checking when there's plenty of space.
379
380 if (_First == _Last) {
381 return {_Last, errc::value_too_large};
382 }
383
384 *_First++ = _Leading_hexit;
385
386 if (_Ieee_mantissa == 0) {
387 // The fraction bits are all 0. Trim them away, including the decimal point.
388 } else {
389 if (_First == _Last) {
390 return {_Last, errc::value_too_large};
391 }
392
393 *_First++ = '.';
394
395 // The hexits after the decimal point correspond to the explicitly stored fraction bits.
396 // float explicitly stores 23 fraction bits. 23 / 4 == 5.75, so we'll print at most 6 hexits.
397 // double explicitly stores 52 fraction bits. 52 / 4 == 13, so we'll print at most 13 hexits.
398 _Uint_type _Adjusted_mantissa;
399 int32_t _Number_of_bits_remaining;
400
401 if constexpr (_IsSame<_Floating, float>::value) {
402 _Adjusted_mantissa = _Ieee_mantissa << 1; // align to hexit boundary (23 isn't divisible by 4)
403 _Number_of_bits_remaining = 24; // 23 fraction bits + 1 alignment bit
404 } else {
405 _Adjusted_mantissa = _Ieee_mantissa; // already aligned (52 is divisible by 4)
406 _Number_of_bits_remaining = 52; // 52 fraction bits
407 }
408
409 // do-while: The condition _Adjusted_mantissa != 0 is initially true - we have nonzero fraction bits and we've
410 // printed the decimal point. Each iteration, we print a hexit, mask it away, and keep looping if we still have
411 // nonzero fraction bits. If there would be trailing '0' hexits, this trims them. If there wouldn't be trailing
412 // '0' hexits, the same condition works (as we print the final hexit and mask it away); we don't need to test
413 // _Number_of_bits_remaining.
414 do {
415 _LIBCPP_ASSERT(_Number_of_bits_remaining >= 4, "");
416 _LIBCPP_ASSERT(_Number_of_bits_remaining % 4 == 0, "");
417 _Number_of_bits_remaining -= 4;
418
419 const uint32_t _Nibble = static_cast<uint32_t>(_Adjusted_mantissa >> _Number_of_bits_remaining);
420 _LIBCPP_ASSERT(_Nibble < 16, "");
421 const char _Hexit = __itoa::_Charconv_digits[_Nibble];
422
423 if (_First == _Last) {
424 return {_Last, errc::value_too_large};
425 }
426
427 *_First++ = _Hexit;
428
429 const _Uint_type _Mask = (_Uint_type{1} << _Number_of_bits_remaining) - 1;
430 _Adjusted_mantissa &= _Mask;
431
432 } while (_Adjusted_mantissa != 0);
433 }
434
435 // C11 7.21.6.1 "The fprintf function"/8: "The exponent always contains at least one digit, and only as many more
436 // digits as necessary to represent the decimal exponent of 2."
437
438 // Performance note: We should take advantage of the known ranges of possible exponents.
439
440 // float: _Unbiased_exponent is within [-126, 127].
441 // double: _Unbiased_exponent is within [-1022, 1023].
442
443 if (_Last - _First < 2) {
444 return {_Last, errc::value_too_large};
445 }
446
447 *_First++ = 'p';
448
449 if (_Unbiased_exponent < 0) {
450 *_First++ = '-';
451 _Unbiased_exponent = -_Unbiased_exponent;
452 } else {
453 *_First++ = '+';
454 }
455
456 // We've already printed '-' if necessary, so static_cast<uint32_t> avoids testing that again.
457 return _VSTD::to_chars(_First, _Last, static_cast<uint32_t>(_Unbiased_exponent));
458}
459
460// For general precision, we can use lookup tables to avoid performing trial formatting.
461
462// For a simple example, imagine counting the number of digits D in an integer, and needing to know
463// whether D is less than 3, equal to 3/4/5/6, or greater than 6. We could use a lookup table:
464// D | Largest integer with D digits
465// 2 | 99
466// 3 | 999
467// 4 | 9'999
468// 5 | 99'999
469// 6 | 999'999
470// 7 | table end
471// Looking up an integer in this table with lower_bound() will work:
472// * Too-small integers, like 7, 70, and 99, will cause lower_bound() to return the D == 2 row. (If all we care
473// about is whether D is less than 3, then it's okay to smash the D == 1 and D == 2 cases together.)
474// * Integers in [100, 999] will cause lower_bound() to return the D == 3 row, and so forth.
475// * Too-large integers, like 1'000'000 and above, will cause lower_bound() to return the end of the table. If we
476// compute D from that index, this will be considered D == 7, which will activate any "greater than 6" logic.
477
478// Floating-point is slightly more complicated.
479
480// The ordinary lookup tables are for X within [-5, 38] for float, and [-5, 308] for double.
481// (-5 absorbs too-negative exponents, outside the P > X >= -4 criterion. 38 and 308 are the maximum exponents.)
482// Due to the P > X condition, we can use a subset of the table for X within [-5, P - 1], suitably clamped.
483
484// When P is small, rounding can affect X. For example:
485// For P == 1, the largest double with X == 0 is: 9.4999999999999982236431605997495353221893310546875
486// For P == 2, the largest double with X == 0 is: 9.949999999999999289457264239899814128875732421875
487// For P == 3, the largest double with X == 0 is: 9.9949999999999992184029906638897955417633056640625
488
489// Exponent adjustment is a concern for P within [1, 7] for float, and [1, 15] for double (determined via
490// brute force). While larger values of P still perform rounding, they can't trigger exponent adjustment.
491// This is because only values with repeated '9' digits can undergo exponent adjustment during rounding,
492// and floating-point granularity limits the number of consecutive '9' digits that can appear.
493
494// So, we need special lookup tables for small values of P.
495// These tables have varying lengths due to the P > X >= -4 criterion. For example:
496// For P == 1, need table entries for X: -5, -4, -3, -2, -1, 0
497// For P == 2, need table entries for X: -5, -4, -3, -2, -1, 0, 1
498// For P == 3, need table entries for X: -5, -4, -3, -2, -1, 0, 1, 2
499// For P == 4, need table entries for X: -5, -4, -3, -2, -1, 0, 1, 2, 3
500
501// We can concatenate these tables for compact storage, using triangular numbers to access them.
502// The table for P begins at index (P - 1) * (P + 10) / 2 with length P + 5.
503
504// For both the ordinary and special lookup tables, after an index I is returned by lower_bound(), X is I - 5.
505
506// We need to special-case the floating-point value 0.0, which is considered to have X == 0.
507// Otherwise, the lookup tables would consider it to have a highly negative X.
508
509// Finally, because we're working with positive floating-point values,
510// representation comparisons behave identically to floating-point comparisons.
511
512// The following code generated the lookup tables for the scientific exponent X. Don't remove this code.
513#if 0
514// cl /EHsc /nologo /W4 /MT /O2 /std:c++17 generate_tables.cpp && generate_tables
515
516#include <algorithm>
517#include <assert.h>
518#include <charconv>
519#include <cmath>
520#include <limits>
521#include <map>
522#include <stdint.h>
523#include <stdio.h>
524#include <system_error>
525#include <type_traits>
526#include <vector>
527using namespace std;
528
529template <typename UInt, typename Pred>
530[[nodiscard]] UInt uint_partition_point(UInt first, const UInt last, Pred pred) {
531 // Find the beginning of the false partition in [first, last).
532 // [first, last) is partitioned when all of the true values occur before all of the false values.
533
534 static_assert(is_unsigned_v<UInt>);
535 assert(first <= last);
536
537 for (UInt n = last - first; n > 0;) {
538 const UInt n2 = n / 2;
539 const UInt mid = first + n2;
540
541 if (pred(mid)) {
542 first = mid + 1;
543 n = n - n2 - 1;
544 } else {
545 n = n2;
546 }
547 }
548
549 return first;
550}
551
552template <typename Floating>
553[[nodiscard]] int scientific_exponent_X(const int P, const Floating flt) {
554 char buf[400]; // more than enough
555
556 // C11 7.21.6.1 "The fprintf function"/8 performs trial formatting with scientific precision P - 1.
557 const auto to_result = to_chars(buf, end(buf), flt, chars_format::scientific, P - 1);
558 assert(to_result.ec == errc{});
559
560 const char* exp_ptr = find(buf, to_result.ptr, 'e');
561 assert(exp_ptr != to_result.ptr);
562
563 ++exp_ptr; // advance past 'e'
564
565 if (*exp_ptr == '+') {
566 ++exp_ptr; // advance past '+' which from_chars() won't parse
567 }
568
569 int X;
570 const auto from_result = from_chars(exp_ptr, to_result.ptr, X);
571 assert(from_result.ec == errc{});
572 return X;
573}
574
575template <typename UInt>
576void print_table(const vector<UInt>& v, const char* const name) {
577 constexpr const char* UIntName = _IsSame<UInt, uint32_t>::value ? "uint32_t" : "uint64_t";
578
579 printf("static constexpr %s %s[%zu] = {\n", UIntName, name, v.size());
580
581 for (const auto& val : v) {
582 if constexpr (_IsSame<UInt, uint32_t>::value) {
583 printf("0x%08Xu,\n", val);
584 } else {
585 printf("0x%016llXu,\n", val);
586 }
587 }
588
589 printf("};\n");
590}
591
592enum class Mode { Tables, Tests };
593
594template <typename Floating>
595void generate_tables(const Mode mode) {
596 using Limits = numeric_limits<Floating>;
597 using UInt = conditional_t<_IsSame<Floating, float>::value, uint32_t, uint64_t>;
598
599 map<int, map<int, UInt>> P_X_LargestValWithX;
600
601 constexpr int MaxP = Limits::max_exponent10 + 1; // MaxP performs no rounding during trial formatting
602
603 for (int P = 1; P <= MaxP; ++P) {
604 for (int X = -5; X < P; ++X) {
605 constexpr Floating first = static_cast<Floating>(9e-5); // well below 9.5e-5, otherwise arbitrary
606 constexpr Floating last = Limits::infinity(); // one bit above Limits::max()
607
608 const UInt val_beyond_X = uint_partition_point(reinterpret_cast<const UInt&>(first),
609 reinterpret_cast<const UInt&>(last),
610 [P, X](const UInt u) { return scientific_exponent_X(P, reinterpret_cast<const Floating&>(u)) <= X; });
611
612 P_X_LargestValWithX[P][X] = val_beyond_X - 1;
613 }
614 }
615
616 constexpr const char* FloatingName = _IsSame<Floating, float>::value ? "float" : "double";
617
618 constexpr int MaxSpecialP = _IsSame<Floating, float>::value ? 7 : 15; // MaxSpecialP is affected by exponent adjustment
619
620 if (mode == Mode::Tables) {
621 printf("template <>\n");
622 printf("struct _General_precision_tables<%s> {\n", FloatingName);
623
624 printf("static constexpr int _Max_special_P = %d;\n", MaxSpecialP);
625
626 vector<UInt> special;
627
628 for (int P = 1; P <= MaxSpecialP; ++P) {
629 for (int X = -5; X < P; ++X) {
630 const UInt val = P_X_LargestValWithX[P][X];
631 special.push_back(val);
632 }
633 }
634
635 print_table(special, "_Special_X_table");
636
637 for (int P = MaxSpecialP + 1; P < MaxP; ++P) {
638 for (int X = -5; X < P; ++X) {
639 const UInt val = P_X_LargestValWithX[P][X];
640 assert(val == P_X_LargestValWithX[MaxP][X]);
641 }
642 }
643
644 printf("static constexpr int _Max_P = %d;\n", MaxP);
645
646 vector<UInt> ordinary;
647
648 for (int X = -5; X < MaxP; ++X) {
649 const UInt val = P_X_LargestValWithX[MaxP][X];
650 ordinary.push_back(val);
651 }
652
653 print_table(ordinary, "_Ordinary_X_table");
654
655 printf("};\n");
656 } else {
657 printf("==========\n");
658 printf("Test cases for %s:\n", FloatingName);
659
660 constexpr int Hexits = _IsSame<Floating, float>::value ? 6 : 13;
661 constexpr const char* Suffix = _IsSame<Floating, float>::value ? "f" : "";
662
663 for (int P = 1; P <= MaxP; ++P) {
664 for (int X = -5; X < P; ++X) {
665 if (P <= MaxSpecialP || P == 25 || P == MaxP || X == P - 1) {
666 const UInt val1 = P_X_LargestValWithX[P][X];
667 const Floating f1 = reinterpret_cast<const Floating&>(val1);
668 const UInt val2 = val1 + 1;
669 const Floating f2 = reinterpret_cast<const Floating&>(val2);
670
671 printf("{%.*a%s, chars_format::general, %d, \"%.*g\"},\n", Hexits, f1, Suffix, P, P, f1);
672 if (isfinite(f2)) {
673 printf("{%.*a%s, chars_format::general, %d, \"%.*g\"},\n", Hexits, f2, Suffix, P, P, f2);
674 }
675 }
676 }
677 }
678 }
679}
680
681int main() {
682 printf("template <class _Floating>\n");
683 printf("struct _General_precision_tables;\n");
684 generate_tables<float>(Mode::Tables);
685 generate_tables<double>(Mode::Tables);
686 generate_tables<float>(Mode::Tests);
687 generate_tables<double>(Mode::Tests);
688}
689#endif // 0
690
691template <class _Floating>
692struct _General_precision_tables;
693
694template <>
695struct _General_precision_tables<float> {
696 static constexpr int _Max_special_P = 7;
697
698 static constexpr uint32_t _Special_X_table[63] = {0x38C73ABCu, 0x3A79096Bu, 0x3C1BA5E3u, 0x3DC28F5Cu, 0x3F733333u,
699 0x4117FFFFu, 0x38D0AAA7u, 0x3A826AA8u, 0x3C230553u, 0x3DCBC6A7u, 0x3F7EB851u, 0x411F3333u, 0x42C6FFFFu,
700 0x38D19C3Fu, 0x3A8301A7u, 0x3C23C211u, 0x3DCCB295u, 0x3F7FDF3Bu, 0x411FEB85u, 0x42C7E666u, 0x4479DFFFu,
701 0x38D1B468u, 0x3A8310C1u, 0x3C23D4F1u, 0x3DCCCA2Du, 0x3F7FFCB9u, 0x411FFDF3u, 0x42C7FD70u, 0x4479FCCCu,
702 0x461C3DFFu, 0x38D1B6D2u, 0x3A831243u, 0x3C23D6D4u, 0x3DCCCC89u, 0x3F7FFFACu, 0x411FFFCBu, 0x42C7FFBEu,
703 0x4479FFAEu, 0x461C3FCCu, 0x47C34FBFu, 0x38D1B710u, 0x3A83126Au, 0x3C23D704u, 0x3DCCCCC6u, 0x3F7FFFF7u,
704 0x411FFFFAu, 0x42C7FFF9u, 0x4479FFF7u, 0x461C3FFAu, 0x47C34FF9u, 0x497423F7u, 0x38D1B716u, 0x3A83126Eu,
705 0x3C23D709u, 0x3DCCCCCCu, 0x3F7FFFFFu, 0x411FFFFFu, 0x42C7FFFFu, 0x4479FFFFu, 0x461C3FFFu, 0x47C34FFFu,
706 0x497423FFu, 0x4B18967Fu};
707
708 static constexpr int _Max_P = 39;
709
710 static constexpr uint32_t _Ordinary_X_table[44] = {0x38D1B717u, 0x3A83126Eu, 0x3C23D70Au, 0x3DCCCCCCu, 0x3F7FFFFFu,
711 0x411FFFFFu, 0x42C7FFFFu, 0x4479FFFFu, 0x461C3FFFu, 0x47C34FFFu, 0x497423FFu, 0x4B18967Fu, 0x4CBEBC1Fu,
712 0x4E6E6B27u, 0x501502F8u, 0x51BA43B7u, 0x5368D4A5u, 0x551184E7u, 0x56B5E620u, 0x58635FA9u, 0x5A0E1BC9u,
713 0x5BB1A2BCu, 0x5D5E0B6Bu, 0x5F0AC723u, 0x60AD78EBu, 0x6258D726u, 0x64078678u, 0x65A96816u, 0x6753C21Bu,
714 0x69045951u, 0x6AA56FA5u, 0x6C4ECB8Fu, 0x6E013F39u, 0x6FA18F07u, 0x7149F2C9u, 0x72FC6F7Cu, 0x749DC5ADu,
715 0x76453719u, 0x77F684DFu, 0x799A130Bu, 0x7B4097CEu, 0x7CF0BDC2u, 0x7E967699u, 0x7F7FFFFFu};
716};
717
718template <>
719struct _General_precision_tables<double> {
720 static constexpr int _Max_special_P = 15;
721
722 static constexpr uint64_t _Special_X_table[195] = {0x3F18E757928E0C9Du, 0x3F4F212D77318FC5u, 0x3F8374BC6A7EF9DBu,
723 0x3FB851EB851EB851u, 0x3FEE666666666666u, 0x4022FFFFFFFFFFFFu, 0x3F1A1554FBDAD751u, 0x3F504D551D68C692u,
724 0x3F8460AA64C2F837u, 0x3FB978D4FDF3B645u, 0x3FEFD70A3D70A3D7u, 0x4023E66666666666u, 0x4058DFFFFFFFFFFFu,
725 0x3F1A3387ECC8EB96u, 0x3F506034F3FD933Eu, 0x3F84784230FCF80Du, 0x3FB99652BD3C3611u, 0x3FEFFBE76C8B4395u,
726 0x4023FD70A3D70A3Du, 0x4058FCCCCCCCCCCCu, 0x408F3BFFFFFFFFFFu, 0x3F1A368D04E0BA6Au, 0x3F506218230C7482u,
727 0x3F847A9E2BCF91A3u, 0x3FB99945B6C3760Bu, 0x3FEFFF972474538Eu, 0x4023FFBE76C8B439u, 0x4058FFAE147AE147u,
728 0x408F3F9999999999u, 0x40C387BFFFFFFFFFu, 0x3F1A36DA54164F19u, 0x3F506248748DF16Fu, 0x3F847ADA91B16DCBu,
729 0x3FB99991361DC93Eu, 0x3FEFFFF583A53B8Eu, 0x4023FFF972474538u, 0x4058FFF7CED91687u, 0x408F3FF5C28F5C28u,
730 0x40C387F999999999u, 0x40F869F7FFFFFFFFu, 0x3F1A36E20F35445Du, 0x3F50624D49814ABAu, 0x3F847AE09BE19D69u,
731 0x3FB99998C2DA04C3u, 0x3FEFFFFEF39085F4u, 0x4023FFFF583A53B8u, 0x4058FFFF2E48E8A7u, 0x408F3FFEF9DB22D0u,
732 0x40C387FF5C28F5C2u, 0x40F869FF33333333u, 0x412E847EFFFFFFFFu, 0x3F1A36E2D51EC34Bu, 0x3F50624DC5333A0Eu,
733 0x3F847AE136800892u, 0x3FB9999984200AB7u, 0x3FEFFFFFE5280D65u, 0x4023FFFFEF39085Fu, 0x4058FFFFEB074A77u,
734 0x408F3FFFE5C91D14u, 0x40C387FFEF9DB22Du, 0x40F869FFEB851EB8u, 0x412E847FE6666666u, 0x416312CFEFFFFFFFu,
735 0x3F1A36E2E8E94FFCu, 0x3F50624DD191D1FDu, 0x3F847AE145F6467Du, 0x3FB999999773D81Cu, 0x3FEFFFFFFD50CE23u,
736 0x4023FFFFFE5280D6u, 0x4058FFFFFDE7210Bu, 0x408F3FFFFD60E94Eu, 0x40C387FFFE5C91D1u, 0x40F869FFFDF3B645u,
737 0x412E847FFD70A3D7u, 0x416312CFFE666666u, 0x4197D783FDFFFFFFu, 0x3F1A36E2EAE3F7A7u, 0x3F50624DD2CE7AC8u,
738 0x3F847AE14782197Bu, 0x3FB9999999629FD9u, 0x3FEFFFFFFFBB47D0u, 0x4023FFFFFFD50CE2u, 0x4058FFFFFFCA501Au,
739 0x408F3FFFFFBCE421u, 0x40C387FFFFD60E94u, 0x40F869FFFFCB923Au, 0x412E847FFFBE76C8u, 0x416312CFFFD70A3Du,
740 0x4197D783FFCCCCCCu, 0x41CDCD64FFBFFFFFu, 0x3F1A36E2EB16A205u, 0x3F50624DD2EE2543u, 0x3F847AE147A9AE94u,
741 0x3FB9999999941A39u, 0x3FEFFFFFFFF920C8u, 0x4023FFFFFFFBB47Du, 0x4058FFFFFFFAA19Cu, 0x408F3FFFFFF94A03u,
742 0x40C387FFFFFBCE42u, 0x40F869FFFFFAC1D2u, 0x412E847FFFF97247u, 0x416312CFFFFBE76Cu, 0x4197D783FFFAE147u,
743 0x41CDCD64FFF99999u, 0x4202A05F1FFBFFFFu, 0x3F1A36E2EB1BB30Fu, 0x3F50624DD2F14FE9u, 0x3F847AE147ADA3E3u,
744 0x3FB9999999990CDCu, 0x3FEFFFFFFFFF5014u, 0x4023FFFFFFFF920Cu, 0x4058FFFFFFFF768Fu, 0x408F3FFFFFFF5433u,
745 0x40C387FFFFFF94A0u, 0x40F869FFFFFF79C8u, 0x412E847FFFFF583Au, 0x416312CFFFFF9724u, 0x4197D783FFFF7CEDu,
746 0x41CDCD64FFFF5C28u, 0x4202A05F1FFF9999u, 0x42374876E7FF7FFFu, 0x3F1A36E2EB1C34C3u, 0x3F50624DD2F1A0FAu,
747 0x3F847AE147AE0938u, 0x3FB9999999998B86u, 0x3FEFFFFFFFFFEE68u, 0x4023FFFFFFFFF501u, 0x4058FFFFFFFFF241u,
748 0x408F3FFFFFFFEED1u, 0x40C387FFFFFFF543u, 0x40F869FFFFFFF294u, 0x412E847FFFFFEF39u, 0x416312CFFFFFF583u,
749 0x4197D783FFFFF2E4u, 0x41CDCD64FFFFEF9Du, 0x4202A05F1FFFF5C2u, 0x42374876E7FFF333u, 0x426D1A94A1FFEFFFu,
750 0x3F1A36E2EB1C41BBu, 0x3F50624DD2F1A915u, 0x3F847AE147AE135Au, 0x3FB9999999999831u, 0x3FEFFFFFFFFFFE3Du,
751 0x4023FFFFFFFFFEE6u, 0x4058FFFFFFFFFEA0u, 0x408F3FFFFFFFFE48u, 0x40C387FFFFFFFEEDu, 0x40F869FFFFFFFEA8u,
752 0x412E847FFFFFFE52u, 0x416312CFFFFFFEF3u, 0x4197D783FFFFFEB0u, 0x41CDCD64FFFFFE5Cu, 0x4202A05F1FFFFEF9u,
753 0x42374876E7FFFEB8u, 0x426D1A94A1FFFE66u, 0x42A2309CE53FFEFFu, 0x3F1A36E2EB1C4307u, 0x3F50624DD2F1A9E4u,
754 0x3F847AE147AE145Eu, 0x3FB9999999999975u, 0x3FEFFFFFFFFFFFD2u, 0x4023FFFFFFFFFFE3u, 0x4058FFFFFFFFFFDCu,
755 0x408F3FFFFFFFFFD4u, 0x40C387FFFFFFFFE4u, 0x40F869FFFFFFFFDDu, 0x412E847FFFFFFFD5u, 0x416312CFFFFFFFE5u,
756 0x4197D783FFFFFFDEu, 0x41CDCD64FFFFFFD6u, 0x4202A05F1FFFFFE5u, 0x42374876E7FFFFDFu, 0x426D1A94A1FFFFD7u,
757 0x42A2309CE53FFFE6u, 0x42D6BCC41E8FFFDFu, 0x3F1A36E2EB1C4328u, 0x3F50624DD2F1A9F9u, 0x3F847AE147AE1477u,
758 0x3FB9999999999995u, 0x3FEFFFFFFFFFFFFBu, 0x4023FFFFFFFFFFFDu, 0x4058FFFFFFFFFFFCu, 0x408F3FFFFFFFFFFBu,
759 0x40C387FFFFFFFFFDu, 0x40F869FFFFFFFFFCu, 0x412E847FFFFFFFFBu, 0x416312CFFFFFFFFDu, 0x4197D783FFFFFFFCu,
760 0x41CDCD64FFFFFFFBu, 0x4202A05F1FFFFFFDu, 0x42374876E7FFFFFCu, 0x426D1A94A1FFFFFBu, 0x42A2309CE53FFFFDu,
761 0x42D6BCC41E8FFFFCu, 0x430C6BF52633FFFBu};
762
763 static constexpr int _Max_P = 309;
764
765 static constexpr uint64_t _Ordinary_X_table[314] = {0x3F1A36E2EB1C432Cu, 0x3F50624DD2F1A9FBu, 0x3F847AE147AE147Au,
766 0x3FB9999999999999u, 0x3FEFFFFFFFFFFFFFu, 0x4023FFFFFFFFFFFFu, 0x4058FFFFFFFFFFFFu, 0x408F3FFFFFFFFFFFu,
767 0x40C387FFFFFFFFFFu, 0x40F869FFFFFFFFFFu, 0x412E847FFFFFFFFFu, 0x416312CFFFFFFFFFu, 0x4197D783FFFFFFFFu,
768 0x41CDCD64FFFFFFFFu, 0x4202A05F1FFFFFFFu, 0x42374876E7FFFFFFu, 0x426D1A94A1FFFFFFu, 0x42A2309CE53FFFFFu,
769 0x42D6BCC41E8FFFFFu, 0x430C6BF52633FFFFu, 0x4341C37937E07FFFu, 0x4376345785D89FFFu, 0x43ABC16D674EC7FFu,
770 0x43E158E460913CFFu, 0x4415AF1D78B58C3Fu, 0x444B1AE4D6E2EF4Fu, 0x4480F0CF064DD591u, 0x44B52D02C7E14AF6u,
771 0x44EA784379D99DB4u, 0x45208B2A2C280290u, 0x4554ADF4B7320334u, 0x4589D971E4FE8401u, 0x45C027E72F1F1281u,
772 0x45F431E0FAE6D721u, 0x46293E5939A08CE9u, 0x465F8DEF8808B024u, 0x4693B8B5B5056E16u, 0x46C8A6E32246C99Cu,
773 0x46FED09BEAD87C03u, 0x4733426172C74D82u, 0x476812F9CF7920E2u, 0x479E17B84357691Bu, 0x47D2CED32A16A1B1u,
774 0x48078287F49C4A1Du, 0x483D6329F1C35CA4u, 0x48725DFA371A19E6u, 0x48A6F578C4E0A060u, 0x48DCB2D6F618C878u,
775 0x4911EFC659CF7D4Bu, 0x49466BB7F0435C9Eu, 0x497C06A5EC5433C6u, 0x49B18427B3B4A05Bu, 0x49E5E531A0A1C872u,
776 0x4A1B5E7E08CA3A8Fu, 0x4A511B0EC57E6499u, 0x4A8561D276DDFDC0u, 0x4ABABA4714957D30u, 0x4AF0B46C6CDD6E3Eu,
777 0x4B24E1878814C9CDu, 0x4B5A19E96A19FC40u, 0x4B905031E2503DA8u, 0x4BC4643E5AE44D12u, 0x4BF97D4DF19D6057u,
778 0x4C2FDCA16E04B86Du, 0x4C63E9E4E4C2F344u, 0x4C98E45E1DF3B015u, 0x4CCF1D75A5709C1Au, 0x4D03726987666190u,
779 0x4D384F03E93FF9F4u, 0x4D6E62C4E38FF872u, 0x4DA2FDBB0E39FB47u, 0x4DD7BD29D1C87A19u, 0x4E0DAC74463A989Fu,
780 0x4E428BC8ABE49F63u, 0x4E772EBAD6DDC73Cu, 0x4EACFA698C95390Bu, 0x4EE21C81F7DD43A7u, 0x4F16A3A275D49491u,
781 0x4F4C4C8B1349B9B5u, 0x4F81AFD6EC0E1411u, 0x4FB61BCCA7119915u, 0x4FEBA2BFD0D5FF5Bu, 0x502145B7E285BF98u,
782 0x50559725DB272F7Fu, 0x508AFCEF51F0FB5Eu, 0x50C0DE1593369D1Bu, 0x50F5159AF8044462u, 0x512A5B01B605557Au,
783 0x516078E111C3556Cu, 0x5194971956342AC7u, 0x51C9BCDFABC13579u, 0x5200160BCB58C16Cu, 0x52341B8EBE2EF1C7u,
784 0x526922726DBAAE39u, 0x529F6B0F092959C7u, 0x52D3A2E965B9D81Cu, 0x53088BA3BF284E23u, 0x533EAE8CAEF261ACu,
785 0x53732D17ED577D0Bu, 0x53A7F85DE8AD5C4Eu, 0x53DDF67562D8B362u, 0x5412BA095DC7701Du, 0x5447688BB5394C25u,
786 0x547D42AEA2879F2Eu, 0x54B249AD2594C37Cu, 0x54E6DC186EF9F45Cu, 0x551C931E8AB87173u, 0x5551DBF316B346E7u,
787 0x558652EFDC6018A1u, 0x55BBE7ABD3781ECAu, 0x55F170CB642B133Eu, 0x5625CCFE3D35D80Eu, 0x565B403DCC834E11u,
788 0x569108269FD210CBu, 0x56C54A3047C694FDu, 0x56FA9CBC59B83A3Du, 0x5730A1F5B8132466u, 0x5764CA732617ED7Fu,
789 0x5799FD0FEF9DE8DFu, 0x57D03E29F5C2B18Bu, 0x58044DB473335DEEu, 0x583961219000356Au, 0x586FB969F40042C5u,
790 0x58A3D3E2388029BBu, 0x58D8C8DAC6A0342Au, 0x590EFB1178484134u, 0x59435CEAEB2D28C0u, 0x59783425A5F872F1u,
791 0x59AE412F0F768FADu, 0x59E2E8BD69AA19CCu, 0x5A17A2ECC414A03Fu, 0x5A4D8BA7F519C84Fu, 0x5A827748F9301D31u,
792 0x5AB7151B377C247Eu, 0x5AECDA62055B2D9Du, 0x5B22087D4358FC82u, 0x5B568A9C942F3BA3u, 0x5B8C2D43B93B0A8Bu,
793 0x5BC19C4A53C4E697u, 0x5BF6035CE8B6203Du, 0x5C2B843422E3A84Cu, 0x5C6132A095CE492Fu, 0x5C957F48BB41DB7Bu,
794 0x5CCADF1AEA12525Au, 0x5D00CB70D24B7378u, 0x5D34FE4D06DE5056u, 0x5D6A3DE04895E46Cu, 0x5DA066AC2D5DAEC3u,
795 0x5DD4805738B51A74u, 0x5E09A06D06E26112u, 0x5E400444244D7CABu, 0x5E7405552D60DBD6u, 0x5EA906AA78B912CBu,
796 0x5EDF485516E7577Eu, 0x5F138D352E5096AFu, 0x5F48708279E4BC5Au, 0x5F7E8CA3185DEB71u, 0x5FB317E5EF3AB327u,
797 0x5FE7DDDF6B095FF0u, 0x601DD55745CBB7ECu, 0x6052A5568B9F52F4u, 0x60874EAC2E8727B1u, 0x60BD22573A28F19Du,
798 0x60F2357684599702u, 0x6126C2D4256FFCC2u, 0x615C73892ECBFBF3u, 0x6191C835BD3F7D78u, 0x61C63A432C8F5CD6u,
799 0x61FBC8D3F7B3340Bu, 0x62315D847AD00087u, 0x6265B4E5998400A9u, 0x629B221EFFE500D3u, 0x62D0F5535FEF2084u,
800 0x630532A837EAE8A5u, 0x633A7F5245E5A2CEu, 0x63708F936BAF85C1u, 0x63A4B378469B6731u, 0x63D9E056584240FDu,
801 0x64102C35F729689Eu, 0x6444374374F3C2C6u, 0x647945145230B377u, 0x64AF965966BCE055u, 0x64E3BDF7E0360C35u,
802 0x6518AD75D8438F43u, 0x654ED8D34E547313u, 0x6583478410F4C7ECu, 0x65B819651531F9E7u, 0x65EE1FBE5A7E7861u,
803 0x6622D3D6F88F0B3Cu, 0x665788CCB6B2CE0Cu, 0x668D6AFFE45F818Fu, 0x66C262DFEEBBB0F9u, 0x66F6FB97EA6A9D37u,
804 0x672CBA7DE5054485u, 0x6761F48EAF234AD3u, 0x679671B25AEC1D88u, 0x67CC0E1EF1A724EAu, 0x680188D357087712u,
805 0x6835EB082CCA94D7u, 0x686B65CA37FD3A0Du, 0x68A11F9E62FE4448u, 0x68D56785FBBDD55Au, 0x690AC1677AAD4AB0u,
806 0x6940B8E0ACAC4EAEu, 0x6974E718D7D7625Au, 0x69AA20DF0DCD3AF0u, 0x69E0548B68A044D6u, 0x6A1469AE42C8560Cu,
807 0x6A498419D37A6B8Fu, 0x6A7FE52048590672u, 0x6AB3EF342D37A407u, 0x6AE8EB0138858D09u, 0x6B1F25C186A6F04Cu,
808 0x6B537798F428562Fu, 0x6B88557F31326BBBu, 0x6BBE6ADEFD7F06AAu, 0x6BF302CB5E6F642Au, 0x6C27C37E360B3D35u,
809 0x6C5DB45DC38E0C82u, 0x6C9290BA9A38C7D1u, 0x6CC734E940C6F9C5u, 0x6CFD022390F8B837u, 0x6D3221563A9B7322u,
810 0x6D66A9ABC9424FEBu, 0x6D9C5416BB92E3E6u, 0x6DD1B48E353BCE6Fu, 0x6E0621B1C28AC20Bu, 0x6E3BAA1E332D728Eu,
811 0x6E714A52DFFC6799u, 0x6EA59CE797FB817Fu, 0x6EDB04217DFA61DFu, 0x6F10E294EEBC7D2Bu, 0x6F451B3A2A6B9C76u,
812 0x6F7A6208B5068394u, 0x6FB07D457124123Cu, 0x6FE49C96CD6D16CBu, 0x7019C3BC80C85C7Eu, 0x70501A55D07D39CFu,
813 0x708420EB449C8842u, 0x70B9292615C3AA53u, 0x70EF736F9B3494E8u, 0x7123A825C100DD11u, 0x7158922F31411455u,
814 0x718EB6BAFD91596Bu, 0x71C33234DE7AD7E2u, 0x71F7FEC216198DDBu, 0x722DFE729B9FF152u, 0x7262BF07A143F6D3u,
815 0x72976EC98994F488u, 0x72CD4A7BEBFA31AAu, 0x73024E8D737C5F0Au, 0x7336E230D05B76CDu, 0x736C9ABD04725480u,
816 0x73A1E0B622C774D0u, 0x73D658E3AB795204u, 0x740BEF1C9657A685u, 0x74417571DDF6C813u, 0x7475D2CE55747A18u,
817 0x74AB4781EAD1989Eu, 0x74E10CB132C2FF63u, 0x75154FDD7F73BF3Bu, 0x754AA3D4DF50AF0Au, 0x7580A6650B926D66u,
818 0x75B4CFFE4E7708C0u, 0x75EA03FDE214CAF0u, 0x7620427EAD4CFED6u, 0x7654531E58A03E8Bu, 0x768967E5EEC84E2Eu,
819 0x76BFC1DF6A7A61BAu, 0x76F3D92BA28C7D14u, 0x7728CF768B2F9C59u, 0x775F03542DFB8370u, 0x779362149CBD3226u,
820 0x77C83A99C3EC7EAFu, 0x77FE494034E79E5Bu, 0x7832EDC82110C2F9u, 0x7867A93A2954F3B7u, 0x789D9388B3AA30A5u,
821 0x78D27C35704A5E67u, 0x79071B42CC5CF601u, 0x793CE2137F743381u, 0x79720D4C2FA8A030u, 0x79A6909F3B92C83Du,
822 0x79DC34C70A777A4Cu, 0x7A11A0FC668AAC6Fu, 0x7A46093B802D578Bu, 0x7A7B8B8A6038AD6Eu, 0x7AB137367C236C65u,
823 0x7AE585041B2C477Eu, 0x7B1AE64521F7595Eu, 0x7B50CFEB353A97DAu, 0x7B8503E602893DD1u, 0x7BBA44DF832B8D45u,
824 0x7BF06B0BB1FB384Bu, 0x7C2485CE9E7A065Eu, 0x7C59A742461887F6u, 0x7C9008896BCF54F9u, 0x7CC40AABC6C32A38u,
825 0x7CF90D56B873F4C6u, 0x7D2F50AC6690F1F8u, 0x7D63926BC01A973Bu, 0x7D987706B0213D09u, 0x7DCE94C85C298C4Cu,
826 0x7E031CFD3999F7AFu, 0x7E37E43C8800759Bu, 0x7E6DDD4BAA009302u, 0x7EA2AA4F4A405BE1u, 0x7ED754E31CD072D9u,
827 0x7F0D2A1BE4048F90u, 0x7F423A516E82D9BAu, 0x7F76C8E5CA239028u, 0x7FAC7B1F3CAC7433u, 0x7FE1CCF385EBC89Fu,
828 0x7FEFFFFFFFFFFFFFu};
829};
830
831template <class _Floating>
832[[nodiscard]] _LIBCPP_HIDE_FROM_ABI
833to_chars_result _Floating_to_chars_general_precision(
834 char* _First, char* const _Last, const _Floating _Value, int _Precision) noexcept {
835
836 using _Traits = _Floating_type_traits<_Floating>;
837 using _Uint_type = typename _Traits::_Uint_type;
838
839 const _Uint_type _Uint_value = _VSTD::bit_cast<_Uint_type>(_Value);
840
841 if (_Uint_value == 0) { // zero detected; write "0" and return; _Precision is irrelevant due to zero-trimming
842 if (_First == _Last) {
843 return {_Last, errc::value_too_large};
844 }
845
846 *_First++ = '0';
847
848 return {_First, errc{}};
849 }
850
851 // C11 7.21.6.1 "The fprintf function"/5:
852 // "A negative precision argument is taken as if the precision were omitted."
853 // /8: "g,G [...] Let P equal the precision if nonzero, 6 if the precision is omitted,
854 // or 1 if the precision is zero."
855
856 // Performance note: It's possible to rewrite this for branchless codegen,
857 // but profiling will be necessary to determine whether that's faster.
858 if (_Precision < 0) {
859 _Precision = 6;
860 } else if (_Precision == 0) {
861 _Precision = 1;
862 } else if (_Precision < 1'000'000) {
863 // _Precision is ok.
864 } else {
865 // Avoid integer overflow.
866 // Due to general notation's zero-trimming behavior, we can simply clamp _Precision.
867 // This is further clamped below.
868 _Precision = 1'000'000;
869 }
870
871 // _Precision is now the Standard's P.
872
873 // /8: "Then, if a conversion with style E would have an exponent of X:
874 // - if P > X >= -4, the conversion is with style f (or F) and precision P - (X + 1).
875 // - otherwise, the conversion is with style e (or E) and precision P - 1."
876
877 // /8: "Finally, [...] any trailing zeros are removed from the fractional portion of the result
878 // and the decimal-point character is removed if there is no fractional portion remaining."
879
880 using _Tables = _General_precision_tables<_Floating>;
881
882 const _Uint_type* _Table_begin;
883 const _Uint_type* _Table_end;
884
885 if (_Precision <= _Tables::_Max_special_P) {
886 _Table_begin = _Tables::_Special_X_table + (_Precision - 1) * (_Precision + 10) / 2;
887 _Table_end = _Table_begin + _Precision + 5;
888 } else {
889 _Table_begin = _Tables::_Ordinary_X_table;
890 _Table_end = _Table_begin + _VSTD::min(_Precision, _Tables::_Max_P) + 5;
891 }
892
893 // Profiling indicates that linear search is faster than binary search for small tables.
894 // Performance note: lambda captures may have a small performance cost.
895 const _Uint_type* const _Table_lower_bound = [=] {
896 if constexpr (!_IsSame<_Floating, float>::value) {
897 if (_Precision > 155) { // threshold determined via profiling
898 return _VSTD::lower_bound(_Table_begin, _Table_end, _Uint_value, less{});
899 }
900 }
901
902 return _VSTD::find_if(_Table_begin, _Table_end, [=](const _Uint_type _Elem) { return _Uint_value <= _Elem; });
903 }();
904
905 const ptrdiff_t _Table_index = _Table_lower_bound - _Table_begin;
906 const int _Scientific_exponent_X = static_cast<int>(_Table_index - 5);
907 const bool _Use_fixed_notation = _Precision > _Scientific_exponent_X && _Scientific_exponent_X >= -4;
908
909 // Performance note: it might (or might not) be faster to modify Ryu Printf to perform zero-trimming.
910 // Such modifications would involve a fairly complicated state machine (notably, both '0' and '9' digits would
911 // need to be buffered, due to rounding), and that would have performance costs due to increased branching.
912 // Here, we're using a simpler approach: writing into a local buffer, manually zero-trimming, and then copying into
913 // the output range. The necessary buffer size is reasonably small, the zero-trimming logic is simple and fast,
914 // and the final copying is also fast.
915
916 constexpr int _Max_output_length =
917 _IsSame<_Floating, float>::value ? 117 : 773; // cases: 0x1.fffffep-126f and 0x1.fffffffffffffp-1022
918 constexpr int _Max_fixed_precision =
919 _IsSame<_Floating, float>::value ? 37 : 66; // cases: 0x1.fffffep-14f and 0x1.fffffffffffffp-14
920 constexpr int _Max_scientific_precision =
921 _IsSame<_Floating, float>::value ? 111 : 766; // cases: 0x1.fffffep-126f and 0x1.fffffffffffffp-1022
922
923 // Note that _Max_output_length is determined by scientific notation and is more than enough for fixed notation.
924 // 0x1.fffffep+127f is 39 digits, plus 1 for '.', plus _Max_fixed_precision for '0' digits, equals 77.
925 // 0x1.fffffffffffffp+1023 is 309 digits, plus 1 for '.', plus _Max_fixed_precision for '0' digits, equals 376.
926
927 char _Buffer[_Max_output_length];
928 const char* const _Significand_first = _Buffer; // e.g. "1.234"
929 const char* _Significand_last = nullptr;
930 const char* _Exponent_first = nullptr; // e.g. "e-05"
931 const char* _Exponent_last = nullptr;
932 int _Effective_precision; // number of digits printed after the decimal point, before trimming
933
934 // Write into the local buffer.
935 // Clamping _Effective_precision allows _Buffer to be as small as possible, and increases efficiency.
936 if (_Use_fixed_notation) {
937 _Effective_precision = _VSTD::min(_Precision - (_Scientific_exponent_X + 1), _Max_fixed_precision);
938 const to_chars_result _Buf_result =
939 _Floating_to_chars_fixed_precision(_Buffer, _VSTD::end(_Buffer), _Value, _Effective_precision);
940 _LIBCPP_ASSERT(_Buf_result.ec == errc{}, "");
941 _Significand_last = _Buf_result.ptr;
942 } else {
943 _Effective_precision = _VSTD::min(_Precision - 1, _Max_scientific_precision);
944 const to_chars_result _Buf_result =
945 _Floating_to_chars_scientific_precision(_Buffer, _VSTD::end(_Buffer), _Value, _Effective_precision);
946 _LIBCPP_ASSERT(_Buf_result.ec == errc{}, "");
947 _Significand_last = _VSTD::find(_Buffer, _Buf_result.ptr, 'e');
948 _Exponent_first = _Significand_last;
949 _Exponent_last = _Buf_result.ptr;
950 }
951
952 // If we printed a decimal point followed by digits, perform zero-trimming.
953 if (_Effective_precision > 0) {
954 while (_Significand_last[-1] == '0') { // will stop at '.' or a nonzero digit
955 --_Significand_last;
956 }
957
958 if (_Significand_last[-1] == '.') {
959 --_Significand_last;
960 }
961 }
962
963 // Copy the significand to the output range.
964 const ptrdiff_t _Significand_distance = _Significand_last - _Significand_first;
965 if (_Last - _First < _Significand_distance) {
966 return {_Last, errc::value_too_large};
967 }
968 _VSTD::memcpy(_First, _Significand_first, static_cast<size_t>(_Significand_distance));
969 _First += _Significand_distance;
970
971 // Copy the exponent to the output range.
972 if (!_Use_fixed_notation) {
973 const ptrdiff_t _Exponent_distance = _Exponent_last - _Exponent_first;
974 if (_Last - _First < _Exponent_distance) {
975 return {_Last, errc::value_too_large};
976 }
977 _VSTD::memcpy(_First, _Exponent_first, static_cast<size_t>(_Exponent_distance));
978 _First += _Exponent_distance;
979 }
980
981 return {_First, errc{}};
982}
983
984enum class _Floating_to_chars_overload { _Plain, _Format_only, _Format_precision };
985
986template <_Floating_to_chars_overload _Overload, class _Floating>
987[[nodiscard]] _LIBCPP_HIDE_FROM_ABI
988to_chars_result _Floating_to_chars(
989 char* _First, char* const _Last, _Floating _Value, const chars_format _Fmt, const int _Precision) noexcept {
990
991 if constexpr (_Overload == _Floating_to_chars_overload::_Plain) {
992 _LIBCPP_ASSERT(_Fmt == chars_format{}, ""); // plain overload must pass chars_format{} internally
993 } else {
994 _LIBCPP_ASSERT(_Fmt == chars_format::general || _Fmt == chars_format::scientific || _Fmt == chars_format::fixed
995 || _Fmt == chars_format::hex,
996 "invalid format in to_chars()");
997 }
998
999 using _Traits = _Floating_type_traits<_Floating>;
1000 using _Uint_type = typename _Traits::_Uint_type;
1001
1002 _Uint_type _Uint_value = _VSTD::bit_cast<_Uint_type>(_Value);
1003
1004 const bool _Was_negative = (_Uint_value & _Traits::_Shifted_sign_mask) != 0;
1005
1006 if (_Was_negative) { // sign bit detected; write minus sign and clear sign bit
1007 if (_First == _Last) {
1008 return {_Last, errc::value_too_large};
1009 }
1010
1011 *_First++ = '-';
1012
1013 _Uint_value &= ~_Traits::_Shifted_sign_mask;
1014 _Value = _VSTD::bit_cast<_Floating>(_Uint_value);
1015 }
1016
1017 if ((_Uint_value & _Traits::_Shifted_exponent_mask) == _Traits::_Shifted_exponent_mask) {
1018 // inf/nan detected; write appropriate string and return
1019 const char* _Str;
1020 size_t _Len;
1021
1022 const _Uint_type _Mantissa = _Uint_value & _Traits::_Denormal_mantissa_mask;
1023
1024 if (_Mantissa == 0) {
1025 _Str = "inf";
1026 _Len = 3;
1027 } else if (_Was_negative && _Mantissa == _Traits::_Special_nan_mantissa_mask) {
1028 // When a NaN value has the sign bit set, the quiet bit set, and all other mantissa bits cleared,
1029 // the UCRT interprets it to mean "indeterminate", and indicates this by printing "-nan(ind)".
1030 _Str = "nan(ind)";
1031 _Len = 8;
1032 } else if ((_Mantissa & _Traits::_Special_nan_mantissa_mask) != 0) {
1033 _Str = "nan";
1034 _Len = 3;
1035 } else {
1036 _Str = "nan(snan)";
1037 _Len = 9;
1038 }
1039
1040 if (_Last - _First < static_cast<ptrdiff_t>(_Len)) {
1041 return {_Last, errc::value_too_large};
1042 }
1043
1044 _VSTD::memcpy(_First, _Str, _Len);
1045
1046 return {_First + _Len, errc{}};
1047 }
1048
1049 if constexpr (_Overload == _Floating_to_chars_overload::_Plain) {
1050 return _Floating_to_chars_ryu(_First, _Last, _Value, chars_format{});
1051 } else if constexpr (_Overload == _Floating_to_chars_overload::_Format_only) {
1052 if (_Fmt == chars_format::hex) {
1053 return _Floating_to_chars_hex_shortest(_First, _Last, _Value);
1054 }
1055
1056 return _Floating_to_chars_ryu(_First, _Last, _Value, _Fmt);
1057 } else if constexpr (_Overload == _Floating_to_chars_overload::_Format_precision) {
1058 switch (_Fmt) {
1059 case chars_format::scientific:
1060 return _Floating_to_chars_scientific_precision(_First, _Last, _Value, _Precision);
1061 case chars_format::fixed:
1062 return _Floating_to_chars_fixed_precision(_First, _Last, _Value, _Precision);
1063 case chars_format::general:
1064 return _Floating_to_chars_general_precision(_First, _Last, _Value, _Precision);
1065 case chars_format::hex:
1066 default: // avoid MSVC warning C4715: not all control paths return a value
1067 return _Floating_to_chars_hex_precision(_First, _Last, _Value, _Precision);
1068 }
1069 }
1070}
1071
1072// clang-format on
1073
1074_LIBCPP_END_NAMESPACE_STD
1075
1076#endif // _LIBCPP_SRC_INCLUDE_TO_CHARS_FLOATING_POINT_H
lib/libcxx/src/ios.cpp+2-2
......@@ -1,4 +1,4 @@
1//===-------------------------- ios.cpp -----------------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
......@@ -137,7 +137,7 @@ ios_base::getloc() const
137137
138138// xalloc
139139#if defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_NO_THREADS)
140atomic<int> ios_base::__xindex_ = ATOMIC_VAR_INIT(0);
140atomic<int> ios_base::__xindex_{0};
141141#else
142142int ios_base::__xindex_ = 0;
143143#endif
lib/libcxx/src/ios.instantiations.cpp+7-4
......@@ -19,15 +19,18 @@ _LIBCPP_BEGIN_NAMESPACE_STD
1919
2020// Original explicit instantiations provided in the library
2121template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ios<char>;
22template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ios<wchar_t>;
2322template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_streambuf<char>;
24template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_streambuf<wchar_t>;
2523template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_istream<char>;
26template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_istream<wchar_t>;
2724template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ostream<char>;
28template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ostream<wchar_t>;
2925template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_iostream<char>;
3026
27#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
28template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ios<wchar_t>;
29template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_streambuf<wchar_t>;
30template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_istream<wchar_t>;
31template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ostream<wchar_t>;
32#endif
33
3134// Additional instantiations added later. Whether programs rely on these being
3235// available is protected by _LIBCPP_ABI_ENABLE_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1.
3336template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_stringbuf<char>;
lib/libcxx/src/iostream.cpp+29-24
......@@ -1,4 +1,4 @@
1//===------------------------ iostream.cpp --------------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
......@@ -17,7 +17,6 @@
1717
1818_LIBCPP_BEGIN_NAMESPACE_STD
1919
20#ifndef _LIBCPP_HAS_NO_STDIN
2120_ALIGNAS_TYPE (istream) _LIBCPP_FUNC_VIS char cin[sizeof(istream)]
2221#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
2322__asm__("?cin@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_istream@DU?$char_traits@D@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
......@@ -25,6 +24,8 @@ __asm__("?cin@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_istream@DU?$char_trai
2524;
2625_ALIGNAS_TYPE (__stdinbuf<char> ) static char __cin[sizeof(__stdinbuf <char>)];
2726static mbstate_t mb_cin;
27
28#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
2829_ALIGNAS_TYPE (wistream) _LIBCPP_FUNC_VIS char wcin[sizeof(wistream)]
2930#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
3031__asm__("?wcin@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_istream@_WU?$char_traits@_W@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
......@@ -32,9 +33,8 @@ __asm__("?wcin@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_istream@_WU?$char_tr
3233;
3334_ALIGNAS_TYPE (__stdinbuf<wchar_t> ) static char __wcin[sizeof(__stdinbuf <wchar_t>)];
3435static mbstate_t mb_wcin;
35#endif
36#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
3637
37#ifndef _LIBCPP_HAS_NO_STDOUT
3838_ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char cout[sizeof(ostream)]
3939#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
4040__asm__("?cout@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@DU?$char_traits@D@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
......@@ -42,6 +42,8 @@ __asm__("?cout@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@DU?$char_tra
4242;
4343_ALIGNAS_TYPE (__stdoutbuf<char>) static char __cout[sizeof(__stdoutbuf<char>)];
4444static mbstate_t mb_cout;
45
46#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4547_ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wcout[sizeof(wostream)]
4648#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
4749__asm__("?wcout@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_traits@_W@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
......@@ -49,7 +51,7 @@ __asm__("?wcout@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_t
4951;
5052_ALIGNAS_TYPE (__stdoutbuf<wchar_t>) static char __wcout[sizeof(__stdoutbuf<wchar_t>)];
5153static mbstate_t mb_wcout;
52#endif
54#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
5355
5456_ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char cerr[sizeof(ostream)]
5557#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
......@@ -58,6 +60,8 @@ __asm__("?cerr@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@DU?$char_tra
5860;
5961_ALIGNAS_TYPE (__stdoutbuf<char>) static char __cerr[sizeof(__stdoutbuf<char>)];
6062static mbstate_t mb_cerr;
63
64#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
6165_ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wcerr[sizeof(wostream)]
6266#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
6367__asm__("?wcerr@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_traits@_W@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
......@@ -65,19 +69,25 @@ __asm__("?wcerr@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_t
6569;
6670_ALIGNAS_TYPE (__stdoutbuf<wchar_t>) static char __wcerr[sizeof(__stdoutbuf<wchar_t>)];
6771static mbstate_t mb_wcerr;
72#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
6873
6974_ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char clog[sizeof(ostream)]
7075#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
7176__asm__("?clog@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@DU?$char_traits@D@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
7277#endif
7378;
79
80#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
7481_ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wclog[sizeof(wostream)]
7582#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
7683__asm__("?wclog@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_traits@_W@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
7784#endif
7885;
86#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
7987
80_LIBCPP_HIDDEN ios_base::Init __start_std_streams _LIBCPP_INIT_PRIORITY_MAX;
88// Pretend we're inside a system header so the compiler doesn't flag the use of the init_priority
89// attribute with a value that's reserved for the implementation (we're the implementation).
90#include "iostream_init.h"
8191
8292// On Windows the TLS storage for locales needs to be initialized before we create
8393// the standard streams, otherwise it may not be alive during program termination
......@@ -107,44 +117,39 @@ DoIOSInit::DoIOSInit()
107117{
108118 force_locale_initialization();
109119
110#ifndef _LIBCPP_HAS_NO_STDIN
111120 istream* cin_ptr = ::new(cin) istream(::new(__cin) __stdinbuf <char>(stdin, &mb_cin));
112 wistream* wcin_ptr = ::new(wcin) wistream(::new(__wcin) __stdinbuf <wchar_t>(stdin, &mb_wcin));
113#endif
114#ifndef _LIBCPP_HAS_NO_STDOUT
115121 ostream* cout_ptr = ::new(cout) ostream(::new(__cout) __stdoutbuf<char>(stdout, &mb_cout));
116 wostream* wcout_ptr = ::new(wcout) wostream(::new(__wcout) __stdoutbuf<wchar_t>(stdout, &mb_wcout));
117#endif
118122 ostream* cerr_ptr = ::new(cerr) ostream(::new(__cerr) __stdoutbuf<char>(stderr, &mb_cerr));
119123 ::new(clog) ostream(cerr_ptr->rdbuf());
124 cin_ptr->tie(cout_ptr);
125 _VSTD::unitbuf(*cerr_ptr);
126 cerr_ptr->tie(cout_ptr);
127
128#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
129 wistream* wcin_ptr = ::new(wcin) wistream(::new(__wcin) __stdinbuf <wchar_t>(stdin, &mb_wcin));
130 wostream* wcout_ptr = ::new(wcout) wostream(::new(__wcout) __stdoutbuf<wchar_t>(stdout, &mb_wcout));
120131 wostream* wcerr_ptr = ::new(wcerr) wostream(::new(__wcerr) __stdoutbuf<wchar_t>(stderr, &mb_wcerr));
121132 ::new(wclog) wostream(wcerr_ptr->rdbuf());
122133
123#if !defined(_LIBCPP_HAS_NO_STDIN) && !defined(_LIBCPP_HAS_NO_STDOUT)
124 cin_ptr->tie(cout_ptr);
125134 wcin_ptr->tie(wcout_ptr);
126#endif
127 _VSTD::unitbuf(*cerr_ptr);
128135 _VSTD::unitbuf(*wcerr_ptr);
129#ifndef _LIBCPP_HAS_NO_STDOUT
130 cerr_ptr->tie(cout_ptr);
131136 wcerr_ptr->tie(wcout_ptr);
132137#endif
133138}
134139
135140DoIOSInit::~DoIOSInit()
136141{
137#ifndef _LIBCPP_HAS_NO_STDOUT
138142 ostream* cout_ptr = reinterpret_cast<ostream*>(cout);
139 wostream* wcout_ptr = reinterpret_cast<wostream*>(wcout);
140143 cout_ptr->flush();
141 wcout_ptr->flush();
142#endif
143
144144 ostream* clog_ptr = reinterpret_cast<ostream*>(clog);
145 wostream* wclog_ptr = reinterpret_cast<wostream*>(wclog);
146145 clog_ptr->flush();
146
147#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
148 wostream* wcout_ptr = reinterpret_cast<wostream*>(wcout);
149 wcout_ptr->flush();
150 wostream* wclog_ptr = reinterpret_cast<wostream*>(wclog);
147151 wclog_ptr->flush();
152#endif
148153}
149154
150155ios_base::Init::Init()
lib/libcxx/src/iostream_init.h created+2
......@@ -0,0 +1,2 @@
1#pragma GCC system_header
2_LIBCPP_HIDDEN ios_base::Init __start_std_streams _LIBCPP_INIT_PRIORITY_MAX;
lib/libcxx/src/legacy_pointer_safety.cpp created+23
......@@ -0,0 +1,23 @@
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 <memory>
11
12// Support for garbage collection was removed in C++23 by https://wg21.link/P2186R2. Libc++ implements
13// that removal as an extension in all Standard versions. However, we still define the functions that
14// were once part of the library's ABI for backwards compatibility.
15
16_LIBCPP_BEGIN_NAMESPACE_STD
17
18_LIBCPP_FUNC_VIS void declare_reachable(void*) {}
19_LIBCPP_FUNC_VIS void declare_no_pointers(char*, size_t) {}
20_LIBCPP_FUNC_VIS void undeclare_no_pointers(char*, size_t) {}
21_LIBCPP_FUNC_VIS void* __undeclare_reachable(void* p) { return p; }
22
23_LIBCPP_END_NAMESPACE_STD
lib/libcxx/src/locale.cpp+363-109
......@@ -1,4 +1,4 @@
1//===------------------------- locale.cpp ---------------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
......@@ -12,28 +12,36 @@
1212#define _LCONV_C99
1313#endif
1414
15#include "string"
16#include "locale"
17#include "codecvt"
18#include "vector"
1915#include "algorithm"
20#include "typeinfo"
21#ifndef _LIBCPP_NO_EXCEPTIONS
22# include "type_traits"
23#endif
2416#include "clocale"
17#include "codecvt"
18#include "cstdio"
19#include "cstdlib"
2520#include "cstring"
21#include "locale"
22#include "string"
23#include "type_traits"
24#include "typeinfo"
25#include "vector"
26
27#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
28# include "cwctype"
29#endif
30
31#if defined(_AIX)
32# include <sys/localedef.h> // for __lc_ctype_ptr
33#endif
34
2635#if defined(_LIBCPP_MSVCRT)
27#define _CTYPE_DISABLE_MACROS
36# define _CTYPE_DISABLE_MACROS
2837#endif
29#include "cwctype"
38
3039#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
31#include "__support/win32/locale_win32.h"
40# include "__support/win32/locale_win32.h"
3241#elif !defined(__BIONIC__) && !defined(__NuttX__)
33#include <langinfo.h>
42# include <langinfo.h>
3443#endif
35#include <stdlib.h>
36#include <stdio.h>
44
3745#include "include/atomic_support.h"
3846#include "include/sso_allocator.h"
3947#include "__undef_macros"
......@@ -81,33 +89,11 @@ struct release
8189 void operator()(locale::facet* p) {p->__release_shared();}
8290};
8391
84template <class T, class A0>
85inline
86T&
87make(A0 a0)
92template <class T, class ...Args>
93T& make(Args ...args)
8894{
8995 static typename aligned_storage<sizeof(T)>::type buf;
90 auto *obj = ::new (&buf) T(a0);
91 return *obj;
92}
93
94template <class T, class A0, class A1>
95inline
96T&
97make(A0 a0, A1 a1)
98{
99 static typename aligned_storage<sizeof(T)>::type buf;
100 ::new (&buf) T(a0, a1);
101 return *reinterpret_cast<T*>(&buf);
102}
103
104template <class T, class A0, class A1, class A2>
105inline
106T&
107make(A0 a0, A1 a1, A2 a2)
108{
109 static typename aligned_storage<sizeof(T)>::type buf;
110 auto *obj = ::new (&buf) T(a0, a1, a2);
96 auto *obj = ::new (&buf) T(args...);
11197 return *obj;
11298}
11399
......@@ -197,11 +183,17 @@ locale::__imp::__imp(size_t refs)
197183{
198184 facets_.clear();
199185 install(&make<_VSTD::collate<char> >(1u));
186#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
200187 install(&make<_VSTD::collate<wchar_t> >(1u));
188#endif
201189 install(&make<_VSTD::ctype<char> >(nullptr, false, 1u));
190#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
202191 install(&make<_VSTD::ctype<wchar_t> >(1u));
192#endif
203193 install(&make<codecvt<char, char, mbstate_t> >(1u));
194#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
204195 install(&make<codecvt<wchar_t, char, mbstate_t> >(1u));
196#endif
205197_LIBCPP_SUPPRESS_DEPRECATED_PUSH
206198 install(&make<codecvt<char16_t, char, mbstate_t> >(1u));
207199 install(&make<codecvt<char32_t, char, mbstate_t> >(1u));
......@@ -211,25 +203,43 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
211203 install(&make<codecvt<char32_t, char8_t, mbstate_t> >(1u));
212204#endif
213205 install(&make<numpunct<char> >(1u));
206#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
214207 install(&make<numpunct<wchar_t> >(1u));
208#endif
215209 install(&make<num_get<char> >(1u));
210#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
216211 install(&make<num_get<wchar_t> >(1u));
212#endif
217213 install(&make<num_put<char> >(1u));
214#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
218215 install(&make<num_put<wchar_t> >(1u));
216#endif
219217 install(&make<moneypunct<char, false> >(1u));
220218 install(&make<moneypunct<char, true> >(1u));
219#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
221220 install(&make<moneypunct<wchar_t, false> >(1u));
222221 install(&make<moneypunct<wchar_t, true> >(1u));
222#endif
223223 install(&make<money_get<char> >(1u));
224#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
224225 install(&make<money_get<wchar_t> >(1u));
226#endif
225227 install(&make<money_put<char> >(1u));
228#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
226229 install(&make<money_put<wchar_t> >(1u));
230#endif
227231 install(&make<time_get<char> >(1u));
232#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
228233 install(&make<time_get<wchar_t> >(1u));
234#endif
229235 install(&make<time_put<char> >(1u));
236#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
230237 install(&make<time_put<wchar_t> >(1u));
238#endif
231239 install(&make<_VSTD::messages<char> >(1u));
240#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
232241 install(&make<_VSTD::messages<wchar_t> >(1u));
242#endif
233243}
234244
235245locale::__imp::__imp(const string& name, size_t refs)
......@@ -246,11 +256,17 @@ locale::__imp::__imp(const string& name, size_t refs)
246256 if (facets_[i])
247257 facets_[i]->__add_shared();
248258 install(new collate_byname<char>(name_));
259#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
249260 install(new collate_byname<wchar_t>(name_));
261#endif
250262 install(new ctype_byname<char>(name_));
263#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
251264 install(new ctype_byname<wchar_t>(name_));
265#endif
252266 install(new codecvt_byname<char, char, mbstate_t>(name_));
267#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
253268 install(new codecvt_byname<wchar_t, char, mbstate_t>(name_));
269#endif
254270_LIBCPP_SUPPRESS_DEPRECATED_PUSH
255271 install(new codecvt_byname<char16_t, char, mbstate_t>(name_));
256272 install(new codecvt_byname<char32_t, char, mbstate_t>(name_));
......@@ -260,17 +276,27 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
260276 install(new codecvt_byname<char32_t, char8_t, mbstate_t>(name_));
261277#endif
262278 install(new numpunct_byname<char>(name_));
279#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
263280 install(new numpunct_byname<wchar_t>(name_));
281#endif
264282 install(new moneypunct_byname<char, false>(name_));
265283 install(new moneypunct_byname<char, true>(name_));
284#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
266285 install(new moneypunct_byname<wchar_t, false>(name_));
267286 install(new moneypunct_byname<wchar_t, true>(name_));
287#endif
268288 install(new time_get_byname<char>(name_));
289#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
269290 install(new time_get_byname<wchar_t>(name_));
291#endif
270292 install(new time_put_byname<char>(name_));
293#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
271294 install(new time_put_byname<wchar_t>(name_));
295#endif
272296 install(new messages_byname<char>(name_));
297#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
273298 install(new messages_byname<wchar_t>(name_));
299#endif
274300#ifndef _LIBCPP_NO_EXCEPTIONS
275301 }
276302 catch (...)
......@@ -283,13 +309,6 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
283309#endif // _LIBCPP_NO_EXCEPTIONS
284310}
285311
286// NOTE avoid the `base class should be explicitly initialized in the
287// copy constructor` warning emitted by GCC
288#if defined(__clang__) || _GNUC_VER >= 406
289#pragma GCC diagnostic push
290#pragma GCC diagnostic ignored "-Wextra"
291#endif
292
293312locale::__imp::__imp(const __imp& other)
294313 : facets_(max<size_t>(N, other.facets_.size())),
295314 name_(other.name_)
......@@ -300,10 +319,6 @@ locale::__imp::__imp(const __imp& other)
300319 facets_[i]->__add_shared();
301320}
302321
303#if defined(__clang__) || _GNUC_VER >= 406
304#pragma GCC diagnostic pop
305#endif
306
307322locale::__imp::__imp(const __imp& other, const string& name, locale::category c)
308323 : facets_(N),
309324 name_("*")
......@@ -319,14 +334,20 @@ locale::__imp::__imp(const __imp& other, const string& name, locale::category c)
319334 if (c & locale::collate)
320335 {
321336 install(new collate_byname<char>(name));
337#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
322338 install(new collate_byname<wchar_t>(name));
339#endif
323340 }
324341 if (c & locale::ctype)
325342 {
326343 install(new ctype_byname<char>(name));
344#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
327345 install(new ctype_byname<wchar_t>(name));
346#endif
328347 install(new codecvt_byname<char, char, mbstate_t>(name));
348#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
329349 install(new codecvt_byname<wchar_t, char, mbstate_t>(name));
350#endif
330351_LIBCPP_SUPPRESS_DEPRECATED_PUSH
331352 install(new codecvt_byname<char16_t, char, mbstate_t>(name));
332353 install(new codecvt_byname<char32_t, char, mbstate_t>(name));
......@@ -340,25 +361,35 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
340361 {
341362 install(new moneypunct_byname<char, false>(name));
342363 install(new moneypunct_byname<char, true>(name));
364#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
343365 install(new moneypunct_byname<wchar_t, false>(name));
344366 install(new moneypunct_byname<wchar_t, true>(name));
367#endif
345368 }
346369 if (c & locale::numeric)
347370 {
348371 install(new numpunct_byname<char>(name));
372#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
349373 install(new numpunct_byname<wchar_t>(name));
374#endif
350375 }
351376 if (c & locale::time)
352377 {
353378 install(new time_get_byname<char>(name));
379#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
354380 install(new time_get_byname<wchar_t>(name));
381#endif
355382 install(new time_put_byname<char>(name));
383#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
356384 install(new time_put_byname<wchar_t>(name));
385#endif
357386 }
358387 if (c & locale::messages)
359388 {
360389 install(new messages_byname<char>(name));
390#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
361391 install(new messages_byname<wchar_t>(name));
392#endif
362393 }
363394#ifndef _LIBCPP_NO_EXCEPTIONS
364395 }
......@@ -396,12 +427,16 @@ locale::__imp::__imp(const __imp& other, const __imp& one, locale::category c)
396427 if (c & locale::collate)
397428 {
398429 install_from<_VSTD::collate<char> >(one);
430#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
399431 install_from<_VSTD::collate<wchar_t> >(one);
432#endif
400433 }
401434 if (c & locale::ctype)
402435 {
403436 install_from<_VSTD::ctype<char> >(one);
437#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
404438 install_from<_VSTD::ctype<wchar_t> >(one);
439#endif
405440 install_from<_VSTD::codecvt<char, char, mbstate_t> >(one);
406441_LIBCPP_SUPPRESS_DEPRECATED_PUSH
407442 install_from<_VSTD::codecvt<char16_t, char, mbstate_t> >(one);
......@@ -411,39 +446,59 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
411446 install_from<_VSTD::codecvt<char16_t, char8_t, mbstate_t> >(one);
412447 install_from<_VSTD::codecvt<char32_t, char8_t, mbstate_t> >(one);
413448#endif
449#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
414450 install_from<_VSTD::codecvt<wchar_t, char, mbstate_t> >(one);
451#endif
415452 }
416453 if (c & locale::monetary)
417454 {
418455 install_from<moneypunct<char, false> >(one);
419456 install_from<moneypunct<char, true> >(one);
457#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
420458 install_from<moneypunct<wchar_t, false> >(one);
421459 install_from<moneypunct<wchar_t, true> >(one);
460#endif
422461 install_from<money_get<char> >(one);
462#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
423463 install_from<money_get<wchar_t> >(one);
464#endif
424465 install_from<money_put<char> >(one);
466#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
425467 install_from<money_put<wchar_t> >(one);
468#endif
426469 }
427470 if (c & locale::numeric)
428471 {
429472 install_from<numpunct<char> >(one);
473#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
430474 install_from<numpunct<wchar_t> >(one);
475#endif
431476 install_from<num_get<char> >(one);
477#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
432478 install_from<num_get<wchar_t> >(one);
479#endif
433480 install_from<num_put<char> >(one);
481#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
434482 install_from<num_put<wchar_t> >(one);
483#endif
435484 }
436485 if (c & locale::time)
437486 {
438487 install_from<time_get<char> >(one);
488#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
439489 install_from<time_get<wchar_t> >(one);
490#endif
440491 install_from<time_put<char> >(one);
492#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
441493 install_from<time_put<wchar_t> >(one);
494#endif
442495 }
443496 if (c & locale::messages)
444497 {
445498 install_from<_VSTD::messages<char> >(one);
499#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
446500 install_from<_VSTD::messages<wchar_t> >(one);
501#endif
447502 }
448503#ifndef _LIBCPP_NO_EXCEPTIONS
449504 }
......@@ -734,6 +789,7 @@ collate_byname<char>::do_transform(const char_type* lo, const char_type* hi) con
734789
735790// template <> class collate_byname<wchar_t>
736791
792#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
737793collate_byname<wchar_t>::collate_byname(const char* n, size_t refs)
738794 : collate<wchar_t>(refs),
739795 __l(newlocale(LC_ALL_MASK, n, 0))
......@@ -779,8 +835,7 @@ collate_byname<wchar_t>::do_transform(const char_type* lo, const char_type* hi)
779835 wcsxfrm_l(const_cast<wchar_t*>(out.c_str()), in.c_str(), out.size()+1, __l);
780836 return out;
781837}
782
783// template <> class ctype<wchar_t>;
838#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
784839
785840const ctype_base::mask ctype_base::space;
786841const ctype_base::mask ctype_base::print;
......@@ -795,6 +850,9 @@ const ctype_base::mask ctype_base::blank;
795850const ctype_base::mask ctype_base::alnum;
796851const ctype_base::mask ctype_base::graph;
797852
853// template <> class ctype<wchar_t>;
854
855#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
798856locale::id ctype<wchar_t>::id;
799857
800858ctype<wchar_t>::~ctype()
......@@ -840,7 +898,7 @@ ctype<wchar_t>::do_toupper(char_type c) const
840898#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
841899 return isascii(c) ? _DefaultRuneLocale.__mapupper[c] : c;
842900#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || \
843 defined(__NetBSD__)
901 defined(__NetBSD__) || defined(__MVS__)
844902 return isascii(c) ? ctype<char>::__classic_upper_table()[c] : c;
845903#else
846904 return (isascii(c) && iswlower_l(c, _LIBCPP_GET_C_LOCALE)) ? c-L'a'+L'A' : c;
......@@ -854,7 +912,7 @@ ctype<wchar_t>::do_toupper(char_type* low, const char_type* high) const
854912#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
855913 *low = isascii(*low) ? _DefaultRuneLocale.__mapupper[*low] : *low;
856914#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || \
857 defined(__NetBSD__)
915 defined(__NetBSD__) || defined(__MVS__)
858916 *low = isascii(*low) ? ctype<char>::__classic_upper_table()[*low]
859917 : *low;
860918#else
......@@ -869,7 +927,7 @@ ctype<wchar_t>::do_tolower(char_type c) const
869927#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
870928 return isascii(c) ? _DefaultRuneLocale.__maplower[c] : c;
871929#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || \
872 defined(__NetBSD__)
930 defined(__NetBSD__) || defined(__MVS__)
873931 return isascii(c) ? ctype<char>::__classic_lower_table()[c] : c;
874932#else
875933 return (isascii(c) && isupper_l(c, _LIBCPP_GET_C_LOCALE)) ? c-L'A'+'a' : c;
......@@ -883,7 +941,7 @@ ctype<wchar_t>::do_tolower(char_type* low, const char_type* high) const
883941#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
884942 *low = isascii(*low) ? _DefaultRuneLocale.__maplower[*low] : *low;
885943#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || \
886 defined(__NetBSD__)
944 defined(__NetBSD__) || defined(__MVS__)
887945 *low = isascii(*low) ? ctype<char>::__classic_lower_table()[*low]
888946 : *low;
889947#else
......@@ -924,11 +982,14 @@ ctype<wchar_t>::do_narrow(const char_type* low, const char_type* high, char dfau
924982 *dest = dfault;
925983 return low;
926984}
985#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
927986
928987// template <> class ctype<char>;
929988
930989locale::id ctype<char>::id;
931990
991const size_t ctype<char>::table_size;
992
932993ctype<char>::ctype(const mask* tab, bool del, size_t refs)
933994 : locale::facet(refs),
934995 __tab_(tab),
......@@ -952,7 +1013,7 @@ ctype<char>::do_toupper(char_type c) const
9521013 static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(c)]) : c;
9531014#elif defined(__NetBSD__)
9541015 return static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(c)]);
955#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__)
1016#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__MVS__)
9561017 return isascii(c) ?
9571018 static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(c)]) : c;
9581019#else
......@@ -969,7 +1030,7 @@ ctype<char>::do_toupper(char_type* low, const char_type* high) const
9691030 static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(*low)]) : *low;
9701031#elif defined(__NetBSD__)
9711032 *low = static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(*low)]);
972#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__)
1033#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__MVS__)
9731034 *low = isascii(*low) ?
9741035 static_cast<char>(__classic_upper_table()[static_cast<size_t>(*low)]) : *low;
9751036#else
......@@ -986,7 +1047,7 @@ ctype<char>::do_tolower(char_type c) const
9861047 static_cast<char>(_DefaultRuneLocale.__maplower[static_cast<ptrdiff_t>(c)]) : c;
9871048#elif defined(__NetBSD__)
9881049 return static_cast<char>(__classic_lower_table()[static_cast<unsigned char>(c)]);
989#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__)
1050#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__MVS__)
9901051 return isascii(c) ?
9911052 static_cast<char>(__classic_lower_table()[static_cast<size_t>(c)]) : c;
9921053#else
......@@ -1002,7 +1063,7 @@ ctype<char>::do_tolower(char_type* low, const char_type* high) const
10021063 *low = isascii(*low) ? static_cast<char>(_DefaultRuneLocale.__maplower[static_cast<ptrdiff_t>(*low)]) : *low;
10031064#elif defined(__NetBSD__)
10041065 *low = static_cast<char>(__classic_lower_table()[static_cast<unsigned char>(*low)]);
1005#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__)
1066#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__MVS__)
10061067 *low = isascii(*low) ? static_cast<char>(__classic_lower_table()[static_cast<size_t>(*low)]) : *low;
10071068#else
10081069 *low = (isascii(*low) && isupper_l(*low, _LIBCPP_GET_C_LOCALE)) ? *low-'A'+'a' : *low;
......@@ -1133,7 +1194,7 @@ ctype<char>::classic_table() noexcept
11331194const ctype<char>::mask*
11341195ctype<char>::classic_table() noexcept
11351196{
1136#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__)
1197#if defined(__APPLE__) || defined(__FreeBSD__)
11371198 return _DefaultRuneLocale.__runetype;
11381199#elif defined(__NetBSD__)
11391200 return _C_ctype_tab_ + 1;
......@@ -1150,6 +1211,12 @@ ctype<char>::classic_table() noexcept
11501211 return _ctype_ + 1;
11511212#elif defined(_AIX)
11521213 return (const unsigned int *)__lc_ctype_ptr->obj->mask;
1214#elif defined(__MVS__)
1215# if defined(__NATIVE_ASCII_F)
1216 return const_cast<const ctype<char>::mask*> (__OBJ_DATA(__lc_ctype_a)->mask);
1217# else
1218 return const_cast<const ctype<char>::mask*> (__ctypec);
1219# endif
11531220#else
11541221 // Platform not supported: abort so the person doing the port knows what to
11551222 // fix
......@@ -1198,7 +1265,26 @@ ctype<char>::__classic_upper_table() noexcept
11981265{
11991266 return *__ctype_toupper_loc();
12001267}
1201#endif // __GLIBC__ || __NETBSD__ || __EMSCRIPTEN__
1268#elif defined(__MVS__)
1269const unsigned short*
1270ctype<char>::__classic_lower_table() _NOEXCEPT
1271{
1272# if defined(__NATIVE_ASCII_F)
1273 return const_cast<const unsigned short*>(__OBJ_DATA(__lc_ctype_a)->lower);
1274# else
1275 return const_cast<const unsigned short*>(__ctype + __TOLOWER_INDEX);
1276# endif
1277}
1278const unsigned short *
1279ctype<char>::__classic_upper_table() _NOEXCEPT
1280{
1281# if defined(__NATIVE_ASCII_F)
1282 return const_cast<const unsigned short*>(__OBJ_DATA(__lc_ctype_a)->upper);
1283# else
1284 return const_cast<const unsigned short*>(__ctype + __TOUPPER_INDEX);
1285# endif
1286}
1287#endif // __GLIBC__ || __NETBSD__ || __EMSCRIPTEN__ || __MVS__
12021288
12031289// template <> class ctype_byname<char>
12041290
......@@ -1255,6 +1341,7 @@ ctype_byname<char>::do_tolower(char_type* low, const char_type* high) const
12551341
12561342// template <> class ctype_byname<wchar_t>
12571343
1344#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
12581345ctype_byname<wchar_t>::ctype_byname(const char* name, size_t refs)
12591346 : ctype<wchar_t>(refs),
12601347 __l(newlocale(LC_ALL_MASK, name, 0))
......@@ -1454,6 +1541,7 @@ ctype_byname<wchar_t>::do_narrow(const char_type* low, const char_type* high, ch
14541541 }
14551542 return low;
14561543}
1544#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
14571545
14581546// template <> class codecvt<char, char, mbstate_t>
14591547
......@@ -1518,6 +1606,7 @@ codecvt<char, char, mbstate_t>::do_max_length() const noexcept
15181606
15191607// template <> class codecvt<wchar_t, char, mbstate_t>
15201608
1609#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
15211610locale::id codecvt<wchar_t, char, mbstate_t>::id;
15221611
15231612codecvt<wchar_t, char, mbstate_t>::codecvt(size_t refs)
......@@ -1730,6 +1819,7 @@ codecvt<wchar_t, char, mbstate_t>::do_max_length() const noexcept
17301819{
17311820 return __l == 0 ? 1 : static_cast<int>(__libcpp_mb_cur_max_l(__l));
17321821}
1822#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
17331823
17341824// Valid UTF ranges
17351825// UTF-32 UTF-16 UTF-8 # of code points
......@@ -3436,6 +3526,7 @@ codecvt<char32_t, char8_t, mbstate_t>::do_max_length() const noexcept
34363526
34373527// __codecvt_utf8<wchar_t>
34383528
3529#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
34393530__codecvt_utf8<wchar_t>::result
34403531__codecvt_utf8<wchar_t>::do_out(state_type&,
34413532 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
......@@ -3517,16 +3608,27 @@ __codecvt_utf8<wchar_t>::do_length(state_type&,
35173608{
35183609 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
35193610 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3611#if defined(_LIBCPP_SHORT_WCHAR)
3612 return utf8_to_ucs2_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3613#else
35203614 return utf8_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3615#endif
35213616}
35223617
35233618int
35243619__codecvt_utf8<wchar_t>::do_max_length() const noexcept
35253620{
3621#if defined(_LIBCPP_SHORT_WCHAR)
3622 if (_Mode_ & consume_header)
3623 return 6;
3624 return 3;
3625#else
35263626 if (_Mode_ & consume_header)
35273627 return 7;
35283628 return 4;
3629#endif
35293630}
3631#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
35303632
35313633// __codecvt_utf8<char16_t>
35323634
......@@ -3680,19 +3782,31 @@ __codecvt_utf8<char32_t>::do_max_length() const noexcept
36803782
36813783// __codecvt_utf16<wchar_t, false>
36823784
3785#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
36833786__codecvt_utf16<wchar_t, false>::result
36843787__codecvt_utf16<wchar_t, false>::do_out(state_type&,
36853788 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
36863789 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
36873790{
3791#if defined(_LIBCPP_SHORT_WCHAR)
3792 const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
3793 const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
3794 const uint16_t* _frm_nxt = _frm;
3795#else
36883796 const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
36893797 const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
36903798 const uint32_t* _frm_nxt = _frm;
3799#endif
36913800 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
36923801 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
36933802 uint8_t* _to_nxt = _to;
3803#if defined(_LIBCPP_SHORT_WCHAR)
3804 result r = ucs2_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3805 _Maxcode_, _Mode_);
3806#else
36943807 result r = ucs4_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
36953808 _Maxcode_, _Mode_);
3809#endif
36963810 frm_nxt = frm + (_frm_nxt - _frm);
36973811 to_nxt = to + (_to_nxt - _to);
36983812 return r;
......@@ -3706,11 +3820,19 @@ __codecvt_utf16<wchar_t, false>::do_in(state_type&,
37063820 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
37073821 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
37083822 const uint8_t* _frm_nxt = _frm;
3823#if defined(_LIBCPP_SHORT_WCHAR)
3824 uint16_t* _to = reinterpret_cast<uint16_t*>(to);
3825 uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
3826 uint16_t* _to_nxt = _to;
3827 result r = utf16be_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3828 _Maxcode_, _Mode_);
3829#else
37093830 uint32_t* _to = reinterpret_cast<uint32_t*>(to);
37103831 uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
37113832 uint32_t* _to_nxt = _to;
37123833 result r = utf16be_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
37133834 _Maxcode_, _Mode_);
3835#endif
37143836 frm_nxt = frm + (_frm_nxt - _frm);
37153837 to_nxt = to + (_to_nxt - _to);
37163838 return r;
......@@ -3742,15 +3864,25 @@ __codecvt_utf16<wchar_t, false>::do_length(state_type&,
37423864{
37433865 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
37443866 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3867#if defined(_LIBCPP_SHORT_WCHAR)
3868 return utf16be_to_ucs2_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3869#else
37453870 return utf16be_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3871#endif
37463872}
37473873
37483874int
37493875__codecvt_utf16<wchar_t, false>::do_max_length() const noexcept
37503876{
3877#if defined(_LIBCPP_SHORT_WCHAR)
3878 if (_Mode_ & consume_header)
3879 return 4;
3880 return 2;
3881#else
37513882 if (_Mode_ & consume_header)
37523883 return 6;
37533884 return 4;
3885#endif
37543886}
37553887
37563888// __codecvt_utf16<wchar_t, true>
......@@ -3760,14 +3892,25 @@ __codecvt_utf16<wchar_t, true>::do_out(state_type&,
37603892 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
37613893 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
37623894{
3895#if defined(_LIBCPP_SHORT_WCHAR)
3896 const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
3897 const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
3898 const uint16_t* _frm_nxt = _frm;
3899#else
37633900 const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
37643901 const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
37653902 const uint32_t* _frm_nxt = _frm;
3903#endif
37663904 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
37673905 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
37683906 uint8_t* _to_nxt = _to;
3907#if defined(_LIBCPP_SHORT_WCHAR)
3908 result r = ucs2_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3909 _Maxcode_, _Mode_);
3910#else
37693911 result r = ucs4_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
37703912 _Maxcode_, _Mode_);
3913#endif
37713914 frm_nxt = frm + (_frm_nxt - _frm);
37723915 to_nxt = to + (_to_nxt - _to);
37733916 return r;
......@@ -3781,11 +3924,19 @@ __codecvt_utf16<wchar_t, true>::do_in(state_type&,
37813924 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
37823925 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
37833926 const uint8_t* _frm_nxt = _frm;
3927#if defined(_LIBCPP_SHORT_WCHAR)
3928 uint16_t* _to = reinterpret_cast<uint16_t*>(to);
3929 uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
3930 uint16_t* _to_nxt = _to;
3931 result r = utf16le_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3932 _Maxcode_, _Mode_);
3933#else
37843934 uint32_t* _to = reinterpret_cast<uint32_t*>(to);
37853935 uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
37863936 uint32_t* _to_nxt = _to;
37873937 result r = utf16le_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
37883938 _Maxcode_, _Mode_);
3939#endif
37893940 frm_nxt = frm + (_frm_nxt - _frm);
37903941 to_nxt = to + (_to_nxt - _to);
37913942 return r;
......@@ -3817,16 +3968,27 @@ __codecvt_utf16<wchar_t, true>::do_length(state_type&,
38173968{
38183969 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
38193970 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3971#if defined(_LIBCPP_SHORT_WCHAR)
3972 return utf16le_to_ucs2_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3973#else
38203974 return utf16le_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3975#endif
38213976}
38223977
38233978int
38243979__codecvt_utf16<wchar_t, true>::do_max_length() const noexcept
38253980{
3981#if defined(_LIBCPP_SHORT_WCHAR)
3982 if (_Mode_ & consume_header)
3983 return 4;
3984 return 2;
3985#else
38263986 if (_Mode_ & consume_header)
38273987 return 6;
38283988 return 4;
3989#endif
38293990}
3991#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
38303992
38313993// __codecvt_utf16<char16_t, false>
38323994
......@@ -4130,14 +4292,21 @@ __codecvt_utf16<char32_t, true>::do_max_length() const noexcept
41304292
41314293// __codecvt_utf8_utf16<wchar_t>
41324294
4295#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
41334296__codecvt_utf8_utf16<wchar_t>::result
41344297__codecvt_utf8_utf16<wchar_t>::do_out(state_type&,
41354298 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
41364299 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
41374300{
4301#if defined(_LIBCPP_SHORT_WCHAR)
4302 const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
4303 const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
4304 const uint16_t* _frm_nxt = _frm;
4305#else
41384306 const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
41394307 const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
41404308 const uint32_t* _frm_nxt = _frm;
4309#endif
41414310 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
41424311 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
41434312 uint8_t* _to_nxt = _to;
......@@ -4156,9 +4325,15 @@ __codecvt_utf8_utf16<wchar_t>::do_in(state_type&,
41564325 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
41574326 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
41584327 const uint8_t* _frm_nxt = _frm;
4328#if defined(_LIBCPP_SHORT_WCHAR)
4329 uint16_t* _to = reinterpret_cast<uint16_t*>(to);
4330 uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
4331 uint16_t* _to_nxt = _to;
4332#else
41594333 uint32_t* _to = reinterpret_cast<uint32_t*>(to);
41604334 uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
41614335 uint32_t* _to_nxt = _to;
4336#endif
41624337 result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
41634338 _Maxcode_, _Mode_);
41644339 frm_nxt = frm + (_frm_nxt - _frm);
......@@ -4202,6 +4377,7 @@ __codecvt_utf8_utf16<wchar_t>::do_max_length() const noexcept
42024377 return 7;
42034378 return 4;
42044379}
4380#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
42054381
42064382// __codecvt_utf8_utf16<char16_t>
42074383
......@@ -4377,7 +4553,7 @@ __widen_from_utf8<32>::~__widen_from_utf8()
43774553{
43784554}
43794555
4380
4556#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
43814557static bool checked_string_to_wchar_convert(wchar_t& dest,
43824558 const char* ptr,
43834559 locale_t loc) {
......@@ -4392,6 +4568,19 @@ static bool checked_string_to_wchar_convert(wchar_t& dest,
43924568 dest = out;
43934569 return true;
43944570}
4571#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
4572
4573#ifdef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4574static bool is_narrow_non_breaking_space(const char* ptr) {
4575 // https://www.fileformat.info/info/unicode/char/202f/index.htm
4576 return ptr[0] == '\xe2' && ptr[1] == '\x80' && ptr[2] == '\xaf';
4577}
4578
4579static bool is_non_breaking_space(const char* ptr) {
4580 // https://www.fileformat.info/info/unicode/char/0a/index.htm
4581 return ptr[0] == '\xc2' && ptr[1] == '\xa0';
4582}
4583#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
43954584
43964585static bool checked_string_to_char_convert(char& dest,
43974586 const char* ptr,
......@@ -4402,6 +4591,8 @@ static bool checked_string_to_char_convert(char& dest,
44024591 dest = *ptr;
44034592 return true;
44044593 }
4594
4595#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
44054596 // First convert the MBS into a wide char then attempt to narrow it using
44064597 // wctob_l.
44074598 wchar_t wout;
......@@ -4412,7 +4603,7 @@ static bool checked_string_to_char_convert(char& dest,
44124603 dest = res;
44134604 return true;
44144605 }
4415 // FIXME: Work around specific multibyte sequences that we can reasonable
4606 // FIXME: Work around specific multibyte sequences that we can reasonably
44164607 // translate into a different single byte.
44174608 switch (wout) {
44184609 case L'\u202F': // narrow non-breaking space
......@@ -4422,6 +4613,16 @@ static bool checked_string_to_char_convert(char& dest,
44224613 default:
44234614 return false;
44244615 }
4616#else // _LIBCPP_HAS_NO_WIDE_CHARACTERS
4617 // FIXME: Work around specific multibyte sequences that we can reasonably
4618 // translate into a different single byte.
4619 if (is_narrow_non_breaking_space(ptr) || is_non_breaking_space(ptr)) {
4620 dest = ' ';
4621 return true;
4622 }
4623
4624 return false;
4625#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
44254626 _LIBCPP_UNREACHABLE();
44264627}
44274628
......@@ -4429,7 +4630,9 @@ static bool checked_string_to_char_convert(char& dest,
44294630// numpunct<char> && numpunct<wchar_t>
44304631
44314632locale::id numpunct< char >::id;
4633#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
44324634locale::id numpunct<wchar_t>::id;
4635#endif
44334636
44344637numpunct<char>::numpunct(size_t refs)
44354638 : locale::facet(refs),
......@@ -4438,35 +4641,49 @@ numpunct<char>::numpunct(size_t refs)
44384641{
44394642}
44404643
4644#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
44414645numpunct<wchar_t>::numpunct(size_t refs)
44424646 : locale::facet(refs),
44434647 __decimal_point_(L'.'),
44444648 __thousands_sep_(L',')
44454649{
44464650}
4651#endif
44474652
44484653numpunct<char>::~numpunct()
44494654{
44504655}
44514656
4657#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
44524658numpunct<wchar_t>::~numpunct()
44534659{
44544660}
4661#endif
44554662
44564663 char numpunct< char >::do_decimal_point() const {return __decimal_point_;}
4664#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
44574665wchar_t numpunct<wchar_t>::do_decimal_point() const {return __decimal_point_;}
4666#endif
44584667
44594668 char numpunct< char >::do_thousands_sep() const {return __thousands_sep_;}
4669#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
44604670wchar_t numpunct<wchar_t>::do_thousands_sep() const {return __thousands_sep_;}
4671#endif
44614672
44624673string numpunct< char >::do_grouping() const {return __grouping_;}
4674#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
44634675string numpunct<wchar_t>::do_grouping() const {return __grouping_;}
4676#endif
44644677
44654678 string numpunct< char >::do_truename() const {return "true";}
4679#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
44664680wstring numpunct<wchar_t>::do_truename() const {return L"true";}
4681#endif
44674682
44684683 string numpunct< char >::do_falsename() const {return "false";}
4684#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
44694685wstring numpunct<wchar_t>::do_falsename() const {return L"false";}
4686#endif
44704687
44714688// numpunct_byname<char>
44724689
......@@ -4489,6 +4706,7 @@ numpunct_byname<char>::~numpunct_byname()
44894706void
44904707numpunct_byname<char>::__init(const char* nm)
44914708{
4709 typedef numpunct<char> base;
44924710 if (strcmp(nm, "C") != 0)
44934711 {
44944712 __libcpp_unique_locale loc(nm);
......@@ -4497,10 +4715,12 @@ numpunct_byname<char>::__init(const char* nm)
44974715 " failed to construct for " + string(nm));
44984716
44994717 lconv* lc = __libcpp_localeconv_l(loc.get());
4500 checked_string_to_char_convert(__decimal_point_, lc->decimal_point,
4501 loc.get());
4502 checked_string_to_char_convert(__thousands_sep_, lc->thousands_sep,
4503 loc.get());
4718 if (!checked_string_to_char_convert(__decimal_point_, lc->decimal_point,
4719 loc.get()))
4720 __decimal_point_ = base::do_decimal_point();
4721 if (!checked_string_to_char_convert(__thousands_sep_, lc->thousands_sep,
4722 loc.get()))
4723 __thousands_sep_ = base::do_thousands_sep();
45044724 __grouping_ = lc->grouping;
45054725 // localization for truename and falsename is not available
45064726 }
......@@ -4508,6 +4728,7 @@ numpunct_byname<char>::__init(const char* nm)
45084728
45094729// numpunct_byname<wchar_t>
45104730
4731#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
45114732numpunct_byname<wchar_t>::numpunct_byname(const char* nm, size_t refs)
45124733 : numpunct<wchar_t>(refs)
45134734{
......@@ -4543,6 +4764,7 @@ numpunct_byname<wchar_t>::__init(const char* nm)
45434764 // localization for truename and falsename is not available
45444765 }
45454766}
4767#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
45464768
45474769// num_get helpers
45484770
......@@ -4718,6 +4940,7 @@ init_weeks()
47184940 return weeks;
47194941}
47204942
4943#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
47214944static
47224945wstring*
47234946init_wweeks()
......@@ -4739,6 +4962,7 @@ init_wweeks()
47394962 weeks[13] = L"Sat";
47404963 return weeks;
47414964}
4965#endif
47424966
47434967template <>
47444968const string*
......@@ -4748,6 +4972,7 @@ __time_get_c_storage<char>::__weeks() const
47484972 return weeks;
47494973}
47504974
4975#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
47514976template <>
47524977const wstring*
47534978__time_get_c_storage<wchar_t>::__weeks() const
......@@ -4755,6 +4980,7 @@ __time_get_c_storage<wchar_t>::__weeks() const
47554980 static const wstring* weeks = init_wweeks();
47564981 return weeks;
47574982}
4983#endif
47584984
47594985static
47604986string*
......@@ -4788,6 +5014,7 @@ init_months()
47885014 return months;
47895015}
47905016
5017#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
47915018static
47925019wstring*
47935020init_wmonths()
......@@ -4819,6 +5046,7 @@ init_wmonths()
48195046 months[23] = L"Dec";
48205047 return months;
48215048}
5049#endif
48225050
48235051template <>
48245052const string*
......@@ -4828,6 +5056,7 @@ __time_get_c_storage<char>::__months() const
48285056 return months;
48295057}
48305058
5059#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
48315060template <>
48325061const wstring*
48335062__time_get_c_storage<wchar_t>::__months() const
......@@ -4835,6 +5064,7 @@ __time_get_c_storage<wchar_t>::__months() const
48355064 static const wstring* months = init_wmonths();
48365065 return months;
48375066}
5067#endif
48385068
48395069static
48405070string*
......@@ -4846,6 +5076,7 @@ init_am_pm()
48465076 return am_pm;
48475077}
48485078
5079#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
48495080static
48505081wstring*
48515082init_wam_pm()
......@@ -4855,6 +5086,7 @@ init_wam_pm()
48555086 am_pm[1] = L"PM";
48565087 return am_pm;
48575088}
5089#endif
48585090
48595091template <>
48605092const string*
......@@ -4864,6 +5096,7 @@ __time_get_c_storage<char>::__am_pm() const
48645096 return am_pm;
48655097}
48665098
5099#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
48675100template <>
48685101const wstring*
48695102__time_get_c_storage<wchar_t>::__am_pm() const
......@@ -4871,6 +5104,7 @@ __time_get_c_storage<wchar_t>::__am_pm() const
48715104 static const wstring* am_pm = init_wam_pm();
48725105 return am_pm;
48735106}
5107#endif
48745108
48755109template <>
48765110const string&
......@@ -4880,6 +5114,7 @@ __time_get_c_storage<char>::__x() const
48805114 return s;
48815115}
48825116
5117#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
48835118template <>
48845119const wstring&
48855120__time_get_c_storage<wchar_t>::__x() const
......@@ -4887,6 +5122,7 @@ __time_get_c_storage<wchar_t>::__x() const
48875122 static wstring s(L"%m/%d/%y");
48885123 return s;
48895124}
5125#endif
48905126
48915127template <>
48925128const string&
......@@ -4896,6 +5132,7 @@ __time_get_c_storage<char>::__X() const
48965132 return s;
48975133}
48985134
5135#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
48995136template <>
49005137const wstring&
49015138__time_get_c_storage<wchar_t>::__X() const
......@@ -4903,6 +5140,7 @@ __time_get_c_storage<wchar_t>::__X() const
49035140 static wstring s(L"%H:%M:%S");
49045141 return s;
49055142}
5143#endif
49065144
49075145template <>
49085146const string&
......@@ -4912,6 +5150,7 @@ __time_get_c_storage<char>::__c() const
49125150 return s;
49135151}
49145152
5153#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
49155154template <>
49165155const wstring&
49175156__time_get_c_storage<wchar_t>::__c() const
......@@ -4919,6 +5158,7 @@ __time_get_c_storage<wchar_t>::__c() const
49195158 static wstring s(L"%a %b %d %H:%M:%S %Y");
49205159 return s;
49215160}
5161#endif
49225162
49235163template <>
49245164const string&
......@@ -4928,6 +5168,7 @@ __time_get_c_storage<char>::__r() const
49285168 return s;
49295169}
49305170
5171#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
49315172template <>
49325173const wstring&
49335174__time_get_c_storage<wchar_t>::__r() const
......@@ -4935,6 +5176,7 @@ __time_get_c_storage<wchar_t>::__r() const
49355176 static wstring s(L"%I:%M:%S %p");
49365177 return s;
49375178}
5179#endif
49385180
49395181// time_get_byname
49405182
......@@ -5113,6 +5355,7 @@ __time_get_storage<char>::__analyze(char fmt, const ctype<char>& ct)
51135355#pragma clang diagnostic ignored "-Wmissing-braces"
51145356#endif
51155357
5358#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
51165359template <>
51175360wstring
51185361__time_get_storage<wchar_t>::__analyze(char fmt, const ctype<wchar_t>& ct)
......@@ -5262,6 +5505,7 @@ __time_get_storage<wchar_t>::__analyze(char fmt, const ctype<wchar_t>& ct)
52625505 }
52635506 return result;
52645507}
5508#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
52655509
52665510template <>
52675511void
......@@ -5300,6 +5544,7 @@ __time_get_storage<char>::init(const ctype<char>& ct)
53005544 __X_ = __analyze('X', ct);
53015545}
53025546
5547#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
53035548template <>
53045549void
53055550__time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct)
......@@ -5375,6 +5620,7 @@ __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct)
53755620 __x_ = __analyze('x', ct);
53765621 __X_ = __analyze('X', ct);
53775622}
5623#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
53785624
53795625template <class CharT>
53805626struct _LIBCPP_HIDDEN __time_get_temp
......@@ -5402,6 +5648,7 @@ __time_get_storage<char>::__time_get_storage(const string& __nm)
54025648 init(ct);
54035649}
54045650
5651#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
54055652template <>
54065653__time_get_storage<wchar_t>::__time_get_storage(const char* __nm)
54075654 : __time_get(__nm)
......@@ -5417,6 +5664,7 @@ __time_get_storage<wchar_t>::__time_get_storage(const string& __nm)
54175664 const __time_get_temp<wchar_t> ct(__nm);
54185665 init(ct);
54195666}
5667#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
54205668
54215669template <>
54225670time_base::dateorder
......@@ -5505,6 +5753,7 @@ __time_get_storage<char>::__do_date_order() const
55055753 return time_base::no_order;
55065754}
55075755
5756#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
55085757template <>
55095758time_base::dateorder
55105759__time_get_storage<wchar_t>::__do_date_order() const
......@@ -5591,6 +5840,7 @@ __time_get_storage<wchar_t>::__do_date_order() const
55915840 }
55925841 return time_base::no_order;
55935842}
5843#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
55945844
55955845// time_put
55965846
......@@ -5627,6 +5877,7 @@ __time_put::__do_put(char* __nb, char*& __ne, const tm* __tm,
56275877 __ne = __nb + n;
56285878}
56295879
5880#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
56305881void
56315882__time_put::__do_put(wchar_t* __wb, wchar_t*& __we, const tm* __tm,
56325883 char __fmt, char __mod) const
......@@ -5641,6 +5892,7 @@ __time_put::__do_put(wchar_t* __wb, wchar_t*& __we, const tm* __tm,
56415892 __throw_runtime_error("locale not supported");
56425893 __we = __wb + j;
56435894}
5895#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
56445896
56455897// moneypunct_byname
56465898
......@@ -6120,6 +6372,7 @@ moneypunct_byname<char, true>::init(const char* nm)
61206372#endif // !_LIBCPP_MSVCRT
61216373}
61226374
6375#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
61236376template<>
61246377void
61256378moneypunct_byname<wchar_t, false>::init(const char* nm)
......@@ -6267,6 +6520,7 @@ moneypunct_byname<wchar_t, true>::init(const char* nm)
62676520 lc->int_n_sign_posn, L' ');
62686521#endif // !_LIBCPP_MSVCRT
62696522}
6523#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
62706524
62716525void __do_nothing(void*) {}
62726526
......@@ -6280,63 +6534,63 @@ void __throw_runtime_error(const char* msg)
62806534#endif
62816535}
62826536
6283template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS collate<char>;
6284template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS collate<wchar_t>;
6537 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS collate<char>;
6538_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS collate<wchar_t>;)
62856539
6286template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS num_get<char>;
6287template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS num_get<wchar_t>;
6540 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS num_get<char>;
6541_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS num_get<wchar_t>;)
62886542
6289template struct _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __num_get<char>;
6290template struct _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __num_get<wchar_t>;
6543 template struct _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __num_get<char>;
6544_LIBCPP_IF_WIDE_CHARACTERS(template struct _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __num_get<wchar_t>;)
62916545
6292template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS num_put<char>;
6293template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS num_put<wchar_t>;
6546 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS num_put<char>;
6547_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS num_put<wchar_t>;)
62946548
6295template struct _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __num_put<char>;
6296template struct _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __num_put<wchar_t>;
6549 template struct _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __num_put<char>;
6550_LIBCPP_IF_WIDE_CHARACTERS(template struct _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __num_put<wchar_t>;)
62976551
6298template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_get<char>;
6299template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_get<wchar_t>;
6552 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_get<char>;
6553_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_get<wchar_t>;)
63006554
6301template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_get_byname<char>;
6302template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_get_byname<wchar_t>;
6555 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_get_byname<char>;
6556_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_get_byname<wchar_t>;)
63036557
6304template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_put<char>;
6305template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_put<wchar_t>;
6558 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_put<char>;
6559_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_put<wchar_t>;)
63066560
6307template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_put_byname<char>;
6308template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_put_byname<wchar_t>;
6561 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_put_byname<char>;
6562_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_put_byname<wchar_t>;)
63096563
6310template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct<char, false>;
6311template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct<char, true>;
6312template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct<wchar_t, false>;
6313template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct<wchar_t, true>;
6564 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct<char, false>;
6565 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct<char, true>;
6566_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct<wchar_t, false>;)
6567_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct<wchar_t, true>;)
63146568
6315template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct_byname<char, false>;
6316template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct_byname<char, true>;
6317template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct_byname<wchar_t, false>;
6318template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct_byname<wchar_t, true>;
6569 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct_byname<char, false>;
6570 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct_byname<char, true>;
6571_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct_byname<wchar_t, false>;)
6572_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct_byname<wchar_t, true>;)
63196573
6320template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS money_get<char>;
6321template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS money_get<wchar_t>;
6574 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS money_get<char>;
6575_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS money_get<wchar_t>;)
63226576
6323template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __money_get<char>;
6324template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __money_get<wchar_t>;
6577 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __money_get<char>;
6578_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __money_get<wchar_t>;)
63256579
6326template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS money_put<char>;
6327template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS money_put<wchar_t>;
6580 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS money_put<char>;
6581_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS money_put<wchar_t>;)
63286582
6329template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __money_put<char>;
6330template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __money_put<wchar_t>;
6583 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __money_put<char>;
6584_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __money_put<wchar_t>;)
63316585
6332template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS messages<char>;
6333template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS messages<wchar_t>;
6586 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS messages<char>;
6587_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS messages<wchar_t>;)
63346588
6335template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS messages_byname<char>;
6336template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS messages_byname<wchar_t>;
6589 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS messages_byname<char>;
6590_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS messages_byname<wchar_t>;)
63376591
6338template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS codecvt_byname<char, char, mbstate_t>;
6339template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS codecvt_byname<wchar_t, char, mbstate_t>;
6592 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS codecvt_byname<char, char, mbstate_t>;
6593_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS codecvt_byname<wchar_t, char, mbstate_t>;)
63406594template class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS codecvt_byname<char16_t, char, mbstate_t>;
63416595template class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS codecvt_byname<char32_t, char, mbstate_t>;
63426596#ifndef _LIBCPP_HAS_NO_CHAR8_T
lib/libcxx/src/memory.cpp+8-29
......@@ -1,4 +1,4 @@
1//===------------------------ memory.cpp ----------------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
......@@ -8,11 +8,11 @@
88
99#include "memory"
1010#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
11# include "mutex"
12# include "thread"
13# if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
14# pragma comment(lib, "pthread")
15# endif
1616#endif
1717#include "include/atomic_support.h"
1818
......@@ -130,7 +130,7 @@ __shared_weak_count::__get_deleter(const type_info&) const noexcept
130130 return nullptr;
131131}
132132
133#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
133#if !defined(_LIBCPP_HAS_NO_THREADS)
134134
135135_LIBCPP_SAFE_STATIC static const std::size_t __sp_mut_count = 16;
136136_LIBCPP_SAFE_STATIC static __libcpp_mutex_t mut_back[__sp_mut_count] =
......@@ -181,28 +181,7 @@ __get_sp_mut(const void* p)
181181 return muts[hash<const void*>()(p) & (__sp_mut_count-1)];
182182}
183183
184#endif // !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
185
186void
187declare_reachable(void*)
188{
189}
190
191void
192declare_no_pointers(char*, size_t)
193{
194}
195
196void
197undeclare_no_pointers(char*, size_t)
198{
199}
200
201void*
202__undeclare_reachable(void* p)
203{
204 return p;
205}
184#endif // !defined(_LIBCPP_HAS_NO_THREADS)
206185
207186void*
208187align(size_t alignment, size_t size, void*& ptr, size_t& space)
lib/libcxx/src/mutex.cpp+1-1
......@@ -1,4 +1,4 @@
1//===------------------------- mutex.cpp ----------------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/mutex_destructor.cpp+1-1
......@@ -1,4 +1,4 @@
1//===--------------------- mutex_destructor.cpp ---------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/new.cpp+1-1
......@@ -1,4 +1,4 @@
1//===--------------------------- new.cpp ----------------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/optional.cpp+1-1
......@@ -1,4 +1,4 @@
1//===------------------------ optional.cpp --------------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/random.cpp+37-16
......@@ -1,4 +1,4 @@
1//===-------------------------- random.cpp --------------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
......@@ -9,8 +9,8 @@
99#include <__config>
1010
1111#if defined(_LIBCPP_USING_WIN32_RANDOM)
12// Must be defined before including stdlib.h to enable rand_s().
13#define _CRT_RAND_S
12 // Must be defined before including stdlib.h to enable rand_s().
13# define _CRT_RAND_S
1414#endif // defined(_LIBCPP_USING_WIN32_RANDOM)
1515
1616#include "limits"
......@@ -18,7 +18,7 @@
1818#include "system_error"
1919
2020#if defined(__sun__)
21#define rename solaris_headers_are_broken
21# define rename solaris_headers_are_broken
2222#endif // defined(__sun__)
2323
2424#include <errno.h>
......@@ -26,16 +26,18 @@
2626#include <stdlib.h>
2727
2828#if defined(_LIBCPP_USING_GETENTROPY)
29#include <sys/random.h>
29# include <sys/random.h>
3030#elif defined(_LIBCPP_USING_DEV_RANDOM)
31#include <fcntl.h>
32#include <unistd.h>
33#if __has_include(<sys/ioctl.h>) && __has_include(<linux/random.h>)
34#include <sys/ioctl.h>
35#include <linux/random.h>
36#endif
31# include <fcntl.h>
32# include <unistd.h>
33# if __has_include(<sys/ioctl.h>) && __has_include(<linux/random.h>)
34# include <sys/ioctl.h>
35# include <linux/random.h>
36# endif
3737#elif defined(_LIBCPP_USING_NACL_RANDOM)
38#include <nacl/nacl_random.h>
38# include <nacl/nacl_random.h>
39#elif defined(_LIBCPP_USING_FUCHSIA_CPRNG)
40# include <zircon/syscalls.h>
3941#endif
4042
4143
......@@ -66,10 +68,8 @@ random_device::operator()()
6668
6769#elif defined(_LIBCPP_USING_ARC4_RANDOM)
6870
69random_device::random_device(const string& __token)
71random_device::random_device(const string&)
7072{
71 if (__token != "/dev/urandom")
72 __throw_system_error(ENOENT, ("random device not supported " + __token).c_str());
7373}
7474
7575random_device::~random_device()
......@@ -170,6 +170,27 @@ random_device::operator()()
170170 return r;
171171}
172172
173#elif defined(_LIBCPP_USING_FUCHSIA_CPRNG)
174
175random_device::random_device(const string& __token) {
176 if (__token != "/dev/urandom")
177 __throw_system_error(ENOENT, ("random device not supported " + __token).c_str());
178}
179
180random_device::~random_device() {}
181
182unsigned random_device::operator()() {
183 // Implicitly link against the vDSO system call ABI without
184 // requiring the final link to specify -lzircon explicitly when
185 // statically linking libc++.
186# pragma comment(lib, "zircon")
187
188 // The system call cannot fail. It returns only when the bits are ready.
189 unsigned r;
190 _zx_cprng_draw(&r, sizeof(r));
191 return r;
192}
193
173194#else
174195#error "Random device not implemented for this architecture"
175196#endif
......@@ -189,7 +210,7 @@ random_device::entropy() const noexcept
189210 return std::numeric_limits<result_type>::digits;
190211
191212 return ent;
192#elif defined(__OpenBSD__)
213#elif defined(_LIBCPP_USING_ARC4_RANDOM) || defined(_LIBCPP_USING_FUCHSIA_CPRNG)
193214 return std::numeric_limits<result_type>::digits;
194215#else
195216 return 0;
lib/libcxx/src/random_shuffle.cpp+1-1
......@@ -1,4 +1,4 @@
1//===----------------------- random_shuffle.cpp ---------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/regex.cpp+121-1
......@@ -1,4 +1,4 @@
1//===-------------------------- regex.cpp ---------------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
......@@ -76,6 +76,125 @@ struct collationnames
7676 char char_;
7777};
7878
79#if defined(__MVS__) && !defined(__NATIVE_ASCII_F)
80// EBCDIC IBM-1047
81// Sorted via the EBCDIC collating sequence
82const collationnames collatenames[] =
83{
84 {"a", 0x81},
85 {"alert", 0x2f},
86 {"ampersand", 0x50},
87 {"apostrophe", 0x7d},
88 {"asterisk", 0x5c},
89 {"b", 0x82},
90 {"backslash", 0xe0},
91 {"backspace", 0x16},
92 {"c", 0x83},
93 {"carriage-return", 0xd},
94 {"circumflex", 0x5f},
95 {"circumflex-accent", 0x5f},
96 {"colon", 0x7a},
97 {"comma", 0x6b},
98 {"commercial-at", 0x7c},
99 {"d", 0x84},
100 {"dollar-sign", 0x5b},
101 {"e", 0x85},
102 {"eight", 0xf8},
103 {"equals-sign", 0x7e},
104 {"exclamation-mark", 0x5a},
105 {"f", 0x86},
106 {"five", 0xf5},
107 {"form-feed", 0xc},
108 {"four", 0xf4},
109 {"full-stop", 0x4b},
110 {"g", 0x87},
111 {"grave-accent", 0x79},
112 {"greater-than-sign", 0x6e},
113 {"h", 0x88},
114 {"hyphen", 0x60},
115 {"hyphen-minus", 0x60},
116 {"i", 0x89},
117 {"j", 0x91},
118 {"k", 0x92},
119 {"l", 0x93},
120 {"left-brace", 0xc0},
121 {"left-curly-bracket", 0xc0},
122 {"left-parenthesis", 0x4d},
123 {"left-square-bracket", 0xad},
124 {"less-than-sign", 0x4c},
125 {"low-line", 0x6d},
126 {"m", 0x94},
127 {"n", 0x95},
128 {"newline", 0x15},
129 {"nine", 0xf9},
130 {"number-sign", 0x7b},
131 {"o", 0x96},
132 {"one", 0xf1},
133 {"p", 0x97},
134 {"percent-sign", 0x6c},
135 {"period", 0x4b},
136 {"plus-sign", 0x4e},
137 {"q", 0x98},
138 {"question-mark", 0x6f},
139 {"quotation-mark", 0x7f},
140 {"r", 0x99},
141 {"reverse-solidus", 0xe0},
142 {"right-brace", 0xd0},
143 {"right-curly-bracket", 0xd0},
144 {"right-parenthesis", 0x5d},
145 {"right-square-bracket", 0xbd},
146 {"s", 0xa2},
147 {"semicolon", 0x5e},
148 {"seven", 0xf7},
149 {"six", 0xf6},
150 {"slash", 0x61},
151 {"solidus", 0x61},
152 {"space", 0x40},
153 {"t", 0xa3},
154 {"tab", 0x5},
155 {"three", 0xf3},
156 {"tilde", 0xa1},
157 {"two", 0xf2},
158 {"u", 0xa4},
159 {"underscore", 0x6d},
160 {"v", 0xa5},
161 {"vertical-line", 0x4f},
162 {"vertical-tab", 0xb},
163 {"w", 0xa6},
164 {"x", 0xa7},
165 {"y", 0xa8},
166 {"z", 0xa9},
167 {"zero", 0xf0},
168 {"A", 0xc1},
169 {"B", 0xc2},
170 {"C", 0xc3},
171 {"D", 0xc4},
172 {"E", 0xc5},
173 {"F", 0xc6},
174 {"G", 0xc7},
175 {"H", 0xc8},
176 {"I", 0xc9},
177 {"J", 0xd1},
178 {"K", 0xd2},
179 {"L", 0xd3},
180 {"M", 0xd4},
181 {"N", 0xd5},
182 {"NUL", 0},
183 {"O", 0xd6},
184 {"P", 0xd7},
185 {"Q", 0xd8},
186 {"R", 0xd9},
187 {"S", 0xe2},
188 {"T", 0xe3},
189 {"U", 0xe4},
190 {"V", 0xe5},
191 {"W", 0xe6},
192 {"X", 0xe7},
193 {"Y", 0xe8},
194 {"Z", 0xe9}
195};
196#else
197// ASCII
79198const collationnames collatenames[] =
80199{
81200 {"A", 0x41},
......@@ -190,6 +309,7 @@ const collationnames collatenames[] =
190309 {"z", 0x7a},
191310 {"zero", 0x30}
192311};
312#endif
193313
194314struct classnames
195315{
lib/libcxx/src/ryu/d2fixed.cpp created+669
......@@ -0,0 +1,669 @@
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// Copyright (c) Microsoft Corporation.
10// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
11
12// Copyright 2018 Ulf Adams
13// Copyright (c) Microsoft Corporation. All rights reserved.
14
15// Boost Software License - Version 1.0 - August 17th, 2003
16
17// Permission is hereby granted, free of charge, to any person or organization
18// obtaining a copy of the software and accompanying documentation covered by
19// this license (the "Software") to use, reproduce, display, distribute,
20// execute, and transmit the Software, and to prepare derivative works of the
21// Software, and to permit third-parties to whom the Software is furnished to
22// do so, all subject to the following:
23
24// The copyright notices in the Software and this entire statement, including
25// the above license grant, this restriction and the following disclaimer,
26// must be included in all copies of the Software, in whole or in part, and
27// all derivative works of the Software, unless such copies or derivative
28// works are solely in the form of machine-executable object code generated by
29// a source language processor.
30
31// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
34// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
35// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
36// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
37// DEALINGS IN THE SOFTWARE.
38
39// Avoid formatting to keep the changes with the original code minimal.
40// clang-format off
41
42#include "__config"
43#include "charconv"
44#include "cstring"
45#include "system_error"
46
47#include "include/ryu/common.h"
48#include "include/ryu/d2fixed.h"
49#include "include/ryu/d2fixed_full_table.h"
50#include "include/ryu/d2s.h"
51#include "include/ryu/d2s_intrinsics.h"
52#include "include/ryu/digit_table.h"
53
54_LIBCPP_BEGIN_NAMESPACE_STD
55
56inline constexpr int __POW10_ADDITIONAL_BITS = 120;
57
58#ifdef _LIBCPP_INTRINSIC128
59// Returns the low 64 bits of the high 128 bits of the 256-bit product of a and b.
60[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __umul256_hi128_lo64(
61 const uint64_t __aHi, const uint64_t __aLo, const uint64_t __bHi, const uint64_t __bLo) {
62 uint64_t __b00Hi;
63 const uint64_t __b00Lo = __ryu_umul128(__aLo, __bLo, &__b00Hi);
64 uint64_t __b01Hi;
65 const uint64_t __b01Lo = __ryu_umul128(__aLo, __bHi, &__b01Hi);
66 uint64_t __b10Hi;
67 const uint64_t __b10Lo = __ryu_umul128(__aHi, __bLo, &__b10Hi);
68 uint64_t __b11Hi;
69 const uint64_t __b11Lo = __ryu_umul128(__aHi, __bHi, &__b11Hi);
70 (void) __b00Lo; // unused
71 (void) __b11Hi; // unused
72 const uint64_t __temp1Lo = __b10Lo + __b00Hi;
73 const uint64_t __temp1Hi = __b10Hi + (__temp1Lo < __b10Lo);
74 const uint64_t __temp2Lo = __b01Lo + __temp1Lo;
75 const uint64_t __temp2Hi = __b01Hi + (__temp2Lo < __b01Lo);
76 return __b11Lo + __temp1Hi + __temp2Hi;
77}
78
79[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __uint128_mod1e9(const uint64_t __vHi, const uint64_t __vLo) {
80 // After multiplying, we're going to shift right by 29, then truncate to uint32_t.
81 // This means that we need only 29 + 32 = 61 bits, so we can truncate to uint64_t before shifting.
82 const uint64_t __multiplied = __umul256_hi128_lo64(__vHi, __vLo, 0x89705F4136B4A597u, 0x31680A88F8953031u);
83
84 // For uint32_t truncation, see the __mod1e9() comment in d2s_intrinsics.h.
85 const uint32_t __shifted = static_cast<uint32_t>(__multiplied >> 29);
86
87 return static_cast<uint32_t>(__vLo) - 1000000000 * __shifted;
88}
89#endif // ^^^ intrinsics available ^^^
90
91[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __mulShift_mod1e9(const uint64_t __m, const uint64_t* const __mul, const int32_t __j) {
92 uint64_t __high0; // 64
93 const uint64_t __low0 = __ryu_umul128(__m, __mul[0], &__high0); // 0
94 uint64_t __high1; // 128
95 const uint64_t __low1 = __ryu_umul128(__m, __mul[1], &__high1); // 64
96 uint64_t __high2; // 192
97 const uint64_t __low2 = __ryu_umul128(__m, __mul[2], &__high2); // 128
98 const uint64_t __s0low = __low0; // 0
99 (void) __s0low; // unused
100 const uint64_t __s0high = __low1 + __high0; // 64
101 const uint32_t __c1 = __s0high < __low1;
102 const uint64_t __s1low = __low2 + __high1 + __c1; // 128
103 const uint32_t __c2 = __s1low < __low2; // __high1 + __c1 can't overflow, so compare against __low2
104 const uint64_t __s1high = __high2 + __c2; // 192
105 _LIBCPP_ASSERT(__j >= 128, "");
106 _LIBCPP_ASSERT(__j <= 180, "");
107#ifdef _LIBCPP_INTRINSIC128
108 const uint32_t __dist = static_cast<uint32_t>(__j - 128); // __dist: [0, 52]
109 const uint64_t __shiftedhigh = __s1high >> __dist;
110 const uint64_t __shiftedlow = __ryu_shiftright128(__s1low, __s1high, __dist);
111 return __uint128_mod1e9(__shiftedhigh, __shiftedlow);
112#else // ^^^ intrinsics available ^^^ / vvv intrinsics unavailable vvv
113 if (__j < 160) { // __j: [128, 160)
114 const uint64_t __r0 = __mod1e9(__s1high);
115 const uint64_t __r1 = __mod1e9((__r0 << 32) | (__s1low >> 32));
116 const uint64_t __r2 = ((__r1 << 32) | (__s1low & 0xffffffff));
117 return __mod1e9(__r2 >> (__j - 128));
118 } else { // __j: [160, 192)
119 const uint64_t __r0 = __mod1e9(__s1high);
120 const uint64_t __r1 = ((__r0 << 32) | (__s1low >> 32));
121 return __mod1e9(__r1 >> (__j - 160));
122 }
123#endif // ^^^ intrinsics unavailable ^^^
124}
125
126void __append_n_digits(const uint32_t __olength, uint32_t __digits, char* const __result) {
127 uint32_t __i = 0;
128 while (__digits >= 10000) {
129#ifdef __clang__ // TRANSITION, LLVM-38217
130 const uint32_t __c = __digits - 10000 * (__digits / 10000);
131#else
132 const uint32_t __c = __digits % 10000;
133#endif
134 __digits /= 10000;
135 const uint32_t __c0 = (__c % 100) << 1;
136 const uint32_t __c1 = (__c / 100) << 1;
137 _VSTD::memcpy(__result + __olength - __i - 2, __DIGIT_TABLE + __c0, 2);
138 _VSTD::memcpy(__result + __olength - __i - 4, __DIGIT_TABLE + __c1, 2);
139 __i += 4;
140 }
141 if (__digits >= 100) {
142 const uint32_t __c = (__digits % 100) << 1;
143 __digits /= 100;
144 _VSTD::memcpy(__result + __olength - __i - 2, __DIGIT_TABLE + __c, 2);
145 __i += 2;
146 }
147 if (__digits >= 10) {
148 const uint32_t __c = __digits << 1;
149 _VSTD::memcpy(__result + __olength - __i - 2, __DIGIT_TABLE + __c, 2);
150 } else {
151 __result[0] = static_cast<char>('0' + __digits);
152 }
153}
154
155_LIBCPP_HIDE_FROM_ABI inline void __append_d_digits(const uint32_t __olength, uint32_t __digits, char* const __result) {
156 uint32_t __i = 0;
157 while (__digits >= 10000) {
158#ifdef __clang__ // TRANSITION, LLVM-38217
159 const uint32_t __c = __digits - 10000 * (__digits / 10000);
160#else
161 const uint32_t __c = __digits % 10000;
162#endif
163 __digits /= 10000;
164 const uint32_t __c0 = (__c % 100) << 1;
165 const uint32_t __c1 = (__c / 100) << 1;
166 _VSTD::memcpy(__result + __olength + 1 - __i - 2, __DIGIT_TABLE + __c0, 2);
167 _VSTD::memcpy(__result + __olength + 1 - __i - 4, __DIGIT_TABLE + __c1, 2);
168 __i += 4;
169 }
170 if (__digits >= 100) {
171 const uint32_t __c = (__digits % 100) << 1;
172 __digits /= 100;
173 _VSTD::memcpy(__result + __olength + 1 - __i - 2, __DIGIT_TABLE + __c, 2);
174 __i += 2;
175 }
176 if (__digits >= 10) {
177 const uint32_t __c = __digits << 1;
178 __result[2] = __DIGIT_TABLE[__c + 1];
179 __result[1] = '.';
180 __result[0] = __DIGIT_TABLE[__c];
181 } else {
182 __result[1] = '.';
183 __result[0] = static_cast<char>('0' + __digits);
184 }
185}
186
187_LIBCPP_HIDE_FROM_ABI inline void __append_c_digits(const uint32_t __count, uint32_t __digits, char* const __result) {
188 uint32_t __i = 0;
189 for (; __i < __count - 1; __i += 2) {
190 const uint32_t __c = (__digits % 100) << 1;
191 __digits /= 100;
192 _VSTD::memcpy(__result + __count - __i - 2, __DIGIT_TABLE + __c, 2);
193 }
194 if (__i < __count) {
195 const char __c = static_cast<char>('0' + (__digits % 10));
196 __result[__count - __i - 1] = __c;
197 }
198}
199
200void __append_nine_digits(uint32_t __digits, char* const __result) {
201 if (__digits == 0) {
202 _VSTD::memset(__result, '0', 9);
203 return;
204 }
205
206 for (uint32_t __i = 0; __i < 5; __i += 4) {
207#ifdef __clang__ // TRANSITION, LLVM-38217
208 const uint32_t __c = __digits - 10000 * (__digits / 10000);
209#else
210 const uint32_t __c = __digits % 10000;
211#endif
212 __digits /= 10000;
213 const uint32_t __c0 = (__c % 100) << 1;
214 const uint32_t __c1 = (__c / 100) << 1;
215 _VSTD::memcpy(__result + 7 - __i, __DIGIT_TABLE + __c0, 2);
216 _VSTD::memcpy(__result + 5 - __i, __DIGIT_TABLE + __c1, 2);
217 }
218 __result[0] = static_cast<char>('0' + __digits);
219}
220
221[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __indexForExponent(const uint32_t __e) {
222 return (__e + 15) / 16;
223}
224
225[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __pow10BitsForIndex(const uint32_t __idx) {
226 return 16 * __idx + __POW10_ADDITIONAL_BITS;
227}
228
229[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __lengthForIndex(const uint32_t __idx) {
230 // +1 for ceil, +16 for mantissa, +8 to round up when dividing by 9
231 return (__log10Pow2(16 * static_cast<int32_t>(__idx)) + 1 + 16 + 8) / 9;
232}
233
234[[nodiscard]] to_chars_result __d2fixed_buffered_n(char* _First, char* const _Last, const double __d,
235 const uint32_t __precision) {
236 char* const _Original_first = _First;
237
238 const uint64_t __bits = __double_to_bits(__d);
239
240 // Case distinction; exit early for the easy cases.
241 if (__bits == 0) {
242 const int32_t _Total_zero_length = 1 // leading zero
243 + static_cast<int32_t>(__precision != 0) // possible decimal point
244 + static_cast<int32_t>(__precision); // zeroes after decimal point
245
246 if (_Last - _First < _Total_zero_length) {
247 return { _Last, errc::value_too_large };
248 }
249
250 *_First++ = '0';
251 if (__precision > 0) {
252 *_First++ = '.';
253 _VSTD::memset(_First, '0', __precision);
254 _First += __precision;
255 }
256 return { _First, errc{} };
257 }
258
259 // Decode __bits into mantissa and exponent.
260 const uint64_t __ieeeMantissa = __bits & ((1ull << __DOUBLE_MANTISSA_BITS) - 1);
261 const uint32_t __ieeeExponent = static_cast<uint32_t>(__bits >> __DOUBLE_MANTISSA_BITS);
262
263 int32_t __e2;
264 uint64_t __m2;
265 if (__ieeeExponent == 0) {
266 __e2 = 1 - __DOUBLE_BIAS - __DOUBLE_MANTISSA_BITS;
267 __m2 = __ieeeMantissa;
268 } else {
269 __e2 = static_cast<int32_t>(__ieeeExponent) - __DOUBLE_BIAS - __DOUBLE_MANTISSA_BITS;
270 __m2 = (1ull << __DOUBLE_MANTISSA_BITS) | __ieeeMantissa;
271 }
272
273 bool __nonzero = false;
274 if (__e2 >= -52) {
275 const uint32_t __idx = __e2 < 0 ? 0 : __indexForExponent(static_cast<uint32_t>(__e2));
276 const uint32_t __p10bits = __pow10BitsForIndex(__idx);
277 const int32_t __len = static_cast<int32_t>(__lengthForIndex(__idx));
278 for (int32_t __i = __len - 1; __i >= 0; --__i) {
279 const uint32_t __j = __p10bits - __e2;
280 // Temporary: __j is usually around 128, and by shifting a bit, we push it to 128 or above, which is
281 // a slightly faster code path in __mulShift_mod1e9. Instead, we can just increase the multipliers.
282 const uint32_t __digits = __mulShift_mod1e9(__m2 << 8, __POW10_SPLIT[__POW10_OFFSET[__idx] + __i],
283 static_cast<int32_t>(__j + 8));
284 if (__nonzero) {
285 if (_Last - _First < 9) {
286 return { _Last, errc::value_too_large };
287 }
288 __append_nine_digits(__digits, _First);
289 _First += 9;
290 } else if (__digits != 0) {
291 const uint32_t __olength = __decimalLength9(__digits);
292 if (_Last - _First < static_cast<ptrdiff_t>(__olength)) {
293 return { _Last, errc::value_too_large };
294 }
295 __append_n_digits(__olength, __digits, _First);
296 _First += __olength;
297 __nonzero = true;
298 }
299 }
300 }
301 if (!__nonzero) {
302 if (_First == _Last) {
303 return { _Last, errc::value_too_large };
304 }
305 *_First++ = '0';
306 }
307 if (__precision > 0) {
308 if (_First == _Last) {
309 return { _Last, errc::value_too_large };
310 }
311 *_First++ = '.';
312 }
313 if (__e2 < 0) {
314 const int32_t __idx = -__e2 / 16;
315 const uint32_t __blocks = __precision / 9 + 1;
316 // 0 = don't round up; 1 = round up unconditionally; 2 = round up if odd.
317 int __roundUp = 0;
318 uint32_t __i = 0;
319 if (__blocks <= __MIN_BLOCK_2[__idx]) {
320 __i = __blocks;
321 if (_Last - _First < static_cast<ptrdiff_t>(__precision)) {
322 return { _Last, errc::value_too_large };
323 }
324 _VSTD::memset(_First, '0', __precision);
325 _First += __precision;
326 } else if (__i < __MIN_BLOCK_2[__idx]) {
327 __i = __MIN_BLOCK_2[__idx];
328 if (_Last - _First < static_cast<ptrdiff_t>(9 * __i)) {
329 return { _Last, errc::value_too_large };
330 }
331 _VSTD::memset(_First, '0', 9 * __i);
332 _First += 9 * __i;
333 }
334 for (; __i < __blocks; ++__i) {
335 const int32_t __j = __ADDITIONAL_BITS_2 + (-__e2 - 16 * __idx);
336 const uint32_t __p = __POW10_OFFSET_2[__idx] + __i - __MIN_BLOCK_2[__idx];
337 if (__p >= __POW10_OFFSET_2[__idx + 1]) {
338 // If the remaining digits are all 0, then we might as well use memset.
339 // No rounding required in this case.
340 const uint32_t __fill = __precision - 9 * __i;
341 if (_Last - _First < static_cast<ptrdiff_t>(__fill)) {
342 return { _Last, errc::value_too_large };
343 }
344 _VSTD::memset(_First, '0', __fill);
345 _First += __fill;
346 break;
347 }
348 // Temporary: __j is usually around 128, and by shifting a bit, we push it to 128 or above, which is
349 // a slightly faster code path in __mulShift_mod1e9. Instead, we can just increase the multipliers.
350 uint32_t __digits = __mulShift_mod1e9(__m2 << 8, __POW10_SPLIT_2[__p], __j + 8);
351 if (__i < __blocks - 1) {
352 if (_Last - _First < 9) {
353 return { _Last, errc::value_too_large };
354 }
355 __append_nine_digits(__digits, _First);
356 _First += 9;
357 } else {
358 const uint32_t __maximum = __precision - 9 * __i;
359 uint32_t __lastDigit = 0;
360 for (uint32_t __k = 0; __k < 9 - __maximum; ++__k) {
361 __lastDigit = __digits % 10;
362 __digits /= 10;
363 }
364 if (__lastDigit != 5) {
365 __roundUp = __lastDigit > 5;
366 } else {
367 // Is m * 10^(additionalDigits + 1) / 2^(-__e2) integer?
368 const int32_t __requiredTwos = -__e2 - static_cast<int32_t>(__precision) - 1;
369 const bool __trailingZeros = __requiredTwos <= 0
370 || (__requiredTwos < 60 && __multipleOfPowerOf2(__m2, static_cast<uint32_t>(__requiredTwos)));
371 __roundUp = __trailingZeros ? 2 : 1;
372 }
373 if (__maximum > 0) {
374 if (_Last - _First < static_cast<ptrdiff_t>(__maximum)) {
375 return { _Last, errc::value_too_large };
376 }
377 __append_c_digits(__maximum, __digits, _First);
378 _First += __maximum;
379 }
380 break;
381 }
382 }
383 if (__roundUp != 0) {
384 char* _Round = _First;
385 char* _Dot = _Last;
386 while (true) {
387 if (_Round == _Original_first) {
388 _Round[0] = '1';
389 if (_Dot != _Last) {
390 _Dot[0] = '0';
391 _Dot[1] = '.';
392 }
393 if (_First == _Last) {
394 return { _Last, errc::value_too_large };
395 }
396 *_First++ = '0';
397 break;
398 }
399 --_Round;
400 const char __c = _Round[0];
401 if (__c == '.') {
402 _Dot = _Round;
403 } else if (__c == '9') {
404 _Round[0] = '0';
405 __roundUp = 1;
406 } else {
407 if (__roundUp == 1 || __c % 2 != 0) {
408 _Round[0] = __c + 1;
409 }
410 break;
411 }
412 }
413 }
414 } else {
415 if (_Last - _First < static_cast<ptrdiff_t>(__precision)) {
416 return { _Last, errc::value_too_large };
417 }
418 _VSTD::memset(_First, '0', __precision);
419 _First += __precision;
420 }
421 return { _First, errc{} };
422}
423
424[[nodiscard]] to_chars_result __d2exp_buffered_n(char* _First, char* const _Last, const double __d,
425 uint32_t __precision) {
426 char* const _Original_first = _First;
427
428 const uint64_t __bits = __double_to_bits(__d);
429
430 // Case distinction; exit early for the easy cases.
431 if (__bits == 0) {
432 const int32_t _Total_zero_length = 1 // leading zero
433 + static_cast<int32_t>(__precision != 0) // possible decimal point
434 + static_cast<int32_t>(__precision) // zeroes after decimal point
435 + 4; // "e+00"
436 if (_Last - _First < _Total_zero_length) {
437 return { _Last, errc::value_too_large };
438 }
439 *_First++ = '0';
440 if (__precision > 0) {
441 *_First++ = '.';
442 _VSTD::memset(_First, '0', __precision);
443 _First += __precision;
444 }
445 _VSTD::memcpy(_First, "e+00", 4);
446 _First += 4;
447 return { _First, errc{} };
448 }
449
450 // Decode __bits into mantissa and exponent.
451 const uint64_t __ieeeMantissa = __bits & ((1ull << __DOUBLE_MANTISSA_BITS) - 1);
452 const uint32_t __ieeeExponent = static_cast<uint32_t>(__bits >> __DOUBLE_MANTISSA_BITS);
453
454 int32_t __e2;
455 uint64_t __m2;
456 if (__ieeeExponent == 0) {
457 __e2 = 1 - __DOUBLE_BIAS - __DOUBLE_MANTISSA_BITS;
458 __m2 = __ieeeMantissa;
459 } else {
460 __e2 = static_cast<int32_t>(__ieeeExponent) - __DOUBLE_BIAS - __DOUBLE_MANTISSA_BITS;
461 __m2 = (1ull << __DOUBLE_MANTISSA_BITS) | __ieeeMantissa;
462 }
463
464 const bool __printDecimalPoint = __precision > 0;
465 ++__precision;
466 uint32_t __digits = 0;
467 uint32_t __printedDigits = 0;
468 uint32_t __availableDigits = 0;
469 int32_t __exp = 0;
470 if (__e2 >= -52) {
471 const uint32_t __idx = __e2 < 0 ? 0 : __indexForExponent(static_cast<uint32_t>(__e2));
472 const uint32_t __p10bits = __pow10BitsForIndex(__idx);
473 const int32_t __len = static_cast<int32_t>(__lengthForIndex(__idx));
474 for (int32_t __i = __len - 1; __i >= 0; --__i) {
475 const uint32_t __j = __p10bits - __e2;
476 // Temporary: __j is usually around 128, and by shifting a bit, we push it to 128 or above, which is
477 // a slightly faster code path in __mulShift_mod1e9. Instead, we can just increase the multipliers.
478 __digits = __mulShift_mod1e9(__m2 << 8, __POW10_SPLIT[__POW10_OFFSET[__idx] + __i],
479 static_cast<int32_t>(__j + 8));
480 if (__printedDigits != 0) {
481 if (__printedDigits + 9 > __precision) {
482 __availableDigits = 9;
483 break;
484 }
485 if (_Last - _First < 9) {
486 return { _Last, errc::value_too_large };
487 }
488 __append_nine_digits(__digits, _First);
489 _First += 9;
490 __printedDigits += 9;
491 } else if (__digits != 0) {
492 __availableDigits = __decimalLength9(__digits);
493 __exp = __i * 9 + static_cast<int32_t>(__availableDigits) - 1;
494 if (__availableDigits > __precision) {
495 break;
496 }
497 if (__printDecimalPoint) {
498 if (_Last - _First < static_cast<ptrdiff_t>(__availableDigits + 1)) {
499 return { _Last, errc::value_too_large };
500 }
501 __append_d_digits(__availableDigits, __digits, _First);
502 _First += __availableDigits + 1; // +1 for decimal point
503 } else {
504 if (_First == _Last) {
505 return { _Last, errc::value_too_large };
506 }
507 *_First++ = static_cast<char>('0' + __digits);
508 }
509 __printedDigits = __availableDigits;
510 __availableDigits = 0;
511 }
512 }
513 }
514
515 if (__e2 < 0 && __availableDigits == 0) {
516 const int32_t __idx = -__e2 / 16;
517 for (int32_t __i = __MIN_BLOCK_2[__idx]; __i < 200; ++__i) {
518 const int32_t __j = __ADDITIONAL_BITS_2 + (-__e2 - 16 * __idx);
519 const uint32_t __p = __POW10_OFFSET_2[__idx] + static_cast<uint32_t>(__i) - __MIN_BLOCK_2[__idx];
520 // Temporary: __j is usually around 128, and by shifting a bit, we push it to 128 or above, which is
521 // a slightly faster code path in __mulShift_mod1e9. Instead, we can just increase the multipliers.
522 __digits = (__p >= __POW10_OFFSET_2[__idx + 1]) ? 0 : __mulShift_mod1e9(__m2 << 8, __POW10_SPLIT_2[__p], __j + 8);
523 if (__printedDigits != 0) {
524 if (__printedDigits + 9 > __precision) {
525 __availableDigits = 9;
526 break;
527 }
528 if (_Last - _First < 9) {
529 return { _Last, errc::value_too_large };
530 }
531 __append_nine_digits(__digits, _First);
532 _First += 9;
533 __printedDigits += 9;
534 } else if (__digits != 0) {
535 __availableDigits = __decimalLength9(__digits);
536 __exp = -(__i + 1) * 9 + static_cast<int32_t>(__availableDigits) - 1;
537 if (__availableDigits > __precision) {
538 break;
539 }
540 if (__printDecimalPoint) {
541 if (_Last - _First < static_cast<ptrdiff_t>(__availableDigits + 1)) {
542 return { _Last, errc::value_too_large };
543 }
544 __append_d_digits(__availableDigits, __digits, _First);
545 _First += __availableDigits + 1; // +1 for decimal point
546 } else {
547 if (_First == _Last) {
548 return { _Last, errc::value_too_large };
549 }
550 *_First++ = static_cast<char>('0' + __digits);
551 }
552 __printedDigits = __availableDigits;
553 __availableDigits = 0;
554 }
555 }
556 }
557
558 const uint32_t __maximum = __precision - __printedDigits;
559 if (__availableDigits == 0) {
560 __digits = 0;
561 }
562 uint32_t __lastDigit = 0;
563 if (__availableDigits > __maximum) {
564 for (uint32_t __k = 0; __k < __availableDigits - __maximum; ++__k) {
565 __lastDigit = __digits % 10;
566 __digits /= 10;
567 }
568 }
569 // 0 = don't round up; 1 = round up unconditionally; 2 = round up if odd.
570 int __roundUp = 0;
571 if (__lastDigit != 5) {
572 __roundUp = __lastDigit > 5;
573 } else {
574 // Is m * 2^__e2 * 10^(__precision + 1 - __exp) integer?
575 // __precision was already increased by 1, so we don't need to write + 1 here.
576 const int32_t __rexp = static_cast<int32_t>(__precision) - __exp;
577 const int32_t __requiredTwos = -__e2 - __rexp;
578 bool __trailingZeros = __requiredTwos <= 0
579 || (__requiredTwos < 60 && __multipleOfPowerOf2(__m2, static_cast<uint32_t>(__requiredTwos)));
580 if (__rexp < 0) {
581 const int32_t __requiredFives = -__rexp;
582 __trailingZeros = __trailingZeros && __multipleOfPowerOf5(__m2, static_cast<uint32_t>(__requiredFives));
583 }
584 __roundUp = __trailingZeros ? 2 : 1;
585 }
586 if (__printedDigits != 0) {
587 if (_Last - _First < static_cast<ptrdiff_t>(__maximum)) {
588 return { _Last, errc::value_too_large };
589 }
590 if (__digits == 0) {
591 _VSTD::memset(_First, '0', __maximum);
592 } else {
593 __append_c_digits(__maximum, __digits, _First);
594 }
595 _First += __maximum;
596 } else {
597 if (__printDecimalPoint) {
598 if (_Last - _First < static_cast<ptrdiff_t>(__maximum + 1)) {
599 return { _Last, errc::value_too_large };
600 }
601 __append_d_digits(__maximum, __digits, _First);
602 _First += __maximum + 1; // +1 for decimal point
603 } else {
604 if (_First == _Last) {
605 return { _Last, errc::value_too_large };
606 }
607 *_First++ = static_cast<char>('0' + __digits);
608 }
609 }
610 if (__roundUp != 0) {
611 char* _Round = _First;
612 while (true) {
613 if (_Round == _Original_first) {
614 _Round[0] = '1';
615 ++__exp;
616 break;
617 }
618 --_Round;
619 const char __c = _Round[0];
620 if (__c == '.') {
621 // Keep going.
622 } else if (__c == '9') {
623 _Round[0] = '0';
624 __roundUp = 1;
625 } else {
626 if (__roundUp == 1 || __c % 2 != 0) {
627 _Round[0] = __c + 1;
628 }
629 break;
630 }
631 }
632 }
633
634 char _Sign_character;
635
636 if (__exp < 0) {
637 _Sign_character = '-';
638 __exp = -__exp;
639 } else {
640 _Sign_character = '+';
641 }
642
643 const int _Exponent_part_length = __exp >= 100
644 ? 5 // "e+NNN"
645 : 4; // "e+NN"
646
647 if (_Last - _First < _Exponent_part_length) {
648 return { _Last, errc::value_too_large };
649 }
650
651 *_First++ = 'e';
652 *_First++ = _Sign_character;
653
654 if (__exp >= 100) {
655 const int32_t __c = __exp % 10;
656 _VSTD::memcpy(_First, __DIGIT_TABLE + 2 * (__exp / 10), 2);
657 _First[2] = static_cast<char>('0' + __c);
658 _First += 3;
659 } else {
660 _VSTD::memcpy(_First, __DIGIT_TABLE + 2 * __exp, 2);
661 _First += 2;
662 }
663
664 return { _First, errc{} };
665}
666
667_LIBCPP_END_NAMESPACE_STD
668
669// clang-format on
lib/libcxx/src/ryu/d2s.cpp created+782
......@@ -0,0 +1,782 @@
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// Copyright (c) Microsoft Corporation.
10// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
11
12// Copyright 2018 Ulf Adams
13// Copyright (c) Microsoft Corporation. All rights reserved.
14
15// Boost Software License - Version 1.0 - August 17th, 2003
16
17// Permission is hereby granted, free of charge, to any person or organization
18// obtaining a copy of the software and accompanying documentation covered by
19// this license (the "Software") to use, reproduce, display, distribute,
20// execute, and transmit the Software, and to prepare derivative works of the
21// Software, and to permit third-parties to whom the Software is furnished to
22// do so, all subject to the following:
23
24// The copyright notices in the Software and this entire statement, including
25// the above license grant, this restriction and the following disclaimer,
26// must be included in all copies of the Software, in whole or in part, and
27// all derivative works of the Software, unless such copies or derivative
28// works are solely in the form of machine-executable object code generated by
29// a source language processor.
30
31// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
34// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
35// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
36// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
37// DEALINGS IN THE SOFTWARE.
38
39// Avoid formatting to keep the changes with the original code minimal.
40// clang-format off
41
42#include "__config"
43#include "charconv"
44
45#include "include/ryu/common.h"
46#include "include/ryu/d2fixed.h"
47#include "include/ryu/d2s.h"
48#include "include/ryu/d2s_full_table.h"
49#include "include/ryu/d2s_intrinsics.h"
50#include "include/ryu/digit_table.h"
51#include "include/ryu/ryu.h"
52
53_LIBCPP_BEGIN_NAMESPACE_STD
54
55// We need a 64x128-bit multiplication and a subsequent 128-bit shift.
56// Multiplication:
57// The 64-bit factor is variable and passed in, the 128-bit factor comes
58// from a lookup table. We know that the 64-bit factor only has 55
59// significant bits (i.e., the 9 topmost bits are zeros). The 128-bit
60// factor only has 124 significant bits (i.e., the 4 topmost bits are
61// zeros).
62// Shift:
63// In principle, the multiplication result requires 55 + 124 = 179 bits to
64// represent. However, we then shift this value to the right by __j, which is
65// at least __j >= 115, so the result is guaranteed to fit into 179 - 115 = 64
66// bits. This means that we only need the topmost 64 significant bits of
67// the 64x128-bit multiplication.
68//
69// There are several ways to do this:
70// 1. Best case: the compiler exposes a 128-bit type.
71// We perform two 64x64-bit multiplications, add the higher 64 bits of the
72// lower result to the higher result, and shift by __j - 64 bits.
73//
74// We explicitly cast from 64-bit to 128-bit, so the compiler can tell
75// that these are only 64-bit inputs, and can map these to the best
76// possible sequence of assembly instructions.
77// x64 machines happen to have matching assembly instructions for
78// 64x64-bit multiplications and 128-bit shifts.
79//
80// 2. Second best case: the compiler exposes intrinsics for the x64 assembly
81// instructions mentioned in 1.
82//
83// 3. We only have 64x64 bit instructions that return the lower 64 bits of
84// the result, i.e., we have to use plain C.
85// Our inputs are less than the full width, so we have three options:
86// a. Ignore this fact and just implement the intrinsics manually.
87// b. Split both into 31-bit pieces, which guarantees no internal overflow,
88// but requires extra work upfront (unless we change the lookup table).
89// c. Split only the first factor into 31-bit pieces, which also guarantees
90// no internal overflow, but requires extra work since the intermediate
91// results are not perfectly aligned.
92#ifdef _LIBCPP_INTRINSIC128
93
94[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __mulShift(const uint64_t __m, const uint64_t* const __mul, const int32_t __j) {
95 // __m is maximum 55 bits
96 uint64_t __high1; // 128
97 const uint64_t __low1 = __ryu_umul128(__m, __mul[1], &__high1); // 64
98 uint64_t __high0; // 64
99 (void) __ryu_umul128(__m, __mul[0], &__high0); // 0
100 const uint64_t __sum = __high0 + __low1;
101 if (__sum < __high0) {
102 ++__high1; // overflow into __high1
103 }
104 return __ryu_shiftright128(__sum, __high1, static_cast<uint32_t>(__j - 64));
105}
106
107[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __mulShiftAll(const uint64_t __m, const uint64_t* const __mul, const int32_t __j,
108 uint64_t* const __vp, uint64_t* const __vm, const uint32_t __mmShift) {
109 *__vp = __mulShift(4 * __m + 2, __mul, __j);
110 *__vm = __mulShift(4 * __m - 1 - __mmShift, __mul, __j);
111 return __mulShift(4 * __m, __mul, __j);
112}
113
114#else // ^^^ intrinsics available ^^^ / vvv intrinsics unavailable vvv
115
116[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_ALWAYS_INLINE uint64_t __mulShiftAll(uint64_t __m, const uint64_t* const __mul, const int32_t __j,
117 uint64_t* const __vp, uint64_t* const __vm, const uint32_t __mmShift) { // TRANSITION, VSO-634761
118 __m <<= 1;
119 // __m is maximum 55 bits
120 uint64_t __tmp;
121 const uint64_t __lo = __ryu_umul128(__m, __mul[0], &__tmp);
122 uint64_t __hi;
123 const uint64_t __mid = __tmp + __ryu_umul128(__m, __mul[1], &__hi);
124 __hi += __mid < __tmp; // overflow into __hi
125
126 const uint64_t __lo2 = __lo + __mul[0];
127 const uint64_t __mid2 = __mid + __mul[1] + (__lo2 < __lo);
128 const uint64_t __hi2 = __hi + (__mid2 < __mid);
129 *__vp = __ryu_shiftright128(__mid2, __hi2, static_cast<uint32_t>(__j - 64 - 1));
130
131 if (__mmShift == 1) {
132 const uint64_t __lo3 = __lo - __mul[0];
133 const uint64_t __mid3 = __mid - __mul[1] - (__lo3 > __lo);
134 const uint64_t __hi3 = __hi - (__mid3 > __mid);
135 *__vm = __ryu_shiftright128(__mid3, __hi3, static_cast<uint32_t>(__j - 64 - 1));
136 } else {
137 const uint64_t __lo3 = __lo + __lo;
138 const uint64_t __mid3 = __mid + __mid + (__lo3 < __lo);
139 const uint64_t __hi3 = __hi + __hi + (__mid3 < __mid);
140 const uint64_t __lo4 = __lo3 - __mul[0];
141 const uint64_t __mid4 = __mid3 - __mul[1] - (__lo4 > __lo3);
142 const uint64_t __hi4 = __hi3 - (__mid4 > __mid3);
143 *__vm = __ryu_shiftright128(__mid4, __hi4, static_cast<uint32_t>(__j - 64));
144 }
145
146 return __ryu_shiftright128(__mid, __hi, static_cast<uint32_t>(__j - 64 - 1));
147}
148
149#endif // ^^^ intrinsics unavailable ^^^
150
151[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __decimalLength17(const uint64_t __v) {
152 // This is slightly faster than a loop.
153 // The average output length is 16.38 digits, so we check high-to-low.
154 // Function precondition: __v is not an 18, 19, or 20-digit number.
155 // (17 digits are sufficient for round-tripping.)
156 _LIBCPP_ASSERT(__v < 100000000000000000u, "");
157 if (__v >= 10000000000000000u) { return 17; }
158 if (__v >= 1000000000000000u) { return 16; }
159 if (__v >= 100000000000000u) { return 15; }
160 if (__v >= 10000000000000u) { return 14; }
161 if (__v >= 1000000000000u) { return 13; }
162 if (__v >= 100000000000u) { return 12; }
163 if (__v >= 10000000000u) { return 11; }
164 if (__v >= 1000000000u) { return 10; }
165 if (__v >= 100000000u) { return 9; }
166 if (__v >= 10000000u) { return 8; }
167 if (__v >= 1000000u) { return 7; }
168 if (__v >= 100000u) { return 6; }
169 if (__v >= 10000u) { return 5; }
170 if (__v >= 1000u) { return 4; }
171 if (__v >= 100u) { return 3; }
172 if (__v >= 10u) { return 2; }
173 return 1;
174}
175
176// A floating decimal representing m * 10^e.
177struct __floating_decimal_64 {
178 uint64_t __mantissa;
179 int32_t __exponent;
180};
181
182[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline __floating_decimal_64 __d2d(const uint64_t __ieeeMantissa, const uint32_t __ieeeExponent) {
183 int32_t __e2;
184 uint64_t __m2;
185 if (__ieeeExponent == 0) {
186 // We subtract 2 so that the bounds computation has 2 additional bits.
187 __e2 = 1 - __DOUBLE_BIAS - __DOUBLE_MANTISSA_BITS - 2;
188 __m2 = __ieeeMantissa;
189 } else {
190 __e2 = static_cast<int32_t>(__ieeeExponent) - __DOUBLE_BIAS - __DOUBLE_MANTISSA_BITS - 2;
191 __m2 = (1ull << __DOUBLE_MANTISSA_BITS) | __ieeeMantissa;
192 }
193 const bool __even = (__m2 & 1) == 0;
194 const bool __acceptBounds = __even;
195
196 // Step 2: Determine the interval of valid decimal representations.
197 const uint64_t __mv = 4 * __m2;
198 // Implicit bool -> int conversion. True is 1, false is 0.
199 const uint32_t __mmShift = __ieeeMantissa != 0 || __ieeeExponent <= 1;
200 // We would compute __mp and __mm like this:
201 // uint64_t __mp = 4 * __m2 + 2;
202 // uint64_t __mm = __mv - 1 - __mmShift;
203
204 // Step 3: Convert to a decimal power base using 128-bit arithmetic.
205 uint64_t __vr, __vp, __vm;
206 int32_t __e10;
207 bool __vmIsTrailingZeros = false;
208 bool __vrIsTrailingZeros = false;
209 if (__e2 >= 0) {
210 // I tried special-casing __q == 0, but there was no effect on performance.
211 // This expression is slightly faster than max(0, __log10Pow2(__e2) - 1).
212 const uint32_t __q = __log10Pow2(__e2) - (__e2 > 3);
213 __e10 = static_cast<int32_t>(__q);
214 const int32_t __k = __DOUBLE_POW5_INV_BITCOUNT + __pow5bits(static_cast<int32_t>(__q)) - 1;
215 const int32_t __i = -__e2 + static_cast<int32_t>(__q) + __k;
216 __vr = __mulShiftAll(__m2, __DOUBLE_POW5_INV_SPLIT[__q], __i, &__vp, &__vm, __mmShift);
217 if (__q <= 21) {
218 // This should use __q <= 22, but I think 21 is also safe. Smaller values
219 // may still be safe, but it's more difficult to reason about them.
220 // Only one of __mp, __mv, and __mm can be a multiple of 5, if any.
221 const uint32_t __mvMod5 = static_cast<uint32_t>(__mv) - 5 * static_cast<uint32_t>(__div5(__mv));
222 if (__mvMod5 == 0) {
223 __vrIsTrailingZeros = __multipleOfPowerOf5(__mv, __q);
224 } else if (__acceptBounds) {
225 // Same as min(__e2 + (~__mm & 1), __pow5Factor(__mm)) >= __q
226 // <=> __e2 + (~__mm & 1) >= __q && __pow5Factor(__mm) >= __q
227 // <=> true && __pow5Factor(__mm) >= __q, since __e2 >= __q.
228 __vmIsTrailingZeros = __multipleOfPowerOf5(__mv - 1 - __mmShift, __q);
229 } else {
230 // Same as min(__e2 + 1, __pow5Factor(__mp)) >= __q.
231 __vp -= __multipleOfPowerOf5(__mv + 2, __q);
232 }
233 }
234 } else {
235 // This expression is slightly faster than max(0, __log10Pow5(-__e2) - 1).
236 const uint32_t __q = __log10Pow5(-__e2) - (-__e2 > 1);
237 __e10 = static_cast<int32_t>(__q) + __e2;
238 const int32_t __i = -__e2 - static_cast<int32_t>(__q);
239 const int32_t __k = __pow5bits(__i) - __DOUBLE_POW5_BITCOUNT;
240 const int32_t __j = static_cast<int32_t>(__q) - __k;
241 __vr = __mulShiftAll(__m2, __DOUBLE_POW5_SPLIT[__i], __j, &__vp, &__vm, __mmShift);
242 if (__q <= 1) {
243 // {__vr,__vp,__vm} is trailing zeros if {__mv,__mp,__mm} has at least __q trailing 0 bits.
244 // __mv = 4 * __m2, so it always has at least two trailing 0 bits.
245 __vrIsTrailingZeros = true;
246 if (__acceptBounds) {
247 // __mm = __mv - 1 - __mmShift, so it has 1 trailing 0 bit iff __mmShift == 1.
248 __vmIsTrailingZeros = __mmShift == 1;
249 } else {
250 // __mp = __mv + 2, so it always has at least one trailing 0 bit.
251 --__vp;
252 }
253 } else if (__q < 63) { // TRANSITION(ulfjack): Use a tighter bound here.
254 // We need to compute min(ntz(__mv), __pow5Factor(__mv) - __e2) >= __q - 1
255 // <=> ntz(__mv) >= __q - 1 && __pow5Factor(__mv) - __e2 >= __q - 1
256 // <=> ntz(__mv) >= __q - 1 (__e2 is negative and -__e2 >= __q)
257 // <=> (__mv & ((1 << (__q - 1)) - 1)) == 0
258 // We also need to make sure that the left shift does not overflow.
259 __vrIsTrailingZeros = __multipleOfPowerOf2(__mv, __q - 1);
260 }
261 }
262
263 // Step 4: Find the shortest decimal representation in the interval of valid representations.
264 int32_t __removed = 0;
265 uint8_t __lastRemovedDigit = 0;
266 uint64_t _Output;
267 // On average, we remove ~2 digits.
268 if (__vmIsTrailingZeros || __vrIsTrailingZeros) {
269 // General case, which happens rarely (~0.7%).
270 for (;;) {
271 const uint64_t __vpDiv10 = __div10(__vp);
272 const uint64_t __vmDiv10 = __div10(__vm);
273 if (__vpDiv10 <= __vmDiv10) {
274 break;
275 }
276 const uint32_t __vmMod10 = static_cast<uint32_t>(__vm) - 10 * static_cast<uint32_t>(__vmDiv10);
277 const uint64_t __vrDiv10 = __div10(__vr);
278 const uint32_t __vrMod10 = static_cast<uint32_t>(__vr) - 10 * static_cast<uint32_t>(__vrDiv10);
279 __vmIsTrailingZeros &= __vmMod10 == 0;
280 __vrIsTrailingZeros &= __lastRemovedDigit == 0;
281 __lastRemovedDigit = static_cast<uint8_t>(__vrMod10);
282 __vr = __vrDiv10;
283 __vp = __vpDiv10;
284 __vm = __vmDiv10;
285 ++__removed;
286 }
287 if (__vmIsTrailingZeros) {
288 for (;;) {
289 const uint64_t __vmDiv10 = __div10(__vm);
290 const uint32_t __vmMod10 = static_cast<uint32_t>(__vm) - 10 * static_cast<uint32_t>(__vmDiv10);
291 if (__vmMod10 != 0) {
292 break;
293 }
294 const uint64_t __vpDiv10 = __div10(__vp);
295 const uint64_t __vrDiv10 = __div10(__vr);
296 const uint32_t __vrMod10 = static_cast<uint32_t>(__vr) - 10 * static_cast<uint32_t>(__vrDiv10);
297 __vrIsTrailingZeros &= __lastRemovedDigit == 0;
298 __lastRemovedDigit = static_cast<uint8_t>(__vrMod10);
299 __vr = __vrDiv10;
300 __vp = __vpDiv10;
301 __vm = __vmDiv10;
302 ++__removed;
303 }
304 }
305 if (__vrIsTrailingZeros && __lastRemovedDigit == 5 && __vr % 2 == 0) {
306 // Round even if the exact number is .....50..0.
307 __lastRemovedDigit = 4;
308 }
309 // We need to take __vr + 1 if __vr is outside bounds or we need to round up.
310 _Output = __vr + ((__vr == __vm && (!__acceptBounds || !__vmIsTrailingZeros)) || __lastRemovedDigit >= 5);
311 } else {
312 // Specialized for the common case (~99.3%). Percentages below are relative to this.
313 bool __roundUp = false;
314 const uint64_t __vpDiv100 = __div100(__vp);
315 const uint64_t __vmDiv100 = __div100(__vm);
316 if (__vpDiv100 > __vmDiv100) { // Optimization: remove two digits at a time (~86.2%).
317 const uint64_t __vrDiv100 = __div100(__vr);
318 const uint32_t __vrMod100 = static_cast<uint32_t>(__vr) - 100 * static_cast<uint32_t>(__vrDiv100);
319 __roundUp = __vrMod100 >= 50;
320 __vr = __vrDiv100;
321 __vp = __vpDiv100;
322 __vm = __vmDiv100;
323 __removed += 2;
324 }
325 // Loop iterations below (approximately), without optimization above:
326 // 0: 0.03%, 1: 13.8%, 2: 70.6%, 3: 14.0%, 4: 1.40%, 5: 0.14%, 6+: 0.02%
327 // Loop iterations below (approximately), with optimization above:
328 // 0: 70.6%, 1: 27.8%, 2: 1.40%, 3: 0.14%, 4+: 0.02%
329 for (;;) {
330 const uint64_t __vpDiv10 = __div10(__vp);
331 const uint64_t __vmDiv10 = __div10(__vm);
332 if (__vpDiv10 <= __vmDiv10) {
333 break;
334 }
335 const uint64_t __vrDiv10 = __div10(__vr);
336 const uint32_t __vrMod10 = static_cast<uint32_t>(__vr) - 10 * static_cast<uint32_t>(__vrDiv10);
337 __roundUp = __vrMod10 >= 5;
338 __vr = __vrDiv10;
339 __vp = __vpDiv10;
340 __vm = __vmDiv10;
341 ++__removed;
342 }
343 // We need to take __vr + 1 if __vr is outside bounds or we need to round up.
344 _Output = __vr + (__vr == __vm || __roundUp);
345 }
346 const int32_t __exp = __e10 + __removed;
347
348 __floating_decimal_64 __fd;
349 __fd.__exponent = __exp;
350 __fd.__mantissa = _Output;
351 return __fd;
352}
353
354[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline to_chars_result __to_chars(char* const _First, char* const _Last, const __floating_decimal_64 __v,
355 chars_format _Fmt, const double __f) {
356 // Step 5: Print the decimal representation.
357 uint64_t _Output = __v.__mantissa;
358 int32_t _Ryu_exponent = __v.__exponent;
359 const uint32_t __olength = __decimalLength17(_Output);
360 int32_t _Scientific_exponent = _Ryu_exponent + static_cast<int32_t>(__olength) - 1;
361
362 if (_Fmt == chars_format{}) {
363 int32_t _Lower;
364 int32_t _Upper;
365
366 if (__olength == 1) {
367 // Value | Fixed | Scientific
368 // 1e-3 | "0.001" | "1e-03"
369 // 1e4 | "10000" | "1e+04"
370 _Lower = -3;
371 _Upper = 4;
372 } else {
373 // Value | Fixed | Scientific
374 // 1234e-7 | "0.0001234" | "1.234e-04"
375 // 1234e5 | "123400000" | "1.234e+08"
376 _Lower = -static_cast<int32_t>(__olength + 3);
377 _Upper = 5;
378 }
379
380 if (_Lower <= _Ryu_exponent && _Ryu_exponent <= _Upper) {
381 _Fmt = chars_format::fixed;
382 } else {
383 _Fmt = chars_format::scientific;
384 }
385 } else if (_Fmt == chars_format::general) {
386 // C11 7.21.6.1 "The fprintf function"/8:
387 // "Let P equal [...] 6 if the precision is omitted [...].
388 // Then, if a conversion with style E would have an exponent of X:
389 // - if P > X >= -4, the conversion is with style f [...].
390 // - otherwise, the conversion is with style e [...]."
391 if (-4 <= _Scientific_exponent && _Scientific_exponent < 6) {
392 _Fmt = chars_format::fixed;
393 } else {
394 _Fmt = chars_format::scientific;
395 }
396 }
397
398 if (_Fmt == chars_format::fixed) {
399 // Example: _Output == 1729, __olength == 4
400
401 // _Ryu_exponent | Printed | _Whole_digits | _Total_fixed_length | Notes
402 // --------------|----------|---------------|----------------------|---------------------------------------
403 // 2 | 172900 | 6 | _Whole_digits | Ryu can't be used for printing
404 // 1 | 17290 | 5 | (sometimes adjusted) | when the trimmed digits are nonzero.
405 // --------------|----------|---------------|----------------------|---------------------------------------
406 // 0 | 1729 | 4 | _Whole_digits | Unified length cases.
407 // --------------|----------|---------------|----------------------|---------------------------------------
408 // -1 | 172.9 | 3 | __olength + 1 | This case can't happen for
409 // -2 | 17.29 | 2 | | __olength == 1, but no additional
410 // -3 | 1.729 | 1 | | code is needed to avoid it.
411 // --------------|----------|---------------|----------------------|---------------------------------------
412 // -4 | 0.1729 | 0 | 2 - _Ryu_exponent | C11 7.21.6.1 "The fprintf function"/8:
413 // -5 | 0.01729 | -1 | | "If a decimal-point character appears,
414 // -6 | 0.001729 | -2 | | at least one digit appears before it."
415
416 const int32_t _Whole_digits = static_cast<int32_t>(__olength) + _Ryu_exponent;
417
418 uint32_t _Total_fixed_length;
419 if (_Ryu_exponent >= 0) { // cases "172900" and "1729"
420 _Total_fixed_length = static_cast<uint32_t>(_Whole_digits);
421 if (_Output == 1) {
422 // Rounding can affect the number of digits.
423 // For example, 1e23 is exactly "99999999999999991611392" which is 23 digits instead of 24.
424 // We can use a lookup table to detect this and adjust the total length.
425 static constexpr uint8_t _Adjustment[309] = {
426 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1,1,0,1,0,1,1,1,0,1,1,1,0,0,0,0,0,
427 1,1,0,0,1,0,1,1,1,0,0,0,0,1,1,1,1,0,0,0,1,1,1,1,0,0,0,1,1,1,1,0,1,0,1,0,1,1,0,0,0,0,1,1,1,
428 1,0,0,0,0,0,0,0,1,1,0,1,1,0,0,1,0,1,0,1,0,1,1,0,0,0,0,0,1,1,1,0,0,1,1,1,1,1,0,1,0,1,1,0,1,
429 1,0,0,0,0,0,0,0,0,0,1,1,1,0,0,1,0,0,1,0,0,1,1,1,1,0,0,1,1,0,1,1,0,1,1,0,1,0,0,0,1,0,0,0,1,
430 0,1,0,1,0,1,1,1,0,0,0,0,0,0,1,1,1,1,0,0,1,0,1,1,1,0,0,0,1,0,1,1,1,1,1,1,0,1,0,1,1,0,0,0,1,
431 1,1,0,1,1,0,0,0,1,0,0,0,1,0,1,0,0,0,0,0,0,0,1,0,1,1,0,0,1,1,1,0,0,0,1,0,1,0,0,0,0,0,1,1,0,
432 0,1,0,1,1,1,0,0,1,0,0,0,0,1,0,1,0,0,0,0,0,1,0,1,0,1,1,0,1,0,0,0,0,0,1,1,0,1,0 };
433 _Total_fixed_length -= _Adjustment[_Ryu_exponent];
434 // _Whole_digits doesn't need to be adjusted because these cases won't refer to it later.
435 }
436 } else if (_Whole_digits > 0) { // case "17.29"
437 _Total_fixed_length = __olength + 1;
438 } else { // case "0.001729"
439 _Total_fixed_length = static_cast<uint32_t>(2 - _Ryu_exponent);
440 }
441
442 if (_Last - _First < static_cast<ptrdiff_t>(_Total_fixed_length)) {
443 return { _Last, errc::value_too_large };
444 }
445
446 char* _Mid;
447 if (_Ryu_exponent > 0) { // case "172900"
448 bool _Can_use_ryu;
449
450 if (_Ryu_exponent > 22) { // 10^22 is the largest power of 10 that's exactly representable as a double.
451 _Can_use_ryu = false;
452 } else {
453 // Ryu generated X: __v.__mantissa * 10^_Ryu_exponent
454 // __v.__mantissa == 2^_Trailing_zero_bits * (__v.__mantissa >> _Trailing_zero_bits)
455 // 10^_Ryu_exponent == 2^_Ryu_exponent * 5^_Ryu_exponent
456
457 // _Trailing_zero_bits is [0, 56] (aside: because 2^56 is the largest power of 2
458 // with 17 decimal digits, which is double's round-trip limit.)
459 // _Ryu_exponent is [1, 22].
460 // Normalization adds [2, 52] (aside: at least 2 because the pre-normalized mantissa is at least 5).
461 // This adds up to [3, 130], which is well below double's maximum binary exponent 1023.
462
463 // Therefore, we just need to consider (__v.__mantissa >> _Trailing_zero_bits) * 5^_Ryu_exponent.
464
465 // If that product would exceed 53 bits, then X can't be exactly represented as a double.
466 // (That's not a problem for round-tripping, because X is close enough to the original double,
467 // but X isn't mathematically equal to the original double.) This requires a high-precision fallback.
468
469 // If the product is 53 bits or smaller, then X can be exactly represented as a double (and we don't
470 // need to re-synthesize it; the original double must have been X, because Ryu wouldn't produce the
471 // same output for two different doubles X and Y). This allows Ryu's output to be used (zero-filled).
472
473 // (2^53 - 1) / 5^0 (for indexing), (2^53 - 1) / 5^1, ..., (2^53 - 1) / 5^22
474 static constexpr uint64_t _Max_shifted_mantissa[23] = {
475 9007199254740991u, 1801439850948198u, 360287970189639u, 72057594037927u, 14411518807585u,
476 2882303761517u, 576460752303u, 115292150460u, 23058430092u, 4611686018u, 922337203u, 184467440u,
477 36893488u, 7378697u, 1475739u, 295147u, 59029u, 11805u, 2361u, 472u, 94u, 18u, 3u };
478
479 unsigned long _Trailing_zero_bits;
480#ifdef _LIBCPP_HAS_BITSCAN64
481 (void) _BitScanForward64(&_Trailing_zero_bits, __v.__mantissa); // __v.__mantissa is guaranteed nonzero
482#else // ^^^ 64-bit ^^^ / vvv 32-bit vvv
483 const uint32_t _Low_mantissa = static_cast<uint32_t>(__v.__mantissa);
484 if (_Low_mantissa != 0) {
485 (void) _BitScanForward(&_Trailing_zero_bits, _Low_mantissa);
486 } else {
487 const uint32_t _High_mantissa = static_cast<uint32_t>(__v.__mantissa >> 32); // nonzero here
488 (void) _BitScanForward(&_Trailing_zero_bits, _High_mantissa);
489 _Trailing_zero_bits += 32;
490 }
491#endif // ^^^ 32-bit ^^^
492 const uint64_t _Shifted_mantissa = __v.__mantissa >> _Trailing_zero_bits;
493 _Can_use_ryu = _Shifted_mantissa <= _Max_shifted_mantissa[_Ryu_exponent];
494 }
495
496 if (!_Can_use_ryu) {
497 // Print the integer exactly.
498 // Performance note: This will redundantly perform bounds checking.
499 // Performance note: This will redundantly decompose the IEEE representation.
500 return __d2fixed_buffered_n(_First, _Last, __f, 0);
501 }
502
503 // _Can_use_ryu
504 // Print the decimal digits, left-aligned within [_First, _First + _Total_fixed_length).
505 _Mid = _First + __olength;
506 } else { // cases "1729", "17.29", and "0.001729"
507 // Print the decimal digits, right-aligned within [_First, _First + _Total_fixed_length).
508 _Mid = _First + _Total_fixed_length;
509 }
510
511 // We prefer 32-bit operations, even on 64-bit platforms.
512 // We have at most 17 digits, and uint32_t can store 9 digits.
513 // If _Output doesn't fit into uint32_t, we cut off 8 digits,
514 // so the rest will fit into uint32_t.
515 if ((_Output >> 32) != 0) {
516 // Expensive 64-bit division.
517 const uint64_t __q = __div1e8(_Output);
518 uint32_t __output2 = static_cast<uint32_t>(_Output - 100000000 * __q);
519 _Output = __q;
520
521 const uint32_t __c = __output2 % 10000;
522 __output2 /= 10000;
523 const uint32_t __d = __output2 % 10000;
524 const uint32_t __c0 = (__c % 100) << 1;
525 const uint32_t __c1 = (__c / 100) << 1;
526 const uint32_t __d0 = (__d % 100) << 1;
527 const uint32_t __d1 = (__d / 100) << 1;
528
529 _VSTD::memcpy(_Mid -= 2, __DIGIT_TABLE + __c0, 2);
530 _VSTD::memcpy(_Mid -= 2, __DIGIT_TABLE + __c1, 2);
531 _VSTD::memcpy(_Mid -= 2, __DIGIT_TABLE + __d0, 2);
532 _VSTD::memcpy(_Mid -= 2, __DIGIT_TABLE + __d1, 2);
533 }
534 uint32_t __output2 = static_cast<uint32_t>(_Output);
535 while (__output2 >= 10000) {
536#ifdef __clang__ // TRANSITION, LLVM-38217
537 const uint32_t __c = __output2 - 10000 * (__output2 / 10000);
538#else
539 const uint32_t __c = __output2 % 10000;
540#endif
541 __output2 /= 10000;
542 const uint32_t __c0 = (__c % 100) << 1;
543 const uint32_t __c1 = (__c / 100) << 1;
544 _VSTD::memcpy(_Mid -= 2, __DIGIT_TABLE + __c0, 2);
545 _VSTD::memcpy(_Mid -= 2, __DIGIT_TABLE + __c1, 2);
546 }
547 if (__output2 >= 100) {
548 const uint32_t __c = (__output2 % 100) << 1;
549 __output2 /= 100;
550 _VSTD::memcpy(_Mid -= 2, __DIGIT_TABLE + __c, 2);
551 }
552 if (__output2 >= 10) {
553 const uint32_t __c = __output2 << 1;
554 _VSTD::memcpy(_Mid -= 2, __DIGIT_TABLE + __c, 2);
555 } else {
556 *--_Mid = static_cast<char>('0' + __output2);
557 }
558
559 if (_Ryu_exponent > 0) { // case "172900" with _Can_use_ryu
560 // Performance note: it might be more efficient to do this immediately after setting _Mid.
561 _VSTD::memset(_First + __olength, '0', static_cast<size_t>(_Ryu_exponent));
562 } else if (_Ryu_exponent == 0) { // case "1729"
563 // Done!
564 } else if (_Whole_digits > 0) { // case "17.29"
565 // Performance note: moving digits might not be optimal.
566 _VSTD::memmove(_First, _First + 1, static_cast<size_t>(_Whole_digits));
567 _First[_Whole_digits] = '.';
568 } else { // case "0.001729"
569 // Performance note: a larger memset() followed by overwriting '.' might be more efficient.
570 _First[0] = '0';
571 _First[1] = '.';
572 _VSTD::memset(_First + 2, '0', static_cast<size_t>(-_Whole_digits));
573 }
574
575 return { _First + _Total_fixed_length, errc{} };
576 }
577
578 const uint32_t _Total_scientific_length = __olength + (__olength > 1) // digits + possible decimal point
579 + (-100 < _Scientific_exponent && _Scientific_exponent < 100 ? 4 : 5); // + scientific exponent
580 if (_Last - _First < static_cast<ptrdiff_t>(_Total_scientific_length)) {
581 return { _Last, errc::value_too_large };
582 }
583 char* const __result = _First;
584
585 // Print the decimal digits.
586 uint32_t __i = 0;
587 // We prefer 32-bit operations, even on 64-bit platforms.
588 // We have at most 17 digits, and uint32_t can store 9 digits.
589 // If _Output doesn't fit into uint32_t, we cut off 8 digits,
590 // so the rest will fit into uint32_t.
591 if ((_Output >> 32) != 0) {
592 // Expensive 64-bit division.
593 const uint64_t __q = __div1e8(_Output);
594 uint32_t __output2 = static_cast<uint32_t>(_Output) - 100000000 * static_cast<uint32_t>(__q);
595 _Output = __q;
596
597 const uint32_t __c = __output2 % 10000;
598 __output2 /= 10000;
599 const uint32_t __d = __output2 % 10000;
600 const uint32_t __c0 = (__c % 100) << 1;
601 const uint32_t __c1 = (__c / 100) << 1;
602 const uint32_t __d0 = (__d % 100) << 1;
603 const uint32_t __d1 = (__d / 100) << 1;
604 _VSTD::memcpy(__result + __olength - __i - 1, __DIGIT_TABLE + __c0, 2);
605 _VSTD::memcpy(__result + __olength - __i - 3, __DIGIT_TABLE + __c1, 2);
606 _VSTD::memcpy(__result + __olength - __i - 5, __DIGIT_TABLE + __d0, 2);
607 _VSTD::memcpy(__result + __olength - __i - 7, __DIGIT_TABLE + __d1, 2);
608 __i += 8;
609 }
610 uint32_t __output2 = static_cast<uint32_t>(_Output);
611 while (__output2 >= 10000) {
612#ifdef __clang__ // TRANSITION, LLVM-38217
613 const uint32_t __c = __output2 - 10000 * (__output2 / 10000);
614#else
615 const uint32_t __c = __output2 % 10000;
616#endif
617 __output2 /= 10000;
618 const uint32_t __c0 = (__c % 100) << 1;
619 const uint32_t __c1 = (__c / 100) << 1;
620 _VSTD::memcpy(__result + __olength - __i - 1, __DIGIT_TABLE + __c0, 2);
621 _VSTD::memcpy(__result + __olength - __i - 3, __DIGIT_TABLE + __c1, 2);
622 __i += 4;
623 }
624 if (__output2 >= 100) {
625 const uint32_t __c = (__output2 % 100) << 1;
626 __output2 /= 100;
627 _VSTD::memcpy(__result + __olength - __i - 1, __DIGIT_TABLE + __c, 2);
628 __i += 2;
629 }
630 if (__output2 >= 10) {
631 const uint32_t __c = __output2 << 1;
632 // We can't use memcpy here: the decimal dot goes between these two digits.
633 __result[2] = __DIGIT_TABLE[__c + 1];
634 __result[0] = __DIGIT_TABLE[__c];
635 } else {
636 __result[0] = static_cast<char>('0' + __output2);
637 }
638
639 // Print decimal point if needed.
640 uint32_t __index;
641 if (__olength > 1) {
642 __result[1] = '.';
643 __index = __olength + 1;
644 } else {
645 __index = 1;
646 }
647
648 // Print the exponent.
649 __result[__index++] = 'e';
650 if (_Scientific_exponent < 0) {
651 __result[__index++] = '-';
652 _Scientific_exponent = -_Scientific_exponent;
653 } else {
654 __result[__index++] = '+';
655 }
656
657 if (_Scientific_exponent >= 100) {
658 const int32_t __c = _Scientific_exponent % 10;
659 _VSTD::memcpy(__result + __index, __DIGIT_TABLE + 2 * (_Scientific_exponent / 10), 2);
660 __result[__index + 2] = static_cast<char>('0' + __c);
661 __index += 3;
662 } else {
663 _VSTD::memcpy(__result + __index, __DIGIT_TABLE + 2 * _Scientific_exponent, 2);
664 __index += 2;
665 }
666
667 return { _First + _Total_scientific_length, errc{} };
668}
669
670[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline bool __d2d_small_int(const uint64_t __ieeeMantissa, const uint32_t __ieeeExponent,
671 __floating_decimal_64* const __v) {
672 const uint64_t __m2 = (1ull << __DOUBLE_MANTISSA_BITS) | __ieeeMantissa;
673 const int32_t __e2 = static_cast<int32_t>(__ieeeExponent) - __DOUBLE_BIAS - __DOUBLE_MANTISSA_BITS;
674
675 if (__e2 > 0) {
676 // f = __m2 * 2^__e2 >= 2^53 is an integer.
677 // Ignore this case for now.
678 return false;
679 }
680
681 if (__e2 < -52) {
682 // f < 1.
683 return false;
684 }
685
686 // Since 2^52 <= __m2 < 2^53 and 0 <= -__e2 <= 52: 1 <= f = __m2 / 2^-__e2 < 2^53.
687 // Test if the lower -__e2 bits of the significand are 0, i.e. whether the fraction is 0.
688 const uint64_t __mask = (1ull << -__e2) - 1;
689 const uint64_t __fraction = __m2 & __mask;
690 if (__fraction != 0) {
691 return false;
692 }
693
694 // f is an integer in the range [1, 2^53).
695 // Note: __mantissa might contain trailing (decimal) 0's.
696 // Note: since 2^53 < 10^16, there is no need to adjust __decimalLength17().
697 __v->__mantissa = __m2 >> -__e2;
698 __v->__exponent = 0;
699 return true;
700}
701
702[[nodiscard]] to_chars_result __d2s_buffered_n(char* const _First, char* const _Last, const double __f,
703 const chars_format _Fmt) {
704
705 // Step 1: Decode the floating-point number, and unify normalized and subnormal cases.
706 const uint64_t __bits = __double_to_bits(__f);
707
708 // Case distinction; exit early for the easy cases.
709 if (__bits == 0) {
710 if (_Fmt == chars_format::scientific) {
711 if (_Last - _First < 5) {
712 return { _Last, errc::value_too_large };
713 }
714
715 _VSTD::memcpy(_First, "0e+00", 5);
716
717 return { _First + 5, errc{} };
718 }
719
720 // Print "0" for chars_format::fixed, chars_format::general, and chars_format{}.
721 if (_First == _Last) {
722 return { _Last, errc::value_too_large };
723 }
724
725 *_First = '0';
726
727 return { _First + 1, errc{} };
728 }
729
730 // Decode __bits into mantissa and exponent.
731 const uint64_t __ieeeMantissa = __bits & ((1ull << __DOUBLE_MANTISSA_BITS) - 1);
732 const uint32_t __ieeeExponent = static_cast<uint32_t>(__bits >> __DOUBLE_MANTISSA_BITS);
733
734 if (_Fmt == chars_format::fixed) {
735 // const uint64_t _Mantissa2 = __ieeeMantissa | (1ull << __DOUBLE_MANTISSA_BITS); // restore implicit bit
736 const int32_t _Exponent2 = static_cast<int32_t>(__ieeeExponent)
737 - __DOUBLE_BIAS - __DOUBLE_MANTISSA_BITS; // bias and normalization
738
739 // Normal values are equal to _Mantissa2 * 2^_Exponent2.
740 // (Subnormals are different, but they'll be rejected by the _Exponent2 test here, so they can be ignored.)
741
742 // For nonzero integers, _Exponent2 >= -52. (The minimum value occurs when _Mantissa2 * 2^_Exponent2 is 1.
743 // In that case, _Mantissa2 is the implicit 1 bit followed by 52 zeros, so _Exponent2 is -52 to shift away
744 // the zeros.) The dense range of exactly representable integers has negative or zero exponents
745 // (as positive exponents make the range non-dense). For that dense range, Ryu will always be used:
746 // every digit is necessary to uniquely identify the value, so Ryu must print them all.
747
748 // Positive exponents are the non-dense range of exactly representable integers. This contains all of the values
749 // for which Ryu can't be used (and a few Ryu-friendly values). We can save time by detecting positive
750 // exponents here and skipping Ryu. Calling __d2fixed_buffered_n() with precision 0 is valid for all integers
751 // (so it's okay if we call it with a Ryu-friendly value).
752 if (_Exponent2 > 0) {
753 return __d2fixed_buffered_n(_First, _Last, __f, 0);
754 }
755 }
756
757 __floating_decimal_64 __v;
758 const bool __isSmallInt = __d2d_small_int(__ieeeMantissa, __ieeeExponent, &__v);
759 if (__isSmallInt) {
760 // For small integers in the range [1, 2^53), __v.__mantissa might contain trailing (decimal) zeros.
761 // For scientific notation we need to move these zeros into the exponent.
762 // (This is not needed for fixed-point notation, so it might be beneficial to trim
763 // trailing zeros in __to_chars only if needed - once fixed-point notation output is implemented.)
764 for (;;) {
765 const uint64_t __q = __div10(__v.__mantissa);
766 const uint32_t __r = static_cast<uint32_t>(__v.__mantissa) - 10 * static_cast<uint32_t>(__q);
767 if (__r != 0) {
768 break;
769 }
770 __v.__mantissa = __q;
771 ++__v.__exponent;
772 }
773 } else {
774 __v = __d2d(__ieeeMantissa, __ieeeExponent);
775 }
776
777 return __to_chars(_First, _Last, __v, _Fmt, __f);
778}
779
780_LIBCPP_END_NAMESPACE_STD
781
782// clang-format on
lib/libcxx/src/ryu/f2s.cpp created+715
......@@ -0,0 +1,715 @@
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// Copyright (c) Microsoft Corporation.
10// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
11
12// Copyright 2018 Ulf Adams
13// Copyright (c) Microsoft Corporation. All rights reserved.
14
15// Boost Software License - Version 1.0 - August 17th, 2003
16
17// Permission is hereby granted, free of charge, to any person or organization
18// obtaining a copy of the software and accompanying documentation covered by
19// this license (the "Software") to use, reproduce, display, distribute,
20// execute, and transmit the Software, and to prepare derivative works of the
21// Software, and to permit third-parties to whom the Software is furnished to
22// do so, all subject to the following:
23
24// The copyright notices in the Software and this entire statement, including
25// the above license grant, this restriction and the following disclaimer,
26// must be included in all copies of the Software, in whole or in part, and
27// all derivative works of the Software, unless such copies or derivative
28// works are solely in the form of machine-executable object code generated by
29// a source language processor.
30
31// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
34// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
35// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
36// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
37// DEALINGS IN THE SOFTWARE.
38
39// Avoid formatting to keep the changes with the original code minimal.
40// clang-format off
41
42#include "__config"
43#include "charconv"
44
45#include "include/ryu/common.h"
46#include "include/ryu/d2fixed.h"
47#include "include/ryu/d2s_intrinsics.h"
48#include "include/ryu/digit_table.h"
49#include "include/ryu/f2s.h"
50#include "include/ryu/ryu.h"
51
52_LIBCPP_BEGIN_NAMESPACE_STD
53
54inline constexpr int __FLOAT_MANTISSA_BITS = 23;
55inline constexpr int __FLOAT_EXPONENT_BITS = 8;
56inline constexpr int __FLOAT_BIAS = 127;
57
58inline constexpr int __FLOAT_POW5_INV_BITCOUNT = 59;
59inline constexpr uint64_t __FLOAT_POW5_INV_SPLIT[31] = {
60 576460752303423489u, 461168601842738791u, 368934881474191033u, 295147905179352826u,
61 472236648286964522u, 377789318629571618u, 302231454903657294u, 483570327845851670u,
62 386856262276681336u, 309485009821345069u, 495176015714152110u, 396140812571321688u,
63 316912650057057351u, 507060240091291761u, 405648192073033409u, 324518553658426727u,
64 519229685853482763u, 415383748682786211u, 332306998946228969u, 531691198313966350u,
65 425352958651173080u, 340282366920938464u, 544451787073501542u, 435561429658801234u,
66 348449143727040987u, 557518629963265579u, 446014903970612463u, 356811923176489971u,
67 570899077082383953u, 456719261665907162u, 365375409332725730u
68};
69inline constexpr int __FLOAT_POW5_BITCOUNT = 61;
70inline constexpr uint64_t __FLOAT_POW5_SPLIT[47] = {
71 1152921504606846976u, 1441151880758558720u, 1801439850948198400u, 2251799813685248000u,
72 1407374883553280000u, 1759218604441600000u, 2199023255552000000u, 1374389534720000000u,
73 1717986918400000000u, 2147483648000000000u, 1342177280000000000u, 1677721600000000000u,
74 2097152000000000000u, 1310720000000000000u, 1638400000000000000u, 2048000000000000000u,
75 1280000000000000000u, 1600000000000000000u, 2000000000000000000u, 1250000000000000000u,
76 1562500000000000000u, 1953125000000000000u, 1220703125000000000u, 1525878906250000000u,
77 1907348632812500000u, 1192092895507812500u, 1490116119384765625u, 1862645149230957031u,
78 1164153218269348144u, 1455191522836685180u, 1818989403545856475u, 2273736754432320594u,
79 1421085471520200371u, 1776356839400250464u, 2220446049250313080u, 1387778780781445675u,
80 1734723475976807094u, 2168404344971008868u, 1355252715606880542u, 1694065894508600678u,
81 2117582368135750847u, 1323488980084844279u, 1654361225106055349u, 2067951531382569187u,
82 1292469707114105741u, 1615587133892632177u, 2019483917365790221u
83};
84
85[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __pow5Factor(uint32_t __value) {
86 uint32_t __count = 0;
87 for (;;) {
88 _LIBCPP_ASSERT(__value != 0, "");
89 const uint32_t __q = __value / 5;
90 const uint32_t __r = __value % 5;
91 if (__r != 0) {
92 break;
93 }
94 __value = __q;
95 ++__count;
96 }
97 return __count;
98}
99
100// Returns true if __value is divisible by 5^__p.
101[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline bool __multipleOfPowerOf5(const uint32_t __value, const uint32_t __p) {
102 return __pow5Factor(__value) >= __p;
103}
104
105// Returns true if __value is divisible by 2^__p.
106[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline bool __multipleOfPowerOf2(const uint32_t __value, const uint32_t __p) {
107 _LIBCPP_ASSERT(__value != 0, "");
108 _LIBCPP_ASSERT(__p < 32, "");
109 // __builtin_ctz doesn't appear to be faster here.
110 return (__value & ((1u << __p) - 1)) == 0;
111}
112
113[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __mulShift(const uint32_t __m, const uint64_t __factor, const int32_t __shift) {
114 _LIBCPP_ASSERT(__shift > 32, "");
115
116 // The casts here help MSVC to avoid calls to the __allmul library
117 // function.
118 const uint32_t __factorLo = static_cast<uint32_t>(__factor);
119 const uint32_t __factorHi = static_cast<uint32_t>(__factor >> 32);
120 const uint64_t __bits0 = static_cast<uint64_t>(__m) * __factorLo;
121 const uint64_t __bits1 = static_cast<uint64_t>(__m) * __factorHi;
122
123#ifndef _LIBCPP_64_BIT
124 // On 32-bit platforms we can avoid a 64-bit shift-right since we only
125 // need the upper 32 bits of the result and the shift value is > 32.
126 const uint32_t __bits0Hi = static_cast<uint32_t>(__bits0 >> 32);
127 uint32_t __bits1Lo = static_cast<uint32_t>(__bits1);
128 uint32_t __bits1Hi = static_cast<uint32_t>(__bits1 >> 32);
129 __bits1Lo += __bits0Hi;
130 __bits1Hi += (__bits1Lo < __bits0Hi);
131 const int32_t __s = __shift - 32;
132 return (__bits1Hi << (32 - __s)) | (__bits1Lo >> __s);
133#else // ^^^ 32-bit ^^^ / vvv 64-bit vvv
134 const uint64_t __sum = (__bits0 >> 32) + __bits1;
135 const uint64_t __shiftedSum = __sum >> (__shift - 32);
136 _LIBCPP_ASSERT(__shiftedSum <= UINT32_MAX, "");
137 return static_cast<uint32_t>(__shiftedSum);
138#endif // ^^^ 64-bit ^^^
139}
140
141[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __mulPow5InvDivPow2(const uint32_t __m, const uint32_t __q, const int32_t __j) {
142 return __mulShift(__m, __FLOAT_POW5_INV_SPLIT[__q], __j);
143}
144
145[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __mulPow5divPow2(const uint32_t __m, const uint32_t __i, const int32_t __j) {
146 return __mulShift(__m, __FLOAT_POW5_SPLIT[__i], __j);
147}
148
149// A floating decimal representing m * 10^e.
150struct __floating_decimal_32 {
151 uint32_t __mantissa;
152 int32_t __exponent;
153};
154
155[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline __floating_decimal_32 __f2d(const uint32_t __ieeeMantissa, const uint32_t __ieeeExponent) {
156 int32_t __e2;
157 uint32_t __m2;
158 if (__ieeeExponent == 0) {
159 // We subtract 2 so that the bounds computation has 2 additional bits.
160 __e2 = 1 - __FLOAT_BIAS - __FLOAT_MANTISSA_BITS - 2;
161 __m2 = __ieeeMantissa;
162 } else {
163 __e2 = static_cast<int32_t>(__ieeeExponent) - __FLOAT_BIAS - __FLOAT_MANTISSA_BITS - 2;
164 __m2 = (1u << __FLOAT_MANTISSA_BITS) | __ieeeMantissa;
165 }
166 const bool __even = (__m2 & 1) == 0;
167 const bool __acceptBounds = __even;
168
169 // Step 2: Determine the interval of valid decimal representations.
170 const uint32_t __mv = 4 * __m2;
171 const uint32_t __mp = 4 * __m2 + 2;
172 // Implicit bool -> int conversion. True is 1, false is 0.
173 const uint32_t __mmShift = __ieeeMantissa != 0 || __ieeeExponent <= 1;
174 const uint32_t __mm = 4 * __m2 - 1 - __mmShift;
175
176 // Step 3: Convert to a decimal power base using 64-bit arithmetic.
177 uint32_t __vr, __vp, __vm;
178 int32_t __e10;
179 bool __vmIsTrailingZeros = false;
180 bool __vrIsTrailingZeros = false;
181 uint8_t __lastRemovedDigit = 0;
182 if (__e2 >= 0) {
183 const uint32_t __q = __log10Pow2(__e2);
184 __e10 = static_cast<int32_t>(__q);
185 const int32_t __k = __FLOAT_POW5_INV_BITCOUNT + __pow5bits(static_cast<int32_t>(__q)) - 1;
186 const int32_t __i = -__e2 + static_cast<int32_t>(__q) + __k;
187 __vr = __mulPow5InvDivPow2(__mv, __q, __i);
188 __vp = __mulPow5InvDivPow2(__mp, __q, __i);
189 __vm = __mulPow5InvDivPow2(__mm, __q, __i);
190 if (__q != 0 && (__vp - 1) / 10 <= __vm / 10) {
191 // We need to know one removed digit even if we are not going to loop below. We could use
192 // __q = X - 1 above, except that would require 33 bits for the result, and we've found that
193 // 32-bit arithmetic is faster even on 64-bit machines.
194 const int32_t __l = __FLOAT_POW5_INV_BITCOUNT + __pow5bits(static_cast<int32_t>(__q - 1)) - 1;
195 __lastRemovedDigit = static_cast<uint8_t>(__mulPow5InvDivPow2(__mv, __q - 1,
196 -__e2 + static_cast<int32_t>(__q) - 1 + __l) % 10);
197 }
198 if (__q <= 9) {
199 // The largest power of 5 that fits in 24 bits is 5^10, but __q <= 9 seems to be safe as well.
200 // Only one of __mp, __mv, and __mm can be a multiple of 5, if any.
201 if (__mv % 5 == 0) {
202 __vrIsTrailingZeros = __multipleOfPowerOf5(__mv, __q);
203 } else if (__acceptBounds) {
204 __vmIsTrailingZeros = __multipleOfPowerOf5(__mm, __q);
205 } else {
206 __vp -= __multipleOfPowerOf5(__mp, __q);
207 }
208 }
209 } else {
210 const uint32_t __q = __log10Pow5(-__e2);
211 __e10 = static_cast<int32_t>(__q) + __e2;
212 const int32_t __i = -__e2 - static_cast<int32_t>(__q);
213 const int32_t __k = __pow5bits(__i) - __FLOAT_POW5_BITCOUNT;
214 int32_t __j = static_cast<int32_t>(__q) - __k;
215 __vr = __mulPow5divPow2(__mv, static_cast<uint32_t>(__i), __j);
216 __vp = __mulPow5divPow2(__mp, static_cast<uint32_t>(__i), __j);
217 __vm = __mulPow5divPow2(__mm, static_cast<uint32_t>(__i), __j);
218 if (__q != 0 && (__vp - 1) / 10 <= __vm / 10) {
219 __j = static_cast<int32_t>(__q) - 1 - (__pow5bits(__i + 1) - __FLOAT_POW5_BITCOUNT);
220 __lastRemovedDigit = static_cast<uint8_t>(__mulPow5divPow2(__mv, static_cast<uint32_t>(__i + 1), __j) % 10);
221 }
222 if (__q <= 1) {
223 // {__vr,__vp,__vm} is trailing zeros if {__mv,__mp,__mm} has at least __q trailing 0 bits.
224 // __mv = 4 * __m2, so it always has at least two trailing 0 bits.
225 __vrIsTrailingZeros = true;
226 if (__acceptBounds) {
227 // __mm = __mv - 1 - __mmShift, so it has 1 trailing 0 bit iff __mmShift == 1.
228 __vmIsTrailingZeros = __mmShift == 1;
229 } else {
230 // __mp = __mv + 2, so it always has at least one trailing 0 bit.
231 --__vp;
232 }
233 } else if (__q < 31) { // TRANSITION(ulfjack): Use a tighter bound here.
234 __vrIsTrailingZeros = __multipleOfPowerOf2(__mv, __q - 1);
235 }
236 }
237
238 // Step 4: Find the shortest decimal representation in the interval of valid representations.
239 int32_t __removed = 0;
240 uint32_t _Output;
241 if (__vmIsTrailingZeros || __vrIsTrailingZeros) {
242 // General case, which happens rarely (~4.0%).
243 while (__vp / 10 > __vm / 10) {
244#ifdef __clang__ // TRANSITION, LLVM-23106
245 __vmIsTrailingZeros &= __vm - (__vm / 10) * 10 == 0;
246#else
247 __vmIsTrailingZeros &= __vm % 10 == 0;
248#endif
249 __vrIsTrailingZeros &= __lastRemovedDigit == 0;
250 __lastRemovedDigit = static_cast<uint8_t>(__vr % 10);
251 __vr /= 10;
252 __vp /= 10;
253 __vm /= 10;
254 ++__removed;
255 }
256 if (__vmIsTrailingZeros) {
257 while (__vm % 10 == 0) {
258 __vrIsTrailingZeros &= __lastRemovedDigit == 0;
259 __lastRemovedDigit = static_cast<uint8_t>(__vr % 10);
260 __vr /= 10;
261 __vp /= 10;
262 __vm /= 10;
263 ++__removed;
264 }
265 }
266 if (__vrIsTrailingZeros && __lastRemovedDigit == 5 && __vr % 2 == 0) {
267 // Round even if the exact number is .....50..0.
268 __lastRemovedDigit = 4;
269 }
270 // We need to take __vr + 1 if __vr is outside bounds or we need to round up.
271 _Output = __vr + ((__vr == __vm && (!__acceptBounds || !__vmIsTrailingZeros)) || __lastRemovedDigit >= 5);
272 } else {
273 // Specialized for the common case (~96.0%). Percentages below are relative to this.
274 // Loop iterations below (approximately):
275 // 0: 13.6%, 1: 70.7%, 2: 14.1%, 3: 1.39%, 4: 0.14%, 5+: 0.01%
276 while (__vp / 10 > __vm / 10) {
277 __lastRemovedDigit = static_cast<uint8_t>(__vr % 10);
278 __vr /= 10;
279 __vp /= 10;
280 __vm /= 10;
281 ++__removed;
282 }
283 // We need to take __vr + 1 if __vr is outside bounds or we need to round up.
284 _Output = __vr + (__vr == __vm || __lastRemovedDigit >= 5);
285 }
286 const int32_t __exp = __e10 + __removed;
287
288 __floating_decimal_32 __fd;
289 __fd.__exponent = __exp;
290 __fd.__mantissa = _Output;
291 return __fd;
292}
293
294[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline to_chars_result _Large_integer_to_chars(char* const _First, char* const _Last,
295 const uint32_t _Mantissa2, const int32_t _Exponent2) {
296
297 // Print the integer _Mantissa2 * 2^_Exponent2 exactly.
298
299 // For nonzero integers, _Exponent2 >= -23. (The minimum value occurs when _Mantissa2 * 2^_Exponent2 is 1.
300 // In that case, _Mantissa2 is the implicit 1 bit followed by 23 zeros, so _Exponent2 is -23 to shift away
301 // the zeros.) The dense range of exactly representable integers has negative or zero exponents
302 // (as positive exponents make the range non-dense). For that dense range, Ryu will always be used:
303 // every digit is necessary to uniquely identify the value, so Ryu must print them all.
304
305 // Positive exponents are the non-dense range of exactly representable integers.
306 // This contains all of the values for which Ryu can't be used (and a few Ryu-friendly values).
307
308 // Performance note: Long division appears to be faster than losslessly widening float to double and calling
309 // __d2fixed_buffered_n(). If __f2fixed_buffered_n() is implemented, it might be faster than long division.
310
311 _LIBCPP_ASSERT(_Exponent2 > 0, "");
312 _LIBCPP_ASSERT(_Exponent2 <= 104, ""); // because __ieeeExponent <= 254
313
314 // Manually represent _Mantissa2 * 2^_Exponent2 as a large integer. _Mantissa2 is always 24 bits
315 // (due to the implicit bit), while _Exponent2 indicates a shift of at most 104 bits.
316 // 24 + 104 equals 128 equals 4 * 32, so we need exactly 4 32-bit elements.
317 // We use a little-endian representation, visualized like this:
318
319 // << left shift <<
320 // most significant
321 // _Data[3] _Data[2] _Data[1] _Data[0]
322 // least significant
323 // >> right shift >>
324
325 constexpr uint32_t _Data_size = 4;
326 uint32_t _Data[_Data_size]{};
327
328 // _Maxidx is the index of the most significant nonzero element.
329 uint32_t _Maxidx = ((24 + static_cast<uint32_t>(_Exponent2) + 31) / 32) - 1;
330 _LIBCPP_ASSERT(_Maxidx < _Data_size, "");
331
332 const uint32_t _Bit_shift = static_cast<uint32_t>(_Exponent2) % 32;
333 if (_Bit_shift <= 8) { // _Mantissa2's 24 bits don't cross an element boundary
334 _Data[_Maxidx] = _Mantissa2 << _Bit_shift;
335 } else { // _Mantissa2's 24 bits cross an element boundary
336 _Data[_Maxidx - 1] = _Mantissa2 << _Bit_shift;
337 _Data[_Maxidx] = _Mantissa2 >> (32 - _Bit_shift);
338 }
339
340 // If Ryu hasn't determined the total output length, we need to buffer the digits generated from right to left
341 // by long division. The largest possible float is: 340'282346638'528859811'704183484'516925440
342 uint32_t _Blocks[4];
343 int32_t _Filled_blocks = 0;
344 // From left to right, we're going to print:
345 // _Data[0] will be [1, 10] digits.
346 // Then if _Filled_blocks > 0:
347 // _Blocks[_Filled_blocks - 1], ..., _Blocks[0] will be 0-filled 9-digit blocks.
348
349 if (_Maxidx != 0) { // If the integer is actually large, perform long division.
350 // Otherwise, skip to printing _Data[0].
351 for (;;) {
352 // Loop invariant: _Maxidx != 0 (i.e. the integer is actually large)
353
354 const uint32_t _Most_significant_elem = _Data[_Maxidx];
355 const uint32_t _Initial_remainder = _Most_significant_elem % 1000000000;
356 const uint32_t _Initial_quotient = _Most_significant_elem / 1000000000;
357 _Data[_Maxidx] = _Initial_quotient;
358 uint64_t _Remainder = _Initial_remainder;
359
360 // Process less significant elements.
361 uint32_t _Idx = _Maxidx;
362 do {
363 --_Idx; // Initially, _Remainder is at most 10^9 - 1.
364
365 // Now, _Remainder is at most (10^9 - 1) * 2^32 + 2^32 - 1, simplified to 10^9 * 2^32 - 1.
366 _Remainder = (_Remainder << 32) | _Data[_Idx];
367
368 // floor((10^9 * 2^32 - 1) / 10^9) == 2^32 - 1, so uint32_t _Quotient is lossless.
369 const uint32_t _Quotient = static_cast<uint32_t>(__div1e9(_Remainder));
370
371 // _Remainder is at most 10^9 - 1 again.
372 // For uint32_t truncation, see the __mod1e9() comment in d2s_intrinsics.h.
373 _Remainder = static_cast<uint32_t>(_Remainder) - 1000000000u * _Quotient;
374
375 _Data[_Idx] = _Quotient;
376 } while (_Idx != 0);
377
378 // Store a 0-filled 9-digit block.
379 _Blocks[_Filled_blocks++] = static_cast<uint32_t>(_Remainder);
380
381 if (_Initial_quotient == 0) { // Is the large integer shrinking?
382 --_Maxidx; // log2(10^9) is 29.9, so we can't shrink by more than one element.
383 if (_Maxidx == 0) {
384 break; // We've finished long division. Now we need to print _Data[0].
385 }
386 }
387 }
388 }
389
390 _LIBCPP_ASSERT(_Data[0] != 0, "");
391 for (uint32_t _Idx = 1; _Idx < _Data_size; ++_Idx) {
392 _LIBCPP_ASSERT(_Data[_Idx] == 0, "");
393 }
394
395 const uint32_t _Data_olength = _Data[0] >= 1000000000 ? 10 : __decimalLength9(_Data[0]);
396 const uint32_t _Total_fixed_length = _Data_olength + 9 * _Filled_blocks;
397
398 if (_Last - _First < static_cast<ptrdiff_t>(_Total_fixed_length)) {
399 return { _Last, errc::value_too_large };
400 }
401
402 char* _Result = _First;
403
404 // Print _Data[0]. While it's up to 10 digits,
405 // which is more than Ryu generates, the code below can handle this.
406 __append_n_digits(_Data_olength, _Data[0], _Result);
407 _Result += _Data_olength;
408
409 // Print 0-filled 9-digit blocks.
410 for (int32_t _Idx = _Filled_blocks - 1; _Idx >= 0; --_Idx) {
411 __append_nine_digits(_Blocks[_Idx], _Result);
412 _Result += 9;
413 }
414
415 return { _Result, errc{} };
416}
417
418[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline to_chars_result __to_chars(char* const _First, char* const _Last, const __floating_decimal_32 __v,
419 chars_format _Fmt, const uint32_t __ieeeMantissa, const uint32_t __ieeeExponent) {
420 // Step 5: Print the decimal representation.
421 uint32_t _Output = __v.__mantissa;
422 int32_t _Ryu_exponent = __v.__exponent;
423 const uint32_t __olength = __decimalLength9(_Output);
424 int32_t _Scientific_exponent = _Ryu_exponent + static_cast<int32_t>(__olength) - 1;
425
426 if (_Fmt == chars_format{}) {
427 int32_t _Lower;
428 int32_t _Upper;
429
430 if (__olength == 1) {
431 // Value | Fixed | Scientific
432 // 1e-3 | "0.001" | "1e-03"
433 // 1e4 | "10000" | "1e+04"
434 _Lower = -3;
435 _Upper = 4;
436 } else {
437 // Value | Fixed | Scientific
438 // 1234e-7 | "0.0001234" | "1.234e-04"
439 // 1234e5 | "123400000" | "1.234e+08"
440 _Lower = -static_cast<int32_t>(__olength + 3);
441 _Upper = 5;
442 }
443
444 if (_Lower <= _Ryu_exponent && _Ryu_exponent <= _Upper) {
445 _Fmt = chars_format::fixed;
446 } else {
447 _Fmt = chars_format::scientific;
448 }
449 } else if (_Fmt == chars_format::general) {
450 // C11 7.21.6.1 "The fprintf function"/8:
451 // "Let P equal [...] 6 if the precision is omitted [...].
452 // Then, if a conversion with style E would have an exponent of X:
453 // - if P > X >= -4, the conversion is with style f [...].
454 // - otherwise, the conversion is with style e [...]."
455 if (-4 <= _Scientific_exponent && _Scientific_exponent < 6) {
456 _Fmt = chars_format::fixed;
457 } else {
458 _Fmt = chars_format::scientific;
459 }
460 }
461
462 if (_Fmt == chars_format::fixed) {
463 // Example: _Output == 1729, __olength == 4
464
465 // _Ryu_exponent | Printed | _Whole_digits | _Total_fixed_length | Notes
466 // --------------|----------|---------------|----------------------|---------------------------------------
467 // 2 | 172900 | 6 | _Whole_digits | Ryu can't be used for printing
468 // 1 | 17290 | 5 | (sometimes adjusted) | when the trimmed digits are nonzero.
469 // --------------|----------|---------------|----------------------|---------------------------------------
470 // 0 | 1729 | 4 | _Whole_digits | Unified length cases.
471 // --------------|----------|---------------|----------------------|---------------------------------------
472 // -1 | 172.9 | 3 | __olength + 1 | This case can't happen for
473 // -2 | 17.29 | 2 | | __olength == 1, but no additional
474 // -3 | 1.729 | 1 | | code is needed to avoid it.
475 // --------------|----------|---------------|----------------------|---------------------------------------
476 // -4 | 0.1729 | 0 | 2 - _Ryu_exponent | C11 7.21.6.1 "The fprintf function"/8:
477 // -5 | 0.01729 | -1 | | "If a decimal-point character appears,
478 // -6 | 0.001729 | -2 | | at least one digit appears before it."
479
480 const int32_t _Whole_digits = static_cast<int32_t>(__olength) + _Ryu_exponent;
481
482 uint32_t _Total_fixed_length;
483 if (_Ryu_exponent >= 0) { // cases "172900" and "1729"
484 _Total_fixed_length = static_cast<uint32_t>(_Whole_digits);
485 if (_Output == 1) {
486 // Rounding can affect the number of digits.
487 // For example, 1e11f is exactly "99999997952" which is 11 digits instead of 12.
488 // We can use a lookup table to detect this and adjust the total length.
489 static constexpr uint8_t _Adjustment[39] = {
490 0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,1,0,1,1,1,0,0,1,1,0,1,0,1,1,0,0,1,0,1,1,0,1,1,1 };
491 _Total_fixed_length -= _Adjustment[_Ryu_exponent];
492 // _Whole_digits doesn't need to be adjusted because these cases won't refer to it later.
493 }
494 } else if (_Whole_digits > 0) { // case "17.29"
495 _Total_fixed_length = __olength + 1;
496 } else { // case "0.001729"
497 _Total_fixed_length = static_cast<uint32_t>(2 - _Ryu_exponent);
498 }
499
500 if (_Last - _First < static_cast<ptrdiff_t>(_Total_fixed_length)) {
501 return { _Last, errc::value_too_large };
502 }
503
504 char* _Mid;
505 if (_Ryu_exponent > 0) { // case "172900"
506 bool _Can_use_ryu;
507
508 if (_Ryu_exponent > 10) { // 10^10 is the largest power of 10 that's exactly representable as a float.
509 _Can_use_ryu = false;
510 } else {
511 // Ryu generated X: __v.__mantissa * 10^_Ryu_exponent
512 // __v.__mantissa == 2^_Trailing_zero_bits * (__v.__mantissa >> _Trailing_zero_bits)
513 // 10^_Ryu_exponent == 2^_Ryu_exponent * 5^_Ryu_exponent
514
515 // _Trailing_zero_bits is [0, 29] (aside: because 2^29 is the largest power of 2
516 // with 9 decimal digits, which is float's round-trip limit.)
517 // _Ryu_exponent is [1, 10].
518 // Normalization adds [2, 23] (aside: at least 2 because the pre-normalized mantissa is at least 5).
519 // This adds up to [3, 62], which is well below float's maximum binary exponent 127.
520
521 // Therefore, we just need to consider (__v.__mantissa >> _Trailing_zero_bits) * 5^_Ryu_exponent.
522
523 // If that product would exceed 24 bits, then X can't be exactly represented as a float.
524 // (That's not a problem for round-tripping, because X is close enough to the original float,
525 // but X isn't mathematically equal to the original float.) This requires a high-precision fallback.
526
527 // If the product is 24 bits or smaller, then X can be exactly represented as a float (and we don't
528 // need to re-synthesize it; the original float must have been X, because Ryu wouldn't produce the
529 // same output for two different floats X and Y). This allows Ryu's output to be used (zero-filled).
530
531 // (2^24 - 1) / 5^0 (for indexing), (2^24 - 1) / 5^1, ..., (2^24 - 1) / 5^10
532 static constexpr uint32_t _Max_shifted_mantissa[11] = {
533 16777215, 3355443, 671088, 134217, 26843, 5368, 1073, 214, 42, 8, 1 };
534
535 unsigned long _Trailing_zero_bits;
536 (void) _BitScanForward(&_Trailing_zero_bits, __v.__mantissa); // __v.__mantissa is guaranteed nonzero
537 const uint32_t _Shifted_mantissa = __v.__mantissa >> _Trailing_zero_bits;
538 _Can_use_ryu = _Shifted_mantissa <= _Max_shifted_mantissa[_Ryu_exponent];
539 }
540
541 if (!_Can_use_ryu) {
542 const uint32_t _Mantissa2 = __ieeeMantissa | (1u << __FLOAT_MANTISSA_BITS); // restore implicit bit
543 const int32_t _Exponent2 = static_cast<int32_t>(__ieeeExponent)
544 - __FLOAT_BIAS - __FLOAT_MANTISSA_BITS; // bias and normalization
545
546 // Performance note: We've already called Ryu, so this will redundantly perform buffering and bounds checking.
547 return _Large_integer_to_chars(_First, _Last, _Mantissa2, _Exponent2);
548 }
549
550 // _Can_use_ryu
551 // Print the decimal digits, left-aligned within [_First, _First + _Total_fixed_length).
552 _Mid = _First + __olength;
553 } else { // cases "1729", "17.29", and "0.001729"
554 // Print the decimal digits, right-aligned within [_First, _First + _Total_fixed_length).
555 _Mid = _First + _Total_fixed_length;
556 }
557
558 while (_Output >= 10000) {
559#ifdef __clang__ // TRANSITION, LLVM-38217
560 const uint32_t __c = _Output - 10000 * (_Output / 10000);
561#else
562 const uint32_t __c = _Output % 10000;
563#endif
564 _Output /= 10000;
565 const uint32_t __c0 = (__c % 100) << 1;
566 const uint32_t __c1 = (__c / 100) << 1;
567 _VSTD::memcpy(_Mid -= 2, __DIGIT_TABLE + __c0, 2);
568 _VSTD::memcpy(_Mid -= 2, __DIGIT_TABLE + __c1, 2);
569 }
570 if (_Output >= 100) {
571 const uint32_t __c = (_Output % 100) << 1;
572 _Output /= 100;
573 _VSTD::memcpy(_Mid -= 2, __DIGIT_TABLE + __c, 2);
574 }
575 if (_Output >= 10) {
576 const uint32_t __c = _Output << 1;
577 _VSTD::memcpy(_Mid -= 2, __DIGIT_TABLE + __c, 2);
578 } else {
579 *--_Mid = static_cast<char>('0' + _Output);
580 }
581
582 if (_Ryu_exponent > 0) { // case "172900" with _Can_use_ryu
583 // Performance note: it might be more efficient to do this immediately after setting _Mid.
584 _VSTD::memset(_First + __olength, '0', static_cast<size_t>(_Ryu_exponent));
585 } else if (_Ryu_exponent == 0) { // case "1729"
586 // Done!
587 } else if (_Whole_digits > 0) { // case "17.29"
588 // Performance note: moving digits might not be optimal.
589 _VSTD::memmove(_First, _First + 1, static_cast<size_t>(_Whole_digits));
590 _First[_Whole_digits] = '.';
591 } else { // case "0.001729"
592 // Performance note: a larger memset() followed by overwriting '.' might be more efficient.
593 _First[0] = '0';
594 _First[1] = '.';
595 _VSTD::memset(_First + 2, '0', static_cast<size_t>(-_Whole_digits));
596 }
597
598 return { _First + _Total_fixed_length, errc{} };
599 }
600
601 const uint32_t _Total_scientific_length =
602 __olength + (__olength > 1) + 4; // digits + possible decimal point + scientific exponent
603 if (_Last - _First < static_cast<ptrdiff_t>(_Total_scientific_length)) {
604 return { _Last, errc::value_too_large };
605 }
606 char* const __result = _First;
607
608 // Print the decimal digits.
609 uint32_t __i = 0;
610 while (_Output >= 10000) {
611#ifdef __clang__ // TRANSITION, LLVM-38217
612 const uint32_t __c = _Output - 10000 * (_Output / 10000);
613#else
614 const uint32_t __c = _Output % 10000;
615#endif
616 _Output /= 10000;
617 const uint32_t __c0 = (__c % 100) << 1;
618 const uint32_t __c1 = (__c / 100) << 1;
619 _VSTD::memcpy(__result + __olength - __i - 1, __DIGIT_TABLE + __c0, 2);
620 _VSTD::memcpy(__result + __olength - __i - 3, __DIGIT_TABLE + __c1, 2);
621 __i += 4;
622 }
623 if (_Output >= 100) {
624 const uint32_t __c = (_Output % 100) << 1;
625 _Output /= 100;
626 _VSTD::memcpy(__result + __olength - __i - 1, __DIGIT_TABLE + __c, 2);
627 __i += 2;
628 }
629 if (_Output >= 10) {
630 const uint32_t __c = _Output << 1;
631 // We can't use memcpy here: the decimal dot goes between these two digits.
632 __result[2] = __DIGIT_TABLE[__c + 1];
633 __result[0] = __DIGIT_TABLE[__c];
634 } else {
635 __result[0] = static_cast<char>('0' + _Output);
636 }
637
638 // Print decimal point if needed.
639 uint32_t __index;
640 if (__olength > 1) {
641 __result[1] = '.';
642 __index = __olength + 1;
643 } else {
644 __index = 1;
645 }
646
647 // Print the exponent.
648 __result[__index++] = 'e';
649 if (_Scientific_exponent < 0) {
650 __result[__index++] = '-';
651 _Scientific_exponent = -_Scientific_exponent;
652 } else {
653 __result[__index++] = '+';
654 }
655
656 _VSTD::memcpy(__result + __index, __DIGIT_TABLE + 2 * _Scientific_exponent, 2);
657 __index += 2;
658
659 return { _First + _Total_scientific_length, errc{} };
660}
661
662[[nodiscard]] to_chars_result __f2s_buffered_n(char* const _First, char* const _Last, const float __f,
663 const chars_format _Fmt) {
664
665 // Step 1: Decode the floating-point number, and unify normalized and subnormal cases.
666 const uint32_t __bits = __float_to_bits(__f);
667
668 // Case distinction; exit early for the easy cases.
669 if (__bits == 0) {
670 if (_Fmt == chars_format::scientific) {
671 if (_Last - _First < 5) {
672 return { _Last, errc::value_too_large };
673 }
674
675 _VSTD::memcpy(_First, "0e+00", 5);
676
677 return { _First + 5, errc{} };
678 }
679
680 // Print "0" for chars_format::fixed, chars_format::general, and chars_format{}.
681 if (_First == _Last) {
682 return { _Last, errc::value_too_large };
683 }
684
685 *_First = '0';
686
687 return { _First + 1, errc{} };
688 }
689
690 // Decode __bits into mantissa and exponent.
691 const uint32_t __ieeeMantissa = __bits & ((1u << __FLOAT_MANTISSA_BITS) - 1);
692 const uint32_t __ieeeExponent = __bits >> __FLOAT_MANTISSA_BITS;
693
694 // When _Fmt == chars_format::fixed and the floating-point number is a large integer,
695 // it's faster to skip Ryu and immediately print the integer exactly.
696 if (_Fmt == chars_format::fixed) {
697 const uint32_t _Mantissa2 = __ieeeMantissa | (1u << __FLOAT_MANTISSA_BITS); // restore implicit bit
698 const int32_t _Exponent2 = static_cast<int32_t>(__ieeeExponent)
699 - __FLOAT_BIAS - __FLOAT_MANTISSA_BITS; // bias and normalization
700
701 // Normal values are equal to _Mantissa2 * 2^_Exponent2.
702 // (Subnormals are different, but they'll be rejected by the _Exponent2 test here, so they can be ignored.)
703
704 if (_Exponent2 > 0) {
705 return _Large_integer_to_chars(_First, _Last, _Mantissa2, _Exponent2);
706 }
707 }
708
709 const __floating_decimal_32 __v = __f2d(__ieeeMantissa, __ieeeExponent);
710 return __to_chars(_First, _Last, __v, _Fmt, __ieeeMantissa, __ieeeExponent);
711}
712
713_LIBCPP_END_NAMESPACE_STD
714
715// clang-format on
lib/libcxx/src/shared_mutex.cpp+1-1
......@@ -1,4 +1,4 @@
1//===---------------------- shared_mutex.cpp ------------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/stdexcept.cpp+1-1
......@@ -1,4 +1,4 @@
1//===------------------------ stdexcept.cpp -------------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/string.cpp+59-8
......@@ -1,4 +1,4 @@
1//===------------------------- string.cpp ---------------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
......@@ -9,24 +9,50 @@
99#include "string"
1010#include "charconv"
1111#include "cstdlib"
12#include "cwchar"
1312#include "cerrno"
1413#include "limits"
1514#include "stdexcept"
1615#include <stdio.h>
1716#include "__debug"
1817
18#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
19# include "cwchar"
20#endif
21
1922_LIBCPP_BEGIN_NAMESPACE_STD
2023
21template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __basic_string_common<true>;
24#ifndef _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON
25
26template <bool>
27struct __basic_string_common;
28
29// The struct isn't declared anymore in the headers. It's only here for ABI compatibility.
30template <>
31struct __basic_string_common<true> {
32 _LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_length_error() const;
33 _LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_out_of_range() const;
34};
35
36void __basic_string_common<true>::__throw_length_error() const {
37 std::__throw_length_error("basic_string");
38}
39void __basic_string_common<true>::__throw_out_of_range() const {
40 std::__throw_out_of_range("basic_string");
41}
42
43#endif // _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON
2244
2345#define _LIBCPP_EXTERN_TEMPLATE_DEFINE(...) template __VA_ARGS__;
2446#ifdef _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
25_LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, char)
26_LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, wchar_t)
47 _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, char)
48# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
49 _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, wchar_t)
50# endif
2751#else
28_LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, char)
29_LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, wchar_t)
52 _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, char)
53# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
54 _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, wchar_t)
55# endif
3056#endif
3157#undef _LIBCPP_EXTERN_TEMPLATE_DEFINE
3258
......@@ -131,6 +157,7 @@ as_integer( const string& func, const string& s, size_t* idx, int base )
131157 return as_integer_helper<unsigned long long>( func, s, idx, base, strtoull );
132158}
133159
160#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
134161// wstring
135162template<>
136163inline
......@@ -175,6 +202,7 @@ as_integer( const string& func, const wstring& s, size_t* idx, int base )
175202{
176203 return as_integer_helper<unsigned long long>( func, s, idx, base, wcstoull );
177204}
205#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
178206
179207// as_float
180208
......@@ -226,6 +254,7 @@ as_float( const string& func, const string& s, size_t* idx )
226254 return as_float_helper<long double>( func, s, idx, strtold );
227255}
228256
257#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
229258template<>
230259inline
231260float
......@@ -249,6 +278,7 @@ as_float( const string& func, const wstring& s, size_t* idx )
249278{
250279 return as_float_helper<long double>( func, s, idx, wcstold );
251280}
281#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
252282
253283} // unnamed namespace
254284
......@@ -258,11 +288,13 @@ stoi(const string& str, size_t* idx, int base)
258288 return as_integer<int>( "stoi", str, idx, base );
259289}
260290
291#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
261292int
262293stoi(const wstring& str, size_t* idx, int base)
263294{
264295 return as_integer<int>( "stoi", str, idx, base );
265296}
297#endif
266298
267299long
268300stol(const string& str, size_t* idx, int base)
......@@ -270,11 +302,13 @@ stol(const string& str, size_t* idx, int base)
270302 return as_integer<long>( "stol", str, idx, base );
271303}
272304
305#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
273306long
274307stol(const wstring& str, size_t* idx, int base)
275308{
276309 return as_integer<long>( "stol", str, idx, base );
277310}
311#endif
278312
279313unsigned long
280314stoul(const string& str, size_t* idx, int base)
......@@ -282,11 +316,13 @@ stoul(const string& str, size_t* idx, int base)
282316 return as_integer<unsigned long>( "stoul", str, idx, base );
283317}
284318
319#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
285320unsigned long
286321stoul(const wstring& str, size_t* idx, int base)
287322{
288323 return as_integer<unsigned long>( "stoul", str, idx, base );
289324}
325#endif
290326
291327long long
292328stoll(const string& str, size_t* idx, int base)
......@@ -294,11 +330,13 @@ stoll(const string& str, size_t* idx, int base)
294330 return as_integer<long long>( "stoll", str, idx, base );
295331}
296332
333#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
297334long long
298335stoll(const wstring& str, size_t* idx, int base)
299336{
300337 return as_integer<long long>( "stoll", str, idx, base );
301338}
339#endif
302340
303341unsigned long long
304342stoull(const string& str, size_t* idx, int base)
......@@ -306,11 +344,13 @@ stoull(const string& str, size_t* idx, int base)
306344 return as_integer<unsigned long long>( "stoull", str, idx, base );
307345}
308346
347#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
309348unsigned long long
310349stoull(const wstring& str, size_t* idx, int base)
311350{
312351 return as_integer<unsigned long long>( "stoull", str, idx, base );
313352}
353#endif
314354
315355float
316356stof(const string& str, size_t* idx)
......@@ -318,11 +358,13 @@ stof(const string& str, size_t* idx)
318358 return as_float<float>( "stof", str, idx );
319359}
320360
361#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
321362float
322363stof(const wstring& str, size_t* idx)
323364{
324365 return as_float<float>( "stof", str, idx );
325366}
367#endif
326368
327369double
328370stod(const string& str, size_t* idx)
......@@ -330,11 +372,13 @@ stod(const string& str, size_t* idx)
330372 return as_float<double>( "stod", str, idx );
331373}
332374
375#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
333376double
334377stod(const wstring& str, size_t* idx)
335378{
336379 return as_float<double>( "stod", str, idx );
337380}
381#endif
338382
339383long double
340384stold(const string& str, size_t* idx)
......@@ -342,11 +386,13 @@ stold(const string& str, size_t* idx)
342386 return as_float<long double>( "stold", str, idx );
343387}
344388
389#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
345390long double
346391stold(const wstring& str, size_t* idx)
347392{
348393 return as_float<long double>( "stold", str, idx );
349394}
395#endif
350396
351397// to_string
352398
......@@ -397,6 +443,7 @@ struct initial_string<string>
397443 }
398444};
399445
446#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
400447template <>
401448struct initial_string<wstring>
402449{
......@@ -421,6 +468,7 @@ get_swprintf()
421468 return static_cast<int (__cdecl*)(wchar_t* __restrict, size_t, const wchar_t*__restrict, ...)>(_snwprintf);
422469#endif
423470}
471#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
424472
425473template <typename S, typename V>
426474S i_to_string(V v)
......@@ -444,20 +492,23 @@ string to_string (unsigned val) { return i_to_string< string>(val); }
444492string to_string (unsigned long val) { return i_to_string< string>(val); }
445493string to_string (unsigned long long val) { return i_to_string< string>(val); }
446494
495#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
447496wstring to_wstring(int val) { return i_to_string<wstring>(val); }
448497wstring to_wstring(long val) { return i_to_string<wstring>(val); }
449498wstring to_wstring(long long val) { return i_to_string<wstring>(val); }
450499wstring to_wstring(unsigned val) { return i_to_string<wstring>(val); }
451500wstring to_wstring(unsigned long val) { return i_to_string<wstring>(val); }
452501wstring to_wstring(unsigned long long val) { return i_to_string<wstring>(val); }
453
502#endif
454503
455504string to_string (float val) { return as_string(snprintf, initial_string< string>()(), "%f", val); }
456505string to_string (double val) { return as_string(snprintf, initial_string< string>()(), "%f", val); }
457506string to_string (long double val) { return as_string(snprintf, initial_string< string>()(), "%Lf", val); }
458507
508#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
459509wstring to_wstring(float val) { return as_string(get_swprintf(), initial_string<wstring>()(), L"%f", val); }
460510wstring to_wstring(double val) { return as_string(get_swprintf(), initial_string<wstring>()(), L"%f", val); }
461511wstring to_wstring(long double val) { return as_string(get_swprintf(), initial_string<wstring>()(), L"%Lf", val); }
512#endif
462513
463514_LIBCPP_END_NAMESPACE_STD
lib/libcxx/src/strstream.cpp+1-1
......@@ -1,4 +1,4 @@
1//===------------------------ strstream.cpp -------------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/support/ibm/mbsnrtowcs.cpp 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#include <cstddef> // size_t
10#include <cwchar> // mbstate_t
11#include <limits.h> // MB_LEN_MAX
12#include <string.h> // wmemcpy
13
14// Returns the number of wide characters found in the multi byte sequence `src`
15// (of `src_size_bytes`), that fit in the buffer `dst` (of `max_dest_chars`
16// elements size). The count returned excludes the null terminator.
17// When `dst` is NULL, no characters are copied to `dst`.
18// Returns (size_t) -1 when an invalid sequence is encountered.
19// Leaves *`src` pointing to the next character to convert or NULL
20// if a null character was converted from *`src`.
21_LIBCPP_FUNC_VIS
22size_t mbsnrtowcs(wchar_t *__restrict dst, const char **__restrict src,
23 size_t src_size_bytes, size_t max_dest_chars,
24 mbstate_t *__restrict ps) {
25 const size_t terminated_sequence = static_cast<size_t>(0);
26 const size_t invalid_sequence = static_cast<size_t>(-1);
27 const size_t incomplete_sequence = static_cast<size_t>(-2);
28
29 size_t source_converted;
30 size_t dest_converted;
31 size_t result = 0;
32
33 // If `dst` is null then `max_dest_chars` should be ignored according to the
34 // standard. Setting `max_dest_chars` to a large value has this effect.
35 if (dst == nullptr)
36 max_dest_chars = static_cast<size_t>(-1);
37
38 for (dest_converted = source_converted = 0;
39 source_converted < src_size_bytes && (!dst || dest_converted < max_dest_chars);
40 ++dest_converted, source_converted += result) {
41 // Converts one multi byte character.
42 // If result (char_size) is greater than 0, it's the size in bytes of that character.
43 // If result (char_size) is zero, it indicates that the null character has been found.
44 // Otherwise, it's an error and errno may be set.
45 size_t source_remaining = src_size_bytes - source_converted;
46 size_t dest_remaining = max_dest_chars - dest_converted;
47
48 if (dst == nullptr) {
49 result = mbrtowc(NULL, *src + source_converted, source_remaining, ps);
50 } else if (dest_remaining >= source_remaining) {
51 // dst has enough space to translate in-place.
52 result = mbrtowc(dst + dest_converted, *src + source_converted, source_remaining, ps);
53 } else {
54 /*
55 * dst may not have enough space, so use a temporary buffer.
56 *
57 * We need to save a copy of the conversion state
58 * here so we can restore it if the multibyte
59 * character is too long for the buffer.
60 */
61 wchar_t buff[MB_LEN_MAX];
62 mbstate_t mbstate_tmp;
63
64 if (ps != nullptr)
65 mbstate_tmp = *ps;
66 result = mbrtowc(buff, *src + source_converted, source_remaining, ps);
67
68 if (result > dest_remaining) {
69 // Multi-byte sequence for character won't fit.
70 if (ps != nullptr)
71 *ps = mbstate_tmp;
72 break;
73 } else {
74 // The buffer was used, so we need copy the translation to dst.
75 wmemcpy(dst, buff, result);
76 }
77 }
78
79 // Don't do anything to change errno from here on.
80 if (result == invalid_sequence || result == terminated_sequence || result == incomplete_sequence) {
81 break;
82 }
83 }
84
85 if (dst) {
86 if (result == terminated_sequence)
87 *src = NULL;
88 else
89 *src += source_converted;
90 }
91 if (result == invalid_sequence)
92 return invalid_sequence;
93
94 return dest_converted;
95}
lib/libcxx/src/support/ibm/wcsnrtombs.cpp 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#include <cwchar> // mbstate_t
10#include <limits.h> // MB_LEN_MAX
11#include <stdlib.h> // MB_CUR_MAX, size_t
12#include <string.h> // memcpy
13
14// Converts `max_source_chars` from the wide character buffer pointer to by *`src`,
15// into the multi byte character sequence buffer stored at `dst`, which must be
16// `dst_size_bytes` bytes in size. Returns the number of bytes in the sequence
17// converted from *src, excluding the null terminator.
18// Returns (size_t) -1 if an error occurs and sets errno.
19// If `dst` is NULL, `dst_size_bytes` is ignored and no bytes are copied to `dst`.
20_LIBCPP_FUNC_VIS
21size_t wcsnrtombs(char *__restrict dst, const wchar_t **__restrict src,
22 size_t max_source_chars, size_t dst_size_bytes,
23 mbstate_t *__restrict ps) {
24
25 const size_t invalid_wchar = static_cast<size_t>(-1);
26
27 size_t source_converted;
28 size_t dest_converted;
29 size_t result = 0;
30
31 // If `dst` is null then `dst_size_bytes` should be ignored according to the
32 // standard. Setting dst_size_bytes to a large value has this effect.
33 if (dst == nullptr)
34 dst_size_bytes = static_cast<size_t>(-1);
35
36 for (dest_converted = source_converted = 0;
37 source_converted < max_source_chars && (!dst || dest_converted < dst_size_bytes);
38 ++source_converted, dest_converted += result) {
39 wchar_t c = (*src)[source_converted];
40 size_t dest_remaining = dst_size_bytes - dest_converted;
41
42 if (dst == nullptr) {
43 result = wcrtomb(NULL, c, ps);
44 } else if (dest_remaining >= static_cast<size_t>(MB_CUR_MAX)) {
45 // dst has enough space to translate in-place.
46 result = wcrtomb(dst + dest_converted, c, ps);
47 } else {
48 /*
49 * dst may not have enough space, so use a temporary buffer.
50 *
51 * We need to save a copy of the conversion state
52 * here so we can restore it if the multibyte
53 * character is too long for the buffer.
54 */
55 char buff[MB_LEN_MAX];
56 mbstate_t mbstate_tmp;
57
58 if (ps != nullptr)
59 mbstate_tmp = *ps;
60 result = wcrtomb(buff, c, ps);
61
62 if (result > dest_remaining) {
63 // Multi-byte sequence for character won't fit.
64 if (ps != nullptr)
65 *ps = mbstate_tmp;
66 if (result != invalid_wchar)
67 break;
68 } else {
69 // The buffer was used, so we need copy the translation to dst.
70 memcpy(dst, buff, result);
71 }
72 }
73
74 // result (char_size) contains the size of the multi-byte-sequence converted.
75 // Otherwise, result (char_size) is (size_t) -1 and wcrtomb() sets the errno.
76 if (result == invalid_wchar) {
77 if (dst)
78 *src = *src + source_converted;
79 return invalid_wchar;
80 }
81
82 if (c == L'\0') {
83 if (dst)
84 *src = NULL;
85 return dest_converted;
86 }
87 }
88
89 if (dst)
90 *src = *src + source_converted;
91
92 return dest_converted;
93}
lib/libcxx/src/support/runtime/stdexcept_default.ipp+1-1
......@@ -1,4 +1,4 @@
1//===--------------------- stdexcept_default.ipp --------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/support/runtime/stdexcept_vcruntime.ipp+1-1
......@@ -1,4 +1,4 @@
1//===------------------- stdexcept_vcruntime.ipp --------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/support/win32/locale_win32.cpp+3-1
......@@ -1,4 +1,3 @@
1// -*- C++ -*-
21//===----------------------------------------------------------------------===//
32//
43// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
......@@ -98,7 +97,10 @@ int snprintf_l(char *ret, size_t n, locale_t loc, const char *format, ...)
9897 ret, n, format, loc, ap);
9998#else
10099 __libcpp_locale_guard __current(loc);
100#pragma clang diagnostic push
101#pragma clang diagnostic ignored "-Wformat-nonliteral"
101102 int result = vsnprintf( ret, n, format, ap );
103#pragma clang diagnostic pop
102104#endif
103105 va_end(ap);
104106 return result;
lib/libcxx/src/support/win32/support.cpp+8-3
......@@ -1,4 +1,3 @@
1// -*- C++ -*-
21//===----------------------------------------------------------------------===//
32//
43// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
......@@ -24,7 +23,10 @@ int __libcpp_vasprintf( char **sptr, const char *__restrict format, va_list ap )
2423 // Query the count required.
2524 va_list ap_copy;
2625 va_copy(ap_copy, ap);
27 int count = _vsnprintf( NULL, 0, format, ap_copy );
26#pragma clang diagnostic push
27#pragma clang diagnostic ignored "-Wformat-nonliteral"
28 int count = vsnprintf( NULL, 0, format, ap_copy );
29#pragma clang diagnostic pop
2830 va_end(ap_copy);
2931 if (count < 0)
3032 return count;
......@@ -34,7 +36,10 @@ int __libcpp_vasprintf( char **sptr, const char *__restrict format, va_list ap )
3436 return -1;
3537 // If we haven't used exactly what was required, something is wrong.
3638 // Maybe bug in vsnprintf. Report the error and return.
37 if (_vsnprintf(p, buffer_size, format, ap) != count) {
39#pragma clang diagnostic push
40#pragma clang diagnostic ignored "-Wformat-nonliteral"
41 if (vsnprintf(p, buffer_size, format, ap) != count) {
42#pragma clang diagnostic pop
3843 free(p);
3944 return -1;
4045 }
lib/libcxx/src/support/win32/thread_win32.cpp-37
......@@ -1,4 +1,3 @@
1// -*- C++ -*-
21//===----------------------------------------------------------------------===//
32//
43// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
......@@ -39,9 +38,6 @@ static_assert(alignof(__libcpp_thread_t) == alignof(HANDLE), "");
3938static_assert(sizeof(__libcpp_tls_key) == sizeof(DWORD), "");
4039static_assert(alignof(__libcpp_tls_key) == alignof(DWORD), "");
4140
42static_assert(sizeof(__libcpp_semaphore_t) == sizeof(HANDLE), "");
43static_assert(alignof(__libcpp_semaphore_t) == alignof(HANDLE), "");
44
4541// Mutex
4642int __libcpp_recursive_mutex_init(__libcpp_recursive_mutex_t *__m)
4743{
......@@ -275,37 +271,4 @@ int __libcpp_tls_set(__libcpp_tls_key __key, void *__p)
275271 return 0;
276272}
277273
278// Semaphores
279bool __libcpp_semaphore_init(__libcpp_semaphore_t* __sem, int __init)
280{
281 *(PHANDLE)__sem = CreateSemaphoreEx(nullptr, __init, _LIBCPP_SEMAPHORE_MAX,
282 nullptr, 0, SEMAPHORE_ALL_ACCESS);
283 return *__sem != nullptr;
284}
285
286bool __libcpp_semaphore_destroy(__libcpp_semaphore_t* __sem)
287{
288 CloseHandle(*(PHANDLE)__sem);
289 return true;
290}
291
292bool __libcpp_semaphore_post(__libcpp_semaphore_t* __sem)
293{
294 return ReleaseSemaphore(*(PHANDLE)__sem, 1, nullptr);
295}
296
297bool __libcpp_semaphore_wait(__libcpp_semaphore_t* __sem)
298{
299 return WaitForSingleObjectEx(*(PHANDLE)__sem, INFINITE, false) ==
300 WAIT_OBJECT_0;
301}
302
303bool __libcpp_semaphore_wait_timed(__libcpp_semaphore_t* __sem,
304 chrono::nanoseconds const& __ns)
305{
306 chrono::milliseconds __ms = chrono::ceil<chrono::milliseconds>(__ns);
307 return WaitForSingleObjectEx(*(PHANDLE)__sem, __ms.count(), false) ==
308 WAIT_OBJECT_0;
309}
310
311274_LIBCPP_END_NAMESPACE_STD
lib/libcxx/src/system_error.cpp+1-1
......@@ -1,4 +1,4 @@
1//===---------------------- system_error.cpp ------------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/typeinfo.cpp+1-1
......@@ -1,4 +1,4 @@
1//===------------------------- typeinfo.cpp -------------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/utility.cpp+1-1
......@@ -1,4 +1,4 @@
1//===------------------------ utility.cpp ---------------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/valarray.cpp+1-1
......@@ -1,4 +1,4 @@
1//===------------------------ valarray.cpp --------------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/variant.cpp+1-1
......@@ -1,4 +1,4 @@
1//===------------------------ variant.cpp ---------------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/vector.cpp+21-2
......@@ -1,4 +1,4 @@
1//===------------------------- vector.cpp ---------------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
......@@ -10,6 +10,25 @@
1010
1111_LIBCPP_BEGIN_NAMESPACE_STD
1212
13template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __vector_base_common<true>;
13#ifndef _LIBCPP_ABI_DO_NOT_EXPORT_VECTOR_BASE_COMMON
14
15template <bool>
16struct __vector_base_common;
17
18template <>
19struct __vector_base_common<true> {
20 _LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_length_error() const;
21 _LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_out_of_range() const;
22};
23
24void __vector_base_common<true>::__throw_length_error() const {
25 _VSTD::__throw_length_error("vector");
26}
27
28void __vector_base_common<true>::__throw_out_of_range() const {
29 _VSTD::__throw_out_of_range("vector");
30}
31
32#endif // _LIBCPP_ABI_DO_NOT_EXPORT_VECTOR_BASE_COMMON
1433
1534_LIBCPP_END_NAMESPACE_STD
src/libcxx.zig+6
......@@ -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_pointer_safety.cpp",
5758 "src/locale.cpp",
5859 "src/memory.cpp",
5960 "src/mutex.cpp",
......@@ -63,10 +64,15 @@ const libcxx_files = [_][]const u8{
6364 "src/random.cpp",
6465 "src/random_shuffle.cpp",
6566 "src/regex.cpp",
67 "src/ryu/d2fixed.cpp",
68 "src/ryu/d2s.cpp",
69 "src/ryu/f2s.cpp",
6670 "src/shared_mutex.cpp",
6771 "src/stdexcept.cpp",
6872 "src/string.cpp",
6973 "src/strstream.cpp",
74 "src/support/ibm/mbsnrtowcs.cpp",
75 "src/support/ibm/wcsnrtombs.cpp",
7076 "src/support/ibm/xlocale_zos.cpp",
7177 "src/support/solaris/xlocale.cpp",
7278 "src/support/win32/locale_win32.cpp",